Data Structures in Java Lecture 5: Sequences and Series, Proofs - - PowerPoint PPT Presentation

data structures in java
SMART_READER_LITE
LIVE PREVIEW

Data Structures in Java Lecture 5: Sequences and Series, Proofs - - PowerPoint PPT Presentation

Data Structures in Java Lecture 5: Sequences and Series, Proofs 9/23/2015 Daniel Bauer 1 Algorithms An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Algorithm Analysis Questions:


slide-1
SLIDE 1

Data Structures in Java

Lecture 5: Sequences and Series, Proofs

9/23/2015

1

Daniel Bauer

slide-2
SLIDE 2

Algorithms

  • An algorithm is a clearly specified set of simple

instructions to be followed to solve a problem.

  • Algorithm Analysis — Questions:
  • Does the algorithm terminate?
  • Does the algorithm solve the problem? (correctness)
  • What resources does the algorithm use?
  • Time / Space

2

slide-3
SLIDE 3

Contents

  • 1. Sequences and Series
  • 2. Proofs

3

slide-4
SLIDE 4

Sequences

  • What are these sequences?
  • 0, 2, 4, 6, 8, 10, …
  • 2, 4, 8, 16, 32, 64, …
  • 1, 1/2, 1/4, 1/8, 1/16, …

4

slide-5
SLIDE 5

Sequences

  • What are these sequences?
  • 0, 2, 4, 6, 8, 10, …
  • 2, 4, 8, 16, 32, 64, …
  • 1, 1/2, 1/4, 1/8, 1/16, …

Arithmetic Sequence

4

slide-6
SLIDE 6

Sequences

  • What are these sequences?
  • 0, 2, 4, 6, 8, 10, …
  • 2, 4, 8, 16, 32, 64, …
  • 1, 1/2, 1/4, 1/8, 1/16, …

Arithmetic Sequence Geometric Sequence

4

slide-7
SLIDE 7

Arithmetic Series

5

slide-8
SLIDE 8

Arithmetic Series

  • Arithmetic Sequence of length N, with start term


a and common difference d. 


5

slide-9
SLIDE 9

Arithmetic Series

  • Arithmetic Sequence of length N, with start term


a and common difference d. 


  • Series: The sum of all elements of a sequence.


5

slide-10
SLIDE 10

Sum-Formulas for Arithmetic Series

  • In particular (for a=1 and d=1):

6

slide-11
SLIDE 11

Geometric Series

7

slide-12
SLIDE 12

Geometric Series

  • Geometric Sequence with start term s and 


common ratio A. 


7

slide-13
SLIDE 13

Geometric Series

  • Geometric Sequence with start term s and 


common ratio A. 


  • Geometric Series:


7

slide-14
SLIDE 14

Geometric Series

  • Geometric Sequence with start term s and 


common ratio A. 


  • Geometric Series:

  • Often 0 < A < 1 or A = 2

7

slide-15
SLIDE 15

Sum-Formulas for Finite Geometric Series

8

slide-16
SLIDE 16

Sum-Formulas for Finite Geometric Series

  • In particular, if s=1

8

slide-17
SLIDE 17

Sum-Formulas for Finite Geometric Series

  • In particular, if s=1
  • In Computer Science we often have A = 2

8

slide-18
SLIDE 18

Sum-Formulas for Infinite Geometric Series

  • nly if 0<A<1

9

slide-19
SLIDE 19

Sum-Formulas for Infinite Geometric Series

  • In particular, if s=1

and

  • nly if 0<A<1

9

slide-20
SLIDE 20

Sum-Formulas for Infinite Geometric Series

  • In particular, if s=1
  • For instance,

and

  • nly if 0<A<1

9

slide-21
SLIDE 21

Analyzing the Towers of Hanoi Recurrence

10

base case: geometric series

slide-22
SLIDE 22

The End of The World

11

Legend says that, at the beginning of time, priests were given a puzzle with 64 golden disks. Once they finish moving all the disks according to the rules, the wold is said to end. If the priests move the disks at a rate of 1 disk/second, how long will it take to solve the puzzle?

slide-23
SLIDE 23

The End of The World

11

Legend says that, at the beginning of time, priests were given a puzzle with 64 golden disks. Once they finish moving all the disks according to the rules, the wold is said to end. If the priests move the disks at a rate of 1 disk/second, how long will it take to solve the puzzle?

slide-24
SLIDE 24

The End of The World

11

Legend says that, at the beginning of time, priests were given a puzzle with 64 golden disks. Once they finish moving all the disks according to the rules, the wold is said to end. If the priests move the disks at a rate of 1 disk/second, how long will it take to solve the puzzle? seconds minutes days years

slide-25
SLIDE 25

Contents

  • 1. Sequences and Series
  • 2. Proofs

12

slide-26
SLIDE 26

Types of Proofs

  • Proof by Induction
  • Proof by Contradiction
  • Proof by Counterexample

13

slide-27
SLIDE 27

Proofs by Induction

  • We are proving a theorem T. (“this property holds for all

cases.”).

  • Step 1: Base case. We know that T holds (trivially) for some

small value.

  • Step 2: Inductive step:
  • Inductive Hypothesis: Assume T holds for all cases up to

some limit k.

  • Show that T also holds for k+1.
  • This proves that T holds for any k.

14

slide-28
SLIDE 28
  • For the Fibonacci numbers, we prove that 


  • Base case: 

  • Inductive step:
  • Assume the theorem holds for i = 1,2,…,k
  • We need to show that 


Proof by Induction - Example

15

slide-29
SLIDE 29

Proof by Induction - Inductive Step

  • We know that and by the

inductive hypothesis:


16

slide-30
SLIDE 30

Proof by Counter-Example

  • We are proving that theorem T is false. (“this

property does not hold for all cases.”).

  • It is sufficient to show that there is a case for which

T does not hold.

  • Example:
  • Show that is false.
  • There are i for which ,e.g.

17

slide-31
SLIDE 31

Proof by Contradiction

  • We want to proof that T is true.
  • Step 1: Assume T is false.
  • Step 2: Show that this assumption leads to a

contradiction.

18

slide-32
SLIDE 32

Proof by Contradiction - Example

  • We want to proof that there is an infinite number of primes.
  • Assume the number of primes is finite and the largest

prime it Pk .

  • Let the sequence of all primes be P1, P2,,…,Pk


  • Since N>Pk, N cannot be prime, so it must have a

factorization into primes. Such a factorization cannot exist: dividing N by any P1, P2,,…,Pk will always leave a remainder of 1.

19