Divide and Conquer & Recurrences: past questions

39 questions · 121 marks · 10 papers. Try each one before checking.

Solve them and check answers →Read the notes first

03 Aug 2025

Question 10 MCQ · 3 marks

Select the correct match of recurrence relation with corresponding complexity. Assume that for all recurrence relations, the base case is $T(1)=1$.

  1. A-3, B-1, C-2, D-4

  2. A-4, B-1, C-3, D-2

  3. A-4, B-1, C-2, D-3

  4. A-1, B-3, C-2, D-4

Question 17 SA · 3 marks

In a list $L$, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. The total number of inversions in $L=[1,5,4,8,6,2,7,3]$ is ___.

Type your answer on the interactive page.

Question 11 MCQ · 3 marks

Consider the following code to find median. What median value will be returned by the given MoM function for the following list?

L = [7, 13, 5, 18, 9, 33, 15, 9, 14, 60, 1, 17, 14, 15, 41, 6, 11, 8, 6, 15, 19, 17, 2, 31]

def MoM(L):
    if len(L) <= 5:
        L.sort()
        return L[2]
    M = []
    for i in range(0, len(L), 5):
        X = L[i:i+5]
        X.sort()
        M.append(X[2])
    return MoM(M)
  1. 15

  2. 9

  3. 14

  4. 17

Question 14 MSQ · 3 marks

Which of the following statements are true about the finding the closest pair of points using divide and conquer strategy?

  1. The algorithm uses the Euclidean distance formula to determine the separation between any two given points.

  2. A fundamental part of the strategy involves recursively finding the closest pair of points within two distinct, smaller subsets of the original point set.

  3. The optimal worst-case time complexity achieved by this divide and conquer approach is $O(n\log n)$.

  4. The combine step requires comparing every point in the left half with every point in the right half to find cross-border closest pairs.

July 2022

Question 6 MCQ · 3 marks

Select the correct match of recurrence relation with corresponding complexity.

  1. A-2, B-4, C-3, D-1

  2. A-2, B-3, C-4, D-1

  3. A-2, B-3, C-1, D-4

  4. A-3, B-2, C-4, D-1

Question 14 SA · 4 marks

In a list $L$, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. The total number of inversions in $L=[2,7,6,1,5]$ is ___.

Type your answer on the interactive page.

Question 16 MCQ · 3 marks

Consider the following function that takes a list of distinct integers and an integer $k$ ($1\le k\le \text{len}(L)$) as input. lower and upper represent the lower and upper index of L. In line 3, the partition function treats the first element of $L$ as a pivot and rearranges the list so that all elements less than or equal to the pivot are in the left part of the list, and all elements greater than the pivot are in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The function returns the index of pivot in the list $L$.

What does function mystery return?

def mystery(L, lower, upper, k):
    if (k > 0 and k <= upper - lower + 1):
        pos = partition(L, lower, upper)
        if (pos - lower == k - 1):
            return L[pos]
        if (pos - lower > k - 1):
            return mystery(L, lower, pos - 1, k)
        else:
            return mystery(L, pos + 1, upper, k - pos + lower - 1)
  1. The smallest value in $L$ that is greater than $k$.

  2. The largest value in $L$ that is less than or equal to $k$.

  3. The $k$th largest element in $L$.

  4. The $k^{th}$ smallest element in $L$.

Question 17 MCQ · 3 marks

Consider the following function that takes a list of distinct integers and an integer $k$ ($1\le k\le \text{len}(L)$) as input. lower and upper represent the lower and upper index of L. In line 3, the partition function treats the first element of $L$ as a pivot and rearranges the list so that all elements less than or equal to the pivot are in the left part of the list, and all elements greater than the pivot are in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The function returns the index of pivot in the list $L$.

Let $T(n)$ denote the worst-case running time for the given function mystery, where $n$ is the length of $L$. The asymptotic expression for $T(n)$ is ___. Consider that the running time for partition function is $O(n)$.

def mystery(L, lower, upper, k):
    if (k > 0 and k <= upper - lower + 1):
        pos = partition(L, lower, upper)
        if (pos - lower == k - 1):
            return L[pos]
        if (pos - lower > k - 1):
            return mystery(L, lower, pos - 1, k)
        else:
            return mystery(L, pos + 1, upper, k - pos + lower - 1)
  1. $O(\log n)$

  2. $O(n)$

  3. $O(n\log n)$

  4. $O(n^2)$

01 Dec 2024

Question 7 MCQ · 3 marks

Select the correct match of recurrence relation with corresponding complexity.

  1. A-2, B-4, C-3, D-1

  2. A-2, B-3, C-4, D-1

  3. A-2, B-3, C-1, D-4

  4. A-3, B-2, C-4, D-1

