Sie sind auf Seite 1von 41

# Lab Manual

of Engineering
Pune-412105
Lab Manual Page No 01
!e"artment of
#om"uter engineering
\$ormat no %e&ision
%e&ision
!ate
#lass 'E
2010-2011
MAE*A#A*#+MP* 01 21*12*11 'emester ,,
Subject:
Theory Practical Term Work Practical Oral
-- 04 -rs Per .ee/ 50 50 --
'r No 0itle of Assignment
0ime '"an
1No of 2ee/s3
1
.rite a #44 "rogram to create binary tree and
"erform recursi&e and non-recursi&e tra&ersals
1
2
.rite a #44 "rogram to create binary tree \$ind
height of the tree and "rint leaf nodes \$ind mirror
image5 "rint original and mirror image using le&el-
2ise "rinting
1
6
.rite a #44 "rogram to create a binary search tree
,nsert and delete elements after creation
7
4
.rite a #44 "rogram to create in-order threaded
binary tree and "erform recursi&e and non recursi&e
tra&ersals
7
5
.rite a #44 "rogram to re"resent gra"h using
ad8acency matri9 and "erform !\$' and :\$'
1
;
.rite a #44 "rogram to re"resent gra"h using
ad8acency list and "erform !\$' and :\$'
7
<
%e"resent gra"h using ad8acency matri9 and generate
minimum s"anning tree using Prim=s algorithm
1
>
%e"resent gra"h using ad8acency matri9 and find
shortest "ath using !i8/stra=s algorithm
7
?
.rite a #44 "rogram for im"lementation of : tree
7
10
.rite a #44 "rogram for im"lementation of A@L
tree
7
11
,m"lementation of direct access file using different
collision resolution techniAues
1
12
.rite a "rogram to add binary numbers 1assume one bit as
one number3 Bse '0L stac/
7
16
.rite a #44 "rogram to im"lement 'LL5 !LL5 #LL
and com"are 2ith '0L im"lementation
1
14
.rite a #44 "rogram to im"lement stac/ and Aueue
using 'LL and com"are 2ith '0L im"lementation
7
1
Lab Manual
15
.rite a "rogram to im"lement !eAueue 1!ouble
ended Aueue3 using '0L
7
1;
.rite a "rogram to use '0L for sorting and searching
2ith user defined records
7
1<
Mini Pro8ect
7
Pre"ared :y) #hec/ed :y)
1 Mrs Anita 0hite 1Prof 'ACain
2 Ms'u8ata 0a"/ir
2
Lab Manual
Assignment No !
Title o" Assignment: #reation of binary tree and "erform recursi&e and non-
%ecursi&e tra&ersals
Algorithms:
#reate and \$nsert:
1 Acce"t a random order of numbers from the user 0he first number 2ould be inserted
at the root node
2 0hereafter5 acce"t the left child and right child of each node
6 Perform this till you reach a null "ointer5 the "lace 2here the "resent data is to be
inserted
4 Allocate a ne2 node and assign the data in this node and allocate "ointers
a""ro"riately
Tra%ersals &'ecursi%e(:
1 ,norder) 0he recursi&e function 2ill recei&e the root of the tree 1or subtree3 from
2here inorder tra&ersal is to be initiated Algorithm is to "roceed left5 2hich in this
case is to call the same function 2ith the left child of the node5 "rint the data and then
"roceed right5 2hich in this case is to call the same function 2ith the right child of the
node
2 Preorder ) ,norder 2as L!%5 first mo&e left5 access data and then mo&e right
Preorder is !L%5 first access data5 mo&e left and then mo&e right
6 Post order is L%!5 first mo&e left5 then mo&e right and then access the data
Tra%ersals &Non 'ecursi%e(
1 0he same effect 2hich ha""ened during the recursi&e run needs to be effected here
2 !eclare a stac/ 2hich holds "ointers 1 the nodes of the :03
6 ,n the inorder case5 begin 2ith a loo" 2hich mo&es left as far as it can5 "ushing the
current node on the stac/
4 .hen you reach null5 "o" a node from the stac/5 access and dis"lay its data5 mo&e
right and go bac/ to ste" 6 ,f stac/ is em"ty at ste" 45 e9it the loo"
5 0he "reorder and "ostorder tra&ersals 2ould "roceed in an identical manner5 e9ce"t
the "osition of dis"laying the contents of data 2ould &ary
6
Lab Manual
Testing:
Test #onditions:
'im"le in"ut of random numbers !is"lay the inorder tra&ersal ,t must be a sorted
list of the numbers entered5 since a :0 has been created 0his 2ould be "ro&ed that
the :0 has been constructed "ro"erly 0he "reorder and "ost order tra&ersals 2ould
gi&e a listing of data5 2hich could be chec/ed by dra2ing the :0 on "a"er and
chec/ing if it 2ere true
\$n)ut:
Enter data 1numbers3 to be stored in the binary tree E&ery node in the :0 2ould contain
6 fields) data5 left child "ointer and right child "ointer
Out)ut:
!is"lay the list of elements in the serial order as they a""ear in the three tra&ersals)
inorder5 "reorder and "ostorder 1both recursi&ely and non recursi&ely3
*A+S:
1 .hat is the time com"le9ity of binary search algorithmD
2 .hat are right and left s"in binary treesD
6 .hat is the conce"t of threads in treesD -o2 it is hel"fulD
4 .hat is height and 2eight balanced treesD
#onclusion:
4
Lab Manual
Assignment No,
Title o" Assignment: .rite a "rogram to create a :inary tree and find the height of tree
and "rint its leaf nodes \$ind its mirror image5 "rint original and mirror image using
le&el-2ise "rinting
Algorithms:
#reate and \$nsert:
1 Acce"t a random order of numbers from the user 0he first number 2ould be inserted
at the root node
2 0hereafter5 e&ery number is com"ared 2ith the root node acce"t the left child and
right child of each node
6 Perform this till you reach a null "ointer5 the "lace 2here the "resent data is to be
inserted
4 Allocate a ne2 node and assign the data in this node and allocate "ointers
a""ro"riately
-eight o" .T :
1 0his algorithm is based on the idea of storing the nodes of e&ery le&el of the :'0 in a
dynamic Aueue 1lin/ list3 ,t is also simultaneously useful to "rint the tree le&el 2ise
0he total number of le&els accessed 2ould be the height of the tree
2 ,nitialiEe the contents of the list 2ith the root of the :'0 0he counter
noFofFnodesFinFcurrentFle&el G1 and the le&elFaccessed G1
6 Access noFofFnodesFinFcurrentFle&el from the lin/ list and add all their children to
the list at the end and simultaneously /ee" trac/ of the number of nodes accessed in
the ne9t le&el in a &ariable 2hich at the end is assigned bac/ to
noFofFnodesFinFcurrentFle&el Also increment le&elFaccessed5 indicating one more
le&el accessed in the :'0
4 #ontinue ste" 6 re"eatedly till noFofFnodesFinFcurrentFle&el is 05 2hich means no
more nodes in the ne9t le&el 0he &alue stored in the &ariable le&elFaccessed is the
height of the :'0
10he abo&e is a non recursi&e im"lementation to find the height of the :'0 +ne could
also 2rite a recursi&e algorithm to do the same3
Lea" Nodes o" .T :
1 0here are many algorithms to find the leaf nodes of a :0 0he one considered here is
based on the idea that one could do a sim"le inorder tra&ersal of the :0 and 8ust
before "rinting the data as one normally does in an inorder tra&ersal5 chec/ if both the
left and right nodes are NBLL ,f so5 it means the node under consideration is a leaf
node and must be "rinted
2 ,norder) 0he recursi&e function 2ill recei&e the root of the tree 1or subtree3 from
2here inorder tra&ersal is to be initiated Algorithm is to "roceed left5 2hich in this
case is to call the same function 2ith the left child of the node5 "rint the data if both
5
Lab Manual
left and right "ointers are NBLL and then "roceed right5 2hich in this case is to call
the same function 2ith the right child of the node
6 0hus all the leaf nodes of the :0 are "rinted
/irror o" Tree :
1 \$ollo2ing is a algorithm of a recursi&e function to find mirror of the tree 0he
function mirrorF0ree acce"ts a "ointer to a tree as the "arameter ,nitially the root
node is "assed later the roots of the subseAuent subtrees are "assed as the "arameter
2 0he function begins by chec/ing if the "ointer "assed is not NBLL ,f not5 allocates a
ne2 node Assigns the data of the original node to the co"ied node Assigns the left
child of the ne2 node by calling the function mirrorF0ree 2ith the right child of the
original node and assigns the right child of the ne2 node by calling the function
mirrorF0ree 2ith the left child of the original node ,f the "ointer "assed is NBLL5
NBLL is returned by the function else the ne2 node created is returned
Le%el 0ise )rinting :
1 0his algorithm is based on the idea of storing the nodes of e&ery le&el of the :0 in a
dynamic Aueue 1lin/ list3
2 ,nitialiEe the contents of the list 2ith the root of the :0 0he counter
noFofFnodesFinFcurrentFle&el G1 and the le&elFaccessed G1
6 Access noFofFnodesFinFcurrentFle&el from the lin/ list Print the Le&el Number and
all the data of all the nodes of the current le&el 'imultaneously add all their children
to the list at the end and /ee" trac/ of the number of nodes accessed in the ne9t le&el
in a &ariable 2hich at the end is assigned bac/ to noFofFnodesFinFcurrentFle&el
Also increment le&elFaccessed5 indicating one more le&el accessed in the :0
4 #ontinue ste" 6 re"eatedly till noFofFnodesFinFcurrentFle&el is 05 2hich means no
more nodes in the ne9t le&el
10he abo&e is a non recursi&e im"lementation to do le&el 2ise "rinting of the :0 +ne
could also 2rite a recursi&e algorithm to do the same3
Testing:
Test #onditions:
'im"le in"ut of random numbers !is"lay the height of the tree and the leaf nodes 0he
:'0 entered could be dra2n on a rough "age and one could chec/ if the height calculated
and the leaf nodes "rinted are correct
\$or eg5 Enter) 645 125 5;5 ;5 145 405 and <0
0he height of the :'0 is 6
0he leaf nodes are ;5 145 40 and <0
\$or Mirror ,mage)
Enter ) 645 125 5;5 ;5 145 405 <0
;
Lab Manual
Le&el 2ise "rinting of original tree
Le&el 1 ) 64
Le&el 2 ) 125 5;5
Le&el 6 ) ;5 145 405 <0
Le&el 2ise "rinting of the mirror tree
Le&el 1 ) 64
Le&el 2 ) 5;5 12
Le&el 6 ) <05405 145;
\$n)ut :
Enter data 1numbers3 to be stored in the binary tree E&ery node in the :0 2ould contain
6 fields) data5 left child "ointer and right child "ointer
Out)ut
0he height of the tree and the list of its leaf nodes
0he original and mirror image "rinted le&el 2ise
*A+S:
1 -o2 to create the mirror image of the treeD
2 .hat is the logic for "rinting the tree le&el 2iseD
6 .hat is the ad&antage of creation of the mirror imageD
#onclusion:
<
Lab Manual
Assignment No1
Title o" Assignment: .rite a "rogram to create a binary search tree ,nsert and delete
elements after creation
'ele%ant Theory 2 Literature Sur%ey: (Brief Theory Expected)
:inary search tree 1:'035 2hich may sometimes also be called an ordered or sorted
binary tree5 is a node-based binary tree data structure 2hich has the follo2ing "ro"erties
1 0he left subtree of a node contains only nodes 2ith /eys less than the nodeHs /ey
2 0he right subtree of a node contains only nodes 2ith /eys greater than the nodeHs
/ey
6 :oth the left and right subtrees must also be binary search trees
Ienerally5 the information re"resented by each node is a record rather than a single data
element -o2e&er5 for seAuencing "ur"oses5 nodes are com"ared according to their /eys
rather than any "art of their associated records
0he ma8or ad&antage of binary search trees o&er other data structures is that the related
sorting algorithms and search algorithms such as in-order tra&ersal can be &ery efficient
:inary search trees are a fundamental data structure used to construct more abstract data
structures such as sets5 multisets5 and associati&e arrays
Algorithms:
\$nsertion: ,nsertion begins as a search 2ould beginJ if the root is not eAual to the &alue5
2e search the left or right subtrees as before E&entually5 2e 2ill reach an e9ternal node
and add the &alue as its right or left child5 de"ending on the nodeHs &alue ,n other 2ords5
2e e9amine the root and recursi&ely insert the ne2 node to the left subtree if the ne2
&alue is less than the root5 or the right subtree if the ne2 &alue is greater than or eAual to
the root
-ereHs ho2 a ty"ical binary search tree insertion might be "erformed in #44)
/* Inserts the node pointed to by "newNode" into the subtree rooted at
"treeNode" */
void InsertNode(Node* &treeNode, Node *newNode)
{
if (treeNode == NULL)
treeNode = newNode
e!se if (newNode"#\$ey % treeNode"#\$ey)
InsertNode(treeNode"#!eft, newNode)
e!se
InsertNode(treeNode"#ri&ht, newNode)
'
>
Lab Manual
3eletion:
0here are three "ossible cases to consider)
!eleting a leaf 1node 2ith no children3) !eleting a leaf is easy5 as 2e can sim"ly
remo&e it from the tree
!eleting a node 2ith one child) %emo&e the node and re"lace it 2ith its child
!eleting a node 2ith t2o children) #all the node to be deleted N !o not delete N
,nstead5 choose either its in-order successor node or its in-order "redecessor node5
R %e"lace the &alue of N 2ith the &alue of R5 then delete R
As 2ith all binary trees5 a nodeHs in-order successor is the left-most child of its right sub
tree5 and a nodeHs in-order "redecessor is the right-most child of its left sub tree ,n either
case5 this node 2ill ha&e Eero or one children !elete it according to one of the t2o
sim"ler cases abo&e
!eleting a node 2ith t2o children from a binary search tree 0he triangles re"resent sub trees of arbitrary
siEe5 each 2ith its leftmost and rightmost child nodes at the bottom t2o &ertices
#onsistently using the in-order successor or the in-order "redecessor for e&ery instance of
the t2o-child case can lead to an unbalanced tree5 so good im"lementations add
inconsistency to this selection
Testing:
Test #onditions:
'im"le in"ut of random numbers ,t must be a sorted list of the numbers entered5 since a
:'0 has been created 0his 2ould be "ro&ed that the :0 has been constructed "ro"erly
\$n)ut:
Enter data 1numbers3 to be stored in the binary search tree E&ery node in the :'0 2ould
contain 6 fields) data5 left child "ointer and right child "ointer
Out)ut:
Element should be inserted*deleted at the "ro"er "laces in the :'0
?
Lab Manual
*A+S:
1 -o2 to create the :'0D
2 .hat is the logic for "rinting the :'0D
6 .hat is the logic for inserting element into and deleting element from :'0D
#onclusion:
10
Lab Manual
Assignment No4
Title o" Assignment: #reation of binary inorder threaded tree 1:'03 and "erform inorder
Algorithms:

