sorting - How can we conclude to this cost? -
I want to find the following algorithms of merge sort:
merge (A , P, Q, R) N1 = qp + 1; N2 = rq; We create scenes: L [1 .... n 1 + 1] and R [1 .... n 2 + 1] I -L [i] i & lt; -i + 1 and a [k] & lt; -R [J.] J & LT; -J + 1 Mergeort (A, P, R) if P & lt; R then Q & LT; MergeSort (A, P, Q) MergeJort (A, Q) + 1, R) Merge (A, P, Q, R)
According to my textbook, cost t (n) = 2 t (n / 2) + cn, n> 1 and t (n) = c, n = 1 but i really do not Understand how we can end this relationship.
Can you explain this to me?
t (n) = 2t (n / 2) // two reucsive calls, each
We'll call it the value of the array + cn // merge in linear time in linear time
T (n) = O (nlogn) T (n) = 2T (n / 2) + cn = 4T (n / 4) + cn + cn = 8t (n / 8) + cn + cn + cn = ... (log time later) = n * T (n / n) + cn + cn + cn + ... + cn (where cn logs (n ) Appears bar) = c * logn * n
Comments
Post a Comment