Trees Flashcards
What is a full binary tree?
a tree in which every node has either 0 or 2 children
what is a complete binary tree?
every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.
perfect binary tree?
is a binary tree in which all interior nodes have two children and all leaves have the same depth or same level
Is a tree that is full and complete necessarily perfect?
NO. You could still have have missing nodes on the right side of the last level (but where all interior levels have no missing nodes (fulfilling the complete property)), but where the second to last level is entirely composed of nodes that have either 0 or 2 children (fulfilling the full property) the
pre order, in order, vs post order
refers to when you visit the root node;
pre order visits root, left, then right
in order visits left, root, right
post order visits left, right, root
What happens when items are inserted into a BST in sorted key order?
The tree degenerates into a linked list with n nodes
How to prevent BSTs from degenerating into linked lists?
Use self balancing binary search trees
Name 7 implementations of self balancing binary search trees
2-3 tree, AVL tree, B-tree, red black tree, splay tree, scapegoat tree, tango tree
What is the differentiating concept between splay trees and other self balancing binary search trees?
Splay trees allow for faster access of recently accessed elements. When an operation is being performed on an element, the tree performs an operation called splaying which pulls the element to the top of the tree
Ben Pfaff paper
Compares performance of different self balancing BST implementations
Regular BSTs excel when randomly ordered input can be relied upon (input as in insertions, accesses, or both?).
Splay trees excel when data is often inserted in a sorted order and later accesses are sequential ( I think author means accessing data in the sorted order it was inserted) or clustered. ( I think author means like repeated access of the same element)
AVL trees excel when data is often inserted in a sorted order and later accesses are random.
Red-black trees excel when data is often inserted in random order but occasional runs of sorted order are expected. [ what about frequent runs of sorted order??] [ by runs does it mean insertions or accesses??]
[what about deletions?]
When are red-black trees preferred over AVL trees?
when there is high frequency of insert/delete operations compared to search as AVL tree balancing (rotation) is expensive. AVL trees are useful if lookup (search) is a lot more common than insertion/deletion.
why do red-black trees have faster insertions/deletions than AVL trees?
they have less strict rules around rebalancing. Conversely, AVL tree is more strictly balanced so lookups are faster than RB tree.
etymology of trie
derived from the word retrieval. pronounced “try”
Performance of self balancing binary trees vs binary heaps
In practice self balancing binary trees are slower. This has to do with the fact that heaps can be implemented on top of an array, while BSTs use recursive tree data structures with child pointers. Array has much better locality of reference.
Binomial tree
Always has 2^N nodes for some integer N
Not sure yet of the structure, but it deinfitely doesn’t always have <=2 children on each node like a binary tree . E.g sometimes has 3 nodes