Difficulty: Medium
Correct Answer: It repeatedly merges two sorted halves obtained by recursively dividing the array into halves until a single sorted array remains
Explanation:
Introduction / Context:
Merge sort is an efficient, stable, divide and conquer sorting algorithm commonly implemented in C when predictable O(n log n) performance is required. It is especially useful for linked lists and external sorting. Understanding the high level steps of merge sort is a frequent topic in data structures examinations.
Given Data / Assumptions:
Concept / Approach:
Merge sort works by repeatedly dividing the array into two halves, sorting each half recursively, and then merging the two sorted halves into a single sorted array. The merge step is key: given two sorted subarrays, it produces one larger sorted array by repeatedly selecting the smaller of the front elements and copying it to the result. Because the array is divided in half at each recursive level, the depth of the recursion is O(log n), and each level performs O(n) work during merging, leading to an overall time complexity of O(n log n).
Step-by-Step Solution:
Step 1: If the array segment has zero or one element, it is already sorted and can be returned as is.Step 2: Otherwise, find the middle index and split the array into a left half and a right half.Step 3: Recursively apply merge sort to the left half to produce a sorted left array.Step 4: Recursively apply merge sort to the right half to produce a sorted right array.Step 5: Merge the two sorted halves by repeatedly taking the smaller of the current elements from each half and copying it into a temporary array, then copying the temporary array back.
Verification / Alternative check:
On a small example such as [4, 1, 3, 2], merge sort splits into [4, 1] and [3, 2], sorts each to [1, 4] and [2, 3], and then merges them to [1, 2, 3, 4]. This illustrates the divide, sort, and merge pattern described in option A.
Why Other Options Are Wrong:
Option B describes bubble sort, which uses adjacent swaps.Option C is selection sort, which picks the smallest element each pass.Option D is insertion sort, which inserts elements into a growing sorted prefix.
Common Pitfalls:
Learners sometimes think merge sort performs merging at every step without recursion, or confuse it with quick sort. The distinguishing feature of merge sort is explicit merging of two already sorted halves after recursive division.
Final Answer:
The correct description is It repeatedly merges two sorted halves obtained by recursively dividing the array into halves until a single sorted array remains.
Discussion & Comments