The complexity of averaging the sorting algorithm

I have a treeort function that performs two different tasks, each with its own time complexity. I understood avg. the time complexity of two tasks, but how to find the overall complexity of the algorithm.

For example, the algorithm accepts a random list of "n" keys x:

Sort(x):
    Insert(x):
        #Time complexity of O(nLog(n))
    Traverse(x):
        #Time complexity of O(n)

I just add two difficulties together to give me O (n + nLog (n)), or I take the dominant task (in this case Insert) and end up with the overall complexity of O (nLog (n))

+3
source share
3 answers

( Insert) O (nLog (n))
. n O(n + nLog(n)) sum . , n .

+2

, ,

O((n) + (n log(n)) = O(n + n log(n))
                  = O(n (log(n) + 1))
                  = O(n log(n))
+7

.

, , n s.

, , , , , ..

, , , .

(Returning to the original questions, if you use the base 2 logarithms, the n=1048576difference between n+n*lognand n*lognis about 5%, which is probably not worth the bother.)

+2
source

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


All Articles