← Back to challenges

Level Order Traversal

PythonHardloopslogicdata_structures

Instructions

Given a Binary Search Tree (BST) implementation, complete the traverse function which is present in the BST class. Here you have to perform the level-order traversal on BST which is another term for Breadth First Traversal.

Examples

traverse() ➞  [10, 4, 20, 1, 5]

      10
      /   \
    4    20
  /  \
1    5

traverse() ➞ [100, 70, 200, 34, 80, 300]

       100
       /    \
    70    200
  /    \          \
34   80      300

Notes

Make sure you don't modify the code that is already in the Code tab. Only complete the traverse() function and return an array.

python3
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.