39
DEPARTMENT OF COMPUTER SCIENCES COLLEGE OF ENGINEERING FLORIDA TECH DISCRETE MATHEMATICS HOMEWORK WILLIAM SHOAFF FALL 2013

DISCRETE MATHEMATICS HOMEWORK - Home - Home - …cs.fit.edu/~wds/classes/adm/Homework/Homework.pdf · department of computer sciences college of engineering florida tech discrete

Embed Size (px)

Citation preview

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 SC O L L E G E O F E N G I N E E R I N G

F L O R I D A T E C H

D I S C R E T EM AT H E M AT I C SH O M E W O R K

W I L L I A M S H O A F F FA L L 2 0 1 3

Problems Sets

Overview 5

Logic 7

Sets 11

Sequences 13

Recursion 15

Summations 19

Induction 21

Relations 23

Functions 25

Numbering & Naming Systems 27

Combinatorics & Number Theory 31

Proofs 35

Index 39

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, thatyou need hints to find a solution or that you simply need the answer to beexplained to you, then use the time honored method: Ask an oracle, perhapsPythia, (a nondeterministic Turing machines)1 to provides the answer, and 1 I am not an oracle. I cannot always give

the right answer to your questions. Somequestions have no answers. I have notmastered the answers to many questions thatdo have answers.

you, the validator (a deterministic Turing machine)2 checks it is correct.

2 I don’t mean to imply anyone is deter-ministic, I don’t believe that. I am justtrying to describe computational ideas inanthropomorphic terms.

You can choose to earn extra credit by solving these problems, but thereare rules.

1. You must start earning extra credit before Monday, October 15. In par-ticular, you cannot seek extra credit toward the end of the semester onceyou’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, extracredit learn to write mathematics in a document processing system such asLATEX or (sigh) Word. A system that can nicely typeset mathematical, andother, notations.

3. You must explain your solution to the instructor’s satisfaction in a solointerview. Schedule an interview through the department’s administrativeassistant: 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 addressthe major classes

• To those who want to learn advanced topics, demonstrate your understand-ing as basic topics by solving these homework problems. You will earn anA in the course.

6 department of computer sciences

college of engineering

florida tech

• To those who want to improve their grade, You can advance at most oneletter grade by solving these extra credit problems. In fact, you can’tadvance from low X to Y, unless your extra credit work is impressive andyou own it: Don’t fall behind.

• To those who want future recommedations: Talk to your instructor fre-quently

Letter Grade Calculation

The letter grade you receive in this course is based on the work you demon-strate in class.

Your total score can be calculated by the formula

S =n−1∑k=0

wk sk

where the non-negative weights wk sum to 1 and the values sk are scores onyour efforts, k = 0, 1, . . . , n − 1. There are ten homework assignments andone final examination; therefore n = 11. These are summarized below. Eachassignment will have a maximum score of 100. Therefore your score will besome 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 achieve-ment of the class. I will use:

• The mean (average) score µ over all students in the class

µ =1m

m−1∑j=0

S j

where there are m students and student j scored S j points.

• The standard deviation σ of all scores

σ =

√∑m−1j=0 (S j − µ)2

m

• Your z score

z =S − µσ

which measures how many standard deviations your score S is above ofbelow the mean µ.

• Your C+ scoreC+ = 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 valuesrather than Boolean values. When you do, addition can implemented bythe 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 beable to add two terms (bits) a and b and a carry-in bit cin to compute asum bit s and a a carry-out bit cout.

(a) Complete the truth table below that describes a full adder: TheBoolean function that adds two bits a, b, and a carry-in bit cin toproduce a sum bit s and a carry-out bit cout.

Input Output

a b cin s cout

0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1

