Beruflich Dokumente
Kultur Dokumente
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–Part A
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–
Ans1(a): The Complexity of an algorithm M is the function f(n) which gives the running time
and/or storagespace requirement of the algorithm in terms of the size n of the input data.
Ans1(b):It is as easier to implement the operations on a circular header linked list as in ordinary
linked list. The easyness in the circular header linked list than ordinary linked list is not much
significant. But it comes from the fact that it is easier for the computer to look or search for a
valid address than a NULL. In case of header circular list we have to check for the starting
address which is a valid address while in case of ordinary list we look for NULL. If a large
number of operations or repetitive steps are to be performed then it will be easier in circular
header list than the ordinary linked list.
1) Single-ended-Queue:A queue in which deletions can take place at one end called front and
insertions can take place only at the other end called the rear.
2)Double-ended-Queue:A queue in which elements ccan be added or removed at either end but
not at the middle also called as a deque.
3)Priority Queue:A queue such that every element in it is assigned a priority and elements are
added and deleted such that :
b) Two elements of the same priority are processed according to the order in which they were
added to the queue.
1)There must be a certain criteria(base criteria),for which the procedure does not calls itself.
2)With each call the procedure proceeds closer to the base criteria.
Ans1(e):Stacks are used in those situations in which there is a postpontment of a decision.For
example, stacks are used in process schedulling,implementation of the towers of hannoi,binary
trees etc.
N=upperbound-lowerbound+1
c)So,for C(18):Since no lower bound is specified we take the default value i.e. 1
so, N=18-1+1=18
LOC(LA[K])=Base(LA)+w(K-1)
Base (LA)=300
W=4
LOC(LA[15])=300+4X(15-1)=356
LOC(LA[15])=300+4X(35-1)=436
Since the array A contains only 46 elements so A[55] is not an element of A and hence will point
to any location in the memory.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–Part B
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–
Ans3:
Algorithm 1:INSERT(INFO,LINK,START,AVAIL,ITEM)
This algorithm inserts ITEM in the list in a sorted manner if it is not empty otherwise creates the
list and then inserts ITEM into it
1) IF(AVAIL=NULL) then Write:Overflow
Exit
Else
Set NEW:=AVAIL
Set AVAIL:=LINK[AVAIL]
Set INFO[NEW]:=ITEM
Set LINK[NEW]:=NULL
[End of If structure]
2) IF(START=NULL)
START=NEW
[End of if structure]
3) PTR:=START
4) PTR2:=PTR
5) Repeat While(ITEM>INFO[PTR])
6) IF (LINK[PTR]=NULL)
LINK[PTR]=NEW
[End of if structure]
PTR2:=PTR
PTR:=LINK[PTR]
7) If(PTR=START)
LINK[NEW]:=START
START:=NEW
Else
LINK[PTR2]=NEW
LINK[NEW]=PTR
[End of if structure]
8) Exit
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–Part C
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
–
Ans4:
Algorithm 2:HANNOI(N,BEG,AUX,END)
This procedure is a recursive solution to the Tower of Hannoi problem for N number of disks.
Step 1: if N=1,then
a) Write:BEGEND
b) Return
[End of if structure]
Call HANNOI(N-1,BEG,END,AUX)
Step3: Write:BEGEND.
Call HANNOI(N-1,AUX,BEG,END)
Step5:Return.
Suppose BEG or stating peg is ‘L’ and END peg is’C’ and ‘R’ is the auxillary peg AUX , then
the solution of tower of hannoi problem for number of disks N=6 is :