Week 10: Graph Theory, Representations, BFS & DFS

4108 words
21 min read
2026-09-12T00:00:00.000Z
Maths Week 1: the start of the relation ladder
Visual companion
Maths
Sets and relations

Maths Week 1: the start of the relation ladder

View
Revision summary

What this note is really saying

Short form

Vertices, edges, degrees, handshaking lemma, adjacency matrices/lists, BFS, DFS, trees, DAGs, and topological sorting. # Mathematics I — Week 10: Graph Theory, Representations, BFS & DFS IITM’s Week 10 moves into **graph theory: representation of graphs, breadth-first search, depth-first search, applications of BFS/...

Visual strip

Relevant recall pieces for this note

Open gallery

Mathematics I — Week 10: Graph Theory, Representations, BFS & DFS

IITM’s Week 10 moves into graph theory: representation of graphs, breadth-first search, depth-first search, applications of BFS/DFS, and directed acyclic graphs.

TL;DR

A graph models objects and relationships:
G=(V,E)G=(V,E)
where:
  • VV = vertices/nodes
  • EE = edges/connections
The highest-value Week 10 ideas are:
  • graph vocabulary
  • undirected vs directed graphs
  • adjacency representations
  • degree / in-degree / out-degree
  • paths and connectivity
  • BFS
  • DFS
  • connected components
  • cycles
  • DAGs
  • why BFS and DFS have different behavior

1. What is a graph?

A graph is usually written:
G=(V,E)\boxed{ G=(V,E) }
where:
  • VV is a set of vertices
  • EE is a set of edges
Example:
V={A,B,C,D}V=\{A,B,C,D\}
and:
E={{A,B},{B,C},{C,D}}.E=\{\{A,B\},\{B,C\},\{C,D\}\}.
This describes:
text
A — B — C — D

2. Why graphs matter

Graphs can model:
  • social networks
  • roads
  • airline routes
  • web pages and hyperlinks
  • computer networks
  • dependencies
  • family trees
  • recommendation systems
  • state transitions
  • knowledge graphs
The abstraction is:
entities + relationships

3. Undirected graph

In an undirected graph, an edge has no direction.
If:
{A,B}∈E,\{A,B\}\in E,
then AA is connected to BB and BB is connected to AA.
Graphically:
text
A — B

4. Directed graph

A directed graph or digraph uses directed edges:
(A,B)(A,B)
meaning:
A→B.A\to B.
This does not automatically imply:
B→A.B\to A.
Example:
text
A → B → C
Directed graphs are useful for:
  • follower relationships
  • prerequisites
  • hyperlinks
  • workflows
  • dependency graphs

5. Vertex / node

A vertex is one object in the graph.
Plural:
  • vertices
  • nodes
These terms are often used interchangeably.

6. Edge

An edge represents a relationship between vertices.
Undirected:
{u,v}\{u,v\}
Directed:
(u,v)(u,v)
or:
u→v.u\to v.

7. Adjacent vertices

Two vertices are adjacent if an edge connects them.
If:
A−B,A-B,
then:
AA
and:
BB
are adjacent.

8. Neighbors

The neighbors of a vertex are all vertices directly connected to it.
For:
text
A — B — C
    |
    D
neighbors of BB are:
{A,C,D}.\{A,C,D\}.

9. Degree of a vertex

In an undirected graph, the degree of vertex vv is the number of incident edges.
Notation:
deg⁡(v)\deg(v)
Example:
text
A — B — C
    |
    D
Then:
deg⁡(B)=3.\deg(B)=3.
And:
deg⁡(A)=1.\deg(A)=1.

10. Handshaking lemma

For an undirected graph:
∑v∈Vdeg⁡(v)=2∣E∣\boxed{ \sum_{v\in V}\deg(v)=2|E| }
Why?
Every edge contributes:
11
to the degree of each of its two endpoints.
So each edge gets counted twice.

11. Consequence: odd-degree vertices

