Lesson 16: Recursion - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Lesson 16: Recursion

Description:

Explain how a set of rooted trees and the sets of extended binary trees are defined ... ( in class) Recursively defining Rooted Trees. Basis Step: A single root ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 12
Provided by: jwi6
Category:

less

Transcript and Presenter's Notes

Title: Lesson 16: Recursion


1
Lesson 16 Recursion
  • Objectives
  • Explain why recursively defined functions are
    well-defined
  • Describe how sets and structures can be
    recursively defined
  • Tell the importance of recursive functions
  • Explain how a set of rooted trees and the sets of
    extended binary trees are defined
  • Outline
  • Recursive functions
  • Defining Sets and Structures Recursively
  • Trees
  • Reading 3.4

2
Recursively defined sequences (functions)
  • Define base case (at 0, 1, etc)
  • Define a rule for calculating next number in
    sequence, given previous number.

3
Recursively defined functions
  • f(n) an

4
Inferred Sequence
  • 0, 2, 6, 12, 20, 30, 42, ...
  • Imply a recursive definition

5
Fibonacci Sequence
  • Fib(n) Fib(n-1) Fib(n-2)
  • http//www.mcs.surrey.ac.uk/Personal/R.Knott/Fibon
    acci/fibnat.html

6
Recursively Defined Sets
  • Basis 2 ? S
  • Recursive step If x ? S and y ? S, then xy ? S
  • What are the elements of S?

7
Recursively defined Sets
  • S 4, 7, 10, 13, 16, 19 ...
  • What is a rule base for defining S? (in class)

8
Recursively defining Rooted Trees
  • Basis Step A single root is a rooted tree
  • Recursive step Taking a rooted Tree T and
    connecting it to the existing rooted tree at any
    vertex produces a rooted tree.

9
Extended Binary Tree
  • Basis Step The empty set is an extended binary
    tree
  • Recursive step If T1 and T2 are EBTs, connect a
    root to the root of the left subtree of T1 and to
    the root of the right subtree of t2 this
    produces a new EBT

10
Full Binary Tree
  • Basis Step A single vertex r
  • Recursive Step Connect two FBTs to root.

11
Variables
  • Consider the alphabets
  • a 0-9, a-z, A-Z
  • b a-z
  • Define a recursive method of generating valid
    variable names.
Write a Comment
User Comments (0)
About PowerShow.com