cs105 lab 11 recursion n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CS105 Lab 11 – Recursion PowerPoint Presentation
Download Presentation
CS105 Lab 11 – Recursion

Loading in 2 Seconds...

play fullscreen
1 / 5

CS105 Lab 11 – Recursion - PowerPoint PPT Presentation


  • 77 Views
  • Uploaded on

CS105 Lab 11 – Recursion. Announcements Midterm 2 may have been harder/longer than we had anticipated We will grade Midterm 2 completely before making any further announcements please watch this space!. Objective: Understanding Recursion.

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 'CS105 Lab 11 – Recursion' - naida


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
cs105 lab 11 recursion
CS105 Lab 11 – Recursion
  • Announcements
    • Midterm 2 may have been harder/longer than we had anticipated
    • We will grade Midterm 2 completely before making any further announcements
      • please watch this space!

CS 105 – Fall 2009

objective understanding recursion
Objective: Understanding Recursion
  • A recursive function can call itself one or more times
    • with “smaller” arguments
  • General structure:

Private Function recFunction(data As … ) As …

If <base case condition> Then

recFunction = <base case answer>

Else

recFunction = recFunction(smaller data)

End If

End Function

Recursive function call

CS 105 – Fall 2009

mystery function 1
Mystery Function 1
  • Open lab11.xls and study the code for Mystery 1
  • Predict what the answer will be for:
    • mystery1(5)
    • mystery1(6)
    • mystery1(7)
  • Now try it and see if you are correct!

CS 105 – Fall 2009

mystery function 2
Mystery Function 2
  • Mystery function 2 is more interesting:

Private Function mystery2(strX As String) As Boolean

  • The data is of type String and the answer is of type Boolean (True/False)
    • We get “smaller” strings using the Mid function
    • Mid(string, startPosition, numberOfLetters)
  • Predict the answer for these cases, then check it:
    • mystery2(“A”)
    • mystery2(“Radar”)
    • mystery2(“radar”)

CS 105 – Fall 2009

mystery function 3
Mystery Function 3
  • Mystery function 3 is more complex:

Function mystery3(intN, intM As Integer) As Integer

  • The first If condition is not a base case!
    • It is a recursive case
  • Predict the answer for these cases, then check it:
    • mystery3(5, 6)
    • mystery3(6, 5)
    • mystery3(2, 6)

CS 105 – Fall 2009