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
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:
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:...
i need this question answered ASAP. thanks. Suppose a student diluted and titrated a bleach unknown...
i need this question answered ASAP. thanks. Suppose a student diluted and titrated a bleach unknown exactly as described in the experimental procedure, except only a single titration was performed which required 15.06 mL of 0.100 M Na2S2O3. 1. Calculate the number of moles of Na2S2O3 used in the titration. 2. Calculate the number of moles of ClO- in the sample titrated. Hint for proper stoichiometry: 1) Clo-+2I-+2H+------> I2+Cl-+H2O 2) I2+2S2O2-3--------> 2I-+S4O2-6 3. Calculate the grams of NaClO in the...
NOTE: I just need the answer for question 5 and 6. I already knew the question...
NOTE: I just need the answer for question 5 and 6. I already knew the question 1-4, and wrote down all the requirements for clarification. In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash script has to accept at least four input arguments, and must: 1) Print to the user a set of instructions explaining how the PATH variable can be used in Bash. 2) Save the manual of the 'awk' command in...
Write a MASM program that computes the sum of the integers from 1 to N where...
Write a MASM program that computes the sum of the integers from 1 to N where N is a positive integer. Use the equal sign directive to define N. Save the sum in the EAX register. You must use loops. For example, 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 Language ( Assembly)...
I need answer to question 5-6 only. You are a nurse practitioner working in an ambulatory...
I need answer to question 5-6 only. You are a nurse practitioner working in an ambulatory clinic in Illinois with a case load of 350 patients. You notice that a large proportion (179 patients) have COPD, and you wonder if it is related to smoking. You create the following 2 x 2 table to explore the relationship between smoking and COPD : With COPD Without COPD total Smokers 82 97 179 Non-Smokers 18 153 171 100 250 350 1. What...