cfgrep - Exercises

The following exercises illustrate the usage of of cfgrep.
  1. For this problem we consider the following two languages over {0,1} :
    A =
    even length palindromic bitstrings
    B =
    bitstrings describing left-first traversals of full binary trees
    The language A is clear. B is not as clear, so let me explain: A full binary tree is a tree containing at least one child, such that every node is either a leaf, or is "full" -so has both a left and right subtrees. A left-first traversal describes a bitstring as follows: For example, the tree:
       / \
      /\ /\
     /\   /\
    /\ 
    
    is described by the bitstring 000011110101
    1. For each of the languages above, come up with a context free grammar.
    2. Use cfgrep to solve the following puzzle: The file searchfile.txt contains exactly one line whose bitstring is in A, and exactly one line whose bitstring is in B. What word occurs on each resulting line? Hint: Together they name the character origins in a recently released movie on DVD.
    SOLUTION
  2. For this problem we consider the following three languages over {0,1}:
    C =
    0*1* - { 0 n 1 n | n ≥ 0 } ( the complement of 0 n 1 n in 0*1* )
    D =
    bitstrings with more 1's than 0's
    E =
    { ( 01) m 0( 01) m (01) n 0( 01) n | m, n ≥ 0 }
    F =
    bitstrings that are not of the form ww. (Hint: play around with your grammar for E)
    1. For each of the languages above, come up with a context free grammar.
    2. For each of the languages C, D, E, F use cfgrep to count the number of 16-bit substrings that are in that language. Here's a file containing all length 16 bit-strings listed on separate lines.
    3. Use cfgrep to solve the following puzzles: For each language C, D, E, F there is a file which contains exactly one line in the given language. What was the unique matching bitstring? Write the cfgrep command you used to find the string. Here are the files that you are supposed to search through
    SOLUTION
  3. Consider the languages G, H, I defined by:
    G =
    { 0i1j0k   |   i = j or j = k where i,j,k ≥ 0 }
    H =
    { 0i1j   |   at least one quarter of the bits are 0 and at least one quarter are 1's }
    I =
    even length strings that are palindromic except at exactly one bit = { uAvvRBuR   |   u, v are arbitrary, and A, B are opposite bits }
    Use cfgrep to solve the following puzzle: A secret message has been hidden via a file containing all length 16 bitstrings, and a code book. The message consists of three words. To discover the first word do the following: For example, supposing there were 41,382 length-16 bitstrings which are in G, you would discover the word "whale" (not surprising in this Moby Dick based text). To discover the second word use the same method, but start from the set H. Similarly, you discover the third word by applying the method to I. You should write down the cfgrep commands used, the number of matches found (use the -c flag), and the final discovered message.

    HINTS:

    SOLUTION

Last modified: Sun Nov 7 13:22:31 2004