Please Explain it.Using recurrence tree, solve the recurrence T(n) = T(n − 1) + O(n)
Please Explain it.Using recurrence tree, solve the recurrence T(n) = T(n − 1) + O(n)
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).