Slide 1 Midterm 1 Midterm 1: Feb 28 th (next week). –In the lecture slot, plus 20 minutes (4:10-5:30 pm, 120 Latimer) –Everything we’ve covered, including.

Slides:



Advertisements
Similar presentations
Chapter 14 Recursion Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,, E. Reingold.
Advertisements

9/27/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 14 Dynamic.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Recursion.
CS3 Fall 2005 Lecture 11: Finish higher order functions Midterm Prep.
Slide 1 CS3: Lecture 8 Advanced recursion. Slide 2 Schedule Oct 10Advanced recursion Oct 17Number-spelling Miniproject Oct 24Higher order procedures Oct.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 14: Number Spelling Mini-project.
Slide 1 CS3 Week 8: Recursion. Slide 2 Midterm 1 You did great If you need a re- grade, see the person that graded that question Solutions are available.
Slide 1. Slide 2 Administrivia Mid-semester survey this week (Thur/Fri) –you NEED to do this. Interviews should be starting in a few weeks. I apologize.
CS3 Fall 2005 Lecture 10: More on higher order functions.
Slide 1 Announcements Next Lab is “Catch Up” –Go back over the last two weeks and fill in places you missed We are going to start taking attendance in.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 4: "Difference Between Dates" and data abstraction.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Lecture 12 Oct 13, 2008 Some simple recursive programs recursive problem solving, connection to induction Some examples involving recursion Announcements.
Slide 1. Slide 2 Midterm 1 You did great If you need a regrade, see the person that graded that question Solutions available on the portal soon.
COMP 14 Introduction to Programming Mr. Joshua Stough February 21, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Administrivia Make sure you have completed the Mid Semester Survey –Scheduled the week before Spring Break –this will be worth some points Reading is.
CS 280 Data Structures Professor John Peterson. Goals Understand “Programming in the small” Java programming Know what’s under the hood in complex libraries.
Feb 28More complicated recursions March 7Tree recursion, etc. Number-spelling Miniproject (#2) March 14Higher order procedures March 21Spring Break March.
Slide 1 Announcements Nate's office hours: –Monday, 12-2 –329 Soda Card key issues? (I've been told that any requests made before September 1 st didn't.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 8: Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!
Administrative Issues ICS 151 Fall 2007 Instructor: Eli Bozorgzadeh.
Midterm Logistics Where? 2050 VLSB When? Monday, 4:10 to 5:40 What to do? –“Review problems” from Thursday/Friday in UCWise. –Two practice exams and solutions.
Slide 1 CS3 Fall 2005 Lecture 9: Higher Order Functions.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
Slide 1. Slide 2 Administrivia Nate's office hours are Wed, 2-4, in 329 Soda! TA Clint will be handing out a paper survey in class sometime this week.
analysis, plug ‘n’ chug, & induction
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
Arbitrarily Long Data Structures: Lists and Recursion CMSC Introduction to Computer Programming October 4, 2002.
Administrative Issues ICS 151 Winter 2010 Instructor: Eli Bozorgzadeh.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Trees! =) Write up-add tree which behaves in this manner: 1 31 / \ / \ 3 5  21 9 / | \ \ / | \ \
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Microsoft ® Office Outlook ® 2007 Training Calendar basics [Your company name] presents:
CS1101: Programming Methodology
ICS202 Data Structures King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
The Endgame These FAQs will be posted and updated as new information comes in. This is as of 12/2/2013. This is all subject to revision. Here are some.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Chapter 1 Review of Real Numbers. § 1.1 Tips for Success in Mathematics.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Sometimes Structural Recursion Isn't Enough CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.1 TexPoint fonts used in EMF. Read the TexPoint manual.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Lecture 18 CSE 331 Oct 12, HW 5 due today Q1, Q2 and Q3 in different piles I will not take any HW after 1:15pm.
Lecture 18 CSE 331 Oct 6, Group/Algo registration deadline BOTH DUE WED by 11:59pm!
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Course Outline Three Themes for the course: Theme 1: Starting a Research Design and setting it up Theme 2: in-depth lectures on the most common research.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
1 Chapter Chapter 2 The Whole Numbers.
Recursion Version 1.0.
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
FINAL EXAM INFORMATION
FINAL EXAM INFORMATION
Finalisation First Check List Once all the information has been added
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
Announcements Nate’s office hours Card key problems?
CMSC201 Computer Science I for Majors Final Exam Information
Announcements HW #1 - graded HW and solutions returned now
Computer Networks CNT5106C
Administrative Issues
CMSC201 Computer Science I for Majors Lecture 12 – Program Design
AME Spring Lecture 11 - Thrust and aircraft range
Presentation transcript:

