Binary Search Trees Flashcards
(8 cards)
What is a Binary Search Tree ?
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.
What is the height and size of a BST ?
Height = The longest path from the root to a leaf,
Size = The total number of nodes in a tree.
How are BSTs constructed ?
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 to do a BST search ?
Start from the root,
Move left or right based on comparisons,
O(log n)
How to do a BST insertion ?
Locate the appropriate leaf node,
insert as a new leaf,
O(log n)
How to do a BST deletion ?
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)
What is an AVL tree ?
A self balancing tree that uses rotations to ensure that the height difference between left and right subtrees is, at most, 1.
What are the AVL tree rotations ?
Left rotation (Right-Right imbalance),
Right rotation (Left-Left imbalance),
Left-Right rotation (Left-right imbalance),
Right-Left rotation (Right-left imbalance.