Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
D E PA R T M E N T O F C O M P U T E R S C I E N C E S COLLEGE OF ENGINEERING FLORIDA TECH DISCRETE M AT H E M AT I C S HOMEWORK WILLIAM SHOAFF FA L L 2 0 1 3 Problems Sets 5 Overview 7 Logic Sets 11 Sequences 13 Recursion 15 19 Summations Induction 21 Relations 23 Functions 25 Numbering & Naming Systems Combinatorics & Number Theory Proofs Index 35 39 27 31 Overview Below is a collection of problems that relate to topics in discrete mathematics. I encourage you to solve some of them. If you find, after a sincere effort, that you need hints to find a solution or that you simply need the answer to be explained to you, then use the time honored method: Ask an oracle, perhaps Pythia, (a nondeterministic Turing machines)1 to provides the answer, and you, the validator (a deterministic Turing machine)2 checks it is correct. You can choose to earn extra credit by solving these problems, but there are rules. 1. You must start earning extra credit before Monday, October 15. In particular, you cannot seek extra credit toward the end of the semester once you’ve realized you will almost certainly not earn the grade you seek. 2. You must present a nicely written solution to the problem. For extra, extra credit learn to write mathematics in a document processing system such as LATEX or (sigh) Word. A system that can nicely typeset mathematical, and other, notations. 3. You must explain your solution to the instructor’s satisfaction in a solo interview. Schedule an interview through the department’s administrative assistant: Mrs. Karen Brown. Students seek extra credit for many reasons: • To improve their grade • To learn advanced topics • For future recommendation from their instructor • And there may be other reasons of which I have not thought. There are many types of students: To many to enumerate, but let me address the major classes • To those who want to learn advanced topics, demonstrate your understanding as basic topics by solving these homework problems. You will earn an A in the course. 1 I am not an oracle. I cannot always give the right answer to your questions. Some questions have no answers. I have not mastered the answers to many questions that do have answers. 2 I don’t mean to imply anyone is deterministic, I don’t believe that. I am just trying to describe computational ideas in anthropomorphic terms. 6 department of computer sciences college of engineering florida tech • To those who want to improve their grade, You can advance at most one letter grade by solving these extra credit problems. In fact, you can’t advance from low X to Y, unless your extra credit work is impressive and you own it: Don’t fall behind. • To those who want future recommedations: Talk to your instructor frequently Letter Grade Calculation The letter grade you receive in this course is based on the work you demonstrate in class. Your total score can be calculated by the formula S = n−1 X wk sk k =0 where the non-negative weights wk sum to 1 and the values sk are scores on your efforts, k = 0, 1, . . . , n − 1. There are ten homework assignments and one final examination; therefore n = 11. These are summarized below. Each assignment will have a maximum score of 100. Therefore your score will be some number from 0 to 100. I expect to use the range of scores below to determine final letter grades. A = 90 – 100 B = 80 – 89 C = 70 – 79 D = 60 – 69 F = 0 – 59 However, I will compute some statistics to help me understand the achievement of the class. I will use: • The mean (average) score µ over all students in the class µ= m−1 1 X Sj m j=0 where there are m students and student j scored S j points. • The standard deviation σ of all scores s Pm−1 j=0 (S j σ= − µ)2 m • Your z score S −µ σ which measures how many standard deviations your score S is above of below the mean µ. z= • Your C + score C + = 10z + 79 which assumes an average student will be at the C+/B- cutoff. • The median m that partitions the scores into two equal-sized groups: Those below m and those above m. Logic 1. It is interesting to think of False =0 and True =1 as numerical values rather than Boolean values. When you do, addition can implemented by the rules 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 10. Full addition requires carry-in and carry-out bits. In general, you must be able to add two terms (bits) a and b and a carry-in bit cin to compute a sum bit s and a a carry-out bit cout . (a) Complete the truth table below that describes a full adder: The Boolean function that adds two bits a, b, and a carry-in bit cin to produce a sum bit s and a carry-out bit cout . Input Output a b cin s 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 cout (b) Find a Boolean expression that represents the sum function. (c) Find a Boolean expression that represents the carry-out function. (d) Explain how you would use Boolean operations to add two 8-bit strings a = a7 a6 · · · a1 a0 and b = b7 b6 · · · b1 b0 together with a sequence of carries c = c7 c6 · · · c1 c0 to product a sum s = s7 s6 · · · s1 s0 and carry out bit c8 . 2. In general, a Boolean function maps an n-tuple of Boolean values to an m-tuple of Boolean values, as in problem 1 where 3 values are mapped to 2. How many different n-input, m-output Boolean functions are there? 8 discrete mathematics homework 3. A quasi-Boolean function maps an n-tuple ( p0 , p1 , . . . , pn−1 ) of Boolean values to one of three values: 0 = (False), 0.5 = (Maybe) or 1 = (True). (a) How many different n-variable quasi-Boolean functions are there? (b) If you allow quasi-Boolean (0, 1/2, 1) input as well, How many different n variable functions are there? 4. Use the laws of Boolean algebra: commutative, associative, distributive, De Morgan’s, etc., and the shorthand p → q for ¬p ∨ q, to prove the following equivalences. (a) p → ( q → r ) ≡ ( p ∧ q ) → r (b) ( p ∧ q ) → r ≡ ( p → r ) ∨ ( q → r ) 5. I once wrote some code that looked like this: bool f(bool p, bool q, bool r) { if (p) { if (q) { return r; } return true; } return true; } One student suggested this refactoring: bool f(bool p, bool q, bool r) { if (p && q) { return r; } return true } Another suggested the code should be written as: bool f(bool p, bool q, bool r) { if (p) { return r; } if (q) { return r; } return true; Are the code fragments functionally equivalent? Which do you think is the more beautiful code? logic 6. Let X and Y be sets with cardinalities n and m, respectively. Let P( x, y) be a predicate meaning x is related to y. There are eight ways to quantify P( x, y) using (∀x) (∀y), (∃x), and (∃y). These are shown in the tree diagram below. (∀x) (∃x) (∃x) (∀x) (∀y) (∃y) Quantification (∀x) (∃x) (∀y) (∃y) (∃y) (∀y) (a) Draw graph diagrams for each of the quantified phrases. i. (∀x)(∀y)( P( x, y)) v. (∀y)(∀x)( P( x, y)) ii. (∀x)(∃y)( P( x, y)) vi. (∀y)(∃x)( P( x, y)) iii. (∃x)(∀y)( P( x, y)) vii. (∃y)(∀x)( P( x, y)) iv. (∃x)(∃y)( P( x, y)) viii. (∃y)(∃x)( P( x, y)) (b) Use your graphs to argue that i. (∀x)(∀y)( P( x, y)) ≡ (∀y)(∀x)( P( x, y)) ii. (∃x)(∃y)( P( x, y)) ≡ (∃y)(∃x)( P( x, y)) iii. None of the other four quantifications are equivalent. (c) You know the rules of Suduko, or if you don’t look them up. Pretend you want to write a program that plays the game. Devise simple predicate statements that allow you to write the rules of the game. Use predicates such as Square ( s) to say “s is a square on the board”; and SameRow ( s0 , s1 ) to say “s0 and s1 are in the same row”. Let board ( s) denote the value at square s. 9 Sets 1. Pretend you are writing traffic accident software and want to categorize accidents by the day of the week on which they occur. Pretend there are n accident reports to categorize. (a) What is the size of the sample space? That is, in how many ways can the n accident reports be distributed over 7 days? (b) In how many ways can all n accidents occur on one single day? (c) In how many ways can all n accidents occur on only two days? (d) Let’s looks at the other end: In how many ways can all n accidents occur on seven, and no less, days. (e) Show that for n ≥ 0 Note that k! 7 X k =0 k! ( ) !( ) X 7 n 7 n = 7n = 7k k k k k =0 where 7k = 7 · 6 · · · (7 − k + 1). 2. There are 2000 students on campus who own Team Fortress 2, Plants vs Zombies, or Kerbal Space Program. If 500 students owe all three games, 200 own only Team Fortress 2, 350 own only Plants vs. Zombies, and 150 own only Kerbal Space Program, how many of these games in total are owned by Florida Tech students? 3. The axiom of choice states that for any collection X of nonempty sets, then there exists a choice function c() that selects an element of A for every set A ∈ X. (a) Give an example of a choice function on the collection X = {{0, 1} , {2, 3} , {4, 5}} (b) How many choice functions could you define on the set X in problems 3a? (c) Let Z = {nk : k ∈ Z}. Let X be the collection X = {Z : n ∈ N} Give an example of a choice function on X. ! 7 7 = k! k k!(7 − k)! = 7 · 6 · · · (7 − k + 1) = 7k is called 7 falling 2. In general, nk is called falling factorial: n falling k. 12 discrete mathematics homework (d) Write the axiom of choice using predicate logic notation. (e) The Cantor C set is defined recursively by removing the middle third of a set of intervals. C0 = [0, 1] 1 2 C1 = [0, ] ∪ [ , 1] 3 3 1 2 1 2 7 8 C2 = [0, ] ∪ [ , ] ∪ [ , ] ∪ [ , 1] 9 9 3 3 9 9 Cn−1 2 + Cn−1 Cn = ∪ 3 3 C0 2 + C0 ∪ 3 3 C1 2 + C1 = ∪ 3 3 = i. What is a choice function for Cn ? ii. What is the total length (measure) of the intervals in Cn ? (f) The Cantor set C is C = lim Cn n→∞ i. What is the total length (measure) of C? Sequences ~ has terms pn defined by a polynomial 1. A polynomial sequence P pn = p ( n ) = m−1 X ak nk k =0 (a) Let p(n) = an + b be a linear polynomial, and let hl0 , l1 , l2 , . . .i = hb, a + b, 2a + b, . . .i be an arithmetic sequence. Show that ln − ln−1 = a for n ≥ 1. (b) Let p(n) = an2 + bn + c be a quadratic polynomial, and let hq0 , q1 , q2 , q3 . . .i = hc, a + b + c, 4a + 2b + c, 9a + 3b + c, . . .i be a quadratic sequence. Show that qn+1 − 2qn + qn−1 = 2a for n ≥ 1. (c) Let p(n) = an3 + bn2 + cn + d be a cubic polynomial, and let hc0 , c1 , c2 , . . .i = hd, a + b + c + d, 8a + 4b + 2c + d, 27a + 9b + 3c + d, . . .i be a cubic sequence. Show that cn+2 − 3cn+1 + 3cn − cn−1 = 6a for n ≥ 1. (d) Generalize the pattern you have discovered. 2. You have just graduated from Florida Tech with a BS in computer science or software engineering. Two companies have offered you a job. 3 • Company ABC offers you $50,000 plus a yearly raise of 5% of your salary. • Company XYZ offers you $60,000 plus a yearly raise of $3,000. (a) All other benefits being equal and assuming long term employment, which company’s offer would you accept? (b) Does your salary from ABC ever exceed your salary from XYZ? (c) How long would you need to stay at ABC until your total earnings equaled your total earnings from XYZ? 3 Recent surveys show most students graduating from Florida Tech’s Computer Science Department earn starting salaries from $50,000 to $70,000. 14 discrete mathematics homework (d) But there is another problem. A dollar today may not be equal to a dollar tomorrow. Assume there is a constant 3% rate of inflation. The value of n dollars today has a future value of only n/1.03 in one year. Using this model on the value of money, how long must you work at ABC? 3. Consider the sequence of sequences. hh0i , h0, 1i , h0, 1, 3, 2i , h0, 1, 3, 2, 6, 7, 5, 4i , h0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8i , . . .i (a) How are the sequences generated? (b) Describe the property of the sequences. Recursion 1. A partition of positive integer n is a collection of positive integers whose sum is n. For instance, 6 = 1 + 5 = 2 + 4 = 3 + 3 are three different partitions of 6 into 2 terms. The order of terms in the sum is not considered relevant. The terms in a partition are called parts. Let p(n, k) denote the number of partitions of n into exactly k parts. For example, 6 can be partitioned into k = 1, 2, 3, 4, 5 and 6 parts in the following ways. p(6, 1) = 1 (6) p(6, 2) = 3 (5 + 1, 4 + 2, 3 + 3) 3 ways p(6, 3) = 3 (4 + 1 + 1, 3 + 2 + 1, 2 + 2 + 2) 3 ways p(6, 4) = 2 (3 + 1 + 1 + 1, 2 + 2 + 1 + 1) 2 ways p(6, 5) = 1 (2 + 1 + 1 + 1 + 1) 1 way p(6, 6) = 1 (1 + 1 + 1 + 1 + 1 + 1) 1 way 1 way That boundary conditions p(n, 0) = 0, p(n, 1) = 1 and p(n, n) = 1, p(n, n + 1) = 0 state you cannot write n as the sum of no parts or n + 1 parts; and you can write n using 1 or n parts in only one way. (a) Find a three-term recursion formula the computes p(n, k) as p(n, k) = p( x, y) + p(z, w) where x and z are smaller than n, and y and w are no greater than k. Be able to explain why your recursion is sensible. (b) Use your recursion formula to fill in the row i = 0 to row i = 9 and 16 discrete mathematics homework column j = 0 through j = i + 1 of the integer partition triangle. Partition numbers p(n, k) k 0 1 2 3 4 5 6 7 8 n 0 1 2 3 4 5 6 7 8 9 9 0 0 0 0 0 0 0 0 0 0 2. A permutation is a one-to-one function from a finite set onto itself. Let ~π = hp0 , p1 , . . . , pn−1 i be a permutation of 0 to n − 1. D E An ascent in a permutation is a pair p j−1 , p j where p j−1 < p j . The pair is a descent if p j−1 > p j . For instance, • h0, 1, 2i has 2 ascents, • h2, 1, 0i has no ascents, • Each of h1, 0, 2i, h0, 2, 1i, h2, 0, 1i, and h1, 2, 0i has one ascent. DE Let nk be the number of permutations of n values with k ascents. From the above example, you know * + * + * + 3 3 3 = 1, = 4, =1 0 1 2 In general, there is only one permutation of n values with no ascents * + n =1 hn − 1, n − 2, . . . , 0i so 0 And, there is only one permutation of n values with n − 1 ascents * + n =1 h0, 1, . . . , n − 1i so n−1 3. Explain why n−1 * + X n k =0 k = n! (1) DnE k k.” is the Eulerian number called “n ascent recursion 4. Explain why * + * + n n = . k n−k−1 (2) 5. Let ~π be a permutation of n values: 0 to n − 1. Develop a notation for the permutation that results from inserting a new value n into ~π and some position j. In how many ways can you insert a new value n into ~π? 6. Let ~π have k ascents. Show there are k + 1 sequences among ~πn, j , j = 0, 1, . . . , n − 1 that have k ascents. 7. Let ~π have k − 1 ascents. Show there are n − k sequences among ~πn, j , j = 0, 1, . . . , n − 1 that have k ascents. 8. Use your answers from the previous problems to explain the three-term recurrence equation + + * + * * n n−1 n−1 = (k + 1) + (n − k ) k k k−1 9. Let n be a natural number greater than 0. Consider the sequence generated by the recurrence equation ! 1 n xk+1 = xk + , k ≥ 0, x0 = 1. 2 xk (a) Compute terms x1 , x2 , x3 , and x4 , for n = 1, 2, 3, 4. (b) What values does the recursion compute? 17 Summations 1. The area under a curve can be approximated by the trapezoid rule. 4 For instance the area under the sine curve from x = 0 to x = π can be approximated by 4 trapezoids with base h = π/4 and heights sin kπ/4, k = 0, 1, 2, 3, 4. 4 How can you compute the area of a trapezoid? y = sin x x In this case, Z π 2= sin xdx 0 π sin 0 + sin π/4 sin π/4 + sin π/2 sin π/2 + sin 3π/4 sin 3π/4 + sin π ≈ + + + 4 2 2 2 2 √ π = (2 + 2 2) 8 ≈ 1.896 ! The trapezoid rule for uniform step size h = (b − a)/n can be written using the notation Z b n−1 hX f ( x) dx ≈ ( f ( xk+1 ) + f ( xk )) 2 a k =0 h = ( f ( x0 ) + 2 f ( x1 ) + 2 f ( x2 ) + · · · + 2 f ( xn−1 ) + f ( xn )) 2 where x0 = a xn = b and xk = xk−1 + h for k = 1, . . . , n Use the trapezoid rule to approximate the area under the curves below. What is the error? (a) y = x2 from x = 0 to x = m using a step size of h = 1. y = x2 (b) y = x2 from x = 0 to x = m using a step size h = m/n. (c) y = 1/x from x = 1 to x = m using a step size h = 1. x Induction 1. Let F~ = hF0 , F1 , F2 , F3 , F4 , . . .i = h0, 1, 1, 2, 3, . . .i be the Fibonacci sequence where Fn = Fn−1 + Fn−2 , F0 = 0 and F1 = 1. Prove Cassini’s identity: For all n ≥ 1 Fn+1 Fn−1 − Fn2 = (−1)n 2. Let a > 1 be a positive integer. Pretend you want to divide n people into some number of teams, each of size a or a + 1. Show that this is possible provided n is larger than values in the Fibonacci polynomial a2 − a − 1 = a(a − 1) − 1. 3. Find the coefficient of of xk in the expansion of ( x + 1/x)n . 4. Show that (see problem 1e) n ( ) X n k =0 k xk = xn Relations 1. Identify the relations on the set of bits B = {0, 1} that are partial orders and those that are equivalence relations. 2. Let F = { f : N → N} be the set of function from the natural numbers to the natural numbers. Let f , g ∈ F and write f = O(g), saying “ f is big-O of g,” if (∃c ∈ N)(∃N ∈ N)(∀n ≥ N )( f (n) ≤ cg(n)) (a) Show that big-O is reflexive and transitive. (b) Write f = Ω(g) and say “ f is big-Omega of g” if f = O(g) and g = O( f ). (c) Loosen the antisymmetry rule to conclude big-O is a loosened partial order on the set F. 3. Consider the rules of “Rock-Paper-Scissors-Lizard-Spock” • Scissors cuts paper • Scissors decapitates lizard • Paper covers rock • Lizard eats paper • Rock crushes lizard • Paper disproves Spock • Lizard poisons Spock • Spock vaporizes rock • Spock smashes scissors • Rock crushes scissors (a) Draw a graph which shows the rules of “Rock-Paper-Scissors-LizardSpock” (b) Construct an adjacency matrix which shows the rules of “Rock-PaperScissors-Lizard-Spock” 24 discrete mathematics homework (c) Is the game a partial order? Why or why not? (d) Is the game an equivalence? Why or why not? 4. A candy machine takes nickels, dimes and quarters. When 50¢ is deposited a candy bar is dispensed along with change if necessary. The diagram below shows the transitions from state-to-state as money is put in the machine. 25 25 25 10 30 10 5 5 0 5 10 5 10 5 10 5 15 5 25 20 10 10|25 40 5 5 5 45 10 25 10 25 10 35 25 25 25 (a) Say that two paths p0 and p1 in the transition graph are path equivalent they start in the same state and end in the same state. Prove path equivalence is an equivalence relation. (b) Say state s precedes state t if there is a path from s to t. (Include trivial paths from a state to itself on input of 0¢, so that state s precedes itself). Prove precedes is a partial order. 5. Let a, b ∈ Z. What do the following mean? Discuss the equivalence classes of integers that the relations define. (a) a ≡ b (mod 2) (b) a ≡ b (mod 1) (c) a ≡ b (mod 0) 6. Let f : X → Y be a function. Let a, b ∈ X, and write a ≡ b if f (a) = f (b). Show that ≡ is an equivalence relation. 5|10|25 50 Functions 1. What function does the following recursive function, written in a pseudocode, compute? int f(int x, int [] a) { // function f accepts input : integer x and // integer array a[]. // f computes a value and returns it. if (a. length () == 0) return 0; else if (a. length () == 1) return a[0]; else return f(x, (a[0]*x+a[1] ,a.tail (). tail ())); } 2. You have a picture that is 5” × 3”. You want to discretize it into an image of 1920 × 1080 pixels. Into which pixel ( p x , p(y ) will ( x, y) fall, for 0 ≤ x ≤ 5, and 0 ≤ y ≤ 3? You may want to start by studying the smaller 19 × 13 grid below. (5, 3) 0 2 4 6 8 10 12 (0, 0) 0 2 4 6 8 10 12 14 16 18 3. Pretend you want to draw a straight line from pixel ( p x , py ) to pixel (q x , qy ). Which pixels would you light? Numbering & Naming Systems 1. How would you define a duovigesimal (base 32) number system? Discuss the alphabet and modeling natural numbers, integers, and rational numbers in fixed point and floating point notations. What is the compression in string length when representing numbers in base 32 over base 2? 2. The powers of 2 form a basis for the natural numbers. Any natural number n ≥ 0 can be written as the sum of powers of 2. m−1 X k bk 2 (∀n ∈ N)(∃bk ∈ B, k = 0, 1, . . . , m − 1) n = k =0 Prove this. 3. The Fibonacci numbers are another interesting base for the natural numbers. That is, m−1 X (∀n ∈ N)(∃bk ∈ B, k = 0, 1, . . . , m − 1) n = bk Fk k =0 Prove this. 4. I got this one from Click & Clack, the Tappet Brothers: Given $1000 in $1 dollar bills and 10 envelops, distribute the money among the envelops so that you can give out any dollar amount from $1 to $1000. 5. Explain how you would define a three’s complement number system to represent integers. What is the major irritation when the base for a complement number system is not even? 6. Let r be a rational number so that r can be written as a fraction p/q in lowest terms, that is, gcd( p, q) = 1. (a) Show that if q = 2k for some integer k, then r can be expressed as a finite binary string. Use fixed point notation. (b) Show that if q , 2k for any integer k, then r cannot be expressed as a finite binary string, but r can be written as a repeating binary pattern of finite length. 28 discrete mathematics homework 7. Write 0.1, 0.2, and 0.3 in fixed point notation as repeating binary patterns. Use your ability to sum an infinite geometric series 5 to show your answers are correct. 5 Infinite series is not taught in this class. Series is a topic in calculus, but you can guess, know, or look up geometric series. 8. In class we’ve used an 8-bit pidgin floating point notation to explain basic concepts in modeling real numbers by a finite set of rational numbers. Modern floating point units are expected to implement the IEEE 754 standard for binary floating-point arithmetic. A single precision floating point numbers are represented in 32 bits: 1 sign bit, 8 exponent bits, and 23 fraction bits. s e7 e6 e5 e4 e3 e2 e1 byte 0 e0 f−1 f−2 f−3 f−4 f−5 f−6 f−7 byte 1 f−8 f−9 f−10 f−11 f−12 f−13 f−14 f−15 byte 2 f−16 f−17 f−18 f−19 f−20 f−21 f−22 f−23 byte 3 • The exponent e = (e7 · · · e0 )2 is biased with b = 127, giving a range from e = 0 − 127 = −127 to e = 255 − 127 = 128. – Normalized numbers x have exponent e in the range emin = (0000 0001)b=127 = −126 to emax = (1111 1110)b=127 = 127 In this case, x = (−1) s × (1. f )2 × 2e – When e = −127 the numbers are denormalized or subnormal. When the fraction bits are not all 0’s, the bit string represents plus or minus 0. 1 (0000 0000) (0000 0000 0000 0000 0000 000) = −0 0 (0000 0000) (0000 0000 0000 0000 0000 000) = +0 Otherwise, the bit string represents a small fraction. 1 (00000000) ( xxxx xxxx xxxx xxxx xxxx xxx) = −0. f × 2emin 0 (00000000) ( xxxx xxxx xxxx xxxx xxxx xxx) = +0. f × 2emin – When e = 128 the bit string encodes ±∞ 1 (1111 1111) (0000 0000 0000 0000 0000 000) = −∞ 0 (1111 1111) (0000 0000 0000 0000 0000 000) = +∞ or Not a Number (NaN) numbers where the fraction is not all 0’s 1 (11111111) ( xxxx xxxx xxxx xxxx xxxx xxx) = NaN 0 (11111111) ( xxxx xxxx xxxx xxxx xxxx xxx) = NaN numbering & naming systems • Rounding occurs whenever an operation produces a result that cannot be represented exactly in floating point notation. The default is to round to the nearest floating point value. (a) What is the single precision floating point approximation to 0.1, 0.2, and 0.3? (b) How are the single precision floating point approximations of 0.1 and −0.2 stored as 4 byte hexadecimal strings of length 8? (c) What are the smallest and largest positive normalized single precision floating point numbers? (d) What are the smallest and largest positive subnormal single precision floating point numbers? (e) Given that normalized single precision floating point numbers have 24 bits of precision, about how many decimal digits of accuracy can you expect? Double precision uses 53 bits. How many decimal digits of accuracy does this give? 29 Combinatorics & Number Theory 1. In how many ways can you find n positive integers that add up to m? (Take the order of the terms into account, for example, 1 + 2 + 4 is different than 2 + 4 + 1.) 2. An n-legged Alien has a drawer full of socks, each of which is red, white, or blue, and there are at least n socks of each color. The Alien pulls out one sock at a time without looking. How many socks must the Alien remove from the drawer to be certain there will be n socks of the same color? Consider the problem again, but suppose there are m sock colors. 3. In the clock game Alice and Bob both start at 12 o’clock. During a move Alice moves 5 hours clockwise on the clock-face and Bob moves 9 hours counterclockwise. How many moves will it take before Bob and Alice stop on the same hour? What if the game is changes so that Alice moves a hours clockwise and Bob moves b hours counterclockwise? n−1 4. Let m = pe00 pe11 · · · pen−1 be the prime factorization of m. How many positive divisors does m have? 5. Back in the day men always wore hats and when they went to a club they would have a hat-check girl store their hats. If n men checked hats, in how many ways can they be returned such that no man gets back his own hat? 6. The rumor is that Blaise Pascal was very interested in gambling and developed many of his ideas about combinatorics from that. (a) In how many five card hands can be dealt from a standard deck of 52 cards? (b) In how many can each of the following hand be dealt? i. A pair, for example discrete mathematics homework 2 ♥ J ♦ ♦ ♦ ♦ ♦ ♦ ♥ ♥ ♦ ♥ ♥ 5 ♠ 5 ♥ ♦ ♠ J A A ♦ ♥ 2 ♠ A A ii. Two pairs, for example 2 K ♦ ♥ ♣ ♥ ♦ ♥ ♦ ♥ ♦ ♥ 2 2 ♠ 2 ♥ ♥ ♠ ♣ A A K ♠ A A iii. Three of a kind, for example 7 A ♥ ♣ ♥ ♣ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♥ ♣ 7 ♠ Q ♦ ♣ ♦ ♠ ♣ A A Q ♠ A A A iv. A straight, for example 5 ♥ ♥ ♥ ♦ ♦ ♦ ♦ ♦ ♥ ♥ 7 ♦ ♣ ♣ ♣ ♣ ♣ ♣ ♣ ♣ ♦ ♦ ♦ ♦ ♦ ♦ ♦ 6 ♠ ♠ ♠ 6 ♦ ♦ ♠ ♣ 4 3 7 ♥ 5 ♠ 4 3 v. A flush, for example 5 10 ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ 10 ♠ ♠ ♠ ♠ ♠ ♠ 5 ♠ 3 vi. A full house, for example K ♠ J ♠ ♠ ♠ J ♠ ♠ ♠ ♠ 3 K 32 combinatorics & number theory ♥ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♣ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♦ ♥ 7 ♦ ♣ 7 ♥ ♣ A 7 ♠ 7 A ♥ ♠ ♥ A A ♠ A A vii. Four of a kind, for example A A ♣ ♣ ♣ ♣ ♣ ♣ ♣ ♦ ♦ ♥ ♣ ♥ ♣ A A ♠ 6 ♦ ♣ ♣ ♥ ♠ 6 A A ♠ A A viii. Straight flush, for example 5 ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠ 7 ♠ ♠ 6 ♠ ♠ ♠ 6 ♠ ♠ 4 ♠ 7 3 ♠ 5 ♠ 4 3 ix. Royal flush, for example 10 Q J ♥ A K ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ Q ♥ ♥ J 10 4 8 7 And a full binary tree ♥ 487 K A (not full) binary tree ♥ 7. Binary trees are basic data structures. A full binary tree is one where each internal node has exactly two children. A (c) What is the probability of each of the above hands? 33 34 discrete mathematics homework 1234 34 12 1 2 3 4 (a) Let T n be a full binary tree with n internal nodes. How many edges does T n have? (b) Let T n be a full binary tree with n internal nodes. How many leafs does T n have? (c) Let Cn be the number of full binary trees with n internal nodes. What is a recurrence equation for Cn ? (d) Let Cn be the number of full binary trees with n internal nodes. What is a formula, involving binomail coefficients, for Cn ? Cn is called a Catalan number. Proofs 1. Let a and b be positive integers. Prove that g = gcd(a, b) is the smallest positive value of as + bt as s and t range over the integers. 2. A real number r is called sensible if there exist positive integers a and b √ √ such that a/b = r. For example, setting a = 2 and b = 1 shows that 2 √ 3 is sensible. Prove that 2 is not sensible. 6 3. Pretend you have n pigeons to put in m pigeonholes. (a) Prove there must be a pigeonhole with n/m or more pigeons. (b) Prove there must be a pigeonhole with n/m or fewer pigeons. 4. Place a knight on each square of a 7 × 7 chessboard. ls it possible for each knight to simultaneously make a legal move? 6 This problem came from MIT course 6.042J/18.062J, by Prof. Albert R. Meyer and Prof. Ronitt Rubinfeld proofs 37 Index Axiom of Choice, 11 Big-Oh Notation, 23 Binary addition, 7 Binary tree, 33 Full, 33 Binomial Theorem, 21 Bits Carry In, 7 Carry Out, 7 Boole, George, 7 Boolean Functions, 7 n-Input, m-Output, 7 Quasi-Boolean, 8 Fibonacci Basis, 27 Fibonacci Polynomial, 21 Full adder, 7 Functions, 25 Pascal,Blaise, 31 Permutations, 16 Pigeons and Pigeonholes, 35 Proofs, 35 Graphs of Quantified Predicate, 9 Greatest Common Divisor, 35 Growth of Arithmetic and Geometric Sequences, 13 Rational Numbers, 27 Base Two, 27 Fixed Point Representation, 28 Floating Point Number Representation, 28 Recursion, 15 Relations, 23 Relationship between powers of x, Falling Factorials, and Second Stirling Numbers, 21 Homework Calculating Grades, 6 IEEE 754, 28 Induction, 21 Cantor set, 12 Cantor, Georg, 12 Cassini’s Identity, 21 Catalan numbers, 34 Click & Clack, the Tappet Brothers, 27 Combinatorics, 31 Complement Number Systems, 27 Logic, 7 Quantifying Predicates, 9 Equivalence Relations, 23 Eulerian Numbers, 16 Partial Orders, 23 Partitions of a Positive Integer, 15 Making teams, 21 Number Systems, 27 Number Theory, 31 Sensible Numbers, 35 Sequences, 13 Ascents, 16 Sets, 11 Bits B = {0, 1}, 23 Integers Z = {0, ±1, ±2, . . .}, 24 Natural Numbers N = {0, 1, 2, . . .}, 23 Summations, 19 Trapezoid Rule, 19