Recursion and Binary Search

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

flashcard set

Earn XP

Description and Tags

Vocabulary practice flashcards covering recursion fundamentals, call stack operations, iterative vs. recursive trade-offs, complexity analysis, and binary search implementation details from Lesson 07.

19 Terms

1
New cards

Recursion

A problem-solving technique where a function solves a problem by calling itself with smaller versions of the same problem.

2
New cards

Base Case

The condition in a recursive algorithm that stops recursion and prevents infinite execution.

3
New cards

Recursive Case

The part of a recursive function where it calls itself with a smaller or simpler subproblem to make progress toward the base case.

4
New cards

Call Stack

The internal data structure used during program execution to keep track of active function calls, parameters, local variables, and return addresses.

5
New cards

Recursive Factorial

A mathematical function on non-negative integers defined recursively as n!=n×(n−1)!n! = n \times (n - 1)!, with the base case 0!=10! = 1.

6
New cards

Complexity of Recursive Factorial

An algorithm that takes O(n)O(n) time and O(n)O(n) auxiliary space because each recursive call must be stored in the call stack.

7
New cards

Complexity of Iterative Factorial

An algorithm that takes O(n)O(n) time and O(1)O(1) auxiliary space because it uses loop control variables with minimal call stack usage.

8
New cards
<p>Overlapping Subproblems in Recursive Fibonacci</p>

Overlapping Subproblems in Recursive Fibonacci

A property of naive recursive Fibonacci where identical function calls are computed repeatedly across different branches, resulting in an exponential time complexity of approximately O(2n)O(2^n).

9
New cards

Complexity of Naive Recursive Fibonacci

An implementation that has a time complexity of approximately O(2n)O(2^n) due to repeated calculations and a space complexity of O(n)O(n) proportional to the deepest chain of recursive calls.

10
New cards

Complexity of Iterative Fibonacci

An iterative approach that executes in O(n)O(n) time and requires O(1)O(1) auxiliary space.

11
New cards

Common Recursion Errors

Flaws in recursive programming that lead to infinite recursion or crashes: having no base case, never reaching the base case, or failing to make correct recursive progress toward the base case.

12
New cards

Linear Search

A sequential search algorithm that checks elements one by one from beginning to end, with a worst-case time complexity of O(n)O(n).

13
New cards

Binary Search

A search algorithm operating on sorted data that repeatedly compares the target with the middle element and discards half of the search space at each step.

14
New cards

Sorted Data Precondition

The requirement that an array must be ordered for binary search to work, ensuring the algorithm can safely discard one half of the elements based on the middle comparison.

15
New cards

Midpoint Formula (Binary Search)

The index calculation given by mid=(low+high)//2\text{mid} = (\text{low} + \text{high}) // 2 used to find the center index between bounds low\text{low} and high\text{high}.

16
New cards

Base Case of Recursive Binary Search

The condition low>high\text{low} > \text{high}, which signifies that the target element is absent from the array and returns −1-1.

17
New cards

Time Complexity of Binary Search

O(log⁡(n))O(\log(n)) in both worst and average cases, derived from halving the search space at each step until n/2k=1n / 2^k = 1, which yields k=log⁡2(n)k = \log_2(n).

18
New cards

Auxiliary Space of Binary Search (Iterative vs. Recursive)

Iterative binary search requires O(1)O(1) auxiliary space, whereas recursive binary search requires O(log⁡(n))O(\log(n)) auxiliary space due to call stack frames.

19
New cards

Divide-and-Conquer

An algorithmic paradigm that breaks a problem down into smaller subproblems of the same type, solves them, and combines the solutions, as seen in Binary Search, Merge Sort, and Quick Sort.