Back to Course

Algorithm

0% Complete
0/82 Steps
  1. Getting Started with Algorithm
    What is an Algorithm?
  2. Characteristics of Algorithm
    1 Topic
  3. Analysis Framework
  4. Performance Analysis
    3 Topics
  5. Mathematical Analysis
    2 Topics
  6. Sorting Algorithm
    Sorting Algorithm
    10 Topics
  7. Searching Algorithm
    6 Topics
  8. Fundamental of Data Structures
    Stacks
  9. Queues
  10. Graphs
  11. Trees
  12. Sets
  13. Dictionaries
  14. Divide and Conquer
    General Method
  15. Binary Search
  16. Recurrence Equation for Divide and Conquer
  17. Finding the Maximum and Minimum
  18. Merge Sort
  19. Quick Sort
  20. Stassen’s Matrix Multiplication
  21. Advantages and Disadvantages of Divide and Conquer
  22. Decrease and Conquer
    Insertion Sort
  23. Topological Sort
  24. Greedy Method
    General Method
  25. Coin Change Problem
  26. Knapsack Problem
  27. Job Sequencing with Deadlines
  28. Minimum Cost Spanning Trees
    2 Topics
  29. Single Source Shortest Paths
    1 Topic
  30. Optimal Tree Problem
    1 Topic
  31. Transform and Conquer Approach
    1 Topic
  32. Dynamic Programming
    General Method with Examples
  33. Multistage Graphs
  34. Transitive Closure
    1 Topic
  35. All Pairs Shortest Paths
    6 Topics
  36. Backtracking
    General Method
  37. N-Queens Problem
  38. Sum of Subsets problem
  39. Graph Coloring
  40. Hamiltonian Cycles
  41. Branch and Bound
    2 Topics
  42. 0/1 Knapsack problem
    2 Topics
  43. NP-Complete and NP-Hard Problems
    1 Topic
Lesson 16 of 43
In Progress

Recurrence Equation for Divide and Conquer

Divide-and-conquer algorithms:

  1. Dividing the problem into smaller sub-problems
  2. Solving those sub-problems
  3. Combining the solutions for those smaller subproblems to solve the original problem

Recurrences are used to analyze the computational complexity of divide-and-conquer algorithms.

Example:
Binary search is a divide-and-conquer algorithm.

  • Assume a divide-and-conquer algorithm divides a problem of size n into a sub-problems.
  • Assume each sub-problem is of size n/b.
  • Assume f(n) extra operations are required to combine the solutions of sub-problems into a solution of the original problem.
  • Let T(n) be the number of operations required to solve the problem of size n. T(n) = a T(n/b) + f(n)

In order to make the recurrence well defined T(n/b) term will actually be either T(n/b) or T(n/b).

The recurrence will also have to have initial conditions. (e.g. T(1) or T(0))

Master Theorem

There is a theorem that gives asymptotic behavior of any sequence defined by a divide-and-conquer recurrence with f(n)=c.n^d for constants c>0 and d>=0. This theorem is sometimes called the master theorem.

Theorem:
Assume a sequence is defined by a recurrence equation
T(n) = aT(n/b) + cnd for n>1,
where a>=1, b>=2, c>0 and d>=0 are constants and n/b is either n/b or n/b, then one of the following holds.

KodNest Capture45

Example :

Assume an algorithm behavior is determined using the following recurrence.Give big-Theta estimate for its complexity.
T(1) = 1
T(n) = T(n/2) + 4, for n>=2

Solution:
a=1, b=2, c=4 and d=0
So, a = b^d = 1.
By Master theorem, T(n) = theta(n^d log n) = theta(log n)

Example:

Assume an algorithm behavior is determined using the following recurrence. Give big-Theta estimate for its complexity.
T(1) = 0
T(n) = T(n/2) + T(n/2) + 1, for n>=2

Solution:
a=2, b=2, c=1 and d=0
So, a > b^d = 1.
By Master theorem, T(n) = theta(n^logba) = theta(n^log22) = theta(n).

New Report

Close