Using recurrence tree, solve the recurrence T(n) = T(n − 1) + O(n)

Viewed 39

Please Explain it.Using recurrence tree, solve the recurrence T(n) = T(n − 1) + O(n)

1 Answers

You build the recurrence tree by repeatedly expanding the term on the right side. This tree is actually just a chain, as each node in that tree only has one child:

                         O(n)
                          |
                         O(n-1)
                          |
                         O(n-2)
                          |
                          ...
                 

The height of this tree is n, and the sum of the terms is

      Σi=1..nO(i)

...which is:

      O( Σi=1..ni )

...which is (cf. triangular numbers):

      O( n(n+1)/2 )

...which is:

      O(n2).

Related