Question 71
HardWith binary lifting, what is the cost of answering one LCA query after O(n log n) preprocessing?
- A.
O(1)
- B.
O(√n)
- C.
O(log n)
- D.
O(n)
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
With binary lifting, what is the cost of answering one LCA query after O(n log n) preprocessing?
O(1)
O(√n)
O(log n)
O(n)
Sign up free to see the answer and a step-by-step explanation.
Which traversal of a binary tree visits nodes in the order they would be printed on a line from left to right?
Preorder
Inorder
Postorder
Level order
Sign up free to see the answer and a step-by-step explanation.
Inorder: 4 2 5 1 6 3 7. Postorder: 4 5 2 6 7 3 1. What is the preorder?
4 2 1 5 6 3 7
1 3 7 6 2 5 4
1 2 3 4 5 6 7
1 2 4 5 3 6 7
Sign up free to see the answer and a step-by-step explanation.
What is the diameter of a binary tree?
The width of the widest level
The number of edges on the longest path between any two nodes
The height of the root
The number of leaves
Sign up free to see the answer and a step-by-step explanation.
Morris inorder traversal uses O(1) extra space. What does it temporarily modify?
Left pointers of leaves
Nothing
Node values
Right pointers of inorder predecessors, creating threads back to their successors
Sign up free to see the answer and a step-by-step explanation.
A segment tree over n elements answers range-sum queries in O(log n). How many nodes does it have?
About 2n (at most 4n with array storage)
log n
n
n²
Sign up free to see the answer and a step-by-step explanation.
What is the maximum width (number of nodes on one level) of a complete binary tree with 100 nodes?
32
37
50
64
Sign up free to see the answer and a step-by-step explanation.
A complete binary tree has 1,000 nodes. How many of them are leaves?
501
500
512
499
Sign up free to see the answer and a step-by-step explanation.
Which traversal can be used to check whether two trees are mirror images in O(n)?
A simultaneous traversal comparing left of one with right of the other
Sorting both
Only inorder
Only level order
Sign up free to see the answer and a step-by-step explanation.
In an n-ary tree stored as left-child right-sibling, what does the right pointer mean?
The parent
Nothing
The next sibling
The rightmost child
Sign up free to see the answer and a step-by-step explanation.