(W11) Data Structures Flashcards

(14 cards)

1
Q

What is the special property of an AVL tree

A

It’s a self balancing binary tree

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

What is the definition of balanced in an AVL tree & how do you calculate it?

A

Balance = height(left) - height(right)

importantly, a tree is balanced if, for each node, at most, the height of the right and left subtree differ by at most 1

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

AVL Tree circumstance:
Balance Factor = 2, left child has a balance of 0 or 1

A

Left-Left case (only 1 operation)

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

AVL tree circumstance:
Balance Factor = 2, left child has a balance of -1

A

Left-right case

Perform left on the child, right on the parent

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

AVL tree circumstance:
Balance Factor = -2, right child has a balance of 0 or -1

A

Right-right case

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

AVL tree circumstance:
Balance Factor = -2, right child has a balance of 1

A

Right-left case

Perform right on the child, left on the parent

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

Time Complexity of AVL operations?

A

O(log n) for all operations. this is because the BST tree is balanced. rotations are O(1)

except traversal O(n)

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

What are the types of nodes in a 2-3 Tree?

A

2-nodes: single key, two children
3-nodes: 2 keys, three children

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

How to insert into a 2-3 Tree

A
  • Do a search, find the leaf node
    ○ If the leaf is a 2-node, turn it into a three node, and add the key
    ○ If it’s a 3-node, temp make it a 4 node
  • If there is a 4 node, then promote the middle key. Do this recursively (including if you need to add a new root node)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Do you ever increase the height of a 2-3 tree from the base?

A

No, if the height of the tree ever increases, it will be the result of adding a node to the parent

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

What are the different complexities of operations in a 2-3 tree?

A

O(log n) for insert/search/delete

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

What is the practical purpose of a Red-Black-Tree?

A

It’s a faster implementation of 2-3 tree. Lower constants

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

What are the 4 properties of a red-black tree?

A

The colour of a non-root node is determined by the colour of its
single incoming edge. The root is by definition black.

All red links lean left, i.e., all red links go to a left child.

No node is adjacent to two red edges.

The tree has perfect black balance: the number of black edges
between any node and each of its descendant leaves are the same.

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

AVL trees vs RBTs regarding complexity?

A

In terms of worst-case complexity - they are both equivalent

AVL trees are more strictly balanced - so this makes them better for lookups (in terms of concrete efficiency)

RBT’s are better for insertion (less rotations that need to be done)

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