C960 Discrete Math 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Exercise 2.19.1: Fast exponentiation. Compute the values of each of the following expressions. You should not need a calculator. c) 11^20 in Z33 (33 is subtext)

22

2.4.1: Arithmetic for integers modulo n 1) What is the value of (6 + 8) mod 4?

2 (6 + 8) mod 4 = 14 mod 4 = 2

3.7.1: Summations Enter the result of the summation 4) k = 0 to 2 ∑ (2 * 4^k)

42

Exercise 2.5.1: Computing using modular arithmetic. Compute the value of the following expression: d) 44^12 mod 6

44^12 mod 6 = (44 mod 6)^12 mod 6 = 2^12 mod 6 = (2^6 mod 6)(2^6 mod 6) mod 6 = (64 mod 6)(64 mod 6) mod 6 = 4 · 4 mod 6 = 16 mod 6 = 4

2.4.1: Arithmetic for integers modulo n 3) What is the value of 4 * 9 mod 6?

0 4·9 mod 6 = 36 mod 6 = 0

2.24.3: Encrypting and decrypting a message with RSA Suppose that Alice and Bob are using the RSA cryptosystem to send a message. Bob selects p = 3 and q = 11. 1) What is the value of N? 2) What is the value of φ? 3) If e is chosen to be 7, what is d? 4) If Bob receives ciphertext c = 25, then what was Alice's plaintext m? (You will probably need a calculator for this question.) 5) If the plaintext m = 2, then what is the ciphertext c?

1) 33 pq = 3·11 = 33 2) 20 φ = (p - 1)(q - 1) = 2·10 = 20 3) 3 d is chosen so that 7·d mod 20 = 1 (7·3) mod 20 = 1 4) 16 m = c^d mod N = 25^3 mod 33 = 16 5) 29 c = m^e mod N = 27 mod 33 = 29

4.16.4: Finding the next r-subset in lexicographic order 1) The subset {3, 4, 7, 8, 9} is chosen from the set {1, 2, ..., 9}. What 5-subset comes next in lexicographic order? {3, 5, 6, 7, 8} {3, 5, 7, 8, 9} {3, 4, 7, 9, 8} 2) The subset {3, 4, 5, 7, 8} is chosen from the set {1, 2, ..., 9}. What 5-subset comes next in lexicographic order? {3, 4, 5, 8, 9} {3, 4, 5, 6, 7} {3, 4, 5, 7, 9} 3) The subset {3, 4, 6, 8, 9} is chosen from the set {1, 2, ..., 9}. What 5-subset comes next in lexicographic order? {3, 4, 7, 8, 9} {3, 4, 6, 9, 8} {3, 5, 6, 7, 8}

1) {3, 5, 6, 7, 8} In order to get a larger 5-subset, the second element must be increased to 5. Then the remaining elements just need to be replaced so that they are larger than 5 and in increasing order. 2) {3, 4, 5, 7, 9} A larger subset can be generated by increasing the last entry from 8 to 9. 3) {3, 4, 7, 8, 9} To get a larger subset than {3, 4, 6, 8, 9}, the 6 must be incremented to 7. If the third to last element is 7, then the next two elements have to be 8 and 9.

4.7.2: Counting r-permutations 2) There are 5 computers and 3 students. How many ways are there for the students to sit at the computers if no computer has more than one student and each student is seated at a computer?

60 5 possible computers for the first student. Once the first student has chosen, there are 4 computers left for the second student to select from, and then 3 possible computer choices for the third student. P(5, 3) = 5 × 4 × 3 = 60

4.7.2: Counting r-permutations 3) A class has ten students. A teacher will give out three prizes: One student gets a gift card, one gets a book, and one gets a movie ticket. No student can receive more than one prize. How many ways can the teacher distribute the prizes?

720 10 students to select from for the first prize. Once the first prize has been given, there are 9 students to select from for the second prize, and then 8 students to select from for the third prize. P(10, 3) = 10 · 9 · 8 = 720

4.7.4: Counting line-ups: Permutations A wedding party consisting of a bride, a groom, two bridesmaids, and two groomsmen line up for a photo. How many ways are there for the wedding party to line up?

720 A line-up of the wedding party is a permutation of the six people in the group, so the number of different line-ups is: 6! = 720

3.21.2: Matching characteristic equations to linear recurrence relations Do the problem directly on the course material

See course material

4.12.1: Counting possibilities by complement See course material

See course material

4.3.1: Counting password possibilities See course material

See course material

2.3.1: Integer divisibility Yes or No 1) Does 7 divide 56?

Yes 56 = 7·8. 56 is an integer multiple of 7.

1.13.1: Asymptotic growth Find the asymptotic behavior for the given functions by dropping the constant factors and by keeping the terms that grow the fastest. Type exponents as: ^# Ex: n^2 4) f(n) = n^3 + 1999n + 1337

n^3 Even though the constant factor in front of n(1999) is quite large, you can still find a large enough n so that n^3 is bigger than 1999n. As you are interested in the behavior for very large values of n, you only keep n^3. Tip: If you cannot readily decide which one of the terms grows faster, plug in several large values for n and compare.

Exercise 3.18.1: Recursively computing sums of cubes a) Give a recursive algorithm to compute the sum of the cubes of the first n positive integers. The input to the algorithm is a positive integer n. The output is j = 1 to n ∑ j^3. The algorithm should be recursive, it should not compute the sum using a closed form expression or a loop.

SumCube(n) Input: A positive integer n Output: 1^3 + 2^3 + ... + n^3 If (n = 1), Return( 1 ) s := SumCube(n - 1) // The recursive call Return( n^3 + s )

Exercise 3.18.4: Recursively computing a number raised to an exponent that is a power of 2 Give a recursive algorithm whose input is a real number r and a non-negative integer n, and whose output is r^(2n) . Note that the exponent of r is 2^n.

SuperPower(r, n) Input: A real number r and a non-negative integer n Output: r^(2n) If (n = 0), Return( r ) p := SuperPower(r, n - 1) // The recursive call Return( p^2 )

Exercise 4.16.1: Ordering 5-tuples. (a) Write the following 5-tuples in lexicographic order: (3, 100, 101, 3, 4) (1, 1, 2, 1, 2) (3, 4, 5, 1, 1) (1, 2, 100, 1, 1) (3, 4, 5, 2, 2) (2, 101, 100, 3, 4) (2, 100, 101, 3, 4) (3, 4, 5, 2, 1) (1, 1, 2, 2, 1)

(1, 1, 2, 1, 2) ≤ (1, 1, 2, 2, 1) ≤ (1, 2, 100, 1, 1) ≤ (2, 100, 101, 3, 4) ≤ (2, 101, 100, 3, 4) ≤ (3, 4, 5, 1, 1) ≤ (3, 4, 5, 2, 1) ≤ (3, 4, 5, 2, 2) ≤ (3, 100, 101, 3, 4)

2.24 RSA Decryption In the previous lesson, the message "no" was encrypted into the ciphertext c = 329940 using the public key N = 373097 and e = 459173. Use the private key d = 84173 to retrieve the plaintext.

The formula m = c^d mod N is used. m = 329940^84173 mod 373097 = 7879

3.11.3: Induction proofs for sums of arithmetic and geometric sequences 1) In the proof of the closed form for the sum of an arithmetic sequence, the inductive hypothesis is: [ j = 0 to (k - 1) ∑ (a + jd) ] = ka + ak(k − 1)/2 Select the expression that is equivalent to the expression below by applying the inductive hypothesis: (a + kd) + [ j = 0 to (k - 1) ∑ (a + jd) ] (a + kd) + ka + ak(k − 1)/2 (a + kd) + ka + ak(k + 1)/2 j = 0 to k ∑ (a + jd)

(a + kd) + ka + ak(k − 1)/2 The expression in this choice is obtained by replacing the left side of the equality in the inductive hypothesis with the right side.

3.7.1: Summations Enter the result of the summation 1) x = 1 to 5 ∑ (x - 4)

-5

1.13.1: Asymptotic growth Find the asymptotic behavior for the given functions by dropping the constant factors and by keeping the terms that grow the fastest. Type exponents as: ^# Ex: n^2 2) f(n) = 109

1 In this example 109 is the constant multiplier of 1. Drop the multiplier 109, but keep the 1 to indicate that this function has a non-zero value.

Exercise 4.16.2: Find the next permutation in lexicographic order For each permutation of {1, 2, 3, 4, 5, 6, 7}, give the next largest permutation or indicate that the permutation is the last one in lexicographic order. (a) (1, 2, 3, 4, 5, 6, 7) (b) (7, 6, 5, 4, 3, 2, 1) (c) (1, 7, 6, 4, 2, 3, 5) (d) (3, 7, 6, 5, 4, 2, 1) (e) (5, 4, 7, 6, 3, 2, 1)

