Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1 Lecture: Data Structure & Algorithm

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.

Every algorithm must satisfy the following criteria:

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;

1.1 Algorithm vs. Data structure


Algorithms manipulate the data in various ways, such as inserting a new data item, searching for a
particular item, or sorting the items.

1.2 Algorithm vs. Program


In formal computer science, one distinguishes between an algorithm, and a program. A program
does not necessarily satisfy condition. One important example of such a program for a computer is
its operating system which never terminates (except for system crashes) but continues in a wait loop
until more jobs are entered.

1.3 Classification of Data Structure


Data structures are broadly divided into two:

1. Primitive or built-in data structures


2. Non-primitive or derived data structures
1.3.1 Primitive or built-in data structures
These are the basic data structures and are directly supported by the systems. They are integers,
floating point numbers, characters, string constants, pointers etc.

1.3.2 Non-primitive or derived data structures


Non primitive data structures are built by grouping/ combining primitive data structures. Array, list,
files, linked list, trees and graphs fall in this category.

1.3.3 Linear and non-Linear data structure


A data structure is said to be linear if its elements form a sequence or a linear list. In linear data
structures, the data is arranged in a linear fashion although the way they are stored in memory need
not the sequential. Arrays. Linked lists, stacks and queues are examples of linear data structures.

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.

1.5 Comparison of different data structures

You might also like