Searching Techniques
Searching Techniques
Searching Techniques
The list given below is the list of elements in an unsorted array. The array contains ten
elements. Suppose the element to be searched is '46', so 46 is compared with all the
elements starting from the 0th element, and the searching process ends where 46 is
found, or the list ends.
The performance of the linear search can be measured by counting the comparisons
done to find out an element. The number of comparison is 0(n).
The searching mechanism proceeds from either of the two halves depending
upon whether the target element is greater or smaller than the central element. If
the element is smaller than the central element, then searching is done in the first
half, otherwise searching is done in the second half.
The records are either sorted either numerically or alphanumerically. The records
are then arranged in ascending or descending order depending on the numerical
value of the key. Here is an example, where the sorting of a lists of marks
obtained by a student in any particular subject of a class.
Categories of Sorting
The techniques of sorting can be divided into two categories. These are:
Internal Sorting
External Sorting
Internal Sorting: If all the data that is to be sorted can be adjusted at a time
in the main memory, the internal sorting method is being performed.
External Sorting: When the data that is to be sorted cannot be
accommodated in the memory at the same time and some has to be kept in
auxiliary memory such as hard disk, floppy disk, magnetic tapes etc, then
external sorting methods are performed.
Various sorting techniques are analyzed in various cases and named these
cases as follows:
Best case
Worst case
Average case
Hence, the result of these cases is often a formula giving the average time
required for a particular sort of size 'n.' Most of the sort methods have time
requirements that range from O(nlog n) to O(n2).