CSC 2 Midterm Review
Which one is the big-O solution for the function as 3 log N + loglogN?
O(logN)
Proof by Contradiction assumes that the theorem is false and show that this assumption implies that some know property is true.
True
Proof by Counterexample is to find a counterexample to show the statement is false.
True
Proof by Induction should not only verify the base case but also the inductive case.
True
The equation X^A^ + XB = X^A+B is always held.
True
The lvalue reference is the standard reference type.
True
The recursive Fibonacci function is not efficient because it has a lot of redundant work.
True
Two ways for Algorithm Analysis are experimental studies and asymptotic algorithm analysis .
True
Using explicit constructor can avoid type conversions.
True
Which order is correct for typical growth rates with C standing for constant) a). C < log N < N < N3 < 2N b). C < N < logN < N3 < 2N c). C < N < logN < N3 < 2N d). C < logN < N < 2N < N3
b a c d
What value will the f(4) return from the following recursive function? int f( int x ) { if( x == 0 ) return 0 /* base case */ else return 2 * f( x - 1 ) + x * x /*recursive call*/ }a). 21 b). 58 c). 6 d). 45 c). none of the above
b) 58
Which statement is a legal statement? a)string & bad1 = "hello" b)string & bad2 = str + " " c)string & sub = str.substr( 0, 4) d)string && bad1 = "hello" e)All of the above
d) string && bad1 - "hello"
rvalue expression identifies a non-temporary object, points to a specific memory location and lives a longer life. ,
False
Based on the following Euclid's algorithm what is the greatest common divisor for 76 and 52 long gcd( long m, long n ) { while( n != 0 ) { long rem = m % n m = n n = rem } return m } ,
GCD(76,52) = 4
Lower-order terms can generally be ignored and constants can be thrown away in asymptotic analysis
True
Only the top element can be accessed in the stack data structure
True
What is the maximum subsequence sum for the following sequence? -2, 11, -4, 15, -3, -2 ,
22
Postfix expressions in applications of stacks are used to enhance explicit precedence rules.
?
STL doesn't provide both iterator nested type and const_iterator nested type.
?
3. The compiler will deduce whether an iterator or const_iterator is substituted automatically.
? 4. The block of memory can be allocated via new[] and doesn't need to be freed via delete , False
Recursive approach normally is a very elegant way to design an algorithm and it is also the most efficient approach.
False
T(N) = O(f(N)) if there are any constant c and n0 such that T(N) <= cf(N) when N >= n0
False
T(N) = O(f(N)) if there are constants c and n0 such that T(N) <= cf(N) when N >= n0
False
The efficient way to compute XN where X and N are integers is to use N-1 multiplications which leads to O(N).,
False
Which of the following statement(s) is/are correct about recursion?a)indication of good use of recursion: difficulty to trace down the sequence of recursive calls b)gives cleaner code but has high cost c)never be used as substitute for a simple 'for' loop d)bad idea to use it to evaluate simple mathematical functions.
All of the above
The recursive solution for Maximum Subsequence Sum Problem (MSSP) is the least efficient algorithm among 4 solutions in the lecture.
False
The recursive solution for Maximum Subsequence Sum Problem (MSSP) is the most inefficient algorithm among 4 solutions in the lecture.
False
2. What is the sum of the first 2000 integers ( i.e. 1+2+3+4+...+2000 ) using the formula for the sum of integers.
Check on ur own
What is the summation value for ∑i=0∞i/6^i
Check on ur own
5. Vector doesn't provide a resize routine that will change the size of the Vector.
False
Asymptotic analysis approach allows us to evaluate the speed of an algorithm independent of the hardware/software environment
False
Asymptotic analysis combines a high-level description of algorithm and implementation detail.
False
Built-in array can be copied with = operator.
False
Built-in array can be copied with the assignment operator =.
False
By default all struct members are private,
False
Experimental studies are empirically to be accurate estimation so it is broadly use.
False
If data members contain pointers the big-five defaults can be used in the class. ,
False
In C++ interface file and implementation file are normally defined in a single file. ,
False
In Euclid's algorithm the remainder decreases by a constant factor
False
In general rules of complexity the running time of an if/else statement is more than the running time of the test plus the larger of the running time of S1 and S2 shown in the following fragment. if( condition ) S1 else S2
False
IntCell( IntCell && rhs ) is copy constructor.
False
Is the equation log(A*B) = logA*logB always held if A and B are positive integers?
False
It is a good idea to use recursion to substitute a simple 'for' loop.
False
It is necessary to implement the algorithm for doing algorithm analysis.
False
Pointer variable stores the address where another object resides and system will automatically do garbage collection.
False
Proof by Contradiction assumes that the theorem is false and show that this assumption implies that some know property is true.
False
Range for loop should be used even the block code needs to access index.
False
6. Node in the List is defined as a struct so the default Node is private.
She said false
Which big-Oh rule is not correct if T1(N) = O(f(N)) and T2(N) = O(g(N))? T1(N) + T2(N) = min(O(f(N)), O(g(N))) T1(N) + T2(N) = O(max(f(N), g(N))) T1(N) * T2(N) = O(f(N) + g(N)) T1(N) * T2(N) = O(f(N)*g(N))
T1(N) * T2(N) = O(f(N) + g(N)) T1(N) * T2(N) = O(f(N)*g(N))
If itr is defined as an iterator cout << *itr statement will print out the content of iterator pointing to.
True
In Euclid's algorithm the remainder doesn't decrease by a constant factor.
True
Lower-order terms can generally be ignored and constants can be thrown away for finding big-O solution.
True
3 categories of data types are Simple, Structured, and Pointer.
True
Asymptotic analysis approach allows us to evaluate the speed of an algorithm independent of the hardware/software environment.
True
Average case analysis is normally extremely complex so worst case has been used.
True
Built-in array doesn't remember how many items it can store.
True
Destructor, copy constructor and operator= are special functions provided by C++. ,
True
Divide-and-conquer strategy is to split the problem into two toughly equal subproblems which are solved recursively and patch together the two solutions to obtain the solution of the whole problem.
True
For parameter passing call by constant reference is for the function if the value of the actual parameter isn't changed and does no copying. ,
True
Which one will return the content of the memory location to which p points?) *P b) &P c) P d) &&P e) None of the above
a) *P
Which is the base case for the following recursive function? void printOut( int n ) // Print nonnegative n { if( n >= 10 ) printOut( n / 10 ) printDigit( n % 10 ) }
c) printDigit( n%10 )
2. If lim N -> ∞ f(N)/g(N) = ∞ then: a) f(N) = O(g(N)) b) g(N) = o(f(N)) c) f(N) = Θ(g(N)) d) none of the above
g(N) = o(f(N))
Call by constant reference is appropriate for: a) small objects that should not be altered by the function. b) large objects that should not be altered by the function. c) all objects that may be altered by the function. d) all objects
large objects that should not be altered by the function.