6.006 Problem Session
- 25Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary purpose of the Master Theorem in algorithms?
What is the primary purpose of the Master Theorem in algorithms?
25 questions
- 1
What is the primary purpose of the Master Theorem in algorithms?
- A
To analyze the space complexity of iterative algorithms.
- B
To provide a systematic way to optimize recursive functions.
- C
To compare the performance of different sorting algorithms.
- D
To offer a quick method for solving recurrence relations.
Correct answer
DTo offer a quick method for solving recurrence relations.
Explanation
The Master Theorem is a powerful tool designed to quickly solve recurrence relations of the form T(n)=aT(n/b)+f(n), providing asymptotic bounds without needing to draw computation trees every time. It's often referred to as a 'sledgehammer' for recurrences due to its efficiency.
- A
- 2
Which component in the Master Theorem recurrence T(n)=aT(n/b)+f(n) represents the branching factor of the computation tree?
- A
The term 'n/b' indicating problem size reduction.
- B
The function 'f(n)' representing work at each node.
- C
The constant 'a' indicating the number of subproblems.
- D
The constant 'b' indicating the division factor for 'n'.
Correct answer
CThe constant 'a' indicating the number of subproblems.
Explanation
In the Master Theorem recurrence T(n)=aT(n/b)+f(n), 'a' represents the number of subproblems, or the branching factor, at each step of the recursion. For example, in merge sort, 'a' would be 2 because it splits into two pieces.
- A
- 3
If a recurrence relation is T(n)=2T(n/2)+O(n), what is the value of 'n to the log base b of a'?
- A
It simplifies to n1, indicating linear growth.
- B
It evaluates to n2, indicating quadratic growth.
- C
It becomes n1/2, indicating square root growth.
- D
It is n0, indicating constant time growth.
Correct answer
AIt simplifies to n1, indicating linear growth.
Explanation
For T(n)=2T(n/2)+O(n), we have a=2 and b=2. Therefore, nlogba becomes nlog22, which simplifies to n1=n.
- A
- 4
Given T(n)=2T(n/2)+O(n), which case of the Master Theorem applies?
- A
Case 3, where f(n) dominates the work.
- B
None of the standard Master Theorem cases are applicable.
- C
Case 2, where f(n) is asymptotically similar to nlogba.
- D
Case 1, where f(n) is upper bounded by nlogba minus an epsilon.
Correct answer
DCase 1, where f(n) is upper bounded by nlogba minus an epsilon.
Explanation
For T(n)=2T(n/2)+O(n), nlogba=nlog22=n1. The function f(n)=O(n)=O(n1/2). We can write n1/2 as O(n1−1/2), where epsilon is 1/2>0. This matches Case 1 of the Master Theorem (f(n)=O(nlogba−ϵ)).
- A
- 5
If f(n)=O(nlogba−ϵ) for some ϵ>0, what is the asymptotic bound for T(n) according to Master Theorem Case 1?
- A
T(n) is Θ(f(n)), meaning f(n) dominates.
- B
T(n) is Θ(nlogbalogkn), with a logarithmic factor.
- C
T(n) is Θ(nlogba+ϵ), for some positive epsilon.
- D
T(n) is Θ(nlogba), indicating tree traversal dominates.
Correct answer
DT(n) is Θ(nlogba), indicating tree traversal dominates.
Explanation
Case 1 of the Master Theorem states that if f(n)=O(nlogba−ϵ) for some positive ϵ, then T(n)=Θ(nlogba). In this case, the work done in dividing and combining (represented by nlogba) dominates the work done at each node (f(n)).
- A
- 6
When solving recurrences by drawing a computation tree, how is the total number of levels in the tree determined?
- A
By the total number of nodes present at the deepest level.
- B
By the value of 'a', the branching factor, at each node.
- C
By the work function 'f(n)' performed at each node.
- D
By the base 'b' of the problem size reduction, usually logbn.
Correct answer
DBy the base 'b' of the problem size reduction, usually logbn.
Explanation
In a computation tree where the problem size is divided by 'b' at each step, the total number of levels is approximately logbn. The recursion stops when the problem size reaches a base case, typically 1.
- A
- 7
For a recurrence T(n)=2T(n/2)+O(n), what is the amount of work done at level l of the computation tree?
- A
It is 2l⋅O(n⋅2−l), considering node count and work.
- B
It is 2l⋅O(n⋅2−l), showing linear growth.
- C
It is O(n), as the total work is constant per level.
- D
It is 2l⋅O(n), as work at each node is proportional to n.
Correct answer
AIt is 2l⋅O(n⋅2−l), considering node count and work.
Explanation
At level l, there are 2l nodes. Each node processes an input of size n/2l. The work done at each node is O(n/2l)=O(n⋅2−l/2). So the total work at level l is 2l⋅O(n⋅2−l/2)=O(n⋅2l/2).
- A
- 8
Which of the following describes the sum of work in a computation tree for a recurrence like T(n)=aT(n/b)+f(n)?
- A
It is always a simple linear sum of terms.
- B
It often simplifies into a logarithmic series.
- C
It usually results in an arithmetic progression of tasks.
- D
It typically forms a geometric series that can be summed.
Correct answer
DIt typically forms a geometric series that can be summed.
Explanation
The sum of work across levels in a computation tree for these types of recurrences often forms a geometric series. Each level's work can be expressed as a term in this series, allowing for a closed-form summation.
- A
- 9
For T(n)=8T(n/4)+O(nn), what is the value of 'n to the log base b of a'?
- A
n3/2, derived from log48.
- B
n1/2, derived from log84.
- C
n2, derived from log48⋅2.
- D
n1, derived from log84⋅2.
Correct answer
An3/2, derived from log48.
Explanation
For T(n)=8T(n/4)+O(nn), we have a=8 and b=4. nlogba becomes nlog48. Since 43/2=(4)3=23=8, log48=3/2. So, the value is n3/2.
- A
- 10
Given T(n)=8T(n/4)+O(nn), which case of the Master Theorem applies?
- A
Case 2, because f(n) is asymptotically equal to nlogba.
- B
Case 3, because f(n) is significantly larger than nlogba.
- C
Case 1, because f(n) is significantly smaller than nlogba.
- D
None, as the terms a and b do not fit the criteria.
Correct answer
ACase 2, because f(n) is asymptotically equal to nlogba.
Explanation
For T(n)=8T(n/4)+O(nn), we found nlogba=n3/2. The work function is f(n)=O(nn)=O(n3/2). Since f(n) is O(n3/2), and the base compares to n3/2, this fits Master Theorem Case 2 with k=0 (as there's no additional logarithmic factor). However, because f(n) is given as 'big O' and not 'big theta', the resulting bound will also be 'big O'.
- A
- 11
What is the asymptotic bound for T(n) for the recurrence T(n)=8T(n/4)+O(nn)?
- A
O(n1/2), due to the square root term.
- B
O(n3/2logn), from Case 2 of Master Theorem.
- C
O(n2), due to the n/4 division.
- D
O(nlogn), if it were merge sort.
Correct answer
BO(n3/2logn), from Case 2 of Master Theorem.
Explanation
This recurrence fits Master Theorem Case 2, where f(n)=O(nlogbalogkn). Here, nlogba=n3/2 and f(n)=O(n3/2). This means k=0. Case 2's result is Θ(nlogbalogk+1n). Since f(n) is an 'O' bound, the result is O(n3/2log0+1n)=O(n3/2logn).
- A
- 12
In the computation tree for T(n)=8T(n/4)+O(nn), how many nodes are at level l?
- A
8l nodes, reflecting the branching factor.
- B
nl nodes, proportional to input size.
- C
4l nodes, reflecting the division factor.
- D
Exactly l nodes, based on the level count.
Correct answer
A8l nodes, reflecting the branching factor.
Explanation
The 'a' term in aT(n/b) indicates the number of recursive calls made at each step, which corresponds to the branching factor. For T(n)=8T(n/4)+O(nn), a=8, so there are 8l nodes at level l.
- A
- 13
For T(n)=8T(n/4)+O(nn), what is the input size for each node at level l?
- A
n/l, as the level determines reduction.
- B
n/8l, as there are 8 children.
- C
n/4l, as the problem size divides by 4.
- D
n/(4⋅8)l, due to combined factors.
Correct answer
Cn/4l, as the problem size divides by 4.
Explanation
The 'b' term in T(n/b) indicates how the problem size is reduced for each subproblem. Here, b=4, so the input size for each node at level l is n/4l.
- A
- 14
What common algorithmic strategy is suggested by a problem requiring logk time to find an item in an unbounded range?
- A
Binary search or bisection method.
- B
Linear scan from the beginning.
- C
Randomized search to quickly converge.
- D
Hashing the potential locations.
Correct answer
ABinary search or bisection method.
Explanation
A time complexity of logk for searching typically indicates the use of binary search or a bisection method, which repeatedly halves the search space. This is highly efficient for ordered data.
- A
- 15
When performing binary search on an unbounded set of planets (e.g., indexed 1, 2, 3...), how can a finite search range be established?
- A
Assume a maximum planet index and search within it.
- B
Start at planet 1 and linearly scan until a bound is found.
- C
Query random planets until the target is located within a known interval.
- D
Incrementally expand the search range by powers of 2 until the target is bracketed.
Correct answer
DIncrementally expand the search range by powers of 2 until the target is bracketed.
Explanation
To apply binary search to an unbounded set, one must first establish a finite upper bound. This is often done by visiting planets at indices like 20,21,22,…,2m until the target planet k is found to be less than or equal to 2m. This process takes O(logk) time, after which a standard binary search can be performed within the range [2m−1,2m].
- A
- 16
After establishing a finite range [L,R] for an unbounded search problem, what is the time complexity of the subsequent binary search?
- A
O(logR), logarithmic with respect to the upper bound.
- B
O(R), directly proportional to the upper bound.
- C
O(1), as the range is now finite and known.
- D
O(R−L), proportional to the size of the range.
Correct answer
AO(logR), logarithmic with respect to the upper bound.
Explanation
Once a finite range [L,R] has been established, a standard binary search can be performed. The time complexity of binary search on a range of size N is O(logN). If R is approximately k, then the search time is O(logk).
- A
- 17
A data structure for image layers needs to support 'import (add on top)' in O(n) and 'move below (reorder)' in O(logn). What combination of data structures would effectively meet these requirements?
- A
A stack for imports and a queue for moves.
- B
An array for imports and a hash table for moves.
- C
A doubly-linked list for ordering and a sorted array/tree of pointers for searching.
- D
Two separate arrays, one for ascending order and one for descending.
Correct answer
CA doubly-linked list for ordering and a sorted array/tree of pointers for searching.
Explanation
The O(n) import time suggests maintaining an explicit sequence (like a linked list) where adding to the top might involve shifting. The O(logn) 'move below' operation, requiring quick element location, points to a balanced binary search tree or sorted array (potentially with a two-finger approach for O(N) overall) that stores pointers to the linked list nodes. A doubly-linked list allows O(1) reordering once the nodes are found.
- A
- 18
Why would attaching pointers from a sorted array/tree to nodes in a doubly-linked list be beneficial for 'move below' operations?
- A
It speeds up adding new elements to the top of the list.
- B
It allows the linked list to be automatically sorted by ID.
- C
It enables O(logn) lookup of specific elements in the linked list.
- D
It reduces the memory footprint of the data structure.
Correct answer
CIt enables O(logn) lookup of specific elements in the linked list.
Explanation
A sorted array or balanced binary search tree allows for O(logn) lookup of an element by its ID. By storing pointers to the actual nodes in the doubly-linked list, once an element's ID is found, its corresponding linked list node can be accessed in O(1) time, facilitating quick reordering.
- A
- 19
What is the time complexity of finding a specific image (by ID) within a doubly-linked list if no auxiliary data structure is used?
- A
O(1), if the head is known.
- B
O(n2), due to potential nested iterations.
- C
O(n), requiring a linear scan through the list.
- D
O(logn), using a binary search approach.
Correct answer
CO(n), requiring a linear scan through the list.
Explanation
In a basic doubly-linked list, finding a specific element by its value (ID) requires traversing the list from the beginning (or end) until the element is found. In the worst case, this takes O(n) time, where n is the number of elements in the list.
- A
- 20
If a linked list element needs to be moved from one position to another, what is the time complexity of the actual splicing and re-linking, assuming pointers to the relevant nodes are already available?
- A
O(1), as only a few pointers need to be updated locally.
- B
O(n), as the entire list might need to be shifted.
- C
O(logn), requiring a search for the new position.
- D
O(nlogn), for complex reordering tasks.
Correct answer
AO(1), as only a few pointers need to be updated locally.
Explanation
In a doubly-linked list, once you have pointers to the node to be moved and its new neighbors, the operation of removing it from its current position and inserting it into a new one involves only updating a constant number of pointers. This makes the actual splicing and re-linking an O(1) operation.
- A
- 21
In the 'brick blowing' problem, the wolf blows houses to the east, and houses with fewer bricks to the east also fall. If the wolf blows on house i, what property must house j (where j>i) have to fall?
- A
House j must be a 'special' house.
- B
House j must have more bricks than house i.
- C
House j must have fewer bricks than house i.
- D
House j must be directly adjacent to house i.
Correct answer
CHouse j must have fewer bricks than house i.
Explanation
The problem states that when the wolf blows on a house, not only does that house fall, but 'also all the houses to the east of that house that have fewer bricks.' This is the critical condition for houses further down the line to fall.
- A
- 22
Consider a sequence of houses with brick counts. If you blow on a house with X bricks, how is the total damage calculated for that house?
- A
It is simply 1, as only the blown house falls.
- B
It is the sum of bricks of all houses to its east.
- C
It is 1 (for the house itself) plus the count of houses to its west with more bricks.
- D
It is 1 (for the house itself) plus the count of houses to its east with fewer bricks.
Correct answer
DIt is 1 (for the house itself) plus the count of houses to its east with fewer bricks.
Explanation
The damage is the house blown (count 1) plus any house to its east (j>i) that has fewer bricks than the blown house (Bricksj<Bricksi). This defines the rule for damage calculation.
- A
- 23
A house in Porkland is 'special' if it has no easterly neighbor or its adjacent easterly neighbor has at least as many bricks. If all but one house is special, what does this imply about the sequence of brick counts?
- A
The sequence increases monotonically until one house, then decreases monotonically.
- B
The sequence forms two segments, each sorted in increasing order.
- C
The sequence is sorted in ascending order, with one exception.
- D
The sequence is completely random, except for one house.
Correct answer
BThe sequence forms two segments, each sorted in increasing order.
Explanation
A 'special' house indicates that Bricksi≤Bricksi+1. If all but one house is special, it means the sequence is generally increasing, with exactly one point where Bricksi>Bricksi+1. This results in two increasing segments, connected at the non-special house (which is the start of the second segment).
- A
- 24
Given the 'special house' condition (all but one house special), if the wolf blows on a house in the first increasing segment (before the decrease), what part of the array can it affect?
- A
Only houses to its west with more bricks.
- B
Only houses in the second increasing segment (to its right).
- C
All houses in the array, regardless of position.
- D
Only houses within its own increasing segment.
Correct answer
BOnly houses in the second increasing segment (to its right).
Explanation
If a house is in the first increasing segment, all houses to its immediate right within that segment will have an equal or greater number of bricks. The rule states only houses with fewer bricks fall. Therefore, only houses in the second (decreasing or later increasing) segment could potentially fall, as these are the only ones to its right that could be smaller.
- A
- 25
To count the damage for each house in O(N) time when the array consists of two increasing segments, which algorithmic technique is most suitable?
- A
Sorting the entire array and then performing a linear scan.
- B
A nested loop, comparing each house to all subsequent houses.
- C
Binary search for each house to find smaller ones to its right.
- D
A two-finger (or two-pointer) algorithm, moving pointers along the array.
Correct answer
DA two-finger (or two-pointer) algorithm, moving pointers along the array.
Explanation
A two-finger (or two-pointer) algorithm is ideal here. Since the left segment's values are increasing, the range of values in the right segment that they can blow over also changes predictably (monotonically). By maintaining one pointer in the left segment and another in the right, both pointers only advance, leading to an O(N) total time complexity.
- A

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