4.6.1 · D4Theory of Computation

Exercises — Alphabet, string, language — formal definitions

1,869 words8 min readBack to topic

Level 1 — Recognition

Can you read the notation and spit out the definition?

L1.1 — Length

State and .

Recall Solution

counts symbol-positions. The string has six positions written left to right, so . The empty string has no positions, so .

L1.2 — Membership on the three floors

For , decide each: (a) is ? (b) is ? (c) is ?

Recall Solution

(a) Yes. and the layer is included, so . (b) No. is the language holding zero strings — nothing is inside it, not even . (c) No. holds exactly one string (the blank word), so . Different floors: is a string, and are languages.

L1.3 — Count a layer

How many strings are in for ? List two of them.

Recall Solution

. Two examples: and .


Level 2 — Application

Plug into the formulas and compute.

L2.1 — Cumulative count

For , how many strings have length at most (i.e. length or )?

Recall Solution

Why sum the layers? "Length at most 3" is the union , and these layers are disjoint (a string has exactly one length), so counts add:

L2.2 — Concatenation of languages

With and over , compute .

Recall Solution

Rule: — glue every left piece to every right piece.

Collect as a set (drop the duplicate ): . So .

L2.3 — Power of a string

Let . Write out and give .

Recall Solution

, so . Length multiplies: . ✔


Level 3 — Analysis

Explain WHY, handle every case.

L3.1 — Reversal length

Prove for every string , and verify on .

Recall Solution

Reversal is defined by and . Induct on length. Base: . ✔ Step: assume . Then for , Reversal only re-orders positions — a bijection on positions — so the count can't change. Check: , and . ✔

L3.2 — Two empties in an operation

Evaluate and justify: (a) for ; (b) ; (c) .

Recall Solution

(a) . There is no to pick, so no pair exists: . (b) , since . So . (c) . By definition (always included), and for . Union: .

L3.3 — Even-length language

Let . Is ? Is finite? How many strings of length does it contain?

Recall Solution

and is even, so . is infinite — it contains a string of every even length , so there is never a "last" one. Length- strings: every string of length has even length, so all of qualifies: .


Level 4 — Synthesis

Build the object / combine several ideas.

L4.1 — Counting a described language

Over , let . How many strings are in ?

Recall Solution

Fix the constrained positions, count the free ones. A length-5 string has positions . The problem forces and . The remaining are free, each with choices. By the multiplication rule:

L4.2 — Language power

Let (the two single-symbol strings). Show and use it to find .

Recall Solution

concatenates picks, each pick being one symbol from . A row of freely-chosen symbols is exactly a length- string, so . Therefore .

L4.3 — Distinguish endpoints

For , list all strings in of length , and state .

Recall Solution

with , .

  • : (length 0)
  • : (length 2)
  • : (length 4)

Length : . Since has one string, each power has one string: .

Because everything in this section is counting strings by fixing some positions and freeing others, the picture below shows the "free-position" view that drives L4.1.

Figure — Alphabet, string, language — formal definitions

Level 5 — Mastery

Prove / reason about the whole framework.

L5.1 — Cardinality of the "at most " set

Give a closed formula for with , and evaluate at .

Recall Solution

Sum the disjoint layers, a finite geometric series: (Geometric-series identity with .) At : .

L5.2 — is countable (constructive proof)

Explain a concrete rule that assigns every string of a unique natural-number position, proving is countably infinite. Give the positions of and .

Recall Solution

Use shortlex (canonical) order: list strings by length first, and within a length use ordinary alphabetical order ( before ). This produces a single infinite list with no gaps and no repeats, so numbering it is a bijection with the naturals — that is the definition of countably infinite. The list begins (): So sits at position and at position . Every finite string appears at some finite position because it has a finite length and only finitely many () strings share that length ahead of it. See the ordering below.

Figure — Alphabet, string, language — formal definitions

L5.3 — Why is not countable (idea, not full diagonal)

is countable, yet the set of all languages over is uncountable. In one paragraph, say why this matters for the rest of the course.

Recall Solution

A language is any subset of , so the set of all languages is the power set . Cantor's theorem says the power set of an infinite set is strictly larger — uncountable. But every machine (DFA/NFA, regex, grammar, Turing machine) is itself a finite description, so there are only countably many machines. Countably many machines cannot cover uncountably many languages ⇒ some languages are recognised by no machine at all — they are undecidable. This mismatch is the seed of the limits and undecidability results that dominate the rest of the theory and separate the regular languages from everything bigger.


Recall Master checklist (open only after finishing all levels)
  • , and is even — obeys length-conditions like any string.
  • .
  • ; "at most " sums to when .
  • Language concatenation returns a set — deduplicate before counting.
  • because is always included.
  • countable (finite strings, shortlex); uncountable (seed of undecidability).