🖨️ Printing Instructions: Press Ctrl/Cmd + P and select "Save as PDF".
1

DAGs, Topological Sort, SCCs and Midterm Review

2

Learning Goals

3

Directed Acyclic Graphs

4

DAG Definition

5

Topological Sort

6

Problem Statement

7

Example: Getting Dressed

8

Algorithm 1: DFS-Based

9

Key Idea

10

Topological-Sort(G)

1. Call DFS(G) to compute finish times f[v]
2. As each vertex finishes, prepend it to a linked list
3. Return the linked list
11

Complexity

12

Correctness Proof

13

Algorithm 2: Kahn's Algorithm

14

Source Removal Idea

15

Analysis of Kahn's

16

DFS vs. Kahn's: Which to Use?

17

Interactive Demo: Topological Sort

18

Strongly Connected Components

19

Definition

20

Kosaraju's Algorithm

21

Interactive Demo: Strongly Connected Components

22

Midterm Review

23

Topics Covered

24

Review Q1: Big-O

25

Review Q2: Recurrence

26

Review Q3: Loop Invariant

27

Review Q4: Sorting Stability

28

Review Q5: Heaps

29

Review Q6: Graph Traversal

30

Review Q7: Quicksort Worst Case

31

Review Q8: Comparison Sort Lower Bound

32

Review Q9: Graph Density

33

Review Q10: Pseudocode Debugging

34

Review Q11: DAGs

35

Review Q12: Master Theorem Gap

36

Review Q13: Heap Build

37

Review Q14: BFS with a Stack

38

Exam Strategies

39

Common Pitfalls & Anti-Patterns

40

Watch Out For...

41

Interactive Practice

42

Activity 1: Topological Sort (DFS)

43

Solution 1

44

Activity 2: Kahn's Algorithm

45

Solution 2

46

Activity 3: Cycle Detection

47

Solution 3

48

Activity 4: SCC Identification

49

Solution 4

50

Lecture Summary

51

All Interactive Demos

52

Supplementary Resources