CPE 130 Algorithms and Data Structures Recursion Asst. Prof. Dr. Nuttanart Facundes.

Slides:



Advertisements
Similar presentations
MAT 4 – Kompleks Funktionsteori MATEMATIK 4 INDUKTION OG REKURSION MM 1.4 MM 1.4: Induktion og Rekursion Topics: Mathematical induction Example of Towers.
Advertisements

Phi, Fibonacci, and 666 Jay Dolan. Derivation of Phi “A is to B as B is to C, where A is 161.8% of B and B is 161.8% of C, and B is 61.8% of A and C is.
Recurrences and Continued Fractions Great Theoretical Ideas In Computer Science V. Adamchik D. Sleator CS Spring 2010 Lecture 8 Feb 04, 2010 Carnegie.
6.1 Golden Section 6.2 More about Exponential and Logarithmic Functions 6.3 Nine-Point Circle Contents 6 Further Applications (1)
Ancient Wisdom: Primes, Continued Fractions, The Golden Ratio, and Euclid’s GCD Great Theoretical Ideas In Computer Science Anupam GuptaCS Fall.
Topic 7 – Recursion (A Very Quick Look). CISC 105 – Topic 7 What is Recursion? A recursive function is a function that calls itself. Recursive functions.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
COMPSCI 105 S Principles of Computer Science Recursion 3.
The Fibonacci Numbers And An Unexpected Calculation. Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 7Feb 3, 2004Carnegie.
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1.
Great Theoretical Ideas in Computer Science.
Fibonacci numbers Fibonacci numbers:Fibonacci numbers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,... where each number is the sum of the preceding two. Recursive.
Recursion.  Identify recursive algorithms  Write simple recursive algorithms  Understand recursive function calling  With reference to the call stack.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Great Theoretical Ideas in Computer Science.
The Golden Ratio, Fibonacci Numbers, And Other Recurrences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2006 Lecture 13October.
Great Theoretical Ideas in Computer Science for Some.
Advanced Counting Techniques
Sequences defined recursively
Recursion Chapter 7 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Department of Computer Science Data Structures Using C++ 2E Chapter 6: Recursion Learn about recursive Definitions Algorithms Functions Explore the base.
© 2006 Pearson Addison-Wesley. All rights reserved 3-1 Chapter 3 Recursion: The Mirrors.
Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Recursion: The Mirrors Chapter 2.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
GOLDEN MEAN AUKSO PJŪVIS. Definition of the Golden Rectangle The Golden Rectangle is a rectangle that can be split into a square and a rectangle similar.
The power of logarithmic computations Jordi Cortadella Department of Computer Science.
CS-2852 Data Structures LECTURE 12B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Ch. 7: Advanced Counting Techniques
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Week 6 - Monday.  What did we talk about last time?  Exam 1!  Before that:  Recursion.
1 Recursion Recursive method –Calls itself (directly or indirectly) through another method –Method knows how to solve only a base case –Method divides.
1 CSE 20 Lecture 11 Function, Recursion & Analysis CK Cheng UC San Diego.
Great Theoretical Ideas in Computer Science.
Leonardo Pisano Fibonacci
Fibonacci Numbers, Vector Programs and a new kind of science.
Fibonacci Sequences and the Golden Ratio Carl Wozniak Northern Michigan University.
Layout Design With Mathamatics
Which rectangle do you like most?
The Fibonacci Sequence. Leonardo Fibonacci (1170 – 1250) First from the West, but lots of evidence from before his time.
COMPSCI 102 Discrete Mathematics for Computer Science.
Great Theoretical Ideas in Computer Science.
1:1.618 The Golden Ratios Phi. Golden Rectangle Fibonacci Numbers The series begins with 0 and 1. Add the last two numbers to get the next. 1, 2, 3,
1 Examples of Recursion Instructor: Mainak Chaudhuri
COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones.
By Steven Cornell.  Was created by Leonardo Pisano Bogollo.  It show’s the growth of an idealized rabbit population.
Essential Questions Introduction to Sequences
Recurrences, Phi and CF Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006 Lecture 13 Feb 28, 2006 Carnegie Mellon.
7. RECURSIONS Rocky K. C. Chang October 12, 2015.
COMPSCI 102 Introduction to Discrete Mathematics.
Recursive Sequences Terry Anderson. What is a Recursive Sequence? A sequence that follows a pattern involving previous terms  To generate new terms,
Petals Most flowers have 5 or 8 petals Seeds Many plants have 3, 5 or 8 seeds.
Sequences and Summations ICS 6D Prof. Sandy Irani.
Recursion by Ender Ozcan. Recursion in computing Recursion in computer programming defines a function in terms of itself. Recursion in computer programming.
History Of Golden Section Ludovica Boncompagni – Italy Evaggelia Antonaki – Greece Team Coordinator – Enrica Maragliano - Italy.
A Number You Can Call Your Own
Induction: One Step At A Time
Fibonacci Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 Definition:
Great Theoretical Ideas in Computer Science
Golden Section and Ratio
Induction: One Step At A Time
Induction: One Step At A Time
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Chapter 3 :Recursion © 2011 Pearson Addison-Wesley. All rights reserved.
Induction: One Step At A Time
Presentation transcript:

CPE 130 Algorithms and Data Structures Recursion Asst. Prof. Dr. Nuttanart Facundes

Leonardo Fibonacci In 1202, Fibonacci proposed a problem about the growth of rabbit populations.

Leonardo Fibonacci In 1202, Fibonacci proposed a problem about the growth of rabbit populations.

Leonardo Fibonacci In 1202, Fibonacci proposed a problem about the growth of rabbit populations.

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

The rabbit reproduction model A rabbit lives forever The population starts as a single newborn pair Every month, each productive pair begets a new pair which will become productive after 2 months old F n = # of rabbit pairs at the beginning of the n th month month rabbits

Inductive Definition or Recurrence Relation for the Fibonacci Numbers Stage 0, Initial Condition, or Base Case: Fib(1) = 1; Fib (2) = 1 Inductive Rule For n>3, Fib(n) = Fib(n-1) + Fib(n-2)n Fib(n)%

Inductive Definition or Recurrence Relation for the Fibonacci Numbers Stage 0, Initial Condition, or Base Case: Fib(0) = 0; Fib (1) = 1 Inductive Rule For n>1, Fib(n) = Fib(n-1) + Fib(n-2)n Fib(n)

Recursion case study: Fibonacci Numbers Fibonacci numbers are a series in which each number is the sum of the previous two numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

Figure 6-9

Algorithm for Fibonacci Numbers The algorithm for calculating Fibonacci numbers: intfib(int n) { if (n < 2) return n; if (n < 2) return n;else return fib(n – 1) + fib(n – 2); return fib(n – 1) + fib(n – 2);}

Great Pyramid at Gizeh

The ratio of the altitude of a face to half the base b a

Notre Dame in Paris: Phi

Golden Ratio: the divine proportion  = … “Phi” is named after the Greek sculptor Phidias How is the Golden Ratio related to Fibonacci numbers?

Tower of Hanoi

Recursion case study: Tower of Hanoi We need to do 2 n – 1 moves to achieve the task, while n = the number of disks.

Solution for 2 disks

Solution for 3 disks, Part I

Solution for 3 disks, Part II

Tower of Hanoi: The Algorithm 1.Move n – 1 disks from source to auxiliaryGeneral Case 2.Move one disk from source to destinationBase Case 3.Move n – 1 disks from auxiliary to destinationGeneral Case