CSC Data Structures and Algorithms
University of Illinois Springfield
College of Health, Science, and Technology
Visual representation of various tree terms
Examples of full vs complete
Note
Tree a shows a perfect binary tree. It is not necessarily true that a tree that is full is also complete and vice versa. Tree b is complete but not full. Node L only has 1 child which violates the “exactly 2 child nodes” of a full tree.

\[ n = 2^{h + 1} - 1 \]
\[ l = 2^h \]

Examples of expression trees
Game Tree for Tic Tac Toe
The order in which each node is processed in pre-order
The order in which each node is processed in in-order
The order in which each node is processed in post-order


Note
Graphs are the general data structure of connected nodes (or vertices) via edges created by one Leonhard Euler in 1735. The field of studying graphs is known as graph theory. Trees and linked lists are special types of graphs.
height(root)getRootItemExample of adding to a Binary Tree
getNode(T obj) to retrieve the BinaryNode object of obj.remove(node) to remove the node objectImportant
We will discuss the algorithm for removing later using two different methods
getNode(T obj)Initial Tree
Replace “B” with “F”
Result of replacing B with last node
Remove the last node of the tree using the parent



queue [a] -> Root
queue [b c] -> Add children of a
queue [c d e] -> Add children of b
queue [d e f] -> Add children of c
queue [e f] -> d has no children to add
queue [f] -> e has no children to add
queue [g] -> Add children of f
queue [] -> g has no children to add
Done
algorithm pre-order() {
pre-order(root)
}
algorithm pre-order(Node node) {
if node is not null {
process(node)
pre-order(node.leftChild)
pre-order(node.rightChild)
}
}
stack [a] -> Root
stack [c b] -> Add children of a
stack [c e d] -> Add children of b
stack [c e] -> d has no children
stack [c] -> e has no children
stack [f] -> Add children of c
stack [g] -> Add children of f
stack [] -> g has no children
Done
algorithm post-order() {
post-order(root)
}
algorithm post-order(Node node) {
if node is not null {
post-order(node.leftChild)
post-order(node.rightChild)
process(node)
}
}
stack [a] -> Push root onto stack
stack [a b]
stack [a b d]
stack [a b]
…
stack [a b e]
stack [a b]
stack [a]
…
stack [a c]
stack [a c f]
stack [a c f g]
…
stack [a c f]
stack [a c]
…
stack [a]
stack []
Done
algorithm in-order() {
in-order(root)
}
algorithm in-order(Node node) {
if node is not null {
in-order(node.leftChild)
process(node)
in-order(node.rightChild)
}
}
postorder(root)

CSC 385 - Data Structures and Algorithms