Unit 1
Unit 1
By:
Dr. Mamata Wagh
Deptt. of CSE
C. V. Raman Global University
Bhubaneswar
INTRODUCTION TO
DATA STRCTURE
Unit-1
COURSE OUTCOMES:
Upon successful completion of this course, students will be able to:
⚫ CO1: Analyze and design of linear data structure such as Queue and
Stack for solving problems.
⚫ CO2: Analyze and design of linear data structure such as Linked List
for solving problems.
⚫ CO3: Analyze and design of non-linear data structure such as Tree for
solving problems.
Elementary
Data items
items Group items
Abstract data types
⮚ ADT, is a logical description of how we view the data and the
operations that are allowed without regard to how they will be
implemented. .
⮚ The ADT is made of with primitive data types , but operation logics are
hidden.
⮚ Example: stack
queue
list etc.
Data Structure
⮚ A data structure is a specialized format for organizing, processing,
retrieving and storing data.
T
1
T
2
T
3
T
4
… T
n
…
Sub
Stack of CDs
Trees
Stack of books
10 and plates
Types Of Data Structure
Types Of Data structure
The DS are divided into following types:
⚫ Primitive data structures can hold only a single value in one specific
location, unlike the non-primitive data structures which can be in a linear
and non-linear order.
⚫ Primitive data structures are the predefined types of data that are
supported in the programming language.
⚫ examples : float, character, integer and pointer.
⚫ The Non-Primitive Data Structures are created with the help of the
primitive data structures.
⚫ The non-primitive data structure is a kind of data structure that can hold
multiple values either in a contiguous or random location.
⚫ examples Arrays, Stacks, Queues
Linear and Non-linear Data structure
Linear Data structure
⮚ A data structure is said to be linear if its elements combine to form
any specific order.
Example : Arrays
Stacks
Ques
Linked list
Non linear Data structure
⮚ This structure is mostly used for representing data that contains a
hierarchical relationship among various elements.
⮚ Example :
Tree
Graph
Array:
An array is a linear data structure that collects elements of the same
data type and stores them in contiguous and adjacent memory
locations.
Stack
⚫ Stack is a data structure in which insertion and deletion operations are
performed at one end only.
⮚ Traversal
⮚ Insertion
⮚ Deletion
⮚ Searching
⮚ Sorting
⮚ Merging.
ARRAY
Why we need array ?
It will reserve 1000 contiguous memory locations for storing the students’
marks
Types of Arrays
⚫ One - Dimensional Array
⚫ Where int specifies the data type or type of elements arrays stores.
⚫ “arr” is the name of array & the number specified inside the square
brackets is the number of elements an array can store, this is also called
sized or length of array.
Arrays
Arrays
⚫ Following are some of the concepts to be remembered about
arrays:
⚫ The first element of the array has index zero[0]. It means the
first element and last element will be specified as: arr[0] &
arr[9] respectively.
Arrays:
⚫ The elements of array will always be stored in the consecutive
(continues) memory location.
A[r][c] is a matrix
where r=Row size(ranges from 0 to r-1)
c=Column size(ranges from 0 to c-1)
B=base address of the array A
Address(A[i][j])=B+(i*c + j) *w
where w=size of each element
Address calculation of Matrix Elements in
Memory
Column-major Order Representation:
A[r][c] is a matrix
where r=Row size(ranges from 0 to R-1)
c=Column size(ranges from 0 to
C-1)
B=base address of the array A
Address(A[i][j])=B+(j*r + i) *w
where w=size of each element
Arrays
PUSH
top
top
Push operation in stack
Pop Operation
POP
top
top
PEEP Operation Algorithm
ALGORITHM:PEEP (STACK, TOP, MAX_SIZE, ITEM)
Input: STACK is the linear array with maximum size
MAX_SIZE.
Output: This algorithm returns the top most
element of the STACK.
Step 1: If TOP=-1, then
Print “Stack is empty” and exit.
Step 2: Return STACK [TOP]
Step 3: Exit
Operations on Stack
Creation
Insertion
Deletion
Displaying
0 Creation #define SIZE 5 0
int stack[SIZE];
Insertion
void push(element){ 4
if(Stack is full)
{ 3
printf(“FULL!!!”);
} 2
else
{ 1
Top++;
stack[Top] = element; 0
}
}
Deletion int pop( ){
if(Stack is Empty)
{
printf(“EMPTY!!!”);
return Top;
}
else
{
deleted = stack[Top];
Top--;
return deleted;
}
}
Displaying void display( ){
if(Stack is Empty)
{
printf(“EMPTY!!!”);
}
else
{
for(i=Top; i>-1; i--)
printf(“%d\
n”,stack[i]);
}
}
Application Of Stack
act on
Ex: A + B
Prefix Notation
operand.
Operand.
Postfix Notation.
⮚The terms “front” and “rear” are used in describing a linear list only
when it is implemented as a queue.
⮚ Queues are also called first-in-first-out (FIFO) lists. In other words, the
order in which elements enter a queue is the order in which they leave.
Types of Queue
Linear Queue
Circular Queue
Double-Ended Queue(Deque)
Priority Queue
Representation of Queue
Input: QUEUE is the linear array with maximum size MAX.FRONT and
REAR are the pointer variables pointing to Front end and Rear
end.
Output: This algorithm inserts an element ITEM on to end of the queue QUEUE.
⚫Circular queue are the queues implemented in circular form rather than
in a straight line.