किसी Array/List में किसी दिए गए तत्व (Element / Key) को ढूँढने की प्रक्रिया को Searching कहते हैं।
Searching �...
---
📘 Unit – IV : Searching
---
🔹 Searching (खोज क्या है?)
किसी Array/List में किसी दिए गए तत्व (Element / Key) को ढूँढने की प्रक्रिया को Searching कहते हैं।
Searching का उद्देश्य होता है – यह पता लगाना कि दिया गया element data structure में मौजूद है या नहीं।
Unit-IV में दो प्रकार की Searching cover की जाती है:
1. Linear Search (रेखीय खोज)
2. Binary Search (द्विआधारी खोज)
---
1️⃣ Linear Search (रेखीय खोज)
📌 परिभाषा
Linear Search एक साधारण खोज तकनीक है। इसमें array/list के प्रत्येक element को एक-एक करके चेक किया जाता है, जब तक कि वांछित element (key) न मिल जाए या पूरी list समाप्त न हो जाए।
---
📌 एल्गोरिद्म के चरण
1. Array के पहले element से search शुरू करें।
2. हर element को key से compare करें।
3. अगर match मिल जाता है → index/position return करें।
4. अगर पूरी list खत्म हो जाए और element न मिले → “Not Found” return करें।
---
📌 Example
Array = [5, 12, 7, 20, 35]
Key = 20
Compare 5 ≠ 20
Compare 12 ≠ 20
Compare 7 ≠ 20
Compare 20 = 20 ✅ Found at position 4
---
📌 Pseudocode
LinearSearch(A, n, key)
for i ← 0 to n-1 do
if A[i] = key then
return i
return -1
---
📌 Time Complexity
Best Case: O(1) (पहले element में मिल जाए)
Worst Case: O(n) (अंत में मिले या न मिले)
Average Case: O(n)
---
📌 विशेषताएँ
✔ सरल और आसान
✔ Unsorted list पर भी लागू
❌ बड़े data set पर inefficient
---
2️⃣ Binary Search (द्विआधारी खोज)
📌 परिभाषा
Binary Search एक efficient searching technique है जो केवल Sorted Array/List पर काम करती है।
यह Divide and Conquer पद्धति का उपयोग करती है।
---
📌 एल्गोरिद्म के चरण
1. Low = पहले element का index, High = आखिरी element का index
2. Mid = (Low + High) / 2
3. अगर A[mid] = key → element मिल गया ✅
4. अगर key A[mid] → Right half में search करें (Low = mid + 1)
6. प्रक्रिया को तब तक दोहराएँ जब तक Low ≤ High हो।
BinarySearch(A, n, key)
low ← 0
high ← n-1
while low <= high do
mid ← (low + high)/2
if A[mid] = key then
return mid
else if key < A[mid] then
high ← mid - 1
else
low ← mid + 1
return -1
index vast am Jnts of data,
enabling far -r and more
sourate search results for users
= around the world
rch algorithms
sist in analyzing large
datasets, making it easier for
ers to find patterns and
Insights that drive data-driven
decisions.
Machine Learning
Machine learning r
advanced searching techniques
to quickly identify relevant data,
enhancing the model training
process and improving
predictive accuracy.
Conclusion and Key Takeaways
Understanding Search Methods Linear h Esics
Learn how linear and binary search operate on data efficiently. Linear searg koh item one by one until the target is found.
Binary Search Overview
inary ee te on NS Binary search is more efficient on sorted data compared to linear search.
Time Complexity Choosing the Right Method
Efficiency Matters
Linear search operates in O(n), while binary search runs in O(log n). Select the search method based on data characteristics and size.