As I read a book about "Algorithm Analysis", I came across count_sort
Algorithm.
However, I have read elsewhere that "Quick Sort/ Merge Sort" are the best and the most efficient sorting algorithms. I found this confusing because the complexity of count_sort
is O(n+k)
, which is better than Mergesort and Quicksort which are O(n ln n).
My question:
What is the problem with this sorting Algorithm?
What are the best sorting Algorithms?
def count_sort(seq): b, c = [], defaultdict(list) for x in seq: c[x].append(x) for k in range(min(c), max(c)+1): b.extend(c[k]) return b
defaultdict
is implemented?<
to order them by. Counting sort can only be "better" when it is applicable