Docsity

Induction and Stack Data Structures: Subset Count and Binary Search, Lecture notes of Computer Science

Partial preview of the text

Download Induction and Stack Data Structures: Subset Count and Binary Search and more Lecture notes Computer Science in PDF only on Docsity!

  • More Induction, Expanding Stack Array,

Hashing

Induction

A(n) is number of subsets of set of size n

A(1) = 2 # all and empty set

A(n) = A(n-1) + A(n-1) = 2A(n-1) # all those in n-1 case w & w/o n

th

2, 4, 8, 16, 32, …, A(n) A(n) = 2

n

? Prove it!

2

Induction

A(n) is number of subsets of set of size n

A(1) = 2 # all and empty set

A(n) = A(n-1) + A(n-1) = 2A(n-1) # all those in n-1 case w & w/o n

th

2, 4, 8, 16, 32, …, A(n) A(n) = 2 n^? Prove it!

  1. Base case: _______________
  2. Given: _______________
  3. Inductive step start: __________ assume for n=k__


  4. Inductive step end: __________ _true for n=k+1____
  5. Therefore, because we’ve shown for n=1 and for n=k+1 assuming n=k A(n) = 2n^ for all positive integers n 5

Induction

A(n) is number of subsets of set of size n

A(1) = 2 # all and empty set

A(n) = A(n-1) + A(n-1) = 2A(n-1) # all those in n-1 case w & w/o n

th

2, 4, 8, 16, 32, …, A(n) A(n) = 2 n^? Prove it!

  1. Base case: _______________
  2. Given: _______________
  3. Inductive step start: __________ assume for n=k__


  4. Inductive step end: __________ _true for n=k+1____
  5. Therefore, because we’ve shown for n=1 and for n=k+1 assuming n=k A(n) = 2n^ for all positive integers n 7

Induction

A(n) is number of subsets of set of size n

A(1) = 2 # all and empty set

A(n) = A(n-1) + A(n-1) = 2A(n-1) # all those in n-1 case w & w/o n

th

2, 4, 8, 16, 32, …, A(n) A(n) = 2 n^? Prove it!

  1. Base case: _______________
  2. Given: _______________
  3. Inductive step start: __________ assume for n=k__


  4. Inductive step end: __________ _true for n=k+1____
  5. Therefore, because we’ve shown for n=1 and for n=k+1 assuming n=k A(n) = 2n^ for all positive integers n 11

Induction

A(n) is number of subsets of set of size n

A(1) = 2 # all and empty set

A(n) = A(n-1) + A(n-1) = 2A(n-1) # all those in n-1 case w & w/o n

th

2, 4, 8, 16, 32, …, A(n) A(n) = 2 n^? Prove it!

  1. Base case: _______________
  2. Given: _______________
  3. Inductive step start: __________ assume for n=k__


  4. Inductive step end: __________ _true for n=k+1____
  5. Therefore, because we’ve shown for n=1 and for n=k+1 assuming n=k A(n) = 2n^ for all positive integers n 13

Do you want to:

A. Do another example now on paper?

B. Move on?

CLICKERS out! (and on, dhl)

Theorem

17

Theorem
In any graph G, there is an independent set SG of vertices (meaning no two are
joined by an edge) such that every vertex of G can be reached from a vertex in SG
by a path of length at most one.
For example in the graph G above, S this...^ or this...or even this!

G could be...

Stack

• Stack operations:

– Push(x), x=pop(), i=size(), b=isEmpty()

• (Partial) Implementation:

– Array-based stack

ArrayStack

INIT:

data = array[20]

count = 0; // next empty space

push(obj o):

if count < 20

data[count] = o

count++

else

ERROR(“Overfull Stack”)