Time complexity to find the diameter of a binary tree having n nodes is
2023
Time complexity to find the diameter of a binary tree having n nodes is
Answer: B. O(n) — The optimal algorithm to find the diameter of a binary tree traverses each node exactly once using post-order traversal. It calculates subtree heights while…
- A.
O(n2)
- B.
O(n)
- C.
O(1)
- D.
O(logn)
Attempted by 888 students.
Show answer & explanation
Correct answer: B
The optimal algorithm to find the diameter of a binary tree traverses each node exactly once using post-order traversal. It calculates subtree heights while updating the maximum diameter found, resulting in a linear time complexity of O(n).
Explore the full course: Iocl Engineers Officers Grade A Paper 2
Loading lesson…