Visual walkthrough — Representations — adjacency matrix (space O(V²)), adjacency list (space O(V+E))
Before any symbol: we will use the letter for how many dots (vertices) are in our graph, and for how many lines (edges) connect them. That is all and ever mean. Let's earn everything else.
Step 1 — What a graph actually is (dots and lines)
WHAT. We draw the four dots and the four friendships .
WHY. Every storage decision below is a decision about how to write this picture down in memory. You cannot judge "wasteful" or "efficient" without the picture in front of you.
PICTURE. Look at the figure: four blue dots, four orange lines. Count them — dots, lines. Notice vertex is popular (touches three others) while vertex is lonely (touches only one).

Step 2 — The grid idea: reserve a box for every pair
WHAT. Draw a checkerboard with all dots along the top and the same dots along the side. Every little box sits at a crossing of one top-dot and one side-dot — i.e. one ordered pair .
WHY a grid and not something cleverer? Because we want the fastest possible answer to "is – an edge?". A grid gives it a fixed home address (row , column ) so we can jump straight there. No searching. That speed is the whole reason the grid exists.
PICTURE. The figure shows the empty grid. Count the boxes: 4 rows 4 columns boxes. We reserved a box for the friendship – and for the non-friendship – — the grid does not care whether the edge exists, it books a box either way.

Step 3 — Fill the grid: this is the adjacency matrix
WHAT. Put a (green) in a box when its two dots are friends, a (gray) when they are not.
WHY. We are converting the picture (Step 1) into numbers a computer can index. The / choice is the simplest encoding of "yes edge / no edge."
PICTURE. Look at row 2 (vertex 2) in the figure: green s sit in columns — exactly the three friends of vertex 2 — and a gray in column (you are not your own friend, no self-loop).
Each entry: means row-dot shakes hands with column-dot .

Step 4 — Count the grid's cost: where is born
WHAT. Count every box we reserved: rows times columns.
WHY. "Space cost" = how many memory slots we occupy. Every box is one slot, occupied whether it holds a or a lonely .
PICTURE. In the figure, the green boxes are real friendships; the gray boxes are wasted — reserved for pairs who are not friends. Same total either way.
The (Big-O Notation) means "grows like" — for large the cost climbs like . For our tiny graph boxes to store just edges: already wasted.

Step 5 — A different idea: give each dot a sticky note
WHAT. Throw away the grid. Instead give each of the dots one sticky note that names only its actual friends.
WHY a list and not the grid? Because the grid's gray boxes were pure waste. A sticky note writes down a friend only when the friendship exists — so nothing is spent on the millions of non-friendships. We trade instant lookup for tiny size.
PICTURE. The figure shows four sticky notes. Vertex 3's note is nearly empty ([2]); vertex 2's note is the longest ([0,1,3]). Note length matches popularity — this is the key difference from the fixed-size grid rows.
0 -> [1, 2]
1 -> [0, 2]
2 -> [0, 1, 3]
3 -> [2]

Step 6 — Count the sticky notes: where is born
WHAT. Add up: note-headers, plus one written name for every edge-endpoint.
WHY two names per edge? Friendship must appear on note 0 (so 0 can find 1) and on note 1 (so 1 can find 0). Look back at Step 5: 1 is on note 0 and 0 is on note 1. Undirected ⇒ each edge is written twice.
PICTURE. In the figure, colored arrows pair up the two copies of each edge. Count the names across all notes: . Add the note-headers.
For our graph: entries. (In a directed graph you'd write each edge once → .)

Step 7 — The degenerate cases (never leave a scenario unshown)
WHAT. Compare the two representations at the boundaries.
WHY. A formula you only tested in the middle can lie at the edges. We check both ends so no reader hits a surprise.
PICTURE. The figure has two panels:
- Empty graph (): grid still books gray boxes (huge waste); sticky notes cost just empty headers. List wins by a mile — this is a sparse graph.
- Complete graph (, everyone friends with everyone): every box is green, and every note is nearly full. Now , so the list is also — no size win — and the grid gives lookups on top. Matrix wins — a dense graph.
Here ("V choose 2") counts how many pairs of dots exist — the maximum possible number of undirected edges.

Recall Self-test the extremes
On an empty graph, which representation wastes memory ::: The matrix — boxes for edges; the list costs only . When does the list's size stop beating the matrix ::: On a dense graph where , since .
The one-picture summary

This is why traversals like Breadth-First Search (BFS) and Depth-First Search (DFS) run in on lists (they only walk real edges), while Floyd-Warshall Algorithm and edge-heavy matrix tricks prefer the grid's lookups. Dijkstra's Algorithm on a sparse graph also rides the list.
Recall Feynman retelling (say it to a 12-year-old)
Four kids; some are friends. Grid way: draw a checkerboard with every kid on the top and side, tick a box for each friendship. Checking any pair is instant — but you drew a box for every possible pair, so most boxes sit empty and wasted. Its size is , no matter how few friendships exist. Sticky-note way: give each kid a note listing only their friends. Tiny when friendships are rare. Its size is notes plus two names per friendship (), so . Few friends → sticky notes (list). Everyone-knows-everyone → the grid is just as small and faster, so use the grid (matrix).