You are on page 1of 1

President University

Mid Term Examination


Bachelor of Computing (IT Major)
Data Structures and Algorithms

1. Data structure for circular array queue can be represented by following declaration.
struct Q{
int front,rear;
int Qa[Max];
};
Although it is easy to implement, the model has one disadvantage.
a. What is the disadvantage of the above model ? Justify your answer!
b. Could the drawback be resolved ? How ?

The following code uses the above structure

void Enqueue(dat,pr,Q) if (pos < Qrear)


{ move_q_down(pos+1,Q);
QP[pos].data = dat;
if(!Full()){
QP[pos].prio = pr;
int pos = Qfront;
Qrear += 1;
while(pr > QP[pos] AND
Qrear %= Max;
pos <= Qrear){ }else
pos += 1; print errormsg;
pos %= Max; }
}

Where Enqueue’s arguments: dat – data to be inserted; pr – priority of the data; Q – the
circular queue structure

2. From the above, answer the following questions:


a. What is the order of the priority queue ?
b. Does the pseudo code give a fairness treatment for incoming items? Justify your
answer!

3. move_q_down shown the above code is a function to move existing data before the new
data is inserted. Please write the correct code for the function.

4. In size_base trace that is shown in Tree.pdf, there exists print subroutine that takes
three arguments, node n, depth of the node, size of (memory). Then try to figure out the
code for such sub routine.

You might also like