Trees Flashcards
What type of data structure is a tree?
A hierarchical data structure
What internal data structure is used in a heap?
A queue
What is a node?
The elements of a data structure
What is an edge?
The theoretical relationship between a parent and child node
What are the two special cases of nodes?
root: topmost node
leaf: bottommost node
What is the length a measure of?
The number of nodes in a path
What is the height of a tree?
The largest depth(length of path)
What is the depth?
The length from the root node to the destination
What are some common uses for trees?
- )represent family trees, like genealogy
- )represent decision making algorithms
- )represent priority queues(as a heap)
- )provide fast access to databases(as a b-tree)
What is a sub-tree?
The tree with a root node that is a descendant of the original root node.
What are the descendants of a node?
The subsequent children of a given parent node
What kind of relationship does a tree have that differs from the predecessor/successor of a list?
parent/child relationship
What are the requirements for a tree to be considered binary?
Each parent node has 2 children, a right and left node
What defines pre-order traversal?
Root-L-R
What defines post-order traversal?
L-R-Root
What defines level-order traversal?
Root-level1-level2-leveln…
What defines in-order traversal?
L-Root-R
What is BST short for?
Binary Search tree
When is a binary tree a BST?
If for every node, the right subtree(k) is greater than the node(k) & the left subtree(k) is smaller
Are duplicates allowed in a standard BST?
no. The insert makes sure of this by throwing a DuplicateException
For the recursive lookup method of a BST, what base cases are there?
- ) the tree is empty
2. ) the root node has the value we are searching for
For the recursive lookup method of a BST, what recursive cases are there?
- ) visit the right subtree
2. ) visit the left subtree
How is the insert method implemented for a BST?
It is the same as the lookup method, but after finding the desired position it is added as a child of the parent
What three cases have to be considered when deleting a node in a BST?
The node to delete has:
- 1 node
- 2 nodes
- no nodes(is a leaf)