CSE 504 Discrete Mathematics & Foundations of Computer Science

Slides:



Advertisements
Similar presentations
Section 4.1: Primes, Factorization, and the Euclidean Algorithm Practice HW (not to hand in) From Barr Text p. 160 # 6, 7, 8, 11, 12, 13.
Advertisements

CSE115/ENGR160 Discrete Mathematics 03/13/12 Ming-Hsuan Yang UC Merced 1.
Number Theory and Cryptography
CSE115/ENGR160 Discrete Mathematics 03/17/11 Ming-Hsuan Yang UC Merced 1.
1 Section 2.5 Integers and Algorithms. 2 Euclidean algorithm for finding gcd Where L is a larger number, and S is a smaller number, to find gcd(L,S):
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Chapter 02 Binary Values and Number Systems Nell Dale & John Lewis.
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
BY MISS FARAH ADIBAH ADNAN IMK
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU1.
CSCI 1900 Discrete Structures
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 2): The Fundamentals: Algorithms, the.
9/2/2015Discrete Structures1 Let us get into… Number Theory.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
February 24, 2015Applied Discrete Mathematics Week 4: Number Theory 1 Modular Arithmetic Let a be an integer and m be a positive integer. We denote by.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
CS105 INTRODUCTION TO COMPUTER CONCEPTS BINARY VALUES & NUMBER SYSTEMS Instructor: Cuong (Charlie) Pham.
1 Discrete Structures ICS-252 Dr. Ahmed Youssef 1.
3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors Let each of a and b be integers. We say that a divides b, in symbols a | b, provided.
MATH 224 – Discrete Mathematics
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
1 Number SystemsLecture 8. 2 BINARY (BASE 2) numbers.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
CPS120: Introduction to Computer Science Computer Math: Converting to Decimal.
Positional Notation 642 in base 10 positional notation is:
Chapter Integers and Algorithms Representations of integers
Foundations of Discrete Mathematics Chapter 4 By Dr. Dalia M. Gil, Ph.D.
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
AF2. Turn off your phones Primes, gcd, some examples, reading.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Module #9 – Number Theory 6/11/20161 Chapter 3 Algorithms, Integers and Matrices.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
Chapter 3 The Fundamentals: Algorithms, the integers, and matrices Section 3.4: The integers and division Number theory: the part of mathematics involving.
Agenda Review:  Relation Properties Lecture Content:  Divisor and Prime Number  Binary, Octal, Hexadecimal Review & Exercise.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
Introduction To Number Systems
The Euclidean Algorithm
CS 210 Discrete Mathematics The Integers and Division (Section 3.4)
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
CSE 504 Discrete Mathematics & Foundations of Computer Science
CSE15 Discrete Mathematics 03/15/17
Chapter 02 Nell Dale & John Lewis.
CMSC Discrete Structures
CSE 102 Introduction to Computer Engineering
Number Theory and Cryptography
Number System conversions
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
Applied Discrete Mathematics Week 4: Number Theory
Foundations of Discrete Mathematics
Enough Mathematical Appetizers!
Week #5 – 23/25/27 September 2002 Prof. Marie desJardins
Chapter 2 Number Systems.
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Copyright © Cengage Learning. All rights reserved.
Representations of Integers
Divisibility and Modular Arithmetic
Number Theory.
Chapter 11 (Part 2): Boolean Algebra
Chapter 8 (Part 2): Relations
Number Theory and Cryptography
Presentation transcript:

CSE 504 Discrete Mathematics & Foundations of Computer Science Dr. Djamel Bouchaffra Chapter 3 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices Integers & Algorithms (Section 3.6) © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Ch. 2 (Part 2) Section 2.5 & 2.7

