Docsity

Lecture 15: Recursion I in Discrete Structures CSci 243, Study notes of Discrete Structures and Graph Theory

Partial preview of the text

Download Lecture 15: Recursion I in Discrete Structures CSci 243 and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

CSci 243

Discrete Structures

Lecture 15

Recursion I

Outline

  • Motivation
  • Recursive Definitions
  • Preview of Recursive Algorithms
  • Fibonacci Example, Power Question

Recursive Definitions

  • Recursion: Defining something in terms of itself
  • Fibonacci numbers:

f(0) = 0, f(1) = 1, f(n) = f(n-1)+f(n-2) (n>1)

  • Summations:
  • QC: Write a recursive definition for n!

− = (^) =

,if n 0

, if n 0

1 (^0 )

( ) n

i

n

i f n f i

f

f i

The Induction/Recursion Connection

  • Induction:
    • Prove a base case
    • Prove that P(k)fP(k+1) for arbitrary k
  • Recursion:
    • Define an object for a base case
    • Define an object for k+1 case in terms of k case
  • Can prove the correctness of recursive

algorithms using induction! (Next month)

Proof Part 1: A z S

  • P(n): 3n e S
    • 3n is an arbitrary value in A (n=1)
  • Basis step: 3x 1 e S?
    • 3 e S (def’n of S)
  • Inductive step: 3k e S f 3(k+1) e S for arb. k?
    • 3(k+1) = 3k+
    • 3k e S by inductive hypothesis, 3 e S by def’n of S
    • First A (3) is in S, and later A’s too (P(k) f P(k+1))
    • So A z S

Proof Part 2: S z A

  • P(n): n e A
    • n is an arbitrary value in S
  • Basis step: 3 e A?
    • 3 x 1 e A (def’n of A)
  • Inductive step: x e S, y e S f x+y e S?
    • x = 3k and y = 3m (x e S,y e S)
    • x+y = 3k+3m = 3(k+m)
    • 3(k+m) e A
    • P(x) ¶ P(y) f P(x+y) so S z A

Example: p \implies q \iff \lnot p \lor q

  • What are valid subexpressions?
    • p e WFE
    • q e WFE
    • p \implies q e WFE
    • \lnot p e WFE
  • What are invalid subexpressions?
    • p \implies ‰ WFE
    • \lnot \implies q ‰ WFE
    • \iff ‰ WFE
    • p \implies q \iff ‰ WFE

WFE Definition

  • What are the base cases?
  • How do you build a bigger expression in terms

of smaller ones?