COMPSCI 102 Introduction to Discrete Mathematics.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Computer Science CSC 474Dr. Peng Ning1 CSC 474 Information Systems Security Topic 2.3 Basic Number Theory.
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
February 19, 2015Applied Discrete Mathematics Week 4: Number Theory 1 The Growth of Functions Question: If f(x) is O(x 2 ), is it also O(x 3 )? Yes. x.
Ancient Wisdom: Primes, Continued Fractions, The Golden Ratio, and Euclid’s GCD Great Theoretical Ideas In Computer Science Anupam GuptaCS Fall.
Factors, Fractions, and Exponents
Elementary Number Theory and Methods of Proof. Basic Definitions An integer n is an even number if there exists an integer k such that n = 2k. An integer.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
Section Section Summary Recursive Algorithms Proving Recursive Algorithms Correct Recursion and Iteration (not yet included in overheads) Merge.
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Lecture 4 Discrete Mathematics Harper Langston. Algorithms Algorithm is step-by-step method for performing some action Cost of statements execution –Simple.
Great Theoretical Ideas in Computer Science.
College Algebra Fifth Edition
WHOLE NUMBERS; INTEGERS Whole numbers: Z 0,+ = the natural numbers  {0}. Integers:
Great Theoretical Ideas in Computer Science for Some.
BY MISS FARAH ADIBAH ADNAN IMK
Great Theoretical Ideas in Computer Science.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Simplifying Rational Expressions.
CSCI 1900 Discrete Structures
Great Theoretical Ideas in Computer Science.
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
Sequences Informally, a sequence is a set of elements written in a row. – This concept is represented in CS using one- dimensional arrays The goal of mathematics.
COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
MATH 224 – Discrete Mathematics
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
Recursive. 2 Recursive Definitions In a recursive definition, an object is defined in terms of itself. We can recursively define sequences, functions.
INDUCTION AND RECURSION. PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function,
Review Introduction to Searching External and Internal Searching Types of Searching Linear or sequential search Binary Search Algorithms for Linear Search.
1 Introduction to Abstract Mathematics Chapter 3: Elementary Number Theory and Methods of Proofs Instructor: Hayk Melikya Direct.
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Factor Each Expression Section 8.4 Multiplying and Dividing Rational Expressions Remember that a rational number can be expressed as a quotient.
CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative.
1 Section 2.1 Functions: Definitions and Examples A function ƒ from A to B associates each element of A with exactly one element of B. Write ƒ : A  B.
Algorithms 1.Notion of an algorithm 2.Properties of an algorithm 3.The GCD algorithm 4.Correctness of the GCD algorithm 5.Termination of the GCD algorithm.
MA/CSSE 473 Day 06 Euclid's Algorithm. MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm.
4/3/2003CSE More Math CSE Algorithms Euclidean Algorithm Divide and Conquer.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Application: Algorithms Lecture 20 Section 3.8 Wed, Feb 21, 2007.
Lesson 2-5. Refresher Simplify the following expressions
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
MA/CSSE 473 Day 07 Euclid's Algorithm. MA/CSSE 473 Day 07 Student Questions Review topics not covered in class Euclid's algorithm (if there is time) extended.
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Slide Copyright © 2009 Pearson Education, Inc. Slide Copyright © 2009 Pearson Education, Inc. Chapter 1 Number Theory and the Real Number System.
Great Theoretical Ideas in Computer Science.
Simplifying. Multiplying and Dividing Rational Expressions Remember that a rational number can be expressed as a quotient of two integers. A rational.
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
Administrative Details Grade – 80% test, 20% homework 4-5 homework assignments Office hours after lesson Tel
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
A Prime Example CS Lecture 20 A positive integer p  2 is prime if the only positive integers that divide p are 1 and p itself. Positive integers.
Recursive Algorithms Section 5.4.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Administrative Details
Advanced Algorithms Analysis and Design
Great Theoretical Ideas in Computer Science
Number Theory and Modular Arithmetic
Numerical Algorithms x x-1
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Great Theoretical Ideas In Computer Science
Applied Discrete Mathematics Week 9: Integer Properties
Application: Algorithms
Application: Algorithms
Introduction to Algorithms
Presentation transcript:

COMPSCI 102 Introduction to Discrete Mathematics

