CS105 Lab 11 – Recursion

1 / 5

# CS105 Lab 11 – Recursion - PowerPoint PPT Presentation

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.

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

## PowerPoint Slideshow about 'CS105 Lab 11 – Recursion' - naida

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
• Announcements
• Midterm 2 may have been harder/longer than we had anticipated
• We will grade Midterm 2 completely before making any further announcements

CS 105 – Fall 2009

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

Else

recFunction = recFunction(smaller data)

End If

End Function

Recursive function call

CS 105 – Fall 2009

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 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”)

CS 105 – Fall 2009

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