Topics of Recursion. 4.Recursive algorithm. 1.Snow Flake 2.Developing Methodology 3.Property of Recursion. 5.Recurrence Model 6.

Σχετικά έγγραφα
Introduction. peptide linkage NH CH C CH C

บทท 6 บทเร ยน ท 18 บททบทวนบทเร ยนท 13-17

11, , , , , , , ,075.00


การสม ครงาน จดหมายอ างอ ง

ว นท พ มพ : 30/9/ :36:21 หน า : 1/60 รายงานรายละเอ ยดประมาณการรายจ ายงบประมาณรายจ ายท วไป ประจ าป งบประมาณ พ.ศ องค การบร หารส วนต าบลจารพ

บทท 6 ค าอธ บายบทเร ยนท 12

การสม ครงาน จดหมายอ างอ ง

ค ณช วยอะไรฉ นหน อยได ไหม? (Khun chuay arai chan noi dai mai?) ค ณพ ดภาษาอ งกฤษหร อเปล า? (Khun pood pasa ang-grid rue plao?)

Può aiutarmi? Parla inglese? Parla _[lingua]_?

การสม ครงาน จดหมายอ างอ ง

Ταξίδι Γενικά. Γενικά - Τα απαραίτητα. Γενικά - Συνομιλία. Phiền bạn giúp tôi một chút được không?

Concrete Mathematics Exercises from 30 September 2016

Ταξίδι Γενικά. Γενικά - Τα απαραίτητα. Γενικά - Συνομιλία. Μπορείτε να με βοηθήσετε; (Borίte na me voithίsete?) Παράκληση για βοήθεια

Ταξίδι Γενικά. Γενικά - Τα απαραίτητα. Γενικά - Συνομιλία. ค ณช วยอะไรฉ นหน อยได ไหม? (Khun chuay arai chan noi dai mai?) Παράκληση για βοήθεια

Ταξίδι Γενικά. Γενικά - Τα απαραίτητα. Γενικά - Συνομιλία. Μπορείτε να με βοηθήσετε; (Borίte na me voithίsete?)

Matrices and Determinants

Για να ρωτήσετε αν κάποιος μπορεί να σας βοηθήσει να γεμίσετε μια φόρμα

ค ม อการใช งาน ฉบ บย อ

Section 8.3 Trigonometric Equations

Προγραµµατισµός. Αναδροµή (1/2)

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

Προγραμματισμός Αναδρομή

4.6 Autoregressive Moving Average Model ARMA(1,1)

Chap. 6 Pushdown Automata

Προγραμματισμός Αναδρομή

ค ณช วยอะไรฉ นหน อยได ไหม? (Khun chuay arai chan noi dai mai?) ค ณพ ดภาษาอ งกฤษหร อเปล า? (Khun pood pasa ang-grid rue plao?)

Απόκριση σε Μοναδιαία Ωστική Δύναμη (Unit Impulse) Απόκριση σε Δυνάμεις Αυθαίρετα Μεταβαλλόμενες με το Χρόνο. Απόστολος Σ.

Areas and Lengths in Polar Coordinates

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

D Alembert s Solution to the Wave Equation

Section 7.6 Double and Half Angle Formulas

Durbin-Levinson recursive method

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

2 Composition. Invertible Mappings

EE512: Error Control Coding

Second Order RLC Filters

Areas and Lengths in Polar Coordinates

6.3 Forecasting ARMA processes

Inverse trigonometric functions & General Solution of Trigonometric Equations

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

Lecture 2. Soundness and completeness of propositional logic

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

derivation of the Laplacian from rectangular to spherical coordinates

Πανεπιστήμιο Δυτικής Μακεδονίας. Τμήμα Μηχανικών Πληροφορικής & Τηλεπικοινωνιών. Τεχνητή Νοημοσύνη. Ενότητα 2: Αναζήτηση (Search)

Jesse Maassen and Mark Lundstrom Purdue University November 25, 2013

ST5224: Advanced Statistical Theory II

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

The challenges of non-stable predicates

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

ES440/ES911: CFD. Chapter 5. Solution of Linear Equation Systems

ANSWERSHEET (TOPIC = DIFFERENTIAL CALCULUS) COLLECTION #2. h 0 h h 0 h h 0 ( ) g k = g 0 + g 1 + g g 2009 =?

Practice Exam 2. Conceptual Questions. 1. State a Basic identity and then verify it. (a) Identity: Solution: One identity is csc(θ) = 1

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

ΜΥΥ105: Εισαγωγή στον Προγραµµατισµό. Αναδροµικές Συναρτήσεις Χειµερινό Εξάµηνο 2014

Homework 3 Solutions

Numerical Analysis FMN011

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

The Simply Typed Lambda Calculus

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Homework 8 Model Solution Section

Example Sheet 3 Solutions

Finite Field Problems: Solutions

Fractional Colorings and Zykov Products of graphs

Διάλεξη 20: Αναδρομή (Recursion) Διδάσκων: Παναγιώτης Ανδρέου

