What is the time complexity for the initialization of top tree?

Category: QuestionsWhat is the time complexity for the initialization of top tree?
Editor">Editor Staff asked 1 month ago

What is the time complexity for the initialization of top tree?
 
(a) O (n)
 
(b) O (n^2)
 
(c) O (log n)
 
(d) O (n!)
 
Question is taken from Binary Trees in section Binary Trees of Data Structures & Algorithms I
 
The question was asked during an interview for a job.

1 Answers
Editor">Editor Staff answered 1 month ago

Right answer is (a) O (n)
 
Best explanation: Generally, trees have weight on its edges. Also there is one to one correspondence of the edges with the top trees. Therefore, top trees can be initialized in O (n) time.