#reate and \$nsert:
1 Acce"t a random order of numbers from the user 0he first number 2ould be inserted
at the root node
2 0hereafter5 e&ery number is com"ared 2ith the root node ,f less than or eAual to the
data in the root node5 "roceed left of the :'05 else "roceed right
6 Perform this till you reach a null "ointer5 the "lace 2here the "resent data is to be
inserted
4 Allocate a ne2 node and assign the data in this node and allocate "ointers
a""ro"riately ,nitialiEe all the thread &alues to Kf= 1false3
#ould be done in t2o 2ays) one after :'0 is created and the other inserting nodes in the
inorder "osition of the :'0 as and 2hen it a""ears
1 \$or the first method5 run an inorder tra&ersal 1by "re&ious algorithm3 and store the
nodes of the inorder tra&ersal as they a""ear in a linear list
2 0hen read the list of nodes and if a node has its left or right "ointer "ointing to NBLL5
ma/e it no2 "oint to the inorder "redecessor or successor res"ecti&ely and assign the
thread &alues to Kt= indicating true Assign a head node5 2ho 2ill be "ointed at by the
left "ointer of the 1
st
node in the inorder tra&ersal and by the right "ointer of the last
node in the inorder tra&ersal
,n the other techniAue5 2hen you 2ant to insert nodes in an e9isting threaded tree5 do the
follo2ing )
1 ,f a node t is to be inserted as the right child of s in a threaded binary tree5 t=s right
child 2ill "oint to s=s right child and so 2ill t=s right thread
2 t=s left child 2ill "oint to s and it=s left thread 2ill be assigned Kt= 1true3 s=s right child
2ill "oint to t and its right thread 2ill be Kf=
6 \$ind the inorder successor of t and its left child 2ill no2 "oint to t
1 .rite a function 2hich 2ill ta/e any node and 2ill gi&e you its inorder successor
0his function 2ill access the right child of the gi&en node
2 ,f thread &alue is Kf=5 then as long as left thread is Kf= /ee" mo&ing left through the left
"ointer
6 0he node thus finally reached 2ould be the inorder successor
11
Lab Manual
4 0he ,norder tra&ersal no2 becomes easy ) :eginning 2ith the first node of the inorder
tra&ersal5 2hich can be reached from the header node5 call the inorder successor
re"eatedly5 dis"lay its data5 and go on till you meet the header node again5 2hich
signals the end of the inorder tra&ersal
Testing:
Test #onditions:
'im"le in"ut of random numbers !is"lay the inorder tra&ersal ,t must be a sorted
list of the numbers entered5 since a :'0 has been created 0his 2ould be "ro&e that
the threaded :'0 has been constructed "ro"erly
\$n)ut:
Enter data 1numbers3 to be stored in the binary search tree E&ery node in the :'0 2ould
contain 5 fields) data5 left child "ointer and right child "ointer5 left thread tag and a right
Out)ut :
!is"lay the list of elements in the serial order as they a""ear in the inorder tra&ersal
*A+S:
1 -o2 to create 0hreaded :'0D
2 .hat is use of 0hreaded :'0D
6 -o2 to tra&el 0readed :'0D
#onclusion:
12
Lab Manual
Assignment No 5
Title o" Assignment: .rite a "rogram to re"resent a gra"h using ad8acency matri9 and
Perform :\$' and !\$'
Algorithms:

