QUIZ 1
1) Two main measures for the efficiency of an algorithm are
A. Processor and memory
B. Complexity and capacity
C. Time and space
D. Data and space
2) The time factor when determining the efficiency of algorithm is measured by
A. Counting microseconds
B. Counting the number of key operations
C. Counting the number of statements
D. Counting the kilobytes of algorithm
3) Which of the following case does not exist in complexity theory
A. Best case
B. Worst case
C. Average case
D. Null case
4) Which of these is the correct big-O expression for 1+2+3+...+n?
A. O(log n)
B. O(n)
C. O(n log n)
D. O(n²)
5) Which of the following formulas in big-O notation best represent the
expression n²+35n+6?
A. O(n³)
B. O(n²)
C. O(n)
D. O(42)
6) What term is used to describe an O(n) algorithm.
A. Constant
B. Linear
C. Logarithmic
D. Quadratic
7) Answer true or false for this statement: For all possible inputs, a linear
algorithm to solve a problem must perform faster than a quadratic algorithm
to solve the same problem.
A. TRUE B. FALSE.
1
8) Here is some code for an integer variable n:
while (n > 0)
{
n = n/10; // Use integer division
}
What is the worst-case time analysis for the above loop?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
9) Express the formula (n - 2)*(n - 4) using big-O notation:
A. O(1)
B. O(8)
C. O(log n)
D. O(n)
E. None of the above
10) Big-O of the following algorithm
i=1;
while(i<=n)
i=i*3;
A. O(n) B. O(i)
C. O(log 3 n) D. O(log 2 n)
11) Big-O of the following algorithm
i=s=0;
while(s<n)
{ i++;
s+=i;
}
A. O(n) B. O(log 2 n)
C. O(i) D. O( )
12) For the following C++ code fragment, find T(n), the exact number of exchange
operation (operations to count are shown in bold font) in terms of n in worst-case
FOR i:= n-1 DOWNTO 1 DO
FOR j:=1 TO i DO
IF A[j]>A[j+1]
THEN exchange value of A[j] and A[j+1];