1) (1, 2, 3, 4, 5, 7, 6) 2) This is the last permutation, so there is no next permutation. 3) (1, 7, 6, 4, 2, 5, 3) 4) (4, 1, 2, 3, 5, 6, 7) 5) (5, 6, 1, 2, 3, 4, 7)

1.7.2: Nested loops - example 1 count := 0 For i = 1 to 3 For j = 1 to 4 count := count + i ⋅ j End-for End-for 1) How many times is the variable count increased? 2) What is the final value of count?

1) 12 For each iteration of the outer loop, the inner loop iterates 4 times. The outer loop iterates 3 times. 3 × 4 = 12 2) 60 1·(1 + 2 + 3 + 4) + 2(1 + 2 + 3 + 4) + 3(1 + 2 + 3 + 4) = 60

1.5.2: For-loops Consider the following pseudocode fragment: sum := 0 For i = 2 to 5 sum := sum + i End-for 1) What is the value of sum after the second iteration? 2) How many iterations will the for-loop execute? 3) What is the final value for sum after executing the for-loop?

1) 5 In the first iteration, i = 2. In the second iteration, i = 3. 2 + 3 = 5 2) 4 i = 2, 3, 4, 5. Four iterations 3) 14 i = 2, 3, 4, 5. sum = 2 + 3 + 4 + 5

2.23.3: Preparation of public and private keys Suppose Bob selects prime numbers p = 5 and q =1 1. 1) What is N? 2) What is φ? 3) What integer e can be chosen between 5 and 8? 4) Given the value for e found in the previous question, what is d?

1) 55 N = (5)(11) = 55 2) 40 φ = (5−1)(11−1) = 40 3) 7 Since 40 = 2^3⋅5, e cannot be divisible by either 2 or 5. Thus, e = 7. The public key is N = 55 and e = 7. 4) 23 Since (−17)7 + (3)40 = 1, d = −17. In practice, only positive integers are used. Thus, the private key is d = −17 + 40 = 23.

3.16.3: Identifying properly nested parentheses 1) ( ( ) ) Properly nested Not properly nested 2) ( ( ) ) ) Properly nested Not properly nested 3) ( ( ( ) ) ( ) ) Properly nested Not properly nested

1) Properly nested 2) Not properly nested 3) Properly nested

3.16.4: Applying recursive rules to get properly nested parentheses What was the last recursive rule applied in constructing each of the following properly nested string or parentheses? Recursive rules: (u) is properly nested. uv is properly nested. 1) ( ( ) ( ) ) Rule 1 Rule 2 2) ( ( ) ( ) ) ( ( ) ) Rule 1 Rule 2 3) ( ( ( ) ( ) ) ( ( ) ) ) Rule 1 Rule 2

1) Rule 1 2) Rule 2 3) Rule 1

Exercise 4.8.1: Mapping permutations to subsets. Consider a function f that maps 5-permutations from the set S = {1, ..., 20} to 5-subsets from S. The function takes a 5-permutation and removes the ordering on the elements. (a) What is the value of f on input (12, 1, 3, 15, 9)? (b) Is (12, 3, 12, 4, 19) a 5-permutation? Why or why not? (c) How many permutations are mapped onto the subset {12, 3, 13, 4, 19}?

1) {1, 3, 9, 12, 15} 2) No because 12 appears twice. 3) 5! because there are 5! ways to order the elements in {12, 3, 13, 4, 19}.

3.7.1: Summations Enter the result of the summation 3) k = 0 to 24 ∑ (5 + 3k)

1025

4.7.2: Counting r-permutations 1) A red, blue, and green die are thrown. Each die has six possible outcomes. How many outcomes are there for the three dice in which they are all different?

120 6 possible outcomes for the red die. Since the blue die must be different from the red die, 5 possibilities for the blue die. Since the green die must be different from the red and blue dice, 4 possibilities for the green die. P(6, 3) = 6 × 5 × 4 = 120

3.6.2: Computing summations Give numerical values for the following summations. 1) j = 2 to 5 ∑ (2j − 1)

24 (2 · 2 - 1) + (2 · 3 - 1) + (2 · 4 - 1) + (2 · 5 - 1) = 3 + 5 + 7 + 9 = 24

3.7.1: Summations Enter the result of the summation 5) j = 0 to 7 ∑ (10 * 2^j)

2550

Exercise 3.6.1: Evaluating summations Evaluate the following summations. a) k = 0 to 4 ∑ 2^k

2^0 + 2^1 + 2^2 + 2^3 + 2^4 = 31

2.7.1: Prime factorizations Select the correct choice 1) Which of the following is the prime factorization for 48? - 3 * 4^2 - 2^4 * 3 - 2 * 3^2

2^4 * 3 = 48. Also, 2 and 3 are both prime numbers.

Exercise 2.14.1: Converting from non-decimal bases to decimal. Compute the decimal representation for each of the following numbers. a) (1100110)2 (2 is subtext)

2^6 + 2^5 + 2^2 + 2^1 = 64 + 32 + 4 + 2 = 102

3.4.1: Recurrence relations Given the definition of a sequence fn whose domain is the set of all non-negative integers: f0 = 1 fn = f(n − 1) + 5n for n≥1 f3 =

31

2.7.1: Prime factorizations Select the correct choice 2) What is the prime factorization for 31? - 31 - 1 * 31 - 3 * 13

31 is a prime number, so its prime factorization is itself.

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: b) 344 div 5

344 = 68·5 + 4, so 344 div 5 = 68

3.15.1: Computing the value of functions defined recursively 1) Given the definition of a function g whose domain is the set of all non-negative integers: g(0) = 0 g(n) = g(n − 1) + n^3 for n ≥ 1 What is g(3)?

36 g(1) = g(0) + 13= 1 g(2) = g(1) + 23= 9 g(3) = g(2) + 33= 36

Exercise 2.14.1: Converting from non-decimal bases to decimal. Compute the decimal representation for each of the following numbers. b) (346)7 (7 is subtext)

3·7^2 + 4·7^1 + 6·7^0 = 3·49 + 4·7 + 6 = 181

3.4.1: Recurrence relations Given the definition of a sequence fn whose domain is the set of all non-negative integers: f0 = 1 fn = n^2 * f(n - 1) for n≥1 f2 =

4

2.15.1: Hexadecimal expansions 1) What is the decimal expansion of (2F)16? (16 is subtext)

47 2 is in the 16's place and F (which corresponds to 15) is in the 1's place. Therefore, (2F)16 = 2 · 16^1 + 15 · 16^0= 47

2.3.3: Computing div and mod Compute the following value: 4) -13 div 6

5 Starting with -13, when 6 is added 3 times to -13, the result is 5, which is in the range from 0 through 5. -13 + 3 · 6 = 5 -13 = -3 · 6 + 5

3.4.1: Recurrence relations Given the definition of a sequence fn whose domain is the set of all non-negative integers: f0 = 2 f1 = 5 fn = f(n − 2) * f(n − 1) for n ≥ 2 f3 =

50

Exercise 2.14.1: Converting from non-decimal bases to decimal. Compute the decimal representation for each of the following numbers. d) (50020)8 (8 is subtext)

5·8^4 + 2·8^1 = 5·4096 + 2·8 = 20496

2.4.1: Arithmetic for integers modulo n 2) What is the value of 5 * 7 mod 9?

8 5·7 mod 9 = 35 mod 9 = 8

1.14.1: Big-O True or False 2) A Θ (n) algorithm is O (n^2).

True As n^2 is worse than n, this is true.

1.14.1: Big-O True or False 5) A O (1) algorithm is Θ (1).

True This is as true as the two complexities are the same.

2.7.1: Prime factorizations Select the correct choice 3) In which prime factorization are the prime factors listed in non-decreasing order? - 2 * 7 * 13 * 11 - 2 * 7 * 11 * 13 - 7 * 2 * 11 * 13

Each prime factor is greater than or equal to the one that precedes it.

4.7 Computer-generated ID numbers A computer program used by a research group generates a four digit identification number for each member of a sample. The program cannot use the digits 0, 1, or 2 in the ID number and each ID cannot contain repeated digits. The ID number system must facilitate 1000 members. Are there enough identification numbers possible?

Excluding the digits 0, 1, and 2, seven digits can be used. The number of ID numbers is equal to the number of 4-permutations of seven objects. The number of 4-permutations of seven objects is P(7,4) = 7 · 6 · 5 · 4 = 840. If the system must facilitate 1000 members, there will not be enough identification numbers.

