Questions with Correct Answers
100 questions
1. A function that calls itself twice per call with input n-1 (like naive Fibonacci) has complexity
about:
A. O(n)
B. O(2^n)
C. O(log n)
D. O(n^2)
Correct Answer: B. O(2^n)
Rationale: Exponential recursion tree.
2. The lower bound for comparison-based sorting in the worst case is:
A. Omega(n)
B. Omega(n log n)
C. Omega(1)
D. Omega(n^2)
Correct Answer: B. Omega(n log n)
Rationale: Decision-tree argument.
3. Space complexity of storing an n x n distance matrix is:
A. O(n)
B. O(1)
C. O(n^2)
D. O(log n)
Correct Answer: C. O(n^2)
Rationale: n squared cells.
4. Checking whether an item exists in a Python list using 'in' has complexity:
A. O(n)
B. O(1)
C. O(log n)
D. O(n log n)
Correct Answer: A. O(n)
Rationale: Linear scan.
5. An in-place algorithm uses:
A. O(n^2) memory
B. Unlimited memory
C. Only disk storage
D. O(1) or very little extra memory
Correct Answer: D. O(1) or very little extra memory
Rationale: Modifies input directly.
6. Big-Omega notation describes:
A. An upper bound
B. The average only
C. A lower bound on growth rate
D. Memory size
Correct Answer: C. A lower bound on growth rate
Rationale: Best-case style bound.
,7. Removing the first element of a Python list with pop(0) is:
A. O(1)
B. O(log n)
C. O(n)
D. O(n^2)
Correct Answer: C. O(n)
Rationale: Shifts elements; use deque instead.
8. Best-case complexity of linear search is:
A. O(n)
B. O(log n)
C. O(n^2)
D. O(1)
Correct Answer: D. O(1)
Rationale: Item at first position.
9. Using an Enum or constants for package status values ('At hub', 'En route', 'Delivered')
improves:
A. Speed only
B. Memory only
C. Nothing
D. Readability and reduces typos
Correct Answer: D. Readability and reduces typos
Rationale: Maintainability.
10. Which data structure is best for a FIFO queue in Python?
A. collections.deque
B. list with pop(0)
C. dict
D. set
Correct Answer: A. collections.deque
Rationale: O(1) popleft.
11. The datetime and timedelta classes are useful for:
A. Hashing
B. Sorting strings
C. Tracking times such as truck departure and delivery times
D. Drawing graphs
Correct Answer: C. Tracking times such as truck departure and delivery times
Rationale: Time arithmetic.
12. Integer division in Python 3 uses the operator:
A. /
B. //
C. %
D. **
Correct Answer: B. //
Rationale: Floor division.
, 13. To look up the distance between address index i and j in a lower-triangular matrix, you
should:
A. Check both [i][j] and [j][i] because only one may be filled
B. Use only [i][j] always
C. Add i and j
D. Sort the matrix first
Correct Answer: A. Check both [i][j] and [j][i] because only one may be filled
Rationale: Symmetric distances.
14. The time complexity of list.remove(value) is:
A. O(1)
B. O(log n)
C. O(n)
D. O(n^2)
Correct Answer: C. O(n)
Rationale: Search and shift.
15. The __init__ method in a Python class is:
A. The constructor that initializes a new object
B. A destructor
C. A static variable
D. A loop
Correct Answer: A. The constructor that initializes a new object
Rationale: Initializer.
16. A Python module is:
A. A class only
B. A file containing Python definitions and statements
C. A variable
D. A loop
Correct Answer: B. A file containing Python definitions and statements
Rationale: Organizes code.
17. Quadratic probing checks slots at offsets of:
A. 1, 2, 3, 4
B. Random
C. 1, 4, 9, 16, ... from the original index
D. Doubling powers of 10
Correct Answer: C. 1, 4, 9, 16, ... from the original index
Rationale: Reduces primary clustering.
18. Using only the string length as a hash for addresses would cause:
A. No collisions
B. Perfect distribution
C. Faster lookups always
D. Many collisions
Correct Answer: D. Many collisions
Rationale: Poor distribution.