Question 13 SA · 3 marks

In an array $A$, two elements $A[i]$ and $A[j]$ form an inversion pair, if $A[i]>A[j]$ for $i<j$. The maximum number of inversion pairs possible in an integer array $A$ of size 17 is ___

Type your answer on the interactive page.

Question 9 MCQ · 3 marks

Consider the following statements

  1. The worst case running time of Quick select algorithm to find the $k$th largest number is $O(n\log n)$
  1. Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n)$.

Which of the following option is correct?

  1. Only statement 1 is correct.

  2. Only statement 2 is correct.

  3. Both statements are correct.

  4. Both statements are incorrect.

Question 8 MCQ · 3 marks

Apply the divide and conquer strategy to find the closest pair of points in a set. After dividing the set into two halves and recursively finding the closest pairs in each half, what additional step is required?

  1. Combine the results directly

  2. Perform a linear search for the closest pair

  3. Consider pairs that span both halves

  4. Sort the points by their distances

06 Apr 2026

Question 10 MCQ · 3 marks

Consider the following strategy to solve a problem of input size $n$. Divide the problem into 6 sub-problems, each of size $\frac{n}{6}$, where the time required to perform this division is proportional to the input size (i.e., $O(n)$). The number of steps required to combine these 6 solutions is $2n+12$. We apply this strategy recursively till the sub-problems can not be further divided into sub-problems. What will be the nearest upper bound for the above algorithm?

  1. $O(n\log n)$

  2. $O(n^2\log n)$

  3. $O(n^2)$

  4. $O(n^6)$

Question 8 MCQ · 3 marks

In a list $L$, two elements $L[i]$ and $L[j]$ form a significant inversion if $L[i]>2\times L[j]$ and $i<j$. The total number of significant inversions for $L=[3,14,1,7,2,6]$ is ___.

  1. 3

  2. 4

  3. 5

  4. 6

Question 16 SA · 3 marks

Consider the following function MoM. What median value will be returned by the given MoM function for the following list?

[12, 7, 5, 20, 3, 18, 15, 1, 9, 14, 22, 6, 11, 8, 17, 4, 10, 2, 13, 16, 25, 19, 21, 23, 24]

