Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Part -1:

Using our rules for Hoare logic, prove the correctness of the following program that computes the integer nth power of integer x. Although you might want to figure out the proof using tree layout, give your solution in linear form similar to the proofs of division given in the textbook.

We give the initial assumption

{n ≥ 0}

and final goal

{ y = xn }

in the program below:

// Slow Exponentiation

{ n ≥ 0 }
y := 1
k := n

while (k > 0) do

y := y ×

k := k - 1

done
{ y = xn }

{y = xn }

Bonus points Why is this called slow exponentiation? To get one bonus point, give code that is exponentially faster in n, and to get the second bonus point, argue convincingly that your speedup is exponential.

Part -2:

Using our rules for Hoare logic, show the correctness of the following program that computes the index of the largest element in an array of integers, A; again present your proof in linear form. Assume that arrays are indexed from 1 to n and n > 0, as in the first tutorial.

// Find Maximum
{ length(A) = n ∧ n > 0 }

maxI .= 1

for j from 2 upto n do

if A [j ]>A [maxI ]

then maxI .= j

else skip

done

{ ∀j ∈[1,n] A[maxI] ≥ A[j] }

Programming Part - 1

P1 Alice believes that the following Java function correctly copies a range of elements in an array to a new location (overwriting what is there).

static void rangeCopy (int A [],
int from , int endWith , int to ) {
for (; from <=endWith ; from +=1, to +=1) {
A [to ] = A [from ];
}
}
So, if
A = [ 0, 1, 2, 3, 4]
initially, then rangeCopy (A, 0, 1, 3) would change A to become
A = [ 0, 1, 2, 0, 1]
This is useful in many places: from copying ranges of cells in Excel to the
memcpy(1) system-library function.

Although the function works for the above example, there are a number of situations where it will do the wrong thing. Identify as many distinct ones of these that you can, explaining the problem and giving a counter-example where the function does the wrong thing. One important case will require you to reason about some kind of separation property. Finally, give a correct Java function, embedded in a class that tests for the various problematic cases you've identified.

Java, Programming

  • Category:- Java
  • Reference No.:- M92664654
  • Price:- $65

Guranteed 36 Hours Delivery, In Price:- $65

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 ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

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 ...

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 ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

  • 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