Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Data Structure

data structure notes

Uploaded by

Prince Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Data Structure

data structure notes

Uploaded by

Prince Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 19

1

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

 Nonlinear data structure

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.

Two subsidiary operations are also possible on stack.


3

 Display or peep

 Reversely display or reverse 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.

Two subsidiary operation can also be performed on queue.

 Display

 Reverse display.

Queue is divided in the following categories:-

(1) Simple queue

(2) Modify queue

(3) Priority queue

(4) Circular queue

(5) Double ended queue


4

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.

1. Single link list

2. Ordered link list

3. Circular link list

4. Doubly link list

5. Circular doubly link list

6. Header link list

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

2. Binary search tree

3. Threaded binary tree

4. Extended binary tree

5. N-ary search tree ( B - Tree )

Application of Data Structure or use of Data Structure


The main purpose of data structure is to arrange huge no of element in such a way
that insertion, deletion, searching can be performed fastly and efficiently.

Stack is used to convert infix expression to its equivalent to postfix


expression. It is also used to evaluate value postfix expression .In recursion
system stack is created to store previous value of the recursive function.

Queue is used to implement the concept of scheduling


algorithm of process management. In first come first serve scheduling modified
queue is used. In round robin scheduling the concept or circular queue is used. In
priority based scheduling the concept of priority queue is used. Queue is also
used to convert infix expression to its equivalent prefix expression. It is also used
in topological shorting by which appropriate topology to connect computer and
internet.

List is used to store huge no of records in sequential


form. Using the concept of list sequential file management is implemented.

Graph is used to establish any network system LAN,


WAN, MAN. It is also used in mobile networking. Graph is used to implement
problem of transportation establish traffic system of a city.
6

Tree is used to search element very fastly. Generally the


concept of tree is used to implement the concept of DBMS. In DBMS generally
the concept of B- tree is internally implemented to arrange huge number of
records.

Qn. Define Stack? Explain it, with suitable example .


stack is a linear data structure in which element are arranged using the concept of
LIFO(last in first out )or FILO(first in last out) that means in stack last inserted
element will be deleted first and first inserted element will be deleted last. Stack
can be implementing using the concept of array or link list. Stack has only one
end which is called top of the stack. A single end is used to insert and delete
element. In stack two basic operations are possible push and pop. The insertion
operation is called push operation. In push operation the condition of overflowing
must be tested. In stack the condition of overflowing is top =size -1 of the array.
If the stack is not overflowing then the value of top should be increment by one
and at the top position value should be pushed.

The deletion operation is called pop operation. In pop operation


the condition of under flowing must be tested. The condition of under flowing is
top equal to -1 (top=-1). initially the value of top should be set by -1. In pop
operation value should be deleted form the top position of array after that the
value of top should be decrement by one

Two subsidiary operations can also be possible on stack –peep


and rev_peep the display operation is called peep operation. In display operation
condition of under flowing should be tested. If the stack is not under flowing then
the value should be display form top position to zero position of the array.

The reverse display operation is called rev peep operation. In


reverse peep operation the condition of under flowing should also be tested. If the
stack is not under flowing then the element should be display from zero position
to top position of the array.
For example :- it self.
7

Qn. What is Queue? Explain it with suitable example.


Queue is 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 the last inserted element will be deleted
last. Queue has two end:-

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.

Two subsidiary operation are also possible on queue –

1. Display

2. Reverse display

Queue is divided in the following categories according to the arrangement of


element.

 Simple queue

 Modify queue

 Priority queue

 Circular queue

 D_queue
8

Simple queue:-simple queue is a simplest queue implementation using


array .there is no concept of simple queue using link list. Simple queue is also a
linear data structure in which elements are arranged using the concept of FIFO.
The only limitation of simple queue is that if once it is full then there are no
chances to insert any element although that lower part is empty. That means no
shifting is possible in simple queue. In simple queue two basic operation insertion
and deletion are possible. In insertion operation the condition of over following
must be tested. In simple Queue the condition of overflowing is rear equal to size
-1(rear = size-1) of the array. If the queue is not over flowing then the value of
rear should be incremented by 1 and element should be inserted in the rear
position in 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.

Two subsidiary operations are also possible in Simple queue.


1 Display

2 Reverse display.

Display:- In display operation the condition of under following should also be


tested. The condition of under flowing is front = rear. If the queue is not under
flowing then value should be displayed from front+1 position to rear position. In
reverse display operation the condition of under flowing should also be tested. If
the queue is not under flowing then elements should be displayed from rear
position to fronts +1 position.

Modify queue: - Modify queue is the extension of simple queue, in which


elements are arranged using the concept of FIFO or LILO and they can be shifted
from Upper part to Lower Part as the requirement of the user. It is also possible to
say modify queue is the advance queue from the simple queue the condition of
over flowing only changed in modify queue. Condition of over following is rear
equal to size -1 and front equal to -1. That means in modify queue elements can
be shifted from upper part and lower part if lower part is empty. In modify queue
two basic operation are possible.

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.

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.

Two subsidiary operations are also possible in Modified queue.


1 Display

2 Reverse display.

Display:- In display operation the condition of under following should also be


tested. The condition of under flowing is front = rear. If the queue is not under
flowing then value should be displayed from front+1 position to rear position. In
reverse display operation the condition of under flowing should also be tested. If
the queue is not under flowing then elements should be displayed from rear
position to fronts +1 position.

Priority queue :- priority Queue is also a linear data structure, in which


elements are arranged using the concept of FIFO and inserted according to the
value of the priority field. In priority Queue elements are inserted in ascending
order or descending order, According to the priority field. In priority Queue Two
basic operation are possible :-
1. Insertion

