1 REPRESENTING GRAPHS

A graph is an abstract data type that can be implemented with a variety of data structures. This chapter introduces the fundamental components of a graph, nodes and edges, then shows how to build the two most common graph representations: adjacency lists and adjacency matrices. Understanding the structure and composition of graphs is critical to harnessing their power and designing algorithms to use them efficiently.

To implement the graphs, we define the Edge, Node, and Graph classes upon which almost every algorithm in this book relies. We discuss what information the classes store and provide functions for interacting ...

Get Graph Algorithms the Fun Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.