def MoM(L): # Median of medians
    if len(L) <= 5:
        L.sort()
        return (L[len(L)//2])
    # Construct list of block medians
    M = []
    for i in range(0, len(L), 5):
        X = L[i:i+5]
        X.sort()
        M.append(X[len(X)//2])
    return (MoM(M))

Type your answer on the interactive page.

Question 9 MCQ · 3 marks

Consider the Quick Select algorithm for finding the $k$th smallest element in an input list $L$ of size $n$ containing distinct elements. The algorithm uses the Median of Medians (MoM) technique to select the pivot element. Which of the following is the correct recurrence relation representing the worst-case running time of this Quick Select algorithm?

  1. $T(n)=T(n-1)+O(n)$

  2. $T(n)=T(n/2)+O(n)$

  3. $T(n)=2T(n/2)+O(n)$

  4. $T(n)=T(n/2)+O(1)$

Aug 2023

Question 15 MCQ · 3 marks

Maximum subarray sum: Given an array of integers, the goal is to find a contiguous subarray (a subarray with elements positioned adjacent to each other in the original array) that has the largest possible sum. Consider the following implementation max_subarray_sum to find the maximum subarray sum in an array. What is the worst-case time complexity of this algorithm when applied to an array of size $n$?

def max_crossing_sum(arr, low, mid, high):
    left_sum = float('-inf')
    curr_sum = 0
    for i in range(mid-1, low - 1, -1):
        curr_sum += arr[i]
        if curr_sum > left_sum:
            left_sum = curr_sum

    right_sum = float('-inf')
    curr_sum = 0
    for i in range(mid, high):
        curr_sum += arr[i]
        if curr_sum > right_sum:
            right_sum = curr_sum
    return left_sum + right_sum

# In First call low = 0, high = len(arr)
def max_subarray_sum(arr, low, high):
    if high - low <= 1:
        return arr[low]

    mid = (low + high) // 2

    left_sum = max_subarray_sum(arr, low, mid)
    right_sum = max_subarray_sum(arr, mid, high)
    cross_sum = max_crossing_sum(arr, low, mid, high)

    return max(left_sum, right_sum, cross_sum)
  1. $O(n)$

  2. $O(\log n)$

  3. $O(n\log n)$

  4. $O(n^2)$

Question 17 MCQ · 3 marks

Consider the following recurrences and choose the correct option.

  1. $T_1(n)=3T_1(n/3)+O(n)$
  1. $T_2(n)=2T_2(n/4)+O(n^2)$

Base case: $T_1(1)=T_2(1)=1$.

  1. $T_1=O(n)$ and $T_2=O(n^2)$

  2. $T_1=O(n\log n)$ and $T_2=O(n^2)$

  3. $T_1=O(n)$ and $T_2=O(n\log n)$

  4. $T_1=O(n^2)$ and $T_2=O(n^2)$

Question 14 SA · 3 marks

In a list $L$, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. Consider a list $L$ of length $n$ in which all elements are distinct. List $L$ has exactly 21 inversions. The minimum possible value of $n$ is ___

Type your answer on the interactive page.

Question 16 MSQ · 3 marks

Consider the following statements and choose the correct ones.

  1. The worst case running time of Quick select algorithm to find the $k$th largest number is $O(n)$

  2. The time taken to find the median in an unsorted list using Median of Medians(MoM) algorithm is $O(n)$

  3. Quick select algorithm is an example of the divide-and-conquer approach to solving problems

  4. Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n)$.

Dec 2023

Question 9 MCQ · 3 marks

Consider the following function to return the minimum element in the list of size $n$. Which of the following represents the correct recurrence relation for the given function find_min?

def find_min(L, low, high):
    if low == high:
        return L[low]
    mid = (low + high) // 2
    min1 = find_min(L, low, mid)
    min2 = find_min(L, mid + 1, high)
    return min(min1, min2)
  1. $T(n)=T(n/2)+n$

  2. $T(n)=2T(n/2)+1$

  3. $T(n)=2T(n/2)+n$

  4. $T(n)=T(n/2)+1$

Question 10 MCQ · 3 marks

Consider the following recurrences.

  1. $T_1(n)=3T_1(n/3)+O(n^2)$
  1. $T_2(n)=9T_2(n/3)+O(n)$

Base case: $T_1(1)=T_2(1)=1$. Select the correct complexity for given recurrences.

  1. $T_1=O(n^2)$ and $T_2=O(n^2)$

  2. $T_1=O(n\log n)$ and $T_2=O(n^2)$

  3. $T_1=O(n\log n)$ and $T_2=O(n^2\log n)$

  4. $T_1=O(n^2)$ and $T_2=O(n\log n)$

Question 12 SA · 4 marks

In a list $L$, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. What is the number of inversion pairs for the list $L=[1,5,4,2,6,3]$?

Type your answer on the interactive page.

Question 17 MSQ · 3 marks

Consider the following statements and choose the correct ones.

  1. The worst case running time of the Quick select algorithm to find the $k$-th largest number is $O(n^2)$

  2. The time taken to find the median in an unsorted list using the Median of Medians (MoM) algorithm is $O(n)$

  3. Quick select algorithm is an example of the divide-and-conquer approach to solving problems

  4. Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n\log n)$.

16 Mar 2025

Question 8 MCQ · 3 marks

Consider the following function to return the minimum element in the list of size $n$. Which of the following represents the correct recurrence relation for the given function find_min?

def find_min(L, low, high):
    if low == high:
        return L[low]
    mid = (low + high) // 2
    min1 = find_min(L, low, mid)
    min2 = find_min(L, mid + 1, high)
    return min(min1, min2)
  1. $T(n)=T(n/2)+n$

  2. $T(n)=2T(n/2)+1$

  3. $T(n)=2T(n/2)+n$

  4. $T(n)=T(n/2)+1$

Question 7 MCQ · 3 marks

Algorithm A solves a problem of size $n$ by dividing it into five subproblems, each of size $n/2$, recursively solving each subproblem, and then combining the solutions in $O(n)$ time. What is the time complexity of Algorithm A?

  1. $O(n\log n)$

  2. $O(n^2)$

  3. $O(n^{\log_2 5})$

  4. $O(n^{\log_2 3})$

Question 15 SA · 3 marks

In the list $L$, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. What is the total number of inversions in $L=[9,1,12,4,7,13,5]$?

Type your answer on the interactive page.

Question 6 MCQ · 3 marks

Which of the following statement is true for searching the $k$th smallest element in an unsorted array of size $n$?

  1. Using the Fast select strategy the worst case running time will be $O(n\log n)$.

  2. Using a max-heap of size $k$ the worst case running time will be $O(k)$.

  3. Using the Quick select strategy the worst case running time will be $O(n^2)$.

  4. Using the Quick select strategy the worst case running time will be $O(n)$.

24 Mar 2024

Question 8 MCQ · 3 marks

Consider the following recurrence relation for an algorithm: $T(n)=4T(n/2)+O(n)$. Base Case: $T(1)=1$. The complexity of this algorithm is ___.

  1. $O(n)$

  2. $O(\log n)$

  3. $O(n^2)$

  4. $O(n\log n)$

Question 15 SA · 3 marks

Let $L$ be an integer list of length $n$. The number of inversions is the number of the different pairs $(i,j)$ where $0\le i<j<n$ and $L[i]>L[j]$. The total number of inversions for $L=[1,3,5,7,9,8,6,4,2]$ is ___.

Type your answer on the interactive page.

Question 12 MSQ · 3 marks

Consider the following statements and choose the correct ones.

  1. The worst case running time of Quick select algorithm to find the $k$th largest number is $O(n)$

  2. The time taken to find the median in an unsorted list using the Median of Medians(MoM) algorithm is $O(n)$

  3. The Quick select algorithm is an example of the divide-and-conquer approach.

  4. Using the Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n^2)$ to find the $k$th largest number.

Question 7 MCQ · 3 marks

Apply the divide and conquer strategy to find the closest pair of points in a set. After dividing the set into two halves and recursively finding the closest pairs in each half, what additional step is required?

  1. Combine the results directly

  2. Perform a linear search for the closest pair

  3. Consider pairs that span both halves

  4. Sort the points by their distances

04 Aug 2024

Question 3 MCQ · 4 marks

Consider the following recurrences and choose the correct option.

  1. $T_1(n)=3T_1(n/3)+O(n)$
  1. $T_2(n)=4T_2(n/2)+O(n)$

Consider base case: $T_1(1)=T_2(1)=1$.

  1. $T_1=O(n)$ and $T_2=O(n^2)$

  2. $T_1=O(n\log n)$ and $T_2=O(n^2)$

  3. $T_1=O(n)$ and $T_2=O(n\log n)$

  4. $T_1=O(n^2)$ and $T_2=O(n^2)$

Question 14 SA · 3 marks

For an integer list $L$ of length $n$ which represents a permutation of numbers from 1 to $n$, the number of inversions is the number of the different pairs $(i,j)$ where $0\le i<j<n$ and $L[i]>L[j]$. Consider $L=[7,2,5,6,1,3,4,8]$. The total number of inversions for the given list $L$ is ___.

Type your answer on the interactive page.

Question 11 MCQ · 3 marks

Which of the following is the correct recurrence relation for the Quick Select algorithm to find the $k^{th}$ smallest element in a list with $n$ distinct elements, where the median of Median (MOM) algorithm is used to find the median element?

  1. $T(n)=T(n-1)+O(n)$

  2. $T(n)=T(n/2)+O(n)$

  3. $T(n)=2T(n/2)+O(n)$

  4. $T(n)=T(n/2)+O(1)$

14 Aug 2026

Question 16 MSQ · 4 marks

Consider the following recurrence relations:

  1. $T_1(n)=2T_1(n/2)+O(n)$
  1. $T_2(n)=4T_2(n/2)+O(n)$
  1. $T_3(n)=8T_3(n/8)+O(n)$
  1. $T_4(n)=3T_4(n/3)+O(n)$

Base Case: $T_1(1)=T_2(1)=T_3(1)=T_4(1)=1$. Which of the above recurrences have asymptotic complexity $O(n\log n)$?

  1. $T_1(n)$

  2. $T_2(n)$

  3. $T_3(n)$

  4. $T_4(n)$

Question 15 SA · 3 marks

In a list $L$ of distinct elements, two elements $L[i]$ and $L[j]$ form an inversion if $L[i]>L[j]$ and $i<j$. Suppose $L$ contains exactly 15 inversions. The minimum possible length of $L$ is ___.

Type your answer on the interactive page.

Question 12 MCQ · 3 marks

Which of the following approaches can improve the worst-case running time of Quick Select to $O(n)$?

  1. Selecting the median of a random sample of $k$ elements (for a fixed constant $k$) as the pivot.

  2. Selecting a uniformly random element as the pivot.

  3. Selecting the median element after sorting the entire current subarray before partitioning.

  4. Selecting the pivot using the Median-of-Medians algorithm.

Question 11 MCQ · 3 marks

In the Divide-and-Conquer Closest Pair of points algorithm, why is brute force typically used when the number of points in a subproblem is at most 3?

  1. Brute force is asymptotically faster than divide-and-conquer

  2. Dynamic programming cannot be applied

  3. The closest pair is always known in advance

  4. The overhead of further recursive division outweighs its benefit for very small inputs

Check your answers →

Other PDSA topics