Day/Month Scheduling and Multi-Attribute Categorisation
Dynamic Programming is one of the highest-yield areas in GATE Computer Science โ it shows up directly in 2-mark coding/complexity questions and indirectly inside Algorithms numerical answer type problems. Most beginners "know DP" but freeze when asked which implementation style they used. The two canonical styles are Memoization and Tabulation, and the GATE examiner loves to test the differences.
Definition: Memoization (top-down DP) is plain recursion plus a lookup table โ you solve a subproblem only when the recursion actually asks for it, and cache the answer for future calls.
Definition: Tabulation (bottom-up DP) is iteration over a table โ you compute every subproblem in dependency order, smallest to largest, with no recursion stack involved.
The Same Recurrence, Two Personalities
Both styles target the same recurrence relation; they just differ in who triggers a subproblem. In memoization the demand is lazy โ a subproblem is computed only when the recursion descends to it. The unvisited states stay empty in the table and consume zero time. In tabulation the demand is eager โ you fill the entire table whether every entry is later needed or not. This is the single deepest distinction between the two and the source of most exam-trap questions.
Take the classic Fibonacci recurrence f(n) = f(nโ1) + f(nโ2). With memoization, computing f(5) visits exactly states {0, 1, 2, 3, 4, 5} โ six work units. With tabulation, you also fill states 0 to 5 in order. Identical here. But change the problem to "longest common subsequence between strings of length 1000, only the final value needed" and you'll find that memoization typically computes fewer states because many (i, j) cells are simply unreachable, while tabulation always fills all 1000 ร 1000 = 10^6 entries. That is the trade-off GATE will ask you to articulate.
Asymptotic Time: The Universal Shortcut
Both styles share the same big-O time complexity, captured by one line:
Time = (number of distinct subproblems) ร (work done per subproblem in transitions)
Apply this and most DP complexity questions become trivial. Fibonacci has n subproblems and constant-time transitions, so time = O(n). 0/1 Knapsack has n ร W subproblems with O(1) transitions, so O(nW). LCS has m ร n subproblems with O(1) transitions, so O(mn). Matrix Chain Multiplication has O(n^2) subproblems but O(n) transition (the partitioning choice), so O(n^3). Internalise this counting rule โ it has appeared verbatim in multiple GATE rubrics.
Why It Matters
GATE CSE numerical-answer-type questions on DP almost always reduce to (a) recognise the recurrence, (b) apply the state-count ร transition-cost rule, and (c) decide whether top-down or bottom-up gives a tighter constant or memory profile. Engineers who know the what of DP but not the which lose easy marks. Equally important, in the interview rounds at Microsoft, Adobe, and several PSU technical interviews after qualifying GATE, candidates are asked exactly this comparison.
Memory and Stack Behaviour
Tabulation runs in a plain for-loop, so the only memory used is the table itself. Memoization runs through recursion, so it uses the table plus the call stack โ and for very deep recurrences (n = 10^6 say) this can blow the default 1 MB stack and produce a StackOverflowError. That is one reason competitive programming culture prefers bottom-up.
Tabulation also enables space optimisation more naturally. For example, in Fibonacci you only ever need the last two table entries, so you can drop the array entirely and keep two variables, reducing space from O(n) to O(1). The same trick works for many "row-only depends on the previous row" DP problems like 0/1 Knapsack โ keep just two rows instead of n. Memoization cannot easily do this because the recursion may revisit any past state.
Real-world example: When Google Maps computes the shortest route across India, it solves a DP-like shortest-path problem at scale. Tabulation-style algorithms are preferred precisely because they exploit predictable memory access patterns and avoid stack overflows on city-sized graphs.
Common misconception: "Top-down is always slower because of recursion overhead." False. When the search space is sparse โ say, a chess-engine DP where 99% of board states are never reached โ memoization can be dramatically faster than tabulation because it skips the unreachable cells entirely. The true rule is: bottom-up is faster when almost every state is needed; top-down is faster when only a few states are needed.
A Worked Example: Counting Paths in a Grid
Question: Count the number of paths from cell (0,0) to (mโ1, nโ1) in an m ร n grid, moving only right or down. State the time and space complexity for both memoization and tabulation.
Solution:
Step 1: Define the recurrence. Let P(i, j) be the number of paths to (i, j). Then P(i, j) = P(iโ1, j) + P(i, jโ1), with P(0, 0) = 1 and P out-of-grid = 0.
Step 2: Count subproblems and transition cost. Number of distinct (i, j) states = m ร n. Transition cost = O(1) (two table lookups and one addition).
Step 3: Time = m ร n ร 1 = O(mn) for both styles.
Step 4: Space. Memoization needs the m ร n table plus a recursion stack up to depth O(m + n), so O(mn). Tabulation needs the m ร n table, so O(mn) โ but with row-only dependency we can reduce to O(min(m, n)) using a single rolling row.
Conclusion: Time complexity is identical at O(mn). Tabulation wins on memory thanks to space optimisation.
| Aspect | Memoization (Top-Down) | Tabulation (Bottom-Up) |
|---|---|---|
| Direction | Recursion descends from goal | Iteration ascends from base case |
| Evaluation | Lazy โ only states actually reached | Eager โ every state in the table |
| Stack usage | Yes (function call stack) | No (plain loop) |
| Space optimisation | Hard | Easy (row reduction) |
| Code style | Closer to the math recurrence | Closer to imperative loops |
| Best when | Sparse state visits | Dense state visits |
- โ- Time complexity = (number of subproblems) ร (work per transition) โ true for both styles.
- โ- Memoization computes only the states it actually visits; tabulation computes all of them.
- โ- Memoization uses recursion stack; deep recurrences risk stack overflow.
- โ- Tabulation enables space optimisation (e.g., rolling rows for O(n) โ O(1) Fibonacci).
- โ- Big-O is the same; constant factors and memory profile differ.
- โ- Choose memoization for sparse state spaces, tabulation for dense ones.
- โ- Always state the recurrence first; implementation choice is secondary.
T-T-B-B: Top-down uses Table + recursion; Bottom-up uses Base case + loop. Top โ Lazy. Bottom โ Eager.
- โ- Memoization and tabulation are two implementations of the same DP recurrence.
- โ- Both share asymptotic time = states ร transition cost.
- โ- Tabulation is loop-based and space-friendly; memoization is recursion-based and skips unreached states.
- โ- For GATE, always justify "I used DP because the recurrence has overlapping subproblems and optimal substructure" โ then pick a style.
Scheduling Shortcuts and Grid Technique
Speed tools:
- Map days/months to numbers: Mon=1...Sun=7; Jan=1...Dec=12. 'X is 3 days after Y' โ day(X) = day(Y)+3.
- 'Between Tuesday and Friday' = Wed, Thu (exclusive) โ 2 days; read inclusivity carefully.
- For 'who does the task on the day immediately before/after', use ยฑ1 on the numeric scale.
- Multi-attribute GRID: rows = persons, columns = attributes; put a โ when forced, โ when ruled out. One โ in a row/column eliminates the rest.
- Start from the most constrained attribute (the one with the fewest options or most clues).
- Combine two single-link clues to form a chain (A-city, city-profession โ A-profession).
Memory aid for days: 'My Tall Wife Took Five Sweet Sundaes' (M,T,W,T,F,S,S). For months use the day-count knuckle trick to handle dates.
Worked Example: Days-of-Week Puzzle
Five persons V,W,X,Y,Z attend meetings on five consecutive days Mon-Fri (one each). Clues: (i) X's meeting is before W's but after V's. (ii) Y meets on Friday. (iii) Z does not meet on Monday.
Solve: Map Mon=1...Fri=5. From (i): V < X < W (in day order). Y = Friday (5). So V,X,W,Z occupy Mon-Thu. Z โ Monday โ Monday is V, X, or W; since V < X < W, the earliest is V, so V = Monday (1) fits. Then X and W are after V. Z must take one of the remaining mid slots. A consistent fill: V=Mon, X=Tue, W=Wed, Z=Thu, Y=Fri โ check: V<X<W โ, Y=Fri โ, Zโ Mon โ.
The method: convert ordering clues to a numeric chain (V<X<W), anchor fixed days (Y=Fri), then place the constrained person (Zโ Mon) into a valid remaining slot. Verify every clue against the final schedule. This grid-plus-number-line technique generalizes to month and date scheduling puzzles too.
Categorisation and Scheduling Puzzles โ revision notes (IBPS PO)
Categorisation (grouping by city/subject/colour) and scheduling (days, dates, months) puzzles are the "double-variable" sets IBPS PO uses to separate cut-off from top scorers. Expect 1 set in Prelims and 1โ2 in Mains; they reward candidates who tabulate and punish those who hold data in their head.
The two families
- Scheduling: items are placed across days/dates/months/time-slots. Order matters; use a timeline.
- Categorisation: each person is tagged with 2โ3 attributes (e.g. person + city + fruit). Order may not matter; use a grid/table.
| Clue phrase | Handling |
|---|---|
| "on the day before/after" | adjacent timeline slots |
| "between Monday and Thursday" | strictly Tue/Wed (endpoints excluded) |
| "neither X nor Y" | eliminate two options from that cell |
| "the one who likes P also lives in Q" | link two attribute columns |
Method
- Draw a table: rows = persons/slots, columns = attributes.
- Enter definite links first; use a "โ / negative" grid for eliminations.
- Chain conditional links ("the one who โฆ also โฆ") to collapse options.
- For dates spanning months, watch month length (e.g. two dates "of different months, same date-number").
Exam Tricks & Tips
- ๐ฏ Maintain a negative-information grid: every "not on Tuesday" or "doesn't like apple" is a โ โ three โ in a row of four forces the fourth.
- ๐ฏ In month/date sets, note days-per-month up front (Feb 28/29, 30-day months) โ "gap of days across two months" hinges on it.
- ๐ฏ "Between Monday and Friday" excludes both endpoints (Tue/Wed/Thu only); the exclusive reading is the trap.
- ๐ฏ Convert "the person from Delhi likes mango" into a locked column-pair so any clue about Delhi also fixes mango.
- ๐ฏ When order is irrelevant (pure categorisation), stop trying to sequence โ just fill the truth-grid.
- โ Common mistake: assuming "before/after" implies immediately before/after โ it doesn't unless "just/immediately" is stated.
Expected exam pattern
7 persons across 7 days (or 4 months ร 2 dates) with one extra attribute. 5 questions on exact day, attribute matching, and odd-one-out.
Quick recap
Tabulate, run a negative grid, respect exclusive "between", pre-note month lengths, and never read "before/after" as immediate unless told.
Categorisation and Scheduling Puzzles โ Flashcards (IBPS PO)
Cover the answer, recall, then check. 11 cards on categorisation and scheduling.
Q1. "P is scheduled between Monday and Friday." Which days are possible?
A1. Tuesday, Wednesday, Thursday โ "between" excludes both endpoints.
Q2. What is a negative-information grid and why use it?
A2. A โ table for every "not/neither" clue; when a row has all-but-one โ, the last cell is forced.
Q3. Does "A is scheduled before B" mean immediately before?
A3. No โ only that A is earlier; use "just/immediately before" for adjacency.
Q4. In categorisation vs scheduling, when does order NOT matter?
A4. In pure categorisation (person + city + fruit with no sequence) โ just fill the truth grid.
Q5. How do you handle "the one from Pune likes tea"?
A5. Lock Puneโtea as a column-pair; any clue fixing one fixes the other.
Q6. Two events fall "on the same date of different months, one being March." Why note month lengths?
A6. Because valid date-numbers depend on days in each month (e.g. no 31st in April/June).
Q7. "Neither red nor blue" for item X removes what?
A7. Two colour options from X, narrowing the remaining choices.
Q8. Best structure to start a double-variable puzzle?
A8. A rows-by-columns table with one row per person/slot and one column per attribute.
Q9. "Exactly two days between A and B." Day-number difference?
A9. 3 (two full days sit between).
Q10. How do conditional "the one who โฆ also โฆ" clues help?
A10. They chain two attribute columns, collapsing many options into a linked pair.
Q11. Most common scheduling error?
A11. Reading plain "before/after" as immediate adjacency and including endpoints of "between".