slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Advanced Induction PowerPoint Presentation
Download Presentation
Advanced Induction

Loading in 2 Seconds...

play fullscreen
1 / 28

Advanced Induction - PowerPoint PPT Presentation


  • 66 Views
  • Uploaded on

Advanced Induction. Drawing hands by Escher. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois. Logistics. Midterm is done grading but entering into Moodle/tallying/analysis will take longer.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Advanced Induction' - hovan


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

Advanced Induction

Drawing handsby Escher

Discrete Structures (CS 173)

Madhusudan Parthasarathy, University of Illinois

logistics
Logistics

Midterm is done grading

but entering into Moodle/tallying/analysis

will take longer.

You should be able to see your exam tomorrow in discussion sections, but probably won’t be able to take it away.

Watch for Piazza posts on status/statistics/etc.

this class
This class
  • More induction
  • Induction on data-structures
    • Lists, trees, graphs, etc. manipulated by algorithms
    • Structural induction
    • Strengthening the hypothesis
strengthenining inductive hypothesis
Strengthenining inductive hypothesis

<< Problem 3 in HW 7 already illustrates this>>

Prove that for any n > 0,

1 + 1/4 + 1/9 + ... +1/n2 < 2

another example
Another example
  • For all n > 1, prove that the sum of the first n odd numbers is a perfect square.
proving properties of recursive algorithms
Proving properties of recursive algorithms
  • Think of the program as a recursive definition.
  • Do induction using the recursive definition to prove algorithm correct.
  • Works for any recursive definition (not just algorithms)

- Structural induction

simple example
Simple example

Let S be the smallest set of integers such that:

  • 3 is in S
  • If x is in S, then x+6 and x-3 both belong to S.

Prove that all elements of S are divisible by 3.

lists
Lists

Recursive definition of lists containing elements in A:

  • <> is a lists(A)
  • If x is in A and L is in lists(A), then x::L is in lists(A).

Now consider the following function: Size: Lists(A)  N

  • Size(<>) = 0
  • Size(x::L) = 2+Size(L).

Prove that Size(L) is even for any list in L(A).

key idea
Key idea
  • prove properties about lists using its recursive definition – structural induction
  • similar to proving properties by induction over length of lists, heights of trees, etc.
  • but more general as you can do this for any recursively defined structure (trees, doubly linked lists, bst, avl, etc.)
  • recursive algorithms  recursive definitions
trees
Trees

Binary trees over alphabet A as follows:

  • <> is in BT(A)
  • If L, R are in BT(A) and x is in A, then

<L, x, R> is in BT(A).

Example trees:

< < <> a <> > b <<> c <> > >

We can prove properties about trees using the above inductive definition.

inserting into a sorted list
Inserting into a sorted list

Recursive algorithm:

insert (x,L) {

if L=<> then return x::<>;

else

y:= cons(L);

L’ = cdr(L);

if (x <= y) return x::y::L’;

else return y::x::L;

}

Think of a recursive algorithm as a recursive definition!

Apply structural induction to prove properties of the algorithm.

Example: if L is sorted then insert(x,L) is sorted.

Recursive function:

insert(x,<>) = x::<>;

insert(x,y::L)= x::y::L if x<=y

y::x::L otherwise

proof of insert on lists
Proof of insert on lists

To prove: if L is sorted then insert(x,L) is sorted.

Try induction:

proof of insert on lists1
Proof of insert on lists

Strengthen the inductive hypothesis:

If L is sorted, then insert(x,L) is sorted and is a

keys stored in it is keys(L) U {x}.

recap
Recap
  • Recursive algms Recursive definitions
  • Prove properties of algorithm by induction using the structure of the recursive definition.
  • However, in practice:
    • writing down the recursive defn explicitly is hard
    • hard for programs that have “state”
    • however, your “proof of the algorithm” can follow the recursive style, nevertheless.
slide19

Correctness of merge

Prove correctness of merge using induction!

Induction is on number of times merge calls itself.

What decreases with each call?

Length of L1? Length of L2?

correctness of binary search
Correctness of binary search

Searching a sorted array A[1..n]

binary_search(int A[],int key,intimin,intimax){

if(imax<imin)return -1;

else{

intimid= midpoint(imin,imax);

if(A[imid]> key)returnbinsearch(A, key,imin,mid-1);

elseif(A[imid]< key)

binsearch(A, key, imid+1,imax);

elsereturnimid;

}

}

searching for a key in a bin search tree
Searching for a key in a bin-search tree

Binary search tree:

- datastructure used to

search for elements fast in an ordered set.

- works best if tree is almost

balanced.

Key property:

For any node n: keys(n.left)  key(n)  keys(n.right)

searching for a key in a bin search tree1
Searching for a key in a bin-search tree

find (k, T) {

if T=nil return false;

else if key(root(T))=k return true;

else if k<key(root(T)) return find(k, T.left);

else return find(k, T.right);

}

Prove inductively thatfind(k,T) return true iff k is stored in T.

take away
Take away
  • Inductive arguments often require strengthening
  • Properties of recursively defined sets/functions can be proved using induction that follows the structure of the definition.
  • Recursive algorithms can be seen as recursive definitions/functions.

Learn how to see that in a recursive algorithm.

  • Prove properties about recursive algorithms using structural induction that implicitly looks at the structure of the recursion in the algorithm.