1 / 18

Chapter 1 Introduction Mathematics Review

Chapter 1 Introduction Mathematics Review. Sections 1.1, 1.2. Outline. Why does program execution time for large inputs matter? Basic mathematical background. Selection Problem. Find the k th largest number from a group of N numbers How would you solve this? Algorithm 1:

astra
Télécharger la présentation

Chapter 1 Introduction Mathematics Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1IntroductionMathematics Review Sections 1.1, 1.2

  2. Outline • Why does program execution time for large inputs matter? • Basic mathematical background

  3. Selection Problem • Find the kth largest number from a group of N numbers • How would you solve this? • Algorithm 1: • Sort the N numbers and pick the kth one. • Easy to implement, but • Sorting requires many comparisons • Much work comparing elements having no chance to be at position K • To sort N elements, need N log2(N) comparisons/swaps in general • An unsorted data set with 10,000,000 elements and 1,000 swaps/sec will take around 2 hours

  4. Selection Problem (Cont’d) • Algorithm 2: (Better) • Sort first K elements in the array. • Then insert elements (K+1) to N, discarding the smallest element each time. • Then pick the kth element. • What if N=10 million and K=5,000,000? • How long do you think this would take? • Both algorithms are impractical. • A better algorithm can solve this in a second!

  5. Mathematics Review • Exponents • Logarithms • Series • Modular arithmetic • Proof techniques

  6. Exponents

  7. Logarithms • All logarithms are to the base 2, unless otherwise specified • Definition 1.1 • XA = B if and only if logxB = A

  8. Properties of logarithms • Theorem 1.1 (base-change) • ; A, B, C > 0, A  1 • Proof: Let X = logCB, Y = logCA, and Z = logAB • Then: CX = B, CY = A, and AZ = B • Implies: B = CX = (CY)Z = CYZ • Hence: X = YZ • And: Z = X/Y

  9. Logarithms (contd.) • Theorem 1.2 • log(AB) = log A + log B; A, B > 0 • Proof: (Assume base 2) • Let: X = log A, Y = log B, and Z = log AB • Hence: 2X = A, 2Y = B, and 2Z = AB • Combining the above: 2Z = AB = 2X2Y = 2(X+Y) • Implies: X + Y = Z

  10. Logarithms (contd.) • More results • log(A/B) = log A – log B • log(AB) = B log A • log X < X for all X > 0 • log 1 = 0 • log2 2 = 1 • log2 1024 = 10 • log2 1,048,576 = 20

  11. Geometric Series • If 0 < A < 1, • If N -> , we have • How??

  12. Arithmetic Series • How about 2+5+8+…+(3k-1) ?

  13. Modular Arithmetic • We say that A is congruent to B modulo N • Written as (mod N) • If N divides (A-B) • In other words, the remainder is the same if either A or B are divided by N • E.g. • (mod 10) • Similar to equality, if (mod N), then • (mod N), and (mod N)

  14. Proof techniques • Two common proof techniques in data structure and algorithm analysis (and in CS, in general) • Proof by induction • Proof by contradiction • Another common technique • Proof a statement false with a counterexample

  15. Proof by Induction • Given a theorem • First prove a base case • Show the theorem is true for some small degenerate values • Next assume an inductive hypothesis • Assume the theorem is true for all cases up to some limit k • Then prove that the theorem holds for the next value (k+1)

  16. Proof by Induction - example • Fibonacci Series • F0 = 1, F1 = 1, Fi = F(i-1) + F(i-2), for i>1 • Show that • Fi < (5/3)i,for i>0 • Base case: • F1 = 1 < 5/3 • F2 = 2 < (5/3)2=25/9 • Inductive Hypothesis • Assuming: Fi < (5/3)i , i = 1, 2, ..., k

  17. Proof by Induction - example (contd.) • Now prove that Fk+1 < (5/3)k+1 • From definition of Fibonacci Sequence • Fk+1 = Fk + Fk-1 • Using inductive hypothesis Fk+1 < (5/3)k+ (5/3)k-1 = (5/3)k+1[ 3/5 + (3/5)2]= (5/3)k+1[24/25]< (5/3)k+1

  18. Other types of proofs • Disprove with a counter-example • The statement is false in the Fibonacci series • Proof: F11 = 144 > 112 = 121 • Proof by contradiction • Initially assume that the theorem is false • Then show that some known property would be false as well. • Example: “There is an infinite number of prime numbers” • Proof: • Assume the theorem is false (so there are only finite prime) • Let P1, P2, ..., Pk be all the primes in increasing order. • Let N =P1P2 Pk + 1,N is > Pk , so it is not a prime • But it is also not divisible by any of the listed primes, contradicting the factorization of integers into primes. • We reach a contradiction

More Related