DSA MCQs*

*Some answers may be wrong. This is just for practice purpose only.


Topics : Space and time complexity of an algorithm, Types of asymptotic notations and orders of growth –
Algorithm efficiency – best case, worst case, average case –

Question:

What is the time complexity of the following function?

int fun(int n) {
  int count = 0;
  for (int i = n; i > 0; i /= 2)
     for (int j = 0; j < i; j++)
        count += 1;
  return count;
}
  • A) O(n^2)
  • B) O(nLogn)
  • C) O(n)
  • D) O(nLognLogn)

Question:

What is the time complexity of the following function?

int fun(int n) {
  int count = 0;
  for (int i = 0; i < n; i++)
     for (int j = i; j > 0; j--)
        count = count + 1;
  return count;
}
  • A) Theta(n)
  • B) Theta(n^2)
  • C) Theta(n*Logn)
  • D) Theta(nLognLogn)

Question:

The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs 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

Question:

Let w(n) and A(n) denote the worst-case and average-case running time of an algorithm executed on an input of size n. Which of the following is ALWAYS TRUE?

  • A) A(n) = Ω(W(n))
  • B) A(n) = Θ(W(n))
  • C) A(n) = O(W(n))
  • D) A(n) = o(W(n))

Question:

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

  • A) (15^10) * n + 12099
  • B) n^1.98
  • C) n^3 / (sqrt(n))
  • D) (2^20) * n

Question:

Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3, and f4?

f1(n) = 2^n
f2(n) = n^(3/2)
f3(n) = nLogn
f4(n) = n^(Logn)
  • A) f3, f2, f4, f1
  • B) f3, f2, f1, f4
  • C) f2, f3, f1, f4
  • D) f2, f3, f4, f1

Question:

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm

int n, rev; 
rev = 0; 
while (n > 0) {
   rev = rev * 10 + n % 10; 
   n = n / 10; 
}

The loop invariant condition at the end of the ith iteration is:

  • A) n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1
  • B) n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1
  • C) n != rev
  • D) n = D1D2….Dm and rev = DmDm-1…D2D1

Question:

What is the time complexity of the following function?

void fun(int n, int arr[]) {
    int i = 0, j = 0;
    for(; i < n; ++i)
        while(j < n && arr[i] < arr[j])
            j++;
}
  • A) O(n)
  • B) O(n^2)
  • C) O(nlogn)
  • D) O(n(logn)^2)

Question:

In a competition, four different functions are observed. All the functions use a single for loop, and within the for loop, the same set of statements are executed. Consider the following for loops:

  • A) for(i = 0; i < n; i++)
  • B) for(i = 0; i < n; i += 2)
  • C) for(i = 1; i < n; i *= 2)
  • D) for(i = n; i > -1; i /= 2)

If n is the size of input (positive), which function is most efficient (if the task to be performed is not an issue)?

  • A) A
  • B) B
  • C) C
  • D) D

Question:

The following statement is valid: log(n!) = θ(n log n).

  • A) True
  • B) False

Question:

What does it mean when we say that an algorithm X is asymptotically more efficient than Y?

  • A) X will be a better choice for all inputs
  • B) X will be a better choice for all inputs except small inputs
  • C) X will be a better choice for all inputs except large inputs
  • D) Y will be a better choice for small inputs

Question:

What is the time complexity of Floyd–Warshall algorithm to calculate all pairs’ shortest path in a graph with n vertices?

  • A) O(n^2logn)
  • B) Theta(n^2logn)
  • C) Theta(n^4)
  • D) Theta(n^3)

Question:

Consider the following functions:

f(n) = 2^n
g(n) = n!
h(n) = n^logn 

Which of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true?

  • A) f(n) = O(g(n)); g(n) = O(h(n))
  • B) f(n) = Ω(g(n)); g(n) = O(h(n))
  • C) g(n) = O(f(n)); h(n) = O(f(n))
  • D) h(n) = O(f(n)); g(n) = Ω(f(n))

Question:

In the following C function, let 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))

Question:

Consider the following C-program fragment in which i, j, and n are integer variables.

for (i = n, j = 0; i > 0; i /= 2, j += i);

