Question

6. [8 marks Consider the sequence 10, 11, ... defined by To = 0, 11 = 1, and ri = i-1 + 24-2 for all i > 2. Consider the foll

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Loop invariaat - a afli-2) and b zf(i-1) the clearly holds just before the cloup The doy sets a=b zf (i-1), brath 2f (1-2) +

Add a comment
Know the answer?
Add Answer to:
6. [8 marks Consider the sequence 10, 11, ... defined by To = 0, 11 =...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0...

    Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0 and an array A[0..(n - 1)] of n integers. Output: The smallest index s such that A[s] is the largest value in A[0..(n - 1)]. For example, if n = 9 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 1, since the largest value in...

  • 6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2)...

    6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the values stored in the variables v1 and v2. Note that % is the modulus operation, and will return the integer remainder r of a/b, i.e., r-a%b Require: Array P with n > 0 values 1: i-1, j-n-l 2: while i<=j do for a=i to j by i do 4: 5: 6: 7: if Pla>Pat 11 and Pla]%2--0 then swap(Plal, Pla+1l) end...

  • To prove the correctness of the following: # pre: int >= 1 fac = 1 i...

    To prove the correctness of the following: # pre: int >= 1 fac = 1 i = n while i>0:      fac = fac*i      i = i-1 # post: fac = n! which loop invariant do we need? (Hint, you will need two statements that are both true. One about fac and one about i) Please provide both full statements as well as which loop invariant is needed in a full proof. 2. To prove correctness of the following:...

  • (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is...

    (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is an earray A. You must assume that indexing begins at 1. 1: for j = 2: A.length do key = A i=j-1 while i > 0 and A[i] > key do Ali + 1] = Ai i=i-1 7: A[i+1] = key (a) Follow this algorithm for A[1..4) =< 7,9,6,8 >. Specifically, please indicate the contents of the array after each iteration of the outer...

  • Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x...

    Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x is an element from the set {n EN|2sn s50). What is the worst-case number of comparisons that this algorithm will perform? O O O O O O

  • Solve and show work for problem 8 Problem 8. Consider the sequence defined by ao =...

    Solve and show work for problem 8 Problem 8. Consider the sequence defined by ao = 1, ai-3, and a',--2an-i-an-2 for n Use the generating function for this sequence to find an explicit (closed) formula for a 2. Problem 1. Let n 2 k. Prove that there are ktS(n, k) surjective functions (n]lk Problem 2. Let n 2 3. Find and prove an explicit formula for the Stirling numbers of the second kind S(n, n-2). Problem 3. Let n 2...

  • Consider the sequence defined by o = 0 and 2 = 2 +(-1)"' i l for...

    Consider the sequence defined by o = 0 and 2 = 2 +(-1)"' i l for n EN Find an expression for in standard form, then prove that your formula is correct for all integers n > 0.

  • Loop Invariants. I need help on the 15 point question. The 10 point question is the...

    Loop Invariants. I need help on the 15 point question. The 10 point question is the "procedure" from the previous question. 2: (10 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is an array A. You must assume that indexing begins at 1. 1: for j = 2: A.length do key = A[j] i=j-1 while i > 0) and A[i] > key do A[i+1] = A[i] i=i-1 A[i+1] = key 3: 4: 5: 6:...

  • Consider the following algorithm Poly(A,a) --------------- 1. n = degree of polynomial (with coef A[n],..,A[0]) 2....

    Consider the following algorithm Poly(A,a) --------------- 1. n = degree of polynomial (with coef A[n],..,A[0]) 2. sum = 0 3. for i = n downto 0 4. sum = sum * a +A[i] show all steps!! (a) Determine the running time of the algorithm, your work should explain your answer (b) what is the loop invariant property of the loop in line 3.

  • Prove procedure to compute Fibinocci(n) where F0 = 0, F1 = 1, Fn = Fn-2 +...

    Prove procedure to compute Fibinocci(n) where F0 = 0, F1 = 1, Fn = Fn-2 + Fn-1. Prove by establishing and proving loop invariant then using induction to prove soundness and termination. 1: Procedure Fib(n) 2: i←0,j←1,k←1,m←n 3: while m ≥ 3 do 4:   m←m−3 5:   i←j+k 6:   j←i+k 7:   k←i+j 8: if m = 0 then 9: return i 10: else if m = 1 then 11: return j 12: else 13.   return k

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT