3

Can anyone explain me this sentence please?

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist).

Link: Arrays.sort(Object[] arr)

I know how Merge works, but I still don't understand well. Thank you.

2 Answers 2

4

Mergesort recursively merges sorted sublists. If the current sublists eligible for merging contain no overlapping elements, there's no need to merge them. The merge operation would be skipped.

Example:

List A
1 4 8 9

List B
10 12 14 19

There's no need to go through the process of comparing these lists because 9 is the largest element of A and 10 (the first element of B) is larger than the largest element of A. The result would just be the concatenation of A and B.

All the document is saying is that they take a shortcut if comprehensive processing is unnecessary.

Sign up to request clarification or add additional context in comments.

Comments

0

Let's say you are doing a merge sort and are about to merge your two sorted sublists, [1, 3, 4] and [2, 5, 6]. Then you must run your merge algorithm to interleave the two halves into the whole [1, 2, 3, 4, 5, 6].

[1] + [2] + [3, 4] + [5, 6] = [1, 2, 3, 4, 5, 6]

But let's say after you've sorted the two halves you have [1, 2, 3] and [4, 5, 6]. The highest element in the low sublist (3) is less than the lowest element in the high sublist (4). There's no need to merge the two sublists; you can simply concatenate them together.

[1, 2, 3] + [4, 5, 6] = [1, 2, 3, 4, 5, 6]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.