Top Selling Computer science Questions

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... In our open-address hash tables, we have used linear probing or double hashing. Another probing method, which avoids some clustering, is called quadratic probing. The simplest version of quadratic... (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... 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... If you are familiar with Javas Comparable interface (Programming Project 11), then rewrite one of the sorting methods so that it sorts an array of Comparable objects. You may choose selectionsort,... 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... The performance of the radix sort from the previous project can be improved by using more supplementary lists (rather than just list0 and list1). For example, you can have an array of 16 lists, which... 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... 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... 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... 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... 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... 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... Discuss the relative merits of classes and type extensions. Which do you prefer? Why? 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]; 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 - ... 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... Repeat Exercise 4.7 using ad hoc attribute space management. Instead of accumulating the translation into a data structure, write it to a file on the fly. Data From Exercise 4.7: Suppose that we want... One problem with automatic space management for attributes in a top-down parser occurs in lists and sequences. Consider for example the following grammar: block begin stmt list end stmt list stmt... 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... 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... 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... 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... 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... (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... 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 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... 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). 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... 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... 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... 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. 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... Write some Java statements that use the String methods indexOf and substring to find the first word in a string. We define word to be a string of characters that does not include whitespace. For... Consider the following fragment of code: if (x > 5) System.out.println("A"); else if (x < 10) System.out.println("B"); else System.out.println("C"); What is displayed if x is a. 4; b. 5; c. 6; d. 9;... What is the value of each of the following boolean expressions if x is 5,y is 10, and z is 15? a. (x < 5 && y > x) b. (x < 5 || y > x) c. (x > 3 || y < 10 && z == 15) d. (! (x > 3) && x!= z || x + y... There is a variation of the bubble sort algorithm called a gap sort that, rather than comparing neighboring elements each time through the list, compares elements that are i positions apart, where i... What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar? Listing 2.3 import java.util.Scanner; public class ChangeMaker { public... Every profession uses computers today. Use aWeb browser and a search engine like Google to find sites that relate your field of study with computer science or computing or computation. For example,... Write a program that reads a bank account balance and an interest rate and displays the value of the account in ten years. The output should show the value of the account for three different methods... Now trace this series of who built on whos work. Who invented the laser printer? One of the winners of the ACM Turing Award (the closest that computer science has to a Nobel Prize) invented a... You are running a bingo game where you want to tweet the winner of each round of the game.You want to announce the name of who won, and how much they won in dollars. Make a function that takes those... Create a function like the pyramid function that does the upside-down version. Your function invertedPyramid should also take an input character and print an inverted pyramid. You have written an essay for school, and it has to be at least five pages long. But your essay is only 4.5 pages long!You decide to use your new Python skills to make your essay longer by spacing... Write a function to blend two pictures, starting with the top third of the first picture and then blend the two together in the middle third and then show the last third of the second picture. This... One of the four functions below generated this picture. Which one is it? A. B. C. D. def flip1(picture): allpixels = getPixels(picture) In = len(allpixels)-1 address = In for index in range (0,1n/2):... One of the below programs that when called like this (with the underscore representing a digit from 1 to 4) generates this output: >>> mixem_("we hold these truths") 'w.e. .h.o.l.d. .t.h.ese truths'... Write a function to draw a simple face with eyes and a mouth. on a picture. Write a general crop function that takes a source picture, the start X value, the start Y value, the end X value, and the end Y value. Create and return the new picture and copy just the specified... Create a CartoonPanel class that takes an array of Pictures and displays the pictures from left to right. It should also have a title and author, and display the title at the top left edge and the... Write a program that produces the following figure (which vaguely resembles the Seattle Space Needle) as its output using nested for loops. Use a class constant to make it possible to change the size... Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows: :mmZ\dxZmx]Zpgy The message is... You have an augmented reality game in which you catch Edoc and acquire Edoc candy. You need 12 candies to evolve an Edoc into a Margorp. An evolution earns you back one candy. Each evolution also... Write a Java program called Lanterns that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. ** ***** **** ***** ********* ***** **... Write a recursive method that will count the number of vowels in a string. Each time you make a recursive call, use the String method substring to construct a new string consisting of the second... Write a JavaFx application that displays a series of pictures of a person with arms, legs, and of course a head. Use a happy face for the head. Use ovals for the body, arms, and legs. Draw a sequence... Write a grading program for an instructor whose course has the following policies: Two quizzes, each graded on the basis of 10 points, are given. One midterm exam and one final exam, each graded on... Create a class that represents a grade distribution for a given course. Write methods to perform the following tasks: Set the number of each of the letter grades A, B, C, D, and F. Read the number of... Write a program to answer questions like the following: Suppose the species Klingon ox has a population of 100 and a growth rate of 15 percent, and it lives in an area of 1500 square miles. How long... Write a new class TruncatedDollarFormat that is the same as the class DollarFormat from Listing 6.14, except that it truncates rather than rounds to obtain two digits after the decimal point. When... Write a program that plays a simplified dice version of blackjack. Instead of selecting from a deck of cards a 14-sided die is rolled to represent a card. The rules of the game for one round, as... Add a method bubbleSort to the class ArraySorter, as given in Listing 7.10, that performs a bubble sort of an array. The bubble sort algorithm examines all adjacent pairs of elements in the array... Add a method insertionSort to the class ArraySorter, as given in Listing 7.10, that performs an insertion sort of an array. To simplify this project, our insertion sort algorithm will use an... The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in the way described in the text. In particular, be sure to add a default constructor, as well as set... Write a program that shows the total number of presents that the person in the song The Twelve Days of Christmas received on each day, as indicated in Table 3.5. Table 3.5 Twelve Days of Christmas Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is... Write a piece of code that prints an array of integers in reverse order, in the same format as the print method from Section 7.2. Consider putting your code into a method called printBackwards that... Students are often asked to write term papers containing a certain number of words. Counting words in a long paper is a tedious task, but the computer can help. Write a program that counts the number... Write a constructor for the UndergraduateStudent class that accepts a name as a parameter and initializes the UnderGraduateStudent s state with that name, an age value of 18, and a year value of 0. Write a program that produces the following figure (which vaguely resembles a textbook) as its output using nested for loops. Use a class constant to make it possible to change the size of the figure... Write a program that produces as output the words of The Twelve Days of Christmas. (Static methods simplify this task.) Here are the first two verses and the last verse of the song: On the first day... Write a complete Java program called WellFormed that prints the following output: Why is recursion an effective way to implement a backtracking algorithm? Rewrite the list insertion method of Example C 16.40 in F# instead of C#. Compile to CIL and compare to the right side of Figure C 16.7. Discuss any differences you find. Figure 16.7 . method private... The grammar of Figure 15.6 assumes that all variables are global. In the presence of subroutines, we should need to generate different code (with fp-relative displacement mode addressing) to access... One problem (of many) with the code we generated in Section 15.3 is that it computes at run time the value of expressions that could have been computed at compile time. Modify the grammar of Figure... What characteristic does Ruby share with Smalltalk? The class StringLinkedListWithIterator (Listing 12.9) is its own iterator, but it does not quite implement the Java Iterator interface. Redefine the class StringLinkedListWithIterator so that it... Write some code that will use an iterator to duplicate every item in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains "a", "b", and "c", after the code... For this project, we will create a data structure known as a queue. A queue can be thought of as a line. Items are added at the end of the line and are taken from the front of the line. You will... Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algorithm has occurred (after each element is selected and moved into... Create an application that will keep track of several groups of strings. Each string will be a member of exactly one group. We would like to be able to see whether two strings are in the same group... Repeat the previous programming project, but read the input data from a file and send the output to another file. If you have covered binary files, use binary files; otherwise, use text files. Read...
Showing 4600 - 4700 of 5000