Algorithm M2

Ace your homework & exams now with Quizwiz!

5

Numerical Answer. Instructions are numbered starting from 1. There is a loop invariant code at Line __________. Answer -1 if there is no loop invariant code. 1. s = 6 2. x = 2.0 3. for (i=0; i <= n; i++) 4. b = 2 * (s + x) + b 5. s = x*x + 2 6. a = a + s << 2

two

Proof by mathematical induction consists of ________ step(s). three one basis two

3

Proving (establishing) a loop invariant requires ______ step/stage(s). 3 2 4 1 None of these answers

initialization

Proving a loop invariant consists of ____________, maintenance, and termination steps.

maintenance

Proving a loop invariant consists of initialization, _____________, and termination steps.

termination

Proving a loop invariant consists of initialization, maintenance, and _____________ steps.

a counterexample

Sara starts her proof with saying "try the value 5 with your code and check the output". Sara is likely trying to prove her point using .... a contradiction loop invariant a counterexample induction None of these answers

incorrect, {100, 34, 4, 1, 5}

Select the best answer for each dropdown menu. Consider this program that should return the largest value in Array A. maxval(A) { currmax = 255; for (i=0; i < A.length; i++) if (A(i) > currmax) currmax = A(i) //A(i) is the ith element in Array A return currmax } This program is [ correct, incorrect ]. A counterexample could be the array A={_______} .

incorrect, A={2000, -34, 4, 1, 5}

Select the best answer for each dropdown menu. Consider this program that should return the smallest value in Array A. minval(A) { currmin = 0; for (i=0; i < A.length; i++) if (A(i) < currmin) currmin = A(i) //A(i) is the ith element in Array A return currmin } This program is [correct or incorrect]. A counterexample could be the array ______.

false, humans, human, two

Select the best answer from each dropdown menu. Consider the statement "All animals have four legs". This statement is ["true", "false", "almost true"] : a counterexample is ["horses", "turtles", "None of these answers", "humans", "tree"] . A ["None of these answers", "horse", "turtle", "human"] is an animal, but it has ["three", "four", "None of these answers", "one", "two"] leg(s).

false, penguins, penguin, cannot

Select the best answer from each dropdown menu. Consider the statement "All birds can fly". This statement is ["true", "almost true", "false"] : a counterexample is ["pigeon", "eagle", "None of these answers", "penguins", "sparrow"] . A ["pigeon", "eagle", "None of these answers", "penguin", "sparrow"] is a bird, but it ["can", "None of these answers", "cannot", "would", "will"] fly.

n+3

Select the best answer. Bob wants to prove a property P for all integer numbers n that are multiple of 3 using mathematical induction. After checking the base case, he must assume P for n and then prove P for _________. None of these answers n + 3 n + 1 n + 2 n + 6

None of these answers - Induction holds for all natural numbers.

Select the best answer. Bob wants to prove a property P for all positive real numbers x (x >= 0) using mathematical induction. He should first show P for _____. 1.0 x = 0 -1.0 x+1 None of these answers

A and (n > 0)

Select the best answer. Suppose Kevin wants to prove A --> (n <= 0) using contradiction. He should start by assuming _____________. A and (n > 0) A and (n <= 0) not (A) and (n <= 0) A and (n >= 0) None of these answers

A and B

Select the best answer. Suppose Kevin wants to prove A --> not(B) using contradiction. He should start by assuming _____________. not (A) and B A and B not(A) and not(B) A and not(B) None of these answers

[] s = 2^i - 1 for all i >= 0 This is true starting from i = 0 because with i = 0 , s = 2^0 - 1 = 0. Before the first iteration, s= 0 (coming from the initialization)

Select the best answer. The objective is to prove that when this program ends, s = 2^(n+1)-1. Of all potential loop invariants in this question, check the best loop invariant before each iteration for the code below. s = 0 for (i=0; i <= n; i++) s = s + 2^i [] s = 2^(i+1) -1 for all i > 0 [] s = 2^(i-1) for all i > 0 [] None of these answers [] s = 2^i - 1 for all i >= 0 [] s < 2^i for all i > 0

s = (i-1)i/2 for all i >=1

Select the best answer. The objective is to prove that when this program ends, s = n(n+1)/2. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. s = 0 for (i=1; i <= n; i++) s = s + i [] s <= n [] s =i(i+1)/2 for all i >=1 [] None of these answers [] s = (i-1)i/2 for all i >=1 [] i <= n [] i >=1

T[k] = 0 for 0 <= k <= (j-1) with j > 0

Select the best answer. The objective is to prove that when this program ends, we will have T[i] = 0 for all i from 0 to 7. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. a = 16 for (j=0; j < 8; j++) T[j] = 0 [] T[k] = 0 for 0 <= k <= (j-1) with j > 0 [] None of these answers [] j <= 8 [] a > 16 [] T[k] = 0 for 0 <= k <= (j-1) with j >= 0 [] a == 16

T[k] = 16 for 0 <= k <= (j-1) with j >= 1

Select the best answer. The objective is to prove that when this program ends, we will have T[i] = 16 for all i from 0 to 7. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. a = 16 for (j=0; j < 8; j++) T[j] = a + j a = a - 1 [] T[k] = 0 for 0 <= k <= (j-1) with j > 1 [] T[k] = 16 for 0 <= k <= (j-1) with j >= 1 [] j <= 8 [] a > 16 [] T[k] = 16 for 0 <= k <= (j-1) with j >= 0

T[k] = 16 for 0 <= k <= (j-1) with j > 1

Select the best answer. The objective is to prove that when this program ends, we will have T[i] = 16 for all i from 0 to 7. Check the best loop invariant before each iteration to use in order to achieve my objective. a = 16 for (j=0; j < 8; j++) T[j] = a + j a = a - 1 [] T[k] = 16 for 0 <= k <= (j-1) with j > 1 [] T[k] = 16 for 0 <= k <= (j-1) with j >= 0 [] j < 8 [] None of these answers [] a > 16 [] T[k] = 0 for 0 <= k <= (j-1) with j > 1

A and (n is even)

Suppose Kevin wants to prove A --> (n is odd) using contradiction. He should start by assuming _____________. None of these answers not (A) and (n is odd) A and (n is even) not(A) and (n is even) A and (n is odd)

A and not(B)

Suppose Kevin wants to prove A --> B using contradiction. He should start by assuming _____________. not(A) and not(B) None of these answers A and not(B) A and B not (A) and B

[] i <= A.length [] m >= A[k] for all k such that 1 <= k <= (i-1) [] i >=2 [] m >= A[1]

The objective is to prove that when this program ends, m will be the largest value in Array A. Check all loop invariants for the code below before the iteration. m = A[1] for (i=2; i <= A.length; i++) if (m < A[i]) m = A[i] [] i <= A.length [] m >= A[k] for all k such that 1 <= k <= (i-1) [] i >=2 [] m >= A[k] for all k such that 1 <= k <= i [] m >= A[1]

[] i >=2 [] m <= A[1] [] i <= A.length [] m <= A[k] for all k such that 1 <= k <= (i-1)

The objective is to prove that when this program ends, m will be the smallest value in Array A. Check all loop invariants for the code below before the iteration. m = A[1] for (i=2; i <= A.length; i++) if (m > A[i]) m = A[i] [] i >=2 [] m <= A[k] for all k such that 1 <= k <= i [] m <= A[1] [] i <= A.length [] m <= A[k] for all k such that 1 <= k <= (i-1)

m <= A[k] for all k such that 1 <= k <= (i-1)

The objective is to prove that when this program ends, m will be the smallest value in Array A. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. m = A[1] for (i=2; i <= A.length; i++) if (m > A[i]) m = A[i] [] m <= A[1] [] m <= A[k] for all k such that 1 <= k <= (i-1) [] m <= A[k] for all k such that 1 <= k <= i [] i >=2 [] i <= A.length

s = i -1 for all i > 0

The objective is to prove that when this program ends, s = n. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. s = 0 for (i=1; i <= n; i++) s = s + 1 [] s = i -1 for all i > 0 [] i <= n for all i > 0 [] s <= n for all i > 0 [] None of these answers [] s > i for all i > 0 [] s <= i - 1 for all i > 0

x + y = a

The objective is to prove that when this program ends, x + y = a. Of all potential loop invariants in this question, check the best loop invariant before each iteration to use in order to achieve my objective. x = a y = 0 while (x > 0) x-- y++ [] x + y <= a [] y <= a [] x + y = a [] a <= x + y [] x <= a

0

We want to prove S= n ∑ i=0 i. =. n(n+1)/2 For the base case, the value of S is ________. 2 n(n+1)/2 None of these answers 0 1

counterexample, contradicts

A _____ is an example that opposes or ______ an idea or a theory.

[] a (true) logical assertion about variables related to the loop [] a true boolean statement about variables related to a loop [] property that variables related to a loop satisfy

A loop invariant property is ________________. [] a (true) logical assertion about variables related to the loop [] a true boolean statement about variables related to a loop [] property that variables related to a loop satisfy [] A set a variables that do not change throughout a loop [] A set of statements in the loop that are always executed

n + 2

Bob wants to prove a property P for all even integer numbers n using mathematical induction. After checking the base case, he must assume P for n and then prove P for _________. n n + 2 None of these answers n + 4 n + 1

n + 1

Bob wants to prove a property P for all integer numbers n (n >= 1) using mathematical induction. After checking the base case, he must assume P for n and then prove P for _________. n n-1 None of these answers n + 1 1

x = 2

Bob wants to prove a property P for all integer numbers x (x > 1) using mathematical induction. He should first show P for _____. None of these answers x = 0 x = 2 x = -1 x = 1

x = 0

Bob wants to prove a property P for all integer numbers x (x >= 0) using mathematical induction. He should first show P for _____. None of these answers x = 0 x = -1 x = 1 x + 1

x = 1

Bob wants to prove a property P for all integer numbers x (x >= 1) using mathematical induction. He should first show P for _____. x = 2 x = -1 x = 1 None of these answers x = 0

n = 1

Bob wants to prove a property P for all odd positive integer numbers n using mathematical induction. His base case must be. n = 1 n = 2 n = 0 None of these answers n = 3

[] j + a = 13 [] a >= 5 [] j <= 7

Check all loop invariants before the iteration for the loop in the program below: a = 13 for (j=0; j < 8; j++) a = a - 1 [] j + a = 13 [] j + a = 8 [] a >= 5 [] a > 6 [] j <= 7

[] i <= n [] s = i (i+1)/2 [] i >=1

Check all loop invariants for the code below after each iteration. s = 0 for (i=1; i <= n; i++) s = s + i [] i <= n [] s <= n [] s = i (i+1)/2 [] i >= 1 [] s <= i

[] T[k] = 0 for 0 <= k <= (j-1) with j > 0 [] j <= 8 [] a = 16

Check all loop invariants for the loop in the program below: a = 16 for (j=0; j < 8; j++) T[j] = 0 [] T[k] = 0 for 0 <= k <= (j-1) with j > 0 [] T[k] = 0 for 0 <= k <= (j-1) with j >= 0 [] j <= 8 [] a = 16

[] a = 16 [] j <= 8 [] T[k] = 0 for 0 <= k <= (j-1) with j > 0

Check all loop invariants for the loop in the program below: a = 16 for (j=0; j < 8; j++) T[j] = 0 [] a = 16 [] T[k] = 0 for 0 <= k <= (j-1) with j >= 0 [] j <= 8 [] T[k] = 0 for 0 <= k <= (j-1) with j > 0

[] y <= a [] x + y = a [] x <= a

Check all loop invariants for the loop in the program below: x = a // a is a positive number y = 0 while (x > 0) x-- y++ [] x + y < a [] y <= a [] x + y = a [] x <= a [] x >= y

[] an overall theory is wrong [] a theorem is wrong [] an algorithm is incorrect

Check all that apply. A counterexample can be used to prove ____________: [] an overall theory is wrong [] a theorem is wrong [] an algorithm is correct [] an algorithm is incorrect [] a theorem

[] j <= 7 [] j + a = 13 [] a >= 5

Check all that apply. Check all loop invariants before the iteration for the loop in the program below: a = 13 for (j=0; j < 8; j++) a = a - 1 [] j <= 7 [] a > 6 [] j + a = 8 [] j + a = 13 [] a >= 5

incorrect, {2000, 34, 4, 1, 5}

Consider this program that should return the smallest value in Array A. minval(A) { currmin = 0; for (i=0; i < A.length; i++) if (A(i) < currmin) currmin = A(i) //A(i) is the ith element in Array A return currmin } This program is ["None of these answers", "optimal", "perfect", "correct", "incorrect"] . A counterexample could be the array A= ["{20, 34, -1, 10, 6}", "None of these answers", "{0, 1, 2, -3, 5}", "{2000, 34, 4, 1, 5}"] .

4

Fill in the blank. Instructions are numbered starting from 1. There is a loop invariant code at Line __________. Answer -1 if there is no loop invariant code. 1. s = 0 2. x = 2.0 3. for (i=0; i <= n; i++) 4. s = x*x + 2 5. b = 2 * (s + x) + b 6. a = a + s << 2

mathematical induction

Loop invariants technique is closest to the ___________ technique. contradiction counterexample mathematical induction magnetic induction None of these answers

induction base

Mathematical induction involves two steps or cases: ___________ and ____________. induction base mathematical contradiction initial


Related study sets

Essentials of Strength Training and Conditioning Ch. 6

View Set

Incident Response and Computer Crime Investigations

View Set

research methods for behavioral sciences final exam study guide

View Set

Subnet Mask Dotted Decimal vs. CIDR

View Set

Adult Health Chapter 17 - Preoperative Nursing Management

View Set

17. Quiz 3: Stages of Development

View Set

Chapter 3: Proteins, Carbohydrates, and Lipids

View Set