1 CS1110 Lec. 11 5 Oct 2010 More on Recursion We develop recursive functions and look at execution of recursive functions Study Sect 15.1, p. 415. Watch.

Slides:



Advertisements
Similar presentations
Chapter 14 Recursion Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,, E. Reingold.
Advertisements

How to Convert Decimal Numbers to Binary EXAMPLES.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
CSC 213 – Large Scale Programming. Today’s Goals  Review discussion of merge sort and quick sort  How do they work & why divide-and-conquer?  Are they.
DISCUSSION OF SOME QUESTIONS ON PRELIM 2 Lecture 23 CS2110 – Spring 2015.
Arrays Recitation – 10/(9,10)/2008 CS 180 Department of Computer Science, Purdue University.
Monday, 12/9/02, Slide #1 CS 106 Intro to CS 1 Monday, 12/9/02  QUESTIONS??  On HW #5 (Due 5 pm today)  Today:  Recursive functions  Reading: Chapter.
0 CS100J September 2007 CS100J: 12 weeks programming using Java, 2 using Matlab. David Gries. CS100M: 7 weeks of Matlab and 7 of Java. Daisy Fan. CS100H:
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
1 Lecture 4: Arithmetic for Computers (Part 4) CS 447 Jason Bakos.
CS1800 Summer 2014 Binary Numbers. Decimal Integers  What does a decimal number like "87294" really mean?  More generally.
Converting binary to decimal decimal to binary
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Number Systems - Part II
CS1101: Programming Methodology Aaron Tan.
Tuesday, October 5 (Blue) Wednesday, October 6 (Gold) Today’s Agenda 1.Fill in planner 1.Practice Vocabulary Review 3.Ch. 4 Test Thursday (Blue)
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
1 CS October 2008 The while loop and assertions Read chapter 7 on loops. The lectures on the ProgramLive CD can be a big help. Quotes for the Day:
IT-101 Section 001 Lecture #3 Introduction to Information Technology.
Year 3 and 4 Calculations Maths Information Session Welcome Multiplication Subtraction Division Addition.
1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:
1 “Not all recursive solutions are better than iterative solutions…” “… recursion, however, can provide elegantly simple solutions to problems of great.
1 CS100J 09 March, 2006 More on Loops Reading: Secs 7.1–7.4 A Billion. The next time you hear someone in government rather casually use a number that includes.
– Digital Circuit 1 Choopan Rattanapoka
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
Examples of Recursion Data Structures in Java with JUnit ©Rick Mercer.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Recursion Recursion Chapter 12. Outline n What is recursion n Recursive algorithms with simple variables n Recursion and the run-time stack n Recursion.
Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system.
Numbers and Arithmetic Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
CSE 143 Lecture 13 Recursive Programming reading: slides created by Marty Stepp
CSC 212 More Recursion, Stacks, & Queues. Linear Recursion Test for the bases cases  At least one base case needs to be defined If not at a base case,
Chapter 8 – Exponents and Exponential Functions 8.1/8.3 – Multiplication and Division Properties of Exponents.

Binary01.ppt Decimal Decimal: Base 10 means 10 Unique numerical digits ,00010,000 Weight Positions 3,
1 CS100J 26 Feb 2008 More on Recursion My first job was working in an orange juice factory, but I got canned: couldn't concentrate. Then I worked in the.
while there is room A draws or ; B draws or ; A wants to get a solid closed curve. B wants to stop A from getting a solid closed curve. Who.
Using Recursion to Convert Number to Other Number Bases Data Structures in Java with JUnit ©Rick Mercer.
COMPETENCY #2 Laws of Exponents Scientific Notation.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
RECURSION, CONTINUED Lecture 8 CS2110 – Fall 2015.
Dec Important Steps 1. Precise Specification What does the method do? What are the preconditions? 2. Write the base case What is the most basic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Numbers in Computers.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every.
1 CS1110 Lecture 16, 26 Oct 2010 While-loops Reading for next time: Ch (arrays) Prelim 2: Tu Nov 9 th, 7:30-9pm. Last name A-Lewis: Olin 155 Last.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
CSC 213 – Large Scale Programming. Bucket Sort  Buckets, B, is array of Sequence  Sorts Collection, C, in two phases: 1. Remove each element v from.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
RECURSION (CONTINUED) Lecture 9 CS2110 – Spring 2016.
Number Systems Decimal Can you write 12,045 in expanded form? Base? Allowable digits for each place?
Lecturer: Santokh Singh
Recursion (Continued)
Recursion (Continued)
CS October 2008 The while loop and assertions
Introduction to Java, and DrJava part 1
Building Java Programs
CS1110 Lec Oct 2010 More on Recursion
Recursion (Continued)
Lesson 8.1 How do you use properties of exponents involving products?
Introduction to Java, and DrJava
Recursion (Continued)
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
Presentation transcript:

1 CS1110 Lec Oct 2010 More on Recursion We develop recursive functions and look at execution of recursive functions Study Sect 15.1, p Watch activity on the CD. In DrJava, write and test as many of the self-review exercises as you can (disregard those that deal with arrays). Thursday 7:30pm prelim: A-K Olin 155, L-Z Olin 255 Wednesday 3:35 lab is less crowded; go there instead?

while there is room A draws or ; B draws or ; A wants to get a solid closed curve. B wants to stop A from getting a solid closed curve. Who can win? What strategy to use?..... Board can be any size: m by n dots, with m > 0, n > 0 A won the game to the right because there is a solid closed curve. A game A and B alternate moves

3 /** = non-negative n, with commas every 3 digits e.g. commafy( ) = “5,341,267” */ public static String commafy(int n) { } What is the base case? A: 0..1 B: 0..9 C: D: E:

4 Executing recursive function calls. /** = non-negative n, with commas every 3 digits e.g. commafy( ) = “5,341,267” */ public static String commafy(int n) { 1: if (n < 1000) 2: return “” + n; // n >= : return commafy(n/1000) + “,” + to3(n%1000); } /** = p with at least 3 chars — 0’s prepended if necessary */ public static String to3(int p) { if (p < 10) return “00” + p; if (p < 100) return “0” + p; return “” + p; } n commafy: 1 Demo commafy( )

5 Recursive functions /** = b c. Precondition: c ≥ 0*/ public static int exp(double b, int c) Properties: (1)b c = b * b c-1 (2)For c even b c = (b*b) c/2 e.g 3*3*3*3*3*3*3*3 = (3*3)*(3*3)*(3*3)*(3*3)

6 Recursive functions /** = b c. Precondition: c ≥ 0*/ public static int exp(double b, int c) { if (c == 0) return 1.0; if (c is odd) return b * exp(b, c–1); // c is even and > 0 return exp(b*b, c / 2); } c number of calls n n is 2 15 so b needs only 16 calls!

7 Binary arithmetic Decimal Binary OctalBinary = = = = = = = = Test c odd: Test last bit = 1 Divide c by 2: Delete the last bit Subtract 1 when odd: Change last bit from 1 to 0. Exponentiation algorithm processes binary rep. of the exponent.

8 Hilbert’s space-filling curve Hilbert(1): Hilbert(2): Hilbert(n): H(n-1) left As the size of each line gets smaller and smaller, in the limit, this algorithm fills every point in space. Lines never overlap. H(n-1) dwn H(n-1) right All methods used in today’s lecture will be on course website

9 Hilbert’s space-filling curve