chapter 6: Searching — Online MCQ Test
COMPUTER SCIENCE · Grade 12 · CBSE(NCERT)
Practice chapter 6: Searching with a free chapter-wise online MCQ test.
This chapter covers: linear search - binary search.
AI-generated questions from basic to board-exam level, with instant results and explanations.
chapter 6: Searching — Important Questions & Answers
Which searching technique checks each element of a list one by one until the required value is found?
- A. Linear search
- B. Binary search
- C. Bubble search
- D. Index search
Answer: A. Linear search
Linear search compares the target value with each element sequentially until a match is found or the list ends.
Linear search compares the target value with each element sequentially until a match is found or the list ends.
Binary search can be applied directly only when the data is:
- A. Unsorted
- B. Sorted
- C. Stored only as strings
- D. Stored only in a dictionary
Answer: B. Sorted
Binary search works by repeatedly dividing the search space into halves, which is possible only when the list is sorted.
Binary search works by repeatedly dividing the search space into halves, which is possible only when the list is sorted.
In linear search, if the element is found at the first position, the case is called:
- A. Worst case
- B. Average case
- C. Best case
- D. Invalid case
Answer: C. Best case
The best case for linear search occurs when the target element is the first element checked.
The best case for linear search occurs when the target element is the first element checked.
What is the worst-case time complexity of linear search for a list of n elements?
- A. O(1)
- B. O(log n)
- C. O(n)
- D. O(n log n)
Answer: C. O(n)
In the worst case, linear search may have to check all n elements of the list.
In the worst case, linear search may have to check all n elements of the list.
A list contains [12, 25, 37, 44, 59]. If linear search is used to find 44, how many comparisons are needed?
- A. 2
- B. 3
- C. 4
- D. 5
Answer: C. 4
Linear search compares 44 with 12, 25, 37, and then 44, so 4 comparisons are required.
Linear search compares 44 with 12, 25, 37, and then 44, so 4 comparisons are required.
For the sorted list [5, 10, 15, 20, 25, 30, 35], what is the first middle element checked while searching for 25 using binary search?
- A. 10
- B. 15
- C. 20
- D. 25
Answer: C. 20
With indices 0 to 6, the middle index is (0 + 6) // 2 = 3, so the first middle element is 20.
With indices 0 to 6, the middle index is (0 + 6) // 2 = 3, so the first middle element is 20.
A sorted list has 16 elements. In the worst case, approximately how many comparisons are needed by binary search?
- A. 2
- B. 4
- C. 16
- D. 32
Answer: B. 4
Binary search takes about log2(n) comparisons; for 16 elements, log2(16) = 4 in the worst-case approximation.
Binary search takes about log2(n) comparisons; for 16 elements, log2(16) = 4 in the worst-case approximation.
Which of the following situations makes binary search unsuitable without preprocessing?
- A. Searching a sorted list of marks
- B. Searching an unsorted list of names
- C. Searching a sorted list of roll numbers
- D. Searching a sorted list of ages
Answer: B. Searching an unsorted list of names
Binary search requires sorted data, so an unsorted list must be sorted before applying binary search.
Binary search requires sorted data, so an unsorted list must be sorted before applying binary search.
For the sorted list [4, 8, 12, 16, 20, 24, 28, 32, 36], binary search is used to find 30. Which middle elements are checked before concluding not found?
- A. 20, 28, 32
- B. 20, 32, 28
- C. 4, 8, 12, 16, 20, 24, 28, 32, 36
- D. 16, 24, 32
Answer: A. 20, 28, 32
First 20 is checked, then the right half gives 28, and then 32. After that the search interval becomes empty, so 30 is not found.
First 20 is checked, then the right half gives 28, and then 32. After that the search interval becomes empty, so 30 is not found.
A list contains duplicate values: [5, 10, 10, 10, 15, 20]. If standard binary search is used to search for 10, which statement is most accurate?
- A. It will always return the first occurrence of 10.
- B. It will always return the last occurrence of 10.
- C. It may return any one occurrence of 10 depending on the mid positions checked.
- D. It cannot find duplicate values at all.
Answer: C. It may return any one occurrence of 10 depending on the mid positions checked.
A standard binary search stops when it finds a match, so with duplicates it may return whichever matching index is encountered first.
A standard binary search stops when it finds a match, so with duplicates it may return whichever matching index is encountered first.