Binary trees come in a few named shapes. The names show up constantly — in interview questions ("check whether a tree is complete"), in data structures (a heap is a complete tree), and in complexity arguments ("in a balanced tree this is O(log n)"). Here are the ones worth knowing, and the counting facts that come with them.
And one that is about values, not shape: a binary search tree keeps everything in a node's left subtree smaller and everything in its right subtree bigger (previous lesson). A BST can have any of the shapes above — and its speed depends on which one.
Members only · free account
The rest of this lesson, with 4 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson