Why is O (N Log N) creating a binary search tree?

Exam preparation. This is not a homework question.

I realized that the worst case is O (N ^ 2) for building a BST. (each comparison of insert req N-1, you summarize all comparisons 0 + 1 + ... + N-1 ~ N ^ 2). This refers to skew BST.

The insert for a (balanced) BST is O (log N), so why the best option is O (N logN) to build a tree?

My guess is best guessed - since a single insert is log N, and summing all the inserts somehow gives us N log.

Thank!

+3
source share
1 answer

:) - O (log N). N - log N, N . N . , N * logN.

+8

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


All Articles