Let val(j) denote the value stored in the variable j after the termination of the for loop. Which one of the following is true?

  • A) val(j) = θ(logn)
  • B) val(j) = θ(sqrt(n))
  • C) val(j) = θ(n)
  • D) val(j) = θ(nlogn)

Question:

The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is:

  • A) 147.1 to 148.1
  • B) 145.1 to 146.1
  • C) 140 to 146
  • D) 140 to 148

Question:

Consider the following pseudo-code. What is the total number of multiplications to be performed?

D = 2
for (i = 1 to n)
   for (j = i to n)
      for (k = j + 1 to n)
           D = D * 3 
  • A) Half of the product of the 3 consecutive integers.
  • B) One-third of the product of the 3 consecutive integers.
  • C) One-sixth of the product of the 3 consecutive integers.
  • D) None of the above.

Question:

Consider the following C-function:

double foo(int n) {
    int i;
    double sum;
    if (n == 0) return 1.0;
    else {
        sum = 0.0;
        for (i = 0; i < n; i++)
            sum += foo(i);
        return sum;
    }
}

The space complexity of the above function is:

  • A) O(1)
  • B) O(n)
  • C) O(n!)
  • D) O(nn)

Question:

Consider the following C-function:

double foo(int n) {
    int i;
    double sum;
    if (n == 0) return 1.0;
    else {
        sum = 0.0;
        for (i = 0; i < n; i++)
            sum += foo(i);
        return sum;
    }
}

Suppose we modify the above function foo() and store the values of foo(i), 0 <= i < n, as and when they are computed. With this modification, the time complexity for function foo() is significantly reduced. The space complexity of the modified function would be:

  • A) O(1)
  • B) O(n)
  • C) O(n!)
  • D) O(n^2)

Topics: Asymptotic analysis for recurrence relation: Iteration Method,Substitution Method, Master Method and Recursive Tree Method.

Question:
Which of the following methods is most suitable for solving simple divide-and-conquer recurrences?
A) Iteration Method
B) Substitution Method
C) Master Method
D) Recursive Tree Method
Answer: C) Master Method

Question:
The recurrence ( T(n) = 2T(n/2) + n ) can be solved using the Master Theorem. What is the time complexity of this recurrence?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: B) O(n log n)

Question:
Which method involves guessing the solution and then proving it by mathematical induction?
A) Iteration Method
B) Substitution Method
C) Master Method
D) Recursive Tree Method
Answer: B) Substitution Method

Question:
For the recurrence ( T(n) = 3T(n/4) + n ), which case of the Master Theorem applies?
A) Case 1
B) Case 2
C) Case 3
D) None of the above
Answer: C) Case 3

Question:
In the Iteration Method, after expanding the recurrence, what is the next step to find the time complexity?
A) Solve the base case
B) Use the Master Theorem
C) Express the expanded terms as a summation
D) Substitute the guessed solution
Answer: C) Express the expanded terms as a summation

Question:
Which of the following recurrence relations can be solved using the Iteration Method?
A) ( T(n) = 2T(n/2) + n )
B) ( T(n) = T(n-1) + 1 )
C) ( T(n) = 3T(n/4) + n )
D) All of the above
Answer: D) All of the above

Question:
The Recursive Tree Method is particularly useful for:
A) Estimating the growth of a recursive algorithm
B) Finding an exact solution to a recurrence
C) Solving linear recurrences
D) Proving the correctness of an algorithm
Answer: A) Estimating the growth of a recursive algorithm

Question:
Which of the following is NOT a valid approach for solving recurrences?
A) Guess-and-check Method
B) Substitution Method
C) Iteration Method
D) Substitution Master Method
Answer: D) Substitution Master Method

Question:
The recurrence ( T(n) = T(n/2) + T(n/4) + n ) is best solved using:
A) Iteration Method
B) Substitution Method
C) Master Method
D) Recursive Tree Method
Answer: D) Recursive Tree Method

Question:
When solving a recurrence relation using the Substitution Method, what is the most important step?
A) Expanding the recurrence
B) Making a good guess
C) Summing the series
D) Applying the Master Theorem
Answer: B) Making a good guess

