AlgoPrecision

Tree Visualizer

Binary Search Trees

Build a BST, trace search decisions, and step through inorder traversal with highlighted nodes and synced pseudocode.

O(n)
4218672991543673

Step Note

Start BFS level-order traversal with the root in a queue.

Details
function levelOrder(root: Node | null) {
  const queue = root ? [root] : []
  while (queue.length > 0) {
    const node = queue.shift()
    visit(node)
    if (node.left) queue.push(node.left)
    if (node.right) queue.push(node.right)
  }
}