Lecture An introduction to object-oriented programming with Java: Chapter 15 - C. Thomas Wu

Chapter 15 - Recursive algorithms. In this chapter, we will present several nonnumerical recursive algorithms in this chapter. We will also discuss some criteria for deciding when to use recursion and when not to. All the recursive algorithms we provide in this chapter, other than those we use for explanation, are algorithms that should be written recursively. | ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Chapter 15 Recursive Algorithms Animated Version Introduction to OOP with Java 4th Ed, C. Thomas Wu © The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Objectives After you have read and studied this chapter, you should be able to Write recursive algorithms for mathematical functions and nonnumerical operations. Decide when to use recursion and when not to. Describe the recursive quicksort algorithm and explain how its performance is better than selection and bubble sort algorithms. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Recursion The factorial of N is the product of the first N positive integers: N * (N – 1) * (N – 2 ) * . . . * 2 * 1 The factorial of N can be defined recursively as 1 if N = 1 factorial( N ) = N * factorial( N-1 ) otherwise Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. The two most important concepts in object-oriented programming are the class and the object. In the broadest term, an object is a thing, both tangible and intangible, which we can imagine. A program written in object-oriented style will consist of interacting objects. For a program to maintain bank accounts for a bank, we may have many Account, Customer, Transaction, and ATM objects. An object is comprised of data and operations that manipulate these data. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Recursive Method An recursive method is a method that contains a statement (or statements) that makes a call to itself. Implementing the factorial of N recursively will result in the following method. public int factorial( int N ) { if ( N == 1 ) { return 1; } else { return N * . | ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Chapter 15 Recursive Algorithms Animated Version Introduction to OOP with Java 4th Ed, C. Thomas Wu © The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Objectives After you have read and studied this chapter, you should be able to Write recursive algorithms for mathematical functions and nonnumerical operations. Decide when to use recursion and when not to. Describe the recursive quicksort algorithm and explain how its performance is better than selection and bubble sort algorithms. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 15 - Recursion The factorial of N is the product of the first N positive integers: N * (N – 1) * (N – 2 ) * . . . * 2 * 1 The factorial of N can be defined .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.