1 !eclare an matri9 to store edges in the gi&en gra"h 0he number of entries in the
gra"h should be according to start and end &erte9 of the gi&en edges in the gra"h
2 0a/e the edge set from the user ,f for eg &erte9 1 is connected to &erte9 2 and 6 in
the gra"h5 the 1
st
location of the array of "ointers 1corres"onding to &erte9 13 2ould
"oint to 2 nodes5 one ha&ing the data 2 1corres"onding to &erte9 23 and the other
ha&ing data 6
6 ,n this 2ay construct the entire ad8acency list
3*S &3e)th *irst Search(
1 0he start &erte9 is &isited Ne9t an un&isited &erte9 2 ad8acent to & is selected and a
!\$' from 2 initiated
2 .hen a &erte9 u is reached such that all its ad8acent &ertices ha&e been &isited5 2e
bac/ u" to the last &erte9 &isited 2hich has an un&isited &erte9 2 ad8acent to it and
initiate a !\$' search from 2
6 0he search terminates 2hen no un&isited &erte9 can be reached from any of the
&isited ones
1 'tarting at &erte9 & and mar/ing it as &isited5 :\$' differs from !\$' in that all
un&isited &ertices ad8acent to & are &isited ne9t
2 0hen un&isited &ertices ad8acent to these &ertices are &isited and so on
6 A Aueue is used to store &ertices as they are &isited so that later search can be initiated
from those &ertices
Testing:
Test #onditions:
Enter the gra"h 2ith > &ertices and 10 edges 115235 115635 125435 125535 165;35 165<35 145>35
155>35 1;5>351<5>3
0he order of the &ertices &isited by !\$' is ) 15 25 45 >5 55 ;5 65 <
0he order of the &ertices &isited by :\$' is ) 15 25 65 45 55 ;5 <5 >
\$n)ut :
0he number of &ertices and the edge set of the gra"h
16
Lab Manual
Out)ut :
0he order of &ertices &isited in both !\$' and :\$'
*A+S:
1 .hat is the time com"le9ity of :\$' L!\$' Ira"hD
2 -o2 to create :\$'D
6 -o2 to create !\$'D
4 .hat is difference bet2een :\$' L !\$'D
#onclusion:
14
Lab Manual
Assignment No6
Title o" Assignment: .rite a "rogram to re"resent a gra"h using ad8acency list and
Perform :\$' and !\$'
Algorithms:

