Search and sort algorithm
Searching and sorting are important tools in programming. We will study some
search and sorting algorithms.
Search
Searching is the process of looking for a particular value in a data set. The searched values are called
keys.
Linear search
Linear search is a simple sorting method used when performing the search in a
unsorted array. The algorithm goes through the entire array for index i = 0, 1, 2, ...,
arr.length-1. If key = arr[i] then index = i, the loop is terminated and index is returned.
If the key is not found in the entire array, -1 is returned. Average complexity for
the linear search algorithm is O(n/2) and in the worst case the complexity is O(n)
Search and sort algorithm
Searching and sorting are important tools in programming. We will study some
search and sorting algorithms.
Search
Searching is the process of looking for a particular value in a data set. The searched values are called
keys.
Linear search
Linear search is a simple sorting method used when performing the search in a
unsorted array. The algorithm goes through the entire array for index i = 0, 1, 2, ...,
arr.length-1. If key = arr[i] then index = i, the loop is terminated and index is returned.
If the key is not found in the entire array, -1 is returned. Average complexity for
the linear search algorithm is O(n/2) and in the worst case the complexity is O(n)