...

/

Linear-time Merging

Linear-time Merging

We'll cover the following...

The remaining piece of merge sort is the merge function, which merges two adjacent sorted subarrays, array[pq]array[p \cdots q] and array[q+1r]array[q+1 \cdots r] into a single sorted subarray in array[pr]array[p \cdots r]. We’ll see how to construct this function so that it’s as efficient as possible. Let’s say that the two subarrays have a total of nn elements. We have to examine each of the elements in order to merge them together, and so the best we can hope for would be a merging time of Θ(n)\Theta(n). Indeed, we’ll see how to merge a total of nn ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy