MBOSE Class XII Computer Science · Chapter 6
Searching
Opening soonHow computers find an item in a list, from checking one by one to the faster binary search, and how hashing finds things almost instantly.
13 lessons · 56 practice questions · unit "Computational Thinking and Programming" carries 40 marks
What this chapter covers
- Searching
- Linear (sequential) search — algorithm, program, comparisons
- Binary search — algorithm, iterative and recursive programs, iterations
- Search by hashing — hash function, remainder method, hash table, collision
Key terms
- Key
Element being searched for
- Linear search
Checking elements one by one
- Binary search
Repeatedly halving a sorted list around its middle element
- Iteration
One pass of the search loop
- Hashing
Finding the position of a key directly by a formula
- Hash function
Formula that gives the index for an element
- Hash table
List storing elements at their hash indices
- Collision
Two elements with the same hash value
Important questions with answers
10 of the 56 questions on this chapter, solved.
Question 1 · Multiple choice · 1 mark
Linear search checks
- (a) the elements one by one
- (b) only the middle element
- (c) the hash index
- (d) only the last element
Answer: (a) the elements one by one
From the first element onwards.
Question 2 · Multiple choice · 1 mark
How many comparisons does linear search make for 25 in [10, 20, 30]?
- (a) 1
- (b) 2
- (c) 0
- (d) 3
Answer: (d) 3
All elements are checked.
Question 3 · Multiple choice · 1 mark
The complexity of binary search is
- (a) O(log n)
- (b) O(n)
- (c) O(n²)
- (d) O(1)
Answer: (a) O(log n)
The range halves each step.
Question 4 · Multiple choice · 1 mark
In the remainder method, h(x) is
- (a) x % size
- (b) x // size
- (c) x * size
- (d) x + size
Answer: (a) x % size
size = size of the hash table.
Question 5 · Assertion and reason · 1 mark
Assertion (A): Binary search is faster than linear search on large sorted lists.
Reason (R): It halves the search range in each step.
- (a) Both A and R are true, and R is the correct explanation of A.
- (b) Both A and R are true, but R is not the correct explanation of A.
- (c) A is true, but R is false.
- (d) A is false, but R is true.
Answer: (a) Both A and R are true, and R is the correct explanation of A.
O(log n) against O(n).
Question 6 · Short answer · 2 marks
Define searching.
Answer
Finding whether a key is present in a collection and its position.
Question 7 · Short answer · 2 marks
Why is mid computed as (first + last) // 2?
Answer
To get the integer index of the middle element.
Question 8 · Short answer · 3 marks
How can collisions be resolved?
Answer
By placing the element in the next free position (linear probing) or keeping a list at each index (chaining).
Question 9 · Long answer · 5 marks
Explain linear search with an algorithm and a program.
Answer
Section 1.2; Section 8.2 (HSSLC 2020, Q6(b) (second choice)).
Question 10 · Long answer · 5 marks
Compare linear search, binary search and hashing.
Answer
Sections 1.2–1.4; Exercise Q7.
Study the whole chapter
13 step-by-step lessons, all 56 practice questions with hints, flashcards and mock tests for MBOSE Class XII Computer Science.