2. Deletion

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
10

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

Two subsidiary operations are also possible in priority queue.


1 Display

2 Reverse display.

Display:- In display operation the condition of under following should also be


tested. The condition of under flowing is front = rear. If the queue is not under
flowing then value should be displayed from front+1 position to rear position. In
reverse display operation the condition of under flowing should also be tested. If
the queue is not under flowing then elements should be displayed from rear
position to fronts +1 position.

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

Initially the value of front and rear should


be set to zero(0) and the flag variable should also be zero. In insertion operation
the condition of over following should be tested. The condition of over following
in circular queue is front is equal to rear (front = rear) and flag is equal to 1 ( flag
= 1). If the queue is not over following then the element should be inserted at the
rear position of the array. The value of rear should be increment by 1 in such a
way that after searching the value of rear to size -1 then the value of rear should
be zero. So the modulo division by size of the array is the increment the process
as rear=(rear+1)%size. The value of flag variable should be set to 1 in insertion
operation.
12

In deletion operation the condition of under following should be tested. The


condition of under following in circular Queue is front is equal to rear (front =
rear) and flag is equal to 0 (flag = 0). If the queue is not under following then the
element from front position should be deleted. After that the value of front should
be incremented as front = (front +1) %size. In deletion operation the flag variable
should be set to zero.

In circular queue two subsidiary operation are also possible

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.

D queue :- D queue is also a linear data structure in which elements are


arranged using the concept of FIFO in which two queue is implemented using a
single array. That means a single array is present and two Queue are implemented
in the array. So, two set of front and rear variable is necessary as rear1 & front1
and rear2 & front2. Initially the value of rear 1 and front 1 is set to -1 and rear 2
and front 2 is set to size of the array. Queue1 is implemented in the lower
segment of the array and Queue 2 is implemented in the upper segment of the
array. In insertion operation of queue, condition of over following should be
tested. The condition of over following in queue1 is rear 1+1 is equal to rear 2
and front1 is equal to -1( front1 = -1 ). If the queue is not overflowing then the
value of rear1 should be increment by one and the value should be inserted at the
rear1 position. Similarly in insertion operation of Queue2, the condition of
overflowing should also be tested. The Condition of overflowing of Queue2 is
rear 1+1 is equal torear2 ( rear1+1 = rear2 ), and front2 is equal to size ( front2 =
size ). If the queue2 is not overflowing then the value of rear2 should be
decremented by one and value should be inserted at the rear2 position of the
array.
13

In deletion operation, the condition of under flowing should be tested. In


deletion operation of Queue1 the condition of under flowing is front1 = rear1, if
the queue1 is not under flowing then the value of front1 should be increment by 1
and the value from front1 position should be deleted. Similarly the condition of
under flowing of Queue2 is rear2 = front2. if Queue2 is not under flowing then
the value of front2 should be decrement by 1 and the value from front2 position
should be deleted.

In display operation the condition of under flowing should also be tested.


If queue1 is not under flowing then the element should be display front 1+1
position to rear 1 position of the array. If queue2 is not under flowing then the
element should be displayed from front 2-1 position to rear position of the same
array.

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

In topological sorting the concept of modify queue is implemented. Any customer


services system is purely based on modified queue. Railway reservation system,
bus reservation system, airlines reservation systems are based on modified queue.

Qn. What is List? Explain it with Suitable Example

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.

Array has various disadvantages to handle huge no of data item in


linear form. The size of array is fixed. So, memory block can be in sufficient as
the requirement of the user. It is also possible that the blocks are huge in
compression with the requirement of the user, So the chances of memory wastage
can be maximum.

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.

Similarly deletion operation in array is also a very time consuming


operation due to left shift, operation of all elements present in the right side of the
deletion point.

To remove the disadvantages of array, two new concepts are arise:-


Dynamic memory allocation and concept of link list.

Dynamic memory allocation is those type of memory allocation process by


which we can allocate memory for the variables at the time of execution using the
function malloc, calloc and realloc. Using the concept of dynamic memory
allocation the concept of insufficient memory and a huge memory of array can be
removed. Using dynamic memory allocation user can allocate specific number of
blocks for a variable as the requirement of the user. There are no chances of
memory wastage or extra memory for wastage.

To remove the disadvantages of array related to insertion and deletion operation.


The concept of link list is arise. Link list is a linear data structure in which
elements can be inserted or deleted in any order without shift operation and they
are connected to each other using pointers. Every elements of link list is called
node. A node is divided in two parts:-
15

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.

1 Single link list

2 Doubly link list

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.

Link list has following advantages:-


 Insertion operation is not a time consuming operation because shifting is
not necessary to insert new element.
16

 Deletion operation is not a time consuming operation because left shifting


is not necessary to delete elements.

 Memory can be physically released using the free function for latter
allocation of nodes.

 The chances of memory wastage are minimum because memories are


allocated dynamically as the requirement of the user.

 The concept of over following of values can not be arising in link list.

The following disadvantages are present with 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.

 In single link list any operations is performed sequentially and so for a


huge no of data item any operation can be very slow.

 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.

For Example: - Write a program of doubly link list.


18

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:-

1 Left pointer or previous pointer

2 Information part

3 Right pointer or next pointer.

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.

Since doubly link list is also a linear data structure. So any


operation on doubly link list is performed sequentially. So for huge number of
data elements any operation becomes a very time consuming operation. To
remove this disadvantage non linear data structure is arise. Doubly link list can
not contain detail information about its own. Such as total number of node, total
deleted node, total updated node etc. To remove this disadvantage, the concept of
header node is arise
19

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

For Example:- It Self

You might also like