Neural Sync Active
Week 7: Graphs & Matrices
Registry Synced
Week 7: Graphs & Matrices
3245 words
16 min read
2026-09-12
Reading compass
Now · TL;DR
Computational Thinking — Week 7: Graphs & Matrices
IITM’s CT Week 7 covers Graphs and Matrices.
TL;DR
Week 6 dealt with:
Week 7 moves to:
A graph represents entities as nodes and relationships as edges.
A matrix gives a compact numerical representation of structured relationships.
Core ideas:
- vertex/node
- edge
- directed vs undirected graph
- degree
- paths and connectivity
- matrix rows and columns
- graph ↔ matrix representation
- reading connections from a matrix
1. What is a graph?
A graph is a mathematical/computational structure consisting of:
- vertices (nodes)
- edges (connections)
Notation:
where:
- V = set of vertices
- E = set of edges
2. Example
Suppose:
and:
Conceptually:
textA --- B --- C
There is:
- an edge between A and B
- an edge between B and C
- no direct edge between A and C
3. Real-world graph examples
Graphs can represent:
- people and friendships
- cities and roads
- webpages and links
- computers and network connections
- courses and prerequisites
- airports and flights
The graph abstraction ignores irrelevant details and focuses on:
4. Vertex
A vertex is one entity in the graph.
Example:
textA
could represent:
- a person
- a city
- a computer
- a course
depending on context.
5. Edge
An edge represents a relationship between two vertices.
Example:
textA --- B
could mean:
- A and B are friends
- road connects A and B
- computers A and B communicate
The interpretation depends on the application.
6. Undirected graph
An undirected edge has no orientation.
Notation:
or visually:
textA --- B
If A is connected to B, B is also connected to A.
Examples:
- friendship
- two-way roads
- physical cable connection
7. Directed graph
A directed edge has a direction.
Notation:
or:
textA ---> B
This does not automatically imply:
textB ---> A
Examples:
- Instagram follow
- webpage hyperlink
- prerequisite
- one-way road
8. Directed vs undirected
Undirected
A−Bmeans a symmetric relationship.
Directed
A→Bmeans orientation matters.
This distinction becomes very important when reading matrix representations.
9. Neighbor / adjacency
Two vertices are adjacent if an edge directly connects them.
Example:
textA --- B --- C
A and B are adjacent.
B and C are adjacent.
A and C are not directly adjacent.
10. Neighborhood
The neighborhood of a vertex is the collection of its adjacent vertices.
For:
textA --- B --- C | D
neighbors of B are:
11. Degree
In an undirected graph, the degree of a vertex is the number of incident edges.
Notation:
Example:
textA --- B --- C | D
Then:
12. Degree example
Graph:
textA --- B | | C --- D
Each vertex has degree:
13. Isolated vertex
A vertex with degree:
is isolated.
Example:
textA --- B C
Then:
14. Directed degree
For directed graphs we distinguish:
In-degree
Number of incoming edges.
Out-degree
Number of outgoing edges.
15. Example
textA ---> B ---> C ^ | D
For B:
incoming from:
- A
- D
so:
Outgoing to:
- C
so:
16. Path
A path is a sequence of vertices connected by edges.
Example:
textA --- B --- C --- D
A path from A to D is:
17. Path length
The length of a path is usually the number of edges traversed.
For:
there are:
edges.
So path length:
18. Reachability
Vertex B is reachable from A if there exists a path from A to B.
In directed graphs, reachability depends on edge direction.
Example:
textA ---> B ---> C
C is reachable from A.
But A is not necessarily reachable from C.
19. Connected graph
An undirected graph is connected if every vertex can reach every other vertex through some path.
Example:
textA --- B --- C | D
All vertices belong to one connected structure.
20. Disconnected graph
Example:
textA --- B C --- D
There is no path between:
and:
So the graph is disconnected.
21. Connected components
A disconnected graph can be divided into connected components.
For:
textA --- B C --- D E
components are:
So there are:
components.
22. Cycle
A cycle is a path that returns to its starting vertex.
Example:
textA --- B | | D --- C
Cycle:
23. Self-loop
An edge from a vertex to itself is a self-loop.
Conceptually:
textA ↺
Whether self-loops are allowed depends on the graph definition/problem.
Do not assume unless specified.
24. Complete graph
A complete undirected graph connects every pair of distinct vertices.
Notation:
For n vertices, number of edges:
This connects directly to Stats combinatorics and CT pairwise iteration.
25. Example
For:
number of edges:
Every vertex has degree:
26. Handshaking lemma
In any undirected graph:
Why?
Every edge contributes:
to the degree of each endpoint.
So each edge is counted twice.
27. Example
Suppose degrees are:
Sum:
Therefore:
so:
28. Matrix
A matrix is a rectangular arrangement of values.
Example:
It has:
- 2 rows
- 3 columns
So its dimension is:
29. Matrix entry
The entry in row i, column j is often written:
For:
and:
30. Row vs column
In:
first row:
second column:
Be precise about row/column orientation.
31. Matrix as structured table of numbers
A matrix resembles a numerical table.
But in mathematics/computation, its position structure is especially important.
Each element is identified by:
32. Graph representation using a matrix
One major connection is the adjacency matrix.
Week 8 explicitly continues with adjacency matrices, but Week 7's graph + matrix topics set up this idea.
Suppose vertices:
33. Example graph
textA --- B \ / C
Every pair is connected.
Adjacency matrix:
Rows and columns correspond to:
34. Reading an adjacency-like matrix
Entry:
can mean:
there is an edge from vertex i to vertex j.
Entry:
means:
no edge.
This binary encoding turns graph structure into a matrix.
35. Undirected graph matrix symmetry
For an undirected graph:
implies:
Therefore adjacency matrix is symmetric:
36. Example
M=010101010Since:
in this sense, it can represent an undirected graph.
Graph:
textA --- B --- C
37. Directed graph matrix
For:
textA ---> B ---> C
matrix may be:
This is not symmetric.
That is normal because directions differ.
38. Matrix row interpretation in directed graphs
For an adjacency matrix, a row can represent outgoing edges.
Example:
for vertex A means A has outgoing edges to:
- B
- C
assuming row-as-source convention.
39. Row sum and degree
For a simple undirected graph with binary adjacency matrix:
Example row:
sum:
So degree is:
40. Directed row/column sums
Under the common convention:
when edge:
then:
- row sum = out-degree
- column sum = in-degree
This is a useful graph-matrix connection.
41. Example
M=001100110Row 1 sum:
so vertex 1 has out-degree 2.
Column 1 sum:
so in-degree 1.
42. Diagonal entries
Entries:
lie on the main diagonal.
In a simple graph without self-loops:
for every vertex.
If a diagonal entry is 1, that may indicate a self-loop.
43. Matrix dimensions for graph
If graph has:
vertices, adjacency matrix is:
because every vertex is compared against every vertex.
This is exactly like nested pair iteration.
44. Graph ↔ nested-loop connection
An adjacency matrix essentially stores information for every pair:
Nested iteration:
textfor each i: for each j:
naturally visits every matrix cell.
So CT Weeks 4 and 7 connect directly.
45. Matrix traversal
Conceptually:
textfor each row i: for each column j: process M[i][j]
This is a nested loop.
For an:
matrix, number of cells is:
46. Example
Matrix:
has:
entries.
A full traversal processes six cells.
47. Sum of matrix entries
Algorithm:
texttotal = 0 for each row: for each entry: total = total + entry
For:
sum:
48. Row sums
For:
row sums:
One outer loop per row, one inner loop over columns.
49. Column sums
Column sums:
The traversal ordering may differ depending on algorithm.
50. Matrix transpose intuition
Transposing a matrix swaps rows and columns.
If:
then:
So:
51. Symmetric matrix
A square matrix is symmetric if:
equivalently:
Undirected adjacency matrices are a key example.
52. Matrix and table distinction
Both have rows and columns, but:
Table
Rows often represent heterogeneous records.
Example:
textName | City | Score
Matrix
Entries are usually treated as elements of a uniform rectangular numerical structure.
This distinction matters computationally.
53. Graph representation choices
A graph can be represented in multiple ways.
Conceptually:
- visual diagram
- edge list
- adjacency list
- matrix
Week 7 focuses on graph/matrix foundations; adjacency matrices are developed further in Week 8.
54. Edge-list intuition
Graph:
textA --- B B --- C
could be stored as:
text(A,B) (B,C)
This directly stores existing edges.
55. Matrix intuition
The same graph can be represented by checking every pair:
This uses:
cells.
56. Sparse graph intuition
A sparse graph has relatively few edges compared with all possible pairs.
Example:
vertices but only:
edges.
An adjacency matrix still has:
cells.
Most would be zero.
57. Dense graph intuition
A dense graph has many of the possible edges.
For an undirected simple graph, maximum edges:
When actual edge count is close to that, the graph is dense.
Matrices can become comparatively natural for dense graphs.
Common mistake: vertex vs edge
Vertices are objects.
Edges are relationships.
Do not say:
A-B is a vertex.
It is an edge connecting vertices A and B.
Common mistake: path must be direct
A and C can be connected by a path even if there is no direct edge.
Example:
textA --- B --- C
No edge:
But path exists:
Common mistake: directed edge is reversible
If:
do not assume:
Direction matters unless reverse edge is explicitly present.
Common mistake: degree in directed graph
Do not collapse in-degree and out-degree if the question distinguishes them.
A vertex may have:
and:
Common mistake: path length = number of vertices
Path:
contains:
vertices but:
edges.
Path length is generally measured in edges.
Common mistake: disconnected means no edges
A disconnected graph may contain many edges.
Example:
textA---B---C D---E
Each component contains edges.
The issue is absence of paths between components.
Common mistake: matrix index reversal
means:
not the reverse.
This becomes especially important for directed adjacency matrices.
Common mistake: every square matrix is symmetric
No.
Example:
is square but not symmetric.
Square only means:
Common mistake: undirected adjacency matrix not symmetric
If an undirected simple graph's adjacency matrix has:
but:
something is inconsistent.
An undirected edge must appear in both mirrored positions.
Common mistake: diagonal entries as ordinary edges
In a simple graph with no self-loops:
Do not count diagonal entries as connections between distinct vertices.
Common mistake: edge count from matrix
For an undirected graph, summing all adjacency-matrix entries counts each ordinary edge twice.
So:
for a simple undirected binary adjacency matrix.
69. Example
M=011100100Sum entries:
Therefore edges:
Indeed:
textB --- A --- C
has 2 edges.
70. Directed edge count from matrix
For a directed graph without special complications, each directed edge appears once.
So:
for a binary directed adjacency matrix.
No division by 2.
71. Matrix traversal trace
Suppose:
Algorithm:
textC = 0 for each row i: for each column j: if M[i][j] == 1: C = C + 1
There are three 1s.
So:
72. Graph-degree trace from matrix
Suppose:
Row sums:
Thus degrees:
Check handshaking:
Therefore:
73. Graph representation as abstraction
Suppose four people have dozens of attributes.
For a friendship problem, we may throw away:
- height
- marks
- address
- age
and keep only:
textperson A connected to person B?
That is computational abstraction:
74. Week 7 master map
textGRAPH │ ├── vertices ├── edges ├── directed / undirected ├── degree ├── path ├── reachability ├── connectivity └── cycles ↓ MATRIX REPRESENTATION │ ├── rows / columns ├── entries aᵢⱼ ├── n × n for graph ├── symmetry for undirected graphs └── row/column sums encode degree
75. Weeks 5–7 progression
textWeek 5 List ↓ ordered sequence Week 6 Table / Dictionary ↓ structured records + lookup Week 7 Graph / Matrix ↓ relationships between entities
So CT is gradually introducing different structures suited to different kinds of information.
76. Connection to Maths 1
Maths 1 Week 10–11 covered graph theory more mathematically.
CT Week 7 approaches graphs as a computational representation of data and relationships.
The concepts overlap:
- vertices
- edges
- paths
- matrices
but CT's emphasis is on how algorithms represent and process them.
77. What you should actually master
By the end of CT Week 7, you should be able to:
- Define a graph.
- Distinguish vertices and edges.
- Distinguish directed and undirected graphs.
- Identify adjacent vertices.
- Calculate degree in an undirected graph.
- Distinguish in-degree and out-degree.
- Identify paths and their lengths.
- Understand reachability.
- Distinguish connected and disconnected graphs.
- Identify connected components.
- Recognize cycles.
- Understand matrix rows, columns and entries.
- Determine matrix dimensions.
- Traverse a matrix using nested iteration.
- Understand how a matrix can encode graph connections.
- Recognize symmetry for undirected adjacency matrices.
- Use row sums to infer degrees.
- Avoid double-counting undirected edges in matrix form.
If these are comfortable, Computational Thinking Week 7 is under control.
Quick Recall & Flashcards
Test your active recall before proceeding to practice problems. Format:
Question :: Answer.- Week 7 Diagnostic: In a graph G = (V, E), if |V| = 5, what is the dimension of its adjacency matrix? :: Answer: B — An adjacency matrix has rows and columns corresponding to each vertex, so it is a |V| x |V| matrix (5 x 5).
- Week 7 Diagnostic: In an undirected graph, what property does the adjacency matrix always have? :: Answer: B — Since undirected edges are bidirectional ((u, v) = (v, u)), the adjacency matrix is symmetric.
Practice & Self-Check
Attempt these diagnostic questions to verify your operational understanding.
1
Question 1
In a graph G = (V, E), if |V| = 5, what is the dimension of its adjacency matrix?
MCQ
3 Unit Assessment
A. 5 x 1
B. 5 x 5
C. 10 x 10
D. 5 x 2
2
Question 2
In an undirected graph, what property does the adjacency matrix always have?
MCQ
3 Unit Assessment
A. It is upper-triangular
B. It is symmetric across the main diagonal (A[i][j] = A[j][i])
C. All diagonal elements are 1
D. It is strictly non-zero