Professional Documents
Culture Documents
Quick sort
• It occurs only if each partition divides the list into two equal size sublists.
• T(n)=2T(n/2)+cn =O(nlog n)
Quick Sort (A worst/bad case):
T(n)=T(n-1)+cn=O(n2)
Worst-Case Analysis:
The pivot is the smallest element, all the time. Then i = 0, and if we ignore T(0) = 1, which is
insignificant, the recurrence is T(N) = T(N − 1) + cN, N > 1
...
To see that this is the worst possible case, note that the total cost of all the partitions in
recursive calls at depth d must be at most N. Since the recursion depth is at most N, this gives an O(N^2)
worst-case bound for quicksort.
Merge sort Analysis
If the time for the merging operations is proportional to ‘n’, then the computing time for merge sort is
described by the recurrence relation.
Where,
Merge sort divides array in half and calls itself on the two halves. After returning, it merges both halves
using a temporary array
. Quick-Sort
. Merge-sort