Other algorithm questions Flashcards

1
Q

Definition of Big O

A

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}

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

Definition of Θ-notation

A

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}

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

Definition of Ω-notation

A

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}

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

What is a loop invariant?

A

A loop invariant is a property that is true before iteration i and is also true before iteration i+1.

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

Equations for:

Number of Levels?
Number of nodes on the ith level?
Array length of nodes on ith level?

In a Merge Sort.

A

Num of Levels = ⌈log n⌉ + 1
Num of Nodes at ith level = 2^(i-1)
Array length at ith level = ⌈n/2^(i-1)⌉

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

What is a full tree for a k-ary tree?

A

A tree is full if every internal node has exactly k children.

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

What is a complete tree?

A

A tree is complete if all levels except possibly the last is entirely filled.

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

What is a perfect tree?

A

A tree is perfect if all levels are entirely filled.

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

What is the heap property?

A

Every element of the tree is larger than any of its children if they exist.

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

What does Heapify() do?

A

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.

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

What is the best way to select a pivot for Quicksort?

A

Select the pivot at random.

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