Algorithms and Complexity - Time Complexity of Recursive Algorithms

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/17

flashcard set

Earn XP

Description and Tags

Flashcards for reviewing time complexity of recursive algorithms, covering recursive algorithms definition, examples, and methods to evaluate time complexity such as Back Substitution, Recursion Tree, and Master Theorem.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

What is a recursive algorithm?

An algorithm which calls itself with smaller input values.

2
New cards

When can you use a recursive algorithm?

A problem can be solved utilizing solutions to smaller versions of the same problem, and the smaller versions reduce to easily solvable cases.

3
New cards

In order to calculate the time complexity of a recursive function, what do we need to do?

To define its time complexity function T(n).

4
New cards

If Sum(1) is computed using a fixed number of operations C1, what is T(1)?

T(1) = C1

5
New cards

If n > 1 the function will perform a fixed number of operations C2, and in addition, it will make a recursive call to Sum(n-1). What is the total?

T(n) = C2 + T(n-1)

6
New cards

How can we reduce finding the time complexity of the Sum function?

Finding the time complexity of the Sum function can then be reduced to solving the recurrence relation T(1) = 1 and T(n) = T(n-1) + 1 when n > 1.

7
New cards

How does a recursive implementation of a Binary Search algorithm work?

Compare the mid of the search space with the key, return the index where the key is found, or call the recursive function for the next search space, halving the search space with each call.

8
New cards

What is the recurrence relation of the recursive binarySearch function?

T(n) = T(n/2) + 1 when n > 1 and T(1) = 1

9
New cards

What is back substitution in the context of recursive algorithms?

A method for finding T(n) in terms of n by repeatedly substituting T(n-1), T(n-2), etc., until a base case is reached.

10
New cards

What is the general formula derived from back substitution in the example provided for the Sum function?

T(n) = T(n-k) + k

11
New cards

How can we reduce finding the time complexity of the recursive binarySearch function?

Finding the time complexity of the recursive binarySearch function can be reduced to solving the recurrence relation T(n) = T(n/2) + 1 when n > 1 and T(1) = 1.

12
New cards

What is the time complexity of binary search?

The algorithm is O(log₂(n)).

13
New cards

What is a recursion tree and what is it useful for?

A diagram that represents the tree of recursive calls and the work done at each call, useful for visualizing recurrence iteration.

14
New cards

What are Trees?

Trees are special cases of graphs having no loops and only one path between any two vertices.

15
New cards

What is the depth of a tree?

Depth of the deepest node.

16
New cards

What is the branching factor of a tree?

The number of children at each node.

17
New cards

What is the Master Theorem?

A theorem used to solve recurrence relations of the form T(n) = aT(n/b) + f(n) under certain conditions.

18
New cards

Under what conditions can you NOT use the Master Theorem?

T(n) is not monotone, f(n) is not a polynomial, b cannot be expressed as a constant.