Algorithms Problem-Solving
- 39Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
When several functions have the same asymptotic growth rate, how should they be represented in an ordered list of growth rates?
When several functions have the same asymptotic growth rate, how should they be represented in an ordered list of growth rates?
39 questions
- 1
When several functions have the same asymptotic growth rate, how should they be represented in an ordered list of growth rates?
- A
As a group at the same position in the ordering
- B
As entries ordered by their values for small inputs
- C
As separate entries in an arbitrary order
- D
Only the function with the largest constant should be listed
Correct answer
AAs a group at the same position in the ordering
Explanation
Asymptotically equivalent functions belong together at the same position in the growth ordering; their relative order is not meaningful asymptotically.
- A
- 2
For positive constants a and b, how does (logn)a compare asymptotically with nb?
- A
Their relative growth depends on the values of a and b
- B
(logn)a grows strictly more slowly than nb
- C
The two functions are asymptotically equivalent
- D
(logn)a grows strictly faster than nb
Correct answer
B(logn)a grows strictly more slowly than nb
Explanation
Any fixed positive power of a logarithm grows more slowly than any fixed positive power of n.
- A
- 3
Suppose the ratio of two positive functions approaches 0 as n grows. What does this imply about their relative growth?
- A
Neither function can be compared asymptotically
- B
The numerator grows more slowly than the denominator
- C
The numerator grows more quickly than the denominator
- D
The two functions have the same asymptotic growth
Correct answer
BThe numerator grows more slowly than the denominator
Explanation
If the ratio of the numerator to the denominator approaches 0, the numerator is asymptotically smaller and grows more slowly.
- A
- 4
What does it indicate if the ratio of two positive functions approaches a positive finite constant?
- A
The denominator grows strictly faster
- B
Both functions must be exponential
- C
The numerator grows strictly faster
- D
The functions are asymptotically equivalent
Correct answer
DThe functions are asymptotically equivalent
Explanation
A ratio that approaches a positive finite constant indicates that the two functions differ by an asymptotically constant factor, so they are asymptotically equivalent.
- A
- 5
Which statement best distinguishes little-o from big-O when comparing two functions?
- A
Little-o expresses strictly slower growth, while big-O allows growth of the same order
- B
Little-o permits equal growth, while big-O requires strictly slower growth
- C
Little-o applies only to exponential functions, while big-O applies to all functions
- D
Little-o compares only constant factors, while big-O compares exponents
Correct answer
ALittle-o expresses strictly slower growth, while big-O allows growth of the same order
Explanation
Big-O allows the functions to have the same asymptotic order. Little-o describes a stricter relationship in which one function grows strictly more slowly.
- A
- 6
Why does multiplying an exponential function by a fixed polynomial factor not make it grow more slowly than every exponential function?
- A
Exponential growth dominates polynomial growth asymptotically
- B
Polynomial factors eventually cancel exponential growth
- C
Exponential and polynomial factors always have the same growth
- D
A polynomial factor changes an exponential into a logarithm
Correct answer
AExponential growth dominates polynomial growth asymptotically
Explanation
An exponential factor eventually dominates any fixed polynomial factor. Polynomial multipliers or divisors can affect comparisons between functions, but do not erase exponential growth.
- A
- 7
Compared with 2n, how does n2n grow asymptotically?
- A
More quickly, because the denominator increases with n
- B
At the same rate, because both functions contain 2n
- C
More slowly, because division by n reduces the function by an unbounded factor
- D
At the same rate, because n is a constant factor
Correct answer
CMore slowly, because division by n reduces the function by an unbounded factor
Explanation
The factor n grows without bound, so dividing by it makes the function asymptotically smaller than 2n, even though both retain exponential growth.
- A
- 8
What does the binomial coefficient (kn) count?
- A
The number of ways to choose n objects from a set of k objects
- B
The number of ways to arrange all n objects in a line
- C
The number of ways to arrange k selected objects in order
- D
The number of ways to choose k objects from n objects without regard to order
Correct answer
DThe number of ways to choose k objects from n objects without regard to order
Explanation
A binomial coefficient counts selections of k objects from n when the order of the selected objects does not matter.
- A
- 9
Which expression gives the factorial formula for (kn)?
- A
n!k!(n−k)!
- B
n!k!(n−k)!
- C
(n−k)!n!
- D
k!(n−k)!n!
Correct answer
Dk!(n−k)!n!
Explanation
The number of ordered selections of k objects is (n−k)!n!. Dividing by k! removes the different orders of the same selection, giving (kn)=k!(n−k)!n!.
- A
- 10
What is the main use of Stirling's approximation when analyzing factorials?
- A
It converts a factorial exactly into a polynomial
- B
It shows that factorials grow more slowly than exponentials
- C
It determines the number of divisors of a factorial
- D
It replaces a factorial with an expression whose asymptotic growth is easier to compare
Correct answer
DIt replaces a factorial with an expression whose asymptotic growth is easier to compare
Explanation
Stirling's approximation estimates factorials using an expression involving powers and a square-root factor, making their asymptotic growth easier to analyze.
- A
- 11
What is the asymptotic order of log(n!)?
- A
Θ(nlogn)
- B
Θ(n2)
- C
Θ(n)
- D
Θ((logn)2)
Correct answer
AΘ(nlogn)
Explanation
Taking the logarithm of Stirling's approximation for n! gives a leading term of nlogn; the remaining terms grow more slowly. Thus log(n!)=Θ(nlogn).
- A
- 12
For fixed k=3, what is the asymptotic order of (3n)?
- A
Θ(n3)
- B
Θ(logn)
- C
Θ(2n)
- D
Θ(nlogn)
Correct answer
AΘ(n3)
Explanation
Using (3n)=6n(n−1)(n−2), the leading term is a constant multiple of n3.
- A
- 13
What is the asymptotic order of the central binomial coefficient (n/2n) for even n?
- A
Θ(n2n)
- B
Θ(n3)
- C
Θ(ennn)
- D
Θ(logn)
Correct answer
AΘ(n2n)
Explanation
Applying Stirling's approximation to (n/2n)=((n/2)!)2n! and simplifying gives asymptotic growth proportional to n2n.
- A
- 14
What makes a sequence interface distinct from a particular array or linked-list implementation?
- A
It specifies the exact memory addresses of the first and last items
- B
It requires all items to occupy consecutive memory locations
- C
It specifies the operations and ordering behavior without prescribing how items are stored
- D
It requires each item to point to the next item
Correct answer
CIt specifies the operations and ordering behavior without prescribing how items are stored
Explanation
An interface describes the supported behavior abstractly. Arrays and linked lists are different possible implementations of a sequence interface.
- A
- 15
What does it mean to say that a sequence has an extrinsic order?
- A
Each item determines the position of the item that follows it
- B
Items are ordered according to their numerical values
- C
Items have positions such as first or tenth based on their arrangement, independent of their values
- D
Items are stored in memory in the order they were allocated
Correct answer
CItems have positions such as first or tenth based on their arrangement, independent of their values
Explanation
A sequence maintains positions such as first, tenth, and last. Those positions are determined by the sequence's arrangement, not by properties of the items themselves.
- A
- 16
A sequence data structure is given as a black box that supports insert-first, insert-last, delete-first, and delete-last in constant time. What is the key restriction of treating it as a black box?
- A
An algorithm must assume the sequence is stored in an array
- B
An algorithm may use only one of its supported operations
- C
An algorithm may inspect its internal memory but may not modify it
- D
An algorithm may rely on the supported operations but not on the hidden implementation
Correct answer
DAn algorithm may rely on the supported operations but not on the hidden implementation
Explanation
A black-box abstraction exposes a public interface while hiding the implementation. Algorithms using it should rely on its specified operations and guarantees.
- A
- 17
When a sequence's delete operation is specified to return the removed item, how can that guarantee help implement an endpoint swap?
- A
Replace both endpoints without retrieving their values
- B
Delete one endpoint and assume the other endpoint changes automatically
- C
Store both deleted endpoint items, then insert each at the opposite end
- D
Copy every item into a new sequence before swapping
Correct answer
CStore both deleted endpoint items, then insert each at the opposite end
Explanation
Deleting the first and last items returns their values. The algorithm can store those two values temporarily and insert each at the opposite end.
- A
- 18
If each sequence operation takes constant time, what is the running time of swapping the first and last items using two deletions and two insertions?
- A
Θ(n)
- B
Θ(1)
- C
Θ(n2)
- D
Θ(logn)
Correct answer
BΘ(1)
Explanation
The swap uses a fixed number of operations, and each operation takes constant time, so the total time is constant.
- A
- 19
What does a left shift by K positions do to a sequence?
- A
It deletes the first K items from the sequence
- B
It moves the last K items to the front in reverse order
- C
It moves the first K items, in their original order, to the back
- D
It reverses the first K items and leaves the rest in place
Correct answer
CIt moves the first K items, in their original order, to the back
Explanation
A left shift takes the first K items and appends them to the back in the same relative order. The former (K+1)st item becomes first.
- A
- 20
In a recursive left-shift algorithm that moves one item and then shifts K−1 items, what is a suitable base case?
- A
When K<0, move one item from the back to the front
- B
When K equals the sequence length, delete every item
- C
When K=0, return without changing the sequence
- D
When K=1, reverse the whole sequence
Correct answer
CWhen K=0, return without changing the sequence
Explanation
With K=0, no items need to be moved, so the recursion can stop without modifying the sequence.
- A
- 21
If each recursive call for a left shift performs a constant number of sequence operations and reduces K by one, what is the running time?
- A
Θ(2K)
- B
Θ(1)
- C
Θ(K)
- D
Θ(K2)
Correct answer
CΘ(K)
Explanation
The recursion makes a number of calls proportional to K, with constant work in each call, giving total time Θ(K).
- A
- 22
Which performance guarantee is associated with indexing into a dynamic array?
- A
Amortized linear time
- B
Worst-case logarithmic time
- C
Amortized quadratic time
- D
Worst-case constant time
Correct answer
DWorst-case constant time
Explanation
A dynamic array supports indexing in worst-case constant time, since an indexed element can be accessed directly.
- A
- 23
Why are insertions and deletions at the front of a conventional dynamic array inefficient?
- A
The array must search every item to find the front
- B
Existing items may need to be shifted to make room or close a gap
- C
Every front operation requires converting the array to a linked list
- D
The array cannot store items at index zero
Correct answer
BExisting items may need to be shifted to make room or close a gap
Explanation
Inserting at or removing from the front changes the positions of the other items, so many of them may need to be shifted.
- A
- 24
What does it mean for an operation to take amortized O(1) time?
- A
The operation's cost is independent of how many prior operations occurred
- B
Across a sequence of m operations, their total cost is bounded by a constant times m
- C
Every individual operation is guaranteed to take constant time
- D
The operation takes constant time only for average-sized inputs
Correct answer
BAcross a sequence of m operations, their total cost is bounded by a constant times m
Explanation
An amortized constant-time guarantee bounds the total cost of a sequence of operations by a constant times the number of operations. Some individual operations may still be expensive.
- A
- 25
How does amortized analysis differ from averaging an algorithm's running time over possible inputs?
- A
It analyzes the total cost of a sequence of operations on a data structure, rather than averaging across an input distribution
- B
It applies only when every operation has the same worst-case cost
- C
It requires assigning probabilities to each operation
- D
It averages the cost across all possible input sizes, while input analysis does not
Correct answer
AIt analyzes the total cost of a sequence of operations on a data structure, rather than averaging across an input distribution
Explanation
Amortized analysis bounds the total cost across multiple operations, often on the same evolving data structure. It does not require a probability distribution over inputs.
- A
- 26
Why can a dynamic array append be amortized constant time even if some appends are expensive?
- A
Resizing never copies existing items
- B
Each append is individually guaranteed to avoid allocation
- C
The array's capacity always equals its number of items
- D
Occasional resizing costs can be spread across many inexpensive appends
Correct answer
DOccasional resizing costs can be spread across many inexpensive appends
Explanation
Most appends are inexpensive, while a resize may require copying many elements. If resizing occurs only after many appends, the expensive costs can be charged across those operations.
- A
- 27
Why does keeping extra capacity at an array's end support amortized constant-time appends?
- A
It ensures the array never has unused memory
- B
It turns an array into a linked list during insertion
- C
It allows many appends before another costly resize is needed
- D
It makes every append avoid changing the array's contents
Correct answer
CIt allows many appends before another costly resize is needed
Explanation
Spare capacity lets the array accept multiple new items without resizing. If the capacity is expanded geometrically or otherwise with linear slack, a resize is separated from the next one by many appends.
- A
- 28
Why might a dynamic array shrink when it becomes much less full?
- A
To make indexing take less than constant time
- B
To guarantee that every deletion uses constant time in the worst case
- C
To preserve the original capacity permanently
- D
To avoid retaining space far larger than the amount needed for its current items
Correct answer
DTo avoid retaining space far larger than the amount needed for its current items
Explanation
If many items are removed but the array keeps its large allocation, it may use far more memory than the remaining sequence requires. Shrinking helps keep space proportional to the number of stored items.
- A
- 29
Why should a shrinking policy leave spare capacity instead of resizing to exactly the current number of items after every deletion?
- A
Exact-size arrays require linked-list nodes for each item
- B
Exact-size arrays cannot support indexing
- C
Spare capacity makes deletion at the front constant time
- D
Spare capacity helps prevent repeated expensive resizing after alternating deletions and insertions
Correct answer
DSpare capacity helps prevent repeated expensive resizing after alternating deletions and insertions
Explanation
If an array is resized to exactly its current size, the next insertion may immediately force growth again. Leaving slack creates room for more operations before another costly resize.
- A
- 30
How can two dynamic arrays be used to support efficient operations at both ends of a sequence?
- A
Alternate individual items between the arrays and scan both for each access
- B
Store one portion in each array, treating one array in reverse order and using index arithmetic
- C
Store every item in both arrays and compare copies after each operation
- D
Use one array only for indexing and the other only for resizing
Correct answer
BStore one portion in each array, treating one array in reverse order and using index arithmetic
Explanation
The sequence can be split into two portions held in separate dynamic arrays. One portion is viewed in reverse, allowing each array's efficient end operations to serve opposite ends of the overall sequence.
- A
- 31
What should a two-array deque-style structure do when one of its arrays becomes empty?
- A
Continue using the empty array for deletions until it contains an item
- B
Copy every item into a permanent fixed-size array
- C
Discard the other array and lose its stored items
- D
Rebalance the remaining items between newly arranged arrays to restore a useful split
Correct answer
DRebalance the remaining items between newly arranged arrays to restore a useful split
Explanation
When one side empties, the structure can redistribute the remaining items between the arrays. Since this rebuild follows many preceding operations, its cost can be amortized across them.
- A
- 32
Which property distinguishes linked-list lookup from dynamic-array indexing?
- A
Both methods require scanning the entire structure
- B
Linked-list lookup may require traversing nodes and take linear time
- C
Dynamic-array indexing requires following every preceding item
- D
Linked-list lookup is always worst-case constant time
Correct answer
BLinked-list lookup may require traversing nodes and take linear time
Explanation
A linked list may store nodes in different memory locations and provides access by following pointers, so finding a distant item can require traversing a linear number of nodes. An array can index directly.
- A
- 33
What information does each node in the singly linked list described in the content contain?
- A
An item and pointers to both the previous and next nodes
- B
A head pointer and the list's total size
- C
An array index and the total capacity of the list
- D
An item and a pointer to the next node
Correct answer
DAn item and a pointer to the next node
Explanation
Each singly linked-list node contains its item and a next pointer. The list itself maintains information such as its head and size.
- A
- 34
Given a singly linked list of 2n nodes, how many next-pointer traversals are needed to reach node n from the head?
- A
n
- B
2n−1
- C
2n
- D
n−1
Correct answer
Dn−1
Explanation
The head is node 1. Reaching node n therefore requires following n−1 next pointers.
- A
- 35
When reversing the next pointers of a singly linked list in place, why must the algorithm save the current node's next pointer before changing it?
- A
So it can continue traversing the unreversed portion after relinking the current node
- B
So it can avoid storing the previous node
- C
So it can determine the current node's item without reading it
- D
So it can calculate the size of the linked list
Correct answer
ASo it can continue traversing the unreversed portion after relinking the current node
Explanation
Changing the current node's next pointer would otherwise lose the link to the unreversed remainder. Saving that pointer first preserves the path for continued traversal.
- A
- 36
Which set of references is sufficient for an iterative in-place reversal of a singly linked-list segment?
- A
The current node, its item, and the list's capacity
- B
The head node, the list size, and an array of all node addresses
- C
The current node and a pointer to the list's tail only
- D
The current node, the previous node, and the saved next node
Correct answer
DThe current node, the previous node, and the saved next node
Explanation
The algorithm needs the current node to modify, the previous node to point back to, and the saved next node to continue traversing.
- A
- 37
After reversing the last n nodes of a list containing 2n nodes, what must happen at the boundary between the unchanged and reversed portions?
- A
The head must point directly to the last node of the original list
- B
The node at position n must be deleted
- C
The node at position n must point to the new first node of the reversed portion
- D
The new last node of the reversed portion must point back to the head
Correct answer
CThe node at position n must point to the new first node of the reversed portion
Explanation
The first n nodes remain in their original order. The node at position n must be linked to the original last node, which becomes the first node of the reversed portion.
- A
- 38
After reversing the final n nodes of a singly linked list in place, what should the next pointer of the new final node be?
- A
It should point to the node before the reversed segment
- B
It should be null
- C
It should point to the list head
- D
It should point to the original final node
Correct answer
BIt should be null
Explanation
The original first node of the reversed segment becomes its final node. Its next pointer must be null so the resulting list terminates correctly.
- A
- 39
If an algorithm is required to reverse part of a linked list in place using only constant extra space, which approach satisfies the restriction?
- A
Copy all node items into a new array and rewrite them in reverse order
- B
Create a second linked list containing the reversed nodes
- C
Store every node address in a temporary list before changing pointers
- D
Relink the existing nodes using a constant number of temporary references
Correct answer
DRelink the existing nodes using a constant number of temporary references
Explanation
In-place reversal modifies the existing nodes' pointers and needs only a constant number of temporary references. The other approaches use a non-constant amount of auxiliary storage or create new nodes.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.