Recursion Trees: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 5: Line 5:
=Overview=
=Overview=
The idea behind the recursion tree method is to write out the work done by the recursive algorithm in a tree structure, where the children of a given node represent the recursive calls made by that node. The tree will facilitate counting the overall work done by the algorithm and facilitate the analysis.
The idea behind the recursion tree method is to write out the work done by the recursive algorithm in a tree structure, where the children of a given node represent the recursive calls made by that node. The tree will facilitate counting the overall work done by the algorithm and facilitate the analysis.
The bottom-most level is log<sub>2</sub>n because the problem size is decreased by a factor of 2 at each level of recursion, and the bottom-most level problem size is 1, so:
<font size=-1>
1 = n/2<sup>m</sup> → n = 2<sup>m</sup> → m = log<sub>2</sub>n
</font>
The analysis reveals that at the level j of the recursion there are 2<sup>j</sup> subproblems and each subproblem has a size of n/2<sup>j</sup>.


=Recursion Tree Example for Merge Sort=
=Recursion Tree Example for Merge Sort=

Revision as of 16:50, 21 September 2021

Internal

Overview

The idea behind the recursion tree method is to write out the work done by the recursive algorithm in a tree structure, where the children of a given node represent the recursive calls made by that node. The tree will facilitate counting the overall work done by the algorithm and facilitate the analysis.

Recursion Tree Example for Merge Sort

TODO

Redo after class.

The method consists in converting the recurrence into graphical tree representation whose nodes represent costs incurred at various level of the recursion. After we lay out the tree, we sum the costs within each level of the tree to obtain a set of per-level costs, then we sum all the per-level costs to determine the total cost of the recursion. The bound such guessed can be proven with the substitution method. Examples on how to build recursion trees are available in CLRS page 37 and page 88.

[Next]