Introduction To Searching Operations
Introduction To Searching Operations
Operations
Searching operations are essential in computer science, enabling us to locate
specific data within a collection. These operations are fundamental for a wide
range of tasks, including finding information in databases, retrieving files on a
computer, and matching patterns in text.
VS by Vinita S
Linear Search
1 Simple Algorithm
Linear search sequentially checks each element in a list until the target
value is found.
2 Unsorted Data
This algorithm is suitable for searching through unsorted data.
3 Worst-Case Scenario
In the worst case, it requires checking every element in the list.
4 Time Complexity
The time complexity of linear search is O(n), meaning the number of
operations grows linearly with the size of the list.
Time Complexity of Linear Search
1 Best Case
The target value is found at the first position. Time complexity
is O(1).
2 Average Case
The target value is found in the middle of the list. Time
complexity is O(n/2).
3 Worst Case
The target value is found at the last position or is not present.
Time complexity is O(n).
Binary Search
Sorted Data
1 Binary search requires the data to be sorted in ascending order.
Efficient Search
3 Binary search is more efficient than linear search for large
datasets.
Time Complexity of Binary Search
Case Time Complexity
Hash Table
A hash table is a data structure that uses a hash function to map keys to
indices in an array.
Collision Handling
Collisions occur when multiple keys map to the same index. Techniques
like separate chaining or open addressing handle collisions.
Advantages and Disadvantages of Hashing
Advantages Disadvantages
Hashing provides constant-time average-case performance Hashing can be susceptible to collisions, which can degrade
for insertion, deletion, and search operations. performance.
It's a simple and efficient way to store and retrieve data. It's not suitable for sorted data or range queries.
Conclusion and Key Takeaways
Time Complexity
Linear search has a time complexity of O(n), while binary search has a time
complexity of O(log n).
Data Structure
Hashing utilizes a hash table to store data, offering fast retrieval.