Data Structures and
Algorithms
Chapter 1: Introduction
Introduction
Algorithm- outline, the essence of a
computational procedure, step-by-step
instructions
Program – an implementation of an algorithm
in some programming language
The way in which the data is organized affects the
performance of a program for different tasks.
Computer programmers decide which data structures
to use based on the nature of the data and the
processes that need to be performed on that data
Abstract Data Types
Solving a problem involves processing data, and an
important part of the solution is the careful
organization of the data
In order to do that, we need to identify:
1. The collection of data items
2. Basic operation that must be performed on them
Abstract Data Type (ADT): a collection of data
items together with the operations on the data
Abstract Data Type (ADT)
The word “abstract” refers to the fact that the
data and the basic operations defined on it
are being studied independently of how
they are implemented
We think about what can be done with the
data, not how it is done
ADT example
Data structure - Implementation of
ADT
An implementation of ADT consists of storage
structures to store the data items and algorithms
for basic operation
A data structure is a scheme for organizing data
in the memory of a computer.
Some of the more commonly used data structures
include lists, arrays, stacks, queues, heaps, trees,
and graphs.
Data Structures, Abstract Data
Types, and Implementations
Consider example of an airplane flight with 10
seats to be assigned
Tasks
List available seats
Reserve a seat
How to store, access data?
10 individual variables
Use of Array to store seats
Algorithm to List available seats
For number ranging from 0 to max_seats-1, do:
If seat[number] == ‘ ’:
Display number
Algorithm to Reserve a seat
Readin number of seat to be reserved
If seat[number] is equal to ‘ ’:
set seat[number] to ‘X’
Else
Display a message that the seat having this number is
occupied
Linear and Non-Linear Data
Structures
We may classify these data structures as linear
and non-linear data structures. However, this is
not the only way to classify data structures.
In linear data structure the data items are
arranged in a linear sequence like in an
array.
In a non-linear, the data items are not in
sequence. An example of a non-linear data
structure is a tree.
Homogeneous and Non-
Homogeneous Data Structures
Data structures may also be classified as
homogenous and non-homogenous data
structures.
An Array is a homogenous structure in which all
elements are of same type.
In non-homogenous structures the elements
may or may not be of the same type.
Records are common example of non-
homogenous data structures.
Static and Dynamic Data
Structures
Static structures are ones whose sizes and
structures associated memory location are
fixed at compile time.
Dynamic structures are ones, which expand or
shrink as required during the program
execution and their associated memory
locations change.
Logical and Physical Data
Structures
Data structures are very important in computer
systems. In a program, every variable is of
some explicitly or implicitly defined data
structure, which determines the set of
operations that are legal upon that variable.
The data structures that we discuss here are
termed logical data structures. There may be
several different physical representations on
storage possible for each logical data
structure.
For each data structure that we consider, several
possible mappings to storage will be introduced.
Data Structure Operations
The data appearing in the data structures are
processed by means of certain operations.
In fact, the particular data structure that one
chooses for a given situation depends largely on
the frequency with which specific operations are
performed.
The following are the major operations performed
on data structures:
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.)
Data Structure Operations - cont
Searching: Finding the location of the record
with a given key value, or finding the locations of
all records that satisfy one or more conditions.
Inserting: Adding a new record to the
structure.
Deleting: Removing a record from the
structure.
Sometimes two or more of the operations may be
used in a given situation; e.g., we may want to
delete the record with a given key, which may
mean we first need to search for the location of
the record.
Data Structure Operations - cont
The following two operations, which are used in
special situations, are also be considered:
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)
Merging: Combining the records in two
different sorted files into a single sorted file
Other operations, e.g., copying and
concatenation, are also used.