Merge Sort - Recursion Tree

So, I studied sorting algorithms.

I am stuck in finding the complexity of sorting a merge.

Can someone please explain to me how h = 1 + lg (n)

enter image description here

+4
source share
1 answer

If you continue to divide n by 2, you will eventually reach 1.
Namely, the logarithm of the logarithm requires log 2 (n) divisions by 2.

Each time we divide by 2, we add a new level to the recursion tree.
Add this to the root level (which does not require any divisions), and we have a common log of 2 (n) + 1.


. , , , T (2n) - 2 T (n) = 2 c n.

n = 2 k T (2 k + 1) - 2 T (2 k) = 2 c 2 .

. U (k) = T (2 k)/(2 c).

U (k + 1) - 2 U (k) = 2 k , U '(k) = U (k + 1) - U (k ):

U '(k) - U (k) = 2 k

k , , , U ' U.

: - , , , ( ).

, U (k) , T.

+5

Source: https://habr.com/ru/post/1545528/


All Articles