COSC 1P03 Data Structures and Abstraction 20.1
COSC 1P03 Data Structures and Abstraction 20.1
COSC 1P03 Data Structures and Abstraction 20.1
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>COSC</strong> <strong>1P03</strong><br />
<strong>Data</strong> <strong>Structures</strong> <strong>and</strong> <strong>Abstraction</strong><br />
<strong>COSC</strong> <strong>1P03</strong><br />
Sequential (Linear) Search<br />
<br />
<br />
<br />
<br />
<br />
Principle<br />
probe in order<br />
Algorithm<br />
as variation of basic search<br />
Simple vs exhaustive<br />
Analysis<br />
depends on where element is found<br />
average performance<br />
each probe eliminates 1 entry<br />
O(n)<br />
E.g. view student<br />
<strong>Data</strong> <strong>Structures</strong> <strong>and</strong> <strong>Abstraction</strong> 20.4<br />
start at first item;<br />
for ( ; ; ) {<br />
if ( no more items ) { not found; break; };<br />
access item<br />
if ( search key matches key on item ) { found; break; };<br />
on to next item;<br />
};<br />
Figure 20.2 Sequential search algorithm<br />
minimum O(1)<br />
maximum O(n)<br />
average<br />
O(n)<br />
Table <strong>20.1</strong> Order of sequential search<br />
20.2