You should be able to implement all of the functions declared in the functions.hpp
, string.hpp
, and sorts.hpp
files.
Although there are some functions that may not be solvable recursively, you should be able to solve the vast majority both iteratively, and recursively.
You should be able to analyze and discuss all algorithms and functions we have implemented in class, along with analyzing some fictitious pseudocode algorithms.
- What are the required components of recursive programming?
- What happens when you create a recursive function that does not reduce the problem size on each call?
Provide recursive definitions, recurrence relations, and Big-Oh notation for the following functions:
function func(int x):
return (x) ? func(abs(x) - 1) + x : 0;
function func(int[] array, int n):
if n <= 1: return
else:
swap(array[0], array[n-1])
func(array + 1, n - 2)
- What does it mean for a sorting algorithm to be stable?
- What does it mean for a sorting algorithm to be in-place?
- What does it mean for a sorting algorithm to be adaptive?
- If you were given input conditions that the arrays would always be almost completely sorted, what algorithm would you choose?
- Given input constraints that every input array would be smaller then 10 elements, which algorithm would you choose? Does it matter?
Calculate the value for n
at which you would choose algorithm A over algorithm B to sort a given list, or if you would always choose algorithm B.
A: T1(n) = 27n; B: T2(n) = n!
A: T1(n) = 10n log n; B: T2(n) = 2^n
A: T1(n) = 5n + n^2 - 6; B: T2(n) = n^3 / 2
A: T1(n) = n^60; B: T2(n) = 100n
- Provide the upper and lower bounds for best and worst cases for Bubble Sort.
- Is Bubble Sort stable? Adaptive? In-Place?
- Are there any advantages to Bubble Sort?
- What is the space-complexity of Bubble Sort?
- Provide the upper and lower bounds for the best and worst cases for Insertion Sort.
- Is Insertion Sort stable? Adaptive? In-Place?
- What are the advantages to Insertion Sort?
- What is the space-complexity of Insertion Sort?
- Provide the upper and lower bounds for the best and worst cases for Selection Sort.
- Is Selection Sort stable? Adaptive? In-Place?
- Are there any advantages to Selection Sort?
- What is the space-complexity of Selection Sort?
- Provide the upper and lower bounds for the best and worst cases for MergeSort.
- Is MergeSort stable? Adaptive? In-Place?
- What is the purpose of the
merge
function in most MergeSort implementations? What about theMergeSort
function? - What is the space complexity of MergeSort?
- Provide the upper and lower bounds for the best and worst cases for QuickSort.
- Is QuickSort stable? Adaptive? In-Place?
- What is the purpose of the
partition
function in quicksort? What about thequicksort
function? - What partitioning scheme did you use in class for your
partition
function? - Find an array that would produce the worst case runtime for this partitioning scheme.
Solve the following recurrence relations:
T(0) = 1 ; T(n) = 2T(n - 1) + 1
T(1) = 1 ; T(n) = 2T(n / 2) + n
T(0) = 1 ; T(n) = T(n - 1) + n
T(1) = 1 ; T(n) = T(n / 3) + 1
T(0) = 1 ; T(n) = T(n - 4) + 1