4 !eclare an array of "ointers to a lin/ list ha&ing a data field 1to store &erte9 number3
and a for2ard "ointer 0he number of array of "ointers 2ould eAual the total number
of &ertices in the gra"h
5 0a/e the edge set from the user ,f for eg5 &erte9 1 is connected to &erte9 2 and 6 in
the gra"h5 the 1
st
location of the array of "ointers 1corres"onding to &erte9 13 2ould
"oint to 2 nodes5 one ha&ing the data 2 1corres"onding to &erte9 23 and the other
ha&ing data 6
; ,n this 2ay construct the entire ad8acency list
3*S &3e)th *irst Search(
4 0he start &erte9 is &isited Ne9t an un&isited &erte9 2 ad8acent to & is selected and a
!\$' from 2 initiated
5 .hen a &erte9 u is reached such that all its ad8acent &ertices ha&e been &isited5 2e
bac/ u" to the last &erte9 &isited 2hich has an un&isited &erte9 2 ad8acent to it and
initiate a !\$' search from 2
; 0he search terminates 2hen no un&isited &erte9 can be reached from any of the
&isited ones
4 'tarting at &erte9 & and mar/ing it as &isited5 :\$' differs from !\$' in that all
un&isited &ertices ad8acent to & are &isited ne9t
5 0hen un&isited &ertices ad8acent to these &ertices are &isited and so on
; A Aueue is used to store &ertices as they are &isited so that later search can be initiated
from those &ertices
Testing:
Test #onditions:
Enter the gra"h 2ith > &ertices and 10 edges 115235 115635 125435 125535 165;35 165<35 145>35
155>35 1;5>351<5>3
0he order of the &ertices &isited by !\$' is ) 15 25 45 >5 55 ;5 65 <
0he order of the &ertices &isited by :\$' is ) 15 25 65 45 55 ;5 <5 >
15
Lab Manual
\$n)ut :
0he number of &ertices and the edge set of the gra"h
Out)ut :
0he order of &ertices &isited in both !\$' and :\$'
*A+S:
5 .hat is the time com"le9ity of :\$' L!\$' Ira"hD
; -o2 to create :\$'D
< -o2 to create !\$'D
> .hat is difference bet2een :\$' L !\$'D
#onclusion:
1;
Lab Manual
Assignment No7
Title o" Assignment: .rite a "rogram to re"resent gra"h using ad8acency list or matri9
and generate minimum s"anning tree using P%,M=s algorithm
Algorithms:
:oth the methods are im"lemented using the Ireedy a""roach 0he difference lies in the
2ay the cycle is "re&ented 0o construct a M'0 from a gra"h of n &ertices5 2e need n-1
edges e9actly Also5 these must be selected in a 2ay that the sum of the n-1 edges is
minimum and so cycle is formed
The Prims method to "ind the /ST is as "ollo0s :
1 'tart from an arbitrary root &erte95 say &erte9 number 1
2 Assign t2o arrays mindist5 in 2hich 2e note the minimum distance from each of the
&erte9 to &erte9 1 and array nearest in 2hich all the &erte9 are initially near &erte9 1
6 Among mindist find the smallest &alue and include that &erte9 in the M'0 along 2ith
the res"ecti&e edge Assign the &alue in the corres"onding nearest entry to M1
4 No2 consider all the other &ertices 2ith res"ect to the &erte9 recently added to the
M'0 ,f the edge from any of these &ertices to the recently added &erte9 is smaller
than the current &alue stored in mindist then change the mindist &alue to this &alue
and change nearest array &alue to the recently added node
5 ,f n-1 edges are not yet "art of the ans2er goto ste" 6
; 0he time com"le9ity of the abo&e algorithm is n
2
5 2here n is the number of &ertices
0here is an outer for loo" that loo"s n-1 times to find the n-1 edges and there is a
inner for loo" that scans the mindist array 2hich of siEe n to find the smallest entry
The 8ruskal9s method to "ind the /ST )roceeds in the "ollo0ing manner :
1 \$orm a min hea" of all the edges according to their 2eights Any call to delete an
edge from the min hea" 2ill return the smallest 2eighted edge and rearrange the hea"
in such a 2ay that the hea" "ro"erty is maintained
2 \$orm a list of connected com"onents in 2hich maintains all the &ertices in different
sets
6 !elete the smallest edge from the hea" #hec/ if the t2o &ertices of the edge belong
to different setsJ if they do then add the edge to the minimum s"anning tree and merge
the sets to 2hich the &ertices belong into 1 set
4 ,f the t2o &ertices of the set belong to a single set5 then do not add the edge to the
M'05 in this 2ay cycles are "re&ented
5 ,f n-1 edges do not yet belong to the solution then go bac/ to ste" 6
; 0he time com"le9ity to sort the edges is aloga5 the number of edges all the other ste"s
are carried out in a time less than this one 0hus for a s"arse gra"h 2here a is
a""ro9imately eAual to n the time com"le9ity is nlogn and for a dense gra"h 2here a
is a""ro9imately eAual to n
2
5 the time com"le9ity is n
2
logn
2

