Algorithms MCQ – Data Structures & Complexity – Part 1
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 timing factor to determine the efficiency of the algorithm is measured by _____?
A Counting microseconds
B Count the number of operations
C Counting the number of declarations
D Counting the kilobytes of the algorithm.
2. What is the time complexity of the following code?
int count(int n) { int c = 0; for (int i = 0; i < n; i++) for (int j = i; j > 0; j--) c = c + 1; return c; }
A O(n)
B O(n^2)
C O(n*Logn)
D O(n*Logn*Logn)
3. Which of the following data structures is not a linear data structure?
A Array
B Linked list
C Both A and B are true.
D None of the above
4. What is the time complexity of the following code?
int count(int n) { int c = 0; for(int i = n; i > 0; i/= 2) for(int j = 0; j < i; j++) c += 1; return c; }
A O(n^2)
B O(n*Logn)
C O(n)
D O(n*Logn*Logn)
5. The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n disks is _______?
A T (n) = 2T (n – 2) + 2
B T (n) = 2T (n – 1) + n
C T (n) = 2T (n / 2) + 1
D T (n) = 2T (n – 1) + 1
6. The complexity of the Linear Search algorithm is _____?
A O(n)
B O(log n)
C O(n2)
D O(n * log n)
7. The average complexity occurs in the Linear Search algorithm. When the searched element _______?
A Is in the middle of the array
B Not found in the array
C Is the last element of the array
D Is the last element of the array or not at all
8. What is the worst-case recurrence of the quick sort algorithm and what is the worst-case time complexity?
A The recurrence is T (n) = T (n-2) + O (n) and the time complexity is O (n ^ 2)
B The recurrence is T (n) = T (n-1) + O (n) and the time complexity is O (n ^ 2)
C The recurrence is T (n) = 2T (n / 2) + O (n) and the time complexity is O (n*Logn)
D The recurrence is T (n) = T (n / 10) + T (9n / 10) + O (n) and the time complexity is O (n*Logn)
9. Which of the following data structures is a linear data structure?
A Tree
B Graphs
C Arrays
D None of the above
10. Suppose we have an O(n) time algorithm that finds the median of an unsorted array. Now consider an implementation of the quick sort algorithm where we first find the median using the quick sort algorithm, and then use the median as a pivot. What will be the worst case time complexity of this modified algorithm?
A O(n^2 Logn)
B O(n^2)
C O(n*Logn*Logn)
D O(n*Logn)