Data Structure CSC311
Arrange the following complexities in increasing order: Quadratic, constant, exponential, logarithmic
constant, logarithmic, Quadratic, exponential
What value do you return to indicate an unsuccessful search of an element in an array or ArrayList?
-1
Consider an algorithm with logarithmic time complexity. How many additional operations are required for the given algorithm when the size of the input is doubled?
1
Consider the algorithm for determining whether a sequence of parentheses is balanced using stack. What is the maximum number of parentheses that will appear on the stack (at any instant, during the entire process) when the algorithm analyzes: (()(())(()))?
3
What notation have we learned that gives an upper bound on algorithms performance?
Big-O notation
Data elements are always shifted while performing insertion in an ArrayList.
False
Modifying the top and the bottom element is allowed in a Stack
False
What is the storage policy of a stack?
Last in First out (LIFO)
The simplest way to search an array is called __________ search
Linear
Consider the following code: int calculate(int val, int raise, int total){ int mid = (val + raise)/2; raise = val + mid; total = raise * total; return total; } What is the time complexity of the above?
O(1)
Consider the following code: (Assume the array has n elements) for(int i = 1; i < arr.length; i *= 2){ value = value + arr[i]; } What is the time complexity of the above?
O(log n)
Consider following method: public static int factorialIter(int n){ int result = 1; for(int k = 1; k <=n; k++) result = result * k; return result; } The efficiency of the above code is: ________
O(n)
What is the time complexity for deleting an element from an ArrayList?
O(n)
What is the time complexity for inserting data into an ArrayList?
O(n)
What is the theoretical lower bound time complexity for a matrix multiplication algorithm?
O(n^2)
An algorithm in O(n2) is also in O(n3)
True
What is the thread-safe equivalent of ArrayList in Java?
Vector
declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty ) { write the stack's top character to the screen pop a character off the stack } What is written to the screen using the above pseudocode for the input "hello"?
olleh
What are any 2 characteristics of a good algorithm?
precision uniqueness finiteness input output precise unique finite
What helper method is called to insert data in an already full ArrayList?
reallocate