0hus for s"arse gra"hs Nrus/al=s algorithm is faster and for a dense gra"h Prim=s
algorithm is faster
1<
Lab Manual
Testing:
Test #onditions:
0he gra"h for 2hich M'0 is to be found out is as follo2s )
@erte9 1 @erte9 2 Edge .eight
1 2 1
2 6 2
1 4 4
2 4 ;
2 5 4
6 5 5
6 ; ;
4 5 6
5 ; >
4 < 4
5 < <
; < 6
0he Minimum '"anning 0ree for the abo&e gra"h is
@erte9 1 @erte9 2 Edge .eight
1 2 1
2 6 2
1 4 4
4 5 6
4 < 4
; < 6
0he total 2eight of the M'0 is 1<
\$n)ut:
Ira"h entered as an ad8acency matri9 for n &ertices ie fill an nOn matri9 2ith the &alues
of the 2eights of the edges of the gra"h 2here the ro2 number and column number as the
t2o &ertices of one edge
Out)ut :
0he Minimum '"anning 0ree of the "articular gra"h5 ie the set of edges 2hich are "art
of the M'0 along 2ith their res"ecti&e 2eights and the total 2eight of the M'0
1>
Lab Manual
*A+S:
1 .hat is the Prim=s algorithmD
2 .hat Nrus/al=s algorithmD
6 .hat is the diffrence bet2een Prim=s L Nrus/al=s algorithmD
#onclusion:
1?
Lab Manual
Assignment No:
Title o" Assignment: .rite a "rogram to re"resent gra"h using ad8acency list or matri9
and find shortest "ath using !i8/stra=s algorithm
Algorithms:
A 'hortest Path 0ree in I from start node s is a tree 1directed out2ard from s if I is a
directed gra"h3 such that the shortest "ath in I from s to any destination &erte9 t is the
"ath from s to t in the tree
!i8/straHs algorithm is called the single-source shortest "ath ,t is also /no2n as the single
source shortest "ath "roblem ,t com"utes length of the shortest "ath from the source to
each of the remaining &ertices in the gra"h
0he single source shortest "ath "roblem can be described as follo2s) Let IG P@5 EQ be a
directed 2eighted gra"h 2ith @ ha&ing the set of &ertices 0he s"ecial &erte9 s in @5
2here s is the source and let for any edge e in E5 Edge#ost1e3 be the length of edge e All
the 2eights in the gra"h should be non-negati&e
!i8/stra=s algorithm5 builds the tree out2ard from s in a greedy fashion
!i8/stra=s Algorithm)
1 ,n"ut) Ira"h I5 2ith each edge e ha&ing a length len1e35 and a start nodes
2 ,nitialiEe) tree G PsQ5 no edges Label s as ha&ing distance 0 to itself
6 ,n&ariant) nodes in the tree are labeled 2ith the correct distance to s
4 %e"eat)
a \$or each neighbor 9 of the tree5 com"ute an 1o&er3-estimate of its distance to s)
distance193 G min Rdistance1&3 4 len1e3S
eG1&593)&tree
,n other 2ords5 by our in&ariant5 this is the length of the shortest "ath to 9 2hose
+nly edge not in the tree is the &ery last edge
b ,nsert the node 9 of minimum distance into tree5 connecting it &ia the argmin 1the
edge e used to get distance193 in the e9"ression3
Testing:
\$n)ut:
Out)ut :
20
Lab Manual
*A+S:
1 .hat is the shortest "ath treeD
2 .hat is !i8/stra=s algorithmD
6 .hat is its efficiencyDD
#onclusion:
21
Lab Manual
Assignment No;
Title o" Assignment: ,m"lement :-0ree of +rder 5 and "erform follo2ing o"erations on
:-0ree) ,nsert 5!elete
Algorithms:
Search:
1 'earching is similar to searching a binary search tree 'tarting at the root5 the tree
is recursi&ely tra&ersed from to" to bottom
2 At each le&el5 the search chooses the child "ointer 1subtree3 2hose se"aration
&alues are on either side of the search &alue
#reate and \$nsert:
1 All insertions start at a leaf node 0o insert a ne2 element
2 'earch the tree to find the leaf node 2here the ne2 element should be added
,nsert the ne2 element into that node 2ith the follo2ing ste"s)
61 ,f the node contains fe2er than the ma9imum legal number of elements5
then there is room for the ne2 element ,nsert the ne2 element in the node5
/ee"ing the nodeHs elements ordered
62 +ther2ise the node is full5 so e&enly s"lit it into t2o nodesA single
median is chosen from among the leafHs elements and the ne2 element
1 @alues less than the median are "ut in the ne2 left node and &alues greater
than the median are "ut in the ne2 right node5 2ith the median acting as a
se"aration &alue
2 ,nsert the se"aration &alue in the nodeHs "arent5 2hich may cause it to be
s"lit5 and so on ,f the node has no "arent 1ie5 the node 2as the root35
create a ne2 root abo&e this node 1increasing the height of the tree3
6 ,f the s"litting goes all the 2ay u" to the root5 it creates a ne2 root 2ith a
single se"arator &alue and t2o children5 2hich is 2hy the lo2er bound on
the siEe of internal nodes does not a""ly to the root
3elete:
0here are t2o "o"ular strategies for deletion from a :-0ree
1 locate and delete the item5 then restructure the tree to regain its in&ariants +%
2 do a single "ass do2n the tree5 but before entering 1&isiting3 a node5 restructure
the tree so that once the /ey to be deleted is encountered5 it can be deleted 2ithout
triggering the need for any further restructuring
0he algorithm belo2 uses the former strategy
22
Lab Manual
0here are t2o s"ecial cases to consider 2hen deleting an element)
the element in an internal node may be a se"arator for its child nodes
!eleting an element may "ut its node under the minimum number of
elements and children
Each of these cases 2ill be dealt 2ith in order
3eletion "rom a lea" node
1 'earch for the &alue to delete
2 ,f the &alue is in a leaf node5 it can sim"ly be deleted from the node5
6 ,f underflo2 ha""ens5 chec/ siblings to either transfer a /ey or fuse the siblings
together
4 if deletion ha""ened from right child retrie&e the ma9 &alue of left child if there is
no underflo2 in left child
5 in &ice-&ersa situation retrie&e the min element from right
3eletion "rom an internal node
1 Each element in an internal node acts as a se"aration &alue for t2o subtrees5 and
2hen such an element is deleted5 t2o cases arise ,n the first case5 both of the t2o
child nodes to the left and right of the deleted element ha&e the minimum number
of elementsJ unless it is /no2n that this "articular :-tree does not contain
du"licate data5 2e must then also 1recursi&ely3 delete the element in Auestion from
the ne2 node
2 ,n the second case5 one of the t2o child nodes contains more than the minimum
number of elements 0hen a ne2 se"arator for those subtrees must be found Note
that the largest element in the left subtree is still less than the se"arator Li/e2ise5
the smallest element in the right subtree is the smallest element 2hich is still
greater than the se"arator :oth of those elements are in leaf nodes5 and either can
be the ne2 se"arator for the t2o subtrees
6 ,f the &alue is in an internal node5 choose a ne2 se"arator 1either the largest
element in the left subtree or the smallest element in the right subtree35 remo&e it
from the leaf node it is in5 and re"lace the element to be deleted 2ith the ne2
se"arator
4 0his has deleted an element from a leaf node5 and so is no2 eAui&alent to the
"re&ious case
26
Lab Manual
'ebalancing a"ter deletion
1 ,f deleting an element from a leaf node has brought it under the minimum siEe5
some elements must be redistributed to bring all nodes u" to the minimum ,n
some cases the rearrangement 2ill mo&e the deficiency to the "arent5 and the
redistribution must be a""lied iterati&ely u" the tree5 "erha"s e&en to the root
'ince the minimum element count doesnHt a""ly to the root5 ma/ing the root be
the only deficient node is not a "roblem 0he algorithm to rebalance the tree is as
follo2s)
i. ,f the right sibling has more than the minimum number of elements
ii. Add the se"arator to the end of the deficient node
iii. %e"lace the se"arator in the "arent 2ith the first element of the right
sibling
iv. A""end the first child of the right sibling as the last child of the deficient
node
v. +ther2ise5 if the left sibling has more than the minimum number of
elements
vi. Add the se"arator to the start of the deficient node
vii. %e"lace the se"arator in the "arent 2ith the last element of the left sibling
viii.,nsert the last child of the left sibling as the first child of the deficient node
ix. ,f both immediate siblings ha&e only the minimum number of elements
x. #reate a ne2 node 2ith all the elements from the deficient node5 all the
elements from one of its siblings5 and the se"arator in the "arent bet2een
the t2o combined sibling nodes
xi. %emo&e the se"arator from the "arent5 and re"lace the t2o children it
se"arated 2ith the combined node
xii. ,f that brings the number of elements in the "arent under the minimum5
re"eat these ste"s 2ith that deficient node5 unless it is the root5 since the
root may be deficient
xiii.0he only other case to account for is 2hen the root has no elements and
24
Lab Manual
one child ,n this case it is sufficient to re"lace it 2ith its only child
Testing:
Test #onditions:

