2015-Spr
2015-Spr
[Answer any five questions from Group A, and any five questions from Groups Band c.]
/ Group A
"'-I Write only the answers of the following questions. No need to write any explanation. (2 x 5)
(a) A is a one-dimensional array containing n distinct integers. Span(A) is defined as the difference
between the maximum and the minimum elements in A. Write the time complexity to evaluate Span(A)
by the most efficient algorithm.
(b) The following ay contains all positive integers up to 13:
13 /3 l? g ~ C{... b t.. c: tt d.
Write the values of a, b,c,d so that it is a max-heap.
(c) A linked list contains an unsorted list of n distinct integers. Write the worst-case time complexity of
w
the best algorithm that can copy and store these integers in a one-dimensional array in a sorted manner.
(d) Sand T are two binary trees, each with n nodes. It is known that the asymptotic height of S is O(logn)
w
but that of T is not so. For the most efficient algorithm, what will be the time complexities to measure
w
are as follows:
n
ol
Which one is asymptotically the best and which one is the worst?
0-2
ns
A and B are two unsorted one-dimensional arrays. A contains m distinct integers, and B contains n distinct
integers. However, an element of A may be equal to some element of B. Suggest an algorithm to construct
a one-dimensional array C such that C stores A UB with all distinct elements. Explain the time complexity
ad
of your algorithm. (7 + 3)
~ A is a one-dimensional array with n positive and negative integers in total, which are mixed up. Suggest
da
an algorithm to find the maximum sum over all possible sub-arrays of A. Explain its time complexity. (7 + 3)
o(1V1 + lEI)
.
AA (a) For a graph G = (V,E), provide a time algorithm to check whether G is bipartite. (5)
in
(b) Prove that every nonempty DAG has at least one vertex with zero in-degree. (5)
A.5 (a) Prove that any two strongly connected components of a directed graph are either equal or disjoint. (5)
(b) Analyze the running time of Prim 's algorithm for computing an MST of a connected undirected graph
using binary heaps and adjacency lists. The heap can store a set of vertices (and not edges). (5)
~Stirling numbers S(n,k) (of the second kind) are defined for integers n,k ~ ° recursively as:
S(O,O) 1,
S(n,O) ° ifn>O,
S(n,k) ° ifk> n,
S(n,k) kS(n -I,k) +S(n -I,k- 1) for 1 ~ k ~ n.
Write an efficient C function that takes nand k as arguments, and returns the value of S(n,k). What is the
time complexity of your C function (in terms of nand k)? (8 + 2)
- Page 1 of4 -
v<1 Let us consider a binary search tree in which each node contains five fields: an integer key value, two
child pointers (left and right), and two other integers min and max. The integer min at a node stores the
minimum of all the key values stored in the subtree rooted at that node. Likewise, the max value at a
node stores the maximum key value stored in the subtree rooted at that node.
(a) Declare a C data type to store a node in this tree. (3)
(b) Write a C function that inserts a key value x in this tree. Notice that a binary search tree does not
contain duplicate key values (in multiple nodes). This means that if the new key value x is already present
in the tree, no change is made. (7)
A.8 In a treasure island, there is a rectangular m x n mesh of cells. The cells are numbered by pairs (i,j) with
°~ i ~ m - 1 and °~
j ~ n -1. The entrance to the mesh is at the cell (0,0). The (i,j)-th cells contains
treasure worth ti,j (Indian Rupees). Each pair of adjacent cells (that is, cells sharing a wall, not only a
corner) has a door which may be locked or unlocked. Write a C program that, given the two-dimensional
treasure matrix (ti,j) O~j~m-l and the information about which doors are locked and which are unlocked,
O~}~n-l
computes the total amount of treasure that you can collect from the mesh (entering at cell (0,0). (10)
Group B
w
B.1 (a) Use mathematical induction to prove the following statement for n ~ 1: (3)
w
1 1 1 1 1
-+-+-+ ...
+ =1---.
w
, (b) Prove that there are infinitely many prime numbers. You may use proof by contradiction. (3)
ol
(c) Let A and B be finite sets, and let !!J'(S) denote the power set of a set S. Prove or disprove: (4)
(i) !!J'(A UB) = !!J'(A) U !!J'(B).
ut
~ (a) LetX = {1 ,2, 3, ... , 30}. Define a relation se onX as x:::::;y if and only ifx2 -; is divisible by 5.
ns
(b) Let A and B be sets of a finite size n. Show that if a function f :A --+ B is onto (surjective), then f is
one-to-one (injective). (3)
da
B.3 (a) We hash 5 keys into 5 memory locations one by one. Assume each key is independently and uniformly
hashed into the memory locations.
. in
(i) What is the probability that the first x records do not produce any collision? (3)
(ii) What is the expected value of x when the first collision occurs? (3)
(b) Suppose that Mike selects a ball by fist picking one of two boxes at random and then selecting a ball
from this box at random. The first box contains 4 red balls and 3 blue balls, and the second box contains
2 red balls and 5 blue balls. What is the probability that Mike picked a ball from the second box ifhe has
selected a red ball? (4)
L4 = {w E {a, b, c}* I the first and the last symbols in ware different}.
- Page 2 of4 -
viS The following two sets are defined over the alphabet {a,b,c}. One of these sets is regular, and the other
not. Which one is what? Give proper justifications. (5 + 5)
(a) Lsa = {wlcw21 WI,W2 E {a,b,c}*}.
(b) LSb = {wlcw21 WI,W2 E {a,b,c}*, IWII = IW21}· (Here, Iwd is the length of the string Wi.)
B.6 (a) Give a context-free grammar for the following language: (6)
(b) Show derivations of the strings aababba and aabaaba using your grammar of Part (a). (4)
Group C
C.l (a) Using a 5-variable K-map, find the minimum SoP expression of (5)
(b) Realize f(a, b, c) = I.m(2, 4,5,7) with a 4-to-l multiplexer module (you can use inverters too). (5)
C.2 A sequential machine with two input wires and a single output has a behavior specified in the following
transition table:
w
00
a c b a a 0 0 0 1
w
b d b b e 0 1 1 1
c e d e a 0 0 0 1
.s
d b d b a 0 1 1 1
e a 1
ol
d c c 0 0 0
Demonstrate that this behavior could be exhibited by a machine with fewer states. Draw the state diagram
ut
which stands for the operation: subtract operandl (dest) from operand2 (src1), replace operand2(src1)
ad
with the result, and jump to target address (target) in case of negative result, else go to the next instruction.
Using the above URIse instruction only, write the following instructions: (2 + 3)
da
(b) A designer implemented an 8-bit unsigned adder with an input from his boss that the sum is always
in
less than 255. Hence he left out the hardware required to generate the carry out. But on the c1ose-to-
delivery date, his boss wanted the carry out signal. So, help the designer to design an efficient circuit to
compute the final carry out. (5)
Jl4Ja) A byte-addressable memory with 32 bits of address has to be assisted with a cache memory. The
cache size is 64 KB, and each cache line has 16 bytes.
Show the various parts of the address and identify which parts of the address are used to access the
following cache configurations: (2 + 3)
(i) A Direct Mapped Cache
(ii) A 2- Way Set Associative Cache
\,{t5) Show by a neat diagram how 128K x 8 SRAM chips can be used to build a 256K x 32 memory
unit. The SRAM chips have input ports i) Din (Input Data Lines), ii) Addr (Address Lines), iii) CS (Chip
Select), and iv) Dout (Output Data Lines). The resultant memory unit should have a) Data In (Input Data
Lines), b) Data Out (Output Data Lines), and c) Address (Input Address Lines). (5)
- Page 3 of4 -
C.5 (a) Let m [ oj ... m [4 J be mutexes (binary semaphores, initialized to 1) and P [0 J ... P [4 J be processes.
Suppose that each process P [i J executes the following:
wait (m[iJ); wait (m[ (i+1) mod 4J);
signal (m[iJ); signal (m[(i+1)mod 4J);
Could this cause (i) Deadlock (ii) Starvation? Justify with logic. (4)
(b) Consider N processes sharing the CPU in a round-robin fashion (N ~ 2). Assume that each context
switch takes S msec, and the time quantum is Q msec. For simplicity, assume that processes never block
on any event and simply switch between the CPU and the ready queue. Find the maximum value of Q
(as a functions of N, Sand T) such that no process will ever wait in the ready queue more than T msec. (3)
(c) Suppose that we have a program that consists of eight pages (numbered 1 through 8), and we have four
frames of physical memory for it. Find the minimum number of page faults possible for the following
page-reference string:
123256346373153634243451
Estimate the number of page faults for the same page-reference string when LRU page-replacement
scheme is applied to it, for two different numbers of available frames: 3 frames and 4 frames. (3)
C£ (a) Consider the following solution to the critical-section problem. Two processes Po and PI share the
J~ variable:
w
do {
.s
flag[iJ=true;
while(flag[l-iJ) ;
ol
CriticalSection
ut
flag[iJ=false;
io
Remainder Section
} while (1) ;
ns
Prove or disprove: The above solution satisfies all the necessary requirements of a solution to the critical-
section problem. (3)
ad
where the element A [0 J [0 J is stored at location 200, in a paged system with pages of size 200. A small
process is in the virtual Page 0 (locations 0 to 199) for manipulating the matrix; thus, every instruction
.
in
fetch will be from the virtual Page O. Let there be three physical frames in the main memory. Assume
that the first frame is occupied by the process, and the other two frames are initially empty. Compute the
number of page faults if the process runs: (i) Program I, (ii) Program II. (4)
Program I
for (j = 0; j < 100; j++)
for (i = 0; i < 100; i++)
A[iJ [jJ = 0;
Program II
for (i = 0; i < 100; i++)
for (j = 0; j < 100; j++)
A[iJ [jJ = 0;
l~ What is Belady's anomaly? Justify with explanation why the LRU page-replacement algorithm is
free from Belady's anomaly. (1 + 2)
- Page 4 of4 -