Wk 5/6 : Graphs, MST's, Kruskal, Primm, BFS, DFS Flashcards

1
Q

What is a path?

A

A

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

What is a cycle?

A

.

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

What is a subgraph?

A

.

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

What is degree?

A

.

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

What is min/max degree?

A

.

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

What is the max # of edges in an undirected graph?

A

.

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

What are connected components?

A

Can get from anyone node to another?

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

What is the definition of the shortest path of a weighted graph??

A

.

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

What is a tree? A rooted tree?

A

.

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

What is a spanning tree?

A

.

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

What is an acyclic graph?

A

.

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

What is a bipartite graph?

A

.

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

How do we store a graph? 2 options….

A

.

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

When would we choose to use an adjacency-list representation over an adjacency-matrix representation of a graph? Why? What are the positives and negatives of each one?

A

When a graph is sparse, the adjacency list makes more sense (|V|^2&raquo_space; E.

If a graph is dense, or we need to quickly tell if there is an edge in between 2 vertices. (for ex. all pairs shortest paths)

Matrices use asympotically more memory than adj-lists, which use only Theta (E+V). But it provides a quick way to know if an edge is in the graph. It is also simpler and makes sense for small grapsh

Lists are easy to add data to, like weight functions and other variants.

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

Which algorithms lean heavily on BFS?

A

Primm, Dijkstra

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

What does BFS do in English?

A

Systematically explores the edges of G to find every vertex that is reachable from s.

Keeps track of the levels that each node is from s as it continually expands the frontier from s.

Creates a BFS tree that from s to any node reachable from s, hs the simple path which is the smallest number of edges.

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

What does BFS use to keep track along the way, and what are the meanings…

A

Colors, white, grey, black.

white is undiscovered
grey is discovered, unprocessed.
black is processed.

grey can be next to whites and blacks. Blacks will not be next to whites.

Also keeps track of predecessors, ancestors….if u is on simple path from s to v, then u is an ancestor of v.

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

What attributes of a node are stored in BFS?

A

u.d = distance from s.
u.pi = predecessor/parent
u.color = color.
( another )

19
Q

How do we know that BFS finds the shortest path from s to v?

A

[INSERT] see proof in book….

20
Q

How does DFS work in words?

A

searches all edges out of the current node until they’ve all been explored, then backtracks to the previous. process continues until we’ve discovered everything that’s discoverable from the source, then if there are still undiscovered vertices it makes additional calls.

21
Q

How is the tree created by predecessors in DFS different from that created in BFS?

A

you can actually have multiple independent trees with DFS. Really its a DF forest. Every vertex will end up in its own tree and these trees are disjoint.

22
Q

How is the coloring scheme of DFS similar to BFS? How does DFS coloring relate to d and f values.

A

Both use white - > gray - > black. d values are timestamps for discovery. f values are timestamps for being finished. a node is white when d is infinity. it is gray in between d and f and black after f.

23
Q

What is the definition of a minimum spanning tree? How many does a graph have?

A

connected, undirected graph with weight in amount of wire needed to connect each node.

we want the acyclic subset that connects all.

that’s a spanning tree, the one with minimum weight is the MST.

Could have more than one MST, but only one MST weight.

24
Q

What three things define a tree?

A

Connected, Acyclic, Undirected.

25
Q

What makes a tree into a forest?

A

It has disconnected parts.

26
Q

What makes an edge a safe edge wrt MST creation?

A

We start with A which is a subset of a MST. If we can add the edge {u,v} to A and still be a subset of a MST, then its safe.

27
Q

What is the difference between a cut, a light edge, and an edge “respecting” the cut?

A

A cut is (S, V-S). If an edge has one endpoint in S and the other in V-S, it crosses the cut.

If a sub-graph A has no edges that cross the cut, it respects it.

A light edge is one that crosses a cut and it’s weight is the minimum of any other edge crossing the cut (there can be more than one)

28
Q

What is the fundamental difference in Kruskal and Primm’s MST algorithms? More specifically, what is the generic MST and how do they each differ from it?

A

They use different techniques from the generic MST algorithm on how they determine if an edge is safe or not.

In Kruskal, the set A is a forest whose vertices are all those of the given graph. The safe edge that is added is a least weight edge that connects two distinct components.

In Prim, the set A forms a single tree. The safe edge that is added is a least weight edge that connects the tree to a vertex that is not in the tree.

While Kruskal is a forest with edges slowly added and doesn’t become a tree until the end, Prim is a tree the entire time.

Kruskal maintains a sorted list of all the edges, picking them up one at a time

29
Q

What is the definition of a greedy algorithm? Which algorithms that we’ve used does it work for?

A

At each decision make smallest cost decision at that place.

Works well for MST’s and is used by

30
Q

How does Greedy Algorithm work in MST? Where is the cost of the G.A.?

A

sort edges, check whether smallest is a cycle, then take it. continue until no more are left.

Cost is in the union’s, ie changing all the pointers.

31
Q

What algorithms are Greedy Algorithms?

A

Really, MST is the one where it happens to be advantageous overall to use G.A.

32
Q

What sub-structures are used in Greedy MST?

A

Make-set
Find-set
Union

33
Q

Why is Kruskal a greedy algorithm, and why do we know it works? What concept do we use to prove both of these?

A

Using the concept of a cut, when we cut smartly, with the MST respected by the cut, the lightest edge that crosses the cut HAS to be part of the MST, so each step we’re adding the lightest edge, the best one for this step which is the greedy part.

34
Q

What are the analogies of for Primm and Kruskal

A

Primm’s analogy is the club. I start with a club and dudes not in the club. Each dude outside the club, either knows someone inside, or doesn’t. His cost is how much he will pay the dude inside the club to let him in, to keep down corruption, we want the minimum payments to get in. We prioritize the least cost guy to get in. Once he’s in, everyone outside adjusts their cost to get in. (this new guy may let them get in for cheaper). Once everyone is in, the club is complete.

Kruskal, just looks down at the graph. He sees the shortest edges in order, he picks them up in order, and if they don’t make a cycle in the MST, then he adds them to the forest. There are scattered edges everywhere until the MST is finalizing.

35
Q

Why would I use Primm instead of Kruskal?

A

Intially, both of them run in O(m lg n) time, with Primm using ordinary binary heaps.

If we change Prim to use Fibonacci heaps, we can improve to O(m + n lg n). This is an improvement if n is much smaller than m.

36
Q

What is the definition of a graph traversal?

A

Moving from one point to another along the edges and knowing how many layers, or steps from the start to the end takes. The minimum # of edges from s to v.

Determines is a graph is connected (unconnected nodes still exist when we’re done with algorithm)

Can determine whether or not the graph has a cycle. (could help discover whether graph is bipartite…odd cycles are never bipartite)

If graph is unweighted, this is the shortest path.

37
Q

What is the naïve complexity of a graph traversal, and how do BFS and DFS improve on that?

A

Naively, you look at every vertex,

38
Q

How do we find the diameter using BFS?

A

Run BFS once. Take farthest node from my point….Run BFS again. farthest node from there is the other end.

Relies on fact that every node is either very far or very close to the ends of the diameter.

39
Q

What is the fundamental difference between BFS and DFS?

A

The Datastructure that they use. BFS uses a FIFO structure, while DFS uses a LIFO structure.

Other than that, they’re essentially the same thing, in terms of exploring nodes, coloring grey, black, white.

DFS stores a time of discovery as well and can determine cycles via knowing whether the graph contains edges that are back edges.

BFS uses the concept of a frontier, and/or fire spreading through the graph.

40
Q

How many times will we have to call DFS for connected vs. non-connected graphs?

A

If graph is connected, its called only once. If unconnected, might have to call it more than once.

41
Q

How do we determine if the cross-edges in a DFS are cross or back edges?

A

We use the time stamps and look at “inner walls” of d values.

42
Q

What is significant of a directed, acyclic graph? where would we want to use these?

A

A graph can be very dense and still not contain cycles. I can be almost complete…. We would want to use DAG’s in process graphs, and then use topological sort to determine what things to do in what order, ala the getting dressed analogy.

43
Q

Where is the datastructure for DFS maintained?

A

On the OS stack with the recursive calls of DFS-visit