Computer ScienceClass 12Searching

Searching in Class 12 Computer Science: Efficient Methods Explained

By ConceptScroll Team · Published on 17 July 2026 · 5 min read

Searching in Class 12 Computer Science: Efficient Methods Explained

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]:

PassElement CheckedMatch?
11No
2-2No
332No
48Yes

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 ]:

IterationFirstLastMidMiddle ValueCompare with KeyAction
106377 == 7Key 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.

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]:

StepFirstLastMid CalculationMid IndexMid ValueCompare KeyNext Search Range
106(0+6)//2 = 3372 < 7First half (0 to 2)
202(0+2)//2 = 1132 < 3First half (0 to 0)
300(0+0)//2 = 0022 == 2Key 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.

Open in ConceptScroll →

Study smarter with ConceptScroll

Daily NCERT-aligned reels, AI doubt solving and chapter quizzes — all free.

Start learning free
#algorithms#binary search#class 12#computer science#data structures#linear search#ncert#searching

Continue reading