IntermediateAbout 20 min

    Binary Search Tree (BST)

    Read the full article on Substack

    6 min read.

    A hierarchical data structure where each node has at most two children. For any node, the left child is smaller and the right child is larger, allowing for efficient O(log n) average-case search, insertion, and deletion (this degrades to O(n) on an unbalanced tree).

    Empty tree

    Empty tree. Run the operations in order.

    1/26

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    In-order traversal

    Sequence

    Keys 50, 30, 70, 20, 40 were inserted into an empty BST. Order the keys as an in-order traversal visits them.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    What is the worst-case time complexity of searching in a BST?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going