CS 220 Final Review Update 2.0

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Let A = {1, 2, 3} and B = {a, b}, which choice is false?

(1,2,3) ∈ AxA

Consider the sets A = {1, 2, 3, 4, 5, 6} B = {1, 2} C = {3, 4, 5, 6}. Match the following sets to their equivalent definitions.

(A ∪ B) ∩ C {3,4,5,6} A ∪ (B ∩ C) {1,2,3,4,5,6} A - C {1,2} C - A ∅

U = {1, 2, 3, 4, 5} A = {1, 2, 3} B = {2, 4} C = {1, 3, 4} Match.

wRONG

What is the best (lowest) big O bound for the following function: f(n) = 100*n^3 + 5*n^2 + 3*n + 100,000,000

O(n^3)

Is the following situation best represented by a permutation or a combination? How many ways are there to find a student council president, vice president, and treasurer out of 100 students?

Permutation

Given pre-condition: x is an integer; and the following program segment: if ((x//3)*3 != x) :x = x - (x % 3) What is the post-condition? Note that "//" is integer division.

Post-condition: x is divisible by 3

Given pre-condition that x is an integer and y is an integer, and the following program segment: if (x < y) :z = y - xelse :z = x - y What is the post-condition for z?

Post-condition: z = absolute difference between x and y

What is the pre-condition for x, if the post-condition is -30 <= y <= 0 for the following program segment? y = x * x - 5 *x - 24

Pre-condition: -3 <= x <= 8

P(1) is true. For all positive integers n, if P(n) is true, then P(2n) is true. We can now infer that P(n) is true for:

The powers of two: {2x:x∈N}={1,2,4,8,...}

If A = A∪B then which of the following statements cannot be true?

A⊂B

What step best completes the following proof if substituted for the "???"? Proposition: A postage price of n≥8n≥8 cents can be payed entirely using 3 cent and 5 cent stamps. We will prove this using strong induction.For the first basis step, n=8, we see that 8=5+3.For the second basis step, n=9, we see that 9=3+3+3.For the third basis step, n=10, we see that 10=5+5.For the inductive step,We will assume that for all 10≤j≤k, j cent postage can be represented using 3 and 5 cent stampsand we will show that a k+1 cent postage can be represented using 3 and 5 cent stamps.We see that k+1=(k−2)+3.???Therefore, k+1=(k−2)+3 can be represnted using 3 and 5 cent stamps, namely the representation of k−2 and an extra 3 cent coin.Since the basis step and the inductive step hold, a postage price of n≥ can be payed entirely using 3 cent and 5 cent stamps.

By the inductive hypothesis, (k−2) can be represented using 3 and 5 cent stamps.

Let p and q be propositions p: I bought a lottery ticket this week q: I won the million dollar jackpot on Friday Match each of these propositions: If I bought a lottery ticket this week then I won the million dollar jackpot on Friday. If I did not buy a lottery ticket this week then I did not win the million dollar jackpot on Friday. I bought a lottery ticket this week and I won the million dollar jackpot on Friday. I bought a lottery ticket this week or I won the million dollar jackpot on Friday. I bought a lottery ticket this week if and only if I won the million dollar jackpot on Friday.

If I bought a lottery ticket this week then I won the million dollar jackpot on Friday. p → q If I did not buy a lottery ticket this week then I did not win the million dollar jackpot on Friday. ¬p → ¬q I bought a lottery ticket this week and I won the million dollar jackpot on Friday. p ^ q I bought a lottery ticket this week or I won the million dollar jackpot on Friday. p ∨ q I bought a lottery ticket this week if and only if I won the million dollar jackpot on Friday. p ↔ q

Consider the sets A = {1, 2, 3, 4, 5} B = {a, b, c} C = {3, b, 1, a}. Match the following sets to their equivalent definitions.

(A ∪ B) ∩ C {3,b,1,a} A ∪ (B ∩ C) {1,23,4,5,a,b} A - C {2,4,5} C - A {a,b} A ∩ B ∅

Consider the sets A = {a, b, c, d, e} B = {c, d, e, f} C = {a, c, f}. Match the following sets to their equivalent definitions.

(A ∪ B) ∩ C {a,c,f} A ∪ (B ∩ C) {a,b,c,d,e,f} A-C {b,d,e} C-A {f} A ∩ ∅ ∅

Here is most of the proof for one of the associative properties. What step goes where the ??? is to best complete the proof? x∈(A∪B)∪Cthereforex∈(A∪B)∪C⇔(x∈(A∪B)∨x∈C)⇔((x∈A∨x∈B)∨x∈C)≡(x∈A∨(x∈B∨x∈C))⇔???⇔(x∈A∪(B∪C))≡x∈A∪(B∪C)

(x ∈ A ∨ (x ∈ B ∪ C))

Here is most of the proof for one of the distributive properties. What step goes where the ??? is to best complete the proof? x∈A∪(B∩C)thereforex∈A∪(B∩C)⇔(x∈A∨(x∈B∧x∈C))≡((x∈A∨x∈B)∧(x∈A∨x∈C)⇔((x∈A∪B)∧(x∈A∪C))⇔(x∈(A∪B)∩(A∪C))≡x∈(A∪B)∩(A∪C)

(x ∈ A ∪ B) ∧ (x ∈ A ∪ C)

What is the loop invariant for the variable x in the following code segment? x = -20 while (x < 10) : x += 5

-20 <= x <=10

Given pre-condition x > 15 and the following program segment, determine the pre-condition/post-condition after each program segment (i.e. use the composition rule) // Pre-condition: x > 15 y = 13; // 1) pre/post condition? z = x + y; // 2) pre/post condition? if (z > 0) z = z + 2 * y; else z = z - 2 * y; // 3) post-condition?

/ 1) pre/post condition? x > 15, y = 13 // 2) pre/post condition? x > 15, y = 13, z > 28 // 3) post-condition? x > 15, y = 13, z >54

Given pre-condition c = 5 and the following program segment, determine the pre-condition/post-condition after each program segment (i.e. use the composition rule) // Pre-condition: c = 5 a = -2; // 1) pre/post condition? b = a * c; // 2) pre/post condition? if (b > 0) b = b * 10 - a; else b = b * 2 + a; // 3) post-condition?

// 1) pre/post condition? a = -2; c = 5 // 2) pre/post condition? b = -10, a = -2; c = 5 // 3) post-condition? b = -22, a = -2, c = 5

Given pre-condition: a = v1, b = v2 What statements must be executed for the post-condition, a = v2 + v1, b = v1 - v2, to be true?

// Pre-condition: a = v1, b = v2 t1 = a + b; t2 = a - b; a = t1; b = t2;

What is the loop invariant for the variable x in the following code segment? x = 25 while (x > 13): x -= 3

13 <= x <= 25

What is the degree of vertex c in the graph

2

For this tree with root a, What is the height of the tree? Which of these is a level 2 vertex? What is the parent of f? Which of these is a leaf?

3 d c e

Let f(x) = x + 1, g(x) = 4x + 7 What is (g o f)(x)?

4x + 11

Let f(x) = x + 1, g(x) = 4x + 7 What is (f o g)(x)?

4x + 8

Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -2 <= x < 4 y = 2*x*x - x +3

<= y <= 18

Let A be the set of computer science students and B be the set of students taking CS220. Match the following sets with their English descriptions.

A ∪ B are taking cs220 or are cs majors A ∩ B are taking cs220 and are cs majors A - B the set of people who cs majors that are not taking cs 220 B - A the set of cs 220 students who are are not cs majors

Let A be the set of people who have read at least one book in the past month and B be the set of people who have seen at least one movie in the past month. Match the following sets with their English descriptions.

A ∪ B read or seen a movie in the past month A ∩ B read and seen a movie in the past month A - B read but have not seen a movie in the past month B-A Seen a movie but not read in the past month

Which sets are proper subsets of the set {10, 20, 30}. Check all answers that are correct.

All but {10, 20, 30, 40, 50} Not 100%

Is the following situation best represented by a permutation or a combination? A coin is flipped six times, producing either heads or tails. How many possible outcomes contain exactly three heads?

Combination

Is the following situation best represented by a permutation or a combination? How many ways can a set of ten letters from the English alphabet be chosen?

Combination

What is the pre-order traversal of the following tree with root a, assuming nodes to the left are visited before nodes to the right. First element: a Second element: b Third element: [ Select ] ["a", "b", "c", "d", "e", "f", "g", "h"] Fourth element: [ Select ] ["a", "b", "c", "d", "e", "f", "g", "h"] Fifth element: e Sixth element: g Seventh element: f Eighth element: h

Answer 1:a Answer 2:b Answer 3:c Answer 4:d Answer 5:e Answer 6:g Answer 7:f Answer 8:h

Consider the following snippet of code: # precondition: a and d are positive integers r = aq = 0 while (r >= d) : r = r − d q = q + 1 Which of the following is a correct loop invariant for this code?

Atleast One of these is wrong a = dq + r q = a % d

Which of the following functions f: Z → Z are not one to one?

Atleast one of these is wrong f(x) = sqrt(x) f(x) = 12

Let A be the set of students who live within one mile of campus and let B be the set of students who walk to classes. Which of the following are equivalent to the set of students who live further than one mile away from campus and walk to class?

A¯∩B B−A and one more

Let A be the set of people who own cats and B be the set of people who own dogs. Which of the following are equivalent to the set of people who own cats and dogs?

A∩B and Another option Not A∪B

Construct truth table for the following x y x → (x→y)

F F t F T t T F f T T t

x y (x → y) → (¬x ∨ y)

F F t F T t T F t T T t

For every set A, there exists a set B such that B ⊂ A.

False

Sequences can not be finite:am, am+1, ... ,an

False

Suppose that AA and BB are sets such that|A|≤|B||A|≤|B| then A⊆BA⊆B.

False

The following function is invertible.f: {0, 1}3 → {0, 1}3. f takes the input string and replaces the first bit by 1. For example, f(001) = 101 and f(110) = 110

False

The following function is invertible.f: {0, 1}4 → {0, 1}4. f takes the input string and replaces the last bit by 0. For example, f(0011) = 1010 and f(1100) = 1100

False

The following is a closed form expression for the sum of a arithmetic sequence. n(n+1/)2

False

The following is a closed form expression for the sum of a geometric sequence. n(n+1)(2N+1)/6

False

True or false: the following graph represents a transitive relation.

False

Is the following program segment correct with respect to pre-condition int x = 2, and the post-condition int y = 51 // Pre-condition: x = 2 int z = 53; int y = x - z; // post-condition: y = 51

No

Here is most of the proof for one of the absorption properties. What step goes where the ??? is to best complete the proof? x∈A∪(A∩B)thereforex∈A∪(A∩B)⇔(x∈A∨(x∈A∩B))⇔???≡(x∈A)≡x∈A

Not (x ∈ A ∧ (x ∈ A ∨ B))

In class we went through a proof for one of DeMorgan's laws for sets. Here is most of another. What step goes where the ??? is to best complete the proof? x∈A∪B¯¯¯¯¯¯¯¯¯¯¯¯¯⇔???⇔¬(x∈A∨A∈B)≡¬(x∈A)∨¬(x∈B)⇔x∈A¯¯¯¯∧x∈B¯¯¯¯⇔x∈(A¯¯¯¯∩B¯¯¯¯)

Not (x ∈ A ∪ x ∈ B) Not (x ∈ A ∩ x ∈ B)

Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -6 < x <= 2 y = x * x - x - 6

Not -6 <= y <= 14

Given pre-condition: a = v1, b = v2 What statements must be executed for the post-condition, a = v2, b = v1, to be true?

Not // Pre-condition: a = v1, b = v2 t = b; a = b; b = t;

Given pre-condition: x is an integer, y is an integer; and the following program segment: if (x < y) z = y - x; else z = x - y; What is the post-condition for z?

Not Post-condition z = x and z = y

Given pre-condition: x is an integer; and the following program segment: if (x < 0) z = (x * 1) * 2 else z = (x * -1) * 2 What is the post-condition for z?

Not Post-condition: z = double the value of x

Given the following program segment, what is the pre-condition for x, that makes the post-condition true? y = -3*x*x*x + 27 // post-condition 108 >= y >= 3

Not Pre-condition: -3 <= x <= 3

What is the pre-condition for x, if the post-condition is -1 <= y <= 29 for the following program segment? y = x * x - 3 *x + 1

Not Pre-condition: -4 <= x <= 6

Let f : Z → Z be f(x) = x + 1. What's the inverse?

Not f is not invertable

What is the loop invariant for z? // Pre-condition: v1 >= 0 int x = -3, y = 2, z = v1 while (x < 2) { z = z / y; x = x + 1; }

Not v1 / 16 <= z <= v1

What is the loop invariant for z? //Pre-condition: v1 >= 0 int x = -4, y = 2, z = v1 while (x < 6) { z = z * y; x = x + 2; }

Not v1 < z < 32*v1^5 Not v1 <= z <= 64*v1

What is the loop invariant for each variable in the following code segment? x = 22; while (x > 0) { x /= 2; } assume x is an integer and that the division is integer division.

Not x > 0 Not 0 < x <= 22

What is the power set of {1, 2}?

Not {( ), (1), (2), (1,2)} Probably { { }, {1}, {2}, {1, 2}}

In class we went through a proof for one of DeMorgan's laws for sets. Here is most of another. What step goes where the ??? is to best complete the proof? x∈A∪B¯¯¯¯¯¯¯¯¯¯¯¯¯thereforex∈A∪B¯¯¯¯¯¯¯¯¯¯¯¯¯⇔???⇔¬(x∈A∨A∈B)≡¬(x∈A)∨¬(x∈B)⇔x∈A¯¯¯¯∧x∈B¯¯¯¯⇔x∈(A¯¯¯¯∩B¯¯¯¯)≡x∈(A¯¯¯¯∩B¯¯¯¯)

Not ¬(x ∈ A ∩ B)

Why is the function f:R → R defined by f(x) = sqrt(x) not well defined?

Some elements in the domain do not map to an element in the range.

Why is the function f:R → R defined by f(x) = 1/(x-1) not well defined?

Some elements in the domain do not map to an element in the target.

Why is the function f:R → R defined by f(x) = ±sqrt(x^2) not valid?

Some elements in the domain map to more than one element in the target.

In class we showed that breaking up a chocolate bar with n squares into the individual squares takes n-1 breaks. Did we show this using regular induction or strong induction?

Strong induction

What is wrong with this "proof" by strong induction? Proposition: an=1an=1 for all nonnegative integers nn. Basis step: a0=1a0=1 by definition of a0a0. Inductive step: Assume that aj=1aj=1 for all nonnegative integers jj with j≤kj≤k. We will show that ak+1=1ak+1=1. We see that ak+1=ak⋅akak−1=1⋅11=1ak+1=ak⋅akak−1=1⋅11=1. Since the basis step and the inductive step hold, an=1an=1 for all nonnegative integers nn.

The basis step does not hold.

:P(0) and P(1) are true. For all nonnegative integers n, if P(n) and P(n + 1) are true, then P(n + 2) is true. We can now infer that P(n) is true for:

The nonnegative integers

P(0) is true. For all nonnegative integers n, if P(n) is true, then P(n + 3) is true. We can now infer that P(n) is true for:

The nonnegative integers divisible by three

P(0) is true. For all nonnegative integers n, if P(n) is true, then P(n + 2) and P(n + 3) are true. We can now infer that P(n) is true for:

The nonnegative integers except n = 1

Assume a flower has an even number of petals, and two players, A and B take turns removing either one or two petals, and assume they proceed as follows: while remaining number of petals is greater than zero: A removes one or two petals if there are petals remaining, B removes the same number of petals that A did Which of the following is a correct loop invariant for this process? Also note that zero is an even number.

The number of remaining petals is even

P(1) and P(2) are true. For all positive integers n, if P(n) and P(n + 1) are true, then P(n+2) is true. We can now infer that P(n) is true for:

The positive integers.

What is wrong with this "proof" by strong induction? Proposition: an=1an=1 for all nonnegative integers nn. Basis step: For n=0n=0, we see that a0=1a0=1 by definition of a0a0. Inductive step: Assume that aj=1aj=1 for all nonnegative integers jj with j≤kj≤k. We will show that ak+1=1ak+1=1. We see that ak+1=ak⋅akak−1=1⋅11=1ak+1=ak⋅akak−1=1⋅11=1. Since the basis step and the inductive step hold, an=1an=1 for all nonnegative integers nn.

This proof requires a basis step for n = 1, and for which the claim is not correct.

What is wrong with this "proof" by strong induction? Proposition: ddxxn=0ddxxn=0 for all n≥0n≥0 Basis step: For n=0n=0, ddxxn=ddxx0=ddx1=0ddxxn=ddxx0=ddx1=0. Inductive step. Assume that ddxxj=0ddxxj=0 for all j≤kj≤k. We will show that ddxxk+1=0ddxxk+1=0. By the product rule, ddxxk+1=ddx(xkx1)=xkddxx1+x1ddxxk=xk⋅0+0⋅x1=0ddxxk+1=ddx(xkx1)=xkddxx1+x1ddxxk=xk⋅0+0⋅x1=0. Since the basis step and the inductive step hold, ddxxn=0ddxxn=0 for all n≥0n≥0.

This proof requires a basis step for n = 1, and for which the claim is not correct.

A sequence is a special type of function in which the domain is a consecutive set of integers.

True

In regular induction, showing P(n) is true for n greater than or equal to zero requires showing the basis step, P(1), and the inductive step, i.e. that for every natural number k, if P(k) then P(k+1). True or false: In strong induction, the only difference from regular induction is in the inductive step where you instead prove that for every natural number k, if P(1)∧P(2)∧...∧P(k) then P(k+1).

True

Suppose that every person given a United States phone number is assigned a unique 10 digit number. Let i represent the first three digits of these phone numbers. Then do the sets Ai: the set of people whose phone number begins with the three digits i form a partition of the set of people with United States phone numbers?

True

The following function is invertible.f: {0, 1}5 → {0, 1}5. f takes the input string x, removes the first 2 bits of x, and adds the bits to the end of x. For example, f(01101) = 10101

True

True or false: A proof using regular induction can be considered a special case of proof by strong induction.

True

True or false: the following graph is a tree.

True

True or false: the following graph is connected

True

True or false: the following graph is connected.

True

Is the following program segment correct with respect to pre-condition int y < -6 and postcondition z < -1 // Pre-condition: y < -6 int x = 5; int z = x + y; // Post-condition: z < -1

Yes

You have an infinite container with blue and red marbles. At each step you randomly pick three marbles from the container. You have a pile of marbles in front of you that is initially empty. At each step you randomly pick three marbles from the container. If all of them are the same color, you discard them. Otherwise, you place the marbles that form the majority (two that are either blue or red) in the pile in front of you. What is the loop invariant that describes the state of the pile you are creating?

Your pile contains an even number of marbles.

Which of the following are properties of exponents

b^m+n = b^m * b^n (b^m)^n = b^m*n (b*c)^n = b^n * c^n

Which of the following functions f: R → Z are not one to one?

f(x) = ceiling(x) f(x) = ceiling(x+1/2) + floor(x - 1/2) f(x) = floor(x)

Which of the following functions f: R → R are not onto?

f(x) = floor(x) f(x) = ceiling(x)

Let f : Z → Z be f(x) = 2x. What's the inverse?

f-1(x) = x/2

Assume a universal set U that contains objects with two characteristics: color and shape, where each object is either square or round (but not both), and either blue or red (but not both). Let A be the set of square things. Let B be the set of round things. Let C be the set of red things. Let D be the set of blue things. Match the following sets with their descriptions

partial

Consider the sets A = {1, 2, 3, 4, 5} B = {1, 5} C = {-3, 1, 7}. Match the following sets to their equivalent definitions.

partial

x y (x ↔ y) ⊕ (x ↔ ¬y) F F F T T F T T

t t t t

Which of the following is the power set of {1, 2}?

{ { }, {1}, {2}, {1, 2}}

Consider the sets A = {a, b} B = {0, 1}. What is A x B?

{(a, 0), (a, 1), (b, 0), (b, 1)}

Consider the set A = {a, b}. What is A x A?

{(a, a), (a, b), (b, a), (b, b)}

Consider the sets A = {a, b} B = {b, c}. What is A x B?

{(a, b), (a, c), (b, b), (b, c)}

For the set {1, 2, 3}, which of the following are valid partitions?

{1,2},{3} {1},{2},{3} {1,2,3} and maybe {2},{1,3}

Which sets are a subset of the set {1, 2}? Check all correct answers.

{1} {2} {} {2, 1}

What is the power set of {WY, CO, NM}?

{{ }, {NM}, {CO}, {WY}, {NM, CO}, {NM, WY}, {CO, WY}, {NM, CO, WY}}

U = {1, 2, 3, 4, 5, 6} A = {1, 2, 3, 4} B = {2, 4, 6} C = {1, 3, 5} Match the following:

{} B∩C B ⊆ A False A ∪ B ∪ C U

A = {1, 2, 3, 4} B = {1, 3, 5} C = {2, 4, 6, 8} Match the following.

|A|=|B| false |A ∪ C| = 6 true A ∩ B ∩ C the empty set A ∪ B {1,2,3,4,5}

Let A={a,b,c,d,e}A={a,b,c,d,e}. Which of the following is True?

∅ ⊆ A |{a,b}| < |A| b ∈ A


संबंधित स्टडी सेट्स

Psychology 110 - Chapter 1 - Exam 1

View Set

LearningCurve - Chapter 5: Price Controls and Quotas: Meddling with Markets

View Set

Limited Partnerships and Limited Liability Companies

View Set

abbreviations for levels of assistance

View Set