A lesson from the data structures and algorithms bootcamp. About a 14 minute read.
A tree is a branching structure with a root, its children, their children, and so on. It is the structure worth learning properly, because it is where recursion stops being a trick and starts being the obvious way to write things down. Heaps are trees. Tries are trees. A graph search on a graph with no cycles is a tree walk. Get this one and four other topics get easier.
A tree is a set of nodes joined by edges with no cycles and one distinguished node called the root. Every other node has exactly one parent, which is what rules out cycles, and any number of children. Nodes with no children are leaves. In a BINARY tree each node has at most two children, and they are ordered: a left child and a right child are different things even when only one of them exists. That ordering is why a binary tree with one child on the left is not the same tree as one with that child on the right, and it is the source of about half of all off-by-one tree bugs.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 536 practice puzzles