Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,

Similar presentations


Presentation on theme: "1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,"— Presentation transcript:

1 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 2 Section 2.5 Integers and Algorithms

3 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 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 5 Example 18 = (1)(12) + 6 12 = (2)(6) + 0 gcd(12,18)

6 6 Example 18 = (1)(12) + 6 12 = (2)(6) + 0 gcd(12,18)

7 7 Example gcd(123,277) 277 = (2)(123) + 31 123 = (3)(31) + 30 31 = (1)(30) + 1 30 = (30)(1) + 0

8 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 9 You can change bases 351 = (101011111) 2 351 = ( 537) 8 351 = (15F) 16 351 = (253) 12

10 10 People There are only 10 types of people. Those who understand binary numbers and those who don’t.

11 11 How? 351 = (29)(12) + 3 29 = (2)(12) + 5 2 = (0)(12) + 2 The remainders tell us the number in base 12 351 = 2 5 3 12 Convert 351 to base 12

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 13 How About the Other Way? 537 8 = 320 + 24 + 7 = 351

14 14 Special Relationships 101011111

15 15 Special Relationships 101011111 7

16 16 Special Relationships 101011111 73

17 17 Special Relationships 101011111 735

18 18 Special Relationships 101011111 735 101011111 2 = 537 8

19 19 Try it Again 101011111

20 20 This time, group by 4 bits 101011111 F

21 21 Special Relationships 101011111 F5

22 22 Special Relationships 101011111 F51

23 23 Special Relationships 101011111 F51 101011111 2 = 15F 16

24 24 0000 0001 0010 0011 0101 0100 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 001010011100101110111 E M range

25 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 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 27 finished


Download ppt "1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,"

Similar presentations


Ads by Google