1.14.1: Big-O True or False 4) A Θ (n) algorithm is O (1).

False As 1 is not worse than n, this is false. If a program takes n instructions asymptotically (a linear number of instructions), you cannot make it worse and have it take only 1 instruction asymptotically (a constant number of instructions).

3.12.2: The principle of strong induction with general range for the base case 2) Select the choice that is equivalent to the following statement: For k ≥ 7, if P(j) is true for all j in the range 2 through k, then P(k + 1) is true. For k ≥ 7, (P(2) ∧ P(3) ∧...P(j)) implies P(j + 1) For k ≥ 7, (P(2) ∧ P(3) ∧...P(k)) implies P(k + 1) For k ≥ 7, (P(7) ∧ P(8) ∧...P(k)) implies P(k + 1)

For k ≥ 7, (P(2) ∧ P(3) ∧...P(k)) implies P(k + 1) Saying that P(j) is true for all j in the range 2 through k is the same as saying (P(2) ∧ P(3) ∧...P(k))

Exercise 2.22.2: Deducing the key from a single (plaintext, ciphertext) pair. (a) Suppose Alice and Bob use the simple encryption scheme in which c = (m + k) mod N and m = (c − k) mod N. Suppose that Eve knows that N = 4657. Suppose that she also manages to learn that the message m corresponding to c = 1322 is 3411. Can she infer the value for k? What is k?

If c = (m + k) mod N, then k = (c - m) mod Nk = (1322 - 3411) mod 4657 = -2089 mod 4657 = 2568

3.20.1: Identifying linear homogeneous recurrence relations 1) f_n = -f_(n - 1) + squareroot(2) * f_(n - 5) Non-linear Linear, non-homogeneous Linear, homogeneous

Linear, homogeneous The expression is a sum of terms all of which are a constant times f_(n - j) for some j.

3.20.1: Identifying linear homogeneous recurrence relations 3) f_n = −f_(n − 1) + 3f_(n − 2) + 1 Non-linear Linear, non-homogeneous Linear, homogeneous

Linear, non-homogeneous All the f_(n - j) terms are multiplied by a constant, so the recurrence relation is linear. However, the +1 term makes the recurrence non-homogeneous.

2.3.1: Integer divisibility Yes or No 3) Does 8 divide 99?

No There is no integer k such that 99 = 8k

3.20.1: Identifying linear homogeneous recurrence relations 2) f_n = -f_(n - 1) + squareroot(n) * f_(n - 5) Non-linear Linear, non-homogeneous Linear, homogeneous

Non-linear The f_(n - 5) is multiplied by squareroot(n) which is a function of n and not a constant. Therefore the recurrence relation is not linear.

Exercise 4.4.1: Devising a 3-to-1 correspondence Find a function from the set {1, 2, ..., 30} to {1, 2, ..., 10} that is a 3-to-1 correspondence. (You may find that the division, ceiling or floor operations are useful.)

One possibility: f(x)=⌈x/3⌉. For j ∈ {1, 2, ..., 10}, the numbers that f maps to j are 3j, 3j - 1, and 3j - 2.

Exercise 3.13.1: Proofs by strong induction - combining stamps Prove each of the following statements using strong induction. b) Prove that any amount of postage worth 24 cents or more can be made from 7-cent or 5-cent stamps.

Proof. By induction on the amount of postage. Base case: 24 cents: use two 5-cent stamps and two 7-cent stamps. 25 cents: use five 5-cent stamps. 26 cents: use one 5-cent stamp and three 7-cent stamps. 27 cents: use four 5-cent stamps and one 7-cent stamp. 28 cents: use four 7-cent stamps. Inductive step: Assume that for k ≥ 28, it is possible to make j cents worth of postage using only 7-cent and 5-cent stamps for any j in the range from 24 through k. Show that it is possible to make k + 1 cents worth of postage using only 7-cent and 5-cent stamps. Since k ≥ 28, then k - 4 ≥ 24. Therefore k - 4 falls in the range from 24 through k, and by the inductive hypothesis, it is possible to make k - 4 cents worth of stamps using only 7-cent and 5-cent stamps. By adding one 5-cent stamp, the amount of postage becomes (k - 4) + 5 = k + 1. Therefore, it is possible to make k + 1 cents worth of postage using only 7-cent and 5-cent stamps.

2.3.1: Integer divisibility Yes or No 2) 7·18 + 14·17 = 364. Does 7 divide 364?

Yes 364 is a linear combination of 7 and 14. 7 divides both 7 and 14.

Exercise 4.16.3: Find the next subset in lexicographic order. For each 7-subset of {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, give the next largest 7-subset or indicate that the 7-subset is the last one in lexicographic order. (a) {1, 2, 3, 4, 5, 6, 7} (b) {2, 4, 5, 9, 11, 12, 13} (c) {2, 4, 5, 11, 12, 13, 14} (d) {2, 4, 5, 6, 11, 12, 14} (e) {7, 8, 10, 11, 12, 13, 14}

a) {1, 2, 3, 4, 5, 6, 8} b) {2, 4, 5, 9, 11, 12, 14} c) {2, 4, 6, 7, 8, 9, 10} d) {2, 4, 5, 6, 11, 13, 14} e) {7, 9, 10, 11, 12, 13, 14}

3.6.3: Removing a final term in a sum. Select the choice whose value is equal to the given sum. 2) j = 0 to (n + 2) ∑ 2^(j - 1) j = 0 to (n + 1) ∑ 2^(j - 1) + 2^n j = 0 to (n - 1) ∑ 2^(j - 1) + 2^(n + 1) j = 0 to (n + 1) ∑ 2^(j - 1) + 2^(n + 1)

j = 0 to (n + 1) ∑ 2^(j - 1) + 2^(n + 1) The final index is n + 2. Therefore the last term is 2^(n + 2 - 1) = 2^(n + 1). When the last term is removed, the final index of the new sum is (n + 2) - 1 = n + 1.

1.13.1: Asymptotic growth Find the asymptotic behavior for the given functions by dropping the constant factors and by keeping the terms that grow the fastest. Type exponents as: ^# Ex: n^2 1) f(n) = 5n + 12

n Drop the term 12 and the constant multiplier 5.

Exercise 1.13.1: Asymptotic function a) f(n) = n^6 + 3n

n^6

Exercise 1.13.1: Asymptotic function d) f(n) = n^n + n

n^n

3.21.6: Matching characteristic equations to recurrence relations - multiple roots Do problem on course material

see course material

4.19.4: Binomial Theorem See course material

see course material

Exercise 4.16.5: Lexicographically ordering n-tuples of varying lengths See course material

see course material

Exercise 4.19.2: Using the binomial theorem to find closed forms for summations see course material

see course material

4.4.4: K-to-1 rule A farm orders x horse shoes for its horses. The farm does not order extras and all the horses will get new horse shoes. Apply the k-to-1 rule to determine the number of horses on the farm. Express your answer as a function of x. You should not need the ceiling or floor functions.

x/4 Every horse has four hooves. Set up a function that assigns horse shoes to horses. The function is 4-to-1, so the number of horses is the number of horse shoes (x) divided by 4.

Exercise 4.16.4: Order the subsets in lexicographic order. (a) Write the 4-subsets of {1, 2, 3, 4, 5, 6} in lexicographic order.

{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 3, 6}, {1, 2, 4, 5}, {1, 2, 4, 6}, {1, 2, 5, 6}, {1, 3, 4, 5}, {1, 3, 4, 6}, {1, 3, 5, 6}, {1, 4, 5, 6}, {2, 3, 4, 5}, {2, 3, 4, 6}, {2, 3, 5, 6}, {2, 4, 5, 6}, {3, 4, 5, 6}

2.3.3: Computing div and mod Compute the following value: 2) 23 div 5

4 Starting with 23, 5 can be subtracted 4 times until the result yields a number in the range from 0 through 4. 23 - 4 · 5 = 3 23 = 4 · 5 + 3

Exercise 2.5.1: Computing using modular arithmetic. Compute the value of the following expression: b) (72 · (−65) + 211) mod 7

(72 · (−65) + 211) mod 7 = ((72 mod 7) · (−65 mod 7) + (211 mod 7)) mod 7 = (2 · 5 + 1) mod 7 = 11 mod 7 = 4

Exercise 2.5.1: Computing using modular arithmetic. Compute the value of the following expression: c) (77 · (−65) + 147) mod 7

(77 · (−65) + 147) mod 7 = ((77 mod 7) · (−65) + (147 mod 7)) mod 7 = (0 · (−65) + 0) mod 7 = 0

