Binary Search Trees Flashcards

(8 cards)

1
Q

What is a Binary Search Tree ?

A

The left subtree of a node contains values less than the node’s value,
The right subtree of a node contains values greater than the node’s value.

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

What is the height and size of a BST ?

A

Height = The longest path from the root to a leaf,
Size = The total number of nodes in a tree.

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

How are BSTs constructed ?

A

If the new value is less than the curerent node, move to the left subtree,
If the value is greater, move it to the right.

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

How to do a BST search ?

A

Start from the root,
Move left or right based on comparisons,
O(log n)

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

How to do a BST insertion ?

A

Locate the appropriate leaf node,
insert as a new leaf,
O(log n)

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

How to do a BST deletion ?

A

The node to delete may have:
No Children - simply remove,
One Child - Replace the node with its child,
Two Children - replace with left or right child,
O(log n)

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

What is an AVL tree ?

A

A self balancing tree that uses rotations to ensure that the height difference between left and right subtrees is, at most, 1.

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

What are the AVL tree rotations ?

A

Left rotation (Right-Right imbalance),
Right rotation (Left-Left imbalance),
Left-Right rotation (Left-right imbalance),
Right-Left rotation (Right-left imbalance.

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