Exercise

Random Practice Questions on Languages

A stream of freshly drawn questions on languages: compute operations on small sets, decide membership, count words, find a shortest word, and judge claims, with instant checking, hints and step-by-step solutions.

Last updated:


Practice until the operations feel automatic

Every press of “New question” draws a fresh question at random from a set of templates, so you can practise as long as you like.
Choose a level, answer, and the tool checks your answer at once.
A language here is a set of words, and the questions use the operations of Words: Inductive Definitions and Operations and Languages: Operations and Equalities:
union, intersection, difference, symmetric difference, concatenation, reverse, the square L2=L⋅LL^2=L\cdot L and the prefix, suffix and subword sets Pref\mathrm{Pref}⁠, Suff\mathrm{Suff} and Sub\mathrm{Sub}⁠.
Some questions use the languages that the automaton workbench knows (for example “words that end with abab”), and some are about DNA sequences or file names.

How the answers are checked

When the answer is a set of words, the tool compares the set you typed with the correct set exactly, over all the words and not only a few samples, and lists the words that are missing from your answer and the words that should not be there.
The shortest-word and counting questions are also checked exactly, and not on the basis of a few sample words.
You can type a set with or without braces, write ε\varepsilon as ε or eps, and list the words in any order.

The question generator needs JavaScript. Use the written questions below on paper instead.

Add ?seed=123 to the page address to get a specific first question again, for example to discuss it in class. The score and the streak are kept only until you leave the page.

Questions on paper

Question 1. Let X={a,ab}X=\{a,ab\} and Y={b,ε}Y=\{b,\varepsilon\}⁠. Compute X⋅YX\cdot Y and say how many words it has.

Hint 1

Write the four products: every word of XX glued to every word of YY⁠.

Hint 2

A set lists every word once, even when two pairs give it. Look for two equal products.

Answer

a⋅b=aba\cdot b=ab⁠, a⋅ε=aa\cdot\varepsilon=a⁠, ab⋅b=abbab\cdot b=abb⁠, ab⋅ε=abab\cdot\varepsilon=ab⁠. So X⋅Y={a,ab,abb}X\cdot Y=\{a,ab,abb\}⁠, three words: the product abab appears twice.

Question 2. Is the word abbaabba in the language L1∩L2CL_1\cap L_2^{C}⁠, where L1L_1 is “words with an even number of aa‘s” and L2L_2 is “words that end with aa”?

Hint

Check the two conditions separately: abba∈L1abba\in L_1⁠, and abba∉L2abba\notin L_2 (the complement means “not in L2L_2”).

Answer

abbaabba has two aa‘s, so it is in L1L_1⁠. It ends with aa⁠, so it is in L2L_2 and therefore not in L2CL_2^{C}⁠.
The intersection needs both, so the answer is no.

Question 3. How many words of length 44 over {a,b}\{a,b\} contain no two equal letters next to each other?

Hint

After the first letter every letter is forced: it must differ from the previous one.

Answer

The first letter has 22 choices and each of the next three letters has exactly 11⁠, so there are 22 words:
abababab and babababa⁠.

Back to the glossary.