2.9.2: Finding a random number Use a calculator for this question if needed. 1) Consider a random integer selected from the range from 2 to 1,000,000,000,000. Approximately, what are the chances that the selected number is prime? 0.0032 0.312 0.036

The chances the selected number is prime is 1/ln(1,000,000,000,000) which is approximately 0.036.

4.19.2: A combinatorial identity 1) Which expression has the same value as (12 choose 4)? (8 choose 4) (11 choose 4) (12 choose 8)

(12 choose 8)

Exercise 1.13.1: Asymptotic function c) f(n) = 3^n + 2^n

3^n

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: h) -215 div 7

(−215) = (−31)·7 + 2, so (−215) div 7 = −31.

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: c) -344 mod 5

(−344) = (−69)·5 + 1, so (−344) mod 5 = 1.

2.3.3: Computing div and mod Compute the following value: 3) -10 mod 5

0 Starting with -10, when 5 is added 2 times to -10, the result is 0, which is in the range from 0 through 4. -10 + 2 · 5 = 0 -10 = -2 · 5 + 0

2.11.2: Extended Euclidean Algorithm The image below shows the sequence of numbers generated by Euclid's algorithm on inputs 225 and 60 as well as partial results for the extended algorithm. 225 60 45 15 15 = 60 - (A * 45) 45 = 225 - (B * 60) 1) What is the correct value for the variable A? 2) What is the correct value for the variable B? 3) The two linear equations above can be used to express gcd(225, 60) as a linear combination of 225 and 60: 15 = C * 225 + D * 60. What is the correct value for C? 4) The two linear equations above can be used to express gcd(225, 60) as a linear combination of 225 and 60: 15 = C * 225 + D * 60 What is the correct value for D?

1) 1 A = 60 div 45 = 1 2) 3 B = 225 div 60 = 3 3) -1 15 = 60 - 45 45 = 225 - (3 · 60) The second equation replaces 45 in the first equation with a linear combination of 225 and 60. 15 = 60 - (225 - 3 · 60) = 4·60 - 225 The coefficient of 225 is -1. 4) 4 15 = 60 - 45 45 = 225 - (3 · 60) The second equation replaces 45 in the first equation with a linear combination of 225 and 60. 15 = 60 - (225 - 3·60) = 4·60 - 225. The coefficient of 60 is 4.

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: g) -215 mod 7

(−215) = (−31)·7 + 2, so (−215) mod 7 = 2.

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: d) -344 div 5

(−344) = (−69)·5 + 1, so (−344) div 5 = −69.

2.3.3: Computing div and mod Compute the following value: 5) -13 div 6

-3 Starting with -13, 6 is added 3 times until the result yields a number in the range from 0 through 5. -13 + 3 · 6 = 5 -13 = -3 · 6 + 5

3.4.1: Recurrence relations Given the definition of a sequence fn whose domain is the set of all non-negative integers: f0 = 4 fn = −5 + f(n − 1) for n≥1 f2 =

-6

2.18.3: An execution of the iterative algorithm for fast exponentiation. Consider the algorithm for iterative fast exponentiation on input x = 3 and y = 13. 1) What is the binary representation of 13? 1011 1101 101 2) The loop executes 4 times on input y = 13. Which best describes the state of the algorithm at the beginning of each iteration of the loop? Iteration 1: (r mod 2) = 1 Iteration 2: (r mod 2) = 0 Iteration 3: (r mod 2) = 1 Iteration 4: (r mod 2) = 1 Iteration 1: (r mod 2) = 1 Iteration 2: (r mod 2) = 1 Iteration 3: (r mod 2) = 0 Iteration 4: (r mod 2) = 1 3) The loop executes 4 times on input y = 13. Which best describes the state of the algorithm at the beginning of each iteration of the loop? Iteration 1: s = x Iteration 2: s = x^2 Iteration 3: s = x^3 Iteration 4: s = x^4 Iteration 1: s = x Iteration 2: s = x^2 Iteration 3: s = x^4 Iteration 4: s = x^8 4) What is the value of the output p at the end of the algorithm? x · x^2 · x^8 x · x^4 · x^8

1) (1101)2 = 2^3 + 2^2 + 2^0 = 13. (the first 2 is subtext) 2) The value of (r mod 2) in each iteration are the bits in the binary representation of y in reverse order. 3) The variable s is squared in each iteration, so if s is a power of x, the exponent doubles each iteration. 4) The initial value for the variable is p = 1. p is multiplied by the current value of s in each iteration in which (r mod 2) = 1. (r mod 2) = 1 during iterations 1, 3, and 4. Therefore the output is x · x^4 · x^8.

3.17.2: How many applications of the recursive rule to build a perfect binary tree? How many recursive steps need to be applied in order to obtain the following perfect binary trees? Need image - do problem directly on course material

1) 0 This tree is given in the basis. Therefore no recursive steps need to be applied. 2) 2 A single vertex is given in the basis. One rule is applied to get a tree with three vertices. One more recursive rule is applied to get the tree shown above.

4.3.2: Applying the product rule: Counting burrito selections A burrito stand sells burritos with different choices of stuffing. The set of choices for each category are: Meats choices = {chicken, beef, pork} Bean choices = {black, pinto} Salsa choices = {mild, medium, hot} 1) If every burrito has meat, beans, and salsa, then how many possible burrito combinations are there? 2) Suppose that the customer can substitute grilled veggies for the meat. Now how many selections are there? 3) Now suppose that the burrito stand introduces a choice between plain flour or whole wheat tortillas? The option to substitute veggies instead of a meat is still available as well. Now how many selections are there?

1) 18 A burrito selection is described by a triple of the form:(meat choice, bean choice, salsa choice). The number of selections is:|meat| · |bean| · |salsa| = 3 · 2 · 3 = 18 2) 24 The set of choices for the filling is now {chicken, beef, pork, veggies}.A burrito selection is described by a triple of the form: (filling choice, bean choice, salsa choice). The number of selections is:|filling| · |bean| · |salsa| = 4 · 2 · 3 = 24 3) 48 A burrito selection is described by a 4-tuple of the form: (tortilla choice, filling choice, bean choice, salsa choice). The number of selections is:|tortilla| · |filling| · |bean| · |salsa| = 2 · 4 · 2 · 3 = 48

2.19.1: An execution of the iterative algorithm for fast modular exponentiation Consider the algorithm for iterative fast exponentiation on input x = 3, y = 13, and n = 7. The mod operations are not applied to the variable r. For exponent y = 13, (r mod 2) = 1 at the beginning of iterations 1, 3, and 4. 1) At the beginning of the first iteration s = x = 3. What is the value of s at the beginning of the second iteration? 2) What is the value of s at the beginning of the third iteration? 3) What is the value of s at the beginning of the fourth iteration? 4) Starting with p = 1, the value for p is multiplied by s mod 7 in each iteration in which (r mod 2) = 1. What is the final value for p?

1) 2 During the first iteration, s := s^2 mod 7 = 3^2 mod 7 = 2 2) 4 At the beginning of the second iteration, s = 2. During the second iteration, s := s^2 mod 7 = 2^2 mod 7 = 4. 3) 2 At the beginning of the third iteration, s = 4. During the third iteration, s := s^2 mod 7 = 4^2 mod 7 = 2. 4) 3 (r mod 2) = 1 during iterations 1, 3, and 4. The value of s at the beginning of iterations 1, 3, and 4 are 3, 4, and 2. The final value for p is3 · 4 · 2 mod 7 = 24 mod 7 = 3.

2.22.5: Simple encryption scheme. In the questions below, let N = 79 and k = 43. Use the simple cryptosystem defined above. 1) Encrypt the plaintext m = 62. 2) Decrypt the ciphertext c = 26. 3) Decrypt the ciphertext c = 12.

1) 26 c = (m + k) mod N = (62 + 43) mod 79 = 26. 2) 62 m = (c - k) mod N = (26 - 43) mod 79 = 62.Note that 62 was the original plaintext from the previous question, and 26 was the ciphertext. 3) 48 m = (c - k) mod N = (12 - 43) mod 79 = 48.

2.23.4: Encrypting plaintext into ciphertext using RSA Given the public key N = 1829 and e = 859, find the ciphertext c for each letter using the ASCII alphabet. "N" = 78 and "O" = 79 1) "N" 2) "O"

1) 498 Using the ASCII table, "N" gives the plaintext m = 78. Thus, c = m^e mod N = 78^859 mod 1829 = 498 2) 737 Using the ASCII table, "O" gives the plaintext m = 79. Thus, c = m^e mod N = 79^859 mod 1829 = 737

