Searching and Sorting
CHAPTER OUTLINE
16.1 Introduction
16.2
Searching
16.3
Linear (Sequential) Search
16.4
Binary Search
16.5
Sorting
16.6
Insertion Sort
16.7 Selection Sort
16.8
Bubble Sort
16.9
Quick Sort
16.10 Tree Sort
Exercises
16.1 INTRODUCTION
In database programs, large data is maintained in the form of records. It would be difficult to
search a record from a large database if data or records are unsorted. Also, it would take a lot of
time to find a particular record if data or records are randomly stored. Quick search methods are
to be adopted to search the data from a heap or large records. Two processes such as searching and
sorting are essential for database applications.
In short/ searching is a process by which a given record is searched from a set of records. Sorting
is a process in which records are arranged in ascending or descending order. A group of fields is
called record. For example, consider the following structure.
struct employee
{
char *name;
int age;
flo a t height;
} s;
We are familiar with the above declarations and definitions. The object s contains three fields as
described in the structure. The database is a collection of such fields. Each record contains the
above fields or depending upon the structure defined. The sorting can be done on any one or
combination of one or more fields. Suppose, we sort the records based on name. Then, the field
name will be the key field. A record is quickly searched in a sorted database. Thus, sorting and
searching are very useful concepts of data structure.
16
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.209.201