Enter the element to be inserted in the :-tree then dis"lay the elements of the :-tree
,n"ut the element to be searched if the element is found dis"lay the com"lete node else
dis"lay element not found Enter the element to be deleted and dis"lay the : tree after
deletion of element
\$n)ut:
Enter any random no to be inserted 5 searched and deleted
Out)ut:
!is"lay the tree after each o"eration ie ,nsertion5 !eletion and searching
*A+S:
1 .hat is : treeD
2 E9"lain significance of order of : treeD
6 E9"lain sibling of : treeD
4 E9"lain s"litting of node in a : treeD
#onclusion:
25
Lab Manual
Assignment No!<
Title o" Assignment: ,m"lement A@L tree and "erform follo2ing o"erations) ,nsertion5
!eletion and 'earching
Algorithms:
#reate and \$nsert:
1 ,nsert a ne2 node as ne2 leaf 8ust as in ordinary search tree
2 No2 trace the "ath from insertion "oint to2ards root
6 for each n encountered chec/ if height of left1n3 and right1n3 differ by at the most 1
4 ,f yes5 mo&e to2ards "arent1n3
5 other 2ise restructure by doing either a single rotation or a double rotation !ifferent
%otations in A@L tree are) LL5 %%5 L%5 %L rotation
3elete :
1 'earch the node 2hich is to be deleted
2 a ,f the searched node to be deleted is a leaf node then sim"ly ma/e it null
b ,f the node to be deleted is not a leaf node5 then node is to be s2a""ed 2ith its
inorder successor +nce the node is s2a""ed 5 2e can remo&e this node
6 No2 2e ha&e to tra&erse bac/ u" the "ath to2ards root5 chec/ing the balance factor
of e&ery node along the "ath ,f 2e encounter unbalancing in some subtree then
balance that subtree using a""ro"riate single or double rotations
Searching:
1 #onsider the node to be searched as K/ey= node
2 #om"are /ey 2ith root node ,f /ey T root then go to the left node and call this
left node as current node ,f /ey U root then go to the right node and call this right
node as current node5 other2ise the desired node is the root node
6 #om"are /ey 2ith current node ,f /ey T current node then go to left node and call
this left node as current node Else if /ey U current node then go to right node and
call this right node as current node else /ey is current node
4 0hus re"eat ste" 6 until the desired node is found or &isited the entire tree

2;
Lab Manual
Testing:
Test #onditions:
'im"le in"ut a random numbers ,nsert the node5 after insertion dis"lay inorder 5 "reorder
and "ost order tra&ersal also after deletion dis"lay all tra&ersals
\$n)ut:

