tree recursion
Download
Skip this Video
Download Presentation
Tree Recursion

Loading in 2 Seconds...

play fullscreen
1 / 23

Tree Recursion - PowerPoint PPT Presentation


  • 123 Views
  • Uploaded on

Tree Recursion. Traditional Approach. Tree Recursion. Consider the Fibonacci Number Sequence: Time: 0 1 2 3 4 5 6 7 8 0, 1, 1, 2, 3, 5, 8, 13, 21, ... / 0 when n = 0 fib(n) = | 1 when n = 1 \ fib(n - 1) + fib(n - 2) otherwise. Tree Recursion (cont.). As code this is:

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 'Tree Recursion' - terrence


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
tree recursion

Tree Recursion

Traditional Approach

tree recursion1
Tree Recursion
  • Consider the Fibonacci Number Sequence:

Time: 0 1 2 3 4 5 6 7 80, 1, 1, 2, 3, 5, 8, 13, 21, ...

/0when n = 0fib(n)= |1 when n = 1\fib(n - 1) + fib(n - 2)otherwise

tree recursion cont
Tree Recursion(cont.)
  • As code this is:

int fib ( int n ) { if ( n <= 0 ) return 0; else if ( n = 1 ) return 1; else return fib ( n - 1 ) + fib ( n - 2 ) ; }

what happens when computing fib 5
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

what happens when computing fib 51
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

what happens when computing fib 52
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

what happens when computing fib 53
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

what happens when computing fib 54
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

what happens when computing fib 55
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

fib(2)

fib(1)

what happens when computing fib 56
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

fib(2)

fib(1)

what is the problem
What is the Problem?
  • I am explaining everything!
  • Why not make this more interesting by using MS Agents
    • Agents are helpers like the paper clip in Word
    • But they are much more:
      • They talk to you
      • And can, in some cases, understand voice commands
slide13

Tree Recursion

MS Agent Approach

tree recursion2
Tree Recursion
  • Consider the Fibonacci Number Sequence:

Time: 0 1 2 3 4 5 6 7 8

0, 1, 1, 2, 3, 5, 8, 13, 21, ...

  • This sequence is defined by the rule:

/0when n = 0

fib(n)= |1 when n = 1

\fib(n - 1) + fib(n - 2)otherwise

tree recursion cont1
Tree Recursion(cont.)
  • As code this is:

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

what happens when computing fib 58
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

what happens when computing fib 59
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

what happens when computing fib 510
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

what happens when computing fib 511
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

what happens when computing fib 512
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

what happens when computing fib 513
What happens when computing fib(5)?

fib(5)

int fib ( int n ) {

if ( n <= 0 ) return 0;

else if ( n = 1 ) return 1;

else return fib ( n - 1 ) + fib ( n - 2 ) ;

}

fib(3)

fib(4)

fib(3)

fib(2)

fib(2)

fib(1)

slide22

MASH: Microsoft Agent Scripting Helper

MASH is an editor that allows you to construct

the scripts that you can then embed in other applications

MASH

where to learn more
Where to Learn More
  • MS Agent Page:http://msdn.microsoft.com/workshop/imedia/agent/default.asp
  • Sunfires MS Agent Page:http://www.angelfire.com/il2/sunfire/index.html
  • Uniquities MS Agent Planet:http://www.uniquities.co.uk/whatsnew.htm
  • Presentation Narrator: http://msdn.microsoft.com/workshop/imedia/agent/sampleoffice.asp
  • Microsoft Agent Scripting Helper:http://www.bellcraft.com/mash/
ad