Merge
Merge
Merging:
• Merge the two sorted halves into one sorted array.
• comparing the elements of each half and placing the smaller
element into the result array.
Initial Array: [38, 27, 43, 3, 9, 82, 10]
Divide: Split the array into two halves. [38, 27, 43] and [3, 9, 82, 10]
Conquer: Recursively sort each half.
Split into [38] and [27, 43]
•
Compare 27 and 3: 3 is smaller, so it goes into the result array.
•Compare 27 and 9: 9 is smaller, so it goes into the result array.
•
Compare 27 and 10: 10 is smaller, so it goes into the result array.
•
Compare 27 and 27: 27 is smaller, so it goes into the result array.
•
Compare 38 and 82: 38 is smaller, so it goes into the result array.
•82 is the only element left, so it goes into the result array.