What Are Graphs?

Get introduced to graphs and their different configurations.

Introduction

Graphs, sometimes called networks, are data structures used to show how different things are connected or related. These things could be places, people, computer databases, and so on. In the graphs, we have points called nodes. The lines between the nodes, called edges, show how the things are connected or related to each other.

Press + to interact
A simple graph with two nodes and one edge
A simple graph with two nodes and one edge

In mathematics, a graph is a set of points (called vertices) connected by lines (called edges).

Family tree example

A family tree can be represented as a graph by considering each person in the tree as a vertex and the relationships between them as edges. In a family tree, the main relationships are typically parent-child and spousal connections. Here's an example of how a simple family tree can be represented as a graph:

Let's assume we have the following family:

Press + to interact
Members of the family represented by nodes.
Members of the family represented by nodes.

In this figure, the family has a couple of parents and two children.

To represent this family as a graph, we can create vertices for each person (A, B, C, and D) and connect them with edges based on their relationships:

  • A node represents each person: A is Parent 1, B is Parent 2, C is Child 1, and D is Child 2.

  • Edges connecting A and B to their children ...