CH5 DS
CH5 DS
Introduction to DS
Low level DS
Classification of DS
1.Primitive data structure
2.Non-primitive data structure
Linear
Non linear
Arrays
linked lists
Stacks
Queues
Trees
Graphs
INTRODUCTION DS
DS provides a structured set of variables that
are associated with each other in different
ways.
provides a way to efficiently store and organize
data so that it can be accessed and manipulated
effectively.
define the relationships between data elements,
the operations that can be performed on the
data, and the constraints or rules governing
those operations.
DS= Organized data + Allowed Operations.
Operation includes:
Insertion: Adding a new element to the list.
Deletion: Removing an element from the list.
Sorting: Arranging the elements in some order.
Merging: Combining two lists into a single list.
LOW LEVEL DATA
STRUCTURES
Fundamental DS implemented at a lower level of
abstraction.
Closer to the hardware and operating system.
Optimized for memory management and
performance.
Importance of low-level data structures:
It forms a basis of programming tool that
represents the relationship between data elements
and helps programmers to process the data easily.
essential for efficient memory management,
system programming, and optimizing
performance-critical applications.
CLASSIFICATION OF DATA
STRUCTURES
Data structure can be classified into two
categories:
1.Primitive data structure
2.Non-primitive data structure
Linear
Arrays
linked lists
stacks
queues.
Non linear
Trees
Graphs
CONT’D…
1.Primitive Data Structure
consist of the numbers and the characters.
manipulated or operated directly by the
machine level instructions.
Basic data types such as integer, real,
character, and Boolean come under primitive
data structures.
2.Non-primitive Data Structure
derived from primitive data structures.
cannot be operated or manipulated directly by the
machine level instructions.
focus on formation of a set of data elements
that is either homogeneous (same data type) or
heterogeneous (different data type).
further divided into linear and non-linear data
structure based on the structure and arrangement of
data.
CONT’D…
Linear Data Structure
maintains a linear relationship among its
elements.
data is arranged in a linear fashion.
Ex: Arrays, linked lists, stacks, queues.
Non-linear Data Structure
data elements are not arranged in a
sequential order.
There is a hierarchical relationship
between individual data items.
The insertion and deletion of data is not
possible in a linear fashion.
EX: Trees and graphs
CLASSIFICATION OF DATA
STRUCTURE(CONT’D)
ARRAY
refers to an orderly arrangement of data
elements.
type of data structure that stores data elements in
adjacent locations.
considered as linear data structure that stores
elements of same data types.
also called as a linear homogenous data
structure.
Example: int Num [5] = { 26, 7, 67, 50, 66 };
classified as one-dimensional array, two-
dimensional array or multidimensional array.
ARRAY(CONT’D)
One-dimensional Array:
It has only one row of elements.
stored in ascending storage location.
Two-dimensional Array:
consists of multiple rows and columns of data
elements.
It is also called as a matrix.
Multidimensional Array:
defined as array of arrays.
not bounded to two indices or
dimensions.
They can include as many indices as
required.
Limitations:
Arrays are of fixed size.
ARRAY(CONT’D)
Applications:
Storing list of data elements belonging to
same data type
Storage of matrices
Limitations:
Arrays are of fixed size.
Insertion and deletion of elements can be
problematic because of shifting of elements
from their positions.
LINKED LIST
each data element contains a pointer or link to
the next element in the list.
insertion and deletion of the data element is
possible at all places of a linear list.
it is not necessary to have the data elements
stored in consecutive locations.
It allocates space for each data item in its own
block of memory.
Each node in the list contains information field
and a pointer field.
The information field contains the actual data
the pointer field contains address of the
subsequent nodes in the list.
LINKED LIST(CONT’D)
Applications:
Temporary storage structure for recursive
operations
Auxiliary storage structure for nested
operations, function calls,
deferred/postponed functions
Evaluation of arithmetic expressions in
various programming languages
In all the problems solutions based on
backtracking.
Operating System functions
UNDO and REDO functions in an editor.
QUEUES
first-in, first-out (FIFO) data
The elements are added at one end called the
rear and removed from the other end called the
front.
Insertion or Enqueue:
This function is used to store data.
perform the following steps:
i. Check whether Queue is full or not.
ii. If full, print a message that queue is full.
iii. If not full, then increment rear by 1 and to that
location new data is inserted.
Deletion or Dequeue:
used to remove data from the Queue.
performs the following steps:
i. Check whether Queue is empty or not.
ii. If empty, message that Queue is empty.
iii. If not empty, print the element represented by
the front location and increment the front by 1.
QUEUES(CONT’D)
Applications:
Job scheduler operations of OS like a
print buffer queue, keyboard buffer
queue to store the keys pressed by users
Job scheduling, CPU scheduling
Priority queues are used in file
downloading operations in a browser
Data transfer between peripheral devices
and CPU.
Interrupts generated by the user
applications for CPU
TREES
a non-linear data structure
data is organized in branches.
The data elements in tree are
arranged in a sorted order.
It imposes a hierarchical structure
on the data elements.
TREES(CONT’D)
Root: The topmost node
Parent: A node that has child nodes
Child: A node connected to a parent node
Sibling: Nodes with the same parent
Leaf: Nodes with no children
Depth: Number of edges from the root to a
node
Height: Maximum depth of any node in the
tree
TREES(CONT’D)
Advantage: Provides quick search, insert, and
delete operations
Applications:
Implementing the hierarchical structures in
computer systems like directory and file system.
Implementing the navigation structure of a
website.
Decision making in gaming applications.
Implementation of priority queues for priority
based OS scheduling functions
For storing data keys for DBMS for indexing
path-finding algorithm to implement in AI,
robotics and video games applications
GRAPHS
non-linear data structure.
each data element is called a vertex and is
connected to many other vertexes through
connections called edges.
considered as a mathematical structure,
which is composed of a set of vertexes and
a set of edges.
GRAPHS(CONT’D)
Advantage: Best models real-world situations
Disadvantage: Some algorithms are slow and
very complex
Applications:
Representing networks and routes in
communication, transportation and travel
applications
Routes in GPS
Interconnections in social networks and
other network-based applications
Ecommerce applications to present user
preferences
Robotic motion and neural networks