Search code examples
algorithmrecursiontreelogarithmrecurrence

How to mathematically derive Height & number of Leafs of this Recursion Tree


I was studying following tree and get stuck on deriving it's Height & number of Leafs: image from clrs book

It says the height is [logbn ]: How to derive it? (also i think height = [logbn] + 1)

How They derive number of Leafs: alogbn = nlogba

Please help me to mathematically derive Height & number of Leafs of this Recursion Tree in a very simple way.Thanks


Solution

  • Height
    The top of the tree begins with n and for every step down it is divided by b. So it goes n, n/b, n/b2,...,1. To find the height we need to find a k such that n / bk = 1 or bk = n, which gives k = logbn.

    Number of leaves
    For every step down the tree, the leaves are multiplied by a times. The number of leaves is ak, where k is the number of steps or height of the tree. The number of leaves = alogbn.