Learn

Fantastic work! We’ve implemented a robust graph data structure in Python. Our two classes, Vertex and Graph are capable of representing the typical variations in graphs that occur in many different algorithms.

Vertex:

  • Uses a dictionary as an adjacency list to store connected vertices.
  • Connected vertex names are keys and the edge weights are values.
  • Has methods to add edges and return a list of connected vertices.

Graph:

  • Can be initialized as a directed graph, where edges are set in one direction.
  • Stores every vertex inside a dictionary
    • Vertex data is the key and the vertex instance is the value.
  • Has methods to add vertices, edges between vertices, and determine if a path exists between two vertices.

Instructions

Great work implementing a graph. When tackling complex problems, it’s a massive advantage if you can model the problem as a graph.

You’ll see this data structure often while working on algorithms, especially those that focus on networks.

Folder Icon

Sign up to start coding

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

Already have an account?