Module:search_algorithms()
Method : linear_search(arr,key,hint=False)
Uses : To search the key value in the array andd return it's position once found, this method also shows the time taken to run the program.
Parameters : arr - an one dimensional array as python list,
key is the key value to be searched in the array,
hint is passed False by default, by declaring hint=True
a detailed description of the linear search algorithm can be found.
from edualgo import algorithms as al
ping = al.search_algorithms()
arr = [10,9,4,5,7,8]
ping.linear_search(arr,5)
Output:
Linear Search Runtime = 0.0
3
For getting the hint just pass hint=True in the function like - linear_search(arr,key,True).
Module:search_algorithms()
Method : binary_search(arr,key)
Uses : To search the key value in the array andd return it's position once found
Parameters : arr - an one dimensional array as python list,
key is the key value to be searched in the array.
from edualgo import algorithms as al
ping = al.search_algorithms()
arr = [10,9,4,5,7,8]
ping.binary_search(arr,5)
Output:
3
Do you want to contribute to our project ? We welcome every python lover to come forwards and have some fun with our source code. Steps to contibute:
Keep coding, keep loving python