Sequential search

  1. read n, the number of entries in the phone book
  2. read N1 ,..., Nn,T1 ,..., Tn
  3. read NAME
  4. set i <- 1
  5. set found = false
  6. repeat until either found or i > n
  7.    if NAME=Ni then
  8.       write Ti
  9.        set found <- true
  10.     else
  11.       set i <- i +1
  12. // end until
  13. if not found then
  14.    write 'sorry, but the name is not in the directory' // end if
  15. stop

We must change the algorithm to allow for telephone books of various sizes (Step 1).

[Prev][TOC][Next]

CS1104 Main Page
Last Updated 01/29/2000
© L.Heath, 2000