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.

Slides:



Advertisements
Similar presentations
Higher-Order Functions and Loops c. Kathi Fisler,
Advertisements

Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013.
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 17: HOF and Tick-Tack-Toe.
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. 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.
Slide 1 CS3 Fall 2005 Lecture week 13: Introduction to the Big Project.
Recursion Introduction to Computing Science and Programming I.
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.
Imperative programming public int factorial (int N){ int F = 1; for(X=N; X>1; X-- ){ F= F*X; } return F; } Functional programming (defun factorial(N) (cond.
Data Abstraction… The truth comes out…. What we’re doing today… Abstraction ADT: Dotted Pair ADT: List Box and Pointer List Recursion Deep List Recursion.
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.
>(setf oldlist ) Constructing a list We know how to make a list in lisp; we simply write it: ‘4321( ) What if we want a new list with that list as a part?
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
Administrivia Make sure you have completed the Mid Semester Survey –Scheduled the week before Spring Break –this will be worth some points Reading is.
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.
מבוא מורחב - שיעור 81 Lecture 8 Lists and list operations (continue).
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”
CS3L: Introduction to Symbolic Programming Summer 2008Colleen Lewis Lecture 9: Recursion Rocks!
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
1 More Counting Techniques Possibility trees Multiplication rule Permutations Combinations.
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.
5th Grade Common Core Math
5th Grade Common Core Math Practice and Solutions for 5th Grade Common Core Math Standard 5.NBT.3 Multiple Choice Set #1 without Answers Multiple Choice.
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.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
5th Grade Common Core Math
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.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
5th Grade Common Core Math
The 8-queens problem CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Review I. Final exam Date TBD. Don ’ t be late! Open book, open notes No calculators or any electronics Worth 50% of final grade.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
4th Grade Common Core Math Practice and Solutions for 4th Grade Common Core Math Standard 4.NF.7 Multiple Choice Set #1 without Answers Multiple Choice.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
CS3: Introduction to Symbolic Programming Spring 2006Nate Titterton Lecture 2: Introduction, and Conditionals.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
CS314 – Section 5 Recitation 10
CS 550 Programming Languages Jeremy Johnson
Introduction to Computing Science and Programming I
Class 11: Two-argument recursion
Lists in Lisp and Scheme
CS 270 Math Foundations of CS Jeremy Johnson
32: Games 3 Functional Data
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2017.
CMSC201 Computer Science I for Majors Lecture 16 – Recursion
PROGRAMMING IN HASKELL
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
List and list operations (continue).
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
ormap, andmap, and filter
Rewriting your function using map and foldr
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
Presentation transcript:

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 on the portal (check announcements).

Slide 3 Question 1 [Shotgun questions] (+ 3 x 5) may not cause an error… –(+ 3 'fred 5) will

Slide 4 Question 2 [add-em] ( add-em '( ))  7 The conditional was tricky here: –Needed to check for 3 things to get sent to the base case

Slide 5 Question 3 [ranking cards] Scores are all over the place (hallmark of a bad question) Accessors!

Slide 6 Question 4 [day-span] Question 4c – the short answers – was a good one (I think). Some had trouble deciding between –conditional, –the base case, –making the problem smaller, –calling the function recursively –combining the recursive calls.

Slide 7 Question 5 [coins] Nice!

Slide 8 Schedule Oct 3Midterm #1 Oct 10Advanced recursion Oct 17Number-spelling Miniproject Oct 24Higher order procedures Oct 31More HOF Lists! (instead of sentences and words) Nov 7Recursion (advanced) Nov 14Midterm #2

Slide 9 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? 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))) ) ))

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. –"down-up": recursion as an extension of writing many specific functions –"many base cases": recursion as using a clone, once you have many base cases

Slide 12 Patterns in recursion Most recursions fall into a kind of patterns –Students say that this helps them As a corollary, some recursions don’t!

Slide 13 Mapping –does something to every part of the input sentence –E.g., square-all Counting –Counts the number of elements that satisfy a predicate –E.g., count-vowels, count-evens Finding –Return the first element that satisfies predicate (or, return rest of sentence) –E.g., member, member-even

Slide 14 Filtering –Keep or discard elements of input sentence –E.g., keep-evens Testing –A predicate that checks that every or any element of input satistfies a test –E.g., all-even? Combining –Combines the elements in some way… –E.g., sentence-sum

Slide 15 What recursions aren’t covered by these patterns? Weird ones like reverse, or downup –... bowling... "Advanced" recursions: –when it does more than one thing at a time –Ones that don’t traverse a single sentence E.g., mad-libs takes a sentence of replacement words [e.g., ‘(fat Henry three) ] and a sentence to mutate [e.g., ‘(I saw a * horse named * with * legs) ] –Tree recursion: multiple recursive calls in a single recursive step

Slide 16 Advanced recursion columns (C) r o w s (R) Pascal’s Triangle How many ways can you choose C things from R choices? Coefficients of the (x+y)^R: look in row R etc.

Slide 17 pair-all Write pair-all, which takes a sentence of prefixes and a sentence of suffixes and returns a sentence pairing all prefixes to all suffixes. –(pair-all ‘(a b c) ‘(1 2 3))  (a1 b1 c1 a2 b2 c2 a3 b3 c3) –(pair-all ‘(spr s k) ‘(ite at ing ong))  (sprite sprat spring sprong site sat sing song kite kat king kong)