CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!

Slides:



Advertisements
Similar presentations
Joshua Eckroth The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the.
Advertisements

Natural Numbers or, "All you ever need is compounds, variants, and recursion".
 A  p q B  C D  r F G E t I J H s u K    P.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 4: Review Conditional & Word Stuff.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
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 18: HOF.
Lecture 2 Feb 3, 2009 goals: continue recursion more examples of recursive programs.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 26: Printing and Stuff.
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.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 12: Homework stuff and Accumulating Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 19: HOF Problems.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 6: Mini-Project Prep.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 4: "Difference Between Dates" and data abstraction.
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.
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.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 10: Recursion Rocks Again!
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 13: Bugs and Two Stage Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 20: Tree Recursion.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 1: Introduction & Administration.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 11: Accumulating Recursion.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 8: Recursion.
Midterm Logistics Where? 4 Leconte ( When? Monday, 4:10 to 5:40 What to do? –“Review problems”
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
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.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 2: Review – Writing Procedures.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 16: Let and Lambda.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 25: Trees and Generalized Lists.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 27: Review – most children and truth about cons.
Slide 1 CS3 Fall 2005 Lecture 9: Higher Order Functions.
Introduction to C Programming CE Lecture 21 Recursion and Linear Linked Lists.
Introduction to C Programming CE Lecture 22 Recursive Functions for Insertion and Deletion in Linear Linked Lists.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 7: Review.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 15: Procedures as Arguments.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 5: Difference Between Dates Case Study.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 24: Review for lists, map and member.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 3: Conditional Expressions.
(a) (b) (c) (d). What is (1,2,3)  (3,4,2)? (a) (1, 2, 3, 4) (b) (1,2)  (3,4) (c) (1,3,4,2) (d) (3,1)  (4,2)
Arbitrarily Long Data Structures: Lists and Recursion CMSC Introduction to Computer Programming October 4, 2002.
CS61A Lecture Colleen Lewis. Clicker Query What else are you doing this summer? A)Taking another class B)Working C)Taking another class and.
Recursion: Linear and Tree Recursive Processes and Iteration CMSC Introduction to Computer Programming October 7, 2002.
Introduction to Recursion Manish Sinha. Topics Two Parts to Recursion: – Solves easy problem in one step – Divide hard problem in smaller ones, and solve.
The way someone or something acts; what they do a)behaviorbehaviorb)darknessdarknessc)illnessillnessd)silencesilence.
Lecture 2 Jan Goals: Introduction to recursion Examples of recursive programs Reading: Chapter 1 of the text.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
CS CS1321: Introduction to Programming Georgia Institute of Technology College of Computing Lecture 10 Sept 25th, 2001 Fall Semester.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
120 I am an even number. 120 I am an even number. I am more than 100.
CS61A Lecture Colleen Lewis. Clicker Test How often do you read piazza posts? A)Whenever I receive an B)Once or twice a day C)When.
The Pact – Day 1 Make a Name Tent. Write your name on a ticket. Take out a piece of paper & pen or pencil. Get ready to write.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
CS61A Lecture Colleen Lewis. Clicker poll How do you feel about the “talk to your neighbor” stuff during lecture A)Like it B)It is okay.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
CS61A Lecture Colleen Lewis. Clicker Test Are you coming to the potluck on Thursday on the 4 th floor of Soda from 6:30pm-9:00? A)Yes B)Maybe.
Intellectual Property An iSafe Lesson By: Audrey.
Arithmetic and Geometric Sequences.
Racket CSC270 Pepper major portions credited to
Year 2 Autumn Term Week 13 Lesson 2
Year 2 Autumn Term Week 13 Lesson 2
Lecture #8 מבוא מורחב.
Modern Programming Languages Lecture 20 Fakhar Lodhi
List and list operations (continue).
Vocabulary Cards Front Side: -Term spelled correctly
Lecture # , , , , מבוא מורחב.
Coming back for hope 1 Thessalonians 4: 13-18
Ms. Waller's Class Newsletter
Presentation transcript:

CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!

Today Copies (we need volunteers) Count-evens Find-evens Recursion In Two Directions

Copies (define (copies n wd) (if (< n 1) ‘() (sentence wd (copies (- n 1) wd)))) ‘() (copies 3 ‘ha) (se ‘ha (copies 2 ‘ha) (se ‘ha (copies 1 ‘ha) (se ‘ha (copies 0 ‘ha) (copies 4 ‘ha) (se ‘ha

(define (count-evens sent) (cond ((empty? sent) ;empty? 0 ) ;base case: return 0 ((even? (first sent)) (+ 1 (count-evens (bf sent))));recurse on the ; rest of sent ((odd? (first sent) (+ 0 (count-evens (bf sent))) ;recurse on the ; rest of sent )) Count the number of even- numbers

The Leap of Faith… Dude this seems like a hard problem! I’ll do this small piece and hope that someone can do the rest.

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

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

The Leap of Faith… Dude this seems like a hard problem! I’ll do this small piece and hope that someone can do the rest. Sum-in-interval What was the “small piece”? What was the “rest”?

Sum-In-Interval