liveBook · Manning

Binary search tree

As explained in Learn C++ by Example

A binary search tree is a binary tree whose nodes are ordered so smaller elements lie to the left and larger elements lie to the right.

A binary search tree stores nodes with at most two child branches. Ordering places smaller elements on the left and larger elements on the right, allowing searches to discard half the tree at each step. section 7.2.1

Searching map keys

A map can store {1:a}, {3:c}, and {5:e} in a balanced binary search tree. Searching for {2:b} starts at {3:c}, moves left to {1:a}, and stops at the leaf. Balanced search, insertion, and removal take logarithmic complexity, O(log(n)). section 7.2.1

Figure 7.2 Three elements in a balanced binary search tree: nodes with smaller keys go on the left and larger keys on the right.
CH07_F02_Buontempo

Use the tree diagram to see how smaller keys occupy the left side and larger keys occupy the right side. section 7.2.1

How Learn C++ by Example covers it

How deep it goes
Defines nodes, branches, ordering, balancing, and logarithmic operations through a small map example.
Examples
Uses map pairs {1:a}, {3:c}, and {5:e}, then traces a search for {2:b}.
What it assumes
Assumes familiarity with map elements and vector scanning while defining binary-tree terminology directly.
What you can do after
Understand why balanced ordered storage reduces map search, insertion, and removal from linear to logarithmic complexity.
How it connects
Connects binary trees with map, keys, balanced trees, vector search, and logarithmic complexity.

Also explained in

Compare how 5 books explain binary search tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.