How it works...

When calling the BFS algorithm, the key parameters are fromExpr, toExpr, and maxPathLength. As our vertices contain the airports, to understand the number of direct flights from Seattle to San Francisco, we will specify:

fromExpr = "id = 'SEA'",
toExpr = "id = 'SFO'

The maxPathLength is the parameter used to specify the maximum number of edges between the two vertices. If maxPathLength = 1, it means that we have only one edge between the two vertices. That is, there is only one flight between the two airports or a direct flight between those two cities. Increasing this value means BFS will attempt to find multiple connections between your two cities. For example, if we were to specify maxPathLength = 2, this would mean two edges or two flights between Seattle and San Francisco. That indicates a layover city, for example, SEA - POR -> SFO, SEA - LAS -> SFO, SEA - DEN -> SFO, and so on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset