Section 7 Chapter 42 - Trees Flashcards
Tree
Connected, undirected graph with no cycles
Rooted tree
A tree where one vertex has been designated as the root
Node
Contains the data and are connected together via edges
Edge
Connects two nodes
Root
The only node with no parent. All other nodes are descendants of the root
Child
node A is a child of node B is they have a direct connection and node B is closer to the root than node A.
Parent
Node A is a parent of node B if they are directly connected and node A is closer to the root
Subtree
The set of nodes and edges comprised of a parent and its descendants
Leaf
A node that has no children
Binary tree
A rooted tree where each node has at most two children
Binary search tree
A binary tree that holds the items in such a way that a binary search can be conducted on the tree very easily
How to construct a binary search tree
The first item is placed at the root. When a new item is added visit the root, which becomes the current node. At each current node, if the item is less than the value of the node take the branch to the left, otherwise take the branch to the right. Repeat until you attempt to take a branch that does not exist. Add the item as a node in this place
The ways to traverse a binary tree (3)
Pre-order
In-order
Post-order
How to know what each traversal means
The prefix of each traversals refers to how whether, at each subtree, you consider the parent node first, second or third.
Uses for each traversal
Pre-order - producing prefix notation
In-order - binary search
Post-order - produce reverse polish notation