4.5.2: Counting selections of officers by the generalized product rule 1) How many ways are there to select the class officers? 2) Now suppose that there are five girls and five boys in the club. How many ways are there to elect the officers if the president is a girl? 3) Again suppose that there are five girls and five boys in the club. How many ways are there to elect the officers if the president is a girl and the VP is a boy?

1) 5040 10 choices for Pres.After Pres chosen, 9 choices for VP. After Pres, VP chosen, 8 choices for Treas. After Pres, VP, Treas chosen, 7 choices for Sec. 10 × 9 × 8 × 7 = 5040 2) 2520 5 girls to choose from for Pres. After Pres chosen, 9 choices for VP. After Pres, VP chosen, 8 choices for Treas. After Pres, VP, Treas chosen, 7 choices for Sec. 5 × 9 × 8 × 7 = 2520 3) 1400 5 girls to choose from for Pres. 5 boys to choose from for VP. After Pres, VP chosen, 8 choices for Treas. After Pres, VP, Treas chosen, 7 choices for Sec. 5 × 5 × 8 × 7 = 1400

4.9.2: Selecting subsets or permutations Provide solutions in the form "P(n, r)" or "n choose r" (e.g. P(8, 3) or 8 choose 3). 1) Dave swims three times in the week. How many ways are there to plan his workout schedule (i.e. which days he will swim) for a given week? 2) Dave will swim one day, run one day, and bike another day in a week. He does at most one activity on any particular day. How many ways are there for him to select his workout schedule (i.e. which activities he does which days)? 3) The students in a class elect a president, vice president, secretary, and treasurer. There are 30 students in the class and no student can have more than one job. How many different outcomes are there from the election process? 4) A class of 30 students elects four students to serve on a student leadership council. The teacher tallies the votes and only reveals the names of the four students who received the most votes. How many different outcomes are there from the election process?

1) 7 choose 3 A schedule for Dave's workouts consists of the set of three days he will swim (e.g., {Mon, Wed, Sat}). The order in which he selects the three days of the week does not affect the schedule.Therefore, Dave is selecting a subset of 3 days from the 7 days of the week. 2) P(7, 3) First Dave picks his swimming day, then his running day, and then his biking day. Since each activity is different, the order in which he selects the days matters. Therefore the number of selections is P(7, 3). 3) P(30, 4) Select an order in which the class officers are elected: Pres, VP, Treas, Sec. The order in which the students are elected (in addition to which students are elected) is important because the order will determine which student gets which job.Therefore, a sequence of four kids are selected from the 30: (president, vice president, secretary, treasurer). 4) 30 choose 4 The students only learn the names of the four students who are elected. Each student that is elected plays the same role as the others. Therefore, the outcome is just a subset of four students chosen from the class of 30 students.

4.7.3: Computer generated security codes. 1) Can the security code process given facilitate 10,000,000 users? Type 'yes' or 'no' 2) How many users could the security code process given facilitate if the security code were six digits instead of five digits?

1) No No. The number of security codes possible is the number of 5-permutations of twenty four objects. P(24,5) = 24 · 23 · 22 · 21 · 20 = 5,100,480 The number of possible codes is not enough to facilitate 10,000,000 users. 2) 96,909,120 The number of security codes is the number of 6-permutations of twenty four objects. P(24,6) = 24 · 23 · 22 · 21 · 20 · 19= 96909120

3.12.4: Strong induction. Consider again the problem of purchasing cans of juice. Suppose now that juice is sold in 2-packs or 5-packs. Let Q(n) be the statement that it is possible to buy n cans of juice by combining 2-packs and 5-packs. This problem discusses using strong induction to prove that for any n ≥ 4, Q(n) is true. 1) The inductive step will prove that for k ≥ 5, Q(k+1) is true. What is the inductive hypothesis? Q(j) is true for any j = 4, 5, ..., k Q(j) is true for any j = 4, 5, ..., k + 1 Q(j) is true for any j = 5, ..., k + 1 2) The inductive step will prove that for k ≥ 5, Q(k + 1) is true. What part of the inductive hypothesis is used in the proof? Q(k - 2) Q(k - 1) Q(k) 3) In the base case, for which values of n should Q(n) be proven directly? n = 3, n = 4, and n = 5 n = 4 and n = 5 n = 4, n = 5, and n = 6

1) Q(j) is true for any j = 4, 5, ..., k The inductive hypothesis assumes that Q(j) is true for any j less than k + 1 down to the initial value which is 4. 2) Q(k - 1) The proof assumes that k - 1 cans can be purchased by combining 2-packs and 5-packs. Adding one additional 2-pack brings the total to k + 1 as desired. 3) n = 4 and n = 5 The inductive step uses Q(k - 1) to prove Q(k + 1). k - 1 is two less than k + 1. Therefore two consecutive values are required for the base case, starting at n = 4.

3.15.1: Computing the value of functions defined recursively 2) Given the definition of a function h whose domain is the set of all non-negative integers: h(0) = 1 h(n) = (n^2 + 1)⋅h(n − 1) for n ≥ 1 What is h(2)?

10 h(1) = (1^2 + 1) * h(0) = 2 h(2) = (2^2 + 1) * h(1) = 10

Exercise 2.9.1: Estimating the number of primes. (a) Use the prime number theorem to give an approximation for the number of prime numbers in the range 2 through 10,000,000.

10,000,000 = 10^7 The number of prime numbers in the range 2 through 10^7 is approximately 10^7/ln(10^7) ≈ 620421

2.16.2: Conversion to expansion base b 3) Find the binary of 21.

10101 21 mod 2 = 1; Rightmost bit is 1. 21 div 2 = 10 10 mod 2 = 0; Next bit to the left is 0. 10 div 2 = 5 5 mod 2 = 1; Next bit to the left is 1. 5 div 2 = 2 2 mod 2 = 0; Next bit to the left is 0. 2 div 2 = 1 1 mod 2 = 1; Next bit to the left is 1. 1 div 2 = 0

4.8.4: Mapping r-permutations to r-subsets Consider a function that maps 5-permutations from a set S = {1, 2, ..., 20} to 5-subsets from S. The function takes a 5-permutation and removes the ordering on the elements. How many 5-permutations map on to the subset {2, 5, 13, 14, 19}?

120or5! There are 5! ways to order five elements in a subset. Therefore, the function mapping 5-permutations to 5-subsets is k-to-1 fork = 5! = 120

3.6.2: Computing summations Give numerical values for the following summations. 2) j = 0 to 2 ∑ (j + 1) ^2

14 (0 + 1)^2 + (1 + 1)^2 + (2 + 1)^2 = 1^2 + 2^2 + 3^2 = 14

4.7.6: Counting line-ups: Permutations and the product rule A wedding party consisting of a bride, a groom, two bridesmaids, and two groomsmen line up for a photo. How many ways are there for the wedding party to line up so that the bride is next to the groom?

240 First decide whether the bride is to the left or right of the groom (2 choices). Then glue the bride and groom together and there are 5! ways to permute the five items. By the product rule, the number of line-ups with the bride next to the groom is: 2 · 5! = 240

3.7.1: Summations Enter the result of the summation 2) n = 2 to 4 ∑ (3n)

27

Exercise 2.5.2: Congruence modulo n a) Group the numbers from the given set into classes of congruence. That is, put two numbers in the same group if they are equivalent modulo 11. {−57, 17, 108, 0, −110, −93, 1111, 130, 232}

Congruent to 0 modulo 11: 0, -110, 1111 Congruent to 1 modulo 11: 232 Congruent to 6 modulo 11: 17, -93 Congruent to 9 modulo 11: -57, 108, 130

Exercise 2.5.2: Congruence modulo n b) Group the numbers from the given set into classes of congruence. That is, put two numbers in the same group if they are equivalent modulo 13. {−63, -54, -41, 11, 13, 76, 80, 130, 132, 137}

Congruent to 0 modulo 13: 13, 130 Congruent to 2 modulo 13: -63, 80, 132 Congruent to 7 modulo 13: 137 Congruent to 11 modulo 13: -54, -41, 11, 76

3.12.2: The principle of strong induction with general range for the base case 1) Consider an inductive proof in which the inductive step is: For all k ≥ 6, if P(3), P(4),...,P(k) are all true, then P(k + 1) is true. What facts must be proven in the base case? P(3) only P(3), P(4), and P(5) P(3), P(4), P(5), and P(6)

P(3), P(4), P(5), and P(6) The base case must show that the inductive hypothesis is true for the smallest value for k. When k = 6, the inductive hypothesis is that P(3), P(4), P(5), and P(6) are true.

Exercise 3.18.2: Recursively computing the product of two integers. (a) Give a recursive algorithm that takes as input two non-negative integers x and y and returns the product of x and y. The only arithmetic operations your algorithm can perform are addition or subtraction. Your algorithm should have no loops.

