CS3: Introduction to Symbolic Programming. Lecture 5:

Similar documents
CS3: Introduction to Symbolic Programming. Lecture 11: Tree Recursion, beginning lists, and Midterm 2. Spring 2007 Nate Titterton

CS3: Introduction to Symbolic Programming. Lecture 10: Tic-tac-toe Lambda.

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

CS3: Introduction to Symbolic Programming. Lecture 8: Introduction to Higher Order Functions. Spring 2008 Nate Titterton

61A Lecture 7. Monday, September 15

CS3 Midterm 2 Standards and Solutions

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)

CS3 Midterm 2 Summer 2008

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

61A Lecture 7. Monday, September 16

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

Read and fill in this page now

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

CS 3L (Clancy) Solutions and grading standards for exam 1

(first (hello)) (hello) CS61A Lecture 2. Computer Science. Hierarchy of Abstraction. Functions. REVIEW: Two Types of( s so far

Solutions and grading standards

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

CS1 Lecture 12 Feb. 11, 2019

The Interpreter + Calling Functions. Scheme was designed by people. The Interpreter + Calling Functions. Clickers. Parentheses Matter We asked scheme

Discussion section number. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z

CS 3 Midterm 1 Review

Searching for Information. A Simple Method for Searching. Simple Searching. Class #21: Searching/Sorting I

CS3 Midterm 1 Fall 2006

This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

61A Lecture 6. Monday, February 2

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Spring 2018

CS3 Midterm 1 Fall 2007 Standards and solutions

(More) Fun with Pointers and Linked Lists! CS 16: Solving Problems with Computers I Lecture #17

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

CS1 Lecture 13 Feb. 13, 2019

CENG 707 Data Structures and Algorithms

CS457/557 Functional Languages

Menu. Class 1: Introduction. Staff. Course Structure and Expectations. Contacting Us. Contacting You

CS120 Computer Science I. Instructor: Jia Song

61A Lecture 3. Friday, September 5

Admin CS41B MACHINE. Midterm topics. Admin 2/11/16. Midterm next Thursday in-class (2/18) SML. recursion. math. David Kauchak CS 52 Spring 2016

ECOM 2314 COMPUTER PROGRAMMING II

Programming Languages and Techniques (CIS120)

Week 3 Web site:

CS61A Lecture 1. Amir Kamil UC Berkeley January 23, 2013

SQL: Recursion. Announcements (October 3) A motivating example. CPS 116 Introduction to Database Systems. Homework #2 graded

Ambiguity. Lecture 8. CS 536 Spring

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Cleveland State University

Central Washington University Department of Computer Science Course Syllabus

CS 1110, LAB 3: STRINGS; TESTING

Lecture #21: Search and Sets. Last modified: Wed Mar 9 15:44: CS61A: Lecture #21 1

Homework 3: Relational Database Design Theory (100 points)

CS 314 Principles of Programming Languages. Lecture 16

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley

by the evening of Tuesday, Feb 6

CS 314 Principles of Programming Languages. Lecture 21


Strings in Python 1 Midterm#1 Exam Review CS 8: Introduction to Computer Science Lecture #6

CS 4349 Lecture August 21st, 2017

Pre- Defined Func-ons in C++ Review for Midterm #1

CSci 4211: Data Communications and Computer Networks. Time: Monday and Wednesday 1 pm to 2:15 pm Location: Vincent Hall 16 Spring 2016, 3 Credits

Python Lists 2 CS 8: Introduction to Computer Science Lecture #9

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

Homework 3: Recursion Due: 11:59 PM, Sep 25, 2018

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Umesh Vazirani February 13, Midterm 1

Programming II (CS300)

1. Textbook #1: Our Digital World (ODW). 2. Textbook #2: Guidelines for Office 2013 (GFO). 3. SNAP: Assessment Software

Welcome to CS 241 Systems Programming at Illinois

CS3: Introduction to Symbolic Programming. Lecture 14: Lists Scheme vs. other programming languages.

CS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

Programming Languages and Techniques (CIS120)

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

CS1 Lecture 15 Feb. 19, 2018

Lecture 26: Sorting CS 1110 Introduction to Computing Using Python

CSci 4211: Introduction to Computer Networks. Time: Monday and Wednesday 2:30 to 3:45 pm Location: Smith Hall 231 Fall 2018, 3 Credits

CMPE 152 Compiler Design

Dynamic Types , Spring March 21, 2017

Data Structures and Algorithms

Lists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10

CS 101: Computer Programming and Utilization. Abhiram Ranade

Programming Languages and Techniques (CIS120)

Welcome (back) to CS1007!

San José State University College of Science/Department of Computer Science CS152, Programming Paradigms, Sections 1 & 2 Spring Semester, 2018

Strings in Python: Cipher Applications CS 8: Introduction to Computer Science, Winter 2018 Lecture #9

Textbook(s) and other required material: Raghu Ramakrishnan & Johannes Gehrke, Database Management Systems, Third edition, McGraw Hill, 2003.

378: Machine Organization and Assembly Language

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

What is this class all about?

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Introduction to Computer Systems

Topic 7: Intermediate Representations

Database Systems: Concepts, design, and implementation ISE 382 (3 Units)

Func%ons in C++ Part 2 CS 16: Solving Problems with Computers I Lecture #5

INF 315E Introduction to Databases School of Information Fall 2015

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

CS106B Handout #25 J Zelenski Feb 11, Midterm Practice

Drawing Hands, by M. C. Escher (lithograph, 1948)

Class Note #02. [Overall Information] [During the Lecture]

Transcription:

CS3: Introduction to Symbolic Programming Lecture 5: Spring 2006 Nate Titterton nate@berkeley.edu

Announcements Nate's office hours this week only: - Thursday, 2-4, in 329 Soda - (Usually, they are Wed 2-4)

Schedule 4 5 6 7 8 9 Feb 6-10 Feb 13-17 Feb 20-24 Feb 27-Mar 3 Mar 6-10 Mar 13-17 Lecture: Data abstraction in DbD Lab: Miniproject I Lecture: Introduction to Recursion Lab: Recursion Lecture: HOLIDAY Lab: Recursion II Lecture: Midterm 1 Lab: Recursion III Lecture: finishing recursion Lab: Miniproject #2 Introduction to Higher Order Proceedures

Announcements Reading for this week - Simply Scheme, chapter 11 - Difference between Dates, Part II Questions for the Jon (the reader), regarding homework grades? - email Jon at cs3-ra@imail.eecs.berkeley.edu

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

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?

An algorithmic technique where a function, in order to accomplish a task, calls itself with some part of the task.

All recursion procedures need 1. Base Case (s) Where the problem is simple enough to be solved directly 2. Recursive Cases (s) 1. Divide the Problem into one or more smaller problems 2. Invoke the function Have it call itself recursively on each smaller part 3. Combine the solutions Combine each subpart into a solution for the whole

Problem: find the first even number in a sentence of numbers (define (find-first-even sent) (if <test> (even? (first sent)) (<do (first the sent) base case>) ;base case: return ; that even number (<do (find-first-even the recursive (bf case>) sent)) ;recurse on the ; rest of sent ))

Count the number of words in a sentence (define (count sent) )) (if (empty? (bf sent)) 1 ;base case: return 1 (+ 1 (count (bf sent)) ;recurse on the ; rest of sent

Problem: find all the even numbers in a 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))) ) ))

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

Count the number of words in a sentence (define (count sent) (if (empty? (bf sent)) ) 01 ;base case: return 01 (+ 1 (count (bf sent)) ;recurse on the ; rest of sent ))

Problem: find all the even numbers in a 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))) ) ))

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

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.

Midterm 1: Feb 27 th (in two weeks). - Location: 50 Birge - Time: In the lecture slot, plus 20 minutes - (4:10-5:30) - Everything we ve covered, including the coming two weeks on recursion. - Review session Saturday, Feb 25th, 2-4pm. - 430 Soda (Wozniak lounge). - Practice exam in reader (do this all at once) - Check Announcements for more practice items, solutions

Sample problem for midterm 1 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. expression (double 'apple) (double 'bus) (double 'box) intended result (two apples) (two buss) (two boxs)

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