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

Information on mathematical induction and stack data structures. The former discusses the formula for calculating the number of subsets of a given set size using induction. The latter covers stack operations, including push, pop, size, and isempty, as well as the implementation of an array-based stack and an expandable array stack. Additionally, the document discusses binary search and its time complexity.

Typology: Lecture notes

2012/2013

Uploaded on 03/23/2013

dhruv
dhruv 🇮🇳

4.3

(12)

194 documents

1 / 54

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
More Induction, Expanding Stack Array,
Hashing
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36

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