Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm For Flight Schedules

I have a list of all direct flights. From this I want to get flights from A to B with connections. What will be a suitable algorithm or data structure for this problem? Thanks.

like image 782
fastcodejava Avatar asked Jan 21 '26 01:01

fastcodejava


1 Answers

Basically, this is a matter of traversing a graph, where each departure or arrival will be a node, and each flight an edge. You'll typically apply costs to the edges -- depending on the user's preference, the "cost" might be the cost of the ticket (to get lowest price), or the flight time (to get the shortest flight time). An arrival and departure at the same airport will be connected by an edge whose cost is the layover time (and from a price viewpoint, that edge will normally have a cost of zero).

like image 177
Jerry Coffin Avatar answered Jan 23 '26 14:01

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!