next up previous
Next: Up: Previous:

Example: Merge Sort

Recursion bottoms out when subproblem contains only one element (p = r)

MergeSort(A,p,r)
1
$\;\;\;\;\;$if p < r
2
$\;\;\;\;\;$then q = $\lfloor$ (p+r)/2 $\rfloor$
3
$\;\;\;\;\;$ $\;\;\;\;\;$MergeSort(A,p,q)
4
$\;\;\;\;\;$ $\;\;\;\;\;$MergeSort(A,q+1,r)
5
$\;\;\;\;\;$ $\;\;\;\;\;$Merge(A,p,q,r)


next up previous
Next: Up: Previous: