Scheme : Definitions and Expressions. Scheme : Functions (define (seven x) (* x 7))

Slides:



Advertisements
Similar presentations
Basics of Recursion Programming with Recursion
Advertisements

C++ Programming:. Program Design Including
What is the sum of the following infinite series 1+x+x2+x3+…xn… where 0
Recursion (define tell-story (lambda () (print ‘’Once upon a time there was a mountain. ‘’) (print ‘’On the mountain, there was a temple. ‘’) (print ‘’In.
Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.
1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Recursion. Binary search example postponed to end of lecture.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
Recursive Algorithms Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 211 RECURSION TREES. Trees versus Linked Lists A tree is like a linked list, except instead of a single next node, it can have multiple next nodes.
David Stotts Computer Science Department UNC Chapel Hill.
I am a two-digit number I am between 10 and 20 I am a multiple of 3
Factors and Simplest Form Section 4.2 b A prime number is a natural number greater than 1 whose only factors are 1 and itself. The first few prime numbers.
Prime Numbers A whole number greater than 1 whose only whole number factors are 1 and itself
M180: Data Structures & Algorithms in Java
Functions and an Introduction to Recursion.  Recursive function ◦ A function that calls itself, either directly, or indirectly (through another function)
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, = 3, so 3 is an odd positive integer.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Reading – Chapter 10. Recursion The process of solving a problem by reducing it to smaller versions of itself Example: Sierpinski’s TriangleSierpinski’s.
Section 8.4: Other Convergence Tests Practice HW from Stewart Textbook (not to hand in) p. 592 # 3-7, 12-17, odd, 33.
Comp Programming Languages Proposal 1 All humans possess a common logical structure which operates independently of language Proposal 2 Language.
Lecture 7 b Recursion is a fundamental programming technique that can provide an elegant solution to certain kinds of problems b Today: thinking in a recursive.
Chapter 12. Recursion Basics of Recursion Programming with Recursion Computer Programming with JAVA.
Principles Of Programming Languages Lecture 2 Today Design-By-Contract Iteration vs. Recursion.
Principles Of Programming Languages Lecture 2 Outline Design-By-Contract Iteration vs. Recursion Scope and binding High-order procedures.
Principles Of Programming Languages Lecture 2 Today Design-By-Contract Iteration vs. Recursion If we have time: live demo!!!
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 8: Recursion Presentation slides for Java Software Solutions for AP* Computer Science 3rd.
1/32 This Lecture Substitution model An example using the substitution model Designing recursive procedures Designing iterative procedures Proving that.
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
Solve each equation and check the solution. 08 September 2015 Warm-Up.
Infinite Geometric Series Recursion & Special Sequences Definitions & Equations Writing & Solving Geometric Series Practice Problems.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
Fundamental Digital Electronics
Chapter 15: Recursion. Recursive Definitions Recursion: solving a problem by reducing it to smaller versions of itself – Provides a powerful way to solve.
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.
Operations of Functions Given two functions  and g, then for all values of x for which both  (x) and g (x) are defined, the functions  + g,
 Radical expressions that contain the sum and difference of the same two terms are called conjugates.
CS314 – Section 5 Recitation 9
CS314 – Section 5 Recitation 10
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Recursion Recursion is a fundamental programming technique that can provide an elegant solution certain kinds of problems © 2004 Pearson Addison-Wesley.
Simplifying Expressions
Recursion DRILL: Please take out your notes on Recursion
Abdulmotaleb El Saddik University of Ottawa
RECURSION.
Add and subtract complex numbers
Java 4/4/2017 Recursion.
To understand recursion, you have to understand recursion!
Recursion
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
The Fundamental Theorem of Algebra
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Which type of claim does this represent?
Which type of claim does this represent?
Recursion Chapter 11.
Unit 1 Test #3 Study Guide.
This Lecture Substitution model
Recursion (part 1) October 24, 2007 ComS 207: Programming I (in Java)
Basics of Recursion Programming with Recursion
This Lecture Substitution model
I can tell the products of 6’s facts
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
Simplifying Expressions
Rational Numbers and Irrational Numbers
Lecture 6 - Recursion.
Presentation transcript:

Scheme : Definitions and Expressions

Scheme : Functions (define (seven x) (* x 7))

Scheme : Functions (define (sum x y) (+ x y))

Scheme : Conditionals (1) (define (test x) (cond ( (> x 0)1) ( (= x 0)0) ( (< x 0)-1)))

Scheme : Conditionals (2) (define (test2 x) (if (< x 0)(- x) x))

Scheme : Recursion (define (sum n) (if (= n 1)1 (+ n (sum(- n 1))))) sum the numbers 1 to N (e,g, 1 to 4) = 4 + ( ) = (2+1) = (2) + 1 (sum 4) = 4 + (sum 3) =

Scheme : Recursion : The Factorial Function (1) How many ways can you get n people to sit in n chairs ? n = 3. (A,B,C)n = 4. (A,B,C,D)

I lost the number of my new mobile phone How can I find the number ? Get my girlfriend to phone every single mobile number. (OK I’ll cook supper!) Approximate solution: Say a mobile number has 10 digits (actually 11) and each digit can be 0 – 9 (10 possibilitities). So the solution is 10! How long will this take? Calculatore!

Scheme : Recursion : The Factorial Function (2) (define (fact n) (if (= n 1)1 (* n (fact (- n 1)))))

I lost the number of my new mobile phone How can I find the number ? Get my girlfriend to phone every single mobile number. (OK I’ll cook supper!) Approximate solution: Say a mobile number has 10 digits (actually 11) and each digit can be 0 – 9 (10 possibilitities). So the solution is 10! How long will this take? Calculatore! (fact 10)

Functional Recursion // Imperative Iteration (define (fact n) (if (= n 1)1 (* n (fact (- n 1)))))

Fundamental Principles of Recursion A recursive function must call a simplified version of itself. This is guaranteed to “bottom out” (to halt). Any call to itself would produce an infinite regress. Don’t run this … ah go on then.. (define (factsr n) (if (= n 1)1 (* n (factsr n))))... and wait for the error message... or worse