(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-bitstrings a = a7a6 · · · a1a0 and b = b7b6 · · · b1b0 together with asequence of carries c = c7c6 · · · c1c0 to product a sum s = s7s6 · · · s1s0

and carry out bit c8.

2. In general, a Boolean function maps an n-tuple of Boolean values to anm-tuple of Boolean values, as in problem 1 where 3 values are mapped to2. 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 Booleanvalues 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 manydifferent 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 thefollowing 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 themore beautiful code?

logic 9

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 quantifyP(x, y) using (∀x) (∀y), (∃x), and (∃y). These are shown in the treediagram below.

Quantification

(∀x)(∀y)

(∃y)

(∃x)

(∀y)

(∃y)

(∃y)(∀x)

(∃x)

(∀y)

(∀x)

(∃x)

(a) Draw graph diagrams for each of the quantified phrases.

i. (∀x)(∀y)(P(x, y))

ii. (∀x)(∃y)(P(x, y))

iii. (∃x)(∀y)(P(x, y))

iv. (∃x)(∃y)(P(x, y))

v. (∀y)(∀x)(P(x, y))

vi. (∀y)(∃x)(P(x, y))

vii. (∃y)(∀x)(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. Pre-tend you want to write a program that plays the game. Devise simplepredicate 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”. Letboard(s) denote the value at square s.

Sets

1. Pretend you are writing traffic accident software and want to categorizeaccidents by the day of the week on which they occur. Pretend there are naccident reports to categorize.

(a) What is the size of the sample space? That is, in how many ways canthe 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 accidentsoccur on seven, and no less, days. Note that

k!(7k

)= k!

7k!(7 − k)!

= 7 · 6 · · · (7 − k + 1)

= 7k

is called 7 falling 2. In general, nk is calledfalling factorial: n falling k.

(e) Show that for n ≥ 0

7∑k=0

k!(7k

)nk

=

7∑k=0

7k

nk

= 7n

where 7k = 7 · 6 · · · (7 − k + 1).

2. There are 2000 students on campus who own Team Fortress 2, Plants vsZombies, or Kerbal Space Program. If 500 students owe all three games,200 own only Team Fortress 2, 350 own only Plants vs. Zombies, and 150own only Kerbal Space Program, how many of these games in total areowned 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 forevery 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 prob-lems 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.

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 thirdof a set of intervals.

C0 = [0, 1]

C1 = [0,13] ∪ [

23

, 1] =C0

3∪

2 +C0

3

C2 = [0,19] ∪ [

29

,13] ∪ [

23

,79] ∪ [

89

, 1] =C1

3∪

2 +C1

3

Cn =Cn−1

3∪

2 +Cn−1

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 isC = lim

n→∞Cn

i. What is the total length (measure) of C?

Sequences

1. A polynomial sequence ~P has terms pn defined by a polynomial

pn = p(n) =m−1∑k=0

aknk

(a) Let p(n) = an + b be a linear polynomial, and let

〈l0, l1, l2, . . .〉 = 〈b, a + b, 2a + b, . . .〉

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

〈q0, q1, q2, q3 . . .〉 = 〈c, a + b + c, 4a + 2b + c, 9a + 3b + c, . . .〉

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

〈c0, c1, c2, . . .〉 = 〈d, a + b + c + d, 8a + 4b + 2c + d, 27a + 9b + 3c + d, . . .〉

be a cubic sequence. Show that cn+2 − 3cn+1 + 3cn − cn−1 = 6a forn ≥ 1.

(d) Generalize the pattern you have discovered.

2. You have just graduated from Florida Tech with a BS in computer scienceor software engineering. Two companies have offered you a job. 3 3 Recent surveys show most students

graduating from Florida Tech’s ComputerScience Department earn starting salariesfrom $50,000 to $70,000.

• Company ABC offers you $50,000 plus a yearly raise of 5% of yoursalary.

• 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 earningsequaled your total earnings from XYZ?

14 discrete mathematics homework

(d) But there is another problem. A dollar today may not be equal to adollar tomorrow. Assume there is a constant 3% rate of inflation. Thevalue 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 atABC?

3. Consider the sequence of sequences.

〈〈0〉 , 〈0, 1〉 , 〈0, 1, 3, 2〉 , 〈0, 1, 3, 2, 6, 7, 5, 4〉 , 〈0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8〉 , . . .〉

(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 whosesum is n. For instance, 6 = 1 + 5 = 2 + 4 = 3 + 3 are three different par-titions of 6 into 2 terms. The order of terms in the sum is not consideredrelevant.

The terms in a partition are called parts. Let p(n, k) denote the number ofpartitions of n into exactly k parts. For example, 6 can be partitioned intok = 1, 2, 3, 4, 5 and 6 parts in the following ways.

p(6, 1) = 1 (6) 1 way

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

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 + 1parts; 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. Beable 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 9

0 01 02 03 0

n 4 05 06 07 08 09 0

2. A permutation is a one-to-one function from a finite set onto itself. Let~π = 〈p0, p1, . . . , pn−1〉 be a permutation of 0 to n − 1.

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,

• 〈0, 1, 2〉 has 2 ascents,

• 〈2, 1, 0〉 has no ascents,

• Each of 〈1, 0, 2〉, 〈0, 2, 1〉, 〈2, 0, 1〉, and 〈1, 2, 0〉 has one ascent.

Let⟨

nk

⟩be the number of permutations of n values with k ascents. From

⟨nk

⟩is the Eulerian number called “n ascent

k.”the above example, you know⟨30

⟩= 1,

⟨31

⟩= 4,

⟨32

⟩= 1

In general, there is only one permutation of n values with no ascents

〈n − 1, n − 2, . . . , 0〉 so⟨n0

⟩= 1

And, there is only one permutation of n values with n − 1 ascents

〈0, 1, . . . , n − 1〉 so⟨

nn − 1

⟩= 1

3. Explain whyn−1∑k=0

⟨nk

⟩= n! (1)

recursion 17

4. Explain why ⟨nk

⟩=

⟨n

n − k − 1

⟩. (2)

5. Let ~π be a permutation of n values: 0 to n − 1. Develop a notation forthe permutation that results from inserting a new value n into ~π and someposition 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-termrecurrence equation⟨

nk

⟩= (k + 1)

⟨n − 1

k

⟩+ (n − k)

⟨n − 1k − 1

⟩9. Let n be a natural number greater than 0. Consider the sequence generated

by the recurrence equation

xk+1 =12

(xk +

nxk

), k ≥ 0, x0 = 1.

(a) Compute terms x1, x2, x3, and x4, for n = 1, 2, 3, 4.

(b) What values does the recursion compute?

Summations

1. The area under a curve can be approximated by the trapezoid rule. 4 4 How can you compute the area of atrapezoid?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.

x

y = sin x

In this case,

2 =

∫ π

0sin xdx

≈π

4

(sin 0 + sin π/4

2+

sin π/4 + sin π/22

+sin π/2 + sin 3π/4

2+

sin 3π/4 + sin π2

)=π

8(2 + 2

√2)

≈ 1.896

The trapezoid rule for uniform step size h = (b− a)/n can be written usingthe notation∫ b

af (x) dx ≈

h2

n−1∑k=0

( f (xk+1) + f (xk))

=h2( f (x0) + 2 f (x1) + 2 f (x2) + · · ·+ 2 f (xn−1) + f (xn))

where x0 = a xn = b and xk = xk−1 + h for k = 1, . . . , n Use the trapezoidrule 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

x

(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.

Induction

1. Let ~F = 〈F0, F1, F2, F3, F4, . . .〉 = 〈0, 1, 1, 2, 3, . . .〉 be the Fibonaccisequence where Fn = Fn−1 + Fn−2, F0 = 0 and F1 = 1. Prove Cassini’sidentity: For all n ≥ 1

Fn+1Fn−1 − F2n = (−1)n

2. Let a > 1 be a positive integer. Pretend you want to divide n peopleinto some number of teams, each of size a or a + 1. Show that this ispossible provided n is larger than values in the Fibonacci polynomiala2 − 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∑k=0

nk

xk = xn

Relations

1. Identify the relations on the set of bits B = 0, 1 that are partial ordersand those that are equivalence relations.

2. Let F = f : N→N be the set of function from the natural numbers tothe natural numbers. Let f , g ∈ F and write f = O(g), saying “ f is big-Oof 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) andg = O( f ).

(c) Loosen the antisymmetry rule to conclude big-O is a loosened partialorder on the set F.

3. Consider the rules of “Rock-Paper-Scissors-Lizard-Spock”

• Scissors cuts paper

• Paper covers rock

• Rock crushes lizard

• Lizard poisons Spock

• Spock smashes scissors

• Scissors decapitates lizard

• Lizard eats paper

• Paper disproves Spock

• Spock vaporizes rock

• Rock crushes scissors

(a) Draw a graph which shows the rules of “Rock-Paper-Scissors-Lizard-Spock”

(b) Construct an adjacency matrix which shows the rules of “Rock-Paper-Scissors-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 de-posited a candy bar is dispensed along with change if necessary. Thediagram below shows the transitions from state-to-state as money is put inthe machine.

0

55

101025

25

5

15

10

30

25

5

2010

35

25

5

10

50

25

10

5

40

25

5

10

25

5

10

4525 5

1025

510|25

5|10|25

(a) Say that two paths p0 and p1 in the transition graph are path equiva-lent they start in the same state and end in the same state. Prove pathequivalence is an equivalence relation.

(b) Say state s precedes state t if there is a path from s to t. (Includetrivial paths from a state to itself on input of 0¢, so that state s precedesitself). Prove precedes is a partial order.

5. Let a, b ∈ Z. What do the following mean? Discuss the equivalenceclasses 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 iff (a) = f (b). Show that ≡ is an equivalence relation.

Functions

1. What function does the following recursive function, written in a pseu-docode, 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 imageof 1920 × 1080 pixels. Into which pixel (px, p(y) will (x, y) fall, for0 ≤ x ≤ 5, and 0 ≤ y ≤ 3?

You may want to start by studying the smaller 19 × 13 grid below.

0 2 4 6 8 10 12 14 16 18

0

2

4

6

8

10

12

(0, 0)

(5, 3)

3. Pretend you want to draw a straight line from pixel (px, py) to pixel(qx, qy). Which pixels would you light?

Numbering & Naming Systems

1. How would you define a duovigesimal (base 32) number system? Discussthe alphabet and modeling natural numbers, integers, and rational numbersin fixed point and floating point notations. What is the compression instring length when representing numbers in base 32 over base 2?

2. The powers of 2 form a basis for the natural numbers. Any natural numbern ≥ 0 can be written as the sum of powers of 2.

(∀n ∈N)(∃bk ∈ B, k = 0, 1, . . . , m − 1)

n =m−1∑k=0

bk2k

Prove this.

3. The Fibonacci numbers are another interesting base for the natural num-bers. That is,

(∀n ∈N)(∃bk ∈ B, k = 0, 1, . . . , m − 1)

n =m−1∑k=0

bkFk

Prove this.

4. I got this one from Click & Clack, the Tappet Brothers: Given $1000 in $1dollar bills and 10 envelops, distribute the money among the envelops sothat you can give out any dollar amount from $1 to $1000.

5. Explain how you would define a three’s complement number systemto represent integers. What is the major irritation when the base for acomplement number system is not even?

6. Let r be a rational number so that r can be written as a fraction p/q inlowest terms, that is, gcd(p, q) = 1.

(a) Show that if q = 2k for some integer k, then r can be expressed as afinite binary string. Use fixed point notation.

(b) Show that if q , 2k for any integer k, then r cannot be expressed as afinite binary string, but r can be written as a repeating binary pattern offinite length.

28 discrete mathematics homework

7. Write 0.1, 0.2, and 0.3 in fixed point notation as repeating binary pat-terns. Use your ability to sum an infinite geometric series 5 to show your 5 Infinite series is not taught in this class.

Series is a topic in calculus, but you canguess, know, or look up geometric series.

answers are correct.

8. In class we’ve used an 8-bit pidgin floating point notation to explain basicconcepts in modeling real numbers by a finite set of rational numbers.Modern floating point units are expected to implement the IEEE 754standard for binary floating-point arithmetic. A single precision floatingpoint numbers are represented in 32 bits: 1 sign bit, 8 exponent bits, and23 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 rangefrom 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. Whenthe fraction bits are not all 0’s, the bit string represents plus or minus0.

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 29

• Rounding occurs whenever an operation produces a result that cannotbe represented exactly in floating point notation. The default is to roundto 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 precisionfloating point numbers?

(d) What are the smallest and largest positive subnormal single precisionfloating point numbers?

(e) Given that normalized single precision floating point numbers have24 bits of precision, about how many decimal digits of accuracy canyou expect? Double precision uses 53 bits. How many decimal digits ofaccuracy does this give?

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 differentthan 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 outone sock at a time without looking. How many socks must the Alienremove from the drawer to be certain there will be n socks of the samecolor?

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 moveAlice moves 5 hours clockwise on the clock-face and Bob moves 9 hourscounterclockwise. How many moves will it take before Bob and Alicestop on the same hour?

What if the game is changes so that Alice moves a hours clockwise andBob moves b hours counterclockwise?

4. Let m = pe00 pe1

1 · · · pen−1n−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 theywould have a hat-check girl store their hats. If n men checked hats, in howmany 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 anddeveloped many of his ideas about combinatorics from that.

(a) In how many five card hands can be dealt from a standard deck of 52cards?

(b) In how many can each of the following hand be dealt?

i. A pair, for example

32 discrete mathematics homework

A♠

A♠

A♥

A♥

2♥

2♥

♦♦♦

5♦

5♦

J♦

J♦

ii. Two pairs, for example

A♠

A♠

A♥

A♥

2♥

2♥

2♦

2♦

K♣

K♣

iii. Three of a kind, for example

A♠

A♠

A♥

A♥

A♣

A♣

♦♦♦

♦♦♦♦

7♦

7♦

Q♣

Q♣

iv. A straight, for example

3♠

3♠

4♥

4♥

♦♦♦

5♦

5♦

♦♦♦

♦♦♦

6♦

6♦

♣♣

7♣

7♣

v. A flush, for example

3♠

3♠

5♠

5♠

♠♠♠♠

♠♠♠♠

10♠

10♠

J♠

J♠

K♠

K♠

vi. A full house, for example

combinatorics & number theory 33

A♠

A♠

A♥

A♥

A♣

A♣

♦♦♦

♦♦♦♦

7♦

7♦

♥♥♥

♥♥♥♥

7♥

7♥

vii. Four of a kind, for example

A♠

A♠

A♥

A♥

A♣

A♣

A♦

A♦

6♣

6♣

viii. Straight flush, for example

3♠

3♠

4♠

4♠

5♠

5♠

6♠

6♠

♠♠

7♠

7♠

ix. Royal flush, for example

♥♥♥♥

♥♥♥♥

10♥

10♥

J♥

J♥

Q♥

Q♥

K♥

K♥

A♥

A♥

(c) What is the probability of each of the above hands?

7. Binary trees are basic data structures. A full binary tree is one where eachinternal node has exactly two children.

A (not full) binary tree

487

4 8

7

And a full binary tree

34 discrete mathematics homework

1234

12

1 2

34

3 4

(a) Let Tn be a full binary tree with n internal nodes. How many edgesdoes Tn have?

(b) Let Tn be a full binary tree with n internal nodes. How many leafsdoes Tn have? Cn is called a Catalan number.

(c) Let Cn be the number of full binary trees with n internal nodes. Whatis a recurrence equation for Cn?

(d) Let Cn be the number of full binary trees with n internal nodes. Whatis a formula, involving binomail coefficients, for Cn?

Proofs

1. Let a and b be positive integers. Prove that g = gcd(a, b) is the smallestpositive 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 bsuch that

√a/b = r. For example, setting a = 2 and b = 1 shows that

√2

is sensible. Prove that 3√2 is not sensible. 6 6 This problem came from MIT course6.042J/18.062J, by Prof. Albert R. Meyerand Prof. Ronitt Rubinfeld3. 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 eachknight to simultaneously make a legal move?

proofs 37

Index

Axiom of Choice, 11

Big-Oh Notation, 23Binary addition, 7Binary tree, 33

Full, 33Binomial Theorem, 21Bits

Carry In, 7Carry Out, 7

Boole, George, 7Boolean Functions, 7

n-Input, m-Output, 7Quasi-Boolean, 8

Cantor set, 12Cantor, Georg, 12Cassini’s Identity, 21Catalan numbers, 34Click & Clack, the Tappet Brothers, 27Combinatorics, 31Complement Number Systems, 27

Equivalence Relations, 23Eulerian Numbers, 16

Fibonacci Basis, 27Fibonacci Polynomial, 21Full adder, 7Functions, 25

Graphs of Quantified Predicate, 9Greatest Common Divisor, 35Growth of Arithmetic and Geometric

Sequences, 13

HomeworkCalculating Grades, 6

IEEE 754, 28Induction, 21

Logic, 7Quantifying Predicates, 9

Making teams, 21

Number Systems, 27Number Theory, 31

Partial Orders, 23Partitions of a Positive Integer, 15

Pascal,Blaise, 31Permutations, 16Pigeons and Pigeonholes, 35Proofs, 35

Rational Numbers, 27Base Two, 27Fixed Point Representation, 28Floating Point Number Representation,

28Recursion, 15Relations, 23Relationship between powers of x, Falling

Factorials, and Second StirlingNumbers, 21

Sensible Numbers, 35Sequences, 13

Ascents, 16Sets, 11

Bits B = 0, 1, 23Integers Z = 0, ±1, ±2, . . ., 24Natural Numbers N = 0, 1, 2, . . ., 23

Summations, 19

Trapezoid Rule, 19