The linear search: a simple algorithm for searching for something. It is what you do when you are searching for a matching sock in your sock drawer. Nevertheless, students find it difficult to code, so presented here is a load of videos to help.
In its simplest form, the linear search is as follows.
i = 0 // the first item in your list
found = false // you haven't found it yet
answer = null // you haven't found it
while i < numberOfItems and not(found)
if currentItem(i) == theThingYouAreLookingFor then
found = true // you found it
answer = i // the position of the thing
else
i ++ // increment i
endif
endwhile
return ( answer )
In English:
Look through all the items in your list in turn, from the start, until you find the one you are looking for. There are two ways a linear search can end: either you find the thing (so you stop searching), or you check everything and don't find it.
#linearSearch #algorithms
dd
Superdecade Games
Algorithms
Computer Science
linear search
PROGRAMMING
videos
A whole load of linear search algorithm videos
Subscribe to:
Post Comments (Atom)