Question:
What is the correct asymptotic complexity for the recurrence ( T(n) = 4T(n/2) + n )?
A) O(n^2)
B) O(n log n)
C) O(n^3)
D) O(log n)
Answer: A) O(n^2)

Question:
The recurrence ( T(n) = T(n/2) + n^2 ) falls under which case of the Master Theorem?
A) Case 1
B) Case 2
C) Case 3
D) Case 4
Answer: C) Case 3

Question:
In the Iteration Method, if a recurrence has ( T(n) = 2T(n/2) + 1 ), what is the total number of levels in the expansion tree?
A) log n
B) n
C) n/2
D) 2n
Answer: A) log n

Question:
Which of the following recurrences is most likely to result in a logarithmic time complexity?
A) ( T(n) = 2T(n/2) + n )
B) ( T(n) = T(n/2) + 1 )
C) ( T(n) = 3T(n/4) + n^2 )
D) ( T(n) = 2T(n/2) + n^2 )
Answer: B) ( T(n) = T(n/2) + 1 )

Question:
The Master Method is applicable when the recurrence has the form:
A) ( T(n) = aT(n/b) + f(n) )
B) ( T(n) = T(n-1) + T(n-2) )
C) ( T(n) = T(n/2) + n )
D) ( T(n) = T(n-1) + 1 )
Answer: A) ( T(n) = aT(n/b) + f(n) )

Question:
For the recurrence ( T(n) = 2T(n/2) + n ), using the Master Theorem, what is the value of the critical exponent ( \log_b a )?
A) 1
B) 2
C) 0.5
D) log n
Answer: A) 1

Question:
The Substitution Method typically involves which of the following steps?
A) Expanding the recurrence into a tree
B) Expressing the solution as a summation
C) Guessing the form of the solution and using induction to verify
D) Applying the Master Theorem
Answer: C) Guessing the form of the solution and using induction to verify

Question:
The Recursive Tree Method visualizes the recurrence by representing it as:
A) A series of nested recurrences
B) A tree where nodes represent subproblems
C) A sequence of iterations
D) A single linear equation
Answer: B) A tree where nodes represent subproblems

Question:
The recurrence ( T(n) = 2T(n/2) + n ) is classified under which case of the Master Theorem?
A) Case 1
B) Case 2
C) Case 3
D) Case 4
Answer: B) Case 2

Question:
For the recurrence ( T(n) = T(n-1) + n ), the Iteration Method would typically involve:
A) Expanding each term iteratively until the base case
B) Using the Master Theorem to find the solution
C) Guessing the solution and using induction
D) Drawing a recursive tree
Answer: A) Expanding each term iteratively until the base case

Topics : Arrays: 1D and 2D array- Stack – Applications of stack: Expression Evaluation, Conversion, of Infix to postfix and prefix expression, Tower of Hanoi

Question:
Which of the following operations is not possible on a static array once it is declared?
A) Accessing an element using its index
B) Inserting an element at a specific position
C) Deleting an element from a specific position
D) Resizing the array
Answer: D) Resizing the array

Question:
If an array A is defined as int A[10] = {0};, what will be the value of A[5]?
A) 0
B) 5
C) Undefined
D) Compilation error
Answer: A) 0

Question:
What is the time complexity of searching for an element in a sorted 1D array using binary search?
A) O(n)
B) O(n^2)
C) O(log n)
D) O(1)
Answer: C) O(log n)

Question:
Which of the following is true about a stack?
A) It follows FIFO (First-In-First-Out) order
B) It allows insertion and deletion from both ends
C) It follows LIFO (Last-In-First-Out) order
D) It allows random access to elements
Answer: C) It follows LIFO (Last-In-First-Out) order

Question:
In which of the following scenarios would you prefer to use a stack over other data structures?
A) Implementing a queue
B) Performing level-order traversal of a tree
C) Evaluating arithmetic expressions
D) Storing records in a database
Answer: C) Evaluating arithmetic expressions

Question:
Which of the following is the correct postfix expression for the infix expression A + B * C?
A) ABC*+
B) AB+C*
C) A*BC+
D) AB*C+
Answer: A) ABC*+

