Introduction to searching
A search operation is carried out to find the location of the desired data item from a collection of data items. The search algorithm returns the location of the searched value where it is present in the list of items and if the data item is not present, it returns None
.
Efficient searching is important to efficiently retrieve the location of the desired data item from a list of stored data items. For example, we have a long list of data values, such as {1, 45, 65, 23, 65, 75, 23}
, and we want to see if 75
is present in the list or not. It becomes important to have an efficient search algorithm when the list of data items becomes large.
There are two different ways in which data can be organized, which can affect how a search algorithm works:
- First, the search algorithm is applied to a list of items that is already sorted; that is, it is applied to an ordered set of items. For example,
[1, 3, 5, 7, 9, 11, 13, 15, 17]
. - The search...