File tree 3 files changed +25
-2
lines changed
3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change
1
+ # Pythonn implementation of Linear Search Algorithm
2
+
3
+ def linearSearch (array , x ):
4
+ for i in range (len (array )):
5
+ if (array [i ] == x ):
6
+ return i
7
+ return - 1
8
+
9
+ # Driver Code
10
+ array = [2 , 4 , 0 , 1 , 9 ]
11
+ x = 1
12
+ result = linearSearch (array , x )
13
+ if (result == - 1 ):
14
+ print ("Element not found" )
15
+ else :
16
+ print ("Element found at index: " , result )
Original file line number Diff line number Diff line change 449
449
<a href="#counting-sort">Counting Sort</a> •
450
450
<a href="#radix-sort">Radix Sort</a> •
451
451
<a href="#bucket-sort">Bucket Sort</a> •
452
- <a href="#heap-sort">Heap Sort</a> •
453
- <a href="#shell-sort">Shell Sort</a>
452
+ <a href="#heap-sort">Heap Sort</a>
454
453
</p >
455
454
456
455
### [ Bubble Sort] ( /Practice%20Concepts/Sorting/bubble-sort.py )
583
582
<a href="#binary-search">Binary Search</a>
584
583
</p >
585
584
585
+ ### [ Linear Search] ( /Practice%20Concepts/Search/linear-search.py )
586
+ * Sequential searching algorithm where we start from one end and check every element of the list until the desired element is found.
587
+ * Method:
588
+ - Start from the first element and compare it with each element in the array
589
+ - Return the index if there is a match
590
+
591
+ ![ ] ( https://github.com/aish21/Algorithms-and-Data-Structures/blob/main/Resources/Animations/linear.gif )
592
+
586
593
## Greedy Algorithms
587
594
<p align =" center " >
588
595
<a href="#introduction-to-greedy-algorithms">Introduction to Greedy Algorithms</a> •
You can’t perform that action at this time.
0 commit comments