MCQ

Algorithms MCQ – Data Structures & Complexity – Part 4

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. Which of the following sorting algorithms has the lowest worst-case complexity?

A Merge sort

B Bubble sort

C Quick sort

D Selection sort
 

 
A
The worst cases for the above sorting algorithms are:

  • Merge sort : n Logn
  • Bubble sort of nLogn : n ^ 2
  • Quick sort : n ^ 2
  • Selection sort : n ^ 2

 

 

2. The elements of an array are successively stored in memory spaces because _____?

A In this way, the computer can only keep track of the address of the first element and the addresses of the other elements can be calculated

B the architecture of the computer memory does not allow arrays to store other than serial

C Both A and B are true

D None of the above

A

 

 

3. Consider the following function
 int fun(int n) {
    int i, j, k = 0;
    for (i  = n/2; i <= n; i++)
        for (j = 2; j <= n; j = j * 2)
            k = k + n/2;
    return k;
 }

What is the value returned by the above function?

A Θ(n^2)

B Θ(n^2Logn)

C Θ(n^3)

D Θ(n^3Logn)

B
  • The outer loop runs n / 2 or Θ(n) times.
  • The inner loop executes Θ(Logn) times (note that j is multiplied by 2 at each iteration).
  • Thus, the statement “k = k + n / 2;” executes Θ(nLogn) times.
  • The statement increments the value of k by n / 2. So the value of k becomes n / 2 * Θ(nLogn) which is Θ(n ^ 2Logn)

 

 

4. The complexity of the binary search algorithm is ______?

A O(n)

B O(log)

C O(n2)

D O(n log n)

B

 

 
 

5. Consider the following three instructions
  1. (n + m) ^ k = Θ(n ^ m), where k and m are constants
  2. 2 ^ (n + 1) = O(2 ^ n)
  3. 2 ^ (2n + 1 ) = O(2 ^ n)

Which of the following statements are correct?

A 1 and 2

B 1 and 3

C 2 and 3

D 1, 2, and 3

A
(1) (n + m) ^ k = n ^ k + c1 * n ^ (k – 1) + … k ^ m = Θ(n ^ k)
(2) 2 ^ (n + 1) = 2 * 2 ^ n = O( 2 ^ n)

 

 

6. The result of iterating through a binary search tree is _____?

A An unsorted list

B A reverse of the input

C A sorted list

D None of the above

C
The binary search tree gives a sorted list when traversed in order.

 

 

7. In the following gcd() function, we have : n >= m.
int gcd(n,m)
{
  if (n%m ==0) return m;  
  n = n%m;
  return gcd(m, n);
}

How many recursive calls are made by this function?

A Θ(logn)

B Ω(n)

C Θ(loglogn)

D Θ(sqrt(n))

A
The above code is the implementation of the Euclidean algorithm for finding the greatest common divisor (GCD).

 

 

8. The queue is a data structure that operates on ______?

A LIFO

B FIFO

C FILO

D None of the above

B
In the queue, the element inserted first will be available first and the element inserted last will be available last. FIFO stands for First In First Out.

 

 
 

9. Une liste chaînée est une structure dynamique?

A True

B False

A
A linked list is a dynamic structure, it can be reduced and increased at the request of the program.

 

 

10. Recursion uses more memory space than iterations because _____?

A It uses the stack instead of the queue.

B Each recursive call must be stored.

C Both A and B are true.

D Aucune de ces réponses n’est vraie.

B
Recursion uses the stack, but the main reason is that each recursive call must be stored separately in memory.

 

 
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 *