Cosmic complexity of quick sorting

I found out that the complexity of the quick-sort space without the Sedgewick trick to eliminate tail recursion is O (n). But if we track calls on the stack that are stored, these are O (log n) steps for any call, as shown in the figure.Call stack when calculating values ​​for leaves

On the image

when calculating the value (1,1), the calls are saved [(1,8), (1,4), (1,2)],

when calculating the value (3.3), calls are saved [(1,8), (1,4), (3,4)], etc.

which make up only O (log n) space at time ant. Then does the complexity become O (n)?

+4
source share
1 answer

, , , . O (log n), , , O (log n) .

, quicksort? , , ? :

    size n
       \
       size n-1
         \
         size n-2
           \
            ...
             \
              1

& Theta; (n), , , quicksort & Theta; (n), .

+5

Source: https://habr.com/ru/post/1648549/


All Articles