Wednesday 26 June 2013

Algorithm: Pseudo-code to find the Smallest element form a list of items stored in a linear array.

a nonempty array DATA with N numerical values is given. an algorithm to find the location LOC and the value MIN of the smallest element of array DATA. a variable K is gonna be use as counter.

  1. set K :=1, LOC :=1 and MIN :=DATA[0].    [ initialization ]
  2. While K<=N, repeat step 3
  3. IF MIN > DATA[K], then set LOC :=K and MIN :=DATA[K]                                         ELSE K :=K+1.
  4. Write: LOC, MIN
  5. Exit.

No comments:

Post a Comment