Question 10
Select the correct match of recurrence relation with corresponding complexity. Assume that for all recurrence relations, the base case is $T(1)=1$.
A-3, B-1, C-2, D-4
A-4, B-1, C-3, D-2
A-4, B-1, C-2, D-3
A-1, B-3, C-2, D-4
Solve them and check answers →Read the notes first
Select the correct match of recurrence relation with corresponding complexity. Assume that for all recurrence relations, the base case is $T(1)=1$.
A-3, B-1, C-2, D-4
A-4, B-1, C-3, D-2
A-4, B-1, C-2, D-3
A-1, B-3, C-2, D-4
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 ___.
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)15
9
14
17
Which of the following statements are true about the finding the closest pair of points using divide and conquer strategy?
The algorithm uses the Euclidean distance formula to determine the separation between any two given points.
A fundamental part of the strategy involves recursively finding the closest pair of points within two distinct, smaller subsets of the original point set.
The optimal worst-case time complexity achieved by this divide and conquer approach is $O(n\log n)$.
The combine step requires comparing every point in the left half with every point in the right half to find cross-border closest pairs.
Select the correct match of recurrence relation with corresponding complexity.
A-2, B-4, C-3, D-1
A-2, B-3, C-4, D-1
A-2, B-3, C-1, D-4
A-3, B-2, C-4, D-1
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 ___.
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)The smallest value in $L$ that is greater than $k$.
The largest value in $L$ that is less than or equal to $k$.
The $k$th largest element in $L$.
The $k^{th}$ smallest element in $L$.
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)$O(\log n)$
$O(n)$
$O(n\log n)$
$O(n^2)$
Select the correct match of recurrence relation with corresponding complexity.
A-2, B-4, C-3, D-1
A-2, B-3, C-4, D-1
A-2, B-3, C-1, D-4
A-3, B-2, C-4, D-1
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 ___
Consider the following statements
Which of the following option is correct?
Only statement 1 is correct.
Only statement 2 is correct.
Both statements are correct.
Both statements are incorrect.
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?
Combine the results directly
Perform a linear search for the closest pair
Consider pairs that span both halves
Sort the points by their distances
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?
$O(n\log n)$
$O(n^2\log n)$
$O(n^2)$
$O(n^6)$
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 ___.
3
4
5
6
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))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?
$T(n)=T(n-1)+O(n)$
$T(n)=T(n/2)+O(n)$
$T(n)=2T(n/2)+O(n)$
$T(n)=T(n/2)+O(1)$
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)$O(n)$
$O(\log n)$
$O(n\log n)$
$O(n^2)$
Consider the following recurrences and choose the correct option.
Base case: $T_1(1)=T_2(1)=1$.
$T_1=O(n)$ and $T_2=O(n^2)$
$T_1=O(n\log n)$ and $T_2=O(n^2)$
$T_1=O(n)$ and $T_2=O(n\log n)$
$T_1=O(n^2)$ and $T_2=O(n^2)$
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 ___
Consider the following statements and choose the correct ones.
The worst case running time of Quick select algorithm to find the $k$th largest number is $O(n)$
The time taken to find the median in an unsorted list using Median of Medians(MoM) algorithm is $O(n)$
Quick select algorithm is an example of the divide-and-conquer approach to solving problems
Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n)$.
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)$T(n)=T(n/2)+n$
$T(n)=2T(n/2)+1$
$T(n)=2T(n/2)+n$
$T(n)=T(n/2)+1$
Consider the following recurrences.
Base case: $T_1(1)=T_2(1)=1$. Select the correct complexity for given recurrences.
$T_1=O(n^2)$ and $T_2=O(n^2)$
$T_1=O(n\log n)$ and $T_2=O(n^2)$
$T_1=O(n\log n)$ and $T_2=O(n^2\log n)$
$T_1=O(n^2)$ and $T_2=O(n\log n)$
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]$?
Consider the following statements and choose the correct ones.
The worst case running time of the 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)$
Quick select algorithm is an example of the divide-and-conquer approach to solving problems
Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be $O(n\log n)$.
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)$T(n)=T(n/2)+n$
$T(n)=2T(n/2)+1$
$T(n)=2T(n/2)+n$
$T(n)=T(n/2)+1$
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?
$O(n\log n)$
$O(n^2)$
$O(n^{\log_2 5})$
$O(n^{\log_2 3})$
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]$?
Which of the following statement is true for searching the $k$th smallest element in an unsorted array of size $n$?
Using the Fast select strategy the worst case running time will be $O(n\log n)$.
Using a max-heap of size $k$ the worst case running time will be $O(k)$.
Using the Quick select strategy the worst case running time will be $O(n^2)$.
Using the Quick select strategy the worst case running time will be $O(n)$.
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 ___.
$O(n)$
$O(\log n)$
$O(n^2)$
$O(n\log n)$
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 ___.
Consider the following statements and choose the correct ones.
The worst case running time of Quick select algorithm to find the $k$th largest number is $O(n)$
The time taken to find the median in an unsorted list using the Median of Medians(MoM) algorithm is $O(n)$
The Quick select algorithm is an example of the divide-and-conquer approach.
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.
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?
Combine the results directly
Perform a linear search for the closest pair
Consider pairs that span both halves
Sort the points by their distances
Consider the following recurrences and choose the correct option.
Consider base case: $T_1(1)=T_2(1)=1$.
$T_1=O(n)$ and $T_2=O(n^2)$
$T_1=O(n\log n)$ and $T_2=O(n^2)$
$T_1=O(n)$ and $T_2=O(n\log n)$
$T_1=O(n^2)$ and $T_2=O(n^2)$
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 ___.
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?
$T(n)=T(n-1)+O(n)$
$T(n)=T(n/2)+O(n)$
$T(n)=2T(n/2)+O(n)$
$T(n)=T(n/2)+O(1)$
Consider the following recurrence relations:
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)$?
$T_1(n)$
$T_2(n)$
$T_3(n)$
$T_4(n)$
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 ___.
Which of the following approaches can improve the worst-case running time of Quick Select to $O(n)$?
Selecting the median of a random sample of $k$ elements (for a fixed constant $k$) as the pivot.
Selecting a uniformly random element as the pivot.
Selecting the median element after sorting the entire current subarray before partitioning.
Selecting the pivot using the Median-of-Medians algorithm.
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?
Brute force is asymptotically faster than divide-and-conquer
Dynamic programming cannot be applied
The closest pair is always known in advance
The overhead of further recursive division outweighs its benefit for very small inputs