1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
2 Section 2.5 Integers and Algorithms
3 Lemma (A short theorem not used for much except proving another theorem) Let a = bq + r, where a,b,q and r are integers. Then gcd(a,b) = gcd(b,r)
4 Euclidean Algorithm procedure gcd(a,b: positive integers) x := a y := b while y > 0 begin r := x mod y x := y y := r end {gcd(a,b) is x}
5 Example 18 = (1)(12) = (2)(6) + 0 gcd(12,18)
6 Example 18 = (1)(12) = (2)(6) + 0 gcd(12,18)
7 Example gcd(123,277) 277 = (2)(123) = (3)(31) = (1)(30) = (30)(1) + 0
8 Representation of Integers Let b be a positive integer greater than 1. Then if n is a positive integer, it can be expressed uniquely in the form where k is a nonnegative integer, a 0,a 1,…,a k are nonnegative integers less than b, and Which means?????
9 You can change bases 351 = ( ) = ( 537) = (15F) = (253) 12
10 People There are only 10 types of people. Those who understand binary numbers and those who don’t.
11 How? 351 = (29)(12) = (2)(12) = (0)(12) + 2 The remainders tell us the number in base = Convert 351 to base 12
12 Convert 351 to base 16 (hex) 351 = 21(16) + 15 (F in base 16) 21 = 1(16) +5 Therefore 351 = 15F 16 1 = 0(16) +1
13 How About the Other Way? = = 351
14 Special Relationships
15 Special Relationships
16 Special Relationships
17 Special Relationships
18 Special Relationships = 537 8
19 Try it Again
20 This time, group by 4 bits F
21 Special Relationships F5
22 Special Relationships F51
23 Special Relationships F = 15F 16
E M range
25 Addition of Integers procedure add(a,b: positive integers) c := 0 for j := 0 to n-1 begin d := (a j + b j + c)/2 s j := a j + b j + c - 2d c := d end s n := c
26 Multiplying Integers procedure multiply(a,b: positive integers) for j := 0 to n-1 begin if b j = 1 then c j := a shifted j places else c j := 0 end p := 0 for j := 0 to n - 1 p := p + c j
27 finished