Searching
CBSE · Class 12 · Computer Science
NCERT Solutions for Searching — CBSE Class 12 Computer Science.
Interactive on Super Tutor
Studying Searching? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.
1,000+ Class 12 students started this chapter today

This is just one of 9+ visuals inside Super Tutor's Searching chapter
Explore the full set5 worked solutions below. Unlock all 9 free in Super Tutor
EXERCISE
1Using linear search determine the position of 8, 1, 99 and 44 in the list:
[1, -2, 32, 8, 17, 19, 42, 13, 0, 44]
Draw a detailed table showing the values of the variables and the decisions taken in each pass of linear search.Show solution
List:
### For key = 8
| Pass | Index | Element | Decision |
|---|---:|---:|---|
| 1 | 0 | 1 | |
| 2 | 1 | -2 | |
| 3 | 2 | 32 | |
| 4 | 3 | 8 | , found |
Position found = 4
### For key = 1
| Pass | Index | Element | Decision |
|---|---:|---:|---|
| 1 | 0 | 1 | , found |
Position found = 1
### For key = 99
| Pass | Index | Element | Decision |
|---|---:|---:|---|
| 1 | 0 | 1 | |
| 2 | 1 | -2 | |
| 3 | 2 | 32 | |
| 4 | 3 | 8 | |
| 5 | 4 | 17 | |
| 6 | 5 | 19 | |
| 7 | 6 | 42 | |
| 8 | 7 | 13 | |
| 9 | 8 | 0 | |
| 10 | 9 | 44 | |
Search is unsuccessful.
### For key = 44
| Pass | Index | Element | Decision |
|---|---:|---:|---|
| 1 | 0 | 1 | |
| 2 | 1 | -2 | |
| 3 | 2 | 32 | |
| 4 | 3 | 8 | |
| 5 | 4 | 17 | |
| 6 | 5 | 19 | |
| 7 | 6 | 42 | |
| 8 | 7 | 13 | |
| 9 | 8 | 0 | |
| 10 | 9 | 44 | , found |
Position found = 10
Not sure why a step works? check your working in Super Tutor
2Use the linear search program to search the key with value 8 in the list having duplicate values such as [42, -2, 32, 8, 17, 19, 42, 13, 8, 44]. What is the position returned? What does this mean?Show solution
For the list , the first occurs at index 3, so the program returns position 4.
This means linear search stops as soon as it finds the first occurrence of the key, even if the same value appears again later in the list.
Not sure why a step works? check your working in Super Tutor
3Write a program that takes as input a list having a mix of 10 negative and positive numbers and a key value.Show solution
def linearSearch(lst, key):
for i in range(len(lst)):
if lst[i] == key:
return i + 1
return None
# input list of 10 mixed negative and positive numbers
lst = []
print("Enter 10 integers (negative and positive):")
for _ in range(10):
lst.append(int(input()))
key = int(input("Enter key value: "))
pos = linearSearch(lst, key)
if pos is None:
print("Key is not present in the list")
else:
print("Key is present at position", pos)
```
This program takes 10 integers and a key, searches using linear search, and prints the position if found; otherwise it prints that the key is not present.
Not sure why a step works? check your working in Super Tutor
4Write a program that takes as input a list of 10 integers and a key value and applies binary search to find whether the key is present in the list or not. If the key is present it should display the position of the key in the list otherwise it should print an appropriate message. Run the program for at least 3 different key values and note the results.Show solution
def binarySearch(lst, key):
first = 0
last = len(lst) - 1
while first <= last:
mid = (first + last) // 2
if lst[mid] == key:
return mid + 1
elif key < lst[mid]:
last = mid - 1
else:
first = mid + 1
return None
# input list of 10 integers in ascending order
lst = []
print("Enter 10 integers in ascending order:")
for _ in range(10):
lst.append(int(input()))
key = int(input("Enter key value: "))
pos = binarySearch(lst, key)
if pos is None:
print("Key is not present in the list")
else:
print("Key is present at position", pos)
```
### Example results for 3 keys
For a sorted list such as :
- key = 15 → present at position 4
- key = 72 → present at position 10
- key = 19 → not present
Binary search works only on a sorted list.
Not sure why a step works? check your working in Super Tutor
5Following is a list of unsorted/unordered numbers:
[50, 31, 21, 28, 72, 41, 73, 93, 68, 43, 45, 78, 5, 17, 97, 71, 69, 61, 88, 75, 99, 44, 55, 9]
- Use linear search to determine the position of 1, 5, 55 and 99 in the list. Also note the number of key comparisons required to find each of these numbers in the list.
- Use a Python function to sort/arrange the list in ascending order.
- Again, use linear search to determine the position of 1, 5, 55 and 99 in the list and note the number of key comparisons required to find these numbers in the list.
- Use binary search to determine the position of 1, 5, 55 and 99 in the sorted list. Record the number of iterations required in each case.Show solution
## 1) Linear search on the unsorted list
Linear search compares items from the beginning.
- 1: not present → 24 comparisons
- 5: found at position 13 → 13 comparisons
- 55: found at position 23 → 23 comparisons
- 99: found at position 21 → 21 comparisons
## 2) Sorted list in ascending order
Using sorting, the list becomes:
## 3) Linear search again on the sorted list
Linear search still checks from the start, so comparisons depend on where the item appears.
- 1: not present → 24 comparisons
- 5: position 1 → 1 comparison
- 55: position 12 → 12 comparisons
- 99: position 24 → 24 comparisons
## 4) Binary search on the sorted list
Binary search uses iterations.
- 1: not present → 5 iterations
- 5: position 1 → 5 iterations
- 55: position 12 → 1 iteration
- 99: position 24 → 5 iterations
## Inference
- In an unsorted list, linear search may need many comparisons.
- In a sorted list, binary search is much faster than linear search.
- Binary search is especially efficient when the key is near the middle.
Not sure why a step works? check your working in Super Tutor
[Perfect, Stupendous, Wondrous, Gorgeous, Awesome, Mirthful, Fabulous, Splendid, Incredible, Outstanding, Propitious, Remarkable, Stellar, Unbelievable, Super, Amazing].
- Use linear search to find the position of Amazing, Perfect, Great and Wondrous in the list. Also note the number of key comparisons required to find these words in the list.
- Use a Python function to sort the list.
- Again, use linear search to determine the position of Amazing, Perfect, Great and Wondrous in the list and note the number of key comparisons required to find these words in the list.
- Use binary search to determine the position of Amazing, Perfect, Great and Wondrous in the sorted list. Record the number of iterations required in each case.
CountryCapital = {'India': 'New Delhi', 'UK': 'London', 'France': 'Paris', 'Switzerland': 'Berne', 'Australia': 'Canberra'}
Let us presume that our hash function is the length of the Country Name. Take two lists of appropriate size: one for keys (Country) and one for values (Capital). To put an element in the hash table, compute its hash code by counting the number of characters in Country, then put the key and value in both the lists at the corresponding indices. For example, India has a hash code of 5. So, we store India at the 5th position (index 4) in the keys list, and New Delhi at the 5th position (index 4) in the values list and so on. So that we end up with:
| hash index = length of key - 1 | List of Keys | List of Values |
|---|---|---|
| 0 | None | None |
| 1 | UK | London |
| 2 | None | None |
| 3 | Cuba | Havana |
| 4 | India | New Delhi |
| 5 | France | Paris |
| 6 | None | None |
| 7 | None | None |
| 8 | Australia | Canberra |
| 9 | None | None |
| 10 | Switzerland | Berne |
Now search the capital of India, France and the USA in the hash table and display your result.
4 more solved questions in Searching
Every remaining exercise is solved step by step in Super Tutor, plus practice quizzes and flashcards for this chapter. Free to start.
Stuck on a step?
Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.
Ask a Doubt FreeFrequently Asked Questions
What are the important topics in Searching for CBSE Class 12 Computer Science?
How to score full marks in Searching — CBSE Class 12 Computer Science?
Where can I get free NCERT Solutions for Searching Class 12 Computer Science?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Searching
Practice Quiz
Test yourself with a quick quiz
Important Questions
Practice with board exam-style questions
Revision Notes
Key points for last-minute revision
Formula Sheet
All formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect visually
Study Plan
Step-by-step plan to ace this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
For serious students
Get the full Searching chapter — for free.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for CBSE Class 12 Computer Science.