diff --git a/Searching/Linear-Search/in_python.py b/Searching/Linear-Search/in_python.py new file mode 100644 index 0000000..c57aa81 --- /dev/null +++ b/Searching/Linear-Search/in_python.py @@ -0,0 +1,36 @@ +#linear searching in python +""" +Linear searching refers to sequential searching + +starting from one end it searches for the desired element +till the pointer reaches the end of the array +""" +""" + * LINEAR SEARCH - + * Start searching from the first element till you find the element in an array + * and return the index. + * + * -if value doesnt exist then return -1. + * -max comparisons in the worst case will be 'N'(big-oh(N)) + """ + +def linear_search(array, N, target): + + for i in range(0, N): + if target == array[i]: + return i + return -1 + +""" Examples: +""" +array={1,4,24,8,2} +N = len(array) +target=10 +print(linear_search(array,N,target)) + +""" Output: +-1 +""" + + +