Introduction to Graphs

A graph is a collection of nodes that are connected in pairs. In data structures, these nodes are called vertices (singular: vertex), and the connections between them are known as edges. Graphs are incredibly useful for modeling relationships and connections in the real world, especially when dealing with interconnected entities.

Key Concepts

  • Vertex: Also known as a node, a vertex represents a point in a graph where data can be stored. Vertices are essential components of a graph.

  • Edge: An edge is a line that connects two vertices in a graph, establishing a relationship between them. Edges can be directed (one-way) or undirected (two-way).


Why Graphs Matter in the Real World

Graphs are invaluable because they can model so many different kinds of connections:

  • Social Networks: Platforms like Facebook and LinkedIn use graphs to show who your friends are and how you're connected to others.
  • Family Trees: Those charts showing your ancestors? They're graphs! They trace connections between family members across generations.
  • Recommendations: Amazon's "Customers who bought this also bought..." feature uses graphs to show product relationships based on purchases.
  • Navigation: Google Maps finds the best route to your destination by using a graph of roads and intersections.

In the next assignment, we'll dive into some of the most common and useful types of graphs.