Java Reference
In-Depth Information
In practice, elementary data can be arbitrary complex. For example, consider
representing an individual. In that case, the key (handle) of objects can be
either the lastname or the firstname, and additional fields could be the address,
phone number, age, etc. Thus all information characterizing an individual can
be modeled by a class with the following set of attributes:
class Individual {
String Firstname;
String Lastname;
String Address;
String Phonenumber;
int Age;
boolean Sex;
}
Let us take a last geometric example for storing points. Each object denotes
then a 2D point, and the key can be the name attached to that point or the x
or y coordinates, etc. Further, additional information fields may be the point
color attribute, its name, etc. A class for storing points can thus be modeled
as:
class Color {int Red, Green, Blue;}
class Point2D
{
double x;
double y;
String name;
Color color;
}
6.3 Sequential search
Once the class for storing object records has been designed, we consider
representing a set of objects by an array of such objects. Objects are stored in
the array in any order. That is, the set of objects stored in the array is not
sorted into any particular order. To seek whether a given query object is inside
the array or not, we simply browse the array sequentially until we find the
object, or we report that it has not been found inside the array. This explains
why the sequential search is also called the linear search since in the worst-case
we need to browse all the array elements to report that the query object was
not found. The basic primitive operation is to compare the key of the query
element with the respective keys of objects of the array. Let us consider a listing
of people, each person modeled by the following class:
 
Search WWH ::




Custom Search