Correct Answer: The cost can depend on the number of bits
Explanation:
Operations on large integers may require time proportional to their bit length rather than constant time.
Incorrect! Try again.
28For linear search on an array of distinct elements, which situation gives the best-case running time?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Medium
A.The target is the first element
B.The target is the final element
C.The target is absent from the array
D.The target occurs after exactly half of the array has been examined
Correct Answer: The target is the first element
Explanation:
Only one comparison is needed when the target is the first element, giving best-case time .
Incorrect! Try again.
29Suppose a successful linear search is equally likely to target any of the array positions. What is the expected number of comparisons?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The expected value is the average of , which is .
Incorrect! Try again.
30Quicksort always chooses the first element as its pivot. Which input is most likely to produce its worst-case behaviour?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Medium
A.An array whose first value happens to equal the median on every recursive call
B.An array split into equal unsorted halves
C.An already sorted array
D.A randomly shuffled array
Correct Answer: An already sorted array
Explanation:
On sorted input, the first element creates partitions of sizes and , leading to time.
Incorrect! Try again.
31An algorithm takes operations with probability and operations with probability . What is its expected operation count?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The expectation is .
Incorrect! Try again.
32What is the tightest big O bound among the choices for ?
Asymptotic notations: big O notation
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The highest-degree term dominates the growth, so the tightest listed bound is .
Incorrect! Try again.
33Consider a loop where starts at and is doubled after each iteration until . What is the loop's running time?
Asymptotic notations: big O notation
Medium
A.
B. because multiplication by two is itself a constant-time operation
C.
D.
Correct Answer:
Explanation:
After iterations, . Reaching therefore requires approximately iterations.
Incorrect! Try again.
34An outer loop runs times, while an inner loop runs from through the current outer-loop index . What is the total running time?
Asymptotic notations: big O notation
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The total iterations are , which is .
Incorrect! Try again.
35What value is returned by the following function when called as ? and for .
Recursion
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The function computes factorial, so .
Incorrect! Try again.
36A recursive function reduces its argument from to and performs constant work per call. What is its maximum call-stack depth?
Recursion
Medium
A.
B.
C. because every active call stores all results from earlier calls
D.
Correct Answer:
Explanation:
The argument decreases by one per call, so approximately calls remain active before the base case.
Incorrect! Try again.
37Which change is necessary to prevent infinite recursion in a function that repeatedly calls itself with a smaller positive integer?
Recursion
Medium
A.Store the argument in a queue
B.Add a reachable base case
C.Increase the argument before every recursive call so that it eventually overflows
D.Use two recursive calls
Correct Answer: Add a reachable base case
Explanation:
A reachable base case stops further calls once the argument reaches a designated value.
Incorrect! Try again.
38What is the asymptotic solution of with ?
Recurrence relations to analyse recursive algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Each recursion-tree level costs , and there are levels.
Incorrect! Try again.
39What is the asymptotic solution of with ?
Recurrence relations to analyse recursive algorithms
Medium
A.
B.
C.
D. because the recurrence contains a recursive term for every smaller input
Correct Answer:
Explanation:
Expanding the recurrence gives , whose sum is .
Incorrect! Try again.
40What is the asymptotic solution of with ?
Recurrence relations to analyse recursive algorithms
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The input is halved on each call, so the recurrence reaches the base case after levels.
Incorrect! Try again.
41A dynamic array starts empty with capacity . Whenever an append finds the array full, its capacity is doubled and all existing elements are copied before the new element is inserted. If , how many existing-element copies occur during the first appends?
Elementary data structures
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Resizing occurs at sizes . Thus the number of copies is .
Incorrect! Try again.
42A queue is implemented using input and output stacks. Enqueue pushes onto the input stack; dequeue transfers every item to the output stack only when the output stack is empty. For any sequence of operations starting from empty, which bounds are tight?
Elementary data structures
Hard
A.Worst-case ; amortized
B.Worst-case ; amortized
C.Worst-case ; amortized
D.Worst-case ; amortized
Correct Answer: Worst-case ; amortized
Explanation:
One dequeue may transfer elements, but each element is pushed and popped from each stack at most once. Therefore, operations take total time.
Incorrect! Try again.
43A disjoint-set forest uses both union by rank and path compression. For operations, including Make-Set operations, which asymptotic bound applies to the total running time?
Elementary data structures
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Union by rank combined with path compression gives amortized time per operation, where is the inverse Ackermann function.
Incorrect! Try again.
44Which capability is available in a word-RAM with -bit words but not generally in a pure pointer-machine model?
Basic computational models
Hard
A.Comparing two stored keys in constant time
B.Following a stored pointer in constant time
C.Accessing array cell from an integer index
D.Updating a constant number of pointer fields
Correct Answer: Accessing array cell from an integer index
Explanation:
A word-RAM supports constant-time address arithmetic and random access. A pointer machine can access objects only by following explicitly stored links.
Incorrect! Try again.
45An algorithm computes using multiplications. Why does the claim that its running time is fail in the bit-complexity model?
Basic computational models
Hard
A.Factorial cannot be represented exactly
B.The number of recursive calls is exponential
C.The algorithm requires comparison sorting
D.Multiplication cost grows with operand length
Correct Answer: Multiplication cost grows with operand length
Explanation:
The operands are not constant-size words: contains bits. Arithmetic costs therefore increase as intermediate values grow.
Incorrect! Try again.
46In the deterministic comparison-tree model, an algorithm sorts distinct keys. What lower bound follows directly from the number of possible input orders?
Basic computational models
Hard
A.At least comparisons in the worst case
B.At least comparisons on every input
C.At least comparisons in the worst case
D.At least comparisons in the worst case
Correct Answer: At least comparisons in the worst case
Explanation:
A binary comparison tree needs at least leaves, one for each permutation. Its height is therefore at least .
Incorrect! Try again.
47A binary string of length is selected uniformly from all nonzero strings. An algorithm scans left to right and stops at the first . What is the exact expected number of inspected bits?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
There are strings whose first is at position . Hence the expectation is .
Incorrect! Try again.
48Randomized Quicksort chooses its pivot uniformly from the current subarray. For any fixed input containing distinct keys, which statement correctly distinguishes expected and worst-randomness behavior?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Hard
A.Expected ; worst choices
B.Expected ; worst choices
C.Expected ; worst choices
D.Expected ; worst choices
Correct Answer: Expected ; worst choices
Explanation:
Uniform random pivots give expected time for every fixed input order. Consistently choosing an extreme pivot produces the quadratic worst case.
Incorrect! Try again.
49An algorithm has best-case running time and worst-case running time . Without specifying an input distribution, what can be concluded about its average-case time?
Analysis of algorithms: best-case, average-case, and worst-case behaviour
Hard
A.It cannot have any asymptotic bound
B.It must be
C.It must be
D.It lies between and
Correct Answer: It lies between and
Explanation:
An average depends on the probability distribution over inputs. It cannot be below the minimum cost or above the maximum cost, but no tighter general bound follows.
Incorrect! Try again.
50For integers , let . Which statement is true?
Asymptotic notations: big O notation
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The exponent always lies in , so . Oscillation arbitrarily close to both endpoints rules out the other three bounds.
Incorrect! Try again.
51Let . Which asymptotic classification is correct for every fixed and ?
Asymptotic notations: big O notation
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Writing shows that it is subpolynomial. Its exponential dependence on still dominates every fixed polylogarithm.
Incorrect! Try again.
52Define when is prime and otherwise. Which relation between and is correct?
Asymptotic notations: big O notation
Hard
A.
B. and
C. but
D. but
Correct Answer: but
Explanation:
The inequality always holds. On arbitrarily large composite values, however, , preventing any positive eventual lower-bound constant.
Incorrect! Try again.
53Quicksort is modified to recurse only on the smaller partition and to process the larger partition by iteration. What are the tight worst-case time and auxiliary-stack bounds?
Recursion
Hard
A. time and stack
B. time and stack
C. time and stack
D. time and stack
Correct Answer: time and stack
Explanation:
Poor pivots can still cause quadratic work. The recursive partition is always at most half the current size, so recursion depth is at most .
Incorrect! Try again.
54A top-down recursive Fibonacci algorithm evaluates and memoizes every computed value. Including the memo table and recursion stack, what are its tight time and space bounds?
Recursion
Hard
A. time and space
B. time and space
C. time and space
D. time and space
Correct Answer: time and space
Explanation:
Memoization computes each argument from through only once. The table stores values, and the initial recursive chain can have depth .
Incorrect! Try again.
55Consider a recursive procedure that makes two separate calls on and performs local work, without memoization. What is its total running time?
Recursion
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The call tree has logarithmic depth but doubles at each level. Its total number of nodes satisfies .
Incorrect! Try again.
56For powers of two, solve with .
Recurrence relations to analyse recursive algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
This is Master-theorem case 2 with an extra logarithmic factor: and the toll is , yielding .
Incorrect! Try again.
57Assume constant base-case cost. What is the solution of ?
Recurrence relations to analyse recursive algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
At each level, subproblem sizes sum to , producing aggregate work. The unbalanced recursion has relevant levels, giving .
Incorrect! Try again.
58For powers of two and constant base-case cost, solve for .
Recurrence relations to analyse recursive algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The aggregate toll near recursion level is proportional to . Summing these terms gives times a harmonic sum, hence .
Incorrect! Try again.
59Given and , which bound is tight?
Recurrence relations to analyse recursive algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Expanding the recurrence gives . The harmonic sum is .
Incorrect! Try again.
60For sufficiently large , let with a constant-size base case. What is the tight solution?
Recurrence relations to analyse recursive algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
After calls, the argument is approximately . It becomes constant when , so .
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 →