What is a time complexity for finding the total length of all string on all edges of a tree?

Category: QuestionsWhat is a time complexity for finding the total length of all string on all edges of a tree?
Editor">Editor Staff asked 1 month ago

What is a time complexity for finding the total length of all string on all edges of a tree?
 
(a) Ɵ (n)
 
(b) Ɵ (n!)
 
(c) Ɵ (1)
 
(d) O (n^2)
 
This is a very interesting question from Suffix tree topic in chapter Trie of Data Structures & Algorithms I
 
The question was posed to me by my college professor while I was bunking the class.

1 Answers
Editor">Editor Staff answered 1 month ago

Correct choice is (d) O (n^2)
 
The best I can explain: To check if a substring is present in a string of a length of n, the time complexity for such operation is found to be O (n). The time complexity for finding the total length of all string on all edges of a tree is O (n^2).