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.

Slides:



Advertisements
Similar presentations
How to Convert Decimal Numbers to Binary EXAMPLES.
Advertisements

Sermon for Sunday, October 20, 2013 Acts Community Church.
Hey Guys! My group and others have been set a challenge to go to city's and country's all over the world. I decided to do the Paris leg because it was.
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.
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
First project Create a JApplet with 3 textfields (2 for input and one for the answer), appropriate labels, and buttons for plus, minus and times. Your.
Lecture 2 Aug 28 goals: Introduction to recursion examples of recursive programs.
Unit 191 Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive.
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 5. Recursive Algorithms.
1 Gentle Introduction to Programming Tirgul 2: Scala “hands on” in the lab.
The Binary Number System 6 th grade math. What is binary? The number system we use is decimal, based on the number 10 The binary system is instead based.
Recursion Chapter 5 Outline Induction Linear recursion –Example 1: Factorials –Example 2: Powers –Example 3: Reversing an array Binary recursion –Example.
Decimal to Binary Conversion Press any key to continue…
Scientific Notation Recognize and use scientific notation.
Resume Writing Today’s Workshop will include: Purpose of a resume
Scientific Notation.
TITLE: T.G.I.M.- Thank God It’s Monday TEXT: I Corinthians 10:31, Colossians 3: THEME: See work as an act of worship enables believers to handle.
Building Java Programs Chapter 13 Searching reading: 13.3.
WELCOME.
Recursion and Dynamic Programming. Recursive thinking… Recursion is a method where the solution to a problem depends on solutions to smaller instances.
Copyright 2005 Curt Hill Binary, Octal and Hexadecimal The number bases used in computers.
Recursion 1. Jump It  board of n squares, n >= 2  start at the first square on left  on each move you can move 1 or 2 squares to the right  each square.
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.
Multiplying and Dividing Decimals by 10, 100, and 1,000
I LEARNED TO KNIT. Why Knitting? I’ve wanted to learn how to knit for a very long time now. My Grandma passed away before she could teach. I never took.
Summary. Data Types int A; I am declaring a variable A, which is an integer.
Grade 5 Module 1 Lesson 15.
CSE 143 Lecture 13 Recursive Programming reading: slides created by Marty Stepp
1 CS100J 31 October 2006 Arrays: searching & sorting. Reading: 8.5 Merry Christmas!! On Halloween? Searching and sorting algorithms are on the course website.
Floating-Point Representation We can store integers and characters easily in binary, but what about fractions? ¼ =.25 = 2.5 * *
PROPERTIES OF EXPONENTS
Exponents Power base exponent means 3 factors of 5 or 5 x 5 x 5.

Binary01.ppt Decimal Decimal: Base 10 means 10 Unique numerical digits ,00010,000 Weight Positions 3,
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.
1 Recursion n what is it? n how to build recursive algorithms n recursion analysis n tracing simple recursive functions n hands on attempts at writing.
1 CS November 2010 insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill. Practice.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
COMPETENCY #2 Laws of Exponents Scientific Notation.
1 CS April 2010 binary search, linear search insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts.
Contest Algorithms January 2016 Pseudo-code for divide and conquer, and three examples (binary exponentiation, binary search, and mergesort). 5. Divide.
CDA 3100 Spring Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
Decimal to Binary Conversion Press any key to continue…
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
1 CS April 2009 Sorting: insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill.
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.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
CDA 3100 Fall Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
Data Representation Covering… Binary addition / subtraction
Lecturer: Santokh Singh
Scientific Notation.
Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Recursion A problem solving technique where an algorithm is defined in terms of itself A recursive method is a method that calls itself A recursive algorithm.
Multiplying & Dividing by Powers of Ten
Exponents & Scientific Notation Test Corrections
Building Java Programs
CS1110 Lec Oct 2010 More on Recursion
Data Representation – Numbers
CSE 373: Data Structures & Algorithms
Multiplying and Dividing in Scientific Notation
CSE 143 Lecture 13 Recursive Programming reading:
CDA 3100 Fall 2012.
Sliding Decimal Points
Addition & Subtraction Addition & Subtraction
Presentation transcript:

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 woods as a lumberjack, but I just couldn't hack it, so they gave me the axe. After that I tried to be a tailor, but I just wasn't suited for it. Mainly because it was a so-so job. Next I tried working in a muffler factory but that was exhausting. I worked as a pilot but eventually got grounded for taking off too much. Then I tried teaching but I couldn't make the grade. We derive 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). Get more of these from the course website

2 Geometry test

3 Recursive functions /** = a copy of s in which s[0..1] are swapped, s[2..3] are swapped, s[3..4] are swapped, etc. */ public static String swapAdjacent(String s) /** = b c. Precondition: c ≥ 0*/ public static int exp(int 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)

4 Recursive functions /** = b c. Precondition: c ≥ 0*/ public static int exp(int b, int c) { if (c = 0) return 1; 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!

5 Binary arithmetic Decimal Binary Dec Binary = = = = = = = = 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 the binary representation of the exponent.

6 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

7 Hilbert’s space-filling curve