Module 01 · DSA · The toolbox · about 20 min to read
Continue where you left off ×
Trees (BST, balancing, heaps, tries)
Trees · Open board
Six numbers arranged as a chart: one at the top, two below it, three below those, and nothing loops back. The ordered counterpart to Hashing ‘s buckets, and the shape behind the B-trees in Storage Engines .
Before you start. You already have the hash table from Hashing : instant lookup, no memory of order. This lesson is the opposite trade, a shape that remembers order, at the cost of one extra comparison per step.
The idea in 30 seconds
Add “smaller left, bigger right” and you get a binary search tree: each comparison throws away half of what’s left, O(log n).
Feed a plain BST already-sorted data and it collapses into one long chain. Self-balancing trees exist to stop that.
Add “parent below child” instead and you get a heap: no left/right order, but the smallest thing is always one lookup away, in a plain array.
Add “one letter per node” and you get a trie: lookup and prefix search that only care about spelling, not how many words you’re holding.
Read the story
Lesson 6 of 96 in DSA
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 1857: a mathematician names the shape 1875: the same shape, counting molecules 1960: the shape learns a rule The catch: the wrong order turns the tree into a line 1962: a fix that never lets it lean 1964: a different question 1960, the same year: a shape that spells One shape, three rules Binary search tree, in numbers Heap, in numbers Trie, in numbers The structure-choice map Classic pitfalls Terms it explains: tree, root, leaves, node, binary search tree, O(log n), heap, priority queue, trie, O(h), in-order, Traversals, pre-order, post-order, level-order, Data Systems callback, B-tree, disk, peek-min O(1), insert O(log n), extract-min O(log n), not sorted, steps, chars/node, question you ask most, base case, balanced, binary tree, BST, complete tree, height h, rotation, self-balancing BST (AVL / red-black), sift up/down, traversal.
Review DSA
Mark as read Saved in this browser, and to your account when you sign in.