Chapter 2 - Mathematical Review Functions

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Lecture 2 Based on Chapter 1, Weiss. Mathematical Foundation Series and summation: ……. N = N(N+1)/2 (arithmetic series) 1 + r+ r 2 + r 3 +………r.
A simple example finding the maximum of a set S of n numbers.
Appendix B Solving Recurrence Equations : With Applications to Analysis of Recursive Algorithms.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
Algorithmics - Lecture 71 LECTURE 7: Algorithms design techniques - Decrease and conquer -
11 Computer Algorithms Lecture 6 Recurrence Ch. 4 (till Master Theorem) Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Proof Techniques and Recursion. Proof Techniques Proof by induction –Step 1: Prove the base case –Step 2: Inductive hypothesis, assume theorem is true.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Analysis of Algorithms
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Analysis of Algorithms
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Chapter 1 Introduction. Goals Why the choice of algorithms is so critical when dealing with large inputs Basic mathematical background Review of Recursion.
Chapter 7 Recursion 1CSCI 3333 Data Structures. 2 Recurrent Sequence A recursively defined sequence – First, certain initial values are specified  c.f.,
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
Project 2 due … Project 2 due … Project 2 Project 2.
CSC201 Analysis and Design of Algorithms Asst.Proof.Dr.Surasak Mungsing Oct-151 Lecture 2: Definition of algorithm and Mathematical.
Methods of Proofs PREDICATE LOGIC The “Quantifiers” and are known as predicate quantifiers. " means for all and means there exists. Example 1: If we.
Chapter 2 Mathematical preliminaries 2.1 Set, Relation and Functions 2.2 Proof Methods 2.3 Logarithms 2.4 Floor and Ceiling Functions 2.5 Factorial and.
Methods of Proof Lecture 3: Sep 9. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 2: Mathematical Foundations.
Design of Algorithms by Induction Part 1 Algorithm Design and Analysis Week 3 Bibliography: [Manber]- Chap.
Chapter 1 - Mathematical Review Functions Factorial - x!=1*2*3*…..*x Permutation - a rearrangement of a sequence Boolean variable - takes on 2 values –
Mathematical Background and Linked Lists. 2 Iterative Algorithm for Sum Find the sum of the first n integers stored in an array v : sum (v[], n) temp_sum.
Basic Mathematics Chapter 1 (1.2 and 1.3) Weiss. Recursion / Slide 2 Logarithms * Definition: if and only if * Theorem 1.1: n Proof: apply the definition.
CSC401 – Analysis of Algorithms Lecture Notes 2 Asymptotic Analysis Objectives: Mathematics foundation for algorithm analysis Amortization analysis techniques.
Logical Reasoning:Proof Prove the theorem using the basic axioms of algebra.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
Cpt S 223 – Advanced Data Structures Math Review 2
Introduction to Algorithms Chapter 4: Recurrences.
Chapter 1: Introduction
Algorithm Analysis Part of slides are borrowed from UST.
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.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Math Review 1.
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction Linda Shapiro Winter 2015.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.
Master Method Some of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Recurrences (in color) It continues…. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. When an algorithm.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
1 Review for Quiz 1. 2 Summations 3 Binomial expansion.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Proofs by Counterexample & Contradiction There are several ways to prove a theorem:  Counterexample: By providing an example of in which the theorem.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Recursion Ali.
11.7 – Proof by Mathematical Induction
Analysis of Algorithms CS 477/677
Fundamental Data Structures and Algorithms
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Mathematical Induction Recursion
Analysis of Algorithms
Algorithm Analysis (for Divide-and-Conquer problems)
CS 3343: Analysis of Algorithms
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
Divide-and-Conquer 7 2  9 4   2   4   7
Lesson 11 – Proof by induction
Applied Discrete Mathematics Week 9: Integer Properties
Recurrence Equation Masters Theorem
Divide & Conquer Algorithms
Recurrences.
Recursion.
Presentation transcript:

Chapter 2 - Mathematical Review Functions Factorial - x!=1*2*3*…..*n Permutation - a rearrangement of a sequence Boolean variable - takes on 2 values TRUE, FALSE 0, 1 Floor - round down x Ceiling - round up x Modulus - mod - Remainder x mod y - remainder when divide x by y 10 mod 3 is 1

Logarithms logby=x  bx=y  blogby=y log mn = log m + log n XAXB=XA+B log m/n = log m - log n XA/XB=XA-B log nr = r log n (XA)B=XAB logan=logbn/logba 2n+2n=2*2n=2n+1

Recursion A recursive algorithm calls itself. Must have a base case to stop recursion Calls must pass a “smaller problem” to the function. This will cause the recursion to eventually stop. Factorial example: int fact(int n) { if (n<=1) return 1; else return n*fact(n-1) } Looks a bit like induction Better to use for’s and while’s when appropriate.

Summations Adding up a list of values f(1)+f(2)+f(3)+…+f(n) if f(i)=i then sum is n(n+1)/2 if f(i)=i2 then sum is n(n+1)(2n+1)/6 if f(i)=2i then sum is 2n+1–1 if f(i)=Ai then sum is (An+1 –1)/(A-1)

Recurrence Relations Many of our operations (functions) will be recursive. We will want to analyze the running time for a problem of size n. Recursion defines this in terms of some work plus the amount of time to solve a smaller problem (using the same algorithm). A mathematical representation of this time will look like: T(n) = T(n-1) + 1 Need the time for the base case T(1) = 0

Recurrence Relation Solving Many recurrence relations are solved using the brute force method. Expand it; see the pattern; solve it. For example: T(n) = T(n-1)+1 = T(n-1)+1+1 = T(1)+(n-1) = n-1 Another example: T(n) = T(n-1)+n; T(1)=1 T(n) = T(n-1)+n = T(n-2)+(n-1)+n = T(1)+2+…n = 1+2+3…+n = n(n+1)/2

Proof Techniques Proof by Contradiction Proof by induction Find a counterexample to prove theorem is false Assume the opposite of the conclusion is true. Use steps to prove a contradiction (for example 1=2), then the original theorem must be true. Proof by induction Show the theorem holds for a base case (n=0 or n=1) Assume the theorem holds for n=k-1 Prove the theorem is true for n=k Example: show 1+2+3+…+n=n(n+1)/2 for n=1 1=1(2)/2=1 assume 1+2+3+…+n-1=(n-1)(n)/2; show 1+2+…+n=n(n+1)/2 (n-1)(n)/2+n=[(n-1)(n)+2n]/2=[n(n-1+2)]/2=n(n+1)/2