Complete Summary and Solutions for Searching – NCERT Class XII Computer Science, Chapter 6 – Linear Search, Binary Search, Hashing, Algorithms, Questions, Answers
Comprehensive summary and explanation of Chapter 6 'Searching' from the Computer Science textbook for Class XII, covering the concept of searching, linear search algorithm and its working, binary search algorithm for sorted lists, hashing techniques for efficient search, collision, and collision resolution—along with all NCERT questions, answers, and exercises for practical understanding.
Updated: 4 months ago
Categories: NCERT, Class XII, Computer Science, Chapter 6, Searching, Linear Search, Binary Search, Hashing, Summary, Questions, Answers, Programming, Comprehension
Searching in Python - Class 12 Computer Science Chapter 6 Ultimate Study Guide 2025
Searching in Python
Chapter 6: Computer Science - Ultimate Study Guide | NCERT Class 12 Notes, Questions, Code Examples & Quiz 2025
Full Chapter Summary & Detailed Notes - Searching Class 12 NCERT
Overview & Key Concepts
Chapter Goal: Understand searching techniques: Linear (sequential), Binary (divide-conquer on sorted), Hashing (direct access via function). Exam Focus: Algorithms 6.1-6.2, Programs 6-1 to 6-3, Tables 6.1-6.10; 2025 Updates: Efficiency in big data. Fun Fact: Brian Kernighan quote on computing ties to search ops. Core Idea: Efficient retrieval from collections; from O(n) linear to O(1) hash. Real-World: Database queries. Expanded: All subtopics point-wise with evidence (e.g., Table 6.2 comparisons), examples (e.g., key=17 in [8,-4,7,17...]), debates (e.g., sorted cost vs binary speed).
Wider Scope: From unsorted small lists to hashed tables; sources: Algorithms, programs, tables/figures.
Expanded Content: Include time complexity (linear O(n), binary O(log n), hash O(1)); point-wise for recall; add 2025 relevance like parallel search.
Introduction
Searching Defined: Locate key in collection; return presence/position. Essential for data retrieval.
Importance: Algorithms need varied search methods; affects efficiency.
Example: Home items vs computer data on demand.
Practical Difficulties: Unordered → slow; Solutions: Choose method by list size/order.
Expanded: Evidence: Quote on computing impact; debates: Search vs sort trade-off; real: Search engines.
Conceptual Diagram: Search Flow
Flow: Collection → Key Input → Compare/Compute Index → Found/Not Found → Position/None. Ties to Algorithm 6.1.
Why This Guide Stands Out
Comprehensive: All methods point-wise, program integrations; 2025 with big-O analysis, processes for real code.
Linear Search
Overview: Sequential check from start; O(n) worst/best variable. For small/unsorted lists.
Algorithm 6.1: Index=0; while
Example 6.1: [8,-4,7,17,0,2,19] key=17 → 4 comparisons (Table 6.2).
Best/Worst: First elem (1 comp), last/not found (n comps) (Tables 6.3-6.4).
Program 6-1: Input list/key; return pos/None (Output: 23 at 2).
All terms from chapter; detailed with examples, relevance. Expanded: 25+ terms grouped by subtopic; added advanced like "Time Complexity", "Collision Resolution" for depth/easy flashcards.
Searching
Locate key in collection. Ex: Find 17 in list. Relevance: Data retrieval.
Linear Search
Sequential from start. Ex: Algorithm 6.1. Relevance: Unsorted small lists.
Halving step. Ex: 4 iters for 15 elems. Relevance: Not direct comps.
Comparison
Key vs element. Ex: Linear 4 for key=17. Relevance: Work measure.
Unsuccessful Search
Key not found. Ex: Print "unsuccessful". Relevance: n comps linear.
Successful Search
Key found. Ex: Position 4. Relevance: Early stop possible.
Tip: Group by method; examples for recall. Depth: Debates (e.g., hash collisions). Historical: Binary in dictionaries. Interlinks: To sorting Ch5. Advanced: Chaining resolution. Real-Life: Google search. Graphs: Complexity table. Coherent: Evidence → Interpretation. For easy learning: Flashcard per term with table ex.
60+ Questions & Answers - NCERT Based (Class 12) - From Exercises & Variations
Based on chapter + expansions (Ex1-9 p94-96). Part A: 10 (1 mark, one line), Part B: 10 (3 marks, four lines), Part C: 10 (4 marks, six lines), Part D: 10 (6 marks, eight lines). Answers point-wise in black text. Include code/tables where apt.
Part A: 1 Mark Questions (10 Qs - Short)
1. Define searching.
1 Mark Answer:
Locate key in collection.
2. What is linear search?
1 Mark Answer:
Sequential comparison.
3. Pre-req for binary search?
1 Mark Answer:
Sorted list.
4. Hash function example?
1 Mark Answer:
Element % size.
5. What is collision?
1 Mark Answer:
Same hash value.
6. Linear worst case?
1 Mark Answer:
n comparisons.
7. Binary mid calc?
1 Mark Answer:
(first+last)//2.
8. Hash time complexity?
1 Mark Answer:
O(1).
9. Perfect hash?
1 Mark Answer:
No collisions.
10. Binary for even elems?
1 Mark Answer:
Floor division.
Part B: 3 Marks Questions (10 Qs - Medium, Exactly 4 Lines Each)
1. Differentiate linear vs binary.
3 Marks Answer:
Linear: Unsorted, O(n).
Binary: Sorted, O(log n).
Ex: Linear 4 comps; binary 1 iter.
Linear simple; binary efficient.
2. Steps in Algorithm 6.1.
3 Marks Answer:
Index=0; while
If match: Print pos.
Else index++.
End: Unsuccessful.
3. Why binary halves list?
3 Marks Answer:
Mid > key: Ignore right.
Mid < key: Ignore left.
Ex: 15→7→3→1.
Reduces search area.
4. Hash function remainder method.
3 Marks Answer:
h(elem) = elem % size.
Ex: 34%10=4.
Insert at index.
One comp search.
5. Linear for duplicates.
3 Marks Answer:
Returns first pos.
Ex: [...,8,...,8] → first 8.
Continues till match.
Ex2: Key not found n comps.
6. Binary applications.
3 Marks Answer:
Dictionary/telephone dir.
Min/max in sorted.
DB indexing.
Data compression.
7. Collision in hashing.
3 Marks Answer:
Same remainder.
Ex: 16,26 %10=6.
Resolution needed.
Beyond scope.
8. Linear comps for key=43.
3 Marks Answer:
List ends with 43.
n=11 comps.
Worst case.
Table trace.
9. Binary for even list.
3 Marks Answer:
10 elems: mid=5 (6th elem).
First half 5, second 4.
Floor //.
Continue halving.
10. Hash table size.
3 Marks Answer:
> List size possible.
Ex: 10 slots for 7 elems.
Reduces collisions.
Python list impl.
Part C: 4 Marks Questions (10 Qs - Medium-Long, Exactly 6 Lines Each)
1. Explain linear with Ex6.1.
4 Marks Answer:
Compare seq till match.
[8,-4,7,17...] key=17.
4 comps (Table 6.2).
Pos 4.
Best:1, worst:n.
Simple, no sort.
2. Binary process with Table 6.7.
4 Marks Answer:
Mid compare, halve.
Key=2: Iter1 mid=17>2 left.
Iter2 mid=7>2 left.
Iter3 mid=3>2 left.
Iter4 match pos1.
Max log n iters.
4. Hash table creation Ex Table 6.10.
4 Marks Answer:
%10 on [34,16...51].
34→4, 16→6, etc.
Table: 0=80,1=51,...
Search: key%10 compare.
One step.
Collisions possible.
5. Compare linear/binary comps (Activity 6.5).
4 Marks Answer:
List 15 elems.
Linear key2:15,43:15,17:8,9:15.
Binary:2:4,43:4,17:1,9:4.
Binary fewer iters.
Linear consistent worst.
Binary log efficient.
6. Program 6-1 linear code.
4 Marks Answer:
Def linearSearch: for loop if match return pos.
Input list size, elems.
Key input, call func.
Print pos/None.
Output ex:23 at2.
Handles not found.
7. Binary vs linear performance.
4 Marks Answer:
Linear: Small unsorted.
Binary: Large sorted, faster.
Ex: 2^30 records mid:30 iters linear 2^30.
Binary scales log.
Sort cost amortize.
Hash beats both avg.
8. Hash collisions resolution.
4 Marks Answer:
Multiple at slot.
Ex: Chaining lists.
Open addressing probe.
Beyond book.
Perfect hash avoid.
Larger table help.
9. Unsorted to sorted linear/binary (Ex5).
4 Marks Answer:
Unsorted linear:1=24,5=24,55=24,99=24 comps.
Sort asc.
Sorted linear same 24.
Binary:1=5,5=3,55=4,99=5 iters.
Binary faster.
Sort enables.
10. Hash for words (Ex6 var).
4 Marks Answer:
Linear unsorted: Amazing=16,Perfect=1,Great=5,Wondrous=8 comps.
Code Examples & Programs - From Text with Simple Explanations
Expanded with evidence, analysis; focus on applications. Added variations for practice.
Example 1: Linear Search (Program 6-1)
Simple Explanation: Seq check list.
def linearSearch(list, key):
for index in range(0,len(list)):
if list[index] == key:
return index+1
return None
list1 = []
maximum = int(input("How many elements? "))
for i in range(0,maximum):
n = int(input())
list1.append(n)
key = int(input("Enter key: "))
position = linearSearch(list1, key)
if position is None:
print("Not present")
else:
print("At",position)
Step 1: Input list [12,23,3,-45].
Step 2: Key23 → pos2.
Step 3: Output present at2.
Simple Way: For unsorted.
Example 2: Binary Search (Program 6-2)
Simple Explanation: Halve sorted.
def binarySearch(list, key):
first = 0
last = len(list) - 1
while(first <= last):
mid = (first + last)//2
if list[mid] == key:
return mid
elif key > list[mid]:
first = mid + 1
elif key < list[mid]:
last = mid - 1
return -1
list1 = []
print ("Create list ascending")
num = int(input())
while num!=-999:
list1.append(num)
num = int(input())
n = int(input("Key: "))
pos = binarySearch(list1,n)
if(pos != -1):
print( n,"at", pos+1)
else:
print (n,"not found")
Step 1: Input [1,3,4,5] key4 → mid match pos3.
Step 2: Unsorted input [12,8,3] key4 → not found.
Step 3: Assumes sorted.
Simple Way: Sorted input.
Example 3: Hash Search (Program 6-3)
Simple Explanation: %10 lookup.
def hashFind(key,hashTable):
if (hashTable[key % 10] == key):
return ((key % 10)+1)
else:
return None
hashTable=[None]*10
print("HashTable:",hashTable)
L = [34, 16, 2, 93, 80, 77, 51]
print("List", L)
for i in range(0,len(L)):
hashTable[L[i]%10] = L[i]
print("Hash contents: ")
for i in range(0,len(hashTable)):
print("index=", i," , value =", hashTable[i])
key = int(input("Search: "))
position = hashFind(key,hashTable)
if position is None:
print("Not present")
else:
print("Present at ",position)
Step-by-step breakdowns of core processes, structured as full questions followed by detailed answers with steps. Visual descriptions; focus on actionable Q&A with examples from chapter.
Question 1: How does linear search work for key=17 in [8,-4,7,17...] (Table 6.2)?
Answer:
Step 1: Index=0, 8!=17, index=1.
Step 2: -4!=17, index=2.
Step 3: 7!=17, index=3.
Step 4: 17==17, return pos4.
Step 5: Stop, 4 comps.
Step 6: Display found.
Visual: Arrow seq – Start → Comp1 No → Comp2 No → ... → Match Stop. Example: Early if first.
Question 2: Binary search steps for key=2 in sorted 15-elem list (Table 6.7)?
Answer:
Step 1: First=0 last=14 mid=7 val=17>2 last=6.
Step 2: Mid=3 val=7>2 last=2.
Step 3: Mid=1 val=3>2 last=0.
Step 4: Mid=0 val=2==2 return1.
Step 5: 4 iters, halves each.
Step 6: Max for edge.
Visual: Tree halve – Full → Left7 → Left3 → Left1 → Match. Example: Mid key=1 iter.
Question 3: Building hash table for [34,16...] %10 (Tables 6.9-10)?