Week 1 Lec 1
Week 1 Lec 1
to Data
Structure
MS. RAEENA TAUQIR
LECTURER
Definition
Data structure is representation of
the logical relationship existing
between individual elements of data.
In other words, a data structure is a
way of organizing all data items that
considers not only the elements
stored but also their relationship to
each other.
Introduction
Data structure affects the design of
both structural & functional aspects
of a program.
Program = algorithm + Data
Structure
A algorithm is a step by step
procedure to solve a particular
function.
Introduction
Algorithm is a set of instruction written
to carry out certain tasks and the data
structure is the way of organizing the
data with their logical relationship
retained.
To develop a program of an algorithm,
we should select an appropriate data
structure for that algorithm.
Therefore algorithm and its associated
data structures from a program.
Classification of Data
Structure
Data structure are normally divided into
two broad categories:
◦ Primitive Data Structure
◦ Non-Primitive Data Structure
Classification of Data
Structure
Data structure
Primitive DS Non-Primitive DS
Head
Pointer fieldInformation field
[STACK]
Stack
The stack can be implemented into two ways:
◦ Using arrays (Static
implementation)
◦ Using pointer (Dynamic
implementation)
Queue
Queue are first in first out type of data
structure (i.e., FIFO)
In a queue new elements are added to
the queue from one end called REAR end
and the element are always removed
from other end called the FRONT end.
The people standing in a railway
reservation row are an example of
queue.
Queue
Each new person comes and stands at the end
of the row and person getting their reservation
confirmed get out of the row from the front end.
The bellow show figure how the operations take
place on a stack:
10 20 30 40 50
front rear
Queue
The queue can be implemented into two
ways:
◦ Using arrays (Static implementation)
◦ Using pointer (Dynamic
implementation)
Trees
A tree can be defined as finite set of data
items (nodes).
Tree is non-linear type of data structure
in which data items are arranged or
stored in a sorted sequence.
Tree represent the hierarchical
relationship between various elements.
Trees
There is a special data item at the top of
hierarchy called the Root of the tree.
The remaining data items are partitioned
into number of mutually exclusive
subset, each of which is itself, a tree
which is called the sub tree.
The tree always grows in length towards
bottom in data structures, unlike natural
trees which grows upwards.
Trees
The tree structure organizes the data
into branches, which related the
information.
A root
B C
D E F G
Graph
Graph is a mathematical non-linear data
structure capable of representing many
kind of physical structures.
It has found application in Geography,
Chemistry and Engineering sciences.
Definition: A graph G(V,E) is a set of
vertices V and a set of edges E.
Graph
An edge connects a pair of vertices and
many have weight such as length, cost
and another measuring instrument for
according the graph.
Vertices on the graph are shown as point
or circles and edges are drawn as arcs or
line segment.
Graph
6
v2 v5
v1 v3
10
v1 8 11
15
9 v2
v3 v4 v4