I "used" to understand Quicksort, and now.. I've gotten myself confused. I know I'm missing something very obvious here and no doubt that Quicksort is O(nlogn)
, and the n
part is easy to see (since we need to use n
comparisons on each level to move the elements based on the pivot accordingly, but how is the splitting logn
? Shouldn' it be n-1
? Example:
1, 2, 3, 4
1, 2 3, 4
1 2 3 4
We split 1, 2, 3, 4
into 1, 2
and 3, 4
on the first level, that's one split. Then in the second level we split 1, 2
into 1 and 2
and 3, 4
into 3 and 4
, that's 2 splits, so 3 splits in total, so n-1 splits?
I don't think this is a duplicate because I am assuming equal splits of the quick-sort algorithm (or rather a generic equal split of a divide and conquer algorithm) What I'm asking is the intuitive explanations why the splitting is log(n)
despite the fact when you count up the actual number of splitting calls it is n-1
in any generic divide and conquer alogirhtm