Trees (chapter 17)
Like linked lists, trees are implemented with pointers.
In a linked list, each node has a pointer to the element that comes after it in the list
In a tree, each node has pointers to all of the nodes that come below it, called its children.
Nodes that have no children are called the leaves of the tree.
Binary trees
In some trees, all nodes have the same number of children.
In other trees, the number of children may vary
Binary trees are trees in which all non-leaf nodes have either one of two children
Binary trees are useful for storing information that will be accessed via a set of binary decisions
Morse code
Morse code is a system for representing the alphabet in which each letter of the alphabet is represented by a short sequence of dots and dashes.
To find out what letter is represented by a particular sequence of dots and dashes, you just start at the top of the tree and follow the links indicated by the sequence. Wherever you stop, that's the letter.
Binary search trees
Binary trees can also be used to hold dynamic lists of numbers.
Adding to a binary tree
Deleting from a binary tree
Searching for an element in a binary tree
Recursion in binary trees
Subtrees
Binary tree code
Tree search algorithms