Contradiction in Cormen regarding Insertion sort

前端 未结 3 1174
余生分开走
余生分开走 2020-12-22 00:38

In Cormen theorem 3.1 says that


For example, the best case running time of insertion sort is big-omega(n),

相关标签:
3条回答
  • 2020-12-22 01:03

    There's no contradiction, since CLRS mentioned nothing about insertion sort of being theta(N^2).

    0 讨论(0)
  • 2020-12-22 01:06

    I think you are a bit confused here.Let me clarify a few points for you.

    Running time can mean two things: the actual running time of the program, or the bounded function like theta or big-oh(so it helps to call this time complexity, in order to avoid the confusion).Hereafter we will use running time for program's actual running time, and time complexity to denote the Big-Oh/theta notation.

    To pick up Big-Oh read my answer here.

    Once you are clear with Big-Oh, the other functions fall in place easily.When we say T(n) is Omega(g(n)), we mean to the right of some point k the curve c.g(n) bounds the running time curve from below.OR in other words:

    T(n)>=c.g(n) for all n>=k, and for some constant c independent of input size.
    

    And theta notation is like saying "I am just one function, but using different constants you can make me bound the running time curve from above and from below"

    So when we say T(n) is theta(g(n)), we mean

    c1.g(n)==k

    Now we know what the functions mean, let's see where CLRS got in the confusion.

    For example, the best case running time of insertion sort is big-omega(n), whereas worst case running time of Insertion sort is Big-oh(n^2). The running time of insertion sort therefore falls between big-omega(n) and Bigoh(n^2)

    Here by running time CLRS means the actual running time T(n).It's poorly worded, and it's not your fault that you misunderstood.In fact I would go ahead and say they it's wrong.There is nothing like falls in between, a function is either in the set O(g(n)) or it isn't. So it's an error.

    Prove that the running time of an algorithm is Big-theta(g(n)) iff its worst case running time is Big-oh(g(n)) and its best case running time is big-omega(g(n))

    Here CLRS means the running time function T(n) and they want you to figure out the time complexity.

    0 讨论(0)
  • 2020-12-22 01:07

    There is no contradiction here. The question only states to prove that Big-Theta(g(n)) is asymptotically tightly bound by Big-O(g(n)) and Big-Omega(g(n)). If you prove the question, you only prove that a function runs in Big-Theta(g(n)) if and only if it runs between Big-O(g(n)) and Big-Omega(g(n)).

    The insertion sort runs from Big-Omega(n) to Big-Oh(n^2), so the running time of insertion sort CANNOT be tightly bound to Big-Theta(n^2).

    As a matter of fact, CLRS never uses Big-Theta(n^2) to tightly bound insertion sort.

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