Exercise

Tables and Splits: Concatenation, Star, Prefixes

Practice concatenation of languages with a product table, powers and star with split searches, cutting a word into two parts, and prefixes, suffixes and substrings. Every question is drawn at random and checked at once.

Last updated:


Four small exercises on the operations on languages

The tool below draws practice questions and checks the answers at once.
Press “New question” for another one. The question code lets you return to the same question (add ?seed= and the code to the address, for example ?seed=7).
The score counts each question once, at its first check.

  • Concatenation table. The concatenation L1L2L_1L_2 is the set of all words xyxy with x∈L1x\in L_1 and y∈L2y\in L_2⁠. Fill in the product of every pair, see when two different pairs give the same word (a collision), and compare the number of words ∣L1L2∣|L_1L_2| with the product ∣L1∣⋅∣L2∣|L_1|\cdot|L_2| of the numbers of words of L1L_1 and L2L_2⁠.
  • Powers and star. L2=LLL^2=LL⁠, L3=LLLL^3=LLL⁠, and L∗L^* is the set of all products of any number of words of LL (the empty product is ε\varepsilon⁠). The tool shows a split into words of LL for a word that belongs, and tries every split for a word that does not.
  • Split marker. Mark where to cut a word ww into w=xyw=xy so that x∈L1x\in L_1 and y∈L2y\in L_2⁠. There can be no valid split, one, or several.
  • Prefix, suffix, substring. A prefix of ww is a beginning of it, a suffix is an ending, and a substring is any block of consecutive letters (all three may be empty, and ww itself is all three). Classify a word, then build Pref(L)\mathrm{Pref}(L)⁠, Suff(L)\mathrm{Suff}(L) and Sub(L)\mathrm{Sub}(L) of a small language.

The tool needs JavaScript. Use the questions below on paper instead.

Questions on paper

Question 1. Let L1={a,aa,aaa}L_1=\{a,aa,aaa\} and L2={aa,aaa,aaaa}L_2=\{aa,aaa,aaaa\}⁠. List L1L2L_1L_2 and compare ∣L1L2∣|L_1L_2| with ∣L1∣⋅∣L2∣|L_1|\cdot|L_2|⁠.

Hint

Write the nine products x⋅yx\cdot y in a table and look for equal words.

Answer

The products are a⋅aa=aaaa\cdot aa=aaa⁠, a⋅aaa=aaaaa\cdot aaa=aaaa⁠, a⋅aaaa=aaaaaa\cdot aaaa=aaaaa⁠, aa⋅aa=aaaaaa\cdot aa=aaaa⁠, aa⋅aaa=aaaaaaa\cdot aaa=aaaaa⁠, aa⋅aaaa=aaaaaaaa\cdot aaaa=aaaaaa⁠, aaa⋅aa=aaaaaaaa\cdot aa=aaaaa⁠, aaa⋅aaa=aaaaaaaaa\cdot aaa=aaaaaa and aaa⋅aaaa=aaaaaaaaaa\cdot aaaa=aaaaaaa⁠.
So L1L2={a3,a4,a5,a6,a7}L_1L_2=\{a^3,a^4,a^5,a^6,a^7\} and ∣L1L2∣=5<9=∣L1∣⋅∣L2∣|L_1L_2|=5<9=|L_1|\cdot|L_2|⁠: three pairs collide on a5a^5 and two pairs on a4a^4 and on a6a^6⁠.

Question 2. Let L={a,ab}L=\{a,ab\}⁠. Which of aabaab⁠, abaaba⁠, abbabb belong to L2L^2⁠?
Does abbabb belong to L∗L^*⁠?

Hint

Try every place to cut the word into two parts and ask whether both parts are in LL⁠.
For L∗L^*⁠, cut from the left and see where the cut fails.

Answer

aab=a⋅abaab=a\cdot ab and aba=ab⋅aaba=ab\cdot a belong to L2L^2⁠. For abbabb the cuts are ε∣abb\varepsilon\mid abb⁠, a∣bba\mid bb⁠, ab∣bab\mid b and abb∣εabb\mid\varepsilon⁠, and each has a part outside LL⁠, so abb∉L2abb\notin L^2⁠.
It is not in L∗L^* either: the words of LL that abbabb can start with are aa and abab⁠, and after either of them the rest (bbbb or bb⁠) starts with bb⁠, which no word of LL does.

Question 3. Let w=aabw=aab⁠, L1={ε,a,aa}L_1=\{\varepsilon,a,aa\} and L2={ab,b}L_2=\{ab,b\}⁠. Find all splits w=xyw=xy with x∈L1x\in L_1 and y∈L2y\in L_2⁠.

Hint

Write the four places where ww can be cut and check in each whether both parts are in the languages.

Answer

The cuts are ε∣aab\varepsilon\mid aab⁠, a∣aba\mid ab⁠, aa∣baa\mid b and aab∣εaab\mid\varepsilon⁠. The first fails because aab∉L2aab\notin L_2 and the last because aab∉L1aab\notin L_1⁠.
The other two work: a⋅aba\cdot ab and aa⋅baa\cdot b⁠. So there are two valid splits.

Question 4. How many different prefixes, suffixes and substrings does w=abbaw=abba have (counting ε\varepsilon and ww⁠)?

Hint

A prefix is determined by its length: write the prefix of length 00⁠, 11⁠, 22 and so on.
For substrings write first the length and then the starting place.

Answer

Prefixes: ε,a,ab,abb,abba\varepsilon,a,ab,abb,abba (5). Suffixes: ε,a,ba,bba,abba\varepsilon,a,ba,bba,abba (5). Substrings: ε,a,b,ab,bb,ba,abb,bba,abba\varepsilon,a,b,ab,bb,ba,abb,bba,abba (9).

Question 5. Which words are both a prefix and a suffix of w=abbaw=abba⁠?

Answer

They are ε\varepsilon⁠, aa and abbaabba⁠.

Back to Languages: Operations and Equalities, or see the glossary.