Alien can Computer Science
Index Sorting Searching

Searching

Linear

shopping clipart

Process:

  1. Start at beginning of list.
  2. Compare search term with first item on list.
  3. If match, stop.
  4. If not match, repeat with next item.
  5. Continue until match is found.

Examples of uses:

Pros

Does not require list to be sorted.

Cons

Slower than Binary

Binary

dictionary clipart

Process:

  1. Pick a pivot. Random will do.
  2. Split the list into two at the pivot point. The list now has two parts: Greater than and Less than.
  3. Move into one of the two new lists, depending on if the search term is greater than or less than pivot point.
  4. Repeat step 2 and 3 until match is found.

Examples of uses:

Pros

Faster than Linear.

Cons

Requires list to be sorted.