Week 7 Flashcards

1
Q

What is a self balancing binary search trees ?

A

*A self balancing BST is one that automatically keeps its height, as small as possible, at all times
*Rotations are preformed on the tree, at key times, to reduce the height
*A rotation will changes the structure of the tree without changing the order of the elements

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

Tree Rotation

A

*Is used to change the structure of the BST without changing the order of the elements

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

AVL Trees

A

An AVL tree is a binary search tree in which:
*Heights of the left and right subtrees of the root node differ by at most one
*Left and right subtrees are again AVL trees - a recursive definition

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

Balance Factors

A

*Each node of an AVL tree contains an additional variable called the balance factor
*Balance factor of a node is the height of its left subtree minus the height of its right subtree
*Balance factor +1, 0, or -1 is considered balanced
*Balance factor +2 or -2 is considered unbalanced and with require the tree to be rebalanced using a rotation

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

Creating an AVL Tree

A

*AVL tree is created as the data items are inserted
*Initially tree is empty - satisfies rules for an AVL tree
*Data items are inserted into the AVL tree using the normal rules for insertion into a BST
*Balance factor of each node on the path from the point of insertion to the root may change
*Nodes with a balance factor ±1 may be changed to ±2. *Unbalanced nodes will have a balance factor of ±2 and the tree is unbalanced
*Unbalanced trees must be rebalanced, using a rotation
*Rotation will take place around the unbalanced node which is nearest to the inserted node

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

Rotations for AVL Trees

A

Single Rotations
*Left-Left Rotation(LL)
*Right-Right Rotation(RR)
Double Rotations
*Left-Right Rotation(LR)
*Right-Left Rotation(RL)
*Rotations take place around the unbalanced node with a balance factor of ±2

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