next up previous
Next: Example: Merge Sort Up: CSE 2320: Algorithms and 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)



Copyright © 1998 The University of Texas at Arlington