Great work! Your Graph class can be used to build graphs of all shapes and sizes. Let’s recap the types of graphs we’ve built and how they modified our implementation.

  • Acyclic graphs: A graph is acyclic if there are no graph cycles. Acyclic graphs had no change to the base implementation.
  • Cyclic graphs: A graph is cyclic if there is at least one graph cycle. Cyclic graphs also did not change the base implementation. This graph, however, greatly changes how to search graphs (you’ll see this in future lessons!)
  • Undirected graphs: Since undirected graphs can travel in both directions from node to node, bidirectional edge support was implemented.
  • Directed graphs: Directed graphs are graphs that dictate the direction in which edges can be traversed. This changed bidirectional support to be an optional request instead of a requirement.
  • Weighted graphs: Weighted graphs provide a numeric value to edges. Since weights are not a requirement when building graphs, our implementation included overloading functions to ensure multiple uses of adding an edge to a graph existed.

Now that our Graph class supports the use of a variety of graphs, let’s create a graph to visualize commercial airliners to put each of the pieces to use!



Build the nodes for each of these airports: "Atlanta", "New York", "Chicago", "Orlando", and "Los Angeles"

Name them atlanta, newYork, chicago, orlando, and losAngeles respectively.


Create a constant graph of type Graph with the nodes above.


Great work! With this graph built, try building some connections between different nodes, then print the graph to make sure that everything is connected correctly. Here’s one set of edges you can use:

  • Atlanta connects to New York for $250
  • Atlanta connects to Orlando for $80
  • Orlando connects to Atlanta for $100
  • Orlando connects to New York for $400
  • Orlando connects to Chicago for $200
  • Los Angeles connects to Chicago for $125
  • Los Angeles connects to Atlanta for $250
  • Chicago connects to New York for $190
  • New York connects to Los Angeles for $400
  • New York connects to Atlanta for $200

Once you’re ready to continue, click the “Up Next” button.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?