Implement a recursive version of these algorithms

Assignment Help JAVA Programming
Reference no: EM131455221

Q1. We want to compare the naive and Karatsuba divide-and-conquer methods to multiply two integers x and y. Download the java file multiply.java from the course web page. Here, your task is to implement a recursive version of these algorithms in the methods naïve (int size, int x, int y) and karatsuba(int size, int x, int y), and to use them to compare the efficiency of each algorithm (i.e. number of arithmetic operations). The variable size is the size of the integers x and y, and is defined as the number of bits used to encode them (Note: we assume that x and y have the same size).

Each method (i.e. naive and karatsuba) will return an integer array result that stores the value of the multiplication in the first entry of the array (i.e. result[0]), and the cost of this computation in the second entry (i.e. result[1]). We define the cost as the number of brute force arithmetic operations of the (addition, subtraction, or multiplication) executed by the algorithm multiplied by the size (in bits) of the integers involved in this operation (Note: We ignore the multiplication by powers of 2 which can be executed using a bit shift. Of course, this is a crude approximation).

In particular, for the base case (i.e. when the size of the integers is 1 bit), this cost will be 1 (brute force multiplication of two integers of size 1). In the induction case, the naive method executes 3 arithmetic operations of integer of size m (i.e. cost is 3 m), in addition of the number of operations executed by each recursive call to the function. By contrast, the Karatsuba algorithm requires 6 arithmetic operations of size m on the top of the cost of the recursion. The output of your program will print a list of numbers such that, the first number of each row is the size of the integers that have been multiplied, the second number is the cost of the naïve method, and the third number the cost of the Karatsuba method.

Q2. We remind the master method for determining the asymptotical behaviour of a recursive function.

Theorem 1 (Master method) Let a ≥ 1 and b ≥ 1 be two constants, and f(n) a function. ∀n ∈ N+ we define T(n) as:

T(n) = aT(n/b) + f(n), where n/b is interpreted as ⌊n/b⌋ or ⌈n/b⌉.

Then, we can find asymptotical bounds for T(n) such that:

1. If f(n) = O(nlog_b a-∈) with ∈ > 0, then T(n) = Θ(nlog_b a).

2. If f(n) = Θ(nlog_b a · logpn), then T(n) = Θ(nlog_b a logp+1n).

3. If f(n) = Ω(nlog_b a+) with ∈ > 0, and a · f(n/b) ≤ cf(n), ∀n > n0 with c < 1 and n0 > 0. Then T(n) = Θ(f(n)).

When possible, apply the master theorem to find the asymptotic behaviour of T(n) from the following recurrences. Show your work and justify your answer for each recurrence.

(a) T(n) = 25 · T(n/5) + n

(b) T(n) = 2 · T(n/3) + n ·  log(n)

(c) T(n) = T(3n/4) + 1

(d) T(n) = 7 · T(n/3) + n3

(e) T(n) = T(n/2) + n(2 - cos n)

Q3. Let TA and TB be two function returning the running time of algorithms A and B, defined by the recusions TA(n) = 7TA(n/2) + n2 and TB(n) = αTB(n/4) + n2. Find the largest integer value of α for which algorithm B is asymptotically faster than A.

Attachment:- Assignment Files.rar

Reference no: EM131455221

Questions Cloud

What does modeling mean to you : What does modeling mean to you? How would you model something from your life now that you know about technology models?
What is the new probability of finding oil : An oil company purchased an option on land in Alaska. Preliminary geologic studies assigned the following prior probabilities.
Evolution of the human resource department : To start off the class, we will discuss the evolution of the Human Resource Department from the Personnel Department of the 1950s to the Human Resource Manageme
What parts of the algorithms can be potentially parallelized : Describe what parts of the algorithms can be potentially parallelized. Describe in pseudo-code a potential parallel implementation for this algorithm.
Implement a recursive version of these algorithms : Comp 251 Assignment. Download the java file multiply.java from the course web page. Here, your task is to implement a recursive version of these algorithms
Provide a brief example of a grey hat hacker : Explain main differences between white hat and grey hat hackers. Provide an example of a grey hat hacker. Discuss any recent story concerning session hijacking.
What is the revised probability : ParFore created a website to market golf equipment and apparel. Management would like a certain offer to appear for female visitors.
Cognitive behavior theory : Choose a theory that you have studied in this course. Do not choose one of the three theories listed above - Compare your selected theory against the three theories listed above.
Explain why they are important in system development process : Explain why they are important in a system development process. State the advantages and disadvantages of the Waterfall approach.

Reviews

len1455221

4/8/2017 4:41:38 AM

The clarity and presentation of your answers is part of the grading. Be neat! Violation of all rules above may result in penalties or even absence of grading (Please, refer to the course webpage for a full description of the policy). The solution of programming questions must be written in java. Submit the Java source file only (i.e. .java). Your program should compile and execute of SOCS computers in a terminal. Java files that do not compile or execute properly on SOCS computer will not be graded.

len1455221

4/8/2017 4:41:33 AM

Your solution must be returned electronically on MyCourse. Written answers and programming questions must be returned in separate submission folders on MyCourse. The only format accepted for written answers are PDF or text files (e.g. .txt or .rtf). PDF files must open on SOCS computers. Any additional files (e.g. images) must be included in the PDF. Do not submit a compressed files (e.g. zip files). Upload instead each PDF or text file individually.

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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