Ucs301 2
Ucs301 2
Note: Attempt all questions (sub-parts) in sequence. Assume missing data, if any,
suitably.
Q1. Convert the given infix expression into an Table 1. Precedence of (3)
equivalent postfix expression using stacks. Show operators.
Operator Precedence
contents of the stack at each intermediate step.
# Highest
Use the precedence table as shown in Table 1.
(A$B+C)#(K+L-M*N+0^13 *W/U)
4., -
$ Lowest
Q2. Let the letters S, E, A, T, B, L has to be pushed on to an empty stack of characters (1)
in the order they appear from left to right. Consider that the output of pop( )
operation is appended in an initially empty output string.
Determine the sequence in which push() and pop() operations should be
called such that the contents in the output string should be STABLE.
Q3. Compute complexity of the following pseudo-codes giving proper justifications. (3)
(a) (b)
for (int i = 1; i <= n; i++) for (int p = 1; p + n/2 <= n; p++)
for(int j = 1; j <= i; j++) for(int q = n; q > 0; q /= 2)
forint k = 1; k <= j; k++) forint r = 1; r*r <= n; r++)
{ ... } for(int s = 1; s < n; s++)
{ break; ... }
(c)
m = n;
while ( n > 0)
{ for(int i = 0; i < m; i++)
...
n = n/3;
}
Q4. (a) A two-dimensional array defined as A [-4 ... 6] [-2 ... 12] requires 2 bytes of (2)
storage for each element. If the array is stored in row major order form with
the address A[4][8] as 4142. Compute the address of A[0][0].
(b) A circular queue of positive integers is implemented using a linear array (1)
A [1..6]. The present contents of A are (4, ..., ..., 7, 9, 2) where '...' represents
empty. After two dequeue and one enqueue operations, let the positions of
front and rear pointers be X and Y, respectively. Then 4X + 5Y will be?
1/2
D A T A B A S E (3)
QS. Let S be an empty stack and Q be a Q:
queue with contents as shown in Fig. L Front
1. isEmpty(Q) or isEmpty(S) returns Fig. 1
true if Q or S is empty, else returns 1. function1 (char val)
false. top(S) returns the character at 2. { if (isEmpty(S) 11 top(S) < val)
the top of S without removing it from S. 3. { push(S,val);
4. return;
Execute the code snippet given in Fig. 5. }
2 and answer the following questions. 6. char c = pop(S);
7. function1(val);
(a) Give the contents of S after each 8. if (c != top(S))
execution of the while loop within 9. push(S,c);
main(). 10. }
11. int main()
(b) Observe the output obtained in Q5. 12.{ while (!isEmpty(Q))
(a) and clearly state the purpose(s) 13. function1(dequeue(Q));
of designing it. 14.}
Fig. 2
Q6. A Radix Sort algorithm utilizing Counting Sort as an intermediate stable sorting (5)
algorithm is to be applied on the contents of array A to arrange them in
increasing order. Let COUNT [0..9] be the array that counting sort uses to store
the frequency values during intermediate steps.
A: 387 690 234 435 567 203 441 892
Illustrate step wise execution of counting sort, i.e. list the contents of array
COUNT, for each of the iterations of Radix sort (starting from LSD). Also show
the contents of array A across all the iterations of Radix sort.
if it is (3)
Q7. Let A[0 .. n - 1] be an array of numbers. A number A[i] is called a principal
greater than the mean of all numbers from A[i] to A[n - 1]. Write an efficient
pseudo-code to delete all the principal numbers in the array A. Explain the
proposed logic with the help of an example.
singly (4)
Q8. Write a pseudo-code to implement Round Robin CPU Scheduling using
circular linked list assuming processes may have different arrival as well as
burst times.
Round Robin is a pre-emptive scheduling algorithm in which CPU is assigned to
a process on the basis of FCFS for a fixed amount of time known as 'time
quantum'. After time quantum expires, the running process is pre-empted and
the processor is assigned to the next arrived process.
Note:
• tq represents time quantum, SCLL is a singly circular linked list maintaining
list of processes which are being executed currently. LL is a simple linked list
maintaining list of processes (in FCFS order) which are freshly arrived and yet
to enter SCLL.
• At the end of each tq, all the processes are deleted from LL and are inserted in
the same order in SCLL. Similarly, when the burst time reaches zero the
corresponding process is finally deleted from SCLL.
• Memory should be allocated to a process only once when it arrives freshly. Also
assume that insertion is happening automatically in LL, so there is no need to
specify it's corresponding pseudo-code.
ALL THE BEST
2/2