Linear Search Algorithm -Example
•Givenanarray,arr[]ofnintegers,andanintegerelementx,findwhetherelementxispresentin
thearray.Printtheindexofthefirstoccurrenceofxinthearray,orPrint“itdoesn'texist”.
•Testcases:
1.Input: arr[] = [1, 2, 3, 4], x = 3
Output: 2
Explanation: There is one test case with array as [1, 2, 3 4] and element to be searched as 3.
Since 3 is present at index 2, the output is 2.
2.Input: arr[] = [10, 8, 30, 4, 5], x = 5
Output: 4
Explanation: For array [10, 8, 30, 4, 5], the element to be searched is 5 and it is at index 4. So,
the output is 4.
3.Input: arr[] = [10, 8, 30], x = 6
Output: it doesn't exist
Explanation: The element to be searched is 6 and its not present, so we print “it doesn't exist”.