Theoretical Computer Science through Examples
-
A Formal Language as a Set of Strings
A formal language is a set of finite strings over a chosen alphabet. It can include the empty string, regardless of whether longer strings are present.
-
The Empty Word and the Empty Language
The empty word is one string of length zero. The empty language is a set containing no strings.
-
Concatenating Two Formal Words
Concatenation joins strings in order and adds their lengths. Changing word order can change the resulting sequence.
-
Union and Concatenation for Languages
Language union keeps words accepted by either input set. Language concatenation uses all pairs to create joined words.
-
Kleene Star on a Small Language
The Kleene star contains all concatenations of zero or more words from its input language.
-
Running a Deterministic Automaton by Hand
A deterministic finite automaton starts in a designated state, reads one symbol at a time, and accepts when the final state is designated accepting.
-
A Finite State Remembers Parity Without a Count
A machine can retain just enough information about earlier symbols to decide later behavior. For parity, two states summarize all possible counts.
-
Tracking the Last Symbol with a Finite State
A small automaton can recognize words ending in a specified symbol by updating its retained state on every step.
-
Remembering That a Pattern Has Occurred
An automaton recognizing whether a substring occurred can preserve a found state after the first detection.
-
A Dead State for Unsupported Prefixes
A complete deterministic automaton defines a transition for every state and alphabet symbol. A dead state can preserve rejection when no future extension can repair a prefix.
-
Running Two Automata in a Product State
A product automaton can track two machines over the same input by storing their current states as an ordered pair.
-
Two Possible Paths in a Nondeterministic Automaton
A nondeterministic automaton can allow several next states for one input. A word is accepted if at least one valid complete path accepts.
-
Reading Three Regular Expression Operations
Alternation selects either pattern. Concatenation places matches one after another. Star repeats a pattern zero or more times.
-
Whole-Input and Substring Matching
A whole-input match asks whether a complete string belongs to a language. A substring search asks whether some contiguous portion belongs.
-
Token Kinds and Their Source Spellings
A lexer can classify spans into token kinds while keeping their original spellings or parsed values for later stages.
-
Recognizing One Kind of Balanced Parenthesis
For a single bracket kind, a count of currently open brackets can track whether a prefix can still be extended to a balanced string.
-
One Grammar with Two Alternative Forms
A grammar production specifies replacements for a category of strings. Alternatives can describe different valid forms under one name.
-
Terminals and Nonterminals in a Grammar
Terminal symbols form the final words. Nonterminals represent categories that a production may replace during derivation.
-
Ambiguity Through Two Parse Trees
A grammar is ambiguous when one terminal string has more than one distinct parse tree under that grammar.
-
Associativity in an Expression Tree
Associativity rules can decide which repeated operator binds first when an expression has no grouping parentheses.
-
A Tape as Abstract Read–Write Storage
A Turing machine can store symbols on a tape, observe the current cell, and use its finite control to choose a write and movement.
-
What It Means to Decide a Language
A decider halts on every allowed input and gives the correct yes or no answer to membership.
-
Recognition by Searching for a Witness
Some recognizers answer yes once they find acceptable evidence but may keep searching when none exists.
-
A Certificate for an Efficiently Checkable Yes Answer
A certificate supplies information a verifier can inspect along with an input to establish an affirmative instance under a defined problem.
-
Finding a Witness and Checking a Supplied Witness
A search procedure must obtain evidence satisfying the condition. A verifier can start from already supplied evidence and test it.
-
Checking a Reduction in Both Directions
A many-one reduction translates an instance so its yes or no answer agrees with that of the original instance.
-
The Direction of a Problem Reduction
Reducing problem A to B gives a way to use a solver for B when answering inputs of A, under the reduction's conditions.
-
Encoded Input Length and Numeric Magnitude
A numeric value can be much larger than the number of bits needed to write it. Complexity claims depend on the chosen input encoding.
-
Why a Small State Description Can Have Many Configurations
A state made from several independent fields has a number of possible combinations given by the product of their possible values.
-
Turning an Optimization Question into a Threshold Decision
An optimization task seeks the best feasible value. A threshold version asks whether any feasible result reaches a specified limit.