Question

*********I need question 6 answered which is from question 5 which is ********* Question 5 :...

*********I need question 6 answered which is from question 5 which is *********

Question 5 : Program Correctness I (1 point)

Use the loop invariant (I) to show that the code below correctly computes

n P−1 k=0 2k

(this sum represents the sum of the first n even integers where n ≥ 1).

Algorithm 1 evenSum(int n)

1: p = 2(n − 1)

2: i = n − 1

3: while i > 0 do

4: //(I) p = nP−1 k=i 2k

5: i − −

6: p = p + 2i

7: end while

8: return p

Prove the Base case of the loop invariant (I):

Question 6 : Program Correctness II (4 point )

(a) Inductive step:

i. (1 point) What is your inductive hypothesis?

ii. (1 point) What are you trying to prove?

iii. (1 point) Complete the proof:

(b) Termination step:

i. (1/2 point) What is the value of i when the loop terminates? i =____________

ii. (1/2 point) Plug your answer from the previous question into (I) to show the loop is correct:

Homework Answers

Answer #1

PLEASE LIKE THE SOLUTION

FEEL FREE TO DISCUSS IN COMMENT SECTION

SOLUTION

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing...
For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing correctness for the main loop in each of the following programs and briefly argue initialization, preservation, and termination. EXAMPLE PROBLEM: //Function to return the max of an array A Maximum(array of integers A) Local integer integer m m=0 for i = 1 to n if A[i] > m then m = A[i] end function Maximum EXAMPLE SOLUTION: The loop invariant is m = max(0,...
Find the exact number of times (in terms of n) the innermost statement (X = X...
Find the exact number of times (in terms of n) the innermost statement (X = X + 1) is executed in the following code. That is, find the final value of X. Then express the total running time in terms of O( ), Ω( ), or Θ( ) as appropriate. X = 0; for k = 1 to n     for j = 1 to n – k         X = X + 1; The following program computes and returns...
Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2...
Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2 Use n as input and test the function for n=100. Question #15. Write a function file that determines the following sum using a for loop: y=i=1n(3-2i)2 Use n as input and test the function for n=100.
Let a0 = 1, a1 = 2, a2 = 4, and an = an-1 + an-3...
Let a0 = 1, a1 = 2, a2 = 4, and an = an-1 + an-3 for n>= 3. Let P(n) denote an an <= 2^n. Prove that P(n) for n>= 0 using strong induction: (a) (1 point) Show that P(0), P(1), and P(2) are true, which completes the base case. (b) Inductive Step: i. (1 point) What is your inductive hypothesis? ii. (1 point) What are you trying to prove? iii. (2 points) Complete the proof:
Let a0 = 1, a1 = 2, a2 = 4, and an = an-1 + an-3...
Let a0 = 1, a1 = 2, a2 = 4, and an = an-1 + an-3 for n>= 3. Let P(n) denote an an <= 2^n. Prove that P(n) for n>= 0 using strong induction: (a) (1 point) Show that P(0), P(1), and P(2) are true, which completes the base case. (b) Inductive Step: i. (1 point) What is your inductive hypothesis? ii. (1 point) What are you trying to prove? iii. (2 points) Complete the proof:
Multiple Choice: The following function is intended to return the value of a[1] + a[2] +...
Multiple Choice: The following function is intended to return the value of a[1] + a[2] + … + a[n] for n ≥ 1. (The sum of the first n entries in an array of integers). Prove that the function is correct, or explain why it does not produce correct results. ArraySumA(integers n, a[1], a[2], … , a[n]) Local variables: integers i, j     i = 0     j = 0     while i ≤ n do         i = i +...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!! QUESTION 1 What is the output after the code executes? Assume there are no syntax errors and the code will compile. int x = 10; do { System.out.println ( x ); x -= 3; } while (x > 0); A. 10 7 4 1...
1. Prove that an integer a is divisible by 5 if and only if a2 is...
1. Prove that an integer a is divisible by 5 if and only if a2 is divisible by 5. 2. Deduce that 98765432 is not a perfect square. Hint: You can use any theorem/proposition or whatever was proved in class. 3. Prove that for all integers n,a,b and c, if n | (a−b) and n | (b−c) then n | (a−c). 4. Prove that for any two consecutive integers, n and n + 1 we have that gcd(n,n + 1)...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
Question: A 1.5kg crate falls from a height of 2m onto an industrial spring scale k=1.5×10^5...
Question: A 1.5kg crate falls from a height of 2m onto an industrial spring scale k=1.5×10^5 N/m. At its greatest compression, what is the reading on the scale? The answer for this question is 3000N. I have to use mgh =(1/2)kx^2 . I checked the solution and it is said that I have to plug in 2 for h. Can you explain why h=2+x is wrong?