In the world of computing, everything ultimately reduces to sequences of symbols. Programs are symbol sequences, data is stored as bits, and every interaction with a computer, from a mouse click to a complex calculation, can be represented in this fundamental way. To study computation, we first need a precise vocabulary to describe these symbol sequences.
This chapter introduces the fundamental vocabulary of theoretical computer science. We will build a formal framework for describing information, which will serve as the bedrock for all the concepts that follow, from simple automata to the limits of what can be computed.
2.1 Aims
This chapter is designed to equip you with the foundational concepts for our entire journey. By the end, you will be able to:
- Define the Core Vocabulary: Understand and use the fundamental concepts of Alphabets, Words, and Languages. These are the basic building blocks for describing information in a computational context, much like letters form words and sentences in natural languages.
- Formalize Algorithmic Problems: Use this new vocabulary to precisely define what an “algorithmic problem” is. We will focus on crucial classes such as Decision Problems, Optimization Problems, Relation Problems, and Generation/Enumeration Problems.
- Measure Information Content: Explore the idea of compressibility by introducing Kolmogorov Complexity. This powerful concept allows us to measure the intrinsic information content of a word and provides a formal, computable definition for the elusive concept of randomness. This also serves as a valuable instrument for investigating computations and proving non-existence results.
2.2 Alphabets, Words, and Languages
Just as natural languages are built from letters, the languages of computation are built from symbols. To precisely define what computers process and how they do it, we must first formalize these fundamental building blocks.
2.2.1 Alphabets: The Building Blocks
Definition 2.1 (Alphabet)
An alphabet is a finite, non-empty set of symbols. We typically denote it with the Greek letter (Sigma). The elements of an alphabet are called letters, characters, or symbols.
The choice of symbols is arbitrary; what matters is that the set is finite. The meaning of the symbols comes from how we interpret them, not from their appearance. For instance, ‘0’ and ‘1’ could just as easily be ‘A’ and ‘B’ – their computational role remains the same.
Common Examples of Alphabets:
- The Boolean Alphabet: . This is the most fundamental alphabet in computing, representing binary data.
- The Latin Alphabet: .
- A Keyboard Alphabet: includes all symbols on a standard computer keyboard: letters, numbers, punctuation, and special characters like the space symbol ().
- The Alphabet for m-adic numbers: for any integer .
- The Alphabet for Logic: , used to represent Boolean formulas.
2.2.2 Words: Sequences of Symbols
Once we have an alphabet, we can form sequences of symbols. In computer science, any text, regardless of its length or meaning in natural language, is considered a “word.”
Definition 2.2 (Word)
A word (or string) over an alphabet is a finite sequence of letters from .
- The empty word, denoted by (or sometimes ), is the sequence with zero letters. Its length is .
- The length of a word , denoted , is the number of letters in the sequence.
- is the set of all possible words over the alphabet , including the empty word. This set represents every possible finite combination of letters from .
- is the set of all non-empty words over .
For example, 010011 is a word over with length . The set contains all possible binary strings: .
2.2.3 Representing Objects as Words (Encoding)
The true power of this formalism comes from its ability to represent any object of interest in computation as a unique word. This universal representation process is called encoding. It’s how we translate complex ideas—numbers, graphs, logical formulas, or even entire computer programs—into the simple sequences of symbols that computers can process.
Representing Numbers
A binary word can represent the natural number: We denote the standard, shortest binary representation of a number as . For , this representation conventionally starts with a ‘1’. For example, . .
A sequence of numbers, like , can be encoded as a single word using a special separator symbol, for instance:
Representing Graphs
A directed graph with vertices can be represented by its adjacency matrix, . In this matrix, the entry is 1 if there is an edge from vertex to vertex , and 0 otherwise.
We can flatten this matrix into a word by listing its rows, separated by a symbol.
Graph Encoding
The graph with the adjacency matrix
0 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 0 \end{pmatrix} $$ is encoded as the word `0011#0011#0101#0000#` over the alphabet $\{0,1,\#\}$. This representation is unambiguous; we can perfectly reconstruct the graph from the word.
Weighted graphs can be represented similarly by encoding the integer weights in binary, using a single to separate weights in a row and a double ## to separate rows. For example, if an edge weight is 7, it would be or 111.
Representing Logical Formulas
Boolean formulas can also be encoded as words. We can use an alphabet like . To handle an infinite number of variables like , we can encode the variable as the word x followed by .
Formula Encoding
The formula is encoded as:
(x1 ∨ x111) ∧ ¬(x1100)Here, , , and .
2.2.4 Operations on Words
We can manipulate words using several fundamental operations.
Definition 2.3 (Concatenation)
The concatenation of two words and , written , is the word formed by appending to the end of . For example, if and , then .
Concatenation is associative (i.e., ). The set of all words with the concatenation operation forms a mathematical structure called a monoid, with the empty word as the neutral element (). Concatenation is generally not commutative (i.e., unless specific conditions are met). The length of concatenated words is additive: .
Definition 2.4 (Reversal)
For a word , where , the reversal of is the word . The reversal of the empty word is . A useful property is that for any words , .
Definition 2.5 (Iteration)
For any word and any integer , the -th iteration of , denoted , is the word formed by concatenating with itself times. By definition, and . For example, .
Definition 2.6 (Subwords)
Let .
- is a subword (or substring) of if there exist words such that .
- is a prefix of if there exists a word such that .
- is a suffix of if there exists a word such that . A subword, prefix, or suffix is proper if it is not equal to the word itself (i.e., ).
Definition 2.7 (Symbol Count)
For a word and a symbol , the notation denotes the number of occurrences of the symbol in . For example, for , and . The total length of a word is the sum of the counts of all its symbols: .
2.2.5 Languages: Sets of Words
In formal language theory, the term “language” has a very broad meaning, encompassing any collection of words.
Definition 2.9 (Language)
A language over an alphabet is any subset of .
This means any set of strings, finite or infinite, is a language. Think of it as a collection of “valid” or “meaningful” words from the infinite pool of all possible words. Languages are the primary way we define the properties of strings we are interested in.
Examples of languages over :
- (the empty language, containing no words).
- (the language containing only the empty word).
- . This language represents strings with a block of
a’s followed by an equal number ofb’s. - (all words with an equal number of
a’s andb’s). - The set of all syntactically correct C++ programs (a language over ).
Since languages are sets, we can apply standard set operations like union (), intersection (), and complement (). We can also extend word operations to languages:
- Concatenation: . This forms a new language by concatenating every word from with every word from .
- Kleene Star: , where . The Kleene star represents concatenating words from the language zero or more times, including the empty word.
- Positive Closure: . This is similar to the Kleene star but excludes the empty word.
Lemma 2.1 (Distributivity of Concatenation over Union)
For any languages over an alphabet , the following holds: This means concatenation distributes over union, similar to multiplication over addition in arithmetic.
Lemma 2.2 (Inclusion for Concatenation and Intersection)
For any languages over an alphabet , the following inclusion holds:
Proof Idea
If a word is in , it means where and . This implies and . Therefore, and , which means .
Lemma 2.3 (Strict Inclusion Example)
There exist languages for which the inclusion in Lemma 2.2 is proper (i.e., not an equality).
Proof of Lemma 2.3
Let . Consider , , and .
First, calculate the left side: (since ). So, .
Next, calculate the right side: . . The intersection is .
Since , the equality does not hold. The word
10is in because it can be formed as (where ) and as (where ). However, it cannot be formed by concatenating a word from with a word from , as is empty.
2.2.6 Canonical Order and Homomorphisms
To work with infinite sets of words, it’s often useful to have a standardized, predictable way to list them. This is where the concept of a canonical order comes in.
Definition 2.8 (Canonical Order)
Let be an alphabet with a fixed ordering on its symbols, . The canonical order (or lexicographical order) on is defined as follows: for any two words , we say if:
- (shorter words come first), OR
- and comes before in the standard dictionary order (comparing symbol by symbol from left to right).
For example, for with , the canonical order is:
This ordering is crucial for enumeration problems, where we need to list the words of a language in a specific sequence.
Another powerful tool for relating languages to each other is a homomorphism, which is a function that preserves the structure of word concatenation.
Definition 2.10 (Homomorphism)
A homomorphism is a function between two alphabets and that satisfies two properties:
- (it maps the empty word to the empty word).
- for all words .
Because of the second property, a homomorphism is completely determined by its action on the individual symbols of the alphabet . If we know for every , we can find the image of any word by concatenating the images of its symbols. For example, if , then .
Homomorphism for Encoding
We can use a homomorphism to encode words from one alphabet into another. Let and . Define a homomorphism by and . Then the word
abais mapped to: .
Homomorphisms are fundamental in formal language theory for simplifying proofs and relating different classes of languages.
2.3 Algorithmic Problems
With our formal vocabulary of words and languages, we can now define what we mean by an “algorithmic problem.” Just as we formalized data, we must formalize the questions we ask about that data to study their solvability and complexity. We’ll focus on several main types.
2.3.1 Decision Problems
A decision problem is a question with a yes/no answer. We can formalize this using languages.
Definition 2.11 (Decision Problem)
A decision problem is a pair , where is an alphabet and is a language. The problem is: for any given word , decide whether .
An algorithm solves or decides this problem if it halts on every input and outputs “yes” (e.g., 1) if , and “no” (e.g., 0) if . A language for which such an algorithm exists is called recursive or decidable.
Primality Test
- Problem: Given a number, is it prime?
- Formalization: Let and . The problem is . An algorithm for this problem would take a binary string as input and output
1if is prime, and0otherwise.
Hamiltonian Cycle Problem
- Problem: Does a given graph contain a cycle that visits every vertex exactly once?
- Formalization: Let and . The problem is . The input would be an encoded graph, and the output would be
1or0.
2.3.2 Optimization Problems
Many real-world problems ask for the “best” solution, not just a yes/no answer.
Definition 2.14 (Optimization Problem)
An optimization problem is a 6-tuple , where:
- is the input alphabet.
- is the output alphabet.
- is the language of valid problem instances (i.e., inputs that have a meaningful interpretation). An is called a problem instance.
- is a function from to , where is the set of feasible solutions for an instance .
- is a function, , assigning a positive real cost to a feasible solution for a given instance .
- is the optimization objective.
The task is to find a feasible solution with the optimal (minimum or maximum) cost. An algorithm solves if for every , it outputs a solution such that is optimal.
Traveling Salesman Problem (TSP)
- Input: An edge-weighted complete graph . This would be encoded as a word .
- Feasible Solutions : The set of all Hamiltonian cycles in . Each cycle can be encoded as a word .
- Cost: The sum of the weights of the edges in a cycle.
- Goal: Minimum.
The main difficulty in optimization problems is that the set of feasible solutions is often astronomically large, making it impossible to check them all. For a graph with vertices, there are distinct Hamiltonian cycles, which grows extremely fast.
2.3.3 Relation Problems
Beyond decision and optimization problems lies a more general class: relation problems. While a decision problem asks for a yes/no answer (a function to ) and an optimization problem seeks a single best solution, a relation problem allows for multiple valid outputs for a single input.
Definition 2.13 (Relation Problem)
A relation problem is defined by a relation , where and are the input and output alphabets. The task is: for a given input , find any output such that .
If for a given no such exists, the problem may be undefined or require a specific output indicating this. The key difference from a function is that a relation can associate one input with many possible correct outputs.
Finding a Factor
- Problem: Given a composite number, find one of its non-trivial factors.
- Formalization: Let be the relation where if and only if is composite and is a factor of such that .
- Task: For input representing the number 15 (e.g.,
1111), both outputs representing 3 (11) and representing 5 (101) are correct. An algorithm only needs to find one of them.
2.3.4 Generation and Enumeration Problems
Some algorithmic tasks don’t require an input at all. Their purpose is to generate a specific output or to list all members of a set.
Definition 2.15 (Generation Problem)
The task of creating a single, specific word . An algorithm solves this by taking no input (or a trivial one like ) and producing . A program that generates can be considered an alternative representation of .
Definition 2.16 (Enumeration Problem)
The task of listing the words of a language . An algorithm for this task, given an integer , typically outputs the first words of according to a defined order (like the canonical order).
A language is recursively enumerable if an algorithm exists that can list all of its words (though the process might never halt if the language is infinite). If an algorithm can also decide membership in the language (a decision problem), the language is called recursive or decidable.
Enumerating Primes
- Problem: List the first prime numbers.
- Formalization: Let be the language of binary representations of prime numbers.
- Task: An enumeration algorithm, given input , would output the first words from in canonical order. For , the output would be
10, 11, 101, 111(representing ).
2.4 Kolmogorov Complexity
Is the string 0101010101010101 complex? What about 1101001011101001? Intuitively, the first is simple because it has a short description: “repeat 01 eight times.” The second seems random, with no obvious pattern. Kolmogorov complexity formalizes this intuition by measuring the intrinsic information content of a word.
Definition 2.17 (Kolmogorov Complexity)
The Kolmogorov complexity of a word , denoted , is the length of the shortest program (in a fixed, universal programming language) that generates as its output and then halts.
This definition elegantly circumvents the problem of choosing a specific compression method by allowing any computable compression. A program that generates a string is the ultimate compressed representation of that string. The length of this shortest program is the measure of its information content.
Lemma 2.4 (Upper Bound)
There exists a constant such that for every word : This is because we can always write a simple program that just contains the string literally and prints it. The constant accounts for the fixed length of the
Lemma 2.5 (Incompressibility)
For every integer , there exists at least one word of length such that .
Proof Idea
This is a simple counting argument. There are possible binary words of length . The number of programs (binary strings) shorter than is the sum of the number of binary strings of length . This sum is . Since there are words of length but only programs shorter than , by the Pigeonhole Principle, at least one word of length cannot be generated by any program shorter than itself. This word is incompressible.
This implies that most long strings are incompressible, which leads to the idea of defining randomness as incompressibility.
Theorem 2.1 (Invariance Theorem)
Let A and B be any two universal programming languages. There exists a constant (that depends only on A and B) such that for all words : This theorem is crucial. It states that the choice of programming language does not significantly change the Kolmogorov complexity of a string. The complexity is robust and language-independent, up to an additive constant. The constant represents the length of a compiler or interpreter program that translates between the two languages. This justifies using “the” Kolmogorov complexity without specifying a particular programming language.
The existence of an algorithm to decide a language can lead to strong statements about the complexity of the words in that language.
Theorem 2.2 (Kolmogorov Complexity of Decidable Language Elements)
Let be a recursive (decidable) language over . Let be the -th word in according to the canonical order. Then there exists a constant such that for all :
Proof Idea
We can construct a program that generates . This program takes as input and uses the decider for as a subroutine. It works as follows:
- Initialize a counter
i = 0.- Generate all words one by one in canonical order ().
- For each word , run the decider for .
- If , increment the counter
i.- If
iequals the inputn, halt and output the current word .The program itself has a fixed size, independent of . The only part of the program that changes is the input number . The length of the binary representation of is approximately . The constant accounts for the fixed size of the generation and checking logic. This theorem shows that if a word belongs to a decidable set, its complexity is bounded by the complexity of its index in that set. This implies that words in decidable languages, when ordered canonically, cannot be “too random” relative to their position in the enumeration.
A word is considered random if it is incompressible, i.e., if . This provides a powerful, algorithmic definition of randomness, aligning with the intuition that a random object has no shorter description than itself.
Definition 2.19 (Randomness)
A word is called random if its Kolmogorov complexity is at least its length, i.e., . A number is called random if .
Application: Lower Bounds for Prime Numbers (Weaker Prime Number Theorem)
Kolmogorov complexity can be used to prove results in number theory. Here, we present a proof idea for a weaker version of the Prime Number Theorem, demonstrating that prime numbers are not “too sparse.”
Lemma 2.6 (Infinite Prime Factors for Complex Numbers)
Let be a strictly increasing infinite sequence of natural numbers such that for every . For every , let be the largest prime number that divides . Then the set is infinite.
Proof Idea (by contradiction)
Assume is finite. Let be the largest prime in . Then every can be uniquely represented as a product of primes from : . We can construct a program that generates given the exponents . The length of this program would be roughly proportional to the sum of the lengths of the binary representations of these exponents. Since each , the program length would be approximately . If were finite, would be a constant. This would imply for some constant . However, for sufficiently large , grows much slower than . This contradicts our assumption that . Therefore, must be infinite.
This lemma, combined with careful encoding arguments, can be used to derive lower bounds on the density of prime numbers, showing that they appear frequently enough to support various computational tasks, especially in randomized algorithms.
2.5 Summary and Outlook
This chapter has laid the essential groundwork for our study of theoretical computer science.
- We defined alphabets, words, and languages as the formal tools to describe data and problems, emphasizing that any computational object can be encoded as a word.
- We categorized algorithmic tasks into decision problems, optimization problems, relation problems, and generation/enumeration problems, providing a precise framework for discussing what algorithms do.
- We introduced Kolmogorov complexity as a robust measure of the intrinsic information content of a string, which also provides a formal definition of randomness. This concept is powerful for both theoretical proofs and understanding the limits of compression.
With this formal language in hand, we are now ready to explore the machines that process it. In the next chapter, we will start with the simplest model of computation: the finite automaton, and use the concepts developed here to understand its capabilities and limitations.
Previous Chapter: Chapter 1 - Introduction Next Up: Chapter 3 - Finite Automata
2.6 Exercises
Exercise 2.1
How many different words of length can be formed over an alphabet with ?
Solution
For each of the positions in the word, there are choices for the symbol. Thus, there are ( times) = possible words.
Exercise 2.2
Given the alphabet . Let be positive integers with . (a) Determine the number of different words of length with exactly occurrences of the symbol . (b) Determine the number of different words of length with at most occurrences of the symbol .
Solution
(a) This is a combinatorial problem. We need to choose positions for the symbol out of available positions. The number of ways to do this is given by the binomial coefficient . For the remaining positions, we can place either a
0or a1. Since there are 2 choices for each of these positions, there are possibilities. Therefore, the total number of such words is .(b) The number of words of length with at most occurrences of is the sum of words with occurrences of . This is .
Exercise 2.3
A binary representation of every positive number begins with a 1. How long is for a given number ?
Solution
For , the length of is . For , , so its length is 1.
Exercise 2.4
Let for an . Consider as an -adic representation of a number . How do you compute ?
Solution
If , where , then . This is the standard positional numeral system conversion.
Exercise 2.5
The proposed representation of a graph as a word over has length for a graph with vertices (using rows and separators). Think of a shorter unique representation of graphs over the alphabet .
Solution
For an undirected graph, the adjacency matrix is symmetric. We only need to store the upper (or lower) triangle of the matrix. For vertices, there are entries in the upper triangle (excluding the diagonal). We could list these entries in a fixed order (e.g., row by row, then column by column). For example, for a graph with 3 vertices, instead of
a11a12a13#a21a22a23#a31a32a33#, we could just lista12a13a23. This would be bits, plus separators if needed. If we assume a fixed number of vertices is known, we might not even need separators.
Exercise 2.6
Design a representation for graphs over the alphabet .
Solution
We can encode the number of vertices first, then the adjacency matrix. For example,
Bin(n)#followed by the flattened adjacency matrix (row by row, without separators between bits, but with a separator between rows). A more compact way: followed by the binary string representing the concatenation of all rows of the adjacency matrix. For example, for a 3-vertex graph with adjacency matrix011;101;110, the encoding could beBin(3)#011101110. The number of vertices allows us to reconstruct the matrix.
Exercise 2.7
Prove that for any words , .
Solution
Let and , where . Then . The reversal of is .
Separately, and . Concatenating these gives .
Since and are identical, the property holds.
Exercise 2.8
What is the maximum number of distinct subwords a word of length can have? List all different subwords of the word
abbcbbab.Solution
A word of length can have at most distinct subwords (including the empty word). This maximum is achieved when all possible substrings are unique, for example, in a word where all characters are distinct.
For the word
abbcbbab(length ):
- Length 0:
- Length 1:
a,b,c- Length 2:
ab,bb,bc,cb,ba- Length 3:
abb,bbc,bcb,cbb,bba,bab- Length 4:
abbc,bbcb,bcbb,cbba,bbab- Length 5:
abbcb,bbcbb,bcbba,cbbab- Length 6:
abbcbb,bbcbbab,bcbbab- Length 7:
abbcbbab- Length 8:
abbcbbabDistinct subwords: ,
a,b,c,ab,bb,bc,cb,ba,abb,bbc,bcb,cbb,bba,bab,abbc,bbcb,bcbb,cbba,bbab,abbcb,bbcbb,bcbba,cbbab,abbcbb,bbcbbab,bcbbab,abbcbbab. Total count: 28 distinct subwords. Using the formula: . The difference arises because not all subwords are unique (e.g.,bbappears multiple times).
Exercise 2.9
Let and . Which words are in the language ?
Solution
- From : , , , .
- From : , , , .
- From : , , , .
So, .
Exercise 2.10
Let be languages over the alphabet . Does hold?
Solution
No, the equality does not hold. The same counterexample logic applies as for multi-letter alphabets. Let , , and .
Left side: . So .
Right side: . . .
Since , the equality does not hold.
Exercise 2.11
Let and for two alphabets and with . Does hold?
Solution
Yes, the equality does hold if .
We know that always holds.
Now we prove the reverse inclusion: . Let . This means and . So, for some and . And for some and .
Since and , and , any word that can be decomposed into a prefix from and a suffix from has a unique such decomposition.
From and , we must have (since they are both prefixes in ) and (since they are both suffixes in ).
Let and . Then we have , and and . This implies . Therefore, .
Since we have shown inclusion in both directions, the equality holds when the alphabets are disjoint.
Exercise 2.12
Do there exist languages such that is finite and is infinite?
Solution
No, such languages do not exist. The property always holds. If a set A is a subset of set B, and A is infinite, then B must also be infinite. Conversely, if B is finite, A must be finite. Therefore, if were infinite, its subset could not be finite.
Exercise 2.13
Prove or disprove: .
Solution
This statement is true.
Let . This language consists of all words that have zero or more
a’s followed by zero or moreb’s (e.g., ).The left side is , which means concatenating zero or more words from . The right side is , which is the set of all possible words over the alphabet .
We need to show that any word in can be formed by concatenating words from .
Consider any word . If contains no
b’s, it’s of the form , which is in . So . If contains noa’s, it’s of the form , which is in . So .If contains both
a’s andb’s, it can be broken down into segments ofa’s andb’s. For example,aaabbab. This can be written as . Each of these segments can be viewed as a word from :
- (with )
- (with )
Therefore, any word in can be decomposed into a concatenation of words from .
Conversely, any word formed by concatenating words from will only contain
a’s andb’s, so it will be in .Thus, the equality holds.
Exercise 2.14
Let be a homomorphism from to . Prove by induction that for every word , where for , .
Solution
Base Case: For , . By definition of homomorphism, . The right side is an empty concatenation, which is also . So the base case holds.
Inductive Hypothesis: Assume that for any word of length , .
Inductive Step: Consider a word of length , so . We can write . Let and . By definition of homomorphism, . By the inductive hypothesis, . And (since is a single symbol, its image is just applied to it). Therefore, .
This completes the induction.
Exercise 2.15
Define a homomorphism from to that maps infinitely many different words from to the same word from .
Solution
A homomorphism is defined by its action on individual symbols. To map infinitely many different words to the same word, we can map some symbols to the empty word .
Let be defined as:
Then, any word containing one or more
#symbols will map to the same word as one without them. For example:Thus, all words of the form for map to
01. This is an infinite set of words mapping to a single word.
Exercise 2.16
Define an injective homomorphism from to to create a unique representation of Boolean formulas over .
Solution
To ensure injectivity, each symbol from must map to a unique non-empty binary string, and the mapping must be prefix-free (no mapping of a symbol is a prefix of another symbol’s mapping) to allow unique decoding.
Let . We can define as follows:
Each symbol is mapped to a unique 3-bit string. This ensures that any word in will have a unique image in . For example, the formula would first be encoded into a word over (e.g.,
(x1 ∨ x111) ∧ ¬(x1100)), and then this homomorphism would map each symbol of that word to its 3-bit representation.
Exercise 2.17
Let and be two alphabets. Let be a homomorphism from to . For every language , we define . Let . Prove or disprove the following statement: .
Solution
The statement is true. We prove this by double inclusion.
: Let . By definition of , there exists a word such that . By definition of language concatenation, for some and . Since is a homomorphism, . By definition of , and . Therefore, .
: Let . By definition of language concatenation, for some and . By definition of , there exist such that , and there exist such that . Substituting these into the expression for : . Since is a homomorphism, . Since and , it follows that . Therefore, .
Since we have shown inclusion in both directions, the equality holds.
Exercise 2.18
For the Traveling Salesman Problem (TSP) on a complete graph with vertices, how many feasible solutions (Hamiltonian cycles) are there?
Solution
A Hamiltonian cycle visits every vertex exactly once and returns to the starting vertex.
- Fix a starting vertex: Let’s pick an arbitrary vertex, say , as the starting and ending point.
- Arrange the remaining vertices: The remaining vertices can be arranged in different sequences. Each sequence forms a unique path starting from , visiting all other vertices, and returning to .
- Account for cycle symmetry: For an undirected graph, a cycle can be traversed in two directions (e.g., is the same cycle as ). So, we divide by 2.
The total number of distinct Hamiltonian cycles is .
Exercise 2.19
The minimum vertex cover problem (MIN-VC) is a minimization problem where one seeks a vertex cover with minimal cardinality for a given (undirected) graph G. (a) Determine the set of all vertex covers of the graph from Figure 2.5. (b) Give the formal description of MIN-VC. Specify the representation of inputs and outputs over the alphabet .
Solution
(a) Assuming Figure 2.5 refers to a specific graph not provided here, I will describe the process. A vertex cover is a subset of vertices such that for every edge , at least one of or is in . To find all vertex covers, one would systematically check subsets of vertices. For a minimal vertex cover, one would find all vertex covers and then select those with the smallest cardinality.
(b) Formal description of MIN-VC:
- (input alphabet for graph representation).
- (output alphabet for vertex set representation).
- : The language of words encoding valid undirected graphs. A word encodes a graph . (e.g.,
Bin(n)#followed by the upper triangle of the adjacency matrix).- : For an input encoding graph , is the set of all words such that encodes a subset of vertices and is a vertex cover for . (e.g., a subset could be encoded as a binary string of length where the -th bit is 1 if , and 0 otherwise).
- : For a solution (encoding vertex set ) and instance (encoding graph ), (the cardinality of the vertex cover).
- .
Exercise 2.24
Argue why is approximately for some constant . What does this tell you about the “randomness” of the string ?
Solution
To generate the string , a program only needs to know the value of and then print
0that many times. A simple program could look like:function generate_zeros(n): for i from 1 to n: print('0')The binary representation of the number requires approximately bits. The rest of the program (the function definition, loop structure, print statement, etc.) has a fixed length, which we can denote as a constant . Therefore, the length of the shortest program to generate is roughly .
This tells us that is not random. Its Kolmogorov complexity is significantly smaller than its length (for large ). A random string, by definition, should have a Kolmogorov complexity approximately equal to its length. The string is highly compressible and predictable.
Exercise 2.27
Prove that for any integers and , there are at least distinct words of length such that .
Solution
This is a counting argument.
- Total words of length : There are distinct binary words of length .
- Words with low Kolmogorov complexity: Consider all programs (binary strings) whose length is less than . The number of binary strings of length is . The total number of programs with length less than is: Each of these programs can generate at most one distinct word. Therefore, there are at most words whose Kolmogorov complexity is less than .
- Words with high Kolmogorov complexity: The number of words of length such that must be at least the total number of words of length minus the number of words with Kolmogorov complexity less than . So, the number of such words is at least . The question asks to prove at least , which is a slightly looser but still correct bound.
Exercise 2.28
Prove that there are infinitely many numbers such that .
Solution
This is a direct consequence of the counting argument used in Lemma 2.5. Let be the length of the binary representation of . We know that there are numbers whose binary representation has length . The number of programs (binary strings) of length less than is .
Consider numbers such that has length . There are such numbers (from to ). If all these numbers had Kolmogorov complexity less than , it would mean we could generate distinct numbers using only programs, which is a contradiction.
Therefore, for every length , there must be at least one number such that . Since , this means . Since there are infinitely many possible lengths , there are infinitely many such numbers .
Key Takeaways
- Formal Language Theory is Foundational: Alphabets, words, and languages provide the precise mathematical framework for describing all computational objects and problems.
- Encoding is Universal: Any object relevant to computation can be uniquely encoded as a word over a finite alphabet, enabling universal processing by algorithms.
- Problem Types: Algorithmic tasks are formally categorized into decision, optimization, relation, generation, and enumeration problems, each with specific objectives.
- Kolmogorov Complexity: This concept offers a robust, machine-independent measure of a word’s intrinsic information content, defining randomness as incompressibility. It’s a powerful tool for theoretical proofs.
- Limits of Computation: Even at this foundational level, we begin to see hints of the inherent limits of computation, both in terms of what can be compressed and what can be efficiently solved.