Documente Academic
Documente Profesional
Documente Cultură
• Sales Office : B-48, Shivalik Main Road, Malviya Nagar, New Delhi-110017
Tel. : 011-26691021 / 26691713
INSTRUCTIONS
DISHA PUBLICATION
ALL RIGHTS RESERVED
© Publisher
No part of this publication may be reproduced in any form without prior permission of the publisher. The author and the
publisher do not take any legal responsibility for any errors or misrepresentations that might have crept in. We have tried
and made our best efforts to provide accurate up-to-date information in this book.
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question
numbers 11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-mark each.
4. Questions are of multiple choice type (MCQ)or numerical answer type. A multiple choice type question will have four
choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
22. Consider the following C program: 26. Which of the following languages is generated by the given
void f (int, short); grammar?
void main () S ® aS | bS | e
{ int i = 100;
(a) {anbm |n, m > 0}
short s = 12;
(b) {w Î {a, b}*|w has equal number of a’s and b’s}
short *p = &s;
__________ ; // call to f () (c) {an|n > 0} È {bn | n > 0} È {anbn|n > 0}
} (d) {a,b}*
Which one of the following expressions, when placed in the 27. Which of the following decision problems are undecidable?
blank above, will NOT result in a type checking error? I. Given NFAs N1 and N2, is L(N1) Ç L(N2) = F?
(a) f (s,*s) (b) i = f (i, s) II. Given a CFG G = (N, S, P, S) and a string x Î S*, does
x Î L(G)?
(c) f (i,*s) (d) f (i,*p)
III. Given CFGs G1 and G2 is L(G1) = L(G2)?
23. The worst case running times of Insertion sort, Merge sort
and Quick sort, respectively, are: IV. Given a TM M, is L(M) = F?
(a) I and IV only (b) II and III only
(a) Q (n log n), Q (n log n), and Q (n2)
(c) III and IV only (d) II and IV only
(b) Q (n2), Q (n2), and Q (n log n)
28. Which one of the following regular expressions represents
(c) Q (n2), Q (n log n), and Q (n log n) the language: the set of all binary strings having two
(d) Q (n2), Q (n log n), and Q (n2) consecutive 0s and two consecutive 1s?
24. Let G be a weighted connected undirected graph with distinct (a) (0+1)*0011(0+1)*+(0+1)*1100(0+1)*
positive edge weights. If every edge weight is increased by (b) (0+1)*(00(0+1)*11+11(0+1)*00)(0+1)*
the same value, then which of the following statements is/ (c) (0+1)*00(0+1)*+(0+1)*11(0+1)*
are TRUE? (d) 00(0+1)*11+11(0+1)*00
P: Minimum spanning tree of G does not change 29. Consider the following code segment:
Q: Shortest path between any pair of vertices does not change x = u – t;
(a) P only (b) Q only y = x * v;
(c) Neither P nor Q (d) Both P and Q x = y + w;
25. Consider the following C program: y = t – z;
#include <stdio.h> y = x * y;
void mystery (int *ptra, int *ptrb){ The minimum number of total variables required to convert
the above code segment to static single assignment form
int *temp; is __________.
temp = ptrb; 30. Consider an arbitrary set of CPU-bound processes with
ptrb = ptra; unequal CPU burst lengths submitted at the same time to a
computer system. Which one of the following process
ptra = temp;
scheduling algorithms would minimize the average waiting
} time in the ready queue?
int main() { (a) Shortest remaining time first
int a=2016, b=0, c=4, d=42; (b) Round-robin with time quantum less than the shortest
mystery (&a, &b); CPU burst
45. What will be the output of the following C program? 50. G = (V,E) is an undirected simple graph in which each edge
void count (int n){ has a distinct weight, and e is a particular edge of G. Which
static int d=1; of the following statements about the Minimum Spanning
Trees (MSTs) of G is/are TRUE?
print f (“%d”, n); I. If e is the lightest edge of some cyclein G, then every
print f (“%d”, d); MST of G includes e
d++;
II. If e is the heaviest edge of some cyclein G, then
if (n>1) count (n – 1);
every MST of G excludes e
print f (“%d”, d);
} (a) I only (b) II only
void main( ){ (c) both I and II (d) neither I nor II
count(3); 51. Let Q denote a queue containing sixteen numbers and S be
} an empty stack. Head (Q) returns the element at the head of
(a) 3 1 2 2 1 3 4 4 4 (b) 3 1 2 1 1 1 2 2 2 the queue Q without removing it from Q. Similarly Top (S)
(c) 3 1 2 2 1 3 4 (d) 3 1 2 1 1 1 2 returns the element at the top of S without removing it from
46. What will be the output of the following pseudo-code when S. Consider the algorithm given below.
parameters are passed by reference and dynamic scoping is
assumed?
a = 3; while Q is not Empty do
void n(x) {x = x * a; print(x);} if S is Empty OR Top(S) £ Head(Q) then
x := Dequeue(Q);
void m(y) {a = 1; a = y – a; n(a); print(a);} Push(S, x);
void main( ) {m(a);} else
x := Pop(S);
(a) 6, 2 (b) 6, 6 Enqueue(Q, x);
(c) 4, 2 (d) 4, 4 end
end
47. An operator delete (i) for a binary heap data structure is to
be designed to delete the item in the i-th node. Assume that
the heap is implemented in an array and i refers to the i-th
index of the array. If the heap tree has depth d (number of The maximum possible number of iterations of the while loop
edges on the path from the root to the farthest leaf), then in the algorithm is _________.
what is the time complexity to re-fix the heap efficiently after 52. Consider the following context-free grammars:
the removal of the element?
G1: S ® aS | B, B ® b | bB
(a) O (1)
G2: S ® aA | bB, A ® aA | B | e, B ® bB | e
(b) O (d) but not O (1)
Which one of the following pairs of languages is generated
(c) O (2d) but not O (d)
by G1 and G2, respectively?
(d) O (d 2d) but not O (2d)
(a) {ambn|m > 0 or n > 0} and {ambn|m > 0 and n > 0}
48. Consider the weighted undirected graph with 4 vertices,
where the weight of edge {i, j} is given by the entry Wi j in (b) {ambn|m > 0 and n > 0} and {ambn|m > 0 or n ³ 0}
the matrix W. (c) {ambn|m ³ 0 or n > 0} and {ambn|m > 0 and n > 0}
(a) {m, K+B (H(m))} (b) {m, K–B (H(m))} output at a rate of 10 megabytes per second. The token
(c) {m, K–A (H(m))} (d) {m, K+A (m)} bucket is currently full and the machine needs to send 12
63. An IP datagram of size 1000 bytes arrives at a router. The mega bytes of data. The minimum time required to transmit
router has to forward this packet on a link whose MTU the data is _______ seconds.
(maximum transmission unit) is 100 bytes. Assume that the 65. A sender uses the Stop-and-Wait ARQ protocol for reliable
size of the IP header is 20 bytes. transmission of frames. Frames are of size 1000 bytes and
The number of fragments that the IP datagram will be the transmission rate at the sender is 80 Kbps (1Kbps =
divided into for transmission is __________ . 1000 bits/second). Size of an acknowledgement is 100
64. For a host machine that uses the token bucket algorithm bytes and the transmission rate at the receiver is 8Kbps.
for congestion control, the token bucket has a capacity The one-way propagation delay is100 milliseconds.
of 1 megabyte and the maximum output rate is 20 Assuming no frame is lost, the sender throughput is
megabytes per second. Tokens arrive at a rate to sustain ________ bytes/second.
2016 -8 SOLVED PAPER - 2016
47. (b)
48. 12 print (1)
3
56. (c)
8 S¢
d b
2 print (3)
5 x 5 a A 2
a c b
8 Print (2)(1) s
The shortest path (excluding x) from 2 to 3 is of weight 12
(2–1–0–3). a
49. 7
57. 384
4 4 Size of memory = 240, Page size = 16KB = 214, No. of pages
= Size of Memory/page size = 240/214 = 226, Size of page
1 table = 226 * 48/8 bytes = 26*6 MB = 384 MB
1 3
5 6 Þ 58. 165
The head movement would be :
2 2
63 => 87 24 movements
50. (b) I is NOT true. Suppose in a rectangular with sides (1, 2,
87 => 92 5 movements
4, 5) and 3 is the weight of the diagonal connecting
vertex between (4, 5) and (1, 2), here e = 3 is the lightest 92 => 121 29 movements
edge of some cycle in G but in MST it is not including. 121 => 191 70 movements
II is true. Let the heaviest edge be e. Suppose the 191 => 10 0 movement
minimum spanning tree which contains e. If we add 10 => 11 1 movement
one more edge to the spanning tree we will create a
11 => 38 27 movements
cycle. Suppose we add edge e' to the spanning tree
which generated cycle C. We can reduce the cost of 38 => 47 9 movements
the minimum spanning tree if we choose an edge other Total head movements = 165
than e from C for removal which implies that e must not 59. 1
be in minimum spann ing tree and we get a a1a2........a20 a1a2...........a20
contradiction. LIFO
51. 256
... n = 16 0 a1
Therefore, maximum number of iterations will be n2 = 256 1 a2
52. (d) In G1, there will be atleast 1 b because S->B and B->b. 2 a3
But no. of A's can be 0 as well and no. of A and B are 3 a4
independent. In G2, either we can take S->aA or S->bB. 4 a5
So it must have atleast 1 a or 1 b. So option (d) is 5 a6
correct. 6 a7 a11 a12 a13 a14 a15 a16 a17 a18 a19 a 20
53. (d) Initial state is also the final state. 7 a8
So an is also accepted. 8 a9
54. (c) 9 a10
55. 9
2 – 5 + 1 – 7 * 3 Þ 2 – (5 + 1) – 7 * 3 For first a1 to a20, The no. of page faults = 20
Þ 2 – 6 – 7 * 3 Þ 2 – (6 – 7) * 3 Þ 2 – (–1) * 3 Now a1 to a9, Hit again a10 to a20 replace only 9th position,
Þ (2 + 1) * 3 Þ 3 * 3 = 9 so no. of page faults = 11. S0, total no. of page faults = 31
2016 -12 SOLVED PAPER - 2016
Optimal 63. 13
Hash L 1000Bytes
M Tx ( msg ) = = = 100 ms
Function Bs 10 ´103 BPS
LA 100Bytes
TA ( Ack ) = = = 100 ms
Senders Private BR 1´103 BPS
–
Key (KB ) H(m) Tp =100 ms
\ Channel Utilization
Tn 100 ms 1
K -B (H (m )) = T + T + 2T = 100 ms + 100 ms + 200 ms = 4
Digital Signature n ack p
generator
1
\ Throughput = h × B = × 10 × 103 = 2.5 Kbps
+ M Å K -B (H (m)) 4
(or 2500 bps)
SOLVED PAPER - 2016 2014-13
2016
SET - 2
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question
numbers 11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-mark each.
4. Questions are of multiple choice type (MCQ)or numerical answer type. A multiple choice type question will have four
choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
GENERAL APTITUDE 4. Pick the odd one from the following options.
(a) CADBE (b) JHKIL
QUESTION 1 TO 5 CARRY ONE MARK EACH (c) XVYWZ (d) ONPMQ
5. In a quadratic function, the value of the product of the
1. The man who is now Municipal Commissioner worked as
____________________. a n + bn
roots (a, b) is 4. Find the value of
(a) the security guard at a university a - n + b- n
(b) a security guard at the university
(a) n4 (b) 4n
(c) a security guard at university
(c) 22n-1 (d) 4n-1
(d) the security guard at the university
2. Nobody knows how the Indian cricket team is going to QUESTION 6 TO 10 CARRY TWO MARKS EACH
cope with the difficult and seamer-friendly wickets in 6. Among 150 faculty members in an institute, 55 are
Australia. connected with each other through Facebook® and 85 are
Choose the option which is closest in meaning to the connected through WhatsApp®. 30 faculty members do
underlined phrase in the above sentence. not have Facebook® or WhatsApp® accounts. The
(a) put up with (b) put in with number of faculty members connected only through
Facebook® accounts is ______________.
(c) put down to (d) put up against
(a) 35
3. Find the odd one in the following group of words.
(b) 45
mock, deride, praise, jeer
(a) mock (b) deride (c) 65
(c) praise (d) jeer (d) 90
2014 -14 SOLVED PAPER - 2016
7. Computers were invented for performing only high-end TECHNICAL SECTION
useful computations. However, it is no understatement
that they have taken over our world today. The internet, QUESTION 11 TO 35 CARRY ONE MARK EACH
for example, is ubiquitous. Many believe that the internet
itself is an unintended consequence of the original 11. Consider the following expressions:
invention. With the advent of mobile computing on our (i) false (ii) Q
phones, a whole new dimension is now enabled. One is left (iii) true (iv) PÚQ
wondering if all these developments are good or, more (v) ØQÚP
importantly, required. The number of expressions given above that are logically
Which of the statement(s) below is/are logically valid and implied by Þ P ^ (P Þ Q) is ________.
can be inferred from the above paragraph? 12. Let f (x) be a polynomial and g(x) = f– (x) be its derivative.
(i) The author believes that computers are not good for If the degree of ( f (x)+ f (–x)) is 10, then the degree of (g(x)
us. – g(–x)) is _______.
(ii) Mobile computers and the internet are both intended 13. The minimum number of colours that is sufficient to vertex-
inventions. colour any planar graph is _______.
(a) (i) only (b) (ii) only 14. Consider the systems, each consisting of m linear equations
(c) both (i) and (ii) (d) neither (i) nor (ii) in n variables.
I. If m < n, then all such systems have a solution
8. All hill-stations have a lake. Ooty has two lakes. Which of
II. If m > n, then none of these systems has a solution
the statement(s) below is/are logically valid and can be
inferred from the above sentences? III. If m = n, then there exists a system which has a
solution
(i) Ooty is not a hill-station.
Which one of the following is CORRECT?
(ii) No hill-station can have more than one lake. (a) I, II and III are true (b) Only II and III are true
(a) (i) only (b) (ii) only (c) Only III is true (d) None of them is true
(c) both (i) and (ii) (d) neither (i) nor (ii) 15. Suppose that a shop has an equal number of LED bulbs
9. In a 2 × 4 rectangle grid shown below, each cell is a of two different types. The probability of an LED bulb
rectangle. How many rectangles can be observed in the lasting more than 100 hours given that it is of Type 1 is
grid? 0.7, and given that it is of Type 2 is 0.4. The probability
that an LED bulb chosen uniformly at random lasts more
than 100 hours is _______.
16. Suppose that the eigen values of matrix A are 1, 2, 4. The
(a) 21 (b) 27 determinant of (A–1)T is _______.
17. Consider an eight-bit ripple-carry adder for computing the
(c) 30 (d) 36
sum of A and B, where A and B are integers represented
10. Choose the correct expression for f(x) given in the graph. in 2’s complement form. If the decimal value of A is one,the
decimal value of B that leads to the longest latency for
the sum to stabilize is _______.
2.5 18. Let, x1Åx2Åx3Åx4= 0 where x1, x2, x3, x4 are Boolean
f(x)
2 variables, and Å is the XOR operator. Which one of the
1.5 following must always be TRUE?
(a) x1x2x3x4 = 0 (b) x1x3 + x2 = 0
1
(c) x 1Å x 3 = x 2Å x 4 (d) x1+ x2+ x3+ x4 = 0
0.5
x
19. Let X be the number of distinct 16-bit integers in 2’s
0
complement representation. Let Y be the number of
-4 -3 -2 -1 0 1 2 3 4
-0.5 distinct 16-bit integers in sign magnitude representation.
-1 Then X - Y is ______.
-1.5 20. A processor has 40 distinct instructions and 24 general
-2 purpose registers. A 32-bit instruction word has an
-2.5 opcode, two register operands and an immediate operand.
The number of bits available for the immediate operand
field is ________.
(a) f (x) = 1 – |x – 1| (b) f (x) = 1 + |x – 1| 21. Breadth First Search (BFS) is started on a binary tree
(c) f (x) = 2 – |x – 1| (d) f (x) = 2 + |x – 1| beginning from the root vertex. There is a vertex t at a
distance four from the root. If t is the n-th vertex in this BFS
traversal, then the maximum possible value of n is ________.
SOLVED PAPER - 2016 2014-15
22. The value printed by the following program is _______. 28. Consider the following types of languages: L1 : Regular, L2
void f(int* p, int m){ : Context-free, L3 : Recursive, L4 : Recursively enumerable.
m = m + 5; Which of the following is/are TRUE?
*p = *p+m; I. L3 È L4 is recursively enumerable
return;
} II. L2 È L3 is recursive
void main () {
int i=5, j=10; III. L*1 Ç L2 is context-free
f(& i, j);
printf (“%d”, i+j);
IV. L1 È L2 is context-free
} (a) I only
23. Assume that the algorithms considered here sort the input (b) I and III only
sequences in ascending order. If the input is already in (c) I and IV only
ascending order, which of the following are TRUE? (d) I, II and III only
I. Quicksort runs in Q(n2) time 29. Match the following:
II. Bubblesort runs in Q(n2) time (P) Lexical analysis (i) Leftmost derivation
III. Mergesort runs in Q(n) time (Q) Top down parsing (ii) Type checking
IV. Insertion sort runs in Q(n) time (R) Semantic analysis (iii) Regular expressions
(a) I and II only (S) Runtime environments (iv) Activation records
(b) I and III only (a) P « i, Q « ii, R « iv,, S « iii
(c) II and IV only (b) P « iii, Q « i, R « ii, S « iv
(d) I and IV only (c) P « ii, Q « iii, R « i, S « iv
24. The Floyd-Warshall algorithm for all-pair shortest paths (d) P « iv, Q « i, R « ii, S « iii
computation is based on 30. In which one of the following page replacement algorithms
(a) Greedy paradigm. it is possible for the page fault rate to increase even when
(b) Divide-and-Conquer paradigm. the number of allocated frames increases?
(c) Dynamic Programming paradigm. (a) LRU (Least Recently Used)
(b) OPT (Optimal Page Replacement)
(d) Neither Greedy nor Divide-and-Conquer nor Dynamic
(c) MRU (Most Recently Used)
Programming paradigm.
(d) FIFO (First In First Out)
25. N items are stored in a sorted doubly linked list. For a
31. B+ Trees are considered BALANCED because
delete operation, a pointer is provided to the record to be
(a) the lengths of the paths from the root to all leaf
deleted. For a decrease-key operation, a pointer is
nodes are all equal.
provided to the record on which the operation is to be
(b) the lengths of the paths from the root to all leaf
performed.
nodes differ from each other by at most 1.
An algorithm performs the following operations on the list
(c) the number of children of any two non-leaf sibling
in this order: Q(N) delete, O(log N) insert, O(log N) find,
nodes differ by at most 1.
and Q(N) decrease-key. What is the time complexity of all
(d) the number of records in any two leaf nodes differ by
these operations put together?
at most 1.
(a) O(log2N) (b) O(N) 32. Suppose a database schedule S involves transactions T1,
(c) O(N2) (d) Q(N2 log N) ...., Tn. Construct the precedence graph of S with vertices
26. The number of states in the minimum sized DFA that representing the transactions and edges representing the
accepts the language defined by the regular expression conflicts. If S is serializable, which one of the following
(0 + 1) * (0 + 1) (0 + 1)* orderings of the vertices of the precedence graph is
is ________. guaranteed to yield a serial schedule?
27. Language L1 is defined by the grammar: S1 ® aS1b|e (a) Topological order
Language L2 is defined by the grammar: S2 ® abS2|e (b) Depth-first order
Consider the following statements: (c) Breadth-first order
P: L1 is regular (d) Ascending order of transaction indices
Q: L2 is regular 33. Anarkali digitally signs a message and sends it to Salim.
Which one of the following is TRUE? Verification of the signature by Salim requires
(a) Both P and Q are true (a) Anarkali’s public key.
(b) P is true and Q is false (b) Salim’s public key.
(c) P is false and Q is true (c) Salim’s private key.
(d) Both P and Q are false (d) Anarkali’s private key.
2014 -16 SOLVED PAPER - 2016
34. In an Ethernet local area network, which one of the 40. Suppose the functions F and G can be computed in 5 and
following statements is TRUE? 3 nanoseconds by functional units UF and UG, respectively.
(a) A station stops to sense the channel once it starts Given two instances of UF and two instances of UG, it is
transmitting a frame. required to implement the computation F(G(Xi)) for 1 £ i
(b) The purpose of the jamming signal is to pad the £ 10. Ignoring all other delays, the minimum time required
frames that are smaller than the minimum frame size. to complete this computation is _______ nanoseconds.
(c) A station continues to transmit the packet even after 41. Consider a processor with 64 registers and an instruction
the collision is detected. set of size twelve. Each instruction has five distinct fields,
(d) The exponential backoff mechanism reduces the namely, opcode, two source register identifiers, one
probability of collision on retransmissions. destination register identifier, and a twelve-bit immediate
35. Identify the correct sequence in which the following value. Each instruction must be stored in memory in a
packets are transmitted on the network by a host when a byte-aligned fashion. If a program has 100 instructions, the
browser requests a web page from a remote server, amount of memory (in bytes) consumed by the program
assuming that the host has just been restarted. text is ________ .
(a) HTTP GET request, DNS query, TCP SYN 42. The width of the physical address on a machine is 40 bits.
(b) DNS query, HTTP GET request, TCP SYN The width of the tag field in a 512 KB 8-way set
(c) DNS query, TCP SYN, HTTP GET request associative cache is________bits.
(d) TCP SYN, DNS query, HTTP GET request 43. Consider a 3GHz (Gigahertz) processor with a three-
stage pipeline and stage latencies t1 , t2 , and t3 such
that t1 = 3 t2 /4 = 2t3. If the longest pipeline stage is split
QUESTION 36 TO 65 CARRY TWO MARKS EACH into two pipeline stages of equal latency, the new
36. A binary relation R on ¥ × ¥ is defined as follows: (a, frequency is_______ GHz, ignoring delays in the
b)R(c, d). If a £ c or b £ d, consider the following pipeline registers.
propositions: 44. A complete binary min-heap is made by including each
P: R is reflexive integer in [1,1023] exactly once. The depth of a node in the
Q: R is transitive heap is the length of the path from the root of the heap
to that node. Thus, the root is at depth 0. The maximum
Which one of the following statements is TRUE?
depth at which integer 9 can appear is _______.
(a) Both P and Q are true.
45. The following function computes XY for positive integers
(b) P is true and Q is false.
X and Y.
(c) P is false and Q is true.
int exp (int X, int Y) {
(d) Both P and Q are false.
int res = 1, a = X, b = Y;
37. Which one of the following well-formed formulae in while (b != 0) {
predicate calculus is NOT valid? if (b%2 == 0) {a = a*a; b = b/2;}
(a) ( " x p(x) Þ " xq(x)) Þ ( $ x Ø p(x) Ú " xq(x)) else {res = res*a; b = b – 1;}
(b) ( $ x p(x) Ú $ xq(x)) Þ $ x (p(x) Ú q(x)) }
(c) $ x (p(x) Ù q(x)) Þ ( $ x p(x) Ù $ xq(x)) return res;
(d) " x (p(x) Ú q(x)) Þ ( " x p(x) Ú " xq(x)) }
Which one of the following conditions is TRUE before
38. Consider a set U of 23 different compounds in a Chemistry
every iteration of the loop?
lab. There is a subset S of U of 9 compounds, each of (a) XY = ab
which reacts with exactly 3 compounds of U. Consider the (b) (res*a)Y = (res*X)b
following statements: (c) XY = res*ab
I. Each compound in U \ S reacts with an odd number of (d) XY = (res*a)b
compounds. 46. Consider the following New-order strategy for traversing
a binary tree:
II. At least one compound in U \ S reacts with an odd
• Visit the root;
number of compounds.
• Visit the right subtree using New-order;
III. Each compound in U \ S reacts with an even number • Visit the left subtree using New-order;
of compounds. The New-order traversal of the expression tree
Which one of the above statements is ALWAYS TRUE? corresponding to the reverse polish expression 3 4 * 5 –
(a) Only I (b) Only II 2 ^ 6 7 * 1 + – is given by:
(a) + – 1 6 7 * 2 ^ 5 – 3 4 *
(c) Only III (d) None (b) – + 1 * 6 7 ^ 2 – 5 * 3 4
39. The value of the expression 1399 (mod 17), in the range (c) – + 1 * 7 6 ^ 2 – 5 * 4 3
0 to 16, is ______ . (d) 1 7 6 * + 2 5 4 3 * – ^ –
SOLVED PAPER - 2016 2014-17
47. Consider the following program: 52. Consider the following two statements:
int f(int *p, int n) I. If all states of an NFA are accepting states then the
{ language accepted by the NFA is å *.
if(n <= 1) return 0; II. There exists a regular language A such that for all
else return max (f (p+1, n–1), p[0]–p[1]); languages B, AÇB is regular.
} Which one of the following is CORRECT?
int main() (a) Only I is true
{ (b) Only II is true
int a[] = {3, 5, 2, 6, 4}; (c) Both I and II are true
printf(“%d”, f(a, 5)); (d) Both I and II are false
} 53. Consider the following languages:
Note: max(x, y) returns the maximum of x and y. L1 = {anbmcn+m : m, n ³ 1}
The value printed by this program is ________ .
L2 = {anbnc2n : n ³ 1}
48. Let A1, A2, A3, and A4 be four matrices of dimensions 10
× 5, 5×20, 20×10, and10 × 5, respectively. The minimum Which one of the following is TRUE?
number of scalar multiplications required to find the (a) Both L1 and L2 are context-free.
product A1A2A3A4 using the basic matrix multiplication (b) L1 is context-free while L2 is not context-free.
method is ________.
(c) L2 is context-free while L1 is not context-free.
49. The given diagram shows the flow chart for a recursive
(d) Neither L1 nor L2 is context-free.
function A(n). Assume that all statements, except for the
recursive calls, have O(1) time complexity. If the worst case 54. Consider the following languages:
time complexity of this function is O(na), then the least L1 = {<M> | M takes at least 2016 steps on some input};
possible value (accurate up to two decimal positions) of a L2 = {<M> | M takes at least 2016 steps on all inputs} and
is ________.
L3 = {<M> | M accepts e};
Flowchart for Recursive Function A(n)
where for each Turing machine M, <M> denotes a specific
encoding of M. Which one of the following is TRUE?
Start
(a) L1 is recursive and L2, L3 are not recursive
A(n / 2)
(b) L2 is recursive and L1, L3 are not recursive
(c) L1, L2 are recursive and L3 is not recursive
Return A(n / 2) A(n / 2) A(n / 2) Return (d) L1, L2, L3 are recursive
55. Which one of the following grammars is free from left
recursion?
A(n / 2)
(a) S ® AB
A ® Aa | b
Return A(n / 2) Return
B ® c
(b) S ® Ab | Bb | c
50. The number of ways in which the numbers 1, 2, 3, 4, 5, A ® Bd | e
6, 7 can be inserted in an empty binary search tree, such
that the resulting tree has height 6, is ________. B ® e
Note: The height of a tree with a single node is 0. (c) S ® Aa | B
51. In an adjacency list representation of an undirected simple A ® Bb | Sc | e
graph G = (V, E), each edge (u, v) has two adjacency list
entries: [v] in the adjacency list of u, and [u] in the B ® d
adjacency list of v. These are called twins of each other. (d) S ® Aa | Bb | c
A twin pointer is a pointer from an adjacency list entry to
A ® Bd | e
its twin. If |E| = m and |V | = n, and the memory size is not
a constraint, what is the time complexity of the most B ® Ae | e
efficient algorithm to set the twin pointer in each entry in 56. A student wrote two context-free grammars G1 and G2 for
each adjacency list? generating a single C-like array declaration. The dimension
(a) Q (n2) (b) Q (n + m) of the array is at least one. For example,
(c) Q (m2) (d) Q (n4) int a [10] [3];
2014 -18 SOLVED PAPER - 2016
The grammars use D as the start symbol, and use six
terminal symbols int ; id [ ]num.
90
Grammar G1 Grammar G2
80
D ® int L; D ® int L;
70
( )
-1 T T 1 that no. of a’s should be equal to no. of b’s, but order
Now, A = A -1 = A -1 = = 0.125
8 of a’s and b’s is different here, it is (ab)*, which will
require no extra memory to be accepted. (Finite
17. –1
Automaton can be built for this language). Hence L2 is
18. (c) regular language. Therefore Q is True.
19. 1
28. (d) Statement (IV) : L2 may or may not be context free
X = –216 – 1 to +216 – 1 – 1
Y = –216 – 1 – 1 to +216 – 1 – 1 because CFL are not closed under complementation.
So it is not true.
Therefore, X – Y = 1
29. (b)
20. 16 6 bits are needed for 40 distinct instructions (because,
30. (d) When the rate of page fault increases even after the
32 < 40 < 64) 5 bits are needed for 24 general purpose
increasing number of allocated frames, then this
registers (because, 16 < 24 < 32) 32-bit instruction word
situation is called “Belady’s Anamoly”. In the given
has an opcode(6 bit), two register operands(total 10
options, it’s occurring in FIFO only.
bits) and an immediate operand (x bits). The number of
31. (a) In B and B+ trees, all the leaf nodes will be at same
bits available for the immediate operand field => x = 32
level.
– (6 + 10) = 16 bits
32. (a)
33. (a) In the process of digital signature generation, by using
sender’s private key, one can encrypt the message and
in the process of verification, by using sender’s public
key, one can decrypt the message.
21. 31 34. (d)
35. (c) When a web browser requests any web page from a
remote server then that request (URL address) is
mapped to IP Address usin g DNS, th en TCP
It would be node number 31 for given distance 4. synchronisation occurs. Finally HTTP verifies that the
22. 30 address exists in the web server or not.
The address of i and value of j are passed to the function of 36. (b) R is reflexive as every ordered pair is related to itself.
f. f modifies i’s value to 20. j’s value remains same (as its (a, b) R (a, b) since a £ a or b £ b
value is passed not the reference). The value printed by the
It is not transitive as (2, 4) R (3, 2) and (3, 2) R(1, 3) but
program will be i + j = 20 + 10 = 30.
(2, 4) R (1, 3).
2014 -22 SOLVED PAPER - 2016
37. (d) P and Q are unary relations. Therefore one can model have to do 10 such calculations. According to question,
each of them as sets Ps and Qs, where P(x) iff x Î Ps and we have 2 instances of UF and UG respectively. So, UF
Q(x) iff x Î Qs. Let W be every object in the universe. can be done in 50/2 = 25 nano seconds. For the start,
Now we can convert each statement into sets:
UF needs to wait for UG output for 3 ns and rest all are
(i) ("xp ( x ) Þ "xq ( x ) ) Þ ( $xØp ( x ) Ú "xq ( x ) ) pipelined and hence no more wait. Therefore, the
Converting the Ú to Þ, we get answer will be:
3 + 25 = 28 ns
( "xp ( x ) Þ "xq ( x ) ) Þ ( Ø$xØp ( x ) Þ "xq ( x ) ) 41. 500 Given No. of registers = 64
( "xp ( x ) Þ "xq ( x ) ) Þ ( "xp ( x ) Þ "xq ( x ) ) Required No. of bits to address registers = log2 64 = 6
Given No. of instructions = 12
Hence, the formula is valid if, for any model where
\ Opcode size = log212 = 4
( "xp ( x ) ) Þ "xq ( x ) ) holds, that ( "xq ( x ) Þ "xq(x ) ) Opcode + 3 reg address + 12 bit immediate value
also holds.
Opcode Reg 1 Reg 2 Reg 3
Immediate
(ii) ( $xp ( x ) Ú $xq ( x ) ) Þ $x ( p ( x ) Ú q ( x ) ) 4 6 6 6 12
If Ps or Qs is not empty, then Ps U Qs is not empty.. Total bits per instruction = 34
Total bytes per instruction = 4.25
It can be easily showed that this holds for any model.
Due to byte alignment 0.75 byte will waste while storing
(iii) $x ( p ( x ) Ù q ( x ) ) Þ ( $xp ( x ) Ù $xq ( x ) ) 4.25 bytes.
Total no. of bytes per instruction = 5
If Ps I Qs is non-empty then Ps is non-empty and Qs is
Total no. of instructions = 100
non-empty. Anything can model this.
Total size = No. of Instructions × Size of Instruction
(iv) "x ( p(x) Ú q ( x ) ) Þ x" ( p(x) Ú "xq(x) ) = 100 × 5 = 500 Bytes
42. 24
If Ps U Qs = W, then Ps = W or Qs = W. This is obviously Tag Set Offset
not true for any choice of Ps and Qs. Actually the only
40 bits
times it will be true is:
(a) When Ps = W, meaning P(x) = True, or Tag bits = 40 – (19 – 3) = 24 bits
(b) When Qs = W, meaning Q(x) = True, or 43. 4
Pipeline
(c) When Ps I Qs ¹ W , i.e., when there is a value of
x where both P(x) and Q(x) do not hold. 4
z1 z1 z1/2
In any other case the choice of P() and Q() will 3
not satisfy (iv). 4
38. (b) The given problem can be solved by taking an tp = z1
3
undirected graph with 23 vertices and 9 of these with
degree 3. New Pipeline
Suppose that if two compounds react with each other, 2 2
then there exists an edge between the vertices. z1 z1 z1
3 3 z1/2
According to Theorem of Degree, atleast one of the
remaining vertices must have odd degree (since m
number of vertices of odd degree is always even).
tp = z 1
39. 4 We have 13 * 13 * 13 * ... * 13 (total 99 terms)
By Remainder theorem, Þ (-4) * (-4) * ... * (-4) (total 99 44. 8 Within ‘n’ levels of min heap, nth smallest element will
terms) Þ 16 * 16 * ... * 16 * (-4) (total 50 terms, 49 terms be present.
for 16 and one term for -4). Reapplying Remainder 45. (c) Before Iteration 1: X^Y=64 res * (a^b)=64
theorem, Þ (-1) * (-1) * ... * (-1) * (-4) (total 50 terms, 49 Before Iteration 2: X^Y=64 res * (a^b)=64
terms for -1 and one term for -4) Þ (-1) * (-4) Þ 4
Before Iteration 3: X^Y=64 res * (a^b)=64
40. 28 This concept is used in pipelining. The important thing
46. (c) The expression tree for the given post-fix expression
here is UF as it takes 5 ns while UG takes 3 ns only. One
is as follows:
SOLVED PAPER - 2016 2014-23
49. 2.32
50. 64
–
To fill 7 levels with 7 elements, at each level we have exactly
2 possible options like 1 and 7 for root one corresponding
+ to making it left skewed and other right skewed. This is
valid for all levels upto 6.
Hence, 26 = 64.
– 1 51. (b) Twin Pointers can be set up by keeping track of parent
2 *
node in BFS or DFS of graph.
* 52. (b) Statement I is not true, because if all the states of DFA
5
2 7
6 are accepting states then the language accepted by
3 4 the DFA is å*
Statement II is true because one can have regular
New-order of shown expression tree is language A = [ ] [Empty Language] which satisfies the
–+ 1*7 6^ 2–5*4 3 given condition.
47. 3 53. (b) L2 is not context free. No. of b’s will match with no. of
Assume base address of array a is 100. a’s leaving c’s to be matched with no one. So L2 cannot
be context free.
3 5 2 6 4 54. (c)
55. (b) Grammar A has direct left recursion because of the
100 102 104 106 108 production rule: A®Aa. Grammar C has indirect left
recursion because of the production rules:S®Aa and
main A®Sc Grammar D has indirect left recursion because
ß of production rules : A®Bd and B®Ae Grammar B
pf (f (100, 5)) 3Þwill be printed doesn't have any left recursion (neither direct nor
ß c 3 indirect).
max (f(102, 4), –2) 56. (a) Both G1 and G2 can correctly generate the declarations.
ß c 3
57. 8.25
ret max (f (104, 3), 3)
ß c 2 Due to SRTF preemption
ret max (f (106, 2), –4)
ß c 2 P1 P2 P3 P2 P4 P1
return max (f (108, 1), 2) 0 3 7 8 10 13 20
ß c 1 ... Completion Time = Arrival Time + Process Turn Around
Time
Return 1 \ Process Turn Around Time = Completion Time – Arrival
48. 1500 Time
We have four matrices A1, A2, A3 and A4, we would have P1 20
((A1A2)A3)A4 = ((A1(A2A3))A4) = (A1A2) (A3A4) P2 7
= A1 ((A2A3)A4) = A1(A2(A3A4)) P3 1
Here A1 is a 10 × 5 matrix, A2 is a 5 × 20 matrix, and A3 is a 20
P4 5
× 10 Matrix and A4 is 10 × 5. Multiplying two matrices A and
B of order l × m and m × n respectively, we get the number of Average Turn Around Time (TAT) = 33/4 = 8.25
scalar multiplications in the multiplication of A and B. That 58. (c)
will be l × m × n. The given statement for two process synchronization using
Therefore, the number of scalar multiplications required in “Turn” variable, fulfils the condition of only mutual exclusion
the following sequence of matrices will be: and bounded waiting but the progress is violated.
A1 ((A2A3)A4) = (5 × 20 × 10) + (5 × 10 × 5) + (10 × 5 × 5) 59. 7
= 1000 + 250 + 250 = 1500 S = – 20 + 12 = – 8
All other options will require more than 1500 number of \ The highest intial value of S for which atleast one P(S)
multiplications. operation remains blocked is 7.
2014 -24 SOLVED PAPER - 2016
60. 30 Suppose minimum frame size is L bits. Tx = L / B where B is
61. (c) the bandwidth = 20 * 106 bits/sec
There is no transaction which reads the data item written by Tp = 40 micro seconds (given)
any other transaction. Therefore the given schedule is Tx = 2 Tp L / B = 80 micro seconds
cascadeless. L = B ´ 80 micro seconds = 20 ´ 106 bits/sec ´ 80 micro
seconds = 1600 bits
62. 2
Now as the answer has to be given in Bytes, hence, 1600/8
First we should perform group by group. We get ajmer 1
bytes = 200 bytes.
bikaner 3 64. (b) RTS-CTS mechanism is used in collision avoidance,
charu 2 but not in collision detection. Hence statement II is
dungargarh 1 false.
Now we should perform total capacity we will get 100. Now 65. 4
perform avg. capacity on total 100/4 = 25. bikaner = 40 which To achieve 100% efficiency, the number of frames that we
is greater than 25 charu is 30 which is also greater than 25. should send = 1 + 2 ´ Tp / Tt where, Tp is propagation delay,
Hence charu and bikaner will be printed therefore answer is and Tt is transmission delay. So, Number of frames sent = 1
+ 4.687 = 5.687 (approx 6). As the protocol used is Selective
2 tuples.
repeat, Receiver window size should be equal to Sender
63. 200 window size. Then, Number of distinct sequence numbers
For frame size to be minimum, its transmission time should required = 6 + 6 = 12 Number of bits required to represent 12
be equal to twice of one way propagation delay, i.e., Tx = 2Tp distinct numbers = 4
SOLVED PAPER - 2015 2015-1
2015
SET - 1
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question numbers
11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-marks each.
4. Questions are of Multiple Choice Question (MCQ) or Numerical Answer type. A multiple choice question will have
four choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
14. The height of a tree is the length of the longest root-to-leaf 21. Which of the following statements is/are FALSE?
path in it. The maximum and minimum number of nodes in I. XML overcomes the limitations in HTML to support a
a binary tree of height 5 are structured way of organizing content.
(a) 63 and 6, respectively II. XML specification is not case sensitive while HTML
(b) 64 and 5, respectively specification is case sensitive.
(c) 32 and 6, respectively III. XML supports user defined tags while HTML uses pre-
(d) 31 and 5, respectively
defined tags.
15. Match the following:
IV. XML tags need not be closed while HTML tags be
P: Prim’s algorithm for minimum spanning tree
closed
Q: Floyd – Warshal algorithm for all pairs shortest paths
R: Mergesort (a) II only (b) I only
S: Hamiltonian circuit (c) II and IV only (d) III and IV only
(I) Backtracking (II) Greedy method 22. A file is organized so that the ordering of data records is the
(III) Dynamic programming same as or close to the ordering of data entries in some index.
(IV) Divide and conquer Then that index is called
(a) P-III, Q-II, R-IV, S-I (a) Dense (b) Sparse
(b) P-I, Q-II, R-IV, S-III (c) Clustered (d) Unclustered
(c) P-II, Q-III, R-IV, S-I 23. Which of the following is/are correct inorder traversal
(d) P-II, Q-I, R-III, S-IV sequence(s) of binary search tree(s)?
16. Which one of the following is NOT equivalent to p«q? I. 3, 5, 7, 8, 15, 19, 25 II. 5, 8, 9, 12, 10, 15, 25
(a) (Øpvq)^(p^Øq) (b) (Øpvq) ^(q®p)
III. 2, 7, 10, 8, 14, 16, 20 IV. 4, 6, 7, 9, 18, 20, 25
(c) (Øp^q)v(p^Øq) (d) (Øp^Øq) v(p^q)
(a) I and IV only (b) II and iii only
17. SELECT operation in SQL is equivalent to
(c) II and IV only (d) II only
(a) the selection operation in relational algebra
(b) the selection operation in relational algebra, except that 24. Suppose two hosts use a TCP connection to transfer a large
SELECT in SQL retains duplicates file. Which of the following statements is/are FALSE with
(c) the projection operation in relational algebra respect to the TCP connection?
(d) the projection operation in relational algebra, except I. If the sequence number of a segment is m, then the
that SELECT in SQL retains duplicates sequence number of the subsequent segment is always
18. For any two languages L1 and L2 such that L1 is context-free m + 1.
and L2 is recursively enumerable but not recursive, which of II. If the estimated round trip time at any given point of
the following is/are necessarily true? time is t sec the value of the retransmission timeout is
I. L1 (complement of L1) is recursive always set to greater than or equal to t sec.
III. The size of the advertised window never changes
II. L2 (complement of L2) is recursive
during the curse of the TCP connection.
III. L1 is context – free IV. The number of unacknowledged bytes at the sender is
always less than or equal to the advertised window.
IV. L1 È L2 is recursively enumerable
(a) III only (b) I and III only
(A) I only (B) III only
(c) I and IV only (d) II and IV only
(C) III and IV only (D) I and IV only
25. For computers based on three-address instruction formats,
19. For a set A, the power set of A is denoted by 2A. If A = {5,
each address field can be used to specify which of the
{6}, {7}}, which of the following options are TRUE?
I. fÎ 2A II. f Î 2A following.
III. {5, {6}} Î 2A IV. {5{6}} Í 2A S1: A memory operand
(a) I and III only (b) II and III only S2: A processor register
(c) I, II and III only (d) I, II and IV only S3: An implied accumulator register
20. Consider a 4-bit Johnson counter with an initial value of (a) Either S1 or S2 (b) Either S2 or S3
0000. The counting sequence of this counter is (c) Only S2 and S3 (d) All of S1, S2 and S3
(a) 0, 1, 3, 7, 15, 14, 12, 8, 0 26. Consider a system with byte–addressable memory, 32-bit
(b) 0, 1, 3, 5, 7, 9, 11, 13, 15, 0 logical addresses, 4 kilobyte page size and page table entries
(c) 0, 2, 4, 6, 8, 10, 12, 14, 0 of 4 bytes each. The size of the page table in the system in
(d) 0, 8, 12, 14, 15, 7, 3, 1, 0 megabytes is ______.
2015 -4 SOLVED PAPER - 2015
27. The following two functions P1 and P2 that share a variable 34. Match the following:
B with an initial value of 2 execute concurrently. P: Condition coverage
P1 ( ) { P2 ( ) { Q: Equivalence class partitioning
C = B – 1; D = 2 * B;
R: Volume testing
B = 2 * C; B = D – l;
} } S: Alpha testing
28. limx®¥ x1/x is (I) Black-box testing (II) System testing
(a) ¥ (b) 0 (III) White-box testing (IV) Performance testing
(c) 1 (d) Not defined
(a) P-II, Q-III, R-I, S-IV
29. Which one of the following is the recurrence equation for the
worst case time complexity of the Quicksort algorithm for (b) P-III, Q-IV, R-II, S-I
sorting n (³ 2) numbers? In the recurrence equations given (c) P-III, Q-I, R-IV, S-II
in the options below, c is a constant. (d) P-III, Q-I, R-II, S-IV
(a) T(n) = 2T(n/2) + cn
(b) T(n) = T(n–1) + T(1) + cn é 2 2ù
(c) T(n) = 2T(n–1) + cn 35. In the LU decomposition of the matrix ê 4 9ú , if the
ë û
(d) T(n) = T(n/2) + cn
diagonal elements of U are both 1, then the lower diagonal
x g(h(x))
30. If g(x) =1 – x and h(x) = , then is entry l22 of L is ______.
x -1 h(g(x))
QUESTION 36 TO 65 CARRY TWO MARKS EACH
h(x) -1
(a) (b) 36. The graph shown below has 8 edges with distinct integer edge
g(x) x
weights. The Minimum Spanning Tree (MST) is of weight 36
g(x) x
(c) (d) and contains the edges: {(A, C), (B, C), (B, E),
h(x) (1 - x) 2 (E, F), (D,F)}. The edge weights of only those edges which
31. In one of the pairs of protocols given below, both the are in the MST are given in the figure shown below. The
protocols can use multiple TCP connections between the minimum possible sum of weights of all 8 edges of this graph
same client and the server. Which one is that? is _______.
(a) HTTP, FTP (b) HTTP, TELNET
(c) FTP, SMTP (d) HTTP, SMTP
32. What are the worst-case complexities of insertion and 15
B E
deletion of a key in a binary search tree? 4
(a) q(log n) for both insertion and deletion
(b) q(n) for both insertion and deletion A F
2
(c) q.(n) for insertion and q(log n) for deletion
(d) q(log n) for insertion and q(n) for deletion 9 6
33. The output of the following C program is ______. D
C
void f1(int a, int b)
{
int c; 37. Consider a disk pack with a seek time of 4 milliseconds and
c=a; a=b; b=c; rotational speed of 10000 Rotations Per Minute (RPM). It
} has 60 sectors per track and each sector can store 512 bytes
void f2(int *a, int *b) of data. Consider a file stored in the disk. The file contains
{ 2000 sectors. Assume that every sector access necessitates a
int c; seek, and the average rotational latency for accessing each
c=*a; *a=*b; *b=c; sector is half of the time for one complete rotation. The total
}
time (in milliseconds) needed to read the entire file is
int main ( )
_______.
{
int a=4, b=5, c=6; 38. Consider the following pseudo code, where x and y are
f1(a, b); positive integers.
f2(&b, &c); begin
printf(“%d”, c–a–b); q: = 0
} r:=x
SOLVED PAPER - 2015 2015-5
while r > y do 41. Consider the NPDA < Q = {q0, q1, q2}, S = {0, 1},
being G = {0, 1,}^d, q0, ^, F = {q2}>, where (as per usual
r:=r–y convention) Q is the set of states, S is the input alphabetd is
q:=q+1 the stack alphabet, d is the state transition function, q0 is the
end initial state, ^ is the initial stack symbol, and F is the set of
end accepting states. The state transition is as follows:
The post condition that needs to be satisfied after the program
terminates is 1, Z ® Z 0, 1Z ® Z
(a) {r = qx + y Ù r < y} 0, Z ® 0Z 1, 0Z ® Z
(b) {x = qy + r Ù r < y} q0 q1 q2
(c) {y = qx + r Ù 0 < r < y}
(d) {q + 1 < r – y Ù y > 0}
39. Consider the following relations:
Students 0/1/ Î
, Z Z® Î, ^ ® Î
55. Consider the following C function. 60. Consider the following C program segment.
int fun1 (int n) while (first <= last)
{ {
int i, j, k, p, q = 0; if (array[middle] < search)
for (i = 1; i < n; ++i) first = middle + 1;
{ else if (array[middle] = = search)
p = 0; found = TRUE;
for(j = n; j > 1; j = j/2) else last = middle – 1;
++p; middle = (first + last)/2;
for(k =1; k < p; k = k*2) }
++q; if (first > last) notPresent = TRUE;
}
return q; The cyclomatic complexity of the program segment is
} ______.
Which one of the following most closely approximates the 61. Consider a max heap, represented by the array: 40, 30, 20,
return value of the function fun1? 10, 15, 16, 17, 8, 4.
(A) n3 (B) n(log n)2
Array Index 1 2 3 4 5 6 7 8 9
(C) n log n (D) n log(log n)
Value 40 30 20 10 15 16 17 8 4
56. Consider a non-pipelined processor with a clock rate of 2.5
gigahertz and average cycles per instruction of four. The Now consider that a value 35 is inserted into this heap. After
same processor is upgraded to a pipelined processor with five insertion, the new heap is
stages; but due to the internal pipelined delay, the clock speed (a) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
is reduced to 2 gigahertz. Assume that there are no stalls in (b) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
the pipeline. The speed up achieved in this pipelined (c) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
processor is _____. (d) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
57. Consider an Entity-Relationship(ER) model in which entity 62. Suppose the following disk request sequence (track numbers)
sets E1 and E2 are connected by an m: n relationship R12. E1 for a disk with 100 tracks is given: 45, 20, 90, 10, 50, 60, 80,
and E3 are connected by a 1: n (1 on the side of E 1 and n on 25, 70. Assume that the initial position of the R/W head is on
the side of E3) relationship R13. track 50. The additional distance that will be traversed by the
E1 has two single-valued attributes a11 and a12 of which a11 R/W head when the Shortest Seek Time First (SSTF)
is the key attribute. E2 has two single-valued attributes a21 algorithm is used compared to the SCAN (Elevator)
and a22 of which is the key attribute. E3 has two single-valued algorithm (assuming that SCAN algorithm moves towards
attributes a31 and a32 of which a31 is the key attribute. The 100 when it starts execution) is ______ tracks.
relationships do not have any attributes. 63. Consider a LAN with four nodes S1¸S2, S3 and S4. Time is
If a relational model is the derived from the above ER model, divided into fixed-size slots, and a node can begin its
then the minimum number of relations that would be transmission only at the beginning of a slot. A collision is said
generated if all the relations are in 3NF is _______.
to have occurred if more than one node transmit in the same
99 slot. The probability of generation of a frame in a time slot
1
58. å x(x + 1)
= ______________ .
by S1, S2, S3 and S4 are 0.1, 0.2, 0.3 and 0.4, respectively.
x =1
The probability of sending a frame in the first slot without any
59. Let a n represent the number of bit strings of length n collision by any of these four stations is ________.
containing two consecutive 1s. What is the recurrence
64. An algorithm performs (log N)1/2 find operations, N insert
relation for an?
operations, (log N)1/2 delete operations, and (log N)1/2
(A) an–2+ an–1+2n–2
decrease-key operations on a set of data items with keys
(B) an–2+2an–1+2n–2
drawn form a linearly ordered set. For a delete operation, a
(C) 2an–2+a n–1+2n–2
pointer is provided to the record that must be deleted. For the
(D) 2an–2+2an–1+2n–2
2015 -8 SOLVED PAPER - 2015
decrease-key operation, a pointer is provided to the record
that has its key decreased. Which one of the following data 1 p=q+r
structures is the most suited for the algorithm to use, if the s=p+q
u=s*v
goal is to achieve the best asymptotic complexity considering
all the operations?
(a) Unsorted array
(b) Min–heap
2 v=r+u 3 q=s*u
(c) Sorted array
(d) Sorted doubly linked list
65. A variable x is said to be live at a statement Si in a program
if the following three conditions hold simultaneously: 4 q=v+r
I. There exists a statement Sj that uses x
II. There is a path from S i to S j in the flow graph The variables which are live at the statement in basic block
corresponding to the program 2 and at the statement in basic block 3 of the above control
III. The path has no intervening assignment to x including flow graph are
at Si and Sj (A) p, s, u (B) r, s, u
(C) r, u (D) q, v
SOLVED PAPER - 2015 2015-9
él l11u12 ù
g ( h ( x )) h (x) = ê 11 ú
= ël21 l21u12 + l22 û
h ( g ( x )) g (x)
\ l11 = 2;l11u12 = 2 Þ u12 = 1
31. (d) HTTP (Hyper Text Transfer Protocol) and SMTP l21 = 4; l21u12 + l22 = 9 Þ l22 = 5
(Simple Message Transfer Protocol) protocols can use
several TCP associations between the same client and 15
the server. B E
10 4
32. (b) If we judge a single string of binary search tree, then
we have to sketch all the nodes for insertion or deletion
2 7 F
in worst case hence θ (n) for both. A
36. 69
33. –5 In function "main ()" 9 6
D
f1 is called by value, so local variables a, b, c of f1 are C
16
customized but not the local variables a, b, c of main
function.
f2 is called by reference. Total sum = 10 + 9 + 2 + 15 + 7 + 16 + 4 + 6 = 69
int main () { 37. 14020
int a = 4, b = 5, c = 6 Given that
f1(a, b) Seek time = 4ms
f2(&b, &c) 60s ® 10000 rotations
printf ("%d", c-a-b); 60s ® 10000 rotations
}
60
f2(int *a, int *b) = 6ms ¬ 1 rotation time
{ 10000
int c; 1
c = * a; c 5 \ Rotational Latency = ´ 6ms = 3ms
2
* a = b; [will change 'b' value of main to c value of
1 track ® 600 sectors
main]
6ms ¬ 600 sectors (1 rotation means 600 sectors or 1 track)
*b = c; [will change 'c' value of main to c value of f2]
} 6ms
34. (d) Condition coverage is also known as predicate coverage 1 sector ® = 0.01ms
600
in which each of the Boolean expression estimated to 2000 sector ® 2000 (0.01) = 20 ms
both true and false.Which is nothing but white-box \ Total time
testing, which tests internal structures of a function? needed to read the entire tile is = 2000 (4 + 3) + 20
Hence = 8000 + 6000 + 20
P matches with III. = 14020 ms
2015 -12 SOLVED PAPER - 2015
38. (b) The loop terminater when r < y. so, r < y is one post 50. (b)
condition. 51. (d) Given that l1 = –1 and l2 = 7 are eigen values of A
In each iteration q is incremented by 1 and y is
subtracted from r. Initialvalue of r is x. By the properties, l1 + l2 = tr ( A ) , traces of A i.e.,
x x sum of the diagonal elements and l1 . l 2 = determinant
So, loop iterates times and q will be equal to
y y of A.
and r = x% y Þ x = qy + r Þ 1+a=6
So, (b) is correct answer. a=5
39. (2) Output table is And ¯
Raj 310 a – 4b = –7
Rohit 140 5 – 4b = –7
–4b = –7 –5
T1 T2 T1 T3 T1 T2 T1 T3 T1 ... –4b = –12 Þ b = 3
40.
1 2 4 5 7 8 10 11 (13) 14
æ1ö
41. (d) 42. (c) 2 cos ç ÷
è x ødx
43. (a) It is clear that from the truth table, the binary operation 52. (-1) òp
1
x2
# is equivalent to XOR i.e., Å,which satisfies both p
commutative and associative i.e., p # q º q # p and p
# (q # r) º (p # q) # r 1
Put =t
44. 3 x
45. 1 M accepts the strings which end with a and N accepts
the strings which end with b. Their intersection should -1
Þ dx = dt
accept empty language. x2
a, b And
2 p
x= Þt=
p 2
46. (a) 1
x= Þ t =p
47. (d) Number of elements in L3 = Number of ways in which p
we can choose 3 elements from 5 with repetition
æQ b f x dX = - a f x dx ö
= 5 × 5 × 5 = 125 Now, when we take x = t, then also the ç òa ( ) òb ( ) ÷ø
given condition is satisfied for any y and z. Here, y è
and z can be taken in 5 × 5 = 25 ways. p
Take x = r, y = p, z = p, these, also the given condition = òp cos t dt
2
25 1
is satisfied. So, pr > > .
p æp ö
125 5 = ( sin t ) p = sin p = sin ç ÷ = -1
For x = p, y = r, z = t , the given condition is not è2ø
2
satisfied.
53. 320 Given that B = 64 kbps
So, Pr ¹ 1.
Tp = 20 ms
So, (d) corret option.
48. (d) h ³ 50%
49. 24 By Euler's formula, For h ³ 50% Þ L ³ BR
|V|+|R| = |E|+2 _________ (1) where |V|, |E|, |R| are Þ L = 64 ×103 × 2 × 20 × 10–3
respectively number of vertices, edges and faces = 2560 bits = 320 bytes
(regions) 54. (a)
Q prev. O Q
Given |V| = 10 _______ (2) and number of edges on
each face is three — 1 0
2 0 0 1
` \ 3|R| = 2|E| Þ |R| = 3 |E|_________ (3) 1 1 1
Subtracting (2), (3) in (1), we get 1 1 0
E 0 0 1
2
10 + E = E + 2 Þ = 8 Þ E = 24 1 1 1
3 3
SOLVED PAPER - 2015 2015-13
D flipflop outputs its input and Jk flipflop output E1(a11, a12), E2 (a21, a22), E3 and R13 (a11, a31, a32),
toggles its output when 1 is given to both J and K R2 (a11, a12),
inputs. But in table (a11, a31, a32) there may be transitive
Q = Dprev (Qprev) + (Dprev) (Qprev). dependency between a 11 and a 32 so we should
55. (c) int fun1(int n){ decompose this table into 2 more tables.
int i, j, k, p, q = 0;
for (i = 1;i < n; ++ p) ® n times 1
0.99 å = _____________ .
99
{ 58. X =1
x ( x + 1)
p=0
For( j = n; j > 1; j = j/ 2) 99
1 1 1 1 1
++p; å x ( x + 1) = 1( 2 ) + 2 ( 3) + 3 ( 4 ) + ... + 99 (100 )
log (log n) times X =1
CPIold 1 99
= = 1- = = 0.99
CFold 100 100
=
CPI new
59. (a)
CFnew
60. 5
(where CF is clock frequency and CPI is cycles per 61. (b)
intruction. So, CPI/CF gives time per instruction)
40
4
= 2.5 = 3.2
1
2 30 20
40
E1 R12 E1
m n
30 20
R13
n
10 16 17
15
E3
8 4 35
a31 a32
2015 -14 SOLVED PAPER - 2015
Heapification 62. 10
63. 0.4404
P = P(S1) P(~S2) P (~S3) P(~S4) +
40
P(~S1) P(S2) P(~S3) P(~S4) +
P(~S1) P(~S2) P(S3) P(~S4) +
P(~S1) P(~S2) P (~S3) P(S4)
30 20
= 0.1 × 0.8× 0.7 × 0.6
+ 0.9 × 0.2 × 0.7 × 0.6
+ 0.9 × 0.8 × 0.3 × 0.6
+ 0.9 × 0.8 × 0.7 × 0.4
16 17
10 15 = 0.4404.
64. (a) If we use unsorted array
(logN) 1/2 find operations will take log N 1/2 .
8 4 35 q(N(log N)1/2) time
N insertions will take N×q(1) = q(N) time
(logN)1/2 delete operations will take (log N) 1/2 ×θ (1)=
q(log N)1/2 time as pointer to the record which should
be deleted is provided
(logN)1/2 decrease key operations will take q(logN)1/2
40 time
\ On the whole, time complete to perform all these
operations is q( N(log N) 1 /2 )
If we use sorted array insertions will take more time
30 20
[O(NlogN) as it should be sorted after insertions]. If
we use min heap, again insertions will take more time
[O(NlogN) as it should be heapifie d].
10 35
16 17 65. (c)
8 4 15
40
35 20
10 16 17
30
8 4 15
SOLVED PAPER - 2015 2015-15
2015
SET - 2
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question numbers
11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-marks each.
4. Questions are of Multiple Choice Question (MCQ) or Numerical Answer type. A multiple choice question will have
four choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
GENERAL APTITUDE 4. A generic term that includes various items of clothing such
as a skirt, a pair of trousers and a shirt is
QUESTION 1 TO 5 CARRY ONE MARK EACH
(a) fabric (b) textile
1. Choose the statement where underlined word is used correctly.
(c) fibre (d) apparel
(a) The industrialist had a personnel jet.
5. Based on the given statements, select the most appropriate
(b) I write my experience in my personnel diary.
option to solve the given question.
(c) All personnel are being given the day off.
What will be the total weight of 10 poles each of same
(d) Being religious is a personnel aspect.
weight?
2. Consider a function f(x) = 1–|x| on –1 £ x £ 1. The value of
Statements:
x at which the function attains a maximum, and the maximum
value of the function are: (I) One fourth of the weight of a pole is 5 Kg.
(a) 0, –1 (b) –1, 0 (II) The total weight of these poles is 160 kg more than the
(c) 0, 1 (d) – 1, 2 total weight of two poles.
3. We ________ our friend's birthday and we ________ how to (a) Statement I alone is not sufficient.
make it up to him. (b) Statement II alone is not sufficient.
(a) completely forget, don't just know (c) Either I or II is sufficient.
(b) forgot completely, don't just know (d) Both statements I and II together are not sufficient.
(c) completely forget, just don't know
(d) forgot completely, just don't know
2015 -16 SOLVED PAPER - 2015
QUESTION 6 TO 10 CARRY TWO MARKS EACH TECHNICAL SECTION
6. If the list of letters, P, R, S, T, U is an arithmetic sequence,
which of the following are also in arithmetic sequence? QUESTION 11 TO 35 CARRY ONE MARK EACH
I. 2P, 2R, 2S, 2T, 2U 11. The number of divisors of 2100 is _____.
II. P–3, R–3, S–3, T–3, U–3 12. Consider the following C function.
III. P2, R2, S2, T2, U2 int fun(int n)
(a) I only (b) I and II {
(c) II and III (d) I and III int x = 1, k;
7. In a triangle PQR, PS is the angle bisector of ÐQPR and if (n = = 1) return x;
ÐQPS = 60°. What is the length of PS? for (k =1; k<n; ++k)
x = x + fun(k) * fun(n–k);
P return x;
}
r q The return value of fun(5) is _____.
13. An unordered list contains n distinct elements. The number
of comparisons to find an element in this list that is neither
Q R maximum nor minimum is
P (a) O(n log n) (b) O(n)
(c) O(log n) (d) O(1)
14. The cardinality of the power set of {0, 1, 2,…, 10}
(q + r) qr
(a) (b) is _______.
qr (q + r) 15. Consider two decision problems Q1, Q2 such that Q1 reduces
in polynomial time to 3–SAT and 3–SAT reduces in
(q + r)2 polynomial time to Q2. Then which one of the following is
(c) (q 2 + r 2 ) (d)
qr consistent with the above statement?
8. Out of the following four sentences, select the most suitable (a) Q1 is in NP, Q2 is NP hard.
sentence with respect to grammar and usage: (b) Q2 is in NP, Q1 is NP hard.
(a) Since the report lacked needed information, it was of (c) Both Q1 and Q2 in NP.
(d) Both Q1 and Q2 are NP hard.
no use to them.
16. With reference to the B+ tree index of order 1 shown below,
(b) The report was useless to them because there were no
the minimum number of nodes (including the Root node) that
needed information in it.
must be fetched in order to satisfy the following query: "Get
(c) Since the report did not contain the needed
all records a search key greater than or equal to 7 and less
information, it was not real useful to them.
than 15" is ____.
(d) Since the report lacked needed information, it would
not had been useful to them.
9
9. If p, q, r, s are distinct integers such that:
f(p, q, r, s) = max(p, q, r, s)
g(p, q, r, s) = min(p, q, r, s) 5 13 17
h(p, q, r, s) = remainder of (p×q)/(r×s) if
(p × q)> (r × s) or remainder of (r×s)/(p×q) if (r×s) > (p×q) 1 3 5 7 9 11 13 15 17
Also a function fgh(p, q, r, s) = f(p, q, r, s) × g(p, q, r, s) × h(p,
q, r, s) 17. Consider a complete binary tree where the left and the right
Also the same operations are valid with two variable subtrees of the root are max-heaps. The lower bound for the
functions of the form f(p, q). number operations to convert the tree to a heap is
What is the value of fg(h(2,5,7,3), 4,6,8)?
10. Four branches of company are located at M, N, O, and P. M (a) W(log n) (b) W(n)
(c) W(n log n) (d) W(n2)
is north of N at a distance of 4 km; P is south of O at a distance
18. Assume that for a certain processor, a read request takes 50
of 2 km; N is southeast of O by 1 km. What is the distance
nanoseconds on a cache miss and 5 nanoseconds on a cache
between M and P in km?
hit. Suppose while running a program, it was observed that
(a) 5.34 (b) 6.74
80% of the processor's read requests result in a cache hit. The
(c) 28.5 (d) 45.49
average read access time in nanoseconds is ______.
SOLVED PAPER - 2015 2015-17
19. A link has a transmission speed of 106 bits/sec. It uses data 25. Identify the correct order in which a server process must
packets of size 1000 bytes each. Assume that the invoke the function calls accept, bind, listen, and recv
acknowledgement has negligible transmission delay, and that according to UNIX socket APL.
its propagation delay is the same as the data propagation (a) listen, accept, bind, recv
delay. Also assume that the processing delays at nodes are (b) bind, listen, accept, recv
negligible. The efficiency of the stop-and-wait protocol in (c) bind, accept, listen, recv
this setup is exactly 25%. The value of the one-way (d) accept, listen, bind, recv
propagation delay(in milliseconds) is _______. 26. In the context of Abstract-Systax-Tree (AST) and Control-
20. Consider the following transaction involving two bank Flow-Graph (CFG), which one of the following is TRUE?
accounts x and y. (a) In both AST and CFG, let node N2 be the successor of
read(x); x: = x–50; write(x); read (y); y = y + 50; write(y) node N1. In the input program, the code corresponding
The constraint that the sum of the accounts x and y should to N2 is present after the code corresponding to N1
remain constant is that of (b) For any input program, neither AST nor CFG will
(a) Atomicity (b) Consistency contain a cycle
(c) Isolation (d) Durability (c) The maximum number of successors of a node in an
21. A Software Requirements Specification (SRS) document AST and a CFG depends on the input program
should avoid discussing which one of the following? (d) Each node in AST and CFG corresponds to at most one
(a) User interface issues statement in the input program.
(b) Non-functional requirements 27. A binary tree T has 20 leaves. The number of nodes in T
(c) Design specification having two children is _____.
(d) Interfaces with third party software 28. A computer system implements a 40-bit virtual address, page
22. Consider the following function written in the C size of 8 kilobytes, and a 128-entry Translation Look-aside
programming languages. Buffer (TLB) organized into 32 sets each having four ways.
void foo(char *a) Assume that the TLB tag does not store any process id. The
{ minimum length of the TLB tag in bits is _______.
if(*a && *a != ‘ ’) 29. Match the following:
{ List – I List – II
foo(a+1); P. Lexical analysis 1. Graph coloring
putchar(*a); Q. Parsing 2. DFA minimization
} R. Register allocation 3. Post-order traversal
} S. Expression evaluation 4. Production tree
The output of the above function on input "ABCD EFGH" (a) P-2, Q-3, R-1, S-4 (b) P-2, Q-1, R-4, S-3
is (c) P-2, Q-4, R-1, S-3 (d) P-2, Q-3, R-4, S-1
(a) ABCD EFGH (b) ABCD 30. Which one of the following statements is NOT correct about
(c) HGFE DCBA (d) DCBA HTTP cookies?
23. A system has 6 identical resources and N processes (a) A cookie is a piece of code that has the potential to
competing for them. Each process can request atmost 2 compromise the security of an Internet user
resources. Which one of the following values of N could lead (b) A cookie gains entry to the user's work area through an
to a deadlock? HTTP header
(a) 1 (b) 2 (c) A cookie has an expiry date and time
(c) 3 (d) 4 (d) Cookies can be used to track the browsing pattern of a
24. Consider the basic COCOMO model where E is the effort user at a particular site
applied in person-months, D is the development time in
é 4 5ù
chronological months, KLOC is the estimated number of 31. The larger of the two eigenvalues of the matrix ê 2 1ú is
delivered lines of code(in thousands) and ab, bb, cb, db have ë û
their usual meanings. The basic COCOMO equations are of _____.
the form 32. Consider the following two statements.
(a) E = ab(KLOC) exp(bb), D = cb (E) exp(db) S1: If a candidate is known to be corrupt, then he will not be
(b) D = ab(KLOC) exp(bb), E = cb(D) exp(db) elected
(c) E = ab exp(bb), D = cb(KLOC) exp(db) S2: If a candidate is kind, he will be elected.
(d) E = ab exp(db), D = cb(KLOC) exp(bb) Which one of the following statements follows from S1 and
S2 as per sound inference rules of logic?
2015 -18 SOLVED PAPER - 2015
(a) If a person is known to be corrupt, he is kind 37. Consider the following routing table at an IP router.
(b) If a person is not known to be corrupt, he is not kind
(c) If a person is kind, he is not known to be corrupt
(d) If a person is not kind, he is not known to be corrupt Newtork No. Net Mask Next Hop
33. Let R be the relation on the set of positive integers such that 128.96.170.0 255.255.254.0 Interface 0
aRb if and only if a and b distinct and have a common divisor
128.96.168.0 255.255.254.0 Interface 1
other than 1. Which one of the following statements about
128.96.166.0 255.255.254.0 R2
R is true?
(a) R is symmetric and reflexive but not transitive 128.96.164.0 255.255.252.0 R3
(b) R is reflexive but not symmetric and not transitive 0.0.0.0 Default R4
(c) R is transitive but not reflexive and not symmetric
(d) R is symmetric but not reflexive and not transitive For each IP address in Group I identify the correct choice of
34. Consider the following statements. the next hop form Group II using the entries from the routing
I. The complement of every Turing decidable language
table above.
is Turing decidable
Group I Group II
II. There exists some language which is in NP but is not
(i) 128.96.171.92 (A) Interface 0
Turing decidable
III. If L is a language in NP, L is Turing decidable (ii) 128.96.167.151 (B) Interface 1
Which of the above statements is/are true? (iii) 128.96.163.151 (C) R2
(a) Only II (b) Only III (iv) 128.96.165.121 (D) R3
(c) Only I and II (d) Only I and III (E) R4
35. The minimum number of JK flip-flops required to construct (a) i-A, ii-C, iii-E, iv-D (b) i-A, ii-D, iii-B, iv-E
a synchronous counter with the count sequence (0, 0, 1, 1, 2, (c) i-B, ii-C, iii-D, iv-E (d) i-B, ii-C, iii-E, iv-D
2, 3, 3, 0, 0,.........) is _______. 38. Consider two relations R1(A,B) with the tuples(1, 5), (3, 7)
QUESTION 36 TO 65 CARRY TWO MARKS EACH and R2(A, C) = (1, 7), (4, 9). Assume that R(A,B,C) is the full
natural outer join of R1 and R2. Consider the following tuples
36. The secant method is used to find the root of an equation f(x)
of the form (A, B, C): a = (1, 5, null), b = (1, null, 7), c = (3,
= 0. It is started from two distinct estimates xa and xb for the
root. It is an iterative procedure involving linear interpolation null, 9), d = (4, 7, null), e = (1, 5, 7), f = (3, 7, null), g = (4,
to a root. The iteration stops if f(xb) is very small and then xb null, 9). Which one of the following statements is correct?
is the solution. The procedure is given below. Observe that (a) R contains a, b, e, f, g but not c, d.
there is an expression which is missing and is marked by? (b) R contains all of a, b, c, d, e, f, g.
Which is the suitable expression that is to be put in place of? (c) R contains e, f, g but not a, b.
So that it follows all steps of the secant method? (d) R contains e but not f, g.
Secant 39. The number of states in the minimal deterministic finite
Initialize: xa, xb, e, N automaton corresponding to the regular expression (0 + 1) *
// e = convergence indicator (10) is _______.
// N = maximum number of iterations 40. Which one of the following well formed formulae is a
fb =f(xb) tautology?
i=0 (a) " x$ y R (x, y) « " x R (x, y)
while (i < N and |fb| > e) do (b) "x [$ y R(x, y) ® S(x, y)]) ® " x $yS (x, y)
i = i + 1 // update counter
(c) ["x$xy (P(x, y) ® R(x,y)] « ["x$y
xt = ? // missing expression for
(ØP (x, y) Ú R(x, y)]
xa = x b
xb = xt // intermediate value (d) "x"y P(x, y) ® " x " y P(y, x)
fb = f(xb) // function value at new xb 41. Consider the C program below.
end while #include <stdio.h>
if |fb| > e then // loop is terminated with i=N int *A, stkTop;
write "Non-convergence" int stkFunc(int opcode, int val)
else {
write "return xb" static int size = 0, stkTop = 0;
end if switch (opcode)
(a) xb – (fb – f(xa)) fb/ (xb – xa) {
(b) xa – (fa – f(xa)) fa/ xb – xa) case –1: size = val; break;
(c) xb – (xb – xa)fb/ (fb – f(xa)) case 0: if(stkTop < size) A[stkTop++]=
(d) xa – (xb – xa) fa/ (fb – f(xa)) val; break;
SOLVED PAPER - 2015 2015-19
default: if (stkTop) return A[– –stkTop]; 46. Which one of the following assertions concerning code
} inspection and code walkthrough is true?
return – 1; (a) Code inspection is carried out once the code has been
} unit tested
int main( ) (b) Code inspection and code walkthrough are synonyms
{ (c) Adherence to coding standards is checked during code
int B[20]; A = B; stkTop = –1; inspection
stkFunc(–1, 10); (d) Code walk through is usually carried out by an
stkFunc(0, 5); independent test team
stkFunc(0, 10); 47. The number of onto functions (surjective functions) from set
printf("%d\n", stkFunc(1,0)+stkFun(1,0); X = {1, 2, 3, 4,} to set Y = {a, b, c} is _______.
} 48. A graph is self-complementary if it is isomorphic to its
The value printed by the above program is ______. complement. For all self-complementary graphs on n
42. Which one of the following hash functions on integers will vertices, n is
(a) A multiple of 4
distribute keys most uniformly over 10 buckets numbered 0
(b) Even
to 9 for i ranging from 0 to 2020?
(c) Odd
(a) h(i) = i2 mod 10 (b) h(i) = i3 mod 10
2 (d) Congruent to 0 mod 4, 1 mod 4
(c) h(i) = (11 * i ) mod 10 (d) h(i) = (12 * i) mod 10
49. Perform the following operations on the maxtrix
43. Consider the alphabet S = {0, 1}, the null/empty string l and
the sets of strings X 0 , X 1 , and X 2 generated by the é 3 4 45ù
corresponding non-terminals of a regular grammar X0, X1, ê 7 9 105ú
and X2 are related as follows. ê ú
ëê13 2 195úû
X0 = 1 X1
X1 = 0 X1 + 1 X2 (i) Add the third row to the second row
X2 = 0 X1 + {l} (ii) Subtract the third column from the first column.
Which one of the following choices precisely represents the The determinant of the resultant matrix is _______.
strings in X0? 50. Assume that the bandwidth for a TCP connection is 1048560
(a) 10(0*+(10)*)1 bits/sec. Let a be the value of RIT in milliseconds (rounded off
(b) 10(0*+(10*)*1 to the nearest integer) after which the TCP window scale option
(c) 1(0+10)*1 is needed. Let b be the maximum possible window size with
(d) 10(0+10)*1+110(0+10)*1 window scale option. Then the values of a and b are
44. The number of min-term after minimizing the following (a) 63 milliseconds, 65535 × 214
Boolean expression is _____. (b) 63 milliseconds, 65535 × 216
[D'+ AB' + A'C + AC'D + A'C'D]' (c) 500 milliseconds, 65535 × 214
(d) 500 milliseconds, 65535 × 216
45. Consider the intermediate code given below.
51. Let f(x) = x–(1/3) and A denote the area of the region bounded
(1) i = 1
by f(x) and the X–axis, when x varies from –1 to 1. Which of
(2) j = 1
the following statements is/are TRUE?
(3) t1 = 5 * i
I. f is continuous in [–1, 1]
(4) t2 = t1+ j
II. f is not bounded in [–1, 1]
(5) t3 = 4 * t2 III. A is nonzero and finite
(6) t4 = t3 (a) II only (b) III only
(7) a[t4] = – 1 (c) II and III only (d) I, II and III
(8) j = j + 1 52. Consider the sequence of machine instructions given
(9) if j < = 5 goto (3) below.
(10) i = i + 1 MUL R5, R0, R1
(11) if i < 5 goto (2) DIV R6, R2, R3
The number of nodes and edges in the control-flow-graph ADD R7, R5, R6
constructed for the above code, respectively, are SUB R8, R7, R4
(a) 5 and 7 (b) 6 and 7 In the above sequence, R0 to R8 are general purpose
(c) 5 and 5 (d) 7 and 8 registers. In the instruction shown, the first register stores the
2015 -20 SOLVED PAPER - 2015
result of the operation performed on the second and the third 59. Consider a processor with byte-addressable memory.
registers. This sequence of instructions is to be executed in Assume that all registers, including Program Counter (PC)
a pipelined instruction processor with the following 4 stages: and Program Status Word (PSW), are of size 2 bytes. A stack
(1) Instruction Fetch and Decode (IF), (2) Operand Fetch in the main memory is implemented from memory location
(OF), (3) Perform Operation (PO) and (4) Write Back the (0100)16 and it grows upward. The stack pointer (SP) points
result (WB). The IF, OF and WB stages take 1 clock cycle to the top element of the stack. The current value of SP is
each for any instruction and 5 clock cycles for DIV (016E)16. The CALL instruction is of two words, the first is
instruction. The pipelined processor uses operand the op-code and the second word is the starting address of the
forwarding from the PO stage to the OF stage. The number subroutine (one word = 2 bytes). The CALL instruction is
of clock cycles taken for the execution of the above sequence implemented as follows.
of instructions is _________. • Store the current value of PC in the stack
53. Which of the following languages is/are regular? • Store the value of PSW register in the stack
L1: {wxwR|w, x Î {a, b}* and |w|, |x| > 0}, • Load the starting address of the subroutine in PC
wR is the reverse of string w The content of PC just before the fetch of CALL instruction
L2: {anbm | m ¹ n and m, n ³ 0} is (5FA0)16 . After execution of the CALL instruction, the
L3: {apbqcr | p, q, r ³ 0} value of the stack pointer is
(a) L1 and L3 only (b) L2 only (a) (016A)16 (b) (016C)16
(c) L2 and L3 only (d) L3 only (c) (0170)16 (d) (0172)16
54. Consider a typical disk that rotates at 150000 Rotations Per 60. Suppose you are provided with the following function
Minute (RPM) and has a transfer rate of 50 × 106 bytes/sec. declaration in the C programming language.
If the average seek time of the disk is twice the average int partition(int a[ ], int n);
rotation delay and the controller's transfer time is 10 times the The function treats the first element of a[ ] as s pivot, and
disk transfer time, the average time (in milliseconds) to read rearranges the array so that all elements less than or equal to
or write a 512-byte sector of the disk is _____. the pivot is in the left part of the array, and all elements
55. A computer system implements 8 kilobyte pages and a 32-bit greater than the pivot is in the right part. In addition, it moves
physical address space. Each page table entry contains a valid the pivot so that the pivot is the last element of the left part.
bit, a dirty bit, three permission bits, and the translation. If the The return value is the number of elements in the left part.
maximum size of the page table of a process is 24 megabytes, The following partially given function in the C programming
the length of the virtual address supported by the system is language is used to find the kth smallest element in an array
_______ bits. a[ ] of size n using the partition function. We assume k £ n.
56. Consider six memory partitions of sizes 200 KB, 400KB, int kth_smallest(int a[ ], int n, int k)
600 KB, 500 KB, 300 KB and 250 KB, where KB refers to {
kilobyte. These partitions need to be allotted to four int left_end = partition(a, n);
processes of sizes 357 KB, 210 KB, 468 KB and 491 KB in if (left_end+1 = =k)
that order. If the best fit algorithm is used, which partitions {
are NOT allotted to any process? Return a[left_end];
(a) 200 KB and 300 KB }
(b) 200 KB and 250 KB if(left_end+1) > k)
(c) 250 KB and 300 KB {
(d) 300 KB and 400 KB return kth_smallest(________);
57. Let X and Y denote the sets containing 2 and 20 distinct }
objects respectively and F denote the set of all possible else
functions defined from X to Y. Let f be randomly chosen from {
F. The probability of f being one-to-one is ________. return kth_smallest(________);
58. Host A sends a UDP datagram containing 8880 bytes of user }
data to host B over an Ethernet LAN. Ethernet frames may }
carry data up to 1500 bytes (i.e. MTU = 1500 bytes).Size of The missing argument lists are respectively
UDP header is 8 bytes and size of IP header is 20 bytes. There (a) (a, left_end, k) and (a+left_end+1, n–left_end–1,
is no option field in IP header. How many total number of IP k–left_end–1)
fragments will be transmitted and what will be the contents (b) (a, left_end, k) and (a, n–left_end–1, k–left_end–1)
of offset field in the last fragment? (c) (a+left_end+1,n–left_end–1, k–left_end–1) and (a,
(a) 6 and 925 (b) 6 and 7400 left_end, k)
(c) 7 and 1110 (d) 7 and 8880 (d) (a, n–left_end–1, k–left_end–1) and (a, left_end, k)
SOLVED PAPER - 2015 2015-21
61. Consider a simple checkpointing protocol and the following 64. Given below are some algorithms, and some lgorithm design
set of operations in the log. paradigms.
(start, T4); (write, T4, y, 2, 3); (start, T1); List – I
(commit, T4); (write, T1, z, 5, 7); 1. Dijkstra's Shortest Path
(checkpoint); 2. Floyd-Warshall algorithm to compute all paris shortest
(start, T2); (write, T2, x, 1, 9); path
(commit, T2); (start, T3), 3. Binary search on a sorted array
(write, T3, z, 7, 2); 4. Backtracking search on a graph
If a crash happens now the system tries to recover using both List–II
undo and redo operations, what are the contents of the undo (i) Divide and Conquer
list and the redo list? (ii) Dynamic Programming
(a) Undo: T3, T1; Redo: T2 (iii) Greedy design
(b) Undo: T3, T1; Redo: T2, T4 (iv) Depth-first search
(c) Undo: none; Redo; T2, T4, T3, T1 (v) Breadh-first search
(d) Undo: T3, T1, T4; Redo: T2 Match the above algorithms on the left to the corresponding
62. A half adder is implemented with XOR and AND gates. A full design paradigm they follow.
adder is implemented with two half adders and one OR gate. (a) 1-i, 2-iii, 3-i, 4-v (b) 1-iii, 2-ii, 3-i, 4-v
The propagation delay of an XOR gate is twice that of and (c) 1-iii, 2-ii, 3-i, 4-iv (d) 1-iii, 2-ii, 3-i, 4-v
AND/OR gate. The propagation delay of an AND/OR gate 65. A Young tableau is a 2D array of integers increasing from left
is 1.2 microseconds. A 4-bit ripple-carry binary adder is to right and from top to bottom. Any unfilled entries are
implemented by using four full adders. The total propagation marked with ¥, and hence there cannot be any entry to the
time of this 4- bit binary adder in microseconds is _____ right of, or below a ¥. The following Young tableau consists
63. In a connected graph, a bridge is an edge whose removal of unique entries.
disconnects a graph. Which one of the following statements
is true? 1 2 5 14
(a) A tree has no bridge 3 4 6 23
(b) A bridge cannot be part of a simple cycle 10 12 18 25
(c) Every edge of a clique with size ³ 3 is a bridge (A
31 ¥ ¥ ¥
clique is any complete subgraph of a graph
(d) A graph with bridge cannot have a cycle When an element is removed from a Young tableau, other
elements should be moved into its place so that the resulting
table is still a Young tableau (unfilled entries may be filled in
with a ¥). The minimum number of entries (other than 1) to
be shifted, to remove 1 from the given Young tableau
is ________.
2015 -22 SOLVED PAPER - 2015
GENERAL APTITUDE P 2 + R 2 + S2 + T 2 + U 2 S2
¹
5 5
1. (c) Personnel-people employed in an organization or
engaged in an organized undertaking such as military 7. (b)
service. 8. (a)
2. (c) f(x) = 1 – |x| on –1 £ x £ 1 (b) there was no needed information
(c) not really useful
ì1 - x, 0 £ x £ 1 (d) would not have been
1- | x | = í
î1 + x, -1 £ x £ 0
7´3
9. 8 h (2, 5, 7, 3) = Remainder of ®1
both functions gives maximum value at x = 0. 2´5
f (0) = 1
fg (h (2, 5, 7, 3), 4, 6, 8) = fg (1, 4, 6, 8)
3. (c)
= f (1, 4, 6, 8) × g (1, 4, 6, 8)
4. (d) apparel- clothing, especially outerwear; garments;
=8× 1=8
attire; raiment
5. (c) Let weight of each pole be x
10. (a) M
x
I. Given, = 15 kg
4
O 1km 4 km
Þ x = 60 kg
All poles are of same weight
\ Weight of 10 poles =10x = 10 × 60 = 600 kg 2 km N
II. Given, 10x = 2x + 160 P
Þ 8x = 160 kg Þ x = 20kg
\ Weight of 10 poles = 10x = 10 × 20 = 200 kg
TECHNICAL SECTION
6. (b) As P, R, S, T, U is an arithmetic sequence
15. (a) 3 – SAT Þ NPC problem requirements and may include a set of use cases that
Q1 £ p describe interactions the user will have with the
3 – SAT £ p software.
Q2 £ p £ p 22. (d)
Hence ® Q1 is in NP £ p
but Q2 is not given in NP f00(ABCDE)
Therefore, Q2 is in NP-Hard.
16. 6
f00(BCDEFGH) print(A)(4)
9
5 13 17 f00(CDEFGH) print(B)(3)
1 3 5 7 9 11 13 15 17
f00(DEFGH) print(C)(2)
17. (a)
18. 14 Average read access time = [(0.8) (5) + (0.2)(50)] ns.
= 4 + 10 = 14 ns
19. 12 Given, B = 106 bps f00((space)EFGH) print(D)(1)
L = 1000 bytes
if condition fails & returns controls
h = 25%
\ DCBA will be pointed
Tp = ?
23. (*) It might be "WRONG" question.
1 N = 2 Þ P1 P2 No. of resources = 6
In stop-and-wait, h =
1 + 2a 2 2
1 1
1 1
Þ = Þ 1 + 2a = 4 Each process can request atmost 2
4 1 + 2a
N = 3 Þ P1 P2 P3
3 2 2 2
2a = 3; a = N = 4 Þ P1 P2 P3 P4
2
1 1 1 1
3 1 1
L 8 ´ 10
Tx = = = 8ms Therefore, no option leads to dead lock.
B 106
24. (a) Basic COCOMO model takes the form
TP 3 Effort applied (E) = ab (kLoc) b b
=
TX 2 ; 2TP = 3T
Development time (D) = cb (E)db
2Tp = 24ms 25. (b) The correct order in which a server process must
Tp = 12ms invoke the function calls is bind, listen, accept and
20. (b) The consistency property ensures that the database recv. First three are used in connection establishment
remains in a consistent state before the (start of the phase and recv is used in data transfer phase.
transaction and after the transaction is over. Here sum 26. (c) Option (a) is false when CFG contains cycle
of the accounts x & y should remain same before & Option (b) is false as CFG can contain cycle
after execution of the given transactions which refers Option (d) is false as a single node can contain block
to the consistency of the sum. of statements.
21. (d) SRS is a description of a software system to be 27. 19 Let the number of vertices of a binary tree with ‘p’
developed, laying out functional & non-functional leaves be n then the tree has–
2015 -24 SOLVED PAPER - 2015
(i)
p vertices (i.e., leaves) of degree 1 then S1 = p ® ~q
(ii)
one vertex (i.e.., root of T) of degree 2 = q® ~ p (contrapositive rule)
(iii)
'n - p -1' (i.e., interval) vertices of degree 3 and s2 : r ® q
(iv)
n -1edges Þ r ® ~p (transitive rule)
\By Handshaking theorem, i.e., If a person is kind, he is not known to be corrupt
p × 1 + 1 × 2 + (n – p – 1) × 3 = 2 (n – 1) \ Option is (c).
Þ n = 2p – 1 33. (d) R is not reflexive as each element can’t be related to
= 39 as p = 20 itself.
2\ n – p =19 vertices have exactly two children R is symmetric
Let a = 3, b = 6 and c = 10 then 3 and 6 have a common
28. 22 22 5 13
division other than 1
TAG SET WORD 6 and 10 have a common division other than 1
OFFSET OFFSET
but 3 &10 have no common division other than 1
29. (c) Lexical Analyzer uses DFA to recognize the longest
3R6 and 6R10 but 3 R 10
possible input sequence that makes up a token. Parser
R is not transitive.
takes input in the form of tokens and usually builds a
data structure in the form of parse tree. Here parse tree 34. (d) Turing decidable Þ Recursive language
can be termed as a Production tree as parser uses Turing recognizable Þ Recursive enumerable
production of the grammar to check whether generated language
tokens form a meaningful compression. (I) Complement of turning decidable language is
Register allocation can be reduced to K-colouring decidable which is true.
problem where K is the number of registers available (III) True (Theorem)
on the target architecture. Which violates (II). Hence correct option is (d).
Post order traversal of expression tree gives postfix 35. 2 Here number of distinct states are 4. So, minimum
notation for a given expression & this post fix notation
number of flip-flop required is = 2.
can be evaluated using stack.
36. (d) It is secant method direct formula.
30. (b)
37. (a) Given,
1st IP : 128.96.171.92
Server Browser 1st MASK : 255.255.254.0
128.96.170.0
Acookiecanbestolen
Which is matching with first entry in n/w no. so the
Attacker corresponding next loop is interface 0.
So (i) ® (A)
(a) Option is correct. Given,
(b) Option is false. 2nd IP : 128.96.167.151
(c) Option is correct. 1st MASK : 255.255.254.0
(d) Option is correct. 128.96.166.0
Which is matching with 3 rd entry of the n/w no.
4-l 5
31. 6 Characteristic equation is column. So the corresponding next lap is R2.
2 1- l = 0
So (ii) ® (C)
Þ l2 – 5l – 6 = 0 Given,
Þ (l – 6) (l + 1) = 0 3rd IP : 128.96.163.151
Þ l = 6, – 1 1st MASK : 255.255.254.0
\ Larger eigen value is 6 128.96.162.0
32. (c) Let p: candidate known to be corrupt Which is not matching
q: candidate will be elected Given,
r: candidate is kind 3rd IP : 128.96.163.151
SOLVED PAPER - 2015 2015-25
1st MASK : 255.255.252.0 41. –2 StkFunc(1, 0) returns –1 both the times. So – 2 will be
128.96.170.0 printed
The corresponding 4th entry of n/w no. column is not 42. (b) If we take first 10 elements, number of collisions taken
matching. So it gives R4. by the hash function given by option (b) is less when
So (iii) ® (E) compared to others.
Given, 43. (c)
4th IP : 128.96.165.121 44. 1 Given function is F(A,B,C,D) [D ¢ + AB¢ + A¢ C + AC¢
Ist MASK : 255.255.254.0 D + A¢ C¢ D]¢
According to the function k-map is
128.96.164.0
It is not matching with the first 3 entries of n/w no
column. If we apply the 2nd mask then the result is CD
128.96.164.0. Since it is matching with 4th entry of n/w AB 00 01 11 10
no column,
00 0 0 0 0
Þ (iv) ® (D) .
So, overall (i) - (A), (ii) - (C),(iii) - (E), (iv) - (D). 01 0 0 0 0
38. (c) R1 A B R2 A C A B C 11 0 0 1 0
1 5 1 7 1 5 7
10 0 0 0 0
3 7 4 9 3 7 null
4 null 9
Number of min terms = 1.
R1-- | x |-- R2 45. (b) 46. (a)
47. 36 Number of onto function from set X to set Y with
39. 3 (0 +1)*10
|x| = m, |y| = n is
0,1
1 0 n -1
A B C å (-1)k .n ck .(n - k)m
k =0
c
Þ m = 4, n = 3 number of onto fns is
2
0 1 å (-1)k .3ck .(3 - k)4 = 34 – (3) (2)4 + (3)(1)4
k =0
A A AB 0 1
= 81 – 48 + 3 = 36
1
A 48. (d) An n vertex self complementary graph has exactly half
B C – A B
0
n(n - 1)
C – – number of edges of the complete graph i.e.,
0 4
1
AB AC AB AC edges. Since n (n –1) must be divisible by 4, n must be
0 congruent to 0 or 1 module 4.
AC A AB B C
é 3 4 45 ù
ê 7 9 105ú
49. 0 Let A = ê ú
êë13 2 195úû
K total minimum DFA states = 3
40. (c) Since P ® R = Ø PVR R2 ® R2 + R3
["x$y(p(x, y) ® R(x, y))] ® ["x$y( Øp(x, y) V
é 3 4 45 ù
VR (x, y))] is a tautology. : êê20 11 300úú
êë13 2 195úû
2015 -26 SOLVED PAPER - 2015
C1 ® C2 – C3 53. (a) L1 = {wxwR| w, x Î {a, b}* and |w|, |x| > 0}
wR is reverse of string w.
é -42 4 45 ù It is regular
~ ê -280 11 300ú = B (resultant matrix) Regular expression
ê ú
êë -182 2 195 úû a (a + b)* a + b (a + b)* b
L2 = {anbm| m ¹ n, m, n ³ 0}
Hence m ¹ n, that mean n is greater than m, or m is
-42 4 3
greater than n.
280 11 300
Now |B| = So we need memory, so we can’t draw DfA for it.
-182 2 195 L3 = {apbqcr|p, q, r ³ 0}
a, b, c
3 4 3
20 11 20
= (–14) (15)
13 2 13
=0
Method 2: Determinant is unaltered by the operations
(i) and (ii)
\ Determinant of the resultant matrix = Determinant of
the given matrix
PAS 232
1 2 3 4 5 6 7 8 9 10 11 12 13 \ No.of frames = = 13 = 219 frames.
P.S 2
I O P P P W
I O - - P P P P P W So, it is given that each page table entry contains a
I - - O - - - - P W valid bit, a dirty bit, 3 permission bits. Þ 5 bits are
I - - O - - - - P W reserved.
SOLVED PAPER - 2015 2015-27
24 ´ 220 ´ 8
Þn= = 223 pages
24
Carry = 2.4 m sec
Length of the virtual address = 23+13=36 bits
A G2 G2 Sum = 4.8 m sec
H.A1 H.A2
56. (a) B
380 c4 s3 c3 s2 c2 s1 c1 s0
\ Probability of a function f being one-one is
400
i.e., 0.95
Here sum and carry delay is same= 4.8 μ sec
So, Ttotal = (4 × 4.8) m sec
= 19.2 m sec
8880 Bytes MIU 63. (b) Since, every edge in a tree is bridge
58. (c)
1500B \ (a) is false
Since, every edge in a complete graph kn (n ³ 3) is not
a bridge Þ (c) is false
Let us consider the following graph G:
(1) (2) (3) (4) (5) (6) (7)
DL 0 - 1471 1472 - 2951 2952 - 4431 4432 - 5911 5912 - 7391 7392 - 8871 8872 - 8879
HL 28 20 20 20 20 20 20
8872
e
OFFSET = 1109
8
59. (d)
60. (a) This graph has a bridge i.e., edge ‘e’ and a cycle of
61. (a) As T1 & T3 are not yet committed they must be
length ‘3’
undone. The transactions which are after the latest
\ (d) is false
checkpoint must be redone. So T2 must be redone. No
Since, in a cycle every edge is not a bridge
need to redo the records which are before last
\ (b) is true
checkpoint, so T4 need not be redone.
62. 19.2 64. (c) Dijkstra shortest path algorithm find next node by
choosing minimum distance hence greedy approach.
2015 -28 SOLVED PAPER - 2015
Floyd warshall always apply dynamic programming, 65. 5 1 2 5 14 ¥ 2 5 14
once it saves a cost and in the next iteration it will 3 4 6 23 3 4 6 23
change if this is minimum hence dynamic. 10 12 18 25 10 12 18 25
Þ Binary search always divide on two parts. 31 ¥ ¥ ¥ 31 ¥ ¥ ¥
Hence divide and conquer.
Ü
2shift
Þ Backtracking uses by DFS, one it will reach to dead 2 4 5 14 2 4 5 14
end it will take back track. 3 618 23 3 ¥ 6 23
Ü
10 12 ¥ 25 10 12 18 25
31 ¥ ¥ ¥ 31 ¥ ¥ ¥
2 shift
Ü
2 4 5 14
3 4 18 23
10 12 25 ¥
31 ¥ ¥ ¥
SOLVED PAPER - 2015 2015-29
2015
SET - 3
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question numbers
11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-marks each.
4. Questions are of Multiple Choice Question (MCQ) or Numerical Answer type. A multiple choice question will have
four choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
120
110
100
90
80
70
60
50
40
30
20
10
0
2000 2001 2002 2003 2004 2005 2006 2007
Export Import
9. Most experts feel that in spite of possessing all the technical III. He failed to make many of his good starts count.
skills required to be a batsman of the highest order, he is IV. Improving his technical skills will guarantee success.
unlikely to be so due to lack of requisite temperament. He (a) (III) and (IV) (b) (II) and (III)
was guilty of throwing away his wicket several times after (c) (I), (II), and (III) (d) (II) only
working hard to lay a strong foundation. His critics pointed 10. The head of a newly formed government desires to appoint
out that until he addressed this problem, success at the highest five of the six selected members P, Q, R, S, T, and U to
level will continue to elude him. portfolios of Home, Power, Defense, Telecom, and Finance.
Which of the statement (s) below is/are logically valid and U does not want any portfolio if S gets one of the five. R
can be inferred from the above passage? wants either Home or Finance or no portfolio. Q says that if
I. He was already a successful batsman at the highest S gets either Power or Telecom, then she must get the other
level. one. T insists on a portfolio if P get one.
II. He has to improve his temperament in order to become Which is the valid distribution of portfolios?
a great batsman. (a) P – Home, Q – Power, R – Defense,
S – Telecom, T – Finance
SOLVED PAPER - 2015 2015-31
be the set of all elements in T which are not in R. Which one QUESTION 36 TO 65 CARRY TWO MARKS EACH
of the following is true? 36. Consider the following C program:
(a) " X Î U (|X| = |X'|) # include<stdio.h>
(b) $ X Î U $ Y Î U (|X| = 2, |Y| = 5 and X Ç Y = 0) int main ( )
(c) " X Î U " Y Î U (|X| = 2, |Y| = 3 and X / Y = 0) {
(d) " X Î U " Y Î U (X/Y = Y'/X') int i, j, k = 0;
33. In a room there are only two types of people, namely Type 1 j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
and Type 2. Type 1 people always tell the truth and Type 2 k –= – –j;
people always lie. You give a fair coin to a person in that for (i = 0; i < 5: i++)
room, without knowing which type he is from and tell him to {
switch (i + k)
toss it and hide the result from you till you ask for it. Upon
{
asking, the person replies the following
case 1:
“The result of the toss is head if and only if I am telling the truth.”
case 2: printf (“\ n%d”, i+k);
Which of the following options is correct?
case 3: printf (“\n%d”, i+k);
(a) The result is head
default: printf (“\n%d”, i+k);
(b) The result is tail
}
(c) If the person is of Type 2, then the result is tail
}
(d) If the person is of Type 1, then the result is tail
return 0;
34. Consider a software project with the following information
}
domain characteristics for calculation of function point metric.
The number of time printf statement is executed is ______.
Number of external inputs (I) = 30
37. Suppose Xi for i = 1, 2, 3 are independent and identically
Number of external output (O) = 60
distributed random variables whose probability mass
Number of external inquiries (E) = 23
functions are Pr[Xi = 0] = Pr[Xi = 1] 1/2 for i = 1, 2, 3.
Number of files (F) = 08
Define another random variable Y = X1 X2 Å X3, where Å
Number of external interfaces (N) = 02
denotes XOR. Then Pr[Y = 0|X3 = 0] = ______.
It is given that the complexity weighting factors for I, O, E,
38. If the following system has non – trivial solution
F and N are 4, 5, 4, 10 and 7, respectively. It is also given that,
px +qy + rz = 0
out of fourteen value adjustment factors that influence the
qx + ry + pz = 0
development effort, four factors are not applicable, each of
rx + py +qz = 0
the other four factors have value 3, and each of the remaining
then which one of the following options is TRUE?
factors have value 4. The computed value of function point
(a) p – q +r = 0 or p = q = – r
metric is _______.
(b) p + q – r = 0 or p = – q = r
35. In a web server, ten WebPages are stored with the URLs of
(c) p + q +r = 0 or p = q = r
the form http://www.yourname.com/var.html; where, var is
(d) p – q +r = 0 or p = – q = – r
a different number from 1 to 10 for each Webpage. Suppose,
39. Language L1 is polynomial time reducible to language L2.
the client stores the Webpage with var = 1 (say W1) in local
Language L3 is polynomial time reducible to L2, which in
machine, edits and then tests. Rest of the WebPages remains
turn is polynomial time reducible to language L4. Which of
on the web server. W1 contains several relative URLs of the
the following is/are true?
form “var.html” referring to the other WebPages.
I. if L4 Î P, then L2 Î P
Which one of the following statements needs to be added in
II. if L1 Î P or L3 Î P, then L2 Î P
W1, so that all the relative URLs in W1 refer to the
III. L1 Î P, if and only if L3 Î P
appropriate WebPages on the web server?
IV. if L4 Î P, then L1 Î P and L3 Î P
(a) <a href: “http://www.yourname.com/”,
(a) II only (b) III only
href: “…var.html”>
(c) I and IV only (d) I only
(b) <base href: “http://www.yourname.com/ ”> 40. Consider the following partial Schedule S involving two
(c) <a href: “http://www.yourname.com/”> transactions T1 and T2. Only the read and the write
(d) <base href: “http://www.yourname.com/”, range operations have been shown. The read operation on data item
“…var.html”>
2015 -34 SOLVED PAPER - 2015
P is denoted by read (P) and the write operation on data item Control Flow Diagram of Program – Y:
P is denoted by write (P).
Time Trans action -id
instance T1 T2
1 read(A)
2 write(A )
3 read(C)
4 write (C)
5 read(B)
6 write(B)
7 read(A )
8 commit
9 read(B)
Schedule S
Suppose that the transaction T1 fails immediately after time
instance 9. Which one of the following statements is correct?
(a) T2 must be aborted and then both T1 and T2 must be re Control Flow Diagram of Program – Z:
– started to ensure transaction atomicity
(b) Schedule S is non – recoverable and cannot ensure
transaction atomicity Control Flow Diagram of
(c) Only T2 must be aborted and then re – started to ensure Program - X
transaction atomicity
(d) Schedule S is recoverable and can ensure atomicity and
nothing else needs to be done
Control Flow Diagram of
41. Consider three software items: Program – X, Control Flow
Diagram of Program – Y and Control Flow Diagram of Program - Y
Program – Z as shown below
Program X:
The values of McCabe’s Cyclomatic complexity of
sumcal (int maxint, int value)
{ Program-X, Program-Y, and Program-Z respectively are
int result =0, i = 0; (a) 4, 4, 7 (b) 3, 4, 7
if (value < 0) (c) 4, 4, 8 (d) 4, 3, 8
{ 42. Two hosts are connected via a packet switch with 107 bits per
value = -value; second links. Each link has a propagation delay of 20
} microseconds. The switch begins forwarding a packet 35
while ((i<value) and (result < = maxint)) microseconds after it receives the same. If 10000 bits of data
} are to be transmitted between the two hosts using a packet
i = i +1; size of 5000 bits, the time elapsed between the transmission
result = result + 1; of the first bit of data and the reception of the last bit of the
} data in microseconds is __________.
if (result <= maxint)
43. Consider the following grammar G
{
S®F|H
printf(result);
F®p|c
}
else H®d|c
{ Where S, F, and H are non – terminal symbols, p, d, and c are
printf (“large”); terminal symbols. Which of the following statements (s) is/
} are correct?
printf(“end of program”); S1: LL(1) can parse all strings that are generated using
} grammar G
SOLVED PAPER - 2015 2015-35
S2: LR(1) can parse all strings that are generated using 48. Consider a B+ tree in which the search key is 12 bytes long,
grammar G block size is 1024 bytes, record pointer is 10 bytes long and
(a) Only S1 (b) Only S2 block pointer is 8 bytes long. The maximum number of keys
(c) Both S1 and S2 (d) Neither S1 nor S2 that can be accommodated in each non – leaf node of the tree
is ______.
44. Suppose C = c [ 0 ] ,...., c [ k - ] is an array of length k, where
49. Consider the following policies for preventing deadlock in a
all the entries are from the set {0, 1}. For any positive system with mutually exclusive resources.
integers a and n, consider the following pseudocode. i. Processes should acquire all their resources at the
DOSOMETHING (c, a, n) beginning of execution. If any resource is not available,
z¬1 all resources acquired so far are released.
for i ¬ 0 to k – 1 ii. The resources are numbered uniquely, and processes
do z ¬ z2 mod n are allowed to request for resources only in increasing
if c[i] = 1 resource numbers
then z ¬ (z × a) mod n iii. The resources are numbered uniquely, and processes
rutrun z are allowed to request for resources only in decreasing
If k = 4, c = 1, 0, 1, 1 , a = 2 and n = 8, then the output of resource numbers
iv. The resources are numbered uniquely. A process is
DOSOMETHING (c, a, n) is _________.
allowed to request only for a resource with resource
45. For the processes listed in the following table, which of the
number larger than its currently held resources
following scheduling schemes will give the lowest average
Which of the above policies can be used for preventing
turnaround time?
deadlock?
(a) Any one of i and iii but not ii or iv
Process Arrival Time Processing Time (b) Any one of i, iii, and iv but not ii
A 0 3 (c) Any one of ii, and iii but not i or iv
B 1 6 (d) Any one of i, ii, iii, and iv
C 4 4 50. Assume that a mergesort algorithm in the worst case takes 30
seconds for an input of size 64. Which of the following most
D 6 2
closely approximates the maximum input size of a problem
that can be solved in 6 minutes?
(a) First Come First Serve
(a) 256 (b) 512
(b) Non – preemptive Shortest Job First
(c) 1024 (d) 2048
(c) Shortest Remaining Time
51. Consider the following C program.
(d) Round Robin with Quantum value two
#include<stdio.h>
46. Consider a network connecting two systems located 8000
int main( )
kilometers apart. The bandwidth of the network is 500 × 106
{
bits per second. The propagation speed of the media is
static int a[ ] = {10, 20, 30, 40, 50};
4 × 106 meters per second. It is needed to design a Go Back
static int *p[ ] = {a, a+3, a+4, a+1, a+2};
– N sliding window protocol for this network. The average
int **ptr = p;
packet size is 107 bits. The network is to be used to its full
ptr++;
capacity. Assume that processing delays at nodes are
printf(“%d%d”, ptr-p, **ptr);
negligible. Then, the minimum size in bits of the sequence
}
number field has to be _________.
The output of the program is ______.
47. Which of the following languages are context-free?
52. In the network 200.10.11.144/27, the fourth octet (in
L1 = {ambnanbm |m, n ³ 1}
decimal) of the last IP address of the network which can be
L2 = {ambnambn|m, n ³ 1}
assigned to a host is ______.
L3 = {ambn|m = 2n+1}
53. Consider the following C program.
(a) L1 and L2 only (b) L1and L3 only
#include<stdio.h>
(c) L2 and L3 only (d) L3 only
int f1(void);
2015 -36 SOLVED PAPER - 2015
int f2(void);
æ1ö 1
int f3(void); 56. If for non-zero x, af ( x ) + bf ç ÷ = - 25 where a ¹ b then
èxø x
int x = 10;
int main ( ) 2
{ ò f ( x )dx is
1
int x = 1;
x + = f1 ( ) + f2 ( ) + f3( ) + f2( );
é 1 47b ù
pirntf (“%d”, x); (a) êa ( In2 - 25) + 2 ú
2 2
a -b ë û
retirm 0;
} é 1 47b ù
int f1 ( ) { int x = 25; x++; return x;}
(b) 2êa ( In2 - 25 ) - 2 ú
2
a -b ë û
int f2 ( ) { static int x = 50; x++; return x;}
é 1 47b ù
êa ( 2In2 - 25 ) + 2 ú
int f3 ( ) {x *= 10; return x}; (c) 2 2
The output of the program is ______. a -b ë û
54. The total number of prime implicants of the function f(w, x,
é 1 47b ù
y, z) = å ( 0, 2, 4, 5, 6,10) is ______. (d) 2êa ( In2 - 25 ) - 2 ú
2
a -b ë û
55. Consider the following two C code segments. Y and X are 57. Let G be a connected undirected graph of 100 vertices and
one and two dimensional arr ays of size n and n × n 300 edges. The weight of a minimum spanning tree of G is
respectively, where 2 £ n £ 10. Assume that in both code 500. When the weight of each edge of G is increased by five,
segments, elements of Y are initialized to 0 and each element the weight of a minimum spanning tree becomes______.
X[i] [j] of array X is initialized to i+j. Further assume that 58. Consider the following recursive C function.
when stored in main memory all elements of X are in same void get (int n)
main memory page frame. {
Code segment 1: if (n<1) return;
//initialize elements of Y to 0 get (n–1);
//initialize elements X[i] [j] of X to i+j get (n–3);
printf(“%d”, n);
for (i = 0; i < n; i++)
}
Y[i] += X[0] [i];
If get (6) function is being called in main ( ) then how many
Code segment 2:
times will the get () function be invoked before returning to
//initialize elements of Y to 0 the main ( )?
//initialize elements X[i] [j] of X to i+j (a) 15 (b) 25
for (i = 0; i < n; i++) (c) 35 (d) 45
Y[i] += X[i] [0]; 59. Consider the following reservation table for a pipeline having
Which of the following statements is/are correct? three stages S1, S2, and S3.
S1: Final contents of array Y will be same in both code Time ®
segments 1 2 3 4 5
S2: Elements of array X accessed inside the for loop shown S1 X X
in code segment 1 are contiguous in main memory
S2 X X
S3: Elements of array X accessed inside the for loop shown
S3 X
in code segment 2 are contiguous in main memory
(a) Only S2 is correct The Minimum Average Latency (MAL) is _____.
(b) Only S3 is correct 60. Let R be a relation on the set of ordered pairs of positive
integers such that ((p,q), (r,s)) Î R if and only if p – s = q –
(c) Only S1 and S2 are correct
r. Which one of the following is true about R?
(d) Only S1 and S3 are correct
SOLVED PAPER - 2015 2015-37
(a) Both reflexive and symmetric Where operation Op is performed on contents of registers Rj
(b) Reflexive but not symmetric and Rk and the result is stored in register Ri.
(c) Not reflexive but symmetric I1: ADD R1, R2, R3
(d) Neither reflexive nor symmetric I2: MUL R7, R1, R3
61. Given the function F = P' + QR, where F is a function in three I3: SUB R4, R1, R5
Boolean variables P, Q and R and P' = !P, consider the I4: ADD R3, R2, R4
following statements. I5: MUL R7, R8, R9
Consider the following three statements.
(S1) F = å ( 4, 5, 6) S1: There is an anti-dependence between instruction I2
(S2) F = å ( 0,1, 2,3, 7 ) and I5
S2: There is an anti-dependence between instructions I2
(S3) F = Õ ( 4,5,6 ) and I4
S3: Within an instruction pipeline an anti-dependence
(S4) F = Õ ( 0,1, 2, 3, 7 )
always creates one or more stalls
Which of the following is true? Which one of above statements is/are correct?
(a) (S1) – False, (S2) – True, (S3) – True, (S4) – False (a) only S1 is true (b) only S2 is true
(b) (S1) – True, (S2) – False, (S3) – False, (S4) – True (c) Only S1 and S3 are true (d) Only S2 and S3 are true
(c) (S1) – False, (S2) – False (S3) – True, (S4) – True 64. Consider the equation (43)x = (y3)8 where x and y are
(d) (S1) – True, (S2) – True, (S3) – False, (S4) – False unknown. The number of possible solutions is ______.
62. Let f(n) = n and g(n) = n(1+sin n), where n is a positive integer. 65. The velocity v (in kilometer/minute) of a motorbike which
Which of the following statements is/are correct? starts from rest, is given at fixed intervals of time t(in
i. f(n) = O(g(n)) minutes) as follows:
ii. f(n) = W(g(n))
t 2 4 6 8 10 12 14 16 18 20
(a) Only i (b) Only ii v 10 18 25 29 32 20 11 5 2 0
(c) Both i and ii (d) Neither i nor ii
63. Consider the following code sequen ce having five The approximate distance (in kilometers) rounded to two
instructions I1 to I5 . Each of these instructions has the places of decimals covered in 20 minutes using Simpson’s
following format. 1/3rd rule is _______.
OP Ri, Rj, Rk
2015 -38 SOLVED PAPER - 2015
(SACK) mechanism, combined with a selective repeat 23. (b) X be an eigen vector corresponding to eigen value l =1,
retransmission policy, can help to overcome these then
limitations. The receiving TCP sends back SACK AX = lX Þ (A - I) X = 0
packets to the sender informing the sender of data that
has been received. The sender can then retransmit é0 -1 2 ù é x ù
ê0 0 0 ú ê y ú
only the missing data segments. ê úê ú =0
III: TCP work as a message stream. This is FALSE êë1 2 0 úû êë z úû
statement.
In TCP, Data is read as a byte stream, no distinguishing Þ – y + 2z = 0 and x + 2y = 0
indications are transmitted to signal message (segment) x
boundaries. Þ y = 2z and =y
-2
x x y z
\ = y = 2z Þ = = a(say)
-2 -4 2 1
18. (b) 71
æ -4ö
ç 2÷
84 Þ X = ç ÷ a; a ¹ 0
65 è 1ø
\ Eigen vector are {a (– 4, 2, 1) |a ¹ 0, a Î R|}
24. (c)
69 83
1 2 3 4 10
67
19. (b) X # Y = X¢ + Y¢ S
S1. L.H.S. R.H.S.
= (P # Q) # R P # (Q # R)
(P # Q)¢ + R¢ P¢ + (Q # R)¢ P
= (P¢ + Q¢)¢ + R¢ P¢ + (Q¢ + R¢)¢
= PQ + R¢ P¢ + QR After *P = '0', array will become
PQ + R¢ ¹ P¢ + QR
Hence S1 is false
S2. Q # R = Q¢ + R¢ ...(I) 1 2 0 4
R # Q¢ = R¢ + Q¢ = Q¢ + R¢ ...(II)
I and II both are equal. Therefore, S2 is true
20. (c) X = sum of the cubes of first n natural numbers
n 2 (n + 1)2 S
= which is q(n4), O (n5) & W (n3).
4
21. (d) Number of processes which are in running processes and we are pointing string S which is 1204.
will be atmost n as there are n processors. Maximum
number of processes that will be in ready state is 6
independent of number of processors. 5 60 60 10
25. (c) 10 10 15 15 15 15
22. (a) 4 12 4 Þ E 201 F
10 5 + 60 6
cache cache
word word
TAG block TAG block
offset offset 8
offset offset
150 150 142
* 8 –
2015 -40 SOLVED PAPER - 2015
26. (a) Inner query collects capacities of all the theatres and in (c) Counter example : Let X = {1, 2} and Y = {2, 3, 4}
outer query we are filtering the tuples with the condition then X/Y = {1} ¹ f
“capacity>=All”. So the theatres which are having Y¢
(d) X/ Y = X – Y= X Ç Y¢ and = Y¢ - X¢ = Y¢ Ç (X¢)
maximum capacity will be satisfy the conductivity and X¢
they will. = Y¢ Ç X = X Ç Y¢
27. 80 X Y¢
\ = , V X, Y Î U
no. of elements 2000 Y X¢
Load factor (a) = = = 80
no. of slots 25 33. (c)
28. (c) X ® Y is trivial if Y Í X 34. 612.06
29. 199 35. (d)
Let the number of leaf nodes of a binary tree with ‘n’ 36. 10 j and k will be evaluated to 2 and – 1 respectively.
vertices be ‘p’ then the tree has In for loop:
When i = 0; 1 time printed (– 1)
(i) ‘p’ vertices of degree ‘1’
When i = 1; 1 time printed (0)
(ii) one vertex (i.e. root of T) of degree ‘2’.
When i = 2; 3 times printed (1, 1, 1)
(iii) 'n – p – 1' vertices of degree ‘3’
When i = 3; 3 times printed (2, 2, 2)
(iv) 'n –1' edges
When i = 4; 2 times printed (3, 3)
\ By Handshaking theorem,
\ on the whole printf is executed 10 times
p × 1 + 1 × 2 + (n – p –1)×3 = 2(n –1) 37. 0.75
Þn=2p–1 Given X3 = 0
= 399 as p = 200 \ Y = X1X2 Å X3 = 0 gives X1X2 = 0
\ Number of nodes having exactly two children are Þ X1 = 1, X2 = 0 or X1 = 0, X2 = 1 or X1 = 0, X2 = 0
n – p i.e., 199
Pr[Y = 0] Ç (x 3 = 0)]
30. (a) varP = varQ = FALSE Initially. \ Pr [Y = 0|X3 = 0] =
Assume that, process X is willing to enter into critical Pr(X3 = 0)
section. So it makes varP = True, then if processor
Pr[X1 = 1, X 2 = 0, X 3 = 0] + Pr[X1 = 0, X 2 = 1, X 3 = 0]
switches to process Y, then process Y can enter into
critical section. = + Pr[X1 = 0, X 2 = 0, X 3 = 0]
Pr[X3 = 0]
After entering into the critical section, then if processor
switches to process X, then process X also can enter
1 1 1 1 1 1 1 1 1
into the critical section. . . + . . + . .
It is clearly showing that both are in critical section at = 2 2 2 2 2 2 2 2 2
1
a time which leads to “failing to guarantee material
2
exclusion” (Q X1, X2, X3 are independent)
To enter into the critical section process X is not waiting 3
for process Y and vice versa. So we can “Prevent = = 0.75
4
Deadlock” so, overall, option (a) is correct. 38. (c) For non-trivial solution, we have | A | = 0
31. (d) Give L = 1250 Bytes
B = 100 mbps p q r
d = 1km i.e., q r p = 0
V= ? r p q
d (C1 ® C1 + C2 + C3)
In CSMA/CD, L = 2 ´ ´B
v
1 q r
3
2dB 2 ´ 10 ´ 10 8 1 r p
(p + q + r) =0
ÞV= = Þ V = 20,000 km/sec 1 p q
L 104
32. (d) Counter example : [R2 ® R2 – R1; R3 ® R3 – R1]
(a) Let X = {1} Þ X¢ = S – X {2, 3, 4, 5, 6} Þ |X| ¹ |X¢| p+ q+r=0
(b) Since |S| = 6 and |X| = 5 = |Y| 1 q r
\ Atleast 4 elements common in X and Y 0 r -q p-r
(or) =0
Þ X Ç Y = f is false 0 p-q q-r
SOLVED PAPER - 2015 2015-41
(i) FcFs
Process AT BT LT TAT
A 0 3 3 3
B 1 6 9 8
Program Y : C 4 4 13 9
Cyclomatic complexity = 10 – 8 + 2 = 4 D 6 2 15 9
Program Z : 29
= 7.25
4
Gantt chart
X
A B C D
0 3 9 13 15
(ii) SJF
Y
Process AT BT LT TAT
Total number of edges = X+Y+1 Þ 20 A 0 3 3 3
Total number of vertices = 15 B 1 6 9 8
Hence cyclomatic complexity = 20 – 15+2 = 7 C 4 4 15 11
42. 175 Transmission time for 5000 bits = Time for 500 bits to D 6 2 11 5
5000 27
travel = = 50 microseconds = 6.75
107 4
Gantt chart
So, after 50 microseconds the packet is completely
transmitted. But the packet must reach at the other and A B D C
this happens exactly after propagation delay which is 9
0 3 11 15
20 microseconds. So, the switch receives packet after
50 + 20 = 70 microseconds. B- 6 C-9 D -2
2015 -42 SOLVED PAPER - 2015
(iii) SRTF Þ 2n – 1 = 201
Process AT BT CT TAT Þ 2n = 202 Þ 2n = 28
A 0 3 3 3 Þn=8
B 1 6 15 14 47. (c) L1 = am bn an bm Þ This one is CFL
C 4 4 8 4 L2 = am bn am bn Þ by pumping lemma this one is not CFL.
D 6 2 10 4 L3 = am bn |m = 2n + 1 Þ This is CFL.
48. 50
25
= 6.25 Suppose that ‘k’ is order of the non-leaf node
4 k(8) + (k – 1)12 £ 1024
Gantt chart 20k £ 1036
é1036 ù
k£ê Þ k £ 51
A A B C C D B ë 20 úû
As the order is 51, maximum we can store 50 keys.
0 1 3 4 6 8 10 15 49. (d) For deadlock prevention we need to dissatisfy any of
A-2 B-5 C-2 -5 B-5
B the necessary condition for deadlock
B-6 C-4 B-5 D-2 1. For hold and wait if we dissatisfy it can be hold or wait
D-2 for hold …before process start os assign all resources.
While executing if process making new resource
(iv) R.Q (Q = 2) request it has to release all its assign resources that is
Process AT BT CT TAT waiting for release resources.
A 0 3 5 5 2. If we dissatisfy circular wait condition suppose there
B 1 6 15 14 r five resources uniquely numbered r1 to r5 and there
C 4 4 13 9 five processes p1 to p5 suppose p2 hold r1, and
D 6 2 11 5 requesting for r2, and r2 hold by p3 and wait for r3, r3
33 hold by p4 wait for r4 which is hold by p5 and wait for
= 8.25 r5 which is held by p1 ( this is happening in circular
4
manner)(condition to come out from circular wait is a
Gantt Chart process can hold the resource and request for new
R.Q. resource only when holding resource id is lesser then
requesting resource id) in above p1 is violating
A B A C B D C B condition.
3. If we dissatisfy preemption if a process hold some
0 2 4 5 7 9 11 13 15 resources requesting for new resources and that
46. 8 requesting resources are busy with some other process
Given requesting process voluntarily release its held
resources.
L = 107 bits üï L 10 ´ 106
T Þ= = According to 1 and 3 above statements, first statement
ý x
B = 500 ´ 106 bps ïþ B 500 ´ 106 = 0.02 sec (i) is correct.
d = 8000km ïü According to above second statement, second
d 8 ´ 106 statement (ii) is correct.
ý Þ T = =
v = 4 ´ 106 m / sïþ
p
v 4 ´ 106 = 2 sec According to above second statement if we implement
h = 100% the logic in reverse order then the third statement (iii)
n=? is also correct.
According to second statement condition statement
Tp 2 (iv) is also correct.
\a= = = 100
Tn 0.02 50. (b) O(n logn) = 30s
n = 64
w O (64 log 64) = 30
Given protocol, Go back N protocol. So h =
1 + 2a Hence will get factor of 12.8 for 6 min= 6×60 = 360s
where w = 2n – 1 O (256 log256) = 360
O (512 log 512) = 360
100 w
= Þ w = 1 + 2a O(1024 log 1024) = 360
100 1 + 2a O (2048 log 2048) = 360
Þ 2n –1 = 1 + 2 (100) So for 512 will get 12.8 as a factor
SOLVED PAPER - 2015 2015-43
51. 140
a 10 20 30 40 50
56.
1
(a) af (x) + b.f. 1 x = - 25
x
( ) ...(1)
( )
Þ af 1 x + b.f (x) = x – 25 ...(2)
Solving, we get f(x) =
p é æ1
1 ö ù
2 êa çè x - 25÷ø - b(x - 25) ú
2
a -b ë û
2
1 éëa{ln x - 25x}12
\ ò f (x)dx = 2
a -b 2
1
ptr after ptr + + Þ ptr – p = 1
(pointer arithmetic)
üï ù
2
ptr ìï x 2
** ptr = 40 b
– í - 25x ý úú
\ printf ("%d%d", p + r – p, p + r) will print 140 îï 2 þï1 û
52. 158
Given IP address 200.20.11.144/27 é 1 ì3 üù
To find out the loss address in a block, we have to set = 2 ê a{ln 2 - 25} - b í 2 - 25ý ú
2
a -b ë î þû
(32–n) no. of right most bits to 1.
n = 27 1 é 47 ù
= 2 êë a{ln 2 - 25} + 2 búû
32 – n = 32 – 27 = 5 a - b2
200.20.11.10010000 57. 995
200.20.11.10011111 G has 100 verticles Þ spanning tree contain 99 edges
200.20.11.159 given, weight of a minimum spanning tree of G is 500
\ CIDR Address range is 200.20.11.128/27- since, each edge of G is increased by five
200.20.11.159/27 \ Weight of a minimum spanning tree becomes
But w.r.t the question, the value of the last octet of last 500 + 5 × 99 = 995.
host in this network is 200.10.11.158. 58. (b)
53. 230 g(6)
01 1 1* 0 1* g(0) g(–2)
11 Total calls = 25
0 0 0 0
59. (a)
10 0 0 0 1* 60. (c) Since p – q ¹ q – p
\ (p, q) R (p, q)
Þ R is not reflective
There are three groups, and all the containing esential- Let (p, q) R (r, s) then p – s = q – r
1, so all are prime implicants as well as essential prime Þr–q=s–p
implicants also. Þ (r, s) R (p, q)
55. (c) Þ R is symmetric
2015 -44 SOLVED PAPER - 2015
61. (a) \ 5 solutions are possible which are (14,7), (12,6),
62. (d) As – 1 £ sin x £ 1, neither of them is true. (10,5), (8,4) and (6,3)
63. (d) (I1) R1 ¬ R2 + R3 65. 309.33
(I2) R7 ¬ R1 × R3 Let ‘S’ be the distance covered in 20 minutes, then by
(I3) R4 ¬ R1 – R5
1
(I4) R3 ¬ R2 + R4 simpson’s rd rule,
(I5) R7 ¬ R8 × R9 3
Anti dependence 20
(i) -------------- = x
(j) X : --------------
S= ò Vdt Q v = velocity
0
then i and j are anti – dependence
Hence I2 and I4 are anti-dependence 2
Þ Anti-dependence create stall in pipeline = [(0 + 0) + 4 (10 + 25 + 32 + 11 + 2) + 2 (18 + 29 + 20
3
64. 5 + 5)]
(43)x = (y3)8 = 309.33 km
Þ 3 + 4x = 3 + 8y Þ 4x = 8y (Here length of each of the subinterval is h = 2)
Þ x = 2y
Þ x ³ 5 and y £ 7
S1-1
Grammar
SECTION - 1 : GENERAL APTITUDE
PART-A : VERBAL ABILITY
1 Grammar
Chapter
5. When refer to the things in a general way: The news of Princess Diana was greatly exaggerated.
the environment, the climate, the human race, the wind, (v) Other words which confuse include:
the future, the weather, the atmosphere, the ocean, the She doesn’t have a means of control over the company
sea. However, if we describe them for a particular she inherited.
instance, we use a/an and not ‘the’, compare.
Politics is not his cup of tea. He is better off in acting.
6. When we expect the listener or reader identifies the thing or
Statistics was always her worst subject.
person we are referring to, on the other hand, a/an is used
when we don’t. Compare the following pairs of sentences. Some more words: economics, linguistics, mathematics,
phonetics, physics, gymnastics, athletics, diabetes, measles,
Wilson bought the house in Lincon Street last month
rabies etc. are singular but seem to be plural.
(= the house we have previously known)
(vi) Nouns used as singular and plural but with different meanings
7. When it is clear from the situation which person or thing we
are referring to. Fish (collectively): There are not many fish in this pond.
What do you think of the carpet? (= the carpet is lying Fishes (separate fishes): Barry cooked all the four fishes
before us) for dinner.
8. When we repeat something about something: Cloths (kinds or pieces of cloth, not made up into
garments) – she cut all cloths into pieces.
Bob ordered a cake and an apple pie but the cake was
found to be stale. In the sentence, we say a ‘cake’ when Clothes (garments): I sent all the clothes to laundry.
we first mention it and ‘the cake’ after that, when the Pronouns – common errors in their use
listener knows which cake we are talking about. A pronoun is a word that takes the place of a noun. Pronouns are
NOUN: COUNTABLE AND UNCOUNTABLE, used to avoid repetitive use of the same noun within a sentence
GENDER AND CASES or narrative. The following is an example without the use of
pronouns:
A noun is a word that can be used to refer to a person, place,
thing, quality or action. It can be a subject or an object of a verb. We invited Kapoors to our party because we like Kapoors.
They can be modified by an adjective and can take an article or The sentence would sound better if a pronoun were introduced
determiner. We invited Kapoors to our party because we like them.
Nouns can be categorized as countable or uncountable. Here Important Tips to Remember
are some nouns which are normally uncountable, though in many
(1) Singular pronouns with singular antecedents and plural
other languages they may be countable:
pronouns with plural antecedents.
Apart from going to work, there’s lots of housework to do
Singular
for Kiran.
The man finished their work quickly... (incorrect)
She wore her jewellery and get ready for the party.
The man finished his work quickly... (correct)
Some common errors in use of nouns:
Plural
(i) Nouns which take a plural verb:
The men finished their work quickly. (correct)
Her all belongings were scattered in all over the place.
The men finished his work quickly. (incorrect)
She sent him her sincere congratulations on his
marriage. (2) Collective Noun Antecedents
She saves half of all her earnings every month. Students often use a collective noun antecedent when the
group members are considered a unit. Here are the examples:
He lives on the outskirts of Mumbai. ( = outlying areas
of a city or town) The construction crew started their project last year.
(incorrect)
(ii) Other nouns like these include:
The construction crew, started its project last year. (correct)
clothes, goods, particulars, premises (= building), riches,
savings, stairs, surroundings, thanks. However, when the group members are taken individually,
the plural pronoun is used.
(iii) The nouns police, people, cattle, staff, artillery always have
a plural verb. The noun whereabouts can be used either a The construction crew, some of them not happy with
singular or plural verb. working conditions, gathered its tools. (incorrect)
(iv) Some nouns always end in –s looking as if they are plural The construction crew, some of them not happy with
but when we use them as the subject, they take a singular working conditions, gathered their tools. (correct)
verb.
Grammar S1-3
(3) Gender Errors in Pronouns Preposition can also govern other parts of speech that are used
He and his were traditionally used to refer to both sexes as nouns.
when the antecedent was unknown. Now, in modern times, She left India for good.
it is fell that this usage is unfair to women, so one male
In short, we don’t want to do anything with them.
pronoun is avoided.
From here you can go to Istambul by air.
Each person has to face his fear of wild animals in the
jungle. (Singular) Position of Prepositions
All persons have to face their fear of wild animals in the Prepositions of place
jungle. (plural) At is used about a place we think of as a point rather than an area.
Each person has to face his or her fear of wild animals in We also use at about are event wherethere is a group of people.
the jungle (he or she) I arrived at Howrah station at 5.
(4) When two nouns are joined with ‘as well as’ then pronoun
On is used when we talk about a position touching a flat surface,
is used in agreement with the first subject.
or on something we consider as a line such as a road or river.
Peter as well as his friends is going on picnic.
There’s a cockroach on the floor.
The students as well as their teacher were present in the
In is used when we talk about a position within a larger area, or
function.
when it is within a larger space.
(5) When two nouns are joined with ‘with’ then the pronoun is
used in agreement with the noun before ‘with’. He works at Connaught place in Delhi.
The boy with his classmates Prepositions of Direction
The boys with their teacher To, towards, across, for, against, along, up, down, into etc. are
You can notice that in both sentences the usage of ‘his’ and called prepositions of direction.
‘their’ is in agreement with number and gender of the second To is used to denote destination
noun. I am going to railway station.
(6) When a subject is made up of two or more items joined by Towards indicates direction.
‘either .........or’ or ‘neither.... nor’, a singular verb is used if
He was last seen going towards the hotel.
the last item is singular and a plural verb if it is plural.
However, in informal English, sometimes a plural verb is used. For denotes destination.
Either your brother or you have eaten your lunch. He is leaving for Canada tomorrow.
Either the teachers or the principal is (or are) is blame Against refers to ‘opposite’, ‘pressing on’, ‘in contravention of’.
for the poor results. It was very difficult to run against such strong winds.
Neither the prime minister nor his spokespersons are to Across denotes ‘on the opposite side of’, ‘from one side to
address the press. another’, ‘both sides’, ‘through’
Prepositions - Important Inferences and Common Errors in
The man who came to see you yesterday lives across the
‘their’ usages.
road.
A preposition is a word which usually precedes a noun or pronoun
‘Come across’ is used when we mean ‘to find’ or ‘encounter’
and shows its relation to some other word in the sentence.
The man on the platform was staring at Gina. She came across this man when she was working in US and
then they got married.
They came after dinner.
Up denotes top and down is used to mean ‘descending’.
The cat is sitting under the table.
The child climbed up the stairs by himself.
In the first example ‘on’ and ‘at’ are two prepositions, which are
before the definite nouns ‘platform’ and ‘Gina’. They help TENSES AND ERRORS IN THEIR USAGE
establish the relationship between ‘the man’ and ‘the platform’ The tense is the form of a verb that shows the time, continuance
and ‘stare’ and ‘Gina’. or completion of an action that is expressed by the verb. ‘He is’ is
Remember in the present tense, ‘He was’ is past tense and ‘He will be’ is
A preposition may also be used at the end of a sentence: future tense.
Who were you talking to? When ‘a permanent state’ or ‘work at present’ is expressed.
This is the house I used to live in. He lives in Mumbai. (Presently living)
S1-4 Grammar
Some Important Tips: You should have taken her along. You should not be so
Please note that except I, we and you, all nouns and selfish.
pronouns fall into the category of third person. ‘Could’ is used as past tense of ‘Can’ to express ability about
Conditional clauses may be put in three categories. doing something in the past.
1. Main clause - future, “if” ....... present (likely or probable) By the time he was 12, he could drive the car competently.
He will help you if you ask him. ‘Must’ is followed by the bare-infinitive.
2. Main clause - conditional, “if”... past (unlikely, imaginary) You must hurry up if you don’t want to miss your train.
He would help you if your asked him. ‘Must’ also expresses strong advice or orders.
3. Main clause - conditional, perfect “if”... past perfect You must stop chewing tobacco if you want to avoid cancer.
(Impossible) ‘Must’ is used to say that something is very likely to be true.
He would have helped you if you had asked him. That elderly woman must be 90.
AUXILIARY VERBS Should and ought have much the same meanings, but ‘ought’ is
followed by to, ‘Ought to’ is used to say that ‘someone should
A verb that is used with another verb to form a particular tense or
do something because it is the best thing to do.
mood, for example - she was pleased, they have left. Sometimes
more than one auxiliary verb is used to form a tense, for example He really ought to stop drinking.
- She will be going, They have been warned. Auxiliary verb are When you talk about things which actually did not happen,
either modal verbs or primary verbs. though they were likely to-
‘Can’ expresses ability You should have been here before 11.
You can drive, can’t you? ‘Do’ makes questions and negative forms of the ordinary verb.
‘May’ denotes permission, doubt or possibility. Do you like apples?
You may be late, so call me tomorrow. ‘Do’ is used to emphasize the main verb in a sentence.
‘Might’ also expresses possibility but you are not at all certain Do be alert.
The train might be a few hours late. ‘Do’ is also used with present participles ending in _ ing
‘Should’ is used to say what is the right thing to do. She does shopping on Saturday.
Grammar S1-5
1. Choose the grammatically INCORRECT sentence : I contemplated ________ Singapore for my vacation but
[GATE 2012, 1Mark] decided against it. [GATE 2011, 1 Mark]
(a) They gave us the money back less the service charges (a) to visit (b) having to visit
of Three Hundred rupees. (c) visiting (d) for a visit
(b) This country’s expenditure is not less than that of 5. Choose the most appropriate alternative from the options
Bangladesh. given below to complete the following sentence :
(c) The committee initially asked for a funding of Fifty Suresh’s dog is the one _________ was hurt in the
Lakh rupees, but later settled for a lesser sum. stampede. [GATE 2012, 1 Mark]
(d) This country’s expenditure on educational reforms is (a) that (b) which
very less.
(c) who (d) all of these
2. Choose the grammatically INCORRECT sentence.
6. Were you a bird, you ____________ in the sky.
[GATE 2013, 1 Mark]
[GATE 2013, 1 Mark]
(a) He is of Asian origin.
(a) would fly (b) shall fly
(b) They belonged to Africa.
(c) should fly (d) shall have flown
(c) She is an European.
7. Who ___________ was coming to see us this evening?
(d) They migrated from India to Australia.
[GATE 2014, Set-2, 1 Mark]
3. While trying to collect an envelope from under the table,
(a) you said (b) did you say
I II
(c) did you say that (d) had you said
Mr. X fell down and was losing consciousness.
8. If she _______________ how to calibrate the instrument,
III IV she _______________ done the experiment.
Which one of the above underlined parts of the sentence is [GATE 2014, Set-3, 1 Mark]
NOT appropriate? [GATE 2014, Set-3, 1 Mark]
(a) knows, will have
(a) I (b) II
(b) knew, had
(c) III (d) IV
(c) had known, could have
4. Choose the most appropriate word(s) from the options given
(d) should have known, would have
below to complete the following sentence.
S1-6 Grammar
1. (d) 5. (d)
2
Chapter
Vocabulary
Quick Revision Material
SENTENCE COMPLETION 3. Tone. Sentences reflect the writer’s attitude towards the
subject matter. It is simple to comprehend material that is
FILL IN THE BLANKS OR SENTENCE presented neutrally. It is far more difficult to comprehend
COMPLETION material that is ironic, condescending, playful, sombre, or
Sentence completion questions test your ability to use your otherwise complex in tone.
vocabulary and recognise logical consistency among the elements 4. Style. Ideas may be expressed in different manners ornately
in a sentence. You need to know more than the dictionary or sparely, poetically or prosaically, formally or informally,
definitions of the words involved. You need to know how the journalistically or academically, originally or imitatively. An
words fit together to make logical and stylistic sense. author’s style depends on such details as word choice,
Sentence completion questions actually measure one part of imagery, repetition, rhythm, sentence structure and length.
reading comprehension. If you can recognise how the different Work through the following Fundas and learn techniques
parts of a sentence affect one another, you should do well at that will help you with vocabulary, grammatical complexity,
choosing the answer that best completes the meaning of the tone, and style.
sentence or provides a clear, logical statement of fact. The ability
Funda-1 : Before you look at the choices, read the sentence and
to recognise irony and humour will also stand you in good stead,
think of a word that makes sense
as will the ability to recognise figurative language and to
See how the process works in a typical model question.
distinguish between formal and informal levels of speech.
1. Because experience had convinced her that he was both
Because the sentence completion questions contain many clues
self-seeking and avaricious, she rejected the likelihood that
that help you to answer them correctly (far more clues than the
his donation had been.................
antonyms provide, for example), and because analysing them
helps you warm up for the reading passages later on in the test, (A) redundant (B) frivolous
on the paper-and-pencil test, answer them first. Then go on to (C) inexpensive (D) altruistic
tackle the analogies, the antonyms, and, finally, the time- This sentence presents a simple case of cause and effect. The
consuming reading comprehension section. key phrase here is self-seeking and avaricious. The woman has
Sentence completion questions may come from any of a number found the man to be selfish and greedy. Therefore, she refuses to
of different fields-art, literature, history, philosophy, botany, believe he can do something_______. What words immediately
come to mind? Selfless, generous, charitable? The missing word
astronomy, geology, and so on. You cannot predict what subject
is, of course, altruistic. The woman expects selfishness (self-
matter the sentences on your test will involve.
seeking) and greediness (avaricious), not altruism (magnanimity).
What makes the hard questions hard? The correct answer is Choice D.
1. Vocabulary Level: Sentences contain words like Funda-2 : Look at all the possible answers before you make
intransigence, nonplussed, harbingers. Answer choices your final choice
include words like penchant, abeyance, and eclectic. See how this Funda helps you deal with another question.
2. Grammatical Complexity . Sentences combine the entire 1. The evil of class and race hatred must be eliminated while it
range of grammatical possibilities adverbial clauses, relative is still in an .......................state; otherwise it may grow to
clauses, prepositional phrases, gerunds, infinitives, and so dangerous proportions.
on in convoluted ways. The more complex the sentence,
(A) Amorphous (B) overt
the more difficult it is for you to spot the key words that can
unlock its meaning. (C) uncultivated (D) embryonic
S1-8 Vocabulary
On the basis of a loose sense of this sentence’s meaning, you Funda-5 : Use your knowledge of word parts and parts of speech
might be tempted to select Choice A. After all, this sentence to figure out the meanings of unfamiliar words
basically tells you that you should wipe out hatred before it gets Note the application of this Funda in the following typical example.
too dangerous. Clearly, if hatred is vague or amorphous, it is less 1. This island is a colony; however, in most matters, it is and
formidable than if it is well defined. However, this reading of the receives no orders from the mother country.
sentence is inadequate: it fails to take into account the sentence’s
(A) dichotomous (B) methodical
key phrase.
(C) heretical (D) autonomous
Funda-3 : In double-blank sentences, go through the answers,
testing the first word in each choice (and eliminating First, eliminate any answer choices that are obviously incorrect.
those that don’t fit) If a colony receives no orders from its mother country, it is
essentially self-governing. It is not necessarily methodical or
1. Critics of the movie version of The Colour Purple ——— systematic nor is it by definition heretical (unorthodox). Thus,
its saccharine, overoptimistic mood at odds with the novel’s you may rule out Choices B and C.
more .....................tone. The two answer choices remaining may be unfamiliar to you.
(A) applauded...sombre Analyse them, using what you know of related words. Choice A,
(B) condemned...hopeful dichotomous, is related to the noun dichotomy, a division into
two parts, as in the dichotomy between good and evil. Though
(C) acclaimed...positive the island colony may be separated from the mother country by
(D) decried...acerbic distance, that has nothing to do with how the colony governs
For a quick, general sense of the opening clause, break it up. itself Choice D, autonomous, comes from the prefix auto-(self)
What does it say? Critics……….the movie’s sugary sweet mood. and the root nom-(law). An autonomous nation is independent; it
rules itself. Thus, the correct answer is autonomous Choice D.
How would critics react to something sugary sweet and over-
hopeful? They would disapprove. Your first missing word must Funda-6 : Break up complex sentences into simpler components
be a synonym for disapprove. See how this Funda helps you to analyse the following sentence.
Now eliminate the misfits. Choices A and C fail to meet the test: 1. Museum director Hoving ——— refers to the smuggled
applauded and acclaimed signify approval, not disapproval. Greek urn as the “hot pot;” not because there are doubts
Choice B, condemned and choice D decried, however, all about its authenticity or even great reservations as to its
disapprobation; they require a second look. price, but because its ——— of acquisition is open to
question.
To decide among Choices B and E, consider the second blank.
The movie’s sugary, overly hopeful mood is at odds with the (A) informally…..costliness
novel’s tone: the two moods disagree. Therefore, the novel’s (B) characteristically…..date
tone is not hopeful or sugary sweet. It is instead on the bitter or (C) colloquially…..manner
sour side; in a word, acerbic The correct answer is clearly Choice
(D) repeatedly…..swiftness
D.
In calling the smuggled urn a “hot pot, “ Hoving is not necessarily
Funda-4 : Watch for signal words that link one part of the speaking characteristically or redundantly or cheerfully. He is
sentence to another speaking either informally or colloquially. (Hot here is a slang
Note the function of such a contrast signal word in the following term meaning stolen or illegally obtained.) Its costliness is not
question. being questioned. However, because the urn has been smuggled
into the country, there clearly are unresolved questions about
1. Paradoxically, the more ——— the details this artist
how it got here, in other words, about its manner of acquisition.
chooses, the better able she is to depict her fantastic, The correct answer is Choice C.
otherworldly landscapes.
SYNONYMS / ANTONYMS
(A) ethereal (B) realistic
This is the other very important area of the vocabulary section.
(C) fanciful (D) extravagant
This section tests widely and exhaustively one’s knowledge of
The artist creates imaginary landscapes that do not seem to belong the language and word power, but goes beyond that to test your
to this world. We normally would expect the details comprising ability to remember words with similar meanings or opposite
these landscapes to be as fantastic and supernatural as the meanings. Or, alternately, to discover the similarity or proximity
landscapes themselves. But the truth of the matter, however, is between the meaning of the given word with one of those in the
paradoxical: it contradicts what we expect. The details she chooses options.
are realistic, and the more realistic they are, the more fantastic the
paintings become. The correct answer is Choice B.
Vocabulary S1-9
These exercises can get confusing sometimes because more than (i) meaning of all given words
one option may appear as the right answer or none of them may (ii) relationship between the given pairs of words
look like the right answer. For such questions a student may
There are different kinds of relationships that could be drawn
consider the following strategies.
from daily usage but some common relationships are given below :
STRATEGY 1
1. CAUSE : EFFECT
If you do not know the meaning of the given word, think of a
Liquor : Intoxication Liquor causes intoxication
context in which you might have used it, that may help you to
figure out the meaning, for example, in the question find the word Wound : pain wound causes pain.
nearest in meaning to In this relation the first word is the cause for the second
and the second is the result of the first
Magnify
2. PURPOSE
(a) Forgive (b) diminish (c) swell (d) extract
Bottle : Cork a cork is used to close a bottle
Now if you do not know what magnify means think of a magnifying
glass and what it does. It expands or makes a thing look bigger. Dress : cloth cloth is used to make a dress
So the right answer will be (c). In this relation, one word is used for another, there is a
STRATEGY 2 purpose between the two
If you cannot find a correct antonym in the given option think of 3. OBJECT : ACTION
the antonyms you know of and subsequently check if there is Gun : Fire you fire a gun
any word in the given options which is synonymous to the Violin : play you play a violin
antonyms in your mind. For example In this, one term is an object and the other action undertaken
Industrious with the help of that object.
(a) stupid (b) harsh (c) indolent (d) complex 4. ACTION : OBJECT
If you don’t know any of the words given as options think of foment : Riot you foment a riot
antonyms you could think of, like lazy, idle. Now think of Wear :clothes you wear clothes
synonyms of lazy and you will know indolent is a synonym of This is opposite to the previous relation, here the first word
lazy. So it will be the antonym to industrious. Formula is the action and the second the object with which that
SYNONYM of ANTONYM is another ANTONYM. action is done.
STRATEGY 3 5. PART : WHOLE
Look at the part of speech of the given verb. A word may exist in Book : Literature a book is a part of the larger body of
various parts of speech. For example precipitate exists as a verb literature
which means send rapidly into a certain state and also as a noun,
Ship : fleet ship is a part of the collection called fleet
precipitate, which means a substance deposited from a solution.
In this relation, the first word will in the same way be a
Polish constituent of a bigger body represented by the second
(a) ruthlessness (b) honesty (c) indolence (d) gaucheness word.
Now is this the verb polish or noun polish. Since all options are 6. SYNONYMS
nouns, this cannot be the verb polish related to shoes but noun Abundant : ample ample means the same as abundant
polish which means culture and sophistication and the antonym
Skilled : adroit the two words are synonymous, i.e., they
to this would be gaucheness.
mean the same
ANALOGIES
This relation is when both the words are synonyms
Analogies, literally means a comparison or a comparable similarity. 7. ANTONYMS :
A student has to find a pair of words in the same relation or a
Abstinence : indulgence indulgence means the opposite
similar relation as that of the given pair of words. Analogy is in a
of Abstinence
sense, a test of vocabulary since you need to know the meaning
of the words given, but in a broader sense it is a test of reasoning Legitimate : Unlawful Legitimate means legal which is
ability. To know the meaning of the words will not be enough if the opposite of unlawful
one is not able to understand clearly what the relation between In this relation, the two words are opposite to each other in
the pairs of words is. Therefore, there are two things that are meaning.
important to attempt a question on analogy :
S1-10 Vocabulary
8. SECONDARY SYNONYMS TIP-1 : The first and foremost step while attempting an
Callous : Indifference The synonym of callous will be analogy question should be to DEFINE THE
indifferent, since both words are adjectives but rather the RELATIONSHIP. To avoid any errors first define
noun form. Indifference has been given in the relation the relationship on paper or in your mind before
searching for options. Once you have defined the
Brainwave : Inspired The synonym of Brainwave is
relationship analyse the given pairs in the light
inspiration, but instead the second word in this relation is
of the relationship.
Inspired - the one who has inspiration.
TIP-2 : Always be careful about apparent and easy
In this relation, the two words are not directly synonymous
similarity. These are only to deceive the student as
but a slight mutation of the part of speech has been made in
you would be attracted by these options. Always
the second word.
confirm all the options and be highly careful while
9. WORKER : ARTICLE CREATED considering an obvious answer.
Carpenter : furniture carpenter makes wooden furniture TIP 3 : Sometimes a word has two meanings, while what
compose : music a composer composes or creates music may first come to your mind will be the more
In this relation, the first word is the doer and the second is frequent use of that word, if you cannot find a
the professional work done by the first. logical relation between the two words, go beyond
Following are certain tips that would help a student to attempt the obvious meaning and link the word with the
analogy questions. other meaning of the second word.
Vocabulary S1-11
1. Choose the most appropriate word from the options given 8. Choose the most appropriate alternative from the options
below to complete the following sentence : given below to complete the following sentence :
[GATE 2010, 1 Mark] Despite several ________ the mission succeeded in its
If we manage to __________ our natural resources, we attempt to resolve the conflict. [GATE 2012, 1 Mark]
would leave a better planet for our children. (a) attempts (b) setbacks
(a) uphold (b) restrain (c) meetings (d) delegations
(c) cherish (d) conserve
9. Which one of the following options is the closest in meaning
2. Choose the most appropriate word from the options given
to the word given below? [GATE 2012, 1 mark]
below to complete the following sentence :
Mitigate
His rather casual remarks on politics ___________ his lack
(a) Diminish (b) Divulge
of seriousness about the subject. [GATE 2010, 1 Mark]
(c) Dedicate (d) Denote
(a) masked (b) belied
10. Which one of the following options is the closest in
(c) betrayed (d) suppressed
meaning to the word given below?
3. Which of the following options is the closest in meaning
Nadir [GATE 2013, 1 Mark]
to the word below : [GATE 2010, 1 mark]
(a) Highest (b) Lowest
Circuitous
(c) Medium (d) Integration
(a) cyclic (b) indirect
11. Complete the sentence:
(c) confusing (d) crooked
Universalism is to particularism as diffuseness is to
4. The question below consists of a pair of related words _______________. [GATE 2013, 1 Mark]
followed by four pairs of words. Select the pair that best (a) specificity (b) neutrality
expresses the relation in the original pair. (c) generality (d) adaptation
[GATE 2010, 1mark] 12. Choose the most appropriate word from the options given
Unemployed : Worker below to complete the following sentence.
(a) fallow : land (b) unaware : sleeper He could not understand the judges awarding her the first
(c) wit : jester (d) renovated : house prize, because he thought that her performance was
5. Which of the following options is the closest in the meaning quite______. [GATE 2014, Set-1, 1 Mark]
to the word below : [GATE 2011, 1 mark] (a) superb (b) medium
Inexplicable (c) mediocre (d) exhilarating
(a) Incomprehensible 13. Match the columns. [GATE 2014, Set-2, 1 Mark]
(b) Indelible Column 1 Column 2
(c) Inextricable 1) eradicate P) misrepresent
(d) Infallible 2) distort Q) soak completely
6. Choose the most appropriate word from the options given 3) saturate R) use
below to complete the following sentence. 4) utilize S) destroy utterly
If you are trying to make a strong impression on your (a) 1:S, 2:P, 3:Q, 4:R (b) 1:P, 2:Q, 3:R, 4:S
audience, you cannot do so by being understated, tentative (c) 1:Q, 2:R, 3:S, 4:P (d) 1:S, 2:P, 3:R, 4:Q
or __________ [GATE 2011, 1 Mark] 14. Which of the following options is the closest in meaning to
(a) hyperbolic (b) restrained the phrase underlined in the sentence below?
(c) argumentative (d) indifferent It is fascinating to see life forms cope with varied
7. Choose the word from the options given below that is most environmental conditions. [2014, Set-1, 1 Mark]
nearly opposite in meaning to the given word : (a) adopt to (b) adapt to
[GATE 2011, 1 Mark] (c) adept in (d) accept with
Amalgamate 15. Choose the word that is opposite in meaning to the word
(a) merge (b) split “coherent”. [GATE 2014, Set-3, 1 Mark]
(c) collect (d) separate (a) sticky (b) well-connected
(c) rambling (d) friendly
S1-12 Vocabulary
1. (b) 8. (b)
2. (a) 9. (a)
3. (d) 10. (b) Nadir means the lowest or most unsuccessful point in
4. (d) a situation.
3
Chapter
Critical Reasoning
Quick Revision Material
Critical Reasoning (CR) is ability to reason clearly to evaluate Strategy to Crack Critical Reasoning Questions
and judge arguments. You are using this skill a lot during your This strategy is not the easiest way to do CR (the easiest would
everyday life while reading newspapers or watching movies. When
be read-and-answer), but it lets you get the most questions right
you think that the movie is pushing the limit of the Reasonable or
spending less time per correct answer.
the news sounds less reasonable than the movie that was pushing
the limit, you are using your Critical Reasoning skills to produce 1. Read the questions first; this is needed so that you would
these conclusions. The argument you meet can be anything from a know what to look for and what to do: find an assumption,
classical argument to an advertisement or a dialog. Critical strengthen/weaken, infer something or else; do not worry
Reasoning questions will ask you to manipulate the argument to about the details in the question, read for keywords, such
weaken/strengthen it, find the conclusion, assumption, explanation, as strengthen, deny, or explain. [Use symbols for
do an inference or supplement a statement, etc. Whatever it is that convenience, e.g. + for strengthen or – for weaken].
you have to do, you will need 2 things to succeed: know the basic 2. Read the passage very attentively because in contrast to
structure of arguments and clearly understand the argument. Reading Comprehension, there is very little text here and
In general, most of them, arguments consist of evidence, usually mostly everything is important; try to read only once.
2 pieces, a conclusion - the main point of an argument, and an Reread if required.
assumption - the bridge between the evidence and conclusion. As you read, look for the problem in the passage (evaluate
The majority of the arguments you encounter on the test will be how convincing it is)
3 step arguments: 3. Paraphrase (reword) the passage. It is a very important
Evidence 1 + Evidence 2 = Conclusion. step because when you do a paraphrase, you check
sumptio
As n whether you understood the passage and at the same
time you extract the skeleton of the argument, making it
easier to identify the conclusion and the assumption. Very
E1 + E2 = C often, the paraphrase of the passage will be pretty close
Example 1 : Last week Mike was detained for shoplifting at a to the conclusion. It is not surprising, since the conclusion
groceries store near his house, but he has been a Christian for 10 is the main point and evidence just supports it.) Your
years, therefore, the police must have been wrong accusing him paraphrase should be as close to the text and as simple as
in stealing. possible so that you would understand it easily and at the
Note : There are two pieces of evidence: ‘Mike was accused of same time could fully trust it. Do not make it too general
stealing’ and that ‘he is a Christian’. The conclusion is that ‘the nor too detail oriented. When you do a paraphrase, do it
police are wrong’. Therefore, our huge assumption here is that ‘a in three steps: Evidence1, Evidence2, and Conclusion;
Christian could not have stolen anything.’ put “therefore” word before you start your conclusion,
Example 2. There are a lot of mosquitoes outside today, please this will help you to set it off.
do not turn on the light in the room because a lot of them will fly 4. Read the question again (now with more understanding
in. of what is being asked; reading the question 2 times, it will
Note : Here the evidences are ‘there are a lot of mosquitoes also help you to make sure your answer exactly what is
outside today’ and ‘do not turn on the light’. The conclusion is stated and that you understand the question.)
that ‘Many will fly in’ and the assumption is ‘mosquitoes will 5. Answer before reading the answer choices. There are two
approach the light.’ reasons for this :
There is no set scheme for structure in CR, but since the majority (i) if you can think of the correct answer or at least the
of the arguments are only a few sentences long, the conclusion general direction that the answer choice needs to be,
usually comes in the first or the last sentence. However, some of you will identify it among the wrong choices much
the arguments encountered will not have a conclusion at all or faster, thus spend less time reading the answers,
will have just an implied one. which usually take 30 seconds to cover.
S1-14 Critical Reasoning
(ii) Often students are seduced by the author’s wording. Example 1 : Stimulus Argument
One reads a few words that were used in the passage Increases in funding for police patrols often lower the rate
and the brain identifies this choice with the passage, of crimes of opportunity such as petty theft and vandalism
thus making it seem more right that it needs to be. by providing visual deterrence in high-crime neighborhoods.
The more problems you practice with, the more Levels of funding for police patrols in some communities
chance is you will guess the right answer even before are increased when federal matching grants are made
reading it. available.
6. Go through the answers, first time scan them for YOUR Question :
answer choice (usually you will guess correctly in 60-70% Which of the following can be correctly inferred from the
of cases), if you did not find it, reread them more attentively. statements above?
7. Draw a grid to eliminate the wrong answers easier. Use Options :
“ ” for a sure answer, “ ” for a definitely wrong answer (a) Areas with little vandalism can never benefit from visual
choice, and “?” for an answer that may be right or deterrence.
questionable. This will help to concentrate only on a few (b) Communities that do not increase their police patrols
answer choices and will prevent you from reading same are at higher risk for crimes of opportunity late at night.
answers several times if you get confused or keep having (c) Federal matching grants for police patrols lower the
troubles locating the right answer. rate of crimes of opportunity in some communities.
(d) Only federal matching grants are necessary to reduce
Types of Critical Reasoning Questions
crime in most neighborhoods.
Critical reasoning questions will ask you to:
Sol. : (c) (c) is a summary of the information provided; it is the
1. Identify the inference / Must be true question
logical end of a chain of reasoning started in the
2. Identify the assumption.
stimulus argument. The sequence of events goes like
3. Strengthen an argument.
this :
4. Weaken an argument.
Increased funding Increased visual deterrence
5. Select the best conclusion / Main Point
Lower crime
6. Identify the paradox
The last statement could be mapped as follows:
7. Evaluation/ Reasoning
Federal grants Increased patrol funds
8. Identify a parallel argument/Structure.
(c) makes the chain complete by correctly stating that
federal grants can lead to lower crime in some
1. IDENTIFY THE INFERENCE / MUST BE TRUE
communities. Now the logical chain becomes:
QUESTION
Federal grants Increased funding Increased
These type of questions are extremely common. An
visual deterrence Lower crime
Inference means the same thing as “must be true”.
The other answer choices may not be correctly inferred
Conclusions differ from inferences in that conclusions
because they go beyond the scope of the argument.
are the result of premises and inferences are something
They may be objectively, factually correct, or they may
that must be true. The following are the typical Inference
be statements that you would tend to agree with.
(Must be true) based Questions:
However, you are limited to the argument presented
• If the statements above are true, which of the
when choosing a correct answer.
following must also be true?
2. IDENTIFYTHE ASSUMPTION
• Which of the following is [implied, must be true,
An assumption is an unstated premise that supports the
implicit, most reasonably drawn] in the passage
author’s conclusion. It’s the connection between the
above?
stated premises and the conclusion. An assumption is
• Which of the following inferences is best supported
something that the author’s conclusion depends upon.
by the statement made above?
Assumption questions are extremely common and have
How to tackle “Identify the inference / Must be true
types that look like this:
questions”:
• Which of the following most accurately states a
• Read the stimulus and look for the argument.
hidden assumption that the author must make in order
• Note that Must Be True questions may not contain
to advance the argument above?
an argument. They may just be a series of facts.
• Which of the following is an assumption that, if true,
Nevertheless, try to find the argument.
would support the conclusion in the passage above?
• Avoid choices which contain absolute statements -
How to approach “Identify the assumption Questions”
never, always, none, only etc. Although these words
• Look for gaps between the premises and the
might appear in some correct choice, you should be
conclusion. Ask yourself why the conclusion is true.
very sure about them.
Before you progress to the answer choices, try to
• Some of the options can be eliminated as they go
get feel of what assumption is necessary to fill that
beyond the scope of the passage. Note that an
gap between the premises.
inference can be based on only some of the
• Beware of extreme language in the answer choices of
information provided and not the complete passage.
assumption questions. Assumptions usually are not
extreme. “Extreme” answer choices usually contain
phrases such as always, never, or totally.
Critical Reasoning S1-15
3. CONCLUSION / MAIN POINT QUESTION • Knock out answers with extreme wording. Main Point
In Main Point / Conlcusion questions, you have to identify answers typically do not use only, always, never, best
the conclusion of an argument. You are trying to find the or any strong words that leave little room.
author’s point and should approach this question in a similar
4. EVALUATION/ REASONING BASED QUESTIONS
way to the reading comprehension main point questions.
Reasoning questions ask you to describe how the argument
They come in several different formats:
was made, not necessarily what it says. These questions
• The main point of the passage is that...
are closely related to assumption, weakening, and
• Which of the following statements about... is best
strengthening questions. The correct answer identifies a
supported by the statements above?
question that must be answered or information that must
• Which of the following best states the author’s
be gathered to determine how strong the stimulus argument
conclusion in the passage above?
is. The information will be related to an assumption that the
• Which of the following conclusions can be most
author is making. Another type of question that you will
properly drawn from the data above?
encounter asks you to identify a flaw in the stimulus
The conclusion of arguments in Main Point questions is
argument. The question tells you that there is a problem
usually not directly stated. To find the conclusion, identify
with the logic of the argument. You just have to choose the
the premises and then identify the conclusion drawn from
answer that describes the flaw. Here are some examples of
the premises. Main Point questions differ from the other
the ways in which these questions are worded:
Critical Reasoning questions in that the argument in the
• How does the author make his point?
stimulus is usually valid. (In most other Critical Reasoning
• A major flaw in the argument above is that it...
questions the reasoning is flawed.) Conclusion questions
• A’s response has which of the following relationships
require you to choose the answer that is a summary of the
to B’s argument?
argument.
How to approach Reasoning Questions
How to approach “Main Point Questions”:
• Read the argument and find the conclusion.
• Main Point answers must be within the scope of the
• State the reasoning in your own words.
passage.
• Check whether the reasoning given in the various
• Your opinions or information outside of the passage
options fall in line with the reasoning described above.
are always outside of the scope.
• Some of the options given can be out of the scope of
the passage.
S1-16 Critical Reasoning
1. Modern warfare has changed from large, scale clashes of having its net despite several failures. Such act of the
armies to suppression of civilian populations. Chemical spider encouraged Bruce not to commit suicide. And
agents that do their work silently appear to be suited to then, Bruce went back again and won many a battle, and
such warfare; and regretfully, there exist people in military the rest is history.
establishments who think that chemical agents are useful
Which one of the following assertions is best supported
tools for their cause. [GATE 2010, 2 Marks]
by the above information? [GATE 2013, 2 Marks]
Which of the following statements best sums up the
meaning of the above passage : (a) Failure is the pillar of success.
(a) Modern warfare has resulted in civil strife (b) Honesty is the best policy.
(b) Chemical agents are useful in modern warfare (c) Life begins and ends with adventures.
(c) Use of chemical agents in warfare would be undesirable (d) No adversity justifies giving up hope.
(d) People in military establishments like to use chemical
5. In a press meet on the recent scam, the minister said, “The
agents in war
buck stops her”. What did the minister convey by the
2. Few school curricula include a unit on how to deal with
statement? [GATE 2014, Set-1, 1 Mark]
bereavement and grief, and yet all students at some point in
their lives suffer from losses through death and parting. (a) He wants all the money
Based on the above passage which topic would not be (b) He will return the money
included in a unit on bereavement? [GATE 2011, 2 Marks] (c) He will assume final responsibility
(a) how to write a letter of condolence (d) He will resist all enquiries
(b) what emotional stages are passed through in the 6. The Palghat Gap (or Palakkad Gap), a region about 30 km
healing process wide in the southern part of the Western Ghats in India, is
(c) what the leading cause of death are lower than the hilly terrain to its north and south. The exact
(d) how to give support to a grieving friend reasons for the formation of this gap are not clear. It results
3. Wanted Temporary, Part-time persons for the post of Field in the neighbouring regions of Tamil Nadu getting more
Interviewer to conduct personal interviews to collect and rainfall from the South West monsoon and the neighbouring
collate economic data. Requirements : High School – pass, regions of Kerala having higher summer temperatures.
must be available for Day. Evening and Saturday work. What can be inferred from this passage?
Transportation paid, expenses reimbursed. [GATE 2014, Set-1, 2 Marks]
Which one of the following is the best inference from the (a) The Palghat gap is caused by high rainfall and high
above advertisement ? [GATE 2012, 2 Marks] temperatures in southern Tamil Nadu and Kerala
(a) Gender – discriminatory (b) The regions in Tamil Nadu and Kerala that are near the
(b) Xenophobic Palghat Gap are low-lying
(c) Not designed to make the post attractive (c) The low terrain of the Palghat Gap has a significant
(d) Not gender – discriminatory impact on weather patterns in neighbouring parts of
Tamil Nadu and Kerala
4. After several defeats in wars, Robert Bruce went in exile
(d) Higher summer temperatures result in higher rainfall
and wanted to commit suicide. Just before committing
near the Palghat Gap area
suicide, he came across a spider attempting tirelessly to
7. Geneticists say that they are very close to confirming the
have its net. Time and again, the spider failed but that did
genetic roots of psychiatric illnesses such as depression
not deter it to refrain from making attempts. Such and schizophrenia, and consequently, that doctors will be
attempts by the spider made Bruce curious. Thus, Bruce able to eradicate these diseases through early identification
started observing the near-impossible goal of the spider and gene therapy.
to have the net. Ultimately, the spider succeeded in
Critical Reasoning S1-17
On which of the following assumptions does the statement (a) Kaliningrad was historically Russian in its ethnic makeup
above rely? [GATE 2014, Set-1, 2 Marks] (b) Kaliningrad is a part of Russia despite it not being
(a) Strategies are now available for eliminating psychiatric contiguous with the rest of Russia
illnesses (c) Koenigsberg was renamed Kaliningrad, as that was
(b) Certain psychiatric illnesses have a genetic basis its original Russian name
(c) All human diseases can be traced back to genes and (d) Poland and Lithuania are on the route from Kaliningrad
how they are expressed to the rest of Russia
(d) In the future, genetics will become the only relevant 10. By the beginning of the 20th century, several hypotheses
field for identifying psychiatric illnesses were being proposed, suggesting a paradigm shift in our
8. Choose the most appropriate phrase from the options given understanding of the universe. However, the clinching
below to complete the following sentence. evidence was provided by experimental measurements of
India is a post-colonial country because the position of a star which was directly behind our sun.
[GATE 2014, Set-2, 1 Mark] Which of the following inference(s) may be drawn from the
(a) it was a former British colony above passage?
(b) Indian Information Technology professionals have (i) Our understanding of the universe changes based on
colonized the world the positions of stars
(c) India does not follow any colonial practices (ii) Paradigm shifts usually occur at the beginning of
(d) India has helped other countries gain freedom centuries
9. The old city of Koenigsberg, which had a German majority (iii) Stars are important objects in the universe
population before World War 2, is now called Kaliningrad. (iv) Experimental evidence was important in confirming
After the events of the war, Kaliningrad is now a Russian this paradigm shift [GATE 2014, Set-3, 2 Marks]
territory and has a predominantly Russian population. It is (a) (i), (ii) and (iv) (b) (iii) only
bordered by the Baltic Sea on the north and the countries (c) (i) and (iv) (d) (iv) only
of Poland to the south and west and Lithuania to the east
respectively. Which of the statements below can be inferred
from this passage? [2014, Set-2, 2 Marks]
S1-18 Critical Reasoning
1. (d) 5. (c)
2. (c) Given passage clearly deals with how to deal with 6. (c) The whole passage describe the physical
bereavement and grief and so after the tragedy occurs characteristics of the Palghat GAP and its significant
and not about precautions. Therefore, irrespective of impacts on weather patterns in neighbouring parts of
the causes of death, a school student rarely gets into Tamil Nadu and Kerala, Hence, (c) option is correct.
details of causes – which is beyond the scope of the
7. (b)
context. Rest all are important in dealing with grief.
8. (a)
3. (d) Gender is not mentioned in the advertisement and (b)
clearly eliminated. 9. (b)
1 Number System
Chapter
TYPES OF NUMBERS Least common multiple : The least common multiple (L.C.M.)
Natural numbers : These are the numbers (1, 2, 3, etc.) that are of two or more numbers is the smallest number which is exactly
used for counting. divisible by each of them.
It is denoted by N.
L.C.M. can be calculated by :
Even numbers : Natural numbers which are divisible by 2 are
even numbers. (i) Prime factorisation method
It is denoted by E. (ii) Division method
E = 2, 4, 6, 8,... H.C.F. AND L.C.M. OF FRACTIONS
Odd numbers : Natural numbers which are not divisible by 2 are First express the given fractions in their lowest terms.
odd numbers. Then,
Prime numbers : Natural numbers which have exactly two fac-
tors, i.e., 1 and the number itself are called prime numbers. H.C.F. of numerators
The lowest prime number is 2. H.C.F.
L.C.M. of denominators
Composite numbers : It is a natural number that has atleast one
divisor different from unity and itself. L.C.M. of numerators
Every composite number can be factorised into its prime factors. L.C.M.
H.C.F. of denominators
Whole numbers : The natural numbers along with zero (0), form
the system of whole numbers. Formula:
It is denoted by W. H.C.F. of numbers × L.C.M. of numbers = Product of numbers
Integers : The number system consisting of natural numbers,
NOTE :
their negative and zero is called integers.
It is denoted by Z or I. • The greatest number that will exactly divide x, y, z = HCF of
Real numbers : All numbers that can be represented on the num- x, y and z.
ber line are called real numbers. • The greatest number that will divide x, y and z leaving
It is denoted by R. remainders a, b and c respectively = HCF of (x – a), (y – b)
DIVISIONALGORITHM and (z – c ).
Dividend = (Divisor × Quotient) + Remainder • The least number which is exactly divisible by x, y and z
HCFAND LCM = LCM of x, y and z.
Highest common factor : The highest common factor (H.C.F.) • The least number which when divided by x, y and z leaves
of two or more numbers is the greatest number which divides the remainder a, b and c respectively= LCM of (x, y and z)–R
each of them exactly. It is also known as greatest common where R = (x – a) = (y – b) = (z – c)
divisor (G.C.D.). • The least number which when divided by x, y and z
leaves the same remainder r in each case = LCM of (x, y
H.C.F. can be calculated by :
and z) + r
(i) Prime factorisation method • The greatest number that will divide x, y and z leaving the same
(ii) Division method remainder in each case = HCF of (x – y), (y – z) and
(z – x).
S1-20 Number System
1. If 137 + 276 = 435 how much is 731 + 672? 5. Out of all the 2-digit integers between 1 and 100, a 2-digit
[GATE 2010, 2 Marks] number has to be selected at random. What is the
(a) 534 (b) 1403 probability that the selected number is not divisible by 7?
(c) 1623 (d) 1513 [GATE 2013, 2 Marks]
2. If log (P) = (1/2) Log (Q) = (1/3) Log (R), then which of the 13 12
(a) (b)
following option is TRUE? [GATE 2011, 1 Mark] 90 90
(a) P2 = Q3R2 (b) Q2 = PR 78 77
(c) Q2 = R3P (d) R = P2Q2 (c) (d)
90 90
3. What will be the maximum sum of 44, 42, 40, _______ ? 6. If (z + 1/z)2 = 98, compute (z2 + 1/z2).
[GATE 2013, 1 Mark] [GATE 2014, Set-1, 1 Mark]
(a) 502 (b) 504 7. When a point inside of a tetrahedron (a solid with four
(c) 506 (d) 500 triangular surfaces) is connected by straight lines to its
4. Find the sum of the expression [GATE 2013, 2 Marks] corners, how many (new) internal planes are created with
these lines? ______. [GATE 2014, Set-1, 2 Marks]
1 1 1 1
........ . 8. Which number does not belong in the series below?
1 2 2 3 3 4 80 81
2, 5, 10, 17, 26, 37, 50, 64
(a) 7 (b) 8
[GATE 2014, Set-3, 1 Mark]
(c) 9 (d) 10
(a) 17 (b) 37
(c) 64 (d) 26
S1-22 Number System
n2 – 7n – 8 = 0
2 1
n = – 1, 8 98 = z 2
z2
Possible base n = 8 (+ ve)
(435)n = (435)8 = (4 × 82 + 3 × 8 + 5)10 = (285)10 1
z2 96
(731)n = (731)8 = (7 × 82 + 3 × 8 + 1)10 = (473)10 z2
(672)n = (672)8 = (6 × 82 + 7 × 8 + 2)10 = (442)10 7. 10 to 10
So (731) 8 + (672)8 = (473)10 + (442)10 = (915)10 8. (c) The series is adding
(915)10 = (1623) +3, +5, +7, +9 etc.
1 Correct one is 50 + 15 = 65
1
2. (b) Log P = log Q = log (R) = K
2 3
2 Algebra
Chapter
• If, in a group, one or more new quantities are added or The results (i) and (iii) can be extended to any number
excluded, then the new quantity or sum of added or of sets.
excluded quantities = [Change in no. of quantities × (iv) n (A–B) = n (A) – n (A B) = n (A B')
original average] ± [change in average × final no. of (v) n (A B) = n (A) + n (B) – 2 n (A B)
quantities] (vi) n(A') = n (U) – n (A)
Take +ve sign if quantities added and (vii) n (A' B') = n (U) – n (A B)
take –ve sign if quantities removed. (viii) n (A' B') = n (U) – n (A B)
(ix) If A1, A2, ......, An are disjoint sets, then
SET
n(A1 A 2 ..... An ) n(A1) n(A 2 ) ..... n(A n )
A set is a collection of well-defined objects. The members
of a set are called element of set. De morgan’s laws
THEOREMS ON CARDINAL NUMBERS (a) (A B)' = A' B'
Let A, B, C are finite sets in a finite universal set U. Then (b) (A B)' = A' B'
(i) n (A B) = n(A) + n(B) – n (A B) (c) A – (B C) = (A – B) (A – C)
(ii) n (A B) = n(A) + n (B) A and B are disjoint non (d) A – (B C) = (A – B) (A – C)
void sets.
(iii) n (A B C) = n(A) + n(B) + n(C) – n(A B)
– n(B C) – n(C A) + n(A B C)
Algebra S1-25
1. 25 persons are in a room. 15 of them play hockey, 17 of them 5. Which of the following assertions are CORRECT?
play football and 10 of them play both hockey and football. P: Adding 7 to each entry in a list adds 7 to the mean of
Then the number of persons playing neither hockey nor the list
football is [GATE 2010, 1 mark]
Q : Adding 7 to each entry in a list adds 7 to the standard
(a) 2 (b) 17 deviation of the list
(c) 13 (d) 3 R : Doubling each entry in a list doubles the mean of the
2. Hari (H), Gita (G), Irfan (I) and Saira (S) are siblings (i.e., list
brothers and sisters). All were born on 1st January. The age S: Doubling each entry in a list leaves the standard
difference between any two successive siblings (that is born deviation of the list unchanged[GATE 2012, 2 Marks]
one after another) is less than 3 years. Given the following
(a) P, Q (b) Q, R
facts: [GATE 2010, 1 mark]
(c) P, R (d) R, S
I. Hari’s age + Gita’s age > Irfan’s age + Saira’s age
6. The cost function for a product in a firm is given by 5q2,
II. The age difference between Gita and Saira is 1 year.
where q is the amount of production. The firm can sell the
However, Gita is not the oldest and Saira is not the youngest
product at a market price of ` 50 per unit. The number of
III. There are no twins. units to be produced by the firm such that the profit is
In what order were they born (oldest first)? maximized is [GATE 2012, 1 Mark]
(a) HSIG (b) SGHI (a) 5 (b) 10
(c) IGSH (d) IHSG (c) 15 (d) 25
3. The variable cost (V) of manufacturing a product varies 7. The roots of ax2 + bx + c = 0 are real and positive. a, b and c
according to the equation V = 4q, where q is the quantity are real. Then ax2 + b|x| + c = 0 has
produced. The fixed cost (F) of production of same product [GATE 2014, Set-1, 1 Mark]
reduces with q according to the equation F = 100/q. How
(a) no roots (b) 2 real roots
many units should be produced to minimize the total cost
(V + F)? [GATE2011, 2 marks] (c) 3 real roots (d) 4 real roots
(a) 5 (b) 4 8. The value of 12 12 12 ... is
(c) 7 (d) 6
[GATE 2014, Set-2, 1 Mark]
4.5. A political party orders an arch for the entrance to the ground
in which the annual convention is being held. The profile of (a) 3.464 (b) 3.932
the arch follows the equation y = 2x – 0.1x2, where y is the (c) 4.000 (d) 4.444
height of the arch in meters. The maximum possible height 9. Consider the equation : (7526)8 – (Y)8 = (4364)8, where (X)N
of the arch is [GATE 2012, 2 marks] to the base N. Find Y. [GATE 2014, Set-3, 2 Marks]
(a) 8 meters (b) 10 meters (a) 1634 (b) 1737
(c) 12 meters (d) 14 meters (c) 3142 (d) 3162
S1-26 Algebra
dy d2y 12 x x
2 – 0.2 x 0
dx 2 12 + x = x2
dx
Hence maximises at 2 – 0.2x = 0 x = 10 x2 – x – 12 = 0
y = 20 – 10 = 10 m (x – 4) (x + 3) = 0
5. (c) P and R always holds true x = 4, – 3
Else consider a sample set {1, 2, 3, 4} and check x = 4 ( the value is real)
accordingly. 9. (c)
6. (a) p = 50q – 5q2
dp d2 p
50 –10q 0
dq dq 2
Percentage & Its Applications S1-27
more than the minimum required passing marks. Then the maximum
PERCENTAGE
100(a b)
marks M .
Increase value y x
• Increase % 100
Original value • If A’s income is r % more than that of B, then B’s income is
less than that of A by
Decrease value
• Decrease % 100 r
Original value 100 %
100 r
• If the price of a commodity increases by r %, then reduction • If A’s income is r % less than that of B, then B’s income is
in consumption, so as not to increase the expenditure is more than that of A by
r
100÷ % . r
100 + r 100 %
100 r
• If the price of a commodity decreases by r%, then the
increase in consumption so as not to decrease the PROFIT AND LOSS
Profit and Loss percentage
r
expenditure is 100 %
100 r Profit
Profit per cent = 100
C.P.
• First Increase and then decrease :
If the value is first increased by x % and then decreased by y %
Loss
Loss per cent = 100
xy C.P.
then there is x y % increase or decrease, according to
100
Goods passing through successive hands
the + ve or – ve sign respectively. When there are two successive profits of a% and b%, then the
• Student and Marks resultant profit per cent is given by
The percentage of passing marks in an examination is x%. If a
ab
candidate who scores y marks fails by z marks, then the maximum a b %
100
100(y z)
marks M = When there is a profit of a% and loss by b% in a transaction, then
x
Marked Price : The price on the lable is called the marked price
Discount
or list price. • Discount % = 100 .
M.P.
The marked price is abbreviated as M.P.
Discount : The reduction made on the ‘marked price’ of an • If the items are sold, each at ` x, one at a gain of p% and the
article is called the discount.
p2
NOTE : When no discount is given, ‘selling price’ is the same other at loss of p%, there is an overall loss given by %.
100
as ‘marked price’.
• Discount = Marked price × Rate of discount.
• S.P. = M.P. – Discount.
Percentage & Its Applications S1-29
Men Women
4. The Gross Domestic Product (GDP) in Rupees grew at 7%
Car 40 34
during 2012-2013. For international comparison, the GDP is
Own vehicle Scooter 30 20
compared in US Dollars (USD) after conversion based on
Both 60 46
the market exchange rate. During the period 2012-2013 the
D o not own vehicle 20 50
exchange rate for the USD increased from Rs. 50/ USD to
Rs. 60/ USD. India’s GDP in USD during the period 2012-
3. The ratio of male to female students in a college for five 2013 [GATE 2014, Set-3, 2 Marks]
years is plotted in the following line graph. If the number of
(a) increased by 5 % (b) decreased by 13%
female students doubled in 2009, by what percent did the
number of male students increase in 2009? (c) decreased by 20% (d) decreased by 11%
1. 850
A group of 5 tourists purchasing round-trip will be m m
= 2
3 2.5
15
charged = 1000 1000 = 850
100 m 6
=
2. 48 m 2.5
Don’t have own scooter = Have only car + Do not
m m
own vehicle % increase of students = ÷ 100
= 74 + 70 = 144 m
Percentage of respondents do not own a scooter =
m 6
= 1÷ 100 = 1÷ 100
144 m 2.5
100 = 48
300
3. 140 3.5
= ÷ 100
2008 2.5
male m = 140%
= = 2.5 4. (d) Rupee value inhered by 76
female f
Final value = 1.07 times
f = m/2.5
2009 50
Ratio of change in exchange value =
60
male m
= =3 India’s GDP in USD
female f
50
m = 1.07 × × 100% = 89%
f = 60
3
It decreased by (100 – 89)
Given f = 2f
= 11%
Time and Work & Speed and Distance S1-31
1 1 1 m
hr – Change in time = 1 × t ; for n > m
x y z n 1
xyz
Time taken to fill the tank hours. n
yz xz – xy = 1 × t1; for m > n
m
• Two filling pipes A and B opened together can fill a cistern
in t minutes. If the first filling pipe A alone takes X minutes • If first part of the distance is covered at the rate of v1 in time
more or less than t and the second fill pipe B along takes Y t1 and the second part of the distance is covered at the rate
minutes more or less than t minutes, then t is given by v1t 2 + v2 t 2
[t = xy] minutes.
of v2 in time t2, then the average speed is t1 + t 2 ÷
• A man covers a certain distance D. If he moves S1 speed • Suppose two trains or two bodies are moving in the same
faster, he would have taken t time less and if he moves S2 direction at u km/hr and v km/hr respectively such that u > v,
speed slower, he would have taken t time more. The original then
speed is given by their relative speed = (u – v) km/hr.
2 S1 S2
If their lengths be x km and y km respectively, then time
S2 ~ S1 taken by the faster train to cross the slower train (moving in
Z(Y – X)
(X + Y) – (X – Y) Upstream Downstream km / hr
Y= = X Y
2 2
• A man can row X km/h in still water. If in a stream which is
flowing of Y km/h, it takes him Z hours to row to a place and
back, the distance between the two places is
Time and Work & Speed and Distance S1-35
1. A transporter receives the same number of orders each day. 5. At what time between 6 a.m. and 7 a.m. will the minute hand
Currently, he has some pending orders (backlog) to be and hour hand of a clock make an angle closest to 60°?
shipped. If he uses 7 trucks, then at the end of the 4th day [GATE 2014, Set-2, 2 Marks]
he can clear all the orders. Alternatively, if he uses only 3 (a) 6 : 22 am (b) 6 : 27 am
trucks, then all the orders are cleared at the end of the 10th (c) 6 : 38 am (d) 6 : 45 am
day. What is the minimum number of trucks required so that 6. A dance programme is scheduled for 10.00 a.m. Some students
there will be no pending order at the end of the 5th day? are participating in the programme and they need to come
(a) 4 (b) 5 [GATE 2011, 2 marks] an hour earlier than the start of the event. These students
(c) 6 (d) 7 should be accompanied by a parent. Other students and
2. 5 skilled workers can build a wall in 20 days; 8 semi-skilled parents should come in time for the programme. The
workers can build a wall in 25 days; 10 unskilled workers instruction you think that is appropriate for this is
can build a wall in 30 days. If a team has 2 skilled, 6 semi- [GATE 2014, Set-3, 2 Marks]
skilled and 5 unskilled workers, how long will it take to build (a) Students should come at 9.00 a.m. and parents should
the wall? [GATE 2010, 2 marks] come at 10.00 a.m.
(a) 20 days (b) 18 days (b) Participating students should come at 9.00 a.m.
(c) 16 days (d) 15 days accompanied by a parent, and other parents and
3. A tourist covers half of his journey by train at 60 km/h, students should come by 10.00 a.m.
half of the remainder by bus at 30 km/h and the rest by (c) Students who are not participating should come by
cycle at 10 km/h. The average speed of the tourist in 10.00 a.m. and they should not bring their parents.
km/h during his entire journey is [GATE 2013, 2 Marks] Participating students should come at 9.00 a.m.
(a) 36 (b) 30 (d) Participating students should come before 9.00 a.m.
(c) 24 (d) 18 Parents who accompany them should come at 9.00
4. What is the average of all multiples of 10 from 2 to 198? a.m. All others should come at 10.00 a.m.
[GATE 2014, Set-2, 1 Mark]
(a) 90 (b) 100
(c) 110 (d) 120
S1-36 Time and Work & Speed and Distance
8000 1900
e
3 Average = = 100
19
1 120°
30 10 9 3
5
Chapter
Ratio & Proportion
Quick Revision Material
a c
If , then a, b, c, d are in proportions. MIXTURE (ALLIGATION)
b d
• Alligation rule :
Direct Proportion : If A and B are directly proportional then we
denote it by A B. Quantity of Cheaper Price of Dearer Mean Price
Also, A = kB, k is constant Quantity of Dearer Mean Price Price of Cheaper
Some Examples : Graphical representation of Alligation Rule :
1. Work done number of men Quantity
Quantity
2. Cost number of Articles a b
3. Work wages
Mean
4. Working hour of a machine fuel consumed Average (d)
5. Speed distance to be covered
Indirect Proportion (or inverse proportion) :
1 b–d d–a
If A and B are indirectly proportional then we denote it by A .
B Quantity of a b d
k Quantity of b d a
Also, A = (k is a constant) Price of the Mixture :
B
Some Examples : • When quantities Qi of ingredients Mi’s with the cost Ci’s
S1-38 Ratio & Proportion
are mixed then cost of the mixture Cm is given by and Quantity of B left = Q – Quantity of A Left
(ii) Let a vessel contains Q unit of ingredient A only. From this
Ci Q i
Cm R unit of ingredient A is taken out and replaced by an equal
Qi amount of ingredient B.
Removal and Replacement If this process is repeated n times, then after n operations,
(i) Let a vessel contains Q unit of mixture of ingredients A and n
B. From this, R unit of mixture is taken out and replaced by R
Quantity of A left = Q 1
an equal amount of ingredient B only. Q
If this process is repeated n times, then after n operations Quantity of B = 1 – Quantity of A left
n
Quantity of A left R
1
Quantity of A originally present Q
Ratio & Proportion S1-39
1. A container originally contains 10 litres of pure spirit. From What is the average of the marks obtained by the class in
this container 1 litre of spirit is replaced with 1 litre of water. the examination?
Subsequently, 1 litre of the mixture is again replaced with 1
(a) 1.34 (b) 1.74
litre of water and this process is repeated one more time.
How much spirit is now left in the container? (c) 3.02 (d) 3.91
[GATE 2011, 2 Marks] 4. The ratio of male to female students in a college for five
years is plotted in the following line graph. If the number of
(a) 7.58 litres (b) 7.84 litres
female students in 2011 and 2012 is equal, what is the ratio
(c) 7 litres (d) 7.29 litres of male students in 2012 to male students in 2011?
2. The current erection cost of a structure is ` 13,200.
1
If the labour wages per day increase by of the current
5
Ratio of male to female students
1 3.5
wages and the working hours decrease by of the 3
24
current period, then the new cost of erection in ` is 2.5
[GATE 2013, 2 Marks] 2
1.5
(a) 16,500 (b) 15,180
1
(c) 11,000 (d) 10,120 0.5
3. The table below has question-wise data on the performance 0
2008 2009 2010 2011 2012
of students in an examination. The marks for each question
are also listed. There is no negative or partial marking in the
examination. [GATE 2014, Set-3, 1 Mark]
[GATE 2014, Set-3, 2 Marks]
A ns wered A n s wered Not (a) 1: 1 (b) 2 : 1
Q No . M arks
Co rrectly W ro ngly A ttempted
1 2 21 17 6 (c) 1.5 : 1 (d) 2.5 : 1
2 3 15 27 2
3 2 23 18 3
S1-40 Ratio & Proportion
3 3
10 – 1 9 729
1. (d) 10 10 male m
10 10 1000 4. (c) In 2011, , =1
female f
729
1 = 7.29 litres male m m '
1000 In 2012, , , = 1.5
female f f
2. (a)
m = f and m' = 1.5f
3. (c) Total marks obtained
6 Permutation and
Chapter Combination & Probability
Quick Revision Material
CIRCULAR PERMUTATIONS 6. The number of permutations of 'n' different things, taking 'r'
(i) Arrangements round a circular table at a time, when each thing can be repeated 'r' times = nr
The number of circular permutations of n different things
COMBINATION
n
Pn
taken all at a time is = (n – 1) !, if clockwise and The number of combinations of 'n' dissimilar things taken 'r' at a
n
time is denoted by nCr or C(n, r). It is defined as,
anticlockwise orders are taken as different.
(ii) Arrangements of beads or flowers (all different) around a n!
nC =
circular necklace or garland: r r!(n r)!
Thus the number of circular permutations of ‘n’ different
things taken. NOTE :
n n n
1 • C0 1, Cn 1; Pr r! n C r
all at a time is (n – 1)!, if clockwise and anticlockwise
2
• n n
orders are taken to be same. Cr Cn r
Conditional Permutations n n n 1
• Cr 1 Cr Cr
1. Number of permutations of n things taking r at a time, in
• nC = nC x+y=n
n 1 x y
which a particular thing always occurs = r . Pr 1 .
• nC = nC = n+1C
r r+1 r
2. Number of permutations of n things taking r at a time, in
nC
n n–1
n 1 • r = . Cr–1
which a particular thing never occurs = Pr . r
3. Number of permutations of n different things taking all at a 1
• nC = (n – r + 1) nCr–1
time, in which m specified things always come together r r
= m!(n m 1)! . nC
• 1 = nCn–1 = n
S1-42 Permutation and Combination & Probability
= n k .
Cr k Conditional Probability
2. Number of combinations of n distinct objects taking r( n)
A
P , represents the conditional probability of occurrence of
at a time, when k (0 k r) particular objects never occur B
= n k A relative to B.
Cr .
= n C1 n
C2 n
C 3 .............. n
Cn 2n 1 If A and B are two independent events, then
7. The number of ways of dividing 'm + n' things into two P(A / B) P(A) and P(B / A) P(B) and
groups containing 'm' and 'n' things respectively
therefore P(A B) P(A )P(B)
(m n)!
= m + nCm nC
n m!n!
Permutation and Combination & Probability S1-43
1. Given digits 2, 2, 3, 3, 3, 4, 4, 4, 4 how many distinct 4 digit 3. An automobile plant contracted to buy shock absorbers
numbers greater than 3000 can be formed? from two suppliers X and Y. X supplies 60% and Y supplies
(a) 50 (b) 51 [GATE 2010, 2 Marks] 40% of the shock absorbers. All shock absorbers are
(c) 52 (d) 54 subjected to a quality test. The ones that pass the quality
2. P, Q, R and S are four types of dangerous microbes recently test are considered reliable. Of X’s shock absorbers, 96%
found in a human habitat. The area of each circle with its are reliable. Of Y’s shock absorbers, 72% are reliable.
diameter printed in brackets represents the growth of a single The probability that a randomly chosen shock absorber,
microbe surviving human immunity system within 24 hours which is found to be reliable, is made by Y is
of entering the body. The danger to human beings varies [GATE 2012, 2 Marks]
proportionately with the toxicity, potency and growth (a) 0.288 (b) 0.334
attributed to a microbe shown in the figure below: (c) 0.667 (d) 0.720
4. The number of people diagnosed with dengue fever
(contracted from the bite of a mosquito) in north India is
twice the number diagnosed last year. Municipal authorities
to destroy half of the body mass in
1000
(milligrams of microbe required
600
Toxicity
1 Mathematical Logic
Chapter
P Q P Q List of Identities
F F F 1. P (P P)
F T F idempotence of
2. P (P P)
T F F
idempotence of
T T T 3. (P Q) (Q P)
IMPLIES ( ) commutativity of
4. (P Q) (Q P)
P Q P Q commutativity of
F F T 5. [(P Q) R] [ P (Q R)]
F T T associativity of
6. [(P Q) R] [ P (Q R)]
T F F
associativity of
T T T
S2-2 Mathematical Logic
(d) × [(tiger (×) lion (×)) {(hungry (×) threatened (d) d (Rainy(d) ~ Cold(d))
(×)) attacks (×)}]
S2-4 Mathematical Logic
9. Which one of the following propositional logic formulas is (a) P1 is a tautology, but not P2
TRUE when exactly two of p, q, and r are TRUE? (b) P2 is a tautology, but not P1
[2014, Set-1, 2 Marks] (c) P1 and P2 are both tautologies
(a) ((p q) r) (p q ~ r) (d) Both P1 and P2 are not tautologies
(b) (~(p q) r) (p q ~ r) 14. P and Q two propositions. Which of the following logical
expressions are equivalent? [2008, 1 Mark]
(c) ((p q) r) (p q ~ r)
1. P ~Q
(d) (~(p q) r) (p q ~ r)
2. ~ (~ P Q)
Problem Based MCQs 3. (P Q) (P ~ Q) (~ P ~ Q)
4. (P Q) (P ~ Q) (~ P Q)
10. Consider the following logic program P :
(a) 1 and 2 (b) 1, 2 and 3
A(x) B(x, y), C(y) (c) 1, 2 and 4 (d) All of 1, 2, 3 and 4
B(x, x) 15. The binary operation is defined as follows
Which of the following first order sentences is equivalent
to P? [2003, 2 Marks]
P Q PQ
(a) ( x) [ y] [B(x, y) C(y)] A(x)] ( x) [B(xx)] True True True
(b) ( x) [ y] [B(x, y) C(y)] A(x)] ( x) [B(xx)] True False True
(c) ( x) [ y] [B(x, y) C(y)] A(x)] ( x) [B(xx)] False True False
False False True
(d) ( x) [ y] [B(x, y) C(y)] A(x) ( x) [B(xx)]
11. Consider the following formula and its two
Which one of the following is equivalent to P Q?
interpretations l1 and l2
[2009, 1 Mark]
: ( x) [Px ( y)[Qxy Qxy]] ( x) [ Px]
(a) Q P (b) P Q
l1 : domain : the set of natural numbers
(c) P Q (d) P Q
Px x is a prime number
16. What is the correct translation of the following statement
Qxy y divides x into mathematical logic? [2012, 1 Mark]
l2 : same as l1 except that Px = x is a composite number “Some real numbers are rational”?
Which of the following statements is true? (a) x (real) (x) v rational (x))
[2003, 2 Mark] (b) x (real) (x) rational (x))
(a) l1 satisfies , l2 does not (c) x (real) (x) rational (x))
(b) l2 satisfies , l1 does not (d) x (rational (x) real (x))
(c) Neither l1 nor l2 satisfies 17. Consider the following logical inferences :
(d) Both l1 and l2 satisfy I1: If it rains, then the cricket match will not be played.
12. Let P, Q and R be three atomic propositional assertions. Let The cricket match was played. [2012, 1 Mark]
X denotes (P Q) R and Y denotes (P R) (Q R). Inference There was no rain.
Which one of he following is a tautology? [2005, 1 Mark] I2 : If it rains, then the cricket match will not be played.
(a) X Y (b) X Y It did not rain.
(c) Y l (d) Y X Inference The cricket match was played.
13. Consider the following propositional statements Which of the following is true?
[2006, 1 Mark] (a) Both I1 and I2 are correct inferences
P1 : ((A B) C) ((A C) (B C)) (b) I1 is correct but I2 is not a correct inferences
CONCEPTUAL MCQs 6. (a) For x, the predicate fsa there exists y and the
corresponding predicate pda which is equivalent to x.
1. (d) ("x) [a Þ b] Þ (("x) [a] Þ " (x) [b]) is a logical \ (A x fsa (x))
2. (d) The statement some boys in the class are taller than
Þ ($ y pda (y) ^ (equivalent (x, y))
all the girls.
So, the logical notation is 7. (c) The correct translation of gold and silver ornaments
($x) (boy (x) Ù ("y) (girl (y) ® taller (x, y))) are precious is choice (d).
3. (b) Every teacher is liked by some students, then the " x ((G(x) Ù S(x)) ® P(x))
logical expression is " (x) [teacher (x) ® $ (y) which reads as “if an ornament is gold or silver, then it
{student (y) Ù likes y(x)}] is precious”. Since, a given ornament cannot be both
where, likes (y, x) mean y likes x, such that y represents gold and silver at the same time.
the student and x represents the teacher.equivalence 8. (d)
and therefore, a valid first order formula. 9. (b) (~ (p « q) Ù r) Ú (p Ù qÙ ~ r)
4. (d) The given statement should be read as ‘If an animal is
a tiger or a lion, then (if the animal is hungry or We prove the truth table as follows:–
threatened) it will attack.’ As the 2nd term in each given option is common we
Therefore, correct option is (d). have included this term only once in the truth table:
5. (b) The statement ‘Not every graph is connected’ is same
as ‘There exists some graph which is not connected'
which is same as $ x {graph (x) Ù Ø connected (x)}.
Also as given exactly two of p, q and r are to be true, so we need to consider only three combinations as above.
We see that only option (B) (~ (p « q) Ù r) Ú (p Ù qÙ ~ r) is true in all three cases when exactly two of p, q and r are true.
We know that P ® Q º ~ Q ® ~ P So, the statement is saying that “Not all the shiny
\ ~ Q : The circket match will be played. surface is Gold.” From the statement it can be deduced
that there is “Some glitters that is “definitely” not
~ P : It is not rain.
gold”. However, nothing can be deduced that whether
\ If the cricket match was played, then there was “some glitters is Gold” or “No glitters is Gold.”
no rain [P ® Q = ~ PQ ® ~ P]
(A) For all x : glitters (x) Þ gold (x)
\ I1 is correct.
It says that if something is glitters then it must not be
I2 : If it rains, then the cricket match will not be played. Gold, which may not be true according to the above
It did not rain. discussion.
Inference : The cricket match was played. (B) For all x : gold (x) Þ glitters (x)
I2 is not correct. It says that if something is Gold then it must be Glitters,
Proof which can’t be deduced from given statement.
According to logic table P ® Q i.e., (C) $ x : gold (x) ^ glitters (x)
It says that if something x is available which is not
P Q P®Q glitters and is Gold. However this also can’t be
F F T deduced from given statement.
F T T (D) $ x : glitters (x) ^ gold (x)
T F F It says that some x exists which is glitters and is not
T T T Gold. We note that from the given statement we
deduced this only as discussed above.
i.e., if there was not rain [i.e., P is F in logic table] then 19. (d) g : mobile in good
match may or may not be played because in both case c : mobile in cheap.
P ® Q is true. P : Good mobile phones are not cheap
So, the correct inference is—the cricket match might » g ® Øc » (Øg Ú Øc)
be played.
Q : cheap mobile phones are not good
18. (d) The Given statement is:
» c ® Øg » (Øc Ú Øg)
“Not all that glitters is Gold”
\ Both P and Q are equivalant
Here “Glitters” means the “Golden shiny surface” that \ L, M and N are correct
looks like gold.
Probability S2-9
2
Chapter
Probability
Quick Revision Material
Binomial Distribution
mr .e m
Probability of r successes, P(r) = Binomial distribution deals with trials of repetitive native in which
r! occurrence of an event or not is of interest.
where, m = np (constant) In a series of trials, the probability of r success in n traits is given
m = mean, variance by
standard deviation = m nC pr qn–r
r
Normal Distribution where, p-probability of success
A continuous random variable X follow normal distribution if its q-probability of failure
probability density function f (x) is given by:
1 (X )2
f (x) = e
2 2 2 2
µ-mean, -standard deviation.
Probability S2-11
13. Two fair dice are rolled and the sum r of the numbers turned 18. An examination consists of two papers, Paper 1 Paper 2.
up is considered [2006, 2 marks] The probability of failing in Paper 1 is 0.3 and that in paper
1 2 is 0.2. Given that a student has failed in Paper 2, the
(a) Pr (r > 6) = probability of failing in Paper 1 is 0.6. The probability of a
6
student failing in both the paper is [2007, 1 mark]
r 5 (a) 0.5 (b) 0.18
(b) Pr is an integer ÷ = (c) 0.12 (d) 0.06
3 6
19. A loaded dice has following probability distribution of
r 5 occurrences [2007, 1 mark]
(c) Pr r = 8 | is an integer ÷ =
4 9
Dice value 1 2 3 4 5 6
r 1 1 1 1 1 1 1
(d) Pr r = 6 | is an integer ÷ = Probability
5 18 4 8 8 8 8 4
14. A class of first year B. Tech students is composed of four
If three identical dice as the above are thrown, the probability
batches A, B, C and D, each consisting of 30 students. It is
of occurrence of values 1, 5 and 6 on the three dice is
found that the sessional marks of students in Engineering
(a) same as that of occurrence 3, 4, 5
Drawing in batch C have a mean of 6.6 and standard deviation
(b) same as that of occurrence 1, 2, 5
of 2.3. The mean and standard deviation of the marks for
the entire class are 5.5 and 4.2 respectively. It is decided by 1 5
the course instructer to normalize the marks of the students (c) (d)
128 8
of all batches to have the same mean and standard deviation 20. The standard deviation of spot speed of vehicles in, a
as that of the entire class. Due to this, the mark of a student highway is 8.8 km/h and the mean speed of the vehicles is
in batch C are changed from 8.5 to [2006, 2 marks] 33 km/h the coefficient of variation in speed is
(a) 6.0 (b) 7.0 [2007, 1 mark]
(c) 8.0 (d) 9.0 (a) 0.1517 (b) 0.1867
15. A probability density function is of the form P(x) = ke– |x|, (c) 0.2666 (d) 0.3646
x ( , ) . The value of k is [2006, 1 mark] 21. Let X be a random variable following normal distribution
(a) 0.5 (b) 1 with mean +1 and variance 4. Let, Y be another normal
(c) 0.5 (d) variable with –1 and variance unknown, if
16. For each element in a set of size 2n, an unbiased coin is P( X 1) P(Y 2), the standard deviation of Y is
tossed. The 2n coins are tossed independently. An element
[2008, 2 marks]
is chosen, if the corresponding coin toss were head. The
(a) 3 (b) 2
probability that exactly n elements are chosen, is
[2006, 1 mark] (c) 2 (d) 1
22. A person on a trip has a choice between private car and
2n 2n public transport. The probability of using a private car is
(a) n ÷ (b) n ÷ 0.45.While using public transport, further choice available
4n 2n are bus and metro, out of which the probability of commuting
by a bus is 0.55. In such a situation, the probability (rounded
1 up to two decimals) of using a car, bus and metro,
2n 1 respectively would be [2008, 2 marks]
(c) (d)
n ÷ 2 (a) 0.45, 0.30 and 0.25 (b) 0.45, 0.25 and 0.30
(c) 0.45, 0.55 and 0 (d) 0.45, 0.35 and 0.20
17. There are 25 calculators in a box. Two of them are defective. 23. Aishwarya studies either computer science or mathematics
Suppose 5 calculators are randomly picked for inspections every day. If she studies computer science on a day, then
(i.e., each has the same chance of being selected), what is the probability that she studies mathematics the next day is
the probability that only one of the defective calculators 0.6. If she studies mathematics on a day, then the probability
will be included in the inspection? [2006, 1 mark] that she studies computer science the next day is 0.4. Given
1 1 that Aishwarya studies computer science on Monday, what
(a) (b) is the probability that she studies computer science on
2 3
wednesday? [2008, 1 mark]
1 1 (a) 0.24 (b) 0.36
(c) (d)
4 5 (c) 0.4 (d) 0.6
Probability S2-13
24. X is a uniformly distributed random variable that takes value 30. Consider a company that assembles computers. The
between 0 and 1. The value of E[X3] will be probability of a faulty assembly of any computer is p. The
[2008, 1 mark] company therefore, subjects each computer to a testing
1 process. This testing process gives the correct result for
(a) 0 (b) any computer with a probability of q. What is the probability
8
of a computer being declared faulty? [2010, 1 mark]
1 1 (a) pq + (1 – p)(1 – q) (b) (1 – q)p
(c) (d) (c) (1 – p)q (d) pq
4 2
25. If probability density function of a random variable X is 31. Two coins are simultaneously tossed. The probability of
two heads simultaneously appearing is [2010, 1 mark]
f ( x) = x 2 for 1 x 1 and f ( x) = 0 for any other
1 1
(a) (b)
1 1 8 6
values of x, then the percentage probability P x ÷
3 3
1 1
is [2008, 1 mark] (c) (d)
4 2
(a) 0.247 (b) 2.47
(c) 24.7 (d) 247 32. A fair dice is tossed two times. The probability that the
26. The standard normal probability function can be second toss results in a value that is higher than the first
approximated as [2009, 2 marks] toss is [2011, 1 mark]
1 2 2
F(X N ) = (a) (b)
1 exp( 1.7255 X N | X N |0.12 ) 36 6
CONCEPTUAL MCQs
1. (c) Let the time taken for first and second modules be
representeed by x and y and total time = t.
t = x + y is a random varibale.
Now, the joint density function
t
g(t) = f(x,y) dx Mean (x) Md M0
0
t
5. (d) Given, P and Q are two random events, then
= f(x,t x) dx (a) Independence of P and Q
0
Probability ( P Q ) = Probability (P). Probability (Q)
t
= f (x)f 2 (t x) dx If two events P and Q are mutually disjoint, then
0 1
which is also called as convolution of f1 and f2, probability ( P Q ) = 0
abbreviated as f1*f2. So, option (a) is incorrect.
2. (a) Since out of (0, 0) (0, 1) (1, 0) (1, 1) only (0, 1) and (b) For two events P and Q
(1, 0) are success. Probability ( P Q) = Probability (P) + Probability
2 1 (Q)
Probability of success P =
4 2 – Probability ( P Q)
Probability of d successes out of n trials Here, Probability ( P Q) Probability (P)
d n d
n 1 1 + probability (Q)
P(X = d) = Cd So, option (c) is incorrect.
2 2
(c) There is no relationship between mutually exclusive
n
Cd and independent for two random variables P and Q.
= So, option (c) is incorrect.
2n
(d) And Probability ( P Q) Probability (P), which
3. (c) Required probability
P(a < X b) = P(a X b) is true for every events.
So, option (d) is correct.
b
f(x) dx 6. (c) Required probability
a P(a < X b) = P(a X b)
4. (d) (a) The measure of skewness depends upon the b
quartiles and moments which include in dispersion. f (x)dx
a
(b) In symmetric distribution, the value of mean, mode
and median are all same. PROBLEM BASED MCQs
i.e., (mean x ) = M0 (mode) = Md (median)
7. (d) Given P(A) = 1
(c) In a positively skewed distribution, P(B) = 1/2
mean > median > mode Both events are independent.
So, P (A B) = P(A). P(B)
= 1.1/2 = 1/2
P(A B)
P(A|B) =
P(B)
1/ 2
M0 Md Mean (x) = 1
1/ 2
(d) In a negatively skewed distribution mode > mean >
median. This sequence is not correct because the right P(A B)
P(B|A) =
sequence is P(A)
mode > median > mean
1/ 2
= 1/ 2
1
S2-16 Probability
14. (d) Let the mean and standard deviation of the students
of batch C are 17. (b) 25 calculators
n 2n n
1 1 1 1
2n 1 1 4 8 8 256
= Cn ÷
2 2 20. (c) We know that,
Standard deviation ( )
2n Variation coefficient
Mean (µ)
1
n
n ÷
= 2 n Cn ÷ = n 8.8
4 4 0.2666
33
S2-18 Probability
3 1/3
P( z 1) P z x 2 dx
Y
1/3
3 x2 is an even function, then using 3rd property of
1
definite integral
y
a a
y 3 f ( x) 2 f ( x ) dx, if f ( x ) is even,
22. (a) Probability of private car = 0.45 a 0
Probability of bus or Public transport = 0.55
1/3 1/3
Since, a person has a choice between private car and 2 x3
public transport. 2 x dx 2
3
Then, probability of public transport 0 0
= 1 – probability of private car
2 1 2
= 1 – 0.45 = 0.55
Now, probability of bus 3 27 81
= Probability of bus and public transport 2
= (Probability of bus or public transport) Probability of percentage 100 2.47%
81
× (Probability of public transport) 26. (d) Given, mean (µ) = 102 cm
= (0.55) × (0.55) = 0.3025 0.30 Standard deviation = 27 cm
Now, probability of metro
= 1 – (Probability of private car + Probability of bus) x1 x2
Also, P (x1 x x2 ) P z
= 1 – (0.45 + 0.30) = 0.25
Probability of private car = 0.45
Probability of bus = 0.30 90 102 102 102
P (90 x 102) P z
Probability of metro = 0.25 27 27
23. (c) Let C denotes computer science study and M denote
maths study. 12
P z 0
P(C on Monday and C on Wednesday) 27
= P(C on Monday, M on Tuesday and C on P( 0.44 z 0)
Wednesday) + P(C on Monday, C on Tuesday and C
on Wednesday)
= 1 × 0.6 × 0.4 + 1 × 1.4 × 0.4 = 0.40
24. (c) Since, X is uniformly distributed random variable
between (0, 1) = (a, b)
The probability density function – 0.44
1 1 The standard area is given by F(0) – F(–0.44)
f (x) 0
b a 1 0 1 1
1, 0 x 1 1 + exp(0) 1 exp[ 1.7255( 0.44)( 0.44) 0.12 ]
So, f (x)
0, other value of x 1 1
1 1 + 1 1 + exp(0.6879)
E ( x )3 x3 f ( x ) dx = 0.5 – 0.3345 = 1.655 16.55%
x 0 = 16.7%
Probability S2-19
27. (c) All the 10 tosses are independent of each other 33. (d) The combination of card will be
(1, 5), (2, 5), (3, 5), (4, 5), (1, 4), (2, 4), (3, 4), (1, 3), (2, 3),
2 8 10
æ1ö æ1ö æ1ö (1, 2) Þ 10
\ Required probability = ç ÷ ç ÷ = ç ÷ Number of combinations that the difference between
è2ø è2ø è2ø
numbers is 1.
28. (b) Let P (face value even) = x (4, 5), (3, 4), (2, 3), (1, 2)
\ P (face value odd) = 0.9x
4 2
Now, since x + 0.9x = 1 Probabilities = =
10 5
1 34. (c) One ball is drawn at random from each container,
x= = 0.5263
1.9 probability that one ball is red and other is blue.
Given, P(2) = P(4) = P(6) 4 3
C1 C1
Now, P(2) + P(4) + P(6) = x P( R) = , P( B) =
7 7
C1 C1
x Each event is mutually independent
P(2) = P(4) + P(6) =
3 4
C1 ´ 3C1
12
P( R) ´ P( B) = =
0.5263 7
C1 ´ 7C1 49
= = 0.1754
3 35. (a) There will be three combination of output
Coin1 Coin 2
æ even ö P(even Ç face > 3)
Pç ÷= H H
è face > 3 ø P(face > 3) H T
T H
[P(4) + P(6)] ´ 2 Thus, for both head probabilites will be P(HH) = 1/3
=
0.75 36. (c) p = number of cars per minute passing through a
certain road junction.
2 ´ 0.1754 p is a random variable following Poisson distribution
= = 0.4677
0.75
= 0.468 l k e -1
Prob ( P = k ) =
29. (b) Let N people in room. \ k!
So, number of events that atleast two people in room Mean = E[ p] = l
born at same date NC2. \ l=3
Probability of observing fewer than 3 cars
N
C2 ´ N C3 ´ ..... ´ NC N = Prob (P = 0) + Prob (P = 1) + Prob (P = 2)
\ 0.5 ³ ÞN=7
N!
30.e -3 31.e -3 32.e -3 1 é 9 ù 17
30. (a) Let F and C denote event of faulty assembly of = + + = 3 ê1 + 3 + ú = 3 .
0! 1! 2! e ë 2 û 2e
computer and the testing process giving correct result 37. (c) To find the expected number of unordered cycles of
respectively. length three.
P(F) = p Considering all the possible triplets of 3 vertices out
P(C) = q of 8 and finding, if they form a cycle.
Required probability Analyzing unordered cycles and choosing any three
vertices out of the 8 in any order.
= P(F Ç C) + P(F'Ç C')
This can be done in 8C3 ways.
= P(F)P(C) + P(F¢).P(C¢) The probability that there is an edge between a pair
of vertices is 1/2. To form a cycle between 3 chosen
= pq + (1 – p)(1 – q)
vertices, we need to form edges between all pairs.
31. (c) The total number of exhaustive cases
n = [(H, H), (H, T), (T, H), (T, T)]
V1
Total number of favourable case = {(H, H)} = m
m 1
Thus, probability = =
n 4 e2
32. (c) Total number of causes = 36
Total number of favourable causes
= 5 + 4 + 3 + 2 + 1 = 15
V2 V3
15 5 e3
Probability = =
36 12
S2-20 Probability
=
( C ) ( C )+
4
3
6
1
4
C4
=
5
f
2
÷ <0
10 10
C4 C4 42 f(x) has maximum
5 1
100 p = 100 × At x = and maximum value
42 2
= 11.9 1 1 1 1 1 1
=f 1 ÷ = . = = 0.25
2 2 2 2 2 4
Set Theory & Algebra S2-21
( )
-1
If (G, .) be a group and a Î G , then a -1 = a.
S2-24 Set Theory & Algebra
4 d Closed Interval.
b
c
2 3 a b
a
1 e
Fig. (b) Lattice Fig. (c) Non-Lattice
The poset shown in Fig. (c) is not a lattice since a and b have two
LUBs namely c and d. Fig. Interval [a, b]
Let a £ b.
From first lattice, following relations are obtained :
Then closed interval of a and b is defined as
1 £ 2, 1 £ 3, 2 £ 4 and 3 £ 4. [a, b] = [x/ a £ x and x £ b].
Here 2 and 3 are not compared. Clearly any closed interval is a chain.
If (P, £ ) is a lattice, then (P, ³ ) is also a lattice, we define as
Duality
³ follows
The dual of a Boolean expression is obtained by interchanging
(x £ y) Þ y ³ x.
Boolean sums and Boolean products and interchanging 0’s and 1’s.
In other words, GLB and LUB are interchanged if we interchange
e.g., The dual of x Ù (y Ú 0) is x Ú (y Ù 1)
relations £ and ³.
In terms of lattices, operations of meet and join on (L, £) become Boolean Algebra (Definition)
the operations of join and meet on (L, £).
1.
xÚ0 = x
}
x Ù 1 = x Identity laws
}
DUAL LATTICE x Ú x' = 1
For the lattice (P, £ ) the dual is (P, ³). 2. x Ù x' = 0 Domination laws
The duals are shown in the figure below. The diagram of (P, ³)
can be obtained from that of (P, £) by simply turning it upside 3. (x Ú y) Ù z) = x Ù (y Ù z) }
(x Ú y) Ú z = x Ú (y Ú z) Associative laws
down.
5 1 4. xÙy = yÙx }
x Ú y = y Ú x Commutative laws
4 5.
x Ú (y Ù z) = (x Ú y) Ù (x Ú z)
}
x Ù (y Ú z) = (x Ù y) Ú (x Ù z) Distributive laws
10. Let å = {a, b, c, d, e} be an alphabet. We define an The last row of the table is [2004, 2 Marks]
encoding scheme as follows g(a) = 3, g(b) = 5, g(c) = 7, (a) c a e b (b) c b a e
g(d)= 9, g(e) = 11. Let Pi denotes the i th prime number (c) c b e a (d) c e a b
(pi = 2) 16. Consider the binary relation :
For a non-empty string s = a1....an, where each a1Îå, S = {(x, y) | y = x + 1 and x, y Î {0, 1, 2,...}}
The reflexive transitive closure of S is [2004, 1 Mark]
define f(s) = Õin= 1 pig(ai) . (a) {(x, y) | y > x and x, y Î {0, 1, 2,...}}
For a none-empty sequence <s1 ...sn> of strings from å*. (b) {(x, y) | y ³ x and x, y Î {0, 1, 2,...}}
(c) {(x, y) | y < x and x, y Î {0, 1, 2,...}}
define h(<s1....sn >) = Õin=1 pif (si .) (d) {(x, y) | y ³ x and x, y Î {0, 1, 2,...}}
Which of the following numbers is the encoding h of a 17. Let f : B ® C and g : A ® B be two functions and let
non-empty sequence of strings? [2003, 2 Marks] h = fog. Given that h is an onto function. Which one of
7 7 7 8 8 8 the following is true? [2005, 2 Marks]
(a) 2 3 5 (b) 2 3 5
(c) 29 39 59 (d) 210 510 710 (a) f and g should both be onto functions
11. Consider the set å* of all strings over the alphabet (b) f should be onto but g needs not be onto
å = {0 , 1} å* with the concatenation operator for strings (c) g should be onto but not be onto
[2003, 1 Mark] (d) both f and g need not be onto
(a) does not form a group 18. Let R and S be any two equivalence relations on a non-
(b) forms a non-commutative group empy set A. Which one of the following statements is
(c) does not have a right identify element true? [2005, 2 Marks]
(d) forms a group, if the empty string is removed from (a) R Ç S, R È S are both equivalence relations
å* (b) R È S is an equivalence relation
12. Consider the following reccurrence relation: (c) R Ç S is an equivalence relation
T(1) = 1 (d) Neither R È S nor R Ç S is an equivalence relation
19. What is the minimum number of ordered pairs of non-
T(n + 1) = T(n) + êë n + 1 úû for all n ³ 1 negative numbers that should be chosen to ensure that
The value of T(m2) for m ³ 1 is [2003, 2 Marks] ther are two paris (a, b) and (c, d) in the chosen set such
m that a º c and mod 3 and b º d mod 5? [2005, 2 Marks]
(a) (21m - 39) + 4 (a) 4 (b) 6
6
m (c) 16 (d) 24
(b) (4m 2 - 3m + 5) 20. Let P, Q, R be three atomic propositional assertions. Let X
6
m denotes (P Ú Q) ® R and Y denotes (P ® R) Ú (Q ® R).
(c) (3m 2.5 - 11m + 20) - 5 Which one of the following is tautology? [2005, 2 marks]
2
(a) X º Y (b) X ®Y
m 5 (c) Y ® X (d) ØY ® X
(d) (5m3 - 34m 2 + 137m - 104) +
6 6 21. The set {1, 2, 4, 7, 8, 11, 13, 14} is a group under multiplica-
13. The following propositional statement is tion modulo 15. The inverses of 4 and 7 are respectively
(P ® (Q Ú R)) ® ((P Ù Q) ® R) [2004, 2 Marks] [2005, 1 mark]
(a) satisfiable but not vaild (a) 3 and 13 (b) 2 and 11
(b) valid (c) 4 and 13 (d) 8 and 14
(c) a contradiction 22. Let A, B and C be non-empty sets and let X = (A – B) – C
(d) None of these and Y = (A – C) – (B – C) [2005, 1 mark]
14. The inclusion of which of the following sets into Which one of the following is true?
S = {{1, 2}, {1, 2, 3}, {1, 3, 5}, {1, 2, 4}, {1, 2, 3, 4, 5}} is (a) X = Y (b) X Ì Y
necessary and sufficient to make S a complete lattice (c) Y Ì X (d) None of these
under the partial order defined by set containment? 23. Let S = {1, 2, 3, ...., m}, m > 3. Lt X1,..., Xn be subsets of S
[2004, 2 Marks] each of size 3. Define a function f from S to the set of natural
(a) {1} numbers as, f (i) is the number of sets Xj that contain the
(b) {1}, {2, 3} m
(c) {1}, {1, 3}
(d) {1}, {1, 3}, {1, 2, 3, 4}, {1, 2, 3, 5}
element i. i.e., f(i) = {j|i ÎXi}, then å f (i) is
i =1
15. The following is the incomplete operation table of a 4- [2006, 1 mark]
element group (a) 3m (b) 3n
* e a b c (c) 2m + 1 (d) 2n + 1
24. Let E, F and G be finite sets. Let X = (E Ç F) – (F Ç G) and Y
e e a b c
= (E – (E Ç G) – E – F). Which one of the following is true?
a a b c e [2006, 2 marks]
b (a) X Ì Y (b) X É Y
c (c) X = Y (d) X – Y ¹ f and Y – X ¹ f
Set Theory & Algebra S2-27
25. The set {1, 2, 4, 7, 8 ,11, 13, 14} is a group under multiplication 33. Consider the set S = {1, w, w2}, where w and w2 are cube
modulo 15. The inverse of 4 and 7. are respectively roots of unity. If * denotes the multiplication operation, the
[2006, 2 marks] structure {S, *} forms [2010, 1 mark]
(a) 3 and 13 (b) 2 and 11 (a) a group (b) a ring
(c) 4 and 13 (d) 8 and 14 (c) an integral domain (d) a field
26. The following is the Hasse diagram of the poset [{a, b, c, d,
e} £ 1]. The poset is [2006, 2 marks] 34. A binary operation Å on a set of integers is defined as
x Å y = x2 + y2. Which one of the following statements
a is true about Å ? [2013, 1 Mark]
(a) Commutative but not associative
(b) Both commutative and associative
(c) Associative but not commutative
b e (d) Neither commutative nor associative
d
35. Let X and Y be finite sets and f : X ® Y be a function.
Which one of the following statements is TRUE?
[2014, Set-3, 1 Mark]
[{a, b, c, d, e}£ 1] (a) For any subsets A and B of X, |f (A È B)| = |f (A)| + |f (B)|
c (b) For any subsets A and B of X, f (A Ç B) = f (A) Ç f (B)
(c) For any subsets A and B of X, |f (A Ç B)| = min {|f (A)|,
(a) not a lattice |f (B)|}
(b) a lattice but not a distributive lattice (d) For any subsets S and T of Y, f –1 (S Ç T) = f –1 (S) Ç f –1 (T)
(c) a distributive lattice but not a Boolean algebra 36. Consider the set of all functions f : {0, 1, ..., 2014} ® {0, 1, ...,
(d) a Boolean algebra 2014} such that f (f (i)) = i, for all 0 £ i £ 2014. Consider the
27. Let A, B and C be non-empty set and let X= (A – B) – C and following statements:
Y = (A – C) – (B – C). Which one of the following is true? P. For each such function it must be the case that for
(a) X = Y (b) X Ì Y [2006, 2 marks] every i, f (i) = i.
(c) Y Ì X (d) None of these Q. For each such function it must be the case that for
28. The set {1, 2, 3, 5, 7, 8, 9} under multiplication modulo 10 is some i, f (i) = i.
not a group. Given below are four possible reasons. Which R. Each such function must be onto.
one of them is false? [2006, 1 mark] Which one of the following is CORRECT?
(a) It is not closed [2014, Set-3, 2 Marks]
(b) 2 does not have an inverse (a) P, Q and R are true
(c) 3 does not have an inverse (b) Only Q and R are true
(d) 8 does not have an inverse (c) Only P and Q are true
29. Let X, Y, Z be sets of sizes x, y and z respectively. Let (d) Only R is true
W = X × Y and E be the set of all subsets of W. The number
of functions from Z to E is [2006, 1mark] Numerical Answer Questions
(a) z (b) z × 2xy
37. Let S denote the set of all functions f: {0, 1}4 ® {0,1}.
(c) z2 (d) 2xyz
Denote by N the number of functions from S to the set
30. Let S be a set of n elements. The number of ordered pairs in
{0,1}. The value of log2 log2 N is ________ .
the largest and the smallest equivalence relations on S are
[2014, Set-1, 2 Marks]
[[2007, 1mark]
38. A pennant is a sequence of numbers, each number being 1
(a) n and n (b) n2 and n
or 2. An n-pennant is a sequence of numbers with sum
(c) n and 0 (d) n and 1 equal to n. For example, (1, 1, 2) is a 4-pennant. The set of all
31. Consider the binary relation R = {(x, y), (x, z), (z, x), (z, y)} on possible 1-pennants is {(1)}, the set of all possible
the set {x, y, z} which one of the following is true? 2-pennants is {(2), (1,1)}and the set of all 3-pennants is
(a) R is symmetric but not anti-symmetric[2009, 1mark] {(2,1), (1,1,1), (1,2)}. Note that the pennant (1,2) is not the
(b) R is not symmetric but anti-symmetric same as the pennant (2,1). The number of 10-pennants is
(c) R is both symmetric and anti-symmetric ______________. [2014, Set-1, 2 Marks]
(d) R is neither symmetric nor anti-symmetric 39. If V1 and V2 are 4-dimensional subspaces of a 6-dimensional
32. What is the possible number of reflexive relations on a set vector space V, then the smallest possible dimension of
of 5 elements? [2010, 1 mark]
V1 Ç V2 is ______. [2014, Set-3, 1 Mark]
(a) 210 (b) 215
(c) 220 (d) 225
S2-28 Set Theory & Algebra
Condition 3 The identity is Î or empty string In a complete lattice L, every non-empty subset of
because for any string w Î å*, L, has both LUB and GLB.
Îw=wÎ=w
Now, since Î belongs to å*, identity exists. Now add {1}. The hasse diagram now becomes
Condition 4 There is no inverse exist for å* because
any string w Î å, there is no string w–1 such that
w. w–1 = Î. {1, 2, 3, 4, 5}
So, å* with the concatenation operator for strings
doesn’t form a group but it does form a monoid.
12. (b) T(1) = 1
{1, 2, 3} {1, 2, 4}
T(2) = T(1) + êë 2 úû {1, 3, 5}
=1+1=2
T(3) = T(2) + êë 3 úû {1, 2}
=2+1=3
T(4) = T(3) + êë 4 úû {1}
=3+2=5
T(5) = T(4) + êë 5 úû Now the above hasse diagram represents a complete
=5+2=7 lattice, since every non-empty subset has both LUB
and GLB.
T(6) = T(5) + êë 6 úû
15. (d) From given table,
=7+2=9 e* a = a, e* b = b, e* c = c
T(7) = 9 + 2 = 11
Þ e is the identity element,
T(8) = 11 + 2 = 13
\ a* e = a, b * e = b, c * e = c
T(9) = 13 + 9 = 16 and so on till. Again from given column, we have
T(16) = 16 + 6 ´ 3 + 4 = 38
\ T(1) = 1, T(4) = 5, T(9) = 16 and T(16) = 38. a*c=e
Choice (a) does not satisfy T(16). \ c*a=e
Choice (c) does not satisfy T(4). (If a is the inverse of c then c is the inverse of a)
Choice (d) does not satisfy T(1). \ First two elements of the last row will be ce.
\ Answer is choice (b) which satisfies T(1) upto
16. (b) S = {(x, y) | y = x + 1 and x, y Î{0, 1, 2,.....}}
T(16).
= {(0, 1), (1, 2), (2, 3), (3, 4),....}
13. (a) P ® (Q Ú R) º P ® QÚR
Now let T1 be the reflexive closure of S.
= P¢ + Q + R
T = {(0, 0), (1, 1), (2, 2), (3, 3)...}
(P Ù Q) ® R º PQ ® R
È {(0 ,1), (1, 2), (2, 3), (3, 4)....}
º (PQ)¢ + R
= {(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3) (3, 3), (3, 4)....}
º P¢ + Q¢ + R
Let T2 be the transitive closure of S.
\ P ® (Q Ú R) ® (P Ù Q) ® R
(0, 1), (1, 2) Î S Þ (0, 2) Î T2
º (P¢ + Q + R) ® P¢ + Q¢ + R
º (P¢ + Q + R)¢ + P¢ + Q¢ + R (0, 2), (2, 3) Î S Þ (0, 3) Î T2
º PQ¢ R¢ + P¢ + Q¢ + R (By absorption rule) (0, 3), (3, 4) Î S Þ (0, 4) Î T2
º P¢ + Q¢ + R and so on....
14. (a) The hasse diagram of the given poset is Also, (1, 2), (2, 3) Î S Þ (1, 3) Î T2
{1, 2, 3, 4, 5} (1, 3), (3, 4) Î S Þ (1, 4) Î T2
(1, 4), (4, 5) Î S Þ (1, 5) Î T2
and so on....
\ T2 = {(0, 1), (0, 2), (0, 3),....,(1, 2), (1, 3), (1, 4),...}
{1, 2, 3} {1, 2, 4}
{1, 3, 5} Now the reflexive, transition closure of S will be
T3 = T1 È T2
= {(0, 0), (0, 1), (0, 2)...., (1, 1), (1, 2)},
{1, 2} (1, 3)...(2, 2) (2, 3), (2, 4)....} and so on
S2-30 Set Theory & Algebra
i.e., 16
( ) = 16
(ii) × is an associative operation. 16
Þ log2log2 2 2
(iii) 1 Î S is the identity element.
(iv) 1–1 = 1, w–1 = (w2) –1 = w 38. 89
\ Inverse axiom is satisfied on given set. A 10 percent will be a sequence of any no. of 1s and 2s such
\ (S, *) is a group that sum is 10.
34. (a) A binary operation Å on a set of integers is defined p.g. (1, 1, 2, 2, 1, 1, 2) is a 10 pennant.
I. When sequence contains all 1s:
as x Å y = x2 + y2 no. of such pennants = 1 (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
x Å y = x2 + y2 II. When sequence contains Eight 1s and one ‘2’ : (8 × 1, 1
y Å x = y2 + x2 × 2)
= x2 + y2 (Q Addition is commutative) 9!
\ Å is commutative. no. of such pennants = 9C1 = =9
1!8!
(x Å y) Å z = (x2 + y2) Å z = (x2 + y2)2 + z2 III. When sequence contains six 1s and Two 2s :
x Å (y Å z) = x Å (y2 + z2) = x2 + (y2 + z2)2 6 × 1, 2 × 2 (e.g. 1, 1, 1, 1, 1, 1, 2, 2,)
Clearly, (x Å y) Å z ¹ x Å (y Å z)
18!
\ Å is not associative. no. of pennants = 18C2 = = 28
Hence, Å is commutative but not associative. 2!6!
35. (d) f : X ® Y defined as f (a) = 1, f(b) = 1, f(c) = 2 IV. When sequence contains 4 1s and 3 2s:-
where, X = {a, b, c} 4 × 1, 3 × 2 (e.g. (1, 1, 1, 1, 2, 2, 2))
Y = {1, 2} 7!
Let A = {a, c}, B = {b, c} be subsets of X no. of pennants = 7C3 = = 35
3!4!
(A) | f (A È B) |= 2 V. When sequence contains 2 1s and 4 2s :
| f (A) |= 2 :| f (B) |= 2 2 × 1, 4 × 2 (e.g. (1, 1, 2, 2, 2, 2,))
\ (A) is false 6!
no. of pennants = 6C4 = = 15
(B) f (A Ç B) = {i} 4!2!
VI. When sequence contains 5 2s and no. 1s:
f(A) = {1, 2) ; f{B} = {1, 2}
no. of pennants = 1 (i.e. (2, 2, 2, 2, 2))
f(A) Ç f (B) = {1, 2}
Total no. of 10 pennants
\ (B) is false.
= 1 + 9 + 28 + 35 + 15 + 1 = 89.
(C) | f (A Ç B) |= 1 39. 2
\ (C) is false. Let the vector space, V be {a, b, c, d, e, f}
(D) is true For smallest possible dimension of V1 Ç V2 ,
36. (b) Consider a function as :
f (0) = 1, f (1) = 0, f (2) = 3, f (3) = 2, ...., f (2012) = 2013, V1 = {a, b, c, d} and V2 = {c, d, e, f}
f (2013) = 2012 and f (2014) = 2014 \ V1 Ç V2 = {c,d}
Clearly f (f (i)) = i for 0 < i < 2014 \ Smallest possible dimension = 2
Here f (i) ¹ i for every i and f (i) = i for some i
Also f is onto
Hence, only Q and R are true
Combinatorics S2-33
4 Combinatorics
Chapter
n!
IMPORTANT RESULTS = n( n 1)(n 2)....(n r 1) ways ways n
Pr ways.
[ n r ]!
n
1. P0 1, n Pn n!; n
C0 1, n
Cn 1 The above formula for nPr involves following conditions :
n
1. All the things are distinct.
2. Pr r! n C r
2. Repetition of things is not allowed in any of the
n arrangements.
3. Pr r.n 1 Pr 1
n 1
Pr n. n 1Pr 1
3. No arrangement is repeated.
4. If r s n , then nPs is divisible by nPr. 4. The arrangement is linear.
RESULT - 2 : The number of permutations of 'n' things taken all
n n n 1
5. Cr Cr 1 that is, r. n C r n . n 1C r 1 and at a time.
r
This will be given by above formula after taking r = n.
n
Cr n 1
Cr 1 Thus, required number of ways = nPn = n!
r 1 n 1 RESULT - 3 : To find the number of permutations of 'n' things
taken all at a time, when 'p' are alike of one kind, 'q' are alike of
Second, 'r' alike of Third, and so on :
S2-34 Combinatorics
Let 'x' be the required number of permutations. 6. Number of ways of arranging n objects on a circle taking r
If p alike things are replaced by p distinct things, which are also at a time
different from others, then without changing the positions of n
Pr
other things these new p-things can be arranged in p! ways. = , if clockwise and anticlockwise arrangements are
r
Each of 'x' permutations will give p! permutations. Thus the total
distinct
number of permutations now are x (p!)
With a similar argument for 'q' - alike and 'r' - alike things, we get n
Pr
= , if clockwise and anticlockwise arrangements cannot
that if all things are different the number of permutations would 2r
be x(p!) (q!) (r!) be distinguished.
But number of permutations of 'n' distinct things; taken all at a
COMBINATIONS :
n!
time = nPn = n!, thus, ( x) p! q! r! n! x Each of the selections that can be made with a given number of
p! q! r!
objects taken some or all of them at a time is called a
RESULT - 4 : To find the number of Permutations of 'n' different COMBINATION.
things, taking 'r' at a time, when each thing can be repeated 'r' RESULT-1 : To find the number of combinations of 'n' dissimilar
times: things taken 'r' at a time :
In the problem we have to fill 'r' vacant places with 'n' things with
n!
repetition. Obviously, each place can be filled in 'n' ways, leaving = nCr
r !(n r )!
again n ways for the other place.
Hence, the number of ways of filling r-places with 'n' things = n Thus, the total number of combinations of 'n' dissimilar things
× n × n × ....... × n (r factors) = n r taken 'r' at a time is nCr.
RESULT - 5 : Number of circular permutations of 'n' distinct The number of combinations of 'n' dissimilar things taken all at a
objects : time = nCn = 1.
The total number of circular permutations of 'n' distinct things is RESULT-2 : To find the number of Combinations of 'n' different
(n – 1)!. things taking some or all at a time :
If no distinction is made between anti-clockwise and clockwise n n n n
C1 C2 C 3 .............. Cn 2n 1
1
arrangements, then the number of permutations is (n – 1)! RESULT-3 : The number of selections of some or all out of (p +
2
q + r + ..... ) things out of which p are alike of one kind, q - alike
CONDITIO NAL PERMUTATIONS of second kind and so on :
1. Number of permutations of n things taking r at a time, when The total number of required ways
a particular object is to be always included in each = = (p + 1) (q + 1) (r + 1) ...... – 1
RESULT-4 : The number of selections of one or more things
r . n 1Pr 1 .
from 'p' identical things of one kind, 'q' identical things of a
2. Number of permutations of n things taking r at a time, when second kind, 'r' identical things of a third kind and 'n' different
n 1 things
a particular object is never taken in any arrangement = Pr .
The total number of required ways
3. Number of permutations of n different things taking all at a = (p + 1) (q + 1) (r + 1) 2n – 1
time, when m specified things always come together
C O U NT I N G
= m!(n m 1)! .
Basic Counting Rules.
4. Number of permutations of n different things taking all at a
There are two basic counting rules which can be used to solve
time, when m specified things never come together
many different counting problems.
= n! m!(n m 1)!
(i) Sum Rule : If first task can be done in n 1 ways and a second
5. Number of permutations of n different things taking r at a task in n2 ways, and if these tasks are such that they cannot
time, in which two specified objects always occur together be done at the same time, then there are n 1 + n2 ways to do
= 2! ( r 1) n 2 Pr either task.
2
Combinatorics S2-35
(ii) Product Rule : Whenever a procedure can be broken down 5. Let A(z) be the generating function of a. Then,
into two tasks and then there are n1 ways to do the first z–i[A(z) – a0 – a1z – a2z2 – ...–ai–1 zi–1]
task and n 2 ways to do the next task after the first task has is the generating function of S–i a.
been done, then there are n1n2 ways to do the procedure. e.g., The generating function of ar = 3r+2, z ³ 0 is
GENERATING FUNCTION æ 9z 2 ö
æ 1 ö 9
A( z ) = z -2 ç - 1 - 3z ÷ = z -2 ç ÷÷ =
The generating function for the sequence a1, a2, ...., ar, .... of real è 1 - 3z ç
ø è 1 - 3z ø 1 - 3z
numbers of a numeric functions (a0, a1, a2, ...ar,...) is the infinite
series. 6. For b = Da, the generating function is given by
A(z) = a0 + a1z + a2z2 + ...+ arzr + ... 1
B(z) = [A(z) - a 0 ] - A(z)
n z
A(z) = å a r z r and for b = Ñ a
r =1
B(z) = A(z) – z A(z)
Some Results 7. Let C = a*b, i.e., C is the convolution of two numeric
1. Let a and b are any two discrete numeric functions and b = functions and its generating function
aa, then C (z) = A(z) · B(z)
B(z) = a A(z) Cr = a 0br + a1br -1 + a 2b r - 2 + ... + a r -1b1 + a r b0
where B(z) is the generating function corresponding to is the coefficient of zr in the product of
numeric b and A(z) is that of a.
e.g., The generating function of the numeric function
(a 0 + a1z + a 2 z 2 + ... + a r z r + ...)(b0 + b1z + b 2z 2 + ... + b r z r + ...)
a r = 5 × 2r r ³ 0
RECURRENCE RELATIONS
1
is A(z) = 5 × A recurrence relation for the sequence {ar} is an equations that
1 - 2z
expresses ar in terms of one or more of the previous terms of the
2. For any three discrete numeric functions a, b and c, if c = a +
sequence.
b, then C(z) = A(z) + B(z) is the generating function
A sequence is called a solution of a recurrence if its terms satisfy
representation.
the recurrence relation.
e.g., The generating function of the numeric function
e.g., The recurrence relation ar = ar–1 + 3 with initial condition
ar = 1r + 2r (r ³ 0)
a1 = 2 defines the sequence {2, 5, 8, 11...}.
1 1 Order of recurrence relation : The order of a recurrence relation
is A(z) = +
1 - z 1 - 2z (or difference equation) is the difference between the largest
3. Let a be a numeric function and A(z) its generating function. and smallest subscript appearing in the relation.
Let b be a numeric function such that e.g., ar = ar–1 + ar–2 is a recurrence relation of order 2.
br = arar Degree of the recurrence relation : The degree of a recurrence
Then, the generating function of b is relation is the highest power of a r occuring in that relations.
¥ ¥ Example a 3r + 3a r2-1 + 6a r4-2 + 4a r -3 is a recurrence relation of
B(z) = å b r z r = å (a r a r )z r
r =0 r =0 degree 3.
Linear recurrence relation with constant coefficients : A
¥
= å a r (az) r = A(az) recurrence relation of the form.
r =0 C0 a r + C1a r -1 + C2 a r -2 + C3arr -3 + ... + Ck a r -k = f (r) ...(i)
B(z) = A(az) Where, Ci’s are constants is called a linear recurrence relation
e.g., The generating function of the numeric function with constant coefficients of kth order, provided C0 and Ck both
1 are non-zero. f(r) is the function of the independent variable ‘r’
ar = 1, r ³ 0 is A(z) = only.
1- z
4. Let A(z) be the generating function of a. Then, z1 A(z) is e.g., 3ar + 6ar–1 = 2r is the first order linear recurrence relation
the generating function of Sia for any positive integer i. with constant coefficients.
A recurrence relation is said to be linear if it's degree is one.
S2-36 Combinatorics
Homogeneous Solution of the Recurrence Relation A characteristic equation of kth degree has k characteristics
A homogeneous solution of a linear difference equation with roots. Two cases of the roots may arise.
constant coefficients is of the form A 1r , where 1 is called a (i) If roots are distinct and real. Then
characteristic root and A is a constant determined by the bounded
a (h)
r A1 r
1 A2 r
2 + ... + A k r
k
conditions. Consider a recurrence relation in the form
C0 a r + C1a r 1 + C2 a r 2 + ... + ..Ck a r k =0 ...(i) (ii) If the roots are multiple roots. Let 1 be a root of
r multiplying m, then
Since, right hand side of Eq. (i) is set to zero, we substitute A
for ar. Eq. (i) become (A1r m 1 + A 2r m 2
+ ... + A m 1r + A m ) r
1
r r 1 r 2 r k is a homogeneous solution.
C0 A C1A C2A + .. + Ck A =0
Note : Although, there is no question asked in past GATE exams
r k k k 1 k 2
A [C0 C1 C2 + ... + Ck ] = 0 from this chapter still, reading of this chapter would be
k k 1 k 2
helpful in future GATE exams.
C0 C1 C2 + ... + Ck = 0 ...(ii)
Eq. (ii) is called characteristic equation. The solutions of this
equaiton are called the characteristic roots of the recurrence
relation.
Graph Theory S2-37
5
Chapter
Graph Theory
Quick Revision Material
Step 1 : Choose any vertex v1 of G. Clearly, a graph may have many different maximal matchings and
Step 2 : Choose an edge e1=v1v2 of G such that v2 v1 and e1 of different sizes. Among these, the maximal matchings with the
has smallest weight among the edges of G incident with largest number of edges are called largest maximal matchings.
v1 . In Fig. (b), a largest maximal matching is shown in heavy lines.
Step 3 : If edges e1, e2, ......., ei have been chosen involving end The number of edges in a largest maximal matching called
points v1, v2, .....vi + 1. Choose an edge vi+1 = vjvk with matching number of the graph.
vj {vi ..........vi + 1} and vk [v1, ....... vi + 1] such that
COVERINGS
ei + 1 has smallest weight among the edges of G with
precisely one end in [v1, ......... vi + 1]. In a graph G a set g of edges is said to cover G if every vertex in
Step 4 : Stop after n – 1 edges have been chosen. Otherwise go G is incident on at least one edge in g. A set of edges that covers
to step 3. a graph G is called edge covering, covering subgraph, or simply
a covering of G.
CUT VERTICES AND CONNECTIVITY e.g. a graph G is trivially its own covering. Spanning tree in a
Cut vertex is analogue of a bridge. A vertex v of a graph is called connected graph (or a spanning forest in an unconnected graph)
a cut vertex of G if is another covering. Hamiltonian circuit (if it exists) in a graph is
(G – v) > (G), also a covering.
Where (G) are number of components in graph G, i.e. a cut
vertex breaks a graph into a subgraph having more connected
components, then G has
G–V
(a) (b)
Fig. Graph and two of its minimal coverings
(G) = 1 (G – v) = 3
Detection of Planarity
Fig. Graph after deleting cut vertex v
Every subgraph of a planar graph is planar and that every graph
which has non-planar graph is also non-planar. A disconnected
ISOMORPHISM OF GRAPHS graph is planar iff each of its components is planar. Similarly, in a
Let G(V, E) and G*(V*, E*) are graphs and f : V V* is a one-to- separable graph, planarity of each block can be considered
one correspondence beta sets of vertices such that [u, v] is an independently. Thus, a separable graph is planar iff each of its
block is planar. Thus, we need to consider only non-separable
edge of G if and only if {f (u), f(v)} is an edge of G*. Then f is
connected graph.
isomorphism between G and G*, and G and G* are called
isomorphic graphs. Normally, we do not distinguish between Colouring of Graphs
isomorphic graphs (even though their diagrams may “look A colouring of a graph G is an assignment of colours to its
different”). vertices such that no adjacent vertices have the same colour. A
given graph can be properly coloured in many different ways.
MATCH IN GS
We are finding the minimum number of colours with which a
Maximal Maching given graph can be properly coloured.
It is a matching to which no edge in the graph can be added. e.g., There are three different proper colouring of a graph with
e.g. in a complete graph of three vertices (i.e. a triangle) any single different number of colours.
edge is a maximal matching. The edges shown by heavy lines.
Yellow Yellow Red
k4 (n 2 3n) / 2
Q3 (n 2 n) / 2
(a) C (b) (n 2 n)C k
(n 2 3n) / 2
Which one of the following statements is true in relation to k =0
these graphs? [2011, 1 mark] n
(a) K4 is planar while Q3 is not (n 2 n)
(c) (n 2 n) / 2 (d) Ck
(b) Both K4 and Q3 are planar Cn 2
k =0
(c) Q3 is planar while K4 is not 10. The minimum number of colours require to colour the
(d) Neither K4 nor Q3 is planar following graph, such that no two adjacent vertices are
4. Which of the following graphs is isomorphic to given graph? assigned the same colour, is [2004, 2 Marks]
[2012, 2 marks]
(a) 2 (b) 3
(c) 4 (d) 5
(a) G1 : (b) G2 :
(c) (d)
b c d (c) 2 4 (d)
e 3 4
19. Let G = (V, E) be a graph. Define (G) i d d, where id
The poset is
d
(a) not a lattice is the number of vertices of degree d in G. If S and T are two
(b) a lattice but not a distributive lattice
(c) a distributive lattice but not a Boolean algebra different trees with (S) (T), then [2010, 1 mark]
(d) A Boolean algebra (a) |S| = 2|T| (b) |S| = |T| –1
(c) |S| = |T| (d) |S| = |T| +1
20. In a binary tree with n nodes, every node has an odd number
14. Let G(x) = 1/ (1 – x)2 = g(i)x i , where |x| < 1. What is of descendants. Every node is considered to be its own
i=0 descendent. What is the number of nodes in the tree that
g(i)? [2005, 2 Marks] have exactly one child? [2010, 2 marks]
(a) i (b) i + 1 (a) 0 (b) 1
(c) 2i (d) 2i n–2
(c) (d) n –1
15. Let G be a simple connected planar graph with 13 vertices 2
and 19 edges. Then, the number of faces in the planar 21. Let G be a complete undirected graph on 6 vertices. If
embedding of the graph is [2006, 1 mark] vertices of G are labeled, then the number of distinct cycles
of length 4 in G is equal to [2012, 2 marks]
(a) 0 (b) 8 (a) 15 (b) 30
(c) 9 (d) 13 (c) 90 (d) 360
16. Let G be a simple connected planar graph with 13 vertices 22. Let G be a simple undirected planar graph on 10 vertices
and 19 edges. Then, the number of faces in the planar with 15 edges. If G is a connnected graph, then the number
embedding of the graph is [2006, 1 mark] of bounded faces in any embedding of G on the plane is
(a) 0 (b) 8 equal to [2012, 1 mark]
(c) 9 (d) 13 (a) 3 (b) 4
17. Consider the DAG with V = {1, 2, 3, 4, 5, 6}, shown below: (c) 5 (d) 6
[2007, 1 mark]
Numerical Answer Questions
2 5
23. The maximum number of edges in a bipartite graph on 12
vertices is _________________. [2014, Set-2, 1 Mark]
24. The number of distinct minimum spanning trees for the
1 4 weighted graph below is _____ [2014, Set-2, 2 Marks]
2
2 1 2 1
3 6
Which of the following is not a topological ordering?
(a) 1 2 3 4 5 6 (b) 1 3 2 4 5 6 2 2
(c) 1 3 2 4 6 5 (d) 3 2 4 1 6 5 2 1
18. Consider the set S = {a, b, c, d}. Consider the following 4 1 1
partitions 1, 2, 3, 4 on S : 1 = {abcd } ,
2 2
2 {ab, cd}, 3 {abc, d}, 4 {a, b, c, d } 25. A cycle on n vertices is isomorphic to its complement. The
Let < be partial. value of n is _____. [2014, Set-2, 2 Marks]
Order on the set of partitions S = ( 1, 2, 3, 4) defined as 26. Let G be a group with 15 elements. Let L be a subgroup of G.
It is known that L G and that the size of L is at least 4.
follows : i < j if and only if i refines j. The poset
The size of L is __________. [2014, Set-3, 1 Mark]
diagram for (S , <) is [2007, 1 mark]
Graph Theory S2-41
CONCEPTUAL MCQs 2
1
1. (b) In a simple connected undirected graph (with more 3
than two vertices) atleast two vertices must have same 1
degree, since, if this is not true then all vertices would 4
have different degree. A graph with all vertices would 1
have different degree. A graph with all vertices having 2 2
different degrees is not possible to construct. Notice Consider option (c) :
that it is possible to construct graph satisfying choices Here, the same explanation as above given. This graph
(a), (c) and (d). is also not isomorphic.
2. (c) If an n-vertex simple contex simple connected graph
contains no cycles of odd length, then its chromatic
number is two, since the vertices cna be alternately 1 2
1 3
coloured with first colour, then the second colour, then
the first colour and then the second colour and so on. 3
Alternatively, since a simple connected graph with no 2
cycles of odd length must be bipartite and since, the 2 2
chromatic number of a bipartite graph is always 2 (in a
Consider option (d) :
bipartite graph each partition requires one colour (there
In this graph, there is a 4 length but in the original
are no edge within a partition of a bipartite graph) and
graph, there is no cycle of length 4. So this graph is
there are only two partitions).
not isomorphic.
2
2 1
2
3. (b) 4
1
K4 is planar 2 2
5. (c) P : Number of odd degree vertices is even.
Q : Sum of degrees of all vertices is even
Q is true
Explanation Calculating the sum of degrees of all
vertices.
Considering an edge, it is joining two vertices (not
necessarily distinct), hence 2 is the sum of degrees.
Hence, for ‘e’ edges, the sum of degrees of all
Q3 is planar
vertices is 2e (i.e., even)
Both K4 and Q3 is planar This is valid even in the case of self loops.
4. (b) The given graph is with degree of each node. P is true
Explanation Let us assume, number of odd degree
1 2 vertices is odd. So, the contribution of odd degree
2
vertices in total sum is odd.
1
Now, the contribution of even degree vertices is also
4 even (whether the number is even or odd).
2 Including vertex of degree zero in even degree
2 2 vertices.
Consider option (a) : So, total sum becomes odd, which is not possible.
In this graph, one vertex has degree of 3 but in the Hence, P is true.
original graph, there is no vertex of degree 3. So, this Both P and Q statements are ture for undirected
graph is not isomorphic. graphs. Hence answer is (c).
S2-42 Graph Theory
n2 n
= edges.
2
v
n 2 3n
From this, we need to choose edges or more
2
or a null graph of n vertices as shown below
n2 n
upto maximum .
2
v
n2 n
Taking =m
In either case, if node v is removed, the number of 2
components will be n – 1, where n is the total
number of nodes in the star graph. n 2 3n
and =p
n – 1 is the maximum number of components 2
possible. Minimum components will result, if the m – n = p, m – p = n
node being removed is a lone vertex in which case, Total number of such graphs
the nubmer of components will be K – 1. = mCp + mCp + 1 + mCp + 2 + …+ mCp + n
The number of components must necessarily lie = mCn + mCn – 1 + mCn – 2 + …+ mC0
between K – 1 nad n – 1. = mC0 + mC1 + mC2 + …+ mCn
7. (a) The number of perfect matchings in a complete
n
graph of n vertices, where n is even, reduces of the
problem of finding unordered partitions of the vertex =
k=0
set of the type p(2n; 2, 2, 2, ....n times)
n
(2n)! n2 n
n = Ck
(2!) n! k=0
2
For n =3, 2n = 6, i.e., complete garph K6, we have 10. (c) An assignment of the colors 1, 2, 3 and 4 to the
6! vertices of the graph is shown below such that the
Number of perfect matchings = graph is shown below such that the graph is
(2!) n n!
properly colored.
6 5 4 3 2 1
= = 15
2 2 2 6 3
8. (d) Given, |E| 3 |V| –6 2 1
2 |E| 6|V| – 12 ...(i) 4 4
Now degrees = 2|E| 3 2
If minimum degree = k, then degrees k|V|
i.e., 2|E| k |V| ...(ii) 1
From Eqs. (i) and (ii), we can say that
So, 4 colors are required.
k |V| 6 |V| – 12
11. (a) From figure (a)
Now substituting k = 3, 4 , 5 , 6 in order
k=3 3 |V| 6 |V| – 12
|V| 4 which is possible
k=4 4 |V| 6 |V| – 12
|V| 6 which is possible
k=5 5 |V| 6 |V| – 12
|V| 12 which is possible
k=6 6 |V| 6 |V| – 12 Touch each other.
which is not possible. So, not planar.
Minimum degree cannot be 6.
Graph Theory S2-43
2 3
e
The poset [{a, b, c, d, e}, ] is a lattice (since every
4
pair of elements has LUB and GLB) but it is not a
distributive lattice. Because distributive latice
satisfies the following conditions. For any x, y, z 19. (c) Given, S and T are two different trees with
x (y z) = (x y) (x z) (S) = (T)
x (y z) = (x y) (x z) 2|ES| = 2|ET|
where, and are meet and join operations but for (By handshaking theorem (G) = 2|EG|)
given poset [{a, b, c, d ,e} ] |ES| = |ET|
b (c d) = b a = b |S| – 1 = |T| – 1
(b c) (b d) = e e = e |S| = |T|
So, it is not distributive. (Also element b has 2 (In a tree |ES| = |S| – 1 and |ET| = |T| – 1, where |S| and |T|
complements c and d, which is not possible in the are numbers of vertices of trees S and T respectively).
distributive lattice, since, in a distributive lattice,
complement, if it exists, is always unique).
S2-44 Graph Theory
20. (a) A tree with 1 node is not possible, since it is given that r = e – v + 2, r = 15 – 10 + 2
every node has exactly 1 child. r=7
a Total number of regions in the given graph are 7 but
one extra region is unbounded and 6 are bounded.
Hence, answer is 6.
NUMERICAL ANSWER QUESTIONS
b 23. 36
Now, consider a tree with 2 nodes (0 is the root) (1) 1, 11 1 × 11 = 11 edges
Now, a has exactly one child, number of descendants (2) 2, 10 2 × 10 = 20 edges
of a = 2 but this contradicts the given fact that every (3) 3, 9 3 × 9 = 27 edges
node has an odd number of descendants. (4) 4, 8 4 × 8 = 32 edges
Now, consider a tree with 3 nodes. Since, every node (5) 5, 7 5 × 7 = 35 edges
has exactly one child, it must be of the form. (6) 6, 6 6 × 6 = 36 edges (maximum)
24. 6
a
a 2
b
2 1 2 1
c b c
Here, a has 3 descendants, b has 2 descendants and c 2 2
has one. Again we have contradiction in that b does
not have odd number of descendants. Similarly, we 1 1 2 1
can show that for tree with 4, 5, 6, ... nodes, it is not d e
possible to have all nodes with odd number of 2
2
descendants. So, correct answer is the trees has 0
nodes. Edges picked to make MST is given the double line.
21. (c) Here, given graph is a complete graph and we can In the right side of MST, we could either pick ‘d’ or ‘e’
choose any 4 vertices from given 6 vertices to make In the left side we could either pick ‘a’, ‘b’ or ‘c’ in MST.
cycle of length 4. There are two options for one edge to be picked and three
We can arrange 4 vertices in (4 – 1)! ways or 3! ways option for other edge to be picked.
because there is a cycle. Total possible MSTs = 2 × 3 = 6
Hence, number of cycles of length 25. 5
6! 6 5 1
4 = 6 × 6C4 = 6 =6 = 90 cycle a G b a b
4! 2! 2
a G b
22. (d) In any graph, bounded faces or bounded region and
unbounded regions are present. c c c c
For example d
d c
d b
2
1 G and G1 are complement and isometric to each other when
there are 5 vertices.
26. 5
In the above graph, there are 2 regions, 1 st is bounded As per Lagrange’s theorem, order of subgroup divides
region or bounded face graph and 2nd is unbounded. order of group
So, we have to calculate the regions of the graph. 3, 5 and 15 can be order of subgroup.
In the question, G is a simple undirected graph on 10 Given, L G it is not 15
vertices and 15 edges and G is connected garph, so and L is atleast 4 it is not 3
there are total number of regions (r). size of L is 5
Linear Algebra S2-45
6
Chapter
Linear Algebra
Quick Revision Material
1 x x2
1 3 4
1 3 5 24. Which one of the following does not equal 1 y y2 ?
18. Rank of the martix is [2008, 1 mark]
1 3 4 1 z z2
(a) 0 (b) 1
(c) 2 (d) 3 [2013, 1 mark]
5 0 2
1 x ( x + 1) x + 1 1 x + 1 x2 + 1
19. A 0 3 0 . The inverse of A is [2010, 1 mark] (a) 1 y ( y + 1) y + 1 (b) 1 y + 1 y 2 + 1
2 0 1 1 z ( z + 1) z + 1 1 z + 1 z2 + 1
1 0 –2 5 0 2
1 1 0 x – y x2 – y2 2 x + y x2 + y2
0 0 0 – 0
(a) 3 (b) 3 y2 – z 2
(c) 0 y–z (d) 2 y+z y2 + z2
–2 0 5 2 0 1
1 z z2 1 z z2
Linear Algebra S2-49
CONCEPTUAL MCQs 2 1 i
A
1. (b) A, B, C, D in n × n matrix. 1– i 6
Given ABCD = 1
2 1 i
ABCDD–1C–1 = D–1C–1 ( A )T = =A
AB = D–1C–1 1+ i 6
A AB = A–1D–1C–1
–1
A* = A
B = A–1D–1C–1 Hence A is a Hermitian matrix.
B = (A–1D–1C–1)–1
–1
0 a b
= (C–1)–1.(D–1)–1.(A–1)–1
= CDA 6. (b) Let A –a 0
c be non null skew symmetric
2. (c) In a symmetric matrix, the lower triangle must be the –b – c 0
mirror image of upper triangle using the diagonal as
matrix. Hence at least one out of a, b, c must not be
mirror. Diagonal elements may be anything. Therefore,
zero.
when we are counting symmetric matrices we count Let a 0 Then
how many ways are there to fill the upper triangle and
diagonal elements. Since, the first row has n elements, 0 a
a2 0
second row (n – 1) elements, third row (n – 2) –a 0
elements and so on upto last row, one element. Hence rank is 2. Thus in any case rank cannot be 1.
Total number of elements in diagonal + Upper 7. (a) For symmetric matrix,
triangle (AB) = AB;
= n (n – 1) + (n – 2) + ... + 1 B A = AB
n(n + 1) It is true only if A = A
= and B = B
2
BA = AB (which is given)
Now, each one of these elements can be either 0 or Hence AB will be symmetric if A and B are symmetric.
1. So total number of ways we can fill these elements 8. (b)
is 9. (a) If A is n × n ordered determinant
n(n +1) |KA| = Kn |A|
= power (2, (n 2 + n)/2) hence n = 4
2 2
Since, there is not choice for lower triangle elements | 2A | = 24 | A | = 16 | A |
the answer is power (2, (n 2 + n)/2) which is choice 10. (a) As per property, determinant of a matrix = product
(c). of eigen values
3. (d) Every entry will remove one row and one column If true of matrix is positive and determinant is
from further consideration of availability, since no negative, then atleast one of eigen values is
negative.
two entries should be in same row or column.
Proceeding in this way we can add a maximum of PROBLEM BASED MCQs
either a entries or b entries depending on which is
lesser, since if a < b we will run out of rows first and 2 1 4 x
if b < a we will run out of columns and if a = b then
11. (b) 4 3 12 y = 5
we run out of both rows and columns. Therefore,
maximum entries that can be added min {a, b}. 1 2 8 z 7
4. (b) Let A and B be orthogonal, then
AA = i and BB = I 2 1 4
Now, (AB) (AB) = (AB) (B A ) = A (BB ) A 4 3 12 , B = 5
A=
= A (I) A = AA = I 1 2 8 7
Similarly, (AB) (AB) = I
Hence AB is orthogonal [A : B]
2 1– i 2 1 4:
5. (d) Since A 4 3 12 : 5
1 i 6
1 2 8:7
Linear Algebra S2-51
1 5 : 1 0 7 5 : 7
1 1 : 2 3 9 0 : 5 1
[A : B] = R3 ¬ R3
1 3 : 3 0 21 3 : 4 3
0 4 : 1 0 7 5 : 7
R1 ¬ R1 + R 2
1 1 : 2 3 9 0 : 5
R3 R3 R2 R1 R1 R 3
0 4 : 1 0 7 1 : 4
3
0 0 : 0
1 1 : 2 0 0 6 : 25
R1 R1 R 3
0 4 : 1 3
R(A : B) = R(A) n(no. of unknowns) 3 9 0 : 5
Hence unique solution 0 7 1 : 4
13. (a) (i) The set H is closed, since multiplication of upper 3
triangular matrices will result only in upper
triangular matrix. R(A : B) = R(A) = n(no. of unknows)
(ii) Matrix multiplication is associative, i.e., A* (B*C) Hence, unique solution
= (A*B)*C.
S2-52 Linear Algebra
|A| = –1 1
By R 3 (R 3 –R 2 )
T 3
0 0 1
0 0 0 a+b+c
A–1 = ( 1) 0 1 0
1 0 0 ~ 1 –2 1 b
0 1–1 1
(c – b)
0 0 1 3
( 1) 0 1 0 Hence (A : B) = 3, If a + b + c 0
A–1 =
1 0 0 and (A) = 2.
then (A : B) (A)
0 0 1 Hence given equations are inconsistent if
a+b+c 0
0 1 0 Hence given equations have no solution if
A –1 =
1 0 0 (a + b + c) 0
Linear Algebra S2-53
2 –2 –4
1 x x2
21. (d) Since A –1 3 4 C2 C2 + C1
24. (a) 1 y y2
1 –2 –3
1 z z2
therefore
2 –2 –4 2 –2 –4
1 x + 1 x2 1 x + 1 x2 + 1
A.A= –1 3 4 –1 3 4
C3 C3 + C1
1 –2 –3 1 –2 –3 1 y 1 y2 1 y + 1 y2 + 1
1 z + 1 z2 1 z +1 z2 + 1
2 –2 –4
–1 3 4 A i.e., option (b)
1 –2 –3
1 x x2 2 x+ y x2 + y 2
A2 = A R1 R1 + R2
1 y y2 2 y+ z y2 + z2
Hence A is an idempotent matrix. R2 R2 + R3
1 z z2 1 z z2
1 1
22. (d) A=
1 12 2
i.e., option (d)
A I =0
1 x x2 0 x y x2 y2
The determinant of the given matrix R1 R1 R2
1 y y2 0 y z y2 z2
R2 R2 R3
1 1 1 0
det =0 1 z z2 0 z z2
1 1 0 1 ÷
i.e., option (c)
1 1 We are able to generate option (b), (c) and (d) from
det 0
1 1 given matrix.
Considering option (a):
1 1
0 1 x( x + 1) x +1
1 1
C3 C3 C1
1 y ( y + 1) y +1
2
1 1 0 1 z ( z + 1) z +1
2
2
2 1 x2 + x x 1 x2 x
2 C2 C2 C3 2
Eigen values are 2 and 2 of A. If A has eigen 1 y y y 1 y y
2 2
values 1, 2 ....... k then An will have eigen values 1 z +z z 1 z z
n n n
1 , 2 ,... k . Option (a) is obtained from the given matrix by
interchanging column 2 and 3.
Eigen values of A19 are ( 2)19 and ( 2)19 , On interchanging any two columns of a matrix, its
hence 512 2 and 512 2 . determinant gets multiplied by “– 1”.
23. (d) For unique solution,
1 x x2 1 x ( x + 1) x +1
1 1 2
1 y y2 1 y ( y + 1) y +1
1 2 3 0
1 z z2 1 z ( z + 1) z +1
1 4 a
1(2a – 12) – 1 (a – 3) + 2(4 – 2) 0 Hence option (a) is NOT equal to the given matrix.
a 5 25. (c) Both I and II.
S2-54 Linear Algebra
1 0 0 0 1
1 1 1 3
0 1 1 1 0
0 4 3 11
0 1 1 1 0
0 1 3 8 R2 R2
A= 0 1 1 1 0
0 3 6 3 R3 R3
1 0 0 0 1
1 1 1 3
0 4 3 +1 x1
0 1 3 8 x2
0 3 6 3 R2 R3 x3
X= x
4
1 1 1 3
x5
0 1 3 8
0 4 3 11 R3 R 3 4R 2 A =X
x1 + x5 = x1 = x5 & x2 + x3 + x4 = x2 = x4
0 3 6 3 R4 R 4 3R 2 I Case
0
1 1 1 3 Let x1 = x5 = a
0 1 3 8 x2 = x3 = x4 = b
0 0 15 21 x1 + x5 = x1
2a = a =2
0 0 15 21 R 4 R 4 + R3
x2 + x3 + x4 = x2
3b = b
1 1 1 3 =3
0 1 3 8 II Case
0 0 15 21 =0
Eigen value = 0
0 0 0 0 There are three eigen values i.e, 2, 3, 0
Clearly, Rank (A) = Rank (AB) = 3 Product of non zero eigen values = 2 × 3 = 6
As number of variables in given system = 3
Numerical Methods S2-55
7
Chapter
Numerical Methods
Quick Revision Material
1. Newton-Raphson Method 3. Simpsons 3/8th rule
We have find the solution of f (x, y) = 0 and g (x, y) = 0 x0 nh 3h
First find an approximate solution of equation (x0, y0) by f ( x) dx = [(y0 + yn) + 3(y1 + y2 + y4 + ... + yn–1)
x0 8
graphical or trial and error method.
+ 2(y3 + y6 + y9 + ... + yn–3)]
From this we find more approximate values (x1, y1) such that
x 1 = x0 + h and y1 = y0 + k Solution of Differential Equations
f (x0 + h, y0 + k) = 0 and g (x0 + h, y0 + k) = 0 1. Runge-Kutta method
From Taylor’s series we get, The rule for finding the increment k of y corresponding to
f f g g the increment h of x.
f0 h k = 0 and g0 h k =0
x0 y0 x0 y 0 dy
=f (x, y) ; y (x0) = y0
Solving these equations we get h and k. dx
Thus we find x1 and y1 Calculation is done as follows :
From this value of x1 and y1 we find x2 and y2 in similar way
h1 k1
k1 = h f (x0, y0), k2 = hf x0 , y0
2. Bisection Method 2 2
For a non linear equation f (x) and for any two number a and
b if f (a), f (b) > 0, then there is atleast one root for the h k2
k3 = hf x0 , y0 , k4 = hf (x0 + h, y0 + k3)
equation f (x) in between a and b. 2 2
Now let x1 = a and x2 = b
1 1 1
We find the mid point of x1 and x2 i.e. x0 k= (k + 2k2 + 2k3 + k4) = (k1 + k4) + (k2 + k3)
6 1 6 3
x1 x2
x0 = The approximate value, y1 = y0 + k
2 2. Taylor’s series method
If f (x0) = 0, x0 is the root dy
If f (x0) f (x1) < 0, root is in between x0 and x1 Given = y = f (x, y) and f (x0) = y0
If f (x0) f (x2) < 0, root is in between x0 and x2 dx
By taylor’s theorem the series about a point x = x0
and this process in continued with either (x0, x1) or with
(x0, x2). ( x x0 )
y = y0 + (x – x0) (y )0 + (y ......
2!
NUMERICAL I NTEGRATIONS From this equation we can find y1 of y for x = x1 and then y ,
1. Trapezoidal method rule y , y are found out.
According to trapezoidal rule for evaluating a definite 3. Euler’s method
integral, dy
Given = y = f (x, y) and y(x0) = y0
x0 nh h dx
f ( x ) dx =
[( y0 yn ) 2( y1 y2 ...... yn 1 )] when h 0, by Taylor’s series
x0 2 y(x + b) = y (x) + h y (x) = y(x) + h f (x, y)
2. Simpsons 1/3rd rule Thus, yn+1 = yn h f( xn, yn)
x0 nh h x x
f ( x) dx = [( y0 yn ) 4( y1 y3 ...... yn 1 ) where, h= n 0 i.e. (xn = x0 + nh)
x0 3 n
2 ( y2 y4 ...... yn 2 )]
S2-56 Numerical Methods
2
1 f(x) d
1. The value of dx computed using Simpson's rule with
x 1,0 (2.05, 1.0)
1 a (1.55, 0.5)
a step size of h = 0.25 is [2007, 2 marks] (0.5, 0.5)
(a) 0.69430 (b) 0.69385
(c) 0.69325 (d) 0.69415
2. Equation ex – 1 = 0 is required to be solved using Newton's x1 1.3
method with an initial guess x0 = –1. Then, after one step of x0 0.6 1.55 x2 2.05
Newton's method, estimate x1 of the solution will be given
b c
by [2008, 1 mark]
(a) 0.71828 (b) 0.36784
(c) 0.20587 (d) 0.000
3. Let x2 – 117 = 0. The iterative steps for the solution using (0.8, –1.0)
Newton-Raphson's method is given by [2009, 1 mark]
1 117 If we use the Newton-Raphson method to find the roots
(a) xk 1 2 xk x of f (x) = 0 using x0, x1 and x2 respectively as initialguesses,
k
the roots obtained would be [2013, 2 marks]
117
(b) xk 1 xk – (a) 1.3, 0.6 and 0.6 respectively
xk (b) 0.6, 0.6 and 1.3 respectively
xk (c) 1.3, 1.3 and 0.6 respectively
(c) xk 1 xk –
117 (d) 1.3, 0.6 and 1.3 respectively
1 117 8. In the Newton-Raphson method, an initial guess of x0 = 2 is
(d) d k 1 xk – 2 xk x made and the sequence x0, x1, x2 ... is obtained for the function
k 0.75x3 – 2x2 – 2x + 4 = 0
4. Newton-Raphson method is used to compute a root of the Consider the statements
equation x2 – 13 = 0 with 3.5 is the initial value. The (I) x3 = 0.
approximation after one iteration is [2010, 2 marks] (II) The method converges to a solution in a finite number
(a) 3.575 (b) 3.677
of iterations.
(c) 3.667 (d) 3.607
Which of the following is TRUE? [2014, Set-2, 2 Marks]
5. The bisection method is applied to compute a zero of the
(a) Only I (b) Only II
function f (x) x 4 x3 x 2 4 in the interval [1, 9]. The (c) Both I and II (d) Neither I nor II
method converges to a solution after ...... iterations. 9. With respect to the numerical evaluation of the definite
[2012, 2 marks] b 2
(a) 1 (b) 3 integral, K = x dx , where a and b are given, which of the
a
(c) 5 (d) 7 following statements is/are TRUE ?
6. Function f is known at the following points: (I) The value of K obtained using the trapezoidal rule is
always greater than or equal to the exact value of the
x 0 0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3.0 definite integral.
f (x) 0 0.09 0.36 0.81 1.44 2.25 3.24 4.41 5.76 7.29 9.00 (II) The value of K obtained using the Simpson’s rule is
always equal to the exact value of the definite integral.
3 [2014, Set-3, 2 Marks]
The value of f ( x ) dx computed using the trapezoidal
0 (a) I only (b) II only
rule is [2013, 1 Mark] (c) Both I and II (d) Neither I nor II
(a) 8.983 (b) 9.003
(c) 9.017 (d) 9.045
Numerical Methods S2-57
e xk –1 e xk .xk – e xk + 1 3 1
xk +1 = xk – = ...(i) xn 1 2
e xk e xk 2
f(2) = 0
But at (k = 0), x0= – 1
So, we get solution in 3rd iteration.
( x0e x0 – e x0 1) – e –1 – e –1 1 6. (d) Function f is known at the following points using the
x1 –1
x0
e e 3
trapezoidal rule to compute f ( x)dx
–2 + e
= 0.71828 ( e = 2.71828) 0
1
3. (a) Let f (x) = x2 – 117 = 0
and f (x) = 2x x 0 0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3.0
Now, by Newton-Raphson method f (x) 0 0.09 0.36 0.81 1.44 2.25 3.24 4.41 5.76 7.29 9.00
f ( xk )
xk 1 xk –
f ( xk )
9.00
x 2 – 117
xk xk – k
f (x)
1
2 xk
0.36
2 xk2 – xk2 117 0.09
2 xk
O 0.3 0.6 0.9 3.0
xk2 117 1 117 x
xk
2 xk 2 xk
S2-58 Numerical Methods
1 let a = 0, b = 1
= (Base 1 + Base 2) × (Height) let n = 4
2
b a 1 0
1 h= = = 0.25
= (0.09 + 0.36) × (0.6 – 0.3) n 4
2
Also, observe that each value of f (x) except x = 3.0 y0 y1 y2 y3 y4
is included in two different regions. x 0 0.25 0.5 0.75 1
3 1
f ( x )dx (0.3) (0.09) y = x2 0 0.625 0.25 0.5625 1
0 2
By Trapezoidal rule
1 1
(0.3) (0.09 + 0.36) + .... (0.3) (7.29 + 9.0) 1
2 2 h
x 2 dx =
2
( y0 + y4 ) + 2(y1 + y2 + y3 )
1 0
= (0.3) (0.09 + 0.36 + 0.81 + 1.44 + 2.25
2
0.25
1 = [(0 + 1) + 2(0.0625 + 0.25 + 0.5625)]
+ 3.24 + 4.41 + 5.76 + 7.29) (0.3) (9.00) 2
2 = 0.34375
= 7.695 + 1.35 = 9.045
1
7. (d) Equation of line a is By Simpson’s rule
3
1 0.5
y–1= (x 0) 1
0 0.5 h
x 2dx =
3
( y0 + y4 ) + 2(y2 ) + 4(y1 + y3 )
y=–x+1 0
This line cuts x-axis at x = 1. Clearly, a perpendicular
at x = 1 will cut the line c and not line b. 0.25
= [(0 + 1) + 2(0.25) + 4(0.0625 + 0.5625)]
x0 = 1.3 3
The perpendicular at x = x1 cutting line b.
1
x1 = 0.6 =
Equation of line d is 3
Exact value of integral is :
1 0.5
y – 0.5 = (x 1.55) 1 1
2.05 1.55 2 x3 1
x dx = =
i,e., y = x – 1.05 3 3
0 0
Clearly perpendicular at x = 1.05 will cut the line c
and not line b.
x2 = 1.3
So, starting from x0, x1 and x2 the roots will be 1.3,
0.6 and 1.3.
Calculus S2-59
8
Chapter
Calculus
Quick Revision Material
Important Limits a £ x £ b, and derivable in open interval (a, b) i.e. a < x < b,
sin x tan x and if f (a) = f (b), then there exist atleast one real c in (a, b)
1. lim = lim = lim cos x = 1 such that f ¢(c) = 0
x®0 x x ®0 x x® 0
2. Lagrange’s first mean value theorem
x If a function f (x) is continuous in closed interval [a, b] and
æ 1ö
2. lim (1 + x )1/ x = lim ç 1 + ÷ = e f ’(x) exist in open interval (a, b) then there exist atleast one
x®0 x®¥ è xø
value of c such that,
loga (1 + x)
3. lim = log a e f (b) – f ( a )
x®0 x f ¢ (c) =
b–a
loge (1 + x)
4. lim = loge e = 1 Standard Integration
x®0 x
x
(1 + x) n –1 1. òe dx = e x
5. lim = n
x® 0 x
x ax
xn – an
2. ò a dx = log a
; ò a dx = 0 (a = constant)
6. lim = na n –1 (a > 0)
x ®0 x – a n +1
n dx = x
a x –1
3. òx n +1
(n ¹ 1)
7. lim = log a (a > 0).
x®0 x
1
log x when n = 1, i.e., ò x dx = log x
8. lim = 0 (n > 0)
x®¥ x n
4. ò sin x dx = – cos x
L-Hospital’s rule
If at x = a, a function f(x) has an indeterminate value such as 5. ò cos x dx = sin x
0 ¥ ¥
, ,1 , ¥ – ¥ etc. then L-hospital’s rule can be applied. 6. ò tan x dx = – log cos x = log sec x.
0 ¥
2
consider two functions f(x) and f(x) having value 0 at x = 0, then 7. ò cos ec x dx = – cot x.
2
lim
f ( x)
= lim
f ¢( x) 8. ò sec x dx = tan x
x® a f( x ) x ® a f ¢ ( x )
If still f ¢ (x) and f¢ (x) has value zero at x = a, then
9. ò sec x dx = log (sec x + tan x)
lim
f ( x)
= lim
f ¢¢( x ) 10. ò cot x dx = log sin x.
and goes on.
x® a g ( x ) x® a ¢¢ ( x)
g
11. ò sec x tan x dx = sec x
Mean Value Theorems
1. Rolle’s theorem
12. ò cosec x cot x dx = – cosec x.
If a function f (x) is continuous in a closed interval [a, b] i.e.
S2-60 Calculus
x 1 1 æ a + xö
13. ò cosec x dx = log (cosec x – cot x) = log tan 2 24. ò a 2 – x2 dx = 2a log çè a – x ÷ø ( x < a)
1
ò dx = sin –1 x = – cos –1 x 25. òe
x
[ f ( x) + f ¢ ( x )]dx = e x f ( x ) + c
14. 2
1– x
f ¢( x )
1
dx = tan –1 x
26. ò dx = log f ( x) + c
15. ò 1 + x2 f ( x)
1 1 æ xö ¶f ¶f ¶f
ò dx = sec –1 ç ÷ Grad f = Ñf = i + j +k
21. a è aø ¶x ¶y ¶z
x x2 – a 2
æ ¶f ¶f ¶y ö
1 1 æ xö
dx = tan –1 ç ÷ div F = çè i. ¶x + j ¶y + k . ¶z ø÷
22. ò 2
x +a 2 a è aø
1 1 æ x – aö
23. ò x 2 – a 2 dx = 2a log çè x + a ÷ø ( x > a)
Calculus S2-61
14. What is the value of the definite integral (a) There exists a y in the interval (0, 1), f (y) = f (y + 1)
a x (b) For every y in the interval (0, 1), f (y) = f (2 – y)
ò0 x+ a–x
dx ? [2011, 1 mark] (c) The maximum value of the function in the interval
(0, 2) is 1
a (d) There exists a y in the interval (0, 1) such that f (y)
(a) 0 (b)
2 = – (2 – y)
(c) a (d) 2a 18. A non-zero polynomial f(x) of degree 3 has roots at x =1,
15. Consider the function f (x) = sin (x) in the interval x Î [p/4, x = 2 and x = 3. Which one of the following must be TRUE?
7p/4]. The number and location(s) of the local minima of [2014, Set-2, 1 Mark]
this function are [2012, 1 mark] (a) f (0) f (4) < 0 (b) f (0) f (4) > 0
(a) one, at p/2 (b) one, at 3p/2 (c) f (0) + f (4) > 0 (d) f (0) + f (4) < 0
(c) two, at p/2 and 3p/2 (d) two, at p/4 and 3p/2 19. The value of the integral given below is
p 2
16. Which one of the following functions is continuous at x = 3? ò0 x cos x dx
[2013, 1 Mark]
[2014, Set-3, 2 Marks]
ì 2, if x = 3 (a) –2p (b) p
(a) ï
f ( x ) = ï x – 1, if x > 3
(c) –p (d) 2p
í
ï x + 3 , if x < 3 Numerical Answer Questions
ïî 3
20. The function f (x) = x sin x satisfies the following equation :
ì 4, if x=3 f¢ '(x) + f (x) + t cos x = 0. The value of t is ______ .
(b) f ( x) = í
î8 – x, if x¹3 [2014, Set-1, 2 Marks]
21. The number of distinct positive integral factors of 2014 is
ì x + 3, if x£3
(c) f ( x) = í _________________________ [2014, Set-2, 2 Marks]
î x – 4, if x>3
2p
1
22. If ò0 | x sin x | dx = kp, then the value of k is equal
(d) f (x) = , if x ¹ 3 to______ . [2014, Set-3, 1 Mark]
x 3 – 27
17. A function f(x) is continuous in the interval [0, 2]. It is known
that f (0) = f (2) = – 1 and f (1) = 1. Which one of the following
statements must be true ? [2014, Set-1, 2 Marks]
Calculus S2-63
CONCEPTUAL MCQs 8 2 2 4y
So ò0 òx \4 f ( x, y )dy dx = ò0 ò0 f ( x, y ) dx dy
1. (c) A cubic polynomial with real coefficients cannot have
more than two extrema and more than three zero s q
crossings. =ò ò p f ( x, y)dx dy
r
e x – (1 + x ) é0 ù
= lim êë 0 Form úû
(8, 2) x ®0 3x 2
ex – 1 é0 ù
= lim êë 0 Form úû
(0, 0) x (8, 0) X-axis x®0 6 x
7. (a) f(x) = | x |
é2 ù é2 ù
ì x, x ³ 0 sin ê x ú sin ê x ú
or f(x) = í - x, x < 0 lim ë 3 û = lim ë 3 û ´ 2 éQ lim sin x = 1ù
10. (a)
î x ®0 x x ®0 é 2 ù 3 êë x ®0 x úû
x
êë 3 úû
The graph of f(x) is
y æ2ö 2
= 1. ç ÷ =
è3ø 3
¥¥
¥ é x –2 ù 1é 1 ù
x' x 11. (c) S = ò x –3 dx = ê ú = –
0 1 ë –2 û1 2 êë x 2 úû1
| x | -0 1
=1 = [ x.e x ]10 – ò e x dx = (1.e – 0) – [ex]01
Right derivative = lim+ x
0
x®0
= (e–1)2 = e–2
apply L’ Hospital rule
1 –2 / 3 a x
x –0 1 1 14. (b) I=ò dx
1
= lim 3 = = x+ a–x
0
= lim 3 ´ 4 12
x ®8 1– 0 x ®8 3 x 2 / 3
a a
9. (a) lim
x - sin x By property ò0 f ( x) = ò0 f (a – x )dx,
x ®¥ x + cos x
a a–x
sin x I= ò dx
1- 0
x a – x+ x
lim
= x®¥ cos x
1+
x Adding both integrals, we get
1- 0 a
= =1 I=
1+ 0 2
Calculus S2-65
lim f ( x) = lim x - 4 = -1
5p/2 x ®3 + x ®3+
f (x) |x = 3 = 3 + 3 = 6
p 3p/2
p/2 2p lim f ( x) ¹ f ( x) x =3
x ®3+
1
p/4 p/4 (d) f ( x) = 3
if x ¹ 3
x - 27
Hence, the solution is (a).
Local minima is at 3p/2 and there is only one local
17. (a) There exist a y in the interval (0, 1)
minima and its value is (– 1).
f (y) = f (y + 1)
3p 18. (a) As per rule, if we put w values to the function which
So, answer is one local minima at .
2 are on either side of root, the product will be less then
zero.
Another approach
Here 0 and 4 are on either side of roots.
Using normal differentiation, compute f ¢(x), equate it \ f (0). f(4) < 0
to 0. Solve for x in the given range. For all solutions
compute f ¢¢ (x). Check its sign if (– ve) then local maxima p
ò0 x
2
19. (a) cos xdx
else local minima.
= | x 2 (sin x ) - 2 x( - cos x) + 2( - sin x) |p0
ì (p2 sinp + 2pcosp – 2sinp) – (0 + 0 + 0) = – 2p
ï 2 if x =3
ï
16. (a) f ( x) í x - 1 if x>3 NUMERICAL ANSWER QUESTIONS
ïx+3
ï if x<3 20. –2
î 3
Given function f(x) = x sin x ...(1)
Given eqn : f ¢¢(x) + f(x) + t cos x = 0 ...(2)
x+3
lim f ( x) = lim =2 As f(x) = x sin x
- - 3
x ®3 x®3
d
f ¢(x) = (x sin x) = sinx + x cos x
lim f ( x ) = lim x - 1 = 2 dx
x ®3+ x® 3+
d
f ¢¢(x) = (sin x + x cos x)
\ lim f ( x) = f ( x ) = lim f ( x) dx
x= 3
x ®3- x®3+
Þ f ¢¢(x) = cos x + cos x – x sin x
This is continuous at x = 3 Þ f ¢(x) = 2 cos x – x sin x ...(3)
Put values from eq. (1) and eq. (3) into eq. (2)
ì 4 if x=3
(b) f (x) = í 2 cos x – x sin x + x sin x + t cos x = 0
î8 - x if x¹3
(t + 2) cos x = 0
lim f ( x) = lim 8 - x = 5 ¹ f ( x) x= 3 Þ t + 2 = 0 (cos x can’t be 0 as the given function is not a
x ®3- x ®3- constant function)
Option (b) is false. Þ t = -2
S2-66 Calculus
21. 8
= [x(- cos x) - 1(- sin x)]p0 - [ - x cos x + sin x ]p
2p
p 2p Þ 4p = kp
= ò (x sin x) + ò -(x sin x)dx
0 p Þk=4
SECTION 3 : TECHNICAL SECTION
Digital Logic S3-1
1 Digital Logic
Chapter
P
R=P+Q Karnaugh Map (K-Map) Simplification
Q
It is a technique for simplifying & manipulating switching
NOR
Fig. gateGate
: NOR expressions. It is a modified form of a truth table.
BOOLEAN ALG EBRA A AB
B 0 1 00 01 11 10
C
Some more Boolean laws : 0 0 2 0 0 2 6 4
(1) P + 0 = P (2) P + 1 = 1 (3) P + P = P (4) P + P = 1 (5) P.1 = P 1 1 3 1 1 3 7 5
(6) P.0 = 0 (7) P.P = P (8) P.P = 0 (9) P = P (10) P = P Fig. : Two variable Fig. : Three Variable
Digital Logic S3-3
AB DEMULTIPLEXER
00 01 11 10
CD The working of a demultiplexer is exactly opposite to that of a
00 0 4 12 8 multiplexer. Demultiplexer receives information from a single line
01 1 5 13 9 and transmits it to several lines.
11 2 7 15 11 m select signals
10 3 6 14 10
S1 S0 R(Reset)
1 Q
D0 R Q
D1 S Q
Y S(Set) 2 Q
D2
D3
½ 7402
Fig. : 4-to-1 multiplexer Fig. : NOR based S-R flip-flop
S3-4 Digital Logic
Table
"Master Latch" "Slave Latch"
Inputs Outputs
Actions J Q
S R Qn+1 Q n+ 1
Clk
0 0 Qn Qn No Change
K Q
0 1 0 1 Reset
Clk
1 0 1 0 Set
1 1 ? ? Forbidden Fig. : The Master-Slave JK Flip-Flop
Master-Slave JK Flip-flop is a “Synchronous” device as it
(b) Clocked S-R Flip-flop
only passes data with the timing of the clock signal.
The clocked SR flip-flop shown in fig. 8 (d) consists of a
(d) D Flip-flops :
basic NOR flip-flop and two AND gates.
• It has only one input known as D (Delay) & two
R
Q outputs Q & Q .
CP S(Set)
D
(clock pulse) 1
3 Q
Q¢
S
Fig. : Clocked S-R Flip-flop CLK
Q n +1 = Sn + R n¢ Q n 2
R 4 Q
R
RC1 C 1 R2 C2 Rc2
1
VC1 + - - + Vc2
Q1 Q2
RC1 R
I4 c2
IC1 I3 R1 R Ic2 Clear
IB2 2 Clock
Q1 Q2
I5 I6
R3 R4 4-bit Serial-in to Serial-out Shift Register
1 1
0 0 0
Set Reset Serial 0 1 0 1
-VBB D Q D Q D Q D Q Q
Data in
FFA FFB FFC FFD Serial
Fig. : Bistable Multivibrator CLK CLK CLK CLK
Data Out
The Shift Register is another type of sequential logic circuit that 4-bit Parallel-in to Parallel-out Shift Register
is used for the storage or transfer of data in the form of binary
numbers and then "shifts" the data out once every clock cycle,
hence the name "shift register". 4-bit Parallel Data Output
• Serial-In To Parallel-Out (SIPO) – the register is loaded QD QC QB QA
with serial data, one bit at a time, with the stored data being
available in parallel form.
• Serial-In To Serial-Out (SISO) – the data is shifted serially D Q D Q D Q D Q
"IN" and "OUT" of the register, one bit at a time in either a FFA FFB FFC FFD
left or right direction under clock control.
• Parallel-In To Serial-Out (PISO) – the parallel data is loaded CLK CLK CLK CLK
into the register simultaneously and is shifted out of the reg-
ister serially one bit at a time under clock control.
• Parallel-In To Parallel-Out (PIPO) – the parallel data is loaded Clock
simultaneously into the register, and transferred together
PD PC PB PA
to their respective outputs by the same clock pulse.
4-bit Parallel Data Input
Digital Logic S3-7
wx
Problem Based MCQs yz 00 01 11 10
1. The number 43 in 2’s complement representation is 00 0 × 0 ×
[2000, 1 Mark]
01 × 1 × 1
(a) 01010101 (b) 11010101
(c) 00010101 (d) 10101011 11 0 × 1 0
2. The simultaneous equations on the Boolean variables x,
10 0 1 × 0
y, z and w, [2000, 2 Marks]
x+y+ z=1 (a) xy + y¢z (b) wx¢ y¢ + xy + xz
xy = 0 (c) w¢ x + y¢ z + xy (d) xz + y
xz + w = 1 6. Consider the following circuit with initial state Q0 = Q1 = 0.
The D flip-flops are positive edged triggered and have set
xy + z w = 0
up times 20 ns and hold times 0.
Have the following solution for x, y, z and w, respectively
(a) 0100 (b) 1101
X D0 D1 Q1 Y
(c) 1011 (d) 1000
3. Which function does not implement the Karnaugh map
given below? [2000, 2 Marks] Clock Q0 Clock
wz C
xy 00 01 11 10 Consider the following timing diagrams of X and C; the
clock period of C ³ 40 ns. Which one is the correct plot
00 0 X 0 0 of Y? [2001, 1 Mark]
01 0 X 1 1
C
11 1 1 1 1
10 0 X 0 0
X
(a) (w + x) y (b) xy + yw
(c) (w + x)(w + y)(x + y) (d) None of these (a)
4. The following arrangement of master-slave flip flops has
the initial state of P, Q as 0, 1 (respectively). After the (b)
clock cycles, the output state P, Q is (respectively)
[2000, 2 Marks] (c)
(d)
P Q1 7. Ths 2’s complement representation of (–539)10 in
hexadecimal is [2001, 2 Marks]
(a) ABE (b) DBC
(c) DE5 (d) 9E7
8. Consider the circuit shown below. The output of a 2 : 1
J K D MUX is given by the function (ac¢ + bc). [2001, 2 Marks]
1 1 a 2:1 g a 2:1
MUX MUX f
0 b c b c
Clock
(a) 1, 0 (b) 1, 1 x1 x2
(c) 0, 0 (d) 0, 1 Which of the following is true?
5. Given the following Karnaugh map, which one of the (a) f = x1¢ + x 2 (b) f = x1¢ x 2 + x1x¢2
following represents the minimal Sum-Of-Products fo the
map? [2001, 1 Mark] (c) f = x1x 2 + x1¢ x¢2 (d) f = x1 + x¢2
S3-8 Digital Logic
9. Consider the circuit given below with initial state Q0 = 1, 15. Consider the following multiplexer where 10, 11, 12, 13 are
Q1 = Q2 = 0. The state of the circuit is given by the value four data input lines selected by two address line
4Q2 + 2Q1 + Q0. [2001, 2 Marks] combinations A1A0 = 00, 01, 10, 11 respectively and f is
the output of the multiplexer. EN is the Enable input.
[2002, 2 Marks]
D0 Q0 D1 Q1 D2 Q2 10
11
12
13 4 to 1
LSB MSB Output f (x, y, z) = ?
multiplexer
A1
Clock A0
Which one of the following is the correct state sequence EN
of the circuit?
(a) 1, 3, 4, 6, 7, 5, 2 (b) 1, 2, 5, 3, 7, 6, 4 The function f (x, y, z) implemented by the above circuit
(c) 1, 2, 7, 3, 5, 6, 4 (d) 1, 6, 5, 7, 2, 3, 4 is
10. Minimum sum of products expression for f (w, x, y, z) (a) xyz¢ (b) xy + z
shown in Karnaugh map below is [2002, 1 Mark] (c) x + y (d) None of these
wx 16. Let f (A, B) = A¢ + B. Simplified expression for function
yz 00 01 11 10 f (f (x + y, y), z) is [2002, 2 Marks]
00 0 1 1 0 (a) x¢ + z (b) xyz
(c) xy¢ + z (d) None of these
01 × 0 0 1 17. Assuming all numbers are in 2’s complement
representation, which of the following numbers is divisible
11 × 0 0 0
by 11111011? [2003, 1 Mark]
10 0 1 1 × (a) 11100111 (b) 11100100
(c) 11010111 (d) 11011011
(a) xz + y¢ z (b) xz¢ + zx¢ 18. The following is a scheme for floating point number
(c) x¢ y + zx¢ (d) None of these representation using 16 bit. [2003, 2 Marks]
11. The decimal value 0.25 [2002, 1 Mark]
(a) is equivalent to the binary value 0.1 Bit position 15 14.......9 8.........0
(b) is equivalent to the binary value 0.01 s e m
(c) is equivalent to the binary vlaue 0.00111... Sign Exponent Mantissa
(d) cannot be represented precisely in binary Let s, e, and m be the numbers represented in binary in
12. the 2’s complement representation of the decimal value –15
the sign, exponent and mantissa fields respectively. Then
is [2002, 1 Mark]
(a) 1111 (b) 11111 the floating point number represented is
(c) 111111 (d) 10001 ìï(-1)s (1 + m ´ 2-9 )2e -31, if the exponent ¹ 111111
13. Sign extension is a step in [2002, 1 Mark] í
(a) floating point multiplication ïî0, otherwise
(b) signed 16 bit integer addition What is the maximum difference between two successive
(c) arithmetic left shift real numbers representable in this system?
(d) converting a signed integer from one size to another
(a) 2–40 (b) 2–9
14. Consider the following logic circuit whose inputs are 22
functions f1, f2, f3 and output is f : [2002, 2 Marks] (c) 2 (d) 231
19. A 1-input, 2-output synchronous sequential circuit behaves
f1 (x, y, z) as follows :
f2 (x, y, z) Let zk, nk denote the numbers of 0’s and 1’s respectively
f (x, y, z) in initial k bits of the input.
(zk + nk = k). The circuit outputs 00 until one of the
following conditions holds.
f3 (x, y, z) = ? • zk – nk = 2. In this case, the output at the kth and
all subsequent clock ticks is 10.
Given that • nk – zk = 2. In this case, the output at the kth and
f1 (x, y, z) = å (0, 1, 3, 5) all subsequent clock ticks is 01.
f2 (x, y, z) = å (6, 7), and What is the minimum number of states required in the
f (x, y, z) = å (1, 4, 5) state transition graph of the above circuit?
f3 is [2003, 2 Marks]
(a) å (1, 4, 5) (b) å (6, 7) (a) 5 (b) 6
(c) å (0, 1, 3, 5) (d) None of these (c) 7 (d) 8
Digital Logic S3-9
20. The literal count of a Boolean expression is the sum of (a) 2 (b) 3
the number of times each literal appears in the expression. (c) 4 (d) 5
For example, the literal count of (xy + xz¢) is 4. What are 27. Which are the essential prime implicants of the following
the minimum possible literal counts of the product-of- Boolean function?
sums and sum-of-products representations respectively f (a, b, c) j = a¢ c + ac¢ + b¢c [2004, 2 Marks]
of the funciton given by the following Karnaugh map? (a) a¢c and ac¢ (b) a¢c and b¢c
Here, × denotes don’t care [2003, 2 Marks] (c) a¢c only (d) ac¢ and bc¢
zw 28. Consider the partial implementation of a 2-bit counter
xy 00 01 11 10 using T flip-flops following the sequence 0-2-3-1-0, as
00 × 1 0 1 shown below : [2004, 2 Marks]
01 0 1 × 0
11 1 × × 0
T2 Q2 X T Q1
1
10 × 0 0 ×
MSB LSB
(a) (11, 9) (b) (9, 13)
(c) (9, 10) (d) (11, 11) CLK
21. Consider the following circuit composed of XOR gates To complete the circuit, the input X should be
and non-inverting buffers :
(a) Q¢2 (b) Q2 + Q1
A B
(c) (Q1 Å Q2)¢ (d) Q1 Å Q2
d1 = 2 d2 = 4 29. A 4-bit carry look ahead adder, which adds two 4-bit
numbers, is designed using AND, OR, NOT, NAND, NOR
The non-inverting buffers have delays d1 = 2 ns and d2 = 4 ns gates only. Assuming that all the inputs are available in
as shown in the figure. Both XOR gates and all wires both complemented and uncomplemented forms and the
have zero delay. Assume that all gate inputs, outputs and delay of eahc gate is 1 time unit, what is the overall
wires are stable at logic level 0 at time 0. If the following propagation delay of the adder? Assume that the carry
waveform is applied at input A, how many transition(s) network has been implemented using two-level AND-OR
(change of logic levels) occur(s) at B during the interval logic. [2004, 2 Marks]
from 0 to 10 ns? (a) 4 time unit (b) 6 time unit
Logic 1
(c) 10 time unit (d) 12 time unit
Logic 0
30. Let A = 1111 1010 and B = 0000 1010 be two 8-bit 2’s
complement numbers. Their product in 2’s complement is
[2003, 2 Marks] [2004, 2 Marks]
(a) 1 (b) 2 (a) 1100 0100 (b) 1001 1100
(c) 3 (d) 4 (c) 1010 0101 (d) 1101 0101
22. A Boolean function x¢y¢ + xy + x¢y is equivalent to 31. The range of integers that can be represented by an n bit
[2004, 1 Mark] 2’s complement number system is [2005, 1 Mark]
(a) x¢ + y¢ (b) x + y (a) –2n–1 to (2n – 1 – 1) (b) – (2n – 1–1) to (2n–1 –1)
(c) x + y¢ (d) x¢ + y (c) –2n–1 to 2n – 1 (d) – (2n – 1+1) to (2n–1 –1)
23. In an SR latch made by cross-coupling two NAND gates, 32. The hexadecimal representation of 6578 is [2005, 1 Mark]
if both S and R inputs are set to 0, then it will result in (a) 1AF (b) D78
[2004, 1 Mark] (c) D71 (d) 32F
(a) Q = 0, Q¢ = 1 (b) Q = 1, Q¢ = 0 33. The switching expression corresponding to f (A, B, C, D)
(c) Q = 1, Q¢ = 1 (d) indeterminate states = å (1, 4, 5, 9, 11, 12) is [2005, 1 Mark]
24. If 73x (in base-x number system) is equal to 54y (in base-y (a) BC¢D¢ + A¢C¢D + AB¢D (b) ABC¢ + ACD + B¢C¢D
number system), the possible values of x and y are (c) ACD¢ + A¢BC¢ + AC¢D¢ (d) A¢BD + ACD¢ + BCD¢
[2004, 1 Mark] 34. The following diagram represents a finite state machine,
(a) 8, 16 (b) 10, 12 which takes as input a binary number from the least
(c) 9, 13 (d) 8, 11 significant bit.
25. What is the result of evaluating the following two 0/0 0/1
expressions using three-digit floating point arithmetic
with rounding? [2004, 1 Mark] 1/0
(a) 9.51 and 10.0 (b) 10.0 and 9.51
1/1
(c) 9.51 and 9.51 (d) 10.0 and 10.0
26. A circuit outputs a digit in the form of 4 bit. 0 is
represented by 0000, 1 by 0001, ..., 9 by 1001. A Q0 Q1
combinational circuit is to be designed which takes these Which one of the following is true? [2005, 2 Marks]
4 bits as input and outputs 1 if the digit ³ 5, and 0 (a) It computes 1’s complement of the input number
otherwise. If only AND, OR and NOT gates may be used, (b) It computes 2’s complement of the input number
what is the minimum number of gates required? (c) It increment the input number
[2004, 2 Marks] (d) It decrements the input number
S3-10 Digital Logic
35. Consider the following circuit : (a) g0(h3h2h1h0) = å (1, 2, 3, 6, 10, 13, 14, 15)
Q0 D1 (b) g1(h3h2h1h0) = å (4, 9, 10, 11, 12, 13, 14, 15)
D0 Q1 (c) g2(h3h2h1h0) = å (2, 4, 5, 6, 7, 12, 13, 15)
(d) g3(h3h2h1h0) = å (0, 1, 6, 7, 10, 11, 12, 13)
Q1¢
Q0¢ 38. Consider the following circuit involving a positive edge
triggered D flip-flop: [2006, 2 Marks]
A
CLK
The flip-flops are positive edge triggered D flip-flops. X
D Q
Each state is designated as a two-bit string Q0Q1. Let the
initial state be 00. The state transition sequence is Y
[2005, 2 Marks]
(a) 00 ® 11 ® 01 (b) 00 ® 11
CLK Q¢
(c) 00 ® 10 ® 01 ® 11 (d) 00 ® 11 ® 01® 10
36. You are given a free running clock with a duty cycle of 50%
Consider the following timing diagram, Let Ai represents
and a digital waveform f which changes only at the negative
the logic level on the line A in the ith clock period.
edge of the clock. Which one of the following circuits (using
clocked D flip-flops) will delay the phase of f by 180°?
[2006, 1 Mark]
CLK
f D D Q
Q 0 1 2 3 4 5
X
(a)
D Q Y f
f D Q
CLK
Z
(c)
Which one of the following is true? [2006, 2 Marks]
(a) f is independent of X
(b) f is independent of Y
(c) f is independent of Z
D D Q (d) None of X, Y, Z is redundant
f
40. We consider the addition of two 2’s complement numbers
Q bn -1b n -2 ....b0 and a n -1a n -2 ....a 0 . A binary adder for
(d) adding unsigned binary numbers is carry-out by Cout. Which
one of the following options correctly identifies the overflow
condition? [2006, 2 Marks]
CLK
(a) (
Cout a n -1 Å bn -1 )
37. Consider numbers represented in 4-bit gray code. Let
h3h2h1h0 be the gray code representation of a number n (b) a n -1bn -1 c n -1 + a n -1bn -1cn -1
and let g3g2g1g0 be the gray code of (n + 1) (modeulo 16) (c) Cout Å Cn -1
value of the number. Which one of hte following
funcitons is correct? [2006, 2 Marks] (d) a n -1 Å b n -1 Å cn -1
Digital Logic S3-11
41. Consider a Boolean function f(w, x, y, z). Suppose that exactly (a) 7 (b) 8
one of its inputs is allowed to change at a time. (c) 9 (d) 10
If the function happens to be true for two input vectors i 1 = 46. What is the maximum number of different Boolean functions
(w1, x1, y1, z1) and i2 = (w2, x2, y2, z2), we would like the involving n Boolean variables? [2007, 1 Mark]
function to remain true as the input changes from i 1 to i2 (i1 (a) n2 (b) 2n
and i2 differ in exactly one bit position) without becoming
false momentarily. Let f (w, x, y, z) = S(5, 7, 11, 12, 13, 15) (c) 22n (d) 2n 2
which of the following cube covers at f will ensure that the 47. The control signal functions of a 4-bit binary counter are
required property is satisfied? given below (where x is don’t care): [2007, 2 Marks]
(a) wxz, wxy, xyz, xyz, wyz [2006, 2 Marks]
Clear Clock Load Count Function
(b) wxy, wxz, xyz
1 × × × Clear to 0
(c) wx yz, xz, wxyz 0 × 0 0 No change
(d)xzy, xyz, wxz, wxz, xyz, xyz 0 1 × Load input
42. Given two three bit numbers a2a1a0 and b2b1b0 and c the
carry in the function that represents the carry generate 0 0 1 Count next
function when these two numbers are added is The counter is connected as follows
[2006, 2 Marks]
(a) a2b2 + a2a1b1 + a2a1a0b0 + a2a0b1b0 + a1b2b1 + a1a0b2b0 A4 A3 A2 A1
+ a0b2b1b0
(b) a2b2 + a2b1b0 + a2a1b1b0 + a1a0b2b1 + a1a0b2 + a1a0b2b0
+ a2a0b1b0
Count = 1
(c) a 2 + b 2 + ( a 2 Å b 2 ) ( a1 + b1 + ( a1 Å b1 ) ( a 0 + b0 ) ) 4-bit counter Load = 0
Clear Clock
(d) a 2b2 + a 2a1b1 + a 2a1a 0 b0 + a 2a 0 b1b0 Input
+ a1 b2 b1 + a1a 0 b2b0 + a 0 b2b1b0
0 0 1 1
43. x
Assume that the counter and gate delays are negligible. If
the counter starts at 0, then it cycles through the following
0 MUX sequence
(a) 0, 3, 4 (b) 0, 3, 4, 5
1 (c) 0, 1, 2, 3, 4 (d) 0, 1, 2, 3, 4, 5
y 48. In a look-ahead carry generator, the carry generate function
Gi and the carry propagate function Pi for inputs Ai and Bi
z are given by [2007, 2 Marks]
0 MUX
f Pi = Ai Å Bi and G i = Ai Bi
1 The expressions for the sum bit Si and the carry bit Ci + 1 of
the look-ahead carry adder are given by
x
Si = Pi Å Ci and Ci +1 = Gi + Pi Ci , where C0 is the input
y
carry.
Consider the circuit above. Which one of the following Consider a two-level logic implementation of the look-ahead
options correctly represents f(x, y, z)? [2006, 2 Marks] carry generator. Assume that all Pi and Gi are available for
the carry generator circuit and that the AND and OR gates
(a) xz + xy + yz (b) xz + xy + yz
can have any number of inputs. The number of AND gates
(c) xz + xy + yz (d) xz + xy + yz and OR gates needed to implement the look-ahead carry
44. Consider the following Boolean function of four variables: generator for a 40-bit adder with S3, S2, S1, S0 and C4 as its
f ( w, x, y, z ) = å (1,3, 4, 6,9,11,12,14 ) [2007, 1 Mark] outputs are respectively
(a) 6, 3 (b) 10, 4
The function is (c) 6, 4 (d) 10, 5
(a) independent of one variable 49. Suppose only one multiplexer and one inverter are allowed
(b) independent of two variables to be used to implement any Boolean function of n variables.
(c) independent of three variables What is the minimum size of the multiplexer needed?
(d) independent of all variables
[2007, 2 Marks]
45. How many 3-to-8 line decoders with an enable input are
(a) 2n line to 1 line (b) 2n + 1 line to 1 line
needed to construct a 6-to-64 line decoder without using
(c) 2n – 1 line to 1 line (d) 2n – 2 line to 1 line
any other logic gates? [2007, 1 Mark]
S3-12 Digital Logic
50. Define the connective * for the Boolean variables X and Y as 56. If P, Q, R are Boolean variables, then [2008, 2 Marks]
X*Y = XY + X’Y’. Let Z = X*Y. Consider the following
expressions P, Q and R” ( P + Q )( P.Q + P.R )( P.R + Q ) simplifies to
P:X=Y *Z Q:Y=X*Z
R:X*Y*Z=1 (a) P.Q (b) P.R
Which of the following is true? [2007, 2 Marks]
(c) P.Q + R (d) P.R + Q
(a) P and Q are valid (b) Q and R are valid
(c) P and R are valid (d) All P, Q, R are valid 57. What is the minimum number of gates required to implement
51. Let f(w, x, y, z) = å ( 0, 4, 5, 7,8,9,13,15 ) . Which of the the Boolean function (AB + C), if we have to use only
following expressions is pre not equivalent to f? 2-input NOR gates) [2009, 1 Mark]
(P) x’y’z’ + w’xy’ + wy’z + xz [2007, 2 Marks] (a) 2 (b) 3
(Q) w’y’z’ + wx’y’ + xz (c) 4 (d) 5
(R) w’y’z’ + wx’y’ + xyz + xy’z 58. (1217)8 is equivalent to [2009, 1 Mark]
(S) x’y’z’ + wx’y’ + w’y (a) (1217)16 (b) (028F)16
(a) P only (b) Q and S (c) (2297)10 (d) (0B17)16
(c) R and S (d) S only 59. The Boolean expression for the output F of the multiplexer
52. Given f1, f3 and f in canonical sum of products form (in shown below is [2010, 1 Mark]
decimal) for the circuit [2008, 1 Mark]
f1
f2 0
R
f R 1
F
f3 R 2
S0
f1 = å m ( 4, 5, 6, 7,8 ) , f3 = å m (1, 6,15 ) R 3 S
1
f = å m (1,6,8,15) Q
Then f2 is P
(a) å m ( 4, 6 ) (b) å m ( 4,8)
(a) PÅQÅR (b) PÅQÅR
(c) å m ( 6,8) (d) å m ( 4, 6,8 )
(c) P + Q + R (d) P+Q+R
53. Let r denotes number system radix. The only value(s) of r
that satisfy the equation 121r = 11r is/are [2008, 1 Mark] 60. P is a 16-bit signed integer. The 2’s complement
(a) decimal 10 (b) decimal 11 representation of P is (F87B)16 . The 2’s complement
(c) decimal 10 and 11 (d) any value > 2 representation 8*P is [2010, 1 Mark]
54. In the Karnaugh map shown below, X denotes a don’t care (a) (C3D8)16 (b) (187B)16
term. What is the minimal form of the function represented (c) (F878)16 (d) (987B)16
by the Karnaugh map? [2008, 1 Mark]
ab
61. The minterm expansion of f(P, Q, R) = PQ + QR + PR is
00 01 11 10 [2010, 1 Mark]
cd
00 1 1 1 (a) m2 + m4 + m6 + m7 (b) m0 + m1 + m3 + m5
(c) m0 + m1 + m6 + m7 (d) m2 + m3 + m4 + m5
01 x 62. In the sequential circuit shown below, if the initial value of
the output Q1Q0 is 00, what are the next four values of
11 x Q1Q0? [2010, 2 Marks]
10 1 1 x
T Q
1 T Q
(a) b.d + a.d (b) a.b + b.d + a.b.d
(c) b.d + a.b.d (d) a.b + b.d + a.d Clock
55. In the IEEE floating point representation, the hexadecimal
value 0 × 00000000 corresponds to [2008, 1 Mark]
(a) the normalized value 2–127 Q0 Q1
(b) the normalized value 2–126
(c) the normalized value + 0 (a) 11, 10, 01, 00 (b) 10, 11, 01, 00
(d) the special value +0 (c) 10, 00, 01, 11 (d) 11, 10, 00, 01
Digital Logic S3-13
63. What is the Boolean expression for the output F of the 69. What is the minimal form of the Karnaugh map shown
combinational logic circuit of NOR gates given below? below? Assume that X denotes a don’t care term.
P [2005, 1 Mark]
Q
ab
cd 00 01 11 10
Q
R 00 1 X X 1
F
P 01 X 1
R [2010, 2 Marks]
11
Q 10 1 X
R
Inputs Outputs
(c) (d)
D0 D1 D2 D3 X0 X1 V
0 0 0 0 x x 0
66. The simplified SOP (Sum of Products) form of the Boolean
( )( )(
expression P + Q + R . P + Q + R . P + Q + R is ) 1
x
0
1
0
0
0
0
0
0
0
1
1
1
[2011, 1 Mark]
x x 1 0 1 0 1
(a) ( PQ + R ) (b) ( P + QR ) x x x 1 1 1 1
(c) ( PQ + R ) (d) (PQ + R)
67. The truth table What function does the truth table represent?
X Y f(X, Y) (a) Priority encoder (b) Decoder
(c) Multiplexer (d) Demultiplexer
0 0 0
72. Which one of the following expressions does not
0 1 0 represent exclusive NOR of x and y? [2013, 1 Mark]
1 0 1 (a) xy + x ¢ y ¢ (b) x Å y ¢
1 1 1
(c) x¢ Å y (d) x ¢ Å y ¢
represents the Boolean function [2012, 1 Mark] 73. Consider the following Boolean expression for F :
(a) X (b) X + Y
(c) X Å Y (d) Y F (P, Q, R, S) = PQ + PQR + PQRS
68. The decimal value 0.5 in IEEE single precision floating
point representation has [2012, 1 Mark] The minimal sum of products form of F is
(a) fractions bits of 000 .... 000 and exponent value of 0 [2014, Set-1, 1 Mark]
(b) fractions bits of 000 .... 000 and exponent value of – 1 (a) PQ + QR + QS (b) P + Q + R + S
(c) fractions bits of 100 .... 000 and exponent value of 0
(d) no exact representation (c) P +Q+R +S (d) PR + PRS + P
S3-14 Digital Logic
74. Consider the 4-to-1 multiplexer with two select lines S1 and 79.
S0 given below.
J Q2 J Q1 J Q0
C C C
0 0 K Q2 K Q1 K Q0
1 1
4-to-1 F
R 2
Multiplexer
R 3 The above synchronous sequential circuit built using JK
S1 S0 flip-flops is initialized with Q2Q1Q0 = 000. The state sequence
for this circuit for the next 3 clock cycles is
[2014, Set-3, 2 Marks]
(a) 001, 010, 011 (b) 111, 110, 101
P Q (c) 100, 110, 111 (d) 100, 011, 001
80. Let Å denote the Exclusive OR (XOR) operation. Let ‘1’
The minimal sum of products form of the Boolean expression
for the output F of the multiplexer is and ‘0’ denote the binary constants.
[2014, Set-1, 2 Marks] Consider the following Boolean expression for F over two
variables P and Q:
(a) PQ + QR + PQR (b) PQ + PQR + PQR
F(P, Q) = ((1 Å P) Å (P Å Q)) Å ((P Å Q) Å (Q Å 0))
(c) PQR + PQR + QR + PQR (d) PQR The equivalent expression for F is [2014, Set-3, 2 Marks]
75. The dual of a Boolean function F (x1, x2, ..., xn, +,., ¢), written (a) P + Q (b) P + Q
as FD, is the same expression as that of F with + and ·
swapped. F is said to be self-dual if F = FD. The number of (c) PÅQ (d) PÅQ
self-dual functions with n Boolean variables is
[2014, Set-2, 1 Mark] Linked Answer Type MCQs
(a) 2n (b) 2n–1
n-1 Statements for Linked Answer Questions 81 and 82
(c) 22n (d) 22 Consider the following floating-point format :
76. Let k =2n. A circuit is built by giving the output of an n-bit 15 14 8 7 0
binary counter as input to an n-to-2n bit decoder. This circuit
is equivalent to a [2014, Set-2, 1 Mark]
(a) k-bit binary up counter.
(b) k-bit binary down counter.
(c) k-bit ring counter. Sign bit Excess-64 Mantissa
exponent
(d) k-bit Johnson counter.
Mantissa is a pure fraction is sign-magnitude form.
77. Consider the following minterm expression for F:
81. The decimal number 0.239 × 213 has the following
F (P, Q, R, S) = å 0, 2,5, 7,8,10,13,15 hexadecimal representation (without normalization and
The minterms 2, 7, 8 and 13 are ‘do not care’ terms. The rounding off) [2005, 2 Marks]
minimal sum-of-products form for F is (a) 0D24 (b) 0D4D
[2014, Set-3, 1 Mark] (c) 4D0D (d) 4D3D
82. The normalized representation for the above format is
(a) QS + QS specified as follows. The mantissa has an implicit 1
(b) QS + QS preceding the binary (radix) point. Assume that only 0’s
are padded in while shifting a field.
(c) QRS + QRS + QRS + QRS The normalized representation of the above number
(0.239 × 213) is [2005, 2 Marks]
(d) ò PQS + PQS + PQS + PQS (a) 0A20 (b) 1134
(c) 49D0 (d) 4AE8
78. Consider the following combinational function block
involving four Boolean variables x, y, a, b where x, a, b are Numerical Answer Questions
inputs and y is the output.
f (x, y, a, b) 83. Design a logic circuit to convert a single digit BCD number
{ to the number modulo six as follows (Do not detect illegal
if (x is 1) y = a; input):
else y = b; (a) Write the truth table for all bits. Label the input bits I1,
} I2, .... With I1 as the least significant bit. Label the
Which one of the following digital logic blocks is the most output bits R1, R2, .... With R1 as the least significant
suitable for implementing this function? bit. Use 1 to signify truth.
[2014, Set-3, 1 Mark] (b) Draw one circuit for each output bit using, altogether,
(a) Full adder (b) Priority encoder two two-input AND gates, one two-input gate and
(c) Multiplexer (d) Flip-flop two NOT gates. [2000, 5 Marks]
Digital Logic S3-15
84. (a) Express the function f(x, y, z) = xy¢ + yz¢ with only one complement operation and one or more AND/OR operations. Draw the
logic circuit implementing the expression obtained, using a single NOT gate and one or more AND/OR gates.
(b) Transform the following logic circuit (without expressing its switching function) into an equivalent logic circuit that employs
only 6 NAND gates each with 2-inputs. [2000, 5 Marks]
85. Consider the following circuit A = a2a1a0 and B = b2b1b0 are three bit binary numbers input to the circuit. The output is Z =
z3z2z1z0. R0, R1 and R2 are registers with loading clock shown. The registers are loaded with their input data with the falling edge
of a clock pulse (signal CLOCK shown) and appears as shown. The bits of input number A, B and the full address are as shown
in the circuit. Assume Clock period is greater than a settling time of all circuits.
[2000, 5 Marks]
A B
CLOCK
REG R0
(6-bit) b2 a2 b1 a1 b0 a0
FA 0
REG R1
(6-bit) b2 a2 b1 a1
FA
REG R2
(5-bit) b2 a2
FA
z1 z0
z2
Z = z3
(a) For 8 clocks pulses on the clock terminal and the inputs A, B as shown, obtain the output z. Assume initial contents of R0,
R1 and R2 as all zeros.
A= 110 011 111 101 000 000 000 000
B= 101 101 011 110 000 000 000 000
Clock No 1 2 3 4 5 6 7 8
(b) What does the circuit implement?
86. The base (or radix) of the number system such that the following equation holds is __________ .
312
= 13.1 [2014, Set-1, 1 Mark]
20
S3-16 Digital Logic
11. (b) The most convenient way to solve such type 15. (a) We need to deeply see the inputs and then resolve
problems is to go by the options. the output. Consider the inputs in the circuit diagram
Lets consider option (a). below, table fo input and output can be formed.
1
1 ´ 2 -1 =
= 0.5
2 10
So, is not the right option. 11
Now, lets consider the option (b).
0.01 12
13 4 to 1
1 Output f (x, y, z)
-1 -2 multiplexer
0´2 +1´ 2 = = 0.25 A1
4
12. (d) Binary form of 15 is 1111. A0
1’s complement of 15 is 0000. EN
2’s complement (add 1), we get = 0001
Finally, add signed bit (MSB) = 10001
13. (a) Sign extension is a step in floating point multiplication If we keep on solvign by putting all possible values
as the floating interprets to represent the number in for x, y, z and then finding the corresponding values
the form for f, we get a table
m × re
14. (a) f1 (x, y, z) = å (0, 1, 3, 5)
K-Map for f1 x y z f
yz 0 0 0 0
x yz yz yz yz 0 0 1 0
x 1 1 1
0 1 3 2
0 1 0 0
x 1 0 1 1 0
4 5 7 6
1 0 0 0
f1 = x y + y z + x z
f2 = (x, y, z) = å (6, 7) 1 0 1 0
K-Map for f2 1 1 0 1
yz 1 1 1 0
x yz yz yz yz
x
0 1 3 2
Now, only option (a) satisfies this.
1 1 16. (c) Since, f (A, B) = A¢ + B,
x f (f (x + y, y), z) = f¢ (x + y, y) + z
4 5 7 6
= ((x + y)¢ + y)¢ + z
K-Map for f = (x + y) · y¢ + z
= xy¢ + z
yz 17. (a) Lets find the decimal value of all the numbers. The
x yz yz yz yz
number divisible by
x 1 11111011 can only be found only by finding out the
0 1 3 2
decimal value
x 1 1
4 5 7 6 2'S 1's Original Decimal
f = yz + x y complement complement number value
f = f1 × f 2 + f 3 = f1f 2 + f3 11100111 11100110 00011001 25
y z + x y = x × y (x.y + y z + xz) + f 3
11100100 11100101 00011100 28
11010111 11010110 00101001 41
f 3 = y z + xy = (x + x) y z + x y (z + z )
11011011 11011010 00100101 37
f3 = x y z + x y z + x y z + x y z = x y z + x y z + x y z
11111011 11111010 00000101 5
x yz = 5
x yz = 1 The number divisible by 11111011 (decimal value, 5)
xyz = 4 is 11100111 (25) as only 25 is divisible out of the
\ f3 = å (1, 4,5) following numbers.
S3-18 Digital Logic
Let the 4 inputs be (a, b, c, d) and the representation accurate answer. In such situation we can make an
can be given as equation and find out its further progress as is done
f (a, b, c, d) = å (5, 6, 7, 8, 9) below
The K map is given as below : x0 = g0 + p0Cin
x1 = g1 + p1g0 + p1p0Cin
ab x2 = g2 + p2g1 + p2p1p0Cin + P2P1Cin
cd 00 01 11 10
x3 = g3 + p3g2 + p3p2g1 + p3p2p1g0
00 + p3p2p1p0Cin
This shows that total gate delays
1 1 1 =1+1+2+2=6
01 Therefore, the total propagation delay of the adder
is 6 time unit.
11 X X X X 30. (a) The solution is found out using the following
strategy :
10 1 1 X X 1. Convert both numbers into decimal form
2. Multiply the decimal numbers
f (a, b, c, d) = a + bc + bd 3. Find the 8-bit representation of the decimal
= a + b (c + d) number
Therefore, no. of gates required are 3. To get this Now,
more clearly, refer the diagram below constructed A=11111010
using the equations thus obtained as a final result. 1 1 1 1 1
7 6 5 4 3
c = -2 ´ 1 + 2 ´ 1 + 2 ´ 1+ 2 ´ 1+ 2 ´ 1
b (c + d)
d 0 1 0
b a a + b (c + d) + 2 2 ´ 1+ 21 ´ 1+ 20 ´ 1
27. (a) The solution of such questions simply depends = – 27 + 26 + 25 + 24 + 23 + 21
upon the construction of the Kmap and then solving = – 128 + 64 + 32 + 16 + 8 + 2
the equations after getting the desired values from =–6
K map. B = 00001010
The K map is as follows : 0 0 0 0 1
7 6 5 4 3
ab = -2 ´ 0 + 2 ´ 0 + 2 ´ 0 + 2 ´ 0 + 2 ´ 1
c 00 01 11 10
0 1 0
0 0 0 1 1 + 22 ´ 0 + 21 ´ 1 + 20 ´ 0
1 1 1 0 1 = 8 + 2 = 10
Multiplying A and B,
Putting the values of a, b and c from the k map in A · B = – 6 × 10 = – 60
f (a, b, c)= a¢c + ac + b¢c 2’s complement of –60 is 11000100.
= a¢c + ac + b¢c 31. (a) If a number is n-bit long then the most significant bit
= a¢ (b + b¢) c + a (b + b¢) c + (a + a¢) b¢c is the sign bit.
[as (x + x¢) =1] So, we have to start from –2(n–1) as the magnitude is
= a¢bc + a¢b¢c + abc¢ + ab¢c¢ represented in (n – 1) place.
+ ab¢c + a¢b¢c Therefore, the range is –2(n–1) to 2(n–1) – 1 including 0.
= 011 + 001 + 110 + 100 + 101 + 001 32. (a) (657)8 ¾® (110 101 111)2
From this it is concluded that a¢c and ac¢ are (0001
{ 1010 { 111) { ® (1 10 15)
essential prime implicants. 1 10 15
28. (d) The given sequence is 0-2-3-1-0 which can be (IAF)16
represented in binary representation as 33. (a) The K map for the function is as below
0 00 CD
AB 00 01 11 10
2 10
3 11 00 1
0 1 3 2
1 01
0 00
01 1 1
4 5 7 6
This kind of sequence is generated by the input 11 1
Q1 Å Q2 12 13 15 14
Therefore, X = Q1 Å Q2 1 1
10
29. (b) These questions are a little tricky type. We need to 8 9 11 10
stepwise analyze the working of the adder to get the
= BC D + A C D + A B D
S3-20 Digital Logic
1 1 0 F = XY × YZ Þ XY + YZ = F
0 1 1
1 0 0 wx 1 1
8 9 11 10
1 0 1
1 1 0
1 1 1
Now, with the values above in the table, the carry c f = x.z + x.z
will be generated in the following cases: f(w, x, y, z) is independent of w and y variables
a0 = a1 = a2 = 1 = b0 = b1 = b2 45. (c) To construct a 6 × 64 decoder,
or a2 = b2 = 1 or a 2 Å b2 = 1 64
= 8 decoders needed
8
or a1 = b1 = 1 or a1 Å b1 = 1
Now, 1 extra decoder is also needed for combining the
or a0 = b0 = 1 result and hence the total number of decoders needed
Now, checking the values in all the options provided =8+ 1=9
only (a) satisfies the possibilities. 46. (c) Consider a binary constant pi to be the value of the
43. (a) x function f(x1, x2, x3, .... xn) where i is the decimal code.
Now, the switching can be expressed as
0
MUX f ( x1, x 2 , x 3 ,....x n ) = p0 x1¢ x ¢2 ....x ¢n + p1x1¢ x ¢2 ....x ¢n + px1x 2 ....x n
f1
Now,
1 For n variables, distinct minterms or maxterms obtained
y MUX = 2^n
An since the function is either 1 or 0 for each minterm,
z 0
Function formed from n variables = 2^2^n
47. (d) The counter start from 0.
f Now, when the load = 0
1
Count = 1
x The counter starts the count as (top to bottom in the
y table)
S3-22 Digital Logic
f1f2 + f3 = f
0000 (0) With this, the value for f0 = 1, the term in the LHS
0001 (1) should be 4.
0010 (2) The option which satisfy this condition is å m ( 6,8)
0011 (3) 53. (d) 121r = 11r
0100 (4) Þ r ¹ 2 , so, now lets take any value greater than 2.
0101 (5) Let r = 3
58. (b) Here, we need to convert (1217)8 is hexadecimal format sequence is 00.
to get the answer. 63. (a)
Now, (1 2 1 7)8
001 010 001 111 P X=P+Q
which is 001 010 001 111. This is the binary format. We Q
need to convert this into hexadecimal format.
X+Y
So, by dividing the binary code groups of 4
0010 1000 1111
2 8 F = (028F)16 Q
59. (b) R Y=X+Y
P Q F
P A= P+ Q
0 0 R R
1 R A+B
0
1 0 R
Q
1 1 R R B=Q+R
Therefore the output is
F= X+Y+ A+B
F = P Q R + P QR + PQ R + PQR
F = (X + Y) × (A + B)
= R(P Q + PQ) + R(PQ + PQ)
F = (X + Y). (A + B)
= R(P Å R) + R(P Å R) = RX + RX F = XA + XB + YA + YB
= RÅX = RÅPÅR F = (P + Q) × (P + R) + (P + Q) × (Q + R)
60. (a) P = (F87B)16 is 1111 1000 0111 1011 = – 1925
P * 8 = 1925 × 8 = 15400 +(Q + R) × (P + R) + (Q + R) × (Q + R)
2’s complement is 1100 0011 1101 1000 F = (P.Q) × (P.R) + (P.Q).(Q.R) + (Q.R ).(P.R) + (Q.R).(Q.R)
Hence, it is equivalent to (C3D8)16.
61. (a) We need to find the mapping for the RHS, i.e., R = P QR + P Q R + PQ R + Q.R
R
QR
P 11
F = P Q R + Q.R = (P + 1)Q R = Q R
00 01 10
m0 m1 m3 m2 F= Q+ R
0
64. (a) 28 = 256 < 258 < 29
1
PQ + QR + PR m4 m5 m7 m6
A 0
65. (d)
P 1
1
B
1 1
0 = ( A Å B ) = XNOR
Q
A 0
From the figure, we can conclude that B
(m2 m6) Map is for QR
(m7 m6) Map is for PQ
(m4 m6) Map is for PR
( ) (
0 = A Å B = AB Å AB = AB + BA )
Hence, m2 + m4 + m6 + m7 maps for the given term. = A Å B = XNOR
62. (a) Initially Q1Q0 = 00
Next sequence after 00 A 0
Following are the conditions to be considered:
T=0 Next state = present state
B
1 ® I1 PQ
Y x
R ® I2 PQR 79. (c)
P.S. FFinputs N.S.
R ® I3
PQR
Q 2 Q1 Q0 J 2 K 2 J1 K1 J 0 K 0 Q+2 Q1+ Q+0
Q ® S0 (Q1 ) (Q0 ) (Q2 ) (Q2 ) (Q1 ) (Q0 )
P ® S1 0 0 0 1 0 0 1 0 1 1 0 0
Now, note the output of each AND Gate written 1 0 0 1 0 1 0 0 1 1 1 0
individually final output is Y = 0 + PQ + PQR + PQR 1 1 0 0 0 1 0 1 1 1 1 1
The K-Map of this is as follows: 80. (d)
PQ LINKED ANSWER TYPE MCQs
R 00 01 10 81. (d) Hexadecimal representation of a number is easily
0 1 1 found out using a simple technique ® Group binary
digits into groups of four and assign each group a
1 1 1 hexadecimal digit.
Using Above K - Map the minimal sum-of-product Therefore, 0.239 × 213 easily converts to 4D3D.
form is: QR + PQ + PQR 82. (d) The normalized form is for 0.239 × 213 can be found
75. (d) A function F is self dual if it has equal numbers of min out on the two assumptions :
terms and max terms, also mutually exclusive terms are 1. The mantissa has an implicit 1 preceding the
not to be included. binary (radix) point.
2. Only 0’s are padded in while shifting a field.
2n And as the hexadecimal representation is 4D3D,
The number of mutually exclusive terms is = 2n–1
2 therefore the normalized representation of 0.239
No. of functions possible by taking any of the one × 213 is 4AE8.
terms from the above mentioned mutually exclusive
n -1
NUMERICAL ANSWER QUESTIONS
pair = 22
76. (c) In case of decoder output, single output will be that 1 83. (a)
and remaining will be zero at any time. The output I4 I3 I2 I1 R3 R2 R1 LSB
that is high will give the count of the ring counter at Input LSB Output
that time.
77. (b) The K-map for the function F is 0 0 0 0 0 0 0
RS RS RS RS 0 0 0 1 0 0 1
RS
PQ 0 0 1 0 0 1 0
1 f
0 0 1 1 0 1 1
PQ
0 1 0 0 1 0 0
0 1 0 1 1 0 1
PQ 1 f
0 1 1 0 0 0 0
f 1 0 1 1 1 0 0 1
PQ
1 0 0 0 0 1 0
PQ f 1 1 0 0 1 0 1 1
S3-26 Digital Logic
Remember: 85. (a) Full Adder
(i) The input should have 4 bits or output should have 3 S =a ÅbÅc
bits. C = ab + ac + bc
(ii) You may use “T” for I and “F” for zero. Given data A = a2a1a0
(iii) The order R3 R2 R1 is very important as I4I3I2I1 b = b2b1b0
(b) INPUT OUTPUT Z = Z3Z2Z1Z0
L.S.B.
I1R1 = I1
I1 Input A 110 011 111 101 000 000 000 000
B 101 101 011 110 000 000 000 000
I2
Clock No. 1 2 3 4 5 6 7 8
R2 = I2I2 + I4 For Clock No. 1
a0b0 = 01 If clock = 0, for bit 010
a1b1 = 10 Z0 = 1, C =0 Next bit 100, Z1 = 1, C = 0
a2b2 = 11 Next bit 110, Z2 = 0, Z3 = 1
84. (a) Given, f(x, y, z) = xy + yz Z = Z3Z2Z1Z0 = 1011 = BH
For Clock No. 2 Clock = 0
Complement of the f(x, y, z) = xy + yz a0b0 = 11 First bit = 110, Z0 = 0, C = 1
a1b1 = 10 Next bit = 101, Z1 = 0, C = 1
= x y + yz a2b2 = 01 Next bit = 111, Z2 = 0, Z3 = 1
Z = Z3Z2Z1Z0 = 1000 = 08H
= x y.yz For Clock No. 3 Clock = 0
a0b0 = 11 First bit = 100, Z0 = 1, C = 0
(
= x+y y+z )( ) a1b1 = 01 Next bit = 010, Z1 = 1, C = 0
a2b2 = 01 Next bit = 110 Z2 = 0 Z3 = 1
= xy + xz + yz Z = Z3Z2Z1Z0 = 1010 = AH
K-map for, xy + xz + yz For Clock No. 4 Clock = 0
a0b0 = 10 First bit = 100, Z0 = 1, C = 0
xy a1b1 = 01 Next bit = 010, Z1 = 1, C = 0
00 01 11 10
a2b2 = 11 Next bit = 110 Z2 = 0 Z3 = 1
z Z = Z3Z2Z1Z0 = 1011 = B
1 For Clock No. 5 Z0 = 0000H Clock No = – 7
For Clock No. 6 Z0 = 0000H Z = 0000 H
1 1 1 Clock No. 8, Z = 0000 H
(b) Circuit implement in the form of octal to hexadecimal,
so circuit look like a convertor.
F ( x, y, z ) = xy + yz 86. 5
= x.y + yz We know that how to convert a number of a given base
‘b’ to base 10; for example:
x x+y (4102.3)6 = (4 × 63) + (1 × 62) + (0 × 61) + (2 × 60)
y + (3 × 6–1)
x + y + yz Now, we also know that if an equation holds for base ‘b’
it will hold for any base ‘b’ if all numbers of the equation
are converted to b' (both sides of the equation).
z The given equation is:
312 (312)b
= 13.1 OR = (13.1)b
(b) 20 (20)b
Let the base of the given equation is ‘b’. We shall
convert all numbers from base ‘b’ to base ‘10’ as follows:
(3 ´ b2 ) + (1´ b1 ) + (2 ´ b0 )
= (1´ b1 ) + (3 ´ b0 ) + (1´ b -1 )
1 0
(2 ´ b ) + (0 ´ b )
3b2 + b + 2 1
Þ = b +3+
Equivalent logic gate employs only 6 NAND GATES 2b b
æ b 2 + 3b + 1 ö
Þ 3b2 + b + 2 = 2b ç ÷
ç b ÷
è ø
2
Þ b – 5b = 0
Þ b (b – 5) = 0
Þ b = 0 or b = 5
Since base can not be 0, so the required base = 5.
2 Computer Organisation
Chapter & Architecture
Quick Revision Material
MACHINE INSTRUCTIONS
1. Data Transfer Instructions :
Data transfer instructions are used to transfer of data from one address to another without changing the contents.
Data Transfer Instructions
ADDRESSI NG MO DES
All addressing modes with Examples
Register Add R4, R3 Regs [R4] ¬ Regs [R4] When a value is in a register.
+ Regs[R3]
Register Add R4, (R1) Regs [R4] ¬ Regs [R4] Accessing using a pointer
indirect + Mem[Regs[R1]] or a compound address
Indexed Add R3, (R1 + R2) Regs [R3] ¬ Regs [R3] Sometimes useful in array
+ Mem[Regs[R1] + Regs [R2]] addressing: R1 = base of array;
R2 = index amount
Computer Organisation & Architecture S3-29
Hit ratio = (no. of cache hits) / (Total no. of memory references) Cache size equation
Mappings Functions Simple equation for the size of a cache:
1. Direct Mapping : (Cache size) = (Block size) × (Number of sets)
In this technique each block of main memory can only go to × (Set Associativity)
a single fixed position in cache. A single block of cache is a • Can relate to the size of various address fields:
possible candidate for few fixed blocks of main memory. (Block size) = 2(# of offset bits)
This mapping is expressed as : (Number of sets) = 2(# of index bits)
i = j modulo m where, i = cache block number (# of tag bits) = (# of memory address bits)
j = main memory block number – (# of index bits) – (# of offset bits)
m = number of blocks in cache Cache Hierarchy
This mapping can be implemented by dividing the 24-bits Average access time
of address into three parts. The least significant w-bits are = T1 + (1 – h1) [ T2 + (1 – h2)Tm ]
used to identify a word within a block. The remaining s-bits Where
are used to identify a main memory block among 2s blocks. • T1 = L1 cache access time (smallest)
This field of s-bits is again divided into two parts for cache • T2 = L2 cache access time (small)
: r-bits line field(least significant) and s-r bits tag field (most • Tm = memory access time (large)
significant). The line field identifies one cache line among • h1, h2 = hit rates (0 £ h1, h2 £ 1)
2r lines of cache. Average access time reduces by adding a cache.
2. Set Associative Mapping : CPU time as
• Address length = (s + w) bits CPUTime = (CC + CC )×t
CPU Execution MemoryStalls CC
• Number of addressable units Cache Performance
= 2s + w words or bytes The memory-stall clock cycles come from cache misses.It can be
• Block size = line size = 2w words or bytes defined as the sum of the stall cycles coming from writes + those
coming from reads:
2s + w
• Number of blocks in main memory = = 2s Memory-Stall CC = Read-stall cycles + Write-stall cycles, where
w
2
Re ads
• Number of lines in set = k Re ad - stall cycles = ´ Read Miss Rate´ Read Miss Penalty
Pr ogram
• Number of sets v = 2d
æ Writes ö
• Number of lines in cache = kv = k × 2d Write - stall cycles = ç ´ Write Miss Rate ´ Write Miss Penalty ÷
è Pr ogram ø
• Size of tag = (s – d) bits
+ WriteBufferStalls
For all cases we consider the following configuration:
Cache Performance Formulas
· Cache Block size=4 bytes and data can be transferred in
Useful formulas for analyzing ISA/cache interactions :
multiples of blocks,
· Cache size = 64 KB, hence cache contains 214 Blocks (called (CPU time) = [(CPU cycles) + (Memory stall cycles)]
“Cache Lines”) × (Clock cycle time)
· Main memory block size = 4 bytes (Memory stall cycles) = (Instruction count) ×
· Main memory size = 16MB, hence main memory contains (Accesses per instruction) × (Miss rate) × (Miss penalty)
222 Blocks You Can split access time into instructions & data:
· Each byte of main memory is directly addressable by a 24- Avg. mem. acc. time = (% instruction accesses) × (inst. mem.
bit address (as 224 = 16M) access time) + (% data accesses) × (data mem. access time)
• Address length = (s + w) bits
Another simple formula:
• Number of addressable units = 2s + w words or bytes
CPU time = (CPU execution clock cycles + Memory stall
• Block size = line size = 2w words or bytes
clock cycles) × cycle time
2s + w Factoring out Instruction Count
• Number of blocks in main memory = = 2s words or bytes
2 w CPU time = IC ´ Clock cycle time ´
14. The performance of a pipelined processor suffers if (a) I/O protection is ensured by operating system
[2002, 2 Marks] routine(s)
(a) the pipeline stages have different delays (b) I/O protection is ensured by a hardware trap
(b) consecutive instructions are dependent on each other (c) I/O protection is ensured during system configuration
(c) the pipeline stages share hardware resources (d) I/O protection is not possible
(d) All of the above 22. Which one of the following is true for a CPU having a single
15. Horizontal micro – programming [2002, 2 Marks] interrupt request line and a single interrupt grant line?
(a) does not require use of signal decodes [2005, 1 Mark]
(b) results in larger sized micro-instructions than vertical (a) Neither vectored interrupt nor multiple interrupting
micro – programming devices are possible
(c) uses one bit for each control signal (b) Vectored interrupt are not possible but multiple
(d) All of the above
interrupting devices are possible
16. Which of the following addressing modes are suitable
(c) Vectored interrupt and multiple interrupting are both
for program relocation at run time? [2004, 1 Mark]
1. Absolute addressing 2. Relative addressing possible
3. Based addressing 4. Indirect addressing (d) Vectored interrupt is possible but multiple interrupting
(a) 1 and 4 (b) 1 and 2 devices are not possible
(c) 2 and 3 (d) 1, 2 and 4 23. For a magnetic disk with concentric circular tracks, the seek
17. For a pipelined CPU with a single ALU, consider the latency is not linearly proportional to the seek distance due
following situations [2004, 1 Mark] to [2008, 1 Mark]
1. The j + 1st instruction uses the result of the j th (a) non-uniform distribution of requests
instruction as an operand. (b) arm starting and stopping inertia
2. The execution of a conditional jump instruction. (c) higher capacity of tracks on the periphery of the platter
3. The j th and ( j + 1) st instrution require the ALU at (d) use of unfair arm scheduling policies
the same time. 24. For inclusion to hold between two cache levels L1 and L2
Which of the above can cause a hazard? in a multi-level cache hierarchy, which of the following are
(a) 1 and 2 (b) 2 and 3 necessary?
(c) 3 only (d) All 1. L1 must be a write-through cache.
18. Match each of the high level language statements given on 2. L2 must be a write-through cache.
the left hand side with the most natural addressing mode 3. The associativity of L2 must be greater than that of
from those listed on the right hand side. [2005, 1 Mark] L1.
4. The L2 cache must be at least as large as the L1
List - I List - II cache. [2008, 2 Marks]
P. A[l] = B[l] 1. Indirect addressing (a) 4 only (b) 1 and 4
(c) 1, 2 and 4 (d) 1, 2, 3 and 4
Q. while (* A ++); 2. Indexed addressing 25. Which of the following are not true in a pipelined
R. int temp = * x; 3. Auto increment processor ?
1. Bypassing can handle all RAW hazards.
(a) P - 3, Q - 2, R - 1 (b) P - 1, Q - 3, R - 2 2. Register renaming can eliminate all register carried
(c) P - 2, Q - 3, R - 1 (d) P - 1, Q - 2, R - 3 WAR hazards.
19. Increasing the RAM of a computer typically improved 3. Control hazard penalties can be eliminated by dynamic
performance because [2005, 1 Mark] branch prediction. [2008, 2 Marks]
(a) virtual memory increases (a) 1 and 2 (b) 1 and 3
(b) larger RAM are faster (c) 2 and 3 (d) 1, 2 and 3
(c) fewer page faults occur 26. The use of multiple register windows with overlap causes
(d) fewer segmentation faults occur a reduction in the number of memory accesses for
20. What is the swap space in the disk used for? 1. function locals and parameters
(a) Saving temporary HTML pages [2005, 1 Mark] 2. register saves and restores
(b) Saving process data 3. instruction fetches [2008, 2 Marks]
(c) Storing the super-block (a) 1 only (b) 2 only
(d) Storing device drivers (c) 3 only (d) 1, 2 and 3
21. Normally user programs are prevented from handling I/O 27. In an instruction execution pipeline, the earliest that the
directly by I/O instructions in them. For CPUs having explicit data TLB (Translation Look a side Buffer) can be
I/O instructions, such I/O protection is ensured by having accessed is [2008, 2 Marks]
the I/O instructions privileged. In a CPU with memory (a) before effective address calculation has started
mapped I/O, there is no explicit I/O instruction. Which one (b) during effective address calculation
of the following is true for a CPU with memory mapped I/O? (c) after effective address calculation has completed
[2005, 1 Mark] (d) after data cache lookup has completed
Computer Organisation & Architecture S3-33
28. Which of the following is/are true of the auto-increment 34. Consider the following sequence of micro-operations.
addressing mode? [2008, 2 Marks] MBR ¬ PC
1. It is used in creating self-relocating code. MAR ¬ X
2. If it is included in an Instruction Set Architecture, then PC ¬ Y
an additional ALU is required for effective address Memory ¬ MBR
calculation. Which one of the following is a possible operation
performed by this sequence? [2013, 2 Marks]
3. The amount of increment depends on the size of the
(a) Instruction fetch
data item accessed.
(b) Operand fetch
(a) 1 only (b) 2 only (c) Conditional branch
(c) 3 only (d) 2 and 3 (d) Initiation of interrupt service
29. Which of the following must be true for the REF (Return 35. In designing a computer’s cache system, the cache block
From Exception) [2008, 2 Marks] (or cache line) size is an important parameter. Which one of
1. It must be a TRAP instruction. the following statements is correct in this context?
2. It must be a privileged instruction. [2014, Set-2, 2 Marks]
3. An exception cannot be allowed to occur during (a) A smaller block size implies better spatial locality
execution of an REE instruction. (b) A smaller block size implies a smaller cache tag and
(a) 1 only (b) 2 only hence lower cache tag overhead
(c) 1 and 2 (d) 1, 2 and 3 (c) A smaller block size implies a larger cache tag and
30. A CPU generally handles an interrupt by executing an hence lower cache hit time
interrupt service routine [2009, 1 Mark] (d) A smaller block size incurs a lower cache miss penalty
(a) as soon as an interrupt as raised 36. If the associativity of a processor cache is doubled while
keeping the capacity and block size unchanged, which one
(b) by checking the interrupt register at the end of fetch
of the following is guaranteed to be NOT affected?
cycle
[2014, Set-2, 2 Marks]
(c) by checking the interrupt register after finishing the (a) Width of tag comparator
execution of the current instruction (b) Width of set index decoder
(d) by checking the interrupt register at fixed time intervals (c) Width of way selection multiplexor
31. A computer handles several interrupt sources of which of (d) Width of processor to main memory data bus
the following are relevant? [2012, 1 Mark]
Interrupt from CPU temperature sensor Problem Based MCQs
Interrupt from Mouse
Interrupt from Keyboard 37. Consider the values of A = 2.0 × 103 , B = – 2.0 × 1030,
C = 1.0, and the sequence
Interrupt from Hard disk
X=A+B Y=A+C
(a) Interrupt from Hard disk
X=X+C Y=Y+B
(b) Interrupt from Mouse
Executed on a computer where floating point numbers are
(c) Interrupt from Keyboard represented with 32 bit. The values for X and Y will be
(d) Interrupt from CPU temperature sensor [2000, 2 Marks]
32. Consider a hypothetical processor with an instruction of (a) X = 1.0, Y = 1.0 (b) X = 1.0, Y = 0.0
type LW (R1), 20 (R2). which during execution reads a 32- (c) X = 0.0, Y = 1.0 (d) X = 0.0, Y = 00
bit word from memory and stores it in a 32-bit register R1. 38. Consider the following data path of a simple
The effective address of the memory location is obtained non-pipelined CPU. The registers A, B, A1, A2, MDR, the
by the addition of constant 20 and the contents of register bus and the ALU are 8-bit wide, SP and MAR are 16 - bit
R2. Which of the following best reflects the addressing registers. The MUX is of size 8 × (2 : 1) and the DEMUX
mode implemented by this instrument for the operand in is of size 8 × (1 : 2). Each memory operation takes 2 CPU
memory? clock cycles and uses MAR (Memory Address Register)
(a) Immediate addressing [2012, 1 Mark] and MDR (Memory Date Register). SP can be decremented
(b) Register addressing locally.
(c) Register indirect scalled addressing
(d) Base indexed addressing
33. Register renaming is done in pipelined processors A2 A1
[2012, 1 Mark] B A MUX DEMUX
(a) as an alternative to register allocation at comptile time 1:2 1:2
(b) for efficient access to function parameters and local
variables dcr SP MAR MDR
(c) to handle certain kinds of hazards
(d) as part of address translation
S3-34 Computer Organisation & Architecture
47. Consider a three word machine instruction: 52. A CPU has a five-stage pipeline and runs at 1 GHz
ADD A[R0], @ B frequency. Instruction fetch happens in the first stage of
The first operand (destination) “A[R0 ]” uses indexed the pipeline. A conditional branch instruction computes
addressing mode with R0 as the index register. The second the target addresses and evaluates the condition in the
operand (source) “@B” uses indirect addressing mode. A third stage of the pipeline. The processor stop fetching
and B are memory addresses residing at the second and the new instructions following a conditional branch until the
third words, respectively. The first word of the instruction branch outcome is known. A program executes 109
specifies the opcode, the index register designation and instructions out of which 20% are conditional branches. If
the source and destination addressing modes. During each instruction takes one cycle to complete on average,
execution of ADD instruction, the two operands are added the total execution time of the program is [2006, 2 Marks]
and stored in the destination (first operand). (a) 1.0 s (b) 1.2 s
The number of memory cycles needed during the execution (c) 1.4 s (d) 1.6 s
cycle of the instruction is [2005, 1 Mark] 53. A CPU has a cache with block size 64 byte. The main memory
(a) 3 (b) 4 has k banks, each bank being c byte wide. Consecutive
(c) 5 (d) 6
c-byte chunks are mapped on consecutive banks with
48. A device with data transfer rate 10 kbyte/s is connected
wrap-around. All the k blanks can be accessed in parallel,
to a CPU. Data is transferred byte wise. Let the interrupt
but two accesses to the same bank must be serialized. A
overhead be 4 ms. The byte transfer time between the cache block access may involve multiple iterations of parallel
device interfaces register and CPU or memory is negligible. bank accesses depending on the amount of data obtained
What is the minimum performance gain of operating the by accessing all the k banks is parallel. Each iteration
device under interrupt mode over operating it under
requires decoding the bank numbers to be accessed in
program controlled mode? [2005, 2 Marks]
(a) 15 (b) 25 k
(c) 35 (d) 45 parallel and this takes ns. The latency of one bank access
2
49. Consider a disk drive with the following specification : is 80 ns. If c = 2 and k = 24, the latecy of retrieving a cache
16 surfaces, 512 tracks/surface, 512 sectors/track, 1 kbyte/ block starting at address zero from main memory is
sector, rotation speed 3000 rpm. The disk is operated in [2006, 2 Marks]
cycle stealing mode whereby whenever one 4 byte word (a) 92 ns (b) 104 ns
is ready it is sent to memory; similarly, for writing, the
(c) 172 ns (d) 184 ns
disk interface reads a 4 byte word from the memory in
54. A CPU has 24-bit instructions. A program starts at address
each DMA cycle. Memory cycle time is 40 ns. The
maximum percentage of time that the CPU gets blocked 300 (in decimal). Which one of the following is a legal
during DMA operation is [2005, 2 Marks] program counter (all values in decimal)? [2007, 1 Mark]
(a) 10 (b) 25 (a) 400 (b) 500
(c) 40 (d) 50 (c) 600 (d) 700
50. Consider a multiplexer with X and Y as data inputs and 55. Consider a disk pack with 16 surfaces, 128 tracks per surface
Z as control input. Z = 0 selects input X, and Z = 1 selects and 256 sectors per track. 512 byte of data are stored in a bit
input Y. What are the connections required to realize the serial manner in a second. The capacity of the disk pack
2 - variable Boolean function f = T + R, without using any and the number of bits required to specify a particular section
additional hardware? [2005, 2 Marks] in the disk are respectively [2007, 1 Mark]
(a) R to X, 1to Y, T to Z (a) 256 Mbyte, 19 bit (b) 256 Mbyte, 28 bit
(b) T to X, R to Y, T to Z (c) 512 Mbyte, 20 bit (d) 64 Gbyte, 28 bit
(c) T to X, R to Y, 0 to Z 56. Consider a 4-way set associate cache consisting of 128
(d) R to X, 0 to Y, T to Z
lines with a line size of 64 words. The CPU generates a 20-
51. Consider a new instruction named branch-on-bit-set
bit address of word in main memory. The number of bits in
(mnemonic bbs). The instruction “bbs reg, pos, label” jumps
the TAG, LINE and WORD fields are respectively.
to label if bit in position pos of register operand reg is one.
A register is 32 bit wide and the bits are numbered 0 to 32, [2007, 1 Mark]
bit in position 0 being the least significant. Consider the (a) 9, 6, 5 (b) 7, 7, 6
following emulation of this instruction on a processor that (c) 7, 5, 8 (d) 9, 5, 6
does not have bbs implemented. 57. Consider a pipelined processor with the following four
tem ¬ reg and mask stages
Branch to lable if temp is non-zero IF : Instruction Fetch
The variable temp is a temporary register. For correct
ID : Instruction Decode and Operand Fetch
emulation, the variable mask must be generated by
(a) mask ¬ 0 × 1 << pos [2006, 2 Marks] EX : Execute
(b) mask ¬ 0 × ffffffff << pos WB : Write Black
(c) mask ¬ pos The IF, ID and WB stages take 1 clock cycle each to complete
(d) mask ¬ 0 × f the operation.
S3-36 Computer Organisation & Architecture
· The number of clock cycle for the EX stage depends 62. On a non-pipelined sequential processor, a program
on the instruction. the ADD and SUB instructions need 1 segment, which is a part of the interrupt service routine, is
clock cycle and the MUL instruction needs 3 clock cycles give to transfer 500 byte from an I/O device to memory
in the EX stage. Operand forwarding is used in the pipelined Initialize the address register
processor. What is the number of clock cycles taken to Initialize the count to 500
complete the following sequence of instructions: LOOP: Load a byte from device
[2007, 2 Marks] Store in memory at address given by address register
ADD R2, R1, R0 R2 ¬ R1 + R0 Increment the address register
Decrement the count
MUL R4, R3, R2 R4 ¬ R3 * R2
If count! = 0 goto LOOP
SUB R6, R5, R4 R6 ¬ R5 – R4
Assume that each statement in this program is equivalent
(a) 7 (b) 6 to a machine instruction which takes one clock cycle to
(c) 10 (d) 14 executive if it is a non-load/store instruction. The load-store
58. How many 32 k × 1 RAM chips are needed to provide a instructions take two clock cycles to execute. The designer
memory capacity of 256 kbyte? [2009, 1 Mark] of the system also has an alternate approach of using the
(a) 8 (b) 32 DMA controller to implement the same transfer. The DMA
(c) 64 (d) 128 controller required 20 clock cycles for initiallization and other
59. A main memory unit with a capacity of 4 megabyte is built overheads. Each DMA transfer cycle takes two clock cycles
using 1 M × 1 bit DRAM chips. Each DRAM chip has 1 to transfer one byte of data from the device to the memory.
rows of cells with 1 k cells in each row. The time taken for a What is the approximate speed up when the DMA controller
single refresh operation is 100 ns. The time required to based design is used in place of the interrupt driven program
based input-output? [2011, 2 Marks]
perform one refresh operation on all the cells in the memory
(a) 3.4 (b) 3.5
unit is [2010, 1 Mark]
(c) 3.3 (d) None of these
(a) 100 ns (b) 100 * 2 ns 10
63. Consider a 4 stage pipeline processor. The number of cycles
(c) 100 * 2 ns 20 (d) 3200 * 220 ns needed by the four instructions I1, I2, I3, I4 in stages S1, S2,
60. Consider a 4-way set associative cache (initially empty) S3, S4 is shown below.
with total 16 cache blocks. The main memory consists of
256 blocks and the request for memory block is in the S1 S2 S3 S4
following order: I1 2 1 1 1
0, 255, 1, 4, 3, 8, 133, 159, 216, 129, 63, 8, 48, 32, 73, 92, 155 I2 1 3 2 2
Which one of the following memory blocks will not be in
I3 2 1 1 3
cache if LRU replacement policy is used? [2010, 2 Marks]
I4 1 2 2 2
(a) 3 (b) 8
(c) 129 (d) 216
What is the number of cycles needed to execute the following
61. A 5-stage pipelined processor has Instruction Fetch (IF),
loop? [2010, 2 Marks]
Instruction Decode (ID), Operand Fetch (OF), Perform For (i = 1 to 2) {I1; I2; I3; I4;}
Operation (PO) and Write Operand (WO) stages. The IF, (a) 16 (b) 23
ID, OF and WO stages take 1 clock cycle each for any (c) 28 (d) 30
instruction. The PO stage takes 1 clock cycle for ADD and 64. An 8 kbyte direct mapped write-back cached is organized
SUB instructions, 3 clock cycles for MUL instruction, and 6 as multiple blocks, each of size 32 byte. The processor
clock cycles for DIV instruction respectively. Operand generates 32-bit addresses. The cache controller maintains
forwarding is used in the pipeline. What is the number of the tag information for each cache block comprising of the
clock cycles needed to execute the following sequence of following
the instructions? [2010, 2 Marks] 1 Valid bit
Instruction Meaning of instruction 1 Modified bit
As many bits as the minimum needed to identify the memory
I0: MUL R2, R0,R1 R2 ® R0 * R1
block mapped in the cache.
I1: DIV R5, R3, R4 R5 ® R3 / R4
What is the total size of memory needed at the cache
I2: ADD R2, R5, R2 R2 ® R5 + R2 controller to store metadata (tags) for the cache?
I3: SUB R5, R2, R6 R5 ® R2 – R6 [2011, 2 Marks]
(a) 13 (b) 15 (a) 4864 bit (b) 6144 bit
(c) 17 (d) 19 (c) 6656 bit (d) 5376 bit
Computer Organisation & Architecture S3-37
65. Consider an instruction pipeline with four stages (S1, S2, (a) 1281 (b) 1282
S3 and S4) each with combinational circuit only. The pipeline (c) 1283 (d) 1284
registers are required between each stage and at the end of 70. A RAM chip has a capacity of 1024 words of 8 bits each
the last stage. Delays for the stages and for the pipeline (1K × 8). The number of 2 × 4 decoders with enable line
registers are as given in the figure [2011, 2 Marks] needed to construct a 16K × 16 RAM from 1K × 8
RAM is [2013, 2 Marks]
State Pipeline State State (a) 4 (b) 5
Pipeline
S1 register S2 register S3 (c) 6 (d) 7
Þ delay Þ Þ delay Þ 71. Consider an instruction pipeline with five stages without
delay delay delay
5ns 1 ns 6ns 1 ns 11ns any branch prediction: Fetch Instruction (FI), Decode
Instruction (DI), Fetch Operand (FO), Execute Instruction
(EI) and Write Operand (WO). The stage delays for FI,
DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns,
State Pipeline respectively. There are intermediate storage buffers after
Pipeline
S each stage and the delay of each buffer is 1 ns. A
/ delay Þ 4 Þ register program consisting of 12 instructions I1, I2, I3, ..., I12 is
1 ns delay delay
8ns 1 ns executed in this pipelined processor. Instruction I4 is the
only branch instruction and its branch target is I9. If the
What is the approximate speed up of the pipeline in steady branch is taken during the execution of this program, the
state under ideal conditions when compared to the time (in ns) needed to complete the program is
corresponding non-pipeline implementation? [2013, 2 Marks]
(a) 4.0 (b) 2.5 (a) 132 (b) 165
(c) 1.1 (d) 3.0 (c) 176 (d) 328
66. Let the page fault service time be 10 Ms in a computer with 72. Consider the following processors (ns stan ds for
average memory access time being 20 ns. If one page fault nanoseconds). Assume that the pipeline registers have zero
is generated for every 106 memory accesses, what is the latency.
effective access time for the memory? [2012, 1 Mark] P1: Four-stage pipeline with stage latencies 1 ns, 2 ns, 2 ns,
(a) 21 ns (b) 30 ns 1 ns.
(c) 23 ns (d) 35 ns P2: Four-stage pipeline with stage latencies 1 ns, 1.5 ns, 1.5
67. The amount of ROM needed to implement a 4 bit multiplier ns, 1.5 ns.
is [2012, 1 Mark] P3: Five-stage pipeline with stage latencies 0.5 ns, 1 ns, 1
(a) 64 bit (b) 128 bit ns, 0.6 ns, 1 ns.
(c) 1 k bit (d) 2 k bit P4: Five-stage pipeline with stage latencies 0.5 ns, 0.5 ns, 1
68. In a k-way set associative cache, the cache is divided ns, 1 ns, 1.1 ns.
into v sets, each of which consists of k lines. The lines Which processor has the highest peak clock frequency?
of a set are placed in sequence one after another. [2014, Set-3, 1 Mark]
The lines in set s are sequenced before the lines in set (a) P1 (b) P2
(s + 1). The main memory blocks are numbered 0 (c) P3 (d) P4
onwards. The main memory block numbered j must be 73. An access sequence of cache block addresses is of length
mapped to any one of the cache lines from N and contains n unique block addresses. The number of
[2013, 1 Mark] unique block addresses between two consecutive accesses
(a) (j mod v) * k to (j mod v) * k + (k – 1) to the same block address is bounded above by k. What is
(b) (j mod v) to (j mod v) + (k – 1) the miss ratio if the access sequence is passed through a
(c) (j mod k) to (j mod k) + (v – 1) cache of associativity A ³ k exercising least-recently-used
(d) (j mod k) * v to (j mod k) * v + (v – 1) replacement policy? [2014, Set-1, 2 Marks]
69. Consider a hard disk with 16 recording surfaces (0-15) (a) n/N (b) 1/N
having 16384 cylinders (0-16383) and each cylinder (c) 1/A (d) k/n
contains 64 sectors (0-63). Data storage capacity in each 74. The value of a float type variable is represented using the
sector is 512 bytes. Data are organised cylinder-wise and single-precision 32-bit floating point format of IEEE-754
the addressing format is < cylinder number, surface standard that uses 1 bit for sign, 8 bits for biased exponent
number, sector number >. A file of size 42797 KB is stored and 23 bits for mantissa. A float type variable X is assigned
in the disk and the starting disk location of the file is the decimal value of –14.25. The representation of X in
< 1200, 9, 40 >. What is the cylinder number of the last hexadecimal notation is [2014, Set-2, 2 Marks]
sector of the file, if it is stored in a contiguous manner? (a) C1640000H (b) 416C0000H
[2013, 2 Marks] (c) 41640000H (d) C16C0000H
S3-38 Computer Organisation & Architecture
83. Assume that the memory is byte addressable and the word c = a + b;
size is 32 bit. If an interrupt occurs during the execution of d = c * a;
the instruction INC R3, what return address will be pushed e = c + a;
on to the stack? [2007, 2 Marks] x = c * c;
if (x > a) {
(a) 1005 (b) 1020
y = a * a;
(c) 1024 (d) 1040 }
Common Data for Questions 84, 85 and 86 else {
Consider a machine with a 2-way set associative data cache of d = d * d;
size 64 kbyte and block size 16 byte. The cache is managed using e = e * e;
32 bit virtual addresses and the page size is 4 kbyte. A program to }
be run on this machine begins as follows. 89. Suppose the instruction set architecture of the processor
double ARR [1024] [1024] has only two registers. The only allowed compiler
int i, j; optimization is code motion, which moves statements
/* Initialize array ARR to 0.0 */ from one place to another while preserving correctness.
What is the minimum number of spills to memory in the
for (i = 0; i < 1024; i ++)
compiled code? [2013, 2 Marks]
for (j = 0; j < 1024; j ++) (a) 0 (b) 1
ARR [i] [j] = 0.0; (c) 2 (d) 3
The size of double is 8 byte. Array ARR is located in memory
starting at the beginning of virtual page 0 × FF000 and stored in 90. What is the minimum number of registers needed in the
row major order. The cache is initially empty and no pre-fetching instruction set architecture of the processor to compile
this code segment without any spill to memory? Do not
is done. The only data memory references made by the program
apply any optimization other than optimizing register
are those to array ARR.
allocation. [2013, 2 Marks]
84. The total size of the tags in the cache directory is (a) 3 (b) 4
[2008, 2 Marks] (c) 5 (d) 6
(a) 32 kbit (b) 34 kbit
(c) 64 kbit (d) 68 kbit Linked Answer Type MCQs
85. Which of the following array elements has the same cache
index as ARR [0] [0] ? [2008, 2 Marks] Statements for Linked Answer Questions 91 and 92
(a) ARR [0] [4] (b) ARR [4] [0] A CPU has a 32 kbyte direct mapped cache with 128-byte block
(c) ARR [0] [5] (d) ARR [5] [0] size. Suppose A is a two-dimensional array of size 512 × 512
86. The cache hit ratio for this initialization loop is with elements that occupy 8-byte each. Consider the following
two C code segments, P1 and P2
[2008, 2 Marks]
P1 : for (i = 0; i < 512; i + +) {
(a) 0% (b) 25% for (j = 0; j < 512; j + +) {
(c) 50% (d) 75% x + = A [i] [j];
Common Data for Questions 87 and 88 : }
A hard disk has 63 sectors per track, 10 platters each with 2 }
recording surfaces and 1000 cylinders. The address of a sector is P2 : for (i = 0; i < 512; i + +) {
given as a triple (c, h, s), where c is the cylinder number, h is the for (j = 0; j < 512; j + +) {
surface number and s is the sector number. Thus, the 0th sector x + = A [j] [i];
}
is addressed as 0, 0, 0 , the 1st sector as 0, 0,1 , and so on. }
87. The address < 400, 16, 29 > corresponds to sector number P1 and P2 are executed independently with the same initial
[2009, 2 Marks] state, namely, the array A is not in the cache and i, j, x
(a) 505035 (b) 505036 are in registers. Let the number of cache misses
(c) 505037 (d) 505038 experienced by P1 be M1 and that for P2 be M2.
91. The value of M1 is [2006, 2 Marks]
88. The address of the 1038th sector is [2009, 2 Marks]
(a) zero (b) 2048
(a) < 0, 15, 31> (b) < 0, 16, 30> (c) 16384 (d) 262144
(c) < 0, 16, 31> (d) < 0, 17, 31>
Common Data for Questions 89 and 90: M1
92. The value of the ratio is [2006, 2 Marks]
The following code segment is executed on a processor which M2
allows only register operands in its instructions. Each 1
instruction can have atmost two source operands and one (a) Zero (b)
16
destination operand. Assume that all variables are dead after
1
this code segment. [2013, 2 Marks] (c) (d) 16
8
S3-40 Computer Organisation & Architecture
Statements for Linked Answer Questions 93 and 94: Statement for Linked Answer Questions 97 and 98 :
Consider the following data path of a CPU: Delayed branching can help in the handling of control hazards.
97. For all delayed conditional branch instructions, irrespective
MAR MDR of whether the condition evaluations to true or false.
[2008, 2 Marks]
(a) the instruction following the conditional branch
instruction in memory is executed
(b) the first instruction in the fall through path is executed
(c) the first instruction in the taken path is executed
S T (d) the branch taken longer to execute than any other
instruction
IR PC GPRs 98. The following code is to run on a pipelined processor with
one branch delay slot: [2008, 2 Marks]
ALU l1: ADD R2 < R7 + R8
l2: SUB R4 ¬ R5 – R6
l3: ADD R1 ¬ R2 + R3
The ALU, the bus and all the registers in the data path are of l4: STORE Memory [R4] ¬ R1
identical size. All operations including incrementation of the PC BRANCH to Label if R1 = 0
and the GPRs are to be carried out in the ALU. Two clock cycles Which of the instructions I1, I2, I3 or I4 can legitimately
are needed for memory bus into the MDR. occupy the delay slot without any other program
93. The instruction “ADD R0, R1” has the register transfer modification?
interpretation R0 < = R0 + R1. The minimum number of clock (a) I1 (b) I2
cycles needed for execution cycle of this instruction is (c) I3 (d) I4
[2005, 1 Mark]
Statements for Linked Answer Questions 99 and 100 :
(a) 2 (b) 3
(c) 4 (d) 5 The computer system has an L1 L2 cache, an L2 cache and a main
94. The instruction “CALL Rn, sub” is a two word instruction. memory unit connected as shown below. The block size in L1
Assuming that PC is incremented during the fetch cycle of cache is 4 words. The block size in L2 cache is 16 words. The
the first word of the instruction, its register transfer memory access times are 2 ns, 20 ns and 200 ns, for L1 cache, L2
interpretation is cache and main memory unit respectively.
Rn < = PC + 1
PC < = M [PC] Data bus Data bus
The minimum number of CPU clock cycles needed during L1 L2 Main
the execution cycle of this instruction is [2005, 1 Mark] Cache memory
Cache
(a) 2 (b) 3 4 words 4 words
(c) 4 (d) 5
Statements for Linked Answer Questions 95 and 96 : 99. When there is a miss in L1 cache and a hit in L2 cache, a
Consider a machine with a byte addressable main memory of 216 block is transferred from L2 cache to L1 cache. What is the
byte. Assume that a direct mapped data cache consisting of 32 time taken for this transfer? [2010, 2 Marks]
lines of 64 byte each is used in the system. A 50 × 50 two- (a) 2 ns (b) 20 ns
dimensional array of bytes is stored in the main memory starting (c) 22 ns (d) 88 ns
from memory location 1100H. Assume that the data cache is 100. When there is a miss in both L1 cache and L2 cache, first a
initially empty. The complete array is accessed twice. Assume block is transferred from main memory to L2 cache, and
that the contents of the data cache do not change in between the then a block is transferred from L2 cache to L1 cache. What
two accesses. is the total time taken for these transfer? [2010, 2 Marks]
95. How many data cache misses will occur in total? (a) 222 ns (b) 888 ns
[2007, 2 Marks] (c) 902 ns (d) 968 ns
(a) 48 (b) 50
Statement for Linked Answer Questions 101 and 102:
(c) 56 (d) 59
A computer uses 46-bit virtual address, 32-bit physical
96. Which of the following lines of the data cache will be address and a three-level paged page table organisation. The
replaced by new blocks in accessing the array for the second page table base register stores the base address of the first-
time? [2007, 2 Marks] level table (T1), which occupies exactly one page. Each entry
(a) Line 4 to line 11 (b) Line 4 to line 12 of T1 stores the base address of a page of the second-level
(c) Line 0 to line 7 (d) Line 4 to line 8 table (T2). Each entry of T2 stores the base address of a page
Computer Organisation & Architecture S3-41
of the third-level table (T3). Each entry of T3 stores a page (a) 2 (b) 4
table entry (PTE). The PTE is 32 bits in size. The processor (c) 8 (d) 16
used in the computer has a 1 MB 16-way set associative
102. What is the minimum number of page colours needed to
virtually indexed physically tagged cache. The cache block guarantee that no two synonyms map to different sets in
size is 64 bytes. the processor cache of this computer? [2013, 2 Marks]
101. What is the size of a page in KB in this computer? (a) 2 (b) 4
[2013, 2 Marks] (c) 8 (d) 16
T1 T2 T3 T4 T5 T6 T7 T8 T9 TA
A15-A8 30H 30H C
AD7-AD0 50H A D B
10/M
conditional branch instructions, and 50% of the wide. When a write request is made, the bus is occupied for
conditional branch instructions are such that the 100 nanoseconds (ns) by the data, address, and control
branch is taken, calculate the average instruction time. signals. During the same 100 ns, and for 500 ns thereafter,
(2000, 5 Marks) the addressed memory module executes one cycle accepting
106. A computer system uses 32-bit virtual address, and 32-bit and storing the data. The (internal) operation of different
physical address. The physical memory is byte addressable, memory modules may overlap in time, but only one request
and the page size is 4 kbytes. It is decided to use two page can be on the bus at any time. The maximum number of
tables to translate from virtual address to physical address: stores (of one word each) that can be initiated in 1 millisecond
Equal number of bits should be used for indexing first level is ____________ [2014, Set-2, 2 Marks]
and second level page table, and size of each page table 111. An instruction pipeline has five stages, namely, instruction
entry is 4 byes. fetch (IF), instruction decode and register fetch (ID/RF),
(a) Give a diagram showing how a virtual address would instruction execution (EX), memory access (MEM), and
be translated to a physical address. register writeback (WB) with stage latencies 1 ns, 2.2 ns, 2
(b) What is the number of page tables entries that can be ns, 1 ns, and 0.75 ns, respectively (ns stands for
contained in each page? nanoseconds). To gain in terms of frequency, the designers
(c) How many bits are available for storing protection have decided to split the ID/RF stage into three stages (ID,
and other information in each page table entry? RF1, RF2) each of latency 2.2/3 ns. Also, the EX stage is
(2002, 5 Marks) split into two stages (EX1, EX2) each of latency 1 ns. The
107. A machine has a 32-bit architecture, with 1-word long new design has a total of eight pipeline stages. A program
instructions. It has 64 registers, each of which is 32 bits has 20% branch instructions which execute in the EX stage
long. It needs to support 45 instructions, which have an and produce the next instruction pointer at the end of the
immediate operand in addition to two register operands. EX stage in the old design and at the end of the EX2 stage
Assuming that the immediate operand is an unsigned integer, in the new design. The IF stage stalls after fetching a branch
the maximum value of the immediate operand is ______ . instruction until the next instruction pointer is computed.
[2014, Set-1, 1 Mark] All instructions other than the branch instruction have an
108. Consider a 6-stage instruction pipeline, where all stages are average CPI of one in both the designs. The execution times
perfectly balanced. Assume that there is no cycle-time of this program on the old and the new design are P and Q
overhead of pipelining. When an application is executing nanoseconds, respectively. The value of P/Q is __________.
on this 6-stage pipeline, the speedup achieved with respect [2014, Set-3, 2 Marks]
to non-pipelined execution if 25% of the instructions incur 112. The memory access time is 1 nanosecond for a read operation
2 pipeline stall cycles is ______________________. with a hit in cache, 5 nanoseconds for a read operation with
[2014, Set-1, 2 Marks] a miss in cache, 2 nanoseconds for a write operation with a
109. A 4-way set-associative cache memory unit with a capacity hit in cache and 10 nanoseconds for a write operation with
of 16 KB is built using a block size of 8 words. The word a miss in cache. Execution of a sequence of instructions
length is 32 bits. The size of the physical address space is involves 100 instruction fetch operations, 60 memory
4 GB. The number of bits for the TAG field is _____. operand read operations and 40 memory operand write
[2014, Set-2, 1 Mark] operations. The cache hit-ratio is 0.9. The average memory
110. Consider a main memory system that consists of 8 memory access time (in nanoseconds) in executing the sequence of
modules attached to the system bus, which is one word instructions is __________. [2014, Set-3, 2 Marks]
Computer Organisation & Architecture S3-43
Case 3 This is write after read problem or concurrency 24. (a) Associativity has no dependence but L2 cache must
dependency so hazardous. be at least as large as L1 cache, since all the words
All the three are hazardous. Hence (d) is correct in L1 are also is L2. Hence (a) is correct option.
option. 25. (d) In a pipelined processor by passing can’t handle all
18. (a) 1. A[l] = B[j] indexed addressing mode the row hazards. Registers carried WAR doesn't
2. While [*A ++] auto increment
have register naming as proper solution. And control
3. int. temp = *x Indirect addressing
hazard penalties are eliminated by delayed branching
19. (c) We know that, size is directly proportional to page
frame. not by dynamic branch prediction. So all are false.
So, the RAM is increased. The main memory also Hence (d) is correct option.
increases and thus the page frame size also increases 26. (c) Multiple register windows with overlap causes a
which results in reduction of swapping. Thus, lesser reduction in the number of memory accesses for
number of page faults occur. instruction fetching. Hence (c) is correct option.
Now, if any replacement rule is applied which doesn’t 27. (b) TLB is used during effective address calculation in
cause blady anomaly always results in reduction of an instruction execution pipeline. Hence (b) is
page faults. correct option.
20. (b) Let us assume that CPU contains two processes when 28. (c) For incrementing the data, the auto-increment
one process is being executed on the CPU the other addressing mode is used which purely depends on
one is swapped out and all the data is saved on the the size of the data. For example:
disk. Thus the swap space is basically used for saving Regs [R1] ¬ Regs [R1] + Mem [Regs [R2]
the process data. Regs [R2] ¬ Regs [R2] + d
21. (a) Memory mapped I/O means, accessing I/O via general
29. (d) When an RFE (Return From Exception) instruction is
memory access as opposed to specialized IO instructions.
executed; no exception is allowed to occur during that
An example,
time and also it must be a trap instruction and also a
unsigned int volatile const *pMappedAddress const
= (unsigned int *) 0 × 100; privileged one.
So, the programmer can directly access any memory Thus all the three statements are true as far as RFE is
location directly. To prevent such an access, the OS concerned.
(kernel) will divide the address space into kernel space 30. (d) The interrupt register is checked after finishing the
and user space. An user application can easily access execution of the current instruction. At this time, a
user application. To access kernel space, we need CPU generally handles an interrupt by the execution
system calls (traps). of an interrupt service routine.
So, IO protection is ensured by OS abstraction. 31. (d) Higher priority interrupt levels are assigned to requests
22. (b) In single line interrupt system, vectored interrupts are which, if delayed or interrupted, could have serious
not possible but multiple interrupting devices are consequences. Devices with high speed transfer such
possible as a single line interrupt system consists of a as magnetic disks are given high priority and slow
single interrupt system consists of a single interrupt diviser such as keyboard receive low priority. Mouse
request line and a interrupt grant line in such a system pointer moments are more frequent then keyboard ticks.
it may be possible that at the same time more than one
So its obvious that its data transfer rate is higher than
output devices can request an interrupt, thus in such
keyboard. Delaying a CPU temperature sensor could
cases only one request will be granted according to
have serious consequences, overheat can damage CPU
the priority as is depicted by the following figure, but
the interrupt is granted to the single request only. circuitry. From the above information we can conclude
that priorities are - CPU temperature sensor > Hard
disk > Mouse > Keyboard.
32. (d) The addressing mode will be base index addressing.
Interrupt
flip-flop Here, 20 will work as base and content of R2 will be
I/O port 0 I/O port 1 I/O port n index. R2 is base regester here and indexing is done by
CPU
adding 20 to the contents of R2.
I/O devices 33. (c) Pipelining of the register renaming logic can help avoid
restricting the processor clock frequency.
23. (c) The seek latency is not linearly proportional to seek
34. (d) The following sequence of micro-operations
distance due to the higher capacity of tracks on the
MBR ¬ PC
periphery of the latter. The higher capacity of the tracks
MAR ¬ X
is responsible for the presence of this certain amount
PC ¬ Y
of time is required for this cells to reach the read-write
head so that data transfer can take place. Memory ¬ MBR.
Computer Organisation & Architecture S3-45
69. (d) Starting disk location of the file is <1200, 9,40 >.
1
Since starting number of sectors left on 9th surface 72. (c) Frequency µ clock period
is = 24. So, on 9th surface total storage of "12288"
B is possible. Now, a part from 9th surface, on Clock period = maximum stage delay + overhead
cylinder number 1200 only 6 surface is left, P1 : CP = Max (1, 2, 2, 1) = 2 ns
Storage possibilities on these 6 surfaces are
P2 : CP = Max (1, 1.5, 1.5, 1.5) = 1.5 ns
= 6 × 26 * 29 storage on each sector
P3 : CP = Max (0.5, 1, 1, 0.6, 1) = 1 ns
number of sectors on each surface
=196608 B P4 : CP = Max (0.5, 0.5, 1, 1, 1, 1) = 1.1 ns
The total on cylinder no 1200, storage possible Q CP of P3 is less, it has highest frequency
= 196608 + 12288 = 208896 B. 1
Frequency 1 P3 = = 1GHz
Since file size is 42797 KB and out of which 208896 1ns
n
B are stored on cylinder, no 1200. So we are left only 73. (a)
N
with 43615232 B. 74. (a) 14.25 = 1110.010
Since in 1 cylinder, storage possible is = 1.110010 × 23
= 24 × 26 × 29 B = 524288 B.
\ m = 110010
43615232B
So, we need about = 524288B = 83.189 more 1 8 23
S E M
cylinders. (= C1640000)
Hence, we will need 1284th cylinder to completely 1 10000010 11001000
store the files since after 1283rd cylinder we will be
left with data which will 189. E = 127 + 3 = 130
70. (b) RAM chip size = 1K × 8 [1024 words of 8 bits each] = 10000010
RAM to construct = 16K × 16
COMMON DATA MCQs
16K ´ 16
Number of chips required = = 16 ´ 2 75. (b) Here value of B incremented by 1 only if carry flag
1K ´ 8
is 1, carry is filled using right rotation, so B will store
So, to select one chip out of 16 vertical chips, we
the no. of is in A0.
need 4 × 16 decoder. Available decoder is 2 × 4
decoder. So we need 5 decoder in total. Hence (b) is correct option.
71. (b) Instruction pipeline with five stages without any 76. (a) In the end of program execution to check whether
branch predicition: Delays for FI, DI, FO.EI and WO both initial and final value of register A is A0, we
are 5,7,10,8,6 ns respectively. need to right rotate register A through carry by one
The maximum time taken by any stage is 10 ns and bit. Hence (a) is correct option.
additional 1ns is required for delay of buffer. 77. (d) Byte addressable so 1 word require 4 bytes.
\ The total time for an instruction to pass from one
stage to another in 11 ns. Instruction no. Size Address range
The instructions are executed in the following order
1 2 1000 – 1007
l1, l2, l3, l4, l9, l10, l11, l12
2 1 1008 – 1011
Execution with Time
3 1 1012 – 1015
Now when l4 is in its execution stage we detect the
4 2 1016 – 1023
branch and when l4 is in WO stage we fetch I9 so
5 1 1024 – 1027
time for execution of instructions from l9 to l12 is =
11* 5 +(4 – 1) * 11= 88 ns. Next location 1028.
But we save 11 ns when fetching l9 i.e., l9 requires
CPU has executed the HALT instruction so next time
only 44 ns additional instead of 55ns because time
the CPU will resume at next location i.e. 1028 which
for fetching l9 can be overlap with WO of l4.
would be at the top of stack.
\ Total Time is = 88 + 88 – 11 = 165 ns
Hence (d) is correct option.
Computer Organisation & Architecture S3-49
78. (b) The clock cycles are per block so if an instruction 85. (b) The array element ARR [4] [0] has the same cache
size is 2 then it requires twice no. of clock cycles. index as ARR [0] [0] since it is given that page size is of
4 kbyte and 1 row contains 1024 elements, i.e., 210
Ins truction no: S ize No of clock cycles
locations.
1 2 3*2+2 8
86. (b) We know that hit ratio is given as
2 1 1*3+2 5
Number of hits/ Number of hits + Number of rows
3 1 1(ad d o nly ) 1
= 4/16 = 25%
4 2 3*2+2 8
87. (c) We have to find the sector number of the address
5 1 2(fetch an d d eco de ) 2 < 400, 16, 29>
Total 24 Therefore, 400 × 2 × 10 × 63 + 16 × 63 + 29
= 505037 sector
79. (a) 2 way set-associative Cache. Size 32 KB 88. (c) <0, 16, 31> this address corresponds to a sector number
2 way so 16 KB sets. Require 14 bits for 2^14 B which is given by 16 × 63 + 31 = 1039
Block size = 32 Byte. = 5 bits.
89. (b) In this question we have to minimize spills to
No. of blocks14 – 5 = 9
Tag index memory (writer). As variables d,e are only used in
Tag Index else part. So we can move d,e instructions inside
18 14 else. The code we get is
18 9 5 c = a + b; Assumption-Register R1 and R2.
h1 = 18/10 + 0.6 ns x = c * c; Already holds a and b respectively,
= 2.4 ns.
80. (b) Similarly to previous question. The CPU address is if (x > a)
same but Direct coaching require for 32 KB 15 bits. { We can first calculate the number of
Which would be 10 + 5 = 17 y=a* a memory spill. The machine code is
equivalent to
17 10 5
else {
h2 = 17/10 + 0.6
d = c * a; R2 ¬ R1 + R2 (c = a + b)
= 2.3 ns Hence (b) is correct option.
81. (d) The memory reference required by the instruction d = d*d; write R2 to memory (So memory has value
R1 ¬ M [3000] is 1 whereas the memory reference of c)
required by R2 ¬ M[R3] and M[R3] ¬ R2 is 10. e = e * e if (R2 > R1) x=c*c
Therefore, total memory reference required = 2 × 10 + 1 } { (x > a)
82. (a) The content in the memory location 2010 doesn’t R2 ¬ R1 + R1 (y – a * a)
change as the value in register R1 becomes zero, so
the loop BNZ exists and as the address in R3 becomes }
2010. Thus, the content of the location still remains else {
100. R2 ¬ (read value of c from memory) R1 (d = c * a)
83. (a) The locations of various operations are given in the R2 ¬ R2 * R2 (d = d * d)
following table: R2 ¬ (read value of c from memonry)
+ R1 (e = c + a)
Location Operation
1000 R1 ¬ M [3000] R2 ¬ R2 * R2 (e = e * e)
1001 }
1002 R2 ¬ M [R3] Þ There has been only 1 memory write observed
1003 R2 ¬ R1 + R2 in the give code.
1004 M[R3] ¬ R2 So the answer is 1.
1005 R3 ¬ R3 + 1 90. (b) Assuming that R1 and R2 holds the value of a and
b respectively. The machine code is equivalent to
Thus, the location of the instruction INCR3 is 1005, if
R2 ¬ R1 + R2 (c = a + b) (R2 holds c)
an interrupt occurs, and thus it is pushed on the stack.
R3 ¬ R2 *R1 (d = c * a)
Tag Set Block R4 ¬ R2 + R1(e = c + a)
84. (b)
17 11 4 R2 ¬ R2 *R2 (x = c * c)
From the above figure and given conditions the total (Removing c from R2 as c is not used after this
number of tags comes out to be = 17 × 2 × 1024 = 32 bit statements R2 holds x)
S3-50 Computer Organisation & Architecture
If (R2 > R1) { {If (x > a)} Therefore, execution cycle is completed in 3 clock
If (R2 > R1) cycles.
{ 94. (b) The minimum number of CPU clock cycles needed
R2 ¬ R1 × R1 during the execution cycle =4As 1 cycle required to
R2 ¬ R1 * R1 (y = a* a) transfer already incremented value of PCand 2 cycle
} for getting data in MDR1 to load value of MDR in PC.
else { 95. (c) The number of data cache misses that occur in total
R3 ¬ R3 * R3 {d =d *d) are 56 as is clear from the given data.
R4 ¬ R4 * R4 (e = e * e) 96. (a) The lines that will be replaced by the new blocks are
} lines 4 to 11.
We have used R1, R2, R3,R4 registers 97. (b) The first instruction in the fall through path is executed
So answer is 4. for all the delayed conditional branch instructions,
LINKED ANSWER TYPE MCQs irrespective of whether the condition evaluates to true
or false.
91. (c) Given loop P1 accesses array A row wise & P2 98. (a) I4 since R1 is only read in I4 and its value will remain as
access column wise. it is while BRANCH is executed and after BRANCH
M1 = ? Cache Capacity = 215 B. get executed , since in BRANCH R1 is only read.
1 element = 23 B Total elements 512 × 512 99. (c) As already given in question,
Total data = 512 × 512 × 8 B = 221 B Memory access time for L1 = 2 ns
Block size = 128 B Memory access time for L2 = 20 ns
Now the required time of transfer = 20 + 2 = 22 ns
1 block can have = 128/8 = 16 elements
100. (a) As given memory access time for main memory
So total blocks require =( 512 × 512 )/16 = 200 ns
= 1638 blocks Memory access time L2 = 2 ns
Since the memory is initially empty so all blocks are Memory access time L2 = 20 ns
required at least once. Total access time = Block transfer time from main
So, M1 = 16384 Hence (c) is memory to L2 cache + Access time of L2 + Acces time
of L1
92. (b) Now M2 = ?
Now, the required time of transfer
In the case (P2 loop) the array is accessed column = 200 + 20 + 2 = 222 ns
wise, so even the block brought for A [0][0] ? 101. (c)
A[0][15] would not be used for second column wise 102. (c)
access i.e. A[1][0]. So new block need to swap,
similarly for A[3][0] & so on. This would continue NUMERICAL ANSWER QUESTIONS
for every element, since memory is contiguous.
103. (a) A: DA H B: 0 9 H
So M2 = 512 × 512 = 262144 C:0 9 H D:51H
And M1/M2 =16384/262144=1/16 (b) ALE : T1 = 1
93. (a) Given that R0 ¬ R0 + R1 T2 = T3 = T4 = 0
The clock cycles operate as follows: RD : T1 = 1
Cycle 1 Out : R1 T2 = T3 = 0. T4 = 1
In : S (c) The IO / M signal and RD signal
Cycle 2 Out : R2 104. (a) (i) 18 H 86H
In : T (ii) D = 00H D = FFH
Cycle 3 Out : S, T E = 19H E 13H
(b) E = | B – C |
Add : ALU
D = 00H if B> C
In : R
and D = FFH if B< C
Computer Organisation & Architecture S3-51
1023
0
1
2
3 Page table for
4 the top 4 m of
5 memory
6
1023
29 29 336
No. of sets = = = 27 \ Average memory access time = ns = 1.68ns
4 22 200
Programming & Data Structures S3-53
Memory
Data type Range of values Properties
Requirement
char -128 to 127 1 byte Holds a character
Int -32,768 to 32,767 2 bytes Holds an integer value
Float 3.4e-38b to 3.4e + e38 4 bytes Holds s ingle precis ion value
double 1.7e-308 to 1.7e + 308 8 bytes Holds double precis ion value
Void 0 byte Holds nothing
C Variable types There are following storage classes which can be used in a C
The Programming language C has two main variable types Program
• Local Variables • auto
• Global Variables • register
Local Variables • static
• Local variables scope is confined within the block or • extern
function where it is defined. Local variables must Auto - Storage Class
always be defined at the top of a block. Auto is the default storage class for all local variables.
• When a local variable is defined - it is not initalised by {
the system, you must initalise it yourself. int Count;
• When execution of the block starts the variable is auto int Month;
available, and when the block ends the variable 'dies'. }
Global Variables The example above defines two variables with the same storage
Global variable is defined at the top of the program file and it can class. auto can only be used within functions, i.e. local variables.
be visible and modified by any function that may reference it. Register - Storage Class
Data Type Initialser Register is used to define local variables that should be stored in
int 0 a register instead of RAM. This means that the variable has a
char '\0' maximum size equal to the register size (usually one word) and
float 0 cant have the unary '&' operator applied to it (as it does not have
pointer NULL a memory location).
If same variable name is being used for global and local variable {
then local variable takes preference in its scope. But it is not a register int Miles;
good practice to use global variables and local variables with the }
same name. Register should only be used for variables that require quick
C - Storage Classes access - such as counters. It should also be noted that defining
A storage class defines the scope (visibility) and life time of 'register' goes not mean that the variable will be stored in a register.
variables and/or functions within a C Program. It means that it MIGHT be stored in a register - depending on
hardware and implementation restrictions.
Programming & Data Structures S3-55
Static - Storage Class The default value for the first one in the list - RED in our case, has
Static is the default storage class for global variables. The two the value of 0. The rest of the undefined constants have a value
variables below (count and road) both have a static storage class. 1 more than the one before, so in our case, YELLOW is 1, GREEN
static int Count; is 2 and BLUE is 3.
int Road; But you can assign values if you wanted to:
enum colors {RED=1, YELLOW, GREEN=6, BLUE };
{ Now RED=1, YELLOW=2, GREEN=6 and BLUE=7.
printf("%d\n", Road); C - Operator Types
} What is Operator? Simple answer can be given using expression
static variables can be 'seen' within all functions in this source 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called
file. At link time, the static variables defined here will not be seen operator. C language supports following type of operators.
by the object modules that are brought in.Static can also be defined • Arithmetic Operators
within a function. If this is done the variable is initalised at run • Logical (or Relational) Operators
time but is not reinitalized when the function is called. This inside • Bitwise Operators
a function static variable retains its value during various calls. • Assignment Operators
Static variables are initialized to 0 automatically. • Misc Operators
Definition vs Declaration : Before proceeding, let us understand Bitwise Operators:
the difference between defintion and declaration of a variable or Bitwise operator works on bits and perform bit by bit operation.
function. Definition means where a variable or function is defined Assume if A = 60; and B = 13; Now in binary format they will be as
in realityand actual memory is allocated for variable or function. follows:
A = 0011 1100
Declaration means just giving a reference of a variable and
B = 0000 1101
function. Through declaration we assure to the complier that this -----------------
variable or function has been defined somewhere else in the A&B = 0000 1100
program and will be provided at the time of linking. In the above A|B = 0011 1101
examples char *func(void) has been put at the top which is a A^B = 0011 0001
declaration of this function where as this function has been ~A = 1100 0011
C - Flow Control Statements
defined below to main() function.
C provides two styles of flow control:
Extern - Storage Class • Branching
Extern is used to give a reference of a global variable that is • Looping
visible to ALL the program files. When you use 'extern' the variable Branching is deciding what actions to take and looping is deciding
cannot be initalized as all it does is point the variable name at a how many times to take a certain action.
storage location that has been previously defined. Branching:
Branching is so called because the program chooses to follow
C - Using Constants
one branch or another.
• Octal constants are written with a leading zero - 015. if statement
• Hexadecimal constants are written with a leading 0x - 0x1ae. If the expression is true then the statement or block of statements
• Long constants are written with a trailing L - 890L. gets executed otherwise these statements are skipped.
'\n' newline Syntax:
'\t' tab if (expression)
statement;
'\\' backslash
or
'\'' single quote if (expression)
'\0' null ( Usedautomatically to terminate character string ) {
Defining Constants Block of statements;
int const a = 1; }
const int a =2; if condition is true ? then X return value : otherwise Y value;
switch statement:
The enum Data type
The switch statement is much like a nested if .. else statement. Its
enum is the abbreviation for ENUMERATE, and we can use this mostly a matter of preference which you use, switch statement
keyword to declare and initialize a sequence of integer constants. can be slightly more efficient and easier to read.
Here's an example: Syntax:
enum colors {RED, YELLOW, GREEN, BLUE}; switch( expression )
S3-56 Programming & Data Structures
variables are passed to a function so that function can Before: Value of a = 10 and value of b = 20
work directly over the addresses. Value of a (p1) = 20 and value of b(p2) = 10
Call Type Description After: Value of a = 10 and value of b = 20
Call by value This method copies the EXAMPLE OFPASS BY REFERENCE
actual value of an argument #include <stdio.h>
into the formal parameter of /* function declaration goes here.*/
the function. In this case, void swap( int *p1, int *p2 );
changes made to the
parameter inside th e int main()
function have no effect on {
the argument. int a = 10;
Call by pointer This method copies the int b = 20;
address of an argument into
the formal parameter. Inside printf("Before: Value of a = %d and value of b = %d\n", a, b );
the function, the address is swap( &a, &b );
used to access the actual printf("After: Value of a = %d and value of b = %d\n", a, b );
argument used in the call. }
This means that changes
made to the parameter affect void swap( int *p1, int *p2 )
the argument. {
Call by reference This method copies the int t;
reference of an argument into
the formal parameter. Inside t = *p2;
the function, the reference is *p2 = *p1;
used to access the actual *p1 = t;
argument used in the call. printf("Value of a (p1) = %d and value of b(p2) = %d\n", *p1,
This means that changes *p2 );
made to the parameter affect }
the argument. Here is the result produced by the above example. Here the values
EXAMPLE OF PASS BY VALUE: of a and b are changes after calling swap function.
#include <stdio.h> Before: Value of a = 10 and value of b = 20
Value of a (p1) = 20 and value of b(p2) = 10
/* function declaration goes here.*/ After: Value of a = 20 and value of b = 10
void swap( int p1, int p2 ); STRINGS
• In C language Strings are defined as an array of
int main() characters or a pointer to a portion of memory containing ASCII
{ characters. A string in C is a sequence of zero or more characters
int a = 10; followed by a NULL '\0' character:
int b = 20; • It is important to preserve the NULL terminating
character as it is how C defines and manages variable length
printf("Before: Value of a = %d and value of b = %d\n", a, b ); strings.
swap( a, b ); • String constants have double quote marks around
printf("After: Value of a = %d and value of b = %d\n", a, b ); them, and can be assigned to char pointers as shown below.
} Alternatively, you can assign a string constant to a char array -
void swap( int p1, int p2 ) either with no size specified, or you can specify a size, but don't
{ forget to leave a space for the null character!
int t; char *string_1 = "Hello";
char string_2[] = "Hello";
t = p2; char string_3[6] = "Hello";
p2 = p1; String Manipulation Functions
p1 = t; • char *strcpy (char *dest, char *src) - Copy src string
printf("Value of a (p1) = %d and value of b(p2) = %d\n", p1, p2 string into dest string.
); • char *strncpy(char *string1, char *string2, int n) - Copy
} first n characters of string2 to stringl .
Here is the result produced by the above example. Here the values • int strcmp(char *string1, char *string2) - Compare
of a and b remain unchanged before calling swap function and string1 and string2 to determine alphabetic order.
after calling swap function. • int strncmp(char *string1, char *string2, int n) -
Compare first n characters of two strings.
S3-58 Programming & Data Structures
an entity called an Abstract data type. There's a clean,simple fruit mango, will create an object mango belonging to the class
interface between the abstract data type and the program(s) that fruit.
use it. Data Abstraction
Data abstraction refers to, providing only essential information Abstraction refers to the act of representing essential features
to the outside world and hiding their background details, i.e., to without including the background details. To understand this
concept more clearly, take an example of 'switch board'. You only
represent the needed information in program without presenting
press particular switches as per your requirement. You need not
the details.
know the internal working of these switches. What is happening
Data abstraction is a programming (and design) technique that inside is hidden from you. This is abstraction, where you only
relies on the separation of interface and implementation. know the essential things to operate on switch board without
knowing the background details of switch board.
Now, if we talk in terms of C++ Programming, C++ classes Data Encapsulation
provides great level of data abstraction. They provide sufficient Encapsulation is the most basic concept of OOP. It is the way of
public methods to the outside world to play with the functionality combining both data and the functions that operate on that data
of the object and to manipulate object data, i.e., state without under a single unit. The only way to access the data is provided
actually knowing how class has been implemented internally. by the functions (that are combined along with the data). These
Access Labels Enforce Abstraction: functions are considered as member functions in C++. It is not
In C++, we use access labels to define the abstract interface to possible to access the data directly. If you want to reach the data
the class. A class may contain zero or more access labels: item in an object, you call a member function in the object. It will
• Members defined with a public label are accessible to read the data item and return the value to you. The data is hidden,
so it is considered as safe and far away from accidental alternation.
all parts of the program. The data-abstraction view of
Data and its functions are said to be encapsulated into a single
a type is defined by its public members. entity.
• Members defined with a private label are not accessible Modularity
to code that uses the class. The private sections hide The act of partitioning a program into individual components is
the implementation from code that uses the type. called modularity. It gives the following benefits.
Designing Strategy: • It reduces its complexity to some extent.
Abstraction separates code into interface and implementation. • It creates a number of well-defined, documented boundaries
So while designing your component, you must keep interface within the program.
independent of the implementation so that if you change Inheritance
underlying implementation then interface would remain intact. It is the capability to define a new class in terms of an existing
In this case whatever programs are using these interfaces, they class. An existing class is known as a base class and the new
would not be impacted and would just need a recompilation with class is known as derived class.
the latest implementation C++ supports such hierarchical classification of classes. The main
benefit from inheritance is that we can build a generic base class,
OOPS
i.e., obtain a new class by adding some new features to an existing
Introduction class and so on. Every new class defined in that way consists of
The object-oriented programming (OOP) is a different approach features of both the classes. Inheritance allows existing classes
to programming. Object oriented technology supported by C++ to be adapted to new application without the need for
is considered the latest technology in software development. modification.
BASIC CONCEPTS Polymorphism
Objects Polymorphism is a key to the power of OOP. It is the concept that
When a program is executed, the objects interact by sending supports the capability of data to be processed in more than one
messages to one another. For example, if 'customer' and 'account' form. For example, an operation may exhibit different behaviour
are two objects in a program, then the customer object may send in different instances. The behaviour depends upon the types of
message to account object requesting for a bank balance. Each data used in the operation.
object contains data and code to manipulate data. Objects can The major benefits are :
interact without having to know details of each other's data or • Software complexity can be easily managed
code. It is sufficient to know the type of massage accepted and • Object-oriented systems can be easily upgraded
the type of response returned by the objects. • It is quite easy to partition the work in a project based on objects.
Classes LINKED LISTS
We have just mentioned that objects contain data and function The link is a pointer to the same type of structure
or code to manipulate that data. The entire set of data and code of struct Node
an object can be made a user-defined data type with the help of a {
class. In fact objects are variables of type class. Once a class has int data ;
been defined, we can create any number of objects associated struct Node *next ;
with that class. For example, mango, apple and orange are members
};
of class fruit. If fruit has been defined as a class, then the statement
This is called a self-referential pointer
S3-60 Programming & Data Structures
Circular Lists
d d+1
The list pointer can have the address of the last element.The tail/ 2*2 -1=2 -1
last element can be accessed by the list pointer.The head/first
3. Atmost complete Binary Tree
element can be accessed from the tail/lastelement (by list->next)
A binary tree of depth d is an almost complete binary tree if:
Provides flexibility in accessing first and last elements
• At any node in the tree with a right descendent at level
Circular lists can be used for queues.
d, node must have a left son and every left descendent
Useful in enqueue/dequeue operations without needing to
of node is either a leaf at level d or has two sons.
traverse the list.
i.e. the tree must be left filled.
Note : ACBT property says that if there are n nodes in the
tree then leaf node have numbers
[(n/2)+1][(n/2)+2]———n
ACBT with n leaves has 2n nodes if it is not a SBT
An ACBT which is also an SBT has 2n-1 nodes for n leaves
Also an ACBT is an SBT if the number of node are odd
T R EE S An ACBT of depth d is intermediate between the complete
A tree is a data structure that is made of nodes and pointers, binary tree of depth, t d-1 that contains 2d-1 nodes , and the
much like a linked list. The difference between them lies in complete binary tree of depth d, which contains 2d+1-1
how they are organized: nodes
In a linked list each node is connected to one “successor”
node (via next pointer), that is, it is linear. Root
In a tree, the nodes can have several next pointers and thus Level 0
are not linear.
The top node in the tree is called the root and all other
nodes branch off from this one.
Every node in the tree can have some number of children. Level 1
Each child node can in turn be the parent node to its children
and so on.
A common example of a tree structure is the binary tree.
A binary tree is a tree that is limited such that each node has only Level 2
two children.
If n1 is the root of a binary tree and n2 is the root of its left
or right tree, then n1 is the parent of n2 and n2 is the left or
right child of n1.
A node that has no children is called a leaf. Level 3
The nodes are siblings if they are left and right children of
the same parent.
The level of a node in a binary tree: A
• The root of the tree has level 0
• The level of any other node in the tree is one more
than the level of its parent.
Types of Binary Tree:- B C
1. Strictly Binary Tree
• If every non leaf node in a binary tree has non empty
left and right sub trees, the tree is termed as strictly
binary tree
D E
Every non leaf node has degree 2.
A strictly binary tree with n leaves has (2n-1) nodes.
Thus a strictly binary tree has odd number of nodes.
2. Complete Binary Tree
A complete binary tree of depth d is the binary tree of depth F G
d that contains exactly 2l at each level l between 0 and d.
Thus the total number of nodes in complete binary tree are Implementation
2d+1-1 where leaf nodes are 2d and non leaf are 2d-1. A binary tree has a natural implementation in linked storage.
Because a complete binary tree is also a strictly binary tree A separate pointer is used to point the tree (e.g. root)
, thus if it has n leaves then it has 2n-1 nodes. Also follows root = NULL; // empty tree
from this is the previous assertion that if n=2d then total Each node of a binary tree has both left and right subtrees
nodes are which can be reached with pointers:
S3-62 Programming & Data Structures
struct tree_node{
int data;
struct tree_node *left_child; 8
struct tree_node *right_child;
}; 3 9
BINARY SEARCH TREE:-
BST is a binary tree. For each node in a BST, the left subtree is
smaller than it; and the right subtree is greater than it. A binary 1 5 12
search tree (BST), sometimes also called an ordered or sorted
binary tree, is a node-based binary tree data structure which has 4 11
the following properties:
The left subtree of a node contains only nodes with keys before insertion
less than the node’s key.
The right subtree of a node contains only nodes with keys
greater than the node’s key.
The left and right subtree must each also be a binary search 8
tree.
There must be no duplicate nodes. 3 9
Implementation
We implement a binary search tree using a private inner class
BSTNode. In order to support the binary search tree property, 1 5 12
we require that data stored in each node is Comparable:
public class BST <An yType extends 4 7 11
Comparable<AnyType>>
{ after insertion
private Node<AnyType> root;
Searching
private class Node<AnyType> Searching in a BST always starts at the root. We compare a data
{ stored at the root with the key we are searching for (let us call it as
private AnyType data; to Search). If the node does not contain the key we proceed
private Node<AnyType> left, right; either to the left or right child depending upon comparison. If the
result of comparison is negative we go to the left child, otherwise
public Node(AnyType data)
- to the right child. The recursive structure of a BST yields a
{
recursive algorithm.
left = right = null;
this.data = data; Deletion
} Deletion is somewhat more tricky than insertion. There are several
} cases to consider. A node to be deleted (let us call it as to Delete)
... is not in a tree;
Insertion is a leaf;
The insertion procedure is quite similar to searching. We start at has only one child;
the root and recursively go down the tree searching for a location
has two children.
in a BST to insert a new node. If the element to be inserted is
already in the tree, we are done (we do not insert duplicates). The If to Delete is not in the tree, there is nothing to delete. If to Delete
new node will always replace a NULL reference. node has only one child the procedure of deletion is identical to
Example: Given a sequence of numbers: deleting a node from a linked list - we just bypass that node being
11, 6, 8, 19, 4, 10, 5, 17, 43, 49, 31 deleted
Draw a binary search tree by inserting the above numbers from
left to right. 8
11 3 9
6 19 1 5 12
4 8 17 43 4 11
before deletion
5 10 31 49
Programming & Data Structures S3-63
c. Its left sub tree is completely full of height h-1 and its right
8 sub tree is complete of height h-1.
A complete tree is filled from the left:
3 12 all the leaves are on
• the same level or
1 5 11 • two adjacent ones and
All nodes at the lowest level are as far to the left as possible.
4 Heaps
A binary tree has the heap property iff
after deletion
a. it is empty or
Deletion of an internal node with two children is less
b. The key in the root is larger than that in either child and
straightforward. If we delete such a node, we split a tree into two
subtrees and therefore, some children of the internal node won’t both sub trees have the heap property.
be accessible after deletion. In the picture below we delete 8: A heap can be used as a priority queue: the highest priority item
is at the root and is trivially extracted. But if the root is deleted, we
8 are left with two sub-trees and we must efficiently re-create a
single tree with the heap property.
3 swap data 9 The value of the heap structure is that we can both extract the
highest priority item and insert a new one in O(logn) time.
1 5 12
Heap operations :
Insert :
To add an element to a heap we must perform an up-
4 11 heap operation (also known as bubble-up, percolate-up, sift-
before deletion up, trickle up, heapify-up, or cascade-up), by following this
algorithm:
1. Add the element to the bottom level of the heap.
5
2. Compare the added element with its parent; if they are in
the correct order, stop.
9 3 9
3. If not, swap the element with its parent and return to the
previous step.
12 1 4 12 Delete :
The procedure for deleting the root from the heap (effectively
11 11 extracting the maximum element in a max-heap or the minimum
eletion after deletion element in a min-heap) and restoring the properties is called down-
heap (also known as bubble-down, percolate-down, sift-
Deletion starategy is the following: replace the node being deleted
down, trickle down, heapify-down, cascade-down and extract-
with the largest node in the left subtree and then delete that
min/max).
largest node. By symmetry, the node being deleted can be
1. Replace the root of the heap with the last element on the
swapped with the smallest node is the right subtree.
last level.
BINAR Y HEAP S
2. Compare the new root with its children; if they are in the
A binary tree is completely full if it is of height, h, and has 2h+1-
correct order, stop.
1 nodes.
3. If not, swap the element with one of its children and return
A binary tree of height, h, is complete iff
to the previous step. (Swap with its smaller child in a min-
a. it is empty or
heap and its larger child in a max-heap.)
b. its left sub tree is complete of height h-1 and its right sub
tree is completely full of height h-2 or
S3-64 Programming & Data Structures
14. Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted (a) both are procedural languages
in that order into an initially empty binary search tree. (b) both are based on l-calculus
The binary search tree uses the usual ordering on natural (c) both are declarative
numbers. What is the in-order traversal sequence of the (d) both use Horn-clauses
resultant tree? [2003, 1 Mark] 21. An Abstract Data Type (ADT) is [2005, 1 Mark]
(a) 7 5 10 3 2 4 6 8 9 (b) 0 2 4 3 1 6 5 9 8 7 (a) same as an abstract class
(c) 0 1 2 3 4 5 6 7 8 9 (d) 9 8 6 4 2 3 0 1 5 7 (b) a data type that cannot be instantiated
15. A data structure is required for storing a set of integers (c) a data type for which only the operations defined on it
such that each of the following operations can be done can be used, but none else
in O(log n), time, where n is the number of elements in the (d) All of the above
set 22. What does the following C-statement declare?
I. Deletion of the smallest element. int (*f) int*); [2005, 1 Mark]
II. Insertion of an element, if it is not already present in (a) A function that takes an integer pointer as argument
the set and returns an integer
Which of the following data structures can be used for (b) A function that takes as argument and returns an integer
this purpose? [2003, 2 Marks] pointer
(a) A heap can be used but not a balanced binary (c) A pointer to a function that takes an integer pointer as
search tree argument and returns an integer
(b) A balanced binary search tree can be used but not (d) A function that takes an integer pointer as argument
a heap and returns a function pointer
(c) Both balanced binary search tree and heap can be 23. Match the following List I with List II and select the
used correct answer using the codes given below the lists.
(d) Neither balanced binary search tree nor heap can be
used List I List II
16. The goal of structured programming is to
[2004, 1 Mark] P. Functional 1. Command-based, procedural
(a) have well indented programmes Q. Logic 2. Imperative, abstract data types
(b) be able to infer the flow of control from the compiled
code R. Object-oriented 3. Side-effect free, declarative,
(c) be able to infer the flow of control form the program expression evaluation
text S. Imperative 4. Declarative, clausal
(d) avoid the use of GOTO statements representation, theorem proving
17. Consider the following C function :
void swap (int a, int b)
{int temp; [2005, 2 Marks]
temp = a; (a) P–2, Q–3, R–4, S–1 (b) P–4, Q–3, R–2, S–1
a = b; (c) P–3, Q–4, R–1, S–2 (d) P–3, Q–4, R–2, S–1
b = temp; 24. Assume that the operators +, –, ×, are left associative and ^
} is right associative. The order of precedence (from highest
In order to exchange the values of two variables x and y. to lowest) is ^, ×, +, –. The postfix expression corresponding
[2004, 1 Mark] to the infix expression a + b × c – d ^ e ^ f is [2005, 2 Marks]
(a) Call swap (x, y) (a) abc × + def ^^ – (b) abc × + de^f^–
(b) Call swap (& x, & y) (c) ab + c × d – e^f^ (d) – + a × bc ^^ def
(c) Swap (x, y) cannot be used as it does not return any 25. A circularly linked list is used to represent a queue. A single
value variable p is used to access the queue. To which node should
(d) Swap (x, y) cannot be used as the parameters are p point such that both the operations en-queue and de-
passed by value queue can be performed in constant time? [2005, 2 Marks]
18. The best data structure to check whether an arithmetic
expression has balanced parenthesis is a [2004, 1 Mark]
(a) queue (b) stack
(c) tree (d) list
19. Which one of the following are essential features of an Front Rear
object-oriented programming language? [2005, 1 Mark]
1. Abstraction and encapsulation
2. Strictly - typedness
p P
3. Type-safe property coupled with sub-type rule
4. Polymorphism in the presence of inheritance
(a) 1 and 2 (b) 1 and 4 (a) Rear node
(c) 1, 2 and 4 (d) 1, 3 and 4 (b) Front node
20. A common property of logic programming languages and (c) Not possible with a single pointer (d)
(d) Node next to front
functional languages is [2005, 1 Mark]
S3-66 Programming & Data Structures
26. Consider the following C program segment: [2005, 2 Marks] (c) The algorithm has a non-linear polynomial complexity
char p [20] and uses branch and bound paradigm
char *s = “string”; (d) The algorithm uses divide and conquer paradigm.
int length = strlen (s); 31. A max-heap is a heap where the value of each parent is
for (i = 0; i < length, i++) greater than or equal to the value of its children. Which of
p[i] = s [length – i]; the following is a max-heap? [2011, 1 mark]
print f(“%s”, p);
(a) (b) 10
The output of the program is 10
(a) gnirts 8 6
8 6
(b) garbage dashing or no value printed
(c) gnirt 5 4 5 1 2
4 2
(d) no output is printed
1
27. Consider the following C-program [2005, 2 Marks]
double foo (double); /* Line 1 */ (c) 10 (d) 5
int main () { 5 6 2 8
double da, db;
// input da 4 8 2 1 4 6 10
1
db = foo (da);
32. Let G be a weighted graph with edge weights greater than
}
one and G be the graph constructed by squaring the weights
double foo (double a) {
of edges in G. Let T and T’ be the minimum spanning trees of
return a;
G and G’ respectively, with total weights t and t’. Which of
The above code compiled without any error or warning. If the following statements is true? [2012, 2 Marks]
Line 1 is deleted, the above code will show (a) T’ = T with total weight t’ = t2
(a) no compile warning or error (b) T’ = T with total weight t’ = t2
(b) some compiler-warnings not leading to unintended (c) T’ = T but total weight t’ = t2
results (d) None of the above
(c) some compiler-warnings due to type-mismatch 33. Consider the following program in C language :
eventually leading to unintended results #include <stdio.h>
(d) compiler errors main ()
28. The inorder and preorder traversal of a binary tree are {
d b e a f c g and a b d e c f g, respectively int i;
The postorder traversal of the binary tree is [2007, 2 Marks] int *pi = &i;
(a) d e b f g c a (b) e d b g f c a scanf ("%d", pi);
(c) e d b f g c a (d) d e f g b c a printf ("%d\n", i + 5);
29. Which languages necessarily need heap allocation in the }
runtime environment? [2011, 2 Marks] Which one of the following statements is TRUE ?
(a) Those that support recursion [2014, Set-1, 1 Mark]
(b) Those that use dynamic scoping (a) Compilation fails
(c) Those that allow dynamic data structures (b) Execution results in a run-time error.
(d) Those that use global variables (c) On execution, the value printed is 5 more than the
30. An algorithm to find the length of the longest monotonically address of variable i.
increasing sequence of numbers in an array A[0 – n] is given (d) On execution, the value printed is 5 more than the
below. integer value entered.
Let Li denotes the length of the longest monotonically 34. Suppose a stack implementation supports an instruction
increasing sequence starting at index i in the array. REVERSE, which reverses the order of elements on the
Initialize Ln–1 = 1 stack, in addition to the PUSH and POP instructions. Which
For all i such that 0 £ i £ n - 2 one of the following statements is TRUE with respect to
this modified stack? [2014, Set-2, 2 Marks]
ì1 + Li +1,if A [ i ] < A [ i + 1]ü (a) A queue cannot be implemented using this stack.
Li = í ý (b) A queue can be implemented where ENQUEUE takes
î 1, otherwise þ a single instruction and DEQUEUE takes a sequence
Finally the length of the longest monotonically increasing of two instructions.
sequence is Max L, L, ... L. (c) A queue can be implemented where ENQUEUE takes
Which of the following statements is true? [2011, 1 mark] a sequence of three instructions and DEQUEUE takes
(a) The algorithm uses dynamic programming paradigm a single instruction.
(b) The algorithm has a linear complexity and uses branch (d) A queue can be implemented where both ENQUEUE
and bound paradigm and DEQUEUE take a single instruction each.
Programming & Data Structures S3-67
35. Consider the following rooted tree with the vertex labeled P y = 3;
as the root : func1(y, x, x);
print x;
P print y;
}
func 1 (x, y, z)
{
Q R y = y + 4;
z = x + y + z;
} [2002, 2 Marks]
(a) 10, 3 (b) 31, 3
(c) 27, 7 (d) None of these
U V 39. Consider the following three C functions
T
S [P1] int*g(void)
{
intx = 10;
W return (&x);
}
[P2] int*g(void)
The order in which the nodes are visited during an in-order {
traversal of the tree is [2014, Set-3, 1 Mark] int* px;
(a) SQPTRWUV (b) SQPTUWRV *px = 10;
(c) SQPTWUVR (d) SQPTRUWV return px;
}
Problem Based MCQs [P3] int*g(void)
36. Consider the following C declaration {
struct { int*px
short s [ 5 ] px = (int*) malloc (size of (int));
union { *px = 10;
float y ; return px;
long z ; }
} u; Which of the above 3 functions are likely to cause
} t; problems with pointers? [2002, 2 Marks]
Assume that objects of the type short, float and long (a) Only P3 (b) P1 and P3
occupy 2 byte, 4 byte and 8 byte, respectively. The (c) P1and P2 (d) P1, P2 and P3
memory requirement for variable t, ignoring alignment 40. Consider the following program :
considerations, is [2000, 1 Mark] Program P2
(a) 22 byte (b) 14 byte var n:int :
(c) 18 byte (d) 10 byte procedure W (var x:int)
37. The value of j at the end of the execution of the following begin
C program int incr (int i) x = x + 1;
{ print x;
static int count = 0; end
count = count + i; procedure D
return (count); begin
} varn:int;
main () { n = 3;
int i j; W (n);
for (i = 0; i < = 4; i + +) End
j = incr (i); begin || begin P2
} n = 10;
is [2000, 2 Marks] D;
(a) 10 (b) 4 end
(c) 6 (d) 7 If the language has dynamic scopping and parameters are
38. What is printed by the print statements in the program P1 passed by reference, what will be printed by the program?
assuming call by reference parameter passing?
[2002, 2 Marks]
Program P1()
(a) 10 (b) 11
{
(c) 3 (d) None of these
x = 10;
S3-68 Programming & Data Structures
77. In a binary tree with n nodes, every node has an odd number scalar multiplications is pqr + prs + pst. If p = 10, q = 100, r =
of descendant. Every node is considered to be its own 20, s = 5 and t = 80, then the minimum number of scalar
descendant. What is the number of nodes in the tree that multiplications needed is [2011, 2 Marks]
have exactly one child? [2010, 1 Mark] (a) 248000 (b) 44000
(a) 0 (b) 1 (c) 19000 (d) 25000
(c) (n – 1)/2 (d) n – 1 83. What does the following fragment of C-program print?
78. What does the following program print? [2011, 2 Marks] char c[ ] = “GATE 2011” [2011, 1 Mark]
#include < stdio.h > char * p = c;
void f (int *p, int *q) printf (“%s”, p + p[3] – p[1];
p = q; (a) GATE 2011 (b) E 2011
*p = 2; (c) 2011 (d) 011
} 84. Suppose a circular queue of capacity (n – 1) elements is
int i = 0, j = 1; implemented with an array of n elements. Assume that the
int main () { insertion and deletion operations are carried out using REAR
f(&i, &j); and FRONT as array index variables, respectively. Initially
printf(“%d%d/n”, i, j); REAR = FRONT = 0. The conditions to detect queue full and
} queue empty are [2012, 2 Marks]
(a) 2 2 (b) 2 1
(a) full (REAR + 1) mod n = = FRONT
(c) 0 1 (d) 0 2
empty: REAR = = FRONT
79. Consider evaluating the following expression tree on a
(b) full (REAR + 1) mod n = = FRONT
machine with load store architecture in which memory can be
empty: (FRONT + 1) mod n = = REAR
accessed only through load and store instructions. The
(c) full (REAR = = FRONT
variables a, b, c, d and e are initially stored in memory. The
binary operators used in this expression tree can be evaluated empty: (REAR + 1) mod n = = REAR
by the machine only when the operands are in registers. The (d) full (FRONT + 1) mod n = = REAR
instructions produce result only in a register. If no intermediate empty: (REAR = = FRONT
results can be stored in memory, what is the minimum number 85. Consider the program given below, in a block-structured
of registers needed to evaluate this expression? pseudo-language with lexical scoping an nesting of
[2011, 2 Marks] procedures permitted.
Program main;
+ Var ......
Procedure A1;
– – Var .....
Call A2;
a b e End A1
+
Procedure A2;
c d Var ...
Procedure A21;
(a) 2 (b) 9 Var....
(c) 5 (d) 3 Call A1;
80. We are given a set of n distinct elements and an unlabelled End A21
binary tree with n nodes. In how ways can we populate the Call A21;
tree with the given set so that it becomes a binary search tree? End A2;
(a) 0 (b) 1 [2011, 2 Marks] Call A1;
1 2n End main.
(c) n! (d) Cn Consider the calling chain:
n +1
81. Which of the given options provides the increasing order of Main ® A1 ® A2 ® A21 ® A1
asymptotic complexity of functions f1, f2, f3 and f4? The correct set of activation records along with their access
links is given by [2012, 2 Marks]
f1(n) = 2n, f2(n) = n 3/2, f3(n) = nlog2 n, f4(n) = n log2n
[2011, 2 Marks] (a) Main
(a) f3, f2, f4, f1 (b) f3, f2, f1, f4
A1
(c) f2, f3, f1, f4 (d) f2, f3, f4, f1
82. Four matrices M1, M2, M3 and M4 are of dimensions p.q, A2
q.r, r.s and s.t respectively can be multiplied in several ways A21
with different number of total scalar multiplications. For
example, when multiplied as (M1 × M2) × (M3 × M4) the Prame A1
pointer Access
total number of scalar multiplications, is pqr + rst + prt. When links
multiplied as (((M1 × M2) × M3) × M4) the total number of
S3-74 Programming & Data Structures
93. Consider the following C function in which size is the (d) The function will exhaust the runtime stack or run
number of elements in the array E: into an infinite loop when j = 50.
int MyX(int*E, unsigned int size) 97. Let A be a square matrix of size n × n. Consider the following
{ pseudocode. What is the expected output ?
int Y = 0; [2014, Set-3, 1 Mark]
int Z; c = 100;
int i, j, k;
for i = 1 to n do
for (i = 0; i < size; i++)
Y = Y + E[i]; for j = 1 to n do
for (i = 0; i < size; i++) {
for (j = i; j < size; j++) Temp = A [i] [j] + C;
{ A [i] [j] = A [j] [i];
Z = 0; A [j] [i] = Temp – C;
for (k = i; k <= j; k++) }
Z = Z + E[k]; for i = 1 to n do
if (Z > Y) for j = 1 to n do
Y = Z; output (A [i] [j]);
} (a) The matrix A itself
return Y; (b) Transpose of the matrix A
} (c) Adding 100 to the upper diagonal elements and
The value returned by the function MyX is the subtracting 100 from lower diagonal elements of A
[2014, Set-1, 2 Marks]
(d) None of the above
(a) maximum possible sum of elements in any sub-array
of array E.
(b) maximum element in any sub-array of array E. Linked Answer Type MCQs
(c) sum of the maximum elements in all possible sub-arrays
of array E. Statement for Linked Answer Questions 98 and 99
(d) the sum of all the elements in the array E. A 3-ary max heap is like a binary max heap, but instead of 2
94. Suppose n and p are unsigned int variables in a C program. children, nodes have 3 children. A 3-ary heap can be
We wish to set p to nC3. If n is large, which one of the following represented by an array as follows : The root is stored in the
statements is most likely to set p correctly? first location, a[0], nodes in the next level, from left to right is
[2014, Set-2, 1 Mark] stored from a[1] to a [3]. The nodes from the second level of
(a) p = n*(n–1)*(n–2) / 6; the tree from left to right are stored from a[4] location onward.
(b) p = n*(n–1) / 2*(n–2) / 3; An item x can be inserted into a 3-ary heap containing n items
(c) p = n*(n–1) / 3*(n–2) / 2; by placing x in the location a[n] and pushing it up the tree to
(d) p = n * (n-1) * (n–2) / 6.0; satisfy the heap property.
95. A priority queue is implemented as a Max-Heap. Initially, it 98. Which one of the following is a valid sequence of
has 5 elements. The level-order traversal of the heap is: 10, elements in an array representing 3 – ary max heap?
8, 5, 3, 2. Two new elements 1 and 7 are inserted into the (a) 1, 3, 5, 6, 8, 9 [2006, 2 Marks]
heap in that order. The level-order traversal of the heap
(b) 9, 6, 3, 1, 8, 5
after the insertion of the elements is: [2014, Set-2, 1 Mark]
(a) 10, 8, 7, 3, 2, 1, 5 (b) 10, 8, 7, 2, 3, 1, 5 (c) 9, 3, 6, 8, 5, 1
(c) 10, 8, 7, 1, 2, 3, 5 (d) 10, 8, 7, 5, 3, 2, 1 (d) 9, 5, 6, 8, 3, 1
96. Consider the C function given below. 99. Suppose the elements 7, 2, 10 and 4 are inserted in that
int f(int j) order, into the valid 3 – ary max heap found in the above
{ question 60. Which one of the following is the sequence
static int i = 50; of items in the array representing the resultant heap?
int k; [2006, 2 Marks]
if (i == j) (a) 10, 7, 9, 8, 3, 1, 5, 2, 6, 4
{ (b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
printf(“something”); (c) 10, 9, 4, 5, 7, 6, 8, 2, 1, 3
k = f(i); (d) 10, 8, 6, 9, 7, 2, 3, 4, 1, 5
return 0;
Statements for Linked Answer Questions 100, 101 and 102:
}
else return 0; Consider a binary max-heap implemented using an array:
} 100. Which one of the following array represents a binary max-
Which one of the following is TRUE? heap? [2009, 1 Mark]
[2014, Set-2, 2 Marks] (a) {25, 12, 16, 13, 10, 8, 14}
(a) The function returns 0 for all values of j. (b) {25, 14, 13, 16, 10, 8, 12}
(b) The function prints the string something for all values
of j. (c) {25, 14, 16, 13, 10, 8, 12}
(c) The function returns 0 when j = 50. (d) {25, 14, 12, 13, 10, 8, 16}
S3-76 Programming & Data Structures
101. What is the content of the array after two delete operations (a) 46, 42, 34, 52, 23, 33 (b) 34, 42, 23, 52, 33, 46
on the correct answer to the previous question? (c) 46, 34, 42, 23, 52, 33 (d) 42, 46, 33, 23, 34, 52
[2009, 1 Mark] 104. How many different insertion sequences of the key values
(a) {14, 13, 12, 10, 8} (b) {14, 12, 13, 8, 10} using the same hash function and linear probing will result
(c) {14, 13, 8, 12, 10} (d) {14, 13, 12, 8, 10} in the hash table shown above? [2010, 2 Marks]
102. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an (a) 10 (b) 20
initially empty hash table of length 10 using open addressing (c) 30 (d) 40
with hash function h(k) = k mod 10 and linear probing. What
is the resultant hash table? [2009, 1 Mark] Common Data MCQs
(a) (b) Common Data for Questions 105 and 106.
0 0
Consider the following recursive C function that takes two
1 1 arguments unsigned into foo (unsigned int, n, unsigned int r) {
2 2 2 12 if n > 0 return n% foo (n/r, r);
3 23 3 13 else return 0,
4 }
4
105. What is the return value of the function foo, when it is called
5 15 5 5 as foo (513, 2)? [2011, 2 Marks]
6 6 (a) 9 (b) 8
7 7 (c) 5 (d) 2
8 18 8 18 106. What is the return value of the function foo, when it is called
as foo (345, 10)? [2011, 2 Marks]
9 9 (a) 345 (b) 12
(c) 5 (d) 3
(c) 0 (d) 0 Common Data for Questions 107 and 108:
1 1 The procedure given below is required to find and replace
2 12 2 12, 2 certain characters inside an input character string supplied in
3 13 3 13, 3, 23 array A. The characters to be replaced are supplied in array
oldc, while their respective replacement characters are supplied
4 2 4
in array newc. Array A has a fixed length of five characters,
5 3 5 5, 15 while arrays oldc and newc contain three characters each.
6 23 6 However, the procedure is flawed.
7 5 7 void find_and_replace (char *A, char *oldc, char *newc)
{
8 18 8 18
for (int i=0; i<5; i++)
9 15 9 for (int j=0; j<3; j++)
if (A[i]==oldc[j]) A[i] =
Statements for Linked Answer Questions 103 and 104 : newc[j];
}
A hash table of length 10 uses open addressing with hash function
h(k) = k mod 10, and linear probing. After inserting 6 values into The procedure is tested with the following four test cases.
an empty has table, the table is as shown below. 1. oldc = “abc”, newc = “dab”
2. oldc = “cde”, newc = “bcd”
0 3. oldc = “bca”, newc = “cda”
4. oldc = “abc”, newc = “bac”
1
2 42 107. The tester now tests the program on all input strings of
length five consisting of characters ‘a’, ‘b’, ‘c’,
3 23
‘d’ and ‘e’ with duplicates allowed. If the tester
4 34 carries out this testing with the four test cases given
5 52 above, how many test cases will be able to capture the
6 46 flaw? [2013, 2 Marks]
(a) Only 1 (b) Only 2
7 33
(c) Only 3 (d) All four
8
9 108. If array A is made to hold the string “abcde”, which of
the above four test cases will be successful in exposing
103. Which one of the following choices gives a possible order the flaw in this procedure? [2013, 2 Marks]
in which the key values could have been inserted in the (a) 2 only (b) 4 only
table? [2010, 2 Marks] (c) 3 and 4 only (d) None
Programming & Data Structures S3-77
13. (d) From the given declaration it is clear that int* A[10] 18. (b) Balanced parenthesis in an equation are such that
is an array of 10 printers. Thus, B[2][3] can be used the no. of opening and closing parenthesis and in
as left hand side as it gives the element of second correct order should be there. We can check
row in the third column. balancing using stack. When we get any opening
14. (c) We can solve it in shortcut that the first given parenthesis, then we push that in the stack & if we
element in 7, so we need to choose that particular get a closing one, then we pop the stack. After the
option in which 7 is at the right place i.e. all the complete scanning of input string if stack is found
elements on its left should be smaller than it & all the empty then the arithmetic expression is balanced.
elements on the right should be equal & greater than
19. (b) Object Oriented Programming (OPP) is a programming
it.
paradigm. The language is object oriented as it use
So this rule is followed in option (c) only.
objects. Objects are the data structures that contain data
To make in order of a binary search tree.
fields and methods together with their interactions.
(i) Start with the root node.
(ii) Scan its left subtree, The main features of the Programming techniques are
(iii) If the node in subtree has any left child then 1. data abstraction
store the node in stack & repeat this step for 2. encapsulation
its left child unit no. left child of any node. 3. modularity
(iv) If leaf reached then print the node & pop the 4. polymorphism
stack, print the poped value.
5. inheritance
(v) Check its right subtree & repeat step (III) for it.
(vi) When stack empty then stop Therefore, the essential features are given by statements
So here inorder is 0 1 2 3 4 5 6 7 8 9. Actually a fact (i) and (iv).
can be remembered that inorder traversal of a BST 20. (c) Languages needs declaration of any statement that we
leads to a sorted sequence of elements. write before its use thus, the common property of both
Hence (c) is correct option. the languages is that both are declarative.
15. (b) Both the tasks can be performed by both the data 21. (c) An abstract data type is a mathematical model for a certain
structures but heap is a data structure where to class of data structures that have similar behaviour. An
perform these function every element has to be abstract data type is indirectly defined by the operations
checked so O(n) complexity. and mathematical constraints thus, is a user defined data
But the balance binary search tree is efficient data type, not a system defined, that can perform operations
structure since at every decision it selects one of its defined by it on that data.
subtree to no. of elements to be checked are reduced 22. (c) Syntax to declare pointer to a function =>datatype
by a factor of 1/2 every time. (*pointer_variable)(list of arguments)
n /2!= x To make a pointer to a function =>pointer_variable =
x = logn function_name
Hence (b) is correct option.
Note: don't use parenthesis of the function.
16. (d) Structured programming : It is way of programming
using the sub-structure method, i.e., splitting the To call (invoke) the function =>pointer_variable(list of
programs into sub-sections. Structured programming arguments)
prevents confusing transfer of control of avoiding 23. P. Functional programming is declarative in nature,
the use of GOTO statements. involves expression evaluation, & side effect free.
17. (d) Why a, b and c are incorrect? a) call swap (x, y) will Q. Logic is also declarative but involves theorem
not cause any effect on x and y as parameters are proving.
passed by value. b) call swap (& x, & y) will no work R. Object oriented is imperative statement based &
as function swap() expects values not addresses have abstract (general) data types.
(or pointers). c) swap (x, y) cannot be used but S. Imperative : The programs are made giving commands
reason given is not correct. Here the function takes & follows definite procedure & sequence.
the arguments by value. Hence (d) is correct option.
Option (a) sends parameter by value but only the 24. (a) a + b × c – d ^ e ^ f
local variable a & b will be exchanged but not the a+b×c–d^e f^
actual variables x & y so incorrect. a+b×c–def^ ^
Option (b) is incorrect sending address of x & y. a+bc×–d e f ^ ^
Option (c) swap (x, y) is usable there is no need to abc× –d e f ^ ^
return. abc× +d e f ^ ^
Option (d) is the opposite statement of option (a), it a b c × + d e f ^ ^–
says that the values are passed by value so won't the result is obtained.
swap so the option is correct.
S3-80 Programming & Data Structures
25. (c) As given p is a single variable that is used to access the old graph G in the old minimum spanning tree T must be
queue and with the single variable it is not possible to replaced by a new edge in tree T' from the graph G' with
perform both the functions of enqueue and dequeue with squared edge weights. The new edge from G' must have
a constant time since, insertion and deletion are a lower weight than the edge from G. This implies that
operations that needs to be done from the opposite end there exists some weights C1 and C2 such that C1 < C2
of the queue rear and front respectively. and C12 >= C22. This is a contradiction.
26. (b) The program undergoes normal execution upto line Sums of squares of two or more numbers is always smaller
number 7 since, no error is present til there but as soon than square of sum.
as the execution goes to line 8 an error occurs as in this Example: 22 + 22 < 42
the pointer s is assigned a character variable, i.e., p and 33. (d) We concentrate on following code segment:
this assignment is not permissible in C language. Thus, ® int *Pi = & i ;
the program produces a garbage value as an output or Nothing wrong as ‘Pi’ is declared as integer pointer
no output is returned. and is assigned the address of ‘i’ which is an “int”.
27. (c) Whenever the a function’s data type is not declared in ® scanf (“%d”, Pi);
the program, the default declaration is taken into We know that scanf ( ) has two arguments:
consideration. By default, the function foo in this is First is control string (“%d” in this case), telling it
assumed to be of int type, then also it returns a double what to read from the keyboard.
type of value. This situation will generate compiler Second is the address where to store the read item.
warning due to this mismatch leading to unintended So, ‘Pi’ refers to the address of “i”, so the value
results. scanned by scanf ( ) will be stored at the address of
28. (a) The inorder traversal sequence is dbeafcg and the ‘i’.
preorder traversal sequence is abdecfg so, the tree is Above statement is equivalent to:
scanf (“%d”, & i);
a Finally the best statement:
printf (“%d\n”, i + 5);
It prints the value 5 more than the value stored in i.
b c So, the program executes successfully and prints the
value 5 more than the integer value entered by the
g user.
d e f 34. (c) The queue can be implemated where ENQUEUE takes
a sequence of three instructions (reverse, push,
In the postorder traversal, the sequence is debfgca. reverse) and DEQUEUE takes a single instruction
29. (c) linked data structures allow more flexibility in and the (pop).
implementation of these linked data structure is through 35. (a) The in order transversal is as :
dynamic data structures left, root, middle, right
30. (a) The algorithm has dynamic programming paradigm as i \ Nodes are visited in SQPTRWUV order.
has been chosen randomly.
31. (b) A binary tree is max-heap if it is a complete binary tree (A PROBLEM BASED MCQs
complete binary tree is a binary tree in which every level,
except possibly the last, is completely filled, and all nodes 36. (c) The amount of memory required to store a structure
are as far left as possible) and it follows the max-heap variable is the sum of the sizes of all its members.
property (value of each parent is greater than or equal to But in the case of union, the amount of memory
the values of its children). required is the amount required by its largest
(a) is not a max-heap because it is not a complete binary member. Therefore u, which is a union member of the
tree struct, occupies only 8 bytes of memory, because
(b) is a max-heap because it is complete binary tree the largest memory is 8 bytes consumed by long z;.
and follows max-heap property. Another member in the struct is short s [5], this will
(c) is not a max-heap because 8 is a child of 5 in this occupy 10 bytes of memory ( 2 bytes x 5). Hence
tree, so violates the max-heap property. total 10 + 8 =18 bytes.
(d) is not a max-heap because 8 is a child of 5 in this 37. (a) Count is static variable in incr(). Statement static int
tree, so violates the max-heap property. There are count = 0 will assign count to 0 only in first call.
many other nodes in this tree which violate max- Other calls to this function will take the old values
heap property in this tree. of count. Count will become 0 after the call incr(0).
32. (d) Squaring the weights of the edges in a weighted graph Count will become 1 after the call incr(1) Count will
will not change the minimum spanning tree. Assume the become 3 after the call incr(2) Count will become 6
opposite to obtain a contradiction. If the minimum after the call incr(3) Count will become 10 after the
spanning tree changes then at least one edge from the call incr(4)
Programming & Data Structures S3-81
38. (b) Note the order in which parameters are passed. T(n) = åT(X)T(k – 1)
Inside func1(), x will actually refer to y of main (); K=1 to n
and y and z will refer to x of main (). The statement Expanding forT (k – 1), we get
y = y + 4; will result in 14 and statement z = x + y T(n) = åT(X).T(0) T(1) T(2).....T(n – 1)]
+ z will make z = 3 + 14 + 14 = 31 (because y and K=1 to n
z point to same variable x of main). Since z refers to no. of nodes in left sub-tree denoted by K
x of main(), main will print 31. Total nodes = n
39. (c) P1 : Here the function is returning address of the So remaining node n – (k – 1) i.e., nodes in the right sub-
variable x (& x ) but the return type is pointer to tree.
integer not address. So incorrect. So = n – k + 1
P2 : *px = 0 directly assigned a value but still px So overall we can say that the no. of different BST's
doesn't point to any memory location, so memory on n different elements.
T(n) = åT(n – k +1)T(k – 1)
initialization or allocation should be done before. So
K=1 to n
incorrect.
43. (d) Here each of PURSH & POP operation take
P3: Correction made in P2, memory pre allocated, So
X seconds &Y seconds are elapsed between two
correct.
consecutive stack operations. m is the life time of
Hence (c) is correct option. element in stack.
40. (d) n = 10 given but not passed to D. In D, n = 3 &W(n) So m X is time for push. m X is time for pop. m Y
increments by 1. So n=n+1=4. is time for intermediate
Hence (d) is correct option. So total m(2X+Y)
41. (b) The function is rewritten as Here initial value of s Average stack life = m( 2X +Y)/ m
increments every time with a factor of (p)x/i = 2X + Y
= Y +2X
Loop
P S 44. (c) 2-3-4 B-tree means the min degree of a node is two
Counter (i) & it can be max 4. So maximum of 3 elements can be
1 x 1+x there in a node.
2 x * x / 2.1 = x / 2.1 1 + x + x 2 / 2
2
x 2 x x3
3 * = .2.1 1 + x + x 2 / 2!+ x 3 / 3!
2 3 3
x3
4 * x / 4 = x 4 / 4! 1 + x + x 2 / 2!+ x 3 / 3!+ x 4 / 4!
3!
G
Thus it can be checked for every value. Here the
assumption is that the value of y is very large so y LPU
approaches infinity So the series 1+ x + x2 / 2! + x3
/ 3!...till infinity will have infinite terms & from our QT
BGHI N VXZ
previous knowledge we know that this series is
expansion of ex (exponential series) so.
1 + x + x2 / 2! + x3 / 3!...........till infinity = ex
Hence (b) is correct option. No. of Element >3
42. (c) Binary search tree has a root node & its 2 sub-trees.
Here in this node the no. of element >3.
So for every node other than the leaves, all the
So we need a split or rotation.
elements smaller than the node are its left subtree &
Since the adjacent child has no. of element
all the nodes which have value equal to or greater
< = n/2= 4/2 = 2
than that node are at right sub-tree. so we apply a right rotation.
Root LPU
A
BGHI N QT VXZ
B C
Left Right LPU
Sub-tree Sub-tree
n(B) = no. of nodes in left sub-tree
n(C)" no. of nodes in right sub-tree BGH IN QT VXZ
T(n) = n(B) + n(C) + 1 Hence (c) is correct answer.
S3-82 Programming & Data Structures
45. (b) If (!A[J]) condition was as follows 47. (b) Here the return 1 any 1 of the following should be
(!A[J]) = = 0) correct.
Then, it prints a non zero value in the array (a) P == NULL i.e the list is empty (ends)
{m|m £ n, (Ei) [m = i2]} (b) P ® next = NULL i.e., have one element.
46. (a) Here X is the global variable so still 5. (c) P->data <= p->next ->data i.e., the element is
Here this is global X whose xy has been changed to smaller than its next element also. This is true for
6 so 6 is printed whole list. Since &&f(p “next”) is also there.
12 66 So overall it gives that the elements should be in
First x = 5 sorted order.
Then by function P(&x) 48. (d) Let take MAXSIZE =10
X = 5 +2 = 7
Then by function Q(x) 1 2 3 4 5 6 7 8 9 10
z =z+x
= 7 + 5 = 12
Here x is global variable so still it is 5.
Return to function P(&x) Stack 1 Stack 2
Y = 7–1= 6
print x =7 Top 1 Top 2
return to main
Print x = 6 Here the stack will be fuel if both top 1 & top 2 are
Here this is global x whose *y has been changed at the adjacent index values i.e., their difference is 1.
to 6 so 6 is printed. So top 1 = top 2 – 1
Here (d) is correct option.
15
10 10
1 15 1 15
12
3 12 3
5 5
16
10
1
1 15
2
3 12 16
3
5
The height of the leaf node (5) is high 3.
Hence (b) is correct option.
Programming & Data Structures S3-83
50. (a) We have to store frequencies of scores above 50. That From the given code it is found that foo is a recursive
is number of students having score 51, number of function and when the function foo (a, sum) is called
students having score 52 and so on. For that an array of where a = 2048 and sum = 0 as per given conditions.
size 50 is the best option. Then, the execution of the function takes in the following
51. (a) manner.
52. (c) This is an implementation of Euclid's algorithm to i) k= n % 10 => modulus operator will return the
find GCD remainder. for example, if n=2048, then 2048 %10 will store
Here if m > n, then m = m – n the value 8 in k.
m < n, then n = n – m ii) j is declared as integer datatype in foo function.
Let take X = 24, Y = 9 Therefore after division if the result contains decimal
Then m = 24, n = 9 part, it will be truncated and only the integer part will be
iteration m n stored in j. For example if j=2048/10, (actual result = 204.8)
1 24 – 9 = 15 9 then 204 will be stored in j.
2 15 – 9 = 6 9 iii) The sum variable declared in the main function will
3 6 9–6=3 not be used by the foo function.
4 6–3=3 3 59. (b) For the given code only the statements S2 and S3 are
Here m = n, so n returned valid and thus, are true. Since, the code may generate a
Which is GCD (Greatest common divisor) of X&Y segmentation fault at runtime depending on the
Hence (c) is correct option. arguments passed as the arguments are passed by
53. (c) Here we take let x = 16 reference and also the swap procedure is correctly
Loop will stop when x – y = 0 or > 0 implemented.
Iteration X Y
1 (16 + 1) / 2 = 8 16 / 8 = 2 60. (d) Both functions work1 &work2 performs the same task,
2 (8 + 2) / 2 = 5 16 / 5 = 3 therefore S1 is true.
3 (5 + 3) / 2 = 4 16 / 4 = 4 In S2 it is asking about improvement in performance i.e.
Here X=Y reduction in CPU time. When compared work2 will reduce
Then take X which is 4. the CPU time, because in work1 a[i+2] is computed twice
(m)1/2 = 4=(16)1/2 but in work2 a[i+2] is computed once and stored in t2,
Hence (c) is correct option. and then t2 is used. When we consider the performance
54. (d) Value initialized by 0 in terms of reduction in CPU time, S2 is correct.
If any root node has left child then it adds 1 to the 61. (c) The condition (i) is true if the last inserted element in c[]
value & move to left child & if any mode has right is from a[] and condition (ii) is true if the last inserted
child also then also calculated the value using element is from b[].
recursion & take maximum of both left & right value 62. (a) The order in which insert and delete operations are
is taken. performed matters here.
So we know that height is the largest distance The best case: Insert and delete operations are performed
between root node & leaf. alternatively. In every delete operation, 2 pop and 1 push
So this program calculates heights. operations are performed. So, total m+ n push (n push
Hence (d) is correct option. for insert() and m push for delete()) operations and 2m
55. (a) pop operations are performed.
56. (c) The iterations that the given code will undergo are: The worst case: First n elements are inserted and then m
From the given conditions we does not take into account elements are deleted. In first delete operation, n + 1 pop
when n = 1 operations and n push operation are performed. Other
Iteration 1 than first, in all delete operations, 1 pop operation is
N = 1 + 1 = 2 therefore, i = 2 performed. So, total m + n pop operations and 2n push
Iteration 2 operations are performed (n push for insert() and m push
N = 2 + 2 = 4 therefore, i = 3 for delete())
Iteration 3 63. (d) From the statement j = j*2 in the code we get to know
N = 4 + 3 = 2 = 4 therefore, i = 4 that j increases in power of 2’s. Let us say that this
Hence, the value returned after three iterations is 7 statement execute x times then, according to the question
When, i = 4 and it also fulfill the condition of n>=5 for while loop
57. (a) Inorder traversal of a BST always gives elements in 2^x < = n
increasing order. Among all four options, (a) is the only Therefore, x < = log2n
increasing order sequence. And also for termination of while loop there will be an
58. (d) Sum has no use in foo(), it is there just to confuse. extra comparison required. Thus, total number of
Function foo() just prints all digits of a number. In main, comparisons = x + 1
there is one more printf statement after foo(), so one = [log2n] + 2
more 0 is printed after all digits of n.
S3-84 Programming & Data Structures
64. (c) A node is a leaf node if both left and right child nodes of When ^ is read, top two are popped and power(2^3) is
it are NULL. calculated
1) If node is NULL then return 0. 8, 8
2) Else If left and right child nodes are NULL return 1. When / is read, top two are popped and division(8/8) is
3) Else recursively calculate leaf count of the tree using performed
below formula. 1
Leaf count of a tree = Leaf count of left subtree + Next two tokens are values, so they are simply pushed.
Leaf count of right subtree After pushing 2 and 3, the stack is as follows
1, 2, 3
When * comes, top two are popped and multiplication is
performed.
1, 6
67. (a) The operator “?:” in C is the ternary operator which means
that, if the expression is exp 1? exp2 : exp3, so it means, if
exp1 is true then exp2 is returned as the answer else exp3
Example Tree is the required answer.
Leaf count for the above tree is 3. So, in the given expression let us consider x = 3, y = 4,
65. (d) We follow, the following steps to obtain the value of f(5) z = 2,
Then, expression becomes a
= (3 > 4)? ((3 > 2)? 3:2): ((4>2?4:2)
f(5)
From this, we get that 3>4 is false so we go for the else
r=5 part of the statement which is 4>2 and is true thus, the
f(3) + 2 = 18 answer is 4, the true part of the statement.
68. (b) The program gets executed in the following manner
f(2) + 5 = 16 Graphical Representation
f(1) + 5 = 11 c 4 b 1000 a 2000
1000 2000 3000
f(0) + 5 = 6
x py ppz
4 1000 2000
1
5000 6000 7000
66. (a) The algorithm for evaluating any postfix expression is Now, considering
fairly straightforward: int y, z;
1. While there are input tokens left **ppy + = 1; z = *ppz = 6
o Read the next token from input. *py + = 2; y = *py = 6
o If the token is a value x=4+3=7
+ Push it onto the stack. return x + y + z;
o Otherwise, the token is an operator and
(operator here includes both operators, and functions). c = 4; b & c; a = &b;
* It is known a priori that the operator takes n arguments. printf (“%d”, f(c, b, a)),
* If there are fewer than n values on the stack From the code,
(Error) The user has not input sufficient values in the
The output is printed as 6 + 6 + 7 = 19.
expression.
69. (d) The option chosen is
* Else, Pop the top n values from the stack.
?1 is ((c = getchar ( ))! = ‘\n’)
* Evaluate the operator, with the values as arguments.
?2 is putchar (c);
* Push the returned results, if any, back onto the stack.
Because the operator ‘1=’ has higher priority than ‘=’
2. If there is only one value in the stack
o That value is the result of the calculation. operator so according to this C = getchar () should be
3. If there are more values in the stack contained in brackets and when the string is reversed
o (Error) The user input has too many values. then the function putchar (c) is used so that the characters
Let us run the above algorithm for the given expression. can be printed.
First three tokens are values, so they are simply pushed. 70. (b) The function rearrange() exchanges data of every node
After pushing 8, 2 and 3, the stack is as follows with its next node. It starts exchanging data from the first
8, 2, 3 node itself.
Programming & Data Structures S3-85
71. (b) AVL trees are binary trees with the following restrictions. 75. (d) When the while loop ends, q contains address of second
(1) the height difference of the children is at most 1. last node and p contains address of last node. So we
(2) both children are AVL trees need to do following things after while loop.
a (i) Set next of q as NULL (q->next = NULL).
/ \ (ii) Set next of p as head (p->next = head).
/ \ (iii) Make head as p ( head = p)
b c
Step (ii) must be performed before step (iii). If we change
/ \ /
/ \ / head first, then we lose track of head node in the original
d e g linked list.
/ 76. (c) f() is a recursive function which adds f(a+1, n–1) to *a if
/ *a is even. If *a is odd then f() subtracts f(a+1, n–1) from
h *a. See below recursion tree for execution of f(a, 6).
72. (b) The program calculates nth Fibonacci Number. The f(add(12), 6) /*Since 12 is first element. a contains
statement t = fun ( n-1, fp ) gives the (n-1)th Fibonacci address of 12 */
number and *fp is used to store the (n-2)th Fibonacci |
Number. Initial value of *fp (which is 15 in the above |
prgram) doesn't matter. Following recursion tree shows 12 + f(add(7), 5) /* Since 7 is the next element, a+1
all steps from 1 to 10, for exceution of fun(5, &x).
contains address of 7 */
(1) fun(5, fp) |
/ \ |
(2) fun(4, fp) (10) t = 5, f = 8, *fp = 5 7 – f(add(13), 4)
/ \ |
(3) fun(3, fp) (9) t = 3, f = 5, *fp = 3 |
/ \
(4) fun(2, fp) (8) t = 2, f = 3, *fp = 2 13 – f(add(4), 3)
/ \ |
(5) fun(1, fp) (7) t = 1, f = 2, *fp = 1 |
/ 4 + f(add(11), 2)
(6) *fp = 1 |
73. (d) In a given program we take the test cases and apply. |
First take T1, if all value equal means 11 – f(add(6), 1)
a=b=c=d |
So, due to T1, a = b condition satisfied and S1 and S4 |
executed. 6+0
So, from T2 when all a, b, c, d distinct. So, the final returned value is
S1, S2 not execute, S3 execute. 12 + (7 – (13 – (4 + (11 – (6 + 0))))) = 15
from T3 when a = b then, S1 execute but c = d so, S2 not
77. (a) Such a binary tree is full binary tree (a binary tree where
execute but S3 and S4 execute but we have no need of T3
because we get all result from above two. every node has 0 or 2 children).
By using T4. If a! = b and c = d 78. (d) * p points to i and q points to j */
So, S1 not execute and S2 and S4 execute so all of S1, S2, void f(int *p, int *q)
S3, S4 execute and covered by T1, T2 and T4. {
74. (b) Let AX, BX, CX be three registers used to store results p = q; /* p also points to j now */
of temporary variables a, b, c, d, e, f. *p = 2; /* Value of j is changed to 2 now */
a(AX) = 1 }
b(BX) = 10
79. (d) R1 ¬ c, R2 ¬ d, R2 ¬ R1 + R2, R1 ¬ e, R2 ¬ R1-R2
c(CX) = 20
d(AX) = a(AX) + b(BX) Now to calculate the rest of the expression we must load
e(BX) = c(CX) + d(AX) a and b into the registers but we need the content of R2
f(AX) = c(CX) + e(BX) later.
b(BX) = c(CX) + e(BX) So we must use another Register.
e(BX) = b(BX) + f(AX) R1 ¬ a, R3 ¬ b, R1 ¬ R1-R3, R1 ¬ R1+R2
d(CX) = 5 + e(BX) 80. (b) It is stated that there is a binary tree and we have populate
return d(CX) + f(AX) the tree with n elements. Sorting the n elements in the
Thus, only 3 registers can be used without any increasing order,and placing them in the inorder traversal
overwriting of data.
nodes of the binarytree makes it only BST possible.
S3-86 Programming & Data Structures
81. (c) For n = 8 88. (c) The number of elements that can be sorted in Q
f1(n) = 2n = 28 = 256
f2(n) = n 3/2 = 83/2 = 8 ´ 8 ´ 8 = 8 × 2 2 = 16 2 æ log n ö
(log n) time using heap sort is Q ç log log n ÷
f3(n) = n log2 n(= 8 log2 8 = 8 × 3 = 24 è ø
f4(n) = n log 2 n = 8log2 8 = 83 = 64 × 8 = 512 Consider the number of elements is "k", which can
Þ f2, f3, f1, f4 be sorted in q (k log k) time.
82. (c) M1 × M2 × M3 Analyzing the options in decreasing order of
For (M1 × M2) × M3 = (p × q × r) + (p × r × s) complexity since we need a tight bound i.e., q.
= (10 × 100 × 20) + (10 × 20 × 5)
= 20000 + 1000 = 21000 æ log n ö
M1 × (M2 × M3) = (p × q × s) + (q × r × s) i.e., q (log n), Q ç , Q( log n ), Q(1)
è loglog n ÷ø
= (10 × 100 × 5) + (100 × 20 × 5)
M1 × (M2 × M3) < (M1 × M2) × M3 So if k Î Q (log n) time required for heap sort is O
= (10 × 100 × 5) + (100 × 20 × 5)
(k log k) i.e.,
M1 × (M2 × M3) < (M1 × M2) × M3
This, (M1 × (M2 × M3)) M4 = 15000 + p × s × t q (log n × log log n), But this is not in Q (log n)
= 15000 + 10 × 5 × 80
= 15000 + 4000 = 19000 æ log n ö
If k Î Q ç log log n ÷ time required for Heap Sort
83. (c) 2011 charc[] = "GATE2011"; è ø
p now has the base address string "GATE2011"
char*p =c;
p[3] is 'E' and p[1] is 'A'. æ log n æ log n ö ö
Qç ´ log ç
p[3] - p[1] = ASCII value of 'E' - ASCII value of 'A' = 4 è log log n è log log n ÷ø ÷ø
So the expression p + p[3] - p[1] becomes p + 4 which is
base address of string "2011
84. (a) FRONT points to the first element that we can remove æ é æ log n ö ùö
and then we increment FRONT REAR points to the first ç ê log ç ú÷
è log log n ÷ø ú÷
empty space in queue so we insert an element and i.e., Q log n ´ ê
ç
increment REAR so now initially queue is empty F=R=0 ç ê log log n ú÷
insert A (AT 0th index) --> increment REAR (REAR =1 ç ê 1 424 3 ú÷
è ëê £1 ûúø
FRONT=0) now if we want to delete A we have FRONT
pointing at that location so we delete A and increment
FRONT (REAR=1 FRONT=1 queue empty) So, this is in Q (log n)
85. (d) Link to activation record of closest lexically enclosing
block in program text. It depends on the static program æ log n ö
text Hence, answer is (c) Q ç log log n ÷
è ø
86. (d) Dijkstra's Algorithm picks nodes as follows:
B(3) from S 89. (b) The return value of the function is q (n2 log n)
A(4) from S
C(5) from A n
The outer for loop goes + 1 iterations.
E(6) from C 2
D(7) from S or B The inner for loop runs independent of the outer
G(8) from E
loop.
T(10) from D or E
Thus the shortest path to T is SBDT, SDT or SACET. n
But because of "the shortest path to a vertex v is updated And for each inner iteration, gets added to k.
2
only when a strictly shorter path to v is discovered",
when E is visited, T's prior node for the shortest path will n
be set as E and not changed again. \ × # outer loops × # inner loops per outer loop.
2
Thus the answer is SACET.
87. (a) The box B1 gets executed when left subtree of n is NULL # Inner loops = q (log n) [Q 2q(log n) = q (n)]
and right sbtree is not NULL. In this case, height of n will
be height of right subtree plus one. n én ù
\ ´ ê + 1ú .q(log n) = q(n2 log n)
The box B2 gets executed when both left and right 2 ë2 û
subtrees of n are not NULL. In this case, height of n will
be max of heights of left and right sbtrees of n plus 1. 90. (d)
Programming & Data Structures S3-87
91. (b) Return value f (p, p) if the value of p is intialized to Take options (b)
5 before the call.
Since, reference of p is passed as 'x' n(n - 1) / 2 (n - 2) / 3
P= ´
Thus, any change in value of x in f would be P1 P2
reflected globally.
P1 will be having no error, thus P will be more accurate
The recursion can be broken down as
Option (c)
5 5
f ( x, c ) n(n - 1) / 3 (n - 2) / 2
P= ´
6 4 P1 P2
x * f ( x, c )
There is possibility of truncation in P1, the accuracy
7 3 of P is less
x * f ( x, c )
8 2
x * f ( x, c ) 10
9 1 7
8
x * f ( x, c ) 95. (a)
92. (c) One-sixth of the product of the 3 consecutive integers. 2 1 5
93. (a) Clearly the code segment: for 3
(i = 0; i < size; i + +) Y = Y + E [i]
Computes the sum of all element in the array E. After insertion of elements,
Note : As the array E may contain negative elements, level - order tansvasal is :
the sum of elements of subarray of E may be greater 10, 8, 7, 3, 2, 1, 5
than the sum of all elements in the array E. 96. (d) When j = 50, j (50), the function goes to an infinite
Now, comes the nested i, j, k loops:
loop by calling f(i) recursively for i = j = 50
‘i’ changes the starting of the subway.
‘j’ changes the end position of the subarray. 97. (a) For the given pseudo code, each element of the
‘k’ loop is used to compute sum of elements of the upper triangle is interchanged by the corresponding
particular subarray. element in lower triangle and later the lower
The sum of subarray is stored in z and is compared to triangular element is interchanged by the upper
the earlier max sum Y. Finally the larger sum gets stored triangular once. Thus the final output matrix will be
in Y. same as that of input matrix A.
i = 0, j = 14
i = 0, j = 2 LINKED ANSWER TYPE MCQs
i = 0, j = 1
98. (d) Create max heap for options.
i = 0, j = 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 9
1
size = 15
i = 2, j = 2 6 3 1
(a) 3 5 6 (b)
i = 2, j = 3 8
i = 2, j = 4
.. Fail Fail
..
i = 2, j = 14 .
This can be easily seen how sum of subarray is
computed with different values of i and j. 9
94. (b) P = nC3 1
6 3 1
n(n - 1)(n - 2)
= (c) 3 5 6 (d) 8
6
If we multiply, n, (n – 1) and (n – 2) together, it may go Fail
beyond the range of unsigned integer. (\ option (a) Fail
and (d) are wrong)
For all values of n, n(n – 1)/2 will always be an integer Here in options (a), (b) and (c), value present at node
value is not greater than all its children. Hence (d) is
But for n(n – 1)/3, it is not certain. correct option.
S3-88 Programming & Data Structures
99. (a) Given heap is as follows 101. (d) Always a greater element is deleted from the binary heap
first. The answer of previous question gave the array as
[25, 14, 16, 13, 10, 12, 8]
So, when the greatest element, i.e., 25 is deleted the array
becomes [14, 16, 13, 10, 12, 8]
And next after second deletion the array becomes [14,
13, 10, 12, 8]
To add 7, 2, 10, 4 we add the node at the end of array Thus, the procedure for the obtaining the final tree is as
follows.
9
Replacing 25 with After heapifying
5 6 8 12 16
3 7 2 4
1 10 14 14 12
16
We keep if at right place in the heap tree.
Compare elements with its parent node. Since 10 > 13 10 8 13 10 8
6 and 7 > 5, we interchange.
Replacing 16 by 8 After heapifying
8 14
14 12 13 12
13 10 8 10
Since 10 > 9, we interchange and we get 102. (c) 12 mod 10 = 2
18 mod 10 = 8
10 13 mod 10 = 3
2 mod 10 = 2 collision
7 9 8 (2 + 1) mod 10 = 3 again collision
3 5 2 4 (using linear probing)
1 6 (3 + 1) mod 10 = 4
3 mod 10 = 3 collision
n / 2 = 10/2 = 5 (3 + 1) mod 10 = 4 again collision
3 is at right position
(using linear probing)
4 is at right position
Order (4 + 1) mod 10 = 5
10 7 9 8 3 1 5 2 6 4 23 mod 10 = 3 collision
Hence (a) is correct option. (3 + 1) mod 10 = 4 collision
100. (c) Suppose that we have a node x, then for the condition 1 (4 + 1) mod 10 = 5 again collision
< = x < = n/2 and A[x] > = A[2x + 1] where 2x and 2x + 1 are (using linear probing)
left child and right child of the node x respectively of a
(5 + 1) mod 10 = 6
binary max-heap.
Thus, under given cases the tree obtained is. 5 mod 10 = 5 collision
(5 + 1) mod 10 = 6 again collision
25 (6 + 1) mod 10 = 7
15 mod 10 = 5 collision
14 (5 + 1) mod 10 = 6 collision
16
(6 + 1) mod 10 = 7 collision
(7 + 1) mod 10 = 8 collision
13 10 8 12 (8 + 1) mod 10 = 9 collision
Programming & Data Structures S3-89
106. (b)
0
1
2 12
3 13
4 2
5 3
6 23
7 5 5 + 4 + 3 = 12
8 18 107. (c) Analyzing the flow in the function. Fix an 'i' in the
9 15 outer loop.
Suppose A[i] = old c[0], then A[i] is set to new c[0]
103. (c) The sequence (A) doesn't create the hash table as the [j = 0].
element 52 appears before 23 in this sequence. Now suppose that old c[1]= new c[0]
The sequence (B) doesn't create the hash table as the
element 33 appears before 46 in this sequence. Þ A[i] = old c[1] (after the j = 0th iteration)
The sequence (C) creates the hash table as 42, 23 and 34 which means in the next iteration with j = 1; A[i]
appear before 52 and 33, and 46 appears before 33. again gets changed form new c[0] (or old c[1]) to
The sequence (D) doesn't create the hash table as the new c[1] which is incorrect.
element 33 appears before 23 in this sequence. The current loop should "break" after a match is
104. (c) In a valid insertion sequence, the elements 42, 23 and 34
found and A[i] is replaced.
must appear before 52 and 33, and 46 must appear before
33. The inner loop should look like
Total number of different sequences = 3! x 5 = 30 for (int j = 0; j < 3, j + +)
In the above expression, 3! is for elements 42, 23 and 34 if (A [i] = = old c[j])
as they can appear in any order, and 5 is for element 46 A[j] = new c [j];
as it can appear at 5 different places.
break;
COMMON DATA MCQs The above flow is exposed by the test cases 3 & 4
105. (d) only. For test 1 and test 2, the expected output is
produced by the code.
Test 3 Expected A after replacements
= "abcde" ® "acdde"
result from code = "abcde" ® "addde"
Test 4 Expected "abcde" ® "bacde"
result form code "abcde" ® "abcde".
\ Answer is 3 and 4 only (c)
108. (b) The FLAWS are identified by a test case of the
following kind.
old c = O1 O2 O3
new c = n1n2n3
æ n1 = O2 ö æ n2 = O3 ö
with ç n ¹ n ÷ or ç n ÷
¹ n3 ø
è 1 2ø è 2
NUMERICAL ANSWER QUESTIONS Total weight = (2 × 10) + (4 × 11) + (8 × 11) + (16 × 10)
= 20 + 44 + 88 + 160
109. (a) Count = 3 = 312
q[1] = 7 q[2] = 3, q[3] = 9 So, label 1, 3, 4 contains coins of 11 gm.
p[7] = 1 p[3] = 2, p[9] = 3 Multiplying these label numbers we get
(b) The first count elements of q contain values (i) such 1 × 3 × 4 = 12.
that set (i) has been called. 113. 9 435Þ 110110011
(c) Suppose p[i] has a value < = 0 or > count, then to num > > 1
set (i) return false. Thus a num is shifted one bit right every time while
Otherwise consider q[p[i]]. Using (b), q[p[i]] contains loop is executed.
a value (i) such that set (i) has been called. Since set While loop is executed 9 times successfully, and 10th
(i) has not been called, q[p[i]] cannot be equal to (i) time num is zero.
and is set (i) returns false. \ Count is incremented 9 times.
110. (a) (1) f[n] ! = 0 114. 6
or
Expression like f(n)3 0 etc. 6
(2) f[n] +
(3) f[n] = t
3 3
(b) O(n) or (n + 1)
–
Alternately +
0 (n3) in the log-cost model.
2 –1 2
111. (a) 7 1
(b) 22210000 1111 + – – +
Arrangements that satisfy one of the following two
constraints are also correct. 1 1 0 1 1 0 1 1
(i) 1’s in the first 4 positions and no 2 in the last 3
positions 115. 1.72 to 1.74
or x 1.5
f(g) + q Þ + =x
1111 010 2 x
22020
all ones no two’s
x2 + 3
(ii) 1’s in the last 3 positions and no zero in the first 4 Þ = x Þ x2 + 3 = 2 x2
2x
positions
Þ x2 = 3 Þ x = 1.73
or
116. 7 P (x) = x5 + 4x3 + 6x + 5
1212 111 = x3 (x2 + 4) + 6x + 5
00020
no zeros all ones Now using only one temporary variable ‘t’
112. 12 (i) t = x * x (Evaluate x2 and store in memory)
No. of Bag = 5 (ii) t = t + 4 (Evaluate (x2 + 4 ) and store in memory)
All coins in a bag have same weight. (iii) t = x2 (Retrieve x2 from memory)
Labels: 1 2 3 4 5 (iv) t = t * x (Evaluate x3 and store in memory)
(v) t = t * (x2 + 4) (Evaluate x3 (x2 + 4) and store in
No. of coins 1 2 4 8 16 memory)
As total weight is 323, the Bag with label 1 must contain (vi) t = 6 * x (Evaluate 6x and store in memory)
coins of 11 gm to make the total odd. (vii) t = t + 5 (Evaluate (6x + 5) and store in memory)
If we remove it the remaining weight = 323 – 11 = 312 gm (viii) t = t + x3 (x2 + 4) (Retrieve x2 (x2 + 4) from memory
Label: 2 3 4 5 and evaluate {x3 (x2 + 4) + 6x + 5}
No. of coins: 2 4 8 16 For the above steps, total number of arithmetic operation
Weights: (I): 10 11 11 10 is 7
i.e., 4 multiplications and 3 additions.
Algorithm Analysis S3-91
4 Algorithm Analysis
Chapter
Algorithm binary search gives a more formal description of this performing the comparison and shifting continues until an element
method. less than or equal to A[i] is found, or when all the sorted sequence
Input : An array A [1..n] of n elements sorted in nondecreasing so far is exhausted.
order and an element x. Input : An array A [1..n] of n elements.
Output : j if x = A [j], 1 £ j £ n, and 0 otherwise. Output : A [1..n] sorted in non-decreasing order.
1. low ¬ 1; high ¬ n; j ¬ 0 1. for i ¬ 2 to n
2. while (low £ high) and (j = 0) 2. x ¬ A[i]
3. mid ¬ [(low + high)/2] 3. j¬i–1
4. if x = A [mid] then j ¬ mid 4. while (j > 0) and (A[j] > x)
5. else if x < A [mid] then high ¬ mid – 1 5. A [j + 1] ¬ A [j]
6. else low ¬ mid + 1 6. j¬j–1
7. end while 7. end while
8. return j 8. A [j + 1] ¬ x
Selection Sort 9. end for
Let A[1..n] be an array of n elements. A simple and straightforward It is easy to see that the number of element comparisons is
algorithm to sort the entries in A works as follows. First, we find minimum when the array is already sorted in nondecreasing order.
the minimum element and store it in A[1]. Next, we find the In this case, the number of element comparisons is exactly n - 1,
minimum of the remaining n -1 elements and store it in A[2]. We as each element A[i], 2 <i <n, is compared with A[i - 1] only. On the
continue this way until the second largest element is stored in other hand, the maximum number of element comparisons occurs
A[n-1]. It is easy to see that the number of element comparisons if the array is already sorted in decreasing order and all elements
performed by the algorithm is exactly are distinct. In this case, the number of element comparisons is as
n -1 n -1
each element A[i], 2 <i <n, is compared with each entry in the
n ( n - 1)
å ( n - i ) = ( n - 1) + ( n - 2) + ... + 1 = å i =
2
. subarray A[1..i-1]. The number of element comparisons performed
i =1 i =1 by Algorithm insertion sort is between n-1 and n(n-1)/2.
Input : An array A [1..n] of n elements. Quicksort
Output : A [1..n] sorted in non-decreasing order. This sorting algorithm has an average running time of Q(n log n).
1. for i ¬ 1 to n – 1 One advantage of this algorithm over Algorithm merge sort is
2. k¬ i that it sorts the elements in place, i.e., it does not need auxiliary
3. for j ¬ i + 1 to n {Find the ith smallest element} storage for the elements to be sorted.
4. if A[j] < A[k] then k ¬ j Partitioning algorithm
5. end for Let A[low..high] be an array of n numbers, and x = A[low]. We
6. if k ¹ i then interchange A[i] and A[k] consider the problem of rearranging the elements in A so that all
elements less than or equal to x precede x which in turn precedes
7. end for
all elements greater than x. After permuting the elements in the
It is also easy to see that the number of element interchanges is
array, x will be A[w] for some w; low £ w £ high. For example, if A
between 0 and n -1. Since each interchange requires three element
assignments, the number of element assignments is between 0 = 5 3 9 2 7 1 8 , and low = 1 and high = 7, then after
and 3(n - 1). The number of element comparisons performed by
Algorithm selection sort is n(n-1)/2. The number of element rearranging the elements we will have 1 3 2 5 7 9 8
assignments is between 0 and 3(n - 1).
Insertion Sort Thus, after the elements have been rearranged, w = 4. The action
This algorithm, which is shown below, works as follows. We begin of rearrangement is also called splitting or partitioning around x,
with the subarray of size 1, A[1], which is already sorted. Next, which is called the pivot or splitting element.
A[2] is inserted before or after A[1] depending on whether it is Input : An array of elements A [low..high].
smaller than A[1] or not. Continuing this way, in the ith iteration, Output : (1) A with its elements rearranged, if necessary, as
A[i] is inserted in its proper position in the sorted subarray A[1::i described above.
-1]. This is done by scanning the elements from index i ¡ 1 down (2) w, the new position of the splitting element A [low].
to 1, each time comparing A[i] with the element at the current 1. i ¬ low
position. In each iteration of the scan, an element is shifted one 2. x ¬ A[low]
position up to a higher index. This process of scanning, 3. for j ¬ low + 1 to high
S3-94 Algorithm Analysis
colorable if and only if it is bipartite, that is, if and only if it does no. If, on the other hand, y is in the proper format,
not contain cycles of odd length. then the algorithm continues to check whether it is a
We say that a class of problems C is closed under solution to the instance x of the problem. If it is indeed
complementation if for any problem P Î C the complement of a solution to the instance x, then it halts and answers
P is also in C. For instance, the complement of the 2-colorable? yes; otherwise it halts and answers no.
Let us call this problem NOT-2-COLOR. We can show that it is in NP-complete Problems
P as follows. Since 2-COLORING is in P, there is a determinsitic The term NP-complete" denotes the subclass of decision
algorithm A which when presented with a 2-colorable graph halts problems in NP that are hardest in the sense that if one of
and answers yes, and when presented with a graph that is not 2- them is proven to be solvable by a polynomial time
colorable halts and answers no. We can simply design a deterministic algorithm, then all problems in NP are solvable
determinsitic algorithm for the problem NOT-2-COLOR by simply by a polynomial time deterministic algorithm, i.e., NP = P.
interchanging the yes and no answers in Algorithm A. This, For proving that a problem is NP-complete, we need the
informally, proves the following fundamental theorem : following definition.
Theorem 10.1 The class P is closed under complementation. • Definition Let P and P¢ be two decision problems.
The Class NP We say that P reduces to P¢ in polynomial time,
The class NP consists of those problems p for which there exists symbolized as P µ poly P¢ , if there exists a
a deterministic algorithm A which, when presented with a claimed
determinsitic algorithm A that behaves as follows.
solution to an instance of p, will be able to verify its correctness
When A is presented with an instance I of problem P,
in polynomial time. That is, if the claimed solution leads to a yes
it transforms it into an instance I¢ of problem P¢ such
answer, there is a way to verify this solution in polynomial time.
that the answer to I is yes if and only if the answer to
In order to define this class less informally, we must first define
I¢ is yes. Moreover, this transformation must be
the concept of a nondeterministic algorithm. On input x, a
achieved in polynomial time.
nondeterministic algorithm consists of two phases
• Definition A decision problem P is said to be NP-
(a) The guessing phase : In this phase, an arbitrary string
hard if for every problem P¢ in NP,
of characters y is generated. It may correspond to a
solution to the input instance or not. In fact, it may P¢ µ poly P .
not even be in the proper format of the desired • Definition A decision problems P is said to be
solution. It may differ from one run to another of the NP-complete if
nondeterministic algorithm. (1) P is in NP, and
(b) The verification phase : In this phase, a deterministic
(2) for every problem P¢ in NP, P¢ µ poly P .
algorithm defines two things. First, it checks whether
the generated solution string y is in the proper format. Thus, the difference between an NP-complete problem P
If it is not, then the algorithm halts with the answer and an NP-hard problem P¢ is that P must be in the class
NP whereas P¢ may not be in NP.
S3-96 Algorithm Analysis
12. An undirected graph G has n nodes. Its adjacency matrix is (a) There must exist a vertex w adjacent to both u and
given by an n × n square matrix whose (i) diagonal elements v in G
are 0’s and (ii) non-diagonal elements are 1’s. Which one of (b) There must exist a vertex w whose removal
the following is true? [2005, 1 Mark] disconnects u and v in G
(a) Graph G has no Minimum Spanning Tree (MST) (c) There must exist a cycle in G containing u and v
(b) Graph G has a unique MST of cost n – 1 (d) There must exist a cycle in G containing u and all its
(c) Graph G has multiple distinct MSTs, each of cost n – 1 neighbours in G
17. Consider an array representation of an n element binary
(d) Graph G has multiple spanning trees of different costs
heap where the elements are stored from index 1 to index
13. Given two arrays of numbers a 1,...an and b1, .... bn where n of the array. For the element stored at index i of the
each number is 0 or 1, the fastest algorithm to find the largest
array (i £ n), the index of the parent is [2001, 1 Mark]
span (i, j) such that ai + ai + 1 + .... + aj = bi + bi + 1 + .... + bj,
or report that there is not such span, [2006, 2 Marks] êiú
(a) Takes O (3n) and W (2n) time if hashing is permitted (a) i – 1 (b) êë 2 úû
(b) Takes O (n 3) and W (n2.5) time in the key comparison
model éiù (i + 1)
(c) êê 2 úú (d)
(c) Take Q (n) time and space 2
18. Randomized quicksort is an extension of quicksort where
(d) ( )
Take O n time only if the sum of the 2n elements is the pivot is chosen randomly. What is the worst case
an even number complexity of sorting n numbers using randomized quick
14. The median of n elements can be found in O(n) time. Which sort? [2001, 1 Mark]
one of the following is correct about the complexity of quick (a) O(n) (b) O(n log n)
sort, in which median is selected as pivot. [2006, 2 Marks] (c) O(n2) (d) O (n!)
(a) q(n) (b) q (n log n) 19. In a heap with n elements with the smallest element at the
root, the 7th smallest element can be found in time
(c) q (n2) (d) q (n3)
[2003, 1 Mark]
15. Consider the following code written in a pass-by-
reference language like FORTRAN and these statements (a) Q (n log n) (b) Q (n)
about the code (c) Q (log n) (d) Q (1)
20. The usual Q (n2) implementation of insertion sort to sort
Subroutine swap (ix, iy) an array uses linear search to identify the position where
it = ix an element is to be inserted into the already sorted part
L1 : ix = iy of the array. If instead, we use binary search to identify
L2 : iy = it the position, the worst case running time will
end [2003, 1 Mark]
ia = 3 (a) remain Q (n ) 2
(b) become Q (n (log n)2)
ib = 8
(c) become Q (n log n) (d) become Q (n)
call swap (ia, ib + 5)
print *, ia, ib 21. The time complexity of computing the transitive closure
end of a binary relation on a set of n element is known to be
[2005, 1 Mark]
S1 : The compiler will generate code to allocate a (a) O(n) (b) O(n log n)
temporary nameless cell, initialize it to 13 and pass (c) O(n3/2) (d) O(n3)
the address of the cell swap 22. Level order traversal of a rooted tree can be done by
S2 : On execution the code will generate a run time error starting from the root and performing [2004, 1 Mark]
on line L1 (a) pre-order traversal
S3 : On execution the code will generate a run time error (b) in-order traversal
on line L2 (c) depth first search
S4 : The program will print 13 and 8 (d) breadth first search
S5 : The program will print 13 and –2
23. An element in ann array X is called a leader, if it is greater
Exactly which of the following sets of statements is / are
than all elements to the right of it in X. The best algorithm to
correct? [2006, 2 Marks]
find all leaders in an array [2007, 2 Marks]
(a) S1 and S2 (b) S1 and S4
(c) S3 (d) S1 and S5 (a) solves it in linear time using a left to right pass of the
16. Let T be a depth first search tree in an undirected graph array
G. Vertices u and v are leaves of this tree T. The degrees (b) solves it in linear time using a right to left pass of the
of both u and v in G are at least 2. Which one of the array
following statements is true? [2006, 2 Marks] (c) solves it using divide and conquer in time q (n log n)
(d) solves it in time q (n2)
S3-98 Algorithm Analysis
24. Consider the following C program fragment in which i, j and (c) The subset sum problem belongs to the class NP
n are integer variables. (d) The subset sum problem is NP-hard
for (i = n, j = 0, i > 0, i/ = 2, j + = i); 33. G is a graph on n vertices and 2n – 2 edges. The edges of G
Let val (j) denotes the value stored in the variable j after can be partitioned into two-edge-disjoint spanning trees.
termination of the for loop. Which one of the following is Which of the following is not true for G? [2008, 2 Marks]
true? [2007, 2 Marks] (a) For every subset of k vertices, the induced subgraph
has at most 2k – 2 edges
(a) val (j) = q (log n) (b) val (j) = q n (b) The minimum cut in G has at least two edges
(c) val (j) = q (n) (d) val (j) = q (n log n) (c) There are two edge-disjoint paths between every pair
25. Which of the following in place sorting algorithms needs of vertices
the minimum number of swaps? [2007, 2 Marks] (d) There are two vertex-disjoint paths between every pair
(a) Quick sort (b) Insertion sort of vertices.
(c) Selection sort (d) Heap sort 34. Consider the following statements about the cyclomatic
complexity of the control flow graph of a program module.
26. To implement Dijkstra’s shortest path algorithm on
Which of these are true? [2009, 2 Marks]
unweighted graphs so that it runs in linear time, the data
I. The cyclomatic complexity of a module is equal to the
structure to be used as [2007, 2 Marks]
maximum number of linearly independent circuits in
(a) queue (b) stack
the graph.
(c) heap (d) B-Tree II. The cyclomatic complexity of a module is the number
27. In a binary max heap containing n numbers, the smallest of decisions in the module plus one, where a decision
element can be found in time [2007, 2 Marks] is effectively any conditional statement in the module.
(a) O (n) (b) O (log n)
III. The cyclomatic complexity can also be used as a
(c) O (log log n) (d) O (1)
number of linearly independent paths that should be
28. Let w be the minimum weight among all edge weights in an
tested during path coverage testing.
undirected connected graph. Let e be a specific edge of
(a) I and II (b) II and III
weight w. Which of the following is false? [2007, 2 Marks]
(c) I and III (d) I, II and III
(a) There is a minimum spanning tree containing e
35. Let pA be a problem that belongs to the class NP. Then,
(b) If e is not in a minimum spanning tree T, then in the which one of the following is true? [2009, 1 Mark]
cycle formed by adding e to T, all edges have the same (a) There is no polynomial time algorithm for pA
weight. (b) If pA can be solved deterministically in polynomial
(c) Every minimum spanning tree has an edge of weight w time, then P = NP
(d) e is present in every minimum spanning tree. (c) If pA is NP-hard, then it is NP-complete
29. In an unweighted, undirected connected graph, the shortest (d) pA may be undecidable
path from a node S to every other node is computed most 36. Which of the following statements is/are correct regarding
efficiently, in terms of time complexity, by [2007, 2 Marks] Bellman-Ford shortest path algorithm?
(a) Dijkstra’s algorithm starting from S P. Always finds a negative weighted cycle, if one exists.
(b) Warshall’s algorithm Q. Finds whether any negative weighted cycle is reachable
(c) Performing a DFS starting from S from the source. [2009, 1 Mark]
(d) Performing a BFS starting from S (a) P only (b) Q only
30. The inorder and preorder traversal of a binary tree are (c) Both P and Q (d) Neither P nor Q
37. What is the number of swaps required to sort n elements
d b e a f c g and a b d e c f g, respectively
using selection sort, in the worst case? [2009, 1 Mark]
The postorder traversal of the binary tree is [2007, 2 Marks]
(a) q (n) (b) q (n log n)
(a) d e b f g c a (b) e d b g f c a (c) q (n2) (d) q (n2 log n)
(c) e d b f g c a (d) d e f g b c a 38. What will be the output of the following C program segment?
31. Which of the following sorting algorithm has the lowest char inChar = ‘A’; [2012, 2 Marks]
worst-case complexity? [2007, 1 Mark] switch (inChar) {
(a) Merge sort (b) Bubble sort case ‘A’ : prinf(“Choice A\n”);
(c) Quick sort (d) Selection sort case ‘B’ :
32. The subset-sum problem is defined as follows: Given a set S case ‘C’ : printf (“Choice B’):
of n positive integers and a positive integer W, determine case ‘D’ :
whether there is a subset of S whose elements sum to W. case ‘E’ :
An algorithm Q solves this problem in O (nW) time. Which default : printf (“No Choice”);}
of the following statements is false? [2008, 2 Marks] (a) No choice
(a) Q solves the subset-sum problem in polynomial time (b) Choice A
when the input is encoded in unary (c) Choice A choice B No choice
(b) Q solves the subset-sum problem in polynomial time (d) Program gives no output as it is erroneous
when the input is encoded in binary
Algorithm Analysis S3-99
50. Consider the following algorithm for searching for a given (a) 29 (b) 31
number x in an unsorted array A [l ...n] having n distinct (c) 38 (d) 41
values
55. The following are the starting and ending times of
1. Choose an i uniformly at random from l ...nf
2. If A [i] = x then stop else Goto 1; activities A, B, C, D, E, F, G and H respectively in
Assuming that x is present A, what is the expected chronological order :
number of comparisons made by the algorithm before it as bs cs ae ds ce es fs be de gs ee fe hs ge he. Here, xs denotes
terminates? [2002, 2 Marks] the starting time and xe denotes the ending time of
(a) n (b) n – 1
activity X. We need to schedule the activities in a set of
n
(c) 2n (d) rooms available to us. An activity can be scheduled in a
2
51. The running time of the following algorithm room only if the room is reserved for the activity for its
Procedure A (n) entire duration. What is the minimum number of rooms
If n < = 2 return (1) else return (A( éê n ùú )); required? [2003, 2 Marks]
(a) 3 (b) 4
is best described by [2002, 2 Marks]
(a) O (n) (b) O (log n) (c) 5 (d) 6
(c) O (log log n) (d) O (1) 56. Let G = (V, E) be a directed graph with n vertices. A path
52. The cube root of a natural number n is defined as the from vi to vj in G is a sequence of vertices (vi, v i + 1,...., vj)
largest natural number m such that m3 £ n. The such that (vk , vk + 1) Î E for all k in i through j – 1. A
complexity of computing the cube root of n (n is simple path is a path in which no vertex appears more
represented in binary notation) is [2003, 2 Marks]
than once. Let A be an n × n array initialized as follows
(a) O(n) but not O(n0.5)
(b) O(n0.5) but not O(log n)k for any constant k > 0 ì1, if ( j, k) ÎE
(c) O (( log n)k) for some constant k > 0 but not O A [ j, k] = í
î0, otherwise
((log log n)m) for any constant m > 0
(d) O (( log log n)k) for some constant K > 0.5 but not Consider the following algorithm :
O ((log log n)0.5) for i = 1 to n
53. Let G = (V, E) be an undirected graph with a subgraph for j = 1to n
G1= (V1, E1). Weights are assigned to edges of G as for k = 1 to n
follows A [j, k] = max (A [j, k], A [j, i ] + A [i, k]) ;
ì0, if e Î E1 Which of the following statements is necessarily true for
w (e ) = í
î1, otherwise all j and k after termination of the above algorithm?
A single – source shortest path algorithm is executed on [2003, 2 Marks]
the weighted graph (V, E, w) with an arbitrary vertex v1 (a) A [j, k] £ n
of V1 as the source. Which of the following can always
be inferred from the path costs computed? (b) If A [j, j] ³ n – 1, then G has a Hamiltonian cycle
[2003, 2 Marks] (c) If there exists a path from j to k, A [j, k] contains the
(a) The number of edges in the shortest paths from v1 longest path length from j to k
to all vertices of G (d) If there exists a path from j to k, every simple path
(b) G1 is connected
from j to k contains at most A [j, k] edges
(c) V1 forms a clique in G
(d) G1 is a tree 57. Let A [1,....., n] be an array storing a bit (1 or 0) at each
54. What is the weight of a minimum spanning tree of the location, and f(m) is a function whose time complexity is
following graph? [2003, 2 Marks] q(m). Consider the following program fragment written in
a C like language :
b 2 g 19 counter = 0;
j
6 for (i = 1; i < = n; i + +)
1 c 3 8
a 2 14 { if (A [i] = = 1) counter + + ;
2 5
15 else {f (counter) ; counter = 0;}
d h
4 }
4
8 9 The complexity of this program fragment is
8 f i
11 [2004, 2 Marks]
2
(a) W (n ) (b) W (n log n) and O(n2)
2
e (c) q (n) (d) O (n)
Algorithm Analysis S3-101
58. The time complexity of the following C function is Which are depth first traversals of the above graph?
(assume n > 0) (a) 1, 2 and 4 (b) 1 and 4
int recursive (int n) { (c) 2, 3 and 4 (d) 1, 3 and 4
if (n = = 1) 64. In the following C function, let n ³ m
return (1) ; int gcd (n, m)
else {
return (recursive (n – 1) + recursive (n – 1); if (n % m == 0) return m;
} [2004, 2 Marks] n = n % m;
(a) O (n) (b) O (n log n) return gcd (m, n);
(c) O (n2) (d) O (2n) }
59. The recurrence equation How many recursive calls are made by this function?
[2007, 2 Marks]
T (1) = 1
(a) Q (log2 n) (b) W (n)
T (n) = 2T (n – 1) + n, n ³ 2
evaluates to
(a) 2n + 1 – n – 2 (b) 2n – n
[2004, 2 Marks] (c) Q (log2 log 2 n) (d) Q ( n)
65. What is the time complexity of the following recursive
(c) 2n + 1– 2n – 2 (d) 2n + n
function?
60. Given the following input (4322, 1334, 1471, 9679, 1989,
int Dosomething (int n) {
6171, 6173, 4199) and the hash function x mod 10. Which it (n < = 2)
of the following statements are true? [2004, 1 Mark] return 1;
(1) 9679, 1989 , 4199 hash to the same value. else
(2) 1471, 6171 hash to the same value. return (Dosomething (floor (sqrt (n))) + n);
(3) All elements hash to the same value } [2007, 2 Marks]
(4) Each element hashes to a different value. (a) Q (n ) 2
(b) Q (n log2 n)
(a) 1 only (b) 2 only
(c) Q (log2 n) (d) Q (log2 log2 n)
(c) 1 and 2 (d) 3 or 4
66. Consider the following graph :
61. The tightest lower bound on the number of comparisons,
in the worst case, for comparison – based sorting is of 2
the order of [2004, 1 Mark]
(a) n (b) n2 b d
1 4
(c) n log n (d) n log n2 1
62. Consider the following three claims : a 3 2 3 f
5
1. (n + k)m = Q (nm), where k and m are constants 6
c 4 e
2. 2n + 1 = O(2n)
3. 22n + 1 = O(2n) 7
Which of these claims are correct? [2003, 1 Mark]
(a) 1 and 2 (b) 1 and 3 Which one of the following cannot be the sequence of
(c) 2 and 3 (d) 1, 2 and 3 edges added, in that order, to a minimum spanning tree
63. Consider the following graph : [2003, 1 Mark] using Kruskal’ algorithm? [2006, 2 Marks]
(a) (a – b), (d – f), (b – f), (d – c), (d – e)
(b) (a – b), (d – f), (d – c), (b – f), (d – e)
a (c) (d – f), (a – b), (d – c), (b – f), (d – e)
(d) (d – f), (a – b), (b – f), (d – e), (d – c)
67. A set X can be represented by an array x [n] as follows
ì1 , if i Î X
x[i] í
b f î0 , otherwise
e
Consider the following algorithm in which x, y and z are
h Boolean arrays of size n :
algorithm zzz (x[], y[], z []) {
int i;
for (i = 0; i < n; + + i )
z [i] = (x[i] ^ ~ y [i] Ú (~ x [i] ^ y [i])
g }
The set Z computed by the algorithm is
[2006, 2 Marks]
Among the following sequences
1. abeghf 2. abfehg
(a) ( X ÈY ) (b) ( X ÇY )
3. abfhge 4. afghbe (c) (X – Y) Ç (Y – X) (d) (X – Y) È (Y – X)
S3-102 Algorithm Analysis
83. We have a binary heap on n elements and wish to insert n 89. Consider the following functions:
more elements (not necessarily one after another) into this f(n) = 2n
heap. The total time required for this is g(n) = n!
[2008, 2 Marks] h(n) = n logn
(a) Q (log n) (b) Q (n) Which of the following statements about the asymptotic
(c) Q (n log n) (d) Q (n2) behaviour of f(n), g(n) and h(n) is true? [2008, 2 Marks]
84. You are given the postorder traversal, P, of a binary search (a) f(n) = O(g(n)); g(n) = O(h(n))
tree on the n elements 1, 2, ..., n. You have to determine the (b) f(n) = W(f(n)); g(n) = O(h(n))
unique binary search tree that has P as its postorder traversal. (c) g(n) = O(f(n)); h(n) = O(f(n))
What is the time complexity of the most efficient algorithm (d) h(n) = O(f(n)); g(n) = W(f(n))
for doing this? [2008, 2 Marks] 90. The Breadth First Search algorithm has been implemented
(a) Q (log n) using the queue data structure. One possible order of visiting
(b) Q (n) the nodes of the following graph is [2008, 1 Mark]
(c) Q (n log n)
(d) None of the above, as the tree cannot be uniquely
determined M N O
–3
b e
2 2
1 –5 1 1
85. a c h f R Q P
2 3 2 3
2 (a) MNOPQR (b) NQMPOR
d g
(c) QMNPRO (d) QMNPOR
91. The most efficient algorithm for finding the number of
Dijkstra’s single source shortest path algorithm when run connected components in an undirected graph on n vertices
from vertex a in the above graph, computers the correct and m edges has time complexity [2008, 1 Mark]
shortest path distance to [2008, 2 Marks] (a) Q (n) (b) Q (m)
(a) only vertex (b) vertices a, e, f, g, h (c) Q (m + n) (d) Q (mn)
(c) vertices a, b, c, d (d) all the vertices 92. In quick sort, for sorting n elements, the (n/4) the smallest
86. Consider the Quick sort algorithm. Suppose there is a element is selected as pivot using an O(n) time algorithm.
procedure for finding a pivot element which splits the list What is the worst case time complexity of the quick sort?
into two sub-lists into two-sub-lists each of which contains [2009, 2 Marks]
at least one-fifth of the elements. Let T(n) be the number of (a) q (n) (b) q (n log n)
comparisons required to sort n elements. Then (c) q (n2) (d) q (n2 log n)
93. Consider the following graph: [2009, 2 Marks]
(a) T ( n ) £ 2T ( n / 5) + n [2008, 2 Marks]
(b) T ( n ) < 2T ( n / 5) + T ( 4n / 5) + n
b 2 e
5
5
(c) T ( n ) £ 2T ( 4n / 5) + n
6 6
(d) T ( n ) £ 2T ( n / 2 ) + n a d 3 g
94. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an 99. What is the time complexity of Bellman-Ford single-
initially empty hash table of length 10 using open addressing source shortest path algorithm on a complete graph of n
vertices? [2013, 1 Mark]
with has function h(k) = k mod 10 and linear probing. What
(a) Q(n2) (b) Q(n2 log n)
is the resultant has table? [2009, 2 Marks] (c) Q(n3) (d) Q(n3 log n)
(a) 0 (b) 0 100. Consider the following operation along the Enqueue and
1 1
Dequeue operations on queues, where k is a global
parameter.
2 2 2 12
Multi-Dequeue(Q){
3 23 3 13 m=k
4 4 while (Q is not empty) and (m > 0){ Dequeue(Q)
5 15 5 5 m=m–1
6 6 }
7 7 }
8 18 8 18
What is the worst case time complexity of a sequence of
n queue operations on an initially empty queue?
9 9
[2013, 2 Marks]
(c) (d) 0 (a) Q(n) (b) Q(n + k)
0
(c) Q(nk) (d) Q(n2)
1 1
101. Consider the following function:
2 12 2 12, 2 int unknown (int n) {
13, 3, int i, j, k=0;
3 13 3
23 for (i=n/2; i<=n; i++)
4 2 4 for (j=2; j<=n; j=j*2)
5 3 5 5, 15 k = k + n/2;
6 return (k);
6 23
7 }
7 5
The return value of the function is
8 18 8 18
[2013, 2 Marks]
9
9 15 (a) Q(n2) (b) Q(n2 log n)
95. The running time of an algorithm is represented by the (c) Q(n3) (d) Q(n3 log n)
following recurrence relation [2009, 2 Marks] 102. An operating system uses the Banker’s algorithm for
deadlock avoidance when managing the allocation of three
ìn , n£3 resource types X, Y, and Z to three processes P0, P1, and
ï
T (n) = í æ n ö P2. The table given below presents the current system state.
ïT ç 3 ÷ + cn, otherwise Here, the Allocation matrix shows the current number of
î è ø
Which one of the following represents the time complexity resources of each type allocated to each process and the
Max matrix shows the maximum number of resources of
of the algorithm?
each type required by each process during its execution.
(a) Q(n) (b) Q(n log n)
(c) Q(n2) (d) Q(n2 log n) Allocation Max
96. Two alternative packages A and B are available for
processing a database having 10 k records. Package A X Y Z X Y Z
requires 0.0001 n2 time units and package B requires 10n P0 0 0 1 8 4 3
log10n time units to process n records. What is the smallest P1 3 2 0 6 2 0
value of k for which package B will be preferred over A? P2 2 1 1 3 3 3
[2010, 1 Mark]
(a) 12 (b) 10 There are 3 units of type X, 2 units of type Y and 2 units of
(c) 6 (d) 5 type Z still available. The system is currently in a safe state.
97. Which one of the following is the tightest upper bound Consider the following independent requests for additional
that represents the number of swaps required to sort n resources in the current state:
numbers using selection sort? [2013, 1 Mark] REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z
(a) O(log n) (b) O(n) REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z
(c) O(n log n) (d) O(n2) Which one of the following is TRUE?
98. Which one of the following is the tightest upper bound [2014, Set-1, 2 Marks]
that represents the time complexity of inserting an object (a) Only REQ1 can be permitted.
into a binary search tree of n nodes? [2013, 1 Mark] (b) Only REQ2 can be permitted.
(a) O(1) (b) O(log n) (c) Both REQ1 and REQ2 can be permitted.
(c) O(n) (d) O(n log n) (d) Neither REQ1 nor REQ2 can be permitted.
Algorithm Analysis S3-105
103. Suppose a polynomial time algorithm is discovered that array as the pivot. Then the tightest upper bound for the
correctly computes the largest clique in a given graph. In worst case performance is [2014, Set-3, 1 Mark]
this scenario, which one of the following represents the (a) O (n2) (b) O (n log n)
correct Venn diagram of the complexity classes P, NP and (c) q (n log n) (d) O (n3)
NP Complete (NPC)? [2014, Set-1, 2 Marks] 107. Consider a hash table with 100 slots. Collisions are resolved
using chaining. Assuming simple uniform hashing, what is
NP the probability that the first 3 slots are unfilled after the first
3 insertions? [2014, Set-3, 2 Marks]
P
(a) (97×97×97)/1003 (b) (99×98×97)/1003
(a) (c) (97×96×95)/1003 (d) (97×96×95)/(3!×1003)
111. What is the minimum possible weight of a path P from vertex 117. What is the average length of the correct answer above
1 to vertex 2 in this graph such that P contains at most 3 question ?
edges? [2010, 2 Marks] [2007, 2 Marks]
(a) 7 (b) 8 (a) 3 (b) 2. 1875
(c) 9 (d) 10 (c) 2.25 (d) 1.9375
Statements for Linked Answer Questions 112 and 113 Statements for Linked Answer Questions 118 and 119
The subset - sum problem is defined as follows : Given a set Consider the following C function :
of n positive integers, S = {a1, a2, a3, ...an}, and positive double foo (int n) {
integer W, is there a subset of S whose elements sum to W? int i ;
A dynamic program for solving this problem uses a 2- double sum;
dimensional Boolean array, X, with n rows and W + 1 if (n = = 0) return 1 .0;
columns. X[i, j], 1 £ i £ n,0 £ j £ W, is true if and only if there else {
is a subset of {a1, a2, ....ai} whose elements sum to j sum = 0.0;
112. Which of the following is valid for 2 £ i £ n and for (i = 0; i < n; i + +)
ai £ j £ W? [2008, 2 Marks] sum + = foo (i) :
(a) X [i, j] = X [i – 1, j] Ú X[i, j – ai] return sum;
(b) X [i, j] = X [i – 1, j] Ú X[i – 1, j – ai] }}
(c) X [i, j] = X [i – 1, j] Ù X[i, j – ai] 118. The space complexity of the above function is
(d) X [i, j] = X [i – 1, j] Ù X[i – 1, j – ai] [2005, 2 Marks]
113. Which entry of the array X, if true, implies that there is (a) O (1) (b) O (n)
a subset whose elements sum to W? [2008, 2 Marks] (c) O (n!) (d) O (nn)
(a) X[1, W] (b) X[n, 0] 119. Suppose we modify the above function foo () and store
(c) X[n, W] (d) X[n –1, n] the values of foo (i), 0 < = i < n, as and when they are
Statements for linked Answer Questions 114 and 115
computed. With this modification, the time complexity for
Consider the following C program that attempts to locate
function foo () is significantly reduced. The space
an element X in an array Y [] using binary search. The
complexity of the modified function would be
program is erroneous.
1. f (int Y[10], int X) { [2005, 2 Marks]
2. int u, j, k; (a) O (1) (b) O (n)
3. i = 0; j = 9; (c) O (n2) (d) O (n!)
4. do { Statements for Linked Answer Questions 120 and 121
5. k = (i + j) / 2 We are given 9 tasks T1, T2, ....T9. The execution of each
6. if (Y[k] < x) i = k; else j = k; task requires one unit of time. We can execute one task
7. } while ((Y[k]! = X) & &(i < j)); at a time. Each task Ti has a profit Pi and deadline di.
8. if (Y[k]) = = x) print f (“x is in the array”); Profit Pi is earned if the task is completed before the end
9. else print f (“x is not in the array”); of the di th unit of time.
10. }
114. On which of the following contents of Y and x does the Task T1 T2 T3 T4 T5 T6 T7 T8 T9
program fail? [2008, 2 Marks] Profit 15 20 30 18 18 10 23 16 25
(a) Y is [1 2 3 4 5 6 7 8 9 10 ] and x < 10 Deadline 7 2 5 3 4 5 2 7 3
(b) Y is [1 3 5 7 9 11 13 15 17 19] and x < 1
(c) Y is [2 2 2 2 2 2 2 2 2 2] and x > 2 120. Are all tasks completed in the schedule that gives
(d) Y is [2 4 6 8 10 12 14 16 18 20] and 2 < x < 20 and maximum profit? [2005, 2 Marks]
x is even (a) All tasks are completed
115. The correction needed in the program to make it work (b) T1 and T6 are left out
properly is [2008, 2 Marks] (c) T1 and T8 are left out
(a) change line 6 to ; if (Y [k] < x) i = k + 1; (d) T4 and T6 are left out
else j = k – 1; 121. What is the maximum profit earned? [2005, 2 Marks]
(b) change line 6 to ; if (Y [k] < x) i = k – 1; (a) 147 (b) 165
else j = k + 1; (c) 167 (d) 175
(c) change line 6 to ; if (Y [k] < = x) i = k; else j = k; Statements for Linked Answer Questions 122 and 123
(d) change line 7 to ; }while ((Y [k] = = x) & &(i < j)) In a permutation a1 .... an of n distinct integers, an inversion is
Statements for Linked Answer Questions 116 and 117 a pair (ai , aj) such that i < i and ai > aj.
Suppose the letters a, b, c, d, e, f have probabilities
122. If all permutations are equally likely, what is the expected
1 1 1 1 1 1 number of inversions in a randomly chosen permutation
, , , , , respectively..
2 4 8 16 32 32 of 1 ... n? [2003, 2 Marks]
116. Which of the following is the Huffman code for the letter n ( n - 1) n ( n - 1)
a, b, c, d, e, f ? [2007, 2 Marks] (a) (b)
(a) 0, 10, 110 , 1110, 11110, 11111 2 4
(b) 11, 10, 011, 010, 001, 000 n ( n + 1)
(c) 11, 10, 01, 001, 0001, 0000 (c) (d) 2n [log 2 n]
(d) 110, 100, 010, 000, 001, 111 4
Algorithm Analysis S3-107
123. What would be the worst case time complexity of the of keys in increasing order. Then what approximately
insertion sort algorithm, if the inputs are restricted to is the average number of keys in each leaf level node.
permutations of 1... n with at most n inversions? (i) In the normal case, and
[2003, 2 Marks] (ii) with the insertion as in (b). [2000, 5 Marks]
(a) Q (n2) (b) Q (n log n) 127. Consider a rooted n node binary tree represented using
(c) Q (n1.5) (d) Q (n) pointers. The best upper bound on the time required to
Statements for Linked Answer Questions 124 and 125: determine the number of subtrees having exactly 4 nodes is
A sub-sequence of a given sequence is just the given sequence O (nalogbn). Then the value of a + 10b is ______.
with some elements (possibly none or all) left out. We are given [2014, Set-1, 1 Mark]
two sequence X[m] and Y[n] of lengths m and n, respectively, 128. Consider an undirected graph G where self-loops are not
with indices of X and Y starting from 0. allowed. The vertex set of G is {(i, j): 1 £ i £ 12, 1 £ j £ 12}.
124. We wish to find the length of the Longest Common Sub- There is an edge between (a, b) and (c, d) if |a – c| £ 1 and
sequence (LCS) of X[m] and Y[n] as l(m, n), where an |b – d| £ 1. The number of edges in this graph is _________.
incomplete recursive definition for the function l (i, j) to [2014, Set-1, 2 Marks]
compute the length of the LCS of X[m] and Y[m] is given 129. Consider the expression tree shown. Each leaf represents a
below numerical value, which can either be 0 or 1. Over all possible
l(i, j) = 0 either i = 0 or j = 0 choices of the values at the leaves, the maximum possible
= expr 1, if i, j > 0 and X[i – 1] = [j – 1] value of the expression represented by the tree is ___.
= expr 2, if i, j > 0 and X[i – 1] = Y[j – 1]
Which one of the following options is correct?
(a) expr 1 º l (i – 1, j) + 1 [2009, 2 Marks]
(b) expr 1 º l (i, j – 1)
(c) expr 2 º max {(l (i –1, j) , l (i, j – 1)}
(d) expr 2 º max {(l (i –1, j – 1) , l (i, j)}
125. The values of (i, j) could be obtained by dynamic programming
based on the correct recursive definition of l (i, j) of the form
given above, using an array L [M, N], where M = m + 1 and
N = n + 1, such that L [i, j] = l (i, j).
Which one of the following statements would be true 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
regarding the dynamic programming solution for the
recursive definition of (i, j)? [2009, 2 Marks] [2014, Set-2, 2 Marks]
(a) All element L should be initialized to 0 for the values 130. The number of distinct minimum spanning trees for the
of (i, j) to be properly computed weighted graph below is _____ [2014, Set-2, 2 Marks]
(b) the values of l (i, j) may be computed in a row major
order or column major order of L(M, N)
2
(c) the values of l (i, j) may be computed in a either row
major order or column major order of L (M, N)
2 1 2 1
(d) L[p, q] needs to be computed before L[r, s] if either
p < r or q < s
2 2
Numerical Answer Questions 1
2
126. (a) Suppose you are given an empty B+-tree where 1 1
each node (leaf and internal) can store up to 5 key
values. Suppose values 1, 2, ... 10 are inserted, in 2 2
order, into the tree, show the tree pictorially
(i) After 6 insertions, and 131. The length of the shortest string NOT in the language (over
(ii) After all 10 insertions S= {a, b}) of the following regular expression is
Do NOT show intermediate stages. ______________. [2014, Set-3, 1 Mark]
(b) Suppose instead of splitting a node when it is full, a*b* (ba)*a*
we try to move a value to the left sibling. If there 132. Suppose we have a balanced binary search tree T holding n
is no left sibling, or the left sibling is full, we split numbers. We are given two numbers L and H and wish to
the node. Show the tree after values, 1, 2, ..., 9 have sum up all the numbers in T that lie between L and H. Suppose
been inserted. Assume, as in (a) that each node can there are m such numbers in T. If the tightest upper bound on
hold up to 5 keys. the time to compute the sum is O (na logb n + mc logd n), the
(c) In general, suppose a B+-tree node can hold a value of 10b + 100c + 1000d is _______.
maximum of m keys, and you insert a long sequence [2014, Set-3, 2 Marks]
S3-108 Algorithm Analysis
13. (c) Given that each number of 0 or 1. it with the last element, then we run min heapify
Now, to achieve algorithm, which brings next the smallest element on
ai + ai + 1 + ... + aj = bi + bi + 1 + ... + bj top. This procedure take 0(log n) time.
We need to find the sum total of LHS and RHS and We need to run it for 7 times. So tight bound
then have to compare. Q (7 log n) = Q(log n)
We need to do this from very starting like first we need Hence option (c) is correct.
to check. 20. (a) Binary search is efficient when the sorted sequence
Whether a1 = b1 is there, but the worst case scenario for insertion
If not then whether a1 + a2 = b1 + b2 sort would not be sorted sequence so even using
And so on .... binary search instead of linear search the complexity
This will take n comparisons. of comparisons will remain Q ().
Therfore, the fastest algorithm to find the largest span 21. (d) Warshall’s algorithm might be used for calculation
takes Q (n) time and space. transitive closure of a set with a elements. This
14. (c) In quick sort the piuot is found in logn time & this runs algorithm has complexity O( ). In transitive closure
for n times. So complexity of Quick sort is 0(nlogn) but two binary relations are there 4 both ranges are the
same set.
since given the median as piuot found in 0(n)
The require three for loops so 0( ).
So for n elements to sort this algorithm will take 0(n2) Hence (d) is correct option.
15. (b) S1 : Yes the compiler will generate a temporary 22. (d) Level order traversal is done by traversing all the
nameless cell & initialize it to 13 and pass to vertices in a particular level & them moving to next
swap. level.This is some as breadth first search where level
S2 : No error by level search is done. Hence (d) is correct option.
S3 : No error 23. (c) In quick sort (divide & conquer) algorithm after every
S4 : Program will print 13 and 8
run we being 1 element at its right place i.e. all the
S5 : False.
Hence (b) is correct option. elements in the left are smaller & in the right are greater
16. (a) Let the graph G be. than it.
So we can apply quick sorts divide & conquer method
of complexity 0(nlogn) to do this, to check whether all
elements in right are smaller than it or not.
24. (c) Here after every iteration the value of i=i/2, & j is the
summation of these i till i reaches to 1.
n
j = n + n / 2 + n / 2 2......n / 2 log 2
(a) is correct since W is the common vertex.
(b) W is removed but u & v are not dis-connected. Sum of this series.
(c) No cycle containing u & v exist. Would give ø(n) order.
(d) Not necessary the graph can be also. 25. (a) Heap is implemented using array & to find maximum or
a minimum element in array we take only n maximum
comparison.
w So complexity is ø(n)
26. (c) Heap is used to implement Dijakstra’s shortest path
u algorithm on unweighted graphs so that it runs on
v
linear time because of the property of heap discussed
17. (b) This is a basic question. We know that to reach a below.
node on level i, the distance to the root is i–1. This Heap is a data structures that allows the following:
implies that if an element is stored at index i of the 1. Add: Heap allows the addition of an element with some
array, then index of the parent is n. priority associated with each element.
18. (b) n randomized quicksort pivot is chosen randomly, 2. Remove: The element with the highest priority is
the case complexity of sorting n. In that case the removed and returned.
worst case O(n2) of quicksort become O(n log n) of 3. Peak : Heap increases the priority of an element to the
randomize quicksort. highest without removing the element from the list.
Hence (b) is correct option. Now, to implement a heap, take a list of elements and
19. (c) Here we can follow simple procedure, we can run according to the priority. The highest priority is O(n)
heap sort for 7 iterations. In each iteration the top time to implement the Dijakstra’s shortest path
most element is the smallest, we note & then replace algorithm on unweighted graphs.
S3-110 Algorithm Analysis
27. (a) Time taken by binary max heap to identify the max 33. (d) Consider this graph with n = 4
element is O(1). Therefore, the time taken by binary
max heap to identify the smallest element is O(n).
28. (d) Minimum weight w
Edge e
Weight w
Now, w is the minimum weight among the edges.
There is a possibility that two edges may contain the
same weight w. This would then be added to minimum
spanning tree. Two spanning trees
Now, when the edge, e is added to the minimum tree
we get a circuit.
Therefore, to avoid the circuit, e cannot be included in
the minimum spanning tree.
29. (d) Since the graph is unweighted and undirected so no
sense in using Dijikstra or Warshall also their
complexities are 0(n2) &0(n3)respectively.
Statement (b), (c) & (d) are correct.
BFS starting from S, traverses all the adjacent nodes,
& then their adjacent nodes, this calculates shortest
path with min complexity. Hence (d) is correct option.
30. (a) In order d b e a f c g
preorder a b d e c f g
1st element of pre order is root
41. (a) The in order transversal is as : So, the maximum possible height would be the range
left, root, middle, right and therefore, is log1n.
\ Nodes are visited in SQPTRWUV order. 49. (d) Consider following rooted trees
42. (b) 2 SAT is in P. This we can prove by reducing 2 SAT a
to directed graph reachability problem which is
known to be in P.
Procedure for reducing 2 SAT to reachability problem : b c d
1. Let j be CNF with clauses of length 2 and let P be
the set of propositional variable (literals) in j e f g
2. Build a graph G = (V, E) with V = P È {Øplp Î P}
n=4
and (x, y) Î Eiff there is a clause in j that is (2n + 1)/3 = 3
equivalent to x ® y (all the clauses are converted No. of leaf nodes = 3
to equivalent implications and the graph built is Hence (d) is correct option.
called as implication graph) 50. (a) Given array A[1.....n], an element A[i] is chosen
3. Observe that j is unsatisfiable iff there is a p Î P randomly from 1 to n.
such that there is both a path from p to Ø p and This would require n selections & comparisons to
from Ø p to p in G.. find x in array.
This condition can be tested by running the Hence (a) is correct option.
reachability algorithm several times. 51. (b) This is a recursive procedure. Which always calls
PROBLEM BASED MCQs itself by value n
So the recursion gas till n >2.
43. (a) t(n) is 0 (1) ® this is called constant growth. t(n) Let n = 256
does not grow at all as a function of n as it is a Rec 1 n = 256
constant. For example, Array access has this 2 n = 16
characteristics. A[i] takes the same time independent 3 n = 4 recursion = 4
of the array A. 4n=2
44. (a) Since f(n) is polynomially greater than g(n) log2 256 = 8
So f(n) = 0(g(n)) Hence (b) is correct option.
But g(n) ¹ 0(f(n)) 52. (c) n is represented in binary let W suppose using K bit.
Hence (a) is correct option. To calculate its cube root the time taken is 0(log n)k
45. (b) Total no. of nodes = n but it can't be
For an edge of n nodes we select any 2 which make 0(log n)m
a graph. Since K < m, K > 0, m > 0.
So nc2 ® n(n – 1)/2 edges m is the cube root, since we are doing in binary so
n = 4 ; ( 4 ´ 3)/2 = 6 we take K.
46. (d) Worst case of searching occurs when the element to Hence (c) is correct option.
be searched is at the end of the list so no. of 53. (b) Since, G = (V, E) is an undirected graph, then C 1 will
comparisons required to search complete list would be connected as for the computed path costs. This
be n. Hence (d) is correct option. can be clearly explained from the example
47. (d) Here, we need to find the number of undirected Graph 1
graphs to be constructed
Now, S = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 ... n – 1
= n (n – 1)/2 ® constructed graphs
= 2S
n ( n –1)
= 2 2
48. (a) Since, it is given that the number of nodes in the left
sub tree is at least half of the girht_subtree.
Weight of edge be 1.
® A to B will cost only 1 neglecting the weight of
other edges
Graph 2
E1
Number of nodes in the at most twice of the right A B
subtree.
E5 E2
D C
E3
Algorithm Analysis S3-113
10
8 5
77. (b)
W(1) <= T(n) <= 0(n)
One possible way to do this is we select first element
1 6
3 +1
( C3 )
as max & also min. Then we compare it with all others. 1.6!
=5
At most this would take 2n comparisons during linear 4 ´ 3!3!
search. But if we use divide & conquer as for merge Therefore, there are 5 trees that can be formed with
three unlabelled node.
sort we have.
S3-116 Algorithm Analysis
1
2
Order a be f c h g d
a ® b= 1 ac= 3 ab= 6 ®
3 ae = ® 2 af= 0 a ® g = 3
4
ah ® = 2
82. (c) This is a formula to calculate the total number of nodes. Since there is no - ve cycle so Dijkstra gives correct
It is 2h + 1 – 1.
result for all vertices.
Let consider some examples to prove this.
1. Simplest could be taking the binary tree of h (height) 86. (b) Pivot element is found in Quick sort in every iteration
= 0. all the elements to its left are smaller than & all in the
Now, the binary tree of height h will have only 1 node. right are greater than it. So if 1/5th of sorted sequence
is the pivot. So sequence is divided into 1/5th & 4/5th
Using formula 2 ^ (0 + 1) – 1 = 1. Hence, the formula is of the sequence. So recursion will be
correct. T(n) = T(n/5) + T(4n/5) + n
2. Binary tree of h (height) = 2
87. (a) In B tree the data is stored at leaves only a particular
1 node can have maximum. 3 keys, so when 4th insertion
comes first split is required, during 7th second split &
3 so on, so for 10 insertions max. 3 splits are required.
2
We can prove it mathematically.
7 No. of split < = 1 + logm/2[n/2]
4 5 6 Here m order = 4 n = 10 b = 3
Using formula 2 ^ (2 + 1) – 1 = 7. Hence, the formula is K <= 1+ log2 [10/3] = 1 + log 2[4]
correct. K<= B
83. (b) Heaps are implemented as simple arrays, to insert n
88. (b) Since all the elements are sorted so we can apply
more elements each element take Q(1) time. So total
binary search here efficiently. In BS the size of array
time would be Q(n).
required to compare reduces by n/2 in every iteration.
84. (b) To construct a BST from post order we also require
Here since the sequence is sorted so the same element
in-order traversal since given the elements are 1 2.......n
would come Consecutive.
So their sorted order would be in order. Using both 89. (d) Since
BST can be constructed in a linear scan. So it will take f(n) = 2n
only 4n time. g(n) = n!
h(n) = n logn
85. (d) We apply Dijkstra Algorithm. It can also be shown as
f(n) = O (2n)
Algorithm Analysis S3-117
R Q P
Let start form Q
® Q comes in queue first (b)
Changing the status of the Q’s child to 1
Queue obtained, Q | M | N | P
Changing the status of the M’s child to 1
Queue obtained, Q | M | N | P | R
Changing the status of the N’s child to 1
Queue obtained Q | M | N | P | R | O
The queue’s final status is as per the table below
Q M N O P R
2 1 1 1 1 (c)
2 2 1 1 1
2 2 2 1 1 1
M N O
(d)
R Q P
(5, 6), (6, 4), (6, 5) and (6, 6) and (1, 12) is connected only
to (1, 11), (2, 11) and (2, 12). 129. 6
So, different vertices are connected to different number of
vertices. However we can visualize this easily using 6
following diagram:– +
3 3
–
+
1 2 3 4 5 6 7 8 9 10 11 12 2 –1 2
1
1 + – – +
2
1 1 0 1 1 0 1 1
3
130. 6
4
5 a 2
6 2 1 2 1
7 b c
8 2 2
9 A 1 1 2 1
10 B d e
11 2
2
12 Edges picked to make MST is given the double line.
In the right side of MST, we could either pick ‘d’ or ‘e’
In the left side we could either pick ‘a’, ‘b’ or ‘c’ in MST.
There are two options for one edge to be picked and three
Each cell of the table represents corresponding vertex option for other edge to be picked.
of the graph. For example the cell ‘A’ represents vertex \ Total possible MSTs = 2 × 3 = 6
(9, 0) of the graph, similarly ‘B’ represents vertex (10, 131. 3
2) of the graph. a * b * (ba) * a *
Now, we easily see that there are three kind of vertices Length 0 is present (as it accepts Î)
in the graph (or table): Length 1 is present (a, b)
(i) Corner vertices which are connected to ‘3’ neighbours. Length 2 is present (aa, ab, ba, bb)
Length 3 is not present (bab not present)
No. of such vertices = 4
\ it is 3
Total no. of edges for such vertices = 4 × 3 = 12
132. 110
(ii) Vertices in first/ last row of first/last column except It takes (log n) time to determine numbers n1 and n2 in
corner vertices, which are connected to ‘5’ neighbours balanced binary search tree T such that
each. 1. n1 is the smallest number greater than or equal to
No. of such vertices = 40 L and there is no predecessor n¢1 of n1 such that n¢1
Total no. of edges for such vertices = 40 × 5 = 200 is equal to n1.
(iii) Internal cells (vertices) that are connected to ‘8’ 2. n2 is the largest number less than or equal to H and
neighbours each. there is no successor of n¢2 of n2 such that is equal
No. of such vertices = 100 to n2.
Total no. of edges for these vertices = 100 × 8 = 800 Since thee are m elements between n 1 and n 2, it takes ‘m’
Edge total of all above cases = 12 + 200 + 800 = 1012 time to add elements between n1 and n2.
So time complexity is O (log n + m)
However in above calculation each edge is counted
So the given expression becomes O (n 0log¢ n + m¢ log0 n)
twice, so, finally total no. of edges in the graph =
And a + 10b + 100c + 1000d = 0 + 10 × 1 + 100 × 1 + 1000 × 1
1012 = 10 + 100 = 110
= 506. Because a = 0, b = 1, c = 1 and d = 0
2
Theory of Computation S3-123
5 Theory of Computation
Chapter
1. Concatenation
Let string x of length a and string y of length b, the q1 e q2
concatenation of x and y, written as xy, is the string
obtained by appending y to the end of x, as in x1 x2, Formally, a non-deterministic finite automation is a 5-tuple (Q,
........ xa y1 y2, ...... yb. and the length of concatenated å, d, q0, F), where
string will be a + b. 1. Q is a non-empty finite set of states.
• å being English alphabet, Hello. John = Hello John. 2. å is a non-empty finite alphabet.
The concatenation of string x for n times, where n 3. d: Q × åe ® P(Q) is the transition function. Also, Q ×
³ 0 is denoted by xn. å Þ 2Q.
• x0 = e, x1 = x, x2 = xx, ............. 4. q0 Î Q is the start state.
2. Substring 5. F Í Q is the set of accept states.
Let x and y be strings over an alphabet å. The string For example, NFA drawn below can be formally written as:–
x is called substring of y if there exist strings m and n 1. Q = {q1, q2, q3, q4}
over å such that y = mxn, m and n can be empty strings. 2. å = {0, 1}
e is a substring of every string and for every string x, 3. d is given as
x is a substring of x itself.
• e, concat, nation and concatenation are substring 0 1 e
of concatenation. q1 { q1} { q1, q 2 } f
3. Reverse q2 { q3 } f { 3}
q
The reverse of string x, written as xr is the string obtained
by writing x in the opposite order.
q3 f {q 4 } f
1
E
b b a
Step of type (iv): (a/b)* e
E
a 2 3
a, b
a To construct a DFA(D) that is equivalent to N, we first need
E
to determine D’s states. Since N is having 3 states, D’s states
E will be 23 = 8. Now label each of D’s state with the subset of
N’s state. Thus D’s state set is
E {f, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
b
The start state of D is the state that are reachable from 1 by
travelling along e arrows. An e arrow goes from 1 to 3, so start
E state is {1, 3}. Accept states of D are the states containing N’s
Step of type (iii): (a/b)*a accept state, i.e. {{1}, {1, 2}, {1, 3}, {1, 2, 3}}. Now, we determine
E D’s transition function. In D, state {2} goes to {2, 3} on input
a, because in N, state Z goes to both 2 and 3 on input a and
we can’t go farther from 2 or 3 along e arrows. State {2} goes
a
E to {3} on input b. Similarly, state {1} goes to f on input a,
a E E because no a arrows exit it in N. Continuing in this way, we
obtain the diagram of D.
E
The above DFA can be simplified by removing the unwanted
b states. In this case, they are {1} and {1, 2} because there are
no arrows pointing at these states and also none of them are
start state and hence they can’t be reached. So, the simplified
E DFA will be
Figure 1 : Steps in constructing an NFAE for (a|b)*a
a b
a, b f {1} {2} {1, 2}
b b b
b (a) a,
a
a
a
{3} {1, 3} a {2, 3} {1, 2, 3}
b b
Diagram of D
Theory of Computation S3-125
Input 0 1 e 1 0 1 0 1 1 1 0 U U U ........
14. Let L1 be a recursive language, and let L2 be a recursively (a) L1 Ç L2 is a deterministic CFL
enumerable but not a recursive language. Which one of the (b) L2 Ç L1 is recursive
(c) L1 Ç L2 is context-free
following is true? [2005, 2 Marks]
(d) L1 Ç L2 Ç L3 is recursively enumerable
(a) L1 is recursive and L2 is recursively enumerable 20. Consider the following statements about the context-free
grammar: [2006, 2 Marks]
(b) L1 is recursive and L2 is not recursively enumerable G = {S ® SS, S ® ab, S ® ba, S ® Î}
1. G is ambiguous.
(c) L1 and L2 are recursively enumerable 2. G produces all strings with equal number of a’s and b’s.
3. G can be accepted by a deterministic PDA.
(d) L1 is recursive enumerable and L2 is recursive Which combination below expresses all the true statements
about G?
15. Consider the languages [2002, 2 Marks] (a) 1 only (b) 1 and 3
(c) 2 and 3 (d) 1, 2 and 3
{ } {
L1 = a n b n c m | n, m > 0 and L2 = a n b m cm | n, m > 0 } 21. Let SHAM3 be the problem of finding a Hamiltonian cycle in
a graph G = (V, E) with |V| divisible by 3 and DHAM3 be the
Which one of the following statements is false? problem of determining if a Hamiltonian cycle exists in such
(a) L1 Ç L2 is a context-free language graphs. Which one of the following is true? [2006, 2 Marks]
(a) Both DHAM3 and SHAM3 are NP-hard
(b) L1 È L2is a context-free language
(b) SHAM3 are NP-hard but DHAM3 is not
(c) L1 and L2 are context-free language (c) DHAM3 is NP-hard, and SHAM3 is not
(d) L1 Ç L2 is a context-sensitive language (d) Neither DHAM3 nor SHAM3 is NP-hard
16. Let Nf and Np denote the classes of languages accepted by 22. Let S be an NP-complete problem and Q and R be two other
non-deterministic finite automata and non-deterministic push- problems not known to be in NP. Q is polynomial time
down automata, respectively. Let Df and Dp denote the reducible to S and S is polynomial time reducible to R. Which
classes of languages accepted by deterministic finite one of the following statements is true? [2006, 1 Mark]
automata and deterministic push-down automata (a) R is NP-complete (b) R is NP-hard
respectively. Which one of the following is true? (c) Q is NP-complete (d) Q is NP-hard
[2005, 2 Marks] 23. The language L = {0 21 | i ³ 0} over the alphabet {0, 1, 2} is
i i
a
(a) Every subset of a regular set is regular
a
(b) Every finite subset of a non-regular set is regular
a, b (c) The union of two non-regular sets is regular
The language recognized by M is (d) Infinite union of finite sets is regular
(a) {W Î (a, b)* | every a in W is followed by exactly two 25. Which of the following problems is undecidable?
b’s}
(b) {W Î (a, b)* | every a in W is followed by at least two (a) Membership problem for CFGs [2007, 1 Mark]
b’s} (b) Ambiguity problem for CFGs
(c) {W Î (a, b)* | W contains the substring abb} (c) Finiteness problem for FSAs
(d) {W Î (a, b)* | W does not contain aa as a substring}
(d) Equivalent problem for FSAs
18. Consider three decision problems P1, P2 and P3. It is known
that P1 is decidable and P2 is undecidable. Which one of the 26. Which of the following are regular sets? [2008, 2 Marks]
following is true?
(a) P3 is decidable if P1 is reducible to P3
[2005, 2 Marks]
1. {a n b2m | n ³ 0, m ³ 0}
(b) P3 is undecidable if P3 is reducible to P2
(c) P3 is undecidable if P2 is reducible to P3
2. {a n bm | n = 2m}
(d) P3 is decidable if P3 is reducible to P2’s complement
19. Let L1 be a regular language, L2 be a deterministic context-
3. {a n bm | n ¹ m}
free language and L3 a recursively enumerable but not 4. {xcy | x, y,Î {a, b} *}
recursive language. Which one of the following statements (a) 1 and 4 (b) 1 and 3
is false? [2006, 1 Mark] (c) 1 only (d) 4 only
S3-130 Theory of Computation
27. Match the List I with List II and select the correct answer (a) 1 and 2 (b) 1 and 4
using the codes given below the lists. [2008, 2 Marks] (c) 2 and 3 (d) 2 and 4
32. Which of the following is true for the language {ap | p is a
List I List II prime}? [2008, 1 Mark]
E. Checking that P. L = {anbmcndm |m ³ 1, m, ³ 1|} (a) It is not accepted by a turning machine
identifiers are (b) It is regular but not context-free
declared before their (c) It is context-free but not regular
F. Number of formal Q. X ® XbX | XcX | dxf | g (d) It is neither regular nor context-free, but accepted by a
parameters in the turing machine
declaration of a 33. Let L1 = L1 Ç L 2 , where L1 and L2 are languages as defined
function agrees with
below
the number of actual
parameters in use of
that function
{ }
L1 = a m b m c a n b n | m, n ³ 0
L 2 = {a i b jck | i, j, k ³ 0}
G. Arithmetic R. L = {WcW | W Î (a | b)*}
expressions with
matched pairs of Then L is [2009, 2 Marks]
parentheses (a) not recursive
H. Palindromes S. X ® bXb |cXc| e (b) regular
(a) E - P, F - R, G - Q, H - S (c) context-free but not regular
(b) E - R, F - P, G - S, H - Q (d) recursively enumerable but not context-free
(c) E - R, F - P, G - Q, H - S 34. Match all items in List I with correct options from those
(d) E - P, F - R, G - S, H - Q given in List II [2009, 1 Mark]
28. Which of the following statements are true? [2008, 2 Marks]
1. Every left-recursive grammar can be converted to a List I List II
right-recursive grammar and vice-versa. P. Regular expression 1. Syntax analysis
2. All e-productions can be removed from any context- Q. Push-down automata 2. Code generation
free grammar by suitable transformations.
R. Dataflow analysis 3. Lexical analysis
3. The language generated by a context-free grammar all
of whose productions are of the form X ® W or X ® S. Register a llocation 4. Code optimization
WY (where, W is a string of terminals and Y is non-
(a) P - 4, Q - 1, R - 2, S - 3 (b) P - 3, Q - 1, R - 4, S - 2
terminal), is always regular.
(c) P - 3, Q - 4, R - 1, S - 2 (d) P - 2, Q - 1, R - 4, S - 3
4. The derivation trees of strings generated by a context-
35. Which one of the following is false? [2009, 1 Mark]
free grammar in Chomsky Normal Form are always
(a) There is unique minimal DFA for every regular
binary trees.
language
(a) 1, 2, 3 and 4 (b) 2, 3 and 4
(c) 1, 3 and 4 (d) 1, 2 and 4 (b) Every NFA can be converted to an equivalent PDA
29. Which of the following statements is false? [2008, 2 Marks] (c) Complement of every context-free language is recursive
(a) Every NFA can be converted to an equivalent DFA (d) Every non-deterministic PDA can be converted to an
(b) Every non-deterministic turing machine can be equivalent deterministic PDA
converted to an equivalent deterministic turing 36. S ® aSa |bSb| a | b; The language generated by the above
machine grammar over the alphabet {a, b} is the set of
(c) Every regular language is also a context-free language [2009, 1 Mark]
(d) Every subset of a recursively enumerable set is (a) all palindromes
recursive (b) all odd length palindromes
(c) strings that begin and with the same symbol
30. If L and L are recursively enumerable, then L is (d) all even length palindromes
[2008, 1 Mark] 37. Let L1 be a recursive language. Let L2 and L3 be languages
(a) regular (b) context-free that are recursively enumerable but not recursive. Which of
(c) context-sensitive (d) recursive the following statements is not necessarily true?
31. Which of the following are decidable? [2008, 1 Mark]
[2010, 1 Mark]
1. Whether the intersection of two regular languages is
(a) L2 – L1 is recursively enumerable
infinite.
(b) L1 – L3 is recursively enumerable
2. Whether a given context-free language is regular.
3. Whether two push-down automata accept the same (c) L 2 Ç L1 is recursively enumerable
language. (d) L 2 È L1 is recursively enumerable
4. Whether a given grammar is context-free
Theory of Computation S3-131
Which of the following can be inferred from these 57. A single tape turing maching M has two states q0 and q1,
reductions? [2003, 1 Mark] of which q0 is the starting state. The tape alphabet of M
(a) Õ is NP-hard but not NP-complete is {0, 1, B} and its input alphabet is {0, 1}. The symbol
(b) Õ is in NP, but is not NP-complete B is the blank symbol used to indicate end of an input
(c) Õ is NP-complete string. The transition function of M is described in the
(d) Õ is neither NP-hard, nor in NP following table.
52. Nobody knows yet, if P = NP. Consider the language L
de as follows: 0 1 B
ì(0 + 1)*;if P = NP q0 q 1, 1, R q1, 1, R Halt
L= í
î f; otherwise q1 q 1, 1, R q 0, 1, L q0, B, L
Which of the following statements is true? The table is interpreted as illustrated below.
[2003, 1 Mark] The entry (q1, 1, R) in row q0 and column 1 signifies that
(a) L is recursive if M is in state q0 and reads 1 on the current tape square,
(b) L is recursively enumerable but not recursive then it writes 1 on the same tape square, moves its tape
(c) L is not recursively enumerable head one position to the right and transitions to state q1
(d) Whether L is recursive or not will be known after we Which of the following statements is true about M?
find out if P = NP
[2003, 2 Marks]
53. The regualr expression 0* (10)* denotes the same set as
(a) M does not halt on any string in (0 + 1)+
[2003, 1 Mark]
(a) (1* 0)*1* (b) 0 + (0 + 10)* (b) M does not halt on any string in (00 + 1)*
(c) (0 + 1)* 10 (0 + 1)* (d) None of these (c) M halts on all strings ending in a 0
54. Consider the following deterministic finite state (d) M halts on all strings ending in a 1
automation M: 58. Define languages L0 and L1 as follows
Let S denotes the set of seven bit binary strings in which L0 = {< M, W, 0 > |M halts on W}
the first, the fourth and the last bits are 1. The number L1 = {<M, W, 1>| M does not halts on W}
of strings in S that are accepted by M is Here < M, W, i > is a triplet, whose first component, M
[2003, 2 Marks] is an encoding of a turing machine, second component W
is a string and third component i is a bit.
1 0 0, 1 Let L = L0 È L1. Which of the following is true?
0 0
[2003, 2 Marks]
1
(a) L is recursively enumerable, but L is not
(a) 1 (b) 5 (b) L is recursively enumerable, but L is not
(c) 7 (d) 8
(c) Both L and L are recursive
55. Let G = ({S}, {a, b}, R, S) be a context-free grammare (d) Neither L nor L is recursively enumerable
where the rule set R is S®aSb|SS| Î 59. Consider the NFA, M, shown below:
Which of the following statements is true?
[2003, 2 Marks]
(a) G is not ambiguous
(b) There exist X, Y ÎL(G) such that XY ÎL(G)
(c) There is a deterministic push-down automaton that
accepts L(G)
(d) We can find a deterministic finite state automaton
that accepts L(G)
56. Consider two languages L1 and L2, each on the alphabet
S. Let f : S ® S be a polynomial time computable
Let the language accepted by M be L. Let L1 be the
bijection such that ( "X) [X Î L1 iff f(X) ÎL2].
language accepted by the NFA M1 obtained by changing
Further, let f–1 be also polynomial time computable.
the accepting state of M to a non-accepting state and by
Which of the following cannot be true?
changing the non-accepting state of M to accepting
[2003, 2 Marks]
(a) L1 Î P and L2 is finite states. Which of the following statements is true?
(b) L1 Î NP and L2 ÎP [2003, 2 Marks]
(c) L1 is undecidable and L2 is decidable (a) L1 = {0, 1}* – L (b) L1 = {0, 1}*
(d) L1 is recursively enumerable and L2 is recursive (c) L1 Í 1 (d) L1 = L
Theory of Computation S3-133
60. The following finite state machine accepts all those 66. Which of the following languages is regular?
{WW | W Î {0,1} }
binary strings in which the number of 1’s and 0’s are R +
respectively. [2004, 2 Marks] (a) [2007, 2 Marks]
1
1
1
(b) {WWR X | X, W Î{0,1}+ }
0 0
1
0 0 0 0 (c) {WXWR | X, W Î {0,1}+ }
1 1 (d) {XWW R | X, W Î {0,1}+ }
(a) divisible by 3 and 2 (b) odd and even 67. A minimum state deterministic finite automaton accepting
(c) even and odd (d) divisible by 2 and 3 the language L = {W | W Î {0, 1}*, number of 0’s and 1’s in
61. Consider the following grammar G:
W are divisible by 3 and 5, respectively as. [2007, 2 Marks]
S ® bS|aA|b
A ® bA |aB (a) 15 states (b) 11 states
B ® bB|aS| a (c) 10 states (d) 9 states
Let Na (W) and Nb (W) denote the number of a’s and b’s 68. Given below are two finite state automata (® indicates the
in a string W respectively. start state and F indicates a final state) [2008, 2 Marks]
The language L(G) Í {a, b}+ generated by G is
(a) {W|Na(W) > 3Nb(W)} [2004, 2 Marks] a b a b
(b) {W|Nb(W) > 3Na(W)}
(c) {W|Na(W) = 3k, kÎ{0, 1, 2,...}} ®1 1 2 ®1 2 2
(d) {W|Nb (W) = 3k, k Î{0, 1, 2,...}} Y: Z:
62. L1 is a recursively enumerable language over S. An 2 (F) 2 1 2 (F) 1 1
algorithm A effectively enumerates its words as W1, W2,
W3,... define another language L2 over S È{#} as {Wi # Which of the following represents the product automation
Wj : W1, Wj Î L1,i < j}. Here, # is a new symbol. Consider Z × Y?
the following assertions. (a) (b)
S1 –L1 is recursive implies L2 is recursive a b a b
S2 –L2 is recursive implies L1 is recursive ®P Q R ®P S Q
Which of the following statements is true?
[2004, 2 Marks] Q R S Q R S
(a) Both S1 and S2 are true
(b) S1 is true but S2 is not necessarily true R(F) Q P R(F) Q P
(c) S2 is true but S1 is not necessarily true
S Q P S P Q
(d) Neither is necessarily true
63. For S Î (0 + 1) * let d(s) denotes the decimal value of s (e.g., (c) (d)
d(101) = 5) [2006, 1 Mark] a b a b
Which one of the following statements is true?
®P Q S ®P S Q
(a) L is recursively enumerable but not recursive
(b) L is recursively but not context-free Q R S Q S R
(c) L is context-free but not regular
(d) L is regular R(F) Q P R(F) Q P
64. If s is a string over (0 + 1)* then let n0(s) denotes the number S Q P S Q P
of 0’s in s and n1(s) the number of 1’s in s. Which one of the
following languages is not regular? [2006, 2 Marks] 69. 1
(a) L = {s Î (0 + 1)* | n0(s) is a 3-digit prime} 0
(b) L = {s Î (0 + 1)* | for every prefix s¢ of s, 0 0
| n0(s¢) – n1(s¢) £ 2}
(c) L = {s Î (0 + 1)* | n0(s) – n1(s)| £ 4
1
(d) L = {s Î (0 + 1)* | n0(s) mod 7 = n 1(s) mod 5 = 0}
The above DFA accepts the set of all strings over {0, 1} that
65. Let L1 = {0n+m1n0m |n, m ³ 0}, L2 = {0n+m1n + m0m |n, m ³ 0},
(a) begin either with 0 or 1 [2009, 2 Marks]
and L3 = {0n+m1n + m 0n + m |n, m ³ 0}. Which of these
(b) end with 0
languages is/are not context free? [2006, 1 Mark]
(c) end with 00
(a) L1 only (b) L3 only
(d) contain the substring 00
(c) L1 and L2 (d) L2 and L3
S3-134 Theory of Computation
70. Given the following state table of an FSM with two states A 76. A deterministic finite automation (DFA)D with alphabet å =
and B, one input and one output {a, b} is given below. [2011, 2 Marks]
b b a, b
Present Present Input Next Next Output p q r
State A State B State A State B
0 0 0 0 0 1
0 1 0 1 0 0 a a
1 0 0 0 1 0
1 1 0 1 0 0 a, b a, b
0 0 1 0 1 0 s t
0 1 1 0 0 1
1 0 1 0 1 1 Which of the following finite state machines is a valid minimal
1 1 1 0 0 1 DFA which accepts the same language as D?
(a)
If the initial state is A = 0, B = 0, what is the minimum length b b a, b
p q r
of an input string, which will take the machine to the state
A = 0, B = 1 with output = 1? [2009, 2 Marks]
(a) 3 (b) 4 a a
(c) 5 (d) 6
71. Which one of the following languages over th e
a, b
alphabet {0 1} is described by the regular expression (0 + 1)
* 0(0 + 1) * ? [2009, 1 Mark] a, b
(a) The set of all strings containing the substring 00 s
(b) The set of all strings containing at most two 0’s (b)
(c) The set of all strings containing at least two 0’s a, b b
p q
(d) The set of all strings that begin and end with
either 0 or 1. a
72. Let W be any string of length n in {0, 1}*. Let L be the set of r a, b
all sub-strings of W. What is the minimum number of states
in a non-deterministic finite automaton that accept L? a, b
[2010, 2 Marks] (c) a, b
(a) n – 1 (b) n a, b b
p q r
(c) n + 1 (d) 2n – 1
73. Consider the languages L1 = {0i1j | i ¹ j}, L2 = {0i1j | i = j}, (d)
L3 = {0i1j | i = 2j + 1 j}, L4 = {0i1j | i ¹ 2j}. Which one of the b
p q
following statements is true? [2010, 2 Marks]
(a) Only L2 is context-free
(b) L2 and L3 are context-free a a
(c) L1 and L2 is context-free
(d) All are context free s a, b
74. Let L = {W Î (0, 1) * | W has even number of 1s}, i.e., L is the
set of all bit strings with even number of 1’s. Which one of 77. Definition of a language L with alphabet {a} is given as
the regular expressions below represents L? following and n is a positive integer constant. What is the
[2010, 2 Marks] minimum number of states needed in a DFA to recognize L ?
(a) (0* 10* 1)* (b) 0 * (10* 10*)* [2011, 2 Marks]
(c) 0 * (10 *1)* 0* (d) 0 * 1(10 * 1) * 10 * (a) k + 1 (b) n + 1
75. Consider the languages, L1, L2 and L3 as given below (c) 2n + 1 (d) 2k + 1
78. Let P be a regular language and Q be a context free language
{
L1 = 0p1q | p, q Î N } [2011, 2 Marks] such that Q Í P . For example, let P be the language
represented by the regular expression p*q* and Q be
L 2 = {0 p1q | p, q Î N and p = q} and ( Qn pn qn n Î N ) . Then which of the following is always
L3 = {0 p1q 0 r | p, q, r Î N and p = q = r}
regular? [2011, 1 Mark]
(a) P Ç Q (b) P – Q
Which of the following statements is not true? (c) å * - P (d) å * - Q
(a) Push Down Automata (PDA) can be used to recognize 79. A list of n strings, each of length n, is sorted into
L1 and L2 lexicographic order using the merge-sort algorithm. The
(b) L1 is a regular language. worst case running time of this computation is
(c) All the three languages are context-free [2012, 2 Marks]
(d) Turning machines can be used to recognize all the (a) O (n log n) (b) O (n2 log n)
languages (c) O (n2 + log n) (d) O (n2)
Theory of Computation S3-135
80. The worst case running time to search for an element in a 87. If L1 = {an | n ³ 0} and L2 = {bn | n ³ 0}, consider
balanced binary search tree with n2n elements is [2014, Set-2, 1 Mark]
[2012, 1 Mark] (I) L1.L2 is a regular language
(a) Q (n log n) (b) Q (n2n) (II) L1.L2 = {anbn | n ³ 0}
(c) Q (n) (d) Q (log n) Which one of the following is CORRECT?
81. The recurrence relation capturing the optimal execution time
(a) Only (I) (b) Only (II)
of the Towers of Hanoi problem with n discs is
(c) Both (I) and (II) (d) Neither (I) nor (II)
[2012, 1 Mark]
88. Let L1 = {w Î {0, 1}*| w has at least as many occurrences of
(a) T(n) = 2T (n – 2) + 2 (b) T(n) = 2T (n – 1) + n
(110)’s as (011)’s}. Let L2 = {w Î{0, 1}* | w has at least as
(c) T(n) = 2T (n/2) + 1 (d) T(n) = 2T (n – 1) + 1
many occurrences of (000)’s as (111)’s}. Which one of the
82. Let W(n) and A(n) denote respectively, the worst case and
average case running time of an algorithm executed on an following is TRUE? [2014, Set-2, 2 Marks]
input of size n. Which of the following is always true? (a) L1 is regular but not L2
[2012, 1 Mark] (b) L2 is regular but not L1
(a) A(n) = W (W(n)) (b) A(n) = Q (W(n)) (c) Both L1and L2 are regular
(c) A(n) = O (W(n)) (d) A(n) = o (W(n)) (d) Neither L1 nor L2 are regular
S*
83. Consider the languages L1 = F and L2 = {a}. Which one 89. Let S be a finite non-empty alphabet and let 2 be the
of the following represents L1 L2* È L1*? power set of S*. Which one of the following is TRUE?
[2014, Set-3, 1 Mark]
[2013, 1 Mark]
(a) {e} (b) F S*
(a) Both 2 and S* are countable
(c) a* (d) (e, a)
84. Consider the finite automation in the following figure. (b) 2S * is countable and S* is uncountable
PDA, L2 can be accepted by deterministic CFL due to 25. (b) Finite state automata (FSA) has no undecidability CFL
presence of special symbol D which tells the middle of membership problem is also decidable.
the string, so deterministic. So option (b) i.e Ambiguity of CFL cannot be
14. (b ) The rules here used will be. decidable.
All those languages which are recursive their 26. (a) Lets gather some knowledge for the regular
complements are also recursive. expressions before going to True or False. The regular
So option (a) & (b) can be correct. sets are defined in such a way that they have to follow
Now languages which are recursively enumerable but some conventions. Conventions on regular
not recursive, their complements can’t be recursively expressions
enumerable. 1. Bold face is not used for regular expressions when
So only option (b) is correct. the expression is not confusing. So, for example,
Hence (b) is correct option. (r + s) is used instead (r + s).
15. (a) L1 and L2 are context-free languages and therefore 2. The operation * has precedence over
L1 Ç L 2 may or may not be context-free, since CFLs concatenation, which further has precedence
are not closed under intersection. Now, let us look at over union (+). Thus, the regular expression (a +
b(c*))) is written as a + bc*.
L1 Ç L 2 .
3. The concatenation of k r’s, where r is regular
L1 Ç L 2 = {anbncn | n > 0} expression, is written as rk. Thus, for example rr =
which is clearly not context-free but is context sensitive. r2. The language corresponding to rk is Lkr , where
16. (d) We know that, the languages accepted by non-
deterministic finite automata are also accepted by Lr is language corresponding to the regular
deterministic finite automata. This may not be in the expression r. For a recursive definition of Lkr .
case of context-free languages.
4. The (r +) is used as a regular expression to
Therefore, Df = Nf and Dp Ì N p
17. (b) a is followed by two or more than 2b’s so the language represent L+r .
Based on the concept, only 1 and 4 are found to
recognized by M is {W Î {a, b} * | .
be regular since in 1, L can be written as a* (bb)*
18. (c) According to the option, P2 is reducible to P3. and 4, (a + b) * c(a + b)* can be written for the 4.
Also it gives that P2 is undecidable. 27. (c) The matched sequence is as given
From (a) and (b) ;
P3 is undecidable. List I List II
19. (b) L1 is regular language E. Checking that identifiers R. L = {WCW | W Î (a | b)*}
L2 is CFL. are declared before their
L3 is recursively enumerable but not REC. use.
(a) L1 I L2 is CFL is true F. Number of formal P. L = {anbmcndm |m ³ 1, m, ³ 1|}
(b) L3 I L1 is recursive, not necessary so false. parameters in the
(c) & (d) are also true. declaration of a function
20. (b) Due to S ® S this Grammar is ambiguous right hand agrees with the number
side has twoNon terminals. Also the strings like of actual parameters in
aaabbb have equal no. of a’s & b’s but can’t be use of that function
produced by this grammar. So 2 is false. G. Arithmetic expressions Q. X ® XbX | XcX | dxf | g
Statement 3 is true since it is a CFG so accepted by PDA.
with matched pairs of
21. (a) There is a difference between SHAM3 and DHAM3
that SHAM3 is used for finding a Hamiltonian cycle in parentheses
a graph but DHAM3 is the problem of determining if a H. Palindromes S. X ® bXb |cXc| e
graph exists in a Hamiltonian cycle. Also it is given
that |V| is divisible by 3, hence the problem can be 28. (d) Statement 1 True: Left recursive and right recursive
reduced from 3 SAT which further determines that grammar can be converted into each other.
SHAM3 and DHAM3 are NP hard. Statement 2 True: All e-productions can be removed
22. (a) S is NP complete and a NP complete problem is from many context-free grammar by suitable
reducible to some unknown problem then that problem transformations.
is also NP complete. So S ® D, R the R is NP complete. Statement 3 False: The language is not always regular
23. (b) L = {Oi i2li | i > 0}, this language can’t be accepted since given the property of the context-free grammar
byDFA to regular, but it is recursive & can be that the right side of the productions have any one of
accepted by PDA to CFL. the following.
24. (b) Finite subset of non-regular set is regular as we know 1. single-terminal
that Pumping Lemma can be applied on all the finite 2. non-terminal followed by a terminal
sets that states that all finite sets are regular. Infinite 3. l
union of finite set is not regular because regular sets Statement 4 False: The derivation trees in CNF are
can never be closed under infinite union. binary trees.
S3-138 Theory of Computation
29. (d) Option (a) True: Non-deterministic finite automata can (b) true, NFA can be converted into an equivalent
be converted into the deterministic finite automata. PDA.
Option (b) True: With reference to option (a), same is (c) CG’S are not recursive but their complements are.
with the non-deterministic turing machine. (d) false, since non deterministic PDA represents,
Option (c) True: Regular language is always context- non deterministic
free but the reverse is not true. CFG, since NDCFG and CFG are proper subsets so
Option (d) False: We know that a set is a subset of conversion required.
itself and hence, every subset of recursively 36. (b) Given grammar S ® aSabSbab.
enumerable set is not recursive. The strings generated through this grammar is
30. (b) As per the theorem, a language is recursive if that definitely palindromes,but not all it can only generate
language and its complement are recursively palindromes of odd length only so (A) & (D) are false,
enumerable. Therefore, L is recursive. (B) is correct.
31. (b) Statement 1 Decidable: The algorithm can be used to Also it can generate palindromes which start and end
check the finiteness/infiniteness on the DFA and also with same symbol, but not all strings eg. aabababba.
the two given DFAs, a product DFA can be 37. (b) L1 ® recursive
constructed. L2,L3 ® recursively enumerable but not recursive.
Statement 2 Undecidable: It is not decidable since the So L1 can be recursive enumerable.
language is context-free. RE - RE = RE
Statement 3 Undecidable: It is also undecidable that So L1 - L3 is recursively enumerable.
whether two push-down automata accept the same 38. (b) DPDA and NPDA because an NPDA cannot be
language. converted into DPDA.
Statement 4 Decidable: If the LHS of each production 39. (c) 1. Non-deterministic Turing Machine can be
has one and only one variable then it is a context-free simulated by a deterministic Turing Machine
grammar. with exponential time true.
32. (d) {aPPis a prime no.} 2. Turing recongnizable language are “not” closed
This prime no. is extra constraint so this language is under complementation. For any Turing
neither LFG nor RG but it can be accepted by turing recognizable language the Turing Machine ‘T’
machine. recognizing ‘L’ may not terminate on inputs
33. (c) It is given that L = L1 Ç L 2 x Ï L - False
Let’s first analyze the given language and check 3. Turing decidable languages are CLOSED under
whether it is context-free or not. The context-free union and complementation. It is easy to
languages are defined as below– determine if turing machine is decidable-True
{
n n
}
A context-free language is L = a b : n ³ 1 that is 40. (d)
So, answer is option (c) only 2.
1. G is a CFG. Is L(G) = f?
the language of all non-empty even-length strings. It Decidable
consists of 2. G is a CFG. Is L(G) = S * ?
1. the entire first halves of which are a’s. Undecidable
2. the entire second halves of which are b’s. 3. M is a Turing Machine. Is L (M) regular?
L is generated by the grammar S ® aSb | ab, and is Undecidable.
accepted by the push-down automation M = ({q0, q1, 4. A is a DFA and N is an NFA. Is L(A) = L(N)?
qf}, {a, b}, {a, z), d q0, {qf}) where d is defined as Decidable.
d(q0, a, z) = (q0, a) Hence, the correct answer is (d) 2 and 3 only.
d(q0, a, a) = (q0, a) 41. (c) We know that a language L is regular if an
d(q0, b, a) = (q1, x) equivalent finite Automaton can be constructed for
d(q1, b, a) = (q1, x) it.
d(q1, l, z) = (qf, z) DFA can be constructed for L as follows:–
d (state1, read pop) = (state2, push) Note that L contains the strings that has 3k + 1
where z is initial stack symbol and x means pop action. number of b’s (that is 4, 7, 10, .......n ...... no. of b’s
Here, in we are given, where a and b are of equal lengths and any no. of a’s)
and followed by c which is of different length. This a a a a a
definitely shows that the languages are context-free
but not regular.
34. (b) Regular expressions are meant for lexical analysis to q0 q1 q2 q3 q4
define tokens.Pushdown Automata is used to accept b b b b
context free language which are used for syntax
analysis.
Data flow analysis is a technique for code optimization. b
Register allocation is used for code generation. q0 is the initial state. q4 is the final state.
So P-3, Q-1, R-4, S-2. FA state remains same when input symbol is “a” at
35. (d) (a) true, since minimal DFA for every regular any point of time.
language is possible. When 1st ‘b’ is read, state is changed from q0 to q1.
When 2nd ‘b’ is read, state is changed from q1 to q2.
Theory of Computation S3-139
When 3rd ‘b’ is read, state is changed from q2 to q3. is superset of Deterministic Finite Automata.
& when 4th ‘b’ is read, state is changed from q3 to Since, the value of arbitrary finite automata is N, so
q4. value of DFA would be the one directly related to it
If no more ‘b’ is encountered, the string is accepted (multiple in most cases).
when last input symbol is read. This implies that value of DFA is 2 N.
However if 5th “b” is there is string, state is changed 47. (c) Since all a’s are divisible by 6.
from q1 to q2 so that to accept the string 2 more bs
must be there in the string at least.
Continuing in this way only those strings are
accepted that has 3k + 1 (k Î N ) number of b’s. (i.e. Total states = 7 ® a
4, 7, 10 ... number of b’s). And all b’s are divisible by 8.
42. (d) If B is not recursively enumerable then A need not be b b b b b
recursively enumerable. 1 2 3 4 5 6
43. (b) The language is recursive enumerable and it is b
undecidable
7
PROBLEM BASED MCQs b
44. (c) Lets consider the regular expressions as given in the
questions: 8
b
F
Total number of states = 9 ® b
So, the minimum number of states in DFA is a + b
= 9 + 7 = 16
48. (a) Lets consider both the statements separately to find
the correct option.
S1 : {02n |n ³ 1|}
Applying the values of n,
® S1 = 00, 0000, 000000, ............
Second, (a + b)* The behaviour shown by the output is regular and
hence, the language is a regular language.
S2 : {0m1n0m + n| m ³ 1 and n ³ 1|}
Applying the values of m and n,
S2 = 0100, 00110000, 000111000000, .........
Here the values of m and n are kept same so thay
are showing the output in symmetry but if we use
the different values of m and n then the output will
display a behaviour which is not regular. Therefore,
confirmed is that S1 is a regular language.
Þ (a + b*)* = (a + b*)
49. (a) As per the given diagram.
Therefore, we can say that S = T
45. (d) Lets take an example to solve this. State Input Output
L1 = {n, nnn, nnnnn, ....} A to A 10 00
= {n ood}
B to A 10 00
= {n 2n+1; for n = 0, 1, 2, 3, 4, 5, 6,...}
and L2 = {n, nnnn, nnnnnn, ...} C to A 10 00
= {n even} Therefore, the finite state machine outputs the sum
= {n 2n; for n = 0, 1, 2, 3, 4, 5, 6 ...} of the present and previous bits of the input.
Therefore, either L must be {an|n is odd}, or L must 50. (b) Answer in the book is wrong
be {an |n is even}
46. (c) The relation between the NDFA and DFA can be a b c
seen in the image below:
Start & end are same as (a) hence the minimum no.
of states required are3. Option (b) is correct. If string
traversal doesn't stop at (a) then string length is not
divisibleby 3.
51. (c) Since, 3 SAT is reduced to Õ, this implies 3 SAT £
Õ and since, Õ is reduced to 3 SAT, this implies
p £ 3 SAT.
It shows that the Non-Deterministic Finite Automaton We know that, if L1 £ L2 and L1 is NP-complete, then
S3-140 Theory of Computation
60.
\ L1= (0 + 1)* = {0, 1}*
(a) The given finite state machine accepts any string W {
L1 = 0 n + m1n 0 m | n, m ³ 0}
Î(0, 1)* in which the number of 1’s is multiple of 3 The production for L1 as follows:
and the number of 0’s is multiple of 2.
61. (b) DFA of the given grammar is S ® 0S0 0A1 e
b A ® 0A1 e
b b
a a a Now, we need to apply these values of the production
S A B F1 individually to generate
a
0 n + m n 0m
b
that is,
0m0n1n0m ® To prove
F2 Applying 0S0 (m times)
S ® 0 S0, S ® 0mS0m
Clearly, the machine is accepting Na(W) = 3k, where k Applying, S ® 0A1
Î{0, 1, 2, 3,...} ® S ® 0m 0A1 0m
62. (c) L1 = {W1, W2, W3,...} Here applying, A ® 0 A1, n – 1 times
L2 = {Wi # Wj: Wi, Wj ÎL1, Wi < Wj} S ® 0m 0 0n–1 A1n–1 10m
= {W1 # W2, W1 # W3, W1 # W4, ... W2 # W3 W2 ® S ® 0m 0n1n0m
# W4, W2 W5,... so on} Hence, proved, so L1 is context-free.
Consider S1: If L1 is recursive, then a membership Going through the same procedure, we can see that
algorithm exists for L1. Now consider an arbitrary Wi two comparisons are made in the L2 language, So it is
# Wj generated by a turing machine. Using the not context-free.
membership algorithm for L1, we can find out L3 ® Going through the same procedure again, we
whether or not Wi Î L1 and Wj Î L1. If it is true can see that two comparisons are made in the L3
that Wi Î L1 and Wj ÎL1 then we can check from language, so it is not context free.
the list L1 = {W1, W2, W3,...} whether i < j. 66. (c) Lets study the regular language.
\ We can determine whether or not Wi # Wj ÎL2. Convenstions on regular expressions
This means, the membership algorithm for L1 can be 1. Bold face is not used for regular expressions when
used to construct a membership alogrithm for the expression is not confusing. So, for example,
L2 as follows. For an arbitrary Wi # Wj. (r + s) is used instead (r + s).
1. If Wi, Wj Î L1 and i < j then Wi # Wj ÎL2. 2. The operation * has precedence over
2. If either Wi ÏL1 or Wj ÎL2 or 1³ j, then Wi # concatentation, which further has precedence
Wj Ï L2. over union (+). Thus, the regular expression (a +
\ L2 is also recursive. S1 is therefore true. b(c*))) is written as a + bc*.
Now, consider S1 : L2 recursive implies L1 is 3. The concatenation of k r’s, where r is regular
recursive. expression, is written as rk. Thus, for example rr =
L2 is recursive means that there is a membership r2. The language corresponding to rk is Lkr , where
algorithm for L2i.e., for an arbitrary Wi # Wj, we can
find out whether or not Wi # Wj ÎL2. However, we Lr is language corresponding to the regular
cannot use this algorithm to construct a membership expression r. For a recursive definition of Lkr .
algorithm for L1, since if Wi # Wj ÏL2, it may be
because Wi ÏL1 or Wj ÏL1 or both ÏL1 and we 4. The (r +) is used as a regular expression to
cannot find out which case it is. Therefore, a represent L+r .
membership algorithm is not possible for L1 using
the membership algorithm for L2. S2 is not necessarily Since, language L can be expressed as
true. r = [0 (0 + 1) * 0] + [1 (0 + 1) * 1]
\ S1 is true but S2 is not necessarily true is the correct and follows the above convention, therefore is regular
answer. 67. (a) It is given that the 0’s and 1’s are divisible by 3 and 5
and we know that 3 and 5 do not have any factor other
S3-142 Theory of Computation
Y Z
No. of states of the product of Z and Y = 2 × 2 = 4 11 0/0 10
Now, the states as per the given options are P, Q, R
and S. The finite state automata is The desired output is obtained with the input string
101, however, the concern is number of states which
a b we found to be 3.
71. (c) We are given with the relation
®P S R (0 + 1) * 0(0 + 1)* 0(0 + 1)*
Here, the accepting languages are
Q R S L = {00, 000, 100, 001, 010, 0000, 0001, 1000, 1001, 0100,
1100, 0010, 0011, 0110, 0101, 1010, ...}
R(F) Q P The common feature in the accepting languages can
be seen that they consist of atleast two 0’s.
S Q P 72. (c) L is the set of all substrings of w where w ! {0,1})
Any string in L would have length 0 to n, with any no.
Table for Z × Y is of 1’s and 0’s
The NDFA
a b
74. (b) It is given that L is the set of all bit strings with even
number of 1’s so the regular expression should exhibit Mo
ve f
the same. r om
A to C
Now, the min string should be e and the string should
be e, 0, 11, 101, ...
The string obtained from such expression is 0* (10* 10
*)* n – 1 discs n – 1 discs
move from
75. (c) { }
L1 = 0 p1q | p, q Î N is regular language A to B
move from
B to C
But s¢Î f Q f is an empty language. (I) 0*1 (1 + 00 * 1)* it represents the given DFA
using following transition:
\ f. L= f
O* :– 1 q0 ® q0
{e} Í L* for all languages L.
1 :– q0 ® q1
As it means taking letters from the language and (1 + 00 * 1) * :– q1 ® q0 ® q0 ® q1
concatenating them ‘0’ times creating a ‘0’ length (1 +) (0) (0*) (1)
string which is possible for all languages. So, the string is accepted.
\ e is in f* (II) 0 * 1 * 1 + 11 * 0 * 1 :-
L1 . L2 = f Following transition occurs :–
and L1 = {e} 0 * :– q0 ® q0
L1 . L2 * È L*1 = (L1 . L2) È L*1 1 * :– q0 ® q0 (if 1 is absent) or 1 * : q0 ® q1 (if 1 is present)
\ f È {e} = {e} (1 + 11*) : q0 ® q1 q1 ® q1
84. (a) Following paths can be taken by the finite Automaton 0 * :– q1 ® q1 (if 0 is absent) q1 ® q0 (if 0 is present)
for the input string “0011”:–– 1 :– q1 ® q1 q0 ® q1
q0 uuuuuuuuu
0 rq0 uuuuuuuuu
0 rq0 uuuuuuuur
1 q0 uuuuuuuur
1 q0 final state is q1 , this string is also accepted.
(III) (0 + 1) * 1 :– Following transition occurs :–
Reachable states (0 + 1) * :– q0 ® q0 ® q1
{q0 } (0 +) (1)
1 :– q1 ® q1
q0 uuuuuuuuu
0 rq0 uuuuuuuuu
0 rq0 uuuuuuuur
1 q0 uuuuuuuur
1 q1
Ans final state is q1, so this string is also accepted. Hence
{q0, q1} (d) is true.
q0 uuuuuuuuu
0 rq0 uuuuuuuuu
0 rq0 uuuuuuuur
1 q1 uuuuuuuur
1 q2 87. (a)
88. (a) L1 is regular but L2 is not
(q0, q1, q2) 89. (c) S* is countabily finite
We note that no other path is possible for the input 2S * is power set of S*
string “0011”. The powerset of countabily infinite set is uncountable
So, finally union of all three cases gives us the set \ 2S* is uncountable and S* is countable.
of Reachable states which is {q0, q1, q2}
COMMON DATA MCQs
85. (c) Both L and L are recursively enumerable but not
recursive. 90. (b) The FSA as obtained in the previous question is b* a
Set of recursive languages is subset of the set of (a + b)*
recursively enumerable languages. The minimum number of states are thus given by
So, if a language is recursive, It must be R.E. also.
b a, b
(a) May be true as a language L and its complement
L need not be recursively enumerable.
q0 q1
(b) May be true if L is r.e. but not recursive and L is a
not recursively enumerable q0 and q1 are the state: that are required at most and
(d) May be true as L and L both can be recursive. hence the minimum number of states is 2 (q0 and q1).
91. (c) The behaviour as per the given PDA is an seen below
However (c) is not possible because if Both L
q0 to q1 ® b*a
and L are recursively enumerable than by a well q1 to q2 ® (a + b) *
known theorem of complexity theory either L or Regular expression = b * a (a + b)*
L has to be recursive. NUMERICAL ANSWER QUESTIONS
86. (d) I, II and III.
Given DFA : 92. 3
a * b * (ba) * a *
O O Length O is present (as it accepts Î)
1 Length 1 is present (a, b)
Length 2 is present (aa, ab, ba, bb)
q0 q1 Length 3 is not present (bab not present)
\ it is 3
1
Compiler Design S3-145
6 Compiler Design
Chapter
Compiler is a special program which reads a program in source 1. if e is a regular expression , then L(e) is {e} where e is
language and translates into an equivalent other language. the only sole member in empty string.
LEXICAL ANALYSIS 2. If a is a symbol e, then regular expression L(a) = {a} that
is the language with one string, length one and position
This is the first phase of a compiler and this reads the input
one.
characters from left to right and creates a sequence of tokens.
These tokens are used by the parser for syntax analysis. Regular Definitions
The schematic representation is given below, The regular definition is a type of regular expression used for
notational convenience. If e is an alphabet of basic symbols,
Token then a regular definition is a sequence of the form,
Source Lexical To semantic
Parser d1 à r1
Program Analyser Analysis
get next d2 à r2
token
…
dnàrn
Symbol where, each di is a new symbol, not in e and not same as any
Table other of the d’s and
Interaction between lexical analyzer and Parser each ri is the regular expression over the alphabet e U
{d1,d2,d3……di-1}
Token Informal Description of Pattern Sample Lexeme Recognition of tokens
If Characters i& f If The piece of code which is given as the input to lexical analyzer
matches for the pattern and returns the respective tokens. For
Else Characters e,l,s,e Else example,
Comparison Stmtà if expr then stmt
< or > or <= or >= or == <,>
operators | Elsestmt
Number Any numeric constants 0,180,3.14 | e
Exprà term relop term
Literal Any character within “ “, except “ “compiler design” | term
Term à id
Id Letter followed by letters and digits Pi, count
| number
Table: Showing Token, Patterns and Lexeme In this the terms if, then, else, relop, id and number are the
Regular Expression names of the tokens as the lexical analyzer is concerned and
these are the reserved words.
Regular expression can be called as a notation which is used
in describing all the languages that can be built from these Transition diagrams
operators applied to symbol of some alphabet. Transition diagrams have a collection of nodes, edges, where
The two rules which form the basics are, nodes are called stated.
Transition diagram
0 a 1 2 3
Start b b
b
NFA accepting (a/b)*abb
S3-146 Compiler Design
0 a 1 2 3
Start b b
a
a
a
DFA accepting (a/b)*abb
E¢ 13 node
1/2
E¢ syn
5 inh
T 2 node E¢ 1.1 syn
+ inh 6
T 4 node 10 syn
id 1 entry 9 inh E1
8 node
* T
num 3 vol E
Symbol
Table
THE BASICS OF CODE OPTIMIZATION
Input to the code generator The optimized code executes faster, provides efficient memory
The input to the code generator comes from intermediate code storage and yields better performance. Compilers can be
generation phase with information in the symbol table which designed to provide code optimizations.
determines the runtime addresses of the data objects. The code optimizer sits between the front end and the code
Target programs generator. This works at intermediate code generator stage, it
The output of the code generator is the target program. The can perform control flow analysis and data flow analysis. And
output may be of any form, absolute machine language,
relocatable machine language or assembly language. does transformations to improve the intermediate code.
Memory management Optimization provided by a compiler are as below:
Mapping of the names in the source program to the addresses – Inlining small functions: this involves in repeatedly
of the data object in runtime memory is done cooperatively by inserting the function code instead of calling it. This
the front end and the code generator. reduces the calling overhead and enables further
Register allocation optimizations. Inlining large function will make the
The instructions having register operands are shorter and executable large.
faster than the operands used in memory.
The use of registers usually has two sub problems – Code hoisting: this involves in moving computation s
1. During register allocation, the set of variables that will outside the loop and this saves computing time.
reside in registers are selected at a point in the – Dead store elimination: If the compiler detects
program.
2. During subsequent register assignment, we pick the variables which are never used , it may safely ignore
specific registry that a variable will reside in. many of the operations that compute their values.
Choice of evaluation order – Eliminating common sub expression
The order in which the computations are done can affect the – Loop unrolling: Loop exit checks costs CPU time. This
efficiency of target code. Some computations require lesser tries to get rid of all checks or atleast minimize the
registeres to hold the values generated in intermediate code number of checks. If it is known that the loop is only
generation. The code would be generated for three address
performed a certain number of time, it can be unrolled.
Compiler Design S3-151
13. Consider the grammar rule E ® E1 – E2 for arithmetic 19. Consider the following two statements:
expressions. The code generated is targeted to a CPU [2007, 2 Marks]
having a single user register. The subtraction operation P: Every regular grammar is LL (1).
requires the first operand to be in the register. If E1 and Q : Every regular set has a LR (1) grammar.
E2 do not have any common sub-expression, in order to Which of the following is true?
get shortest possible code. [2004, 1 Mark] (a) Both P and Q are true
(a) E1 should be evaluated first (b) P is true and Q is false
(b) E2 should be evaluated first (c) P is false and Q is true
(c) Evaluation of E1 and E2 should necessarily be (d) Both P and Q are false
interleaved 20. Some code optimizations are carried out on the intermediate
(d) Order to evaluation of E1 and E2 is of no code because [2008, 1 Mark]
consequence (a) they enhance the portability of the compiler to other
14. The grammar A ® AA | (A) | Î is not suitable for predictive- target processors
parsing because the grammar is [2005, 1 Mark] (b) program analysis is more accurate on intermediate code
(a) ambiguous (b) left-recursive than on machine code
(c) right-recursive (d) an operator grammar (c) the information from data flow analysis cannot be used
15. Consider line number 3 of the following C program: for optimization
int min () { /* Line 1 */ (d) the information from the front end cannot be used for
int I, N; /* Line 2 */ optimization
fro (I = 0, I < N, I ++); /* Line 3 */ 21. Which of the following describes a handle (as applicable to
Identify the compiler’s response about this line while LR-parsing) appropriately? [2008, 1 Mark]
creating the object-module. [2005, 2 Marks] (a) It is the position in a sentential form where, the next
(a) No compilation error shift or reduce operation will occur
(b) Only a lexical error (b) It is non-terminal whose production will be used for
(c) Only syntactic errors reduction in the next step
(d) Both lexical and syntactic errors (c) It is a production that may be used for reduction in a
16. Consider the following C code segment: future step along with a position in the sentential form
[2006, 2 Marks] where, the next shift or reduce operation will occur
for (i = 0, i < n; i ++) { (d) It is a production p that may be used for reduction in a
for (j = 0, j < n; j ++) { future step along with a position in the sentential form
if (i % 2){ where, the right hand side of the production may be
x + = (4 * j + 5 * i); found.
Y + = (7 + 4 * j); }}} 22. Which of the following are true? [2008, 2 Marks]
Which one of the following is false? 1. A programming language which does not permit global
(a) The code contains loop invariant computation. variables of any kind and has no nesting of
(b) There is scope of common sub-expression elimination procedures/functions, but permits recursive can be
in this code implemented with static storage allocation
(c) There is scope of strength reduction in this code 2. Multi-level access link (or display) arrangement is
(d) There is scope of dead code elimination in this code needed to arrange activation records only, if the
17. Which one of the following is a top-down parser? programming language being implemented has nesting
(a) Recursive descent parser [2007, 1 Mark] of procedures/functions.
(b) Operator precedence parser 3. Recursion in programming languages cannot be
(c) An LR (k) parser implemented with dynamic storage allocation
(d) An LALR (k) parser 4. Nesting of procedures/functions and recursion require
18. Consider the grammar with non-terminals N = {S, C, S1}, a dynamic heap allocation scheme and cannot be
terminals T = {a, b, i, t, e} with S as the start symbol and the implemented with a stack-based allocation scheme for
following set of rules [2007, 2 Marks] activation records.
S ® iCtSS1 | a 5. Programming languages which permit a function to
S1 ® eS | e return a function as its result cannot be implemented
C®b with a stack based storage allocation scheme for
The grammar is not LL(1) because activation records
(a) it is left recursive (b) it is right recursive (a) 2 and 5 (b) 1, 3 and 4
(c) it is ambiguous (d) it is not context-free (c) 1, 2 and 5 (d) 2, 3 and 5
Compiler Design S3-153
23. An LALR(1) parser for a grammar G can have shift-reduce 30. A canonical set of items is given below
(S-R) conflicts, if and only, if [2008, 2 Marks] S ® L. > R
(a) the SLR (1) parser for G has S-R conflicts Q ® R.
(b) the LR (1) parser for G has S-R conflicts On input symbol < the set has [2014, Set-1, 2 Marks]
(c) the LR (0) parser for G has S-R conflicts (a) a shift-reduce conflict and a reduce-reduce conflict.
(d) the LALR (1) parser for G has reduce-reduce conflicts (b) a shift-reduce conflict but not a reduce-reduce conflict.
24. Which of the following statements are true? (c) a reduce-reduce conflict but not a shift-reduce conflict.
[2009, 2 Marks] (d) neither a shift-reduce nor a reduce-reduce conflict.
31. Consider the grammar defined by the following production
1. There exist parsing algorithms for some programming
rules, with two operators * and +
languages whose complexities ar less than q (n3).
S®T*P
2. A programming language which allows recursive can
T®U|T*U
be implemented with static storage allocation.
P ®Q+P|Q
3. No L-attributed definition can be evaluated in the Q ® Id
framework of bottom-up parsing. U ® Id
4. Code improving transformations can be performed at Which one of the following is TRUE?
both source language and intermediate code level. [2014, Set-2, 1 Mark]
(a) 1 and 2 (b) 1 and 4 (a) + is left associative, while * is right associative
(c) 3 and 4 (d) 1, 3 and 4 (b) + is right associative, while * is left associative
25. Which data structure in a compiler is used for managing (c) Both + and * are right associative
information about variables and their attributes? (d) Both + and * are left associative
[2010, 1 Mark] 32. Which one of the following is NOT performed during
(a) Abstract syntax-tree (b) Symbol table compilation? [2014, Set-2, 1 Mark]
(c) Semantic stack (d) Parser table (a) Dynamic memory allocation
26. The grammar S ® aSa | bS| c is [2010, 2 Marks] (b) Type checking
(c) Symbol table management
(a) LL (1) but not LR (1) (b) LR (1) but not LL (1)
(d) Inline expansion
(c) Both LL (1) and LR (1) (d) Neither LL (1) and LR (1)
33. One of the purposes of using intermediate code in compilers
27. In a compiler, keyboards of a language are recognized during
is to [2014, Set-3, 1 Mark]
[2011, 1 Mark]
(a) make parsing and semantic analysis simpler.
(a) parsing of the program
(b) improve error recovery and error reporting.
(b) the code generation (c) increase the chances of reusing the machine-
(c) the lexical analysis of the program independent code optimizer in other compilers.
(d) data flow analysis (d) improve the register allocation.
28. The lexical analysis for a modern computer language such 34. Which of the following statements are CORRECT?
as Java needs the power of which one of the following (1) Static allocation of all data areas by a compiler makes
machine models in a necessary and sufficient sense? it impossible to implement recursion.
[2011, 1 Mark] (2) Automatic garbage collection is essential to implement
(a) Finite state automata recursion.
(b) Deterministic push down automata (3) Dynamic allocation of activation records is essential
(c) Non-deterministic push down automata to implement recursion.
(d) Turing machine (4) Both heap and stack are essential to implement
29. Which one of the following is FALSE ? recursion. [2014, Set-3, 1 Mark]
[2014, Set-1, 1 Mark] (a) 1 and 2 only (b) 2 and 3 only
(a) A basic block is a sequence of instructions where (c) 3 and 4 only (d) 1 and 3 only
control enters the sequence at the beginning and exits 35. Which one of the following problems is undecidable?
at the end. [2014, Set-3, 2 Marks]
(b) Available expression analysis can be used for (a) Deciding if a given context-free grammar is ambiguous.
(b) Deciding if a given string is generated by a given
common subexpression elimination.
context-free grammar.
(c) Live variable analysis can be used for dead code
(c) Deciding if the language generated by a given context-
elimination.
free grammar is empty.
(d) x = 4 * 5 Þ x = 20 is an example of common
(d) Deciding if the language generated by a given context-
subexpression elimination. free grammar is finite.
S3-154 Compiler Design
Here, id is a token that represents an integer and id value ® a) to parse a string with n tokens? [2013, 1 Mark]
represents, the corresponding integer value. For an input
n
‘2 * 3 + 4’, this translation scheme prints. (a) (b) n – 1
2
(a) 2 * 3 + 4 (b) 2 * + 3 4
(c) 2 3 * 4 + (d) 2 3 4 + * (c) 2n – 1 (d) 2n
46. In a simplified computer, the instructions are 49. Consider the following two sets of LR(1) items of an
OP Rj, Ri – Performs Rj OP Ri and stores the result in register LR(1) grammar.
Ri. X ® c.X, c/d X ® c.X, $
OP m, Rj – Performs val OP Ri and stores the result in Rj. val X ® .cX, c/d X ® .cX, $
denotes the content of memory location m. X ® .d, c/d X ® .d, $
MOV m, Ri – Moves the content of memory location m to Which of the following statements related to merging of
register Ri. the two sets in the corresponding LALR parser is/are
MOV, Ri, m – Moves the content of the register Ri to memory false?
location m. 1. Cannot be merged since look aheads are different.
The computer has only two registers, and OP is either ADD 2. Can be merged but will result in S-R conflict.
or SUB. Consider the following basic block: 3. Can be merged but will result in R-R conflict.
t1 = a + b 4. Cannot be merged since goto on c will lead to two
t2 = c + d different sets. [2013, 2 Marks]
t3 = e – t2 (a) 1 only (b) 2 only
t4 = t1 – t3 (c) 1 and 4 only (d) All of these
Assume that all operands are initially in memory. The final
value of the computation should be in memory. What is the 50. Consider the following languages:
{ }
minimum number of MOV instructions in the code generated
for this basic block? [2007, 2 Marks] L1 = 0p 1q 0r | p, q, r ³ 0 |
(a) 2 (b) 3
(c) 5 (d) 6 L2 = {0 p q
1 0 r p, q, r ³ 0, p ¹ r }
47. Consider two binary operators and ¯ with the precedence
Which one of the following statements is false?
of operator ¯ being lower than that of operator . Operator
is right associative while operator ¯ is left associative. [2013, 2 Marks]
Which one of the following represents the parse tree for (a) L2 is context-free
expression (7 ¯ 3 4 3 ¯ 2) ? [2011, 2 Marks] (b) L1 Ç L2 is context-free
(c) Complement of L2 is recursive
(a) ¯ (b) ¯ (d) Complement of L1 is context-free but not regular
2
7
¯
51. Consider the following relational schema.
3 Students (rollno: integer, sname: string)
Courses (courseno: integer, cname: string)
4 ¯ 7
Registration (rollno: integer, courseno: integer,
2 3
3 percent: real)
3
4 Which of the following queries are equivalent to this
query in English?
(c) (d) None of these “Find the distinct names of all students who score more
¯
than 90% in the course numbered 107”
¯ I. SELECT DISTINCT S.sname
7
FROM Students as S, Registration as R
2
WHERE R.rollno = S.rollno AND R.courseno=107
3 AND R.percent > 90
II. Psname (scourseno=107 Ù percent>90
3
4 (Registration > no < Students))
III. {T | $SÎ Students, $RÎ Regist ration
48. What is the maximum number of reduce moves that can (S.rollno=R.rollno
be taken by a bottom-up parser for a grammer with no Ù R.courseno=107 Ù R.percent>90 Ù
epsilon-and unit-production (i.e. of type A ® e and A T.sname=S.sname)}
S3-156 Compiler Design
IV. {<SN> |$SR$RP (<SR, SN>Î Students Ù <SR, 107, 55. The above grammar and the semantic rules are fed to a yacc
RP>Î Registration Ù RP>90)} [2013, 2 Marks] tool (which is an LALR (1) parser generator) for parsing
(a) I, II, III and IV (b) I, II and III only and evaluating arithmetic expressions. Which one of the
(c) I, II and IV only (d) II, III and IV only following is true about the action of yacc for the given
52. For a C program accessing X[i][j][k], the following grammar?
intermediate code is generated by a compiler. Assume that (a) It detects recursion and eliminates recursion
the size of an integer is 32 bits and the size of a character is (b) It detects reduce-reduce conflict and resolves
8 bits. (c) It detects shift-reduce conflict and resolves the conflict
t0 = i * 1024 in favour of a shift over a reduce action
t1 = j * 32 (d) It detects shift reduce conflict, and resolves the conflict
t2 = k * 4 in favour of a reduce over a shift action
t3 = t1 + t0 56. Assume the conflicts in Part (a) of this question are resolved
t4 = t3 + t2 and an LALR(1) parser is generated for parsing arithmetic
t5 = X[t4] expressions as per the given associativity properties does
Which one of the following statements about the source the generated parser realize?
code for the C program is CORRECT? (a) Equal precedence and left associativity; expression is
[2014, Set-2, 2 Marks] evaluated to 7
(a) X is declared as “int X[32][32][8]”. (b) Equal precedence and left associativity; expression is
(b) X is declared as “int X[4][1024][32]”. evaluated to 9
(c) X is declared as “char X[4][32][8]”. (c) Precedence of ‘x’ is higher than that of ‘+’ and both
(d) X is declared as “char X[32][16][2]”. operators are left associative; expression is evaluated
53. Consider the basic block given below. to 7
a=b+ c (d) Precedence of ‘+’ is higher than that of ‘×’ and both
c=a+d operators are left associative; expression is evaluated
d=b+c to 9
e=d-b Statements for Linked Answer Questions 57 and 58:
a=e+b 57. Which one of the following grammars generates the
The minimum number of nodes and edges present in the language
DAG representation of the above basic block respectively L = {ai bj} i ¹ j]? [2006, 2 Marks]
are [2014, Set-3, 2 Marks]
(a) S ® AC | CB (b) S ® aS | Sb |a| b
(a) 6 and 6 (b) 8 and 10
C ® aC b |a|b
(c) 9 and 12 (d) 4 and 4
A ® aA | Î
54. Consider the following languages over the alphabet
B ® bB | Î
S = {0, 1, c}:
(c) S ® AC | CB (d) S ® AC | CB
L1 = {0n1n | n ³ 0}
C ® aC b | Î C ® aC b | Î
L2 = {wcwr |w Î {0, 1}*}
A ® aA | Î A ® aA |a
L3 = {wwr |w Î {0, 1}*}
B ® Bb | Î B ® bB |b
Here, wr is the reverse of the string w. Which of these
languages are deterministic Context-free languages? 58. In the correct grammar above, what is the length of the
[2014, Set-3, 2 Marks] derivation (number of steps starting from S) to generate the
(a) None of the languages string albm with l ¹ m? [2006, 2 Marks]
(b) Only L1 (a) max (l, m) + 2 (b) l + m + 2
(c) Only L1 and L2 (c) l + m + 3 (d) max (l, m) + 3
(d) All the three languages Statements for Linked Answer Questions 59 and 60 :
Consider the CFG with {S, A, B} as the non-terminal alphabet,
Linked Answer Type MCQs {a, b} as the terminal alphabet, S as the start symbol and the
following set of production rules [2007, 2 Marks each]
Statements for Linked Answer Questions 55 and 56: S ® aB S ® bA
Consider the following expression grammar. The semantic rules B®b A®a
for expression evaluation are stated next to each grammar B ® bS A ® aS
production. [2005, 2 Marks] B ® aBB A ® bAA
E ® number E.val = number.val 59. Which of the following strings is generated by the grammar?
| E ‘+’ E E(1).val = E(2).val + E(3).val (a) aaaabb (b) aabbbb
| E ‘×’ E E(1).val = E(2).val × E(3).val (c) aabbab (d) abbbba
Compiler Design S3-157
60. For the correct answer strings to Q. above, how many global int i = 100, j = 5;
derivation trees are there? void P (x) {
(a) 1 (b) 2 int i = 10;
(c) 3 (d) 4 print (x + 10);
Statements for Linked Answer Questions 61 and 62 : i = 200;
j = 20;
For the grammar below, a partial LL (1) parsing table is also
print (x);
presented along with the grammar. Entries that need to be filled
}
are indicated as E1, E2 and E3. e is the empty string, $ indicates main () {P (i + j);}
end of input and | separates alternate right hand sides of 63. If the programming language uses static scoping and call
productions. [2012, 2 Marks each]
by need parameter passing mechanism, the values printed
S®aAbB| bAaB|e
by the above program are [2003, 2 Marks]
A®S
(a) 115, 220 (b) 25,220
B®S
(c) 25,15 (d) 115, 105
64. If the programme language uses dynamic scoping and
a b $
call by name parameter passing mechanism, the values
S E1 E2 S®e
printed by the above program are [2003, 2 Marks]
A A®S A®S error (a) 115, 220 (b) 25, 220
B B® S B® S E3 (c) 25, 15 (d) 115, 105
61. The FIRST and FOLLOW sets for the non-terminals A and
B are Numerical Answer Questions
(a) FIRST (A) = {a, b, e} = FIRST (B)
65. Consider the syntax directed translation scheme (SDTS)
FOLLOW (A) = {a, b}
FOLLOW (B) = {a, b, $} given in the following. Assume attribute evaluation with
(b) FIRST (A) = {a, b, $} bottom-up parsing, i.e., attributes are evaluated
FIRST (B) = {a, b, e} immediately after a reduction. [2000, 5 Marks]
FOLLOW (A) = {a, b} E ® E1 * T {E.val = E1.val * T. val}
FOLLOW (B) = {$} E ® T {E.val = T. val}
(c) FIRST (A) = {a, b, e} = FIRST (B) T ® F – T1 {T.val = F.val – T1. val}
FOLLOW (A) = {a, b} T ® F {T.val = F. val}
FOLLOW (B) = Æ
F ® 2 {F.val = 2}
(d) FIRST (A) = {a, b,} = FIRST (B)
FOLLOW (A) = {a, b} F ® 4 {F.val = 4}
FOLLOW (B) = {a, b,} (a) Using this SDTS, construct a parse tree for the
62. The appropriate entries for E1, E2 and E3 are expression
(a) E1 : S ® aAbB, A ® S 4–2–4*2
E2 : S ® bAaB, B ® S and also compute its E.val.
E3 : B ® S (b) It is required to compute the total number of
(b) E1 : S ® aAbB, S ® e reductions performed to parse a given input. Using
E2 : S ® bAaB, S ® e
synthesized attributes only, modify the SDTS given,
E3 : S ® e
(c) E1 : S ® aAbB, S ® e without changing the grammar, to find E.red, the
E2 : S ® bAaB, S ® e number of reductions performed while reducing an
E3 : B ® S input to E.
(d) E1 : A ® S, S ® e 66. Consider a paging hardware with a TLB. Assume that the
E2 : B ® S, S ® e entire page table and all the pages are in the physical
E3 : B ® S memory. It takes 10 milliseconds to search the TLB and 80
milliseconds to access the physical memory. If the TLB hit
Common Data MCQs ratio is 0.6, the effective memory access time (in milliseconds)
Common Data for Questions 63 and 64 is _________. [2014, Set-3, 2 Marks]
The following program fragment is written in a progrmming
language that allows global variable and does not allow nested
declrations of functions.
S3-158 Compiler Design
18. (a) The grammar has production S " iCtSS1 here the right of the recognizer, while the space bound goes up to n
hand side of grammar has the same symbol as left side. 3 in general in order to store the parse trees. In fact it
So the grammar is left recursive. The grammar is not would probably be most efficient to implementthe
ambiguous. algorithm to do just a look-ahead of 1. To implement
the full look-ahead for any k would be more costly
19. (a) LL(1) parsers can recognize the regular grammars also
inprogramming effort and less efficient overall since
LL(1) is subset of LR(1) or CLR grammar so it also
so few programming languages need the extra look-
recognizes regular sets. So both accept regular
ahead. Improving transformations are performed on a
grammar. target-specific representation of the program. for both
P: regular can be left or right regular for left regular a existing and proposed architectures, to gather trace
left recursion elimination can be done. information for code improvements are often applied
Q: regular set is set of string represented by a regular to a high-level intermediate languagethough it can be
expression for which a dfa can be created so a LL(1) applied to the source level also but it can impact the
parser is available so is LR(1) grammar. effectiveness of code improvements
I. Statement is true since there are some parsers which
20. (b) Code optimizations are carried out on the intermediate
take 0(n log2n) time for parsing.
code because program analysis is more accurte on
II. Completely false, since there is no use of stack which
intermediate code than on machine code.
is required for recursion.
21. (d) It is a production p that may be used for reduction in
afuture step along with a position in the sentential III. False
form where, the right hand side of the production may IV. True since both types of optimizations are applied
befound. 25. (b) Symbol table is a data structure used by a language
translator such as a compiler or interpreter, where each
A “handle” of a string is a substring that matches the
identifier in a program's source code is associated with
RHS of a production and whose reduction to the non-
information relating to its declaration or appearance in
terminal (on the LHS of the production) represents
the source, such as its type, scope level and sometimes
one step along the reverse of a rightmost derivation
its location.
toward reducing to the start symbol. Symbol table
If S ® * aAw ®* abw, then A ® b in the position In a symbol table is a data structure used by a language
following a is a handle of abw. translator such as a compiler or interpreter, where each
In such a case, it is suffice to say that the substring b identifier in a program's source code is associated with
is a handle of abw, if the position of b and the information relating to its declaration or appearance in
corresponding production are clear. the source, such as its type, scope level and sometimes
Consider the following grammar: its location.
E ® E + E | E * E | (E) | id Implementation
and a right-most derivation is as follows: A common implementation technique is to use a hash
E ® E + E ® E+ E * E ® E + E * id3 ® E + id2 * id3 ® table. A compiler may use one large symbol table for
id1 + id2 * id3 all symbols or use separated, hierarchical symbol
22. (a) I. Statement is false since global variables are tables for different scopes. There are also trees, linear
required for recursions with static storage. This lists and self-organizing lists which can be used to
is due to unavailability of stack in static storage. implement symbol table.It also simplifies the
II. This is true classification of literals in tabular format.
III. In dynamic allocation heap structure is used, so An object file will contain a symbol table of the
it is false. identifiers it contains that are externally visible. During
IV. False since recursion can be implemented. the linking of different object files, a linker will use
V. Statement is completely true. So only II & V are these symbol tables to resolve any unresolved
true. references.
A symbol table may only exist during the translation
Hence (a) is correct option.
process, or it may be embedded in the output of that
23. (b) LALR parser is reduced form of CLR or LR(1) parser,
process for later exploitation, for example, during an
LALR parser uses the LR(1) items of CLR parser & of
interactive debugging session, or as a resource for
any shift reduce conflicts are there then it is due to
formatting a diagnostic report during or after execution
LR(1) parser.
of a program.
24. (b) The time bounds for the parser are the same as those While reverse engineering an executable, many tools
S3-160 Compiler Design
refer to the symbol table to check what addresses have 20000190 t AT91F_US_TxReady
been assigned to global variables and known
functions. If the symbol table has been stripped or 200001c0 t AT91F_US_PutChar
cleaned out before being converted into an executable, 200001f8 T AT91F_SpuriousHandler
tools will find it harder to determine addresses or
20000214 T AT91F_DataAbort
understand anything about the program.
At that time of accessing variables and allocating 20000230 T AT91F_FetchAbort
memory dynamically, a compiler should perform many 2000024c T AT91F_Undef
works and as such the extended stack model requires
the symbol table. 20000268 T AT91F_UndefHandler
A C compiler that parses this code will contain at least 20000284 T AT91F_LowLevelInit
following symbol table entries:
2.00E+05 t AT91F_DBGU_CfgPIO
Symbol name Type Scope
Bar function, double extern 2000030c t AT91F_PIO_CfgPeriph
X double function parameter 20000360 t AT91F_US_Configure
Foo function, double global
Count int function parameter 200003dc t AT91F_US_SetBaudrate
Sum double block local 2000041c t AT91F_US_Baudrate
I int for-loop statement
200004ec t AT91F_US_SetTimeguard
In addition, the symbol table will also contain entries
generated by the compiler for intermediate expression 2000051c t AT91F_PDC_Open
values (e.g., the expression that casts the i loop variable 2000059c t AT91F_PDC_DisableRx
into a double, and the return value of the call to function
bar()), statement labels, and so forth. 200005c8 t AT91F_PDC_DisableTx
As another example, the symbol table of a small 200005f4 t AT91F_PDC_SetNextTx
program is listed below. The table itself was generated
20000638 t AT91F_PDC_SetNextRx
using the GNU binutils'nm utility. There is one data
symbol, (noted by the “D” type), and many functions 2000067c t AT91F_PDC_SetTx
(self defined as well as from the standard library). The 200006c0 t AT91F_PDC_SetRx
first column is where the symbol is located in the
memory, the second is “The symbol type” and the 20000704 t AT91F_PDC_EnableRx
third is the name of the symbol. By passing suitable 20000730 t AT91F_PDC_EnableTx
parameters, the symbol table was made to sort on basis
of address.
2000075c t AT91F_US_EnableTx
20000788 T __aeabi_uidiv
Example table
20000788 T __udivsi3
Address Type Name
20000884 T __aeabi_uidivmod
00000020 a T_BIT
2000089c T __aeabi_idiv0
00000040 a F_BIT
2000089c T __aeabi_ldiv0
00000080 a I_BIT
2000089c T __div0
20000004 t irqvec
200009a0 D _data
20000008 t fiqvec
200009a0 A _etext
2000000c t InitReset
200009a0 D holaamigosh
20000018 T _main
200009a4 A __bss_end__
20000024 t End
20000030 T AT91F_US3_CfgPIO_useB 200009a4 A __bss_start
26. (c) S ® aSa | bS | C 31. (b) + is right associative (with right recursion from S)
The above grammar is LL (1) because, is left associative (with left recursion from T)
First [aSa] Ç first [bS] = (a) Ç (b) = f 32. (a) Dynamic memory allocation is not performed during
compilation.
First [bS] Ç first [c] = (b) Ç (c) = f
It is performed during sun time not during complete
First [c] Ç first [aSa] = (c) Ç (a) = f
time
As the above grammar is LL (1), also LR (1) because 33. (c) Intermediate code makes it easy to retarget the
LL (1) grammar is always LR (1) grammar. compiler to generate code for newer and different
27. (c) In a compiler, keyboards of a language are recognized processors.
during the lexical analysis of the program. Typically, 34. (d) Heap is essential to allocate memory for data
the lexical analysis phase of compilation breaks the structures at runtime, not for recurssion
input text up into sequences of lexemes that each 35. (a) There is no algorithm for ambiguity of CFG
belongs to some particular token type that's useful in
later analysis. Consequently, keywords are usually first PROBLEM BASED MCQs
recognized during lexical analysis in order to make
36. (c) A token is strictly a string of characters that the
parsing easier. Since parsers tend to be implemented
compiler replaces with another string of characters.
by writing context-free grammars of tokens rather than
Token are defined as a sort of search and replace.
of lexemes (that is, the category of the lexeme rather
Token can be used for common phrases, page
than the contents of the lexeme), it is significantly
elements, handy shortcuts, etc. Token are defined
easier to build a parser when keywords are marked
with either the define or replace tags and can use
during lexing.
single or paired tag syntax.
28. (a) Lexical analysis is the first step in compilation. In lexical
Examples
analysis, program is divided into tokens. Lexical
<define%bgcolor%#ccffcc>
analyzers are typically based on finite state automata.
<define (c) & copy;>
Tokens can typically be expressed as different regular
<define [email] joe@ cool.com>
expressions:
<:replace [mailto] <a hre =
An identifier is given by [a-zA-Z][a-zA-Z0-9]*
mailto: [email] > [email] </a>:>
The keyword if is given by if.
37. (d) 1. Px = newQ();
Integers are given by [+-]?[0-9]+.
2. Qy = newQ();
29. (d) The statement:–
3. Pz = newQ();
x = 4 × 5 Þ x = 20 4. x : f (1); print 2 # i = 2
‘is an example of common subexpression elimination.] 5. ((P) y) : f (1);
is False. 6. z : f (1) print 2 # i = 2
Explanation: but line 5. will print 2 because typecast to parent
Common Subexpression elimination is a compiter class can't prevent over ridding. So function f(1) of
optimization that searches for instances of identical class Q will be called not f (1) of class P.
expressions (that evaluate to same value) and Hence (d) is correct option.
analyses whether it is worthwhile replacing them 38. (d) S " TR
with a single variable holding the computed value. R "+ T {pr int(' + ');}R e
example: T " num{print(num.val);}
Z1 = (x + y) + 1; Given string 9 + 5 + 2
Z2 = (x + y) + b; S " TR
Z3 = (x + y) + c; T + TR {print(+);}
Above code segment may be transformed to: T+T+T {print(+);}
tmp = x + y; 9 +T+T {print(9);}
Z1 = tmp + a; 9 +5+T {print(5);}
Z2 = tmp + b; 9 +5+2 {print(2);}
Z3 = tmp + c; So ++ 952 is printed
So, the addition (x + y) is performed only once. Hence (d) is correct option.
It is worth noting that the given option (D) 39. (d) In 3-address code we use temporary variables to
x = 4 × 5 Þ x = 20 reduce complex instructions so here
is called the “constant folding” technique of compiler t1 = Y t2 = Z
optimization. t3 = t1 + t2
30. (d) Neither a shift reduce nor a reduce-reduce conflict. x = t3
Hence (d) is correct option.
S3-162 Compiler Design
40. (c) The parse tree would be 43. (c) The grammar is
E S® S * E
E # T S®E
# T & F E ®F+E
E T
F E ®F
T T & F
F ® id
F F
LR(0) items corresponding to the grammar above.
num num num num num
(2) (3) (5) (6) (4) 1. S®S*E
Now we evaluate bottom up 2. E ® F. + E
T
3. E ® F + .E
T
Now, S ® S * .E ...(i)
T & F
T & F S ® .E ...(ii)
F 3+ 5 = 8 F 6 + 4 = 10 E ®F+ .E ...(iii)
num num From Eqs. (i) and (iii),
num num
(3) (5) (6) (4) We see that in both the productions, the Dot is left to
E
E. Hence, belonging to the same set in canonical set of
items for the grammar.
E T
# 44. (a) The predictive parser table is given as.
T
T & F 2 + 8 = 10
No n ) id $
F
F termin al
num num S S”FR
(3) num
(5) F F”id
(3)
E R R”)SR” ! R”!
47. (b) Let us consider the given expression (7¯343¯2). 4. Domain Calculus Domain Calculus is equivalent
Since the precedence of is higher, the sub-expression to relational algebra and provide distinct value
(343) will be evaluated first. In this sub-expression, for the query. true.
43 would be evaluated first because is right to left Hence, all queries are equivalent to this query in
associative. So the expression is evaluated as English, (a) I, II, III and IV.
((7¯(3(43)))¯2). Also, note that among the two ¯ 52. (a) X is declared as “int × [32] [32] [8]”
operators, first one is evaluated before the second 53. (a) The given block is
one because the associativity of ¯ is left to right. a=b+c
48. (c) The maximum number of reduce moves that can be c=a+d=b+c+d
taken by a bottom-up parser for a grammar with no d=b+c
epsilon and unit production (i.e., of type A ® e and = b + b + c + d = 2b + c + d
A ® a) to parse a string with n taken (c) 2n – 1 e=d–b=b+b+c+d–b=b+c+d
49. (d) a = e + b = b + b + c + d = 2b + c + d
50. (d) L1 = {0p1q,0r| p, q, r ³ 0} Therefore e and c are same, a and d are same.
L2 = {0p1q0r| p, q, r ³ 0, p ¹ r} The DAG generated is as follows :
(a) L2 is context Free – true
We can accept, or reject L2 with single stack. + d, a
Insert P 0's into stack skip q 1's. c, e
For each 0 corresponding to r, remove 0 from stack. + a
(b) L1 Ç L2 is context Free – true +
Here L1 Ç L2 = L2 which is context Free.
(c) Complement of L2 is recursive – true
L2 is Context-Free language c
d b
Complement of CFL may or may not be CFL.
Complement by CFL is definately recursive. The maximum number of nodes and edges is (6, 6)
(d) Complement of L1 is Context Free, but not regular 54. (c) L1 and L2 have deterministic push down automata
false. but for L3 only not-deterministic PDA is possible.
So L3 is not deterministic.
L1 = {0p qq 0r }
p,q,r ³ 0 LINKED ANSWER TYPE MCQs
0 0 55. (c) Yacc tool is used to create a LALR(1) parser. This parser
0 1 0 can detect the conflicts but to resolve the conflicts it
actually prefers shift over reduce action.
1 56. (b) The grammar has equal precedence and it is also
ambiguous. Since LALR(1) parser prefer shift over
0, 1 reduce so + operation will be executed here before ). 2
Which is regular, + 1 = 3 & 3 # 3 = 9 also the operators are right
associative.
0 1 0 Hence (b) is correct option.
57. (d) In the language
L1= 0 1 0
language L = {ai bj | i ¹ j}
1 The expression i ¹ j indicates that language L is a
language in which number of a ¹ number of b.
Here, we need to search for a language in which
Regular number of a ¹ number of b.
Considering the options:
Hence, the answer is (d). Options (a)
51. (a) “Find the distinct names of all students who score S ® AC | CB
more than 90% in the course numbered 107”. C ® aCb | a| b
1. SQL Query Condition would give all sname A ® aA | Î
having score > 90 and attending course no. 107 B ® Bb | Î
and (a), S ® (C) B ® a(b) ® aBb ® ab
DISTINCT S.sname will give distinct student Here, the number of a = number of b, hence, it is not
names, true the required grammar.
2. Relational Algebra psname gives projection of Option (b)
all students meeting the condition and p gives S ® as | Sb | a | b
DISTINCT value, true S ® as ® abB
3. Tuple Calculus Gives DISTINCT student name
Here, number of a = number of b, hence it is not the
having score > 90 and course No is 107. true
required grammar.
S3-164 Compiler Design
Option (c) 61. (a) First (S) = first (aAbB) È First (bAaB) È Î
S ® AC | CB = {a} È {b} È Î
C ® aC b| Î
A ® aA | Î = {a, b,Î}
B ® Bb | Î
First (A) = First S = {a, b,Î}
S(C)B ® acbB ® ab
Here, number of a = number of b, hence it is not the First (B) = First S = {a, b,Î}
required grammar. Follow (S) = {$} È follow (A) È follows (B)
Option (d) Follow (A) = {a, b}
S ® AC | CB Follow (B) = Follow (S) = {$, a, b}
C ® aC b| Î 62. (c) Entry E for [S, a] = {S ® aAbB, S ® Î }
A ® aA | a S ® aAbB
B ® Bb | b First (aAbB) = {a}
Consider the production S ® aAbB
First (bAaB) = {b}
S ® AC | CB
Put (S ® Î ) production as per follow (S)
Applying, C ® Î Follow (S) = {a, b, $}
We get S ® A|B Hence, (S ® Î ) will come in [S, a], [S, b] and [S, $]
Now, applying A or B, S generates a^n.b^n. So, Entry E2 for [S, b] = {S ® bAaB, S ® Î }
L = {aibj | i ¹ j} Entry E3 for [B, $] = {B ® S}
Now, consider the production, S ® AC | CB. If the Production {B ® S} will come in as per
production C ® acb is applied then, it generates First (S) = {a, b, Î }
a^n,b^n. Hence, put B ® S in [B, a] [B, b]
Now, applying either A or B it will give that number of First (S) contains Î so consider [S, $]
a ¹ number of b. Put [B ® S] in [S, $]
58. (a) It is very clear from the previous solution that the no. COMMON DATA MCQs
of steps required depend upon the no. of a' s & b ' s
which ever is higher & exceeds by 2 due to S " AC CB 63. (d) In static scoping the variables are initialized at
& C "! compile time only
So i = 100 &j = 5
So max(l , m) + 2
P (i + j) = P (100 + 5) = P(105)
Hence (a) is correct So x = 105
59. (c) Let solve out to get the string generated by the x + 10 = 105 + 10 = 115
grammar. So 115 & 105 will be printed.
S ® aB Hence (d) is correct option.
S ® aaBB 64. (b) In dynamic scoping, the local values are considered
S ® aabB & variables are initialized at run time.
S ® aabbS Since x = i + j & in P (x)
S ® aabbaB i = 200 &j = 20 x = 200 + 20 = 220
S ® aabbab & printing (x + 10)
We get the string as aabbab. 9. = i + j + 10
60. (b) The string received is aabbab. = 10 + 5 + 10 = 25
We can total 2 derivation trees: Leftmost derivation Hence (b) is correct option
and rightmost derivation. NUMERICAL ANSWER QUESTIONS
65. (a) E.val = 12
S
S (b) E ® E1 * T {E.red = E1.red + T. red + 1}
E®T {E.red = T.red + 1}
T ® F – T1 {T.red = F.red + T1.red + 1}
a a B T®F {T.red = F.red + 1}
B
F®2 {F.red = 1}
B F®4 {F.red = 1}
B a
a B 66. 122
B Tave = H1 × (TTLB + TM) + (1 – H1) × (TTLB + 2 × TM)
S
b TTLB = 10 ms
S b b
b TM = 30 ms
B
A a H1 = 0.6
b
Tave = 0.6 X ( 10 + 80) + (1 – 0.6) (10 + 2X80)
= 0.6 X 90 + 0.4X 170
a b = 122 ms
Operating System S3-165
7
Chapter
Operating System
Quick Revision Material
The Process
Process memory is divided into four sections:
• The text section comprises the compiled program
code, read in from non-volatile storage when the
program is launched.
• The data section stores global and static variables,
allocated and initialized prior to executing main.
• The heap is used for dynamic memory allocation, and
Process Control Block
is managed via calls to new, delete, malloc, free, etc.
For each process there is a Process Control Block, PCB, which
• The stack is used for local variables. Space on the stores the following (types of) process-specific information.
stack is reserved for local variables when they are Process State - Running, waiting, etc., as discussed
declared (at function entrance or elsewhere, depending above.
on the language ), and the space is freed up when Process ID, and parent process ID.
CPU registers and Program Counter -
the variables go out of scope.
These need to be saved and restored when swapping
Process State processes in and out of the CPU.
Processes may be in one of 5 states, as shown in Figure CPU-Scheduling information - Such as priority information
and pointers to scheduling queues.
• New - The process is in the stage of being created.
Memory-Management information - E.g. page tables or
• Ready - The process has all the resources available
segment tables.
that it needs to run, but the CPU is not currently Accounting information - user and kernel CPU time
working on this process's instructions. consumed, account numbers, limits, etc.
• Running - The CPU is working on this process's I/O Status information - Devices allocated, open file
instructions. tables, etc.
• Waiting - The process cannot run at the moment, process state
Progress
of Q 1 2
Release
A P and Q
A wait A
Required Release
B
Get A
B deadlock
Required 3 inevitable P and Q
wait B
5
Get B
4
6
The six paths depicted in above correspond to the following. other resource. Deadlock is now inevitable.
1. Q acquires both resources, then releases them. P can 5. P acquires both resources, then Q requests B. Q is
operate freely later. blocked until the resources are released, but can then
2. Q acquires both resources, then P requests A. P is operate freely.
blocked until the resources are released, but can then 6. P acquires both resources, then releases them. Q can
operate freely. operate freely later.
3. Q acquires B, then P acquires A, then each requests the Contrast the above example with the situation where P does
other resource. Deadlock is now inevitable. not need the resources simultaneously: P has the form get A,
4. P acquires A, then Q acquires B, then each requests the ... release A, ..., get B, ..., release B, and Q is defined as
before.
Progress
of Q
1 2 3
Release
A
4
A Release P and Q
Required B wait A
P and Q
Get A
wait B
B
Required
5
Get B
6
Progress
Get A Release A of P
Get B Release B
A Required B Required
= both P and Q wait resource A
= possible progress path of P and Q.
= both P and Q wait resource B Horizontal portion of path indicates P is excuting
and Q is waiting.
VErtical portion of path indicates Q is executing
and P is waiting.
Example of No Deadlock
Again the six paths show the possible execution sequences. (ii) Avoidance involves making dynamic choices that
Conditions for Deadlock guarantee prevention.
Three policy conditions are necessary for deadlock to be (iii) Detection and recovery involves recognising when
possible. deadlock has occurred, and trying to recover.
(i) Mutual exclusion : Only one process may use a resource Deadlock Prevention
at one time. We can prevent deadlock from occurring by adopting either an
(ii) Hold and wait: A process may hold some resources while indirect policy that disallows one of the three necessary
waiting for others. conditions, or a direct policy that disallows sets of processes
(iii) No preemption: No process can be forced to release a resource. that can exhibit a circular wait.
(iv) Circular wait: A closed chain of processes exists, such
Deadlock Avoidance
that each process is blocked waiting for a resource held
by another process in the set. Deadlock avoidance Simplest algorithm - each process tells max
number of resources it will ever need. As process runs, it
Three approaches exist for dealing with deadlock:
requests resources but never exceeds max number of resources.
(i) Prevention involves adopting a static policy that disallows System schedules processes and allocates resoures in a way
one of the four conditions above. that ensures that no deadlock results.
S3-168 Operating System
CPU SCHEDULING
Process Arrival Time Execute Time Service Time
Almost all programs have some alternating cycle of CPU
P0 0 5 0
number crunching and waiting for I/O of some kind.
P1 1 3 5
(Even a simple fetch from memory takes a long time
relative to CPU speeds.) P2 2 8 8
P3 3 6 16
Preemptive Scheduling
CPU scheduling decisions take place under one of four
P0 P1 P2 P3
conditions:
1. When a process switches from the running state to
the waiting state, such as for an I/O request or 0 5 8 16 22
invocation of the wait( ) system call. First come first serve
2. When a process switches from the running state to Shortest Job First (SJF)
the ready state, for example in response to an Best approach to minimize waiting time.
interrupt. Impossible to implement
3. When a process switches from the waiting state to Processer should know in advance how much time
process will take.
the ready state, say at completion of I/O or a return Wait time of each process is following
from wait( ). Process Wait Time :
4. When a process terminates. Service Time - Arrival Time
P0 3-0=3
If scheduling takes place only under conditions 1 and 4,
P1 0-0=0
the system is said to be non-preemptive, or cooperative. P2 16 - 2 = 14
Under these conditions, once a process starts running it P3 8-3=5
keeps running, until it either voluntarily blocks or until it Average Wait Time: (3+0+14+5) / 4 = 5.50
finishes. Otherwise the system is said to be preemptive.
Process Arrival Time Execute Time Service Time
Dispatcher
P0 0 5 0
The dispatcher is the module that gives control of the
CPU to the process selected by the scheduler. This P1 1 3 3
function involves: P2 2 8 8
• Switching context. P3 3 6 16
• Switching to user mode.
• Jumping to the proper location in the newly loaded P0 P1 P2 P3
program.
The dispatcher needs to be as fast as possible, as it is
run on every context switch. The time consumed by the 0 3 8 16 22
dispatcher is known as dispatch latency. Shortest Job First
Scheduling Algorithms Priority Based Scheduling
Each process is assigned a priority. Process with highest
First Come First Serve (FCFS) priority is to be executed first and so on.
Jobs are executed on first come, first serve basis. Processes with same priority are executed on first come
first serve basis.
Easy to understand and implement.
Priority can be decided based on memory requirements,
Poor in performance as average wait time is high. time requirements or any other resource requirement.
Wait time of each process is following Wait time of each process is following
Process Wait Time : Service Time - Arrival Time Process Wait Time :
Service Time - Arrival Time
P0 0 - 0 = 0
P0 0 - 0 = 0
P1 5 - 1 = 4 P1 3 - 1 = 2
P2 8 - 2 = 6 P2 8 - 2 = 6
P3 16 - 3 = 13 P3 16 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.55 Average Wait Time: (0+2+6+13) / 4 = 5.25
Operating System S3-169
Step 2 If the reference was invalid, terminate the process. Write new page in the frame of free pool, mark the page
If it was valid, but pagehave not yet brought table and restart the process.
in, page in the latter. Now write the dirty page out of disk and place the frame
Step 3 Find a free frame. holding replaced page in free pool.
Least Frequently Used (LFU) algorithm
Step 4 Schedule a disk operation to read the desired
page into the newly allocated frame. Page with the smallest count is the one which will be
selected for replacement.
Step 5 When the disk read is complete, modify the internal This algorithm suffers from the situation in which a page
table kept with theprocess and the page table to is used heavily during the initial phase of a process, but
indicate that the page is now in memory. then is never used again.
Step 6 Restart the instruction that was interrupted by Most Frequently Used (MFU) algorithm
the illegal address trap. The process can now This algorithm is based on the argument that the page
access the page as though it had always been in with the smallest count was probably just brought in and
memory. Therefore, the operating system reads has yet to be used.
the desired page into memory and restarts the
process as though the page had always been in I/O SYSTEM
memory. I/O management is a major component of operating
system design and operation
Page is on
• Important aspect of computer operation
backing store
3 • I/O devices vary greatly
Operating • Various methods to control them
System
• Performance management
reference 2 • New types of devices frequent
1 trap • Ports, busses, device controllers connect to various
Load devices
i
M 6 Direct Memory Access
Used to avoid programmed I/O (one byte at a time) for
Free frame
Restart
5 4 large data movement
instruction
Reset page Requires DMA controller
table Bring in Bypasses CPU to transfer data directly between I/O
Physical missing device and memory
Memory page OS writes DMA command block into memory
Page Fault Trap • Source and destination addresses
Page Replacement Algorithm • Read or write mode
• Count of bytes
Page replacement algorithms are the techniques using which • Writes location of command block to DMA controller
Operating System decides which memory pages to swap out, • Bus mastering of DMA controller - grabs bus from
write to disk when a page of memory needs to be allocated. CPU
Paging happens whenever a page fault occurs and a free page • Cycle stealing from CPU but still much more efficient
cannot be used for allocation purpose accounting to reason • When done, interrupts to signal completion
that pages are not available or the number of free pages is • Version that is aware of virtual addresses can be even more
lower than required pages.
efficient - DVMA
First In First Out (FIFO) algorithm
CPU
Oldest page in main memory is the one which will be 1 I/O controller
selected for replacement.
device driver initiates I/O 2
Optimal Page algorithm initiates I/O
An optimal page-replacement algorithm has the lowest CPU executing checks for
interrupts between instructions 3
page-fault rate of all algorithms. An optimal page-
replacement algorithm exists, and has been called OPT or input ready, output
CPU receiving interrupt, 4
MIN. transfers control to complete, or error
7
Replace the page that will not be used for the longest interrupt handler generates interrupt signal
period of time . Use the time when a page is to be used. 5
Least Recently Used (LRU) algorithm interrupt handler processes
Page which has not been used for the longest time in main data, returns from interrupt
memory is the one which will be selected for replacement. 6
Page Buffering algorithm CPU resumes processing
of interrupted task
To get process start quickly, keep a pool of free frames.
On page fault, select a page to be replaced. Interrupt-Driven I/O Cycle
Operating System S3-171
12. Using a larger block size in a fixed block size file system Which one of the following is true?
leads to [2003, 1 Mark] (a) The implementation may not work, if context switching
(a) better disk throughput but poorer disk space is disabled in P
utilization (b) Instead of using fetch-and-set, a pair of normal load/
(b) better disk throughput and better disk space store can be used
utilization (c) The implementation of V is wrong
(c) poorer disk throughput but better disk space (d) The code does not implement a binary semaphore
utilization 17. List I contains some CPU scheduling algorithms and List II
(d) poorer disk throughput and poorer disk space contains some applications. Match entries in List I to entries
utilization in List II using the codes given below the lists.
13. Consider the following statements with respect to user-
level threads and kernel-supported threads: List I List II
[2004, 1 Mark] Guaranteed
1. Context switch is faster with kernel-supported threads P. Gang Scheduling 1.
Scheduling
2. for user-level threads, a system call can block the
entire process Rate Monotonic Real-time
Q. 2.
3. Kernel supported threads can be scheduled Scheduling Scheduling
independently R. Fair Share 3. Thread Scheduling
4. User level threads are transparent to the kernel
Which of the above statements are true? Codes [2007, 1 Mark]
(a) 2, 3 and 4 (b) 2 and 3 (a) P - 3, Q - 2, R - 1 (b) P - 1, Q - 2, R - 3
(c) 1 and 3 (d) 1 and 2 (c) P - 2, Q - 3, R - 1 (d) P - 1, Q - 3, R - 2
14. The minimum number of page frames that must be 18. Consider the following statements about user level threads
allocated to a running process in a virtual memory and kernel level threads: [2007, 1 Mark]
environment is determined by [2004, 1 Mark] Which one of the following statements if false?
(a) the instruction set architecture (a) Context switch time is longer for kernel level threads
(b) page size than for user level threads
(c) physical memory size (b) User level threads do not need any hardware support
(d) number of processes in memory (c) Related kernel level threads can be scheduled on
15. A computer system supports 32-bit virtual addresses as well different processors in a multi-processor system
as 32-bit physical addresses. Since, the virtual address space
(d) Blocking one kernel level thread blocks all related
is of the same size as the physical address space, the
threads
operating system designers decide to get rid of the virtual
19. A virtual memory system uses First In First Out (FIFO) page
memory entirely. Which one of the following is true?
replacement policy and allocates a fixed number of frames to
[2006, 1 Mark]
a process. Consider the following statements:
(a) Efficient implementation of multi-user support is no
longer possible P: Increasing the number of page frames allocated to a
(b) The processor cache organization can be made more process sometimes increases the page fault rate.
efficient now Q: Some programs do not exhibit locality of reference.
(c) Hardware support for memory management is no longer Which one of the following is true? [2007, 2 Marks]
needed (a) Both P and Q are true, and Q is the reason for P
(d) CPU scheduling can be made more efficient now (b) Both P and Q are true, and Q is not the reason for P
16. The atomic fetch-and-set x, y instruction unconditionally (c) P is false but Q is true
sets the memory location x to 1 and fetches the old value of (c) Both P and Q are false
x in y without allowing any intervening access to the memory 20. Two processes P1 and P2, need to access a critical section
location x. Consider the following implementation of P and V of code. Consider the following synchronization construct
functions on a binary semaphore S. [2006, 2 Marks] used by the processes:
void P (binary_semaphore *S) { /* P1 */ /* P2 */
unsigned y; while (true) { while (true){
unsigned *x = & (S -> value); wants1 = true; wants2 = true;
do { while while (wants 1 = = true);
fetch-and-set x, y; (wants2 = = true); /* Critical
} while (y); /* Critical Section */
} Section */ wants2 = false;
void V (binary_semaphore *S) { wants1 = false; } /* Remainder section */
s - > value = 0; } (/* Remainder Section)
}
S3-174 Operating System
Here, wants1 and wants2 are shared variables, which are Now consider the following statements:
initialized to false, 1. If a process makes a transition D, it would result in
Which one of the following statements is true about the another process making transition A immediately.
above construct? [2007, 2 Marks] 2. A process P2 is blocked state can make transition E
(a) it does not ensure mutual exclusion while another process P1 is in running state.
(b) it does not ensure bounded waiting 3. The operating system uses pre-emptive scheduling.
(c) it requires that processes enter the critical section in 4. The operating system uses n on-pre-emptive
strict alternation scheduling.
(d) it does not prevent deadlocks, but ensures mutual Which of the above statements are true?
exclusion (a) 1 and 2 (b) 1 and 3
21. Which of the following is not true for deadlock prevention (c) 2 and 3 (d) 2 and 4
and deadlock avoidance schemes? [2008, 1 Mark] 27. The enter _CS() and leave_CS() functions to implement
(a) In deadlock prevention, the request for resources is critical section of a process are realized using test-and-set
always granted, if the resulting state is safe instruction as follows [2009, 2 Marks]
(b) In deadlock avoidance, the request for resources is void enter_CS(X)
always granted, if the resulting state is safe {
(c) Deadlock avoidance is less restrictive than deadlock while (test-and-sex (X));
prevention }
(d) Deadlock avoidance requires knowledge of resource void leave_CS(X)
requirement a priori {
22. A multilevel page table is preferred in comparison to a single X = 0;
level page table for translating virtual address to physical }
address because [2008, 1 Mark] In the above solution, X is a memory location associated
(a) it reduces the memory access time to read or write a with the CS and is initialized to 0. Now, consider the following
memory location statements:
(b) it helps to reduce the size of page table needed to 1. The above solution to CS problem is deadlock-free.
implement the virtual address space of a process 2. The solution is starvation-free.
(c) it is required by the translation look-aside buffer 3. The processes enter CS in FIFO order.
(d) it helps to reduce the number of page faults in page 4. More than one processes can enter CS at the same
replacement algorithms time.
23. Which of the following system calls results in the sending Which of the above statements is true?
of SYN packets? [2008, 2 Marks] (a) 1 only (b) 1 and 2
(a) Socket (b) Bind (c) 2 and 3 (d) 4 only
(c) Listen (d) Connect 28. The data blocks of a very large file in the Unix file system are
24. In which one of the following page replacement policies, allocated using [2009, 2 Marks]
Belady’s anomaly may occur? [2009, 1 Mark] (a) contiguous allocation
(a) FIFO (b) Optimal (b) linked allocation
(c) LRU (d) MRU (c) indexed allocation
25. The essential content(s) in each entry of a page table is/are (d) an extension of indexed allocation
(a) virtual page number [2009, 2 Marks] 29. Which of the following statements about synchronous and
(b) page frame number asynchronous IN/OUT is not true? [2009, 2 Marks]
(c) both virtual number and page frame number (a) An ISR is invoked on completion of IN/OUT in
(d) access right information synchronous IN/OUT but not in asynchronous IN/
26. In the following process state transition diagram for a OUT
uniprocessor system, assume that there are always some (b) In both synchronous and asynchronous IN/OUT, an
processes in the ready state. [2009, 2 Marks] ISR (Interrupt Service Routine) is involved after
completion of the In/OUT
B
(c) A process making a synchronous IN/OUT call waits
A
D until IN/OUT is complete, but a process making an
Start Ready Running Terminated asynchronous IN/OUT call does not wait for
C completion of the IN/OUT
E (d) In the case of synchronous IN/OUT, the process
F
waiting for the completion of IN/OUT is woken up by
Blocked the ISR that is invoked after the completion of IN/OUT
Operating System S3-175
30. Consider the methods used by processes P1 and P2 for 35. A scheduling algorithm assigns priority proportional to
accessing their critical sections whenever needed, as given the waiting time of a process. Every process starts with
below. The initial values of shared Boolean variables S1 and priority zero (the lowest priority). The scheduler re-
S2 are randomly assigned. evaluates the process priorities every T time units and
decides the next process to schedule. Which one of the
Methods used by P1 Methods used by P2
following is TRUE if the processes have no I/O
while (S1 == S2); while (S 1 ! = S 2) operations and all arrive at time zero? [2013, 1 Mark]
Critical Section Critical Section (a) This algorithm is equivalent to the first-come-
S1 = S2 ; S2 = not (S1); first-serve algorithm
(b) This algorithm is equivalent to the round-robin
Which one of the following statements describes the
algorithm
properties achieved? [2010, 1 Mark]
(c) This algorithm is equivalent to the shortest-job-first
(a) Mutual exclusion but not progress
algorithm
(b) Progress but not mutual exclusion
(d) This algorithm is equivalent to the shortest-
(c) Neither mutual exclusion nor progress
remaining-time-first algorithm
(d) Both mutual exclusion and progress
31. Which of the following statements are true? 36. Which one of the following is FALSE?
I. Shortest remaining time first scheduling may cause [2014, Set-1, 1 Mark]
starvation. (a) User level threads are not scheduled by the kernel.
II. Pre-emptive scheduling may cause starvation. (b) When a user level thread is blocked, all other threads
III. Round robin is better than FCFS in terms of response of its process are blocked.
time [2010, 2 Marks] (c) Context switching between user level threads is faster
(a) I only (b) I and III than context switching between kernel level threads.
(c) II and III (d) I, II and III (d) Kernel level threads cannot share the code segment.
32. A thread is usually defined as a ‘light weight process’ 37. A computer has twenty physical page frames which contain
because an Operating System (OS) maintains smaller data pages numbered 101 through 120. Now a program accesses
structures for a thread than for a process. In relation to this, the pages numbered 1, 2, ..., 100 in that order, and repeats
which of the following is true? [2011, 1 Mark] the access sequence THRICE. Which one of the following
(a) On perthread basis, the operating system maintains page replacement policies experiences the same number of
only CPU register state page faults as the optimal page replacement policy for this
(b) The operating system does not maintain a separate program? [2014, Set-2, 2 Marks]
stack for each thread (a) Least-recently-used (b) First-in-first-out
(c) On perthread basis, the operating system does not (c) Last-in-first-out (d) Most-recently-used
maintain virtual memory state
(d) On per thread basis, the operating system maintains Problem Based MCQs
only scheduling and accounting information.
33. A computer handles several interrupt sources of which of 38. Suppose the time to service a page fault is on the average
the following are relevant for this question? 10 ms, while a memory access takes 1 ms. Then, a 99.99%
Interrupt from CPU temperature sensor hit ratio result in average memory access time of
Interrupt from Mouse [2000, 2 Marks]
Interrupt from Keyboard (a) 1.9999 ms (b) 1 ms
Interrupt from Hard Disk [2011, 1 Mark] (c) 9.999 ms (d) 1.9999 ms
(a) Interrupt from Hard Disk 39. Consider a machine with 64 Mbyte physical memory and
(b) Interrupt from Mouse a 32-bit virtual address space. If the page size is 4 kbyte,
(c) Interrupt from Keyboard what is the approximate size of the page table?
(d) Interrupt from CPU temp sensor [2001, 2 Mark]
34. Consider the virtual page reference string: (a) 16 Mbyte (b) 8 Mbyte
1, 2, 3, 2, 4, 1, 3, 2, 4, 1 (c) 2 Mbyte (d) 24 Mbyte
On a demand paged virtual memory system running on a 40. Following declaration of a two-dimensional array in C:
computer system that has main memory size of 3 page frames [2002, 2 Marks]
which are initially empty. Let LRU FIFO and OPTIMAL
char a [100] [100];
denote the number of page faults under the corresponding
Assuming that the main memory is byte addressable and
page replacement policy. Then, [2012, 2 Marks]
that the array is stored starting from memory address 0,
(a) OPTIMAL < LRU < FIFO
the address of a [40] [50] is
(b) OPTIMAL < FIFO < LRU
(a) 4040 (b) 4050
(c) OPTIMAL = LRU
(d) OPTIMAL = FIFO (c) 5040 (d) 5050
S3-176 Operating System
algorithm and schedules a new process either when the Which is the total waiting time for process P2?
running process gets blocked an IN/OUT or when the [2007, 2 Marks]
running process finishes its compute burst. Assume that all (a) 5 (b) 15
IN/OUT operations can be overlapped as much as possible. (c) 40 (d) 55
For what percentage of time does the CPU remain idle?
55. A single processor system has three resources types X, Y
[2005, 2 Marks]
and Z, which are shared by three processes. There are 5
(a) 0% (b) 10.6%
(c) 30.0% (d) 89.4% units of each resources type. Consider the following
50. Consider three CPU-intensive processes, which require 10, scenario, where the column alloc denotes the number of
20 and 30 time units and arrive at times 0, 2 and 6, respectively. units of each resource type allocated to each process, and
How many context switches are needed, if the operating the column request denotes the number of units of each
system implements a shortest remaining time first scheduling resource type requested by a process in order to complete
algorithm? Do not count the context switches at time zero execution. Which of these processes will finish last?
and at the end. [2006, 1 Mark]
(a) 1 (b) 2 alloc request
(c) 3 (d) 4 X Y Z X Y Z
51. A CPU generates 32-bit virtual addresses. The page size is 4 P0 1 2 1 1 0 3
kbyte. The processor has a transition look-aside buffer (TLB) P1 2 0 1 0 1 2
which can hold a total of 128 page table entries and is 4-way P2 2 2 1 1 2 0
set associative. The minimum size of the TLB tag is
[2006, 1 Mark] [2007, 2 Marks]
(a) 11 bit (b) 13 bit (a) P0
(c) 15 bit (d) 20 bit (b) P1
52. Consider three processes (process id 0, 1, 2 respectively) (c) P2
with compute time bursts 2, 4 and 8 time units. All processes (d) None of the above, since the system is in a deadlock
arrive at time zero. Consider the Longest Remaining Time
First (LRTF) scheduling algorithm. In LRTF ties are broken 56. A process executes the following code
by giving priority to the process with the lowest process id.
for (i = 0; i < n; i ++) for (); [2008, 1 Mark]
The average turn around time is [2006, 1 Mark]
The total number of child processes created is
(a) 13 unit (b) 14 unit
(a) n (b) 2n – 1
(c) 15 unit (d) 16 unit
(c) 2n (d) 2n + 1 – 1
53. Consider the following snapshot of a system running n
processes. Process/is holding Xi instances of a resource 57. A process uses 36 bit physical addresses and 32 bit virtual
R, I £ i £ n. Currently, all instances of R are occupied. addresses, with a page frame size of 4 kbyte. Each page table
Further, for all i process i has placed a request for an entry is of size 4 byte. A three level page table is used for
additional yi instances while holding the xi instances it virtual to physical address translation, where the virtual
already has. There are exactly two processes p and q address is used as follows
such that yp = yq = 0. Which one of the following can Bit 30-31 are used to index into the first level page table
serve as a necessary condition to guarantee that the Bit 21-29 are used to index into the second level page table
system is not approaching a deadlock?[2006, 2 Marks] Bit 12-20 are used to index into the third level page table, and
(a) min (xp, xq) < maxkp,p yk) Bit 0-11 are used as offset within the page
(b) xp + xq ³ maxk ¹ p,q yk The number of bits required for addressing the next level
page table (or page frame) in the page table entry of the first,
(c) max (xp, xq) > 1
(d) min (xp, xq) > 1 second and third level page tables are respectively
54. An operating system uses Shortest Remaining Time First [2008, 2 Marks]
(SRTF) process scheduling algorithm. Consider the arrival (a) 20, 20 and 20 (b) 24, 24 and 24
times and execution times for the following processes (c) 24, 24 and 20 (d) 25, 25 and 24
58. Consider a system with 4 types of resources R1 (3 units), R2
Process Execution time Arrival time (2 unit), R3 (3 unit), R4 (2 unit). A non-pre-emptive resource
P1 20 0 allocation policy is used. At any given instance, a request is
P2 25 15 not entertained if it cannot be completely satisfied. Three
P3 10 30 processes P1, P2, P3 request the resource as follows, if
P4 15 45 executed independently. [2009, 2 Marks]
S3-178 Operating System
Process P1; Process P2; Process P3; (a) 0 and 0 (b) 0 and 1
t = 0: requests 2 unit t = 0: requests 2 unit t = 0: requests 1 (c) 1 and 0 (d) 1 and 1
of R2 of R3 unit of R4 61. A system uses FIFO policy for page replacement. It has 4
t = 1: requests 1 unit t = 2: requests 1 unit t = 2: requests 1 frames with no page loaded to begin with. The system first
accesses 100 distinct pages in same order and then accesses
of R3 of R4 unit of R1
the same 100 pages but now in the reverse order. How many
t = 3: requests 2 unit t = 4: requests 1 unit t = 5: requests 1
page faults will occur? [2010, 1 Mark]
of R1 of R1 unit of R1
(a) 196 (b) 192
t = 5: releases 1 unit (c) 197 (d) 195
t = 6: releases 1 unit t = 7: requests 1
of R2 and 1 unit of 62. The following program consist of 3 concurrent processes
of R3 unit of R2
R1 and 3 binary semaphores. The semaphores are initialized as
t = 8: requests 1 S0 = 1, S1 = 0, S2 = 0 [2010, 2 Marks]
t = 8: Finishes
unit of R3
t = 7: releases 1 unit Process P0 Process P1 Process P2
t = 9: Finishes
of R3 wait (S0); wait (S 1); wait (S1);
t = 8: releases 2 unit print '0' release (S0); release (S0);
of R4 release (S1 )
t = 10; Finishes release (S2);
Which one of the following statements is true, if all three }
processes run concurrently starting at time t = 0?
(a) All processes will finish without any deadlock How many times will process P print ‘0’?
(b) P1 and P2 will be in deadlock (a) Atleast twice (b) Exactly twice
(c) P1 and P3 will be in deadlock (c) Exactly thrice (d) Exactly once
(d) All three processes will be in deadlock 63. A system has n resources R0, ..... Rn – 1, and k processes P0,
59. Consider a disk system with 100 cylinders. The requests to .... Pk–1. The implementation of the resources request logic
access the cylinders occur in following sequence of each process Pi, is as follows if (i% 2 = = 0) {
4, 34, 10, 7, 19, 73, 2, 15, 6, 20 if (i < n) request Ri;
Assuming that the head is currently at cylinder 50, what is if (i + 2 < n) request Ri + 2;
the time taken to satisfy requests, if it takes 1 ms to move }
from one cylinder to adjacent one and shortest seek time else {
first policy is used? [2009, 2 Marks] if (i < n) request Rn – i;
(a) 95 ms (b) 119 ms if (i + 2 < n) request Rn – i – 2;
(c) 233 ms (d) 276 ms }
60. The P and V operations on counting semaphores, where s is In which one of the following situations is a deadlock
a counting semaphore, and defined as follows possible? [2010, 2 Marks]
P(s): s = s – 1; (a) n = 40, k = 26 (b) n = 21, k = 12
if s < 0 then wait;
(c) n = 20, k = 10 (d) n = 41, k = 19
V(s): s = s + 1;
64. Let the time taken to switch between user and kernel modes
if s < = 0 then we ke up a process waiting on s;
of execution be t1 while the time taken to switch between
Assume that Pb and Vb the wait and signal operations on
two processes be t2. Which of the following is true?
binary semaphores are provided. Two binary semaphores
Xb and Yb are used to implement the semaphore operations (a) t1 > t2 [2011, 1 Mark]
P(s) and V(s) as follows (b) t1 = t2
P(s) : Pb(Xb); (c) t1 < t2
s = s – 1; (d) Nothing can be said about the relation between t1 and
if (s < 0) { t2
Vb (Xb); 65. An application loads 100 libraries at startup. Loading each
Pb (Yb); library requires exactly one disk access. The seek time of the
} disk to a random location is given as 10 ms. Rotational speed
else Vb (Xb); of disk is 6000 rpm. If all 100 libraries are loaded from random
V(s): Pb (Yb); location on the disk, how long does it take to load all libraries?
s = s + 1; (The time to transfer data from the disk block once the head
if (s < = 0) Vb (Yb); has been positioned at the start of the block may be
Vb(Xb); neglected? [2011, 2 Marks]
The initial values of Xb and Yb are respectively (a) 0.50 s (b) 1.50 s
[2009, 2 Marks] (c) 1.25 s (d) 1.00 s
Operating System S3-179
66. Consider the following table of arrival time and burst time 70. Consider the 3 processes, P1, P2 and P3 shown in the table:
for three processes P0, P1 and P2.
Arrival Time units
Process
time required
Process Arrival time Burst time
P1 0 5
P0 0 ms 9 ms
P2 1 7
P1 1 ms 4 ms
P3 3 4
P2 2 ms 9 ms
The completion order of the 3 processes under the policies
The pre-emptive shortest job first scheduling algorithm is FCFS and RR2 (Round Robin scheduling with CPU quantum
used. Scheduling is carried out only at arrival or completion 2 time units) are [2012, 2 Marks]
of processes. What is the average waiting time for the three (a) FCFS: P1, P2, P3 RR2 : P1, P2, P3
processes? [2011, 2 Marks] (b) FCFS: P1, P3, P2 RR2 : P1, P3, P2
(a) 5.0 ms (b) 4.33 ms (c) FCFS: P1, P2, P3 RR2 : P1, P3, P2
(c) 6.33 ms (d) 7.33 ms (d) FCFS: P1, P2, P3 RR2 : P1, P2, P3
67. A process executes the code 71. Three concurrent processes, X, Y and Z execute three
fork (); different code segments that access and update certain
fork (); shared variables. Process X executes the P operation
fork (); (i.e. wait) on semaphores a, b and c; process Y executes
The total number of child processes created is the P operation on semaphores b, c and d; process Z
[2012, 1 Mark] executes the P operation on semaphores c, d and a
(a) 3 (b) 4 before entering the respective code segments. After
(c) 7 (d) 8 completing the execution of its code segment, each
process invokes the V operation (i.e. signal) on its three
68. A file system with 300 Gbyte disk uses a file descriptor with
semaphores. All semaphores are binary semaphores
8 direct block addresses, 1 indirect block address and 1
initialized to one. Which one of the following represents
doubly indirect block address. The size of each disk block is
a deadlock-free order of invoking the P operations by the
128 byte and the size of each disk block address is 8 byte.
processes? [2013, 1 Mark]
The maximum possible file system is [2012, 2 Marks]
(a) X: P(a)P(b)P(c) Y: P(b)P(c)P(d) Z: P(c)P(d)P(a)
(a) 3 kbyte
(b) X: P(b)P(a)P(c) Y: P(b)P(c)P(d) Z: P(a)P(c)P(d)
(b) 35 kbyte
(c) X: P(b)P(a)P(c) Y: P(c)P(b)P(d) Z: P(a)P(c)P(d)
(c) 280 kbyte
(d) X: P(a)P(b)P(c) Y: P(c)P(b)P(d) Z: P(c)P(d)P(a)
(d) dependent on the size of the disk
72. A shared variable x, initialised to zero, is operated on by
69. Fetch_And_Add (X, i) is an atomic Read-Modify-Write four concurrent processes W, X, Y, Z as follows. Each of
instruction that reads the value of memory location X , the processes W and X reads x from memory, increments
increments it by the value i and returns the old value of X. It by one, stores it to memory and then terminates. Each of
is used in the pseudocode shown below to implement a the processes Y and Z reads x from memory, decrements
busy-wait lock. L is an unsigned integer shared variable by two, stores it to memory and then terminates. Each
initialized to 0. The value of 0 corresponds to lock being process before reading x invokes the P operation (i.e.
available, while any non-zero value corresponds to the lock wait) on a counting semaphore S and invokes the V
being not available. operation (i.e. signal) on the semaphore S after storing
AcquireLock (L) { x to memory. Semaphore S is initialised to two. What is
while (Fetch_And_Add (L, 1)) the maximum possible value of x after all processes
L = 1; complete execution? [2013, 2 Marks]
} (a) –2 (b) –1
ReleaseLock (L) { (c) 1 (d) 2
L= 0 73. A certain computation generates two arrays a and b such
} that a[i] = f(i) for 0 £ i < n and b[i] = g(a[i]) for 0 £ i < n.
This implementation [2012, 2 Marks] Suppose this computation is decomposed into two
(a) fails as L can overflow concurrent processes X and Y such that X computes the
(b) fails as L can take on a non-zero value that lock is array a and Y computed the array b. The processes
actually available employ two binary semaphores R and S, both initialized
(c) works correctly but may starve some processes to zero. The array a is shared by the two processes. The
(d) works correctly without starvation structures of the processes are shown below.
S3-180 Operating System
Process X:
private i; Allocation Max
for (i=0; i<n; i++) { X Y Z X Y Z
a[i] = f(i); P0 0 0 1 8 4 3
ExitX(R, S); P1 3 2 0 6 2 0
} P2 2 1 1 3 3 3
Process Y:
There are 3 units of type X, 2 units of type Y and 2 units of
private i;
type Z still available. The system is currently in a safe state.
for (i=0; i<n; i++) {
Consider the following independent requests for additional
EntryY(R, S);
b[i] = g(a[i]); resources in the current state:
} REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z
Which one of the following represents the correct REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z
implementations of ExitX and EntryY? Which one of the following is TRUE?
[2013, 2 Marks] [2014, Set-1, 2 Marks]
(a) ExitX(R, S) { (a) Only REQ1 can be permitted.
P(R); (b) Only REQ2 can be permitted.
V(S); (c) Both REQ1 and REQ2 can be permitted.
} (d) Neither REQ1 nor REQ2 can be permitted.
EntryY(R, S) {
P(S); Common Data MCQs
V(R);
} Common Data for Questions 75 and 76
(b) ExitX(R, S) { The processor uses 2-level page tables for virtual to physical
V(R); address translation. Page tables for both levels are stored in
V(S); the main memory. Virtual and physical addresses are both 32
} bits wide. The memory is byte addressable. For virtual to
EntryY(R, S) { physical address translation, the 10 most significant bits of the
P(R); virtual address are used as index into the first level page table
P(S); while the next 10 bits are used as index into the second level
} page table. The 12 least significant bits of the virtual address
(c) ExitX(R, S) { are used as offset within the page. Assume that the page table
P(S); entries in both levels of page tables are 4 bytes wide. Further,
V(R); the processor has a Translation Look-aside Buffer (TLB), with
} a hit rate of 96%. The TLB caches recently used virtual page
EntryY(R, S) { numbers and the corresponding physical page numbers. The
V(S); processor also has a physically addressed cache with a hit rate
P(R); of 90%. Main memory access time is 10 ns, cache access time
} is 1ns, and TLB access time is also 1ns.
(d) ExitX(R, S) { 75. Assuming that no page faults occur, the average time
V(R); taken to access a virtual address is approximately (to the
P(S); nearest 0.5 ns) [2003, 2 Marks]
} (a) 1.5 ns (b) 2 ns
EntryY(R, S) { (c) 3 ns (d) 4 ns
V(S); 76. Suppose a process has only the following pages in its
P(R); virtual address space : two contiguous code pages
}
starting at virtual address 0 × 00000000, two contiguous
74. An operating system uses the Banker’s algorithm for
data pages starting at virtual address 0 × 00400000, and
deadlock avoidance when managing the allocation of three
a stack page starting at virtual address 0 × FFFFF000. The
resource types X, Y, and Z to three processes P0, P1, and
amount of memory required for storing the page tables of
P2. The table given below presents the current system state.
Here, the Allocation matrix shows the current number of this process is [2003, 2 Marks]
resources of each type allocated to each process and the (a) 8 kbyte (b) 12 kbyte
Max matrix shows the maximum number of resources of (c) 16 kbyte (d) 20 kbyte
each type required by each process during its execution.
Operating System S3-181
16. (c) When the system has same number of bits supporting that the most recent arrival is placed at the back, and
virtual addresses and physical addresses, i.e., 32 bit, the earliest arrival in front. T the time of page
then the conversion from virtual to physical that is replacement, oldest page is selected to get replaced.
done by MMU (Memory Management Unit) is not Practical implementation of FIFO is not very good as
required in such cases. Thus, no hardware support is the algorithm experiences Belady’s anomaly.
required. In FIFO when the number of frames increases then,
17. The correct matching is shown the number of page faults also increases and this
behaviour is found by Belady’s anomaly. Thus, FIFO
List-I List-II have this Belady’s anomaly, e.g., in FIFO for three
P. Gang Scheduling 1. Thread Scheduling frames the reference string
Rate Monotonic 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Q. 2. Real-time Scheduling There are 9 page faults and for four frames for the
Scheduling reference string there will be 10 faults.
Fair Share Guaranteed 25. (b) A page table is the data structure used to store the
R. 3. mapping between virtual addresses and physical
Scheduling Scheduling addresses. A page table is used by a virtual memory
18. (d) Blocking one kernel level threads does not block all system in a computer operating system. Virtual
related threads. In kernel level threads, in blocking addresses are the addresses which are unique to the
system call, it can happen with the kernel that another accessing process while physical addresses are the
thread is scheduled while kernel is executing. addresses that are unique to the CPU, i.e., RAM. Page
19. (b) As we know that in case of Belady’s anomaly, the frame number is essential content in each of the page
increase in number of pages results in increase of page table. Virtual page number may not be store entirely in
fault rate so both P and Q are true but Q is not the the page table and thus, cannot be considered as the
reason for P. essential content.
20. (d) Wants2 enters the critical section, if process P1’s 26. (c) 1. is false. If a process makes a transition D, it would
variable wants1 is true and if wants2 is true then wants1 result in another process making transition B, not A.
enters critical section. In both cases, there will be 2. is true. A process can move to ready state when I/O
deadlock but no mutual exclusion. completes irrespective of other process being in
21. (a) Deadlock prevention does not guarantee the state that running state or not.
the state would be safe when the request for resources 3. is true because there is a transition from running to
is granted instead it is guaranteed by deadlock ready state.
avoidance and there will be no deadlock at that time. 4. is false as the OS uses preemptive scheduling
27. (a) The given program initializes the memory location X
22. (b) As we know that the use of multilevel page table
to 0 in the test and set instruction and in the function
reduces the size of the page table needed to implement
leave_CS().
the virtual address space of a process. \ Above solution is deadlock free.
23. (d) socket() creates a new socket of a certain socket type, 28. (d) Indexed allocation is used for the efficient direct access
identified by an integer number, and allocates system good use of disk space. However, it cannot allocate
resources to it. very large files. Thus, the data blocks of very large file
bind() is typically used on the server side, and in unix system are allocated using an extension of
associates a socket with a socket address structure, indexed allocation or EXT2 file system.
i.e. a specified local port number and IP address. 29. (b) This is so because we know that an Interrupt Service
listen() is used on the server side, and causes a bound Routine (ISR) is invoked before the completion of IN/
TCP socket to enter listening state. OUT irrespective of its type whether asynchronous or
connect() is used on the client side, and assigns a free synchronous.
local port number to a socket. In case of a TCP socket, 30. (a) As per the methods provided in process 1 and process
it causes an attempt to establish a new TCP 2, th e process 1 and pr ocess 2 can not exist
connection. simultaneously in the critical section. So, when the
When connect() is called by client, following three process 1 is in the critical section, process 2 is not and
way handshake happens to establish the connection thus, the condition of mutual exclusion is satisfied but
in TCP. not progress.
(1) The client requests a connection by sending a 31. (d)
SYN (synchronize) message to the server. 32. (a) Threads are called 'light weight process' because they
(2) The server acknowledges this request by sending only need storage for stack and registers. They don't
SYN-ACK back to the client. need separate space for other things like code segment,
(3) The client responds with an ACK, and the global data, etc.
connection is established. 33. (d) We know that mouse pointer movements are more
24. (a) In Belady’s anomaly, if number of frames are increased frequent than keyboard ticks. So its obvious that its
then number of page faults increases. data transfer rate is higher than keyboard. Delaying a
This behaviour found only with FIFO. CPU temperature sensor could have serious
The First In, First Out (FIFO) page replacement consequences, overheat can damage CPU circuitry.
algorithm is a low-overhead algorithm. In FIFO, the From the above information we can conclude that
operating system keeps track of all the pages in priorities are : CPU temperature sensor > Hard Disk >
memory in a queue. The queue is managed in a way Mouse > Keyboard
Operating System S3-185
34. (b) Reference string: (c) User Level threads are faster to (reate &
1, 2, 3, 2, 4, 1, 3, 2, 4, 1 manage than kernel threads as no intervention
3 page frames. from kernel is required, so the context switch in
FIFO them is also faster.
(d) As all threads share code & data including
1 2 3 2 4 1 3 2 4 1
kernel level threads, so this option is ‘FALSE’.
1 1 1 1 4 4 4 4 4 4 37. (d) Pages 1, 2, 3, ... 19, 20, 21, ... 100, 1, ... 19, 20, 21, ... 100
Input 2 2 2 2 1 1 1 1 1 Optimal page replacement :
3 3 3 3 3 2 2 2
1 2 3 19 20 20 page faults after 1 to 20 pages
Page P P P X P P X P X X
faults 1 2 3 19 100 80 page faults after 21 to 100 pages
There are 6 page faults.
Optimal
1 2 3 19 100 No page faults from 1 to 19 pages
1 2 3 2 4 1 3 2 4 1
1 1 1 1 1 1 1 1 1 1 20 21 22 20 100 üï 80 pages faults after 20 to 99 pages
Input 2 2 2 4 4 4 4 4 4 ý
and then no page fault for 100
3 3 3 3 3 2 2 2 20 21 22 20 100 ï Total page faults = 180
þ
Page P P P X P X X P X X
faults PROBLEM BASED MCQs
There are 5 page faults.
LRU 38. (d) Since, hit ratio = 99.99%
It will make 0.9999 ms.
1 2 3 2 4 1 3 2 4 1
Therefore,
1 1 1 1 4 4 4 2 2 2
Average memory access time for 99.99% hit ratio
Input 2 2 2 2 2 3 3 3 1
= Memory access time + 0.9999 = 1 ms + 0.9999 ms
3 3 3 1 1 1 4 4
= 1.9999 ms
Page P P P X P P P P P P 39. (b) Size of main memory = 64 MB
faults Size of virtual memory = 232 B
There are 9 page faults. No. of pages = 232/212
Hence, OPTIMAL < FIFO < LRU = 220 pages
35. (b) Process scheduling is independent of the time it
Required 1 M enteries.
takes for a process to execute. Thus, shortest-job-
But each entry has both a virtual address &
first algorithm and shortest remaining-time-first
algorithm can be discarded corresponding physical address.
(i.e., option c and d) Total bits in each entry = 32 +26 (Physical) = 58
Initially as all the processes arrive simultaneously = 58/8 = 8Bytes.
the waiting time for each process = 0 So total memory = 8×1 MB= 8 MB
Any of the processes can be scheduled first say P1. Hence (b) is correct option.
Since, the scheduler re-evaluates the process priorities 40. (b) Given is a [40] [50].
every T time units. In a [40] [50],
After T units of time, Row = 40
Waiting time of P1 = 0 and waiting time of all the Column = 50
others = T. The address is 4050.
Thus, in priority all other processes supercede P1 41. (c) 32 bit virtual address, i.e. 232 kB of virtual memory
and hence other processes get scheduled thereafter. & 1 kB page size.
Once, every process gets scheduled one time each So total pages = 232.
for T time units all the processes will have same So. we need to maintain a page table of 232 rows,
waiting time i.e., (n – 1)T, where n is the process this require 4 GB main memory which is quite
number.
impractical due to large memory overhead.
On the basis of analysis this is Round Robin with
preemptions at periods of T. Hence (c) is correct option.
Option (a) is incorrect because scheduling is 42. (d) I/O performance is not entirely dependent upon disk
independent of the arrival time of the processor. access, it has effect of various other devices, so
36. (d) (a) is correct as user Perel threads are managed using SSTF in place of FCFS may reduce disk access
without kernel support. time but no improvement in the I/O is done. For
(b) In many one model, it one thread makes a slightly larger loads, SSTF offers better performance
blocking system call, the entire process is than FCFS.
blocked so all its threads are also blocked. Hence (d) is correct option.
S3-186 Operating System
43. (a) Turn around time = (Submit time – finish time) 49. (b) Let three processes be p0, p1 and p2. Their execution
Gantt Chart – time is 10, 20 and 30 respectively. p0 spends first 2 time
units in I/O, 7 units of CPU time and finally 1 unit in I/
P1 P2 P 2 P2 P4 P3 P 3 P3 P1 P1 P 1 P 1
O. p1 spends first 4 units in I/O, 14 units of CPU time
1 2 3 4 5 6 7 8 9 10 11 12 and finally 2 units in I/O. p2 spends first 6 units in I/O,
Turn around time for P1 = 12 – 0 = 12 21 units of CPU time and finally 3 units in I/O.
P2 = 4 – 1 = 3 idle p0 p1 p2 idle
P3 = 8 – 2 = 6 0 2 9 23 44 47
P4 = 5 – 4 = 1 Total time spent = 47
Total = 22 Idle time = 2 + 3 = 5
Average turnaround time = 22/4 Percentage of idle time = (5/47) × 100 = 10.6 %
= 5.5 50. (a) Gantt chart for LRTF CPU scheduling algorithm is
Hence (a) is correct option. P0 P1 P 2 P2 P2 P2 P 2 P1 P2 P 1 P2 P0 P1 P2
44. (d) Memory access time
= 0.90×150 +0.10×(150 +150) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Turn around time P0 = 12 – 0 = 12
= 135 +30
P1 = 13 – 0 = 13
= 165 ns
P2 = 14 – 0 = 14
The error rate = 1/10000 = 10–4
CPU burst time = 100 ns 12 + 13 + 4
Average = = 13.
Total execution time 3
= [100 + 2[165] +10 – 4×8×106] 51. (a) We know that 4 kbyte page size requires 12 bit as 4
= 100 + 330 + 800 kbyte = 4 × 210 = 212 byte so 12 bit
= 100 + 1130 number of pages = 128 = 27 so 7 bit required for page
= 1230 ns table entry.
Hence (d) is correct option. The memory cell out of 4-way associative memory
requires 2 bit and 4 kbyte page required 12 bit.
45. (d) Here semaphores are required to obtain mutual
Therefore, total bits required = 7 + 12 + 2 = 21 bit.
exclusion since both access X & Y . So at L1 P(Sx)
TLB minimum size = 32 – 21 = 11 bit.
which means now Sx = wait at L2P(Sy) Sy wait, this
52. (b) Context switches are required only at the time during
prevents process P2 to start access X &Y . the switching over to some other process. Let the three
V(Sx) & V(Sy) in the end of P1 makes Sx & Sy signal given processes be P1, P2 and P3.
so that at L3 & L4 P(Sx) & P(Sy) can start.
Process Arrival time Burst time
Hence (d) is correct option.
P1 0 10
46. (c) Size of 1 block = 1 kB
P2 2 20
Block addresses size 1 pointer size = 32 bit
P3 6 30
= 4 bytes.
The gantt chart for SRTF scheduling algorithm is
210
So, no. of pointers in = B P1 P2 P3
22 0 10 30 60
1 block = 256 So, there are only two context switches required, i.e.,
So direct pointer will have = 10×1kB = 10kB at the time unit 10 context switch from P1 to P2 and at
Double will have = 256×256×1 kB the time unit 30 context switch from P2 to P3.
Triple will have = 256×256×256×1 kB 53. (b) Here option (b) is that min (xp,xq) < maxk? p,q yk
Means the min no. of resources allocated should be
= 28×28×28×210 B less than the maximum number of resources required
= 234 B by any process other than p & q
Hence (c) is correct option. It prevent from deadlock.
47. (c) For every Pi Si is maximum resource requirement Hence (b) is correct option.
where Si > 0. To allot resources to all processes 54. (b) Gantt chart for SRTF is
without any deadlock situation is
P1 P2 P3 P4 P5
n
å si < (m + n) 0 20 30 40 55 70
i=1 Waiting time for process P2 is given as
i.e. sum of all maximum resource requirement should (20 – 15) + (40 – 50), i.e., 15
be less than m + n. 55. (c) From the given matrix we found that the number of
Hence (c) is correct option. available resources of X, Y and Z types are 0, 1, 2
48. (d) Initial value of a is let 10 and its address &a would respectively. Therefore, P1 will avail these resources
first and after release the resources available will be (2,
be different for both parent & child process so.
1, 3) which will be used by P0 as its request is of 1, 0, 3
(A) & (B) are incorrect also parent process executes
resources. After P 0 releases the resources, the
a = a – 5 = 5 = u & child executes a = a + 5 = 15
availability becomes (3, 3, 4) and P2 will use these
= x so u +10 = x resources then as per its requirements. Thus, P2
Hence (d) is correct option. finishes in the last.
Operating System S3-187
56. (b) We know that the total number of processes is 2n but Now, after the pages are accessed, they are to be
we subtract the main process therefore, total number accessed in reverse order. But in reverse, there won’t
of children = 2 (n – 1). be any fault for page numbers 100, 99, 98, 97.
57. (b) From the given conditions, it is concluded that the Therefore, all page frames are occupied. Now, for
equivalent number of bits are required for the three remaining 96 accesses, 96 faults would occur.
levels of page, i.e., 24. Total
Therefore, 100 (Direct access) + 96 (Reverse access) = 196
Number of bits required for first lent = 24 Alternate method
Number of bits required for second lent = 24 Fault of n pages = 2n – 4
Number of bits required for third lent = 24 So, for 100 pages = 2 × 100 – 4 = 196
62. (a) P0 uses a semaphore. Hence, anything whose value is
58. (a) R2 - 2 R3 - 2 R4 - 1 1, P0 will print ‘0’.
t=0 After the release of S1 and S2, we observe that either
un its u nits un its
R2 - 2 R3 - 3 R4 - 2 R1 - 1 P1 or P2 will release S0 so that it print ‘0’ at least 2
t=2 times.
un its u nits un its u nit
Therefore, it is concluded that neither P1 nor P2 will
R2 - 2 R3 - 3 R4 - 2 R1 - 4 go, it is the P0 that prints ‘0’ 2 times atleast.
t=3
un its u nits un its units 63. (b)
R2 - 2 R3 - 3 R4 - 2 R1 - 5 64. (c) t1 < t2
t=4
un its u nits un its units Process switching involves mode switch. Context
R2 - 1 R3 - 3 R4 - 2 R1 - 2 switching can occur only in kernel mode.
t=5 65. (b) 6000 rotations ............. 60 sec
un its u nits un its u nits
R2 - 1 R3 - 2 R4 - 2 R1 - 2 1 rotation ............. 10 ms
t=6 \ Rotational latency = 5 ms
un its u nits un its u nits
Time for one disk access = 15 ms
R2 - 2 R3 - 1 R4 - 2 R1 - 2 Time to load all libraries = 15 ´ 100 = 1500 ms = 1.5 s
t=7
un its u nits un its u nits 66. (a) Process P0 is allocated processor at 0 ms as there is no
R2 - 2 R3 - 1 R4 - 3 R1 - 1 other process in ready queue. P0 is preempted after 1
t=8
un its u nits units u nit ms as P1 arrives at 1 ms and burst time for P1 is less
t=9 than remaining time of P0. P1 runs for 4ms. P2 arrived
at 2 ms but P1 continued as burst time of P2 is longer
The Bolded line show that at that time the requirement than P1. After P1 completes, P0 is scheduled again as
of resource is less than avaiability but it does not cause the remaining time for P0 is less than the burst time of
dead lock. P2.
All process finish without any dead lock P0 waits for 4 ms, P1 waits for 0 ms amd P2 waits for 11
59. (b) Requests 4 34 10 7 ms. So average waiting time is (0+4+11)/3 = 5.
19 73 2 15 6 20 67. (c) A process executes the code and works as follows:
Current 50 34 20 19 The number of child processes created = 2n – 1
15 10 7 6 4 2 = 23 – 1 = 8 – 1 = 7
Next access 34 20 19 15 where, n = 3 Q 3 fork () are executing.
10 7 6 4 2 73 68. (b) Total number of possible addresses stored in a disk
Difference 16 14 1 4 block = 128/8 = 16
5 3 1 2 2 71 Maximum number of addressable bytes due to direct
Therefore, total moves address block = 8 × 128
= 16 + 14 + 1 + 4 + 5 + 3 + 1 + 2 + 2 + 71 = 119 ms Maximum number of addressable bytes due to 1 single
60. (c) From the given code we get that P(S) and V(S), indirect address block = 16 × 128
decrement and increment the value of semaphore Maximum number of addressable bytes due to 1 double
respectively. So, from the given conditions we indirect address block = 16 × 16 × 128
conclude that to avoid mutual exclusion in the value The maximum possible file size
of Xb should be 1 and that of Yb should be 0. = 8 × 128 + 16 × 128 + 16 × 16 × 128 = 35 Kbyte
61. (a) The First In First Out (FIFO) page replacement 69. (b) Take closer look the below while loop.
algorithm is a low-overhead algorithm. In FIFO, the while (Fetch_And_Add(L,1))
operating system keeps track of all the pages in L = 1; // A waiting process can be here just after
memory in a queue. The queue is managed in a way // the lock is released, and can make L = 1.
that the most recent arrival is placed at the back, and Consider a situation where a process has just released
the earliest arrival in front. T the time of page the lock and made L = 0. Let there be one more process
replacement, oldest page is selected to get replaced. waiting for the lock, means executing the AcquireLock()
Practical implementation of FIFO is not very good as function. Just after the L was made 0, let the waiting
the algorithm experiences Belady’s anomaly. processes executed the line L = 1. Now, the lock is
Given are 4 page frames. available and L = 1. Since L is 1, the waiting process
The 100 pages are accessed in some order ® 1 to 100 (and any other future coming processes) can not come
pages will get 100 faults. out of the while loop.
S3-188 Operating System
The above problem can be resolved by changing the Z : P(a) P(c) P(d)
AcuireLock() to following.
AcquireLock(L){ X Y Z
while (Fetch_And_Add(L,1)) P(b) P(c) . P(a )
{ // Do Nothing } P(a) P(b) P( c) .
}
P(c) . P(d) P(d )
70. (c) Arrival Time units
Process The sequence of variable P(b) and P(c) are reverse
time required and opposite [i.e., P(b) P(c) P(a) and P(a) P(b) P(c)]
P1 0 5 So, deadlock may occurs in X and Y respectively
P2 1 7 (Not Acceptable)
(d) X : P(a) P(b) P(c)
P3 3 4
Y : P(c) P(b) P(d)
FCFS: Z : P(c) P(d) P(a)
P1 P2 P3
X Y Z
0 5 12 16
Order P1 ® P2 ® P3 P(a) P(c) . P( c) .
Round robin Here, not P2 because in the ready queue P(b) P(b) P(d )
P2 comes later than P3. P(c) . P(d) P(a )
P1 P2 P1 P3 P2 P1 P3 P2 P2 The sequence of variable P(c) and P(a) are opposite
0 2 4 6 8 10 11 13 15 16 in Z and X. So, deadlock may occur (Not Acceptable)
Hence, the answer is (b).
Here, not P3 because in the ready queue P1 comes first 72. (d) Each of the processes W and X reads x from memory
than P3. and .increment x by .1.
Order P1 ® P3 ® P2 Each of the processes Y and Z reads x from memory,
71. (b) Three concurrent processes X, Y and Z execute and decrement by 2.
three different code segments that access and 1. Start with X and perform P(S) then S = 1 read
update certain shared variables. x=0x=x+1=1
Processes 2. Then Y will perform P(S) then S = 0 read X = 0
x = x–2 = –2 then store x. V(S),S = 1
X Y Z 3. Then Z will perform P(S) then S = 0, read x = – 2 x
P(a) P(b) P(c) . = x – 2 = – 4 then store x, V(S).S = 1.
P(b) P(c) . P(d) 4. Then x will store x.V(S), S =2, X = 1
5. Then W will perform P(S),S =1, read x = 1
P(c) . P(d) P(a) x = x + 1 = 2, store x, V(S),S = 2, x = 2
(a) X : P(a) P(b) P(c) Hence, answer is option (d)
Y : P(b) P(c) P(d) 73. (c) Option (a) Suppose process X executes Exit X then
Z : P(c) P(d) P(a) it will wait for R, and then process Y executes Entry
Suppose X first executes P(a) and P(b) and Y then it will wait for S. Since, initially both binary
then switches to process Z, where P(c) and P(d) are semaphores are 0, no one will increment it and both
executed and wait for P(a), Then again process process will be stuck up in a deadlock.
switches to X and then wait for P(c). \ Option (a) is incorrect.
\ Process X is waiting for C which is occupied Option (b) Here if process X executes for n times
by Z and Z is waiting for a which is occupied by repeatedly it will set both semaphores to 1 (since
process X. only two values are possible) and after that process
So, neither can execute and deadlock occurs. Y executes. First time it passes the Entry Y and make
(Not Acceptable) both semaphores to 0.
(b) X : P(b) P(a) P(c) And on second time it finds both semaphores to 0
Y : P(b) P(c) P(d) and cannot pass the Entry Y barrier. Hence it will get
Z : P(a) P(c) P(d) stuck.
So, option (b) is wrong.
X Y Z Option (c) Considering any sequence of operation of
P(b) P(b) P(a) process X and process Y, first process X will wait for
S which is increment by process Y and then process
P(a) P(c) . P(c) . Y waits for R which is incremented by process X.
P(c) . P(d) P(d) There is no sequence of operation in which the
Execution can be carried out in a proper way value of R or S overlaps.
without deadlock occurance and no wait for any \ Both processes execute one after another.
variable in the processer. (Acceptable) So, option (c) is correct.
(c) X : P(b) P(a) P(c) Option (d) Suppose first process X executes it sets
Y : P(c) P(b) P(d) R = 1 and then waits for S. Now after that process
Operating System S3-189
Initially Head is of 100, so it services Request for 100 replaced which will not be used for the longest period of
itself. Then 105 is serviced because it is nearest to 100. time”. Use of this algorithm guarantees the lowest possible
Now as head is at 105, Request for ‘110’ is serviced as page fault rate for a fixed number of frames. Furthermore,
it is nearer than 90. Finally as head is on 110, out of two this algorithm also does not suffer with Belady’s Anomaly.
nearest requests viz. 90 & 135, ‘90’ is serviced since it is Required page
nearer than “135”. 80, ‘90’ is serviced after servicing 3 Frames
Requests. Page fault (Y/N)
86. 7.2 milli seconds 1 2 3 4 2 1 5 3 2 4 6
As we know, in the shortest remaining time first algorithm,
1 1 1 1 5 3 6
at a given time t, process p is scheduled if its remaining
execution time is minimum among all processes. (Note that - 2 2 2 2 2 2
this algo is applicable only when all processes declare their - - 3 4 4 4 4
execution time in advance before they begin). Y Y Y Y N N Y Y N N Y
Now the Gantt chart for the given processes is as follows:
We can see that “Page 4” replaced “Page 3” as it will not be
0 3 5 7 8 10 12 15 21
used for longest period of time (Page 1, 2 both will be used
A B A A C C E D before page 3). Similarly, Red marked page - 3 replaced
page - 5 as both page - 2, 4 will be used in future.
From the above table:
Total Execution Process selected
6 2 4 6 3 Total no. of page faults = 7.
Time (Given) for Execution with 88. 1000
Shortest Remaining
Process A B C D E exec. Time. Process id t c ti0 A.T TQ = 50 ms
Time Remaining Execution time A 100 ms 500 ms 0 ms
0 6 - - - - A
3 3 2 - - - B B 350 ms 500 ms 5 ms
5 3 0 4 - - A C 200 ms 500 ms 10 ms
7 1 0 4 6 - A
8 0 0 4 6 - C The Gantt chart for Round robin algorithm for the first
10 0 0 2 6 3 C iteration execution for each of the 3 processes is as follows :
12 0 0 0 6 3 E R.Q A B CA
15 0 0 0 6 0 D
21 0 0 0 0 0 - A B C A B C B C B C B
0 50 100 150 200 250 300 350 400 450 500 650
The first column of the table indicates the running time.
Each entry in the table indicates the remaining execution
time of that process at that time. Here a ‘–’ indicates that a A goes for I/O C goes for I/O
process has not arrived and a ‘zero’ indicates that the operation operation
process has finished. After finishing tc CPU ms at time 500ms, C goes for I/O
The last column indicates the process selected for execution operation, that needs 500ms more, so the time at which
that has shortest remaining execution time; these are marked process C would complete its first I/O operations is
with red circles. 500 + 500 = 1000ms
Using the Gantt chart, the arrival time, termination time and 89. 6
turnaroud time of different processes is as follows: Implementing least recently used (LRU) page replacement
Process Arrival Termination Turnaround policy using 3 page frames.
Time Time Time (m sec)
A 0 8 8 4/ 1
B 3 5 2 2/ 2
C 5 12 7
6/ 7
D 7 21 14
E 10 15 5 Total page faults = 6
Total turnaround item of all processes = 36 m sec. 90. 5.5
36 The Gantt chart for SRTF scheduling algorithm is:
Average turnaround time = = 7.2 m sec. P1 P2 P3 P4 P1
5
87. 7 page faults 0 2 6 12 17 27
The given reference string is:
1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6. 15 + 0 + 3 + 4
Average waiting time =
Available no. of frames = 3. 4
We know that in the optimal replacement policy, when a 22
page fault occurs, the required page is loaded from = = 5.5
secondary memory and “that page in main memory will be 4
Databases S3-191
8 Databases
Chapter
The attributes which have multiple values for a given entity, MAPPING CARDINALITIES
this type of attributes are called multivalued attributes. For It describes the number of entities to which another entity can be
example, an employee can have more than one phone related
number, therefore phone number is a multivalued attribute. The binary relationship between 2 entity sets, the mapping
(iii) Derived attributes: cardinality should be one of the following.
The value of an attribute can be derived from the other 1. One to one: An entity in A is related utmost to one entity in
values of other related attributes. For example, the attribute B and vice versa.
date_of_birth and age are related attributes. Age is a derived 2. One to Many: An entity in A can be associated with any
attribute which can be calculated using date_of_birth and number of entities in B. An entity in B can be associated to
need not be a part of schema. And date_of_birth attribute utmost one entity in A.
is called a stored attribute. 3. Many to one: An entity in A can be associated to utmost
RELATIONSHIP SETS one entity in B and entity B can be associated with any
A relationship set defines how two entities interact with each number of entities in A.
other. For example, an employee works for HR department, 'works 4. Many to many: An entity in A is associated with any number
for' is the relationship. of entities in B vice versa.
The set of relationship sets of same type is called relationship PARTICIPATION CONSTRAINTS
sets. Key: subset of attributes that uniquely identifies an entity
(candidate key)
A B
Entity Schema:
A1 B1 The meta-information of entity type name, attributes (and
A2 B2 associated domain), key constraints Entity Types tend to
correspond to nouns; attributes are also nouns albeit descriptions
A3 B3 of the parts of entities. May have null values for some entity
A4 B4 attribute instances – no mapping to domain for those instances.
One to One A B
A1 B1
A B
A2 B2
B1
A1 A3 B3
B2
A4 B4
A2 B3
B4
A3 B5 Many to Many
Keys : Keys are very important part of Relational database. They
One to Many
are used to establish and identify relation between tables. They
also ensure that each record within a table can be uniquely
A B identified by the combination of one or more fields within a table.
A1
B1
Super Key: It is a collection of one or more attributes used to
A2 uniquely identify an entity in entity set.
A3 B2 Candidate key: It is a minimal super key of which no proper subset
A4 is also a super key.
B3
A5 Primary key: It is the candidate key which is used to uniquel
identify an entity in entity set.
Relationship Degree, Recursive Relationship Composite key: Key that consists of two or more attributes that
uniquely identity an entity occurance is called Composite key.
The degree of a relationship is defined by number of entity types But any attribute that makes up the Composite key is not a simple
participating in it. The relationship with degree two is called binary key in its own.
relationship and degree of three is called ternary Foreign key: term used in relational databases (but not in the
Recursive Relationship: E-R model) for an attribute that is the primary key of another table
In some cases the entity types self-links and is called recursive and is used to establish a relationship with that table where it
relationship. For example, the employee is an entity type and appears as an attribute also.
manages is a relationship. The employee entity is related to So a foreign key value occurs in the table and again in the other
manager entity where both employee and manager belong to same table. This conflicts with the idea that a value is stored only once;
entity sets. the idea that a fact is stored once is not undermined.
Databases S3-193
Secondary or Alternative key : The candidate key which are not 3. Create separate table for multivalued attribute and the
selected for primary key are known as secondary keys or primary key of the entity would be added as a column
alternative keys. to the table of the multivalued attribute.
Non-key attribute : Non-key attributes are attributes other than 4. Similarly create separate table for weak entity and the
candidate key attributes in a table primary key of weak entities/multivalued attributes is
Non-prime attribute : Non-prime attributes are attrubutes other formed by combining partial key of weak entity and
than primary attribute. primary key of strong entity to which the weak entity
Weak entity types: Entity types that do not have primary key is related to.
attribute are called weak entity type. 5. Tables for relations depend upon the cardinality of the
relationship. For one to many and one to one there is
ENTITY RELATIONSHIP DIAGRAM no need to create separate tables.
Entity relationship diagrams express the logical structure of a 6. For many to many, create a separate table for
database the main components of entity relationship diagram are relationship and add primary key by combining the
: primary key of both the entities.
Symbol Meaning
RELATIONAL ALGEBRA
Relational algebra is a procedural language. It consists of set of
1. Rectangle Entity set operations which takes one or two relations as input and gives
out a result which is a new relation.
The examples for the different operations will be explained by
2. Ellipse Attributes using the company database,
Employee (employee_name, emp_id, DOfB,
address,gender,dep_number,salary)
Department (Dep_name, D_number, mngr_id, mngr_st_date)
3. Diamonds Relatiohship stes
Project (proj_num, proj_name, p_location, d_num)
4. Lines Linkd attributes to entity Works_on (empl_id, p_num, hours)
sets and entity sets to Dependent (emp_id, depen_name, gender, bdate, relationship)
relationship sets The SELECT Operation
The SELECT operation selects the tuples from the relation which
5. Double ellipse Multivalued attributes satisfies the selection condition, it is denoted by symbol 's'
(sigma). The selection acts as a filter to the tuples to be selected.
The comparisons operators like <,>, =, ¹ are used in selection
predicate. The connectives like and (), or (V), not(-) are used to
6. Dotted ellipse Derived attributes combine several predicates.
The PROJECT operation
7. Double line Total participation of
entity in relationship This operation is used to select certain columns from a relation
sets and discards the other columns. It is denoted by P (Pi).
UNION Example
8. Weak entity
9. Identifying relationship
right outer join orders o on c.cust_id = o.cust_id Multitable clustering organization of customer and depositor:
This returns all rows from order table and matched rows
from customer table. Hayes Main Brooklyn
4. Full join: This returns all rows from both the tables and fills Hayes A-102
in nulls for missing matches on either sides.
Hayes A-220
Eg: select cust_id, cust_name, order_id,order_date from
customer c Hayes A-503
full outer join orders o on c.cust_id = o.cust_id Turner Putnam Stamford
order by o.cust_id Turner A-305
Files and Indexes
The information is represented in the form of records and these A sequential file organization is better way of processing
records in sorted order based on some search key, sometimes
records are stored in the memory i.e. in pages. These records are
this search key may be a primary key or a super key or not.
logically organized into files. A file of records is a collection of To allow the faster access of records the records are linked
records that may extend to several pages. Each record has a unique together by using pointers. The pointer in each record points
identifier called record id or rid in short and page containing a to the next key in the sorted order. To reduce the number of
particular can be accessed by using this rid. A basic file structure accesses to different the records are physically stored as
called heap file contains records in random order and supports close as possible.
the retrieval of the records by using rid. Clustering file organization
The data in a heap file is unordered and the data can be retrieved A cluster file organization stores the data from two or more
using the unique identifier of every record in the file and every relations in a same block. This kind of file organization allows
page in the file is of same size. The operations supported on a us to read records that would satisfy join condition and
heap file are create file, destroy file, insert record, delete record, data read from only one block. The records in the cluster
file organization are chained together using pointers. When
get a record with a given rid and scan all the records in the file.
clustering is to be used it depends on the query types which
The two alternatives to maintain the information is discussed below.
are used frequently. This is decided by the database
Sequential file organization designer. Clustering is very useful in improving performance
Sequential file organization when used carefully.
Indexes
A-217 Brighton 750 An index is an auxiliary data structure which is used to speed up
the record search. The indexes are used to gain faster random
A-101 Downtown 500
access to records on a file. There are two kinds of indices,
A-110 Downtown 600
1. Ordered indices – this is based on a sorted order of the
A-215 Mianus 700 values. The file containing the records is sequentially
A-102 Perryridge 400 ordered based on a primary index which can be a primary
A-201 Perryridge 900 key or a super key.
A-218 Perryridge 700 There are two types of ordered indices,
A-222 Redwood 700 Dense index: Every search key value will have an index
A-305 Round Hill 350 record in the file. In a dense index, the primary index will
contain the search key value and pointer to the first record
Multitable clustering with the search key value. The rest of the records would be
Store several relations in one file using a multitable clustering arranged sequentially with the same search value.
file organization. Sparse index: Only some of the search key values will have
index records. To access a record, we find the index entry
with largest key and starting from that record’s index entry
Customer_name account_number following the pointers the desired record is found.
Hayes A-102 B+ tree index files
B+ tree is efficient disk based structure which stores value of key
Hayes A-220 or value in pair. B+ tree supports faster record search, fast record
Hayes A-503 traversal and maintains sorted tree structure. A B+ tree a tree
where the nodes of the tree is equal to pages on the disk. The B+
Turner A-305 tree has leaf nodes and interior nodes.
2. Hash indices- The values are distributed in different buckets,
and the bucket to which the value is determined using hash
Customer_name customer_street customer_city function.
B tree index files:
Hayes Main Brooklyn B tree indexes are similar to B+ tree indices. The different between
Turner Putnam Stamford these two indices is that B-tree index eliminates the redundant
storage of key values. In B-tree, search key values appear only
once, thus B-tree indices uses less space.
S3-198 Databases
11. From the following instance of a relational schema (c) Names of students who have got an A grade in at
R(A, B, C), we can conclude that least one of the courses taught by Korth
(d) None of the above
A B C 15. Consider the following functional dependencies in a
database:
1 1 1 Date_of_Birth ® Age Age ® Eligibility
1 1 0 Name ® Roll_number Roll_number ® Name
Course_number ® Course_name Course_number ® Instructor
2 3 2 (Roll_number, Course_number) ® Grade
2 3 2 The relation (Roll_number, Name, Date_of_birth, Age) is
[2003, 2 Marks]
[2002, 2 Marks] (a) in second normal form but not in third normal form
(a) A functionally determines B and B functionally (b) in third normal form but not in BCNF
determines C (c) in BCNF
(b) A functionally determines B and B does not (d) none of the above
functionally determine C 16. Let R1 (A, B, C) and R2(D, E) be two relational sachemas,
(c) B does not functionally determine C where the primary keys are shown underlined, and let C
(d) A does not functionally determine B and B does not be a foreign key in R1 referring to R2. Suppose there is
functionally determine C no violation of the above referential integrity constraint
12. In the index allocation scheme of blocks to a file, the in the corresponding relational instances r1 and r2. Which
maximum possible size of the file depends on one of the following relational algebra expressions would
[2002, 2 Marks] necessarily produce an empty relation? [2004, 1 Mark]
(a) the size of the blocks, and the size of the address of (a) PD (r2) – PC (r1) (b) PC (r1) – PD (r2)
the blocks (c) PD (r1 r
C ¹ D 2 ) (d) PC (r1 C = D r 2)
(b) the number of blocks used for the index and the size 17. The employee information in a company is stored in the
of the blocks relation
(c) the size of the blocks, the number of blocks used for Employee (name, sex, salary, deptName)
the index and the size of the address of the blocks Consider the following SQL query :
(d) None of the above Select deptName
13. Which of the following scenarios may lead to an From Employee
irrecoverable error in a database system? Where sex = ‘M’
[2003, 1 Mark] Group by deptName
(a) A transaction writes a data item after it is read by an Having avg(salary) >
uncommitted transaction (select avtg (salary) from Employee)
(b) A transaction reads a data item after it is read by an It returns the name of the department in which
uncommitted transaction [2004, 2 Marks]
(c) A transaction reads a data item after it is written by (a) the average salary is more than the average salary in
a committed transaction the company
(d) A transaction reads a data item after it is written by (b) the average salary of male employees is more than
an uncommitted transaction the average salary of all male employees in the
14. Consider the set of relations shown below and the SQL company
query that follows : (c) the average salary of male employees is more than
Students : (Roll_number, Name, Data_of_birth) the average salary of employees in the same
Courses : (Course number, Course_name, Instructor) department
Grades : (Roll_number, Course_number, Grade) (d) the average salary of male employees is more than
Select distinct Name the average salary in the company
from Students, Courses, Grades 18. The relation book (title, price) contains the titles and prices
where Students. Roll_number = Grades Roll_number and of different books. Assuming that no two books have the
same price, what does the following SQL query list?
Grades.grade
select title
and courses. Instructor = korth
from book as B
and Courses.course - number = Grades.course - number
where (select count (*)
Roll_number = Grades.Roll_number and Grades.grade = A
from book as T
Which of the following sets is computed by the above
where T. price > B. price) < 5
query? [2003, 2 Marks]
[2005, 1 Mark]
(a) Names of students who have got an A grade in all
(a) Title of four most expensive book
courses taught by Korth (b) Title of fifth most inexpensive book
(b) Names of students who have got an A grade in all (c) Titles of fifth most expensive book
courses (d) Titles of five most expensive book
S3-200 Databases
19. Let r be a rational instance with schema R = (A, B, C, D). We 23. The following functional dependencies are given
define r1 = PA, B, C (r) and r2 = PA, D (r). Let s = r1 * r2 where AB ® CD, AF ® D, DE ® F, C ® G, F ® E, G ® A
* denotes natural join. Given that the decomposition of r Which one of the following options is false? [2007, 1 Mark]
into r1 and r2 is lossy, which one of the following is true? (a) {CF}+ = {ACDEFG} (b) {BG}+ = {ACDG}
[2005, 1 Mark] +
(c) {AF} ={ACDEFG} (d) {AB}+ = {ACDFG}
(a) s Ì r (b) r È s = r 24. Consider the relation enrolled (student, course) in which
(c) r Ì s (d) r * s = s (student, course) is the primary key, and the relation paid
20. Which one of the following statements about normal forms (student, amount) where student is the primary key.
is false? [2005, 1 Mark] Assume no null values and no foreign keys or integrity
(a) BCNF is stricter than 3 NF constraints. Given the following four queries:
(b) Lossless, dependency-preserving decomposition into Query1 : select student from enrolled where student in
3NF is always possible (select student from paid)
(c) Lossless, dependency-preserving decomposition into Query2 : select student form paid where student in (select
BCNF is always possible student from enrolled)
(d) Any relation with two attributes is in BCNF Query3 : select E.student from enrolled E, paid P where
21. Which one of the following is a key factor for preferring B+ E.student = P. student
trees to binary search trees for indexing database relations? Query4 : select student from paid where exists
[2005, 1 Mark] (select * from enrolled where enrolled.student
(a) Database relations have a large number of records = paid.student)
(b) Database relations are sorted on the primary key Which one of the following statements is correct?
(c) B+ trees require less memory than binary search trees [2006, 2 Marks]
(d) Data transfer from disks is in blocks (a) All queries return identical row sets for any database
22. Consider the relation account (customer, balance) where (b) Query2 and Query4 return identical row sets for all
customer is a primary key and there are no null values. databases but there exist databases for which
We would like to rank customers according to decreasing Query1 and Query2 return different row sets
balance. The customer with the largest balance gets rank (c) There exist databases for which Query3 returns
1. Ties are not broken but ranks are skipped : If exactly strictly fewer rows than Query2
two customers have the largest balance they each get (d) There exist databases for which Query4 will encounter
rank 1 and rank 2 is not assigned. [2006, 2 Marks] an integrity violation at runtime
25. Consider the relation enrolled (student, course) in which
(student, course) is the primary key, and the relation paid
select A.customer, count (B.customer) (student, amount) where student is the primary key.
Query1 : from account A, account B Assume no null values and no foreign keys or integrity
where A.balance <= B.balance constraints. Assume that amount 6000, 7000, 8000, 9000
group by A.customer and 10000 were each paid by 20% of the students.
Consider these query plans (Plan 1 on left, Plan2 on right)
select A.customer, 1 + count (B.customer) to “list all courses taken by students who have paid more
from account A, account B than x” : [2006, 2 Marks]
Query2 :
where A.balance < B.balance
group by A.customer
Enrolled Paid Enrolled Paid
Consider these statements about Query1 and Query2.
1. Query1 will produce the same row set as Query2 for
some but not all databases. Sequential
Probe index scan, select Probe index Sequential
2. Both Query1 and Query2 are correct implementation on student amount > x on student scan
of the specification.
3. Query1 is a correct implementation of the specification
but Query2 is not. Indexed nested loop join Indexed nested loop join
4. Neither Query1 nor Query2 is correct implementation
of the specification.
5. Assigning rank with a pure relational query takes Project on course Select on amount > x
less time than scanning in decreasing balance order
assigning ranks using ODBC.
Project on course
Which two of the above statements are correct?
(a) 2 and 5 (b) 1 and 3
(c) 1 and 4 (d) 3 and 5
Databases S3-201
A disk seek takes 4 ms, disk data transfer bandwidth is (a) Names of employees with a male supervisor
300 MB/s and checking a tuple to see if amount is greater (b) Names of employees with no immediate male
than x takes 10 µs. Which of the following statements is subordinates
correct? (c) Names of employees with no immediate female
(a) Plan1 and Plan2 will not output identical row sets for subordinates
all databases (d) Names of employees with a female supervisor
(b) A course may be listed more than once in the output 29. Consider the table employee (empId, name, department,
of Plan1 for some databases salary) and the two queries Q1, Q2 below. Assuming that
(c) For x = 5000, Plan 1 executes faster than Plan 2 for all department 5 has more than one employee, and we want
databases to find the employees who get higher salary than anyone
(d) For x = 9000, Plan 1 executes slower than Plan2 for all in the department 5, which one of the statements is true
databases for any arbitrary employee table?
26. Information about a collection of students is given by the Q1 : Select e.empId
relation studinfo (studld, name, sex). The relation enroll From employee e
(studld, courseld) gives which student has enrolled for (or Where not exists
taken) what course(s). Assume that every course is taken (Select * From employee s where s.department = “5” and
by at least one male and at least one female student. What s.salary>=e.salary)
does the following relational algebra expression represent? Q2 = Select e.empId
Pcourseld (P studld (ssex = “female” (studinfo) × pcourseheld From employee e
(enroll)) – enroll) [2007, 1 Mark] Where e.salary > Any
(a) Courses in which all the female students are enrolled (Select distinct salary from employee s Where s.department
(b) Courses in which a proper subset of female students = “5”) [2007, 2 Marks]
are enrolled (a) Q1 is the correct query
(c) Courses in which only male students are enrolled (b) Q2 is the correct query
(d) None of the above (c) Both Q1 and Q2 produce the same answer
27. Consider the following log sequence of two transactions on (d) Neither Q1 nor Q2 is the correct query
a bank account, with initial balance 12000, that transfer 2000 30. Which one of the following statements is false?
to a mortagage payment and then apply a 5% interest. [2007, 2 Marks]
1. T1 start [2007, 1 Mark] (a) Any relation with two attributes is in BCNF
2. T1 B old = 1200 new = 10000 (b) A relation in which every key has only one attribute
3. T1 M old = 0 new = 2000 is in 2NF
4. T1 commit (c) A prime attribute can be transitively dependent on a
5. T1 start key in a 3NF relation
6. T2 B old = 10000 new = 10500 (d) A prime attribute can be transitively dependent on a
7. T2 commit key in a BCNF relation
Suppose the database system crashes just before log record 31. Consider the following schedules involving two
is written. When the system is started, which one statement transactions. Which one of the following statements is
is true of the recovery procedure? true?
(a) We must redo log record 6 to set B to 10500 S1 : r1(X); r1(Y); r2(X); r2(Y); w2 (Y); w1 (X)
(b) We must redo log record 6 to set B to 10000 and the S2 : r1(X); r2(X); r2(Y); w2 (Y); r1(Y); w1 (X)
redo log records 2 and 3. [2007, 2 Marks]
(c) We need not redo log records 2 and 3 because (a) Both S1 and S2 are conflict serializable
transaction T1 has committed (b) S1 is conflict serializable and S2 is not conflict
(d) We can apply redo and undo operations in arbitrary serialzable
order because they are idempotent (c) S1 is not conflict serializable and S2 is conflict
28. Consider the relation employee (name, sex, serializable
supervisorName) with name as the key. supervisorName (d) Both S1 and S2 are not conflict serializable
gives the name of the supervisor of the employee under 32. A clustering index is defined on the fields which are of type
consideration. What does the following tuple relational (a) non-key and ordering [2008, 1 Mark]
calculus query produce? (b) non-key and non-ordering
{e.name | employee (e) Ù} (c) key and ordering
( x) [Øemployee (x)Ú x. supervisorName ¹ e. name vx. sex (d) key and non-ordering
= “male”]} [2007, 2 Marks]
S3-202 Databases
33. Consider the following relational schemas for a library 38. Consider a relational table r with sufficient number of records,
database:
having attributes A1, A2, ... An, let let 1 £ p £ n . Two queries
Book (Title, Author, Catalog_no, Publisher, Year, Price)
Collection (Title, Author, Catalog_no) Q1 and Q2 are given below.
within the following functional dependencies Q1 = p A .....A where c is constant.
1. Title, Author ® Catalog_no 1 p
2. Catalog_no ® Title Author Publisher Year
3. Publisher Title Year ® Price 1 p (
Q 2 = p A .....A sc £ A p £ c 2
1 ) and c 1 and c 2 are
Assume {Author, Title} is the key for both schemas. Which
constants.
of the following statements is true?
[2008, 2 Marks] Which of the following statements is true? [2011, 2 Marks]
(a) Both Book and Collection are in BCNF (a) Ordered indexing will always outperform hashing for
(b) Both Book and Collection are in 3 NF only both queries
(c) Book is in 2 NF and Collection is in 3 NF (b) Hashing will always outperform ordered indexing for
(d) Both Book and Collection are in 2 NF only both queries
34. Let R and S be two relations with the following schemas. (c) Hashing will outperform ordered indexing on Q1 but
R(P . Q, R1, R2, R3)
not on Q2.
S (P . Q, S1, S2)
Where {P, Q}is the key for both schemas. Which of the (d) Hashing will outperform ordered indexing on Q2 but
following queries are equivalent? [2008, 2 Marks] not on Q1.
1. Pp (R >< S) 39. Consider a relational table with a single record for each
2. Pp (R) >< Pp (S) registered student with the following attributes:
3. Pp(PP, Q (R) Ç PP, Q (S)) 1. Registration_Number: Unique registration number for
4. Pp(PP, Q (R) >< PP, Q (R) – PP, Q (S))) each registered student
(a) 1 and 2 (b) 1 and 3 2. UID: Unique Identity Number, unique at the national
(c) 1, 2 and 3 (d) 1, 3 and 4
level for each citizen
35. Let R and S be relational schemas such that R = {a, b, c} and
S = {c}. Now consider the following queries on the database: 3. Bank Account_Number: unique account number at
1. pR – S (r) – pR – S (pR – S (r) × S – pr – S, S (r)) the bank. A student can have multiple accounts or
joint accounts. This attributes stores the primary
2. {t | t ÎpR-S ( r ) Ù"u Îs ( $Ú Î r ( u = v[s] Ù t = v[R -S]))} account number
3. {t | t ÎpR-S ( r) Ù"u Î s ($u Îs (u = v[s] Ù t = v[R -S]))} 4.
5.
Name: Name of the Student
Hostel_Room: Room number of the hostel
4. Select R.a, R. b Which of the following options is incorrect? [2011, 1 Mark]
From R, S
(a) Bank Account_Number is a candidate key
Where R.c = S.c
(b) Registration Account_Number can be primary key
Which of the above queries are equivalent? [2009, 2 Marks]
(a) 1 and 2 (b) 1 and 3 (c) UID is a candidate key if all students are from the same
(c) 2 and 4 (d) 3 and 4 country
36. Consider two transactions T1 and T2, and four schedules (d) If S is a superkey such that S UID Ç is NULL then S
S1, S2, S3, S4 of T1 and T2 as given below : UID is also a super key
T1 : R1 [X] W1 [X] W1[y] 40. Which of the following is true? [2012, 1 Mark]
T2 : R2 [x] R2 [y] W2 [y] (a) Every relation in 3NF is also in BCNF
S1 : R1 [x] R2 [x] W1 [x] W1 [y] W2[y]
(b) A relation R is in 3 NF if every non-prime attribute of R
S2 : R1 [x] R2 [x] R2 [y] W1 [x] W2[y] W1 [y]
S3 : R1 [x] W1 [x] R2 [x] W1 [y] R2[y] W2 [y] is fully functionally dependent on every key of R.
S4 : R2 [x] R2 [y] R1 [x] W1 [x] W1[y] W2 [y] (c) Every relation in BCNF is also in 3 NF
Which of the above schedules are conflict-serializable? (d) No relation can be in both BCNF and 3NF
[2009, 2 Marks] 41. Given the basic ER and relational models, which of the
(a) S1 and S2 (b) S2 and S3 following is incorrect? [2012, 1 Mark]
(c) S3 only (d) S4 only (a) An attribute of an entity can have more than one value
37. Which of the following concurrency control protocols ensure
(b) An attribute of an entity can be composite
both conflict serializability and freedom from deadlock?
(c) In a row of a relational table. an attribute can have
1. 2-phase locking [2010, 1 Mark]
2. Time-stamp ordering more than one value
(a) 1 only (b) 2 only (d) In a row of a relational table. an attribute can have
(c) Both 1 and 2 (d) Neither 1 nor 2 exactly one value or a null value
Databases S3-203
42. Which of the following statements are true about an SQL 47. The line graph L(G) of a simple graph G is defined as
query? [2012, 1 Mark] follows:
P. An SQL query can contain HAVING clause even if it • There is exactly one vertex v(e) in L(G) for each
does not have a GROUP BY clause edge e in G.
Q. An SQL query can contain HAVING clause only if it
does not have a GROUP BY clause • For any two edges e and e¢ in G, L(G) has an edge
R. All attributes used in the GROUP BY clause must between v(e) and v ( e¢ ) , if and only if e and e¢ are
appear in the SELECT clause
S. Not all attributes used in the GROUP BY clause need incident with the same vertex in G.
to appear in the SELECT clause Which of the following statements is/are true?
(a) P and R (b) P and S P. The line graph of a cycle is a cycle.
(c) Q and R (d) Q and S Q. The line graph of a clique is a clique.
43. Consider the following transactions with data items P and Q R. The line graph of a planar graph is planar.
initialized to zero: [2012, 2 Marks] S. The line graph of a tree is a tree.
T1 : read (P); [2013, 2 Marks]
read (Q); (a) P only (b) P and R only
if P = 0 then Q = Q + 1; (c) R only (d) P, Q and S only
write (Q); 48. Consider the relation scheme R = (E, F, G, H, I, J, K, L, M, N)
T2 : read (Q); and the set of functional dependencies {{E, F} ® {G}, {F}
read (P);
® {I, J}, {E, H} ® {K, L}, {K} ® {M}, {L} ® {N}} on R.
if Q = 0 then P = P + 1;
What is the key for R ? [2014, Set-1, 1 Mark]
write (P);
Any non-serial interleaving of T1 and T2 for concurrent (a) {E, F} (b) {E, F, H}
execution leads to (c) {E, F, H, K, L} (d) {E}
(a) a serializable schedule 49. Given the following statements:
(b) a schedule that is not conflict serializable S1: A foreign key declaration can always be replaced by
(c) a conflict serializable schedule an equivalent check assertion in SQL.
(d) a schedule for which a precedence graph cannot be S2: Given the table R(a,b,c) where a and b together form
drawn the primary key, the following is a valid table definition.
44. Suppose R1 (A, B) and R2 (C, D) are two relation schemas. CREATE TABLE S (
let r1 and r2 be the corresponding relation instances. B is a a INTEGER,
foreign key that refers to C in R2. If data in r 1 and r2 satisfy d INTEGER,
referential integrity constraints, which of the following is e INTEGER,
always true? [2012, 2 Marks] PRIMARY KEY (d),
(a) P B ( r1 ) - P C ( r2 ) = Æ FOREIGN KEY (a) references R)
Which one of the following statements is CORRECT?
(b) P C ( r2 ) - P B ( r1 ) = Æ
[2014, Set-1, 1 Mark]
(c) P B ( r1 ) - P C ( r2 ) (a) S1 is TRUE and S2 is FALSE.
(b) Both S1 and S2 are TRUE.
(d) P B ( r1 ) - P C ( r2 ) ¹ Æ (c) S1 is FALSE and S2 is TRUE.
45. An index is clustered, if [2013, 1 Mark] (d) Both S1 and S2 are FALSE.
(a) it is on a set of fields that form a candidate key 50. Consider the following three statements about link state
(b) it is on a set of fields that include the primary key and distance vector routing protocols, for a large network
(c) the data records of the file are organised in the same with 500 network nodes and 4000 links.
order as the data entries of the index [S1] The computational overhead in link state protocols is
(d) the data records of the file are organised not in the higher than in distance vector protocols.
same order as the data entries of the index [S2] A distance vector protocol (with split horizon) avoids
46. Which one of the following is not logically equivalent to persistent routing loops, but not a link state protocol.
[S3] After a topology change, a link state protocol will
Ø $x ( " y ( a ) Ù " z ( b ) ) ? [2013, 2 Marks]
converge faster than a distance vector protocol.
(a) "x ( $z ( Øb) ® "y ( a ) ) Which one of the following is correct about S1, S2, and S3?
[2014, Set-1, 1 Mark]
(b) "x ( "z ( b ) ® $ y ( Ø a ) ) (a) S1, S2, and S3 are all true.
(b) S1, S2, and S3 are all false.
(c) "x ( "y ( a ) ® $ z ( Ø b ) )
(c) S1 and S2 are true, but S3 is false.
(d) "x ( $ y ( Ø a ) ® $ z ( Ø b ) ) (d) S1 and S3 are true, but S2 is false.
S3-204 Databases
51. Consider the following four schedules due to three Which one of the following statements is CORRECT?
transactions (indicated by the subscript) using read and (a) S is conflict-serializable but not recoverable
write on a data item x, denoted by r(x) and w(x) respectively. (b) S is not conflict-serializable but is recoverable
Which one of them is conflict serializable? (c) S is both conflict-serializable and recoverable
[2014, Set-1, 2 Marks] (d) S is neither conflict-serializable nor is it recoverable
(a) r1 (x); r2(x); w1 (x); r3(x); w2(x) 55. Consider a join (relation algebra) between relations r (R)and
(b) r2 (x); r1(x); w2 (x); r3(x); w1(x) s (S) using the nested loop method. There are 3 buffers
(c) r3 (x); r2 (x); r1 (x); w2(x); w1(x) each of size equal to disk block size, out of which one buffer
(d) r2 (x); w2(x); r3 (x); r1(x); w1(x) is reserved for intermediate results. Assuming size
52. Given the following two statements: (r (R))<size(s (S)), the join will have fewer number of disk
S1: Every table with two single-valued attributes is in 1NF, block accesses if [2014, Set-2, 2 Marks]
2NF, 3NF and BCNF. (a) relation r (R) is in the outer loop.
S2: AB ® C, D ® E, E ® C is a minimal cover for the set (b) relation s (S) is in the outer loop.
of functional dependencies AB ® C, D ® E, AB ® E, (c) join selection factor between r (R) and s (S) is more
E ® C. than 0.5.
Which one of the following is CORRECT? (d) join selection factor between r (R) and s (S) is less
[2014, Set-1, 2 Marks] than 0.5.
(a) S1 is TRUE and S2 is FALSE. 56. Consider the procedure below for the Producer-Consumer
(b) Both S1 and S2 are TRUE. problem which uses semaphores: [2014, Set-2, 2 Marks]
(c) S1 is FALSE and S2 is TRUE. semaphore n = 0;
(d) Both S1 and S2 are FALSE. semaphore s = 1;
53. Given the following schema: void producer() void consumer()
employees (emp-id, first-name, last-name, hire-date, dept- { {
id, salary) while(true) while(true)
departments (dept-id, dept-name, manager-id, location-id) { {
You want to display the last names and hire dates of all produce(); semWait(s);
latest hires in their respective departments in the location semWait(s); semWait(n);
ID 1700. You issue the following query: addToBuffer(); removeFromBuffer();
SQL > SELECT last-name, hire-date semSignal(s); semSignal(s);
FROM employees semSignal(n); consume();
WHERE (dept-id, hire-date) IN } }
(SELECT dept-id, MAX (hire-date) } }
FROM employees JOIN departments USING (dept-id) Which one of the following is TRUE?
WHERE location-id = 1700 (a) The producer will be able to add an item to the buffer,
GROUP BY dept-id), but the consumer can never consume it.
What is the outcome? [2014, Set-1, 2 Marks] (b) The consumer will remove no more than one item from
the buffer.
(a) It executes but does not give the correct result.
(c) Deadlock occurs if the consumer succeeds in
(b) It executes and gives the correct result.
acquiring semaphore s when the buffer is empty.
(c) It generates an error because of pairwise comparison.
(d) The starting value for the semaphore n must be 1 and
(d) It generates an error because the GROUP BY clause
not 0 for deadlock-free operation.
cannot be used with table joins in a subquery.
57. SQL allows duplicate tuples in relations, and
54. Consider the following schedule S of transactions T1, T2,
correspondingly defines the multiplicity of tuples in the
T3, T4. [2014, Set-2, 2 Marks]
result of joins. Which one of the following queries always
gives the same answer as the nested query shown below:
T1 T2 T3 T4 select * from R where a in (select S.a from S)
Reads (X) [2014, Set-2, 2 Marks]
Writes (X) (a) select R.* from R, S where R.a=S.a
Commit (b) select distinct R.* from R, S where R.a = S.a
(c) select R.* from R, (select distinct a from S) as S1 where
Writes (X) R.a = S1.a
Commit (d) select R.* from R,S where R.a=S.a and is unique R
Writes (Y) 58. A prime attribute of a relation scheme R is an attribute that
Reads (Z) appears [2014, Set-3, 1 Mark]
Commit (a) in all candidate keys of R.
Reads (X) (b) in some candidate key of R.
Reads (Y) (c) in a foreign key of R.
Commit (d) only in the primary key of R.
Databases S3-205
59. Consider the transactions T1, T2, and T3 and the schedules (b) Names of all the employees with at most one of their
S1 and S2 given below. [2014, Set-3, 2 Marks] customers having a ‘GOOD’ rating.
T1: r1(X); r1(Z); w1(X); w1(Z) (c) Names of all the employees with none of their
T2: r2(Y); r2(Z); w2(Z) customers having a ‘GOOD’ rating.
T3: r3(Y); r3(X); w3(Y) (d) Names of all the employees with all their customers
S1: r1(X); r3(Y); r3(X); r2(Y); r2(Z); w3(Y); w2(Z); r1(Z); having a ‘GOOD’ rating.
w1(X); w1(Z)
S2: r1(X); r3(Y); r2(Y); r3(X); r1(Z); r2(Z); w3(Y); w1(X); Problem Based MCQs
w2(Z); w1(Z)
Which one of the following statements about the schedules 62. Given the following relation instance [2000, 2 Marks]
is TRUE?
(a) Only S1 is conflict-serializable.
X Y Z
(b) Only S2 is conflict-serializable.
1 4 2
(c) Both S1 and S2 are conflict-serializable.
(d) Neither S1 nor S2 is conflict-serializable. 1 5 3
60. Consider the relational schema given below, where eId of 1 6 3
the relation dependent is a foreign key referring to empId of 3 2 2
the relation employee. Assume that every employee has at
least one associated dependent in the dependent relation. Which of the following functional dependencies are
employee (empId, empName, empAge) satisfied by the instance?
dependent(depId, eId, depName, depAge) Consider the
(a) XY ® Z and Z ® Y (b) YZ ® X and Y ® Z
following relational algebra query:
(c) YZ ® X and X ® Z (d) XZ ® Y and Y ® X
P empId (employee)- P empId (employee|X|(empId = eID)^.(empAge . 63. In SQL, relations can contain null values, and comparisons
dependent) with a null values are treated as unknown. Suppose all
depAge)
The above query evaluates to the set of empIds of comparisons with a null value are treated as false. Which
employees whose age is greater than that of of the following pairs is not equivalent?
[2014, Set-3, 2 Marks] [2000, 2 Marks]
(a) some dependent. (a) x = 5 not (not (x = 5)
(b) all dependents. (b) x = 5 x > 4 and x < 6, where x is an integer
(c) some of his/her dependents. (c) x ¹ 5 not (x = 5)
(d) all of his/her dependents.
(d) None of the above
61. Consider the following relational schema:
64. Let r and s be two relations over the relational schemas
employee (empId,empName,empDept)
R and S respectively, and let A be an attribute in R. Then
customer(custId,custName,salesRepId,rating)
salesRepId is a foreign key referring to empId of the the relational algebra expression s A = a (r >< s) is always
employee relation. Assume that each employee makes a equal to [2001, 1 Mark]
sale to at least one customer. What does the following query
(a) s A= a (r) (b) r
return?
SELECT empName (c) s A = a (r) >< s (d) None of these
FROM employee E +
65. A B tree index is to be built on the name attribute of the
WHERE NOT EXISTS (SELECT custId
relation STUDENT. Assume that all student names are of
FROM customer C
WHERE C. salesRepId = length 8 byte, disk blocks are of size 512 byte and index
E.empId pointers are of size 4 byte. Given this scenario, what
AND C.rating < > ‘GOOD’); would be the best choice of the degree (i.e., the number
[2014, Set-3, 2 Marks] of pointers per node) of the B+ tree? [2002, 2 Marks]
(a) Names of all the employees with at least one of their (a) 16 (b) 42
customers having a ‘GOOD’ rating. (c) 43 (d) 44
S3-206 Databases
66. Consider three data items D1, D2 and D3 and the 69. Consider the following relational schema pertaining to a
following execution schedule of transactions T1, T2 and student’s database:
T3. In the diagram, R(D) ans W(D) denote the actions Students (Rollno., name, address)
reading and writing the data item D respectively. Enroll (Rollno., Courseno., coursename)
Where the primary keys are shown underlined. The
T1 T2 T3 numbers of tuples in the student and Enroll tables are 120
and 8 respectively. What are the maximum and minimum
R(D3);
numbers of tuples that can be present in (Student *
R(D2); Enroll), where * denotes natural join? [2004, 1 Mark]
W(D2); (a) 8, 8 (b) 120, 8
R(D2); (c) 960, 8 (d) 960, 120
R(D3); 70. Consider the relation Student (Name, sex, marks), where
the primary key is shown underlined, pertaining to
R(D1); students in a class that has at least one boy and one girl.
time
W(D1); What does the following relational algebra expression
produce?
W(D2);
(Note : p is the rename operator)
W(D3);
p name (rsex - female (student)) - p name (student sex Po, x, m
R(D1);
[2004, 2 Marks]
R(D2); (a) names of girl students with the highest marks
W(D2); (b) names of girl students with more marks than some
boy student
W(D1); (c) names of girl students with marks not less than some
boy student
Which of the following statements is correct?
(d) names of girl students with more marks than all the
[2003, 2 Marks]
boy students
(a) The schedule is serializable as T2 ; T3 ; T1
71. The order of an internal node in a B+ tree index is the
(b) The schedule is serializable as T2 ; T1 ; T3
maximum number of children it can have. Suppose that a
(c) The schedule is serializable as T3 ; T2 ; T1
child pointer takes 6 byte, the search field value takes 14
(d) The schedule is not serializable
byte, and the block size is 512 byte. What is the order of
67. Consider the following SQL query:
the internal node? [2004, 2 Marks]
Select distinct a1, a2,...,an
(a) 24 (b) 25
From r1, r2,...,rm
(c) 26 (d) 27
Where P
72. It is desired to design an object-oriented employee record
For an arbitrary predicate P, this query is equivalent to
system for a company. Each employee has a name, unique
which of the following relational algebra expressions?
Id and salary. Employees belong to different categories
[2003, 1 Mark]
and their salary is determined by their category. The
P s P (r1 ´ r2 ´ ... ´ rm ) functions get Name, geld and compute salary are
(a) a1 ,a 2 ,...,a n
required. Given the class hierarchy below, possible
P sP(r1 >< r2 >< ... >< rm ) locations for these functions are
(b) a1 ,a 2 ,...,a n 1. getId is implemented in the superclass
2. getId is implemented in the subclass
P s P (r1 È r2 È ... È rm ) 3. getName is an abstract function in the superclass
(c) a1 ,a 2 ,...,a n
4. getName is implemented in the superclass
P s P (r1 Ç r2 Ç ... Ç rm ) 5. getName is implemented in the subclass
(d) a1 ,a 2 ,...,a n
6. getSalary is an abstract function in the superclass
68. The relational schema Student Performance (name, 7. getSalary is implemented in the superclas
coureNo., rollNo., grade) has the following functional 8. getSalary is implemented in the subclass
dependencies
name, courseNo. ® grade Employee
rollNo., courseNo. ® grade
name ® rollNo
rollNo. ® name Manager Engineer Secretary
The highest normal form of this relation schema is
[2004, 1 Mark] Choose the best design. [2004, 2 Marks]
(a) 2NF (b) 3NF (a) 1, 4, 6, 7 (b) 1, 4, 7
(c) BCNF (d) 4NF (c) 1, 3, 5, 6, 8 (d) 2, 5, 8
Databases S3-207
73. Consider a relational schema R = (A, B, C, D, E, H) on which number of data items that can be stored in it. The B+ tree
the following functional dependencies hold: {A ® B, BC ® is initially empty.
D, E ® C, D ® A}. What are the candidate keys of R? 10, 3, 6, 8, 4, 2, 1
[2005, 1 Mark] The maximum number of times leaf nodes would get split
(a) AE, BE (b) AE, BE, DE up as result of these insertions is [2009, 2 Marks]
(c) AEH, BEH, BCH (d) AEH, BEH, DEH (a) 2 (b) 3
(c) 4 (d) 5
74. The following table has two attributes A and C where A is 79. The following functional dependencies hold for relations
the primary key and C is the foreign key referencing a with R(A, B, C) and S(B, D, E) [2010, 2 Marks]
on-delete cascade. B ® A,
A®C
A C The relation R contains 200 tuples and the relation S
2 4 contain 100 tuples. What is the maximum number of tuples
3 4 possible in the natural join R >< S?
4 3 (a) 100 (b) 200
(c) 300 (d) 2000
5 2
80. Consider the following schedules for transactions T1, T2
7 2
and T3: [2010, 2 Marks]
9 5
6 4
T1 T2 T3
Read (X)
The set of all tuples that must be additionally deleted to
preserve referential integrity when the tuple (2, 4) is deleted Read (Y)
is [2005, 1 Mark] Read (Y)
(a) (3, 4) and (6, 4) (b) (5, 2) and (7, 2) Write (Y)
(c) (5, 2), (7, 2) and (9, 5) (d) (3, 4), (4, 3) and (6, 4) Write (X)
75. Let E1 and E2 be two entities in an E/R diagram with simple Write (X)
single valued attributes. R1 and R2 are two relationship Read (X)
between E1 and E2, where R1 is one-to-many and R2 is many- Write (X)
to-many. R1 and R2 do not have any attributes of their own.
What is the minimum number of tables required to represent Which one of the schedules below is the correct serialization
this situation in the relational model? [2005, 2 Marks] of the above?
(a) 2 (b) 3 (a) T1 ® T3 ® T2 (b) T2 ® T1 ® T3
(c) 4 (d) 5 (c) T2 ® T3 ® T1 (b) T3 ® T1 ® T2
76. The order of a leaf node in a B+ tree is the maximum number 81. A relational schema for a train reservation database is given
of (value, data record pointer) pairs it can hold. Given that below.
the block size is 1 kbyte, data record pointer is 7 byte long, Passenger (pid, pname, age)
the value field is 9 byte long and a block pointer is 6 byte Reservation (pid, class, tid)
long, what is the order of the leaf node? [2007, 2 Marks] Table: Passenger
(a) 63 (b) 64
(c) 67 (d) 68 pid pname Age
77. Consider a file of 16384 records. Each record is 32 byte long 0 Sachin 65
and its key field is of size 6 byte. The file is ordered on a non- 1 Rahul 66
key field, and the file organization is unspanned. The file is 2 Sourav 67
stored in a file system with block size 1024 byte, and the size
3 Anil 69
of a block pointer is 10 byte. If the secondary index is built
on a key field of the file, and a multi-level index scheme is Table : Reservation
used to store the secondary index, the number of first-level
and second-level blocks in the multi-level index are pid class tid
respectively [2008, 2 Marks]
0 AC 8200
(a) 8 and 0 (b) 128 and 6
(c) 256 and 4 (d) 512 and 5 1 AC 8201
78. The following key values are inserted into a B+ tree in 2 SC 8201
which order of the internal nodes is 3, and that of the leaf 5 AC 8203
nodes is 2, in the sequence given below. The order of
1 SC 8204
internal nodes is the maximum number of tree pointers in
each node, and the order of leaf nodes is the maximum 3 AC 8202
S3-208 Databases
What pids are returned by the following SQL query for the
above instance of the tables? Common Data MCQs
SELECT pid
Common Data for Questions 86 and 87
FROM Reservation Consider the following relational schemas :
WHERE class = AC AND Suppliers (sid : integer, sname : string, city : string, street : string)
EXISTS (SELECT * Parts (pid : integer, pname : string, color : string)
FROM Passenger Catalog (sid : integer, pid : integer, cost : real)
WHERE age > 65 AND 86. Consider the following relational query on the above
Passenger.pid = Reservation.pid) [2010, 1 Mark] database :
(a) 0, 1 (b) 1, 2 SELECT S.sname
(c) 1, 3 (d) 1, 5 FROM Suppliers S
82. Consider a B+ tree in which the maximum number of keys in WHERE S.sid NOT IN (SELECT C. sid
a node is 5. What is the minimum number of keys in any non- FROM Catalog C
root node? [2010, 1 Mark] WHERE C.pid NOT IN (SELECT P.pid
(a) 1 (b) 2 FROM Parts P
WHERE P.color < > ‘blue’))
(c) 3 (d) 4
Assume that relations corresponding to the above schema
83. Consider a database table T containing two columns X and
are not empty. Which one of the following is the correct
Y each of type integer. After the creation of the table, one
interpretation of the above query? [2009, 2 Marks]
record (X = 1, Y = 1) is inserted in the table. Let MX and MY (a) Find the names of all suppliers who have supplied
denote the respective maximum values of X and Y among all a non-blue part
records in the table at any point in time. Using Mx + 1, 2*MY (b) Find the names of all suppliers who have not
+ 1 respectively. It may be noted that each time after the supplied a non-blue part
insertion, values of MX and MY change. What will be the (c) Find the names of all suppliers who have supplied
output of the following SQL query after the steps mentioned only blue parts
above the carried out? (d) Find the names of all suppliers who have not
SELECT Y FROM T WHERE X = 7; [2011, 2 Marks] supplied only blue parts
(a) 127 (b) 255 87. Assume that, in the suppliers relation above, each
(c) 190 (d) 257 supplier and each street within a city has a unique name,
and (sname, city) forms a candidate key. No other
84. Database table by name Loan_Records is given below. functional dependencies are implied other than those
implied by primary and candidate keys. Which one of the
Borrower Bank_Manager Loan_Amount
following is true about the above schema?
Ramesh Sunderajan 100000.00
[2009, 2 Marks]
Suresh Ramgopal 5000.00
(a) The schema is in BCNF
Mahesh Sunderajan 7000.00 (b) The schema is in 3NF but not in BCNF
What is the output of the following SQL query? (c) The schema is in 2NF but not in 3NF
SELECT count (*) (d) The schema is not in 2NF
FROM(
Common Data for Questions 88 and 89 :
(SELECT Borrower. Bank_Manager FROM Loan_Records)
Consider the following relations A, B and C:
AS S
NATURAL JOIN
A
(SELECT Bank_Manager, Loan_Amount FROM
Loan_Records) AS T Id Name Age
); [2011, 2 Marks] 12 Arun 60
(a) 3 (b) 9 15 Shreya 24
(c) 5 (d) 6 99 Rohit 11
85. What is the optimized version of the relation algebra
expression p A1 (p A2 (s F1 (s F 2 (r )))) , where A1, A2 are sets
B
of attributes in r with A1 Ì A2 and F1, F2 are Boolean
Id Name Age
expressions based on the attributes in r ?
15 Shreya 24
[2014, Set-3, 1 Mark]
25 Hari 4
(a) p A1(s( F1ÙF 2) (r )) (b) p A1(s( F1Ú F 2) ( r ))
98 Rohit 20
(c) p A2 (s( F1ÙF 2) (r )) (d) p A2 (s( F1Ú F 2) (r )) 99 Rohit 11
Databases S3-209
Student Student
Student Name Student Email CPI
ID Age
M R1 P R2 N 2345 Shankar shankar@math X 9.4
1287 Swati swati@ee 19 9.5
90. The minimum number of tables needed to represent M, N, 7853 Shankar shnkar@cse 19 9.4
P, R1, R2 is [2008, 2 Marks]
(a) 2 (b) 3 9876 Swati swati@mech 18 9.3
(c) 4 (d) 5 8765 Ganesh ganesh@civil 19 8.7
91. Which of the following is a correct attribute set for one
of the tables for the correct answer to the above
For (StudentName, StudentAge) to be a key for this instance,
question? [2008, 2 Marks]
the value X should NOT be equal to _____________ .
(a) {M1, M2, M3 P1} (b) {M1, P1, N1, N2}
96. A system contains three programs and each requires three
(c) {M1, P1, N1} (d) {M1, P1}
tape units for its operation. The minimum number of tape
units which the system must have such that deadlocks never
arise is _________. [2014, Set-3, 2 Marks]
S3-210 Databases
Since D is a key so it has all the possible values of C. compute {AF}+ = {AF}
So difference would always be empty. = {AFD} AF -> D
Hence (b) is correct. ={AFDE} F -> E
17. (d) SQL query will compute as follows 24. (b) Query 1 Return student names for different courses,
1. Selects the name from the department so one student name may occur more than one time.
2. Selects the male employee Query 2 Student listed in paid, one student for one
3. Computes that time only.
the average salary of male employees is more than the Query 3 Repeating students.
average salary in the company. Query 4 One student selected only once from paid.
18. (d) The computation is as follows So (a) is false.
(b) is correct since (2) & (4) return same rows, but
1. Select the name of the title since three is repeating, so even when one student
2. title is selected from the book enrolled in one course only then
3. Initiates a count Query 1 and Query 2 results in some rows otherwise
4. consider book as T their result is always same.
Query 3 can't return few rows than Query 2 in any
5. compute the title of five most expensive books case.
19. (c) R = (A, B, C, D) 25. (c) Given that left hand side is plan1 and right hand side is
r1 = P A,B,C ( R ) and r2 = P A,D ( r ) plan2.
Plan1
s = r1 * r 2 1. select records form paid
The tuples in s are more than that of r. Also, s consists 2. joins them
of all the tuples of r along with other tuples. Therefore, Plan2
the most appropriate relation is r Ì s . 1. joins records from paid
20. (c) The statement false is Lossless, dependency- 2. records are checked
preserving decomposition into BCNF is always The seek time of disk is 4 ms and data transfer rate is
possible. 300 MB/s.
Lossless, dependency preserving decomposition is So, if x = 5000. Although the output remains the same
possible in certain cases only. It is important to note but the plan 1 executes faster than plan 2 for all
that BCNF is not dependency preserving in all cases databases.
but in some cases only. 26. (b) (ssex = “female” (studinfo) tells that students are
21. (d) We know that indexing is better if the data block is females.
large. Pcourseld (enroll) gives the Id of the course in which to
Now, B+ trees are preferred over the binary search enroll.
trees as in B+ trees, transfer of data from disk to primary PstudId (enroll) tells regarding a proper subset of
memory is in form of data blocks. These data blocks females that are enrolled.
can store large information while transferring, Finally,
information on a single block is more efficient. Pcourseheld tells Course in which a proper subset of
22. (c) Query1 where A.balance<=B.balance ® this line female students are enrolled.
computes the A group of customers and the balance is 27. (c) As it is given that the transaction is already committed,
less than or equal to the group B. the changes are already made.
Query2 where A.balance < B.balance ® this line Now, since the changes are made, they are permanent
computes the A group of customers and the balance is so we do need to restore them as the failure has no
less than the group B. effect on the transaction.
Therefore, the row produced by query1 and query2 We need not redo log records 2 and 3 because
will be same but not in every case as the results of transaction T1 has committed.
query1 and query2 differ in case where query1 has the 28. (c) We are given with the below relational calculus :
situation <= but query2 has only <. {e.name|employee (e) Ù}
None of the query provides the correct implementation ("x)[Ø employee (x) Ú x.supervisorName ¹ x.sex
of the specification.
= “male”]}
23. (c) Consider a+ {e.name|employee (e) Ù} gives he name of the employee
result = a
Also consider, a = a+ ("x)[Ø employee (x)j v x.supervisorName ¹ x.sex
While do = “male”]} tells that employee does not have nay female
for each functional dependency X ® Z in f subordinate.
do begin 29. (b) As per given,
if X C a (result), then employee (empId, name, department, salary)
result = result YZ This suggests that an employees is to be denoted
end using the employee Id, name, department, salary
S3-212 Databases
Query1 It selects an employee but does not compute 3. Pp(PP, Q (R) Ç PP, Q (S))
the result as after the ‘where not exists’, it does not Column P and column Q are projected from R. Similarly,
have statement to produce the result. Column P and column Q are projected from R.
Query2 It selects an employee who gets higher salary Similarly, Column P and Column Q are projected from
than anyone in the department 5. S. The intersection function finally joins the relation
Therefore, the query2 is correct. of R and S projecting column P.
30. (d) Statement (A) Any relation with two attributes is in 4. Pp(PP, Q (R) >< PP, Q (R) – PP, Q (S)))
BCNF is true as with the rules of BCNF, any relation Function will not create relation between R and S.
with two attributes gets into Boyce codd normal form. Therefore, 1, 2, 3 are similar and one kind.
Statement (B) A relation in which every key has only 35. (c) This is very clear from the options itself that the option
one attribute is 2NF is true as 2NF allows only the 2 and option 4 are equivalent as option 2 is technical
relation where a key has only one attribute. representation of code given in option 4.
Statement (C) A prime attribute can be transitively Therefore
dependent on a key in a 3NF relation is also true as
prime attribute has to be transitively dependent on a {t | t Î pR -S ( r ) Î "u Î s ( $Ú Î r ( u = v [s] Ù t = v [R - S]))}
key in 3NF. = Select R.a, R.b
Statement (D) A prime attribute can be transitively From R, S
dependent on a key in a BCNF relation is false as this = Where R.c = S.c
is a feature of 3NF and not BCNF. 36. (b) Let us construct the schedule and transition diagram
31. (c) Lets construct the S1 and S2 with the time to check the to determine the conflict:
serializable conflict.
T1 R1x W1x W1y
¾¾
®
Time S1
S1 : r1 (X);r1(Y);r2 (Y); w 2 (Y); w1(X)
T2 R2x R2y W2x
S2 : r1 (X); r2 (X); r2 (Y); w 2 (Y);r1(Y); w1(X)
S1 ® No serializable conflict
S2 ® Serializable conflict in w1(x) T1 R1x W1x W1y
32. (a) We are given that the clustering index is defined on
the fields. S2
Now, if the records of the file are physically ordered
on a non-key field since it is a non-key, it will not have T2 R2x R2y W2x
a distinct value for each record.
Therefore, the clustering index is defined on the fields
of type non-key and ordering. T1 R2x W1x W1y
33. (c) We will observe that if all the non-key fields are fully S3
dependent on a whole key then a table would be formed
in the Second normal form (2NF). T2 R2x R2y W2x
This table will be in 3NF only when non-key fields are
independent on a whole key then a table.
Alternatively,
Relation Book: transitivity dependency by 1, 2, 3 T1 R1x W1x W1y
statements as given, hence, the relation Book is in S4
2NF.
Relation Collection L: it is in 3 NF as there is fully T2 R2x R2y W2x
transitive dependency.
Therefore Book is in 2NF and Collection is in 3NF. Schedule S2
34. (c)
1. Pp (R S) T1 T2
Joins the relation between R and S projecting column R[x]
P. R[x]
2. Pp (R) Pp (S) R[y]
Column P is projected from R and individually, column W[x]
P is projected from S, finally joining the relation. This W[y]
can simply be said that it joins the relation between R W[y]
and S projecting column P.
Databases S3-213
41. (c) An attribute of an entity can have more than one value
Dependency graph T1 T2 S 2 have no
or multivalue.
cycles. For example,
Schedule S3
Name Phone Number
T1 T2 Ram 012364
R[x] Ram 023146
W[x]
Anil 058633
R[x]
W[y] Anil 014362
W[y] Anil 056342
W[y]
Hence, option (a) is correct.
Attributes can be composite also, Hence, option
Dependency graph T1 T2 S3 also have no (b) is also correct. In the relational table, any attribute
cycles. can contain only one value which can be null. Hence,
Here, we can see that S1 and S4 are not conflict option (d) is also correct but by the definition of 1 NF,
serializable but S2 and S3 are conflict serializable. any attribute in the relational table can contain only
one value not more than one values. Hence option (c)
37. (b) Time stamp ordering ensures both conflict serializability
is false or incorrect.
and freedom from deadlock as timestamp-based
42. (d) Consider P statement:
concurrency control is a non-lock concurrency control
An SQL query can contain a having clause even if it
method. The method is employed in relational
has a GROUP BY clause. So, the given statement is
databases to safely handle transactions. It uses the
false.
timestamps for the same.
Consider Q statement:
38. (c) This statement is correct.
39. (a) Candidate key cannot be commen. Here, the two Consider R statement:
students can have common account nuntler bank This statement is wrong because all the attributes used
account number will not work like candidate keys. in GROUP BY clause are superset of all the attributes
40. (c) According to relation between the different normal which are listed in SELECT clause.
forms i.e., Consider S statement:
This statement is wrong because not all attributes used
1NF in GROUP BY clause need to appear in the SELECT
2NF clause.
3NF 43. (b) Suppose the schedule is
BCNF T1 T2
R(P)
R(Q) R(Q)
R(P)
B is a foreign key that refers to C in R2. 48. (b) We know that K is a key for Relation schema R it
If r1 and r2 satisfy referential integrity constraints K ® R; i.e. K functionally determines each & every
attribute of R. This is definition off key using functional
therefore, P B ( r1 ) Ê P B ( r2 )
dependency.
45. (c) A clustered Index sorts and stores the data rows in the Now, the Given Relation-Schema is R (E, F, G, H, I, J, K,
table or view based on their key values. L, M, N) and the Given functional dependencies:
The column on which clustered Index is created need {E, F}®{G} (i) {K}®{M} (iv)
not be primary key but it should always be not Null. {F}®{I, J} (ii) {L}®{N} (v)
46. (a) "´ ($z (Øb) ® "y(a)) {E, H}®{K, L} (iii)
Now we need to find function dependency whose right
(d) "´ ($y (Øa ) ® $z (Øb)) side is R.
is NOT logically equivalent to (a) {E, F} Cannot be a key as it determines only ‘G’
Ø$ ´ ("y (a ) Ù "z (b)) (b) {E, F, H} is a key:
47. (a) (P) The line graph of a cycle is a cycle. · using Transitivity on (i) and (ii) we get
Let c be a cycle. In the line graph L(c) {E, F}®{G, I, J} .......(vi)
(i) There will be an edge between two vertices · using preudotransitivity on (iii) and (vi) we get
corresponding to adjacent edges in the cycle. {E, F, H}®{G, I, J, K, L} ........(vii)
(ii) Degree of each vertex in L(c) will be 2. · using Decomposition on (vii) we get
(iii) L(c) will be connected. {E, F, H}®{K} and {E, F, H}®{L}
Hence L(c) will also be a cycle \ P is true. Combining above with (iv) and (v) respectively
(Q) The line graph of a clique is a clique. {E, F, H} ®{M} and {E, F, H} ®{N}
Let 'Kn' be a clique on 'n' vertices. Now, finally performing union of these with (vii) we
Consider line graph L (Kn) – L (Kn) has nC2 vertices. get:
For n> 3, there will be atleast two edges say e1, e2 in {E, F, H} ®{G, I, J, K, L, M, N} ...........(viii)
"Kn" which do not share a vertex in "Kn". Also {E, F, H}®{E, F, H} is trivial, combine this with
So, V (e1), V (e2) will not be adjacent in L(Kn) (viii) using union, we get:
Hence, L(Kn) is not always a clique. {E, F, H} ®{E, F, G, H, I, J, K, L, M, N}
(Q) is false. Þ {E, F, H} ® R
(R) The Line graph of a planar graph is planar So, {E, F, H} is a key of R.
Let G be a star graph. Considering a line graph (c) {E, F, H, K, L} is a super key but not a key since it is not
L(G) : V(e1), V(e2), V(e3) ® K5, minimal (i.e. contains extra attributes)
& (D) {E} cannot be a key of R clearly.
e1 49. (d) Both S1 and S2 are false.
e5 50. (d) S1, S3 are true, but S2 is false.
S1 is true as the link state Routing uses “Dijkstra’s
e2 Algorithm” to compute new routes which has high
computation complexity.
e3 e4 ‘S2’ is false as Distance vector routing suffers from
Two-node loop problem.
V(e4), V (e5) will form a clique S3 is true as in link state routing each node has the
A planar graph cannot have a K5 entire topology of the domain.
\ Through G is planar L (G) is not a Planar graph 51. (d) rQ (x); w2 (x); r3 (x); r1 (x); w1 (x) is conflict serializable.
So, R is false. Conflicting Instructions: Two instructions are said to
(S) The line graph of a tree is a tree. be conflicting instructions if they are performed on
Let 'T' be an example tree, and L{T) is its line graph. In the same data item and atleast one of them is “write”
L(T) :e1,e2,e3 will form a K3 (D le) instruction.
Serial schedule : A schedule is called a serial schedule
if it consists of a sequence of instructions from various
transactions, where the instructions belonging to one
single transaction appear together in that schedule.
Conflict serializable schedule: A schedule is called
conflict serializable if it can be transformed into a “serial
e1 e2 e3
schedule” using valid swap operation where valid
swap denotes the swapping of any two “Non-
i.e. a 3 – cycle.
conflicting” instructions.
Tree is an acyclic graph i.e., does not have a cycle. So,
(a) r1 (x); r2 (x); w1 (x); r3 (x); w2 (x); is not conflict
L(T) is not a tree.
serializable because w1 (x); cannot be swapped either
So, S is false
with r2 (x); or r3 (x).
\ Answer is "P" only i.e., Option (a).
Databases S3-215
(b) It is also not conflict serializable as w2 (x) cannot be A gives the set of empIds of those employees whose
swapped with r1 (x) or r3 (x). age is less than or equal to the age of some of his/her
(c) Same here as w2 (x) and r1 (x) are conflicting. dependents.
(d) It is conflict serializable as if we swap r3 (x) with r1 (x) Set of empIds of all employees - set of empIds
which are Non-conflicting, we get r2 (x); w2 (x); r1 (x); obtained from part A gives the set of empIds of
r3 (x) ; w3(x) employees whose age is greater than that of all of his/
Which is a SERIAL SCHEDULE. her dependents.
52. (a) S1 is true and S2 is false. 61. (d)
S1: Every table with two single valued attributes is in
1 NF, 2NF, 3NF and BCNF PROBLEM BASED MCQs
S1 is trially true by the definition of all normal forms.
62. (b) From the table given above, the B functional
S2 : AB ® C, D ® E, E ® C is a minimal cover for the set
of functional dependencies dependency is satisfied by the instance.
AB ® C, D® E, AB ® E, E ® C. We can say this by the following :
It is clearly false as any combination of the functional Y is functionally dependent on Z.
dependencies AB® C, D ® E, E® C cannot generate ® YZ is functionally dependent on X.
the func. dependency AB® E. Since AB®E cannot This is referred to as multivalued independency.
be inferred, the given set cannot be the minimal cover. 63. (c) Option (a) The output of the LHS is 5. In RHS, there
So, S2 is false. are two not operations. Now, when it comes to produce
Finally, S1 is true and S2 is false. the result, not and not cancels and produce 5.
53. (b) It executes and gives the correct result. As we see Option (b) Clearly, LHS and RHS produce the same
there is nothing wrong with the Given query so it result 5
displays the expected result. Option (c) The output of LHS is the number which is
54. (c) S is both conflict - serializable and recoverable. not equal to 5. In RHS, the output will differ in SQL
55. (a) taking the given conditions into considerations.
56. (c) Consumer executes wait (S), then wait (n) and goes to 64. (c) Relational schemas R and S
sleep by decreasing n value. A be an attribute in R.
After the consumer sleep, producer goes to the sleep SA=a (r) >< s
by executing wait (s).
Dead lock occurs if the consumers succeeds in The next step is to select A = in relation
aquiring semaphore S when the buffer is empty. Now, since A is attribute of R and r is also a relation of
57. (c) The one that give same answer is : R.
select R. * from R, (select distinct a from S) as S1 Here write expression is to be performed.
where R.a = S1. s A =a (r >< s) = sA =a (r) >< s
58. (b) A prime attribute of a relation scheme R is an attribute 65. (d) Size of 1 record of index = 8 + 4 = 12 bytes.
that appears in some candidate key of R1 others are Let no. of pointers required = P
non-prime or non-key attributes. No. of index values per block = P – 1
59. (a) Precedence graph
So (P – 1) 8 + 4P = 512
S1 S2 12P = 520
P < = 44
T1 T2 T3 T1 66. (c) As per the table given,
In T3,
R(D2) is conflicted with the original R(D2) in T2 as it
reads R(D2) as W(D2).
T3 No cycle T2 cycle In T2,
R(D1) is conflicted with the original R(D1) in T1 as it
\ S1 is conflict serializable reads In T1, R(D1) as W(D1).
60. (d) In T1,
R(D2) is conflicted with the original R(D2) in T2 as it
A reads R(D2) as W(D2)
67. (a) SQL does the following operations
p (employee) – p (employee) dependent 1. It forms the Cartesian product of relations that
are named in form clause.
(emp Id = eID) Ù (emp Age £ dep Age)
2. It performs a relational algebra selection using
the where clause predicate. By this the results
are projected onto attributes of selected clause.
S3-216 Databases
78. (a) No. of splits would be three. This can be further and the pld common to reservation is 1 and 3.
displayed in the figure below
Insert 10 : 10 1 AC
Insert 3 : 3, 10
Insert 6 3 AC
6 82. (b) In B+ tree, the root node has minimum 2 block pointers
and maximum P block pointer where, P = order where,
First split
key = order – 1 and in the non-root node, the minimum
3 10 number of keys
6
éPù
= ê ú -1
Insert 8 ë2û
3 8, 10
So, in the question key = 5, order = 6
6
So, minimum number of keys in non-root node
Insert 4
é6ù
3, 4 8, 10 = ê ú -1 = 2
ë 2û
3, 6
83. (a) X Y
Insert 2 1 1
2 4 8, 10 2 3
3 7
Second split
4 15
3, 6 5 31
6 63
Insert 1 7 127
1, 2 4 8, 10 For X= 7 Þ Y = 127
Therefore, the total number of splits is
79. (a) B ® A where R(A, B, C) and S(B, D, E), A ® C
84. (a) S T
R contains 200 tuples and S contains 100 tuples.
Borrower Bank manager Bank manager Loan amount
Natural join >< = R >< S = p[s(R × S)]
Ramesh Sunderajan Sunderjan 10000.00
So, R = 200 tuples and S = 100 tuples
Suresh Ramgopal Ramgopal 5000.00
So, R >< S = 100 [common is both or we can say distinct
Mahesh Sunderajan Sunderajan 7000.00
equality between all common attributes]
80. (a) The solution can be obtained by checking with all the
available options. S >< T
The correct serialization is T1 ® T3 ® T2. Borrower Bank manager Bank manager Loan amount
Ramesh Sunderajan Sunderjan 1000.00
This will result in same result as in the given schedule
Ramesh Sunderajan Sunderajanl 7000.00
and will not conflict in read write operation of same
data items. Ramesh Sunderajan Sunderajan 5000.00
Mahash Sunderajan Sunderajan 10000.00
81. (c) The solution is best understood in steps Mahesh Sunderajan Sunderajan 7000.00
1. select the process Id from reservation whose class is
AC the condition is satisfied by 0, 1, 5, 3 Count *(S >< T) = 5
2. select a passenger whose age > 65 and the pld of
passenger id = pld of reservation id passenger whose P A1 (P A2 (s F1 (s F2 (r))))
85. (a)
ages > 65 are those of pld 1, 2, 3
= P A1 (P A 2 (s(F1 Ù F2 )(r)))
pld pname Age
Q A1 Ì A 2 , final relation will be displaying values
1 Rahul 66
for attributes present in set A.
2 Sourav 67
P A1 (s(F1 Ù F2 )(r))
3 Anil 69
S3-218 Databases
Entities Identified – Vendors, Receiving office, Inspection office ENTITIES: Vendor, Receiving office, Inspection office and
Documents Indentified - Delivery note, discrepancy note, Items purchase office
Received note. DOCUMENTS: Delivery note, Items received note and
Using these a document flow diagram is drawn. discrepancy note.
The diagram is interpreted as follows:
DATA FLOW DIAGRAM (DFD)
(1) Vendors deliver items to receiving office accompanied by
a delivery note DFD has entities and data flows, DFD specifies processing
(2) Receiving Office sends items to inspection office along performed by some of the entities. It specifies which entities
with an items received note generate documents and also indicate their flow. Data stores which
are referred while processing data and in which processed data
(3) Receiving office sends discrepancy note to Purchase
may be written or stored are also represented in the Diagram.
office
• Entities are, originators of data and “consumers” of data • Abstract specification: Specify sub-systems.
• Vendor, Inspection office and purchase office are entities • Interface design: Describe sub-system interfaces.
in the diagram • Component design: Decompose sub-systems
• Data flows are delivery note, items received note and into components.
discrepancy note • Data structure design: Design data structures to hold
• A circle is used to depict a process problem data.
• A pair of parallel lines depict a store • Algorithm design: Design algorithms for problem
functions.
INPUT/OUTPUT DESIGN
Design Phases
• Architectural design: Identify sub-systems.
Information System and Software Engineering S3-221
The project management team should: 4. Schedule the work and resources
1. Plan how to deliver the required outcomes and benefits 5. Identify risks and design controls
2. Decide how to manage relationships with key stakeholders 6. Document and gain approval for the plan
3. Decide how to project manage the delivery process Software Estimation
4. Determine resource requirements and ensure they can be
Estimation techniques
made available when required
Organizations need to make software effort and cost estimates.
5. Develop Business Case to enable the SRO/Project Board
There are two types of technique that can be used to do this:
to decide whether project is cost and risk justified.
Cost is estimated as a mathematical function of product, project
The SRO should ensure:
and process attributes whose values are estimated by project
1. Post project reviews are carried out to measure the degree
managers:
to which benefits have been achieved
· Effort = A ‘SizeB’ M
2. The Business Case is updated to reflect operational reality
· A is an organisation-dependent constant, B reflects the
3. Potential improvements/changes/opportunities identified
disproportionate effort for large projects and M is a
in the reviews fed into the strategic planning process for
multiplier reflecting product, process and people attributes.
consideration
The most commonly used product attribute for cost estimation is
Planning checklist code size.Most models are similar but they use different values
1. Confirm scope and purpose of the plan: for A, B and M.
2. Define the deliverables:
3. Identify and estimate activities
Project duration and staffing 3. Systems design: Describes desired features and
Calendar time can be estimated using a COCOMO 2 formula operations in detail, including screen layouts, business
, *
• TDEV = 3 (PM)(0.33 + 0.2 (B-1.01)) rules, process diagrams, pseudocode and other
PM is the effort computation and B is the exponent computed as documentation.
discussed above (B is 1 for the early prototyping model). This • Implementation: The real code is written here.
computation predicts the nominal schedule for the project.The • Integration and testing: Brings all the pieces together
time required is independent of the number of people working on into a special testing environment, then checks for
the project. errors, bugs and interoperability.
• Acceptance, installation, deployment: The final stage
SDLC - CODING, TESTING, IMPLEMENTATION,
of initial development, where the software is put into
MAINTENANCE PHASES
production and runs actual business.
A number of system development life cycle (SDLC) models have • Maintenance: What happens during the rest of the
been created: waterfall, fountain, spiral, build and fix, rapid software's life: changes, correction, additions, moves
prototyping, incremental, and synchronize and stabilize. to a different computing platform and more. This, the
1. Project planning, feasibility study: Establishes a high- least glamorous and perhaps most important step of
level view of the intended project and determines its goals. all, goes on seemingly forever.
2. Systems analysis, requirements definition: Refines
project goals into defined functions and operation of the
intended application. Analyzes end-user information
needs.
Information System and Software Engineering S3-225
9. The cyclomatic complexity of each of the modules A and B Which one of the following options provides the set of non-
shown below is 10. What is the cyclomatic complexity of the redundant tests using equivalence class partitioning
sequential integration shown on the right hand side? approach from input perspective for Black Box testing?
[2010, 1 mark] [2011, 2 marks]
(a) T1, T2, T3, T6 (b) T1, T3, T4, T5
(c) T2, T4, T5, T6 (d) T2, T3, T4, T5
11. A company needs to develop a strategy for software product
A development for which it has a choice of two programming
B languages L1 and L2. The number of Lines of Code (LOC)
A
developed using L2 is estimated to be twice the LOC
developed with L1. The product will have to be maintained
B for 5 years. various parameters for the company are given in
(a) 19 (b) 21 the table below. [2011, 1 mark]
(c) 20 (d) 10 Parameter Language L1 Language L2
10. The following is comment written for a C function
Man years needed for LOC/10000 LOC/10000
/* This function computes the roots of a quadratic equation.
development
a.x2 + b.x + c = 0. The function stores two real roots.
in *root1 and *root2 and returns the status of validity of Development ` 10,00,000 ` 7,50,000
roots. It handles four different kinds of cases. cost per year
1. When coefficient a is zero irrespective of discriminant Maintenance time 5 yr 5 yr
2. When discriminant is positive Cost of maintenance ` 1,00,000 ` 50,000
3. When discriminant is zero per year
4. When discriminant is negative
Only in cases 2 and 3, the stores roots are valid. Total cost of the project includes cost of development and
Otherwise 0 is stored in the roots. the function returns 0 maintenance. What is the LOC for L1 for which the cost of
when the project using L1 is equal to the cost of the project using
the roots are valid and – 1 otherwise. L2?
The function also ensures root 1 > = root 2. (a) 4000 (b) 5000
int get_QuadRoots float a, (float b, float c, float * root1, float (c) 4333 (d) 4667
* root2);
*/
A software test engineer is assigned the job of doing Block
Box testing. He comes up with the following test cases, many
of which are redundant.
Initiation Step II
Step I
The answer of the match of the following can be obtained from the above figure. We know that the software development is a
process which is done stepwise. The left hand side of the match the following is mentioned in the figure above along with the step.
With this we can assume the answer.
4. (d) Algorithm for software implementation 6. (c) Prototyping is a method of requirements validation
5. (b) 1–d, 2–a, 3–b, 4–c 7. (b) In the content of modular software design these
In Evolutionary model softwares evolve so should be high cohesion, since cohesion is measure
specification can be developed incrementally. of internal strength within a module. The coupling
In waterfall model inflexible partitioning of the is measure of interdependency among modules, so
project into stages need to be done. it should be low.
S3-228 Information System and Software Engineering
10 Computer Networks
Chapter
Interface
Presentation protocol
6 Presentation Presentation PPDU
Session protocol
5 Session Session SPDU
Layer 1 – Physical - Physical layer defines the cable or 255, e.g., 129.79.16.40. The leading 1-3 bytes of the IP identify
physical medium itself, e.g., thinnet, thicknet, unshielded the network and the remaining bytes identify the host on that
twisted pairs (UTP). network.
Layer 2 – Data Link - Data Link layer defines the format of Layer 4 - Transport - Transport layer subdivides user-buffer
data on the network. The data link layer handles the physical into network-buffer sized datagrams and enforces desired
and logical connections to the packet’s destination, using a transmission control. Two transport protocols, Transmission
network interface. The data link layer’s protocol-specific header Control Protocol (TCP) and User Datagram Protocol (UDP), sits
specifies the MAC address of the packet’s source and at the transport layer. TCP keeps track of the packet delivery
destination. When a packet is sent to all hosts (broadcast), a order and the packets that must be resent. UDP on the other
special MAC address (ff:ff:ff:ff:ff:ff) is used. hand provides a low overhead transmission service, but with
Layer 3 – Network- NFS uses Internetwork Protocol (IP) as its less error checking.
network layer interface. IP is responsible for routing, directing Layer 5 - Session - The session protocol defines the format of
datagrams from one network to another. IP addresses are the data sent over the connections. RPC may be built on either
written as four dot-separated decimal numbers between 0 and TCP or UDP.
S3-230 Computer Networks
Layer 6 - Presentation - External Data Representation (XDR) Layer 1 – Link - This layer defines the network hardware and
sits at the presentation level. It converts local representation device drivers.
of data to its canonical form and vice versa. The canonical uses Layer 2 – Network- This layer is used for basic communication,
a standard byte ordering and structure packing convention, addressing and routing. TCP/IP uses IP and ICMP protocols at
independent of the host. the network layer.
Layer 7 - Application - Provides network services to the end- Layer 3 – Transport - Handles communication among programs
users. Mail, ftp, telnet, DNS, NIS, NFS are examples of network on a network. TCP and UDP falls within this layer.
applications. Layer 4 – Application - End-user applications reside at this
layer. Commonly used applications include NFS, DNS, arp,
TCP/IP Network Model rlogin, talk, ftp, ntp and traceroute.
TCP/IP is designed around a simple four-layer scheme. The
four network layers defined by TCP/IP model are as follows.
Difference between OSI & TCP/IP Model:
OSI TCP/IP
OSI makes the distinction between TCP/IP does not originally clearly
services, interfaces, and protocol. distinguish between services, interface, and
protocol.
The OSI model was devised before the TCP/IP model was just a description of the
protocols were invented. It can be made existing protocols. The model and the
to work in diverse heterogeneous protocol fit perfectly.
networks
The OSI model supports both The TCP/IP model has only one mode in
connectionless and connection-oriented the network layer (connectionless) but
communication in the network layer, but supports both modes in the transport layer,
only connection-oriented giving the user choice.
communication in the transport layer.
OSI has seven layers: Application; TCP/IP has four layers: Application;
Presentation; Session; Transport; Transport; Internet; Host-to-network
Network; Data link; Physical
Preamble Start of Frame Delimiter Dest. Address Source Address Length 802.2 Header + Data Frame Checksum
(7 bytes) (1 byte) (2/6 bytes) (2/6 bytes) (2 bytes) (46-1500 bytes) (4 bytes)
Preamble :Each frame starts with a preamble of 7 bytes, each byte containing the bit pattern 10101010. Manchester encoding
is employed here and this enables the receiver’s clock to synchronize with the sender’s and initialise
itself.
Start of Frame Delimiter :This field containing a byte sequence 10101011 denotes the start of the frame itself.
Dest. Address :The standard allows 2-byte and 6-byte addresses. Note that the 2-byte addresses are always local addresses
while the 6-byte ones can be local or global.
2-Byte Address - Manually assigned address
Individual(0)/Group(1) Address of the machine
(1 bit) (15 bits)
Multicast : Sending to group of stations. This is ensured by setting the first bit in either 2-byte/6-byte addresses to 1
Broadcast : Sending to all stations. This can be done by setting all bits in the address field to 1.All Ethernet cards(Nodes)
are a member of this group.
Computer Networks S3-231
Source Address :Refer to Dest. Address. Data :Actually this field can be split up into two parts -
Length : The Length field tells how many bytes are Data(0-1500 bytes) and Padding(0-46 bytes).
present in the data field, from a minimum of 0 to a Frame Checksum : It is a 32-bit hash code of the data.
maximum of 1500. The Data and padding together can be If some bits are erroneously received by the destination
from 46bytes to 1500 bytes as the valid frames must be (due to noise on the cable), the checksum computed by
at least 64 bytes long, thus if data is less than 46 bytes the destination wouldn’t match with the checksum sent
the amount of padding can be found out by length field. and therefore the error will be detected.
IEEE 802.5: Token Ring Network it may change the token to a start-of-frame sequence and
Token Ring is formed by the nodes connected in ring transmit the Frame
format as shown in the diagram below. The principle used P = Priority
in the token ring network is that a token is circulating in Priority Bits indicate tokens priority, and therefore, which
the ring and whichever node grabs that token will have stations are allowed to use it. Station can transmit if its priority
right to transmit the data. as at least as high as that of the token.
M = Monitor
The monitor bit is used to prevent a token whose priority is
greater than 0 or any frame from continuously circulating on
the ring. If an active monitor detects a frame or a high priority
token with the monitor bit equal to 1, the frame or token is
aborted. This bit shall be transmitted as 0 in all frame and
tokens. The active monitor inspects and modifies this bit. All
other stations shall repeat this bit as received.
R = Reserved bits
The reserved bits allow station with high priority Frames to request
Token that the next token be issued at the requested priority.
Ending Delimiter Format:
Token Format
The token is the shortest frame transmitted (24 bit) MSB (Most J K I J K I I E
Significant Bit) is always transmitted first - as opposed to
J = Code Violation
Ethernet
K = Code Violation
SD AC ED I = Intermediate Frame Bit
E = Error Detected Bit
SD = Starting Delimiter (1 Octet)
Frame Format:
AC = Access Control (1 Octet)
MSB (Most Significant Bit) is always transmitted first - as
ED = Ending Delimiter (1 Octet)
opposed to Ethernet
Starting Delimiter Format:
SD AC FC DA SA DATA CRC ED FS
J K O J K O O O
SD=Starting Delimiter(1 octet)
J = Code Violation AC=Access Control(1 octet)
K = Code Violation FC = Frame Control (1 Octet)
DA = Destination Address (2 or 6 Octets)
Access Control Format:
SA = Source Address (2 or 6 Octets)
P P P T M R R R DATA = Information 0 or more octets up to 4027
CRC = Checksum(4 Octets)
T=Token ED = Ending Delimiter (1 Octet)
T = 0 for Token FS=Frame Status
T = 1 for Frame
Starting Delimiter Format:
When a station with a Frame to transmit detects a token which
has a priority equal to or less than the Frame to be transmitted, J K 0 J K 0 0 0
S3-232 Computer Networks
J K 1 J K 1 I E
J = Code Violation
K = Code Violation
I = Intermediate Frame Bit
If this bit is set to 1, it indicates that this packet is an
intermediate part of a bigger packet, the last packet would have
this bit set to 0.
E = Error Detected Bit
Computer Networks S3-233
Control Variables
Sender has 3 variables: S, SF, and SL.S holds the
sequence number of recently sent frame.SF holds the
sequence number of the first frame.SL holds the sequence
number of the last frame.Receiver only has the one
variable, R, that holds the sequence number of the frame
it expects to receive. If the seq. no. is the same as the
value of R, the frame is accepted, otherwise rejected.
The ACK can be delayed at the receiver or due to some
problem.It is received after the timer for frame 0 has
expired.Sender retransmitted a copy of frame 0. However,
R =1 means receiver expects to see frame 1. Receiver
discards the duplicate frame 0.Sender receives 2 ACKs, it
discards the second ACK.
Piggybacking
Acknowledgement
Receiver sends positive ACK if a frame arrived safe and
in order. If the frames are damaged/out of order, receiver
is silent and discards all subsequent frames until it
receives the one it is expecting.For example, suppose the
sender has sent frame 6, but the timer for frame 3 expires
(i.e. frame 3 has not been acknowledged), then the sender
goes back and sends frames 3, 4, 5, 6 again. Thus it is
A method to combine a data frame with ACK. Station A and
called Go-Back-N-ARQ.The receiver does not have to
B both have data to send.Instead of sending separately,
acknowledge each frame received, it can send one
station A sends a data frame that includes an ACK.Station
cumulative ACK for several frames.
B does the same thing.Piggybacking saves bandwidth
Go-Back-N ARQ, normal operation
Sender Sliding Window
The sender keeps track of the outstanding frames and
At the sending site, to hold the outstanding frames until
updates the variables and windows as the ACKs arrive.
they are acknowledged, we use the concept of a window.The
size of the window is at most 2m -1 where m is the number
of bits for the sequence number.Size of the window can be
variable, e.g. TCP.The window slides to include new
unsent frames when the correct ACKs are received.
S3-234 Computer Networks
Go-Back-N ARQ, lost frame received and then sender resends only frame 2 and it is
accepted as it is in the range of the window
Selective Repeat ARQ, sender window size
Size of the sender and receiver windows must be at most one-
half of 2m. If m = 2, window size should be 2m /2 = 2. Fig
compares a window size of 2 with a window size of 3. Window
size is 3 and all ACKs are lost, sender sends duplicate of frame
0, window of the receiver expect to receive frame 0 (part of the
window), so accepts frame 0, as the 1st frame of the next cycle
- an error.
Sliding Window
The whole idea behind Sliding Window is not to wait for
an acknowledgment for individual frames, but to send a
few frames (and then get an acknowledgment that
Frame 2 is lost.When the receiver receives frame 3, it discards acknowledges several frames at the same time).
frame 3 as it is expecting frame 2 (according to window).After It works by having the sender and receiver have a
the timer for frame 2 expires at the sender site, the sender sends “window” of frames. The sender can send as many
frame 2 and 3. (go back to 2) frames as would fit into a window. The receiver, upon
Go-Back-N ARQ, damaged/lost/delayed ACK receiving enough frames, will respond with an
If an ACK is damaged/lost, we can have two situations.If the acknowledgment of all frames up to a certain point in the
next ACK arrives before the expiration of any timer, there is no window. The window it then said to “slide”, and the
need for retransmission of frames because ACKs are cumulative whole thing starts again (the sender sends more frames,
in this protocol. the receiver gets more frames, sends an acknowledgment
Go-Back-N ARQ, sender window size of those frames, etc.)
Size of the sender window must be less than 2m. Size of the Each frame has to be numbered in relation to the sliding
receiver is always 1. If m = 2, window size = 2m - 1 = 3. window. For a window of size N, frames get a number
Selective Repeat ARQ, sender and receiver windows from 0 to N - 1. Subsequent frames get a number mod N.
Go-Back-N ARQ simplifies the process at the receiver site.
Receiver only keeps track of only one variable, and there is no ERROR CONTROL
need to buffer out-of-order frames, they are simply Error control involves retransmission of the lost, damaged, or
discarded.However, Go-Back-N ARQ protocol is inefficient for corrupted frame. The scheme is called ARQ, for Automatic
noisy link. It bandwidth inefficient and slows down the Repeat Request.
transmission.In Selective Repeat ARQ, only the damaged frame The general scheme works this way: the sender sends the data.
is resent.It is more bandwidth efficient but more complex If data arrives without any problems, the receiver sends out an
processing at receiver.It defines a negative ACK (NAK) to ACK message (acknowledgment). If the data has a problem
report the sequence number of a damaged frame before the (corrupt), the receiver sends out an NAK (negative
timer expires. acknowledgment). Upon getting a NAK message, the sender
Selective Repeat ARQ, lost frame retransmits. There is also a timer; which allows for data
retransmission if the original message or ACK or NAK got lost.
ROUTI NG ALGORITHMS
Routing is the process of forwarding of a packet in a network
so that it reaches its intended destination.
Classification of Routing Algorithms
The routing algorithms may be classified as follows:
1. Adaptive Routing Algorithm: These algorithms change
their routing decisions to reflect changes in the topology
and in traffic as well. These get their routing information
from adjacent routers or from all routers. The optimization
parameters are the distance, number of hops and estimated
transit time. This can be further classified as follows:
1. Centralized: In this type some central node in the
network gets entire information about the network
topology, about the traffic and about other nodes.
This then transmits this information to the respective
routers.
2. Isolated: In this method the node decides the
routing without seeking information from other
Frames 0 and 1 are accepted when received because they are
nodes. The sending node does not know about the
in the range specified by the receiver window. Same for frame
3.Receiver sends a NAK2 to show that frame 2 has not been status of a particular link.
Computer Networks S3-235
2. Non-Adaptive Routing Algorithm: These algorithms do 1. The Sub-network level, where each node in a region has
not base their routing decisions on measurements and information about its peers in the same region and about
estimates of the current traffic and topology. Instead the the region’s interface with other regions. Different regions
route to be taken in going from one node to the other is may have different ‘local’ routing algorithms. Each local
computed in advance, off-line, and downloaded to the
algorithm handles the traffic between nodes of the same
routers when the network is booted. This is also known
as static routing. This can be further classified as: region and also directs the outgoing packets to the
1. Flooding: Flooding adapts the technique in which appropriate interface.
every incoming packet is sent on every outgoing 2. The Network Level, where each region is considered as a
line except the one on which it arrived. One problem single node connected to its interface nodes. The routing
with this method is that packets may go in a loop. algorithms at this level handle the routing of packets
As a result of this a node may receive several copies between two interface nodes, and is isolated from intra-
of a particular packet which is undesirable. Some regional transfer.
techniques adapted to overcome these problems are
In Hierarchical routing, the interfaces need to store information
as follows:
• Sequence Numbers about:
• Hop Count All nodes in its region which are at one level below it.
• Spanning Tree Its peer interfaces.
2. Random Walk: In this method a packet is sent by At least one interface at a level above it, for outgoing
the node to one of its neighbours randomly. This packages.
algorithm is highly robust. When the network is
highly interconnected, this algorithm has the property Non-Hierarchical Routing
of making excellent use of alternative routes. It is In this type of routing, interconnected networks are viewed as a
usually implemented by sending the packet onto the single network, where bridges, routers and gateways are just
least queued link. additional nodes.
Every node keeps information about every other node in
Delta Routing the network
Delta routing is a hybrid of the centralized and isolated routing
algorithms. Here each node computes the cost of each line (i.e In case of adaptive routing, the routing calculations are
some functions of the delay, queue length, utilization, bandwidth done and updated for all the nodes.
etc) and periodically sends a packet to the central node giving Source Routing
it these values which then computes the k best paths from Source routing is similar in concept to virtual circuit routing. It is
node i to node j. Let Cij1 be the cost of the best i-j path, Cij2 implemented as under:
the cost of the next best path and so on.If Cijn - Cij1 < delta, Initially, a path between nodes wishing to communicate is
(Cijn - cost of n’th best i-j path, delta is some constant) then found out, either by flooding or by any other suitable
path n is regarded equivalent to the best i-j path since their method.
cost differ by so little. When delta -> 0 this algorithm becomes This route is then specified in the header of each packet
routed between these two nodes. A route may also be
centralized routing and when delta -> infinity all the paths
specified partially, or in terms of some intermediate hops.
become equivalent. Policy Based Routing
Multipath Routing In this type of routing, certain restrictions are put on the type of
In the above algorithms it has been assumed that there is a packets accepted and sent. e.g.. The IIT- K router may decide to
single best path between any pair of nodes and that all traffic handle traffic pertaining to its departments only, and reject packets
between them should use it. In many networks however there from other routes. This kind of routing is used for links with very
are several paths between pairs of nodes that are almost low capacity or for security purposes.
equally good. Sometimes in order to improve the performance Shortest Path Routing
multiple paths between single pair of nodes are used. This A network is represented as a graph, with its terminals as nodes
technique is called multipath routing or bifurcated routing. In and the links as edges. A ‘length’ is associated with each edge,
this each node maintains a table with one row for each possible which represents the cost of using the link for transmission. Lower
destination node. A row gives the best, second best, third best, the cost, more suitable is the link. The cost is determined
etc outgoing line for that destination, together with a relative depending upon the criteria to be optimized.
weight. Before forwarding a packet, the node generates a
random number and then chooses among the alternatives, Shortest Path Algorithm
using the weights as probabilities. The tables are worked out 1. Dijktstra’s Algorithm:
manually and loaded into the nodes before the network is At the end each node will be labeled with its distance from
brought up and not changed thereafter. source node along the best known path. Initially, no paths
are known, so all nodes are labeled with infinity. As the
Hierarchical Routing algorithm proceeds and paths are found, the labels may
This is essentially a ‘Divide and Conquer’ strategy. The network change reflecting better paths. Initially, all labels are tentative.
is divided into different regions and a router for a particular region When it is discovered that a label represents the shortest
knows only about its own domain and other routers. Thus, the possible path from the source to that node, it is made
network is viewed at two levels: permanent and never changed thereafter.
S3-236 Computer Networks
Look at the weighted undirected graph where the weights Whenever a node is relabeled, we also label it with the node
represent, for example, distance. We want to find shortest from which the probe was made so that we can construct
path from A to D. We start by making node A as permanent, the final path later. Having examined each of the nodes
indicated by a filled in circle. adjacent to A, we examine all the tentatively labeled nodes
Then we examine each of the nodes adjacent to A (the in the whole graph and make the one with the smallest label
working node), relabeling each one with the distance to A. permanent, This one becomes new working node.
B 7 C B(2, A) C(¥, –)
2 3
2 E 2 F 3 E(¥, –)
A
1 2 D A F(¥, –) D(¥, –)
6 4 2
G (a) H G(6, A) (b) H(¥, –)
E(4, B) E(4, B)
A F(¥, –) D(¥, –) A F(6, E) D(¥, 1)
E(4, B) E(4, B)
A F(6, E) D(¥, –) A F(6, E) D(¥, –)
We now start at B, and examine all nodes adjacent to it. If CONGESTION CONTROL
the sum of the label on B and the distance from B to the
Problem: When too many packets are transmitted through a
node being considered is less than the label on the node,
we have a shorter path, so the node is relabeled. After all network, congestion occurs.
the nodes adjacent to the working node have been At very high traffic, performance collapses completely, and almost
inspected and the tentative labels changed if possible, the no packets are delivered.
entire graph is searched for the tentatively labeled node
with the smallest value. This node is made permanent and Perfect
becomes the working node for the next round. Maximum carrying
2. Bellman Ford’s Algorithm: capacity of subnet
Packets delivered
It eliminates bursts completely packets passed to the subnet Closed Loop Congestion Control
at the same rate Congestion Control in Virtual Circuits
This may be a bit overdone, and also packets can get lost
These are closed-loop based designed for virtual circuits
(when bucket is full)
Token bucket: Tokens are added at a constant rate. For a subnets, which are connection oriented ® during
packet to be transmitted, it must capture and destroy one connection set up, something can be done to help
token congestion control.
(a) shows that the bucket holds three tokens with five The basic principle is obvious: When setting up a virtual
packets waiting to be transmitted circuit, make sure that congestion can be avoided.
(b) shows that three packets have gotten through but the
• Admission control: Once congestion has been
other two are stuck waiting for tokens to be generated
Unlike leaky bucket, token bucket allows saving, up to signaled, no more new virtual circuits can be set up
maximum size of bucket n. This means that bursts of up to n until the problem has gone away. This is crude but
packets can be sent at once, giving faster response to simple and easy to do
sudden bursts of input • Select alternative routes to avoid part of the
An important difference between two algorithms: token network that is overloaded, i.e. temporarily rebuild
bucket throws away tokens when the bucket is full but your view of network
never discards packets while leaky bucket discards
packets when the bucket is full. Congestion
A
Let token bucket capacity be C (bits), token arrival rate
r (bps), maximum output rate M (bps), and burst length
S (s)
– During burst length of S (s), tokens generated are rS
(bits), and output burst contains a maximum of C +
rS (bits)
B
– Also output in a maximum burst of length S (s) is M
· S (bits), thus
C
C + rS = MS or d =
M -r
Token bucket still allows large bursts, even though the Congestion
maximum burst length S can be regulated by careful (a)
selection of r and M
• One way to reduce the peak rate is to put a leaky A
bucket of a larger rate (to avoid discarding packets)
after the token bucket.
Faucet
Host
computer B
Packet
Unregulated Virtual
Leaky
flow circuit
bucket The bucket (b)
Water holds packets
Interface Regulated e.g. Normally, when router A sets a connection to B, it
containing flow would pass through one of the two congested routers, as
a leaky bucket
Water drps out this would result in a minimum-hop route (4 and 5 hops
of the hole
at a constant rate
respectively). To avoid congestion, a temporary subnet is
Network
redrawn by eliminating congested routers. A virtual
(a) (b)
circuit can then be established to avoid congestion
• Negotiate quality of connection in advance, so that
Host Host network provider can reserve buffers and other
computer computer resources, guaranteed to be there.
Choke Packets
This closed-loop congestion control is applicable to both
One token is added The bucket virtual circuits and datagram subnets
to the bucket holds tokens
every DT
Networks Networks
(a) (b)
S3-238 Computer Networks
ok
to router E as well as reduces its traffic to D. Thus the problem
ok
Ch
Ch
Ch
ok
ok
e
e
Us age : TCP is used in case of non-time critical UDP is used for games or applications that require
applications. fast transmission of data. UDP's stateless nature is
also useful for servers that answer small queries
from huge numbers of clients.
Examples: HTTP, HTTPs, FTP, SMTP Telnet etc... DNS, DHCP, TFTP, SNMP, RIP, VOIP etc...
Orde ring of data TCP rearranges data packets in the order UDP has no inherent order as all packets are
packets: specified. independent of each other. If ordering is required, it
has to be managed by the application layer.
Spe e d of transfe r: The speed for TCP is slower than UDP. UDP is faster because there is no error-checking for
packets.
Re liability: There is absolute guarantee that the data There is no guarantee that the messages or packets
transferred remains intact and arrives in the sent would reach at all.
same order in which it was sent.
He ade r Size : TCP header size is 20 bytes UDP Header size is 8 bytes.
Common He ade r Source port, Destination port, Check Sum Source port, Destination port, Check Sum
Fie lds:
Streaming of data: Data is read as a byte stream, no Packets are sent individually and are checked for
distinguishing indications are transmitted to integrity only if they arrive. Packets have definite
signal message (segment) boundaries. boundaries which are honored upon receipt, meaning
a read operation at the receiver socket will yield an
entire message as it was originally sent.
We ight: TCP requires three packets to set up a UDP is lightweight. There is no ordering of
socket connection, before any user data can messages, no tracking connections, etc. It is a small
be sent. TCP handles reliability and transport layer designed on top of IP.
congestion control.
Data Flow Control: TCP does Flow Control. TCP requires three UDP does not have an option for flow control
packets to set up a socket connection,
before any user data can be sent. TCP
handles reliability and congestion control.
Error Che cking: TCP does error checking UDP does error checking, but no recovery options.
Fie lds: 1. Sequence Number, 2. AcK number, 3. 1. Length, 2. Source port, 3. Destination port, 4.
Data offset, 4. Reserved, 5. Control bit, 6. Check Sum
Window, 7. Urgent Pointer 8. Options, 9.
Padding, 10. Check Sum, 11. Source port,
12. Destination port
Acknowle dge ment: Acknowledgement segments No Acknowledgment
S3-240 Computer Networks
5. Match the List I with list II and select the correct answer by using the codes given below the lists. [2004, 1 Mark]
Lis t I Lis t II
P. Data link layer 1. Ens ures reliable trans port of data over a phys ical point-to-point link.
Q. Network layer 2. Encodes /decodes data for phys ical trans mis sion.
R. Trans port layer 3. A llows en d-to-end communication between two proces es .
4. Routes data from one network node to the next.
11. Match the List I with List II and select the correct answer by (a) 1 and 2 (b) 1 and 3
using the codes given below the lists. [2007, 2 Marks] (c) 2 and 4 (d) 3 and 4
18. One of the header fields in an IP datagram is the Time To
List I List II
Live (TTL) field. Which of the following statements best
explains the need for the field? [2010, 1 Mark]
P: SMTP 1. Application layer (a) It can be used to prioritize packets
Q: BGP 2. Transport layer (b) It can be used to reduce delays
R: TCP 3. Data link layer (c) It can be used to optimize throughput
S: PP 4. Networ k layer (d) It can be used to prevent packet looping
5. Physical layer 19. HTML (Hyper Text Markup Language) has language
elements which permit certain actions other than describing
(a) P - 2, Q - 1, R - 3, S - 5 (b) P - 1, Q - 4, R - 2, S - 3 the structure of the web document. Which one of the
(c) P - 1, Q - 4, R - 2, S - 5 (d) P - 2, Q - 4, R - 1, S - 3 following actions is not supported by pure HTML (without
12. Which one of the following uses UDP as the transport any server or client side scripting) pages? [2011, 1 Mark]
protocol? [2007, 1 Mark] (a) Embed web objects from different sites into the same
(a) HTTP (b) Telnet page
(c) DNS (d) SMTP (b) Refresh the page automatically after a specified interval
13. In Ethernet when Manchester encoding is used, the bit rate (c) Automatically redirect to another page upon download
is [2007, 1 Mark] (d) Display the client time as part of the page
(a) half the baud rate (b) twice the baud rate 20. Consider the different activities related to email:
(c) same as the baud rate (d) None of these m1: Send an email from a mail client to a mail server.
14. A client process P needs to make a TCP connection to a m2: Download an email from mailbox server to a mail client.
server process S. Consider the following situation. The server m3: Checking email in a web browser. [2011, 1 Mark]
process S executes a socket (), a bind () and a listen () system Which is the application level protocol used in each activity?
call in that order, following which it is preempted. (a) m1: HTTP m2: SMTP m3 : POP
Subsequently, the client process P executes a socket () (b) m1: SMTP m2: FTP m3 : HTTP
system call followed by connect () system call to connect to (c) m1: SMTP m2: POP m3 : HTTP
the server process S. The server process has not executed (d) m1: POP m2: SMTP m3 : IMAP
any accept () system call. Which one of the following events 21. The Protocol Data Unit (PDU) for the application layer in the
could take place? [2007, 2 Marks] Internet stack is [2012, 1 Mark]
(a) Connect () system call returns successfully (a) segment (b) datagram
(b) Connect () system call blocks (c) message (d) frame
(c) Connect () system call returns an error 22. The transport layer protocols used for real time
(d) Connect () system call returns in a core dump multimedia, file transfer, DNS and e-mail, respectively are
15. In the slow start phase of the TCP congestion control [2013, 1 Mark]
algorithm, the size of the congestion window [2008, 2 Marks] (a) TCP, UDP, UDP and TCP
(a) does not increase (b) increases linearly (b) UDP, TCP, TCP and UDP
(c) increases quadratically (d) increases exponentially (c) UDP, TCP, UDP and TCP
16. Which of the following system calls results in the sending
(d) TCP, UDP, TCP and UDP
of SYN packets? [2008, 1 Mark]
(a) Socket (b) Bind 23. Using public key cryptography, X adds a digital signature
(c) Listen (d) Connect s to message M, encrypts < M, s > and sends it to Y,
17. In the RSA public key cryptosystem, the private and public where it is decrypted. Which one of the following
sequences of keys is used for the operations?
keys are (e, n) and (d, n) respectively, where n = p*q and p
[2013, 1 Mark]
and q are large primes. Besides, n is public and p and q are
private. Let M be an integer such that 0 < M < n and f (n) (a) Encryption: X’s private key followed by Y’s private
= (p – 1) (q – 1). Now consider the following equations. key; Decryption: X’s public key followed by Y’s
[2009, 2 Marks] private key
1. M’ = Me mod n (b) Encryption: X’s private key followed by Y’s public
M = (M’)d mod n key; Decryption: X’s public key followed by Y’s
2. ed º 1 mod n private key
3. ed = 1 mod f n (c) Encryption: X’s public key followed by Y’s private
4. M’ = Me mod f n key; Decryption: Y’s public key followed by X’s
M = (M’)d mod f n private key
Which of the above equations correctly represent RSA (d) Encryption: X’s private key followed by Y’s public
cryptosystem? key; Decryption: Y’s private key followed by X’s
public key
Computer Networks S3-243
24. Assume that source S and destination D are connected 30. An IP machine Q has a path to another IP machine H via
through two intermediate routers labelled R. Determine three IP routers R1, R2, and R3.
how many times each packet has to visit the network Q—R1—R2—R3—H
layer and the data link layer during a transmission from H acts as an HTTP server, and Q connects to H via HTTP
S to D. [2013, 1 Mark] and downloads a file. Session layer encryption is used,
with DES as the shared key encryption protocol. Consider
the following four pieces of information:
S R R D
[I1] The URL of the file downloaded by Q
[I2] The TCP port numbers at Q and H
(a) Network layer–4 times and Data link layer–4 times [I3] The IP addresses of Q and H
(b) Network layer–4 times and Data link layer–3 times [I4] The link layer addresses of Q and H
(c) Network layer–4 times and Data link layer–6 times Which of I1, I2, I3, and I4 can an intruder learn through
(d) Network layer–2 times and Data link layer–6 times sniffing at R2 alone? [2014, Set-2, 2 Marks]
25. Which of the following are used to generate a message (a) Only I1 and I2 (b) Only I1
digest by the network security protocols? (c) Only I2 and I3 (d) Only I3 and I4
[2014, Set-1, 1 Mark] 31. Host A (on TCP/IP v4 network A) sends an IP datagram D
(P) RSA (Q) SHA-1 to host B (also on TCP/IP v4 network B). Assume that no
(R) DES (S) MD5 error occurred during the transmission of D. When D reaches
(a) (P) and (R) only (b) (Q) and (R) only B, which of the following IP header field(s) may be different
(c) (Q) and (S) only (d) (R) and (S) only from that of the original datagram D?
26. Identify the correct order in which the following actions (i) TTL (ii) Checksum
take place in an interaction between a web browser and a (iii) Fragment Offset [2014, Set-3, 1 Mark]
web server. (a) (i) only (b) (i) and (ii) only
1. The web browser requests a webpage using HTTP. (c) (ii) and (iii) only (d) (i), (ii) and (iii)
2. The web browser establishes a TCP connection with
the web server. Problem Based MCQs
3. The web server sends the requested webpage using
32. The subnet mask for a particular network is 255.255.31.0.
HTTP.
4. The web browser resolves the domain name using Which of the following pairs of IP addresses could
DNS. [2014, Set-1, 1 Mark] belong to this network? [2003, 2 Marks]
(a) 4, 2, 1, 3 (b) 1, 2, 3, 4 (a) 172.57.88.62 and 172.56.87.233
(c) 4, 1, 2, 3 (d) 2, 4, 3 (b) 10.35.28.2 and 10.35.29.4
27. Which one of the ofllowing is TRUE about the interior (c) 191.203.31.87 and 191.234.31.88
gateway routing protocols - Routing Information Protocol (d) 128.8.129.43 and 128.8.161.55
(RIP) and Open Shortest Path First (OSPF) ?
33. A 2 km long broadcast LAN has 107 bps bandwidth and
[2014, Set-2, 1 Mark]
uses CSMA/CD. The signal travels along the wire at
(a) RIP uses distance vector routing and OSPF uses link
state routing 2 × 108 m/s. What is the minimum packet size that can be
(b) OSPF uses distance vector routing and RIP uses link used on this network? [2003, 2 Marks]
state routing (a) 50 bytes (b) 100 bytes
(c) Both RIP and OSPF use link state routing (c) 200 bytes (d) None of these
(d) Both RIP and OSPF use distance vector routing 34. Host A is sending data to host B over a full duplex link.
28. Which one of the following socket API functions converts A and B are using the sliding window protocol for flow
an unconnected active TCP socket into a passive socket?
control. The send and receive window sizes are 5 packets
[2014, Set-2, 1 Mark]
each. Data packets (sent only from A to B) are all 1000
(a) Connect (b) Bind
byte long and the transmission time for such a packet is
(c) Listen (d) Accept
29. In the following pairs of OSI protocol layer/sub-layer and 50 ms Acknowledgement packets (sent only from B to A)
its functionality, the INCORRECT pair is are very small and require negligible transmission time.
[2014, Set-3, 1 Mark] The propagation delay over the link is 200 ms. What is the
(a) Network layer and Routing maximum achievable through put in this communication?
(b) Data Link Layer and Bit synchronization [2003, 2 Marks]
(c) Transport layer and End-to-end process communication 6
(a) 7.69 × 10 bps (b) 11.11 × 106 bps
(d) Medium Access Control sub-layer and Channel 6
(c) 12.33 × 10 bps (d) 15.00 × 106 bps
sharing
S3-244 Computer Networks
35. The routing table of a router is shown below : back-n error control strategy. All packets are ready and
immediately available for transmission. If every 5th packet
Destination Subnet Mask Interface that A transmits gets lost (but no acts from B ever get lost),
128.75.43.0 255.255.255.0 Eth 0 then what is the number of packets that A will transmit for
128.75.43.0 255.255.255.128 Eth 1 sending the message to B? [2006, 2 Marks]
192.12.17.5 255.255.255.255 Eth 3 (a) 12 (b) 14
D efault Eth 2 (c) 16 (d) 18
43. Station A uses 32 byte packets to transmit messages to
On which interface will the router forward packets Station B using a sliding window protocol. The round trip
addressed to destinations 128.75.43.16 and 192.12.17.10 delay between A and B is 80 ms and the bottleneck bandwidth
respectively? [2004, 2 Marks] on the path between A and B is 12 kbps. What is the optimal
(a) Eth 1 and Eth 2 (b) Eth 0 and Eth 2 window size that A should use? [2006, 2 Marks]
(c) Eth 0 and Eth 3 (b) Eth 1 and Eth 3 (a) 20 (b) 40
36. How many 8-bit characters can be transmitted per second (c) 160 (d) 320
over a 9600 baud serial communication link using 44. The distance between two stations M and N is L km. All
asynchronous mode of transmission with one start bit, frames are K bits long. The propagation delay per kilometer
eight data bits, two stop bits and one parity bit?
is t s. Let R b/s be the channel capacity. Assuming that
[2004, 1 Mark]
processing delay is negligible, the minimum number of bits
(a) 600 (b) 800
(c) 876 (d) 1200 for the sequence number field in a frame for maximum
37. A and B are the only two stations on an Ethernet. Each utilization, when the sliding window protocol is used, is
has a steady queue of frames to send. Both A and B [2007, 2 Marks]
attempt to transmit a frame, collide, and A wins the first é 2LTR + 2K ù é 2LTR ù
backoff race. At the end of this successful transmission (a) ê log 2 K ú (b) ê log 2
K úû
ë û ë
by A, both A and B attempt to transmit and collide. The
probability that A wins the second backoff race is é 2LTR + K ù é 2LTR + K ù
[2004, 2 Marks]
(c) êlog 2 K ú (d) êlog 2
2K ú
ë û ë û
(a) 0.5 (b) 0.625 45. The message 11001001 is to be transmitted using the CRC
(c) 0.75 (d) 1.0 polynomial x3 + 1 to protect it from errors. The message that
38. An organization has a class-B network and wishes to should be transmitted is [2007, 2 Marks]
form subnets for 64 departments. The subnet mask would (a) 11001001000 (b) 11001001011
be [2005, 1 Mark] (c) 11001010 (d) 110010010011
(a) 255.255.0.0 (b) 255.255.64.0 46. The address of a class B host is to be split into subnets with
(c) 255.255.1.28.0 (d) 255.255.252.0 a 6-bit subnet number. What is the maximum number of
39. The maximum window size for data transmission using the subnets and the maximum number of hosts in each subnet?
selective reject protocol with n-bit frame sequence number [2007, 2 Marks]
is [2005, 1 Mark] (a) 62 subnets and 262142 hosts
(a) 2n (b) 2n–1 (b) 64 subnets and 262142 hosts
(c) 2n – 1 (d) 2n – 2 (c) 62 subnets and 1022 hosts
40. In a packet switching network, packets are routed from source (d) 64 subnets and 1024 hosts
47. In a token ring network, the transmission speed is 107 bps
to destination along a single path having two intermediate
and the propagation speed is 200 m/ms. The 1-bit delay in
nodes. If the message size is 24 byte and each packet this network is equivalent to [2007, 2 Marks]
contains a header of 3 byte, then the optimum packet size is (a) 500 m of cable (b) 200 m of cable
[2005, 2 Marks] (c) 20 m of cable (d) 50 m of cable
(a) 4 (b) 6 48. There are n stations in a slotted LAN. Each station attempts
to transmit with a probability p in each time slot. What is the
(c) 7 (d) 9
probability that only one station transmits in a given time
41. Suppose the round trip propagation delay for a 10 Mbps slot? [2007, 2 Marks]
Ethernet having 48 bit jamming signal is 46.4 ms. The minimum (a) np(1 – p)n – 1 (b) (1 – p)n – 1
frame size is [2005, 2 Marks] (c) p(1 – p)n – 1 (d) 1 – (1 – p)n – 1
(a) 94 (b) 416 49. If a class B network on the Internet has a subnet mask of
255.255.248.0, what is the maximum number of hosts per
(c) 464 (d) 512 subnet? [2008, 2 Marks]
42. Station A needs to send a message consisting of 9 packets (a) 1022 (b) 1023
to Station B using a sliding window (window size 3) and go- (c) 2046 (d) 2047
Computer Networks S3-245
50. What is the maximum size of data that the application layer (a) 1005 ms (b) 1010 ms
can pass on to the TCP layer below? [2008, 1 Mark] (c) 3000 ms (d) 3003 ms
(a) Any size 57. An Internet Service Provider (ISP) has the following chunk
(b) 216 byte size of TCP header of CIDR-based IP addresses available with it; 245.248. 128.0/
(c) 216 byte 20. The ISP wants to give half of this chunk of addresses to
(d) 1500 byte organization A and a quarter to organization B, while retaining
51. A computer on a 10 Mbps network is regulated by a token the remaining with itself. Which of the following is a valid
bucket. The token bucket is filled at a rate of 2 Mbps. It is allocation of addresses to A to B? [2012, 2 Marks]
initially filled to capacity with 16 Megabits. What is the (a) 245.248. 136.0/21 and 245.248. 128.0/022
maximum duration for which the computer can transmit at (b) 245.248. 128.0/21 and 245.248. 128.0/22
the full 10 Mbps? [2008, 2 Marks] (c) 245.248. 132.0/22 and 245.248. 132.0/21
(a) 1.6 s (b) 2 s (d) 245.248. 136.0/24 and 245.248. 132.0/21
(c) 5 s (d) 8 s 58. Consider an instance of TCP’s Additive Increase
52. Let G(x) be the generator polynomial used for CRC checking. Multiplicative Decrease (AIMD) algorithm where the
What is the condition that should be satisfied by G(x) to Window size at the start of the slow phase is 2 MSS and the
detect odd number of bits in error? [2009, 2 Marks] threshold at the start of the first transmission is 8 MSS.
(a) G(x) contains more than two terms Assume that a timeout occurs during the fifth transmission.
(b) G(x) does not divide 1 + xk, for any k not exceeding the
Find the congestion Window size at the end of the tenth
frame length
transmission. [2012, 2 Marks]
(c) 1 + x is a factor of G(x)
(a) 8 MSS (b) 14 MSS
(d) G(x) has an odd number of terms
(c) 7 MSS (d) 12 MASS
53. While opening a TCP connection, the initial sequence
number is to be derived using a time-of-day (ToD) clock that 59. Determine the maximum length of the cable (in km) for
keeps running even when the host is down. The low order transmitting data at a rate of 500 Mbps in an Ethernet
32 bits of the counter of the ToD clock is to be used for the LAN with frames of size 10,000 bits. Assume the signal
initial sequence numbers. The clock counter increments once speed in the cable to be 2,00,000 km/s. [2013, 2 Marks]
per millisecond. The maximum packet lifetime is given to be (a) 1 (b) 2
64s. Which one of the choices given below is closest to the (c) 2.5 (d) 5
minimum permissible rate at which sequence numbers used
60. In an IPv4 datagram, the M bit is 0, the value of HLEN
for packets of a connection can increase? [2009, 2 Marks] is 10, the value of total length is 400 and the fragment
(a) 0.015/s (b) 0.064/s offset value is 300. The position of the datagram, the
(c) 0.135/s (d) 0.327/s sequence numbers of the first and the last bytes of the
54. A layer-4 firewall (a device that can look at all protocol payload, respectively are [2013, 2 Marks]
headers up to the transport layer) cannot [2011, 1 Mark] (a) Last fragment, 2400 and 2789
(a) block entire HTTP traffic during 9:00 PM and 5:00 AM (b) First fragment, 2400 and 2759
(b) block all ICMP traffic (c) Last fragment, 2400 and 2759
(c) stop incoming traffic from a specific IP address but (d) Middle fragment, 300 and 689
allow outgoing traffic to the same IP address 61. Consider the store and forward packet switched network
(d) block TCP traffic from a specific user on a multi-user given below. Assume that the bandwidth of each link is 106
system during 9:00 PM and 5:00 AM bytes / sec. A user on host A sends a file of size 103 bytes to
55. Suppose computers A and B have IP addresses 10.105.1.113 host B through routers R1 and R2 in three different ways. In
and 10.105.1.91 respectively and they both use the same net the first case a single packet containing the complete file is
mask N. Which of the values of N given below should not transmitted from A to B. In the second case, the file is split
be used, if A and B should belong to the same network? into 10 equal parts, and these packets are transmitted from
[2011, 2 Marks] A to B. In the third case, the file is split into 20 equal parts
(a) 255.255.255.0 (b) 255.255.255.128 and these packets are sent from A to B. Each packet contains
(c) 255.255.255.192 (d) 255.255.255.244 100 bytes of header information along with the user data.
56. Consider a source computer (S) transmitting a file of size 106 Consider only transmission time and ignore processing,
bit to a destination computer (D) over a network of two queuing and propagation delays. Also assume that there
routers (R1 and R2) and three links (L1, L2 and L3). L1 are no errors during transmission. Let T1, T2 and T3 be the
connects S to R1; L2 connects R1 to R2 and L3 connects R2 times taken to transmit the file in the first, second and third
to D. Let each link be of length 100 km. Assume signals case respectively. Which one of the following is CORRECT?
travel over each link at a speed of 108 m/s. Assume that the
link bandwidth on each link is 1 Mbit/s. Let the file be broken A R1 R2 B
down into 1000 packets each of size 1000 bits. Find the total [2014, Set-2, 2 Marks]
sum of transmission and propagation delays in transmitting (a) T1 < T2 < T3 (b) T1 > T2 > T3
the file from S to D? [2012, 2 Marks] (c) T2 = T3, T3 < T1 (d) T1 = T3, T3 > T2
S3-246 Computer Networks
62. An IP router with a Maximum Transmission Unit (MTU) of void prt Fun (void)
1500 bytes has received an IP packet of size 4404 bytes with { static int a = 2;
an IP header of length 20 bytes. The values of the relevant int b = 1 ;
fields in the header of the third IP fragment generated by a + = + + b;
the router for this packet are [2014, Set-3, 2 Marks] }
(a) MF bit: 0, Datagram Length: 1444; Offset: 370 printf (“\n %d” %d”, a, b);
(b) MF bit: 1, Datagram Length: 1424; Offset: 185 66. In the IPv4 addressing format, the number of networks
(c) MF bit: 1, Datagram Length: 1500; Offset: 370 allowed under Class C addresses is [2012, 1 Mark]
(d) MF bit: 0, Datagram Length: 1424; Offset: 2960 (a) 214 (b) 27
63. A bit-stuffing based framing protocol uses an 8-bit delimiter (c) 221 (d) 224
pattern of 01111110. If the output bit-string after stuffing is 67. Which of the following transport layer protocols is used to
01111100101, then the input bit-string is support electronic mail? [2012, 1 Mark]
[2014, Set-3, 1 Mark] (a) SMTP (b) IP
(a) 0111110100 (b) 0111110101 (c) TCP (d) UDP
(c) 0111111101 (d) 0111111111
Linked Answer Type MCQs
Common Data MCQs
Statements for Linked Answer Questions 68 and 69
Common Data for Questions 64 and 65 Consider the diagram shown below where a number of LANs are
Consider three IP networks A, B and C. Host HA in connected by (transparent) bridges. In order to avoid packets
networks A sends message each containing 180 byte of looping through circuits in the graph, the bridges organize
application data to a host HC in network C. The TCP layer
themselves in a spanning tree. First, the root bridge is identified
prefixes a 20 byte header to the message. This passes
through an intermediate network B. The maximum packet as the bridge with the least serial number. Next, the root sends
size, including 20 byte IP header, in each network is out (one or more) data units to enable the setting up of the
A : 1000 byte spanning tree of shortest paths from the root bridge to each
B : 100 byte bridge.
C : 1000 byte Each bridge identifies a port (the root port) through which it will
The network A and B are connected through a 1 Mbps
forward frames to the root bridge. Port conflicts are always
link, while B and C are connected by a 512 kbps link (bps
= bits per second). resolved in favour of the port with the lower index value. When
there is a possibility of multiple bridges forwarding to the same
Network A 1 Mbps Network B 512 Mbps Network C LAN (but not through the root port), ties are broken as follows:
bridges closest to the root get preference and between such
64. What is the rate at which application data is transferred brides, the one with the lowest serial number is preferred.
to host HC? Ignore errors, acknowledgements, and other
overheads. [2004, 2 Marks] B1
(a) 325.5 kbps (b) 354.5 kbps 1 2
H1 H2 H3 H4
(c) 409.6 kbps (d) 512.0 kbps
65. Assuming that the packets are correctly delivered, how
many bytes, including headers, are delivered to the IP 2 3
layer at the destination for one application message, in B5 4 B3
the best case? Consider only data packets. 3
1 4 1 2
[2004, 2 Marks]
(a) 200 (b) 220
(c) 240 (d) 260
H5 H6 H7 H8
Common Data for questions 66 and 67 2 2 1
1
Consider the following C code segment : B4 B2
int a, b, c = 0 ; 3 3
void prtFun (void);
main ( ) H9 H10 H11 H12
{ static int a = 1; /* Line 1 */
prtFun ( ); 68. For the given connection of LANs by bridges, which one of
a + = 1; the following choices represents the depth first traversal of
prt Fun ( ) ; the spanning tree of bridges? [2006, 2 Marks]
printf (“\n %d %d” , a, b) ; (a) B1, B5, B3, B4, B2 (b) B1, B3, B5, B2, B4
} (c) B1, B5, B2, B3, B4 (d) B1, B3, B4, B5, B2
Computer Networks S3-247
69. Consider the correct spanning tree for the previous question.
R2 7 R4
Let host H1 send out a broadcast ping packet. Which of the
following options represents the correct forwarding table 6 8
on B3? [2006, 2 Marks] 2 1 R6
R1
Host Port 4
3
H1, H2, H3, H4 3
R3 9 R5
(a) H5, H6, H9, H10 1
H7, H8, H11, H12 2 72. All the routers use the distance vector based routing
algorithm to update their routing tables. Each router starts
with its routing table initialized to contain an entry for each
Host Port neighbour with the weight of the respective connecting link.
H1, H2 4 After all the routing tables stabilize, how many links in the
H3, H4 3 network will never be used for carrying any data?
(b) [2011, 2 Marks]
H5, H6 1
(a) 4 (b) 3
H7, H8, H9, H10, H11, H12 2 (c) 2 (d) 1
73. Suppose the weights of all unused links in the previous
Host Port question are changed to 2 and the distance vector algorithm
H3, H4 3 is used again until all routing tables stabilize. How many
links will now remain unused? [2011, 2 Marks]
H5, H6, H9, H10 1
(c) (a) 0 (b) 1
H1, H2 4 (c) 2 (d) 3
H7, H8, H11, H12 2 Statements for Linked Answer Questions 74 and 75
Consider a network with five nodes, N1 to N5, as shown below:
Host Port
3 1
H1, H2, H3, H4 3 N5 N2 N1
(d) H5, H7, H9, H10 1
H7, H8, H9, H10 4 4 6
CONCEPTUAL MCQs only by the routing tables in the routers on the way.
It is the routing algorithms and the routing tables
1. (a) The primary use of padding is to prevent the which determine the route of outgoing packets.
cryptanalyst from using that predictability to find 3. (d) The transport layer of TCP/IP model is very similar
cribs that aid in breaking the encryption. Hence, to the transport layer of OSI model. The transport
padding bits are used to protect the bits. All the layer is more commonly known as Host to Host
bytes that are required to be padded are padded protocol layer as it is responsible to setup and
with zero. maintain (end to end communication) between two
There are two types of padding methods : Bit hosts. Hence, the transport protocols maintain the
padding/Byte padding and Zero padding. end to end connectivity.
Bit Padding : Two types of bits are used in the 4. (b) Bridge is the device which work at data link layer
process : Single set bit generally represented by 1 whereas router works at network layer. Both
and Reset Bit 0. A single set (1) bit is added to a selectively forward packets, build routing table &
message and then as many reset (0) bits as connect between LAN & WAN but since bridge
necessary are added to the same message. The total works at data link it uses MAC addresses to route
number of reset (0) bits added actually depends on whereas router uses IP addresses.
the boundary of the message to which the message 5. (a) Transport layer functions as a communication layer
needs to be extended. In bit terms this is 1000 ... for any kind of end to end communication, creation
0000, in hex byte terms this is 80 00 ... 0000. of sockets. Network layer routes the data from one
For example, a message of 23 bit that is padded with node to other, till it reach to destination. Datalink
9 bits in order to fill a 32 bit block layer ensures reliable data transfer by error correction,
... | 1011 1001 1101 0100 0010 0111 0000 0000| duplication check ordered delivery etc.
Zero Padding : In zero padding, all bytes are 6. (b) By the definition
padded with zero. Example : In the following Spanning tree protocol (STP) is a link layer network
example the block size is 8 byte and padding is protocol that ensures a loop-free topology for any
required for 4 byte bridged LAN. Thus, the basic function of STP is to
... |DD DD DD DD DD DD DD DD| DD DD DD DD prevent bridge loops and ensuing broadcast radiation
00 00 00 00 | and this is why the STP is used for Bridge Routing.
Zero padding makes it impossible to distinguish 7. (d) Address Resolution Protocol (ARP) is a computer
between plain text data bytes and padding bytes as networking protocol used by the Internet Protocol
it is not reversible in the case when original file (IP) for determining a network host’s link layer or
ends with one or more zero bytes hardware address (MAC Address) when only its
Internet Layer (IP) or Network Layer address is
2. (a) Option (a) : A computer cannot have more than one known. The protocol operates as a part of the
IP Address. It is only with the case, if a computer interface between the OSI network and OSI link
is attached with two different Ethernet adaptors. layer below the network layer.
Also, two computers cannot have same IP address.
As discussed, the term address resolution refers to
Option (b) : In a connectionless transmission, an IP the process of finding an address of a computer in
packet can take many different routes as determined a network. In this process, a piece of information is
by the routing algorithms. sent by a client process executing on the local
Option (c) : IP ensures that a packet is discarded, computer to a server process executing on a remote
if it is unable to reach its destination within a given computer to resolve the address. The information
number of hops. This is ensured by TTL (Time to which is received by the server enables it to
Live). Time to live (TTL) is a limit on the period of uniquely identify the network system for which the
time or transmissions in computer and computer address was required and hence, to provide the
network technology that a unit of data (e.g., a required address. The address resolution procedure
packet) can experience before it should be discarded. is successfully completed when the client receives
If the limit is not defined then the packets can go the required address as the response from the
into an indefinite loop. server.
Option (d) : The packet source cannot set the route Reverse of ARP is called Reverse Address Resolution
of an outgoing packets; the route is determined Protocol (RARP).
S3-250 Computer Networks
The handshake (TCP Handshaking) between sender 22. (c) The Transport layers protocols used for
and receiver is established by connect so that SYN l. Real Time Multimedia can be unreliable but has
packets could be sent. to be tast so UDP.
TCP knows whether the network connection is 2. File Transfer has to be secure and reliable so
opening, synchronizing or established by using the uses TCP.
SYNchronize 3. DNS Domain name system can be both TCP and
and ACKnowledge messages when establishing a UDP
network connection. 4. Email User TCP for reliability.
When the communication between two computer ends, Hence, answer is option (c) UDP, TCP, UDP and TCP
another 3-way communication is performed to tear 23. (d) As stated X adds a digital signature s to message M
down the TCP connection. This setup and teardown encrypts < M, s > and transmits it to Y.
of a TCP connection is part of what qualifies TCP a In order to the make sure that Y receives the
reliable protocol. message and is able to decrypt it the following
17. (b) The RSA laboratories define RSA cryptosystems as sequences of keys is used for the operations.
the following (D) Encryption X’s private key followed by Y’s
The RSA cryptosystem is a public-key cryptosystem public key The message needs to be encrypted by
that offers both encryption and digital signatures the sender’s private key and receiver’s public key in
(authentication). Ronald Rivest, Adi Shamir and order to maintain authenticity and confidentiality.
Leonard Adleman developed the RSA system in 1977; Decryption Y’s private key followed by X’s public
RSA stands for the first letter in each of its investor’s key On receiving the encrypted message, receiver Y
last names. will have to decrypt it using his own private key and
The RSA algorithm works as follows: take two large by using sender X’s public key.
primes, p and q, and compute their product n = pq, n is 24. (c)
called the modulus. Choose a number, e, less than n
and relatively prime to (p – 1) (q – 1), which means e NL NL NL
DLL DLLDLL DLL NL
and (p – 1) (q – 1) have no common factors except 1. DDLL PL PL PL DLL
PL
Find another number d such that (ed – 1) is divisible by PL S R R D PL
(p – 1) (q – 1). The values e and d are called the public
\ Each packet has to visit the network layer 4
and private exponents, respectively. The public key is
times and the data link layer 6 times during a
the pair (n, e); the private key is (n, d). The factors p
transmission from S to D.
and q may be destroyed or kept with the private key.
It is currently difficult to obtain the private key d from The answer is (c) NL-4 times and DLL-6 times
the public key (n, e). However, if one could factor n 25. (c) Q and S only.
into p and q, then one could obtain the private key d. Both SHA-1 and MD5 can be used to generate a
Thus, the security of the RSA system is based on the message digest.
assumption that factoring is difficult. 26. (a) First the web-browser resolves the domain name
The RSA cryptosystem in the problem is correctly using DNS (i.e. finding the IP address of the server
represented by the equation 1 and 3. specified in the URL).
18. (d) Time to live (TTL) is a limit on the period of time or Then a TCP connection is established between web
transmissions in computer and computer network browser & the server
technology that a unit of data (e.g., a packet) can After that the web browser requests a webpage
experience before it should be discarded. If the limit is using HTTP...,
not defined then the packets can go into an indefinite Finally the web server sends the requested webpage
loop. The packet is discarded when the Time to live using HTTP.
field reaches 0 to prevent looping. 27. (a) RIP uses distance vector routing and OSPF was link
19. (d) state rating.
20. (c) Sending an email will be done through user agent and 28. (c) Listen converts active unconnected mode to possive
message transfer agent by SMTP, downloading an mode, indicating that the kernal should accept
email from mail box is done through POP, checking incoming connection requests directed to this socket.
email in a web browser is done through HTTP. 29. (b) Bit synchronization is handled by physical layer of
21. (c) The Protocol Data Unit (PDU) are as follows: OSI model and not Data Link Layer.
For application layer – Message 30. (c) Sniffing at R2 alone, an intrudor can learn the TCP port
For application layer – Segment numbers and IP address of Q and H.
For network layer – Data gram 31. (d) When an IP Datagram is transferred from one host
For data link layer – Frame to another, TTL, checksum and fragment offset will
be changed.
S3-252 Computer Networks
Class Leading Bits Size of Network Size of Rest Number of Addresses per Start End
Number Bit field Bit Networks Network address address
field
7 24
Class A 0 8 24 128 (2 ) 16,777,216 (2 ) 1.0.0.1 127.255.255.254
14 16
Class B 10 16 16 16,384 (2 ) 65,536 (2 ) 128.0.0.1 191.255.255.254
21 8
Class C 110 24 8 2,097,152 (2 ) 256 (2 ) 192.0.0.1 223.255.255.254
1110 not defined not defined not defined not defined 224.0.0 239.255.255.255
Class D
(multicast)
1111 not defined not defined not defined not defined 240.0.0.0 255.255.255.255
Class E
(reserved)
Hence, the given subnet mask — 255.255.31.0 is a class Delay = 250 + 200 = 450 ms = 450 × 10– 6 ms
B network. Finally, Maximum Achievable Throughput
Now, the range of a class B network is from 128.0.0.0
Size of window
(lowest) to 191.255.0.0 (Highest). The two values/IP = = bps
Total time
addresses whose range are 191.203.31.87 and 191.234.31.88
33. (d) Now, Distance = Speed × Time 5000
Þ 2 × 103 = 2 × 108 × Time = = 11.11×106 bps
450 ×10-6
Þ Time = 10(–5)s or 10 × 10– 6 s or 10 ms
Minimum Packet size = l × Time 35. (c) Here, the answer l ies in question only. We have to
= 107 × 10 × 10– 6 find the nearest values.
= 100 bits = 12 Byte Here, 192.12.17.10 lies in range of Eth 3. So option
34. (b) Now, Transmission time for 1 packet = 50 ms (a) and (b) can be ignored. Now, considering the
Transmission time for 5 packet = 5 × 50 ms = 250 ms class of the network through subnet mask through
Propagation delay = 200 ms the following table, it is seen that 128.75.43.16 lies in
Total time = Transmission time + Propagation the range of Eth 0
Computer Networks S3-253
Class Leading Bits Size of Network Size of Rest Bit Number of Networks Addresses per Start End
Number Bit field field Network address address
7 24
Class A 0 8 24 128 (2 ) 16,777,216 (2 ) 1.0.0.1 127.255.255.254
14 16
Class B 10 16 16 16,384 (2 ) 65,536 (2 ) 128.0.0.1 191.255.255.254
21 8
Class C 110 24 8 2,097,152 (2 ) 256 (2 ) 192.0.0.1 223.255.255.254
Class D
(multicast) 1110 not defined not defined not defined not defined 224.0.0 239.255.255.255
Class E
(reserved) 1111 not defined not defined not defined not defined 240.0.0.0 255.255.255.255
It is seen that 128.75.43.16 lies in the range of Eth 0. 37. (b) In the first back off race, there are two conditions
0 and 1
Serial communication link (baud)
36. (b) In the second back off race there are four
(start bit + data bit + end bit + parity bit) conditions 0, 1, 2 and 3
9600 Hence, winning probability of A can be calculated
= as
1+ 8 + 2 +1 1/2 × 3/4 + 1/2 × 1/2
9600 = 3/8 + 1/4
= = 800 = 5/8
12
= 0.625
Hence, 800 8-bit characters can be transmitted per
second over a 9600 baud serial communication link
using asynchronous mode of transmission.
38. (d) Firstly, we should know, what a Class B network is and how is it different from Class A network and Class B network.
IP Address Class Network and Host Capacities
# of Possible Network 7
2 – 2 = 126
14
2 = 16,384
21
2 = 2,097,152
IDs
Here, we have the number of departments = 64 39. (b) Let us assume the following
that means – 26 (2 raise to the power 6) I Communication between two Stations; Station A and
So, number of subnet, n = 6 Station B
II The size of Window to be 8 (0, 1, 2, 3, 4, 5, 6, 7) Now, the
According to the formula number of subnets = 2n
communication between the two stations would be as
So, the subnet mask would be
follows
= 11111111.11111111.11111100.00000000 1. Station A sends frame 0 to Station B
255 . 255 . 252 . 0 2. Station B receive frame 0 and sends an
i.e., 255.255.252.0 acknowledgement (ack) as RR1
S3-254 Computer Networks
48. (a) It is already given that n stations transmit with a So rate of generation of packets 1= 64 ms= .064/sec
probability p in a slotted LAN. For this, the stations Hence (b) is correct option.
need to acquire a medium. Let us assume the following 54. (a) Since, it is a layer 4 firewall, it cannot block application
1 be the event when station 1 transmits layer protocol like HTTP.
2 be the event when station 2 transmits 55. (d) First of all, let us know what is Netmask. A Netmask is
N be the event when station N transmits a 32-bit mask used to divide an IP address into subnets
The probability for a station to transmit is represented and specify the networks available hosts. In a netmask,
as two bits are always automatically assigned. For
uur
(
P 1 2 3...N U 1 2 3 4...N U 1 2 3 4 5...N U... ) example, in 255.255.225.0, 0 is the assigned network
address; and in 255.255.255.255, 255 is the assigned
As all the events are mutually exclusive. Hence, the broadcast address. The 0 and 255 are always assigned
probability can be given as and cannot be used.
Here, in the problem, both IP Addresses are on same
network. To find out the solution, we have to try out
( ) ( ) ( ) ()
P (1) P 2 P 3 ...P N + P 1 P ( 2 ) P 3 P 4 ...P N () () ( ) for all four options available.
+ P (1) P ( 2 ) P ( 3) P ( 4 ) P ( 5 ) ...P ( N ) + ...
Now, post Mask operation, a same ID must come for
the both. However, it does not come as and when we
As given that all events are independent, hence the use 255.255.255.224. Lets see it from the calculations
probability below
= p(1 – p) (1 – p) ... (1 – p) + (1 – p) p (1 – p) ... (1 – p) 10. 105. 1. 113 10. 105. 1. 91
+ (1– p) (1 – p) (1 – p) ... (1 – p) + .... 255. 255. 255. 224 255. 255. 255. 224
= np (1 – p) n – 1 10. 105. 1. 106. 10. 105. 1. 64
49. (c) As we have the Subnet Mask 255.255.248.0
Here, we can see that both the ID are different from
i.e., 255.255.11111100.00000000
each other.
where 1 represents the network portion and 0’s
56. (a) Transmission delay for 1st packet from each of S, R1
represent the host.
and R2 will take 1 ms
So, the number of host = 2n
Where n = no. of 0s. Propagation delay on each link l1,l2 and l3 for one
So, the number of host = 211 packet is 1ms
So, the number of host = 2046 Therefore the sum of transmission delay and
50. (b) The application layer is the layer that uses the protocol propagation delay on each link for one packet is 2ms.
like SMTP and FTP and accepts the raw data from the The first packet reaches the destination at 6th ms
user irrespective of the size. It is the TCP layer that The second packet reaches the destination at 7th ms
breaks the communication in packets of size 216 byte So, inductively we can say that 1000th packet reaches
and hence, application layer is not limited to the size of the destination at 1005th ms.
transfer. 57. (a) Given, IP addresses
51. (b) Let the duration of transmission be x s. 245.248.128.0/20
Transmission Network of Computer by y s = 11111111.11111111.11110000.00000000
Network initially filled with p Megabits Now, total number of hosts we have = 212
Initial rate of transmission be q per second Half of the host we have to give to organization A that
Now, from the above, we can easily formulate means 212 hosts we have to give.
y + qx = xy Þ y = x (y – q) So, 12th bit from right or 1st bit of host ID of given
Þ 16 = x (10 – 2) Þ x = 2 network have to be done either 0 or 1.
52. (c) The solution is just based on the very basic concepts NID = 11110101.11111000.10000000.00000000
regarding CRC checking. There are two ways by which So, for B network ID will be
the solution can be out by using the basic concepts.
Solution 1 – 11110101. 11111000. 10001 0 00 . 00000000
There are odd numbers of bit in the error. Due to which,
NID HID
the error function will have a factor of (1 + x2 + x4 + ....).
Now this can never be divided by the generator having or
NID
(1 + x) as a factor. 11110101. 11111000. 10001 1 00 . 00000000
Solution 2 –
In a polynomial code method, the sender and receiver NID HID
mutually agrees on a generator polynomial G(x). Here,
So, bit number 22 could be 0 or 1.
both of the high order bit and the low order bit and the
Þ 245.248.136.0 / 22
low order bit of the generator must be 1. Hence, 1 + x is
or
a factor of G(x). Þ 245.248.140.0 / 22
53. (b) Packet life time = 64 sec So, none of them are in the option for organization B.
Increment time = 1 ms
S3-256 Computer Networks
Case (A) : If we fix the 21st bit as 0. Hence threshold = (congestion window size)/2=10/2 = 5
11110101. 11111000. 10001000 . 00000000 Time = 6, transmits 2
Time = 7, transmits 4
NID = 21 HID = 11
Time = 8, transmits 5(threshold is 5)
245.248.128.0 / 21
Time = 9, transmits 6
For remaining address we have to put 21st bit as 1
because 0 is used in organization A. So, remaining Time = 10, transmits 7
address. During 10th transmission, it transmits 7 segments
hence at the end of the 10th transmission the size of
11110101. 11111000. 10001000 . 0000000
congestion window is 7 MSS.
NID HID 59. (b) Data Rate in an Ethernet LAN = 500 Mbps
For organization B, we need half addresses so but of Frame size =10000 bits
11 bit, we need 10 bit for organization B. Propagation Time = Transmission time + Collision
From case A Answers would be signal
A: 245-248.128.0/2 Frame size Length Length
B: 245.248.136.0 / 22 = +
Propagation time Signal speed Signal speed
or Not present in options
B : 245.248.140.0 / 22 10000 bits 2 ´ length
=
Case B : For organization A in bit 21st, now take 500 ´ 10 bits / s 2 ´105 km / s
6
HID Length = 2 km
Hence, the maximum length of the cable (in km) is (b)
11110101. 11111000. 10001000 . 00000000
2 km.
NID 60. (c) Since M bit is 0 there would be no fragment other
Þ 245.248.136.0 / 22 than this fragment. Hence, this fragment is the "Last
So, 1 in 21st position is used now for remaining we Fragment".
need to take 0 in 21st position. HLEN defines the length of the Header in the
11110101. 11111000. 10000000 . 00000000 Datagram. The value of HLEN is 10
\ Size of the header is 10 * 4 = 40 B.
NID HID Length of Data = Total length – Header length
Out of this add half of them we need to give to = 400 – 40 = 360 B
organization B. So, in position 22nd, it could be 0 or 1.
The fragment offset of data in the original datagram
HID is measured in units of 8 B. So to find first byte of
first Byte
11110101. 11111000. 1000 000 . 00000000 This fragment = Fragment offset.
B
NID First Byte = 300 * 8 = 1 '2400' B.
Þ 245.248.128.0 / 22 and hence the length of data is 360 B
HID So last byte on this datagram is 2759 i.e 2400 and
2759
or 11110101. 11111000. 10000100 . 00000000 Hence answer is (c) Last fragment, 2400 and 2759.
61. (d) I Transmission
NID 1000 + 100 = 1100 bytes (transmitted from A at a time)
Þ 245.248.132.0 / 22 In 1 second ® 106 bytes
In Case B we get
A: 245-248.136.0/21 8
\ For 1100 bytes Þ 1100 ×
B: 245.248.128.0 / 22 106
or Anyone is correct = 8.8 m sec. (transmission time)
B : 245.248.132.0 / 22 From A, R1 and R2 it takes T1 = 8.8 + 8.8 + 8.8
58. (c) Given threshold = 8 = 26.4 m sec. (to reach B)
Time = 1, during first transmission, window size = 2 II Transmission
(slow start phase) 100 + 100 = 200 bytes (transmitted 10 times from A)
Time = 2, congestion window size = 4 (double the no.
8
of acknowledgments) For 200 bytes Þ 200 × = 1.6 m sec.
Time = 3, congestion window size is = 8 106
Time = 4, congestion window size = 9, after threshold From A, transmission time to entire packet = 1.6 × 10
(increase by one addictive increase) = 16 m sec.
Time = 5, transmits 10 MSS, but time out occurs From A, R1 and R2 it takes T2 = 16 + 1.6 + 1.6
congestion windw size = 10 = 19.2 m sec. (to reach B)
Computer Networks S3-257
R2 7 R4 218
\ 218 unique Ids Þ
8 1000
2
= 28
R1 2 1 R6 = 256 seconds
77. 28 to 30 sec.
3 4
78. 1100 to 1300 m sec.
R3 R5 79. 5 bits
80. 26
73. (b) As in the previous question R1 R 2 and Initial value of TTL field is 32.
Except R, all nodes will decrement the TTL value.
R4 R6 not used. So, we give them weight =
\ TTL value when packet is received at R = 32 – 6 = 26
2, by applying same method only one link not used. 81. 1
Address 131.23.151.76
1 N1 Coming to I field of given routing table.
N5 3 N2
74. (a) Þ 131.16.0.0/12
131.0001 0111.151.76
131.0001 0000.0.0 (mask bit = 12)
4 6
131.16.0.0 (matched)
Coming to II field of given routing table.
N4 N3 Þ 131.28.0.0/14
2 131.0001 0111.151.76
131.0001 0100.0.0 (mask bit = 14)
Distance vector for N3 will be
131.20.0.0 (not matched)
N3 : (N1, N2, N3, N4, N5) Coming to III field of given routing table
N3 : (3, 2, 0, 2, 5) Þ 131.19.0.0/16
75. (d) N3 – N1 = 2 + ¥ = ¥ 131.0001 0111.151.76
131.0001 0111.0.0 (mask bit = 16)
NUMERICAL ANSWER QUESTIONS 131.23.0.0 (not matched)
76. 256 Coming to IV field of given routing table
Each host has a globally unique IPv4 address. Þ 131.22.0.0/15
To design a 50 bit unique Id, 50 bit in the sense (32 + 18) 131.0001 0111.151.76
\ it shows IP address (32 bit) followed by 18 bits. 131.0001 0110.0.0 (mask bit = 15)
1000 unique IDs Þ 1sec 131.22.0.0 (matched)
Q I and IV entries are matched, we pickup longest mask
bit
\ Output interface identifies is 1.
Web Technology S3-259
11 Web Technology
Chapter
• An author may use the style attribute to assign presentational properties to a particular element.
• The title attribute is used to attach subtextual explanation to an element. In most browsers this attribute is displayed as a tooltip.
• The lang attribute identifies the natural language of the element's contents, which may be different from that of the rest of the
document. For example, in an English-language document:
The abbreviation element, abbr, can be used to demonstrate some of these attributes :
Comprehensive list of HTML tags with their semantically appropriate uses
Tag What it is When to use it
<a> Anchor (most Vital. Use to create links in content. Use the title attribute whenever the contents of the
commonly a link) <a>…</a> pair do not accurately describe what you'll get from selecting the link. Title
attribute often displays as a tooltip in visual browsers, which may be a helpful usability
aid.
<abbr> Defines an Works in a similar way to <dfn> and <acronym>, using a title attribute (displays
abbreviation a tooltip in standard visual browsers). e.g. <abbr title="Hypertext markup
language">HTML</abbr>
<ACRONYM> Defines an acronym Works in a similar way to <abbr> and <dfn>, using a title attribute (displays a tooltip in
standard visual browsers).
<ADDRESS> Used for marking up Not commonly used. Recommend looking
a physical (e.g. mailing) into microformats, which allow for more detail
address and interoperability.
<APPLET> Inserts a Java applet The old way to insert a Java app. Use <object> instead today.
<AREA> Hotspot in image map Avoid image maps where possible. Occasionally necessary.
<BASE> Specifies the base Use only when necessary. Adjusts any
location of the document. within the document.
relative links and paths
<BASEFONT> Sets default font size Display info - never use it
<BIG> Larger text Display info - never use it
<BLINK> Makes text blink You go to hell if you use this
<BLOCKQUOTE> Large quoted block of text Use for any quoted text that constitutes one or more
paragraphs (note: should contain <p> tags as well). Use <q> for quotations within a
paragraph. Often used in conjunction with <cite> to cite the quotation's source.
<BODY> Document body Essential (unless you're using frames)
<BR> Line break This is arguably display information. Still in common use, but use with restraint.
<B> Bold text Display info - never use it
<BUTTON> Used for a standard Often better than <input type="button" />
clickable button within or <input type="submit" />, as it allows you
a form to assign different styles based on the HTML element alone, whereas differentiating style
based on the type of input is less well supported.
<CAPTION> Caption for a table: The correct way to assign a title to a table
describe the tables’s of
content
<CENTER> Centred block Display info - never use it. Use <div> or some
other block-level tag with the style text-
align:center instead
<CITE> Defines a citation Defines the source of a quotation (in conjunction with content in <q> or <blockquote>
pairs).
<CODE> Defines an extract Not commonly used. Similar to <pre> tag,
of code but collapses consecutive white spaces and line breaks in the source.
Web Technology S3-261
<OPTION> Selection list option Vital for options within a drop-down control.
<PARAM> Parameter for Java Used in conjunction with an <object> or <applet> tag to pass additional setting information
applet at runtime.
<PRE> Preformatted text Renders text in a pre-formatted style, preserving line breaks and all spaces present in the
source. May be useful. (This one's a paradox, as it is strictly display info that applies only
to visual browsing, but it's still so commonly used and useful that I'm hesitant to advise
against using it.)
<P> Paragraph Only use to denote a paragraph of text. Never use for spacing alone.
<Q> Short quotation Use for inline quotations (whereas <blockquote> should be used for quotations of a
paragraph or more). Often used in conjunction with <cite> to cite the quotation's source.
<SAMP> Denotes sample Similar to the <code> tag. Rarely used. Avoid.
output text
<SCRIPT> Inline script It's better to have all scripts as separate files
(e.g. JavaScript) than to write inline or in the <head> section, however still has its uses.
<SELECT> Selection list A drop-down selector for a form.
<SMALL> Smaller text Display info - never use it
<SPAN> An inline span Use to apply meaning (and style) to a span
within text of text that goes with the flow of content (whereas a <div> tag is block-level and breaks the
flow)
<Strikeout> Display info - never use it
<STRONG> Strong emphasis Use this instead of the old <b> tag.
<STYLE> CSS style settings Normally used in <head> section of a page. Try to use external stylesheets, to enable you
to apply different styles for different output media.
<SUB> Subscript text Arguably display info - recommend using alternative tags (e.g. <cite>). May be required in
some academic uses, e.g. Chemical formulas.
<SUP> Superscript text
<TABLE> Table Use for repeated data that has a naturally tabular form. Never use for layout purposes.
<TD> Table data cell A cell containing actual data. If a cell actually contains a descriptor or identifier for a row
or column, use a <th> (table header) tag, not a <td>. This usually applies to column
headers (within a <thead>), column footers (within a <tfoot>), as well as row headers
(usually the first cell in a row in the <tbody>).
<TEXTAREA> Multi-line text input Essential
area in a form
<TH> Table column or row May appear in a <thead> (to denote a
header cell column header cell), <tbody> (to denote a row header), and in <tfoot> (to denote a column
foot cell, e.g. a total)
<TBODY> Indicates the main body It is always worth using this tag, as well as
of a data table using <thead> and <tfoot> where appropriate.
Note that it is permissible to have more than one <tbody>, <thead>, and <tfoot> in the same
table.
<THEAD> The head section The place to put column header cells (<th>)
of a table
<TFOOT> The foot section of Good place to put e.g. summary data, such
a table as totals. Note that it goes before the <tbody> tag!
<TITLE> Document title Essential
<TR> Table row Essential with tables
Web Technology S3-263
S CH EM A Both the code that processes the SQL request and the data reside
on the server, allowing it to use its own processing power to find
A schema is a document that provides a model of structure.
the requested data.
Declaration 3. Transaction Server :
XML Schema documents begin with an XML declaration Client invoke remote procedures that reside on servers, which
<?xml version="1.0" ?> also contain an SQL database engine. The server has procedural
statements to execute a group of SQL statements.
Root Element OLTP (On Line Transaction Processing) tend to be critical
The root element is the <schema> element. The <schema> element applications that always require a 1-3 second response time and
allows you to declare namespace information. tight control over the security and the integrity of the database.
Element Definitions 4. Application Server:
The element definitions are placed within the schema element. Used to serve user needs. Downloading capabilities, e-mail
Each element will assign a value for the name or ref attribute, and process, allow users to share data, while security and management
declare the content model or set the value for the type attribute. services, also based on the server, ensure data integrity and
Elements that have element content, have the content model security.
defined within a <complexType> definition. <simpleType> are Basic Characteristics:
used to define text only content. The basic characteristics of client server architectures as follows:
1. A combination of a client or front-end portion that interacts
XPATH with the user and a server or back-end portion that interacts
XPath is the XML Path Language used to select parts of an XML with the shared resources.
instance document for processing by various other XML 2. The front-end task and back-end task have fundamentally
technologies such as XSLT, XPointer, XQuery and XForms. XPath different requirements for computing resources.
provides a language for modelling XML instance documents as a 3. The environment is typically heterogeneous and
set of hierarchical nodes with axes used to navigate from one multivendor. The hardware platform and OS of client and
node to another. A number of functions are available for server are not usually the same. Client and Server processes
processing contents of nodes and predicates can be used to communicate through a well-defined set of standard
further filter node identifiers. application program interface (API).
<!-- A single step location path --> 4. Scalability.
child::Phone[@type="Home"] Components:
<!-- A two step location path --> 1. User interface: Client server interacts with users, screens,
child::Person/child::Phone[@type="Home"] windows, window management ,keyboard and mouse
Basic Structure handling.
The root element for XSLT documents is a <stylesheet> element 2. Business processing : The application uses the user
or a <transform> element. interface data to perform business tasks.
<xsl:stylesheet 3. Database processing : The application code manipulates
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" data with in the application. Data manipulation is done using
version="1.0" > a data manipulation language such as SQL.
With the stylesheet element declared we can then use the elements The development and implementation of client server
from the XSL namespace and XPath functions and identifiers to computing is more complex, more difficult, more expensive.
create a layout for an XML document Utilizing an OO methodology we can manage the complexity
B ASI C CO N C EP T S OF C LI E NT- S E RV E R of client server applications.
CO MP U TI NG Server - a computer program running to serve the requests of
other programs, the "clients"
Servers are software programs that in most cases run off normal
computing hardware. Server software includes:
Clients • Printing
Internet
Server
• File sharing
• Game hosting
• Websites
the client-server model • Other web services
Server is of different forms : Client - an application or system that accesses a service made
1. File server : available by a server
The client passes requests for files or file records over a network Clients are software programs and processes that connect to
to the file server. This form of data service requires large servers, sending requests and receiving responses. Client
bandwidth. Traditional LAN computing allows users to share examples include:
resources, such as data files and peripheral devices. • Web browser page requests
2. Database Server • Chat systems on mobile phones
Client pass SQL requests as messages to the server and the results • Online games
of the query are returned over the network.
Web Technology S3-265