What is the time complexity of level-order traversal of a binary tree?

Practice Questions

Q1
What is the time complexity of level-order traversal of a binary tree?
  1. O(n)
  2. O(log n)
  3. O(n log n)
  4. O(1)

Questions & Step-by-Step Solutions

What is the time complexity of level-order traversal of a binary tree?
  • Step 1: Understand what level-order traversal means. It means visiting each level of the binary tree from top to bottom and left to right.
  • Step 2: Realize that in a binary tree, there are 'n' nodes in total.
  • Step 3: During level-order traversal, we visit each of these 'n' nodes exactly once.
  • Step 4: Since we visit each node once, the time taken is proportional to the number of nodes.
  • Step 5: Therefore, the time complexity is O(n), where 'n' is the number of nodes in the binary tree.
No concepts available.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely