Searching Algorithm BSCE-24008
Searching Algorithm BSCE-24008
DISCRETE STRUCTURES
Searching algorithm ek technique hai jo kisi data set mein specific value ko locate karne ke liye use hoti
hai. Discrete structures mein searching algorithms ka study logical thinking, algorithm analysis, and
mathematical modeling ka hissa hota hai.
2. Definition
A searching algorithm is a method used to find an element (called a "key") within a data structure such
as an array, list, or graph.
TYPES :
1. Linear Search:
🔧 Pseudocode:
if array[i] == target:
return i
⏱ Time Complexity
🧠 Computational Complexity
✅ Advantages
Simple to implement
Works on both sorted and unsorted lists
No preprocessing required
❌ Disadvantages
💡 Suggested Improvements
If the data is searched frequently, sort the data and use Binary Search.
2. Binary Search:
🔧 Pseudocode
left = 0
right = length(array) - 1
if array[mid] == target:
return mid
left = mid + 1
else:
right = mid - 1
return -1
⏱ Time Complexity
🧠 Computational Complexity
Space Complexity: O(1) for iterative, O(log n) for recursive
✅ Advantages
❌ Disadvantages
💡 Suggested Improvements
Function Computation
Searching algorithms are an essential topic in discrete structures because they combine logic,
algorithm design, and mathematical reasoning. They form the basis of problem-solving in computer
science and have applications in databases, AI, and decision-making systems.
🚀 General Improvements
· Build search indices for faster access (used in databases and search engines).