Saturday, June 14, 2008

Sequential Search

Algorithm Seqsearch

In this algorithm in the set of ‘N’ data item is given—D1, D2 .... Dn having k1, k2 .... kN, ‘N’ distinct respective keys. If the desired record is located that contains the key ‘ki’ then the search is successful otherwise unsuccessful. We assume that n ³ 1.


Step 1 Initialization

set i ¬ 1


Step 2 Loop, Comparison

while ( i < = N)

{

if (k = ki) then

{

message : ‘‘successful search’’

display (k) go to step 4

}

else

set i ¬ i + 1

}

End of loop


Step 3 If no match

If (k ¹ ki) then

message : "unsuccessful search"


Step 4 Finish

Exit.

No comments: