Understanding merge sort algorithm
The strategy from the earlier example could be used to create an algorithm. To explain this algorithm, we will take an array as an input list, but the same algorithm can be applied to any list data structure.
Algorithm
The merge sort algorithm begins by dividing the input array into two roughly equal-sized subarrays. This division continues recursively, breaking the array into smaller and smaller segments, until each subarray contains only a single element. At this stage, each subarray is trivially sorted, as a single element is inherently in order.
Liking the course? Check our discounted plans to continue learning.