MCQ

Algorithms MCQ – Data Structures & Complexity – Part 2

Computer architecture MCQ questions and answers for the preparation of tests, exams, and certifications. So you will find questions about loops and conditionals, data structure, complexity, flowchart, pseudocode, and much more. This systematic learning method will easily prepare anyone to pass their exam.
 

1. The average case complexity of an algorithm is _______?

A Much more complicated to analyze than the worst case

B Much easier to analyze than the worst case

C Sometimes more complicated and sometimes simpler than the worst case

D None of the above

A

 

 
[st_adsense]  

2. Which of the following statements is not true about comparison-based sorting algorithms?

A The minimum possible time complexity of a comparison-based sorting algorithm is O (n*Logn) for a random input array.

B Any comparison-based sorting algorithm can be made stable by using position as a parameter when two elements are compared

C The Counting sort is not a sorting algorithm based on comparison

D Heap Sort is not a comparison-based sorting algorithm.

D
Heap sort is a comparison-based sorting technique that relies on the binary heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for the rest.

 

 

3. 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

C

 

 
4. Consider w(n) and V(n), respectively, as the worst-case and average execution time of an algorithm run on an input of size n. Which of the following statements is ALWAYS TRUE?
 
A V(n) = Θ(w(n))

B V(n) = Ω(w(n))

C V(n) = O(w(n))

D V(n) = o(w(n))

C
The worst-case time complexity is always greater than or equal to the average time complexity.

 

 
[st_adsense]  

5. Which of the following is not O (n ^ 2)?

A n ^ 3 / (sqrt (n))

B n ^ 1,78

C (13 ^ 10) * n + 12087

D (2 ^ 40) * n

A
The growth order of the A option is n ^ 2.5, which is greater than n ^ 2.

 

 

6. Linked lists are best suited for ____?

A gathering of permanent data

B Size and constantly changing data

C All the answers are true

D None of the above

B

 

 

7. Which of the options provides the increasing order of the asymptotic complexity of g1, g2, g3 and g4 functions?
   g1 (n) = 2 ^ n
   g2(n) = n ^ (3/2)
   g3(n) = n * Logn
   g4(n) = n ^ (logn)

A g3, g2, g4, g1

B g3, g2, g1, g4

C g2, g3, g1, g4

D g2, g3, g4, g1

B
Except for g3(n), all the others are exponential. So g3 is definitely the first one out.

 

 

8. Space factor is measured by ____?

A The maximum memory size required by the algorithm

B The minimum memory size required by the algorithm

C The average memory size required by the algorithm

D The maximum disk space size required by the algorithm

A

 

 
[st_adsense]  

9. Consider the following program to reverse the digits of an integer. Where n = P1 * P2 … Pm
int n, res;
res = 0;
while (n > 0) 
{ 
   res = res*10 + n%10; 
   n = n/10; 
}

The loop condition at the end of the iteration is as follows:

A n = P1*P2 … Pm-i and res = Pm*Pm-1 … Pm-i + 1

B n = Pm-i + 1… Pm-1 * Pm and res = Pm-1 … P2*P1

C n = P2*P1 … Pm and res = Pm * Pm-1 … P2*P1

D n! = res

A
We can get it by taking an example of n = 98765. After 2 iterations, res = 56 and n = 987.

 

 

10. What is the best time complexity of the bubble sort algorithm?

A N ^ 2

B N * logN

C N

D N (log * N) ^ 2

C
Bubble sort is optimal if the input data is sorted. Which means, if the input data is sorted in the same order as the expected output. This can be achieved by using a Boolean variable. The Boolean variable is used to check whether the values are exchanged at least once in the inner loop. See the following code snippet:

int main () {

    int arr[] = {9, 1, 5, 8, 3};
    int i;
    int j;
    int isSwapped;
    int n = sizeof(arr) / sizeof(*arr);

    isSwapped = 1;

    for (i = 0; i < n - 1 && isSwapped; ++ i) {
        isSwapped = 0; 
        for(j = 0; j < n - i - 1; ++ j)
            if (arr[j] > arr[j + 1]) {
                swap (&arr[j], &arr[j + 1]);
                isSwapped = 1;
            }
    } 
    for (i = 0; i < n; ++ i) 
        printf ("%d", arr[i]); 

    return 0; 
}

Please note that in the above code, the outer “for” loop is executed only once.

 

 
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *