Source invariant: "Inorder means: fully visit the left subtree, then this node, then the right subtree — recursion does the bookkeeping for you."
2. For maximum depth, what should a real node return?
Source invariant: "The answer for a node is a function of its children's answers; trust the recursion on subtrees and only decide what happens at this node."
3. Spot the Same Tree bug:
if not p or not q:
return True
Source invariant: "Two trees are identical iff their roots match and both pairs of subtrees are identical — compare them in lockstep."
4. What separates one BFS level from the next?
Source invariant: "A queue processes nodes in the order discovered; snapshot the queue length to process exactly one level at a time."
5. What travels upward beside height in Diameter and Balanced?
Source invariant: "Compute height recursively and carry the real answer up alongside it — one traversal answers both questions."
6. Which check belongs in Balanced Binary Tree?
Source invariant: "Compute height recursively and carry the real answer up alongside it — one traversal answers both questions."
Self-check gate
Pass tonight if at least 2 of your 3 blank-file attempts pass on run one or two, and you can say the invariant before each solution.
Failure path: if a problem fails after two runs, write WA: <root cause>, add that failed problem to the next revision, and ask your teacher with the code plus the invariant you tried to use.