Advanced Topics in Computer Science

Unit 8: Graphs and Graph Theory

Students learn to model networks of relationships and solve problems involving paths, connectivity, and traversal.

Unit Focus

What this unit is really teaching

Graphs bring together sets, maps, queues, stacks, recursion, and algorithm efficiency in one major capstone unit.

Key Topics

  • +Graph vocabulary: vertices, edges, degree, path, cycle, connected component, and weight
  • +Adjacency lists, adjacency matrices, and edge lists
  • +Depth-first search and breadth-first search
  • +Connectivity, cycle detection, and path reconstruction
  • +Shortest-path intuition, including Dijkstra-style priority queue thinking
  • +Applications in social networks, maps, cybersecurity, robotics, and dependency systems

Practice Work

Implementation and analysis tasks

Student task

Build a graph traversal visualizer or route finder.

Student task

Analyze a network dataset and report connected components and shortest paths.

DSA Assignment Bank

30 interview-style algorithm questions for this unit

Code Scholars provides structured assignments, implementation support, edge-case review, and runtime analysis coaching so students learn the concept rather than only memorizing a solution.

1

DFS or BFS

Count connected components

Given an undirected graph, count how many disconnected groups of vertices exist.

2

BFS

Find shortest path in an unweighted graph

Use BFS to find the fewest edges from a start vertex to a target and reconstruct the path.

3

DFS with parent tracking

Detect a cycle in an undirected graph

Traverse a graph and identify a cycle without mistaking the edge back to the parent as a cycle.

4

DFS recursion states

Detect a cycle in a directed graph

Use visiting and finished states to detect whether a directed graph contains a cycle.

5

BFS coloring

Check if a graph is bipartite

Color neighboring vertices with opposite colors and detect conflicts.

6

DAG ordering

Topologically sort prerequisites

Given course prerequisites, produce a valid order or report that no order exists because of a cycle.

7

Directed connectivity

Find strongly connected groups

Explain how vertices can reach each other in directed graphs and outline a two-pass strategy.

8

Weighted graph with heap

Run Dijkstra-style shortest path

Use a priority queue to find shortest paths when all edge weights are nonnegative.

9

Greedy graph design

Find minimum spanning tree

Choose edges that connect all vertices with minimum total cost while avoiding cycles.

10

Grid graph traversal

Flood fill a grid

Treat cells as graph vertices and recolor a connected region using BFS or DFS.

11

Grid components

Count islands in a grid

Count connected groups of land cells and explain how marking visited cells prevents double counting.

12

Backtracking on graph

Find all paths in a DAG

List every path from source to target in a directed acyclic graph.

13

Map old nodes to new nodes

Clone an undirected graph

Copy graph nodes and edges without duplicating shared neighbors incorrectly.

14

Connectivity sensitivity

Find bridge edges

Identify edges whose removal disconnects a graph and explain the role of discovery times.

15

BFS levels

Analyze a social network radius

Given a friendship graph, find everyone within two connections of a student.

16

Shortest path with constraints

Route around blocked roads

Find a path in a road network while avoiding closed edges and reporting no path when necessary.

17

Topological reasoning

Model dependency resolution

Given software package dependencies, determine a safe installation order.

18

BFS from start

Find nearest exit in a maze

Use BFS in a grid to find the closest boundary exit while avoiding walls.

19

Reachability

Determine if all rooms are reachable

Given keys found in rooms, decide whether every room can be visited.

20

Union-find intuition

Find redundant connection

Process edges and identify the first edge that connects vertices already connected.

21

Graph robustness

Detect articulation points

Find vertices whose removal disconnects the graph and explain why they matter in network reliability.

22

Adjacency tradeoffs

Choose graph representation

Compare adjacency lists, adjacency matrices, and edge lists for dense and sparse graphs.

23

Graph statistics

Compute graph degree summary

Given an edge list, compute each vertex degree and identify isolated or highly connected vertices.

24

Binary search or modified Dijkstra

Find path with minimum maximum edge

Find a path that minimizes the largest single edge cost encountered along the route.

25

DAG longest path idea

Schedule project tasks

Given task durations and dependencies, compute the earliest completion time for the final task.

26

Two-hop neighbors

Build a recommendation graph

Recommend activities based on shared memberships while excluding activities already selected.

27

Traversal correctness

Debug visited-state mistakes

Given a BFS or DFS that marks visited too late, show how duplicates or loops can occur.

28

Traversal order

Compare BFS and DFS outputs

Given a graph and neighbor order, predict BFS and DFS visit orders.

29

Attack path modeling

Use graph algorithms for cybersecurity

Model systems as vertices and access paths as edges, then find shortest paths from an exposed node to a sensitive node.

30

DSA support

Plan a graph assignment

Create a graph assignment with representation choice, traversal code, path reconstruction, tests, and written analysis.

Need support with Unit 8?

Work through the concepts, code, edge cases, and runtime analysis with 1:1 guidance.