1. Trang chủ
  2. » Công Nghệ Thông Tin

Function & Recursion docx

35 328 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

 Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com Data Structures & Algorithms  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com   Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 1. Function 2. The Concept Of Stack 3. The Sequence Of Execution During A Function Call 4. Parameter Passing & Call By Reference 5. Resolving Variable References 6. Recursion 7. Stack Overheads In Recursion 8. Writing A Recursive Function 9. Types Of Recursion  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com  –  !"#$##%&'" –  (!)#"*# "!!""+",!#"* – -(!".'*  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com #  "$/#012#3 4 # 567 ./#56787993 4  5 9017 : # 7 :  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com ;-< – -stack  $'%%"!"#"#=!"# >##= ",$+(""!!push"pop  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com ?@AB--CC – When the funcon is called, the current execuon is temporarily stopped and the control goes to the called funcon. Aer the call, the execuon resumes from the point at which the execuon is stopped. – To get the exact point at which execuon is resumed, the address of #% )# ###%#"*. When the funcon call completes, the address at the top of the stack is taken.  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com ?@AB--CC – Funcons or sub-programs are implemented using a stack. – When a funcon is called, the address of the next instrucon is pushed into the stack. – When the funcon is !nished, the address for execuon is taken by using the pop operaon.  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com  Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com D--E-B – passing by value • #%"!,.""&#%"!! "#%"  – passing by reference • changed value aer the funcon completes [...]... INDUSTRY 9 TYPES OF RECURSION – LINEAR RECURSION (tuyến tính) – TAIL RECURSION (đuôi) – BINARY RECURSION (nhị phân) – EXPONENTIAL RECURSION (đa tuyến) – NESTED RECURSION (lồng) – MUTUAL RECURSION (tương hỗ) Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY 9 TYPES OF RECURSION LINEAR RECURSION Only makes... UNIVERSITY OF INDUSTRY 9 TYPES OF RECURSION - EXPONENTIAL RECURSION Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 9 TYPES OF RECURSION HO CHI MINH UNIVERSITY OF INDUSTRY – NESTED RECURSION • In nested recursion, one of the arguments to the recursive function is the recursive function itself • These functions tend to grow extremely... Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY 9 TYPES OF RECURSION – MUTUAL RECURSION • A recursive function doesn't necessarily need to call itself • Some recursive functions work in pairs or even larger groups For example, function A calls function B which calls function C which in turn calls function A Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn–... makes a single call to itself each time the function runs – • Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 9 TYPES OF RECURSION - HO CHI MINH UNIVERSITY OF INDUSTRY TAIL RECURSION Tail recursion is a form of linear recursion In tail recursion, the recursive call is the last thing the function does Often, the value of the recursive... http://duythanhcse.wordpress.com 9 TYPES OF RECURSION HO CHI MINH UNIVERSITY OF INDUSTRY - EXPONENTIAL RECURSION An exponential recursive function is one that, if you were to draw out a representation of all the function calls, would have an exponential number of calls in relation to the size of the data set (exponential n meaning if there were n elements, there would be O(a ) function calls where a is a positive... RECURSION - A method of programming whereby a function directly or indirectly calls itself - Problems: stop recursion? Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 6 RECURSION HO CHI MINH UNIVERSITY OF INDUSTRY Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 6 RECURSION. .. http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY 7 STACK OVERHEADS IN RECURSION Two important results: the depth of recursion and the stack overheads in recursion – Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY 8 WRITING A RECURSIVE FUNCTIONRecursion enables us to write a program in a natural way The... http://duythanhcse.wordpress.com 6 RECURSION HO CHI MINH UNIVERSITY OF INDUSTRY Hanoi tower Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 6 RECURSION HO CHI MINH UNIVERSITY OF INDUSTRY Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com 6 RECURSION HO CHI MINH UNIVERSITY... tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY 9 TYPES OF RECURSION – MUTUAL RECURSION Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY Exercises 1: Recursion • Convert number from H10->H2 7 1 2 3 1 2 1 2 1 0 Author: Trần Duy Thanh – Phone : 0987773061-... Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– Blog: http://duythanhcse.wordpress.com HO CHI MINH UNIVERSITY OF INDUSTRY Exercises 2: Recursion • • E1 (43/174) Write a program to compute: S = 1 + 2 + 3 + … n using recursion E2  E9 (page 43 -44 / 174) All Student must complete E1->E9 exercises IF not complete… Author: Trần Duy Thanh – Phone : 0987773061- Email: tranduythanh@hui.edu.vn– . !"#$##%&'" –  (!)#"*# "!!""+",!#"* – -(!".'*  Author:. http://duythanhcse.wordpress.com ;-< – -stack  $'%%"!"#"#=!"# >##= ",$+(""!!push"pop  Author:

Ngày đăng: 15/03/2014, 15:20

Xem thêm: Function & Recursion docx

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN