algorithm
algorithm
Merge Sort
Merge:
o Compares elements from each subarray and places the smaller element into a
temporary array.
o Ensures that elements with equal values maintain their original order.
Time Complexity:
Space Complexity: O(n) due to the temporary array used for merging.
Stability:
Consistent Performance: O(n log n) time complexity regardless of the initial order of the
input data.
Suitable for Large Datasets: Efficiently handles large arrays due to its divide-and-conquer
approach.
Note: While other sorting algorithms like Heap Sort also have O(n log n) time complexity,
Merge Sort generally offers better performance in practice, especially for large datasets.