Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92263961
  • Price:- $60

Guranteed 36 Hours Delivery, In Price:- $60

Have any Question?


Related Questions in Java

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As