independently (Conquer). Then the two sorted halves are merged to a sorted sequence (Combine) (Figure 1). Figure 1: Mergesort(n) The following procedure mergesort sorts a sequence a from index lo to index hi. void mergesort(int lo, int hi) { if (lo<hi) { int m=(lo+hi)/2; mergesort(lo, m); mergesort(m+1, hi); m, hi); } } index m in the middle between lo and hi is determined. Then the first part of the sequence (from lo to m) and the second part (from m+1 to hi) are sorted by recursive calls of mergesort. Then the two sorted halves are merged by procedure
independently (Conquer). Then the two sorted halves are merged to a sorted sequence (Combine) (Figure 1). Figure 1: Mergesort(n) The following procedure mergesort sorts a sequence a from index lo to index hi. void mergesort(int lo, int hi) { if (lo<hi) { int m=(lo+hi)/2; mergesort(lo, m); mergesort(m+1, hi); m, hi); } } index m in the middle between lo and hi is determined. Then the first part of the sequence (from lo to m) and the second part (from m+1 to hi) are sorted by recursive calls of mergesort. Then the two sorted halves are merged by procedure