Alg 2 Flashcards

1
Q

Meaning of f(n) ∈ O(g(n))

A

f grows no faster than g

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

Meaning of f(n) ∈ o(g(n))

A

f grows strictly slower than g

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

Meaning of f(n) ∈ Ω(g(n))

A

f grows no slower than g

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

Meaning of f(n) ∈ ω(g(n))

A

f grows strictly faster than g

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

Meaning of f(n) ∈ Θ(g(n))

A

f grows at roughly the same rate as g

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

Formal definition of f(n) ∈ Θ(g(n))

A

There exist c > 0, C > 0 and n0 > 0 such that for all n ≥ n0, we have cg(n) ≤ f(n) ≤ Cg(n).

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

Does big O satisfy transitivity?

A

Yes. if f(n) ∈ O(g(n)) and g(n) ∈ O(h(n)), then f(n) ∈ O(h(n))

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

Does big O respect addition?

A

Yes. if f(n) ∈ O(h(n)) and g(n) ∈ O(h(n)), then f(n) + g(n) ∈ O(h(n))

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

Does big O respect scalar multiplication?

A

Yes. if f(n) ∈ O(g(n)), then for all constants A > 0, A*f(n) ∈ O(g(n))

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

Does big O respect multiplication of functions?

A

No. if f(n) ∈ O(h(n)) and g(n) ∈ O(h(n)), then f(n)·g(n) = O(h(n)) isn’t always true.

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

Does big O respect squaring?

A

Yes. if f(n) ∈ O(g(n)), then f(n)2 ∈ O(g(n)2)

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

Does big O respect expenonentation?

A

No. if f(n) ∈ O(g(n)), then 2f(n) ∈ O(2g(n)) isn’t always true.

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

Interval Scheduling

A

A request is a pair of integers, the start and finish time.

A set of requests is compatible if none of them overlap.

Greedy algorithm: keep choosing compatible interval with earliest finish time. O(nlogn)

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

Graph Terminology

A

Two graphs are equal if their vertices and edges are identical.

Two graphs are isomorphic if there exists a mapping between their vertices. (They are the same graph but relabelled)

A subgraph is induced if all edges that connect the sub-vertices in the original graph are also included in the subgraph.

A component of a graph is a maximally connected induced subgraph. E.g. if a graph consists of two triangles, each of those triangles is a separate component.

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

Euler Walks

A

A walk is a sequence of connected edges

An euler walk is a walk using each edge exactly once

A path is a walk with no repeated vertices.

A graph cannot have a walk if the number of vertices with an odd degree is not 0 or 2.

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

Digraphs

A

G is strongly connected if for all pairs of vertices u,v there is a path from u-v AND v-u.

G is weakly connected if for all pairs of vertices u,v there is a path from u-v OR v-u

Strong components are components that are strongly connected.
Weak components are components that are weakly connected.

In-neighbourhood of a vertex (D-) is the number of incoming edges.
Out-neighbourhood of a vertex (D+) is the number of outgoing edges.

17
Q

Digraph Walks

A

A digraph cannot have an euler walk if it is not weakly connected.
It cannot have an euler walk with the same start/end point if it is not strongly connected.

18
Q

Ways of representing matrices?

A

Adjacency Matrix - Row represents starting vertex, column is ending.
Adjacency List - Each vertex has a list of the other vertices it is connected to.

19
Q

Adjacency Matrix Runtimes/space

A
20
Q

Adjacency List Runtimes/space

A
21
Q

Adjacency List vs Matrix

A
22
Q

Depth-First Search Algorithm

A

Pick an unvisited vertex, repeat from that vertex recursively until no unseen vertices from current vertex, then backstep until there is an unseen.

23
Q

Depth-First Search Trees

A

If x and y are adjacent in the original graph, one will be the ancestor of the other in the DFS tree.

24
Q

Depth-First Search Invariant and Time

A

When helper is called, if explorer[i] = 1 then V_i is in the component.

25
Q

Breadth-First Search Algorithm

A

Visit all unvisited vertices adjacent to the subgraph of visited vertices. Repeat until all visited.

26
Q

Breadth-First Search Time Analysis

A
27
Q

Bipartite lemma?

A

G is bipartite if and only if it has no odd-length cycle.

28
Q

What is an augmenting path?

A

In a graph with a matching, an augmenting path is a path that alternates between edges in the matching (a matching edge) and edges outside the matching (non-matching edge). It also start & ends with a non-matching edge

29
Q

What does the Switch function do? (matchings)

A

If P is an augmenting path for M,

Switch(M, P) returns a new path, where every edge that was matching is now non-matching and vice-versa. Two additional edges are added to either end as non-matching.

30
Q

What is an auxiliary digraph? (matchings)

A

A bipartite graph with sections (A,B) where all matching edges are directed B to A and all non-matching edges are directed A to B.

D(G, M) where the graph is G and the matching is M.

31
Q

Lemma for if a path is augmenting.

A

If and only if it is also a path from the non-matching vertices of A to the non-matching vertices of B in the auxiliary digraph.

32
Q

Algorithm to find maximal matching?

A

Find a bipartition (A,B) of G. Initialise M <- []
loop:
Form the graph D(G, M)
Set P to be a path from UnA to UnB in D(G,M) if exists:
Otherwise, break
Update M <- Switch(M, P)

return M

33
Q

Invariant of the algorithm to find maximal matching?

A

At the start of the ith loop iteration, M is a matching with i-1 edges. M can have at most |V|/2 edges in total, so it outputs a matching with no augmenXting paths.

34
Q

Maximal matching algorithm runtime?

A

O(|E||V|)

35
Q

Berge’s lemma?

A

M has no augmenting paths => M is maximal.

36
Q

Prim’s Algorithm

A

Keep adding the edge with lowest weight that connects a disconnected vertex to the existing tree.

Implemented as BFS with a priority queue.

O(|E| log |E|)

37
Q

Kruskal’s Algorithm

A

Keep adding any edge in the graph with the lowest weight so long as it isn’t connecting two already existing vertices.

O(|E| log |E|)