Week 3 — Python OOP & DSA Trees

intermediate python dsa

Goal: “The tree that bends in the wind does not break.” — This week we bend our brains around trees, heaps, and binary search while leveling up Python with OOP and decorators.

Topics

DayTrackFocusTopics
MonA — DSAQueues, Heaps & TreesQueues and Deques · Priority Queues and Heaps · Design Problems · Binary Trees
TueB — PythonClosures & GeneratorsClosures and nonlocal · Decorators · Generators and Iterators
WedA — DSABSTs & Binary SearchBinary Search Trees · Binary Search · Tree Construction and Serialization · Lowest Common Ancestor
ThuB — PythonOOP FoundationsBuilt-in Functions · Classes and Objects · Inheritance and MRO · Dunder Methods
FriB — PythonOOP Advanced@staticmethod vs @classmethod · Property Decorators · Abstract Classes and Interfaces · Dataclasses

Key Concepts

  • Binary search is everywhere — not just sorted arrays. The “binary search on answer” pattern lets us solve problems like “minimum capacity to ship packages” by searching the answer space.
  • Trees are recursive structures, so tree problems are naturally recursive. If we can solve for one node assuming children are solved, we’re golden.
  • Heaps give us O(log n) insert and O(1) min/max access — perfect for “top K” and streaming problems.
  • Python decorators are syntactic sugar for higher-order functions. @decorator above a function is the same as func = decorator(func).
  • MRO (Method Resolution Order) determines which parent method Python calls in diamond inheritance — it uses the C3 linearization algorithm.
  • Dunder methods (__init__, __repr__, __eq__, etc.) let us customize how Python objects behave with operators and built-in functions.

Practice

  • Implement a min-heap from scratch (insert, extract-min, heapify)
  • Solve 2 binary search variants (e.g., search rotated array, find first/last occurrence)
  • Write a Python decorator that logs function calls with arguments and return values
  • Create a class hierarchy with an abstract base class — e.g., Shape with Circle and Rectangle subclasses

~19 topics · ~2 hrs/day · Dual-track: DSA trees + Python OOP