Array ( [0] => [1] => questions [2] => HackwithInfy-Previous-Questions [3] => Linear-Search )
Given a list of integers and a search value. Find the search value from the array using Linear Search Algorithm.
First line contains the size of array (n), Second line contains the search value followed by n integers separated by spaces.
Print the index of the search value if present else print -1.
5 3 32 45 3 56 790
2
6 34 37 46 33 205 67 105
-1
5 980 37 463 756 980 67 105
3
Login to see Discussion
Step-i) Take the input search value and array from the user.
Step-ii) Traverse through the whole array, by comparing each array element with the search value.
Step-iii) If the elements match return the index of element in array, else return -1.
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution