Skip to content

Questions about Finite-state machine

Short answers, pulled from the story.

What is a finite-state machine and how does it work?

A finite-state machine is a mathematical model of computation that can be in exactly one of a finite number of states at any given time. It changes states in response to inputs, with each change called a transition. An FSM is defined by its list of states, its initial state, and the inputs that trigger each transition.

What are real-world examples of finite-state machines?

Common examples include vending machines, elevators, traffic lights, combination locks, and subway turnstiles. A turnstile is a classic illustration: it has two states (Locked and Unlocked) and two inputs (coin and push), and it transitions between states based on those inputs.

What is the difference between a Moore machine and a Mealy machine?

A Moore machine produces output that depends only on the current state, using entry actions. A Mealy machine produces output that depends on both the current state and the triggering input, which often results in fewer states needed to model the same behavior.

What are the four types of finite-state machines?

Finite-state machines are classified as acceptors (which produce binary accepted/rejected output), classifiers (which produce output with more than two values), transducers (which generate output based on state and input), and sequencers (which produce a single output sequence from a single-letter input alphabet).

How does a finite-state machine compare to a Turing machine in computational power?

A finite-state machine has less computational power than a Turing machine. An FSM is equivalent only to a Turing machine whose head can only read (not write) and must always move left to right. There are computational tasks a Turing machine can perform that an FSM cannot, because an FSM's memory is bounded by its finite number of states.

How are finite-state machines used in compilers?

Finite automata appear in the frontend of programming language compilers. A lexical analyzer built from FSMs reads a sequence of characters and produces language tokens such as reserved words, literals, and identifiers. A parser then uses those tokens to build a syntax tree, handling the context-free parts of the grammar.