written 5.8 years ago by |
In this method, we draw a recurrence tree and calculate the time taken by every level of tree. Finally, we sum the work done at all levels. To draw the recurrence tree, we start from the given recurrence and keep drawing till we find a pattern among levels. The pattern is typically a arithmetic or geometric series. For example consider the recurrence relation
T(n) = T(n/4) + T(n/2) + cn$^{2}$
If we further break down the expression T(n/4) and T(n/2),we get following recursion tree.
Breaking down further gives us following
To know the value of T(n), we need to calculate sum of tree nodes level by level. If we sum the above tree level by level, we get the following series
T(n) = c(n^2 + 5(n^2)/16 + 25(n^2)/256) + ....
The above series is geometrical progression with ratio 5/16. To get an upper bound, we can sum the infinite series. We get the sum as (n 2 )/(1 - 5/16) which is O(n 2 )