Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Visualizer › Trees

Binary Search Tree Search

In a BST every key on the left is smaller and every key on the right is bigger, so each comparison discards one subtree.

How it works

Complexity

Code (Python)

def search(node, target):
    while node:
        if target == node.val:
            return node
        node = node.left if target < node.val else node.right
    return None

Practise: Trees problems