MIT Programming Fundamentals Review
- 29Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What are the two primary reasons for studying algorithm efficiency according to the lecture?
What are the two primary reasons for studying algorithm efficiency according to the lecture?
29 questions
- 1
What are the two primary reasons for studying algorithm efficiency according to the lecture?
- A
To reduce code length and to improve readability
- B
To pass exams and to impress employers
- C
To compare different programming languages and to optimize memory usage
- D
To predict runtime on large inputs and to understand how design choices affect time
Correct answer
DTo predict runtime on large inputs and to understand how design choices affect time
Explanation
The lecturer states two reasons: first, to predict how much time an algorithm will need for a problem of a particular size; second, to understand how design choices influence runtime.
- A
- 2
According to the lecture, what trade-off is often present in algorithm design?
- A
A trade-off between using lists and dictionaries
- B
A trade-off between using recursion and iteration
- C
A trade-off between code simplicity and code correctness
- D
A trade-off between time efficiency and space efficiency
Correct answer
DA trade-off between time efficiency and space efficiency
Explanation
The lecture mentions that there is often a trade-off between time and space, and that dictionaries provide an example where pre-computing and storing values reduces time at the cost of memory.
- A
- 3
Why does algorithm efficiency remain important despite faster computers?
- A
Because problem sizes are growing rapidly, such as data sets on the web
- B
Because computers are becoming slower due to overheating
- C
Because users demand real-time responses regardless of problem size
- D
Because programming languages are becoming less efficient
Correct answer
ABecause problem sizes are growing rapidly, such as data sets on the web
Explanation
The lecturer argues that data sets are growing massively (e.g., Google serving 30 trillion pages), so even with faster computers, efficient algorithms are needed to handle large inputs.
- A
- 4
What is the primary focus when measuring efficiency in this lecture?
- A
Time efficiency
- B
Code readability
- C
Space efficiency
- D
Number of lines of code
Correct answer
ATime efficiency
Explanation
The lecturer says efficiency refers to both space and time, but primarily to time.
- A
- 5
Which of the following is a challenge with using timing to evaluate algorithm efficiency?
- A
Timing only works for very small inputs
- B
Timing cannot measure the number of operations
- C
Timing depends on implementation and the specific computer used
- D
Timing requires specialized hardware
Correct answer
CTiming depends on implementation and the specific computer used
Explanation
The lecturer notes that timing varies with implementation and computer hardware, and it may not predict performance on large inputs due to factors like memory access.
- A
- 6
What is the main advantage of counting operations over timing?
- A
Counting operations is independent of the computer's speed
- B
Counting operations gives exact runtime in seconds
- C
Counting operations eliminates the effect of algorithm design
- D
Counting operations is easier to automate
Correct answer
ACounting operations is independent of the computer's speed
Explanation
Counting operations abstracts away the computer's speed and focuses on the number of operations, which is independent of the machine.
- A
- 7
What drawback does counting operations still have according to the lecture?
- A
It is not affected by the size of the input
- B
It cannot be done for recursive algorithms
- C
It requires knowledge of assembly language
- D
It depends slightly on implementation details
Correct answer
DIt depends slightly on implementation details
Explanation
The lecturer shows that using a while loop instead of a for loop can change the operation count (e.g., 3x vs 4x per iteration), so it still depends on implementation.
- A
- 8
What method does the lecturer recommend for evaluating algorithm efficiency?
- A
Orders of growth / Big O notation
- B
Timing with a stopwatch
- C
Measuring memory usage
- D
Counting operations exactly
Correct answer
AOrders of growth / Big O notation
Explanation
The lecturer introduces orders of growth and Big O notation as a way to abstract away constants and implementation details, focusing on asymptotic behavior.
- A
- 9
What does 'order of growth' refer to in algorithm analysis?
- A
The exact number of operations an algorithm performs
- B
The growth of the computer's memory over time
- C
How the runtime grows as the input size increases
- D
The order of lines in the code
Correct answer
CHow the runtime grows as the input size increases
Explanation
The lecturer defines orders of growth as a way to express the growth of the program's runtime as the input size grows.
- A
- 10
In Big O notation, what do we typically ignore?
- A
The worst-case behavior
- B
The algorithm's correctness
- C
The input size
- D
Additive and multiplicative constants
Correct answer
DAdditive and multiplicative constants
Explanation
The lecturer states that we ignore additive and multiplicative constants to focus on the dominant term, which determines the asymptotic growth.
- A
- 11
When analyzing algorithms, which case do we usually focus on?
- A
Average-case
- B
Random-case
- C
Best-case
- D
Worst-case
Correct answer
DWorst-case
Explanation
The lecturer says we focus on the worst-case behavior because it gives an upper bound on the runtime.
- A
- 12
What does the law of addition state for sequential code blocks?
- A
The overall order of growth is the product of the individual orders
- B
The overall order of growth is the maximum of the individual orders
- C
The overall order of growth is the sum of the individual orders
- D
The overall order of growth is the average of the individual orders
Correct answer
BThe overall order of growth is the maximum of the individual orders
Explanation
The lecturer illustrates that for sequential pieces, the overall order of growth is the larger one (e.g., O(n) + O(n^2) = O(n^2)).
- A
- 13
What does the law of multiplication state for nested structures?
- A
The overall order of growth is the maximum of the individual orders
- B
The overall order of growth is the sum of the individual orders
- C
The overall order of growth is the product of the individual orders
- D
The overall order of growth is the difference of the individual orders
Correct answer
CThe overall order of growth is the product of the individual orders
Explanation
The lecturer explains that nested loops multiply the orders: outer loop O(n) and inner O(n) gives O(n^2).
- A
- 14
Which of the following is the correct order of growth from slowest (best) to fastest (worst)?
- A
O(log n), O(1), O(n), O(n^2), O(2^n)
- B
O(2^n), O(n^2), O(n log n), O(n), O(log n), O(1)
- C
O(1), O(log n), O(n), O(n log n), O(n^2), O(2^n)
- D
O(n), O(1), O(log n), O(2^n), O(n^2)
Correct answer
CO(1), O(log n), O(n), O(n log n), O(n^2), O(2^n)
Explanation
The lecture lists complexity classes in order: constant, logarithmic, linear, log-linear, quadratic, exponential.
- A
- 15
An algorithm that runs in constant time has which Big O?
- A
O(log n)
- B
O(n)
- C
O(1)
- D
O(n^2)
Correct answer
CO(1)
Explanation
Constant time means the runtime does not depend on the input size, denoted O(1).
- A
- 16
Which complexity class grows slower than linear but faster than constant?
- A
O(n log n)
- B
O(1)
- C
O(log n)
- D
O(n)
Correct answer
CO(log n)
Explanation
Logarithmic growth is slower than linear and faster than constant, as shown in the complexity class hierarchy.
- A
- 17
For an O(n^2) algorithm, if the input size doubles, the runtime increases by approximately a factor of:
- A
2
- B
It depends on the constant
- C
4
- D
1
Correct answer
C4
Explanation
Quadratic growth means doubling n multiplies the runtime by 4, since (2n)^2 = 4n^2.
- A
- 18
The lecturer states that exponential complexity is much worse than which of the following?
- A
O(n)
- B
O(log n)
- C
O(n^2)
- D
All of the above
Correct answer
DAll of the above
Explanation
Exponential is worse than all polynomial and logarithmic complexities; the lecture shows exponential quickly outgrows quadratic and linear.
- A
- 19
What is the order of growth of the iterative factorial function presented in the lecture?
- A
O(log n)
- B
O(n)
- C
O(1)
- D
O(n^2)
Correct answer
BO(n)
Explanation
The factorial function uses a single loop from n down to 1, with constant work per iteration, so it is O(n).
- A
- 20
In the linear search algorithm for an unsorted list, what is the worst-case order of growth?
- A
O(log n)
- B
O(n) where n is the length of the list
- C
O(n^2)
- D
O(1)
Correct answer
BO(n) where n is the length of the list
Explanation
In the worst case, the element is not in the list and the algorithm examines every element, so O(n).
- A
- 21
Even if a list is sorted, the linear search algorithm still has what worst-case order of growth?
- A
O(1)
- B
O(n^2)
- C
O(n)
- D
O(log n)
Correct answer
CO(n)
Explanation
The lecturer explains that although sorted list allows early exit, the worst case still requires checking all elements, so O(n).
- A
- 22
According to the lecture, accessing the i-th element of a list in Python takes what amount of time?
- A
Constant time O(1)
- B
Linear time O(n)
- C
Logarithmic time O(log n)
- D
Quadratic time O(n^2)
Correct answer
AConstant time O(1)
Explanation
The lecturer explains that due to indirection, any element can be accessed in constant time by computing the address base + i*size.
- A
- 23
The 'is subset' algorithm using nested loops has what order of growth if both lists have length n?
- A
O(n^2)
- B
O(log n)
- C
O(1)
- D
O(n)
Correct answer
AO(n^2)
Explanation
Outer loop runs n times, inner loop runs up to n times, so O(n^2).
- A
- 24
The 'intersection' algorithm presented has what overall order of growth?
- A
O(n^2)
- B
O(n log n)
- C
O(2^n)
- D
O(n)
Correct answer
AO(n^2)
Explanation
The lecture states that both the nested loop and the cleanup loop are quadratic, so overall O(n^2).
- A
- 25
In the simple iterative loop for summing digits of a string, the order of growth is:
- A
O(1)
- B
O(log n)
- C
O(n) where n is the length of the string
- D
O(n^2)
Correct answer
CO(n) where n is the length of the string
Explanation
The lecturer shows a loop over each character with constant work, so O(n).
- A
- 26
Which of the following is a primitive operation assumed to take constant time?
- A
Arithmetic operations, comparisons, assignments, and memory access
- B
Loop iterations
- C
String concatenation
- D
Function calls
Correct answer
AArithmetic operations, comparisons, assignments, and memory access
Explanation
The lecturer defines primitive operations as arithmetic, comparisons, assignments, and retrieval from memory, all assumed constant.
- A
- 27
What does the lecturer say about the relationship between timing and algorithm evaluation?
- A
Timing works well for all types of algorithms
- B
Timing is independent of the computer used
- C
Timing confounds implementation effects with algorithm effects
- D
Timing is the only accurate way to measure efficiency
Correct answer
CTiming confounds implementation effects with algorithm effects
Explanation
Timing varies with implementation and computer, making it hard to isolate algorithm efficiency.
- A
- 28
Why do we focus on the worst case in Big O analysis?
- A
It is the easiest to compute
- B
It is the only one that matters for small inputs
- C
It provides an upper bound on runtime
- D
It always happens in practice
Correct answer
CIt provides an upper bound on runtime
Explanation
The worst case gives a guarantee on the maximum time, which is useful for ensuring performance.
- A
- 29
What is an example of an algorithm that runs in logarithmic time?
- A
Binary search on a sorted list
- B
Nested loops for subset check
- C
Iterative factorial
- D
Linear search on an unsorted list
Correct answer
ABinary search on a sorted list
Explanation
Although not explicitly in the lecture, binary search is a classic O(log n) algorithm; the lecture mentions log n as a complexity class.
- A

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