---- SyllabusBuddy ----
___________________________________________
Python MCQs: Data Structures & Searching/Sorting ( UNIT - 5 )
1. Which data structure in Python is best for FIFO (First In First Out)?
a) list
b) stack
c) queue
d) set
Answer: c
Explanation: Queues follow FIFO order; Python’s [Link] is
often used.
2. What is the time complexity of accessing an element in a list by
index?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a
Explanation: List elements are accessed directly by index in constant
time.
3. Which of the following structures automatically eliminates duplicate
entries?
a) list
b) tuple
c) set
d) array
Answer: c
Explanation: Sets in Python are unordered collections of unique elements.
4. What is the result of: len({1, 2, 3, 3, 2})?
a) 5
b) 3
c) 4
d) Error
Answer: b
Explanation: Sets remove duplicates; result is {1, 2, 3}.
5. Which module provides a stack implementation in Python?
a) queue
b) stacklib
c) collections
d) threading
Answer: a
Explanation: Python’s [Link] provides stack behavior.
6. What is the default behavior of a [Link]() method?
a) Removes first element
b) Removes last element
c) Clears the list
d) Returns index
Answer: b
Explanation: pop() removes and returns the last element by default.
7. Which search technique compares each element sequentially?
a) Binary search
b) Linear search
c) Hash search
d) Tree search
Answer: b
Explanation: Linear search goes through each element in sequence.
8. Which sorting algorithm is best suited for nearly sorted data?
a) Bubble sort
b) Selection sort
c) Insertion sort
d) Merge sort
Answer: c
Explanation: Insertion sort performs efficiently on nearly sorted lists.
9. Which algorithm has O(n log n) time complexity in the average case?
a) Bubble sort
b) Selection sort
c) Merge sort
d) Linear search
Answer: c
Explanation: Merge sort has consistent O(n log n) performance.
10. What is the best case time complexity of binary search?
a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
Answer: a
Explanation: Best case occurs when the target is at the middle index.
11. Which Python module offers efficient arrays of numeric values?
a) lists
b) arrays
c) array
d) collections
Answer: c
Explanation: The array module in Python handles numeric data efficiently.
12. What does the append() method do to a list?
a) Adds item to start
b) Replaces last item
c) Adds item to end
d) Returns last item
Answer: c
Explanation: append() adds an element to the end of a list.
13. Which of the following is mutable?
a) tuple
b) string
c) list
d) int
Answer: c
Explanation: Lists are mutable; others are immutable types.
14. What is the output of: sorted([3, 1, 2])?
a) [3, 1, 2]
b) [2, 1, 3]
c) [1, 2, 3]
d) (1, 2, 3)
Answer: c
Explanation: sorted() returns a new sorted list.
15. Which method removes all elements from a list?
a) remove()
b) del()
c) pop()
d) clear()
Answer: d
Explanation: clear() empties the list.
16. What is the time complexity of inserting an element at the beginning
of a list?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: c
Explanation: Elements need to be shifted, making it O(n).
17. Which search algorithm needs the list to be sorted?
a) Linear search
b) Jump search
c) Binary search
d) Hash search
Answer: c
Explanation: Binary search only works on sorted data.
18. Which sort algorithm selects the smallest value and swaps it forward?
a) Bubble sort
b) Merge sort
c) Selection sort
d) Quick sort
Answer: c
Explanation: Selection sort places the smallest element in place.
19. What is the output of set("hello")?
a) {'h', 'e', 'l', 'o'}
b) {'hello'}
c) ['h', 'e', 'l', 'o']
d) Error
Answer: a
Explanation: A set is created with unique characters.
20. What is a stack overflow?
a) Too many pushes
b) Stack underflow
c) Exceeding stack limit
d) Stack cleared
Answer: c
Explanation: Stack overflow occurs when memory is exceeded due to deep
recursion or excessive stacking.
21. Which of the following is true about bubble sort?
a) It's the fastest sort
b) It compares adjacent elements
c) It requires recursion
d) It uses divide and conquer
Answer: b
Explanation: Bubble sort compares and swaps adjacent elements.
22. Which function adds an item to a set?
a) insert()
b) append()
c) add()
d) push()
Answer: c
Explanation: Sets use add() to include new elements.
23. How is a queue implemented in Python efficiently?
a) list
b) tuple
c) array
d) deque
Answer: d
Explanation: [Link] supports efficient queue operations.
24. What happens in insertion sort at each iteration?
a) Swap max and min
b) Insert element into sorted part
c) Recurse list
d) Find middle
Answer: b
Explanation: It inserts the current element into the sorted portion.
25. Which structure is suitable for LIFO order?
a) Queue
b) List
c) Stack
d) Set
Answer: c
Explanation: Stacks use LIFO ordering.
26. What is the worst-case time of bubble sort?
a) O(n log n)
b) O(n^2)
c) O(n)
d) O(log n)
Answer: b
Explanation: Bubble sort compares adjacent elements repeatedly.
27. How many comparisons in binary search (worst case) for 32 elements?
a) 5
b) 6
c) 32
d) 16
Answer: b
Explanation: log₂(32) = 5, worst case is 6 comparisons.
28. Which data structure is best for unique values and fast lookup?
a) List
b) Array
c) Set
d) Stack
Answer: c
Explanation: Sets are optimized for uniqueness and lookup.
29. Which method checks if a value exists in a list?
a) contains()
b) find()
c) in
d) search()
Answer: c
Explanation: in is used for membership testing.
30. What is the output of list("abc")?
a) ['abc']
b) ['a', 'b', 'c']
c) {'a', 'b', 'c'}
d) ('a', 'b', 'c')
Answer: b
Explanation: Converts string to list of characters.
31. What does [Link]() do in [Link]()?
a) Removes front item
b) Adds item
c) Checks size
d) Returns last item
Answer: a
Explanation: get() removes item from front of queue.
32. What is the time complexity of binary search?
a) O(n)
b) O(log n)
c) O(n^2)
d) O(1)
Answer: b
Explanation: Each step halves the search space.
33. Which sorting technique swaps adjacent items if out of order?
a) Bubble sort
b) Selection sort
c) Insertion sort
d) Binary sort
Answer: a
34. Which structure is not ordered in Python?
a) List
b) Tuple
c) Set
d) String
Answer: c
35. What will a = [1,2]; b = a; b[0]=0; print(a) output?
a) [0, 2]
b) [1, 2]
c) Error
d) None
Answer: a
36. Which of the following is true about selection sort?
a) Uses recursion
b) Stable sort
c) Always makes O(n^2) comparisons
d) Fastest for all data
Answer: c
37. Which is not a valid list operation?
a) append()
b) push()
c) insert()
d) remove()
Answer: b
38. What is returned by [Link](x)?
a) Number of x
b) Position of x
c) Length of list
d) Nothing
Answer: b
39. Which function removes a value from a list by index?
a) pop()
b) remove()
c) discard()
d) del()
Answer: a
40. Which sorting method requires shifting of elements on each insert?
a) Bubble
b) Selection
c) Insertion
d) Merge
Answer: c
41. Which data structure is best for fast insertion and deletion at both
ends?
a) list
b) array
c) deque
d) set
Answer: c
42. How many comparisons in linear search worst case for 20 elements?
a) 20
b) 10
c) 5
d) 1
Answer: a
43. What happens if you search an item not in list using .index()?
a) -1
b) None
c) Error
d) 0
Answer: c
44. What does reverse() do on a list?
a) Sorts descending
b) Reverses elements in place
c) Removes last item
d) Nothing
Answer: b
45. Which method creates a copy of a list?
a) clone()
b) copy()
c) duplicate()
d) new()
Answer: b
46. Which of these algorithms is not comparison-based?
a) Bubble sort
b) Radix sort
c) Merge sort
d) Selection sort
Answer: b
47. Which module supports priority queues?
a) heapq
b) queue
c) priority
d) stacklib
Answer: a
48. Which function in Python returns the number of elements in a
structure?
a) count()
b) size()
c) len()
d) index()
Answer: c
49. What is the main drawback of bubble sort?
a) Complexity
b) Code size
c) Accuracy
d) Memory
Answer: a
50. What is the average case complexity of selection sort?
a) O(n log n)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: d
---- SyllabusBuddy ----
___________________________________________
SyllabusBuddy is your ultimate hub for chapter-wise study materials,
including PDFs, DOCs, and TXT files of MCQs, objectives, previous year
papers, and sample papers.
Get simplified, organized academic content for easy exam preparation —
download all study resources by subject and chapter at SyllabusBuddy.