Standard Algorithm 2 – Linear Search

This algorithm asks the user for something to look for and then checks through a list of items to see if it can find it. If it does find it, the algorithm says in what position it found it. So for example from the following list:

“Stewart”, “Simon”, “Dara”, “Scott”, “Keith”, “Farooq”, “Gaetano”

User Input Algorithm Output

Stewart 1

Dara 3

Gaetano 7

In the same way as the last standard algorithm you need to be able to write the pseudocode in the exam!

1.1 ask for item being searched for

 

1.2 for each item in the array

 

1.3 if this item matches the item being searched for

1.4 store the position

 

1.5 end if

 

1.6 end loop

 

1.7 print out where the item was found

 

Powerpoint below:

linear-search.jpg

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: