Bird
0
0

In a collaborative drawing application using the Memento pattern for undo functionality, which strategy optimizes both performance and memory usage?

hard📝 Trade-off Q8 of 15
LLD - Behavioral Design Patterns — Part 2
In a collaborative drawing application using the Memento pattern for undo functionality, which strategy optimizes both performance and memory usage?
AKeep only the latest state and discard all previous states
BSave full snapshots of the entire canvas after every user action
CStore incremental changes as mementos instead of full snapshots
DUse a single global memento shared among all users
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem context

    Collaborative drawing apps require efficient undo with minimal memory overhead.
  2. Step 2: Evaluate options

    Full snapshots (Save full snapshots of the entire canvas after every user action) consume high memory; single state (Keep only the latest state and discard all previous states) loses undo history; global memento (Use a single global memento shared among all users) breaks isolation.
  3. Step 3: Choose incremental changes

    Storing incremental changes as mementos (Store incremental changes as mementos instead of full snapshots) reduces memory use and supports efficient undo.
  4. Final Answer:

    Store incremental changes as mementos instead of full snapshots -> Option C
  5. Quick Check:

    Incremental saves optimize memory and performance [OK]
Quick Trick: Incremental mementos save memory and improve undo speed [OK]
Common Mistakes:
MISTAKES
  • Assuming full snapshots are always better for undo
  • Discarding all previous states losing undo capability
  • Sharing a single memento across multiple users

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes