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

Post on 12-Jan-2016

257 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 1: Chapter 1: IntroductionIntroduction

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

ExponExponentsents

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

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

• (Xa )b = Xab

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

LogarithmsLogarithms

• loga(XY) = logaX + logaY

• loga(X/Y) = logaX – logaY

• loga(Xn) = nlogaX

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

• a loga x = x

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.

Recursive DefinitionsRecursive Definitions

• Terminating ruleTerminating rule - defining the object explicitly.

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

ExamplesExamples

• Factorials N!f(n) = n!

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

ExamplesExamples

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

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

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

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))

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 → ∞.

Some DerivativesSome Derivatives

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

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

ProofsProofs

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

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

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

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

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.

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

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.

GENERIC COMPONENTS IN JAVA

Study Generic syntax in Java 1.5 API

top related