This introductory section provides necessary concepts of what data type and data structure is. It provides overview on abstract data type and its implementation.
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Introduction to Data Structure and Algorithm
1. Chapter 1
Concepts of Data Structure
1.1 Data Types
A data type is defined as a set of data values which have some
predefined characteristics. Each data type share a common
property. For example : integer, string, float and so on. Each
of these data types have their own properties and limitations.
Such properties and limitations are defined by the
programming language used.
1.2 Data Structure
A data structure is defined as a grouping of data types along
with a set of operations for organizing and accessing the
collection. Each operation is a property manually provided to
the structure. The main concept is to define organization and
set of rules to implement and control the organization of such
structure. For eg : array, struct, class, stack, queue, list, graph
and so on.
1.3 Types of Data Structure
1.3.1 Primitive Data Structure:
Primitive data structure is the basic data structure that directly
operate upon the machine instructions. Their representation
depends on the hardware used or programming language used.
Eg : integer, string, float, character, pointer and so on.
2. 1.3.2 Non Primitive Data Structure
Non primitive data structure is the data structure that are
derived from the primitive data structures. It is concerned with
grouping of similar or dissimilar data items together along
with the relationship between them. Eg: array, structure, stack
and so on.
1.4 Basic Data Structure Operations
1. Insertion : Addition of a new data element in a data
structure.
2. Deletion : Removing of a data element from a data structure
if exists.
3. Searching : Search for a specified data element in a data
structure.
3. 4. Traversal : Processing all the data elements present in a
data structure.
5. Sorting : Arranging data elements in a specified order
(ascending or descending).
6. Merging : Combining elements of a similar data structures
to form a new data structure of same type.
1.5 Importance of Data Structure
- Store and organize data in most efficient way
- Organize data based on the problem
- Make locating, retrieval and manipulating of data easy
1.6 Abstract Data Types (ADT)
ADT is a abstraction of data structure for specifying the
logical properties of a data type. It is a basic mathematical
concept to define a particular data type.
ADT consists of following specification about a data
structure:
1. Data stored
2. Operations on the data
3. Error conditions associated with the data operations
Consider a simple calculating system of a rational numbers
for performing addition, subtraction and multiplication.
Here, the ADT can be specified as :
/*Value Definition (Defines collection of values)*/
4. abstract typedef <integer, integer> rational;
condition rational[1] != 0;
/*Operator Definition (abstract functions specifying possible operations)*/
abstract rational createRational(a,b)
int a, b;
precondition b != 0;
postcondition createRational[0] == a;
createRational[1] == b;
abstract rational add(a,b)
rational a, b;
postcondition add[0] == a[0] * b[1] + b[0] * a[1];
add[1] == a[1] * b[1];
abstract rational subtract(a,b)
rational a, b;
postcondition subtract[0] == a[0] * b[1] - b[0] * a[1];
subtract[1] == a[1] * b[1];
abstract rational multiply(a,b)
rational a, b;
postcondition multiply[0] == a[0] * b[0];
multiply[1] == a[1] * b[1];
1.7 Algorithm
Algorithm is defined as a set of rules defined in necessary
flow so as to complete a specific task. It provides a core logic
necessary to solve a problem.
The significant traits of a good algorithm are as follows :
1. An algorithm should be terminated in finite number of
steps and each step should consume finite amount of
time.
5. 2. Each step of an algorithm should be clearly defined.
3. An algorithm must have finite number of inputs.
4. An algorithm must provide desirable output.
5. An algorithm should consume less time and less space to
execute.
1.8 Classification of Algorithm (Based on algorithmic
Paradigm)
1. Brute Force Algorithm (Looks for all the possibilities and
selects the best one)
2. Divide and Conquer Algorithm (Divides problem into
smaller parts and solve each part separately)
3. Greedy Algorithm (Chooses the best option at current stage
and does not consider about the future)
4. Dynamic Algorithm (Builds up to a solution from
previously built sub solutions)