IntermediateAbout 20 min

    B-Tree Indexes

    Read the full article on Substack

    7 min read.

    An interactive visualization showing how databases use B-Trees to retrieve data in O(log n) time without scanning the full table.

    Think of it this way: A B-Tree index is like the index at the back of a textbook. Instead of reading every page (Full Table Scan) to find a topic, you jump straight to the exact page number.

    B-tree index0 page reads
    50
    20
    35
    5
    10
    15
    25
    30
    40
    45
    70
    85
    55
    60
    65
    75
    80
    90
    95
    Full table scan0 of 19 rows
    5
    10
    15
    20
    25
    30
    35
    40
    45
    50
    55
    60
    65
    70
    75
    80
    85
    90
    95
    Find 45. The index walks down the tree; the scan reads rows in order.

    Check your understanding

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

    Look up a key

    Sequence

    Order an index lookup through a B-tree.

    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

    Which operation is highly efficient in a B+ Tree index but very slow using a Hash index?

    Done with this lesson?

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

    Keep going