Searching in Computer Science: Class 12 NCERT Guide
By ConceptScroll Team · Published on 17 July 2026 · 6 min read

Searching is a fundamental concept in Class 12 NCERT Computer Science that involves finding a specific element in a list or database. This guide covers popular searching techniques like linear search, binary search, and hashing to help you grasp their working and applications.
What is Searching in Computer Science?
Searching is the process of locating a particular element or value within a collection of data, such as a list or an array. In Class 12 NCERT Computer Science, searching is essential for understanding how computers retrieve information efficiently.
Key points about searching:
- It helps find whether a key (element) exists in a dataset.
- It returns the position of the key if found.
- Searching algorithms vary based on data organization.
Searching is fundamental to many applications like database queries, file systems, and internet search engines.
Linear Search: The Simplest Searching Technique
Linear search, also called sequential search, is the simplest method. It checks each element in the list one by one until it finds the key or reaches the end.
How linear search works:
1. Start from the first element. 2. Compare the current element with the key. 3. If equal, return the position. 4. Else, move to the next element. 5. Repeat until the key is found or list ends.
Example:
List: [1, -2, 32, 8, 17, 19, 42, 13, 0, 44] Search key: 8
- Pass 1: 1 ≠ 8
- Pass 2: -2 ≠ 8
- Pass 3: 32 ≠ 8
- Pass 4: 8 = 8 → Found at position 4
Advantages:
- Simple to implement
- Works on unsorted data
Disadvantages:
- Inefficient for large lists (worst case: O(n) time complexity)
Linear search always returns the first occurrence if duplicates exist.
Want to test yourself on Searching? Try our free quiz →
Binary Search: Efficient Searching on Sorted Lists
Binary search works only on sorted lists. It repeatedly divides the search interval in half to quickly locate the key.
Steps:
1. Find the middle element. 2. If middle element equals key, return position. 3. If key is less, repeat search on left half. 4. If key is greater, repeat on right half. 5. Continue until key is found or interval is empty.
Formula for middle index:
$$ mid = \left\lfloor \frac{low + high}{2} \right\rfloor $$
Example:
Sorted list: [2, 8, 15, 23, 38, 56, 72] Search key: 23
- low=0, high=6, mid=3 → element=23 → Found at position 4
Advantages:
- Much faster than linear search (O(log n) time complexity)
Disadvantages:
- Requires sorted data
- More complex to implement than linear search
Hashing: Constant Time Searching Using Hash Functions
Hashing is a powerful searching technique taught in Class 12 NCERT Computer Science that allows locating elements in constant time, ideally with just one comparison.
Key concepts:
- A hash function computes an index from the element's value.
- The index points to the position in a hash table where the element is stored.
Example of hash function (remainder method):
$$ hash\_value = element \% table\_size $$
Consider inserting elements: 34, 16, 2, 93, 80, 77, 51 into a hash table of size 10.
| Element | 34 | 16 | 2 | 93 | 80 | 77 | 51 |
|---|---|---|---|---|---|---|---|
| Hash Value | 4 | 6 | 2 | 3 | 0 | 7 | 1 |
The hash table stores elements at these indices:
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Value | 80 | 51 | 2 | 93 | 34 | 16 | 77 |
Collision: When two elements produce the same hash value, it is called a collision. Collision resolution techniques like chaining or open addressing handle this.
Advantages:
- Very fast search (average O(1) time)
- Useful in databases, caching, and associative arrays
Disadvantages:
- Requires good hash functions
- Handling collisions adds complexity
Comparing Searching Techniques: When to Use What?
Choosing the right searching technique depends on the data and requirements. Here's a comparison:
| Feature | Linear Search | Binary Search | Hashing |
|---|---|---|---|
| Data Requirement | Unsorted or sorted | Sorted only | Any (but hash function needed) |
| Time Complexity | O(n) | O(log n) | O(1) average |
| Implementation | Simple | Moderate | Complex |
| Space Complexity | O(1) | O(1) | Extra space for table |
| Use Case | Small or unsorted data | Large sorted data | Fast lookup in large datasets |
Summary:
- Use linear search for small or unsorted lists.
- Use binary search for large, sorted lists.
- Use hashing for very fast search in large datasets where extra memory is available.
Worked Example: Searching for a Key Using Linear Search
Let's apply linear search to find the position of key 8 in the list:
List: [42, -2, 32, 8, 17, 19, 42, 13, 8, 44]
| Pass | Current Element | Comparison Result | Action |
|---|---|---|---|
| 1 | 42 | 42 ≠ 8 | Continue |
| 2 | -2 | -2 ≠ 8 | Continue |
| 3 | 32 | 32 ≠ 8 | Continue |
| 4 | 8 | 8 = 8 | Found at pos 4 |
The search stops at the first occurrence of 8, returning position 4.
This example shows linear search's step-by-step comparison process.
Summary and Exam Tips for Searching in Class 12 NCERT
To excel in the Searching chapter:
- Understand the working of linear, binary, and hashing search.
- Practice writing and tracing simple search algorithms.
- Remember the conditions for using binary search (sorted data).
- Learn the hashing concept, hash functions, and collision handling.
- Solve NCERT exercises and sample problems thoroughly.
Searching is a common exam topic with questions on algorithm steps, comparisons, and coding. Focus on clarity and logic in your answers.
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 divides sorted lists to find the key faster.
How does hashing provide faster searching?
Hashing uses a hash function to compute an index, allowing direct access to the element in constant time on average.
What happens when two elements have the same hash value?
This causes a collision, which is resolved using methods like chaining or open addressing.
Can binary search be used on unsorted data?
No, binary search requires the list to be sorted to correctly divide the search space.
Does linear search find all occurrences of a key?
No, linear search returns the first occurrence of the key in the list.
Why is hashing not always used despite its speed?
Hashing requires extra memory and careful collision handling, making it complex compared to simpler methods.
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.