Graphs

Concept shape

Core
Definition

A graph models relationships between nodes using edges.

Step 1 / 5
Concept shape
Current lesson

Graphs Lab

Graphs Core

Graphs

Welcome to the Graphs concept lab. A graph represents things as nodes and relationships as edges. The same idea can model friends in a social network, cities connected by roads, web pages connected by links, or dependencies between services. Graph problems usually start by choosing a representation, then carefully tracking visited nodes so traversal does not loop forever. The must know points are: Graphs can be directed or undirected. Edges can be weighted or unweighted. Visited tracking prevents loops. The common operations are: add node, add edge, traverse neighbors. The complexity shape is Traversal O(V + E). Watch out for these pitfalls: Not marking visited. Confusing directed and undirected edges. Related algorithms include BFS, DFS, Dijkstra Shortest Path.

Concept details

A graph represents things as nodes and relationships as edges.

The same idea can model friends in a social network, cities connected by roads, web pages connected by links, or dependencies between services.

Graph problems usually start by choosing a representation, then carefully tracking visited nodes so traversal does not loop forever.

Must know

  • Graphs can be directed or undirected.
  • Edges can be weighted or unweighted.
  • Visited tracking prevents loops.

Complexity

Traversal O(V + E)

Open deeper visual structure lesson
1.0x