MOD 6_ZYBOOKS 7_RECURSION & ALGORITHM Flashcards

(36 cards)

1
Q

What is a recursive algorithm?

A

A recursive algorithm is an algorithm that breaks the problem into smaller subproblems and applies the same algorithm to solve the smaller subproblems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the base case?

A

A recursive algorithm must describe how to actually do something, known as the base case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a recursive function?

A

A function that calls itself is a recursive function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 2 steps to creating a recursive function?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are 2 common errors when creating recursive functions?

A

A common error is to not cover all possible base cases in a recursive function. Another common error is to write a recursive function that doesn’t always reach a base case. Both errors may lead to infinite recursion, causing the program to fail.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are “outer” and “inner” functions?

A

Typically, programmers will use two functions for recursion. An “outer” function is intended to be called from other parts of the program, like the function int CalcFactorial(int inVal). An “inner” function is intended only to be called from that outer function, for example a function int CalcFactorialHelper(int inVal). The outer function may check for a valid input value, e.g., ensuring inVal is not negative, and then calling the inner function. Commonly, the inner function has parameters that are mainly of use as part of the recursion, and need not be part of the outer function, thus keeping the outer function more intuitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Before writing a recursive function, a programmer should determine?

A

1) Does the problem naturally have a recursive solution?
2) Is a recursive solution better than a non-recursive solution?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an algorithm?

A

An algorithm describes a sequence of steps to solve a computational problem or perform a calculation. An algorithm can be described in English, pseudocode, a programming language, hardware, etc. as long as the algorithm precisely describes the steps of a computational procedure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a computational problem?

A

A computational problem specifies an input, a question about the input that can be answered using a computer, and the desired output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

VIEW: Example computational problems and common algorithms

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are NP-complete problems and what are their characteristics?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Algorithm efficiency is typically measured by?

A

The algorithm’s computational complexity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is computational complexity?

A

Computational complexity is the amount of resources used by the algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the most common resources considered by computational complexity?

A

Runtime and memory usage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an algorithm’s runtime complexity?

A

An algorithm’s runtime complexity is a function, T(N), that represents the number of constant time operations performed by the algorithm on an input of size N.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is meant by an algorithm’s best case and worst case scenario?

A

An algorithm’s best case is the scenario where the algorithm does the minimum possible number of operations. An algorithm’s worst case is the scenario where the algorithm does the maximum possible number of operations.

17
Q

VIEW: Input data size must remain a variable

18
Q

What is an algorithm’s space complexity?

A

An algorithm’s space complexity is a function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N.

Ex: The space complexity of an algorithm that duplicates a list of numbers is S(N) = 2N + k, where k is a constant representing memory used for things like the loop counter and list pointers.

19
Q

What is an algorithm’s auxiliary space complexity?

A

An algorithm’s auxiliary space complexity is the space complexity not including the input data.

Ex: An algorithm to find the maximum number in a list will have a space complexity of S(N) = N + k, but an auxiliary space complexity of S(N) = k, where k is a constant.

20
Q

What is a constant time operator?

A

In practice, designing an efficient algorithm aims to lower the amount of time that an algorithm runs. However, a single algorithm can always execute more quickly on a faster processor. Therefore, the theoretical analysis of an algorithm describes runtime in terms of number of constant time operations, not nanoseconds.

A constant time operation is an operation that, for a given processor, always operates in the same amount of time, regardless of input values.

21
Q

VIEW: Common constant time operations

22
Q

What are lower and upper bounds?

A

Given a function T(N), an infinite number of lower bounds and upper bounds exist. Ex: If an algorithm’s best case runtime is T(N) = 5N + 4, then subtracting any nonnegative integer yields a lower bound: 5N + 3, 5N + 2, and so on. So two additional criteria are commonly used to choose a preferred upper or lower bound. The preferred bound:

1) Is a single-term polynomial and
2) bounds T(N) as tightly as possible.

23
Q

What is an asymptotic notation?

A

Asymptotic notation is the classification of runtime complexity that uses functions that indicate only the growth rate of a bounding function.

24
Q

What 3 asymptotic notations are commonly used in complexity analysis?

25
VIEW: Notations for algorithm complexity analysis
26
What is Big O notation?
Big O notation is a mathematical way of describing how a function (running time of an algorithm) generally behaves in relation to the input size. In Big O notation, all functions that have the same growth rate (as determined by the highest order term of the function) are characterized using the same Big O notation. In essence, all functions that have the same growth rate are considered equivalent in Big O notation.
27
Given a function that describes the running time of an algorithm, the Big O notation for that function can be determined using what rules?
28
VIEW: Rules for determining Big O notation of composite functions
29
VIEW: Growth rates for different input sizes
30
VIEW: Common Big O runtime complexities
31
To analyze how runtime of an algorithm scales as the input size increases, we first determine how many ____ the algorithm executes for a specific ____ size, N. Then, the big-O notation for that function is determined.
Operations, input
32
Algorithm runtime analysis often focuses on?
The worst-case runtime complexity.
33
For algorithm analysis, the definition of a single operation does/does not need to be precise?
Does NOT
34
What is an operation?
An operation can be any statement (or constant number of statements) that has a constant runtime complexity, O(1).
35
Describe runtime analysis for nested loops.
Runtime analysis for nested loops requires summing the runtime of the inner loop over each outer loop iteration. The resulting summation can be simplified to determine the big-O notation.
36
VIEW: Common summation: Summation of consecutive numbers