Quantcast

Linear Search

Last modified by
on
Jun 13, 2023, 2:48:45 PM
Created by
on
Jun 12, 2023, 5:09:33 PM
`S = [i_1, i_2, i_3, ... i_n]`
`(I) "Search item"`
Tags
UUID
e6ef7ca7-0943-11ee-b65f-bc764e203090

Linear Search is a type of searching algorithm that iterates through each item in a list, comparing each item in the list to the desired item until the first instance of it is found. 

 

 

 

INSTRUCTIONS: Enter the following

  • In this program, there is a list of integers, 1-100, in a random order 
  • (S) Enter the number you would like to search for 

Search Index (S): When an integer is found, the algorithm will return the INDEX of the number in the list

[62, 51, 28, 36, 20, 21, 12, 1, 76, 72, 92, 86, 9, 84, 67, 48, 37, 15, 69, 65, 24, 89, 42, 38, 33, 52, 27, 40, 26, 6, 61, 45, 79, 29, 34, 3, 17, 64, 7, 49, 11, 95, 25, 41, 50, 56, 77, 53, 14, 93, 78, 18, 32, 35, 74, 30, 75, 10, 57, 100, 58, 47, 39, 13, 5, 83, 63, 54, 46, 90, 8, 85, 16, 22, 2, 80, 73, 87, 31, 96, 60, 43, 82, 99, 97, 4, 94, 59, 19, 55, 44, 70, 81, 71, 88, 68, 23, 98, 91, 66]

 

Index vs Position

In an array or list, we count the index starting at 0. So a list of 5 elements has indexes 0-4:

  first_item second_item third_item fourth_item fifth_item ...
Index 0 1 2 3 4 ...

 

Complexity

  • Linear Search: O(n)

 


  • Comments
  • Attachments
  • Stats
No comments
This site uses cookies to give you the best, most relevant experience. By continuing to browse the site you are agreeing to our use of cookies.