2014-Aut
2014-Aut
[Answer any five questions from Group A, and anyfive questions from Groups B and c.]
Group A
A.I (a) Explain what is mathematically meant by the notationf(n) = O(g(n)), where f(n) andg(n) are
two positive real-valued func~ions of non-negative integers n. (2)
(b) Consider the following functions:
4 + 3 sinn, 5 + 2cosn, )n, 10g2 n, nlogn, and P logn (where I is the number of one bits in n).
From this list, pick two functions f(n) and g(n) such that both f(n) = O(g(n)) and g(n) = o (f(n) ). (2)
(c)" From the list of Part (b), pick two functions f(n) and g(n) such that neither f(n) = O(g(n)) nor
w
A.2 You are given a min-heap H with n elements, and a search key k (not necessarily present in H). Your
w
task is to print all the keys stored in H, that are ~ k. Propose an efficient algorithm to solve this
(8 + 2)
.s
A.3 Suppose that each node in a binary search tree T stores only a numeric data and two child links (and
ol
no other items). Initially, T is created as a BST with respect to the data values used as keys. Part (i)
of the following figure shows a BST with respect to the data values.
ut
io
ns
,
,,
, ,
r
,r
.
ad
. ,
.
da
.:. 3 .:. 3
search(2) search(2)
(i) The old/original data values (ii) The new/updated data values
. in
(a) Now, we want the data item in each node u to be replaced by the sum of the old key values stored
in the data fields of all the nodes in the subtree rooted at u. Part (ii) of the above figure illustrates
this updating process. Design an O(n)-time algorithm to perform this task, where n is the number of
nodes in T. Do not use any extra item (other than data and the two links) in the nodes. (5)
(b) After the computation of Part (a), T need not be a BST with respect to the new/updated data
values. But it continues to remain a BST with respect to the the old/original data values. Write an
efficient algorithm to perform search in the modified T with respect to the old data values. (part (ii)
of the above figure demonstrates a successful search and an unsuccessful search in the modified tree.) (5)
A.4 Let A be an array of n non-zero integers, both positive and negative. The array A need not be sorted,
but it is given that all the negative integers in A appear before all the positive integers in A. Your task
is to find out whether there exist indices i, j with 0 ~ i < j ~ n - 1 such that
- Page 1 of5 -
--------- - -
A.5 Mr. Sarkar plans a flight schedule from City X to City Y. He is given a list of cities and flights from
all airlines connecting pairs of cities. Since Mr. Sarkar is an India-Government employee, he has to
avail flights from Air India and its alliances. A complete list of the alliances of AI is supplied to
Mr. Sarkar. Only when some consecutive cities in anX-to-Y route do not have AI-compliant flights,
Mr. Sarkar is allowed to travel by a non-AI-compliant flight. The task of Mr. Sarkar is to locate a
sequence of cities Xo ,Xl, ... ,}0 with Xo = X. and}0 = Y such that each (Xi ,Xi+ I) is connected by a
flight, and the number of non-AI-compliant legs (Xi,Xi+d is as small as possible. Pose this problem
as a graph-theoretic problem, and solve the problem. Express the running time of your algorithm in
terms of the number of cities and the number of pairs of cities connected by direct flights. (8 + 2)
A.6 A hungry mouse is sitting at the south-west comer of a 20 meter by 20 meter square room. At
the center of the room lies fabulous food F considered as a point. The mouse starts a sequence of
movements in the directionsN,E,S,W,N,E,S,W, ... (where N means north, E means east, Smeans
south, and W means west). One movement is made in one minute. In the first movement/minute, the
mouse covers 20 meters north (and reaches the north-west comer). Each movement makes the mouse
tired, so in each minute the mouse covers only 90% of the distance covered in the previous minute. In
the second minute, the mouse moves 20 x 0.9 = 18 meters toward east, and reaches 2 meters west of
w
the north-east comer of the room. The first few moves of the mouse are shown below.
w
w
N
.s
ol
s
ut
Start
io
After each movement/minute, the mouse checks whether it is within a meter of the food F (inside the
circle surrounding F in the above figure). If so, it jumps on the food and enjoys its dinner. Your task
ns
is to write a C program to find out how many movements/minutes the mouse needs to reach its dinner. (10)
A.7 A Sudoku solution is a 9 x 9 array of integers in the range 1-9 such that each row is a permutation of
ad
1,2,3, ... ,9, and so also is each column. Moreover, if the solution is broken into 3 x 3 blocks, then
each block is again a permutation of 1,2,3, ... ,9. An example of a Sudoku solution is given below:
da
9 2 4 7 6 1 3 8 5
7 3 8 2 4 5 9 6 1
1 6 5 3 8 9 4 2 7
. in
6 5 2 8 7 3 1 4 9
3 7 9 6 1 4 2 5 8
8 4 1 9 5 2 7 3 6
5 8 3 4 9 7 6 1 2
4 9 6 1 2 8 5 7 3
2 1 7 5 3 6 8 9 4
Write a C function that, upon the input of a 9 x 9 array of integers, checks whether the array stores a
Sudoku solution. (10)
A.8 (a) Declare a C data type to store an undirected graph in the adjacency-list representation. (3)
(b) You are given a graph G in the above representation, two vertices u and v (not necessarily distinct)
in G, and a non-negative integer h. By a hop in G, we mean following an edge in G. Your task is to
locate whether v can be reached from u after exactly h hops. Write a C function to solve this problem.
Notice that during the sequence of hops, vertices and edges may be repeated. Moreover, during each
hop, you have to follow an edge (that is, you cannot stay still at a vertex). (7)
- Page20f5-
Group B
B.l A vending machine dispensing books of stamps accepts only $1 coins, $1 bills, and $2 bills. Let an
denote the number of ways of depositing n dollars in the vending machine, where the order in which
the coins and bills are deposited matters.
(a) Find a recurrence relation for an, and give the necessary initial conditionts). (3)
(b) Find an explicit formula for an by solving the recurrence relation in Part (a). (7)
B.2 (a) Given 12 different 2-digit numbers, show that one can choose two of them such that their differ-
ence is a two-digit number with identical first and second digit. (5)
(b) There are three (non-identical) bags and ten (identical) balls. In how many ways can you put all
the balls in the three bags such that no bag is empty and no bag contains more than five balls? (5)
B.3 An aircraft emergency locator transmitter (ELT) is a device designed to transmit a signal in the case
of a crash. The Altigauge Manufacturing Company makes 80% of the ELTs, the Bryant Company
w
makes 15% of them, and the Chartair Company makes the other 5%. The ELTs made by Altigauge
have a 4% rate of defects, the Bryant ELTs have a 6% rate of defects, and the Chartair ELTs have a
w
9% rate of defects (which helps to explain why Chartair has the lowest market share).
w
(a) If an ELT is randomly selected from the general population of all ELTs, find the probability that
it was made by the Altigauge Manufacturing Company. (5)
.s
(b) If a randomly selected ELT is then tested and is found to be defective, find the probability that it
ol
B.4 (a) Construct a DFA to accept the set of strings over {a, b} which contain the two substrings aa and
ut
bb. (7)
io
(b) Design a regular expression for the set of strings on the alphabet {O,1,2} in which every 2 is
followed by exactly two O's and every 1 is followed by either a 0 or by a 20. (3)
ns
(b) All infinite unions of regular sets are also regular. (3)
B.6 Design a pushdown automaton (PDA) to accept the following language. State your acceptance crite-
da
Group C
C.l (a) Minimize f(w,x,y,z) = 1:(0,4, 5, 7,8,9,13,15) to an expression with the smallest possible number
of terms. (3)
(b) Let f(XI ,X2,··· ,Xn-l ,xn) and g(Y1 ,Y2) be self-dual functions. Define
C.2 (a) Draw a Mealy machine for a serial even parity generator which generates a parity bit for every
sequence of three bits that it receives. The system works as follows:
- Page 3 of5 -
(i) For each ofthe first three input bits (taken serially), it outputs zero.
(ii) With the fourth input bit, it outputs a parity (0/1) with respect to the previous three input bits and
then goes to Step (i). (5)
(b) We wish to design a prefix-detector circuit that takes two 16-bit inputs A = aI5 ... ao and B =
bI5 ..• boo The output should be a 16-bit number C = CI5 ... Co which has a 1 at the first position from
the right (least significant bit) at which A and B are unequal. At all other bit positions the output
should be zero. For example, let
In this case, C = 0000 0100 0000 0000. Here, A and B are identical for bits 0-9 but not at bit 10, the
first position from the right where it is so; hence CIO = 1. All the other bits of C are zero. Design a
combinational circuit for such a system. (5)
C.3 Consider the "Subtract and branch if less than or equaf to zero" instruction which subtracts the con-
w
tents in the accumulator from the memory location specified by the first operand and the result is
stored both in the accumulator and the memory location of the first operand. If the result is not
w
(a) How would you implement ''Add $a$ $b$" ($a$ and $b$ being memory locations) using this
instruction? (3)
.s
(b) Develop the datapaths for the CPU to implement this instruction. (4)
ol
(c) List the micro-operations needed to realize this instruction using the developed datapaths (3)
ut
CA (a) Describe and compare polling and vectoring mechanisms for interrupt handling. (5)
(b) Write down the usual C code for the multiplication of two matrices A and B (both n x n) so that
io
C = A x B. Assuming that the matrices are stored in row-major order, identify the array accesses that
are cache un-friendly and suggest restructuring the program to make it more cache friendly. (5)
ns
signal (82);
}
If the initial values of SO, S1, and S2 are 0, 1, and 0, respectively, how many times will process PO
print 'O'? Justify your answer. (2)
(b) A computer system uses 32-bit virtual address, and 32-bit physical address. The physical memory
is byte addressable, and the page size is 4 kbytes. It is decided to use two-level page tables to translate
from virtual address to physical address. Assume that the size of each page table entry is 4 bytes.
(i) What would be the size of the outer page table? (3)
(ii) Explain with a diagram how a virtual address would be translated to a physical address. (5)
C.6 (a) A system uses FIFO policy for page replacement. It has 4 page frames with no pages loaded to
begin with. The system first accesses 100 distinct pages in some order, and then accesses the same
100 pages but now in the reverse order. How many page faults will occur? Give a short justification. (2)
(b) Consider the following solution for the critical section problem. The two processes, PO and PI,
share the following variables:
- Page40f5-
boolean flag [2]
int turn; 1* initialized to 0 or 1*1
The structure of the Process i (i = 0 or 1) is as follows:
do {
flag[i] = true;
while (flag [j]) {
if (turn == j) {
flag[i] = false;
while (turn == j);
flag[i] = true;
}
}
Critical section();
turn = j;
flag[i] = false;
Non-Critical section();
w
} while (1);
w
Does the above solution satisfy all the necessary requirements of the critical-section problem (mutual
exclusion, progress, no-starvation)? For each of the requirements, if the answer is yes, argue why, and
w
- Page 5 of5 -