Slide 1 Midterm 1 Midterm 1: Feb 28 th (next week). –In the lecture slot, plus 20 minutes (4:10-5:30 pm, 120 Latimer) –Everything we’ve covered, including this coming week on recursion. –Review session Sunday, Oct 2nd, 1-3pm. 430 Soda (Wozniak lounge). problem requests to Nate –Practice exam in reader (do this all at once) –Check Announcements for more practice items, solutions –Nate’s office hours on that Monday: 12-2, 329 Soda.

Slide 2 Announcements Recursion in Lab this week. Read Chapter 11 in the textbook before lab.

Slide 3 How did the miniproject go?

Slide 4 Recursion Everyone thinks it's hard! –(well, it is… aha!-hard, not complicated-hard) The first technique (in this class) to handle arbitrary length inputs. –There are other techniques, easier for some problems. What is it?

Slide 5 An algorithmic technique where a function, in order to accomplish a task, calls itself with some part of the task. ALL recursive procedures need: 1) Base Case (s) 2) Recursive Case (s) that 1) Divide the problem 2) Call the function (recursively) 3) Combine the solutions

Slide 6 Problem: find the first even number in sentence of numbers (if ( ) (define (find-first-even sent) (if (even? (first sent)) (first sent) ;base case: return ; that even number (find-first-even (bf sent)) ;recurse on the ; rest of sent ))

Slide 7 Problem: find all the even numbers in sentence of numbers (define (find-evens sent) (cond ( ;base case ) ( ;rec case 1: odd ) ( ;rec case 2: even ) )) (define (find-evens sent) (cond ((empty? (bf sent)) ;base case (first sent) ) ((odd? (first sent)) ;rec case 1 (find-evens (bf sent)) ) (else ;rec case 2: even (se (first sent) (find-evens (bf sent))) ) ))

Slide 8 Base cases can be tricky By checking whether the (bf sent) is empty, rather than sent, we won't choose the recursive case correctly on that last element! –Or, we need two base cases, one each for the last element being odd or even. Better: let the recursive cases handle all the elements Your book describes this well

Slide 9 Problem: find all the even numbers in sentence of numbers (define (find-evens sent) (cond ((empty? (bf sent)) ;base case (first sent) ) ((odd? (first sent)) ;rec case 1: odd (find-evens (bf sent)) ) (else ;rec case 2: even (se (first sent) (find-evens (bf sent))) ) )) (define (find-evens sent) (cond ((empty? sent ) ;base case '() ) ((odd? (first sent)) ;rec case 1: odd (find-evens (bf sent)) ) (else ;rec case 2: even (se (first sent) (find-evens (bf sent))) ) ))

Slide 10 > (find-evens '( ))  (se 2 (se 4 (se 6 ())))  (2 4 6) (se 2 (se 4 (se 6 () sent = ( ) sent = ( ) sent = ( ) sent = ( 5 6 ) sent = ( 6 ) sent = ( )

Slide 11 Why is recursion hard? ONE function: –replicates itself, –knows how to stop, –knows how to combine the “replications” There are many ways to think about recursion: you absolutely do not need to understand all of them. –Knowing recursion WILL help with all sorts of ways while programming, even if you don’t often use it.

Slide 12 Consider a procedure named double that, given a word as argument, returns a two-word sentence. The first word is two. The second word is the result of adding an "s" to the end of the argument. expressionintended result (double 'apple)(two apples) (double 'bus)(two buss) (double 'box)(two boxs) Sample Problem for Midterm 1: double

Slide 13 Now consider some incorrect implementations of double. For each one, indicate what the call (double 'apple) will return. If no value is returned because the procedure crashes, give the error message that results. (define (double wd) (sentence 'two '(word wd s))) (define (double wd) (sentence 'two (sentence wd s)) ) (define (double wd) (sentence 'two (wd 's)) )