Data Structure
Data Structure
Q1:- what is data structure what are the component of data structure? What is
the use of data structure?
Ans:--The study of the arrangement huge no of data elements are called data
structure. Alternately we can say that data structure is the arrangement of the data
element in such a way that the processing on the data element are very fast. It is
also possible to say that data structure is the study of arrangement of a huge no of
data elements in linear and nonlinear form. Data structure is divided in to two
categories basically.
Linear data structure:- Linear data structure is those type of data structure
in which every element has at most one successor and almost one predecessor.
That means linear data structure is those type of data structure in which after an
element at most one element can be present and similarly before an element
maximum one element can be present. It is also possible to say an element can
have one child at most at most one present in the Linear Data Structure. Linear
data structure is divided in the following categories :-
Stack
Queue
List
Stack:- Stack is a linear data structure in which elements are arranged using the
concept of LIFO (last in first out) or FILO (first in last out) that means the first
inserted element will be deleted last. Alternately we can say that the last inserted
element will be deleted first. In stack only one end is present to insert and delete
element which is called top of the stack. Two basic operations are possible on
stack.
Insertion or push.
Deletion or pop.
Display or peep
Queue :- Queue is also a linear data structure in which elements are arranged
using the concept of FIFO(first in first out) or LILO(last in last out). That means
the first inserted element will be deleted first and last inserted element will be
deleted last. Queue has two end:- The insertion end is called rear and deletion end
is called front. In queue two basic operations are performed:-
Insert
Delete.
Display
Reverse display.
List
List is also a linear data structure in which elements are arranged neither FIFO
nor LIFO. That means list is those type of linear data structure in which element
are arranged in random order that means in any order, element can be inserted
and in any order it can be deleted. In list many operation can be possible as the
choice of the user. List is implemented using array or link list. List is divided in
the following categories.
Non linear data structure:- Non linear data structure is those type of data
structure in which an element can have more then one successor and more then
one predecessor. That means non linear data structure is those type of data
structure in which after a particular element more then one element can be present
similarly before a particular element more than one element can also be present.
Non linear data structure is only one type that is graph.
Graph is a non linear data structure, which is the collection of vertices and edges.
It is also possible to say that graph is on order pair of (V,E) where
V={v1,v2,v3….vn} set of vertices and E={e1,e2,e3…..en}set of edges. The
element present in graph is called vertices and the connecting line present
between the vertices is called edges. Path is the collection of edges through which
we can move from one vertex to another vertex. Graph is divided according to the
type of path in two categories:-
1. Cyclic graph
2. Acyclic graph
Cyclic Graph:- Cycle graph is those of graph in which more then one path is
present between any two particular vertex.
5
Acyclic Graph:- Acyclic graph those type of graph in which more then one
path can not be present between any two particular vertex. Acyclic graph is also
called tree.
Tree: - Tree is an acyclic graph in which after a particular element more then
one successor can be present but at most one predecessor can be present.
Alternately we can say that tree is a non linear data structure which is used to
implement parent child relationship. According to the number of child and height
of the tree, it is divided in the following categories:-
1. Binary tree
1 Rear
2 Front
The insertion end is called rear end and the deletion end is called front end.
Queue can also be implemented using the concept of array and link list. In array
implementation the value of front and rear should be set in -1. In queue two basic
operation are possible –
1. Insert
2. Delete.
1. Display
2. Reverse display
Simple queue
Modify queue
Priority queue
Circular queue
D_queue
8
2 Reverse display.
1. Insert
2. delete.
9
In insertion operation the condition of over flowing must be tested. The condition
of over flowing is rear equal to size -1 of the array and front equal to -1. If the
Queue is not over flowing then the value of rear should be incremented by 1 and
at the rear position value should be inserted. If the upper part of the array is full
and lower part is empty then the upper element should be shifted to the lower
blocks and corresponding value rear and front should be set. After shifting the
value of rear should be incremented by 1 and value should be inserted in the rear
position of the array.
2 Reverse display.
2. Deletion
value of rear should be incremented by 1 and value should be inserted in the rear
position of the array.
In delete operation the condition of under flowing must be tested. The condition
of under following is front equal to rear. If the queue is not under flowing then
the value of front should be increment by 1 and value of front position of the
array, Should be deleted.
11
2 Reverse display.
Circular queue :- circular queue is also a liner data structure in which elements
are arranged using the concept of FIFO logically in circular form. Circular queue
is implemented using array and using link list. In array implementation a single
dimension array is necessary. for insertion purpose a real variable is necessary
and for deletion purpose front variable is necessary. In circular queue two basic
operations are possible.
1. Insertion
2. Deletion
1. Display
2. Reverse display
In reverse display operation the condition of under flowing should be tested. If
the circular queue is not under flowing then the elements should be displayed
from front position two rears -1 position in circular form.
In rev display operation the condition of under flowing should also be tested. If
the condition of under following is false then the element should be displayed
from rear-1 position to front position in circular form.
In rev display operation the condition of under flowing should also be tested. If
queue1 is not under flowing then the elements should be displayed from rear1
position to front 1 +1 position. If queue2 is not under flowing then the elements
should be displayed from rear 2 position to front 2-1 position.
Application of stack
Stack has various applications in programming as well as in computer system.
We know that computer execute postfix expression internally using the concept
of stack. User understands only infix expression and only supply infix expression
in the computer system. Infix expression is converted to postfix using the concept
of stack. In recursion a single functions calls by it- self and the previous value of
the called function stored in a stack and at the end all the value stored in the stack
are retrieved and return to the actual calling function.
Application of queue:-
Queue is most popularly used data structure in computer science. The main
application of Queue are most of the scheduling algorithm of process
management is implemented using the concept of queue first come first serve
scheduling is implemented using the concept of modify queue. Round robin
scheduling is implemented using the concept of circular queue. priority based
scheduling is implemented using the concept of priority queue. The concept of
multilevel priority queue based scheduling is implemented using the concept of
D-queue. The concept of back ground and fore ground processing is implemented
using the concept of D- queue.
14
List: - List is a linear data structure in which elements are arranged in random
order. That means list is those type of linear data structure in which elements are
arranged neither LIFO nor FIFO. List is implemented using array and link list.
Insertion operation in array is very time consuming operation due to right shift.
Operation of all elements present in the right side of the insertion point.
1 information part
2 link part.
Information part: - The information part actually contains the information for
the node. This part can be standard variable or user define type variable. That
means user can store any standard value in the information part. It is also possible
to store record type value in the information part. The link part is a pointer which
is used to store address of the next node or the address of the pervious node
according to the number of pointer. Link list is divided into two categories.
Single link list: - Single link list is those type of linear data structure in which
elements can be inserted or deleted in any order and the link part contains the
single pointer to points to the next node. This pointer is also called next pointer.
In single link list the information part can contain any type of values and the next
pointers contains address of the next node. The next pointer of last node contain
null value which represent this node is the last node. Every node is connected
with the next node using a single pointer. A simple node type pointer is present to
store the address of the first node from which any operation can be start.
Memory can be physically released using the free function for latter
allocation of nodes.
The concept of over following of values can not be arising in link list.
In single link list nodes are connected using a single pointer to point to the
next node. If the link list is accidentally destroyed then the chances of data
loss after the destruction point is maximum. Data recovery is not possible.
In single link list every node contains a single pointer to represent next
node So we can move only forwardly. Backward movement is not possible
without recursion.
Link list can not contain detail description about its own as total number of
node, Total no of deleted nodes, total number of updated nodes etc.
Without any operation user can not display the detail description about the
link list.
Circular link list :- To increase the data security of single link list, the concept
of single circular link is arise in which a next part of last node contains the
address of first node. In circular link list user can move from the end of the list to
the beginning of the list using a single step. That means circular link list increase
the data security as well as increase movement of control firstly.
For example:- Write a program for circular link list.
17
Ordered link list: - ordered link list is special type of single link list in which
every node inserted in sorted order, According to the value of some specific field
of information part. That means ordered link list is a sorted link list. It can be in
ascending order or descending order as same as priority queue.
Doubly Link List:- To increase the data security and movement of both way
direction in link list, the concept of doubly link list is arise. In Doubly Link list a
node is divided in three section:-
2 Information part
The left pointer or previous pointer is a node type pointer which is used to store
address of the previous node. Using left pointer user can move in back word
direction. The information part can store any standard values and any record type
value as the choice of the user. The right pointer or next pointer is used to store
the address of next node. Using next pointer or right pointer user can move
forwardly. The right pointer of last node contains a null value. Which indicates
this is last node. Similarly left pointer of first node contains a null value which
indicates this is the first node. In doubly link list every nodes are connected using
two link, So if a single link accidentally destroy then the chances of data loss is
minimum. In doubly link list every node contains two pointer one for the next
node and another for the previous node. So user can move forward and backward
in the entire list as the choice of the user.
Generally a simple pointer type variable is of node type is used to store the
address of the first node of the list. So it is not possible to store detail description
about the link list. A header node is a node in which the information part contains
various counter to store detail information. Such as total inserted node total
number of deleted node, total updated node etc. The next part of header node is
node type pointer to store address of first node of the list. Initially the value of all
the counter should be zero as well as the value of next pointer should be null after
every operation corresponding counter variables should be incremented or
decremented. User can display detail information about the list by the just
displaying the information part of header node with out executing any other
operation.
Circular double link list:- circular link list is those type of linear data
structure in which the right pointer of last node contains the address of first node
and the left pointer of first node contain the address of last node. Circular doubly
link list is the most secure liner data structure in which security of data element
maximum