Cpsc 327 homework write a recursive java function void max


Homework

1. In class, we looked at Karatsuba's algorithm for fast multiplication of large integers. Java's BigInteger class can multiply very large integers. Does it use the standard \grade-school" algorithm, Karatsuba's algorithm, or maybe something else.

Your Assignment: Analyze this data and say what you can about the algorithm used by multiplication in BigInteger. Is it likely to be the grade-school algorithm? Karatsuba's algorithm? Something else? Can you tell? Explain your reasoning carefully! If you would like to experiment further, you can find a copy of the program in /classes/cs327. (Hint: Consider the ratio T(10 * n)/T(n).)

Q2. a) Write a recursive Java function, void max( int[] A, int lo, int hi ), that finds the maximum value among the array elements A[lo], A[lo+1], . . . , A[hi], using the tournament method. (That is, find the maximums in two halves of the array and then compare them.)

b) This function can be used to find the max of an N-element array by calling max(A,0,N-1). Write a recurrence relation for the run time, T(N), of the function.

c) Use the Master Theorem to find T(N). (Explain your reasoning. You shouldn't be surprised by the answer!)

3. Suppose that a recursive algorithm divides a problem of size n into 4 problems of size n=2. The amount of extra work that is done to split the problem into parts and to combine the results from processing the parts is Θ (n2). Write a recurrence relation for the run time of the algorithm and use the Master Theorem to find the run time. How does the answer change if the extra work has run time Θ(n3/2)?

4. This is a small programming assignment using Java's HashSet data type. You might already have done something similar in CPSC 225. You can work on this assignment with a partner if you want; if you do, be sure to list both names in the file. Your program for this assignment must be named Books.java. You can submit your program to any location inside your homework folder in /classes/cs327/homework. My script will look for files named Books.java in that directory. My version of the program is 42 lines long, without comments. You do not need to include comments in this program.

The program will read words from two text files. (You can ask the user for the file names, or you can get the file names from command line arguments, but please do not hard code them into the file!) Read the words from one file, convert them to lower case, and put them into a HashSet. Read the words from the other file into another HashSet. A word is defined to be a sequence of ASCII letters, possibly with embedded apostrophes as in the words o'clock and shouldn't've. You can read words easily using a Scanner, provided you change the delimiter that is used by the Scanner to separate tokens. Here is a command that you can use to set a Scanner, scanr, to read words from the file and discard everything else:

scanr.useDelimiter("('*[^a-zA-Z']'*|''+|^'|'$)+");

(It took me significantly longer to write and debug the regular expression in this command than it did to write the rest of the program. You can copy-and-paste it from the PDF of this assignment on line.)

Now that you have the two hashsets, your goal is to answer the following questions: How many unique words were found in each file? How many words were present in the first file that were not in the second file? How many words were present in the second file that were not in the first file? Putting all the words from the two files together, how many unique words were there in both files combined? (You can answer all of these questions using the HashSet API, without writing any loops.)

To make things a little more interesting, you might want to try your program on some of the files in /classes/cs327/books, which contain the full text of several classic (out-of-copyright) books. For example, here is the output from my program when it compared Jane Austin's Pride and Prejudice to Mark Twain's Huckleberry Finn:

File 'books/austin.txt' contains 6346 unique words.

File 'books/twain.txt' contains 6089 unique words.

'books/austin.txt' contains 4213 words that are not in 'books/twain.txt'.

'books/twain.txt' contains 3956 words that are not in 'books/austin.txt'.

Together, 'books/austin.txt' and 'books/twain.txt'

contain a total of 10302 different words.

Attachment:- Assignment Files.rar

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Cpsc 327 homework write a recursive java function void max
Reference No:- TGS02664306

Expected delivery within 24 Hours