diff --git a/Algorithms/Search/linear-search.py b/Algorithms/Search/linear-search.py new file mode 100644 index 0000000..66dde53 --- /dev/null +++ b/Algorithms/Search/linear-search.py @@ -0,0 +1,9 @@ +#Code to return first index of occurrence of element x if it is present in array arr, -1 if not present +def search(arr, x): + + for i in range(len(arr)): + + if arr[i] == x: + return i + + return -1