Skip to content

Commit a4e69bb

Browse files
committed
Added Mergesort description
1 parent 63fd8d3 commit a4e69bb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compare-sorting-algorithms.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ private static int Partition(int[] array, int start, int end, bool printUpdates)
448448
return partitionIndex;
449449
}
450450

451+
/* Sorts an array using Mergesort algorithm, along with Merge().
452+
* Splits the array into two halves, then recursively calls Mergesort on each half.
453+
* Base case is when there's the array only contains one element (i.e. it must be sorted).
454+
* Sorted arrays are then Merged() to create larger sorted arrays.
455+
* Time complexity: Worst = n logn, Best = n logn, Average = n logn.
456+
* Space complexity: O(n) (note it's usually O(logn) for a linked list version)
457+
*/
451458
private static void MergeSort(int[] array, bool printUpdates)
452459
{
453460
int n = array.Length;

0 commit comments

Comments
 (0)