Академический Документы
Профессиональный Документы
Культура Документы
NO:-1
Title:- Sorting list using array
Theory:-
Here sorting of list, we are using array. First we are
taking choise of user about ascending or decending order
of list. The elements of array are fixed by programme.
Then by using for loop & condition we are sorting list
as per users choise. Arry is a type of data structure
which contains a group of similar data types that share a
common name and has fixed length. The elements of an
array start at zero and at n-1 i.e in continuous pattern.
In sorting, we make usr of a temp.
Variablewhich tempararely stores the elements of a
arrary for carring out sorting operation.
Algorithm:
1) Consider an arrary a such that
a ={n1,n2…….nm}
2) N = a. length
3) For decending list
For {int i=0; i<n; i++}
{
For ( int j = i+1 ; j ++)
If a[i] < a [j]
{
Int temp = a [i];
a [i] = a [j];
a [j]= temp;
}
}
}
4) For ascending order
For (int I = 0; i<n; i++
{
For (int j = 0i +1 ; j < n; j++)
{
If (a[i] = a [j]) --
1--
{
Int temp = a [j];
a [j] = a [i];
a [j] =temp;
}
}
}
5) Display.
Conclusion:-
Thus elements I a given array sorted.
--2—
ROGRAM:-2
Title:- The Tower Of Hanoi
Theory:-
The tower at Honai problems consist of three
peg. A,B & C five disks of differing diameters are placed
on peg A so that a arger disk is always below a smaller
disk. The abject is to move the five disks to peg C using
peg Bas auxillary. Only the top disks an any peg may be
moved to another peg and a larger disk may be never
rest on smaller one.
Basically the tower of Honai problems works on
the principle of recursive function.
Let us consider the general casse of tri disks.
Suppose we had a solution for cn-11 disks we could state
the solution for n disks in terms of solutions for (n-1)
disks. This can be done by merely contiuously
substracting 1form n to eventually produce 1 or merely
moving a single disk from peg A to C.
Therefore we wil have developed a recursive
soln it we can state a soln for n disks in terms of n-1.
Suppose we could move four disks from peg A
to C. Then we could move the largest disks from A to C
and again apply the soln for four disks from B to C using
the now empty peg A as an aux
Thus we may state the recursive solution to
tower of Hanoi problem.
ALGORITHM:-
1)If n = 1 then move the single disk form A to C and
exit.
RESULT:-
Thus we have solved the towers of Hanoi by
using recursive function.
--3--
PROGRAM:-3
Title:- COPY BYTES FROM ONE FILES TO
ANOTHER.
Theory:-
As we copy characters using file reader or
file writer class, similary we are copying bytefrom one
file to another using file input stream & file output
stram.
First we bad created two objects of inbuild
class file, assign a particular file with .dat extention.
Then by using .read () fn we can read modify it. Then by
using .exit () we can exit from loop. After all these
things we have to close it that’s why we are using .close
() to close file.
Java provides two kinds of type stream
CLASS:-
1) INPUT STREAM CLASS:-
Input stream classes that are used to read 8
bit byte includea super classes for supporting
various I/P related functions.
2) OUTPUT STREAM CLASS:-
It si an adstract class.
INPUT
DATA
INFILE INPUT
PROGRAM
DATA
INFILE
Write ()
ALGORITHM:-
CONCLUSION:-
CONCLUSION:-
This we have concatenated and buffer the
contents of two files.
--6--
PROGRAM:-5
ADT:-
It is mathematical and logigal description of
datatype is knownas as ADT. There are two types of
stack.
1) Instance
2) Operation.
INSTANCE:-
Stack is a data structure which stores the data in
such a way that we canadd a element or delete an
element from only one side i.e from top of stack i.e stack
follows before scenario i.e the LIFO. & the first element
that we are inserted an the stack will deleted first.
OPERATION:-
There are four types of operation we can
perform on stack i.e push,pop,size can perform on stack.
In which push & pop operation are very important for
implementation of stack.
PUSH(l):-
By using push operation we can insert an
element an to the stack from only one side i.e from only
one side ie from top of stack we cant insert an element
from bottom of stack
POP():-
If we want to delete an element from the stack
then we are using POP() operation in which we can
delete an element from only one end i.e only of stack but
we have to check that whether stack is empty or not.
--7--
ALGORITHM OF STACK:-
Algorithm isempty ()
Return (TOP<0)
Algorithm size ()
Return (size top)
Algorithm push (l)
If (size ==n)
Throw full stock exception
Top = top+1
}
[top] = u
Procedure push (l)
If (size ==n)
Throws full stack exception
Top top + 1
Procedure pop ()
If (is empty() )
Throws Empty stack Exception
Temp S[top]
S[top] null
Top top -1
EXAMPLE:-
1) Delete an element from bottom
2) Insert an element A from bottom.
3) Insert element B,C,D TO stack.
4) Delete an element from top.
5) Insert an element
E,F,G to stack.
The size of stack
is 6
STEP-I:-
1) Delete an element
from bottom.
As there is no
element present in
stack. Stack
undergoes
A
underflow.
--8--
STEP-II:- 2) Insert an element A
0 top = bottom
=0
C
B
A
5
4
3 TOP
1
BOTTOM
0
--9--
STEP-IV :- 4) Delete an element from top.
C
B
A
3
2 TOP
1
BOTTOM
0
G 5 TOP
F 4
C
B
A
3
1
BOTTOM
CONCLUSION:-
Here we are studied stack method.
--10--
PROGRAM:-6
Title:- PROGRAM FOR QUEUE
Theory:-
The queue can be formally defined as ordered
collection of element has two ends name front and rare.
QUEUE AS AN ADT:-
A is mathematical and logigal description of array is
called as ADT. It has two parts Instance and Operations.
INSTANCE:-
The queue is collection of elements in which
element can be inserted by one end called rare and
elements get detected from one end called front.
OPERATIONS:-
Que – full ( ):- Cheks where queue is full or not.
Que – empty ( ) :- Cheks the queue is empty or
not.
Que – insert ( ) :- Insert the element in queuee
from rare end.
Que – delete ( ):- Delete the elements in queue
from fornt end.
QUEUE IMPLEMENTATION:-
1) Linear array
2) Circular array.
1
20 30 40 50
0
Front rear
--11--
ALGORITHM:-
Procedure isempty( ) –
if (f = = -1)
the queue is empty
Procedure insert (l) –
if (size = = N)
return full Queue Exception.
r = (r + 1 ) % N
A [ r] = L
Procedure delete ( ) :
Is ( isempty (j))
EXAMPLE:-
Create a circular queue of size 6 and perform following
operations.
i) Delete an element from right.
ii) Add A,B,to left.
iii) Add C to left.
iv) Add D,E to right.
v) Delete an element from right.
vi) Add F,G,H to right
vii) Add I to left.
viii) Delete an element from left.
ix) Delete an element from right.
1 2 3 4 5 6
Left
Right
l=r = 0
--12--
1) Delete an element from right.
As there Is no element present in queue, queue underflow occurs.
2) Add A,B to left.
1 2 3 4 5 6
Left
Right A B
l=6, r=1
3) Add C to left
1 2 3 4 5 6
Left
Right A C B
l=5, r=1
4) Add D, E to right
1 2 3 4 5 6
Left
Right A D E C B
l=5, r=3
1 2 3 4 5 6
Left
Right A D E B
l=6, r=3
--13--
6) Delete an element from right
1 2 3 4 5 6
Left
Right A D B
l=6, r=2
1 2 3 4 5 6
Left
Right A D F G H B
l=6, r=5
8)Add I to left
As queue is full then it undergoes overflow.
l=1, r=5
10) Delete an element from right
1 2 3 4 5 6
Left
Right A D F G
l=1, r=4
CONCLUSION:-
Hence we are studied queue method.
--14--
PROGRAM:7
Title:- QUICK SORT
DIVIDE:-
Split the array into two sub arrays that each
element in the left sub array is less than or equal the
middle element and each element in the right sub array
is greater than the middle element. The splitting of the
arrry into sub array is based on pivot element. All the
elements that are less than pivot should be in the left.
Sub array and all the elements that are move than pivot
should be in right sub array.
CONQUER:-
Recursively sort the two sub array.
COMBINE :-
Combine all the sorted elements in a
group to form a list of sorted elements.
In merge sort the division of array
based on the position of array elements but in
quick sort this division is based on actual value
of elements.
ALGORITHM:-
Public vaid quick ( int low, int high)
{
If m, I;
If (low,high)
{
m = Partition (low, m-1);
quick (low,m-1);
quick (m+1 ,high);
--15--
}
}
EXAMPLE:-
List- 30 70 90 10 50
Step I- 30 70 90 10 50
I j
(low pivot) (high)
Step II- 30 70 90 10 50 (stop incrementing I, and
start pivot i j
decrementing j)
Step III- 30 70 90 10 50 (stop decrementing j)
pivot i j --
16--
Step VII - 30 10 90 70 50
pivot i,j
Step VIII - 30 10 90 70 50
pivot I j
Step IX - 30 10 50 70 90 (swaping)
pivot middle
l.sub list:-
30 10
i j
(pivot low) (high)
Checking condition for I & j Swaping I & j
i.e l.sub list = 1030
R.sub list:-
70 90
i j
(pivot low) (high)
Checking condition for I & j no operation can be
done.
i.e r.sub list = 70 90
started list = 10 30 50 70 90 --
17--
PROGRAM : 8
Title:- MERGE SORT
{
Temp [k] = A [j];
I++;
K++;
}
Else
{
Temp [K] = A [j];
J++;
K++;
}
While(i< = mid)
{
Temp [k] = A[i];
I++;
K++;
}
While (j<= high)
{
Temp [k] = A [j];
J++;
K++;
}
For(k = low; k<=high;k++)
A[k] = temp [k];
}
CONCLUSION:-
Thus we implement the merge sort.
--19--
EXAMPLE:-
70 20 30 40 10 50
7 2 3
0 0 0
4 1 5
0 0 0
7 20 3 4 1 5
0 0 0 0 0
20 2070
7 230 70
3
1 2 3 4
10 5
1 7
40 40
14 50
50 50
0 0 0
0 0 0 0 0 000
--20--
PROGRAM:9
Theory:-
When an array of elements is almost sorted then it is
best case complexity. The best case time complexity of
insertion sort is O (n).
--21--
ALGORITHM:-
Public void Insert_ sort (int n)
{
Int temp,j:
For (int i = 1; i< = -1; i++)
{
Temp = A[i];
j= i-1;
while ( ( j>= 0 )& & A[j] > temp ) )
{
A [j+1] = A[j];
J= j-1;
}
A[j+1] = temp;
}
}
CONCLUSION:
EXAMPLE:-
LIST – 20, 50 10 90 40
Step – I:-
20 5 1 9 4
0 0 0 0
Started Unstarted
2 5 1 9 40
0 0 0 0
Step – II
Started Unstarted
--22--
Step – III
1 2 50 9 4
0 0 0 0
Started Unstarted
Step – IV
1 20 5 9 4
0 0 0 0
Started Unstarted
Step –V
1 2 4 5 90
0 0 0 0
Started list
--23--
PORGRAM:-10
THEORY:-
Linked list is a very common data structure usedto
store sililar data in memory. The elements of linked are
not stored in continues memory location. They are
scattered all over the memory. But these elements are
still boubded to each other. This order and bounding
between thr elements is maintained byexplicit links
between them as shown in fig.
Linear linked list.
Into Next Into Next Into Next
4 2 9 nu
ll
Left
Node-1 node-2 node
EXAMPLE:-
1. Create node into next
Null Null
RESULT:-
B C
F G
E
D E E
D
D D
H I
J
K
In order H D B I K I E A F C
A
--26--
POSTORDER:-
Public posr order (node.temp)
{
If (temp: = null)
A
{
Post order
B (temp.left)
C
{ A E A
System.out.print ln(“”+ temp.data);
F F
} G
D E C
Postorder(temp.right);
C A
} A
} H I
EXAMPLE:-
J
K
INORDER H D B I K I E A F C
G
CONCLUSION:-
Thus we have implemented tree.
A
--27--
PROGRAM:-12
THEORY:-
A graph is collection of nodes which are verticles
connected in pairs by line segments called as edge E.
There are two types of graph.
1) Undirected graph
2)Directed graph
1) Undirected graph:-
In undirected graph where one in each edge is an
undergenerated pair of
EXAMPLE:-
A B
C D
2) Directed graph:-
It is usually represented as diagraph. It is
represented by a specific direction or by directed pair.
--28--
EXAMPLE:-
A B
D C
CONCLUSION:-
Thus we have implemented program for graph.
--29--
LIST OF EXPERIMENTS
Sr.No. Name of the Experiment
01. Sorting list using array
8 Graphs 04
Graph as an ADT
Graph representation
Graph Traversal (Depth First Search , Breadth First
Search)
Theory Examination :
1. Question paper will be comprising of total 7 questions, each of 15 marks.
2. Only 5 questions need to be solved.
3. Q.1 will be compulsory and based on entire syllabus.
4. Remaining questions will be mixed in nature. ( e.g. – suppose Q.2 has a
part(a)from, module 3 then
part (b) will be from any module other than module 3.)
5. In question paper weightage of each module will be proportional to number of
respective lecture
hours as mentioned in the syllabus.
Term Work :
Text Books :
1. Y.Langsam , M.J.Augenstein and A.M.Tanenbaum. , “Data Stures
using JAVA”, Pearson Edition.
2. J.Foley, Van Dam , S.Feiner, J.Highes, “Computer Graphics
Principles and practice”,
3. 2nd edition , Pearson Education , 2003, ISBN 81 -7808-038-9
Reference Books :
• John R. Hubbard and Harry “data Structure with java”- pearson Education
• Mark Allen weiss ”Data Structure and algorithm Analysis in C++ ”. 3rd
EDI-Pearson Education
• Sanjay Pahuja, “A Practical To data Structure & Algorothm”, 1st Edi, New
Age International Edi
• Alan L. Tharp “File Organization and Processing ”,Amazon publication
LABORATORY MANUAL
Department
Of
Computer Engineering
Semester :- III
DATA STRUCTURES & FILES