Enter data 1 could be 2ords5 characters or numbers3 to be stored in the 0ree
+ut"ut)
!is"lay the inorder5 "reorder and "ostorder tra&ersals of the tree
*A+S:
1 -o2 to insert the ne2 node A@L 0reeD
2 -o2 to delete node from the A@L 0ree D
6 .hat is LL5 %%5 L%5 %L rotationD
4 .hat is difference bet2een A@L tree and :inary 'earch 0reeD
#onclusion:
2<
Lab Manual
Assignment No!!
Title o" Assignment: .rite a "rogram to im"lement direct access file
Algorithms:
#haining :
-ere 2e lin/ all the synonyms in the file Each time 2e come across a synonym 2e add
it to em"ty s"ace in the file and ma/e it=s "re&ious node 2ith same hash /ey "oint to it
'o 2e get different chains of the same synonym in the main file
1 Acce"t record from the user
2 #alculate hashed &alue of the /ey field
6 #hec/ for that "osition in the file
4 ,f "osition found em"ty insert record ,f not goto ne9t a&ailable location and store
data there
5 #onnect the ne9t "ointer of the "re&ious synonym of that /ey to this location and the
"re&ious "ointer of this record to "re&ious synonym
'earching for a record )
1 Acce"t the /ey of record to be searched
2 #alculate hash &alue of the /ey
6 #hec/ at the "osition in the file
4 ,f not5 match found5 chec/ for that record in the entire chain by using the ne9t lin/
5 ,f /ey matched then dis"lay the record
!eletion of a record )
1 Acce"t the /ey field of the record to be deleted
2 'earch the record in the file using the chain
6 ,f found5 then delete the record by ma/ing /ey G -1
4 Ma/e the "ointer of the "re&ious node "oint to the ne9t node the current record 2as
"ointing to
A""end a record "roceeds similarly as dis"lay record5 e9ce"t that after the record is
obtained changes are made to it and 2ritten in the same location as 2as read
2>
Lab Manual
Testing:
Test #onditions:
Enter any student database 2ith student name5 roll number and mar/s Bse roll
number as /ey !is"lay the records to see if they are accessed "ro"erly !elete a
record and then try to dis"lay it A""ro"riate error message must be "rinted
\$n)ut:
'tudent data to be entered in the 'im"le ,nde9 file
Out)ut :
!ata dis"layed on reAuest
*A+S:
1 .hat is chainingD
2 .hat are the ty"es of chainingD
6 -o2 to access data directly by using direct access fileD
#onclusion:
2?
Lab Manual
Assignment No!,
Title o" Assignment: .rite a "rogram to add binary numbers 1assume one bit as one
Number3 use '0L stac/
Algorithms:
Standard Tem)late Library:
0em"late can be use to create the generic classes and functions that e9tend
su""ort to generic "rogramming 0he collection of the generic classes and functions is
called standard tem"late library
#om)onents o" STL:
1 #ontainers
2 Algorithms
6 ,terators
#ontainers:
,t is an ob8ect that actually stores data ,t is the 2ay in 2hich data is stored in
memory '0L containers are im"lemented by tem"late classes and therefore can be easily
customiEed to hold different data ty"es
Algorithm:
An algorithm is a "rocedure that is used to "rocess data that is held in containers
'0L includes many different ty"es of algorithm
\$terator:
,t is an ob8ect that "oints to an element in a container .e can use an iterator to
more through the contents of a container ,terators are handled 8ust li/e li/e "ointers
Ste)s:
Acce"t and con&ert the no in binary)-
2 +btain remainder on di&ision by 2
6 Push remainder onto stac/
4 !i&ide no by 2
5 ,f noU0 5 goto ste" 2
; !is"lay no
< return
1 ,nitialiEe carry to Eero
2 Po" one element from each stac/
6 Add the t2o and "ush result into the third stac/also initialise carry caused due to
60
Lab Manual
4 ,n both stac/s are not em"ty 5 goto ste" 2
5 \$or stac/ that is not em"ty 5 "erform addition 2ith carry and "ush result into the third
stac/
; #on&ert result intodecimal
< %eturn
Testing:
Test #onditions:
:inary &alue for <G 111
:inary &alue for ?G 1001
%esult G 1; in binary G 10000
\$n)ut:
Enter the no in decimal
Out)ut :
+ut"ut is in decimal as 2ell as in binary
*A+S:
1 .hat is '0LD
2 .hy 2e are using '0LD
6 .hat are the functions used in this "rogramD
4 .hat is ,tratorD
5 .hat is #ontainerD
#onclusion:
Assignment No!1
61
Lab Manual
Title o" Assignment: ,m"lementation of 'ingle Lin/ed List5 !ouble Lin/ed List and
#ircular Lin/ed List using 'tandard 0em"late Library
3esign Analysis 2 \$m)lementation Logic:
Algorithms and 'e=uirements:
#44 "ro&ides L,'0- header file 2hich contains built in functions for the im"lementation
of single lin/ed list !:L,'0- header file can be used for the im"lementation of doubly
lin/ed list
#reate and \$nsert:
1 Acce"t data to be entered in the 'LL one element at a time \$or the 1
st
data create a
node using List add function \$or !LL use add function from !:L,'0 library
2 \$rom the second element entry on2ards5 add function 2ill automatically add the
element to the first "osition 2hich 2ill become the ne2 head of the list
6 \$or #ircular Lin/ed list ne9t "ointer of last node "oints to the start of Lin/ed List
3elete :
1 Bse !etach function from Listh library to remo&e the ob8ect from the lin/ed list
2 .hich ob8ect has to be deleted and in 2hich manner de"ends on the arguments "assed
to the function Eg &irtual &oid detach1 const +b8ectL to!etach5 !elete0y"e dt G
No!elete 3J
3is)lay :
1 Bse the List ,terator container class to tra&erse through the lin/ed list
2 Bse o"erator 44 function to tra&erse to the ne9t node
Testing:
Test #onditions:
'im"le in"ut of random numbers After e&ery insertion dis"lay to see if all the
contents are dis"layed "ro"erly After e&ery deletion also do the same !elete nodes at
different locations in the 'LL for eg start node5 last node and middle node Ma/e
sure that your delete function 2or/s for all cases
\$n)ut:
Enter data 1could be 2ords5 characters or numbers3 to be stored in the 'LL or !LL
E&ery node in the 'LL or !LL 2ould contain 2fields) data5 "ointer
Out)ut :
!is"lay the list of elements in the serial order as they a""ear in the 'LL or !LL
*A+S:
1 .hat is a 'tandard 0em"late LibraryD
2 .hat built in data structure im"lementations do it "ro&ideD
6 .hat are the built in functions for in Listh and !blisthD
#onclusion:
62
Lab Manual
,n this assignment 2e ha&e studied the basics about tem"late library and ho2 to create
singly lin/ed list5 doubly lin/ed list and circular lin/ed list and &arious o"erations on it
Assignment No!4
Title o" Assignment: ,m"lementation of stac/ L Aueue using 'tandard 0em"late Library
3esign Analysis 2 \$m)lementation Logic:
Algorithms and 'e=uirements:
#44 "ro&ides '0A#N- header file 2hich contains built in functions for the
66
Lab Manual
im"lementation of stac/ VBEBE- header file can be used for the im"lementation of
Aueue
#reate and \$nsert:
4 Acce"t data to be entered in the stac/ one element at a time Bse stac/) "ush function
to add the data to stac/
5 \$or Aueue5 after acce"ting the data from user use Aueue) "ut function to add the data
to Aueue
; \$or #ircular Lin/ed list ne9t "ointer of last node "oints to the start of Lin/ed List
3elete :
6 Bse stac/) "o" function to remo&e the data from the stac/
4 Bse Aueue) get function to remo&e the data from the Aueue
3is)lay :
6 .e can use get,tems,n#ontainer 1 3 function to get the totals no of items in the
stac/ And can use a stac/ ,terator to iterate through the stac/
4 ,n the same 2ay 2e can create a ,terator for the Aueue and dis"lay the contents of
the Aueue
Testing:
Test #onditions:
'im"le in"ut of random numbers After e&ery insertion dis"lay to see if all the
contents are dis"layed "ro"erly After e&ery deletion also do the same
\$n)ut:
Enter data 1could be 2ords5 characters or numbers3 to be stored in the stac/ or Aueue
E&ery node in the 'tac/ or Aueue 2ould contain 2fields) data5 "ointer
Out)ut :
!is"lay the list of elements in the serial order as they a""ear in the 'tac/ or Aueue
*A+S:
1 .hat is a 'tandard 0em"late LibraryD
2 .hat built in data structure im"lementations do it "ro&ideD
6 .hat are the built in functions for in stac/h and AueuehD
#onclusion:
,n this assignment 2e ha&e studied the basics about tem"late library and ho2 to create
stac/ and Aueue and &arious o"erations on it
Assignment No!5
Title o" Assignment: .rite a "rogram to im"lement !eAueue using '0L
Algorithms:
A deAue is double ended Aueue 2ith o"timiEed o"erations both at the front and the bac/
0he deAue is maintained into standard tem"late library
64
Lab Manual
'ome of the o"erations that can be "erformed are)
\$ront13
:ac/13
PushFfront13
Po"Ffront13
PushFbac/13
Po"Fbac/13
Em"ty13
1 Main13
2 '2itch1choice3
#all) "ushFfront1element3
#ase 2) read element from user
#all) PushFbac/13
#ase 6) !is"lay front13
#all) "o"Ffront13
#ase 4) !is"lay bac/13
#all) "o"Fbac/13
6 ,f user 2ants to continue goto ste" 1
4 E9it
1 !is"lay13
!eclare an iterator of the container ty"e ie in this case deAueue say ,
\$or1,GdAbegin13J,WGdAendJi443
!is"lay1Oi3
%eturn
Testing:
Test #onditions:
6 !elete from front
4 !elete from rear
Enter the element to add from front)2
Enter the element to add from front)1
Enter the element to add from rear)4
Enter the element to add from rear)<
0he element of the deAue are ) 1 2 4 <
!elete the element from the front)
65
Lab Manual
!elete the element from the rear)
0he element of the deAue are ) 2 4
\$n)ut:
Ii&e the integer in"ut from front and rear store that data in deAue
Out)ut:
!is"lay the data "resent in the deAue !is"lay it after deletion of the data from front and
from rear
*A+S:
4 .hat are the deAue functions declared in the '0LD
5 -o2 to use deAue functionsD
; .hat is the use of these deAue functionsD
#onclusion:
Assignment No!6
Title o" Assignment: .rite a "rogram to use '0L for sorting and searching 2ith user
defined records
Algorithms:
:y including algorithmh the abo&e file many useful generic algorithms can be a""lied
on containers 0hese algorithms can be a""lied to containers such as list 5&ector 5deAue5
etc
'ome of the common generic algorithms are a&ailable)
'ort) sort the element "resent in the container class
:inary search to search for the element in container class
EAual) to chec/ t2o containers are eAual or not
6;
Lab Manual
#o"y) to co"y the item of one container class into another container
class
\$ill) to fill all the elements of a container class 2ith a "articular item
%emo&e) to remo&e all the elements from the container class
main13
2 'elect case choice
#ase 1)
#ase 2)
#all)dis"lay13
#ase 6)
!eclare an iterator of that ty"e
#all) search1start5end5data3
#ase 4)
#all) sort1start5end3
6E9it
dis"lay13
1 !eclare the iterator of the container ty"e 5 say ,
2 \$or ,G begin13 J , not eAual to end13 J ,44
!,'PLA(1Oi3J
6 %eturn
Testing:
Test #onditions:
1 A!!
2 !,'PLA(
6 'EA%#-
4 '+%0
5 EX,0
EN0E% (+B% #-+,#E)1
EN0E% %+LLFN+ )1
EN0E% NAME ) A
1 A!!
2 !,'PLA(
6<
Lab Manual
6 'EA%#-
4 '+%0
5 EX,0
EN0E% (+B% #-+,#E)1
EN0E% %+LLFN+ )2
EN0E% NAME ) :
1 A!!
2 !,'PLA(
6 'EA%#-
4 '+%0
5 EX,0
EN0E% (+B% #-+,#E)1
EN0E% %+LLFN+ )6
EN0E% NAME ) #
1 A!!
2 !,'PLA(
6 'EA%#-
4 '+%0
5 EX,0
EN0E% (+B% #-+,#E)2
%+LL N+)1
NAME )A
%+LL N+)2
NAME ):
%+LL N+)6
NAME )#
1 A!!
2 !,'PLA(
6 'EA%#-
4 '+%0
5 EX,0
6>
Lab Manual
EN0E% (+B% #-+,#E)6
EN0E% %+LL N+ )2
0-E %E#+%! .A' \$+BN!
%+LL N+)2
NAME ):
1 A!!
2 !,'PLA(
6 'EA%#-
4 '+%0
5 EX,0
EN0E% (+B% #-+,#E)4
%+LL N+)1
NAME )A
%+LL N+)2
NAME ):
%+LL N+)6
NAME )#
\$n)ut:
Enter the name and roll number of the students
Out)ut:
.hate&er the name and roll number dis"lay the records
.hate&er the name and roll number search the records by roll number
.hate&er the name and roll number sort the records by roll number
6?
Lab Manual
*A+S:
1 -o2 to search the records by roll numberD
2 -o2 to sort the records by roll numberD
#onclusion:
Assignment No!7
Title o" Assignment: .rite a #44 "rogram to im"lement a small database mini )roject
to understand "ersistent ob8ects and o"erations on seAuential files 1eg library
information5 in&entory systems5 automated ban/ing system5 reser&ation systems etc3 \$or
e9am"le5 2rite a "rogram to create a database for reser&ation system using information
such as Name5 se95 age5 starting "lace of 8ourney and destination Program should ha&e
follo2ing facilities
a3 0o dis"lay entire "assenger list
b3 0o dis"lay "articular record
c3 0o u"date record
40
Lab Manual
d3 0o delete and sort record
Bse E9ce"tion -andling for data &erification
3esign Analysis 2 \$m)lementation Logic:
Testing:
*A+S:
#onclusion:
41