Data Structures & AlgorithmsModerateProduct-company MCQ pattern
What is the time to search for a word of length L in a trie that holds n words?
- A. O(L log n)
- B. O(L)
- C. O(log n)
- D. O(n)
Correct answer: B. O(L)
The search follows one child pointer per character, so the cost depends only on the word length, not on how many words are stored. That is the main advantage of a trie over a BST of strings (O(L log n)).
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected graph has 12 vertices and the sum of the degrees of all vertices is 40. How many edges does it have?
- The preorder traversal of a BST is 8, 5, 1, 7, 10, 12. What is its postorder traversal?
- A binary tree has inorder 4 8 2 5 1 6 3 7 and preorder 1 2 4 8 5 3 6 7. What is its postorder?
- 10, 4, 7, 1, 3 are inserted in that order into an empty binary min-heap (array form, sift-up after each insert). What is the array at the…
- The bottom-up build-heap procedure (sift down from the last internal node back to the root) turns [3, 1, 6, 5, 2, 4] into a max-heap. What…
- The maximum is deleted from the max-heap [50, 30, 40, 10, 20, 35]: the last element replaces the root and is sifted down. What is the heap…