Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,

Slides:



Advertisements
Similar presentations
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Advertisements

Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Sets, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides.
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Chapter 4 Properties of the integers: mathematical induction Yen-Liang Chen Dept of IM NCU.
Inverses and GCDs Supplementary Notes Prepared by Raymond Wong
Discrete Structures Chapter 2 Part B Mathematical Induction
4/17/2017 Section 3.6 Program Correctness ch3.6.
Section Section Summary Recursive Algorithms Proving Recursive Algorithms Correct Recursion and Iteration (not yet included in overheads) Merge.
Lecture 4 Discrete Mathematics Harper Langston. Algorithms Algorithm is step-by-step method for performing some action Cost of statements execution –Simple.
More on Recursion Averting Program Crashes CSC 1401: Introduction to Programming with Java Week 9 – Lecture 3 Wanda M. Kunkle.
BY MISS FARAH ADIBAH ADNAN IMK
Divisibility October 8, Divisibility If a and b are integers and a  0, then the statement that a divides b means that there is an integer c such.
CSCI 1900 Discrete Structures
1 Properties of Integers Objectives At the end of this unit, students should be able to: State the division algorithm Apply the division algorithm Find.
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.
Reading and Writing Mathematical Proofs
Chapter 1 Introduction. Goals Why the choice of algorithms is so critical when dealing with large inputs Basic mathematical background Review of Recursion.
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.
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,
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Copyright © Cengage Learning. All rights reserved. CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF.
WIKIPEDIA HAS MANY MORE DIVISIBILITY RULES. EXAMPLE Since 52=13(4) is divisible by 4, is divisible by 4 Since 452=56(8)+4 is not divisible.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Mar 3, 2006.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Recursive Algorithms &
Copyright © 2009 Pearson Education, Inc. Chapter 5 Section 1 - Slide 1 Chapter 1 Number Theory and the Real Number System.
MAT 320 Spring 2008 Section 1.2.  Start with two integers for which you want to find the GCD. Apply the division algorithm, dividing the smaller number.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Feb 18, 2005.
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.
Chapter 4: Elementary Number Theory and Methods of Proof 4.8 Application: Algorithms 1 Begin at the beginning…and go on till you come to the end: then.
Euclidean Algorithm How to find a greatest common divisor in several easy steps.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
Application: Algorithms Lecture 20 Section 3.8 Wed, Feb 21, 2007.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
1 Computer Algorithms Tutorial 2 Mathematical Induction Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
5-5 Indirect Proof. Indirect Reasoning: all possibilities are considered and then all but one are proved false. The remaining possibility must be true.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Slide Copyright © 2009 Pearson Education, Inc. Slide Copyright © 2009 Pearson Education, Inc. Chapter 1 Number Theory and the Real Number System.
Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Fuw-Yi Yang1 Textbook: Introduction to Cryptography 2nd ed. By J.A. Buchmann Chap 1 Integers Department of Computer Science and Information Engineering,
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Recursive Algorithms Section 5.4.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Advanced Algorithms Analysis and Design
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Mathematical Induction Recursion
Proofs, Recursion and Analysis of Algorithms
Copyright © Cengage Learning. All rights reserved.
Axiomatic semantics Points to discuss: The assignment statement
CSE 311: Foundations of Computing
The Division Algorithm
Applied Discrete Mathematics Week 9: Integer Properties
Topic Past Papers –Proofs
Application: Algorithms
Application: Algorithms
Useful GCD Fact If a and b are positive integers, then gcd(a,b) = gcd(b, a mod b) Proof: By definition of mod, a = qb+ (a mod b) for.
Recursion.
Sets, Combinatorics, Probability, and Number Theory
Program Correctness an introduction.
Data Structures & Programming
Presentation transcript:

Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs, Recursion, and Analysis of Algorithms

Section 2.3More on Proof of Correctness1 Loop Rule Suppose that s i is a loop statement in the form: while condition B do P end while where B is a condition that is either true or false and P is a program segment. The precondition Q holds before the loop is entered and after it terminates. The Loop Rule of inference states that we can derive {Q} s i {Q Λ B} from {Q Λ B} P {Q} Because it may not be known exactly when the loop will terminate, Q must remain true after each iteration through the loop. Q represents a predicate, or relation, among the values of the program variables. The loop invariant is the relation among these variables unaffected by the action of the loop iteration.

Section 2.3More on Proof of Correctness2 Euclidean Algorithm The Euclidean algorithm finds the greatest common divisor of two positive integers a and b. The greatest common divisor of a and b, denoted by gcd(a, b), is the largest integer n such that n|a and n|b. For example, gcd(12, 18) = 6 and gcd(420, 66) = 6. The Euclidean algorithm works by a succession of divisions. To find gcd(a, b), assuming that a >= b, you first divide a by b, getting a quotient and a remainder. Next, you divide the divisor, b, by the remainder and keep doing this until the remainder is 0, at which point the greatest common divisor is the last divisor used.

Section 2.3More on Proof of Correctness3 Euclidean Algorithm ALGORITHM: Euclidean algorithm GCD(positive integer a; positive integer b) //a  b Local variables: integers i, j i = a j = b while j != 0 do compute i = qj + r, 0  r < j i = j j = r end while //i now has the value gcd(a, b) return i; end function GCD

Section 2.3More on Proof of Correctness4 Euclidean Algorithm Proof To prove the correctness of this function, we need one additional fact: (  integers a, b, q, r)[(a = qb + r)  (gcd(a, b) = gcd(b, r))] Using function GCD, we will prove the loop invariant Q: gcd(i, j) = gcd(a, b) and evaluate Q when the loop terminates. We use induction to prove: Q(n): gcd(i n, j n ) = gcd(a, b) for all n  0. Q(0) is gcd(i 0, j 0 ) = gcd(a, b) is true because when we first get to the loop statement, i and j have the values a and b. Assume Q(k): gcd(i k, j k ) = gcd(a, b). Show Q(k + 1): gcd(i k + 1, j k + 1 ) = gcd(a, b).

Section 2.3More on Proof of Correctness5 Euclidean Algorithm Proof By the assignment statements within the loop body, we know that i k + 1 = j k j k + 1 = r k Then, by the additional fact on the previous slide: gcd(i k + 1, j k + 1 ) = gcd(j k, r k ) = gcd(i k, j k ) By the inductive hypothesis, the above is equal to gcd(a, b) Q is therefore a loop invariant. At loop termination, gcd(i, j) = gcd(a, b) and j = 0, so gcd(i, 0) = gcd(a, b). But gcd(i, 0) is i, so i = gcd(a, b). Therefore, function GCD is correct.