The number of vertices with odd degree is always even.
This follows from the handshaking lemma.
A surprisingly useful graph-theory fact.

12. In-degree and out-degree

For directed graphs:

In-degree

Number of edges entering a vertex.
deg⁡−(v)\deg^-(v)

Out-degree

Number of edges leaving a vertex.
deg⁡+(v)\deg^+(v)
Example:
text
A → B ← C
    ↓
    D
For BB:
deg⁡−(B)=2\deg^-(B)=2
and:
deg⁡+(B)=1.\deg^+(B)=1.

13. Directed degree identity

For a directed graph:
∑vdeg⁡−(v)=∣E∣\boxed{ \sum_v \deg^-(v)=|E| }
and:
∑vdeg⁡+(v)=∣E∣\boxed{ \sum_v \deg^+(v)=|E| }
Each directed edge contributes once to total in-degree and once to total out-degree.

14. Walk

A walk is a sequence of vertices where consecutive vertices are connected.
Vertices and edges may repeat.
Example:
A→B→C→B→D.A\to B\to C\to B\to D.
This can be a valid walk even though BB repeats.

15. Path

A path typically means a walk without repeated vertices.
Example:
A→B→C→D.A\to B\to C\to D.
Path length is usually the number of edges.
So:
A−B−C−DA-B-C-D
has length:
3.3.

16. Cycle

A cycle starts and ends at the same vertex, without unnecessary repetition of internal vertices.
Example:
text
A — B
|   |
D — C
One cycle:
A→B→C→D→A.A\to B\to C\to D\to A.

17. Connected graph

An undirected graph is connected if every pair of vertices has a path between them.
Example:
text
A — B — C
    |
    D
Everything is reachable from everything else.
So the graph is connected.

18. Disconnected graph

Example:
text
A — B     C — D
There is no path from AA to CC.
So the graph is disconnected.

19. Connected components

A connected component is a maximal connected part of a graph.
For:
text
A — B     C — D — E     F
there are:
33
connected components:
{A,B}\{A,B\} {C,D,E}\{C,D,E\} {F}.\{F\}.

20. Complete graph

A complete graph has an edge between every pair of distinct vertices.
Notation:
Kn.K_n.
For nn vertices, the number of edges is:
(n2)=n(n−1)2\boxed{ \binom n2=\frac{n(n-1)}2 }

21. Why?

Each edge corresponds to choosing:
22
vertices from nn.
So:
∣E∣=(n2).|E|=\binom n2.
Example:
K5K_5
has:
5⋅42=10\frac{5\cdot4}{2}=10
edges.

22. Graph representation problem

A graph is an abstract object.
A computer needs a concrete representation.
Two major representations:
  1. adjacency matrix
  2. adjacency list

23. Adjacency matrix

