Wk 7/8 : SSSP, BF, Dijkstra, APSP, FW, Trans. Closure Flashcards

1
Q

Can a shortest path have cycles? Why not?

A

If you find an SSSP with a cycle, and remove it, you still have a source to definition and the total weight is less.

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

How does the single-source-shortest-path problem relate to its cousins? (what are its cousins?)

A

single-destination (SSSP in opposite direction this would be a column in the matrix)
single-pair (this is a single entry in the matrix, it is already solved when SSSP is run, and its not any faster)
all-pairs shortest path (this is finding every value in the matrix, in other words all the rows and all the columns, therefore also all the pairs/points as well) You don’t need to run SSSP from each vertex to find this, we can do it quicker.

single source finds a row in the matrix.

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

What is the optimal sub-structure of a shortest path mean?

A

Every sub-path of a SSSP is also a SSSP. This is what connects this to dynamic programming and the greedy method.

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

What is the relationship between negative weight cycles and the shortest path algorithms?

A

shortest path is not defined for a graph that has negative weight cycles, because any shortest path would continually go round and round that cycle and get -INF weight

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

What is the main difference between Dijkstra and Bellman-Ford with regard to assumptions?

A

Bellman-Ford can handle negative weight edges but is slower. Dijkstra takes advantage of the assumption that if there are no negative edge weights and runs faster than Bellman-Ford.

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

How do we track the actual shortest path found by the algorithm?

A

With predecessor pointers and Shortest-Path trees.

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

What is the general format for all the algorithms in this chapter? (BF and Dijk)

A

Initialize the d values and pointers of every node, then repeatedly “relax” the deges until we have the shortest path

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

How does Bellman-Ford return whether or not there are negative weight cycles in the graph?

A

After it runs to get the shortest path, it runs one more time and if the weights decrease again, then we know there’s a negative cycle somewhere.

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

What is the main data structure of Dijkstra’s algorithm? Why?

A

Priority Queue…

[INSERT]

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

How does Dijkstra use the assumption of no negative edge weights in its advantage?

A

[INSERT]

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

What are the similarities between Dijkstra and Primm? What are the differences?

A

[INSERT]

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

Why is Dijkstra considered to be a greedy algorithm?

A

Each time through its loop it pulls the current lowest value vertex from the priority queue to add to the set S which is the growing SSSP.

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

Prove that the u that comes off the priority queue in Dijkstra is in fact the SP….

A

[INSERT]

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

How is Dijkstra similar to both Primm and BFS?

A

Single source shortest path algorithms (Dijkstra) are just BFS with different data structures. Dijkstra uses a priority queue. BFS only used a standard queue. Primm used priority queue as well.

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

How many times do we have to run the EXTEND SHORTEST PATHS within the SLOW-ALL-PAIRS SHORTEST PATHS algorithm? How about for the FAST?

A

We have to do it n-1 times. Once we hit the nth time, the matrix values don’t change. Essentially every edge and every path has been looked at. For the fast, it’s CLG(lg n) because that’s how many times it takes until we’re bigger than n. Book says that all L^m = L^n-1 for all m >= n-1

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

What are the math replacements required to make FAST-APSP equivalent to matrix multiplication?

A

see note card

17
Q

What is a transitive closure of a graph and how is it different from a standard graph?

A

Transitive closure is a {V,E} where E instead of having all the edges that exist in the graph has all the paths that exist in the graph.

18
Q

Why would we prefer the Transitive-Closure version algorithm over a FW run with each edge weight set to 1?

A

Because on most machines, logical operations run faster than arithmetic operations, also, because boolean values are smaller than integer, it likely takes up less space as well

19
Q

How could we use FW to determine the transitive closure of a graph?

A

set all edges weight to 1 and run FW. Those with a path get d

20
Q

What is dynamic programming?

A

Using the concept of sub-optimality (think SSSP) we take a small solution and grow it with one extra degree of freedom each time. Previous solutions are look-ups…And each sub-part of the total solution is itself a solution of the smaller problem.

21
Q

What is triangle inequality and why does it matter for SSSP?

A

If I have a shortest path from s to v. by definition its the shortest way to get there. I can’t go somewhere else and get there in anything less than the same amount of time, likely more.