1. Trang chủ
  2. » Tất cả

Đề thi cấu trúc dữ liệu và giải thuật dsa ch3 recursion (2)

47 1 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

Thông tin cơ bản

Định dạng
Số trang 47
Dung lượng 609,84 KB

Nội dung

Recursion Dr Nguyen Ho Man Rang Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and backtracking Recursion implementation in[.]

Recursion Dr Nguyen Ho Man Rang Chapter Recursion Data Structures and Algorithms Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Dr Nguyen Ho Man Rang Faculty of Computer Science and Engineering University of Technology, VNU-HCM Recursion and backtracking Recursion implementation in C/C++ 3.1 Outcomes Recursion Dr Nguyen Ho Man Rang • L.O.8.1 - Describe the basic components of recursive algorithms (functions) • L.O.8.2 - Draw trees to illustrate callings and the value of parameters passed to them for recursive algorithms • L.O.8.3 - Give examples for recursive functions written in C/C++ • L.O.8.5 - Develop experiment (program) to compare the recursive and the iterative approach • L.O.8.6 - Give examples to relate recursion to backtracking technique Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and backtracking Recursion implementation in C/C++ 3.2 Contents Recursion Dr Nguyen Ho Man Rang Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and backtracking Recursion implementation in C/C++ Recursion and backtracking Recursion implementation in C/C++ 3.3 Recursion Dr Nguyen Ho Man Rang Recursion and the basic components of recursive algorithms Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and backtracking Recursion implementation in C/C++ 3.4 Recursion Recursion Dr Nguyen Ho Man Rang Definition Recursion is a repetitive process in which an algorithm calls itself • Direct : A → A Recursion and the basic components of recursive algorithms • Indirect : A → B → A Example Factorial Properties of recursion " F actorial(n) = Using recursion: " F actorial(n) = n × (n − 1) × × × if n = if n > Designing recursive algorithms Recursion and backtracking Recursion implementation in C/C++ n × F actorial(n − 1) if n = if n > 3.5 Recursion Basic components of recursive algorithms Dr Nguyen Ho Man Rang Two main components of a Recursive Algorithm Base case (i.e stopping case) General case (i.e recursive case) Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Example Factorial F actorial(n) = " n × F actorial(n − 1) if n = if n > base general Recursion and backtracking Recursion implementation in C/C++ 3.6 Recursion Recursion Dr Nguyen Ho Man Rang Recursion and the basic components of recursive algorithms Properties of recursion Designing recursive algorithms Recursion and backtracking Factorial (3) Recursively (source: Data Structure - A pseudocode Approach with C++) Recursion implementation in C/C++ 3.7 Recursion Recursion Dr Nguyen Ho Man Rang Factorial: Iterative Solution Algorithm iterativeFactorial(n) Calculates the factorial of a number using a loop Pre: n is the number to be raised factorially Post: n! is returned - result in factoN i=1 factoN = while i

Ngày đăng: 25/03/2023, 08:39

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

TÀI LIỆU LIÊN QUAN

w