Μεταγλωττιστές Βελτιστοποίηση

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Αναδρομή (Recursion) Πώς να λύσουμε ένα πρόβλημα κάνοντας λίγη δουλειά και ανάγοντας το υπόλοιπο να λυθεί με τον ίδιο τρόπο.

Math221: HW# 1 solutions

Problem Set 3: Solutions

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Differential equations

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

Partial Differential Equations in Biology The boundary element method. March 26, 2013

A Bonus-Malus System as a Markov Set-Chain. Małgorzata Niemiec Warsaw School of Economics Institute of Econometrics

Forced Pendulum Numerical approach

C.S. 430 Assignment 6, Sample Solutions

( y) Partial Differential Equations

ΑΛΓΟΡΙΘΜΟΙ Άνοιξη I. ΜΗΛΗΣ

Διάλεξη 15: Αναδρομή (Recursion) Διδάσκων: Παναγιώτης Ανδρέου

ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 7η: Consumer Behavior Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

Mock Exam 7. 1 Hong Kong Educational Publishing Company. Section A 1. Reference: HKDSE Math M Q2 (a) (1 + kx) n 1M + 1A = (1) =

Reminders: linear functions

Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

Αναδροµή (Recursion) ύο παρεξηγήσεις. Σκέψου Αναδροµικά. Τρίγωνο Sierpinski Μη αναδροµικός ορισµός;

Lanczos and biorthogonalization methods for eigenvalues and eigenvectors of matrices

Review Test 3. MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Answers - Worksheet A ALGEBRA PMT. 1 a = 7 b = 11 c = 1 3. e = 0.1 f = 0.3 g = 2 h = 10 i = 3 j = d = k = 3 1. = 1 or 0.5 l =

Trigonometric Formula Sheet

- 1+x 2 - x 3 + 7x x x x x x 2 - x 3 - -

SOLUTIONS TO MATH38181 EXTREME VALUES AND FINANCIAL RISK EXAM

CHAPTER 101 FOURIER SERIES FOR PERIODIC FUNCTIONS OF PERIOD

Math 6 SL Probability Distributions Practice Test Mark Scheme

Πανεπιστήμιο Πελοποννήσου. Σχολή Θετικών Επιστημών & Τεχνολογίας. Τμήμα Επιστήμης & Τεχνολογίας Υπολογιστών. Προγραμματισμός Ι Εργαστήριο

MAT Winter 2016 Introduction to Time Series Analysis Study Guide for Midterm

Every set of first-order formulas is equivalent to an independent set

SOLUTIONS TO MATH38181 EXTREME VALUES AND FINANCIAL RISK EXAM

Transcript:

Topics of Recursion 1.Snow Flake 2.Developing Methodology 3.Property of Recursion Step Level Depth 4.Recursive algorithm factorial function fibonacci sequence Ackermanm Function 5.Recurrence Model 6.Removing Recursion 1

Solving Recurrences 1. Solving Recurrences Using Induction 2. Solving Recurrences Using The Characteristic Equation 2.1 Homogeneous Linear Recurrences 2.2 Nonhomogeneo us Linear Recurrences 3. Solving Recurrences By Substitution 2

1.Snow flake ค อร ปแบบ fractal ท น ามาท าให ร ปร างตามส วนใด ส วนหน งของร ปภาพซ งม ขนาดใดก ได เม อน ามาขยายก จะมองเห นเหม อนร ปภาพเด ม ซ ง ประกอบด วย 1. Primitive (ภาพเร มต น) 2. กฎการ recursive ซ งส มพ นธ ก บ ส วนของร ป...ซ งม ขนาดต างๆก น 3

Fractal and Snowflake Definition of Fractal Fractal : โดยล กษณะของร ป... ท ม การแผ ออกไปน จะถ กเร ยกว า... ร ปต วอย างท Supplement บน web 4

2.Developing Methodology When developing a recursive algorithm for a problem, we need to Develop a way to obtain the solution to an instance from the solution to one or more smaller instances. Determine the terminal condition(s) that the smaller instance(s) is (are) approaching Determine the solution in the case of the terminal condition(s) 5

3.Property of Recursion A recursive program is one that calls... Algorithm ท ม ล กษณะ recursion ค อม ค ณสมบ ต ด งน 1. ม ค า argument บางต วท เร ยกว า... เพ อเป น... 2. ในแต ละคร งท เร ยกต วเองจะต องเข าใกล... ต วอย าง recursive program ท ร จ กก นด ได แก factorial... 6

4.1Factorial ผลค ณของเลขจ านวนเต มบวกจาก 1 ถ ง n ค อ n! n! =1*2*3*...*(n-2) * (n-1) * n ; when n >= 1 0! = Definition 1. If n = then n! = 2. If n > then n! = ด งน น factorial ม base value = จาก definition 7

ต วอย าง 4! ต วอย างเช น การแสดง step การหา 4! 1. 4! = 2. 3! = 3. 2! = 4. 1! = 5. 0! = 5. 0! = 1 6. 1! = = 7. 2! = = 8. 3! = = 9. 4! = = 8

