Enter an array separated by commas as : 16,15,15,10,1 or just press the hand icon to generate a random array then press enter or Sort button. Sorting will start and you can watch each pass as it gets sorted. When it shows green it means the two of them are being compared when red shows, it means the left number is greater than right number so it needs swapping The blue color means the number is at its correct position and thus sorted it will continue to check other numbers until it reaches end.
Merge sort was invented by John von Neumann in 1945. It is a classic divide-and-conquer algorithm that is particularly effective for large datasets and is widely used in computer science and programming.
O(n log n)
– Consistent performance across all cases.
O(n log n)
– Maintains efficient performance on
average.O(n log n)
– Efficient even in the worst-case
scenario.Space Complexity: O(n)
– Requires additional space for the temporary
arrays used in the merging process.
function mergeSort(arr):
if length(arr) <= 1:
return arr
mid = length(arr) / 2
left = mergeSort(arr[0:mid])
right = mergeSort(arr[mid:length(arr)])
return merge(left, right)
function merge(left, right):
result = []
while left and right are not empty:
if left[0] <= right[0]:
append left[0] to result
remove left[0]
else:
append right[0] to result
remove right[0]
append remaining elements of left and right to result
return result
Merge sort is a powerful and efficient sorting algorithm that consistently performs at
O(n log n)
complexity. Its stability and performance make it ideal for sorting large
datasets and is widely utilized in computer science applications.