Formula for determining number of comparisons in a sort?

I'm curious if there's a formula/rule to find the total number of comparisons done in a sorting algorithm, particularly merge sort, selection sort, and insertion sort. I'm pretty sure with selection sort the rule is n(n-1)/2where n is the number of elements being sorted. I thought the same was the case for an insertion sort but apparently that's not true according to a practice Java test I took (with a list of 6 items the insertion sort makes 14 comparisons, according to the answer key, and 15 comparisons with a...

Read More »

By: StackOverFlow - 7 days ago

Related Posts