Shortest Paths Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a shortest path?

A

A shortest path in a weighted digraph is the path with the smallest total weight from a source vertex to a destination vertex.

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

What is a shortest path tree (SPT)?

A

An SPT is a subgraph containing the source vertex and all vertices reachable from it, forming a directed tree rooted at the source such that every tree path is a shortest path in the digraph.

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

What are the properties of shortest paths?

A
  • Paths are directed
  • Weights are not necessarily distances
  • Not all vertices need to be reachable
  • Algorithms ignore cycles
  • Shortest paths are not necessarily unique
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are edges on the SPT represented?

A

Edges on the SPT are represented using a parent-edge representation in a vertex-index array ‘edgeTo[]’ of DirectedEdge objects, where edgeTo[v] is the edge connecting v to its parent.

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

How is the distance to the source represented?

A

The distance to the source is represented by a vertex-indexed array ‘distTo[]’, where distTo[v] is the shortest known path from the source to v.

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

What is edge relaxation?

A

Edge relaxation is the process of testing whether the best known way from the source to a vertex w is to go through another vertex v using the edge v-w. If this path is shorter, the data structures are updated.

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

What is vertex relaxation?

A

Vertex relaxation involves considering all incoming edges to a vertex and updating the shortest distance based on the shortest distances of its neighboring vertices.

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

What is the importance of edge relaxation?

A

it is the primary method to update shortest path estimates and ensure they are minimized.

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

What is the process to relax an edge in Dijkstra’s algorithm?

A

In Dijkstra’s algorithm, to relax an edge, you update the shortest path estimate if the path through the edge is shorter.

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

What is the process of Dijkstra’s algorithm?

A
  1. Extract vertex with minimum distance v from s from pq.
  2. For each neighbour u of v:
    * If current known distance to u > distance to v + weight of vu, update distance to u and change predecessor to v
    * If distance updated, insert v into PQ with new distance
    * Repeat under PQ empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the space time usage of Dijkstra’s?

A

Space = V
Time = E log V

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

Why does Djikstra’s not work on negative weights?

A

Assumption that adding edges will not decrease length and adding vertex SPT will mean it won’t change afterwards

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

Why can Djikstra’s not be used to find longest path?

A

Selecting node with largest distance may not necessarily lead to finding longest path because it might involve smaller distances

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

How do we find the shortest path in a DAG?

A
  1. Sort topologically
  2. Process each vertex in the sorted order
  3. For each vertex v and its adjacent vertices u:
    * If current distance to u > distance to v + weight of vu, update distance to u
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the time use of relaxing vertices in topological order for shortest and longest paths?

A

E + V

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

How do we find the longest path in a DAG?

A
  1. Sort topologically
  2. Set distances to all other vertices to negative infinity
  3. Process vertex in topological order
  4. For each vertex v and adjacent vertices u:
    * If distance to u is LESS than distance to v + weight of vu, update.

OR

Create copy of given DGA with negated edge weights. The shortest path in the copy is the longest path in the original. Negate the weights in the solution.

17
Q

What is the critical path method?

A
  1. Create DAG with source and sink
  2. Add edge from each job’s start vertex to end vertex
  3. For each precedence constraint v-> w, add zero-weight edge from end of task v to start of w
  4. Add zero-weight edge from source to start vertex of each job
  5. add zero-weight edges frfom end vertex to sink node
  6. Solve using the longest path algorithm for DAG
18
Q

What are the restrictions for Dijkstra’s, topological sort and Bellman ford algorith?

A
  1. Positive edge weights
  2. Edge weighted DAGs
  3. No negative cycles
19
Q

What are the worst case time performances for D, TS, and BF? What are their space uses?

A
  1. Elog V
  2. E + V
  3. VE (has typical of E +V)

V

20
Q

What are the sweet spots for D, TS, BF?

A
  1. Worst-case guarantee
  2. Optimal for acyclic
  3. Widely applicable