Use the construction in the proof of Theorem 1.49 to give the state diagrams of NFAs recognizing the star of the languages described in a. Exercise 1.6b. b. Exercise 1.6j. c. Exercise 1.6m. Exercise...
This exercise concerns TM M 2 , whose description and state diagram appear in Example 3.7. In each of the parts, give the sequence of configurations that M 2 enters when started on the indicated...
Read the informal definition of the finite state transducer given in Exercise 1.24. Give a formal definition of this model, following the pattern in Definition 1.5. Assume that an FST has an input...
Show that EQ CFG is undecidable.
Read the informal definition of the finite state transducer given in Exercise 1.24. Give the state diagram of an FST with the following behavior. Its input and output alphabets are {0,1}. Its output...
In Theorem 3.21, we showed that a language is Turing-recognizable iff some enumerator enumerates it. Why didnt we use the following simpler algorithm for the forward direction of the proof? As...
Prove that there exists an undecidable subset of {1} * .
Show that P is closed under union, concatenation, and complement.
Show that NP is closed under union and concatenation.
Show that ALL DFA is in P.
Jacob Weinstein wants a program that displays his savings account balance at the end of the month, given the beginning balance, total deposits, and total withdrawals. a. Using the chart shown earlier...
Create a program that allows the user to enter the ages (in years) of five people. The program should display the average age. Use the for statement. Display the average age with one decimal place....
Karlton Learning wants a program that displays the amount of money a company owes for a seminar. The fee per person is based on the number of people the company registers, as shown in Figure 6-42....
Rewrite the code from Pencil and Paper Exercise 4 using the do while statement in the outer loop and the while statement in the nested loop.
Rewrite the code from Pencil and Paper Exercise 2 using the replace function.
In this exercise, you will modify the tip program shown earlier in Figure 7-31. Follow the instructions for starting C++ and viewing the ModifyThis16.cpp file, which is contained in either the...
What is the output of the following code? b = 1; while(b < 4) { System.out.print(b + " "); b = b + 1; } a. 1 b. 1 2 3 c. 1 2 3 4 d. 1 1 1 1 1...
What does the following statement output? for(a = 0; a < 5; ++a) System.out.print(a + " "); a. 0 0 0 0 0 b. 0 1 2 3 4 c. 0 1 2 3 4 5 d. Nothing
What does the following statement output? for(b = 1; b > 3; ++b) System.out.print(b + " "); a. 1 1 1 b. 1 2 3 c. 1 2 3 4 d. Nothing
Create a JFrame that holds five buttons with the names of five different fonts. Include a sixth button that the user can click to make a font larger or smaller. Display a demonstration JLabel using...
a. Create aMine Field game in which the user attempts to click 10 panels of a grid before hitting the bomb. Set up a JFrame using BorderLayout, use the NORTH region for a congratulatory message, and...
Which of the following is true in a standard menu application? a. A JMenuItem holds a JMenu. b. A JMenuItem holds a JMenuBar. c. A JMenuBar holds a JMenu. d. A JMenu holds a JMenuBar
You developed an interactive GUI application for Carlys Catering. Now, design a JPanel that uses graphics to display a logo for the company, and modify the GUI application to include it. Save the...
Write an application that extends JPanel and uses the Graphics2D environment to create a GeneralPath object. Use the GeneralPath object to create the outline of your favorite state. Display the...
Suppose that you have created a program with only the following variables. int a = 5; int b = 6; Suppose that you also have a method with the following header: public static void mathMethod(int a)...
This project is a continuation of the previous project. For a quadratic expression such as ax 2 + bx + c, a real root is any double number x such that ax 2 + bx + c = 0. For example, the quadratic...
Implement the previous project with the following modification: All of the input numbers to the Statistician are required to be integers in the range from 0 to 100. This modification means that its...
Specify, design, and implement a class that can be used to simulate a lunar lander, which is a small spaceship that transports astronauts from lunar orbit to the surface of the moon. When a lunar...
Revise the Statistician with median (Programming Project 15 on page 172) so that it stores the input numbers on a doubly linked list using the doubly linked node class from the previous project....
Add a new method to the random number class of the previous project. The new method generates the next pseudorandom number but does not return the number directly. Instead, the method returns this...
Reimplement the bag class from Figure 4.17 so that the items of the bag are stored with a new technique. Heres the idea: Each node of the noefw linked list contains two integers. The first integer is...
What is meant by the term prompt?
This project is a continuation of the previous project. Many applications require pseudorandom number sequences that are not uniformly distributed. For example, a program that simulates the birth of...
Write a program that evaluates an arithmetic expression in infix notation, without full parentheses. Use the following algorithm: There are two stacks: a numbers stack and an operators stack. When a...
Which operator do you use to read into a variable?
This project requires a little understanding of velocity and gravity, but dont let that scare you away! Its actually an easy project. The assignment is to write a class in which each object...
Suppose that you want to implement a bag class to hold non-negative integers, and you know that the biggest number in the bag will never be more than a few thousand. One approach for implementing...
In this project, you will design and implement a class called Towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection...
What terminates input into an integer?
Write a program that converts spelled-out numbers such as zero and two into digits, such as 0 and 2. When the user inputs a number, the program should print out the corresponding digit. Do it for the...
Another way to store a collection of items is called a keyed bag. In this type of bag, whenever an item is added, the programmer using the bag also provides an integer called the key. Each item added...
Give five examples of legal names that you shouldnt use because they are likely to cause confusion.
Define a rule to help decide if a conversion from one type to another is safe or unsafe.
In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise, you will write a similar program to evaluate boolean expressions. Rather than arithmetic...
Do exercise 6, but with three string values. So, if the user enters the values Steinbeck, Hemingway, Fitzgerald, the output should be Fitzgerald, Hemingway, Steinbeck.
Build a regular expression that captures all nonempty sequences of letters other than file, for, and from. For notational convenience, you may assume the existence of a not operator that takes a set...
Write regular expressions to capture the following. (a) Strings in C. These are delimited by double quotes ("), and may not contain newline characters. They may contain double-quote or backslash...
Give a grammar that captures all levels of precedence for arithmetic expressions in C.
Write top-down and bottom-up grammars for the language consisting of all well-formed regular expressions. Arrange for all operators to be left associative. Give Kleene closure the highest precedence...
(a) Show the NFA that results from applying the construction of Figure 2.7 to the regular expression letter ( letter | digit )*. (b) Apply the transformation illustrated to create an equivalent DFA....
Build a nested-case-statements finite automaton that converts all letters in its input to lower case, except within Pascal-style comments and strings. A Pascal comment is delimited by { and }, or by...
Suppose that the expression grammar in Example 2.8 were to be used in conjunction with a scanner that did not remove comments from the input, but rather returned them as tokens. How would the grammar...
Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples: abs := n if n < 0 then abs := 0 - abs fi sum := 0 read count while...
Give three concrete examples drawn from programming languages with which you are familiar in which a variable is live but not in scope.
The dangling else problem of Pascal was not shared by its predecessor Algol 60. To avoid ambiguity regarding which then is matched by an else, Al-gol 60 prohibited if statements immediately inside a...
Consider the design of a Fortran 77 compiler that uses static allocation for the local variables of subroutines. Expanding on the solution to the previous question, describe an algorithm to minimize...
Write a simple program in Scheme that displays three different behaviors, depending on whether we use let, let*, or letrec to declare a given set of names.
Give two examples of reasonable semantic rules that cannot be checked at reasonable cost, either statically or by compiler-generated code at run time.
As part of the development team at MumbleTech.com, Janet has written a list manipulation library for C that contains, among other things, the code in Figure 3.16. (a) Accustomed to Java, new team...
One potential criticism of the obvious solution to the previous problem is that the values in internal nodes of the parse tree do not reflect the value, in context, of the fringe below them. Create...
Consider the following program in Scheme: What does this programprint? What would it print if Scheme used dynamic scoping and shallow binding? Dynamic scoping and deep binding? Explain your answers....
As noted, C# has unusually sophisticated support for firstclass subroutines. Among other things, it allows delegates to be instantiated from anonymous nested methods, and gives local variables and...
A CFG-based attribute evaluator capable of handling non-L-attributed attribute flow needs to take a parse tree as input. Explain how to build a parse tree automatically during a top-down or bottom-up...
For certain values of x, (0.1 + x) * 10.0 and 1.0 + (x * 10.0) can differ by as much as 25%, even when 0.1 and x are of the same magnitude. Verify this claim. (Warning: If youre using an x86...
Languages that employ a reference model of variables also tend to employ automatic garbage collection. Is this more than a coincidence? Explain.
In Section 6.1.2 (Orthogonality), we noted that C uses = for assignment and == for equality testing. The language designers state: Since assignment is about twice as frequent as equality testing in...
Suppose that we want to translate constant expressions into the postfix, or reverse Polish notation of logician Jan ukasiewicz. Postfix notation does not require parentheses. It appears in...
Repeat the previous exercise using the underlying CFG of Figure 4.3. Figure 4.3 1. T TT.st := T.val E.val := TT.val 2. Ti + T T. + T TT2 TT2.st := TT1.st + T.val TT1.val := TT2.val %3D 3. TTi - ...
Consider the following expression in C: a/b > 0 && b/a > 0. What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to...
As noted in Section 6.4.2, languages vary in how they handle the situation in which the controlling expression in a case statement does not appear among the labels on the arms. C and Fortran 90 say...
As noted in Figure 6.1, Fortran and Pascal give unary and binary minus the same level of precedence. Is this likely to lead to nonintuitive evaluations of certain expressions? Why or why not? Figure...
In Example 6.9 we described a common error in Pascal programs caused by the fact that and and or have precedence comparable to that of the arithmetic operators. Show how a similar problem can arise...
In Lisp, most of the arithmetic operators are defined to take two or more arguments, rather than strictly two. Thus (* 2 3 4 5) evaluates to 120, and (- 16 9 4) evaluates to 3. Show that parentheses...
Consider a language implementation in which we wish to catch every use of an uninitialized variable. In Section 6.1.3 we noted that for types in which every possible bit pattern represents a valid...
In Section 7.2.2 we introduced the notion of a universal reference type (void * in C) that refers to an object of unknown type. Using such references, implement a poor mans generic queue in C, as...
Write an attribute grammar, based on the following context-free grammar, that accumulates jump code for Boolean expressions (with short-circuiting) into a synthesized attribute code of condition, and...
(Difficult) Use call-with-current-continuation (call/cc) to implement the following structured nonlocal control transfers in Scheme. (This requires knowledge of material in Chapter 11.) You will...
Suppose you are implementing an Ada compiler, and must support arithmetic on 32-bit fixed-point binary numbers with a programmer-specified number of fractional bits. Describe the code you would need...
When Sun Microsystems ported Berkeley Unix from the Digital VAX to the Motorola 680x0 in the early 1980s,many C programs stopped working, and had to be repaired. In effect, the 680x0 revealed certain...
Discuss the relative merits of classes and type extensions. Which do you prefer? Why?
Rewrite the code of Figure 7.3 in Ada, Java, or C#. Figure 7.3: template class queue { item items [max_items]; int next_free, next_full, num_items; public: queue () : next_free (0), next_full(0),...
Figure 7.3 passes integer max_items to the queue abstraction as a generic parameter. Write an alternative version of the code that makes max_items a parameter to the queue constructor instead. What...
In the spirit of Example 10.8, write a double-ended queue (deque) abstraction (pronounced deck), derived from a doubly linked list base class.
Using the C# indexer mechanism, create a hash table class that can be indexed like an array. (In effect, create a simple version of the System.Collections.Hashtable container class.) Alternatively,...
Explain the meaning of the following C declarations: double *a[n]; double (*b)[n]; double (*c[n])(); double (*d())[n];
In Section 9.3.1 we noted that Ada 83 does not permit subroutines to be passed as parameters, but that some of the same effect can be achieved with generics. Suppose we want to apply a function to...
In Section 8.2.3 we discussed how to differentiate between the constant and variable portions of an array reference, in order to efficiently access the subparts of array and record objects. An...
Write an LL(1) parser generator in purely functional Scheme. If you consult Figure 2.24, remember that you will need to use tail recursion in place of iteration. Assume that the input CFG consists of...
Explain how to obtain the effect of Fortran 90s allocate statement for one-dimensional arrays using pointers in C. You will probably find that your solution does not generalize to multidimensional...
Pointers and recursive type definitions complicate the algorithm for determining structural equivalence of types. Consider, for example, the following definitions: type A = record x : pointer to B y...
Suppose A is a 1010 array of (4-byte) integers, indexed from [0][0] through [9][9]. Suppose further that the address of A is currently in register r1, the value of integer i is currently in register...
Suppose we are compiling for a machine with 1-byte characters, 2-byte shorts, 4-byte integers, and 8-byte reals, and with alignment rules that require the address of every primitive data element to...
Write the equivalent of Figure 6.5 in C# or Ruby. Write a second version that performs an in-order enumeration, rather than preorder. Figure 6.5: class BinTree: def -_init_ (self): # constructor...
Modify the solution to the postfix expression evaluation problem so that it checks for the validity of the expression that is entered by the user. Issue an appropriate error message when an erroneous...
Write an algorithm for the add method that will add at the end of the list instead of at the beginning. What is the time complexity of this algorithm?
Modify the maze problem in this chapter so that it can start from a user defined starting position (other than 0, 0) and search for a user-defined ending point (other than row-1, column-1).
In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozit followed by one or more Whatzits. A Whoozit is the character x followed by zero or more ys. A Whatzit is a q...
Write a recursive method that returns the value of N! (N factorial) using the definition given in this chapter. Explain why you would not normally use recursion to solve this problem.
What is the time complexity of a radix sort?
Calculate the time complexity of the find method.