For nn vertices, create an:
n×nn\times n
matrix.
Let:
Aij={1,if edge i→j exists0,otherwiseA_{ij}= \begin{cases} 1,&\text{if edge }i\to j\text{ exists}\\ 0,&\text{otherwise} \end{cases}
For undirected graphs, the matrix is symmetric.

24. Example

Graph:
text
A — B
|
C
Ordering:
A,B,C.A,B,C.
Adjacency matrix:
(011100100)\begin{pmatrix} 0&1&1\\ 1&0&0\\ 1&0&0 \end{pmatrix}

25. Why diagonal entries are often zero

In a simple graph, there are no self-loops.
So:
Aii=0.A_{ii}=0.
If self-loops are allowed, diagonal entries may be nonzero.

26. Symmetry in undirected graphs

If:
A−B,A-B,
then:
AAB=1A_{AB}=1
and:
ABA=1.A_{BA}=1.
Therefore:
A=AT\boxed{ A=A^T }
for simple undirected graphs.

27. Adjacency list

Instead of storing an entire matrix, store each vertex's neighbors.
Example:
text
A — B
|
C
Adjacency list:
text
A: B, C
B: A
C: A

28. Matrix vs list

Adjacency matrix

Space:
O(V2)O(V^2)
Good for:
  • dense graphs
  • fast edge existence lookup

Adjacency list

Space:
O(V+E)O(V+E)
Good for:
  • sparse graphs
  • traversal algorithms
Most real-world sparse graphs favor adjacency lists.

29. Edge lookup complexity

With adjacency matrix:
Is there edge (u,v)(u,v)?
Usually:
O(1).O(1).
With adjacency list:
depends on how neighbors are stored.
Potentially:
O(deg⁡(u)).O(\deg(u)).

30. Graph traversal

Graph traversal means:
systematically visit vertices of a graph.
Two fundamental algorithms:
BFS\boxed{\text{BFS}}
and:
DFS.\boxed{\text{DFS}}.
BFS = Breadth-First Search.
Core idea:
Explore the graph layer by layer.
Starting from a source:
  1. visit source
  2. visit all neighbors
  3. visit neighbors of those neighbors
  4. continue outward

32. BFS mental picture

Suppose:
text
        A
      /   \
     B     C
    / \     \
   D   E     F
Starting BFS at:
A,A,
a typical traversal:
A,B,C,D,E,F.A,B,C,D,E,F.
It visits by distance layers:
0,1,2,…0,1,2,\dots

33. BFS uses a queue

BFS is naturally implemented using a queue.
Queue behavior:
FIFO\boxed{\text{FIFO}}
First In, First Out.
Conceptually:
text
enqueue(start)

while queue not empty:
    v = dequeue()
    for each unvisited neighbor u:
        mark u visited
        enqueue(u)

34. Why marking visited matters

Graphs can contain cycles.
Without a visited set:
text
A — B
|   |
D — C
the algorithm could keep looping:
A→B→C→D→A→⋯A\to B\to C\to D\to A\to\cdots
So each vertex should generally be marked visited.

35. BFS and shortest paths

One of BFS's most important properties:
In an unweighted graph, BFS finds shortest paths measured by number of edges.
Why?
Because it explores vertices in increasing distance from the source.
First:
00
edges away.
Then:
11
edge away.
Then:
22
edges away.
And so on.

36. Example

Graph:
text
A — B — D
|   |
C — E
Start:
A.A.
Distances:
d(A)=0d(A)=0 d(B)=1,d(C)=1d(B)=1,\qquad d(C)=1 d(D)=2,d(E)=2.d(D)=2,\qquad d(E)=2.
BFS naturally discovers these layers.

37. BFS applications

Common applications:
  • shortest path in unweighted graph
  • finding connected components
  • network broadcasting
  • degree-of-separation problems
  • web crawling
  • bipartite testing
  • level-order exploration

DFS = Depth-First Search.
Core idea:
Go as deep as possible before backtracking.
From a vertex:
  1. choose an unvisited neighbor
  2. explore it
  3. continue deeper
  4. when stuck, backtrack

39. DFS mental picture

Using:
text
        A
      /   \
     B     C
    / \     \
   D   E     F
Possible DFS:
A,B,D,E,C,F.A,B,D,E,C,F.
Exact order depends on neighbor ordering.
The defining feature is depth-first behavior, not one fixed output sequence.

40. DFS uses a stack

DFS can be implemented using:
  • recursion
  • explicit stack
Stack behavior:
LIFO\boxed{\text{LIFO}}
Last In, First Out.
Recursive pseudocode:
text
DFS(v):
    mark v visited

    for each neighbor u of v:
        if u not visited:
            DFS(u)

41. Backtracking intuition

DFS explores:
text
A
↓
B
↓
D
If DD has nowhere new to go, it returns:
text
D
↑
B
Then explores another branch.
That returning behavior is backtracking.

42. DFS applications

DFS is useful for:
  • connected components
  • detecting cycles
  • topological sorting
  • maze exploration
  • dependency analysis
  • path existence
  • structural graph analysis
  • strongly connected components in more advanced settings

43. BFS vs DFS

BFSDFS
breadth firstdepth first
queuestack/recursion
explores levelsexplores branches
shortest unweighted pathnot generally shortest
useful for distanceuseful for structure/backtracking
Neither is universally "better."
They solve different kinds of problems naturally.

44. BFS complexity

Using adjacency lists:
O(V+E)\boxed{ O(V+E) }
Why?
Each vertex is processed at most once.
Each edge is examined a constant number of times.

45. DFS complexity

Also:
O(V+E)\boxed{ O(V+E) }
with adjacency-list representation.
So asymptotically BFS and DFS often have the same traversal complexity.
Their behavior and applications differ.

46. Traversal on disconnected graphs

Starting BFS/DFS from one vertex only explores its connected component.
To visit the entire graph:
text
for each vertex v:
    if v unvisited:
        BFS(v)
or DFS.
Each new traversal discovers another component.

47. Counting connected components

Initialize:
count=0.count=0.
For every unvisited vertex:
  1. increment count
  2. run BFS/DFS from it
At the end:
countcount
equals number of connected components.

48. Cycle detection intuition

In an undirected graph during DFS:
If you encounter a visited neighbor that is not the current vertex's parent, you have found a cycle.
In directed graphs, cycle detection requires tracking traversal state more carefully.

49. Trees

A tree is an undirected graph that is:
  • connected
  • acyclic
A tree with:
nn
vertices always has:
n−1\boxed{n-1}
edges.

50. Equivalent tree characterizations

For a finite undirected graph, several statements are equivalent:
  • connected and acyclic
  • exactly one simple path between every pair of vertices
  • connected with ∣V∣−1|V|-1 edges
  • acyclic with ∣V∣−1|V|-1 edges
These relationships are highly useful.

51. Why trees matter here

BFS and DFS naturally generate search trees.
As you discover new vertices, you can remember which vertex discovered each one.
Those parent relationships form a tree.

52. BFS tree

A BFS tree rooted at source ss organizes vertices by distance:
text
distance 0: s
distance 1: neighbors
distance 2: neighbors of neighbors
...
So it captures shortest unweighted distances.

53. DFS tree

A DFS tree captures the recursive exploration structure.
It is especially useful for reasoning about:
  • ancestry
  • backtracking
  • cycles
  • ordering

54. Directed Acyclic Graph

A DAG is a:
Directed Acyclic Graph\boxed{\text{Directed Acyclic Graph}}
So it is:
  1. directed
  2. contains no directed cycle
Example:
text
A → B → D
 \      ↑
  → C ──
provided there is no route that returns to the starting node following arrow directions.

55. Why DAGs are important

DAGs model dependencies.
Examples:

Courses

text
Calculus I → Calculus II

Build systems

text
source → compile → package → deploy

Tasks

text
design → implement → test → release

Data pipelines

text
raw data → clean → transform → train

56. Directed cycle problem

Suppose:
text
A → B
↑   ↓
D ← C
Then:
A→B→C→D→A.A\to B\to C\to D\to A.
This is a directed cycle.
So the graph is not a DAG.
In a dependency system, this could mean:
A depends on B, B depends on C, ..., and something eventually depends back on A.
That is impossible to resolve sequentially.

57. Topological ordering intuition

A DAG can be arranged so that every directed edge points forward.
Example:
text
A → B
A → C
B → D
C → D
One topological ordering:
A,B,C,D.A,B,C,D.
Another:
A,C,B,D.A,C,B,D.
Topological order is generally not unique.

58. What topological order means

For every edge:
u→v,u\to v,
vertex uu must appear before vv.
This makes topological ordering ideal for dependency scheduling.

59. A directed graph has a topological ordering iff

For a finite directed graph:
topological ordering exists  ⟺  graph is a DAG\boxed{ \text{topological ordering exists} \iff \text{graph is a DAG} }
This is a fundamental relationship.

60. BFS-style topological sorting intuition

One approach repeatedly chooses vertices with:
in-degree=0.\text{in-degree}=0.
Why?
Such a vertex has no unresolved prerequisites.
Process it, remove its outgoing edges, and repeat.
This is commonly known as Kahn's algorithm.
Even if not required by name, understand the mechanism.

61. DFS-style topological sorting intuition

DFS can also construct a topological order.
Rough idea:
place a vertex after all vertices reachable from it have been processed.
Then reverse finishing order.
This is another example of DFS being useful for structural ordering.

62. Graph traversal ordering is not unique

Suppose AA has neighbors:
B,C,D.B,C,D.
If the representation lists:
B,C,D,B,C,D,
one BFS/DFS order results.
If it lists:
D,B,C,D,B,C,
another may result.
Therefore, unless neighbor ordering is specified:
multiple traversal sequences may be valid.
This is a common MCQ trap.

63. Path existence

To determine whether there is a path from:
ss
to:
t,t,
run BFS or DFS from ss.
If:
tt
is visited, a path exists.
If traversal completes without visiting tt, no path exists in that reachable component.

64. Recovering a path

During BFS/DFS, store:
parent[v].parent[v].
When vv is first discovered from uu:
parent[v]=u.parent[v]=u.
Then to recover path from source to target:
t→parent[t]→parent[parent[t]]→⋯t \to parent[t] \to parent[parent[t]] \to\cdots
until source.
Reverse that sequence.

65. BFS shortest-path example

Suppose:
text
A — B — D
|   |
C — E — F
From AA, BFS might assign:
parent[B]=Aparent[B]=A parent[C]=Aparent[C]=A parent[D]=Bparent[D]=B parent[E]=Bparent[E]=B parent[F]=E.parent[F]=E.
Then shortest path to FF:
A→B→E→F.A\to B\to E\to F.
Length:
3.3.

66. Graph as relation — Week 1 connection

Recall Week 1:
A relation:
R⊆A×A.R\subseteq A\times A.
A directed graph on vertex set VV can be viewed as a relation:
E⊆V×V.E\subseteq V\times V.
So relation theory and graph theory are closely connected.
An edge:
(u,v)(u,v)
simply means:
uRv.uRv.

67. Adjacency matrix as relation matrix

For a relation:
R⊆V×V,R\subseteq V\times V,
the adjacency matrix records:
Aij=1A_{ij}=1
exactly when:
viRvj.v_iRv_j.
So Week 10 is partly a computational representation of Week 1 relations.

68. Symmetric relation ↔ undirected-style adjacency

If a directed relation is symmetric:
uRv⇒vRu,uRv\Rightarrow vRu,
then its adjacency matrix is symmetric.
This mirrors an undirected graph.
Nice connection:
symmetric relation↔symmetric adjacency matrix\boxed{ \text{symmetric relation} \leftrightarrow \text{symmetric adjacency matrix} }

69. Reflexivity ↔ self-loops

Recall:
vRvvRv
for every vv means reflexive.
Graphically, every vertex would have a self-loop:
text
 ↺
 A
So relation properties have natural graph interpretations.

70. Transitivity ↔ shortcut edges

If:
u→vu\to v
and:
v→w,v\to w,
transitivity requires:
u→w.u\to w.
So the Week 1 mental model:
every two-step relation requires a shortcut
is literally graph language.

71. Complexity intuition

For graph algorithms, input size is not just:
V.V.
There may also be many edges:
E.E.
So traversal complexity:
O(V+E)O(V+E)
means work grows roughly with the amount of graph data that actually exists.
This is more informative than saying simply:
O(V2).O(V^2).
for sparse graphs.

72. Sparse vs dense graphs

A sparse graph has relatively few edges.
Typically:
E≪V2.E\ll V^2.
A dense graph has many possible edges present.
This distinction affects which representation is sensible.

Sparse

Adjacency list often better.

Dense

Adjacency matrix may be convenient.

73. Maximum undirected edges

For a simple graph with:
nn
vertices:
∣E∣max⁡=n(n−1)2\boxed{ |E|_{\max} = \frac{n(n-1)}2 }
because each pair can have at most one edge.

74. Maximum directed edges

For a simple directed graph without self-loops:
each ordered pair of distinct vertices can be an edge.
So:
∣E∣max⁡=n(n−1)\boxed{ |E|_{\max}=n(n-1) }
because direction distinguishes:
u→vu\to v
from:
v→u.v\to u.
Common mistake: BFS always gives unique order
No.
BFS guarantees increasing distance layers, but the ordering within a layer may depend on adjacency ordering.

Common mistake: DFS finds shortest paths
Not generally.
DFS may go down a long branch before discovering a much shorter route.
For shortest paths in an unweighted graph, think:
BFS\boxed{\text{BFS}}
Common mistake: graph cycle means repeated vertex in traversal
A traversal can encounter a repeated vertex conceptually because the graph has multiple incoming routes, but visited-state handling prevents processing it repeatedly.
Cycle is a structural property of the graph, not simply "I saw something twice in my notes."

Common mistake: DAG means no undirected cycle
A DAG specifically means:
no directed cycles.
The underlying undirected structure may contain an undirected cycle while the edge directions prevent a directed cycle.
Example:
text
A → B
↓   ↓
C → D
Underlying undirected edges form a square-like structure, but there may be no directed route returning to its start.

Common mistake: degree in directed graph
Do not use a single ambiguous degree if the question distinguishes direction.
Track:
deg⁡−(v)\deg^-(v)
and:
deg⁡+(v).\deg^+(v).
Common mistake: path length
Path:
A→B→C→DA\to B\to C\to D
contains:
  • 44 vertices
  • 33 edges
Path length is usually:
3\boxed{3}
not 44.

81. BFS pseudocode

A clean conceptual version:
text
BFS(G, s):
    mark s visited
    enqueue s

    while queue not empty:
        v = dequeue

        for each neighbor u of v:
            if u not visited:
                mark u visited
                parent[u] = v
                enqueue u
Key structure:
queue\boxed{\text{queue}}

82. DFS pseudocode

Recursive version:
text
DFS(G, v):
    mark v visited

    for each neighbor u of v:
        if u not visited:
            parent[u] = v
            DFS(G, u)
Key structure:
recursion / stack\boxed{\text{recursion / stack}}

83. A useful comparison mental model

Think of exploring a building.

BFS

Check:
  • every room 1 door away
  • then every room 2 doors away
  • then 3 doors away
Good for shortest number of doors.

DFS

Pick one corridor and keep walking until it ends.
Then backtrack.
Good for fully exploring branches.

84. Full graph-analysis example

Suppose:
text
A — B — D
|   |
C — E
Vertices:
V={A,B,C,D,E}.V=\{A,B,C,D,E\}.
Edges:
E={{A,B},{A,C},{B,D},{B,E}}.E= \{ \{A,B\}, \{A,C\}, \{B,D\}, \{B,E\} \}.
So:
∣V∣=5|V|=5
and:
∣E∣=4.|E|=4.
Degrees:
deg⁡(A)=2\deg(A)=2 deg⁡(B)=3\deg(B)=3 deg⁡(C)=1\deg(C)=1 deg⁡(D)=1\deg(D)=1 deg⁡(E)=1.\deg(E)=1.
Sum:
2+3+1+1+1=8.2+3+1+1+1=8.
And:
2∣E∣=8.2|E|=8.
Handshaking lemma confirmed.

85. Is this graph a tree?

It has:
55
vertices and:
44
edges.
It is connected and has no cycles.
Therefore:
yes, it is a tree\boxed{\text{yes, it is a tree}}

86. BFS from AA

Possible BFS:
A,B,C,D,E.A,B,C,D,E.
Layers:
L0={A}L_0=\{A\} L1={B,C}L_1=\{B,C\} L2={D,E}.L_2=\{D,E\}.
So shortest distance from AA to EE:
2.2.

87. DFS from AA

Depending on neighbor ordering, one valid DFS:
A,B,D,E,C.A,B,D,E,C.
Another could differ.
Again:
traversal order depends on tie-breaking.

88. Week 10 formula/fact sheet

Graph

G=(V,E)\boxed{G=(V,E)}

Handshaking lemma

∑vdeg⁡(v)=2∣E∣\boxed{ \sum_v\deg(v)=2|E| }

Complete undirected graph

∣E∣=n(n−1)2\boxed{ |E|=\frac{n(n-1)}2 }

BFS complexity

O(V+E)\boxed{ O(V+E) }

DFS complexity

O(V+E)\boxed{ O(V+E) }

Tree

For a tree:
∣E∣=∣V∣−1\boxed{ |E|=|V|-1 }

DAG

directed + no directed cycle\boxed{ \text{directed + no directed cycle} }

89. Week 10 conceptual map

text
Graph G=(V,E)
│
├── vertices
├── edges
├── degree
├── paths
├── cycles
└── connectivity
     │
     ▼
Representation
├── adjacency matrix
└── adjacency list
     │
     ▼
Traversal
├── BFS → queue → layers → shortest unweighted path
└── DFS → stack → depth → backtracking
     │
     ▼
Structure
├── components
├── trees
└── DAGs
     └── dependency ordering

90. What you should actually master

By the end of Week 10, you should be able to:
  1. Define:
    • graph
    • vertex
    • edge.
  2. Distinguish directed and undirected graphs.
  3. Compute vertex degree.
  4. Compute in-degree and out-degree.
  5. Apply the handshaking lemma.
  6. Identify paths and cycles.
  7. Determine connectivity/components.
  8. Construct/read adjacency matrices.
  9. Construct/read adjacency lists.
  10. Explain BFS.
  11. Trace BFS manually.
  12. Explain why BFS gives shortest paths in unweighted graphs.
  13. Explain DFS.
  14. Trace DFS manually.
  15. Distinguish queue-based BFS from stack/recursive DFS.
  16. Recognize a tree.
  17. Use:
∣E∣=∣V∣−1|E|=|V|-1
appropriately for trees. 18. Recognize a DAG. 19. Understand dependency/topological-order intuition. 20. Know BFS/DFS traversal complexity:
O(V+E).O(V+E).
If those are comfortable, Week 10 is under control.

Quick Recall & Flashcards

Test your active recall before proceeding to practice problems. Format:
Question :: Answer.
  • Handshaking Lemma for undirected graph G=(V,E)G = (V, E) :: ∑v∈Vdeg⁡(v)=2∣E∣\sum_{v \in V} \deg(v) = 2|E|
  • Maximum number of edges in simple undirected graph with nn vertices :: (n2)=n(n−1)2\binom{n}{2} = \frac{n(n-1)}{2}
  • Maximum number of directed edges in simple digraph with nn vertices :: n(n−1)n(n-1)
  • Breadth-First Search (BFS) primary data structure :: Queue (FIFO) — finds shortest paths in unweighted graphs
  • Depth-First Search (DFS) primary data structure :: Stack (LIFO) or recursion
  • Number of edges in a tree with nn vertices :: n−1n - 1
  • DAG stands for :: Directed Acyclic Graph
  • A directed graph has a topological sort if and only if :: It contains no directed cycles (it is a DAG)

Practice & Self-Check

Attempt these diagnostic questions to verify your operational understanding.
1

Question 1

An undirected graph has 6 vertices, each of degree 3. How many edges does the graph have?
NAT
3 Unit Assessment
2

Question 2

Which data structure is fundamentally used to implement Breadth-First Search (BFS)?
MCQ
3 Unit Assessment
A. Stack (LIFO)
B. Queue (FIFO)
C. Priority Queue
D. Binary Search Tree

Active Recall Session

Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.