(Units 1-7) - Questions with Correct Answers
100 questions
1. Big-O analysis helps a developer:
A. Choose variable names
B. Format output
C. Predict how a program will scale as data grows
D. Write comments
Correct Answer: C. Predict how a program will scale as data grows
Rationale: Scalability.
2. Two nested loops that each run n times give a complexity of:
A. O(n)
B. O(2n)
C. O(n^2)
D. O(log n)
Correct Answer: C. O(n^2)
Rationale: n times n.
3. Linear search on an unsorted list of n items has worst-case complexity:
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Correct Answer: B. O(n)
Rationale: May check every item.
4. Empirical performance testing complements Big-O because it:
A. Replaces analysis
B. Measures actual running times on real hardware and data
C. Ignores input size
D. Is always identical
Correct Answer: B. Measures actual running times on real hardware and data
Rationale: Benchmarking.
5. Average-case complexity of linear search is:
A. O(1)
B. O(log n)
C. O(n^2)
D. O(n)
Correct Answer: D. O(n)
Rationale: About n/2 comparisons.
6. If an algorithm takes 1 second for n = 1,000 and is O(n^2), approximately how long for n =
2,000?
A. 2 seconds
B. 4 seconds
C. 8 seconds
D. 1 second
Correct Answer: B. 4 seconds
Rationale: Doubling n quadruples time.
,7. Amortized analysis is used to describe:
A. Average cost per operation over a sequence, e.g., list append is amortized O(1)
B. The worst single operation only
C. Memory leaks
D. Network latency
Correct Answer: A. Average cost per operation over a sequence, e.g., list append is amortized
O(1)
Rationale: Occasional resizing averaged out.
8. Checking whether a key exists in a Python dict has average complexity:
A. O(n)
B. O(log n)
C. O(n^2)
D. O(1)
Correct Answer: D. O(1)
Rationale: Hash-based.
9. Which describes O(1)?
A. Running time doubles with n
B. Running time does not depend on input size
C. Running time grows logarithmically
D. Running time is zero
Correct Answer: B. Running time does not depend on input size
Rationale: Constant time.
10. The time complexity of accessing an element by index in a Python list is:
A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
Correct Answer: C. O(1)
Rationale: Lists are dynamic arrays.
11. An algorithm is said to be scalable if:
A. It continues to perform acceptably as input size grows
B. It only works for small inputs
C. It uses global variables
D. It has no comments
Correct Answer: A. It continues to perform acceptably as input size grows
Rationale: Growth behavior.
12. Calling a function that is O(n) inside a loop that runs n times gives:
A. O(n)
B. O(2n)
C. O(log n)
D. O(n^2)
Correct Answer: D. O(n^2)
Rationale: Multiply nested costs.
, 13. A triple nested loop over n items each is:
A. O(n^2)
B. O(3n)
C. O(n log n)
D. O(n^3)
Correct Answer: D. O(n^3)
Rationale: Cubic.
14. Python's built-in sort algorithm is:
A. Bubble sort
B. Timsort
C. Quick sort only
D. Selection sort
Correct Answer: B. Timsort
Rationale: Hybrid merge/insertion.
15. Big-Theta notation describes:
A. Only the upper bound
B. A tight bound (both upper and lower)
C. Only the lower bound
D. Constant time
Correct Answer: B. A tight bound (both upper and lower)
Rationale: Exact growth class.
16. Using ''.join(list_of_strings) is efficient because it:
A. Hashes strings
B. Sorts strings
C. Copies twice
D. Builds the result in one pass
Correct Answer: D. Builds the result in one pass
Rationale: Linear time.
17. A truck traveling 18 mph covers 4.5 miles in:
A. 15 minutes
B. 25 minutes
C. 4.5 minutes
D. 45 minutes
Correct Answer: A. 15 minutes
Rationale: 4.5/18 = 0.25 hour.
18. Python dictionary keys must be:
A. Lists
B. Any mutable object
C. Dictionaries
D. Hashable (immutable types such as strings, numbers or tuples of immutables)
Correct Answer: D. Hashable (immutable types such as strings, numbers or tuples of
immutables)
Rationale: Hash requirement.