16 Greedy vs DP Flashcards

1
Q

How is dynamic programming and greedy algorithms in common?

A

Both solve optimization problems that require making a sequence of choices.

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

Greedy algorithms are usually ____ than DP solutions.

A

More efficient

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

Greedy Algorithm

A

Makes a squence of decisions. For each decision:
- takes the decision that looks best right now, without regard for future consequences.

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

Greedy algorithms have the advantage of :

A

Being simple and fast.

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

Spanning tree

A

An undirected graph G = (V,E) is a subgraph of G that is a tree and contains all the vertices of G.

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

Minimum spanning tree

A

A subgraph of an undirected wieghted graph such that
- its a tree (acyclic graph)
- covers all the vertices (contains V-1 edges)
- total cost associated with tree edges is the minimum among all possible spanning trees.

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

Two greedy algorithsm with the same asymptotic complexity:

A

Kruskal’s and Prim’s algorithm.

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

Prim’s algorithm

A

For finding an minimum spanning tree
Is a greedy algorithm.

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

Prim’s Algorithm time complexity using binary heap

A

O(V log V) + O(E log V)

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

Prim’s Algorithm time complexity using an array

A

O(V^2) + O(E) == O(V^2)

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

Prim’s Algorithm time complexity using a heap

A

O(E lg V)

Sparse Graph: E is approximately V, so O(V log V)
Dense Graph E is approximately V^2, so O(V^2 log V)

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

Prim’s Algorithm is only for :

A

Undirected Graphs (That are also connected and weighted)

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

Spanning Tree

A

For an undirected graph G = (V,E) is a subgraph of G that is a tree and contains all the vertices of G

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

Weight of a subgraph

A

The sum of the weights of the edges.

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

Minimum Spanning Tree

A

A subgraph of an undirected weighted graph such that
- it is a tree (acyclic)
- it covers all vertices (contains V-1 edges)
- the total cost associated with tree edges is the minimum among all possible spanning tree.
- Note that is it not necessarily unique (it is only unique if the original graph G is a tree).

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