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!
source
share