Product(x, y) Input: Two non-negative integers, x and y Output: x * y If (y = 0), Return( 0 ) p := Product(x, y - 1). // The recursive call Return( p + x )

Exercise 3.13.1: Proofs by strong induction - combining stamps Prove each of the following statements using strong induction. (a) Prove that any amount of postage worth 8 cents or more can be made from 3-cent or 5-cent stamps.

Proof. By induction on the amount of postage. Base case: 8 cents: use a 3-cent and a 5-cent stamp. 9 cents: use three 3-cent stamps. 10 cents: use two 5-cent stamps. Inductive step: Assume that for k ≥ 10, it is possible to make j cents worth of postage using only 3-cent and 5-cent stamps for any j in the range from 8 through k. Show that it is possible to make k + 1 cents worth of postage using only 3-cent and 5-cent stamps. Since k ≥ 10, then k - 2 ≥ 8. Therefore k - 2 falls in the range from 8 through k, and by the inductive hypothesis, it is possible to make k - 2 cents worth of stamps using only 3-cent and 5-cent stamps. By adding one 3-cent stamp, the amount of postage becomes (k - 2) + 3 = k + 1. Therefore, it is possible to make k + 1 cents worth of postage using only 3-cent and 5-cent stamps.

Exercise 3.13.3: Proof by the well-ordering principle Prove each of the following statements using the principle of well-ordering. b) Prove that any amount of postage worth 8 cents or more can be made from 3-cent or 5-cent stamps.

Proof. Let S be the set of all integers n, such that n ≥ 8 and it is not possible to make n cents worth of stamps from 3-cent and 5-cent stamps. By the well-ordering principle, S has a smallest element m. Since any integer must be at least 8 to be in S, m ≥ 8. Also by definition of m, it is impossible to make m cents worth of stamps and for any j in the range 8 through m-1, it is possible to make j cents worth of stamps. For each of the following cases, we obtain a contradiction: m = 8: a 3-cent and a 5-cent stamp makes 8 cents worth of stamps. m = 9: three 3-cent stamps makes 9 cents worth of stamps. m = 10: two 5-cent stamps makes 10 cents worth of stamps. The last case is that m ≥ 11. Since m ≥ 11, m - 3 ≥ 8. Therefore the value m - 3 lies in the range from 8 through m - 1 and by definition of m, it is possible to make m - 3 cents worth of stamps using only 3-cent and 5-cent stamps. By adding one more 3-cent stamps to a collection of stamps worth m - 3 cents, the collection of stamps is worth m cents. Therefore, it is possible to make m cents worth of stamps using only 3-cent and 5-cent stamps.

4.8.1: Counting subsets of bit strings See course material

See course material

Exercise 3.18.3: Recursively computing the set of all binary strings of a fixed length a) Give a recursive algorithm that takes as input a non-negative integer n and returns a set containing all binary strings of length n. Here are the operations on strings and sets you can use: - Initialize an empty set S. - Add a string x to S. - y := 0x. This operation adds a 0 to the beginning of string x and assigns the result to string y. - y := 1x. This operation adds a 1 to the beginning of string x and assigns the result to string y. - return(S) - A looping structure that performs an operation on every string in a set S: for every x in S, perform some sequence of steps with string x.

StringSet(n) Input: A non-negative integer n Output: A set containing all binary strings of length n. S := ∅ If (n = 0) Add λ to S Return( S ) End-if T := StringSet(n - 1) // The recursive call For every x ∈ T y := 0x Add y to S y := 1x Add y to S End-for Return( S )

2.16.3: Number of digits base b In the questions below, assume that numbers are expressed without any leading zeroes. 3) How many digits are required to express the binary expansion of 2^55? 56 55

The binary expansion of 2^55 is a 1 followed by 55 0's.

4.18 The inclusion-exclusion with three sets: course enrollments A computer science department offers three lower division classes in a given quarter: discrete math, digital logic, and introductory programming. The department would like to know the number of students enrolled in any of the three courses. Let M be the set of students enrolled in discrete math, L be the set of students enrolled in digital logic, and P the set of students enrolled in introductory programming. Here are numbers for enrollments in the courses: |M| = 112 students enrolled in discrete math. |L| = 138 students enrolled in digital logic. |P| = 142 students enrolled in introductory programming. |M ∩ L| = 25 students enrolled in both discrete math and digital logic. |L ∩ P| = 17 students enrolled in both digital logic and introductory programming. |M ∩ P| = 32 students enrolled in both introductory programming and discrete math. |M ∩ L ∩ P| =7 students are enrolled in all three classes.

The total number of students enrolled in any of the three courses is: |M ∪ L ∪ P| = |M|+ |L| + |P| - |M ∩ L| - |L ∩ P| - |M ∩ P| + |M ∩ L ∩ P| = 112 + 138 + 142 - 25 - 17 - 32 + 7 = 325

Exercise 4.5.2: Strings with no repetitions. (a) How many strings are there over the set {a, b, c} that have length 10 in which no two consecutive characters are the same? For example, the string "abcbcbabcb" would count and the strings "abbbcbabcb" and "aacbcbabcb" would not count.

There are three choices for the first character. There are two choices in selecting each of the next 9 characters from left to right because each character can be any element from the set {a, b, c}, except the one that was chosen to be the previous character. Putting together all the choices by the generalized product rule, the number of strings of length 10 that do not have two consecutive characters that are the same is 3 * 29^.

1.14.1: Big-O True or False 6) A O (n) algorithm is Θ (1).

This may or may not be true depending on the algorithm. In the general case it is false. If an algorithm is Θ(1), then it certainly is O(n). But if it is O(n) then it may not be Θ(1). For example, a Θ(n) algorithm is O(n) but not Θ(1).

1.14.1: Big-O True or False 3) A Θ (n^2) algorithm is O (n^3).

True As n^3 is worse than n^2, this is true.

Exercise 3.17.1: Devising recursive definitions for sets of strings Let A = {a, b} a) Give a recursive definition for A*. b) The set A+ is the set of strings over the alphabet {a, b} of length at least 1. That is A+ = A* - {λ}. Give a recursive definition for A+. c) Let S be the set of all strings from A* in which there is no b before an a. For example, the strings λ, aa, bbb, and aabbbb all belong to S, but aabab ∉ S. Give a recursive definition for the set S. (Hint: a recursive rule can concatenate characters at the beginning or the end of a string.)

a) Base case: λ ∈ A* Recursive rule: if x ∈ A* then, xa ∈ A* xb ∈ A* b) Base case: a ∈ A+ and b ∈ A+ Recursive rule: if x ∈ A+ then, xa ∈ A+ xb ∈ A+ c) Base case: λ ∈ S Recursive rule: if x ∈ S then, ax ∈ S xb ∈ S

Exercise 2.24.1: Encrypting and decrypting a message with RSA. In this problem, we will implement the RSA algorithm to encrypt and decrypt the message "HI". For this exercise, you may want to use a calculator that can compute the mod function. a) Use the scheme used in your text to convert the message "HI" into an integer. Call the integer m. b) Set the primes p and q as follows: p = 43 and q = 79. What are the values for N and φ? c) The value for e is chosen to be 29. Use Euclid's algorithm to verify that e and φ are relatively prime and to find d, the multiplicative inverse of e mod φ. d) Encrypt the message m by computing m^e mod N e) The result of the previous question is the ciphertext c that is transmitted. To decrypt the message, compute c^d mod N. f) Verify that the decrypted message is the same as m. Convert m back into a text message.

