Professional Documents
Culture Documents
Data Structure
Data Structure
STRUCTURES
CHAPTER 1:
INTRODUCTION TO
DATA STRUCTURES
(1)DATA MANAGEMENT
CONCEPTS
Till now we have learnt the basics of programming in C and know how to
Our Aim has been to design good programs where a good program is
defined as follow:
runs correctly
is easy to read and understand
is easy to debug
is easy to modify
management concepts.
DATA MANAGEMENT
CONCEPTS(cont.)
Data structure is a part of data management.
A data structure is basically a group of data
DATA MANAGEMENT
CONCEPTS(cont.)
Data structures are applied in areas like:
compiler design
operating system
DBMS
Graphics
Numerical Analysis
Artificial Intelligence
For Example:
In DBMS Following data structure are
used
(1) In RDBMS data structure used is arrays
(2) Network data model is graphs
(3)Hierarchical data model is trees
DATA MANAGEMENT
CONCEPTS(cont.)
When selecting a data structure to solve a problem
DATA TYPES(cont.)
(3)TYPES OF DATA
STRUCTURES
(1)ARRAYS
below
Marks[
0]
ele. 3
fig: ele.
4
ele.
5
ele.
6
ele.
7
ele.
8
ele.
TYPES OF DATA
STRUCTURES(cont.)
(1)ARRAYS(cont.)
Array have following limitation:
(1) Array are of fixed size
(2) Data elements are stored in continuous
memory location which may not be always
available.
(3)Adding and Removing of elements is
problematic because of shifting the elements
from their positions.
However ,these limitation can be solved by using
linked lists.
TYPES OF DATA
STRUCTURES(cont.)
(2)Linked Lists
TYPES OF DATA
STRUCTURES(cont.)
(3)STACKS
as a linear array.
Every stack has a variable TOP associated with it.
TOP is used to store the address of the top most
element of the stack. it is this position from where
the element will be added or deleted.
There is another variable MAX , which will be used
to store the maximum number of elements that the
stack can store.
AB
ABC
ABCD that stack is empty
IfA TOP=NULL
then itABCD
indicates
E
and if TOP=MAX , then stack is full.
0
1
2
3
TOP=4 5
6
7
STACK REPRESENTION:
TYPES OF DATA
STRUCTURES(cont.)
(3)STACKS(cont.)
In fig. TOP=4 ,so insertion and deletion will be done at this
position.
Here ,the stack can store maximum of 8 elements where the
rang from 0-7.In above stack 3 more elements can still stored.
A stack has basic 3 operations:
(1)push(this operation adds elements to the top of the
stack)
(2)pop(this operation removes the element from top
of the stack)
(3)peep(returns the value of topmost element of the
stack)
Advantage: last in, fist out(LIFO) access.
Disadvantage: slow access to other elements.
TYPES OF DATA
STRUCTURES(cont.)
(4)QUEUE
1
2
18
14
36
Here ,front=0 and rear=5.if we want to add another element with the
value 45,then rear would be incremented by 1 and rear point the value
45.
See fig.(QUEUE AFTER INSERTION OF NEW ELEMENT)
12
18
14
36
45
Here front=0 and rear =6.everytime new element has to be added, we will re
TYPES OF DATA
STRUCTURES(cont.)
(4)QUEUE(cont.)
Now ,if we want to delete an element from the queue , then the value of
18
14
36
45
front
rear
TYPES OF DATA
STRUCTURES(cont.)
(5)TREES
A binary tree is a data structure which is defined as a collection of
element.
Every binary tree has a root element pointed by a root pointer.
The root element is the topmost element in tree.if root=NULL ,then tree
is empty.`
TYPES OF DATA
STRUCTURES(cont.)
(5)TREES(cont.)
Figure 1.7 shows a binary tree. If the root node R is
TYPES OF DATA
(6)GRAPHS
STRUCTURES(cont.)
TYPES OF DATA
STRUCTURES(cont.)
(6)GRAPHS(cont.)
Every node in the graph may represent a city and
Time-Space Trade-of
The best algorithm to solve a particular problem at hand
executes in 10 iterations and the other in 20 iterations, the diference between the two
algorithms is not much. However, if the first algorithm executes in 10 iterations and
the other in 1000 iterations, then it is a matter of concern.
We have seen that the number of statements executed in the function for n elements
0 (n ).
The Big-Oh notation, where the 0 stands for 'order of', is concerned
(6)areBIG-OH
NOTATION(Cont.)
There
certain limitations
with the Big-Oh
notation of expressing the complexity of
algorithms.
These limitations include: