Overview
A graph is a data structure used to represent relationships between things. It is made up ofnodes (vertices) that represent the objects you care about and edges that represent the connections between them.

Types of Graphs
Directed Graph: Edges have a direction, so a connection goes from one node to another.




Here, the most efficient way from
A to D is ABCD (the shortest path).
Here, the most efficient way from
A to D is AFGBCD (the lowest total cost).Code Representations
There are three common ways to represent a graph in code.Example graph:

Edge Lists
A graph is stored as a plain list of edges. Each edge is a pair (from, to) for unweighted graphs, or a triple (from, to, weight) for weighted graphs.
Adjacency Matrices
A graph is stored as a 2D grid of values. The cell at (i, j) indicates whether there is an edge from node i to node j (often 0/1), or stores the edge weight in weighted graphs.
Adjacency Lists
A graph is stored as a mapping from each node to its neighbors. Each key is a node, and its value is a list of directly connected (outgoing) nodes (or pairs like (neighbor, weight) for weighted graphs).