Implementing the Linear Search in Python - using Python Lists

preview_player
Показать описание
In this video , we are going to implement Linear Search using Python Lists .

Linear Search is the most standard searching algorithm which is

used for searching an element in an Array . However , that

element may or may not be present in an Array .

TIME COMPLEXITY :

BEST CASE : O(1)

AVERAGE CASE : O(N)

WORST CASE : O(N)

where N is the number of Elements in an Array .

ALGORITHM :

1. Take an array as an input .

2. INPUT the element you want to search in an array read it as “ item “ and initialize a variable count = 0 .

3. Now , we will match this item with each element of an array i.e A[i] , where A[i] is the element of array at i-th position , with the help of loop.

4. If A[i] gets equal to item , then set count=1 , FOUND

5. Else if i ) N and count=1 , then NOT FOUND

Рекомендации по теме
visit shbcf.ru