Trees Flashcards
Define tree
connected undirected graph with no cycles
Define root of a tree
start node for traversals
Define branch of a tree
path from root to an end point
Define height of a tree
number of edges connected to root node and furthest leaf node
Define parent and child mode
- Parent node: node that comes directly before another
- Child node: no children
Define binary tree
-rooted tree where every node has at most two child nodes
Define binary search tree
ordered to optimise searching
Uses for trees
- used in compilers to build syntax trees.
- to represent algebraic and boolean expressions
- speed up searching
Records for each nodes will contain:
- the index
- the data
- left child pointer
- right child pointer
Which side do you do pre-order tree traversal in?
left side
Algorithm of pre-order?
- Output the node
- Left
- Right
Which side do you do in-order traversal?
below
Algorithm of in-order?
- left
- output the node
- right
Which side do you do post-order traversal?
right side
Algorithm of post-order?
- left
- right
- output the node