Algorithm

Getting Started with AlgorithmWhat is an Algorithm?

Characteristics of Algorithm1 Topic

Analysis Framework

Performance Analysis3 Topics

Mathematical Analysis2 Topics

Sorting AlgorithmSorting Algorithm10 Topics

Searching Algorithm6 Topics

Fundamental of Data StructuresStacks

Queues

Graphs

Trees

Sets

Dictionaries

Divide and ConquerGeneral Method

Binary Search

Recurrence Equation for Divide and Conquer

Finding the Maximum and Minimum

Merge Sort

Quick Sort

Stassenâ€™s Matrix Multiplication

Advantages and Disadvantages of Divide and Conquer

Decrease and ConquerInsertion Sort

Topological Sort

Greedy MethodGeneral Method

Coin Change Problem

Knapsack Problem

Job Sequencing with Deadlines

Minimum Cost Spanning Trees2 Topics

Single Source Shortest Paths1 Topic

Optimal Tree Problem1 Topic

Transform and Conquer Approach1 Topic

Dynamic ProgrammingGeneral Method with Examples

Multistage Graphs

Transitive Closure1 Topic

All Pairs Shortest Paths6 Topics

BacktrackingGeneral Method

NQueens Problem

Sum of Subsets problem

Graph Coloring

Hamiltonian Cycles

Branch and Bound2 Topics

0/1 Knapsack problem2 Topics

NPComplete and NPHard Problems1 Topic
Participants2253
Recurrence Equation for Divide and Conquer
Divideandconquer algorithms:
 Dividing the problem into smaller subproblems
 Solving those subproblems
 Combining the solutions for those smaller subproblems to solve the original problem
Recurrences are used to analyze the computational complexity of divideandconquer algorithms.
Example:
Binary search is a divideandconquer algorithm.
 Assume a divideandconquer algorithm divides a problem of size n into a subproblems.
 Assume each subproblem is of size n/b.
 Assume f(n) extra operations are required to combine the solutions of subproblems 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 divideandconquer 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.
Example :
Assume an algorithm behavior is determined using the following recurrence.Give bigTheta 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 bigTheta 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).