Week 4 — Python Advanced & DSA Graphs

intermediate python dsa

Goal: “The only way out is through.” — Month 1 ends with the hardest DSA topics so far (graphs and DP) and the deepest Python concepts (GIL, async, concurrency). We push through together.

Topics

DayTrackFocusTopics
MonA — DSATries & GraphsTries · Graph Representations · BFS and DFS · Topological Sort
TueB — PythonScope & MemoryLEGB Scope Rule · Shallow vs Deep Copy · Garbage Collection
WedA — DSAShortest Paths & DPShortest Path Algorithms · Union Find · Advanced Graph Problems · DP Fundamentals
ThuB — PythonError Handling & ContextGlobal Interpreter Lock · Exception Handling · Custom Exceptions · Context Managers
FriB — PythonConcurrencyThreading vs Multiprocessing · asyncio and async/await · Concurrent Futures

Key Concepts

  • BFS = shortest path in unweighted graphs (think “ripple outward”), DFS = exploring all paths (think “go deep, then backtrack”). Know when to use which.
  • Topological sort only works on DAGs (directed acyclic graphs) — it’s the go-to for dependency resolution problems.
  • DP is just recursion + memoization. If we can write the brute-force recursive solution first, we can convert it to DP by caching subproblems.
  • The GIL means Python threads don’t truly run in parallel for CPU-bound work — use multiprocessing for CPU tasks, threading for I/O tasks.
  • Context managers (with statement) handle cleanup automatically — no more forgetting to close files or release locks.
  • asyncio is single-threaded concurrency. It’s great for I/O-bound tasks like API calls, but won’t speed up CPU-heavy computation.

Practice

  • Implement BFS and DFS on an adjacency list — print the traversal order for both
  • Solve 1 topological sort problem (e.g., course schedule)
  • Write a context manager using both the class approach (__enter__/__exit__) and the @contextmanager decorator
  • Solve a basic DP problem (climbing stairs or fibonacci with memoization, then convert to tabulation)

~18 topics · ~2 hrs/day · Dual-track: DSA graphs + Python advanced