Sunteți pe pagina 1din 448

• Head Office : B-32, Shivalik Main Road, Malviya Nagar, New Delhi-110017

• Sales Office : B-48, Shivalik Main Road, Malviya Nagar, New Delhi-110017
Tel. : 011-26691021 / 26691713

Coupon Code : Scratch the label gently

INSTRUCTIONS

1. Scratch the Silver Coating with a Coin to reveal the Code,


2. You can access your test on any window based Desktop,
Android tablets or Ipads absolutely free,
3. Go to mylearninggraph.com and Click on Registration on
the Top Right bar,
4. Enter your Details and Click on "Create an account".
5. Click on your Name on the Top Right bar to open the Menu
and Click on Apply Coupon (Skip Steps 2 & 3 if you are
already registered).
Typeset by Disha DTP Team 6. Enter your Coupon Code and click Apply and your Course
will be added to your "My Program".
7. Contact us at support@mylearninggraph.com for any
assistance.

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.

For further information about the books from DISHA,


Log on to www.dishapublication.com or email to info@dishapublication.com
CONTENT
• Solved Paper 2016 [Set-1] 2016-1-12

• Solved Paper 2016 [Set-2] 2016-13-24

• Solved Paper 2015 [Set-1] 2015-1-14

• Solved Paper 2015 [Set-2] 2015-15-28

• Solved Paper 2015 [Set-3] 2015-29-44

SECTION - 1 : GENERAL APTITUDE S1-1-S1-44

PART-A : VERBAL ABILITY

1. Grammar ............................................................................................................................................ 1-6


2. Vocabulary ....................................................................................................................................... 7-12
3. Critical Reasoning ...................................................................................................................... 13-18

PART-B : NUMERICAL ABILITY

1. Number System ........................................................................................................................... 19-22


2. Algebra ............................................................................................................................................... 23-26
3. Percentage & Its Applications ......................................................................................... 27-30
4. Time and Work & Speed and Distance ..................................................................... 31-36
5. Ratio & Proportion ................................................................................................................... 37-40
6. Permutation and Combination & Probability .......................................................... 41-44

SECTION 2 : ENGINEERING MATHEMATICS S2-1-S2-66

1. Mathematical Logic .................................................................................................................. 1-8

2. Probability ........................................................................................................................................ 9-20

3. Set Theory & Algebra ............................................................................................................. 21-32

4. Combinatorics ............................................................................................................................... 33-36

5. Graph Theory ................................................................................................................................ 37-44


6. Linear Algebra .............................................................................................................................. 45-54

7. Numerical Methods .................................................................................................................. 55-58

8. Calculus ............................................................................................................................................. 59-66

SECTION 3 : TECHNICAL SECTION S3-1-S3-266

1. Digital Logic................................................................................................................................... 1-26

2. Computer Organisation & Architecture ...................................................................... 27-52

3. Programming & Data Structures ..................................................................................... 53-90

4. Algorithm Analysis ..................................................................................................................... 91-122

5. Theory of Computation ......................................................................................................... 123-144

6. Compiler Design .......................................................................................................................... 145-164

7. Operating System ...................................................................................................................... 165-190

8. Databases ....................................................................................................................................... 191-218

9. Information System and Software Engineering ................................................... 219-228

10. Computer Networks ................................................................................................................. 229-258

11. Web Technology .......................................................................................................................... 259-266

4 ONLINE PRACTICE SETS


2016
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-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 (a) zentaga (b) tagafer


(c) tagazen (d) relffer
QUESTION 1 TO 5 CARRY ONE MARK EACH 5. A cube is built using 64 cubic blocks of side one unit. After
1. Out of the following four sentences, select the most suitable it is built, one cubic block is removed from every corner of
sentence with respect to grammar and usage. the cube. The resulting surface area of the body (in square
(a) I will not leave the place until the minister does not meet me. units) after the removal is __________.
(b) I will not leave the place until the minister doesn’t meet me. (a) 56 (b) 64
(c) I will not leave the place until the minister meet me. (c) 72 (d) 96
(d) I will not leave the place until the minister meets me. QUESTION 6 TO 10 CARRY TWO MARKS EACH
2. A rewording of something written or spoken is a
______________. 6. A shaving set company sells 4 different types of razors,
(a) paraphrase (b) paradox Elegance, Smooth, Soft and Executive. Elegance sells at Rs.
(c) paradigm (d) paraffin 48, Smooth at Rs. 63, Soft at Rs. 78 and Executive at Rs. 173
per piece. The table below shows the numbers of each razor
3. Archimedes said, “Give me a lever long enough and a fulcrum
sold in each quarter of a year.
on which to place it, and I will move the world.”
The sentence above is an example of a _________ statement. Quarter/Pro du ct Elegance Smo oth So ft Executive
(a) figurative (b) collateral Q1 27300 20009 17602 9999
(c) literal (d) figurine
Q2 25222 19392 18445 8942
4. If ‘relftaga’ means carefree, ‘otaga’ means careful and
‘fertaga’ means careless, which of the following could mean Q3 28976 22429 19544 10234
‘aftercare’? Q4 21012 18229 16595 10109
2016 -2 SOLVED PAPER - 2016
Which product contributes the greatest fraction to the 12. Let an be the number of n-bit strings that do NOT contain
revenue of the company in that year? two consecutive 1s. Which one of the following is the
(a) Elegance (b) Executive recurrence relation for an?
(c) Smooth (d) Soft (a) an = an–1+ 2an–2 (b) an = an–1+ an–2
7. Indian currency notes show the denomination indicated in (c) an = 2an–1+ an–2 (d) an = 2an–1+ 2an–2
at least seventeen languages. If this is not an indication of
the nation’s diversity, nothing else is. sin( x - 4)
13. lim = ________.
Which of the following can be logically inferred from the x ®4 x-4
above sentences? 14. A probability density function on the interval [a,1] is given
(a) India is a country of exactly seventeen languages. by 1/x2 and outside this interval the value of the function is
(b) Linguistic pluralism is the only indicator of a nation’s zero. The value of a is ________.
diversity. 15. Two eigen values of a 3×3 real matrix P are (2+ -1) and 3.
(c) Indian currency notes have sufficient space for all the The determinant of P is _________.
Indian languages. 16. Consider the Boolean operator # with the following
(d) Linguistic pluralism is strong evidence of India’s properties:
diversity. x#0 = x, x#1 = x , x#x = 0 and x # x = 1. Then x#y is equivalent
8. Consider the following statements relating to the level of
to
poker play of four players P, Q, R and S.
(a) x y + x y (b) x y + x y
I. P always beats Q
(c) x y + x y (d) x y + x y
II. R always beats S
17. The 16-bit 2’s complement representation of an integer is
III. S loses to P only sometimes
1111 1111 1111 0101; its decimal representation is ________.
IV. R always loses to Q
18. We want to design a synchronous counter that counts the
Which of the following can be logically inferred from the
above statements? sequence 0-1-0-2-0-3 and then repeats. The minimum number
(i) P is likely to beat all the three other players of J-K flip-flops required to implement this counter is
(ii) S is the absolute worst player in the set ________.
(a) (i) only 19. A processor can support a maximum memory of 4 GB, where
(b) (ii) only the memory is word-addressable (a word consists of two
(c) (i) and (ii) bytes). The size of the address bus of the processor is at
(d) neither (i) nor (ii) least _________bits.
9. If f (x) = 2x7+ 3x – 5, which of the following is a factor of f (x)? 20. A queue is implemented using an array such that ENQUEUE
(a) (x3 + 8) (b) (x – 1) and DEQUEUE operations are performed efficiently. Which
(c) (2x – 5) (d) (x + 1) one of the following statements is CORRECT (n refers to
10. In a process, the number of cycles to failure decreases the number of items in the queue)?
exponentially with an increase in load. At a load of 80 units, (a) Both operations can be performed in O(1) time
it takes 100 cycles for failure. When the load is halved, it (b) At most one operation can be performed in O(1) time
takes 10000 cycles for failure. The load for which the failure but the worst case time for the other operation will be
will happen in 5000 cycles is ________. W(n)
(a) 40.00 (b) 46.02 (c) The worst case time complexity for both operations
(c) 60.01 (c) 92.02
will be W(n)
(d) Worst case time complexity for both operations will be
TECHNICAL SECTION W(log n)
21. Consider the following directed graph:
QUESTION 11 TO 35 CARRY ONE MARK EACH
11. Let p, q, r, s represent the following propositions: b c
p: x Î {8, 9, 10, 11,12}
a f
q: x is a composite number
r: x is a perfect square d e
s: x is a prime number
The number of different topological orderings of the vertices
The integer x > 2 which satisfies Ø((p Þ q) ^ ( Ø r Ú Ø s)) is _____. of the graph is ________ .
SOLVED PAPER - 2016 2016-3

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

if (a < c) (c) Uniform random


(d) Highest priority first with priority proportional to CPU
mystery (&c, &a);
burst length
mystery (&a, &d);
31. Which of the following is NOT a superkey in a relational
printf (“%d\n”, a); schema with attributes V,W, X, Y, Z and primary key V Y?
} (a) VXYZ (b) VWXZ
The output of the program is_______ . (c) VWXY (d) VWXYZ
2016 -4 SOLVED PAPER - 2016
32. Which one of the following is NOT a part of the ACID Step 4. If the outcomes are (TAILS, TAILS), then go to
properties of database transactions? Step 1.
(a) Atomicity (b) Consistency The probability that the output of the experiment is Y is (up
(c) Isolation (d) Deadlock-freedom to two decimal places)________ .
33. A database of research articles in a journal uses the following 40. Consider the two cascaded 2-to-1 multiplexers as shown in
schema. the figure.
(VOLUME, NUMBER, STARTPAGE, ENDPAGE, TITLE, YEAR, PRICE)
R
The primary key is (VOLUME, NUMBER, STARTPAGE, ENDPAGE)
and the following functional dependencies exist in the
schema. 0 0 X
0 2-to-1 2-to-1
(VOLUME, NUMBER, STARTPAGE, ENDPAGE) ® TITLE 1
R 1 MUX MUX
(VOLUME, NUMBER) ® YEAR s s
(VOLUME, NUMBER, STARTPAGE, ENDPAGE) ® PRICE
The database is redesigned to use the following schemas.
P Q
(VOLUME, NUMBER, STARTPAGE, ENDPAGE, TITLE, PRICE)
(VOLUME, NUMBER, YEAR) The minimal sum of products form of the output X is
Which is the weakest normal form that the new database (a) P Q+PQ R (b) P Q +Q R
satisfies, but the old one does not?
(a) 1NF (b) 2NF (c) P Q + P Q R (d) Q P + P Q R
(c) 3NF (d) BCNF 41. The size of the data count register of a DMA controller is 16
34. Which one of the following protocols is NOT used to bits. The processor needs to transfer a file of 29,154 kilobytes
resolve one form of address to another one? from disk to main memory. The memory is byte addressable.
(a) DNS (c) ARP The minimum number of times the DMA controller needs to
(b) DHCP (d) RARP get the control of the system bus from the processor to
transfer the file from the disk to main memory is __________.
35. Which of the following is/are example(s) of stateful
42. The stage delays in a 4-stage pipeline are 800, 500, 400 and
application layer protocols?
300 picoseconds. The fir st stage (with delay 800
(i) HTTP (ii) FTP (iii) TCP (iv) POP3
picoseconds) is replaced with a functionally equivalent
(a) (i) and (ii) only (b) (ii) and (iii) only design involving two stages with respective delays 600 and
(c) (ii) and (iv) only (d) (iv) only 350 picoseconds. The throughput increase of the pipeline is
__________ percent.
QUESTION 36 TO 65 CARRY TWO MARKS EACH
43. Consider a carry lookahead adder for adding two n-bit
36. The coefficient of x12 in (x3 + x4 + x5 + x6 + ...)3 is _______ . integers, built using gates of fan-in at most two. The time to
37. Consider the recurrence relation a1 = 8, an = 6n 2 + 2n + an-1. perform addition using this adder is
Let a99 = K ×104. The value of K is _________. (a) Q (1) (b) Q (log)(n))
38. A function f : ¥ + ® ¥ +, defined on the set of positive (c) Q ( n ) (d) Q (n)
44. The following function computes the maximum value
integers ¥ +, satisfies the following properties:
contained in an integer array p[ ] of size n (n >= 1).
f (n) = f (n/2) if n is even int max (int *p, int n){
f (n) = f (n+5) if n is odd int a = 0, b = n –1;
Let R = {i| $ j : f ( j) = i} be the set of distinct values that while (__________){
f takes.The maximum possible size of R is_______. if (p[a]<= p[b]){a = a + 1;}
39. Consider the following experiment: else {b = b – 1;}
Step 1. Flip a fair coin twice. }
Step 2. If the outcomes are (TAILS, HEADS) then output return p[a];
Y and stop. }
Step 3. If the outcomes are either (HEADS, HEADS) or The missing loop condition is
(HEADS, TAILS), then output N and stop. (a) a != n (b) b != 0
(c) b > (a+1) (d) b != a
SOLVED PAPER - 2016 2016-5

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}

é0 2 8 5ù (d) {ambn|m ³ 0 and n > 0} and {ambn|m > 0 or n > 0}


ê2 0 5 8 úú 53. Consider the transition diagram of a PDA given below with
ê
W = ê8 5 0 xú input alphabet å = {a, b} and stack alphabet G = {X, Z}.
ê ú Z is the initial stack symbol. Let L denote the language
ë5 8 x 0û
accepted by the PDA.
The largest possible integer value of x, for which at least
one shortest path between some pair of vertices will a, X/XX
a, X/XZ b, X/e
contain the edge with weight x is ________.
49. Let G be a complete undirected graph on 4 vertices, having 6
edges with weights being 1, 2, 3, 4, 5, and 6. The maximum b, X/e e, Z/Z
possible weight that a minimum weight spanning tree of G
can have is ________ .
2016 -6 SOLVED PAPER - 2016
Which one of the following is TRUE? (a1, a2,..., a20, a1, a2, ..., a20), where each ai is a distinct virtual
page number. The difference in the number of page faults
(a) L= {anbn|n ³ 0} and is not accepted by any finite
between the last-in-first-out page replacement policy and
automata
the optimal page replacement policy is _________.
(b) L = {an|n ³ 0} È {anbn|n ³ 0} and is not accepted by 60. Consider the following proposed solution for the critical
any deterministic PDA
section problem. There are n processes : P0...Pn–1. In the
(c) L is not accepted by any Turing machine that halts on code, function pmax returns an integer not smaller than
every input any of its arguments. For all i, t[i] is initialized to zero.
(d) L = {an|n ³ 0} È {anbn|n ³ 0} and is deterministic Code for Pi:
context-free do {
54. Let X be a recursive language and Y be a recursively
c[i] = 1; t[i] = pmax (t[0],..., t[n – 1]) + 1; c[i] = 0;
enumerable but not recursive language. Let W and Z be
two languages such that Y reduces to W, and Z reduces for every j ¹ i in{0,..., n–1} {
to X (reduction means the standard many-one reduction). while(c[j]) ;
Which one of the following statements is TRUE? while(t[j] != 0 && t[j] <= t[i]);
(a) W can be recursively enumerable and Z is recursive. }
(b) W can be recursive and Z is recursively enumerable. Critical Section ;
(c) W is not recursively enumerable and Z is recursive.
t[i] = 0 ;
(d) W is not recursively enumerable and Z is not
Remainder Section;
recursive.
55. The attributes of three arithmetic operators in some } while (true);
programming language are given below. Which one of the following is TRUE about the above
Operator Precedence Associativity Parity solution?
+ High Left Binary
(a) At most one process can be in the critical section at
– Medium Right Binary
any time.
* Low Left Binary
The value of the expression 2 – 5 + 1 – 7 * 3 in this language (b) The bounded wait condition is satisfied.
is _________ . (c) The progress condition is satisfied.
56. Consider the following Syntax Directed Translation Scheme
(d) It cannot cause a deadlock.
(SDTS), with non-terminals {S, A}and terminals{a, b}.
61. Consider the following two phase locking protocol.
S ® aA {print 1}
Suppose a transaction T accesses (for read or write
S ® a {print 2}
operations), a certain set of objects {O1; ...,Ok. This is
A ® Sb {print 3}
done in the following manner:
Using the above SDTS, the output printed by a bottom-
up parser, for the input aab is: Step 1. T acquires exclusive locks to O1, ..., Ok in
(a) 1 3 2 (b) 2 2 3 increasing order of their addresses.
(c) 2 3 1 (d) syntax error Step 2. The required operations are performed.
57. Consider a computer system with 40-bit virtual addressing Step 3. All locks are released.
and page size of sixteen kilobytes. If the computer system This protocol will
has a one-level page table per process and each page table (a) guarantee serializability and deadlock-freedom
entry requires 48 bits, then the size of the per-process
(b) guarantee neither serializability nor deadlock-freedom
page table is _________ megabytes.
58. Consider a disk queue with requests for I/O to blocks on (c) guarantee serializability but not deadlock-freedom
cylinders 47, 38, 121, 191, 87, 11, 92, 10. The C-LOOK (d) guarantee deadlock-freedom but not serializability
scheduling algorithm is used. The head is initially at 62. Consider that B wants to send a message m that is digitally
cylinder number 63, moving towards larger cylinder signed to A. Let the pair of private and public keys for A
numbers on its servicing pass. The cylinders are numbered and B be denoted by K x- and K x+ for x = A, B,
from 0 to 199. The total head movement (in number of respectively. Let Kx(m) represent the operation of encrypting
cylinders) incurred while servicing these requests is
m with a key Kx and H(m) represent the message digest.
_______ .
Which one of the following indicates the CORRECT way
59. Consider a computer system with ten physical page
of sending the message m along with the digital signature
frames. The system is provided with an access sequence
to A?
SOLVED PAPER - 2016 2016-7

(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

1. (d) The use of double negatives in a single is unacceptable 10. (b)


according to the current English standard. From the above data, we can say
2. (a) Paraphrase means the rewording of something written Exponent = log(cycles) × load
or spoken. Paradox means an absurd statement. Þx = log(10000) × 80 = 160
Paradigm means an example or pattern of something.
Paraffin means a liquid made from coal or petroleum. 160
\ load = = 43.25
3. (a) The given statement is an example of figurative log 5000
statement which means words or phrases used not Since 40.00 < 43.25 < 46.02
with their basic meaning but with a more imaginative \ (b) is correct.
meaning to create a special effect. 11. 11
4. (c) taga and care are a matching pair in every combination.
(p Þ q) will result {8, 9, 10, 12}
So, taga surely represents care.
Ø r will result {8,10, 11, 12}
fer ® less
Ø s will result {8, 9, 10, 12}
o ® full
Also, after checking it is found that the second half of ( Ø r Ú Ø s) will result {8, 9, 10, 11, 12}
the word in encoded value refers to the first half of the (p Þ q) Ù ( Ø r Ú Ø s) will result {8, 9, 10, 12}
word in the decoded value. Going by the same logic, Ø ((p Þ q) Ù ( Ør Ú Ø s)) will result 11.
the answer would be tagazen. 12. (b)
5. (d) The surface area of the body will remain unchanged as Case I ® First bit is ‘0’
when a cube is removed, it exposes three faces, which
makes the number of exposed faces same as before
removal. 0_ _ a_n _–1_ _ _
So, surface area of the body after removal Case II ® First bit is ‘1’
= 6 × side × side 0_ _an_–2_ _ _ 10 ® (It must be zero)
= 6 × 4 × 4 = 96
6. (b) Revenue from Elegance
= (27300 + 25222 + 28976 + 21012) × 48 \ an = an –1 + an – 2
= ` 4920480 sin ( x - 4 ) sin ( x - 4 )
Revenue from Smooth = (20009 + 19392 + 22429 + 18229) 13. lim = lim
x ®4 x-4 x - 4®0 x -4
× 63 = ` 5043717
Revenue from Soft = (17602 + 18445 + 19544 + 16595) × sin y
78 = ` 56350508 = lim (By taking y = x - 4) = 1
y ®0 y
Revenue from Executive = (9999 + 8942 + 10234 + 10109)
× 173 = ` 6796132 14. 0.5
Total revenue = ` 22390837 1
Fraction of Revenue for Elegance = 0.29 Given f(x) = x Î [a , 1 ]
Fraction of Revenue for Smooth = 0.225 x2
Fraction of Revenue for Soft = 0.251 = 0 otherwise
Fraction of Revenue for Executive = 0.303 1
Hence (b) is the correct option.
7. (d) We know that ò f ( x ) dx = 1
a
The second sentence of the given para logically infer that
‘Linguistic pluralism is strong evidence of India’s diversity’. 1 1
8. (d) 1 æ -1 ö
Since S loses to P only sometimes no statement is true.
Þ ò x 2 dx = 1 Þ çè x ÷øa = 1
a
9. (b)
Given f(x) = 2x7 + 3x – 5, putting x = 1 in f(x) 1
2(1)7 + 3(1) – 5 = 0 Þ -1 = 1
a
5–5=0
Þ a = 0.5
\ (x – 1) is a factor of f(x).
SOLVED PAPER - 2016 2016-9

15. 15 22. (d)


Given that 2 + -1 and 3 are two Eigen values of 3 × 3 real ‘i’ is integer and *P is value of a pointer to short.
23. (d)
matrix. That is (2 + i) and 3 are Eigen values. But (2 – i) is also
The worst case running times of Insertion sort is O(n 2),
an Eigen value ( Q complex roots occur in pair only)
because of the series of swaps required for each insertion.
determinant of p = Product of Eigen values = (2 + i) × (2 – i)
Merge sort is O(n log n) as merge sort always divides the
× 3 = 5 × 3 = 15
array in two halves and take linear time to merge two halves
16. (a) x #0 = x; and Quick sort is O(n2).
x #1 = x; 24. (a) The shortest path may change. The reason is, there
may be different number of edges in different paths
x # x = 0; from s to t. For example, let shortest path be of weight
10 and has 5 edges. Let there be another path with 2
x # x = 1.
edges and total weight 25. The weight of the shortest
This function # basically represents XOR.
path is increased by 5*10 and becomes 10 + 50. Weight
17. – 11
of the other path is increased by 2*10 and becomes 25
1111 1111 1111 0101
+ 20. So the shortest path changes to the other path
2’s complement 0000 0000 0000 1011
with weight as 45.
11 and Ist bit is 1 The Minimum Spanning Tree doesn't change.
So result is –11
Remember the Kruskal's algorithm where we sort the
18. 3 edges first. If we increase all weights, then order of
Let output of 3 flip-flops be S1, S2, S3.
edges won't change.
S1 S2 S3 25. 2016
As in C, parameters are passed by value - even if they are
pointers. So, here the pointer values are exchanged within
the function only (one can use * operator to exchange the
values at the location of the pointers and this will affect the
A B values in main). So, there will be no change in a, b, c, d. The
C
output of the program is 2016.
26. (d)
S1 S2 S3 A B C 27. (c) There is no known algorithm to verify whether the
1 0 0 1 0 0 language accepted by TM is empty or not. Similarly
there is no algorithm to verify whether language of
0 0 1 0 0 1
CFG’s are equivalent.
1 0 1 1 0 0 28. (b) Option (a) contains 00 and 11 consecutively which
0 1 0 0 1 0 does not fulfill the required condition. Option (c) does
1 1 0 1 0 0 not give assurance that both 00 and 11 will be exist in
0 1 1 0 1 1 the string.
According to option (d), string should start with 11
So, if one takes BC as final output, then it can generate the and ends with 00 or vice versa. Hence option (b) is the
sequence 0 ® 1 ® 0 ® 2 ® 0 ®3. Hence the answer is 3. correct answer.
19. 31 29. 10
Maximum memory = 4 GB = 232 bytes 30. (a) SRTF is the preemptive SJF which generates less
Size of a word = 2 bytes average waiting time in which jobs are schedule
Therefore, Number of words = 232/2 = 231 according to shortest remaining time.
So, we require 31 bits for the address bus of the processor. 31. (b) Super key = Candidate key + other attributes. But
20. (a) We can use circular array to implement both O(1) time. option (b) does not include Y which is part of candidate
21. 6 Key.
The different topological orderings will be as follows: 32. (d) ‘D’ stands for Durability, not deadlock-freedom.
(1) a b c d e f 33. (a) The candidate key is (volume, number, start page, end
(2) a d e b c f page), (Volume, number) ® year is a partial dependency.
(3) a b d c e f But it does not follow 2NF.
(4) a d b c e f 34. (c) DHCP is not used to resolve one form of address to
(5) a b d e c f another. DHCP is used to assign IP dynamically. All
(6) a d b e c f others are used to convert one address to other.
2016 -10 SOLVED PAPER - 2016
35. (c) TCP is stateful as it maintains connection information
across multiple transfers, but TCP is not an application æ ö
1æ 1 æ1ö ö 1ç 1 ÷ 1 4 1
2
layer protocol. Of the given protocols, only FTP and ç1 + + + ..... ÷ = ç ÷= ´ =
POP3 are stateful application layer protocols. = 4 ç 4 çè 4 ÷ø ÷ 4ç 1 4 3 3
è ø ç 1 - ÷÷
36. 10 è 4ø
(x3 + x4 + x5 + x6 + ....)3 = 0.33
= x9 (1 + x + x2 + .......)3 40. (d)
= x9 ((1 – x)–1)3
= x9 (1 – x)–3 The output of first multiplexer is Y1 = P0 + PR = PR
The output of second multiplexer is
¥
( n + 1)( n + 2 ) x n
=x å
9
2 X = QR + QY1 = QR + QPR
n=0
To find the coefficient of x12, put n = 3 Þ QR + PQR

4´5 41. 456


= = 10 Number of times the DMA controller needs to get the control
2
of the system bus from the processor to transfer the file
37. 198 from the disk to main memory =
The given recurrence relation can be written as
an – an–1 = 6n2 + 2n ...(i) 29154kB
Þ Þ 455.53125 = 456
Hence, the characteristic equation is m – 1 = 0, m = 1 216 byte
and complementary solution = a (n1) = C1 (1) n = C1 42. 33.33
Old design tp = 800
(b)
(2
)
Let the particular solution be a n = An + Bn + C n ...(ii) New design tp = 600
800 - 600
(... RHS is second degree polynomial and 1 is root) Throughput = ´ 100% = 33.33%
By putting an = (An 2 + Bn + C)n in (1) and solving A = 600
2, B = 4, C = 2 43. (b)
44. (d)
General solution is a n = a (c) (b) 2
n + a n = C1 + (2n + 4n + 2) n P[a] will have the maximum value of the array, when a = b.
Given a1 = B Þ B = C1 + B Þ C1 = 0 45. (a)
Given a99 = K × 104
Þ [2(99)2 + 4(99) + 2]99 = 2[(100 – 1)2 + 2(100 – 1) +
(100 – 1)]
= 104(198) = K × 104 main()
K = 198
38. 2 Count (3)
In the given properties, we can observe that f(1) = f(2)
= f(3) = f(4) = f(6) = f(7) and f(5) = f(10) = f(15) = ....
Obviously, the range of f(x) will contain two distinct Pr(4)
elements only. Pr(3) Pr(1) Count (2)
39. 0.33
From the given steps the probabilities of y are
2 Pr(4)
1 æ 1 öæ 1 ö æ 1 ö 1 Pr(2) Count (1)
, ç ÷ç ÷ , ç ÷ ,...... Pr(2)
4 è 4 øè 4 ø è 4 ø 4
Hence, Required probability
Pr(4)
1 æ 1 1 ö ææ 1 ö 1 ö
2
Pr(1) Pr(3) Count (0)
= 4 ç 4 4 ÷ ç ç 4 ÷ ´ 4 ÷÷ + .....
+ ´ + ç
è ø èè ø ø
2 3 Output will be 312213444.
1 æ1ö æ1ö 46. (d)
= + ç ÷ + ç ÷ + .....
4 è4ø è4ø Dynamic scoping refers to definition of free variable in the
reverse order of calling sequence.
SOLVED PAPER - 2016 2016-11

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

0 a1 1000 Bytes MTU


1 a2 (980 + 20) Bytes 100 Bytes
2 a3 (80 + 20) Bytes
3 a4
Therefore the no. of fragments that are transferred in this
4 a5 case is 13.
5 a6 64. 1.2
6 a7 a11 a12 a13 a14 a15 a16 a17 a18 a19 a 20 Given c = 1 Mb
7 a8 Max Output rate (m) = 20 Mbps
Arrival rate (p) = 10 Mbps.
8 a9
\ The minimum time required to transmit the data is
9 a10
c
For first a1 to a20 there are 20 page faults. S=
m-p
Next a1 to a9, Hit again a10 to a19, replace any location from
1Mb 1
0 to 9 for a20 Hit. So total no. of page faults = 30. S= = = 0.1sec
20 - 10Mbps 10
Difference = 31 – 30 = 1
For 12 Mb of data, S value becomes 1.2 seconds.
60. (a) 65. 2500
61. (a) Frame size (L) = 1000 bytes
Sender side Bandwidth (Bs) = 80 kbps
Two phase locking protocol ensures serializability and due
Acknowledgement (LA) = 100 bytes
to following linear order in acquiring the locks, there will be Receiver side Bandwidth (BR) = 8kbps
no deadlock. Tp = 100 ms
62. (b) Tx
n=
Tx + Tack + 2Tp

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

Miss rate (%)


L ® id [E L ® id E
E ® num] E ® E[num] 60
E ® num] [E E ® [num] 50
Which of the grammars correctly generate the declaration 40
mentioned above? 30
(a) Both G1 and G2 (b) Only G1 20
(c) Only G2 (d) Neither G1 nor G2
10
57. Consider the following processes, with the arrival time and
0
the length of the CPU burst given in milliseconds. The 0 10 20 30 40 50 60 70 80 90
scheduling algorithm used is preemptive shortest remaining-
time first. Cache Size (MB)

Proces s Arrival Time Burs t Time


The smallest cache size required to ensure an average
P1 0 10 read latency of less than 6 ms is ________MB.
P2 3 6 61. Consider the following database schedule with two
P3 7 1 transactions, T1 and T2.
P4 8 3 S = r2(X); r1(X); r2(Y); w1(X); r1(Y); w2(X); a1; a2
where ri(Z) denotes a read operation by transaction Ti on
The average turnaround time of these processes is a variable Z, wi(Z) denotes a write operation by Ti on a
________ milliseconds. variable Z and ai denotes an abort by transaction Ti.
58. Consider the following two-process synchronization Which one of the following statements about the above
solution : schedule is TRUE?
Process 0 Process 1 (a) S is non-recoverable
Entry: loop while (turn = = 1); Entry: loop while (turn = = 0); (b) S is recoverable, but has a cascading abort
(c) S does not have a cascading abort
(critical section) (critical section)
(d) S is strict
Exit: turn =1; Exit: turn = 0;
62. Consider the following database table named
The shared variable turn is initialized to zero. Which one water_schemes :
of the following is TRUE?
(a) This is a correct two-process synchronization water_schemes
solution. scheme_no. district_name capacity
(b) This solution violates mutual exclusion requirement. 1 Ajmer 20
(c) This solution violates progress requirement. 1 Bikaner 10
(d) This solution violates bounded wait requirement. 2 Bikaner 10
59. Consider a non-negative counting semaphore S. The 3 Bikaner 20
operation P(S) decrements S, and V(S) increments S. 1 Churu 10
During an execution, 20 P(S) operations and 12 V(S)
2 Churu 20
operations are issued in some order. The largest initial
value of S for which at least one P(S) operation will remain 1 Dungargarh 10
blocked is _________ .
The number of tuples returned by the following SQL query
60. A file system uses an in-memory cache to cache disk is ________.
blocks. The miss rate of the cache is shown in the figure. with total (name, capacity) as
The latency to read a block from the cache is 1 ms and to
select district_name, sum (capacity)
read a block from the disk is 10 ms. Assume that the cost
of checking whether a block exists in the cache is from water_schemes
negligible. Available cache sizes are in multiples of 10 MB. group by district_name
SOLVED PAPER - 2016 2014-19

with total_avg (capacity) as I. At least three non-overlapping channels are available


select avg (capacity) for transmissions.
from total II. The RTS-CTS mechanism is used for collision
select name detection.
from total, total_avg III. Unicast frames are ACKed.
where total.capacity ³ total_avg.capacity (a) II, and III (b) I and III only
63. A network has a data transmission bandwidth of 20 × 106 (c) II and III only (d) II only
bits per second. It uses CSMA/CD in the MAC layer. The 65. Consider a 128×103 bits/second satellite communication
maximum signal propagation time from one node to link with one way propagation delay of 150 milliseconds.
another node is 40 micro seconds. The minimum size of a Selective retransmission (repeat) protocol is used on this
frame in the network is ________ bytes. link to send data with a frame size of 1 kilobyte. Neglect
64. For the IEEE 802.11 MAC protocol for wireless the transmission time of acknowledgement. The minimum
communication, which of the following statements is/are number of bits required for the sequence number field to
TRUE? achieve 100% utilization is ________ .
2014 -20 SOLVED PAPER - 2016

1. (b) 10. (c)


2. (a) ‘Cope with’ in the given sentence means to deal 11. 4 Given expression is :
effectively with something difficult. Therefore, ‘put up = P Ù (P Þ Q)
with’ is the closest in meaning to the underlined phrase = P Ù (P¢Ú Q)
in the given sentence.
= (P Ù P¢) Ú (P Ù Q)
3. (c) Praise is the odd word out as others are the synonyms
of mock. = F Ù (P Ù Q)
= (P Ù Q)
+1 +1 +1 +1
1. (P Ù Q) Þ F = (P Ù Q)¢ Ú F = (P¢ Ú Q¢) Ú F = (P¢ Ú Q¢)
4. (d) (a) C A D B E (b) J H K I L = Contingency but not Tautology
+1 +1
2. (P Ù Q) Þ Q = (P Ù Q)¢ Ú Q = (P¢ Ú Q¢) Ú Q = P¢ Ú (Q¢ Ú
+1 +1 +1 +1 Q) = P¢ Ú T = T
(c) X V Y WZ (d) O N P M Q = Tautology
+1 –1
3. (P Ù Q) Þ T = (P Ù Q)¢ Ú T = T = Tautology
In options (a), (b) and (c), the letters skipped between 4. (P Ù Q) Þ P Ú Q = (P Ù Q)¢ Ú P Ú Q = (P¢ Ú Q¢) Ú P Ú Q
consecutive pair of letters in the english alphabet in = (P¢ Ú P) Ú (Q Ú Q¢)
increasing order i.e. A and B, H and I, V and W but in
= T Ú T = T = Tautology
option (d). N and M are present instead of M and N.
So, option (d) is odd one in the group. 5. (P Ù Q) Þ Q¢ Ú P = (P Ù Q)¢ Ú Q¢ Ú P = (P¢ Ú Q¢) Ú Q¢ Ú
P = (P¢ Ú P) Ú (Q¢ Ú Q¢)
a n + bn a n + bn a n + bn = T Ú Q¢ = T = Tautology
5. (b) -n -n
= = n = a n bn
a +b 1 1 b +a n
Therefore, statements (2), (3) (4) and (5) satisfies.
+
a n bn a n bn
12. 9
(ab)n = (4) n Let f(x) is polynomial of degree n,
then g(x) = f¢(x) is polynomial of degree n,
6. (a) Facebook WhatsApp Þ f(x) + f(– x) is polynomial of degree n,
150
But given f(x) + f(–x) is polynomial of degree 10.
\ n =10
35 20 Þ g(x) is polynomial of 9.
\ g(x) – g(– x) is polynomial of degree 9.
13. 4
Any planar graph is four-colourable.
14. (c)
The faculty members having any account = 150 – 30 = 120 Statement I is not true.
The faculty members having both the accounts = (FB + W) – x + y+ z = 5
120
x + y+ z = 0
\ The number of faculty members connected = (55 + 85)
The above equations has no solution, when number of
– 120 = 20
equations is less than number of variables.
Only through Facebook Account = 55 – 20 = 35.
Statement II is also not true.
7. (d)
Consider the equations:
8. (d)
x – 2y = 2
5 5´ 4 3´ 2 2x + 8y = 16
9. (c) C2 ´ 3 C2 = ´ = 30
2 ´1 2 ´ 1 x+y=5
Hence, 30 rectangles can be observed in the grid. The solution of these equations is x = 4 & y = 1
SOLVED PAPER - 2016 2014-21

Statement III is true. 23. (d)


Consider the equations: For an array already sorted in ascending order, Quicksort
x+y=4 has a complexity Q(n2) [Worst Case].
x + 2y = 0 Bubblesort has a complexity Q(n) [Best Case].
These equations has solutions x = 8 and y = –4 Mergesort has a complexity Q(n log n) [Any Case] .
15. 0.55 Insertsort has a complexity Q(n) [Best Case]
Event of selecting type-I bulb = E 1 24. (c)
Event of selecting type-II bulb = E2 Floyd-Warshall algorithm is based on dynamic programming
Event of selecting a bulb lasts more than 100 hours = A paradigm.
Given P(E1) = 0.5, P(E2) = 0.5 25. (c)
P(A/E1) = 0.7, P(A/E2) = 0.4 The time complexity which can put all these operations
Required Probability, together will be O(N2).
P(A) = P(E1) P(A/E1) + P(E2) P(A/E2) 0, 1 1, 0
26. 2 +
= 0.5 × 0.7 + 0.5 × 0.4
= 0.55 So, the minimum number of states is 2.
16. 0.125 27. (c) L1 has the property that no. of a’s should be equal to
Given that 1, 2, 4 are eigen values of matrix A no. of b’s in a string, and all a’s should precede all b’s.
Hence extra memory will be required to check this
1 1 property of a string (Finite Automaton can't be built
Þ |A| = 8 and |A–1| = A = 8
for this type of language). Hence this is not regular
language. Therefore P is False. L2 has the property

( )
-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.

GENERALAPTITUDE (c) Flippancy – Lightness


(d) Profligate – Extravagant
QUESTION 1 TO 5 CARRY ONE MARK EACH 4. Based on the given statements, select the most appropriate
option to solve the given question.
1. Given Set A = {2, 3, 4, 5} and Set {11, 12, 13, 14, 15}, two If two floors in a certain building are 9 feet apart, how many
numbers are randomly selected, one from each set. What is steps are there in a set of stairs that extends from the first floor
the probability that the sum of the two numbers equals 16? to the second floor of the building?
(a) 0.20 (b) 0.25 Statements:
(c) 0.30 (d) 0.33
2. Which of the following options is the closest in meaning to 3
I. Each step is foot high
the sentence below? 4
She enjoyed herself immensely at the party. II. Each step is 1 foot wide.
(a) She had a terrible time at the party (a) Statement I alone is sufficient, but statement II alone is
(b) She had a horrible time at the party not sufficient
(c) She had a terrific time at the party (b) Statement II alone is sufficient, but statement I alone is
(d) She had a terrifying time at the party not sufficient
3. Which one of the following combinations is incorrect? (c) Both statements together are sufficient, but neither
(a) Acquiescence – Submission statement alone is sufficient
(b) Wheedle – Roundabout (d) Statement I and II together are not sufficient
2015 -2 SOLVED PAPER - 2015
5. Didn’t you buy ______ when you went shopping? A ns wered A n s wered No t
(a) any paper (b) much paper Q. No M arks
Co rrectly W ron gly A ttemp ted
(c) no paper (d) a few paper
1 2 21 14 6
QUESTION 6 TO 10 CARRY TWO MARKS EACH 2 3 15 27 2
6. The pie chart below has the breakup of the number of 3 1 11 29 4
students form different departments in an engineering college 4 2 23 18 3
for the year 2012. The proportion of male to female students 5 5 31 12 1
in each department is 5:4. There are 40 males in Electrical What is the average of the marks obtained by the class in the
Engineering. What is the difference between the numbers of examination?
female students in the Civil department and the female (a) 2.290 (b) 2.970
students in the Mechanical department? (c) 6.795 (d) 8.795
10. The probabilities that a student passes in Mathematics,
Mechanical,
Physics and Chemistry are m, p, and c respectively. Of these
10%
subjects, the student has 75% chance of passing in atleast
Computer one, a 50% chance of passing in atleast two and a 40% chance
Electrical, 20% Science, 40% of passing in exactly two.
Following relation are drawn in m, p, c.
I. p + m + c = 27/20
II. p + m + c = 13/20
III. (p) × (m) × (C) = 1/10
Civil, 30%
(a) only relation I is true
7. The given statement is followed by some courses of action. (b) only relation II is true
Assuming the statement to be true, decide the correct option. (c) relations II and III are true
Statement: There has been a significant drop in the water (d) relations I and III are true
level in the lakes supplying water to the city.
Course of action:
TECHNICAL SECTION
I. The water supply authority should impose a partial cut
in supply to tackle the situation. QUESTION 11 TO 35 CARRY ONE MARK EACH
II. The government should appeal to all the residents 11. Suppose that everyone in a group of N people wants to
through mass media for minimal use of water. communicate secretly with the N-1 others using symmetric
II. The government should ban the water supply in lower key cryptographic system. The communication between any
areas. two persons should not be decodable by the others in the
group. The number of keys required in the system as a whole
(a) Statements I and II follow
to satisfy the confidentiality requirement is
(b) Statements I and III follow
(a) 2N (b) N(N-1)
(c) Statements II and III follow
(c) N(N-1)/2 (d) (N-1)2
(d) All statements follow 12. Which one of the following fields of an IP header is NOT
8. Select the alternative meaning of the underlined part of the modified by a typical IP router?
sentence. (a) Checksum
The chain snatchers took to their heels when the police party (b) Source address
arrived. (c) Time To Live (TTL)
(a) took shelter in a thick jungle (d) Length
(b) open indiscriminate fire 13. Which one of the following is TRUE at any valid state in shift
(c) took to flight – reduce parsing?
(d) unconditionally surrendered (a) Viable prefixes appear only at the bottom of the stack
and not inside
9. The number of students in a class who have answered
(b) Viable prefixes appear only at the top of the stack and
correctly, wrongly, or not attempted each question in exam,
not inside
are listed in the table below. The marks for each question are
(c) The stack contains only a set of viable prefixes
also listed. There is no negative or partial marking.
(d) The stack never contains viable prefixes
SOLVED PAPER - 2015 2015-3

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® Î, ^ ® Î

Roll No. Student Name


1 Raj Which one of the following sequences must follow the string
2 Rohit
101100 so that the overall string is accepted by the
automation?
3 Raj
(a) 10110 (b) 10010
Performance (c) 01010 (d) 01001
42. What is the output of the following C code? Assume that the
address of x is 2000 (in decimal) and an integer requires four
Roll No Course Marks bytes of memory?
1 Math 80 int main( )
1 English 70 {
2 Math 75 unsigened int x[4] [3] = {(1,2,3), {4,5,6}, {7, 8, 9}, {10, 11,
3 English 80 12}};
printf(“%u, %u, %u”, x+3, *(x+3),
2 Physics 65
*(x+2)+3);
3 Math 80
}
(a) 2036, 2036, 2036
Consider the followin g SQL query. SELECT S. (b) 2012, 4, 2204
Student_Name, sum (P.Marks) (c) 2036, 10, 10
FROM Student S, Performance P (d) 2012, 4, 6
WHERE S.Roll_No. = P.Roll_No. 43. The binary operator ¹ is defined by the following truth table.
GROUP BY S.Student_Name
The number of rows that will be returned by the SQL query
p q p¹q
is _______.
0 0 0
40. Consider a uniprocessor system executing three tasks T1, T2
and T3, each o which is composed of an infinite sequence of 0 1 1
jobs (or instances) which arrive periodically at intervals of 3, 1 0 1
7 and 20 milliseconds, respectively. The priority of each task 1 1 0
is the inverse of its period, and the available tasks are
scheduled in order of priority, with the highest priority task Which one of the following is true about the binary operator ¹ ?
scheduled first. Each instance of T1, T2 and T3 requires an (a) Both commutative and associative
execution time of 1, 2 and 4 milliseconds, respectively. Given (b) Commutative but not associative
that all tasks initially arrive at the beginning of the 1st (c) Not commutative but associative
millisecond and task preemptions are allowed, the first (d) Neither commutative nor associative
instance of T3 completes its execution at the end of ______
milliseconds.
2015 -6 SOLVED PAPER - 2015
44. The least number of temporary variables required to create 48. Let G = (V, E) be a simple undirected graph, and s be a
three-address code in static single assignment form for the particular vertex in it called the source. For x Î V, let d(x)
expression q+r/3+s–t*5+u*v/w is ______. denote the shortest distance in G from s to x. A Breadth First
45. Search (BFS) is performed starting at s. Let T be resultant
BFS tree. If (u, v) is an edge of G that is not in T, then which
b a one of the following CANNOT be the value of d(u) – d(v)?
(a) –1 (b) 0
a (c) 1 (d) 2
M:
49. Let G be a connected planar graph with 10 vertices. If the
number of edges on each face is three, then the number of
b edges in G is ______.
50. Consider the operations
f(X,Y,Z) = X1YZ+ XY1+Y1Z1 and
a b
g(X,Y,Z) = X1YZ+ X1YZ1++XY.
Which one of the following is correct?
b
N: (a) Both {f} and {g} are functionally complete
(b) Only {f} is functionally complete
(c) Only {g} is functionally complete
a
(d) Neither {f} nor {g} is functionally complete
Consider the DFAs M and N given above. The number of 51. Consider the following 2 × 2 matrix A where two elements
states in a minimal DFA that accepts the languages are unknown and are marked by a and b. The eigenvalues of
L(M) Ç L(N) is ________. this matrix ar –1 and 7. What are the values of a and b?
46. Consider a main memory with five page frames and the æ 1 4ö
following sequence of page references: 3, 8, 2, 3, 9, 1, 6, 3, A = çè b a ÷ø
8, 9, 3, 6, 2, 1, 3. Which one of the following is true with
(A) a = 6, b = 4 (B) a= 4, b = 6
respect to page replacement policies First In First Out (FIFO)
(C) a = 3, b = 5 (D) a= 5, b = 3
and Least Recently Used (LRU)?
(a) Both incur the same number of page faults 52. 2/ p cos(1/ x)
òp dx = _________ .
(b) FIFO incurs 2 more page faults than LRU x2
(d) LRU incurs 2 more page faults than FIFO 53. Suppose that the stop-and-wait protocol is used on a link with
(d) FIFO incurs 1 more page faults than LRU a bit rate of 64 kilobits per second and 20 milliseconds
47. Suppose L = {p,q,r,s,t} is a lattice represented by the propagation delay. Assume that the transmission time for the
following Hasse diagram: acknowledgement and the processing time at nodes are
negligible. Then the minimum frame size in bytes to achieve
t a link utilization of at least 50% is _________.
54. A positive edge-triggered D flip-flop is connected to a
positive edge-triggered JK flip-flop as follows. The Q output
of the D flip-flop is connected to both the J and K inputs of
q r s
the JK flip-flop, while the Q output of the JK flip-flop is
connected to the input of the D flip-flop is connected to both
the J and K inputs of the JK flip-flop, while the Q output of
p the JK flip-flop is connected to the input of the D flip-flop.
Initially, the output of the D flip-flop is set to logic one and
For any x, y Î L, not necessarily distinct, x Ú y and x Ù y are the output of the JK flip-flop is cleared. Which one of the
join and meet of x, y respectively. Let L3 = {(x,y,z): x,y,z Î following is the bit sequence (including the initial state)
L} be the set of all ordered triplets of the elements of L. Let generated at the Q output of the JK flip-flop when the flip-
pr be the probability that an element (x, y, z) Î L3 chosen flops are connected to a free running common clock? Assume
equiprobably satisfies x Ú (y Ù z) = (x Ú y) Ù (x Ú z). Then that J = K = 1 is the toggle mode and J = K = 0 is the state-
holding mode of the JK flip-flop. Both the flip-flops have
(a) pr = 0 (b) pr = 1
non-zero propagation delays.
1 1 (a) 0110110….. (b) 0100100….
(c) 0 < pr £ (d) < pr < 1
5 5
(c) 011101110…. (d) 011001100…
SOLVED PAPER - 2015 2015-7

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

GENERAL APTITUDE TECHNICAL SECTION


1. (a) Number of possible combinations of two number 11. (c) In Symmetric Key Cryptography, if 'N' number of users
is keen to partake, then N (N-1)/2 number of keys is
one from each set = 4C1 ´ 5C1 = 20 required to satisfy the confidentiality requirements of
Combinations having sum 16 are (2, 14), (3, 13), any users.
(4, 12) and (5, 11) 12. (b) Option (a), (Checksum) needs to be reorganized by each
visited Router since Time to Live value is customized.
4 Option (b), (Source Address) can't be customized by
Required Probability = = 0.20
20 an IP router. Only NAT (Network Address Translation)
2. (c) can transform it.
3. (b) As a verb wheedle is to cajole or attempt to persuade Option (c), (TTL) is decremented by each visited router.
by flattery. As a adjective roundabout is indirect When it arrives at to zero, then packet will be rejected.
circuitous or circumlocutionary; that doesnot do some Option (d), (Length) also customized whenever there
they in a direct way. is a need of performing the destruction process.
3
13. (b) Viable prefixes appear only at the top of the stack and
4. (a) I. Each step is foot high. not inside is valid in shift reduce parsing, because we
4 will write the shift reduce parsing program for every
9´ 4 variable such that if any variable contain more than
No. of steps = = 12 one possibility, it will choose the correct production.
3
14. (a) We know that the maximum no. of nodes in a binary
Statement I alone is sufficient to answer.
tree with (height) h = 2h+1–1.
5. (a)
Here h = 5, then, we easily calculate the h as:
6. 32 Let total number of students be x
h = 25 + 1–1= 64 – 1 = 63
5 And the minimum no. of nodes with height h is h + 1.
Then, ´ 20% of x = 40
9 \h = 5
5 20 x L=0
´ = 40
9 100 L=1
x = 360 L=2
4 L=3
No. of females in civil department = ´ 30% of x
9 L=4
4 L=5
No. of females in Mechanical department = ´ 10% of x
9 15. (c) Prim's Algorithm always select minimum distance
between two of its positions which is not anything
4 é 3x x ù 4 x but greedy method. Floyd-Warshall always varies it
Difference = - = ´
9 êë 10 10 úû 9 5 distance at each iteration, which is nothing but dynamic
programming, in Merge Sort first, we always divided
4 360 the data and merge to it withcomplete sorting. Hence
= ´ = 32
9 5 divide and conquer.
7. (a) 8. (c) 16. (c) We can present p « q as:
21 ´ 2 + 15 ´ 3 + 11 ´ 11 ´ 1 + 23 ´ 2 + 31 ´ 5 p « q º (p ® q) Ù (p ® q)
9. (b) = 2.970
21 + 15 + 11 + 23 + 31 º (7p Ú q) Ù (7p Ú q) (\ p ® q = 7p Ú q)
10. (a) P(atleast two) – P(exactly 2) º (7p Ù q) Ú (q Ù 7q) Ú (7p Ù p) Ú (q Ù p)
= 0.5 – 0.4 = 0.1 (using distributive laws)
0.75 = p + m + c + 0.1 – (0.5 + 0.11 × 2) º (7p Ù 7q) Ú (q Ù p) (using complement laws
and commutative laws)
27
\ p + m + c = 0.65 + 0.7 = 1.35 = = \ p « q is NOT equivalent to (7p Ù q) Ú (q Ù 7q)
20
2015 -10 SOLVED PAPER - 2015
17. (d) SELECT operation in SQL perform vertical partitioning 24. (b) I: FALSE
which is made by projection operation in relational The sequence number of the subsequent segment
calculus, but SQL is multi-sets. Hence the projection depends on the number of 8-byte characters in the
operation in relational algebra, except that SELECT in current segment.
SQL retains duplicates answer is correct. II:TRUE
Depending on the value of a or expected RTT it may
18. (d) I Þ L1 is recursive or may not be greater than 1.
This one is true, because L1 is context free which is III: FALSE
nonentity but recursive, recursive language is closed It is the size of the receiver's buffer that's never
under complement. Hence it is true. changed. Receive Window is the part of the receiver's
buffer that's changing all the time depending on the
II Þ L2 (complement of L2) is recursive processing ability at the receiver's side and the network
If L2 and L2 both are recursive enumerable then L2 is traffic.
recursive IV: TRUE
The number of unappreciated bytes that A sends cannot
Hence, statement II is false
exceed the size of the receiver's window. But if it can't
III Þ L1 is context free exceed the receiver's window, then it definitely has no
way to exceed the receiver's buffer as the window size
Which is false because context free language does
is always less than or equal to the buffer size. On the
not closed under complement.
other hand, for urgent messages, the sender CAN send
IV Þ L1 L2 is recursive enumerable. it in even although the receiver's buffer is full.
25. (a)
L1 recursive, because every recursive language is 26. (d) Given that Logical Address (LA) = 32 bits
Logical Address Size (LAS) = 232 = 448
also recursive enumerable.
Page size = 4 kB
L2 recursive enumerable. LAS 44B G
\ number of pages = = = 220 = 1m
P.S 4KB K
L1 È L2 Þ recursive enumerable, because recursive
Size of the page table entry = 4 bytes
enumerable language closed under union.
19. (c) 2A ® Power set of A i.e., set of all subsets of A. Since \ Page table size = 4B × 1m = 4 mB
27. (c) If we execute P2 process after P1 process, then we get
empty set is a subset of every set
B= 3
\ φ Í 2 A and φ Î 2 A If we execute P1 process after P2 process, then we get
B= 4
Since {5, 6 } Í and 5 Ï 2A If we did preemption between P1 and P2 processes,
then we get B = 2 (Preemption have done from P1 to
\ {5, 6 } Î 2 A and {5, 6 }Í 2 A
P2) or B = 3 (Preemption have done from P2 to P1). So,
\ I, II and III are TRUE among 2 and 3 values, only one value will be saved in
20. (d) 0000 – 0 B. So, total no. of different values that B can possibly
1000 – 8 take after the execution is 3.
1100 – 12 1
and so on.
28. (c) Let y = lim xx
21. (c) I . XML overcomes the limitations in HTML to support X ®¥
a structured way of organizing content.There for, it is
true. In x
In y = lim (Taking Logorihms)
II. HTML is case insensitive while XML is case X ®¥ x
sensitive Hence it is false.
III. XML supports user defined tags while HTML 1
¥
uses predefined tags. Hence it is true. In y = lim x ( form and using L-Hospital rule)
IV XML tags must be closed Hence it is false. X ®¥ 1 ¥
22. (a) According to the given question, we can say that In y = 0
each data record in the data file has one entry in the Hence, y = 1
index file. So it must be dense index. 29. (b) When the pivot is the smallest or largest element at
23. (a) In-order traversal of binary search tree gives ascending partitioning on a block of size n the result capitulates
orders and in BST, at every node root element is greater one empty sub-block, one element (pivot) in the correct
than and equal to all element present in left sub-tree place and sub block of size n-1
and less than or equal to all the elements in right sub- Hence recurrence relation
tree. T(n) = T(n – 1) + T(1) + Cn
SOLVED PAPER - 2015 2015-11

30. (a) g(x) = 1 – x ...(1) Equivalence class partitioning is a software testing


method that divides the input data of a software unit
x
h (x) = ...(2) into partitions of corresponding data from which test
x -1
cases can be derived, which is nothing but black box
Replace x by h (x) in ...(1) testing.
Replace x by g (x) in ...(2) Hence
g(h(x) ) =1– h (x) Q Matches with I.
x -1 Volume testing submits to testing a software
= 1- = application with certain amount of data which is
x -1 x -1
nothing but system testing.
g (x) Hence
h ( g ( x )) = =
1- x
g (x) -1 -x R matches with II.
Alpha testing is replicated or actual operation testing
g ( h ( x )) x by potential client/stakeholders, which is nothing but
= performance testing.
h ( g ( x )) ( x - 1)(1 - x ) Hence
R matches with IV
x
g ( h ( x )) é 2 2 ù é l11 0 ù é1 u12 ù
= x -1 35. 5 A = LU Þ ê ú=ê úê ú
h ( g ( x )) 1- x ë 4 9 û ël21 l22 û ë0 1 û

é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

for (k = 1;k < p;k = k * 2)


++q; 2 -1 3 - 2 4 - 3 100 - 99
= + + + ...
} 1( 2 ) 2 ( 3 ) 3 ( 4 ) 99 (100 )
return q;
}
1 1 1 1 1 1 1 1 1
\ nlog(logn) = - + - + ... + - + -
56. 3.2 Speed up = old execution time/ new execution time. 1 2 2 3 3 98 99 99 100

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

Without pipelining an instruction was taking 4 cycles.


After pipelining to 5 stayes we need to see the
maximum clock cycle a staye can take and this will be 10 15
16 17

the CPI assuning no stalls.


57. 5
8 4
a11 a12 a21 a22
Insert 35 Þ according to CBT

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

P + R + S +T + U 11. 36 Let N = 2100


=S = 22 + 3 × 52 × 7 (i.e., product of primes)
5
Then the number of division of 2100 is
Statement I.
(2 + 1). (1 + 1). (2 + 1). (1 + 1) i.e., (3) (2) (3) (2) i.e.., 36
2P + 2R + 2S + 2T+2U 12. 51 Recurrence Relation is
5 f(n) = 1, if n = 1
n -1
æ P+ R +S+ T + U ö
= 2ç
5
÷ = 2S f(n) = 1 + å f (k).f (n - k) if n > 1
è ø k =1

\ 2P, 2R, 2S, 2T, 2U is an arithmetic sequence.


Statement II. n 1 2 3 4 5 6
f (n) 1 2 5 15 51 188
( P - 3) + ( R - 3) + ( S - 3) + ( T - 3) + ( U - 3)
5 13. (d) Consider first three element of the list, atleast one of
them will be neither minimum nor maximum
15 \ Q(1)
=S - =S - 3
5 14. 2008
\ These terms are in arithmetic sequence. Cardinality of the power set of {0, 1, 2, … , 10} is 211
Statement III. i.e.., 2048
SOLVED PAPER - 2015 2015-23

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

3 4 45 54. 6.1 60sec ® 15000 rotations


= 7 9 105 60
= 4 ms ¬ 1 rotation
13 2 195 15000

= 0 (Since C1, C3 are proportional i.e., C3 = 15 C1) 1


\ Average rotational delay = ´ 4 = 2ms
50. (c) 2
51. (a) Since f(0) ® ¥ Þ As per question, average seek time
\ f is not bounced in [–1, 1] and hence f is not = 2 × Avg. rotational delay
continuous in [–1, 1] = 2 × 2 = 4ms
1 0 -1/ 3 1
A= ò1 f (x)dx = ò-1 x dx + ò x -1/ 3dx ü
0 1sec ® 50 ´106 bytes
ï
512 ý disk transfer time
0.01ms = ¬ 512 bytes ï
( )
2 2/3
( )
2 2/3
0 1
= x + x =0 50 ´106 þ
3 -1 3 0

\ Statement II only true Þ As per question, controller's transfer time is


52. 13 I Þ Instruction Fetch and Decode = 10 × 0.01 ms = 0.1 ms
O Þ Operand Fetch \ Avg. Time = 4ms + 0.1 ms + 2ms = 6.1 ms
P Þ Perform operation 55. 36 Given page size = 8 kb
W Þ write back the result PAS = 32 – bit

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

\ It means one entry requires 19 + 5 = 24 bits


\ Page Table size = n × e
24 × 220 × 3 = n × (24) A
Sum = 2.4 m sec
B

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

C Carry = 4.8 m sec

357 kB 491kB 468kB 201kB

not allocated to any process B3 A3 B2 A2 B1 A1 B0 A0


c0
57. 0.95 |X| = 2, |Y| = 20
Number of functions from X to Y is 202 i.e., 400 and F.A2 F.A2 F.A1 F.A0
number of one-one functions from X to Y is 20p2 i.e.,
20 × 19 = 380

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.

GENERAL APTITUDE 3. A function f(x) is linear and has a value of 29 at x = – 2 and


39 at x = 3. Find its value at x =5.
QUESTION 1 TO 5 CARRY ONE MARK EACH
(a) 59 (b) 45
(c) 43 (d) 35
1. The Tamil version of _________ John Abraham – starrer 4. Select the pair that best expresses a relationship similar to
Madras Café _______ cleared by the Censor Board with no that expressed in the pair
cuts last week, but the film’s distributors ______ no takers
Children : Pediatrician
among the exhibitors for a release in Tamil Nadu _______
(a) Adult : Orthopaedist
this Friday.
(b) Females : Gynaecologist
(a) Mr., was, found, on
(b) a, was, found, at (c) Kidney : Nephrologist
(c) the, was, found, on (d) Skin: Dermatologist
(d) a, being, find, at 5. Extreme focus on syllabus and studying for tests has become
2. If ROAD is written as URDG, then SWAN should be written such a dominant concern of Indian students that they close
as: their minds to anything _____ to the requirements of the
(a) VXDQ (b) VZDQ exam.
(c) VZDP (d) UXDQ (a) related (b) extraneous
(c) outside (d) useful
2015 -30 SOLVED PAPER - 2015
QUESTION 6 TO 10 CARRY TWO MARKS EACH (a) x = y–|y| (b) x = –(y–|y|)
6. Choose the most appropriate equation for the function drawn (c) x = y+ |y| (d) x = – (y+|y|)
as a thick line, in the plot below. 7. Alexander turned his attention towards India, since he had
conquered Persia. Which one of the statements below is
logically valid and can be inferred from the above sentence?
y (a) Alexander would not have turned his attention towards
India had he not conquered Persia.
(2, 0) x (b) Alexander was not ready to rest on his laurels, and
wanted to march to India
(0, – 1) (c) Alexander was completely in control of his army and
could command it to move towards India.
(d) Since Alexander’s kingdom extended to Indian borders
after the conquest of Persia, he was keen to move
further.
8. The exports and imports (in crores of Rs) of a country from the year 2000 to 2007 are given in the following bar chart. In which
year is the combined percentage increase in imports and exports the highest?

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

(b) R – Home, S – Power, P – Defense, (a) Only I is correct


Q – Telecom, T – Finance (b) Only I and III are correct
(c) P – Home, Q – Power, T – Defense, (c) Only II and III are correct
S – Telecom, U – Finance (d) All of I, II, and III are correct
(d) Q – Home, U – Power, T – Defense, 18. While inserting the elements 71, 65, 84, 69, 67, 83 in an
R – Telecom, P – Finance empty Binary Search Tree (BST) in the sequence shown, the
element in the lowest level is
TECHNICAL SECTION
(a) 65 (b) 67
QUESTION 11 TO 35 CARRY ONE MARK EACH (c) 69 (d) 83
19. Let # be a binary operator defined as X # Y = X1 +Y1 where
11. Consider the following array of elements
X and Y are Boolean variables.
(89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100)
Consider the following two statements
The minimum number of interchanges needed to convert it
into a max-heap is S1: (P # Q) # R = P # (Q # R)
(a) 4 (b) 5 S2: Q # R = R # Q
(c) 2 (d) 3 Which of the following is/are true for the Boolean variables
P, Q and R?
e- x
(
12. The value of lim x ®¥ 1 + x 2 ) is (a) Only S1 is true (b) Only S2 is true
(c) Both S1 and S2 are true (d) Neither S1 nor S2 are true
n
1
(a) 0 (b) 20. Consider the equality å i3 = X and the following choices
2 i =0
(c) 1 (d) ¥ for X
13. The number of 4 digit numbers having their digits in non I. q(n4) II. q(n5)
III. O(n )5 IV. W(n3)
decreasing order (from left to right) constructed by using the
digits belonging to the set {1, 2, 3} is ______. The equality above remains correct if X is replaced by
14. Let L be the language represented by the regular expression (a) Only I (b) Only II
å *0011å* where å = {0,1} . (c) I or III or IV but not II (d) II or III or IV but not I
21. The maximum number of processes that can be in Ready state
What is the minimum number of states in a DFA that
for a computer system with n CPUs is
recognizes L (complement of L)? (a) n (b) n2
(a) 4 (b) 5 (c) 2n (d) Independent of n
(c) 6 (d) 8 22. Consider a machine with a byte addressable main memory of
15. Consider a software program that is artificially seeded with
220 bytes, block size of 16 bytes and a direct mapped cache
100 faults. While testing this program, 159 faults are
having 212 cache lines. Let the addresses of two consecutive
detected, out of which 75 faults are from those artificially
bytes in main memory be (E201F)16 and (E2020)16. What
seeded faults. Assuming that both real and seeded faults are
of same nature and have same distribution, the estimated are the tag and cache line address (in hex) for main memory
number of undetected real faults is _________. address (E201F)16?
16. Among simple LR (SLR), canonical LR, and look – ahead (a) E, 201 (b) F, 201
LR (LALR), which of the following pairs identify the method (c) E, E20 (d) 2, 01F
that is very easy to implement and the method that is the most
powerful, in that order é1 -1 2ù
(a) SLR, LALR 23. In the given matrix ê 0 1 0ú , one of the eigen values is
ê ú
(b) Canonical LR, LALR êë1 2 1 úû
(c) LSR, canonical LR
(d) LALR, canonical LR 1. The eigen vectors corresponding to the eigen value 1 are
17. Consider the following statements
(a) {a(4, 2, 1) |a ¹ 0, a Î R}
I. TCP connections are full duplex
(b) {a(–4, 2, 1) |a ¹ 0,a Î R}
II. TCP has no option for selective acknowledgment
(c) {a( 2 , 0, 1) |a ¹ 0, a Î R}
III. TCP connections are message streams
(d) {a(– 2 , 0, 1) |a ¹ 0, a Î R}
2015 -32 SOLVED PAPER - 2015
24. Consider the following C program segment. 30. Two processes X and Y need to access a critical section.
#include <stdio.h> Consider the following synchronization construct used by
int main( ) both the processes
{ Process X
char sl[7] = “1234”, *p; /* other code for process X */
p = sl + 2; while (true)
*p = ‘0’; {
printf (“%s”, s1); varP = true;
} while (varQ == true)
What will be printed by the program? {
(a) 12 (b) 120400 /* critical section */
(c) 1204 (d) 1034 varP = false;
25. The result evaluating the postfix expression }
10, 5, +, 60, 6, /, *, 8, – is }
(a) 284 (b) 213 /* other code for process X */
(c) 142 (d) 71 Process Y
26. Consider the following relation /* other code for process Y */
Cinema (theater, address, capacity) while (true)
Which of the following options will be needed at the end of {
the SQL query varQ = true;
SELECT P1. address while (varP == true)
FROM Cinema P1 {
Such that it always finds the addresses of theaters with /* critical section */
maximum capacity? varQ = false;
(a) WHERE P1. capacity >= All (select P2. capacity from }
Cinema P2)
}
(b) WHERE P1. capacity >= Any (select P2. capacity from
/* other code for process Y */
Cinema P2)
Here, varP and varQ are shared variables and both are
(c) WHERE P1. capacity > All (select max(P2. capacity)
initialized to false. Which one of the following statements is
form Cinema P2)
true?
(d) WHERE P1. capacity > Any (select max (P2. capacity)
(a) The proposed solution prevents deadlock but fails to
from Cinema P2)
guarantee mutual exclusion
27. Given a hash table T with 25 slots that stores 2000 elements,
(b) The proposed solution guarantees mutual exclusion but
the load factor a for T is ______.
fails to prevent deadlock
28. Consider the relation X(P, Q, R, S, T, U) with the following
(c) The proposed solution guarantees mutual exclusion and
set of functional dependencies
prevents deadlock
F={
(d) The proposed solution fails to prevent deadlock and
{P, R} ® {S, T},
fails to guarantee mutual exclusion
{P, S, U} ® {Q, R}
31. Consider a CSMA/CD network that transmits data at a rate
}
of 100 Mbps (108 bits per second) over a 1 km (kilometer)
Which of the following is the trivial functional dependency
cable with no repeaters. If the minimum frame size required
in F+, where F+ is closure of F?
for this network is 1250 bytes, what is the signal speed
(a) {P, R}®{S, T}
(km/sec) in the cable?
(b) {P, R}®{R, T}
(a) 8000 (b) 10000
(c) {P, S}® {S}
(d) {P, S, U}® {Q} (c) 16000 (d) 20000
29. Consider a binary tree T that has 200 leaf nodes. Then, the 32. Suppose U is the power set of the set S = {1, 2, 3, 4, 5, 6}.
number of nodes in T that have exactly two children For any T Î U, let |T| denote the number of elements in T and
are _______. T1 denote the complement of T. For any T, R Î U, let T\ R
SOLVED PAPER - 2015 2015-33

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

GENERAL APTITUDE QUESTIONS 2


12. (a) lim (1 + x 2 )e - x = lim 1 + x is ¥ form
x ®¥ x ®¥ e x ¥
1. (c) John-Abraham starrer Madras Café talks about the
movie not the person, so Mr. is ruled out. 2x
‘Find no takers’ is not the correct phrase. At this Friday = lim x (using L-Hospitals rule)
x ®¥ e
is incorrect. So, option c is correct.
2
2. (b) R + 3 = U, O + 3 = R, A + 3 = D, D + 3 = G; \ xlim (1 + x 2 )e- x = lim = 0 and xlim (1 + x 2 )e x = ¥
®¥ x®¥ ex ®¥
S + 3 = V, W + 3 = Z, A + 3 = D, N + 3 = Q
13. 15 4-digit numbers with first digit ‘1’
3. (c) f(x) = 2x + 33
1111, 1112, 1113, 1122, 1123, 1133, 1222, 1223, 1233, 1333
4. (b) Community of people: Doctor i.e., 10
5. (b) extraneous -irrelevant or unrelated to the subject being 4 digit numbers with first digit 2 : 2222, 2223, 2233, 2333
dealt with. i.e, 4
6. (b) 4 digit numbers with first digit 3: 3333 i.e, 1
14. (b)
7. (a)
15. 28 75% of faults are detected because 75 artificially seeded
100 - 70 faults are detected out of 100.
8. 2006 Increase in exports in 2006 = = 42.8% No. of detected real faults = 159 – 75 = 84
70
84 ´ (100)
Hence, no. of real faults = = 112
120 - 90 75
Increase in imports in 2006 = = 33.3%
90 \ undetected real faults = 112 – 84 = 28
which is more than any other year 16. (c) In SLR method, we work with LR(0) items where as in
CLR(1) we work with LR(1) items.
9. (b)
LR(1) item is comprised of two parts-the LR(0) item and
10. (b) Since U does not want any portfolio, (c) and (d) are a look ahead associated with the item. If we work with
ruled out. R wants Home, or Finance or no portfolio, (a) LR(1) items instead of using LR(0) items, then every
is not valid. Hence option (b) is correct. state of the parser corresponds to a set of LR(1) items.
When the parser looks ahead in the input buffer to
TECHNICAL SECTION decide whether the reduction is to be done or not the
information about the terminals is available in the state
of the parser itself which is not in case of SLR parser
l1. 3 89
state. Hence, CLR(1) parser is more powerful than SLR.
17. (a) I: TCP allows full – duplex communication. This is TRUE
statement.
TCP is a full-duplex protocol; it allows both parties to
19 send and receive data within the context of the single
50
TCP connection.
II: TCP has no option for selective acknowledgments.
17 12 15 2 This is FALSE statement.
TCP may experience poor performance when multiple
packets are lost from one window of data. With the
limited information available from cumulative
5 7 11 6 9 100
acknowledgments, a TCP sender can only learn about
a single lost packet per round trip time. An aggressive
1st swap is : 100 and 15
sender could choose to retransmit packets early, but
2nd swap is : 100 and 50 such retransmitted segments may have already been
3rd swap is : 100 and 89 successfully received. A Selective Acknowledgment
SOLVED PAPER - 2015 2015-39

(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

Þ (r – q)2 – (p – q) (p – r) = 0 According to question, switch forwards after 35


Þ p2 + q2 + r2 – pq – qr – pr = 0 microseconds.
Þ (p – q)2 + (q – r)2 + (r – p)2 = 0 So, after 70 + 35 = 105 microseconds, the switch
Þ p – q = 0; q – r = 0, r – p = 0 forwards the packet and at 105 + 70 = 175 microseconds
Þ p = q = r. the receiver receives the last bit of data.
39. (c) L2 £ PL4 43. (d)
L1 £ PL2 44. 0 C i 0 1 1
If L4 Î P then L2 Î P hence L1 Î P, hence, option (c)
is correct. 20 something
30. (b) T2 is reading the value written by T1 and getting
{z = 1
committed before T1 commits. So it is non-recoverable
schedule. for i = 0 + 0.3 k=0
41. (a) Program-X do z=1

z ¬ z2 mod z=1 z=4 z=0 z=0


if c[i] = 1 c [0] = 1 c [1] = 0 c [1] = 1 c [1] = 1
z ¬ 2 × z mod 8 z = 2 z=0 z=0
end
return 2
}
Complexity = 9 – 7 + 2 = 4
45. (c) Process AT BT ü
A 0 3 ïï
ï
B 1 6 ý Given Snapshot
C 4 4 ï
ï
D 6 2 ïþ

(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)

In function main x will be updated as follows


x = x + f1() + f 2() + f 3() + f 2()x
¯ ¯ ¯ ¯ ¯
1 26 51 100 52 g(5)
g(3)
Note: static variable in f2 ( ) will be initialized only once
& it retains value in between function calls. g(2) g(2) g(0)
g(4)
54. 3
yz g(1) g(–1) g(1) g(–1)
g(3) g(1)
wx 00 01 11 10 g(0) g(–2) g(0) g(–2)
g(2) g(0)
g(0) g(–2)
00 *1 0 0 1
g(1) g(–1)

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

Quick Revision Material


Articles - Kinds, Usage & Common Errors in their uses 8. With exclamatory expressions
An article is a word that is added to a noun to indicate – the type What a wonderful car!, what a good boy he is!
of reference being made by the noun. It’s a kind of adjective
9. With a person’s name who may be unknown to the person
which gives some information about a noun. addressed.
The word ‘a’ (becomes ‘an’ when the word that follows begins A peter wants to speak to you on the ‘phone’.
with a vowels - a, e, i, o, u) is called the ‘indefinite article’ because
the noun it combines with is indefinite or general. The word ‘the’
We use ‘An’:
is called the ‘definite article’ as it indicates some specific thing 1. When, the noun you are referring to begins with a vowel
(a, e, i, o, u)
I went by a car.
an orange, an egg, an idea, an umbrella, an Italian.
I went by the car.
2. When the word begins with a silent letter ‘h’.
The above two sentences differ since in the first sentence I went
by just any car while the second sentence refers to a particular an hour, an honest man, an honour, an heir (= a person
car and not just any car. who inherits money etc., when someone dies)
3. With abbreviations said as individual letters that begins with
We use ‘A’:
A, E, F, H, I, L, M, N, O, R, S or X:
1. When a word begins with consonant sound
an MLA, an FBI agent, an MP, an x-ray, an MA. However,
a book, a cat, a chair the abbreviations said as words are exceptions.
2. When a word begins with a vowel but has a consonant We use, ‘The’:
sound
1. When we say that someone or something is ‘unique’ – that
a university, a one parent family, a Europian there is only one or only one of its kind – (we also use zero
3. With words that have the sense of one article, i.e., no article, but not a/an):
The culprit could not speak a word before the judge. Cricket has become the international sports.
4. With abbreviations said as words. 2. When we refer to a person’s job title, or their particular
a NATO general a FIFA official position.
5. We use ‘a’ not ‘one’ when we mean ‘any one of a particular Bob has been appointed the director of the company.
type of thing. Sometimes ‘the’ is omitted which is called ‘zero article’.
I really need a cup of tea. (not ... one cup of tea) 3. Before a superlative adjective (the largest, the cheapest, the
most beautiful, etc.) when the superlative adjective is followed
6. With number and quantity expressions such as:
by a noun or defining phrase:
two times a year, a quarter of a litre, a day or so.
He is the best player in the team at the moment.
7. Rather than ‘one’ in the pattern a .... of ..... with possessives,
4. When we know that there is only one of a particular thing.
as in
the earth, the sun, the world, the international market,
He’s a friend of mine.
the film industry, the south pole, the nuclear family.
S1-2 Grammar

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. (c) Since “European” starts with constant sound, it 6. (a)


should be “a European”. 7. (b)
3. (d) lost consciousness. 8. (c) had known, could have
4. (c) Contemplate is a transitive verb and hence is followed
by a gerund. Hence the correct usage of contemplate
is verb + ing form.
Vocabulary S1-7

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.

5. (a) Inexplicable means not explicable; that cannot be 11. (a)


explained, understood, or accounted for. So the best 12. (c) Mediocre means Averge.
synonyms here is incomprehensible.
13. (a) eradicate - destroy utterly
6. (b) Tone of the sentence clearly indicates a word that is
distrot - misrepresent
similar to understated is needed for the blank.
Alternatively, word should be antonym of strong (fail saturate - soak completely
to make strong impression). Therefore, best choice is
utilize - use
restrained which means controlled/reserved/timid.
14. (c)
7. (b) Amalgamate means combine or unite to form one
organization or structure. So best option here is split. 15. (c) Coherent means logically connected while rambling
Separate on the other hand, although a close means aimlessly wandering.
synonyms, it is too general to be the best antonym in
the given question while Merge is the synonym; Collect
is not related.
Critical Reasoning S1-13

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)

4. (d) 10. (d)


PART-B : NUMERICAL ABILITY
Number System S1-19

1 Number System
Chapter

Quick Revision Material

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

ARITHMETIC PROGRESSION (A.P.) Note:


The sequence < x1, x2, x3, ...., xn, .... > is called an Arithmetic A.M. of any n positive numbers a1, a2, .........., an is
progression (A.P.), if x2 – x1 = x3 – x2 = x4 – x3 = ...... = xn – xn–1 a1 a2 a3 .....an
A=
= ....... In general (xn – xn–1) = constant, n N. This constant n
difference is called Common Difference . If 'a' is the first term and GEOMETRIC PROGRESSION (G.P.)
'd' is the common difference, then the A.P. can be written as If 'a' is the first term and 'r' is the common ratio, then a G.P. can be
a + (a + d) + (a + 2d) + (a + 3d) + ...... + {a + (n – 1)d} + ..... written as, a, ar, ar2, ar3, ........ .
Note that a, b, c are in AP 2b = a + c Note that a, b, c are in G. P. b2 = ac
General Term of an AP: General term of a G. P. :
General term (i.e. nth term) of an AP is given by General term (nth term) of a G.P. is given by Tn = arn–1
Tn = a + (n – 1) d Sum of n terms of a G. P. :
NOTE : The sum of first n terms of a G.P. is given by
(i) If a sequence has n terms, then its nth term is also denoted
a (1 r n ) a r Tn
by , which indicate last term Sn = , when r < 1
(ii) Common difference can be zero, + ve or – ve. 1 r 1 r
(iii) If there are n terms in an A.P, then mth term from end a(r n 1) rTn a
= (n – m + 1)th term from beginning. or Sn = , when r > 1
r 1 r 1
Sum of first n terms of an AP: and Sn = na, when r = 1
The sum of first n terms of an A.P. is given by Sum of an infinite G. P. :
The sum of an infinite G.P. with first term a and common ratio r
n n
Sn = [2a + (n – 1) d] or Sn = [a + Tn] such that | r | < 1,
2 2
a
n S =
or Sn (a l ) 1 r
2
Some standard results: Geometric mean (g. m.)
(i) Sum of first n natural numbers, If G be the G.M. between two given quantities a and b then a, G, b,
n are in G.P.
r = n (n 1) G b
r 1 2 i.e. G2 = ab G = ab
a G
n
HARMONIC PROGRESSION (H.P)
(ii) Sum of first n odd natural numbers, (2r 1) = n2
If reciprocal of each term of a progression are in A.P., then the
r 1
(iii) Sum of first n even natural numbers, progression is called Harmonic progression.
The standard form of a H.P. is
n
1 1 1
2r = n (n + 1) , , , ......
r 1 a a d a 2d
General Term of a H.P.
(iv) Sum of squares of first n natural numbers, General term or nth term of a H.P. is given by
n 1
r2 n ( n 1)(2n 1) Tn =
a (n 1)d
=
r 1 6 HARMONIC MEAN
(v) Sum of cubes of first n natural numbers, If H.M. between two given quantities a and b be H, then a, H, b,
n are in H.P. then
2
r 3 = n (n 1) 2ab
r 1 2 H=
a b
Arithmetic Mean (A.M)
The A.M. between the two given quantities a and b is A if a, A, b
are in A.P.
a b
i.e. A – a = b – A A=
2
Number System S1-21

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

1. (c) By observation of summation, it can be seen that 3. (c)


numbers are not in decimal. Let they have base n. Then 4. (b)
converting all number in decimal
5. (d)
(137)n = [1 × n2 + 3n + 7 nº]10
6. 96
(276)n = [2n2 + 7n + 6nº]10
(435)n = [4n2 + 3n + 5nº]10 2
1
z 98
(731)n = [7n2 + 3n + 1nº]10 z
(672)n = [6n2 + 7n + 2nº]10
2
(137)n + (276)n = (435)n 1 2 1 1
z = z 2z
n2 + 3n + 7 + 2n2 + 7n + 6n = 4n2 + 3n + 5 z z2 z

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

P = bk, Q = b2k, R = b3k


Now, Q2 = b4k = b3k bk = PR
Algebra S1-23

2 Algebra
Chapter

Quick Revision Materials

ALGEBRAIC EXPRESSIONS 6. (a + b + c + d)2 = a2 + b2 + c2 + d2 + 2a (b + c + d)


Some symmetric functions of roots are : + 2b (c + d) + 2cd
(i) 2 2
( )2 2 7. (a + b) (a – b) = a2 – b2
8. (x + a) (x + b) = x2 + (a + b) x + ab
(ii) 2
( ) 4
9. (x + a) (x + b) (x + c)
2 2 = x3 + (a + b + c)x2 + (ab + bc + ca) x + abc
(iii) ( )( ) ( ) ( )2 4
10. (a + b)3 = a3 + 3ab (a + b) + b3
(iv) 3 3 3
( ) 3 ( ) 11. (a – b)3 = a3 – 3ab (a – b) – b3
3 3 12. a3 + b3 = (a + b)3 – 3ab (a + b)= (a + b) (a2 – ab + b2)
(v) ( – )3 3 ( )&
13. a3 – b3 = (a – b)3 + 3ab (a – b) = (a – b) (a2 + ab + b2)
( )2 4 14. a3 + b3 + c3 – 3abc = (a + b + c) (a2 + b2 + c2 – ab – ac – bc)
If a + b + c = 0 then a3 + b3 + c3 = 3abc
4 4
(vi) ( 2 2 2
) 2 2 2
AVERAGE
2 2 2
( ) 2 2( ) Sum of given quantities
• Average or Mean =
Number of quantities

(vii) 4 4 2 2 2 2 Variance and standard deviation


( )( )
• The variance of a variate X is the arithmetic mean of the
( )2 2 ( )2 4 squares of all deviations of X from the arithmetic mean of
the observations and is denoted by Var (X) or 2
Formation of Quadratic Equation with given Roots : • The positive square root of the variance of a variate X is
An equation whose roots are and can be written as known as standard deviation.
2
(x – ) (x – ) = 0 or x – ( )x+ = 0 or x2 – (sum of the
i.e., V(x)
roots) x + product of the roots = 0.
• To calculate the sum of quantities, they should be in the
ALGEBRAIC FORMULAE & THEIR APPLICATION
same unit.
An equation is a statement that two algebraic expressions are • Average of a group consisting two different groups when
equal. If an equation is satisfied by any value of the variable, their averages are known :
then equation is said to be an identity.
Let Group A contains m quantities and their average is a
1. (a + b)2 = a2 + 2ab + b2 = (a – b)2 + 4ab and Group B contains n quantities and their average is b,
2. (a – b)2 = a2 – 2ab + b2 = (a + b)2 – 4ab then average of group C containing a + b quantities
3. (a + b)2 + (a – b)2 = 2(a2 + b2) ma mb
= .
4. (a + b)2 – (a – b)2 = 4ab m n
5. (a + b + c)2 = a2 + b2 + c2 + 2(ab + bc + ca)
S1-24 Algebra

• 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

H x F Hence p is maximum at 50 – 10q = 0 or q = 5 Alternately


check with options.
1. (d) 5 10 7 5 + 10 + 7 + x = 25 x=3 7. (d) ax2 + b|x| + c = 0
For x > 0
2. (b) (i) H+ G> I + S ax2 + bx + c = 0
I – H< G – S ...(i) This eqn has two real roots
(ii) G – S = 1 For x < 0
From equations (i) and (ii), we get I – H < 1 H> 1 ax2 – bx + c = 0
Hence order is SGHI because G is not oldest and S is This eqn has two real roots
not youngest. Hence, total real roots are 4.
3. (a) Checking with all options in formula (4q + 100/q) i.e.
(V + F). 8. (c) Let 12 12 ... = x
Option (a) gives minimum cost.
4. (b) y = 2x – 0.1x2 12 12 12... x

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

3 Percentage & Its


Chapter Applications
Quick Revision Material

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

A candidate scoring x % in an examination fails by ‘a’ marks, ab


the resultant profit or loss per cent is given by a b %,
100
while another candidate who scores y% marks gets ‘b’ marks
S1-28 Percentage & Its Applications

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

1. Round-trip tickets to a tourist destination are eligible for a


discount of 10% on the total fare. In addition, groups of 4 or
more get a discount of 5% on the total fare. If the one way

Ratio of male to female students


3.5
single person fare is Rs 100, a group of 5 tourists purchasing 3
round-trip tickets will be charged Rs ________ 2.5
[GATE 2014, Set-1, 2 Marks] 2
2. In a survey, 300 respondents were asked whether they own 1.5
a vehicle or not. If yes, they were further asked to mention 1
whether they own a car or scooter or both. Their responses 0.5
are tabulated below. What percent of respondents do not 0
own a scooter? 2008 2009 2010 2011 2012

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%

[GATE 2014, Set-2, 2 Marks]


S1-30 Percentage & Its Applications

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

4 Time and Work &


Chapter Speed and Distance
Quick Revision Material

TIME AND WORK Z(a 1)


days. and time taken by B = Z(a + 1) days.
• If A can do a piece of work in X days, then A’s one day’s a
1 • If A working alone takes ‘x’ days more than A and B together,
work = th part of whole work.
X and B working along takes ‘y’ days more than A and B
together then the number of days taken by A and B working
1
• If A’s one day’s work = th part of whole work, then A can
X together is given by [ xy] days.
finish the work in X days. • If n men or m women can do a piece of work in X days, then
• If A can do a piece of work in X days and B can do it in Y N men and M women together can finish the work in
days then A and B working together will do the same work
nmX
days.
XY nM mN
in days.
X Y
• If ‘M1’ persons can do ‘W1’ works in ‘D1’ days and ‘M2’
• If A, B and C can do a work in X, Y and Z days respectively persons can do ‘W2’ works in ‘D2’ days then
then all of them working together can finish the work in M1D1W2 = M2D2W1
XYZ If T1 and T2 are the working hours for the two groups then
days.
XY YZ XZ M1D1W2T1 = M2D2W1T2
• If A and B together can do a piece of work in X days and A Similarly,
alone can do it in Y days, then B alone can do the work in M1D1W2T1E1 = M2D2W1T2E2, where E1 and E2 are the ef-
XY ficiencies of the two groups.
days.
Y–X • If A is n times as efficient as B, i.e. A has n times as much
• A and B can do a work in ‘X’ and ‘Y’ days respectively.
1
They started the work together but A left ‘a’ days before capacity to do work as B, A will take of the time taken by
n
completion of the work. Then, time taken to finish the work
B to do the same amount of work.
is

Y(X a) PIPE AND CISTERNS


X Y The same principle of Time and Work is employed to solve the
• If ‘A’ is ‘a’ times efficient than B and A can finish a work in problems on Pipes and Cisterns. The only difference is that in
X days, then working together, they can finish the work in this case, the work done is in terms of filling or emptying a cistern
(tank) and the time taken is the time taken by a pipe or a leak
aX
days. (crack) to fill or empty a cistern respectively.
a 1
Inlet : A pipe connected with a tank (or a cistern or a reservoir) is
• If A is ‘a’ times efficient than B and working together they
called an inlet, if it fills it.
finish a work in Z days then, time taken by A =
Outlet : A pipe connected with a tank is called an outlet, if it
empties it.
S1-32 Time and Work & Speed and Distance

• If a pipe can fill a tank in x hours, then the part filled in 1 5


1 km/h m/sec,
1 18
hour
x
• If a pipe can empty a tank in y hours, then the part of the 18
1 m/sec km/h
5
1
full tank emptied in 1 hour .
y 22
1 miles/hr ft/sec
• If a pipe can fill a tank in x hours and another pipe can 15
empty the full tank in y hours, then the net part filled in 1
Total Distance
(ii) Average speed =
1 1 Total time
hour, when both the pipes are opened – • If a certain distance (d), say from A to B, is covered at ‘a’
x y .
km/hr and the same distance is covered again say from B to
Time taken to fill the tank, when both the pipes are A in ‘b’ km/hr, then the average speed during the whole
journey is given by :
xy
opened .
y–x 2ab km
• If a pipe can fill a tank in x hours and another can fill the Average speed =
a b hr
xy • If a body travels a distance ‘d’ from A to B with speed ‘a’ in
same tank in y hours, then time taken to fill the tank ,
y x
time t1 and travels back from B to A i.e., the same distance
when both the pipes are opened
m
• If a pipe fills a tank in x hours and another fills the same tank with of the usual speed ‘a’, then the change in time
n
is y hours, but a third one empties the full tank in z hours,
and all of them are opened together, then net part filled in 1 taken to cover the same distance is given by :

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 ÷

Relative Speed : When two bodies are moving in same direction


TIME, SPEED AND DISTANCE with speeds S1 and S2 respectively, their relative speed is the
The rate at which any moving body covers a particular difference of their speeds.
distance is called its speed. i.e. Relative Speed = S1 – S2
Distance = Speed × time When two bodies are moving in opposite direction with speeds
Unit : SI unit of speed is metre per second (mps). It is also S1 and S2 respectively, their relative speed is the sum of their
measured in kilometers per hour (kmp) or miles per hour (mph). speeds.
Conversion of units : i.e. Relative Speed = S1 + S2
(i) 1 hour = 60 minutes = 60 × 60 seconds. • If two persons (or vehicles or trains) start at the same time
1 km = 1000 m in opposite directions from two points A and B, and after
1 km = 0.6214 mile crossing each other they take x and y hours respectively to
1 mile = 1.609 km, i.e., complete the journey, then
8 km = 5 miles
1 yard = 3 feet Speed of first y
1 foot = 12 inches Speed of second x
Time and Work & Speed and Distance S1-33

• 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

• If a person with two different speeds U & V cover the same x y


the same direction) = hrs.
distance, then required distance u v

U V • Suppose two trains or two bodies are moving in opposite


Difference between arrival time
U~V directions at u km/hr and v km/hr, then their relative speed
= (u + v) km/hr.
U V
Also, required distance otal time taken If their lengths be x km & y km, then :
U V

• For finding the angle between the hands of a clock is x y


time taken to cross each other = hrs.
u v
11(M)
Angle = 30H
2 • If a man is running at a speed of u m/sec in the same direction
where H = Hours and M = Minutes in which a train of length L meters is running at a speed

TRAINS v m/sec, then (v – u) m/sec is called the speed of the train


relative to man. Then the time taken by the train to cross the
A train is said to have crossed an object (stationary or moving)
only when the last coach of the train crosses the said object L
man = seconds
completely. It implies that the total length of the train has crossed v u
the total length of the object. • If a man is running at a speed of u m/sec in a direction
• Time taken by a train to cross a pole/a standing man opposite to that in which a train of length L meters is running
Length of train with a speed v m/sec, then (u + v) is called the speed of the
.
Speed of train train relative to man.
Then the time taken by the train to cross the man
• Time taken by a train to cross platform/bridge etc. (i.e. a
stationary object with some length) L
= seconds.
v u
length of train + length of platform/bridge etc.
.
speed of train BOAT AND STREAM
• When two trains with lengths L1 and L2 and with speeds S1 Stream : It implies that the water in the river is moving or flowing.
and S2 respectively, then Upstream : Going against the flow of the river.
(a) When they are moving in the same direction, time taken Downstream : Going with the flow of the river.
by the faster train to cross the slower train Still water : It implies that the speed of water is zero (generally, in
a lake).
L1 L2
.
difference of their speeds
Flow of water
(b) When they are moving in the opposite direction, time Boat
taken by the trains to cross each other Up stream Down stream
Boat
L1 L 2
.
sum of their speeds
S1-34 Time and Work & Speed and Distance

Let the speed of a boat (or man) in still water be


Z(X2 – Y 2 )
X m/sec and the speed of the stream (or current) be Y m/
2X
sec. Then,
• Speed of boat with the stream (or downstream or D/S) • A man rows a certain distance downstream in X hours and
= (X + Y) m/sec. returns the same distance in Y hours. If the stream flows at
• Speed of boat against the stream (or upstream or U/S) the rate of Z km/h, then the speed of the man in still water is
= (X – Y) m/sec. given by
• Speed of boat in still water is Z(X Y)
km / hr
Y–X
(X Y) (X – Y) Upstream Downstream
X
2 2 • And if speed of man in still water is Z km/h then the
• Speed of the stream or current is speed of stream is given by

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

1. (c) Let each truck carry 100 units. 3. (c)


2800 = 4n + e 4. (b) First taken sum
where, n = normal Arrange the multiple of 10
3000 = 10n + e (10 + 190) + (20 + 180) + ... + (90 + 110) + 100
where, e = excess/pending = (9 × 200) + 100
100 = 1800 + 100
n
3 = 1900

8000 1900
e
3 Average = = 100
19

5 100 8000 5. (a) At 6 a.m. the clock likes.


5 days 500 x
3 3
12
8500
500 x
3
180°
17 9 3
x
3
x>5
6
Minimum possible = 6
2. (d) 5 skilled workers build wall in 20 days i.e., it is 180° apart
1 skilled worker build wall in 20 × 5 days
To make 60° angle, it has to move (180° – 60°) = 120°
Hence in 1 day, part of work done by skilled
360
1 Angle moved in one minute = = 6°
work 60
100
Similarly in 1 day part of work done by semi-skilled 120°
Number of minutes move 120° = = 20 minutes
workers 6

1 The nearest answer is 6 : 22 am


25 8
12
and in 1 day part of work done by un-skilled worker

1 120°
30 10 9 3

So part of work done in 1 day by 2 skilled, 6 semi- 60°


4
skilled and 5 unskilled 5
6
2 6 5 1
100 200 300 15 6. (b)
So work done by given workers in days = 15
Ratio & Proportion S1-37

5
Chapter
Ratio & Proportion
Quick Revision Material

RATIO 1. More men, less time


2. Less men, more hours
The ratio of two terms ‘x’ and ‘y’ is denoted by x : y.
3. More speed, less taken time to be covered distance
Compound ratio :

The compound ratio of a : b and c : d is


a c
, i.e., ac : bd.
PARTNERSHIP
b d A partnership is an association of two or more persons who invest
• In any 2-dimensional figures, if the corresponding sides are their money in order to carry on a certain business.
in the ratio x : y, then their areas are in the ratio A partner who manages the business is called the working partner
x2 : y2. and the one who simply invests the money is called the sleeping
• In any two 3-dimensional figures, if the corresponding sides partner.
are in the ratio x : y, then their volumes are in the ratio x3 : y3. • If the period of investment is the same for each partner,
• If the sum of two numbers is A and their difference is a, then the profit or loss is divided in the ratio of their invest-
then the ratio of numbers is given by A + a : A – a. ments.
PROPORTION If A and B are partners in a business, then
When two ratios are equal, the four quantities composing them Investment of A Pr ofit of A Loss of A
or
are said to be in proportion. Investment of B Pr ofit of B Loss of B

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

= (21 × 2) + (15 × 3) + (23 × 2) = 133 m' 1.5


=
m 1
Total number of students = 21 + 17 + 6 = 44
Permutation and Combination & Probability S1-41

6 Permutation and
Chapter Combination & Probability
Quick Revision Material

4. Number of permutations of n different things taking all at a


PERMUTATION
time, in which m specified things never come together =
Each of the arrangements, which can be made by taking, some or
all of a number of things is called a PERMUTATION. n! m!(n m 1)!
For Example : Formation of numbers, word formation, sitting 5. The number of permutations of 'n' things taken all at a time,
arrangement in a row.
when 'p' are alike of one kind, 'q' are alike of second, 'r' alike
• The number of permutations of 'n' things taken 'r' at a time is
n! n!
denoted by nPr. It is defind as, nPr . of third, and so on = .
(n r)! p! q! r!
• nP = n!
n

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

Conditional Combinations PROBABILITY


1. Number of combinations of n distinct things taking r ( n )
No. of elementary events favourable to A
P (A)
at a time, when k (0 k r) particular objects always occur Total no. of equally likely elementary events

= 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 .

3. Number of selections of r things from n things when p A P(A B) B P(A B)


P = and P =
particular things are not together in any selection B P(B) A P(A)
= nCr – n – pCr – p
4. Number of selection of r consecutive things out of n things Multiplication theorem
in a row = n – r + 1 If A and B are two events, then
5. Number of selection of r consecutive things out of n things P( A B) = P (A) P (B/A), if P (A) > 0
along a circle
= P (B) P (A/B) if P (B) > 0
n, when r n
= From this theorem we get
1, when r n
P(A B) P(A B)
6. The number of Combinations of 'n' different things taking P(B / A)= and P(A / B)=
P(A) P(B)
some or all at a time

= 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

P (50 mm) have concluded that measures to control the mosquito


800
population have failed in this region.
Which one of the following statements, if true, does not
kilograms)

600
Toxicity

Q (40 mm) contradict this conclusion? [GATE 2014, Set-2, 2 Marks]


400
R (30 mm)
S (20 mm) (a) A high proportion of the affected population has
200
returned from neighbouring countries where dengue
0 is prevalent
0.2 0.4 0.6 0.8 1
Potency (b) More cases of dengue are now reported because of
(Probability that microbe will overcome human
an increase in the Municipal Office’s administrative
immunity system)
efficiency
(c) Many more cases of dengue are being diagnosed this
year since the introduction of a new and effective
A pharmaceutical company is contemplating the
diagnostic test
development of a vaccine against the most dangerous
(d) The number of people with malarial fever (also
microbe. Which microbe should the company target in its
contracted from mosquito bites) has increased this
first attempt?
year
(a) P (b) Q [GATE 2011, 2 Marks]
(c) R (d) S
S1-44 Permutation and Combination & Probability

1. (b) Case 1 : First digit = 3 3... 443 3


Rest 3 digits may by combination of 444 1
234 3! 333 1
223 3!/2! Total combinations = 26
224 3!/2! Required answer = 25 + 26 = 51
332 3!/2! 2. (d) By observation of the table, we can say S
334 3!/2!
442 3!/2! P Q R S
443 3!/2! Requirement 800 600 300 200
444 1 Potency 0.4 0.5 0.4 0.8
Total combinations = 25
Case 2 : First digit = 4 4... 3. (b) X Y
Rest 3 digits may be combination of Supply 60% 40%
234 6 Reliable 96% 72%
223 3 Overall 0.576 0.288
224 3 0.288
P(X) 0.334
332 3 0.576 0.288
334 3
4. (d)
442 3
SECTION 2 : ENGINEERING MATHEMATICS

1 Mathematical Logic
Chapter

Quick Revision Material

MATHEMATICAL LOGIC IF AND ONLY IF (P Q)


NOT
P Q P Q
AND
OR F F T
IF ...THEN or F T F
IF AND ONLY IF or T F F
OR ( ) T T T

P Q P Q Converse and Contrapositive


F F F For the proposition
F T T
(i) P Q, the Q P is called its converse.
(ii) Q P is called its contrapositive.
T F T
T T T Tautologies and Contradictions
‘A statement (or propositional function) which is true all possible
NOT ( ) truth values of its propositional variables is called a tautology.’
A statement which is always false all possible truth values of its
P P propositional variables is called a contradiction.
T F
Reasoning
F T
Logical reasoning is the process of drawing conclusion from
AND ( ) premises using rules of inference.

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

7. (P Q) [ P Q] e.g., (i) Dual of (p q) r is (p q) r


De-Morgan’s law (ii) Dual of (p q) 0 is (p q) 1.
8. (P Q) [ P Q] (2) Tautology implications : A statement A is said to
De-Morgan’s law tautologically imply a statement B if and only if A B is a
9. [P (Q R] [( P Q) (P R)] tautology which is read as “A implies B”.
distributivity of over The implications listed below have important applications
10. [P (Q R] [( P Q) (P R)] which can be proved by truth tables :
distributivity of over 1. p q p p p q
11. (P True) True 2. ~ p p q q p q
12. (P False) False 3. ~ (p q) p ~ (p q) ~ q
13. (P False) P 4. P (P q) q ~ p (p q) q
14. (P True) P 5. (p q) (q r) p r
15. (P P) True
Implications
16. (P P) False
The relationship between propositions that can be derived from
17. P ( P)
the definitions of connectives.
double negation
List of implication
18. (P Q) ( P Q)
1. P (P Q) addition
implication
2. (P Q) P simplification
19. (P Q) (P Q) (Q P)
3. [P (P Q)] Q modus ponens
equivalence
4. [(P Q) Q] P modus tollens
20. [(P Q) R] [P (Q R)]
5. [ P (P Q)] Q disjunctive syllogism
exportation
6. [(P Q) (Q R)] (P R) hypothetical syllogism
21. [(P Q) [P Q) P
7. (P Q) [(Q R) (P R)]
absurdity
8. (P Q) [(R S) [(P R) (Q S)]
22. [P Q ( Q P)
9. [(P Q) (Q R) [(P R)
contrapositive
(1) Two formulae A and A* are said to be duals of each other if Predicate Logic
either one can be obtained from the other by replacing by A predicate is a verb phrase template that describes a property of
and by . objects or relationship among objects represented by the
If the formula A contains special variables 1 or 0, then its variables.
dual A* is obtained by replacing 1 by 0 and 0 by 1.
Mathematical Logic S2-3

5. Let graph (x) be a predicate which denoted that x is a graph.


Conceptual MCQs Let graph (x) is connected. Which of the following first
order logic sentences does not represent the statement ‘Not
1. Which of the following is a valid first order formula? every graph is connected’? [2008, 1 Mark]
(Here and are first order formulae with x as their only
free variable) [2003, 2 Marks] (a) x (graph (x) connected (x))

(a) ( x) [ ] ( x) [ ] ( x) [ ] (b) x (graph (x) connected (x))

(b) ( x) [ ] [ x] [ ] (c) ( graph (x)) (connected (x))


(c) ( x) [ ] [ x] [ ] ( x) [ ] (d) x (graph (x)) connected (x))
(d) ( x) [ ] (( x) [ ] ( x) [ ]) 6. Let fsa and pda be two predicates such that fsa(x) means x
is a finite state automation and pda(y), means y is a push
2. Identify the correct translation into logical notation of the
down automation. Let equivalent be another predicate such
following assertion. Some boys in the class are taller than
that equivalent (a, b) means a and b are equivalents. Which
all the girls.
of the following first order logic statements represents the
Note Taller (x, y) is true, if x is taller than y. following: [2008, 1 Mark]
[2004, 1 Mark] (a) ( x fsa (x)) ( y pda(y) equivalent (x, y))
(a) ( x) (boy (x) ( y) (girl (y) taller (x, y))) (b) ~ y ( x fsa (x) ( y pda(y) equivalent (x, y))
(b) ( x) (boy (x) ( y) (girl (y) taller (x, y))) (c) x y (fsa(x) pda (y) equivalent (x, y))
(c) ( x) (boy (x) ( y) (girl (y) taller (x, y))) (d) x y (fsa(x) pda (x) equivalent (x, y))
(d) ( x) (boy (x) ( y) (girl (y) taller (x, y))) 7. Which one of the following is the most appropriate logical
3. What is the first order predicate calculus statement formula to represent the statement [2009, 1 Mark]
equivalent to the following? [2005, 1 Mark]
‘Gold and silver ornaments are precious’?
Every teacher is liked by some student.
The following notations are used
(a) (x) [teacher (x) (y) {student (y) likes (y, x)}]
G(x) : x is a gold ornament
(b) (x) [teacher (x) (y) {student (y) likes (y, x)}]
S(x) : x is a silver ornament
(c) (y), (x) [teacher (x) {student (y) likes (y, x)}]
P(x) : x is precious
(d) (x) [teacher (x) (y) {student (y) likes (y, x)}]
(a) x (P(x)) (G(x) S(x))
4. Which one of the first order predicate calculus statements
given below, correctly expresses the following english (b) x (G(x)) S(x) P(x))
statement? [2007, 1 Mark] (c) x ((G(x) S(x)) P(x))
Tiger or lions attack, if they are hungry or threatened. (d) x (G(x) S(x)) P(x)
(a) × [(tiger (×) lion (×)) {(hungry (×) threatened 8. The CORRECT formula for the sentence, “not all rainy days
(×)) attacks (×)}] are cold” is [2014, Set-3, 2 Marks]
(b) × [(tiger (×) lion (×)) {(hungry (×) threatened (a) d (Rainy(d) ~ Cold(d))
(×)) attacks (×)}]
(b) d (~Rainy(d) Cold(d))
(c) × [(tiger (×) lion (×)) {(attacks (×) hungry (×))
threatened (×))}] (c) d (~Rainy(d) Cold(d))

(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

P2 : ((A B) C) ((A C) (B C)) (c) I1 is not correct but I2 is a correct inference


(d) Both I1 and I2 are not correct inferences
Which one of the following is true?
Mathematical Logic S2-5

18. Consider the statement 19. Consider the following statements:


“Not all that glitters is gold” P: Good mobile phones are not cheap
Predicate glitters (x) is true if x glitters and predicate gold Q: Cheap mobile phones are not good
(x) is true if x is gold. Which one of the following logical
L: P implies Q
formulae represents the above statement?
M: Q implies P
[2014, Set-1, 1 Mark]
N: P is equivalent to Q
(a) x : glitters( x ) gold ( x )
Which one of the following about L, M, and N is
(b) x : gold ( x ) glitters( x ) CORRECT? [2014, Set-3, 1 Mark]
(a) Only L is TRUE.
(c) x : gold ( x ) glitters( x )
(b) Only M is TRUE.
(d) x : glitters( x ) gold ( x ) (c) Only N is TRUE.
(d) L, M and N are TRUE.
S2-6 Mathematical Logic

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)}.

Option (A) (B) (C) (D) 2nd Final truth value


p q r ~r p « q ~(p« q) p® q st Common
1 term Ist Ist Ist
term Option (A) (B) (C) (D)
1 1 0 1 1 0 1 0 0 0 0 1 1 1 1 0
1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0
0 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0

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.

"y (y does not divide x)) "x (x is not a composite


PROBLEM BASED MCQs number)
10. (c) p Þ q º ~ p Ú q By same reasoning used above, a now becomes
(B(x, x) ® [B(x, y), C(y) ® A(x)] "x (x is a composite number Û false) "x (x is not
º Ø B(x, x) Ú [B(x, y) Ù C(y) ® A(x)] composite) is also true.
11. (d) Qyy º "y" divides y is always true. Since, if no number divides x, x cannot be a
\ Qxy Û Ø Qyy is same as Qxy Û False. composite number, is true.
Now a becomes \ Both l1 and l2 satisfy a.
("x) [P(x) Û ("y) (Qxy Û False)] 12. (b) X : (P Ú Q) ® R
Þ ("x) [Ø P(x)] Y : (P ® R) Ú (Q ® R)
Now consider l1 : P(x) º "x is a prime number". X : P + Q ® R º (P + Q)' + R º P'Q' + R
a becomes "x (x is a prime number if and only if "y
Y : (P' + R) + (Q' + R) º P' + Q' + R
(y does not divide x) is always false (since x divides
x always). a now becomes Clearly, X¹Y
"x (x is a prime number Û false) Û "x (x is not a Consider X ®Y
prime). º (P'Q' + R ) ® (P' + Q' + R)
which is true.
º (P'Q' + R)' + P' + Q' + R
Now consider l2 : P(x) º "x is a composite number".
Now a becomes º (P'Q')' R' + P' + Q' + R
"x (x is a composite number if and only if º (P + Q) R' + P' + Q' + R (Q by distribution law)
Mathematical Logic S2-7

º PR' + QR' + P' + Q' + R º Q' P' + P(Q + Q')


º (PR' + R) + (QR' + Q') + P' º Q' P' + P (Q by complement law)
º (P + R)(R' + R) + (Q + Q') × (R' + Q') + P' º (Q' + P) × (P' + P) (Q by distribution law)
º P + P' + R + R' + Q’ (by complente law) º Q' + P
º 1 + 1 + Q' = 1 Choice (b) P Ú Ø Q = P Ú Q'
\ X ® Y tautology. = PQ' + P (Q')' + P' (Q')'
13. (d) P1 : ((A Ù B) ® C) º ((A ® C) Ù (B ® C)) º PQ' + PQ + P'Q
LHS (A Ù B ) ® C º AB ® C º P (Q' + Q) + P'Q
= (AB)' + C º P + P'Q (Q by complement law)
= A' + B' + C º (P + P') (P + Q) (Q by distribution law)
RHS (A ® C) Ù (B ® C) º (A' + C) (B' + C) = P+Q
= A' B' + C Choice (c) Ø P Ú Q = P' Ú Q
Þ RHS ¹ LHS º P'Q + P'Q' + (P')' Q'
\ P1 is not tautology. º P'Q + P'Q' + PQ'
P2 : ((A Ù B) ® C º ((A ® C) Ú (B ® C) º P' (Q + Q') + PQ'
LHS (A Ú B) ® C º A + B ® C = P' + PQ' (Q by complement law)
º (A + B)' + C = (P' + P) (P' + Q') º P' + Q' (Q by distribution law)
= A'B' + C Choice (d) Ø P Ø Q º P' Q'
RHS (A ® C) Ú (B ® C) º P'Q' + P' (Q')' + (P')' (Q')'
º (A' + C) + (B' + C) º P'Q' + P'Q + PQ
= A' + B' + C º P'(Q' + Q) + PQ
Þ LHS ¹ RHS º P' + PQ (Q by complement law)
Þ P2 is also not tautology. º (P' + P) (P' + Q) (Q by distribution law)
14. (b) (i) P Ù ~ Q º P + Q' = P' + Q
(ii) ~ (~ P Ù Q) (P' + Q)' º P + Q' We can clearly see only choice (b) P Ú Ø Q is equivalent
(iii) (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù ~ Q) to P + Q.
= (PQ) + (PQ' ) + (P'Q') 16. (c) The given statement or sentence is—
= P(Q + Q') + P'Q' 'Some real number are rational.' We can also write this
sentence as follows:
= P + P'Q'
'There exists real number that are rational' therefore we
= (P + P') (P + Q')
have to use $ (Existential) quantifier consider number
= P + Q' as random variable x. Then,
(iv) (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù Q) $x (real) (x)) Þ This, indicates 'There exists number
= (PQ) + (PQ' ) + (P'Q) that are real.'
= P(Q + Q') + P'Q $ x (rational (x)) Þ This indicates 'There exists number
= P + P'Q that are rational.'
= (P + P') (P + Q) Hence, $x (real (x) Ù rational (x) Þ
= P+Q This indicates 'There exists real number that are rational.
Clearly, (i), (ii), (iii) are equivalent. Correct choice is (b). 17. (b) I1 : If it rains, then then the cricket match will not be
15. (b) The given table can be converted into Boolean played.
function by adding minterms corresponding to true- The cricket match was played.
row. Inference : There was no rain.
Translates P Ú Q = PQ + PQ' + P'Q' Hence, I1 is correct.
Using this we can check the choices one by one to see Proof
which is equivalent to P + Q Suppose P : It rains
Choice (a) Ø Q Ú Ø P º Q' Ú P' Q : The cricket match will not be played.
º Q' P' + Q' (P')' + (Q')' (P')' It is given P ® Q
º Q' P' + Q' P + QP
S2-8 Mathematical Logic

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

INTRODUCTI ON number of elements in A B


Probability is the measure of degree of certainity or uncertainity = no of elements in A
of occurrence of an event. The set of all possible outcomes is
B
called sample space of that experiment and is denoted by S. i.e., P(B A) = P(A) . P
Probability of an event is denoted by P(E). A
[Multiplication theorem of conditional probability]
0 P(E) 1 Mean, Median, Mode
Addition law of probability x1 x2 ...... xn
mean x =
P(A) and P(B) are probabilities of two events A and B, then n
P(A B) = P(A) + P(B) – P(A B) Median : Median is the middle term in the collected data. In case
of even number of terms, take average of middle terms.
For mutually exclusive events P(A B) = 0.
N
Law of total probability C÷
If B1, B2,...... Bn are mutually exclusive events and an event A median = L + 2 h
f
occurs only if Bi occurs, then :
Probability of occurrence of A is given by L-lower limit of median class
N-total frequency = fi
n
A h -width of median class.
P(A) = P P(Bi )
Bi C-cumulative frequency upto class preceding median class
i 1
f -cumulative frequency of median class
P(A/Bi)-Probability of occurrence of A when Bi has already Mode : It is the value that occur most frequently or it is the value
happened. with maximum frequency.
Baye’s Theorem fi fi 1
If B1, B2, B3,...... Bn are mutually exclusive and exhaustive random mode = ×h
( fi f i 1 ) ( fi fi 1 )
events whose individual probabilities are greater than zero, and
L-lower limit of class certaining mode
A be an event within these events. (P(A) > 0), then,
fi-maximum frequency
A fi–1-frequency preceding fi
P . P(E i )
B Bi fi+1-frequency just after fi
P i = h-size of model class
A n
A
P P(Bi ) Points to be noted
i 1
Bi
For asymmetric distribution : mean = medians = mode
Conditional probability For normal distribution : mean – mode
B = 3(mean – median).
P(AB) = P(A) . P
A Poission Distribution
B
P . P(A) Poission’s distribution is related to probabilities of events which
A A
P = are extremely rare but have large number of individual chances to
B P(B)
occur. E.g.- number of persons die by dog-bite in a city. The
Consider one event B which occurs after occurrence of event A, number of trials n is taken very large and chance of P is taken
then every small taking np constant.
B P(B A)
P =
A P(A)
S2-10 Probability

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

(a) f(b – a) (b) f (b) – f(a)


Conceptual MCQs
b b
1. A program consists of two modales executed sequentially. (c) f (x)dx (d) xf (x)dx
a a
Let f1(t) and f2(t) respectively denote the probability
density functions of time taken to execute the two
modules. The probability density function of the overall
Problem Based MCQs
time taken to execute the program is given by 7. Let P(E) denotes the probability of the event E. Given
[2003, 2 Marks] P(A) = 1, P(B) = 1/2, the values of P(A/B) and P(B/A)
t respectively are [2003, 1 Mark]
(a) f1(t) + f2(t) (b) f (x)f 2 (x) dx
0 1 (a) 1/4, 1/2 (b) 1/2, 1/4
t
(c) 1/2, 1 (d) 1, 1/2
(c) f (x) f 2 (t x) dx (d) max {f1(t), f2(t)} 8. If a fair coin is tossed four times. What is the probability
0 1
that two heads and two tails will result?
2. Two n bit binary strings S1 and S2 are chosen randomly [2004, 1 Mark]
with uniform probability. The probability that the Hamming (a) 3/8 (b) 1/2
distance between these strings (the number of bit (c) 5/8 (d) 3/4
positions where the two stings differ) is equal to d is 9. An examination paper has 150 multiple choice questions
[2004, 2 Marks] of one mark each with each question having four choices.
(a) nCd/2n (b) nCd/2d Each incorrect answer fetches –0.25 mark. Suppose 1000
(c) d/2n (d) 1/2d students choose all their answers randomly with uniform
3. If f(x) be the continuous probability density function of probability. The sum total of the expected marks obtained
a random variable X. The probability that a < X b, is by all these students is [2004, 2 Marks]
[2005, 1 Mark] (a) 0 (b) 2550
(a) f (b – a) (b) f (b) – f (a)
(c) 7525 (d) 9375
b b 10. A point is randomly selected with uniform probability in
(c) f (x) dx (d) xf (x) dx
a a the X-Y plane within the rectangle with corners at (0, 0),
4. Which one of the following statements is not true? (1, 0), (1, 2) and (0, 2). If p is the length of the position
[2005, 1 mark] vector of the point, the expected value of p2 is
(a) The measure of skewness is dependent upon the [2004, 2 Marks]
amount of dispersion (a) 2/3 (b) 1
(b) In a symmetric distribution, the value of mean, mode (c) 4/3 (d) 5/3
and median are the same 11. A fair dice is rolled twice. The probability that an odd number
(c) In a positive skewed distribution mean > median > mode will follow an even number is [2005, 1 mark]
(d) In a negative skewed distribution, mode > mean >
median 1 1
(a) (b)
5. If P and Q are two random events, then which of the following 2 6
is true? [2005, 1 mark]
(a) Independence of P and Q implies that probability 1 1
(c) (d)
3 4
(P Q) = 0
12. A fair coin is tossed three times in succession. if the first
(b) Probability ( P Q) Probability (P) + Probability (Q) toss produces a head, then the probability of getting exactly
(c) If P and Q are mutually exclusive, then they must be two heads in three tosses is [2005, 1 mark]
independent 1 1
(d) Probability ( P Q) Probability (P) (a) (b)
8 2
6. Let f(x) be the continuous probability density function of a
random variable X. The probability that a < X b, is 3 3
(c) (d)
8 4
[2012, 1 mark]
S2-12 Probability

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

where X N = standard normal deviate, if mean of standard 5 1


(c) (d)
deviations of annual precipitation are 102 cm and 27 cm 12 2
respectively, the probability that the annual precipitation 33. A deck of 5 cards (each carrying a distinct number from 1 to
will be between 90 cm and 102 cm is 5) is shuffled throughly. Two cards are then removed one at
(a) 66.7% (b) 50.0% a time from the desk. What is the probability that the two
(c) 33.3% (d) 16.7% cards are selected with the number of the first card being
27. A fair coin is tossed 10 times. What is the probability that one higher than the number on the second card?
only the first two tosses will yield heads? [2009, 1 mark]
[2011, 1 mark]
2 2
1 10 1
(a) ÷ (b) C2 ÷ 1 4
2 2 (a) (b)
5 25
10 10
1 10 1 1 2
(c) ÷ (d) C2 ÷ (c) (d)
2 2 4 5
28. An unbalanced dice (with 6 faces, number from 1 to 6) is 34. There are two containers, with one containing 4 red and 3
thrown. The probability that the face value is odd is 90% of green balls and other containing 3 blue and 4 green balls.
the probability that the face value is even. The probability One ball is drawn at random from each container. The
of getting any even numbered face is the same. if the probability that one of the balls is red and the other is blue
probability that the face is even given that it is greater than will be [2011, 1 mark]
3 is 0.75, which one of the following option is closest to the
probability that the face value exceeds 3? [2009, 1 mark] 9
(a) 17 (b)
(a) 0.4533 (b) 0.468 49
(c) 0.485 (d) 0.492
29. Assume for simplicity that N people, all born in April (a 12 3
(c) (d)
month of 30 days) are collected in a room. Consider, the 49 7
event of atleast two people in the room being born on the 35. If two fair coins are flipped and atleast one of the outcomes
same date of the month, even in different years, e.g., 1980 is known to be a head, what is te porbability that both
and 1985. What is the smallest N. So that the probability of
outcomes are heads? [2012, 1 mark]
this event exceeds 0.5? [2009, 1 mark]
(a) 20 (b) 7 (a) 1/3 (b) 1/4
(c) 15 (d) 16 (c) 1/2 (d) 2/3
S2-14 Probability

36. Suppose p is the number of cars per minute passing


through a certain road junction between 5 pm and 6 pm Numerical Answer Questions
and p has a poisson distribution with mean 3. What is
the probability of observing fewer than 3 cars during any 38. Four fair six-sided dice are rolled. The probability that the
given minute in this interval? [2013, 1 mark] sum of the results being 22 is X/1296. The value of X is
______ . [2014, Set-1, 2 Marks]
8 9 39. The security system at an IT office is composed of 10
(a) (b)
( )
2e 3
( )
2e3 computers of which exactly four are working. To check
whether the system is functional, the officials inspect four
of the computers picked at random (without replacement).
17 26 The system is deemed functional if at least three of the four
(c) (d)
(2e )
3
(2e )
3 computers inspected are working. Let the probability that
the system is deemed functional be denoted by p.Then
37. Consider an undirected random graph of eight vertices. 100p = _____________. [2014, Set-2, 1 Mark]
The probability that there is an edge between a pair of 40. The probability that a given positive integer lying between
vertices is 1/2. What is the expected number of unordered 1 and 100 (both inclusive) is NOT divisible by 2, 3 or 5 is
cycles of length three? [2013, 1 mark] ______ . [2014, Set-2, 2 Marks]
(a) 1/8 (b) 1 41. Let S be a sample space and two mutually exclusive events
(c) 7 (d) 8 A and B be such that A B = S. If P (·) denotes the
probability of the event, the maximum value of P(A) P (B) is
________ . [2014, Set-3, 2 Marks]
Probability S2-15

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

1 12. (b) Total samples = (H, T), (H, T), (H, T)


8. (a) P(H) = Given, first toss produces a head
2 Then, total chance becomes = H, (H, T), (H, T)
1 For exactly two heads in three toss = H, H, H
P(T) = total favourable events
2
So, probability =
Assuming occurrence of two heads as success. total sample
Required probability = P(2H,2T) 3 1
2 4 2
= =
4 1 1 6 2
= C2 . 13. (c) If two fair dice rolls the probability distribution of r,
2 2 where r is the sum of the numbers on each dice is
4 3 1 3 given by
=
2 16 8 r 2 3 4 5 6 7 8 9 10 11 12
X 1 – 0.25 1 2 3 4 5 6 5 4 3 2 1
9. (d) P( r )
P(X) 1 3 36 36 36 36 36 36 36 36 36 36 36
4 4 The above table has been obtained by taking all
Expected marks per question different ways of obtaining a particular sum.
1 3 Example A sum of six can be obtained by (1, 5), (2, 4), (3, 3),
=1× ( 0.25) (4, 2), (5, 1)
4 4
6
1 3 1 P ( x = 6) =
= 36
4 16 16 (a) Probability (r > 6) = Probability (r 7)
Total marks expected for 150 question per student
6 5 4 3 2 1 7
1 75 = + + + + + =
= 150 36 36 36 36 36 36 12
16 8
Option (a) is wrong.
75 (b) Probability (r/3 is an integer)
For 1000 students = 1000 9375 marks
8 = Probability (r = 3) + Probability (r = 6)
10. (d) Here, 0 x 1, 0 y 2 + probability (r = 9) + Probability (r = 12)
2 5 4 1 1
1 = + + + =
p(x) = 1 36 36 36 36 3
1 0 Option (b) is wrong
1 1 (c) Probability of (r/4 is an integer)
p(y) = = Probability (r = 4) + Probability (r = 8)
2 0 2
+ Probability (r = 12)
4 2 3 5 1 9 1
E(x2) = x p( x ) dx = + + = =
0
36 36 36 36 4
1 5
4 2 x3 1 and Probability (r = 8) =
= x dx = 36
0 3 3 r
0
Then, probability r = 8 | is an integer ÷
2 2 4
E(y2) = y p( y ) dy
5
0
5
1 2 2 = 36 =
= y dy 1 9
2 0
4
1 3 2 So, option (c) is right.
= ( y )0
6 (d) Probability of (r/5 is an integer)
= Probability (r = 5) + Probability (r = 10)
8 4
= 4 3 7
6 3 = + =
E(p2) = E(x2) + E(y2) 36 36 36
5
1 4 5 and Probability (r = 6) =
= 36
3 3 3 then, Probability (r =6 | r/5 is an integer)
5
11. (d) Both the events are independent 5
= 36 =
1 1 1 7 7
Required probability = = 36
2 2 4
Option (d) is wrong
Probability S2-17

14. (d) Let the mean and standard deviation of the students
of batch C are 17. (b) 25 calculators

C = 6.6 and C = 2.3


And the mean and standard deviations of the entire 2 defective 23 (non-defective)
class
5 calculators
Students are c = 5.5 and = 4.2
(randomly picked)
In order to normalize the batch C and entire class
x
z= (standard normal variate) 1 defective 4 non-defective

xC The probability that only one of the defective


C 8.5 6.6
For batch C = =
2.3
calculators will be included in the inspection
C
2
C1 23C4
x x 5.5 =
25
For entire class, z = = C5
4.2
2 23 22 21 20 5
By the instructer zC = z =
25 24 23 22 21
8.5 6.6 x 5.5 1
= =
2.3 4.2 3
x 9.0 18. (c) Assuming A and B are the events of failing in Paper 1
and Paper 2 respectively.
P(A) = 0.3
15. (c) P( x )dx = 1 P(B) = 0.2
A
P ÷ = 0.6
B
| x|
ke dx = 1 Probability of failing in both the papers
A
P( A B) = P ÷ . P( B)
0 B
ke x dx + ke x
dx = 1 = 0.6 × 0.2 = 0.12
0 19. (c) Probability of occurrence of values 1, 5 and 6 on three
dice is
k x 0 k x = P(1) × P(5) × P(6)
(e ) + (e )0 = 1
1 1 1 1
k k 4 8 4 128
+ =1 Similarly, probability of occurrence of values 3, 4 and 5.
On three dice is
2k = = P(3) × P(4) × P(5)
k = 0.5
1 1 1 1
1 8 8 8 512
16. (a) P ( H ) = P (T ) =
2 And probability of occurrence of values 1, 2 and 5 on
The probability that exactly n elements are chosen = three dice is
The probability of getting n heads out of 2n tosses = P(1) × P(2) × P(5)

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

21. (a) Given, µX = 1, X2 = 4, µY = –1 and µY2 is unknown 1


Given, P(X –1) = P(Y 2) x3 .1 dx
Converting into standard normal variates 0
1 X 2 Y 1
P z P z x4 1
X Y
4 4
0
1 1 2 ( 1)
P z P z
2 Y 25. (b) The PDF is f ( x) x 2 , x [–1, 1]
= 0, other value of x
3
P( z 1) P z
1/3
Y 1 1
But P x f ( x ) dx
Since, P( z 1) P z 1 3 3
1/3

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

So, the probability of the occuring is 40. 0.259 to 0.261


1 1 1 1 First we find out numbers which are divisible by either 2, 3
= or 5
2 2 2 8 Consider 2
By definition of Expectation, which is if X is a All even numbers are divisible by 2
random variable over sample space No. of numbers divisible by 2 between 1 and 100 = 50
[X] = x P ( x) Consider 3
x Multiples of 3 cm 3, 6, 9, 12, 15 ...
100
1 8 Total nos = = 33
Here P(x) = x and x spans over all C3 3
8 Out of this alternate numbers are divisible by 2 also.
configurations Number of remaining numbers = 33 – 16 = 17
1 Consider 4
Hence, expected value = 8C3 × =7 Multiples of 5 are 5, 10, 15, 20, 25...
8
Hence, the option is (c). 100
Total no. = = 20
NUMERICAL ANSWER QUESTIONS 5
Out of this alternate numbers are divisible by 2
38. 10 Remaining no. = 10
Given that four six-sided dice are rolled. Out of remaining odd numbers 15, 45 and 75 are divisible by 3
Since each dice can result 1, 2, 3, 4, 5 or 6. Remaining is 7
Total no. of outcomes = 6 × 6 × 6 × 6 Total number of nos divisible by 2, 3 or 5
= 1296 = 50 + 17 + 7
Now, we shall calculate number of favourable cases for sum = 74
of the results being 22. Probability of integer not divisible by 2, 3 or 5
We note that only two cases can result in sum 22.
(i) Two dice result 6, Two dice result 5 (6, 6, 5, 5) 74
=1 = 0.26
(ii) Three dice result 6, One dice result 4 (6, 6, 6, 4) 100
No other combination will result is sum 22. 41. 0.25
4! A B=S
No. of favourable cases for case (i) = 4C2 = =6 P (A B) = P(S) = 1
2!2!
P(A) + P(B) = 1 ( A & B are mutually
4!
No. of favourable cases for case (ii) = 4C1 = =4 exclusive)
1!3! P(B) = 1 – P(A)
Since either case (i) can occur or case (ii), Maximum value of P(A)P(B) = P(A) [1 – P(A)]
So, total no of favourable cases = 6 + 4 = 10 Let P(A) = X
(Probability of sum = 22) Let f(x) = x(1 – x) = x – x2
no. of favourable cases 10 for f(x) maximum
= = f (x) = 0
Total no. of cases 1296
So, value of X = 10. 1
39. 11.85 to 11.95 1 – 2x = 0 x=
2
P = P [atleast 3 computers are working] f (x) = – 2
= P [3 or 4 computers working]
1

=
( 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

3 Set Theory & Algebra


Chapter

Quick Revision Material


= | A | + | B | – | A B | + | C | – | (A C) (B C) |
ALGEBRAIC OPERATIONS ON SETS = |A| + | B | + | C | – |A B | – [ |A C | + | B C | –A B C | ]
Idempotent operation : For any set A, we have hence follows the result
(i) A A = A and = | A | + | B | + | C | – | A B | – | A C | – | B C | + | A B C|]
(ii) A A = A
CARTESIAN PRODUCT OF SETS
Identity operation : For any set A, we have
Ordered Pair : A pair of objects, listed in a specific order, is
(i) A = A and
called an ordered pair, for example (a, b) is an ordered pair of two
(ii) A U = A elements a and b, a is called the FIRST ELEMENT and b the
i.e. and U are identity elements for union and intersection SECOND ELEMENT.
respectively. Two ordered pairs (a, b) and (c, d) are equal if any only if
Commutative operation : For any set A and B, we have a = c and b = d.
(i) A B = B A Cartesian product of Sets : Let A and B are two non-empty sets.
(ii) A B = B A and The set of all ordered pairs (a, b) of elements a A and b B is
(iii) A B = B A called the Cartesian Product of sets A and B and is denoted by
i.e. union intersection and symmetric difference of two sets A × B. Thus A × B = {(a, b) : a A, b B}
are commutative. For example : If A = {1, 2, 3} and B = {a, b}, then
(i) A × B = {(1, a)}, (1, b), (2, a), (2, b), (3, a), (3, b)}
REL ATI ONS
A – B B – A and A × B B × A Let A and B be two non-empty sets. Then a relation (BINARY
RELATION) R from A to B is a subset of A×B.
LAWS OF SET THEORY
That is, R is a relation from A to B R A × B
1. Commutative Law
If R A×A, the R is said to be a relation on A.
A B= B A;A B= B A.
2. Associative Law If (a, b) R, then we write aRb and we say a is R related to b.
A (B C) = (A B) C Thus, (a, b) R aRb.
A (B C) = (A B) C If (a , b) R , then we write a R b and say that a is not related to b.
3. Distributive Law
A (B C) = (A B) (A C) DOMAIN AND RANGE OF A RELATION
A (B C) = (A B) (A C) Let A and B are two sets and R is a relation from A to B,
4. Complement Law i.e. R A × B
A A° = U ; A Ac = .
The set of all the first components of the ordered pairs of the
5. Identity Law
A =A= A relation R is called the DOMAIN of R. Thus
A U = A = U A. domain of R = {a A : (a, b) R for some b B}
6. Absorption Law A (A B) = A ; A (A B) = A The set of all the second components of the ordered pairs of the
7. De Morgan’s Law (A B)c = Ac Bc ; (A B)c = Ac Bc relation R is called the RANGE of R. Thus,
8. Involution Law (Ac)c = A. range of R = {b B : (a, b) R for some a A}
Obs. Using the distributive law, we can extend the above result Clearly domain of R A and range of R B
for three sets A, B, C
The set B is called the CO-DOMAIN of R
| A B C | = (A B) C |
= | A B | + | C | – | (A B) C |
S2-22 Set Theory & Algebra

Example : If (a, b) R and (b, a) R, then still R is an antisymmetric


(i) If A = {1,2,3} and B = {a, b, c} let R = {(1,a) (1,c), (2, b) relation.
Then domain of R = {1, 2} range of R = {a, b, c} Example : Let R be a relation on the set N of natural numbers
Number of Relations : Let A contains m elements and B contains defined by
n element. Then A×B contains mn elements. Hence, A×B has xRY ‘x divides y’ for all x, y N
2mn subsets. That is the total number of relations from A to B are This relation is a antisymmetric relation on N.
2mn. The relations (called a VOID RELATION) and A × B (called Since for any two numbers a, b N.
an UNIVERSAL RELATION) are said to be TRIVIAL RELATIONS a/b and b/a a = b i.e. aRb and bRa a = b
from A to B.
EQUI VAL ENCE RELATION
Inverse Relation : The inverse relation of a relation R is the set
obtained by reversing each of the ordered pairs of R and is A relation R on a set A is an equivalence relation if and only if
denoted by R–1. (a) R is reflexive, i.e, aRa a A
Example : (b) R is symmetric, i.e., aRb bRa
(i) Let A = {1, 2, 3} and B = {a, b, c} (c) R is transitive, i.e., aRb and bRc aRc
If R = {(1, a), (2, a), (3, b), (3, c)} A × B Partial order relation :
Then R–1 = {(a, 1), (a, 2), (b, 3), (c, 3)} B×A A relation R on a set A is a partial order relation if and only if.
(a) R is reflexive, i.e. aRa a A
TYPES OF RELATIONS ON THE SET A (b) R is antisymmetric i.e., aRb and bRa a = b
Let A be a set and R is a relation on A, i.e. R A × A. Then we (c) R is transitive, i.e., aRb and bRc aRc.
define Relation of congruence modulo m :
1. Void Relation : If R = , then R is called a void relation on Let m be a fixed positive integer. Two integers a and b are said to
A. be “congruent modulo m” if a – b is divisible by m. We write
a b (mod m)
2. Universal Relation : If R = A×A, then R is called an universal
Thus. a b (mod m) [Read as “ a is congruent to b modulo m”]
relation on A.
iff a – b is divisible by m; a, b .
3. Identity Relation : A relation R is defined as an identity For example :
relation if R = {(a, a) : a A}. Thus in an identity relation (i) 25 5 (mod 4) because 25–5 = 20 is divisible by 4.
on A, every element of A is related to itself only. Identity (ii) 23 2 (mod 3) because 23 –2 = 21 is divisible by 3
relation on A is also denoted by IA. Thus (iii) 20 / 3 (mod 5) because 20 – 3 = 17 is not divisible by 5
IA = {(a, a) : a A} The relation “ congruence modulo m” is an equivalence
Example : If A = {1, 2, 3}, then IA = {(1, 1), (2, 2), (3,3)} relation on I.
4. Reflexive Relation : A relation R is said to be a reflexive
relation on A if every element of A is related to itself.
DOMAIN, CO-DOMAIN AND RANGE
Thus R is reflexive (a,a) R, i.e. aRa a A If f A B is a funciton, then A is called domain, B is called co-
domain of f.
[The symbol is read as “for every element”]
Range :
Example : Let A = {1, 2, 3} be a set. If f : A B is a function, then set of all images of the elements of
Then R = {(1, 1), (2, 2), (3, 3), (1, 3), (2, 1)} is a reflexive A is called range of f.
relation on A. Range is a subset of the co-domain, i.e. f (A) B.
5. Symmetric Relation : A relation R on a set A is defined as a e.g. If A = {1, 2, 3, 4}, B = {p, q, r} and f = (1, q), (2, q), (3, q), (4, q)},
symmetric relation if (a,b) R (b, a) R That is, then f is a function.
aRb bRa, where a, b A. Domain = A, Co-domain = B.
Example : Let A = {1, 2, 3, 4} and let R1 be relation on Range of f = f (A) = {f (1), f (2), f (3), f (4)}
A given by R1 = {(1, 3), (1, 4), (3, 1), (2, 2), (4, 1)} is a = {q, q, p, q} = {p, q}
symmetric relation on A. f (A) B
6. Transitive relation : A relation R on a set A is defined as a KINDS OF FUNCTIONS
transitive relation if (a,b) R and (b,c) R (a,c) R 1. One-to-one Function (or injective function)
That is, aRb and bRc aRc, where a, b, c, A. A function f : A B is called one-one mapping if every
Example : Let L be the set of all straight line in distinct element of A has a distinct image in B.
a plane. Then the relation ‘is parallel to on L is a transitive Thus, a function f : A B is one-one
relation, because of any 1, 2, 3, L.
2. Many-one Function : A function f : A B is many-one if
|| and 2|| 3 ||
1 2 1 3 two or more different elements of A have the same image in B.
7. Antisymmetric Relation : A relation R on a set A is
Thus, f : A B is many-one if
antisymmetric if (a,b) R and (b,a) R a = b
Set Theory & Algebra S2-23

3. Onto or Surjective Function : The function f : A ® B is Theorem 4 :


said to be an onto function if every element of B is image of If (G, .) be a group and a, b Î G, then (ab)–1 = b–1a–1
at least one element of A. Theorem 5 :
For a surjective function f, If (G, .) be a group and a1, a2, .... an Î G, then
Range of f = co-domain (B)
(a1a 2 .....a n ) -1 = a n-1a n--11.........a1-1
4. Into Function : If the function f : A ® B is such that there
is at least one element of B which is not the image of any Theorem 6 :
element of A, then f is called an into function. Cancellation laws hold in a group, i.e. If (G, .) is a group then
For an into function f. I. a, b, c Î G, ab = ac
Range of f Ì co-domain (B) Þ b=c
II. a, b, c, Î G, ba = ca
f f
Þ b = c.
x1 y1 x1 y1 Definition 4.
x2 y2 x2 y2
x3 y3 x3 y3
y4
If (G, .) be a gorup and a Î G, n Î z, then an is defined as follows :
A B A B I. a0 =e
Many-one Into One - One Into II. If n > 0, then a1 = a; an+1 = an . a
f f III. If n < 0, then an = (a–n)–1
x1 y1 x1 y1 Theorem 7.
x2 y2 x2 y2
x3 x3 y3 Let (G, .) be a group and a Î G.
If m, n Î Z, then
A B
Many-one Onto
I. am . an = am+n = anam
One - One Onto
Bijective function : A function f : A ® B is a bijective II. (a )
m n
= a mn
function if f is one-one as well as onto, i.e. f is injective and Definition 5.
surjective both. Let (G, .) be a group. An element a Î G is called idempotent if a2 = a.
Definition 6.
GROUP
A group (G, .) is called finite group if G is a finite set The number of
A semigroup with identity and in which every element is invertible different elements in G is callled order of the fininte group (G, .). It
is called a group. is denoted by O(G).
Definition 1 Definition 7.
Let G be a non-empty set and * be a binary operation on G. Then A group (G, .) is called infinite group if G is an infinite set. The
algebraic system (G, *) is called a group if order of an infinite group is defined to be ¥.
I. a * (b * c) = (a * b) * c, " a, b, c Î G Definition 8.
II. $e Î G Þ a * e = e * a = a, " a Î G If S is a finite set containing n elements, then group of all
III. a Î G bijections on S is called a permutation group or symmetric group.
Þ $b Î G Þ a * b = b * a = e It is denoted by Pn or Sn.
• The element e in condition II of the definition of a group is Note : 0(Sn) = n!
called identity element of the group.
LATTICE
• The element b corresponding to a in condition III of the
definition of a group is called inverse of a in the group. It is a partially ordered set (P, £) in which any two elements Î P
Definition 3 : has single GLB and single LUB.
A group (G, *) is said to be a non-abelian group, if (G, *) is not Join = LUB
abelian.
PROPERTIES OF A GROUP. (a) (b)
Theorem 1 :
In a group, identity element is unique. Meet = GLB
Theorem 2 : Fig. (a)
In a group, inverse of every element is unique.
In the Fig. (a) GLB and LUB are shown, which are also called
Theorem 3 : meet and join respectively.

( )
-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

2 3 Boolean Algebra Homomorphism


If (A, +, .,', 0, 1) and (B, Ù, Ú, –, 0', 1') are two Boolean algebras, a
2 3 function h : A ® B is called a Boolean algebra homomorphism if
h preserves the two binary operation and the unary operations
4
in the following since, for all a, b Î A
(a) h(a + b) = h(a) Ú h(b)
1 5 (b) h(a × b) = h(a) Ù h(b)
1£ 2£ 4£ 5 5³ 4³ 2³ 1
1£ 3£ 4£ 5 5³ 4³ 3³ 1 (c) h (a' ) = h' (a)
Let a * b = meet of a and b = GLB, and a Å b = join of a and b = A Boolean homomorphism h : A ® B is a Boolean isomorphism
LUB if h is one-to-one onto B.
SUB-LATTICE.
Let (L, *, Å) be a lattice and let S Í L. The set (S, *, Å) is called
sublattice iff it is closed under * and Å. Sublattice is itself a
lattice.
Set Theory & Algebra S2-25

7. Consider the following relation on subsets of the set S of


Conceptual MCQs integers between 1 and 2014. For two distinct subsets U
1. Let (S, ) be a partial order with two minimal elemetns a and V of S we say U < V if the minimum element in the
and b, and a maximum element c. Let P : S {True, symmetric difference of the two sets is in U.
False} be a predicate defined on S. Suppose that P(a) = Consider the following two statements:
True, P(b) = False and P(x) P(y) for all x, y S S1: There is a subset of S that is larger than every other
satisfying x y, where stands for logical implication.
subset.
Which of the following statements cannot be true?
[2003, 2 Marks] S2: There is a subset of S that is smaller than every other
(a) P(x) = True for all x S such that x such that x b subset.
(b) P(x) = False for all x S such that x a and x c Which one of the following is CORRECT?
(c) P(x) = False for all x S such that b x such that [2014, Set-2, 2 Marks]
x c (a) Both S1 and S2 are true
(d) P(x) = False for all x S such that a x and b c (b) S1 is true and S2 is false
2. The following resolution rule is used in logic programming (c) S2 is true and S1 is false
Derive clause (P Q) from clauses (P R), (Q R)
(d) Neither S1 nor S2 is true
Which of the following statements related to this rule is
false? [2003, 2 Marks]
(a) (P R) (Q R) (P Q) is logically valid Problem Based MCQs
(b) (P Q) (P Q) (Q R) is logically valid
8. Let f : A B be an injective (one-to-one) function. Define
(c) (P Q) is satisfiable if and only if (P R) (Q R)
(d) (P R) False if and only if both P and Q are g : 2A 2B as :g(C) = {f(x) x C), for all subsets C of
unsatisfiable A.
3. A relation R is defined an ordered pair of integers as follows Define h : 2B 2A as : h(D) = {x | x A, f(x) D}, for
(x, y) R (u, v), if x < u and y < v. The, R is [2006, 1 mark] all subsects D of B.
(a) neither a Partial Order nor an Equivalence Relation Which of the following stattements is always true?
(b) a Partial Order but not a Total Order [2003, 2 Marks]
(c) a Total Order (a) g(h(D)) D (b) g(h(D)) D
(d) an equivalence Relation
(c) g(h(D)) D = (d) g(h(D)) (B – D)
4. If P, Q, R are subsets of the universal set U, then
9. Consider the set {a, b, c} with binary operators + and
(P Q R) (Pc Q R) Qc Rc is [2008, 1mark]
defined as follows :
(a) Qc Rc
(b) P Qc Rc
(c) Pc Qc Rc + a b c × a b c
(d) U a b a c a a b c
5. Which one of the following is not necessarily a property of b a b c b b c a
a group? [2009, 1mark] c a c b c c c b
(a) Commutativity
(b) Associativity For example, a + c = c, c + a = a, c b = c and b c = a.
(c) Existence of inverse for every element Given the following set of equations
(d) Existence of identity (a x) + (a y) = c
6. Which one of the following Boolean expressions is NOT a (b x) + (c y) = c
tautology? [2014, Set-2, 2 Marks]
The number of solutions [i.e., pair (s) (x, y) that satisfies
(a) ((a b) (b c) (a c)
(b) (a c) ( ~ b (a c)) the equations] is [2003, 2 Marks]
(c) (a b c) ( c a) (a) 0 (b) 1
(d) a (b a) (c) 2 (d) 3
S2-26 Set Theory & Algebra

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

CONCEPTUAL MCQs (a ´ x) + (a ´ y) = c ...(i)


(b ´ x) + (c ´ y) = c ....(ii)
1. (d) If a £ x, since p(x) Þ p(y) whenever x £ y Substitue first (x, y) = (a, a)
\ p(a) Þ p(x) LHS of Eq. (i) becomes
Now since p(a) = True, p(x) = cannot be false. (a ´ a) + (a ´ a) = a + a = b
\ (d) cannot be true. Now, RHS of Eq. (i) = c.
2. (b) Derive caluse P Ú Q from clauses P Ú R, Q ÚØ R Therefore, LHS ¹ RHS. This means that (a, a) is not
means that a solution pair. Similarly try each of the remaining
(P Ú R) Ù (Q Ú Ø R) Þ P Ú Q seven possible solution pairs. It will be found that
\ (a) is true only two pairs (b, c) and (c, b) will satisfy both Eqs.
Since, x Þ y does not imply that y Þ x (i) and (ii) simultaneously.
\ P Ú Q Þ (P Ú R) Ù (Q Ú Ø R) 10. (b) If S = {a, b, c, d, e}
\ may or may not be true. Hence, (b) is not true. g(a) = 3
3. (a) (x, y) R (u, v) if x < u and y > v (x, x) R, (x, x) g(b) = 5
sincex </ x adn x >/ x. g(c) = 7
So. R is not reflexive. g(d) = 9
\ is neither a partial order, nor an equivalence relation. g(e) = 11
4. (d) Q Qc È Rc = (Q Ç R)c Now, consider the string aaa, where s1 =a, s2 = a and
and (P Ç Q Ç R) È (Pc Ç Q Ç R) = Q Ç R s3 = a
Therefore, (P Ç Q Ç R) È (Pc Ç Q Ç R) È Qc È Rc
1
= (Q Ç R) È (Q Ç R)c
= U (Universal set) f(s1) = f(s2) = f(s3) = Õ pig(a i )
i =1
5. (a) Group properties are closure, associativity, existence of
identity and existence of inverse for every element. = p1g(a1 )
Commutativity is not required for a mathematical
structure to become a group. = p1g(a ) = 23 = 8
6. (b) (a « c) ® (~ b ® (a Ù c))
7. (a) Nullset is larger than any other set. 3
Universal set is smaller than any other set. h(s1, s2 s3) = Õ pif (si )
i =1
PROBLEM BASED MCQs
= 2f (s1 ).3f (s 2 ).5f (s3 )
8. (a) consider A, B and f as defined below (since f needs = 28 38 58
not be onto) 11. (a) å = {0, 1}
A B å* = {0, 1} *
= {Î, 0, 1, 01, 10, 11, 000, ...}
1 f So, (å*, •) is an algebraic system, where •
a
2 (concatenation) is a binary operation.
b
So (å*, •) is a group, if and only if the following
c conditions are satisfied.
1. • (Concatenation) is a closed operation.
Consider a subset D of B such that 2. • is an associative operation.
D = {a, c} 3. There is an identity.
h(D) = {1} 4. Every element of å* has a left inverse.
g(h(D)) = {a} Condition 1 * is a closed operation because for any
g(h(D)) Í D is true w1 Î å* and w2 Î å*, w1 . w2 Î å*
Notice, that if the function f were both one-to-one Condition 2 For any string x, y, z Î å*, x. (y . z)
and onto then g(h(D)) = D. = (x . y) . z
9. (c) The possible solution pairs are (a, a), (a, b), (a, c), (b, So, it is associative for example, Let
a), (b, b), (c, a), (c, b) and (c, c). x = 01, y = 11, z = 00 then
Substitute them one by one in both equations and LHS = x . (y . z)
see which of them satisfies both the equations. = 01. (11.00) = 01.(1100) = 011100
The given equations are RHS = (x. y) . z
= (01.11) .00 = (0111).00 = 011100
Set Theory & Algebra S2-29

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

17. (b) Clearly form the shown diagram, 20. (b) X : (P Ú Q) ® R


Y : (P ® R) Ú (Q ® R)
A B C
X : P + Q ® R º (P + Q)¢ + R = P¢ Q¢ + R
a 1 x Y : (P¢ + R) + (Q¢ + R) º P¢ + Q¢ + R
b 2 y Clearly, X ¹Y
3 Consider X ® Y
º (PQ)¢ + R) ® (P¢ + Q¢ + R)
g is into
º (P¢Q¢ + R)¢ + P¢ + Q¢ + R
f is onto
and h = g of is onto º (P¢ Q¢)¢ R¢ + P¢ + Q¢ + R
º (P + Q) R¢ + P¢ + Q¢ + R
18. (c) Given R and S be two equivalence relations on a
º PR¢ + QR¢ + P¢ + Q¢ + R
non-empty set A. Then both are reflexive, symmatric
and transitive. º (PR¢ + R) + (QR¢ + Q¢) + P¢
" x Î A, y Î A, z ÎA º (P + R) (R¢ + R) + (Q + Q¢) × (R¢ + Q¢) + P¢
(a) (x, x) Î R and (x, x) Î S º P + P¢ + R + R¢ + Q¢
Þ (x, x) Î R Ç S = 1 + 1 + Q¢ º 1
\ R Ç S is reflexive.
\ X ® Y is a tautology.
(a) (x, y) Î R Ç S
Þ (x, y) Î R and (x, y) ÎS 21. (c) The set S = {1, 2, 4, 7, 8, 11, 13, 14} is a group under
Þ (y, x) ÎR and (y, x) Î S multiplication modulo 15.
(Q R, S are symmetric) The identity element for this group is e = 1 since,
Þ (y, x) Î R Ç S
Thus, R Ç S is symmetric "x ÎS,1× x mod 15 = x
(c) (x, y) R Ç S and (y, z) Î R Ç S Now, let the inverse of 4 be 4–1.
Þ (x, y) Î R and (x, y) Î S Now, (4·4) mod 15 = 1
and (y, z) Î R and (y, z) Î S
\ 4–1 = 4 (This inverse is unique)
Þ [(x, y) Î R and (y, z) Î R]
and [(x, y) Î S and (y, z) Î R] Similarly, let the inverse of 7 be 7–1.
Þ (x, z) Î R and (x, z) Î S (7·7–1) mod 15 = 1
(By transitivity of R and S) Putting each element of set as 7–1 by trial and error,
Þ (x, y) Î R Ç S we get
Hence, R Ç S is transitive.
Thus, R Ç S is an equivalence relation. (7·13) mod 15 = 91 mod 15 = 1
But R È S is not necessarily an equivalence relation \ 7–1 = 13
on A which can be explained by an example. So, 4–1 and 7–1 are respectively 4 and 13.
Let A = {1, 2, 3} 22. (a) X = (A – B) – C
and R = {(1,1), (2, 2), (3, 3) (1, 2), (2, 1)}
= (A Ç B¢) Ç C ¢
S = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1), (2, 3) (3, 2)}
Then, R È S = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1), = A Ç B¢ Ç C¢
(2, 3), (3, 2)} Y = (A – C) – (B – C)
Cleanly, R and S are equivalence relations on A but = (A – C¢) – (B Ç C¢)
R È S is not equivalence relations on A as it is not = (A Ç C¢) Ç (B Ç C¢)¢
transitive because (1, 2) 6 R È S and (2, 3) Î R È
= (A Ç C¢) Ç (B¢ È C)
S but (1, 3) Ï R È S.
19. (c) The number of combinations of pairs (a mod 3, b mod = (A Ç C¢ Ç B¢) È (A Ç C¢ Ç C)
5) is = A Ç B¢ Ç C¢
3 ´ 5 = 15 \ X= Y
(since, a mod 3 can be 0, 1 or 2) and b mod 5 can 23. (b) Here, n = mC3
be 0, 1, 2, 3 or 4
and f (1) = f (2)... = f (m) = m–1C2
\ If 16 different ordered pairs are chosen at least 2
of them must have (a mod 3, b mod 5) as same (basic m
pigeon hole principle). Þ å f (i) = mm –1C 2
Let such two pairs be (a, b) and (c, d) then i =1
a mod 3 º c mod 3 Þ a º c mod 3
and b mod 5 º d mod 5 Þ b º d mod 5. = 3 × m C3 = 3 × n = 3n
Set Theory & Algebra S2-31

24. (c) X = (E Ç F) – (F Ç G) 27. (a) X = (A – B) – C


= (E Ç F) Ç (F Ç G)¢ = (A Ç B¢) Ç C¢
= (E Ç F) Ç (F¢Ç G¢) = A Ç B¢ Ç C¢
= (E Ç F Ç F¢) È (E Ç F Ç G¢) Y = (A – C) – (B – C)
= E Ç F Ç G¢ = (A Ç C¢) – (B Ç C¢)
Y = (E – (E Ç G)) – (E – F) = (A Ç C¢) Ç (B Ç C¢)¢
= (E Ç (E Ç G¢)) – (E Ç F¢) = (A Ç C ¢) Ç (B ¢È C)
= (E Ç (E¢ È G¢) Ç (E Ç F¢)¢ = (A Ç C¢ÇB¢) È (A Ç C¢Ç C)
= (E Ç E¢) È (E Ç G¢) Ç (E È F) = A Ç B¢Ç C¢
= (E Ç G¢) Ç (E¢È F) \ X= Y
= (E Ç G ¢ Ç E¢) È (E Ç G¢Ç F) 28. (a) Let A = {1, 2, 3, 5, 7, 8, 9}
= E Ç F Ç G¢ Construct the table for any x, y Î A such that
Þ X= Y x * y = (x. y) mod 10
25. (c) The set S = {1, 2, 4, 7, 8, 11, 13, 14} is a group under
multiplication modulo 15.
· 1 2 3 5 7 8 9
The identity element for this group is e = 1
Since, " x ÏS, 1. x and 15 = x 1 1 2 3 5 7 8 9
Now, let the inverse of 4 be 4–1. 2 2 4 6 0 4 6 8
Now, (4. 4–1) mod 15 = e = 1 3 3 6 9 5 1 4 7
Now, (4. 4) mod 15 = 1 5 5 0 5 5 5 0 5
Since, (4. 4) mod 15 = 1 7 7 4 1 5 9 6 3
\ 4–1 = 4 (This inverse is unique) 8 8 6 4 0 6 4 2
Similarly, let the inverse of 7 by 7–1 9 9 8 7 5 3 2 1
(7. 7–1) mod 15 = 1
Putting each element of set as 7–1 by trial and error, we get We know that 0 ÏA. So, it is not closed. Therefore,
(7.13) mod 15 = 91 mod 15 = 1 option (a) is true.
7–1 = 13 The identity element = 1
So, 4–1 and 7–1 are respectively 4 and 13. \ (2. 2–1) mod 10 = 1
From the table we see that 2–1 does not exist
26. (b) a
Since, (3.7) mod 10 = 1
\ 7 is the inverse of 3 and 7 Î A.
29. (d) Let n (X) denotes the number of elements of set X.
b e d Given, n (X) = x
n (Y) = y
n (Z) = z
n (E) = Number of all subsets of W
c = Number of all subsets of X × Y
= 2n(X).n(Y)=2xy
The poset [{a, b, d, e}, £ 1] is a lattice (since, every pair Therefore, the number of functions from Z to E
of element has LUB and GLB) but it is not a distributive = [n (E)]n(Z)
lattice. Because distributive lattice satisfying the = (2xy)z = 2xyz
following conditions. For any x, y, z
30. (b) Let S = {1, 2, 3,..., n} be a set of n elements number of
x Ù (y Ú z) = (x Ù y) Ú (x Ùz) ordered pairs in the smallest equivalent relation on S is
x Ú (y Ù z) = (x Ú y) Ù (x Úz) n, it must contain all the reflexive elements viz.,
where, Ù and Ú are meet and join operations but for {(1, 1), (2, 2), (3, 3), ...., (n, n)}
given poset [{a, b, c, d, e}, £ 1] and the largest equivalence relation on S has n × n = n2
b Ù (c Ú d) = b Ù a = b ordered pairs.
(b Ù c) Ú (b Ù d) = e Ú e = e 31. (d) Given, R = {x, y}, (x, z), (z, x), (z, y)} on set {x, y, z}
So, it is not distributive. (Also, element b has 2 Now, since (x, y) ÎR and (y, x) Ï R, R is not symmetric.
complements c and d, which is not possible in the Also since (x, z) Î R and (z, x) Î R, R is not anti-symmetric
distributive lattice, since in a distributive lattice, either.
complement if it exist, is always unique). \ R is neither symmetric nor anti-symmetric.
S2-32 Set Theory & Algebra

32. (c) Let the set NUMERICAL ANSWER QUESTIONS


S = {a, b, c, d, e}
Relation is subset of S × S 37. 16
There are totally 52 = 25 ordered pairs in S × S including The value of log2 log2 N is 16.
five ordered pairs (a, a), (b, b), (c, c), (d, d) and (e, e) that We know that the total no. of functions f : A ® B
must be included in order to find reflexive = (Cardinality of B) (Cardinality of A) = |B||A|
\ Total number of reflexive relation on S Now for the given questions:
S = 225–5 = 220 {0, 1}4 represents all 4-tubles on the set {0, 1},
33. (a) Here, we have onlyh one operation given. e.g. (1, 0, 1, 0,), (1, 1, 1, 0) etc.
Therefore, given options viz; ring, integral domain Total no. of 4-tubles on {0, 1} = 24 = 16
and field are ruled out. (Since each element of four tuble has 2 choice)
As it requires two binary operations. Total no. of functions f : {0, 1}4 ® {0, 1} = 216 (|B||A|)
Alternative Method A B
(i) For all a, b, Î S Set S contains all these functions, so cardinality (S) = 216
a×bÎS Now, N denotes the no. of func. g: S ® {0, 1}.
a*bÎS Þ N = |{0, 1}||s| = 22
16

i.e., 16

\ Closure property hold son set S. Þ N = 22

( ) = 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

Quick Revision Material

FUNDAMENTAL PRINCIPLES OF COUNTING


n 1
6. n. Cr 1 (n r 1) n C r 1
1. Principle of Addition : If an event can occur in 'm' ways and
another event can occur in 'n' ways independent of the first 7. n
Cr n
Cr n 1
Cr
1
event, then either of the two events can occur in (m + n)
ways. 8. n n
Cr Cn r
2. Principle of Multiplication : If an operation can be
n n
performed in 'm' ways and after it has been performed in any 9. Cx Cy x y or x y n
one of these ways, a second operation can be performed in
n n n n
'n' ways, then the two operations in succession can be 10. C0 C1 C 2 ..... Cn 2n
performed is (m × n) ways.
n n n n
nP and nC : 11. C0 C 2 ..... C1 C3 ........ 2 n 1
r r If n N and 'r' is an integer such that 0 r n ,
then we define the following symbols : 12. 2n 1
C0 2n 1
C1 ..... 2 n 1C n 2 2n
n!
(i) P(n, r) or nPr = PERMUTATIONS
( n r )!

n! Each of the arrangements, which can be made by taking, some or


(ii) C(n, r) or nC = n
r r!( n r )! . The symbol Cr is also deonoted all of a number of things is called a PERMUTATION.
RESULT - 1 : To find the number of permutations of 'n' things
n taken 'r' at a Time :
by .
r The number of ways of filling 'r' places with 'n' things

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

PATHS, CONNECTIVITY SPANNING TREES AND CONNECT OR


PROBLEMS
Path and its length in a graph (multigraph) G : A path in G
with origin v0 and end vn is an alternating sequence of vertices Let G be a graph. A subgraph H of G is called a spanning subgraph
of G if vertex set of H is same as the vertex set of G. Similarly, a
and edges of the form.
spanning tree of a graph G is a spanning subgraph of G, that is a
v0 , e1 , v1 , e 2 , v2 ,..., e n 1 , vn 1 , e n , v n tree.
Theorem.
where each edge ei is incident on vertices vi–1 and vi. The number
A graph G is connected if it has a spanning tree.
of edges, n is called length of . When there is no ambiguity, we
denote by its sequence of edges, = (e1, e2, ... en), or by its
sequence of vertices = (vo, v1, ..., vn).

BRIDGE OR CUT EDGE


K4
On removing an edge from a graph, the number of connected
components of the graph either remains unchanged or it increases
Cayley's theorem
by exactly 1. So, an edge e of a graph G is called bridge or cut
The complete graph Kn has nn–2 different spanning trees.
edge, if the subgraph G=e has more connected components than
G has. Kruskal’s Algorithm
Theorem 1 : In this algorithm, choose an edge of G which has smallest weight
among the edges of G which are not loops. This algorithm gives
Let e be an edge of the graph G and, as usual let G-e be the
an acyclic subgraph T of G and theorem given below proves that
subgraph obtained by deleting e. T is a minimal spanning tree of G.
Then (G) (G e) (G) + 1 Following steps are required.
Step 1 : Choose e1, an edge of G, such that weight of e1, (e1) is
where (a) is number of connected components of G.
as small as possible and e1 is not a loop.
Theorem 2 : Step 2 : If edges e1, e2, .... ei have been chosen, then choose an
An edge e of a grpah G is a bridge if e is not a part of any cycle edge ei+1 not already chosen, such that
in G.
(i) induced subgraph G [(e1,.....ei+1)] is acyclic, and
Theorem 3 : (ii) (ei+1) is as small as possible.
Let G be a graph with n vertices, and q edges and, let (G) Step 3 : If G has n vertices, stop after n-1 edges have been
denote number of connected components of G. Then G has chosen. Otherwise repeat step 2.
at least n- (G) edges, i.e. q n- (G)
Greedy Algorithms :
Corollary : A graph with n vertices less than (n – 1) edges can
not be connected. Greedy algorithms are essentially algorithms that proceed by
Theorem 4 : selecting the choice that looks best at the moment.
Let G be a graph with n vertices, then following three statements Prim’s Algorithm :
are equivalent. Another algorithm used for finding a minimal spanning tree is
I. G is tree Prim’s algorithm. It chooses a vertex first and chooses and edge
II. G is an acyclic graph with (n – 1) edges. with smallest weight incident on that vertex.
III. G is a connected graph with (n – 1) edges. The algorithm involves following steps.
S2-38 Graph Theory

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

Green Green Yellow

Red Blue Red Blue Red Blue


(a) (b)
Fig. Graph and two of its maximal matchings. Pink Yellow Yellow
Five colours are used Four colours are used Three colours are used
Graph Theory S2-39

Conceptual MCQs Problem Based MCQs


1. Which one of the following is true for any simple connected 6. Let G be an arbitary graph with n nodes and k
undirected graph with more than 2 vertices? components. If a vetex is remvoed form G, the nubmer of
[2009, 2 marks] components in the resultant graph must necessarily lie
(a) No two vertices have the same degree between [2003, 1 Mark]
(b) Atleast two vertices have the same degree (a) k and n (b) k – 1 and k + 1
(c) Atleast three vertices have the same degree (c) k – 1 and n – 1 (d) k + 1 and n – k
(d) All vertices have the same degree 7. How many perfect matchings are there in a complete
2. What is the chromatic number of an n-vertex simple graph of 6 vertices? [2003, 2 Marks]
connected graph which does not contain any odd length (a) 15 (b) 24
cycle? Assume n 2 [2009, 2 marks] (c) 30 (d) 60
(a) 2 (b) 3 8. A graph G = (V, E) satisfies |E| 3 |V| –6. The min-degree
(c) n – 1 (d) n of G is defined as min {degree (v)}. Therefore, min-
v V
3. K4 and Q3 are graphs with the following structure
degree of G cannot be [2003, 2 Marks]
(a) 3 (b) 4
(c) 5 (d) 6
9. How many graphs on n labelled vertices exist which have
at least (n2 – 3n)/2 edges? [2004, 2 Marks]

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

11. Which of the following graphs is not planar?


(a) (b) [2005, 1 mark]

(a) G1 : (b) G2 :
(c) (d)

5. Which of the following statements is/are true for


undirected graphs?
P: Number of odd degree vertices is even.
Q: Sum of degrees of all vertices is even. (c) G3 : (d)
[2013, 1 mark]
(a) P only (b) Q only
(c) Both P and Q (d) Neither P nor Q
S2-40 Graph Theory

12. Let G be a simple connected planar graph with 13 vertices a1


and 19 edges. Then, the number of faces in the planar
1
embedding of the graph is [2005, 1 Mark] a2
(a) 0 (b) 8
(c) 9 (d) 13 (a) (b) 3 4
a3
13. The following is the hasse diagram of the poset [{a, b, c,
d, e}, ]. [2005, 1 Mark]
a4 3
a
1 1 2 3

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

PROBLEM BASED MCQs 9. (d) Number of edges available in n labelled vertices is

6. (c) Maximum components will result after removal of a n n(n 1)


= C2 =
node, if graph G is a star graph as shown below 2

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

From figure (b)


1
14. (b) = (1 –x)–2
(1 x) 2

= 1 + 2 C1x + 3 C 2 x 2 + ........ | x |< 1


= g(0) + g(1)x + g(2) x2 + .......
g(0) = 1
2
g(1) = C1 = 2
3
g(2) = C2 = 3 C1 = 3
From figure (c)
… … …
g(i) = i + 1Ci = i + 1C1 = i + 1
15. (b) Given, V = 13, E = 19
Let R be the number of regions.
Applying Euler’s formula, (Here faces and regions
mean one and the same).
R= E – V + 2
or R = 19 – 13 + 2 = 8
From figure (d) 16. (b) Given, V = 13, E = 19
Let, R be the number of regions
Applying Euler's formula (Here faces and regions mean
one and the same)
(i) E = E – V + 2 = 19 – 13 + 2 = 8
17. (d) In topological sorting, the partial ordering of the DAG,
must be preserved i.e., if a b in the DAG, then in
the topological order, b must come after a, not before.
Consider the ordering 3 2 4 1 6 5. 1 4 in the given
12. (b) Given, V = 13, E = 19 DAG but 4 is coming before 1 in 3 2 4 1 6 5 order which
Let R be the number of regions. means that 3 2 4 1 6 5 is not a topological order of the
Applying Euler’s formula, (Here faces and regions given DAG.
mean one and the same). 18. (c) A partition P1 is called a refinement of the partitions P2
R=E–V+2 is every set in P1 is a subset of one of the sets in P2.
or R = 19 – 13 + 2 = 8
4 is a refinement of 2, 3 and 1.
a 2 and 3 are refinements of 1.
13. (b) 2 and 3 are not comparable since, neither is a
refinement of the other.
So, the poset diagram for (S , <) would be
b c d
1
[{a, b, c, d, e}, ]

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

SYMMETRIC MATRIX ORTHOGONAL MATRIX


A square matrix in which aij = aji A square matrix A is called an orthogonal matrix if AAT = ATA = I
a b c TRACE OF A MATRIX
Ex. A= b d e Let = [aij]n×n be a square matrix. Then the sum of all diagonal
c e f elements of A is called the trace of A and is denoted by tr (A).
Thus,
For symmetric matrix, AT = A
n
SKEW SYMMETRIC MATRIX tr (A) = aii
A square matrix in which aij = – aji i =1
All principal diagonal elements in skew symmetric matrix are zero.
IDEMPOTENT MATRIX
0 a b
A square matrix A is called an idempotent matrix if A2 = A.
Ex. A= a 0 c
b c 0 Properties of transpose of a matrix
In skew symmetric matrix, AT = – A ( AT )T = A
HERMITIAN MATRIX (A + B)T = AT + BT
T T
A square matrix in which aij is the conjugate complex of aji (pA) = pA
i.e. aij a ji (AB)T = BTAT(not ATBT)
T T
AA = A A
5 2 3i 4 2i
Inverse of a Matrix
Ex. 2 3i 2 5 3i
adj. A
4 2i 5 3i 0 A –1 =
|A|
a12 = 2 + 3i, a21 conjugate complex of a12 = 2 – 3i
Properties of Inverse of Matrix
SKEW HERMITIAN MATRIX
A square matrix in which aij = a ji (A–1)–1 = A
(AB)–1 = B–1A–1
Note : Principal diagonal elements of skew hermitian matrix should
be zero or pure imaginary numbers. A 1
(KA)–1 = K–1A–1 =
Orthogonal Matrix K
AAT = ATA = I 1
| A–1 | =
|A|
SINGULAR MATRIX
A square matrix is a singular matrix if its determinant is zero. adj. (AB) = (adj. B) (adj. A)
Otherwise, it is a non-singular matrix. | adj. A| = | A |n–1 where A is square matrix.
S2-46 Linear Algebra

ECHELON MATRIX and its roots is called eigen values.


A matrix is said to be echelon marix if : For eigen values ( ) of matrix A, there is a non zero vector X such
(1) Leading entry of each non zero row is 1 that AX = X is called characteristic vector (eigen vector) of A.
Relations between Eigen values and Eigen vector
(2) The number of zeros preceeding this entry 1 is larger than
number of proceeding rows. is a eigen values of a matrix A if and only if there exists a
non-zero vector X such that
0 1 2 3 4 AX = X
0 0 0 1 2 If X is a characteristic vector of a matrix A corresponding to
Ex. A = the characteristic value , then KX is also a characteristic
0 0 0 0 1
vector of A corresponding to the same characteristic value
0 0 0 0 0 . Here K is any non-zero scalar.
If X is a eigen vector of a matrix A, then X cannot correspond
Consistency of a Algebraic Equations to more than one eigen value of A.
Note : Eigen vectors corresponding to distinct characteristic roots
An equation is said to be homogeneus if b = 0 i.e. of form AX = of a matrix are linearly independent.
0.
Properties of Eigen Values
A system of equations is said to be consistent, if there are one or
more solution for the equation. Sum of eigen values is equal to sum of element of principal
diagonal of the matrix i.e.
A system of equations is said to be inconsistent, if there is no
Product of eigen values = determinant of the matrix.
solution. When we reduce a matrix A to echelon form it is called
argument matrix A*. 1
If is eigen value of an orthogonal matrix, A then is also
If p(A*) = p(A) the equations are consistent
its eigen value.
If p(A*) p(A) the equations are inconsistent.
In a homogeneous system of equation (AX = 0), 1
If is eigen value of matrix A, then is eigen value of
If p(A) = no. of unknowns (n), it has no solution –1
matrix A .
If p(A) < no of unknown (n), it has infinite solutions. n n n
If 1, 2, 3... are eigen values of matrix A, then 1, 2 , 3 ...
Consider an augmented matrix AB which is reduced to echelon n
are eigen values of matrix A .
form. Both A and AT will have same eigen values.
If p(A) p(AB), system is inconsistent Eigen values of triangular matrix is equal to its diagonal
If p(A) = p(AB) = no. of unknown (n), system is consistent with elements.
unique solution. Eigen values of real symmetrix matrix are all real.
If p (A) = p(AB) < number of unknowns (n), system is consistent Eigen values of skew hermitian matrix are purely imaginary
with infinite solutions. or zero.
Eigen Values and Eigen Vectors |A|
It is eigen value of A, then is eigen value of adj. (A).
For an n × n matrix A and a scalar , characteristic matrix of A is
A – I. The equations | A – I | = 0 is called characterisic equation
Linear Algebra S2-47

10. Which one of the following statements is TRUE about every


Conceptual MCQs n × n matrix with only real eigenvalues?
1. Let A, B, C D be n n matrices, each with non-zero [2014, Set-3, 1 Mark]
determinant. If ABCD = l, then B–1 is [2004, 1 mark] (a) If the trace of the matrix is positive and the determinant
(a) D–1 C–1 A–1 of the matrix is negative, at least one of its eigen values
(b) CDA is negative.
(c) ADC (b) If the trace of the matrix is positive, all its eigenvalues
(d) Does not necessarily exist are positive.
2. The number of different n n symmetric matrices with (c) If the determinant of the matrix is positive, all its
each element being either 0 or 1 is eigenvalues are positive.
{Note : Power (2, x) is same as 2x} [2004, 1 mark] (d) If the product of the trace and determinant of the matrix
(a) power (2, n) is positive, all its eigenvalues are positive.
(b) power (2, n 2)
(c) power (2, (n 2 + n)/2) Problem Based MCQs
(d) power (2, (n2 – n) / 2)
3. In an M N matrix such that all non-zero enteries are 11. Consider the following system of linear equations:
covered in a rows and b columns. Then the maximum
number of non-zero entries, such that no two are on the 2 1 4 x
same row or column, is [2004, 2 marks] 4 3 12 y = 5
(a) a+b (b) max (a, b) 1 2 8 z 7
(c) min [M – a, N – b] (d) min {a, b}
4. Product of two orthogonal matrices is a Notice that the second and the third columns of the
[2006, 1 mark] coefficient matrix are linearly dependent. For how many
(a) unitary matrix (b) orthogonal matrix values of , does this system of equations have infinitely
(c) unit matrix (d) none of these many solutions? [2003, 2 marks]
2 1– i (a) 0 (b) 1
5. If A = 1 i 6 , then A is [2007, 1 mark] (c) 2 (d) Infinitely many
12. How many solutions does the following system of linear
(a) skew symmetric (b) symmetric equations have?
(c) skew hermitian (d) hermitian –x + 5 y = –1
6. A skew symmetric matrix cannot be of rank x–y= 2
[2008, 2 marks]
x + 3y = 3 [2004, 2 marks]
(a) 0 (b) 1
(a) Infinitely many (b) Two distinct solutions
(c) greater than 1 (d) – 1
(c) Unique (d) None of these
7. If AB = BA, then AB is a symmetric matrix, if A and B are
13. Consider the set H of all 3 3 matrices of the type:
[2009, 2 marks]
(a) symmetric martix (b) skew symmetric matrix
a f e
(c) orthogonal martix (d) none of these
8. If there exists a non-zero minor of order r, then rank of A is 0 b d
[2009, 1 mark] 0 0 c
(a) equal to r (b) greater than or equal to r
where a, b, c, d, e and f are real numbers and abc 0.
(c) less than r (d) less than or equal to r
9. If A is a square matrix of order 4, and I is a unit matrix, then it Under the matrix multiplication operations, the set H is
is true that [2010, 2 marks] [2005, 2 mark]
(a) det (2A) = 16 det (A) (a) a group
(b) det (–A) = – det (A) (b) a monoid but not group
(c) det (2A) = 2 det (A) (c) a semi-group but not a monoid
(d) det (A + I) = 16 det A + I (d) neither a group nor a semi-group
S2-48 Linear Algebra

14. Consider the following system of equations in three real


variables x1, x2 and x3 [2005, 2 marks] 1 1 1 1
0 0 –
2x1 – x2 + 3x3 = 1 5 2 5 2
3x1 – 2x2 + 5x3 = 2 1 1
–x1 – 4x2 + x3 = 3 0 0 0 0
(c) 3 (d) 3
This system of equations has 1 1
(a) no solution 0 1 – 0 1
2 2
(b) a unique solution
(c) more than one but a finite number of solutions 20. The system of equations [2011, 2 marks]
(d) an infinite number of solutions – 2x + y + z = a
15. What are the eigen values of the following 2 2 matrix? x – 2y + z = b
x + y – 2z = c
2 1
[2005, 2 marks] have no solution if
4 5 (a) a + b + c 0 (b) a + b + c = 0
(a) –1 and 1 (b) 1 and 6 (c) a = 1, b = 1, c = – 2 (d) none of these
(c) 2 and 5 (d) 4 and – 1 2 –2 –4
16. The system of equations [2006, 2 marks] –1 3 4
x + 2y + 3z = 4 21. The martix A = is [2011, 1 mark]
1 –2 –3
2x + 3y + 8z = 7
x – y + 9z = 1 (a) involutory (b) orthogonal
have (c) nilpotent of index 2 (d) idempotent
(a) unique solution (b) no solution 22. Let A be the 2 × 2 matrix with elements a11 = a12 = a21 = +1
(c) infinite solutions (d) none of these and a22 = –1. Then,the eigen values of the matrix A19 are
[2012, 1 mark]
0 0 1
(a) 1024 and – 1024 (b) 1024 2 and 1024 2
0 1 0 ,
17. If A = the A–1 is [2007, 2 marks] (c) 4 2 and 4 2 (d) 512 2 and 512 2
1 0 0
23. The following system of equations [2013, 1 mark]
x1 + x2 + 2x3 = 1
1 0 0 0 0 1
x1 + 2x2 + 3x3 = 2
0 1 0 0 1 0 x1 + 4x2 + ax3 = 4
(a) (b)
1 0 0 1 0 0 has a unique solution. The only possible value (s) for a is/
are
0 1 0 (a) 0
(b) either 0 or 1
0 0 1
(c) (d) none of these (c) one of 0, 1 or –1
1 0 0 (d) any real number other than 5

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

25. Let the function


Numerical Answer Questions
sin cos tan
26. Consider the following system of equations :
f( ) = sin cos tan ÷ 3x + 2y = 1
6 6 6 4x + 7z = 1
x+y+z=3
sin cos tan ÷ x – 2y + 7z = 0
3 3 3
The number of solutions for this system is ___________
[2014, Set-1, 1 Mark]
where , and f ( ) denote the derivative of f 27. The value of the dot product of the eigen vectors
6 3 corresponding to any pair of different eigenvalues of a
with respect to . Which of the following statements is/are 4-by-4 symmetric positive definite matrix is
TRUE? _____________________. [2014, Set-1, 1 Mark]
28. If the matrix A is such that [2014, Set-2, 1 Mark]
(I) There exists , such that f ( ) = 0.
6 3 2
4 [1 9 5]
A=
(II) There exists , such that f ( ) 0. 7
6 3
[2014, Set-1, 1 Mark] then the determinant of A is equal to _______ .
(a) I only (b) II only 29. The product of the non-zero eigenvalues of the matrix
(c) Both I and II (d) Neither I nor II
1 0 0 0 1
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
1 0 0 0 1

is ______ . [2014, Set-2, 2 Marks]


S2-50 Linear Algebra

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

R2 R1 – (R1 + R2) (iii) Identify element is


2 1 4 : 1 0 0
1 0 0 : 5 7 0 1 0
l=
1 2 8 : 7 0 0 1
R3 R3 – 2R1 and this belongs to H as l is an upper triangular
2 1 4 : as well as lower triangular matrix.
(iv) If A H, then |A| = abc. Since it is given that abc
1 0 0 : 2
0, this means that |A| 0 i.e., every matrix
3 0 0 : 7 2 belonging to H is non-singular and has a unique
inverse.
1 The set H under matrix multiplication operation
R3 ¬ R1
3 is a group.
14. (b) 2x1 – x2 + 3x3 = 1
2 1 4 :
3x1 – 2x2 + 5x3 = 2
1 0 0 : 2 –x1 – 4x2 + x3 = 3
1 0 0 : 7 2
2 1 3 1
3
3 2 5 ,B = 2
R3 R3 – R2 A=
1 4 1 3
2 1 4 :
[A : B]
1 0 0 : 2
0 0 0 : 1 5 2 1 3 : 1
3 3 2 5 : 2
1 4 1 : 3
1 5 1 1
0, = , Here is only one value of
3 5 5
0 7 5 : 7
for infinite soln.
12. (c) –x + 5y = – 1 3 2 5 : 2
R1 ¬ R1 + 2R 3
x–y=2 1 4 1 : 3
x + 3y = 3
1 5 1 0 7 5 : 7
1 1 , 2 3 9 0 : 5
A= B= R 2 ¬ R 2 + R1
1 3 3 1 4 1 : 3

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

15. (b) Let 1and


2 are two eigen values 1 3 4
1 2+= 2 + 5...(1) (Sum of diagonal elements)
18. (c) Let A 1 3 5
1. 2 = 6 ... (2) (determinant of matrix)
From eqn (1) & (2) 1 3 4
6 R2 R2 – R1
1+ =7 R3 R3 – R1
1
2 2 1 3 4
1 +6= 7 1 1 7 1+6=0 1= 6,1
A 0 0 1
For 1 = 1, 2 = 6 & for 1 = 6, 2 =1
16. (c) Given equations are 0 0 0
x + 2y + 3z = 4
3 4
2x + 3y + 8z = 7 Minor 3 0
x – y + 9z = 1 0 1
So Rank = 2
1 2 3 : 4 19. (a) det A = |A|
2 3 8 : 7 = 5 [3 – 0] – 0 [0 – 2] + 2 [0 – 6]
Here [A : B] =
1 –1 9 : 1 = 15 – 12 = 3
3 0 –6
1 0 0 : 0 C2 C2 –2C1
0 1 0
~ 2 –1 2 : –1 C3 C3 –3C1 Adj A =
–6 0 15
1 –3 6 : –3 C4 C4 –4C1
AdjA
A –1
1 0 0 : 0 |A|
~ 2 –1 2 : –1 , R 3 R 3 –3R1
3 0 –6 1 0 –2
–5 0 0 : 0 1
0 1 0 0 1/ 3 0
(A : B) = 2 3
–6 0 15 –2 0 5
Also (A) = 2
(A : B) = (A) 20. (a) Given equations are
– 2x + y + z = a
= 2 < 3 (number of variables)
x – 2y + z = b
Hence, given equations are consistent and have infinite
x + y – 2z = c
solutions.
Augmented matrix,
0 0 1 –2 1 1 : a
17. (b) A = 0 1 0 [A:B]= 1 –2 1 : b
1 0 0 1 1 –2 : c
By R1 R2 + R3 + R1
C11 0 C22 1 C33 0
C12 0 C23 0 0 0 0 a b c
C13 1 C31 1 ~ 1 –2 1 b
C21 0 C32 0 1 1 –2 c

|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

NUMERICAL ANSWER QUESTIONS


The Given system has unique solution.

The solution is (x, y, z) = 11 19 7


26. 1 , ,
Representing the Given system in matrix form, the 5 5 5
Augmented matrix is: 27. 0
We know that for a symmetric positive definite matrix the
3 2 0 1 eigen vectors corresponding to two different eigen
4 0 7 1 values are orthogonal.
[A | B] So, their dot product is equal to zero.
1 1 1 3
However we must not that the eigen vectors corresponding
1 2 7 0 to the same eigen value (occuring more than once) need
We shall transform this matrix to echelon form as follows not be orthogonal to each other.
(to find the Rank of Above matrix) : Above mentioned result is deduced from spectral theorem
of Linear Algebra.
3 2 0 1 28. 0
4 0 7 1 R1 R3
2 2 10 18
1 1 1 3
A= 4 [1 9 5] = 4 20 36
1 2 7 0
7 7 35 63
1 1 1 3 Determinant : 2 [(– 20 × 63) – (35 × 36)] – 10 [(–4 × 63) – (36
× 7)] + 18 [(– 4 × 35) – (– 20 × 7)]
4 0 7 1 R2 R 2 4R1
= – 5040 + 5040 + 0
3 2 0 1 R3 R 3 3R1 =0
1 2 7 0 R4 R 4 R1 29. 6

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

7. A piecewise linear function f(x) is plotted using thick


Problem Based MCQs solid lines in the figure below (the plot is drawn to scale).

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

PROBLEM BASED MCQs 4. (d) f (x) = x2 – 13 = 0, f (x) = 2x


Initial value of approximation
2
= x0 = 3.5
1 If x1 be the approximation after one iteration,
1. (c) dx = 0
x By Newton-Raphson method,
1
f (x 0 )
1 x1 x0
f (x) = f (x 0 )
x
f (1) = 1
f (1.25) = 0.8 (3.5)2 13
3.5 = 3.607
f (1.5) = 0.66667 2 3.5
f (1.75) = 0.57143
5. (b) f (x) x 4 x3 x2 4
f (2) = 0.5
Simpson rule, required value interval [1, 9]
h x1 = 1, x 2 = 9
[y0 4 y1 2 y2 4 y3 y4 ]
3 f (x1 ) 5, f (x 2 ) 5447 (Positive value)
(0.25) x1 x 2 9 1
[(1 0.5) 4(0.8 0.57143) 2(0.66667)] xn 5 … (i)
3 1
2 2
= 0.69325 f(5) = 471 (Positive value)
x1 1, x 2 5
2. (a) Let f (x) = ex – 1 = 0
f (x) = ex 5 1
Now, by Newton-Raphson method xn 1 3 …(ii)
2
f ( xk ) f(3) = 41, (Positive value)
xk 1 xk –
f ( xk ) x1 1, x 2 3

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

Plotting x and f (x) 8. (a) x0 = 2


x1 = 0
1 x2 = 2
Area of region I = × (Base) × (Height)
2 x3 = 0 ..........
1 b
= × (0.09) × (0.03)
2 9. (c) x 2 dx
Area of region II a

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)

ò u.vdx = u ò v dx – ò êëçè dx ÷ø ( ò v dx )úû dx


éæ du ö ù
1 1 -1 æ x ö 27.
16. ò a2 + x2 dx = a tan çè a÷ø
u is first function, v is second function. To find first function
out of two we follow ‘ILATE’ rule.
1 1 -1 x
17. ò 2
dx =
a
sec
a
I-Inverse, L-Log function , A-Algebr aic funtion ,
T- Trignomatric function, E-Exponential function.
x x –a
MAXIMA AND MINIMA
1 æ ö
18. ò dx = log ç x + a 2 – x 2 ÷ To find maximum and minimum values of function f (x)
è ø
a2 - x2 • Find f ¢(x) and take f ¢ (x) = 0 and find the roots.
• Then find f ¢¢ (x) for each of these roots.
1 æ ö If f ¢¢ (a) > 0, f (a) is minimum value of f (x)
19. ò dx = log ç x + a 2 + x 2 ÷ dx
2 2 è ø If f ¢¢ (a) < 0, f (a) is maximum value of f (x)
a +x
If f ¢¢ (a) = 0, f (a) is not maximum or minimum value.
1 ¶F ¶F ¶F
20. ò dx = log x + x 2 - a 2 Curl F = D × F = i ´ + j´ +k´
2 2 ¶x ¶y ¶z
x –a

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

7. Consider the following two statements about the function


Conceptual MCQs
f(x) = |x| : [2007, 2 marks]
1. A cubic polynomial with real coefficients [2009, 2 marks] P : f(x) is continuous for all real values of x.
(a) Can possibly have no extrema and no zero crossing Q. f(x) is differentiable for all real values of x.
(b) may have upto three extrema and upto two zero
Which of the following is true.
crossings
(c) cannot have more than two extrema and more than three (a) P is true and Q is false (b) P is false and Q is true
zero crossings (c) Both P and Q are true (d) Both P and Q are false
(d) Will always have an equal number of extrema and zero
crossing
x1/ 3 – 2
8. The value of lim is [2008, 1 mark]
Problem Based MCQs x ®8 x – 8
1 1
2. For the function f (x) = x2 e–x, the maximum occurs when x is (a) (b)
16 12
equal to [2005, 2 marks] 1 1
(a) 2 (b) 1 (c) (d)
(c) 0 (d) –1 8 4
3. Changing the order of the integration in the double integral x - sin x
s q 9. lim equals [2008, 2 marks]
8 2 x + cos x
I =ò
0 òx / 4
f ( x, y )dy dx leads to I = òr ò p f ( x, y)dx dy. x ®¥

What is q? [2005, 1 mark] (a) 1 (b) –1


(a) 4y (b) 2 (c) ¥ (d) –¥
(c) x/4 (d) None of these 2
sin x
2 x2 – 7 x + 3 10. The lim 3 is [2010, 1 mark]
4. If f ( x) = then lim f ( x ) will be x®0 x
5x 2 –12 x – 9 x ®3
2
1 5 (a) (b) 1
(a) – (b) [2006, 1 mark] 3
3 18 1 1
(c) (d)
4 2
2
(c) 0 (d) ¥ –3
5
p / 3 it
11. If S = ò1 x dx then, S has the value [2010, 1 mark]
5. Assuming i = –1 and t is a real number ò0
e dt is
1 1
(a) – (b)
[2006, 1 mark] 3 4
1
(c) (d) 1
3 i 3 i 2
(a) + (b) –
2 2 2 2 x 1
12. The value of the quantity P, where P = ò xe dx is equal to
0
1 3 1 æ 3ö
(c) +i + + i ç1 – ÷ (d) 0
2 2 2 è 2 ø (a) 0 (b) 1 [2010, 1 mark]
æ 1
x2 ö (c) e (d)
e x – ç1 + x + ÷ e
6. lim è 2 ø is equal to [2007, 1 mark]
x ®0 x3 æ 1ö
2n
1 13. What is the value of lim ç1 - ÷ ? [2010, 2 marks]
(a) 0 (b) n®¥ è nø
6
1 (a) 0 (b) e –2
(c) (d) 1
3 (c) e–1/2 (d) 1
S2-62 Calculus

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

PROBLEM BASED MCQs


Hence, r = 0, s = 2, p = 0 and q = 4y
2. (a) f (x) = x2e–x
2 x2 – 7 x + 3 é0 ù
f ¢ (x) = x2 (– e–x) + e–x × 2x lim =
4. (b)
x ®3 2 êë 0 From úû
5 x – 12 x – 9
= e–x (2x – x2)
Putting f ¢ (x) = 0, 4x – 7 5
lim = = [By L’ Hospital rule]
e–x (2x – x2) = 0 x ®3 10 x –12 18
e–x x(2 – x) = 0
p/3 p/3
x = 0 and x = 2 are the stationary points. p / 3 it é eit ù é cos t + i sin t ù
f ¢¢ (x) = e–x (2 – 2x) + (2x – x2) (– e–x)
5. (a) ò0
e dt = ê ú
ë i û0

ë i úû
0

= e–x [2 – 2x – (2x – x2)]


= e–x (x2 – 4x + 2) é p pù
ê cos 3 + i sin 3 ú é cos 0 + i sin 0 ù
At x = 0, f ¢ (0) = e–0 (0 – 0 + 2) = 2 =ê ú–
ë i û ëê i ûú
Since, f ¢¢ (0) = 2 is > 0, at x = 0, at x = 0, we have a
minima.
1 3 1 3
Now, at x = 2 +i –1 – i + i2 é i
i 2 2 3ù
= 2 2 ´ = = – ê– – ú
f ¢¢ (2) = e–2 (22 – 4 × 2 + 2) i i i2 ë 2 2û
= – 2e–2 < 0
\ At x = 2, we have a maxima. é 3 iù
=ê + ú
ë 2 2û
8 2
3. (a) Given, I = ò0 òp / 4 f ( x, y)dx dx
æ x2 ö
Equation of the line is x = 4y. e x – ç1 + x + ÷ é0 ù
6. (b) lim è 2 ø êë 0 by L' Hospital rule úû
x ®0 3
Y-axis x=8 y = x/4 x

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

Starting value of x is zero and the final value of x is 8 e x e0 1


but we want the result of first integration in terms of y, = lim = =
x ®0 6 6 6
so that we can integrate the result with respect to y to
get the final result. So, limits are from 0 to 4 y. and
integration limit for y is from 0 to 2.
S2-64 Calculus

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

f(x) is continous for all real values of x


1 é 1 1ù 1 1
= – ê – ú = – (0 – 1) =
lim | x |= lim | x |= 0 2 ë¥ 1 û 2 2
x ® 0- x ®0+

Left derivative = lim-


x®0
| x | -0
x
= -1 12. (d)
1 x 1
P = ò xe x dx = [ x ò e dx ]0 – ò0
0
1
{ d
dx }
( x ) ò e x dx dx

| x | -0 1
=1 = [ x.e x ]10 – ò e x dx = (1.e – 0) – [ex]01
Right derivative = lim+ x
0
x®0

Þ Left derivative ¹ Right derivative = e – e + e0 = 1

\ f(x) is not differentiable at x = 0.


2
æ 1ö
2n éæ 1 ö n ù
13. (b) lim ç1 - ÷ = lim êç 1 - ÷ ú
x1/ 3 – 2 é0 ù n®¥ è nø n®¥ ëè nø û
8. (b) Given, lim êë 0 Form úû
x ®8 x – 8

= (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

15. (b) The sin (x) graph is as follows:


ì x + 3 if x£3
(c) f (x) = í
îx - 4 x>3

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+

Option (c) is false.

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

The integral factors are 1, 2, 19, 38, 53, 106, 1007


22. 4 = ( -p cos p + sin p - 0) -

2p éë( -2p cos p + sin 2p ) - (p cos p + sin p)ùû


ò | x sin x |dx
= p + 0 - [ -2p + 0 - (p + 0)] = kp
0

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

Quick Revision Material


NUMBER SYSTEM On reading the remainders from bottom to top, the decimal
(444)10 ® (674)8. Now, fractional conversion
Binary-Decimal Conversion Multiplication Generated Integer
Example : Find the decimal equivalent of binary number 11111. 0.499 ´ 8 = 3.992 3
Solution:
The equivalent decimal number is, 0.992 ´ 8 = 7.936 7
= 1 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 1 × 20 0.936 ´ 8 = 7.488 7
= 16 + 8 + 4 + 2 + 1 = ( 31 )10 0.488 ´ 8 = 3.904 3
Decimal-to Binary Conversion The process gets terminated when significant digits are
acquired. Thus, octal equivalent is (444.499)10 = (674.3773)8
Example : Express the 25.5 decimal number in the binary form.
Solution: Octal-Binary Conversion
Integer Part: It can be explained through the following example: To convert
Thus, (25)10 = (11001)2 (377)8 into binary, replace each significant digit by its 3-bit binary
equivalent.
2 25 (377)8 = 3 7 7
2 12 — 1 = 011 111 111
Thus, (377)8 = (011111111)2
2 6 —0
Binary-Hexadecimal Conversion
2 3 —0
e.g., (10100110111110)2 = (0010 1001 1011 1110)2 = (2 9 B E)16 × 1
2 1 —1 Hexadecimal-Binary Conversion
2 0 —1 It can be explained through an example. To convert (1D5)16 into
binary, replace each significant digit by its 4-bit binary equivalent.
Read down to up (1D5)16 = 1 D 5
Fraction part = 0001 1101 0101
Thus, (1D5)16 = (000111010101)2
0 . 5
´ 2 DIGITAL LOGICAL GATES
1 . 0 OR Gate
Table
i.e., 0.510 = 0.12
Therefore 25.510 = 11001.12 Inputs Output
Decimal-Octal Conversion R= P+ Q
P Q
This can be achieved by dividing the given decimal number 0 0 0
repeatedly by 8, until a quotient of 0 is obtained. : 0 1 1
Example : Convert conversion (444.499)10. 1 0 1
Solution :
Division Generated Remainder 1 1 1
444 / 8
P
55/ 8 ® 4 R=P+Q
Q
6/8 ® 7
0/8 ® 6 Fig.
OR: Gate
OR Gate
S3-2 Digital Logic

AND Gate Demorgan’s Theorems :


Table
• PQ = P + Q
Inputs Output • P + Q = P.Q
R=P.Q
P Q HalfAdder
0 0 0
Half Adder is used for the addition of two bits.
0 1 0
Sum = A Å B
1 0 0
Carry = A.B
1 1 1
Truth Table
Table
P
R=PQ A B SUM (S) CARRY (C)
Q
0 0 0 0
Fig. : AND Gate 0 1 1 0
NOT Gate (Inverter)
1 0 1 0
Table
1 1 0 1
Inp ut P Ou tp ut R
0 1
1 0 A
Sum
B
P R=P
Fig. : NOT Gate
NAND Gate Cout
Table
Inputs O utpu t Fig. : Half adder
R FULL ADDER
P Q
0 0 1 A full adder is a device capable of adding three bits.
0 1 1
Sum = A Å B Å C
1 0 1
Carry = AB + BC + CA
1 1 0
Truth Table
P Table
R=P.Q
Q
A B Carry-in (C in ) SUM (S) CA RRY (C)
Fig. : NAND Gate 0 0 0 0 0
NOR Gate 0 0 1 1 0
Table
0 1 0 1 0
Inputs O utpu t 0 1 1 0 1
R
P Q 1 0 0 1 0
0 0 1
1 0 1 0 1
0 1 0
1 0 0 1 1 0 0 1
1 1 0 1 1 1 1 1

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

Fig. : Four variable


DIGITAL IC FAMILIES 1 input
signal
Specification Table for Logical Family Devices Demultiplexer n output
signals
S pecification RTL TTL CMOS
Po wer s u pp ly 3.8 Vo lts +5 Vo lts 3-15 Vo lts
Pro p agatio n d elay 12 n s ec 15 n s ec 25 n s ec Fig. : Block diagram of demultiplexer
Po wer Dis s ip ation 30-100 mW 100 mW 10 nW Table
No is e M arg in 0.2 Vo lts 0.4 Vo lts 45% o f VD D
Data Control Control
Fan Ou t 4 10 >50
input input Input Output
MULTIPLEXER D S1 S2 Y3 Y2 Y1 Y0
A Multiplexer is a Data selector, which gets several input signals D 0 0 0 0 0 D
to the single output. D 0 1 0 0 D 0
Table
D 1 0 0 D 0 0
Input Input Output D 1 1 D 0 0 0
S1 S2 Y
0 0 D0
0 1 D1 Data
input S1 S0
1 0 D2
D
1 1 D3

From table output, Y = S1S2 D0 + S1S2 D1 + S1S2 D 2 + S1S2 D3 Y0


Y1
m select signals
Y2
Y3

Fig. : 1-to-4 demultiplexer

n input FLIP FLOPS


Multiplexer 1 output
signals • It is an electronic circuit that has two stable states & can
signal
be used to store state information. It is basically a bistable
multivibrator or latch or toggle.
(a) S-R (Set-Reset) Flip-flops
Fig. : Block diagram of multiplexer

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

S
Fig. : Clocked S-R Flip-flop CLK

Q n +1 = Sn + R n¢ Q n 2
R 4 Q

Table S-R Flip-flop Truth Table (Clear)


(a) Using NAND gates
Q S R Q(t+1) Fig. : D-flip-flop Using NAND gates
0 0 0 0
0 0 1 0 D Q
0 1 0 1
0 1 1 Indeterminate CLK Q
1 0 0 1
1 0 1 0 Fig. : Logic symbol
1 1 0 1
Table
1 1 1 Indeterminate
CLK Input (D) Output (Qn +1)
The disadvantage of S-R flip-flop is for S = 1, R = 1 output 1 0 0
cannot be determined. This can be eliminated in J-K flip-
1 1 1
flop.
0 X No change
J Q (e) T Flip-flops
• It is also known as trigger or toggle flip flop.
K Q
T Q
Fig. : Graphic symbol of J-K flip flop
(c) J-K Flip-flops : CLK Q
The Master-Slave JK Flip-flop
The Master-Slave Flip-Flop is basically two gated SR flip- Fig. : Block diagram of T flip flop
flops connected together in a series configuration with the Table
slave having an inverted clock pulse. The outputs from Q
and Q from the “Slave” flip-flop are fed back to the inputs CLK Input (T) Output (Qn +1)
of the “Master” with the outputs of the “Master” flip-flop 0 0 0
being connected to the two inputs of the “Slave” flip-flop. 0 1 1
This feedback configuration from the slave’s output to the 1 0 1
master's input gives the characteristic toggle of the JK flip- 1 1 0
flop as shown in fig.
Digital Logic S3-5

CO UN TERS output so generated by sample and hold circuit is used to convert


A counter is a special kind of register, designed to count the data into digital signals by means of analog-to-digital convertor
number of clock pulses arriving at its input. The input to this (A/D).
counter is a rectangular waveform called clock. Each time the S
clock signal changes state from low to high, the counter will add Vi V0
one (1) to the number stored in its flip flop.
C
The counter can be used as an instrument for measuring time
and therefore frequency. There are basically two different types
of counters Synchronous and Asynchronous.
(a) Synchronous counters: In a ripple counter each flip - flop (a) Schematic diagram
has a delay time and these delay times are additive.
Therefore the total "settling" time for the counter is equal V0 -
V0
to the delay time multiplied by total number of flip - flops. Vi +
C LM 102
This problem can be overcome by the use of a synchronous C
or parallel counter. Here every flip-flop is triggered in Control gate
synchronism with the clock.
(b) Practical diagram
Fig. : Sample-and-hold circuit
Q3 J3 Q2 J2 Q1 J1 Q0 J0 High MULTIVIBRATOR
Q3 K3 Q2 K2 Q1 K1 Q0 K0
• It is basically a two-stage switching electronic circuit in
CLR which the output of the first stage is fed to the input of the
Fig. : Synchronous counter second stage & vice versa.
(b) Asynchronous counter (ripple counter): When the output • Here, output of two stages are complement to each other.
of a flip-flop is used as the clock input for the next flip-flop • It is of three types: astable, monostable & bistable.
we call the counter as a ripple counter or asynchronous (a) Astable Multivibrator :
counter. • It is also known as free running multivibrator.
• It generates square waves without any external
triggering pulse.
• This multivibrator does not have stable states i.e.,
GET GET GET
have two quasi stable states where it switches back &
forth from one state to each other.
CLR CLR CLR +VCC

R
RC1 C 1 R2 C2 Rc2
1
VC1 + - - + Vc2
Q1 Q2

Fig. : Astable Multivibrator


(b) Monostable Multivibrator :
8
• It is also known by the name of monoshot or one-shot
Fig. : Asynchronous counter multivibrator or univibrator.
• This multivibrator has one stable state & one quasi-
ANALOG TO DIGITAL CONVERTER (A/D) stable state.
• It is a device that converts a continuous physical quantity
(usually voltage) to a digital number that represents the +VCC
quantity’s amplitude.
RC1 R C1 R
DIGITAL TO ANALOG CONVERTER IC1 C IR2 c2
VC1 + - V
R1IR1 c2
• It involves transforming the binary values 0’s & 1’s into an Q1
analog signal which represents the binary data. C2 R2 IB2 Q2
- V
SAMPLE & HOLD CIRCUIT Input + BB
Sample & hold circuit is a device that is generally used to convert trigger
analog signal into its digitised form i.e. when an analog signal is pulse
applied at the input terminal of sample & hold circuit, it assigns Fig. : Monostable Multivibrator
a digital level to every pulse with the help of the switch. The
S3-6 Digital Logic

(c) Bistable Multivibrator 4-bit Serial-in to Parallel-out Shift Register


• It is also known as flip flops or Eccles-Jordan circuit. 4-bit Parallel Data Output
• This multivibrator has two stable states.
QA QB QC QD
+VCC
D Q D Q D Q D Q
Serial
I1 I2 FFA FFB FFC FFD
C1 C2
Data in

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

SCHMITT TRIGGER Clock


• It acts as a wave shaping circuit where a square wave can
be generated from a sine wave input. 4-bit Parallel-in to Serial-out Shift Register
1 Q
DE CO D ER mux D Q mux D Q mux D Q mux D Q
Serial
FFA FFB FFC FFD Data out
Þ Decoder is combinational ckt which have many i/p
and many o/p.
Þ It is used to convert binary data to other code (binary
Clock
to ****)
PD PC PB PA
THE SHIFT REGISTER 4-bit Parallel Data Input

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)

CLK Let A’ represents the complement of A. The correct output


sequence on Y over the clock period 1 through 5 is
f D Q D Q (a) A0A1A1' A3A 4 (b) A0A1A'2A3A 4
CLK
(c) A1A 2A'2A3A 4 (d) A1A'2A3A 4A5'
(b) 39. Consider the following circuit:
X

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

(a) Q+R (b) P+Q


(a) bd (b) b d + bc
(c) P + R (d) P + Q + R
64. The minimum number of D-flops needed to design a (c) b d + abcd (d) b d + bc + cd
mod-258 counter is [2011, 1 Mark]
(a) 9 (b) 8 70. The smallest integer that can be represented by an 8-bit
(c) 512 (d) 258 number in 2’s complement form is [2013, 1 Mark]
65. Which one of the following circuits is not equivalent to a (a) –256 (b) –128
2-input XNOR (exclusive NOR) gate? [2011, 1 Mark] (c) –127 (d) 0
71. In the following truth table, V = 1 if and only if the input
(a) (b)
is valid. [2013, 1 Mark]

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

6. (c) The answer can be easily made out from the


PROBLEM BASED MCQs
following figure :
1. (a) (43)10 ¾¾ ®(101011) 2 C
1’s complement of (101011)2 is
2’s complement of (101011)2 is
X
0 1 0 1 0 0
The first pulse is 1 since, X = 1 and D1 = 1
0 1 0 1 0 0 This pulse will drop to 0 due to setup times 20 ns
+ 1 and 0 hold times.
7. (c) Lets go step by step.
0 1 0 1 0 1 1. 539 in binary is 1000011011.
So, 2’s complement of (43)10 is 2. Taking complement to get 1’s complement we
get 0111100100.
0 0 0 1 0 1 0 1 3. Adding 1 to get 2’s complement we get
2. (c) This is solved by heuristics and by not lengthy 0111100111.
computations. 4. Putting signed bit, i.e., 1 in MSB we get
Since, xy = 0 and from the last equation, we get 10111100111.
z¢w¢ = 0 5. Since, these are 11 bits and hexadecimal needs
Therefore, only option (c) satisfies both these, i.e., to make group of 4 bits, we have to add an extra
xy = 0 and z¢w¢ = 0 bit.
3. (b) xywz 6. Since, signed bit is 1 we pad it with 1 only in
wz wz wz wz
starting.
xy 0 X 0 0 7. We get finally 110111100101.
xy 0 X 1 1 8. This is DE5 in hexadecimal.
xy 1 1 1 1 8. (c) 1 a 0 a
2:1 2:1 1
MUX MUX
xy 0 X 0 0 0 b c b c
(f (x, y, w, z) x1 x2
f = xy + y · w Using formula given, i.e., output = ac¢ + bc
4. (a) For first MUX, we get
P Q1 g = 1 × x1¢ + 0 × x1 - x1¢
Now,
For second MUX, we get f = x1¢ x ¢2 + x1x 2
J K D
9. (c) x1 g
g = x1 ×1 + x1.0
1 0 1
g = x1 .....(1)
1 0
Clock
In J-K flip-flop, when J = 1 and K = 1 there is race x2 f f = x 2g + x 2 x1
around condition in which output continuously 0 g From eqn. (1)
toggles. At the instant, the clock cycles output of J-
K flip-flop becomes 1 but the clock becomes zero so 1 x1 f = x 2 x1 + x 2 x1
in D flip-flop, output becomes zero. Thus, the final 10. (b) Lets elaborate the given K map
output is 1, 0 form J-K flip-flop and D flip-flop wx
respectively. yz 00 01 11 10
5. (a) wx w x wx wx wx 00 0 1 1 0
yz 00 01 11 10
01 × 0 0 1
y z 00 0 X 0 X
11 × 0 0 1
y z 01 X 1 X 1
10 0 1 1 0
y z 11 0 X 1 0

y z 10 0 1 X 0 With the described Kmap, following is concluded.


For minterm (SOP), f = xz¢ + zx¢
F = yz + y × x
Digital Logic S3-17

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

18. (c) The maximum difference can be obtained only if we Logic 1


subtract the minimum value from the maximum value. Logic 0
Difference = Maximum value – Minimum value
The floating point number represented as
ìï(-1)s (1 + m ´ 2-9 )2e -31, if the exponent ¹ 111111 Time Transitions
í 1 ns Transition from logic 0 to logic 1
ïî0, otherwise 2 ns Transition from logic 1 to logic 1
The value of e = 111110 = 62 4 ns Transition from logic 1 to logic 0
Maximum value
Therefore, total number of transitions form 0 ns to 10 ns
= (-1)s (1 + (m + 1) ´ 2 -9 )2e - 31 is 3.
22. (d) x¢y¢ + xy + x¢y = xy + xy + xy
Minimum value = ( -1)s (1 + m ´ 2 -9 )2e- 31 = x¢(y + y¢) + xy
= x¢ + xy (as q + q¢ = 1)
Difference = (-1)s (1 + (m + 1) ´ 2 -9 )2e - 31 = x¢ + y (as q + q¢r = q + r)
23. (c) Diagramatic representation of such as SR latch is
= (-1)s (1 + m ´ 2 -9 )2e -31
Putting the value of e = 62 and solving, we get S
Q
231 × 2–9
22
= 2 which is the maximum difference.
19. (c) (zk + nk = k)
zk – nk = 2 the output at the kth and all subsequent
clock ticks is 10. Q¢
nk – zk = 2 In this case, the output at the kth and R
all subsequent clock ticks is 01. Now, lets construct a truth table with regards to the
Þ zk + n k = 2 circuit diagram above with S and R as input
No. of transition states = 23 – 1 = 8 – 1 = 7
S R Q
20. (a) 1. For product of sums,
Lets draw a K map to find out number of literals. 0 0 Q = Q¢ = 1
zw
1 0 1
xy 00 01 11 10 0 1 0
00 × 1 0 1 1 1 Indeterminate
01 0 1 × 0 Therefore, we get Q = Q¢ = 1
24. (d) These types of problems are to dealt directly using
11 1 × × 0
the options provided. Hence, by converting all the
10 × 0 0 × options we get the answer as (d).
Lets eleborate
No. of literals
The value of 73x if x = 8
= (z + w + x) (z ¢ + w¢) (z¢ + y¢)(x¢ + y)
738 = 7 × 81 + 3 × 8^0
Therefore, total number of literals in product of sums
= 56 + 3
is 11.
= 59
2. For sum of products,
The value of 54Y if y = 11
Lets draw a K map to find out number fo literals.
5411 = 5 × 111 + 4 × 110
zw = 55 + 4
xy 00 01 11 10
= 59
00 × 1 0 1
Therefore, x = 8 and y = 11
01 0 1 × 0 25. (a) The exponent value is 10.0 and therefore evaluating
11 1 × × 0 the above expression taking the exponent values to
be 10 are 9.51 and 10.0.
10 × 0 0 × 26. (b) Now, input is 4 bit and output is 1 bit when the input
No. of literals is greater than 5. Now, a point ot understand is that
= wy + xz¢w¢ + x¢z¢y¢ + w¢x¢y¢ output can be 1 bit till 9 as after that it will become
Therefore, total no. of literals in sum of products is 2 digit (10, 11, 12, 13, 14 and 15)
9. This implies output will be 1 in case of 5 to 9 which
So, the minimum number of literal counts is (11, 9). are represented as follows
21. (c) From the question, we have
0101 (5)
d1 = 2ns and d2 = 4ns
A B
0110 (6)
0111 (7)
d1 = 2 d2 = 4
Now, considering the fitgure below, we will follow 1000 (8)
the transitions that occured. 1001 (9)
Digital Logic S3-19

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

34. (b) Let the output function be S. We need to calculate


the output function as if helps us to know which Clock X Q=0 Q=1 Ai Y
statement is true, will compute teh 2’s complement of 0 1 0 1 A0' A0'
the number inserted as an input. To find the output 1 1 0 1 A1' A0'
funciton, transition diagram of the finite state
2 0 0 1 A2' A1
machine is to be constructed.
Transition diagram is as below 3 1 0 1 A3' A1'
4 1 0 1 A4' A3
0 1
5 0 0 1 A5' A4'
Q0 (0) Q0, 0 Q0, 1
Q1 (1) Q1, 1 Q1, 0 Therefore, the correct sequence on Y over clock period
and hence the output function 0 through 5 is A¢0 , A 0¢ , A1, A1¢ , A 3 , A¢4

0 1 And clock period 1 throug 5 is A 0 , A1, A1¢ , A3 , A 4


39. (c) As in the circuit, lets draw how the input is fed and
0 0 1 output is obtained.

1 1 0 F = XY × YZ Þ XY + YZ = F

S computes the 2’s complement, and therefore Þ ( )


XY Z + Z + YZ X + X = F ( )
option (b) is true.
As X + X = 1
35. (d) As shown in the diagram, the inputs are A and X. Þ F = XYZ + XY Z + XYZ + XYZ
Lets first find out the equation obtained at D.
D = AX + X¢ Q¢ The K map for the above is
With this now we need to find out the transitions. yz
x 00 01 11 10
Q0Q1 State tranitions
00 11
0 1
11 01
01 10
10 00
1 1 1 1
00 11
11 01
01 10 Therefore, f is independent of Z.
10 00 40. (c) Let
Continues… Continues…
A = a n -1a n -2 ....a 0
The transitions thus obtained are
B = b n -1bn -2 ....b0
00 ® 11 ® 01 ® 10
C = cn -1cn -2 ....c0
Also, let the overflow condition be 0.
36. (c) As in the option (c), there are two D flip-flops.
Now, if the left most D flip-flop is activated that is the Then, 0 = a 'n -1 b 'n -1 cn -2 + a n -1bn -1c 'n -2
clock value is set to 1 then the clock value of the right Also, it is known that cn–1 is Cout
most D flip becomes 0. Therefore, it delays the phase f Hence, 0 = Cout Å Cn -1
by 180°
37. (b) Lets find out the property of the numbers whose i.e., Overflow condition is 0 = Cout Å Cn -1
gray value is displayed. 41. (a) The problem is solved in two steps:
Now, (n + 1) is a 5 bit. Hence, in decimal, it ranges 1. Draw the K map
from 0 to 31. 2. Check the cube covers from the different options
Therefore, the correct option is 1. K map is as follows
g1(h3h2h1h0) = (4, 9, 10, 11, 12, 13, 14, 15) wx
For (n + 1) modulo 16. 00 01 11 10
38. (a) Considering the inputs in the diagram, the equation yz
for D flip-flop comes out to be 00 0 0 0 0
D = ( Ai X ') ' ( X 'Q') '
01 0
( ) 1 1 0
D = A i' + X + X + Q
11 1 1 1 0
D = Ai' + X + Q
Now, we have to check the response over different clock
10 0 0 1 0
period that Clock period 0 through Clock period 5.
Digital Logic S3-21

2. Checking the cube covers of the options


Z f1
Cube covers of option (a) is as below:
0 x
w'xz 0101 (5) f1 = zx + zy ...(i)
1 y
wxy' 1101 (13)
xyz 0101 (5) y f
wyz 0111 (7) 0 f1
f = yf1 + yx ...(ii)
1011 (11) 1 x
Therefore, option (a) satisfies the condition of differing From eqs. (i) and (ii)
by one bit at least one member of each of other pairs. f = y(zx + zy) + yz
42. (a) Given are a2a1a0 and b2b1b0. f = xy z + yz + xy
f = yz + xy z + xy(z + z)
a2 a1 a0 f = yz + xy z + xyz + xyz
0 0 0 f = yz + xy z + xyz + xyz + xyz
0 0 1 f = yz + xz(y + y) + xy(z + z)
0 1 0
f = yz + xz + xy
0 1 1 44. (b) yz
1 0 0 yz yz yz yz
wx
1 0 1
1 1 0
wx 1 1
0 1 3 2
1 1 1
wx
b2 b1 b0
1 1
4 5 7 6
0 0 0
0 0 1 1 1
0 1 0 wx 12 13 15 14

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

When the counter reaches 5, the counter is cleared to 0. 1´ 9 + 2 ´ 3 + 1 = 9 + 6 + 1 = 16 = 3 + 1 = (11)r


48. (b) A single one bit adder requires gate = 5 AND gates or 54. (d) Lets make a K map for the problem
2 OR gates in two level logic.
Now, given is 4 bit adder with outputs ab
cd 00 01 11 10
= S3, S2, S1, S0 and C4
This 4 bit adder would require two one bit adders and
therefore 2 × (5 AND gates and 2 OR gates) 00 1 1 1
= 10 AND gates and 4 OR gates
49. (c) In the implementation of n variable functions, following 01 x
is required.
1. Data selector with n – 1 select inputs x
11
2. 2n –1 data inputs
Therefore, the minimum size of multiplexer is 2n – 1 line
to 1 line. 10 1 1 x
50. (d) Let’s construct a truth table to find the validity of the
given statements.
X Y Z=X *Y Y* Z X*Z X*Y*Z
0 0 1 0 0 1
(
= a b + a d + cd b + cd b = a b + a d + d b c + c )
0 1 0 0 1 1 = ab + ad + db ë (
éQ c + c = 1ù
û )
1 0 0 1 0 1
55. (d) We have the given value as 0 × 00000000
1 1 1 1 1 1 0000 0000 0000 0000
This depicts that the statements (P), (Q) and (R) are 0000 0000 0000 0000
valid and therefore, the option (d) is correct.
51. (a) We are given with the function 0
Hence, the IEEE floating point representation of
f ( w, x, y, z ) = å ( 0, 4,5, 7,8,9,13,15 ) 0 × 00000000 is the special value + 0.
The best to find solution in such type of question is to
assign a value and the match the output. Let w = x = y 56. (a) (P + Q)(P.Q + P.R)(P.R + Q)
= z = 1. Then the values of the equation becomes Þ (P.Q + P.R + P.Q + P.Q.R)(P.R + Q)
(P) x’y’z’ + w’xy’ + wy’z + xz
= 0.0.0 + 0.1.0 + 1.0.1 + 1.1 = 1 Þ (P.Q + P.R + P.Q.R)(P.R + Q)
(Q) w’y’z’ + wx’y’ + xz = 0.0.0 + 1.0.0 + 1.1 = 1
(R) w’y’z’ + wx’y’ + xyz + xy’z Þ P.Q + P.R.Q + P.Q.R
= 0.0.0 + 1.0.0 + 1.1.1 + 1.0.1 = 1 Þ P.Q(1 + R) + P.R.Q = P.Q + P.R.Q
(S) x’y’z’ + wx’y’ + w’y = 0.0.0 + 1.0.0 + 0.1 = 0
Therefore, (S) is not equivalent to f. Þ P.Q(1 + R) = P.Q
52. (c) We need to build the table for the given logic circuit. 57. (b) We have to construct the diagram to get the output
f1 f2 f f1f2 f2
1 0 1 1 x A (A + C)
4 1 0 0 C
5 1 0 0
((A + C) + (B + D))
6 1 1 1 x x
7 1 0 0 B
8 1 0 1 1 1 D
(B + D)
15 0 1 1 x = (A + C) (B + D)
= AB + C \ (C = D)
Digital Logic S3-23

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

T=1 Next state compliment of present state 0 = A Å B = A + AB = ( AB + AB) = XNOR


For input T = 1, output Q0 goes to next T flip-flop as a 66. (b) P + Q + R = 011
clock. Since both are complimented so the output
becomes 11. Hence, the first sequence after 00 is 11. P + Q + R = 010
Next sequence after 11 P + Q + R = 001
The very next second Q1 remains 1 and Q0 becomes 0.
The next sequence becomes 10.
Similarly, the next sequence after 10 is 01 and the fourth
S3-24 Digital Logic

71. (a) This is a 4 × 2 priority encoder, where the highest


P Q R F
priority bits (Inputs) are to the right and “X”
0 0 0 1 indicates an irrelevant value.
0 0 1 0 72. (d) Exclusive NOR of x and y = xy + x¢y¢
0 1 0 0
x Å y = xy + x¢y¢
0 1 1 0
\ option (a) xy + x¢ y¢ represents exclusive NOR of
1 0 0 1
x and y.
1 0 1 1 Evaluating (b)
1 1 0 1 x Å y¢
1 1 1 1 Þ x Å y¢ = x¢ y¢+ xy (Q a Å b = a¢b + ab¢)
Q R QR QR QR Þ x Å y¢ = x Å y
P 1 0
Evaluating (c)
0 0
i.e., P + QR x¢ Å y
P 1 1 1 1 Þ x¢ Å y = x¢y¢ + xy
67. (a) The truth table is given by Þ x¢ Å y = x Å y
X Y f(X, Y) Evaluating (d)
0 0 0 x¢ Å y¢
Þ x¢ Å y¢ = x¢y + xy¢
0 1 0
\ It is observed x¢ Å y¢ ¹ x Å y
1 0 1
So, (d) i.e., x¢ Å y¢ is not equivalent to exclusive NOR
1 1 1 of x and y.
One method to find out Boolean function’s work. It 73. (a) The Given Boolean expression:
works as same as the X works. F (P, Q, R, S) = PQ + PQR + PQRS
Another method is to draw K-map for this Boolean The K-Map for the above expression is as follows:
function.
PQ
X
Y 0 1 RS 00 01 10
0 0 1 00 1
f(X, Y) = X
1 0 1 01 1 1

68. (a) The decimal value 0.5 is represented in binary as 11 1 1


follows: 10 1 1
(0.5)10 = (0.1)2 and (0.1) º (1) ´ 2 - 1 The Minterm combination for the above K-Map is as
In normalized form, left bit to the decimal point should follows:
be 1.
PQ PQ
0.1 º 1.0 ´ 2 -1 RS 00 01 10 RS 00 01 10
Here, exponent value º (– 1). 00 1 00 1
Mantissa value = all 0’s
and the left bit to the decimal point is not written in the 01 1 1 01 1 1
floating point format. 11 1 1 11 1 1
69. (b) ab 10 1 1 10 1 1
cd ab ab ab ab
Minterm: PQ Minterm: QR
cd 1 X X 1
PQ
cd X 1 RS 00 01 10
cd 00 1
01 1 1
cd 1 X
11 1 1
Fig. : K-Map for f 10 1 1
F =d.b+c.b Minterm: QS
70. (b) The general formula for 2’s complement So, the Minimal sum of products form of F is as
representation of n-bits is follows:
(– 2n–1 to 2n–1 – 1) PQ + QR + QS
For n = 8, the maximum negative number is
– 28–1 = – 27 = – 128
Digital Logic S3-25

74. (a) PQ + QR + PQR P1 = QS


The given diagram is: P2 = QS
0 \ F (P, Q, R, S) = P1 + P2
= QS + QS
1
78. (c) y = xb + xa
R x is working as a selection line.
Two input lines are a and b
R
S1 S0 \ function F (x, y, a, b) can be implemented using
(2 × 1) multiplexer as follows.
a I1
P Q 2×1
y
This question can be easily solved by comparing it to MUX
the standard diagram of the multiplexer: I2
b
0 ® I0 0

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

Name Mnemonic Operation


Load LD Transfers data from a memory location
to a processor register
Store ST Transfers data from a processor register
to a memory location
Move MOV Transfers data between register-register
OR between Memory-Register
Exchange XCH Swaps data between register-register
OR between Memory-Register
Input IN IN read from a part.
Output OUT OUT write to part.
Push PUSH Pushes the data from a register onto
a memory stack
Pop POP Pops the data from a memory stack
and store it onto a register
Eight Addressing Modes for the Load Instruction

Mode Assembly Convention Register Transfer


Direct address LD ADR AC ¬ M[ADR]
Indirect address LD @ADR AC ¬ M[M[ADR]J
Relative address LD $ADR AC ¬ M[PC + ADR]
Immediate operand LD #NBR AC ¬ NBR
Index addressing LD ADR(X) AC ¬ M[ADR + XR]
Register LD R1 AC ¬ R1
Register indirect LD (R1) AC ¬ M[R1]
Autoincrement LD (R1) + AC ¬ M[R1], R1 ¬ R1 + 1

Abbreviations used has meaning as follows : ADR=address, 2. Data Manipulation Instructions:


NBR=number/operand, X=index register, AC=Accumulator, Data manipulation instructions perform various operations
R1=General purpose register, @=indirect addressing mode, on data and provide the computational capabilities for the
$=relative address to the PC, computer. We can further classify the Data Manipulation
Instructions in following 3 types :
S3-28 Computer Organisation & Architecture

I. Arithmetic Instructions: III. Shift Instructions:


It includes addition, subtraction, multiplication, and division. These instructions are used to move the bits of a Memory
Following table shows various arithmetic instructions in a Word or register in a particular directions. Shift instructions
typical computer: have many variants like : logical shifts, arithmetic shifts, or
Typical Arithmetic Instructions circular shifts. In either case the shift may be to the right or
Name Mnemonic to the left. Various shift instructions in a typical computer
Increment INC are as follows :
Decrement DEC Typical Shift Instructions
Add ADD
Name Mnemonic
Subtract SUB
Multiply MUL Logical shift right SHR
Divide DIV Logical shift left SHL
Add with carry ADDC Arithmetic shift right SHRA
Subtract with borrow SUBB Arithmetic shift left SHLA
Negate (2’s complement) NEG Rotate right ROR
II. Logical and Bit Manipulation Instructions: Rotate left ROL
Logical instructions include bitwise AND, bitwise OR etc.
Rotate right through carry RORC
Logical and bit manipulation instructions in a typical
Rotate left through carry ROLC
computer are as follows :
Typical Logical and Bit Manipulation Instructions (a) Logical Shifts :
Name Mnemonic These instructions insert 0 at the last bit position and
shift all the bits of the memory word in specified
Clear CLR
direction by one bit position.
Complement COM
AND AND (b) Arithmetic shifts :
OR OR These instructions are meant for signed-2’s
Exclussive-OR XOR complement numbers. These instructions preserve the
Clear carry CLRC sign bit in the leftmost position.
Set carry SETC (c) Circular Shifts :
Complement carry COMC These instructions treat the bit sequence as a circular
Enable interrupt EI list. It means that the rightmost bit position is treated
Disable interrupt DI adjacent to the leftmost bit.

ADDRESSI NG MO DES
All addressing modes with Examples

Addressing mode Example instruction Meaning When used


Immediate Add R4, #3 Regs [R4] ¬ Regs [R4] + 3 For constants.
Direct or Add R1, (1001) Regs [R1] ¬ Regs [R1] Sometimes useful for accessing
absolute + Mem [1001] static data; address constant may
need to be large.
Memory Add R1, @(R3) Regs [R1] ¬ Regs [R1] If R3 is the address of a pointer P,
indirect + Mem[Mem[Regs[R3]]] then mode yields *p.

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

MEMORY INTERFACE INPUT/OUTPUT INTERFACE


Memory chips may be connected to the CPU as follows : I/O interface provides a method for transferring
information between CPU and external devices. The I/
O interface resolves the differences that exist between
CPU the cpu and each External device. The major
Address bus
644444744444 8 differences are:
16-11 10 9 8 7–1 RD WR Data bus 1. Conversion of signals between CPU and external
devices.
2. Synchronization issues due to the speed
difference between CPU(extremely faster) and
Decoder external devices (very slow).
3 2 1 0 3. Data codes and formats in External devices differ
CS1 from the word format in the CPU and memory.
CS2 128 × 8 4. Difference in operating modes external devices
RD Data with each other.
WR RAM 1 CACHE
AD7 Processor does all memory operations with cache.
• Miss - If requested word is not in cache, a
CS1 block of words containing the requested
CS2 128 × 8 word is brought to cache, and then the
RD Data processor request is completed.
WR RAM 2
AD7 • Hit - If the requested word is in cache, read
or write operation is performed directly in
cache, without accessing main memory.
CS1 • Block - minimum amount of data transferred
CS2 128 × 8
RD Data between cache and main memory.
WR RAM 3 Temporal & Spatial Locality
AD7 There are two types of locality:
TEMPORAL LOCALITY (locality in time) If an item is
CS1 referenced, it will likely be referenced again soon. Data
CS2 128 × 8 is reused.
RD Data
SPATIAL LOCALITY (locality in space) If an item is
WR RAM 4
AD7 referenced, items in neighboring addresses will likely
be referenced soon
CPU execution time must factor in stalls from
CS1
memory access-
1–7 CS2 128 × 8
Data Assume the on-chip cache responds within the amount
8
9 AD9 ROM of time allotted to it from the load/store or instruction
fetch unit (e.g., 1 clock cycle)
Memory connection to the CPU CPU time = IC * CPI * Clock cycle time
IC * CPI must include all stalls so now we have to add
memory stalls
This configuration gives a memory capacity of 512 bytes (128x4) of RAM
IC * CPI = CPU clock cycles + memory stall cycles
and 512 bytes of ROM. Where IC We can view memory cycle stalls as number
Following table shows how a particular RAM chip is selected based on of stalls per instruction or per memory access (loads
values of 8th and 9th bits in the address bus : & stores have 2 memory accesses per instruction, all
th th others have 1 memory access per instruction)
8 bit in address 9 bit in RAM chip
Memory stall cycles = IC × (misses / instruction) ×
bus address bus Selected
miss penalty
st Memory stall cycles = IC × (memory accesses /
0 0 1 RAM Chip
0 1 nd
2 RAM Chip
instruction) × miss rate × miss penalty
1 0 rd Hit Ratio: The ratio of the number of hits divided by
3 RAM Chip
th the total CPU references to memory (hits plus misses)
1 1 4 RAM Chip
is the hit ratio.
S3-30 Computer Organisation & Architecture

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 ´

• Number of lines in cache = m = 2r ( CPIexec + Accesses ´ Miss rate ´ Miss penalty )


• Size of tag = (s – r) bits Accesses Misses
´ Miss rate ®
instruction instruction
Computer Organisation & Architecture S3-31

7. More than one words are put in one cache block to


Conceptual MCQs [2002, 1 Mark]
1. A graphics card has on board memory of 1 Mbyte. Which (a) exploit the temporal locality of reference in a program
of the following modes can the card not support? (b) exploit the spatial locality of reference in a program
[2000, 2 Marks] (c) reduce the miss penalty
(a) 1600 × 400 resolution with 256 colours on a 17 inch (d) None of the above
monitor 8. A low memory can be connected to 8085 by using
(b) 1600 × 400 resolution with 16 million colours on a 14 [2002, 1 Mark]
inch monitor (a) INTER (b) RESET IN
(c) 800 × 400 resolution with 16 million colours on a 17
inch monitor (c) HOLD (d) READY
(d) 800 × 800 resolution with 256 colours on a 14 inch 9. Suppose a processor does not have any stack pointer
monitor register. Which of the following statements is true?
2. Which is the most appropriate match for the items in the [2002, 1 Mark]
first column with the items in the second column? (a) It cannot have subroutine CALL instruction
[2001, 2 Marks] (b) It can have subroutine CALL instruction, but no
nested subroutine CALLS
List I List II (c) Nested subroutine CALLS are possible, but interrupts
P. Indirect addressing 1. Array implementation are not
Q. Indexed addressing 2. Writing relocatable code (d) All sequences of subroutine CALLS and also
interrupts are possible
R. Base register addressing 3. Passing array as parameter
10. A processor needs software interrupt to [2002, 1 Mark]
(a) P – 3, Q – 1, R – 2 (b) P – 2, Q – 3, R – 1 (a) test the interrupt system of the processor
(c) P – 3, Q – 2, R – 1 (d) P – 1, Q – 3, R – 2 (b) implement co–routines
3. A device employing INTR line for device interrupt puts (c) obtain system services which need execution of
the CALL instruction on the data bus while privileged instruction
[2002, 1 Mark] (d) return from subroutine
11. A CPU has two modes - privileged and non-privileged. In
(a) INTA is active (b) HOLD is active
order to change the mode from privileged to non-
(c) READY is active (d) None of these
4. In 8085, which of the following modifies the program privileged [2002, 1 Mark]
counter? [2002, 1 Mark] (a) a hardware interrupt is needed
(a) Only PCHL instruction (b) a software interrupt is needed
(b) Only ADD instruction (c) a privileged instruction (which does not generate an
(c) JMP and CALL instruction interrtupt) is needed
(d) All instructions (d) a non-privileged instruction (which does not generate
5. Which of the following is not a form of memory? an interrtupt) is needed
[2002, 1 Mark] 12. Which of the following requires a device driver?
(a) Instruction cache [2002, 1 Mark]
(b) Instruction register (a) Register (b) Cache
(c) Instruction opcode (c) Main memory (d) Disk
(d) Translation look-a-side buffer 13. The most appropriate matching for the following pairs
6. In the absolute addressing mode [2002, 1 Mark] X : Indirect addressing 1 : Loops
(a) the operand is inside the instruction Y : Immediate addressing 2 : Pointers
(b) the address of the operand is inside the instruction Z : Auto decrement addressing 3 : Constants
(c) the register containing the address of the operand is is [2002, 1 Mark]
specified inside the instruction (a) X – 3, Y – 2, Z – 1 (b) X – 1, Y – 3, Z – 2
(d) the location of the operand is implicit (c) X – 2, Y – 3, Z – 1 (d) X – 3, Y – 1, Z – 2
S3-32 Computer Organisation & Architecture

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

The CPU instruction “ Push r”, where = A or B, has the


specification Load
M [SP] ¬ r Control address
SP ¬ SP – 1 register
How many CPU clock cycles are needed to execute the
“push r” instruction? [2001, 2 Marks] Increment
(a) 2 (b) 3
(c) 4 (d) 5 Control
39. What are the sates of the Auxiliary Carry (AC) and carry memory
Flag (CY) after executing the following 8085 program? 13
MUX y
[2002, 2 Marks]
MVI H, 5DH 8 Micro-operations
x
MVI L, 6BH
MOV A, H Status bits
ADD L
(a) AC = 0 and CY = 0 (b) AC = 1 and CY = 1 How many bits are there in the X and Y fields, and what
(c) AC = 1 and CY = 0 (d) AC = 0 and CY = 1 in the size of the control memory in number of words?
40. Consider the ALU shown below : [2004, 2 Marks]
(a) 10, 3, 1024 (b) 8, 5, 256
K B0 (c) 5, 8, 2048 (d) 10, 3, 512
B1
A1 A0 44. A hard disk with a transfer rate of 10 Mbyte/s is
constantly transferring data to memory using DMA. The
processor runs at 600 MHz, and takes 300 and 900 clock
to initiate and complete DMA transfer respectively. If the
C1 C0 size of the transfer is 20 kbyte, what is the percentage of
Full Full
adder processor time consumed for the transfer operation?
adder
[2004, 2 Marks]
(a) 5.0% (b) 1.0%
S1 S0
(c) 0 5% (d) 0.1%
[2003, 2 Marks] 45. A 5 stage pipelined CPU has the following sequence of
If the operands are in 2’s complement representation, stages
which of the following operations can be performed by IF : Instruction fetch from instruction memory
suitably setting the control lines K and C0 only (+ and RD : Instruction decode and register read
– denote addition and subtraction respectively)? EX : Execute: ALU operations for data and address
(a) A + B and A – B but not A + 1 computation
(b) A + B and A + 1 but not A – B MA : Data memory access : for write access, the register
(c) A + B but not A – B or A + 1 read at RD stage is used
(d) A + B and A – B and A + 1 WB : Register write back
41. Consider an array multiplier for multiplying two n-bit Consider the following sequence of instructions:
numbers. If each gate in the circuit has a unit delay, the
I1 : L R0 loc 1; R0 < = M [loc1]
total delay of the multiplier is [2004, 1 Mark]
I2 : A R0 ; R0; R0 < = R0 + R0
(a) Q(1) (b) Q(log n) I3 : S R2 ; R0; R2 < = R2 – R0
(c) Q (n) (d) Q(n2 ) Let each state takes on clock cycle.
What is the number of clock cycles taken to complete the
42. Consider a small two-way set-associative cache memory,
above sequence of instructions starting from the fetch of
consisting of four blocks. For choosing the block to be
replaced, use the Least Recently Used (LRU) scheme. I1 ? [2005, 1 Mark]
The number of cache misses for the following sequence (a) 8 (b) 10
of block addresses is 8, 12, 0, 12, 8 [2004, 2 Marks] (c) 12 (d) 15
(a) 2 (b) 3 46. Consider a direct mapped cache of size 32 kbyte with block
(c) 4 (d) 5 size 32 byte. The CPU generates 32 bit address. The number
43. The micro-instructions stored in the control memory of a of bits needed for cache indexing and the number of tag
processor have a width of 26 bit. Each micro-instruction bits are respectively [2005, 1 Mark]
is divided into three fields ; a micro-operation field of 13 (a) 10, 17 (b) 10, 22
bit, a next address field (X), and a MUX select field (Y), (c) 15, 17 (d) 5, 17
there are 8 status bits in the inputs of the MUX.
Computer Organisation & Architecture S3-35

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

(a) 1007 (b) 1020


Common Data MCQs (c) 1024 (d) 1028
Common Data for Questions 75 and 76 78. Let the clock cycles required for vavious operations be
Consider the following assembly language program for a as follows :
hypothetical processor. A, B and C are 8 registers. The Register to/from memory transfer : 3 clock cycles
meanings of various instructions are shown as comments. Add with both operands in register : 1 clock cycle
MOV, B # 0 ; B¬0 Instruction fetch and decode : 2 clock cycles
MOV, B # 0 ; C¬B per word
Z : CMP C # 0 ; compare C with 0 The total number of clock cycles requires to execute the
JZX ; jump of X if zero flat is set prgram is [2005, 2 Marks]
SUB C # 1 ; C¬C–1 (a) 29 (b) 24
RRC A # 1 ; right rotate A through carry (c) 23 (d) 20
by one bit. Thus : Common Data for Questions 79 and 80
; if the initial values of A and Consider two cache organizations :
the carry flag are a7 ...a0 and The first one is 32 kbyte 2-way set associative with 32 k byte
; c0 respectively, their values block size. The second one is of the same size but direct
after the execution of this mapped. The size of an address is 32 bit in both cases. A 2-
instruction will be c0a7...a1 to-1 multiplexer has a latency of 0.6 ns while a k-bit comparator
and a0 respectively. has a latency of k/10 ns. The hit latency of het set associative
JCY ; jump to Y if carry flag is organization is h1 while that of the direct mapped one is h2.
set 79. The value of h1 is [2006, 2 Marks]
JMP Z ; jump to Z (a) 2.4 ns (b) 2.3 ns
Y : ADD B # 1 ; B¬B+1 (c) 1.8 ns (d) 1.7 ns
JMP Z ; jump to Z 80. The value of h2 is [2006, 2 Marks]
X: (a) 2.4 ns (b) 2.3 ns
75. If the initial value of register A is A0, the value of register (c) 1.8 ns (d) 1.7 ns
B after the program execution will be [2003, 2 Marks] Consider Data for Questions 81, 82 and 83
(a) The number of 0 bit in A0 Consider the following program segments. Here R1, R2 and R3
(b) The number of 1 bit in A0 are purpose registers.
(c) A0 Instruction Operation Instruction size
(d) B (number of words)
76. Which of the following instructions when inserted at
MOV R1, 3000 R1 ¬ M [3000] 2
location X will ensure that the value of register A after
LOOP MOV R2, R3 R2 ¬ M [R3] 1
program execution is the same as its initial value?
ADD R2, R2 ¬ R1 + R2 1
[2003, 2 Marks]
(a) RRC A # 1 MOV R3, R2 M[R3] ¬ R2 1
(b) NOP ; no operation INC R3 R3 ¬ R3 + 1 1
(c) LRC A # 1; left rotate A through carry flag by one bit DEC R1 R1 ¬ R1 – 1 1
(d) ADD A # 1 BNZ LOOP Branch on not zero 2
Common Data for Questions 77and 78 HALT Stop 1
Consider the following program segment for a hypothetical Assume that the content of memory location 3000 is 10 and the
CPU having three user registers R1, R2 and R3. content of the register R3 is 2000. The content of each of the
Instruction operation Instruction size memory locations from 2000 to 2010 is 100. The program is loaded
(in words) from the memory location 1000. All the numbers are in decimal.
MOV R1, 5000 ; R1 ¬ Memory [5000] 2 81. Assume that the memory is word addressable. After the
MOV R2, R1 ; R2 ¬ Memory [R1] 1
execution of this program, the content of memory location
ADD R2, R3 ; R2 ¬ R2 + R3 1
2010 is [2007, 2 Marks]
MOV 6000, R2 ; Memory [6000] ¬ R2 2
HALT ; Machine halts 1 (a) 10 (b) 11
77. Consider that the memory is byte addressable with size (c) 20 (d) 21
32 bit, and the program has been loaded starting from 82. Assume that the memory is word addressable. After the
memory location 1000 (decimal). If an Interrupt occurrs execution of this program, the content of memory location
while the CPU has been halted after executing the HALT 2010 is [2007, 2 Marks]
instruction, the return address (in decimal) saved in the (a) 100 (b) 101
stack will be [2005, 2 Marks] (c) 102 (d) 110
Computer Organisation & Architecture S3-39

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

Numerical Answer Questions


103. Consider the 8085 instruction IN 09H stored as follows:

Memory Address Machine Code


3050 DA
3051 09
Add the following incomplete timing diagram for the instruction: (2000, 5 Marks)

T1 T2 T3 T4 T5 T6 T7 T8 T9 TA
A15-A8 30H 30H C

AD7-AD0 50H A D B

10/M

(a) Write the contents of the boxes, A, B, C and D in S3 : INC A


hexademcimal in your answer sheet do not draw any DAA
pictures. MOV E, A (2000, 5 Marks)
(b) Write the state of both ALE and RD pins at times T1, S4 : .......
T2, T3 and T4. (a) For the two pairs (B = 44, C = 25) and (B = 33, C = 46)
(c) How do you generate the signal that tells the at S1,
peripheral to put the data on the bus? Answer by (i) Find the values in register A when control reaches S2.
completing the following statement in your answer (ii) Find the values in registers D and E when control
book: reaches S4.
By combining signals .............. (b) What, in general, is the value of D and E as a function
104. Consider the following 8085 program segment, where of B and C when control reaches S4.
registers B and C contain BCD values: 105. An instruction pipeline has five stages where each stage
S1 : MVI A, 99H takes 2 nanoseconds and all instructions use all five stages.
MVI D, 00H Branch instructions are not overlapped, i.e., the instruction
SUB C after the branch is not fetched till the branch instruction is
ADD B
completed. Under ideal conditions.
DAA
(a) Calculate the average instruction execution time
S2 : JC S3
MOV E, A assuming that 20% of all instruction executed are
MVI A, 99H branch instructions. Ignore the fact that some branch
SUB E instructions may be conditional.
MOV E, A (b) If a branch instruction is a conditional branch
JZ S4 instruction, the branch need not be taken. If the
MVI D, FFH branch is not taken, the following instructions can be
JMP S4 overlapped. When 80% of all branch instructions are
S3-42 Computer Organisation & Architecture

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

CONCEPTUAL MCQs some interrupt or subroutine call. So if SP register


not available then no subroutine call instructions are
1. (b) A graphics card with on board memory of 1 Mbyte possible.
cannot support a mode of 1600 × 400 resolution with Hence (a) is correct option.
16 million colours on a 14 inch monitor. 10. (c) A CPU needs software interrupt to obtain system
2. (a) Indexed addressing is used for array implementation services which need execution of privileged
where each element has indexes. Base register is instructions. Hence (c) is correct option.
used to re-locatable code, where starts from base 11. (b) A software interrupt is initiated by some program
address & then all local addresses as added to base module which need some CPU services, at that time
address. the two modes can be interchanged. Hence (b) is
Indirect addressing is done when array is passed as correct option.
parameter only name is passed. 12. (d) A device driver is a computer program that enables
Hence (a) is correct option. the operating system to interact with a hardware
3. (a) INTR is a signal which if enabled then microprocessor device. It provides the operating system with
has interrupt enabled. It receives high INR signal & information of how to control and communicate with
activates INTA signal, so another request can’t be a certain piece of hardware. The driver is an
accepted till CPU is busy in servicing interrupt. important and vital piece to a program application.
Hence (a) is correct option. Device driver is the program which co-ordinates with
4. (d) Program counter is the register which has the next CPU to regulate the devices. Register, cache & main
location of the program to be executed next. JMP & memory are directly connected to CPU.
CALL changes the value of PC. PCHL instruction So only Disk from given options require device
copies content of registers H & L to PC. drivers. Hence (d) is correct option.
ADD instruction after completion increments program 13. (a) Indexed addressing is used for array implementation
counter. So program counter is modified in all cases. where each element has indexes. Base register is
Hence (d) is correct option. used to re-locatable code, where starts from base
5. (c) Instruction register stores instruction, look-a-side address & then all local addresses as added to base
buffer & instruction cache are also memory. But address. Indirect addressing is done when array is
instruction opcodes are the opcodes related to an passed as parameter only name is passed. Hence (a)
instruction which are not part of memory hierarchy. is correct option.
Hence (c) is correct option. 14. (d) Pipelining is a method to execute a program breaking
6. (d) In absolute address mode, the effective address in it in several independent sequence of stages.
memory is part of the instruction. Some processors In that case pipeline stages can't have different
have full and short versions of absolute addressing delays, no dependency among consecutive
(with short versions only pointing to a limited area instructions & sharing of hardware resources
in memory, normally starting at memory location shouldn't be there. So option (d) is true.
zero). Unless overridden by hardware for virtual 15. (c) In horizontal microprogramming the instruction size
memory mapping, programs that use this address is not large, & no decoding is required. But 1 bit is
mode can not be moved in memory. In absolute used for all control signals. Hence (c) is correct
addressing mode, no need of giving operand, the option.
operand are implicit, instruction itself has knowledge 16. (c) Program relocation at run time transfers complete
of operands. block to some memory locations. Relocation is the
Hence (d) is correct option. process of assigning load addresses to various parts
7. (a) Cache is the small memory which has a very less of a program and adjusting the code and data in the
access time. So it is used for temporal locality of program to reflect the assigned addresses This
reference whereas virtual memory is for spatial require base address and block should be relatively
locality of reference. Hence (a) is correct option. addressed through this base address.
8. (d) Memory can be connected to 8085 by using READY This require both based addressing and relative
signal. If READY is set then communication is addressing mode. Hence (c) is correct option.
possible. Hence (d) is correct option. 17. (d) Case 1 is here of data dependency, this can’t be safe
9. (a) Stack pointer register holds the address of top of with single ALU so read after write.
stack, which is the location of memory at which the Case 2 Conditional jumps are always hazardous as
CPU should resume its execution after servicing they create conditional dependency in pipeline.
S3-44 Computer Organisation & Architecture

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

Analysis Thus, the value stored in AC and CY is 1 and 0


1. First micro operation stores the value of PC into respectively as the value of P flag is passed to AC
Memory Base Register (MBR). as a carry.
2. Second micro operation stores the value of X into 40. (d) This is the ckt to add two numbers in 2’s complement
Memory Address Resister (MAR). form. K & C0 are set to 1. So A + B & A – B using
3. Third micro operation stores value of Y into PC. bit adders can be done. Also since C0 = 1 & in case
4. Fourth micro operation stores value of MBR to B 0, B1........ all are 0, then it gives A + 1.
Hence (d) is correct option.
memory.
41. (c) The no. of gates used in n bit array multiplier (n#n)
So before execution of these instructions PC holds
is 2n – 1. So. if every single gate takes unit delay,
the value of next instruction to be executed. We first then total delay 0(2n – 1) = 0(n). It is of linear order.
stores the value of PC to MBR and then through Hence (c) is correct option.
MBR to memory i.e., We are saving the value of PC
in memory and then load PC with a new value. This 1 2 3
can be done only in two types. Operations 42. (b)
12 0
Conditional branch and interrupt service. 8
As we are not checking here for any conditions. *
So, it is an Initiation of interrupt service. * * 0
35. (d) A smaller cache block size accomodate more number 12 12
of blocks, it improves hit ratio of cache, so the miss 8
After that 12 8 & 8 are 8
penalty is covered.
36. (d) If the associativity of a processor cache is doubled referred but this does not cause any miss So no. of
while keeping the capacity and cache block size miss = 3
unchanged, the width of processor to main data bus This stars (*) shows the misses. Hence (b) is correct
is not affected. option.
43. (a) MUX has 8 states bits as input lines so we require
PROBLEM BASED MCQs 3 select inputs to select & input lines. No. of bits in
37. (b) X = A + B which gives zero. control memory next address field
Then, X = X + C which gives 1.0. = 26 – 13 – 3
Y = A + C which gives A only as 1.0 when added to = 10
A is neglected and thus when Y = Y + B gives 0.0. 10 bit addressing, we have 210 memory size. So X,
38. (b) Push 'r' Y size = 10,3,1024 Hence (a) is correct option.
44. (d) Transfer rate = 10 MB ps
Consist of following operations
Data = 20 KB
M [ SP] !r
Transfer rate =10 Mb ps
SP ! SP – 1
DATA = 20 kb
'r' is stored at memory at address stack pointer
Time = (20 × 210)/10 × 220 = 2 × 103 = 2 ms
currently is, this take 2 clock cycles.
Processor speed =600 MHz=600 cycles/ sec
SP is then decremented to point to next top of stack. Cycles required by CPU=300+900, For DMA =1200
So total cycles = 3 Time =1200/(600 × 106) =.002 ms
Hence (b) is correct option.
39. (c) The MVI instruction loads 5DH in H register and 0.002
%= ´ 100 = 0.1%
6BH in L register respectively. The MOV instruction 2
moves the contents of the source to the destination 45. (a)
R0 = M
i.e., the contents of register H are copied in Clock cycle R 0 = R 0 + R 0 R 2 = R 2 – R0
[loc 1]
accumulator A.
1 IF
And the ADD instruction adds the contents of 2 RD
destination register i.e., L to the accumulator A. 3 EX IF
Thus, the program performs the above functions 4 MA RD
and adds 5DH and 6BH to obtain the result as 5 WB EX
0101 1101 (5DH) + 0110 1011 (6BH) 6 MA IF
= 1100 1000 7 WB RD
8 EX
The result 1100 1000 is stored in the flags as
9 MA
1 1 0 0 1 0 0 0 10 WB
S Z AC P CY Thus, total number of clock cycles required = 10
S3-46 Computer Organisation & Architecture

46. (a) As given 53. (d) As given,


Cache size = 32 kbyte = 32 × 210 byte Number of banks in main memory = 24 and each is of 2
= 2 15 byte = 15 bit byte long.
Therefore, size of tag = 32 – 15 = 17 bit Block size of cache = 64 byte
Since, 32 byte of block is used by cache, so there Due to availability of parallel accessing of the banks,
actually 1 k blocks and for indexing that we need 10 only two accesses are needed to traverse the entire
bit.
data and the time required for this access comes out to
47. (c) Following are the memory cycles needed during the
be 92 ns.
execution cycle.
First memory cycle Read value of A to calculate index At total time = Decoding time + Latency time
addresses = 24/2 + 80 = 92 ns
Second memory cycle Add R0 to get the address of Total latency time for 2 such accesses
first source and read its value = 2 × 92 = 184 ns
Third memory cycle Read the contents of B 54. (a) Each address is multiple of 3 as the starting address is
Fourth memory cycle Read the values of the contents 300 and is each instruction consists of 24 bit, i.e., 3
of B byte.
Fifth memory cycle Write the answer Thus, in the given options the valid counter will be the
® Total memory cycles needed during the execution one which is the multiple of 3. Out of the options we
cycle of the instruction = 5 can see that only 600 satisfies the condition.
48. (b) Data transfer rate = 10000 B/sec Therefore, it is 600.
Total data = 25 × 103
55. (a) The formula used is
Rate = 104
Total disk size is given by = Number of surfaces ×
Performance gain=(25 / 104) × 100 = 25%
49. (b) Disk revolutions = 3000 PM or 50 RPS Number of tracks × Number of sectors × Capacity of
At a time can read in each sector.
One revolution = 512 KB Therefore from the given data, we get
Tracks read /sec = (219/22 ) × 50 = 50 × 217 per sec Total disk size = 16 × 128 × 256 × 512 byte
Interrupt=.2621 sec = 28 × 220 = 28 megabyte = 256 MB
Percentage gain =.2621/100 =26% Total number of sectors = 16 × 128 × 256 byte
50. (a) We require f = T + R = 219 byte
We have MUX equation 56. (d) 64 words require 6 bitsno. of sets = no. of lines / set
f = Z' x + zy size = 128/4 = 32 sets which require 5 bitsno. of tag bits
Now if we make the new ckt truth table is as follows = 20-5-6 = 9,5,6
57. (b) As given the pipelined processor has four stages i.e.,
Truth Table
IF, ID, EX, WB,
R T F Z
And we know that number of clock cycles required to
0 0 0 0 ADD and SUB instructions is 1 and by MUL
0 1 1 1 instructions are 3.
1 0 1 0 In the pipelined processor while one instruction is
1 1 1 1 fetched, the other is either being decoded or executed
or some action is being performed. Thus, the number
So X = R Y = 1 Z = T of cycles required by the given set of instructions can
f=T'R+T be obtained from the following diagram.
= (T + T ')(T + R)
f=T+R Clock cycle ADD MUL SUB
51. (a) From the given conditions it can be determined that 1 IF
we have to set all the other bits to 0 in temp, as the
2 ID IF
position pos is the only deciding factor in jumping to
the label. If the left shift over 1 is done by the pos 3 EX ID IF
number then the mask register can have 1 in pos place, 4 WB EX ID
which is required. Thus, is the option mask ¬ 0 × 1 <<
pos is correct. 5 EX
52. (b) As given there is no conditional loop for the 80% of 6 EX IF
109 instruction thus only single cycle is required for
7 WB EX
them and rest requires 2 extra cycles.
Thus the total time required = Time of one cycle 8 WB
= (80/100 × 109 × 1 + 20/100 × 109 × 2) Thus, total number of clock cycles required are 8.
= 1/1G × (80/100 × 109 × 1 + 20/100 × 109 × 2) = 1.2s
Computer Organisation & Architecture S3-47

58. (c) As given, basic RAM is 32 k × 1 and we have to design ( 5 + 6 + 11 + 8) ´ 1 30


a RAM of 256 k × 8. 65. (b) Speed up = = = 2.5
(11 + 1) 12
Therefore, number of chips required
66. (b) Effective access time = p × page fault service time
= 256 k × 8/(32 k × 1)
+ (1 – p) × memory access time
= 245 × 1024 × 8/32 × 1024 × 1)
(Multiplying and dividing by 1024) 1
= 64 = 8 × 8 where p = page fault rate = = 0.000001
106
Means, 64 = 8 parallel lines × 8 serial RAM chips.
59. (d) One chip contains 106 bits.to build 4MB capacity MM memory access time = 20 ns
32 chips will be required there are 1K × 1K cells in each Page fault service time = 10 ms = 10000000
chip i.e. 106 cellshence time taken to refresh a single Þ 0.000001 × 10000000 ns + 0.999999 × 20 ns = 29.9998
chip 106 × 100 ns.there are 32 such chips hence » 30 ns
32 × 106 × 100 ns time will be takeni.e. 3200 × 220 ns 67. (d) The normal size of ROM is n × 2n
60. (d) Set 0 48 \ Now, we are multiplying two n-bit numbers.
4 32 So, the resultant has 2n bit.
8
26 92 Hence, the size of the ROM is 2n × 22n
Set 1 1 In the question, n = 4
133 Hence, Þ 2 × 4 × 22×4
73
129 Þ 8 × 28 Þ 23 × 28
Set 2 Þ 2 × 210 Þ 2 k bit
Set 3 255155 OR
3
159 As there is two independent 4 bit inputs, so you need
63 2 × 4 = 8 address lines A 4 bit × 4 bit multiplication has
0 mod 4 = 0 (set 0) 8 bit result, you need 8 data lines.
255 mod 4 = 3 (set 3) \ Rom needs to be at least 256 × 8 = 2 k bit.
Like this the sets in the above table are determined for 68. (a) Considering the following case such that the cache
the other values. blocks are arranged as follows
61. (b) As per the given, the instructions are arranged
0 3 6 9 12
accordingly to their meanings. We get the following:
1 4 7 10 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2 5 8 11 14
I0 IF ID OF PO PO PO WO
The cache is divided into v = 3 sets and each of
I1 IF ID Stall Stall PO PO PO PO PO PO PO WO
which consists of k = 5 lines.
I2 IF ID OF – – – – – – – PO WO
e.g. suppose we need to find the block 9, then
I3 IF ID OF – – – – – – PO WO
Option (a) :
(9 mod 3) * 5 to (9 mod 3) * 5 + 4 = 0 to 4
Here, we can see that the last operation (Write
Operand) comes at the 15th clock cycle so it takes 15 Option (b) :
clock cycles to execute given sequence of instructions. (9 mod 3) to (9 mod 3) + 4 = 0 to 4
62. (a) Number of clock cycles required by susing load-store Option (c) :
approach = 2 + 500 × 7 = 3502 and that of by using (9 mod 5) + (9 mod 5) + 2 = 4 to 6
DMA = 20 + 500 × 2 = 1020 Option (d) :
Required speed up = 3502 / 1020 = 3.4 (9 mod 5) * 3 to (9 mod 5) * 3 + 2 = 12 to 14
63. (d) Number of cycle for executing loop i=1 is 15 so, Now check for option (a), (b), (c) and (d).
total no. of cycle is 2*15(loop runs 2 time), if Check for block 11.
we calculate no. of pipeline continuous no option Option (a) :
will match, so here we have to take loop independently. (11 mod 3) * 5 to (11 mod 3) * 5 + 4 = 10 to 14
64. (d) Direct mapped cache => number of sets = 8KB/32B Option (b) :
= 2565 bits for offset within a block & 8 bits for (11 mod 3) to (11 mod 3) + 4 = 2 to 6
identifying set. So remaining 32 – 8 – 5 = 19 bits for Option (c) :
tag.1 tag/32B block it includes 2 more bits. So 21 bits/ (11 mod 5) to (11 mod 5) + 2 = 6 to 8
32 B block Number of such blocks = 256 So total tag Clearly, option (a) gives correct answer.
mem = 256 × 21 = 5376
S3-48 Computer Organisation & Architecture

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

105. (a) 3.6 nano seconds (b) 2.96 nano seconds

106. (a) Virtual address space Physical memory address


0–4 K 2 0–4 K
Page 0 4
4–8 K
4–8 K
Page 1 8–12 K 6
12–16 K 0 8–12 K
Page 2
16–20 K 4 12–16 K
20–24 K 3
X 16–20 K
24–28 K
OR
28–32 K X 20–24 K
32–36 K 5
24–28 K
36–40 K X
40–44 K 7 28–32 K
44–48 K X
48–52 K X Page frame
Memory Physical
map 52–56 K X
memory
Page n 56–60 K X
60–64 K X
Virtual Memory 64–68 K X
68–72 K X
72–76 K X Virtual page
76–80 K X

Virtual Address translated into physical address

Second level page


table
Top level to pages
page table
0
Bits 1
10 10 12 2
pt 3
PT1 PT2 Offset 4
5
6

1023

0
1
2
3 Page table for
4 the top 4 m of
5 memory
6

1023

Two level page table


S3-52 Computer Organisation & Architecture

(b) page = 4 k bytes = 215 bit set offset = 7 bits


Physical address = 32 bit = 232 bit memory Byte offset = 8 × 4 bytes = 32 bytes = 25
Size pages = 4 bytes = 25 bit Þ 5 bits
252 12 TAG = 32 – (7 + 5) = 20 bits
Number page entry / page = 15 5 = 2 = 4096
2 ´2 32 bit
Cachup disabled modified Present /absent SET BYTE
TAG OFFSET OFFSET
(c) Page frame no 20 7 5
110. 10000
Each write request, the basic occupied for 100 ns
Referenced Protection
Storing the data requires 100 ns.
A typical page table entry In 100 ns – 1 store

present / absent ® 1 bit 100


ms ® 1 store
protection ® in simplest form, the field is 1 bit, in sophisti- 106
cated form 3 bit
Modified ® 16 bit 106
1 ms = stores
Referenced ® 1 bit 100
Catchup ® 1 bit = 10.000 stores
107. 16383 111. 1.54
(i) Given is 32-bit architecture machine with 1 word
long instruction; so, the instruction size is 32 bit. Avg.
No. of Stall Stall Clock
access
32-bit stages cycle frequency period
time
(Instruction) Old design 5 5 20% 2.2ns P
(ii) As the machine need to support 45 instructions, the New Design 8 5 20% 1 ns Q
number of bits required in the “opcode field” is 6
bits, because, é æ 1 2 öù
5-bits: 25 = 32 P = ê80%(1clock) + 20% ç + ú ´ Tc - p
(Not sufficient)
ë è completion stall clock ÷ø û
6-bits: 26 = 64 (Sufficient)
(iii) As the machine has 64 registers, so to uniquely P = (.8 + .6) × 2.2ns = 3.08ns
identify a register out of those 64 registers, we need é æ 1 5 öù
6-bits. (using the similar argument as above) Q = ê80%(1clock) + 20% ç + ú ´ Tc - p
ë è completion stallclock ÷ø û
As each instruction has 2 register operands, so
6 + 6 = 12 bits are needed for them. P = (.8 + .12) × 1ns = 2ns
So, finally instruction will took like as follows:
P 3.08ns
So the value of = = 1.54
Opcode Reg 1 Reg 2 Immediate operand Q 2ns
6 6 6 14 112. 1.68
(Total = 32 bits) Total instructions = 100 instruction fetch operation + 60
(iv) As 14-bits are available for immediate operand, the memory operant read operation + 40 operant write
max value will be 214 = 16384. operation
However one value will be used for “Zero” also as Therefore, total of 200 instructions
the operand is an “unsigned integer”. So, finally, the Time taken for fetching 100 instructions (equivalent to
maximum value that the immediate operand can take read)
= 214 – 1 = 16383. = 90 × 1ns + 10 × 5ns = 140ns
108. 4 to 4 Memory operand Read operations = 90%(60) × 1ns +
109. 20
10% (60) × 5ns
Physical address size = 32 bit
= 54ns + 30ns = 84ms
Cache size = 16k bytes = 214 bytes
block size = 8 words = 8 × 4 byte = 32 byte Memory operands write operation time = 90%(40) × 2ns
+ 10%(40) × 10ns
214 = 72ns + 40ns = 112ns
No. of blocks = = 29
25 Total time taken for executing 200 instructions = 140 + 84
block offset = 9 bits + 112 = 336ns

29 29 336
No. of sets = = = 27 \ Average memory access time = ns = 1.68ns
4 22 200
Programming & Data Structures S3-53

3 Programming & Data


Chapter Structures
Quick Revision Material

PROGRAMMING IN C C - Reserved Keywords


C Program File The following names are reserved by the C language. Their
All the C programs are writen into text files with extension ".c" for meaning is already defined, and they cannot be re-defined to
example hello.c. You can use "vi" editor to write your C program mean anything else.
into a file. Auto else Long switch
C Compilers Break enum register typedef
When you write any program in C language then to run that Case extern return union
program you need to compile that program using a C Compiler Char float Short unsigned
which converts your program into a language understandable by Const for signed void
a computer. This is called machine language (ie. binary format). Continue goto Sizeof volatile
Preprocessor Commands: These commands tells the compiler to Default if Static while
do preprocessing before doing actual compilation. Like #include Do int Struct Packed
<stdio.h> is a preprocessor command which tells a C compiler to Double
include stdio.h file before going to actual compilation. C Preprocessor, Directives and Header Files:
Functions: are main building blocks of any C Program. Every C C Preprocessor :
Program will have one or more functions and there is one As part of compilation, the C compiler runs a program called the
mandatory function which is called main() function. This function C preprocessor. The preprocessor is able to add and remove code
is prefixed with keyword int which means this function returns an from your source file. One of the major functions of C
integer value when it exits. This integer value is returned using preprocessor is Tokenizing. The final step of the preprocessor is
return statement.The C Programming language provides a set of to link the resulting program with necessary programs and library.
built-in functions. In the above example printf() is a C built-in This directive is used for text substitution. Every occurrence of
function which is used to print anything on the screen. the identifier is substituted by the substitution_token. The
Variables: are used to hold numbers, strings and complex data primary advantage is that it increases the readability of the
for manipulation. program.
Statements & Expressions : Expressions combine variables and # include directive:
constants to create new values. Statements are expressions, This directive searches for a header or source file, which can be
assignments, function calls, or control flow statements which processed by the implementation, to be include in the program.
make up C programs. Header files:
Comments: are used to give additional useful information inside Header files are a collection of macros, types, functions and
a C Program. All the comments will be put inside /*...*/ as given in constants. Any program that needs those functions can include
the example above. the corresponding header files.
S3-54 Programming & Data Structures

List of some commonly used Header file and their purposes:


Header Files Purpose Functions Declared
printf(), scanf(), getchar(),
Used for standard input and output (I/O)
stdio.h putchar(), gets(), puts(), getch(),
operations.
putch(), fopen, fclose(), feof()
Contains declaration for console I/O
conio.h clrscr(); exit()
functions
Used for character-handling or testing
ctype.h isupper(), is lower, isalpha()
characters.
Declares mathematical functions and pow(), squr(), cos(), tan(), sin(),
math.h
macros log()
Used for number conversions, storage
stdlib.h rand(), srand()
allocations.
streln(), strcpy(), strcmp(), stract(),
string.h Used for manipulating strings
strlwr(), strupr(), strrev()
Data Type
Data type determines the kind of data which is going to be stored in the variable declared to of that type. The biggest advantage of data
types is efficient use of memory space.

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

{ following the loop or switch.


case constant-expression1: statements1; continue statement Causes the loop to skip the
[case constant-expression2: statements2;] remainder of its body and
[case constant-expression3: statements3;] immediately retest its condition
[default : statements4;] prior to reiterating.
} goto statement Transfers control to the labeled
Using break keyword: statement. Though it is not
If a condition is met in switch case then execution continues on advised to use goto statement in
into the next case clause also if it is not explicitly specified that your program.
the execution should exit the switch statement. This is achieved printf() function
by using break keyword. This is one of the most frequently used functions in C for output.
scanf() function
Looping This is the function which can be used to to read an input from
Loops provide a way to repeat commands and control how many the command line.
times they are repeated. C - Pointing to Data
while loop A pointer is a special kind of variable. Pointers are designed for
A while statement is like a repeating if statement. Like an If storing memory address i.e. the address of another variable.
statement, if the test condition is true: the statments get executed. Declaring a pointer is the same as declaring a normal variable
The difference is that after the statements have been executed, except you stick an asterisk '*' in front of the variables identifier.
the test condition is checked again. If it is still true the statements • There are two new operators you will need to know to
get executed again.This cycle repeats until the test condition work with pointers. The "address of" operator '&' and
evaluates to false. the "dereferencing" operator '*'. Both are prefix unary
syntax of while loop operators.
while ( expression ) • When you place an ampersand in front of a variable
{ you will get it's address, this can be stored in a pointer
Single statement variable.
or • When you place an asterisk in front of a pointer you
Block of statements; will get the value at the memory address pointed to.
} Arrays
An array is used to store a collection of data, but it is often more
for loop useful to think of an array as a collection of variables of the same
for loop is similar to while, it's just written differently. for type.
statements are often used to proccess lists such a range of All arrays consist of contiguous memory locations. The lowest
numbers: address corresponds to the first element and the highest address
Syntax of for loop to the last element.
for( expression1; expression2; expression3) First Element Last Element
{
Single statement
or
Block of statements; Numbers[0] Numbers[1] Numbers[2] Numbers[3] ......
} Array Initialization
do...while loop int array [8] = {2, 4, 6, 8, 10, 12, 14, 16};
do ... while is just like a while loop except that the test condition is An array of characters ie string can be initialized as follows:
checked at the end of the loop rather than the start. This has the char string[10] = "Hello";
effect that the content of the loop are always executed at least Functions and Variables:
once. Passing Parameters to a Function
syntax of do...while loop There are two ways to pass parameters to a function:
Do • Pass by Value: mechanism is used when you don't
{ want to change the value of passed paramters. When
Single statement parameters are passed by value then functions in C
or create copies of the passed in variables and do required
Block of statements; processing on these copied variables.
}while(expression); • Pass by Reference : mechanism is used when you
Control Statement Description want a function to do the changes in passed
break statement Terminates the loop or switch parameters and reflect those changes back to the
statement and transfers execution calling function. In this case only addresses of the
to the statement immediately
Programming & Data Structures S3-57

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

• int strlen(char *string) - Determine the length of a int ovel;


string. };
• char *strcat(char *dest, const char *src); - Concatenate C - Working with Files
string src to the string dest. When accessing files through C, the first necessity is to have a
• char *strncat(char *dest, const char *src, int n); - way to access the files. For C File I/O you need to use a FILE
Concatenate n chracters from string src to the string pointer, which will let the program keep track of the file being
dest. accessed. For Example:
• char *strchr(char *string, int c) - Find first occurrence FILE *fp;
of character c in string. To open a file you need to use the fopen function, which returns
• char *strrchr(char *string, int c) - Find last occurrence a FILE pointer. Once you've opened a file, you can use the FILE
of character c in string. pointer to let the compiler perform input and output functions on
• char *strstr(char *string2, char string*1) - Find first the file.
occurrence of string string1 in string2. FILE *fopen(const char *filename, const char *mode);
• char *strtok(char *s, const char *delim) - Parse the Here filename is string literal which you will use to name your file
string s into tokens using delim as delimiter. and mode can have one of the following values
C++ supports a wide range of functions that manipulate null- w - open for writing (file need not exist)
terminated strings: a - open for appending (file need not exist)
S.N. Function & Purpose r+ - open for reading and writing, start at beginning
1 strcpy(s1, s2); w+ - open for reading and writing (overwrite file)
Copies string s2 into string s1. a+ - open for reading and writing (append if file exists)
2 strcat(s1, s2); Note that it's possible for fopen to fail even if your program is
Concatenates string s2 onto the end of string s1. perfectly correct: you might try to open a file specified by the
3 strlen(s1); user, and that file might not exist (or it might be write-protected).
Returns the length of string s1. In those cases, fopen will return 0, the NULL pointer.
4 strcmp(s1, s2); Here's a simple example of using fopen:
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; FILE *fp;
greater than 0 if s1>s2.
5 strchr(s1, ch);
fp=fopen("/home/tutorialspoint/test.txt", "r");
Returns a pointer to the first occurrence of character ch in
This code will open test.txt for reading in text mode. To open a file
string s1.
in a binary mode you must add a b to the end of the mode string;
6 strstr(s1, s2);Returns a pointer to the first occurrence of
for example, "rb" (for the reading and writing modes, you can add
string s2 in string s1.
the b either after the plus sign - "r+b" - or before - "rb+")
C - Structured Datatypes
To close a function you can use the function:
A structure in C is a collection of items of different types.
int fclose(FILE *a_file);
Following is the example how to define a structure.
fclose returns zero if the file is closed successfully.
struct student {
char firstName[20]; An example of fclose is:
char lastName[20]; fclose(fp);
char SSN[9]; To work with text input and output, you use fprintf and fscanf,
float gpa; both of which are similar to their friends printf and scanf except
}; that you must pass the FILE pointer as first argument.
your variables of student type: Binary I/O
struct student student_a, student_b; There are following two functions which will be used for binary
Pointers to Structs: input and output:
Declaring pointers to structures is basically the same as declaring size_t fread(void *ptr, size_t size_of_elements,
a normal pointer: size_t number_of_elements, FILE *a_file);
struct student *student_a;
To dereference, you can use the infix operator: ->. size_t fwrite(const void *ptr, size_t size_of_elements,
printf("%s\n", student_a->SSN); size_t number_of_elements, FILE *a_file);
Unions Datatype Both of these functions deal with blocks of memories - usually
Unions are declared in the same fashion as structs, but have a arrays. Because they accept pointers, you can also use these
fundamental difference. Only one item within the union can be functions with other data structures; you can even write structs
used at any time, because the memory allocated for each item to a file or a read struct into memory.
inside the union is in a shared memory location.
Abstract Data types
Here is how we define a Union
C is not object-oriented, but we can still manage to inject some
union Shape {
object-orientedprinciples into the design of C code. For example,
int circle;
int triangle; a data structure and its operations can be packaged together into
Programming & Data Structures S3-59

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

Uses and Operations on Linked Lists Make p->next equal to q


Linear linked list: last element is not connected to anything )
Circular linked list: last element is connected to the first
Dynamic: Size of a linked list grows or shrinks during the execution Delete after p
of a program and is just right Call the next node, i.e., p->next as q
Advantage: It provides flexibility in inserting and deleting elements Make p->next equal to q->next
by just re-arranging the links Delete q
Disadvantage: Accessing a particular element is not easy There STACKS
are three major operations on linked lists A stack is simply a list of elements with insertions and deletions
permitted at one endcalled the stack top. That means that it is
1 Insertion possible to remove elements from a stack in reverse order from
2 Deletion the insertion of elements into the stack. Thus, a stack data
3 Searching structure exhibits the LIFO (last in first out) property. Push and
Insertion at the beginning of the list pop are the operations that are provided for insertion of an element
Create a new node (say q) into the stack and the removal of an element from the stack,
Make q->next point to head respectively.
Make head equal to q Operations on stack:
list is empty, i.e., head is NULL The insertion of elements into stack is called PUSH operation.
Make head equal to q The deletion of elements from stack is called POP operation.
POP operation:
Insertion at end of list Following actions taken place in POP:
Create a new node (say q) Check the stack empty or not.
Find the last element (say p) Remove the top element from the stack.
Make p->next point to q Return this element to the calling function or program.
if list is empty, i.e., head is NULL QUEUE
Make head equal to q A queue is a container of objects (a linear collection) that are
Deletion at the beginning of the list inserted and removed according to the first-in first-out (FIFO)
Make p equal to head principle. An excellent example of a queue is a line of students in
Make head equal to head->next the food court of the UC. New additions to a line made to the back
Delete p (by using free) of the queue, while removal (or serving) happens in the front. In
If list is empty, i.e., head is NULL the queue only two operations are allowed enqueue and dequeue.
Nothing to do Enqueue means to insert an item into the back of the queue,
If list contains only one element dequeue means removing the front item. The picture demonstrates
Delete head the FIFO access.
head is now NULL The difference between stacks and queues is in removing. In a
stack we remove the item the most recently added; in a queue, we
Deletion from the end of the list remove the itemthe least recently added.
Find the last element (say p) Queues
While finding p, maintain q that points to p Queue operations are also called First-in first-out Operations
q is the node just before p, i.e., q->next is p Enqueue: insert at the end of queue
Make q->next NULL Dequeue: delete from the beginning of queue
Delete p (by using free) Code: similar to previous code on linked lists
If list is empty, i.e., head is NULL Queue Application: Executing processes by operating system
Nothing to do Operating System puts new processes at the end of a
If list contains only one element queue.System executes processes at the beginning of the queue
Delete head
head is now NULL Circular Lists
The last element of a linked list points to the first element.
Searching a node (insert after, delete after) A reference pointer is required to access the list: head
Make p equal to head
While p->data not equal to the data that is being searched,
make p equal to p->next
Using search, insert after and delete after operations can be
implemented
Insert after p
Create a new node q
Make q->next equal to p->next
Programming & Data Structures S3-61

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

(a) Rotates s left by k positions


Conceptual MCQs (b) Leaves s unchanged
(c) Reverses all elements of s
1. The following C declarations (d) None of these
struct node{ 7. The process of assigning load addresses to the various
int i : parts of the program and adjusting the code and date in
float j ; the program to reflect the assigned addresses is called
} [2001, 1 Mark]
struct node * s [10]; (a) assembly (b) parsing
define s to be [2000, 1 Mark] (c) relocation (d) symbol resolution
(a) an array, each element of which is a pointer to a 8. In the C language [2002, 1 Mark]
structure of type node (a) at most one activation record exists between the
(b) a structure of 2 fields, each field being a pointer to current activation record and the activation record
an array of 10 elements for the main
(c) a structure of 3 fields : an integer, a float and an (b) the number of activation records between the
array of 10 elements current activation record and the activation record
(d) an array, each element of which is a structure of type for the main depends on the actual function calling
node sequence
2. The most approximate matching for the following pairs (c) the visibility of global variables depends on the
X. m = malloc (5); m = NULL; 1. using dangling actual function calling sequence
pointers (d) recursion requires the activation record for the recursive
Y. free (n); n- > value = 5; 2. using uninitialized function to be saved on a different stack before the
pointers recursive function can be called
9. The results returned by function under value – result and
Z. char *p; *p = ‘a’; 3. lost memory
reference parameter passing conventions
is [2000, 1 Mark]
[2002, 1 Mark]
(a) X – 1, Y – 3, Z – 2 (b) X – 2, Y – 1, Z – 3 (a) do not differ
(c) X – 3, Y – 2, Z – 1 (d) X – 3, Y – 1, Z – 2 (b) differ in the presence of loops
3. The most appropriate matching for the following pairs is (c) differ in all cases
X. depth first search 1. heap (d) may differ in the presence of exception
Y. breadth-first search 2. queue 10. To evaluate an expression without any embedded function
Z. sorting 3. stack calls [2002, 2 Marks]
[2000, 1 Mark] (a) one stack is enough
(a) X – 1, Y – 2, Z – 3 (b) X – 3, Y – 1, Z – 2 (b) two stacks are needed
(c) X – 3, Y – 2, Z – 1 (d) X – 2, Y – 3, Z – 1 (c) as many stacks as the height of the expression tree
4. Consider the following nested representation of binary are needed
trees: (XYZ) indicates Y and Z are the left and right sub (d) a turning machine is needed in the general case
trees, respectively, of node X. Note that Y and Z may be 11. Dynamic linking can cause security concerns because
NULL, or further nested. Which of the following represents [2002, 2 Marks]
a valid binary tree? [2000, 1 Mark] (a) security is dynamic
(a) (1 2 (4 5 6 7)) (b) (1 (2 3 4) (5 6 )7) (b) the path for searching dynamic libraries is not
(c) (1 (2 3 4) (5 6 7)) (d) (1 (2 3 NULL) (4 5)) known till runtime
5. Aliasing in the context of programming languages refers (c) linking is insecure
to [2000, 1 Mark] (d) cryptographic procedures are not available for
(a) multiple variables having the same memory location dynamic linking
(b) multiple variables having the same value 12. What is the minimum number of stacks of size n required
to implement a queue of size n? [2002, 2 Marks]
(c) multiple variables having the same identifier
(a) one (b) Two
(d) multiple uses of the same variables
(c) Three (d) Four
6. Suppose you are given an array s[1....n] and a procedure 13. Assume the following C variable declaration
reverse (s,i,j) which reverses the order of elements in a int* A [10], B [10] [10];
between positions i and j (both inclusive). What does the Of the following expressions which will not give compile
following sequence do, where 1 £ k £ n : [2000, 2 Marks] time errors if used as left hand sides of assignment
reverse (s, 1, k); statements in a C program ? [2003, 1 Mark]
reverse (s, k + 1, n); (a) A [2] (b) A [2] [3]
reverse (s, 1, n); (c) B [1] (d) B [2] [3]
Programming & Data Structures S3-65

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

41. Consider the following C function : (c)


float f (float x, int y) { I P U
float p, s; int i;
for (s = 1), p = 1, i = 1; i < y ; i ++){
p* = x/i; B G H LN Q T V X Z
s + = p;
} (d) None of these
return s; 45. In the following C program fragment j, k n and TwoLog_n
} are integer variables, and A is an array of integers. The
For large value of y, the return value of the function f best variable n is initialized to an integer ³ 3, and TwoLog_n
approximates [2003, 1 Mark] is initialized to the value of 2* êélog 2 (n)úù
(a) x y (b) e x
for (k = 3; k < = n; k + +)
(c) ln(1+ x) (d) x x
A [k] = 0;
42. Let T (n) be the number of different binary search trees
for (k = 2; k < = TwoLog_n; k + +)
n for (j = k + 1; j < = n; j + +)
on n distinct elements. Then, T (n) = å T (K–1) T ( x), A[j] = A[j] || (j%k);
k =1 ` for (j = 3; j < = n; j + +)
where x is [2003, 1 Mark] if (!A[j]) printf (“%d”, j);
(a) n – k + 1 (b) n – k The set of numbers printed by this program fragment is
(c) n – k – 1 (d) n – k – 2 [2003, 2 Marks]
43. Let S be a stack of size n ³ 1. Starting with the empty (a) {m | m £ n ( $i ) [m = i!]}
stack, suppose we push the first n natural numbers in (b) {m | m £ n, ( $i ) [m = i2]}
sequence, and then perform n pop operations. Assume (c) {m | m £ n, (m is prime)}
that Push and Pop operations take X seconds each, and
(d) { }
Y seconds elapse between the end of one such stack 46. Consider the C program shown below :
operations and the start of the next operation. For m ³ 1, # include < stdio. h >
define the stack – life of m as the time elapsed from the # define print(x) printf (“ %d”, x)
end of Push (m) to the start of the pop operation that int x ;
removes m from S. The average stack – life of an element void Q (int z) {
of this stack is [2003, 2 Marks] z + = x; print(z);
(a) n (X + Y) (b) 3Y + 2X }
(c) n (X + Y) – x (d) Y + 2X void P (int *y) {
44. Consider the following 2 – 3 – 4 tree (i. e., B – tree with int x = *y + 2;
a minimum degree of two) in which each data item is a Q (x); *y = x – 1;
letter. The usual alphabetical ordering of letters is used in print (x);
constructing the tree. [2003, 2 Marks] }
main (void) {
L P U x = 5;
P (& x)
Print (x);
}
The output of this program is [2003, 2 Marks]
(a) 12 7 6 (b) 22 12 11
BHI N QT VXZ (c) 14 6 6 (d) 7 6 6
47. Consider the function f defined below :
What is the result of inserting G in the above tree? struct item {
(a) P int data;
struct item * next :
};
G L U int f (struct item * p) {
return ((p = = NULL) P (p – > next = = NULL) P
B HI N QT VXZ ((p– > data < = p – > next –> data) &&
f (p–> next)));
}
(b) P
For a given linked list p, the function f returns 1, if and
only, if [2003, 2 Marks]
H L U (a) the list is empty or has exactly one element
(b) the elements in the list are sorted in non-decreasing
order of data value
BG I N QT VXZ (c) the elements in the list are sorted in non-increasing
order of data value
(d) not all element in the list have the same data value
Programming & Data Structures S3-69

48. A single array A [1...MAXSIZE] is used to implement two y = 1;


stacks. The two stack graw from opposite ends of the while (x– y > Î )
array. Variable top 1 and top 2 (top 1 < top 2 ) point to { x = (x + y) / 2;
the location of the topmost element in the each of the y = m/x;
stacks. If the space is to be used efficiently, the condition }
for stack full is [2004, 1 Mark] print (x);
(a) (top1 – MAXSIZE / 2 ) and (top 2 = MAXSIZE/2 + 1) (a) log m (b) m2
(b) top1 + top 2 = MAXSIZE 1 1
(c) (top1 = MAZSIZE/2) or (top 2 = MAXSIZE) m3
(d) top1 = top 2 – 1 (c) m2 (d)
54. Consider the following C program segment
49. The following numbers are inserted into an empty binary
struct Cell Node{ [2005, 2 Marks]
search tree in the given order : 10, 1, 3, 5, 15, 12, 16. What
struct Cell Node *left Child;
is the height of the binary search tree (the height is the
int element;
maximum distance of a leaf node from the root)?
struct Cell Node *right Child;
[2004, 1 Mark]
}
(a) 2 (b) 3
int Dosomething (struct Cell Node *ptr)
(c) 4 (d) 6
{
50. A program P reads in 500 integers in the range [0, 100]
int value = 0;
representing the scores of 500 students. It then prints the
if (ptr! = NULL)
frequency of each score above 50. What would be the best
{ if (ptr-> left Child! = NULL)
way for P to store the frequencies? [2005, 1 Mark]
value = 1 + Dosomething (ptr -> left Child);
(a) An array of 50 numbers
if(ptr-> rightChild! = NULL)
(b) An array of 100 numbers
value = max (value, 1 + Dosomething (ptr-
(c) An array of 500 numbers
> rightChild));
(d) A dynamically allocated array of 550 numbers
}
51. Consider the following program fragment for reversing
return (value);
the digits in a given integer to obtain a new integer. Let
}
n = d1d2 ... dm.
The value returned by the function Dosomething when a
int n, rev;
pointer to the root of a non-empty tree is passed as
rev = 0;
argument is
while (n > 0) {
(a) the number of leaf nodes in the tree
rev = rev * 10 + n% 10;
(b) the number of nodes in the tree
n = n/ 10;
(c) the number of internal nodes in the tree
}
(d) the height of the tree
The loop invariant condition at the end of the ith iteration
55. The elements 32, 15, 20, 30, 12, 25, 16, are inserted one by
is [2005, 2 Marks]
one in the given order into a max-heap. The resultant max-
(a) n = d1d2 ...dm – i and rev = dmdm–1 ...dm – j + 1
heap is [2005, 2 Marks]
(b) n = dm – i + 1 ...dm – 1 dm or rev = dm – i...d2d1
(c) n ¹ rev 32 32
(d) n = d1d2 ...dm or rev = dm ...d2d1
52. Consider the following C program : (a) 30 25 (b) 25 30
main ()
{ int x, y, m, n;
12 15 20 16
scanf (“%d %d” , &x, &y); 15 12 20 16
/ * Assume x > 0 and y > 0 */
m = x; n = y; 32 32
while (m! = n)
{ if (m > n) (c) 30 25 (d) 25 30
m = m – n;
else 15 12 16 20 12 15 16 20
n = n – m;
} 56. Consider the following C function: [2005, 2 Marks]
printf (“ % d”, n); int f (int n)
} { static int i = 1;
The program computes [2005, 2 Marks] if (n > = 5) return n;
(a) x ÷ y using repeated subtraction n = n + 1;
(b) x mod y using repeated subtraction i ++;
(c) the greatest common divisor of x and y return f(n);
(d) the least common multiple of x and y }
53. What does the following algorithm approximate? The value returned by f (1) is
(Assume m > 1, Î > 0). [2005, 2 Marks] (a) 5 (b) 6
x = m; (c) 7 (d) 8
S3-70 Programming & Data Structures

57. Postorder traversal of a given binary search tree, T produces


the following sequence of keys int work2 {int *a, int i, int j)
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 {
Which one of the following sequences of keys can be the int t1 = i + 2
result of an in-order traversal of the tree T? [2005, 2 Marks] int t2 = a[t1]
a[j] = t2 + 1;
(a) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
return t2 – 3;
(b) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
}
(c) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(d) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29 S1: The transformation form work1 to work2 is valid, i.e., for
58. Consider the following C-program: [2005, 2 Marks]
any program state and input arguments, work2 will compute
void foo (int n, int sum) {
the same output and have the same effect on program state
int k = 0, j = 0
if (n = = 0) return; as work 1.
k = n% 10, j = n/10; S2: All the transformations applied to work1 to get work2
sum = sum + k; will always improve the performance (i.e., reduce CPU time)
foo (j, sum); of work2 compared to work1
printf (“%d”, k); (a) S1 is false and S2 is false
} (b) S1 is false and S2 is true
int main () { (c) S1 is true and S2 is false
int a = 2048, sum = 0; (d) S1 is true and S2 is true
foo (a, sum); 61. Consider the following C-function in which a[n] and b[m]
printf (“%d\n”, sum); are two sorted integer arrays and c[n + m] be another array.
What does the above program print? void xyz (int a [ ], int b [ ], int c [ ]) [2006, 2 Marks]
(a) 8, 4, 0, 2, 14 (b) 8, 4, 0, 2, 0 {
(b) 2, 0, 4, 8, 14 (d) 2, 0, 4, 8, 0 int i, j, k;
59. Consider this code to swap integers and these five
i = j = k = 0;
statements:
while ((i < n) && (j < m))
The code [2006, 2 Marks]
if (a [i] < b [j] c [k++] = a[i++];
else c[k++] = b[j++];
void swap (int *px, int *py) {
}
*px = *px – *py; Which of the following conditions hold(s) after the
*py = *px + *py; termination of the while loop?
*px = *py – *px; (i) j < m, k = n + j – 1 and a [n – 1] < b[j], if i = n
(ii) i < n, k = m + i – 1 and b [m – 1] £ a[i], if j = m
}
(a) only (i)
S1 : will generate a compilation error (b) only (ii)
S2 : may generate a segmentation fault by runtime (c) either (i) or (ii) but not both
depending on the arguments passed (d) neither (i) nor (ii)
S3 : correctly implements the swap procedure for all input 62. An implementation of a queue Q, using two stacks S1 and
pointers referring to integers stored in memory locations S2 is given below [2006, 2 Marks]
accessible to the process void insert (Q, x) {
S4: implements the swap procedure correctly for some but push (S1, x);
not all valid input pointers }
S5 : may add or subtract integers and pointers
void delete (Q) {
(a) S1 only (b) S2 and S3
(c) S2 and S4 (d) S2 and S5 if (stack-empty (S2)) then
60. Consider these two functions and two statements S1 and S2 if (stack-empty (S1)) then {
about them. [2006, 2 Marks] print (“Q is empty”);
return;
int work1 (int*a, int i, int j) }
{ else while (! (stack-empty (S1))) {
int x = a[i + 2]; x = pop (S1);
a[j] = x + 1; push (S2, x);
return a[i + 2] – 3; }
} x = pop (S2);
}
Programming & Data Structures S3-71

Let n insert and m(£ n) delete operations be performed in an 823^/23*+51*-


arbitrary order on an empty queue Q. Let x and y be the Note that ^ is the exponentiation operator. The top two
number of push and pop operations performed respectively elements of the stack after the first * is evaluated are
in the process. Which one of the following is true for all m (a) 6, 1 (b) 5, 7
and n? (c) 3, 2 (d) 1, 5
(a) n + m £ x < 2n and 2m £ y £ n + m 67. Which combination of the integer variables x, y and z makes
the variable a get the value 4 in the following expression?
(b) n + m £ x £ 2n and 2m £ y £ 2n
a = (x > y)? ((x > z)? x : z) : ((y > z)? y : z) [2008, 1 Mark]
(c) 2m £ x < 2n and 2m £ y £ n + m (a) x = 3, y = 4, z = 2
(d) 2m £ x < 2n and 2m £ y £ 2n (b) x = 6, y = 5, z = 3
63. Consider the following segment of C-code [2007, 1 Mark] (c) x = 6, y = 3, z = 5
int j, n; (d) x = 5, y = 4, z = 5
j = 1; 68. What is printed by the following C program? [2008, 2 Marks]
while (j < = n) int f (int x, int * py, int ** ppz)
j = j*2; {
The number of comparisons made in the execution of the int y, z;
loop for any n > 0 is **ppz + = 1; z = *ppz;
(a) [log2 n] + 1 (b) n *py + = 2; y = *py;
(a) [log2 n] (b) [log2 n] + 1 x + = 3;
64. Consider the following C program segment where CellNode return x + y + z;
represents a node in a binary tree: [2007, 2 Marks] }
struct Cell Node { void main ()
struct Cell Node *leftChild; {
int element; int c, *b, **a,
struct CellNode *rightChild; c = 4; b & c; a = & b
} printf(“%d”, f(c, b, a));
int GetValue (struct CellNode *ptr) { }
int value = 0 (a) 18 (b) 19
if (ptr ! = NULL) (c) 21 (d) 22
if ((ptr - > leftChild = = NULL) && 69. Choose the correct option to fill ? 1 and ?2 so that the program
(ptr -> rightChild == NULL){ below prints an input string in reverse order. Assume that
value = 1; the input string is terminated by a newline character.
else void recerse (void){ [2008, 2 Marks]
value = value + GetValue (ptr -> leftChild) int c;
+ GetValue (ptr -> rightChild); if (?1) reverse ();
} ?2
return (value); }
} main ( ) {
The value returned by GetValue when a pointer to the root printf(“Enter Text”); printf(“/n”);
of a binary tree is passed as its argument is reverse ( ); printf(“/n”)
(a) the number of nodes in the tree (a) ?1 is (getchar ( )! = ‘\n’)
(b) the number of internal nodes in the tree ?2 is getchar (c);
(c) the number of leaf nodes in the tree (b) ?1 is (c = getchar ( ))! = ‘\n’)
(d) the height of the tree ?2 is getchar (c);
65. Consider the following C function: [2007, 2 Marks] (c) ?1 is (c! = ‘\n’)
int f (int n) ?2 is putchar (c);
{static int r = 0; (d) ?1 is (c = getchar ( ))! = ‘\n’)
if (n < = 0) return 1; ?2 is putchar (c);
if (n > 3) 70. The following C function takes a single-linked list of integers
{r = n; as a parameter and rearranges the elements of the list. The
return f (n – 2) + 2; function is called with the list containing the integers 1, 2, 3,
} 4, 5, 6, 7 in the given order. What will be the contents of the
return f(n – 1) + r; list after the function completes execution? [2008, 2 Marks]
} struct node {
What is the value of f(5)? int value;
(a) 5 (b) 7 struct node *next;
(c) 9 (d) 18 };
66. The following postfix expression with single digit operands void rearrange (struct node *list){
is evaluated using a stack: [2007, 2 Marks] struct node *p, *q;
S3-72 Programming & Data Structures

int temp; (a) T1, T2, T3 (b) T2, T4


if (!list | | !list -> next) return; (c) T3, T4 (d) T1, T2, T4
p = list, q = list –> next; 74. The program below uses six temporary variables a, b, c, d, e,
while (q){ f. [2010, 2 Marks]
temp = p - > value; p -> value = q - > value; a= 1
q - > value = temp; p = q - > next; b = 10
q = p?p -> next: 0;
c = 20
}
} d=a+b
(a) 1, 2, 3, 4, 5, 6, 7 (b) 2, 1, 4, 3, 6, 5, 7 e=c+d
(c) 1, 3, 2, 5, 4, 7, 6 (d) 2, 3, 4, 5, 6, 7, 1 f= c+ e
71. What is the maximum height of any AVL-tree with 7 nodes? b=c+e
Assume that the height of a tree with a single node is 0. e=b+f
[2009, 1 Mark] d=5+e
(a) 2 (b) 3 return d + f
(c) 4 (d) 5 Assuming that all operations take their operands from
72. Consider the program below: [2009, 1 Mark] registers, what is the minimum number of registers needed
#include < stdio.h > to execute this program without spilling?
int fun (int n, int * f_p){ (a) 2 (b) 3
int t, f; (c) 4 (d) 6
75. The following C function takes a simply-linked list as input
if (n < = 1) {
argument. It modifies the list as input argument. It modifies
*f_p = 1 the list by moving the last element to the front of the list and
return 1; returns the modified list. Some part of the code is left blank.
} type def struct node { [2010, 2 Marks]
t = fun (n – 1, *f_p); int value;
f = t + *f_p; struct node *next;
*f_p = t; } Node*;
Node *move_to_front (Node *head) {
return f;
Node *p, *q;
} if (head = = NULL | | (head -> next = = NULL)) return head;
int main () { q = NULL; p = head;
int x = 15; while (p - > next ! = NULL) {
printf (“% d\n”, fun (5, & x)); q = p;
return 0; p = p - > next;
} }
return head;
The value printed is }
(a) 6 (b) 8 Choose the correct alternative to replace the blank line.
(c) 14 (d) 15 (a) q = NULL; p - > next = head; head = p;
73. The following program is to be tested for statement coverage. (b) q - > next = NULL; head = p; p - > next = head;
begin [2010, 2 Marks] (c) head = p; p -> next = q; q -> next = NULL;
if (a = = b) {S1; exit;} (d) q-> next = NULL; p-> next = head; head = p;
76. What is the value printed by the following C program?
else, if (c = = d) {S2;} #include < stdio.h> [2010, 2 Marks]
else {S3; exit;} int f (int *a, int n)
S4; {
end if (n < = 0) return 0;
The test cases T1, T2, T3 and T4 given below are expressed else if (*a % 2 = = 0) return *a + f(a + 1, n – 1);
in terms of the properties satisfied by the values of variables else return *a – f(a + 1, n – 1);
}
a, b, c and d. The exact values are not given.
int main ()
T1: a, b, c and d are all equal {
T2: a, b, c and d are all distinct int a [ ] = {12, 7, 13, 4, 11, 6};
T3: a = b and c! = d print f (“%d, f(a, 6));
T4: a! = b and c = d return 0,
}
Which of the test suites given below ensures coverage of
(a) – 9 (b) 5
statements S1, S2, S3 and S4?
(c) 15 (d) 19
Programming & Data Structures S3-73

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

(b) The appropriate expressions for the two boxes B1 and B2


Main are
(a) B1 : (1 + height (n ® right)
A1
B2 : (1 + max (h1, h2)
A2 (b) B1 : (height (n ® right)
B2 : (1 + max (h1, h2)
A21 (c) B1 : (height (n ® right)
B2 : max (h1, h2)
Prame A1
pointer Access (d) B1 : (1 + height (n ® right)
links B2 : max (h1, h2)
(c) 88. The number of elements that can be sorted in Q(log n)
Main
time using heap sort is [2013, 2 Marks]
Prame
pointer
A1
(a) Q(1) (b) Q ( log n )
A2
Access æ log n ö
A21 links (c) Qç (d) Q(log n)
è log log n ÷ø
(d) Main 89. Consider the following function:
int unknown (int n) {
A1 int i, j, k=0;
A2 for (i=n/2; i<=n; i++)
for (j=2; j<=n; j=j*2)
A21 k = k + n/2;
return (k);
Prame A1
pointer Access }
links The return value of the function is [2013, 2 Marks]
86. Consider the directed graph shown in the figure below. There (a) Q(n2) (b) Q(n2 log n)
are multiple shortest paths between vertices S and T. Which (c) Q(n3) (d) Q(n3 log n)
one will be reported by Dijkstra’s shortest path algorithm’? 90. The pre-order traversal sequence of a binary search tree
Assume that in any iteration, the shortest path to a vertex v is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the
is updated only when a strictly shorter path to v is discovered. following is the post-order traversal sequence of the
[2012, 2 Marks] same tree? [2013, 2 Marks]
2 (a) 10, 20, 15, 23, 25, 35, 42, 39, 30
E 2 (b) 15, 10, 25, 23, 20, 42, 35, 39, 30
G
C 1 (c) 15, 20, 10, 23, 25, 42, 35, 39, 30
A
1
4 3 (d) 15, 10, 23, 25, 20, 35, 42, 39, 30
3 91. What is the return value of f(p,p), if the value of p
4 D 3 is initialized to 5 before the call? Note that the first
7 O
S 5 T parameter is passed by reference, whereas the second
3 4
5 parameter is passed by value. [2013, 2 Marks]
3
B int f (int &x, int c) {
F
c = c – 1;
(a) SDT (b) SBDT if (c==0) return 1;
(c) SACDT (d) SACET x = x + 1;
87. The height of a tree is defined as the number of edges on the return f(x,c) * x;
longest path in the tree. The function shown in the below in }
invoked as height (root) to compute the height of a binary (a) 3024 (b) 6561
tree rooted at the tree pointer root. [2012, 2 Marks] (c) 55440 (d) 161051
{ if (n = = NULL) return – 1; 92. Consider the following pseudo code. What is the total
if (n ® left = = NULL) number of multiplications to be performed?
if (n ® right = = NULL) return 0; [2014, Set-1, 2 Marks]
else return B1 ; // Box 1 D=2
for i = 1 to n do
else {h1 = height (n ® left); for j = i to n do
if (n ® right = NULL) return (1 + h1); for k = j + 1 to n do
else {h2 = height (n ® right); D = D*3
return B2 ; // Box 1 (a) Half of the product of the 3 consecutive integers.
(b) One-third of the product of the 3 consecutive integers.
} (c) One-sixth of the product of the 3 consecutive integers.
} (d) None of the above.
}
Programming & Data Structures S3-75

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

111. An array contains four occurrences of 0, five occurrences


Numerical Answer Questions of 1, and three occurrences of 2 in any order. The array
109. Suppose you are given arrays p[1 ...N] and q[1...N] both is to be sorted using swap operations (elements that are
swapped need to be adjacent). [2000, 5 Marks]
uninitialized that is, each location may contain an
(a) What is the minimum number of swaps needed to
arbitrary value), and a variable count, initialized to 0.
sort such an array in the worst case?
Consider the following procedures set and iset: (b) Give an ordering of elements in the above array so
[2000, 5 Marks] that the minimum number of swaps needed to sort
Set (i) { the array is maximum.
count = count + 1; 112. There are 5 bags labeled 1 to 5. All the coins in a given bag
q [count] = i; have the same weight. Some bags have coins of weight 10
p[i] = count; gm, others have coins of weight 11 gm. I pick 1, 2, 4, 8, 16
} coins respectively from bags 1 to 5. Their total weight comes
is_set(i) { out to 323 gm. Then the product of the labels of the bags
if (p[i] £ 0 or p[i] > count) having 11 gm coins is _____ . [2014, Set-1, 2 Marks]
return false; 113. Consider the function func shown below:
if (q[p[i]] ¹ i) int func(int num) {
return false; int count = 0;
while (num) {
return true;
count++;
}
num>>= 1;
(a) Suppose we make the following sequence of calls: }
set (7); set (3); set(9); return (count);
After these quence of calls, what is the value of }
count, and what do q[1], q[2], q[3], p[7], p[3] and The value returned by func (435) is __________.
p[9] contain? [2014, Set-2, 1 Mark]
(b) Complete the following statement “The first count 114. Consider the expression tree shown. Each leaf represents a
elements of ................ contain values i such that set numerical value, which can either be 0 or 1. Over all possible
(....................) has been called”. choices of the values at the leaves, the maximum possible
(c) Show that if set (i) has not been called for some i, value of the expression represented by the tree is ___.
then regardless of what p[i] contains, is_set (i) will
return false.
110. A recursive program to compute Fibonacci numbers is
shown below. Assume you are also given an array
f[0...m] with all elements initialized to 0.
[2000, 5 Marks]
fib(n){
if (n > m) error ();
if (n = = 0) return 1;
if (n = = 1) return 1; 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
if ( ) .......................... (1)
[2014, Set-2, 2 Marks]
return .......................... (2)
115. Consider the following function
t = fib (n – 1) + fib (n – 2); double f(double x){
.......................... (3) if( abs(x*x – 3) < 0.01) return x;
return t; else return f(x/2 + 1.5/x);
} }
Give a value q (to 2 decimals) such that f(q) will return
(a) Fill in the boxes with expressions/statements to q:_____. [2014, Set-2, 2 Marks]
make fib() store and reuse computed Fibonacci 116. The minimum number of arithmetic operations required to
values. Write the box number and the corresponding evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given
contents in your answer book. value of X, using only one temporary variable is _____.
(b) What is the time complexity of the resulting program [2014, Set-3, 1 Mark]
when computing fib(n)?
S3-78 Programming & Data Structures

7. (c) The process of assigning load addresses to the


CONCEPTUAL MCQs
various parts of the program and adjusting the code
1. (a) From the given declaration, it is obtained that s is an and date in the program to reflect the assigned
array denoted by s[10], containing 10 elements addresses is called relocation. Suppose any default
which are pointers indicated by the symbol, *, to location say x is added to all the addresses in the
structure of type node as defined by struct node code leading to correct references. So, it is assembler
statement. whose output must distinguish those portions of the
2. (d) X - A pointer is assigned to NULL without freeing instructions and addresses that are relocatable.
memory so a clear example of memory leak. Y - 8. (b) (a) There is no such restriction in C language
Trying to retrieve value after freeing it so dangling (b) True
pointer. Z - Using uninitialized pointers. (c) False. In C, variables are statically scoped, not
3. (c) X. depth first search is done in stack. dynamically.
Y. breadth first search is done in queue (d) False. The activation records are stored on the
Z. sorting is done in a heap. same stack.
4. (c) (XYZ) indicates that Y is left sub-tree and Z is right 9. (b) The results returned by function under value &
subtree reference parameter passing may differ in presence
Node is X of loops.
10. (a) A stack machine implements registers with a stack.
The operands of the arithmetic logic unit (ALU) are
always the top two registers of the stack and the
result from the ALU is stored in the top register of
the stack. 'Stack machine' commonly refers to
computers which use a Last-in, First-out stack to
hold short-lived temporary values while executing
As per given in the questions: individual program statements. The instruction set
(1 (234) (567)) carries out most ALU actions with postfix (Reverse
We get, the following tree Polish notation) operations that work only on the
expression stack, not on data registers or main
memory cellsThe same opcode that handles the
frequent common case of an add, an indexed load, or
a function call will also handle the general case
involving complex subexpressions and nested calls
11. (d) The path for searching dynamic libraries is not
known till runtime. So the intruders may place the
malicious programs in the DLL location and
1 is the root node cryptographic procedures are not available for
2 and 3 are the non-leaf node dynamic linking.
4, 5, 6, 7 are the leaf node which may be null or 12. (b) 2 stacks . You can even simulate a queue using only
further nested because in a binary tree every node one stack. The second (temporary) stackcan be
has 0 or children and not just 1. simulated by the call stack of recursive calls to the
5. (a) Aliasing describes a situation in which a data insert method.
location in memory can be accessed through different The principle stays the same when inserting a new
symbolic names in the program. Thus, modifying the element into the queue:
data through one name implicitly modifies the values • You need to transfer elements from one stack to
associated to all aliased names, which may not be another temporary stack, to reverse their order.
expected by the programmer. As a result, aliasing Then push the new element to be inserted, onto
makes it particularly difficult to understand, analyze the temporary stack.
and optimize programs. Thus, multiple variables Then transfer the elements back to the original
having same memory location. stack.
6. (a) From the given conditions it can be clearly concluded • The new element will be on the bottom of the
that, the given sequence rotates s left by k stack, and the oldest element is on top (first to
positions. be popped).
Programming & Data Structures S3-79

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.

49. (b) Given are 10, 1, 3, 5, 15, 12, 16


10
10
10
1 3 5 1
10
1
1 3
3
5

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

So, resulting hash table

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

Hence, the answer is (b) only two.


1 (Q c = 0 in this call)
\ Answer is = x4 * x * x * x.
1+1=2 The final value of x = 9
\ 94 = 6561 i.e., Option (b)
S3-90 Programming & Data Structures

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

Quick Revision Material

ALGORITHM ANALYSIS AND DESIGN


Any Algorithm must satisfy the following criteria (or
C.g(n)
Properties) No
f(n) Matter
1. Input: It generally requires finite number of inputs.
2. Output: It must produce at least one output. F(n)
3. Uniqueness: Each instruction should be clear and
unambiguous.
4. Finiteness: It must terminate after a finite number of steps. n0
n
ASYMPTOTIC NOTATIONS Fig. 1
These notations are used to describe the Running time of an For all values of n to the right of n 0, the value of f(n) is always lies
algorithm, in terms of functions, whose domains are the set of on or below Cg(n).
natural numbers, N = {1, 2, ……}. Such notations are convenient THE NOTATION W (BIG 'Omega')
for describing the worst case running time function. T(n) (problem O-Notation provides as asymptotic upper bound for a function;
size input size). The complexity function can be also be used to W-Notation provides as asymptotic upper bound for a function;
compare two algorithms P and Q that perform the same task. The W-Notation, provides an asymptotic lower-bound for a given
basic Asymptotic Notations are: function.
1. O(Big-"Oh") Notation. [Maximum number of steps to solve
a problem, (upper bound)] We say that the function f (n) = W( g (n))) [read as "f of n is big
2. W (Big-"Omega") Notation [Minimum number of steps to "Omega" of g of n"], if and only if there exist two positive
solve a problem, (lower bound)] constants C and n0 such that
3. q (Theta) Notation [Average number of steps to solve a f (n) ³ C.g (n) : "n ³ n0
problem, (used to express both upper and lower bound of a
given )f(n)).

THE NOTATION O (BIG 'Oh') C.g(n)


No
Big 'Oh' Notation is used to express an asymptotic upper bound f(n) Matter f(n) = W g(m)
(maximum steps) for a given function f(n). Let f(n) and g(n) are
two positive functions, each from the set of natural numbers F(n)
(domain) to the positive real numbers.
We say that the function f(n) = O (g(n)) [read as "f of n is big
"Oh" of g of n"], if there exist two positive constants C and N0
such that n0
f (n) £ C.g (n) : "n ³ n0 n
Fig. 2
The intuition behind O-notation is shown in figure-1
Note that for all values of f(n) always lies on or above g(n).
S3-92 Algorithm Analysis

THE NOTATION q (Theta) 5. Y ¬ Y - { y}


Q-Notation provides simultaneous both asymptotic lower bound
and asymptotic upper bound for a given function. 6. T ¬ T È {( x, y )}
Let f(n) and g(n) are two positive functions, each from the set of 7. end while
natural numbers (domain) to the positive real numbers. In some
DIVIDE AND CONQU ER
cases, we have f (n) = O( g ( n)) and f = W( g (n)) then
In its simplest form, a divide-and-conquer algorithm divides the
f (n) = Q( g (n)) . problem instance into a number of subinstances, recursively
We say that the function f (n) = Q( g (n)) [read as "f of n is solves each subsistences parately, and then combines the
solutions to the subinstances to obtain the solution to the original
Theta" of g of n"], if and only if there exist three positive constants
problem instance.
C1, C2 and n 0 such that
C1 .g (n) £ f (n) £ C2 .g (n) for all n ³ n0 ...(i) BINARY SEARCH
(Note that this inequality (1) represents two conditions to be The algorithm is as follows
satisfied simultaneously viz C1 .g (n) £ f (n) and Input : An array A [1..n] of n elements sorted in non-decreasing
order and an element x.
f (n) £ C2 .g (n);
Output : j if x = A [j], 1 £ j £ n, and 0 otherwise.
clearly this implies 1. binarysearch (1, n)
if f(n) = O (g (n)) and f = W (g(n)) then f(n) = Q (g(n)). Procedure binarysearch (low, high)
The following figure-1 shows the intuition behind the Q-Notation. 1. if low > high then return 0
2. else
3. mid ¬ [(low + high)/2]
c2g(n) 4. if x = A [mid] then return mid
5. else if x < A [mid] then return binary search (low, mid–1)
f(n) 6. else return binarysearch (mid + 1, high)
c1g(n)
7. end if
f(n)
f(n) = q (g(n)) SO RTING AND SEARCHING
Henceforth, in the context of searching and sorting problems, we
will assume that the elements are drawn from a linearly ordered
set, for example the set of integers.
n n0
Let A[1..n] be a sequence of n elements. Consider the problem of
determining whether a given element x is in A. This problem can
be rephrased as follows. Find an index j; 1 £ j £ n, such that
Fig. 3 x = A[j] if x is in A, and j = 0 otherwise. A straightforward approach
Note that for all values of n to the right of the n0 the value is to scan the entries in A and compare each entry with x. If after
of f(n) lies at or above C1g(n) and at or below C2.g(n). j comparisons, 1 £ j £ n, the search is successful , i.e., x = A[j], j is
Hence inequality (1) simultaneously satisfied for C1 = 1, returned; otherwise a value of 0 is returned indicating an
C2 = 2 and n ³ 1 . unsuccessful search. This method is referred to as sequential
Hence f(n) = Q (g(n)). search. It is also called linear search.
Minimum Cost Spanning Trees (Prim's Algorithm) ALGORITHM LINEAR SEARCH
Input : An array A [1..n] of n elements of an element x.
The algorithm is outlined below. It finds the set of edges T of a
Output : j if x = A [j], 1 £ j £ n, and 0 otherwise.
minimum cost spanning tree.
1. i¬1
1. T ¬ {}; X ¬ {1}; Y ¬ V – {1}
2. while Y ¹ {} 2. while (j < n) and ( x ¹ A[ j])

3. Let (x, y) be of minimum weight such that x Î X and y ÎY . 3. j ¬j+1


4. end while
4. X ¬ X È { y} 5. if x = A [j] then return j else return 0
Algorithm Analysis S3-93

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

4. if A [j] £ x then 4. SIFT-DOWN (A[1..j – 1], 1)


5. i ¬i+1 5. end for
6. if i i ¹ j then interchange A[i] and A[j] Algorithm heapsort sorts n elements in O(n log n) time and Q (1)
space.
7. end if
Hashing
8. end for
• The integer h(x) is called the hash value of key x
9. interchange A [low] and A[i]
• A hash table for a given key type consists of
10. w ¬ i
11. return A and w – Hash function h
The number of element comparisons performed by the above – Array (called table) of size N
algorithm is exactly n - 1. Thus, its time complexity is Q(n). • When implementing a dictionary with a hash table,
Sorting Algorithm the goal is to store item (k, o) at index i = h(k).
In its simplest form, Algorithm quicksort can be summarized as Example
follows.The elements A[low::high] to be sorted are rearranged • We design a hash table fora dictionary storing items
using Algorithm split so that the pivot element, which is always (SSN, Name), where SSN (social security number) is a
A[low], occupies its correct position A[w], and all elements that nine-digit positive integer
are less than or equal to A[w] occupy the positions A[low::w - 1], • Our hash table uses an array of size N = 10,000 and
while all elements that are greater than A[w] occupy the positions the hash function
A[w + 1::high]. The subarrays A[low::w - 1] and A[w+1::high] are h(x) = last four digits of x
then recursively sorted to produce the entire sorted array. Hash Functions
The formal algorithm is shown as Algorithm quicksort. • A Hash function is usually specified as the
Input : An array A[1..n] of n elements. composition of two functions:
Output : The elements in A sorted in non-decreasing order. – Hash code map:
1. quicksort (A, 1, n) C : keys ® integers
Procedure quicksort (A, low, high) Compression map:
1. if low < high then : integers ® [0, N – 1]
2. SPLIT (A [low..high], w) {w is the new position of A[low]} • The hash code map is applied first, and the
3. quicksort (A, low, w – 1) compression map is applied next on the result, i.e.,
4. quicksort (A, w + 1, high)
h(x) = h(c(x))
4. if A [j] £ x then
• The goal of the hash function is to "disperse" the
5. end if
keys in an apparently random way
Heapsort
Given an array A[1..n], we sort its elements in nondecreasing COMPLEXITY OF PROBLEMS
order efficiently as follows. First, we transform A into a heap with The Class P
the property that the key of each element is the element itself, i.e., The class of decision problems P consists of those decision
key(A[i]) = A[i], 1 <i <n. Next, since the maximum of the entries in problems whose yes/no solution can be obtained using a
A is now stored in A[1], we may interchange A[1] and A[n] so deterministic algorithm that runs in polynomial number of steps,
that A[n] is the maximum element in the array. Now, the element i.e., in O (nk) steps, for some nonnegative integer k, where n is the
stored in A[1] may be smaller than the element stored in one of its input size.
children. Therefore, we use Procedure shift-down to transform sorting: Given a list of n integers, are they sorted in nondecreasing
A[1..n –1] into a heap. Next, we interchange A[1] with A[n –1] order?
and adjust the array A[1..n –2] into a heap. This process of set disjointness: Given two sets of integers, is their intersection
exchanging elements and adjusting heaps is repeated until the empty?
heap size becomes 1, at which point A[1] is minimum. shortest path: Given a directed graph G = (V;E) with positive
Input : An array A[1..n] of n elements. weights on its edges, two distinguished vertices and a positive
Output : Array A sorted in non-decreasing order. integer k, is there a path from s to t whose length is at most k?
1. MAKEHEAP (A) 2-coloring: Given an undirected graph G, is it 2-colorable?, i.e.,
2. for j ¬ n down to 2 can its vertices be colored using only 2 colors such that no two
3. interchange A[1] and A[j] adjacent vertices are assigned the same color? Note that G is 2-
Algorithm Analysis S3-95

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

(a) d(r, u) < d(r, v) (b) d(r, u) > d(r, v)


Conceptual MCQs (c) d(r, u) £ d(r, v) (d) None of these
1. Let LASTPOST, LASTIN and LASTPRE denote the last 6. A program takes as input a balanced binary search tree
vertex visited in a postorder, inorder and preorder with n leaf nodes and computes the value of a function
traversal. Respectively, of a complete binary tree. Which g (x) for each node x. If the cost of computing g (x) is min
of the following is always true? [2000, 2 Marks] (number of leaf-nodes in left – subtree of x,number of leaf
(a) LASTIN = LASTPOST – nodes in right – subtree of x) then the worst – case time
(b) LASTIN = LASTPRE complexity of the program is [2004, 2 Marks]
(c) LASTPRE = LASTPOST (a) (n) (b) (n log n)
(d) None of these (c) (n2) (d) (n2 log n)
2. Consider the following functions : 7. Consider the label sequences obtained by the following
pairs of traversals on a labelled binary tree. Which of
f (n) = 3n n these pairs identify a tree uniquely? [2004, 2 Marks]
(i) Preorder and postorder
g (n) = 2 n log 2 n (ii) Inorder and postorder
h(n) = n! (iii) Preorder and inorder
Which of the following is true? [2000, 2 Marks] (iv) Level order and postorder
(a) h (n) is O (f(n)) (a) (i) only (b) (ii) and (iii)
(b) h (n) is O (g(n)) (c) (iii) only (d) (iv) only
8. Two matrices M1 and M2 are to be stored in arrays A and
(c) g (n) is not O (f(n)) B respectively. Each array can be stored either in row–
(d) f (n) is O (g(n)) major or column–major order in contiguous memory
locations. The time complexity of an algorithm to compute
3. Let G be an undirected graph with distinct edge weight. M1 × M2 will be [2004, 2 Marks]
Let e max be the edge with maximum weight and emin be (a) best if A is in row – major, and B is in column major
the edge with minimum weight. Which of the following order
statements is false? [2000, 2 Marks] (b) best if both are in row – major order
(a) Every minimum spanning tree of G must contain e min (c) best if both are in column – major order
(b) If emax is in a minimum spanning tree, then its (d) independent of the storge scheme
removal must disconnect G 9. Suppose each set is represented as a linked list with
(c) No minimum spanning tree contains e max elements in arbitrary order. Which of the operations
(d) G has a unique minimum spanning tree among union, intersection, membership, cardinality will
4. Let G be an undirected graph. Consider a depth – first be the slowest? [2004, 2 Marks]
traversal of G, and let T be the resulting depth – first (a) Union only
search tree. Let u be a vertex in G and let v be the first (b) Intersection, membership
new (unvisited) vertex visited after visiting u in the (c) Membership, cardinality
traversal. Which of the following statements is always (d) Union, intersection
true? [2000, 2 Marks]
(a) {u, v} must be an edge in G, and u is a descendant 10. Suppose there are éê log n ùú sorted lists of êë n / log n úû
of v in T elements each. The time complexity of producing a sorted
(b) {u, v} must be an edge in G, and v is a descendant list of all these elements is
of u in T (Hint : Use a heap data structure) [2005, 2 Marks]
(c) If {u, v} is not an edge in G, then u is a leaf in T (a) O (n log log n) (b) q (n log n)
(d) If {u, v} is not an edge in G, then u and v must have
(c) W (n log n) (d) W (n 3/2)
the same parent in T
11. Let G (V, E) be an undirected graph with positive edge
5. Consider an undirected unweighted graph G. Let a
breadth – first traversal of G be done starting from a node r. weights Dijkstra’s single source shortest path algorithm
Let d (r, u) and d (r, v) be the lengths of the shortest paths can be implemented using the binary heap data structure
from r to u and v respectively in G. If u is visited before with time complexity [2005, 2 Marks]
v during the breadth – first traversal, which of the (a) O (| V |2) (b) O (| E | + | V | log | V |)
following statements is correct? [2001, 2 Marks] (c) O (| V | log | V |) (d) O ((| E | + | V |) log | V |)
Algorithm Analysis S3-97

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

39. Which of the following statements are true?


1. The problem of determining whether there exists a Problem Based MCQs
cycle in an undirected graph is in P. 43. Let s be a sorted array of n integers. Let t(n) denotes the
2. The problem of determining whether there exists a time taken for the most efficient algorithm to determine if
cycle in an undirected graph is in NP. there are two elements with sum less than 1000 in s.
3. If a problem A is NP-complete, there exists a Which of the following statements is true?
non-deterministic polynomial time algorithm to solve [2000, 1 Mark]
A. [2013, 1 Mark] (a) t(n) is 0(1) (b) n £ t(n) £ n log 2 n
(a) 1, 2 and 3 (b) 1 and 2 only
ænö ænö
(c) 2 and 3 only (d) 1 and 3 only (c) n log2 n £ t(n) < ç ÷ (d) t (n) = ç ÷
è2ø è2ø
40. Let G be a graph with n vertices and m edges. What is the
tightest upper bound on the running time of Depth First 44. Let f (n) = n2 log n and g(n) = n (log n)10 be two positive
functions of n. Which of the following statements is
Search on G, when G is represented as an adjacency matrix ?
correct? [2001, 1 Mark]
[2014, Set-1, 1 Mark] (a) f(n) = O(g(n)) and g(n) ¹ O(f(n))
(a) Q(n) (b) Q(n + m) (b) g(n) = O(f (n)) and f(n) ¹ O(g(n))
(c) f(n) ¹ O(g(n)) and g(n) ¹ O(f(n))
(c) Q(n2 ) (d) Q(m2 ) (d) f(n) = O(g(n)) and g(n) = O(f(n))
41. Consider the following rooted tree with the vertex labeled P 45. Maximum number of edges in a n-node undirected graph
as the root : without self loops is [2002, 1 Mark]
n ( n - 1)
(a) n2 (b)
P 2
( n + 1)( n )
(c) n – 1 (d)
2
46. In the worst case, the number of comparisons needed to
Q R search a singly linked list of length n for a given element
is [2002, 1 Mark]
n
(a) log n (b)
2
U V
T (c) log n2 - 1 (d) n
S
47. How many undirected graphs (not necessarily connected)
can be constructed out of a given set V = {v1, v2,....,vn}of
n vertices? [2001, 2 Marks]
W
n ( n - 1)
(a) (b) 2n
2
The order in which the nodes are visited during an in-order n( n -1)
traversal of the tree is [2014, Set-3, 1 Mark] (c) n! (d) 2 2
(a) SQPTRWUV (b) SQPTUWRV 48. A weight – balanced tree is a binary tree in which for each
(c) SQPTWUVR (d) SQPTRUWV node, the number of nodes in the left sub tree is at least
42. Consider the decision problem 2CNFSAT defined as follows: half and at most twice the number of nodes in the right
{f | f is a satisfiable propositional formula in CNF with at sub tree. The maximum possible height (number of nodes
most two literals per clause } on the path from the root to the furthest leaf) of such a
tree on n nodes is best described by which of the
For example, f = (x1 Ú x2) Ù (x1 Ú x 3 ) Ù (x2 Ú x4) is a Boolean following? [2002, 2 Marks]
formula and it is in 2CNFSAT. (a) log2n (b) log4/3n
The decision problem 2CNFSAT is (c) log3n (d) log3/2n
[2014, Set-3, 2 Marks] 49. The number of leaf nodes in a rooted tree of n nodes,
with each node having 0 or 3 children is
(a) NP-Complete.
[2002, 2 Marks]
(b) solvable in polynomial time by reduction to directed
graph reachability. n ( n - 1)
(a) (b)
(c) solvable in constant time since any input instance is 2 3
satisfiable. ( n - 1) ( 2n + 1)
(d) NP-hard, but not NP-complete. (c) (d)
2 3
S3-100 Algorithm Analysis

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

68. Consider the following recurrence : {


int i, n;
( )
T (n) = 2T éë n ùû + 1, T (1) = 1 for (i = 2, 9 < = sqrt (n); i + +)
Which one of the following is true? [2006, 2 Marks] if (n % i = = 0)
{printf (“Not Prime\n”); return 0;}
(a) T(n) = q (log log n) (b) T(n) = q (log n)
return 1;
(c) T(n) = q ( n) (d) T(n) = q (n) }
Let T(n) denotes the number of times the for loop is executed
69. A priority–queue is implemented as a max–heap. Initially, by the program on input n. Which of the following is true?
it has 5 elements. The level – order traversal of the heap
is given below. (a) T (n) = O ( n ) and T ( n ) = W ( n )
10, 8, 5, 3, 2
Two new elements 1 and 7 are inserted in the heap in that (b) T ( n ) = O ( n ) and T ( n ) = W (1)
order. The level – order traversal of the heap after the
insertion of the element is [2005, 2 Marks] (c) T(n) = O(n) and T ( n ) = W ( n )
(a) 10, 8, 7, 5, 3, 2, 1 (b) 10, 8, 7, 2, 3, 1, 5 (d) None of these
(c) 10, 8, 7, 1, 2, 3, 5 (d) 10, 8, 7, 3, 2, 1, 5 77. An array of n numbers is given, where n is an even number.
70. How many distinct binary search trees can be created out
The maximum as well as the minimum of these n numbers
of 4 distinct keys? [2005, 2 Marks]
needs to be determined. Which of the following is true about
(a) 5 (b) 14
the number of comparisons needed? [2007, 2 Marks]
(c) 24 (d) 42 (a) At least 2n – c comparisons, for some constant c, are
71. In a complete k-array tree, every internal node has exactly needed
k children. The number of leaves in such a tree with n (b) At most 1.5n – 2 comparisons are needed
internal nodes is [2005, 2 Marks] (c) At least nlog2 n comparisons are needed
(a) nk (b) (n – 1) k + 1 (d) None of the above
(c) n (k – 1) + 1 (d) n (k – 1) 78. Consider the process of inserting an element into a Max
ænö Heap, where the Max Heap is represented by an array.
72. Suppose T (n) = 2T ç ÷ + n, T(0) = T (1) = 1 Suppose we perform a binary search on the path from the
è2ø
new leaf to the root to find the position for the newly inserted
Which one of the following is false? [2005, 2 Marks] element, the number of comparisons performed is
(a) T (n) = O (n2) (b) T (n) = q (n log n) [2007, 2 Marks]
2
(c) T (n) = W (n ) (d) T (n) = O (n log n) (a) Q (log2 n) (b) Q (log2 log2 n)
73. A scheme for storing binary trees in an array X is as follows. (c) Q (n) (d) Q (n log2 n)
Indexing of X starts at 1 instead of 0. The root is stored at 79. A complete n-array tree is a tree in which each node has n
X[1].For a node stored at X[i], the left child, if any, is stored children or no children. Let l be the number of internal nodes
in X[2i] and the right child, if any in X[2i | 1]. To be able to and L be the number of leaves in a complete n-array tree. If
store any binary tree on n vertices the minimum size of X L = 41, and l = 10, what is the value of n? [2007, 2 Marks]
should be [2007, 2 Marks] (a) 3 (b) 4
(a) log2 n (b) n (c) 5 (d) 6
(c) 2n + 1 (d) 2n – 1 80. Consider a hash table of size seven, with starting index zero,
74. Consider a weighted complete graph G on the vertex set {v1, and a hash function (3x + 4) mod 7. Assuming the hash table
v2, .... vn} such that the weight of the edge (vi, vj) is 2|i – j|. is initially empty, which of the following is the contents of
The weight of a minimum spanning tree of G is the table when the sequence 1, 3, 8, 10 is inserted into the
[2007, 2 Marks] table using hashing? Note that ‘–’ denotes an empty location
(a) n – 1 (b) 2n – 2 in the table. [2007, 2 Marks]
(a) 8, _, _, _, _, _, 10 (b) 1, 8, 10, _, _, _, 3
ænö (c) 1, _, _, _, _, _, 3 (d) 1, 10, 8, _, _, _, 3
(c)ç ÷ (d) n 2
è2ø 81. The maximum number of binary trees that can be formed
75. Consider the polynomial p(x) = a0 + a1x + a2x2 + a3x3, where with three unlabelled nodes is [2007, 1 Mark]
(a) 1 (b) 5
a i ¹ 0, " i . The minimum number of multiplications needed
(c) 4 (d) 3
to evaluate p on the input x is [2007, 2 Marks] 82. The height of a binary tree is the maximum number of edges
(a) 3 (b) 4 in any root to leaf path. The maximum number of nodes in a
(c) 6 (d) 9 binary tree of height h is [2007, 1 Mark]
76. Consider the following C code segment: [2007, 2 Marks] (a) 2h – 1 (b) 2h–1 – 1
int is Prime (n) (c) 2h + 1 – 1 (d) 2h + 1
Algorithm Analysis S3-103

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

87. A B-tree of order 4 is built from scratch by 10 successive 6


5
insertions. What is the maximum number of node splitting 3 4
c f
operations that may take place? [2008, 2 Marks] 6
(a) 3 (b) 4
(c) 5 (d) 6 Which one of the following is not the sequence of edges
88. The minimum number of comparisons required to determined added to the minimum spanning using Kruskal’s algorithm?
if an integer appears more than n/2 times in a sorted array of (a) (b, e) (e, f) (a, c) (b, c) (f, g) (c, d)
n integers is [2008, 2 Marks] (b) (b, e) (e, f) (a, c) (f, g) (b, c) (c, d)
(a) Q(n) (b) Q (log n) (c) (b, e) (a, c) (e, f) (b, c) (f, g) (c, d)
(c) Q (log *n) (d) Q (1) (d) (b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
S3-104 Algorithm Analysis

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)

NPC Common Data MCQs


Common Data for Questions 108 and 109
Consider the following C functions :
int f1 (int n)
P NP {
if (n == 0 || n == 1)
(b) return n;
else
return (2*f1 (n – 1) + 3 * f1(n – 2));
NPC }
int f2 (int n)
{
int i;
P=NP int X[N], Y[N], Z[N];
NPC
X[0] = Y[0] = Z[0] = 0;
X[1] = 1; Y[1] = 2; Z[1] = 3;
(c)
for (i = 2; i <= n; i++) {
X[i] = Y[i – 1] + Z[i – 2];
Y[i] = 2*X[i];
Z[i] = 3*X[i];
}
P=NP=NPC return X[n];
}
108. The running time of f1 (n) and f2 (n) are
(d) [2008, 2 Marks]
(a) Q (n) and Q (n) (b) Q (2n) and Q (n)
(c) Q (n) and Q (2n) (d) Q (2n) and Q (2n)
109. f1 (8) and f2 (8) return the values [2008, 2 Marks]
104. Consider a hash table with 9 slots. The hash function is (a) 1661 and 1640 (b) 59 and 59
h(k) = k mod 9. The collisions are resolved by chaining. (c) 1640 and 1640 (d) 1640 and 1661
The following 9 keys are inserted in the order: 5, 28, 19, 15, Common Data for Questions 110 and 111
20, 33, 12, 17, 10. The maximum, minimum, and average chain Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}.
lengths in the hash table, respectively, are Entry Wij in the matrix W below is the weight of the edge {i, j}
[2014, Set-1, 2 Marks]
(a) 3, 0, and 1 (b) 3, 3, and 3 æ 0 1 8 1 4ö
ç ÷
(c) 4, 0, and 1 (d) 3, 0, and 2 ç 1 0 12 4 9÷
105. An ordered n-tuple (d1, d2, .., dn) with d1 ³ d2 ³ ... ³ dn is ç 8 12 0 7 3÷
called graphic if there exists a simple undirected graph with W= ç 1 4 7 0 2÷
÷
ç
n vertices having degrees d1, d2, ..., dn respectively. Which ç 4 9 3 2 0 ÷ø
of the following 6-tuples is NOT graphic? è
[2014, Set-1, 2 Marks] 110. What is the minimum possible weight of a spanning tree T in
(a) (1, 1, 1, 1, 1, 1) (b) (2, 2, 2, 2, 2, 2) this graph such that vertex 0 is a leaf node in the tree T?
(c) (3, 3, 3, 1, 0, 0) (d) (3, 2, 1, 1, 1, 0) [2010, 2 marks]
106. You have an array of n elements. Suppose you implement (a) 7 (b) 8
quicksort by always choosing the central element of the (c) 9 (d) 10
S3-106 Algorithm Analysis

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

G(x) is calculated for each x.


CONCEPTUAL MCQs
With the behaviour, we can easily suggest that
1. (b) Lets, draw a tree in context with the given statements program has linear worst case complexity which is
given by (n).
7. (b) For a tree we not only require in order & preorder
but also postorder traversal.
Preorder & postorder help to determine the roots of
binary subtrees, inorder arranges those roots in
order.
Hence (b) is correct option.
8. (d) Since the matrices are stored in array, there is no
dependence of time complexity on row major or
column major. Here only the starting address is
known & on the basis of indexes the next memory
LASTIN–inorder–GDHBIEJAC locations are calculated.
LASTPRE–Preorder–ABDGHEIJC Hence (d) is correct option.
LASTPOST–Postorder–GHDIJEBCA 9. (d) Membership & cardinality functions takes constt.
Here we can see that last vertex is C ln LASTIN and time i.e. 0(1), but union & intersection require
LASTPRE. emparison of 1 element with all the other elements so
2. (d) Solution is obtained by solving the given f (n) and these two would be slowest.
h(n) cannot be solved further. We need to solve g(n). Hence (d) is correct option.
10. (a) There are log n sorted lists, with n / logn elements
12 C each, total elements n. We need to merge these heap
A & procedure sorted. Merging take.
22 log n time & sorting takes 0(n log n).
4
Overall to produce sorted result take 0(n log log n)
E 9 F 11. (b) Dijkstra Algorithm for every vertex we consider the
8
binary heap to find shortest path. This take V logV
6 7
3 time.
B And we need to transverse each edge 1 time atleast.
14 D
So overall complexity O ((| E | + | V |) log | V |)
Solving g(n) will bring out a relation related to f (n). The 12. (c) Given adjacency matrix of order 4 is 4*4
complexity of f (n) is hence, f (n) is O(g (n)). 0 0 1 1 1
3. (c) The minimum spanning tree will contain both
1 1 0 1 1
maximum and minimum edge.
For example, 2 1 1 0 1
The edge ED is the minimum edge with weight = 3 3 1 1 1 0
The edge CF is maximum edge with weight = 22
4. (c) G is an undirected graph. Now, when G is traversed
via depth first. The resultant obtained is T (depth
first tree). V is the first vertex visited after visiting u.
Now, if u and v are not connected, then no cycle is
formed and u is a leaf in T.
However, if u and v are connected, then a cycle will There can be many min spaning but all of n – 1 cost
be formed.
5. (c) In BFS if u is visited before v then either u is some
levels before v or u &v are at the same level but u
is leftmost in v .
d(r,u) # d(r,v)
Hence (c) is correct option
6. (a) As given, input is a balanced binary search tree with
So on.
n leaf nodes.
Algorithm Analysis S3-109

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

min cent has 3 edges.


Two edge & vertex disjoint paths are present can be
in preorder b is before d e. & c is before f g. seen in two spanning trees but option (A) is false for
K=2 2K – 2= i.e 2 edges
should be there but it is not true.
34. (b) Statement I is incorrect.
debfgca The cyclomatic complexity of the module is not equal
to maximum number of linearly independent circuits in
the graph.
31. (a) The complexities of worst case when all the elements Statement II is correct.
are reverse sorted for all algorithms are. The cyclomatic complexity of a module is the number
Norge 0(nlog2n) of decisions in the module plus one, where a decision
is effectively any conditional statement in the module.
Quick 0( )
Statement III is correct.
Selection 0( ) The cyclomatic complexity can also be used as a
Bubble 0( ) number of linearly independent paths that should be
Merge no has no effect of input nature since it keeps tested during path coverage testing.
35. (c) Problems which are both NP &NP hard are called NP
on dividing into
complete problems. So option (C) is correct option.
2 problems of size 4/2 so complexity is lower then other (a) Can’t be correct since P€NP, so there can be any
three. Algorithm with P time.
32. (b) W is an integer so the time taken by the algorithm is (b) Is not true, if some solved deterministically but if
Q (n) only. Since subset problem is NP complete, it not NP complete then can’t be P=NP.
(d) Is not correct because some problems which are
should be in class NP & NP hard, so option (C) & (D)
NP decidable under certain conditions.
are true. 36. (b) The Bellman-Ford algorithm solves the single-source
Using unary integer the algorithm will be solved in Q (n) shortest paths problem for a graph. This is done with
time but using binary it would take more time depending both positive and negative edge weights.
upon no. of bits. Let pictorially understands the concept of the Bellman-
Ford algorithm.
Algorithm Analysis S3-111

t x executed then case B and then case C and then case D


5 and E and finally the default case will be executed and
¥ ¥
6 –2 print.
–3 Choice A
8 –4 7 Choice B No choice
s 0 39. (a) Using Depth First search Algorithm to check if there
2
is a cycle in an undirected graph. Whenever a back
7 ¥ ¥ edge is encountered in DFS then gives undirected
y 9 z graph which has a cycle.
Initialization 1. Also if there is a cycle in the undirected graph,
we must encounter a back edge in DFS. DFS
t 5 x can be done a O (| E | + | V |) time for graph G
2 4 = (V, E). So it can be in P.
–2
6 –3 2. P Í NP, This is also in NP.
3. NP-complete problem A Î NP by definition
s 0 8 –4 7 every problem in NP can be solved in
2 polynomial time using non-deterministic turing
7 7, s 2, t machine. So, answer is (a) i.e., 1, 2, 3 are true.
9 40. (c) Let the graph G contains n vertices. When the graph
y z is represented as an adjacency list, the depth first
After pass 1 search of the graph takes Q (m + n) time.
However, when the graph is represented as Adjacency
t 5 x matrix, since it has a size of n × n, to perform depth
6 ¥ first search on the graph, for every vertex, we
6 –2
–3 transverse the row corresponding to that vertex to
find out all adjacent vertices. This need to be
s 0 8 –4 7 performed for all n vertices (n times for each vertex).
2 So, the time complexity becomes
7 Q (n × n) = Q (n2)
7, s ¥
9 C
y z F
After pass 2
A B
t 5 x
6 4
6 –2
–3 E
8 7 D
s 0 –4 (Graph G)
2
Adjacency List:–
7 7, s 2, t
9 Vertex Neighbours
y z
After pass 3 A B, C, E, F
The order of edges examined in each pass B A, D
(t, x), (t, z), (x, t), (y, x), (y, t), (y, z), (z, x), (z, s), (s, t), C A, F
(s, y). D B
37. (c) In selection sort the worst case would be when the
elements are reverse sorted, here the algorithm selects E A
the min element the first element, and during linear F A, C
scan if element found min then a swap takes place.
So during n iterations maximum. Adjacency Matrix:
n swap can occur in each iteration. A B C D E F
No. of swaps = n[n + (n – 1) + (n – 2) ............1]
= Q(n2) is correct option. A é0 1 1 0 1 1ù
38. (c) In switch case statements, there can be more cases, B ê1 0 0 1 0 0 úú
which case satisfied the condition will be executed, so ê
C ê1 0 0 0 0 1ú
we have to add break statement after every case in ê ú
switch. If there is no break statement then all switch D ê0 1 0 0 0 0ú
cases will be executed and default case will also be E ê1 0 0 0 0 0ú
executed. ê ú
In the given program, there is no error so, case A is F ëê 1 0 1 0 0 0 ûú 6 ´ 6
S3-112 Algorithm Analysis

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

Here, A to B will not cost only 1 as they are not


connected. So, they needs to be connected. Index Hash value
54. (b) Starting from vertex a 4322 2
{(a, b), (a, c), (a, d), (a, c)} min = (a, c) = 1
{(a, b), (a, d), (a, e), (c, d)} min = (a, d) = 2 1334 4
{(a, b), (a, e), (c, d), (b, d), (d, h)} min = (b, d) = 3 1471 1
(c, d) not selected since it make cycle 9679 9
{(a, b), (a, e), (d, h), (b, g)} min = (b, g)=2
{(a, b), (a, e), (d, h), (g, h), (g, j), (g, i)} (g, h) =8 1989 9
{(a, e), (d, h), (g, j), (g, i), (h, i), (h, f), (e, h)} (h, i) = 4 6171 1
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h)(e, i), (f, i), (j, i)} min 6173 3
= (e, i) = 2
4199 9
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h), (f, i), (j, i), (e, f)} = 4
{(a, e), (d, h), (g, j), (g, i), (e, h), (f, i), (j, i), (e, f)} (j, i) = 5 By the table above, it is observed that statement 1
8 15 19 14 8 9 5 11 and statement 2 are correct.
Sum 1 + 2 + 3 + 2 + 8 + 4 + 2 + 4 + 5 61. (c) Sorting worst case occurs when arrays are reverse
= 31 sorted, we need to select every element once & for
Hence (b) is correct option. every element min no. of comparison might be log 2n.
55. (b) Sequence asbscsaedsceesfsbedegseefehsgehe So overall min. complexity 0(n log n)
No. of rooms 0 1 2 3 2 3 2 3 4 3 2 3 2 1 2 1 0 Hence (c) is correct option.
Maximum no. of rooms required at a time = 4 option 62. (a) Statement 1 is correct
(b). Consider k to be constant
Here the logic is very simple increase the no. of room f(n) = (n + k)m
if some activity start & decrease by 1 if activity ® f(n) = (1 + n)m
ends. ® f(n) = O(nm)
56. (d) Here A during initialization gives the adjacency Statement 2 is correct
matrix for directed graph G(V, E). And for very (j,k) f(n) = 2n+1
we calculate A[j,k], which stores maximum of the sum ® f(n) = 2n.2
of edges making a simple path. ® f(n) = O2n
So if there exists a simple path from j to k . A[j,k] Statement 3 is incorrect
contain no. of edges in that path. f(n) = 22n+1
a b c ® f(n) = 22n.2
a 0 1 1 ® f(n) = O22n
b 0 0 1 Therefore, we can see that the only statement 3 is false.
c 0 0 0 63. (d) DFS traversal takes the path to the end & then move
57. (c ) Here the fragment of code contains for loop which to other branch.
goes from 1 to n. a
Since due to given conditions m < n.
So complexity of code is q(n) e b f
Hence (c) is correct option.
58. (d) The C function given above is resursive. h
g
The output of the program thus, obtained is

Hence option (d) is correct.


64. (a) In gcd is replaced by n/m in every iteration so
running time has to be less than O(n) or W (n) even
less than q( n).
Such inputs which produces the output in the form as It has to be Q (log2 n) since recursion cause the
given in the figure have the complexity of the order of 2n. problem size reduced by n/2 every iteration.
Therefore, the complexity is O (2n). Hence (a) is correct option.
59. (a) 65. (d) Here T(n) = T( n) + n
60. (c) The solution can be achieved by finding the hash e.g. n = 16, n = 4, n = 2 so
values of the input. Recursion tree
S3-114 Algorithm Analysis

69. (d) Initial level order traversal with 10, 8, 5, 3, 2

We find that Now, let us insert the values


2–k log2n = 1
® 2k = log2n = 1
® k = log2log2n
® T(n) = Q (log2log2 n)
66. (d) Let us check each option

10

8 5

(a) (a – b), (d – f), (b – f), (d – c), (d – e) 3 2 1 7


(b) (a – b), (d – f), (d – c), (b – f), (d – e), (d – c) & (b – f)
has same weight so correct.
inserting 7 here
(c) (d – f), (a – b), (d – c), (d – f), (d – e) possible
(d) (d – f), (a – b), (b – f), (d – e) (d – c).
(b – f) has weight = 2
(d – e) has weight = 3
(d – c) has weight = 2
So (d – e) can't be taken before (d – c)
So (d) is incorrect.
Hence (d) is correct option.
67. (d) The condition given in the FOR loop is
z[i] = {x[i] Ù ~ y[i]} Ú (~ x[i] Ù y[i])
Therefore, the level order traversal comes out to be
Now, we clearly can see that the condition reflect the 10, 8, 7, 3, 2, 1, 5
XOR operation and in the XOR operation set 70. (b) The number of keys as per given are 4
obtained is Applying the direct formula
(X Ç Y¢) È (X¢ Ç Y) Bn = 1/(n + 1) × (2n! / n!n!)
Since, the formula is X Ç Y¢ = X¢ – Y where, Bn is number of binary trees and n is the
Result obtained is (X – Y) È (Y – X) number of keys.
68. (a) T(1) = 1 ® Bn = 1/(4 + 1) × (8! / 4!4!)
® Bn = 1/5 × (8 × 7 × 6 × 5 × 4!) / 4!4!
T(n) = 2T( n ) + 1] ® Bn = 8 × 7 × 6/(4 × 3 × 2)
Also we know that log2 2 = 1 ® Bn = 56/4
log2 2 = 1 ® Bn = 14
The total number of binary trees with n = 4 is 14.
n2–k problem size at level k of recursion
71. (c) No. of internal nodes = n
n2–k constant as the recursion is stopped once the Each node has k children
value is achieved. So total nk
Suppose n2–k Leaf nodes = nk – n
Solving, = n(k – 1)
2–k log2 n = 1 So considering not node also.
® k = (log log n) No. of leaf nodes = n(k – 1) + 1
® T(n) = q (log log n) Hence (c) is correct option.
Algorithm Analysis S3-115

72. (b) Since, T(n) 2T(n/2) + 2 for n > 2


æ nö T(n) = 3n/2 – 2
T(n) = 2T ç ÷ + n
è 2ø = 1.5n – 2
T(0) = T(1) = 1 78. (a) In a Max heap we insert 1 element this takes 0 (1) time
T(n) can be further computed as
since it is an array. Now to find correct position we
log n
T (n) = n å (2 / 2)i perform Binary search, & we know BS an array takes
i =0 0(log2n) time
log n So (a) is correct option.
® T (n) = n å (1)i 79. (c) Each internal node has n children & so total nodes I # n
i=0
® T(n) = Q (n log n) No. of leaf in them
73. (b) Right child & left child of element X[i] are shared in I* n – 1
array at X[2i+1] &X[2i] respectively & index is at X[1] I(n – 1)
& X[2] & X[3] are its child. So till index 3 we stored 3 But root can’t produce leaf
elements & so on. So we require the array of size n to I(n – 1) + 1 = L
store n elements. n = L – 1/ l + 1
74. (b) The minimum spanning tree is formed when n=(41 – 1 )/10 +1 =5
Vi ¬ {1, 2, ....} 80. (b) As given,
Lets construct a tree on the basis of Size of the hash table is 7.
(vi, vj) is 2|i – j| Starting index = 0
Considering the maximum value (n) to be 4. Now, hash function h(x) = (3x + 4) mod 7
v1 ® h(x) = (3x + 4) mod 7
® h(1) = (3.1 + 4) mod 7
2 |2 – 1| 2 |3 – 2| h(1) = 7 mod 7 = 0 at the 0th location
Similarly, h(3) = 6th location
v2 v3 and h(8) = 0th location
Since, 0th position is already occupied then the location
2 |4 – 3| will be next location to it. So, h(8) will be 1st location.
Also h(10) = 6th location and the 6th position is
v4 occupied, so h(10) is hashed to 2nd position.
As Vi is connected to Vi + 1, Diagrammatically.
The minimum weight of each edge = 2
Therefore, the weight of tree with n – 1 edges 0 1
= 2(n – 1) = 2n – 2. 1 8
75. (a) The minimum number of multiplications can be found
out by simplifying the given expression 2 10
p(x) = a0 + x(a1 + a2x + a3x2) 3 –
® p(x) = a0 + x(a1 + (a3x + a2)x) 4 –
Here we can see three multiplications
1. a3 *x 5 –
2. x(a2 + a3x) 6 3
3. x * (a1 + x(a2 + a3x))
76. (b) The loop runs from 2 to n . So maximum iterations can
be n. 81. (b) It is given that n = 3
When n = 2 loop has only 1 iteration so. 1 &n are lower
& upper bounds respectively. n +1
( )
1 2n
Cn

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

g(n) = O(n!) Complexity of this algorithm is same as 1 DFS run


h(n) = O (nlogn)
0(m + n) since
Now,
As per the asymptotic order of function n log n £ C2 n DFS is the basis of articulation point.
for all n ³ n 0 92. (b) Pivot in guide sort is the index which is sorted in that
Let us assume C = 1 and n 0 = 2 run, all the elements in its left are smaller than it &
It comes out to be 2 log 2 ³ 22 elements greater than it are on its right side.
® h(n) = O(f(n)) ® one result So the recursion becomes.
Now, T(n) = T(n/4) + T(3n/4) + n
g(n) = n! & f(n) = 2n
As per the asymptotic order of function Solution to this recursion is Q (nlogn)
93. (d) Kruskal’s algorithm, arranging edges in ascending
n! ³ C2n for n £ n 0
Let us assume C = 1 and n = 4 order.
{2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6}
24 ³ 24
³ 16
® g(n) = W (f(n)) ® second result
Therefore, the two results are
h(n) = O(f(n)); g(n) = W (f(n))
90. (c) Applying BFS algorithm on the following figure
M N O (a)

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

(a, c) can’t be taken after (b, c).


91. (c) The algorithm we use for finding the number of Hence (d) is correct option.
connected components in an undirected graph on n 94. (c) Enter the keys and check if the collision occurs. If the
vertices is to calculate articulation point detection collision occurs then at what point.
Key 12
algorithm.
12 mod 10 = 2
This articulation point divides the graph into 2 Key 18
connected components. 18 mod 10 = 8
Key 13
13 mod 10 = 3
Key 2
2 mod 10 = 2 ® Collision occurred
S3-118 Algorithm Analysis

(2 + 1) mod 10 = 3 ® Collision tree with n nodes is O (n).


(3 + 1) mod 10 = 4 99. (c) The time complexity of Bellman-Ford algorithm on a
Key 3 graph with n vertices and m edges is O (nm).
3 mod 10 = 3 For a complete graph, m = nC2 = O (n2)
(3 + 1) mod 10 = 4 ® Collision (Since there is an edge between all pair of vertices)
(4 + 1) mod 10 = 5 \ The complexity = O (n2 . n)
Key 23 = O (n3)
23 mod 10 = 3 ® Collision \ Solution is (c).
(3 + 1) mod 10 = 4 ® Collision 100. (a) To compute the worst case time complexity of a
(4 + 1) mod 10 = 5 ® Collision sequence of n queue operations on an initially
(5 + 1) mod 10 = 6 empty queue is q (n).
Key 5 Complexity of a squence of 'n' queue operations =
5 mod 10 = 5 ® Collision Total complexity of Enqueue operations (a) + Total
(5 + 1) mod 10 = 6 ® Collision complexity of Dequeue operations (b).
(6 + 1) mod 10 = 7 Total complexity of Dequeue operations (b) £ Total
Key 15 complexity of Enqueue operations
15 mod 10 = 5 ® Collision b£a ...(i)
(5 + 1) mod 10 = 6 ® Collision Total complexity of queue operations (a) £ n ...(ii)
(6 + 1) mod 10 = 7 ® Collision Total complexity of n operations = a + b
(7 + 1) mod 10 = 8 ® Collision £a+a [From ...(i)]
(8 + 1) mod 10 = 9 £n+n [From ... (ii)]
This gives us the following has table £2 n
\ Worst Case Time Complexity of 'n' operations is
0 (a) q (n).
1 101. (b) The return value of the function is q (n2 log n)
2 12 n
3 13 The outer for loop goes + 1 iterations.
4 2 2
5 3 The inner for loop runs independent of the outer
6 23 loop.
7 5 n
8 18 And for each inner iteration, gets added to k.
2
9 15
n
95. (a) For n < = 3 T(n) = n \ × # outer loops × # inner loops per outer loop.
2
i.e Q (n) # Inner loops = q (log n) [Q 2q(log n) = q (n)]
For n > 3
n én ù
T(n) = T(n/3) + Cn \ ´ ê + 1ú .q(log n) = q(n2 log n)
This can be solved by Master’s Theorem 2 ë2 û
a = 1 b = 2 logba = log31= 0 102. (b) Only REQ2 can be permitted.
f (n) = Cn 103. (d) P = NP = NPC
n logba < f(n) We know that clique problem is NP - Hard.
n0 < f(n) Given that it can be solved in polynomial time.
So, T (n) = q(f(n)) case III We also know that a problem is NPC if it is both NP
= q(Cn) and NP hard. So using given also it can also be solved
= q(n) in polynomial time.
Whole complexity ¥ n A problem in NP can be transformed in NPC in
T(n) =Q(n)+Q(n) polynomial time; so NP problem can also be solved in
= q(n) polynomial time using given algo.
Hence (a) is correct option. Finally P is the set of all problems that can be solved
10n log10 n 10log10 in polynomial time, hence we get
96. (c) = = approx 106 P = NP = NPC.
2 0.001
0.0001 n 104. (a)
Therefore, the value of k comes out to be 6. Given no. of slots = 9
97. (b) The tightest upper bound that represents the Given hash fune (k) = k mod 9.
number of swaps required to sort n numbers using Collisions are resolved by chaining.
selection sort are O (n). Given 9 keys : 5, 28, 19, 15, 20, 33, 12, 17, 10.
98. (c) The tightest upper bound that represents the time High table after insertions will be as follows :–
complexity of inserting an object into a binary search
Algorithm Analysis S3-119

Key (Place in Hash descending order, irrespective of position of pivot


Table) element in array.
0 5 mod 9 = 5 107. (a) Insertion done is such a way that first three slots
are unfilled
1 28 ® 19 ® 10 28 mod 9 = 1 First insertion
2 20 19 mod 9 = 1 97 C1 97
P(A) = 100 C = 100
3 12 15 mod 9 = 6 1
Second insertion
4 20 mod 9 = 2
97 C1 97
5 5 33 mod 9 = 6 P(B) = 100 C = 100
1
® 12 mod 9 = 3 Third insertion
6 15 33
7 97 C1 97
17 mod 9 = 8 P(C) = 100 C = 100
1
8 17 10 mod 9 = 1 Total probability = P(A) × P(B) × P(C)
(Hash table)
Maximum chain length = 3 (At position 1) 97 97 97
= ´ ´
Minimum chain length = 0 (At positions 0, 4, 7) 100 100 100
0 + 3 +1+1 + 0 +1+ 2 + 0 +1 9
= (97 × 97 × 97)/ 1003
Avg chain length = = =1
9 9 COMMON DATA MCQs
105. (c) An ordered n type is graphic if it is a degree sequence
108. (b) Procedure f1 has the nature
of some simple undirected graph. options with
T(0) = 0, T(1) = 1=20
corresponding graphs are shown below:–
T(n) = 2T(n – 1)+3T(n – 2)
(a) is Graphic seq. (1, 1, 1, 1, 1, 1)
Solution to this recursion is 2n
A B So Q (2n)
Procedure f2 has a single for loop from 2 to n so the
C D complexity will be Q(n).
Hence (b) is correct option.
109. (c) For f(1), we are given that
E F
(2 * f1 (n –1) + 3 * f1 (n – 2))
(b) is Graphic seq. (2, 2, 2, 2, 2, 2) For f(2), we are given that
A B C X[0] = Y[0] = Z[0] = 0;
X[1] = 1; Y[1] = 2; Z[1] = 3;
And for loop we are given that:
X[i] = Y[i – 1] + Z[i – 2];
Y[i] = 2 * X[i];
Z[i] = 3 * X[i];
F E D Calculating f(1),
(d) is Graphic seq. (3, 2, 1, 1, 1, 0) f(n) = (2* f1 (n – 1) + 3* f1(n – 2))
C f(2) = (2* f1 (2 – 1) + 3* f1 (2 – 2))
® f(2) = (2* 1 + 3* 0) = 2
A D F Similarly,
f(3) = 7
B E f(4) = 20
(c) is not graphic seq. (3, 3, 3, 1, 0, 0) f(5) = 61
f(6) = 182
Clearly we can safely remove isolated vertices (i.e. vertices f(7) = 547
with zero degree) to prepare the graph with this degree f(8) = 1640
sequence. Remaining sequence is (3, 3, 3, 1). Let us name Therefore, f1(8) returns 1640.
these as A, B, C, D Now vertex with degree 1 (is D) f2(8) will also return the same value as f2(n) is the
Must be connect only one A, B or C. If we remove this also non-recursive function of f1(n).
then 3 vertices remains A, B and C. One of them will have 110. (a) Let {0,1,2,3,4} be {a,b,c,d,e}
degree = 2 and other's degree = 3. Now remove vertex with
degree 2, finally two vertices remains that must have degree
= 2 which is not possible in a simple undirected graph.
Hence the seq. (3, 3, 3, 1, 0, 0) is not graphic.
106. (a) The highest upper bound for the worst case
performance is O (n 2). This occurs when elements
of the input array are already in ascending or
S3-120 Algorithm Analysis

Drawing spanning true using Prim’s Algorithms start As i = 4


with a Now, k = (4 + 9)/2 = 6
Therefore, y[6] < x is true.
(A) &(a,b),(a,c),(a,d),(a,e) (a,b) = 1
® i = 6 and j = 9
(B) &(a,c), (a,d), (a,e), (b,c), (b,d), (b,e) (a,d) = 1 III iteration
(D) &(a,c), (a,e), (b,c), (b,d), (b,e), (c,d) (d,e) = 2 As i = 6
(E) &(a,c), (a,e), (b,c), (b,d), (b,e), (c,d), (c,e) (c,e) = 3 Now, k = (6 + 9) / 2 = 7
Therefore, y[7] < x is true
® i = 7 and j = 9
IV iteration
As i = 7
Now, k = (7 + 9)/2 = 8
Therefore, y[8] < x is true
® i = 8 and j = 9
V iteration
As i = 8
Now, k = (8 + 9) / 2 = 8
Therefore, y[8] < x is true
® i = 8 and j = 9
As we have proved that 4[8]! = x & i < j, the program
Weight = 1 + 1 + 2 + 3 = 7 will remain forever in loop.
111. (b) Min possible path from B to C so we draw all paths 115. (a) The correction in the program is needed as in the
from B to C above solution we can see that the program cannot
B ¾® C = 12 work properly.
Now, when y[k] < x
B ¾® AC = 1 + 8 = 9 Increase 1 to k + 1
B ¾® EC = 9 + 3 = 12 Otherwise, decrease j to k –1
B ¾® EC = 4 + 2 + 3 = 9 This will ensure that in the while condition, element
B ¾® A EC = 1 + 4 + 3 = 8 at k position will be checked for equality.
This is min path. 116. (a) We know that characters with high probability need
less number of bits and vice-versa.
Hence (b) is correct option. The number of bits required are 1, 2, 3, 4, 5, 5
112. (b) Dynamic programming can be successfully used, i.e ® a, b, c, d, e, f, are represented by 0, 10, 110, 1110,
n rows for n elements &w + 1 columns. 11110, 11111
Each row is filled on the basis of its previous rows Diagrammatically,
& the (j – ai) – th column.
If any of them is 0 then X[i, j] should be zero.
This require X[i, j] = X[i – 1, j] Ú # [i – 1, j – ai]
Hence (b) is correct option.
113. (c) The algorithm of dynamic programming has n rows
& w columns.These would be filled dynamically
depending upon previous rows &columns. So X[n,w]
will be filled in the last & this would give the result.
If X[n,w] = 1 i.e. TRUE, then we know that there is
subset present
whose sum = integer w.
Otherwise subset not present.
Hence (c) is correct option.
114. (c) We are given that
i = 0; j = 9;
k = (i + j)/2
I iteration
Let consider x = 4
Now, k = (0 + 9)/2 = 4 117. (d) The formula used here is
Therefore, y[4] < x is true
® i = 4 and j = 9
Average length = å Bits required ´ Probability
II iteration = 1/2 × 1 + 2 × 1/4 + 3 × 1/8 + 4 ´ 1/16 + 5 ´ 1/32
Algorithm Analysis S3-121

+ 5 ´ 1/32 L[4, 5] require


= 1.9375 L[3, 4]L[3, 5] here (3, 4), (3, 5) & (4, 4)
118. (c) We need to store largest variables double sum. The
L[4, 4]L[4, 5] need to be calculated before [4, 5]
function foo() has recursive calls n times.
For every recursion we need 1 sum variable, size of So L[p, q] required to be calculated before L[r, s] if
largest double would be 1 : 2 : 3 :........n = n! p < r or q < s.
So complexity 0(n!)
This factorial is the no. of sub recursions in every NUMERICAL ANSWER QUESTIONS
recursion.
Hence (c) is correct option. 4
119. (b) Here we store values in foo(i ) only when they are 126. (a)
completed then in every recursion we require space
to store 1 double.
1 2 3 4 5 6
So overall n calls we require 0(n)
Hence (b) is correct option. (b)
120. (d) As per given, the total tasks are 9.
Let consider R initially empty. Now, R is to be fed
with the tasks. 4 7
The tasks will be allotted to tasks as per the given
profit and associated deadlines.
® T4 and T6 will be left out as the maximum profit 1 2 3 4 5 6 7 8 9 10
is achieved without entering them.
121. (a) This is calculated by summing all the profits given
in the table. This is 5
15 + 20 + 30 + 18 + 18 + 10 + 23 + 16 + 25 = 147
Therefore, the maximum profit is 147.
122. (b) Since, Permutations are equally likely, 1 2 3 4 5 6 7 8 9
Expected number of inversions in a randomly chosen
permutation = 1/2(nC2)
= (1/2) n! (2!.(n – 2)!) émù m
(c) (i) ê ú or
= 1/2 . n(n – 1) (n – 2) !/ (2. (n – 2)!) ë2û 2
= n(n – 1)/4 (ii) m
123. (a) Here at most n inversions are allowed, it means ai>aj 127. 1 to 1
only for n times. Value of a + 10b = 1.
52134 ¾® {(5,2), (2, 1), (5, 1), (5, 4), (5, 3)} We can find the subtree with 4 nodes in O(n) time, we can
Best case of insertion sort when all are sorted takes use following Algorithm:
0(n) time. (1) Transverse the tree in bottom up manner and find
Worst case when reverse sorted take 0(n 2) size of subtree rooted with current node.
So here the solution in between 0(n) & O(n2) (2) If size becomes 4, then print the current node.
Only n inversions means only n comparison required, int print 4 subtree (struct Node *root)
each comparison take log n time. {
So time complexity is 0(n log n). if (root = = NULL)
124. (c) LCS problem is solved using dynamic programming in return 0;
which every row is dependent upon previous rows & int l = print 4 subtree (root ® left);
columns. If two literals at ith row & jth column doesn’t int r = print 4 subtree (root ® right);
if ((l + r + 1) = = 4)
match then.
printf (“%d”, root ® data);
Eve fill l[i, j] with max [L[i–1,j],[I ,j –1]] i.e max of return (l + r + 1)
previous cell in row & column. }
So expr 1 =L[i–1, j–1]+1 128. 506 edges
expr 2 =max([l[i–1,j],L[i,j –1]]) The vertices of Graphs are ordered pair (i, j) where two
vertices (a, b) and (c, d) are connected by an edge only
125. (d) During solution through dynamic programming option
if |a – c| < 1 and |b – d| < 1. Also given that 1 < i < 12,
(b) & (c) are incorrect since the solution is done in row i < j < 12.
major order. But not in column major order. So, for example (1, 2) is connected to (1, 1), (2, 1), (2, 2),
(a) is true but not necessary. (2, 3) and (1, 3)
(d) is correct eg. Similarly (5, 5) is connected to (4, 4), (4, 5), (4, 6), (5, 4),
S3-122 Algorithm Analysis

(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

Quick Revision Material

ALPHABET AND STRINGS 4. q0 Î Q is the start state.


An alphabet is a finite non-empty set of symbols. It is denoted 5. F Í Q is the set of accept states.
by a letter å. Non-Deterministic Finite Automata (NFA)
• å = {0, 1} is a binary alphabet. When the machine is in a given state and reads the next input
• å = {A, B, ........, Z; a, b, c, ........., z} is an english symbol, we know the next state (using transition), i.e. it is
alphabet. determined. This is called deterministic computation. In a non-
A string over an alphabet å is a sequence of any deterministic machine, several choices may exist for the next
number of symbols from å. state at any point. Also, the automation can choose to make
• 0, 1, 11, 00 and 011 are strings over {0, 1}. a transition from one state to another without reading any
OPERATIO NS ON STRINGS symbol. This type of transition is shown below.

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

• (hello)r = olleh; (concatenation)r = noitanetacnoc


q4 {q4 } {q 4 } f
The set of strings created from any number of 4. ql is the start state.
symbols in an alphabet å is denoted by å*.
5. F = {q4}
FINITE AUTOMATA 0, 1 0, 1
A finite automata is a 5-tuple (Q, å, d, q0, F), where
1. Q is a non-empty finite set called states. 1 0, e 1
2. å is a non-empty finite set called alphabet. q1 q2 q3 q4
3. d : Q × å ® Q is the transition function.
S3-124 Theory of Computation
Step of type (i): a Some important points to remember:
a 1. Any DFA is also an NFA.
2. For each NFA, there exist an equivalent DFA.
Step of type (i): b 3. Taking into account above two points, a language is
regular if and only if some NFA recognizes it.
b 4. If n is the number of states in NFA, then the equivalent
DFA will have 2n state including f state.
Step of type (ii): a/b
Converting NFA to DFA
a Let’s have a look at the NFA(N) below that we will be converting
E in DFA(D).

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

FINITE AUTOMATA WITH OUTPUTS REGU LA R EX PRESSI ON


Under finite automata we have two other machines. (a) Mealy The regular expressions are useful for representing certain sets
machine and (b) Moore machine. These machines produces of string in an algebraic fashion. Formal definition of regular
some output also at every state. expressions is as follows:–
(i) Mealy Machine 1. Any terminal symbol, i.e. symbols å including ^ and f
A mealy machine is a tuple are regular expression. When, we view a in å as a
(Q, S, D, d, l, q0) where % %
regular expression, we denote it by a.
Q = finite set of states %
S = finite non-empty set of input alphabets 2. The union of two regular expressions R1 and R2 written
D = the set of output alphabets as R1 + R2 also a regular expression.
d = transition function defined as Q × S ® Q. 3. The concatenation of two regular expressions R1 and
l = the output function defined as S × Q ® D means at R2 written as R1 R2 is also a regular expression.
any state the value of current state and current input 4. The iteration of a regular expression R, written as R* is
defines the output also a regular expression.
q0 = initial state 5. If R is a regular expression, then (R) is also a regular
0/a expression.
6. The regular expression over å are precisely those
q0 q1 obtained successively by the application of the rules 1
to 5 once or several times.
Any regular expression can be converted into a finite automation
0/b that recognizes the language, it describes and vice versa. Some
Here, in the given mealy machine when input 0 is applied basic conversions from regular expression to finite automation
to state q0 it produces output a and when 0 is applied (M) are shown below:–
to state q1 it produces the output b. The transition table
• If r = e, M is
will be represented as
e
s f or s
State Input 0
Next state Output • If r = f, M is s
® q0 q1 a • If r = {a} for some a Î å, M is
q1 q0 b
a
s f
In case of Mealy machine output is ^ if input is ^.
(ii) Moore Machine • If r = r1 + r2, then M is
Moore machine is a set of six tuples (Q S, D, l q0)
where, r1
Q = set of states e S1 f1
S = set of inputs s
D = set of outputs e r2
S2 f2
d = transition function defined as Q × S ® Q
l = output function defined as Q ® D means only the
current state of automata will define the output • If r = r1 . r2, then M is
q0 = the initial state
As we can illustrate the Moore machine in following
example. S1 f1 e S2 f2
Herre, q0 state will generate output a and q1 state will
generate output b. The transition table will be given as r1 r2
State Input = 0 Output • If r = r1, then M is
q0 q1 a e
q1 q0 b
e r1
S S1 f1
0
e
q0/a q1/b
Using the above basic rules / examples, any regular expression
can be converted into a finite automata.
0
S3-126 Theory of Computation

Properties (Identities) of regular expression PUMP ING LEMMA


1. f+ R= R If A is a regular language, then there is a number P (the
2. f R + Rf = f pumping length) where, if S is any string in A of length at least
3. ^R = R ^ = R P, then S may be divided into three pieces, S = xyz, satisfying
the following conditions:–
4. ^ * = ^ and f * = ^
5. R+R=R 1. For each i ³ 0, xy2z Î A
6. R*R*=R* 2. | y| > 0, and
7. RR * = R * R 3. | xy| £ P.
8. (R*)* = R* • If a language does not satisfy these conditions, then it
9. ^ + RR * = ^ + R * R = R* is a non-regular language.
10. (PQ) * P = P (QP) *
11. (P + Q)* = (P * Q*) = ( P* + Q*)*
12. (P + Q) R = PR + QR and R (P + Q) = RP + RQ How to use the Pumping Lemma to prove
that a language L is not regular
Regular expressions over an alphabet å For each l³ 1, find some w Î L of length ³ lso that
no matter how w is split into three, w = u1vu2,
• each symbol a Î å is a regular expression (†)
• e is a regular expression with length (u1v) £ l and length (v) ³ 1.
• is a regular expression there is some n ³ 0 for which u1vnu2 is not in L.
• if r and s are regular expressions, then so is (r|s)
• if r and s are regular expressions, then so is r|s
• if r is a regular expression, then so is (r)*
Every regular expression is built up inductively, CONTEXT FREE LA NGUAGES
by finitely many applications of the above rules. A context free language (CFL) is a language generated by a
context free grammar (CFG). A CFG is a set of rules for deriving
(N.B. we assume e, , (, ), |, and * are not symbols in å.) (or generating) strings (or sentences) in a language.
Informally, a CFG consists of:–
— A set of replacement rules, each having a LHS and a
RHS.
• u matches a Î å iff u = a
— Two types of symbols, variables and terminals.
• u matches e iff u = e
— LHS of each rule is a single variable (no terminals).
• no string matches
• u matches r|s iff u matches either r or s — RHS of each rule is string of zero or more variables and
• u matches rs iff it can be expressed as the concatenation of terminals.
two strings, u = vw, with v matching r and w matching s — A string consists of only terminals.
• u matches r* iff either u = e , or u matches r, or u can be Formally, a CFG is a 4-tuple (V, å, R, S), where
expressed as the concatenation of two or more strings, 1. V is a finite set called variables.
each of which matches r 2. å is a finite set, disjoint from V, called terminals.
3. R is a finite set of rules, with each rule being a variable
Construction of Finite Automata from Regular Expressions
For regular expression (a + b) the FA will be and a string of variables and terminals.
4. S Î V is the start variable.
a
a, b Chomsky Normal Form
or
b A context free grammar is in Chomsksy Normal Form if every
rule is of the form.
For regular expression ab the FA will be
A ® BC
a b
A®a
where, a is any terminal and A, B and C are any variables except
For regular expression a* the FA will be B and C may not be the start variable. In addition, the rule S
® e, where S is the start material is allowed.
a
Backus Naur Form
An example of a context-free grammar in BNF is given
Theory of Computation S3-127

Pumping Lemma for CFL


Example of Backus-Naur Form (BNF)
If A is a CFL, then there is a number P (the pumping length)
Terminals: where, if S is any string in A of length at least P, then S may
x ¢ + – * ( ) be divided into five pieces S = uvwxy satisfying the conditions:–
Non-terminals: 1. for each i ³ 0, uv2wx2y Î A,
id op exp 2. | vx| > 0, and
Start symbol: 3. | vwx | £ P.
exp
TU RING M ACHINES
Productions:
id ::= x | id¢ A turing machine is a 7-tuple (Q, å, G, d, q0, qaccept, qreject),
op ::= + | – | * where
exp ::= id | exp op exp | (exp) 1. Q is the set of states.
2. å is the input alphabet not containing the blank symbol, .
Push Down Automata 3. G is the tape alphabet, where Î G and å Í G.
Push Down Automata are like non-deterministic finite automata 4. d : Q × G ® Q × G × {L, R} is the transition function.
5. q0 Î Q is the start state.
but have an extra component called a stack. The stack provides
additional memory beyond the finite automata provides. 6. qaccept Î Q is the accept state.
Formally, a push down automata is a 6-tuple (Q, å, G, d, q0, F), 7. qreject Î Q is the reject state, where qreject ¹ qaccept.
where Initially M (turing machine) receives its input w Î å* on the
1. Q is the set of states. leftmost n squares of the tape and rest of the tape is blank, i.e.
2. å is the input alphabet. filled with blank symbol. The head starts from the leftmost
3. G is the stack alphabet. square of the tape. Once M has started, the computation
4. d : Q × åe × Ge ® P (Q × Ge) is the transition function. proceeds according to the rules described by the transition
function. If M ever tries to move its head to the left off the left
5. q0 Î Q is the start state, and
hand end of the tape, the head stays in the same place for that
6. F Í Q is the set of accept states. move, even though the transition function indicates L. The
Below is the description of PDA that recognizes the language transition continues until it enters either the accept or reject
{0n 1n | n ³ 0}. Let M1 be (Q, å, G, d, q1, F), where states at which point it halts. If neither occurs, M goes on
Q = {q1, q2, q3, q4} forever. As a TM computes, changes occur in the current state,
å = {0, 1} current tape content and current head location. A setting of
G = {0, $} $ = This signifies that stack is empty these three items is called a CONFIGURATION.
F = {q1, q4} and q7
d is given by the following table, where in blank
entries signify f.

Input 0 1 e 1 0 1 0 1 1 1 0 U U U ........

e e e • The above diagram shows a TM with configuration


Stock 0 $ 0 $ 0 $
10101q7 110.
q1 {(q2, $)} Let C1 and C2 be configuration of M. C1 yields C2 if M
is in configuration C2 after running M in configuration
q2 {(q2, 0)} {(q3, e)} C1 for one step. Suppose d(q1, b) = (q2, C, L), then aaq1
q3 {(q3, e)} {(q4, e)} bb yields aq2 acb. Let w Î å* and M be a turing
machine. M accepts w if there are configs Co, Ci, ...........,
q4 Ck, s.t.
We can also use a state diagram to describe a PDA, as shown — Co = q0 w
below:– — Ci yields Ci + 1 for i = 0, ........., k-1, and
e, e ® $ — Ck contains the accept state qaccept.
q1 q2 0, e ® 0 • A Turing Machine M recognizes a language L if M
accepts exactly those strings in L.
1, 0 ® e • A language L is called recognizable or recursively
enumerable if some TM recognizes L.
q4 q3 1, 0 ® e • A TM decides a language L if M accepts all strings in
e, $ ® e L and rejects all strings not in L.
• A language is context free if and only if some push • A language is called decidable or recursive if some TM
down automata recognizes it. decides L.
• Every regular language is context free language. • L is decidable if and only if both L and Ø L are
recognizable.
S3-128 Theory of Computation

(c) deterministic context-free


Conceptual MCQs (d) recursive
7. Which of the following is true? [2002, 1 Mark]
1. Let L denotes the language generated by the grammar
(a) The complement of a recursive enumerable language
S ® 0S0/00. Which of the following is true?
is recursive
(a) L = 0+ [2000, 1 Mark]
(b) The complement of a recursively enumerable language
(b) L is regular but not 0+
is recursively enumerable
(c) L is context-free but not regular
(c) The complement of a recursive language is either
(d) L is not context-free
recursive or recursively enumerable
2. Consider the following decision problems:
(d) The complement of a context-free language is contxt-
[2000, 2 Marks]
free
P1. Does a given finite state machine accept a given
8. The C language is [2002, 1 Mark]
string?
(a) a context-free language
P2. Does a given context-free grammar generate an
(b) a context-sensitive language
infinite number of strings?
(c) a regular language
Which of the following statements is true?
(d) parsable fully only be a turing maching
(a) Both P1 and P2 are decidable
9. If the strings of a language L can be effectively
(b) Neither P1 nor P2 are decidable
enumerated in lexicographic (i.e., alphabetic) order, which
(c) Only P1 is decidable
of the following statements is true? [2003, 1 Mark]
(d) Only P2 is decidable
(a) L is necessarily finite
3. Which of the following statements is true?
(b) L is regular but not necessarily finite
[2001, 1 Mark]
(c) L is context-free but not necessarily regular
(a) If a language is context-free it can always be a
(d) L is recursive but not necessarily context-free
ccepted by a deterministic push-down automaton
10. The problems 3-SAT and 2-SAT are [2004, 1 Mark]
(b) The union of two context-free languages is context-
(a) both in P
free
(b) both NP-complete
(c) The intersection of two context-free languages is
(c) NP-complete and in P respectively
context-free
(d) undecidable and NP-complete respectively
(d) The complement of a context-free language is
11. The language {ambncm+n|m,n ³ 1} is
context-free
(a) regular [2004, 2 Marks]
4. Consider the following languages:
(b) context-free but not regular
L1 = {WW| W Î {a, b}*}
(c) context-senstitive but not context-free
L2 = {WWR| W Î {a, b}*,WR is the reverse of W}
(d) type-0 but not context-sensitive
L3 = {02i| i si an integer}
i2 12. Consider the following two problems on undirected graphs:
L3 = {0 |i is an integer} a — Given, G (V, E), does G have an independent set of size
Which of the languages are regular? [2001, 2 Marks] |V| – 4?
(a) L1 and L2 (b) L2, L3 and L4 b — Given, G (V, E), does G have an independent set of size 5?
(c) L3 and L4 (d) Only L3 Which one of the following is true? [2005, 2 Marks]
5. Consider the following problem X: (a) a is in P and b is NP-complete
Given a turing machine M over the input alphabet S, any (b) a is NP-complete b is in P
state q of M and a word W ÎS *, does the (c) Both a and b are NP-complete
computation of M on W visit the state q? (d) Both a and b are in P
Which of the following statements about X is correct? 13. Consider the languages: [2005, 2 Marks]
(a) X is decidable [2001, 2 Marks] L1 = {WWR | W Î {0, 1)*}
(b) X is undecidable but partially decidable L2 = {W # WR | W Î {0, 1)*} where # is a special symbol
(c) X is undecidable and not even partially decidable L3 = {W W | W Î {0, 1)*}
(d) X is not a decision problem Which one of the following is true?
6. The language accepted by a push-down automaton in (a) L1 is a deterministic CFL
which the stack is limited to 10 items is best described as (b) L2 is a deterministic CFL
[2002, 1 Mark] (c) L3 is a CFL but not a deterministic CFC
(a) context-free (d) L3 is a deterministic CFL
(b) regular
Theory of Computation S3-129

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) Df Ì Nf and Dp Ì Np (b) Df Ì Nf and Dp = Np (a) not recursive [2007, 2 Marks]


(c) Df = Nf and Dp = Np (d) Df = Nf and Dp Ì Np
(b) is recursive and is a deterministic CFL
17. Consider the machine M: [2005, 2 Marks]
a (c) is a regular language
b b (d) is not a deterministic CFL but a CFL
a b b
24. Which of the following is true? [2007, 1 Mark]

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

38. Which of the following pairs have different expressive


power? [2011, 1 Mark] Problem Based MCQs
(a) Deterministic Finite Automata (DFA) and Non-
deterministic Finite Automata (NFA) 44. Let S and T be languages over S = {a, b} represented by
(b) Deterministic Push Down Automata (DPDA) and Non- the regular expressions (a + b*)* and (a + b)*, respectively.
deterministic Push Down Automata (NPDA) Which of the following is true? [2000, 1 Mark]
(c) Deterministic single-tape turing machine and non- (a) S Ì T (b) T Ì S
deterministic single tape turing machine (c) S = T (d) S Ç T = f
(d) Single-tape turing machine and multi-tape turing 45. What can be said about a regular language L over {a}
machine whose minimal finite state automaton has two states?
(a) L must be {an|n is odd} [2000, 2 Marks]
39. Which of the following statements is/are false? (b) L must be {an|n is even}
1. For every non-deterministic Turing machine, there (c) L must be {an| ³ 0}
exists an equivalent deterministic Turing machine. (d) Either L must be {an| n is odd}, or L must be {an |
2. Turing recognisable languages are closed under n is even}
union and complementation. 46. Given an arbitrary Non-deterministic Finite Automaton
3. Turing decidable languages are closed under (NFA) with N states, the maximum number of states in an
intersection and complementation. equivalent minimized DFA is at least [2001, 1 Mark]
4. Turing recognisable languages are closed under (a) N2 (b) 2N
union and intersection. [2013, 1 Mark] (c) 2N (d) N!
(a) 1 and 4 only (b) 1 and 3 only 47. Consider a DFA over S = {a, b} accepting all strings
(c) 2 only (d) 3 only which have number of a’s divisible by 6 and number of
40. Which of the following is/are undecidable? b’s divisible by 8. What is the minimum number of states
1. G is a CFG. Is L(G) = F? that the DFA will have? [2001, 2 Marks]
2. G is a CFG. Is L(G) = å*? (a) 8 (b) 14
3. M is a Turing machine. Is L(M) regular? (c) 15 (d) 48
4. A is a DFA and N is an NFA. Is L(A) = L(N)? 48. Consider the following two statements:
[2013, 2 Marks] S1 – {02n| n ³ 1|} is regular language.
(a) 3 only (b) 3 and 4 only S2 – {0m1n0m+n|m ³ 1 and n ³ 1|} is a regular language
(c) 1, 2 and 3 only (d) 2 and 3 only Which of the following statements is correct?
41. Which one of the following is TRUE ? (a) Only S1 is correct [2001, 1 Mark]
[2014, Set-1, 1 Mark] (b) Only S2 is correct
(a) The language L = {a b | ³ 0} is regular..
n n
(c) Both S1 and S2 are correct
(b) The language L = {an| n is prime} is regular. (d) None of these
(c) The language L = {w | w has 3k + 1b's for some k Î N 49. The finite state machine described by the following state
with S = {a, b}} is regular.
(d) The language L = {ww | wÎ S* with S = {0, 1}} is x
diagram with A as starting state, where an arc label is
regular. y
42. Let A £ m B denotes that language A is mapping reducible and x stands for 1-bit input and y stands for 2 bit output
(also known as many-to-one reducible) to language B. [2002, 2 Marks]
Which one of the following is FALSE? 0/01
[2014, Set-2, 1 Mark]
0/00 A B C 1/10
(a) If A £m B and B is recursive then A is recursive. 0/01 1/10
(b) If A £m B and A is undecidable then B is undecidable.
(a) outputs the sum of the present and the previous bits
(c) If A £m B and B is recursively enumerable then A is of the input
recursively enumerable. (b) outputs 01 whenever the input sequence contains 11
(d) If A £m B and B is not recursively enumerable then (c) outputs 00 whenever the input sequence contains 10
(d) None of the above
A is not recursively enumerable. 50. The smallest finite automaton which accepts the language
43. Let < M > be the encoding of a Turing machine as a string {x| length of x is divisible by 3} has [2002, 2 Marks]
over S = {0, 1}. Let L = {<M>| M is a Turing machine that (a) 2 states (b) 3 states
accepts a string of length 2014}. Then, L is (c) 4 states (d) 5 states
[2014, Set-2, 2 Marks] 51. Ram and Shyam have been asked to show that a certain
(a) decidable and recursively enumerable
problem P is NP-complete. Ram shows a Polynomial time
(b) undecidable but recursively enumerable
reduction from the 3-SAT problem to II, and Shyam
(c) undecidable and not recursively enumerable
shows a polynomial time reduction from Õ to 3-SAT.
(d) decidable but not recursively enumerable
S3-132 Theory of Computation

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

(c) 2S * is uncountable and S* is countable


0,1 1
S*
(d) Both 2 and S* are uncountable
q0 1 q1 0,1 q2 0,1 q3
Common Data MCQs
Which is the set of reachable states for the input string Common Data for Questions 90 and 91 :
0011? [2014, Set-1, 1 Mark] Consider the following Finite State Automation:
(a) {q0, q1, q2} (b) {q0, q1}
q3
(c) {q0, q1, q2, q3} (d) {q3}
85. Let L be a language and L be its complement. Which one
of the following is NOT a viable possibility? a b
[2014, Set-1, 2 Marks] b b
(a) Neither L nor L is recursively enumerable (r.e.). a b
(b) One of L and L is r.e. but not recursive; the other is q0 q1 q2
a
not r.e. a
(c) Both L and L are r.e. but not recursive. 90. The language accepted by this automation is given by the
(d) Both L and L are recursive. regular expression [2007, 2 Marks]
86. Which of the regular expressions given below represent (a) b * ab * ab * ab (b) (a + b)*
the following DFA? [2014, Set-1, 2 Marks] (c) b* a (a + b)* (d) b * ab * ab *
91. The minimum state automation equivalent to the above FSA
0 0 1 has the following number of states [2007, 2 Marks]
(a) 1 (b) 2
(c) 3 (d) 4
1
Numerical Answer Questions
I 0*1(1+00*1)*
II 0*1*1+11*0*1 92. The length of the shortest string NOT in the language (over
III (0+1)*1 S= {a, b}) of the following regular expression is
(a) I and II only (b) I and III only ______________. [2014, Set-3, 1 Mark]
(c) II and III only (d) I, II, and III a*b* (ba)*a*
S3-136 Theory of Computation

CONCEPTUAL MCQs Also, the problem is not completely undecidable


since, the input and the state is given so after a
1. (b) S®0S0/00 certain point of time the probability of finding out
S®0S0 (type 2 production) the answer increases.
This is a context-free grammar as in CFG, the left 6. (b) It is given that the stack is limited to 10 items
hand side of the production rule has no left and right therefore the stack function is a type of recursion.
context. This directly implies that the language accepted by
S®00 push-down automata is a regular language.
means S®^ (null)* (type 3 production) 7. (a) Option (a) True : The complement of recursive
This is called the regular grammar. language is always recursive.
2. (a) In P1, A given finite state machine accepts a given Option (b) False : The recursively enumerable
string if it is decidable because in decidable problem language is the language, when taken its complement,
there exists a turing machine that gives the correct lose its recursively enumerable nature.
answer for every statement in the domain of the Option (c) False : The complement of recursive
problem. A class of problems with two outputs yes language is always recursive and never recursively
or no is said to be decidable (solvable), if there exist enumerable.
some definite algorithm which always terminates Option (d) False : The complement of context free
(halts) with one of the two outputs yes or no. language is never context-free.
Similarly, in P2, the context-free grammar generates. 8. (a) C language is context-free language by nature.
3. (b) Option (a) False: If the language is context-free then A context-free language is L = {anbn: n ³ 1} that is
it cannot be said that the language will be accepted the language of all non-empty even-length strings. It
by the deterministic push-down automaton as there consists of
are some cases defined where the context-free 1. the entire first halves of which are a’s.
language is not accepted. 2. the entire second halves of which are b’s.
Option (b) True: The union of context-free languages L is generated by the grammar S®aSb|ab, and is
always produces a context-free language but it not accepted by the push-down automaton.
the case with intersection of two context-free M = ({q0, q1, qf}, {a, b}, {a, z}, d, q0, {df}), where
languages. d is defined as follows:
Option (c) False: As discussed in Option (b). d(q0, a, z) = (q0, a)
Option (d) False: Similar to intersection, complement d(q0, a, a) = (q0, a)
of a context-free language is not always a context-free d(q0, b, a) = (q1, x)
language. d(q1, b, a) = (q1, x)
4. (d) Lets study the rgular language first and then will d(q1, l, z) = (qf, z)
udge which language is regular.
Conventions on regular expression. 9. (b) According to the theory of the language, if a
1. Bold face is not used for regular expressions when language is effectively enumerated in lexicographic
the xpression is not confusing. So, for example, order then the language is necessarily a regualr
(r + s) is used instead of (r + s). language.
2. The operation * has precedence over concatenation, Now, the language is arranged alphabetically, so
which further has precedence over union (+). Thus, there are less chances of repetition however, the
the regular expression (a + b(c*))) is written as a + surity is that, the language L is rgular but not finite.
bc*. 10. (c) 3 SAT ® NP-complete problem
3. The concatenation of k r’s, where r is a regular 2 SAT ® P type problem
expression, is written as rk. Thus, for example rr = r 2. 11. (a) L = {am bncm+n|m,n ³ 1}
k A DPDA can accept this language. When a’s and b’s
The language corresponding to r is Lkr
, where Lr
are in input, these are pushed into the stack and
is the language corresponding to the regular when c’s appear in input the a’s and b’s are popped
expression r. For a recursive definition of Lkr . out. If after all c’s are finished, if stack is empty, this
means nc(W) = na (W) + nb(W) and the string is
4. The (r+) is used as a regular expression to represent accepted. Else it is rejected. Now, since a DPDA
Lr+. exists, the language is context-free. Clearly the
L3 = {02i|i is an integer} follows all the conventions language is not regular, since we must count and
of the regular language and therefore, is regular. compare c’s with a’s and b’s which cannot be done
5. (b) Option (d) is incorrect as the problem is a decision by any FA.
problem. Now, we need to check whether the 12. (a)
problem is decidable or not. 13. (b) In all the options there is linear relationship among
The problem is not decidable since the word wÎS. strings so all CFL’s , but L1 & L3 can be accepted by
Theory of Computation S3-137

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

L2 is also NP-complete. Now, L2 ÎP and L2 is finite is not contradictary.


Since, 3 SAT is NP-complete so Õ is also NP \ (a) can be true.
complete. Option (b): L1 ÎNP and L2 ÎP
52. (a) Consider the case where L = (0 + 1)* Now, L2 £ pL1
Here the answer of any turing machine would be yes
and L1Î N P Þ L2ÎNP which does not contradict
since some output is displayed.
L2ÎP.
Consider the case where L = f
and L2 ÎP Þ L1 ÎP L1 £ pL2 which does not
Here, the answer of any turing machine would be
contradict LIÎNP
No since no output is displayed.
\ (b) can be true.
This type of behaviour is displayed by the recursive
Consider (c): L1 undecidable and L2 is decidable
language and therefore, the language L is recursive
Now L1 £ pL2
language and therefore, the language L is recursive.
and L2 is decidable Þ L1 is decidable. which
53. (d) Option (a) solves to (1*0*)1*
contradicts L1 is undecidable.
Option (b) solves to 0 + (0*1*0*)
\ (c) cannot be true.
Option (c) solves to 0*1*10(0*1*)
Consider (d): L1 is RE and L2 and REC.
Therefore, none of the statement has the output
L2 £ pL1 and L1 is RE Þ L2 is RE.
equivalent to the given.
which does not contradict L2 is REC.
54. (c) The strings accepted by the given automata are of
L1 £ pL2 and L2 is REC Þ L1 is REC.
type. Option
which does not contradict that L1 is RE.
1234567
57. (a) This turning machine starts at 90 if it doesn't get any
1– – 1 – – 1
input symbol but B then it stops.
The four blank spaces can have a probability of
So if (00 + 1) * is chosen then the M/C can halt.
having 0 or 1, so total 2(pow,4)= 16 strings are
Option (b) is wrong.
possible, but the given automata does not accept all
Option (c) & (d) are possible but not necessary.
of those.
Option (a) (0 + 1) * 1 or more occurrence of 0 or 1.
1. 1 1 1 1 0 0 1
So 0, 1, 00, 01, 10, 11........are valid strings & the
2. 1 1 0 1 0 0 1
machine doesn't halt for them.
3. 1 0 1 1 0 0 1
Hence (a) is correct option
4. 1 0 0 1 0 0 1
58. (a) If L0 È L1 is recursively enumerable, it means we can
5. 1 0 0 1 0 0 1
find out for all W ÎS*, where M halts or does not
6. 1 0 0 1 1 0 1
halt. This means that if L0 È L1 is recursively
7. 1 0 0 1 1 1 1
enumerable, the halting problem would be decidable.
Hence (c) is correct option
But we know, the halting problem is undecidable.
55. (c) The grammar is S® aSb|SS|Î
Therefore L = L0 È L1 is not RE.
(a) G is not ambiguous is false, since Î which
belongs to L(G), has infinite number of c c
Since, L = (L0 ÈL1)c = L 0 Ç L1 = f which is regular
derivation trees, which makes G ambiguous.
Some derivation trees are language and hence is RE.
Therefore, L is RE.
So, correct option is (b), which is L is RE but L is
not.
59. (b) The given machine M is

(b) There exists x, y Î L(G) such that xy ÏL(G) is


false, since S®SS, can be used derive xy,
whenever x ÎL(G) and yÎL(G).
(c) It is true, since this language is L(G) =
{W|na(W) = nb (W) and n a(v) ³ nb (V) where V
is any prefix of W}
This language happens to be deterministic Now, the complementary machine M is
context-free language.
\ There exists a dpda that accepts it. q1
(d) It is false, as the given language is not regular.
\ number of DFA exists to accept it.
56. (a) Since, f is polynomial time computable 1
0
L1 £ pL2 ...(i)
Since f–1 is also polynomial time computable 1,0
L2 £ pL1 ...(ii) q2 q0
Now consider (a): L1ÎP and L2 is finite. From Eq. (ii), 0, 1
we can say that L1 ÎP Þ L2ÎP. 0
Theory of Computation S3-141

63. (d) Given that, d(s) mod 5 = 2 and d(s) mod 7 ¹ 4}


In the case of DFA, L(M) = L(M) but in the case of
Both the languages are regular languages, since there
nfa this is not true. Infact L(M) and L (M) have no exists deterministic finite automata for both of them.
We also have an algorithm to check the regular nature
connection.
of the language therefore L is regular.
To find L1 = L(M) , we have to look at M and 64. (c) Option (a), (b) & (d) can be accepted by DFA, & there
directly find its language. is no linear relationship between the no. of 0’s &1’s in
the string but in (c)n0(S) - n1(S) <=4 can’t be accepted
Clearly, l = L(M) , since q0 is accepting it (0 + 1) by DFA, we require a PDA.
(0 + 1)* ÎL(M) , since q2 is accepting it. So not regular.
65. (d) The language is context free or not, this can be proved
\ L(M) = L1 = l + (0 + 1) (0 + 1)* by finding out the grammar for all the languages.

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

than themselves or 1 i.e., these cannot be further


breakdown. State Input Output
Therefore, number of states = 3 × 5 = 15 q0 to q0 1, 0 00
The schematic representation is as follows: q1 to q0 1, 0 00
q2 to q0 1, 0 00
1
Therefore, the above DFA ends with 00.
1 1 1 1
1 2 3 4 5 70. (a) The initial state = 00
Final state required = 01
0 0 0 0 0 Let us construct the transition diagram for the given.
0 0 0 0
00 01 01
0 6 1 7 1 8 1 9 1 10 0 0
0 1 2
0 0
0 0 0 Initial state Final state
We get the total number of states to be 3 when getting
1 1 1
11 12 13 14 1 15 the desired output. The transition diagram can further
X X X X X be elaborated as below.
There can be 4 states 00, 01, 10, 11.
68. (a) Given: Transition table for Y and Z With this, the FSM can be designed as
The number of states of Z = 2
0/1
The number of states of Y = 2
Z× Y 1/0
b a, b 00 01
a 1/1
a
1 2 1 2
1/1 1/1 0/0
b a, b

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

® (1, 2) (2, 1) (2, 2)

(1, 2) (2, 2) (2, 1)

(2, 1) (1, 1) (1, 2)

F(2, 2) (1, 2) (1, 1) Here n = 4


So to accept all the substrings the no. of states
69. (c) 1 required are n + 1 = 4 + 1 = 5
Hence (c) is correct option.
1 0
73. (d) These sort of languages are accepted by PDA, so all
0 0 should be context free languages. L2 & L3 are definitely
q0 q1 q2 CFL since accepted by stockof PDA.
And also L1 & L4 are linear comparisons of i & j so can
also be represented using PDA. So all are context free
1 languages.
Theory of Computation S3-143

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

L2 = {0p1q | p, q Î N and p = q} is context-free Peg A Peg B Peg C


language For this, we can recursion algorithm. Firstly, we have
{ p q r
L3 = 0 1 0 | p, q, r Î N and p = q = r is not} to move all upper n – 1 discs from peg A to B, then last
largest disc moved from peg A to C, then again (n – 1)
context-free. discs moved from peg B to C.
76. (a) As state (s) and (t) both are final states and accepting Algorithm
a* + b*, we can combine both states and we will get function (n, A, B, C)
{
b b function (n – 1, A, C, B);
p q r a, b A®C
function (n – 1, B, A, C);
a }
a
Then, the recurrence relation for this problem is
a, b T(n) = 2T(n – 1) + 1
s 82. (c) As we have given,
A(n) ® Average case complexity
77. (b) As n is constant atleast n + 1 states will required to W(n) ® Worst case complexity
design ank. As we know that average case will always be less than
or equal to worst case complexity.
78. (c) å * - P and å * - P is the complement of P and
A (n) £ W (n )
complement of regular language is also regular.
79. (b) Given, there are n strings and length of each string is Consider option (a):
n. A(n) = W (W(n))
Normal recurrence relation for merge sort is \ It says W(n), worst case complexity is less than the
T(n) = 2T (n/2) + Cn average case complexity which is wrong because W
Here, we need n comparisons to compare two strings asymptotic notation shows (³) sign. Hence, this option
i.e., 2 elements of set. is false.
So, recurrence relation will be Consider option (b)
T(n) = 2T (n/2) + Cn2 A(n) = q (W(n))
By solving this using master method, we will get \ It says A(n), worst case complexity is same as worst
case complexity because q notation shows equality
T(n) = O (n2)
sign. Hence, this is false.
80. (c) Time complexity to search an element in a balanced
Consider option (c)
binary search tree is
A(n) = O (W(n))
= log [number of elements in binary search tree]
\ It says that average case complexity A(n) is less
= log [n × 2n]
than or equal to W(n) worst case complexity. Hence,
= log n + log 2n
this option is correct.
= log n + n log 2
Consider option (d)
= log n + n (Q while log2 2 = 1) A(n) = O (W(n))
= q (n) \ It says that A(n) is strictly less than W (n), so this
81. (d) Tower of Hanoi problem with n discs are follows: option is false.
83. (a) Considering the languages L1 = f and L2 = {a}
We have given n discs in peg A and we have to move
For all languages L it is known that f . L = f
all n discs from A to C peg. We will take help of extra
peg B and we arrange all the n discs in peg C as follows Suppose, $ a string s Î f.L
that the smallest disc is at the top position and the $ s' such that s = s' . s"
largest disc is at the lowest position. and s¢Î fs¢¢Î L
S3-144 Theory of Computation

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

Quick Revision Material

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

Start state Final state


a

0 a 1 2 3
Start b b
b
NFA accepting (a/b)*abb
S3-146 Compiler Design

Start state b b Final state

0 a 1 2 3
Start b b
a
a
a
DFA accepting (a/b)*abb

Finite automata recursive descent parsing and backtracking, Recursive descent


parsing, constructs a parse tree for the input string starting
Finite automata can be further divided into,
from roots and nodes are created in preorder.
1. Nondeterministic finite automata (NFA) can have multiple For grammar S ® CAd
paths and have e labeled edges. These edges are called
A ® ab|a
e - transitions. Some of the characters can label 2 or
S S S
more edges out of the same state. Example,
2. Deterministic finite automata(DFA) , no edges are C A d C A d C A d
labeled with e and each character can label at most one
edge out of same state. DFA has one unique path. a b a
(1) (2) (3)
LEX Steps in top-down Parse
Lex is a program generator. It takes lexical specification as input First and Follow
and gives a lexical processor written in C language. First : For first(a) where a is any string of grammar symbols,
Implementation of Lex, to be the set of terminals that begin strings that are derived
Lex specàNFAàDFAà Transition tables + actions àyylex( from a. If a à e , then e is also in FIRST (a).
Follow( A), For non-terminal A , to be the set of terminals a that
) can appear immediately to the right of A in some sentential
Expression is a regular expression and action is a piece of code form. i.e the set of terminals a such that there exists a
of C programming. derivation of the form SàaAab.
Consider grammar First Follow
SYNTAX ANALYSIS OR PARSING First (E) = First (T)
Syntax Analysis is the second phase of the compiler after = First (E')
Lexical Analysis. It is also called as hierarchical analysis or E ® TE' {(, id} {) $}
Parsing. E' ® +TE'/e {+ e} {) $}
T ® FT' {(id} {+) $}
Syntax Error Handling T' ® *FT'/e {*e} {+) $}
The different type of errors which comes up during programming F ® (E)/id {(id} {*+) $}
can be categorized into Example first and follow :
– Lexical, like wrong spellings in an identifier, keyword, S ® cAd Find a derivation for
or operator A ® ab | a for w ® cad
– Syntactic, for example arithmetic expression with S S Backtrack S
unbalanced parenthesis /|\ ® /|\ ® /|\
– Semantic, such as an operator applied to wrong cAd cAd cAd
operands / \ |
– Logical, such as infinity recursive call. a b a
The error detection and recovery in a compiler happens around
the syntax analysis phase. Predictive Parser: Generalities
The error handler in the parser has simple goals like, • In many cases, by carefully writing a grammar–
– It should report the error clearly and accurately eliminating left recursion from it and left factoring
– It should recover from one error quickly so that it is the resulting grammar–we can obtain a grammar
able to detect subsequent errors. that can be parsed by a recursive-descent parser
– It should not slow down the processing of correct that needs no backtracking.
programs. Such parsers are called predictive parsers.
Top down Parsing Left Recursive Grammars I
In top down, a parse tree is constructed for an input string from
root which means parse tree has been built in preorder(depth • A grammar is left recursive if it has a nonterminal A
first). This also involves finding the left most derivation and at such that there is a derivation A ® Aa, for some
each step of a top down parse, the production to be applied string a
is determined. It matches the terminal symbols in production • A left-recursive rule such as A ® A a | b can be
body with input string. The top down Parsing further includes eliminated by replacing it by:
Compiler Design S3-147

– A ®b R where R is a new non-terminal LL(1) Grammar


– R ® a R | e and e is the empty string • A grammar whose passing table has no multiply-defined
entries is said to be LL(1).
Left-Recursive Grammars II
Parsing table
• The general procedure for removing direct left
recursion–recursion that occurs in one rule–is the Constructing the Parsing Table I: First and Follow
following: • First(a) is the set of terminals that begin the strings
derived from a. Follow(A) is the set of terminals a that
– Group the A-rules as can appear to the right of A. First and Follow are used
A ® Aa1 |… | Aam | b1 | b2 |…| bn in the construction of the parsing table.
• Computing First:
where none of the b’s begins with A – If X is a terminal, then First(X) is {X}
– If X ® e is a production, then add ? to First(X)
– Replace the original A-rules with – If X is a non-terminal and X ® Y1 Y2 … Yk is a
» A ® b1A’ | b2 A’ | … | bn A’ production, then place a in First(X) if for some i, a is in First(Yi)
and ? is in all of First(Y1)…First(Yi-1)
» A’ ® a1 A’ | a2 A’ | … | am A’ Constructing the Parsing Table II: First and Follow
Left-Recursive Grammars III • Place $ in Follow(S), where S is the start symbol
and $ is the input right endmarker.
Here is an example of a (directly) left-recursive grammar • If there is a production A ®aBb, then everything
E ®E+T|T in First(b) except for e is placed in Follow(B).
• If there is a production A ®aB, or a production A
T ®T*F|F ®aBb where First(b) contains e, then everything
in Follow(A) is in Follow(B)
F ® (E) | id Example: E ® TE' E' ® +TE' | e
This grammar can be re-written as the following non left- T ® FT' T' ® *FT' | e
recursive grammar: F ® (E) | id
First(E) = First(T) = First(F) = {(, id} First(E') = {+, e}
E ® T E’ E’ ® + TE’ | e First(T') = {*, e}
T ® F T’ T' ® * FT’ | e Follow(E) = Follow(E') = {),$} Follow(F)={+,*,),$} Follow(T)
= Follow(T') = {+,),$}
F ® (E) | id Constructing the Parsing Table III
Left-Factoring a Grammar I Algorithm for constructing a predictive parsing table:
• For each production A ® a of the grammar, do steps 2
• Left Recursion is not the only trait that disallows and 3
top-down parsing. • For each terminal a in First(a), add A ® a to M[A, a]
• If e is in First(a), add A ® a to M[A, b] for each
• Another is whether the parser can always choose terminal b in Follow(A). If e is in First(a), add A ® a
the correct Right Hand Side on the basis of the to M[A,b] for each terminal b in Follow(A). If e is in
next token of input, using only the first token First(a) and $ is in Follow(A), add A ® a to M[A, $].
generated by the leftmost nonterminal in the • Make each undefined entry of M be an error.
current derivation.
Bottom up Parsing
Left-Factoring a Grammar II
It gives a string of terminals. In this method, the parse tree is
Here is the procedure used to left-factor a grammar: built from leaves and working up towards the root. This is the
reverse of right most derivation and used for type of grammar
• For each non-terminal A, find the longest prefix a called LR. LR parsers are difficult to build by hand, hence we
common to two or more of its alternatives. use automatic parser generators for LR grammars.
• Replace all the A productions: hift reduce Parsing
A ® ab1 | ab2 … | abn | g This is a type of bottom up parsing. It consists of stacks which
hold grammar symbols,
(where g represents all alternatives that do not begin with a) Actions in shift reduce Parsesr ® shift, reduce, accept,
Left-Factoring a Grammar III error.
For grammar E ® E + T|F
• Here is an example of a common grammar that needs left T ® T *F|F
factoring: F ® (e)|id
S ® iEtS | iEtSeS | a Stack INPUT Action
E®b $ $id*id2$ Shift
$id *id12 $ reduce by F ® id
( i stands for “if”; t stands for “then”; and e $F *id2$ reduce by T ® F
stands for “else”) $T *id2$ shift
Left factored, this grammar becomes $T* *id2$ shift
$T*id2 $ reduce by F ® id
S ® iEtSS’ | a $T*F $ reduce by T ® T*F
S’ ® eS | e *T $ reduce by E ® T
$E $ Accept
E®b
S3-148 Compiler Design

SYNTAX DIRECTED TRANSLATION Application of syntax directed translation


The conceptual view of syntax-directed translation, Production Semantic Rule
Input string à parse tree à dependency graph à evaluation
order for semantic rules 1) E -> E1 + T E.node=new node('+', E1.node,T.node)
Syntax directed definitions (SDD) 2) E -> E1 - T E.node=new node('-', E1.node,T.node)
3) E -> T E.node = T.node
This is a generalization of context free grammar in which each 4 ) T -> (E) T.node = E.node
grammar symbol has an associated set of attributes and rules. 5) T -> id T.node = new Leaf(id,id.entry)
Attributes are associated with grammar symbols and rules are 6) T -> num T.node = new Leaf(num,num.val)
associated with productions.
Syntax directed translation schemes (SDT) Syntax tree for L-attributed definition
Example : An annotated parse tree for 2*6+ 4n Production Semantic Rules
Annotated parse tree for 2 * 6 + 4n
1) E - > TE' 1. E.node=E'.syn
L.vol = 16 E'.inh=T.node
2) E'-> + TEI' 2. E1'.inh=new node('+', E'.inh,T.node)
E.vol = 16 n E'.syn=E1'.syn
3) E'-> - TEI' 3. E1'.inh=new node('+', E'.inh,T.node)
E'.syn=E1'.syn
E.vol = 12 + T.vol = 4
4) E'->-e 4. E'.syn = E'.inh
5) T->(E) 5. T.node = E.node
T.vol = 12 F.vol = 4 6) T-id 6. T.node=new Leaf(id,id.entry)
7) T->num__ 7. T.node = new Leaf(num,num.val)

T.vol = 2 * F.vol = 6 digit.lexvol = 4


Parse-Stack implementation of postfix SDT’s
F.vol = 2 digit.lexvol = 6 • In a shift-reduce parser we can easily implement
semantic action using the parser stack
• For each nonterminal (or state) on the stack we can
digit.lexvol = 2 associate a record holding its attributes
• Then in a reduction step we can execute the semantic
S-attributed Definitions action at the end of a production to evaluate the
attribute(s) of the non-terminal at the leftside of the
An SDD is S-attributed if every attribute is synthesized. S- production
attributed definitions is evaluated in bottom up fashion in a • And put the value on the stack in replace of the
parse tree and it can be implemented during bottom-up parsing rightside of production
as bottom up traversal corresponds to post order traversal and
SDT’s for L-Attributed definitions
post order corresponds to the order in which an LR parser
reduces a production body to its head. • We can convert an L-attributed SDD into an SDT using
following two rules:
L-attributed definitions
1. Embed the action that computes the inherited
Between the attributes associated with production body, the
attributes for a nonterminal A immediately before
edges in the dependency graph can go from left to right but that occurrence of A. if several inherited attributes
not right to left. Hence the name L-attributed. of A are dependent on one another in an acyclic
Each attribute must be either fashion, order them so that those needed first are
– Synthesized attributes computed first.
2. Place the action of a synthesized attribute for the
– Inherited attribute. It follows certain rules, head of a production at the end of the body of the
For a given production AàX1 X2…..Xn and there is an production
inherited attribute Xi.a associated with this production. Example:
Then the rule may use only, Steps to construct parse tree for a+2*c
Sol: Steps in the construction of syntax tree
1. Inherited attributes associated with head A.
(1) S1 = new leaf (id, entry a);
2. Either synthesized attribute or inherited attribute
(2). S2 = new leaf (num 2);
with the occurences X1 X2 …Xi-1
(3) S3 = new node (+, S1, S2);
Located to the left of Xi
(4) S4 = new leaf (id, entry c);
3. There should not be any cycles in the dependency
(5) S5 = new node (*, S3, S4);
graph for the occurrences of Xi formed by the Dependency graph for a + 2 * c with L-attributed SDD
attributes of Xi.
Compiler Design S3-149

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

RU NTI ME ENV IR ONMENT – On return, a simple jump to the return address.


These were completely language independent, i.e. independent
of target language. The runtime environment which Code for main
concentrates on target machines memory structures and
maintenance of memory is explained in this topic.
There are mainly three types of environment, Code for function i
- Static environment used in language like FORTRAN
77
- Stack based environment used in languages like Code for function n
Pascal, C,C++
- Fully dynamic environment used in LISP language
Activation record Global data
The components of activation record are
– Return value - The v alue which will be returned by
the function after performing some action. This value Activation record for function i
will be stored in this.
– Actual parameters – These are used to send the
inputs to the function from caller functions
– Optional control link- pointer to the activation record
of the caller function
– Optional access link- pointer to caller local data area
to access global data Activation record for function n
– Machine status – values of program counter, machine
registers, etc Memory organization
– Local data of function for static environment
– Temporaries INTERMEDIATE CODE GENERATION
Static runtime environment The front end analyses the source program and creates an
The data is stored in fixed memory locations during the intermediate code representation. The back end makes use of
execution of the program in static runtime environment. this code and generates target code. This enables to attach a
The memory organization of static environment is as shown back end for the new machine to an existing front end. This is
below, a typical scenario in analysis-synthesis model.
The calling sequence of the function is, Logical representation of a compiler front end
– Each argument is computed and stored in its
appropriate parameter location. The compiler front end is organized as shown in the diagram
– The return address is saved and jump to the begging which includes static checking, parsing and intermediate code
of the caller function. generation. These are done sequentially.
Logical structure of a compiler front end

Token Abstrat Static Decorated Intermediate


Parser Intermediate
stream syntax tree checker Abstrat code generator code
syntax tree
Syntax Trees Three address Code (TAC)
Syntax trees are suited for static type of checking and they are TAC is a statement containing at most 3 addresses or
high level of IR. They are natural hierarchical structure of the operands.
source program. The general form is x:= y op z where op stands for operator.
DAG (Directed Acyclic graph)- It’s variant of syntax tree. X is the result, y and z are the operands which may be
variables, constants or temporaries. TAC is the linear
A DAG identifies the common sub expression of the given representation of a binary syntax tree.
expression. A DAG has leaves corresponding to atomic
operands and interior nodes corresponding to operators. DAG Three address code representation
gives clues to compiler to generate efficient code to evaluate The representation includes
– Quadruples: In this representation, for a given instruction
the expression. includes op, arg1,arg2 and result.
S3-150 Compiler Design
Example a = b * – c + b * – c statements in the same order produced by intermediate code
op org1 org2 result generator.
Flow graphs
0 minus c t1
A graphic representation of three address statements is called
a flow graph. It is useful in understanding code generation
1 * b t1 t2
algorithms.
Basic blocks
2 minus c t3
A basic block is a sequence of consecutive statements in
which the control flow enters the beginning and leaves the end
3 * b t3 t4 without a possibility of halt or branching except for the end.
The algorithm used to partition of a sequence into basic
4 + t2 t4 t5 blocks,
Algorithm: Partition into basic blocks
5 = t5 a Input: A sequence of three address statement
Output: A list of basic blocks
Transformations of basic blocks
The primary structure preserving transformations on basic
– Triples: This representation has only three fields for blocks are,
each instruction op,arg1 and arg2. The result of 1. Common sub-expression elimination
operation x= y op z will be represented by its position 2. Dead code elimination
– Indirect triples: This consists of pointers to triples Suppose x is dead and never to be used then the
rather than the set of triples. expression x:=y+z appears in a basic block can be safely
– Static single-assignment form: SSA form is an intermediate removed without affecting a basic block
representation that facilitates certain code optimizations. 3. Renaming of temporary variables
Consider a statement t:=a+b where t is a temporary. If
CO DE G ENERATI ON the statement is changed to u:=a+b where u is a new
The final phase of our compiler is code generation and it takes temporary variable. The change all uses the value u in
the input from intermediate code generation phase and place of t , the value of basic blocks remains the same.
produces an equivalent target program. 4. Interchange of two adjacent statements
The schematic representation of position of code generator, Suppose we have a block with two adjacent statements,
Source Front Intermediate Code Intermediate Code TAK4
T1:= a+b
Program end code optimizer code optimizer AK09 KAH T2:= x+y
Then we can interchange the two statements without affecting
the value of a block.

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

(a) In statically types languages, each variable in


Conceptual MCQs program has a fixed type
1. Given the following expression grammar[2000, 2 Marks] (b) In un-typed languages, values do not have any
E®E*F|F+E|F types
E ® F – | id (c) In dynamically typed languages, variable have no
Which of the following is true? types
(a) * has higher precedence than + (d) In all statically typed languages, each variable in
(b) – has higher precedence than * program is associated with value of only a single
(c) + and – have same precedence type during the execution of the program
(d) + has higher precedence than * 8. Consider the grammar shown below : [2003, 2 Marks]
2. Which of the following derivations does a top-down S ®i E t S S’ / a
parser use while parsing an input string? The input is S ® e S Ie
assumed to be scanned in left to right order. E®b
[2000, 2 Marks] In the predictive parser table, M of this grammar, the
(a) Leftmost derivation entire M[S’, e] and M [S’,$] respectively are
(b) Leftmost derivation traced out in reverse (a) {S’® e S} and {S’® e}
(c) Rightmost derivation (b) {S’® e S} and { }
(d) Rightmost derivation traced out in reverse (c) {S’® e} and {S’® e}
3. Which of the following statements is false? (d) {S’® e S, S’® e} and {S’® e}
[2001, 1 Mark] 9. Consider the grammar shonws below :[2003, 2 Marks]
(a) An unambiguous grammar has same leftmost and S ® CC
ans rightmost derivation C ® cc / d
(b) An LL (1) parser is a top – down parser This grammar is
(c) LALR is more powerful than SLR (a) LL (1)
(d) An ambiguous grammar can never be LR (k) for any (b) SLR (1) but not LL (1)
k (c) LALR (1) but not SLR (1)
4. Which of the following suffices to convert an arbitrary (d) LR (1) but not LALR (1)
CFG to an LL (1) grammar? [2003, 1 Mark] 10. Which of the following is not an advantage of using
(a) Removing left recursion alone shared, dynamically linked libraries as opposed to using
(b) Factoring the grammar alone statically linked libraries? [2003, 2 Marks]
(c) Removing left recursion and factoring the grammar (a) Smaller sizes of executable files
(d) None of the above (b) Lesser overall page fault rate in the system
5. Assume that the SLR parser for a grammar G has n1 (c) Faster program startup
states and the LALR parser for G has n2 states. The (d) Existing programs need not be relinked to take
relationship between n1 and n2 is [2003, 1 Mark] advantage of newer versions
(a) n1 is necessarily less than n2 11. Which of the following grammar rules violate the
(b) n1 is necessarily equal to n2 requirement of an operator grammar? P, Q, R are non –
(c) n1 is necessarily greater than n2 terminals, and r, s, t are terminals. [2004, 1 Mark]
(d) None of these 1. P ® Q R 2. P®QSR
6. In a bottom-up evaluation of a syntax directed definition, 3. P ® e 4. P ® Q t R r
inherited attributes can [2003, 1 Mark] (a) 1 only (b) 1 and 3
(a) always be evaluated (c) 2 and 3 (d) 3 and 4
(b) be evaluated only, if the definition is L – attributed 12. Consider a program P that consists of two source
(c) be evaluated only, if the definition has synthesized modules M1 and M2 contained in two different files. If M1
attributes contains a reference to a function defined in M2, the
(d) never be evaluated reference will be resolved at [2004, 1 Mark]
7. Which of the following statements is false? (a) edit time (b) compile time
[2003, 1 Mark] (c) link time (d) load time
S3-152 Compiler Design

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

40. Consider the grammar with the following translation rules


Problem Based MCQs and E as the start symbol : [2004, 2 Marks]
36. The number of tokens in the following C statements E ® E # T {E. value =E1 value * T . value}
print f(“i = % d, & i = % x”, i & i) is | T {E. value =T. value}
[2000, 2 Marks] T ® T1 & F {T. value =T1 value F . value}
(a) 3 (b) 26 |F {T. value =F. value}
(c) 10 (d) 21 F ® num {F. value = num. value }
37. Consider the following class definition in a hypothetical Compute E value for the root ofthe parser tree for the
object oriented language that supports inheritance and expression
uses dynamic binding. The language should not be 2 # 3 & 5 # 6 & 4.
assuemed to be either Java or C++ , though the syntax (a) 200 (b) 180
is similar. [2003, 2 Marks] (c) 160 (d) 40
Class P { Class Q subclass of P { 41. Consider the grammar S ® (S) | a [2005, 2 Marks]
void f (int i) { void f (int i) { Let the number of states in SLR (1), LR(1) and LALR (1)
print (i); print (2*i); parsers for the grammar be n1, n2 and n3 respectively. Which
} of the following relationships holds good?
}
(a) n1 < n2 < n3 (b) n1 = n3 < n2
Now, consider the following program fragment”
(c) n1 = n2 = n3 (b) n1 ³ n3 ³ n2
Px = new Q()
42. Consider the grammar [2005, 2 Marks]
Qy = new Q();
E ®E+n|E×n|n
Pz = new Q();
X.f(1); ((P)y). f(1); z.f(1); For a sentence n + n × n, the handles in the right-sentential
Here, ((P)y) denotes a type cast of y to P. The output form of the reduction are
produced by executing the above program fragment will (a) n, E + n and E + n × n (b) n, E + n and E + E × n
be (c) n, n + n and n + n × n (d) n, E + n and E × n
(a) 1 2 1 (b) 2 1 1 43. Consider the following grammar. [2006, 1 Mark]
(c) 2 1 2 (d) 2 2 2 S®S*E
38. Consider the translation scheme shown below : S®E
[2003, 2 Marks] E ®F+E
S ® RT E ®F
R ® + T {print (‘+’ :) R / e F ® id
T ® num {print (num. val) ; } Consider the following LR (0) items corresponding to the
Here, num is a taken that represents an integer and num. grammar above.
val represents the corresponding integer value. For an 1. S ® S * E
input string ‘ 9 + 5 + 2’, this translation scheme will print 2. E ® F. + E
(a) 9 + 5 + 2 (b) 95 + 5 + 3. E ® F + .E
(c) 952 + + (d) + + 952 Given the items above, which two of them will appear in the
39. Consider the syntax directed definition shown below : same set in the canonical sets-of-items for the grammar?
[2003, 2 Marks]
(a) 1 and 2 (b) 2 and 3
S ® id = E {gen (id.place = E.place;) ;}
(c) 1 and 3 (d) None of these
E ® E1 + E2 {t = newtemp () ;
44. Consider the following grammar: [2006, 2 Marks]
gen (t= E1 place + E2. place;);
S ® FR
E . place = t;
E ® id {E. place = id. place;} R ® *S|e
Here, gen a function that generates the output code, and F ® id
newtemp is a function that returns the name of a new In the predictive parser table, M, of the grammar the entries
temporary variable on every call. Assume that t1‘ s are the M [S, id] and M[R, $] respectively.
temporary variable names generated by newtemp. For the (a) {S ® FR} and {R ® e] (b) {S ® FR} and {}
statement ‘X = Y + Z’, the 3 - address code sequence (c) {S ® FR} and {R ® *S}(d) {F ® id} and {R ® e}
generated by this definition is 45. Consider the following translation scheme:
(a) X = Y + Z S ® FR [2006, 2 Marks]
(b) t1 = Y + Z; X = t1 R ® *E{print (‘*’); R|e
(c) t1 = Y; t2 = t1+ Z; X = t2 E ® F + E {print (‘+’); |F
(d) t1 = Y; t2 = Z; t3 = t1 + t2 ; X = t3 F ® (S)| id {print (id. value);}
Compiler Design S3-155

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

CONCEPTUAL MCQs This grammar is CLR and also reducible to LALR


without any conflicts. So (d) is false.
1. (b) ‘–’ has higher precedence than ‘*’ as ‘–’ is a leaf Only need to check for SLR(1) or LR(0)
node in the tree formed using this whereas ‘*’ is not. This grammar is not SLR.
2. (c) The rightmost derivation is defined as the list that we Hence (c) is correct option.
get, if we always replace the rightmost non-terminal 10. (c) The advantages of shared dynamically linked libraries
first. include.
The distinction between left most derivation and (a) smaller size of executable since less data
rightmost derivation is important. The reason is, in (b) lesser overall page fault rate.
most parsers, the transformation of the input is (c) No need for re-linking if newer versions of
defined by giving a piece of code for every grammar libraries are there.
rule that is executed whenever the rule is applied. But since compilation time doesn't include
Therefore, it is important to know whether the parser linking so a long linking time required during
determines a leftmost or a rightmost derivation as it runtime in DLL ' s so slow startup.
determines the order in which the pieces of code Hence (c) is correct option.
would be executed. 11. (b) 1. P ® QR is not possible since two NT should
3. (a) So (a) & (c) are, true. include one operator as Terminal.
An ambiguous grammar can't be LR (K) 2. Correct
So option (a) is false since an unambiguous grammar 3. Again incorrect. (4) Correct.
has unique right most derivation & left most Hence (b) is correct option.
derivations but both are not same. Hence (a) is 12. (c) The two modules needed to be linked since definition
correct option exist & M2 & M1 refers it. So during linking phase
4. (c) If a grammar has left recursion & left factoring then M1 links to M2.
it is ambiguous. So to convert a CFG to LL(1) Hence (c) is correct option.
grammar both removal of left recursion & left 13. (b) E1 is to be kept in accumulator & accumulator is
factoring need to be done. required for operations to evaluate E2 also. So E2
Hence (c) is correct option. should be evaluated first & then E 1, so finally E1 will
5. (b) SLR parsue is less range of context free languages be in accumulator, otherwise need to use move &
than LALR but still both n 1 & n2 are same for SLR load instructions.
& LALR respectively. Hence (b) is correct option.
Hence (b) is correct option. 14. (a) The grammar is definitely left & right recursive but it is
6. (c) Every S (synthesized)-attributed definitions is L- not suitable for predictive parsing because it is
attributed. So in a bottom-up evaluation of SDD ambiguous. Also predictive-parsing is possible for
inherited attributes can be evaluated only if the only LL(k). Ambigiousness also incorporates left
definition has synthesized attributes.
recursion so a)
Hence (c) is correct option.
7. (c) (a) True for statically typed languages where each Hence (a) is correct option.
variable has fixed type. Similarly (d) is also 15. (c) There are no lexical errors for C because all the wrong
correct. spelled keywords would be considered as identifiers
(b) True, in un-typed languages types of values until the syntax is checked.
are not defined. So the compiler would give syntax errors.
But option (c) is false, since in dynamically 16. (b) There is scope of common sub-expression elimination
typed language variables have dynamically in this code
changing types but not that they have no type. The expression 4*j is there in both the following lines
Hence (c) is correct option.
x + = (4*j + 5*i);
8. (d)
9. (c) Given grammar y + = (7 + 4*j);
S ® CC 17. (a) Top-down parsing is a technique to analyze unknown
C ® cC / d data relationship. This is done by hypothesizing
it can't be LL since C ® cC is recursive. LR(1) also general parser tree structures and then considering
known as CLR parser, and every CF grammar is CLR whether the known fundamental structures are
grammar. compatible with the hypothesis that was made earlier.
So (a) is false but (c) & (d) can be correct.
Recursive descent parser is a top down parser.
Compiler Design S3-159

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

2000005c t AT91F_PIO_CfgPeriph 200009a4 A __bss_start__

200000b0 T main 200009a4 A _edata

20000120 T AT91F_DBGU_Printk 200009a4 A _end


Compiler Design S3-161

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”!

E # T So at M [ S, id] = { S " FR}


E # T T & F M [ R,$] = {R "!}
T & F F 45. (b) Input string 2 ) 3 + 4
T 16 ×10 = 160
S " ER
F F
FR
num num num num num
(2) (3) (5) (6) (4) idR {print(2)}
LL " left to right left most derivation no ambignity id)ER {print())}
should be there id) F+ER {print(+)}id)
SLR or LR(0) L to R reverse right sentential form id + ER {print(3)} id) id ) id +id
create LR(0) items. So 2 )+ 3 4 are printed
CLR or LR(1) create LR(1) items no bound
LALR reduced CLR if while reducing any conflict 46. (b) Operations Variables Explanations
found then not
MOV b, R1 b is kept R1
LALR
ADD a, R1 a is added to whatever is
Hence (c) is correct option.
present in R1 i.e. a is
41. (b) The no. of states for SLR(1) &LALR(1) are equal so n 1
added to be
= n3, but CLR(1) or LR(1) will have no. of states greater
than LALR &LR(0) both. Þ t1 = a + b
42. (d) Given grammar MOV d, R2 d is moved to R2
E"E+n ADD c, R2 c is added to whatever is
E"E#n present in R2 i.e. is added
E"n to d
String = n + n # n Þ t2 = c + d
Right sentential so right most non terminal will be used. SUB e, R2 e – t 2 = t3
E"E#n {E " E # n} SUB R1, R2 t1 – t3
E+n#n {E " E + n} MOV R2, T4 t4 = t1 – t 3
n+n#n {E " n}
This how, we obtain 3 MOV instruction in the code
So during reduction the order is reverse.
generated for the basic block.
So {E " n , E " E + n, E " E # n}
Compiler Design S3-163

47. (b) Let us consider the given expression (7¯3­4­3¯2). 4. Domain Calculus Domain Calculus is equivalent
Since the precedence of ­ is higher, the sub-expression to relational algebra and provide distinct value
(3­4­3) will be evaluated first. In this sub-expression, for the query. true.
4­3 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­(4­3)))¯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

because it is waiting for some resource to become process number


available or for some event to occur. For example the program counter
process may be waiting for keyboard input, disk
registers
access request, inter-process messages, a timer to go
off, or a child process to finish. memory limits

• Terminated - The process has completed. list open files

Process control block


S3-166 Operating System

THREADS accessing a shared resource R, no other process should be


A thread is a basic unit of CPU utilization, consisting of able to access R until P has finished with R.
a program counter, a stack, and a set of registers, ( and There are essentially three approaches to implementing mutual
a thread ID. ) exclusion.
INTERPROCESS COMMUNICATION • Leave the responsibility with the processes themselves:
this is the basis of most software approaches.
Processes executing concurrently in the OS may be either
independent processes or cooperating processes. • Allow access to shared resources only through special-
• A process is independent if it cannot affect or be purpose machine instructions:
affected by the other processes executing in the • Provide support through the operating system, or through
system. Any process that does not share data with the programming language.
any other process is independent. Semaphores
• A process is cooperating if it can affect or be
affected by the other processes executing in the The fundamental idea of semaphores is that processes "communicate"
system. Clearly, any process that shares data with via global counters that are initialised to a positive integer and that
other processes is a cooperating process. can be accessed only through two atomic operations:
Shared-Memory Systems semSignal(x) increments the value of the semaphore x.
Interprocess communication using shared memory requires semWait(x) tests the value of the semaphore x: if x > 0, the
communicating processes to establish a region of shared process decrements x and continues; if x = 0, the process is
memory. Typically, a shared-memory region resides in the blocked until some other process performs a semSignal.
address space of the process creating the shared-memory
segment.
Deadlock
Deadlock is defined as the permanent blocking of a set of
C O NC U R R E N C Y, S Y N C H R O N I ZAT I O N &
processes that either compete for global resources or
DEADLOCK
communicate with each other. It occurs when each process in
Principles and Problems in Concurrency the set is blocked awaiting an event that can be triggered only
Concurrency is the interleaving of processes in time to give the by another blocked process in the set.
appearance of simultaneous execution. Consider Figure , in which both processes P and Q need both
Mutual Exclusion resources A and B simultaneously to be able to proceed.
Mutual exclusion is in many ways the fundamental issue in Thus P has the form get A, ... get B, ..., release A, ..., release B, and
concurrency. It is the requirement that when a process P is Q has the form get B, ... get A, ..., release B, ..., release A.

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

Get A Get B Release A Release B Progress


of P
= both P and Q want resource A A
= both P and Q want resource B Required
B Required
= deadlock-inevitable region
= possible progress path of P and Q.
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 Deadlock
Operating System S3-167

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

Round Robin Scheduling Fragmentation


Each process is provided a fix time to execute called quantum. As processes are loaded and removed from memory, the free
Once a process is executed for given time period. Process is
preempted and other process executes for given time period. memory space is broken into little pieces. It happens after
Context switching is used to save states of preempted sometimes that processes can not be allocated to memory
processes.
Wait time of each process is following blocks considering their small size and memory blocks remains
ProcessWait Time: Service Time - unused. This problem is known as Fragmentation.
Arrival Time Fragmentation is of two types
P0 (0-0) + (12-3) = 9
P1 (3-1) = 2 1 External Total memory space is enough to satisfy a
P2 (6-2) + (15-9) = 10 request or to reside fragmentation a process in it, but
P3 (9-3) + (18-12) = 12
Average Wait Time: (9+2+10+12) / 4 = 8.25 it is not contiguous so it can not be used.
2 Internal Memory block assigned to process is bigger.
Process Arrival Time Execute Time
Some portion of fragmentation memory is left unused as
P0 0 5 it can not be used by another process.
P1 1 3 Paging
P2 2 8 External fragmentation is avoided by using paging technique.
P3 3 6 Paging is a technique in which physical memory is broken
into blocks of the same size called pages (size is power of
2, between 512 bytes and 8192 bytes).
P0 P1 P2 P3 P0 P2 P3 P2 Address generated by CPU is divided into
Page number (p) – page number is used as an index into
a page table which contains base address of each page
0 3 6 9 12 15 18 21 24 in physical memory.
Round Robin Scheduling
Page offset (d) – page offset is combined with base
MEMORY MANAGEMENT address to define the physical memory address.
Operating system uses the following memory allocation Segmentation
mechanism. Segmentation is a technique to break memory into logical
S. No. Memory Allocation Description pieces where each piece represents a group of related
1 Single-partition In this type of allocation, relocation- information.
allocation Address generated by CPU is divided into
register scheme is used to protect
Segment number (s) – segment number is used as an
user processes from each other, and index into a segment table which contains base address
from changing operating-system of each segment in physical memory and a limit of
segment.
code and data. Relocation register Segment offset (o) – segment offset is first checked
contains value of smallest physical against limit and then is combined with base address to
define the physical memory address.
address whereas limit register
Demand Paging
contains range of logical addresses.
A demand paging system is quite similar to a paging system
Each logical address must be less with swapping. When we want to execute a process, we swap
than the limit register. it into memory. Rather than swapping the entire process into
2 Multiple-partition In this type of allocation, main memory, however, we use a lazy swapper called pager.
allocation memory is divided into a number When a process is to be swapped in, the pager guesses which
of fixed-sized partitions where pages will be used before the process is swapped out again.
Instead of swapping in a whole process, the pager brings only
each partition should contain only those necessary pages into memory. Thus, it avoids reading
one process. When a partition is a into memory pages that will not be used in anyway, decreasing
the swap time and the amount of physical memory needed.
process is selected from the input
Page fault can be handled as following
queue and is loaded into the free
partition. When the process
Step Description

terminates, the partition becomes


Step 1 Check an internal table for this process, to
determine whether the reference was a valid or it
available for another process. was an invalid memory access.
S3-170 Operating System

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

Six Step Process to Perform DMA Transfer

Characteristics of I/O Devices PROTECTION AND SECURITY


Protection
Aspect Variation Example Protection: mechanisms that prevent accidental or
data transfer mode character terminal intentional misuse of a system.
block disk • Accidents: generally easier to solve (make them
access method sequential modem unlikely)
• Malicious abuse: much more difficult to eliminate
random CD-ROM
(can't leave any loopholes, can't use probabilities).
transfer shedule synchronous tape Three aspects to a protection mechanism:
asynchronous keyboard • Authentication: identify a responsible party (principal)
behind each action.
sharing dedicated tape
• Authorization: determine which principals are allowed
sharable keyboard
to perform which actions.
device speed latency • Access enforcement: combine authentication and
seek time authorization to control access.
transfer rate
delay between
operations
I/O direction read only CD-ROM
write only graphics
read-write controller
disk
S3-172 Operating System

(a) always decrease the number of page faults


Conceptual MCQs (b) always increase the number of page faults
(c) sometimes increase the number of page faults
1. The most appropriate matching for the following pairs (d) never affect the number of page faults
[2000, 1 Mark] 7. Which of the following statements is false?
X : depth first search 1 : heap [2001, 1 Mark]
Y : breadth first search 2 : queue (a) Virtual memory implements the translation of a
Z : sorting 3 : stack program’s address space into physical memory
(a) X – 1, Y – 2, Z – 3 (b) X–3, Y – 1, Z – 2 address space
(c) X – 3, Y – 2, Z – 1 (d) X–2, Y – 3, Z – 1 (b) Virtual memory allows each program to exceed the
2. Consider Peterson’s algorithm for mutual exclusion size of the primary memory
between two concurrent processes i and j. The program (c) Virtual memory increases the degree of multi-
executed by process is shown below. [2001, 2 Marks] programming
repeat flag [i] = true; (d) Virtual memory reduces the context switching
turn = j; overhead
while (P) do no-op; 8. Which of the following scheduling algorithms is non-pre
Enter critical section, perform actions, then exit critical -emptive? [2002, 1 Mark]
section (a) Round Robin
Flag [i] = false; (b) First-in-First out
Perform other non-critical section actions. Until false; (c) Multilevel Queue Scheduling
For the program to guarantee mutual exclusion, the (d) Multilevel Queue Scheduling with Feedback
predicate P in the while loop should be 9. The optimal page replacement algorithm will select the
(a) flag [j] = true and turn = i page that [2002, 1 Mark]
(b) flag [j] = true and turn = j (a) has not been used for the longest time in the past
(b) will not be used for the longest time in the future
(c) flag [j] = true and turn = j
(c) has been used least number of times
(d) flag [j] = true and turn = i
(d) has been used most number of times
3. Which of the following is not a valid deadlock prevention
10. Which combination of the following features will suffice
scheme? [2000, 2 Marks]
to characterize an operating system as a multi-programmed
(a) Release all resources before requesting a new
operating system? [2002, 2 Marks]
resource (A) More than one programs may be loaded into main
(b) Number the resources uniquely and never request a memory at the same time for execution.
lower numbered resource than the last one requested (B) If a program waits for certain events such as IN/
(c) Never request a resource after releasing any resource OUT, another program is immediately scheduled for
(d) Request and all required resources be allocated execution.
before execution (C) If the execution of a program terminates, another
4. Consider a set of n tasks with known runtimes r1, r2, ...rn program is immediately scheduled for execution.
to be run on a uniprocessor machine. Which of the (a) (A) only (b) (A) and (B)
following processor scheduling algorithms will result in (c) (A) and (C) (d) (A), (B) and (C)
the maximum throughput? [2001, 1 Mark] 11. A uni-processor computer system only has two processes,
(a) Round Robin both of which alternate 10 ms CPU bursts with 90 ms IN/
(b) Shortes Jobs First OUT bursts. Both the processes were created at nearly
(c) Highest Response Ratio Next the same time. The IN/OUT of both processes can
(d) First Come First Served proceed in parallel. Which of the following scheduling
5. Where does the swap space reside? [2001, 1 Mark] strategies will result in the least CPU utilization (over a
(a) RAM (b) Disk long period of time) for this system? [2003, 2 Marks]
(c) ROM (d) On-chip cache (a) First come first served scheduling
6. Consider a virtual memory system with FIFO page (b) Shortest remaining time first scheduling
replacement policy: For an arbitrary page access pattern, (c) Static priority scheduling with defferen priorities for
increasing the number of page frames in main memory will the two processes
[2001, 1 Mark] (d) Round robin scheduling with a time quantum of 5 ms
Operating System S3-173

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

41. In a system with 32 bit virtual addresses and 1 kbyte page P1 P2


size, use of one-level page tables for virtual to physical
While true do { While true do {
address translation is not practical because of
L 1 : …….. L 3 : ……..
[2003, 1 Mark]
(a) the large amount of internal fragmentation L 2 : …….. L 4 : ……..
(b) the large amount of external fragmentation X = X + 1; Y = X + 1;
(c) the large memory overhead in maintaining page Y = Y – 1; X = Y – 1;
tables V (S x ); V (S y );
(d) the large computation overhead in the translation V (S y ); V (S x );
process In order to avoid deadlock, the correct operators at L1, L2,
42. Consider an operating system capable of loading and
L3 and L4 are respectively
executing a single sequential user process at a time. The
disk head scheduling algorithm used is First Come First (a) P(Sy), P(Sx), P(Sx), P(Sy)
Served (FCFS). If FCFS is replaced by Shortest Seek Time (b) P(Sx), P(Sy), P(Sy), P(Sx)
First (SSTF), claimed by the vendor to give 50% better
(c) P(Sx), P(Sx), P(Sy), P(Sy)
benchmark results, what is the expected improvement in
the IN/OUT performance of user programs? (d) P(Sx), P(Sy), P(Sx), P(Sy)
[2004, 1 Mark] 46. A unix-style I-node has 10 direct pointers and one single,
(a) 50% (b) 40% one double and one triple indirect pointers. Disk block
(c) 25% (d) 0% size is 1 kbyte, disk block address is 32 bit, and 48-bit
43. Consider the following set of processes with the arrival
integers are used. What is the maximum possible file size?
times and the CPU burst times given in millisecond
[2004, 2 Marks] [2004, 2 Marks]
24 32
(a) 2 byte (b) 2 byte
Process Arrival Time Burst Time (c) 234 byte (d) 248 byte
P1 0 5 47. Suppose n processes, p1, p2 ..., pn share m identical
P2 1 3 resource units, which can be reserved and released one
P3 2 3 at a time. The maximum resource requirement of process
P4 4 1 Pi is si, where Si > 0. Which one of the following is a
sufficient condition for ensuring that deadlock does not
What is the average turn-around time for these proceses occur? [2005, 2 Marks]
with the pre-emptive Shortest Remaining Processing Time (a) "i, si < m (b) "i, si < n
First (SRPTF) algorithm?
n n
(a) 5.50 (b) 5.75
(c) 6.00 (d) 6.25 (c) å si < (m + n) (d) å si < (m * n)
i =1 i =1
44. Consider a system with a two-level paging scheme in 48. Consider the following code fragment: [2005, 2 Marks]
which a regular memory access takes 150 ns and
if (fork () = = )
servicing a page fault takes 8 ms. An average instruction
takes 100 ns of CPU time, and two memory accesses. The { a = a + 5, print f (“%d, %d\n”, a, &a), }
TLB hit ratio is 90%, and the page fault rate is one in else { a = a – 5, print f (“%d, %d\n”, a, &a), }
every 10,000 instructions. What is the effective average Let u, v be the values printed by the parent process, and
instruction execution time? [2004, 2 Marks] x, y be the values printed by the child process. Which
(a) 645 ns (b) 1050 ns one of the following is true?
(c) 1215 ns (d) 1230 ns
(a) u = x + 10 and v = y (b) u = x + 1 and v ¹ y
45. Consider two processes P1 and P2 accessing the shared
variables X and Y protected by two binary semaphores (c) u + 10 = x and v = y (d) u + 10 = x and v ¹ y
Sx and Sy respectively, both initialized to 1. P and V 49. Consider three processes, all arriving at time zero, with total
denote the usual semaphore operators, where P execution time of 10, 20 and 30 units, respectively. Each
decrements the semaphore value, and V increments the process spends the first 20% of execution time doing IN/
semaphore value. The pseudo-code of P1 and P2 is as OUT, the next 70% of time doing computation, and the last
10% of the time doing IN/OUT again. The operating system
follows: [2004, 2 Marks]
uses a shortest remaining compute time first scheduling
Operating System S3-177

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

Common Data for Questions 77 and 78 : 11 : V(S);


Suppose we want to synchronize two concurrent processes P }
and Q using binary semaphores S and T. The code for the The variables process-arrived and process_left are shared
among all processes and are initialized to zero. In a
processes P and Q is shown below:
concurrent program all the three processes call the barrier
Process P Process Q
function when they need to synchronize globally.
while (1) { while (1) { 79. The above implementation of barrier is incorrect. Which
W: Y: one of the following is true? [2006, 2 Marks]
print ‘0’; print ‘1’ (a) The barrier implementation is wrong due to the use
print ‘0’; print ‘1’ of binary semaphore S
X: Z : (b) The barrier implementation may lead to a deadlock,
} if two barrier invocations are used in immediate
Synchronization statement can be inserted only at point succession
(c) Lines 6 to 10 need not be inside a critical section
W, X, Y and Z
(d) The barrier implementation is correct, if there are
77. Which of the following will always lead to an output only two processes instead of three
string with ‘001100110011’? [2003, 2 Marks] 80. Which one of the following rectifies the problem in the
(a) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T implementation? [2006, 2 Marks]
initially 1 (a) Lines 6 to 10 are simply replaced by process arrived
(b) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially (b) At the beginning of the barrier the first process to
1, and T initially 0 enter the barrier waits until process_arrived becomes
(c) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T zero before proceeding to execute P(S)
(c) Context switch is disabled at the beginning of the
initially 1
barrier and re-enabled at the end
(d) P(S) at W, V(T) at X, P(T) at Y, V(T) at Z, S initially
(d) The variable process_left is made private instead of
1, and T initially 0 shared
78. Which of the following will ensure that the output string
never contains a substring of the form 01n0 or 10n1 where Linked Answer Type MCQs
n is odd? [2003, 2 Marks]
(a) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T Statements for Linked Answer Questions 81 & 82
initially 1 A process has been allocated 3 page frames. Assume that none
(b) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T of the pages of the process are available in the memory initially.
The process makes the following sequence of page references
initially 1
(reference string) [2007, 2 Marks Each]
(c) P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1
1, 2, 1, 3, 7, 4, 5, 6, 3, 1
(d) V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T 81. If optimal page replacement policy is used, how many page
initially 1 faults occur for the above reference string?
Statements for Linked Answer Questions 79 and 80 (a) 7 (b) 8
Barrier is a synchronization construct where a set of processes (c) 9 (d) 10
synchronizes gobally, i.e., each process in the set arrives at the 82. Least Recently Used (LRU) page replacement policy is a
barrier and waits for all others to arrive and then all processes practical approximation to optimal page replacement. For the
leave the barrier. Let the number of processes in the set be 3 above reference string, how many more page faults occur
and S be a binary semaphore with the usual P and V function. with LRU than with the optimal page replacement policy?
(a) zero (b) 1
Consider the following C implementation of a barrier with line
(c) 2 (d) 3
numbers shown on left:
Statement for Linked Answer Questions 83 & 84
void barrier (void) { A computer has a 256 kbyte. 4-way set associative, write back
1 : P(S); data cache with block size of 32 byte. The processor sends 32 bit
2 : process_arrived ++; addresses to the cache controller. Each cache tag directory entry
3 : V(S); contains, in addition to address tag, 2 valid bit, 1 modified bit and
4 : while (process_arrived ! = 3); 1 replacement bit. (2012, 2 Marks Each)
5 : P(S); 83. The number of bits in the tag field of an address is
6 : process_left++; (a) 11 (b) 14
7 : if (process_left = = 3);{ (c) 16 (d) 27
8 : process_arrived = 0; 84. The size of the cache tag directory is
9 : process_left = 0; (a) 160 kbit (b) 136 kbit
10 : } (c) 40 kbit (d) 32 kbit
S3-182 Operating System

the OS of the computer assigns different I/O devices to


Numerical Answer Questions each process. Also, the scheduling overhead of the OS is
negligible. The processes have the following characteristics:
85. Suppose a disk has 201 cylinders, numbered from 0 to 200. Process id tc tio
At some time the disk arm is at cylinder 100, and there is a A 100 ms 500 ms
queue of disk access requests for cylinders 30, 85, 90, 100, B 350 ms 500 ms
105, 110, 135 and 145. If Shortest-Seek Time First (SSTF) is C 200 ms 500 ms
being used for scheduling the disk access, the request for The processes A, B, and C are started at times 0, 5 and 10
cylinder 90 is serviced after servicing ____________ milliseconds respectively, in a pure time sharing system
number of requests. [2014, Set-1, 1 Mark] (round robin scheduling) that uses a time slice of 50
86. Consider the following set of processes that need to be milliseconds. The time in milliseconds at which process C
scheduled on a single CPU. All the times are given in would complete its first I/O operation is ___________.
milliseconds. [2014, Set-2, 2 Marks]
89. A system uses 3 page frames for storing process pages in
Process Name Arrival Time Execution Time
A 0 6 main memory. It uses the Least Recently Used (LRU) page
B 3 2 replacement policy. Assume that all the page frames are
initially empty. What is the total number of page faults that
C 5 4
will occur while processing the page reference string given
D 7 6
below? [2014, Set-3, 1 Mark]
E 10 3
4, 7, 6, 1, 7, 6, 1, 2, 7, 2
Using the shortest remaining time first scheduling 90. An operating system uses shortest remaining time first
algorithm, the average process turnaround time (in msec) is scheduling algorithm for pre-emptive scheduling of
____________________. [2014, Set-1, 2 Marks] processes. Consider the following set of processes with
87. Assume that there are 3 page frames which are initially their arrival times and CPU burst times (in milliseconds):
empty. If the page reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4,
6, the number of page faults using the optimal replacement Process Arrival Time Burst Time
policy is__________. [2014, Set-1, 2 Marks] P1 0 12
88. Three processes A, B and C each execute a loop of 100 P2 2 4
iterations. In each iteration of the loop, a process performs P3 3 6
a single computation that requires tC CPU milliseconds and P4 8 5
then initiates a single I/O operation that lasts for t io The average waiting time (in milliseconds) of the processes
milliseconds. It is assumed that the computer where the is _________. [2014, Set-3, 2 Marks]
processes execute has sufficient number of I/O devices and
Operating System S3-183

program is available here so context switching is


CONCEPTUAL MCQs
reduced. But virtual memory doesn't translate
1. (b) A mutual exclusion look is called mutex. In this two program’s address space into physical memory.
or more processes executes simultaneously and wait Hence (a) is correct option.
for the execution of another process. The process is 8. (b) Round robin is preemptive since processes are
called deadlock when two or more process cycled for CPU time, & run for a particular time
simultaneously trying to enter a critical section, look stamp in one cycle. Multilevel queue scheduling
each other out. maintains various quenes, each having different
Let look at the simple algorithm for achieving the priorities. But in FIFO scheme, only the process
mutual exclusion between two processes with PID which enters once, would be completed first, so no.
equal to 0 or 1 preemption.
int turn; Hence (b) is correct option.
int interested [2]; 9. (b) Optimal page replacement algorithm assumes that
void Get_Mutex (int pid) the pages that will come in future are already known,
{ so replacement of the page which will not be used
int other; in future occurs.
other = 1-pid; Hence (b) is correct option.
while (turn = = pid && interested [other]) 10. (b) Multi-programmed:- More than one program can run
{ on single CPU, when one is blocked.
} (A) Is true and a characteristic of multi-programmed
} (B) Is true & also characterize a multi-programmed OS
release_mutex (int pid) (C) Is true but no necessary for this type this
{ happens in all OS, even in batch processor.
interested [pid] = false; Hence (b) is correct option.
} 11. (a) There should be no doubt that round robin
2. (b) While loop if true predicate then the program enters scheduling would lead to maximum CPU utilization,
into critical region. This program enters into critical but since in FCFS one task would starve for a long
region of flag [i]=true act as semaphore, & true =j, time so min CPU utilization would be in this case.
the requirement of resource is by some other Hence (a) is correct option.
process. 12. (a) Using larger block size in a fixed block size system
Hence (b) is correct option. lead to poor disk space utilization due to data items
3. (c) In deadlock prevention scheme, which are very small comparable to block size cause
The operating system requests a resource after fragmentation. But it leads to better disk through put
since no. of blocks needs to fetch & replace become
releasing the resource held by him, if needed. This
less.
is not a condition that a process cannot request a
13. (b)
resource.
(1) It is false, context switch is not faster in support of
4. (b) Here the running times r1to rn are already known,
kernel threads.
single processor system. In this scenario, throughput
(2) A system call can truly block the user level threads,
i.e. CPU is maximum utilized in shortest job first
since they don’t have permission to do that.
scheduling.
(3) True since kernel supported threads have their
5. (b) Swap space is the memory space where the part of independent memory & resources.
the program not currently in main memory for (4) False since user level threads might need support of
execution is stored, this program part can be kernel threads.
swapped into memory when required. Hence (b) is correct option.
This space is generally indisk. 14. (a) Page frames are allocated in main memory, for virtual
Hence (b) is correct option. memory pages. This no. of page frames depends
6. (c) During F1F0 page replacement policy, due to increase upon the instruction set architecture.
in the no. of page frames in memory should decrease Hence (a) is correct option.
the no. of page faults since more frames can be kept 15. (a) The P and V functions are given from that we determine
there. that fetch and set instructions always set the memory
But due to Belady's Anomaly after certain limit or in location x to 1 and fetch the old value of x into y. S
some page access instances no. of page faults are takes only 2 values either 0 or 1 when S is initialized to
high. 0, statement 3 will start at location x with this value and
Hence (c) is correct option. fetch-set instruction change the value of x from 0 to 1
7. (a) Virtual memory enables a program to exceed the size and y becomes 0. If more than 2 processes were there
of primary memory so it increases degree of multi- and context switching was disabled in P then this won’t
programming. Since data required by executing work properly.
S3-184 Operating System

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

Y executes. It first sets S = 1 and decrement R = 0.


It comes again and then again sets S = 1 (i.e., it 3 3 3 3 3 3 3
overlaps the value of S) and then again wait for R. 2 2 2 7 4 5 6 6 6
Clearly hence one iteration of process X is lost due
to overlapping of value of S, and after n – 1 iteration 1 1 1 1 1 1 1 1 1 1
process X will be stuck. 1 2 1 3 7 4 5 6 3 1
So option (d) is wrong.
74. (b) Only REQ2 can be permitted. Page
F F F F F F F
faults
COMMON DATA MCQs Total number of page fault = 7
75. (d) TLB is successfully 96% of total request & for 82. (c) LRU replaces the page which is used least recently.
remaining 4%. RAM is accessed twice. Page frames
So average time taken. 3 3 3 5 5 5 1
= 0.96(1 +(0.9×1) +0.1×(1 +10))+0.04(21 +(0.9×0.1))
+0.1×(1 +10) 2 2 2 7 7 7 6 6 6
= 0.96(1 + 0.9 +1.1) +0.4(21 + 0.09 +1.1) 1 1 1 1 1 4 4 4 3 3
= 0.96×3 +0.4×23
1 2 1 3 7 4 5 6 3 1
= 2.88 +0.92 F F F F F F F F F
= 3.80 » 4 ns
Total number of page faults = 9
Hence (d) is correct option.
Therefore, an increase of 2 is there (9 – 7) in LRU than
76. (c) Total no. of pages required = 5 in optimal.
But due to 2 level page table = 24 KB
= 16 kB Cache size
83. (c) Number of blocks in the cache (c) =
Hence (c) is correct option. Block size
77. (b) For output string 001100110011 alternatingly we
256
require process P & Q to execute. = = 213
For this to happen P(s) with S = 1 should be placed 32
at W. At the same time P(T) with T = 0 will be at Y. Number of blocks in main memory
At X we have V(T) which will have T = 1 so process Main memory size 232 B
Q starts. ( m) = = = 227
Block size 32B
At the same time at Z we have V(s) which make S
= 0 to stop process P. Number of blocks in each set (S) = 4
Hence (b) is correct option. Number of tag bits = log m – log c + log S
78. (c) To ensure this condition that substring of form 01n0 = 27 – 13 + 4 = 16 bit
or 10n1, where n is odd S should be initially 1, we 84. (b) Number of tag bits = 16
Number of valid bits = 2
will case only 1 semaphore S.
Number of modified bits = 1
So at W P(s), at X V(s) whereas at Y P(s), at Z V(s) Number of replacement bits = 1
Hence (c) is correct option. Total bits in each entry = 16 + 2 + 1 + 1 = 20 bit
79. (b) This barrier implementation is to keep track of arrival Each entry is attached to each cache block
& completion of processes in system, by Number of cache blocks are = 213
incrementing no. of process arrived & left. This Tag directory size = Number of cache blocks
implementation may lead to deadlock if two barrier × Each entry size
function's invocations are used is immediate sessions. = 213 × 20 bit = 20 × 160 bit = 160 kbit
SinceV(s) in first invocation at line 3 removes 1-3
NUMERICAL ANSWER QUESTIONS
from critical section bring 5-11 in critical section at
line 7. 85. No. of Requests = 3
Hence (b) is correct option. Remember that in SSTF algo the request with shortest
80. (b) To rectify the barrier function at the beginning of the seek fine from “current Head Position” is serviced first.
functions the first process which inters the function We prepare the following table:
waits until process arrived becomes zero before Request with
Current Nearest Nearest
executing P(s). Shortest seek time
Head Left Right
This removes any deadlock situation. Position Request Request (& Hence serviced)
Hence (b) is correct option.
100 100 100 100
Initially
LINKED ANSWER TYPE MCQs 100 90 105 105
81. (a) Optimal page replacement policy replaces the page 105 90 110 110
which will not be used for longest time 110 90 135 90
Page frames
S3-190 Operating System

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

Quick Revision Material

DATABASE MODEL Schema Diagram: A diagrammatic display of (some aspects


A Database model defines the logical design of data. The of) a database schema.
model describes the relationships between different parts Database Instance: The actual data stored in a database at
of the data. In history of database design, three models a particular moment in time. Also called database state (or
have been in use. occurrence).
Database Model (i) Hierarchical Model
It refers to a set of concepts to describe the structure of a In this model each entity has only one parent but can have
database and certain constraints that the database should several children . At the top of hierarchy there is only one
obey. entity which is called Root.
(ii) Network Model: In the network model, entities are organised
Department in a graph, in which some entities can be accessed through
No. Name several path
(iii) Relational Model
Course Student In this model, data is organised in two-dimesional tables
no. name unit id name course called relations. The tables or relation are related to each
other.
id Name Professor
ENTITYAND ENTITY SETS:
Example of Hierarchical Movel An entity is a basic unit of E-R model which is an object or a thing
in real world having independent existence. An entity may be
Department Student
concrete and a physical existence (e.g.: person, place) or it can be
no. name id name course student
abstract or conceptual existence like loan, course.
Course Professor Entity set is a collection of entities of a particular entity type at
No. Name Unit id Name any point of time.
TYPES OF ATTRIBUTES:
Example of Network Model There are several types of attributes in E-R model as given below,
Categories of data models (i) Simple and composite attributes
• Conceptual (high-level, semantic) data models: Provide The attributes which cannot be divided further is called
concepts that are close to the way many users perceive simple or atomic attributes.
data. (Also called entity-based or object-based data The attributes which can be divided into smaller subparts
models.) with independent meanings is called composite attribute.
• Physical (low-level, internal) data models: Provide For example, In employee entity, the attribute emp_no is a
concepts that describe details of how data is stored in simple attribute. The emp_name can be called a composite
the computer. attribute as name can be divided into first name, middle
• Implementation (representational) data models: Provide name and last name.
concepts that fall between the above two, balancing (ii) Single valued and multivalued attributes
user views with some computer storage details. The attributes which have a single value for a given entity
Database Schema: The description of a database. Includes are said to be single valued attributes. For instance, the
descriptions of the database structure and the constraints employee number attribute refers to only one employee
that should hold on the database. number.
S3-192 Databases

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

for weak entity set


Translating Tables into ERD
1. The following rules can be followed to convert tables
into ERD
Create a table for all strong entities and column for all
attributes. If an attribute is a composite attribute then
create columns only for sub attributes.
2. Do not create any column for derived attributes as
they would not be included in the table.
S3-194 Databases

INTERSECTION Example Natural Join


Invariably the JOIN involves an equality test, and thus is often
R described as an equi-join. Such joins result in two attributes in
A 1 the resulting relation having exactly the same value.
B 2 OUTER JOINs
D 3 An outer join retains the information that would have been lost
F 4 R INTERSECTION S from the tables, replacing missing data with nulls.
E 5 There are three forms of the outer join, depending on which data
A 1 is to be kept.
S D 3 • LEFT OUTER JOIN - keep data from the left-hand table
A 1 • RIGHT OUTER JOIN - keep data from the right-hand
C 2 table
D 3 • FULL OUTER JOIN - keep data from both tables
E 4 RELATIONAL CALCULUS
DIFFERENCE Example Relational calculus is an alternative form of relational algebra
which is non-procedural or declarative language where it is not
R required to be concerned about the procedure to obtain the result
rather the output is obtained without knowing the method of
A 1 R DIFFERENCE S retrieval.
B 2
B 2 Tuple relational Calculus
D 3 A tuple variable is a variable which ranges over particular database
F 4 F 4
E 5 relation. That is, every value assigned to tuple variable has same
E 5 number and type of fields. For example, a simple calculus query
S can be written as {T | p(T)}.
Here T is a tuple variable and p(T) is a conditional expression for
A 1
S DIFFERENCE R it. The query will return the result set which satisfies the selection
C 2
condition.
D 3 C 2
E 4 E 4 Atoms
For the construction of the formulae we will assume an infinite
Cross Product Operation set V of tuple variables. The formulas are defined given a database
schema S = (D, R, h) and a partial function type : V -> 2C that
The cross product combines the tuples in A and B in a defines a type assignment that assigns headers to some tuple
combinatorial manner, i.e. every tuple in A will be combined with variables. We then define the set of atomic formulas A[S,type]
every in relation B. with the following rules:
Example, 1. if v and w in V, a in type(v) and b in type(w) then the formula
s branch_name='bangalore' (Depositor × Borrower) “v.a = w.b” is in A[S,type],
Renaming Operation 2. if v in V, a in type(v) and k denotes a value in D then the
The rename operation is denoted by lowercase Greek letter rho(r). formula “ v.a = k “ is in A[S,type], and
The rename operation can be expressed by the following, rA ( R) 3. if v in V, r in R and type(v) = h(r) then the formula “r(v)” is in
changes the name of the relation to A A[S,type].
rA(c1,c2,c3…..cn)( R ) changes the name of the relation to A and Examples of atoms are:
the column names to c1,c2,c3,…cn. • (t.age = s.age) — t has an age attribute and s has an age
JOIN Operator attribute with the same value
JOIN is used to combine related tuples from two relations: • (t.name = “Codd”) — tuple t has a name attribute and its
• In its simplest form the JOIN operator is just the cross value is “Codd”
product of the two relations. • Book(t) — tuple t is present in relation Book.
• As the join becomes more complex, tuples are removed within The formal semantics of such atoms is defined given a database db
the cross product to make the result of the join more over S and a tuple variable binding val : V -> TD that maps tuple
variables to tuples over the domain in S:
meaningful.
1. “v.a = w.b” is true if and only if val(v)(a) = val(w)(b)
The notation used is
2. “v.a = k” is true if and only if val(v)(a) = k
R JOINjoin condition S
3. “r(v)” is true if and only if val(v) is in db(r)
Equi join Formulas
A special case of join condition where the join condition is only The atoms can be combined into formulas, as is usual in first-
between the equalities, like employee.dept_no = order logic, with the logical operators Ù (and), Ú (or) and ¬ (not),
department.dept_num. There is equality between 2 fields of and we can use the existential quantifier ($) and the universal
employee and department. quantifier ( ") to bind the variables. We define the set of formulas
Equi join is represented by R S where R & S are two relations. F[S,type] inductively with the following rules:
Databases S3-195

1. every atom in A[S,type] is also in F [S,type] Customer Table:


2. if f1 and f2 are in F [S,type] then the formula “ f1 Ù f2” is also
in F[S,type] Cust_id Cust_name Prod_id Prod_name Sales_detail
3. if f1 and f2 are in F[S,type] then the formula “ f1 Ú f2” is also 123 Amar 10 Prod1 Sales_1
in F[S,type]
123 Amar 11 Prod2 Sales_2
4. if f is in F[S,type] then the formula “ ¬ f ” is also in F [S,type]
5. if v in V, H a header and f a formula in F [S,type[v->H]] then 124 Rekha 12 Prod3 Sales_3
the formula
“ $ v : H ( f )” is also in F[S,type], where type[v->H] denotes To reduce this into second normal form, create 3 different
the function that is equal to type except that it maps v to H, tables.
6. if v in V, H a header and f a formula in F[S,type[v->H]] then
Customer_table:
the formula
“ "v : H ( f )” is also in F[S,type] Cust_id Cust_name
NOR MALIZATION
123 Amar
Normalization is a process of organizing the data in such a way
that data is easily accessed, managed and modified. 124 Rekha
Normal forms:
The commonly used four normal forms are first(1NF), Product table:
second(2NF), third(3NF) and Boyce Codd normal form(BCNF).
Prod_id Prod_name
The other normal forms are fourth(4NF) and fifth(5NF).
First normal form:- 10 Prod1
The row of data in a table should not contain repeated 11 Prod2
group of data i.e. each column should have unique value. 12 Prod3
Each record in a table should have a unique identifier,
primary key. Sales Table:
Non-Normalized table :
Customer_id Product_id Sales_detail

Student_id S tudent_name S ubjects 123 10 Sales1

123 A mar Phys ics 123 11 Sales2


123 A mar Chemis try 124 12 Sales3
124 Rekha M aths
125 A vin as h Biology Third Normal form (3NF)
A table or relation is said to be in 3NF if,
This can be normalized in 1NF by creating 2 separate tables • It satisfies 2NF
Student Table: • Every non-prime attribute in the table should depend
Subject table : on primary key. The functional transitive dependency
is removed from the table. This helps in reducing the
Stu_id Stu_name data duplication and achieves data integrity.
123 Amar Employee table:
124 Rekha
125 Avinash Emp_id Emp_name DOB Addr1 City State Zipcode

This will be in 3NF when ZIPcode table is created as addr1,


Subject_id Student_id Subj_name city, state is dependent on zipcode
101 123 Physics Emp_table:
102 123 Chemistry Emp_id Emp_name DOB Zip_code
103 124 Maths
104 125 Biology Address table:

Zip_code Addr1 City State


Second normal form(2NF)
A table is said to be in 2NF, if it Boyce & Codd normal form (BCNF)
• Satisfies 1NF BCNF is a higher version of 3NF. A 3NF table doesn’t have
• No partial dependency of any column on primary key. multiple candidate keys.
S3-196 Databases

Fourth normal form • Primary key definition: PRIMARY KEY ( [comma


A table is said to be in 4NF if, separated column list] )
• It satisfies 3 NF • Constraints: {CONSTRAINT}[constraint definition]
• A record should not contain two or more independent • RDBMS specific functionality
multi values about an entity. Said t 2. DROP statements
Fifth Normal Form To destroy an existing database, table, index, or view.
A table is said to be in 5NF if, A DROP statement in SQL removes an object from a relational
• It satisfies 4NF database management system (RDBMS). The typical usage is
• The table consists of a key and non-key attribute only. simply:
DROP objecttypeobjectname.
QUERRY LANGUAGES (SQL) 3. ALTER statements
To modify an existing database object.
SQL operators :
The typical usage is:
1. Rename operation : it is used to rename the attributes i.e
ALTER objecttypeobjectnameparameters.
columns or relations i.e tables using ‘as’ clause.
4. Truncate
2. ALL : This specifies all the tuples and explicitly doesn’t
These command permanently removes the rows of the table from
remove the duplicates from the result set.
the database and noclauses can be appended to this command.
Basic structure of SQL Example : Truncate table table-name
It consists of three clauses: select, from and where. DML commands
Select corresponds to attributes to be retrieved from the table
SQL supports querying, inserting, deleting updating of records
From is the relation or data structure to be scanned to get
in a table. These operations can be performed using DML
the desired result.
commands.The DML commands are Insert, update,delete.
Where clause specifies the condition used while fetching
1. Insert : used to add new rows into a table
the data from one or multiple tables.
Insert into students (s_rollnumber,s_name, addr1, gender,
3. AND &OR : are used normally when there are multiple
email) values
conditions to be specified in the query.
(123, ‘amar’,’abc..’, ‘M’,’amar@gmail.com’)
Example: select emp_no, emp_name from employees where
2. Update : used to update the value of an attribute in a row.
emp_name = ‘Alex’ and emp_sal> 10000
Update students set email =’amar123@gmail.com’
4. NOT : The rows get selected where the specified condition
Where s_rollnumber = 123
is false.
3. Delete : used to delete rows from the table
Example: select emp_name, emp_no from emp where NOT dept
Delete from students where s_rollnumber = 123
= ‘HR’
Nested queries:
DCL Commands
A query within a query or a query nested in a larger query is
1. ORDER BY clause: This is used to arrange or sort the
called a subquery. A subquery can be added in SELECT, FROM
result set either in ascending or descending orders by using
OR WHEREclauses.
keywords ASC,DESC.
SQL joins :
Example : select emp_id, emp_name from employees where
SQL joins are generally used to combine rows from different tables
dept= ‘Finance’
bassed on a common field among tables. SQL joins can be used
Order by emp_nodesc
in ‘where’ clause of select, update, insert and delete commands.
2. GROUP BY AND HAVING clause
1. Inner join or equi join: The query with inner join turns all
Group by is used with conjunction to group functions to
rows from different tables which satisfies the join condition.
retrieve grouped data according to one or more columns.
It returns the rows when there is atleast one match in both
DDL commands tables.
The SQL supports the DDL operations are used to create, modify Example: selectcust_id, cust_name, order_id,order_date
and delete database objects. from customer c,orders o
1. CREATE statement Where c.cust_id = o.cust_id
To make a new database, table, index, or stored 2. Left outer join : It returns all rows from left table and matched
procedure. rows from right table.
CREATE TABLE statement Example:select cust_id, cust_name, order_id,order_date
A commonly used CREATE command is the CREATE TABLE from customer c
command. The typical usage is: left outer join orders o on c.cust_id = o.cust_id
CREATE TABLE [table name] ( [column definitions] ) [table This returns all rows from customer table and matched rows
parameters]. from order table.
column definitions: A comma-separated list consisting of any 3. Right outer join : It returns all rows from right table and
of the following matching rows from left table.
• Column definition: [column name][data Example: select cust_id, cust_name, order_id,order_date
type]{NULL | NOT NULL}{column options} from customer c
Databases S3-197

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

7. Consider a relation geq which represents “greater than or


Conceptual MCQs equal to”, that is, (x, y) Î geq only if y ³ x.
1. B+ trees are preferred to binary trees in databases create table geq
because [2000, 1 Mark] (lb integer not null
(a) disk capacities are greater than memory capacities ub integer not null
(b) disk access is much slower than memory access primary key lb
(c) disk data transfer rates are much less than memory foreign key (ub) references geq on delete cascade)
data transfer rates Which of the following is possible if a tuple (x, y) is
(d) disks are more reliable than memory
deleted? [2001, 2 Marks]
2. Given relations r(w, x) and s(y, z), the result of
select distinct w, x (a) A tupel (z, w) with z > y is deleted
from r, s (b) A tuple (z, w) with z > x is deleted
is guaranteed to be same as r, provided (c) A tuple (z, w) with w < x is deleted
[2000, 2 Marks] (d) The deletion of (x, y) is prohibited
(a) r has no duplicates and s is non-empty 8. Relation R with an associated set of functional
(b) r and s have no duplicates dependencies F, is decomposed into BCNF. The
(c) s has no duplicates and r is non-empty redundancy (arising out of functional dependencies) in
(d) r and s have the same number of tuples the resulting set of relations is [2002, 1 Mark]
3. Consider a schema R(A, B, C, D) and functional
(a) zero
dependencies A ® B and C ® D. Then the decomposition
(b) more than zero but less than that of an equivalent
of R into R1 (AB) and R2(CD) is [2001, 1 Mark]
(a) dependency preserving and lossless join 3NF decomposition
(b) lossless join but not dependency preserving (c) proportional to the size of F
(c) dependency preserving but not lossless join (d) indetermine
(d) not dependency preserving and not lossless join 9. With regard to the expressive power of the formal
4. Suppose the adjacency relation of vertices in a graph is relational query languages, which of the following
represented in a table Adj (X, Y). Which of the following statements is true? [2002, 1 Mark]
queries cannot be expressed by a relational algebra (a) Relational algebra is more powerful than relational
expression of constant length? [2001, 1 Mark] calculus
(a) List of all vertices adjacent to a given vertex
(b) Relational algebra has the same power as relational
(b) List of all vertices which have self loops
(c) List of all vertices which belong to cycles of less calculus
than three vertices (c) Relational algebra has the same power as safe
(d) List of all vertices reachable from a given vertex relational calculus
5. R(A, B, C, D) is a relation. Which of the following does (d) None of the above
not have a lossless join, dependency preserving BCNF 10. Relation R is decomposed using a set of functional
decomposition? [2001, 2 Marks] dependencies F, and relation S is decomposed using
(a) A ® B, B ® CD (b) A ® B, B ® C, C ® D another set of functional dependencies G. One
(c) AB ® C, C ® AD (d) A ® BCD decomposition is definitely BCNF, the other is definitely
6. Which of the following relational calculus expressions is
3NF, but it is not known which is to make a guaranteed
not safe? [2001, 2 Marks]
identification, which one of the following tests should be
(a) {t | $u Î R1(t[A] = u[A]) Ù Ø$s ÎR 2 (t[A] = s[A])} used on the deocmpositions? (Assume that the closures
(b) {t | "u Î R1(u[A] = “x” Þ $s Î R 2 (t[A] of F and G are available). [2002, 2 Marks]
(a) Dependency-preservation
s[A] Ù s[A] = u[A]))}
(b) Lossless-join
(c) {t | Ø(t Î R1)} (c) BCNF definition
(d) {t | $u ÎR1(t[A] = u[A] = u[A] Ù $s ÎR 2 (t[A] = s[A]))} (d) 3NF definition
Databases S3-199

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

C Numerical Answer Questions


Id Name Age
92. Consider a bank database with only one relation
10 2200 2 transaction (transno, acctno, data, amount)
99 2100 1 The amount attribute value is positive for deposits and
negative for withdrawals. [2000, 5 Marks]
88. How many tuples does the result of the following SQL query (a) Define an SQL view TP containing the information.
contain? [2012, 2 Marks] (acctno, T1.date, T2.amount)
SELECT A. Id for every pair of transactions T1, T2 such that T1
FROM A and T2 are transaction on the same account and the
WHERE A. Age > ALL (SELECT B. Age date of T2 is £ the date of T1.
FROM B (b) Using only the above view TP, write a query to find
WHERE B. Name = ‘Arun’) for each account the minimum balance it ever
(a) 4 (b) 3 reached (not including the 0 balance when the
(c) 0 (d) 1 account is created). Assume there is at most one
89. How many tuples does the result of the following relational transaction per day on each account, and each
algebra expression contain? Assume that the schema of account has had atleast one transaction since it was
created. To simply your query, break it up into 2
A È B is the same as that of A. [2012, 2 Marks]
steps by defining an intermediate view V.
( A È B) A.ld >40Ú C.ld<15C 93. A FAT (file allocation table) based file system is being used
(a) 7 (b) 4 and the total overhead of each entry in the FAT is 4 bytes in
(c) 5 (d) 9 size. Given a 100 × 106 bytes disk on which the file system is
stored and data block size is 103 bytes, the maximum size of
Linked Answer Type MCQs a file that can be stored on this disk in units of 106 bytes is
____________. [2014, Set-2, 1 Mark]
Statements for Linked Answer Questions 90 and 91 94. The maximum number of superkeys for the relation schema
Consider the following ER diagram : R(E, F, G, H) with E as the key is _____.
95. Given an instance of the STUDENTS relation as shown
M1 M2 M3 P1 P2 N1 N2 below : [2014, Set-2, 1 Mark]

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

CONCEPTUAL MCQs 8. (a) According to the problem, R is associated with


functional dependencies, so this clearly indicates that
1. (b) We know that indexing is better if the data block is relation R is in 3NF, i.e., third normal form.
large. The property of 3NF says that there are few or no error
Now, B+ trees are preferred over the binary search are left and therefore, redundancy (arising out of
trees as in B+ trees, transfer of data is in form of data functional dependencies) in resulting set of relations
blocks. These data blocks can store large information is negligible or 0 in most cases.
while transferring, information on a single block is more 9. (c) This is a rule of database theory that relational algebra
efficient. has same power as safe relational calculus.
2. (a) Distinct keyword tells that it will give duplicate entries 10. (c) BCNF is more stricter than 3NF. So if we check database
only once and if r has duplicate entries than it will not for BCNF, then it will definitely be in 3NF.
show them more than once which tells us that if answer Hence (c) is correct option.
is to be same as r then r should not have any duplicate 11. (a) Here * denotes the natural join.
entries. So, maximum and minimum numbers of tuples that can
Options (c) and (d) are completely wrong but in option be present in (Student * Enroll) would be represented
(b) its also not necessary that s must also have no
by the minimum of these min (120, 8) = 8.
duplicate entries thus the answer is option (a).
12. (b) As per the definition and the process of index allocation
3. (c) We need to check two paramenters for the solutions
scheme for blocks in a file, the maximum possible size
1. Loseless join
2. Dependency preserving of file depends on the number of blocks used for index
1. Lossless join R1(AB) Ù R2(CD) ® R1(AB) and the size of the blocks.
Also, R1(AB) Ù R2(CD) ® R1(CD) 13. (d) A transaction reads a data item after it is written by an
But we know that uncommitted transaction.
Functional dependencies A ® B and C ® D As the errors cannot recovered in this situation.
Hence, the statement above is not possible. 14. (c) The relations are as given,
® R(ABCD) is not a lossless join. Students : (Roll_number, Name, Date_of_birth)
2. Dependency preserving Courses : (Course number, Course_name, Instructor)
Since, R1(AB) Ú R2 (CD) ® R(ABCD) Grades : (Roll_number, Course_number, Grade)
It is dependency preserving. Now, the distinct name is to be selected, where
4. (c) Just need to have little knowledge about adjacency 1. Name of the student is selected on the basis of
matrix the grade.
Adjacency matrix is used as a mean to represent the 2. Instructor of the course in Korth.
vertices of a graph that are adjacent to which other 3. Courses selected on the basis of grade.
vertices. Another matrix representation for a graph is 4. Grade should be A.
the incidence matrix. The query thus, computed is name of the students
5. (c) The solution exhibits as another case of multivalued who gets A grade in atleast one of the courses taught
dependency. by Korth.
Here, the given relation is R(A, B, C, D). 15. (a) From the given,
This means all are dependent on eahc other. Date of birth ® Eligibility
Now, A ® B and B ® C Since, Date_of_Birth ® Age; Age ® Eligibility
This implies, A ® C or we can say the AB ® C Also,
Similarly, Course-number ® Instructor
C ® AD Since, Course_number ® Course_name;
6. (c) (c) {t | Ø(t Î R1)} Course_number ® Instructor (from the given)
This option contradicts itself. We want a tuple t and t Checking for 2nd normal form,
itself is in r1 and we want other tuples than t by using It is second normal form, as all the non-prime attributes
negation so it;s not safe. are functionally dependent on the given relation keys.
7. (c) When the tuple (x, y) is deleted, consider the tuple (z, Checking for 3rd normal form,
w). Here, since the non-prime attributes are not dependent
Now, in tupel (z, w), on the candidate key, so it is not the third normal form.
z is the lower bound and hence > X. 16. (b) C is an attribute in R1 but D is a key in K2.
and w is the upper bound and hence > Y. So consider PC (r1) – PD (r2)
® (X, Y) will be easily deleted. So the result of this query would be all those tuples
Therefore, Y > X which are in PC (r1) but not in PD (r2).
Databases S3-211

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)

BCNF is more restricted than 3 NF and 3 NF is more W(Q)


W(P)
restricted than 2 NF and so on.
Consider option (a):
The statement is given which is wrong because every T1 T2
relation which is in 3rd normal form it is not necessar
that those will be in BCNF form. Hence, this is false.
Precedence graph for the schedule
Consider option (b):
When every non-prime attribute of R is fully functionally So, this is not the conflict serilizable schedule so option
dependent on every key of R. (c) is not correct. Also option (d) is eliminated because
above, we have drawn the precedence graph.
Then, that relation is in 2 NF not in 3 NF.
Above schedule is not even view serilizable schedule
Consider option (c):
(it fails the condition of view serializable schedule).
Every relation which is in BCNF, then it is confirmed
So, above schedule is not serializable schedule.
that it is also in 3 NF.
Consider option (d): 44. (b) Suppose, there are two relation schemas R1 (A, B)
This statement is wrong because the relation can be in and R2 (C, D)
r1 and r2 are two relation instances of R1 and R2
both BCNF and 3 NF.
respectively.
S3-214 Databases

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

Now, Name is a function of superclass.


All the possible combination of tuples from r1, r2,...rn = Also, Name can be common/duplicate, so must be
r1 × r2 × r3 × r4...rn. If P is a predicate then select all the implemented in superclass.
condition is denoted by sP (r1 × r2 ×...×rn). Salary is a function of superclass.
If we want to select only some tupels in relation then Also, salary is dependent on the category and hence
composite expression for above SQL is is implemented in the subclass.
P s P (r1 ´ r2 ´ ... ´ rm ) 73. (d) A ®B, BC ®D, E ® C, D ® A
a1 ,a 2 ,...,a n We start form set of all the attributes and reduce
68. (a) Name, course no. " grade them using given functional dependences
Roll no. course no. " grade ABCDEH ABCDEH
Name, Roll no. are candidate keys grade depend upon ABCEH {BC- ® D}
both super keys. ABEH{E ® C} BCDEH {D ® A}
So it is 2NF , non key attribute grade depend upon AEH {A ® B} BEH {E ® C}
super keys fully. ABCDEH
But not in 3NF , since grade is not fully dependent ACDEH {A ® B}
upon all candidate keys ADEH{E ® C}
69. (b) Lets consider A and B first. DEH{D ® A}
So candidate keys are AEH, BEH &DEH
A B 74. (c) On delete cascade says that deletion of a primary key
1 1 value should
delete its all foreign key references.
1 1 So in (2,4) 2 is primary key so tuples (5,2) & (7,2)
2 3 should be deleted,
but in (5,2) 5 is also a key so (9,5) also deleted
2 3
cascade.
Value of relation A is equal to the value of the relation Hence (c) is correct option.
B as A and B follow the same pattern. The value of A
does not change where the value of B does not change. 75. (b)
Lets now consider B and C.
E1 R1 E1
B C
1 1
R2
1 0
3 2 Since R2 is many to many so E1 has some primary key
3 2 so one tables for E1 & to represent many to many
relationship 1 table for R2 which will have the common
Value of relation B is not equal to the value of the attribute of E2.R1 & E2 can be merged. So total 3 tables
relation B as B and C do not follow the same pattern. are required.
The value of C changes where the value of B does not Hence (b) is correct option
change.
70. (d) This query first computes join where marks are less 76. (b) Let the order of leaf node is n.
than or equal to marks are less than or equal to max As per given, Block size = 1 k = 1024
marks, & then selects the name of all the girl students Þ 6 + 7n + (n – 1) 9 = 1024
with more marks than all the boys students. Þ 16n = 1024
71. (c) Let the order of the internal node be X, Þ n = 64
Then from the given, 77. (c) No. of records = 16384
(X – 1) 14 + 6X £ 512 Size of record = 32 byte
Þ 15X – 14 + 6X £ 512 Block size = 1024 = 210
20X £ 256 Here, we need to find the option that satisfies the
X = 26 condition 210.
72. (a) ID is unique so can be implemented in the superclass. Option (a), 8 × 0 = 0
Option (b), 128 × 6 = 768
Employee
Option (c), 256 × 4 = 1024
Option (d), 512 × 5 = 2560
Since, option (c) satisfies the block size, it is the desired
Manager Engineer Secretary answer.
Databases S3-217

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

COMMON DATA MCQs LINKED ANSWER TYPE MCQs


86. (a) S name is selected form Supplier S. Now this S.sid 90. (b) There are 3 entity set, but 2 relations R1 & R2 only.
should not be in C.sid of Catalog C. R1 is one to many from P to M. R2 is one to many from
Therefore, it will find the names of all suppliers who P to N. N is weak entity set here.
have supplied a non-blue part. 91. (a) Two tables in the scenario will be M1,M2,M3,P1 which
87. (b) The candidate key needs to be searched first so that is for relation R1 &N1,N2,P1,P2 with P1 as primary key
the prime attribute (candidate key) is identified. N1 is a weak entity set. This is for relation R2.
Here (sname, city) is the candidate key. So, the prime NUMERICAL ANSWER QUESTIONS
attribute are sname and city.
92. (a) Create view TP (acctno, date amount)
Each supplier and each street has a unique name ®
street, city ® sname as select T1.acctno, T1.date
Since street, city does not form a candidate key as the T2.amount from transaction T1,
candidate key available here is (sname, city), the transaction T2
schema is in 3NF and not in BCNF. where T1.acctno = T2.acctno
88. (a) Result of AUB will be following table and T2.date < = T1.date
Id Name Age (b) Create view V (acctno, date, balance)
---------------- as select acctno, date, sum (amount)
12 Arun 60 from TP
15 Shreya 24 group by acctno, date
99 Rohit 11 Select acctno, min (balance)
25 Hari 40 from V
98 Rohit 20 group by acctno.
The result of given relational algebra expression will 93. 99.6 Number of Entries in the FAT
be
Disk Capacity 108
Id Name Age Id Phone Area = = 3 = 105
Block Size 10
---------------------------------
12 Arun 60 10 2200 02 Total space consumed by FAT
15 Shreya 24 10 2200 02 = 105 ´ 4B = 0.4 ´ 106 B
99 Rohit 11 10 2200 02 Maximum size of the file that can be stored
25 Hari 40 10 2200 02 = 100 ´ 106 – 0.4 ´ 106 = 99.6 ´ 106 B
98 Rohit 20 10 2200 02 94. 8 Maximum no. of super keys = 2n–1
99 Rohit 11 99 2100 01 = 24–1 = 23 = 8
98 Rohit 20 99 2100 01 95. 19 Age cannot be 19 as (Student Name, Student Age) is
89. (b) SELECT A. Id a key.
FROM A 96. 7
WHERE A. Age > ALL (SELECT B. Age Maximum Allocate Need Available
FROM B -3 2 1 1
WHERE B. Name = ‘Arun’) -3 2 1
In the table B ‘Arun’ is not there, so there query in -3 2 1
WHERE clause returns null set.
From the above data, after allocating 2 units of tape to each
If a subquery returns zero rows, the condition evaluates process, with 1 available unit any of the 3 process can be
as true. satisfied in such a way, that no dead lock will be there.
So, all 3 rows will evaluated as true. Therefore it is 7 unit tapes.
Information System and Software Engineering S3-219

9 Information System and


Chapter Software Engineering

Quick Revision Material

Information Gathering Strategies


Methods Used To Gather An Information System's
The strategy consists of identifying information sources, evolving
Requirements
a method of obtaining information from the identified sources
and using an information flow model of organization. Interviews involve at least one systems analyst and at least one
user conversing about the information system's requirements.
Information Sources
Interviewing for requirements is similar to your interviewing for a
The main sources of information are users of the system, forms job position or a television talk show host interviewing a guest.
and documents used in the organization, procedure manuals, rule Observation is the act of the systems analyst going to a specific
books etc, reports used by the organization and existing computer location to observe the activities of the people and machinery
programs(If Any). involved in the problem domain of interest.
Feasibilty Analysis Questionnaires are feedback forms designed to gather information
Feasibility analysisis used to assess thestrengths and weaknesses from large groups of people.
of a proposed project and give directions of activities that shall Creating a prototype of the information system can be done on
improve a project and achieve desired results. an individual level or in a group setting. The idea is to explore
system alternatives by developing small working models of the
Requirements Determination Sub-activities :
proposed system so that user reactions can be gathered.
1. Requirements Anticipation. The systems analyst hypothesizes
that particular requirements are relevant based on his or her SY STEM RE QU IR EMEN TS SP EC IF I CATI ON
previous experience with other similar systems and knowledge (SRS)
about the problem domain. SRS is obtained after excessive discussions with the user. System
2. Requirements Elicitation. The systems analyst uses this requir ements specification specifies what Information
activity to gather the essential requirements from the user requirements will be provided. It does not specify how the system
employing a variety of techniques, such as interviews, will be designed.
questionnaires, group brainstorming meetings, and voice and e
DEVELOPING A DOCUMENT FLOW
mail.
3. Requirements Assurance. The systems analyst uses the DIAGRAM
activity of requirements assurance to validate and verify the Example Word Statement
requirements with the user as being the real and essential
“Our company receives many items from several vendors each
requirements. A user walk through in which the systems analyst
accompanied by a delivery note. A receiving office receives the
and the user together review documented requirements in detail
item and checks the delivery note with corresponding order. Any
is one assurance technique.
discrepancy is reported to purchase office. The items received
4. Requirements Specification. This is the activity that the
along with items received note (with details of items) is sent to
systems analyst uses to explicitly catalog and document the
the inspection office.”
requirements either during or after the elicitation and assurance
activities.
S3-220 Information System and Software Engineering

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

Coupling by state decentralization(as in objects)and


It is the measure of the strength of the inter-connections between component communication is done via parameters
system components. Loose coupling means component changes or message passing.(see Message passing).
are unlikely to affect other components.Shared variables or – No coupling
control information exchange lead to Tight coupling. Loose Modules do not communicate at all with one another.
coupling can be achieved by state decentralization (as in objects) C OH E S IO N
and component communication via parameters or message
A measure of how well a component “fits together”.A component
passing. Coupling and Inheritance.
should implement a single logical entity or function.Various levels
• Types of Coupling
of cohesion have been identified
– Content coupling (high)
· Coincidental cohesion (weak)
Content coupling is when one module modifies or
– Parts of a component are simply bundled together.
relies on the internal workings of another module
· Logical association (weak)
(e.g., accessing local data of another module).
Therefore changing the way the second module – Components which perform similar functions are
produces data (location, type, timing) will lead to grouped.
changing the dependent module. · Temporal cohesion (weak)
– Common coupling – Components which are activated at the same time are
Common coupling is when two modules share the grouped.
same global data (e.g., a global variable). Changing
· Communicational cohesion (medium)
the shared resource implies changing all the modules
using it. – All the elements of a component operate on the same
– External coupling input or produce the same output.
External coupling occurs when two modules share · Sequential cohesion (medium)
an externally imposed data format, communication – The output for one part of a component is the input
protocol, or device interface. to another part.
– Control coupling
· Functional cohesion (strong)
Control coupling is one module controlling the flow
of another, by passing it information on what to do – Each part of a component is necessary for the
(e.g., passing a what-to-do flag). Stamp coupling execution of a single function.
(Data-structured coupling). Stamp coupling is when · Object cohesion (strong)
modules share a composite data structure and use – Each operation provides functionality which allows
only a part of it, possibly a different part (e.g., passing object attributes to be modified or inspected.
a whole record to a function that only needs one
field of it). This may lead to changing the way a SOFTWARE LIFE CYCLE MODELS
module reads a record because a field, which the
The software life cycle is a general model of the software
module doesn't need, has been modified.
development process, including all the activities and work
– Data coupling
products required to develop a software system. A software life
Data coupling is when modules share data through,
cycle model is a particular abstraction representing a software
for example, parameters. Each datum is an elementary
life cycle. Such a model may be:
piece, and these are the only data shared (e.g.,
· activity-centered — focusing on the activities of software
passing an integer to a function that computes a
development
square root).
· entity-centered — focusing on the work products created
– Message coupling (low)
by these activities
This is the loosest type of coupling. It can be achieved
S3-222 Information System and Software Engineering

Software Processes and Process Groups in IEEE 1074


Process Group Processes
Life Cycle Modeling Selection of a Life Cycle Model
Project Initiation
Project Management Project Monitoring and Control
Software Quality Management
Concept Exploration
Pre-development
System Allocation
Requirements
Development Design
Implementation
Installation
Operation and Support
Post-development
Maintenance
Retirement
Verification and Validation
Software Configuration Management
Integral Processes
Documentation Development
Training

Waterfall Model Spiral Model


This prescribes a sequential execution of a set of development Spiral model addresses the weakness of the waterfall model, spiral
and management processes, with no return to an earlier activity model focuses on addressing risks incrementally by repeating
once it is completed. Some variants of the waterfall model allow the waterfall model in a series of cycles or rounds:
revisiting the immediately preceding activity (“feedback loops”) · Concept of Operation
if inconsistencies or new problems are encountered during the · Software Requirements
current activity. · Software Product Design
V-Model · Detailed Design
· Code
Another variant of the waterfall model — the V-model —
· Unit Test
associates each development activity with a test or validation at
· Integration and Test
the same level of abstraction. Each development activity builds a
· Acceptance Test
more detailed model of the system than the one before it, and
· Implementation
each validation tests a higher abstraction than its predecessor.

PLANNING AND MA NAGING THE PRO JECT

Initiating the project


The SRO, or identifier of the potential project should:
1. Define and justify the need for the project
2. Specify, quantify and agree desired outcome and benefits
3. Appoint a Project Manager and if appropriate set up a Project Board
Information System and Software Engineering S3-223

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

The COCOMO 2 model


Long history from initial version published in 1981 (COCOMO-81) through various instantiations to COCOMO 2.COCOMO 2 takes
into account different approaches to software development, reuse, etc.
COCOMO estimation models
Project Formula Description
complexity
Simple PM = 2.4 (KDSI)1.05 ´ M Well-understood applications
developed by small teams.
Moderate PM = 3.0 (KDSI)1.12 ´ M More complex projects where
team members may have limited
experience of related systems.
Embedded PM = 3.6 (KDSI)1.20 ´ M Complex projects where the
software is part of a strongly
coupled complex of hardware,
software, regulations and
operational procedures.

Application composition model • M = PERS ´ RCPX ´ RUSE ´ PDIF ´ PREX ´ FCIL ´


Based on standard estimates of developer productivity in SCED;
application (object) points/month. • A = 2.94 in initial calibration, Size in KLOC, B varies
Formula is from 1.1 to 1.24 depending on novelty of the project,
· PM = ( NAP ´ (1 - %reuse/100 ) ) / PROD development flexibility, risk management approaches
· PM is the effort in person-months, NAP is the number and the process maturity.
of application points and PROD is the productivity. Reuse model estimates
Application-point productivity 1. For generated code:
Based on a standard formula for algorithmic models • PM = (ASLOC * AT/100)/ATPROD
• PM = A ´ SizeB ´ M where • ASLOC is the number of lines of generated code
S3-224 Information System and Software Engineering

• AT is the percentage of code automatically generated.


• ATPROD is the productivity of engineers in integrating this code.
2. When code has to be understood and integrated:
• ESLOC = ASLOC * (1-AT/100) * AAM.
• ASLOC and AT as before.
• AAM is the adaptation adjustment multiplier computed from the costs of changing the reused code, the costs of
understanding how to integrate the code and the costs of reuse decision making.
Post-architecture level
The code size is estimated as:
• Number of lines of new code to be developed;
Scale factors used in the exponent computation in the post-architecture model
Scale factor Explanation
Precedentedness Reflects the previous experience of the organisation with this type of project. Very low means no previous
experience. Extra high means that the organisation is completely familiar with this application domain.
Development Reflects the degree of flexibility in the development process. Very low means a prescribed process is used;
flexibility Extra high means that the client only sets general goals.
Architecture/risk Reflects the extent of risk analysis carried out. Very low means little analysis, Extra high means a complete a
resolution through risk analysis.
Team cohesion Reflects how well the development team know each other and work together. Very low means very difficult
interactions. Extra high means an integrated and effective team with no communication problems.
Process maturity Reflects the process maturity of the organisation. The computation of this value depends on the CMM maturity
Questionnaire but an estimate can be achieved by subtracting the CMM process maturity level from 5.

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

5. Match the following :


Conceptual MCQs (1) Waterfall model (a) Specifications can be
developed
1. The coupling between different modules of a software is
incrementally
categorized as follows [2009, 1 mark]
(2) Evolutionary model (b) Requirements
1. Content coupling 2. Common coupling
compromises are
3. Control coupling 4. Stamp coupling inevitable
5. Data coupling (3) Component-based (c) Explicit recognition
Coupling between modules can be ranked in the order of software engineering of risk
strongest (least desirable) to weakest (most desirable) as (4) Spiral development (d) Inflexible patitioning
follows of the project into
(a) 1, 2, 3, 4, 5 (b) 5, 4, 3, 2, 1 stages
(c) 1, 3, 5, 2, 4 (d) 4, 2, 5, 3, 1 [2014, Set-1, 1 Mark]
2. Which of the following statements are true? (a) 1-a, 2-b, 3-c, 4-d (b) 1-d, 2-a, 3-b, 4-c
[2010, 2 marks] (c) 1-d, 2-b, 3-a, 4-c (d) 1-c, 2-a, 3-b, 4-d
1. The context diagram should depict the system as a 6. Which one of the following is TRUE?
single bubble. [2014, Set-2, 1 Mark]
2. External entities should be identified clearly at all levels (a) The requirements document also describes how the
of DFDs requirements that are listed in the document are
3. Control information should not be represented in a DFD. implemented efficiently.
4. A data store can be connected either to another data (b) Consistency and completeness of functional
store or to an external entity. requirements are always achieved in practice.
(a) 2 and 3 (b) 2 and 3 (c) Prototyping is a method of requirements validation.
(d) Requirements review is carried out to find the errors in
(c) 1 and 3 (d) 1, 2 and 3
system design.
3. What is the appropriate pairing of items in the two columns 7. In the context of modular software design, which one of the
listing various activities encountered in a software life cycle? following combinations is desirable?
[2011, 2 marks] [2014, Set-3, 1 Mark]
(a) High cohesion and high coupling
P. Requirements 1. Module Development (b) High cohesion and low coupling
Capture and Integration (c) Low cohesion and high coupling
Q. Design 2. Domain Analysis (d) Low cohesion and low coupling
R. Implementation 3. Structural and
Behavioral Modeling
Problem Based MCQs
S. Maintenance 4. Performance 8. A company needs to develop digital signal processing
software for one of its newest inventions. The software is
(a) P - 3, Q - 2, R - 4, S - 1 (b) P - 2, Q - 3, R - 1, S - 4 expected to have 40000 lines of code. The company needs to
determine the effort in person-months needed to develop
(c) P - 3, Q - 2, R - 1, S - 4 (d) P - 2, Q - 3, R - 4, S - 1
this software using the basic COCOMO model. The
4. Which of the following is not desired in a good Software
multiplicative factor for this model is given as 2.8 for the
Requirement Specifications (SRS) document?
software development on embedded systems, while the
(a) Functional Requirements [2011, 1 mark]
exponentiation factor is given as 1.20. What is the estimated
(b) Non-Functional Requirements effort in person months? [2011, 1 mark]
(c) Goals of Implementation (a) 234.25 (b) 932.50
(d) Algorithms for Software Implementation (c) 287.80 (d) 122.40
S3-226 Information System and Software Engineering

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.

Input set Expected Output set


Test case Return value
abc Root 1 Root 2
T1 0.0 0.0 7.0 0.0 0.0 –1
T2 0.0 1.0 3.0 0.0 0.0 –1
T3 1.0 2.0 1.0 – 1.0 – 1.0 0
T4 4.0 - 12.0 9.0 1.5 1.5 0
T5 1.0 - 2.0 - 3.0 3.0 – 1.0 0
T6 1.0 1.0 4.0 0.0 0.0 –1
Information System and Software Engineering S3-227

CONCEPTUAL MCQs Control coupling


Control coupling is the process in which one module controls
the flow of another, by passing it information. This
1. (a) HIGH CO NTENT information is basically what work is to be done.
COMMON Stamp coupling
CO NTROL Stamp coupling is the process in which modules share a
composite data structure however use only a part of it.
STAMP 2. (c) 1. The context diagram always depicts the system
LOW DATA as single bubble. Hence, it is true.
2. External entities cannot be identified at all levels
Content coupling (high) of DFD’s. Hence, it is false.
Content coupling is the process in which one module relies 3. DFD does not allow the representation of control
on the internal workings of another module. information. Hence, it is true.
Common coupling 4. A data store cannot be connected to other data
Common coupling is the process in which two modules share stores or external entity. Hence, it is false.
the same global data.

3. (b) Software Development Life Cycle (SDLC)


Operation Disposition
&
maintenance Step X
Imple-
Step IX
mentation
Integration
& test Step VIII

Development Step VII


Design Step VI
Requirement
analysis Step V
Planning
Step IV
System concept
development Step III

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

Thus T6 is example of discriminant < 0.


PROBLEM BASED MCQs
means T3 and T4 are also redundant.
8. (a) Effort person per month 11. (a) Suppose, LOC of project L1 is x.
The LOC of project L2 is 2x.
= a × (kLOC)B [B = exponent; a = multiplicative value] Cost of project L1
= 2.8 × (40)1.20 = Development cost + Maintenance cost
= 234.22 person per month = Manyears × Development cost/year + Maintenance
9. (a) Individual cyclomatic complexity = 10 time × Maintenance cost/year
Now, in the cases of sequential integration, the general x
behaviour is that the complexity is decreased than the = ´ 1000000 + 5 ´ 100000
10000
two independent modules. This decrease is unitary = 100 x + 500000
and hence the answer is 19 (10 + 10 – 1 = 19). Cost of project L2,
10. (c) Test cases T1 and T2 both are examples of a = 0. Thus, = Development cost + Maintenance cost
T1 and T2 are redundant. 2x
For T3 discriminant b2 – 4ac = 4 – 4 = 0 = ´ 750000 + 5 ´ 50000
For T4 discriminant b2 – 4ac = (– 12)2 – 4 × 9 × 4 10000
= 100 × x + 500000 = 150 × x + 250000
= 144 – 144 = 0 100 × x + 250000 = 150 × x
For T5 discriminant b2 – 4ac = (– 2)2 – (– 3) × 4 × 1 50 x = 250000
= 4 + 12 = 16 > 0 x = 5000
Thus T5 is example of discriminant > 0
For T6 discriminant b2 – 4ac = (1)2 – 4 × 1 × 4
= 1 – 16 = – 13
Computer Networks S3-229

10 Computer Networks
Chapter

Quick Revision Material

ISO/OSI NETWORK MODEL


The standard model for networking protocols and distributed applications is the International Standard Organization’s Open
System Interconnect (ISO/OSI) model. It defines seven network layers.
Name of unit
Layer exchanged
Application protocol
7 Application Application APDU

Interface
Presentation protocol
6 Presentation Presentation PPDU

Session protocol
5 Session Session SPDU

Transport Transport protocol Transport TPDU


4
Communication subnet boundary
Internal subnet protocol
3 Network Network Network Network Packet

2 Data link Data link Data link Data link Frame

1 Physical Physical Physical Physical Bit


Host A Router Router Host B
Network layer host-router protocol
Data link layer host-router protocol
Physical layer host-router protocol

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

IEEE 802.3 Frame Structure

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)

6-Byte Address - Every Ethernet card with globally unique address

Individual(0)/Group(1) Unversal(0)/Local(1) Address of the machine


(1 bit) (1 bit) (46 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.

Ethernet Frame Structure

Preamble Dest. Address Source Address Type Data Frame Checksum


(8 bytes) (2/6 bytes) (2/6 bytes) (2 bytes) (46-1500 bytes) (4 bytes)

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 = Code Violation This bit is set if any interface detects an error.


K = Code Violation
FLOW AND ERROR CONTROL
Access Control Format:
FLOW CONTROL
P P P T M R R R Flow control tells the sender how much data to send. It makes
the sender wait for some sort of an acknowledgment (ACK)
T=Token before continuing to send more data.
T = “0” for Token, There are two primary methods of flow control: Stop-and-wait,
T = “1” for Frame. and Sliding Window.
When a station with a Frame to transmit detects a token which Stop And Wait
has a priority equal to or less than the Frame to be transmitted, Stop And Wait is a simple scheme, where the sender has
it may change the token to a start-of-frame sequence and to wait for an acknowledgment of every frame that it
transmit the Frame. sends. It sends a frame, waits for acknowledgment, then it
P = Priority
sends another frame, and again, waits for acknowledgment.
Bits Priority Bits indicate tokens priority, and therefore, which
stations are allowed to use it. Station can transmit if its priority Stop and wait
is atleast as high as that of 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 that the next token be issued at the
requested priority
Frame Control Format:

F F CONTROL BITS (6 BITS)


FF= Type of Packet-Regular data packet or MAC layer packet
Control Bits= Used if the packet is for MAC layer protocol
itself In the above diagram
Data Format: Sender keeps a copy of the last frame until it receives an
No upper limit on amount of data as such, but it is limited by acknowledgement.For identification, both data frames
the token holding time. and acknowledgements (ACK) frames are numbered
alternatively 0 and 1.Sender has a control variable (S) that
Checksum: holds the number of the recently sent frame. (0 or
The source computes and sets this value. Destination too
1).Receiver has a control variable ® that holds the
calculates this value. If the two are different, it indicates an
number of the next frame expected (0 or 1).Sender starts
error, otherwise the data may be correct.
a timer when it sends a frame. If an ACK is not received
Frame Status: within a allocated time period, the sender assumes that
It contains the A and C bits. the frame was lost or damaged and resends it.Receiver
A bit set to 1: destination recognized the packet. send only positive ACK if the frame is intact.ACK
C bit set to 1: destination accepted the packet. number always defines the number of the next expected
This arrangement provides an automatic acknowledgement for frame.
each frame. The A and C bits are present twice in the Frame
Status to increase reliability in as much as they are not covered
by the checksum.
Ending Delimiter Format:

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

When a receiver receives a damaged frame, it discards it Receiver Sliding Window


and keeps its value of R.After the timer at the sender Size of the window at the receiving site is always 1 in this
expires, another copy of frame 1 is sent. If the sender protocol.Receiver is always looking for a specific frame to
receives a damaged ACK, it discards it.When the timer of arrive in a specific order.Any frame arriving out of order
the sender expires, the sender retransmits frame Receiver is discarded and needs to be resent.Receiver window
has already received frame 1 and expecting to receive frame slides as shown in fig. Receiver is waiting for frame 0 in
0 (R=0). Therefore it discards the second copy of frame1. part a.
Stop-and-Wait, delayed ACK frame

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(¥, –)

B(2, A) C(9, B) B(2, A) C(9, B)

E(4, B) E(4, B)
A F(¥, –) D(¥, –) A F(6, E) D(¥, 1)

G(6, A) H(¥, –) G(5, E) H(¥, –)


(c) (d)

B(2, A) C(9, B) B(2, A) C(9, B)

E(4, B) E(4, B)
A F(6, E) D(¥, –) A F(6, E) D(¥, –)

G(5, E) H(9, G) G(5, E) H(8, F)


(e) (f)

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

We look at the distributed version which works on the


Desirable
premise that the information about far away nodes can be
had from the adjoining links.
The algorithm works as follows. Congested
• Compute the link costs from the starting node to
every directly connected node.
• Select the cheapest links for every node (if there is
more than one).
• For every directly connected node, compute the link
costs for all these nodes. Packets sent
• Select the cheapest route for any node.
Repeat until all nodes have been processed. Causes: The bursty nature of traffic is the root cause ? When
Every node should have the information about it’s immediate part of the network no longer can cope a sudden increase of
neighbors and over a period of time we will have information traffic, congestion builds upon. Other factors, such as lack of
about other nodes. Within n units of time , where n is the diameter bandwidth, ill-configuration and slow routers can also bring up
congestion.
of the network, every node will have the complete information.
We do not need to be synchronized i.e. do not need to exchange Open-Loop Congestion Control
information at the same time. Leaky Bucket / Token Bucket
Routing algorithms based on Dijkstra’s algorithm are called Leaky bucket: consists of a finite queue
Link State Algorithms. Distance Vector Protocols are based on – When a packet arrives, if there is a room on the queue
distributed Bellman’s algorithm. In the former we are sending its joins the queue; otherwise, it is discarded
little information to many nodes while in the latter we send – At every (fixed) clock tick, one packet is transmitted
huge information to few neighbors. unless the queue is empty
Computer Networks S3-237

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

sends a choke packet to A. Note how long it takes for A


B C B C
to reduce the rate and eventually to relieve D
A D A D • Solution: Use “push-back” or hop-by-hop choke
Heavy flow
E F E F packets
When choke packet reaches router F, it forwards choke packet

Choke packets in WANs (a) basic, (b) hope-by-hope


e
e

ok
to router E as well as reduces its traffic to D. Thus the problem
ok

Ch
Ch

that D has is “push-back” to F and D gets relief quickly. This


process is repeated down the route until the “ball” is back to
Choke Choke
Reduced the “root” source A.
flow
Hop-by-Hop Choke Packets
This technique is an advancement over Choked packet
Ch

Ch
ok

ok
e
e

method. At high speed over long distances, sending a


packet all the way back to the source doesn’t help much,
Reduced because by the time choke packet reach the source,
flow already a lot of packets destined to the same orginal
destination would be out from the source.
So to help this, Hop-by-Hop Choke packets are used. In
Flow is still
at maximum rate this approach, the choke packet affects each and every
intermediate router through which it passes by.
Flow is Here, as soon as choke packet reaches a router back to
reduced
(a) (b) its path to the source, it curtails down the traffic between
those intermediate routers. In this scenario, intermediate
Choke packets in WANS (a) basic, (b) hope-by-hope nodes must dedicate few more buffers for the incoming
Basic idea: Router checks the status of each output line: traffic as the outflow through that node will be curtailed
if it is too occupied, sends a Choke packet to the source. down immediately as choke packet arrives it, but the
The host is assumed to be cooperative and will slow input traffic flow will only be curtailed down when choke
down. packet reaches the node which is before it in the original
• When the source gets a chock packet, it cuts rate by path.
half, and ignores further choke packets coming from
the same destination for a fixed period.
• After that period has expired, the host listens for P P
Q Chok
e Q
R
more choke packets. If one arrives, the host cut rate Heavy Heavy
R
by half again. If no choke packet arrives, the host (a)
flow
(b)
flow

may increase rate.


P P
Uncooperative cheating host may get all bandwidth while Choke Q Q
R R
cooperative honest host gets penalized ® Use weighted Reduced Reduced Reduced
flow flow flow
fair queueing to enforce cooperation and assign priority (c) (d)

Problem of basic Choke Packets: For high-speed WANs,


return path for a choke packet may be so long that too Depict the functioning of Hop-by-Hop choke packets
many packets have already been sent by the source (a) Heavy traffic between nodes P and Q, (b) Node Q
before the source notes congestion and takes action sends the Choke packet to P, (c) Choke packet
Host in San Francisco (router A) is sending heavy traffic reaches R, and the flow between R and Q is curtail down.
to a host in New York (router D), and D is in trouble. It Choke packet reaches P, and P reduces the flow out.
Computer Networks S3-239

TCP and UDP


TCP UDP
Acronym for: Transmission Control Protocol User Datagram Protocol or Universal Datagram
Protocol
Function: As a message makes its way across the UDP is also a protocol used in message transport or
internet from one computer to another. This transfer. This is not connection based which means
is connection based. that one program can send a load of packets to
another and that would be the end of the relationship.

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

Protocol Role Port POP3 Post Office Protocol 3


HTTP Hyper Text Transfer Protocao 1. The point of POP3 is to fetch email from
the remote mailbox and store it on the 110
• browser and web server communication
1. client browser connects to HTTP server 80 user’s local machine to read later.
2. client browser send a request to the 2. Downloaded emails are then deleted
HTTP server from the server.
3. HTTP server by sending a response
4. HTTP server disconnects IMAP Internet Message Access Control
1. Retrieve e-mails
143
FTP File transfer protocol 2. retaining e-mail on the server and for
20 organizaing it in folders on the serve
1. allow people anywhere on the Internet to
log in and download whatever files they SMTP Sending email
have placed on the FTP server, or upload 25
other files. 1. Sending e-mails
2. Port 20 for data channel and 21 for 2. Establish TCP connection to port 25 of
control channel 21 the destination machine/server
3. Start sending email message
Computer Networks S3-241

(d) The packet source cannot set the route of an


Conceptual MCQs outgoing packets; the route is determined only by
the routing tables in the roaters on the way
1. In serial data transmission, every byte of data is padded
3. Which of the following functionalities must be
with a ‘0’ in the beginning and one or two 1’s at the end
implemented by a transport protocol over and above the
of byte because [2002, 1 Mark]
network protocol? [2003, 1 Mark]
(a) receiver is to be synchronized for byte reception
(a) Recovery from packet losses
(b) receiver recovers lost 0s and 1s from these padded
(b) Detection of duplicate packets
bits
(c) Packet delivery in the correct order
(c) padded bits are useful in parity computation
(d) End to end connectivity
(d) None of the above
4. Which of the following is not true with respect to a
2. Which of the following assertions is false about the
transparent bridge and a router? [2004, 1 Mark]
Internet Protocol (IP)? [2003, 1 Mark]
(a) Both bridge and router selectively forward data
(a) It is possible for a computer to have multiple IP
packets
addresses
(b) A bridge uses IP addresses while a router uses MAC
(b) IP packets from the same source to the same
addresses
destination can take different routes in the network
(c) A bridge builds up its routing table by inspecting
(c) IP ensures that a packet is discarded, if it is unable
incoming packets
to reach its destination within a given number of
(d) A router can connect between a LAN and a WAN
hops

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.

(a) P–1, Q – 4, R – 3 (b) P–2, Q – 4, R – 1 (c) P–2, Q – 3, R – 1 (d) P–1, Q – 3, R – 2


6. In a network of LANs connected by bridges, packets are (a) TCP but not UDP (b) TCP and UDP
sent from one LAN to another through intermediate (c) UDP but not TCP (d) Neither TCP nor UDP
bridges. Since, more than one path may exist between two 9. Two computers C1 and C2 are configured as follows. C1 has
LANs, packets may have to be routed through multiple IP address 203.197.2.53 and netmask 255.255.128.0. C2 has
bridges. Why is the spanning tree algorithm used for
IP address 203.197.75.201 and netmask 255.255.192.0. Which
bridge-routing? [2005, 1 Mark]
one of the following statements is true? [2006, 2 Marks]
(a) For shortest path routing between LANs
(a) C1 and C2 both assume they are on the same network
(b) For avoiding loops in the routing paths
(b) C2 assumes C1 is on same network, but C1 assumes
(c) For fault tolerance
(d) For minimizing collisions C2 is on a different network
(c) C1 assumes C2 is on same network, but C2 assumes
7. The Address Resolution Protocol (ARP) is used for
C1 is on a different network
[2005, 1 Mark]
(d) C1 and C2 both assume they are on different networks
(a) finding the IP address from the DNS 10. For which one of the following reasons does Internet
(b) finding the IP address of the default gateway Protocol (IP) use the Time To Live (TTL) field in the IP
(c) finding the IP address that corresponds to a MAC datagram header? [2006, 1 Mark]
address (a) Ensure packets reach destination within that time
(d) finding the IP address that corresponds to a IP address (b) Discard packets that reach later than that time
8. Packets of the same session may be routed through different (c) Prevent packets from looping indefinitely
paths in [2005, 1 Mark] (d) Limit the time for which a packet gets queued in
intermediate routers
S3-242 Computer Networks

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

Statements for Linked Answer Questions 70 and 71


Frames of 1000 bits are sent over a 106 bps duplex link between N4 N3
2
two hosts. The propagation time is 25 ms. Frames are to be
The network uses a distance vector routing protocol. Once the
transmitted into this link to maximally pack them in transit (within
routes have stabilized, the distance vectors at different nodes
the link). are as following. Each distance vector is the distance of the best
70. What is the minimum number of bits l that will be required to known path at that instance to nodes, N1 to N5, where the distance
represent the sequence numbers distinctly? Assume that to itself is 0. Also, all links are symmetric and the cost is identical
no time gap need to be given between transmission of two in both directions. In each round, all nodes exchange their distance
frames. [2009, 2 Marks] vectors with their respective neighbours, Then all nodes update
(a) l = 2 (b) l = 3 their distance vectors. In between two rounds, any change in
(c) l = 4 (d) l = 5 cost of a link will cause the two incident nodes to change only
71. Suppose that the sliding window protocol is used with the that entry is their distance vectors.
sender window size of 21, where 1 is the number of its 74. The cost of link N2-N3 reduces to 2 in (both directions).
After the next round of updates, what will be the new
identified in the earlier part and acknowledgments are always
distance vector at node N3? [2011, 2 Marks]
piggy backed. After sending 21 frames, what is the minimum
(a) 3, 2, 0, 2, 5 (b) 3, 2, 0, 2, 6
time, the sender will have to wait before starting transmission (c) 7, 2, 0, 2, 5 (d) 7, 2, 0, 2, 6
of the next frame? (Identify the closest choice ignoring the 75. After the update in the previous question, the link N1-N2
frame processing time.) [2009, 2 Marks] goes down. N2 will reflect this change immediately in its
(a) 16 ms (b) 18 ms distance vector as cost ¥ . After the next round of update,
(c) 20 ms (d) 22 ms what will be the cost to N1 in the distance vector of N3?
Statements for Linked Answer Questions 72 and 73 [2011, 2 Marks]
Consider a network with 6 routers R1 to R6 connected with links (a) 3 (b) 9
having weights as shown in the following diagram. (c) 10 (d) ¥
S3-248 Computer Networks

80. In the diagram shown below, L1 is an Ethernet LAN and L2


Numerical Answer Questions is a Token Ring LAN. An IP packet originates from sender S
and traverses to R, as shown. The links within each ISP and
76. Every host in an IPv4 network has a 1-second resolution
across the two ISPs, are all point to point optical links. The
real-time clock with battery backup. Each host needs to
initial value of the TTL field is 32. The maximum possible
generate up to 1000 unique identifiers per second. Assume
value of the TTL field when R receives the datagram is
that each host has a globally unique IPv4 address. Design
________ . [2014, Set-2, 1 Mark]
a 50-bit globally unique ID for this purpose. After what ISP2
period (in seconds) will the identifiers generated by a host ISP1
wrap around? [2014, Set-3, 2 Marks]
77. Consider a token ring network with a length of 2 km having LAN L2
10 stations including a monitoring station. The propagation R
speed of the signal is 2 × 108 m/s and the token transmission S LAN L1
time is ignored. If each station is allowed to hold the token
for 2 msec, the minimum time for which the monitoring station 81. An IP router implementing Classless Inter-domain Routing
should wait (in m sec)before assuming that the token is lost (CIDR) receives a packet with address 131.23.151.76. The
is _______. [2014, Set-1, 2 Marks] router’s routing table has the following entries:
78. Let the size of congestion window of a TCP connection be
32 KB when a timeout occurs. The round trip time of the Output Interface
connection is 100 msec and the maximum segment size used Prefix
Identifier
is 2 KB. The time taken (in msec) by the TCP connection to 131.16.0.0/12 3
get back to 32 KB congestion window is _________. 131.28.0.0/14 5
[2014, Set-1, 2 Marks] 131.19.0.0/16 2
79. Consider a selective repeat sliding window protocol that 131.22.0.0/15 1
uses a frame size of 1 KB to send data on a 1.5 Mbps link
with a one-way latency of 50 msec. To achieve a link The identifier of the output interface on which this packet
utilization of 60%, the minimum number of bits required to will be forwarded is ______. [2014, Set-3, 2 Marks]
represent the sequence number field is ________.
[2014, Set-1, 2 Marks]
Computer Networks S3-249

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

server port 53 for either. Ordinary DNS request can be


made with TCP, through convention dictates the use
192, 168, 0.1 192, 168, 0.2 192, 168, 0.3 of UDP for normal operation. TCP must be used for
00:00:1A:3E:0.2:56 00:C0:BC:00:FF:B1 00:E0:FE:3:09.C2:11
zone transfers, however, because of the danger of
dropping records with an unreliable delivery protocol
such as UDP.
13. (b) Two voltage level are used for binary 0’s and 1’s in
Ethenet Manchester encoding system in Ethernet.
Number of signal elements for 0’s = 2
Number of signal elements for 1’s = 2
Total number of different signal elements,
1 ARP REQUEST
From, 192, 168, 0.1 M=2+2=4
(00:00:1A:3E:02:56) Modulation rate = D
To 192, 168, 0.3 Bit rate = R
(FF:FF:FF:FF:FF:FF)
R
D=
2 ARP REPLY log 2 M
From, 192, 168, 0.3
(00:E0:FE:09:C2:11) R
To 192, 168, 0.1 D=
(00:00:1A:BE:02:56) log 2 4
R
8. (d) Selection of any path during routing of a packet is D= Þ R = 2D
2
done at Network layer not at transport layer, So TCP
14. (c) In a TCP connection The process is
& UDP both have nothing to do with this. P ........ Flag ® S
9. (c) C1 C2 P ........ Sync ® S
IP Addr 203.197.2.53 203.197.75.201 P <........ ACK – S
Mask 255.255.128.0 255.255.192.0 P ........ Data Transfer ® S
N W ID 203.197.0.0 203.197.64.0 If any error occurs connect () system call returns an
error.
Both are at different networks but. The handshake (TCP Handshaking) between sender
and receiver is established by connect () so that SYN
C1 C2 packets could be sent. Now, to send these packets,
203.197. 2. 53 203.197.75.201 server should execute accept () in return so that connect
255.255.192.0 255.255.128.0 () gets an acknowledgement and a handshake could
N/W 203.197.0.0 occur. Since, there is no Handshake, error occurs.
15. (d) Slow start is one of the algorithm that TCP uses to
Interchanging of mask by C1 gives the same N/W ID control congestion inside the network, also known as
as C1 originallyhas for C2 so C1 assumes that C2 is exponential growth phase, here theTCP congestion
one same network, but C2'ssubnet doesn't given window size is increased.
same N/W ID so. 16. (d) The 3 way handshake is shown as below
C2 assumes C1 is not in same network.
Hence (c) is correct option
10. (b) Time to Live (TTL) is a limit on the period of time SYN
or transmissions in computer and computer network SYN/ACK
technology that a unit of data (e.g., a packet) can ACK
experience before it should be discarded. If the limit CONNECT
is not defined then, the packets can go into an
indefinite loop.
11. (b) SMTP (Simple mail transfer Protocol) is application Server
Host
layer based.
Host A sends a TCP SYNchronize packet to Host B
BGP is network layer based.
Host B receives A’s SYN
TCP (Transport Control Protocol) is transport layer
Host B sends a SYNchronize-ACKnowledgement
based.
Host A receives B’s SYN-ACK
PPP (Point to Point protocol) is data link layer based
Host A sends ACKnowledge
protocol. Host B receives ACK. TCP connecting is (Established).
Hence (b) is correct option. SYNchronize and ACKnowledge messagess are
12. (c) Either TCP or UDP can be used as transport protocol indicated by a bit inside the TCP head of the segment.
to transport DNS protocol messages, connecting to
Computer Networks S3-251

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

PROBLEM BASED MCQs


32. (d) Refer the two tables below to find the class of the given subnet mask IP Address Class Network and Host Capacities

IP Address Clas s Class A Class B Clas s C


Total # of Bits 8/24 16/16 24/8
for Network ID/Host ID

First Octet of IP 0xxx xxxx 10xx xxxx 110x xxxx


Addres s
# of Network ID Bits 1 2 3
us ed to Identify Clas s

Us able # of Network ID 8– 1=7 16 – 2 = 14 24 – 3 = 21


Bits

# of Pos s ible Network 7


2 – 2 = 126 2
14
= 16,384 2
21
= 2,097,152
IDs

# of Host IDs per


24 16 8
Network ID 2 – 2 = 16,277,214 2 – 2 = 65,534 2 – 2 = 254

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

IP Address Class Class A Class B Class C


Total # of Bits 8/24 16/16 24/8
for Network ID/Host ID

First Octet of IP 0xxx xxxx 10xx xxxx 110x xxxx


Address
# of Network ID Bits 1 2 3
used to Identify Class

Usable # of Network ID 8– 1=7 16 – 2 = 14 24 – 3 = 21


Bits

# of Possible Network 7
2 – 2 = 126
14
2 = 16,384
21
2 = 2,097,152
IDs

# of Host IDs per


24 16 8
Network ID 2 – 2 = 16,277,214 2 – 2 = 65,534 2 – 2 = 254

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

3. Station A sends frame 1 to Station B A = = 6 = = = Þ B (A sends packet 6 to B)


4. Station B receive frame 1 and sends an A <= = ACK for 5 = = = B (B sends acknowledgment
acknowledgement (ack) as RR2 for 5 that 5 is not received)
5. Station A sends frame 2 to Station B A = = 5 = = = Þ B (A sends packet 5 to B)
6. Station B receive frame 2 and sends an A = = 7 = = = Þ B (A sends packet 7 to B)
acknowledgement (ack) as RR3 A = = 8 = = = Þ B (A sends packet 8 to B)
7. Station A sends frame 3 to Station B A = = 9 = = = Þ B (A sends packet 9 to B)
8. Station B receive frame 3 and sends an 43. (b) Bandwidth delay production = Roundtrip delay ×
acknowledgement (ack) as RR4 Bottle neck bandwidth
9. Station A sends frame 5 to Station B = 80 × 10–3 × 128 × 1024 bit
10. Station B receive frame 5 and sends an
acknowledgement (ack) as RR6 80 ´ 10 -3 ´ 128 ´ 1024
11. Station A sends frame 6 to Station B = bit
8
12. Station B receive frame 6 and sends an
acknowledgement (ack) as RR7 [because 1 byte = 8 bit]
13. Now, RR7 is lost in the transmission. Since, Station A Now, Optimal size window
will send frame 7 Bandwidth Delay Production
only after receiving RR7, so it will Time Out as RR7 is =
Packet size
already lost.
14. Now, A times out retransmit frame 0 80 ´ 10-1 ´ 128 ´1024
15. But B was expecting frame 7, so it considers frame 7 as = bits = 40
Lost and accept frame 0 as a new frame 8 ´ 32
This problem is overcome by limiting the maximum 44. (b) As the distance is L km,
windows size to 2n–1. Total propagation delay = L km × t s = Lt
40. (d) Packet switched network message = 24 byte Roundtrip time (back and forth) = 2 × Lt s
Header size = 3 From Channel Capacity (as given),
Case 1 If packet size = 4 Number f bits transmitted in roundtrip = 2 LtR bits
Then data = 4 – 3 = 1 byte only Number of frames = 2 LtR/K
So require 24 packets Assume, the number of bits in sequence number to be
Case 2 Packet size 6 x.
Data = 6 – 3 = 3 Frames = 2x
Require 8 pakets. Þ 2x = 2 LTR/K Þ x = [log2 2 LTR/K]
Case 3 Packet size = 7 45. (b) The message P(x) = 11001001
Data = 7 – 3 = 4 Divisor, D(x) = 1001
Require 4 CRC Remainder = 011
24 = 4 packets. Therefore, the transmitted message comes out to be –
Case 4 Packet size = 9 11001001011
Data = 9 – 3 = 6 46. (c) With a class B Host, if it is to be split in a 6 Bit subnet
Require 6 number (As given),
= 24 = 4 packets. Then,
So min requirement is in case 4. It would have a 10 bit host number
41. (d) We are given with To understand this ->
Jamming Signal = 48 bit It is with a 16 Bit host number that it is divided into 6
Round trip propagation delay = 46.4 ps bit Subnet number and 10 bit host number
Now, To get actual round propagation time, subtract 0 16 31
transmission time of 48 bit
1 0 net Id host Id
We get actual round propagation time = 51.2 ms.
42. (a) As in a data transfer from A to B. The message So, 16 Bit hos number is divided and we can calculate
consists of 9 packets. The transmission can be the following,
shown as follows: Maximum of subnets = 2^6 – 2 = 62
A = = 1 = = = Þ B (A sends packet 1 to B) Maximum number of host in each subnet
A = = 2 = = = Þ B (A sends packet 2 to B) = 2^10 – 2 = 1022
A = = 3 = = = Þ B (A sends packet 3 to B) 47. (c) 107 bits require time = 1 s
A <= = ACK = = = B (B sends back acknowledgment Þ 1 Bit require = 1/107 s (unitary method)
to A) 6
-
A = = 4 = = = Þ B (A sends packet 5 to B) = 1/(10 × 106) = 10 10 s = 1/10 ms
A = = 5 = = = Þ B – lost packet (A sends packet 5
Now, 1 ms = 200 m cable
to B and this packet is lost) Þ 1/10 ms = 20 m cable
Computer Networks S3-255

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

III transmission So, for network, there are 24 bits


50 + 100 = 150 bytes transmitted 20 times from A. But for class C addressing, the first 3 bits are used to
represent class C network.
8
For 150 bytes Þ 150 × = 1.2 m sec. 110 ......... ......... ............. ...................
106
3 bits Network ID Host ID
From A, transmission time for entire packet = 1.2 × 20
= 24 m sec. For class C
i.e., 21 bits.
From A, R1 and R2 it takes T3 = 24 + 1.2 + 1.2
= 26.4 m sec. (to reach B) We have 21 bits to generate network for class C. So
\ T1 = T3 = 26.4 m sec. total number of network in class C = 221.
67. (c) E-mail uses SMTP (Simple Mail Transfer Protocol) in
T2 = 19.6 m sec. < T3
application layer to transfer mails and SMTP uses TCP
(Transport Control Protocol) to transfer data in
62. (a) Router transport layer.
4404 bytes
m 1500 bytes LINKED ANSWER TYPE MCQs
MTU
68. (a)

Data length 1480 1480 1444


+ +
Header length 20 20
MF 1 1 0
63. (b) Output bit – string after stuffing : 0111110 Þ 0101
(Stuffed bit)
\ Input string is 0111110101

COMMON DATA MCQs


The required depth first traversal is
B1 ® B5 ® B3 ® B4 ® B2.
64. (b) The Nyquist theorem, also known as the sampling 69. (a) The answer is simple. As we know the correct answer
theorem, is a principle that engineers follow in the of depth first traversal, the forwarding table for B3:
digitization of analog signals. For Analog-to-Digital comes out be
Conversion (ADC) to result in a faithful reproduction Hosts Port
of the signal, slices, called samples of the analog H1, H2, H3, H4 3
waveform must be taken frequently. The number of
samples per second is called the sampling rate or H5, H6, H9, H10 1
sampling frequency. H7, H8, H11, H12 2
Hence, by ignoring errors. i.e., noise so B = 2H
(Nyquist theorem) Number of bits 1000
70. (d) Pulse rate = = = 4 × 104
Here, the maximum data transferred = 180 kb Time taken 25 ´ 10-3
Þ Þ B = 2 ´ 180 Now, Bit rate = Pulse rate × 21
= 360 kbps 21 = 25 Þ I = 5
» 354.5 kbps 71. (b) Time taken to send 10^6 bits = 1 s
Now, as 1 frame = 1000 bits
65. (d) Size of message sent by network A = 180 byte Time taken to send 2^5 frames = 32 ms
The size received by B = 100 Byte Also, Time taken for first frame to be acknowledged
Now, in the best considered case, = 25 × 2 = 50 ms
The only possible combination is Hence, the waiting time = 50 – 32 = 18 ms
72. (d) According to the problem, all the routers use the
20 80 20 80 20 40 distance vector based routing algorithm to update their
(20 + 80) + (20 + 80) + (20 + 40) routing tables. Each router starts with its routing table
= 260 Byte initialized to contain an entry for each neighbour with
66. (c) In class C of IPv4 addressing the weight of the respective connecting link.
Here, the routing table for Router R1 will not have any
8 bit 8 bit 8 bit 8 bit entry to router R6 when all the routing tables have
...................................... .............
stabilized for R1. Hence, there will not only be 1 link
Network ID Host ID that will never be used for carrying any data.
S3-258 Computer Networks

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

Quick Revision Material


HTML • Headings: HTML headings are defined with the <h1> to
• HTML stands for Hyper Text Markup Language <h6> tags:
• An HTML file is a text file containing small markup tags <h1>Heading1</h1>
• The markup tags tell the Web browser how to display the <h2>Heading2</h2>
page <h3>Heading3</h3>
• An HTML file must have an htm or html file extension <h4>Heading4</h4>
MARKU P <h5>Heading5</h5>
<h6>Heading6</h6>
• The following is an example of the classic Hello world
• Paragraphs:
program, a common test employed for comparing
<p>Paragraph 1</p> <p>Paragraph 2</p>
programming languages, scripting languages and markup
languages. This example is made using 9 lines of code: Line breaks:<br />. The difference between <br /> and <p>
is that 'br' breaks a line without altering the semantic
<!DOCTYPE html>
structure of the page, whereas 'p' sections the page into
<html>
paragraphs. Note also that 'br' is an empty element in that,
<head> while it may have attributes, it can take no content and it
<title>This is a title</title> may not have an end tag.
</head> <p>This <br /> is a paragraph <br /> with <br /> line breaks</
<body> p>
<p>Hello world!</p> • Comments:
</body> <!-- This is a comment -->
</html> Comments can help in the understanding of the markup
and do not display in the webpage.
• (The text between <html> and </html> describes the web
page, and the text between <body> and </body> is the ATTRIBUTES
visible page content. The markup text '<title>This is a title</
There are several common attributes that may appear in many
title>' defines the browser page title.)
elements :
EL EM EN TS • The id attribute provides a document-wide unique identifier
for an element. For example, the ID "Attributes" in http://
Element examples-
en.wikipedia.org/wiki/HTML#Attributes
Header of the HTML document:<head>...</head>. Usually the
title should be included in the head, for example: • The class attribute provides a way of classifying similar
<head> elements. Multiple class values may be specified; for
<title>The Title</title> example class="notation important" puts the element into
</head> both the 'notation' and the 'important' classes.
S3-260 Web Technology

• 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

<COL> Identifies a particular Can be very useful. e.g. < col


column in a table class="namecol"> can be applied to each first column in a series of tables, then the width
of each column may be set to be equal in the stylesheet, overriding the table's natural
tendency to adjust its own column widths to fit its contents.
<DFN> Definition of a term Works in a similar way to <abbr> and <acronym>, using a title attribute (displays a tooltip
in standard visual browsers).
<DIR> Directory list Now deprecated. Use a standard <ul> or other list instead.
<DIV> Division Specifies a logical division within a document. Use it to separate or identify chunks of
content that are not otherwise distinguished naturally using other tags.
One of the most common HTML tags.
<DL> Definition list Contains one or more definition-term / definition-description pairs.
<DT> Definition term Used as part of a <dt></dt><dd></dd> pair within a definition list (<dl></dl>)
<DD> Definition description
<EM> Emphasis Commonly used in place of the old <i> (italics) tag to indicate emphasis (but less than
<strong>)
<FONT> Font settings Display info - never use it
<FORM> Input form Essential for data input
<H1> Level 1 header Aim to have one H1 on each page, containing a description of what the page is about.
<H2> Level 2 header Defines a section of the page
<H3> Level 3 header Defines a sub-section of the page (should always follow an H2 in the logical hierarchy)
<H4> Level 4 header Etc. Less commonly used
<H5> Level 5 header Less commonly used. Only complex academic documents will break down to this level of
detail.
<H6> Level 6 header Less commonly used
<HEAD> Document head Essential. Contains information about a page that does not constitute content to be
communicated as part of the page.
<HR> Horizontal rule Display info with no semantic value - never use it. "Horizontal", by definition, is a visual
attribute.
<HTML> Core element of every web page.
<IMG > Show an image Vital. Always use the alt or longdesc attributes when the image has content value
<INPUT> Input fields within forms Vital. (I prefer to use <button> for buttons and submit buttons though)
<ISINDEX> Old type of search input Not really used any more. Use <form> instead.
<I> Italicised text Display info - never use it
<KBD> Keyboard input Display info - never use it
<LINK> Defines a relationship Commonly used to reference external
to another document stylesheets, but has other minor uses
<LI> List item Specifies an item in an unordered or ordered list (<ul> or <ol>)
<MAP> Client-side imagemap May have occasional value, but only use when absolutely necessary
<MARQUEE> Makes text scroll See <blink>
across the screen
<MENU> Menu item list Deprecated. Do not use. Use other standard list types instead.
<META> Meta-information Useful way to insert relevant information into the <head> section of the page that does not
need to be displayed.
<OL> Ordered list Type of list where the order of elements has some meaning. Generally rendered with item
numbers (best managed with CSS).
S3-262 Web Technology

<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

<TT> "Teletype" - simulates Similar to <pre>, except that it collapses white


typewriter output space like normal HTML (whereas <pre> leaves all consecutive white space intact). Avoid
if possible
<UL> Unordered list Essential. Use for lists where the order or items has no particular importance.
<U> Underline text Display info - never use it
<VAR> Variable in computer Obscure tag, may only be useful in academic
code documents. Avoid.

Xml Text content is specified as #PCDATA, and mixed content is


XML is a standard for adding structure to data. An XML parser specified by combining #PCDATA and element content as choices
can process an XML document and present the data to an in the content model. The #PCDATA content must be listed first:
application. <!ELEMENT order (#PCDATA)>
<!ELEMENT order (#PCDATA | elem1| elem2 | elem3)*>
Xml Tags With mixed content you must also include a 'cardinality indicator'
An XML tag is text that begins with a < and ends with a >. Tags of 'zero or more' (*) after the closing bracket of the content model.
are normally paired in which case the closing tag has the same Other cardinality indicators are 'zero or once' (?), 'once or more
text but begins with a </. Whitespace is allowed before the closing (+). If no cardinality indicator is given, this indicates 'once and
> of a tag, but not immediately after the opening < of a start-tag or only once'
the opening </ of a end-tag. The content model can also be specified as 'empty' (no content)
or 'any' (any content from the DTD can appear in any order):
Xml Declarations
<!ELEMENT br EMPTY>
An XML declaration, if used, must occur at the first character on <!ELEMENT comment ANY>
the first line of the file. The declaration must begin with <?xml and
end with ?>. The declaration must identify the version number, Entity Declarations
and can optionally also specify values for the encoding and Entity Type Description
standalone attributes, in that order
Built-in There are five built-in entities in XML: &, <, >,’,”.
N am e s p a c e s To use these entities, begin with an & character,
A namespace allows you to localize elements: the same name can followed by the entity name (amp, it, gt, apos,
be used in different namespaces to identify different elements. quot), and end with a semi-colon
The namespace prefix can then be attached to element names: Character To use unicode characters, begin with a
<ord:orders xmlns:ord="http://www.myweb.com/orders" / ampersand, followed by a hash, the unicode value
> for the character, and finish with a semicolon. Or
<ord:id>09BA3423</ord:id> you can use the hexidecimal Unicode value by
<ord:item>Widget 5</ord:item> beginning with an ampersand, followed by a hash,
</ord> an ‘x’, the hexadecimal value and finish with a
DTD semicolon. The unicode charts can be found at
General Must be declared previously in the DTD before
A DTD allows you to define a valid vocabulary for an XML
use. Generally used to specify reusable string and
document. The XML document can then be validated against the
can be declared using internal declaration,
DTD. DTDs should be placed on the line immediately following
texternal system declaration or extemal public
the XML declaration and take the form:
<!DOCTYPE root-element-name [ ]> declaration:
• <!ENTITY my-string “Bult with Template
Between the square brackets, you can place declarations for the Toolkit”>
elements, attributes and entities defined by the DTD: this is called • <!ENTITY my-object “filename. txt”>
internal subset declaration. To refer to a general entity, simply precede the
Element Declarations entity name with a ampersand: & my-string
The element declaration begins: <!ELEMENT followed by the Parameter Unlike General entities, Parameter entities car be
element name and a definition of the content (content model). made from DTD declaration, and thus can be used
The content model may contain element children, text, a to refer to other DTDs, allowing modular
combination of both or it may be empty. For element content, the development of DTDs:
content can be specified as a sequence or option group or both: <!ENTITY % HTML lat1 PUBLIC”-//W3C//
<!ELEMENT order (elem1, elem2, elem3)> ENTITIES Latin 1 for XHTML//EN” xhtml-
<!ELEMENT order (elem1 | elem2 | elem3)> lat1.ent”>
<!ELEMENT order (elem1 | (elem2, elem3))> To refer to a Parameter entity precede the name
<!ELEMENT order (elem1, (elem2 | elem3))> with a percent sign
S3-264 Web Technology

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

4. A graphical HTML browser resident at a network client


Conceptual MCQs machine Q accesses a static HTML webpage from a HTTP
1. Consider the HTML table definition given below: server S. The static HTML page has exactly one static
<table border = 1> [2009, 2 marks] embedded image which is also at S. Assuming no caching,
<tr> <td rowspan = 2> ab </td> which one of the following is correct about the HTML
<td colspan = 2> cd </td> webpage loading (including the embedded image)?
</tr> [2014, Set-2, 2 Marks]
<tr><td> ef </td> (a) Q needs to send at least 2 HTTP requests to S, each
<td rowspan = 2> gh </td> necessarily in a separate TCP connection to server S
</tr> (b) Q needs to send at least 2 HTTP requests to S, but a
<tr> <td colspan = 2> ik </td> single TCP connection to server S is sufficient
</table>
(c) A single HTTP request from Q to S is sufficient, and a
The number of rows in each column and the number of
single TCP connection between Q and S is necessary
columns in each row are
(a) <2, 2, 3> and <2, 3, 2> (b) <2, 2, 3> and <2, 2, 3> for this
(c) <2, 3, 2> and <2, 3, 2> (d) <2, 3, 2> and <2, 2, 3> (d) A single HTTP request from Q to S is sufficient, and
2. Which one of the following is not a client server application? this is possible without any TCP connection between
[2010, 1 mark] Q and S
(a) Internet chat (b) Web browsing
(c) E-mail (d) Ping
3. Match the problem domains in group I with the solution
technologies in group II.
Group I Group II
P. Service oriented 1. Interoperability
computing
Q. Heterogeneous 2. BPMN
communicating systems
R. Information 3. Publish-find-bind
representation
S. Process description 4. XML
[2013, 1 Mark]
(a) P-1, Q-2, R-3, S-4 (b) P-3, Q-4, R-2, S-1
(c) P-3, Q-1, R-4, S-2 (d) P-4, Q-3, R-2, S-1
S3-266 Web Technology

CONCEPTUAL MCQs Output generated is

1. (c) The answer is a simple HTML output which can be C1 C2 C3


visualized as follows R1 cd
Consider the first line of the coding: ab
R2 ef
<td rowspan = 2> ab </td> gh
R3 ik
Output obtained is
ab Now, with the final output, we can count the number
of rows and columns,
Adding another line of code: <td colspan = 2> cd
where R1, R2 and R3 are the rows and C1, C2 and C3
</td>
are the columns.
ab cd Hence, the answer is <2, 3, 2> and 2, 3, 2.
Output becomes 2. (d) Ping is an administration utility of the computer
With the next line of coding: <tr> <td> ef </td> network. It is used to test whether a host is reachable
across an Internet Protocol (IP) network or not.
cd
ab Ping is not a client server application as it operates by
ef
sending Internet Control Message Protocol (ICMP)
Output becomes echo and waits for an ICMP response. Hence, the main
And with another line of code: <td rowspan = 2> purpose of ping is to measure the round-trip time and
gh </td> records any packet loss.
cd All of three other options reflect client server
ab applications as these are the services provided by the
ef gh
internet services and internet works on a client server
Output becomes architecture.
Finally with list line of code 3. (c)
<tr> <td colspan = 2> ik </td> 4. (b) Q needs to send 2 HTTP requests and 1 TCP
connection to server S.
cd
ab
ef
gh
ik

S-ar putea să vă placă și