Skip to content

Commit 03d422b

Browse files
committed
added Performance analysis
1 parent 32a66ca commit 03d422b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Mergesort/README.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ This method is quite straightforward:
120120

121121
4. If control exits from the previous while loop, it means that either `leftPile` or `rightPile` has it's contents completely merged into the `orderedPile`. At this point, you no longer need to do comparisons. Just append the rest of the contents of the other array until there's no more to append.
122122

123+
124+
Most implementations of Mergesort produce a *stable* sort.
125+
126+
*"A sort is stable when elements that have identical sort keys remain in the same relative order after sorting. This is not important for simple values such as numbers or strings, but it is important when sorting more complex objects. In the example above, if two objects have the same `priority`, regardless of the values of their other properties, those two objects don't get swapped around."* Matthijs Hollemans
127+
128+
### Performance
129+
130+
The speed of mergesort is dependent on the size of the array it needs to sort. Whether or not the initial array is sorted already doesn't affect the speed of the sort since you'll be doing the same amount splits and comparisons irregardless of the initial order of the elements.
131+
132+
Therefore, the time complexity for the best, worst, and average case will always be O(n log n).
133+
123134
## See Also
124135

125136
See also [Wikipedia](https://en.wikipedia.org/wiki/Merge_sort)

0 commit comments

Comments
 (0)