2014 SPR
2014 SPR
[Answer any five questions from Group A, and any five questions from Groups Band c.]
Group A
A.l Let G be a directed acyclic graph with n vertices. Let s be a source (a vertex with in-degree zero) and
t a sink (a vertex of out-degree zero) in G. We want to compute the number of paths from s to t. For
u, v E G, letN(u, v) denote the number of paths in G from u to v. So our task is to compute N(s, t). Let
VI, V2,"" Vkbe all the neighbors of s is G. Then, we have N(s,t) = N(VI ,t) +N(V2,t) +...+N(Vk,t),
that is, we compute each N( Vi, t) recursively, and return their sum.
(a) Describe the termination condition(s) for the above recursive algorithm. (3)
(b) Prove that the worst-case complexity of the above recursive algorithm can be exponential in n. (7)
if<a) Describe what ADT (abstract data type) calls (operations with functional specifications) should
, be defined for implementing stacks. Do not implement the calls. Only mention the call prototypes.
w
For example, here is a call prototype for inserting an element in an ordered list at a given index:
w
(b) Use these stack ADT calls to recognize strings with balanced parentheses. Examples of such
w
V Let [PO,PI,P2,'" ,Pn-d be an array of n distinct points in the two-dimensional plane. Each point
11 is specified by its to coordinates Xj,Yj. A point P; in the given array is called maximum if for all
ol
" ,'.
jE{0,1,2, ... ,n-l}withj#i,wehavexj::::;;xjandYj::::;;Yj. .,... 'to I '" '," l'
ut
(a) Show that not every array of points contains maximum point(s). (3)
(b) Propose an efficient algorithm to find a maximum point in a given array of points (if a maximum
io
A.5 Let u, v, w be n-dimensional column vectors (that is, n x 1 matrices), and 1the n x n identity matrix.
Propose a 0(n)-time algorithm to compute the vector (1 + uv'jw, where v' is the transpose of v.
,I Assume that only u, v, ware supplied as input to your algorithm. 1is a constant matrix and does not
.in
An expression tree is a binary tree having two properties: (a) every non-leaf node stores a binary
operator and has two child nodes, and (b) every leaf node stores a numeric operand. Such a tree stands
for an arithmetic expression. For example, the following tree stands for the expression (35/11) +
(69 - (3 * 17)), and evaluates to 21. Assume that the operands are integers, and that the operators to
be supported are +, -, *, / and % with their usual meanings.
r' I
~.. r 1 S,
- Page 1 of4 -
(a) What elements you should store in a node of an expression tree? (3)
(b) Propose an efficient algorithm to evaluate the expression tree. Report error if the input tree is not
a valid expression tree. You do not need to write a C code. A description of your algorithm suffices. (5 + 2)
0n a doubly linked list, each node is given two pointers, the first pointing to the next element in the list,
and the second to the previous element in the list. The next pointer of the last node and the previous
pointer of the first node should be NULL.
(a) Describe a suitable C data type to store a node in a doubly linked list. Suppose that each node in
the list stores an integer key value. (3)
(b) Let L be a sorted doubly linked list (of integers). Write a C function to insert an integer x in L. If
x already resided in L, then the insertion produces no change. If x was absent from L, it is inserted in
the appropriate position so that after the insertion, L continues to remain sorted. (7)
A.8 A d-dimensional Gray code is a listing of all of the 2d binary strings oflength d with any two consecu-
tive strings in the list differing in exactly one position. A recursive construction of Gray codes follows.
For d = 1, it is the listing (0,1). So suppose d ~ 2, and let (SO,SI,... ,s2d-LI) be a (d - 1)-dimensional
Gray code. Then, (Oso, OSI,... , OS2d-1_1,Is2d-LI,"" 1SI, Iso) is a d-dimensional Gray code.
(a) Define a suitable C data type to store an array of2d strings each oflength d. (3) .
w
(b) Write a C function that, upon the input of d, returns the d-dimensional Gray code as a data of type
defined in Part (a). . (7)
w
w
Group B
.s
ol
~Determine the number of integers between 1 and 250 that are divisible by (at least) one of the integers
2,3,5, and 7. (10)
ut
~ Find the general solution of s; -4Sn-1 +4Sn-2 = 2n +n2n. P 'f,..pyP 0-1»: P (10)
, 'f H ) T T t\, .
io
B A biased coin (with probability of obtaining a head equal to p > 0) is tossed repeatedly and indepen-
I dently until the first head is observed. Compute the probability that the first head appears at an even
ns
o
ad
Q;he following two languages are defined over the alphabet L = {O,I}. By nl (y), we denote the
number of l's in the stringy. ~1.~
B.5 (a) Construct a DFA comprising at most six states which accepts the language (over L = {O, I})
in
~) A grammar G = (V, T,S,P) (all symbols having their usual meanings) is said to be right-linear if
all productions are either of the form 'A -+ xB' or of the form 'A -+ x'. Prove that if G is right-linear,
then L (G) is regular. (5)
) Inductively prove that every string produced by the grammar r
S °
-+ 1SO 1OS 11SS 1SSI 1SIS
- Page20f4 -
~~-----------=---------------------------------------------=----------------------------'-
Group C
~ Prove, using Boolean algebraic justifications, that arithmetic overflow is impossible if two n-bit
~mbers of opposite signs are added in a 2 's complement number system. (3)
(b) Consider the Boolean expressions:
I
IP A+BSo+BSl,
IG AB
I
s. +ABS3, and
F IP(J)IG(J)M,
where A,B,M,So,Sl ,Sz and S3 are Boolean variables. Prove, using Boolean algebra, that if M = 1,
(c) From the above expression for F, explain how F can be used to implement all sixteen two-variable
Boolean functions F(A,B). (1)
w
C.2 We wish to design a sequence detector circuit which detects three or more consecutive 1's in an infinite
stream of bits coming through an input line, by making an output line logic-l (which is otherwise at
w
logic-O).
w
(a) Draw the state diagram of the finite state machine. (2)
(b) Determine the type of the circuit (Moore or Mealy machine). (1)
.s
(c) Write the complete state transition table of the circuit, assuming minimum number ofD flip-flops.
ol
C.3 (a) Identify four distinguishing features ofCISC and RISC architectures. (4)
io
i) If multiple devices are connected to the same interrupt line, how does the CPU identify the
source of the interrupt? (2)
ad
ii) Once the interrupting device is identified, how is the corresponding interrupt handler invoked? (2)
iii) How are nested interrupt requests typically handled (arrival of an interrupt request while another
da
(3)
~ In a two-level cache memory system, the parameters are:
Main memory access time: 150 ns 0.>8' ~ 'j. 20(\/1> + ;2..s- j. (.2.0 +(~s ·I.~ f5bN>~t~)
Ll access time: 20 ns
-+ (t~ '/. (so M -+ ~o-o-))
L2 access time: 50 ns . . +150.
Ll hit ratio: 98.5%
L2 hit ratio: 85.0% (w.r.t. the residual accesses that hit L2)
MM-L2 block transfer time: 500 ns
L2-Ll block transfer time: 150 ns '
Estimate the average access time of the memory system. - (4)
..(c) For a set-associative cache memory, estimate the hardware overhead required to identify whether
a requested memory location is present in the cache or not. (3)
- Page 30f4 -
C.S MConsider three processes (process IDs 0,1,2) with CPU burst times 2, 4, 8 units. All processes
arrive at the time zero. Consider the preemptive longest remaining time first (LRTF) scheduling
algorithm. In this algorithm, the process with the longest next remaining CPU time will be scheduled
first. In LRTF, ties are broken by giving priority to tlie process with the lower process id. Compute
the average turnaround time with the help of Gantt chart. Assume that the time units are integral. (4)
~ Assume that we have a demand paged memory. The page table is held in registers. It takes 8 ms
to service page fault if an empty frame is available or if the replaced page is not modified, and 20 ms
if the replaced page is modified. Memory access time is 100 ns. Assume that the page to be replaced
is modified 70% ofthe time. What is the maximum acceptable page-fault rate for an effective access
-
time of no ~ore than 200 ns. ? 0 6 IV' ~ C1- p) x 00 IV> -to p"X ( ::, e '/. "- 'B rI\f) -+ :WI
(c) A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation
look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way
.,....11-
set associative .
3))
storing p to memory. Semaphore S is initialized to two. What is the maximum possible value of p
w
waiting for mutual exclusion. In such a system, explain whether it is possible that a high priority
.s
process gets delayed indefinitely because of the presence oflower priority processes? Assume that no
process does any I/O and there is no deadlock in the system. (3)
ol
(c) A system uses FIFO policy for page replacement. It has four page frames with no pages loaded
to begin with. The system first accesses 100 distinct pages in some order and then accesses the same
ut
100 pages but now in the reverse order. How many page faults will occur? (3)
io
;<;(
f.
ns
ad
da
. in
- Page40f4-