## Finite State Machine :

A finite state machine (FSM) is a mathematical model of computation used to design algorithms and digital logic. It consists of a finite number of states, which are represented by circles in a state diagram, and a set of transitions between those states, which are represented by arrows. A finite state machine can be in only one state at a time, and it can transition from one state to another only in response to a specific input.

One example of a finite state machine is a simple vending machine. The vending machine has a finite number of states, such as “idle,” “accepting payment,” and “dispensing product.” It also has a set of transitions between those states, such as “insert coin” or “select product.” When the vending machine is in the “idle” state and a user inserts a coin, the machine transitions to the “accepting payment” state. When the user then selects a product, the machine transitions to the “dispensing product” state, and so on.

Another example of a finite state machine is a traffic light at an intersection. The traffic light has a finite number of states, such as “red,” “yellow,” and “green.” It also has a set of transitions between those states, such as “time expired” or “emergency vehicle detected.” When the traffic light is in the “red” state and the time for that state expires, the light transitions to the “green” state. If an emergency vehicle is detected, the light may transition to the “yellow” state and then to the “red” state to allow the emergency vehicle to pass.

In both of these examples, the finite state machine is able to respond to specific inputs and transition between states in a predictable and well-defined manner. This allows the machine to perform a specific task, such as dispensing a product or controlling traffic, in a reliable and efficient way.