A familiar problem Flip a fair coin until it comes up tails. HHHHHHHT Let X be a random variable denoting the number of heads.

How do we solve this? Look at small values. Hypothesis: If hypothesis holds, Let

Proof by Induction Hypothesis: Base case: Holds for n ≤ 6 Inductive step:

Recurrences on Expectations Flip a fair coin until it comes up tails. HHHHHHHT Let X be a random variable denoting the number of heads.

Why does this work? Let Y denote number of heads in first coin toss. Let Z denote number in remaining tosses. If Y = 0, then X = 0, Z = 0. If Y = 1, then X = 1 + Z. E[X|Y=0] = 0. E[X|Y=1] = 1 + E[Z|Y=1] = 1 + E[X].

Rules of the Game Each person will have a unique number For each question, I will first give the class time to work out an answer. Then, I will call three different people at random They must explain the answer to me. If I’m satisfied, the class gets points. If the class gets 1,700 points, then you win

GCD DEFINITION ALGO PROPERTIES GCD ALGORITHM CONVER- GENTS EXAMPLES RUNNING TIME AN ALGORITHM CONTINUED FRACTIONS

1. The Greatest Common Divisor (GCD) of two non-negative integers A and B is defined to be: 2. As an example, what is GCD(12,18) and GCD(5,7) The largest positive integer that divides both A and B GCD(12,18) = 6 GCD(5,7)=1

A Naïve method for computing GCD(A,B) is: Give an algorithm to compute GCD(A,B) that does not require factoring A and B into primes, and does not simply try dividing by most numbers smaller than A and B to find the GCD. Run your algorithm to calculate GCD(67,29) Factor A into prime powers. Factor B into prime powers. Create GCD by multiplying together each common prime raised to the highest power that goes into both A and B. Euclid(A,B) = Euclid(B, A mod B) Stop when B=0

Euclid’s GCD algorithm can be expressed via the following pseudo-code: Euclid(A,B) If B=0 then return A else return Euclid(B, A mod B) Show that if this algorithm ever stops, then it outputs the GCD of A and B GCD(A,B) = GCD(B, A mod B) ( d | A and d | B )  ( d | (A - kB ) and d | B ) The set of common divisors of A, B equals the set of common divisors of B, A - kB Proof:

Show that the running time for this algorithm is bounded above by 2log 2 (max(A,B)) Proof: Claim: A mod B < ½ A If B = ½ A then A mod B = 0 If B < ½ A then any X Mod B < B < ½ A If B > ½ A then A mod B = A - B < ½ A Euclid(A,B) = Euclid(B, A mod B) Stop when B=0 GCD(A,B) calls GCD(B, <½A) Proof of Running Time: which calls GCD(<½A, B mod <½A) Every two recursive calls, the input numbers drop by half

DAILY DOUBLE

A simple continued fraction is an expression of the form: a + b + c + d + e + … Where a,b,c,d,e, … are non-negative integers. We denote this continued fraction by [a,b,c,d,e,…]. What number do the fractions [3,2,1] and [1,1,1] represent? (simplify your answer) [3,2,1] = 10/3 [1,1,1] = 3/2

Letr 1 = [1] r 2 = [1,1] r 3 = [1,1,1] r 4 = [1,1,1,1] : Find the value of r n as a ratio of something we’ve seen before (prove your answer) r n = Fib(n+1)/F(n) Fib(n+1) Fib(n) Fib(n)+Fib(n-1) Fib(n) =1 + 1 Fib(n) Fib(n-1) =

Let  = [a 1, a 2, a 3,...] be a continued fraction Define:C 1 = [a 1 ] C 2 = [a 1,a 2 ] C 3 = [a 1,a 2,a 3 ] : C k is called the k-th convergent of   is the limit of the sequence C 1, C 2, C 3,… A rational p/q is the best approximator to a real  if no rational number of denominator smaller than q comes closer to  Given any CF representation of , each con- vergent of the CF is a best approximator for 

C 1 = 3 C 2 = 22/7 C 3 = 333/106 C 4 = 355/113 C 5 = /33102 C 6 =104348/33215 Find best approximators for  with denominators 1, 7 and 113

1. Write a continued fraction for 67/ Write a formula that allows you to calculate the continued fraction of A/B in 2log 2 (max(A,B)) steps