COMPUTER SCIENCE & TECHNOLOGY • COMPUTING
Finite-State Machine
Choose an initial state and event sequence to see how a deterministic finite-state machine maps each state–event pair to exactly one next state.
Trace deterministic state transitions
Use a two-state turnstile to see how the same event can produce a different action depending on the current state.
LEARN WITH THE SIMULATION
Understand Finite-State Machine by experimenting.
A deterministic finite-state machine models behavior with a finite set of states, a finite event alphabet and a transition function that selects exactly one next state for every supported state-event pair. This premium turnstile laboratory separates four ideas that are often mixed together: the current state, the incoming event, the next state and the action produced during the transition. By designing event sequences and targeting a final state, learners can reason about the machine rather than merely watch arrows move.
BUILD THE IDEA
What you should understand first
- Trace a deterministic transition function δ(state,event) one event at a time.
- Distinguish current state, input event, next state and transition action as separate parts of the machine.
- Explain why the same event can produce different actions when the machine begins in a different state.
- Design an event sequence that reaches a requested final state while controlling side effects such as alarm actions.
TRY IT YOURSELF
Can the same event sequence produce different actions even when it eventually ends in the same state?
- Start in Locked and use a sequence containing both Coin and Push events. Record every state, next state and action.
- Change only the initial state to Unlocked while leaving all four events unchanged.
- Compare the two traces, paying attention to the first event where the action differs.
- Change one event and predict the new final state before reading the inspector.
The transition function is deterministic, but determinism is conditional on both the current state and the event. The same event can therefore trigger different actions in different states, and changing the starting state can alter an entire trace even when a later event makes the paths converge.
WHY IT WORKS 01
State is compressed memory of the relevant past
A finite-state machine does not need to remember every earlier event explicitly. Its current state summarizes exactly the history that matters for future transitions. For the turnstile, whether the previous event was a coin or push is irrelevant once the machine is known to be Locked or Unlocked. That compressed memory is what makes finite-state models useful for controllers and protocols.
WHY IT WORKS 02
Transitions can change state, produce an action, or both
A Push event while Locked keeps the state Locked but produces an alarm, whereas a Coin while Locked changes the state to Unlocked and produces an unlock action. Treating actions and states separately prevents a common modeling mistake in which every visible output is assumed to require a new persistent state.
WHY IT WORKS 03
Determinism is a property of the transition function
For each supported pair such as Locked + Coin, this machine has exactly one defined result. Another model could allow several possible next states for the same input and would be nondeterministic. Determinism therefore describes the mapping rule, not whether the event sequence itself was predictable in advance.
DO NOT MIX THESE UP
Common misconception
Deterministic does not mean that the machine always follows one global path regardless of input. It means that once the current state and event are known, exactly one next state is defined. A state is also not the same thing as an action: unlock, lock, alarm and thank are outputs associated with transitions, while Locked and Unlocked are the persistent modeled states.
PRACTICE CHALLENGE
Can you reach a requested final state while producing as few alarm actions as possible?
- Choose the target final state in the premium controls.
- Edit the four-event sequence until the final-state inspector matches the target.
- If any alarm actions occur, change events while preserving the same target final state.
- Explain each transition using the current state and event rather than memorizing the whole sequence.
Reveal the reasoning
To avoid alarms, do not apply Push while the turnstile is Locked. Reaching a target state is therefore a sequence-design problem: each event changes or preserves the state according to δ, and later events operate on the state produced by the earlier ones. Multiple low-alarm sequences can reach the same final state.
MODEL BOUNDARIES
What this simulation assumes
Every simulation simplifies reality or a mathematical system. These are the assumptions and limits to keep in mind while interpreting the results.
Model assumptions
- The turnstile has exactly two modeled states, Locked and Unlocked, and two modeled events, Coin and Push.
- Events arrive one at a time in a fixed order and each supported state-event pair has one deterministic transition.
- Actions such as alarm, unlock and lock are symbolic outputs rather than simulated physical hardware operations.
Model limitations
- Concurrency, event timing, failures, sensors and asynchronous hardware behavior are outside this simplified machine.
- The turnstile is one teaching example and does not represent the full expressive range of finite automata or statecharts.
CONNECT IT
Where this matters
- User-interface and workflow logic
- Protocol and embedded-controller design
- Parsers, games and automation systems
- Reasoning about control logic before implementation
WORDS THAT MATTER
Key vocabulary
- State
- Discrete condition summarizing the part of the machine's history that matters for future behavior.
- Event
- Input symbol presented to the machine and evaluated together with the current state.
- Transition function
- Rule δ that maps a current state and supported event to one next state in a deterministic machine.
- Action
- Output produced during a transition, which may occur whether or not the persistent state changes.
- Deterministic
- Property that each supported state-event pair has exactly one defined next state.
NEXT STEP