Bird
Raised Fist0

Which data structure change fundamentally alters the approach and requires a different design?

hard🎤 Interviewer Follow-up Q10 of Q15
OOP & Design Patterns - Command Pattern - Undo/Redo, Request Queuing & Logging
Suppose you want to extend the Command Pattern to support multi-level undo/redo with branching histories (i.e., multiple redo paths after undo). Which data structure change fundamentally alters the approach and requires a different design?
AUse a tree or graph structure to represent branching command histories
BUse a doubly linked list to store commands linearly
CStore commands in a hash map keyed by command ID
DReplace undo and redo stacks with a single queue
Step-by-Step Solution
Solution:
  1. Step 1: Understand branching undo/redo requirements

    Branching histories require tracking multiple redo paths after undo.
  2. Step 2: Identify suitable data structure

    A tree or graph structure models branching histories; hash map alone does not represent order or branches.
  3. Step 3: Evaluate options

    Queue and doubly linked list are linear, insufficient for branching; hash map is for fast lookup, not history structure.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Branching undo/redo requires tree/graph, not linear or hash map alone [OK]
Quick Trick: Branching histories need tree/graph, not linear or hash map [OK]
Common Mistakes:
MISTAKES
  • Choosing linear structures for branching undo
  • Confusing hash map with history structure
Trap Explanation:
PITFALL
  • Candidates often pick hash map for fast access but miss that it doesn't model branching history order.
Interviewer Note:
CONTEXT
  • Tests ability to adapt Command Pattern for complex undo/redo scenarios
Master "Command Pattern - Undo/Redo, Request Queuing & Logging" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes