What is Linear Search?
Linear Search, also known as Sequential Search, is the most common searching algorithm. In this method, each element in the list is checked sequentially until the target element is found or the end of the list is reached.
Characteristics of Linear Search:
- Linear Search starts from the first element and moves sequentially to the next element.
- Inefficient for large datasets because of its linear time complexity.
- Easy to implement and understand.
- Linear Search has time complexity of O(N) where N is the number of elements in the list.
Example:
Consider an array arr[] = {10 ,20, 30, 40, 50} and the element to be searched, that is the target is 30.
- Start from the first element (index = 0), arr[0] = 10 which is not equal to the target element 30.
- Move to the second element (index = 1), arr[1] = 20 which is also not equal to the target element 30.
- Move to the third element (index = 2), arr[2] = 30, which is equal to the target element 30. So, return 2 as the index where target element is present.
Difference Between Linear Search and Jump Search
Linear Search and Jump Search are two different techniques used to find an element in a list. Each algorithm has its own set of characteristics, advantages, and limitations, making them suitable for different scenarios. This article explores the key differences between Linear Search and Jump Search.