Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
SFO
0
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
SFO
184
0
946
621
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
SFO
371
328
184
0
946
621
1575
PVD
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
SFO
371
328
184
0
946
621
1575
3075
BOS
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
SFO
371
328
184
0
946
621
1423
3288
2467
MIA
3288
ORD
BOS
PVD
JFK
MIA
DFW
LAX
SFO
371
328
184
0
946
621
1423
2658
2467
BWI
DFW
LAX
SFO
371
328
184
0
946
621
1423
2658
2467
ORD
BOS
PVD
JFK
BWI
MIA
DFW
LAX
fill up the gas tank in City 1
for c = 2 to n –1 do
// decide whether to stop in City c for gas while approaching
(2.1) if there is still enough gas to go to City ( c +1) then
don’t stop in City c
(2.2) else
fill up the gas tank in City c
It can be proved that this greedy algorithm minimizes the number of gas
stops. The time complexity is O( n ) because the loop in Step (2) runs O( n )
iterations in which each iteration uses O(1) time (in Steps (2.1) and (2.2)).
Proofs Techniques for Greedy Algorithms