Professional Documents
Culture Documents
Data Structure 1
Data Structure 1
RATHOD
DEFINATION
Data Structure is a way to store and organize data so that it can be
used efficiently.
The primitive data structures are primitive data types. The int, char,
float, double, and pointer are the primitive data structures that can
hold a single value.
The data structures used for this purpose are Arrays, Linked list,
Stacks, and Queues.
Queue
Linked List
TYPES OF DATA STRUCTURES
Non-Linear Data Structure
• Updation: We can also update the element, i.e., we can replace the
element with another element.
• String reversal
• UNDO/REDO
• Recursion
• Backtracking
• Expression conversion
• Memory management
C PROGRAM FOR STACK
#include <stdio.h>
int stack[100], i, j, choice=0, n, top=-1;
void push();
void pop();
void show();
void main ()
{
• Simple Queue
• Circular Queue
• Priority Queue
• Double ended Queue
SIMPLE QUEUE / LINEAR QUEUE
In Linear Queue, an insertion takes place from one end while the
deletion occurs from another end.
The end at which the insertion takes place is known as the rear
end, and the end at which the deletion takes place is known as
front end.
Peek: It returns the element, which is pointed by the front pointer in the
queue but does not delete it.
If the first three elements are deleted from the Queue, we cannot
insert more elements even though the space is available in a Linear
Queue.
In this case, the linear Queue shows the overflow condition as the
rear is pointing to the last element of the Queue.
CIRCULAR QUEUE
The drawback that occurs in a linear queue is overcome by using
the circular queue.
It is similar to the linear Queue except that the last element of the
queue is connected to the first element.
A B C
CIRCULAR QUEUE REPRESENTATION
DIAGRAMMATIC EXPLANATION
A] E]
B] F]
C] G]
D] H]
ALGORITHM FOR INSERT
Step 1: IF (REAR+1)%MAX = FRONT
Write " OVERFLOW "
Goto step 4
[End OF IF]
Step 2: IF FRONT = -1 and REAR = -1
SET FRONT = REAR = 0
ELSE IF REAR = MAX - 1 and FRONT ! = 0
SET REAR = 0
ELSE
SET REAR = (REAR + 1) % MAX
[END OF IF]
Step 3: SET QUEUE[REAR] = VAL
Step 4: EXIT
ALGORITHM FOR DELETE
Step 1: IF FRONT = -1
Write " UNDERFLOW "
Goto Step 4
[END of IF]
Step 2: SET VAL = QUEUE[FRONT]
Step 3: IF FRONT = REAR
SET FRONT = REAR = -1
ELSE
IF FRONT = MAX -1
SET FRONT = 0
ELSE
SET FRONT = FRONT + 1
[END of IF]
[END OF IF]
Step 4: EXIT
APPLICATION OF CIRCULAR QUEUE
• Memory management
• CPU Scheduling
• Traffic system
PRIORITY QUEUE
It is a special type of queue in which the elements are arranged
based on the priority.
Suppose some elements occur with the same priority, they will be
arranged according to the FIFO principle.
PRIORITY QUEUE
There are two types of priority queue :
It means that we can insert and delete elements from both front and
rear ends of the queue.
A B C D E B B F
DEQUE (OR, DOUBLE ENDED QUEUE)
There are two types of deque :
• Linked list can be defined as the nodes that are randomly stored in
the memory.
• A node in the linked list contains two parts, i.e., first is the data part
and second is the address part.
• After array, linked list is the second most used data structure.
struct node
{
int data;
struct node *next ;
}
TYPES OF LINKED LIST
• Singly-linked list
struct node
int data;
};
• INSERT LAST
• DELETE BEGINNING
• DELETE LAST
• TRAVERSING
• SEARCHING
INSERT BEGINNING
INSERT BEGINNING
INSERT END
INSERT END
INSERT MIDDLE
INSERT MIDDLE
DELETE BEGINNING
DELETE BEGINNING
DELETE LAST
DELETE LAST
DELETE MIDDLE
DELETE MIDDLE
DISPLAY / TRAVERSING
DOUBLY LINKED LIST
Doubly linked list is a complex type of linked list in which a node
contains a pointer to the previous as well as the next node in the
sequence.
struct node
int data;
}
OPERATIONS ON DOUBLY LINKED LIST
• INSERT BEGINING
• INSERT LAST
• DELETE BEGINNING
• DELETE LAST
• TRAVERSING
• SEARCHING
INSERT BEGINNING
g
INSERT END
INSERT MIDDLE
DELETE BEGINNING
DELETE END
DELETE MIDDLE
APPLICATION OF LINKED LIST
• Mailing list
• Memory management
• Addition of 2 Polynomials
• Multiplication of 2 polynomials.
Thank you