Quiz 2

Computational Thinking · Week 7 — Graphs & matrices

1101 words
6 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

vertices, edges, adjacency, matrix cells — concepts, pattern families, and traps for Quiz 2 week 7. # Week 7 — graphs & matrices > **Quiz 2 scope:** Weeks 1–8 per IITM May 2026 foundation courses.

Week 7 — graphs & matrices

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

Vertices & edges → adjacency idea → matrix stores edge data → read cell

Classify → Represent → Execute → Trap-check

  • Recognize: Ask: What does matrix entry (i,j) usually mean?
  • Procedure: Sum or count cells meeting rule (nonzero, or equals 1). Row i entries are out-edges from i in directed graph.
  • Variations / traps: Watch for: Row vs column meaning swapped for directed edges.

Formula chain (compressed)

graph V,E → adjacency list/matrix → matrix[i][j] cell meaning.
  1. GraphG = (V, E) — vertices + edges
  2. Adjacency listneighbours of v — sparse graphs
  3. Adjacency matrixA[i][j] = 1 if edge — dense / quick lookup
  4. UndirectedA symmetric — edge i–j = j–i
  5. Degreecount incident edges — row/column sums

Deep study

Computational Thinking · Week 7 — Graphs and matrices

Deep study for Quiz 2 week 7. Graphs model connections between vertices; matrices store grid or adjacency data in rows and columns.

Week map

Vertex and edge → directed vs undirected → adjacency matrix → matrix indexing → paths and degrees.

Graph notation

  • Vertex (node) → entity → labeled v1,v2,v_1, v_2, \ldots or named A, B, C.
  • Edge → connection between two vertices → (u,v)(u, v).
  • Undirected edge{u,v}\{u, v\} — travel both ways.
  • Directed edge(uv)(u \to v) — one-way arrow from uu to vv.
  • Degree of vertex → number of edges incident → in directed graph: in-degree and out-degree separately.
Mini-example: vertices {A, B, C}, edges A—B, B—C. A has degree 1, B has degree 2, C has degree 1.

Path

  • Path → sequence of vertices where consecutive pairs are edges.
  • Simple path → no repeated vertices.
Path A→B→C exists above; A→C does not (no direct edge).

Adjacency matrix notation

For nn vertices labeled 0..n10..n-1:
  • MM is n×nn \times n matrix.
  • M[i][j]=1M[i][j] = 1 (or weight) if edge from ii to jj exists; else 00.
  • Undirected graph → matrix symmetric: M[i][j]=M[j][i]M[i][j] = M[j][i].
Mini-example: 3 vertices, edges 0—1 and 1—2 (undirected):
text
M = [0 1 0]
    [1 0 1]
    [0 1 0]
Row ii lists neighbors of vertex ii (out-neighbors if directed).

Matrix indexing

  • M[i][j]M[i][j] → row ii, column jj → 0-based unless problem states 1-based.
  • Row ii → all jj values — outgoing from ii.
  • Column jj → all ii values — incoming to jj (directed).

Pattern families

Easy — Read graph from diagram

Count vertices and edges. List neighbors of one vertex. Identify directed vs undirected.

Medium — Build or read adjacency matrix

Fill matrix from edge list. Read M[i][j]M[i][j] for edge existence. Check symmetry for undirected.

Hard — Degree and path reasoning

Compute degree from matrix row sums. Determine if path exists of length 2 (via intermediate vertex). Spot isolated vertex (all zeros in row and column).

Worked mini-examples

Example 1 — Neighbors.
Triangle on {0,1,2} all connected. Each vertex degree 2.
Example 2 — Directed matrix.
Edge 010 \to 1 only: M[0][1]=1M[0][1]=1, M[1][0]=0M[1][0]=0. Not symmetric.
Example 3 — Row sum = out-degree.
Row [0, 1, 1, 0] sums to 2 — vertex has two outgoing edges (directed).
Example 4 — Path length 2.
M[0][1]=1M[0][1]=1 and M[1][2]=1M[1][2]=1 implies path 0→1→2 exists (length 2).
Example 5 — Isolated vertex.
Row and column all zero — no edges incident.

Traps

  • 0-based vs 1-based vertex labels in matrix.
  • Directed edge iji \to j does not imply jij \to i.
  • Counting self-loop M[i][i]=1M[i][i]=1 in degree twice wrongly in undirected mental model.
  • Confusing number of vertices with matrix size nn.
  • Path vs edge — path can use multiple edges.

Diagnostic (try yourself)

  1. Graph with vertices {P, Q, R} and edges P—Q, Q—R. What is degree of Q?
  2. Write adjacency matrix (0/1) for single undirected edge between vertices 0 and 1, no other edges (n=2n=2).
  3. In directed graph, M[2][5]=1M[2][5]=1. What does this mean?
  4. How many edges in undirected graph if adjacency matrix has 6 ones above the diagonal?
  5. Vertex with row sum 0 in directed adjacency matrix — what can you conclude?

ChatGPT prep archive

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

Core concepts

  • Graph: vertices (nodes) and edges (connections); may be directed or undirected.
  • Adjacency: whether edge exists between two vertices.
  • Matrix representation: rows and columns index vertices; cell encodes edge weight or count.
  • Undirected: matrix often symmetric; directed: row → column direction.

Notation & vocabulary

CellMeaning
M[i][j]edge from i to j
0no edge (often)
>0weight or count

Pattern families

Easy — Count edges from matrix

Sum or count cells meeting rule (nonzero, or equals 1). Row i entries are out-edges from i in directed graph.

Medium — Directed vs undirected

Undirected: M[i][j]=M[j][i]. Directed: only one direction may have entry. Neighbor of i: scan row i or column i per definition.

Hard — Path of length 2

Two-step paths via intermediate vertex k: check pairs (i,k) and (k,j). Nested loops over k and j common in CT traces.
Drill these on the pattern atlas — filter to week 7.

Traps

  • Row vs column meaning swapped for directed edges.
  • Assuming symmetry without undirected statement.
  • Diagonal entries (self-loops) policy ignored.
  • Counting each undirected edge twice.

Retrieval prompts

  1. What does matrix entry (i,j) usually mean?
  2. How to tell undirected from matrix?
  3. Where are out-edges of vertex i?

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 7.
  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.