Searching algorithms are designed to check whether a specific element exists within a data structure or to retrieve its position if it exists.
Linear Search is a simple algorithm that checks every element in the list sequentially until it finds the target or reaches the end.
Algorithm | Time Complexity | Space Complexity |
---|---|---|
Linear Search | O(n) | O(1) |
Binary Search is a more efficient algorithm than Linear Search. It works on sorted arrays and repeatedly divides the search interval in half.
Algorithm | Time Complexity | Space Complexity |
---|---|---|
Binary Search | O(log n) | O(1) |