You are on page 1of 3

Q.1 (a) what is the need of algorithm complexity and how it is evaluated?

 To check Time and Space requirements of algorithmand which require less time &less space
is more accurate.
 Time and Space complexity
 Notation Big O,Big Theata,Big Omega

Q.1 (b) A programmer wants to write a rudimentary scanner that would check unbalanced braces,
brackets and square brackets in a C source file. He maintains a storage list, which would get all open
braces, brackets and square brackets. When a closing brace, bracket or square bracket is seen, it is
compared with the contents of the list to issue a suitable diagnostic. Which is the best possible data
structure of the storage list to accomplish this task? Justify your answer with proper reason.

 Stack is best possible data structure of the storage list to accomplish this task.
 Stack is used to check balanced parenthesis expression.
 In an expression no.of opening brackets is equal to number of closing brackets.
 Computer check this with the help of stack.
 By using stack computer determines no of open brackets is equal to no.of closing brackets in
an expression.

Q.1(c) Algorithm A requires n2 days and algorithm B requires n3 seconds to solve a problem. Which
algorithm would you prefer for a problem instance with n=106? Justify your answer with proper
reason.

Q.2 (a) Consider the usual algorithm to convert an infix expression to a postfix expression. Suppose
that you have read 10 input characters during a conversion and that the stack now contains these
symbols:
Q.2 (b) Design a data representation which sequentially map N data objects in to an array[1,N], n1 of
these data objects are stack and n2=N-n1, are queues. Writealgorithms to add and delete elements
from these objects.
Stack Algorithm
1. Top=0,
2. Maxsize=n1
3. Push();
4. Pop();
Queue Algorithm
5. front=n1,rear=n1;
6. front=front+1;
7. rear=rear+1;
8. queue[rear]=item
Q.2(c )Consider the following queue of characters where queue is a circular
array which is allocated six memory cells. Front=2, Rear= 4 and “_ “ denotes
empty cell Queue: _, A, C, D ,_ ,_ Describe the queue as the following
operations takes place: (i) F is added (ii) Two letters are deleted (iii) K, L and M
are added (iv) Two letters are deleted (v) R is added (vi) Two letters are
deleted (vii) S is added (viii) Two letters are deleted

You might also like