๐๐จ๐ฐ ๐๐๐ซ๐ ๐ ๐๐จ๐ซ๐ญ ๐๐จ๐ซ๐ค๐ฌ
Merge Sort is a classic Divide & Conquer algorithm.
Hereโs the idea:
- Divide โ Split the array into two halves
- Conquer โ Recursively sort both halves
- Combine โ Merge the sorted halves into one sorted array
The magic lies in the merge step, where two sorted arrays are combined efficiently in linear time.
Time Complexity: O(n log n) (always)
Quick example:
[5, 2, 4, 1] โ [5, 2] [4, 1] โ [2, 5] [1, 4] โ [1, 2, 4, 5]
โป๏ธ Repost to help others in your network