ArticleslgStudy

computer science

State (computer science)

State (computer science) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand State (computer science) rather than just read about it. In short: In information technology and computer science, a system is described as stateful if it is designed to remember preceding events or user interactions and stateless if it doesn't. The remembered information is called the state of the system.

Key takeaways

  • State (computer science) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect State (computer science) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of State (computer science) from memory before moving on to harder problems.

Reference excerpt

In information technology and computer science, a system is described as stateful if it is designed to remember preceding events or user interactions and stateless if it doesn't. The remembered information is called the state of the system. The set of states a system can occupy is known as its state space. In a discrete system, the state space is countable and often finite. The system's internal behaviour or interaction with its environment consists of separately occurring individual actions or events, such as accepting input or producing output, that may or may not cause the system to change its state. Examples of such systems are digital logic circuits and components, automata and formal language, computer programs, and computers. The output of a digital circuit or deterministic computer program at any time is completely determined by its current inputs and its state.

Digital logic circuit state Digital logic circuits can be divided into two types: combinational logic, whose output signals are dependent only on its present input signals, and sequential logic, whose outputs are a function of both the current inputs and the past history of inputs. In sequential logic, information from past inputs is stored in electronic memory elements, such as flip-flops. The stored contents of these memory elements, at a given point in time, are collectively referred to as the circuit's state and contain all the information about the past to which the circuit has access. Since each binary memory element, such as a flip-flop, has only two possible states, one or zero, and there is a finite number of memory elements, a digital circuit has only a certain finite number of possible states. If N is the number of binary memory elements in the circuit, the maximum number of states a circuit can have is 2N.

Program state Similarly, a computer program stores data in variables, which represent storage locations in the computer's memory. The contents of these memory locations, at any given point in the program's execution, are called the program's state. A more specialized definition of state is used for computer programs that operate serially or sequentially on streams of data, such as parsers, firewalls, communication protocols and encryption. Serial programs operate on the incoming data characters or packets sequentially, one at a time. In some of these programs, information about previous data characters or packets received is stored in variables and used to affect the processing of the current character or packet. This is called a stateful protocol and the data carried over from the previous processing cycle is called the state. In others, the program has no information about the previous data stream and starts fresh with each data input; this is called a stateless protocol. Imperative programming is a programming paradigm (way of designing a programming language) that describes computation in terms of the program state, and of the statements which change the program state. Changes of state are implicit, managed by the program runtime, so that a subroutine has visibility of the changes of state made by other parts of the program, known as side effects. Object-oriented programming attempts to improve on the imperative and procedural programming paradigms by encapsulating related state (and behavior) within objects. The state of an object is often hidden in an attempt to isolate it from other objects and reduce coupling. State that is hidden in this way is often referred to as the "internal state" of the object. In declarative programming languages, the program describes the desired results and doesn't specify changes to the state directly. In functional programming, state is usually represented with temporal logic as explicit variables that represent the program state at each step of a program execution: a state variable is passed as an input parameter of a state-transforming function, which returns the updated state as part of its return value. A pure functional subroutine only has visibility of changes of state represented by the state variables in its scope.

Finite-state machines The output of a sequential circuit or computer program at any time is completely determined by its current inputs and current state. Since each binary memory element has only two possible states, 0 or 1, the total number of different states a circuit can assume is finite, and fixed by the number of memory elements. If there are N binary memory elements, a digital circuit can have at most 2N distinct states. The concept of state is formalized in an abstract mathematical model of computation called a finite-state machine, used to design both sequential digital circuits and computer programs.

Examples An example of an everyday device that has a state is a television set. To change the channel of a TV, the user usually presses a channel up or channel down button on the remote control, which sends a coded message to the set. In order to calculate the new channel that the user desires, the digital tuner in the television must have stored in it the number of the current channel it is on. It then adds one or subtracts one from this number to get the number for the new channel, and adjusts the TV to receive that channel. This new number is then stored as the current channel. Similarly, the television also stores a number that controls the level of volume produced by the speaker. Pressing the volume up or volume down buttons increments or decrements this number, setting a new level of volume. Both the current channel and current volume numbers are part of the TV's state. They are stored in non-volatile memory, which preserves the information when the TV is turned off, so when it is turned on again, the TV will return to its previous station and volume level. As another example, the state of a personal computer is the contents of all the memory elements in it. When computers such as laptops go into hibernation mode to save energy by shutting down the processor, the state of the processor, memory, and I/O devices are stored on the computer's hard disk, so they can be restored when the computer comes out of hibernation. The processor can then pick up where it left off.

See also Data (computing) Variable (high-level programming language) - Container used to store an object's state

References

Worked examples

Example 1 — a first encounter with State (computer science)

Start with the simplest possible case. Write down what State (computer science) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to State (computer science) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about State (computer science) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of State (computer science)

In research
State (computer science) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses State (computer science) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
State (computer science) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cognition, Models of computation, so understanding it makes those chapters shorter.
In everyday life
Look for State (computer science) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “State (computer science)” →

How to study State (computer science) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what State (computer science) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain State (computer science) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is State (computer science) in simple terms?

In information technology and computer science, a system is described as stateful if it is designed to remember preceding events or user interactions and stateless if it doesn't. The remembered information is called the state of the system.

Why does State (computer science) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study State (computer science)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on State (computer science).

Tags

  • Cognition
  • Models of computation

Keep exploring