If one uses straight two-way merge sort algorithm to sort the following elements in ascending order:
then the order of these elements after second pass of the algorithm is:
View worked solution
Answer: B
In a straight two-way merge sort (also known as iterative or bottom-up merge sort), we start by considering each element as a sorted run of size . In each subsequent pass, we merge adjacent sorted runs of size to form sorted runs of size .
Let's trace the algorithm step-by-step for the given array:
Pass 1:
Merge adjacent runs of size to form sorted runs of size :
- Merge and
- Merge and
- Merge and
- Merge and
- Merge and
Array after Pass 1:
Pass 2:
Merge adjacent runs of size to form sorted runs of size :
- Merge and
- Merge and
- The remaining run has no adjacent run to merge with, so it remains as is:
Array after Pass 2:
This matches the sequence given in Option B.
Free practice · Your answers on this page are not saved.