Question:
Given a stack with an initial state of empty, what will be the stack after the following operations: push(1), push(2), pop(), push(3)?
A) 3, 2, 1
B) 1, 2, 3
C) 1, 3
D) 3, 1
Answer: C) 1, 3

Question:
Which of the following is NOT an application of a stack?
A) Parsing expressions
B) Function call management in recursion
C) Breadth-first search in a graph
D) Balancing parentheses in an expression
Answer: C) Breadth-first search in a graph

Question:
In the Tower of Hanoi problem with 3 disks, what is the minimum number of moves required to solve the problem?
A) 3
B) 5
C) 7
D) 9
Answer: C) 7

Question:
What is the time complexity for the conversion of an infix expression to a postfix expression using a stack?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(1)
Answer: A) O(n)

Question:
Consider an array arr of size n. What is the best-case time complexity for finding the maximum element in this array?
A) O(n^2)
B) O(n log n)
C) O(n)
D) O(1)
Answer: C) O(n)

Question:
What is the postfix form of the infix expression (A + B) * (C + D)?
A) AB+CD+*
B) ABCD+*+
C) A+B*C+D+
D) AB+*CD+
Answer: A) AB+CD+*

Question:
In an array of size n, if elements are inserted one after another, what is the worst-case time complexity for inserting an element at the beginning of the array?
A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)
Answer: C) O(n)

Question:
How many stacks are required to evaluate a postfix expression?
A) One
B) Two
C) Three
D) None
Answer: A) One

Question:
What will be the content of the stack after converting the infix expression A * (B + C) / D to postfix?
A) AB+C*D/
B) ABC+*D/
C) AB+C*D/
D) ABC*D+/
Answer: B) ABC+*D/

Question:
In a stack, which operation removes the top element of the stack?
A) Push
B) Pop
C) Peek
D) Insert
Answer: B) Pop

Question:
What is the time complexity of finding the middle element in a stack implemented using a linked list?
A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)
Answer: C) O(n)

Question:
In a 2D array, how do you calculate the address of an element at row i and column j given that the array is stored in row-major order?
A) Base address + (i * number of columns + j) * size of element
B) Base address + (j * number of rows + i) * size of element
C) Base address + (i + j) * size of element
D) Base address + (i * j) * size of element
Answer: A) Base address + (i * number of columns + j) * size of element

Question:
For the infix expression A + B * (C - D), what is the equivalent prefix expression?
A) +A*B-CD
B) *AB-CD+
C) *+AB-CD
D) +A*B-CD
Answer: D) +A*B-CD

Question:
What is the maximum number of elements that can be present in a stack of size n?
A) n+1
B) n
C) n-1
D) n^2
Answer: B) n

Question:
In the Tower of Hanoi problem with n disks, how does the time complexity of the solution change with respect to n?
A) O(2^n)
B) O(n^2)
C) O(n log n)
D) O(n)
Answer: A) O(2^n)

Question:
What is the minimum number of moves required to solve the Tower of Hanoi problem for n disks?
A) 2n – 1
B) 2^n – 1
C) 2n^2 – 1
D) 2^n + 1
Answer: B) 2^n – 1

Question:
In which of the following scenarios is a circular queue more advantageous than a regular queue?
A) When the queue is full
B) When implementing a stack
C) When dealing with fixed-size arrays
D) When reusing space that is freed after dequeuing
Answer: D) When reusing space that is freed after dequeuing

Question:
What will be the stack content after evaluating the postfix expression 3 4 + 2 * 7 /?
A) 14
B) 2
C) 7
D) 4
Answer: B) 2

Question:
Which of the following expressions correctly converts the infix expression A / B + C * D - E to postfix?
A) AB/CD*+E-
B) AB/CD*E+-
C) AB/C*DE+-
D) AB/C+D*E-
Answer: D) AB/C+D*E-

Question:
Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below:

OperatorPrecedenceAssociativity
+HighestLeft
−HighRight
*MediumRight
/LowRight

Given these rules, what is the value of the expression 3 + 5 * 2 - 4 / 2?

Answer:
The value of the expression is 12.