a) H → 08, I → 09. m = 0809 = 809 b) N = 43·79 = 3397φ = (43 - 1)(79 - 1) = 42·78 = 3276 c) 3276 29 28 1 3276 mod 29 = 28 29 mod 28 = 1 The equations for substitution are: 1 = 29 - 28 28 = 3276 - 112·29 Substitute (3276 - 112·29) for 28 into the equation 1 = 29 - 28 1 = 29 - (3276 - 112·29) = 113·29 - 3276 gcd(3276, 29) = 1 = 113·29 - 3276 The coefficient of 29 in the equation above is 113. The multiplicative inverse of 29 mod 3276 is 113. Check: 29·113 mod 3276 = 3277 mod 3276 = 1 d = 113 d) ciphertext = 809^29 mod 3397 809^2^0 mod 3397 = 809^1 mod 3397 = 809 mod 3397 = 809 809^2^1 mod 3397 = 809^2 mod 3397 = 654481 mod 3397 = 2257 809^2^2 mod 3397 = 2257^2 mod 3397 = 5094049 mod 3397 = 1946 809^2^3 mod 3397 = 1946^2 mod 3397 = 3786916 mod 3397 = 2658 809^2^4 mod 3397 = 2658^2 mod 3397 = 7064964 mod 3397 = 2601 29 = (11101)2 (2 is subtext) 809^29 mod 3397 = (809^2^4 mod 3397) * (809^2^3 mod 3397) * (809^2^2 mod 3397) * (809^2^0 mod 3397) mod 3397 = (2601 * 2658 *1946 * 809) mod 3397 = 336 ciphertext = 336 e) Message = 336^113 mod 3397 336^2^0 mod 3397 = 336^1 mod 3397 = 336 mod 3397 = 336 336^2^1 mod 3397 = 336^2 mod 3397 = 112896 mod 3397 = 795 336^2^2 mod 3397 = 795^2 mod 3397 = 632025 mod 3397 = 183 336^2^3 mod 3397 = 183^2 mod 3397 = 33489 mod 3397 = 2916 336^2^4 mod 3397 = 2916^2 mod 3397 = 8503056 mod 3397 = 365 336^2^5 mod 3397 = 365^2 mod 3397 = 133225 mod 3397 = 742 336^2^6 mod 3397 = 742^2 mod 3397 = 550564 mod 3397 = 250 113 = (1110001)2 (2 is subtext) 336^113 mod 3397 = (336^2^6 mod 3397) * (336^2^5 mod 3397) * (336^2^4 mod 3397) * (336^2^0 mod 3397) mod 3397 = (250·742·365·336) mod 3397 = 809 Message = 809 f) The decrypted message is 809, the original value for m. 809 → 08 09 → HI

Exercise 4.3.1: Counting passwords made up of letters, digits, and special characters Consider the following definitions for sets of characters: Digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } Letters = { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z } Special characters = { *, &, $, # } Compute the number of passwords that satisfy the given constraints. (a) Strings of length 6. Characters can be special characters, digits, or letters. (b) Strings of length 7, 8, or 9. Characters can be special characters, digits, or letters. (c) Strings of length 7, 8, or 9. Characters can be special characters, digits, or letters. The first character cannot be a letter.

a) Let D be the set of digits, L the set of letters, and S the set of special characters. The three sets are mutually disjoint, so the total number of characters is |D ∪ L ∪ S| = |D| + |L| + |S| = 10 + 26 + 4 = 40 Each of the six characters in the string can be any of the 40 characters, so there are a total of 40^6 strings of length 6. b) The sets of strings of length 7, 8, and 9 are mutually disjoint. The number of strings of length j with no other restrictions on the characters is 40^j. Therefore, by the sum rule, the total number of strings of length 7, 8, or 9 is: 40^7 + 40^8 + 40^9 c) In selecting a string of length j in which the first character is not a letter, there are 14 choices for the first character because there are 4 + 10 digits and special characters. There are 40 choices for each of the remaining characters. Putting the choices together by the product rule, the total number of strings of length j in which the first character is not a letter is 14·40^(j - 1). Sets of strings of length 7, 8, and 9 are mutually disjoint. Therefore, by the sum rule, the number of strings of length 7, 8, or 9 which do not start with a letter is: 14·40^6 + 14·40^7 + 14·40^8 = 14(40^6 + 40^7 + 40^8)

Exercise 2.22.1: Converting text to numerical messages. One way to convert text messages to numerical values is to use the ASCII (American Standard Code for Information Interchange) character encoding scheme. In ASCII, a character is represented by a byte (8 bits) code. To convert a text message to a numerical value, concatenate together the codes for each character in the message. The resulting binary string is interpreted as an integer written in binary. The table below gives the ASCII codes for a few characters. Use the table to convert each word into an integer. Character ASCII code P 01010000 s 01110011 w 01110111 d 01100100 I 01001001 N 01001110 (a) Pswd b) PIN

a) Pswd → 01010000 01110011 01110111 01100100 (1010000011100110111011101100100)2 = 1349744484 b) PIN → 01010000 01001001 01001110 (10100000100100101001110)2 = 5261646 (The 2s are subtext)

Exercise 4.9.1: Selecting students for jobs. (a) A teacher selects 4 students from her class of 37 to work together on a project. How many ways are there for her to select the students? (b) A teacher selects students from her class of 37 students to do 4 different jobs in the classroom: pick up homework, hand out permission slips, staple worksheets, and organize the classroom library. Each job is performed by exactly one student in the class and no student can get more than one job. How many ways are there for her to select students and assign them to the jobs?

a) There are (37 choose 4) ways to select a subset of 4 students from a set of 37 students. The order in which the students are chosen does not matter, just the subset of 4 students selected. b) Suppose that the teacher assigns each selected student to the jobs in order. That is, the first student selected is assigned to pick up homework, the second student will hand out permission slips, the third student will staple worksheets, and the fourth student will organize the classroom library. The order in which the students are selected is important because the order determines which student gets which job. The number of ways to select an ordered list of four students from a set of 37 with no repetitions is P(37, 4).

Exercise 4.5.1: Counting passwords without repeating characters Consider the following definitions for sets of characters: Digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } Letters = { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z } Special characters = { *, &, $, # } Compute the number of passwords that satisfy the given constraints. (a) Strings of length 6. Characters can be special characters, digits, or letters, with no repeated characters. (b) Strings of length 6. Characters can be special characters, digits, or letters, with no repeated characters. The first character can not be a special character.

a) There are a total of 40 characters. There are 40 possibilities for the first character. There are 39 for the second character (because the second character can not match the first character), then 38 choices for the third character, etc. The total number of length 6 strings with no repetitions is: 40 · 39 · 38 · 37 · 36 · 35 b) There are 36 characters that are not special characters. Therefore there are 36 choices for the first character. Once the first character is chosen, there are 39 choices for the second character because the second character can be any character, except the character that was chosen to be first. For the next character, there are 38 choices, etc. The total number of length 6 strings with no repetitions in which the first character is not a special character is: 36 · 39 · 38 · 37 · 36 · 35

3.6.3: Removing a final term in a sum. Select the choice whose value is equal to the given sum. 1) j = 0 to n ∑ 2^j j = 0 to (n - 1) ∑ 2^j + 2^j j = 0 to (n - 1) ∑ 2^j + 2^(n - 1) j = 0 to (n - 1) ∑ 2^j + 2^n j = 0 to n ∑ 2^j + 2^n

j = 0 to (n - 1) ∑ 2^j + 2^n The last term in the sum is 2n. Since that term is now outside the sum, the upper limit is n - 1.

1.6.2: While-loops product := 1 count := 5 While ( count > 0 ) product := product⋅count count := count - 2 End-while 1) What is the value of product after the second iteration? 2) How many iterations will the while-loop execute? 3) What is the final value for product?

1) 15 In the first iteration, count = 5. In the second iteration, count = 3. 5⋅3 = 15 2) 3 count = 5, 3, 1. Three iterations 3) 15 product = 5⋅3⋅1 = 15

1.7.3: Nested loops - example 2 Consider the following pseudocode fragment: count := 0 For i = 1 to 3 For j = i+1 to 4 count := count + i ⋅ j End-for End-for 1) When i = 2, how many times does the inner loop iterate? 2) How many times is the variable count increased? 3) What is the final value of count?

1) 2 The initial value of j is i + 1. The final value of j is 4. j = 3, 4. 2 iterations. 2) 6 When i = 1, j = 2, 3, 4. When i = 2, j = 3, 4. When i = 3, j = 4. A total of 6 iterations. 3) 35 1·(2 + 3 + 4) + 2·(3 + 4) + 3·(4) = 35

2.10.2: Euclid's Algorithm. Consider an Euclid's algorithm with input integers y = 156 and x = 54. 1) What is the value of r at the beginning of the first iteration of the loop in Euclid's algorithm? 2) What is the value of r at the beginning of the second iteration of the loop in Euclid's algorithm? 3) What is the value of r after the second iteration of the loop in Euclid's algorithm? 4) How many times does the loop in Euclid's algorithm execute on input 156 and 54? 5) What is the gcd of 156 and 54?

1) 48 r = 156 mod 54 = 48 2) 6 x = 54, y = 48, r = 54 mod 48 = 6 3) 0 x = 48, y = 6, r = 48 mod 6 = 0 4) 2 After the second iteration of the loop, r = 0, so the loop executes two times. 5) 6 After the last iteration of the loop, y = 54, x = 6, and r = 0. Therefore the gcd is x = 6.

2.15.1: Hexadecimal expansions 2) What is the binary expansion of (2F)16? Omit the leading zeroes in your answer. (16 is subtext)

