Searching in Class 12 Computer Science: Efficient Methods Explained
By ConceptScroll Team · Published on 17 July 2026 · 5 min read

Searching is a fundamental concept in Class 12 Computer Science that involves finding a specific element within a list or dataset. This chapter explains popular searching methods like linear and binary search, helping students grasp efficient ways to locate data in sorted and unsorted lists.
What is Searching in Computer Science?
Searching is the process of locating a particular element, called the key, within a collection of data. In Class 12 NCERT Computer Science, searching helps students understand how to efficiently find information in lists or arrays.
Key points about searching:
- It involves checking elements to find a match with the key.
- Can be applied to sorted or unsorted data.
- Essential for data retrieval in programming and databases.
Searching algorithms differ based on the data structure and whether the data is sorted. The two primary methods covered in Class 12 are linear search and binary search.
Linear Search: Simple and Straightforward
Linear search is the most basic searching algorithm. It checks each element in the list one by one until the key is found or the list ends.
How Linear Search Works:
1. Start from the first element. 2. Compare the current element with the key. 3. If they match, return the position. 4. If not, move to the next element. 5. Repeat until the key is found or list ends.
Example:
Search for key 8 in the list [1, -2, 32, 8, 17]:
| Pass | Element Checked | Match? |
|---|---|---|
| 1 | 1 | No |
| 2 | -2 | No |
| 3 | 32 | No |
| 4 | 8 | Yes |
The key 8 is found at position 4.
Advantages:
- Works on both sorted and unsorted lists.
- Simple to implement.
Disadvantages:
- Inefficient for large lists (time complexity $O(n)$).
- Returns first occurrence only if duplicates exist.
Want to test yourself on Searching? Try our free quiz →
Binary Search: Faster Searching on Sorted Lists
Binary search is an efficient searching technique that requires the list to be sorted in ascending or descending order.
How Binary Search Works:
1. Find the middle element of the list. 2. Compare the middle element with the key. 3. If they match, return the position. 4. If the key is smaller, search the left half. 5. If the key is larger, search the right half. 6. Repeat the process on the reduced half until the key is found or search space is empty.
Example:
Search for key 7 in sorted list [ -4, 0, 2, 7, 8, 17, 19 ]:
| Iteration | First | Last | Mid | Middle Value | Compare with Key | Action |
|---|---|---|---|---|---|---|
| 1 | 0 | 6 | 3 | 7 | 7 == 7 | Key found at position 4 |
Binary search takes fewer steps than linear search, especially for large datasets.
Advantages:
- Much faster with time complexity $O(\log n)$.
- Efficient for large sorted lists.
Disadvantages:
- Requires the list to be sorted.
- Slightly more complex to implement.
Comparing Linear and Binary Search
Understanding the differences between linear and binary search helps in choosing the right algorithm.
| Feature | Linear Search | Binary Search |
|---|---|---|
| Data Requirement | Works on unsorted lists | Requires sorted lists |
| Time Complexity | $O(n)$ | $O(\log n)$ |
| Search Method | Sequential check | Divide and conquer |
| Implementation | Simple | Slightly complex |
| Use Case | Small or unsorted data | Large sorted data |
For example, searching for key 2 in [2, 3, 5, 7, 10] using binary search takes fewer comparisons than linear search.
Choosing the right search method is crucial for optimizing performance in programming and exams.
Worked Example: Applying Binary Search Step-by-Step
Let's apply binary search to find key 2 in the sorted list [2, 3, 5, 7, 10, 11, 12]:
| Step | First | Last | Mid Calculation | Mid Index | Mid Value | Compare Key | Next Search Range |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 6 | (0+6)//2 = 3 | 3 | 7 | 2 < 7 | First half (0 to 2) |
| 2 | 0 | 2 | (0+2)//2 = 1 | 1 | 3 | 2 < 3 | First half (0 to 0) |
| 3 | 0 | 0 | (0+0)//2 = 0 | 0 | 2 | 2 == 2 | Key found at position 1 |
This example shows how binary search narrows down the search space efficiently.
Practical Tips for Class 12 Students on Searching
When preparing for NCERT Class 12 Computer Science exams, keep these tips in mind:
- Always check if the list is sorted before applying binary search.
- Practice writing both linear and binary search algorithms.
- Understand the time complexity differences for exam questions.
- Use diagrams or tables to explain the search process clearly.
- Solve NCERT exercises and sample problems to strengthen concepts.
Mastering searching algorithms not only helps in exams but also builds a strong foundation for programming and data structures.
Frequently asked questions
What is the main difference between linear and binary search?
Linear search checks elements one by one and works on unsorted lists, while binary search requires sorted lists and divides the search space in half each time.
Can binary search be used on unsorted lists?
No, binary search only works on sorted lists because it relies on order to eliminate half the search space each step.
What is the time complexity of binary search?
Binary search has a time complexity of $O(\log n)$, making it much faster than linear search for large datasets.
Does linear search find all occurrences of a key in a list?
No, linear search returns the position of the first occurrence of the key. To find all occurrences, the algorithm must continue searching after the first match.
Why is sorting important before applying binary search?
Sorting arranges data in order, which allows binary search to correctly decide whether to search the left or right half of the list.
Ready to ace this chapter?
Get the full Searching chapter — interactive notes, diagrams, worked solutions, polls and a free practice quiz — in the ConceptScroll app.
Study smarter with ConceptScroll
Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.
Start learning freeContinue reading
- Project Based Learning in Class 12 Computer Science: A Complete Guide
Discover how Project Based Learning (PBL) in Class 12 Computer Science helps students apply concepts through real-world projects, improving problem-solving and teamwork skills.
- Project Based Learning in Class 12 Computer Science: A Complete Guide
Discover how Project Based Learning (PBL) enhances practical skills in Class 12 Computer Science. Understand the process, benefits, and examples from NCERT.
- Project Based Learning in Class 12 Computer Science: A Practical Approach
Discover how Project Based Learning (PBL) in Class 12 Computer Science helps students apply theory through real-world projects, enhancing skills and teamwork.