Other algorithm questions Flashcards
Definition of Big O
Let g(n) be a function.
Then O(g(n)) is the set of functions:
O(g(n)) = {f (n) : There exist positive constants c and n0
such that 0 ≤ f (n) ≤ cg(n) for all n ≥ n0}
Definition of Θ-notation
Let g(n) be a function.
Then Θ(g(n)) is the set of functions:
Θ(g(n)) = {f (n) : There exist positive constants c1, c2 and n0 s.t. 0 ≤ c1g(n) ≤ f (n) ≤ c2g(n) for all n ≥ n0}
Definition of Ω-notation
Let g(n) be a function.
Then Ω(g(n)) is the set of functions:
Ω(g(n)) = {f (n) : There exist positive constants c and n0
such that 0 ≤ cg(n) ≤ f (n) for all n ≥ n0}
What is a loop invariant?
A loop invariant is a property that is true before iteration i and is also true before iteration i+1.
Equations for:
Number of Levels?
Number of nodes on the ith level?
Array length of nodes on ith level?
In a Merge Sort.
Num of Levels = ⌈log n⌉ + 1
Num of Nodes at ith level = 2^(i-1)
Array length at ith level = ⌈n/2^(i-1)⌉
What is a full tree for a k-ary tree?
A tree is full if every internal node has exactly k children.
What is a complete tree?
A tree is complete if all levels except possibly the last is entirely filled.
What is a perfect tree?
A tree is perfect if all levels are entirely filled.
What is the heap property?
Every element of the tree is larger than any of its children if they exist.
What does Heapify() do?
Checks if the children of an element are greater than the element. If the child is great than the element the two nodes will be exchanged.
What is the best way to select a pivot for Quicksort?
Select the pivot at random.