Questions with Correct Answers
100 questions
1. If f(n) = 100n and g(n) = n^2, for large n:
A. f grows faster than g
B. They grow equally
C. g grows faster than f
D. Neither grows
Correct Answer: C. g grows faster than f
Rationale: Quadratic dominates.
2. An algorithm that processes each pair of n items once has complexity about:
A. O(n^2)
B. O(n)
C. O(log n)
D. O(1)
Correct Answer: A. O(n^2)
Rationale: n(n-1)/2 pairs.
3. Computing the distance between every pair of n delivery locations requires about:
A. O(n) operations
B. O(log n) operations
C. O(1) operations
D. O(n^2) operations
Correct Answer: D. O(n^2) operations
Rationale: Distance matrix.
4. Sequential (not nested) loops of n and m iterations give:
A. O(n * m)
B. O(n + m)
C. O(n^m)
D. O(1)
Correct Answer: B. O(n + m)
Rationale: Add sequential costs.
5. Which is NOT polynomial time?
A. O(2^n)
B. O(n^3)
C. O(n log n)
D. O(n)
Correct Answer: A. O(2^n)
Rationale: Exponential.
6. Binary search on a sorted list has worst-case complexity:
A. O(n)
B. O(1)
C. O(n^2)
D. O(log n)
Correct Answer: D. O(log n)
Rationale: Halves the search space.
,7. Sorting a list with Python's built-in sorted() has worst-case complexity:
A. O(n log n)
B. O(n)
C. O(n^2)
D. O(1)
Correct Answer: A. O(n log n)
Rationale: Timsort.
8. Which operation on a Python dict is O(n)?
A. Getting a value by key
B. Setting a value by key
C. Iterating over all keys
D. Checking key existence
Correct Answer: C. Iterating over all keys
Rationale: Visiting every item.
9. Creating a Package class with attributes like ID, address, deadline and status is an example
of:
A. Recursion
B. Object-oriented modeling
C. Sorting
D. Hashing
Correct Answer: B. Object-oriented modeling
Rationale: Modeling domain entities.
10. A Python function is defined with:
A. func
B. def
C. function
D. lambda only
Correct Answer: B. def
Rationale: Syntax.
11. Reading a CSV file in Python is commonly done with:
A. The csv module
B. The os.system function only
C. The math module
D. The random module
Correct Answer: A. The csv module
Rationale: csv.reader.
12. PEP 8 is:
A. A sorting algorithm
B. Python's style guide
C. A data structure
D. A Python version
Correct Answer: B. Python's style guide
Rationale: Readability conventions.
, 13. A Python set:
A. Allows duplicates
B. Stores key-value pairs
C. Is immutable always
D. Stores unique elements without order
Correct Answer: D. Stores unique elements without order
Rationale: Uniqueness.
14. A lambda in Python is:
A. A loop
B. A class
C. An anonymous single-expression function
D. A module
Correct Answer: C. An anonymous single-expression function
Rationale: Often used as sort keys.
15. Python's 'is' operator checks:
A. Value equality
B. Type equality
C. Hash equality
D. Whether two references point to the same object
Correct Answer: D. Whether two references point to the same object
Rationale: Identity.
16. A Python list is implemented as:
A. A linked list
B. A dynamic array
C. A binary tree
D. A hash table
Correct Answer: B. A dynamic array
Rationale: Contiguous references.
17. A hash table does NOT efficiently support:
A. Lookup by key
B. Insertion by key
C. Retrieving items in sorted key order
D. Deletion by key
Correct Answer: C. Retrieving items in sorted key order
Rationale: Unordered.
18. Primary clustering is a problem of:
A. Chaining
B. Linear probing
C. Binary search
D. Heaps
Correct Answer: B. Linear probing
Rationale: Long runs of filled slots.