(i) Define a recurrence relation using Divide and Conquer technique and describe its
elements
(ii) Solve the following recurrence relation using Recurrence Tree Method.
T(ğ‘›) = {1 ğ‘‡(ğ‘›/2 ) + n
ğ‘–ğ‘“ n=1
ğ‘–ğ‘“ n> 1
Show all the steps.
i)
Divide
the problem into subproblems that are smaller instances of the same problem.
Conquer
the subproblems by solving them recursively. If the subproblems are small enough, solve them trivially or by "brute force."
Combine
the subproblem solutions to give a solution to the original problem.
Recurrences
The recursive nature of D&C leads to recurrences, or functions defined in terms of:
ii)
Step-01:
The given recurrence relation shows-
The given recurrence relation shows-
Step-02:
 Determine cost of each level-
Step-03:
 Determine total number of levels in the recursion tree-
 Continuing in similar manner, we have-
Size of sub-problem at level-i = n/2i
Suppose at level-x (last level), size of sub-problem becomes 1. Then:
n / 2x = 1
2x = n
Taking log on both sides, we get-
xlog2 = logn
x = log2n
 ∴ Total number of levels in the recursion tree = log2n + 1
Step-04:
 Determine number of nodes in the last level-
 Continuing in similar manner, we have-
Level-log2n has 2log2n nodes i.e. n nodes
Step-05:
 Determine cost of last level-
Cost of last level = n x T(1) = θ(n)
Â
Step-06:
 Add costs of all the levels of the recursion tree and simplify the expression so obtained in terms of asymptotic notation:
for n > 1 :
T(n) = = n x log2n + θ (n)= nlog2n + θ (n)= θ (nlog2n)
for n = 1 :
T(1) = θ (1)
Comments
Leave a comment