Coursify
Create New CourseGalleryContact

AP Computer Science Principales

Unit 1
Unit 1: Basics
Introduction to AP Computer Science AData TypesAlgorithmsObject Oriented Programming
Unit 2 • Chapter 1

Recursion

Video Summary

Recursion is a method of solving a problem by breaking it down into smaller and smaller subproblems until they reach a base case that can be solved directly. The solution to the original problem is then found by combining the solutions to the subproblems. For example, to find the factorial of a number n, you can start by recursively calling the factorial function with n-1. The base case is when n is 0, in which case the factorial is 1. The solution to the original problem is then n * factorial(n-1). Recursion can be a powerful tool for solving problems, but it can also be difficult to understand and implement. It is important to be careful when using recursion to avoid infinite loops.

Knowledge Check

What does a recursive function call itself?

What is the halting problem?

Which of the following is not a recursive data structure?