Explanation:
According to the precedence and associativity:

  1. Multiplication (*) is performed first: 5 * 2 = 10.
  2. Division (/) is next: 4 / 2 = 2.
  3. Addition (+) and subtraction (−) are then evaluated from left to right:
  • 3 + 10 = 13
  • 13 - 2 = 11

Final Result: 11


Question:
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is correct (n refers to the number of items in the queue)?

Answer:
In an array-based queue, both ENQUEUE and DEQUEUE operations can be performed in O(1) time, provided the array is used in a circular manner.

Explanation:
If the queue is implemented in a circular fashion using an array, ENQUEUE (adding an element to the end) and DEQUEUE (removing an element from the front) can be efficiently handled without shifting elements, thus operating in constant time.


Question:
The result of evaluating the postfix expression 6 2 3 * - 4 2 / + is:

Answer:
The result is 4.

Explanation:
To evaluate the postfix expression:

  1. Multiply 2 and 3: 6.
  2. Subtract this result from 6: 6 - 6 = 0.
  3. Divide 4 by 2: 2.
  4. Add the results from steps 2 and 3: 0 + 2 = 2.

Final Result: 2


Question:
A function f defined on stacks of integers satisfies the following properties: f(∅) = 0 and f(push(S, i)) = max(f(S), 0) + i for all stacks S and integers i. If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?

Answer:
The value of f(S) is 5.

Explanation:
Evaluating f(S) step by step:

  1. Start with an empty stack: f(∅) = 0.
  2. Push 2: f(push(∅, 2)) = max(0, 0) + 2 = 2.
  3. Push -3: f(push(S, -3)) = max(2, 0) - 3 = 2 - 3 = -1.
  4. Push 2: f(push(S, 2)) = max(-1, 0) + 2 = 0 + 2 = 2.
  5. Push -1: f(push(S, -1)) = max(2, 0) - 1 = 2 - 1 = 1.
  6. Push 2: f(push(S, 2)) = max(1, 0) + 2 = 1 + 2 = 3.

Final Result: 3

Question:
Which of the following is the correct way to access the third element of a one-dimensional array arr?

Answer:
arr[2]


Question:
In a 2D array matrix[4][5], how do you access the element in the first row and fourth column?

Answer:
matrix[0][3]


Question:
What data structure is typically used to evaluate postfix expressions?

Answer:
Stack


Question:
What is the postfix notation for the infix expression A - B + C?

Answer:
A B - C +


Question:
Which of the following correctly represents the infix expression (A + B) * (C - D) in prefix notation?

Answer:
* + A B - C D


Question:
What is the correct postfix notation for the expression (A + B) * (C - D) / E?

Answer:
A B + C D - * E /


Question:
In the Tower of Hanoi problem, how many moves are needed to solve the puzzle for 3 disks?

Answer:
7


Question:
Given the postfix expression 5 1 2 + 4 * + 3 -, what is the result of the expression?

Answer:
14


Question:
Which operation in a stack removes the top element?

Answer:
POP


Question:
In the context of stack operations, what does the PUSH operation do?

Answer:
Adds an element to the top of the stack


Question:
What is the result of the infix expression A + B * C when converted to postfix notation?

Answer:
A B C * +


Question:
Which operation is used to add an element to the stack?

Answer:
PUSH


Question:
When converting the infix expression A + (B - C) * D to prefix notation, what is the result?

Answer:
+ A * - B C D


Question:
How do you represent the infix expression A / (B + C) in postfix notation?

Answer:
A B C + /


Question:
What is the correct prefix notation for the expression A * (B + C) - D?

Answer:
- * A + B C D


Question:
What is the result of the postfix expression 8 2 / 4 5 * +?

Answer:
14


Question:
In a stack, which operation retrieves the top element without removing it?

Answer:
PEEK


Question:
What is the minimum number of moves required to solve the Tower of Hanoi problem with 4 disks?

Answer:
15


Question:
In the conversion of an infix expression to postfix notation, when should operators be popped from the stack?

Answer:
When encountering an operator with lower or equal precedence than the one on the stack


Question:
Which of the following is the result of converting the infix expression A - B / C * D to postfix notation?

Answer:
A B C D * / -


Question:
In prefix notation, what is the equivalent of the infix expression A - (B / C * D)?

