Trees Flashcards

1
Q

Tree height

A
  • length of longest path from node to leaf

- leaves have height zero

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

tree Depth

A

length of the path from the root to that node

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

Internal path length

A

sum oof the depths of all the nodes

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

Preorder/ inorder/postorder

A

preorder = node left right
in order = left node right
postorder = right left node

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

BST

A
  • nodes have at most 2 kids
  • all nodes in left subtree are less than key
  • all nodes in right are greater
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The maximum number f nodes in a binary tree of height h is

A

2^h+1 -1

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

Worst case depth for a n-node BST is

A

n-1

Meaning that the data was already sorted beforehand

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

AVL Tree

A

Keeps track of a balancing factor/height attribute, whereby the height of the left and right subtrees differs at most by one

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

AVL trees can hit -3 or 3 bf

A

false

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

Rotations in slides!

A

yeah!

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

Runtime of find, insert, remove and print in AVL tree?

A

All log n except print, which is always linear

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

Red-black trees

A
  • each node has a color attribute, red or black
  • the root is black
  • leaves are black
  • both children of every red node are black
  • every simple path from a node to any descendant leaf has the same number of black nodes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

RB tree vs AVL tree

A
  • AVL are more rigidly balanced and require more rotations sometimes
  • Red black are slightly faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Splay tree

A
  • self balancing tree that keeps recently used nodes close to the top
  • improves performance for finding values
  • great for cache data storage techniques
  • easier to implement than other trees
  • every find/insert/delete, you splay the tree around that node
  • splay is Omega(h) height
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Amortized

A

averaged over time! AVL as good amortized and not amortized, meaning O(log n).

Splay tree has good amortized but not actual runtime.

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

When to use trees?

A
  • aren’t sorted
  • less complexity, like a stack or queue
  • constant time operations on attributes/retrieves