Final Exam Flashcards

1
Q

running times of insertion sort

A

o Best case: O(n)
o Worst case: O(n^2)
o Average case: O(n^2)

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

running times of bubble sort

A

o Best case: O(n)
o Worst case: O(n^2)
o Average case: O(n^2)

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

running times of heap sort

A

o Best case: O(n log n)
o Worst case: O(n log n)
o Average case: O(n log n)

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

running times of merge sort

A

o Best case: O(n log n)
o Worst case: O(n log n)
o Average case: O(n log n)

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

recurrence relationship for merge sort

A

T(n) = 2T(n/2) + O(n) n > 1

O(1) n = 1

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

running times for quick sort

A

o Best case: O(n log n)
o Worst case: O(n^2)
o Average case: O(n log n)

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

running time and recurrence for quick sort with a 8 to 3 split

A

RT = O(n log n)

T(n) = T(8n/11) + T(3n/11) + O(n) n > 1
O(1) n = 1

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

recurrence relationship for worst case of quick sort

A

T(n) = T(n-1) + O(n) n > 1

O(1) n = 1

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

Djikstras priority queue implemented with array: running times for insert, decrease key, and delete min

A

insert: O(1)
decreasekey: O(1)
deletemin: O(n)

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

Djikstras priority queue implemented with binary heap: running times for insert, decrease key, and delete min

A

insert: O(log n)
decreasekey: O(log n)
deletemin: O(log n)

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

running times for search, insert, and delete on regular binary search tree with n nodes

A

O(h) where h is the height of the tree . . . or O(n)

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

running times for search, insert, and delete in a red-black tree with n internal nodes

A

O(log n)

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

running time for topological ordering (linearization) algorithm

A

O(|V| + |E|)

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

running time for longest common string

A

O(n * 2^m)

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

running time for edit distance

A

O(n * m)

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

definition for Asymptotic / Big O Notation

A

f(n) = O(g(n)) if there exist positive constants c and n0 such at 0 <= f(n) <= c*g(n) for n >= n0

worst case / lower bound

17
Q

height of heap with n nodes

A

O(log n)

18
Q

height of red-black tree with n internal nodes

A

O(log n)

19
Q

definition of master theorem

A

T(n) = aT(n/b)+(n^d) for a > 0, b > 1, d >= 0
then,
O(n^d) if d > log_b a
T(n) = O(n^d * log n) if d = log_b a
O(n^log_b a) if d < log_b a

20
Q

definition of big omega notation

A

best case RT / lower bound

21
Q

definition of big theta notation

A

is both big O and big omega

22
Q

True or False: If f(n) = Θ(g(n)) and g(n) = Θ(h(n)), then h(n) = Θ(f(n)).

A

True

23
Q

True or False: If f(n) = O(g(n)) and g(n) = O(f(n)) then f(n) = g(n).

A

False

24
Q

True or False: 𝑛/100 = Ω(n).

A

True

25
Q

Properties of min heap

A

Complete tree where every parent must be of lower value than its children

26
Q

Properties of red-black tree

A
  1. Every node is colored red or black.
  2. The root is black.
  3. Every “leaf” (the sentinel) is colored black.
  4. Both children of a red node are black.
  5. Every simple path from a child of node X to a leaf has the same number of black nodes.
27
Q

Under what condition will the Bellman-Ford algorithm not work?

A

When the graph contains a negative cycle

28
Q

what is black height for a RBT?

A

number of black nodes in a path (must be the same for all paths)

29
Q

running time of Kruskal’s

A

O( |E| * log|V|)

30
Q

running of time of Primm’s as binary heap, as array

A

binary heap: O(|E| + |V|) * log|V|),

array: O(|E|^2)
* same as running time of Djikstras

31
Q

running time of Djikstras: binary heap and array

A

binary heap: O(|E| + |V|) * log|V|),

array: O(|V|^2)

32
Q

running time of Bellman-Ford

A

O(|V| * |E|)

33
Q

running time of DFS

A

O(|V| + |E|)

34
Q

running time of BFS

A

O(|V| + |E|)