Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a state machine in the context of elevator design?
A state machine is a model that represents the different states an elevator can be in (like moving up, moving down, idle, door open) and the transitions between these states based on events.
Click to reveal answer
beginner
Why is testing state machines important in elevator design?
Testing ensures the elevator behaves correctly in all states and transitions, preventing errors like doors opening while moving or skipping floors, which could cause safety issues.
Click to reveal answer
intermediate
How does an elevator's state machine handle multiple requests?
It manages requests by transitioning between states to serve floors efficiently, deciding when to move up or down, stop, or open doors based on queued requests.
Click to reveal answer
intermediate
What could happen if an elevator's state machine is not properly tested?
The elevator might behave unpredictably, causing safety hazards like moving with doors open, ignoring requests, or getting stuck between floors.
Click to reveal answer
beginner
Give a real-life example of a state transition in an elevator state machine.
When the elevator is idle at a floor and receives a request to go up, it transitions from 'idle' to 'moving up' state, then to 'door open' when it reaches the requested floor.
Click to reveal answer
What does a state machine in elevator design primarily represent?
AThe physical size of the elevator
BDifferent elevator states and transitions
CThe color of elevator buttons
DThe number of passengers inside
✗ Incorrect
A state machine models the elevator's states and how it moves between them.
Why must elevator state machines be tested thoroughly?
ATo change elevator colors
BTo improve elevator speed only
CTo ensure safe and correct operation
DTo reduce electricity usage only
✗ Incorrect
Testing ensures the elevator operates safely and correctly in all situations.
Which state might an elevator be in when waiting for a request?
AIdle
BMoving up
CDoor open
DMaintenance
✗ Incorrect
Idle means the elevator is waiting and not moving.
What could be a dangerous outcome of a faulty elevator state machine?
ALights turning off
BElevator playing music
CButtons lighting up
DDoors opening while moving
✗ Incorrect
Doors opening while moving is a serious safety hazard.
How does the elevator decide to move up or down?
ABased on queued floor requests
BRandomly
CBased on time of day
DBased on passenger weight
✗ Incorrect
The elevator uses requests to decide direction.
Explain why elevator design uses state machines and why testing them is critical.
Think about how an elevator moves and reacts to button presses.
You got /5 concepts.
Describe a typical request flow in an elevator state machine from idle to door open.
Imagine pressing a floor button and what happens next.
You got /5 concepts.
Practice
(1/5)
1. Why is elevator design often used to test state machines in system design?
easy
A. Because elevators have clear states and transitions that model real-world behavior
B. Because elevators require complex database management
C. Because elevators use machine learning algorithms
D. Because elevators operate without any state changes
Solution
Step 1: Understand elevator operation basics
Elevators move between floors and have states like moving up, moving down, idle, door open, and door closed.
Step 2: Connect elevator states to state machine concept
State machines model systems with defined states and transitions, matching elevator behavior perfectly.
Final Answer:
Because elevators have clear states and transitions that model real-world behavior -> Option A
Quick Check:
Elevator states = clear states and transitions [OK]
Hint: Elevators have clear states and transitions [OK]
Common Mistakes:
Thinking elevators don't have states
Confusing state machines with databases
Assuming elevators use AI for basic movement
2. Which of the following correctly represents a state transition in an elevator state machine?
easy
A. Idle -> Door Open -> Moving Up
B. Idle -> Moving Up -> Door Open
C. Door Open -> Moving Down -> Door Closed
D. Moving Up -> Door Closed -> Idle
Solution
Step 1: Identify valid elevator state order
An elevator usually goes from Idle to Moving Up, then Door Open when it reaches the floor.
Step 2: Check each option's sequence
Idle -> Moving Up -> Door Open correctly shows Idle -> Moving Up -> Door Open, a valid transition sequence.
Final Answer:
<code>Idle -> Moving Up -> Door Open</code> -> Option B
Quick Check:
Idle to Moving Up to Door Open = valid transition [OK]
Hint: Elevator moves before doors open [OK]
Common Mistakes:
Opening doors before moving
Closing doors while idle
Skipping moving state
3. Given this simplified elevator state machine code snippet, what is the final state after these events: callElevator(), arriveFloor(), openDoor()?
states = ['Idle', 'Moving', 'DoorOpen']
current_state = 'Idle'
def callElevator():
global current_state
if current_state == 'Idle':
current_state = 'Moving'
def arriveFloor():
global current_state
if current_state == 'Moving':
current_state = 'DoorOpen'
def openDoor():
global current_state
if current_state == 'DoorOpen':
current_state = 'Idle'
medium
A. Idle
B. Moving
C. DoorOpen
D. Error
Solution
Step 1: Trace callElevator()
Starting at 'Idle', callElevator() changes state to 'Moving'.
Step 2: Trace arriveFloor() and openDoor()
arriveFloor() changes 'Moving' to 'DoorOpen', then openDoor() changes 'DoorOpen' back to 'Idle'.
Final Answer:
Idle -> Option A
Quick Check:
Idle after all events = Idle [OK]
Hint: Follow state changes step-by-step [OK]
Common Mistakes:
Skipping openDoor() effect
Assuming state stays at DoorOpen
Confusing event order
4. In this elevator state machine code, what is the bug causing the elevator to never open doors?
current_state = 'Idle'
def callElevator():
global current_state
if current_state == 'Idle':
current_state = 'Moving'
def arriveFloor():
global current_state
if current_state == 'Moving':
current_state = 'Idle' # Bug here
def openDoor():
global current_state
if current_state == 'DoorOpen':
current_state = 'Idle'
medium
A. current_state is not initialized
B. callElevator() does not change state
C. openDoor() changes state incorrectly
D. arriveFloor() sets state to 'Idle' instead of 'DoorOpen'
Solution
Step 1: Analyze arriveFloor() function
arriveFloor() changes 'Moving' state directly to 'Idle', skipping 'DoorOpen'.
Step 2: Understand effect on door opening
Since state never becomes 'DoorOpen', openDoor() condition never triggers, so doors never open.
Final Answer:
arriveFloor() sets state to 'Idle' instead of 'DoorOpen' -> Option D
Quick Check:
arriveFloor() wrong state change = no door open [OK]
Hint: Check if all states are reachable in transitions [OK]
Common Mistakes:
Ignoring wrong state assignment
Assuming callElevator() is faulty
Overlooking openDoor() condition
5. You are designing an elevator system with multiple elevators and floors. Why is modeling the system as a state machine important for safety and scalability?
hard
A. It eliminates the need for sensors and hardware checks
B. It allows elevators to learn user preferences automatically
C. It ensures predictable behavior and clear transitions, preventing unsafe states
D. It reduces the number of elevators needed by half
Solution
Step 1: Understand state machine benefits in complex systems
State machines define clear states and transitions, making system behavior predictable and easier to manage.
Step 2: Connect predictability to safety and scalability
Predictable transitions prevent unsafe states like doors opening while moving, and help scale by managing multiple elevators consistently.
Final Answer:
It ensures predictable behavior and clear transitions, preventing unsafe states -> Option C
Quick Check:
Predictable states = safety and scalability [OK]
Hint: Predictable states prevent unsafe elevator behavior [OK]