Quiz 2

Computational Thinking · Week 8 — Adjacency & labelled graphs

1031 words
5 min read
2026-08-16T00:00:00.000Z
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

adjacency matrix, edge labels, representation switch — concepts, pattern families, and traps for Quiz 2 week 8. # Week 8 — adjacency & labelled graphs > **Quiz 2 scope:** Weeks 1–8 per IITM May 2026 foundation courses.

Week 8 — adjacency & labelled graphs

Quiz 2 scope: Weeks 1–8 per IITM May 2026 foundation courses. Source baseline: IITM BS admissions important-dates calendar · May 2026 cycle. Times on assessments are operational conventions — verify hall ticket.
Part of the Quiz 2 prep system%20%C2%B7%20%5BWeeks%201%E2%80%938%20index%5D(.%2Fmay-2026-ct-quiz-2-weeks-1-8-prep) · Pattern atlas · Formula chains.

Week map

Adjacency matrix → labelled edges → switch list ↔ matrix view

Classify → Represent → Execute → Trap-check

  • Recognize: Ask: How fill matrix from edge list?
  • Procedure: Zero matrix; for each edge (u,v,w) set M[u][v]=w (and M[v][u] if undirected).
  • Variations / traps: Watch for: Off-by-one vertex numbering (1..n vs 0..n-1).

Formula chain (compressed)

labelled edges → matrix stores weight/label → switch list ↔ matrix.
  1. Labelled edgeedge (u,v,w) — weight or name w
  2. Matrix entryM[u][v] = label or 0 — no edge = sentinel
  3. DirectedM[u][v] ≠ M[v][u] — one-way edges
  4. Representation switchlist ↔ matrix — same graph, two views
  5. Self-loopM[i][i] nonzero? — check diagonal

Deep study

Computational Thinking · Week 8 — Labelled adjacency graphs

Deep study for Quiz 2 week 8. Labels on edges carry weights, costs, or names — adjacency structures must store values, not just 0/1.

Week map

Unweighted vs labelled → weight matrix → multi-graph caution → shortest-path intuition → reading labelled diagrams.

Labelled edge notation

  • Label → data on edge → weight, distance, time, capacity.
  • Weighted graph → each edge has numeric label → often non-negative in intro problems.
  • M[i][j]=wM[i][j] = w → edge from ii to jj has weight ww.
  • M[i][j]=0M[i][j] = 0 or \infty → no edge (convention varies — read problem statement).
Mini-example: three cities 0, 1, 2. Direct roads: 0→1 weight 4, 1→2 weight 2, 0→2 weight 10.
text
     1 --4-- 2
      \       |
       10     2
        \     |
         ---- 3
(Adjust to matrix form in examples below.)

Weight matrix

text
W = [ 0  4 10]
    [ ∞  0  2]
    [ ∞  ∞  0]
Use ∞ or blank for missing edge. W[0][1]=4W[0][1]=4, W[1][2]=2W[1][2]=2. Path 0→1→2 has total weight 4+2=64+2=6, better than direct 0→2 weight 10.

Adjacency list with labels

Alternative to matrix:
text
0 → [(1, 4), (2, 10)]
1 → [(2, 2)]
2 → []
Each entry (neighbor, weight). Space-efficient for sparse graphs.

Directed vs undirected weights

Undirected road length ww on {i,j}\{i,j\} → typically W[i][j]=W[j][i]=wW[i][j] = W[j][i] = w.
Directed → only one direction gets weight unless both stated.

Pattern families

Easy — Read label from diagram

Identify weight on edge between two named vertices. List all neighbors with weights from one vertex.

Medium — Build weight matrix

From edge list (u,v,w)(u, v, w) fill W[u][v]W[u][v]. Handle missing edges with 0 or ∞ per convention.

Hard — Compare path totals

Sum weights along path. Compare two routes. Greedy “pick lightest edge next” may fail globally — but Quiz 2 often asks direct sum comparison only.

Worked mini-examples

Example 1 — Matrix fill.
Edges: (0,1,3), (1,2,5). Directed:
text
W[0][1]=3, W[1][2]=5, others missing
Example 2 — Path sum.
Path 0→1→2: weights 3 + 5 = 8.
Example 3 — Undirected symmetry.
Edge A—B weight 7 → W[A][B]=W[B][A]=7W[A][B]=W[B][A]=7.
Example 4 — No edge.
W[2][0]W[2][0] missing → no direct 2→0 edge in directed sense.
Example 5 — List form lookup.
From vertex 1 list [(0, 2), (2, 4)]: edge to 0 weight 2, to 2 weight 4.

Traps

  • Confusing “no edge” 0 with “zero weight” edge — problem defines convention.
  • Forgetting directed orientation when summing path.
  • Double-counting undirected edge in degree/weight tally.
  • Picking edge with min label locally vs min total path.
  • Vertex label mismatch with matrix index.

Diagnostic (try yourself)

  1. Weighted edge from X to Y is 6. In matrix with X=1, Y=2, what is W[1][2]W[1][2]?
  2. Path A→B→C with weights 3 and 5. Total weight?
  3. Undirected edge weight 4 between vertices 0 and 2. What are W[0][2]W[0][2] and W[2][0]W[2][0]?
  4. Adjacency list for vertex 1 is [(2, 7), (3, 1)]. What is weight of edge 1→3?
  5. Direct path weight 12 vs two-hop path 4+5. Which route is cheaper?

ChatGPT prep archive

Archived import for extra depth — complements the notes above, not official IITM material.

Core concepts

  • Adjacency matrix: n×n for n vertices; entry labels edge or 0/absent.
  • Labelled graph: edges carry names/weights/distances—not just on/off.
  • Switch representation: same graph as edge list or matrix; convert by filling cells.
  • Sparse vs dense: matrix fine small n; list of pairs for few edges.

Notation & vocabulary

RepBest when
matrixdense, fixed n
edge listfew edges
labelweight/name in cell

Pattern families

Easy — Fill adjacency matrix

Zero matrix; for each edge (u,v,w) set M[u][v]=w (and M[v][u] if undirected).

Medium — Read label

Shortest direct connection label is cell value. No edge often 0 or infinity per convention—check problem.

Hard — Convert representations

Matrix to list: scan nonzero cells. List to matrix: place labels at indices. Verify vertex count n consistent.
Drill these on the pattern atlas — filter to week 8.

Traps

  • Off-by-one vertex numbering (1..n vs 0..n-1).
  • Missing reverse edge in undirected fill.
  • Label 0 confused with no edge.
  • Matrix size not matching vertex count.

Retrieval prompts

  1. How fill matrix from edge list?
  2. What is labelled edge?
  3. When matrix vs edge list?

Practice loop

  1. Read Deep study (if present) or core concepts once.
  2. Recite the formula chain without looking.
  3. Open one easy pattern on the interactive atlas for week 8.
  4. Attempt without solutions; mark studied after an honest try.
  5. Say one trap aloud before closing the tab.
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.