# Graph (Data Structure)

> Nodes joined by edges, where any node can link to any other.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Graph, Network Graph, Nodes and Edges

## Think of it like

Think of it like a map of towns joined by roads. Any town can link to any other.

## Definition

A graph is a set of nodes joined by lines called edges. Unlike a tree, any node can link to any other, and the links can form loops. Edges can have a direction, like a one-way street, and a weight, like a distance. Road maps, friend networks and links between web pages are all graphs. Many hard problems become easier once you see them as one.

## Example

Emma's social app stores who follows whom as a graph. Finding friends of friends means walking two edges out from her.

## Why it matters

Road trips, friend lists and web links are all graph problems underneath.

## Common mistake

Walking a graph without marking the nodes you have seen. Because of loops, the walk can go round forever.

## Three principles

- **Nodes and edges.** Things and links.
- **Loops allowed.** Unlike a tree.
- **Direction and weight.** One-way, distance, cost.

## Related terms

- [Tree (Data Structure)](https://learn.benibix.com/term/development/tree)
- [Breadth-First Search (BFS)](https://learn.benibix.com/term/development/breadth-first-search)
- [Depth-First Search (DFS)](https://learn.benibix.com/term/development/depth-first-search)
- [Dijkstra's Algorithm](https://learn.benibix.com/term/development/dijkstras-algorithm)
- [Pathfinding](https://learn.benibix.com/term/development/pathfinding)
- [Directed Acyclic Graph (DAG)](https://learn.benibix.com/term/development/directed-acyclic-graph)
- [Code Graph](https://learn.benibix.com/term/development/code-graph)

## Told apart from

- [Tree vs Graph](https://learn.benibix.com/compare/tree-vs-graph): A tree is a graph with rules. It has one root and no loops, so there is one path to each node. A graph may link any node to any other, loops and all.

---

Source: https://learn.benibix.com/term/development/graph
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