Integers & Algorithms (3.6) Introduction Algorithm is a set a procedures that handle arithmetic operations Use binary representations to enter the world of computer arithmetic Good illustration of the complexity of an algorithm Role of the Euclidean algorithm Base b expansion and modular exponentiation, important in cryptography CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Representations of integers Theorem 1 Let b be a positive integer grater than 1. Then if n is a positive integer, it can be expressed uniquely in the form n = akbk + ak-1bk-1 +…+ a1b + a0, where k is a nonnegative integer, a0, a1, …,ak are nonnegative integers less than b, and ak  0. The representation of n given in theorem 1 is known as the base b expansion of n. CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Example: What is the decimal expansion of the integer that has (1 0101 1111)2 as its binary expansion? Solution: (1 0101 1111)2 = 1*28 + 0*27 + 1*26 + 0*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20 = 351 CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Hexadecimal expansions = base 16 expansion 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F The letters A through F represent the digits corresponding to the number 10 through 15. Example: What is the decimal expansion of the hexadecimal expansion of (2AE0B)16? Solution: (2AE0B)16 = 2*164 + 10*163 + 14*162 + 0*161 + 11*160 = (175627)10 Each hexadecimal digit can be represented using 4 bits. (1110 0101)2 = (E5)16 (E16 = (1110)2 ; 516 = (0101)2) Bytes: bit strings of length 8 represented by two hexadecimal digits. CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Representations of integers (cont.) Base conversion Example: Find the base 8 (or octal) expansion of (12345)10 Solution: First, divide 12345 by 8. 12345 = 8 * 1543 + 1 1543 = 8 * 192 + 7 192 = 8 * 24 + 0 24 = 8 * 3 +0 3 = 8 * 0 + 3  (12345)10 = (30071)8 CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Example: Find the hexadecimal expansion of (11 1110 1011 1100)2 and the binary expansion of (A8D)16. Solution: Form blocks of 4 digits and add zeros at the start of the leftmost block if necessary. They are: 0011, 1110, 1011 and 1100. Convert each binary block into decimal (0011)2 = 316; (1110)2 = E16; (1011)2 = B16; (1100)2 = C16 Therefore, (11 1110 1011 1100)2 = (3EBC)16. The conversion of (A8D)16 into binary notation requires replacing each hexadecimal digit by a block of 4 binary digits. They are: A16 = (1010)2, 816 = (1000)2, D16 = (1101)2 CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Algorithms for integer operations Goal 1: Compute the sum of two integers expressed with their binary expansions. The complexity will be based on the number of bits used. a = (an-1an-2 … a1a0)2, b = (bn-1bn-2 … b1b0)2 a + b? (sum of two n-bits numbers) First: a0 + b0 = c0* 2 + s0 where s0 = rightmost bit in the binary expansion of a + b c0 = carry = 0 or 1. Second: a1 + b1 + c0 = c1* 2 + s1 where s1 = next bit of the sum expansion c1 = carry … a + b = (snsn-1sn-2 … s1s0)2 CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Example: Add a = (1110)2 and b = (1011)2 Solution: a0 + b0 = 0 + 1 = 0 * 2 + 1  c0 = 0, s0 = 1 a1 + b1 + c0 = 1 + 1 + 0 = 1 * 2 + 0  c1 = 1, s1 = 0 a2 + b2 + c1 = 1 + 0 + 1 = 1 * 2 + 0  c2 = 1, s2 = 0 a3 + b3 + c2 = 1 + 1 + 1 = 1 * 2 + 1  c3 = 1, s3 = 1  s4 = c3 = 1  a + b = (1 1001)2 1 = a = b 1 1 = c CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Goal 2: Compute the product since b = bn-1bn-2…b1b0 then: ab = a (b020 + b121 + … + bn-12n-1) = a (b020) + a(b121) + … + a(bn-12n-1) Using this latter equation, we can compute a * b. abj = a if bj = 1 and 0 otherwise. Each time we multiply a term by 2, we shift its binary expansion one place to the left and add a zero at the tail end of the expansion. CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Example: Find the product of a = (110)2 and b = (101)2 Solution: ab020 = (110)2 * 1 * 20 = (110)2 ab121 = (110)2 * 0 * 21 = (0000)2 (4 zeros-shift) ab222 = (110)2 * 1 * 22 = (11000)2 add 2-zero bits CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) To find the product, we need to perform: (110)2 + (0000)2 + (11000)2 ab = (11110)2 Other exercise: check for example: 7 * 5 = 35 is true in binary expansion. 1 CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) The Euclidean algorithm Goal: Compute the great common divisor (gcd) of two integers avoiding the prime factorization of each number which is time-consuming. CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Illustration: Find gcd(91, 287) Divide 287 (the larger) by 91 (the smaller) 287 = 91 * 3 + 14 Any divisor of 91 and 287 must be a divisor of 287 – 91 * 3 =14 (Theorem 1, part 1 & 2) Any divisor of 91 and 14 divides 287 = 91 * 3 + 14 gcd(91,287) = gcd(91,14) Next divide 91 by 14 to obtain: 91 = 14 * 6 + 7 Using the same reasoning, our next step is to: Divide 14 by 7: 14 = 7 * 2 since 7/14  gcd(14,7) = 7. But since gcd(287,91) = gcd(91,14) = gcd (14,7) = 7, we have solved the problem CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices

Integers & Algorithms (3.6) (cont.) Lemma 1: Let a = bq + r, where a, b, q and r are integers. Then we can write: gcd(a,b) = gcd(b,r) Example: Determine the gcd of 414 and 662 using the Euclidean algorithm. Solution: 662 = 414 * 1 + 248 414 = 248 * 1 + 166 248 = 166 * 1 + 82 166 = 82 * 2 + 2 82 = 2 * 41 Therefore: gcd(414,662) = 2 (since 2 is the last nonzero remainder !) CSE 504, Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices