School Revise · Class 11 Computer Science · Chapter 6
Code 083, Class 12. S
|
|
Searching looks for a value in a list. Linear search checks each item in turn. Binary search is much faster but needs the list to be sorted.
Go through the list one item at a time until you find the value or reach the end. It works on any list.
|
nums = [4, 7, 2, 9] target = 2 for i in range(len(nums)): if nums[i] == target: print(“found at”, i) Output: found at 2 |
On a sorted list, look at the middle. If the target is smaller, search the left half; if larger, the right half. Each step halves the list, so it is very fast.
Use linear search for small or unsorted lists. Use binary search for large sorted lists, because it is far quicker.
Explore the idea by tapping. The interactive opens right here in the lesson.
Write and run real Python right here in the lesson, then work through the practice problems with answers.
Type each one into the code lab above, then open the card to see the worked solution and its output.
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
Linear search.
Binary search.
middle item.
Binary search.
|
Searching finds a value in a list. Linear search checks items one by one and works on any list. Binary search needs a sorted list and looks at the middle, then halves the search each step, so it is much faster. Use linear for small or unsorted lists and binary for large sorted lists. |
| Open the Virtual Lab |
These free Class 12 Computer Science notes explain searching, linear search on any list, binary search on a sorted list, and when to use each with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.
© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Computer Science syllabus. Unauthorised copying is not permitted.