single-source shortest paths Flashcards

all shortest path algorithms (14 cards)

1
Q

What is the primary purpose of shortest-path algorithms?

A

To find the shortest path between nodes in a graph.

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

True or False: Dijkstra’s algorithm can handle negative weight edges.

A

False.

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

Fill in the blank: The __________ algorithm is used for finding the shortest paths from a single source vertex to all other vertices in a graph with negative weight edges.

A

Bellman-Ford

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

Which algorithm is generally more efficient for graphs with non-negative weights, Dijkstra’s or Bellman-Ford?

A

Dijkstra’s algorithm.

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

What is the time complexity of Dijkstra’s algorithm using a priority queue?

A

O((V + E) log V), where V is the number of vertices and E is the number of edges.

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

what is the psduecode for bellman ford

A

BELLMAN-FORD.G; w; s/
1 INITIALIZE-SINGLE-SOURCE.G; s/
2 for i D 1 to jG:Vj 1
3 for each edge .u; / 2 G:E
4 RELAX.u; ; w/
5 for each edge .u; / 2 G:E
6 if :d > u:d C w.u; /
7 return FALSE
8 return TRUE

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

I Eat Really Cold Ice For Good

A

“I Eat Really Cold Ice For Good “

Breakdown:

I — Initialize single source

E — Edges loop |V| - 1 times

R — Relax each edge

C — Check for negative cycles

I — If d[v] > d[u] + w(u,v)

F — False → negative cycle

V — Valid path → no neg cycle

G — Good to return TRUE

T — Termination success

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

what is the pedosocde for INITIALIZE-SINGLE-SOURCE

A

INITIALIZE-SINGLE-SOURCE.G; s/
1 for each vertex v E G.V
v.d = infity
v.pi =NIL
s.d = 0

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

path relaztion proof

A

=[=p—

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

what is the pedosocde for Relax ?

A

RELAX(u,v,w)
if v.d > u.d +w(u,v)
v.d = u.d+w(u,v)
v.pi=u

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

psdeocode for dag shirest path

A

DAG-SHORTEST-PATH(G,w,s)
topologically sort the vertices
INIT-SINGLE-SOURCE(G,s)
for each vertex u, taken in topicallay sorted order
for each vertex v E G.adj[u]
relax(u,v,w)

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

corretness for dag shirtest path

A
  • becausse we process vertices in topoglovally sorted order,edges of any path must be relaxed in order of appearance in the path.
  • edges on any shortest path are relaxed in order

by path relaztio theroem, correct

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

psedocode for dikstra algoritm

A

DIJKSTRA(G, w, s):
INITIALIZE-SINGLE-SOURCE(G, s)
S = {} // The set of processed vertices
Q = G:V // The priority queue with all vertices
while Q ≠ ∅:
u = EXTRACT-MIN(Q) // Extract the vertex with the minimum distance
S = S ∪ {u} // Add u to the set of processed vertices
for each v ∈ G:Adj[u]:
RELAX(u,v,w) // Relaxation step

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

do example on page 680

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