In the database, you will consider your city network as a tree, with the outgoing city as the root, and each outgoing flight is a pointer to a child. You will do a recursive depth search using the tree to find all the paths to the destination, but checking the loop when you go and interrupting any path that leads to the loop.
When you find possible paths, you can either just save the shortest, but find it as the only solution; or keep a higher subset of the paths found, stratified by some criteria regarding departure time, if you want to choose on this basis.
Depending on the specifics of the database and nodes, you can also use other rules to reduce your search for paths, for example, if you know that the departure and destination are located at a distance of 1000 miles and your trace is still flying at 3000 miles, and you're still not there, spin it, go to the next search path.
source share