Professional Documents
Culture Documents
Algorithm vs. Data Structure
Algorithm vs. Data Structure
Def.A data structure is an arrangement of data in a computer’s memory or sometimes on a disk. Data structures
include linked lists, stacks, binary trees, and hash tables, among others.
Def.An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and
produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that
transform the input into the output.
Algorithms manipulate the data in the data structures in various ways, such as inserting a new data
item, searching for a particular item, or sorting the items. An algorithm can be thought of as the
detailed instructions for carrying out some operation. In a computer program these instructions
take the form of program statements.
1. Input: there are zero or more quantities which are externally supplied;
2. Output: at least one quantity is produced;
3. Definiteness: each instruction must be clear and unambiguous;
4. Finiteness: if we trace out the instructions of an algorithm, then for all cases the algorithm
will terminate after a finite number of steps;
Conversely a data structure is said to be non-linear if the data is not arranged in sequence. The
insertion and deletion of data is therefore not possible in a linear fashion. Trees and graphs are
examples of non-linear data structures.
1.4 Data Structure Operations: Algorithms
The data appearing in our data structures are processed by means of certain operations.
1. Traversing: Accessing each record exactly once so that certain items in the record may be
processed. (This accessing and processing is sometimes called “visiting” the record.)
2. Searching: Finding the location of the record with a given key value. or finding the locations
of all records which satisfy one or more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting: Removing a record from the structure.
5. Sorting: Arranging the records in some logical order (e.g.. alphabetically according to some
NAME key, or in numerical order according to some NUMBER key, such as social security
number or account number)
6. Merging: Combining the records in two different sorted files into a single sorted files.