zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What are the general steps for writing a recursive function?

  1. Identify the base case(s). 2. Define the recursive call to solve a smaller subproblem. 3. Ensure the recursive call moves towards the base case.
Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What are the general steps for writing a recursive function?

  1. Identify the base case(s). 2. Define the recursive call to solve a smaller subproblem. 3. Ensure the recursive call moves towards the base case.

What are the steps of the binary search algorithm?

  1. Find the middle element. 2. Compare the target to the middle element. 3. If target equals middle, return index. 4. If target is less than middle, search the left half. 5. If target is greater than middle, search the right half. 6. Repeat until found or search space is empty.

What are the main steps of the merge sort algorithm?

  1. Divide the array into two halves. 2. Recursively sort the two halves. 3. Merge the sorted halves.

What are the differences between recursion and iteration?

Recursion: Solves problems by breaking them into smaller, self-similar subproblems. Can be more elegant for some problems. | Iteration: Solves problems by repeating a block of code until a condition is met. Generally more efficient in terms of speed and memory.

What are the differences between linear search and binary search?

Linear Search: Checks each element sequentially. Works on unsorted arrays. | Binary Search: Repeatedly divides the search interval in half. Requires a sorted array.

What are the key differences between iterative and recursive binary search?

Iterative Binary Search: Uses loops to narrow the search space. More efficient in terms of memory usage. | Recursive Binary Search: Calls itself with smaller sub-arrays. Can be more concise and easier to read for some programmers.

What is the definition of Recursion?

A method of solving a problem where the solution depends on solutions to smaller instances of the same problem. A function calls itself with a smaller version of the original problem.

What is the definition of Base Case?

A condition in a recursive method that terminates the recursive calls and provides a direct solution.

What is the definition of Recursive Call?

When a function calls itself with a modified version of the original problem, usually after checking the base case.

What is the definition of Binary Search?

A search algorithm that finds the position of a target value within a sorted array by repeatedly dividing the search interval in half.

What is the definition of Merge Sort?

An efficient, general-purpose, comparison-based sorting algorithm that divides an array into two halves, sorts each half, and then merges the sorted halves back together.