Lowed bound for sorting by comparison

后端 未结 3 1790
无人共我
无人共我 2021-01-13 00:08

Today I was reading a great article from Julienne Walker about sorting - Eternally Confuzzled - The Art of Sorting and one thing caught my eye. I don\'t quite understand the

相关标签:
3条回答
  • 2021-01-13 00:33

    You didn't miss anything from CompSci class. What you missed was math class. The Wikipedia page for Stirling's Approximation shows that log n! is asymptotically n log n + lower order terms.

    0 讨论(0)
  • 2021-01-13 00:35
    • N! < N^N
    • ∴ log N! < log (N^N)
    • ∴ log N! <N * log N

    With this, you can prove θ(log N!) = O(N log N). Proving the same for Ω is left as an exercise for the reader, or a question for mathematics stackexchange or theoretical computer science stackexchange.

    0 讨论(0)
  • 2021-01-13 00:35

    My favorite proof of this is very elementary.

    N! = 1 * 2 * .. * N - 1 * N

    We can can a very easy lower bound by pretending the first half of those products don't exist, and then that the second half are all just N/2.

    (N/2)^(N/2) <= N!

    log((N/2)^(N/2) = N/2 * log(N/2) = N/2 * (log(N) - 1) = O(n log n)

    So even when you take only the second half of the expression, and pretend that all those factors are no bigger than N/2, you are still in O(n log n) territory for a lower bound, and this is super elementary. I could convince an average high school student of this. I can't even derive Stirling's formula by myself.

    0 讨论(0)
提交回复
热议问题