Notes From CS Undergrad Courses FSU
This project is maintained by awa03
Instructions: Answer all questions, marking T for True or F for False in the T/F questions. Write answers clearly for short answer questions, for longer problems provide well commented code and explanations. Keep answers concise and organized.
// put code here
unsigned int factorial(int n){
if(n == 0 || n == 1){return 1;}
else return n * factorial(n-1);
}
// put code here
int fibonacci(int n){
if(n <= 1){
return n; // base case
}
else {
// Recursive call
return fibonacci(n-1) + fibonacci(n-2);
}
}
True or False: Induction is a technique used to prove the correctness of algorithms or mathematical statements. True
Explain the concept of geometric series and provide a formula to calculate the sum of a geometric series. A geometric sequence of numbers where each term after the first is found by multiplying the previous term by a fixed number. The formula is $Sum = \frac{a}{1-r}$
Prove by induction that for all positive integers n, 1 + 2 + 3 + ... + n = (n * (n + 1)) / 2.
Explain the differences between 'public', 'private', and 'protected' access specifiers in C++ classes. Public member variables are accessible from wherever, assuming they are within the scope of declaration. Private member variables only hold scope within the class that they are declare in, these values may be returned through a getter. Protected Variables are accessible through inherited classes.
Discuss different parameter passing methods in C++ (e.g., pass by value, pass by reference) and provide examples for each. Pass by value allows for a copy to be made of the passing value, this may be disadvantageous for passing large values or objects. A more suitable alternative may be pass by reference which allows for direct access to the object/ value to be passed.
Define and explain the concept of function objects in C++. Function objects allow for comparison of objects. For example the operator== may allow a class to be compared for equality with another class.
// code goes here
template <typename T>
void move(T& obj1, T& obj2){
T object = obj1;
obj1 = obj2;
obj2 = object;
}
Templates allow for passed values to be of any type. This allows functions too serve multiple purposes, and utilize differing values. For example say a user wants to see if all values within an array are equal. The user may use a template to allow for types other than int or string to be used.
// Example Worked Out
template <typename T>
bool equal(T* array){
int x = 0;
for(int i=0; i < array.size() - 1; ++i){
x = i+1;
if(!(array[i] == array[x])){
return false;
}
}
return true;
}
Define and explain the formal notations 'Big O', 'Big Omega', and 'Big Theta' used for analyzing algorithm complexity. Provide an example for each. Big O is the upper limit of the functions time complexity, meaning the worst case. Big Omega describes the best case, it represents the lower bounds of a function. Big theta is the average case, combining both the lower and upper bound.
Analyze the time complexity of a simple sorting algorithm (e.g., bubble sort) in terms of Big O notation.
Explain the circular array concept in the implementation of a deque data structure. How is the number of elements determined in a deque? A circular array holds both the head and the tail values. This allows for O(1) indexing of a circular queue. The number of elemnts is determined between the discrepency in space between the head and tail elements.
Provide the key methods and their time complexities for a doubly-linked list and its iterator implementation. O(1) insertion and deletion, O(n) printing the array
Describe the concept and prototype of a stack and its applications. Provide an example of an application using a stack data structure.
Explain the concept and prototype of a queue and its applications. Provide an example of an application using a queue data structure.
// code goes here
// code goes here