Answer:
- A / B * C D


Question:
In a 2D array, how is the element in the second row and fifth column accessed?

Answer:
array[1][4]

Topics : Searching and Sorting


Which of the following is true about linear search?

a) It requires the list to be sorted.

b) It has a time complexity of O(log n).

c) It can be used on both sorted and unsorted lists.

d) It performs better than binary search for large datasets.

Answer: c) It can be used on both sorted and unsorted lists.


Consider a sorted array of 1000 elements. What is the worst-case time complexity of binary search?

a) O(1)

b) O(n)

c) O(log n)

d) O(n log n)

Answer: c) O(log n)


Given a list of 100 elements, what is the maximum number of comparisons required by a binary search?

a) 7

b) 10

c) 20

d) 100

Answer: b) 10


In the context of linear search, if an element is present in the middle of a list of size n, how many comparisons are required on average?

a) n/2

b) n

c) log(n)

d) (n+1)/2

Answer: d) (n+1)/2


Which of the following searching algorithms would be the most efficient for an unsorted list of size 1,000,000?

a) Linear search

b) Binary search

c) Hashing

d) Interpolation search

Answer: c) Hashing


Which of the following sorting algorithms has the worst-case time complexity of O(n^2) and is stable?

a) Insertion sort

b) Selection sort

c) Bubble sort

d) Merge sort

Answer: a) Insertion sort


In which sorting algorithm does the worst-case performance occur when the list is already sorted or nearly sorted?

a) Selection sort

b) Insertion sort

c) Bubble sort

d) Quick sort

Answer: b) Insertion sort


What is the average-case time complexity of Bubble Sort?

a) O(n)

b) O(n log n)

c) O(n^2)

d) O(log n)

Answer: c) O(n^2)


Which sorting algorithm repeatedly selects the minimum element from the unsorted part and moves it to the end of the sorted part?

a) Bubble sort

b) Selection sort

c) Insertion sort

d) Merge sort

Answer: b) Selection sort


Which of the following sorting algorithms performs the minimum number of swaps in the worst case?

a) Bubble sort

b) Selection sort

c) Insertion sort

d) Quick sort

Answer: b) Selection sort



For which of the following scenarios is binary search most efficient?

a) Searching in a linked list.

b) Searching in a small, unsorted array.

c) Searching in a large, sorted array.

d) Searching in a large, unsorted array.

Answer: c) Searching in a large, sorted array.


In a binary search tree (BST), which of the following traversal methods would yield the elements in ascending order?

a) Pre-order traversal

b) In-order traversal

c) Post-order traversal

d) Level-order traversal

Answer: b) In-order traversal


What is the best-case time complexity of bubble sort when the input list is already sorted?

a) O(n)

b) O(n log n)

c) O(n^2)

d) O(log n)

Answer: a) O(n)


In a worst-case scenario, how many comparisons are needed to sort a list of n elements using insertion sort?

a) n

b) n log n

c) n^2

d) n^2/2

Answer: c) n^2


For a list of size n, what is the maximum number of swaps performed by selection sort?

a) n

b) n-1

c) n^2

d) (n-1)^2

Answer: b) n-1


Which sorting algorithm uses a divide-and-conquer strategy and is known for its O(n log n) average and worst-case time complexity?

a) Merge sort

b) Bubble sort

c) Insertion sort

d) Selection sort

Answer: a) Merge sort


What is the space complexity of the in-place version of the quick sort algorithm?

a) O(n)

b) O(log n)

c) O(n log n)

d) O(1)

Answer: b) O(log n)


If a list is sorted using quick sort with a poorly chosen pivot each time, what is the worst-case time complexity?

a) O(n log n)

b) O(n)

c) O(n^2)

d) O(n^3)

Answer: c) O(n^2)


In a list sorted by insertion sort, how many elements need to be compared in the worst case when inserting a new element?

a) 1

b) n/2

c) n

d) log(n)

Answer: c) n


Which of the following is NOT a stable sorting algorithm?

a) Merge sort

b) Bubble sort

c) Insertion sort

d) Selection sort

Answer: d) Selection sort


Scroll to Top