next up previous
Next: Example: Merge Sort Up: l1 Previous: Example: Merge Sort

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: Example: Merge Sort Up: l1 Previous: Example: Merge Sort