1What does the time complexity of an algorithm describe?
Time and Space Complexity
Easy
A.The number of variables in the program
B.The accuracy of the produced output
C.The programming language used for coding
D.The growth of running time with input size
Correct Answer: The growth of running time with input size
Explanation:
Time complexity describes how an algorithm's running time grows as the input size increases.
Incorrect! Try again.
2What does auxiliary space complexity measure?
Time and Space Complexity
Easy
A.The size of the input data
B.The extra memory used by the algorithm
C.The number of output values
D.The time required to read input
Correct Answer: The extra memory used by the algorithm
Explanation:
Auxiliary space is the additional memory used by an algorithm, excluding the storage occupied by the input.
Incorrect! Try again.
3What is the best-case time complexity of insertion sort when the array is already sorted?
Complexity Analysis of Insertion Sort and Merge Sort
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Insertion sort makes one comparison for each element in an already sorted array, giving time.
Incorrect! Try again.
4What is the worst-case time complexity of insertion sort?
Complexity Analysis of Insertion Sort and Merge Sort
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case, each element may be compared with and shifted past all earlier elements, requiring time.
Incorrect! Try again.
5What is the standard time complexity of merge sort for an array of elements?
Complexity Analysis of Insertion Sort and Merge Sort
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Merge sort has levels, and each level performs merging work.
Incorrect! Try again.
6How much auxiliary space does the standard array-based merge sort use?
Complexity Analysis of Insertion Sort and Merge Sort
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Standard merge sort uses temporary arrays whose total size is proportional to the input size.
Incorrect! Try again.
7A loop executes exactly times and performs constant work in each iteration. What is its time complexity?
Analysis of Iterative Algorithms
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Repeating constant-time work times results in a total time complexity of .
Incorrect! Try again.
8Two nested loops each execute times. If the inner operation takes constant time, what is the total time complexity?
Analysis of Iterative Algorithms
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The inner operation runs times, so the total complexity is .
Incorrect! Try again.
9What is the purpose of a base case in a recursive algorithm?
Analysis of Recursive Algorithms
Easy
A.To divide the input into equal parts
B.To increase the recursion depth
C.To stop further recursive calls
D.To combine all recursive results
Correct Answer: To stop further recursive calls
Explanation:
A base case provides a stopping condition so that the recursive calls eventually terminate.
Incorrect! Try again.
10Which recurrence represents a function that makes one recursive call on input size and performs constant additional work?
Analysis of Recursive Algorithms
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
One call on size contributes , while the constant additional work contributes .
Incorrect! Try again.
11What is the main idea of the substitution method for solving recurrences?
Substitution Method
Easy
A.Guess a bound and prove it by induction
B.Replace recursion with an iterative loop
C.Draw every recursive call as a tree
D.Apply only the merge sort recurrence
Correct Answer: Guess a bound and prove it by induction
Explanation:
The substitution method begins with a guessed asymptotic bound and verifies it using mathematical induction.
Incorrect! Try again.
12In the recursion tree method, what does each level of the tree represent?
Recursion Tree Method
Easy
A.One element of the final output
B.One stage of recursive subproblems
C.One statement in the source code
D.One variable used by the program
Correct Answer: One stage of recursive subproblems
Explanation:
Each level represents the subproblems generated at a particular depth of recursion.
Incorrect! Try again.
13For , what is the total work performed at each non-leaf level of the recursion tree?
Recursion Tree Method
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Although the number of subproblems doubles, their sizes halve, so the total work at each level remains .
Incorrect! Try again.
14What is the standard form of a recurrence handled by the Master Method?
Master Method
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The Master Method applies to divide-and-conquer recurrences of the form .
Incorrect! Try again.
15Using the Master Method, what is the solution of ?
Master Method
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Here, , , and . Since , the result is .
Incorrect! Try again.
16How many recursive matrix multiplications does Strassen's algorithm use for two partitioned matrices?
Strassen's Matrix Multiplication
Easy
A.Seven multiplications
B.Nine multiplications
C.Six multiplications
D.Eight multiplications
Correct Answer: Seven multiplications
Explanation:
Strassen's method reduces the usual eight recursive multiplications to seven.
Incorrect! Try again.
17What is the asymptotic time complexity of Strassen's matrix multiplication algorithm?
Strassen's Matrix Multiplication
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Strassen's recurrence is , giving , approximately .
Incorrect! Try again.
18In a set of distinct elements, what is the first order statistic?
Order Statistics
Easy
A.The minimum element
B.The maximum element
C.The average element
D.The median element
Correct Answer: The minimum element
Explanation:
The first order statistic is the smallest element in the ordered set.
Incorrect! Try again.
19What is the average-case time complexity of Quick Select?
Quick Select
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Quick Select usually examines only one partition recursively, resulting in an average time complexity of .
Incorrect! Try again.
20What is the third smallest element in the array ?
k-th Smallest Element
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Sorting the values gives , so the third smallest element is .
Incorrect! Try again.
21Consider the following loops, where is a power of :
for (i = 1; i <= n; i *= 2)
for (j = 0; j < i; j++)
operation();
What are the time and auxiliary space complexities?
Time and Space Complexity
Medium
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
The total operations are , which is . Only loop variables are stored, so auxiliary space is .
Incorrect! Try again.
22When insertion sort processes the array , how many element shifts are performed?
Complexity Analysis of Insertion Sort and Merge Sort
Medium
A. shifts
B. shifts
C. shifts
D. shifts
Correct Answer: shifts
Explanation:
Insertion sort performs one shift for each inversion. The inversions are , , , and , giving shifts.
Incorrect! Try again.
23A standard top-down merge sort uses temporary arrays during merging. What are its worst-case time and auxiliary space complexities?
Complexity Analysis of Insertion Sort and Merge Sort
Medium
A. time and auxiliary space
B. time and auxiliary space
C. time and auxiliary space because only the recursion stack is counted and temporary merge arrays require no storage
D. time and auxiliary space
Correct Answer: time and auxiliary space
Explanation:
Merge sort has levels with merging work per level. Temporary merge storage requires auxiliary space.
Incorrect! Try again.
24What is the time complexity of the following loop structure?
for (i = 1; i <= n; i++)
for (j = 1; j <= i; j++)
operation();
Analysis of Iterative Algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The operation executes times, which is .
Incorrect! Try again.
25Determine the time complexity of the following code:
for (i = 1; i <= n; i++)
for (j = i; j <= n; j += i)
operation();
Analysis of Iterative Algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
For each , the inner loop runs about times. Thus, the total is .
Incorrect! Try again.
26An algorithm has recurrence with . What is its asymptotic running time?
Analysis of Recursive Algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Expanding the recurrence gives . This arithmetic sum is .
Incorrect! Try again.
27A recursive function makes two calls on inputs of size and performs a loop taking time outside the calls. What is its running time?
Analysis of Recursive Algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The recurrence is . Each recursion level costs , and there are levels.
Incorrect! Try again.
28For , suppose the inductive hypothesis is for . What expression results after substitution and simplification?
Substitution Method
Medium
A.
B.
C. for every positive value of , without requiring any restriction on the inductive constant
D.
Correct Answer:
Explanation:
Substitution gives .
Incorrect! Try again.
29To prove is , assume . What condition on makes the induction step valid?
Substitution Method
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The substitution gives . Requiring this to be at most yields , so .
Incorrect! Try again.
30For the recurrence , how does the nonrecursive cost change from one recursion-tree level to the next, and what is the resulting complexity?
Recursion Tree Method
Medium
A.It increases by , giving
B.It increases by , giving
C.It decreases by , giving
D.It remains constant, giving
Correct Answer: It increases by , giving
Explanation:
At level , the cost is . Costs increase toward the leaves, whose total contribution is .
Incorrect! Try again.
31Consider . What complexity is indicated by a recursion-tree analysis?
Recursion Tree Method
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The subproblem sizes at each level sum to , so each level contributes . The tree has depth, producing total work.
Incorrect! Try again.
32Use the Master Method to solve .
Master Method
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Here, , , and . Since , Master Method case 1 gives .
Incorrect! Try again.
33What is the solution of according to the Master Method?
Master Method
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Since and , the extended second case gives .
Incorrect! Try again.
34Strassen's algorithm divides each matrix into four blocks but uses seven recursive block multiplications. Which pair correctly describes its recurrence and asymptotic time?
Strassen's Matrix Multiplication
Medium
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Seven half-sized multiplications produce the recursive term, while block additions cost . Therefore, the time is .
Incorrect! Try again.
35An array contains distinct elements. After partitioning, a pivot has exactly elements smaller than it and elements larger than it. Which order statistic is the pivot?
Order Statistics
Medium
A.Its order cannot be identified because partitioning provides no rank information unless the entire array is first sorted in increasing order
B.The th smallest element
C.The th smallest element
D.The th smallest element
Correct Answer: The th smallest element
Explanation:
If exactly five elements are smaller, the pivot has rank . It is also the median of the elements.
Incorrect! Try again.
36Using the pairwise method, what is the minimum number of comparisons needed to find both the minimum and maximum of distinct elements?
Order Statistics
Medium
A. comparisons
B. comparisons
C. comparisons
D. comparisons
Correct Answer: comparisons
Explanation:
For even , the pairwise method uses comparisons. For , this is .
Incorrect! Try again.
37For randomized Quick Select, which pair correctly states the expected and worst-case running times?
Quick Select
Medium
A. expected and worst case
B. expected and worst case
C. expected and worst case
D. expected and worst case
Correct Answer: expected and worst case
Explanation:
Random pivots produce linear expected time. Repeatedly choosing an extreme pivot creates subproblems of sizes , resulting in time.
Incorrect! Try again.
38Quick Select seeks the th smallest element. After partitioning, the pivot is the th smallest element of the current subarray. What should the algorithm do next?
Quick Select
Medium
A.Search for the th smallest element in the right partition
B.Search for the th smallest element in the left partition
C.Search for the rd smallest element in the left partition
D.Search for the rd smallest element in the right partition
Correct Answer: Search for the rd smallest element in the right partition
Explanation:
The desired rank is greater than the pivot rank, so Quick Select searches the right partition. Its adjusted rank is .
Incorrect! Try again.
39To find the th smallest element in an unsorted array, an algorithm maintains a max-heap containing the smallest values seen so far. What does the heap root represent at the end, and what is the running time?
k-th Smallest Element
Medium
A.The smallest element in time
B.The th smallest element in time
C.The th largest element in time
D.The largest element in time
Correct Answer: The th smallest element in time
Explanation:
The max-heap retains the smallest elements, so its root is the largest among them—the th smallest overall. Each relevant replacement costs .
Incorrect! Try again.
40An array of distinct elements is sorted in ascending order and indexed from . At which index is the th largest element?
k-th Largest Element
Medium
A.Index
B.Index
C.Index
D.Index
Correct Answer: Index
Explanation:
In a zero-based ascending array of length , the th largest element is at index . Thus, .
Incorrect! Try again.
41Consider a recursive procedure that makes two calls with parameter until , performs work per call, and stores no results. If output storage is excluded, what are its time and auxiliary-space complexities when called with ?
Time and Space Complexity
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
The recursion tree contains calls, but only one root-to-leaf path of length is active at a time. Thus, time is exponential while stack space is linear.
Incorrect! Try again.
42An array of length contains exactly inversions. Insertion sort uses a sentinel, so every insertion performs one final unsuccessful key comparison. What are the exact number of shifts and key comparisons?
Complexity Analysis of Insertion Sort and Merge Sort
Hard
A. shifts and comparisons
B. shifts and comparisons
C. shifts and comparisons
D. shifts and comparisons
Correct Answer: shifts and comparisons
Explanation:
Each shift removes exactly one inversion, giving shifts. Each of the insertions also has one final failed comparison, so the comparison count is .
Incorrect! Try again.
43A top-down merge sort allocates a temporary array proportional to the current subproblem size in each active call and releases it when that call returns. What are its worst-case time and peak auxiliary-space complexities?
Complexity Analysis of Insertion Sort and Merge Sort
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
Merging costs per recursion level over levels. Along an active path, allocated arrays have total size .
Incorrect! Try again.
44Determine the running time of the following loop, assuming the body is :
for (i = 1; i <= n; i *= 2)
for (j = i; j <= n; j += i)
body
Analysis of Iterative Algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
For , the inner loop executes times. Summing the geometric series gives .
Incorrect! Try again.
45What is the asymptotic running time of the following algorithm?
for (i = 1; i <= n; i++)
for (j = i; j <= n; j += i)
for (k = 1; k <= j; k *= 2)
body
Analysis of Iterative Algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
For a fixed , there are multiples of , and the logarithmic loop contributes on average. Summing over gives .
Incorrect! Try again.
46For constant-size base cases, determine the tight bound for
Analysis of Recursive Algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The total subproblem size at each next level is at most of the preceding level. The nonrecursive work therefore forms a decreasing geometric series totaling .
Incorrect! Try again.
47For , suppose the induction hypothesis is substituted directly, without adding a lower-order term. Which condition on makes the inductive inequality hold for all sufficiently large ?
Substitution Method
Hard
A. only
B.
C.
D.
Correct Answer:
Explanation:
Writing , substitution leaves the extra term . It becomes nonpositive for sufficiently large exactly when .
Incorrect! Try again.
48Let be a power of two and consider
with a constant-size base case. What bound follows from a recursion-tree analysis?
Recursion Tree Method
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
At level , the total nonrecursive cost is . Summing over the levels produces times a harmonic sum of length , giving .
Incorrect! Try again.
49Using the Master Method, determine the tight bound for
Master Method
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Here grows polynomially faster than . Master Method case 1 therefore gives .
Incorrect! Try again.
50Consider
Which statement is correct?
Master Method
Hard
A.Master Method case 3 applies, and
B.Master Method case 2 applies, and
C.The basic Master Method is inconclusive, and
D.Master Method case 1 applies, and
Correct Answer: The basic Master Method is inconclusive, and
Explanation:
The function is not polynomially smaller than . A level-wise sum yields times a harmonic series over levels, producing .
Incorrect! Try again.
51Strassen's algorithm is applied to two matrices where is not a power of two. Each matrix is padded to size , where is the next power of two. What is the resulting asymptotic running time in terms of ?
Strassen's Matrix Multiplication
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The next power of two satisfies , so . Hence padding changes only a constant factor, preserving the bound.
Incorrect! Try again.
52At recursion level of Strassen's algorithm, there are subproblems of dimension . What is the total matrix-addition work at that level?
Strassen's Matrix Multiplication
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each subproblem performs addition work. Multiplying by gives .
Incorrect! Try again.
53In the comparison model, what is the optimal worst-case number of comparisons needed to find both the minimum and maximum of elements?
Order Statistics
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Pairing elements first uses one comparison per pair, after which winners compete for the maximum and losers for the minimum. This achieves the matching lower bound .
Incorrect! Try again.
54Quick Select repeatedly chooses a pivot that is the smallest remaining element while searching for the largest element. What recurrence and worst-case running time result?
Quick Select
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Each partition scans the current subarray but discards only the pivot. The work is .
Incorrect! Try again.
55For randomized Quick Select on an arbitrary fixed input, where each pivot is chosen uniformly from the active subarray, which pair of bounds is correct?
Quick Select
Hard
A.Expected and worst-case
B.Expected and worst-case
C.Expected and worst-case
D.Expected and worst-case
Correct Answer: Expected and worst-case
Explanation:
Random pivots reduce the expected active-subarray size sufficiently to give linear expected time. A sequence of consistently extreme pivots still causes quadratic worst-case time.
Incorrect! Try again.
56Two arrays of lengths and are individually sorted. Without merging them, what time and auxiliary-space bounds can a binary-partition algorithm achieve for finding the -th smallest element?
k-th Smallest Element
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
Binary search over a partition index in the shorter array identifies complementary prefixes containing exactly elements. Only a constant number of indices and boundary values are stored.
Incorrect! Try again.
57A three-way partition around pivot produces elements greater than , elements equal to , and the rest smaller than . For ranks counted with multiplicity, when is the -th largest element?
k-th Largest Element
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Ranks through belong to values strictly greater than . The next ranks, namely through , all have value .
Incorrect! Try again.
58Suppose deterministic selection groups elements in threes, recursively finds the median of the group medians, and partitions around it. Ignoring rounding, which recurrence describes the standard worst-case analysis, and what bound does it yield?
Order Statistics
Hard
A., yielding
B., yielding
C., yielding
D., yielding
Correct Answer: , yielding
Explanation:
Finding the pivot recursively costs , while the larger partition may contain about elements. Since the recursive fractions sum to , the recurrence gives rather than a linear guarantee.
Incorrect! Try again.
59An algorithm scans unsorted elements while maintaining a min-heap containing the largest elements seen so far. What are its worst-case time and auxiliary-space complexities?
k-th Largest Element
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
Each scanned element may cause a heap update costing , and the heap never stores more than elements. Its root is the -th largest after the scan.
Incorrect! Try again.
60In median-of-medians selection with groups of five, which worst-case recurrence correctly captures the pivot-selection call and the largest possible recursive partition, up to constant rounding terms?
k-th Smallest Element
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The median of the group medians costs . The pivot guarantees that roughly elements lie on each side, so the larger recursive partition has at most about elements, yielding linear time.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →