merge_sort_analysis
merge_sort_analysis
Insertion Sort
- Worst case time complexity: O(n^2)
- Best case time complexity: O(n) (when the list is already sorted)
- Average case time complexity: O(n^2)
Insertion sort also has a quadratic time complexity, making it less efficient for
large lists
Merge Sort
- Worst case time complexity: O(n log n)
- Best case time complexity: O(n log n)
- Average case time complexity: o(n log n)
Merge sort has a time complexity of O(n log n) in all cases. It is more efficient
for larger lists and is a stable, divide-and-conquer sorting algorithm
Summary
When comparing the time complexities , merge sort is more efficient than bubble
sort and insertion sort, especially for larger datasets. Merge sort consistently
has a time complexity
of O(n log n), while bubble sort and insertion sort have quadratic time
complexities (O(n^2)) in the worst and average cases. Therefore, for sorting larger
sets of data, merge sort
is the preferred choice due to its better time complexity