A Binary Search tree is a binary tree with two additional rules what are they (invariant of BST)
•Elements in the left sub-tree of a node have values less than the value of the node.
•Elements in the right sub-tree of a node have values greater than the value of the node.
Operations of a queue
What is push, pop and peek?
In an AVL tree a balance factor greater or less than what will result in a re-balancing?
1 and -1
A node inserted into a red black tree is always ____ and always has color ____.
a leaf, red
The time complexity of pushing an element into a linked list
What is O(1)? (or: constant time)
Post order traversal traverses a tree in what order?
Left, Right, Root
What is FILO(First in last out)
There are only two ways that a tree or a sub tree can become unbalanced, what are they?
Adding or removing an element.
When inserting into a red black tree, what would have to happen for it to be a trivial case? (No more operations needed)
The parent of the node is black.
True or False:
O(log(n)) is a faster algorithm than O(n)
True
When removing from a BST, and the item you are removing has two children what do you do?
we swap the node to be deleted with a suitable replacement node in one of its sub-trees and remove it from its new position instead.
If I "push" to the stack the element is here.
What is the top
When encountering a node that needs to be re-balanced in an AVL tree, what is the maximum number of rotations?
2
The root of a Red black tree always gets recolored to what?
black
The time complexity of accessing the third element in an array
What is O(1)? (or: constant time)
All operations on a correctly implemented balanced BST list have an average run time of log n, except for two of them, what are those two?
isEmpty() O(1)
size() O(1)
The stack that results from the following operations:
Push(1)
Push(2)
Push(3)
Pop()
Pop()
Push(4)
Push(5)
Push(6)
Pop()
Push(7)
1 4 5 7 <- Top
Recall that rebalancing is only necessary
along __________
This means at most ______need to be checked for
imbalance.
-path of nodes from the altered node to the root
-the depth of the tree’s worth of nodes
Name the three rules that govern a red black tree
•The root is black.
•All children of a red node are black.
•Every path from the root to a leaf contains the same number of black nodes.
The time complexity of merge sort
What is O(n log(n))?
The correct IN-ORDER traversal for the above tree is
4, 2, 5, 3, 1 TRUE/FALSE
FALSE
If I have a stack of queues of stacks is this operations valid?
stack.push().peek().pop()
What is True
50
40 60
Null 45
If you remove the 60 from the above tree, what kind of rotation is required to re-balance the tree?
Left-Right
45
40 50
When inserting a new node into a red black tree and the parent is red, the parent's sibling is null and the node is outside relative to grandparent, what do you do?
rotate parent and grandparent then recolor
The time complexity of an algorithm with a for loop that iterates "size" times inside another for loop that iterates "size" times
What is O(n^2)