Brian wants to rename this page "Searching a List." --MF, 2/19/18
On this page, you will see how the characteristics of a list can affect the algorithm for searching in it.
When searching for an item in unsorted data, you have to check every item until you find the value you are looking for.
position of number in unsorted list
block that reports the earliest location of a number in an unsorted list or reports "Not In List" (or NIL, if you like) if the number is not in the list.If you are searching for a number in a sorted list, you have more information. Suppose you have a sorted list and you want to locate the position of a number.
position in sorted list
and the number guesser algorithm should have the same overall structure.
position of number in sorted list
block that returns the position of a number in a list sorted from lowest to highest or zero if the number is not in the list. (Note: This task is identical to the previous one except that instead of the block "saying" the position it will need to "report" the position.)position in sorted list
with position in unsorted list
:
Length of List | Number of Guesses |
---|---|
3 | |
7 | 3 |
15 | |
63 | |
127 |