Write a recursive java function

Assignment Help Computer Engineering
Reference no: EM131868809

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<String>. Read the words from the other file into another HashSet<String>. 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

Reference no: EM131868809

Questions Cloud

Calculate the exercise price of call option : You bought a call option with a strike price of $45 on Fox stocks that are currently selling at $55 a share. The call option is trading at $4.50.
Summary of the main points and details of the experiment : Review papers typically follow the following structure: Support from the article or your text for your agreement or disagreement with the authors' position.
Write a proposal with security options for the organization : You Have Been Selected To Provide Consulting Services To A Security Organization That Is Switching From A Full In-House Security Team.
Investors about investing in the stock : Suppose the market price of the stock is $30 (different from the price that CAPM says it should be), what would you tell the investors about investing
Write a recursive java function : CPSC 327, Homework. Write a recursive Java function, void max( int[] A, int lo, int hi ), that finds the maximum value among the array elements
How might sloan alleviate the patients fears : Discussion: Electronic Medical Records- How might Sloan alleviate the patients' fears about their records being available on the Internet to so many people?
Determining an interest rate : Identify and briefly discuss the different components, elements, and/or risk factors that are considered in determining an interest rate.
Important concept to understand in understanding of finance : The "Time Value of Money" is an important concept to understand in the understanding of finance, and its role in financial decision-making
Is the stock market efficient : Is the stock market efficient? Explain Why you hold this opinion. How does your position on the question of Market Efficiency impact

Reviews

len1868809

2/19/2018 2:07:05 AM

Problem 1-3 written with explanation. Problem 4 is a small java program. And do not do problem 5. 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.

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd