InterviewSolution
| 1. |
Describe the Linear Search Algorithm. |
|
Answer» To find an element in a group of ELEMENTS, the linear search can be used. It works by traversing the list of elements from the beginning to the end and inspecting the properties of all the elements encountered along the way. Let us consider the case of an array containing some integer elements. We want to find out and print all of the elements' positions that match a particular value (also known as the "key" for the linear search). The linear search works in a flow here, matching each element with the number from the beginning to the end of the list, and then printing the element's location if the element at that position is equal to the key. Given below is an algorithm describing Linear Search:
The time complexity of the Linear Search Algorithm is O(N) where n is the size of the list of elements and its space complexity is constant, that is, O(1). |
|