Trees Flashcards
(37 cards)
What is a Node?
- The elements of the tree
- Each node contains a key which uniquely identifies that node
What is an Edge?
The link/connection between nodes
What is unique about the root node?
It has no parent
What are leaf nodes?
Nodes that have no child
What is a Path?
A sequence of nodes connected by edges
How is the length of a path determined?
Determined by the number of nodes in the path (including start and end nodes)
What is a Parent node?
The unique predecessor of every node
What is a Child node?
The successor to a parent node
What are Sibling nodes?
Nodes that have a common parent
What is the Level of a node?
- The number of nodes between this node and the root node
- Calculated using the shortest path to the root node
What is the height of a tree?
The height is determined by the highest level node
What are Sub-trees?
- A Sub-tree is formed using a parent node and all of it’s descendants.
- The parent node becomes the root node of the Sub-tree.
What is the difference between a Strictly Binary Tree and a Knuth Binary tree?
- Each node in a Strictly Binary tree has either 0 or 2 sub-trees
- Each node in a Knuth Binary Tree can have 0, 1 or 2 sub trees
What 3 qualities make Trees a recursive data structure?
- The data of the node itself
- A reference to the left child node (can be null)
- A reference to the right child node (can be null)
What makes a tree balanced?
All leaf nodes have the same level
What is a Breadth-first traversal?
Returns the data of each node level by level
(e.g. returns all nodes at level 1, then level 2, etc.)
What is the procedure for a Depth first Pre-order traversal?
- Process current node
- Traverse to left sub-tree
- Return to parent node
- Traverse to right sub-tree
- Return to parent node
-Process, Left, Right or P, L, R
What is the procedure for a Depth first In-order traversal?
- Visit current node
- Traverse to left sub-tree
- Process current node
- Traverse to right sub-tree
- Return to parent node
- Left, Process, Right or LPR
What is the procedure for a Depth first Post-order traversal?
- Visit current node
- Traverse to left sub-tree
- Visit current node
- Traverse to right sub-tree
- Process current node
- Return to parent node
- Left, Right, Process or LRP
What is a Binary Search Tree (BST)?
- A Binary Tree that is ordered so that, starting at the root, when we search for a node we always know which sub tree to search in
- This mean the maximum number of comparisons = height of tree
How is a BST organised?
- The values in the left sub-tree are always less than the parent
-The values in the right sub-tree are always greater than the parent
What is the worst-case and best-case time complexity of searching a BST?
- Worst case: O (n) when every parent node only has one child
- Best case: O (log n) when every parent node has 2 children
What type of traversal is needed to return an ordered list of items from a BST?
Depth first in-order traversal
What is a Full Binary tree?
A binary tree where every level of the tree has the maximum possible number of nodes