Trees Flashcards

1
Q

What is a full binary tree?

A

a tree in which every node has either 0 or 2 children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a complete binary tree?

A

every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

perfect binary tree?

A

is a binary tree in which all interior nodes have two children and all leaves have the same depth or same level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is a tree that is full and complete necessarily perfect?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

pre order, in order, vs post order

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when items are inserted into a BST in sorted key order?

A

The tree degenerates into a linked list with n nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to prevent BSTs from degenerating into linked lists?

A

Use self balancing binary search trees

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Name 7 implementations of self balancing binary search trees

A

2-3 tree, AVL tree, B-tree, red black tree, splay tree, scapegoat tree, tango tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the differentiating concept between splay trees and other self balancing binary search trees?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Ben Pfaff paper

A

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?]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When are red-black trees preferred over AVL trees?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

why do red-black trees have faster insertions/deletions than AVL trees?

A

they have less strict rules around rebalancing. Conversely, AVL tree is more strictly balanced so lookups are faster than RB tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

etymology of trie

A

derived from the word retrieval. pronounced “try”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Performance of self balancing binary trees vs binary heaps

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Binomial tree

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the ratio of insert+deletes to search at which at or greater than this ratio R-b trees are more performant than AVL trees?

A

[not sure. But see Ben pfaff paper or other papers]

17
Q

If self balancing trees are slower than binary heaps in practice, then when are do self balancing trees have any use cases in the real world?

A

18
Q

When would we use self balancing bsts for a priority queue instead of a binary heap?

A

According to geeks for geeks, we would use it for a doubly ended priority queue:

With a Binary Heap, we can either implement a priority queue with support of extractMin() or with extractMax(). If we wish to support both the operations, we use a Self-Balancing Binary Search Tree to do both in O(Log n)

19
Q

Worst case height of AVL tree

A

~1.44 log(n)

20
Q

Worst case height of RB tree

A

2 log n