Analysis of Algorithms | Big | ''Function to find whether a key exists in an array or not using linear search ; '' Traverse the given array, a[] ; '' Check if a[i] is equal to key ; ''Given Input ; ''Function Call
def linearSearch ( a , n , key ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT if ( a [ i ] == key ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT arr = 2 , 3 , 4 , 10 , 40 NEW_LINE x = 10 NEW_LINE n = len ( arr ) NEW_LINE if ( linearSearch ( arr , n , x ) ) : NEW_LINE INDENT print ( " Element ▁ is ▁ present ▁ in ▁ array " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) NEW_LINE DEDENT