chapter 1: introduction mathematical review (self study) mark allen weiss: data structures and...

21
Chapter 1: Chapter 1: Introduction Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Upload: whitney-gibbs

Post on 12-Jan-2016

256 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Chapter 1: Chapter 1: IntroductionIntroduction

Mathematical Review(self study)

Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Page 2: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Mathematical Review

• ExponentsExponents• LogarithmsLogarithms• Recursive DefinitionsRecursive Definitions• Function GrowthFunction Growth• ProofsProofs

Page 3: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

ExponExponentsents

• X0 = 1 by definition• XaXb = X (a+b)

• Xa / Xb = X (a-b) Show that: X-n = 1 / Xn

• (Xa )b = Xab

Page 4: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

LogarithmsLogarithms

• logaX = Y aY = X , a > 0, X > 0E.G: log28 = 3; 23 = 8

• loga1 = 0 because a0 = 1logX means log2XlgX means log10XlnX means logeX,

where ‘e’ is the natural number

Page 5: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

LogarithmsLogarithms

• loga(XY) = logaX + logaY

• loga(X/Y) = logaX – logaY

• loga(Xn) = nlogaX

• loga b = (log2 b)/ (log2a)

• a loga x = x

Page 6: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Recursive DefinitionsRecursive Definitions

• Basic idea:Basic idea: To define objects, processes and properties in terms of

simpler objects,

simpler processes or

properties of simpler objects/processes.

Page 7: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Recursive DefinitionsRecursive Definitions

• Terminating ruleTerminating rule - defining the object explicitly.

• Recursive rulesRecursive rules - defining the object in terms of a simpler object.

Page 8: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

ExamplesExamples

• Factorials N!f(n) = n!

f(0) = 1 i.e. 0! = 1f(n) = n * f(n-1) i.e. n! = n * (n-1)!

Page 9: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

ExamplesExamples

• Fibonacci numbersF(0) = 1F(1) = 1F(k+1) = F(k) + F(k-1)

1, 1, 2, 3, 5, 8, ….

Page 10: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Function GrowthFunction Growth

• lim ( n ) = ∞, n → ∞• lim ( na ) = ∞, n → ∞, a > 0• lim ( 1 / n ) = 0, n → ∞• lim ( 1 / (na) ) = 0, n → ∞, a > 0• lim ( log( n )) = ∞, n → ∞• lim ( an ) = ∞, n → ∞, a > 0

Page 11: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Function GrowthFunction Growth

• lim (f(x) + g(x)) = lim (f(x)) + lim (g(x))

• lim (f(x) * g(x)) = lim (f(x)) * lim (g(x))

• lim (f(x) / g(x)) = lim (f(x)) / lim (g(x))

• lim (f(x) / g(x)) = lim (f '(x) / g '(x))

Page 12: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

ExamplesExamples

• lim (n/ n2 ) = 0, n → ∞• lim (n2 / n) = ∞, n → ∞• lim (n2 / n3 ) = 0, n → ∞• lim (n3 / n2 ) = ∞, n → ∞• lim (n / ((n+1)/2) = 2, n → ∞.

Page 13: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Some DerivativesSome Derivatives

• (logan)' = (1/n) logae

• (an)' = (an) ln(a)

Page 14: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

ProofsProofs

• Direct proofDirect proof• Proof by inductionProof by induction• Proof by counterexampleProof by counterexample• Proof by contradictionProof by contradiction• Proof by contrapositionProof by contraposition

Page 15: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Direct ProofDirect Proof

Based on the definition of the object / property

Example:

Prove that if a number is divisible by 6 then it is divisible by 2

Proof: Let m divisible by 6.

Therefore, there exists q such that m = 6q

6 = 2 . 3

m = 6q = 2.3.q = 2r, where r = 3q

Therefore m is divisible by 2

Page 16: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Proof by InductionProof by Induction

We use proof by induction when our claim concerns a sequence of cases, which can be numbered

Inductive base: Show that the claim is true for the smallest case, usually k = 0 or k = 1.

Inductive hypothesis: Assume that the claim is true for some k Prove that the claim is true for k+1

Page 17: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Example of Proof by Example of Proof by InductionInduction

Prove by induction that S(N) = Σ 2i = 2 (N+1) - 1, for any integer N ≥ 0

   i=0 to N

1. Inductive baseLet n = 0. S(0) = 20 = 1On the other hand, by the formula S(0) = 2 (0+1) – 1 = 1.Therefore the formula is true for n = 0

2. Inductive hypothesisAssume that S(k) = 2 (k+1) – 1We have to show that S(k+1) = 2(k + 2) -1

By the definition of S(n):S(k+1) = S(k) + 2(k+1) = 2 (k+1) – 1 + 2(k+1) = 2. 2(k+1) – 1 = 2(k+2) – 1

Page 18: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Proof by CounterexampleProof by Counterexample

Used when we want to prove that a statement is false.Types of statements: a claim that refers to all members of a class.

EXAMPLE: The statement "all odd numbers are prime" is false.

A counterexample is the number 9: it is odd and it is not prime.

Page 19: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Proof by ContradictionProof by Contradiction

Assume that the statement is false, i.e. its negation is true.

Show that the assumption implies that some known property is false - this would be the contradiction

Example: Prove that there is no largest prime number

Page 20: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

Proof by ContrapositionProof by Contraposition

Used when we have to prove a statement of the form P Q.

Instead of proving P Q, we prove its equivalent ~Q ~P

Example: Prove that if the square of an integer is odd then the integer is odd

We can prove using direct proof the statement:

If an integer is even then its square is even.

Page 21: Chapter 1: Introduction Mathematical Review (self study) Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

GENERIC COMPONENTS IN JAVA

Study Generic syntax in Java 1.5 API