CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation

Slides:



Advertisements
Similar presentations
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Advertisements

Main Index Contents 11 Main Index Contents Week 10 – Recursive Algorithms.
1 Introduction to Recursion  Introduction to Recursion  Example 1: Factorial  Example 2: Reversing Strings  Example 3: Fibonacci  Infinite Recursion.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 14 Recursion.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
Introduction. 2COMPSCI Computer Science Fundamentals.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
RecursionRecursion Recursion You should be able to identify the base case(s) and the general case in a recursive definition To be able to write a recursive.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
Reading – Chapter 10. Recursion The process of solving a problem by reducing it to smaller versions of itself Example: Sierpinski’s TriangleSierpinski’s.
Review Introduction to Searching External and Internal Searching Types of Searching Linear or sequential search Binary Search Algorithms for Linear Search.
Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if.
Debugging and Printing George Mason University. Today’s topics Review of Chapter 3: Printing and Debugging Go over examples and questions debugging in.
7. RECURSIONS Rocky K. C. Chang October 12, 2015.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Recursion CENG 707.
Recursion CENG 707.
CMPT 120 Topic: Python’s building blocks -> More Statements
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Recursion – Part 2
Topic: Functions – Part 1
Recursion DRILL: Please take out your notes on Recursion
BIT116: Scripting Loops.
Topic: Python’s building blocks -> Variables, Values, and Types
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
Topic: Recursion – Part 1
CMPT 120 Topic: Functions – Part 4
Topic: Functions – Part 2
Functions CIS 40 – Introduction to Programming in Python
10.2 Implementation and Execution of Recursive Code
Java Lecture Recursion 29th feb 2005
CMIS 102 Competitive Success-- snaptutorial.com
CMIS 102 Education for Service-- snaptutorial.com
CMIS 102 Teaching Effectively-- snaptutorial.com
CMSC201 Computer Science I for Majors Lecture 16 – Recursion
Writing Functions( ) (Part 5)
Learning to Program in Python
Inheritance April 7, 2006 ComS 207: Programming I (in Java)
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Learning to Program in Python
Important Notes Remaining Schedule: recall the 2 bad weather days (Jan 8th, Jan 17th) we will need to make up. In providing the 2 weeks needed for the.
Recursion Chapter 11.
Fundamentals of Programming
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Passing Parameters by value
Learning to Program in Python
Recursion.
Design and Implementation
Faculty of Computer Science & Information System
Module 1-10: Recursion.
Picture This! Fractions and Wholes.
Java Programming: Chapter 9: Recursion Second Edition
CMPT 120 Lecture 12 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
Topic: Iterative Statements – Part 2 -> for loop
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Lecture 17 – Practice Exercises 3
CMPT 120 Lecture 18 – Unit 3 – Graphics and Animation
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Lecture 17 – Practice Exercise 3 SOLUTIONS
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Recursive Function Prepared by Harprith ICT2102 Introduction to Data Structure.
Lecture 6 - Recursion.
Presentation transcript:

CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation Python – Implementing and Visualizing Recursion

Review – What to consider when creating a function Function interface Function name (to reflect the task performed by the function) Parameter(s) Returned value

Review – What to consider when creating a recursive function Base Case Stops the function from calling itself indefinitely Recursive Case This is where the function calls itself with a modified (often smaller) form of the problem How do we get this “modified form of the problem” -> a rule

Last Lecture – we were here! Descriptive function name 1 parameter -> n Docstring describes the task performed by our function Let’s complete our program!

Execution Flow and Recursion How does recursion actually work? How can we test our recursive function? Let’s have a look at it through the Python Code Visualizer Online textbook calls this box tracing Box tracing technique used to hand trace the execution of a function (especially a recursive function) in order to figure out what it does

Box tracing a recursive function Knowing how to hand/box trace code is very important Even more important when dealing with recursive functions Why? Because following the execution of recursive functions can become very complicated very quickly Box tracing allows us to figure out what a recursive function does (keeping track of its parameters and local variables), what it produces (keeping track of its returned value) and where the execution flow returns to in a systematic way

Let’s try this again! Problem Statement Write a Python function that reverse a string

Let’s go back to our Turtle Trees! And have a look at more complicated recursive function that draws trees using a dictionary What does a dictionary have to do with trees?

Next Lecture Feedback on our algorithms of last Friday New practice exercises