Step 1. ก าหนด 4! ในเทอม ซ งย งไม ทราบค าของ 4! จนกว าจะทราบค าของ 2. ก าหนด 3! ในเทอม ซ งย งไม ทราบค าของ 3! จนกว าจะทราบค าของ 3. ก าหนด 2! ในเทอม ซ งย งไม ทราบค าของ 2! จนกว าจะทราบค าของ 4. ก าหนด 1! ในเทอม ซ งย งไม ทราบค าของ 1! จนกว าจะทราบค าของ 5. ได ค าของ 0! = 1 เน องจาก เป น base value 6.-9. ท างานกล บโดยใช ค า 0! แทนค าให 1! และ 1! แทนค าให 2! ไป เร อยๆ 9

Level and Depth of Recursion จ านวน...ของโปรแกรมท เก ดข นในระหว างการเร ยกต วเอง หมายเลขระด บในแต ละการท างานของโปรแกรมพ จารณาจากข อม ลท เหล ออย ใน ในแต ละ ยกต วอย างจาก การหา 4! การแสดงการท างานแบบ Recursion จะ ใช stack ในการเก บค า ส าหร บข นตอนการเร ยกต วเอง step ท 1-5 จะเป นการ push ค า factorial ท ย งไม ทราบลงก อน step ท 5-4 ก จะเป นการแทนค ากล บแล ว pop ค า ออกจาก stack 4! 10

step ท level ยกต วอย างจาก การหา 4! 1 2 4 1! 3 2! 3 2! 2 3! 2 3! 2 3! 2 1 4! 1 4! 1 4! 1 4! 1 4! 3 4 5 4 3 5 0! = 1 1! 2! 3! 4 1 3 2! 3 2 2 3! 2 3! 1 4! 1 4! 6 7 2 1 6 4! 8 1 24 9 Depth = no. of max level ด งน น Depth = 5 11

ร ปของป ญหา : Factorial Algorithm Algorithms : Factorial Problem : Determining n! = 1* 2 * 3 *... * (n-2) * (n-1) * n ; when n >= 1 Inputs : Outputs : Function : 0! = 1 12

ร ปของป ญหา : Factorial Algorithm (ต อ) function fact(n:integer) : integer; begin if n = then fact := else fact := end; 13

Code in C of Factorial Function long rec_fac (long) { if (n= ) return( ) else return ( ); } 14

4.2Fibonacci sequence (อ นด บไฟโบแนซซ ) Definition : Fibonacci sequence IF n = or n = then F(n) = IF n > = then F(n) = base values : แบบฝ กห ด จงเข ยน - ร ปของป ญหา : Fibonacci sequence Algorithm - Code in C or Pascal or Any Language for : Fibonacci sequence 15

ร ปของป ญหา : Fibonacci Algorithm Algorithms : Fibonacci Problem : Determining Fib(n).. Inputs : a nonnegative integer n. =? Outputs : Fib(n) Function :.. 16

4.3Ackermamn Function : ฟ งก ช นแอคเคอร มานน Definition : Ackermanm IF m = then A(m,n) = IF m!= but n = then A(m,n) = A(m-1,1) IF m!= but n!= then A(m,n) = A(m-1,A(m,n-1)) base values (criteria) : m = 17

ต วอย าง Ackermamn Function หาค าของA(1,1) A(1,1) = A(1,0) = A(0,1) = A(1,0) = A(1,1) = A(0,2) = A(1,1) = 18

ร ปของป ญหา : Ackermanm Algorithm Algorithms : Ackemanm Problem : Determining A(n).. Inputs : a nonnegative integer n. =? Outputs : A(n) Function :.. 19

5.Recurrence Model การแปลงร ปจากสมการท วไปท ย งไม ใช ร ปแบบเว ยนเก ดให เป นร ปแบบ เว ยนเก ดหร อเร ยกต วเองท าได โดย 1. ท าการแปลงให อย ในร ปของ IF-Case 2. หา initial condition (base criteria) ต วอย างเช น ร ปท วไปของสมการ S(n) = S(n-1) + f(n) ; for all n = 1,2,3, S(0) = 1 ; special case for n= f(n) = n-1 20

5.Recurrence Model ร ปท วไปของสมการ สามารถท าให เป น Recurrence Model ได ด งน 1. If n = then S(n) = 2. If n > then S(n) = 21

6.Removing Recursion การแปลงร ปแบบของ recursive ให เป น non recursive เช น factorial long nonrec_fac(long n) { long fact; long i; // declaration if (n == ) return else { } for ( i = ;i <= fact = return ( ) ; i++) 22

GCD : Greatest Common Division Definition : GCD(B,A) ; A < B GCD (A,B) = A ; B = 0 Version Recursive Non-Recursive ต วอย างเช น การหา GCD(8,28) GCD(B,MOD(A,B)) ;otherwise 23

Recursive GCD int GCD_Rec (int a, int b) { if (b ==) return ; else if ( < ) GCD_Rec ( ) else GCD_Rec ( ); } 24