101111 0010 corresponds to 2 and 1111 corresponds to F. Put 0010 and 1111 together to get 00101111 and drop the leading zeroes to get 101111.

2.16.2: Conversion to expansion base b 2) Find the expansion base 7 of 52.

103 52 mod 7 = 3; Rightmost digit is 3. 52 div 7 = 7 7 mod 7 = 0; Next digit to the left is 0. 7 div 7 = 1 1 mod 7 = 1; Next digit to the left is 1. 1 div 7 = 0

Exercise 2.5.1: Computing using modular arithmetic. Compute the value of the following expression: e) 17^12 mod 3

17^12 mod 3 = (17 mod 3)^12 mod 3 = 2^12 mod 3 = (2^6 mod 3)(2^6 mod 3) mod 3 = (64 mod 3)(64 mod 3) mod 3 = 1 · 1 mod 3 = 1

Exercise 2.14.1: Converting from non-decimal bases to decimal. Compute the decimal representation for each of the following numbers. c) (120121)3 (3 is subtext)

1·3^5 + 2·3^4 + 1·3^2 + 2·3^1 + 1·3^0 = 243 + 2·81 + 9 + 2·3 + 1 = 421

1.4.3: If-else-statement 2) What is the value of abs after the following lines of code are run? x := -2 If ( x > 0 ) abs := x Else abs := -x End-if

2 The condition ( x > 0 ) evaluates to false because the value of x is -2. The line abs := x is skipped and the line abs := -x is executed. Therefore the final value of abs is -x, which is -(-2) = 2.

1.4.3: If-else-statement 1) What is the value of abs after the following lines of code are run? x := 2 If ( x > 0 ) abs := x Else abs := -x End-if

2 The condition ( x > 0 ) evaluates to true because the value of x is 2. The line abs := x is executed and the line abs := -x is skipped. Therefore the final value of abs is 2.

Exercise 2.8.1: Computing using prime factorizations. Some numbers and their prime factorizations are given below. 140 = 2^2 · 5 · 7 175 = 5^2 · 7 532 = 2^2 · 7 · 19 648 = 2^3 · 3^4 1078 = 2 · 7^2 · 11 1083 = 3 · 19^2 15435 = 3^2 · 5 · 7^3 25480 = 2^3 · 5 · 7^2 ·13 Use these prime factorizations to compute the following quantities. d) 25480/140

2 * 7 * 13 = 182

Exercise 2.8.1: Computing using prime factorizations. Some numbers and their prime factorizations are given below. 140 = 2^2 · 5 · 7 175 = 5^2 · 7 532 = 2^2 · 7 · 19 648 = 2^3 · 3^4 1078 = 2 · 7^2 · 11 1083 = 3 · 19^2 15435 = 3^2 · 5 · 7^3 25480 = 2^3 · 5 · 7^2 ·13 Use these prime factorizations to compute the following quantities. a) gcd(1078, 25480)

2 * 7^2 = 98

2.16.2: Conversion to expansion base b 1) Find the expansion base 5 of 57.

212 57 mod 5 = 2; Rightmost digit is 2. 57 div 5 = 11 11 mod 5 = 1; Next digit to the left is 1. 11 div 5 = 2 2 mod 5 = 2; Next digit to the left is 2. 2 div 5 = 0

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: f) 215 div 7

215 = 30·7 + 5, so 215 div 7 = 30.

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: e) 215 mod 7

215 = 30·7 + 5, so 215 mod 7 = 5.

2.12.2: Find the multiplicative inverse using the results of the Extended Euclidean Algorithm 2) Euclid's algorithm returns gcd(14, 33) = 1 = 3 · 33 - 7 · 14. What is the multiplicative inverse of 14 in Z33? (the 33 is subscript)

26 -7 is the coefficient of 14 in the equation:1 = 3 · 33 - 7 · 14 The inverse of 14 in Z33 is (c mod 33), where c is the coefficient of 14: -7 mod 33 = 26

2.12.2: Find the multiplicative inverse using the results of the Extended Euclidean Algorithm 1) Euclid's algorithm returns gcd(61, 54) = 1 = 26 · 54 - 23 · 61 What is the multiplicative inverse of 54 mod 61?

26 26 is the coefficient of 54 in the equation:1 = 26 · 54 - 23 · 61 The inverse of 54 mod 61 is (c mod 61), where c is the coefficient of 54: 26 mod 61 = 26

Exercise 2.8.1: Computing using prime factorizations. Some numbers and their prime factorizations are given below. 140 = 2^2 · 5 · 7 175 = 5^2 · 7 532 = 2^2 · 7 · 19 648 = 2^3 · 3^4 1078 = 2 · 7^2 · 11 1083 = 3 · 19^2 15435 = 3^2 · 5 · 7^3 25480 = 2^3 · 5 · 7^2 ·13 Use these prime factorizations to compute the following quantities. b) lcm(175, 25480)

2^3 * 5^2 * 7^2 * 13 = 127400

Exercise 2.8.1: Computing using prime factorizations. Some numbers and their prime factorizations are given below. 140 = 2^2 · 5 · 7 175 = 5^2 · 7 532 = 2^2 · 7 · 19 648 = 2^3 · 3^4 1078 = 2 · 7^2 · 11 1083 = 3 · 19^2 15435 = 3^2 · 5 · 7^3 25480 = 2^3 · 5 · 7^2 ·13 Use these prime factorizations to compute the following quantities. c) 175 * 25480

2^3 * 5^3 * 7^3 * 13 = 4459000

Exercise 1.13.1: Asymptotic function b) f(n) = 2^n + 12

2^n

Exercise 2.3.1: Computing div and mod Compute the value of the following expressions: a) 344 mod 5

344 = 68·5 + 4, so 344 mod 5 = 4.

Exercise 2.5.1: Computing using modular arithmetic. Compute the value of the following expression: a) 38^7 mod 3

38^7 mod 3 = (38 mod 3)^7 mod 3 = (2^7) mod 3 = 128 mod 3 = 2

2.3.3: Computing div and mod Compute the following value: 1) 17 mod 6

5 The answer is the remainder of 17 divided by 6. 17 = 2 · 6 + 5

2.15.1: Hexadecimal expansions 3) What is the hexadecimal number that corresponds to 1011101?

5D The rightmost four bits, 1101, corresponds to D. The remaining bits on the left are 101. Add a leading zero to 101 on the left to get 0101 which corresponds to 5. Therefore 1011101 corresponds to a hexadecimal expansion of 5D.

2.9.1: Brute force factoring. 1) Suppose that the slightly better brute force algorithm for factoring is given the number 653117 as input. How many numbers would the algorithm have to check to either find a factor or determine that the input is prime? (653117 happens to be a prime number). 808 234497 19

808 The algorithm can stop checking numbers when it reaches x=⌊squareroot (653117)⌋= 808. Since 653117 is prime, the algorithm will not find a factor before reaching x = 808.

Exercise 2.12.1: Computing a multiplicative inverse For each x and n, find the multiplicative inverse mod n of x. Your answer should be an integer s in the range 0 through n - 1. Check your solution by verifying that sx mod n = 1. b) x = 77, n = 52

From the solution to the previous problem: gcd(77, 52) = 1 = 25·77 - 37·52 The coefficient of 77 in the equation above is 25. The multiplicative inverse of 77 mod 52 is (25 mod 52) = 25. Check: 77·25 mod 52 = 1925 mod 52 = 1

1.14.1: Big-O True or False 1) A Θ (n) algorithm is O (n)

True This is as true as our original program was theta (n). You can achieve big O (n) without altering your program at all.

1.13.1: Asymptotic growth Find the asymptotic behavior for the given functions by dropping the constant factors and by keeping the terms that grow the fastest. Type exponents as: ^# Ex: n^2 5) f(n) = n + squareroot(n)

n In this example, n grows faster than \sqrt{n} as n increases.

1.13.1: Asymptotic growth Find the asymptotic behavior for the given functions by dropping the constant factors and by keeping the terms that grow the fastest. Type exponents as: ^# Ex: n^2 3) f(n) = n^2 + 3n + 112

n^2 In this example n^2 grows larger than 3n for sufficiently large n, so the n^2 term impacts the growth of the function the most as n grows.


Conjuntos de estudio relacionados

Personality Psych (Stein) Quiz Questions & Study Guide

View Set

PEDS Exam 2: Immunizations, Communicable Diseases, and Skin Alterations Quiz

View Set

IBUS International Business Law Chapter 11

View Set

BUSN331 Managerial Accounting Ch 10-13

View Set

Exercises 1-1 to 1-3 and Tables 1-1 to 1-4

View Set