Professional Documents
Culture Documents
INSTRUCTIONS
1. Mail your Order ID at ebooks.support@aiets.co.in
to get the 16 digit Access Code.
2. Go to www.educoreonline.com/register.htm
3. Enter your details along with your 16 digit Access
Code.
4. Click Register & you would be successfully
redirected to the Login Page.
Note: If you are already registered with us, you just
have to login (http://www.educoreonline.com/login.
htm) & enter your new 16 Character Unique Code
under your Account Section.
5. Login with your registered email ID & password.
Typeset by Disha DTP Team 6. You can now view you e-book(s) under your Library.
7. You can read your e-books either Online or Offline.
For offline, simply download our Educore App once
& download the e-books inside the app. Educore App
Compiled & Edited by Vinit Garg (B. Tech, M. Tech) is available for Windows Desktop, IOS & Android.
8. Educore works best in Desktop, Laptop, 7” & 10”
tablets.
9. Contact us at support@educoreonline.com for any
further assistance.
Note: This app is not accessible on Mobiles.
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.
1. English Grammar 1 - 14
2. Sentence Completion 15 - 22
3. Synonyms & Antonyms 23 - 34
4. Verbal Analogies / Contexual Usage 35 - 42
5. Critical Reasoning & Verbal Deduction 43 - 54
1. Number System 55 - 66
2. Algebra 67 - 78
3. Percentage & Its Applications 79 - 86
4. Time, Work, Speed and Distance 87 - 100
5. Ratio, Proportion, Partnership and Mixtures (Aligations) 101 - 112
6. Permutation and Combination & Probability 113 - 124
1. Mathematical Logic 1 - 10
2. Probability 11 - 28
4. Combinations 47 - 56
EBD_7203
5. Graph Theory 57 - 66
6. Linear Algebra 67 - 90
1. Digital Logic 1 - 46
The key idea, which allows this book to deal with a wide range of content related to the CS & IT Exams along with
covering each and every topic, is based on the syllabus introduced by IIT for GATE. Covering 100% topics of the
syllabus for CS & IT Exam, the content of this book includes an extended version of a collection of exhaustive theory,
past year questions, practice problems and 10 practice sets.
In writing this book, we have assumed that readers are well acquainted with the very basic concepts of Computer
Architecture, Programming, Theory of Computation, Algorithms, etc. Drafted in compliance with GATE syllabus by
qualified and experienced professionals, this book has questions of previous 13 years of GATE examinations. Having
100-150 questions in each unit with detailed solutions, this book in helpful in practicing and preparing for the exams
in an effective manner within the shortest span of time.
Structured approach, Introduction of Concepts in Simple Terms, Fundamental Principles in Context of Simple
Application and Accuracy were our main objectives that we aimed while writing this book. In order to make sure that
the students get well prepared for the exams, we have divided into three section.
Students who read this book will gain a basic understanding of principles, problems and solutions, including an
introduction to the format of GATE exam.
SUPPLEMENTS: Online Tests which contains 4 Practice Sets designed exactly on the exact pattern of GATE exam.
ACKNOWLEDGEMENT
Special thanks go to our team which has given its best possible effort to prepare such a book, thoroughly checked
the solutions, so as to eliminate any possibility of error.
However, some errors may have crept in, so feedbacks from the readers regarding the same are highly appreciated.
Author
EBD_7203
Syllabus for Computer Science &
Information Technology
SECTION I : GENERAL APTITUDE(GA) Memory hierarchy: cache, main memory and secondary
storage; I/O interface (interrupt and DMA mode).
Programming and Data Structures ____________
Verbal Ability: _____________________________
Programming in C. Recursion. Arrays, stacks, queues,
English grammar, sentence completion, verbal analogies, linked lists, trees, binary search trees, binary heaps,
word groups, instructions, critical reasoning and verbal graphs.
deduction.
Algorithms ________________________________
Numerical Ability: __________________________
Searching, sorting, hashing. Asymptotic worst case time
Numerical computation, numerical estimation,
and space complexity. Algorithm design techniques:
numerical reasoning and data interpretation.
greedy, dynamic programming and divide and conquer.
Graph search, minimum spanning trees, shortest paths.
SECTION II : ENGINEERING MATHEMATICS Theory of Computation _____________________
Regular expressions and finite automata. Context-free
Engineering Mathematics: ___________________ grammars and push-down automata. Regular and contex-
Discrete Mathematics: Propositional and first order logic. free languages, pumping lemma. Turing machines and
Sets, relations, functions, partial orders and lattices. undecidability.
Groups. Graphs: connectivity, matching, coloring. Compiler Design ____________________________
Combinatorics: counting, recurrence relations, Lexical analysis, parsing, syntax-directed translation.
generating functions. Runtime environments. Intermediate code generation.
Linear Algebra: Matrices, determinants, system of linear Operating System __________________________
equations, eigenvalues and eigenvectors, LU
Processes, threads, inter process communication,
decomposition.
concurrency and synchronization. Deadlock. CPU
Calculus: Limits, continuity and differentiability. Maxima
scheduling. Memory management and virtual memory.
and minima. Mean value theorem. Integration.
File systems.
Probability: Random variables. Uniform, normal,
exponential, poisson and binomial distributions. Mean, Databases _________________________________
median, mode and standard deviation. Conditional ER-model. Relational model: relational algebra, tuple
probability and Bayes theorem. calculus, SQL. Integrity constraints, normal forms. File
organization, indexing (e.g., B and B+ trees). Transactions
and concurrency control.
SECTION III : TECHNICAL SECTION
Computer Networks ________________________
Concept of layering. LAN technologies (Ethernet). Flow
Digital Logic _______________________________
and error control techniques, switching. IPv4/IPv6,
Boolean algebra. Combinational and sequential circuits. routers and routing algorithms (distance vector, link
Minimization. Number representations and computer
state). TCP/UDP and sockets, congestion control.
arithmetic (fixed and floating point).
Application layer protocols (DNS, SMTP, POP, FTP, HTTP).
Computer Organization and Architecture ______ Basics of Wi-Fi. Network security: authentication, basics
Machine instructions and addressing modes. ALU, of public key and private key cryptography, digital
data ]path and control unit. Instruc on pipelining. signatures and certificates, firewalls.
TOPIC WISE NUMBER OF QUESTIONS ANALYSIS
Gate Computer Science & Information Technology (2005-17)
Subject 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
General Aptitude - - - - - - 10 10 10 10 10 10 10
Engg. Mathematics 18 14 15 18 10 11 6 6 6 8 6 11 11
TECHNICAL SECTION
Digital Logic 9 6 8 5 2 5 5 4 4 3 2 5 3
Computer Organization
13 7 8 12 6 5 7 6 8 4 4 3 8
and Architecture
Programming and Data
8 6 4 4 4 8 5 8 6 8 8 8 7
Structures
Algorithm Analysis 12 15 15 17 9 4 8 6 8 7 7 4 3
Theory of Computation 7 8 7 9 7 4 6 5 3 4 4 6 4
Compiler Design 6 6 6 4 1 3 1 4 4 3 5 3 4
Operating system 2 9 8 7 7 5 5 4 2 5 5 5 4
Databases 7 5 6 6 5 5 3 6 5 5 4 4 5
Computer Networks 9 11 14 9 5 8 3 6 5 6 5 6 6
Web Technologies - - - - - - - - 2 1 2 - -
EBD_7203
2017
SET - 1
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. The subject specific GATE paper section consists of 55 questions. The GA section consists of 10 questions.
3. 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.
4. 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
TECHNICAL n
where A = [a1.......an] and b = å ai . The set of equations has
QUESTION 1 TO 25 CARRY ONE MARK EACH i =1
(a) a unique solution at x = Jn where Jn denotes a n -
1. The statement (Ø p) Þ (Ø q) is logically equivalent to dimensional vector of all 1
which of the statements below? (b) no solution
I. p Þ q II. q Þ p (c) infinitely many solutions
III. (Ø q) Ú p IV. (Ø p) Ú q (d) finitely many solutions
(a) I only (b) I and IV only 4. Consider the following functions from positive integers to
(c) II only (d) II and III only real numbers:
2. Consider the first-order logic sentence F: " x ( $ y R(x,y)). 100
Assuming non-empty logical domains. which of the 10, n , n , log2 n, .
n
sentences below are implied by F?
The CORRECT arrangement of the above functions in
I. $ y ( $ y R(x, y)) II. $ y ( " x R(x, y)) increasing order of asymptotic complexity is:
III. " y ( $ x R(x, y)) IV. Ø $ x ( " y Ø R(x, y))
100
(a) IV only (b) I and IV only (a) log2 n, , 10, n,n
(c) II only (d) II and III only n
100
n (b) , 10, log2n, n,n
3. Let C1.......Cn be scalars not all zero, such that å ci ai =0 n
i =1 100
(c) 10, , n , log2 n, n
where ai are column vectors in Rn. Consider the set of n
linear equations 100
Ax = b (d) , log2 n, 10, n,n
n
EBD_7203
2017 -2 SOLVED PAPER - 2017
5. Consider the following table: 10. Consider the following context-free grammar over the
alphabet å = {a, b, c} with S as the start symbol:
Algorithms Design Paradigms
S ® abScT | abcT
(P) Kruskal (i) Divide and Conquer
(Q) Quicksort (ii) Greedy
T ® bT | b
(R) Floyd-Warshall (iii) Dynamic Programming
Which one of the following represents the language
generated by the above grammar?
Match the algorithms to the design paradigms they are (a) {(ab)n(cb)n ] n ³ 1}
based on.
(a) (P) « (ii), (Q) « (iii), (R) « (i) (b) {(ab)n cb m1 cb m2 ... cb mn | n, m1 m2 ..., mn ³ 1}
(c) {(ab)n (cbm)n | m, n ³1}
(b) (P) « (iii), (Q) « (i), (R)« (ii)
(d) {(ab)n(cbn)m | m,n ³ 1}
(c) (P) « (ii), (Q) « (i), (R) « (iii)
(d) (P) « (i), (Q) « (ii), (R) « (iii) 11. Consider the C struct, defined below:
6. Let T be a binary search tree with 15 nodes. The minimum struct data {
and maximum possible heights of T are: int marks [100];
Note: The height of a tree with a single node is 0. char grade;
(a) 4 and 15 respectively int cnumber;
(b) 3 and 14 respectively };
(c) 4 and 14 respectively struct, data student;
(d) 3 and 15 respectively The base address of student is available in register Rl. The
7. The n-bit fixed-point representation of an unsigned real field student grade can be accessed efficiently using
number X uses /bits for the fraction part. Let i = n — f. The (a) Post-increment addressing mode, (Rl)+
range of decimal values for X in this representation is
(b) Pre-decrement addressing mode, – (Rl)
(a) 2–f to 2i
(c) Register direct addressing mode, Rl
(b) 2–f to (2i – 2–f)
(c) 0 to 2i (d) Index addressing mode. X(R1), where X is an offset
(d) 0 to (2i – 2–f) represented in 2’s complement 16- bit representation.
8. Consider the C code fragment given below. 12. Consider the following intermediate program in three address
typedef struct node { code
int data ; P= a – b
node* next; q= P*c
} node ; P= u * v
void join (node* m, node* n){ q=p+q
node* p = n; Which one of the following corresponds to a static single
while (p – > next != NULL) { assignment form of the above code?
p = p– > next ;
(a) p1 = a – b (b) p3 = a – b
}
q1 = p1 * c q4 = p3 * c
p– > next – m ;
} p1 = u * v p4 = u * v
Assuming that m and n point to Valid NULL-terminated q1 = p1 + q1 q5 = p4 + q4
linked lists, invocation of join will
(a) append list m to the end of list n for all inputs. (c) p1 = a – b (d) p1 = a – b
(b) either cause a null pointer dereference or append list q1 = p2 * c q1 = p * c
m to the end of list n. p3 = u * v p2 = u * v
(c) cause a null pointer dereference for all inputs. q2 = p4 + q3 q2 = P + q
(d) append list n to the end of list m for all inputs.
9. When two 8-bit numbers A7 ... A0 and B7 ... B0 in 2’s 13. Consider the following C code:
complement representation (with A0 and B 0 as the least #include < stdio.h >
significant bits) are added using a ripple-carry adder, the
int *assignval (int *x, int val) {
sum bits obtained are S7 ... S0 and the carry bits are C7 ... C0
*x = val;
. An overflow is said to have occurred if
(a) the carry bit C7 is 1 return x;
(b) all the carry bits ( C7, ..., C0) are 1 }
void main () {
(c) ( A7 . B7 . S7 + A7 . B7 . S7) is 1 int *x = malloc (sizeof (int) ) ;
(d) ( A0 . B0 . S0 + A0 . B0 . S0) is l if (NULL == x) return;
x = assignval(x,0);
SOLVED PAPER - 2017 2017-3
(i) a naive pipeline implementation (NP) with 5 stages and void main() {
(ii) an efficient pipeline (EP) where the OF stage is divided static int x = 0;
into stages OF1 and OF2 with execution times of 12 ns int. i = 5;
and 8 ns respectively. for (; i > 0; i --) {
The speedup (correct to two decimal places) achieved by x = x + total (i);
EP over NP in executing 20 independent instructions with }
no hazards is _______ . printf (“%d\n”, x) ;
51. Consider a 2-way set associative cache with 256 blocks and }
uses LRU replacement. Initially the cache is empty. Conflict
misses are those misses which occur due to contention of GENERAL APTITUDE
multiple blocks for the same cache set. Compulsory’ misses QUESTION 56 TO 65 CARRY ONE MARKS EACH
occur due to first time access to the block. The following
sequence of accesses to memory blocks 56. After Rajendra Chola returned from his voyage to Indonesia,
(0, 128, 256, 128, 0, 128 ,256, 128, 1, 129, 257, 129, 1, 129, 257, he _______ to visit the temple in Thanjavur.
129) is repeated 10 times. The number of conflict misses (a) was wishing (b) is wishing
experienced by the cache is ________. (c) wished (d) had wished
52. Consider the expression (a – 1) * (((b + c) / 3) + d )), Let X be 57. Research in the workplace reveals that people work for many
the minimum number of registers required by an optimal reasons ________.
code generation (without any register spill) algorithm tor a (a) money beside (b) beside money
load/store architecture, in which (i) only load and store (c) money besides (d) besides money
instructions can have memory operands and (ii) arithmetic 58. Rahul, Murali, Srinivas and Arul are seated around a square
instructions can have only register or immediate operands. table. Rahul is sitting to the left of Murali. Srinivas is sitting
The value of X is______. to the right of Arul. Which of the following pairs are seated
53. Consider the following C program. opposite each other?
#include <stdio.h>
(a) Rahul and Murali
#include <string.h>
(b) Srinivas and Arul
void print length (char *s, char *t) { (c) Srinivas and Murali
unsigned int c = 0; (d) Srinivas and Rahul
int len = ((strlen (s) – strlen (t) ) > c) ? strlen (s) : strlen (t) ; 59. Find the smallest number y such that y × 162 is a perfect cube.
printf (“%d\n’’, len); (a) 24 (b) 27
} (c) 32 (d) 36
void main ( ) { 60. The probability that a k-digit number does NOT contain the
char *x = “abc”; digits 0, 5, or 9 is
char *y = “defgh”; (a) 0.3 k (b) 0.6 k
printlength (x,y) ; (c) 0.7 k (d) 0.9 k
} 61. “The hold of the nationalist imagination on our colonial past
Recall that strlen is defined in string.h as returning a value is such that anything inadequately or improperly nationalist
of type size_t, which is an unsigned int. The output of the
is just not history.”
program is ________.
Which of the following statements best reflects the author’s
54. A cache memory unit with capacity of N words and block
size of B words is to be designed. If it is designed as a direct opinion?
mapped cache, the length of the TAG field is 10 bits. If the (a) Nationalists are highly imaginative.
cache unit is now designed as a 16-way set-associative (b) History is viewed through the filter of nationalism.
cache, the length of the TAG field is______ bits. (c) Our colonial past never happened.
55. The output of executing the following C program is _______. (d) Nationalism has to be both adequately and properly
#include <stdio.h> imagined.
int total (int v) { 62. Six people are seated around a circular table. There are at
static int. count = 0; least two men and two women. There are at least three right-
while (v) { handed persons, Every woman has a left-handed person to
count + = v&l ; her immediate right. None of the women are right-handed.
v >>= 1; The number of women at the table is
} (a) 2 (b) 3
return count;
(c) 4 (d) Cannot be determined
}
EBD_7203
2017 -8 SOLVED PAPER - 2017
65. A contour line joins locations having the same height above
( x + y )- | x - y |
63. The expression is equal to the mean sea level. The following is a contour plot of a
2 geographical region. Contour lines are shown at 25 m
(a) the maximum of x and y intervals in this plot. If in a flood, the water level rises to 525
(b) the minimum of x and y m. which of the villages P, Q, R, S, T get submerged?
(c) l
(d) none of the above
64. Arun, Gulab, Neel and Shweta must choose one shirt each 425 Q
from a pile of four shirts coloured red, pink, blue and white R
450 550
respectively. Arun dislikes the colour red and Shweta
dislikes the colour white, Gulab and Neel like all the colours.
In how many different ways can they choose the shirts so
that no one has a shirt with a colour he or she dislikes? P
(a) 21 (b) 18 550
(c) 16 (d) 14 T
500
450
500 S
(a) P, Q (b) P, Q, T
(c) R, S, T (d) Q, R, S
SOLVED PAPER - 2017 2017-9
1. (d) By the rule of contrapositive. 3. (c) Since the scalars (Ci) are not all zero. Such that,
The given statement (Øp) Þ (Øq) is logically equivalent to Sci ai = 0, where the column vectors ai for (i = 1, 2, .....
q Þ p, and (Øq) Ú p, because n) are linearly dependent in Rn. Hence rank (A) < n.
The equation Ax = b become according to given
\ ( Ø p ) Þ (Ø q ) Û q Þ p
n
\ q Þ p Û (Øq) Ú p statement, A = [a1, ...... an], b = åa .
i =1
i
By taking
L.H.S. :-
é X1 ù
q Þ p Û ( q '+ p ) êX ú
ê 2ú
Now, R.H.S.:- [a1 , a2 , a3 ......an ] ê X 3 ú = a1 + a2 + a3 + ....an
ê ú
(Øq) Ú p Û (q + p) ê M ú
êë X n úû
So, q Þ p Û (Øq) Ú p
Hence, clearly the given statement is same as (ii) and n
(iii), only. So option (d) is correct. if ([A] = 0) and b = åa
i =1
i
3. In option (c), the dangling pointer is nothing but the 15. (b) For security violations, sender S can launch a birthday
pointer which is pointing to non-existing memory. attack to replace message (m) with a fraudulent message
(deallocated or deleted memory) which is not happening because he has the signature and he can decrypt the
here, so it is also not correct. signature by his own public key and get’s the hash
4. In option (d), when you are calling malloc second time, value, with that same hash value, he can create another
then new location is assigned to X and previous memory message and can be sent instead of original. Hence
location is lost and now we do not have no reference option (b) is correct.
to that location, resulting in memory leak, so option (d) 16. (a) The given functional dependencies are for the relational
is correct. schema R (V, W, X, Y, Z)
14. (d)
ì V ®W ü
1. ïVW ® X ï
Client (a ) Server (b ) ï ï
Client sent connection Server awaiting connection í ý
ï Y ® VX ï
request 1 reuest 1. ïî Y ® Z ïþ
Client awaiting Received connection request 1.
acknowledgement.
Where as, W is extraneous from (VW ® X )
Received Sent Acknowledgement 1.
acknowledgement 1.
Received connection Sent connection request 2. 2. ìV ® W ü
request 2. Awaiting acknowledgement 2. ïV ® X ï
ïï ïï
Sent acknowledgement 2. Received acknowledgement 2. íY ® V ý
ïY ® X ï
Open connection is The connection is open and ï ï
established, then data data moves in both direction. îï Y ® Z þï
moves in both direction.
FINAL WAIT-1 CLOSE WAIT- 1 Where, (Y ® X ) is redundant functional dependence.
Sent close request a . Received close request a .
3. ìV ® W ü
Awaiting
ïV ® X ï
acknowledgement a. ï ï
Received Sent Acknowledgement a . í ý
ï Y ® V ï
Acknowledgement a . When finishing sending data. ïî Y ® Z ïþ
FINAL WAIT-2 CLOSE WAIT-2
Received close request (b). Send close request (b) It is the minimal set that cover all the given functional
Awaiting acknowledgement b . dependencies and it is irreducible equivalent to this
Sent acknowledgement (b), Allowing time is not matched given F.D.
allowing time for delivery so, its listening. 17. (c) Follow (Q) ?
of acknowledgement (b). Follow (Q) is First (R) Hence First (R) = {W, E}.
We add ‘W’ in Follow (Q) and for Î.
Still awaiting for
Closed We calculate :
acknowledgement (b).
First (S) = {y}
A. "fictional" state, so Awaiting connection request.
So, follow (Q) = First (R S)
there is no connection
= {{W} – Î} È First (S)
Follow (Q) = {W, y} (\ First (S ) = { y})
Client Server
FIN Segmen Hence option (c) is correct.
(FIN-WAIT-1 STATE) t
18. (d) Threads of a process can share both heep and global
Close variables because these are shared by every thread of
wait a process. Generally every thread of a process have
state their own PC and Stack. So option (d) is correct.
(FIN-WAIT-2 STATE) ACK
19. (0) Given X is a Gaussian random variable. It is same as
normal random variable. So the distribution of X is N
(0, s2), for X, Median = Mode = Mean = 0.
EBD_7203
2017 -12 SOLVED PAPER - 2017
For Y = Max (X, 0)
ì0 if ( -¥ < x £ 0) ü EC
=í ý 23. (2.6) S.No. Dept Name Number
î x if (0 < x < ¥, is a random variable)þ
1 AA 4
So, Median being positional average will not be affected
2 AB 3
and will remain at 0.
Since now half will be at 0 and half will be positive. 3 AC 3
So, Median (Y) = 0. 4 AD 2
20. (18) A tree with 10 vertices has 9 edges. 5 AE 1
Such that, n = 10, e = (n – 1) = 10 – 1 = 9 Total — 13
then, Sdegree (Vi) = 2 [edges (E)] = 2 × 9 = 18.
21. (1) The given K’MAP :-
13
Result of outer query or Avg (NUM) = = 2.6.
ba 5
dc 00 01 11 10 24. (3)
00 × ×
P1 P2 P3 P4 P1 P3
01 1 ×
0 3 5 6 8 12 17
F (a, b, c, d) = ac = ac = a + c Then,
(\ x + y = x × y ) P1 P2 P4 P1 P3
0 3 6 8 12 17
c
P2 P4 P1 P3
(a + c)
a So, turn around time is for P1,P2,P3,P4 are:
(So only one NoR Gate is required.) P1 Þ (12 - 0), P2 Þ (6 - 3),
22. (4) The given regular expression is (a + b)* b (a + b).
In this all string whose second last bit is ‘b’. P3 Þ (17 - 5), P4 Þ (8 - 6)
So, the minimal NFA is
Þ P1 = 12, P2 = 3, P3 = 12, P4 = 2
a, b
As we know that
b a, b
A B C Waiting time = Turn around time - Burst time
So, waiting time for P1,P2,P3,P4 are:
It can be described as “All string over {a, b} ending
with ‘ba’ or ‘bb’. Then the minimal (DFA) accepting P1 Þ (12 - 7) = 5
(L), find by converting it into minimal DFA by subset P2 Þ (3 - 3) = 0
construction Algorithm.
P3 Þ (12 - 5) = 7
a b P4 Þ (2 - 2) = 0
b Hence, avg. waiting time
A AB ABC
b P1 + P2 + P3 + P4 5 + 7
= = = 3.0
4 4
a b a a 25. (0.05) As given that, an application incurs 1.4 memory
accesses per instruction.
So, the Number of memory Accesses in 1000 instructions
AC is
= 1.4 × 1000 = 1400.
Hence, it is a minimal DFA with 4 states.
SOLVED PAPER - 2017 2017-13
Number of Misses in L2 cache one lock and can wait for release of another lock, which
arises deadlock.
Miss per instructions
= (d) X = 1, Y = 1
Number of Memory Accesses
If there is one thread and one locks, then one thread
can hold one lock, then there will be no deadlock
7 Miss (Per 1000 instruction)
= = 0.005 situation.
1400 (Memory Accesses)
So, option (c) is correct.
Miss in L2 æ X 7 - 2X 5 + 1 ö 1- 2 + 1 æ 0 ö
Miss rate L2 = Miss in L 28. (c) lim ç 3 ÷= = ç ÷ form.
1 X ®1 ç X - 3 X 2 + 2 ÷ 1 - 3 + 2 è0ø
è ø
\ (given, Miss rate of L1 cache is 0.1) Now, by using (L’ Hospital Rule)
0.005
So, L2 = é 7 X 6 - 10 X 4 ù
0.1 Þ lim ê ú
X ®1 3 X 2 - 6 X
ë û
Miss Rate L2 = 0.05.
26. (a) The Graph G is a connected undirected edge-weighted Applying limit (X = 1) then
graph, since all the edge weights are unique, hence the
æ 7 - 10 ö -3
minimum spanning tree of the graph will be unique and Þç ÷= =1
shortest path between the two vertices need not be unique. è 3 - 6 ø -3
For example, consider a rectangle :- So, option (c) is correct.
29. (0) The given expression ( P ® q) ® r be a
(V1) A 1 B(V2 ) contradiction, then the expression
(r ® P) ® q is always true when q is true.
P q r
(V3) C 4 D (V4)
T T F
here there are four vertices V1, V2, V3, V4. F T F
Let take V2 is source and V3 is destination then we find F F F
the shortest path from (V2 )B to C(V 3 ) are two
when q is false then (r ® P) ® q will be false.
(V2 ® V1 ® V3 ) or ( B ® A ® C ) and (V2 ® V3 ) or
Since if (P = 0) is false then option (c) is not correct
(B ® C ) . because when P is false i.e. (P = 0), then q is free to be
Both of weight = ‘3’. true or false.
Hence path is not unique. Hence option (d) is correct.
27. (c) In an multithreaded program P executes with X number 30. (a) Here u and v be two vector given a relation
of threads and Y number of locks for ensuring mutual || u ||= 2 || v ||
exclustion while operating on shared memory location.
So, u is twice as log as v.
Now consider each option.
If the vector 2v has same length as u and hence (u + 2v)
(a) X = 1, Y = 2.
will bisect angle between u and 2v.
If there is one thread and two locks then there is not
Now angle between u and v is same as angle between
situation of deadlock.
u and 2v
(b) X = 2, Y = 1.
Since 2 is the only a scalar.
Similarly if there is only 1 lock and 2 thread, then there
So, the required vector is (u + 2v).
will be no deadlock situation.
Hence, (w = u + 2v), compare with (w = u + av)
(c) X = 2, Y = 2
So, (a = 2)
If there is 2 thread and 2 locks then the Deadlock
Hence option (a) is correct.
situation can arise because both threads can holds
EBD_7203
2017 -14 SOLVED PAPER - 2017
31. (b) p ( A) < n Þ| A |= 0 Þ one eigen value must be So, the message 01011011 is transmitted as
01011011101.
Î [-5, 5] So, option (c) is correct.
\ (I) is true. 33. (b) As given circuit diagram :
é 5 0 0ù
Let A = êê 0 -5 0úú
T Q1 D Q0
êë 0 0 0úû
Flip Flip
flop flop
3 3
= åå A
i =1 j =1
2
ij = 50 Clock
35. (c) In the given program, when the function fun 1( ) is 39. (a) A Tweing Machine (M) is a recursive if F it halts for
calling function fun 2 ( ), after printing value and after every input string either in accept or reject state. Here
returning from fun 2 ( ), it prints the same value. a computable function is defined in simple way such
In the function fun 2 ( ) also the same thing happens so
as { X # f ( X ) | X Î A*}
by looking options we can find the correct sequence
of the output after executing fun1(5), (n = 5), fun1(n), So, f is computable if and only if Lf is recursive.
print Þ 5. So, option (a) is correct.
fun2 (n – 2) Þ fun2 (3), Print Þ 3. 40. (b) Statement 1 : It is “True” because there can be a case
Similarly all steps execute then, we get the correct. when page selected to be replaced is by FIFO policy
Sequence is 5 3 4 2 3 1 2 2 1 3 2 4 3 5 because Random page replacement algorithm can
Hence, option (c) is correct. behave like FIFO.
36. (c) In the given program, invocation of foo (3) and bar (3), Hence it can suffer from Belady’s anamaly.
in which, foo (3) turn calls foo (3). This goes on infinite Statement 2 : It is false because LRU, page replacement
number of times which causes memory overflow and algorithm does not suffers from Beledy’s Anomaly.
causes abnormal termination. So, option (b) is correct.
bar (3) ® bar (2) ® bar (1) ® bar (0) and (return 0) 41. (d) Consider the each option.
from here onwards bar (1) will bar (0) and bar (0) will (i) The results empname who does not belongs to any
return 0 to bar (1) and this goes on forever without departments.
causing memory overflow but it goes on infinite loop
(ii) The results empname who does not belongs to some
execution.
departments.
Hence, option (c) is correct.
(iii) The results empname who belongs to same
37. (b) The context free grammar given over alphabets
departments.
S = {a, b, c}, with S and T are nonterminals.
All the given queries generate finite number of tuple
Given, G1 : S ® aSb | T , T ® cT | Î hence all are safe query.
G2 : S ® bSa | T , T ® cT | Î Hence, option (d) is correct.
42. (a) The given two transaction TS (T1) and TS (T2), in which
Lets L(G1) is the language for Grammar (G1) and L(G2)
T1 holds lock on resource R, T2 requires conflict lock
is the language for Grammar (G2).
on same resource R and T2 wait for graph.
where L(G1 ) = {a n cm b n | m, n ³ 0} If (TS(T2) < TS (T1)).
Then T1 killed.
L(G2 ) = {bn cm a n | m, n ³ 0}
(If restart with same TS value).
then L(G1 ) Ç L(G2 ) = {a n c m bn } Ç {bn c m a n } Else T2 waits.
This process shows avoids both deadlock and
= {c m | m ³ 0} = C * starvation because the transaction, who got killed will
Since the only common strings will be those strings be starting with same time stamps and both are not
with only ‘C’, so the intersection is not finite but regular. waiting for each other.
38. (a) The given language over Alphabets S = (a, b, c) and Hence, option (a) is correct.
the given language are :- 43. (1024) The number of control Paths is depends on number of
n n m if statement that is 2n, where, n is the number. of if
L1 = {a b c | n, m ³ 0} is a CFL
statements
L2 = {a m bn c n | n, m ³ 0} is also a CFL For (2 “if statements”) 22 = 4 control flow Paths are
then union of two CFL is always CFL, possible:
L1 È L2 = {a n bm c k | (n = m) or (m = k ), n, m ³ 0} is e1
a context free language.
Intersection of two CFL is may or may not be a context
e2 e3
free language. (1) (2)
if e4 if e4
L1 Ç L2 = {a n bm c k | (n = m) or (m = k ), n, m ³ 0} or
48. (5) To find out the smallest index i such that A[i] is 1 by
Execution time (TNP) = (k + n – 1) tP1
probing the minimum number of location in A. Assume
i be the index of first element and j be the index of last = (5 + 20 – 1) 22 n sec.
element. TNP = 528 n sec.
By using the binary search algorithm with some Now, for efficient pipeline (TEP), the number. of stages
changes. (k = 6), n = 20, t P2 = ?
Now,
tP2 = Max (Stage delay + Buffer delay)
é low+high ù
Find middle element of Array = A ê ú = (12 nS + 2 nS) = 14 ns.
ë 2 û
Assuming ‘A’ is an array of 31 elements with ‘1’ and if So, TEP = (k + n – 1) t P2
it is ‘1’, we check the left part recursively and if it is ‘0’, = (6 + 20 – 1) * 14
we check the right part of the array recursively. = 350 n sec.
Which take log2(31) comparisons in the worst case, so
the total worst case probes is (TNP ) 528
Speed up (S) = = = 1.508.
Þ Ceil (log231) = 5 (TEP ) 350
(Q Ceil means compute fast log base 2 ceiling)
5 probes performed by an optimal algorithm. 51. (76) A compulsory Miss is not considered a conflict miss if
49. (–16) In program storage, the block is accessed for the first time.
Assuming the starting address (EA) is 0000, then Number of lines = 256
Add R1 ¬¾
¾ ( R1 + R2 )
Block ID Type Content
Div. R1 ¬¾
¾ R1 / 3
0 Co n flict M is s 128, 0
128 h it 0, 128 Load R2 ¬¾
¾d
256 Co n flict M is s 128, 256
128 h it 256, 128 Add R1 ¬¾
¾ R1 + R2
0 Co n flict M is s 128, 0
Load R2 ¬¾
¾a
128 h it 0, 128
256 Co n flict M is s 128, 256 Sub. R2 ¬¾
¾ R2 - 1
128 h it 256, 128
Mul. R1 ¬¾
¾ R1 * R2
The number of conflict Miss in set 1 = 4 Hence, only two registers are required.
Similarly for {1, 129, 257, 129, 1, 129, 257, 129}. 53. (3) In the given program.
The number of conflict miss in set 2 = 4. X is pointer of string “abc” which length is 3.
Total number of conflict misses in both sets = (4 + 4) = 8. Strlen (S) = 3
Note that content of each set is same before and after where (S) is pointer that pointed to X.
2nd Iteration, therefore each of the remaining iterations Y is pointer of string “defgh”, which length is 5.
will also have 8 conflict misses. Strlen (t) = 5.
Total 9 iteration take to complete the 2nd time access, where t is pointer that pointed to y, value of C is 0.
so total conflict Miss in 2nd time access is = 9 × 8 = 72 Now consider the statement :
Then, total conflict miss Intlen = [(Strlen (S) – Strlen (t) > 0)? Strlen (S) : Strlen (t)]
= (Ist time Access conflict Miss = [(3 – 5)] > 0
+ 2nd time Access conflict miss = [–2] > 0
= 4 + 72 = 76). It is not true but, since it is given in question
ææ b + c ö ö [Strlen (S) – Strlen (t)] will give unsigned value.
52. (2) The given expression is (a - 1) * ç ç ÷+d ÷ So, [Strlen (S) – Strlen (t)] = |–2| = 2.
èè 3 ø ø
Therefore
Þ 2 > 0 (it is true) : Strlen (S) : Strlen (t);
Since (2 > 0) will evaluate true so it will give output as
* 2 Strlen (S) = 3. Hence ‘3’ will be printed.
54. (14) In Direct Mapped :
– 1 + 1
Direct Mapped
10 bits 16 bits
a 1 1 1 d 0 TAG LINE - NUMBER OFFSET
1 0
éNù
+ 1 3 No. of line in direct mapped cache = êBú bits
ë û
0
éN ù
b c For no, of lines = log ê ú
ëBû
1 0
In Set Associative :
if (V = 2)
N
No. of sets in set associative cache = bits Count = 1 + 2 & 1 = 1 + 0 = 1
16 B
if (V = 1), count = (1 +(1 & 1)) = 1 + 1
æ N ö Count = (1 + 1) = 2
For no. of sets = log ç ÷ Return (2);
è 16 B ø
Then, X = 2 + total (4):
and offset for both mapping is = log (B).
Ccunt = (2 + (4 & 1)) = 2 + 0 = 2
Compare both Direct and Set Associative Mapped :
(\ 2 is static)
æ Nö æ N ö If (V = 2)
TAG1 + log ç ÷ + log( B) = TAG2 + log ç + log( B)
è Bø è 16 B ÷ø Count = (2 + (2 & 1 )) = 2 + 0 = 2
By cancelling the same terms if (v = 1)
As given that Count = ( 2 + (1 & 1)) = 3
TAG1 = 10 bits for Direct Mapping. Count = 3
TAG2 let say X bits.
return (3)
æ Nö æ N ö X = ((2 + 3) + total (3);)
Then, 10 + log ç ÷ = X + log ç
è Bø è 16 B ÷ø
(Q2 is static)
By taking exponentation both side w.r.t 2. X = (5 + total (3);)
æ éN ùö æ æ N öö ( Q 5 is static)
Ùç 10 + log 2 ê ú ÷ Ù ç X + log ç ÷÷
2 è ë B ûø
= 2 è è 16 B ø ø So, count = (3 + (3 & 1)) = 3 + 1 = 4
If (V = 2)
æNö æ N ö Count = (4 + (2 & 1)) = 4 + 0 = 4
(2Ù10 )* ç ÷ = (2Ù X )* ç ÷
èBø è 16B ø If (V = 1)
Count = (4 + (1 & 1)) = 4 + 1 = 5
æ1ö
(2Ù10 ) = (2Ù X ) ç ÷ Count = 5
è 16 ø
return (5)
^10 ^X æ 1 ö
(2 ) = (2 ) ç ^4 ÷ X = (5 + 5) + total (2);
è2 ø
(Q5 is static)
(2Ù14 ) = (2Ù X ) X = (10 + total (2);)
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. The subject specific GATE Paper section consists of 55 questions. The General Aptitude section consists of 10 questions.
3. 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.
4. 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
2R
= , then the constants R and S are respectively
π R Q P
2 16 2
(a) and (b) and 0 (a) MNOPQR (b) NQMPOR
π π π (c) QMNROP (d) POQNMR
4 4 16 16. Identify the language generated by the following grammar,
(c) and 0 (d) and where S is the start variable.
π π π
SOLVED PAPER - 2017 2017-23
r=r–y; L(R) ?
q=q+I; II. Given a context-free grammar G. is L(G) = f ?
} III. Given a context-free grammar G. is L(G) =S*for some
Which of the following conditions on the variables x, y, alphabet S ?
q and r before the execution of the fragment will ensure IV. Given a Turing machine M and a string w, is w Î
that the loop terminates in a state satisfying the condition L(M) ?
(a) I and IV only (b) II and III only
x == (y * q + r) ?
(c) II, III and IV only (d) III and IV only
(a) (q == r) && (r == 0) 42. The next state table of a 2-bit saturating up-counter is
(b) (x > 0) && (r == x) && (y > 0) given below.
(c) (q == 0) && (r == x)&& (y > 0)
(d) (q == 0) && {y > 0)
Q1 Q0 Q1+ Q0+
38. Consider the following C function.
int. fun (int n) { 0 0 0 1
int i, j ; 0 1 1 0
for (i = 1; i <= n; i++) { 1 0 1 1
for (j = 1; j < n; j += i) {
printf{“ %d %d”, i, j}; 1 1 1 1
}
} The counter is built as a synchronous sequential circuit
} using T flip-flops. The expressions for T1 and T0 are
Time complexity of fun in terms of Q notation is (a) T1 = Q1Q0, T0 = Q1 Q0
(a) Q (n n ) (b) Q (n2)
(b) T1 = Q1 Q0 , T0 = Q1 + Q0
(c) Q (n log n) (d) Q (n2 log n)
39. Let d denote the transition function and d denote the (c) T1 = Q1 + Q0, T0 = Q1 + Q0
extended transition function of the Î-NFA whose transition
table is given below: (d) T1 = Q1 Q0 , T0 = Q1 + Q0
43. Consider the following snippet of a C program. Assume
δ Î a b that swap (&x, &y) exchanges the contents of x and y.
® q 0 {q 2 } {q1} {q0 } int main( ) {
q1 {q 2 } {q 2 } {q3} int array [ ] = {3, 5, 1, 4, 6, 2};
int done = 0;
q2 {q 0 } f f int i ;
q3 f f {q2 }
while {done == 0) {
Then d (q2, aba) is done = 1;
(a) f (b) {q0, q1, q3} for (i=0; i <=4 ; i + +) {
(c) {q0, q1, q2} (d) {q0, q2, q3,} if (array[i] < array[i+1]) {
40. Consider the following languages. swap (&array [i] , &array [i+1]);
L1 = {ap | p is a prime number} done = 0;
L2 = {anbmc2m | n ³ 0, m ³ 0} }
L3 = {anbnc2n | n ³ 0} }
L4 = {an bn | n ³ 1} for (i = 5; i>=l ; i – –) {
Which of the following are CORRECT? if (array [i] > array[i – 1]) {
I. L1 is context-free but not regular. swap (&array [i] , &array [i – 1]);
II. L2 is not context-free. done = 0 ;
III. L3 is not context-free but recursive. }
IV. L4 is deterministic context-free. }
(a) I, II and IV only (b) II and III only }
(c) I and IV only (d) III and IV only printf (“%d”, array[3] ) ;
41. Let L(R) be the language represented by regular expression }
R. Let L(G ) be the language generated by a context free The output of the program is _______.
grammar G. Let L(M) be the language accepted by a 44. Two transactions T1 and T2 are given as
Turing machine M. Which of the following decision T1: r1 (X) w1(X)r1(Y)w1(Y)
problems are undecidable? T2: r2 (Y) w2(Y)r2(Z) w2(Z)
I. Given a regular expression R and a string w, is w Î where ri(V) denotes a read operation by transaction Ti on
EBD_7203
2017 -26 SOLVED PAPER - 2017
a variable V and wi(V) denotes a write operation by Character Probability
transaction Ti on a variable V. The total number of conflict P 0.22
serializable schedules that can be formed by T1 and T2 is Q 0.34
__________. R 0.17
45. The read access times and the hit ratios for different S 0.19
caches in a memory hierarchy are as given below. T 0.08
Cache Read access time Hit ratio Total 1.00
(in nanoseconds) If a message of 100 characters over X is encoded using
I-cache 2 0.8 Huffman coding, then the expected length of the encoded
D-cache 2 0.9 message in bits is ________.
L2-cache 8 0.9 51. Consider the set of processes with arrival time (in
The read access time of main memory is 90 nanoseconds. milliseconds). CPU burst time (in milliseconds) and priority
Assume that the caches use the referred- word-first read (0 is the highest priority) shown below. None of the
policy and the write back policy. Assume that all the processes have I/O burst time.
caches are direct mapped caches. Assume that the dirty
Process Arrival Time Burst Time Priority
bit is always 0 for all the blocks in the caches. In execution
P1 0 11 2
of a program. 60% of memory reads are for instruction
P2 5 28 0
fetch and 40% are for memory operand fetch. The average
P3 12 2 3
read access time in nanoseconds (up to 2 decimal places)
is ________. P4 2 10 1
46. Consider the following database table named top_scorer. P5 9 16 4
Player Country Goals The average waiting time (in milliseconds) of all the
Klose Germany 16 processes using preemptive priority scheduling algorithm
Ronaldo Brazil 15 is ________.
G Muller Gemany 14 52. If the characteristic polynomial of a 3 × 3 matrix M over
Fontaine France 13 R, (the set of real numbers) is l3 – 4 l2 + al + 30, aÎR,
Pele Brazil 12 and one eigenvalue of M is 2. then the largest among the
Klinsmann Germany 11 absolute values of the eigenvalues of M is ________.
Kocsis Hungary 11 53. Consider a machine with a byte addressable main memory
Batistuta Argentina 10 of 232 bytes divided into blocks of size 32 bytes. Assume
Cubillas Peru 10 that a direct mapped cache having 512 cache lines is used
Lato Poland 10 with this machine. The size of the tag field in bits is
Lineker England 10 ________.
T Miller Germany 10 54. Consider the following C Program.
Rahn Germany 10 #include<stdio.h>
Consider the following SQL query: int. main ( ) {
SELECT ta.player FROM top_scorer AS ta int m = 10 ;
WHERE ta.goals >ALL (SELECT tb.goals int n, n1 ;
FROM top_scorer AS tb n = ++m;
WHERE tb.country = ‘Spain’) n1 = m++;
AND ta.goals >ANY (SELECT tc.goals n – –;
FROM top_scorer AS tc – – n1;
WHERE tc.country = ‘Germany’) n – = n1;
The number of tuples returned by the above SQL query printf (“%d”, n) ;
is ________. return 0;
47. If the ordinary generating function of a sequence {an }µ
n =0
}
The output of the program is _________.
1+z 55. Consider the following C Program.
is , then (a3 – a0) is equal to ________.
(1–z)3 #include<stdio.h>
48. If a random variable X’ has a Poisson distribution with #include<string.h>
mean 5. then the expectation E[(X + 2)2] equals _______. int main ( ) {
49. In a B+ tree, if the search-key value is 8 bytes long, the char* c = “GATECSIT2017” ;
block size is 512 bytes and the block pointer size is 2 char* p = c ;
bytes, then the maximum order of the B+ tree is ______. printf (“%d”, (int) strlen (c+2[p]–6[p]–1));
50. A message is made up entirely of characters from the set return 0 ;
X = {P,Q,R,S,T}. The table of probabilities for each of the }
characters is shown below: The output of the program is ________.
SOLVED PAPER - 2017 2017-27
GENERAL APITITUDE 62. There are three boxes. One contains apples, another
contains oranges and the last one contains both apples
QUESTION 56 TO 60 CARRY ONE MARKS EACH and oranges. All three are known to be incorrectly labelled.
If you are permitted to open just one box and then pull
out and inspect only one fruit, which box would you open
56. Choose the option with words that are not synonyms. to determine the contents of all three boxes?
(a) aversion, dislike (b) luminous, radiant (a) The box labelled ‘Apples’
(c) plunder, loot (d) yielding, resistant (b) The box labelled ‘Apples and Oranges’
57. Saturn is __________to be seen on a clear night with the (c) The box labelled ‘Oranges’
naked eye. (d) Cannot be determined
(a) enough bright (b) bright enough
63. X is a 30 digit number starting with the digit 4 followed
(c) as enough bright (d) bright as enough by the digit 7. Then the number X3 will have
58. There are five buildings called V, W, X, Y and Z in a row
(a) 90 digits (b) 91 digits
(not necessarily in that order). V is to the West of W. Z
(c) 92 digits (d) 93 digits
is to the East of X and the West of V. W is to the West
64. The number of roots of ex + 0.5x2 – 2 = 0 in the range
of Y. Which is the building in the middle?
[–5, 5] is
(a) V (b) W
(a) 0 (b) 1
(c) X (d) Y
59. A test has twenty questions worth 100 marks in total. (c) 2 (d) 3
There are two types of questions. Multiple choice 65. An air pressure contour line joins locations in a region
questions are worth 3 marks each and essay questions are having the same atmospheric pressure. The following is
worth 11 marks each. How many multiple choice questions an air pressure contour plot of a geographical region.
Contour lines are shown at 0.05 bar intervals in this plot.
does the exam have?
(a) 12 (b) 15 R
(c) 18 (d) 19
0.65 0.9
60. There are 3 red socks, 4 green socks and 3 blue socks,
0.7 0.9
you choose 2 socks. The probability that they are of the 5
0.95
S
same colour is
(a) 1/5 (b) 7/30
(c) 1/4 (d) 4/15 P 0.9
QUESTION 61 TO 65 CARRY TWO MARKS EACH
0.8
61. “We lived in a culture that denied any merit to literary Q
0.8 0.75
works, considering them important only when they were
handmaidens to something seemingly more urgent - namely
ideology. This was a country where all gestures, even the 0 1 2 km
most private, were interpreted in political terms.” If the possibility of a thunderstorm is given by how fast
The author’s belief that ideology is not as important as air pressure rises or drops over a region, which of the
literature is revealed by the word: following regions is most likely to have a thunderstorm?
(a) ‘culture’ (b) ‘seemingly’ (a) P (b) Q
(c) ‘urgent’ (d) ‘political’ (c) R (d) S
EBD_7203
2017 -28 SOLVED PAPER - 2017
(
So, X = 1011 1100 0101 1001
11 12 10 9
) 3. L1–R is context-free because if context-free language
is intersection to the complement of regular language
then it is always context-free. L1 - R = L1 Ç R1 , so it is
= 001 011 110 001 011 001
correct.
= 1 3 6 2 5 1
4. L1 Ç L2 is not context-free because context-free
= (1 3 6 2 5 1)8
languages are not closed under complement operations.
Hence, option (d) is correct. So it is incorrect.
2. (a) 1. Static char var; : Initialization of a variable located 5. (c) According to the complier phase. Shown in figure
in data section of memory because var is defined below.
as character variable whose associated storage
The lexical analysis Phase Processes the character
class is static.
strem and generates tokens stream, these tokens are
2. m = m alloc (10); m = Null; A lost memory which processed by syntex analysis analyzer and generate
cannot be freed because free (m) is missed in code the syntex tree. these syntex tree is processed by the
due to 10 contiguous bytes of memory is allocated semantic analyzer, and generate the intermediate
is address of first byte is stored in ‘m’ and later it representation such as (3-Address code) is used for
is updated with NULL. Now we lost the address code generation process.
of first bytes of that chunk of memory completely, (Character stream)
so we can’t free that space as we need the address
of first byte to free it.
3. Char * Ptr [10]; : Sequence of memory locations to Lexical analyzer
store addresses because ptr is an array of 10 Token stream
pointers pointing to character variables.
Syntex analyzer
4. Register int var1; : Request to allocate a CPU
register to store data because the complier to store Syntex tree
the var 1 “value” in CPU Register. Semantic analyzer
Hence, option (d) is correct. Intermediate representation
3. (c) 1. Towers of Hanoi with n disks : 2T(n – 1) + 1 Þ Q (2n)
Code generation
2. Binary search given n sorted numbers :
6. (a) Bottom up Parsers in decreasing order of their power :
æ nö
= T ç ÷ + 1 = Q (log n) CLR >> LALR ³ SLR ³ LR , then
è 2ø
1. Connonical (CLR) is the most powerful Parsers among
3. Heap sort given n numbers at the worst case : all the LR(k) Parsers or SLR. So, it is correct.
æ nö 2. SLR is more powerful than LALR is incorrect.
= 2T ç ÷ + n = Q (n log n)
è 2ø 3. SLR is more powerful than canonical LR is incorrect.
So, option (a) is correct.
4. Addition of two n × n matrices :
7. (b) The thread is a light weight process and all the threads
æ nö in a process has share address space but other entities
= 4T ç ÷ + 1 = Q (n2 )
è 2ø like, stack, PC, registers are not shared and every thread
will have its own.
Hence option (c) is correct.
So, option (b) is correct.
4. (b)
8. (d) Contiguous allocation suffer from external fragmentation.
1. L1ÈL2 is context-free because the union of two context But linked and indexed allocations are non-contigous,
free language is always a context free or CFL are closed so they will not suffer from external fragmentation.
under union operation . So, it is correct. Hence, option (d) is correct.
SOLVED PAPER - 2017 2017-29
20. (9) A record route option is used to record the internet then, 2( E ) ³ S degree of vertices
routers that handles the datagram. It can list up to nine
router addresses. It can be used for debugging and (\ According to undirected graph)
management purpose. 2( E ) ³ 3n
In IPv4, options and padding 40 bytes are allotted,
maximum nine routers addresses are allowed. 2( E )
n£
Each IPv4 address is 32 bits or 4 bytes. 3
So, Þ 4 × 9 = 36 bytes. 2 ´ 25
Extra byte are used for the option. n£
3
Hence, the record route (RR) option field of an IPv4
header is (9). n £ 16.66
So, n is at Most 16.
Hence, 9 is correct answer.
Hence 16 is correct answer.
21. (0) In the given Hasse Diagram :-
e 24. (8) Given Quadratic equation
X2 – 13X + 36 = 0 with coefficients in a base 'b'.
c
In base 'b', 13 = (1´ b1 ) + (3 ´ b0 ) = (b + 3)
d 36 = (3 ´ b1 ) + (6 ´ b0 ) = (3b + 6)
b
So equation become
a X 2 - (b + 3) X + (3b + 6) = 0
The diagram is already a littic if for every pair of element Since (X = 5) is a solution
there exist a LUB (Lowest Upper Bound) and GLB
(Greatest Lower Bound). And LUB and GLB exist for (5)2 - (b + 3)5 + (3b + 6) = 0
every two elements taken from {a, b, c, d, e}. So it is
Þ 25 - 5b - 15 + 3b + 6 = 0,
already a lattice.
So, minimum number of ordered Pairs that need to be Þ 2b = 16 (b = 8)
added = 0. Similarly, by putting (X = 6)
Hence, 0 is correct answer. we get
22. (2) As given Matrix (6)2 - (b + 3) *6 + (3b + 6) = 0
é1 1 -1ù é -1 -2 -1ù Þ 36 - 6b - 18 + 3b + 6 = 0
ê ú ê ú
P = ê 2 -3 4 ú and Q = ê 6 12 6 ú
Þ 18 - 3b + 6 = 0
êë 3 -2 3 úû ëê 5 10 6 ûú (3b = 24), (b = 8)
Hence, the value of b is (8).
é0 -1 -2 ù
25. (8) The Minimum possible number of states of deterministic
P + Q = êê8 9 10 úú finite Automation that accepts the regular language.
êë8 8 8 úû As given that,
1 1 = ( w + x) + ( yz) + wx
P( B) = 2 ´ =
12 6
= ( w + wx ) + x + yz ( w + wx = w[1 + x ] = w
The probability that A does not apply for the job given
é Aù = w + x + yz Q [1 + x = 1]
that B does nto apply for the job is P ê B ú then
ë û L.H.S. = R.H.S.
é A ù P[ A Ç B ] 1 - P ( A È B ) So, it is correct.
Pê ú = =
ëBû P[ B ] 1 - P( B) (3) ( wx ( y + xz ) + wx ) y = xy
\ P( A Ç B ) = 1 - P( A È B) Take, L.H.S.Þ ( wx ( y + xz ) + wx ) y
\ P[ B ] = 1 - P[ B] Þ ( wxy + wxxz + wx ) y
\ P ( A È B ) = [ P( A) + P ( B ) - P ( A Ç B )]
Þ ( wxy + wx ) y Q ( xx = 0)
then
Þ ( wxy × y + wxy ) Q ( y × y = y)
é A ù 1 - [ P ( A) + P( B) - P ( A Ç B)]
Pê ú =
ëBû 1 - P ( B) Þ xy ( w + w) (Q ( w + w) = 1)
é1 1 1 ù R.H.S. = xy
1- ê + - ú 2
4 6 12 û 3 4
= ë = = So, L.H .S . ¹ R.H .S .
é 1ù 5 5
1 - So, it is not correct.
êë 6 úû 6
(4) ( w + y )( wxy + wyz ) = wxy + wyz
A 4 Take, L.H.S. Þ (w + y) (wxy + wyz)
P =
B 5 Þ wxy + wyz + wxy + wyz
Þ wxy + wyz
æ 4ö L.H.S. Þ R.H.S., So it is correct.
Hence, ç ÷ is correct answer.
è5ø
Hence, only (c) is incorrect.
SOLVED PAPER - 2017 2017-33
= Õ M
(4, 9, 12, 13, 14) × d (5, 6, 11, 15) From eq. (3) put (L1) value to eq. (4)
1
= 8 + 18 X
yz 00 01 11 10 2X
wx yz yz yz yz
wx æ 1 ö
ç - 18 X ÷ = 8
00 1 1 1 1 è 2 X ø
0 1 3 2
wx × 1 - 36 X 2 = 16 X
0 × 1 Þ x.z
01 4 5 7 6
Þ (x + z)
wx 36 X 2 + 16 X - 1 = 0
0 0 × 0
11
12 13 15 14 Compair to aX 2 + bx + c = 0
wx 1 0 × 1
10 a = 36, b = 16, c = –1
8 9 11 10 Þ w.z
Þ (w + z ) -b ± b 2 - 4ac
('×' represents dont care) =
2a
-16 ± 256 + 4 ´ 36 ´1
Then, the PoS Þ ( x × z ) × ( w × z ) =
2 ´ 36
Þ ( x + z ) × (w + z ) -16 ± 2 4
= = (take +ve value only)
Hence, the option (a) is correct. 72 72
29. (a) As given that :
X = 0.055
The access time L1 = 1 clock cycles
or (Hit time) Then Miss rate L1 = 2X = 2 × 0.055 = 0.111
The access time L2 = 8 clock cycles L2 = X = 0.055
Y ® + FY / Î 2
q= =1
T ® FY 2
F ® ( E ) | id q =1
Hence option (c) is correct. Hence, option (a) is correct.
SOLVED PAPER - 2017 2017-35
8 16 = Q(n log n)
Hence option (c) is correct.
6 9 18 19
39. (c) Converting the table to a state diagram then we get.
2 7 10 17 20 q1
b b
Now, post order is : (Left, Right, Root) a
Post order will be, 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12 q0 a,
q3
Hence option (b) is correct.
37. (c) The given programe is : b
While (r > = y) q2
{
r = r – y; (/*statement 1*/)
q = q + 1; (/* statement 2*/) then, dˆ (q2 , aba) = All states reachable from q2 by aba.
}
If aba is broken as Î, a, Î, Î, b, a. then from q2 it can
Condition given
reach q1 and from there by null transaction to reach
X = (Y*q + r) state q2 as well as q0.
EBD_7203
2017 -36 SOLVED PAPER - 2017
L2 = {a nb m c 2m | n ³ 0, m ³ 0} 3 5 1 4 6 2
0 1 2 3 4 5
L3 = {a nbn c 2n | n ³ 0} , L4 = {a nbn | n ³ 1} .
For first loop : i very from (0 to 4), then the contents of
Now, consider each option:
the Array are :
(i) L1 is context free but not regular is Incorrect because
it is not CFL, it is a CSL (Context sensitive language). i = 0 5 3 1 4 6 2
(ii) L2 is not CFL is also Incorrect because it is CFL. i = 1 5 3 1 4 6 2
(iii) L3 is not context free but recursive is correct because i = 2 5 3 4 1 6 2
L3 is CSL (context sensitive language) and every CSL i = 3 5 3 4 6 1 2
is recursive.
i = 4 5 3 4 6 2 1
(iv) L4 is deterministic context free is correct because L4 is
a proper subset of context free language. For second loop : i very from (5 to 1) then the contents
Hence option (d) is correct. of the Array are :
41. (d) Consider each options :
i = 5 5 3 4 6 2 1
(a) statement is membership problem of regular language
i = 4 5 3 4 6 2 1
and it is decidable for finite state machine and regular
expression. i = 3 5 3 6 4 2 1
(b) statement is emptyness problem of CFL emptyness i = 2 5 6 3 4 2 1
problem is decidable for CFG by checking usefulness i = 1 6 5 3 4 2 1
of start symbol.
Now, since done = 0, then the for loops will execute
(c) statement is a problem of CFL, and it is undecidable again.
problem, we can not check whether L(G) = S* or not
but rather we can check complement of L(G) is f. For first loop : again i is very from 0 to 4, then the
contents of the Array are :
(d) statement is a membership problem of a Turing
Machine and it is undecidable problem for turning i = 0 6 5 3 4 2 1
machine.
i = 1 6 5 3 4 2 1
So, options (c) and (d) are undecidable.
i = 2 6 5 4 3 2 1
Hence option (d) is correct.
i = 3 6 5 4 3 2 1
42. (b) The next state table of a 2-bit saturating up-counter is
i = 4 6 5 4 3 2 1
shown in given table :
SOLVED PAPER - 2017 2017-37
For second loop : Again i is very from (5 to 1) then the 6. r1 ( X )r2 (Y )w1 ( X ) w2 (Y )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can
contents of the array are :
place in 4C2 = (6 ways).
* Total conflict serializable of T1 and T2
i = 5 6 5 4 3 2 1
= (53 + 1) = 54 ways.
i = 4 6 5 4 3 2 1
Hence 54 is correct answer.
i = 3 6 5 4 3 2 1
45. (4.72)As given table is :
i = 2 6 5 4 3 2 1
i = 1 6 5 4 3 2 1 Cache Read access time Hit ratio
L-cache 2 0.8
The value of done is still "zero". Hence the for loop will
execute again. D-cache 2 0.9
First for loop : L2-cache 8 0.9
This time there will be no change by the for loop. Read access time of Main memory is = 90
Then the value of done is '1', hence the loop terminate Hit ratio of Main memory is = 1.0
here, then the final contents of the Array are : So, average read time is :
6 5 4 3 2 1 (Fraction of Instruction fetch * Average Instruction
Fetch time + Frection of Data Fetch * Average Data
Hence, the output of the program array [3] is '3'. Hence fetch time).
answer is 3.
So, First find out the average Instruction fetch time :
44. (54) The given two transactions T1 and T2 are :
= (L1 acess time + L1 miss Rate * L2 access time
T1 : r1 ( X ) w1 ( X )r1 (Y ) w1 (Y ) + L1 miss rate* L2 miss rate * Memory Access time)
= (2 + 0.2 * 8 + 0.2 * 0.1 * 90) = 5.4 ns.
T2 : r2 (Y ) w2 (Y )r2 ( Z ) w2 ( Z )
Average Data fetch Time
The conflict condition RW, WR, WW, because there is
= (L1 access time + L1 miss rate + L2 access time + L1
only 'one' way to have serializable schedule as
miss rate * L2 miss rate * memory access time)
(T1 ® T2 ) because last operation of T1 and first
= (2 + 0.1 * 8 + 0.1 * 0.1 * 90) = 3.7 ns.
operation of T2 conflicts each other. (T1 ® T2 :1) . So, Avg memory access time
r1(X) w1(X) r1(Y) w1(Y) r2(Y) w2(Y) r2(Z) w2(Z). = (0.6 * 5.4 + 0.4 * 3.7) = 4.72 n sec.
Then, we see how many schedules are conflict Hence 4.72 is correct answer.
serializable to (T2 ® T1 ) for this, we writing S as : 46. (7) Consider the database table named top-scorer also
consider the given SQL query is :
S : r2 (Y ) w2 (Y ) r1 (Y ) w1 (Y ) Select ta. Player from to P_Scorer as ta.
r1 ( X ) w1 ( X ) must be before r1(Y), so that Where ta. goals > ALL (select tb. goals from top_ scorer
as tb where tb. country = 'Spain')
(r2 (Y ) w2 (Y ))(r1 ( X )w1 ( X )) can place, then 4C2 = 6 AND ta. goals > ANY (Select tc. goals from top_scorer
ways. as tc where tc.country = 'Germany')
Then the number of tables are :
1. r2 (Y )w2 (Y )r1 ( X ) w1 ( X )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can
place in 6C2 = 15 ways.
Player
2. r2 (Y )r1 ( X )w1 ( X ) w2 (Y )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can 1 K-los e
place in 4C2 = 6 ways. 2 Ron aldo
3. r2 (Y )r1 ( X )w2 (Y ) w1 ( X )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can 3 G-M u ller
place in 5C2 = 10 ways. 4 Fo ntaine
5 Pele
Total tables are : 7.
4. r1 ( X ) w1 ( X )r2 (Y ) w2 (Y )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can
6 Klin s man n
place in 4C2 = 6 ways.
7 Ko cs is
5. r1 ( X )r2 (Y )w2 (Y ) w1 ( X )r1 (Y ) w1 (Y )r2 (Z ) w2 ( Z ) can
place in 5C2 = (10 ways). Hence 7 is the correct answer.
EBD_7203
2017 -38 SOLVED PAPER - 2017
47. (15) The given sequence is 50. (225) By using haffman tree :
1+ z
{an }¥n = 0 = , 1.0
(1 - z )3 0 1
1+ z 0.59 0.41
Consider, 3
= (1 + z )(1 - z ) -3
(1 - z ) 0 1 0 1
Block size = 512 bytes. Waiting Time = (Completion time – Arrival time
Block pointer (BP) = 2 bytes. – Burst time).
Then maximum order of B+ tree is SAT = (0 + 5 + 12 + 2 + 9) = 28
Let K is the order then,
SBT = (11 + 28 + 2 + 10 + 16) = 67
K * Bp + ( K - 1)* Key £ Block size
SCT = (67 + 51 + 49 + 40 + 33) = 240
K *2 + ( K - 1) *8 £ 512 Waiting time = (240 – 28 – 67) = 145
10 K £ (512 + 8) 145
Average waiting time = = 29 ms
10 K £ 520 5
Hence, 29ms is correct answer.
æ 520 ö
K =ç ÷ = 52 52. (5) The given function is:
è 10 ø
Hence, 52 is correct answer. f (l) = l3 - 4l 2 + al + 30 = 0 ...(i)
SOLVED PAPER - 2017 2017-39
Here, (2) is one Root of this equation. (8) Print f ("%d", n);
So, (l = 2) Then, the output will be 0.
Then, f (2) = (2)3 – 4(2)2 + a × 2 + 30 = 0 Hence, 0 is correct answer.
Þ a = –11 55. (2) In the given program :
By putting the value of a in (i) equation. String Þ (C + 2[ P ] - 6[ P] - 1)
So, the equation is: l - 4l - 11l + 30 = 0
3 2
0 1 2 3 4 5 6 7 8 9 10 11
Now, by polynomials division, we get, G A T E C S I T 2 0 1 7
100
é l3 - 4l 2 - 11l + 30 ù 2 0[P] 2[P] 6[P]
ê ú = (l - 2l - 15)
ë ( X - 2) û Let, address ((0[P] = 100) = C)
Strlen (C + 2[P] + 6[P] – 1)
So the root of l 2 - 2l - 15 = 0 are
= Strlen (100 + ('T ' – 'I') – 1)
2 ± 4 + 60 2 ± 8 No, putting ACCII value of T and I, then
l= = = 5 and - 3
2 2 = Strlen (100 + 11 – 1)
So, the value of l is 2, 5, –3 the Maximum value of the = Strlen (100 + 10)
eigen value of Matrix M is = 5. = Strlen (110)
Hence, 5 is correct answer. =2
53. (18) As given that, 56. (d)
Tha main memory size = 232 byte 57. (b)
Block size = 32 byte 58. (a) According to data arrangement is
Direct Mapped Cache line = 512 West ¬ X Z V W Y ® East
Address Forment : V is in middle
59. (b) Let number of MCQ,s be = x
32 bit
Let number of essay type Questions be = y
Tag Block Identi? er (L0 ) Block Size (W0 ) According to Question
X (log2 512) = 9 bit (log2 32) = 5 bit x + y = 20
9 bit 5 bit 3x + 11y = 100
So, the size of the tag field (X) = (32 – (5 + 9)) = 18 bit. After solving
Hence, 18 bits is correct answer. x = 15 ; y = 5
54. (0) Consider each statement in the program So there are 15 MCQs in test
(1) int m = 10; //m = 10 60. (d) Total socks = 10
(2) int n, n1; Probability of cutting 2 same colour socks
(3) n = + + m; //n = 11 3
C2 + 4C2 + 3C2 3 + 6 + 3 12
= =
(n = (++m)) will increment by m and it assign to n: 10
C2 45 45
(n = 11, m = 11)
(4) n1 = m++; //n = 11 4
P(E) =
n1 = m++; will assign (m) to (n1) and then 15
increment m by one. 61. (b)
So, (n1 = 11), (m = 12)
62. (b) has has has
(5) n– –; //n = 10 Apples Oranges Both
(n - -), decremented by 1 then (n = 10).
Oranges Apples Apples
(6) - - n1; //n1 = 10 Label: or or or
(- - n1) decremented by 1 then (n1 = 10) Both Both Oranges
(7) n - = n1; //n = 0 We will open box labeled apple and oranges & we draw
(n- = n1), same as n = (n – n1) = 10 – 10 = 0 one fruit.
EBD_7203
2017 -40 SOLVED PAPER - 2017
If it is apple, then it cannot be box containing apples & x2 -2
1
oranges as it must be incorrectly labeled. 64. (c) ex + = 0
2
So, it must contain apples.
2
Same case will happen if drawn fruit is orange
Then, we are left with two boxes & two labels & we know 1
label is incorrect on box so we can place correct label
–2 2
63. (a) 30 digit number can be assumed as 47 × 1028
y = 47 × 1028
2
Cubing on both sides 1x
ex = 2 -
2
y3 = (47)3 × (1028)3
Number of solution are 2
= 103828 × 1084 65. (c) In the figure region R has lowest pressure. Hence most
\ y3 has 90 digits likely to have thunderstorm in this region
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.
22. Consider the following C program: 26. Which of the following languages is generated by the given
void f (int, short); grammar?
void main () S ® aS | bS | e
{ int i = 100;
(a) {anbm |n, m > 0}
short s = 12;
(b) {w Î {a, b}*|w has equal number of a’s and b’s}
short *p = &s;
__________ ; // call to f () (c) {an|n > 0} È {bn | n > 0} È {anbn|n > 0}
} (d) {a,b}*
Which one of the following expressions, when placed in the 27. Which of the following decision problems are undecidable?
blank above, will NOT result in a type checking error? I. Given NFAs N1 and N2, is L(N1) Ç L(N2) = F?
(a) f (s,*s) (b) i = f (i, s) II. Given a CFG G = (N, S, P, S) and a string x Î S*, does
x Î L(G)?
(c) f (i,*s) (d) f (i,*p)
III. Given CFGs G1 and G2 is L(G1) = L(G2)?
23. The worst case running times of Insertion sort, Merge sort
and Quick sort, respectively, are: IV. Given a TM M, is L(M) = F?
(a) I and IV only (b) II and III only
(a) Q (n log n), Q (n log n), and Q (n2)
(c) III and IV only (d) II and IV only
(b) Q (n2), Q (n2), and Q (n log n)
28. Which one of the following regular expressions represents
(c) Q (n2), Q (n log n), and Q (n log n) the language: the set of all binary strings having two
(d) Q (n2), Q (n log n), and Q (n2) consecutive 0s and two consecutive 1s?
24. Let G be a weighted connected undirected graph with distinct (a) (0+1)*0011(0+1)*+(0+1)*1100(0+1)*
positive edge weights. If every edge weight is increased by (b) (0+1)*(00(0+1)*11+11(0+1)*00)(0+1)*
the same value, then which of the following statements is/ (c) (0+1)*00(0+1)*+(0+1)*11(0+1)*
are TRUE? (d) 00(0+1)*11+11(0+1)*00
P: Minimum spanning tree of G does not change 29. Consider the following code segment:
Q: Shortest path between any pair of vertices does not change x = u – t;
(a) P only (b) Q only y = x * v;
(c) Neither P nor Q (d) Both P and Q x = y + w;
25. Consider the following C program: y = t – z;
#include <stdio.h> y = x * y;
void mystery (int *ptra, int *ptrb){ The minimum number of total variables required to convert
the above code segment to static single assignment form
int *temp; is __________.
temp = ptrb; 30. Consider an arbitrary set of CPU-bound processes with
ptrb = ptra; unequal CPU burst lengths submitted at the same time to a
computer system. Which one of the following process
ptra = temp;
scheduling algorithms would minimize the average waiting
} time in the ready queue?
int main() { (a) Shortest remaining time first
int a=2016, b=0, c=4, d=42; (b) Round-robin with time quantum less than the shortest
mystery (&a, &b); CPU burst
45. What will be the output of the following C program? 50. G = (V,E) is an undirected simple graph in which each edge
void count (int n){ has a distinct weight, and e is a particular edge of G. Which
static int d=1; of the following statements about the Minimum Spanning
Trees (MSTs) of G is/are TRUE?
print f (“%d”, n); I. If e is the lightest edge of some cyclein G, then every
print f (“%d”, d); MST of G includes e
d++;
II. If e is the heaviest edge of some cyclein G, then
if (n>1) count (n – 1);
every MST of G excludes e
print f (“%d”, d);
} (a) I only (b) II only
void main( ){ (c) both I and II (d) neither I nor II
count(3); 51. Let Q denote a queue containing sixteen numbers and S be
} an empty stack. Head (Q) returns the element at the head of
(a) 3 1 2 2 1 3 4 4 4 (b) 3 1 2 1 1 1 2 2 2 the queue Q without removing it from Q. Similarly Top (S)
(c) 3 1 2 2 1 3 4 (d) 3 1 2 1 1 1 2 returns the element at the top of S without removing it from
46. What will be the output of the following pseudo-code when S. Consider the algorithm given below.
parameters are passed by reference and dynamic scoping is
assumed?
a = 3; while Q is not Empty do
void n(x) {x = x * a; print(x);} if S is Empty OR Top(S) £ Head(Q) then
x := Dequeue(Q);
void m(y) {a = 1; a = y – a; n(a); print(a);} Push(S, x);
void main( ) {m(a);} else
x := Pop(S);
(a) 6, 2 (b) 6, 6 Enqueue(Q, x);
(c) 4, 2 (d) 4, 4 end
end
47. An operator delete (i) for a binary heap data structure is to
be designed to delete the item in the i-th node. Assume that
the heap is implemented in an array and i refers to the i-th
index of the array. If the heap tree has depth d (number of The maximum possible number of iterations of the while loop
edges on the path from the root to the farthest leaf), then in the algorithm is _________.
what is the time complexity to re-fix the heap efficiently after 52. Consider the following context-free grammars:
the removal of the element?
G1: S ® aS | B, B ® b | bB
(a) O (1)
G2: S ® aA | bB, A ® aA | B | e, B ® bB | e
(b) O (d) but not O (1)
Which one of the following pairs of languages is generated
(c) O (2d) but not O (d)
by G1 and G2, respectively?
(d) O (d 2d) but not O (2d)
(a) {ambn|m > 0 or n > 0} and {ambn|m > 0 and n > 0}
48. Consider the weighted undirected graph with 4 vertices,
where the weight of edge {i, j} is given by the entry Wi j in (b) {ambn|m > 0 and n > 0} and {ambn|m > 0 or n ³ 0}
the matrix W. (c) {ambn|m ³ 0 or n > 0} and {ambn|m > 0 and n > 0}
(a) {m, K+B (H(m))} (b) {m, K–B (H(m))} output at a rate of 10 megabytes per second. The token
(c) {m, K–A (H(m))} (d) {m, K+A (m)} bucket is currently full and the machine needs to send 12
63. An IP datagram of size 1000 bytes arrives at a router. The mega bytes of data. The minimum time required to transmit
router has to forward this packet on a link whose MTU the data is _______ seconds.
(maximum transmission unit) is 100 bytes. Assume that the 65. A sender uses the Stop-and-Wait ARQ protocol for reliable
size of the IP header is 20 bytes. transmission of frames. Frames are of size 1000 bytes and
The number of fragments that the IP datagram will be the transmission rate at the sender is 80 Kbps (1Kbps =
divided into for transmission is __________ . 1000 bits/second). Size of an acknowledgement is 100
64. For a host machine that uses the token bucket algorithm bytes and the transmission rate at the receiver is 8Kbps.
for congestion control, the token bucket has a capacity The one-way propagation delay is100 milliseconds.
of 1 megabyte and the maximum output rate is 20 Assuming no frame is lost, the sender throughput is
megabytes per second. Tokens arrive at a rate to sustain ________ bytes/second.
EBD_7203
2016 -8 SOLVED PAPER - 2016
47. (b)
48. 12 print (1)
3
56. (c)
8 S¢
d b
2 print (3)
5 x 5 a A 2
a c b
8 Print (2)(1) s
The shortest path (excluding x) from 2 to 3 is of weight 12
(2–1–0–3). a
49. 7
57. 384
4 4 Size of memory = 240, Page size = 16KB = 214, No. of pages
= Size of Memory/page size = 240/214 = 226, Size of page
1 table = 226 * 48/8 bytes = 26*6 MB = 384 MB
1 3
5 6 Þ 58. 165
The head movement would be :
2 2
63 => 87 24 movements
50. (b) I is NOT true. Suppose in a rectangular with sides (1, 2,
87 => 92 5 movements
4, 5) and 3 is the weight of the diagonal connecting
vertex between (4, 5) and (1, 2), here e = 3 is the lightest 92 => 121 29 movements
edge of some cycle in G but in MST it is not including. 121 => 191 70 movements
II is true. Let the heaviest edge be e. Suppose the 191 => 10 0 movement
minimum spanning tree which contains e. If we add 10 => 11 1 movement
one more edge to the spanning tree we will create a
11 => 38 27 movements
cycle. Suppose we add edge e' to the spanning tree
which generated cycle C. We can reduce the cost of 38 => 47 9 movements
the minimum spanning tree if we choose an edge other Total head movements = 165
than e from C for removal which implies that e must not 59. 1
be in minimum spann ing tree and we get a a1a2........a20 a1a2...........a20
contradiction. LIFO
51. 256
... n = 16 0 a1
Therefore, maximum number of iterations will be n2 = 256 1 a2
52. (d) In G1, there will be atleast 1 b because S->B and B->b. 2 a3
But no. of A's can be 0 as well and no. of A and B are 3 a4
independent. In G2, either we can take S->aA or S->bB. 4 a5
So it must have atleast 1 a or 1 b. So option (d) is 5 a6
correct. 6 a7 a11 a12 a13 a14 a15 a16 a17 a18 a19 a 20
53. (d) Initial state is also the final state. 7 a8
So an is also accepted. 8 a9
54. (c) 9 a10
55. 9
2 – 5 + 1 – 7 * 3 Þ 2 – (5 + 1) – 7 * 3 For first a1 to a20, The no. of page faults = 20
Þ 2 – 6 – 7 * 3 Þ 2 – (6 – 7) * 3 Þ 2 – (–1) * 3 Now a1 to a9, Hit again a10 to a20 replace only 9th position,
Þ (2 + 1) * 3 Þ 3 * 3 = 9 so no. of page faults = 11. S0, total no. of page faults = 31
EBD_7203
2016 -12 SOLVED PAPER - 2016
Optimal 63. 13
Hash L 1000Bytes
M Tx ( msg ) = = = 100 ms
Function Bs 10 ´103 BPS
LA 100Bytes
TA ( Ack ) = = = 100 ms
Senders Private BR 1´103 BPS
–
Key (KB ) H(m) Tp =100 ms
\ Channel Utilization
Tn 100 ms 1
K -B (H (m )) = T + T + 2T = 100 ms + 100 ms + 200 ms = 4
Digital Signature n ack p
generator
1
\ Throughput = h × B = × 10 × 103 = 2.5 Kbps
+ M Å K -B (H (m)) 4
(or 2500 bps)
SOLVED PAPER - 2016 2014-13
2016
SET - 2
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question
numbers 11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-mark each.
4. Questions are of multiple choice type (MCQ)or numerical answer type. A multiple choice type question will have four
choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
GENERAL APTITUDE 4. Pick the odd one from the following options.
(a) CADBE (b) JHKIL
QUESTION 1 TO 5 CARRY ONE MARK EACH (c) XVYWZ (d) ONPMQ
5. In a quadratic function, the value of the product of the
1. The man who is now Municipal Commissioner worked as
____________________. a n + bn
roots (a, b) is 4. Find the value of
(a) the security guard at a university a - n + b- n
(b) a security guard at the university
(a) n4 (b) 4n
(c) a security guard at university
(c) 22n-1 (d) 4n-1
(d) the security guard at the university
2. Nobody knows how the Indian cricket team is going to QUESTION 6 TO 10 CARRY TWO MARKS EACH
cope with the difficult and seamer-friendly wickets in 6. Among 150 faculty members in an institute, 55 are
Australia. connected with each other through Facebook® and 85 are
Choose the option which is closest in meaning to the connected through WhatsApp®. 30 faculty members do
underlined phrase in the above sentence. not have Facebook® or WhatsApp® accounts. The
(a) put up with (b) put in with number of faculty members connected only through
Facebook® accounts is ______________.
(c) put down to (d) put up against
(a) 35
3. Find the odd one in the following group of words.
mock, deride, praise, jeer (b) 45
(a) mock (b) deride (c) 65
(c) praise (d) jeer (d) 90
EBD_7203
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.
EBD_7203
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];
EBD_7203
2014 -18 SOLVED PAPER - 2016
The grammars use D as the start symbol, and use six
terminal symbols int ; id [ ]num.
90
Grammar G1 Grammar G2
80
D ® int L; D ® int L;
70
( )
-1 T T 1 that no. of a’s should be equal to no. of b’s, but order
Now, A = A -1 = A -1 = = 0.125
8 of a’s and b’s is different here, it is (ab)*, which will
require no extra memory to be accepted. (Finite
17. –1
Automaton can be built for this language). Hence L2 is
18. (c) regular language. Therefore Q is True.
19. 1
28. (d) Statement (IV) : L2 may or may not be context free
X = –216 – 1 to +216 – 1 – 1
Y = –216 – 1 – 1 to +216 – 1 – 1 because CFL are not closed under complementation.
So it is not true.
Therefore, X – Y = 1
29. (b)
20. 16 6 bits are needed for 40 distinct instructions (because,
30. (d) When the rate of page fault increases even after the
32 < 40 < 64) 5 bits are needed for 24 general purpose
increasing number of allocated frames, then this
registers (because, 16 < 24 < 32) 32-bit instruction word
situation is called “Belady’s Anamoly”. In the given
has an opcode(6 bit), two register operands(total 10
options, it’s occurring in FIFO only.
bits) and an immediate operand (x bits). The number of
31. (a) In B and B+ trees, all the leaf nodes will be at same
bits available for the immediate operand field => x = 32
level.
– (6 + 10) = 16 bits
32. (a)
33. (a) In the process of digital signature generation, by using
sender’s private key, one can encrypt the message and
in the process of verification, by using sender’s public
key, one can decrypt the message.
21. 31 34. (d)
35. (c) When a web browser requests any web page from a
remote server then that request (URL address) is
mapped to IP Address usin g DNS, th en TCP
It would be node number 31 for given distance 4. synchronisation occurs. Finally HTTP verifies that the
22. 30 address exists in the web server or not.
The address of i and value of j are passed to the function of 36. (b) R is reflexive as every ordered pair is related to itself.
f. f modifies i’s value to 20. j’s value remains same (as its (a, b) R (a, b) since a £ a or b £ b
value is passed not the reference). The value printed by the
It is not transitive as (2, 4) R (3, 2) and (3, 2) R(1, 3) but
program will be i + j = 20 + 10 = 30.
(2, 4) R (1, 3).
EBD_7203
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.
EBD_7203
2014 -24 SOLVED PAPER - 2016
60. 30 Suppose minimum frame size is L bits. Tx = L / B where B is
61. (c) the bandwidth = 20 * 106 bits/sec
There is no transaction which reads the data item written by Tp = 40 micro seconds (given)
any other transaction. Therefore the given schedule is Tx = 2 Tp L / B = 80 micro seconds
cascadeless. L = B ´ 80 micro seconds = 20 ´ 106 bits/sec ´ 80 micro
seconds = 1600 bits
62. 2
Now as the answer has to be given in Bytes, hence, 1600/8
First we should perform group by group. We get ajmer 1
bytes = 200 bytes.
bikaner 3 64. (b) RTS-CTS mechanism is used in collision avoidance,
charu 2 but not in collision detection. Hence statement II is
dungargarh 1 false.
Now we should perform total capacity we will get 100. Now 65. 4
perform avg. capacity on total 100/4 = 25. bikaner = 40 which To achieve 100% efficiency, the number of frames that we
is greater than 25 charu is 30 which is also greater than 25. should send = 1 + 2 ´ Tp / Tt where, Tp is propagation delay,
Hence charu and bikaner will be printed therefore answer is and Tt is transmission delay. So, Number of frames sent = 1
+ 4.687 = 5.687 (approx 6). As the protocol used is Selective
2 tuples.
repeat, Receiver window size should be equal to Sender
63. 200 window size. Then, Number of distinct sequence numbers
For frame size to be minimum, its transmission time should required = 6 + 6 = 12 Number of bits required to represent 12
be equal to twice of one way propagation delay, i.e., Tx = 2Tp distinct numbers = 4
SOLVED PAPER - 2015 2015-1
2015
SET - 1
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question numbers
11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-marks each.
4. Questions are of Multiple Choice Question (MCQ) or Numerical Answer type. A multiple choice question will have
four choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
14. The height of a tree is the length of the longest root-to-leaf 21. Which of the following statements is/are FALSE?
path in it. The maximum and minimum number of nodes in I. XML overcomes the limitations in HTML to support a
a binary tree of height 5 are structured way of organizing content.
(a) 63 and 6, respectively II. XML specification is not case sensitive while HTML
(b) 64 and 5, respectively specification is case sensitive.
(c) 32 and 6, respectively III. XML supports user defined tags while HTML uses pre-
(d) 31 and 5, respectively
defined tags.
15. Match the following:
IV. XML tags need not be closed while HTML tags be
P: Prim’s algorithm for minimum spanning tree
closed
Q: Floyd – Warshal algorithm for all pairs shortest paths
R: Mergesort (a) II only (b) I only
S: Hamiltonian circuit (c) II and IV only (d) III and IV only
(I) Backtracking (II) Greedy method 22. A file is organized so that the ordering of data records is the
(III) Dynamic programming same as or close to the ordering of data entries in some index.
(IV) Divide and conquer Then that index is called
(a) P-III, Q-II, R-IV, S-I (a) Dense (b) Sparse
(b) P-I, Q-II, R-IV, S-III (c) Clustered (d) Unclustered
(c) P-II, Q-III, R-IV, S-I 23. Which of the following is/are correct inorder traversal
(d) P-II, Q-I, R-III, S-IV sequence(s) of binary search tree(s)?
16. Which one of the following is NOT equivalent to p«q? I. 3, 5, 7, 8, 15, 19, 25 II. 5, 8, 9, 12, 10, 15, 25
(a) (Øpvq)^(p^Øq) (b) (Øpvq) ^(q®p)
III. 2, 7, 10, 8, 14, 16, 20 IV. 4, 6, 7, 9, 18, 20, 25
(c) (Øp^q)v(p^Øq) (d) (Øp^Øq) v(p^q)
(a) I and IV only (b) II and iii only
17. SELECT operation in SQL is equivalent to
(c) II and IV only (d) II only
(a) the selection operation in relational algebra
(b) the selection operation in relational algebra, except that 24. Suppose two hosts use a TCP connection to transfer a large
SELECT in SQL retains duplicates file. Which of the following statements is/are FALSE with
(c) the projection operation in relational algebra respect to the TCP connection?
(d) the projection operation in relational algebra, except I. If the sequence number of a segment is m, then the
that SELECT in SQL retains duplicates sequence number of the subsequent segment is always
18. For any two languages L1 and L2 such that L1 is context-free m + 1.
and L2 is recursively enumerable but not recursive, which of II. If the estimated round trip time at any given point of
the following is/are necessarily true? time is t sec the value of the retransmission timeout is
I. L1 (complement of L1) is recursive always set to greater than or equal to t sec.
III. The size of the advertised window never changes
II. L2 (complement of L2) is recursive
during the curse of the TCP connection.
III. L1 is context – free IV. The number of unacknowledged bytes at the sender is
always less than or equal to the advertised window.
IV. L1 È L2 is recursively enumerable
(a) III only (b) I and III only
(A) I only (B) III only
(c) I and IV only (d) II and IV only
(C) III and IV only (D) I and IV only
25. For computers based on three-address instruction formats,
19. For a set A, the power set of A is denoted by 2A. If A = {5,
each address field can be used to specify which of the
{6}, {7}}, which of the following options are TRUE?
I. fÎ 2A II. f Î 2A following.
III. {5, {6}} Î 2A IV. {5{6}} Í 2A S1: A memory operand
(a) I and III only (b) II and III only S2: A processor register
(c) I, II and III only (d) I, II and IV only S3: An implied accumulator register
20. Consider a 4-bit Johnson counter with an initial value of (a) Either S1 or S2 (b) Either S2 or S3
0000. The counting sequence of this counter is (c) Only S2 and S3 (d) All of S1, S2 and S3
(a) 0, 1, 3, 7, 15, 14, 12, 8, 0 26. Consider a system with byte–addressable memory, 32-bit
(b) 0, 1, 3, 5, 7, 9, 11, 13, 15, 0 logical addresses, 4 kilobyte page size and page table entries
(c) 0, 2, 4, 6, 8, 10, 12, 14, 0 of 4 bytes each. The size of the page table in the system in
(d) 0, 8, 12, 14, 15, 7, 3, 1, 0 megabytes is ______.
EBD_7203
2015 -4 SOLVED PAPER - 2015
27. The following two functions P1 and P2 that share a variable 34. Match the following:
B with an initial value of 2 execute concurrently. P: Condition coverage
P1 ( ) { P2 ( ) { Q: Equivalence class partitioning
C = B – 1; D = 2 * B;
R: Volume testing
B = 2 * C; B = D – l;
} } S: Alpha testing
28. limx®¥ x1/x is (I) Black-box testing (II) System testing
(a) ¥ (b) 0 (III) White-box testing (IV) Performance testing
(c) 1 (d) Not defined
(a) P-II, Q-III, R-I, S-IV
29. Which one of the following is the recurrence equation for the
worst case time complexity of the Quicksort algorithm for (b) P-III, Q-IV, R-II, S-I
sorting n (³ 2) numbers? In the recurrence equations given (c) P-III, Q-I, R-IV, S-II
in the options below, c is a constant. (d) P-III, Q-I, R-II, S-IV
(a) T(n) = 2T(n/2) + cn
(b) T(n) = T(n–1) + T(1) + cn é 2 2ù
(c) T(n) = 2T(n–1) + cn 35. In the LU decomposition of the matrix ê 4 9ú , if the
ë û
(d) T(n) = T(n/2) + cn
diagonal elements of U are both 1, then the lower diagonal
x g(h(x))
30. If g(x) =1 – x and h(x) = , then is entry l22 of L is ______.
x -1 h(g(x))
QUESTION 36 TO 65 CARRY TWO MARKS EACH
h(x) -1
(a) (b) 36. The graph shown below has 8 edges with distinct integer edge
g(x) x
weights. The Minimum Spanning Tree (MST) is of weight 36
g(x) x
(c) (d) and contains the edges: {(A, C), (B, C), (B, E),
h(x) (1 - x) 2 (E, F), (D,F)}. The edge weights of only those edges which
31. In one of the pairs of protocols given below, both the are in the MST are given in the figure shown below. The
protocols can use multiple TCP connections between the minimum possible sum of weights of all 8 edges of this graph
same client and the server. Which one is that? is _______.
(a) HTTP, FTP (b) HTTP, TELNET
(c) FTP, SMTP (d) HTTP, SMTP
32. What are the worst-case complexities of insertion and 15
B E
deletion of a key in a binary search tree? 4
(a) q(log n) for both insertion and deletion
(b) q(n) for both insertion and deletion A F
2
(c) q.(n) for insertion and q(log n) for deletion
(d) q(log n) for insertion and q(n) for deletion 9 6
33. The output of the following C program is ______. D
C
void f1(int a, int b)
{
int c; 37. Consider a disk pack with a seek time of 4 milliseconds and
c=a; a=b; b=c; rotational speed of 10000 Rotations Per Minute (RPM). It
} has 60 sectors per track and each sector can store 512 bytes
void f2(int *a, int *b) of data. Consider a file stored in the disk. The file contains
{ 2000 sectors. Assume that every sector access necessitates a
int c; seek, and the average rotational latency for accessing each
c=*a; *a=*b; *b=c; sector is half of the time for one complete rotation. The total
}
time (in milliseconds) needed to read the entire file is
int main ( )
_______.
{
int a=4, b=5, c=6; 38. Consider the following pseudo code, where x and y are
f1(a, b); positive integers.
f2(&b, &c); begin
printf(“%d”, c–a–b); q: = 0
} r:=x
SOLVED PAPER - 2015 2015-5
while r > y do 41. Consider the NPDA < Q = {q0, q1, q2}, S = {0, 1},
being G = {0, 1,}^d, q0, ^, F = {q2}>, where (as per usual
r:=r–y convention) Q is the set of states, S is the input alphabetd is
q:=q+1 the stack alphabet, d is the state transition function, q0 is the
end initial state, ^ is the initial stack symbol, and F is the set of
end accepting states. The state transition is as follows:
The post condition that needs to be satisfied after the program
terminates is 1, Z ® Z 0, 1Z ® Z
(a) {r = qx + y Ù r < y} 0, Z ® 0Z 1, 0Z ® Z
(b) {x = qy + r Ù r < y} q0 q1 q2
(c) {y = qx + r Ù 0 < r < y}
(d) {q + 1 < r – y Ù y > 0}
39. Consider the following relations:
Students 0/1/ Î
, Z Z® Î, ^ ® Î
55. Consider the following C function. 60. Consider the following C program segment.
int fun1 (int n) while (first <= last)
{ {
int i, j, k, p, q = 0; if (array[middle] < search)
for (i = 1; i < n; ++i) first = middle + 1;
{ else if (array[middle] = = search)
p = 0; found = TRUE;
for(j = n; j > 1; j = j/2) else last = middle – 1;
++p; middle = (first + last)/2;
for(k =1; k < p; k = k*2) }
++q; if (first > last) notPresent = TRUE;
}
return q; The cyclomatic complexity of the program segment is
} ______.
Which one of the following most closely approximates the 61. Consider a max heap, represented by the array: 40, 30, 20,
return value of the function fun1? 10, 15, 16, 17, 8, 4.
(A) n3 (B) n(log n)2
Array Index 1 2 3 4 5 6 7 8 9
(C) n log n (D) n log(log n)
Value 40 30 20 10 15 16 17 8 4
56. Consider a non-pipelined processor with a clock rate of 2.5
gigahertz and average cycles per instruction of four. The Now consider that a value 35 is inserted into this heap. After
same processor is upgraded to a pipelined processor with five insertion, the new heap is
stages; but due to the internal pipelined delay, the clock speed (a) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
is reduced to 2 gigahertz. Assume that there are no stalls in (b) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
the pipeline. The speed up achieved in this pipelined (c) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
processor is _____. (d) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
57. Consider an Entity-Relationship(ER) model in which entity 62. Suppose the following disk request sequence (track numbers)
sets E1 and E2 are connected by an m: n relationship R12. E1 for a disk with 100 tracks is given: 45, 20, 90, 10, 50, 60, 80,
and E3 are connected by a 1: n (1 on the side of E 1 and n on 25, 70. Assume that the initial position of the R/W head is on
the side of E3) relationship R13. track 50. The additional distance that will be traversed by the
E1 has two single-valued attributes a11 and a12 of which a11 R/W head when the Shortest Seek Time First (SSTF)
is the key attribute. E2 has two single-valued attributes a21 algorithm is used compared to the SCAN (Elevator)
and a22 of which is the key attribute. E3 has two single-valued algorithm (assuming that SCAN algorithm moves towards
attributes a31 and a32 of which a31 is the key attribute. The 100 when it starts execution) is ______ tracks.
relationships do not have any attributes. 63. Consider a LAN with four nodes S1¸S2, S3 and S4. Time is
If a relational model is the derived from the above ER model, divided into fixed-size slots, and a node can begin its
then the minimum number of relations that would be transmission only at the beginning of a slot. A collision is said
generated if all the relations are in 3NF is _______.
to have occurred if more than one node transmit in the same
99 slot. The probability of generation of a frame in a time slot
1
58. å x(x + 1)
= ______________ .
by S1, S2, S3 and S4 are 0.1, 0.2, 0.3 and 0.4, respectively.
x =1
The probability of sending a frame in the first slot without any
59. Let a n represent the number of bit strings of length n
collision by any of these four stations is ________.
containing two consecutive 1s. What is the recurrence
64. An algorithm performs (log N)1/2 find operations, N insert
relation for an?
operations, (log N)1/2 delete operations, and (log N)1/2
(A) an–2+ an–1+2n–2
decrease-key operations on a set of data items with keys
(B) an–2+2an–1+2n–2
drawn form a linearly ordered set. For a delete operation, a
(C) 2an–2+a n–1+2n–2
pointer is provided to the record that must be deleted. For the
(D) 2an–2+2an–1+2n–2
EBD_7203
2015 -8 SOLVED PAPER - 2015
decrease-key operation, a pointer is provided to the record
that has its key decreased. Which one of the following data 1 p=q+r
structures is the most suited for the algorithm to use, if the s=p+q
u=s*v
goal is to achieve the best asymptotic complexity considering
all the operations?
(a) Unsorted array
(b) Min–heap
2 v=r+u 3 q=s*u
(c) Sorted array
(d) Sorted doubly linked list
65. A variable x is said to be live at a statement Si in a program
if the following three conditions hold simultaneously: 4 q=v+r
I. There exists a statement Sj that uses x
II. There is a path from S i to S j in the flow graph The variables which are live at the statement in basic block
corresponding to the program 2 and at the statement in basic block 3 of the above control
III. The path has no intervening assignment to x including flow graph are
at Si and Sj (A) p, s, u (B) r, s, u
(C) r, u (D) q, v
SOLVED PAPER - 2015 2015-9
él l11u12 ù
g ( h ( x )) h (x) = ê 11 ú
= ël21 l21u12 + l22 û
h ( g ( x )) g (x)
\ l11 = 2;l11u12 = 2 Þ u12 = 1
31. (d) HTTP (Hyper Text Transfer Protocol) and SMTP l21 = 4; l21u12 + l22 = 9 Þ l22 = 5
(Simple Message Transfer Protocol) protocols can use
several TCP associations between the same client and 15
the server. B E
10 4
32. (b) If we judge a single string of binary search tree, then
we have to sketch all the nodes for insertion or deletion
2 7 F
in worst case hence θ (n) for both. A
36. 69
33. –5 In function "main ()" 9 6
D
f1 is called by value, so local variables a, b, c of f1 are C
16
customized but not the local variables a, b, c of main
function.
f2 is called by reference. Total sum = 10 + 9 + 2 + 15 + 7 + 16 + 4 + 6 = 69
int main () { 37. 14020
int a = 4, b = 5, c = 6 Given that
f1(a, b) Seek time = 4ms
f2(&b, &c) 60s ® 10000 rotations
printf ("%d", c-a-b); 60s ® 10000 rotations
}
60
f2(int *a, int *b) = 6ms ¬ 1 rotation time
{ 10000
int c; 1
c = * a; c 5 \ Rotational Latency = ´ 6ms = 3ms
2
* a = b; [will change 'b' value of main to c value of
1 track ® 600 sectors
main]
6ms ¬ 600 sectors (1 rotation means 600 sectors or 1 track)
*b = c; [will change 'c' value of main to c value of f2]
} 6ms
34. (d) Condition coverage is also known as predicate coverage 1 sector ® = 0.01ms
600
in which each of the Boolean expression estimated to 2000 sector ® 2000 (0.01) = 20 ms
both true and false.Which is nothing but white-box \ Total time
testing, which tests internal structures of a function? needed to read the entire tile is = 2000 (4 + 3) + 20
Hence = 8000 + 6000 + 20
P matches with III. = 14020 ms
EBD_7203
2015 -12 SOLVED PAPER - 2015
38. (b) The loop terminater when r < y. so, r < y is one post 50. (b)
condition. 51. (d) Given that l1 = –1 and l2 = 7 are eigen values of A
In each iteration q is incremented by 1 and y is
subtracted from r. Initialvalue of r is x. By the properties, l1 + l2 = tr ( A ) , traces of A i.e.,
x x sum of the diagonal elements and l1 . l 2 = determinant
So, loop iterates times and q will be equal to
y y of A.
and r = x% y Þ x = qy + r Þ 1+a=6
So, (b) is correct answer. a=5
39. (2) Output table is And ¯
Raj 310 a – 4b = –7
Rohit 140 5 – 4b = –7
–4b = –7 –5
T1 T2 T1 T3 T1 T2 T1 T3 T1 ... –4b = –12 Þ b = 3
40.
1 2 4 5 7 8 10 11 (13) 14
æ1ö
41. (d) 42. (c) 2 cos ç ÷
è x ødx
43. (a) It is clear that from the truth table, the binary operation 52. (-1) òp
1
x2
# is equivalent to XOR i.e., Å,which satisfies both p
commutative and associative i.e., p # q º q # p and p
# (q # r) º (p # q) # r 1
Put =t
44. 3 x
45. 1 M accepts the strings which end with a and N accepts
the strings which end with b. Their intersection should -1
Þ dx = dt
accept empty language. x2
a, b And
2 p
x= Þt=
p 2
46. (a) 1
x= Þ t =p
47. (d) Number of elements in L3 = Number of ways in which p
we can choose 3 elements from 5 with repetition
æQ b f x dX = - a f x dx ö
= 5 × 5 × 5 = 125 Now, when we take x = t, then also the ç òa ( ) òb ( ) ÷ø
given condition is satisfied for any y and z. Here, y è
and z can be taken in 5 × 5 = 25 ways. p
Take x = r, y = p, z = p, these, also the given condition = òp cos t dt
2
25 1
is satisfied. So, pr > > .
p æp ö
125 5 = ( sin t ) p = sin p = sin ç ÷ = -1
For x = p, y = r, z = t , the given condition is not è2ø
2
satisfied.
53. 320 Given that B = 64 kbps
So, Pr ¹ 1.
Tp = 20 ms
So, (d) corret option.
48. (d) h ³ 50%
49. 24 By Euler's formula, For h ³ 50% Þ L ³ BR
|V|+|R| = |E|+2 _________ (1) where |V|, |E|, |R| are Þ L = 64 ×103 × 2 × 20 × 10–3
respectively number of vertices, edges and faces = 2560 bits = 320 bytes
(regions) 54. (a)
Q prev. O Q
Given |V| = 10 _______ (2) and number of edges on
each face is three — 1 0
2 0 0 1
` \ 3|R| = 2|E| Þ |R| = 3 |E|_________ (3) 1 1 1
Subtracting (2), (3) in (1), we get 1 1 0
E 0 0 1
2
10 + E = E + 2 Þ = 8 Þ E = 24 1 1 1
3 3
SOLVED PAPER - 2015 2015-13
D flipflop outputs its input and Jk flipflop output E1(a11, a12), E2 (a21, a22), E3 and R13 (a11, a31, a32),
toggles its output when 1 is given to both J and K R2 (a11, a12),
inputs. But in table (a11, a31, a32) there may be transitive
Q = Dprev (Qprev) + (Dprev) (Qprev). dependency between a 11 and a 32 so we should
55. (c) int fun1(int n){ decompose this table into 2 more tables.
int i, j, k, p, q = 0;
for (i = 1;i < n; ++ p) ® n times 1
0.99 å = _____________ .
99
{ 58. X =1
x ( x + 1)
p=0
For( j = n; j > 1; j = j/ 2) 99
1 1 1 1 1
++p; å x ( x + 1) = 1( 2 ) + 2 ( 3) + 3 ( 4 ) + ... + 99 (100 )
log (log n) times X =1
CPIold 1 99
= = 1- = = 0.99
CFold 100 100
=
CPI new
59. (a)
CFnew
60. 5
(where CF is clock frequency and CPI is cycles per 61. (b)
intruction. So, CPI/CF gives time per instruction)
40
4
= 2.5 = 3.2
1
2 30 20
40
E1 R12 E1
m n
30 20
R13
n
10 16 17
15
E3
8 4 35
a31 a32
EBD_7203
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
EBD_7203
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?
EBD_7203
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
EBD_7203
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 ________.
EBD_7203
2015 -22 SOLVED PAPER - 2015
GENERAL APTITUDE P 2 + R 2 + S2 + T 2 + U 2 S2
¹
5 5
1. (c) Personnel-people employed in an organization or
engaged in an organized undertaking such as military 7. (b)
service. 8. (a)
2. (c) f(x) = 1 – |x| on –1 £ x £ 1 (b) there was no needed information
(c) not really useful
ì1 - x, 0 £ x £ 1 (d) would not have been
1- | x | = í
î1 + x, -1 £ x £ 0
7´3
9. 8 h (2, 5, 7, 3) = Remainder of ®1
both functions gives maximum value at x = 0. 2´5
f (0) = 1
fg (h (2, 5, 7, 3), 4, 6, 8) = fg (1, 4, 6, 8)
3. (c)
= f (1, 4, 6, 8) × g (1, 4, 6, 8)
4. (d) apparel- clothing, especially outerwear; garments;
=8× 1=8
attire; raiment
5. (c) Let weight of each pole be x
10. (a) M
x
I. Given, = 15 kg
4
O 1km 4 km
Þ x = 60 kg
All poles are of same weight
\ Weight of 10 poles =10x = 10 × 60 = 600 kg 2 km N
II. Given, 10x = 2x + 160 P
Þ 8x = 160 kg Þ x = 20kg
\ Weight of 10 poles = 10x = 10 × 20 = 200 kg
TECHNICAL SECTION
6. (b) As P, R, S, T, U is an arithmetic sequence
15. (a) 3 – SAT Þ NPC problem requirements and may include a set of use cases that
Q1 £ p describe interactions the user will have with the
3 – SAT £ p software.
Q2 £ p £ p 22. (d)
Hence ® Q1 is in NP £ p
but Q2 is not given in NP f00(ABCDE)
Therefore, Q2 is in NP-Hard.
16. 6
f00(BCDEFGH) print(A)(4)
9
5 13 17 f00(CDEFGH) print(B)(3)
1 3 5 7 9 11 13 15 17
f00(DEFGH) print(C)(2)
17. (a)
18. 14 Average read access time = [(0.8) (5) + (0.2)(50)] ns.
= 4 + 10 = 14 ns
19. 12 Given, B = 106 bps f00((space)EFGH) print(D)(1)
L = 1000 bytes
if condition fails & returns controls
h = 25%
\ DCBA will be pointed
Tp = ?
23. (*) It might be "WRONG" question.
1 N = 2 Þ P1 P2 No. of resources = 6
In stop-and-wait, h =
1 + 2a 2 2
1 1
1 1
Þ = Þ 1 + 2a = 4 Each process can request atmost 2
4 1 + 2a
N = 3 Þ P1 P2 P3
3 2 2 2
2a = 3; a = N = 4 Þ P1 P2 P3 P4
2
1 1 1 1
3 1 1
L 8 ´ 10
Tx = = = 8ms Therefore, no option leads to dead lock.
B 106
24. (a) Basic COCOMO model takes the form
TP 3 Effort applied (E) = ab (kLoc) b b
=
TX 2 ; 2TP = 3T
Development time (D) = cb (E)db
2Tp = 24ms 25. (b) The correct order in which a server process must
Tp = 12ms invoke the function calls is bind, listen, accept and
20. (b) The consistency property ensures that the database recv. First three are used in connection establishment
remains in a consistent state before the (start of the phase and recv is used in data transfer phase.
transaction and after the transaction is over. Here sum 26. (c) Option (a) is false when CFG contains cycle
of the accounts x & y should remain same before & Option (b) is false as CFG can contain cycle
after execution of the given transactions which refers Option (d) is false as a single node can contain block
to the consistency of the sum. of statements.
21. (d) SRS is a description of a software system to be 27. 19 Let the number of vertices of a binary tree with ‘p’
developed, laying out functional & non-functional leaves be n then the tree has–
EBD_7203
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úû
EBD_7203
2015 -26 SOLVED PAPER - 2015
C1 ® C2 – C3 53. (a) L1 = {wxwR| w, x Î {a, b}* and |w|, |x| > 0}
wR is reverse of string w.
é -42 4 45 ù It is regular
~ ê -280 11 300ú = B (resultant matrix) Regular expression
ê ú
êë -182 2 195 úû a (a + b)* a + b (a + b)* b
L2 = {anbm| m ¹ n, m, n ³ 0}
Hence m ¹ n, that mean n is greater than m, or m is
-42 4 3
greater than n.
280 11 300
Now |B| = So we need memory, so we can’t draw DfA for it.
-182 2 195 L3 = {apbqcr|p, q, r ³ 0}
a, b, c
3 4 3
20 11 20
= (–14) (15)
13 2 13
=0
Method 2: Determinant is unaltered by the operations
(i) and (ii)
\ Determinant of the resultant matrix = Determinant of
the given matrix
PAS 232
1 2 3 4 5 6 7 8 9 10 11 12 13 \ No.of frames = = 13 = 219 frames.
P.S 2
I O P P P W
I O - - P P P P P W So, it is given that each page table entry contains a
I - - O - - - - P W valid bit, a dirty bit, 3 permission bits. Þ 5 bits are
I - - O - - - - P W reserved.
SOLVED PAPER - 2015 2015-27
24 ´ 220 ´ 8
Þn= = 223 pages
24
Carry = 2.4 m sec
Length of the virtual address = 23+13=36 bits
A G2 G2 Sum = 4.8 m sec
H.A1 H.A2
56. (a) B
380 c4 s3 c3 s2 c2 s1 c1 s0
\ Probability of a function f being one-one is
400
i.e., 0.95
Here sum and carry delay is same= 4.8 μ sec
So, Ttotal = (4 × 4.8) m sec
= 19.2 m sec
8880 Bytes MIU 63. (b) Since, every edge in a tree is bridge
58. (c)
1500B \ (a) is false
Since, every edge in a complete graph kn (n ³ 3) is not
a bridge Þ (c) is false
Let us consider the following graph G:
(1) (2) (3) (4) (5) (6) (7)
DL 0 - 1471 1472 - 2951 2952 - 4431 4432 - 5911 5912 - 7391 7392 - 8871 8872 - 8879
HL 28 20 20 20 20 20 20
8872
e
OFFSET = 1109
8
59. (d)
60. (a) This graph has a bridge i.e., edge ‘e’ and a cycle of
61. (a) As T1 & T3 are not yet committed they must be
length ‘3’
undone. The transactions which are after the latest
\ (d) is false
checkpoint must be redone. So T2 must be redone. No
Since, in a cycle every edge is not a bridge
need to redo the records which are before last
\ (b) is true
checkpoint, so T4 need not be redone.
62. 19.2 64. (c) Dijkstra shortest path algorithm find next node by
choosing minimum distance hence greedy approach.
EBD_7203
2015 -28 SOLVED PAPER - 2015
Floyd warshall always apply dynamic programming, 65. 5 1 2 5 14 ¥ 2 5 14
once it saves a cost and in the next iteration it will 3 4 6 23 3 4 6 23
change if this is minimum hence dynamic. 10 12 18 25 10 12 18 25
Þ Binary search always divide on two parts. 31 ¥ ¥ ¥ 31 ¥ ¥ ¥
Hence divide and conquer.
Ü
2shift
Þ Backtracking uses by DFS, one it will reach to dead 2 4 5 14 2 4 5 14
end it will take back track. 3 618 23 3 ¥ 6 23
Ü
10 12 ¥ 25 10 12 18 25
31 ¥ ¥ ¥ 31 ¥ ¥ ¥
2 shift
Ü
2 4 5 14
3 4 18 23
10 12 25 ¥
31 ¥ ¥ ¥
SOLVED PAPER - 2015 2015-29
2015
SET - 3
Duration: 3 hrs Maximum Marks: 100
INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question numbers
11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-marks each.
4. Questions are of Multiple Choice Question (MCQ) or Numerical Answer type. A multiple choice question will have
four choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions, mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.
120
110
100
90
80
70
60
50
40
30
20
10
0
2000 2001 2002 2003 2004 2005 2006 2007
Export Import
9. Most experts feel that in spite of possessing all the technical III. He failed to make many of his good starts count.
skills required to be a batsman of the highest order, he is IV. Improving his technical skills will guarantee success.
unlikely to be so due to lack of requisite temperament. He (a) (III) and (IV) (b) (II) and (III)
was guilty of throwing away his wicket several times after (c) (I), (II), and (III) (d) (II) only
working hard to lay a strong foundation. His critics pointed 10. The head of a newly formed government desires to appoint
out that until he addressed this problem, success at the highest five of the six selected members P, Q, R, S, T, and U to
level will continue to elude him. portfolios of Home, Power, Defense, Telecom, and Finance.
Which of the statement (s) below is/are logically valid and U does not want any portfolio if S gets one of the five. R
can be inferred from the above passage? wants either Home or Finance or no portfolio. Q says that if
I. He was already a successful batsman at the highest S gets either Power or Telecom, then she must get the other
level. one. T insists on a portfolio if P get one.
II. He has to improve his temperament in order to become Which is the valid distribution of portfolios?
a great batsman. (a) P – Home, Q – Power, R – Defense,
S – Telecom, T – Finance
SOLVED PAPER - 2015 2015-31
be the set of all elements in T which are not in R. Which one QUESTION 36 TO 65 CARRY TWO MARKS EACH
of the following is true? 36. Consider the following C program:
(a) " X Î U (|X| = |X'|) # include<stdio.h>
(b) $ X Î U $ Y Î U (|X| = 2, |Y| = 5 and X Ç Y = 0) int main ( )
(c) " X Î U " Y Î U (|X| = 2, |Y| = 3 and X / Y = 0) {
(d) " X Î U " Y Î U (X/Y = Y'/X') int i, j, k = 0;
33. In a room there are only two types of people, namely Type 1 j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
and Type 2. Type 1 people always tell the truth and Type 2 k –= – –j;
people always lie. You give a fair coin to a person in that for (i = 0; i < 5: i++)
room, without knowing which type he is from and tell him to {
switch (i + k)
toss it and hide the result from you till you ask for it. Upon
{
asking, the person replies the following
case 1:
“The result of the toss is head if and only if I am telling the truth.”
case 2: printf (“\ n%d”, i+k);
Which of the following options is correct?
case 3: printf (“\n%d”, i+k);
(a) The result is head
default: printf (“\n%d”, i+k);
(b) The result is tail
}
(c) If the person is of Type 2, then the result is tail
}
(d) If the person is of Type 1, then the result is tail
return 0;
34. Consider a software project with the following information
}
domain characteristics for calculation of function point metric.
The number of time printf statement is executed is ______.
Number of external inputs (I) = 30
37. Suppose Xi for i = 1, 2, 3 are independent and identically
Number of external output (O) = 60
distributed random variables whose probability mass
Number of external inquiries (E) = 23
functions are Pr[Xi = 0] = Pr[Xi = 1] 1/2 for i = 1, 2, 3.
Number of files (F) = 08
Define another random variable Y = X1 X2 Å X3, where Å
Number of external interfaces (N) = 02
denotes XOR. Then Pr[Y = 0|X3 = 0] = ______.
It is given that the complexity weighting factors for I, O, E,
38. If the following system has non – trivial solution
F and N are 4, 5, 4, 10 and 7, respectively. It is also given that,
px +qy + rz = 0
out of fourteen value adjustment factors that influence the
qx + ry + pz = 0
development effort, four factors are not applicable, each of
rx + py +qz = 0
the other four factors have value 3, and each of the remaining
then which one of the following options is TRUE?
factors have value 4. The computed value of function point
(a) p – q +r = 0 or p = q = – r
metric is _______.
(b) p + q – r = 0 or p = – q = r
35. In a web server, ten WebPages are stored with the URLs of
(c) p + q +r = 0 or p = q = r
the form http://www.yourname.com/var.html; where, var is
(d) p – q +r = 0 or p = – q = – r
a different number from 1 to 10 for each Webpage. Suppose,
39. Language L1 is polynomial time reducible to language L2.
the client stores the Webpage with var = 1 (say W1) in local
Language L3 is polynomial time reducible to L2, which in
machine, edits and then tests. Rest of the WebPages remains
turn is polynomial time reducible to language L4. Which of
on the web server. W1 contains several relative URLs of the
the following is/are true?
form “var.html” referring to the other WebPages.
I. if L4 Î P, then L2 Î P
Which one of the following statements needs to be added in
II. if L1 Î P or L3 Î P, then L2 Î P
W1, so that all the relative URLs in W1 refer to the
III. L1 Î P, if and only if L3 Î P
appropriate WebPages on the web server?
IV. if L4 Î P, then L1 Î P and L3 Î P
(a) <a href: “http://www.yourname.com/”,
(a) II only (b) III only
href: “…var.html”>
(c) I and IV only (d) I only
(b) <base href: “http://www.yourname.com/ ”> 40. Consider the following partial Schedule S involving two
(c) <a href: “http://www.yourname.com/”> transactions T1 and T2. Only the read and the write
(d) <base href: “http://www.yourname.com/”, range operations have been shown. The read operation on data item
“…var.html”>
EBD_7203
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);
EBD_7203
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
EBD_7203
2015 -38 SOLVED PAPER - 2015
(SACK) mechanism, combined with a selective repeat 23. (b) X be an eigen vector corresponding to eigen value l =1,
retransmission policy, can help to overcome these then
limitations. The receiving TCP sends back SACK AX = lX Þ (A - I) X = 0
packets to the sender informing the sender of data that
has been received. The sender can then retransmit é0 -1 2 ù é x ù
ê0 0 0 ú ê y ú
only the missing data segments. ê úê ú =0
III: TCP work as a message stream. This is FALSE êë1 2 0 úû êë z úû
statement.
In TCP, Data is read as a byte stream, no distinguishing Þ – y + 2z = 0 and x + 2y = 0
indications are transmitted to signal message (segment) x
boundaries. Þ y = 2z and =y
-2
x x y z
\ = y = 2z Þ = = a(say)
-2 -4 2 1
18. (b) 71
æ -4ö
ç 2÷
84 Þ X = ç ÷ a; a ¹ 0
65 è 1ø
\ Eigen vector are {a (– 4, 2, 1) |a ¹ 0, a Î R|}
24. (c)
69 83
1 2 3 4 10
67
19. (b) X # Y = X¢ + Y¢ S
S1. L.H.S. R.H.S.
= (P # Q) # R P # (Q # R)
(P # Q)¢ + R¢ P¢ + (Q # R)¢ P
= (P¢ + Q¢)¢ + R¢ P¢ + (Q¢ + R¢)¢
= PQ + R¢ P¢ + QR After *P = '0', array will become
PQ + R¢ ¹ P¢ + QR
Hence S1 is false
S2. Q # R = Q¢ + R¢ ...(I) 1 2 0 4
R # Q¢ = R¢ + Q¢ = Q¢ + R¢ ...(II)
I and II both are equal. Therefore, S2 is true
20. (c) X = sum of the cubes of first n natural numbers
n 2 (n + 1)2 S
= which is q(n4), O (n5) & W (n3).
4
21. (d) Number of processes which are in running processes and we are pointing string S which is 1204.
will be atmost n as there are n processors. Maximum
number of processes that will be in ready state is 6
independent of number of processors. 5 60 60 10
25. (c) 10 10 15 15 15 15
22. (a) 4 12 4 Þ E 201 F
10 5 + 60 6
cache cache
word word
TAG block TAG block
offset offset 8
offset offset
150 150 142
* 8 –
EBD_7203
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.
In for loop:
vertices be ‘p’ then the tree has
When i = 0; 1 time printed (– 1)
(i) ‘p’ vertices of degree ‘1’
When i = 1; 1 time printed (0)
(ii) one vertex (i.e. root of T) of degree ‘2’.
When i = 2; 3 times printed (1, 1, 1)
(iii) 'n – p – 1' vertices of degree ‘3’
When i = 3; 3 times printed (2, 2, 2)
(iv) 'n –1' edges
When i = 4; 2 times printed (3, 3)
\ By Handshaking theorem,
\ on the whole printf is executed 10 times
p × 1 + 1 × 2 + (n – p –1)×3 = 2(n –1) 37. 0.75
Þn=2p–1 Given X3 = 0
= 399 as p = 200 \ Y = X1X2 Å X3 = 0 gives X1X2 = 0
\ Number of nodes having exactly two children are Þ X1 = 1, X2 = 0 or X1 = 0, X2 = 1 or X1 = 0, X2 = 0
n – p i.e., 199
Pr[Y = 0] Ç (x 3 = 0)]
30. (a) varP = varQ = FALSE Initially. \ Pr [Y = 0|X3 = 0] =
Assume that, process X is willing to enter into critical Pr(X3 = 0)
section. So it makes varP = True, then if processor
Pr[X1 = 1, X 2 = 0, X 3 = 0] + Pr[X1 = 0, X 2 = 1, X 3 = 0]
switches to process Y, then process Y can enter into
critical section. = + Pr[X1 = 0, X 2 = 0, X 3 = 0]
Pr[X3 = 0]
After entering into the critical section, then if processor
switches to process X, then process X also can enter
1 1 1 1 1 1 1 1 1
into the critical section. . . + . . + . .
It is clearly showing that both are in critical section at = 2 2 2 2 2 2 2 2 2
1
a time which leads to “failing to guarantee material
2
exclusion” (Q X1, X2, X3 are independent)
To enter into the critical section process X is not waiting 3
for process Y and vice versa. So we can “Prevent = = 0.75
4
Deadlock” so, overall, option (a) is correct. 38. (c) For non-trivial solution, we have | A | = 0
31. (d) Give L = 1250 Bytes
B = 100 mbps p q r
d = 1km i.e., q r p = 0
V= ? r p q
d (C1 ® C1 + C2 + C3)
In CSMA/CD, L = 2 ´ ´B
v
1 q r
3
2dB 2 ´ 10 ´ 10 8 1 r p
(p + q + r) =0
ÞV= = Þ V = 20,000 km/sec 1 p q
L 104
32. (d) Counter example : [R2 ® R2 – R1; R3 ® R3 – R1]
(a) Let X = {1} Þ X¢ = S – X {2, 3, 4, 5, 6} Þ |X| ¹ |X¢| p+ q+r=0
(b) Since |S| = 6 and |X| = 5 = |Y| 1 q r
\ Atleast 4 elements common in X and Y 0 r -q p-r
(or) =0
Þ X Ç Y = f is false 0 p-q q-r
SOLVED PAPER - 2015 2015-41
(i) FcFs
Process AT BT LT TAT
A 0 3 3 3
B 1 6 9 8
Program Y : C 4 4 13 9
Cyclomatic complexity = 10 – 8 + 2 = 4 D 6 2 15 9
Program Z : 29
= 7.25
4
Gantt chart
X
A B C D
0 3 9 13 15
(ii) SJF
Y
Process AT BT LT TAT
Total number of edges = X+Y+1 Þ 20 A 0 3 3 3
Total number of vertices = 15 B 1 6 9 8
Hence cyclomatic complexity = 20 – 15+2 = 7 C 4 4 15 11
42. 175 Transmission time for 5000 bits = Time for 500 bits to D 6 2 11 5
5000 27
travel = = 50 microseconds = 6.75
107 4
Gantt chart
So, after 50 microseconds the packet is completely
transmitted. But the packet must reach at the other and A B D C
this happens exactly after propagation delay which is 9
0 3 11 15
20 microseconds. So, the switch receives packet after
50 + 20 = 70 microseconds. B- 6 C-9 D -2
EBD_7203
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 = 2 sec
p
v = 4 ´ 106 m / sïþ 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 é
\ ò f (x)dx = 2 2ë
a{ln x - 25x}12
1 a -b
ptr after ptr + + Þ ptr – p = 1
(pointer arithmetic)
üï ù
2
ptr ìï x 2
** ptr = 40 b
– í - 25x ý úú
\ printf ("%d%d", p + r – p, p + r) will print 140 îï 2 þï1 û
52. 158
Given IP address 200.20.11.144/27 é 1 ì3 üù
To find out the loss address in a block, we have to set = 2 ê a{ln 2 - 25} - b í 2 - 25ý ú
2
a -b ë î þû
(32–n) no. of right most bits to 1.
n = 27 1 é 47 ù
= 2 êë a{ln 2 - 25} + 2 búû
32 – n = 32 – 27 = 5 a - b2
200.20.11.10010000 57. 995
200.20.11.10011111 G has 100 verticles Þ spanning tree contain 99 edges
200.20.11.159 given, weight of a minimum spanning tree of G is 500
\ CIDR Address range is 200.20.11.128/27- since, each edge of G is increased by five
200.20.11.159/27 \ Weight of a minimum spanning tree becomes
But w.r.t the question, the value of the last octet of last 500 + 5 × 99 = 995.
host in this network is 200.10.11.158. 58. (b)
53. 230 g(6)
01 1 1* 0 1* g(0) g(–2)
11 Total calls = 25
0 0 0 0
59. (a)
10 0 0 0 1* 60. (c) Since p – q ¹ q – p
\ (p, q) R (p, q)
Þ R is not reflective
There are three groups, and all the containing esential- Let (p, q) R (r, s) then p – s = q – r
1, so all are prime implicants as well as essential prime Þr–q=s–p
implicants also. Þ (r, s) R (p, q)
55. (c) Þ R is symmetric
EBD_7203
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
PART-A : VERBAL ABILITY
1 English Grammar
Articles - Kinds, Usage & Common Errors in their uses 2. When the word begins with a silent letter ‘h’.
An article is a word that is added to a noun to indicate – the type · an hour, an honest man, an honour, an heir (= a person
of reference being made by the noun. It’s a kind of adjective who inherits money etc., when someone dies)
which gives some information about a noun. 3. With abbreviations said as individual letters that begins with
The word ‘a’ (becomes ‘an’ when the word that follows begins A, E, F, H, I, L, M, N, O, R, S or X:
with a vowels - a, e, i, o, u) is called the ‘indefinite article’ because · an MLA, an FBI agent, an MP, an x-ray, an MA. However,
the noun it combines with is indefinite or general. The word ‘the’ the abbreviations said as words are exceptions.
is called the ‘definite article’ as it indicates some specific thing
· a NATO general, a FIFA officials
· I went by a car.
· I went by the car. We use, ‘The’:
The above two sentences differ since in the first sentence I went 1. When we say that someone or something is ‘unique’ – that
by just any car while the second sentence refers to a particular car there is only one or only one of its kind – (we also use zero
and not just any car. article, i.e., no article, but not a/an):
We use ‘A’: · Cricket has become the international sports.
1. When a word begins with consonant sound · Sydney is the capital city of New South Wales.
· a book, a cat, a chair 2. When we refer to a person’s job title, or their particular
2. When a word begins with a vowel but has a consonant sound position.
· a university, a one parent family, a Europian · Bob has been appointed as the director of the company.
3. With words that have the sense of one Sometimes ‘the’ is omitted which is called ‘zero article’.
· The culprit could not speak a word before the judge. 3. Before a superlative adjective (the largest, the cheapest, the
4. With abbreviations said as words. most beautiful, etc.) when the superlative adjective is followed
· a NATO general · a FIFA official by a noun or defining phrase:
5. We use ‘a’ not ‘one’ when we mean ‘any one of a particular · He is the best player in the team at the moment.
type of thing. · His comment was the most awkward in the meeting.
· I really need a cup of tea. (not ... one cup of tea)
However, often ‘The’ is left out, particularly in an informal
· You can never find a mosquito in this house. (not ... one
style, when there is no noun or defining phrase after the
mosquito)
superlative adjective.
6. With number and quantity expressions such as:
· Mr X: Why did you plan to go to Manali?
· two times a year, a quarter of a litre, a day or so.
· ` 100 a kg. (we can also say ‘....’ for one kg.) · Mr. Y: It was (the) coldest.
· a little sugar, a huge number of people, a few artistes] 4. When we know that there is only one of a particular thing.
7. Rather than ‘one’ in the pattern a .... of ..... with possessives, · the earth, the sun, the world, the international market,
as in the film industry, the south pole, the nuclear family.
· He’s a friend of mine. 5. When refer to the things in a general way:
· That’s a relative of my friend. · the environment, the climate, the human race, the wind,
8. With exclamatory expressions the future, the weather, the atmosphere, the ocean, the
· What a wonderful car!, what a good boy he is! sea. However, if we describe them for a particular instance,
9. With a person’s name who may be unknown to the person we use a/an and not ‘the’, compare.
addressed. · I could hear the wind whistling through the trees in the
· A peter wants to speak to you on the ‘phone’. forest.
We use ‘An’: · There was a cold wind blowing from the East.
1. When, the noun you are referring to begins with a vowel · What do you plan for the future?
(a, e, i, o, u) · She dreamt of a future where she could spend more time
· an orange, an egg, an idea, an umbrella, an Italian. with him.
EBD_7203
S1-2 GENERAL APTITUDE FOR GATE
6. When we expect the listener or reader identifies the thing or (i) Ordinals
person we are referring to, on the other hand, a/an is used · She was the first to come to the party
when we don’t. Compare the following pairs of sentences. (j) Comparatives
· Wilson bought a house in Lincon Street last month and · He is the smarter of the two brothers.
· Wilson bought the house in Lincon Street last month (k) Adjectives with plural nations indicating a whole class
(= the house we have previously known) of persons:
· A minister has been expelled from the house and · The poor are not always despondent.
· The minister has been expelled from the house (= the However, ‘the poor men are not always despondent’ is
minister we have previously known) wrong.
· There’s a train coming and (l) Common noun as a substitute for the possessive
· The train is coming. (= it’s the train we are talking about) adjective:
· There is a man on the door and · Bob stared at Rick in the face. (Rick’s face)
· There is the man on the door. (= You know which man I (m) Noun defined by adjectives or adverbial phrases or
am talking about) clauses:
· He proved himself to be the dark horse of this
7. When it is clear from the situation which person or thing we
election.
are referring to.
(he was not well known but won unexpectedly)
· What do you think of the carpet? (= the carpet is lying
· She was runner-up and got the red ribbon.
before us)
(= she came second-place)
· How did you prepare the broth? It tastes good (= the
(n) Adjectives and common nouns in the singular form
broth I am just eating)
expressing an abstract idea:
· The plants are blooming now that it’s spring. (= the plants
· Nobody knows about the future. (= futurity)
here in the garden)
· The man in him prevented him from running away
8. When we repeat something about something:
from the accident spot. (= manly feelings)
· Bob ordered a cake and an apple pie but the cake was
found to be stale. In the sentence, we say a ‘cake’ when NOUN: COUNTABLE AND UNCOUNTABLE,
we first mention it and ‘the cake’ after that, when the GENDER AND CASES
listener knows which cake we are talking about. A noun is a word that can be used to refer to a person, place,
· There was a severe fire in a building in Connaught place thing, quality or action. It can be a subject or an object of a verb.
yesterday. The building was totally destroyed. They can be modified by an adjective and can take an article or
Here again, we say ‘a building’ when we first talk about it. determiner.
We use ‘the building’ when we mention it again because the Nouns can be categorized as countable or uncountable. Here are
listener will know which building we are talking about. some nouns which are normally uncountable, though in many
9. With the names of: other languages they may be countable:
(a) Religious books · Apart from going to work, there’s lots of housework to do
· the Bible, the Vedas, the Ramcharitmanas, the Kuran. for Kiran.
(b) Mountains, Islands, Oceans, Rivers · She wore her jewellery and get ready for the party.
· the Himalayas, the Pacific, the Ganges, the Bay of Some more nouns like this:
Bengal, the Arabian Sea, the Indian Ocean
(c) Religious groups furniture, homework, information, luggage, money, news,
· the Hindus, the Sikhs, the Mohammedans, the scenery, transport, weather, work accommodation, assistance
Parsees evidence, fun, harm, health, housing, advice, applause, baggage,
equipment leisure, litter, luck, machinery, money, mud, music,
(d) Names of law enforcing agencies
nonsense, parking, pay, permission, photography, poetry,
· the CBI, the FBI, the ISI, the Navy, the Air Force.
pollution, produce, progress, publicity, safety, rubbish, research,
(e) Press, clubs, foundations etc.
shipping, sightseeing, violence, undercover, sunshine.
· the PTI, the Rotary Club, the NCC.
(f) Nationalists Some common errors in use of nouns:
· the Indians, the Americans, the Chinese, the (i) Nouns which take a plural verb:
Norwegian · Her all belongings were scattered in all over the place.
(g) Historical events, empires or dynasties. · She sent him her sincere congratulations on his marriage.
· the Tughlak Dynasty, the Second World War, the · She saves half of all her earnings every month.
Non-cooperation Movement, the Mughal Period, · He lives on the outskirts of Mumbai. ( = outlying areas
the Chinese Revolution. of a city or town)
(h) Trains, aeroplanes, ships (ii) Other nouns like these include:
· The Sub-way train, the Rajdhani, the Lufthansa clothes, goods, particulars, premises (= building), riches,
Cargo, the Kingfisher, the Air India. savings, stairs, surroundings, thanks.
ENGLISH GRAMMAR S1-3
(iii) The nouns police, people, cattle, staff, artillery always have Important Tips to Remember
a plural verb. The noun whereabouts can be used either a
(1) Singular pronouns with singular antecedents and plural
singular or plural verb.
pronouns with plural antecedents.
(iv) Some nouns always end in –s looking as if they are plural
Singular
but when we use them as the subject, they take a singular
· The man finished their work quickly... (incorrect)
verb.
· The man finished his work quickly... (correct)
· The news of Princess Diana was greatly exaggerated.
Plural
(v) Other words which confuse include:
· The men finished their work quickly. (correct)
· She doesn’t have a means of control over the company
· The men finished his work quickly. (incorrect)
she inherited.
(2) Collective Noun Antecedents
· Politics is not his cup of tea. He is better off in acting.
Students often use a collective noun antecedent when the
· Statistics was always her worst subject.
group members are considered a unit. Here are the examples:
Some more words: economics, linguistics, mathematics, · The construction crew started their project last year.
phonetics, physics, gymnastics, athletics, diabetes, measles,
(incorrect)
rabies etc. are singular but seem to be plural.
· The construction crew, started its project last year. (correct)
(vi) Nouns used as singular and plural but with different meanings
However, when the group members are taken individually,
· Fish (collectively): There are not many fish in this pond.
the plural pronoun is used.
· Fishes (separate fishes): Barry cooked all the four fishes · The construction crew, some of them not happy with
for dinner.
working conditions, gathered its tools. (incorrect)
· Cloths (kinds or pieces of cloth, not made up into
· The construction crew, some of them not happy with
garments) – she cut all cloths into pieces.
working conditions, gathered their tools. (correct)
· Clothes (garments): I sent all the clothes to laundry.
(3) Gender Errors in Pronouns
Pronouns – common errors in their use He and his were traditionally used to refer to both sexes
A pronoun is a word that takes the place of a noun. Pronouns are when the antecedent was unknown. Now, in modern times, it
used to avoid repetitive use of the same noun within a sentence is fell that this usage is unfair to women, so one male pronoun
or narrative. The following is an example without the use of is avoided.
pronouns: · Each person has to face his fear of wild animals in the
· We invited Kapoors to our party because we like Kapoors. jungle. (Singular)
The sentence would sound better if a pronoun were introduced · All persons have to face their fear of wild animals in the
· We invited Kapoors to our party because we like them. jungle. (plural)
Problems with Interrogative pronouns usage · Each person has to face his or her fear of wild animals in
Interrogative pronouns are the most troublesome area for students. the jungle (he or she)
The most common errors the students make with their usage are (4) When two nouns are joined with ‘as well as’ then pronoun is
who and whom. Who is used for the subjective case while whom used in agreement with the first subject.
for the objective case. · Peter as well as his friends is going on picnic.
In Questions: Subjective: · The students as well as their teacher were present in the
· Whom frightened the baby? (incorrect) function.
· Who frightened the baby? (correct) (5) When two nouns are joined with ‘with’ then the pronoun is
In Questions: Objective: used in agreement with the noun before ‘with’.
· Who did the dog scare? (incorrect) · The boy with his classmates
· Whom did the dog scare? (correct) · The boys with their teacher
Now, use the pronoun ‘who’ in a question when it takes the place You can notice that in both sentences the usage of ‘his’ and
of the subject and use ‘whom’ when it takes the place of object. ‘their’ is in agreement with number and gender of the second
Use of pronoun in Dependent Clause noun.
If you want to avoid errors in choosing the correct pronoun, first (6) When a subject is made up of two or more items joined by
identify the clause, then determine the function of pronoun in the ‘either .........or’ or ‘neither.... nor’, a singular verb is used if
respective clause. If it acts as the subject, use, who (whoever), if it the last item is singular and a plural verb if it is plural.
acts as the object, use whom (whomever). However, in informal English, sometimes a plural verb is used.
· Subjective: I saw who scared the dog. · Either your brother or you have eaten your lunch.
Here the pronoun is taking the place of the subject. Who is used. · Either the teachers or the principal is (or are) is blame
· Objective: I saw the man whom the dog scared. for the poor results.
Here the pronoun is taking the place of the object. Whom is · Neither the prime minister nor his spokespersons are to
used. address the press.
EBD_7203
S1-4 GENERAL APTITUDE FOR GATE
A Quick Review Remember
· They went to Paris and enjoyed (incorrect) A preposition may also be used at the end of a sentence:
· They went to Paris and enjoyed themselves (correct) · Who were you talking to?
· You should avail of this opportunity (incorrect) · This is the house I used to live in.
· You should avail, yourself of this opportunity (correct) Preposition can also govern other parts of speech that are used
· You and Bob have wasted their time. (incorrect) as nouns.
· You and Bob have wasted your time (correct) · She left India for good.
· Marbella and myself went to the pictures (incorrect) · In short, we don’t want to do anything with them.
· Marbella and I went to the pictures. (correct) · From here you can go to Istambul by air.
· I, you and he will go to the pictures tomorrow. (incorrect)
· You, he and I will go to the pictures tomorrow. (correct) Position of Prepositions
· It is me. (incorrect) Prepositions of place
· It is I. (correct) At is used about a place we think of as a point rather than an area.
· Let him and I do the talking. (incorrect) We also use at about are event wherethere is a group of people.
· Let him and me do the talking. (correct) · I arrived at Howrah station at 5.
· After seeing his father in the bar, he tried to hide behind the · I last met her at her sister’s birthday.
table. (incorrect) · They were waiting at the far end of the room.
· After seeing his father in the bar, he tried to hide himself · There were a number of people at the conference.
behind the table. (correct) On is used when we talk about a position touching a flat surface,
· Peter resigned to the will of God. (incorrect) or on something we consider as a line such as a road or river.
· Peter resigned himself to the will of God. (correct) · There’s a cockroach on the floor.
(Please note that after verbs like absent, avail, apply, enjoy, hide · They have bought a villa on the beach.
etc. reflexive pronoun is used after them) In is used when we talk about a position within a larger area, or
· They have visited neither of these three Churches. (incorrect) when it is within a larger space.
· They have visited none of these three Churches. (correct) · He works at Connaught place in Delhi.
· Between you and I, he is not reliable. (incorrect) · Bob looked again in the drawer and found the punching
· Between you and me, he is not reliable. (correct)
machine.
· He scored better than me in the exams. (incorrect)
Prepositions of Direction
· He scored better than I (did) in the exams. (correct)
To, towards, across, for, against, along, up, down, into etc. are
· We all did not accept his offer. (incorrect)
called prepositions of direction.
· None of us accepted his offer. (correct)
To is used to denote destination
· These two brothers always help one another. (incorrect)
· I am going to railway station.
· These two brothers always help each other. (correct)
· The four sisters help each other with chores. (incorrect) Towards indicates direction.
· The four sisters help one another with chores. (correct) · He was last seen going towards the hotel.
· One must keep his word. (incorrect) For denotes destination.
· One must keep one’s word. (correct) · He is leaving for Canada tomorrow.
· None of us know the truth. (incorrect) Against refers to ‘opposite’, ‘pressing on’, ‘in contravention of’.
· None of us knows the truth (correct) · It was very difficult to run against such strong winds.
· Except he, all went to the circus. (incorrect) · There used to be a lamppost against the wall here.
· Except him, all went to the circus. (correct) · You cannot go against the law of the land.
· It is All India Radio. (incorrect) Across denotes ‘on the opposite side of’, ‘from one side to
· This is All India Radio. (correct) another’, ‘both sides’, ‘through’
Prepositions - Important Inferences and Common Errors in ‘their’ · The man who came to see you yesterday lives across the
usages. road.
A preposition is a word which usually precedes a noun or pronoun · This metro station is being built across the river.
and shows its relation to some other word in the sentence. · She put the scarf across her neck.
· The man on the platform was staring at Gina. · The cattle were going across the field.
· They came after dinner. ‘Come across’ is used when we mean ‘to find’ or ‘encounter’
· The cat is sitting under the table. · She came across this man when she was working in US and
In the first example ‘on’ and ‘at’ are two prepositions, which are then they got married.
before the definite nouns ‘platform’ and ‘Gina’. They help establish Up denotes top and down is used to mean ‘descending’.
the relationship between ‘the man’ and ‘the platform’ and ‘stare’ · The child climbed up the stairs by himself.
and ‘Gina’. · The child could not climbed down the stairs.
ENGLISH GRAMMAR S1-5
Prepositions of Time Absolve from: He has been absolved from all charges.
At, on, for, before, after, since, within, till, by, during, from are Replete with: His condition is replete with misery.
some examples of prepositions of time. Look at: He was looking at all pros and cons.
‘At’ denotes time or hour. Square with: I paid him ` 10,000 and squared with him.
· I’ll be there at 2 = 30. Put out: She put out the lights and went to sleep.
· They started for outing at down. Sue for: you can be sued for contempt of court.
· The accident occurred at daybreak. Side with: He sided with the ruling party.
‘On’ is used to denote ‘day’ and ‘date’. Take up: She has taken up the matter with higher-ups.
· She’ll be here on Saturday. Conjunctions – Their usages and Errors in their uses
· This road will be opened for public on 15th August. A conjunction is a part of speech which is used to correct words,
‘For’ is used to denote ‘period of time’. phrases, clauses, and sentences. They are such as, and, because,
· I had been waiting for the train for two hours. or, if, but, for and when.
· What are you waiting for? Here are some important conjunctions and their uses:
‘Since’ is used to refer to ‘a point of time’ Not only........... but also
· She has been living in UK since 2003. · He is not only the director but also the producer of this
· He has been living in this village since birth. movie.
‘After’ and ‘before’ are used with the ‘period of time’ or ‘point of Either........... or
time’ in past tense. · Either the teachers or the principal is (or are) to blame for the
· Our exams will be over before Christmas. mishap.
· She will get married after she completes her graduation. Neither........... nor
· He will return the loan to me after 2 years. · Neither the prime minister nor the ministers are responsible
Some useful Prepositions after verbs for economic slowdown.
Abstain from: Having been advised by the doctor, he vowed to Both.......... and
abstain from alcohol. · He can both speak and write French.
In accordance with: Everything has been done in accordance · He’s lived in both Mumbai and Chennai.
with your request. · Both he and his sister are going to get married this winter.
Learn about: We learnt about o-zone when were in school. Scarcely/hardly .... when
Know about: Now everybody knows about black holes. · He had scarcely left when the rain started.
Think of: What do you think of my new suit? (ask for an opinion) · He had scarcely sat down when the phone rang.
Think about: Your job is think about safety and nothing else. Though/Although
(concentrating on something) · Though/Although Mahesh failed to score a goal himself, he
Accuse of: He was accused of spousal abuse. helped Rajesh to score.
Acquaint with: You should acquaint yourself with new gadgets. · He has bought a house, though/although he has yet to make
Acquit of: He has been acquited of all charges. the payment.
Apprised of: Has the management been apprised of the strike? Both ‘though and ‘although’ may be used but ‘though’ is less
Ashamed of: You should be ashamed of these poor results. formal. No sooner had/did .... than.
Clamp on: The dictator clamped a curfew on the town. · No sooner had he entered the room than the light went out.
Conducive to: the working conditions are not conducive to · No sooner did he pick up the newspaper to read than his
productivity. father called out.
Confer on: The university conferred a degree on him. Lest .............should
Cope with: She cannot cope with the new environment. · He turned away from the door lest the boss see him.
Detrimental to: This kind of lifestyle is really detrimental to his · He worried lest he should fall short of family’s expectations.
health. (Please not that lest is negative, hence cannot be followed by not.
Debar from: He was debarred from school for his bad behaviour. It is followed by should).
Desist from: If you do not desist from your activities, you may be Other than
behind bars. · He was familiar with no one other than the watchman.
Encroach on: He has encroached on the public property by · He doesn’t like milk, but other than that he’ll drink just
building a concrete wall. anything.
Embroil in: Please do not embroil me in this controversy. So..........as (in negative sense)
Fed up with: He is fed up with her constant tauntings. · She did not collect so many flowers as her sister did.
Focus on: Now all the players have to focus on the game, other · You cannot drive so far as you want. There’s not enough
issues will be sorted out later. gas.
Give in: Finally, I had to give in to the temptation. as..........as
Good at: She’s is very good at dancing. · The kids want to stay with their grandparents as much as
Indulge in: Sometimes you have to indulge in the children. she does.
EBD_7203
S1-6 GENERAL APTITUDE FOR GATE
· The elderly woman cannot walk as fast as she used to Errors ‘in’ Subject Verb Agreement
Such...........as Now let’s discuss the different conditions in which subject agrees
· Such lodging as you provided was hardly worthy of living. with verb.
· There is no such thing as magic. If two singular nouns are joined with and, then the verb is plural.
Like................(pronoun/noun) · Marbella and her husband have gone to Paris.
· No one else can sing such a difficult song like he can. · A computer and a printer have been sold in the junk market.
· You are just talking like a child. If two singular nouns are joined with ‘and’ but preceded by each/
If ............. (used when talking about something that might happen every etc. then it takes a singular verb.
or might have happened or be true) · Each boy and each girl has to join the NCC.
· We’ll all go to the pictures if father gives the money. · Every worker and every executive has to be in the office in
· If you didn’t apologize, you’d feel guilty. time.
· If you had come earlier, I would have accompanied you. If two singular nouns are joined with ‘and’ but denote something
· If mother were here, she would know what to cook. about the same person, thing or expression, then singular verb is
Whether .......... or not (used when talking about a choice) used.
· I am not sure whether to believe him or not. · Bread and butter is not something that you take in dinner.
· I am taking the kids along, whether you like it or not. · Rice and rajma sells at 30 rupees per plate.
· She doesn’t know whether to stay or leave. Other examples are – horse and carriage, hammer and sickle, crown
Reason ............. that (‘the reason for something’ is used and not and glory etc.
‘the reason because ‘something happens) When two nouns or pronouns are joined with – with, alongwith,
· I’d like to know the reason why they refused to follow the together with, accompanied by, led by, guided by, governed by,
orders. controlled by, as well as, in addition to, besides, like, unlike etc.
· The reason I telephoned was to ask about her health. then the verb is according to the noun or pronoun shown in the
Because (used when you are giving reason for something. first case.
· We didn’t go out because the weather was so dull. · She was accompanied by her mother.
· Why can’t she go to the cinema? Because she’s not old · The council was led by the minister.
enough. · She is clever as well as beautiful.
In order to do something (used for the purpose of doing something) · He hurt his arm as well as breaking his leg.
· Bob is working very hard on his maths in order to improve · In addition to cooking the food, she has to clean the floors.
his grades. · Besides myself, the only Indian people there were Sachin
Until (used to denote when something happens until a particular and his wife.
time, it continues and then stops at that time). · Her hair is blonde like her mother.
· Your driving licence is valid until 2018. · Unlike her mother, she doesn’t go to market every Sunday.
· I waited until mother finished cooking. When two subjects are joined by ‘not only....... but also’, ‘either
Till (In spoken English ‘till’ is preferred to ‘until’) ......... or’, ‘neither....nor’, then the verb always follows its nearest
· He didn’t start drinking till he was 30. subject.
· This market opens till 9’O’ clock on all days. · He is not only an actor but also a dramatist.
As long as (used to talk about one thing that can happen or be · He’s the kind of person you either love or hate.
true only if another thing happens or true). · Neither she nor her mother is planning to go Italy.
· You can stay with us as long as you desire. When subjects are joined with ‘not....but’ or ‘not’, then the verb
· They tried to stay awake for as long as they could. follows the subject which is not with the subject ‘not’.
Verb Agreement – Rules, Syntax of Subject · Not the principal but the teachers are to blame.
· The principal not the teachers is to blame.
Verb agreement works on two basic rules:
When in a sentence, ‘each of’, ‘either of’, ‘neither of’, ‘everyone of’,
Rule 1: When the subject is singular, verb is singular. ‘one of’, etc. are used, the noun or pronoun is always plurals, but
· She likes mangoes. the verb remains singular.
(Here the subject is singular, so the verb is also singular). · Each of the students has to take part in this program.
· Bob plays cricket. · One of them has been arrested by the police.
· Mr. Jim goes to office. · The teacher asked the students if everyone of them has
(‘you’ always take a plural subject). brought books.
Rule 2: When the subject is plural, the verb is also plural. When the subject of a sentence is ‘everybody’, ‘somebody’,
· They play cricket in this field every day. ‘nobody’, ‘anybody’, ‘no one’, ‘everyone’, ‘anyone’, ‘everything’,
(Here the subject is plural i.e., ‘they’ so the verb ‘play’ and not ‘something’, ‘nothing’, ‘anything’, etc. then the verb is always
‘plays’ is used) singular.
Basically, the number and person of any finite verb is in · Everybody knowns that the sun rises in the east.
correspondence with the number and person of the subject. · Someone among his friends has broken this window pane.
ENGLISH GRAMMAR S1-7
When the subject of a sentence is ‘many’, ‘both’, ‘few’, ‘a few’, · If you ask, I’ll accompany you to the movies.
etc. then the verb is plurals. When a sentence has expressions such as ‘suppose that’, It is
· Both Marbella’s parents are working with External Affairs. high time’, as if, it is time, etc’, a future or the present tense is not
· Many were trapped in the debris but a few have survived. used.
After ‘both of’, ‘a few of’, ‘few of’, ‘many of’, etc. the noun or · It is high time that you called his bluff.
pronoun is plural which is also followed by a plural verb. When a statement refers to two past actions, the action that
· Many of tourists at Taj are English. finishes first is in past perfect and that finishes later should be in
· A great many workers have gone on strike. simple past.
However, after ‘many a...’ both the noun and verb are singular. · They told him they had not met him before.
· Many a parent has gone through this awful situation. · We heard that a fire has broken out in the neighbouring
Nouns in plural that represent an amount, a fraction, or an element house.
of time are taken as singular and so take singular verb. When a part of the sentence is with ‘as if’ or ‘as though’, past
· Thirty minutes is not enough to finish this test. tense and plural form of the verb is used.
Some words that end in – s and seem to represent a single thing · He behaved as if he were the owner of the house.
but they take plural verb. · It looks as though everyone else has gone to bed.
· The scissors have to be brought from the market. Words like ‘often’, ‘generally’, ‘usually’, ‘whenever’, whichever’,
· My trousers are too short to fit. etc. are used in simple present tense.
· The spectacles have been broken by the child.
· This type of furniture is generally found in junk market.
Words ‘like’, ‘fleet’, ‘crowd’, ‘army’, ‘jury’, ‘committee’ always
· I often go to meet him.
take singular verbs.
· He usually goes for a walk after dinner.
· The committee has not decided on his proposal yet.
· The crowd is increasing in the city day-by-day. Some Important Tips:
TENSES AND ERRORS IN THEIR USAGE ® Please note that except I, we and you, all nouns and pronouns
fall into the category of third person.
The tense is the form of a verb that shows the time, continuance
® Conditional clauses may be put in three categories.
or completion of an action that is expressed by the verb. ‘He is’ is
1. Main clause - future, “if” ....... present (likely or probable)
in the present tense, ‘He was’ is past tense and ‘He will be’ is
future tense. · He will help you if you ask him.
When ‘a permanent state’ or ‘work at present’ is expressed. 2. Main clause - conditional, “if”... past (unlikely, imaginary)
· He lives in Mumbai. (Presently living) · He would help you if your asked him.
· His father works in a government department (Presently 3. Main clause - conditional, perfect “if”... past perfect
working) (Impossible)
To express a present habit. · He would have helped you if you had asked him.
· He goes for a walk everyday. GERUND AND INFINITIVE - Usage and Errors in
· She takes a bath before breakfast. their uses
· He smokes after dinner.
Gerund is a noun in the form of present participle of a verb, for
(All these activities are a habit with are a daily routine).
example ‘Fishing is my best pastime. While ‘infinitive’ is the basic
When the verb in principal clause is in past tense, the verb of the
form of a verb which is used with ‘to’, for example - I want to meet
subordinate clause is also in the past tense.
you: In this sentence, ‘to meet’ is an infinitive.
· He went for a walk after he had taken his dinner.
When the subordinate clause is in reporting speech, any tense Usage of Gerund
can be used. Gerund acts as a subject when an action is being considered in
· She said, “I won’t stay at this place any more”. general sense.
When a universal truth or habitual truth is expressed, the tense in · Swimming is a sport.
subordinate clause is not necessarily changed. · Climbing mountains is a sport, too
· The teacher said that sun rises in the East. · Riding is pleasanter than walking.
· He said that he gets up at 5 everyday. · I hate telling lies.
If a comparison is made by using ‘than’, then in subordinate Verbs such as enjoy, excuse, suggest, help, avoid, dread, prevent,
clause, any tense may be used. risk, recollect, stop, detest, finish, mind, dislike, deny, no use, no
· She liked the commerce better than she liked the science. good, resent, delay, postpone, defer, forgive, pardon, etc. are
When there is an expression of past time (yesterday, two days followed by the gerund.
ago, last night, etc.), the present perfect tense is not used. · They enjoyed watching TV all day.
· I wrote to you yesterday about your mother’s ill-health.
· Will you excuse us coming late.
When the statement is conditional, the subordinate clause
· Will you stop talking so loudly.
beginning with ‘if’ may be in present or past tense but not in
· Would you mind moving a bit.
future.
· It’s no use asking them for a ticket.
EBD_7203
S1-8 GENERAL APTITUDE FOR GATE
· It’s no ‘good’ calling her at this hour. · I’d rather have a quiet night at my place.
A gerund is put after a preposition. · I’d rather fail than copy in the exams.
· They are tired of talking. After adjectives such as angry, glad, like, delight, astonished, the
However, prepositions ‘except’ and ‘but’ are an exception which infinitive is used.
are followed by an infinitive. · She was angry to see the children trampling on her flowers.
A gerund that shows a physical activity is placed after come and · I was glad to hear the news of your engagement with Sussane.
go. · I’d like to meet him when I am there next week.
· He went shopping. · She was astonished to hear the news of your success in
· They went boating. exams.
Nouns that are followed by a gerund are placed in the possessive The verb ‘know’ is not followed by the infinitive but a conjunction
case. and then infinitive.
· She hates her husband’s smoking while the kids are around. · She doesn’t know how to drive.
When there’s a sense of hesitation, dislike, risk, etc., the · Do you know how to talk with elders?
gerund is used. ‘........had better’ is followed by the infinitive without to’.
· I dislike his coming so late in the night. · You’d better leave this place before the police arrive.
· I cannot risk losing my purse in this jam packed bus. · You’d better stop drinking as your condition is deteriorating.
In possessive case, an adjective before gerund is put. When the verb of perception like ‘to see’, ‘to hear’, ‘to watch’
· She doesn’t mind their playing as long as they do not make occur in the sentence, infinitive is not used with ‘to’.
a noise. · I saw him climb the window.
Usage of Infinitive Split infinitive is not used.
· ‘He vowed not to go there’ and not ‘He vowed to not go
Infinitive acts as a noun, an adjective and adverb. there’.
Here are some verbs that are followed by infinitive – try, attempt,
care, decide, prepare, undertake, arrange, forget, agree, regret, Auxiliary Verbs
remember, promise, consent, neglect, swear, refuse, purpose, A verb that is used with another verb to form a particular tense or
endeavour, fail, hope, hesitate, determine, manage, seen, etc. mood, for example - she was pleased, they have left. Sometimes
· I tried to contact them several times. more than one auxiliary verb is used to form a tense, for example -
· I attempted to solve all these questions. She will be going, They have been warned. Auxiliary verb are
· Would you care to ask your help to hand over the keys to either modal verbs or primary verbs.
me. ‘Can’ expresses ability
· She was just preparing to go when father called. · You can drive, can’t you?
· I am sorry I forgot to post your letter. · She can speak French fluently.
· I regret to inform you to gramophone reached here broken. · The police are doing all they can to find the truth.
· She refused to pay head to my warning. ‘May’ denotes permission, doubt or possibility.
· He failed to response in affirmative. · You may be late, so call me tomorrow.
· I hesitated to ask her for the dinner. · These chemicals may cause irritation to your skin.
Some verbs like tell, oblige, permit, teach, advise, encourage, · Never mind, I may have been wrong.
request, remind, warn, order, invite, allow, compel, instruct, tempt, ‘Might’ also expresses possibility but you are not at all certain
urge, show, forbid, etc. are followed by object and infinitive. · The train might be a few hours late.
· The principal told the staff to stay back after school gets · They might not want to come with us.
over. · They might have missed the flight.
· Finally, he obliged to accept my offer. ‘Should’ is used to say what is the right thing to do.
· Will you permit me to go? · You should have taken her along. You should not be so
· The doctor advised him to take rest for a few days. selfish.
· She encouraged me to sit for this competition. · You shouldn’t come home after 12 in the night.
· He requested me to help the accident victim. · The children should not stay up late in the night.
· She forbade me to smoke in her office. ‘Could’ is used as past tense of ‘Can’ to express ability about
· They instructed us to sit outside the office. doing something in the past.
Verbs/expressions such as – do, can, will, let, may and must, etc., · By the time he was 12, he could drive the car competently.
are followed by infinitive without to. · I couldn’t catch the train as I was caught in a traffic jam.
· Let him play as long as he wants. · My income was so low that I couldn’t afford the rent.
The verb ‘see’ may be used infinitive or without it. ‘Must’ is followed by the bare-infinitive.
· Go see her or Go to see her. · You must hurry up if you don’t want to miss your train.
Expressions like ‘would rather’, ‘rather than’, ‘sooner than’, ‘had · She must wear the seat belt if she doesn’t want to be penalized.
better’ are followed by infinitive without to. · If you want to improve your grades, you must work hard.
· You had better inform the authorities in advance. ‘Must’ also expresses strong advice or orders.
ENGLISH GRAMMAR S1-9
· You must stop chewing tobacco if you want to avoid cancer. · The interior of the country is mainly desert.
‘Must’ is used to say that something is very likely to be true. After ‘Comparatively’ or ‘relatively’, the adjective of positive
· That elderly woman must be 90. degree is used.
· Their new bungalow must have cost them around `10 million. · Crime on the hill stations is comparatively scarce.
· She must have been really upset with her brother. · This software is relatively easy to use.
Should and ought have much the same meanings, but ‘ought’ is When ‘enough’ is used in a sentence, use positive degree.
followed by to, ‘Ought to’ is used to say that ‘someone should do · You would be foolish enough to lend him ` 10,000.
something because it is the best thing to do. · The car is big enough to accommodate eight persons.
· He really ought to stop drinking. ‘To’ is used after ‘prefer’, if there is comparison between two
· You ought to get together sometime soon. nouns or noun equivalents.
· He ought to be ashamed of himself. · She prefers tea to coffee.
When you talk about things which actually did not happen, though · I prefer to wear cotton clothes.
they were likely to- When adjectives are joined with ‘and’ then both the adjective
· You should have been here before 11. take same degree.
‘Do’ makes questions and negative forms of the ordinary verb. · bad and ugly woman (both positive)
· Do you like apples? · worse and uglier woman (both comparative)
· She doesn’t feel like going to cinema tonight. · worst and ugliest woman (both superlative)
· Does he speak Japanese? Yes, he does. To convert superlative degree into comparative and positive, some
‘Do’ is used to emphasize the main verb in a sentence. examples are given below.
· Do be alert. · Sachin is the best player in the team. (Superlative)
· She does look charming in that dress. · Sachin is better than all other players in the team. (Comparative).
· I do think the manager has behaved badly. Or
‘Do’ is also used with present participles ending in _ ing · Sachin is better than any other players in the team.
· She does shopping on Saturday. · No other player in the team as good as Sachin. (Positive)
· You just keep quiet. Let me do the talking. Synthesis of Positive degree and Comparative degree
Leaving out words after auxiliary verbs. · He is as good as you. (Positive degree)
· They say they’ve completed the work, but I don’t’ think · He is not better than you. (Comparative degree)
they have (instead of ...........have completed the work). It is, therefore, clear that for positive degree, ‘so/as.... as’ is
· Are you going to appear in the exams this year? Well, no, I’m used on the other hand, for comparative degree, ‘comparative
not (instead of .......I’m not going to appear in the exams). + than’ is used.
To avoid repeating words from a previous clause, we use an Some adjectives that confuse the most
auxiliary verb (be, have, can, will, would, etc.)
Each is used every one of two or more things or people.
Adjectives and Errors in their usage · Each student was given a particular job for gardening.
A word that names an attribute, used to describe a noun or · The tickets cost ` 250 each.
pronoun. · You give each of the children a balloon.
· A small child A tall man ‘Every’ used to refer to all things or people in a particular group
An adjective has three forms which are (a) positive e.g., cold · Every child will get his share of chocolates.
(b) comparative e.g. colder and (c) Superlative e.g. coldest. · She enjoyed every page of the novel.
Rules of Comparison · They applauded every word of the speaker.
‘Less’ defines’ ‘not so much or to a smaller degree.’
After adjectives such as junior, senior, superior, inferior, posterior,
· I hope you would worry less if you understood the case.
prior, etc, the preposition ’to’ is applied and not ‘than’.
· She is doing less talking lately.
· There are several students junior to him in the class.
‘Fewer’ represents a smaller number of
· We are in the same department, but he’s senior to me.
· Fewer trains are late these days.
· Your bike is far superior to mine.
· Fewer birds migrated here this year.
· He always felt inferior to his wife.
‘Older’ refers to persons or things.
Please note after these words ‘more’ or ‘most’ is not used.
· These plants are older than those in that garden.
· ‘There are several students more junior to him’ is wrong.
‘Elder’ is used of two people especially brothers and sisters
Words such as minor, major, interior, exterior are the adjectives of
· His elder son Sunny became an architect
positive degree. Hence, before them ‘more’ or ‘most’ and after
· Marbella is the elder of two.
‘than’ or ‘to’ is rarely used.
‘A little’ expresses a small amount.
· There is a major problem with traffic in Delhi.
· Marbella speaks a little Portuguese.
· Losing by eleven wickets was a major setback for the team.
· She’s a little over 3 years.
EBD_7203
S1-10 GENERAL APTITUDE FOR GATE
· I have a little time to spare. · very much stronger, very much better, very much wiser, etc.
‘Little’ represents only a small amount, not much (sense in negative) ‘Very and much’ are also used with superlative degree.
· There is little sugar left is the kitchen. · The very best gymnast in the country.
The little (that) is used to emphasize how small an amount there is · Much the best boy in the class.
· She did the little she could do. ‘Very’ is used before the present participle
‘Farther’ shows a greater distance then before. · very enjoying, very entertaining, very interesting, very
· We went hiking and decided not to go any farther. daring, very challenging, very perplessing etc.
‘Further’ means more or to a greater degree. ‘Much’ is used before the past participle.
· The minister refused to comment or recent developments · much surprised, much admired, much tired, much aggrieved,
until the evidence could be studied further. much ashamed, much amazed, etc.
‘Later’ defines after the time you are talking about Please note that ‘very’ is not used with a past participle
· I’m just travelling. I’ll call you later. except a few instances.
‘The latter’ is the second of two people or things. · very pleased, very frightened, very delighted, very dejected,
· In the latter case, you’ll have to pay on interest of 25%. very drunk, very contented, very limited, etc.
Adverbs and Errors in their usage ‘Quite’ (means perfectly, completely) is not used in place of ‘very.
An adverb is a word that qualifies the meaning of a verb, adjective · She is quite beautiful (×)
or another adverb She is very beautiful (P)
· She shook her head sadly. · The boss is quite busy (×)
In the example, ‘sadly’ is an adverb which tells the speciality
The boss is very busy (P)
of the verb ‘shake’.
· Bob is quite handsome. (×)
(i) Adverbs of time are – today, yesterday, ago, at present, last
Bob is very handsome. (P)
month, last year, presently, shortly, recently, lately, etc.
However ‘quite’ is used in the sense of ‘very’ with some past
(ii) Adverbs of numbers – once, twice, thrice, etc.
participles.
(iii) Adverbs of place – here, there, in, out, indoors, outdoors,
· Quite delighted (= very delighted)
far, near, away, etc.
(iv) Adverbs of quantity – too, very, much, enough, quits · Quite tired (= very tired)
completely, wholly, partially, fairly, rather, far, etc. ‘Quite’ is also used with positive degree.
(v) Adverbs of manner – Thus, so, carefully, badly, fluently, · quite well, quite wrong, quite chilly, quite warm, quite right,
etc. quite alone, quite cool, etc.
(vi) Adverbs of affirmation or Negation – Yes, no, surely, not ‘Plenty’ is followed by ‘of’
certainly, etc. · Drink plenty of water in summer.
Now, some important adverbs are explained here. · There’s plenty of time. So, don’t rush the things.
‘Too’ expresses ‘more than’ is acceptable or possible If the gender is not known, use the pronoun of masculine gender.
· Don’t you think the colour of your jacket is too bright · If anybody has got the book, he may return it by Monday.
‘Too ...... to do something’ ‘Both’ and ‘as well’ are not used together.
· She is too weak to climb the stairs. · Both Sussane and Rick have failed in the exams.
‘Too ..... for something’ ‘Supposing’ and ‘if’ are not used together.
· This box is too heavy for me. · Supposing, it really is a storm.
‘Much /far too’ · If that babysitter does not turn up, who will hold the baby?
· Sussane is far too young to go to school. ‘As ...........as’ is used with an adjective or adverb in between when
‘None too’ (not at all) we mean that something or someone is like something or someone
· He was none too pleased when he was told about new else, or that one situation resembles another.
developments. · The Charlie Chaplin movie was as funny as his last one.
‘Only too’ used to emphasize that a particular situation exists · He finished the job as quickly as he could.
when you wish against it. Negative forms may be used with either ‘not as’ or ‘not’so’
· The principal regretted is say that these rumours are only · The gap between two poles is not as wide as it was before.
too true. · The bees are not, so common as last summer.
‘Very’ is used with both pleasant and unpleasant adjectives. Adverb ‘not’ is not used with words that have negative sense.
· She’s very beautiful. · The doctor forbade him not to smoke. (incorrect)
· She’s very ugly. · The doctor forbade him to smoke. (correct)
‘Very’ is used with positive degree. ‘Only’ is to be positioned right before the word it modifies.
· very clever, very honest, very lucky, very good, very wise, etc. · He only bought two eggs. (incorrect)
‘Much’ is used with comparative degree. · He bought only two eggs. (correct)
· much stronger, much pleasenter, much better, much wiser, ‘Due to’ modifies a noun and not a verb. So no sentence should
etc. begin with ‘due to’.
‘Very much + comparative’ is used.
ENGLISH GRAMMAR S1-11
· He quit smoking due to ill-health. fear, shirk, resist, benefit, etc are not followed by any preposition
Perversion is used when the sentence begins with seldom, hardly, when used in the form of active voice.
barely, scarcely, never, etc. · I have to accompany her to the airport.
· Never have I seen such a bad movie. · She requested me to hire a taxi for her.
Provision is also used with expressions beginning with ‘No.... to · The chairman emphasised the need of improving safely
emphasize. standards.
· Under no circumstances, Will I accept his proposal? ‘Yet’ is used to express negative sense and questions whether
‘Cent percent’ and ‘word by word’ should be replaced with ‘a/ something that was expected has happened.
one hundred percent’ and ‘word for word’ · Have you finished ironing yet?
‘Needful’ means necessary, so ‘do the needful’ is incorrect. Instead · Has Sussane arrived yet?
use ‘do what is necessary’. · Have you finished talking on phone? ‘Not yet’.
‘Family members’ may be replaced with ‘members of the family’ · I haven’t asked her yet.
‘Talking terms’ should be replaced with ‘speaking terms’ The phrase ‘type of, ‘sort of’ and ‘kind of’ do not have a/ an with
· Dindsay is not on speaking terms with her father. them.
Verbs like ‘emphasis’ accompany, attack, discuss, fear, succeed, · What kind of question is that?
request, arsist, resemble, comprise, recommend, order, reach, join,
EXERCISE
Directions (Qs. 1-25) : In this section, you have to identify errors 7. (a) The boy was wearing a new suit
in sentences. Read each sentence carefully to find out whether (b) He took offence at this
there is any error in any of the parts. Errors, if any, are only in (c) Please put your sign here
one of the parts. No sentence has more than one error. When you (d) Please put your signature here
spot an error in any of the parts of the sentence. Choose the (e) No error
corresponding alphabet. 8. (a) He is my cousin brother
1. (a) The author mentioned that (b) We are all brothers
(b) there were many people (c) I spent the middle of the day working
(c) who were deprived of (d) He had a large amount of money
(e) No error
(d) a minimum basic facilities
9. (a) He got into bad company
(e) No error
(b) one of my servant tells me
2. (a) The child (b) had been a deaf
(c) some of any servants tell me
(c) since birth (d) no error.
(d) the front of the house
3. (a) Little knowledge
(e) No error
(b) of music that he possessed
10. (a) We were all very happy
(c) proved to be a boon for him
(b) at Mr. Khurana being awarded
(d) when he was utterly helpless. (c) the Nobel Prize.
(e) No error (d) No error
4. (a) The scenery here is not good 11. (a) He informed me
(b) I have lost my furnitures (b) that he had gone to
(c) We have received no information (c) one of the minister’s residences
(d) He told his mother this news (d) and stayed there all night.
(e) No error (e) No error
5. (a) Please excuse the trouble 12. (a) I had a bathe in the sea
(b) He took pains over his work (b) I have hurt a toa
(c) In India there are many poor (c) Each of these days we play games
(d) Scouts wear shorts (d) None of us went
(e) No error (e) No error
6. (a) In science the credit goes to a man 13. (a) This blade’s edge
(b) who conveniens the world (b) is sharper than any
(c) not to the man to whom (c) other blade’s said
(d) the idea first occurs. (d) the marketing executive of the company.
(e) No error (e) No error
EBD_7203
S1-12 GENERAL APTITUDE FOR GATE
14. (a) A man should work hard 27. Had I been a little early. I would not have missed the train.
(b) A man should not waste his time (a) Had I been a little early, I would not have missed the
(c) A boy should not waste his time train.
(d) Here is my cup, please fill it (b) Had I been a little early than now, I would not have
(e) No error
missed the train.
15. (a) The boy who does best he will get a prize
(b) whoever does best will get a prize (c) Had I been a little earlier, I would not have missed the
(c) Who did this? I train.
(d) He and I are brothers (d) Had I only been a little early than now, I would not
(e) No error have missed the train.
16. (a) The prize was (b) given to the girls 28. We were still talking about what we should do when we
(c) whom they said (d) stood first. heard the children shouting.
(e) No error (a) We were still talking about that we should do when we
17. (a) He did not like (b) me to smoking heard the children shouting.
(c) in the presence (d) of our teacher yesterday.
(b) We were still talking about what we should do when
(e) No error
18. (a) A student was we heard the children shouting.
(b) arrested for displaying (c) We were still talking about what we must do when we
(c) an indecently heard the children shouting.
(d) art work in public. (d) We were still talking about what we need to do when
(e) No error we heard the children shouting.
19. (a) He is worse than I 29. She is as intelligent as her sister if not more.
(b) A horse is more useful than a car (a) She is more intelligent than her sister.
(c) He gets a small salary (b) She is as intelligent as her sister if not more intelligent.
(d) In our library the number of books is less (c) She and her sister are equally intelligent.
(e) No error
(d) She is less intelligent than her sister.
20. (a) Open your book at page six
(b) He is in class ninth 30. The fees charged by the architect of the plans of the building
(c) This article costs ten rupees were unreasonable high.
(d) He came a second time (a) The fees charged by the architect of the plans of the
(e) No error building were unreasonable high.
21. (a) He is the more clever of the two (b) The fees charged by the architect of the plans of the
(b) he is the cleverer of the two building had been unreasonable high.
(c) from the three he is more clever (c) The fees charged by the architect of the plans of the
(d) of the two plans this is the better building were unreasonable higher.
(e) No error
(d) The fees charged by the architect of the plans of the
22. (a) He avoids (b) taking the
(c) prescribed medicine (d) at regular interval. building had been unreasonably higher.
(e) No error 31. You will not succeed unless you are optimistic.
23. (a) His good qualities include (a) You will not be successful unless you are optimistic.
(b) his ability to take (b) You will not succeed until you are an optimistic.
(c) quickly and (c) You will not succeed unless you don’t be optimistic.
(d) appropriate decisions (d) You will not succeed unless you don’t be and optimistic.
(e) No error 32. The implementation of the scheme encountered some
24. (a) The unreasonable behaviour problems because of some unscrupulously elements and
(b) of his daughter their vested interests.
(c) was thoroughly
(a) The implementation of the scheme encountered some
(d) upset Mr. Gupta.
(e) No error problems because of few unscrupulously elements
25. (a) Being a rainy day (b) Vijay decided to stay and their vested interests.
(c) at home and work (d) further on the problem. (b) The implementation of the scheme encountered some
(e) No error problems because of a few unscrupulously elements
Directions (Qs. 26-35) : Each question below has a sentence and their vested interests.
from the choices provided identify the one which best restates (c) The implementation of the scheme encountered some
the given sentence and mark its number as the answer. problems because of a little unscrupulously elements
26. Rajan abided by all the rules which was explained to him and their vested interests.
before programme. (d) The implementation of the scheme encountered some
(a) all the rules which was (b) all the rules which were problems because of some unscrupulously elements
(c) all the rule which were (d) all rules which was and their vested interests.
ENGLISH GRAMMAR S1-13
33. Despite being ill, he attended the classes. Directions (Qs. 46-50) : There are two sentences A and B are
(a) Despite of being ill, he attended the classes. given in each of the following questions.
(b) Despite his illness, he attended the classes. Mark (a) if you find an error in sentence A
(c) In spite of his being ill, he attended classes. Mark (b) if you find an error in sentence B
(d) The classes were attended by him in spite of being ill. Mark (c) if you find errors in both sentences A and B
34. He is as old as I. Mark (d) if you do not find any error in any of sentences.
(a) He is as old as me. 46. (A) A body of volunteers have been organized to help the
(b) He and I are equally old. faculty members in their attempt to raise the funds.
(c) He and I are equally older. (B) In our college, it was obligatory for each of the students
(d) Both he and I are of the same age. to buy his own instrument.
35. A man becomes wiser with age and experience. 47. (A) Most of the news pertaining to the sudden demise of
(a) A man as he is aged and experienced becomes the wiser. the spiritual guru have been communicated by some of
the ruffians whom I know well.
(b) A man with age and experience becomes wiser.
(B) Not only the doctor but also the nurses of this nursing
(c) A man as he is aged and experienced becomes the wiser.
home is very kind and helpful tot he attendants.
(d) With age and experience, a man becomes wiser.
48. (A) A few days before the general election, there were
Directions (Qs. 36-40) : Each sentence is divided into four parts reports that an amendment on primary education
(a), (b), (c), (d). Mark the part which has an error. Ignore the should be made compulsory in India?
errors of punctuation. (B) Nobody else but these comely young women have
36. (a) If I was you played a prank on you, but its is pitiable that you don’t
(b) I would have told understand it.
(c) the chairman to keep 49. (A) The lawyers face the same problems in their day to day
(d) his mouth shut lives as do an ordinary man of our society.
37. (a) You and I (b) am going (B) Some of highly significant observations has been made
(c) to take part (d) in the meeting by the UN Secretary General, Ban-Ki-Moon in his
38. (a) His behaviour with all his employees annual report submitted to the current session of
(b) is so pleasing that General Assembly.
(c) everyone come forward 50. (A) Not Vinay and his friends but Seema has surreptitiously
(d) to help him. taken your photographs and sent them to her friends.
(B) None of the six qualifiers who have been given a chance
39. (a) Scotsmen are notorious
to join this team play confidently.
(b) for their thrift
51. Choose the grammatically INCORRECT sentence :
(c) and he is butt
[GATE 2012, 1Mark]
(d) of many exaggerated jokes.
(a) They gave us the money back less the service charges
40. (a) The aeroplane is a
of Three Hundred rupees.
(b) powerful instrument of war (b) This country’s expenditure is not less than that of
(c) and their peacetime role Bangladesh.
(d) is just as important (c) The committee initially asked for a funding of Fifty
Directions (Qs. 41-45) : Given below are five sentences, each of Lakh rupees, but later settled for a lesser sum.
which may or may not have errors. (d) This country’s expenditure on educational reforms is
Mark (a), if there is only one error very less.
Mark (b), if there are two errors 52. Choose the grammatically INCORRECT sentence.
Mark (c), if there are more than two errors [GATE 2013, 1 Mark]
Mark (d), if there is no error (a) He is of Asian origin.
41. One of the reasons I resigned from the team was that I broke (b) They belonged to Africa.
my leg. (c) She is an European.
42. Measles are a disease caused by a virus contact with fluids (d) They migrated from India to Australia.
from an infected person’s nose and mouth either directly 53. While trying to collect an envelope from under the table,
and through aerosol transmission. I II
43. Those athletes who did not adhere to the rules of athletics Mr. X fell down and was losing consciousness.
was deprived of taking part in the championship. III IV
44. Every man and woman of the village have come out to see Which one of the above underlined parts of the sentence is
this strange child who claims to know everything on his NOT appropriate? [GATE 2014, Set-3, 1 Mark]
prenatal existence. (a) I (b) II
45. If Mahatma Gandhi was alive he would have started weeping (c) III (d) IV
seeing the present condition of India.
EBD_7203
S1-14 GENERAL APTITUDE FOR GATE
Sentence completion questions test your ability to use your 4. Style. Ideas may be expressed in different manners ornately
vocabulary and recognise logical consistency among the elements or sparely, poetically or prosaically, formally or informally,
in a sentence. You need to know more than the dictionary journalistically or academically, originally or imitatively. An
definitions of the words involved. You need to know how the author’s style depends on such details as word choice,
words fit together to make logical and stylistic sense. imagery, repetition, rhythm, sentence structure and length.
Sentence completion questions actually measure one part of Work through the following Fundas and learn techniques
reading comprehension. If you can recognise how the different that will help you with vocabulary, grammatical complexity,
parts of a sentence affect one another, you should do well at tone, and style.
choosing the answer that best completes the meaning of the
sentence or provides a clear, logical statement of fact. The ability FUNDA 1
to recognise irony and humour will also stand you in good stead, BEFORE YOU LOOK AT THE CHOICES, READ THE
as will the ability to recognise figurative language and to SENTENCE AND THINK OF A WORD THAT MAKES SENSE
distinguish between formal and informal levels of speech.
Because the sentence completion questions contain many clues
that help you to answer them correctly (far more clues than the Your problem is to find the word that best completes the sentence
antonyms provide, for example), and because analysing them helps in both thought and style. Before you look at the answer choices,
you warm up for the reading passages later on in the test, on the see if you can come up with a word that makes logical sense in the
context. Then look at all five choices. If the word you thought of
paper-and-pencil test, answer them first. Then go on to tackle the
is one of your five choices, select that as your answer. If the word
analogies, the antonyms, and, finally, the time-consuming reading
you thought of is not one of your five choices, look for a synonym
comprehension section.
of that word. Select the synonym as your answer.
Sentence completion questions may come from any of a number
of different fields-art, literature, history, philosophy, botany,
This Funda is helpful because it enables you to get a sense of the
astronomy, geology, and so on. You cannot predict what subject
sentence as a whole without being distracted by any misleading
matter the sentences on your test will involve.
answers among the answer choices. You are free to concentrate
on spotting key words or phrases in the body of the sentence
What makes the hard questions hard? and to call on your own “writer’s intuition” in arriving at a
1. Vocabulary Level: Sentences contain words like stylistically apt choice of word.
intransigence, nonplussed, harbingers. Answer choices
include words like penchant, abeyance, and eclectic. See how the process works in a typical model question.
2. Grammatical Complexity . Sentences combine the entire
range of grammatical possibilities adverbial clauses, relative 1. Because experience had convinced her that he was both
clauses, prepositional phrases, gerunds, infinitives, and so self-seeking and avaricious, she rejected the likelihood that
on in convoluted ways. The more complex the sentence, his donation had been.................
the more difficult it is for you to spot the key words that can (A) redundant (B) frivolous
unlock its meaning. (C) inexpensive (D) ephemeral
3. Tone. Sentences reflect the writer’s attitude towards the (E) altruistic
subject matter. It is simple to comprehend material that is
presented neutrally. It is far more difficult to comprehend This sentence presents a simple case of cause and effect. The
material that is ironic, condescending, playful, sombre, or key phrase here is self-seeking and avaricious. The woman has
otherwise complex in tone. found the man to be selfish and greedy. Therefore, she refuses to
EBD_7203
S1-16 GENERAL APTITUDE FOR GATE
believe he can do something_______. What words immediately In a sentence completion question with two blanks, read through
come to mind? Selfless, generous, charitable? The missing word the entire sentence to get a sense of it as a whole. Then insert the
is, of course, altruistic. The woman expects selfishness (self- first word of each answer pair in the sentence’s first blank. Ask
seeking) and greediness (avaricious), not altruism (magnanimity). yourself whether this particular word makes sense in this blank. If
The correct answer is Choice E. the initial word of an answer pair makes no sense in the sentence,
you can eliminate that answer pair.
Practice of Funda 1 extensively develops your intuitive sense of (Note: Occasionally this Funda will not work. In some questions,
just the exactly right word. However, do not rely on Funda 1 for example, the first words of all five answer pairs may be near-
alone. On the test, always follow up Funda 1 with Funda 2. synonyms. However, the Funda frequently pays off, as it does in
the following example.)
FUNDA 2
1. Critics of the movie version of The Colour Purple ——— its
LOOK AT ALL THE POSSIBLE ANSWERS BEFORE YOU saccharine, overoptimistic mood at odds with the novel’s
MAKE YOUR FINAL CHOICE more .....................tone.
(A) applauded...sombre
Never decide on an answer before you have read all the choices. (B) condemned...hopeful
You are looking for the word that best fits the meaning of the (C) acclaimed...positive
sentence as a whole. In order to be sure you have not been hasty (D) denounced...sanguine
in making your decision, substitute all the answer choices for the (E) decried...acerbic
missing word. Do not spend a lot of time doing so, but do try For a quick, general sense of the opening clause, break it up.
them all. That way you can satisfy yourself that you have come What does it say? Critics……….the movie’s sugary sweet mood.
up with the best answer.
How would critics react to something sugary sweet and over-
See how this Funda helps you deal with another question.
hopeful? They would disapprove. Your first missing word must
1. The evil of class and race hatred must be eliminated while it
be a synonym for disapprove.
is still in an .......................state; otherwise it may grow to
dangerous proportions. Now eliminate the misfits. Choices A and C fail to meet the test:
(A) Amorphous (B) overt applauded and acclaimed signify approval, not disapproval.
(C) uncultivated (D) embryonic Choice B, condemned, Choice D, denounced and Choice E,
(E) independent decried, however, all disapprobation; they require a second look.
On the basis of a loose sense of this sentence’s meaning, you To decide among Choices B, D, and E, consider the second blank.
might be tempted to select Choice A. After all, this sentence The movie’s sugary, overly hopeful mood is at odds with the
basically tells you that you should wipe out hatred before it gets novel’s tone: the two moods disagree. Therefore, the novel’s tone
too dangerous. Clearly, if hatred is vague or amorphous, it is less is not hopeful or sugary sweet. It is instead on the bitter or sour
formidable than if it is well defined. However, this reading of the side; in a word, acerbic The correct answer is clearly Choice E.
sentence is inadequate: it fails to take into account the sentence’s
Remember that, in double-blank sentences, the right answer must
key phrase.
correctly fill both blanks. A wrong answer choice often includes
one correct and one incorrect answer. ALWAYS test both words.
The key phrase here is ‘grow to dangerous proportions’. The
writer fears that class and race hatred may grow large enough to FUNDA 4
endanger society. He wants us to wipe out this hatred before it is
fully-grown. Examine each answer choice, eliminating those
WATCH FOR SIGNAL WORDS THAT LINK ONE PART OF
answers that carry no suggestion that something lacks its full THE SENTENCE TO ANOTHER
growth. Does overt suggest that something isn’t fully-grown?
Writers use transitions to link their ideas logically. These
No, it suggests that something is obvious or evident. Does
uncultivated suggest that something isn’t fully grown? No, it transitions or signal words are clues that can help you figure out
suggests that something is unrefined or growing without proper what the sentence actually means. Sentences often contain several
care or training. Does independent suggest that something isn’t signal words, combining them in complex ways.
fully-grown? No, it suggests that something is free and
unconstrained. Only one word suggests a lack of full growth: 1. Cause and Effect Signals
embryonic (at a rudimentary, early stage of development). The Look for words or phrases explicitly indicating that one
correct answer is Choice D. thing causes another or logically determines another.
Cause and Effect signal Words
FUNDA 3 Accordingly in order to Because
IN DOUBLE-BLANK SENTENCES, GO THROUGH THE so...that Consequently Therefore
ANSWERS, TESTING THE FIRST WORD IN EACH CHOICE Given thus Hence
(AND ELIMINATING THOSE THAT DON’T FIT) when….then If….then
SENTENCE COMPLETION S1-17
Look for words or phrases explicitly indicating that the If a word used by the author is unfamiliar, or if an answer choice
omitted portion of the sentence supports or continues a is unknown to you, two approaches are helpful.
thought developed elsewhere in the sentence. In such cases, 1. Break up the word into its component parts - prefixes,
a synonym or near-synonym for another word in the suffixes, and roots - to see whether they provide a clue to
sentence may provide the correct answer. its meaning. For example, in the preceding list of Implicit
Support Signal Words Contrast Signal Words, the word incongruous contains
Additionally furthermore Also three major word parts, in- here means not; con- means
indeed And Likewise together; gru- means to move or conic. Incongruous
as well moreover besides behaviour, therefore, is behaviour that does not go together
too or agree with someone’s usual behaviour; it is unexpected.
2. Contrast Signals (Explicit)
Look for functional words or phrases (conjunctions, 2. Change the unfamiliar word from one part of speech to
adverbs, etc.) that explicitly indicate a contrast between another. If the adjective embryonic is unfamiliar to you, cut
one idea and another, setting up a reversal of a thought. In off its adjective suffix -nic and recognise the familiar word
such cases, an antonym or near-antonym for another word embryo. If the noun precocity is unfamiliar to you cut off its
in the sentence may provide the correct answer. noun suffix -ity and visualise it with different endings. You
Explicit Contrast Signal Words may think of the adjective precocious (maturing early). If
Albeit nevertheless Although the verb appropriate is unfamiliar to you, by adding a word
nonetheless But part or two, you may come up with the common noun
Notwithstanding despite appropriation or the still more common noun
on the contrary even though misappropriation (as in the misappropriation of funds).
on the other hand however
rather than in contrast still Note the application of this Funda in the following typical example.
in spite of while instead of yet 1. This island is a colony; however, in most matters, it is and
3. Contrast Signals (Implicit) receives no orders from the mother country.
Look for content words whose meanings inherently indicate (A) dichotomous (B) methodical
a contrast. These words can turn a situation on its head. (C) heretical (D) autonomous
They indicate that something unexpected, possibly even (E) disinterested
unwanted, has occurred.
Implicit Contrast Signal Words First, eliminate any answer choices that are obviously incorrect.
anomaly Anomalous anomalously If a colony receives no orders from its mother country, it is
illogically illogical essentially self-governing. It is not necessarily methodical or
incongruity incongruous incongruously systematic nor is it by definition heretical (unorthodox) or
irony ironic ironically disinterested (impartial). Thus, you may rule out Choices B, C,
paradox paradoxical paradoxically and E.
surprise surprising surprisingly
unexpected unexpectedly The two answer choices remaining may be unfamiliar to you.
Note the function of such a contrast signal word in the following Analyse them, using what you know of related words. Choice A,
question. dichotomous, is related to the noun dichotomy, a division into
1. Paradoxically, the more ——— the details this artist chooses, two parts, as in the dichotomy between good and evil. Though
the better able she is to depict her fantastic, otherworldly the island colony may be separated from the mother country by
landscapes. distance, that has nothing to do with how the colony governs
(A) ethereal (B) realistic itself Choice D, autonomous, comes from the prefix auto-(self)
(C) fanciful (D) extravagant and the root nom-(law). An autonomous nation is independent; it
(E) sublime rules itself. Thus, the correct answer is autonomous Choice D.
The artist creates imaginary landscapes that do not seem to belong
to this world. We normally would expect the details comprising
FUNDA 6
these landscapes to be as fantastic and supernatural as the BREAK UP COMPLEX SENTENCES INTO SIMPLER
landscapes themselves. But the truth of the matter, however, is COMPONENTS
paradoxical: it contradicts what we expect. The details she chooses
are realistic, and the more realistic they are, the more fantastic the In analysing long, complex sentence completion items, you may
paintings become. The correct answer is Choice B. find it useful to simplify the sentences by breaking them up.
Rephrase dependent clauses and long participal phrases, turning
FUNDA 5 them into simple sentences.
USE YOUR KNOWLEDGE OF WORD PARTS AND PARTS See how this Funda helps you to analyse the following sentence.
OF SPEECH TO FIGURE OUT THE MEANINGS OF 1. Museum director Hoving ——— refers to the smuggled
Greek urn as the “hot pot;” not because there are doubts
UNFAMILIAR WORDS
about its authenticity or even great reservations as to its
EBD_7203
S1-18 GENERAL APTITUDE FOR GATE
price, but because its ——— of acquisition is open to Note that in sentence completion questions a choice may he
question. complicated by an unusual word order, such as:
(A) informally…..costliness 1. placing the subject after the verb: To the complaints window
(B) characteristically…..date strode the angry customer.
(C) colloquially…..manner 2. placing the subject after an auxiliary of the verb: Only by
(D) repeatedly…..swiftness unending search could some few Havana cigars be found.
(E) cheerfully.....m ode 3. inverting the subject and verb to give the sense of “if”:
Were defeat to befall him today’s dear friends would be
What do we know?
tomorrow’s acquaintances, and next week’s strangers.
1. The urn has been smuggled.
4 placing a negative word or phrase first’ which usually
2. Hoving calls it a “hot pot.”
requires at least part of the verb to follow: Never have I
3. It is genuine. (There are no doubts about its authenticity.)
encountered so demanding a test!
4. It did not cost too much. (There are no great reservations as
to its price.) In all these instances, rephrase the sentence to make it more
straightforward. For example :
In calling the smuggled urn a “hot pot, “ Hoving is not necessarily
1. The angry customer strode to the complaints window.
speaking characteristically or redundantly or cheerfully. He is
2. Some few Havana cigars could be found only by unending
speaking either informally or colloquially. (Hot here is a slang
search.
term meaning stolen or illegally obtained.) Its costliness is not
3. If defeat were to befall him, today’s dear friends would be
being questioned. However, because the urn has been smuggled
tomorrow’s acquaintances, and next week’s strangers.
into the country, there clearly are unresolved questions about
4. I have never encountered so demanding a test!
how it got here, in other words, about its manner of acquisition.
The correct answer is Choice C.
EXERCISE
DIRECTIONS (Q. 1-46) : Each of the following items is followed 7. It is inconceivable that in many schools children are
by four words or group of words. Fill in the blanks with the subjected to physical _________ in the name of
appropriate word or group of words. discipline.
1. Although I was _________ of his plans, I encouraged him, (a) violation (b) exercise
because there was no one else who was willing to help. (c) violence (d) security
(a) sceptical (b) remorseful 8. We have not yet fully realised the _________ consequences
(c) fearful (d) excited of the war.
2. You have no business to _________ pain on a weak and (a) happy (b) pleasing
poor person. (c) grim (d) exciting
(a) inflict (b) put 9. The scholar was so .............. in his field that many of our
(c) direct (d) force professors became nervous in his presence.
3. Her uncle died in a car accident. He was quite rich. She (a) eminent (b) pathological
suddenly _________ all her uncle’s money. (c) petulant (d) amiable
(a) succeeded (b) caught 10. Criticism that tears down without suggesting areas of
(c) gave (d) inherited improvement is not .............. and should be avoided if
4. There was a major accident. The plane crashed. The pilot possible.
_________ did not see the tower.
(a) constructive (b) mandatory
(c) pertinent (d) sagacious
(a) likely (b) probably
(c) scarcely (d) hurriedly 11. Language, culture and personality may be considered
5. I had a vague _________ that the lady originally belonged independently of each other in thought, but they are ..............
to Scotland. in fact.
(a) notion (b) expression (a) equivocal (b) pervasive
(c) imagination (d) theory (c) inseparable (d) autonomous
6. The prisoner showed no _________ for his crimes. 12. The people of Europe came to India .............. for riches,
(a) hatred (b) obstinacy followed quickly by the desire to rule.
(c) remorse (d) anger (a) basically (b) fundamentally
(c) primarily (d) seemingly
SENTENCE COMPLETION S1-19
13. You may wonder how the expert on fossil remains is able to 25. Fast food restaurants have become popular because many
trace descent through teeth, which seem .............. pegs upon working people want ............... .
which to hang whole ancestries. (a) to eat quickly and cheaply
(a) reliable (b) inadequate (b) eating quickly and cheaply
(c) novel (d) specious (c) eat quickly and cheaply
14. He was .............. very clever, but he .............. performed (d) the eat quickly and cheaply
excellently. 26. Our _____ to understand the process of learning underlying
(a) certainly- obviously (b) never- also Behavior change is _____by the fact that any given behavior
(c) not- always (d) rarely- seldom is determined jointly by many processes.
15. A .............. analysis of these substances will show that they
(a) nature, determined (b) implication, followed
differ .............. .
(a) random- minutely (b) detailed- essentially (c) scope, preceded (d) attempt, complicated
(c) careful- completely (d) final- Structurally 27. Not all countries benefit_____from liberalization, the
16. We were amazed that a man who had been the most .............. benefits tend to_____first to the advantaged and to those
public speakers could, in a single speech electrify an with the right education to be able to benefit from the
audience and bring the cheering crowd to their feet. opportunities presented :
(a) enthralling (b) accomplished (a) equally, generate (b) suitably, ascribe
(c) pedestrian (d) masterful (c) richly, downgrade (d) uniformally, percolate
17. Education is central because electronic networks and 28. Unless new reserves are found soon, the world’s supply of
software-driven technologies are beginning to ......... the coal is being_____in such a way that with demand
economic barriers between the nations. continuing to grow at present rates reserves will be_____by
(a) Break down (b) Break the year 2050?
(c) Crumble (d) Dismantle (a) consumed, completed (b) reduced, augmented
18. Professionals focus their ........ on fulfilling their (c) depleted, exhausted (d) burnt, destroyed
responsibilities and achieving results, not on ......... a
29. In the absence of native predators to stop the spread of
particular image.
their population, the imported goats ________ to such an
(a) leadership - attributing (b) planning - devising
inordinate degree that they over–grazed the countryside
(c) abilities - contributing (d) energies - portraying
and ________ the native vegetation.
19. When you are living with your ........ values and principles,
(a) suffered, abandoned
you can be straightforward, honest and ........
(a) inherited - distinct (b) core -up-front (b) propagated, cultivated
(c) innate - durable (d) cultural - perceptive (c) thrived, threatened
20. In the role of a counsellor, you are an authority figure whose (d) dwindled, eliminated
objective is to ....... attentively and sensitively to employees 30. Carried away by the ________ effects of the experimental
who .......... you with their feelings. medication, the patient ________ his desire to continue as
(a) manage - direct (b) projects - focus a subject for as long as he could.
(c) listen - trust (d) concentrate - believe (a) noxious, proclaimed
21. If a junior executive neglects his professional development (b) supplementary, announced
and ............ education, he can easily and quickly become (c) frantic, repeated
obsolete in a world changing at ............ rates.
(d) salutary, reiterated
(a) higher - vulnerable
(b) management - voluminous 31. Being a bit hesitant about.........the man as the complete fraud
(c) better - supreme he suspected him to be, he chose to attack the weaker points
(d) continuing - dizzying of his theory,...........them one by one:
22. .............. the reactions of people with amnesia, scientists are (a) ridiculing, proving
learning about the process of memory of the brain. (b) denouncing, debunking
(a) By studying (b) To study (c) castigating, strengthening
(c) They study (d) They are studying (d) mocking, destroying
23. I hope she ............... . 32. The analysis of the coach's report was anything but ..............
(a) must come (b) should come but those of us who have learned to discount such dismal
(c) will come (d) must be coming ............are optimistic:
24. Encounters between people from different countries can (a) sanguinary, traps
result in misunderstandings .............. different conceptions
(b) pessimistic, confusion
about space.
(c) malicious, benefits
(a) because they (b) is because they
(c) is because their (d) of their (d) pleasant, prognostications
EBD_7203
S1-20 GENERAL APTITUDE FOR GATE
33. The best punctuation is that of which the reader is least 42. Choose the most appropriate word from the options given
conscious; for when punctuation, of lack of it, ______ below to complete the following sentence :
itself, it is usually because it _____ His rather casual remarks on politics ___________ his lack
(a) conceals, recedes (b) enjoins fails of seriousness about the subject. [GATE 2010, 1 Mark]
(c) obtrudes, offends (d) effaces, counts (a) masked (b) belied
34. Companies that try to improve employees' performance by (c) betrayed (d) suppressed
_______rewards encourage negative kinds of behaviour,
43. Choose the most appropriate word from the options given
instead of _______a genuine interest in doing the work
below to complete the following sentence.
well.
(a) conferring, discrediting If you are trying to make a strong impression on your
(b) bestowing, discouraging audience, you cannot do so by being understated, tentative
(c) giving, seeking or __________ [GATE 2011, 1 Mark]
(d) withholding, fostering (a) hyperbolic (b) restrained
35. A growing number of th ese expert profession als (c) argumentative (d) indifferent
_______having to train foreigners as the students end 44. Choose the most appropriate word(s) from the options given
up _____the teachers who have to then unhappily contend below to complete the following sentence.
with no jobs at all or new jobs with drastically reduced pay I contemplated ________ Singapore for my vacation but
packets. decided against it. [GATE 2011, 1 Mark]
(a) welcome, assisting (b) resist, challenging (a) to visit (b) having to visit
(c) resent, replacing (d) are, supplanting (c) visiting (d) for a visit
36. The law prohibits a person from felling a sandalwood tree 45. Choose the most appropriate alternative from the options
even if it grows on one’s own land, without prior permission given below to complete the following sentence :
from the government. As poor people cannot deal with the
Suresh’s dog is the one _________ was hurt in the
government, this legal provision leads to a rip-roaring
stampede. [GATE 2012, 1 Mark]
business for________who care neither for
the_________nor for the trees. (a) that (b) which
(a) middlemen, rich (b) touts, rich (c) who (d) all of these
(c) the government, poor (d) touts, poor 46. Choose the most appropriate alternative from the options
37. The best punctuation is that of which the reader is least given below to complete the following sentence :
conscious; for when punctuation, or lack of it,_______itself, Despite several ________ the mission succeeded in its
it is usually because it_________. attempt to resolve the conflict. [GATE 2012, 1 Mark]
(a) obtrudes, offends (b) carceals, recedes (a) attempts (b) setbacks
(c) enjoins, fails (d) effaces, counts (c) meetings (d) delegations
38. The argument that the need for a looser fiscal policy to 47. Were you a bird, you ____________ in the sky.
_________demand outweighs the need to [GATE 2013, 1 Mark]
_________budget deficits is persuasive. (a) would fly (b) shall fly
(a) assess, minimize (b) stimulate, control (c) should fly (d) shall have flown
(c) outstrip, eliminate (d) restrain, conceal 48. Choose the most appropriate word from the options given
39. This simplified_________to the decision - making process
below to complete the following sentence.
is a must read for anyone_________important real estate,
He could not understand the judges awarding her the first
personal, or professional decisions.
(a) primer, maximizing (b) introduction, under prize, because he thought that her performance was
(c) tract, enacting (d) guide, facing quite______. [GATE 2014, Set-1, 1 Mark]
40. ______ the general had been told by the field staff that (a) superb (b) medium
continuing warfare would be ________ to his soldiers, he (c) mediocre (d) exhilarating
insisted on deploying more battle tanks. 49. Who ___________ was coming to see us this evening?
(a) Because...instrumental [GATE 2014, Set-2, 1 Mark]
(b) Although...detrimental (a) you said (b) did you say
(c) Although...formidable (c) did you say that (d) had you said
(d) Because...immediate 50. If she _______________ how to calibrate the instrument,
41. Choose the most appropriate word from the options given she _______________ done the experiment.
below to complete the following sentence : [GATE 2014, Set-3, 1 Mark]
[GATE 2010, 1 Mark] (a) knows, will have
If we manage to __________ our natural resources, we (b) knew, had
would leave a better planet for our children.
(c) had known, could have
(a) uphold (b) restrain
(d) should have known, would have
(c) cherish (d) conserve
SENTENCE COMPLETION S1-21
EXERCISE
SYNONYMS 17. PATRONAGE
(a) donation (b) support
DIRECTIONS (Qs. 1-80): Pick out the nearest correct meaning
(c) espionage (d) beneficiary
or synonym of the words given below:
18. TRAVERSE
1. ADVICE (a) mingle (b) frustrate
(a) council (b) counsel (c) take (d) cross
(c) practice (d) proposal 19. FOUND
2. MISERABLE (a) see (b) establish
(a) object (b) obstruct (c) realize (d) search
(c) abject (d) abstract 20. RECUPERATE
3. QUOTE (a) recapture (b) reclaim
(a) sight (b) sigh (c) recover (d) regain
(c) sue (d) cite 21. ALMS
4. HARMONY (a) blessings (b) charity
(a) cemetery (b) ceremony (c) prayers (d) worship
(c) symmetry (d) hierarchy 22. ATTENUATE
5. UNLAWFUL (a) repent (b) make thin
(a) elicit (b) draw (c) force (d) divide
(c) illegitimate (d) illicit 23. VINDICTIVE
6. HAUGHTY (a) revengeful (b) triumphant
(a) imperial (b) imperious (c) strategic (d) demonstrative
(c) adamant (d) empire 24. DISCOMFIT
7. WISE (a) litigate (b) ease
(a) momentous (b) pragmatic (c) conflict (d) frustrate
(c) judicious (d) delay 25. WRATH
8. LOQUACIOUS (a) violence (b) anger
(a) Victorian (b) bombastic (c) hatred (d) displeasing
(c) verbose (d) ambiguous 26. ABSTINENCE
9. COURAGEOUS (a) synchronic (b) torrential
(a) fickle (b) insipid (c) restraint (d) gluttony
(c) timorous (d) fearless 27. ERUDITE
10. WATCHFULNESS (a) execute (b) expanse
(a) Supervision (b) Custody (c) academic (d) settle
(c) Superintendence (d) Vigil 28. TACITURNITY
11. ATTACHMENT (a) dumbness (b) changeableness
(a) Affinity (b) Influence
(c) hesitation (d) reserve
(c) Causation (d) Appendage
29. ANIMATE
12. WEARY
(a) kill (b) dead
(a) Tired (b) Fatigued
(c) energise (d) calm
(c) Sentimental (d) Emotional
30. NIGGARDLY
13. BEQUEST
(a) penurious (b) generous
(a) Parsimony (b) matrimony
(c) heritage (d) patrimony (c) liberal (d) nimbus
14. GULLIBLE 31. BLITHE
(a) credible (b) believable (a) joyless (b) grudging
(c) credulous (d) fallible (c) somnolent (d) cheerful
15. BRAVERY 32. CAPTIVATE
(a) onslaught (b) arrogant (a) repel (b) subjugate
(c) fortitude (d) nepotism (c) dangerous (d) fascinate
16. JEALOUS 33. REDEEM
(a) obvious (b) atrocious (a) extend (b) fulfil
(c) envious (d) ferocious (c) reconsider (d) recover
SYNONYMS AND ANTONYMS S1-25
34. BLAND 53. ANNEX
(a) unpleasant (b) irritating (a) add (b) low
(c) affable (d) tasteless (c) copy (d) initial
35. VISIONARY 54. MENAGE
(a) dreaming (b) savant (a) suffocation (b) system
(c) philosopher (d) saint (c) law (d) household
36. REVOKE 55. DILEMMA
(a) repudiate (b) repeal (a) darkness (b) freedom
(c) impute (d) force (c) trap (d) confusion
37. REPRISAL 56. RIGMAROLE
(a) denial (b) reluctance (a) short-cut
(c) unequivocal (d) retaliation (b) lengthy procedure
38. FASTIDIOUS (c) unnecessary burden
(a) faint (b) dainty (d) happy responsibility
(c) delicious (d) dormant 57. TRANSCEND
39. ATTRIBUTE
(a) lower (b) climb
(a) Infer (b) impute
(c) energise (d) cross
(c) inhere (d) inundate
58. IMPERATIVE
40. DIALECTIC
(a) order (b) command
(a) argumentative (b) instructive
(c) suggestion (d) necessity
(c) constructive (d) destructive
41. GERMINATE 59. EXEMPT
(a) decay (b) breed (a) duty (b) provide
(c) produce (d) sprout (c) relieve (d) forgive
42. EFFICACY 60. INFIRMITY
(a) delicacy (b) ruthlessness (a) disease (b) malady
(c) efficiency (d) solemnity (c) weakness (d) slimness
43. MAGNATE 61. IMMINENT
I) tycoon (b) senior executive (a) eminent (b) immediate
(c) non-magnetic (d) symbolic (c) future (d) impending
44. FACET 62. CHASTE
(a) sweet (b) tap (a) Filthy (b) Lewd
(c) deceit (d) aspect (c) Immoral (d) Noble
45. PERNICIOUS 63. FEMINITY
(a) deadly (b) curious (a) Cowardice (b) Manly
(c) gorgeous (d) expensive (c) Angelic (d) Inheritant
46. PERSUADE 64. CURVATURE
(a) assure (b) opinionated (a) Angularity (b) Straightness
(c) convince (d) cheat (c) Short-cut (d) Streamline
47. FORTIFY 65. SUMMIT
(a) topple (b) destroy (a) Base (b) Slope
(c) reproduce (d) strengthen (c) Declivity (d) Peak
48. PHENOMENAL 66. WEAN
(a) incidental (b) eventful (a) Introduce (b) Withdraw
(c) natural (d) extraordinary (c) Detach (d) Alienate
49. PARADIGM 67. MENDACIOUS
(a) solution (b) model (a) false (b) misleading
(c) discovery (d) invention (c) provocative (d) truthful
50. HONORARY 68. OSTRACISED
(a) honest (b) dignified (a) hated (b) shut out from the society
(c) unpaid (d) praiseworthy (c) criticized (d) applauded by the majority
51. FACULTY 69. SPURIOUS
(a) privilege (b) desire (a) false (b) harmful
(c) branch (d) ability (c) poisonous (d) foreign
52. FORESEE 70. OBNOXIOUS
(a) contemplate (b) visualise (a) clever (b) shrewd
(c) assume (d) hypothesis (c) disagreeable (d) outdated
EBD_7203
S1-26 GENERAL APTITUDE FOR GATE
71. PERNICIOUS 85. Match the columns. [GATE 2014, Set-2, 1 Mark]
(a) radical (b) baneful Column 1 Column 2
(c) scientific (d) negative 1) eradicate P) misrepresent
72. RECTIFY 2) distort Q) soak completely
(a) to command (b) to correct 3) saturate R) use
(c) to destroy (d) to build 4) utilize S) destroy utterly
73. CORDON (a) 1:S, 2:P, 3:Q, 4:R (b) 1:P, 2:Q, 3:R, 4:S
(a) pile of logs (b) heavy cloak (c) 1:Q, 2:R, 3:S, 4:P (d) 1:S, 2:P, 3:R, 4:Q
(c) line of people placed as guard 86. Which of the following options is the closest in meaning to
(d) none of these the phrase underlined in the sentence below?
74. CONCERT It is fascinating to see life forms cope with varied
(a) beauty (b) power environmental conditions. [2014, Set-1, 1 Mark]
(c) agreement (d) none of these (a) adopt to (b) adapt to
75. MITIGATE (c) adept in (d) accept with
(a) to heal (b) soothen
(c) to pardon (d) to send on a mission ANTONYMS
76. DEVOID DIRECTIONS (Qs. 1-75) : Pick out the antonym of the words
(a) evasive (b) hopeless given below:
(c) lacking (d) stupid 1. IMPLICATE
77. RESOLVED (a) appease (b) exonerate
(a) summarized (b) dispelled (c) adore (d) advocate
(c) determined (d) hanged 2. VACILLATING
78. APPOSITE (a) fascinating (b) fanaticism
(a) appropriate (b) foolish (c) indolence (d) resolute
(c) paiuful (d) none of these 3. RECKLESS
(a) modest (b) awkward
79. BUOYANT
(c) celebrated (d) cautious
(a) childlike (b) sturdy
4. INSULT
(c) brisk (d) light-hearted
(a) Humiliation (b) Credulity
80. INFIRM
(c) Degradation (d) Honour
(a) Sturdy (b) Anxious
5. ABANDON
(c) Patient (d) feeble
(a) Roost (b) Forfeit
81. Which of the following options is the closest in meaning (c) quit (d) Forsake
to the word below : [GATE 2010, 1 mark] 6. OFFEND
Circuitous (a) angry (b) hate
(a) cyclic (b) indirect (c) force (d) respect
(c) confusing (d) crooked 7. INDICT
82. Which of the following options is the closest in the meaning (a) condemn (b) reprimand
to the word below : [GATE 2011, 1 mark] (c) acquit (d) allege
Inexplicable 8. OBSCENE
(a) Incomprehensible (a) decent (b) objectionable
(b) Indelible (c) condemnable (d) jealousy
(c) Inextricable 9. LIBERATE
(d) Infallible (a) imprison (b) enclose
83. Which one of the following options is the closest in meaning (c) liberal (d) conceal
to the word given below? [GATE 2012, 1 mark] 10. MELANCHOLY
Mitigate (a) depressed (b) prejudiced
(a) Diminish (b) Divulge (c) reckless (d) cheerful
(c) Dedicate (d) Denote 11. LEGITIMATE
84. Which one of the following options is the closest in (a) valid (b) extend
meaning to the word given below? (c) unlawful (d) distinguished
Nadir [GATE 2013, 1 Mark] 12. VACILLATE
(a) Highest (b) Lowest (a) amplify (b) stimulate
(c) Medium (d) Integration (c) consistent (d) eradicate
SYNONYMS AND ANTONYMS S1-27
13. HINDER 28. FRAIL
(a) expidite (b) protect (a) worried (b) strong
(c) devote (d) create (c) nervous (d) wily
14. TERSE 29. CRUDE
(a) lengthy (b) scarce (a) classical (b) graceful
(c) diffuse (d) headless (c) natural (d) polished
15. MULTIPLICITY 30. RETRIBUTION
(a) finite (b) uniformity (a) compensation (b) forgiveness
(c) magnitude (d) infinite (c) contempt (d) grudge
16. NAIVE 31. PROCLAIM
(a) subtle (b) energise (a) denounce (b) pretend
(c) spotless (d) clever (c) attend (d) distend
17. ANACHRONISTIC 32. SUMPTUOUS
(a) formerly (b) present (a) irritable (b) meagre
(c) futuristic (d) non-existing (c) fancy (d) sad
18. TRAIT 33. FEIGN
(a) symbol (b) uncharacteristic (a) condone (b) attend
(c) habit (d) identity (c) willing (d) original
19. GARISH 34. INSIPID
(a) tasteful (b) green (a) witty (b) meagre
(c) scenic (d) contrasting (c) wily (d) lucid
20. GEOLOGICAL 35. SALUBRIOUS
(a) astral (b) solar (a) sticky (b) soft
(c) galactic (d) heavenly (c) famous (d) malaise
21. REJUVENATION 36. REFULGENT
(a) sexual (b) perfect (a) angry (b) dull
(c) killing (d) magical (c) sad (d) lament
22. ORIGIN 37. INNOCUOUS
(a) ointment (b) detergent (a) offensive (b) harmless
(c) remnant (d) comfort (c) organic (d) anger
23. APATHETIC 38. AFFECTATION
(a) agitated (b) happy (a) sincerity (b) humility
(c) concerned (d) surprised (c) stirring (d) affluent
24. HOMOGENISED 39. LUMINOUS
(a) set type (b) multi-coloured (a) dark (b) ludicrous
(c) different (d) rejected (c) unsteady (d) provoking
25. PROVE 40. INTRICACY
(a) vapid (b) assume (a) ornate (b) simplicity
(c) disincline (d) atone (c) distance (d) cordiality
26. ACCOLADE 41. AMELIORATE
(a) balcony (b) outer garment (a) amend (b) gyrate
(c) drink (d) criticism (c) sweeten (d) worsen
27. INSTANTLY 42. LACKADAISICAL
(a) repeatedly (b) lately (a) abundant (b) energetic
(c) gradually (d) awkwardly (c) theatrical (d) actual
EBD_7203
S1-28 GENERAL APTITUDE FOR GATE
43. CAPRICIOUS 61. PROFANE
(a) thoughtful (b) specious (a) pious (b) kitten
(c) energy (d) wild
(c) carcinogenic (d) capacious
62. DOMINATE
44. PERFIDIOUS (a) defeat (b) succumb
(a) loyal (b) treacherous (c) threaten (d) sheepish
(c) religious (d) humane 63. UNFATHOMABLE
(a) comprehensible (b) sinkable
45. ENNUI (c) uncomfortable (d) infallible
(a) sticky (b) activity 64. TERMINATION
(c) start (d) yearly (a) endeavouring (b) beginning
46. LASCIVIOUS (c) amendment (d) phasing
(a) devout (b) fluid 65. INSPIRED
(c) chaste (d) stable (a) discouraged (b) extracted
47. CONSCIENTIOUS (c) negated (d) admired
(a) cruel (b) licentious 66. PARTICIPATE
(c) careless (d) whip (a) precipitate (b) change
48. PERIGEE (c) disengage (d) boycott
(a) apogee (b) hybrid 67. EGALITARIAN
(c) descent (d) night (a) unequal (b) socialist
49. FLUCTUATE (c) capitalist (d) liberal
(a) conceive (b) stabilise 68. DEFICIENCY
(c) energise (d) emancipate (a) abundance (b) deficit
50. RADICAL (c) ill (d) profit
(a) superficial (b) slow 69. FLOURISH
(c) narrow (d) simple (a) improve (b) retard
51. ACCORD (c) hamper (d) stop
(a) concord (b) policy 70. VENEER
(c) dissent (d) act (a) exterior (b) interior
52. HAPLESS (c) impression (d) armour
(a) lucky (b) kind 71. DICTATORSHIP
(c) helpful (d) futile (a) democracy (b) tyranny
53. FRIVOLOUS (c) aristocracy (d) self-rule
(a) trivial (b) significant 72. EVENTUALLY
(c) fearless (d) permissive (a) primarily (b) resultantly
54. INTEGRAL (c) initially (d) objectively
(a) minor (b) major 73.73. PHENOMENAL
(c) essential (d) independent (a) ordinary (b) experiential
55. HOLISTIC (c) natural (d) spiritual
(a) negative (b) piecemeal 74. NONCHALANT
(c) impure (d) inadequate (a) fearful (b) cowardly
56. EXTENSION (c) patriotic (d) excited
(a) diminution (b) condensation 75. ABOMINATE
(c) deletion (d) subtraction (a) love (b) loathe
57. INDIGENTLY (c) abhor (d) despise
(a) richly (b) awfully 76. Choose the word from the options given below that is most
(c) completely (d) diligency nearly opposite in meaning to the given word :
58. AUDACITY [GATE 2011, 1 Mark]
(a) quivering (b) patricide Amalgamate
(c) bravado (d) cowardice (a) merge (b) split
59. WORTHY
(c) collect (d) separate
(a) unimportant (b) valuable
77. Choose the word that is opposite in meaning to the word
(c) undeserving (d) ugly
“coherent”. [GATE 2014, Set-3, 1 Mark]
60. ELEVATION
(a) sticky (b) well-connected
(a) depression (b) deflation
(c) rambling (d) friendly
(c) depreciation (d) recession
SYNONYMS AND ANTONYMS S1-29
70. (c) disagreeable, unpleasant, nasty, offensive 8. (a) Obscene means indecent, objectionable and
condemnable mean similar to obscene.
71. (b) Pernicious is ruinous, injurious, hurtful. Baneful is
9. (a) Liberate is to make someone free and imprison is to
destructive.
put in prison, conceal is to hide and vacillation is to
72. (b) Rectify is to correct.
move from one place or idea to another.
73. (d) Cordon means a line of policemen or soldiers which
10. (d) Melancholy means depressed and is therefore opposite
guards or prevents people entering or leaving an area
to cheerful.
As it is not covered any of the options, answer should
11. (c) Legitimate means legal or lawful, distinguished means
be ‘none of these.
eminent, and courteous means polite.
EBD_7203
S1-32 GENERAL APTITUDE FOR GATE
12. (d) Vacillate means to move from one place to another 29. (d) Crude means raw, undeveloped or unsophisticated,
and consistent means to stay the same, eradicate means graceful can also be an antonym to crude but polished
to remove is more exactly opposite to crude.
13. (a) Hinder means to prevent the growth or progress of 30. (b) Retribution is punishment, contempt is feeling of
something while expedite is to make fast the process disgust and grudge is an ill-feeling.
or facilitate. Vindicate means to justify. 31. (a) Proclaim is to announce usually in favour of, denounce
14. (a) Terse means brief. Diffuse means spread widely or means to speak against.
thinly. 32. (b) Sumptuous means sufficient or more in quantity,
15. (b) Multiplicity is presence of multiple or many identities, meagre means very little.
while uniformity means same everywhere, infinite 33. (d) Feign means to pretend, that is show what is not real
means endless. or original, condone is to forgive and condemn is to
express disapproval of something.
16. (d) Naive means inexperienced, someone who will not be
34. (a) Insipid means unintelligent, plain or flat, witty means
very sharp or clever owing to lack of experience.
clever intelligent.
17. (c) Anachronistic is something that belongs to a time gone 35. (d) Salubrious means health giving, malaise is something
by, while futuristic is something that belongs to the that causes discomfort or pain, like a disease.
future or suggests how the future would be. 36. (c) Refulgent means bright, lament is to repent.
18. (b) Trait means characteristic. 37. (b) Innocuous is harmless or inoffensive.
19. (a) Garish means gaudy or in bad taste. 38. (b) Affectation means haughtiness or pride while humility
20. (d) Geological means belonging to or related to the earth, means humble, polite behaviour.
while galactic is that which belongs to the galaxy. 39. (c) Luminous means bright or giving out a lot of light.
Heavenly is belonging to heaven so opposite to 40. (b) The carpets are priced so high due to the intricacy of
earthly. Heavenly is also called unearthly. patterns. An intricate pattern is made up of many small
details. It is complicated, not simple. The noun from
21. (c) Rejuvenation means rebirth and regeneration or to live
simple is simplicity.
again.
41. (d) If you ameliorate a situation, you make it better or easier
22. (c) Origin means the starting point and remnant is what is in some way. The opposite of better is worse. If you
left after finishing or distrubution. make a situation worse, you worsen
23. (c) Apathetic is one who does not care or is indifferent. 42. (b) The fielding of the Indian cricket team is lackadaisical.
24. (c) Homogenised means when every part of the group, That is, the fielders do not show much interest or
mixture or collection has been made similar or same, enthusiasm; they are rather lazy. Jadeja, however, is an
variety means the opposite, i.e difference. exception. He is Energetic.
43. (a) He was fed up with the capricious behaviour of his
25. (b) Prove means to state that a statement or theory is
wife. It began to prove difficult for him to fulfil her
correct after giving valid and logical reasons while
caprices. A caprice is an unexpected action or decision;
assumption is something which is believed without
It has no strong reason or purpose. In fact, the
any proofs or evidence. husband could not tolerate her. He was a thoughtful
26. (d) Accolade is a token of respect and admiration or kind man; his actions were based on reason.
of reward given to appreciate, criticism is to find faults. 44. (a) One who is perfidious is treacherous or untrustworthy.
27. (c) Instantly means something that happens in an instant He may be with you today and against you tomorrow.
or very quickly, gradually means to happen step by On the other hand, a local person remains Firm in his
step. slowly has not been considered as the apt choice or her friendship or support.
because instantly suggests in one step and gradually 45. (b) Ennui is a feeling of tiredness, boredom and
means in several steps so it is a more appropriate dissatisfaction caused by lack of interest and having
antonym. nothing to do. Only activity (something to do) can be
its antidote. [An antidote is a substance that prevents
28. (b) Frail means something or someone very weak, usually
the bad effects of a disease.]
due to illness.
SYNONYMS AND ANTONYMS S1-33
46. (c) One who is lascivious shows an unnaturally strong in nature is connected in some way. A piecemeal
interest in sex. On the other hand, a chaste person approach, on the other hand, deals with only one part
does not have sex with anyone, or has it only with his at a time.
or her spouse. 56. (d) There has been an extension of STD facility to 2000
47. (c) Rachna is very conscientious about her actions. That more villages. In other words, there has been an
is, she is very careful to do her work properly. Now, the addition to the number of villages under STD coverage.
opposite of careful is careless. Now, the opposite of addition is subtraction.
48. (a) The perigee is the point where the path of an object 57. (a) One who is indigent is very poor. The opposite of
through space is closest to the Earth. The apogee is poor is rich.
the point where the path is farthest from the Earth. 58. (d) Audacity is audacious behaviour. If you are audacious,
49. (b) How do you rectify voltage fluctuations’! With the you take risks in order to achieve something. So it is a
help of a voltage stabiliser. If something fluctuates, it kind of bravery. Now, the opposite of bravery is
changes a lot in an irregular way. If you stop this, it cowardice.
becomes stable. 59. (c) Biased teachers are not worthy of respect. Teachers
50. (a) Radical comes from Latin radix (= root). If you make a are expected to be impartial. If not so, they do not
radical change in something, the change goes to its deserve respect. In other words, they are undeserving
very roots, thus affecting the entire thing. On the other of respect.
hand, there are changes which do not disturb the entire 60. (a) An elevation is a ‘piece of ground that is higher
thing; the changes take place only on the surface. In (elevated) than the area around it. A depression in a
other words, they are superficial changes. surface is an area which is lower (depressed) than the
51. (c) Four of the judges were in accord with one another parts surrounding it.
while one dissented. That is, four of them were in 61. (a) Cows are sacred to the Hindus. Killing of cows is a
agreement with one another on the judgement. There profane act for them. That is, they consider the act to
was no conflict between their opinions. One judge, be a disrespect for the religion, and therefore sinful.
however, did not share the majority opinions. He was Pious (very religious and moral) Hindus would plug
of a different opinion. In other words, he dissented. their ears even if they heard of it.
52. (a) All reservations have been abolished from this year! 62. (b) Having piled a huge total, the Sri Lankan cricket team
Hari Paswan, a scheduled caste candidate, has fallen a was in a dominating position. That is, the Sri Lankans
hapless victim to the new law. That is, he was unlucky were in control of the match (the Independence Cup
not to have taken the exam last year. His elder brother, final). The Pakistani a succumbed to the pressure. That
Barkhu, was lucky enough to have made it last year. is, they were affected the Sri Lankan domination.
53. (b) Farming on such a barren land! It is a frivolous project. 63. (a) The Vedas are unfathomable; that is, one cannot fully
That is, it would only entail a wastage of time and understand the depth of their meaning. The
money. It is not useful. It would make no significant commentaries, however, are simplified versions easy
(important) contribution to ameliorating the plight of to understand. In other words, they are
the poor. comprehensible’.
54. (d) Kashmir is an integral part of India. That is, it is an 64. (b) The controversy led to a termination of the contract.
essential part of India without which the country That is, the contract came to an end. The opposite of
cannot be complete. It cannot be separated from the End is beginning.
country. That is what most of the people believe. 65. (a) My success is due to my elder brother, who has
However, a handful of people believe it should be inspired me at every point. That is, he encouraged me
independent - that It has no connection whatsoever to go ahead with my work. The opposite of encouraged
with the rest of India. is discouraged.
55. (b) Holistic medicine treats the whole person, not just the 66. (d) Only 76 countries participated in the meet. The rest
diseased part. That which is holistic is based on the boycotted it. That is, they refused to participate (take
principles of holism. Holism is the belief that everything part) in it because they disapproved of it.
EBD_7203
S1-34 GENERAL APTITUDE FOR GATE
67. (a) Some people believe that reservations are against the in a country. In effect, it becomes a one-man rule.
idea of an egalitarian society. An egalitarian society Countries like India, however, believe in a rule “by the
supports or follows the idea that all people are equal; people”. In other words, we believe in democracy. In a
they should have the same right and opportunities. So democracy, power is not centred in one person. The
why give special rights to some? Others, however, feel ruler is merely the representative or’ the people.
that the society, as it stands today, is unequal. Only 72. (c) Eventually means “at the end”; initially means “in the
reservations can bring an equilibrium and make the beginning”.
society egalitarian. 73. (a) Dhirubhai Ambani has had a phenomenal (unusually
68. (a) A deficiency of iodine leads to goitre. In other words, big) success. Such a success is not usually had by
iodine is riot present in enough quantity. On the other ordinary persons.
hand, if it be present in large quantities, that is more 74. (d) A nonchalant person seems not to worry or care about
than enough (usually), we say it is in abundance. things. He or she seems very calm. Not al all excited.
69. (b) The economy flourishes when there are lesser 75. (a) If: you abominate something, you hate it very much.
restrictions. That is, it grows quickly and strongly. The opposite of hate is love.
Imposing of restrictions makes the growth of the 76. (b) Amalgamate means combine or unite to form one
economy retard. That is, it gets slower, as if under organization or structure. So best option here is split.
brakes. Separate on the other hand, although a close
70. (b) The veneer of something is the coating from outside. synonyms, it is too general to be the best antonym in
It is the exterior which often gives a false impression the given question while Merge is the synonym; Collect
of the reality inside. The inside of something is its is not related.
interior. 77. (c) Coherent means logically connected while rambling
71. (a) What happens in a dictatorship? All the decisions are means aimlessly wandering.
made by the dictator — a ruler who has complete power
u u u
4 Verbal Analogies/ Contexual Usage
ANALOGIES
Analogies, literally means a comparison or a comparable similarity. 4. ACTION : OBJECT
A student has to find a pair of words in the same relation or a foment : Riot ® you foment a riot
similar relation as that of the given pair of words. Analogy is in a Wear :clothes ® you wear clothes
sense, a test of vocabulary since you need to know the meaning This is opposite to the previous relation, here the first word
of the words given, but in a broader sense it is a test of reasoning is the action and the second the object with which that
ability. To know the meaning of the words will not be enough if action is done.
one is not able to understand clearly what the relation between 5. PART : WHOLE
the pairs of words is. Therefore, there are two things that are Book : Literature ® a book is a part of the larger body of
important to attempt a question on analogy : literature
i) meaning of all given words Ship : fleet ® ship is a part of the collection called fleet
ii) relationship between the given pairs of words In this relation, the first word will in the same way be a
constituent of a bigger body represented by the second
word.
It is more convenient and time saving to first figure out the relation
between the given pair and then compare it with the relations 6. SYNONYMS
between the pairs in the options given for choice. Consider the Abundant : ample ® ample means the same as abundant
following example Skilled : adroit ® the two words are synonymous, i.e., they
Pen : Write : : Book : mean the same
Now first determine the relation between the first two words, it is This relation is when both the words are synonyms
that of purpose, pen is used to write. Then determine the other 7. ANTONYMS :
word which will be in the same relation to the third word. Book is Abstinence : indulgence ® indulgence means the opposite
used to read, then of Abstinence
Pen : Write : : Book : read Legitimate : Unlawful ® Legitimate means legal which is
There are different kinds of relationships that could be drawn the opposite of unlawful
from daily usage but some common relationships are given below : In this relation, the two words are opposite to each other in
meaning.
1. CAUSE : EFFECT
8. SECONDARY SYNONYMS :
Liquor : Intoxication ® Liquor causes intoxication
Callous : Indifference ® The synonym of callous will be
Wound : pain ® wound causes pain.
indifferent, since both words are adjectives but rather the
In this relation the first word is the cause for the second and
noun form. Indifference has been given in the relation
the second is the result of the first
Brainwave : Inspired ® The synonym of Brainwave is
2. PURPOSE inspiration, but instead the second word in this relation is
Bottle : Cork ® a cork is used to close a bottle Inspired - the one who has inspiration.
Dress : cloth ® cloth is used to make a dress In this relation, the two words are not directly synonymous
In this relation, one word is used for another, there is a but a slight mutation of the part of speech has been made in
purpose between the two the second word.
CONTEXUAL USAGE
Contexual meaning or Contexual usage is another important word- Strategies for contexual usage :
based question. Contexual usage basically involves, identifying The following steps and strategies will be useful while attempting
the synonym/antonym of a word when it is used in a particular contexual usage questions.
context so the context provides you a clue to the meaning, even 1) Read the highlighted word first; if it is familiar to you try to
if the word is unfamiliar to you. think of a synonym for it before going on to read the
Example 1 sentence or the option.
MORIBUND : By the fourth century A.D, the Roman Civilization 2) If it is not a familiar word, simply read the sentence and try
was already moribund. to understand its meaning from the context. Think of a
(1) extinct (2) forgotten (3) flourishing (4) stagnant word that could suitably take its place.
3) Read the options if one of them is the word you thought
In the context of the given sentence the meaning of the word will of in step 1 or 2, or its close synonym, then choose that as
be stagnant, hence [4]. an answer not before at least glancing at the other options
and trying to see if one of them might be more suitable.
There may be sentences where most or even all of the options are
4) If none of the options is similar to the word you thought
synonymous to the highlighted word, but only one of them fits
of in step 1 or 2, then read all the options and see if any of
the particualr context. This means that you have to be aware of
them suit the context of the sentence.
the very subtle nuances of the words, making contexual usage
more of a challenge to your command over words. 5) If you cannot understand the word from the context of the
sentence or if you have trouble understanding the
More Examples sentence itself, then look at the options. Sometimes the
GELID : It is hard to believe that any life could ever arise in the options can give you a clue, if you know where to look.
gelid environment of Titan. For example, if all the options, except one have a negative
(1) Frigid (2) Suffocation (3) gelatinous (4) hostile / positive connotation then the exception is likely to be
the answer. Also sometimes the words in the options are
Gelid means icycold or frozen. In the context also we can see that much more familiar ones than the question word, so using
gelid can refer to a cold environment where no life can arise. them in the sentence instead of the quesion word should
The answer is [1]. help you eliminate the wrong options.
EXERCISE
ANALOGIES 6. REHEARSAL : PERFORMANCE: :
DIRECTIONS (Qs. 1-51) : Choose the option which contains a (a) Satisfaction : Appetite
pair of words related to each other in the same way as the pair (b) Applause: Audience
given in capital letters. (c) Engagement: Marriage
(d) Entrapment: Game’
1. BACTERIA : ILLNESS : :
(a) Medicine: Germs (b) Calcium: Bones 7. ROOM : HOUSE : :
(c) Knife: Laceration (d) Fire: Explosion (a) Chair : Room (b) Cabin: Ship
2. POETRY : PROSE : : (c) Wheel: Car (d) Cockpit: Plane
(a) Stanza : Chapter (b) Art : Fiction 8. SORROW : DEATH: :
(c) Clause: Sentence (d) Novel: Variation (a) Laugh : Cry (b) Happiness: Birth
3. SIP: GULP : : (c) Fear: Hate (d) Confusion: Anger
(a) Soup : Water (b) Tent: Hut 9. HANDCUFFS : PRISONER : :
(c) Touch: Push (d) Cup: Glass (a) Shoes : Feet (b) Leash: Dog
4. FRAGILE : CRACK: : (c) Tail: Kite (d) Ring: Finger
(a) Irreducible : Reduce
10. ISLAND : OCEAN : :
(b) Cemetery : Death
(a) Hill : Stream (b) Forest: Valley
(c) Hydro: Water
(d) Pliable: Bend (c) Tree: Field (d) Oasis: Desert
5. BOUQUET : FLOWERS: : 11. DRAMA : DIRECTOR : :
(a) Necklace : Beads (b) Door: Handle (a) Movie : Scenario (b) Hope: Optimist
(c) Room: Door (d) Door: Window. (c) Magazine: Editor (d) Anchor: Playwright
EBD_7203
S1-38 GENERAL APTITUDE FOR GATE
12. LOYALTY : TRAITOR : : 26. MALAPROPISM : WORDS
(a) Truthfulness : Liar (a) anachronism : time
(b) Hope : Optimist (b) ellipsis : sentence
(c) Diligence : Worker (c) jinjanthropism : apes
(d) Understanding : Sage (d) catechism : religion
13. LYING : PERJURY 27. ANTERIOR : POSTERIOR
(a) statement : testimony (a) in : out (b) top : bottom
(b) seeing : observing (c) head : tail (d) front : rear
(c) taking : stealing 28. BRICK : BUILDING
(d) eating : dining (a) word : dictionary (b) alphabet : letter
14. PREHISTORIC : MEDIEVAL
(c) platoon : soldier (d) idiom : language
(a) Akbar : British
29. PEEL : PEAL
(b) present : future
(a) coat : rind (b) laugh : bell
(c) Shakespeare : Tennyson
(d) colossus : elephant (c) rain : reign (d) brain : cranium
15. LOUD : STENTORIAN 30. DOGGEREL : POET
(a) mild : noisy (a) symphony : composer
(b) painful : prickly (b) prediction : astrologer
(c) adjective : descriptive (c) wine : vintner
(d) bright : resplendent (d) pulp fiction : novelist
16. BUILDING : STOREY 31. EDITOR : NEWSPAPER : :
(a) book : chapter (b) sentence : adjective (a) Lecturer : University
(c) tree : stem (d) elephant : tusk (b) Teacher : School
17. EASE : ALLEVIATE (c) Nurse : Hospital
(a) hint : allocate (b) revolt : repudiate (d) Architect : Design
(c) collapse : rise (d) question : interogate 32. HORSE : STABLE : :
18. SECRET : CLANDESTINE (a) Hen : Coop (b) Monk : Hermit
(a) overt : furtive (b) covert : stealthy
(c) Fish : Pond (d) Dog : Kennel
(c) open : closed (d) news : rumour
33. OPENING : INAUGURATION : :
19. LIMPID : MURKY
(a) dazed : clouded (b) obscure : vague (a) Memory : Commemoration
(c) bright : gloomy (d) nebulous : dim (b) Display : Exhibition
20. DRAMA : AUDIENCE (c) Admission : Initiation
(a) brawl : vagabonds (d) Solemn : Vestments
(b) obscure : vague 34. ANTLERS : STAG : :
(c) art : critics (a) Mane : Lion (b) Wings : Eagle
(d) movie : actors (c) Hoofs : Horse (d) Horns : Bull
21. LIQUIDITY : GASEOUSNESS 35. INCUBATOR : INFANT : :
(a) serum : fume (b) humid : arid (a) Cooler : Wine (b) Archives : Document
(c) thaw : distil (d) smoke : cloud (c) Hive : Bee (d) Greenhouse : Plant
22. DOUBT : FAITH 36. RUFFLE : COMPOSURE : :
(a) atheist : religious (b) sceptic : pious
(a) Flourish : Prosperity
(c) iconoclast : idol (d) apostate : state
23. FISSION : FUSION (b) Adjusted : Balance
(a) implosion : explosion (c) Upset : Equilibrium
(b) separation : togetherness (d) Flounce : Turmoil
(c) intrusion : extrusion 37. INDIGENT : WEALTH : :
(d) enemy : friend (a) Emaciated : Nourishment
24. ACTION : REACTION (b) Aristocratic : Stature
(a) introvert : extrovert (c) Contented : Happiness
(b) assail : defend (d) Smug : Complacency
(c) diseased : treatment 38. OVATION : APPLAUSE : :
(d) death : rebirth
(a) Grief : Loss (b) Rout : Defeat
25. DULCET : RAUCOUS
(a) sweet : song (c) Triumph : Failure (d) Pathway : Ruin
(b) crazy : sane 39. INVESTMENT : SOUND : :
(c) palliative : exacerbating (a) Technique : Inept (b) Physique : Sturdy
(d) theory : practical (c) Fabric : Silk (d) Intellect : Noble
VERBAL ANALOGIES/ CONTEXUAL USAGE S1-39
40. PLANT : PARASITE : : CONTEXUAL USAGE
(a) Transient : Permanent
DIRECTIONS (Qs. 1-40) : In each of the following questions,
(b) Wild : Prey
out of the given alternatives, choose the one which best expresses
(c) Flora : Fauna (d) Sailor : Pirate
the meaning of the italicised bold part of the sentence.
41. MANAGER : OFFICE : :
(a) Doctor : Patient (b) Curator : Museum 1. Deepak has a penchant for fine poetry.
(c) Bank : Account (d) Fruit : Seed (a) desire (b) bias
42. BRAVE : VALOUR : : (c) liking (d) training
(a) Look : See 2. The number of aboriginal inhabitants in Australia is
(b) Cynic : Doubt considerable.
(c) Man : Management (a) primitive (b) ancient
(d) Thief : Victim
(c) unoriginal (d) irrational
43. TREASURE : CHEST : :
3. The inspector was a vigilant young man.
(a) Money : Account
(b) Coins : Mint (a) smart (b) watchful
(c) Finance : Exchequer (c) ambitious (d) intelligent
(d) Cash : Vault 4. He would have been successful, but for his lack of temerity.
44. WOOL : WARMTH : : (a) audacity (b) sincerity
(a) Radio : Broadcast (c) confidence (d) strength
(b) Person : Success
5. His judicious handling of the matter saved the situation
(c) Marketing : Advertising
from going out of control.
(d) Spring : Elasticity
45. TORCH : LIBERTY : : (a) nervous (b) helpful
(a) Laws : Court (b) Scales : Justice (c) sensible (d) cautious
(c) Balance : Equity (d) Weights : Measure 6. The operator was commended for his dexterity.
46. GREENHOUSE: PLANT : : (a) cooperation (b) courtesy
(a) Incubator : Infant (c) punctuality (d) skill
(b) Hen house : Chicken 7. Few teachers have been spared the problem of an
(c) Hive : Bee opstreperous pupil in the class.
(d) Archives : Document
(a) awkward (b) lazy
47. WHISPER : SPEAK : :
(a) Listen : Bear (b) Request : Ask (c) unruly (d) sullen
(c) Brush : Touch (d) Heat : Chill 8. Many cities were incinerated during the war
48. PHILATELIST : STAMPS : : (a) destroyed (b) shaken
(a) Carpenter : Saw (c) bombed (d) burnt
(b) Runner : Sneakers 9. Ritu asked Rashmi not to meddle in her affairs.
(c) Numismatist : Coins (a) intercede (b) impose
(d) Astrologer : Predictions
(c) cross (d) interfere
49. UMPIRE : GAME : :
(a) Chef : Banquet (b) Legislator : Election 10. His speech was full of affectation.
(c) Moderator : Debate (a) boasting (b) pretence
(d) Prodigy : Wonder (c) pedantry (d) euphemism
50. SIEVE : SIFT : : 11. Gandhiji always advocated the cause of indigenous
(a) Pendant : Neck (b) Crowbar : Pry industries.
(c) Cement : Trowel (d) Scales : Justice (a) foreign (b) big
51. COLT : STALLION : : (c) cottage (d) native
(a) Doe : Stag (b) Dove : Peace
12. The benevolence of the God of Rain has seen a very
(c) Aster : Botanist (d) Calf : Cow
successful monsoon this year too.
52. The question below consists of a pair of related words
followed by four pairs of words. Select the pair that best (a) vision (b) morbidity
expresses the relation in the original pair. (c) kindness (d) ill-will
[GATE 2010, 1mark] 13. I disdain those who tell lies.
Unemployed : Worker (a) condemn (b) scorn
(a) fallow : land (b) unaware : sleeper (c) hate (d) despise
(c) wit : jester (d) renovated : house
EBD_7203
S1-40 GENERAL APTITUDE FOR GATE
14. There is no efficacious remedy to the unemployment 28. The magazine was embellished with amusing articles.
problem in a country which has no ideological convictions. (a) filled (b) replete
(a) suitable (b) possible (c) adorned (d) sprinkled
(c) effective (d) proper 29. It was incumbent on him to report the matter at once.
15. Reading of poetry is not congenial to his taste. (a) pointless (b) depending
(a) suited (b) beneficial (c) pressing (d) optional
(c) helpful (d) preferable 30. Lost in his own revery, he forgot that vicissitudes can change
16. The tour was cancelled on account of incessant rain. the course of man’s life.
(a) constant (b) heavy (a) difficulties (b) changes of fortune
(c) intermittent (d) unexpected (c) impediments (d) good fortunes
17. Sporadic rise in his temperature has caused us much worry. 31. He was annoyed at his flippant remark.
(a) Frequent (b) Irksome (a) discourteous (b) bitter
(c) Irregular (d) Scattered (c) humorous (d) casual
32. War always has a baneful effect on the people of a nation.
18. Ever since the death of his mother, my friend is utterly forlorn
and wretched. (a) unpleasant (b) foul
(a) frustrated (b) lonely (c) pernicious (d) harmful
(c) fearful (d) gloomy 33. The newly found drug on the epidemic was not at all
deleterious.
19. The raucous shout of the audiences forced the management
to call off the show. (a) effective (b) intoxicating
(a) unpleasant (b) loud (c) noxious (d) successful
(c) harsh (d) harmful 34. The problem is tedious to tackle.
20. She has an insatiable love for music. (a) easy (b) difficult
(c) tiring (d) troublesome
(a) undesirable (b) irreconcilable
35. They tolerated him though they disliked his craven
(c) unchanging (d) unsatisfiable
behaviour.
21. Sagacity increases with age.
(a) silly (b) cowardly
(a) Wisdom (b) Love
(c) indecent (d) mean
(c) Maturity (d) Efficiency
36. The President of the party deprecated the move of the
22. He is very discreet while deciding such matters.
Government to introduce electoral reforms in a haste.
(a) obstinate (b) cunning
(a) extricated (b) humiliated
(c) prudent (d) trustworthy
(c) protested (d) welcomed
23. He enjoyed the salubrious climate of the place.
37. He enjoys vicarious authority.
(a) cold (b) temperate
(a) tenuous (b) limited
(c) warm (d) healthful
(c) delegated (d) wide
24. In order to tarnish the public image of his opponent, he has 38. The petals of the flowers are usually conspicuous to attract
got a mendacious story planted in the local newspaper.
birds for pollination.
(a) false (b) fabricated
(a) prominent (b) beautifully shaped
(c) imaginary (d) horrible
(c) colourful (d) scented
25. He listened to her mellifluous music under the genial
39. It was presumptuous of him to make a remark in the assembly.
influence of wine.
(a) ridiculous (b) unthoughtful
(a) heavy (b) stressing
(c) self-confident (d) ambiguous
(c) drowsy (d) sympathetic
40. He spent his whole life caught up in mundane matters.
26. His lascivious habits brought him nothing but bad name
(a) foolish (b) worldly
(a) treacherous (b) erotic (c) inconsequential (d) criminal
(c) lustful (d) vicious 41. Complete the sentence:
27. The aberration in the Indian economy can be attributed to Universalism is to particularism as diffuseness is to
short-sightedness of its political masters. _______________. [GATE 2013, 1 Mark]
(a) deviation (b) steadfastness (a) specificity (b) neutrality
(c) privilege (d) procrastination (c) generality (d) adaptation
VERBAL ANALOGIES/ CONTEXUAL USAGE S1-41
EXERCISE
1. My neighbor’s dogs bark and howl every time their owner (a) The environment created by the meeting between
lets them outside. My CPA told me that dogs tend to bark activist disunity and local difference is ideal for antique
and howl when they see birds resting in the top branches dealers to thrive in India.
of their favorite trees. I personally believe they bark and (b) Only Indians are not proud of their cultural heritage
howl because they enjoy disrupting my meditations. and are hungry for the foreign currency that is easily
Which of the following can be inferred from the preceding available in return of artefacts.
passage? (c) Most Indian families have heirlooms which can be sold
(a) The dogs must be abused by their owners. at high prices to Europeans and Americans.
(b) The dogs’ owners do not care how they are viewed (d) India provides a rich market for unscrupulous antique
by their neighbors. dealers.
(c) There are many pedestrians who walk by this 5. Animals in general are shrewd in proportion as they cultivate
society. Elephants and beavers show the greatest signs of
neighbor’s house, and the dogs are starving for
this sagacity when they are together in large numbers, but
attention.
when man invades their communities they lose all their spirit
(d) The dogs will bark and howl at 3 a.m. if they are outside
of industry. Among insects, the labours of the bee and the
at that time. ant have attracted the attention and admiration of naturalists,
2. Efficiency is all right in its place, in the shop, the factory, the but all their sagacity seems to be lost upon separation, and
store. The trouble with efficiency is that it wants to rule our a single bee or ant seems destitute of every degree of industry.
play as well as our work; it won’t be content to reign in the It becomes the most stupid insect imaginable, and it
shop, it follows us home. languishes and soon dies.
It can be inferred from the above passage that Which of the following can be inferred from the above
(a) Efficiency can become all - pervading passage
(b) Efficiency does not always pay (a) Humankind is responsible for the destruction of the
(c) Efficiency can be more of a torture than a blessing natural habitat of the animals and insects.
(d) None of these (b) Animals, In general, are unable to function effectively
3. The company encourages its managers to interact regularly, outside their normal social environment.
without a pre-set agenda, to discuss issues concerning the (c) Naturalists have great admiration for bees and ants,
company and society. This idea has been borrowed from the despite their lack of industry upon separation.
ancient Indian concept of religious congregation, called (d) Elephants and beavers are smarter than bees and ants
satsang. Designations are forgotten during these mettings; in the presence of human beings.
hence, it is not uncommon in these meetings to find a sales 6. Szymanski suggests that the problem of racism in football
engineer questioning the CEO on some corporate policy or may be present even today. He begins by verifying an earlier
on his knowledge of customers hypothesis tha clubs’ wage bills explain 90% of their
Based on the information provided in the above passage, it performance. Thus, if players’ salaries were to be only based
can be inferred that on their abilities, clubs that spend more should finish higher.
(a) The company is concerned about its reputation with If there is pay discrimination against some group of players-
its employees. fewer teams bidding for black players thus lowering the
(b) The company believes in fostering the spirit of dialogue salaries for blacks with the same ability as whites-that neat
without degenerating it into a position-based debate. relation may no longer hold. He concludes that certain clubs
(c) The company has some inter-personnel problems in seem to have achieved much less than what they could have,
by not recruiting black players.
the past due to which it felt the need for these corporate
Which one of the following findings would best support
satsangs.
Szymanski’s conclusion?
(d) All of the above
(a) Certain clubs took advantage of the situational hiring
4. From Cochin to Shimla, the new culture vultures are tearing above-average shares of black players.
down acres of India’s architectural treasures. Ancestral (b) Clubs hiered white players at relatively high wages
owners often fobbed off with a few hundred rupees for an and did not show proportionately good performance.
exquisitely carved door or window, which fetches fifty times (c) During the study period, clubs in towns with a history
that much from foreign dealers, and yet more from the drawing of discrimination against blacks, under performed
room sophisticates of Europe and the US. The reason for relative to their wage bills
such shameless rape of the Indian architectural wealth can (d) Clubs in one region, which had higher proportions of
perhaps, not wrongly, be attributed to the unfortunate blend black players, had significantly lower wage bills than
of activist disunity and local indifference. their counterparts in another region which had
It can be inferred from the above passage that predominantly white players.
CRITICAL REASONING AND VERBAL DEDUCTION S1-47
7. The pressure on Italy’s 257 jails has been increasing rapidly. (b) The football and hockey players, but not the swimmers,
Those jails are old and overcrowded. They are supposed to were aware at the start of the experiment that they were
hold up to 43,000 people -----9, 000 fewer than now. San Vittore being tested for aggressiveness.
in Milan, which has 1, 800 inmates, is designed for 800. The (c) The same psychological research indicated that the
number of foreigners inside jails has also been increasing. football and hockey players had a great respect for
The minister in charge of prisons fears that tensions may cooperation and team play, whereas the swimmers were
snap, and so has recommended to government an amnesty most concerned with excelling as individual
policy ? competitors.
Which one of the following, if true, would have most (d) The research studies were designed to include no
influenced the recommendation of the minister? college athletes who participated in both contact and
(a) Opinion polls have indicated that many Italians favour non-contact sports.
a general pardon. 10. For our nation to compete successfully in the high
technology enterprises of the future, workers with skills in
(b) The opposition may be persuaded to help since
maths and science will be needed. But it is doubtful that
amnesties must be approved by a two-thirds majority
they will be available, since there is a shortage of high school
in parliament.
maths and science teachers that shows no signs of
(c) During a recent visit to a large prison, the Pope whose
improving. Industry can help alleviate this problem by
pronouncements are taken seriously, appealed for ‘a
funding scholarship grants and aid to college students who
gesture of clemency’ graduate in maths and science with the hope of pursuing
(d) Shortly before the recommendation was made, 58 teaching careers.
prisons reported disturbances in a period of two weeks. Which of the following, if true, would most probably prevent
8. Although in the limited sense of freedom regarding the proposed plan from achieving its intended effect?
appointment and internal working, the independence of the (a) After graduation from college, most maths and science
Central Bank is unequivocally ensured, the same cannot be graduates opt for jobs in industry rather than in
said of its right to pursue monetary policy without co- teaching.
ordination with the central government. The role of the (b) Many high schools have been forced to lower their
Central Bank has turned out to be subordinate and advisory standards in hiring maths and science teachers.
in nature. (c) More scholarship money is already available for
Which one of the following best supports the conclusion students of maths and science than is available for
drawn in the passage? those in any other field.
(a) The decision of the chairman of the Central Bank to (d) Population statistics show that the number of high
increase the bank rate by two percentage points sent school students is expected to decline over the next
shock waves in industry, academic and government ten years.
circles alike. 11. Some scientists believe that, in certain species of birds,
(b) Government has repeatedly resorted to monetisation actual particles of metal within the brain react to the Earth’s
of the debt despite the reservations of the Central magnetic field in the same way as the needle in a compass.
Bank. It is this mechanism that is thought to underlie the
(c) The central Bank does not need the central birds’amazing ability to navigate accurately over distances
government’s nod for replacing soiled currency notes. of thousands of miles by day and night during migration.
(d) The inability to remove coin shortage was a major To test this theory, researchers surgically removed the metal
shortcoming of this government. particles from the heads of some birds and then released
9. Psychological research indicates that college hockey and them, alongwith a number of untreated birds, at the usual
football players are more quickly moved to hostility and time and place of their annual winter migration.
Which of the following results would most seriously weaken
aggression than are college athletes in non-contact sports
the theory being tested?
such has swimming. But the researchers’ conclusion—that
(a) The untreated birds were confused by the erratic flight
contact sports encourage and teach participants to be hostile
patterns of the surgically treated birds and failed to
and aggressive—is untenable. The football and hockey
migrate successfully.
players were probably more hostile and aggressive to start
(b) The surgically treated birds were able to follow their
with, than the swimmers. usual flight patterns successfully by day, but not by
Which of the following, if true, would most strengthen the night.
conclusion drawn by the psychological researchers? (c) The surgically treated birds were able to migrate about
(a) The football and hockey players became more hostile as accurately as the untreated birds.
and aggressive during the season and remained so (d) The surgically treated birds were able to migrate
during the off season, whereas there was no increase successfully only when closely following a group of
in aggressiveness among the swimmers. untreated birds.
EBD_7203
S1-48 GENERAL APTITUDE FOR GATE
12. The argument for liberalisation which answers the worries Which of the following conclusions may be drawn from the
of the Left parties about the possible trade deficits created above experiment?
by the opening up of the Indian economy goes thus: ‘In (a) The ringing of a bell was associated with food in the
today’s economic scenario, where there are many trading mind of the cat.
countries, the trade between two specific countries need (b) Cats and other animals can be easily tricked.
not be balanced. The differing demands of goods and (c) A conclusion cannot be reached on the basis of one
services and the differing productive capabilities of the same experiment.
(d) Two stimuli are stronger than one.
among different countries will cause a country like India to
15. There are many reasons why individuals want to run their
have trade deficits with some countries and surpluses with
own businesses. Some foresee more personal satisfaction
other countries. On the whole, the trade deficits and if they are successful in launching their own business, while
surpluses will balance out in order to give a trade balance’. others are interested mainly in the prospect of large financial
Which of the following conclusions best summarises the rewards. Since 1980s and early 1900s tax regulation and
argument presented in the passage above? liberal policies have encouraged increasing number of
(a) Left parties need not worry about trade deficits in India venture capitalists and entrepreneurs to start new
since its trade will always be in balance even though it enterprises. Since 1990, some one half million new ventures
runs a deficit with a single country. have been started. Not all have succeeded, of course.
(b) India’s trade deficits and surpluses with other countries The above statements make use of which of the following
assumptions ?
always balance out.
(a) Success in starting a new business depends in large
(c) The Left parties in India should not be concerned part on sound financial planning.
about India’s trade deficits with specific countries (b) Venture capitalists are motivated by non monetary
because they will balance out in the long run. gains.
(d) None of these (c) Social incentives motivate investors just as much as
13. Most large retail stores of all goods and brands hold discount financial rewards.
sales in the month of November. The original idea of price (d) Most new business ventures succeed initially but fail
reduction campaigns in November became popular when it later on.
was realized that the sales of products would generally slow 16. “Some men are certainly intelligent, others are certainly
down following the Diwali rush. The lack of demand could not intelligent, but of intermediate men, we should say,
be solved by the simple solution of reducing prices. There “intelligent’ ? Yes, I think, so or no, I shouldn’t be inclined
is now an increasing tendency among major chains of stores to call him intelligent.
across the country to have their “November sales” begin Which of the following most accurately reflects the
intention of the writer of the above?
before Diwali. The idea behind this trend is to endeavour to
(a) Every imperial concept has a degree of vagueness.
sell the maximum amount of stock at a profit, even if that
(b) To call men intelligent who are not strikingly so must
may not be at the maximum profit.
be to use the concept with undue imprecision.
Which of the following conclusions cannot be drawn from (c) Calling someone intelligent or not depends upon
the above? one’s whim.
(a) The incidence of “early” November sales results in (d) There is no need to be as indecisive as the writer of
lower holdings of stocks with the corollary of lower the above.
stock holding costs. 17. Although in the limited sense of freedom regarding
(b) Demand is a function of price; as you lower price, appointment and internal working, the independence of the
demand increases. Central Bank is unequivocally ensured, the same cannot be
(c) Major stores seem to think it makes sense to have the said of its right to pursue monetary policy without co-
ordination with the Central Government. The role of the
November sales campaigns pre-Diwali.
Central Bank has turned out to be subordinate and advisory
(d) The major department stores do not worry as much in nature.
about profit maximization as they do about sales Which one of the following best supports the conclusion
maximization. drawn in the passage?
DIRECTIONS (Qs. 14) : Answer these questions independent of (a) The decision of the Chairman of the Central Bank to
each other. increase the bank rate by two percentage points sent
14. In a famous experiment at the IISC campus, when a cat shock waves in industry, academic and government
smelled milk, it salivated. In the experiment, a bell was rung circles alike
whenever food was placed near the cat. After a number of (b) Government has repeatedly resorted to monetisation
trials, only the bell was rung, whereupon the cat would of the debt despite the reservations of the Central Bank
salivate even though no food was present. Such behaviour (c) The Central Bank does not need the Central
has been observed in other animals such as dogs, monkeys, Government's nod for replacing soiled currency notes
etc. and is a vital input for training domesticated animals. (d) The inability to remove coin shortage was a major
shortcoming of this government
CRITICAL REASONING AND VERBAL DEDUCTION S1-49
18. There are three main factors that control the risks of Which of the following, if true, would most probably prevent
becoming dependent on drugs. These factors are the type the proposed plan from achieving its intended effect?
of drug, th e personality of the individual and the (a) After graduation from college, most maths and science
circumstances in which the drug is taken. Indeed, it could graduates opt for jobs in industry rather than in
be said that the majority of the adult population have taken teaching.
alcohol, yet few have become dependent on it. Also, many (b) Many high schools have been forced to lower their
strong drugs that have been used for medical purposes standards in hiring maths and science teachers.
have not caused the patient to become addicted. However, (c) More scholarship money is already available for
it can be demonstrated that people who have taken drugs students of maths and science than is available for
for fun are more likely to become dependent on the drug. those in any other field.
The dependence is not always physiological but may remain (d) Population statistics show that the number of high
psychological, although the effects are still essentially the school students is expected to decline over the next
same. Those at greatest risk appear to be personalities that
ten years.
are psychopathic, immature, or otherwise unstable.
DIRECTIONS (Qs. 21-24) : In these questions, four alternative
Psychological dependence is very strong with heroin,
morphine, cocaine and amphetamines. Physiological summaries are given below each text. Choose the option that
dependence is great with heroin and morphine, but less best captures the essence of the text.
with amphetamines, barbiturates and alcohol. 21. You seemed at first to take no notice of your school fellows,
Which of the following conclusions can be drawn from the or rather to set yourself against them because they were
text ? strangers to you, they knew as little of you as you did of
(a) One cannot become addicted to certain drugs if one them; this would have been the reason for their keeping
has a strong personality, aloof from you as well, which you would have felt as a
(b) Taking drugs for “kicks” increases the possibility of hardship. Learn never to conceive a prejudice against others
becoming dependent on drugs. because you know nothing of them. It is bad reasoning, and
(c) Psychological dependence is the greatest with heroin.
makes enemies of half the world. Do not think ill of them till
(d) Alcohol is a safe drug since very few people become
they behave ill to you; and then strive to avoid the faults
dependent on it.
which you see in them. This will disarm their hostility sooner
19. The use of petroleum products in the manufacture of plastics
should be regulated and limited by law. Our country’s need than pique of resentment or complaint.
for petroleum for energy production is more vital than our (a) You encountered hardship amongst your school-
need for plastics and our growing dependence on foreign fellows because you did not know them well. You
sources of petroleum could have serious consequences if, should learn to not make enemies because of your
for example, a war cuts off our access to these imports. By prejudices irrespective of their behaviour towards you.
reducing our use of petroleum products in making plastics, (b) The discomfort you felt with your school-fellows was
we can take a major step towards national energy because both sides knew little of each other. Avoid
independence and so enhance our country’s security. prejudice bad behaviour from others, and then win
Which of the following, if true, would most greatly weaken
them over by shunning the faults you have observed.
the argument above ?
(a) Only a small fraction of petroleum products consumed (c) The discomfort you felt with your school-fellows was
in this country is used in making plastics. because both sides knew little of each other. You should
(b) New methods of plastics manufacture can some what not complain unless you find others prejudiced against
reduce the amount of petroleum needed. you and have attempted to carefully analyse the faults
(c) The development of atomic energy as an alternative to you have observed in them.
petroleum-based energy has been slowed by legitimate (d) You encountered hardship amongst your school- fellow
concerns over safety. because you did not know them well. You should learn
(d) In times of war, combatant nations would be seriously to not make enemies because of your prejudices unless
tempted to seize forcibly the territories of petroleum
they behave badly with you.
producing nations.
20. For our nation to compete successfully in the high 22. The human race is spread all over the world, from the polar
technology enterprises of the future, workers with skills in regions to the tropics. The people of whom it is made up eat
maths and science will be needed. But it is doubtful that different kinds of food, partly according to the climate in
they will be available, since there is a shortage of high school which they live, and partly according to the kind of food
maths and science teachers that shows no signs of which their country produces. In hot climates, meat and fat
improving. Industry can help alleviate this problem by are not much need; but in the Arctic regions they seem to be
funding scholarship grants and aid to college students who very necessary for keeping up the heat of the body. Thus,
graduate in maths and science with the hope of pursuing in India, people live chiefly on different kinds of grains,
teaching careers. eggs, milk, or sometimes fish and meat. In Europe, people
EBD_7203
S1-50 GENERAL APTITUDE FOR GATE
eat more meat and less grain. In the Arctic region; where no agents of resource- intensification are given preferential
grains and fruits are produced, the Eskimo and other races treatment by the state, through the grant of generous long
live almost entirely on meat and fish. leases over mineral of fish stocks, for example, of the
(a) In hot countries, people eat mainly grains while in the provision of raw material at an enormously subsidized price,
Arctic, they eat meat and fish because they cannot With the injustice so compounded, local communities at the
grow grains. receiving end of this process, have no resource except direct
(b) Hot climates require people to eat grains while cold action, resisting both' the state and outside exploiters
regions require people to eat meat and fish. through a variety of protest techniques. These struggles
(c) Food eaten by people in different regions of the world might perhaps be seen as a manifestation of a new kind of
depends on the climate and produce of the region, and class conflict.
varies from meat and fish in the Arctic to predominantly (a) Preferential treatment given by the state to agents of
grains in the tropics. resource-intensification for an expanding commercial-
(d) While people in Arctic regions like meat and fish and industrial economy exacerbates injustice to local
those in hot regions like Indian prefer mainly grains, communities and leads to direct protests from them,
they have to change what they eat depending on the resulting in a new type of class conflict.
local climate and the local produce. (b) The grant of long leases to agents of resource
23. Although, almost all climate scientists agree that the Earth intensification for an expanding commercial industrial
is gradually warming, they have long been of two minds economy leads to direct protests from the local
about the process of rapid climate shifts within larger periods community, which sees it as unfair.
of change. Some have speculated that the process works (c) A new kind of class conflict arises from preferential
like a giant oven or freezer, warming or cooling the whole treatment given to agents of resource intensification
planet at the same time. Others think that shifts occur on by the state , which the local community sees as unfair.
opposing schedules in the Northern and Southern (d) Local communities have no option but to protest
Hemispheres, like exaggerated seasons. Recent research in against agents of resource- intensification and create
Germany examining climate patterns in the Southern a new type of class conflict when they are given raw
Hemisphere at the end of the last Ice Age strengthens the material at subsidized prices for an expanding
idea that warming and cooling occurs at alternate times in commercial-industrial economy.
the two hemispheres. A more definitive answer to this debate 25. Modern warfare has changed from large, scale clashes of
will allow scientists to better predict when and how quickly armies to suppression of civilian populations. Chemical
the next climate shift will happen. agents that do their work silently appear to be suited to
(a) Research in Germany will help scientists find a definitive such warfare; and regretfully, there exist people in military
answer about warming and cooling of the Earth and establishments who think that chemical agents are useful
predict climate shifts in the future in a better manner. tools for their cause. [GATE 2010, 2 Marks]
(b) Scientists have been unsure whether rapid shifts in Which of the following statements best sums up the
the Earth's climate happen all at once or on opposing meaning of the above passage :
schedules in different hemispheres; finding a definitive (a) Modern warfare has resulted in civil strife
answer will help them better predict climate shift in (b) Chemical agents are useful in modern warfare
future. (c) Use of chemical agents in warfare would be undesirable
(c) Scientists have been unsure whether rapid shifts in (d) People in military establishments like to use chemical
the Earth's climate happen all at once or on opposing agents in war
schedules in different hemispheres; research will help 26. Few school curricula include a unit on how to deal with
find a definitive answer and better predict climate shift bereavement and grief, and yet all students at some point in
in future. their lives suffer from losses through death and parting.
(d) More research rather than debates on warming or Based on the above passage which topic would not be
cooling of the Earth and exaggerated seasons in its included in a unit on bereavement? [GATE 2011, 2 Marks]
hemispheres, will help scientists in Germany predict (a) how to write a letter of condolence
climate changes better in future. (b) what emotional stages are passed through in the
24. Local communities have often come in conflict with agents healing process
trying to exploit resources, at a faster pace for an expanding (c) what the leading cause of death are
commercial-industrial economy. More often than not, such (d) how to give support to a grieving friend
CRITICAL REASONING AND VERBAL DEDUCTION S1-51
27. Wanted Temporary, Part-time persons for the post of Field (a) The Palghat gap is caused by high rainfall and high
Interviewer to conduct personal interviews to collect and temperatures in southern Tamil Nadu and Kerala
collate economic data. Requirements : High School – pass, (b) The regions in Tamil Nadu and Kerala that are near
must be available for Day. Evening and Saturday work. the Palghat Gap are low-lying
Transportation paid, expenses reimbursed. (c) The low terrain of the Palghat Gap has a significant
Which one of the following is the best inference from the impact on weather patterns in neighbouring parts of
above advertisement ? [GATE 2012, 2 Marks] Tamil Nadu and Kerala
(a) Gender – discriminatory (d) Higher summer temperatures result in higher rainfall
near the Palghat Gap area
(b) Xenophobic
31. Geneticists say that they are very close to confirming the
(c) Not designed to make the post attractive
genetic roots of psychiatric illnesses such as depression
(d) Not gender – discriminatory
and schizophrenia, and consequently, that doctors will be
28. After several defeats in wars, Robert Bruce went in exile able to eradicate these diseases through early identification
and wanted to commit suicide. Just before committing and gene therapy.
suicide, he came across a spider attempting tirelessly to On which of the following assumptions does the statement
have its net. Time and again, the spider failed but that above rely? [GATE 2014, Set-1, 2 Marks]
did not deter it to refrain from making attempts. Such (a) Strategies are now available for eliminating psychiatric
attempts by the spider made Bruce curious. Thus, Bruce illnesses
started observing the near-impossible goal of the spider (b) Certain psychiatric illnesses have a genetic basis
to have the net. Ultimately, the spider succeeded in (c) All human diseases can be traced back to genes and
how they are expressed
having its net despite several failures. Such act of the
(d) In the future, genetics will become the only relevant
spider encouraged Bruce not to commit suicide. And
field for identifying psychiatric illnesses
then, Bruce went back again and won many a battle, and
32. Choose the most appropriate phrase from the options given
the rest is history.
below to complete the following sentence.
Which one of the following assertions is best supported
India is a post-colonial country because
by the above information? [GATE 2013, 2 Marks]
[GATE 2014, Set-2, 1 Mark]
(a) Failure is the pillar of success. (a) it was a former British colony
(b) Honesty is the best policy. (b) Indian Information Technology professionals have
(c) Life begins and ends with adventures. colonized the world
(d) No adversity justifies giving up hope. (c) India does not follow any colonial practices
29. In a press meet on the recent scam, the minister said, “The (d) India has helped other countries gain freedom
buck stops her”. What did the minister convey by the 33. The old city of Koenigsberg, which had a German majority
population before World War 2, is now called Kaliningrad.
statement? [GATE 2014, Set-1, 1 Mark]
After the events of the war, Kaliningrad is now a Russian
(a) He wants all the money
territory and has a predominantly Russian population. It is
(b) He will return the money
bordered by the Baltic Sea on the north and the countries of
(c) He will assume final responsibility
Poland to the south and west and Lithuania to the east
(d) He will resist all enquiries
respectively. Which of the statements below can be inferred
30. The Palghat Gap (or Palakkad Gap), a region about 30 km
from this passage? [2014, Set-2, 2 Marks]
wide in the southern part of the Western Ghats in India, is (a) Kaliningrad was historically Russian in its ethnic makeup
lower than the hilly terrain to its north and south. The exact (b) Kaliningrad is a part of Russia despite it not being
reasons for the formation of this gap are not clear. It results contiguous with the rest of Russia
in the neighbouring regions of Tamil Nadu getting more (c) Koenigsberg was renamed Kaliningrad, as that was
rainfall from the South West monsoon and the neighbouring its original Russian name
regions of Kerala having higher summer temperatures. (d) Poland and Lithuania are on the route from Kaliningrad
What can be inferred from this passage? to the rest of Russia
[GATE 2014, Set-1, 2 Marks]
EBD_7203
S1-52 GENERAL APTITUDE FOR GATE
34. By the beginning of the 20th century, several hypotheses (ii) Paradigm shifts usually occur at the beginning of
were being proposed, suggesting a paradigm shift in our centuries
understanding of the universe. However, the clinching (iii) Stars are important objects in the universe
evidence was provided by experimental measurements of (iv) Experimental evidence was important in confirming
the position of a star which was directly behind our sun. this paradigm shift [GATE 2014, Set-3, 2 Marks]
Which of the following inference(s) may be drawn from the (a) (i), (ii) and (iv) (b) (iii) only
above passage? (c) (i) and (iv) (d) (iv) only
(i) Our understanding of the universe changes based on
the positions of stars
CRITICAL REASONING AND VERBAL DEDUCTION S1-53
1 Number System
TYPES OF NUMBERS : R+ : Positive real numbers and
Natural Numbers R– : Negative real numbers.
These are the numbers (1, 2, 3, etc.) that are used for counting. Real numbers = Rational numbers + Irrational numbers.
It is denoted by N.
There are infinite natural numbers and the smallest natural DIVISIBILITY RULES
number is one (1). Divisibility by 2 : A number is divisible by 2 if its unit’s digit is
Even numbers : Natural numbers which are divisible by 2 are even even or 0.
numbers.
Divisibility by 3 : A number is divisible by 3 if the sum of its
It is denoted by E.
digits are divisible by 3.
E = 2, 4, 6, 8,...
Smallest even number is 2. There is no largest even number. Divisibility by 4 : A number is divisible by 4 if the last 2 digits
Odd numbers : Natural numbers which are not divisible by 2 are are divisible by 4, or if the last two digits are 0’s.
odd numbers. Divisibility by 5 : A number is divisible by 5 if its unit’s digit is
It is denoted by O. 5 or 0.
O = 1, 3, 5, 7, ... Divisibility by 6 : A number is divisible by 6 if it is simulta-
Smallest odd number is 1. neously divisible by 2 and 3.
There is no largest odd number. Divisiblity by 7 : A number is divisible by 7 if unit’s place digit
Prime Numbers : Natural numbers which have exactly two is multiplied by 2 and subtracted from the remaining digits and
factors, i.e., 1 and the number itself are called prime numbers. the number obtained is divisible by 7.
The lowest prime number is 2. Divisibility by 8 : A number is divisible by 8 if the last 3 digits of
2 is also the only even prime number. the number are divisible by 8, or if the last three digits of a
Composite Numbers : It is a natural number that has atleast one number are zeros.
divisor different from unity and itself. Divisibility by 9 : A number is divisible by 9 if the sum of its
Every composite number can be factorised into its prime digits is divisible by 9.
factors. Divisibility by 10 : A number is divisible by 10 if its unit’s
For Example : 24 = 2 × 2 × 2 × 3. Hence, 24 is a composite digit is 0.
number. Divisibility by 11 : A number is divisible by 11 if the sum of
The smallest composite number is 4. digits at odd and even places are equal or differ by a number
Whole Numbers : The natural numbers along with zero (0), form divisible by 11.
the system of whole numbers. Divisibility by 12 : A number is divisible by 12 if the number is
It is denoted by W. divisible by both 4 and 3.
There is no largest whole number and Divisibility by 13 : A number is divisible by 13 if its unit’s place
The smallest whole number is 0. digit is multiplied by 4 and added to the remaining digits and
Integers : The number system consisting of natural numbers, the number obtained is divisible by 13.
their negative and zero is called integers. Divisibility by 14 : A number is divisible by 14 if the number is
It is denoted by Z or I. divisible by both 2 and 7.
The smallest and the largest integers cannot be determined. Divisibility by 15 : A number is divisible by 15 if the number is
The number line : The number line is a straight line between divisible by both 3 and 5.
negative infinity on the left to positive infinity on the right.
Divisibility by 16 : A number is divisible by 16 if its last 4 digits
is divisible by 16 or if the last four digits are zeros.
-4 -3 -2 -1 0 1 2 3 4
Divisibility by 17 : A number is divisible by 17 if its unit’s place
Real Numbers : All numbers that can be represented on the
number line are called real numbers. digit is multiplied by 5 and subtracted from the remaining digits
and the number obtained is divisible by 17.
It is denoted by R.
EBD_7203
S1-56 GENERAL APTITUDE FOR GATE
Divisibility by 18 : A number is divisible by 18 if the number is Example 3 :
divisible by both 2 and 9. Find the H.C.F. of 324, 630 and 342 by division method.
Divisibility by 19 : A number is divisible by 19 if its unit’s place
digit is multiplied by 2 and added to the remaining digits and Solution : 324 630 1
the number obtained is divisible by 19. 324
DIVISIONALGORITHM 306 324 1
Dividend = (Divisor × Quotient) + Remainder 306
18 306 17
Method to find the number of different divisors (or factors) 306
(including 1 and itself) of any composite number N : ×
STEP I : Express N as a product of prime numbers as
N = xa × yb × zc ......... 18 342 19
STEP II : Number of different divisors (including 1 and itself) 342
×
= (a + 1)(b + 1)(c + 1) ........
HCF AND LCM \ H.C.F. of 324, 630 and 342 is 18.
Highest common factor : The highest common factor (H.C.F.) of Least common multiple : The least common multiple (L.C.M.)
two or more numbers is the greatest number which divides each of two or more numbers is the smallest number which is
of them exactly. It is also known as greatest common divisor exactly divisible by each of them.
(G.C.D.). L.C.M. can be calculated by :
H.C.F. can be calculated by : (i) Prime factorisation method
(ii) Division method
(i) Prime factorisation method
(i) L.C.M. by prime factorisation method :
(ii) Division method Example 4 :
(i) H.C.F. by prime factorisation method : Find the L.C.M. of 12 and 20 by prime factorization method.
Example 1 : Solution :
Find the H.C.F. of 40 and 60 by prime factorisation method. 12 = 2 × 2 × 3 and 20 = 2 × 2 × 5
Solution : \ L.C.M = 2 × 2 × 3 × 5 = 60.
Prime factors of 40. (ii) L.C.M. by division method :
Example 5 :
2 40
2 20 Find the L.C.M. of 14, 56, 91 and 84.
2 10 \ 40 = 2E55
´F2 ´ 2 ´ 5|
Solution : 2 14, 56, 91, 84
55
1 2 7, 28, 91, 42
Prime factors of 60 7 7, 14, 91, 21
1, 2, 13, 3
2 60
2 30 \ L.C.M = 2 × 2 × 7 × 2 × 13 × 3 = 2184.
3 15 \ 60 = 2E55
´F2 ´ 3 ´ 5|
55 H.C.F. AND L.C.M. OF FRACTIONS :
1 First express the given fractions in their lowest terms.
Hence H.C.F. = 2 × 2 × 5 = 20. Then,
(ii) H.C.F by Division method : H.C.F. of numerators
H.C.F. =
Example 2 : L.C.M. of denominators
Find the H.C.F. of 140 and 200 by division method.
L.C.M. of numerators
L.C.M. =
Solution : 140 200 1 H.C.F. of denominators
140 Formula:
60 140 2
120 H.C.F. of numbers × L.C.M. of numbers = Product of numbers
20 60 3
60
× NOTE :
• The greatest number that will exactly divide x, y, z = HCF
\ H.C.F. of 140 and 200 = 20. of x, y and z.
H.C.F. of three numbers by division method :
NUMBER SYSTEM S1-57
• The greatest number that will divide x, y and z leaving (v) Sum of cubes of first n natural numbers,
remainders a, b and c respectively = HCF of (x – a), (y – b) n 2
and (z – c ). å r3 = éê n (n + 1) ùú
• The least number which is exactly divisible by x, y and z r =1 ë 2 û
= LCM of x, y and z. Arithmetic Mean (A.M)
• The least number which when divided by x, y and z leaves The A.M. between the two given quantities a and b is A if a, A, b
the remainder a, b and c respectively= LCM of(x, y and are in A.P.
z)–R where R = (x – a) = (y – b) = (z – c) a+b
i.e. A – a = b – A Þ A =
• The least number which when divided by x, y and z leaves 2
the same remainder r in each case = LCM of (x, y and z) + r Note:
• The greatest number that will divide x, y and z leaving the A.M. of any n positive numbers a1, a2, .........., an is
same remainder in each case = HCF of (x – y), (y – z) and a1 + a2 + a3 + .....an
A=
(z – x). n
Arithmetic Progression (A.P.) Geometric Progression (G.P.)
The sequence < x1, x2, x3, ...., xn, .... > is called an Arithmetic If 'a' is the first term and 'r' is the common ratio, then a G.P. can be
progression (A.P.), if x2 – x1 = x3 – x2 = x4 – x3 = ...... = xn – xn–1 = written as, a, ar, ar2, ar3, ........ .
....... In general (xn – xn–1) = constant, n Î N. This constant Note that a, b, c are in G. P. Û b2 = ac
difference is called Common Difference . If 'a' is the first term and General term of a G. P. :
'd' is the common difference, then the A.P. can be written as General term (nth term) of a G.P. is given by Tn = arn–1
Sum of n terms of a G. P. :
a + (a + d) + (a + 2d) + (a + 3d) + ...... + {a + (n – 1)d} + .....
The sum of first n terms of a G.P. is given by
Note that a, b, c are in AP Û 2b = a + c
General Term of an AP: a (1 - r n ) a - r Tn
Sn = = , when r < 1
General term (i.e. nth term) of an AP is given by 1- r 1- r
Tn = a + (n – 1) d
a(r n - 1) rTn - a
NOTE : or Sn = = , when r > 1
(i) If a sequence has n terms, then its nth term is also denoted r -1 r -1
by l, which indicate last term and Sn = na, when r = 1
(ii) Common difference can be zero, + ve or – ve. Sum of an infinite G. P. :
(iii) If there are n terms in an A.P, then mth term from end The sum of an infinite G.P. with first term a and common ratio r
= (n – m + 1)th term from beginning. such that | r | < 1,
a
S¥ =
Sum of first n terms of an AP: 1- r
The sum of first n terms of an A.P. is given by Geometric mean (g. m.)
n n If G be the G.M. between two given quantities a and b then a, G, b,
Sn = [2a + (n – 1) d] or Sn = [a + Tn]
2 2 are in G.P.
n
or Sn = (a + l ) G b
=
2 i.e. Þ G2 = ab Þ G = ab
Some standard results: a G
(i) Sum of first n natural numbers, Harmonic Progression (H.P)
n If reciprocal of each term of a progression are in A.P., then the
å r = n (n + 1) progression is called Harmonic progression.
r =1 2 The standard form of a H.P. is
n 1 1 1
(ii) Sum of first n odd natural numbers, å (2r - 1) = n2 , , , ......
a a + d a + 2d
r =1
(iii) Sum of first n even natural numbers, General Term of a H.P.
General term or nth term of a H.P. is given by
n
1
å 2r = n (n + 1) Tn =
a + (n - 1)d
r =1
HARMONIC MEAN
(iv) Sum of squares 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
å r2
=
n ( n + 1)(2 n + 1)
2ab
r =1 6 H=
a+b
EBD_7203
S1-58 GENERAL APTITUDE FOR GATE
EXERCISE
1. The LCM and HCF of two numbers are 84 and 21, 11. There are four prime numbers written in ascending order.
respectively. If the ratio of two numbers be 1 : 4, then the The product of the first three is 385 and that of the last
larger of the two numbers is : three is 1001. The first of the prime numbers is :
(a) 21 (b) 48 (a) 5 (b) 7
(c) 84 (d) 108 (c) 19 (d) 17
2. If one-third of a number is 3 more than one -fourth of the 12. A positive integer, which added to 1000, gives a sum
number, then the number is : which is greater than the product obtained when it is
(a) 18 (b) 24
multiplied by 1000. The positive integer is :
(c) 30 (d) 36
(a) 1 (b) 5
3. Which of the following pair of fractions adds up to a
number greater than 5 ? (c) 2 (d) 3
13 11 11 8 3 2
(a) , (b) , 13. Of the 120 people in the room, are women. If of
5 6 4 3 5 3
the people are married, then what is the maximum number
7 11 5 3
(c) , (d) , of women in the room who are unmarried?
3 5 3 4 (a) 40 (b) 50
4. The number of 3-digit number exactly divisible by 5 is : (c) 60 (d) 80
(a) 181 (b) 180 14. How many odd numbered pages are there in a book of
(c) 179 (d) 199 1089 pages ?
5. A boy was asked to write 25 ´ 9 2 but he wrote 2592. The (a) 545 (b) 544
(c) 543 (d) 547
numerical difference between the two is:
(a) 0 (b) 3 15. If p is a prime number greater than 3, then (p 2 - 1) is
(c) 2 (d) 9 always divisible by :
6. How many of the following numbers are divisible by (a) 6 but not 12 (b) 24
132 ? (c) 12 but not 24 (d) None of these
264, 396, 4, 762, 792, 968, 2178, 5184, 6336 16. Three friends divided some bullets equally. After each of
(a) 4 (b) 5 them shot 4 bullets, the total number of bullets remaining
(c) 6 (d) 7 is equal to the bullets each had after division . Find the
7. In a class, 20 opted for Physics, 17 for Maths, 5 for both original number of bullets:
and 10 for other subjects. The class contains how many (a) 15 (b) 17
students? (c) 20 (d) 18
(a) 35 (b) 42 17. Four bells begin to toll together and toll respectively at
(c) 52 (d) 60 intervals of 6, 5, 7, 10 and 12 seconds. How many times they
8. Find the number which, when added to itself 13 times, will toll together in one hour excluding the one at the start ?
gives 112. (a) 7 times (b) 8 times
(a) 9 (b) 7 (c) 9 times (d) 11 times
(c) 8 (d) 11 18. HCF of 3240, 3600 and a third number is 36 and their LCM
9. Given, n = 1 + x, where x is the product of four consecutive is 2 4 ´ 35 ´ 5 2 ´ 7 2 . The third number is :
integers. Then which of the following is true ?
(a) 2 4 ´ 53 ´ 7 2 (b) 2 2 ´ 35 ´ 7 2
A. n is an odd integer
B. n is prime. (c) 2 3 ´ 35 ´ 7 2 (d) 25 ´ 52 ´ 7 2
19. If x and y are negative, then which of the following
C. n is a perfect square
statements is/are always true ?
(a) Both A and C are correct. I. x + y is positive
(b) Both A and B are correct. II. xy is positive
(c) Only A is correct III. x – y is positive
(d) Only C is correct (a) I only (b) II only
(c) III only (d) I and II only
10. How many five-digit multiples of 11 are there, if the five
20. The LCM of two numbers is 4800 and their HCF is 160.
digits 3, 4, 5, 6 and 7 are in the same order ?
If one of the numbers is 480, then the other number is :
(a) 12 (b) 13 (a) 16 (b) 16000
(c) 10 (d) None of these (c) 160 (d) 1600
NUMBER SYSTEM S1-59
21. What is the value of M and N respectively if M39048458N 31. A number when divided by 765 leaves a remainder 42. What
is divisible by 8 and 11, where M and N are single digit will be the remainder if the number is divided by 17 ?
integers? (a) 8 (b) 7
(a) 7, 4 (b) 8, 6 (c) 6 (d) 5
(c) 6, 4 (d) 3, 2 32. The traffic lights at three different road crossings change
22. The LCM of two numbers is 280 and their ratio is 7 : after every 48 seconds, 72 seconds and 108 seconds
8. The two numbers are : respectively. If they all change simultaneously at 8 : 20 hours,
(a) 70, 80 (b) 54, 68 then at what time will they again change simultaneously ?
(c) 35, 40 (d) 28, 36 (a) 8 : 20 : 08 hrs (b) 8 : 24 : 10 hrs
23. What is the third term in a sequence of numbers that (c) 8 : 27 : 12 hrs (d) 8 : 30 : 15 hrs
leave remainders of 1, 2 and 3 when divided by 2, 3 and 33. The circumferences of the fore and hind-wheels of a carriage
4, respectively ?
(a) 13 (b) 17 2 3
are 2 and 3 respectively. A chalk mark is put on the
(c) 19 (d) 35 5 7
24. A man has a certain number of small boxes to pack into point of contact of each wheel with the ground at any given
parcels. If he packs 3, 4, 5 or 6 boxes in a parcel, then he is moment. How far will the carriage have travelled so that its
left with only one. If he packs 7 boxes in a parcel, then none chalk marks may be again on the ground at the same time?
is left over. What is the number of boxes that he must pack? (a) 26 m (b) 16 m
(a) 106 (b) 301 (c) 24 m (d) 42 m
(c) 309 (d) 400 34. Find the value of 13 + 23 + 33 + ... + 153.
25. On Monday, a certain animal shelter housed 55 cats and (a) 11025 (b) 13400
dogs. By Friday, exactly 1/5 of the cats and 1/4 of the dogs (c) 900 (d) 14400
had been adopted; no new cats or dogs were brought to the 35. The sum of 40 terms of an AP whose first term is 4 and
shelter during this period. What is the greatest possible common difference is 4, will be :
(a) 3280 (b) 1600
number of pets that could have been adopted from the animal (c) 200 (d) 2800
shelter between Monday and Friday ? 36. What is the next number in the series given below?
(a) 11 (b) 12 53, 48, 50, 50, 47
(c) 13 (d) 14 (a) 51 (b) 46
26. Determine the value of ............... (c) 53 (d) 52
37. The value of (13 + 23 + 33 + .... + 153) – (1 + 2 + 3 + .... 15) is
1 1 1 1
+ + + ....... + (a) 14280 (b) 14400
1+ 2 2+ 3 3+ 4 120 + 121 (c) 12280 (d) 13280
38. Let Sn denote the sum of the first ‘n’ terms of an AP in which
(a) 120 (b) 10
S3n
(c) 12 12 (d) 8 S2n = 3Sn. Then, the ratio of is equal to:
Sn
27. The numbers 1 to 29 are written side by side as follows
1234567891011............................ 28 29 (a) 4 (b) 6
If the number is divided by 9, then what is the remainder ? (c) 8 (d) 10
(a) 3 (b) 1 P+Q P
(c) 0 (d) None of these 39. What is the value of , if =7 ?
28. The H.C.F. and L.C.M. of two numbers are 21 and 4641 P-Q Q
respectively. If one of the numbers lies between 200 and
4 2
300, then the two numbers are (a) (b)
(a) 273, 357 (b) 273, 361 3 3
(c) 273, 359 (d) 273, 363 2 7
29. The letters L, M, N, O, P, Q, R, S and T in their order are (c) (d)
6 8
substituted by nine integers 1 to 9 but not in that order. 4 is
assigned to P. The difference between P and T is 5. The 40. If G be the geometric mean of x and y, then
difference between N and T is 3. What is the integer assigned 1 1
to N? + =
2 2
G -x G - y2
2
(a) 4 (b) 5
(c) 6 (d) 7 1
30. If 11,109,999 is divided by 1111, then what is the remainder? (a) G2 (b)
(a) 1098 (b) 11888 G2
(c) 1010 (d) 1110 2
(c) (d) 3G2
G2
EBD_7203
S1-60 GENERAL APTITUDE FOR GATE
41. The number of common terms to the two sequences 17, 21, 49. Sum of n terms of the series
25, ....., 417 and 16, 21, 26, ........, 466 is – 8 + 88 + 888 + .... equals
(a) 19 (b) 20
(c) 21 (d) 91 8 8
(a) [ 10n+1 – 9n – 10] (b) [ 10n – 9n – 10]
81 81
42. If the sum of the first 2n terms of 2, 5, 8, ....... is equal to
the sum of the first n terms of 57, 59, 61......., then n is
8
equal to – (c) [10n+1 – 9n + 10] (d) None of these
81
(a) 10 (b) 12
(c) 11 (d) 13 50. Sum of n terms of series 12 + 16 + 24 + 40 + ... will be
43. The arithmetic mean of the series (a) 2 (2n – 1) + 8n (b) 2(2n – 1) + 6n
1, 2, 4, 8, 16, ...............2n is (c) 3 (2n – 1) + 8n (d) 4(2n – 1) + 8n
51. The sum of n terms of the series 22 + 42 + 62 +........ is
2n - 1 2n + 1 - 1
(a) (b)
n n +1 n( n + 1)(2n + 1) 2n(n +1)(2n +1)
(a) (b)
3 3
2n + 1 2n - 1
(c) (d) n( n + 1)(2n + 1) n(n + 1)(2n + 1)
n +1 n +1 (c) (d)
6 9
44. How many integers between 100 and 150, both inclusive,
can be evenly divided by neither 3 nor 5? 52. The sum of the first n terms of the series
(a) 33 (b) 28
12 + 2.2 2 + 3 2 + 2.4 2 + 5 2 + 2.6 2 + ...
(c) 27 (d) 26
45. A sequence is generated by the rule that the n th term is n(n + 1)2
n2 + 1 for each positive integer n. In this sequence, for any is when n is even. When n is odd the sum is
2
value n > 1, the value of (n + 1)th term less the value of nth
term is 2
é n(n + 1) ù n2 (n + 1)
(a) 2n2 + 1 (b) n2 + 1 (a) êë 2 úû (b)
2
(c) 2n + 1 (d) n+ 2
46. The sum to n terms of the series
n(n + 1)2 3n(n + 1)
(c) (d)
1 3 7 15 4 2
+ + + + .............. is
2 4 8 16 53. The nth term of the series
(a) n – 1 – 2 – n (b) 1 (1 + 2) (1 + 2 + 3)
1+ + + ... is equal to
2 3
(c) n – 1 + 2 – n (d) 1 + 2– n
47. The sum to infinity of the progression (n + 1)(2 n + 1)
(a) n2(n – 1) (b)
2
1
9 – 3 + 1 – + ¼ is :
3 n +1 n(n + 1)
(c) (d)
(a) 9 (b) 9/2 2 2
(c) 27/4 (d) 15/2 54. 2 + 4 + 7 + 11 + 16 + ........ to n terms =
48. The sum of infinite terms of the geometric
1 2 n 2
2 +1 1 1 (a) (n + 3n + 8) (b) (n + 3n + 8)
progression , , ........ is 6 6
2 -1 2 - 2 2
1 2 n 2
(c) (n - 3n + 8) (d) (n - 3n + 8)
(a) 2( 2 + 1) 2 (b) ( 2 + 1)2 6 6
(c) 5 2 (d) 3 2+ 5
NUMBER SYSTEM S1-61
55. If 137 + 276 = 435 how much is 731 + 672? 59. 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
probability that the selected number is not divisible by 7?
(a) 534 (b) 1403
[GATE 2013, 2 Marks]
(c) 1623 (d) 1513
56. 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
57. What will be the maximum sum of 44, 42, 40, _______ ? 60. If (z + 1/z)2 = 98, compute (z2 + 1/z2).
[GATE 2013, 1 Mark] [GATE 2014, Set-1, 1 Mark]
(a) 502 (b) 504 61. When a point inside of a tetrahedron (a solid with four
(c) 506 (d) 500 triangular surfaces) is connected by straight lines to its
58. 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
+ + + ........ + . 62. 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
EBD_7203
S1-62 GENERAL APTITUDE FOR GATE
æ 12 24 ö Sn 2an 2 n + 1 1 S
33. (c) Required distance = L.C.M of ç , ÷ Þ = ´ = or 3n = 6
è 5 7 ø S3n n + 1 12an 2 6 Sn
L.C.M.of(12,24) 24 P
= = m +1
H.C.F.of (5, 7) 1 P+Q Q 7 +1 8 4
39. (a) = = = =
Hence, carriage will travelled 24m so that its chalk marks P-Q P 7 -1 6 3
-1
may be again on the ground at the same time. Q
34. (d) We have, sum of the cubes of n natual
2
40. (b) As given G = xy
é n( n + 1) ù
numbers = ê ú 1 1 1 1
ë 2 û \ + = +
2 2 2 2 2
2
G -x G -y xy - x xy - y 2
é 15 (15 + 1) ù
\ 13 + 23 + 33 + .... + 153 = ê ú = 14400 1 ì 1 1ü 1 1
ëê 2 ûú = í- + ý = =
x - y î x y þ xy G 2
n
35. (a) S40 = [2a + (n – 1)d] = 20 (2 × 4 + 39 × 4) 41. (b) Common terms will be 21, 41, 61, ........
2 21 + (n – 1) 20 £ 417 Þ n £ 20.8 Þ n = 20
= 20 × 164 = 3280
2n n
36. (d) 53, 48, 50, 50, 47, .......... 42. (c) Given, {2.2 + (2n - 1)3} = {2.57 + ( n - 1)2}
The sequence consists of two sequences, one 2 2
descending and the other ascending. or 2 (6n + 1) = 112 + 2n or 10n = 110 \ n = 11
53, 50, 47, ..... is descending while 48, 50, ..... is 43. (b) Required arithmetic mean
ascending. Hence the next term would be 52. Sum of the (n + 1) terms of the given series
=
37. (a) (13 + 23 + 33 + .... + 153) – (1 + 2 + 3 + .... 15) n +1
2
é15(15 + 1) ù é15(15 + 1) ù 1.(2n +1 - 1)
=ê ú –ê ú
ë 2 û ë 2 û 2 -1 2n +1 - 1
= =
n +1 n +1
é 3 2
é n(n +1) ù ù
êQ 1 + 23 + 33 + .... + n 3 = ê ú 44. (c) The number of integers from 100 to 150 is 51.
êë ë 2 úû úû The numbers divisible by 3 are 102, 105, ..... 150
These are 17 numbers (calculated by A.P. rule)
é15 ´ 16 ù
2
é15 ´ 16 ù Similarly, the numbers divisible by 5 are 100, 105,......,
=ê ú –ê 2 ú 150. These are 11 numbers
ë 2 û ë û
And the numbers divisible by 15 are 105, 120, ...., 150.
= (120)2 – (120) = 120 × 119 = 14280 These are 4 numbers. These 4 numbers are also
38. (b) Let a be the first term and the common difference be d. included in the numbers that are divisible by 3 or 5.
n
[2a + (n – 1)d] , So the number of integers that are divisible by 3 or 5
Now, Sn =
2 is 17 + 11 – 4 = 24
Hence the number of integers divisible by neither 3
2n
S2 n = [2a + (2n – 1)d ] or 5 = 51 – 24 = 27
2
2 2
3n 45. (c) (n +1)th term – nth term = (n + 1) + 1 - (n + 1)
and S3n = [2a + (3n – 1)d]
2 = n 2 + 2n + 1 + 1 - n 2 - 1 = 2n + 1
We have, S2n = 3Sn 1 3 7 15
46. (c) + + + + ...
2n 2 4 8 16
Þ [2a + (2n – 1)d ] = 3 n [2a + (n – 1)d]
2 2
æ 1 ö æ 1 ö æ 1ö æ 1ö
or 4a + (4n – 2)d = 6a + (3n – 3) d = ç1 - ÷ + ç1 - ÷ + ç1 - ÷ + ç1 - ÷ + ....
è 2 ø è 4 ø è 8 ø è 16 ø
2a
or d (4n – 2 – 3n + 3) = 2a or d =
n +1 1ì 1ü
í1 - n ý
2 2 2î 2 þ
Therefore, Sn =
2an
and S3n =
12an = n- = n - 1 + 2- n
n +1 n +1 1
1-
2
NUMBER SYSTEM S1-65
47. (c) Given series is, Sn = T1 + T2 + T3 + .... +Tn
1 = (22 + 23 + 24 + ..... upto n terms)+ (8 + 8 + 8 + ....
9 – 3 + 1 - + ¼ an infinite GP upto n terms)
3
1 22 (2n – 1)
Here a = 9, r = - = + 8n = 4(2n – 1) + 8n.
3 2 –1
Where a = first term and r = common ratio 51. (b) 22 + 42 + 62 + ......+ (2n2)
1 (n - 1)(n - 1 + 1)2
Common ratio of the series =
2( 2 + 1) = + n2
2
2
æ n - 1 ö 2 n (n + 1)
( 2 + 1) 2( 2 + 1) =ç + 1÷ n =
= . = 2( 2 + 1) 2 è 2 ø 2
( 2 - 1) (1 + 2)
8 (1 + 2) (1 + 2 + 3)
53. (c) Given series is 1 + + + ...
49. (a) Sum = [ 9 + 99 + 999 + ...n terms] 2 3
9
8 1 + 2 + 3 + ...n n(n + 1) / 2 n + 1
= [(10–1) + (100–1) + (1000–1) + .... n terms] \ tn = = =
9 n n 2
8 1 1
= [10n+1 – 9n – 10] Tn = 2 + (n - 1)(4 + {n - 2}1) = (n2 + n + 2)
81 2 2
50. (d) Let nth term of series is Tn then
Sn = 12 + 16 + 24 + 40 + .... + Tn 1 1
Now S = STn = S(n 2 + n + 2) = (Sn2 + Sn + 2S1)
Again Sn = 12 + 16 + 24 + .... + Tn 2 2
On subtraction
1 ì1 1 ü
0 = (12 + 4 + 8 + 16 + ... + upto n terms) – Tn = í n(n + 1)(2n + 1) + n(n + 1) + 2n ý
2 î6 2 þ
or Tn = 12 + [4 + 8 + 16 + .... + upto (n – 1) terms]
n
4(2n-1 –1) = {(n + 1)(2 n + 1 + 3) + 12}
= 12 + = 2n +1 + 8 12
2 –1
On putting n = 1, 2, 3..... n n
T1 = 22 + 8, T2 = 23 + 8, T3 = 24 + 8.... etc. = {( n + 1)( n + 2) + 6} = ( n 2 + 3n + 8)
6 6
EBD_7203
S1-66 GENERAL APTITUDE FOR GATE
55. (c) By observation of summation, it can be seen that 57. (c)
numbers are not in decimal. Let they have base n. Then 58. (b)
converting all number in decimal 59. (d)
(137)n = [1 × n2 + 3n + 7 nº]10 60. 96
(276)n = [2n2 + 7n + 6nº]10 2
(435)n = [4n2 + 3n + 5nº]10 æ 1ö
ç z + z ÷ = 98
(731)n = [7n2 + 3n + 1nº]10 è ø
(672)n = [6n2 + 7n + 2nº]10
2
\ (137)n + (276)n = (435)n æ 1ö 2 1 1
Þ n2 + 3n + 7 + 2n2 + 7n + 6n = 4n2 + 3n + 5 ç z + z ÷ = z + z 2 + 2z z
è ø
Þ n2 – 7n – 8 = 0
Þ n = – 1, 8 2 1
98 = z + +2
Possible base n = 8 (+ ve) z2
(435)n = (435)8 = (4 × 82 + 3 × 8 + 5)10 = (285)10
(731)n = (731)8 = (7 × 82 + 3 × 8 + 1)10 = (473)10 1
z2 + = 96
(672)n = (672)8 = (6 × 82 + 7 × 8 + 2)10 = (442)10 z2
So (731) 8 + (672)8 = (473)10 + (442)10 = (915)10 61. 10 to 10
(915)10 = (1623)8 62. (c) The series is adding
+3, +5, +7, +9 etc.
1 1
56. (b) Log P = log Q = log (R) = K Correct one is 50 + 15 = 65
2 3
\ P = bk, Q = b2k, R = b3k
Now, Q2 = b4k = b3k bk = PR
2 Algebra
INDICES Comparison of surds :
When a number ‘a’ is multiplied by itself ‘m’ times, then we say Step I : Convert each surd into a surd of same order.
that ‘a is of m-indice’. am is read as ‘a raised to the power m’.
Step II : Compare the radicand of the surds. The surd with larger
Laws of Indices
radicand is the largest of the given surds.
I. a m ´ a n = a m+ n Multiplication and division of Surds :
am Surds of same order can be multiplied and divided according to
II. = a m -n the following law :
an
n
a a
III. (a m )n = a mn (i) n
a ´ n b = n ab (ii) =n
n b
b
IV. (ab)n = a n bn
ALGEBRAIC EXPRESSIONS AND INEQUALITY
n n Linear Equation in one variable : A linear equation which con-
æaö a
V. ç ÷ = n tains only one variable is called linear equation in one variable.
èbø b
The general form of such equations is ax + b = c, where a, b and c
VI. a0 = 1 are constants and a ¹ 0 .
All the values of x which satisfy this equation are called its
SURDS solution(s).
Linear equation in two variables : General equation of a linear
a1/ n is called a surd or radical of order n and a is called the equation in two variables is ax + by + c = 0, where a, b ¹ 0 and c
radicand. is a constant, and x and y are the two variables.
For Example : 2, 3
3 , etc. The sets of values of x and y satisfying any equation are called its
solution(s).
Laws of Surds :
QUADRATIC EQUATION
I. ( n a )n = a General form : ax2 + bx + c = 0...........(1) where a, b and c are all real
n
number and a ¹ 0.
II. a n b = n ab The roots of the quadratic equation (1) can be evaluated using
the following formula.
n
a a
III. =n
n
b b - b ± b 2 - 4ac
x=
2a
mn
IV. a = mn a = n m
a
The expression inside the square root b 2 - 4ac is called the
Conversion of surds into surds of the same order : DISCRIMINANT of the quadratic equation and denoted by D.
Let the surds be n1
a1 , n2
a2 , n3
a 3 , ... Nature of Roots : The nature of roots of the equation depends
upon the nature of its discriminant D.
Step I : Compute L.C.M. of n 1, n2, n3, ... (i) If D < 0, then the roots are non-real complex, Such roots are
Let L.C.M. = n always conjugate to one another. That is, if one root is p + iq
then other is p – iq, q ¹ 0.
n n n
Step II : Compute , , , ... = m1, m2, m3, ... (ii) If D = 0, then the roots are real and equal. Each root of the
n1 n 2 n3
b
Step III : Required surds are equation becomes - . Equal roots are referred as repeated
2a
n a1m1 , n a 2 m2 , n a 3m3 , ... roots or double roots also.
(iii) If D > 0 then the roots are real and unequal.
EBD_7203
S1-68 GENERAL APTITUDE FOR GATE
Sign of Roots : Let a, b are real roots of the quadratic equation
3. Multiplying each side of an inequality with same number
ax2 + bx + c = 0 that is D = b 2 - 4 ac ³ 0 . Then
does not effect the sign of inequality, i.e., if x £ y then
(i) Both the roots are positive if a and c have the same sign and
the sign of b is opposite. ax £ ay (where, a > 0).
(ii) Both the roots are negative if a, b and c all have the same 4. Multiplying each side of an inequality with a negative
sign. number effects the sign of inequality or sign of inequality
(iii) The Roots have opposite sign if sign of a and c are opposite. reverses, i.e., if x < y then ax > ay (where a < 0).
(iv) The Roots are equal in magnitude and opposite in sign if 5. Dividing each side of an inequation by a positive number
b = 0 [that is its roots a and –a]
does not effect the sign of inequality, i.e., if x £ y then
Some symmetric functions of roots are :
x y
(i) a 2 + b 2 = (a + b ) 2 - 2 ab £ (where a > 0).
a a
(ii) a - b = ± (a + b ) 2 - 4 ab 6. Dividing each side of an inequation by a negative
number reverses the sign of inequality, i.e., if x > y then
x y
(iii) a 2 - b 2 = ± (a + b) (a - b) = ± (a + b) (a + b) 2 - 4ab < (where a < 0).
a a
(iv) a 3 + b3 = (a + b)3 - 3ab (a + b) ALGEBRAIC FORMULAE & THEIR APPLICATION
An equation is a statement that two algebraic expressions are
(v) a 3 - b3 = (a – b)3 + 3ab (a - b) & equal. If an equation is satisfied by any value of the variable,
then equation is said to be an identity.
a - b = ± (a + b )2 - 4ab
1. (a + b)2 = a2 + 2ab + b2 = (a – b)2 + 4ab
(vi) a 4 + b4 = (a 2 + b2 )2 - 2a 2b 2 2. (a – b)2 = a2 – 2ab + b2 = (a + b)2 – 4ab
2
3. (a + b)2 + (a – b)2 = 2(a2 + b2)
= é (a + b)2 - 2abù - 2(ab)2 4. (a + b)2 – (a – b)2 = 4ab
ë û
5. (a + b + c)2 = a2 + b2 + c2 + 2(ab + bc + ca)
(vii) a 4 - b 4 = (a 2 + b 2 )(a 2 - b 2 ) 6. (a + b + c + d)2 = a2 + b2 + c2 + d2 + 2a (b + c + d)
[ é
ë
] ù
= (a + b) 2 - 2ab ê± (a + b) 2 - 4ab ú
û
+ 2b (c + d) + 2cd
7. (a + b) (a – b) = a2 – b2
8. (x + a) (x + b) = x2 + (a + b) x + ab
Formation of Quadratic Equation with given Roots :
An equation whose roots are a and b can be written as 9. (x + a) (x + b) (x + c)
(x – a) (x – b) = 0 or x2 – (a + b) x + ab = 0 or x2 – (sum of the roots) = x3 + (a + b + c)x2 + (ab + bc + ca) x + abc
x + product of the roots = 0. 10. (a + b)3 = a3 + 3ab (a + b) + b3
INEQUALITY 11. (a – b)3 = a3 – 3ab (a – b) – b3
12. a3 + b3 = (a + b)3 – 3ab (a + b)= (a + b) (a2 – ab + b2)
Inequations : A statement or equation which states that one thing
is not equal to another, is called an inequation. 13. a3 – b3 = (a – b)3 + 3ab (a – b) = (a – b) (a2 + ab + b2)
14. a3 + b3 + c3 – 3abc = (a + b + c) (a2 + b2 + c2 – ab – ac – bc)
Symbols :
If a + b + c = 0 then a3 + b3 + c3 = 3abc
‘<’ means “is less than”
‘>’ means “is greater than” AVERAGE
‘ £ ’ means “is less than or equal to” Sum of given quantities
• Average or Mean =
Number of quantities
‘ ³ ’ means “is greater than or equal to”
Variance and standard deviation
PROPERTIES • The variance of a variate X is the arithmetic mean of the
1. Adding the same number to each side of an equation squares of all deviations of X from the arithmetic mean of
does not effect the sign of inequality, it remains same, i.e. the observations and is denoted by Var (X) or s2
if x > y then, x + a > y + a . • The positive square root of the variance of a variate X is
2. Subtracting the same number to each side of an inequation known as standard deviation.
does not effect the sign of inequaltiy, i.e., if x < y then,
i.e., s = + V(x)
x – a < y – a.
ALGEBRA S1-69
• To calculate the sum of quantities, they should be in the THEOREMS ON CARDINAL NUMBERS
same unit. Let A, B, C are finite sets in a finite universal set U. Then
• Average of a group consisting two different groups when (i) n (A È B) = n(A) + n(B) – n (A Ç B)
their averages are known :
(ii) n (A È B) = n(A) + n (B) Û A and B are disjoint non
Let Group A contains m quantities and their average is a void sets.
and Group B contains n quantities and their average is b,
(iii) n (A È B È C) = n(A) + n(B) + n(C) – n(A Ç B)
then average of group C containing a + b quantities
– n(B Ç C) – n(C Ç A) + n(A Ç B Ç C)
ma + mb The results (i) and (iii) can be extended to any number
= .
m+n of sets.
• If, in a group, one or more new quantities are added or (iv) n (A–B) = n (A) – n (A Ç B) = n (A Ç B')
excluded, then the new quantity or sum of added or (v) n (A D B) = n (A) + n (B) – 2 n (A Ç B)
excluded quantities = [Change in no. of quantities ×
(vi) n(A') = n (U) – n (A)
original average] ± [change in average × final no. of
quantities] (vii) n (A' È B') = n (U) – n (A Ç B)
Take +ve sign if quantities added and (viii) n (A' Ç B') = n (U) – n (A È B)
take –ve sign if quantities removed. (ix) If A1, A2, ......, An are disjoint sets, then
EXERCISE
1. 1.236 ´ 1015 - 5.23 ´ 1014 equals : 1 3 1
10. If x + = 5 , then the value of x + 3 is :
14 x
(a) 7.13 ´ 10 (b) 7.13 × 1015 x
(c) 71.3 × 1014 (d) – 3.994 (a) 125 (b) 110
-
2 (c) 45 (d) 75
-1 ö
2. The value of æç ÷
3
is : 11. Father is 5 years older than the mother and mother’s age
è 216 ø now is thrice the age of the daughter. The daughter is
now 10 years old. What was father’s age when the daughter
1 1 was born?
(a) (b) -
36 36 (a) 20 years (b) 15 years
(c) – 36 (d) 36 (c) 25 years (d) 30 years
3. The value of 3 0.000064 is :
x 2 + 7 y 2 + 9z 2
(a) 0.02 (b) 0.2 12. If x : y : z :: 1 : 3 : 5, then the value of
(c) 2.0 (d) None of these x
is :
4. (28 - 10 3)1/ 2 - (7 + 4 3) -1/ 2 equals : (a) 7 (b) 17
(a) 4 (b) 5 (c) 13 (d) 1
(c) 3 (d) 4.3 13. In a community of 175 persons, 40 read the Times, 50 read
the Samachar and 100 do not read any. How many persons
5. Taking 2 = 1.414 , 3 = 1.732 , 5 = 2.236 and read both the papers ?
(a) 10 (b) 15
9+ 2 6- 2 (c) 20 (d) 25
6 = 2.449 , find the value of +
5+ 3 5- 3 14. The set of inequations | x - 4 | + | y - 2 | £ 2 , where x and
to the three places of decimal. y are positive integers, has :
(a) 9.2321 (b) 13.716 (a) 8 solutions (b) 9 solutions
(c) 11.723 (d) 15.892 (c) 11 solutions (d) None of these
6. Which one of the following is the largest ? 15. Which of the following equations has real roots ?
2 5 , 6 3 , 3 7 and 8 2 (a) 3x 2 + 4 x + 5 = 0 (b) x2 + x + 4 = 0
x y z 17. (d)
12. (b) Let = = = k Þ x = k, y = 3 k, z = 5k
1 3 5 TV 40 25 15 Newspaper
x 2 + 7y2 + 9z 2 k 2 + 7 ´ 9k 2 + 9 ´ 25k 2
Now, =
x k Total % of people watching TV or reading newspaper
= 40 + 25 + 15 = 80%
= 1 + 63 + 225 = 289 = 17 Therefore, 20% of the people who neither watch TV
13. (b) Number of persons who read newspaper nor read newspaper.
= 175 – 100 = 75.
Now, the number of persons who read either or both 18. (c) 2x 2 - 7xy + 3y 2 = 0
of the newspapers =
(40 + 50) = 90 2
æxö æxö
Hence, the number of those who read both the 2 çç ÷÷ - 7çç ÷÷ + 3 = 0 (Dividing by y2)
newspapers = (90 – 75) = 15 èyø è yø
14. (d) | x - 4 | + | y - 2 | £ 2
For the above inequality x and y can have following x - b ± b 2 - 4ac 7 ± 49 - 24 7 ± 5 1
= = = = 3,
sets of values y 2a 2´ 2 4 2
(4, 4) (4, 3) (4, 2) (4, 1) (3, 3) (3, 2) (3, 1) (2, 2) (5, 1)
(5, 2) (5, 3) (6, 2) x 3 x 1
Þ = or =
Hence, it has 12 solutions. None of the given options y 1 y 2
is correct.
19. (a) Let A’s, B’s and C’s ages be A, B and C respectively
15. (c) Roots of a quadratic equation
at present.
2
ax 2 + bx + c = 0 are real if b - 4ac ³ 0
1
Let us work with options as follows. We have, A = B ...........(i)
6
2
Option (a) : 3x + 4x + 5 = 0 Present age of C = 10 years
b2 - 4ac = (4) 2 - 4(3)(5) = -44 < 0 . And, (B + 10) = 2(C + 10) ...........(ii)
From (ii), B + 10 = 40 or B = 30
Thus, roots not real.
Þ From (i), we have A = 5 years.
Option (b) : x 2 + x + 4 = 0
2
æ 1ö
b2 - 4ac = (1) 2 - 4(1)(4) = 1 - 16 = -15 < 0 20. (b) We have, ç a + ÷ = 3
è aø
Thus, root not real.
Option (c) : (x –1) (2x – 5) = 0 Þ 2x2 – 7x + 5 = 0 3
b2 – 4ac = (–7)2 – 4 × 2 × 5 = 49 – 40 = 9 > 0 1 æ 1ö æ 1ö
Now, a 3 + 3
= ç a + ÷ - 3ç a + ÷
thus roots are real. a è aø è aø
5
or x = 1 and x = are real roots. æ 1ö éæ 1ö
2 ù æ 1ö
2 = ça + ÷ êç a + ÷ - 3ú = ç a + ÷ [3 - 3] = 0
è aø êëè a ø úû è aø
Option (d) : 2 x 2 - 3x + 4 = 0
b 2 - 4ac = (-3) 2 - 4(2)(4) = 9 - 32 = -23 21. (c) Nose studs Ear rings
Thus, roots not real. only only
Hence, option (c) is correct.
16. (d) Equations in options (a) and (c) are not quadratic 4 3 5
equations as in (a) max. power of x is fractional and
in (c), it is not 2 in any of the terms. 7 8
2 Number of women who have nose studs only
For option (b), (x – 1) (x + 4) = x + 1
= 7 – 3 = 4. Number of women who have ear rings
or x 2 + 4 x - x - 4 = x 2 + 1 or 3x - 5 = 0 only = 8 – 3 = 5. Thus, the number of women who
which is not a quadratic equations but a linear. have both nose studs and ear rings
For option (d), (2x + 1) (3x – 4) = 2 x 2 + 3 = 15 – (4 + 5 + 3) = 15 – 12 = 3.
22. (d) Percentage of those who opted for both
or 6 x 2 - 8 x + 3x - 4 = 2 x 2 + 3
= (73 + 62 - 100) = 35%
or 4x 2 - 5x - 7 = 0
Þ number of those who opted for both
which is clearly a quadratic equation.
= 220 × 35% = 77
EBD_7203
S1-76 GENERAL APTITUDE FOR GATE
40 10 10
Percentage of families own both a car and a phone
= (15 + 15) – (100 – 65) = 5%
Out of 35% of the families, 20% have only phone, 10%
have only car and 5% have both phone and the car. \ No. of persons speaking atleast one of these two
Given that 5% = 2000 languages = persons speaking french only + persons
2000 ´ 100 speaking spanish only + common persons speaking
Þ The total number of familes = = 40000 French and Spanish = 40 + 10 + 10 = 60.
5
Thus the statements II and III are correct. Basketball
24. (b) According to question, we have 30. (a) Hockey
A – 10 = B + 10 Þ A – B = 20 .....(i) 160 40
216 B = 336
and 2 (B – 20) = (A + 20) H = 240 24
Þ 2 B – 40 = A + 20 or A – 2B = – 60 .....(ii) 16 56
From (i) and (ii), we get A = 100 and B = 80
25. (b) Adding the given inequations, we get 128
(x + y) + (x – y) > 5 + 3 Þ 2x > 8 Þ x > 4 Cricket
26. (c) Basketball Tennis C = 224
\ No. of boys who did not play any game
26%
d + a + b + c = 25000 a + b = 10,500
xa xb xc
= + + b + c = 13,000 b = 2, 500
(x a + x b + x c ) (x a + x b + x c ) (x a + x b + x c )
On solving these equations we get
(x a + x b + x c ) a = 8,000
= =1 c = 10,500
(x a + x b + x c )
d = 25,000 – 21,000 = 4,000
\ % population who read neither of these newspaper
41. (c) 4
( 28 + 16 3) = ( 28 + 16 3 )
4, 000
= ´ 100 = 16%
25, 000
= ( 28 + 2 192 =) ( 16 + 12 )
2
46. (d) Let the number of papers be x. Then, 63x + 20 + 2 = 65x
or 2x = 22 or x = 11.
= 16 + 12 = (4 + 2 3 ) H x F
47. (b) 5 10 7 \ 5 + 10 + 7 + x = 25 Þ x = 3
( )
2
= 3 +1 = 3 +1
48. (b) (i) H + G > I + S
nx n Þ I – H< G – S ...(i)
42. (a) mxm = nxn \ xm =
m (ii) G – S = 1
æ 1 ö
1 From equations (i) and (ii), we get I – H < 1 Þ H > 1
\ Given ç n + n ÷
nx n nx n Hence order is SGHI because G is not oldest and S is
ç +x -x ÷
è m m ø not youngest.
EBD_7203
S1-78 GENERAL APTITUDE FOR GATE
49. (a) Checking with all options in formula (4q + 100/q) i.e. ax2 + bx + c = 0
(V + F). This eqn has two real roots
Option (a) gives minimum cost. For x < 0
50. (b) y = 2x – 0.1x2 ax2 – bx + c = 0
This eqn has two real roots
dy d2y
= 2 – 0.2 x <0 Hence, total real roots are 4.
dx dx 2
Hence maximises at 2 – 0.2x = 0 Þ x = 10 54. (c) Let 12 + 12 + ... = x
\ y = 20 – 10 = 10 m
51. (c) P and R always holds true \ 12 + 12 + 12... = x
Else consider a sample set {1, 2, 3, 4} and check
accordingly. 12 + x = x
52. (a) p = 50q – 5q2 12 + x = x2
x2 – x – 12 = 0
dp d2 p (x – 4) (x + 3) = 0
\ = 50 –10q <0
dq dq 2 \ x = 4, – 3
Hence p is maximum at 50 – 10q = 0 or q = 5 Alternately x = 4 (Q the value is real)
check with options. 55. (c)
53. (d) ax2 + b|x| + c = 0
For x > 0
3 Percentage & Its Applications
PERCENTAGE PROFIT AND LOSS
A percentage is a fraction with denominator hundred. Cost Price : The amount paid to purchase an article or the price
It is denoted by the symbol %. at which an article is made, is known as its cost price.
Numerator of the fraction is called the rate per cent. The cost price is abbreviated as C.P..
Increase value Selling Price : The price at which an article is sold, is known as
• Increase % = ´100 its selling price.
Original value
The selling price is abbreviated as S.P..
Decrease value Profit : If the selling price (S.P.) of an article is greater than the
• Decrease % = ´ 100 cost price (C.P.), then the difference between the selling price
Original value
and cost price is called profit.
• If the price of a commodity increases by r %, then reduction Thus, If S.P. > C.P., then
in consumption, so as not to increase the expenditure is Profit = S.P. – C.P.
Loss : If the selling price (S.P.) of an article is less than the cost
æ r ö
çè ´ 100÷ % . price (C.P.), then the difference between the cost price (C.P.) and
100 + r ø
the selling price (S.P.) is called loss.
• If the price of a commodity decreases by r%, then the increase Thus, if S.P. < C.P., then
in consumption so as not to decrease the expenditure is Loss = C.P. – S.P.
Profit and Loss percentage
æ r ö
ç ´100 ÷ %
è 100 - r ø Profit
Profit per cent = ´ 100
First Increase and then decrease : C.P.
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, while æ ab ö
another candidate who scores y% marks gets ‘b’ marks more than the resultant profit or loss per cent is given by ç a - b - ÷% ,
è 100 ø
the minimum required passing marks. Then the maximum marks
Marked Price : The price on the lable is called the marked price
100(a + b)
M= . or list price.
y-x
The marked price is abbreviated as M.P.
• If A’s income is r % more than that of B, then B’s income is
less than that of A by Discount : The reduction made on the ‘marked price’ of an
article is called the discount.
æ r ö NOTE : When no discount is given, ‘selling price’ is the same
ç ´ 100 ÷ %
è 100 + r ø as ‘marked price’.
• If A’s income is r % less than that of B, then B’s income is • Discount = Marked price × Rate of discount.
more than that of A by • S.P. = M.P. – Discount.
æ r ö Discount
ç ´100 ÷ % • Discount % = ´ 100 .
è 100 - r ø M.P.
EBD_7203
S1-80 GENERAL APTITUDE FOR GATE
EXERCISE
1. When the price of a radio was reduced by 20%, its sale
ac
increased by 80%. What was the net effect on the sale? (a) c% (b) %
b
(a) 44% increase (b) 44% decrease
(c) 66% increase (d) 75% increase bc
(c) % (d) abc%
2. In a co-education school there are 15 more girls than a
boys. If the number of girls is increased by 10% and the
number of boys is also increased by 16%, there would be 1
10. In a class, 40% of the boys is same as of the girls and
nine more girls than boys. What is the number of students 2
in the school? there are 20 girls. Total number of students in the class
(a) 240 (b) 225 is :
(c) 265 (d) 245 (a) 70 (b) 45
1 (c) 35 (d) 25
3. Ravi sells an article at a gain of 12 %. If he had sold it
2 11. In a shipment of 120 machine parts, 5 per cent were
at ` 22.50 more, he would have gained 25%. The cost defective. In an another shipment of 80 machine parts, 10
price of the article is : per cent were also defective. For the two shipments
(a) ` 165 (b) ` 160 combined, what per cent of the machine parts were
defective?
(c) ` 196 (d) ` 180
(a) 6.5 % (b) 7.0%
4. If A’s salary is 25% higher than B’s salary, then how
(c) 7.5% (d) 8.0%
much per cent is B’s salary lower than A’s ?
12. Population of a district is 2,96,000 out of which 1,66,000 are
1 males. 50% of the population is literate. If 70% males are
(a) 16 % (b) 20%
3 literate, then the number of women, who are literate, is
(a) 32,200 (b) 31,800
1
(c) 25% (d) 33 % (c) 66,400 (d) 48,000
3 13. In a certain town, 25% families own a phone and 15% own
5. Lucknow Shatabdi Express has a capacity of 500 seats of
a car, 65% families own neither a phone nor a car. 2000 families
which 10% are in the Executive class and the rest are chair
own both a car and a phone. Consider the following
cars. During one journey, the train was booked to 85% of
statements in this regard:
its capacity. If Executive class was booked to 96% of its A. 10% families own both a car and a phone.
capacity, then how many chair car seats were empty during B. 35% families own either a car or a phone.
that journey? C. 40,000 families live in the town.
(a) 78 (b) 73 Which of the above statements are correct?
(c) 72 (d) None of these (a) A and B (b) A and C
6. Of the 1000 inhabitants of a town, 60% are males of whom (c) B and C (d) A, B and C
20% are literates. If, of all the inhabitants, 25% are literates, 14. A clothing supplier stores 800 coats in a warehouse, of
then what % of the females of the town are literates ? which 15 percent are full-length coats. If 500 of the shorter
(a) 22.5 (b) 27.5 length coats are removed from the warehouse, then what
(c) 32.5 (d) 35.5 percent of the remaining coats are full length?
7. Mohan took half a pizza on Monday. He took half of what (a) 5.62% (b) 9.37%
was left on Tuesday and so on. He followed this pattern (c) 35% (d) 40%
for one week. How much of the pizza would he have taken 15. A loss of 19% gets converted into a profit of 17% when
during the week? the selling price is increased by ` 162. Find the cost price
(a) 99.22% (b) 95% of the article.
(c) 98.22% (d) 100% (a) ` 450 (b) ` 600
8. A number is increased by 10% and then reduced by 10%. (c) ` 460 (d) ` 580
After these operations, the number : 16. What price should a shopkeeper mark on an article costing
(a) does not change (b) decreases by 1% him ` 153 to gain 20% after allowing a discount of 15% ?
(c) increases by 1% (d) increases by 0.1%
(a) ` 162 (b) ` 621
9. If a% of x is equal to b% of y, then c% of y is what %
(c) ` 216 (d) ` 226
of x ?
PERCENTAGE & ITS APPLICATIONS S1-81
17. If selling price is doubled then, the profit triples. What is 25. A shopkeeper marks the prices of his goods at 25 % higher
profit per cent ? than the original price. After that, he allows a discount of
12 %. What profit or loss did he get?
2
(a) 66 (b) 100 (a) 15% profit (b) 10% profit
3
(c) 10% loss (d) 15% loss
1 26. Ramesh purchased a bicycle for `. 5,200 and spent ` 800 on
(c) 33 (d) 125 its repairs. He had to sell it for ` 5,500. Find his profit or loss
3
per cent.
18. A man sells an article at 5% profit. If he had bought it at (a) 14.07% loss (b) 8.14% loss
5% less and sold it for Re 1 less, he would have gained
(c) 9.81% loss (d) None of these
10%. The cost price of the article is :
27. A number is increased by 11% and then reduced by 10%.
(a) ` 200 (b) ` 150 After these operations, the number :
(c) ` 240 (d) ` 280 (a) does not change (b) decreases by 1%
19. The cost price of 20 articles is the same as the selling (c) increases by 1% (d) increases by 0.1%
price of x articles. If the profit is 25%, then the value of 28. If 10 % of an electricity bill is deducted, ` 45 is still to be
x is : paid. How much was the bill?
(a) 25 (b) 18 (a) ` 50 (b) ` 60
(c) 16 (d) 15 (c) ` 55 (d) ` 70
29. Venkat purchased twenty dozens of toys at the rate of
20. A company blends two varieties of tea from two different
` 375 per dozen. He sold each one of them at the rate of
tea gardens, one variety costing `20 per kg and other
` 33. What was his percentage profit?
` 25 per kg, in the ratio 5 : 4. He sells the blended tea
(a) 6.5 (b) 5.6
at ` 23 per kg. Find his profit per cent :
(c) 3.5 (d) 4.5
(a) 5% profit (b) 3.5% loss 30. Pradip spends 40 per cent of his monthly income on food
(c) 3.5% profit (d) No profit, no loss items, and 50 per cent of the remaining on clothes and
21. A shopkeeper sells a pair of sunglasses at a profit of 25%. conveyance. He saves one-third of the remaining amount
If he has bought it at 25% less and sold it for `10 less, then after spending on food, clothes and conveyance. If he saves
he would have gained 40%. Determine the cost price of the ` 19,200 every year, what is his monthly income?
pair of sunglasses. (a) ` 24,000 (b) ` 12,000
(a) `50 (b) ` 25 (c) ` 16,000 (d) ` 20,000
(c) `75 (d) ` 60 31. When 30 per cent of a number is added to another number
22. A machine costs m rupees per day to maintain and n paise the second number increases by its 20 per cent. What is the
ratio between the first and the second number?
for each unit it produces. If the machine is operated 7 days
(a) 3 : 2 (b) 2 : 3
a week and produces r units in a week, then which of the
(c) 2 : 5 (d) Data inadequate
following is the total cost, in `., of operating the machine for
32. If by selling twelve note-books, the seller earns profit equal
a week ?
to the selling price of two note-books, what is his percentage
700 m + nr profit?
(a) 7 m + 100 nr (b) (a) 20% (b) 25%
100
(c) m + nr (d) 700 mnr 2
(c) 16 % (d) Data inadequate
23. A shopkeeper marks up his goods to gain 35%. But he allows 3
10% discount for cash payment. His profit on the cash 33. If 15 oranges are bought for a rupee, how many must be
transaction in percentage, is sold for a rupee to gain 25%?
(a) 12 (b) 10
(a) 13 1 (b) 25 (c) 20 (d) 18
2 34. What per cent of selling price would be 34% of cost price if
1 1 gross profit is 26% of the selling price?
(c) 21 (d) 31 (a) 17.16 (b) 74.00
2 2
(c) 25.16 (d) 88.40
24. A man buys apples at a certain price per dozen and sells 35. The cost price of 20 articles is equal to the selling price of
them at eight times per hundred. What is his gain or loss 25 articles. The loss percent in the transaction is
per cent? (a) 5 (b) 20
(a) 4% loss (b) 8¼ loss (c) 25 (d) 30
(c) 4% gain (d) 6¼ % gain
EBD_7203
S1-82 GENERAL APTITUDE FOR GATE
36. Round-trip tickets to a tourist destination are eligible for a
discount of 10% on the total fare. In addition, groups of 4 or
15
20. (c) Let the quantity of two varities of tea be 5x kg and
14. (d) No. of full length coats = ´ 800 = 120 coats. 4x kg, respectively.
100
Now, SP = 23 × 9x = 207x
\ total no. of short-length coats = 680
After removing 500 short length coats, the remaining and CP = 20 × 5x + 25 × 4x = 200x
short length coats = 180
7x
\ % of full length coats from remaining Profit % = ´ 100 = 3.5%
200x
120
coats = ´ 100 = 40% 21. (a) Let the CP of the sunglasses be ` 100.
120 + 180
Now, SP = ` 125
15. (a) Let the cost price be ` x.
New CP = ` 75
Then, SP at a loss of 19% = 0.81x.
New SP = 75 × 1.4 = ` 105
Now, x ´ 1.17 = (0.81x + 162) Thus, if he sells for ` (125 – 105) = 20 less, then
Þ 1.17 x - 0.81x = 162 Þ x = ` 450 CP = 100
16. (c) CP = `153, desired gain 20% If he sells for ` 10 less, then
Þ SP = 153 × 1.2 = ` 183.60 100
Let the marked price be ` x CP = ´ 10 = ` 50
20
Then, x ´ 0.85 = 183.60
22. (b) Cost of 1 day to maintain the machine = ` m
183.60 \ 7 day’s cost for maintainence = ` 7m.
Þ x= = ` 216
Similarly, cost of 1 unit = n paise (for 1 day)
0.85
17. (b) Let CP be ` x and SP be ` y. n
Then, profit = ` (y – x) =`
100
If SP = 2y, then profit = 3(y – x)
Now, 2 y - x = 3( y - x ) rn
\ Cost of r unit = `
100
Þ y = 2x
rn 700m + nr
y-x 2x - x Hence, Total cost = 7m + =
Now, profit = ´ 100 = ´ 100 = 100% 100 100
x x
18. (a) Let the CP of the article be ` x. 23. (c) Let the cost price be ` 100.
\ Marked price is ` 135.
105x At 10% discount, the customer has to pay
Then, SP = `
100 = Marked price – discount = 135 – 13.5 = 121.5.
95x 105x 1
Now, new CP = ` and new SP = -1 \ % profit = 21.5% = 21 %.
100 100 2
According to the question 24. (a) Let man buys apples at ` x per dozen.
105x 95 10 ´ 95x x
-1- = \ Cost price =
100 100 100 ´100 12
\ x = ` 200
19. (c) CP of 20 articles = SP of x articles = 1 (say) 8x
and selling price =
100
1
Therefore, CP of 1 article = , Here, S.P < C.P., therefore
20
There is loss
1 which is equal to CP – SP
And SP of 1 article =
x
x 8x 25x – 24x x
= – = =
1 1 12 100 300 300
-
25 æ 20 - x ö 25
Now, gain% = x 20 = Þ ç ÷ ´ 20 = \ Loss per cent
1 100 è 20 x ø 100
20 Loss x 12
= ´ 100 = ´ 100 ´ = 4%
Þ 80 – 4x = x Þ 5x = 80 Þ x = 16 C.P 300 x
PERCENTAGE & ITS APPLICATIONS S1-85
25. (b) Let the cost price = ` 100
2
By question, marked price = `125 32. (a) Percentage profit = ´100 < 20%
12 – 2
88
Selling price after 12% discount = 125 ´ 1
100 33. (a) C.P. for one orange = `
15
Let the shopkeeper get x% profit.
\ Selling price = (100 + x )% (100 + 25) 1 125 1
Then S.P. = ´ = =
88 100 100 15 100 ´15 12
Now, cost price = 125 ´ ´
100 100 + x
1
Hence S.P. for one orange = `
125 ´ 88 12
Þ 100 = Þ 11000 =10000 + 100 x
100 + x \ 12 oranges must be sold for a rupee
34. (c) Let the selling price of the article be ` 100.
1000 \ Profit = ` 26
Þ =x
100 \ Cost price of the article = 100 – 26 = ` 74
Þ x% = 10% profit 34 ´ 74
\ Reqd. % = = 25.16%
26. (d) Cost price of bicycle = ` 5,200. 100
He spent ` 800 on it’s repairs
35. (c) Let C.P. of 1 article = ` 1
\ C.P. = 5200 + 800 = 6000.
then C.P. of 25 articles = ` 25
Selling price = ` 5, 500
and S.P. of 25 articles = ` 20
\ Loss = 6000 – 5500 = 500
500 \ loss % = 25 - 20 ´ 100 = 25%
Hence, loss % = ´ 100 = 8.33% 20
6000
36. 850
27. (b) Let the original number be 100.
A group of 5 tourists purchasing round-trip will be
Then, the new number = 100 × 1.1 × 0.9 = 99
i.e. the number decreases by 1%. 15
charged = 1000 - 1000 ´ = 850
28. (a) Let the bill be ` x. Then 100
90% of x = 45 37. 48
45 ´ 100 Don’t have own scooter = Have only car + Do not
Þ x= = ` 50 own vehicle
90
= 74 + 70 = 144
29. (b) Cost price of 20 dozen toys = 20 × 375 = ` 7,500
Percentage of respondents do not own a scooter =
Selling price of 20 dozen toys = 20 × 33 × 12 = ` 7,920
144
7, 920 , 7,500 ´100 = 48
Profit percentage = ´100 < 5.6% 300
7,500
38. 140
30. (c) Food items = 40% 2008
1 male m
Clothes + conveyance = of 60% = 30% = = 2.5
2 female f
1 19, 200 Þ f = m/2.5
of 30% = Þ10% = 1600 2009
3 12
\ 100% = ` 16,000 male m¢
= =3
female f¢
120
31. (b) 30% of I + II = II ´
100 m¢
Þf¢=
3
3 2
or, I= II Þ I : II = 2 : 3. Given f ¢ = 2f
10 10
m¢ m
Þ = 2´
3 2.5
EBD_7203
S1-86 GENERAL APTITUDE FOR GATE
39. (d) Rupee value inhered by 76
m¢ 6
\ = \ Final value = 1.07 times
m 2.5
50
æ m¢ - m ö Ratio of change in exchange value =
% increase of students = çè ÷ ´ 100 60
m ø \ India’s GDP in USD
æ m¢ ö æ 6 ö 50
= çè - 1÷ ´ 100 = ç - 1÷ ´ 100 = 1.07 × × 100% = 89%
m ø è 2.5 ø 60
\ It decreased by (100 – 89)
æ 3.5 ö = 11%
= çè ÷ø ´ 100
2.5
= 140%
4 Time and Work &
Speed and Distance
EXERCISE
1. A train running between two stations A and B arrives (a) 10 days (b) 12 days
at its destination 10 minutes late when its speed is 50 (c) 15 days (d) 9 days
km/h and 50 minutes late when its speed is 30km/h. 10. A and B can do the a piece of work in 6 days. A alone
What is the distance between the stations A and B ? can do it in 10 days. What time will B require to do it
(a) 40 km (b) 50 km alone ?
(c) 60 km (d) 70 km (a) 20 days (b) 15 days
2. A man makes his upward journey at 16 km/h and downward (c) 25 days (d) 3 days
journey at 28 km/h. What is his average speed ? 11. Mohan travels 760 km to his home, partly by train and
(a) 32 km/h (b) 56 km/h partly by car. He takes 8 hours if he travels 160 km by train
(c) 20.36 km/h (d) 22 km/h and the rest by car. He takes 12 minutes more if he travels
3. If a man travels at 30 km/h, he reaches his destination late 240 km by train and the rest by car. The speeds of the train
by 10 minutes but if he travels at 42 km/h then he reaches and the car, respectively are:
10 minutes earlier. The distance travelled by him is : (a) 80 km/h, 100 km/h (b) 100 km/h, 80 km/h
(a) 30 km (b) 35 km (c) 120 km/h, 120 km/h (d) 100 km/h, 120 km/h
(c) 45 km (d) 36 km 12. I can do a piece of work in 8 days, which can be done by
4. During a journey of 80 km a train covers first 60km with a you in 10 days. How long will it take to do it if we work
speed of 40 km/h and completes the remaining distance together?
with a speed of 20 km/h. What is the average speed of the
train during the whole journey? 4 3
(a) 4 days (b) 5 days
(a) 30 km/h (b) 32 km/h 9 9
(c) 36 km/h (d) 40 km/h
5. Two trains each of 120 m in length, run in opposite 1 7
(c) 5 days (d) 4 days
directions with a velocity of 40 m/s and 20 m/s respectively. 2 9
How long will it take for the tail ends of the two trains to 13. Two pipes can fill a tank in 10 hours and 12 hours respectively,
meet each other during the course of their journey ? while the third can empty it in 20 hours . If all the pipes are
(a) 20 s (b) 3 s opened together, the tank will be filled in :
(c) 4 s (d) 5 s
1
6. Pipes A and B can fill a tank in 5 and 6 hours, respectively. (a) 7 hours (b) 10 hours
Pipe C can empty it in 12 hours. The tank is half full. All 2
the three pipes are in operation simultaneously. After how 1
much time, the tank will be full ? (c) 8 hours (d) 9 hours
10
9 14. A train 110 m in length travels at 60 km/h. How much time
(a) 3 h (b) 11 h
17 does the train take in passing a man walking at 6 km/h
against the train ?
8 13 (a) 6 s (b) 12 s
(c) 2 h (d) 1 h
11 17 (c) 10 s (d) 18 s
7. A boat goes 24 km upstream and 28 km downstream in 6 15. A motor boat whose speed is 15 km/h in still water goes
hours. It goes 30km upstream and 21 km downstream in 30 km downstream and comes back in four and a half
6 hours and 30 minutes. The speed of the stream is : hours. The speed of the stream is :
(a) 10 km/h (b) 5 km/h (a) 46 km/h (b) 6 km/h
(c) 4 km/h (d) None of these (c) 7 km/h (d) 5 km/h
8. A mother and a daughter working together can complete 16. A can do a piece of work in 25 days B in 20 days. They
a certain work in 4 days. But if the mother worked alone work together for 5 days and then A goes away. In how
she could complete the work in 6 days. Both of them many days will B finish the remaining work ?
worked for one day and then the mother had to leave. (a) 17 days (b) 11 days
How long will the daughter take to complete remaining
(c) 10 days (d) None of these
work ?
17. A gun is fired at a distance of 3.32 km from Chauhan. He
(a) 7 days (b) 8 days
hears its sound 10 seconds later. Find the speed of the
(c) 6 days (d) 9 days
sound.
9. 12 men complete a work in 18 days. Six days after they
(a) 301 m/s (b) 302 m/s
had started working, 4 men joined them. How many days
(c) 332 m/s (d) 340 m/s
will all of them take to complete the remaining work ?
TIME AND WORK & SPEED AND DISTANCE S1-91
18. Two men and 7 children complete a certain piece of work (a) 48 km/hr (b) 54 km/hr
in 4 days, while 4 men and 4 children complete the same (c) 66 km/hr (d) 82 km/hr
work in only 3 days. The number of days required by 1 28. A can do a piece of work in 10 days, while B alone can
man to complete the work is : do it in 15 days. They work together for 5 days and the
(a) 60 days (b) 15 days rest of the work is done by C in 2 days. If they get ` 450
(c) 6 days (d) 51 days for the whole work, how should they divide the money ?
19. A tap can fill a tank in 16 minutes and another can empty (a) ` 225, ` 150, ` 75
it in 8 minutes. If the tank is already 1/2 full and both the (b) ` 250, ` 100, ` 100
taps are opened together, will the tank be filled or emptied? (c) ` 200, ` 150, ` 100
How long will it take before the tank is either filled or (d) ` 175, ` 175, ` 100
emptied completely as the case may be ? 29. Three pipes A, B and C can fill a tank in 6 minuets,
(a) Emptied; 16 min (b) Filled; 8 min 8 minutes and 12 minutes, respectively. The pipe C is
(c) Emptied; 8 min (d) Filled; 12 min closed 6 minutes before the tank is filled. In what time will
20. There are 20 poles with a constant distance between each the tank be full ?
pole. A car takes 24 seconds to reach the 12th pole . How (a) 4 min (b) 6 min
much time will it take to reach the last pole? (c) 5 min (d) Data inadequate
(a) 25.25 s (b) 17.45 s 30. A train covers 180 km distance in 4 hours. Another train
(c) 35.75 s (d) 41.45 s covers the same distance in 1 hour less. What is the
Directions [Qs. 21- 23] : Read the information given below to difference in the distances covered by these trains in one
answer the questions that follow. hour ?
Monica started moving from point B towards point A. Exactly an (a) 45 km (b) 9 km
hour after Puran started from A in the opposite direction but at a (c) 40 km (d) None of these
speed twice as much as that of Puran. By the time Puran covered 31. A sum of ` 25 was paid for a work which A can do in 32
one sixth of the distance between the points A and B, Monica also days, B in 20 days, B and C in 12 days and D in 24 days. How
covered the same distance. much did C receive if all the four work together ?
21. The point where Puran and Monica would meet is:
(a) closer to A 14 16
(a) ` (b) `
(b) exactly between A and B 3 3
(c) closer to B
(d) Monica and Puran will not meet at all 15 17
(c) ` (d) `
22. How many hours would Puran take to reach B ? 3 3
(a) 2 (b) 5 32. Two pipes A and B can fill a tank in 20 and 30 hours
(c) 6 (d) 12 respectively. Both the pipes are opened to fill the tank but
23. How many more hours would Puran take (compared to when the tank is 1/3rd full, a leak develops in the tank through
Monica) to complete the journey ? which one-third water supplied by both the pipes goes out.
(a) 4 (b) 5 The total time taken to fill the tank is
(c) 6 (d) 7 (a) 12 hours (b) 16 hours
24. A certain number of people were supposed to complete (c) 14 hours (d) 18 hours
a work in 24 days. The work, however, took 32 days, since 33. A sailor can row a boat 8 km downstream and return back to
9 people were absent throughout. How many people were the starting point in 1 hour 40 minutes. If the speed of the
supposed to be working originally? stream is 2 km/h, then the speed of the boat in still water is:
(a) 32 (b) 27 (a) 5 km/h (b) 10 km/h
(c) 36 (d) 30 (c) 15 km/h (d) 20 km/h
25. A pipe can fill a tank in 15 minutes and another one in 10 34. A car travels first half distance between two places with a
minutes. A third pipe can empty the tank in 5 minutes. The speed of 40 km/h and the rest of the half distance with a
first two pipes are kept open for 4 minutes in the beginning speed of 60 km/h. The average speed of the car is
and then the third pipe is also opened. In what time will the (a) 48 km/h (b) 37 km/h
tank be emptied ? (c) 44 km/h (d) none of these
(a) 35 min (b) 15 min 35. Two taps can fill a tank in 15 and 12 min, respectively. A third
(c) 20 min (d) Cannot be emptied
tap can empty it in 20 min. If all the taps are opened at the
26. If a heavily load trailer travelled 7 km in 1 hour and 10 minutes, same time, then in how much time will the tank be filled ?
then what was its speed in km per hour?
(a) 6 (b) 6.5 1
(a) 8 min (b) 10 min
(c) 8 (d) 10 2
27. A train 108 m long moving at a speed of 50 km/hr crosses a
train 112 m long coming from the opposite direction in 6 1
(c) 11 min (d) 14 min
seconds. The speed of the second train is 3
EBD_7203
S1-92 GENERAL APTITUDE FOR GATE
36. How many litres of water flows out of a pipe of cross section (a) 10 km/h (b) 30 km/h
5 cm2 in 1 min. If the speed of water in the pipe is 20 cm/sec? (c) 5 km/h (d) 20 km/h
(a) 2 litres (b) 5 litres 46. If I walk at 4 km/h, I miss the bus by 10 minutes. If I walk at
(c) 6 litres (d) 9 litres 5 km/h, I reach 5 minutes before the arrival of the bus. How
37. A train 100 metres long passes a bridge at the rate of far I walk to reach the bus stand ?
72 km/ hr in 25 seconds. What is the length of the bridge? (a) 5 km (b) 4.5 km
(a) 170 m (b) 400 m 1
(c) 600 m (d) None of these (c) 5 km / h (d) Cannot be determined
4
38. 12 men take 18 days to complete a job whereas 12 women in
Directions (Qs. 47-48): Answer the following questions on the
3 basis of the information given below:
18 days can complete of the same job. How many days (i) Trains A and B are travelling on the same route heading
4
will 10 men and 8 women together take to complete the same towards the same destination. Train B has already covered
job? a distance of 220 km before train A started.
1 (ii) The two trains meet each other 11 hours after the start of
(a) 6 (b) 13 train A.
2
(c) 12 (d) Data inadequate (iii) Had the trains been travelling towards each other (from a
39. The work done by a woman in 8 hours is equal to the work distance of 220 km), they would have met after one hour.
done by a man in 6 hours and by a boy in 12 hours. If 47. What is the speed of train B in kmph?
working 6 hours per day, 9 men can complete a work in 6 (a) 100 (b) 180
days then in how many days can 12 men, 12 women and 12 (c) 116 (d) Data inadequate
boys together finish the same work by working 8 hours per 48. What is the speed of train A in kmph?
day? (a) 102 (b) 80.5
(c) 118 (d) None of these
(a) 1 1 days (b) 3 2 days
3 3 49. A train consists of 12 boggies, each boggy 15 metres long.
1 The train crosses a telegraph post in 18 seconds. Due to
(c) 3 days (d) 1 days some problem, two boggies were detached. The train now
2
40. 24 men working 8 hours a day can finish a work in 10 days. crosses a telegraph post in
Working at the rate of 10 hours a day, the number of men (a) 18 sec (b) 12 sec
required to finish the same work in 6 days is : (c) 15 sec (d) 20 sec
(a) 30 (b) 32 50. Three fill pipes A, B and C can fill separately a cistern in 3, 4
(c) 34 (d) 36 and 6 minutes respectively. A was opened first. After 1
41. X can do a piece of work in 15 days. If he is joined by Y who minute, B was opened and after 2 minutes from the start of
is 50% more efficient, in what time will X and Y together A, C was also opened. Find the time when the cistern will be
finish the work? full ?
(a) 10 days (b) 6 days 1 1
(c) 18 days (d) Data insufficient (a) 2 min (b) 4 min
9 2
42. Two pipes can fill a cistern in 14 and 16 hours respectively.
The pipes are opened simultaneously and it is found that 3
due to leakage in the bottom, 32 minutes extra are taken for (c) 3 min (d) 3 min
4
the cistern to be filled up. If the cistern is full, in what time 51. A transporter receives the same number of orders each day.
would the leak empty it ? Currently, he has some pending orders (backlog) to be
(a) 110 hours (b) 112 hours shipped. If he uses 7 trucks, then at the end of the 4th day
(c) 115 hours (d) 100 hours he can clear all the orders. Alternatively, if he uses only 3
43. Starting with the initial speed of 30 km/hr, the speed is
trucks, then all the orders are cleared at the end of the 10th
increased by 4 km/hour every two hours. How many hours
day. What is the minimum number of trucks required so that
will it take to cover a distance of 288 km?
there will be no pending order at the end of the 5th day?
(a) 4 (b) 6
(a) 4 (b) 5 [GATE 2011, 2 marks]
(c) 12 (d) 8
(c) 6 (d) 7
44. There are 20 poles with a constant distance between each
52. 5 skilled workers can build a wall in 20 days; 8 semi-skilled
pole. A car takes 24 seconds to reach the 12th pole . How
much time will it take to reach the last pole? workers can build a wall in 25 days; 10 unskilled workers
(a) 25.25 s (b) 17.45 s can build a wall in 30 days. If a team has 2 skilled, 6 semi-
(c) 35.75 s (d) 41.45 s skilled and 5 unskilled workers, how long will it take to build
45. On a journey across Bombay, a tourist bus averages 10 km/h the wall? [GATE 2010, 2 marks]
for 20% of the distance, 30 km/h for 60% of it and 20 km/h for (a) 20 days (b) 18 days
the remainder. The average speed for the whole journey was (c) 16 days (d) 15 days
TIME AND WORK & SPEED AND DISTANCE S1-93
53. A tourist covers half of his journey by train at 60 km/h, should be accompanied by a parent. Other students and
half of the remainder by bus at 30 km/h and the rest by parents should come in time for the programme. The
cycle at 10 km/h. The average speed of the tourist in instruction you think that is appropriate for this is
km/h during his entire journey is [GATE 2013, 2 Marks] [GATE 2014, Set-3, 2 Marks]
(a) 36 (b) 30 (a) Students should come at 9.00 a.m. and parents should
(c) 24 (d) 18 come at 10.00 a.m.
54. What is the average of all multiples of 10 from 2 to 198? (b) Participating students should come at 9.00 a.m.
[GATE 2014, Set-2, 1 Mark] accompanied by a parent, and other parents and
(a) 90 (b) 100 students should come by 10.00 a.m.
(c) 110 (d) 120 (c) Students who are not participating should come by
55. At what time between 6 a.m. and 7 a.m. will the minute hand 10.00 a.m. and they should not bring their parents.
and hour hand of a clock make an angle closest to 60°? Participating students should come at 9.00 a.m.
[GATE 2014, Set-2, 2 Marks] (d) Participating students should come before 9.00 a.m.
(a) 6 : 22 am (b) 6 : 27 am Parents who accompany them should come at 9.00
(c) 6 : 38 am (d) 6 : 45 am a.m. All others should come at 10.00 a.m.
56. A dance programme is scheduled for 10.00 a.m. Some students
are participating in the programme and they need to come
an hour earlier than the start of the event. These students
EBD_7203
S1-94 GENERAL APTITUDE FOR GATE
x 10 x 50 x 1 x 5 1 1 1 17
Then, - = - Þ - = - simultaneously in one hour is = + - =
50 60 30 60 50 6 30 6 5 6 12 60
60
x x 2 i.e. it takes hours to fill up the tank completely.
or - = or x = 50 km 17
30 50 3
Thus distance between the stations A and B is 50 1
Now, of the tank is filled with all the pipes open,
km. 2
2. (c) Let the distance travelled during both upward and
60 1 13
downward journey be x km. simultaneously together in ´ = 1 hours
17 2 17
Total distance covered 7. (c) Let the speed of the stream be x km/h and the speed
Average speed =
Total time taken of the boat in still water be y km/h.
Downward speed = (x + y) km/h
x+x 2 and upward speed = (y – x) km/h
= =
x x 28 + 16
+ 24 28
16 28 28 ´16 We have, + = 6 ....... (i)
y-x y+x
2 ´ 28 ´16
= = 20.36 km / h
44 30 21 1 13
and, + =6 = ....... (ii)
3. (b) Let the distance travelled be x km. y-x y+x 2 2
Then, the correct time at a speed of 30 km/h Solving (i) and (ii), we have,
Þ y + x = 14 and y – x = 6 Þ x = 4 km/h
x 10
= - and
30 60 1
8. (d) (Mother + Daughter)’s one day’s work =
4
x 10
the correct time at a speed of 42 km/h = +
42 60 3
Remaining work =
4
Now, x 10 x 10
- = + 1
30 60 42 60 Mother’s one day’s work =
6
x x 2 12x 2
or - = or = or x = 35 km 1 1 1
30 42 6 1260 6 Daughter’s one day’s work = - =
4 6 12
Total distance
4. (b) Average speed = 1
Total time work is done by the daughter in 1 day.
12
80 80 3
= = = 32 km/h Therefore, work will be done by the daughter in
60 20 2.5 4
+
40 20
12 ´ 3
5. (c) Relative speed of the trains = (40 + 20) = 60 m/s = 9 days
4
Distance = (120 + 120) = 240 m
Time taken by trains to cross each other completely 1
9. (d) In 1 day, work done by 12 men =
18
240
= = 4s 6 1
60 In 6 days, work done by 12 men = =
18 3
TIME AND WORK & SPEED AND DISTANCE S1-95
2 æ 1 1 ö 45 9
Remaining work = 16. (b) (A + B)’s 5 days’ work = 5 ç + ÷ = =
3 è 25 20 ø 100 20
Now, m1 ´ d1 ´ w 2 = m 2 ´ d 2 ´ w1
æ 9 ö 11
Remaining work = ç1 - ÷ =
2 è 20 ø 20
or 12 ´18 ´ = 16 ´ d 2 ´ 1
3
11
of the work would be finished by B in
4 ´ 18 ´ 2 20
or d 2 = = 9 days
16
11
1 1 1 20 = 11days.
10. (b) B’s one day work = - =
6 10 15 1
Hence, B can do the work alone in 15 days. 20
11. (a) Suppose the speed of the train be x km/h and that of 17. (c) Distance between Chauhan and the gun
the car be y km/h., = 3.32 × 1000 = 3320 m
160 600 Time taken = 10 s
Now, + =8 ............... (i)
x y 3320
Þ Speed = = 332 m / s
240 520 41 10
and + = ............... (ii)
x y 5 1
18. (b) (2M + 7C)’s 1 day’s work =
Solving (i) and (ii), we have x = 80 km/h and 4
y = 100 km/h. Þ work will be completed by 4 (2M + 7C)
1 1 9 = 8 M + 28 C
12. (a) Work done together in one day = + =
8 10 40 1
Therefore, the work will be completed together in Again, (4M + 4C)’s 1 day’s work =
3
40 4 i.e. 12M + 12C will complete the work.
or 4 days.
9 9 Þ 8M + 28C = 12M + 12C or M = 4C
13. (a) Portion of the tank filled by all the pipes together in Therefore, 4M + 4C = 5M
1 1 1 6+5-3 8 2 Since 5M complete a work in 3 days,
1 hour = + - = = =
10 12 20 60 60 15 1 M will complete it in 15 days.
19. (c) If both the pumps are opened together, then the tank
15 1 will be emptied because the working efficiency of
Hence, the tank will be filled in hours or 7
2 2 pump empting is more than that of the pump filling
hours. it. Thus in 1 min net work done
14. (a) Relative speeds of the train and the man
æ1 1 ö 1
66 ´ 5 = ç - ÷= parts
= (60 + 6) = 66 km/h = m/s è 8 16 ø 16
18
or the tank will be emptied in 16 min
Distance = 110 m
Therefore, time taken in passing the men 1
Þ tank will be emptied in 8 min.
2
110 ´ 18
= = 6s 20. (d) Let the distance between each pole be x m.
66 ´ 5
Then, the distance up to 12th pole = 11 x m
15. (d) Let the speed of the stream be x km/h.
Then, upstream speed = (15 – x) km/h. 11x
and downstream speed = (15 + x) km/h. Speed = m/s
24
30 30 Time taken to covers the total distance of 19x
Now, + = 4.5
(15 + x) (15 - x) 19x ´ 24
= = 41.45 s
Solving these equations, we get x = 5 km/h. 11x
EBD_7203
S1-96 GENERAL APTITUDE FOR GATE
For Qs. 21 to 23 : 25. (c) Proportion of the volume of the tank filled by both
Puran Monica æ1 1ö 2
the pipes in 4 min = 4ç + ÷ = rd of the tank.
A B è 15 10 ø 3
x km
2y km/hr y km/hr Volume of the tank filled by all the pipes working
Let the distance between the point A and B be x km and the 1 1 1 -1 1
speeds of Monica and Puran be 2y km/hr and y km/hr, together = + - = i.e. tank is emptied
15 10 5 30 30
respectively.
in 1 min.
x x/6 x
Now, time taken by Puran to cover km = = hours 2 2 ´ 30
6 y 6y \ rd of the tank can be emptied in = 20
3 3
min
x x/6
Time taken by Monika to cover km = 26. (a) In 70 minutes, HLT travelled 7 km.
6 2y
In 1 hour, HLT travelled 6 km.
x \ Speed = 6 km/h
= hours 27. (d) Let the speed of the second train be x km/h
12y
The relative speed = (50 + x) km/h
x x These trains will cross each other in a time equivalent
We have, = +1 of covering a distance equal to 108 + 112,
6 y 12y
i.e. 220 meters in 6 seconds, running speed of (50 + x)
km/h
x é1 1 ù
or - =1 or x = 12y
y êë 6 12 úû 1 220 6
\ ´ = Þ x = 82
50 + x 1000 3600
21. (a) Since Monica has already moved a distance (covered
in an hour) before Puran starts his journey, both of \ The speed of the second train = 82 km/hr.
them are in motion for the first time when the distance 28. (a) Work done by A and B in 5 days
between them is
æ 1 1ö 5
(12y – y) = 11y km = ç + ÷´5 =
è 10 15 ø 6
This relative speed = y + 2y = 3y km/hr
5 1
11y 11 Work remaining = 1 - =
Time when they will meet = = hr 6 6
3y 3
\ C alone can do the work in 6 × 2 = 12 days
Distance travelled by Monica when both of them meet
5 5 2
11 22 Ratio of their share work = : : = 3 : 2 :1
= ´ 2y = y = 7.33 y km 10 15 12
3 3 Share of wages = ` 225, ` 150, ` 75.
Therefore, their point of meeting is closer to A 29. (a) Let it takes t minutes to completely fill the tank.
x t t t -6
22. (d) Time taken by Puran to reach the point B = Now, + + =1
y 6 8 12
12y 4t + 3t + 2 t - 12
= 12 hours or =1 or 9t – 12 = 24
= 24
y
23. (c) Time taken by Monica to cover 12y km 36
or 9t = 36 or t= = 4 min .
9
12 y
= = 6 hours 30. (d) First train’s speed is 45km/hr.
2y
æ Distance ö
Hence, Puran will take (12 – 6) = 6 hours more as çè Using speed = ÷
Time ø
compared to Monica to complete the journey
24. (c) Let x people were supposed to be working originally. Second train’s speed is 60km/hr.
Difference in the distance covered by these trains
Therefore, 24x = 32 (x – 9) or 24x = 32x – 288
in 1 hr. is 15 km.
or x = 36 people
TIME AND WORK & SPEED AND DISTANCE S1-97
Speed of the stream = 2 km/ hr
1
31. (b) A's one day's work = \ Speed of the boat downstream = (x + 2) km/hr
32
Speed of the boat upstream = (x – 2) km/hr
1
B's one day's work = 8 8 2 5
20 \ + =1 =
x+2 x–2 3 3
1 Þ 24x – 48 + 24x + 48 = 5(x2 – 4)
(B + C)'s one day's work =
12
Þ 5x2 – 48x – 20 = 0
1 1 1
\ C's one day's work = - = 48 ± 2304 + 400 48 ± 52
12 20 30 Þx= = = 10 , – 0.4
10 10
1 \ Speed of the boat in still water = 10 km/hr.
D's one day's work =
24
2 ´ V1 ´ V2 2 ´ 40 ´ 60
\ (A + B + C + D)'s one day's work 34. (a) Average speed = =
V1 + V2 40 + 60
1 1 1 1 75 + 120 + 80 + 100 = 48 km/h
= + + + =
32 20 30 24 2400 35. (b) Part of tank filled in one minute in given condition
375 15 5 1 1 1 4+5–3 6 1
= = = + – = = =
2400 96 32 15 12 20 60 60 10
5 \ Tank will be completely filled in 10 min.
\ Out of of work done,
32 36. (c) Let speed of water in pipe = 20 cm/sec.
Area of cross – section = 5 cm2.
1
of the work is done by C. \ Volume of water in 60 second
30
= 60 × 100 cm3
Þ Out of ` 25 paid for the work, C will receive = 6000 cm3
1/ 30 1 32 16 » 6 litre
` ´ 25 = ´ ´ 25 = `
5 / 32 30 5 3 (Q 1litre = 1000 cm)
32. (b) The pipes A and B together can fill
37. (b) Let x be the length of the bridge.
1 1 1 Length of the train = 100 m
+ = of the tank in one hour..
20 30 12
72 ´ 5
Speed of train = 72 km/hr = m/s
1 18
\ of the tank is filled by both the pipes A and B
3 Time taken by train = 25 seconds.
together in 4 hours. ...........(1)
100 + x 5
Now because of developing a leak after 4 hours, both \ 25 = Þ 25 × 72 × = 100 + x
5 18
1 1 1 72 ´
the pipes can fill - = of the tank in one hour 18
12 36 18
Þ x = 500 – 100 = 400 m.
1
[ Becauses rd of the water supplied by both the pipes 4
3 38. (b) 12 M × 18 = 12 W × 18 ×
3
goes out]
3
2 [ W= M
\ Remaining of the tank can be filled by both the 4
3
3
2 10M + 8W = 10M + 8 × M = 16 M
pipes in × 18 = 12 hours ...... (2) 4
3 [ 16 men can complete the same work
\ The total time taken to fill the tank is 16 hours.
12 ≥18 27 1
33. (b) Let the speed of the boat in still water be x km/hr in < < 13 days
16 2 2
EBD_7203
S1-98 GENERAL APTITUDE FOR GATE
39. (d) 8W = 6M = 12B
15 1 1
= - = th
12M + 12W + 12B Þ 12M + 9M + 6M = 27M 112 8 112
[ 9 men can complete the work by working 1 hour per \ in 112hr, the leakage would empty the cistern.
day in 6 × 6 days
43. (d) Hour Speed (km/h) Distance travelled (in km)
6≥ 6≥ 9 1
[ 27 men working 8 hours per day = < 1 days.
27 ≥8 2 2 30 60
2 34 68
40. (b) m1 ´ d1 ´ t1 ´ w 2 = m 2 ´ d 2 ´ t 2 ´ w1 2 38 76
2 42 84
24 × 10 × 8 × 1 = m2 × 6 × 10 × 1 8 288
24 ´ 10 ´ 8
Þ m2 = = 32 men Hence, the required time = 8 hours
6 ´ 10
44. (d) Let the distance between each pole be x m.
19 x ´ 24
1 1 1 = = 41.45 s
\ (X + Y)’s one day’s work = + = th work 11x
15 10 6
45. (d) Let the average speed be x km/h.
Hence, they together finish the work in 6 days.
and Total distance = y km. Then,
42. (b) Cistern filled by both pipes in one hour
0.2 0.6 0.2 y
y+ y+ y=
1 1 15 10 30 20 x
= + = th
14 16 112
1
Þx= = 20km / h
0.05
112
\ Both pipes filled the cistern in hrs .
15
é difference of time ù
46. (a) d = product of speed ê ú
Now, due to leakage both pipes filled the cistern in ë difference of speed û
Þ d = 5 km
1
\ due to leakage, filled part in one hour =
8
220 220
VA – VB = Þ Þ V A - VB = 20 .... (i) 17
11 11 Þ x=
3
220 Þ x>5
VA + VB = Þ VA + VB = 220 .... (ii)
1
Minimum possible = 6
Solving the equations (i) and (ii), we get VA = 120 km/hr 52. (d) 5 skilled workers build wall in 20 days
and VB = 100 km/hr
\ 1 skilled worker build wall in 20 × 5 days
47. (a) 48. (d)
Hence in 1 day, part of work done by skilled
49. (c) Length of train = 12 × 15 = 180 m.
1
work =
180 100
Then, speed of train = = 10 m / s
18
Similarly in 1 day part of work done by semi-skilled
Now, length of train = 10 ´15 = 150m workers
150 1
\ Required time = = 15sec. =
10 25 ´ 8
50. (a) Let cistern will be full in x min. Then, and in 1 day part of work done by un-skilled worker
19 1 2 6 5 1
Þ 9x = 19 Þ x = = 2 min = + + =
9 9 100 200 300 15
51. (c) Let each truck carry 100 units. So work done by given workers in days = 15
where, e = excess/pending (10 + 190) + (20 + 180) + ... + (90 + 110) + 100
= (9 × 200) + 100
100
\ n= = 1800 + 100
3
= 1900
8000
e=
3 1900
\ Average = = 100
19
5 ´100 8000
Þ 5 days ® 500 x = +
3 3
EBD_7203
S1-100 GENERAL APTITUDE FOR GATE
55. (a) At 6 a.m. the clock likes.
120°
\ Number of minutes move 120° = = 20 minutes
6
12
The nearest answer is 6 : 22 am
180° 12
9 3
120°
9 3
6
60°
4
i.e., it is 180° apart 5
6
To make 60° angle, it has to move (180° – 60°) = 120°
56. (b)
360
Angle moved in one minute = = 6°
60
5 Ratio & Proportion, Partnership
& Mixture (Alligations)
a c a -b c-d This is expressed by saying that ‘a’ is to ‘b’ as ‘c’ is to ‘d’ and the
4. If = , th en = . This property is proportion is written as
b d b d
called Dividendo. a : b :: c : d or a:b=c: d
The terms a and d are called the extremes while the terms b and c
a c a +b c+d are called the means.
5. If = , th en = . This property is
b d a -b c-d NOTE :
called Componendo – Dividendo. • If four quantities are in proportion, the product of the ex-
a c e tremes is equal to the product of the means.
6. If = = = .............. . Then, Let a, b, c, d be in proportion, then
b d f
a c
= Þ ad = bc.
sum of Numerators b d
Each ratio = sum of denominators • If three quantities a, b and c are in continued proportion,
then a : b = b : c
i.e.
a c a + c + e + ...
= =
\ ac = b2
b d b + d + f + ... b is called mean proportional.
EBD_7203
S1-102 GENERAL APTITUDE FOR GATE
• If three quantities are proportionals, then first is to the third MIXTURE (ALLIGATION)
is the duplicate ratio of the first is to the second.
Simple Mixture : When two different ingredients are mixed
If a : b :: b : c then a : c = a2 : b2 together, it is known as a simple mixture.
Direct Proportion : Compound Mixture : When two or more simple mixtures are mixed
If on the increase of one quantity, the other quantity increases to together to form another mixture, it is known as a compound
the same extent or on the decrease of one, the other decreases to mixture.
the same extent, then we say that the given two quantities are
Alligation : Alligation is nothing but a faster technique of solving
directly proportional. If A and B are directly proportional then we
problems based on the weighted average situation as applied to
denote it by A µ B. the case of two groups being mixed together.
Also, A = kB, k is constant
The word ‘Alligation’ literally means ‘linking’.
Some Examples :
• Alligation rule : It states that when different quantities of
1. Work done µ number of men
the same or different ingredients of different costs are mixed
2. Cost µ number of Articles
together to produce a mixture of a mean cost, the ratio of
3. Work µ wages
their quantities is inversely proportional to the difference in
4. Working hour of a machine µ fuel consumed
their cost from the mean cost.
5. Speed µ distance to be covered
Quantity of Cheaper Price of Dearer - Mean Price
Indirect Proportion (or inverse proportion) : =
Quantity of Dearer Mean Price - Price of Cheaper
If on the increase of one quantity, the other quantity decreases to
Graphical representation of Alligation Rule :
the same extent or vice versa, then we say that the given two
quantities are indirectly proportional. If A and B are indirectly Quantity Quantity
a b
1
proportional then we denote it by A µ . Mean
B
Average (d)
k
Also, A = (k is a constant)
B
b–d d–a
EXERCISE
1. The ratio of the prices of two houses A and B was 4 : 5 9. The ages of two persons are in the ratio of 5 : 7. Sixteen
last year. This year, the price of A is increased by 25% years ago, their ages were in the ratio of 3: 5. Their present
and that of B by ` 50000. If their prices are now in the ages are:
ratio 9 : 10, the price of A last year was : (a) 30 years and 44 years
(a) `3,60,000 (b) `4,50,000 (b) 35 years and 52 years
(c) `4,80,000 (d) `5,00,000 (c) 40 years and 56 years
2. A, B and C enter into a partnership with investments of (d) 45 years and 60 years
`3500, `4500 and `5500, respectively. In the first six 10. In a mixture of 28 litres, the ratio of milk and water is 5 : 2.
months, profit is `405. What is A’s share in the profit ? Another 2 litres of water is added to the mixture. The ratio of
(a) `200 (b) `105 milk and water in the new mixture is:
(c) `250 (d) `151 (a) 1: 1 (b) 2: 1
(c) 3: 1 (d) 4: 1
3. Ram spends `3620 for buying pants at the rate of `480
11. In three vessels, the ratio of water and milk is 6 : 7, 5 : 9 and
each and shirts at the rate of `130 each. What will be the
8 : 7, respectively. If the mixtures of the three vessels are
ratio of pants to shirts when maximum number of pants
mixed together, then what will be the ratio of water and milk?
are to be bought ?
(a) 2431 : 3781 (b) 3691 : 4499
(a) 7 : 2 (b) 7 : 3
(c) 4381 : 5469 (d) None of these
(c) 2 : 7 (d) None of these 12. A container contains 40 litres of milk. From this container, 4
4. Mixture of milk and water has been kept in two separate litres of milk was taken out and replaced by water. This
containers. Ratio of milk to water in one of the containers is process was repeated further two times. How much milk is
5 : 1 and that in the other container is 7 : 2. In what ratio
now contained by the container ?
should the mixtures of these two containers be added
together so that the quantity of milk in the new mixture may (a) 26.34 litres (b) 27.36 litres
become 80%? (c) 28 litres (d) 29.16 litres
(a) 3 : 2 (b) 2 : 3 13. Three containers A, B and C are having mixtures of milk
(c) 4 : 5 (d) None of these and water in the ratio 1 : 5, 3 : 5 and 5 : 7, respectively.
If the capacities of the containers are in the ratio 5 : 4 :
5. Rahul started a business with a capital of ` 8,000. After six
5, then find the ratio of the milk to the water if the mixtures
months, Sanjay joined him with an investment of some
capital. If at the end of the year each of them gets equal of all the three containers are mixed together.
amount as profit, how much did Sanjay invest in the (a) 51 : 115 (b) 52 : 115
business? (c) 53 : 115 (d) 54 : 115
(a) `16,000 (b) `17,500 14. A began a business with `4500 and was joined afterwards
(c) `18,000 (d) `16,500 by B with `5400. If the profits at the end of year was
divided in the ratio 2 : 1, B joined the business after :
6. At Narmada Sarovar Bachao (NSB) demonstration,
(a) 5 month (b) 4 months
supporters of Ms Patkar outnumbered the police by 9 : 1.
The police arrested 135 NSB supporters averaging 5 for (c) 6 months (d) 7 months
every 3 policemen. How many supporters of NSB were there 15. Profits of a business are distributed among three partners
in the demonstration? A, B and C in such a way that 4 times the amount received
(a) 1215 (b) 665 by A is equal to 6 times the amount received by B and 11
(c) 405 (d) None of the above times the amount received by C. The ratio in which the three
7. A mixture (40 litres) contains tonic and water in the ratio received the amount is
3 : 1. To make the ratio 7 : 2, how much additional amount of (a) 4 : 6 : 11 (b) 11 : 6 : 4
water is required? 1 1 1
(a) 5 litres (b) 4 litres (c) : : (d) 66 : 44 : 24
4 6 11
(c) 3 litres (d) 2 litres
16. A and B are two alloys of gold and copper prepared by
8. An iron cube of size 10 cm is hammered into a rectangular mixing metals in the ratio 7 : 2 and 7 : 11 respectively. If equal
sheet of thickness 0.5 cm. If the sides of the sheet be in the quantities of the alloys are melted to form a third alloy C,
ratio 1 : 5, then the sides are then the ratio of gold and copper in alloy C will be
(a) 20 cm, 100 cm (b) 10 cm, 50 cm (a) 5 : 7 (b) 5 : 9
(c) 40 cm, 200 cm (d) None of these (c) 7 : 5 (d) 9 : 5
RATIO & PROPORTION, PARTNERSHIP & MIXTURE (ALLIGATIONSS1-105
)
17. Given that 24 carat gold is pure gold. 18 carat gold is (a) ` 9,000 (b) ` 12,000
3 5 (c) ` 11,000 (d) ` 10,000
pure gold and 20 carat gold is pure gold. The ratio 27. Salaries of Rajesh and Sunil are in the ratio of 2 :3. If the
4 6
of the pure gold in 18 carat gold to the pure gold in 20 salary of each one is increased by ` 4000 the new ratio
carat gold is : becomes 40 : 57. What is Sunil’s present salary?
(a) 3 : 8 (b) 9 : 10 (a) ` 17000 (b) ` 20000
(c) 15 : 24 (d) 8 : 5 (c) ` 25500 (d) None of these
18. The ratio of the rate of flow of water in pipes varies 28. The ratio of males and females in a city is 7 : 8 and the
inversely as the square of the radii of the pipes. What is percentage of children among males and females is 25% and
the ratio of the rates of flow in two pipes of diameters 2 20% respectively. If the number of adult females in the city
cm and 4 cm, respectively? is 156800 what is the total population?
(a) 1 : 2 (b) 2 : 1 (a) 245000 (b) 367500
(c) 1 : 8 (d) 4 : 1 (c) 196000 (d) 171500
19. If the ratio of boys to girls in a class is B and the ratio 29. The ratio of number of ladies to gents at a party was 1 : 2,
of girls to boys is G, then 3 (B + G) is : but when 2 ladies and 2 gents left, the ratio became 1 : 3.
(a) equal to 3 (b) less than 3 How many people were originally present at the party?
1 (a) 6 (b) 9
(c) more than 3 (d) less than
3 (c) 12 (d) 10
20. The monthly income of two persons are in the ratio of A B C
4 : 5 and their monthly expenditures are in the ratio of 30. If A : B : C = 2 : 3 : 4, then : : is equal to :
B C A
7 : 9. If each saves ` 50 a month, then what are their
monthly incomes ? (a) 4 : 9 : 16 (b) 8 : 9 : 12
(a) `100, ` 125 (b) ` 200, `s 250 (c) 8 : 9 : 16 (d) 8 : 9 : 24
(c) ` 300, ` 375 (d) ` 400, ` 500 31. Mr. Kutty has only hens and sheep. If the total number of
21. A bag contains Rs 216 in the form of one rupee, 50 paise their heads is 38 and the total number of legs is 100 then
and 25 paise coins in the ratio of 2 : 3 : 4. The number of what is the ratio between the numbers of hens and sheep?
50 paise coins is : (a) 2 : 1 (b) 1 : 2
(a) 96 (b) 144 (c) 6 : 13 (d) 13 : 6
(c) 114 (d) 141 32. A bag contains an equal number of one rupee, 50 paise and
22. If `1066 is divided among A, B, C and D such that 25 paise coins respectively. If the total value is ` 35, how
A : B = 3 : 4, B : C = 5 : 6 and C : D = 7 : 5, who will get many coins of each type are there?
the maximum? (a) 20 coins (b) 30 coins
(a) B (b) A
(c) 28 coins (d) 25 coins
(c) C (d) D
23. The sum of three numbers is 98. If the ratio of the first to 33. A and B enter into partnership with capitals in the ratio 3 : 4.
the second is 2 : 3 and that of the second to the third is At the end of 10 months A withdraws, and the profits now
5 : 8, then the second number is : are divided in the ratio of 5 : 6. Find how long B remained in
(a) 20 (b) 30 the business?
(c) 38 (d) 48 (a) 9 months (b) 8 months
24. If two numbers are in the ratio 6 : 13 and their least (c) 6 months (d) 7 months
common multiple is 312, then the sum of the numbers is :
(a) 75 (b) 57 34. Gold is 19 times as heavy as water and copper is 9 times
(c) 76 (d) 67 heavy. In what ratio must these metals be mixed so that the
25. If 40% of a number is equal to two-thirds of another number, mixture may be 15 times as heavy as water?
what is the ratio of the first number to the second? (a) 2 : 3 (b) 3 : 2
(a) 7 : 3 (b) 3 : 7 (c) 1 : 3 (d) 2 : 1
(c) 2 : 5 (d) 5 : 3 35. Alcohol cost ` 3.50 per litre and kerosene oil cost ` 2.50 per
26. Three friends A, B and C started a business by investing a litre. In what proportion these should be mixed so that the
sum of money in the ratio of 5 : 7 : 6. After 6 months C
resulting mixture may be ` 2.75 per litre?
withdraws half of his capital. If the sum invested by ‘A’ is
` 40,000, out of a total annual profit of ` 33,000, C’s share (a) 2 : 5 (b) 1 : 3
will be (c) 4 : 7 (d) 2 : 3
EBD_7203
S1-106 GENERAL APTITUDE FOR GATE
36. The ratio of the present ages of a son and his father is 1 : 5 45. If a certain number of workmen can do a piece of work in 25
and that of his mother and father is 4 : 5. After 2 years the hours, in how many hours will another set of an equal number
ratio of the age of the son to that of his mother becomes of men, do a piece of work, twice as great, supposing that 2
3 : 10. What is the present age of the father? men of the first set can do as much work in an hour, as 3 men
(a) 30 years (b) 28 years of the second set do in an hour ?
(c) 37 years (d) None of these (a) 60 (b) 75 (c) 90 (d) 105
37. When 50% of one number is added to a second number, the 46. A contractor undertook to do a certain piece of work in 9
second number increases to its four-thirds. What is the ratio days. He employed certain number of men, but 6 of them
between the first number and the second number? being absent from the very first day, the rest could finish
(a) 3 : 2 (b) 3 : 4 the work in 15 days. The number of men originally employed
(c) 2 : 3 (d) None of these were :
1 2 3 (a) 12 (b) 15 (c) 18 (d) 24
38. If ` 782 be divided into three part, proportional to : : ,
2 3 4 47. Three men A, B and C together subscribe `4700 for a
then the first part is : business. A puts in `700 more than B and B puts in ` 500
(a) `182 (b) `190 more than C. How much B will receive out of a total profit of
(c) `196 (d) ` 204 `4230?
39. The ratio of number of ladies to gents at a party was 1 : 2, (a) `1560 (b) `1350
but when 2 ladies and 2 gents left, the ratio became 1 : 3.
How many people were originally present at the party? (c) `1100 (d) `1475
(a) 6 (b) 9 48. A and B enter into partnership with capitals in the ratio 3 : 4.
(c) 12 (d) None of these At the end of 10 months A withdraws, and the profits now
40. Mrs X spends ` 535 in purchasing some shirts and ties for are divided in the ratio of 5 : 6. Find how long B remained in
her husband. If shirts cost ` 43 each and the ties cost ` 21 the business?
each, then what is the ratio of the shirts to the ties, that are (a) 9 months (b) 8 months
purchased ? (c) 6 months (d) 7 months
(a) 1 : 2 (b) 2 : 1 (c) 2 : 3 (d) 3 : 4
49. A began business with `12500 and is joined afterwards by
41. Zinc and copper are melted together in the ratio 9 : 11. What
B with ` 37500. When did B join, if the profits at the end of
is the weight of melted mixture, if 28.8 kg of zinc has been
consumed in it? the year are divided equally?
(a) 58 kg (b) 60 kg (c) 64 kg (d) 70 kg (a) 8 months (b) 9 months
42. Three containers have their volumes in the ratio 3 : 4 : 5. (c) 10 months (d) 7 months
They are full of mixtures of milk and water. The mixtures
50. Three students A, B and C hired a computer for a month. A
contain milk and water in the ratio of (4: 1), ( 3 : 1) and (5 : 2)
runs 27 floppy discs for 19 days, B runs 21 for 17 days and
respectively. The contents of all these three containers are
poured into a fourth container. The ratio of milk and water in C runs 24 for 23 days. If at the end of the month, the rent
the fourth container is: amounts to `23, 700, how much rent to be paid by C?
(a) 4 : 1 (b) 151 : 48 (a) ` 10,000 (b) ` 9,200
(c) 157 : 53 (d) 5 : 2
43. A man and a boy together can do a certain amount of digging (c) ` 8,700 (d) None of these
in 40 days. Their skills in digging are in the ratio of 8 : 5. How 51. A container originally contains 10 litres of pure spirit. From
many days will the boy take, if engaged alone. this container 1 litre of spirit is replaced with 1 litre of water.
(a) 52 days (b) 104 days
Subsequently, 1 litre of the mixture is again replaced with 1
(c) 68 days (d) 80 days
litre of water and this process is repeated one more time.
44. A garrison of 3000 men has provisions for 25 days, when
given at the rate of 900 g per head. At the end of 11 days, a How much spirit is now left in the container?
reinforcement arrives and it was found that now the [GATE 2011, 2 Marks]
provision will last 10 days more, when given at the rate of
840 g per head. What is the strength of reinforcement ? (a) 7.58 litres (b) 7.84 litres
(a) 1500 men (b) 1800 men (c) 7 litres (d) 7.29 litres
(c) 1950 men (d) Cannot be determined
RATIO & PROPORTION, PARTNERSHIP & MIXTURE (ALLIGATIONSS1-107
)
52. The current erection cost of a structure is ` 13,200. 54. The ratio of male to female students in a college for five
1 years is plotted in the following line graph. If the number of
If the labour wages per day increase by of the current female students in 2011 and 2012 is equal, what is the ratio
5
1 of male students in 2012 to male students in 2011?
wages and the working hours decrease by of the
24
current period, then the new cost of erection in ` is
[ (a - b) 2 ³ 0 Þ a + b - 2ab ³ 0
4 2 2
After 3rd operation 32.4 – ×32.4 7.6 –
4
× 7.6 + 4 Q
40 40
= 32.4 – 3.24 =7.6 – 0.76 + 4 a 2 + b2
Þ a 2 + b 2 ³ 2ab Þ ³2]
= 29.16 = 10.84 ab
\ The quantity of milk in the container = 29.16 litres. 20. (d) Let the income of two persons be `4x and `5x
13. (c) Ratio of milk in the containers are,
Let their expenses be ` 7y and ` 9y
1 3 5 5 3 25 \ Saving = 4x – 7y = 50 ............. (i)
5´ : 4´ : 5´ = : :
6 8 12 6 2 12 and 5x – 9y = 50 ................ (ii)
and the ratio of water in the containers are, on solving (i) and (ii), we get
x = 100 and y = 50
5 5 7 25 5 35
5´ : 4´ : 5´ = : : Thus, the income of the two persons are ` 400 and
6 8 12 6 2 12
` 500, respectively.
Ratio of mixture of milk and water in the containers 21. (b) Let the no. of one rupee, 50 paise and 25 paise coins
be 2x, 3x and 4x respectively.
= ç ´ 5 + ´ 4 + ´ 5 ÷ : ç ´ 5 + ´ 4 + ´ 5 ö÷
æ1 3 5 ö æ5 5 7
è 6 8 12 ø è 6 8 12 ø According to question,
= 106 : 230 = 53 : 115
æ 3x 4x ö
14. (d) Let B joined after x months. ` ç 2x + + ÷ = ` 216
Then, 4500 × 12 : 5400 × (12 – x) = 2 : 1 è 2 4 ø
4500 ´ 12 2 10 2 8x + 6x + 4x
or = or = Þ = 216
5400 ´ (12 - x ) 1 12 - x 1 4
or 10 = 24 – 2x or 2x = 14 or x = 7 months \ x = 48
15. (c) According to given condition, we have \ Number of 50 paise coins = 48 × 3 = 144
4A = 6B = 11C º k(say) 22. (c) Since A : B = 3 : 4 .......... (i)
B:C=5:6 .......... (ii)
k k k and C : D = 7 : 5 .......... (iii)
Þ A= ,B = ,C =
4 6 11 Therefore, by, proportionating, (i) and (ii)
1 1 1 A : B = 3 × 5 : 4 × 5 = 15 : 20
\ Ratio of receiving the amount = : :
B : C = 20 : 24 and C : D = 7 : 5
4 6 11
16. (c) Gold Copper Hence, A : B : C = 15 : 20 : 24 .......... (iv)
Type A 14 4 Now, A : B : C = 15 × 7 : 20 × 7 : 24 × 7
Type B 7 11 = 105 : 140 : 168
Type C 21 15 \ C : D = 24 × 7 : 24 × 5 = 168 : 120
\ The ratio of the Gold and Copper in the type C alloy [By proportionating (iii) and (iv)]
= 7 : 5.
Hence, A : B : C : D = 105 : 140 : 168 : 120
3 Hence, C gets the maximum share.
17. (b) 18 carat gold = pure gold
4 23. (b) Let A, B and C be the first, second and third nos.
3 respectively.
= ´ 24 = 18 carat pure gold
4 Then, A : B = 2 : 3 and B : C = 5 : 8
5 Consider, A : B = 2 : 3 = 2 × 5 : 3 × 5 = 10 : 15
20 carat gold = pure gold
6 and B : C = 5 : 8 = 5 × 3 : 8 × 3 = 15 : 24
5 \ A : B : C = 10 : 15 : 24
= ´ 24 = 20 carat pure gold Let the required number be 10x, 15x and 24x.
6
\ Required ratio = 18 : 20 = 9 : 10 Given, sum of three numbers = 98
18. (d) Radius of the two pipes are 1 cm and 2 cm. Then,
Square of the radii of the pipes are 1 and 4. \ 10x + 15x + 24x = 98
\ Required ratio of rates of flow in the two pipes Þ 49x = 98 Þ x = 2
1 Þ Second number = 15x = 15 × 2 = 30
= 1: =4:1
4 24. (c) Let the numbers be 6x and 13x.
19. (c) Let the number of boys be x and the number of girls LCM (6x, 13x) = 13 × 6 × x = 312 (given)
be y.
312
æx yö 3(x 2 + y2 ) Þ x= Þ x=4
Then, 3(B + G) = 3 ç + ÷ = , 13 ´ 6
èy xø xy So, the numbers are 24 and 52.
Clearly, which is greater than 3. \ Sum of the numbers = 24 + 52 = 76
EBD_7203
S1-110 GENERAL APTITUDE FOR GATE
25. (d) Suppose the first number is x and the second number y. 35. (b) By the rule of alligation, we have
2 Cost of Alcohol Cost of Kerosene Oil
Therefore, 40% of x = of y ` 3.50 ` 2.50
3
x 2 100 5
\ = ´ = cost of
y 3 40 3 mixture
26. (a) Sum invested by A, B and C is ` 2.75
5 × 12 : 7 × 12 : 6 × 6 + 3 × 6
or, 60 : 84 : 54 or, 10 : 14 : 9
9
[ Share of C = ´ 33, 000 <` 9, 000 2.75 – 2.50 = 0.25 3.30 – 2.75 = 0.75
33
27. (d) Let the salaries of Rajesh and Sunil be ` 2x and ` 3x 0.25 1
\ Required ratio = = i.e. 1: 3
respectively. 0.75 3
2x + 4000 40 S 1
Then, = = Þ F = 5S
3x + 4000 57 36. (d)
F 5
or, 114x + 228000 = 120x + 160000
or, 6x = 68000 M 4 4
or, 3x = ` 34000 = ÞM = F
F 5 5
100
28. (b) Number of females = 156800 × = 196000 S+2 3
80 =
M + 2 10
7
[ Number of males = × 196000 = 171500
8 4
[ Total population = 196000 + 171500 = 367500 Þ 10S + 20 = 30 M + 6 = 3 ´ ´5S+ 6 = 12S + 6
5
29. (c) Let number of ladies = x
then, number of gents = 2x [ 2 S = 14 Þ S = 7 years
x-2 1 [ F = 5S = 35 years
Now, = Þ 3x - 6 = 2x - 2 37. (c) Let the numbers be y and x respectively
2x - 2 3
Þx=4 4x y 4x
\ Total number of people originally present x + 50% of y = or, = –x
3 2 3
= 4 + 8 = 12
30. (d) Let A = 2x, B = 3x and C = 4x. Then, y x y 2
or, = or, =
A 2x 2 B 3x 3 C 4x 2 2 3 x 3
= = , = = and = =
B 3x 3 C 4x 4 A 2x 1 1 2 3
A B C 2 3 2 38. (d) Given the ratio = : : = 6 : 8 : 9.
Þ : : = : : = 8 : 9 : 24. 2 3 4
B C A 3 4 1
31. (d) Let the total number of hens and sheep be x and y æ 6ö
\ 1st part = ` ç 782 ´ ÷ = ` 204.
respectively. è 23 ø
i.e., x + y = 38 and 2x + 4y = 100 \ Ratio = 13 : 6 39. (c) Let number of ladies = x
32. (a) Let number of each type of coin = x. Then, and, number of gents = 2x
1 × x + .50 × x + .25 x = 35 x-2 1
Þ 1.75x = 35 Þ x = 20 coins Now, = Þ 3x - 6 = 2x - 2
33. (a) Initially A’s investment = 3x and B’s investment = 4x 2x - 2 3
Let B remain in the business for ‘n’ months. Þx=4
Þ 3x × 10 : 4x × n = 5 : 6 \ Total number of people originally present
\ 3x ×10 × 6 = 4x × n × 5 Þ n = 9 = 4 + 8 = 12
34. (b) By the rule of alligation, we have 40. (b) Let S denotes the shirts and T denotes the ties.
Gold Copper We have, 43S + 21T = 535
19 times 9 times By hit and trial, S = 10, T = 5
Þ 43 × 10 + 21 × 5 = 535
\ Ratio of shirts to ties = 10 : 5 = 2 : 1
15 times
41. (c) For 9 kg zinc, mixture melted = (9 + 11) kg.
For 28.8 kg zinc, mixture melted
15 – 9 =6 19 – 15 =4 æ 20 ö
= ç ´ 28.8 ÷ kg = 64 kg.
\ Required ratio = 6 = 3 : 2 è 9 ø
4
RATIO & PROPORTION, PARTNERSHIP & MIXTURE (ALLIGATIONSS1-111
)
42. (c) Let the three containers contain 3x, 4x and 5x litres of 44. (a) 3000 men taking 900 gms per head have provision for
mixtures, respectively. 25 – 11 = 14 days.
Less ratio per head, more men (Indirect Proportion)
æ 4ö 12x Less days, more men (Indirect Proportion)
Milk in 1st mix. = ç 3x ´ ÷ litres = litres.
è 5ø 5
Ratio 840 : 900 ü
ý :: 3000 : x
æ 12x ö 3x Days 10 : 14 þ
Water in 1st mix. = ç 3x - ÷ litres = litres.
è 5 ø 5 \ 840 × 10 × x = 900 × 14 × 3000
Þ x = 4500
æ 3ö \ strength of reinforcement =4500 – 3000=1500 men
Milk in 2nd mix. = ç 4x ´ ÷ litres = 3x litres.
è 4ø 45. (b) Let the required number of hours be x.
Speeds of working of first and second type of men are
Water in 2nd mix. = (4x – 3x) litres = x litres.
1 1
æ 5ö 25x and .
Milk in 3rd mix. = ç 5x ´ ÷ litres = litres. 2 3
è 7 ø 7
More work, More time (Direct Proportion)
Less speed, More time (Indirect Proportion)
æ 25x ö 10x
Water in 3rd mix. = ç 5x - ÷ litres = litres.
è 7 ø 7 Work 1: 2 ü
ï
Total milk in final mix. 1 1 ý : : 25 : x
Speed : ï
3 2þ
æ 12x 25x ö 314x
=ç + 3x + ÷ litres = litres.
è 5 7 ø 35 æ 1 ö æ 1 ö
\ ç 1´ ´ x ÷ = ç 2 ´ ´ 25 ÷ Þ x = 75.
è 3 ø è 2 ø
Total water in final mix.
46. (b) Let there be x men at the beginning.
æ 3x 10x ö 106x Less men, More days (Indirect Proportion)
= ç +x+ ÷ litres = litres.
è 5 7 ø 35 Men : x : x – 6
Required ratio of milk and water Days : 15 : 9
\15 : 9::x : (x - 6) Þ 15(x - 6) = 9x
314x 106x
= : = 157 : 53.
35 35 Þ 6x = 90 Þ x = 15.
43. (b) Let M denotes man and B denotes boy. 47. (b) If C puts in ` x, then B puts in ` x + 500 and A puts in
(x + 500) + 700 i.e. x + 1200
1 Þ (x + 1200) + (x + 500) + x = 4700
(M + B)'s 1 day's work =
40 Þ 3x + 1700 = 4700 Þ x = 1000
Ratio of their investment 2200 : 1500 : 1000 = 22 : 15 : 10
1 1 1
i.e. + = 15
M B 40 Thus, share of B = ´ 4230 = ` 1350
22 + 15 + 10
8 1 1 8 48. (a) Initially A’s investment = 3x and B’s investment = 4x
Ratio of their skill = i.e. = Let B remain in the business for ‘n’ months.
5 M B 5
Þ 3x × 10 : 4x × n = 5 : 6
Let efficiency of a man of 1 days work = x \ 3x ×10 × 6 = 4x × n × 5 Þ n = 9
Hence, B remained for 9 months in the business
1
i.e. =x 49. (a) Let B join after x months of the start of the business so
M
that B’s money is invested for (12–x) months.
\ Profit ratio is 12 × 12500 : (12 – x) × 37500
1 8 1 1 5x
Now, = ´ Þ = or 12 : 3(12 – x)
M 5 B B 8
Since profit is equally divided. therefore
12 = 3(12 – x) or x = 8. Thus B joined after 8 months.
13x 1 1 1 1
Now, = Þx= Þ M = 65 and =
8 5 65 B 104
EBD_7203
S1-112 GENERAL APTITUDE FOR GATE
50. (b) Ratio of rent amount = 27 × 19 : 21 × 17 : 24 × 23 53. (c) Total marks obtained
= 513 : 357 : 552 = (21 × 2) + (15 × 3) + (23 × 2) = 133
º 171 : 119 : 184 Total number of students = 21 + 17 + 6 = 44
184
\ Rent paid by C = ´ 23, 700 = ` 9, 200
474 male m
54. (c) In 2011, , =1
female f
3 3
æ 10 – 1 ö æ 9ö 729
51. (d) 10 ç ÷ = 10 ç ÷ = male m m '
è 10 ø è 10 ø 1000 In 2012, , , = 1.5
female f f
729 \ m = f and m' = 1.5f
\ ´ 1 = 7.29 litres
1000
m' 1.5
52. (a) \ =
m 1
6 Permutation and Combination &
Probability
PERMUTATION garland on the left is turned over we obtain the arrangement
Each of the arrangements, which can be made by taking, some or on the right, i.e., anticlockwise and clockwise order of
all of a number of things is called a PERMUTATION. arrangements are not different.
For Example : Formation of numbers, word formation, sitting Thus the number of circular permutations of ‘n’ different
arrangement in a row. things taken.
• The number of permutations of 'n' things taken 'r' at a time is
D C C D
n!
denoted by nPr. It is defind as, nP
r = .
(n - r)!
E B B E
• nP = n!
n
A A
Circular permutations:
1
(i) Arrangements round a circular table : all at a time is (n – 1)!, if clockwise and anticlockwise
Consider five persons A, B, C, D and E to be seated on the 2
circumference of a circular table in order (which has no head). orders are taken to be same.
Now, shifting A, B, C, D and E one position in anticlockwise
Conditional Permutations
direction we will get arrangements as follows:
1. Number of permutations of n things taking r at a time, in
-
E D C which a particular thing always occurs = r . n 1Pr -1 .
A D E C D B Distinguishable Permutations
Suppose a set of n objects has n 1 of one kind of object, n2 of
a second kind, n 3 of a third kind, and so on, with n = n 1 + n2
B C A B E A
+ n3 + . . . + nk, Then the number of distinguishable permuta-
(i) (ii) (iii) n!
tions of the n objects is
n1 ! n 2 ! n 3 !..... n k !
Þ P(A) + P(A) = 1
PERMUTATION AND COMBINATION & PROBABILITY S1-115
• The ODDS IN FAVOUR of occurrence of A are given by 3. If A and B are two mutually exclusive events and the
probability of their occurence are P(A) and P(B) respectively,
m : (n – m) or P(A) : P (A )
then probability of either A or B occuring is given by
• The ODDS AGAINST the occurrence of A are given by P(A or B) = P(A) + P(B)
(n – m) : m or P (A ) : P (A). Þ P(A + B) = P(A) + P(B)
• Let A and B be two events related to a random experiment. Independence
We define An event B is said to be independent of an event A if the probability
(i) The event “A or B” denoted by “A È B”, which occurs that B occurs is not influenced by whether A has or has not
when A or B or both occur. Thus, occurred. For two independent events A and B.
P(A È B) = Probability that at least one of the events P(A Ç B) = P(A) P(B)
occur
Conditional Probability
(ii) The event “A and B”, denoted by " A Ç B" , which
Let A and B be two events associated with a random experiment.
occurs when A and B both occur. Thus,
P(A Ç B) = Probability of simultaneous occurrence of æAö
Then Pç ÷ , represents the conditional probability of occurrence
A and B. èBø
EXERCISE
1. A bag has 4 red and 5 black balls. A second bag has 3 red 8. In a hockey championship there were 153 matches played.
and 7 black balls. One ball is drawn from the first bag and Every two teams played one match with each other. The
two from the second. The probability that there are two number of teams participating in the championship is :
black balls and a red ball is : (a) 18 (b) 19
14 11 (c) 17 (d) 16
(a) (b)
45 45
1
9. The probability that a student is not a swimmer is . Then
7 9 5
(c) (d)
15 54 the probability that out of the five students, four are
2. If two dices are tossed simultaneously, the number of swimmers is :
elements in the resulting sample space is :
2 4
(a) 6 (b) 8 5C æ 4 ö æ 1 ö æ 4ö æ1ö
(a) 4ç ÷ ç ÷ (b) ç ÷ ç ÷
(c) 36 (d) 24 è 5ø è5ø è 5ø è5ø
3. The probability of raining on day 1 is 0.2 and on day 2 is 0.3.
What is the probability of raining on both the days ? 5C æ 1 öæ 4 ö
4
1 2 23. India plays two matches each with West Indies and
(a) (b) Australia. In any match the probabilities of India getting
5 5
points 0, 1 and 2 are 0.45, 0.05 and 0.50 respectively.
1 2 Assuming that the outcomes are independent, the
(c) (d)
3 3 probability of India getting at least 7 points is
15. In how many different ways can the letters of the word (a) 0.0624 (b) 0.8875
‘MATHEMATICS’ be arranged so that the vowels always (c) 0.8750 (d) 0.0250
come together ? 24. A committee consists of 9 experts taken from three
(a) 10080 (b) 4989600 institutions A, B and C, of which 2 are from A, 3 from B and
(c) 120960 (d) None of these 4 from C. If three experts resign, then the probability that
16. A man and his wife appear in an interview for two vacancies they belong to different institutions is:
for the same post. The probability of the husband’s selection
1 1
is 1/7 and the probability of the wife’s selection is 1/5. What (a) (b)
is the probability that only one of them is selected ? 729 24
4 2 1 2
(a) (b) (c) (d)
5 7 21 7
25. There are three events A, B and C, out of which one and
8 4 only one can happen. The odds are 8 to 3 against A, 5 to 2
(c) (d)
15 7 against B. Find the odds against C :
17. A cricket club has 15 members, of whom only 5 can bowl. If (a) 43 : 34 (b) 43 : 77
the names of the 15 members are put into a box and 11 drawn (c) 34 : 43 (d) 77 : 43
at random, then the chance of obtaining an eleven containing 26. Three persons work independently on a problem. If the
at least 3 bowlers is respective probabilities that they will solve it are 1/3, 1/4
(a) 7/13 (b) 6/13 and 1/5, then the probability that none can solve it is :
(c) 11/15 (d) 12/13 (a) 1/5 (b) 1/3
18. The number of ways in which 6 men and 5 women can dine (c) 2/5 (d) None of these
at a round table if no two women are to sit together is given 27. A Chartered Accountant applies for a job in two firms X and
by Y. The ability of his being selected in firm X is 0.7, and being
(a) 6 ! × 5 ! (b) 5 ! × 4 ! rejected at Y is 0.5 and the probability of at least one of his
(c) 30 (d) 7 ! × 5 ! applications being rejected is 0.6. What is the probability
19. Out of 13 applicants for a job, there are 5 women and 8 men. that he will be selected in one of the firms?
It is desired to select 2 persons for the job. The probability (a) 0.8 (b) 0.2
that atleast one of the selected persons will be a woman is (c) 0.4 (d) 0.7
(a) 25/39 (b) 5/13 28. Out of 20 consecutive positive integers, two are chosen at
(c) 14/39 (d) 10/3 random. The probability that their sum is odd is
20. Four boys and three girls stand in queue for an interview. (a) 19/20 (b) 10/19
The probability that they will stand in alternate positions is: (c) 1/20 (d) 9/19
(a) 1/34 (b) 1/35 29. Three dice are rolled. The number of possible outcomes in
(c) 1/17 (d) 1/68 which at least one dice shows 5 is
21. There are 100 students in a college class of which 36 are (a) 215 (b) 36
boys studying statistics and 13 girls not studying statistics. (c) 125 (d) 91
If there are 55 girls in all, then the probability that a boy 30. The number of ways in which one or more balls can be
picked up at random is not studying statistics, is selected out of 10 white, 9 green and 7 blue balls is
(a) 3/5 (b) 2/5 (a) 892 (b) 881
(c) 1/5 (d) None of these (c) 891 (d) 879
22. A box contains 5 brown and 4 white socks. A man takes out
Directions (Qs. 31-32): Answer these questions on the basis
two socks. The probability that they are of the same colour
of the information given below:
is
From a group of 6 men and 4 women a committee of 4 persons
5 1 is to be formed.
(a) (b)
18 6 31. In how many different ways can it be done so that the
committee has at least one woman?
5 4
(c) (d) (a) 210 (b) 225
108 9 (c) 195 (d) 185
EBD_7203
S1-118 GENERAL APTITUDE FOR GATE
32. In how many different ways can it be done so that the 40. Two dice are thrown. The probability that the sum of the
committee has at least 2 men? numbers coming up on them is 9, if it is known that the
(a) 210 (b) 225 number 5 always occurs on the first die, is
(c) 195 (d) 185
1 1
33. A bag contains 2 red, 3 green and 2 blue balls. 2 balls are (a) (b)
6 3
to be drawn randomly. What is the probability that the
balls drawn contain no blue ball? 2 1
(c) (d)
3 2
5 10
(a) (b) 41. A speaks the truth in 70 percent cases and B in 80 percent.
7 21
The probability that they will contradict eact. other when
2 11 describing a single event is
(c) (d) (a) 0.36 (b) 0.38
7 21
34. In a box there are 8 red, 7 blue and 6 green balls. One ball (c) 0.4 (d) 0.42
is picked up randomly. What is the probability that it is 1+ 4p 1- p 1- 2p
neither red nor green? 42. If , and are the probabilities of three
4 2 2
7 2 mutually exclusive events, then value of p is
(a) (b) 1 1
19 3
(a) (b)
2 3
3
(c) (d) none of these 1 2
4 (c) (d)
4 3
35. The probability that the 13th day of a randomly chosen month
43. A student appears for tests I, II and III. The student is
is a Friday, is
successful if he passes either in tests I and II or tests I and
1 1 III. The probabilities of the student passing in tests I, II, II
(a) (b)
12 7 1
are p, q and respectively. The probability that the student
2
1 1 1
(c) (d) is successful is then the relation between p and q is
84 13 2
36. If a leap year selected at random, the chance that it will given by
contain 53 Sunday is (a) pq + p = 1 (b) p2 + q = 1
(c) pq – 1 = p (d) none of these.
3 1 44. Let A, B, C be three events such that P (A) = 0.3 P(B) = 0.4,
(a) (b)
7 7 P(C) = 0.8, P(A Ç B) = 0.08, P(A Ç C) = 0.28, P(A Ç B Ç C)
= 0.09. If P(A È B È C) ³ 0.75, then
2 4
(c) (d) (a) 0.23 £ P(B Ç C) £ 0.48
7 7
37. If A and B are two independent events with P(A) = 0.6, P(B) (b) 0.23 £ P(B Ç C) £ 0.75
= 0.3, then P(A 'ÇB' ) is equal to : (c) 0.48 £ P(B Ç C) £ 0.75
(a) 0.18 (b) 0.28 (d) none of these.
(c) 0.82 (d) 0.72 45. If A and B are two independent events and
38. The probability that at least one of the events A and B P(C) = 0, then A, B, C are :
occurs is 0.7 and they occur simultaneously with probability (a) independent
(b) dependent
0.2. Then P(A) + P( B) = (c) not pairwise independent
(a) 1.8 (b) 0.6 (d) none of the above.
(c) 1.1 (d) 0.4 46. If two dice are tossed, find the probability of throwing a
39. If the probability that A and B will die within a year are p and total of ten or more.
q respectively, then the probability that only one of them 1 1
will be alive at the end of the year is (a) (b)
2 6
(a) p + q (b) p + q – 2pq
(c) p + q – pq (d) p + q + pq. 1 1
(c) (d)
4 5
PERMUTATION AND COMBINATION & PROBABILITY S1-119
47. A bag contain 5 white, 7 red and 8 black balls. If 4 balls are
drawn one by one with replacement, what is th probability
kilograms)
600
Toxicity
Q (40 mm)
4 4 400
(c) (d) S (20 mm)
20 8 R (30 mm)
200
48. A coin is tossed 5 times. What is the probability that head
appears an odd number of times? 0
0.2 0.4 0.6 0.8 1
2 1 Potency
(a) (b) (Probability that microbe will overcome human
5 5 immunity system)
1 4
(c) (d)
2 25 A pharmaceutical company is contemplating the
development of a vaccine against the most dangerous
3 1
49. A and B are events such that P(A È B) = , P(A Ç B) = , microbe. Which microbe should the company target in its
4 4
2 first attempt?
P( A ) = then P ( A Ç B) is (a) P (b) Q [GATE 2011, 2 Marks]
3
(c) R (d) S
5 3 53. An automobile plant contracted to buy shock absorbers
(a) (b)
12 8 from two suppliers X and Y. X supplies 60% and Y supplies
40% of the shock absorbers. All shock absorbers are
5 1 subjected to a quality test. The ones that pass the quality
(c) (d)
8 4 test are considered reliable. Of X’s shock absorbers, 96%
are reliable. Of Y’s shock absorbers, 72% are reliable.
50. Seven white balls and three black balls are randomly placed
The probability that a randomly chosen shock absorber,
in a row. The probability that no two black balls are placed
which is found to be reliable, is made by Y is
adjacently equals
[GATE 2012, 2 Marks]
1 7 (a) 0.288 (b) 0.334
(a) (b) (c) 0.667 (d) 0.720
2 15
54. The number of people diagnosed with dengue fever
2 1 (contracted from the bite of a mosquito) in north India is
(c) (d) twice the number diagnosed last year. Municipal authorities
15 3
have concluded that measures to control the mosquito
51. Given digits 2, 2, 3, 3, 3, 4, 4, 4, 4 how many distinct 4 digit population have failed in this region.
numbers greater than 3000 can be formed? Which one of the following statements, if true, does not
(a) 50 (c) 51 [GATE 2010, 2 Marks] contradict this conclusion? [GATE 2014, Set-2, 2 Marks]
(c) 52 (d) 54 (a) A high proportion of the affected population has
52. P, Q, R and S are four types of dangerous microbes recently returned from neighbouring countries where dengue
found in a human habitat. The area of each circle with its is prevalent
diameter printed in brackets represents the growth of a single (b) More cases of dengue are now reported because of
microbe surviving human immunity system within 24 hours an increase in the Municipal Office’s administrative
of entering the body. The danger to human beings varies efficiency
proportionately with the toxicity, potency and growth (c) Many more cases of dengue are being diagnosed this
attributed to a microbe shown in the figure below: year since the introduction of a new and effective
diagnostic test
(d) The number of people with malarial fever (also
contracted from mosquito bites) has increased this
year
EBD_7203
S1-120 GENERAL APTITUDE FOR GATE
M5 2 ´3´ 4 2
M3 ==
9! 7
W2 6!3!
W3
25. (a) Let A, B, C be three events.
M4 Given: Odd are 8: 3 against A
19. (a) Total no. of ways of choosing two persons from 13
= 13C2 = 78. 3 3
\ P(A) = =
No. of ways in which atleast one woman is selected 8 + 3 11
= One woman and one man are selected 2 2
+ 2 women are selected Similarly, P(B) = =
5+2 7
= 5C1 × 8C1 + 5C2 = 40 + 10 = 50.
Also we know, P(A) + P(B) + P(C) = 1
50 25 Þ 1 – (P(A) + P(B)) = P(C)
\ Required probability = =
78 39
EBD_7203
S1-122 GENERAL APTITUDE FOR GATE
We can odd sum only when one even and one odd is
é 3 2ù é 21 + 22 ù 77 – 43 34 added.
Þ P(C) = 1 – ê + ú = 1 – ê ú = 77 = 77
ë 11 7 û ë 77 û \ No. of ways of choosing 1 even and 1 odd
\ Odds against C = 43: 34 Out of 10 even and 10 odd = 10C1 × 10 C1
26. (c) Given : 3 persons say, A, B and C solves a problem = 10 × 10 = 100
independently. 100 10
\ Required probability = =
1 190 19
Also Given: P (A solves problem) =
3 29. (d) Required number of possible outcomes
= Total number of possible outcomes –
1
P(B solves the problem) = Number of possible outcomes in which 5 does
4 not appear on any dice. (hence 5 possibilities in each
1 throw)
and P(C solves the problem) = = 63 – 53 = 216 – 125 = 91
5
30. (d) The required number of ways
2 = (10 + 1)(9 + 1)(7 + 1) - 1 = 879 .
\ P(A does not solve the problem) = ,
3 31. (c) Reqd. no. of ways
3
P(B does not solve the problem) = = 4 C1× 6C3 + 4 C2 × 6 C2 + 4 C3 ´ 6 C1 + 4 C4
4
6 × 5× 4 4× 3 6× 5 4× 3× 2
4 = 4× + × + × 6 +1
P(C does not solve the problem) = 1×2 × 3 1× 2 1 × 2 1× 2 × 3
5
= 80 + 90 + 24 + 1=195
2 3 4 2 32. (d) Reqd. no. of ways
Now, P (none can solve the problem) = ´ ´ =
3 4 5 5 6
= C2 × 4 C2 + 6 C3 × 4 C1 + 6 C4
7
27. (a) Given P (selection in firm X) = 6×5 4×3 6×5× 4 6×5× 4 ×3
10
= 1× 2 × 1×2 + 1×2×3 × 4 + 1×2×3×4
3
\ P (rejection in firm X) = º P (X) = 90 + 80 + 15 = 185.
10
5
C2 5 ´ 4 10
5 33. (b) Reqd probability = 7 = =
Similarly, P (selection in firm Y) = and C2 7 ´ 6 21
10
34. (d) If the drawn ball is neither red nor green, then it must
5
P (rejection in firm Y) = º P(Y) be blue, which can be picked in 7C1 = 7 ways. One
10 ball can be picked from the total (8 + 7 + 6 = 21) in
21C = 21 ways.
6 1
Also, given that P (at least one rejection) =
10 \ Reqd probability = 7 = 1
6 21 3
i.e, P (X È Y ) =
10 1
35. (c) Probability of selecting a month = .
To find : 1 - P ( X Ç Y )
12
13th day of the month is friday if its first day is sunday
As we know, P ( X È Y ) = P(X) + P(Y) - P(X Ç Y)
1
and the probability of this = .
6 3 5 7
Þ = + - P(X Ç Y)
10 10 10 1 1 1
\ Required probability = . = .
2 12 7 84
Þ P(X Ç Y) =
10 36. (c) A leap-year has 366 days i.e. 52 complete weeks and
two days more these two days be two consecutive
2 8 days of a week. A leap year will have 53 Sundays if out
\ Required Prob = 1 - = = 0.8
10 10 of the two consecutive days of a week selected at
28. (b) Out of 20 consecutive numbers there are 10 even and random one is a Sunday.
10 odd Let S be the sample space and E be the event that out
We have to choose 2 numbers out of 20 of the two consecutive days of a week one is Sunday,
then
20 20 ´ 9
\ Total outcomes = C2 = = 190 S = {(Sunday, Monday), (Monday, Tuesday),
2
PERMUTATION AND COMBINATION & PROBABILITY S1-123
(Tuesday, Wednesday), (Wednesday, Thursday), because A and B are independent. Therefore, putting
(Thursday, Friday), (Friday, Saturday), (Saturday, P(A) = 0.7 and P(B) = 0.8 the required probability is
Sunday)} (0.7) (0.2) + (0.3) (0.8) = 0.38.
\ n (S) = 7
1 + 4p 1 - p 1 - 2p
and E = {(Sunday, Monday), (Saturday, Sunday) 42. (a) , , are probabilities of the three
\ n (E) = 2 4 2 2
mutually exclusive events, then
n ( E) 2
Now, required Probability, P(E) =
n(S)
= 1 + 4p 1- p 1 - 2p
7 0£ £ 1, 0 £ £ 1, 0 £ £1
4 2 2
37. (b) Since, A and B are independent events \ A’ and B’ are
also independent events 1 + 4 p 1 - p 1 - 2p
and 0 £ + + £1
Þ P(A 'ÇB' ) = P(A ' ).P(B' ) 4 2 2
= (0.4)(0.7) = 0.28 1 3 1 1 1 5
\- £ p £ , - 1 £ p £ 1, - £ p , £ p £
[QP(A' ) = 1 - P(A), P(B' ) = 1 - P(B)] 4 4 2 2 2 2
1 Mathematical Logic
MATHEMATICAL LOGIC NOT (ù )
Logic is concerned with all types of reasoning such as valid P ùP
statements, mathematical proofs, valid conclusions etc. Logical T F
reasoning is used to prove theorems, to verify the correctness of
F T
computer programs and to draw conclusions from experiments.
AND (Ù)
Propositional Logic
Propositional logic is a logic at the sentential level. The smallest P Q PÙQ
unit we deal within propositional logic is a sentence. F F F
“Sentences considered in propositional logic are not arbitrary F T F
sentences but are the ones that are either true or false, but not T F F
both. This kind of sentences are called propositions.” T T T
If a proposition is true, then we say, it has a truth value of true, if
a proposition is false its truth value is false’. We shall use the IMPLIES (®)
letters p, q, r,... to represent arbitrary statements.
P Q P ®Q
Elements of propositional Logic F F T
Larger and more complex sentences are constructed from basic F T T
propositions by combining them with connectives. There are five T F F
basic connectives T T T
NOT ù
AND Ù IF AND ONLY IF (P « Q)
OR Ú
P Q P «Q
IF ...THEN ® or Þ
IF AND ONLY IF « or Þ F F T
F T F
Propositions Variable and Function
T F F
A symbol which represents an arbitrary proposition. Thus,
T T T
propositional variable is a variable that can be replaced by a
statement and denoted by p, q, r... or P1, P2, ...
Converse and Contrapositive
Propositional function is a function or statement which is formed
For the proposition
by using propositional variables and connectives.
(i) P ® Q, the Q ® P is called its converse.
Truth Table (ii) Ø Q ® Ø P is called its contrapositive.
F represents false and T true. The contrapositive of a proposition is always logically equivalent
OR (Ú) to the proposition.
Tautologies and Contradictions
P Q PÚQ ‘A statement (or propositional function) which is true all possible
F F F truth values of its propositional variables is called a tautology.’
F T T A statement which is always false all possible truth values of its
propositional variables is called a contradiction.
T F T
A proposition that is neither tautology nor a contradiction is
T T T called contingency.
(P Ú Q) is a contingency.
EBD_7203
S2-2 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Reasoning which can be proved by truth tables :
Logical reasoning is the process of drawing conclusion from 1. p Ù q Þ p pÞpÚq
premises using rules of inference. 2. ~ p Þ p ® q qÞp®q
3. ~ (p ® q) Þ p ~ (p ® q) Þ ~ q
List of Identities
4. P Ù (P ® q) Þ q ~ p Ù (p Ú q) Þ q
1. P Û (P Ú P) 5. (p ® q) Ù (q ® r) Þ p ® r
idempotence of Ú
2. P Û (P Ù P) Implications
idempotence of Ù The relationship between propositions that can be derived from
3. (P Ú Q) Û (Q Ú P) the definitions of connectives.
commutativity of Ú List of implication
4. (P Ù Q) Û (Q Ù P) 1. P Þ (P Ú Q) addition
commutativity of Ù 2. (P Ù Q) Þ P simplification
5. [(P Ú Q) Ú R] Û [ P Ú (Q Ú R)] 3. [P Ù (P ® Q)] Þ Q modus ponens
associativity of Ú 4. [(P ® Q) Ù Ø Q] Þ Ø P modus tollens
6. [(P Ù Q) Ù R] Û [ P Ù (Q Ù R)] 5. [Ø P Ù (P Ú Q)] Þ Q disjunctive syllogism
associativity of Ù 6. [(P ® Q) Ù (Q ® R)] Þ (P ® R) hypothetical syllogism
7. Ø (P Ù Q) Û [Ø P Ú Ø Q] 7. (P ® Q) Þ [(Q ® R) ® (P ® R)]
De-Morgan’s law 8. (P ® Q) Ù [(R ® S) Þ [(P Ù R) ® (Q Ù S)]
8. Ø (P Ú Q) Û [Ø P Ù Ø Q] 9. [(P « Q) Ù (Q « R) Þ [(P « R)
De-Morgan’s law Reasoning with Propositions
9. [P Ù (Q Ú R] Û [( P Ù Q) Ú (P Ù R)]
Logical reasoning is the process of drawing conclusions from
distributivity of Ù over Ú
premises using rules of inference. The basic inference rule is
10. [P Ú (Q Ù R] Û [( P Ú Q) Ù (P Ú R)]
modus ponens. It states that if both P ® Q and P hold, then Q
distributivity of Ú over Ù
can be concluded and it is written as
11. (P Ú True) Û True
12. (P Ù False) Û False P
13. (P Ú False) Û P P® Q
14. (P Ù True) Û P ............
15. (P Ú Ø P) Û True Q
16. (P Ù Ø P) Û False Here, the lines above the dotted line are premises.
17. P Û Ø (Ø P)
double negation Predicate Logic
18. (P ® Q) Û (Ø P Ú Q) A predicate is a verb phrase template that describes a property of
implication objects or relationship among objects represented by the
19. (P « Q) Û (P ® Q) Ù (Q ® P) variables.
equivalence Arguments
20. [(P Ù Q) ® R] Û [P ® (Q ® R)] (1) An argument is an assertion that a given set of propositions
exportation p1, p2, ... pn (called premises) yields another proposition q
21. [(P ® Q) Ù [P ® Ø Q) Û Ø P (called conclusion). The argument is symbolically written
absurdity as “p1, p2, ..., pn q”
^
contrapositive whenever all the premises p1, p2, ... pn are true. An argument
(1) Two formulae A and A* are said to be duals of each other if which is true is said to be ‘valid argument’. Otherwise it is
either one can be obtained from the other by replacing Ù by called a fallacy.
Ú and Ú by Ù. (2) Theorem : The argument p1, p2, ..., pn q is valid if and
^
If the formula A contains special variables 1 or 0, then its only if the proposition (p1 Ù p2 Ù p3 Ù ..., Ù pn) ® q is a
dual A* is obtained by replacing 1 by 0 and 0 by 1. tautology.
e.g., (i) Dual of (p Ú q) Ù r is (p Ù q) Ú r The proportions p1, p2, ..., pn are simultaneously true if and
(ii) Dual of (p Ù q) Ú 0 is (p Ú q) Ù 1. only if the proposition p1 Ù p2 Ù ..., Ù pn is true i.e., , if the
(2) Tautology implications : A statement A is said to proposition (p1 Ù p2 Ù ..., Ù pn) ® q is a tautology.
tautologically imply a statement B if and only if A ® B is a Obs. The validity of an argument depends upon the
tautology which is read as “A implies B”. particular form of the argument, not on the truth values of
The implications listed below have important applications the statement appearing in the argument.
MATHEMATICAL LOGIC S2-3
QUA NTIFI ERS The notation $ xP(x) is used for the existential quantification
(1) In a propositional function, when all the variables are where $ is called the existential quantifier.
assigned values, the resulting statement has a truth value. Obs. When it is possible to list all the elements in the
However, there is another method to create a proposition universe say : x1, x2, ..., xn, then the existential quantification
from a propositional function which is called quantification. $x P(x) is same as the disjunction P(x1) Ú P(x2) Ú ..., P(xn).
It is of two types : Universal quantification and Existential Sample Problem
quantification. What is the truth value of the quantification $xp(x) where.
(2) Universal Quantification : Many statements assert that a (a) P(x) is the statement ‘x > 5’ and universe of discourse
property is true for all values of a variable in a certain domain. is the set of real numbers.
This domain is termed as the universe of discourse and (b) P(x) is the statement ‘x2 > 18’ and the universe of discourse
such a statement is expressed using universal quantification. consists of positive integers not exceeding 5?
Thus the universal quantification of P(x) is the proposition Sol. (a) Since ‘x > 5’ is true, say : for x = 6, etc.
‘P(x) is true for all values of x in the universe of discourse’ \ $xP(x) is true.
The universal quantification of P(x) is denoted by " xP(x). (b) The statement $xP(x) is same as the disjunciton P(1) Ú
The symbol " is called the universal quantifier.. P(2) Ú P(3) Ú P(4) Ú P(5)
Sample Problem The universe of discourse is 1, 2, 3, 4, 5 and P(5) is the
What is the truth value of the quantification " x P(x) where statement 52 > 18, which is true.
(a) P(x) is the statement ‘x < 5’ and universe of discourse Hence $ xP(x) is also true.
is the set of real numbers. Well-formed Formula for First Order Predicate
(b) P(x) is the statement ‘x2 < 18’ and the universe of Logic
discourse consists of positive integers not exceeding Not all strings can represent propositions of the predicate logic.
5? Those which produce a proposition when their symbols are
Sol. (a) For instance, P(6) is false ; therefore P(x) is not true for all interpreted must follow the rules given below, and they are called
real numbers x. Thus " xP(x) is false. Wffs (well formed formulas) of the first order predicate logic.
(b) The statement " xP(x) is same as the conjunction P(1)
Ù P(2) Ù P(3) Ù P(4) Ù P(5) Rules for constructing Wffs : A predicate name followed by a list
Here the universe of discourse is 1, 2, 3, 4, 5 and P(5) is the of variables such as P(x, y), where P is a predicate name and x and
statement ‘52 < 18’ which is false. Hence " xP(x) is also y are variables, is called an atomic formula.
false. 1. True and False are Wffs.
(3) Existential Quantification : Many statements assert that 2. Each propositional constant (i.e. specific proposition) and
there is an element with a certain property. To express such each propositional variable (i.e. a variable representing
statements we use existential quantification. In such cases, propositions) are Wffs.
we form a proposition which is true if and only if P(x) is true 3. Each atomic formula (i.e., a specific predicates with variables)
for at least one value of x in the universe of discourse. is a Wff.
Thus the existential quantification of P(x) is the proposition 4. If A, B and C are Wffs, then so are Ø A, (A Ù B), (A Ú B),
‘these exists an element x in the universe of discourse such (A ® B) and (A « B).
that P(x) is true. 5. If x is a variable (representing objects of the universe of
discourse) and A is Wff, then so are, " xA and $ x A.
EBD_7203
S2-4 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. What is the first order predicate calculus statement 6. P and Q two propositions. Which of the following logical
equivalent to the following? [2005, 1 Mark] expressions are equivalent? [2008, 1 Mark]
Every teacher is liked by some student. 1. P Ú ~ Q
(a) " (x) [teacher (x) ® $ (y) {student (y) ® likes (y, x)}] 2. ~ (~ P Ù Q)
(b) " (x) [teacher (x) ® $ (y) {student (y) Ù likes (y, x)}] 3. (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù ~ Q)
4. (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù Q)
(c) $ (y), " (x) [teacher (x) ® {student (y) Ù likes (y, x)}]
(a) 1 and 2 (b) 1, 2 and 3
(d) " (x) [teacher (x) ® $ (y) {student (y) ® likes (y, x)}]
(c) 1, 2 and 4 (d) All of 1, 2, 3 and 4
2. Let P, Q and R be three atomic propositional assertions. Let
7. Let isa and pda be two predicates such that fsa(x) means x is
X denotes (P Ú Q) ® R and Y denotes (P ® R) Ú (Q ® R).
a finite state automation and pda(y), means y is a push
Which one of he following is a tautology? [2005, 1 Mark]
down automation. Let equivalent be another predicate such
(a) X º Y (b) X ® Y
that equivalent (a, b) means a and b are equivalents. Which
(c) Y ® l (d) Ø Y ® x
of the following first order logic statements represents the
3. Consider the following propositional statements
following: [2008, 1 Mark]
[2006, 1 Mark]
(a) (" x fsa (x)) Þ ($ y pda(y) Ù equivalent (x, y))
P1 : ((A Ù B) ® C) º ((A ® C) Ù (B ® C))
(b) ~ " y ($ x fsa (x) Þ ($ y pda(y) Ù equivalent (x, y))
P2 : ((A Ú B) ® C) º ((A ® C) Ú (B ® C))
(c) "x $ y (fsa(x) Ù pda (y) Ù equivalent (x, y))
Which one of the following is true?
(d) "x $ y (fsa(x) Ù pda (x) Ù equivalent (x, y))
(a) P1 is a tautology, but not P2
8. The binary operation is defined as follows
(b) P2 is a tautology, but not P1
(c) P1 and P2 are both tautologies
(d) Both P1 and P2 are not tautologies P Q PQ
4. Which one of the first order predicate calculus statements True True True
given below, correctly expresses the following english True False True
statement? [2007, 1 Mark] False True False
Tiger and lions attack, if they are hungry or threatened. False False True
(a) " × [(tiger (×) Ù lion (×)) ® {(hungry (×) Ú threatened
(×)) ® attacks (×)}] Which one of the following is equivalent to P Ú Q?
(b) " × [(tiger (×) Ú lion (×)) ® {(hungry (×) Ú threatened [2009, 1 Mark]
(×)) ® attacks (×)}] (a) Ø Q Ø P (b) P Ø Q
(c) " × [(tiger (×) Ú lion (×)) ® {(attacks (×) Ú hungry (×)) (c) Ø P Q (d) Ø P Ø Q
Ú threatened (×))}] 9. Which one of the following is the most appropriate logical
(d) " × [(tiger (×) Ú lion (×)) ® {(hungry (×) Ú threatened formula to represent the statement [2009, 1 Mark]
(×)) ® attacks (×)}] ‘Gold and silver ornaments are precious’?
5. Let graph (x) be a predicate which denoted that x is a graph. The following notations are used
Let graph (x) is connected. Which of the following first G(x) : x is a gold ornament
order logic sentences does not represent the statement ‘Not S(x) : x is a silver ornament
every graph is connected’? [2008, 1 Mark] P(x) : x is precious
(a) Ø " x (graph (x) Þ connected (x)) (a) " x (P(x)) ® (G(x) Ù S(x))
(b) $ x (graph (x) Ù Ø connected (x)) (b) " x (G(x)) Ù S(x) ® P(x))
(c) Ø " (Ø graph (x)) Ú (connected (x)) (c) $ x ((G(x) Ù S(x)) ® P(x))
(d) " x (graph (x)) Þ Ø connected (x)) (d) " x (G(x) ® S(x)) ® P(x)
MATHEMATICAL LOGIC S2-5
10. Consider the following logical inferences : (c) $x : gold ( x ) Ù Øglitters( x )
I1: If it rains, then the cricket match will not be played. (d) $x : glitters( x ) Ù Øgold ( x )
The cricket match was played. [2012, 1 Mark] 13. Suppose you break a stick of unit length at a point chosen
Inference There was no rain. uniformly at random. Then the expected length of the shorter
I2 : If it rains, then the cricket match will not be played. stick is ______ . [2014, Set-1, 1 Mark]
14.. Which one of the following propositional logic formulas is
It did not rain.
TRUE when exactly two of p, q, and r are TRUE?
Inference The cricket match was played. [2014, Set-1, 2 Marks]
Which of the following is true? (a) ((p « q) Ù r) Ú (p Ù q Ù ~ r)
(a) Both I1 and I2 are correct inferences (b) (~(p « q) Ù r) Ú (p Ù q Ù ~ r)
(c) ((p « q) Ù r) Ú (p Ù q Ù ~ r)
(b) I1 is correct but I2 is not a correct inferences (d) (~(p « q) Ù r) Ù (p Ù q Ù ~ r)
(c) I1 is not correct but I2 is a correct inference 15. Consider the following statements:
(d) Both I1 and I2 are not correct inferences P: Good mobile phones are not cheap
Q: Cheap mobile phones are not good
11. What is the correct translation of the following statement
L: P implies Q
into mathematical logic? [2012, 1 Mark]
M: Q implies P
“Some real numbers are rational”? N: P is equivalent to Q
(a) $ x (real) (x) v rational (x)) Which one of the following about L, M, and N is
(b) " x (real) (x) ® rational (x)) CORRECT? [2014, Set-3, 1 Mark]
(a) Only L is TRUE.
(c) $x (real) (x) Ù rational (x))
(b) Only M is TRUE.
(d) $ x (rational (x) ® real (x)) (c) Only N is TRUE.
12. Consider the statement (d) L, M and N are TRUE.
“Not all that glitters is gold” 16. The CORRECT formula for the sentence, “not all rainy days
Predicate glitters (x) is true if x glitters and predicate gold are cold” is [2014, Set-3, 2 Marks]
(x) is true if x is gold. Which one of the following logical (a) " d (Rainy(d) Ù ~ Cold(d))
formulae represents the above statement? (b) " d (~Rainy(d) ® Cold(d))
[2014, Set-1, 1 Mark] (c) $ d (~Rainy(d) ® Cold(d))
(a) "x : glitters( x ) Þ Øgold ( x ) (d) $ d (Rainy(d) Ù ~ Cold(d))
PAST GATE QUESTIONS EXERCISE 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
1. (b) Every teacher is liked by some students, then the
threatened) it will attack.’
logical expression is " (x) [teacher (x) ® $ (y)
Therefore, correct option is (d).
{student (y) Ù likes y(x)}]
5. (b) The statement ‘Not every graph is connected’ is same
where, likes (y, x) mean y likes x, such that y represents
as ‘There exists some graph which is not connected'
the student and x represents the teacher.
which is same as $ x {graph (x) Ù Ø connected (x)}.
2. (b) X : (P Ú Q) ® R
6. (b) (i) P Ù ~ Q º P + Q'
Y : (P ® R) Ú (Q ® R)
(ii) ~ (~ P Ù Q) (P' + Q)' º P + Q'
X : P + Q ® R º (P + Q)' + R º P'Q' + R
(iii) (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù ~ Q)
Y : (P' + R) + (Q' + R) º P' + Q' + R
= (PQ) + (PQ' ) + (P'Q')
Clearly, X¹Y
= P(Q + Q') + P'Q'
Consider X ®Y
= P + P'Q'
º (P'Q' + R ) ® (P' + Q' + R)
= (P + P') (P + Q')
º (P'Q' + R)' + P' + Q' + R
= P + Q'
º (P'Q')' R' + P' + Q' + R
(iv) (P Ù Q) Ú (P Ù ~ Q) Ú (~ P Ù Q)
º (P + Q) R' + P' + Q' + R (Q by distribution law)
= (PQ) + (PQ' ) + (P'Q)
º PR' + QR' + P' + Q' + R
= P(Q + Q') + P'Q
º (PR' + R) + (QR' + Q') + P'
= P + P'Q
º (P + R)(R' + R) + (Q + Q') × (R' + Q') + P'
= (P + P') (P + Q)
º P + P' + R + R' + Q’ (by complente law)
= P+Q
º 1 + 1 + Q' = 1
Clearly, (i), (ii), (iii) are equivalent. Correct choice is (b).
\ x ® y tautology.
7. (a) For x, the predicate fsa there exists y and the
3. (d) P1 : ((A Ù B) ® C) º ((A ® C) Ù (B ® C)) corresponding predicate pda which is equivalent to x.
LHS (A Ù B ) ® C º AB ® C \ (A x fsa (x))
= (AB)' + C Þ ($ y pda (y) ^ (equivalent (x, y))
= A' + B' + C 8. (b) The given table can be converted into Boolean function
RHS (A ® C) Ù (B ® C) º (A' + C) (B' + C) by adding minterms corresponding to true-row.
= A' B' + C Translates P Ú Q = PQ + PQ' + P'Q'
Þ RHS ¹ LHS Using this we can check the choices one by one to see
\ P1 is not tautology. which is equivalent to P + Q
P2 : ((A Ù B) ® C º ((A ® C) Ú (B ® C) Choice (a) Ø Q Ú Ø P º Q' Ú P'
LHS (A Ú B) ® C º A + B ® C º Q' P' + Q' (P')' + (Q')' (P')'
º (A + B)' + C º Q' P' + Q' P + QP
= A'B' + C º Q' P' + P(Q + Q')
RHS (A ® C) Ú (B ® C) º Q' P' + P (Q by complement law)
º (A' + C) + (B' + C) º (Q' + P) × (P' + P) (Q by distribution law)
= A' + B' + C º Q' + P
Þ LHS ¹ RHS Choice (b) P Ú Ø Q = P Ú Q'
Þ P2 is also not tautology. = PQ' + P (Q')' + P' (Q')'
EBD_7203
S2-8 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
º PQ' + PQ + P'Q I2 : If it rains, then the cricket match will not be played.
º P (Q' + Q) + P'Q It did not rain.
º P + P'Q (Q by complement law) Inference : The cricket match was played.
º (P + P') (P + Q) (Q by distribution law) I2 is not correct.
= P+Q Proof
According to logic table P ® Q i.e.,
Choice (c) Ø P Ú Q = P' Ú Q
º P'Q + P'Q' + (P')' Q'
P Q P®Q
º P'Q + P'Q' + PQ'
F F T
º P' (Q + Q') + PQ'
F T T
= P' + PQ' (Q by complement law) T F F
= (P' + P) (P' + Q') º P' + Q' (Q by distribution law) T T T
Choice (d) Ø P Ø Q º P' Q'
º P'Q' + P' (Q')' + (P')' (Q')' i.e., if there was not rain [i.e., P is F in logic table] then
º P'Q' + P'Q + PQ match may or may not be played because in both case
P ® Q is true.
º P'(Q' + Q) + PQ
So, the correct inference is—the cricket match might
º P' + PQ (Q by complement law) be played.
º (P' + P) (P' + Q) (Q by distribution law) 11. (c) The given statement or sentence is—
= P' + Q 'Some real number are rational.' We can also write this
We can clearly see only choice (b) P Ú Ø Q is equivalent sentence as follows:
to P + Q. 'There exists real number that are rational' therefore we
9. (d) The correct translation of gold and silver ornaments have to use $ (Existential) quantifier consider number
are precious is choice (d). as random variable x. Then,
$x (real) (x)) Þ This, indicates 'There exists number
" x ((G(x) Ù S(x)) ® P(x))
that are real.'
which reads as “if an ornament is gold or silver, then it
$ x (rational (x)) Þ This indicates 'There exists number
is precious”. Since, a given ornament cannot be both
that are rational.'
gold and silver at the same time.
Hence, $x (real (x) Ù rational (x) Þ
10. (b) I1 : If it rains, then then the cricket match will not be
This indicates 'There exists real number that are rational.
played.
12. (d) The Given statement is:
The cricket match was played.
“Not all that glitters is Gold”
Inference : There was no rain.
Here “Glitters” means the “Golden shiny surface” that
Hence, I1 is correct. looks like gold.
Proof So, the statement is saying that “Not all the shiny
Suppose P : It rains surface is Gold.” From the statement it can be deduced
that there is “Some glitters that is “definitely” not
Q : The cricket match will not be played.
gold”. However, nothing can be deduced that whether
It is given P ® Q “some glitters is Gold” or “No glitters is Gold.”
We know that P ® Q º ~ Q ® ~ P (A) For all x : glitters (x) Þ gold (x)
\ ~ Q : The circket match will be played. It says that if something is glitters then it must not be
~ P : It is not rain. Gold, which may not be true according to the above
discussion.
\ If the cricket match was played, then there was
(B) For all x : gold (x) Þ glitters (x)
no rain [P ® Q = ~ PQ ® ~ P]
It says that if something is Gold then it must be Glitters,
\ I1 is correct.
which can’t be deduced from given statement.
MATHEMATICAL LOGIC S2-9
(C) $ x : gold (x) ^ glitters (x) deduced this only as discussed above.
13. 0.24
It says that if something x is available which is not
glitters and is Gold. However this also can’t be Length of the shorter stick is 0.24.
deduced from given statement. 14. (~ (p « q) Ù r) Ú (p Ù qÙ ~ r)
(D) $ x : glitters (x) ^ gold (x) We prove the truth table as follows:–
It says that some x exists which is glitters and is not As the 2nd term in each given option is common we have
Gold. We note that from the given statement we included this term only once in the truth table:
nd
Option (A) (B) (C) (D) 2 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
S( xi - x )2 1 (X -m )2
-
s= f (x) = e 2 s2
Sfi 2ps 2
2 µ-mean, s-standard deviation.
S f i di 2 æ S f i di ö
s= -ç ÷ ´C Normal Distribution Curve
Sf i è Sf i ø y or f(x)
Variance : square of standard deviation (s2)
coeff. of variation : s ´ 100 i.e. ratio of S.D. to mean.
x
Random Variable
In a system, those variables which are one explicit function of
time is called random variable.
Mean (or Expectation) of random variable X = E(X)
E(X) = X(a1) . P(a1) + X(a2) . P(a2) + ...... x
u
n + X(an) P(an) For this curve mean, median and mode coincide
= å X(ai ) . P(ai ) It is symmetrical about y-axis with equal on both sides.
i =1
Binomial Distribution
Variance of X = s2 = E(X2) – [E(X)]2 Binomial distribution deals with trials of repetitive native in which
Standard deviations = s. occurrence of an event or not is of interest.
Poission Distribution In a series of trials, the probability of r success in n traits is given
by
Poission’s distribution is related to probabilities of events which nC pr qn–r
r
are extremely rare but have large number of individual chances to where, p-probability of success
occur. E.g.- number of persons die by dog-bite in a city. The q-probability of failure
number of trials n is taken very large and chance of P is taken Tips : This is important for GATE exam.
every small taking np constant. Example
Probability of zero success = nC0 p0qn–0 = qn
mr .e - m
Probability of r successes, P(r) = Probability of 1 success = nC1 p1qn–1 = npqn–1
r! Probability of 2 success = nC2 p2qn–2 = n(n – 1) . p2qn–2 etc.
where, m = np (constant)
m = mean, variance Points to be noted
standard deviation = m Sum of probabilities = qn + nC1 pqn–1 + nC2 p2qn–2 + ...... + pn
= (q + p)n = 1
Mean of binomial distribution = np and standard deviation = npq
EBD_7203
S2-14 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. A fair dice is rolled twice. The probability that an odd number 6. A class of first year B. Tech students is composed of four
will follow an even number is [2005, 1 mark] batches A, B, C and D, each consisting of 30 students. It is
found that the sessional marks of students in Engineering
1 1
(a) (b) Drawing in batch C have a mean of 6.6 and standard deviation
2 6
of 2.3. The mean and standard deviation of the marks for the
1 1 entire class are 5.5 and 4.2 respectively. It is decided by the
(c) (d) course instructer to normalize the marks of the students of
3 4
all batches to have the same mean and standard deviation
2. A fair coin is tossed three times in succession. if the first
as that of the entire class. Due to this, the mark of a student
toss produces a head, then the probability of getting exactly
in batch C are changed from 8.5 to [2006, 2 marks]
two heads in three tosses is [2005, 1 mark]
(a) 6.0 (b) 7.0
1 1 (c) 8.0 (d) 9.0
(a) (b) 7. A probability density function is of the form P(x) = ke–a|x|,
8 2
x Î ( -¥, ¥) . The value of k is [2006, 1 mark]
3 3
(c) (d) (a) 0.5 (b) 1
8 4
(c) 0.5a (d) a
3. If P and Q are two random events, then which of the following
8. For each element in a set of size 2n, an unbiased coin is
is true? [2005, 1 mark]
tossed. The 2n coins are tossed independently. An element
(a) Independence of P and Q implies that probability
is chosen, if the corresponding coin toss were head. The
(P Ç Q) = 0 probability that exactly n elements are chosen, is
[2006, 1 mark]
(b) Probability ( P È Q ) ³ Probability (P) + Probability (Q)
æ 2 nö æ 2 nö
(c) If P and Q are mutually exclusive, then they must be çè n ÷ø ç ÷
independent (a) (b) è n ø
(d) Probability ( P Ç Q ) £ Probability (P) 4n 2n
cards are selected with the number of the first card being
one higher than the number on the second card? 30. Consider an undirected random graph of eight vertices.
The probability that there is an edge between a pair of
[2011, 1 mark]
vertices is 1/2. What is the expected number of unordered
1 4 cycles of length three? [2013, 1 mark]
(a) (b)
5 25 (a) 1/8 (b) 1
(c) 7 (d) 8
1 2
(c) (d) 31. Four fair six-sided dice are rolled. The probability that the
4 5
sum of the results being 22 is X/1296. The value of X is
26. There are two containers, with one containing 4 red and 3 ______ . [2014, Set-1, 2 Marks]
green balls and other containing 3 blue and 4 green balls.
32. The security system at an IT office is composed of 10
One ball is drawn at random from each container. The
computers of which exactly four are working. To check
probability that one of the balls is red and the other is blue
whether the system is functional, the officials inspect four
will be [2011, 1 mark]
of the computers picked at random (without replacement).
9 The system is deemed functional if at least three of the four
(a) 17 (b) computers inspected are working. Let the probability that
49
the system is deemed functional be denoted by p.Then 100p
12 3 = _____________. [2014, Set-2, 1 Mark]
(c) (d)
49 7 33. The probability that a given positive integer lying between
1 and 100 (both inclusive) is NOT divisible by 2, 3 or 5 is
27. If two fair coins are flipped and atleast one of the outcomes
______ . [2014, Set-2, 2 Mark]
is known to be a head, what is te porbability that both
outcomes are heads? [2012, 1 mark] 34. Let S be a sample space and two mutually exclusive events
A and B be such that A È B = S. If P (·) denotes the
(a) 1/3 (b) 1/4
probability of the event, the maximum value of P(A) P (B) is
(c) 1/2 (d) 2/3
________ . [2014, Set-3, 2 Marks]
28. Let f(x) be the continuous probability density function of a
random variable X. The probability that a < X £ b, is
[2012, 1 mark]
(a) f(b – a) (b) f (b) – f(a)
b b
(c) òa f (x)dx (d) òa xf (x)dx
PROBABILITY S2-17
1. If µ is mean of distribution, then Sf i ( yi - µ) is equal to 7. A random variable X follows binomial distribution with mean
a and variance b. Then :
(a) MD (b) Standard deviation
(a) 0 < a < b
(c) 0 (d) None of these
2. The mean of a set of number is x . If each number is increased a2
(b) is a positive integer
by l, then variance of the new set is a-b
PAST GATE QUESTIONS EXERCISE (d) In a negatively skewed distribution mode > mean >
median. This sequence is not correct because the right
1. (d) Both the events are independent
sequence is
1 1 1 mode > median > mean
\ Required probability = ´ =
2 2 4
2. (b) Total samples = (H, T), (H, T), (H, T)
Given, first toss produces a head
Then, total chance becomes = H, (H, T), (H, T)
For exactly two heads in three toss = H, H, H
total favourable events
So, probability = Md M0
total sample Mean (x)
M0 Md Mean (x)
PROBABILITY S2-21
5 k k
Þ + =1
36 5 a a
= =
1 9 2k = a
4 k = 0.5 a
So, option (c) is right.
(d) Probability of (r/5 is an integer) 1
8. (a) P ( H ) = P (T ) =
= Probability (r = 5) + Probability (r = 10) 2
4 3 7 The probability that exactly n elements are chosen =
= + = The probability of getting n heads out of 2n tosses
36 36 36
n 2n - n
5 æ 1ö æ 1ö
and Probability (r = 6) = = 2nCn ç ÷ ç ÷
36 è 2ø è 2ø
then, Probability (r =6 | r/5 is an integer)
5 æ 2n ö
n çè n ÷ø
5 æ 1ö
= 36 = = 2 n Cn ç ÷ =
7 7 è 4ø 4n
36
\ Option (d) is wrong
6. (d) Let the mean and standard deviation of the students 9. (b) 25 calculators
of batch C are
mC = 6.6 and sC = 2.3 2 defective 23 (non-defective)
And the mean and standard deviations of the entire
class 5 calculators
Students are mc = 5.5 and s = 4.2 (randomly picked)
In order to normalize the batch C and entire class
x-m
Q z= (standard normal variate) 1 defective 4 non-defective
s
xC - mC 8.5 - 6.6 The probability that only one of the defective
For batch C = sC
=
2.3 calculators will be included in the inspection
x - m x - 5.5 2
C1 ´ 23C4
For entire class, z = = =
s 4.2 25
C5
By the instructer zC = z
2 ´ 23 ´ 22 ´ 21 ´ 20 ´ 5
8.5 - 6.6 x - 5.5 =
= 25 ´ 24 ´ 23 ´ 22 ´ 21
2.3 4.2
x ; 9.0 1
=
¥ 3
7. (c) ò P( x )dx = 1 10. (c) Assuming A and B are the events of failing in Paper 1
-¥ and Paper 2 respectively.
¥ P(A) = 0.3
Þ ò ke -a| x | dx = 1 P(B) = 0.2
-¥
æ Aö
P ç ÷ = 0.6
0 ¥ è Bø
Þ ò ke a x dx + ò ke
-a x
dx = 1
\ Probability of failing in both the papers
-¥ 0
æ Aö
k ax 0
(e ) -¥ +
k -ax ¥
(e )0 = 1 P ( A Ç B ) = P çè ÷ø .P( B)
Þ B
a -a
= 0.6 × 0.2 = 0.12
EBD_7203
S2-22 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
11. (c) Probability of occurrence of values 1, 5 and 6 on three = (0.55) × (0.55) = 0.3025 @ 0.30
dice is Now, probability of metro
= P(1) × P(5) × P(6) = 1 – (Probability of private car + Probability of bus)
= 1 – (0.45 + 0.30) = 0.25
1 1 1 1
= ´ ´ = \ Probability of private car = 0.45
4 8 4 128 Probability of bus = 0.30
Similarly, probability of occurrence of values 3, 4 and 5. Probability of metro = 0.25
On three dice is 15. (c) Let C denotes computer science study and M denote
= P(3) × P(4) × P(5) maths study.
1 1 1 1 P(C on Monday and C on Wednesday)
= ´ ´ = = P(C on Monday, M on Tuesday and C on
8 8 8 512 Wednesday) + P(C on Monday, C on Tuesday and C
And probability of occurrence of values 1, 2 and 5 on on Wednesday)
three dice is = 1 × 0.6 × 0.4 + 1 × 1.4 × 0.4 = 0.40
= P(1) × P(2) × P(5) 16. (c) Since, X is uniformly distributed random variable
1 1 1 1 between (0, 1) = (a, b)
= ´ ´ = The probability density function
4 8 8 256
12. (c) We know that, 1 1
f (x) = Þ Þ0
b - a 1- 0
Standard deviation (s)
Variation coefficient = 0 < x <1
Mean (µ) ì1,
So, f (x) = í
î0, other value of x
8.8
= = 0.2666 1
33
13. (a) Given, µX = 1, sX2 = 4, µY = –1 and µY2 is unknown E ( x )3 = ò x3 f ( x ) dx
x =0
Given, P(X £ –1) = P(Y ³ 2)
Converting into standard normal variates 1
= ò x3 .1 dx
æ -1 - m X ö æ 2 - mY ö
Pç z £ ÷ = Pç z ³ ÷ 0
è sX ø è sY ø
1
é x4 ù 1
-1 - 1 ö æ 2 - (-1) ö =ê ú =
Þ P æç z £ ÷ = Pç z ³ ÷ ëê 4 ûú 0 4
è 2 ø è sY ø
17. (b) The PDF is ìï f ( x) = x 2 , x Î[–1, 1]
æ 3 ö í
Þ P ( z £ -1) = P ç z ³ ÷ ïî = 0, other value of x
è sY ø
1/3
Since, P( z £ -1) = P ( z ³ 1) æ 1 1ö
But P ç - £ x £ ÷ = ò f ( x ) dx
è 3 3ø
-1/3
æ 3 ö
Þ P ( z £ -1) = P ç z ³ ÷ 1/3
è sY ø
= ò x 2 dx
3 -1/3
Þ 1= x2 is an even function, then using 3rd property of
sy
definite integral
sy = 3 a a
= 0.468 òa f (x)dx
EBD_7203
S2-24 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
29. (c) p = number of cars per minute passing through a Now, we shall calculate number of favourable cases for sum
certain road junction. of the results being 22.
p is a random variable following Poisson distribution We note that only two cases can result in sum 22.
(i) Two dice result 6, Two dice result 5 (6, 6, 5, 5)
l k e -1 (ii) Three dice result 6, One dice result 4 (6, 6, 6, 4)
Prob ( P = k ) =
\ k! No other combination will result is sum 22.
Mean = E[ p] = l
4!
\ l=3 No. of favourable cases for case (i) = 4C2 = =6
2!2!
Probability of observing fewer than 3 cars
= Prob (P = 0) + Prob (P = 1) + Prob (P = 2) 4!
No. of favourable cases for case (ii) = 4C1 = =4
1!3!
30.e -3 31.e -3 32.e -3 1 é 9 ù 17 Since either case (i) can occur or case (ii),
= + + = 3 ê1 + 3 + ú = 3 .
0! 1! 2! e ë 2 û 2e So, total no of favourable cases = 6 + 4 = 10
30. (c) To find the expected number of unordered cycles of (Probability of sum = 22)
length three. no. of favourable cases 10
Considering all the possible triplets of 3 vertices out = =
Total no. of cases 1296
of 8 and finding, if they form a cycle.
So, value of X = 10.
Analyzing unordered cycles and choosing any three
32. Soln : 11.85 to 11.95
vertices out of the 8 in any order.
P = P [atleast 3 computers are working]
This can be done in 8C3 ways.
= P [3 or 4 computers working]
The probability that there is an edge between a pair
of vertices is 1/2. To form a cycle between 3 chosen
vertices, we need to form edges between all pairs. =
( C ) ´( C ) +
4
3
6
1
4
C4
=
5
10 10
C4 C4 42
V1 5
\ 100 p = 100 ×
42
= 11.9
e2 33. 0.259 to 0.261
First we find out numbers which are divisible by either 2, 3
or 5
Consider 2
V2 V3 All even numbers are divisible by 2
e3 \ No. of numbers divisible by 2 between 1 and 100 = 50
Consider 3
Multiples of 3 cm 3, 6, 9, 12, 15 ...
So, the probability of the occuring is
100
1 1 1 1 Total nos = = 33
= ´ ´ = 3
2 2 2 8
Out of this alternate numbers are divisible by 2 also.
By definition of Expectation, which is if X is a
\ Number of remaining numbers = 33 – 16 = 17
random variable over sample space W
Consider 4
[X] = å x P ( x) Multiples of 5 are 5, 10, 15, 20, 25...
x ÎW
100
Total no. = = 20
1 5
8
Here P(x) = " x and x spans over all C3 Out of this alternate numbers are divisible by 2
8
\ Remaining no. = 10
configurations
Out of remaining odd numbers 15, 45 and 75 are divisible by 3
1 \ Remaining is 7
Hence, expected value = 8C3 × =7 \ Total number of nos divisible by 2, 3 or 5
8
Hence, the option is (c). = 50 + 17 + 7
31. 10 = 74
Given that four six-sided dice are rolled. \ Probability of integer not divisible by 2, 3 or 5
Since each dice can result 1, 2, 3, 4, 5 or 6. 74
Total no. of outcomes = 6 × 6 × 6 × 6 = 1- = 0.26
100
= 1296
PROBABILITY S2-25
34. 0.25
2 4 æ 6 6ö
AÈB = S x3 x2 x3 x2
=k + 2k + ç -k + 6k ÷
Þ P (A È B) = P(S) = 1 3 2 ç 3 2 ÷
0 2 è 4 4ø
Þ P(A) + P(B) = 1 ( Q A & B are mutually
exclusive) æ 8ö æ 152 ö 1
Þ P(B) = 1 – P(A) = k ç ÷ + k (12) - k ç ÷ + 3k (20) = (24) = 3
è 3ø è 3 ø 8
Maximum value of P(A)P(B) = P(A) [1 – P(A)]
Let P(A) = X 1 2
3 3
Let f(x) = x(1 – x) = x – x2 4. (a) Total frequency, N = ò x dx + ò (2 - x) dx
for f(x) maximum 0 1
Þ f¢(x) = 0
1 1 1
1 = + =
Þ 1 – 2x = 0 Þ x = 4 4 2
2
\ m1 ' (about the origin)
f ¢¢ (x) = – 2
1é ù
1 2
æ 1ö
f ¢¢ ç ÷ < 0 = ê ò x.x 3dx + ò x (2 - x )3 dx ú
è 2ø Nê úû
ë0 1
\ f(x) has maximum
1 ì 51 2 2ü
At x = and maximum value ïx (2 - x )4 (2 - x)5 ï
2 = 2í + - x. - ý
ïî 5 0 4
1
20
1ï
þ
æ 1ö 1 æ 1ö 1 1 1
= f çè ÷ø = çè1 - ÷ø = . = = 0.25
2 2 2 2 2 4 æ1 1 1 ö
= 2ç + + ÷ =1
è 5 4 20 ø
PRACTICE EXERCISE
m 2 ' (about the origin)
1. (c) Sf i ( yi - m) = fi yi - M Sfi
1 é 2 3 ù
1 2
= Sfi yi - Sfi yi = 0
= N êò x .x dx + ò x (2 - x ) dx ú
2 3
0
ì 1 1 1 é 1 1 ù ü 16
2 4 6
= 2 í + + ê + úý =
î 6 4 2 ë 5 30 û þ 15
i.e., ò kxdx + ò 2 kdx + ò (- kx + 6k )dx = 1
0 2 4 1
\ s 2 = m 2 = m 2 '- (m1 ')2 =
2 6
15
x2 4 æ x2 ö
Þk + 2k x 2 + ç -k + 6kx÷ = 1 1
2 è 2 ø4 i.e., standard deviation s =
0 15
1 Mean deviation about the mean
Þ 2k + 4k + (-10k + 12k ) = 1 Þ k =
8 ìï 1 2 ü
1 3 ï
í ò x - 1 x dx + ò x - 1 (2 - x ) dxý
3
Mean of X =
N
6
îï 0 1 þï
= ò xf ( x)dx
ìï 1 2 üï
0 = 2 í ò (1 - x ) x 3dx + ò ( x - 1)(2 - x)3 dx ý
2 4 6
ïî 0 1 ïþ
= ò kx 2 dx + ò 2kx dx + ò x( - kx + 6k )dx
ìæ 1 1 ö æ 1 öü 1
0 2 4 = 2 íç - ÷ + ç 0 + ÷ ý =
è
î 4 5 ø è 20 ø þ 5
EBD_7203
S2-26 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
5. (b) It follows a Poisson distribution as probability of 8. (a) The probability p of getting a white ball in a single
occurrence is very small. draw is 3/9 = 1/3. If X is the number of white balls
Mean, m = np = 2000 (0.001) = 2 drawn, then X ~ B (n, p), with n = 4. Therefore the
Probability that more than 2 will get a bad reaction probability of getting exactly one white ball is
= 1– [probability that no one gets a bad reaction + P(X = 1) = 4C1 pq3 = 4(1/3) (2/3)3 = 32/81.
probability that one gets a bad reaction + probability
e -m m 2
that two get bad reaction] 9. (c) We are given that e–m . m = 0.3 and = 0.2
2!
é m1e - m m 2e - m ù
= 1 - ê e-m + + ú 4
ëê 1! 2! ûú Dividing, m = 0.4 ¸ 0.3 =
3
é1 2 2ù \ P (X = 0) = e–m = e–4/3
=1 - ê 2 + 2 + 2 ú [Q m = 2]] 10. (c) We suppose the distribution to be Binomial with
ëe e e û n = 10, p = 0.2, q = 1 – p = 0.8
5 \ The probability that not more than one defective is
= 1- 2 [Q e = 2.718] found.
e
= 0.32 ænö
= P(k = 0) + P(k = 1) = q n + çç ÷÷p q n -1
6. (a) If n is the required number of tosses and p the è1 ø
probability of heads, X ~ B (n, p) .
1 1 = (0.8)10 + 10(0.2)(0.8) 9 = (0.8) 9 [0.8 + 2] = 2.8(0.8) 9.
Therefore, since p = and q = 1 – p = , This value is very small so the Binomial probabilities
2 2
are approximated by Poisson probabilities then
n
we get P(X = r ) = n C r (p r )(q n -r ) = n C r æç ö÷ m = np = 10 ´ 0.2 = 2
1
è2ø \ The probability that not more than one defective is
For the given A.P., we have 2P(X = 5) = P(X = 4) + P(X found.
= 6), i.e., = P(k = 0) + P(k = 1) = e- m + me- m
n n n n n
æ1ö æ1ö æ1ö C C = e -2 + 2e -2 = 3e -2
2 ( n C5 ) ç ÷ = n C4 ç ÷ + n C6 ç ÷ Þ 2 = n 4 + n 6
è2ø è2ø è2ø C5 C5
4
11. (a) Here p = = .04 ; n = 100
n 100
C4 é n! ù é 5!( n - 5)! ù 5
Now, n =ê úê ú = Probability of exactly 4 defectives =
C 5 ë 4!(n - 4)! û ë n! û n-4
100 4 96
p(4)= C4 × p × q
n
Similarly, C6 (n - 5) , so that
=
n 6
C5 100 100 ´ 99 ´ 98 ´ 97
= × (.04) 4 × (.96) 96= ´ .00000256 ´ (.96) 96
4 96 24
5 n - 5 30 + (n - 4)(n - 5)
2= + = It is a very small quantity.
n-4 6 6( n - 4)
As p is very small as compared to n, Poisson
Þ 12(n – 4) = 30 + n2 – 9n + 20 Þ n2 – 21n + 98 = 0 approximation is more convenient.
Þ (n – 7) (n – 14) = 0 i.e. n = 7 or 14 Here, parameter m of Poisson distribution is given by
7. (b) Suppose X ~ B(n, p), where n is a positive integer and m = np = 100 ´ .04 = 4
0 < p < 1. We have mean = np and variance = npq. But
Let the random variable X denote the number of
b defectives in a sample of 100. Then, by Poisson formula
np = a, npq = b Þ = q . Since npq > 0, we get b > 0.
a e - m .m r
p ( X ) x =r = p ( r ) =
b r
Also, 0 < p < 1, 0 < q < 1 Þ 0 < < 1 or a > b
a
e -4 .4 4 256 1 32
\a > b > 0 \ p( 4) = = . 4 = 4
4 24 e 3e
a a
Now, p = and q = 1 - = antilog[log 32 - log 3 - 4 log10 e]
n n
= anti log[1.5051 - 0.4771 - 4 ´ 0.4343]
æ a öæ a ö a2
Thus, b = n ç ÷ç1 - ÷ Þ n = = antilog (-0.7092) = anti log(-1 + .2908) = .1954
è n øè n ø (a - b )
PROBABILITY S2-27
P(E Ç F) P(E Ç F) n
+ æ4ö
12. (a, d) A. P (E / F) + P ( E / F) =
P(F) P(F) Þ ç ÷ ³ 10 Þ n(log 4 - log 3) ³ 1
è3ø
P( E Ç F) + P (E Ç F)
= ¹1 P[(X = a + b) Ç P(X ³ a)]
P (F) Also, P(X = a + bX ³ a) =
P(X ³ a)
P(E Ç F) P(E Ç F)
D. P (E/ F ) + P ( E / F ) = + P(X = a + b) pq a + b
P(F) P(F) = = = pq b = P(X = b)
P( X ³ a ) q a
3 1 1
draw is = . If X is the number of white balls drawn, 18. (b) P(A) = 1/4, P(A/B) = , P(B/A) = 2/3
9 3 2
then X ~ B(n, p), with n = 4. Therefore the probability By conditional probability,
of getting exactly one white ball is P(A Ç B) = P(A) P(B/A) = P(B)P(A/B)
3 1 2 1 1
æ 1 öæ 2 ö 32 Þ ´ = P ( B ) ´ Þ P( B ) =
P(X = 1) = 4 C1pq 3 = 4ç ÷ç ÷ = 4 3 2 3
3
è øè ø 3 81
19. (a) In this case
14. (d) Let X ~ B(100, p) be the number of coins showing
heads, and let q = 1 – p. Then, since P(X = 51) = P(X=50), æ C ö P(C Ç D) P (C )
Pç ÷ = =
we have èDø P( D ) P ( D)
100
C51 (p 51 )(q 49 ) = 100 C50 (p 50 )(q 50 ) æC ö
Where, 0 £ P ( D ) £ 1 , hence P çè ÷ø ³ P (C )
D
p æ 100! öæ 51!49! ö
Þ =ç ÷ç ÷ 20. (d) Given : P(I) = 0.3 and P(II) = 0.2
q è 50!50! øè 100! ø
\ P( I ) = 1 – 0.3 = 0.7 and P( II ) = 1 – 0.2 = 0.8
p 51 51 \ The required probability
Þ 1 - p = 50 Þ 50p = 51 – 51p Þ p =
101
= P ( I Ç II) = P( I ).P(II) = 0.7 × 0.2 = 0.14
15. (b) Let n denote the required number of shots and X the
number of shots that hit the target. Then X ~ B(n, p), P ( A Ç B ) P( A È B) 1 - P( A È B)
21. (c) P ( A / B) = = =
with p = 1/4. P( B ) P (B) P( B )
Now, P(X ³ 1) ³ 0.9 Þ1 - P(X = 0) ³ 0.9 22. (b) m = 1
n n –m 1
æ3ö
n æ3ö 1 P (X < 0) = P (Z < ) = P(Z < – )
Þ 1 - C 0 ç ÷ ³ 0.9 Þ ç ÷ £ s 2
è4ø è4ø 10 = P (Z < – 0.5)
P (X < 0) = 0.5 – P (0 < z < 5)
EBD_7203
S2-28 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1 = P( A)(1 - P ( B )) = P( A) P ( B )
3 5
1 æ1ö æ1ö 2 Hence A and B are independent.
23. (c) Probability = + ç ÷ + ç ÷ + ....¥ = 2 =
2 è2ø è2ø 1 3 26. (c) Standard Deviation of new data
1–
4
2 2
24. (a) S (la1 )2 æ Slai ö Sa12 æ Sai ö
= -ç ÷ = l2 -ç =| l | s
25. (a) P ( A È B ) = P ( A) + P ( B ) - P ( A Ç B ) n è n ø n è n ÷ø
27. (d) n = 4
\ P (( A Ç C ) È ( B Ç C )) = P ( A Ç C ) + P( B Ç C )
Let X be event of showing no. of heads.
- P( A Ç C Ç B Ç C ) Req. prob = P (X = 3) + P (X = 4)
and P (( A È B ) Ç C ) = P ( A Ç C ) + P ( B Ç C ) = 4 C3 ( 1 2 ) ( 2 ) + 4 C2 ( 1 2 ) 4
3 1
= 5/16
- P( A Ç B Ç C ) 28. (c)
P (( A È B) Ç C ) P( A Ç C ) P ( A Ç ( A È B ))
Þ = 29. (a) P( A / A È B) =
P (C ) P (C ) P( A È B)
P(B Ç C) P( A Ç B Ç C) P( A) P( A)
+ - = =
P(C) P(C) P ( A È B ) P( A) + P ( B )
Þ P ( A È B / C ) = P ( A / C ) + P( B / C ) - P ( A Ç B / C ) 30. (d) Here, m + s 2 = 24
(b) P ( A Ç B / C ) + P( A Ç B / C ) and ms 2 = 128
Solving we get
P( A Ç B Ç C ) P( A Ç B Ç C )
= + m = 16 or 8
P (C ) P (C ) If m = 16 then
s2 = 8
P( A Ç B Ç C ) + P( A Ç B Ç C )
= If m = 8 then
P (C ) s2 = 56.
Case I : np = 16 and npq = 8
P( A Ç B Ç C ) È ( A Ç B Ç C )
=
P (C ) 1 1
Þ p= , q = and n = 32
2 2
P( A Ç C ) Case II: np = 8 and npq = 56
= = P( A / C )
P (C ) Þ q = 7, which is not possible
(c) P( A Ç B ) 32
n æ 1 1ö
Hence distribution is (q + p ) = ç + ÷
= P( A) - P( A Ç B ) = P ( A) - P ( A) P ( B ) è 2 2ø
3 Set Theory & Algebra
ALGEBRAIC OPERATIONS ON SETS 3. Distributive Law
Idempotent operation : For any set A, we have A Ç (B È C) = (A Ç B) È (A Ç C)
A È (B Ç C) = (A È B) Ç (A È C)
(i) A È A = A and
4. Complement Law
(ii) A Ç A = A A È A° = U ; A Ç Ac = f.
Identity operation : For any set A, we have 5. Identity Law
(i) A È f = A and AÈf=A= fÈ A
(ii) A Ç U = A A Ç U = A = U Ç A.
i.e. f and U are identity elements for union and intersection 6. Absorption Law A È (A Ç B) = A ; A Ç (A Ç B) = A
respectively. 7. De Morgan’s Law (A È B)c = Ac Ç Bc ; (A Ç B)c = Ac È Bc
Commutative operation : For any set A and B, we have 8. Involution Law (Ac)c = A.
(i) A È B = B È A Obs. Using the distributive law, we can extend the above result
(ii) A Ç B = B Ç A and for three sets A, B, C
| A È B È C | = (A È B) È C |
(iii) A D B = B D A
= | A È B | + | C | – | (A È B) Ç C |
i.e. union intersection and symmetric difference of two sets = | A | + | B | – | A Ç B | + | C | – | (A Ç C) È (B Ç C) |
are commutative. = |A| + | B | + | C | – | AÇ B | – [ |A Ç C | + | B Ç C | –AÇ B Ç C | ]
hence follows the result
= | A | + | B | + | C | – | A Ç B | – | A Ç C | – | B Ç C | + | A Ç B Ç C|]
A – B ¹ B – A and A × B ¹ B × A Duality : If S be any identity involving sets and operations (e.g.
i.e. difference and Cartesian product of two sets are not complement, intersection Ç and union È etc.) and a new set S*
commutative. is obtained by replacing Ç by È, È by Ç, f by U and U by f in
S, then the statement S* is true and is called the dual of the
Associative operation : If A, B and C are any three sets, then statement S.
(i) (A È B) È C = A È (B È C) For instance, the dual of A Ç (B È A) = A is A È (B Ç A) = A.
(ii) (A Ç B) Ç C = A Ç (B Ç C) Sample Problem
(iii) (A D B) DC = A D (B D C) 1. In a survey conducted on 250 persons, it was found that
i.e. union, intersection and symmetric difference of three sets 180 drink tea and 70 drink coffee and 50 take both tea and
are associative. coffee. How many drink atleast one bevarage and how many
drink neither ?
Note : Sol. Let A be the set of tea drinkers and B the set of coffee
(A – B) – C ¹ A – (B – C) and (A × B) × C ¹ A × (B × C) drinkers. Then
i.e. difference and Cartesian product of three sets are not | A È B | = | A | + | B | – | A Ç B | = 180 + 70 – 50 = 200
associative. Hence 200 persons drink at least one bevarage and 250 – 200 =
50 persons drink neither tea nor coffee.
Distributive operation : If A, B and C are any three sets, then 2. How many integers are between 1 and 200 which are divisible
by any one of the integers 2, 3 and 5 ?
(i) A È (B Ç C) = (A È B) Ç (A È C)
Sol. Let A1, A2, A3 denote the set of integers between 1 and 200
(ii) A Ç (B È C) = (A Ç B) È (A Ç C) which are divisible by 2, 3, 5 respectively.
i.e. union and intersection are distributive over intersection
é 200 ù é 200 ù é 200 ù
and union respectively. [A1 ] = ê ú = 100, [A2 ] = ê ú = 66, [A3 ] = ê = 40
ë 2 û ë 3 û ë 5 úû
LAWS OF SET THEORY
é 200 ù é 200 ù
1. Commutative Law [A1 Ç A 2 ] = ê ú = 33, [A1 Ç A3 ] = ê = 20
A È B = B È A ; A Ç B = B Ç A. ë 2 ´ 3 û ë 2 ´ 5 úû
2. Associative Law
é 200 ù é 200 ù
A È (B È C) = (A È B) È C [A2 Ç A3 ] = ê = 13,[A1 Ç A2 Ç A3 ] = ê =6
A Ç (B Ç C) = (A Ç B) Ç C ë 3 ´ 5 úû ë 2 ´ 3 ´ 5 ûú
EBD_7203
S2-30 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Hence The corresponding arrow diagram is as follows :
[A1 È A 2 È A3 ] =| A1 | + | A 2 | + | A3 | - | A1 Ç A 2 | A A
- | A 2 Ç A3 | - | A3 Ç A1 | +[A1 Ç A 2 Ç A3 ] 2 2
= 100 + 66 +40 – 33 – 13 – 20 + 6 = 146. 3 3
CARTESIAN PRODUCT OF SETS 5 5
Ordered Pair : A pair of objects, listed in a specific order, is 6 6
called an ordered pair, for example (a, b) is an ordered pair of two
elements a and b, a is called the FIRST ELEMENT and b the DOMAIN AND RANGE OF A RELATION
SECOND ELEMENT.
Let A and B are two sets and R is a relation from A to B,
Two ordered pairs (a, b) and (c, d) are equal if any only if
a = c and b = d. i.e. R Í A × B
Cartesian product of Sets : Let A and B are two non-empty sets. The set of all the first components of the ordered pairs of the
The set of all ordered pairs (a, b) of elements a Î A and b Î B is relation R is called the DOMAIN of R. Thus
called the Cartesian Product of sets A and B and is denoted by domain of R = {aÎA : (a, b) Î R for some bÎB}
A × B. Thus A × B = {(a, b) : a ÎA, b Î B} The set of all the second components of the ordered pairs of the
For example : If A = {1, 2, 3} and B = {a, b}, then relation R is called the RANGE of R. Thus,
(i) A × B = {(1, a)}, (1, b), (2, a), (2, b), (3, a), (3, b)} range of R = {bÎB : (a, b) Î R for some a ÎA}
(ii) B × A = {(a, 1)}, (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
Clearly domain of R Í A and range of R Í B
(iii) A × A = {(1, 1)}, (1, 2), (1, 3), (2, 1), (2, 2), (2, 3),
(3, 1), (3, 2), (3, 3)} The set B is called the CO-DOMAIN of R
(iv) B × B = { (a, a), (a, b), (b, a) (b, b)} Example :
(i) If A = {1,2,3} and B = {a, b, c} let R = {(1,a) (1,c), (2, b)
REL ATI ONS
Then domain of R = {1, 2} range of R = {a, b, c}
Let A and B be two non-empty sets. Then a relation (BINARY
(ii) Let R be a relation on the set N of natural numbers defined
RELATION) R from A to B is a subset of A×B.
by a + 3b = 12.
That is, R is a relation from A to B Û RÍA × B
Then R = {(9, 1), (6, 2), (3, 3)}
If R Í A×A, the R is said to be a relation on A.
[The values of a can be obtained by giving the values
If (a, b) ÎR, then we write aRb and we say a is R related to b.
Thus, (a, b) ÎR Û aRb. b = 1, 2, 3. Clearly b >| 3, otherwise a becomes zero or
If (a , b) Ï R , then we write a R b and say that a is not related to b. negative]
Example : \ domain of R = {9, 6, 3} and range of R = {1, 2, 3}
(i) If A = {3, 5} and B = {2, 4}, then Number of Relations : Let A contains m elements and B contains
A× B = {(3,2), (3,4), (5,2), (5,4)} n element. Then A×B contains mn elements. Hence, A×B has
Let R be a relation “is greater than” from A to B, 2mn subsets. That is the total number of relations from A to B are
2mn. The relations f (called a VOID RELATION) and A × B (called
That is aRb Û a > b, a Î A, b Î B
an UNIVERSAL RELATION) are said to be TRIVIAL RELATIONS
Then, 3R2, 5R2, 5R4
from A to B.
\ R = {(3,2), (5,2), (5,4)}. Clearly R Í A ´ B Inverse Relation : The inverse relation of a relation R is the set
The visual representation of a relation is an arrow diagram obtained by reversing each of the ordered pairs of R and is
as shown below: denoted by R–1. Clearly, if R Í A×B then R–1Í B × A. We write
R–1 ={(y, x) : (x, y) Î R}
A B \ (x, y) Î R Û (y, x) ÎR–1 . It is clear that domain of
R–1 = range of R and range of R–1 = domain of R also.
(R–1)–1 = R
3 2
Example :
(i) Let A = {1, 2, 3} and B = {a, b, c}
5 4
If R = {(1, a), (2, a), (3, b), (3, c)} Í A × B
Then R–1 = {(a, 1), (a, 2), (b, 3), (c, 3)} Í B×A
(ii) Let A be set of first ten natural numbers. Define a relation R
(ii) If A = {2, 3, 5, 6} and R be a relation “divides” on A that is on the set A by (a, b) Î R Û a + 2b = 10
aRb Û a divides b then 2R2, 2R6, 3R3, 3R6, 5R5, 6R6
\ R = {(2,2), (2,6), (3,3), (3,6) (5,5) (6,6} Í A×A 10 - a
We have b = . Clearly a must be even.
2
SET THEORY & ALGEBRA S2-31
Also A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} (c) R is transitive, i.e., aRb and bRc Þ aRc
\ 2R4, 4R3, 6R2, 8R1 Partial order relation :
Thus R = {(2, 4), (4, 3), (6, 2), (8, 1)} A relation R on a set A is a partial order relation if and only if.
and R–1 = {(4, 2), (3, 4), (2,6) (1,8)} (a) R is reflexive, i.e. aRa " aÎA
(b) R is antisymmetric i.e., aRb and bRa Þ a = b
TYPES OF RELATIONS ON THE SET A (c) R is transitive, i.e., aRb and bRc Þ aRc.
Let A be a set and R is a relation on A, i.e. R Í A × A. Then we Relation of congruence modulo m :
define Let m be a fixed positive integer. Two integers a and b are said to
be “congruent modulo m” if a – b is divisible by m. We write
1. Void Relation : If R = f , then R is called a void relation on A.
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ÎI.
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 on (i) 25 º 5 (mod 4) because 25–5 = 20 is divisible by 4.
A, every element of A is related to itself only. Identity relation (ii) 23 º 2 (mod 3) because 23 –2 = 21 is divisible by 3
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
SO ME T HEO REM S ON EQ UIV AL EN CE
relation on A if every element of A is related to itself.
RELATION
Thus R is reflexive Û (a,a) ÎR, i.e. aRa " aÎA
1. If R and S are two equivalence relations on a set A, then
[The symbol " is read as “for every element”] R Ç S is also an equivalence relation on A.
Example : Let A = {1, 2, 3} be a set. 2. If R and S are two equivalence relations on a set A, then
Then R = {(1, 1), (2, 2), (3, 3), (1, 3), (2, 1)} is a reflexive R È S is not necessarily an equivalence relation
relation on A. 3. If R is an equivalence relation on a set A, then R–1 is also an
5. Symmetric Relation : A relation R on a set A is defined as a equivalence relation on A.
symmetric relation if (a,b) ÎR Þ (b, a) ÎR That is, COMPOSITION OF RELATIONS
aRb Þ bRa, where a, bÎA. Let R be a relation from set A to the set B and S be another
Example : Let A = {1, 2, 3, 4} and let R1 be relation on relation from set B to the set C. Then we define a relation SoR
A given by R1 = {(1, 3), (1, 4), (3, 1), (2, 2), (4, 1)} is a symmetric (Read as “ R composite S”) from A to C such that (a, c) Î SoR Û
relation on A. $ bÎB such that (a, b) Î R and (b,c) ÎS
6. Transitive relation : A relation R on a set A is defined as a [The symbol $ is read as “ there exists”]
transitive relation if (a,b) ÎR and (b,c) ÎR Þ (a,c) ÎR Clearly, aRb and bSc Þ a SoRc
That is, aRb and bRc Þ aRc, where a, b, c, ÎA. Example :
Let A = {1, 2, 3} B = {x, y}, C = {a, b, c}
Example : Let L be the set of all straight line in
Let R = {(1, x), (1,y), (3, y)} ÎA×B
a plane. Then the relation ‘is parallel to on L is a transitive S = {(x,a), (x,b), (y,b), (y,c)} Í B×C
relation, because of any l1, l2, l3, Î L. Then SoR = {(1,a), (1,b), (1,c), (3,b), (3,c)} Í A × C
l1||l2 and l2||l3 Þ l1||l3 Because (1,x) ÎR and (x,a) ÎS Þ (1,a) Î SoR, etc.
7. Antisymmetric Relation : A relation R on a set A is
PARTITION OF A SET
antisymmetric if (a,b) ÎR and (b,a) ÎR Þ a = b
Let S be a non-empty set and A1, A2,......be non-empty subsets
If (a, b) Î R and (b, a) ÏR, then still R is an antisymmetric
of S. Then the set P given by P = {A1, A2, ......} is called a partition
relation.
of the set S, provided
Example : Let R be a relation on the set N of natural numbers
(i) A1ÈA2È........= S, i.e. U Ai = S
defined by i
xRY Û ‘x divides y’ for all x, y Î N (ii) For any two subsets Ai and Aj of S, Ai I Aj = f
This relation is a antisymmetric relation on N. i.e. Ai I Aj = f, i ¹ j, Ai, AjÎP
Since for any two numbers a, b Î N. Example :
a/b and b/a Þ a = b i.e. aRb and bRa Þ a = b (i) Let S = {1, 2, 3, 4, 5, 6, 7} Suppose
A1 = {1, 5}, A2 = {2, 4,7}, A3 = {3, 6}
EQUI VAL ENCE RELATION
Clearly A1 U A 2 U A 3 = S
A relation R on a set A is an equivalence relation if and only if
(a) R is reflexive, i.e, aRa " aÎA and A1 I A 2 = f, A 2 I A 3 = f, A 3 I A1 = f
(b) R is symmetric, i.e., aRb Þ bRa \ P = {A1 , A 2 , A 3} is a partition of the set S.
EBD_7203
S2-32 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(ii) All partitions of the set {a, b, c,} are DOMAIN, CO-DOMAIN AND RANGE
P1 = {{a , b, c}}, P2 = {{a}, {b, c}}, P3 ={{b}, {a , c}}, If f A ® B is a funciton, then A is called domain, B is called co-
P4 = {{c}, {a , b}}, P5 = {{a}, {b}, {c}} domain of f.
Range :
ONE - ONE CO R RES PONDENCE If f : A ® B is a function, then set of all images of the elements of
If A and B are two sets such that each element of A corresponds A is called range of f.
to one and only one element of B, and conversely, each element It is denoted by f (A) = {f (a)/a Î A}
of B corresponds to one and only one element of A, then we say Range is a subset of the co-domain, i.e. f (A) Í B.
that there is one-one correspondence between the elements of A e.g. If A = {1, 2, 3, 4}, B = {p, q, r} and f = (1, q), (2, q), (3, q), (4, q)},
and the elements of B. then f is a function.
For example : Domain = A, Co-domain = B.
Range of f = f (A) = {f (1), f (2), f (3), f (4)}
ì 1 1 1 1 1ü
(i) Let A = {1,2,3,4,5,6} and B = í1, , , , , ý then there = {q, q, p, q} = {p, q}
î 2 3 4 5 6þ \ f (A) Í B
is one-one correspondence between the elements of A and
There is no pre-image for the element r Í B.
their reciprocals in B and vice versa
Every then f : A ® B is a funciton (hence for every element there
(ii) There is one-one correspondence between the set of real may not be pre-images).
numbers R and the points on a straight line. e.g. (i) Let A = {1, 2, 3, 4}, {p, q, r} and g = {(1, p), (2, q), (3, p),
FUNCTION OR MAPPING (4, p), (1, r)}.
The element 1 Î A has two images p and r in B.
If A and B are two non-empty sets, then a function or mapping or So, g : A ® B is not a function but it is only a relation.
map from A to B is a subset f of A×B such that for every xÎA • If N is a the set of natural numbers and
there is a unique yÎB, and the ordered pairs (x, y) Î f. f = {a, b} | a, b Î N, b = 2a}, then f : N ® N is a function.
In other words, a function f is a relation from a non empty set A • If f (x) = | x |, " x Î R, then F : R ® R is a function, i.e.
into a non empty set B such that domain of f is A and no two f = {(x, | x |) x Î R}
ordered pairs in f have the same first component. Clearly, every f (x) = x if x ³ 0, f (x) = –x if x < 0.
function is a relation but every relation is not a function. KINDS OF FUNCTIONS
If f is a function from A into B, then we write (x,y) Î f as f (x) = y, 1. One-to-one Function (or injective function)
where x Î A and y Î B, y is called the IMAGE of x under f and x A function f : A ® B is called one-one mapping if every
is called the PRE-IMAGE of y under f. The function f from A into
distinct element of A has a distinct image in B.
B is denoted by f : A ® B .
Thus, a function f : A ® B is one-one
For example :
if f ( x1 ) = f ( x 2 ) Þ x1 = x 2"x1, x 2 Î A
Let A = {1,2,3}, B = {a , b, c}
Alternatively, x1 ¹ x 2 Þ f ( x1 ) ¹ f (x 2 )
let us define following relations from A to B
2. Many-one Function : A function f : A ® B is many-one if
(i) R1 = {(1, a ), (3, b), (2, c)}
two or more different elements of A have the same image in B.
In R1 every element of A occurs once and only once as the Thus, f : A ® B is many-one if
first element in the ordered pairs of R1, hence R1 is a
function. We say that a is the image of 1; b is the image of 3 f ( x1 ) = f (x 2 ) Þ x1 ¹ x 2
and c is the image of 2 and we may write or x1 ¹ x 2 Þ f ( x1 ) = f ( x 2 ) for some x1 , x 2 Î A
f (1) = a, f (2) = c and f (3) = b 3. Onto or Surjective Function : The function f : A ® B is
1, 2 and 3 are pre-images of a, c and b respectively. said to be an onto function if every element of B is image of
(ii) R 2 = {(1, a ), (2, a ), (3, a )} R2 is a function at least one element of A. That is,
In this case ‘a’ is the image of each of 1, 2 and 3, thus if for each y Î B , there exists at least one x Î A such that
f (1) = a, f (2) = a and f (3) = a f(x) = y, then f is an onto function.
(iii) R 3 = {(1, a ), (1, c), (2, a ), (3, b)} R3 is not a function as 1 Thus, for a surjective function f,
occurs twice as the first elements in ordered pairs of R3. Range of f = co-domain (B)
(iv) R 4 = {(1, a ), (2, b)} 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
R4 is not a function as 3 does not occur as the first element
element of A, then f is called an into function.
in any of the ordered pairs of R4.
For an into function f.
SET THEORY & ALGEBRA S2-33
Range of f Ì co-domain (B) Sample Problem
Example : Various combinations are shown in the following If G = Q – {1}, if * is defined on G as a * b = a + b – ab, show
Venn diagrams. that (G, *) is an abelian group.
Sol. Clearly G is non-empty.
f f
Let a, b Î G
x1 y1 x1 y1 aÎG Þ a Î Q, a ¹ 1
x2 y2 x2 y2
x3 y3 x3 y3 bÎG Þ b Î Q, b ¹ 1
y4 a Î Q, b Î Q Þ a + b Î Q,
A B A B
Many-one Into ab Î Q Þ a + b – ab Î Q
One - One Into
f f Þ a* bÎQ
If a*b=1
x1 y1 x1 y1
x2 y2 x2 y2 then a + b – ab = 1
x3 x3 y3 Þ a – 1 + b – ab = 0
A B Þ 1(a – 1) – b(a – 1) = 0
Many-one Onto One - One Onto Þ (a – 1) (a – 1) = 0
Þ a = 1 or b = 1
Bijective function : A function f : A ® B is a bijective Contradiction : a * b ¹ 1
function if f is one-one as well as onto, i.e. f is injective and a * bÎ Q, a * b ¹ 1,
surjective both. Þ a* bÎG
COMPOSITION OF FUNCTIONS Therefore * is a binary operation on G.
Let, a, b, c Î G.
Let A, B, C be three sets and f : A ® B , g : B ® C be two functions. a * (b * c) = a * (b + c – bc)
Define a function go f : A ® C such that go f (x) = g ( f(x)) for all = a * (b + c) – bc) – a(b + c – bc)
x ÎA. = a + b + c – bc – ab – ac + abc
Since f (x) ÎB \ g ( f (x)) Î C. (a * b) * c = (a + b – ab) * c
= a + b – ab + c – (a + b – ab) c
The function go f is called the composition of f and g
= a + b + c – ab – ac – bc + abc
f g
\ a * (b * c) = (a * b) * c
Therefore * is an associative binary operation on G.
x
Let e be the identity element of G, then
f(x) g(f(x)
a * e = a, " a Î G
A B C a* e= a
gof
Þ a + e – ae = a
[see also the composition of relations] Þ e(1 – a) = 0
Þ e=0
GROUP \e = 0 Î G is identity element in G.
A semigroup with identity and in which every element is invertible Let a Î G. If b is inverse of a, then
is called a group. a*b=0
Definition 1 Þ a + b – ab = 0
Let G be a non-empty set and * be a binary operation on G. Then Þ b (a – 1) = a
algebraic system (G, *) is called a group if a
I. a * (b * c) = (a * b) * c, " a, b, c Î G Þ b= Î G.
a -1
II. $e Î G Þ a * e = e * a = a, " a Î G
a
III. a Î G Therefore b = ÎG is inverse of a in G..
a -1
Þ $b Î G Þ a * b = b * a = e
Let a, b Î G, then a * b = a + b – ab
• The element e in condition II of the definition of a group is
= b + a– ba = b * a
called identity element of the group.
Therefore * is a commutative in G.
• The element b corresponding to a in condition III of the
Therefore (G, *) is an abelian group
definition of a group is called inverse of a in the group.
Definition 3 :
Definition 2 A group (G, *) is said to be a non-abelian group, if (G, *) is not
A group (G, *) is called an abelian group or commutative group if abelian.
a * b = b * a, " a, b Î G.. PROPERTIES OF A GROUP.
e.g. (Z, +), (Q, +), (R, +), (C, +) are all abelian groups. Theorem 1 :
In a group, identity element is unique.
EBD_7203
S2-34 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Theorem 2 : Thus (G, .) is a finite abelian group.
In a group, inverse of every element is unique. Definition 8.
Theorem 3 : If S is a finite set containing n elements, then group of all
bijections on S is called a permutation group or symmetric group.
( )
-1
If (G, .) be a group and a Î G , then a -1 = a. It is denoted by Pn or Sn.
Note : 0(Sn) = n!
Theorem 4 :
If (G, .) be a group and a, b Î G, then (ab)–1 = b–1a–1 PARTIAL ORDERING
Theorem 5 : A relation ~ on a set P is called partial order if it is
If (G, .) be a group and a1, a2, .... an Î G, then (a) reflexive x ~ x, " x Î P :
(a1a 2 .....a n ) -1 = a n-1a n--11.........a1-1 (b) antisymmetric : (x ~ y) Ù (y ~ x) Þ x = y
(c) transitive : (x ~ y) Ù (y ~ z) Þ x ~ z
Theorem 6 :
A partial order is always denoted as £ .
Cancellation laws hold in a group, i.e. If (G, .) is a group then
The set P with a partial order £ is called partially ordered set,
I. a, b, c Î G, ab = ac
denoted by (P, £) and it is also called poset.
Þ b=c
Totally ordered Poset.
II. a, b, c, Î G, ba = ca
A poset (P, £) is called totally ordered set, if for all x, y Î P,
Þ b = c. (x £ y) Ú (y £ x).
Definition 4. Cover of x.
If (G, .) be a gorup and a Î G, n Î z, then an is defined as follows : Let x Î (P, £). An element Î (P, £) is called cover of x if x £ y and
I. a0 =e there exists no element z Î P such that x £ z and z £ y.
II. If n > 0, then a1 = a; an+1 = an . a Hasse diagram.
III. If n < 0, then an = (a–n)–1 It is a graph whose points are points of P, where points x and y
Theorem 7. are connected by an edge if y covers x. Any finite poset can be
Let (G, .) be a group and a Î G. represented by a Hasse diagram.
If m, n Î Z, then e.g. Let P = {1, 2, 3, 4, 5, 6, 25, 100}.
I. am . an = am+n = anam Hasse graph is given in the figure.
II. (a )
m n
= a mn
4
100
25
Definition 5. 6
Let (G, .) be a group. An element a Î G is called idempotent if a2 = a.
Definition 6. 2 5
A group (G, .) is called finite group if G is a finite set The number of 1
different elements in G is callled order of the fininte group (G, .). It Least element.
is denoted by O(G). y is least element of P if y £ x for all x Î P.
Definition 7. Greatest element.
A group (G, .) is called infinite group if G is an infinite set. The y is greatest element of P if x £ y for all x Î P.
order of an infinite group is defined to be ¥. Upper bound.
Sample Problem Let A Í P. An element x Î P is called upper bound of A if a £ x for
Let G = {1, –1, i, –i} where i2 = –1. Show that G is a finite all a Î A.
abelian group under multiplications of complex numbers. Lower bound.
Sol. The composition table for multiplication is as follows. Let A Í P. An element y Î P is called upper bound of A if y £ a for
all a Î A.
1 -1 i -i
Least upper bound (LUB).
1 1 -1 i -i LUB of A is x is an upper bound and if y is any other upper
-1 -1 1 -i i bound, then x £ y.
i i -i -1 1 Greatest lower bound (GLB).
-i -i i 1 -1 GLB of A is y if y is a lower bound for A and if b is any other lower
bound, then b £ y.
The multiplication of complex numbers is associative and
Sometimes GLB is called infimum and LUB is called supremum.
commutative.
By observing the table it follows that 1 is the identity element LATTICE
in G and the inverses of 1, –1, i, –i are 1, –1, –i, i respectively. It is a partially ordered set (P, £) in which any two elements Î P
has single GLB and single LUB.
SET THEORY & ALGEBRA S2-35
(a) (b)
Meet = GLB
Fig. (a) a = a * b = meet = GLB
a£b
In the Fig. (a) GLB and LUB are shown, which are also called
meet and join respectively. Sol. Leta £ b
4 d Since a £ a, we have a £ a * b.
Since a * b is lower bound for both a and b, we have
a * b £ a.
c Hence a = a * b.
2 3 a b
2. Show that a lattice with less than 4 elements is a chain.
Sol. Let (L, £) be a lattice.
Obviously if | L | = 1 or 2 it must be a chain.
1 e
Figure given below shows all possible combinations on
Fig. (b) Lattice Fig. (c) Non-Lattice
three elements.
The poset shown in Fig. (c) is not a lattice since a and b have two
LUBs namely c and d. 2 2 3
From first lattice, following relations are obtained :
1 £ 2, 1 £ 3, 2 £ 4 and 3 £ 4. 1 1 1 2
Here 2 and 3 are not compared.
If (P, £ ) is a lattice, then (P, ³ ) is also a lattice, we define as 1
³ follows L L L
(x £ y) Þ y ³ x.
(a) (b) (c) (d)
In other words, GLB and LUB are interchanged if we interchange
relations £ and ³. 2 3
2 3 2 3
In terms of lattices, operations of meet and join on (L, £) become
the operations of join and meet on (L, £). 1 1 1
(e) (f) (g)
DUAL LATTICE
The posets shown on Figures (c), (e), (f) and (g) are not
For the lattice (P, £ ) the dual is (P, ³). lattices as no two elements have GLB or LUB. Other posets
The duals are shown in the figure below. The diagram of (P, ³) are lattices and they are chains.
can be obtained from that of (P, £) by simply turning it upside SUB-LATTICE.
down. Let (L, *, Å) be a lattice and let S Í L. The set (S, *, Å) is called
5 1 sublattice iff it is closed under * and Å. Sublattice is itself a
lattice.
4 Closed Interval.
2 3 b
2 3
4
a
1 5
1£ 2£ 4£ 5 5³ 4³ 2³ 1
1£ 3£ 4£ 5 5³ 4³ 3³ 1
Let a * b = meet of a and b = GLB, and a Å b = join of a and b = Fig. Interval [a, b]
LUB Let a £ b.
Then closed interval of a and b is defined as
Sample Problem
[a, b] = [x/ a £ x and x £ b].
1. For a, b Î a lattice (P, £ ), prove a £ b; Clearly any closed interval is a chain.
Ûa* b= a
EBD_7203
S2-36 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Complete lattice. converse is not true.
A lattice is complete if each of its non-empty subsets has a least • In a bounded distributive lattice, elements which have
upper bound and a greatest lower bound. complements form a sublattice.
Every finite lattice is complete. Sublattice.
BOUNDS Let <L, *, Å > be a lattices and S Í L.
The least and greatest elements of lattice are called bounds, and Then <S, *, Å > is a sublattices of <L, *, Å > iff S is closed under
denoted by 0 and 1. operations * and Å.
Complement. Homomorphisn.
In a bounded lattice (L, *, Å, 0, 1), if a * b = 0 and a Å b = 1, then Let < L, *, Å > and < S, Ù, Ú > be two lattices.
b is called complement of a. A mapping g : L ® S is called Homomorphism if for any a, b Î L
If b is complement of a, then a is complement of b. g (a * b) = g(a) Ù g(b)
Consider lattice shown in the figure. g (a Å b) = g(a) Ú g(b)
5 Boolean Expression and Boolean Functions
Let B = {0, 1}. The variable x is called a Boolean variable if it
4
assume values only from B. A functon Bn, the set {(x1, x2, ..., xn)}
: xi Î B,
2 1 £ i £ n} to B is called a Boolean function of degree n. The
3 values of a Boolean function are often displayed in tables.
1 Identities of Boolean Algebra
5 = (1) = greatest element
1. Commutative laws
1 = (0) = least element
a Ú b= bÚa
In that lattice, 2 has two complements 4 and 3.
a Ù b= bÙa
0 and 1 are complement.
2. Associative laws
Complemented lattice.
a Ú (b Ú c) = (a Ú b) Ú c
A lattice (L, *, Å, 0, 1), is called complemented if every element a
a Ù (b Ù c) = (a Ù b) Ù c
of L has atleast one ocmplement b
3. Distributive laws
(i.e. a * b = 0 and a Å b = 1).
a Ù (b Ú c) = (a Ù b) Ú (a Ù c),
3 = (1) a Ú (b Ù c) = (a Ú b) Ù (a Ú c)
4. Identity laws
2 aÚ0=0Úa=a
aÙ1=1Ùa=a
1 = (0) 5. Complement laws
Fig. Lattice but not complemented a Ú a' = 1, a Ù a' = 0
e..g. consider a chain of 3 elements show in the figure. 6. Idempotent laws
Here 2 * 3 = 2 ¹ (0) = least element a Ú a = a, a Ù a = a
Distributive lattice. 7. Null laws
A lattice is distributive if a Ú 1 = 1, a Ù 0 = 0
8. De-Morgan's laws
a * (b Å c) = (a * b) * (a * c)
(a Ú b)' = a' Ù b'
and a Å (b * c) = (c Å b) * (a Å c)
(a Ù b)' = a' Ú b'
5 5 9. Absorption laws
a Ú (a Ù b) = a, a Ù (a Ú b) = a
4
10. Involution laws
2 3 4 (a' )' = a
2
Duality
3 The dual of a Boolean expression is obtained by interchanging
1 1
e.g. Boolean sums and Boolean products and interchanging 0’s and 1’s.
• Every chain is a distributive lattice. e.g., The dual of x Ù (y Ú 0) is x Ú (y Ù 1)
• Cancellation law can be stated as in a distributive lattice. Principle of Duality
(a * b = a * c) Ù (a Å b = a Å c) Þ b = c The dual of a Boolean function f represented by a Boolean
Modular lattice. expression in the function represented by the dual of this
A lattice is modular if a £ c, then a Å (b * c) = (a Å b) * c expression. This dual function, denoted by Fd, does not depend
• We can show every distributive lattice is modular but the upon the particular Boolean expression used to represent F. An
SET THEORY & ALGEBRA S2-37
identity between function represented by Boolean expressions Conjunctive Normal Form
remains valid when the duals of both sides of the identity are 1. If a Boolean function f (x1, x2, ...., xn) is expressed in the
taken. This result is called the duality principle. form of factors and each factor is the sum of all the
Boolean Algebra (Definition) n-variables, then such a function is called a conjunctive
By a Boolean algebra we mean a system consisting of non-empty normal form or maxterm normal form or dual canonical form.
set B together with two binary operations Ù and Ú and a unary 2. If a conjunctive normal of a function of n variables contains
operation satisfying the following properties for all x, y, z Î B : all the 2n distinct factors, then such a function is called a
}
complete conjunctive normal form.
x Ú 0 = x Identity laws
1. x Ù1 = x 3. Complement funciton of a conjunctive normal form function
}
f is a Boolean function which is the product of all those
x Ú x' = 1
2. x Ù x' = 0 Domination laws terms of complete conjunctive normal form which are not
present in conjunctive normal form of f.
3. (x Ú y) Ù z) = x Ù (y Ù z) }
(x Ú y) Ú z = x Ú (y Ú z) Associative laws
Switching Circuits
4. xÙy = yÙx }
x Ú y = y Ú x Commutative laws 1. A switching network is an arrangement of wires and
switches (or gates) which connect two terminals. A switch
5.
x Ú (y Ù z) = (x Ú y) Ù (x Ú z)
}
x Ù (y Ú z) = (x Ù y) Ú (x Ù z) Distributive laws
can be either closed or open. A closed switch permits and
an open switch stops flow of current.
Boolean Algebra Homomorphism 2. If P denotes a switch, then P' denotes the switch which is
If (A, +, .,', 0, 1) and (B, Ù, Ú, –, 0', 1') are two Boolean algebras, a open when P is closed and P' is closed when P is open.
function h : A ® B is called a Boolean algebra homomorphism if 3. Two switches P1 and P2 are either connected in series
h preserves the two binary operation and the unary operations (represented by Ù) or connected in parallel (represented by Ù).
in the following since, for all a, b Î A
(a) h(a + b) = h(a) Ú h(b)
(b) h(a × b) = h(a) Ù h(b) P1 P2
(c) h (a' ) = h' (a)
A Boolean homomorphism h : A ® B is a Boolean isomorphism if P1 and P2 in series : P1 Ù P2
h is one-to-one onto B. (i)
Minimal Boolean Function
P1
A minimal Boolean function in n variables is the product of x 1, x2,
....., xn. It is also called minterm.
If x, y are two variables and x', y' are their complementary variables
respectively, then x Ú y, x' Ú y', x' Ú y, x Ú y', x Ù y', x' Ú y' are each
a minimal Boolean functions. P2
P1 and P2 in parallel : P1 Ú P2
Disjunctive Normal Form
1. A Boolean function which can be expressed as sum of (ii)
minimal Boolean functions is called a Disjunctive normal If B [0, 1] is non-empty set and Ù, Ú, / are the operation on
form or minterm normal form or canonical form. B, then the system [ {0, 1}, Ù, Ú, / ] is usually called Boolean
switching algebra.
2. If the number of distinct terms is a Disjunctive normal form
of Boolean function in ‘n’ variables are 2n, then it is called 4. Simplification of circuits : The simplification of switching
a complete disjunctive normal form. circuits is equivalent to simplification of the corresponding
Boolean function.
3. Complement function of a disjunctive normal form function
f is the sum of all those terms of a complete disjunctive
normal form which are not disjunctive normal form of f.
EBD_7203
S2-38 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Let P, Q, R be three atomic propositional assertions. Let X 8. The following is the Hasse diagram of the poset [{a, b, c, d,
denotes (P Ú Q) ® R and Y denotes (P ® R) Ú (Q ® R). e} £ 1]. The poset is [2006, 2marks]
Which one of the following is tautology? [2005, 2 marks]
a
(a) X º Y (b) X ®Y
(c) Y ® X (d) ØY ® X
2. The set {1, 2, 4, 7, 8, 11, 13, 14} is a group under multiplica-
tion modulo 15. The inverses of 4 and 7 are respectively b e d
[2005, 1 mark]
(a) 3 and 13 (b) 2 and 11
(c) 4 and 13 (d) 8 and 14 [{a, b, c, d, e}£ 1]
c
3. Let A, B and C be non-empty sets and let X = (A – B) – C and
Y = (A – C) – (B – C) [2005, 1 mark] (a) not a lattice
Which one of the following is true? (b) a lattice but not a distributive lattice
(a) X = Y (b) X Ì Y (c) a distributive lattice but not a Boolean algebra
(d) a Boolean algebra
(c) Y Ì X (d) None of these
9. Let A, B and C be non-empty set and let X= (A – B) – C and
4. A relation R is defined an ordered pair of integers as follows
Y = (A – C) – (B – C). Which one of the following is true?
(x, y) R (u, v), if x < u and y < v. The, R is [2006, 1 mark] (a) X = Y (b) X Ì Y [2006, 2marks]
(a) neither a Partial Order nor an Equivalence Relation (c) Y Ì X (d) None of these
(b) a Partial Order but not a Total Order 10. The set {1, 2, 3, 5, 7, 8, 9} under multiplication modulo 10 is
(c) a Total Order not a group. Given below are four possible reasons. Which
one of them is false? [2006, 1mark]
(d) an equivalence Relation
(a) It is not closed
5. Let S = {1, 2, 3, ...., m}, m > 3. Lt X1,..., Xn be subsets of S (b) 2 does not have an inverse
each of size 3. Define a function f from S to the set of natural (c) 3 does not have an inverse
numbers as, f (i) is the number of sets Xj that contain the (d) 8 does not have an inverse
11. Let X, Y, Z be sets of sizes x, y and z respectively. Let
m W = X × Y and E be the set of all subsets of W. The number
element i. i.e., f(i) = {j|i ÎXi}, then å f (i) is of functions from Z to E is [2006, 1mark]
i =1
(a) z (b) z × 2xy
(a) 3m (b) 3n [2006, 1 mark] (c) z2 (d) 2xyz
(c) 2m + 1 (d) 2n + 1 12. Let S be a set of n elements. The number of ordered pairs in
the largest and the smallest equivalence relations on S are
6. Let E, F and G be finite sets. Let X = (E Ç F) – (F Ç G) and Y
[[2007, 1mark]
= (E – (E Ç G) – E – F). Which one of the following is true? (a) n and n 2
(b) n and n
(a) X Ì Y (b) X É Y [2006, 2marks] (c) n and 0 (d) n and 1
(c) X = Y (d) X – Y ¹ f and Y – X ¹ f 13. If P, Q, R are subsets of the universal set U, then
7. The set {1, 2, 4, 7, 8 ,11, 13, 14} is a group under multiplication (P Ç Q Ç R) È (Pc Ç Q Ç R) È Qc È Rc is [2008, 1mark]
(a) Qc È Rc
modulo 15. The inverse of 4 and 7. are respectively
(b) P È Qc È Rc
(a) 3 and 13 (b) 2 and 11[2006, 2marks]
(c) Pc È Qc È Rc
(c) 4 and 13 (d) 8 and 14 (d) U
SET THEORY & ALGEBRA S2-39
14. Consider the binary relation R = {(x, y), (x, z), (z, x), (z, y)} on 21. Which one of the following Boolean expressions is NOT a
the set {x, y, z} which one of the following is true? tautology? [2014, Set-2, 2 Marks]
(a) ((a ® b) Ù (b ® c) )® (a ® c)
(a) R is symmetric but not anti-symmetric[2009, 1mark]
(b) (a « c) ® ( ~ b ® (a Ù c))
(b) R is not symmetric but anti-symmetric (c) (a Ù b Ù c) ® ( c Ú a)
(c) R is both symmetric and anti-symmetric (d) a ® (b ® a)
(d) R is neither symmetric nor anti-symmetric 22. Consider the following relation on subsets of the set S of
15. Which one of the following is not necessarily a property of integers between 1 and 2014. For two distinct subsets U
and V of S we say U < V if the minimum element in the
a group? [2009, 1mark] symmetric difference of the two sets is in U.
(a) Commutativity Consider the following two statements:
(b) Associativity S1: There is a subset of S that is larger than every other
(c) Existence of inverse for every element subset.
(d) Existence of identity S2: There is a subset of S that is smaller than every other
subset.
16. What is the possible number of reflexive relations on a set Which one of the following is CORRECT?
of 5 elements? [2010, 1 mark] [2014, Set-2, 2 Marks]
10 15
(a) 2 (b) 2 (a) Both S1 and S2 are true
(c) 2 20
(d) 225 (b) S1 is true and S2 is false
(c) S2 is true and S1 is false
17. Consider the set S = {1, w, w2}, where w and w2 are cube
(d) Neither S1 nor S2 is true
roots of unity. If * denotes the multiplication operation, the 23. Let X and Y be finite sets and f : X ® Y be a function. Which
structure {S, *} forms [2010, 1 mark] one of the following statements is TRUE?
(a) a group (b) a ring [2014, Set-3, 1 Mark]
(c) an integral domain (d) a field (a) For any subsets A and B of X, |f (A È B)| = |f (A)| + |f (B)|
(b) For any subsets A and B of X, f (A Ç B) = f (A) Ç f (B)
18. A binary operation Å on a set of integers is defined as (c) For any subsets A and B of X, |f (A Ç B)| = min {|f (A)|,
|f (B)|}
x Å y = x2 + y2. Which one of the following statements
(d) For any subsets S and T of Y, f –1 (S Ç T) = f –1 (S) Ç f –1 (T)
is true about Å ? [2013, 1 Mark] 24. If V1 and V2 are 4-dimensional subspaces of a 6-dimensional
(a) Commutative but not associative vector space V, then the smallest possible dimension of
(b) Both commutative and associative V1 Ç V2 is ______. [2014, Set-3, 1 Mark]
(c) Associative but not commutative 25. Consider the set of all functions f : {0, 1, ..., 2014} ® {0, 1, ...,
(d) Neither commutative nor associative 2014} such that f (f (i)) = i, for all 0 £ i £ 2014. Consider the
19. Let S denote the set of all functions f: {0, 1}4 ® {0,1}. following statements:
P. For each such function it must be the case that for
Denote by N the number of functions from S to the set
every i, f (i) = i.
{0,1}. The value of log2 log2 N is ________ . Q. For each such function it must be the case that for
[2014, Set-1, 2 Marks] some i, f (i) = i.
20. A pennant is a sequence of numbers, each number being 1 R. Each such function must be onto.
or 2. An n-pennant is a sequence of numbers with sum Which one of the following is CORRECT?
equal to n. For example, (1, 1, 2) is a 4-pennant. The set of all [2014, Set-3, 2 Marks]
(a) P, Q and R are true
possible 1-pennants is {(1)}, the set of all possible
(b) Only Q and R are true
2-pennants is {(2), (1,1)}and the set of all 3-pennants is (c) Only P and Q are true
{(2,1), (1,1,1), (1,2)}. Note that the pennant (1,2) is not the (d) Only R is true
same as the pennant (2,1). The number of 10-pennants is
______________. [2014, Set-1, 2 Marks]
EBD_7203
S2-40 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. If aN = {ax : x Î N} and bN Ç cN = dN, where b, c Î N are 8. The relation “ congruence modulo m” on the set I of all
relatively prime, then integers is
(a) d = bc (b) c = bd (a) an equivalence relation
(c) b = cd (d) None of these (b) a partial order relation
2. Let A¢ and B are two sets in a universal set U. Then (c) reflexive and symmetric
(a) A – B = A¢ – B¢ (d) reflexive and antisymmetric
(b) A – (A – B) = A Ç B 9. Assume R and S are (non-empty) relations in a set A. Which
(c) A – B = A¢ Ç B¢ of the following relation given below is false
(d) A È B = (A – B) È (B–A) È (A Ç B) (a) If R and S are transitive, then R È S is transitive.
3. A market research group conducted a survey of 1000 (b) If R and S are transitive, then R Ç S is transitive.
consumers and reported that 720 consumers liked product A (c) If R and S are symmetric, then R È S is symmetric.
and 450 consumers liked product B. What is the least number
(d) If R and S are reflexive, Then R Ç S is reflexive.
that must have liked both products ?
10. If S = {1, 2, 3, 4, 5,} and R = {(x, y) : x + y < 6} then n (R) =
(a) 170 (b) 280
(a) 8 (b) 10
(c) 220 (d) None of these
(c) 6 (d) 5
4. At a certain conference of 100 people, there are 29 Indian
women and 23 Indian men. Of these Indian people 4 are 11. For the following relation
doctors and 24 are either men or doctors. There are no foreign R = {(0, 0), (0, 1), (1, 1), (2, 1), (2, 2), (2, 0), (1, 0), (0, 2), (0, 1)}
doctors. How many foreigners and women doctors are (a) domain = {0, 1} (b) range = {0, 1, 2}
attending the conference? (c) both correct (d) none of these
(a) 48, 1 (b) 34, 3 12. One of the partitions of the set {1, 2, 5 x, y, 2 , 3 } is
(c) 46, 4 (d) 42, 2
5. Each student in a class of 40, studies at least one of the (a) {{1, 2, x}, {x, 5, y}, { 2 , 3 }}
subjects English, Mathematics and Economics. 16 study
(b) {{1,2, 2 }, {x,y, 2 }, { 5, 2 , 3 }}
English, 22 Economics and 26 Mathematics, 5 study English
and Economics, 14 Mathematics and Economics and 2 study (c) {{1, 2}, {5, x}, { 2 , 3 }}
all the three subjects. The number of students who study (d) {{1, 2, 5}, {x, y}, { 2 , 3 }}
English and Mathematics but not Economics is
13. Let R = {(2, 3), (3, 4)} be relation defined on the set of natural
(a) 7 (b) 5
numbers. The minimum number of ordered pairs required to
(c) 10 (d) 4
be added in R so that enlarged relation becomes an
6. A survey of 500 television viewers produced the following
equivalence relation is :
information, 285 watch football, 195 watch hockey, 115 watch
(a) 3 (b) 5
basket-ball, 45 watch football and basket ball, 70 watch
(c) 7 (d) 9
football and hockey, 50 watch hockey and basket ball, 50 do
14. Total number of equivalence relations defined in the set
not watch any of the three games. The number of viewers,
S = {a, b, c } is :
who watch exactly one of the three games are
(a) 5 (b) 3!
(a) 325 (b) 310 3
(c) 2 (d) 33
(c) 405 (d) 372
15. Let R be a relation in the set of real numbers defined as a
7. Let S be the set of all points in a plane. Let R be a relation on
S such that for any two points a and b, aRb iff b is within 1cm 1
R b iff | a – b | ³ . Then the relation R is:
from a . R is 2
(a) Equivalence relation (a) an equivalence relation
(b) Reflexive and symmetric not transitive (b) reflexive and symmetric but not transitive
(c) Reflexive and transitive not symmetric (c) symmetric and transitive but not reflexive
(d) Symmetric and transitive not reflexive (d) symmetric but neither reflexive nor transitive
SET THEORY & ALGEBRA S2-41
(b) {x Î R : f ( x ) g ( x ) = 0} ì 1 ü
A = í( x , y) : y = , x ¹ 0, x Î R ý
î x þ
(c) {x Î R : (f (x) ) + (g (x) ) = 0}
2 2
{
\ P Ç Q = x Î R : (f ( x ))2 + (g( x ))2 = 0 } where
1
= -x
17. (a) f'(x) = 2 + cosx > 0 "x Î R . Also f(x) tends to ¥ as x
x ® ¥ and f ( x ) ® -¥ as x ® -¥ . Thus f(x) is one- Þ x 2 = -1 .
one and onto. Which has no real solution. So, the curves do not intersect.
\A ÇB =f [see figure also]
p -1 p 1 é 1 1ù
18. (a) - 6 £ sin ( 2 x ) £ 2 Þ - 2 £ 2 x £ 1 Þ x Î ê- 4 , 2 ú 23. (b) Q {x} Î [0, 1)
ë û
\ sin{x} Î [0, sin 1) but f(x) is defined if sin{x} ¹ 0
1 æ 7ù
19. (c) f ( x ) = 1 + Þ Range = ç1, ú . 1 æ 1 ö é 1 ù
æ 1ö
2
3 è 3û \ sin{ x} Î ç sin 1 , ¥ ÷ \ ê sin{x} ú Î {1, 2, 3,....}
çx + ÷ + è ø ë û
è 2ø 4
1 px
24. (a) 3x + 3 – [3x + 3] has the period and sin has the
ax + d 3 2
20. (c) f ( x ) =
cx + b 2p
æ ax + d ö period p i.e 4. therefore, the period of f(x) is
aç ÷+d 2
cx + b ø a 2 x + ad + cd x + bd
f (f ( x ) ) = è =
æ ax + d ö cax + cd + bcx + b 2 1
cç ÷+ b L.C.M. ( , 4) = 4
è cx + b ø 3
25. (c) Let x + y = a and x – y = b
a 2 x + ad + cdx + bd
f(f(x)) = x Þ =x a+b a -b
cax + cd + bcx + b 2 x= and y = \ f ( x + y, x - y) = xy
2 2
Þ c(a + b) x 2 - (a 2 - b 2 )x - (a + b) d = 0 a + b a - b a 2 - b2
Þ f (a , b) = . =
Þ (a + b) (cx 2 - (a - b)x - d ) = 0 Þ a + b = 0 2 2 4
x 2 - y2 y2 - x 2
As cx 2 - (a - b)x - d ¹ 0 for all x \ f ( x, y) = and f ( y, x ) =
4 4
ALTERNATE : \ Arithmetic mean of f(x, y) and f (y, x) is zero.
Since f(f(x) = x for all x we may choose a particular value
of x, say x = 0. 26. (a) Since f ( x + y) = f ( x ) + f ( y) - xy - 1, " x, y Î R
\ f ( x + 1) = f ( x ) + f (1) - x - 1 [ Putting y = 1]
ædö
aç ÷ + d Þ f (x + 1) = f (x) - x [Q f (1) = 1]
d af (0) + d b (a + b ) d
f (0) = , f [f (0)] = = è ø =
b cf (0) + b ædö 2 \ f (n + 1) = f (n ) - n < f (n) Þ f (n + 1) < f (n )
c ç ÷ + b cd + b
èbø So, f (n) < f (n -1) < f (n - 2).... < f (3) < f (2) < f (1) = 1
\ f (n ) = n holds only for n = 1
=0 Þ a+b =0
4 Combinatorics
FUNDAMENTAL PRINCIPLES OF COUNTING ænö
by çç ÷÷ .
1. Principle of Addition : If an event can occur in 'm' ways and èrø
another event can occur in 'n' ways independent of the first
event, then either of the two events can occur in (m + n) IMPORTANT RESULTS
ways. n
1. P0 = 1, n Pn = n!; n
C 0 = 1, n
Cn = 1
2. Principle of Multiplication : If an operation can be
performed in 'm' ways and after it has been performed in any n
2. Pr = r! n C r
one of these ways, a second operation can be performed in
'n' ways, then the two operations in succession can be 3. n
Pr = r.n -1 Pr -1 + n -1Pr = n. n -1Pr -1
performed is (m × n) ways.
4. If r £ s £ n , then nPs is divisible by nPr.
Sample Problem
1. In a class there are 10 boys and 8 girls. The class teacher n n n -1
5. Cr = C r -1 that is, r. n C r = n . n -1C r -1 and
wants to select a student for monitor of the class. In how r
many ways the class teacher can make this selection ?
n n +1
Sol. The teacher can select a student for monitor in two exclusive Cr C r +1
=
ways r +1 n +1
(i) Select a boy among 10 boys, which can be done in 10 n -1
ways
6. n. C r -1 = (n - r + 1) n C r -1
OR 7. n
C r -1 + n C r = n +1
Cr
(ii) Select a girl among 8 girls, which can be done in 8 ways.
Hence, by the fundamental principle of addition, either a 8. n
Cr = n
C n -r
boy or a girl can be selected in 10 + 8 = 18 ways.
n
2. In a class there are 10 boys and 8 girls. The teacher wants to 9. C x = n C y Û x = y or x + y = n
select a boy and a girl to represent the class in a function. In
how many ways can the teacher make this selection? 10. n
C 0 + n C1 + n C 2 + ..... + n C n = 2 n
Sol. The teacher has to perform two jobs :
(i) To select a boy among 10 boys, which can be done in 11. n
C 0 + n C 2 + ..... = n
C1 + n C3 + ........= 2 n -1
10 ways.
2 n +1
(ii) To select a girl, among 8 girls, which can be done in 8 12. C 0 + 2 n + 1 C 1 + ..... 2 n + 1C n = 2 2n
ways. Sample Problem
Hence, the required number of ways = 10 × 8 = 80.
1. If nPr = nPr + 1 and nCr = nCr – 1, then the values of n and r
NOTATIONS are
(a) 4, 3 (b) 3, 2
The Factorial : The continued product of first 'n' natural numbers
(c) 4, 2 (d) None of these
is called the "n factorial" and is denoted by n! or | n Sol. (b) We have, nPr = nPr + 1
Thus, n! = n ( n - 1)(n - 2)......... .......... 4. 3. 2.1 n! n! 1
Þ = Þ =1
Obviously, n! = n ( n - 1)! = n ( n - 1)( n - 2)! = .......... etc. ( n - r ) ! ( n - r - 1) ! (n - r)
Generally, "zero factorial" is defined as 1, i.e., 0! = 1. or n – r = 1 ...(1)
The factorials of fractions and negative integers are not defined. Also, nCr = nCr – 1 Þ r + r – 1 = n Þ 2r – n = 1 ...(2)
nP and nC : If n Î N and 'r' is an integer such that 0 £ r £ n , Solving (1) and (2), we get r = 2 and n = 3
r r
2. The number of positive terms in the sequence
then we define the following symbols :
n+3
n! 195 P3
(i) P(n, r) or nPr = xn = - , n Î N is
n n +1
( n - r )! 4 Pn Pn + 1
n! (a) 2 (b) 3
(ii) C(n, r) or nCr = r!( n - r )! . The symbol nCr is also deonoted (c) 4 (d) None of these
EBD_7203
S2-48 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
n+3 Having filled the first place, there remain 'n – 1' things so the
195 P3
Sol. (c) We have, xn = - second place can be filled in (n – 1) ways.
n +1
4.n Pn Pn + 1
Hence, first two places can be filled in n (n – 1) ways.
195 (n + 3) (n + 2) (n + 1)
= – After filling the first two places there are 'n – 2' objects left with
4.n! (n + 1)! to fill the third place, and so on.
195 (n + 3) (n + 2) 195 - 4n 2 - 20n - 24 Hence, the number of ways of filling 'r' places with 'n' things
= – =
4.n! n! 4.n ! n!
= n( n - 1)(n - 2)....(n - r + 1) ways = ways = n Pr ways.
171- 4n 2 - 20n [ n - r ]!
=
4.n ! The above formula for nPr involves following conditions :
19 9
Now x n > 0 Þ - < n < Þ n £ 4 1. All the things are distinct.
2 2
2. Repetition of things is not allowed in any of the
METHODS OF SAMPLING
arrangements.
Suppose {x1, x2, ....., xn} is a set of 'n' distinct objects from which 3. No arrangement is repeated.
we want to take a sample of r (1 £ r £ n ) objects. To complete 4. The arrangement is linear.
the problem we need the following specifications to be clearly RESULT - 2 : The number of permutations of 'n' things taken
stated : all at a time.
1. Is the order in which we take the sample important or not. This will be given by above formula after taking r = n.
2. Is the repetition of the objects allowed or not. Thus, required number of ways = nPn = n!
If the order is important, then we say that the sample consists of RESULT - 3 : To find the number of permutations of 'n' things
ARRANGEMENTS. If the order is not important, we have taken all at a time, when 'p' are alike of one kind, 'q' are alike
SELECTIONS. If repetition is allowed we have REPLACEMENT. of Second, 'r' alike of Third, and so on :
Thus, our sampling process can be divided into following forms : Let 'x' be the required number of permutations.
1. The order is IMPORTANT and the repetition is ALLOWED, If p alike things are replaced by p distinct things, which are also
each sample is then a SEQUENCE. different from others, then without changing the positions of
other things these new p-things can be arranged in p! ways.
2. The order is IMPORTANT and the repetition is NOT
ALLOWED, each sample is then a PERMUTATION. Each of 'x' permutations will give p! permutations. Thus the total
number of permutations now are x (p!)
3. The order is NOT IMPORTANT and repetition is
ALLOWED, each sample is then a MULTISET. With a similar argument for 'q' - alike and 'r' - alike things, we get
that if all things are different the number of permutations would
4. The order is NOT IMPORTANT and repetition is NOT
be x(p!) (q!) (r!)
ALLOWED, each sample is then a COMBINATION.
But number of permutations of 'n' distinct things; taken all at a
Let us take out two objects from the set {a, b, c}. The
following situations arise as per above theory : n!
time = nPn = n!, thus, ( x) p! q! r! = n! Þ x =
p! q! r!
[1] SEQUENCE [2] PERMUTATION [3] MULTISET [4] COMBINATION
functions from a set with m elements to one with n elements. = å a r (az) = A(az)
r
r =0
2. How many bit strings of length nine either start with 1 bit B(z) = A(az)
or end with the two bits 00 ? e.g., The generating function of the numeric function
Sol. Procedure can be divided into two tasks. 1
ar = 1, r ³ 0 is A(z) =
First task is constructing a bit string of length nine 1- z
beginning with a 1 bit. This can be done in 4. Let A(z) be the generating function of a. Then, z1 A(z) is the
28 ways = 256 ways. generating function of Sia for any positive integer i.
5. Let A(z) be the generating function of a. Then,
Second task of constructing a bit string of length nine z–i[A(z) – a0 – a1z – a2z2 – ...–ai–1 zi–1]
ending with two bits 00. This can be done in is the generating function of S–i a.
27 = 128 ways. e.g., The generating function of ar = 3r+2, z ³ 0 is
From this we have to remove the number of ways of æ 1 ö æ 9z 2 ö 9
A( z ) = z -2 ç - 1 - 3z ÷ = z -2 ç ÷÷ =
choosing 1 in the first bit and corresponding 00 in the last è 1 - 3z ç
ø è 1 - 3z ø 1 - 3z
two bits. This can be done in 6. For b = Da, the generating function is given by
26 ways = 64 ways.
1
Therefore, total number of bit string of length nine that B(z) = [A(z) - a 0 ] - A(z)
z
can be constructed, that begin with 1 and end with a 00, in
and for b = Ñ a
256 + 128 – 64 = 320 ways. B(z) = A(z) – z A(z)
EBD_7203
S2-52 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
7. Let C = a*b, i.e., C is the convolution of two numeric A homogeneous solution of a linear difference equation with
functions and its generating function constant coefficients is of the form Aa 1r , where a1 is called a
C (z) = A(z) · B(z) characteristic root and A is a constant determined by the bounded
Cr = a 0br + a1br -1 + a 2b r - 2 + ... + a r -1b1 + a r b0 conditions. Consider a recurrence relation in the form
is the coefficient of zr in the product of C0 a r + C1a r -1 + C2 a r - 2 + ... + ..Ck a r -k = 0 ...(i)
Since, right hand side of Eq. (i) is set to zero, we substitute Aar
(a 0 + a1z + a 2 z 2 + ... + a r z r + ...)(b0 + b1z + b 2z 2 + ... + b r z r + ...)
for ar. Eq. (i) become
RECURRENCE RELATIONS C0 Aa r + C1Aa r -1 + C2Aa r - 2 + .. + Ck Aa r -k = 0
A recurrence relation for the sequence {ar} is an equations that
expresses ar in terms of one or more of the previous terms of the Aa r -k [C0a k + C1a k -1 + C2a k -2 + ... + Ck ] = 0
sequence.
C0a k + C1a k -1 + C2a k -2 + ... + Ck = 0 ...(ii)
A sequence is called a solution of a recurrence if its terms satisfy
the recurrence relation. Eq. (ii) is called characteristic equation. The solutions of this
e.g., The recurrence relation ar = ar–1 + 3 with initial condition equaiton are called the characteristic roots of the recurrence
a1 = 2 defines the sequence {2, 5, 8, 11...}. relation.
Order of recurrence relation : The order of a recurrence relation A characteristic equation of kth degree has k characteristics
(or difference equation) is the difference between the largest and roots. Two cases of the roots may arise.
smallest subscript appearing in the relation. (i) If roots are distinct and real. Then
e.g., ar = ar–1 + ar–2 is a recurrence relation of order 2. a (h) r r r
r = A1a1 + A 2 a 2 + ... + A k a k
Degree of the recurrence relation : The degree of a recurrence
relation is the highest power of a r occuring in that relations. (ii) If the roots are multiple roots. Let a1 be a root of
multiplying m, then
Example a 3r + 3a r2-1 + 6a r4-2 + 4a r -3 is a recurrence relation of
degree 3. (A1r m-1 + A 2r m- 2 + ... + A m-1r + A m )a1r
Linear recurrence relation with constant coefficients : A is a homogeneous solution.
recurrence relation of the form. Note : Although, there is no question asked in past GATE exams
C0 a r + C1a r -1 + C2 a r -2 + C3arr -3 + ... + Ck a r -k = f (r) ...(i) from this chapter still, reading of this chapter would be
helpful in future GATE exams.
Where, Ci’s are constants is called a linear recurrence relation
with constant coefficients of kth order, provided C0 and Ck both
are non-zero. f(r) is the function of the independent variable ‘r’
only.
e.g., 3ar + 6ar–1 = 2r is the first order linear recurrence relation
with constant coefficients.
A recurrence relation is said to be linear if it's degree is one.
Homogeneous Solution of the Recurrence Relation
COMBINATORICS S2-53
1. Each of the nine words in the sentence ”The quick brown 2. There are two elements x, y in a group (G, *) such that every
fox jumps over the lazy dog” is written on a separate piece element in the group can be written as a product of some
of paper. These nine pieces of paper are kept in a box. One number of x’s and y’s in some order. It is known that
of the pieces is drawn at random from the box. The expected x*x=y*y= x*y*x *y=y*x*y*x=e
length of the word drawn is _____________. (The answer where e is the identity element. The maximum number of
should be rounded to one decimal place.) elements in such a group is __________.
[2014, Set-2, 1 Mark] [2014, Set-3, 2 Marks]
1. Given five different green dyes, four different blue dyes 6. A five digit number divisible by 3 is to be formed using the
and three different red dyes. The number of combinations numerals 0, 1, 2, 3, 4 and 5, without repetition. The total
of dyes which can be chosen, taking at least one green and number of ways this can be done is
one blue dye, is (a) 216 (b) 240
(a) 3240 (b) 3570 (c) 600 (d) 3125
(c) 3720 (d) 3880 7. A person writes letters to six friends and addresses the
2. Six persons A, B, C, D, E and F are to be seated at a circular corresponding envelopes. Let x be the number of ways so
table. The number of ways, this can be done if A must have that at least two of the letters are in wrong envelopes and
either B or C on his right and B must have either C or D on y be the number of ways so that all the letters are in wrong
his right is envelopes. Then x – y =
(a) 36 (b) 12 (a) 719 (b) 265
(c) 24 (d) 18 (c) 454 (d) None
8. In a chess tournament, where the participants were to play
3. Given five line segments of length 2, 3, 4, 5, 6 units. Then
one game with another, two chess players fell ill, having
the number of triangles that can be formed by joining these
played 3 games each. If the total number of games played
lines is
is 84, the number of participants at the beginning was
(a) 5C3 – 3 (b) 5C3 – 1 (a) 15 (b) 16
(c) 5C3 (d) 5C3 – 2 (c) 20 (d) 21
4. A teaparty is arranged for 16 people along two sides of a 9. The number of ways in which 52 cards can be divided into
large table with 8 chairs on each side. Four men want to sit 4 sets, three of them having 17 cards each and the fourth
on one particular side and two on the other side. The number one having just one card
of ways in which they can be seated is
52! 52 !
6! 8!10! 8! 8!10! (a) 3 (b)
(a) (b) (17 !) (17 !) 3 3!
4! 6! 4! 6!
51! 51!
8! 8! 6! (c) 3 (d)
(c) (d) None of these (17 !) (17 !) 3 3!
6! 4!
10. The number of ways in which a mixed doubles game in
5. Ten different letters of an alphabet are given, words with tennis can be arranged from 5 married couples, if no
five letters are formed from these given letters. Then the husband and wife play in the same game, is
number of words which have at least one letter repeated is (a) 46 (b) 54
(a) 69760 (b) 30240 (c) 60 (d) None of these
(c) 99784 (d) None of these
EBD_7203
S2-54 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
11. A contest consists of predicting the results (win, draw or 17. The solution of the recurrence relation
defeat) of 10 football matches. Then the number of ways in ar + 6ar–1 + 12ar–2+ 8ar –3 = 0 is
which one entry contains at least 5 correct answers is :
(a) ar = (A1r + A2r + 2A3r3) (2)r
5 4
(a) 310 - å 10 C r 2 r
r =1
(b) 310 – å 10 Cr 210-r (b) ar = (A1 + A2r2 + A3r3) (3)r
(c) ar = (A1 + A2r + A3r2) (–2)r
r=0
5 10 (d) None of the above
10 10
(c) å Cr (d) å C r 3r
r =1 r=6 18. Solution of recurrence relation
12. A shop keeper sells three varieties of perfumes and he has ar – 5ar–1 + 8ar–2 – 4ar–3 = 0 is
a large number of bottles of the same size of each variety in
(a) ar = A1 (1)r + (A2 + A3r) (2)r
this stock. There are 5 places in a row in his show case. The
(b) ar = A1(1)r + (A2 + A3 r (2)r
number of different ways of displaying the three varieties
of perfumes in the show case is (c) ar = A1(2)r + A2 + A3r(1)r
(a) 6 (b) 50 (d) None of these
(c) 150 (d) None of these 19. The generating function for the sequence 0, 1, 2, 4, 8,.... is
13. All the words that can be formed using alphabets A, H, L,
U and R are written as in a dictionary (no alphabet is 2z 1 + 3z
(a) (b)
repeated). Rank of the word RAHUL is 1 + z2 1 + 8z
(a) 71 (b) 72
(c) 73 (d) 74 z2 +1 z
14. In a test there were n questions. In the test 2n – i students (c) 2 (d)
z –1 1 + 2z
gave wrong answers to i questtions i = 1, 2, 3, ........n. If the
total number of wrong answers given is 2047 then n is 20. The number n of ways that an organization consisting of
(a) 12 (b) 11 twenty-six members can elect a president, treasurer, and
(c) 10 (d) None of these secretary (assuming no person is elected to more than one
position) is
15. At certain college, the housing office has decided to
(a) 15600 (b) 15400
appoint, for each floor, one male and one female residential
(c) 15200 (d) 15000
advisor. The pairs of advisors can be selected for a seven
21. Number n of license plates that can be made where each
story building from 12 male and 15 female candidates are
plate contains two distinct letters followed by three different
(a) 40000 (b) 5096520 digits is
(c) 568400 (d) 70000 (a) 486000 (b) 468000
16. The generating function for the sequence 2, 2, 2, 2, 2, 2 is (c) 498000 (d) 489000
22. Suppose a license plate contains two letters followed by
z2 + 1 18( z –1) three digits with the first digit not zero. How many different
(a) (b) license plates can be printed?
( z –1) z2 + 1
(a) 608000 (b) 608200
(c) 608400 (d) 608600
2( z 5 –1)
(c) (d) None of these
( z –1)
COMBINATORICS S2-55
PAST GATE QUESTIONS EXERCISE way = 3 ! = 6, where three persons A,B,C together are
treated as single.
1. 3.8 to 3.9
For ABD, C, E, F, the number of ways = 6. For AC, BD,
words are : THE, QUICK, BROWN, FOX, JUMPS, OVER,
E,F the number of ways = 6.
THE, LAZY, DOG.
Let x = length of word. Hence, total number of ways = 18.
Length of words THE, FOX, THE, DOG is 3 3. (a) We know that in any triangle the sum of two sides is
Length of words OVER, LAZY is 4 always greater than the third side.
Length of words QUICK, BROWN, JUMPS = 5 \ The triangle will not be formed if we select segments
x Probabilities of length (2, 3, 5), (2, 3, 6) or (2, 4, 6).
3 4/9 Hence no. of triangles formed = 5C3 – 3.
4 2/9 4. (b) There are 8 chairs on each side of the table. Let the
5 3/9 sides be represented by A and B. Let four persons sit
on side A, then number of ways of arranging 4 persons
Expected length of word = S x p (x)
on 8 chairs on side A = 8P4 and then two persons sit
æ 4ö æ 2ö æ 3ö on side B. The number of ways of arranging 2 persons
= 3 çè ÷ø + 4 çè ÷ø + 5 çè ÷ø on 8 chairs on side B = 8P2 and the remaining 10
9 9 9
persons can be arranged in remaining 10 chairs in 10!
= 3.88 ways.
2. 4 Hence the total number of ways in which the persons
x × x = e Þ x is its own inverse can be arranged
y × y = e Þ y is its own inverse
(x × y) × (x × y) = e Þ (x × y) is its own inverse 8! 8!10!
(y × x) × (y × x) = e Þ (y × x) is its own inverse = 8P4 × 8P2 × 10! =
4! 6!
also x × x × e = e × e can be rewritten as follows
x × y × y × x = e × y × y × e = e [Q y × y = e] 5. (a) Total number of words that can be formed = 105 .
(x × y) × (y × x) = e Number of words in which no letter is repeated = 10P5.
Therefore elements of such group are {x, y, e, x X y} So, number of words in which at least one letter is
repeated = 105 – 10P5 = 69760.
PRACTICE EXERCISE
1. (c) Out of 5 different green dyes, one or more can be 6. (a) If a number is divisible by 3, the sum of the digits in it
chosen in must be a multiple of 3. The sum of the given six
numerals is 0 + 1 + 2 + 3 + 4 + 5 = 15. So to make a five
5
C1 + 5C2 + 5C3 + 5C4 + 5C5 = 25 -1 = 32 -1 = 31 ways digit number divisible by 3, we can either exclude 0 or
Out of 4 different blue dyes one or more can be chosen 3. If 0 is left out, then 5! = 120 number of ways are
in possible. If 3 is left out, then the number of ways of
4 making a five digit numbers is 4 × 4! = 96, because 0
C1 + 4 C 2 + 4 C3 + 4 C 4 = 2 4 - 1 = 16 - 1 = 15 ways
cannot be placed in the first place from left, as it will
Out of 3 different red dyes, none, one or more than give a number of four digits.
one can be chosen in
Hence, total number = 120 + 96 = 216.
3
C0 + 3 C1 + 3C 2 + 3 C3 = 23 = 8 ways . 7. (c) If all the letters are not in the right envelopes, then at
least two letters must be in wrong envelopes.
Hence number of combinations of the dyes under the
\ x = 6! – 1 = 719.
given condition = 31 × 15 × 8 = 3720.
Now y = number of ways so that all the letters are in
2. (d) When A has B or C to his right we have the order : wrong envelopes
AB or AC ...(1)
When B has C or D to his right, we have the order : ì 1 1 1 1 1 1ü
= 6! í1 - 1! + 2! - 3! + 4! - 5! + 6!ý
BC or BD ...(2) î þ
Taking these two possibilities together, we must have [Deragement formula]
ABC or ABD or AC and BD. = 360 – 120 + 30 – 6 + 1 = 265
For ABC, D, E, F to arrange along a circle, number of \ x – y = 454
EBD_7203
S2-56 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
8. (a) Let there be n participants in the beginning. Then the n
number of games played by (n – 2) players
n – 2C \ n - 2 C + 6 = 84
14. (b) å 2n -i = 2047
= 2 2 i =1
(Two players played three games each) Þ 2n – 1 + 2n – 2 + 2n – 3 +.......+ 2 + 1 = 2047
Þ n -2 C 2 = 78 2n - 1
Þ = 2047 Þ n = 11
Þ (n - 2)(n - 3) = 156 2 -1
15. (b) From 12 male candidates, 7 candidates can be selected
Þ n 2 - 5n - 150 = 0 Þ n = 15 . in 12C7 ways. From 15 female candidates, 7 candidates
9. (b) Here we have to divide 52 cards into 4 sets, three of can be selected in 15C7 ways. Therefore, the total
them having 17 cards each and the fourth one having
just one card. First we divide 52 cards into two groups number of possible pairs of advisors of the required
type is
52!
of 1 card and 51 cards, this can be done in 1! 51! ways. 12 12! 15!
C7 ´ 15 C7 = ´
Now every group of 51 cards can be divided into 3 7!5! 7!8!
= 792 × 6435
51! = 5096520
groups of 17 each in .
(17 !) 3 3! 16. (c) ar = 2, 2,2, 2, 2
Hence the required number of ways
2( z 5 –1)
52! 51! 52! A( z ) =
= . = ( z –1)
1! 51! (17 !) 3 3! (17 !) 3 3!
17. (c) The characteristic equation is
10. (c) Let the sides of the game be A and B. Given 5 married a3 – 6a2 + 12a + 8 = 0
couples, i.e., 5 husbands and 5 wives. Now, 2 a = – 2, – 2, – 2
husbands for two sides A and B can be selected out The solution of the recurrence relation is
of 5 = 5C2 = 10 ways. ar = (A1 + A2r + A3r2) (–2)r
After choosing the two husbands their wives are to 18. (a) The characteristic equation to the given recurrence
be excluded (since no husband and wife play in the relation is
same game). So we have to choose 2 wives out of a3 – 5a2 + 8a – 4 = 0
remaining 5 – 2 = 3 wives i.e., 3C2 = 3 ways. (a –1) (a – 2)2 = 0
Again two wives can interchange their sides A and B
a = 1, 2, 2
in 2! = 2 ways.
and the solution is
By the principle of multiplication, the required number
ar = A1 (1)r + (A2 + A3r)2r.
of ways = 10 × 3 × 2 = 60
11. (b) Total number of possible predictions = 310 19. (d) A(z) = 0 + z – 2z2 + 4z3 – 8z4 + ...
No. of predictions which have r wrong and 10 – r = z (1 – 2z + 4z2 – 8z3 + ....) = z (1 + 2z)–1
correct entries = 10Cr 210 – r z
= ,| 2 z |< 1
4 1 + 2z
\ Desired no. of ways = 310 – å 10C r 210-r 20. (a) The president can be elected in twenty-six different
ways; following this, the treasurer can be elected in
r =0
[Note that above no. of ways is also equal to twenty-five different ways (since the person chosen
5
president is not eligible to be treasurer); and following
å 10C r 2 r] this, the secretary can be elected in twenty-four
different ways.
r= 0
Thus, by above principle of counting, there are n = 26
12. (c) Number of ways of displaying without restriction × 25 × 24 = 15 600 different ways in which the
= 35 organization can elect the officers.
Number of ways in which all places are occupied by 21. (b) n = 26 × 25 × 10 × 9 × 8
single variety = 3 × 1 = 468000.
Number of ways in which all places are occupied by
i.e. there are twenty-six choices for the first letter, but
two different varieties = 3C2 [25 – 2]
only twenty-five choices for the second letter which
[Q There are two ways when all places will be occupied
by single variety each.] must be different from the first letter. Similarly, choices
\ No. of way of displaying all three varieties for the digits are 10,9 and 8 since the digits must be
= 35 – 3 – 3C2 (25 – 2) = 150 distinct.
13. (d) No. of words starting with A are 4 ! = 24 22. (c) Each letter can be printed in twenty-six different ways,
No. of words starting with H are 4 ! = 24 the first digit in nine ways and each of the other two
No. of words starting with L are 4 ! = 24 digits in ten ways.
These account for 72 words Hence 26 × 26 × 9 × 10 × 10 = 608400 different plates
Next word is RAHLU and the 74th word RAHUL. can be printed.
5 Graph Theory
PATHS, CONNECTIVITY
SPANNING TREES AND CONNECT OR PROBLEMS
Path and its length in a graph (multigraph) G : A path a 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
and edges of the form. of G if vertex set of H is same as the vertex set of G. Similarly, a
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.
where each edge ei is incident on vertices vi–1 and vi. The number Theorem.
of edges, n is called length of a. When there is no ambiguity, we A graph G is connected if it has a spanning tree.
denote a by its sequence of edges, a = (e1, e2, ... en), or by its
sequence of vertices a = (vo, v1, ..., vn).
Simple path and trail in a graph (multigraph) G.
A path a = (v0, v1, ..., vn) is simple if all the vertices are distinct.
The path is a trail if all the edges are distinct. K4
Closed path and a cycle in a graph (multigraph) G.
A path a = (v0, v1, ..., vn) is closed if v0 = vn, i.e. if origin (a) = end Cayley's theorem
(a). The path a is a cycle if it is closed and if all vertices are The complete graph Kn has nn–2 different spanning trees.
distinct except v0 = vn. A cycle of length k is called k-cycle. A Spanning trees of K4 :
cycle in a graph must therefore have length three or more. Since, here, n = 4, so, there will be 4 4–2 = 16 spanning trees.
A weighted graph is a graph G in which each edge e has been
BRIDGE OR CUT EDGE
assigned a real number w(e), called weight of e.
On removing an edge from a graph, the number of connected
If H is a subgraph of a weighted graph, weight w(H) of H is sum
components of the graph either remains unchanged or it increases
of the weights w(e1) + ......+ w(ek), where [e1,.........., ek] is set of
by exactly 1. So, an edge e of a graph G is called bridge or cut
edge, if the subgraph G=e has more connected components than edges of H.
G has. Since many optimisation problems could be solved by using
Theorem 1 : weighted graphs, hence try to find a subgraph of the weighted
Let e be an edge of the graph G and, as usual let G-e be the graph, with minimum (or maximum) weight.
subgraph obtained by deleting e. Now look at a connected spanning subgraph of G which should
not have a cycle, i.e. look at a spanning tree of G and finally look
Then w(G) £ w(G - e) £ w(G) + 1
for a spanning tree with minimum weights, such a tree is called
where w(a) is number of connected components of G. minimal spanning tree or an optimal tree for G.
Theorem 2 : Thus there are two algorithms for finding such a tree. A necessary
An edge e of a grpah G is a bridge if e is not a part of any cycle condition for these algorithms is that no weights should be
in G. negative.
Theorem 3 :
Let G be a graph with n vertices, and q edges and, let w(G)
denote number of connected components of G. Then G has
at least n-w(G) edges, i.e. q ³ n-w(G)
Corollary : A graph with n vertices less than (n – 1) edges can not
be connected. Fig. spanning trees for k 4
Theorem 4 :
Kruskal’s Algorithm
Let G be a graph with n vertices, then following three statements
are equivalent. In this algorithm, choose an edge of G which has smallest weight
I. G is tree among the edges of G which are not loops. This algorithm gives
an acyclic subgraph T of G and theorem given below proves that
II. G is an acyclic graph with (n – 1) edges.
T is a minimal spanning tree of G.
III. G is a connected graph with (n – 1) edges.
EBD_7203
S2-58 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Following steps are required. Greedy Algorithms :
Step 1 : Choose e1, an edge of G, such that weight of e1, w(e1) is Kruskal’s algorithm is an example of a type of algorithm known
as small as possible and e1 is not a loop. as Greedy. Greedy algorithms are essentially algorithms that
Step 2 : If edges e1, e2, .... ei have been chosen, then choose an proceed by selecting the choice that looks best at the moment.
edge ei+1 not already chosen, such that All processes cannot be handled so simply.
(i) induced subgraph G [(e1,.....ei+1)] is acyclic, and Prim’s Algorithm :
(ii) w(ei+1) is as small as possible. Another algorithm used for finding a minimal spanning tree is
Step 3 : If G has n vertices, stop after n-1 edges have been chosen. Prim’s algorithm. It chooses a vertex first and chooses and edge
Otherwise repeat step 2. with smallest weight incident on that vertex.
Theorem : The algorithm involves following steps.
Let G be a weighted connected graph in which weights of the Step 1 : Choose any vertex v1 of G.
edges are all non-negative numbers. Step 2 : Choose an edge e1=v1v2 of G such that v2 ¹ v1 and e1
Let T be a subgraph of G obtained by Kruskal's algorithm. Then has smallest weight among the edges of G incident with
T is a minimal spanning tree of G. v1 .
Sample Problem Step 3 : If edges e1, e2, ......., ei have been chosen involving end
Given below is a weighted graph G with 5 vertices. Apply points v1, v2, .....vi + 1. Choose an edge vi+1 = vjvk with
Kruskal’s Algorithm to determine a minimal spanning tree. vj Î {vi ..........vi + 1} and vk Ï [v1, ....... vi + 1] such that
v1 ei + 1 has smallest weight among the edges of G with
3 4 precisely one end in [v1, ......... vi + 1].
v5 3 3 Step 4 : Stop after n – 1 edges have been chosen. Otherwise go
v2
3 1
to step 3.
2 2 Theorem :
Let G be a weighted connected graph in which weights of the
v4 3 v3
edges are all non-negative numbers. Let T be a subgraph of G
Sol. According to step 1, choose, e = v2v4 as it has minimum
obtained by Prim’s algorithm. Then T is a minimal spanning tree
weight.
v1 v1
of G.
3 4 3 4 Sample Problem
3 3 3 3
v5 v2 v5 v2 Find minimal spanning tree of the weighted graph in
3 3
previous example using Prim’s algorithm.
2 1 2 2 1 2 Sol.
v1
v4 3 v3 v4 3 v3 4
3
Choose e = v2v3 v5 3 3 v2
v1 v1 3
3 4 3 4 2 1 2
v5 3 3 v5 3 3
v2 v2
3 3 v4 3 v3
2 1 2
v2
3
2 v4 3 v3
1
2 Now, we look on to the weights,
v4
w(v1, v2) = 4, w(v1,v4) = 3, w(v1, v5) = 3, w(v3; v2) = 2,
v3 w (v3, v4) = 3
GRAPH THEORY S2-59
Since minimum is w(v3, v2), we choose, e = v3, v2 Theorem :
Let G be a graph with n vertices, when n ³ 2. Then G has at least
v1
two vertices which are not cut vertices.
3 4
3 3
If a connected graph G has a cut vertex v, then connectness of G
v5 v2
3 is vulnerable at v. Let G be a simple graph. The connectivity of G,
denoted by k(G), is the smallest number of vertices in G whose
2 1 2
deletion from G leaves either a disconnected graph or k1.
v4 3 v3 k(kn) = n – 1.
Connected graph has
Again, w(v2, v5) = 3, w(v2, v4) = 1 and w(v3, v4) = 3. k(G) = 1, iff either G = k2 or G has a cut vertex.
We choose e = v2, v4 k(G) = 0, iff either G = k1 or G is disconnected.
v1
3 4
v5 3 3 u
v2
3
2 1 2
v
v4 3 v3
G–V
(a) (b) p3 p4
a3
(a) G1 : (b) G2 :
a4 p3
p1 p1 p2 p3
(c) p2 p4 (d)
(c) G3 : (d)
p3 p4
6. Which one of the following is true for any simple connected
undirected graph with more than 2 vertices?
2. Let G be a simple connected planar graph with 13 vertices [2009, 2 marks]
(a) No two vertices have the same degree
and 19 edges. Then, the number of faces in the planar
(b) Atleast two vertices have the same degree
embedding of the graph is [2006, 1 mark] (c) Atleast three vertices have the same degree
(a) 0 (b) 8 (d) All vertices have the same degree
(c) 9 (d) 13 7. What is the chromatic number of an n-vertex simple
3. Let G be a simple connected planar graph with 13 vertices connected graph which does not contain any odd length
and 19 edges. Then, the number of faces in the planar cycle? Assume n ³ 2 [2009, 2 marks]
embedding of the graph is [2006, 1 mark] (a) 2 (b) 3
(a) 0 (b) 8 (c) n – 1 (d) n
(c) 9 (d) 13 8. Let G = (V, E) be a graph. Define x (G) = å id ´ d, where id
4. Consider the DAG with V = {1, 2, 3, 4, 5, 6}, shown below: d
[2007, 1 mark] is the number of vertices of degree d in G. If S and T are two
2 5 different trees with x(S) = x(T), then [2010, 1 mark]
(a) |S| = 2|T| (b) |S| = |T| –1
(c) |S| = |T| (d) |S| = |T| +1
9. In a binary tree with n nodes, every node has an odd number
1 4 of descendants. Every node is considered to be its own
descendent. What is the number of nodes in the tree that
have exactly one child? [2010, 2 marks]
6 (a) 0 (b) 1
3
n–2
Which of the following is not a topological ordering? (c) (d) n –1
2
(a) 1 2 3 4 5 6 (b) 1 3 2 4 5 6
10. K4 and Q3 are graphs with the following structure
(c) 1 3 2 4 6 5 (d) 3 2 4 1 6 5
5. Consider the set S = {a, b, c, d}. Consider the following 4
partitions p1 , p2 , p3 , p4 on S : p1 = {abcd } ,
2 1 2 1
(c) (d) 2 2
2 1
12. Let G be a complete undirected graph on 6 vertices. If vertices 1 1
of G are labeled, then the number of distinct cycles of length
2 2
4 in G is equal to [2012, 2 marks]
(a) 15 (b) 30 17. A cycle on n vertices is isomorphic to its complement. The
(c) 90 (d) 360 value of n is _____. [2014, Set-2, 2 Marks]
13. Let G be a simple undirected planar graph on 10 vertices 18. Let G be a group with 15 elements. Let L be a subgroup of G.
with 15 edges. If G is a connnected graph, then the number It is known that L ¹ G and that the size of L is at least 4.
of bounded faces in any embedding of G on the plane is
The size of L is __________. [2014, Set-3, 1 Mark]
equal to [2012, 1 mark]
PAST GATE QUESTIONS EXERCISE 4. (d) In topological sorting, the partial ordering of the DAG,
1. (a) From figure (a) 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
DAG but 4 is coming before 1 in 3 2 4 1 6 5 order which
means that 3 2 4 1 6 5 is not a topological order of the
given DAG.
5. (c) A partition P1 is called a refinement of the partitions P2
is every set in P1 is a subset of one of the sets in P2.
Touch each other. p4 is a refinement of p2, p3 and p1.
So, not planar. p2 and p3 are refinements of p1.
p2 and p3 are not comparable since, neither is a
From figure (b)
refinement of the other.
So, the poset diagram for (S¢, <) would be
p1
p2 p3
p4
6. (b) In a simple connected undirected graph (with more
From figure (c) than two vertices) atleast two vertices must have same
degree, since, if this is not true then all vertices would
have different degree. A graph with all vertices would
have different degree. A graph with all vertices having
different degrees is not possible to construct. Notice
that it is possible to construct graph satisfying choices
(a), (c) and (d).
7. (c) If an n-vertex simple contex simple connected graph
contains no cycles of odd length, then its chromatic
From figure (d) number is two, since the vertices cna be alternately
coloured with first colour, then the second colour, then
the first colour and then the second colour and so on.
Alternatively, since a simple connected graph with no
cycles of odd length must be bipartite and since, the
chromatic number of a bipartite graph is always 2 (in a
bipartite graph each partition requires one colour (there
are no edge within a partition of a bipartite graph) and
there are only two partitions).
2. (b) Given, V = 13, E = 19
8. (c) Given, S and T are two different trees with
Let R be the number of regions.
x(S) = x(T)
Applying Euler’s formula, (Here faces and regions
Þ 2|ES| = 2|ET|
mean one and the same).
(By handshaking theorem x(G) = 2|EG|)
R= E – V + 2
Þ |ES| = |ET|
or R = 19 – 13 + 2 = 8
Þ |S| – 1 = |T| – 1
3. (b) Given, V = 13, E = 19
Þ |S| = |T|
Let, R be the number of regions
(In a tree |ES| = |S| – 1 and |ET| = |T| – 1, where |S| and |T|
Applying Euler's formula (Here faces and regions mean
are numbers of vertices of trees S and T respectively).
one and the same)
(i) E¢ = E – V + 2 = 19 – 13 + 2 = 8
GRAPH THEORY S2-65
9. (a) A tree with 1 node is not possible, since it is given that 2
every node has exactly 1 child. 1
1 3
a
4
1
2 2
Consider option (c) :
b Here, the same explanation as above given. This graph
Now, consider a tree with 2 nodes (0 is the root) is also not isomorphic.
Now, a has exactly one child, number of descendants
of a = 2 but this contradicts the given fact that every 1 2
1 3
node has an odd number of descendants.
Now, consider a tree with 3 nodes. Since, every node 3
has exactly one child, it must be of the form. 2
a 2 2
Consider option (d) :
In this graph, there is a 4 length but in the original
b graph, there is no cycle of length 4. So this graph is
not isomorphic.
c 2
2 1
Here, a has 3 descendants, b has 2 descendants and c
has one. Again we have contradiction in that b does 2
not have odd number of descendants. Similarly, we 4
can show that for tree with 4, 5, 6, ... nodes, it is not 1
possible to have all nodes with odd number of 2 2
descendants. So, correct answer is the trees has 0 12. (c) Here, given graph is a complete graph and we can
nodes. choose any 4 vertices from given 6 vertices to make
cycle of length 4.
We can arrange 4 vertices in (4 – 1)! ways or 3! ways
because there is a cycle.
Hence, number of cycles of length
10. (b) Þ 6! 6´5
4 = 6 × 6C4 = 6 ´ = 6´ = 90 cycle
4! 2! 2
K4 is planar
13. (d) In any graph, bounded faces or bounded region and
unbounded regions are present.
For example
Þ 2
1
Q3 is planar
Both K4 and Q3 is planar In the above graph, there are 2 regions, 1 st is bounded
11. (b) The given graph is with degree of each node. region or bounded face graph and 2nd is unbounded.
1 2 So, we have to calculate the regions of the graph.
2 In the question, G is a simple undirected graph on 10
1 vertices and 15 edges and G is connected garph, so
there are total number of regions (r).
4
2 r = e – v + 2, r = 15 – 10 + 2
2 2 r=7
Consider option (a) : \ Total number of regions in the given graph are 7 but
In this graph, one vertex has degree of 3 but in the one extra region is unbounded and 6 are bounded.
original graph, there is no vertex of degree 3. So, this Hence, answer is 6.
graph is not isomorphic.
EBD_7203
S2-66 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
14. (c) P : Number of odd degree vertices is even. G and G1 are complement and isometric to each other when
Q : Sum of degrees of all vertices is even there are 5 vertices.
Q is true 18. 5
Explanation Calculating the sum of degrees of all As per Lagrange’s theorem, order of subgroup divides
vertices. order of group
Considering an edge, it is joining two vertices (not \ 3, 5 and 15 can be order of subgroup.
necessarily distinct), hence 2 is the sum of degrees. Given, L ¹ G \ it is not 15
Hence, for ‘e’ edges, the sum of degrees of all and L is atleast 4 \ it is not 3
vertices is 2e (i.e., even) \ size of L is 5
This is valid even in the case of self loops.
P is true PRACTICE EXERCISE
Explanation Let us assume, number of odd degree 1. (b) Each vertex n is connected to the other n – 1 vertices,
vertices is odd. So, the contribution of odd degree hence deg(n) = n – 1 for every v in Kn.
vertices in total sum is odd. 2. (c) The graphs G* must also have eight connected
Now, the contribution of even degree vertices is also components.
even (whether the number is even or odd). 3. (b)
Including vertex of degree zero in even degree 4. (c) Count the number of edges leaving each vertex to
vertices. obtain
So, total sum becomes odd, which is not possible. deg(P1) = 1, deg(P2) = 3, deg(P3) = 2, deg(P4) = 3,
Hence, P is true. deg(P5) = 3,
\ Both P and Q statements are ture for undirected 5. (a) The vertex n is isolated if it does not belong to any
graphs. Hence answer is (c). edge. Thus n is isolated if and only if deg (n) = 0
15. 36 Consider the multigraph G where
(1) 1, 11 Þ 1 × 11 = 11 edges V(G) = {A, B, C, D} and
(2) 2, 10 Þ 2 × 10 = 20 edges E(G) = [{A, C}, {A, D}, {B, B}, {B, C}, {C, A},
(3) 3, 9 Þ 3 × 9 = 27 edges {C, B}, {D, B}, {D, D}]
(4) 4, 8 Þ 4 × 8 = 32 edges 6. (c) Maximum components will result after removal of a
(5) 5, 7 Þ 5 × 7 = 35 edges node is graph G is a star graph as shown below
(6) 6, 6 Þ 6 × 6 = 36 edges (maximum)
16. 6
a 2
V
2 1 2 1
b or a null graph of n vertices as shown below
c
2 2
1 1 V
2 1
d e
2
2
In either case, if node V is removed, the number of
Edges picked to make MST is given the double line. components will be n – 1, where n is the total number
In the right side of MST, we could either pick ‘d’ or ‘e’ of nodes in the star graph.
In the left side we could either pick ‘a’, ‘b’ or ‘c’ in MST. \ n – 1 is the maximum number of components possible.
There are two options for one edge to be picked and three Minimum component will result, if the node being
option for other edge to be picked. removed is a lone vertex in which case the number of
\ Total possible MSTs = 2 × 3 = 6 components will be k – 1.
17. 5 \ The number of components must necessarily lie
between k – 1 and n – 1.
1
a G b a b
a G b
c c c c
d
d c
d b
6 Linear Algebra
MATRIX 7. Null Matrix
Matrix is a set of numbers written in rows and column. A matrix A matrix with all elements are zero
with m rows and n columns is called m × n matrix. é0 0 0ù
ê0 0 0ú
é a11 a12 K a1n ù Ex. ê ú
êa ú
ê 21 a22 K a2 n ú ëê0 0 0úû
ê M ú 8. Triangular Matrix
ê ú (a) Upper triangular matrix :
ë am1 am 2 K amn û A square matrix with all elements below principal
Types of Matrices diagonal are zero
1. Row Matrix
é 2 3 4ù
A matrix with only one row, m = 1
Ex. ê 0 5 6ú
Ex. [ a b c K] ê ú
êë 0 0 2úû
2. Column Matrix
A matrix with only one column, n = 1 (b) Lower triangular matrix :
A square matrix with all elements above principal
éa ù diagonal are zero
êb ú
é 2 0 0ù
Ex. ê ú ê1 3 0ú
êc ú
ê ú Ex. ê ú
ëM û êë 2 3 4úû
3. Square Matrix 9. Symmetric Matrix
A matrix with same number of rows and column i.e., A square matrix in which aij = aji
m=n éa b c ù
é a1 a2 a3 ù ê ú
Ex. A = êb d e ú
ê ú
Ex. ê b1 b2 b3 ú êë c e f úû
êë c1 c2 c3 úû T
For symmetric matrix, A = A
10. Skew symmetric matrix
4. Diagonal Matrix
A square matrix in which aij = – aji
A matrix with all elements above and below the principal All principal diagonal elements in skew symmetric matrix
diagonal are zero i.e. aij = 0 when i ¹ j are zero.
é a11 0 0 ù é 0 a bù
ê 0 a 0 úú ê- a 0 cú
Ex. ê 22 Ex. A = ê ú
êë 0 0 a33 úû
ëê - b - c 0úû
5. Scalar Matrix In skew symmetric matrix, AT = – A
A matrix with all principal diagonal elements are same. 11. Hermitian Matrix
A square matrix in which aij is the conjugate complex of aji
é 4 0 0ù
ê ú i.e. aij = a ji
Ex. ê 0 4 0ú
êë 0 0 4úû é 5 2 + 3i 4 - 2i ù
ê 2 - 3i 2 5 + 3i úú
6. Unit Matrix Ex. ê
A diagonal matrix will all diagonal elements one êë 4 + 2i 5 - 3i 0 úû
i.e., aij = 1, when i = j and aij = 0 when i ¹ j
a12 = 2 + 3i, a21 conjugate complex of a12 = 2 – 3i
EBD_7203
S2-68 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
12. Skew Hermitian Matrix Multiplication
· Two matrices can be multiplied only if number of columns
A square matrix in which aij = - a ji on first matrix is equal to number of column on second matrix.
Note : Principal diagonal elements of skew hermitian matrix should If, A = m × n B = n × p, then A can be multiplied by B is
be zero or pure imaginary numbers. A × B.
13. Orthogonal Matrix · The final product will be of order m × p.
Orthogonal matrix is a square matrix A such that A.B ¹ B. A
T T
AA = A A = I · A(BC) = (AB)C
14. SINGULAR MATRIX · A(B + C) = AB + AC
A square matrix is a singular matrix if its determinant is · (B + C) A = BA + CA
zero. Otherwise, it is a non-singular matrix. · p(qA) = (pq)A where p, q are scalars:
Example 1 Determine the values of x for which the matrix · (– p)B = p(– B)
· A × I = A = I × A I-unit matrix
é x + 1 -3 4 ù Properties of transpose of a matrix
ê -5 x + 2 2 ú ( AT )T = A
A= ê ú is singular.. T T T
êë 4 1 x - 6úû · (A + B) = A + B
T T
· (pA) = pA
Solution A is a singular matrix if · (AB)T = BTAT(not ATBT)
· AAT = ATA
x +1 -3 4 But for any matrix A; AAT and ATA will be square matrices and
-5 x+2 2 =0 may be of different order.
|A|= 0 Þ
4 1 x-6 Adjoint of a Matrix
é a11 a12 K a1n ù
x+2 2 -5 2 -5 x + 2 êa ú
Þ ( x + 1) 1 - ( -3) +4 =0 ê 21 a22 K a2 n ú
x-6 4 x-6 4 1 For any matrix A , A=
ê M ú
ê ú
Þ ( x + 1){( x + 2)( x - 6) - 2} + 3{-5 x + 30 - 8} ë am1 am 2 K amn û
th
+4{-5 - 4 x - 8} = 0 Minor of any element aij = mij is obtained by deleting the i row
th
and j column and then finding its determinant
Þ ( x + 1)( x 2 - 4 x - 14) + 3(-5 x + 22) + 4( -4 x - 13) = 0 The signal minor (– 1)i+j mij is called w factor.
The matrix obtained by replacing the elements of matrix with the
1 w factors is called matrix of cofactors or cofactor matrix. The
Þ x( x 2 - 3x - 49) = 0 Þ x = 0, x = (3 ± 205)
2 transpose of cofactor matrix is called adjoint of a matrix or adjugate
ORTHOGONALMATRIX of the matrix A denoted by adj (A).
A square matrix A is called an orthogonal matrix if AAT = ATA = I é A11 A 21 K A n1 ù
If A is an orthogonal matrix, then ê ú
A A 22 K A n2 ú
AAT = 1 adj (A) = ê 12
T T
Þ |AA | = |I| Þ |A| |A | = |I| ê ú
2 ê M ú
Þ |A| = 1 Þ |A| = ± 1. êë A1m A 2m K A nm úû
This, every orthogonal matrix is non-singular. Consequently
every orthogonal matrix is invertible. Sample Problem
TRACE OFAMATRIX Let = [aij]n×n be a square matrix. Then é 2 3ù
the sum of all diagonal elements of A is called the trace of A and is Find adjoint of matrix ê ú
ë 4 5û
denoted by tr (A). Thus,
n é 2 3ù
Sol. A = ê ú
tr (A) = å aii ë 4 5û
i =1
é5 4ù
IDEMPOTENT MATRIX A square matrix A is called an minor of A = ê ú
idempotent matrix if A2 = A. ë3 2û
Properties of Operation on Matrix é 5 - 4ù
Addition cofactor matrix of A = ê ú
· Two matrix can be added only if it has same number of rows ë- 3 2 û
and columns. T
é 5 - 4ù é 5 - 3ù
· Consider two m × n matrices A and B, then: adj. (A) = ê ú =ê ú
A+ B = B +A ë- 3 2 û ë- 4 2 û
LINEAR ALGEBRA S2-69
Inverse of a Matrix Sample Problem
Matrix B is called inverse of matrix A if,
é 1 2 3ù
AB = BA = I I -unit matrix. ê - 2 - 3 - 1ú
–1 Find rank of matrix ê
B is called inverse of matrix A and is denoted by A ú
–1 adj. A ëê 2 3 1 úû
A = Sol. | A | = 1(– 3 + 3) + 2(– 2 + 2) + 3(– 6 + 6) = 0
|A|
\ Rank is less than 3.
SHORT CUT
é 1 2 ù
éa b ù Consider submatrix ê ú whose modulus
For a non singular square matrix ê ú ë - 2 - 3û
ëc d û =– 3+4 =–1
é d -b ù
1 \ Rank of matrix = 2 (since it is a 2 × 2 matrix).
–1
A = ê -c a ú where ad ¹ bc Properties of Rank of Matrix
ëad - bc
û · For a m × n matrix A, p(A) £ m or n whichever is lesser.
Sample Problem · Rank of unit matrix of order n, In = n i.e. p(Ii) = n
· p(A) = p(AT)
é 2 3ù ·
Find inverse of matrix ê ú p(AB) £ p(A), p(B) i.e., rank of product of two matrices A, B
ë 4 5û cannot exceed of each matrix.
· Similarly, rank of sum of two matrices cannot exceed sum of
é 5 - 3ù their rank.
Sol. adj. (A) = ê ú
ë- 4 2 û p (A + B) £ p(A) + p(B)
|A | = 5 × 2 – 4 × 3 ECHELON MATRIX
= 10 – 12 = – 2 A matrix is said to be echelon marix if :
(1) Leading entry of each non zero row is 1
é 5 - 3ù (2) The number of zeros preceeding this entry 1 is larger than
ê ú number of proceeding rows.
adj. A ë- 4 2 û
A –1 = =
|A| 2 é0 1 2 3 4ù
ê0 0 0 1 2 úú
é - 5/3 3/2 ù Ex. A = ê
= ê ê0 0 0 0 1ú
ë 2 - 1úû ê ú
ë0 0 0 0 0û
é 2 3 ù é - 5/2 3/2 ù Any matrix A of order m × n can be reduced to echelon matrix by
Check A . A–1 = ê úê
ë 4 5û ë 2 - 1úû row transformation. Row transformation are :
(1) Inter changing of rows (Ri « Rj)
é -5 + 6 3 - 3 ù (2) Multiplying row with a constant (Ri ® kRi)
= ê -10 + 10 6 - 5 ú (3) Addition of k times a row with another row
ë û (Ri ® Ri + kRj)
é1 0 ù Consistency of a Algebraic Equations
= ê ú =I Consider in linear equations of n variables
ë0 1û
a11 x1 + a12 x2 + ... + a1n xn = b1
Properties of Inverse of Matrix
· (A–1)–1 = A a21 x1 + a22 x2 + ... + a2 n xn = b2
–1 –1 –1
· (AB) = B A M
A -1 am1 x1 + am2 x2 + ... + amn xn = bn
· (KA)–1 = K–1A–1 =
K In matrix notation, this can be written as
1 é a11 a12 a13 K a1n ù é x1 ù é b1 ù
· | A–1 | = êa
|A| a22 a23 K a2n ú ê x2 ú ê b2 ú
ê 21 ú ê ú =ê ú
· adj. (AB) = (adj. B) (adj. A) ê M úê M ú êMú
· n–1
| adj. A| = | A | where A is square matrix. ê úê ú ê ú
ë am1 am2 K K amn û ë xn û ëbn û
Rank of a Matrix
For a m × n matrix A, rank of A is non negative integer r such that or AX = B
(i) there is at least one r ×r submatrix of A with a non zero
é a11 a12 K a1n ù é x1 ù é b1 ù
determinant (ii) determinant of all square submatrices of A of êa ú êx ú êb ú
order > r + 1 is zero a22 K a2 n
ê 21 ú; X = ê 2 ú; B = ê 2ú
Rank of matrix A is denoted by p(A) A= ê M ú ê M ú êMú
Note : Rank of zero matrix is zero, all other matrices have rank ³ 1. ê ú ê ú ê ú
ë a m1 am 2 K a mn û ë xn û ë bn û
EBD_7203
S2-70 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
A is called coeff. matrix.
é 1 2 -1 3 ù
é a11 a12 K a1n b1 ù ê 0 -3 2 -4 ú
ê ú ê ú ,R - R
ê a21 a22 K a2 n b2 ú = ê 0 0 4 -2 ú 4 2
Augmented matrix, AB = ê M ú ê ú
ë0 0 0 0 û
ê ú
êë am1 am 2 K amn bn úû \ Rank of (AB) = 3 (no. of non zero rows)
Note : é1 2 -1ù
An equation is said to be homogeneus if b = 0 i.e. of form AX = 0. ê0 - 3 2 ú
ê ú
A system of equations is said to be consistent, if there are one or A = ê0 0 4 ú (first 3 column)
more solution for the equation. ê ú
A system of equations is said to be inconsistent, if there is no ë0 0 0û
solution. When we reduce a matrix A to echelon form it is called \ Rank of A = 3.
argument matrix A*. Number of unknowns = 3 (x, y, z)
If p(A*) = p(A) the equations are consistent
\ Rank (A) = Rank (AB) = no. of unknowns
If p(A*) ¹ p(A) the equations are inconsistent. Hence system is consistent with unique solution
In a homogeneous system of equation (AX = 0),
If p(A) = no. of unknowns (n), it has no solution Solutions of Linear Equations
If p(A) < no of unknown (n), it has infinite solutions. Method-I
Consider an augmented matrix AB which is reduced to echelon In order to find the solution of linear equations, find the rank of
form. augmented matrix (A), p(A) and find number of solutions as
discussed above
If p(A) ¹ p(AB), system is inconsistent
From the reduced augmented matrix, find the reduced equation
If p(A) = p(AB) = no. of unknown (n), system is consistent with
and solve them.
unique solution.
1. The system of equation 5x + 3y + 7z = 4, 3x + 26y + 2z = 9,
If p (A) = p(AB) < number of unknowns (n), system is consistent
7x + 2y + 10z = 5 has
with infinite solutions.
(a) a unique solution
Sample Problem (b) no solution
Find if the system of equation is consistent x – y + z = – 1, (c) an infinite number of solutions
x + 2y + 3z = 1, 2x + y = 2, x + 2y – z = 3. (d) none of these
é 1 -1 1 -1ù 1. (b)
ê1 2 3 1 ú The system Ax = B is consistent (has solution) If r(A) =
Sol. Augmented matrix AB = ê ú t(A:B) Also if
ê2 1 0 2 ú
ê ú r(A) = r(AB) = no. of unknowns, then system has a unique
ë 1 2 -1 3 û solution and if r(A) = r(A:B) < no. of unknowns, then system has
an infinite no. of solution.
é 1 2 -1 3 ù
ê1 2 3 1 ú 5 3 7 : 4
ê ú,R «R
= ê2 1 0 2 ú
4 1 3 26 2 : 9
Now, here [A : B] =
ê ú 7 2 10 : 5
ë 1 -1 1 -1û
é 1 2 -1 3 ù
ê 0 0 4 -2 ú , R 2 - R 1
=ê ú , R - 2R 53 7 : 4
ê 0 -3 2 -4 ú 3 1
æ 3 ö
ê ú , R 4 - R1 121 -11 33 R - R Þ R2
ç 2 5 1 ÷
ë 0 -3 2 -4 û 0
5 5
:
5 ç ÷
= 7
-11 1 -3 ç R3 - R1 Þ R3 ÷
é 1 2 -1 3 ù 0 : è 5 ø
ê 0 -3 2 -4 ú 5 5 5
ê ú,R «R
= ê 0 0 4 -2 ú 2 3
ê ú 5 3 7 : 4
ë 0 -3 2 -4 û 121 -11 33
0 : æ R2 ö
= 5 5 5 çè R2 + Þ R3 ÷
ø
11
0 0 0 : 0
LINEAR ALGEBRA S2-71
Þ r(A) = 2 = r (A:B) 1
i.e. Þ r(A) = r (A:B) = 2 < no. of unknowns (3) · If l is eigen value of an orthogonal matrix, A then is also
l
Thus system has an infinite no. of solutions. its eigen value.
Method-II
Matrix inversion method 1
· If l is eigen value of matrix A, then is eigen value of
For an m × n non singular matrix A, AX = B implies l
–1
–1 –1
X = A B is solution of equation is A B. matrix A .
n n n
· If l1, l2, l3... are eigen values of matrix A, then l1, l2 , l3 ...
–1 adj. A are eigen values of matrix A . n
A =
|A| · Both A and AT will have same eigen values.
–1 –1
Multiply A with B i.e., A B to get solution of equation · Eigen values of triangular matrix is equal to its diagonal
Method-III elements.
Cramer’s rule · Eigen values of real symmetrix matrix are all real.
Let equation be : · Eigen values of skew hermitian matrix are purely imaginary
a11 x1 + a12 y + a13 z = b1 or zero.
a21 x + b22 y + a23 z = b2 |A|
· It l is eigen value of A, then is eigen value of adj. (A).
a31 x + a32 y + a33 z = b3 l
1. The system of equations [2006, 2 marks] 9. If A is a square matrix of order 4, and I is a unit matrix, then
x + 2y + 3z = 4 it is true that [2010, 2 marks]
2x + 3y + 8z = 7 (a) det (2A) = 16 det (A)
x – y + 9z = 1 (b) det (–A) = – det (A)
have (c) det (2A) = 2 det (A)
(a) unique solution (b) no solution (d) det (A + I) = 16 det A + I
(c) infinite solutions (d) none of these
2. Product of two orthogonal matrices is a [2006, 1 mark] é 5 0 2ù
(a) unitary matrix (b) orthogonal matrix 10. A = êê 0 3 0úú . The inverse of A is [2010, 1 mark]
(c) unit matrix (d) none of these
êë 2 0 1 úû
é0 0 1ù
ê 0 1 0ú ,
3. If A = ê ú the A–1 is [2007, 2 marks] é1 0 –2 ù é5 0 2ù
êë1 0 0 úû ê ú ê ú
ê0 1 ê0 – 1 0ú
0ú
(a) ê 3 ú (b) ê 3 ú
é1 0 0ù é0 0 1 ù ê –2 0 5 úû ê2 0 1ú
ë ë û
ê0 1 0ú ê0 1 0ú
(a) ê ú (b) ê ú
êë1 0 0úû êë1 0 0úû
é1 1ù é 1 1ù
ê5 0 0 – ú
2ú ê 5 2
é0 1 0ù ê ú ê ú
ê0 0 1 ú ê0 1 1
0ú ê 0 0 ú
(c) ê ú (d) none of these ê 3 ú ê 3 ú
êë1 0 0úû (c) ê ú (d) ê ú
ê1 0 1ú ê– 1 0 1 ú
ëê 2 ûú ëê 2 ûú
é 2 1– iù
4. If A = ê ú , then A is [2007, 1 mark]
ë1 + i 6 û 11. The system of equations [2011, 2 marks]
(a) skew symmetric (b) symmetric – 2x + y + z = a
(c) skew hermitian (d) hermitian x – 2y + z = b
5. A skew symmetric matrix cannot be of rank[2008, 2 marks] x + y – 2z = c
(a) 0 (b) 1 have no solution if
(c) greater than 1 (d) – 1 (a) a + b + c ¹ 0 (b) a + b + c = 0
(c) a = 1, b = 1, c = – 2 (d) none of these
é1 3 4 ù
ê1 3 5 ú
6. Rank of the martix ê ú is [2008, 1 mark] é 2 –2 –4ù
êë1 3 4 úû ê –1 3 4 ú
12. The martix A = ê ú is [2011, 1 mark]
(a) 0 (b) 1 ëê 1 –2 –3ûú
(c) 2 (d) 3
(a) involutory (b) orthogonal
7. If AB = BA, then AB is a symmetric matrix, if A and B are
(c) nilpotent of index 2 (d) idempotent
[2009, 2 marks]
13. Let A be the 2 × 2 matrix with elements a11 = a12 = a21 = +1
(a) symmetric martix (b) skew symmetric matrix
(c) orthogonal martix (d) none of these and a22 = –1. Then,the eigen values of the matrix A19 are
8. If there exists a non-zero minor of order r, then rank of A is [2012, 1 mark]
[2009, 1 mark] (a) 1024 and – 1024 (b) 1024 2 and -1024 2
(a) equal to r (b)greater than or equal to r
(c) less than r (d) less than or equal to r (c) 4 2 and -4 2 (d) 512 2 and -512 2
LINEAR ALGEBRA S2-73
14. The following system of equations
ép pù
x1 + x2 + 2x3 = 1 where q Î ê , ú and f ¢(q) denote the derivative of f
x1 + 2x2 + 3x3 = 2 ë6 3û
x1 + 4x2 + ax3 = 4 with respect to q. Which of the following statements is/are
has a unique solution. The only possible value (s) for a is/ TRUE?
are
æp pö
(a) 0 (I) There exists q Î ç , ÷ such that f ¢(q) = 0.
(b) either 0 or 1 è6 3ø
(c) one of 0, 1 or –1
æp pö
(d) any real number other than 5 (II) There exists q Î ç , ÷ such that f ¢(q) ¹ 0 .
è6 3ø
[2014, Set-1, 1 Mark]
1 x x2
(a) I only (b) II only
15. Which one of the following does not equal 1 y y2 ? (c) Both I and II (d) Neither I nor II
19. If the matrix A is such that [2014, Set-2, 1 Mark]
1 z z2
é2 ù
[2013, 1 mark] ê -4ú [1 9 5]
A= ê ú
1 x + 1 x2 + 1 êë7 úû
1 x ( x + 1) x + 1
(a) 1 y ( y + 1) y +1 (b) 1 y + 1 y2 + 1 then the determinant of A is equal to _______ .
1 z ( z + 1) z +1 2 20. The product of the non-zero eigenvalues of the matrix
1 z +1 z +1
é1 0 0 0 1ù
0 x – y x2 – y2 2 x + y x2 + y2 ê0
ê 1 1 1 0úú
(c) 0 y–z y2 – z 2 (d) 2 y+z y2 + z2 ê0 1 1 1 0ú
z2 ê ú
1 z 1 z z2 ê0 1 1 1 0ú
16. Consider the following system of equations : êë1 0 0 0 1 úû
3x + 2y = 1
4x + 7z = 1 is ______ . [2014, Set-2, 2 Marks]
x+y+z=3 21. Which one of the following statements is TRUE about every
x – 2y + 7z = 0 n × n matrix with only real eigenvalues?
The number of solutions for this system is ___________ [2014, Set-3, 1 Mark]
[2014, Set-1, 1 Mark] (a) If the trace of the matrix is positive and the determinant
17. The value of the dot product of the eigen vectors of the matrix is negative, at least one of its eigen values
corresponding to any pair of different eigenvalues of a is negative.
4-by-4 symmetric positive definite matrix is (b) If the trace of the matrix is positive, all its eigenvalues
_____________________. [2014, Set-1, 1 Mark] are positive.
18. Let the function (c) If the determinant of the matrix is positive, all its
eigenvalues are positive.
sin q cos q tan q (d) If the product of the trace and determinant of the matrix
is positive, all its eigenvalues are positive.
æ pö æ pö æ pö
f (q) = sin ç ÷ cos ç ÷ tan ç ÷
è 6ø è 6ø è 6ø
æ pö æ pö æ pö
sin ç ÷ cos ç ÷ tan ç ÷
è 3ø è 3ø è 3ø
EBD_7203
S2-74 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
é1 2 3 ù
ê ú é1 3 2ù
15. Find nullity of matrix A = ê 2 5 8 ú . ê –1 1 1 úú
êë 3 7 11úû 22. Find nullity of the matrix A = ê .
ê2 2 1ú
ê ú
(a) 1 (b) 2 ë3 5 2û
(c) 3 (d) 0
(a) 0 (b) 1
16. Consider a non-homogeneous system of linear equation
representing mathematically an over determined system. (c) 2 (d) 3
Such system will be 23. Consider the system of equations
(a) consistent having unique solution A(n × n) X(n × l) = l(n × l), where l is a scalar. Let (li, xi)
(b) consistent having many solutions be an eigen pair of an eigen value and its corresponding
(c) inconsistent having unique solution eigen vector of a real matrix A. Let l be a (n × n) unit
(d) inconsistent having no solution matrix, which one of the following statements is not
correct?
é2 0 0 0ù (a) For a homogeneous n × n system of linear equations,
ê0 0 0 0 úú (A – l I) X = 0 having a non-trivial solution, the rank
17. Find rank of the matrix ê .
ê0 0 –1 0 ú of (A – l I) is less than n
ê ú
ë0 0 0 1û (b) For a matrix Am, m being a positive integer,
(a) 4 (b) 1 (l m m
i , xi ) will be eigen pair for all i
(c) 2 (d) 3
(c) AT = AT, then | li | = 1 for all i
18. If the eigen value of a matrix is 2, 2 and 3. Then
determinant of matrix is (d) AT = A, then li = is real for all i
é1 –1 0 ù
é1 0 0 0ù
ê32 1 0 The inverse of matrix S = ê1 1 1 ú is
0 úú
34.
ê ú
26. Find the determinant of the matrix ê . êë0 0 1 úû
ê 63 60 1 0ú
ê ú
ë52 31 16 1û
é1 0 1 ù é 0 1 1ù
ê0 0 0ú ê –1 –1 1ú
(a) 0 (b) 1 (a) ê ú (b) ê ú
(c) 63 (d) 331 êë0 1 1 úû êë 1 0 1úû
é5 0 2ù –4 –3
(a) (b)
39. If A= ê0 3 0ú . then A–1 is 5 5
ê ú
êë 2 0 1 úû
3 4
(c) (d)
5 5
é1 0 –2 ù é5 0 2ù
ê ú ê ú 44. Consider the following system of equations.
ê0 1 –1
0ú ê0 0ú 2x1 + x2 + x3 = 0 ; x2 – x3 = 0; and x1 + x2 = 0. The system
(a) ê 3 ú (b) ê 3 ú
ê –2 has:
ë 0 5 úû ê2
ë 0 1 úû
(a) unique solution
(b) no solution
é1 1ù é1 –1 ù (c) infinite number of solution
ê5 0 0
2ú ê5 2ú
ê ú ê ú (d) five solution
ê0 1 1
0ú ê0 0ú 45. Choose the correct set of functions which are linearly
ê 3 ú ê 3 ú
(c) ê ú (d) ê ú dependent.
ê1 0 1ú ê –1 0 1ú (a) sin x, sin2x, cos2 x
êë 2 úû êë 2 úû
(b) cos x, sin x, tan x
é 3 2ù (c) cos 2x, sin2x, cos2 x
40. Eigen values of matrix S = ê ú is 5 and 1. The eigen (d) cos 2x, sin x, cos x.
ë 2 3û
values of matrix S2 is
é1 + b b 1ù
(a) 1, 25 (b) 6, 4 ê b 1 + b 1ú
(c) 5, 1 (d) 2, 10 46. The determinant ê ú equal to.
êë 1 2b 1úû
41. Multiplication of matrices E and F is G. Matrices E and G
(a) 0 (b) 2b (b – 1)
é cos q – sin q 0 ù é1 0 0ù
ê ú (c) 2 (1 – b)(1 + 2b) (d) 3b (1 + b)
are E = ê sin q cos q 0 ú and G = ê0 1 0ú . What
ê ú 47. Let A = [aij], 1£ i, j £ n with n ³ 3and aij = i.j. Then the
ëê 0 0 1 úû êë0 0 1úû rank of A is
is matrix F? (a) 0 (b) 1
é cos q – sin q 0 ù é cos q cos q 0ù (c) n – 1 (d) n
ê sin q cos q 0 ú ê – cos q sin q 0ú
(a) ê ú (b) ê ú é –3 2 ù
êë 0 0 1 úû êë 0 0 1 úû 48. If A = ê ú then A satisfies the relation
ë –1 0 û
(a) A + 3 I + 2 A–1 = 0
é cos q sin q 0 ù é sin q – cos q 0ù
ê – sin q cos q 0 ú ê cos q sin q 0ú (b) A2 + 2A + 2I = 0
(c) ê ú (d) ê ú (c) (A + I) (A + 2I) = 0
êë 0 0 1 úû êë 0 0 1 úû
(d) eA = 0
42. The number of linearly independent eigen vectors of 49. The characteristic equation of a 3 × 3 matrix p is defined
as a (l) = |lI – p| = l3 + 2l + l2 + I = 0
é2 1ù
ê 0 2 ú is The inverse of p will be:
ë û (a) p2 + p + 2I (b) p2 + p + I
(a) 0 (b) 1 (c) – (p2 + p + I) (d) – (p2 + p + 2I)
(c) 2 (d) infinite
é –1 3 5ù
é3 4 ù ê –3 –1 6ú
ê 5 5ú 50. The eigen values of the following matrix ê ú
43. For a matrix [M] = ê 3 ú . The transpose of matrix êë 0 0 3úû
x
ë 5û
are.
is equal to the inverse of the matrix, [m]T = [m] –1. The
value of x is given by (a) 3, 3 + 5j, 6 – j (b) – 6 + 5j, 3 + j , 3 – j
(c) 3 + j, 3 – j, 5 + j (d) 3, – 1 + 3j, – 1 – 3j
EBD_7203
S2-78 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
51. The dimension of the null space of the matrix 57. Determine the rank of the following matrices:
é0 1 1ù é0 1 –3 –1ù
ê 1 –1 0 ú é 1 2 3ù ê1 0 1 1 úú
ê ú is ê 1 4 2ú ê
êë –1 0 –1úû (i) ê ú (ii) ê3 1 0 2ú
êë 2 6 5úû ê ú
ë1 1 –2 0 û
(a) 0 (b) 1
(a) 0 (b) 1
(c) 2 (d) 3 (c) 2 (d) 3
58. Investigate the value of l and m so that the equations
é2 –2 ù é x1 ù é 0ù 2x + 3y + 5z = 9, 7x + 3y – 2z = 8, 2x + 3y + lz = m,
52. The equation ê 1 –1úû êë x2 úû
= ê ú has
ë ë 0û have (i) no solution, (ii) a unique solution and (iii) an infinite
number of solutions.
(a) no solution
59. Find the eigen values and eigen vectors of the matrix
(b) only one solution
é5 4ù
(c) non-zero unique solution ê1 2 ú .
ë û
(d) multiple solution
60. Find the eigen values and eigen vectors of the matrix
53. x + 2y + z = 4
2x + y + 2z = 5 é1 1 3ù
ê1 5 1ú .
x–y+z=1 ê ú
êë3 1 1úû
The system of algebraic equations given above has
(a) a unique solution of x = 1, y = 1 and z = 1 61. Find the eigen values and eigen vectors of the matrix
(b) only the two solutions of (x = 1, y = 1, z = 1) and é3 1 4 ù
(x = z1 y = 1, z = 0) A = êê0 2 6 úú
(c) infinite number of solution êë0 0 5 úû
(d) no feasible solution 62. Find eigen values and eigen vectors of the matrix.
é –5 –3ù é1 0 ù é 8 –6 2 ù
54. Given that A = ê ú and I = ê 0 1 ú . The valued A3 A = êê –6 7 –4 úú
ë2 0û ë û
êë 2 –4 3 úû
is
(a) 15 A + 12 I (b) 19 A + 30 I 63. If w cube root of – 1, then find value of
(c) 17 A + 15 I (d) 17 A + 21 I é 1 – w w2 ù
ê ú
é10 – 4 ù ê –w w2 1 ú
55. The eigen values of matrix ê18 –12 ú are ê ú
ë û êë w2 1 – wúû
(a) 4,9 (b) 6, – 8
é 1 3 5 1ù
(c) 4, 8 (d) – 6, 8 ê 2 4 8 0ú
64. Rank of the matrix A = ê ú is
ëê 3 1 7 5ûú
a2 + l2 ab + cl ca – bl l -c b
2 2
(a) 0 (b) 1
56. Evaluate ab – cl b + l bc + al ´ c l -a
(c) 3 (d) 4
ca + bl bc – al c 2 + l 2 -b a l
é 3 –1 –1ù
ê –1 3 –1ú
65. Eigen values of the matrix ê ú are
(a) l 3 ( a 2 + b 2 + c 2 + l 2 )3 (b) l 2 ( a 2 + b 2 + c 2 )3 êë –1 –1 3 úû
(a) 1, 1, 1 (b) 1, 1, 2
(c) l 3 ( a 2 - b 2 - c 2 - l 2 )3 (d) l 2 ( a 2 + b 2 + c 2 - l 2 ) 2
(c) 1, 4, 4 (d) 1, 2, 4
LINEAR ALGEBRA S2-79
66. Eigen values and corresponding eigen vectors of a 2 × 2
matrix are given by é3ù é –3ù
ê –2 ú ê2ú
Eigenvalue Eigenvector (a) ê ú (b) ê ú
ëê 1 ûú ëê –1ûú
é1ù
l1 = 4 v1 = ê ú
ë1û é1ù é5ù
ê –2 ú ê2ú
é1ù (c) ê ú (d) ê ú
l2 = 8 v2 = ê ú êë 3 úû êë 0 úû
ë –1û
The matrix is 70. If product of matrix
é 2 4ù é4 8ù
(c) ê 4 2ú (d) ê 8 4ú é cos 2 f cos f sin f ù
ë û ë û B=ê ú is a null matrix, then q and f
êëcos f sin f sin 2 f úû
67. Eigen vectors of a real symmetric matrix corresponding to
different eigen values are differ by an
(a) orthogonal (b) singular (a) odd multiple of p (b) even multiple of p
(c) non-singular (d) none of these (c) odd multiple of p/2 (d) even multiple of p/2
68. Rank of a 3 × 3 matrix C (= AB), found by multiplying a non- 71. An arbitrary vector X is an eigen vector of the matrix
zero column matrix A of size 3 × 1 and a non-zero row matrix
é1 0 0 ù
B of size 1 × 3, is ê0 a 0ú ,
(a) 0 (b) 1 A= ê ú if (a, b) =
êë 0 0 b úû
(c) 2 (d) 3
(a) (0, 0) (b) (1, 1)
é3 –2 2 ù
ê ú (c) (0,1) (d) (1, 2)
69. For matrix p ê0 –2 1 ú , if one of the eigen values is equal
ëê0 0 1 úû
to –2, then which of the following is an eigen vector?
EBD_7203
S2-80 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
é –2 1 1 : a ù æ é1 - l 1 ùö
[A:B]= êê 1 –2 1 : b úú det ç ê ÷ =0
èë 1 - 1 - l ûú ø
êë 1 1 –2 : c úû
1- l 1
By R1 ® R2 + R3 + R1 =0
1 -1 - l
é0 0 0 a + b + c ù
-1 - l + l + l 2 - 1 = 0
~ êê1 –2 1 b úú
êë1 1 –2 c úû l2 = 2
l =± 2
1
By R 3 ® (R 3 –R 2 ) Eigen values are + 2 and - 2 of A. If A has eigen
3
values l1, l 2 .......l k then An will have eigen values
é0 0 0 a + b + c ù l1n , l 2n ,...l kn .
~ êê1 –2 1 b úú
ê0 1 –1 1 ú \ Eigen values of A19 are ( 2)19 and ( - 2)19 ,
ê (c – b) ú
ë 3 û hence 512 2 and -512 2 .
14. (d) For unique solution,
Hence r (A : B) = 3, If a + b + c ¹ 0
and r (A) = 2. 1 1 2
then r (A : B) ¹ r (A) 1 2 3 ¹0
Hence given equations are inconsistent if
1 4 a
a+b+c¹0
Hence given equations have no solution if Þ 1(2a – 12) – 1 (a – 3) + 2(4 – 2) ¹ 0
(a + b + c) ¹ 0 Þ a¹5
EBD_7203
S2-82 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1 x x2 é3 2 0 1ù
ê4 0 7 1 úú
C ®C + C
15. (a) 1 y y 2 ¾¾¾¾¾®
2 2 1 ê º [A | B]
ê1 1 1 3ú
1 z z2 ê ú
ë1 -2 7 0û
We shall transform this matrix to echelon form as follows
1 x + 1 x2 1 x + 1 x2 + 1 (to find the Rank of Above matrix) :
C ®C + C
1 y + 1 y 2 ¾¾¾¾¾
3 3 1
® 1 y +1 y2 + 1
é3 2 0 1ù
1 z + 1 z2 1 z + 1 z2 + 1 ê4 0 7 1 úú R1 « R 3
ê
ê1 1 1 3ú :
i.e., option (b) ê ú
ë1 -2 7 0û
1 x x2 2 x+ y x2 + y 2
R ®R + R é1 1 1 3ù :
1 y y 2 ¾¾¾¾¾®
1 1 2 2 y+ z y2 + z2 ê4 ú
R2 ® R2 + R3
ê 0 7 1 ú R 2 ® R 2 - 4R1
1 z z2 1 z z2 ê3 2 0 1 ú R 3 ® R 3 - 3R1
ê ú
ë1 -2 7 0 û R 4 ® R 4 - R1
i.e., option (d)
1 x x2 0 x- y x2 - y 2 é1 1 1 3 ù
R ®R - R
ê0 -4 3 -11úú :
1 y y 2 ¾¾¾¾¾®
1 1 2 0 y-z y2 - z2 ê
R2 ® R2 - R3 ê0 ú
-1 -3 -8 R 2 ® -R 2
1 z z2 0 z z2 ê ú
ë0 -3 6 -3 û R 3 ® -R 3
i.e., option (c)
We are able to generate option (b), (c) and (d) from é1 1 1 3ù
given matrix. ê0 4 -3 +1úú
Considering option (a): ê
ê0 1 3 8ú :
ê ú
1 x( x + 1) x +1 ë0 -3 6 -3û R 2 « R 3
C ®C -C
1 y ( y + 1) y + 1 ¾¾¾¾¾
3 3 1
®
1 z ( z + 1) z +1 é1 1 1 3ù
ê0 1 3 8 úú :
ê
1 x2 + x x 1 x2 x ê0 4 -3 11 ú R 3 ® R 3 - 4R 2
ê ú
C ® C -C ë0 -3 6 -3û R 4 ® R 4 + 3R 2
1 y2 + y y ¾¾¾¾¾®
2 2 3
1 y2 y
2 2
1 z +z z 1 z z
é1 1 1 3 ù
ê0 1 3 8 úú
Option (a) is obtained from the given matrix by ê
interchanging column 2 and 3. ê0 0 -15 -21ú :
On interchanging any two columns of a matrix, its ê ú
ë0 0 15 21 û R 4 ® R 4 + R 3
determinant gets multiplied by “– 1”.
1 x x2 é1 1 1 3 ù
1 x ( x + 1) x +1 ê0
ê 1 3 8 úú
\ 1 y y 2 = - 1 y ( y + 1) y +1
ê0 0 -15 -21 ú
1 z z 2 1 z ( z + 1) z +1 ê ú
ë0 0 0 0 û
Hence option (a) is NOT equal to the given matrix. Clearly, Rank (A) = Rank (AB) = 3
16. 1 As number of variables in given system = 3
Representing the Given system in matrix form, the The Given system has unique solution.
Augmented matrix is:
The solution is (x, y, z) = æç - , , ö÷
11 19 7
è 5 5 5ø
LINEAR ALGEBRA S2-83
17. 0 PRACTICE EXERCISE
We know that for a symmetric positive definite matrix the
eigen vectors corresponding to two different eigen values é1 2 3ù
are orthogonal.
1. (b) A = êê1 3 5úú
So, their dot product is equal to zero.
However we must not that the eigen vectors corresponding êë 2 5 8úû
to the same eigen value (occuring more than once) need
not be orthogonal to each other. é1 2 3ù
Above mentioned result is deduced from spectral theorem ê 0 1 2 ú R 2 ® R 2 – R1
of Linear Algebra. ê ú R ® R – 2R
18. (c) Both I and II. êë 0 1 2úû 3 3 1
19. 0
é1 2 3ù
é2 ù é 2 10 18ù ê 0 1 2ú R ® R – R
ê ú ê ú ê ú 3 3 2
A = ê -4ú [1 9 5] = ê -4 -20 36ú
êë 0 0 0 úû
êë 7 úû êë 7 35 63úû
Determinant : 2 [(– 20 × 63) – (35 × 36)] – 10 [(–4 × 63) – (36 \ R(A) = 2.
× 7)] + 18 [(– 4 × 35) – (– 20 × 7)] é 4 2 1 3ù
= – 5040 + 5040 + 0
2. (c) A = ê6 3 4 7 ú
=0 ê ú
20. 6 êë 2 1 0 1úû
é1 0 0 0 1ù R3 ® R1
ê0 1 1 1 0úú
ê é2 1 0 1ù
ê0 1 1 1 0ú = ê6 3 4 7ú
A = ê0 ú ê ú
1 1 1 0ú
ê ëê 4 2 1 3ûú
êë1 0 0 0 1úû
R1
R1 ®
2
é x1 ù
ê ú é 1 1ù
êx2 ú ê1 2 0 2 ú
ê x3 ú
= ê6 3 4 7 ú
X = êx ú ê ú
ê 4ú ê4 2 1 3 ú
êx ú ë û
ë 5û
A l = Xl é 1 1ù
Þ x1 + x5 = lx1 = lx5 & x2 + x3 + x4 = lx2 = lx4 ê1 2 0 2ú
I Case = ê ú R ® R 2 – 6R1
ê0 0 4 4ú 2
l¹0 ê0 0 1 R ® R 3 – 4R1
Let x1 = x5 = a ë 1 úû 3
x2 = x3 = x4 = b
Þ x1 + x5 = lx1 é 1 1ù
Þ 2a = la Þ l = 2 ê0 2 0 2 ú
Þ x2 + x3 + x4 = lx2 = ê0 0 4 4 ú R ® R – 1 R
Þ 3b = lb ê ú 3 3 2
ê0 0 0 0 ú 4
Þl=3 ë û
II Case
l=0 \ Rank = 2.
Þ Eigen value l = 0 3. (d) Rank = number of non-zero elements in diagonal
\ There are three eigen values i.e, 2, 3, 0 \ Rank = 3.
Product of non zero eigen values = 2 × 3 = 6 4–l –2
21. (a) As per property, determinant of a matrix = product 4. (c) Characteristic equation = =0
–2 1–l
of eigen values
If true of matrix is positive and determinant is (4 – l) (1 – l) – 4 = 0
negative, then atleast one of eigen values is \ l = 0, 5.
negative. 5. (b)
EBD_7203
S2-84 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
6. (a) XT Y (3 × 4) and (4 × 3) Þ (3 × 3) 12. (b)
\ (XT Y)–1 Þ (3 × 3) 13. (a) Co-factor of a11 = 3 × 2 – (1 × 6) = 0
P(XT Y)–1 (2 × 3) and (3 × 3) Þ (2 × 3) Co-factor of a22 = 1 × 2 – (5 × 2) = – 8
P(XT Y)–1 PT = (2 × 3) and (3 × 2) Þ (2 × 2) Co-factor of a33 = 1 × 3 – (2 × 2) = – 1.
\ [P(XT Y–1 PT)]T Þ (2 × 2). 14. (b)
é1 1 1 2 ù é1 2 3 ù
7. (b) AB = ê1 2 3 7 ú 15. (a) A = ê2 5 8 ú
ê ú ê ú
êë1 4 7 17ûú ëê 3 7 11úû
é1 1 1 2 ù é 1 2 3ù
ê ú R 2 ® R 2 – R1 ê ú R 2 ® R 2 – 2R1
= ê0 1 2 5 ú = ê 0 1 2ú
R 3 ® R 3 – R1 R 3 ® R 3 – 3R1
ëê 0 3 6 15ûú ëê 0 1 2úû
Rank of A = 2
é1 1 1 2ù Nullity of matrix = number of columns – rank
= ê 0 1 2 5ú R 3 ® R 3 – 3R 2 = 3 – 2 = 1.
ê ú
16. (a) In determined system, number of equations >
ëê 0 0 0 0ûú
number of unknowns.
Rank of (AB) = 2 \ System is consistent with unique solution.
No. of unknowns = 3 17. (d) Use properties:
\ system is consistent with infinite solutions. It is a diagonal matrix. Rank of diagonal matrix is
é1 1 1 1 ù equal to number of non-zero diagonal elements = 3.
18. (b) Determinant of matrix = Product of eigen values
8. (c) AB = ê 2 3 4 1 ú
ê ú = 2 × 2 × 3 = 12.
êë 4 5 6 2úû 19. (d) For singular matrix, |A| = 0
Þ 1(3x – 0) –2(2x – 2) = 0
é1 1 1 1 ù 3x – 4x + 4 = 0
R ® R 2 – 2R1
= ê 0 1 2 –1 ú 2 –x + 4 = 0
ê ú R ® R – 4R x = 4.
êë 0 1 2 – 2 úû 3 3 1
adj A
20. (b) A–1 = .
é1 1 1 1 ù A
= êê 0 1 2 –1úú R 3 ® R 3 – R 2 21. (b)
êë 0 0 0 –1úû é1 3 2ù
Rank of (AB) = 3 ê –1 1 1ú
Rank of A = 2 (first 3 columns) 22. (b) A = ê ú
ê2 2 1ú
\ system has no solution. ê ú
9. (c) Sum of eigen values = sum of diagonal elements = 3 ë3 5 2û
\ either (a) or (c) is correct.
Product of eigen values = determinant of matrix = 0 é1 3 2ù
ê0 R ® R 2 + R1
\ (c) is correct. 4 3 úú 2
10. (d) Sum of eigen values = sum of diagonal elements = ê R ® 2R1 – R 3
ê0 4 3ú 3
é1 2 ù ê ú R ® 3R1 – R 4
11. (c) Let A = ê ë0 4 3û 4
ú
ë4 3û
é1 3 2ù
éa b ù ê0
A= ê ú 4 3 úú R 3 ® R 3 – R 2
ëc d û = ê
ê0 0 0ú R 4 ® R 4 – R 2
By using ê ú
ë0 0 0û
1 é d -b ù
A -1 =
| A | êë - c a úû 1 3
=4¹0
| A | = 3 – 8 = –5 0 4
\ Rank = 2
é -3 2ù
Nullity = number of columns – rank
1 é 3 -2 ù ê4 5ú
A -1 = =ê ú = 3 – 2 = 1.
-5 ë -4 1 ûú ê 4
ê -1 ú 23. (c) For an orthogonal matrix, if l1 is an eigen value then
êë 5 5 úû
LINEAR ALGEBRA S2-85
([ D ] [ F] [ D ]) ( )
T T T
= [D] [ F]T [ D]T x –b x –d
T
27. (c) = ; =
y a y c
= [D] [F] [D]T ([F] is symmetric)
\ it is symmetric. It is consistent iff
1 2 –1 –b –d
=
25. (b) |A| = 1 1 0 a c
4 1 3 Þ ad = bc.
é 2 + 2b b 1ù é1 2 1 4 ù
D = 2 + 2b 1 + b 1ú
ê = ê0 –3 0 –3ú R3 - R2
ê ú ê ú
êë 2 + 2b 2b 1úû êë0 0 0 0 úû
é –5 –3ù
é1 2 3K n ù 54. (b) A=ê ú
ê 2 4 6L 2nú ë2 0û
ê ú
47. (b) A = ê 3 6 9L 3n ú charac. eqn. = l2 + 5l + 6 = 0
ê ú Þ A2 + 5A + 6I = 0
êM M M Mú
êë n 2n 3nL n úû \ A2 = – 5A – 6 I
A3 = – 5A2 – 6 A
A3 = – 5A2 – 6A
P (A) = 1 (Qall rows are propotional) = – 5 (– 5 A – 6 I) – 6A
48. (c) Charac. eqn. = 19 A + 30 I
|A – lI| = 0 55. (b) By property, sum of eigen values equals sum of
–3 – l 2 diagonal elements.
–1 0–l
=0 56. (a) By the rule of multiplication of determinants, the
resulting determinant
l2 – (– 3) l + 2 = 0
l2 + 3l + 2 = 0 d11 d12 d13
Þ A2 + 3A + 2I = 0 D = d 21 d 22 d 23
(A + I) (A + 2I) = 0 d31 d32 d33
49. (d) |lI – P| = 0
l3 + l2 + 2l + I = 0 where d11 = (a2 + l2)l + (ab + cl)c + (ca – bl) (– b)
Þ p3 + p2 + 2p + I = 0 = l (a2 + b2 + c2 + l2)
p (p2 + p + 2) = – I d12 = (a2 + l2) (– c) + (ab + cl) l + (ca – bl)a = 0
p2 + p + 2I = – I P–1 d13 = 0,
= – P–1 d21 = 0, d22 = l(a2 + b2 + c2 + l2), d23 = 0.
\ p = – (p + p + 2I)
–1 2 d31 = 0, d32 = 0, d33 = l(a2 + b2 + c2 + l2).
50. (d) sum of eigen values = sum of diagonal elements Hence
=–1–1+3=1
3 + (– 1 + 3j) + (– 1 – 3j) = 1 l(a2 + b2 + c2 +l2 ) 0 0
51. (b) Dimension of null space = (no. of variables – rank) D= 0 2 2 2
l(a + b + c +l )2
0
= (3 – 2) = 1 0 0 2
l(a + b + c2 +l2 )
2
é 2 –2 ù é x1 ù é0 ù
52. (d) ê 1 –1ú ê x ú = ê 0 ú = l3(a2 + b2 + c2 + l2)3.
ë ûë 2û ë û
EBD_7203
S2-88 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
57. (c) 59. The characteristic equation is [A – lI] = 0
(i) Operate R2 – R1 and R3 – 2R1 so that the given matrix
5–l 4
é1 2 3 ù i.e., = 0 or l2 – 7l + 6 = 0
1 2–l
~ êê 0 2 –1úú = A (say)
or (l – 6) (l – 1) = 0 \ l= 6, 1.
ëê 0 2 –1úû Thus the eigen values are 6 and 1.
Obviously, the 3rd order minor of A vanishes. Also its If x, y be the components of an eigen vector
2nd order minors formed by its 2nd and 3rd rows are all corresponding to the eigen value l, then
é1 3 ù é5 – l 4 ù é xù
zero. But another 2nd order minor is ê ú = –1¹ 0. [A – lI]X = ê =0
ë0 –1û ë 1 2 – l ûú ëê y ûú
\ r (A) = 2. Hence the rank of the given matrix is 2.
(ii) Given matrix é –1 4 ù é x ù
Corresponding to l = 6, we have ê úê ú = 0
é0 1 –3 –1ù é0 1 –3 –1ù ë 1 –4 û ë y û
ê1 0 0 0ú ú ê1 0 0 0 úú which gives only one independent equation – x + 4y = 0
~ê ~ê
ê3 1 –3 –1ú ê3 0 0 0ú x y
ê ú ê ú \ = giving the eigen vector (4, –1).
ë1 1 –3 –1û ë1 0 0 0û 4 –1
[Operating C3 – C1, C4 – C1] [Operating R3 – é 4 4ù é x ù
R1, R4 – R1] Corresponding to l = 1, we have ê1 1 ú ê y ú = 0
ë ûë û
é0 1 –3 –1ù é 0 1 0 0ù
Which gives only one independent equation x + y = 0
ê1 0 0 0 úú êê1 0 0 0 úú
~ê ~ = A (say) x y
ê0 0 0 0 ú ê0 0 0 0ú \ = giving the eigen vector (1, 1)
ê ú ê ú 1 1
ë0 0 0 0 û ë0 0 0 0û
60. The characteristic equation is
[Operating R3 – 3R2, R4 – R2] [Operating C3 +
3C2, C4 + C2] é1– l 1 3 ù
Obviously, the 4th order minor of A is zero. Also every | A – lI |= êê 1 5 – l 1 úú , i.e., l3 – 7l2 + 36 = 0
3rd order minor of A is zero. But, of all the 2nd order
êë 3 1 1– lúû
é 0 1ù
minors, only ê ú = –1 ¹ 0. \ r (A) = 2. Since l = – 2 satisfies it, we can write this equation as
ë1 0û (l + 2) (l2 – 9l + 18) = 0 or (l + 2) (l – 3) (l – 6) = 0.
Hence the rank of the given matrix is 2. Thus the eigen values of A are l = – 2, 3, 6.
é2 3 5 ù é x ù é9 ù If x, y z be the components of an eigen vector
ê 7 3 –2ú ê y ú = ê 8 ú corresponding to the eigen value l, we have
58. We have ê úê ú ê ú
êë 2 3 l úû êë z úû êëm úû é1 – l 1 3 ù é xù
ê
[A – lI]X = ê 1 5–l 1 úú êê y úú = 0
The system admits of unique solution if, and only if, ...(i)
the coefficient matrix is of rank 3. This requires that
ëê 3 1 1– l ûú ëê z ûú
2 3 5
Putting l = – 2, we have 3x + y + 3z = 0, x + 7y + z = 0,
7 3 –2 = 15(5 – l) ¹ 0 3x + y + 3z = 0.
2 3 l The first and third equations being the same, we have
Thus for a unique solution l ¹ 5 and m may have any from the first two
value. If l = 5, the system will have no solution for x y z x y z
those value of m for which the matrices = = or = =
–20 0 20 –1 0 1
é2 3 5 ù Hence the eigen vector is (– 1, 0, 1), Also every non-
é2 3 5 9 ù
A = êê7 3 –2 úú zero multiple of this vector is an eigen vector
and K = êê7 3 –2 8 úú
êë 2 3 5 úû corresponding to l = – 2.
ëê 2 3 5 m ûú Similarly, the eigen vectors corresponding to l = 3 and
are not of the same rank. But A is of rank 2 and K is not l = 6 are the arbitrary non-zero multiples of the vectors
of rank 2 unless m = 9. Thus if l = 5 and m ¹ 9, the (1, – 1,1) and (1, 2, 1) which are obtained from (i).
system will have no solution. Hence the three eigen vectors may be taken as
If l = 5 and m = 9, the system will have an infinite (– 1, 0, 1), (1, – 1, 1), (1, 2, 1).
number of solutions.
LINEAR ALGEBRA S2-89
61. The characteristic equation is These equations determine a single linearly
independent solution which may be taken as (1, 2, 2),
é3 – l 1 4 ù so that every non-zero multiple of this vector is an
ê 0 2–l 6 úú = 0 eigen vector corresponding to l = 0. Similarly,eigen
[A – l I] = 0, i.e., ê vectors corresponding to l = 3 and l = 15 are arbitrary
ëê 0 0 5 – l ûú
non-zero multiples of the vectors (2, 1, – 2) and
(2, – 2, 1) which are obtained from above equation.
or (3 – l) (2 – l) (5 – l) = 0
Hence three vectors may be taken as (1, 2, 2), (2, 1, –2),
Thus the eigen values of A are 2, 3, 5.
(2, – 2, 1)
If x, y, z be the components of an eigen vector 63. Since w is cube root of – 1, therefore
corresponding to the eigen value l, we have w3 = – 1
i.e., w3 + 1 = 0 Þ (w + 1) (w2 – w + 1)
é3–l 1 4 ùé x ù =0
ê
[A – lI]X= ê 0 2 – l 6 úú êê y úú = 0 Hence either w = – 1 or w2 – w + 1 = 0
ëê 0 0 5 – l úû êë z úû
é 1 – w w2 ù
ê ú
Putting l = 2, we have x + y + 4z = 0, 6z = 0, 3z = 0, i.e., A = ê – w w2 1 ú
x + y = 0 and z = 0. Let ê ú
êë w2 1 – wúû
x y z
\ = = = k1 (say) C1 ® C1 + C2 + C3
1 -1 0
Hence the eigen vector corresponding to l = 2 is k1 é 1 – w + w2 – w w2 ù é0 – w w2 ù
(1, –1, 0). ê ú ê ú
A = ê – w + w2 + 1 w2 1 ú = ê0 w2 1 ú
Putting l = 3, we have y + 4z = 0, – y + 6z = 0, 2z = 0, i.e., ê ú ê ú
y = 0, z = 0. êë w2 + 1 – w 1 – wúû ë0 1 – wû
x y z =0 (since 1 – w + w2 = 0)
= = = k2 64. (c) Given matrix A possesses a minor of order 3
1 0 0
Hence the eigen vector corresponding to l = 3 is k2 1 3 1 0 0 1
(1, 0, 0). 2 4 0 = 2 4 0
viz.
Similarly, the eigen vector corresponding to l = 5 is k3 3 1 5 –2 –14 5
(3, 2, 1).
62. Characteristic equation is replacing C1 and C2 by C1 – C3 and C2 – 3C3.
2 4
é8 – l –6 2 ù = expanding with respect to R1
–2 –14
ê
| A – l | ê –6 7 – l 4 úú
= 2 (– 14) – (4) (–2) = – 28 + 8 ¹ 0
êë 2 –4 3 – l úû \ p (A) ³ 3
Also A does not possess any minor of order 4, i.e., 3 + 1
= l3 + 18 l3 – 45l = 0 \ p (A) £ 3 ...(ii)
Þ l (l – 3) (l – 15) = 0 From equation (i) and (ii) we get
\ l = 0, 3, 15 P(A) = 3 i.e., rank of A is 3.
Thus eigen values of A are 0, 3, 15. 65. (c) Characteristic equation is
If x, y, z be the component of an eigen vectors [A – lI] = 0
corresponding to the eigen value l, then
é3 – l –1 –1 ù
ê –1 3 – l –1 ú = 0
é8–l –6 2 ù é xù ê ú
[A – ll ]X= êê –6 7 – l –4 úú êê y úú = 0 ëê –1 –1 3 – l ûú
êë 2 –4 3 – l úû êë z úû Þ (3 – l) {(3 – l)2 – 1} – 1 (3 – l) + 1} – 1 {(3– l) + 1} = 0
Þ {(3 – l) + 1} {(3 – l) {(3 – l –1)} – 2} = 0
Putting l = 0, we have l = 1, 4, 4
8x – 6y + 2z = 0, \ l = 1, 4, 4 are eigen values.
– 6x + 7y + 4z = 0,
2x – 4y + 3z = 0
EBD_7203
S2-90 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
= a1 a2 [b1b2 c1c2 – b1b2c1c2] = 0
é6 2ù
66. (a) Given matrix : A = ê ú a1a2 a1b2
ë2 6û Cofactor b a =0
We know |lI – A| = 0 1 2 b1ab
So rank = 1
l–6 –2
Þ =0
–2 l–6 3–l –2 2
Þ l2 – 12l + 32 = 0 69. (d) | P – lI |= 0 –2 – l 1 =0
Þ l = 4, 8 (eigen values) 0 0 1– l
For l1 = 4,
\ l = – 2, 3, 1
é –2 –2 ù é1ù Putting l = – 2, we get
(l1I–A)= ê ú , v1 = ê ú
ë –2 –2 û ë1û 5x – 2y + 2z = 0
z=0
For l1 = 8,
é 2 –6 ù é1ù é 5ù
(l1I–A)= ê ú , v2 = ê ú = ê ú
ë –6 2 û ë –1û So, 5x = 2y eigen vector ê 2ú
67. (a) Let A be a real symmetric matrix, therefore êë 0úû
AT = A 70. (c) AB
Let a1 and a2 be different eigen values of the matrix A,
and X1 and X2 be the corresponding vectors, then é cos q cos f cos(q – f ) cos q sin f.cos(q – f) ù
=ê ú
AX1 = a1 X1 and AX2 = a2 X2 ëcos f sin q.cos( q – f ) sin q.sin f cos(q – f) û
Taking transpose of the second equation = A null matrix, when cos (q – f) = 0
(AX2)T = (a2 X2)T
Þ X2T AT = a2. X2T æ pö
i.e. if (q – f) is an odd multiple of ç ÷ .
But AT = A, è 2ø
\ X2T A = a2. X2T 71. (b) Since matrix is triangular, hence eigen values are a, a, b.
Post multiply by X1, we get If (X1, X2 , X3 ) is an arbitrary eigen vector, say
X2T AX1 = a2X2T X1 corresponding to 1, then
But AX1 = a1X1
\ X2T a1X1 = a2X2T X1 é1 0 0 ù é X1 ù é X1 ù
Þ (a1– a2) X2T X1 = 0 ê 0 a 0 ú ê X ú = 1 êX ú
ê úê 2ú ê 2ú
Since a1 ¹ a2, a1 – a2 ¹ 0 êë 0 0 b úû êë X3 úû êë X 3 úû
\ X2T X1 = 0
i.e. X2 and X1 are orthogonal. X2, X3 being not zero, we have
X1 = X1; aX2 = X2
é a1 ù which gives a = 1
ê ú and bX = X3
68. (b) Let A = ê b1 ú ; B = [a2b2 c2 ]
êë c1 úû Þ b=1
\ (a, b) = (1, 1).
é a1a2 a1b2 a1c2 ù
C = êê b1a2 b1b2 b1c2 úú
\
ëê c1a2 c2b2 c1c2 ûú
7 Numerical Methods
Sol. f (x) = x3 – 8x – 5 = 0
L U D EC OM P O SI T I ON F O R S Y ST EM S O F
LI NEAR EQUATI ONS f (3) = 33 – 8(3) – 5 = – 2
f (4) = 43 – 8 (4) – 5 = – 27
The secant method is very similar to the Newton-Raphson
method. The main disadvantage of the Newton-Raphson method Therefore one root lies between 3 and 4. Let the initial
is that the method requires the determination of the derivatives approximations be x0 = 3, and x1 = 3.5. Then, x2 is given by
of the function at several points. Often, the calculation of these x0 f ( x1 ) – x1 f ( x0 )
derivatives takes too much time. In some cases, a closed-form x2 =
f ( x1 ) – f ( x0 )
expression for f ¢(x) may difficult to obtain or may not be available.
To remove this drawback of the Newton-Raphson method, the The calculations are summarised in the following table
derivatives of the function being approximated by finite
differences instead of being calculated analytically. In particular, x0 f(x0) x1 f(x1) x2 f(x2)
the derivative f ¢ (x) is approximated by the backward difference 3 –2 3.5 9.875 3.08421 –0.33558
f ( xi ) – f ( xi –1 ) 3.5 9.875 3.08421 –0.33558 3.09788 –0.05320
f ¢ ( xi ) = ... (i) 3.08421 –0.33558 3.09788 –0.05320 3.10045 0.00039
xi – xi –1
3.09788 –0.05320 3.10045 0.00039 3.10043 0
where xi and xi–1 are two approximations to the root but does not 3.10045 0.00039 3.10043 0 3.10043 0
require the condition f (xi). f (xi–1) < 0.
Now, from the Newton-Raphson method, we have Hence, a root is 3.1004 correct up to five significant figures.
f ( xi ) f ( xi )( xi – xi –1 ) ...(ii) 2. Determine a root of the equation sin x + 3 cos x – 2 = 0,
xi +1 = xi – = xi –
f ¢ ( xi ) f ( x)i – ( xi –1 ) using the secant method. The initial approximations x0 and
It should be noted here from Eq. (ii) that this method x1 are 0 and 1.5.
requires two initial guess values x 0 and x 1 for the root. The Sol. The formula for x2 is given by
secant method is illustrated geometrically as shown in Fig., x0 f ( x1 ) – x1 f ( x0 )
where a secant is drawn connecting f (x i–1 ) and f (x i). The x2 =
f ( x1 ) – f ( x0 )
point where it intersects the x-axis is x i+1 . Another secant is
drawn connecting f(x i) and f (x i+1 ) to obtain x i+2 and process The calculations are summarised in the following table
continues.
f(x) x0 f(x0) x1 f(x1) x2 f(x2)
0 –2.33914 1.5 –0.79029 1.24488 –0.09210
1.5 –0.79029 1.24488 –0.09210 1.21122 –0.00833
1.24488 –0.09210 1.21122 –0.00833 1.20788 –0.00012
1.21122 –0.003833 1.20788 –0.00012 1.20783 0
1.20788 –0.00012 1.20783 0 1.20783 0
xi xi+1
O xi+2 xi+3 x
Hence, a root is 1.2078 correct up to five significant figures.
Putting x = x0 + rh y
Þ dx = hdr
n
\ I = h ò f ( x0 + rh)dr
0
h 1
= ( y0 + 4 y1 + y2 ) = [(1 + .027) + 2(.5 + .2 + .1 + .0588 + .0385) = 1.4108
3 2
x0 + 4 h 1
h (ii) By Simpson’s rule
Similarly, ò f ( x )dx = ( y2 + 4 y3 + y4 )
3
3
x0 + 2 h 6
dx h
x0 + nh
h
ò 1 + x2 = [( y0 + y6 ) + 4( y1 + y3 + y5 ) + 2( y2 + y4 )]
3
ò f ( x )dx = ( yn - 2 + 4 yn -1 + yn )
3
0
x0( n - z ) h 1
= [(1 + .027) + 4(0.5 + 0.1 + 0.0385) + 2(0.2 + 0.0588)
n being even. 3
Adding all these integrals, when n is even, = 1.3662
x0 + nh
h 3
ò f ( x) dx = [( y0 + yn ) + 4( y1 + y3 + .... + yn -1 )
3
(iii) By Simpson’s rule,
8
x0
6
+2( y2 + y4 + ... + yn - 2 )] dx 3h
4. Simpson’s three-eighth rule :
ò 1 + x2 = [( y + y6 ) + 3( y1 + y2 + y4 + y5 ) + 2 y3 ]
8 0
0
Putting n = 3 in equation (i) above and taking the curve 3
through (xi, yi) i = 0, 1, 2, 3 as a polynomial of third order so = [(1 + 0.027) + 3(0.5 + 0.2 + 0.0588 + 0.0385 + 2(0.1)]
8
that differences above the third order vanish, we get = 1.3571
EBD_7203
S2-96 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
2
6. Function f is known at the following points:
æ1ö
1. The value of ò ç ÷ dx computed using Simpson's rule with
èxø x 0 0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3.0
1
f ( x) 0 0.09 0.36 0.81 1.44 2.25 3.24 4.41 5.76 7.29 9.00
a step size of h = 0.25 is [2007, 2 marks]
(a) 0.69430 (b) 0.69385 3
(c) 0.69325 (d) 0.69415 The value of ò0 f ( x ) dx computed using the trapezoidal
2. Equation ex – 1 = 0 is required to be solved using Newton's rule is [2013, 1 Mark]
method with an initial guess x0 = –1. Then, after one step of (a) 8.983 (b) 9.003
Newton's method, estimate x1 of the solution will be given
(c) 9.017 (d) 9.045
by [2008, 1 mark]
7. In the Newton-Raphson method, an initial guess of x0 = 2 is
(a) 0.71828 (b) 0.36784
made and the sequence x0, x1, x2 ... is obtained for the function
(c) 0.20587 (d) 0.000
3. Let x2 – 117 = 0. The iterative steps for the solution using 0.75x3 – 2x2 – 2x + 4 = 0
Newton-Raphson's method is given by [2009, 1 mark] Consider the statements
(I) x3 = 0.
1æ 117 ö (II) The method converges to a solution in a finite number
(a) xk +1 = 2 ç xk + x ÷
è k ø of iterations.
117 Which of the following is TRUE? [2014, Set-2, 2 Marks]
(b) xk +1 = xk – (a) Only I (b) Only II
xk
(c) Both I and II (d) Neither I nor II
xk 8. With respect to the numerical evaluation of the definite
(c) xk +1 = xk –
117 b 2
1æ 117 ö integral, K = òa x dx , where a and b are given, which of the
(d) d k +1 = xk – 2 ç xk + x ÷
è k ø following statements is/are TRUE ?
4. Newton-Raphson method is used to compute a root of the (I) The value of K obtained using the trapezoidal rule is
equation x2 – 13 = 0 with 3.5 is the initial value. The always greater than or equal to the exact value of the
approximation after one iteration is [2010, 2 marks] definite integral.
(a) 3.575 (b) 3.677 (II) The value of K obtained using the Simpson’s rule is
(c) 3.667 (d) 3.607 always equal to the exact value of the definite integral.
5. The bisection method is applied to compute a zero of the [2014, Set-3, 2 Marks]
function f (x) = x 4 - x3 - x 2 - 4 in the interval [1, 9]. The (a) I only (b) II only
method converges to a solution after ...... iterations. (c) Both I and II (d) Neither I nor II
[2012, 2 marks]
(a) 1 (b) 3
(c) 5 (d) 7
NUMERICAL METHODS S2-97
1. Show that LU decomposition method fails to solve the 7. If e0 = 1, e1 = 2.72, e2 = 7.39, e3 = 20.09 and e4 = 54.60, then
system of equations 1 4 x
x1 + x2 – x3 = 2 by Simpson's rd rule value of ò e dx is
3 0
2x1 + 2x2 + 5x3 = – 3 (a) 52.78 (b) 53.87
3x1 + 2x2 – 3x3 = 6. (c) 5.278 (d) 5.387
whose exact solution is? 8. The Newton-Raphson iteration
2. The table below gives values of a function F(x) obtained for xn 3
values of x at intervals 0.25 xn +1 = + can be used to solve the equation
2 2 xn
x 0 0.25 0.5 0.75 1 (a) x2 = 3 (b) x3 = 3
(c) x2 = 2 (d) x3 = 2
f(x) 1 0.9412 0.8 0.64 0.5
9. The convergence of the bisection method is
The value of the integral of the function between the limit 0 (a) cubic (b) quadratic
to 1 using Simpson's rule is (c) linear (d) None of these
(a) 0.7854 (b) 2.3562 1
(c) 3.1416 (d) 7.5000 10. Given, a > 0, we wish to calculate its reciprocal value by
a
3. Newton-Raphson method is used to compute a root of the
using Newton-Raphson method for f(x) = 0.
equation x3 – 13 = 0 with 3.5 as the initial value. The
The Newton-Raphson algorithm for the function will be
approximation after one iteration is
(a) 3.575 (b) 3.677 1æ a ö æ a ö
(a) xk +1 = ç xk + ÷ (b) xk +1 = ç xk + xk2 ÷
(c) 3.667 (d) 3.607 2è xk ø è 2 ø
4. Using Newton-Raphson method, a root correct to three
decimal places of the equation x3 – 3x – 5 = 0 is a 2
(c) xk +1 = 2 xk – axk2 (d) xk +1 = xk – xk
(a) 2.275 (b) 2.279 2
(c) 2.222 (d) None of these
5. The square root of a number N is to be obtained by applying 11. The relation to solve x = e–x using Newton-Raphson method
the Newton-Raphson iteration to the equation x2 – N = 0. If is
I denotes the iteration index the correct iterative scheme (a) xn +1 = e – xn
will be
1æ Nö (b) xn +1 = xn – e – xn
1æ Nö xi +1 = ç xi2 +
(a) xi +1 = ç xi + ÷ (b) ÷
2è xi ø 2è xi2 ø
e – xn
(c) xn+1 = (1 + xn )
1 + e – xn
1æ N2 ö 1æ Nö
(c) xi +1 = çç xi + ÷ (d) xi +1 = ç xi – ÷
2è xi ÷ø 2è xi ø x 2 – e – xn (1 + xn ) –1
(d) xn+1 = n
6. Using trapezoidal rule and the table given below, xn – e – xn
5.2
ò4 ln x dx will be 12. A numerical solution of the equation f (x) = x + x - 3 = 0
can be obtained using Newton-Raphson method. If the
x 4 4.2 4.4 4.6 4.8 5 5.2 starting value of x = 2 for ten iteration, the value of x that is
to be used in the next step
ln x 1.39 1.44 1.48 1.53 1.57 1.61 1.65 (a) 0.306 (b) 0.739
(a) 1.8277 (b) 1.9284 (c) 1.694 (d) 2.306
(c) 1.6424 (d) 0.98795
EBD_7203
S2-98 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
13. The equation x3 + 4x – 9 = 0 needs to be numerically solved 17. For a = 7 and starting with x0 = 0.2, the first two iterations
using the Newton-Raphson method is will be
æ 2 x3 + 9 ö 3xk2 + 4 (a) 0.11, 0.1299 (b) 0.12, 0.1392
(a) xk +1 = ç k ÷ .8 (b) xk +1 =
ç 3x 2 + 4 ÷ 2 xk2 + 9 (c) 0.12, 0.1416 (d) 0.13, 0.1428
è k ø
3
1
xk +1 =
4 xk2 + 3 18. The integral ò x d x when evaluated by using Simpsons
(c) xk +1 = xk – 3xk2 +4 (d) 1
9 xk2 + 2
14. Solving x2 – 2 = 0 by Newton Raphson technique, when 1
rd rule on two equal sub intervals each of length 1,
initial guess x0 = 1.0, then subsequent estimate of x (i.e., x1) 3
will be equal to
(a) 1.414 (b) 1.5 (a) 1 (b) 1.008
(c) 2.0 (d) None of these (c) 1.1111 (d) 1.120
15. The following equation needs to be numerically solved
using the Newton-Raphson method. 1é Rù
x3 + 4x – 9 = 0 19. The Newton-Raphson iteration xn +1 = 2 ê xn + x ú can be
The iterative equation for this purpose is (k indicates the ë nû
iteration level) used to compute the
2x 3k + 9 2x 2k + 4 (a) square of R (b) reciprocal of R
(a) x k + 1 = (b) xk + 1 = (c) square root of R (d) logarithm of R
3x 2k + 4 3x 2k + 4
20. The trapezoidal rule for integration give exact result when
4x 2k + 3 the integrand is a polynomial of degree.
(c) x k + 1 = xk – 3x k2 + 4 (d) x k + 1 =
9x 2k + 2 (a) 0 but not 1 (b) 1 but not 0
16. The table below gives values of a function F(x) obtained (c) 0 or 1 (d) 2
for values of x at intervals of 0.25 21. The Newton-Raphson method is to be used to find the
x 0 0.25 0.5 0.75 1.0 root of the equation and f ¢(x) is the derivative of f. The
method converges
F ( x) 1 0.9412 0.8 0.64 0.50
(a) always (b) only if f is a polynomial
The value of the integral of the function between the (c) only if f (x0) > 0 (d) none of above
limits 0 to 1 using Simpson’s rule is
(a) 0.7854 (b) 2.3562
(c) 3.1416 (d) 7.5000
NUMERICAL METHODS S2-99
e xk –1 e xk .xk – e xk + 1 3 +1
xk +1 = xk – = ...(i) x n +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 = =
e x0 e –1 3
–2 + e
trapezoidal rule to compute ò f ( x)dx
Þ = 0.71828 (Q e = 2.71828) 0
1
3. (a) Let f (x) = x2 – 117 = 0
x 0 0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3.0
and f ¢ (x) = 2x
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
xk2 – 117
f (x)
xk +1 = xk –
2 xk
0.36
2 x 2 – xk2 + 117 0.09
= k
2 xk
O 0.3 0.6 0.9 3.0
x
xk2 + 117 1 æ 117 ö
= = ç xk +
2 xk 2è xk ÷ø
Plotting x and f (x)
EBD_7203
S2-100 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1 1
Area of region I = × (Base) × (Height) =
2 3
1 Exact value of integral is :
= × (0.09) × (0.03)
2 1 1
x3 1
ò x dx =
2
Area of region II =
3 3
1 0 0
= (Base 1 + Base 2) × (Height) PRACTICE EXERCISE
2
1. Case I If we write (taking lii= 1)
1
= (0.09 + 0.36) × (0.6 – 0.3) 0 ù ém11 m12 m13 ù
2 é 1 1 –1ù é 1 0
Also, observe that each value of f (x) except x = 3.0 ê 2 2 5 ú = êl 0 úú êê 0 m22 m23 úú
ê ú ê 21 1
is included in two different regions. êë 3 2 –3ûú êël31 l32 1 ûú êë 0 0 m33 úû
3 1
ò0 f ( x)dx = 2 (0.3) (0.09) é m11 m12 m13 ù
ê
= êm11l21 m12 l21 + m 22 m13l21 + m23 ú
1 1 ú
+ (0.3) (0.09 + 0.36) + .... + (0.3) (7.29 + 9.0)
2 2 êëm11l31 m12 l31 + m 22l32 m13l31 + l32m 23 + m33 úû
1 On comparing, we obtain
= (0.3) (0.09 + 0.36 + 0.81 + 1.44 + 2.25 m11 = 1, m12 = 1, m13 = –1
2
l21 m11 = 2, Þ l21 = 2
1 m12l21 + m22 = 2 + m22 = 2 Þ m22= 0
+ 3.24 + 4.41 + 5.76 + 7.29) (0.3) (9.00)
2 Hence, LU decomposition method fails as the pivot
= 7.695 + 1.35 = 9.045 m22 = 0.
7. (a) x0 = 2 Case II If we write (taking mii = 1)
x1 = 0
x2 = 2 é 1 1 –1ù é l11 0 0 ù é1 m12 m13 ù
x3 = 0 .......... ê 2 2 5 ú = êl 0 úú êê0 1 m23 úú
ê ú ê 21 l22
b êë 3 2 –3úû êël31 l32 l33 úû ëê0 0 1 ûú
òx
2
8. (c) dx
a é l11 l11m12 l11m13 ù
let a = 0, b = 1 ê
= l21 l21m12 + l22 ú
l21m13 + l22 m 23
let n = 4 ê ú
êël31 l31m12 + l32 l31m13 + l32 m 23 + l33 úû
b - a 1- 0
Þh= = = 0.25 On comparing, we obtain
n 4
l11 = 1, l21 = 2, l31 = 3
y0 y1 y2 y3 y4 m12 = 1, m13 = – 1, l22 = 0
x 0 0.25 0.5 0.75 1 Hence, LU decomposition method fails as again the
pivot l 22 = 0.
2
y= x 0 0.625 0.25 0.5625 1 2. (a) Given, h = 0.25
By Trapezoidal rule x 0 0.25 0.5 0.75 1.00
1
h
òx
2
dx = é( y0 + y4 ) + 2(y1 + y2 + y3 ) ùû f(x) 1 0.9412 0.8 0.64 0.50
0
2ë
1
0.25 By Simpson's rd rule
= [(0 + 1) + 2(0.0625 + 0.25 + 0.5625)] 3
2
x0 + nh h
= 0.34375 òx0 F( x)dx = [{F(0) + F(1)} + 2{F(0.5)}
3
1
By Simpson’s rule + 4 {F (0.25)} + F (0.75)}]
3
0.25
1
h = [(1 + 0.5) + 2 (0.8) + 4(0.9412 + 0.64)]
ò x dx = 3 éë( y0 + y4 ) + 2(y2 ) + 4(y1 + y3 ) ùû
2 3
0 0.25
= (9.4248) = 0.7854
0.25 3
= [(0 + 1) + 2(0.25) + 4(0.0625 + 0.5625)]
3
NUMERICAL METHODS S2-101
3. (d) f (x) = x2 – 13 = 0, f ¢(x) = 2x 8. (a) We know,
Initial value approximation Newton-Raphson method
x0= 3.5
If x1 be the approximation after one iteration. By f ( xn )
Newton-Raphson method method xn +1 = xn –
f ¢( xn )
f ( x0 ) From option (a), x2 = 3
x1 = x0 –
f ¢( x0 ) x2 – 3 = 0
f (x) = x2 – 3
(3.5)2 –13 f ¢ (x) = 2x
= 3.5 – = 3.607
2 ´ 3.5 f ( xn )
4. (b) Given, f (x) = x3 – 3x – 5 = 0 Now, xn +1 = xn –
f (2) = – 3 (– ve) f ¢( xn )
f (3) = 13 (+ ve)
Therefore, a real root lies between 2 and 3 xn2 – 3 2 xn2 – xn2 + 3
= xn – =
f ¢ (x) = 3x2 – 3 2 xn 2 xn
Let, the initial approximation be x0 = 2
f ¢(2) = 12 – 3 = 9 xn 3
By Newton-Raphson method xn +1 = +
2 2 xn
f ( x0 ) So, this is the right answer.
x1 = x0 – = 2.333333
f ¢( x0 ) 9. (c) Linear because the order of convergence of bisection
method is 1/2.
f ( x1 )
x2 = x1 – = 2.280555 1 1
f ¢( x1 ) 10. (c) Given, a > 0 and x = or a =
a x
f ( x2 )
x3 = x2 – = 2.279020 1
f ¢( x2 ) Let f ( x) = –a =0 ...(i)
x
f ( x3 )
x4 = x3 – = 2.279019 æ1ö
f ¢( x3 ) Here, we wish to find the reciprocal of ç ÷
èaø
The correct root is 2.279019.
5. (a) Given, x2 – N = 0 1
f (x) = x2 – N f ¢( x) = –
f ¢(x) = 2x x2
Now, by Newton-Raphson method
f ( xi )
fx+i = xi – f ( xk )
f ¢( xi ) xk +1 = xk –
f ¢( xk )
xi2 – N 1 é Nù
= xi – = ê xi + ú æ 1 ö
2 xi 2ë xi û
çè x – a÷ø
6. (a) By trapezoidal rule, xk +1 = xk – k = xk + ( xk – axk2 )
æ 1ö
h –
= [( y0 + yn ) + 2( y1 + y2 + y3 + ... + yn –1 ) çè x 2 ÷ø
2 k
æ 5.2 – 4 ö xk +1 = 2 xk – axk2
çQ h = ÷
è 6 ø 11. (c) Let f (x) = x – e–x
0.2 \ The given equation can be written as
= [(1.39 + 1.65) + 2 (1.44 + 1.48 + 1.53 + 1.57 + 1.61)] f (x) = x – e–x = 0
2
= 1.82764 f ¢(x) = 1 + e–x
7. (b) Here, h = 1 Newton-Raphson method is
By Simpson rule, f ( xn )
4 x h xn +1 = xn –
= [e0 + e4 + 4(e1 + e3 ) + 2e 2 ] f ¢( xn )
ò0
e dx
3
4 x 1 xn – e – xn
Þ xn+1 = xn –
ò0
e dx = [(55.60) + (91.24) + (14.78)]
3 1 + e – xn
1
= (161.62) = 53.87 e – xn
3 = (1 + xn )
1 + e – xn
EBD_7203
S2-102 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
15. (a) f(x) = x3 + 4x – 9 = 0
12. (c) Let f (x) = x + x - 3
f ¢(x) = 3x2 + 4 = 0
1 2 x +1 By Newton-Raphson method,
f ¢(x) = 1 + =
2 x 2 x
xk + 1 = xk –
f (xk )
= xk –
(x 3
k + 4x k – 9 )
xn +1 = xn -
( xn + xn - 3)
´ 2 xn
f '( x k ) ( 3x 2
k +4 )
(2 xn + 1)
3x 3k + 4x k – x 3k – 4x k + 9 2x 3k + 9
= = .
(2 xn xn + 2 xn - 6 xn ) 3x 2k + 4 3x 2k + 4
xn +1 = xn -
(2 xn + 1) 16. (a) By Simpson’s 1/3 rd rule,
(2 xn + 2 xn xn - 6 xn ) 1
= xn -
(2 xn + 1) ò f ( x ) dx
0
2 xn xn + xn - 2 xn - 2 xn xn + 6 xn h
= = éf ( 0) + f (1) + 2 { f (.5)} + 4 {f (.25) + f (.75)} ùû
(2 xn + 1) 3ë
xn - 2 xn + 6 xn 0.25
= [1 + .5 + 2 × .8 + 4 (.9412 + .64)]
= 3
2 xn + 1
= 0.7854.
6 xn - xn 17. (b) xk + 1 = 2 xk – a xk2
= \ x1 = 2 x0 – a x02 = 2(0.2) – 7(0.2)2
2 xn + 1
= 0.12
6 2-2 x2 = 2x1 – 7(x1)2
f (2) = = 1.694
2 2 +1 = 2(0.12) – 7(0.12)2 = 0.1392.
f ( xk ) Simpson’s rule:
xk +1 = xk –
f ¢( xk ) b
h
ò ydx = 3 [( y0 + yn ) + 4( y1 + y3 + ...) + 2( y2 + y4 + ...)]
x3 + 4 xk – 9 a
xk +1 = xk – k
3xk2 + 4 1
= [(1 + 0.33) + 4(0.5)] = 1.111
3
3xk3 + 4 xk – xk3 – 4 xk + 9
xk +1 = [Remember to start from y0 and not y1].
3xk2 + 4 19. (c)
20. (c)
æ 2 x3 + 9 ö
xk +1 = 8 ç k ÷ 21. (d)
ç 3x 2 + 4 ÷
è k ø
14. 2
(b) x – 2 = 0
f ( x0 )
x1 = x0 -
f '( x0 )
1
= 1+ = 1.5
2
8 Calculus
LIMITS
Limits is used to find out the real number k to which a function a x –1
7. lim = log a (a > 0).
f (n) approaches, when x tends to a point a, this is represented as. x®0 x
lim f ( x) = k .
x® a log x
8. lim = 0 (n > 0)
Right hand limit : (RHL) x®¥ x n
lim f ( x ) = k .
x® a + Sandwitch theorem
Left hand limit (LHL) In a certain neighbour hood of x = a, f(x) £ g(x) £ h(x) £ b(x) and
lim f ( x) = k . if xlim f ( x ) = lim h ( x) = n , then lim g ( x) = n.
x® a – ®a x® a x® a
Limit of the function exist if RH Limit = LH Limit. L-Hospital’s rule
Limit does not exist if either RHL or LHL does not exist and if both
of them are unequal. If at x = a, a function f(x) has an indeterminate value such as
Theorems 0 ¥ ¥
, ,1 , ¥ – ¥ etc. then L-hospital’s rule can be applied.
0 ¥
1. lim f ( x).g ( x ) = lim f ( x). lim g ( x)
x® a x ®a x® a consider two functions f(x) and f(x) having value 0 at x = 0, then
xn – an x 2 + x - sin x
6. lim = na n –1 (a > 0) = lim
2 + sin x
=1
x ®0 x – a Þ lim 2
x®0 x x®0 2
EBD_7203
S2-104 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
CO NTI NU I TY f ¢(c) f (b) – f (a)
(a) Continuity at a point =
g ¢ (c ) g (b) – g (a)
A function f (x) is said to be continuous at x = a if
4. Taylor’s theorem
lim f ( x) = f ( a ) n–1
If f (x) is continuous and f ¢(x), f ¢¢ (x)... f are all continuous
x®a
in closed interval [a, a + b] and exist in (a, a + b) where
(b) Continuity in an interval. h = (b – a) then,
(i) Open interval.
A function f (x) is said to be continuous in an open h2
f (a + h) = f (a) + h f ¢(a) + f ¢¢(a) + .... +
interval (a, b) if it is continuous at each point of (a, b). 2!
(ii) Closed interval.
A function f (x) is said to be continuous in a closed hn –1 ( n –1) hn 'n
´ f¢ (a) + f (a )
interval [a, b] if f(x) is continuous at each point of (a, b) (n –1)! h!
(iii) lim f ( x ) = f (a) and lim f (x) = f (b).
x® a + x ®b –
Evaluation of definite and improper integrals
Standard Integration
Property of Continuity
x
If two functions f(x) and g(x) are continuous at x = a, then 1. òe dx = e x
f (x) + g (x), f(x) – g (x), a. f (x), f (x). g (x) are also continuous at
x = 0. x ax
2. òa dx =
log a
; ò a dx = 0 (a = constant)
f ( x)
Moreover is also continuous at x = 0 pr ovided
g ( x)
n x n+1
g(x) ¹ 0. 3. ò x dx = n +1
(n ¹ 1)
DIFFERENTIABILITY 1
A function f (x) is said to be differentiable at x = a if
when n = 1, i.e., ò x dx = log x
both lim
f (a + h) - f (a)
,h > 0
4. ò sin x dx = – cos x
h® 0 h
f (a - h) - f (a)
5. ò cos x dx = sin x
and lim ,h > 0
h® 0 -h 6. ò tan x dx = – log cos x = log sec x.
exist and have common value (finite). This common value is called
2
derivative of f (x) at the point x = a and is denoted by f ¢(a). 7. ò cos ec x dx = – cot x.
2
Mean Value Theorems
8. ò sec x dx = tan x
1 1 -1 æ x ö
16. ò a2 + x2 dx = a tan çè ÷ø
a \ dy =
1
dx
1 + x2
1 1 -1 x
17. ò dx =
a
sec
a –1
x x2 – a esin x -1
\ ò dx = ò e y ´ dy = ey + c = esin x
+c
2
1 1+ x
æ ö
18. ò dx = log ç x + a 2 – x 2 ÷
2 2 è ø
a -x Partial Derivations
Derivative of function z w.r.t. x and x is allowed to vary is called
1 æ ö
19. ò dx = log ç x + a 2 + x 2 ÷ dx
2 2 è ø ¶z
a +x partial derivative of z w.r.t. x and is devoted by
¶x
1
20. ò dx = log x + x 2 - a 2 ¶z = Lt f [( x + dx ), y ] – f ( x, y )
2 2 d ®
x –a ¶x x 0 dx
1 1 æ xö ¶z
ò dx = sec –1 ç ÷ ¶x
is first order partial derivative of z.
21. a è aø
x x2 – a 2
¶z
1 1 æ xö Similarly derivative of z w.r.t. y is denoted by .
dx = tan –1 ç ÷ ¶y
22. ò 2
x +a 2 a è aø
When z is a function of a function of two variables x and y i.e,
z = f(u) and u = (x, y), then,
1 1 æ x – aö
23. ò x 2 – a 2 dx = 2a log çè x + a ÷ø ( x > a) ¶z ¶z ¶u
= ´
¶x ¶u ¶x
1 1 æ a + xö
24. ò a 2 – x2 dx = 2a log çè a – x ÷ø ( x < a) ¶z ¶z ¶u
= ´
¶y ¶u ¶y
x
25. òe [ f ( x) + f ¢ ( x )]dx = e x f ( x ) + c Partial derivatives of higher order
¶u ¶ 2u
f ¢( x ) Partial derivative of w.r.t. x is given by 2
26. ò f ( x)
dx = log f ( x) + c ¶x ¶x
¶ 2u ¶ æ ¶u ö
=
27.
éæ du ö
ò u.vdx = u ò v dx – ò êëçè dx ÷ø ( ù
)
ò v dx úû dx
i.e.
¶x 2 ç ÷
¶x è ¶x ø
Gradient.
æ ®ö
Del (Ñ) applied to vector function Ñ f is defined as the (iv) Ñ. ç U A ÷ = ( ÑU ) .A + U ( ÑA )
gradient of the scalar point function f and written as grad f. è ø
Thus gradient f defined as
æ ®ö
¶f ¶f ¶f (v) Ñ´ ç U A÷ = ( ÑU) ´ A + U( Ñ´ A)
Grad f = Ñf = i + j + k è ø
¶x ¶y ¶z
Grad f is a vector normal to surface f = constant, and has a
æ ® ®ö
magnitude equal to the rate of change of f along this normal. (vi) Ñ. ç A ´ B ÷ = B ( Ñ ´ A ) - A ( Ñ ´ B)
DIVERGENCE è ø
The divergence of a continuously differentiable vector point
function F is denoted by divergence F and is define by the æ ® ®ö
equation (vii) Ñ. ç A ´ B ÷ = ( B.Ñ) A - B ( Ñ.A ) - ( A.Ñ) B + A ( Ñ.B)
è ø
¶F ¶F ¶F
div F = DF = i +j + k. (viii) Ñ( A.B) = ( B.Ñ) A + ( A.Ñ) B + B ´ ( Ñ ´ A) + A ´ ( Ñ ´ B)
¶x ¶y ¶z
If F = fi + fj + yk, then
(ix) Ñ. ( ÑU ) = Ñ2 U
æ ¶ ¶ ¶ö
div F = Ñ.F = çè i. + j + k . ÷ø (fi + fj + yk) (x) Ñ´ ( ÑU) = 0 , i.e. curl of grad of U = 0
¶x ¶x ¶x
= 4iˆ - 2ˆj - kˆ
( ) ( )
¶u 2 ¶u 2
= 2x x 2 + y 2 + z 2 , = 2y x 2 + y 2 + z 2 ; 4 ( 4 ) + ( -2 )( -2 ) + 4 ( -1) 16
¶x ¶y = =
6 21 6 21
¶u
¶z
(
= 2z x 2 + y 2 + z 2 ) Hence the required angle q = cos
-1 æ
ç
8 ö
÷
è 3 21 ø
¶u ¶u ¶u
Also, du ( x, y, z ) = dx + dy + dz
¶x ¶y ¶z 4. The minimum point of the function
x2
( )
2
f ( x) = - x is at :
= 2 x 2 + y2 + z 2 ( xdx + ydy + zdz ) 3
Sol. For min value f '( x) = 0
2 dt
= 2t . , taking x2 + y2 + z2 = t and 2(xdx + ydy + zdz) = dt
2 f '( x) = x 2 - 1
Integrating both sides,
x 2 - 1 = 0 Þ x = ±1
( )
1 1 3
u = ò t 2 dt + c = t 3 + c = x 2 + y 2 + z 2 + c f "( x ) = 2 x
3 3
At x = 1, f "( x ) = 2 > 0
1
Hence, u = r 3/2 + c At x = –1, f "( x) = -2 < 0
3
2. Find a unit vector normal to the surface xy3z2 = 4 at the point \ minimum is at x = 1
(– 1, – 1, 2). 5. Find max slope of the curve x3 + 4 x 2 + 2 x + 1
f '( x ) = 3 x 2 + 8 x + 2 ( = F(x))
¶
¶x ( ) (
¶
¶y
¶
= ˆi xy3z2 - 4 + ˆj xy3z2 - 4 + kˆ xy3z2 - 4
¶z ) ( ) F '( x ) = 6 x + 8
( ) ( ) ( )
3 2 2 2 3 F ''( x) = 6
= ˆi y z + ˆj 3xy z + kˆ 2xy z For maxima and minima
= -4iˆ - 12ˆj + 4kˆ at the point (– 1, – 1, 2). F '( x ) = 0
\ x = – 4/ 3
Hence the desired unit normal to the surface.
F '( -4 / 3) = 6
-4iˆ - 12ˆj + 4kˆ
=
é( -4) 2 + ( -12 ) 2 + 42 ù
=-
1 ˆ ˆ ˆ
11
i + 3j - k ( ) Hence slope (i.e., F ( x) ) is max at x = –4 / 3
êë úû Max-slope = F ( -4 / 3) = 3( -4 / 3) 2 + 8( -4 / 3) + 2
16 32 -10
= - +2 =
3 3 3
EBD_7203
S2-108 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
r r r r
6. Find divergence of vector r = xi + yj + zk y2 x 2
r r r
Sol. g = D .r
ò ò Rf (x, y)dxdy = ò ò f (x, y)dx dy
y1 x1
æ ¶ ¶ ¶ ö x2 y2
=ç i+ j+ k ÷ ( xi + yj + zk ) =ò
è ¶ x ¶ y ¶ z ø x1 òy1 f (x, y)dy dx
=1+1+1=3 (i) If region R is partitioned into two parts, say R1 and R2,
MULTIPLE INTEGRALS then
Let a single-valued and bounded function f(x, y) of two òòR f ( x, y ) dx dy = òòR 1 f ( x, y ) dx dy + òòR 2 f ( x, y) dx dy
independent variables x, y be defined in a closed region R of the
xy-plane. Divide the region R into sub-regions by drawing lines (ii) Double integral of the algebraic sum of a fixed number
parallel to co-ordinate axes. Number the rectangles which lie of functions is equal to algebraic sum of the double
entirely inside the region R from 1 to n. integrals taken for each term.
Let (xr, yr) be any point inside the r th rectangle whose area is dAr, Thus
( )
f x 1, y1 d A 1 + f ( x 2 , y 2 ) d A 2 + .....f ( x n , y n ) d A n òòR éëf1 ( x, y) + f2 ( x, y) + f3 ( x, y ) + ...ùû dx dy
n = òòR f1 ( x, y ) dx dy + òòR f 2 ( x, y ) dx dy + òòR f3 ( x, y ) dx dy + ...
= å f ( x r , y r ) dA r ...(i)
r =1 (iii) A constant factor may be taken outside the integral
Let number of these sub-regions increases indefinitely such that sign. Thus,
the largest linear dimension (i.e. diagonal) of dAr approaches
zero. The limit of the sum (i), if it exists, irrespective of the mode of
òòR K f ( x, y) dx dy = K òòR f ( x, y ) dx dy
sub-division, is called double integral of f(x, y) over the region R where K is constant
Evaluation of Double Integrals
and is denoted by òò R f (x, y)dA .
In other words, During evaluating double integrals, first integrate with respect to
the variable limits, treating other variables as constant, and then
Lt n integrate with respect to the variable with constant limit.
n ® ¥ å f ( x r , y r ) dA r = òò R f (x, y)da
dA r ®0 r =1
Sample Problem
which is also expressed as òòR f ( x, y) dx dy 5 x2
or òòR f ( x, y ) dy dx Evaluate òò ( )
x x 2 + y 2 dx dy
0 0
Let the region R be bounded by the curves
x = x1 and y = y2 5 x2 5é x2
y3 ù
x = x2 and y = y2 Sol. I = ò dx ò( )
x 3 + xy 2 dy = ò ê x 3 y + x. ú
êë 3 úû
dx
Properties of a Double Integral 0 0 0 0
(i) When x1, x2 are functions of y and y1, y2 are constants. 5é
Let AB and CD be the curves x1 = f1(y) and x2 = f2(y). y6 ù
= ò ê x3 .x 2 + x. ú dx
3 ú
0 êë
Then û
y2
x 2 =f2 ( y ) 5æ 7ö é 2ù 5
x6 x8
òòR f ( x, y) dx dy = ò òx1=f1( y) f ( x, y) dx dy 5 x 6 1 5
= ò ç x + 3 ÷ dx = 6 + 24 = 5 ê 6 + 24 ú = 18880.2 nearly.
y1 0è ø 0 ëê ûú
(ii) When y1, y2 are functions of x and x1, x2 are constants. CHANGE OF ORDER OF INTEGRATION
Let AB and CD be the curves
y1 = f1(x) and y2 = f2(x). In a double integral with variable limits, the change of order of
integration changes the limit of integration. While doing so,
Then sometimes it is required to split up the region of integration and
x2 the given integral is expressed as the sum of a number of double
y 2 =f2 ( x )
òòR f ( x, y ) dx dy = ò òy1=f1( x ) f ( x, y) dy dx integrals with changed limits. To fix up the new limits, it is always
advisable to draw a rough sketch of the region of integration.
x1
The change of order of integration quite often facilitates the
(iii) When x1, x2, y1, y2 are constants. evaluation of a double integral. The following examples will make
Here the region of integration R is the rectangle. Therefore, these ideas clear.
CALCULUS S2-109
Sample Problem Sample Problem
By changing the order of integration of 1 z x+z
¥ ¥ –xy ¥ sin px p Evaluate ò –1 ò0 òx–z (x + y + z)dxdydz.
ò ò
0 0
e sin px dxdy, show that
0 x
dx = .
2 ò Sol. Integrating first w.r.t.y keeping x and z constant,we have
Sol.
¥ ¥ –xy
ò0 ò0 e sin px dxdy = ò (ò
¥ ¥ –xy
0 0
e sin px dx dy ) I=
1 z
ò ò
–1 0
xy +
y2
+ yz
x+z
dx dz
2 x–z
–xy ¥
¥ e 1 zé 1 ù
=ò – (p cos px + y sin px) dy = ò – 1 ò 0 ê ( x + z )( 2 z ) + 4 x z ú d x d z
0 p2 + y 2 0
ë 2 û
z
¥ ¥ 1 x2z x2
p æ yö p 2
= ò 2 2
dy = tan –1 ç ÷
è pø
=
2 ...(i)
=2 ò
–1 2
+z x+ z dz
2 0
0 p +y 0
On changing the order of integration, we have 1
1 æ z3 z3 ö z4
¥ ¥ –xy
ò0 ò0 e
¥
sin px dx dy = ò sin px
0 {ò ¥ –xy
0
e dy dx } = 2ò ç + z3 + ÷ dz = 4
–1 è 2 2ø 4 –1
=0
¥
¥ e –xy ¥ sin px FOURIER SERIES
=
0 ò
sin px
–x 0
dx =
0 x
dx ò ...(ii)
If number a0, a1, ....., an, ....., b1, b2, ............, bn, ........... are derived
from a function f by means of Euler-Fourier formulas
¥ sin px p
Thus from (i) and (ii), we have ò0 x
dx =
2 1
p
TRIPLE INTEGRALS
an =
p ò f ( x ) cos nx dx (n = 0, 1, 2, ....)
–p
Consider a function f (x, y, z) defined at every point of the
3-dimensional finite region V. Divide V into n elementary volumes p
1
dV1, dV2,..., dVn. Let (xr, yr, zr) be any point within the rth bn =
p ò f ( x ) sin nx dx (n = 1, 2, .....)
sub-division dVr. Consider the sum –p
¥ ¥
å f (x r , y r , zr )dVr . then series a 0 + å ( a n cos nx + bn sin nx ) is called Fourier
r =1 n =1
The limit of this sum, if it exists, as n ® ¥ and dVr ® 0 is called the series.
triple integral of f (x, y, z) over the region V and is denoted by
Dirichlet’s Condition
òòò f (x, y, z)dV. Assumptions for expansion in a Fourier’s series:
For purposes of evaluation, it can also be expressed as the (i) Given function f(x) is assumed to be defined and single valued
repeated integral in the given range (– l, l)
x 2 y2 z2 (ii) f(x) is periodic outside (– l, l) with period 2l.
òx1 òy1 òz1 f (x, y, z)dxdydz. ¥
If x1, x2 are constants; y1, y2 are either constants or functions of (iii) Series a0 + å ( a n cos nx + bn sin nx ) is uniformly
x and z1, z2 are either constants or functions of x and y, then this n =1
integral is evaluated as follows: convergent, so that term by term integrating of the series is
First f (x, y, z) is integrated w.r.t.z between the limits z1 and z2 possible.
keeping x and y fixed. The resulting expression is integrated w.r.t.y Even and Odd function of x (sine series and cosine series)
between the limits y1 and y2 keeping x constant. The result just Case I: When f(x) is an even function
obtained is finally integrated w.r.t.x from x1 to x2. ¥
x2 y2 (x) z 2 (x,y)
f ( x) = a0 + å a n cos nx
Thus I = ò x1 ò ò
y1(x) z1(x,y)
f (x, y, z)dz dy dx n =1
1 p
f ( x ) dx
p ò0
where the integration is carried out from the innermost rectangle where, a 0 =
to the outermost rectangle.
The order of integration may be different for different types of p
2
limits. a n = ò f ( x ) cos nx dx
p
0
bn = 0
EBD_7203
S2-110 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
Case II: When f(x) is an odd function dG(t) d
¥ F(t) = = [G(t) + C] then ò F(t)dt = G(t) + C
f ( x) = å ( bn sin nx ) dt dt
n =1 This is called the indefinite integral of F(t) and its definite integral
2p is
where, bn = ò f ( x ) sin nx dx
p0 b
ò F(t) dt = [ G(t)]a = G(b) - G(a).
b
a0 = 0 an = 0
Half Range Expansions a
A series which contains only sine terms or cosine terms is called
Sample Problem
half range Fourier sine or cosine series respectively.
In this case, function f(x) is generally defined in the interval (0, l). 1
ˆ evaluate (R ´ d 2 R/dt 2 )dt.
Now, if f(x) is an even function, then Fourier cosine series is Given R (t) = 3t 2 iˆ + tjˆ - t 3k, ò
¥ 0
nxp
f ( x) = a0 + å a n cos
l dæ dR ö dR dR d2R d2R
n =1
Sol. ç R ´ ÷ = ´ + R ´ = R ´
l dt è dt ø dt dt dt 2 dt 2
1
lò
where a 0 = f (x)dx ;
æ d2R ö dR
0 \ ò çç R ´ dt 2 ÷ dt = R ´
÷ dt
l è ø
2 npx
a n = ò f ( x ) cos dx ˆ ´ (6tiˆ + ˆj - 3t 2k)
= (3t 2 iˆ + tjˆ - t 3k) ˆ
l l
0
If f(x) is an odd function of x, then Fourier sine series is I J K
¥
n px = 3t 2 t - t 3 = -2t 3ˆi + 3t 4 ˆj - 3t 2 kˆ
f (x) = å bn sin
l
n =1 6t 1 -3t 2
l
2 n px 1 æ d 2R ö
where, a0 = 0 bn = l ò f ( x ) sin l dx Thus ç R ´ 4 2 1
ò è dt 2 ÷ø dt = - 2t ˆi + 3t ˆj - 3t kˆ 0
3
0 0
Fourier series in the interval (a, b)
If function f(x) satisfies Dirichlet’s conditions in the interval = -2iˆ + 3jˆ - 3kˆ
(a, b), then
LINE INTEGRAL
¥
æ 2npx 2npx ö
f ( x) = a0 + å çè a n cos
b-a
+ b n sin
b-a ø
÷
Consider a continuous vector function F(R) which
is defined at each point of curve C in space. Divide
n =1 Pn = B
C into n parts at the points A = P0, P1, ..., Pi–1, Pi ...,
b Pn = B. Let their position vectors be R0, R1, ..., Ri–1, Pn – 1
1
f ( x ) dx
b-a ò
where, a 0 = Ri, ..., Rn. Let Ui, be the position vector of any Pi
a point on the arc Pi–1 Pi.
b n
2npx
an =
2
ò f ( x ) cos dx Now consider the sum S = å F(Ui ).d R i ,
b-a b-a i =0 Pi – 1
a
where dRi = Ri – Ri – 1. C
b The limit of this sum as n ® ¥ in such a way that
2 2npx
bn = ò f ( x ) sin dx |dRi| ® 0, provided it exists, is called the tangential
b-a b-a P0 = A
a line integral of F(R) along C and is symbolically
written as
INTEGR ATION O F V ECTORS
dR
If two vector functions F(t) and G(t) be such that
ò F(R).dR or ò F.
dt
dt.
dG(t) C C
= F(t),
dt When the path of integration is a closed curve, this fact is denoted
then G(t) is called an integral of F(t) with respect to the scalar
variable t and we write
by using Ñò in place of ò .
If F(R) = ˆi f (x, y, z) + ˆjf(x, y, z) + kˆ y (x, y, z)
ò F(t)dt = G(t).
If C be an arbitrary constant vector, we have and dR = ˆidx + ˆjdy + kdz
ˆ
CALCULUS S2-111
a2 sin 2t p
2 ò F. dS or ò F. NdS where N is a unit outward normal at P to S.
= t + = pa 2 S S
2 2 0
Other types of surface integrals are ò F ´ dS and ò F. dS which
SU RF ACES S S
A surface S may be represented by F(x, y, z) = 0. are both vectors.
The parametric representation of S is of the form Notation : Only one integrals sign is used when there is one
differential (say dR or dS) and two (or three) signs when there are
R(u, v) = x(u, v)iˆ + y(u, v)jˆ + z(u, v)kˆ
two (or three) differentials.
EBD_7203
S2-112 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
Flux across a surface : If F represent the velocity of a fluid particle
then the total outward flux of F across a closed surface S is the
2 2
To find N in S5, we note that Ñ y + z = 2yjˆ + 2zkˆ ( )
surface integral ò F. dS . 2yjˆ + 2zkˆ yjˆ + zkˆ é 2
\ N= = Q y + z 2 = 9 ùú
ëê
S
When the flux of F across every closed surfaces in a region E
( 4y2 + 4z 2 ) 3 û
vanishes, F is said to be a solenoidal vector point function in E. and | N .K | = z/3, so that ds = dxdy (z/3)
Sample Problem (
2 3 - y3 + 4xz3 ) .dydx / ( z / 3)
Thus ò F.N ds = ò ò 3
Evaluate ò F.Nds where F = 2x 2 yiˆ - y2ˆj + 4xz2kˆ and S is S5 0 0
S 2 3æ
- y3 ö
the closed surface of the region in the first octant bounded 2 .dydx [Put y = 3 sinq, z =3 cosq
by the cylinder y2 + z 2 = 9 and the planes x = 0,
= ò òè z
ç + 4xz ÷
ø
0 0
x = 2, y = 0 and z = 0. \ dy = 3 cos q dq]
Sol. The given closed surface S is piecewise smooth and is 2 p/2é
)úúû 3cos qdqdx
ù
comprised of S1 – the rectangular face OAEB in xy-plane;
S2 – the rectangular face OADC in xz-plane; S3 – the circular
= ò
-27 sin3 q 2
ò ê 3 cos q + 4x 9 cos q
ê (
0 0 ë
quadrant ABC in yz-plane. S4 – the circular quadrant AED 2
and S5 – the curved surface BCDE of the cylinder in the first é 2 2ù
octant = ò êë -27 ´ 3 + 108x ´ 3 úû dx = 108
0
3
C2
O 3 B x=
2 h(x
)
x=b
x=a
Y
2 x = x(x)
C1
A 3 E
O X
X
æ ¶y ¶f ö
ò (fdx + ydy) = òò çè ¶x - ¶y ø÷ dxdy. ...(1)
\ ò F.Nds = ò F.Nds + ò F.Nds + ò F.Nds C E
S S1 S2 S3 Consider the region E bounded by a single closed curve C which
is cut by any line parallel to the axes at the most in two points.
+ ò F.Nds + ò F.Nds ...(i) Let E be bounded by x = a, y = x(x), x = b and y = h(x), where h ³ x,
S4 S5 so that C is divided into curves C1 and C2
2 ˆ
Now ò F.Nds = ò (2x yi - y 2 ˆj + 4xz 2k).(
ˆ -k)ds
ˆ
b éh ¶f ù b
¶f h
S1 S1 \ òò ¶y
dxdy = ò dx ê ò dy ú = dx f x
ê ¶y ú ò
= -4 ò xz ds =0 [Q z = 0 in the xy - plane]
2 E a ëx û a
b
S1
= ò [f(x, h) - f(x, x)]dx
Similarly, ò F.N ds = 0 and ò F.N ds = 0 a
S2 S3
=- ò f(x, y)dx - ò f(x, y)dx = - ò f(x, y)dx ...(2)
C
ò F.N ds = ò (2x
2
yiˆ - y 2 ˆj + 4xy 2k).i
ˆ ˆ ds C2 C1
2
Hence Stoke’s theorem takes th e form ò ( fdx + y dy)
y= p C
p
x= æ ¶y ¶f ö
2 = ò ç - ÷ dx dy which is Green’s theorem in a plane.
è ¶x ¶x ø
C
Sample Problem
If F = 3ziˆ - xzjˆ + yz kˆ and S is the surface of the paraboloid
A X 2
O y=0
æ ¶Y ¶f ö
= òò R çè ¶x - ¶y ø÷ dx dy Sol. By Stokes theorem, I = òò ( Ñ ´ F).dS = Ñò F.dR
S C
x =p / 2 y = 2x / p
where S is the surface 2z = x2 + y2 bounded by z = 2.
= ò ò ( - sin x - 1) dy dx \ ò F.dr
I=Ñ
x= 0 y=0 C
Ñò (3yI - xzJ + yz )
p/2
2x / p =
2
K . ( dxI + dyJ + dzK )
=- ò ( sin x + 1) y 0 dx C
0
Q S º x 2 + y 2 = 4, z = 2
p/2
Ñò (3ydx - xzdy + yz )
2 \ Put x = 2 cos q, y = 2 sin q
=-
p ò x (sin x + 1)dx =
2
dz
0 C C º x 2 + y 2 = 4, q = 0 to 2 p
p/2
2 ìï üï 2p
p/2
=–
pï
í x(– cos x + x) 0 – ò 1.(– cos + x)dx ý Þ ò (3 ´ 2sin q ´ -2sin q d q -
î 0 ïþ 0
2cos q ´ 2 ´ 2cos q d q + 2sin q ´ 4 ´ 0)
ì p/2ü
2 ï p2 x2 ï
=- í - - sin x + ý 2p
pï 4 2
0 ï ò (-12sin
2
î þ Þ qd q - 8cos 2 q)d q
0
p 2æ p2 ö
2p
- + ç - 1 + ÷ -æ p + 2 ö Þ -4 ò (3sin 2 q d q + 2cos 2 q)d q
= 2 pç 8 ÷ = çè 4 p ÷ø
è ø 0
EBD_7203
S2-114 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
2p 2p
Gauss’s Divergence Theorem (Relation between surface and
-4 ò (2 + sin q)d q = -4 æç 2 + 1 - cos 2q ö÷ d q
2 volume integrals).
Þ
0
òè 2 ø “Volume integral of a vector field F taken over a volume V is equal
0
to the surface integral of F taken over the closed surface
2p 2p surrounding the volume V.”
-2 ò (4 + 1 - cos 2q) d q = -2 (5 - cos 2q) d q
Þ
0
ò Mathematically, for any vector-field F
0
2p
é
-2 ò (5 - cos 2q) d q = -2 ê5q -
sin 2q ù
2p
ò F.N dS = ò div Fd v
Þ
0
ë 2 úû 0 S E
where N is the unit external vector
Þ –2[10p] = –20 p If F(R) = f(x, y, z)i + f(x, y, z) j + Y(x, y, z) k
VOLUME INTEGRAL then, òò ( f dy dz + f dzdx + ydx dy)
Consider a continuous vector function F(R) and surface S
enclosing the region E. Divide E into finite number of æ ¶f ¶f ¶y ö
sub-regions E 1 , E 2 , ..., E n. Let dvi be the volume of the
= òòò çè ¶x + ¶y + ¶x ø÷ dx dy dx ...(i)
E
sub-region Ei enclosing any point whose position vector is Ri.
Consider a general region E assume that it can be split into finite
n number of sub-region each of which is met by line parallel to any
Consider the sum V = å F(R i )dvi axis in only two points. Applying equation (i) to each of these
i =1 sub-regions and adding results, the volume integral will be
The limit of this sum as n ® ¥ in such a way that dvi ® 0, is called combine to give the volume integrals over the wholes region E.
the volume integral of F(R) over E and is symbolically written as Also surface integrals over the common boundaries of two
sub-regions cancel because of each occur twice and having
ò Fdv. corresponding normal in opposite direction of whereas remaining
E surface integrals combine to give the surface integral over the
entire – surface.
If F(R) = f (x, y, z)iˆ + f(x, y, z)ˆj + y(x, y, z)kˆ so that dv = dxdydz,
Consider a region E bounded by two closed surface S1, S2 (S,
then being within S2). The outward normal at points S1 is directed
inwards (i.e. away from S2) introducing an adding surface cutting
ò F dv = ˆi òòò fdxdydz + ˆj òòò fdxdydz + kˆ òòò ydxdydz.
S1, S2 so that all parts of E are bounded by single closed surface.
E E E E
Thus the theorem also holds for regions enclosed by several
surfaces.
CALCULUS S2-115
1
21. If ò0 | x sin x | dx = kp, th en the value of k is equal
(d) f (x) = , if x ¹ 3 to______ . [2014, Set-3, 1 Mark]
x 3 – 27
22. The value of the integral given below is
17. The function f (x) = x sin x satisfies the following equation : p 2
f¢ '(x) + f (x) + t cos x = 0. The value of t is ______ . ò0 x cos x dx
[2014, Set-1, 2 Marks]
[2014, Set-3, 2 Marks]
18. A function f(x) is continuous in the interval [0, 2]. It is known
(a) –2p (b) p
that f (0) = f (2) = – 1 and f (1) = 1. Which one of the following
(c) –p (d) 2p
statements must be true ? [2014, Set-1, 2 Marks]
CALCULUS S2-117
1. The directional derivative of f(x, y, z) = 2x2 + 3y2 + z2 at 8. For a scalar function f(x, y, z) = x2 + 3y2 + 2z2, the
the point P : (2, 1, 3) in the direction of the vector directional derivative at the point P(1, 2, –1) in the
a = i – 2 k is r r r
direction of a vector i – j + 2k is
(a) – 2.785 (b) – 2.145
(c) – 1.789 (d) 1.000 (a) –18 (b) –3 6
2. A class of first year B.Tech. students is composed of four
(c) 3 6 (d) 18
batches A, B, C and D, each consisting of 30 students.
It is found that the sessional marks of students in é2 ù
Engineering, Drawing in batch C have a mean of 6.6 and sin ê x ú
9. The lim ë 3 û is
standard deviation of 2.3. The mean and standard
x ®0 x
deviation of the marks for the entire class are 5.5 and 4.2,
respectively. It is decided by the course instructor to 2
normalize the marks of the students of all batches to have (a) (b) 1
3
the same mean and standard deviation as that of the
entire class. Due to this, the marks of a student in batch 1 1
(c) (d)
C are changed from 8.5 to 4 2
(a) 6.0 (b) 7.0 10. A parabolic cable is held between two supports at the
(c) 8.0 (d) 9.0 same level. They horizontal span between the supports is
3. A velocity vector is given as L. The sag at the mid-span is h. The equation of the
r r r r
V = 5xyi + 2y2 j + 3yz 2 k x2
parabola is y = 4h , where x is the horizontal
The divergence of this velocity vector a (1, 1, 1) is L2
(a) 9 (b) 10 coordinate and y is the L vertical coordinate with the
(c) 14 (d) 15 origin at the centre of the cable. The expression for the
total length of the cable is
¥
sin t
4. Evaluate ò dt. L
h2 x2
L/2
h3 x 2
0
t (a) ò 1 + 64
L4
dx (b) 2 ò 1 + 64
L4
dx
0 0
p
(a) p (b) L/2 L/2
2 h2 x2 h2 x2
(c) ò 1 + 64
L4
dx (d) 2 ò 1 + 64
L4
dx
p p 0 0
(c) (d) 11. Given a function f(x, y) = 4x2 + 6y2 – 8x – 4y + 8
4 3
The optimal value of f(x, y)
3x
10
5. The value of ò ò (6 – x – y) dx dy is (a) Is a minimum equal to
3
00
Q p
(a) (b) 0
2
R 2p
(c) (d) 1
3
x3 + x 2
25. The value of the function f(x) = lim is
x®0 2x 3 – 7x 2
P
1
(a) 0 (b) –
O 7
(a) ad – bc (b) ac + bd 1
(c) (d) ¥
(c) ad + bc (d) ab – cd 7
CALCULUS S2-119
26. The function f(x) = 2x3 – 3x2 – 36x + 2 has its maxima at 11
(a) x = –2 only (b) x = 0 only x+y
(c) x = 3 only (d) both x = –2, x = 3
34. òòe dx dy equal to
00
27. The function f(x) = 2x(3x – 2) is
(a) (e – 1) (b) (e – 1)2
1 2 (c) (c – 1)3 (d) 1
(a) minimum at (b) minimum at
3 3 35. The maxima and minima of function x3 – 9x2 + 24x + 5
1 2 occurs at
(c) maximum at (d) maximum at (a) x = 2, 3 (b) x = 2, 4
3 3
(c) x = 2, 1 (d) x = 2, 5
sin x 36. What is the magnitude of gradient of function f(x) = xyz
28. lim is equal to
x ®0 x at (1, 0, 1)?
(a) 0 (b) 1 (a) 0 (b) 1
(c) sin x (d) x (c) ¥ (d) 2
r
37. Given a vector field F = y 2 xaˆ x – yzay
ˆ – x 2 aˆ z , the line
xa
29. lim is equal to
x ®0 xb integral ò F.dl evaluated along a segment on x-axis from
(a) 0 (b) 1 x = 1 to x = 2 is
a a! (a) 2.33 (b) 0
(c) (d) (c) 2 (d) 7
b b! 38. A function y = 5x2 + 10x is defined over on open interval
Ñò ( xy dy – y )
2
30. Value of dx , where c is the square cut dy
(1, 2). At least at one point in the interval, is exactly
c dx
from the first quadrant by the lines x = 1, y = 1 will be (a) 20 (b) 25
(c) 30 (d) 35
1
(a) (b) 1 39. The maximum value of f(x) = x3 – 9x2 + 24x + 5 in interval
2 [1, 6] is
3 5 (a) 21 (b) 25
(c) (d) (c) 41 (d) 46
2 3
40. The function f (x) = 2x – x2 + 3 has
31. A rail engine accelerates from its stationary position for (a) a maxima at x = 1 and minima at x = 5
8 seconds and travels a distance of 280 m. According to (b) a maxima at x = 1 and minima at x = – 5
the mean value theorem, the speedometer at a certain time (c) only a maxima at x = 1
during acceleration must read exactly (d) only a minima at x = 1
(a) 0 (b) 8 kmph 41. Roots of the algebraic equations x3 + x2 + x + 1 = 0 are
(c) 75 kmph (d) 126 kmph (a) (1, i, – i) (b) (1, –1, 1)
32. Consider likely applicability of Cauchy’s integral theorem (c) (0, 0, 0) (d) (–1, i, –i)
to evaluate the following integral counter clockwise 42. The direction of vector A is radially outward from the
origin, with |A| krn where, r2 = x2 + y2 + z2 and k is
around the unit circle C l = Ñò sec z × dz, z being a complex constant. The value of n for which Ñ. A = 0 is
(a) –2 (b) 2
variable. The value of l will be (c) 1 (d) 0
(a) l = 0, singularities set = f
–1 i 3
ì 2n + 1 ü 43. The two vector [1, 1, 1] and [1, a, a2] where a = +
(b) l = 0, singularities set = í± p; n = 0, 1 , 2, .....ý 2 z
î 2 þ are
(a) ortho normal (b) orthogonal
p (c) parallel (d) collinear
(c) l = , singularities set =
2
{ ± n p; n = 0, 1 , 2, .....}
sin t
(d) none of the these 44. At t = 0, the function f (t) = has
t
33. Which of the following vectors are orthogonal to (a) a minimum
each other? (b) a discontinuty
(a) [1, 2, 3] [3, 2, 1] (b) [2, 0, 1] [0, 1, 2] (c) a point of inflection
(c) [2, 2, 2] [2, 2, 2] (d) [1, 0, 3] [0, 2, 0] (d) a maximum
EBD_7203
S2-120 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1
2p Value of integral ò ò 2 x dx dy over the triangle is
47. The integral
2p ò sin(t – t) cos td t equals.
0 1
(a) sin t cos t (b) 0 (a) 1 (b)
3
1 1
(c) cos t (d) sin t 1 1
2 2 (c) (d)
8 8
48. Divergence of the 3-D radial vector rr is
(a) 3 (b) 1/r 58. Maximum value of the directional derivative of the function
(c) i + j + k (d) 3 (i + j + k) f = 2x2 + 3y2+ 5z2 at a point (1, 1, –1) is
(a) 10 (b) – 4
49. F (x, y) = (x2 + xy) aˆ x + ( y 2 + xy ) aˆ y
Its line integral of the straight line from (x, y) = (0, 2) to (c) 152 (d) 152
(x, y) = (2, 0) evaluates to
p/2p/2
(a) – 8 (b) 4
(c) 8 (d) 0 59. ò ò sin( x + y )dx dy is
50. Divergence of the vector field v (x, y, z) = – x (x cos xy 0 0
+ y) i + (y cos xy)j + [(sin z2) + x2 + y2] k is (a) 0 (b) p
(a) 2z cos z2 (b) sin xy + 2z cos z2
(c) p/2 (d) 2
(c) x sin xy – cos z (d) none of these
51. For a function f (x) = x2e–x the maximum occur when x is 60. Find the nth derivative of (i) cos x cos 2x cos 3x
equal to (ii) e3x cos2 x sin x.
(a) 2 (b) 1 61. Find the nth derivative of ex (2x + 3)3.
(c) 0 (d) –1
62. In the Mean value theorem f (b) – f(a) = (b – a) f ¢(c), ...(i)
x2 y2 determine c lying between a and b, if f (x) = x (x – 1) (x – 2),
52. For a scalar field is = + , the magnitude of gradient
2 3 a = 0 and b = 1/2.
at the point (1, 3) is (a) 0.141 (b) 0.236
13 9 (c) 0.348 (d) 0.847
(a) (b)
9 2 xe x – log(1 + x)
63. Evaluate (i) Lt .
9 x ®a x2
(c) 5 (d)
2
53. If f (x) = 3x4 – 4x2 + 5, then the interval for which f(x) satisfied xx – x
(ii) Lt
all the condition of Rolle’s theorem is x ®1 x –1– log x
(a) [0, 2] (b) [–1, 1]
(c) [–1, 0], (d) [1, 2] e x sin x – x – x 2
64. Evaluate = Lt .
54. Maximum slope of the curve – x3 + 6x2 + 2x + 1is x® 0 x 2 + x log (1 – x )
(a) 14 (b) 16
65. Evaluate (i) Lt (sin x) tan x
(c) 19 (d) – 13 x ®p / 2
55. The function f(x) = x5 – 5x4 + 5x3 – 1has
1/ x
(a) one minima and two maxima æ ax + bx + cx ö
(ii) Lt ç ÷
(b) two minima and one maxima x ®0 è 3 ø
(c) two minima and two maxima
(d) one minima and one maxima
CALCULUS S2-121
1/ x 2 4 p/2
æ tan x ö 69. Integrate (i) ò sin x dx (ii ) ò cos6 x dx.
(iii) Lt ç ÷ 0
x ®0 è 3 ø
a xn
66. If u = sin –1 x + 2 y + 3z
, find the value of 70. Evaluate ò0 dx.
Hence find the value of
(a 2 – x 2 )
x8 + y 8 + z 8
1 n
¶u ¶u ¶u ò0 x sin –1 x dx.
x +y +z .
¶x ¶y ¶z
71. Integrate (i) ò sin 4 x cos2 x dx
67. If x increases at the rate of 2 cm/sec at the instant when
x = 3 cm. and y = 1 cm., at what rate must y be changing in
order that the function 2xy – 3x2y shall be neither increasing ¥ t6 ¥ x2
nor decreasing? (ii) ò0 (1 + t 2 )7 (iii) ò0 (1 + x2 )7 / 2 dx
dt
p dx p
68. Given ò0 a + b cos x = (a > b), 72. Evaluate
p/2
ò0 log sin x dx.
(a – b2 )
2
1/ n
p dx p cos x ìæ 1 öæ 2 ö æ n ö ü
evaluate ò0 (a + b cos x)2 and ò0 (a +bcos x)2 dx 73. Evaluate Lt íç1 + ÷ç1 + ÷ ... ç1 + ÷ ý
n ®¥ îè n øè n ø è n ø þ
.
EBD_7203
S2-122 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
8 2 e x –1 é0 ù
= lim êë 0 Form úû
2. (a) Given, I = ò0 òp / 4 f ( x, y ) dx dx x®0 6 x
Equation of the line is x = 4y.
e x e0 1
= lim = =
Y-axis y = x/4 x ®0 6 6 6
x=8
6. (a) f(x) = | x |
ì x, x ³ 0
(8, 2) or f(x) = í - x, x < 0
î
The graph of f(x) is
x1/ 3 – 2 é0 ù a a–x
7. (b) Given, lim êë 0 Form úû I= ò dx
x ®8 x – 8 0
a – x+ x
apply L’ Hospital rule Adding both integrals, we get
1 –2 / 3 a
x –0 1 1 I=
1
= lim 3 = lim =
3 ´ 4
=
12 2
x ®8 1– 0 x ®8 3 x 2 / 3
15. (b) The sin (x) graph is as follows:
x - sin x
8. (a) lim
x ®¥ x + cos x
5p/2
sin x
1- p 3p/2
lim x
= x®¥ cos x p/2 2p
1+
x
1- 0
= =1
1+ 0 p/4 p/4
9. (c) A cubic polynomial with real coefficients cannot have
Local minima is at 3p/2 and there is only one local
more than two extrema and more than three zero
minima and its value is (– 1).
crossings.
3p
é2 ù é2 ù So, answer is one local minima at .
sin ê x ú sin ê x ú 2
lim ë 3 û = lim ë 3 û ´ 2 éQ lim sin x = 1ù Another approach
10. (a)
x ®0 x x®0 é 2 ù 3 êë x ®0 x úû
Using normal differentiation, compute f ¢(x), equate it
êë 3 x úû
to 0. Solve for x in the given range. For all solutions
compute f ¢¢ (x). Check its sign if (– ve) then local maxima
æ2ö 2 else local minima.
= 1. ç ÷ =
è3ø 3
ì
¥
¥ –3 é x –2 ù 1é 1 ù
¥ ï 2 if x =3
11. (c) S=ò x dx =ê ú =– ê 2ú ï
1 ë –2 û1 2 ë x û1 16. (a) f ( x) í x - 1 if x>3
ïx+3
1 é 1 1ù 1 1 ï if x<3
= – ê – ú = – (0 – 1) = î 3
2 ë¥ 1 û 2 2
{ }
1 d x+3
12. (d)
1 x 1
P = ò xe x dx = [ x ò e dx ]0 – ò0 ( x ) ò e x dx dx lim f ( x) = lim =2
0 dx x ®3 -
x®3 - 3
1 lim f ( x) = lim x - 1 = 2
= [ x.e x ]10 – ò e x dx = (1.e – 0) – [ex]01 x ®3+ x ®3+
0
= e – e + e0 = 1 \ lim f ( x) = f ( x ) = lim f ( x)
x= 3
x ®3- x®3+
2n éæ 1 ö n ù2 This is continuous at x = 3
æ 1ö
13. (b) lim ç1 - ÷ = lim êç 1 - ÷ ú
n®¥ è nø n®¥ ëè nø û ì 4 if x=3
(b) f (x) = í
= (e–1)2 = e–2 î8 - x if x¹3
lim f ( x) = lim 8 - x = 5 ¹ f ( x) x= 3
a x x ®3- x ®3-
14. (b) I=ò dx
0 x+ a–x Option (b) is false.
a a
By property ò0 f ( x) = ò0 f (a – x )dx,
EBD_7203
S2-124 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Þ 4p = kp
ì x + 3 if x£3
Þk=4
(c) f (x) = í
îx - 4 x>3 p
ò0 x
2
22. (a) cos xdx
lim f ( x) = lim x - 4 = -1
+ +
x ®3 x ®3
= | x 2 (sin x ) - 2 x( - cos x) + 2( - sin x) |p0
f (x) |x = 3 = 3 + 3 = 6
(p2 sinp + 2pcosp – 2sinp) – (0 + 0 + 0) = – 2p
lim f ( x) ¹ f ( x) x =3
x ®3+ PRACTICE EXERCISE
Option (c) is false.
a i – 2k (i – 2k)
1. (c) Unit vector â = = =
1 a 1+ 4 5
(d) f ( x) = if x ¹ 3
x3 - 27 ¶f ¶f ¶f
Hence, the solution is (a). grad (f) = Ñf = i + j +k
¶x ¶y ¶z
17. –2 = i × 4x + j × 6y + k × 2z
Given function f(x) = x sin x ...(1) At P (2, 1, 3)
Given eqn : f ¢¢(x) + f(x) + t cos x = 0 ...(2) Ñf = 8i + 6j + 6k
As f(x) = x sin x Directional derivative = Ñf . â
d ( i – 2k )
f ¢(x) = (x sin x) = sinx + x cos x = (8i + 6j + 6k) .
dx 5
8 – 12
d = = –1.789.
f ¢¢(x) = (sin x + x cos x) 5
dx
x–m
Þ f ¢¢(x) = cos x + cos x – x sin x 2. (d) Standard normal variant, Z =
Þ f ¢(x) = 2 cos x – x sin x ...(3) s
Put values from eq. (1) and eq. (3) into eq. (2) 8.5 – 6.6 1.9
For batch C, Zc = =
2 cos x – x sin x + x sin x + t cos x = 0 2.3 2.3
(t + 2) cos x = 0 x – 5.5
For entire class, Z =
Þ t + 2 = 0 (cos x can’t be 0 as the given function is not a 4.2
constant function) Z = Zc
1.9 x – 5.5
Þ t = -2 =
2.3 4.2
18. (a) There exist a y in the interval (0, 1) \ x = 9.
f (y) = f (y + 1) 3. (d) V = 5xyi + 2y2j + 3yz2k
19. (a) As per rule, if we put w values to the function which div V = Ñ . V
are on either side of root, the product will be less then
zero.
æ ¶
= çi
è ¶ x ¶
¶
y
¶ ö
¶zø
(
+ j + k ÷ × 5xyi + 2y 2 j + 3yz 2 k )
Here 0 and 4 are on either side of roots.
\ f (0). f(4) < 0 =
¶
¶x
(5xy) +
¶
¶y
2y 2 +
¶
( )
¶z
3yz 2 ( )
20. 8
The integral factors are 1, 2, 19, 38, 53, 106, 1007 = 5y + 4y + 6yz
At (1, 1, 1)
21. 4 Ñ . V = 5 + 4 + 6 = 15.
2p 1
4. (b) L (sin t) =
ò | x sin x |dx 1 + p2
0
¥
æ sin t ö
p 2p L çè
t ø
÷ = ò L (sin t) dx
= ò (x sin x) + ò -(x sin x)dx ¥
p
¥
ò 1 + x 2 a x = [ tan ]p
0 p 1 –1x
=
= [x(- cos x) - 1(- sin x)]0p - [ - x cos x + sin x ]p
2p
p
p
= ( -p cos p + sin p - 0) - = tan–1 ¥ – tan–1 p = – tan–1 p
2
éë( -2p cos p + sin 2p ) - (p cos p + sin p)ùû When p = 0,
¥
p p
= p + 0 - [ -2p + 0 - (p + 0)] = kp ò sin t dt = 2
– tan–1 (0) = .
0 2
CALCULUS S2-125
æ2 ö æ2 ö ¶y æ ¶v ö
= 6x ç =
sin ç x÷
è3 ø
sin ç x ÷
è3 ø 2 ¶x è ¶y ø÷
9. (a) lim = lim ´
x ®0 x x ®0 æ2 ö 3 \ V = 6xy + c.
çè x÷ø
3 p
13. (c) For function to be continuous at x =
2
æ 2ö 2 æ sin x ö
=1× ç ÷= çè lim = 1÷ +
è 3ø 3 x ®0 x ø æpö æpö æpö
–
fç ÷ = fç ÷ = fç ÷
è2ø è2ø è2ø
L2
10. (d) x2 = y
2h æ pö
lim f ( x ) = f ç ÷ = 1
2
x × 2h
x®2 è 2ø
y=
L2 l cos x
lim f ( x ) = lim
dy 8hx p p p
= 2 x® x® –1
dx L 2 2 2
L/2 2 l sin x
æ dy ö = limp – = 1. (L’hospitable rule)
Length of curve = 2 ò 1 + ç ÷ dx
è dx ø x®
–1
0 2
EBD_7203
S2-126 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
a f ''(4) = 6 (+ve) \ minimum at x = 4
x f ''(2) = – 6 (–ve) \ maximum at x = 2.
14. (b) I = ò x + a – x
dx ... (1)
21. (d) Time taken to travel stationary point
0
a a 8
= hours
ò f ( x ) dx = ò f ( a – x ) dxp 60 ´ 60
0 0
a
280
a–x Distance travelled = = 0.28 m
\ I= ò a–x× x
... (2) 1000
0 D distance 0.280
Adding (1) and (2), Speed = = = 126 km/hr..
D time 8
a ´ 60
60
2I = ò 1 dx
0
22. (a) f(x) = 2x3 – 3x2 – 36x
f '(x) = 6x2 – 6x – 36
a
\ I= . To get maximum and minimum values, take f '(x) = 0
2 f ' (x) = 0 Þ 6(x2 – x – 6) = 0
r r x2 – 3x + 2x + 6 = 0
( )
2
15. (a) a2 b2 – a × b = (a2 × b2) – a2 b2 cos q \ x = –2, 3
r r 2 f ''(x) = 126 – 6
= a2 b2 sin2 q = a ´ b . f ''(– 2) = – 30 (less than zero; maxima)
16. (a) f ''(3) = 36.6 (minimum).
23. (b)
17. (a) Area = OP ´ OR = ( ai + bi) ´ ( i ´ j) 24. (d) The given series is the expansion of sin
\ lim f ( x ) = lim sin x = 1.
= bc ( –k ) + ad ( k ) = ad – bc. p p
x® x®
2 2
x3 + x 2 x +1
18. (b) f(x) = lim = lim x3 + x 2 x +1 1
x®0 2x – 7x 3 2 x ®0 2x – 7 25. (b) lim = lim =– .
x ®0 2x 3 – 7x 2 x ® 0 2x – 7 7
0 +1 1
= =– . 26. (a) f(x) = 2x3 – 3x2 – 36x + 2
0–7 7 f¢(x) = 6x2 – 6x – 36
19. (a) Equation of plane OQR, f¢(x) = 0
Þ 6x2 – 6x – 36 = 0
x y 2 1 Þ x2 – x – 6 = 0
0 0 0 1 Þ (x – 3) (x + 2) = 0
=0 \ x = 3, –2
1 3 4 1
f¢¢(x) = 12x – 6
2 1 –2 1 At x = 3, f¢¢(x) = 30 > 0 (minima).
Expanding with respect to R2, At x = –2, f¢¢(x) = –30 > 0 (maxima).
27. (a) f(x) = 2x(3x – 2) = 6x2 – 4x
x y z f¢(x) = 12x – 4
1 3 4 =0 f¢¢(x) = 12
2 1 –2 f¢(x) = 0
Þ 4(3x – 1) = 0
Expanding with respect to R1,
x(– 6 – 4) – y(– 2 – 8) + 2(1 – 6) = 0 1
Þ x=
Þ 2x – 2y + 2 = 0 3
Distance from P to plane OQR is æ1ö
f = ç ÷ = 12 (minima).
2 ´ 3 – 2 ´ ( – 2 ) + ( –1) 9 è 3ø
= = = 3.
2 + ( – 2) + 1
2 2 3 sin x
28. (b) lim
20. (c) f(x) = – x3 9x2
+ 24x + 4 x ®0 x
f '(x) = 3x2 – 18x + 24 = (x2 – 6x + 8)3 0
f ''(x) = (2x – 6)3 = 6(x – 3) we get value as which is not defined
0
For maximum and minimum values, take f’(x) = 0
\ we apply L’Hospitable Rule
f ' (x) = 0
\ x2 – 6x + 8 = 0 sin x cos x
\ lim = lim = 1.
(x – 4) (x – 2) = 0 x ®0 x x ®0 1
x = 4, 2
CALCULUS S2-127
xa –3p – p p 3p
29. (d) lim Sum of residues = ... + 2 + 2 + 2 – 2 ... = 0
x ®0 xb
\ Singularities set = f
0 l = 2p i (åRo)
we get as , so apply L¢Hospitable Rule
0 = 2p i × 0 åRo – Sum of residues
\ lim
xa
= lim
a xa – 1 l= Ñò sec z dz = 0.
x ®0 xb x®0 b x b –1 33. (d) For orthogonal vectors, a1 a2 = b1 b2 = c1 c2 = 0.
1 1 1
ò (e )
a ( a – 1) x a – 2 x+y x+y 1
= lim
34. (b) ò ò e dx dy = 0
dy
b ( b – 1) x
x ®0 b–2 0 0 0
Ñò ( xy dy – y dx ) = Ñò éë( –y ) dx + xy dyùû
0
2 2 0
30. (c) Given
= (e1 + 1
– e ) – (e 1
–e) 1+0 0
c c
= (e2 – e
– e + 1)
By greens theorem, = e – 2e + 1 = (e – 1)2.
2
3 2
æ ¶N ¶M ö 35. (b) f(x) = x – 9x + 24x + 5
Ñò ( M dx + N dy) = ò ò çè ¶x –
¶y ø÷
dx dy f¢(x) = 3x2 – 18x + 24
s Condition for maxima and minima,
f¢(x) = 0
Þ ò ò ( y + 2y) dx dy Þ 3x2 – 18x + 24 = 0
s Þ x2 – 6x + 8 = 0
Since, I quadrant, (x – 4) (x – 2) = 0 Þ x = 4, 2.
1 1 36. (b) f(x) = xyz
1
ò ò 3y dy dx = 3 ( )
1
æ ¶ ¶ö
x=0 y=0 2 ò y2
0
dx Ñ × f = çi
¶
+ j + k ÷ ×f
x=0 è ¶x ¶y ¶z ø
1 = yzi + xzj + xyk
3 3 1 3
= ò 1 dx = ( x )0 = = 0 + |x| j + 0 = 1 j
2 2 2
x=0 \ Ñ × f = 1.
8 37. (b) F = y 2 x aˆ x – yzaˆ y – x 2 aˆ z along x-axis, y = 0, z = 0
31. (d) Time taken = 8 s = hours
60 ´ 60 \ dy = dz = 0
280 2
2 2
ò F.dl = ò y xdx = y 2x = 0 (Q y = 0)
Distance travelled = km 2
103
1
280 38. (b) 10x + 10 = 25
distance 103 15
Speed = = = 126 km/hr.. \ x= = 1.5 Î (1, 2)
time 8 10
´ 60
60 39. (c) f (x) = x3– 9x2 + 24x + 5 in [1, 6]
f (1) = 21, f (6) = 41
32. (a) l = Ñò sec z d z f ¢ (x) = 3x2 – 18x + 24 = 0
Residues at origin: Þ x = 2, 4
cos z = 0, sin z = 1, tan z = ¥ f ¢¢ (x) = 6x – 18
f ¢¢ (2) = – 6 < 0
p æ 1ö
\ z=np+ = pçn + ÷ f ¢¢ (4) = – 6 > 0
2 è 2ø f (2) = 25, f (4) = 21
\ Poles are at origin \ max value of f (x) in [1, 6] is 41.
–3p – p p 3p 40. (c) f ¢(x) = 2– 2x = 0 Þ x = 1
z = ..., , , , , ... f ¢¢(x) = – 2 < 0
2 2 2 2 \ max. at x = 1
EBD_7203
S2-128 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
41. (a) x = – 1 is a root of x3 + x2 + x + 1 = 0
\ (x + 1) (x2 + 1) = 0 y
Þ x = –1, i, – i
42. (a) |A| = krn (0, 2)
Þ A = krnar = Ar aˆr
Ñ. A = 0
1 é¶ 2 ù
Þ 2 êë ¶r
(r A r ) ú = 0 x
r û (2, 0)
1 éæ ¶ 2 n ö ù
Þ êç (r kr ) ÷ø ú = 0 0.2
r 2 ëè ¶r û Þ y–2= ´ ( x – 0)
2–0
1 é¶ ù
Þ 2 êë ¶r
(kr n+ 2 )ú Þ x+y=2 ...(1)
r û
Þ dx = – dy
1
Þ 2
K.(n + 2)r n+1 = 0 F (x, y) = (x2 + xy) aˆ x + ( y 2 + xy )aˆ y
r
\ n=–2 Integrating,
43. (b) p = [1,1,1]
ò F.dr = ò éë ( x + xy )dx + ( y 2 + xy )dy ù
2
2 û
q = [1, a, a ] c
–1 + i 3 From (1)
a=
2 é ù
2 ê ò F.dr =ò ( x 2 + x (2 – x)dx + (( x – x ) 2 + x (2 – x))(– dx) ú
p.q = 1 + a + a êë úû
c
2
–1 + i 3 æ –1 + i 3 ö
= 1+ +ç ÷ø = –1
2 è 2 2
\ vectors are orthogonal. = ò éë x 2 + (2 – x)2 ùûdx = 0
0
sin t
44. (b) f (t ) =
t 50. (a) V (x1y1z) = – (x cos xy + y) i + (y cos xy) j +
lim f (t ) = 1 but f (0) does not exist (sin z2 + x2 + y2) k
t ®¥
p cos x pb
\ ò0 (a + b cos x)2 dx = (a 2 – b2 )3 / 2 . =
(n –1)(n – 3)...2 n
a , if n is odd ï
ü
n(n – 2)...3 ï
(2) Leibnitz’s rule for variable limits of integration ý
(n – 1) (n – 3)...1 p n ...(i)
= . a ,if n is even ï
¶f ( x, a) n(n – 2)...2 2 ïþ
If f (x, a), be continuous functions of x and
¶a
a, then Now integrating by parts, we have
{ }
1
d y (a ) x n +1 1 x n +1 1
ò f ( x, a )dx 1 n
d a f(a ) ò x sin –1 x dx = (sin –1
x ). –ò dx
0 n + 1 0 0 n + 1 (1 – x 2 )
y ( a ) ¶f ( x, a ) dy dy df
=ò dx + + f [y (a), a] – f [ f(a ), a ]
f(a ) ¶a da da da 1 é p 1 x n +1 ù
(n + 1) ëê 2 ò0 (1 – x 2 ) ûú
= ê – ú [Using (i) ]
provided f (a) and y (a) possesses continuous first
order derivatives w.r.t.a.
Its proof is beyond the scope of this book. 1 ìp n(n – 2)(n – 4)...1 p ü
69. (i) We have the reduction formula = í – ý when n is odd
n + 1 î 2 (n + 1)(n –1)( n – 3)... 2 þ
n sin n –1 x cos x n –1
ò sin x dx = sin n – 2 x dx
n ò
+ 1 ìp n(n – 2)( n – 4)...2 ü
n = í – ý when n is even
n + 1 î 2 (n + 1)(n –1)( n – 3)... þ
Putting n = 4, 2 successively,
EBD_7203
S2-132 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
71. (i) We have the reduction formula : p/2 p/2
m –1 3 =ò log sin 2 xdx – ò log 2 dx
m 2 sin x cos x m –1 0 0
ò sin x cos x dx =
m+2
+
m+2 p/ 2 p/2
m –2 2
= ò0 log sin 2 xdx – log 2 ò
0
dx
ò sin x cos x dx
p/2 p
Putting m = 4, 2 successively, =ò log sin 2 xdx – log 2 | x |p0 / 2 = I '- log 2 ...(iii)
0 2
4 2 sin 3 x cos3 x 3 p/2
ò sin x cos x dx = – 6
+ ò sin 2 x cos 2 x dx
6 where I¢ = ò
0
log sin 2 x dx
....(1)
é Put, 2 x = t ,so that 2 dx = dt
2 2 sin x cos3 x 1 2 ê When x = 0, t = 0; when x = p / 2, t = p
ò sin x cos x dx = –
4
+
4 ò cos x dx ë
1 p/2 1 p
1 2 1æ 1 ö
But ò cos x dx = ò (1 + cos 2 x) dx = ç x + sin 2 x ÷
= ò
2 0
log sin t dt = ò log sin x dx
2 0
2 2è 2 ø [Q log sin (p – x) = log sin x,
2 sin x cos3 x 1 1 p/2
\ ò sin x cos 2 x dx = – + (2 x + sin 2 x ) = .2ò log sin x dx = I.
4 16 2 0
Substituting this in (1), we get Thus from (iii), 2I = I – (p/2) log 2, i.e., I = – (p/2) log 2.
1/ n
4 2 sin3 x cos3 x 1 ìæ 1 ö æ 2 ö æ n ö ü
ò sin x cos x dx = – 6
+
2
73. Let P = Lt íç1 + ÷ ç1 + ÷ ... ç1 + ÷ ý
n ®¥ îè n ø è n ø è n øþ
.
¥ t6 p/ 2 tan 6 q æ rö 1
sec 2 qd q Its general term = log çè1 + ÷ø . = log(1 + x).dx
ò0 (1 + t 2 )7
dt = ò
0 sec14 q
n n
[Putting r/n = x and 1/n = dx]
p/2 5.3.1 ´ 5.3.1 p 5p Also for first term r = 1 and for the last term r = n.
=ò sin 6 q cos6 q d q = ´ = .
0 12.10.8.6.4.2 2 2048 \ The lower limit of integration = Lt (1/ n) = 0
n ®¥
(iii) Putting x = tan q, so that
and the upper limit = Lt (n / n) = 1
¥ x2 p / 2 tan 2 q n ®¥
=ò dx = ò sec 2 qd q
0 2 7/2 0 7
(1 + x ) sec q 1 1
Hence log P = ò log(1 + x) dx = ò log(1 + x).1dx
0 0
p/2 1.2 2
=ò sin 2 q cos3 qd q = = . [Integrate by parts]
0 5.3.1 15
1 1 1
p/2 = log(1 + x).x 0 – ò0 .x dx
72. Let I = ò log sin x dx. ...(i) 1+ x
0
11 + x – 1 1 1 dx
p/2 p/2 = log 2 – ò dx = log 2 – ò dx + ò
then I = ò log sin(p / 2 – x) dx = ò log cos x dx 0 1+ x 0 0 1+ x
0 0
...(ii) 1
= log 2 – x 0 + log(1 + x) 0 = log 2 –1 + log 2
1
Adding (i) and (ii)
p/2
= log22 – loge e = log (4/e). Hence, P = 4/e.
2I = ò (log sin x + log cos x) dx
0
p/2 p/2 æ sin 2 x ö
=ò log(sin x cos x ) dx = ò log ç dx
0 0 è 2 ÷ø
1
Page – 1 - 46
DIGITAL LOGIC
O Ø
Ø
Binary Arithematic, Signed numbers
T Ø
Ø
Digital IC families
N
T
S
EBD_7203
S3-2 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
NUMBER SYSTEM
In general, in any number system there is an ordered set of symbols known as digits
with rules defined for performing arithmetic operations like addition, subtraction,
multiplication and division. A collection of these digits makes a number which in general
has two parts-integer and fractional.
The digits in a number are placed side by side and each position in the number is
assigned a weight or index. Table 1 below gives the details of commonly used number
systems.
Table 1
SIGNED NUMBERS
Representation for signed binary numbers:
(i) Signed and Magnitude: In this representation, MSB is used to represent sign (0
for positive and 1 for negative) and remaining bits are used to represent magnitude
of the number. e.g., binary 6-bit number 011010 represent a positive number and
its value is 26, where as 111010 represents a negative number written as –26.
DIGITAL LOGIC S3-5
(ii) One’s complement notation: In a binary number, if we replace each 0 by 1. and
each 1 by 0, we obtain another binary number which is one’s complement of the
first binary number. e.g., while (0111)2 represents (+7)10, (1000)2.
In general, maximum positive and negative number that can be represented by
(2n–1 – 1) and – (2n–1 – 1) respectively.
(iii) Two’s complement notation: By adding 1 to the one’s complement of a binary
numbers we get two’s complement of that binary number. e.g., 0101 represents +5,
where as its complement, 1011 (1s complement +1) represents –5.
CO D ES
1. BCD code
Þ Binary coded decimal
Þ Weighted code
Þ 4 bit code
Þ 8421 code
Þ Each decimal digit is represented with 4 bit.
Decimal BCD Excess 3 code
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
1010ü
1011ïï
1100ïï
ý invalid BCD code or don ' t care.
1101ï
1110ï
ï
1111ïþ
Þ During Arithmetic operation if invalid BCD present the add 0110 to got correct
result.
Þ For write BCD code each digit (decimal) is write separately in BCD.
e.g. (534)10 = (01010011 0100)BCD.
2. Excess – 3code
Excess – 3 code = BCD + 3
Unweighted code
4 bit code.
Decimal Excess – 3 code
0 0011
1 0100
2 0101
3 0110
4 0111
5 1000 self complement
6 1001
7 1010
8 1011
9 1100
EBD_7203
S3-6 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Þ It is self complement code.
Þ Only unweighted code which is self complement is Excess 3-code.
Þ The code which addition is 9 is self complement code.
eg. 2421ü ü
3321ïï ï
ï
ý weighted ý self compemented
4311ï ï
5211ïþ ïþ
Decimal 2421
0 0000
1 0001
2 0010
3 0011
4 0100
5 1011 self complement
6 1100
7 1101
8 1110
9 1111
3. Binary to Gray code
(A) Binary to Gray:-
Þ Unweighted code.
Þ Successive no. is differ by 1 bit.
Þ Also called unit distance code.
Þ Also cyclic code, Reflective code and Minimum error code.
Binary 1 0 1 1 B3 B 2 B1 B0
1 1 1 0 G3 G2 G1 G0
B3 G3
B2 G2
B1 G1
B0 G0
B3 B2 B1 B0
1 0 1 1
DIGITAL LOGIC S3-7
G3 B3
G2 B2
G1 B1
G0 B0
Inputs Output
R= P+ Q P
P Q R=P+Q
Q
0 0 0
: 0 1 1 Fig.OR
1 (a)Gate
: OR Gate
1 0 1
1 1 1
AND Gate: Its symbol is given in the fig. 1(b) & its truth table is 4(b)
Table 4(b)
Inputs Output
P
R=P.Q R=PQ
P Q Q
0 0 0
0 1 0 Fig. 1 (b) : AND Gate
1 0 0
1 1 1
NOT Gate (Inverter): Its symbol is given in the fig. 1(c) & its truth table is 4(c)
Table 4(c)
Inp ut P Ou tp ut R P R=P
0 1 Fig. 1 (c) : NOT Gate
1 0
NAND Gate: Its symbol is given in in the fig. 1(d) & its truth table is 4(d)
Table 4(d)
Inputs O utpu t
R P
P Q R=P.Q
0 0 1 Q
0 1 1
Fig. 1 (d) : NAND Gate
1 0 1
1 1 0
NOR Gate: Its symbol is given in the fig. 1(e) & its truth table is 4(e)
Table 4(e)
Inputs O utpu t
R
P Q
0 0 1 P
R=P+Q
0 1 0 Q
1 0 0
1 1 0 Fig. NOR
1 (e) :gate
NOR Gate
EBD_7203
S3-8 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
BOOLEAN ALG EBRA
• It is used to simplify the design of logic circuits.
• Here we make use of boolean logic operations, properties of boolean algebra &
binary addition & multiplication.
- Commutative Property: P+Q = Q+P
- Associative property: P + (Q + R) = (P + Q) + R
- Distributive property: P + QR =(P + Q)(P + R)
Some more Boolean laws :
(1) P + 0 = P (2) P + 1 = 1 (3) P + P = P (4) P + P = 1 (5) P.1 = P
(6) P.0 = 0 (7) P.P = P (8) P.P = 0 (9) P = P (10) P = P
Demorgan’s Theorems :
• PQ = P + Q
• P + Q = P.Q
Half Adder
In order to solve arithmetic operations, this type of devices are introduced. Half Adder
is used for the addition of two bits. Half adder generates two outputs as SUM and
CARRY. The logical diagram along with truth table 5 is depicted.
A Sum = A Å B
Sum Carry = A.B
B
Truth Table
Table 5
Cout A B SUM (S) CARRY (C)
0 0 0 0
Fig. 2 : Half adder 0 1 1 0
1 0 1 0
1 1 0 1
FULL ADDER
A full adder is a device capable of adding three bits as shown in figure. Full Adder
generates two outputs same as half adder.
VDD
Q1 Sum = A Å B Å C
Carry = AB + BC + CA
Q2 Truth Table
C
Table 6
Q3
A A B Carry-in (C in ) SUM (S) CARRY (C)
0 0 0 0 0
B 0 0 1 1 0
Q4
Schematic 0 1 0 1 0
0 1 1 0 1
Fig. 3
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
A Multiplexer is a Data selector, which gets several input signals to the single output.
The method of selecting one of the several inputs is controlled by Control lines. We can
define multiplexer as "a device consists of n-input line and having a single output line
to process". Generally multiplexers are used in parallel - to serial conversion of data
because it is used for routing several signals to the same destination, for example bus,
synchronous transmission etc. In other words, we can say that a multiplexer is a digitally n input Multiplexer
signals 1 output
controlled multi-position switch. The fig. 6 (a) shows the block diagram of a multiplexer: signal
Fig. 6 (b) shows the example of a 4 ´ 1 multiplexer along with two control lines:
Table 8
Fig. 6 (a): Block diagram of multiplexer
Input Input Output
S1 S0
S1 S2 Y
0 0 D0
0 1 D1 D0
1 0 D2 D1
1 1 D3 Y
D2
From table 8 output, Y = S1S2 D0 + S1S2 D1 + S1S2 D 2 + S1S2 D3 D3
Application of MUX:
• Data Routing Fig. 6 (b): 4-to-1 multiplexer
• Logic Function generator
m select signals
• Control Sequencer
• Conversion parallel to series
DEMULTIPLEXER
The working of a demultiplexer is exactly opposite to that of a multiplexer. Demultiplexer 1 input
signal
receives information from a single line and transmits it to several lines. That is why Demultiplexer n output
demultiplexer is used in serial-to-parallel conversion and Data Distributors. The fig. 7 signals
(a) shows the block diagram of a Demultiplexer with one input signal, m select signals
and n output signals.
Fig. 7 (a): Block diagram of demultiplexer
Fig. 7 (b) shows the example of 1 ´ 4 demultiplexer along with two control lines.
EBD_7203
S3-12 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Data Table 9
input S1 S0
D Data Control Control
input input Input Output
D S1 S2 Y3 Y2 Y1 Y0
Y0
D 0 0 0 0 0 D
Y1
D 0 1 0 0 D 0
Y2 D 1 0 0 D 0 0
Y3 D 1 1 D 0 0 0
Q n +1 = Sn + R n¢ Q n
Table 11: S-R Flip-flop Truth Table S=J.Q Q
J 1 S
Q S R Q(t+1) CLK
K R=K.Q
0 0 0 0 2 R Q
0 0 1 0
0 1 0 1 Fig. 8 (e): J-K flip-flop using S-R flip-flop
0 1 1 Indeterminate
1 0 0 1 J Q
1 0 1 0
1 1 0 1
K Q
1 1 1 Indeterminate
The disadvantage of S-R flip-flop is for S = 1, R = 1 output cannot be determined. Fig. 8 (f): Graphic symbol of J-K flip flop
This can be eliminated in J-K flip-flop.
S-R flip flop can be converted to J-K flip-flop by using the two equation S = JQ’
and R = KQ.
(c) J-K Flip-flops :
• It has two inputs: J & K & two outputs: Q & Q .
• The two outputs Q & Q are complement to each other..
• It can be designed by using S-R flip flops. Table 12
• Here we have created a J-K flip flop using clocked S-R flip flop with its
symbol as shown in fig. 8 (e) and 8 (f) respectively.
• Its truth table can be made as shown in Table 12
The Master-Slave JK Flip-flop
The Master-Slave Flip-Flop is basically two gated SR flip-flops connected
together in a series configuration with the slave having an inverted clock pulse.
The outputs from Q and Q from the “Slave” flip-flop are fed back to the inputs of
the “Master” with the outputs of the “Master” flip-flop being connected to the
two inputs of the “Slave” flip-flop. This feedback configuration from the slave’s
"Master Latch" "Slave Latch"
output to the master's input gives the characteristic toggle of the JK flip-flop as
shown in J Q
fig. 8 (g). Clk
The input signals J and K are connected to the gated “master” SR flip-flop which K Q
“locks” the input condition while the clock (Clk) input is “HIGH” at logic level “1”. Clk
As the clock input of the “slave” flip-flop is the inverse (complement) of the
Fig. 8 (g): The Master-Slave JK Flip-Flop
“master” clock input, the “slave” SR flip-flop does not toggle. The outputs from
the “master”flip-flop are only “seen” by the gated “slave” flip-flop when the
clock input goes “LOW” to logic level “0”.
When the clock is “LOW”, the outputs from the “master” flip-flop are latched and
any additional changes to its inputs are ignored. The gated “slave” flip-flop now
D S(Set)
responds to the state of its inputs passed over by the “master” section. Then on 1
3 Q
the “Low-to-High” transition of the clock pulse the inputs of the “master” flip-
flop are fed through to the gated inputs of the “slave” flip-flop and on the “High- CLK
to-Low” transition the same inputs are reflected on the output of the “slave”
R 4 Q
making this type of flip-flop edge or pulse-triggered. 2
Then, the circuit accepts input data when the clock signal is “HIGH”, and passes (Clear)
the data to the output on the falling-edge of the clock signal. In other words, the (a) Using NAND gates
Fig. 8 (h) : D-flip-flopUsing
Master-Slave JK Flip-flop is a “Synchronous” device as it only passes data with NAND gates
the timing of the clock signal. D Q
(d) D Flip-flops :
• It has only one input known as D (Delay) & two outputs Q & Q . CLK Q
• It can be designed from NAND gates or through S-R flip flops. Fig. 8 (i) : Logic symbol
EBD_7203
S3-14 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
• It is given in the fig. 8 (h) along with its symbol in fig. 8 (i).
• Its truth table is shown in Table 13
Table 13
CLK Input (D) Output (Qn +1)
1 0 0
1 1 1
0 X No change
(e) T Flip-flops
J Q • It is also known as trigger or toggle flip flop.
CLK • It has only one data input denoted by T, a clock input & two outputs Q & Q .
K Q • It can be designed by using J-K flip flop where J & K inputs are wired together.
Fig. 8 (j) : T flip flop using a J-K-flip flop • It is given in fig. 8 (j) with its symbol fig. 8 (k).
• Its truth table is shown here:
T Q Table 14
CLK Input (T) Output (Qn +1)
CLK Q 0 0 0
0 1 1
Fig. 8 (k) : Block diagram of T flip flop
1 0 1
1 1 0
CO UN TERS
A counter is a special kind of register, designed to count the number of clock pulses
arriving at its input. It is one of the most useful subsystem in a digital systems. The input
to this counter is a rectangular waveform called clock. Each time the clock signal changes
state from low to high, the counter will add one (1) to the number stored in its flip flop.
This means the counter will count the number of clock transitions from low to high.
A clock having a small circle (bubble) in the input side would count clock transitions
form high to low. Since clock pulses occur at known intervals, 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: The ripple counter is the simplest of all kinds of counters.
But the problem with it is its delay time. In a ripple counter each flip - flop has a
delay time and these delay times are additive. Therefore the total "settling" time
for the counter is equal to the delay time multiplied by total number of flip - flops.
This problem can be overcome by the use of a synchronous or parallel counter.
Here every flip-flop is triggered in synchronism with the clock.
The fig. 9 (a) shows how to build a synchronous counter with positive - edge
triggered flip - flop. Here the clock pulses drive all the flip -flop in parallel.
The J and K inputs of Q0 flip-flop are tied to a high voltage. Therefore, it responds
Q3 J3 Q2 J2 Q1 J1 Q0 J0 High to each positive clock edge. But the remaining flip flops can responds to the +ve
Q3 K 3 Q2 K2 Q 1 K1 Q0 K0 clock edge with certain conditions. The Q1 flip flop toggles on the positive clock
CLR edge only when Q0 is 1, the Q2 flip flop toggles only when Q1, Q0 are 1; the Q3 flip
Fig. 9 (a) : Synchronous counter flop toggles only when Q2, Q1 and Q0 are 1. That is , a flip - flop toggles on the next
+ve clock edge if all lower bits are 1.
Here is the counting action. A low CLR reset the counter. Q = 0000. When the CLR
goes high, the counter is ready to go. The first +ve clock edge sets Q, therefore Q
= 0001.
(i) Ring Counter: A ring counter is a shift-left register because the bits are
DIGITAL LOGIC S3-15
shifted left one position per positive clock edge. But the final output is
feedback to the D0 input. This kind of action is known as “rotate left” the bits
are shifted left and fed back to the input.
The following fig. 9 (b) is a ring counter built with D flip flops.
When CLR goes low, the initial o/p word is Q = 0001. The first positive clock
edge shifts MSB into LSB. The other bits shift left one position. Therefore
the output word becomes Q = 0010. Fig. 9 (b) : Ring counter
The second positive clock edge causes another rotate left and o/p word
becomes Q = 0100.
After third positive clock edge, the output word is Q = 1000.
The fourth positive clock edge starts the cycle and rotate left produces
Q = 0001.
The stored 1 bit follows a circular path. This is why the circuit is called a ring
counter. By adding more flip-flops we can build a ring counter of any length.
(ii) Decode counter ( Mode - 10 counter) : A counter with 10 distinct states is
known as a decade counter. This counter counts 10 sequences and reset on
10th clock pulse. That is, the circuit count from 0000 to 1001 and on the tenth
clock pulse, it generates its own clear signal and count jump back to 0000.
The following shown in fig. 9 (c) is the mod –10 counter design.
The counter can be reset, if the AND gate output is low. This can be happened
with a low CLR or low Y. Initially low CLR produce Q = 0000. when CLR is
high, the counter is ready and count sequence progress.
The output of the NAND gate is, Y = Q3 Q1. This output is high for the first
nine states ( 0000 to 1001). Nothing happens when the circuit is counting
from 0 to 9 on the tenth clock pulse, the Q word becomes; Q = 1010, which
means that Q3 and Q1 are high. Then immediately Y goes low, forcing the
counter to reset to Q = 0000.
Q3 J3 Q2 J2 Q1 J1 Q0PR J0
Q3 K3 Q2 K2 Q1 K1 Q0 K0 CLK
CLR
Y
Fig. 9 (c) : Decode counter
(b) Asynchronous counter (ripple counter): When the output of a flip-flop is used as
the clock input for the next flip-flop we call the counter as a ripple counter or
asynchronous counter. The triggers move through the flip-flops like ripple in
water — because of this, the over all settling time is the sum of the individual
delays. Fig. 9 (d) shows a 3 bit asynchronous counter with timing diagram.
y0
A (MSB) y1
2 ×4
Decoder y2
B y3
E
Fig. 15 (a)
EBD_7203
S3-18 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Truth table:-
EAB y3 y2 y1 y0
0xx 0 0 0 0
10 0 0 0 0 1
101 0 0 1 0
11 0 0 1 0 0
111 1 0 0 0
logical expression:-
y0 = A B E
y1 = A B E
y2 = A B E
y3 = AB E
A B
E y0
y1
y2
y3
Fig. 15 (b)
Þ Decoder and Demux internal ckt remains sam.
Q. Implement Halt adder using 2 × 4 decoder.
AB
A (MSB) AB
2 ×4 AB Sum = AB + AB
B Decoder
AB CARRY = AB
E=1
Fig. 15 (c)
Þ We implement HA using 1 – 2 × 4 Decoder and 1 or gate and same for HS.
AB
BARROW = AB
A AB
2 ×4 AB AB + AB
Decoder
B AB
E=1
Fig. 15 (d)
Binary to octal Decoder:-
Þ Also called as 3 × 8 Decoder
DIGITAL LOGIC S3-19
ABC
y0
ABC
y1
ABC y
A (MSB) 2
ABC y
3×8 3
B Decoder ABC
y4
C ABC
y5
ABC
y6
A B C y7
E=1
Fig. 15 (e)
Q. Implement using 3 × 8 Decoder. make FA.
Sol. Sum = S m (1, 2, 4, 7)
= A B C + A B C + A B C + ABC
CARRY = Sm (3, 5, 6, 7)
0
1
2
A (MSB)
3 SUM
B 4
C 5
6 CARRY
7
Fig. 15 (f)
THE SHIFT REGISTER
The Shift Register is another type of sequential logic circuit that 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". It basically consists of several single
bit "D-Type Data Latches", one for each bit (0 or 1) connected together in a serial or
daisy-chain arrangement so that the output from one data latch becomes the input of the
next latch and so on.
The data bits may be fed in or out of the register serially, i.e. one after the other from
either the left or the right direction, or in parallel, i.e. all together. The number of individual
data latches required to make up a single Shift Register is determined by the number of
bits to be stored with the most common being 8-bits (one byte) wide, i.e. eight individual
data latches.
Generally, shift registers operate in one of four different modes with the basic movement
of data through a shift register being:
• Serial-In To Parallel-Out (SIPO) - the register is loaded 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 "IN" and "OUT" of the
register, one bit at a time in either a left or right direction under clock control.
• Parallel-In To Serial-Out (PISO) - the parallel data is loaded into the register simulta-
neously and is shifted out of the register serially one bit at a time under clock control.
• Parallel-In To Parallel-Out (PIPO) - the parallel data is loaded simultaneously into
the register, and transferred together to their respective outputs by the same
clock pulse.
EBD_7203
S3-20 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The effect of data movement from left to right through a shift register can be presented
graphically as:
Parallel Data Output
Q3 Q2 Q1 Q0
MSB LSB
Serial D Q Serial
Data Data
Input Output
1-bit 1-bit 1-bit 1-bit
MSB LSB
D3 D2 D1 D0
QA QB QC QD
D Q D Q D Q D Q
Serial
Data in
FFA FFB FFC FFD
Clear
Clock
Fig. 16 (b)
The operation is as follows. Lets assume that all the flip-flops ( FFA to FFD ) have just
been RESET ( CLEAR input ) and that all the outputs QA to QD are at logic level "0" i.e, no
parallel data output. If a logic "1" is connected to the DATA input pin of FFA then on the
first clock pulse the output of FFA and therefore the resulting QA will be set HIGH to logic
"1" with all the other outputs still remaining LOW at logic "0". Assume now that the
DATA input pin of FFA has returned LOW again to logic "0" giving us one data pulse or
0-1-0.
The second clock pulse will change the output of FFA to logic "0" and the output of FFB
and QB HIGH to logic "1" as its input D has the logic "1" level on it from QA. The logic "1"
has now moved or been "shifted" one place along the register to the right as it is now at
QA. When the third clock pulse arrives this logic "1" value moves to the output of FFC
( QC ) and so on until the arrival of the fifth clock pulse which sets all the outputs Q A to
QD back again to logic level "0" because the input to FFA has remained constant at logic
level "0".
The effect of each clock pulse is to shift the data contents of each stage one place to the
right, and this is shown in the following table until the complete data value of 0-0-0-1 is
stored in the register. This data value can now be read directly from the outputs of QA to
QD. Then the data has been converted from a serial data input signal to a parallel data
output. The truth table and following waveforms show the propagation of the logic "1"
through the register from left to right as follows.
DIGITAL LOGIC S3-21
Basic Movement of Data through a Shift Register
Clock
Pulse No. QA QB QC QD
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 0 0 0 0
1
Data 0 0
Input
1 2 3 4 5
ClK
1
0 0 0 0 0
QA
1
0 0 0 0 0
QB
1
0 0 0 0 0
QC
1
0 0 0 0 0
QD
Fig. 16 (c)
Note that after the fourth clock pulse has ended the 4-bits of data ( 0-0-0-1 ) are stored in
the register and will remain there provided clocking of the register has stopped. In
practice the input data to the register may consist of various combinations of logic "1"
and "0". Commonly available SIPO IC's include the standard 8-bit 74LS164 or the 74LS594.
Serial-in to Serial-out (SISO)
This shift register is very similar to the SIPO above, except were before the data was read
directly in a parallel form from the outputs QA to QD, this time the data is allowed to flow
straight through the register and out of the other end. Since there is only one output, the
DATA leaves the shift register one bit at a time in a serial pattern, hence the name Serial-
In To Serial-Out Shift Register or SISO.
The SISO shift register is one of the simplest of the four configurations as it has only
three connections, the Serial Input (SI) which determines what enters the left hand flip-
flop, the Serial Output (SO) which is taken from the output of the right hand flip-flop and
the sequencing clock signal (Clk). The logic circuit diagram below shows a generalized
serial-in serial-out shift register.
4-bit Serial-in to Serial-out Shift Register
1 1
0 0 0
Serial 0 1 0 1
D Q D Q D Q D Q Q
Data in
FFA FFB FFC FFD Serial
Data Out
CLK CLK CLK CLK
Clock
Fig. 16 (d)
EBD_7203
S3-22 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
You may think what's the point of a SISO shift register if the output data is exactly the
same as the input data. Well this type of Shift Register also acts as a temporary storage
device or as a time delay device for the data, with the amount of time delay being
controlled by the number of stages in the register, 4, 8, 16 etc or by varying the application
of the clock pulses. Commonly available IC's include the 74HC595 8-bit Serial-in/Serial-
out Shift Register all with 3-state outputs.
Parallel-in to Serial-out (PISO)
The Parallel-in to Serial-out shift register acts in the opposite way to the serial-in to
parallel-out one above. The data is loaded into the register in a parallel format i.e. all the
data bits enter their inputs simultaneously, to the parallel input pins PA to PD of the
register. The data is then read out sequentially in the normal shift-right mode from the
register at Q representing the data present at PA to PD.
This data is outputted one bit at a time on each clock cycle in a serial format. It is
important to note that with this system a clock pulse is not required to parallel load the
register as it is already present, but four clock pulses are required to unload the data.
4-bit Parallel-in to Serial-out Shift Register
1 mux D Q mux D Q mux D Q mux D Q Q
Serial
FFA FFB FFC FFD Data out
Clock
PD PC PB PA
4-bit Parallel Data Input
Fig. 16 (e)
As this type of shift register converts parallel data, such as an 8-bit data word into serial
format, it can be used to multiplex many different input lines into a single serial DATA
stream which can be sent directly to a computer or transmitted over a communications
line. Commonly available IC's include the 74HC166 8-bit Parallel-in/Serial-out Shift
Registers.
PARALLEL-IN TO PARALLEL- OUT (PIPO)
The final mode of operation is the Parallel-in to Parallel-out Shift Register. This type of
register also acts as a temporary storage device or as a time delay device similar to the
SISO configuration above. The data is presented in a parallel format to the parallel input
pins PA to PD and then transferred together directly to their respective output pins QA to
QA by the same clock pulse. Then one clock pulse loads and unloads the register. This
arrangement for parallel loading and unloading is shown below.
4-bit Parallel-in to Parallel-out Shift Register
4-bit Parallel Data Output
QD QC QB QA
D Q D Q D Q D Q
FFA FFB FFC FFD
CLK CLK CLK CLK
Clock
PD PC PB PA
Z
0 MUX
Which one of the following is true? [2006, 2 Marks]
1
(a) f is independent of X
(b) f is independent of Y y
(c) f is independent of Z
(d) None of X, Y, Z is redundant z 0 MUX
3. We consider the addition of two 2’s complement numbers f
bn -1b n - 2 ....b0 and a n -1a n -2 ....a 0 . A binary adder for 1
adding unsigned binary numbers is carry-out by Cout. Which x
one of the following options correctly identifies the overflow
condition? [2006, 2 Marks] y
DIGITAL LOGIC S3-25
Consider the circuit above. Which one of the following The counter is connected as follows
options correctly represents f(x, y, z)? [2006, 2 Marks] A4 A3 A2 A1
(a) xz + xy + yz (b) xz + xy + yz
(c) xz + xy + yz (d) xz + xy + yz
7. You are given a free running clock with a duty cycle of 50%
and a digital waveform f which changes only at the negative Count = 1
edge of the clock. Which one of the following circuits (using 4-bit counter Load = 0
Clear Clock
clocked D flip-flops) will delay the phase of f by 180°?
[2006, 1 Mark] Input
f D D Q 0 0 1 1
Assume that the counter and gate delays are negligible. If
Q
the counter starts at 0, then it cycles through the following
(a) sequence
(a) 0, 3, 4 (b) 0, 3, 4, 5
CLK (c) 0, 1, 2, 3, 4 (d) 0, 1, 2, 3, 4, 5
9. In a look-ahead carry generator, the carry generate function
Gi and the carry propagate function Pi for inputs Ai and Bi
Q are given by [2007, 2 Marks]
f D Q D
Pi = Ai Å Bi and Gi = Ai Bi
CLK The expressions for the sum bit Si and the carry bit Ci + 1 of
the look-ahead carry adder are given by
(b)
Si = Pi Å Ci and Ci +1 = Gi + Pi Ci , where C0 is the input
carry.
Consider a two-level logic implementation of the look-
ahead carry generator. Assume that all Pi and Gi are
f D Q D Q available for the carry generator circuit and that the AND
and OR gates can have any number of inputs. The number
CLK of AND gates and OR gates needed to implement the look-
(c) ahead carry generator for a 40-bit adder with S3, S2, S1, S0
and C4 as its outputs are respectively
(a) 6, 3 (b) 10, 4
(c) 6, 4 (d) 10, 5
10. Suppose only one multiplexer and one inverter are allowed
to be used to implement any Boolean function of n variables.
f D D Q What is the minimum size of the multiplexer needed?
[2007, 2 Marks]
Q (a) 2n line to 1 line (b) 2n + 1 line to 1 line
(d) (c) 2n – 1 line to 1 line (d) 2n – 2 line to 1 line
11. Define the connective * for the Boolean variables X and Y as
X*Y = XY + X’Y’. Let Z = X*Y. Consider the following
CLK expressions P, Q and R”
P:X=Y*Z Q:Y=X*Z
8. The control signal functions of a 4-bit binary counter are R:X*Y*Z=1
given below (where x is don’t care): [2007, 2 Marks] Which of the following is true? [2007, 2 Marks]
(a) P and Q are valid (b) Q and R are valid
Clear Clock Load Count Function (c) P and R are valid (d) All P, Q, R are valid
12. Let f(w, x, y, z) = å ( 0, 4, 5, 7,8,9,13,15) . Which of the
1 × × × Clear to 0 following expressions is pre not equivalent to f?
0 × 0 0 No change (P) x’y’z’ + w’xy’ + wy’z + xz [2007, 2 Marks]
(Q) w’y’z’ + wx’y’ + xz
0 1 × Load input (R) w’y’z’ + wx’y’ + xyz + xy’z
0 0 1 Count next (S) x’y’z’ + wx’y’ + w’y
(a) P only (b) Q and S
(c) R and S (d) S only
EBD_7203
S3-26 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
13. Consider the following Boolean function of four variables: 19. In the IEEE floating point representation, the hexadecimal
value 0 × 00000000 corresponds to [2008, 1 Mark]
f ( w, x, y, z ) = å (1,3, 4, 6,9,11,12,14 ) [2007, 1 Mark]
(a) the normalized value 2–127
The function is (b) the normalized value 2–126
(a) independent of one variable (c) the normalized value + 0
(b) independent of two variables (d) the special value +0
(c) independent of three variables 20. If P, Q, R are Boolean variables, then [2008, 2 Marks]
(d) independent of all variables
14. How many 3-to-8 line decoders with an enable input are ( P + Q )( P.Q + P.R )( P.R + Q ) simplifies to
needed to construct a 6-to-64 line decoder without using
any other logic gates? [2007, 1 Mark] (a) P.Q (b) P.R
(a) 7 (b) 8 (c) P.Q + R (d) P.R + Q
(c) 9 (d) 10
21. What is the minimum number of gates required to
15. What is the maximum number of different Boolean
implement the Boolean function (AB + C), if we have to
functions involving n Boolean variables? [2007, 1 Mark]
use only 2-input NOR gates) [2009, 1 Mark]
(a) n2 (b) 2n
(a) 2 (b) 3
n
(c) 22 (d) 2n 2 (c) 4 (d) 5
16. Given f1, f3 and f in canonical sum of products form (in 22. (1217)8 is equivalent to [2009, 1 Mark]
decimal) for the circuit [2008, 1 Mark] (a) (1217)16 (b) (028F)16
(c) (2297)10 (d) (0B17)16
f1 23. In the sequential circuit shown below, if the initial value
f2 of the output Q1Q0 is 00, what are the next four values of
Q1Q0? [2010, 2 Marks]
f
f3
T Q
1 T Q
f1 = å m ( 4, 5, 6, 7,8 ) , f3 = å m (1, 6,15 )
f = å m (1,6,8,15) Clock
Then f2 is
Q0 Q1
(a) å m ( 4, 6 ) (b) å m ( 4,8)
(a) 11, 10, 01, 00 (b) 10, 11, 01, 00
(c) å m ( 6,8) (d) å m ( 4, 6,8 ) (c) 10, 00, 01, 11 (c) 11, 10, 00, 01
17. Let r denotes number system radix. The only value(s) of r 24. What is the Boolean expression for the output F of the
combinational logic circuit of NOR gates given below?
that satisfy the equation 121r = 11r is/are [2008, 1 Mark]
P
(a) decimal 10 (b) decimal 11 Q
(c) decimal 10 and 11 (d) any value > 2
18. In the Karnaugh map shown below, X denotes a don’t care
term. What is the minimal form of the function represented Q
by the Karnaugh map? [2008, 1 Mark] R
ab F
cd
00 01 11 10 P
R [2010, 2 Marks]
00 1 1 1
01 x Q
R
11 x
(a) Q+R (b) P+Q
10 1 1 x (c) P + R (d) P + Q + R
25. The Boolean expression for the output F of the multiplexer
shown below is [2010, 1 Mark]
(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
DIGITAL LOGIC S3-27
32. The decimal value 0.5 in IEEE single precision floating
0
point representation has [2012, 1 Mark]
R
(a) fractions bits of 000 .... 000 and exponent value of 0
R 1 (b) fractions bits of 000 .... 000 and exponent value of – 1
F (c) fractions bits of 100 .... 000 and exponent value of 0
R 2
(d) no exact representation
S0
R 3 S
1
33. The smallest integer that can be represented by an 8-bit
Q
number in 2’s complement form is [2013, 1 Mark]
P (a) –256 (b) –128
(a) PÅQÅR (b) PÅQÅR (c) –127 (d) 0
(c) P + Q + R (d) P + Q + R 34. In the following truth table, V = 1 if and only if the input
26. P is a 16-bit signed integer. The 2’s complement is valid. [2013, 1 Mark]
representation of P is (F87B) 16 . The 2’s complement
Inputs Outputs
representation 8*P is [2010, 1 Mark]
(a) (C3D8)16 (b) (187B)16 D0 D1 D2 D3 X0 X1 V
(c) (F878)16 (d) (987B)16 0 0 0 0 x x 0
27. The minterm expansion of f(P, Q, R) = PQ + QR + PR is 1 0 0 0 0 0 1
[2010, 1 Mark] x 1 0 0 0 1 1
(a) m2 + m4 + m6 + m7 (b) m0 + m1 + m3 + m5
x x 1 0 1 0 1
(c) m0 + m1 + m6 + m7 (d) m2 + m3 + m4 + m5
x x x 1 1 1 1
28. The minimum number of D-flops needed to design a
mod-258 counter is [2011, 1 Mark] What function does the truth table represent?
(a) Priority encoder (b) Decoder
(a) 9 (b) 8
(c) Multiplexer (d) Demultiplexer
(c) 512 (d) 258
29. Which one of the following circuits is not equivalent to a 35. Which one of the following expressions does not
2-input XNOR (exclusive NOR) gate? [2011, 1 Mark] represent exclusive NOR of x and y? [2013, 1 Mark]
(a) xy + x ¢ y ¢ (b) x Å y ¢
(c) x ¢ Å y (d) x ¢ Å y ¢
(a) (b)
36. Consider the following Boolean expression for F :
F (P, Q, R, S) = PQ + PQR + PQRS
The minimal sum of products form of F is
(c) (d) [2014, Set-1, 1 Mark]
(a) PQ + QR + QS (b) P + Q + R + S
30. The simplified SOP (Sum of Products) form of the Boolean (c) P + Q + R + S (d) PR + PRS + P
( )( )(
expression P + Q + R . P + Q + R . P + Q + R is ) 37. The base (or radix) of the number system such that the
following equation holds is __________ .
[2011, 1 Mark]
312
(a) ( PQ + R ) (b) ( P + QR ) 20
= 13.1 [2014, Set-1, 1 Mark]
0 0 0 1 1
R 2 4-to-1 F
0 1 0 Multiplexer
1 0 1 R 3
S1 S0
1 1 1
represents the Boolean function [2012, 1 Mark]
(a) X (b) X + Y
(c) X Å Y (d) Y P Q
EBD_7203
S3-28 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The minimal sum of products form of the Boolean expression 42. Consider the following combinational function block
for the output F of the multiplexer is involving four Boolean variables x, y, a, b where x, a, b are
[2014, Set-1, 2 Marks] inputs and y is the output.
(a) PQ + QR + PQR f (x, y, a, b)
{
(b) PQ + PQR + PQR if (x is 1) y = a;
else y = b;
(c) PQR + PQR + QR + PQR
}
(d) PQR Which one of the following digital logic blocks is the most
39. The dual of a Boolean function F (x1, x2, ..., xn, +,., ¢), written suitable for implementing this function?
as FD, is the same expression as that of F with + and · [2014, Set-3, 1 Mark]
swapped. F is said to be self-dual if F = FD. The number of (a) Full adder (b) Priority encoder
self-dual functions with n Boolean variables is (c) Multiplexer (d) Flip-flop
[2014, Set-2, 1 Mark] 43.
(A) 2n (B) 2n–1
n -1
(C) 22n (D) 2 2 J Q2 J Q1 J Q0
40. Let k =2n. A circuit is built by giving the output of an n-bit C C C
binary counter as input to an n-to-2n bit decoder. This circuit K Q2 K Q1 K Q0
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. The above synchronous sequential circuit built using JK
(d) k-bit Johnson counter. flip-flops is initialized with Q2Q1Q0 = 000. The state
41. Consider the following minterm expression for F: sequence for this circuit for the next 3 clock cycles is
[2014, Set-3, 2 Marks]
F (P, Q, R, S) = å 0, 2,5, 7,8,10,13,15 (a) 001, 010, 011 (b) 111, 110, 101
The minterms 2, 7, 8 and 13 are ‘do not care’ terms. The (c) 100, 110, 111 (d) 100, 011, 001
minimal sum-of-products form for F is 44. Let Å denote the Exclusive OR (XOR) operation. Let ‘1’
[2014, Set-3, 1 Mark] and ‘0’ denote the binary constants.
(a) QS + QS Consider the following Boolean expression for F over two
variables P and Q:
(b) QS + QS
F(P, Q) = ((1 Å P) Å (P Å Q)) Å ((P Å Q) Å (Q Å 0))
(c) QRS + QRS + QRS + QRS The equivalent expression for F is [2014, Set-3, 2 Marks]
(a) P+ Q (b) P+Q
(d) ò PQS + PQS + PQS + PQS
(c) PÅQ (d) PÅQ
DIGITAL LOGIC S3-29
1. A signed integer has been stored in a byte using 2’s 4. In figure given below the LED emits light when
complement format. We wish to store the same integer in
16-bit word. We should copy the original byte to the less
VCC = 5 V
significant byte of the word and fill the more significant
byte with
1 kW 1 kW 1 kW
(a) 0
1 kW
(b) 1
(c) equal to the MSB of the original byte
(d) complement of the MSB of the original byte.
2. In the given combinational circuit, the output Z is 1 kW
(a) D (A C + A C) (b) (
D BÅ C + A C )
(
(c) D B Å C + A B )
(d) D (B C + A B) B R
8. The network shown in figure implements
(a) AB + AQ (b) AB + BQ
A 1 MUX (c) Both A and B (d) None of these
f 13. If the input to the digital circuit (in the figure) consisting
1 0 S0 of a cascade of 20 XOR-gates is X, then the output Y is
equal to
B 1 MUX 1
0 0 S0
Y
X
C
(a) NOR gate (b) NAND gate (a) 0 (b) 1
(c) XOR gate (d) XNOR gate (c) X (d) X
9. The MUX shown in figure is 4 × 1 multiplexer. The output
Z is 14. The counter shown in the figure is a
C I3
I2
MUX z
I1 Q J Q J Q J 1
I0 C B A
S1 S0
Q K Q K Q K 1
+5V A B
CLK
(a) ABC (b)
A Å BÅ C
(a) MOD-8 up counter (b) MOD-8 down counter
(c) A B C (d) A + B + C
(c) MOD-6 up counter (d) MOD-6 down counter
10. The input signal Vi shown in figure is applied to a FF 15. The mod-number of the asynchronous counter shown in
figure when initially in its 0-state. Assume all timing figure is
constraints are satisfied. The output Q is
J Q0 J Q1 J Q2 J Q3 J Q4
Vi D Q
CLK
K CLR K CLR K CLR K CLR K CLR
Q
I0 I1 I2 I3 J Q J Q
A S1
B S0
Y 1 K Q 1 K Q
F
CK
(a) A (b) B (a) 1 (b) 2
(c) AB (d) AB + AB (c) 3 (d) 4
EBD_7203
S3-32 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
28. Figure below shows a ripple counter using positive edge 33. The boolean expression YZ + XZ + XY is logically
triggered flip flops. If the present state of the counter is
Q2Q1Q0 = 011, then its next state (Q2Q1Q0) will be equivalent to
1 (a) YZ + X
1
1 T0 Q0 T1 Q1 T2 Q2 (b) YZX + XYZ
(c) YZ + XZ + XY
CLK
Q0 Q1 Q2 (d) XYZ + XYZ + XYZ + XYZ
(a) 010 (b) 100 34. Race around condition always arise in a
(c) 111 (d) 101 (a) Combination circuit (b) Asynchronous circuit
29. In the circuit assuming initially Q0 = Q1 = 0. Then the (c) Synchronous circuit (d) Digital circuit
states of Q0 and Q1 immediately after the 33rd pulse are 35. For a mod-12 counter, the FF has a t pd = 60 ns. The NAND
gate has a tpd of 25 ns. The frequency is
Q0
(a) = 3.744 MHz (b) > 3.744 MHz
J0 Q0 J1 Q1 Q1 (c) < 3.774 MHz (d) = 4.167 MHz
36. The initial state of MOD-16 down counter 0110. After 37
Q'1
clock pulses, the state of the counter will be
K0 Q'0 K1
CLK (a) 1011 (b) 0110
(c) 0101 (d) 0001
(a) 1 1 (b) 1 0 37. The initial contents of the 4-bit serial-in parallel-out right-
(c) 0 1 (d) 0 0 shift shift register shown in figure is 0110. After three clock
30. The three state Johnson-ring counter as shown above is pulses applied, the contents of the shift register will be
clocked at constant frequency of fc from the starting state
of Q0Q1Q2 = 101. The frequency of outputs Q0Q1Q2 will Clock
be 0 1 1 0
Serial
in
J0 Q0 J1 Q1 J2 Q2 +
fc f D4
(c) (d) c E 1= error
3 2 D3 0 = no error
31. A synchronous sequential circuit is designed to detect a bit D2
sequence 0101 (overlapping sequence include). Everytime D1
this sequence is detected, the circuit produces an output of D0
‘1’. What is the minimum number of states the circuit must
have? (a) error, error (b) error, no error
(a) 4 (b) 5 (c) no error, error (d) no error, no error
(c) 6 (d) 7 40. The counter start off in the ‘0000’ state, and then clock
32. It is required to construct a 2n to multiplexer by using pulses are applied. Some time later the clock pulses are
2- to -1 multiplexers only. How many of 2-to-1 multiplexers removed and the counter FFs read ‘0011’. How many clock
are needed? pulses have occurred?
(a) n (b) 22n (a) 3 (b) 35
(c) 2 n – 1 (d) 2n – 1 (c) 51 (d) any of them
DIGITAL LOGIC S3-33
41. For given MOD-16 counter with a 10 kHz clock input 47. The minimum Boolean expression for the following circuit
determine the frequency at Q3. is
B
A
CP1
C
10 kHz CP0 MoD - 16
A B
MR1 MR2
A
Q3 Q2 Q1 Q0
C
B
(a) AB + AC + BC (b) A + BC
(a) 625 Hz (b) 10 kHz
(c) A + B (d) A + B + C
(c) 2.5 kHz (d) 0 Hz
48. A carry look ahead adder is frequency used for addition
42. For a stable timer circuit, given RB = 750 W. Determine because, it
value for RA and C to provide a 1.0 MHz clock that has a (a) is faster (b) is more accurate
duty cycle of 25%. (c) used fewer gates (d) costs less
(a) 15 kHz, 600 pF (b) 1.5 kHz, 480 pF 49. Which one of the following can be used to change data
(c) 1 kHz, 6 mF (d) 1.5 kHz, 600 pF from special code to temporal code?
43. The open collector output of 2-input NAND gates are (a) Shift registers (b) Counters
connected to a common pull-up resister. If the inputs of (c) A/D converters (d) Combinational circuits
50. Match List-I (computer terms) with List-II (definitions)
the gates are A, B and C, D respectively, the output is
and select the correct answer using the codes given below
equal to this lists.
(a) A.B. C.D (b) A.B + C.D List - I List - II
(c) A.B + C.D (d) A. B. C. D A. Interface 1. A measure of rate of
44. Metastability in D-Flip Flop occurs when data transmission
(a) Set up time of input data is not met B. A bit 2. A binary digit
(b) Clock period is too large C. Baud Speed 3. The common boundary
between various
(c) Set and reset are active simultaneously
sections and sub-
(d) D and Q pins are shortened. sections
45. How many 1’s are present in the binary representation of 4. Analog to digital
3 × 512 + 7 × 64 + 5 × 8 + 3? converter
(a) 8 (b) 9 Codes:
(c) 10 (d) 11 A B C
46. In the following question, match each of the items A, B (a) 3 2 1
and C on the left with an approximate item on the right. (b) 3 1 2
A. A shift register 1. for code conversion (c) 2 4 1
can be used (d) 4 2 213
51. A divide by 78 counter can be realized by using
B. A multiplexer can 2. to generate memory
(a) 6 nos of mod-13 counters
be used slip to select (b) 13 nos of mod-6 counters
C. A decoder can be 3. for parallel-to-serial (c) one mod-13 counter followed by one mod-6 counter
used conversion (d) 13 nos of mod-13 counters
4. as a many-to-one 52. The minimal product-of sums function described by the
switch K-map given in Figure
5. for analog-to-digital (a) A’C’ (b) A’ + C’
conversion (c) A + C (d) AC
A B C AB
C 00 01 11 10
(a) 1 2 3
(b) 3 4 1 0 1 1 f 0
(c) 5 4 2
1 0 0 f 0
(d) 1 3 5
EBD_7203
S3-34 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
53. The circuit shown in the given figure is 57. A new Binary Coded Pentary (BCP) number system is
proposed in which every digit of a base-5 number is
X Y represented by its corresponding 3-bit binary code. For
example, the base-5 number 24 will be represented by its
BCP code 010100. In this numbering system, the BCP code
100010011001 corresponds to the following number in
base-5 system
x =10101010 Output
58. 1
Input ¾¾¾¾¾¾® XOR ® Gray Code ¾¾¾¾
®
x 2 =11111111 decimal
R
P Q
CLR
Q
Clock
66. If all the flip-flops were reset to 0 at power on, what is the
64. The stable reading of the LED display is
total number of distinct outputs (states) represented by PQR
(a) 06 (b) 07 (c) 12 (d) 13
generated by the counter?
65. The magnitude of the error between VDAC and Vin at
(a) 3 (b) 4
steady state in volts is
(c) 5 (d) 6
(a) 0.2 (b) 0.3 (c) 0.5 (d) 1.0
67. If at some instance prior to the occurrence of the clock
Common Data for Question 66 and 67:
edge, P, Q and R have the values 0, 1 and 0 respectively,
Consider the circuit involving three D-type flip-flops used in a what shall be the value of PQR after the clock edge?
certain type of counter configuration. (a) 000 (b) 001
(c) 010 (d) 011
EBD_7203
S3-36 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Þ ( )
XY Z + Z + YZ X + X = F ( )
2. Checking the cube covers of the options
As X + X = 1
Cube covers of option (a) is as below:
Þ F = XYZ + XY Z + XYZ + XYZ
The K map for the above is w'xz 0101 (5)
yz wxy' 1101 (13)
x 00 01 11 10 xyz 0101 (5)
wyz 0111 (7)
0 1
1011 (11)
1 1 1 1
Therefore, option (a) satisfies the condition of differing
by one bit at least one member of each of other pairs.
Therefore, f is independent of Z.
DIGITAL LOGIC S3-37
5. (a) Given are a2a1a0 and b2b1b0.
y f
a2 a1 a0
0 f1
0 0 0
f = yf1 + yx ...(ii)
1 x
0 0 1
From eqn. (i) and (ii)
0 1 0
f = y(zx + zy) + yz
0 1 1
f = xy z + yz + xy
1 0 0
f = yz + xy z + xy(z + z)
1 0 1
f = yz + xy z + xyz + xyz
1 1 0
1 1 1 f = yz + xy z + xyz + xyz + xyz
f = yz + xz(y + y) + xy(z + z)
b2 b1 b0
f = yz + xz + xy
0 0 0
7. (c) As in the option (c), there are two D flip-flops.
0 0 1 Now, if the left most D flip-flop is activated that is the
0 1 0 clock value is set to 1 then the clock value of the right
0 1 1
most D flip becomes 0. Therefore, it delays the phase f
by 180°
1 0 0 8. (d) The counter start from 0.
1 0 1 Now, when the load = 0
Count = 1
1 1 0
The counter starts the count as (top to bottom in the
1 1 1 table)
Now, with the values above in the table, the carry c will 0000 (0)
be generated in the following cases: 0001 (1)
a0 = a1 = a2 = 1 = b0 = b1 = b2
0010 (2)
or a2 = b2 = 1 or a 2 Å b2 = 1
0011 (3)
or a1 = b1 = 1 or a1 Å b1 = 1 0100 (4)
or a0 = b0 = 1
0101 (5)
Now, checking the values in all the options provided
only (a) satisfies the possibilities. When the counter reaches 5, the counter is cleared to 0.
6. (a) 9. (b) A single one bit adder requires gate = 5 AND gates or
2 OR gates in two level logic.
x Now, given is 4 bit adder with outputs
= S3, S2, S1, S0 and C4
MUX This 4 bit adder would require two one bit adders and
0 f1 therefore 2 × (5 AND gates and 2 OR gates)
= 10 AND gates and 4 OR gates
1 10. (c) In the implementation of n variable functions, following
y MUX is required.
1. Data selector with n – 1 select inputs
z 2. 2n –1 data inputs
0 Therefore, the minimum size of multiplexer is 2n – 1 line
f to 1 line.
1 11. (d) Let’s construct a truth table to find the validity of the
x given statements.
y X Y Z=X *Y Y* Z X*Z X*Y*Z
0 0 1 0 0 1
Z f1
0 1 0 0 1 1
0 x
f1 = zx + zy ...(i) 1 0 0 1 0 1
1 y
1 1 1 1 1 1
EBD_7203
S3-38 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
This depicts that the statements (P), (Q) and (R) are f1 f2 f f1f2 f2
valid and therefore, the option (d) is correct.
12. (a) We are given with the function 1 0 1 1 x
4 1 0 0
f ( w, x, y, z ) = å ( 0, 4,5, 7,8,9,13,15 )
5 1 0 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 6 1 1 1 x x
= z = 1. Then the values of the equation becomes 7 1 0 0
(P) x’y’z’ + w’xy’ + wy’z + xz
8 1 0 1 1 1
= 0.0.0 + 0.1.0 + 1.0.1 + 1.1 = 1
(Q) w’y’z’ + wx’y’ + xz = 0.0.0 + 1.0.0 + 1.1 = 1 15 0 1 1 x
(R) w’y’z’ + wx’y’ + xyz + xy’z f1f2 + f3 = f
= 0.0.0 + 1.0.0 + 1.1.1 + 1.0.1 = 1 With this, the value for f0 = 1, the term in the LHS
(S) x’y’z’ + wx’y’ + w’y = 0.0.0 + 1.0.0 + 0.1 = 0 should be 4.
Therefore, (S) is not equivalent to f. The option which satisfy this condition is å m ( 6,8)
13. (b)
17. (d) 121r = 11r
yz Þ r ¹ 2 , so, now lets take any value greater than 2.
Let r = 3
yz yz yz yz
wx
1´ 9 + 2 ´ 3 + 1 = 9 + 6 + 1 = 16 = 3 + 1 = (11)r
wx 1 1 18. (d) Lets make a K map for the problem
0 1 3 2 ab
cd 00 01 11 10
wx
1 1
5
00 1 1 1
4 7 6
01 x
1 1
wx 12 13 15 14
11 x
wx 1 1
8 9 11 10
10 1 1 x
= a b + a d + cd b + cd b = a b + a d + d b c + c ( )
f = x.z + x.z
f(w, x, y, z) is independent of w and y variables = ab + ad + db ë (
éQ c + c = 1ù
û )
14. (c) To construct a 6 × 64 decoder, 19. (d) We have the given value as 0 × 00000000
64 0000 0000 0000 0000
= 8 decoders needed
8
0000 0000 0000 0000
Now, 1 extra decoder is also needed for combining the
result and hence the total number of decoders needed 0
=8+ 1=9 Hence, the IEEE floating point representation of 0 ×
15. (c) Consider a binary constant pi to be the value of the 00000000 is the special value + 0.
function f(x1, x2, x3, .... xn) where i is the decimal code. 20. (a) (P + Q)(P.Q + P.R)(P.R + Q)
Now, the switching can be expressed as
Þ (P.Q + P.R + P.Q + P.Q.R)(P.R + Q)
f ( x1, x 2 , x 3 ,....x n ) = p 0 x1' x '2....x 'n + p1x1' x '2 ....x 'n + px1x 2 ....x n
Þ (P.Q + P.R + P.Q.R)(P.R + Q)
Now,
For n variables, distinct minterms or maxterms obtained Þ P.Q + P.R.Q + P.Q.R
= 2^n
Þ P.Q(1 + R) + P.R.Q = P.Q + P.R.Q
An since the function is either 1 or 0 for each minterm,
Function formed from n variables = 2^2^n Þ P.Q(1 + R) = P.Q
16. (c) We need to build the table for the given logic circuit.
DIGITAL LOGIC S3-39
21. (b) We have to construct the diagram to get the output F = (X + Y). (A + B)
F = XA + XB + YA + YB
F = (P + Q) × (P + R) + (P + Q) × (Q + R)
A (A + C)
C +(Q + R) × (P + R) + (Q + R) × (Q + R)
F = (P.Q) × (P.R) + (P.Q).(Q.R) + (Q.R ).(P.R) + (Q.R).(Q.R)
((A + C) + (B + D))
R = P QR + P Q R + PQ R + Q.R
B
D F = P Q R + Q.R = (P + 1)Q R = Q R
(B + D)
F= Q+ R
= (A + C) (B + D)
= AB + C \ (C = D) 25. (b)
22. (b) Here, we need to convert (1217)8 is hexadecimal format P Q F
to get the answer.
0 0 R
Now, (1 2 1 7)8
001 010 001 111 1 R
0
which is 001 010 001 111. This is the binary format. We
need to convert this into hexadecimal format. 1 0 R
So, by dividing the binary code groups of 4 1 1 R
0010 1000 1111
2 8 F = (028F)16 Therefore the output is
23. (a) Initially Q1Q0 = 00
Next sequence after 00 F = P Q R + P QR + PQ R + PQR
Following are the conditions to be considered: = R(P Q + PQ) + R(PQ + PQ)
T=0 Next state = present state
= R(P Å R) + R(P Å R) = RX + RX
T=1 Next state compliment of present state
= RÅX = RÅPÅR
For input T = 1, output Q0 goes to next T flip-flop as a
26. (a) P = (F87B)16 is 1111 1000 0111 1011 = – 1925
clock. Since both are complimented so the output P * 8 = 1925 × 8 = 15400
becomes 11. Hence, the first sequence after 00 is 11. 2’s complement is 1100 0011 1101 1000
Next sequence after 11 Hence, it is equivalent to (C3D8)16.
The very next second Q1 remains 1 and Q0 becomes 0. 27. (a) We need to find the mapping for the RHS, i.e.,
The next sequence becomes 10.
R
Similarly, the next sequence after 10 is 01 and the fourth QR
sequence is 00. P 00 01 11 10
24. (a) m0 m1 m3 m2
0
1
P X=P+Q
PQ + QR + PR m4 m5 m7 m6
Q
P 1
X+Y 1 1 1
Q Q
From the figure, we can conclude that
R Y=X+Y (m2 m6) Map is for QR
P A= P+ Q (m7 m6) Map is for PQ
R (m4 m6) Map is for PR
A+B Hence, m2 + m4 + m6 + m7 maps for the given term.
28. (a) 28 = 256 < 258 < 29
Q A 0
R 29. (d)
B=Q+R B
0 = ( A Å B ) = XNOR
F= X+Y+ A+B
A 0
F = (X + Y) × (A + B)
B
EBD_7203
S3-40 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
( ) (
0 = A Å B = AB Å AB = AB + BA ) and the left bit to the decimal point is not written in the
floating point format.
33. (b) The general formula for 2’s complement representation
= A Å B = XNOR
of n-bits is
A 0 (– 2n–1 to 2n–1 – 1)
For n = 8, the maximum negative number is
B – 28–1 = – 27 = – 128
34. (a) This is a 4 × 2 priority encoder, where the highest
0 = A Å B = A + AB = ( AB + AB) = XNOR priority bits (Inputs) are to the right and “X”
30. (b) P + Q + R = 011 indicates an irrelevant value.
35. (d) Exclusive NOR of x and y = xy + x¢y¢
P + Q + R = 010
x Å y = xy + x¢y¢
P + Q + R = 001 \ option (a) xy + x¢ y¢ represents exclusive NOR of
P Q R F x and y.
0 0 0 1 Evaluating (b)
0 0 1 0 x Å y¢
Þ x Å y¢ = x¢ y¢+ xy (Q a Å b = a¢b + ab¢)
0 1 0 0
0 1 1 0 Þ x Å y¢ = x Å y
1 0 0 1 Evaluating (c)
x¢ Å y
1 0 1 1 Þ x¢ Å y = x¢y¢ + xy
1 1 0 1
Þ x¢ Å y = x Å y
1 1 1 1
Evaluating (d)
Q R QR QR QR x¢ Å y¢
P 1 0 0 0 Þ x¢ Å y¢ = x¢y + xy¢
i.e., P + QR
P 1 1 1 1 \ It is observed x¢ Å y¢ ¹ x Å y
So, (d) i.e., x¢ Å y¢ is not equivalent to exclusive NOR
31. (a) The truth table is given by of x and y.
X Y f(X, Y) 36. (a) The Given Boolean expression:
0 0 0 F (P, Q, R, S) = PQ + PQR + PQRS
0 1 0
The K-Map for the above expression is as follows:
1 0 1 PQ
RS 00 01 10
1 1 1
One method to find out Boolean function’s work. It 00 1
works as same as the X works. 01 1 1
Another method is to draw K-map for this Boolean
function. 11 1 1
X 10 1 1
Y 0 1
0 0 1 The Minterm combination for the above K-Map is as
f(X, Y) = X follows:
1 0 1
32. (a) The decimal value 0.5 is represented in binary as PQ PQ
follows: RS 00 01 10 RS 00 01 10
Þ 3b + b + 2 = 2b ç ÷
ç b ÷ 40. (c) In case of decoder output, single output will be that 1
è ø
and remaining will be zero at any time. The output that
Þ b2 – 5b = 0 is high will give the count of the ring counter at that
Þ b (b – 5) = 0 time.
Þ b = 0 or b = 5 41. (b) The K-map for the function F is
Since base can not be 0, so the required base = 5.
38. (a) PQ + QR + PQR
RS RS RS RS RS
The given diagram is:
PQ
0
1 f
PQ
1
PQ 1 f
R
f 1
R PQ
S1 S0
PQ f 1
P Q
EBD_7203
S3-42 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
a
7. (d) (
Z = D A BC + A BC + ABC + ABC + ABC )
I1
2×1
y ( ( )
= D A B C + C + BC A + A + ABC ( ) )
MUX
b I2 ( ) ( (
= D A B + BC + AB C = D B A + AC + BC ) )
= D ( BA + BC + BC) = D ( B e C + A B)
x 8. (b) f1 = C0 + CB = CB,S = F1
43. (c) f = f 1 + f1 A = CB + CBA = CB + A
The circuit given above is a comparator circuit. 62. (b) As per question, the truth table
When X < Y, F1 = 1; when X = Y, F2 = 1 and; When X
> Y, F3 = 1 P1 P2 a b c d e f g
54. (b) SR latch is shown in figure 0 0 1 1 1 1 1 1 0
R 0 1 1 0 1 1 0 1 1
Q
1 0 1 1 0 1 1 0 1
1 1 1 0 0 1 1 1 1
Hence, a = 1
Q
S b = P1 P 2 + P1 P 2 = P 2 (P1 + P1 ) = P 2
A latch employs cross – coupled feedback c = P1 P 2 + P1P2 = P1 (P 2 + P2 ) = P1
connections.
d=1
(ii) Registers are made of edge triggered FFS, where as
latches are made from level triggered FFS. e = P1P2 = P1 + P2
55. (c) Four 1-bit full adders are cascaded. So, carry bit is
travelled by three adders. Hence; f = P1 P 2 = P1 + P2
Time taken by last Sum bit
= 3 × (20 + 40) = 100 ns = 100 × 109 S g = P1 P 2 = P1 + P2
Maximum rate of addition/sec 63. (d) a = 1
1 b = P 2 Þ 1 NOT gate required
= = 107 / Second
100 ´10-9 c = P1 Þ 1 NOT gate required
56. Each diode causes a voltage level loss of 0.75 V. e = P1 + P 2 Þ 1 OR gate required
Therefore 0.75n < 2.5 V Þ n = 3.
57. 100010011001 ® 4231 f = P1 + P2 Þ 1 OR gatre required
g = P1 + P2 Þ 1 OR gate required
01010101 Hence, 2 NOT and 3 OR gates required.
58. xl Å x 2 = = 1111111 = +127
Gray Code 3
9.375
64. (d) VDAC = å 2n -1 bn = 2–1 b0 + 20b1 + 21b2 + 22b3
n=0
59. Step size output is - = – 2.3444 V Counter output will start from 0000 and will increase
4
for 12 bit BCD, decimal no. is 000 to 999 till Vin > VDAC. When VDAC = 6.5 V, the comparator
output will be zero and the counter will be stable
9.99V at that reading and the number displayed at LED will
Step size = 0.01 V
999 be 13.
EBD_7203
S3-46 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The counting sequence is shown below. 65. (b) Error voltage = VDC – Vin
b3 b2 b1 b0 VDAC = 6.5 – 6.2 = 0.3 volts
0 0 0 0 0 0
66. (a) P Q R
1 0 0 0 1 0.5
2 0 0 1 0 1 0 0 0 P
Q
3 0 0 1 1 1.5 0 1 0
4 0 1 0 0 2 0 1 1 Q
5 0 1 0 1 2.5 1 0 1
P Q
6 0 1 1 0 3 1 0 0
7 0 1 1 1 3.5 0 0 0 Q
8 1 0 0 0 4
= 5 States R
9 1 0 0 1 4.5 P Q
10 1 0 1 0 5
Q
11 1 0 1 1 5.5
12 1 1 0 0 6
67. (d) 011
13 1 1 0 1 6.5
14 1 1 1 0 7
15 1 1 1 1 7.5
2
Page - 47 - 118
O Ø
Ø
ALU and data-path
N Ø Memory interface
T
Ø I/O interface (Interrupt and DMA mode)
Ø Instruction pipelining
N
Ø Secondary storage
T
S
EBD_7203
S3-48 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
MACHINE INSTRUCTIONS
A Computer needs to perform various different kind of tasks. To perform these diverse
tasks, a computer needs various instructions that interact with low level hardware. For
example to set some color on a part of display screen a computer needs an instruction. To
read a single character from a keyboard the computer need other instruction. Similarly to
perform arithmetic and logical operations like addition, subtraction, complement etc it
needs a set of instructions. Although different computer have different instruction sets,
yet the basic instruction are more or less same, the difference lies between the binary
encoding of the instructions on different machines. For ex. Bit sequence “10011001” may
mean ADDITION on a machine while “Complement operation” on the other. In any case
there is a set of basic operations that most computers include in their instruction set. We
can classify the instructions of a computer in following types :
1. Data transfer instructions : copy data from one to another.
2. Data manipulation instructions : Use existing bit patterns to compute a new bit
patterns.
3. Program control instructions : Direct the execution of the program.
Instructions that perform arithmetic, logic, and shift operations are called Data
Manipulation Instructions. Instructions like Conditional Branch, Jump instruction,
subroutine call are included in Program control instructions that provide decision-making
capabilities and change the path taken by the program when executed in the computer.
1. Data Transfer Instructions :
Data transfer instructions are used to transfer of data from one address to another
without changing the contents. Mostly the transfer of data occurs between two
registers of the processor, between main memory (often called RAM) and the
registers of processor and between processor registers and I/O Devices. Data can
be transferred between registers or between register and the memory. Following
data transfer instructions are commonly used:
Data Transfer Instructions
The CLR instruction replaces all the bits of the operand (register) with 0. The COM
(Complement) instruction exchanges 0s with 1s and vice-versa. The AND, OR, and
XOR instructions produce the corresponding logical operations on individual bits
of the operands.
Truth tables explains AND, OR and XOR operations :
Before Shift 1 0 0 1 0 0 1 0
ADDRESSI NG MO DES
The opcode field of an instruction specifies the operation to be A typical instruction has the following format :
performed e.g. addition, subtraction, complement etc. Most
instructions need operands, so we need to specify where the Opcode Address Field
operands are in memory for an instruction. This is called the
addressing of the data. Addressing mode refers to the system how the bits of an address
field are interpreted to find the operands. In other words the way the operands are
EBD_7203
S3-52 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
chosen during program execution is referred to as the addressing mode of the system.
The address field in a typical instruction format is relatively small. We need to reference
a large range of locations in main memory. For this the no. of bits in address field are
sometimes insufficient. For example if address field has 7 bits then it can only differentiate
between 27 different addresses. If the main memory has more than 27=128 words, then
we need different approach to address all words of the memory. To achieve this different
addressing schemes have been employed. Following addressing schemes are commonly
used:
1. Implied Mode
2. Immediate Mode
3. Direct Addressing
4. Indirect Addressing mode
5. Register mode
6. Register Indirect Addressing mode
7. Indexed Addressing
A single computer can use multiple addressing modes for different instructions. Here the
question is, How does it differentiate between these addressing modes? Most common
approach is to use one or more bits as “MODE FIELD” in instruction format. The value
of the MODE FIELD determines that which addressing mode is to be used for a particular
instruction.
There bits in the address field may be interpreted as operand or
A typical instruction format with mode field is given below : location. If address is not required for an instruction then
Opcode Mode Field Address field corresponding bits may designate an operand itself. If an instruction
requires address, the address field may designate a memory address
or a processor register.
Although most addressing modes need the address field of the instruction, there are two
modes that need no address at all. These are the “implied mode” and “immediate mode”.
1. Implied Mode:
There are some instructions that need no operand at all. For such instructions the
operands are interpreted automatically by the definition of the instruction itself.
For example, the instruction “Complement AC” is an implied mode instruction
because the data in the AC register is to be complemented and no need to specify
where the data resides. All register reference instructions that use Accumulator
(AC) are implied mode instructions. Zero address instructions in a computer based
on stack organization are also implied mode instructions where the operands are
Example : always fetched from the top of the stack.
2. Immediate Mode :
MOV R2 100 Many times the instructions need constant operands. Rather than
(An Immediate instruction for loading a constant “100” specifying addresses, the operand itself can be provided at the
into register R2) address field of the instructions. Such scheme is called Immediate
Mode addressing. This is automatically fetched from memory
Instruction Format
when the instruction itself is fetched.
Opcode Operand Since the operand is directly available in the instruction itself, no
extra memory reference is needed to fetch the operand, thereby
reducing the execution time. However, the disadvantage is that
Immediate Mode
only a constant can be supplied as an operand using this method.
Also the value of the constant is limited by the size of the address
Example : field.
MOV R2 0000 0001 0010 1100 3. Direct Addressing:
Another method for specifying an operand in memory is
( Above instruction fetches the data at address “0000 0001 0010 1100”
by giving its full address of main memory.
(decimal: 300) from main memory and loads it in the register R2 )
COMPUTER ORGANIZATION AND ARCHITECTURE S3-53
This mode is called direct addressing. Direct addressing is restricted in its use:
Instruction
Although, the address value can be changed, it can only be used to access global 300
variables whose address is known at compile time. Memory
4. Indirect Addressing Mode :
In this mode that address is stored at the address field of the instruction
where the address of the operand is located. For Example, Let the operand
be located at address 500. Now there is another memory word at address 300 Operand
400 whose value (i.e. data stored at it) is 500. So, in Indirect addressing Direct Mode
mode the value 400 will be stored at the address field of the instruction.
Following figure will make it more clear : Instruction
5. Register Addressing : 400
Register addressing is similar to the above discussed direct addressing. The Memory
difference between both is that in this case the address field specifies a register
instead of a memory location. Because registers are so important (due to fast 500 Operand
access and short addresses) this addressing mode is the most common one on
most computers. This is often used by modern compilers for code optimaztion e.g.
400 500
To store those variables of loop that are accessed frequently (e.g. loop counters).
This addressing mode is known simply as register mode. Indirect Addressing
6. Register Indirect Addressing :
This mode is similar to Indirect addressing mode discussed above. In this mode Instruction
also, the operand being specified comes from memory or goes to memory, but its R
address provided in the instruction is not absolute as in direct addressing. Instead,
the address is contained in a register which is identified by the address field of the
instruction. So, in other words the operands are found at some address and this Operand
address is stored in a register which is identified by the address field of the
instruction.
7. Indexed Addressing : Register Mode
In many cases it is good to reference memory words at a known offset from an
address stored in register. Addressing memory by giving a register (explicit or Instruction
implicit) plus a constant offset is called indexed addressing. This is specially useful R
while accessing elements of an array in a loop. To see how that works, consider the Memory
following example. We have One one-dimensional array ‘X’ of 500 numbers, and
we wish to find largest number in the array. In this case we can put the base
address of X in one register R, and then step through its elements one by one by
adding fixed constant offset to address stored in register R. The fixed constant is
equal to the size of one element of the array. Operand
Register Indirect
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
EBD_7203
S3-54 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ALU (ARITHMETIC AND LOGICAL UNIT)
ALU, the Arithmetic and Logical Unit of the Central Processing Unit is that part of
Control Flags the computer that actually performs arithmetic and logical operations on data.
unit ALU Other parts of the system (like Control Unit, Registers, Memory and I/O devices),
Registers Registers hosts the data that is brought to the ALU for computation. ALU performs the
required operation on the data and then the results are taken back to other parts of
the system. ALU contains various electronic circuits required to perform various
Arithmetic (e.g addition, subtraction etc) and Logical (e.g. AND, OR, Complement
etc) operation.
Following block diagram shows the Input and Output of an ALU :
Data are presented to the ALU in registers, and the results of the operation are also
stored in registers. To perform a microoperation the contents of specified registers are
placed in the inputs of the ALU. ALU performs the required microoperation and the
result is then transferred to a destination register. These registers are temporary storage
locations, within the processor that are connected by signal paths to the ALU. The
control unit provides signals that control the operation of the ALU and the movement of
the data into and out of the ALU. There are various control variable called “flags” that
can be set by the ALU after it performs the required operation on the data. For example
an overflow flag can be set by ALU if the result of an operation has bigger size then a
register can hold. The registers that hold the operands, the registers that hold the result
of the operation performed by the ALU and the registers that hold the “flags”, All resides
within the CPU.
The ALU shown in figure has two components : One to
One stage of arithmetic logic shift unit perform Arithmetic operation and other to perform Logical
S3 operations. Di is output of Arithmetic subunit while Ei is
S2
output of logical subunit of ALU. Inputs Ai and Bi are supplied
to the both components of the ALU. Inputs S0 and S1 decides
S1
what micooperation is to be performed on the data. A 4 x 1
S0 multiplexer is used to choose one of the arithmetic output Di
Ci and Logical Output Ei . The data in the multiplexer are selected
with inputs S3 and S2. In case of shift-right operation and
shift-left operation the other two data inputs Ai-1 ( for the
shift-right operation) and Ai+ 1 (for the shift-left operation)
One stage of need to be supplied to multiplexor.
Di The shown figure is a simplification of the actual ALU. This
arithmetic
circuit shows the part of the ALU handling only 1-bit of information.
Select Above figure must be repeated N-times for an N-bit ALU.
Select
Moreover, The output carry Ci+1, of a given arithmetic stage
00 4 × 1
Fi must be connected to the input carry Ci, of the next stage.
Ci + 1 1 MUX The input carry to the first stage is the input carry Cin , which
2
provides a selection variable for the arithmetic operations.
3
The above circuit provides eight arithmetic operation, four
One stage of Ei logic operations, and two shift operations. Each operation is
Bi logic circuit selected with the five variables S3, S2, SI, So, and Cin , The
input carry Cin is used for selecting an arithmetic operation
Ai
only. A and B are two four bit input lines which is used to
Ai – 1 shr select a particular operation in the unit. The selection lines
shl
are decoded within ALU. F is output, S2 is mode select. It is
Ai + 1 set to 0 for Arithmetic operation and 1 for logical operations.
C in and C out to carry input and output lines.
Following Table lists all the 14 operations of the ALU. The first eight are arithmetic
operations and are selected with S3=0, S2=0. The next four are logic operations and are
selected with S3=0, S2=1. The input carry has no effect during the logic operations and
is marked with don’t-care x’s. The last two operations are shift operations and are selected
with S3=1, S2 = 0 and S3=1, S2 =1. Other three selection inputs S1, S0 and Cin have no
effect on the shift operations.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-55
Funtion Table for Arithmetic Logic Shift Unit
Operation select
S3 S2 S1 S0 C in Operation Function
0 0 0 0 0 F=A Transfer A
0 0 0 0 1 F=A+ 1 Increment A
0 0 0 1 0 F=A+ B Addition
0 0 0 1 1 F = A+ B + 1 Add with carry
0 0 1 0 0 F=A+ B Subtract with borrow
0 0 1 0 1 F = A+ B + 1 Subtraction
0 0 1 1 0 F =A – 1 Decrement A
0 0 1 1 1 F=A Transfer A
0 1 0 0 × F= AÙB AND
0 1 0 1 × F= AÚ B OR
0 1 1 0 × F= AÅB XOR
0 1 1 1 × F= A Complement A
1 0 × × × F = shr A Shift right A into F
1 1 × × × F = shl A Shift left A into F
Register R
Upcode Mode = 2 Reg R Address of the operand
Memory
Operand
Address Location
EBD_7203
S3-58 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
MEMORY INTERFACE
The data and address buses connect memory chips (RAM and ROM) to the CPU. Some
bits in the address bus are used to select one of the many memory chips while other bits
select the memory word in the selected chip. Memory chips may be connected to the
CPU as follows :
CPU
644444Address bus
744444 8
16-11 10 9 8 7–1 RD WR Data bus
Decoder
3 2 1 0
CS1
CS2 128 × 8
RD Data
WR RAM 1
AD7
CS1
CS2 128 × 8
RD Data
WR RAM 2
AD7
CS1
CS2 128 × 8
RD Data
WR RAM 3
AD7
CS1
CS2 128 × 8
RD Data
WR RAM 4
AD7
CS1
1–7 CS2 128 × 8
Data
8
9 AD9 ROM
When the 10th bit is equal to 1, i.e. when ROM is enabled the operations on different
inputs can be summarized by the following table :
CS1 CS 2 RD Memory function State of the data bus
0 0 X Inhibit High Impedance
0 1 X Inhibit High Impedance
1 0 0 Inhibit High Impedance
1 0 1 Read Read data from ROM
1 1 X Inhibit High Impedance
So We note that ROM is only enabled when CS1=1, CS2 = 0 and RD input is enabled.
READ Operation is performed on ROM in this case. ROM is disabled or data bus is in
high impedence state in all other cases. We also note that when the chip is not enabled
either CS1=0 or =1, the value of RD input becomes insignificant which is denoted by “X”
in the above table.
EBD_7203
S3-60 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
INPUT/OUTPUT INTERFACE
External Devices
The input—output subsystem provides communication between the CPU and the
external devices. A computer needs programs and data for processing and then it need to
display the results obtained by processing. The most common way to feed data to the
computer is through the keyboard. Other common external devices are display units,
scanner, mouse, printers, magnetic disks and tapes etc.
Input—Output Interface
I/O interface provides a method for transferring information between CPU and external
devices. The I/O interface resolves the differences that exist between the cpu and each
External device. The major differences are:
1. Conversion of signals between CPU and external devices.
2. Synchronization issues due to the speed difference between CPU(extremely faster)
and external devices (very slow).
3. Data codes and formats in External devices differ from the word format in the CPU
and memory.
4. Difference in operating modes external devices with each other.
I/O interfaces are connected as shown in following figure :
I/O bus consists of data lines, address lines, and control lines. Each interface decodes
the address and control received
I/0 bus
Data from the I/O bus, interprets them
Processor for the external device, and
Address
provides signals for the device
Control
controller along with
synchronization. To communicate
with a particular device, the
processor places a device address
Interface Interface Interface Interface
on the address lines. When the
interface detects its own address
on the address line, it activates the
Keyboard path between the bus lines and the
and Magnetic Magnetic
display
Printer
disk tape
device that it controls. The CPU
terminal also provides a function code in
the control lines. The selected
interface responds to the function code (I/O Commands) and proceeds to execute it. I/O
Commands are classified as control, status, data output, and data input. A control
command is issued to activate the External device and to inform it what to do. A status
command is used to test various status conditions in the interface and the external
device. A data output command causes the interface to respond by transferring data
from the bus into one of its registers. In case of data input command, the interface
receives an item of data from the external device and places it in its buffer register. The
processor checks if data are available by means of a status command and then issues a
data input command. The interface places the data on the data lines, where they are
accepted by the processor.
Isolated versus Memory-Mapped I/O
In the computers in which one common line is used to transfer data between memory or
I/O and the CPU, a memory transfer and an I/O transfer is distinguished by separate read
and write lines. The CPU enables one of two possible read or write lines to specify
whether the address on the address lines is for a memory word or for an interface register.
The I/O read and I/O write control lines are enabled during an I/O transfer. The memory
read and memory write control lines are enabled during a memory transfer. In this system
all I/O interface addresses are isolated from the memory addresses, so it is referred to as
COMPUTER ORGANIZATION AND ARCHITECTURE S3-61
the isolated I/O method. The isolated I/O method isolates memory and I/O addresses so
that memory address values are not affected by interface address assignment since each
has its own address space.
In the Memory-Mapped organization, same address space is used for both memory and
I/O. The computer treats an interface register as being part of the memory system. The
assigned addresses for interface registers cannot be used for memory words, which
reduce the memory address range available. In a memory-mapped I/0 organization there
are no specific input or output instructions. The CPU can manipulate I/O data residing in
interface registers with the same instructions that are used to manipulate memory words.
So, the computers with memory-mapped I/O can use memory-type instructions to access
I/O data. It allows the computer to use the same instructions for either input—output
transfers or for memory transfers. For example, the load and store instructions used for
reading and writing from memory can be used to input and output data from I/O registers.
This reduces the size of the instruction set of the computer.
Modes of data Transfer
Data transfer between CPU and I/O devices can be done in many ways which are called
modes of data transfer. Following modes are used in a typical computer :
1. Programmed I/O :
Programmed I/O operations are based on Interface
the concept of constant monitoring of the Data bus I/0 bus
external devices by the CPU. In the Address bus Data register
programmed I/O method, the CPU stays in Data valid I/0
CPU I/0 read
a program loop until the I/O unit indicates device
that it is ready for data transfer. I/0 write Status Data accepted
register F
Disadvantage is that it keeps the processor
busy needlessly.
Example : F = Flag bit
When a byte of data is available, the device places it in the I/O
bus and enables its data valid line. The interface accepts the
byte into its data register and enables the data accepted line. Read data register
The interface sets a bit in the status register that we will refer to
as an F or “flag” bit. The device can now disable the data valid
line, but it will not transfer another byte until the data accepted Check flag bit
line is disabled by the interface. This is done by reading the
status register into a CPU register and checking the value of the
=0 Flag
flag bit. If the flag is equal to 1, the CPU reads the data from the
data register. The flag bit is then cleared to 0 by either the CPU or
=1
the interface, depending on how the interface circuits are
designed. Once the flag is cleared, the interface disables the Read status register
data accepted line and the device can then transfer the next data
byte.
2. Interrupt-Initiated I/O: Transfer data to memory
In this mode, the interface keeps monitoring the device and
informs the CPU when it is ready to transfer data. CPU does not
constantly monitor the flag. The flag is set by the interface when Operation no
it is ready to transfer data. When the flag is set, the CPU is complete?
interrupted from executing the current program and is informed
that the flag has been set. The CPU goes to take care of the input yes
or output transfer. After the transfer is completed, the CPU
returns to the previous program to continue what it was doing Continue
before the interrupt. The CPU responds to the interrupt signal with
program
by storing the return address from the program counter into a
memory stack and then control branches to a service routine Flowchart for CPU program to input data
EBD_7203
S3-62 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
that processes the required I/O transfer. The branch address can be chosen by one
of the two methods: Vectored interrupt and Non-Vectored interrupt. In vectored
interrupt, the source that initiates the interrupt, supplies the branch information to
the CPU. This information is called the Interrupt Vector. The interrupt vector is
either the first address of the I/O service routine OR it is an address that points to
a location in memory where the beginning address of the I/O service routine is
stored. In Non-Vectored interrupt, the branch address is always assigned to a fixed
location in memory.
Priority Interrupt
In a typical computer system more than one I/O devices are attached to the computer,
with each device being able to originate an interrupt request. The first task of the
interrupt system is to identify the source of the interrupt. There is also the possibility
that several sources will request service simultaneously. In this case the system
must also decide which device to service first. A priority interrupt is a system that
establishes a priority over the various sources to determine which interrupt is to
be serviced first when two or more interrupt arrive simultaneously. The system
may also determine which conditions are permitted to interrupt the computer while
another interrupt is being serviced. Higher-priority interrupt levels are assigned to
requests which, if delayed or interrupted, could have serious consequences.
Devices with high-speed transfers such as magnetic disks are given high priority,
and slow devices such as keyboards receive low priority. When two devices
interrupt the computer at the same time, the computer services the device, with the
higher priority first.
3. Direct Memory Access:
The disadvantage of above modes is that all data must go through the CPU.
Although CPU is fast fast at computations it is relatively very slow when it comes
to large amount of data transfer. So if data is transferred
Diagram shows the CPU bus signals for DMA transfers : between main memory and I/O devices without going
through CPU, high speed-up can be achieved, which is
Bus Request BR DBUS Address Bus the essence of the “Direct Memory Access (DMA)”
mode. In DMA, the I/O device controls the buses and
ABUS Data Bus directly transfers the data to and from main memory and
CPU CPU has no control over it. The CPU initiates the transfer
RD Read by supplying the interface with the starting address and
Bus Grant BG the number of words needed to be transferred and then
WR Write proceeds to execute other tasks. When the transfer is
made, the DMA requests memory cycles through the
memory bus. When the request is granted by the memory controller, the DMA
transfers the data directly into memory.
Following Diagram shows the CPU bus signals for DMA transfers :
DMA controller requests the CPU to leave control of buses using BR input. On
this request the CPU stops executing the current task and blocks Address bus,
Data bus, Read line and write lines. Then CPU activates BG input to inform DMA
controller that it can now use the buses. Now, the DMA controller takes over the
control of all buses to perform data transfers between I/O devices and main memory.
After the data transfer is completed, it disables the BR line. The CPU notes it and
disables the BG line and takes over the control of all buses and resumes the
execution where it stopped.
INSTRUCTION PIPELINE
There are various ways in which performance of a computer system can be improved.
This includes using faster hardware, developing faster algorithms, code optimization by
the compiler. Orgnizational approaches like Using multiple CPUs, Using multiple registers,
Using various levels in memory hierarchy have also been used to improve the performance.
Instruction pipelining is also an organizational approach which is commonly used in
modern systems to improve the performance. Instruction pipelining is similar to the use
COMPUTER ORGANIZATION AND ARCHITECTURE S3-63
of an assembly line in a production factory. In an assembly line a product goes through
various mutually exclusive stages of production. Products at various stages can be
done simultaneously.
To apply this concept to instructions, we note that, in fact, an instruction has a number
of stages.
Indirection Indirection
Multiple Multiple
operands results
FI DI CO FO EI WO
Instruction 3
FI DI CO FO EI WO
Instruction 4
FI DI CO FO EI WO
Instruction 5
FI DI CO FO EI WO
Instruction 6
FI DI CO FO EI WO
Instruction 7
FI DI CO FO EI WO
Instruction 8
FI DI CO FO EI WO
Instruction 9
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
FI DI CO FO EI WO
Instruction 2
FI DI CO FO EI WO
Instruction 3
FI DI CO FO
Instruction 4
FI DI CO
Instruction 5
FI DI
Instruction 6
FI
Instruction 7
FI DI CO FO EI WO
Instruction 15
FI DI CO FO EI WO
Instruction 16
Fetch
instruction
FI
Decode
DI instruction
Calculate
CO operands
Yes
Unconditional
branch?
No
Fetch
FO operands
E1 Execute
instruction
Update WO Write
PC operands
Empty
pipe Yes Branch No
or
interrupt?
Six-Stage CPU Instruction Pipeline
So, Instruction pipelining is a powerful technique for enhancing performance but requires
careful design to achieve optimum results with reasonable complexity.
EBD_7203
S3-66 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example 2: Consider the unpipelined machine with 10 ns clock cycles. It uses four
cycles for ALU operations and branches whereas five cycles for memory operations.
Assume that the relative frequences of these operations are 40%, 40% and 20%,
respectively. Let due to clock skew and setup pipelining, the machine adds 1ns of
overhead to the clock. How much speed in the instruction execution rate will gain
from a pipeline ?
Sol. Average instruction execution time = Clock cycle × Average CPI
= 10 ns × [(40% + 20%) + 4 + 40% × 5]
= 10 ns × 4.4 = 44 ns
In the pipelined implementation, clock must run at the speed of slowest stage plus
overhead, which will be 10 + 1 or 11 ns; this is the average instruction execution
time.
Thus, speed up from pipelining,
Average instruction time unpiplined
(Speed up)pipelinging =
Average instruction pipelined
44ns
= = 4 times
11ns
Example 3: Assume that the time required for the five functional units, which operate in
each of the five cycle are 10 ns, 8 ns, 10 ns, 10ns and 7 ns.
Assume that pipelining adds 1 ns of overhead. Find out the speed up versus single
cycle data path
Sol. Since unpipelined machine executes all instructions in a single clock cycle, its
average time per instruction is simply the clock cycle time. The clock cycle time is
equal to sum of the times for each step in the execution.
Average instruction execution time = 10 + 8 + 10 + 10 + 7
= 45 ns
Clock cycle time on the pipelined machine must be the largest time for any stage in
the pipeline (10 nos) plus overhead of 1 ns, for a total of 11 ns.
Since CPI is 1, this yields an average instruction execution time of 11 ns.
45ns
= = 4.1 times
11ns
Example 4: Consider a computer with four floating point pipeline processors. Let each
processor uses a cycle time of 40 ns. How long will it take to perform 400 floating-
point operations ? Is there a difference if the same 400 operations are carried out
using a single pipeline processor with a cycle time of 10 ns ?
Sol. Divide 400 operations into each of the four processors,
400
processing time = ´ 40 = 4000 n sec
4
Using a single pipeline,
processing time = 400 × 10 = 4000 n sec
CACHE MEMORY
As we know CPU is much faster than memory. The problem comes into the picture when
the CPU issues a memory request, it will not get the data it need for many CPU cycles.
The slower the memory the more cycles the CPU will have to wait. This problem can be
COMPUTER ORGANIZATION AND ARCHITECTURE S3-67
overcome by introducing a small and very fast memory near the CPU. The small, fast
memory is called Cache Memory. The basic idea behind a cache is simple: Keep those
memory words in cache that are heavily required by CPU e.g. A loop counter. When the
CPU needs a word, it first looks in the cache. Only if the word is not there does it go to
main memory. If a substantial fraction of the words are in the cache, the average access
time can be greatly reduced.
Memory access time is important to performance . Users want large memories with fast
access times ideally unlimited fast memory.
Levels of the Memory Hierarchy
Memory Hierarchy
We can exploit the natural locality in programs by implementing the memory of a computer
as a memory hierarchy.
Cache
Processor does all memory operations with cache.
• Miss - If requested word is not in cache, a block of words containing the
requested word is brought to cache, and then the processor request is
completed.
• Hit - If the requested word is in cache, read or write operation is performed
directly in cache, without accessing main memory.
• Block - minimum amount of data transferred between cache and main memory.
Temporal & Spatial Locality
There are two types of locality:
TEMPORAL LOCALITY (locality in time) If an item is referenced, it will likely be referenced
again soon. Data is reused.
SPATIAL LOCALITY (locality in space) If an item is referenced, items in neighboring
addresses will likely be referenced soon
Most programs contain natural locality in structure. For example, most programs contain
loops in which the instructions and data need to be accessed repeatedly. This is an
example of temporal locality. Instructions are usually accessed sequentially, so they
contain a high amount of spatial locality. Also, data access to elements in an array is
another example of spatial locality.
EBD_7203
S3-68 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The general idea is that when a word is referenced, it and some of its neighbors
Main
memory are brought from the large main memory into the cache, so that the next time it is
CPU used, it can be accessed quickly. A common arrangement of the CPU, cache, and
main memory is shown in fig.
Cache So, if CPU finds it data in the cache it will work faster say for example if CPU
accesses a data K times in a short period of time, if will need 1 reference to main
memory and K-1 references to cache. The performance gets better with the
Bus larger values of K.
If the required memory word is found in cache, it is called a “cache hit”, otherwise it is
called a “cache miss”.
CPU execution time must factor in stalls from memory access-
Assume the on-chip cache responds within the amount of time allotted to it from the
load/store or instruction fetch unit (e.g., 1 clock cycle)
CPU time = IC * CPI * Clock cycle time
IC * CPI must include all stalls so now we have to add memory stalls
IC * CPI = CPU clock cycles + memory stall cycles
Where IC We can view memory cycle stalls as number of stalls per instruction or per
memory access (loads & stores have 2 memory accesses per instruction, all others have
1 memory access per instruction)
Memory stall cycles = IC × (misses / instruction) × miss penalty
Memory stall cycles = IC × (memory accesses / instruction) × miss rate × miss penalty
Example 5 : A machine has CPI cycles per instruction 2.0 when all memory accesses hit
in the chache. The only data accesses are loads and stores, and these total 40% of
the instructions. If miss penalty is 25 clock cycles and miss rate is 2%, how much
faster would be the machine be if all the instructions were cache hits ?
Sol. Performance for machine that always hits,
CPU execution time = (IC × CPI + 0) clock cycle (where IC = instruction cycle)
= IC × 2.0 × clock cycle
Now for machine with the real cache,
Memmory clock cycles
= IC × Memory reference per instruction × miss rate × Miss penalty
= IC × (1 + 0.4) × 0.2 × 25
= IC × 0.7
where middle term (1 to 0.4) represents one instruction access and 0.4 data
acesses per instruction.
Hence total performance is
(CPU execution time)Cache = (IC * 2.0 + IC * 0.7) * clock cycle
= 2.7 × IC × clock cycle
• Address length = (s + w) bits The blocks of main memory are assigned to lines of the cache as follows :
• Number of addressable units = 2s + w
Cache Line Main memory blocks assigned
words or bytes
s
• Block size = line size = 2w words or 0 0, m, 2m, ………. , 2 -m
bytes s
1 1, m+1, 2m+1, ……. 2 -m+1
• Number of blocks in main memory =
. .
2s + w s . .
= 2 words or bytes
2w . .
• Number of lines in cache = m = 2r m-1 s
m-1, 2m-1, 3m-1, …….., 2 -1
• Size of tag = (s – r) bits
Using a part of address as a line number provides a unique mapping of each block of
main memory into the cache.
Now, Suppose a block is read from main memory into the cache at position ‘p’. To
distinguish it from other candidate blocks for that postion ‘p’, we need to store the tag
field (most significant s-r bits) along with the data in the cache.
Tag Line Word
Main memory address =
8 14 2
For our example configuration the mapping becomes as follows :
The blocks that map to the same cache line have the same tag. So, at any point of time
only one of these blocks can occupy cache. A read operation works as follows: CPU
generates a 24-bit address. The 14-bit line number is used as an index to access a
particular cache line. Matching logic is applied and if the 8-bit number matches the tag
field currently stored in that line, then the remaining 2-bit number is used to select one
bytes of the total 4 bytes in that particular line. In case of a miss, the 22-bit (TAG and line
field) is used to fetch a block from the memory.
Advantage of Direct mapping is that it is simple and easy to implement. Disadvantage is
that “Thrashing” may occur. It refers to the phenomenon when a program repeatedly
reference two block from main memory that are candidate blocks for same cache line, so
that only one of them can occupy the cache. Now, as the program repeatedly references
these two blocks, these will kick-out each other on every memory reference hence
significantly decreasing the Hit-Ratio, Even all other cache is empty.
2. Associative Mapping :
This method is used to overcome the problems which are there in Direct mapping.
This enables us to store a block of main memory at any random place in the cache.
In this method, the address is treated as a TAG and a Word field. No line field is
there in this case. The tag field uniquely identifies a block of main memory. In this
mapping any block of main memory can occupy any place in the cache, so it is also
called fully associative cache. The logic is explained in figure:
Tag Word
Main memory address = 22 2
COMPUTER ORGANIZATION AND ARCHITECTURE S3-71
(Miss in cache)
K-way set associative logic
Cache Design
The level’s design is described by four behaviors:
Block Placement: Where could a new block be placed in the given level?
Block Identification: How is a existing block found, if it is in the level?
Block Replacement: Which existing block should be replaced, if necessary?
Write Strategy: How are writes to the block handled?
EBD_7203
S3-74 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Handling a Miss
Miss occurs when data at the required memory address is not found in cache.
Controller actions:
• If cache is full
– select the least recently used (LRU) block in cache for over-writing
– If selected block has inconsistent data, take proper action
• Copy the block containing the requested address from memory
Miss During Instruction Fetch
Send original PC value (PC – 4) to the memory.Instruct main memory to perform a read
and wait for the memory to complete the access.Write cache entry.Restart the instruction
whose fetch failed.
Writing to Memory
Cache and memory become inconsistent when data is written into cache, but not to
memory – the cache coherence problem.Strategies to handle inconsistent data:
• Write-through
– Write to memory and cache simultaneously always.
– Write to memory is ~100 times slower than to (L1) cache.
• Write-back
– Write to cache and mark block as “dirty”.
– Write to memory occurs later, when dirty block is cast-out from the cache
to make room for another block
Writing to Memory: Write-Back
Write-back (or copy back) writes only to cache but sets a “dirty bit” in the block where
write is performed.When a block with dirty bit “on” is to be overwritten in the cache, it is
first written to the memory.“Unnecessary” writes may occur for both write-through and
write-back
– write-through has extra writes because each store instruction causes a
transaction to memory (e.g. eight 32-bit transactions versus 1 32-byte
burst transaction for a cache line)
– write-back has extra writes because unmodified words in a cache line get
written even if they haven’t been changed
– penalty for write-through is much greater, thus write-back is far more
popular
Cache Hierarchy
Average access time
= T1 + (1 – h1) [ T2 + (1 – h2)Tm ]
Where
• T1 = L1 cache access time (smallest)
• T2 = L2 cache access time (small)
• Tm = memory access time (large)
• h1, h2 = hit rates (0 £ h1, h2 £ 1)
Average access time reduces by adding a cache.
Cache Miss Behavior
If the tag bits do not match, then a miss occurs.
Upon a cache miss:
• The CPU is stalled
• Desired block of data is fetched from memory and placed in cache.
• Execution is restarted at the cycle that caused the cache miss.
• Recall that we have two different types of memory accesses:
• reads (loads) or writes (stores).
COMPUTER ORGANIZATION AND ARCHITECTURE S3-75
Thus, overall we can have 4 kinds of cache events:
read hits, read misses, write hits and write misses.
Cache Hits vs. Cache Misses
Consider the write-through strategy: every block written to cache is automatically writ-
ten to memory.
• Pro: Simple; memory is always up-to-date with the cache
– No write-back required on block replacement.
• Con: Creates lots of extra traffic on the memory bus.
– Write hit time may be increased if CPU must wait for bus.
One solution to write time problem is to use a write buffer to store the data while it is
waiting to be written to memory.After storing data in cache and write buffer, processor
can continue execution. Alternately, a write-back strategy writes data to main memory
only a block is replaced.
• Pros: Reduces memory bandwidth used by writes.
• Cons: Complicates multi-processor systems
Hit/Miss Rate, Hit Time, Miss Penalty
The hit rate or hit ratio is fraction of memory accesses found in upper level.
The miss rate (= 1 – hit rate) is fraction of memory accesses not found in upper levels.
The hit time is the time to access the upper level of the memory hierarchy, which includes
the time needed to determine whether the access is a hit or miss.The miss penalty is the
time needed to replace a block in the upper level with a corresponding block from the
lower level (may include the time to write back an evicted block).
Cache Performance Analysis: Performance is always a key issue for caches.
• We consider improving cache performance by:
(1) reducing the miss rate, and
(2) reducing the miss penalty.
For (1) we can reduce the probability that different memory blocks will contend for the
same cache location.For (2), we can add additional levels to the hierarchy, which is called
multilevel caching.
We can determine the CPU time as
CPUTime = (CC + CC )×t
CPU Execution MemoryStalls CC
Cache Performance
The memory-stall clock cycles come from cache misses.It can be defined as the sum of
the stall cycles coming from writes + those coming from reads:
Memory-Stall CC = Read-stall cycles + Write-stall cycles, where
Re ads
Re ad - stall cycles = ´ Re ad Miss Rate ´ Re ad Miss Penalty
Pr ogram
æ Writes ö
Write - stall cycles = ç ´ Write Miss Rate ´ Write Miss Penalty ÷
è Pr ogram ø
+ WriteBufferStalls
Registers
Cache
Faster
Speed
Bigger
Main memory Capacity
Magnetic disk
Among all the CPU registers are fastest that can be accessed at a speed equivalent to
the CPU, however they have very small capacity. Next is the cache memory, which is a
little slower than registers and size range is from few KB to few MB. Next is Main
memory, little more slower and size currently ranging from 16 MB to upto few GB. Then
there are magnetic disks substantially slower but with high storage capacity from 200 GB
upto few TeraBytes. Finally, we have magnetic tape and optical disks for archival storage.
As we move down the hierarchy, three key parameters increase. First, the access time
gets bigger. CPU registers can be accessed in a few nanoseconds. Cache memories take
a small multiple of CPU registers. Main memory accesses are typically a few tens of
nanoseconds. Now comes a big gap, as disk access times are at least 10 msec, and tape
or optical disk access can be measured in seconds if the media have to be fetched and
inserted into a drive. Second, the storage capacity increases as we go downward. CPU
registers are good for perhaps 128 bytes, caches for a few megabytes, main memories for
tens to thousands of megabytes, magnetic disks for a few gigabytes to tens of gigabytes.
Tapes and optical disks are offline so can be as much as needed.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-77
Magnetic Disks Read/write head
Magnetic disks play two roles in computer systems: (1 per surface)
· Long-term, nonvolatile storage for files, even when no programs Surface 7
are running
· A level of the memory hierarchy below main memory used as a Surface 6
backing store for virtual memory during program execution Surface 5
A magnetic disk consists of a collection of platters (generally 1 to 12),
rotating on a spindle at 3,600 to 15,000 revolutions per minute (RPM). Surface 4
These platters are metal or glass disks covered with magnetic recording Surface 3
material on both sides, so 10 platters have 20 recording surfaces. Direction of
Surface 2 arm motion
The disk surface is divided into concentric circles, called tracks. Each Surface 1
track in turn is divided into sectors. A sector is the smallest unit that can
be read or written. Surface 0
C
B
(A) Track
(B) Geometrical sector
(C) Track sector D
(D) Cluster
Recording more sectors on the outer tracks than on the inner tracks is called
constant bit density, and is mostly practiced now a days. To read and write
information into a sector, a movable arm containing a read/write head is located Sector
over each surface. Rather than represent each recorded bit individually, groups of
bits are recorded using a run-length-limited code. The arms for all surfaces are
Shaft
connected together and move in conjunction, so that all arms are over the same
track of all surfaces. The term cylinder is used to refer to all the tracks under the
Cylinder
arms at a given point on all surfaces.
To read or write a sector, the disk controller sends a command to move the arm over
Track
the proper track. This operation is called a seek, and the time to move the arm to the
desired track is called seek time. The time for the requested sector to rotate under
the head is the rotational latency or rotational delay. Note that there are two
mechanical components to a disk access. It takes several milliseconds on average
for the arm to move over the desired track and several milliseconds on average for
the desired sector to rotate under the read/write head. The next component of disk
EBD_7203
S3-78 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
access, transfer time, is the time it takes to transfer a block of bits, typically a sector,
under the read-write head. A Disk Controller is associated with each drive that controls
the drive. Some controllers contain a full CPU. The controller’s tasks include accepting
commands from the software, such as READ, WRITE, and FORMAT (writing all the
preambles), controlling the arm motion, detecting and correcting errors, and converting
8-bit bytes read from memory into a serial bit stream and vice versa. Some controllers
also handle buffering of multiple sectors, caching sectors read for potential future use,
and remapping bad sectors. This latter function is caused by the existence of sectors
with a bad (permanently magnetized) spot. When the controller discovers a bad sector,
it replaces it by one of the spare sectors reserved for this purpose within each cylinder
or zone.
Optical Disks
Optical disks are another type of secondary memory. Many types of optical disks are
available in the market like CD(Compact disks), DVD (Digital versatile disks) etc. CD-R
are write once CDs i.e. data can be written to them only once. CD-RW on the other hand
are rewritable CDs i.e. data can be written and erased many times. Similar variations
DVD-R and DVD-RW are also available in the market. Optical disks encodes binary data
in the form of “Pits”: binary value of 0 or off, due to lack of reflection when read and
“lands”: binary value of 1 or on, due to a reflection when read, on a special material often
aluminium on one of its flat surfaces. The data is stored on the disc with a laser or
stamping machine.
Program Control Instructions
JUMP GROUP
Allows programmer to skip program sections
and branch to any part of memory for the
next instruction.
- A conditional jump instruction allows decisions
based upon numerical tests.
- results are held in the flag bits, then tested by
conditional jump instructions
• LOOP and conditional LOOP are also forms
of the jump instruction.
Unconditional Jump (JMP) Short jump is a 2-byte Near jump 3-byte Far jump 5-byte far
instruction that allows jumps or branches to near jump allows a jump allows a jump to
memory locations within +127 and – 128 bytes branch or jump any memory location
- from the address following the jump within ±32K within the real memory
The short and near jumps are often called bytes from the system.
intrasegment jumps. instruction in the Far jumps are called
current code segment. intersegment jumps
Short Jump
• Called relative jumps because they can be moved, with related software, to any
location in the current code segment without a change.
– jump address is not stored with the opcode
– a distance, or displacement, follows the opcode
• The short jump displacement is a distance represented by a 1-byte signed number
whose value ranges between +127 and –128.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-79
Far Jump
Obtains a new segment and offset address to accomplish the jump:
– bytes 2 and 3 of this 5-byte instruction contain the new offset address
EBD_7203
S3-80 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
– bytes 4 and 5 contain the new segment address
– in protected mode, the segment address accesses a descriptor with the base
address of the far jump segment
– offset address, either 16 or 32 bits, contains the offset address within the new
code segment
A far jump instruction replaces the contents of both CS and IP with 4 bytes
following the opcode
• The far jump instruction sometimes appears with the FAR PTR directive.
– another way to obtain a far jump is to define a label as a far label
– a label is far only if it is external to the current code segment or procedure
• The JMP UP instruction references a far label.
– label UP is defined as a far label by the EXTRN UP:FAR directive
Jumps with Register Operands
• Jump can also use a 16- or 32-bit register as an operand.
– automatically sets up as an indirect jump
– address of the jump is in the register specified by the jump instruction
• Unlike displacement associated with the near jump, register contents are trans-
ferred directly into the instruction pointer.
An indirect jump does not add to the instruction pointer
• JMP AX, for example, copies the contents of the AX register into the IP.
– allows a jump to any location within the current code segment
Conditional Jumps and Conditional Sets
• Always short jumps in 8086 - 80286.
– limits range to within +127 and –128 bytes from the
location following the conditional jump
• In 80386 and above, conditional jumps are either short or near
jumps (±32K).
– in 64-bit mode of the Pentium 4, the near jump distance is
±2G for the conditional jumps
• Allows a conditional jump to any location within the current
code segment.
• Conditional jump instructions test flag bits:
– sign (S), zero (Z), carry (C)
– parity (P), overflow (0)
• If the condition under test is true, a branch to the label associ-
ated with the jump instruction occurs.
– if false, next sequential step in program executes
– for example, a JC will jump if the carry bit is set
• Most conditional jump instructions are straightforward as they
often test one flag bit.
– although some test more than one
• Because both signed and unsigned numbers are used in pro-
gramming.
Because the order of these numbers is different, there are two sets of conditional
jump instructions for magnitude comparisons
COMPUTER ORGANIZATION AND ARCHITECTURE S3-81
Signed and unsigned numbers follow different orders
• When signed numbers are compared, use the JG, JL, JGE, JLE, JE, and JNE
instructions.
– terms greater than and less than refer to signed numbers
• When unsigned numbers are compared, use the JA, JB, JAB, JBE, JE, and JNE
instructions.
– terms above and below refer to unsigned numbers
• Remaining conditional jumps test individual flag bits, such as overflow and parity.
The Conditional Set Instructions
• 80386 - Core2 processors also contain conditional set instructions.
– conditions tested by conditional jumps put to work with the conditional set
instructions
– conditional set instructions set a byte to either 01H or clear a byte to 00H,
depending on the outcome of the condition under test
Useful where a condition must be tested at a point much later in the program.
LOOP
• A combination of a decrement CX and the JNZ conditional jump.
• In 8086 - 80286 LOOP decrements CX.
– if CX != 0, it jumps to the address indicated by the label
– If CX becomes 0, the next sequential instruction executes
In 80386 and above, LOOP decrements either CX or ECX, depending upon instruction
mode
• In 16-bit instruction mode, LOOP uses CX; in the 32-bit mode, LOOP uses ECX.
– default is changed by the LOOPW (using CX) and LOOPD (using ECX)
instructions 80386 - Core2
• In 64-bit mode, the loop counter is in RCX.
– and is 64 bits wide
EBD_7203
S3-82 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
There is no direct move from segment register to segment register instruction
Conditional LOOPs
• LOOP instruction also has conditional forms: LOOPE and LOOPNE
• LOOPE (loop while equal) instruction jumps if CX != 0 while an equal condition
exists.
– will exit loop if the condition is not equal or the CX register decrements to 0
• LOOPNE (loop while not equal) jumps if CX != 0 while a not-equal condition exists.
– will exit loop if the condition is equal or the CX register decrements to 0
• In 80386 - Core2 processors, conditional LOOP can use CX or ECX as the counter.
– LOOPEW/LOOPED or LOOPNEW/LOOPNED override the instruction mode
if needed
• Under 64-bit operation, the loop counter uses RCX and is 64 bits in width
• Alternates exist for LOOPE and LOOPNE.
– LOOPE same as LOOPZ
– LOOPNE instruction is the same as LOOPNZ
• In most programs, only the LOOPE and LOOPNE apply.
• Easier to use assembly language statements IF, ELSE, ELSEIF, and ENDIF to
control the flow of the program than to use the correct conditional jump
statementOther statements developed include REPEAT–UNTIL and WHILE–
ENDW.
WHILE Loops
• Used with a condition to begin the loop.
– the .ENDW statement ends the loop
• The .BREAK and .CONTINUE statements are available for use with the while loop.
– .BREAK is often followed by .IF to select the break condition as in .BREAK
.IF AL == 0DH
– .CONTINUE can be used to allow a DO–.WHILE loop to continue if a certain
condition is met
• The .BREAK and .CONTINUE commands function the same manner in C++.
REPEAT-UNTIL
Loops
• A series of instructions is repeated until some condition occurs.
• The .REPEAT statement defines the start of the loop.
– end is defined with the .UNTIL statement, which contains a condition
• An .UNTILCXZ instruction uses the LOOP instruction to check CX for a repeat loop.
• – .UNTILCXZ uses the CX register as a counter to repeat a loop a fixed number
of times
PROCEDURES
• A procedure is a group of instructions that usually performs one task.
– subroutine, method, or function is an important part of any system’s
architecture
• Disadvantage of procedure is time it takes the computer to link to, and return from it.
– CALL links to the procedure; the RET (return) instruction returns from the
procedure
• CALL pushes the address of the instruction following the CALL (return address)
on the stack.
– the stack stores the return address when a procedure is called during a
program
RET instruction removes an address from the stack so the program returns to the
instruction following the CALL
COMPUTER ORGANIZATION AND ARCHITECTURE S3-83
CALL
• Transfers the flow of the program to the procedure.
• CALL instruction differs from the jump instruction because a CALL saves a return
address on the stack.
• The return address returns control to the instruction that immediately follows the
CALL in a program when a RET instruction executes.
Near CALL
• 3 bytes long.
– the first byte contains the opcode; the second and third bytes contain the
displacement
• When the near CALL executes, it first pushes the offset address of the next in-
struction onto the stack.
– offset address of the next instruction appears in the instruction pointer (IP or
EIP)
It then adds displacement from bytes 2 & 3 .Kto the IP to transfer control to the
procedure
The effect of a near CALL on the stack and the instruction pointer.
Far CALL
• 5-byte instruction contains an opcode followed by the next value for the IP and CS
registers.
– bytes 2 and 3 contain new contents of the IP
– bytes 4 and 5 contain the new contents for CS
EBD_7203
S3-84 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
• Far CALL places the contents of both IP and CS on the stack before jumping to the
address indicated by bytes 2 through 5.
• This allows far CALL to call a procedure located anywhere in the memory and
return from that procedure.
• Figure below shows how far CALL calls a far procedure.
– contents of IP and CS are pushed onto the stack
• The program branches to the procedure.
– A variant of far call exists as CALLF, but should be avoided in favor of
defining the type of call instruction with the PROC statement
• In 64-bit mode a far call is to any memory location and information placed onto the
stack is an 8-byte number.
– the far return instruction retrieves an 8-byte return address from the stack and
places it into RIP
The effect of a far CALL instruction
INTERRUPTS
• An interrupt is a hardware-generated CALL
– externally derived from a hardware signal
• Or a software-generated CALL
– internally derived from the execution of an instruction or by some other
internal event
– at times an internal interrupt is called an exception
• Either type interrupts the program by calling
an interrupt service procedure (ISP) or interrupt handler.
Interrupt Vectors
• A 4-byte number stored in the first 1024 bytes of memory (00000H–003FFH) in real
mode.
– in protected mode, the vector table is replaced by an interrupt descriptor table
that uses 8-byte descriptors to describe each of the interrupts
• 256 different interrupt vectors.
EBD_7203
S3-86 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
– each vector contains the address of an interrupt service procedure
• Each vector contains a value for IP and CS that forms the address of the interrupt
service procedure.
– the first 2 bytes contain IP; the last 2 bytes CS
• Intel reserves the first 32 interrupt vectors for the present and future products.
– interrupt vectors (32–255) are available to users
• Some reserved vectors are for errors that occur during the execution of software
– such as the divide error interrupt
• Three different interrupt instructions available:
– INT, INTO, and INT 3
• In real mode, each fetches a vector from the vector table, and then calls the
procedure stored at the location addressed by the vector.
• In protected mode, each fetches an interrupt descriptor from the interrupt
descriptor table.
• Similar to a far CALL instruction because it places the return address (IP/EIP and
CS) on the stack.
INTs
• 256 different software interrupt instructions (INTs) available to the programmer.
– each INT instruction has a numeric operand whose range is 0 to 255 (00H–
FFH)
• For example, INT 100 uses interrupt vector 100, which appears at memory address
190H–193H.
– address of the interrupt vector is determined by multiplying the interrupt type
number by 4
• Address of the interrupt vector is determined by multiplying the interrupt type
number by 4.
– INT 10H instruction calls the interrupt service procedure whose address is
stored beginning at memory location 40H (10H ´ 4) in the mode
• In protected mode, the interrupt descriptor is located by multiplying the type
number by 8
– because each descriptor is 8 bytes long
• Each INT instruction is 2 bytes long.
– the first byte contains the opcode
– the second byte contains the vector type number
When a software interrupt executes, it:
– pushes the flags onto the stack
– clears the T and I flag bits
– pushes CS onto the stack
– fetches the new value for CS from the interrupt vector
– pushes IP/EIP onto the stack
– fetches the new value for IP/EIP from the vector
– jumps to the new location addressed by CS and IP/EIP
• INT performs as a far CALL
– not only pushes CS & IP onto the stack, also pushes the flags onto the stack
• The INT instruction performs the operation of a PUSHF, followed by a far CALL
instruction.
• Software interrupts are most commonly used to call system procedures because
the address of the function need not be known.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-87
The interrupts often control printers, video displays, and disk drives
• INT replaces a far CALL that would otherwise be used to call a system function.
– INT instruction is 2 bytes long, whereas the far CALL is 5 bytes long
• Each time that the INT instruction replaces a far CALL, it saves 3 bytes of memory.
• This can amount to a sizable saving if INT often appears in a program, as it does for
system calls.
INT 3
• A special software interrupt designed to function as a breakpoint.
– a 1-byte instruction, while others are 2-byte
• Common to insert an INT 3 in software to interrupt or break the flow of the soft-
ware.
– function is called a breakpoint
– breakpoints help to debug faulty software
• A breakpoint occurs for any software interrupt, but because INT 3 is 1 byte long,
it is easier to use for this function.
INTO
• Interrupt on overflow (INTO) is a conditional software interrupt that tests over-
flow flag (O).
– If O = 0, INTO performs no operation
– if O = 1 and an INTO executes, an interrupt occurs via vector type number 4
• The INTO instruction appears in software that adds or subtracts signed binary
numbers.
– eith these operations, it is possible to have an overflow
• JO or INTO instructions detect the overflow.
Interrupt Control
• Two instructions control the INTR pin.
• The set interrupt flag instruction (STI) places 1 in the I flag bit.
– which enables the INTR pin
• The clear interrupt flag instruction (CLI) places a 0 into the I flag bit.
– which disables the INTR pin
The STI instruction enables INTR and the CLI instruction disables INTR
• In software interrupt service procedure, hardware interrupts are enabled as one of
the first steps.
– accomplished by the STI instruction
• Interrupts are enabled early because just about all of the I/O devices in the per-
sonal computer are interrupt-processed.
– if interrupts are disabled
Controlling the Carry Flag Bit
• The carry flag (C) propagates the carry or borrow in multiple-word/doubleword
addition and subtraction.
– can indicate errors in assembly language procedures
• Three instructions control the contents of the carry flag:
– STC (set carry), CLC (clear carry), and CMC (complement carry)
EBD_7203
S3-88 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Instruction Function
WAIT If the WAIT instruction executes while the BUSY pin = 1,
nothing happens and the next instruction executes.
– pin inputs a busy condition when at a logic
0 level
– if BUSY pin = 0 the microprocessor waits
for the pin to return to a logic 1
HLT Stops the execution of software.
There are three ways to exit a halt:
– by interrupt; a hardware reset, or DMA
operation
Often synchronizes external hardware interrupts with the
software system
NOP NOP, which performs absolutely no operation When the
microprocessor encounters a NOP, it takes a short time to
execute.
ENTER and LEAVE Used with stack frames, mechanisms used to pass
parameters to a procedure through the stack memory.
Stack frame also holds local memory variables for the
procedure.
Stack frames provide dynamic areas of memory for
procedures in multiuser environments.
• ENTER creates a stack frame by pushing BP onto
the stack and then loading BP with the uppermost
address of the stack frame.
– allows stack frame variables to be accessed
through the BP register
• ENTER contains two operands:
– first operand specifies the number of bytes to
reserve for variables on the stack frame
– the second specifies the level of the procedure
LEAVE instruction removes the stack frame from the
stack. The BP register addresses stack frame data.
BOUND instruction compares the contents of any 16-bit register
against the contents of two words of memory: an upper
and a lower boundary.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-89
PAST GATE QUESTIONS EXERCISE 7. (c) We know that, size is directly proportional to page
frame.
1 (a) So, the RAM is increased. The main memory also
R0 = M
Clock cycle R 0 = R 0 + R 0 R 2 = R 2 – R0 increases and thus the page frame size also increases
[loc 1] which results in reduction of swapping. Thus, lesser
1 IF number of page faults occur.
2 RD
Now, if any replacement rule is applied which doesn’t
3 EX IF
4 MA RD cause blady anomaly always results in reduction of
5 WB EX page faults.
6 MA IF 8. (b) Let us assume that CPU contains two processes when
7 WB RD one process is being executed on the CPU the other
8 EX one is swapped out and all the data is saved on the
9 MA disk. Thus the swap space is basically used for saving
10 WB the process data.
Thus, total number of clock cycles required = 10 9. (a) Memory mapped I/O means, accessing I/O via general
2. (a) As given memory access as opposed to specialized IO
Cache size = 32 kbyte = 32 × 2 ^ 10 byte instructions. An example,
= 2 ^ 15 byte = 15 bit unsigned int volatile const *pMappedAddress const
Therefore, size of tag = 32 – 15 = 17 bit = (unsigned int *)0×100;
Since, 32 byte of block is used by cache, so there So, the programmer can directly access any memory
actually 1 k blocks and for indexing that we need 10 bit. location directly. To prevent such an access, the OS
3. (a) 1. A[l] = B[j] indexed addressing mode (kernel) will divide the address space into kernel space
2. While [*A ++] auto increment and user space. An user application can easily access
3. int. temp = *x Indirect addressing user application. To access kernel space, we need
4. (c) Following are the memory cycles needed during the system calls (traps).
execution cycle. So, IO protection is ensured by OS abstraction.
First memory cycle Read value of A to calculate index 10. (b) In single line interrupt system, vectored interrupts are
addresses not possible but multiple interrupting devices are
Second memory cycle Add R0 to get the address of possible as a single line interrupt system consists of a
first source and read its value single interrupt system consists of a single interrupt
Third memory cycle Read the contents of B request line and a interrupt grant line in such a system
Fourth memory cycle Read the values of the contents it may be possible that at the same time more than one
of B output devices can request an interrupt, thus in such
Fifth memory cycle Write the answer cases only one request will be granted according to
® Total memory cycles needed during the execution the priority as is depicted by the following figure, but
cycle of the instruction = 5 the interrupt is granted to the single request only.
5. (a) Given that R0 ¬ R0 + R1
The clock cycles operate as follows:
Cycle 1 Out : R1
In : S Interrupt
Cycle 2 Out : R2 flip-flop
I/O port 0 I/O port 1 I/O port n
In : T CPU
Cycle 3 Out : S, T
Add : ALU I/O devices
In : R 11. (a) From the given conditions it can be determined that we
Therefore, execution cycle is completed in 3 clock have to set all the other bits to 0 in temp, as the position
cycles. pos is the only deciding factor in jumping to the label.
6. (b) The minimum number of CPU clock cycles needed If the left shift over 1 is done by the pos number then
during the execution cycle =4As 1 cycle required to the mask register can have 1 in pos place, which is
transfer already incremented value of PCand 2 cycle required. Thus, is the option mask ¬ 0 × 1 << pos is
for getting data in MDR1 to load value of MDR in PC. correct.
EBD_7203
S3-108 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
12. (b) As given there is no conditional loop for the 80% of
10^9 instruction thus only single cycle is required for Clock cycle ADD MUL SUB
them and rest requires 2 extra cycles. 1 IF
Thus the total time required = Time of one cycle
2 ID IF
= (80/100 × 109 × 1 + 20/100 × 109 × 2)
= 1/1G × (80/100 × 109 × 1 + 20/100 × 109 × 2) = 1.2s 3 EX ID IF
13. (d) As given, 4 WB EX ID
Number of banks in main memory = 24 and each is of 2
5 EX
byte long.
Block size of cache = 64 byte 6 EX IF
Due to availability of parallel accessing of the banks, 7 WB EX
only two accesses are needed to traverse the entire 8 WB
data and the time required for this access comes out to
Thus, total number of clock cycles required are 8.
be 92 ns.
20. (a) Each address is multiple of 3 as the starting address is
At total time = Decoding time + Latency time
300 and is each instruction consists of 24 bit, i.e., 3
= 24/2 + 80 = 92 ns
byte.
Total latency time for 2 such accesses Thus, in the given options the valid counter will be the
= 2 × 92 = 184 ns one which is the multiple of 3. Out of the options we
14. (c) The number of data cache misses that occur in total are can see that only 600 satisfies the condition.
56 as is clear from the given data. Therefore, it is 600.
15. (a) The lines that will be replaced by the new blocks are 21. (a) The formula used is
lines 4 to 11. Total disk size is given by = Number of surfaces ×
16. (d) The memory reference required by the instruction Number of tracks × Number of sectors × Capacity of
R1 ¬ M [3000] is 1 whereas the memory reference each sector.
required by R2 ¬ M[R3] and M[R3] ¬ R2 is 10. Therefore from the given data, we get
Therefore, total memory reference required = 2 × 10 + 1 Total disk size = 16 × 128 × 256 × 512 byte
17. (a) The content in the memory location 2010 doesn’t = 28 × 220 = 28 megabyte = 256 MB
change as the value in register R1 becomes zero, so the Total number of sectors = 16 × 128 × 256 byte
loop BNZ exists and as the address in R3 becomes = 219 byte
2010. Thus, the content of the location still remains 22. (d) 64 words require 6 bitsno. of sets = no. of lines / set
100. size = 128/4 = 32 sets which require 5 bitsno. of tag bits
18. (a) The locations of various operations are given in the = 20-5-6 = 9,5,6
following table: 23. (b) The first instruction in the fall through path is executed
for all the delayed conditional branch instructions,
irrespective of whether the condition evaluates to true
Location Operation
or false.
1000 R1 ¬ M [3000]
24. (a) I4 since R1 is only read in I4 and its value will remain as
1001 it is while BRANCH is executed and after BRANCH get
1002 R2 ¬ M [R3] executed , since in BRANCH R1 is only read.
1003 R2 ¬ R1 + R2
1004 M[R3] ¬ R2 Tag Set Block
25. (b)
1005 R3 ¬ R3 + 1 17 11 4
From the above figure and given conditions the total
Thus, the location of the instruction INCR3 is 1005, if
number of tags comes out to be = 17 × 2 × 1024 = 32 bit
an interrupt occurs, and thus it is pushed on the stack. 26. (b) The array element ARR [4] [0] has the same cache index
19. (b) As given the pipelined processor has four stages i.e., as ARR [0] [0] since it is given that page size is of 4
IF, ID, EX, WB, kbyte and 1 row contains 1024 elements, i.e., 210
And we know that number of clock cycles required to locations.
ADD and SUB instructions is 1 and by MUL 27. (b) We know that hit ratio is given as
instructions are 3. Number of hits/ Number of hits + Number of rows
In the pipelined processor while one instruction is = 4/16 = 25%
fetched, the other is either being decoded or executed 28. (d) When an RFE (Return From Exception) instruction is
or some action is being performed. Thus, the number executed; no exception is allowed to occur during that
of cycles required by the given set of instructions can time and also it must be a trap instruction and also a
be obtained from the following diagram. privileged one.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-109
Thus all the three statements are true as far as RFE is 37. (c) As already given in question,
concerned. Memory access time for L1 = 2 ns
29. (c) For incrementing the data, the auto-increment Memory access time for L2 = 20 ns
addressing mode is used which purely depends on the Now the required time of transfer = 20 + 2 = 22 ns
size of the data. For example: 38. (a) As given memory access time for main memory
Regs [R1] ¬ Regs [R1] + Mem [Regs [R2] = 200 ns
Regs [R2] ¬ Regs [R2] + d Memory access time L2 = 2 ns
30. (c) The seek latency is not linearly proportional to seek Memory access time L2 = 20 ns
distance due to the higher capacity of tracks on the Total access time = Block transfer time from main
periphery of the latter. The higher capacity of the tracks memory to L2 cache + Access time of L2 + Acces time
is responsible for the presence of this certain amount of L1
of time is required for this cells to reach the read-write Now, the required time of transfer
head so that data transfer can take place. = 200 + 20 + 2 = 222 ns
31. (d) The interrupt register is checked after finishing the
execution of the current instruction. At this time, a CPU
39. (b) As per the given, the instructions are arranged
generally handles an interrupt by the execution of an
accordingly to their meanings. We get the following:
interrupt service routine.
32. (c) As given, basic RAM is 32 k × 1 and we have to design 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
a RAM of 256 k × 8. I0 IF ID OF PO PO PO WO
Therefore, number of chips required
I1 IF ID Stall Stall PO PO PO PO PO PO PO WO
= 256 k × 8/(32 k × 1)
I2 IF ID OF – – – – – – – PO WO
= 245 × 1024 × 8/32 × 1024 × 1)
I3 IF ID OF – – – – – – PO WO
(Multiplying and dividing by 1024)
= 64 = 8 × 8
Here, we can see that the last operation (Write Operand)
Means, 64 = 8 parallel lines × 8 serial RAM chips.
comes at the 15th clock cycle so it takes 15 clock cycles
33. (c) We have to find the sector number of the address
to execute given sequence of instructions.
< 400, 16, 29>
40. (d) One chip contains 10^6 bits.to build 4MB capacity MM
Therefore, 400 * 2 * 10 * 63 + 16 * 63 + 29
32 chips will be required there are 1K × 1K cells in each
= 505037 sector
chip i.e. 10^6 cellshence time taken to refresh a single
34. (c) <0, 16, 13> this address corresponds to a sector number
chip 10^6 × 100 nsthere are 32 such chips hence
which is given by 16 * 63 + 31 = 1039
32 × 10^6 × 100 ns time will be takeni.e. 3200 × 2^20ns
41. (a) Number of clock cycles required by susing load-store
35. (d) Set 0 48 approach = 2 + 500 × 7 = 3502 and that of by using
4 32 DMA = 20 + 500 × 2 = 1020
8
26 92 Required speed up = 3502 / 1020 = 3.4
Set 1 1 42. (d) Direct mapped cache => number of sets = 8KB/32B =
133 2565 bits for offset within a block & 8 bits for identifying
73 set So remaining 32-8-5=19 bits for tag.1 tag/32B block
129
Set 2 it includes 2 more bits. So 21 bits/32 B block Number of
Set 3 255155 such blocks = 256 So total tag mem = 256 × 21 = 5376
3
159 ( 5 + 6 + 11 + 8) ´ 1 30
43. (b) Speed up = = = 2.5
63 ( 11 + 1 ) 12
44. (d) Higher priority interrupt levels are assigned to requests
which, if delayed or interrupted, could have serious
0 mod 4 = 0 (set 0)
consequences. Devices with high speed transfer such
255 mod 4 = 3 (set 3)
as magnetic disks are given high priority and slow
Like this the sets in the above table are determined for
diviser such as keyboard receive low priority. Mouse
the other values.
pointer moments are more frequent then keyboard ticks.
36. (d) Number of cycle for executing loop i=1 is 15 so,
So its obvious that its data transfer rate is higher than
total no. of cycle is 2*15(loop runs 2 time), if
keyboard. Delaying a CPU temperature sensor could
we calculate no. of pipeline continuous no option
have serious consequences, overheat can damage CPU
will match, so here we have to take loop independently.
circuitry. From the above information we can conclude
EBD_7203
S3-110 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
that priorities are - CPU temperature sensor > Hard Option (b) :
disk > Mouse > Keyboard. (11 mod 3) to (11 mod 3) + 4 = 2 to 6
45. (d) The addressing mode will be base index addressing. Option (c) :
Here, 20 will work as base and content of R2 will be (11 mod 5) to (11 mod 5) + 2 = 6 to 8
index. R2 is base regester here and indexing is done by Clearly, option (a) gives correct answer.
adding 20 to the contents of R2. 50. (d) The following sequence of micro-operations
46. (b) Effective access time = p × page fault service time MBR ¬ PC
+ (1 – p) × memory access time MAR ¬ X
PC ¬ Y
1
where p = page fault rate = = 0.000001 Memory ¬ MBR.
106 Analysis
memory access time = 20 ns 1. First micro operation stores the value of PC into
Page fault service time = 10 ms = 10000000 Memory Base Register (MBR).
Þ 0.000001 × 10000000 ns + 0.999999 × 20 ns = 29.9998 2. Second micro operation stores the value of X into
» 30 ns Memory Address Resister (MAR).
47. (d) The normal size of ROM is n × 2n 3. Third micro operation stores value of Y into PC.
\ Now, we are multiplying two n-bit numbers. 4. Fourth micro operation stores value of MBR to
So, the resultant has 2n bit. memory.
Hence, the size of the ROM is 2n × 22n So before execution of these instructions PC holds
In the question, n = 4 the value of next instruction to be executed. We first
Hence, Þ 2 × 4 × 22×4 stores the value of PC to MBR and then through
Þ 8 × 28 Þ 23 × 28 MBR to memory i.e., We are saving the value of PC
Þ 2 × 210 Þ 2 k bit in memory and then load PC with a new value. This
OR can be done only in two types. Operations
As there is two independent 4 bit inputs, so you need Conditional branch and interrupt service.
2 × 4 = 8 address lines A 4 bit × 4 bit multiplication has As we are not checking here for any conditions.
8 bit result, you need 8 data lines. So, it is an Initiation of interrupt service.
\ Rom needs to be at least 256 × 8 = 2 k bit. 51. (d) Starting disk location of the file is <1200, 9,40 >.
48. (c) Pipelining of the register renaming logic can help avoid Since starting number of sectors left on 9th surface
restricting the processor clock frequency. is = 24. So, on 9th surface total storage of "12288"
49. (b) Considering the following case such that the cache B is possible. Now, a part from 9th surface, on
blocks are arranged as follows cylinder number 1200 only 6 surface is left,
Storage possibilities on these 6 surfaces are
0 3 6 9 12 = 6 × 26 * 29 storage on each sector
1 4 7 10 13 number of sectors on each surface
2 5 8 11 14 =196608 B
The total on cylinder no 1200, storage possible
The cache is divided into v = 3 sets and each of
= 196608 + 12288 = 208896 B.
which consists of k = 5 lines.
Since file size is 42797 KB and out of which 208896
e.g. suppose we need to find the block 9, then
B are stored on cylinder, no 1200. So we are left only
Option (a) :
with 43615232 B.
(9 mod 3) * 5 to (9 mod 3) * 5 + 4 = 0 to 4
Since in 1 cylinder, storage possible is
Option (b) :
= 24 * 26 * 29 B = 524288 B.
(9 mod 3) to (9 mod 3) + 4 = 0 to 4
Option (c) : 43615232B
So, we need about = 524288B = 83.189 more
(9 mod 5) + (9 mod 5) + 2 = 4 to 6
Option (d) : cylinders.
(9 mod 5) * 3 to (9 mod 5) * 3 + 2 = 12 to 14 Hence, we will need 1284th cylinder to completely
Now check for option (a), (b), (c) and (d). store the files since after 1283rd cylinder we will be
Check for block 11. left with data which will 189.
Option (a) : 52. (b)
(11 mod 3) * 5 to (11 mod 3) * 5 + 4 = 10 to 14 53. (b) Instruction pipeline with five stages without any
COMPUTER ORGANIZATION AND ARCHITECTURE S3-111
branch predicition: Delays for FI, DI, FO.EI and WO e = e * e if (R2 > R1) x=c*c
are 5,7,10,8,6 ns respectively. } { (x > a)
Explanation The maximum time taken by any stage is R2 ¬ R1 + R1 (y – a * a)
10 ns and additional 1ns is required for delay of }
buffer. else {
\ The total time for an instruction to pass from one R2 ¬ (read value of c from memory) R1 (d = c * a)
stage to another in 11 ns. R2 ¬ R2 * R2 (d = d * d)
The instructions are executed in the following order R2 ¬ (read value of c from memonry)
l1, l2, l3, l4, l9, l10, l11, l12 + R1 (e = c + a)
Execution with Time R2 ¬ R2 * R2 (e = e * e)
Now when l4 is in its execution stage we detect the }
branch and when l4 is in WO stage we fetch I9 so Þ There has been only 1 memory write observed
time for execution of instructions from l9 to l12 is = in the give code.
11* 5 +(4 – 1) * 11= 88 ns. So the answer is 1.
But we save 11 ns when fetching l9 i.e., l9 requires 56. (b)
only 44 ns additional instead of 55ns because time 57. (c)
for fetching l9 can be overlap with WO of l4. 58. 16383
\ Total Time is = 88 + 88 – 11 = 165 ns (i) Given is 32-bit architecture machine with 1 word long
54. (b) Assuming that R1 and R2 holds the value of a and instruction; so, the instruction size is 32 bit.
b respectively. The machine code is equivalent to
R2 ¬ R1 + R2 (c = a + b) (R2 holds c) 32-bit
R3 ¬ R2 * R1 (d = c * a)
(Instruction)
R4 ¬ R2 + R1(e = c + a)
R2 ¬ R2 * R2 (x = c * c) (ii) As the machine need to support 45 instructions, the
(Removing c from R2 as c is not used after this number of bits required in the “opcode field” is 6
statements R2 holds x) bits, because,
If (R2 > R1) { {If (x > a)} 5-bits: 25 = 32 (Not sufficient)
6
If (R2 > R1) 6-bits: 2 = 64 (Sufficient)
{ (iii) As the machine has 64 registers, so to uniquely
R2 ¬ R1 × R1 identify a register out of those 64 registers, we need
R2 ¬ R1 * R1 (y = a* a) 6-bits. (using the similar argument as above)
} As each instruction has 2 register operands, so
else { 6 + 6 = 12 bits are needed for them.
R3 ¬ R3 * R3 {d =d *d) So, finally instruction will took like as follows:
R4 ¬ R4 * R4 (e = e * e)
Opcode Reg 1 Reg 2 Immediate operand
}
We have used R1, R2, R3,R4 registers 6 6 6 14
So answer is (b) 4. (Total = 32 bits)
55. (b) In this question we have to minimize spills to memory (iv) As 14-bits are available for immediate operand, the
(writer). As variables d,e are only used in else part. max value will be 214 = 16384.
So we can move d,e instructions inside else. The However one value will be used for “Zero” also as
code we get is the operand is an “unsigned integer”. So, finally, the
c = a + b; Assumption-Register R1 and R2. maximum value that the immediate operand can take
x = c * c; Already holds a and b respectively, = 214 – 1 = 16383.
if (x > a) 59. 4 to 4
{ We can first calculate the number of
n
y=a* a memory spill. The machine code is 60. (A)
N
equivalent to
else { 61. 20
d = c * a; R2 ¬ R1 + R2 (c = a + b) Physical address size = 32 bit
d = d*d; write R2 to memory (So memory has value Cache size = 16k bytes
of c) = 214 bytes
EBD_7203
S3-112 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
block size = 8 words P1 : CP = Max (1, 2, 2, 1) = 2 ns
= 8 × 4 byte P2 : CP = Max (1, 1.5, 1.5, 1.5) = 1.5 ns
= 32 byte P3 : CP = Max (0.5, 1, 1, 0.6, 1) = 1 ns
214 P4 : CP = Max (0.5, 0.5, 1, 1, 1, 1) = 1.1 ns
No. of blocks = = 29 Q CP of P3 is less, it has highest frequency
25
block offset = 9 bits 1
Frequency 1 P3 = = 1GHz
29 29 1ns
No. of sets = = = 27
4 22 67. 1.54
set offset = 7 bits
Byte offset = 8 × 4 bytes A vg.
No. of Stall Stall Clock
acces s
= 32 bytes s tages cycle frequency period
time
= 25 Old des ign 5 5 20% 2.2ns P
Þ 5 bits New Des ign 8 5 20% 1 ns Q
TAG = 32 – (7 + 5) = 20 bits
P=
32 bit
SET BYTE
TAG OFFSET OFFSET é æ 1 2 öù
ê80%(1clock) + 20% ç + ú ´ Tc - p
20 7 5 ë è completion stall clock ÷ø û
62. (d) A smaller cache block size accomodate more number
P = (.8 + .6) × 2.2ns = 3.08ns
of blocks, it improves hit ratio of cache, so the miss
penalty is covered. Q=
63. (d) If the associativity of a processor cache is doubled
é æ 1 5 öù
while keeping the capacity and cache block size ê80%(1clock) + 20% ç + ú ´ Tc - p
unchanged, the width of processor to main data bus ë è completion stall clock ÷ø û
is not affected.
P = (.8 + .12) × 1ns = 2ns
64. (a) 14.25 = 1110.010
= 1.110010 × 23 P 3.08ns
\ m = 110010 So the value of = = 1.54
Q 2ns
1 8 23 68. 1.68
S E M Total instructions = 100 instruction fetch operation + 60
(= C1640000)
1 10000010 11001000 memory operant read operation + 40 operant write
operation
E = 127 + 3 = 130
Therefore, total of 200 instructions
= 10000010
65. 10000 Time taken for fetching 100 instructions (equivalent to
Each write request, the basic occupied for 100 ns read)
Storing the data requires 100 ns. = 90 × 1ns + 10 × 5ns = 140ns
In 100 ns – 1 store Memory operand Read operations = 90%(60) × 1ns +
100 10% (60) × 5ns
ms ® 1 store
106 = 54ns + 30ns = 84ms
Memory operands write operation time = 90%(40) × 2ns
106 + 10%(40) × 10ns
1 ms = stores
100 = 72ns + 40ns = 112ns
= 10.000 stores
Total time taken for executing 200 instructions = 140 + 84
1 + 112 = 336ns
66. (c) Frequency µ clock period
336
Clock period = maximum stage delay + overhead \ Average memory access time = ns = 1.68ns
200
COMPUTER ORGANIZATION AND ARCHITECTURE S3-113
PRACTICE EXERCISE Required bits for block = 2 (as 4 block are in 1 set)
Two operand locations and a result location are 61. (c) 62. (d) 63. (a) 64. (d)
explicitly contained in the instruction word. 65. (b) Speed up
e.g., Y = A – B
2 address instruction 1
=
æ1 - % of time cache ö é % of time cache can be used ù
One of the addresses is used to specify both an ç ÷+ê ú
è can be used ø ë speed up using cache û
operand and the result location.
e.g., Y = Y + X
1
1 address instruction 1 1
= (1 - 0.7 ) + 0.7 = = = 2.7
Two addresses are implied in the instruction and 10 0.3 + 0.07 0.37
accumulator based operations.
Hence, we obtain a speed up from the cache of about
e.g., ACC = ACC + X
2.7 times
0 address instructions
66. (b) 67. (d)
They are applicable to a slpecial memory organization
68. (d) The performance of a pipelined processor depends
called a stack. It interact with a stack using push and
upon delays of different stage and its hardware
pop operations. All addresses are implied as in
resources also it depends upon con secutive
register based operations.
instructions format.
T = Tap(T – 1)
69. (d) Memory address: 16 bits
54. (d) The secondary cache can be considerably slower,
Number of words in cache = 256 = 28
but it shold be much larger to ensure a high hit rate
if speed is less critical, because it only affects the
COMPUTER ORGANIZATION AND ARCHITECTURE S3-115
8 8 78. (a)
TAG Index 79. (a) A Þ Two address instruction
B Þ One address instruction
Block Word C Þ Zero address instruction
5 3 80. (a) Pipelined operation is interrupted whenever two
70. (b) operations being attempted in parallel need the same
71. (c) Initially R0 ¬ X, R1 ¬ Y, R2 ¬ Z hardware component, such a conflict can occur if the
The sequence of operations to compute XY + XYZ + execution phase of an instruction requires access to
YZ is as follows the main memory, which also contains the next
Operation Meaning No. of clock cycles instruction that should be fetched at the same time.
MUL R0, R1, R3 R3 ¬ XY 1 81. (c) Average instruction execution time
MUL R1, R2, R5 R5 ¬ YZ 1 = 1 ns × ((40% + 20%) × 4 + 40% ×5) = 4.4 ns
MUL R2, R3, R4 R4 ¬ XYZ 1 Speed up from pipeline
ADD R3, R4, R6 R6 ¬ XY + XYZ 1 = Average instruction time unpip lined/Average
ADD R5, R6, R7 R7 ¬ XY + XYZ + YZ 2 instruction time pipelined
Total 6 clock cycles 4.4
= = 3.7
72. (d) Average access time = Hit ratio × Cache access time + 1.2
Miss ratio × Memory access time
82. (c) Control command: A control command is issued to
Here, memory access time = 1.5 ms i.e. 1500 ns
activate the peripheral and to inform it what to do.
So, average across time = 0.98 × 12 ns + 0.02 × 1500ns
Status: A status comman is used to test various status
= 11.76 ns + 30 ns = 41.76 ns
conditions in the interface and the peripheral.
73. (b)
Data output command causes the interface to respond
74. (c) The diagram shows, extended addressing mode. In this, by transferring data from the bus into one of its register.
the effective memory address directly specified and it
is used by some of the processor and address specified 83. (c) A synchronous data transfer between two independent
is 16 bit address. units requires that control signals be transmitted
between the communicating units to indicate the time
75. (b)
at which data is being transmitted.
76. (c) There are 7 pushes and pops for a cost of 35 bytes plus
3 arithmetic instructions for a total of 38 bytes storage. Two ways of achieving this
After instruction Stack contains New variables 1. By means of a strobe pulse supplied by one of the
units to indicate to the other unit when the transfer has
push b b
to occur.
push x b, x
add b+x Data bus
Source Destination
pop c c= b+ x unit Strobe unit
push c b+x c= b+ x
push y b + x, y c= b+ x 2. To accompany each data item being transferred with a
control signal that indicates the presence of data in the
add b+x+y c= b+ x
bus. The unit receiving the data item responds with
push c b + x + y, b + x c= b+ x another control signal to acknowledge receipt of the
sub y c= b+ x data. This type of agreement between two independent
pop z c = b + x, z = y units is referred to as handshaking.
77. (b) Initially VC Z 1100 1100 84. (a) Rounding to plus and minus infinity are useful in
00 0 1000 1111 implementing a technique known as interval arithmetic.
After addition 11 0 10101 1011 Interval arithmetic provides an efficient method for
V-bit is set to 1 due to arithmetic overflow. monitoring and controlling errors in floating point
computations by producting two values for each result.
C-bit is set to 1 because most significant digits generates a
The two values correspond to the lower and upper
carry.
endpoints of an interval that contains the true result.
Z-bit is set to 0 because the result of addition is not zero.
EBD_7203
S3-116 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The width of the interval, which is the difference
æ ö
n
between the upper and lower endpoints, indicates the Number of TAG bits = log2 (mx) – ç log 2 k + log 2 x ÷
è ø
accuracy of the result of the endpoints of an interval
are not representable then the interval endpoints are nx mk
rounded down and up respectively. = log 2 ( mx ) - log = log 2
k n
85. (d) Effective access time = (hit ratio) × (memory access
95. (b)
time + search time in associative registers) + (fail ratio)
× (search time in associative registers + 2 × memory 96. (b) We are asked minimum performance gain , So consider
access time) = (0.90 × 150) + (0.10 × 250) = 160 for transferring minimum amount of data which is 1
nanoseconds. Byte. For program controlled mode, CPU will be busy
for 1/(10 * 2 ^ 10) = 97.66 microsec.
Now percentage slowdown = 160 – 100 = 60
For interrupt mode extra overhead = 4microsec. So
86. (b) The first format defines 26 patterns, among which 3 are
minimum performance gain is 25 approx.
not used for op-codes. The second format occurs for
these 3 cases, and each case corresponds to 26 patterns. 97. (b) 98. (b) 99. (b)
So, the total number of op-codes = 26 – 3 + 3 × 26 = 61 100. (c) Minimum cycle time =latency of longest module in
+ 192 = 253. data path plus pipeline latch time =7ns + 1 ns=8 ns.
87. (d) 88. (d) 89. (c) assuming that thereis no limit on the number of pipeline
stages. We need to know how many pipeline stages
90. (b) DMA Clock is 2 MHz Þ Each DMA Clock state is 0.5
the processor requires to operate at a cycle time of 8ns.
mS
We can group any set of adajacent modules with total
Each DMA Cycle has 6 Clock States Þ Each DMA latencies of 7 ns or less into a single stage. Doing this
cycle is 3 mS gives 5 pipeline stages.
In Cycle Steaing 1 CPU and 1 DMA Cycles run 5 stages * 8 ns cycle time = 40 ns latency
alternately and the CPU Cycle takes 2 mS.
101. 165.420 microsecond
Therefore, every 3 + 2 = 5 mS, 1 Byte is transferred by
102. 4.76
DMA device.
Data Transfer Rate = 1000000/5 × 1 Byte nt p 100 ´ 50 500
S= = = =
(k + n - 1) t p (6 + 100 - 1) ´ 10 105
= 200 Kbytes/Sec.
91. (b) Next Address Field = 7 Bits 103. the current generation of chips (DDR SDRAM)
ALU function field is of 4 Bits (to select possible 1 of has a refresh time of 64 ms and 8,192 rows, so the
13 ALU fns) refresh cycle interval is 7.8 µs
Register-in and Register-out fields of 3 Bits each 104. 3
Shifter field of 2 bits to select 1 out of three possibilities 105. 21
Auxiliary field of 4 Bits A virtual page with 32-bit addresses between
Total Bits in m-instruction = 7 + 4 + 3 + 3 + 2 + 4 = 23 0xffff e800 to 0xffff efff
92. (b) 93. (a) • Virtual Page size = (0xffff efff - 0xffff e800 + 1)
n = 2 × 1024 B = 2 kB
94. (a) Number of sets = • Number of offset bits = log2 (2 × 1024) =
k
log2(211)
Let there are x words per block in main memory.
• Number of VPN bits = 32 - 11
log2 mx 106. 5.3
TAG SET word Let M = main memory access time
n
log2 k log2x M
C = cache memory access time =
10
COMPUTER ORGANIZATION AND ARCHITECTURE S3-117
Total access time using cache = 0.9 + 0.1 M it is 2-way set association, 32 sets if 4-way set associative,
and 16 set if 8-way set-associative.
M
= 0.9 + 0.1 M = 0.19 M 116. 34
10
Using the formula,
M
Speed up = = The average access time =(THitX H1t) + (TmissXmiss)The
0.19 M
average access time is (12 ns x 0.75) + (100 ns x 0.25) =
107. 28 34 ns
117. 96.2
C1S1 + C2C2
Average cost = The average access time
S1 + S2
10ns = (8ns × hit rate) + 60 ns × (1–(hit rate)),
1024 ´100 + 4096 ´10 143360 (The hit and miss rates at a given level should sum to 100
= = =
1024 + 4096 5120 percent). Solving for hit rate, we get required hit rate of
108. 00111000 96.2%.
Register R contains : 10011100 118. 4
After arithmetic shift right register R contains 11001110 No of RAM chips = 2048/ 256 =8 .
After arithmetic shift left register R contains 00111000 No of ROM chips = 4096/ 1024=4 (note that rest of
the info is given to confuse and is not required)
109. 64
119. 1.4
Memory capacity is 4096 × 16 Each chip is 128 × 8
CPI = (1 inst-per-cycle) + (0.05)(8 cycles/miss) = 1.4
No. of chips which is 128 x 8 of 4096 x 16 memory capacity
120. (c) 121. (c) 122. (c) 123. (a) 124. (c)
=4096 * 16/ (128 *8) =64
110. 16 125. (a) Tag(6 bits) Set(6 bits) Word (4 bits)
Number of RAM chips required = 2048 / 128 =16
126. (c) 357 A, whose 16 bits are 0011010101111010, the first
111. 11
6 bits of which determine the “tag” value. The
2048 =2(pow, 11) . Hence 11 lines of the address bus must decimal value of 001101 is 13.
be used to access 2048 bytes of memory.
127. (b) Instructions No. of clock cycles
112. 6 microseconds
AC: = M(X) LOAD A 1
At 10,000 r/min, it takes 6ms for a complete
AC: = AC + M(Y) ADD Y 1
rotation of the disk. On average, the read/write head will
M(Z): = AC STORE Z 1
have to wait for half rotation before the needed sector
reaches it, SC) the average rotational latency will be 3ms. Total = 3
Since there are 1024 sectors on the track, the transfer time 128. (c) Instructions No. of clock cycles
will he equal to the rotation time of the disk divided by DR: = AC MOVE DR, AC 1
1024, or approximately 6 microseconds. AC: = AC – DR SUB 1
113. 6 Total = 2
2(pow,6)= 64, so the 6 bits of address determine an 129. (a) Average Memory Access time
address's byte within a cache line.
= Hit Time L1 + Miss rate L1 × (Hit time L2 + Miss rate
114. 1024 L2 × Miss Penalty L2) = 1 + 4% (10 + 50% × 100)
The number of lines in cacheis simply the capacity
divided by the line length, so the cache has 1024 lines é 40 ù
ê Miss rate L1 = 1000 ´ 100 = 4% ú
with 32-byte lines, 512 lines with 64-byte lines, and 256 ë û
lines with 128 byte lines.
é 40 ù
115. 64 =1 + 4% × 60 ê Miss rate L1 = ´100 = 4% ú
ë 1000 û
With 128-byte lines, the cache contains a total of 128
= 3.4 clock cycles
lines.The number of sets in the cache is the number of
lines divided by the associativity so cache has 64 sets if
EBD_7203
S3-118 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
130. (c) Average Memory Stall per instruction 132. (c) Average instruction time pipelined = 1 + 0.2 = 1.2 ns
= Misses per instruction L1 × Hit time L2
4.4
+ Misses per instruction L2 × Miss penalty L2 Speedup from pipelined = = 3.7 ns
1.2
= (60/1000) × 10 + (30/1000) × 100 = 3.6 clock cycles.
133. (b) 134. (b) 135. (b) 136. (b)
131. (b) Average instruction execution time
= Clock cycles × Average Cp1
= 1[(40% + 20%) × 4 + 40% × 5)] ns
= 1 × 4.4ns = 4.4 ns
3
Page - 119 - 200
C Ø Programming in C
O Ø
Ø
Functions, Recursion
Parameter Passing
N Ø Scope, Binding
T
Ø Abstract data types, Arrays, Stacks
N
Ø Binary heaps
T
S
EBD_7203
S3-120 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
PROGRAMMING AND DATA STRUCTURES PROGRAMMING
IN C
C is a general-purpose high level language that was originally developed by Dennis
Ritchie for the Unix operating system. It was first implemented on the Digital
Equipment Corporation PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C
language. C has now become a widely used professional language for various
reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
C Program File
All the C programs are writen into text files with extension ".c" for example hello.c.
You can use "vi" editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to write
programming insturctions inside a program file.
C Compilers
When you write any program in C language then to run that program you need to
compile that program using a C Compiler which converts your program into a
language understandable by a computer. This is called machine language (ie. binary
format). So before proceeding, make sure you have C Compiler available at your
computer. Preprocessor Commands
• Functions
• Variables
• Statements & Expressions
• Comments
The following program is written in the C programming language. Open a text file
First.c using vi editor and put the following lines inside that file.
#include <stdio.h>
int main()
{
/* My first program */
printf("This is a C program! \n");
return 0;
}
Preprocessor Commands: These commands tells the compiler to do preprocessing
before doing actual compilation. Like #include <stdio.h> is a preprocessor command
which tells a C compiler to include stdio.h file before going to actual compilation.
Functions: are main building blocks of any C Program. Every C Program will have one
or more functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function returns
an integer value when it exits. This integer value is returned using return
statement.The C Programming language provides a set of built-in functions. In the
above example printf() is a C built-in function which is used to print anything on the
screen.
Variables: are used to hold numbers, strings and complex data for manipulation.
Statements & Expressions : Expressions combine variables and constants to create
new values. Statements are expressions, assignments, function calls, or control flow
statements which make up C programs.
Comments: are used to give additional useful information inside a C Program. All the
comments will be put inside /*...*/ as given in the example above.
Note the followings
PROGRAMMING AND DATA STRUCTURES S3-121
• C is a case sensitive programming language. It means in C printf and Printf
will have different meanings.
• C has a free-form line structure. End of each C statement must be marked
with a semicolon.
• Multiple statements can be one the same line.
• White Spaces (ie tab space and space bar ) are ignored.
• Statements can continue over multiple lines.
C - Reserved Keywords
The following names are reserved by the C language. Their meaning is already
defined, and they cannot be re-defined to mean anything else.
Auto else Long switch
Break enum register typedef
Case extern return union
Char float Short unsigned
Const for signed void
Continue goto Sizeof volatile
Default if Static while
Do int Struct Packed
Double
While naming your functions and variables, other than these names, you can choose
any names of reasonable length for variables, functions etc.
C Preprocessor, Directives and Header Files:
C Preprocessor :
As part of compilation, the C compiler runs a program called the C preprocessor. The Syntax :
preprocessor is able to add and remove code from your source file. One of the major #define directive:
functions of C preprocessor is Tokenizing. The final step of the preprocessor is to #define identifier substitution_token
link the resulting program with necessary programs and library. For Example:
This directive is used for text substitution. Every occurrence of the identifier is #define TRUE 1
substituted by the substitution_token. The primary advantage is that it increases the #define FALSE
readability of the program. #define MAX 100
# include directive: #define PI 3.14
Syntax :
This directive searches for a header or source file, which can be processed by the #include <filename>
implementation, to be include in the program.
Header files:
Header files are a collection of macros, types, functions and constants. Any program
that needs those functions can include the corresponding header files.
List of some commonly used Header file and their purposes:
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
A variable is just a named area of storage that can hold a single value (numeric or
character). The C language demands that you declare the name of each variable that
you are going to use and its type, or class, before you actually try to do anything
with it.
The Programming language C has two main variable types
• Local Variables
• Global Variables
Local Variables
• Local variables scope is confined within the block or function where it is
defined. Local variables must always be defined at the top of a block.
• When a local variable is defined - it is not initalised by the system, you
must initalise it yourself.
• When execution of the block starts the variable is available, and when the
block ends the variable 'dies'.
Global Variables
Global variable is defined at the top of the program file and it can be visible and
modified by any function that may reference it.
Data Type Initialser
int 0
char '\0'
float 0
pointer NULL
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 good practice to use global variables and
local variables with the same name.
C - Storage Classes
A storage class defines the scope (visibility) and life time of variables and/or
functions within a C Program.
There are following storage classes which can be used in a C Program
• auto
• register
• static
• extern
auto - Storage Class
auto is the default storage class for all local variables.
{
int Count;
auto int Month;
}
PROGRAMMING AND DATA STRUCTURES S3-123
The example above defines two variables with the same storage class. auto can only
be used within functions, i.e. local variables.
register - Storage Class
register is used to define local variables that should be stored in a register instead
of RAM. This means that the variable has a maximum size equal to the register size
(usually one word) and cant have the unary '&' operator applied to it (as it does not
have a memory location).
{
register int Miles;
}
Register should only be used for variables that require quick access - such as
counters. It should also be noted that defining 'register' goes not mean that the
variable will be stored in a register. It means that it MIGHT be stored in a register
- depending on hardware and implementation restrictions.
static - Storage Class
static is the default storage class for global variables. The two variables below (count
and road) both have a static storage class.
static int Count;
int Road;
{
printf("%d\n", Road);
}
static variables can be 'seen' within all functions in this source file. At link time, the
static variables defined here will not be seen by the object modules that are brought
in.Static can also be defined within a function. If this is done the variable is initalised
at run time but is not reinitalized when the function is called. This inside a function
static variable retains its value during various calls.
NOTE : Here keyword void means function does not return anything and it does not
take any parameter. You can memoriese void as nothing. Static variables are initialized
to 0 automatically.
Definition vs Declaration : Before proceeding, let us understand the difference
between defintion and declaration of a variable or function. Definition means where
a variable or function is defined in realityand actual memory is allocated for variable
or function. Declaration means just giving a reference of a variable and function.
Through declaration we assure to the complier that this variable or function has been
defined somewhere else in the program and will be provided at the time of linking.
In the above examples char *func(void) has been put at the top which is a declaration
of this function where as this function has been defined below to main() function.
There is one more very important use for 'static'. Consider this bit of code.
char *func(void);
main()
{
char *Text1;
Text1 = func();
}
char *func(void)
{
char Text2[10]="martin";
return(Text2);
}
Now, 'func' returns a pointer to the memory location where 'text2' starts But text2 has
a storage class of 'auto' and will disappear when we exit the function and could be
overwritten but something else. The storage assigned to 'text2' will remain reserved
for the duration if the program.
EBD_7203
S3-124 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
extern - Storage Class
extern is used to give a reference of a global variable that is visible to ALL the
program files. When you use 'extern' the variable cannot be initalized as all it does
is point the variable name at a storage location that has been previously defined.
File 1: main.c
int count=5;
main()
{
write_extern();
}
File 2: write.c
void write_extern(void);
void write_extern(void)
{
printf("count is %i\n", count);
}
Here extern keyword is being used to declare count in another file.
Now compile these two files as follows
gcc main.c write.c -o write
This fill produce write program which can be executed to produce result.
Count in 'main.c' will have a value of 5. If main.c changes the value of count - write.c
will see the new value
The same program in C ++
int count ;
extern void write_extern();
main()
{
count = 5;
write_extern();
}
Second File: support.cpp
#include <iostream>
void write_extern(void)
{
std::cout << "Count is " << count << std::endl;
}
Here, extern keyword is being used to declare count in another file. Now compile these
two files as follows:
$g++ main.cpp support.cpp -o write
C - Using Constants
A C constant is usually just the written version of a number. For example 1, 0, 5.73,
12.5e9. We can specify our constants in octal or hexadecimal, or force them to be
treated as long integers.
• Octal constants are written with a leading zero - 015.
• Hexadecimal constants are written with a leading 0x - 0x1ae.
• Long constants are written with a trailing L - 890L.
Character constants are usually just the character enclosed in single quotes; 'a', 'b',
'c'. Some characters can't be represented in this way, so we use a 2 character sequence
as follows.
'\n' newline
'\t' tab
'\\' backslash
'\'' single quote
'\0' null ( Usedautomatically to terminate character string )
In addition, a required bit pattern can be specified using its octal equivalent.
'\044' produces bit pattern 00100100.
Character constants are rarely used, since string constants are more convenient. A
string constant is surrounded by double quotes eg "Brian and Dennis". The string
is actually stored as an array of characters. The null character '\0' is automatically
placed at the end of such a string to act as a string terminator.
A character is a different type to a single character string. This is important poing
to note.
Defining Constants
ANSI C allows you to declare constants. When you declare a constant it is a bit like
a variable declaration except the value cannot be changed.
The const keyword is to declare a constant, as shown below:
int const a = 1;
const int a =2;
The enum Data type
enum is the abbreviation for ENUMERATE, and we can use this keyword to declare
and initialize a sequence of integer constants. Here's an example:
enum colors {RED, YELLOW, GREEN, BLUE};
I've made the constant names uppercase, but you can name them which ever way you
want.
Here, colors is the name given to the set of constants - the name is optional. Now,
if you don't assign a value to a constant, the default value for the first one in the
list - RED in our case, has the value of 0. The rest of the undefined constants have
a value 1 more than the one before, so in our case, YELLOW is 1, GREEN is 2 and
BLUE is 3.
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.
The main advantage of enum is that if you don't initialize your constants, each one
would have a unique value. The first would be zero and the rest would then count
upwards.
EBD_7203
S3-126 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
#include <stdio.h>
int main() {
enum {RED=5, YELLOW, GREEN=4, BLUE};
RED = 5
YELLOW = 6
GREEN = 4
BLUE = 5
C - Operator Types
• Arithmetic Operators
• Logical (or Relational) Operators
• Bitwise Operators
• Assignment Operators
• Misc Operators
Lets have a look on all operators one by one.
Arithmetic Operators:
There are following arithmetic operators supported by C language:
Assume variable A holds 10 and variable B holds 20 then:
Show Examples
<= Checks if the value of left operand is less than (A <= B) is true.
or equal to the value of right operand, if yes
then condition becomes true.
&& Called Logical AND operator. If both the (A && B) is true.
operands are non zero then then condition
becomes true.
|| Called Logical OR Operator. If any of the two (A || B) is true.
operands is non zero then then condition
becomes true.
! Called Logical NOT Operator. Use to reverses !(A && B) is false.
the logical state of its operand. If a condition is
true then Logical NOT operator will make
false.
Bitwise Operators:
Bitwise operator works on bits and perform bit by bit operation.
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Show Examples
There are following Bitwise operators supported by C language
EBD_7203
S3-128 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
>> Binary Right Shift Operator. The left A >> 2 will give 15 which is
operands value is moved right by the 0000 1111
number of bits specified by the right
operand.
Assignment Operators:
There are following assignment operators supported by C language:
Co mm a , Left to rig ht
EBD_7203
S3-130 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
All above operators are similar to C++.
Operators Precedence in C++:
Operator precedence determines the grouping of terms in an expression. This affects
how an expression is evaluated. Certain operators have higher precedence than
others; for example, the multiplication operator has higher precedence than the
addition operator:
For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with
the lowest appear at the bottom. Within an expression, higher precedence operators
will be evaluated first.
Looping
Loops provide a way to repeat commands and control how many times they are
repeated. C provides a number of looping way.
while loop
The most basic loop in C is the while loop.A while statement is like a repeating if
statement. Like an If statement, if the test condition is true: the statments get
executed. The difference is that after the statements have been executed, the test
condition is checked again. If it is still true the statements get executed again.This
cycle repeats until the test condition evaluates to false.
Basic syntax of while loop is as follows:
while ( expression )
{
Single statement
or
Block of statements;
}
for loop
for loop is similar to while, it's just written differently. for statements are often used
to proccess lists such a range of numbers:
Basic syntax of for loop is as follows:
C++ programming language provides the following types of loop to handle looping
requirements.
{
float Miles;
Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage for
the number. On PCs this is likely to be 8 bytes.
{
double Atoms;
Atoms = 2500000;
}
char - data type
char defines characters.
{
char Letter;
Letter = 'x';
}
Modifiers
The data types explained above have the following modifiers.
• short
• long
• signed
• unsigned
The modifiers define the amount of storage allocated to the variable. The amount of
storage allocated is not cast in stone.
Qualifiers
A type qualifier is used to refine the declaration of a variable, a function, and
parameters, by specifying whether:
• The value of a variable can be changed.
• The value of a variable must always be read from memory rather than from
a register
Standard C language recognizes the following two qualifiers:
• const
• volatile
The const qualifier is used to tell C that the variable value can not change after
initialisation.
const float pi=3.14159;
Now pi cannot be changed at a later time within the program.
ARRAYS:
We have seen all basic data types. In C language it is possible to make arrays whose
elements are basic types. Thus we can make an array of 10 integers with the
declaration.
int x[10];
The square brackets mean subscripting; parentheses are used only for function
references. Array indexes begin at zero, so the elements of x are:
Thus Array are special type of variables which can be used to store multiple values
of same data type. Those values are stored and accessed using subscript or index.
Arrays occupy consecutive memory slots in the computer's memory.
x[0], x[1], x[2], ..., x[9]
If an array has n elements, the largest subscript is n-1.
Multiple-dimension arrays are provided. The declaration and use look like:
int name[10] [20];
n = name[i+j] [1] + name[k] [2];
PROGRAMMING AND DATA STRUCTURES S3-135
Subscripts can be arbitrary integer expressions. Multi-dimension arrays are stored by
row so the rightmost subscript varies fastest. In above example name has 10 rows and
20 columns.
Same way, arrays can be defined for any data type. Text is usually kept as an array
of characters. By convention in C, the last character in a character array should be
a `\0' because most programs that manipulate character arrays expect it. For example,
printf uses the `\0' to detect the end of a character array when printing it out with
a `%s'.
Array Initialization
• As with other declarations, array declarations can include an optional
initialization
• Scalar variables are initialized with a single value
• Arrays are initialized with a list of values
• The list is enclosed in curly braces
int array [8] = {2, 4, 6, 8, 10, 12, 14, 16};
The number of initializers cannot be more than the number of elements in the array
but it can be less in which case, the remaining elements are initialized to 0.if you like,
the array size can be inferred from the number of initializers by leaving the square
brackets empty so these are identical declarations:
int array1 [8] = {2, 4, 6, 8, 10, 12, 14, 16};
int array2 [] = {2, 4, 6, 8, 10, 12, 14, 16};
An array of characters ie string can be initialized as follows:
char string[10] = "Hello";
To declare an array in C or C++, the programmer specifies the type of the elements
and the number of elements required by an array as follows:
type arrayName [ arraySize ];
This is called a single-dimension array. The arraySize must be an integer constant
greater than zero and type can be any valid C++ data type. For example, to declare
a 10-element array called balance of type double, use this statement:
double balance[10];
Initializing Arrays
You can initialize array in C either one by one or using a single statement as follows:
double balance[5]={1000.0,2.0,3.4,17.0,50.0};
The number of values between braces { } can not be larger than the number of
elements that we declare for the array between square brackets [ ].
If you omit the size of the array, an array just big enough to hold the initialization
is created. Therefore, if you write:
double balance[]={1000.0,2.0,3.4,17.0,50.0};
You will create exactly the same array as you did in the previous example. Following
is an example to assign a single element of the array:
balance[4]=50.0;
The above statement assigns element number 5th in the array with a value of 50.0.
All arrays have 0 as the index of their first element which is also called base index
and last index of an array will be total size of the array minus 1. Following is the
pictorial representation of the same array we discussed above:
0 1 2 3 4
balance 1000.0 2.0 3.4 7.0 50.0
Accessing Array Elements
An element is accessed by indexing the array name. This is done by placing the index
of the element within square brackets after the name of the array. For example:
double salary = balance[9];
The above statement will take 10th element from the array and assign the value to
salary variable.
EBD_7203
S3-136 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Dynamic Memory Allocation:
It enables us to create data types and structures of any size and length to suit our
programs need within the program. We use dynamic memory allocation concept when
we don't know how in advance about memory requirement.
There are following functions to use for dynamic memory manipulation:
• void *calloc(size_t num elems, size_t elem_size) - Allocate an array and
initialise all elements to zero .
• void free(void *mem address) - Free a block of memory.
• void *malloc(size_t num bytes) - Allocate a block of memory.
• void *realloc(void *mem address, size_t newsize) - Reallocate (adjust size)
a block of memory.
Command Line Arguments:
It is possible to pass arguments to C programs when they are executed. The brackets
which follow main are used for this purpose. argc refers to the number of arguments
passed, and argv[] is a pointer array which points to each argument which is passed
to main.
#include <stdio.>h
main( int argc, char *argv[] )
{
if( argc == 2 )
printf("The argument supplied is %s\n", argv[1]);
else if( argc > 2 )
printf("Too many arguments supplied.\n");
else
printf("One argument expected.\n");
}
Note that *argv[0] is the name of the program invoked, which means that *argv[1]
is a pointer to the first argument supplied, and *argv[n] is the last argument. If no
arguments are supplied, argc will be one. Thus for n arguments, argc will be equal
to n + 1. The program is called by the command line:
$myprog argument1
More clearly, Suppose a program is compiled to an executable program myecho and
that the program is executed with the following command.
$myeprog aaa bbb ccc
When this command is executed, the command interpreter calls the main() function
of the myprog program with 4 passed as the argc argument and an array of 4 strings
as the argv argument.
argv[0] - "myprog"
argv[1] - "aaa"
argv[2] - "bbb"
argv[3] - "ccc"
Multidimensional Arrays:
The array we used in the last example was a one dimensional array. Arrays can have
more than one dimension, these arrays-of-arrays are called multidimensional arrays.
They are very similar to standard arrays with the exception that they have multiple
sets of square brackets after the array identifier. The above array has two dimensions
and can be called a doubly subscripted array.
ip++;
On a typical 32-bit machine, *ip would be pointing to 5 after initialization. But ip++;
increments the pointer 32-bits or 4-bytes. So whatever was in the next 4-bytes, *ip
would be pointing at it.
Pointer arithmetic is very useful when dealing with arrays, because arrays and
pointers share a special relationship in C.
return total;
}
A return keyword is used to return a value and datatype of the returned value is
specified before the name of function. In this case function returns total which is
int type. If a function does not return a value then void keyword can be used as
return value.
Once you have defined your function you can use it within a program:
main()
{
Demo();
}
Functions and Variables:
Each function behaves the same way as C language standard function main(). So
a function will have its own local variables defined. In the above example total
variable is local to the function Demo.
A global variable can be accessed in any function in similar way it is accessed in
main() function.
PROGRAMMING AND DATA STRUCTURES S3-139
Declaration and Definition
When a function is defined at any place in the program then it is called function
definition. At the time of definition of a function actual logic is implemented with-in
the function.
A function declaration does not have any body and they just have their interfaces.
A function declaration is usually declared at the top of a C source file, or in a separate
header file.
A function declaration is sometime called function prototype or function signature.
For the above Demo() function which returns an integer, and takes two parameters
a function declaration will be as follows:
int Demo( int par1, int par2);
Passing Parameters to a Function
There are two ways to pass parameters to a function:
• Pass by Value: mechanism is used when you don't want to change the
value of passed paramters. When parameters are passed by value then
functions in C create copies of the passed in variables and do required
processing on these copied variables.
• Pass by Reference : mechanism is used when you want a function to do
the changes in passed parameters and reflect those changes back to the
calling function. In this case only addresses of the variables are passed to
a function so that function can work directly over the addresses.
By default, C++ uses call by value to pass arguments.
While calling a function, there are two ways that arguments can be passed to a
function:
Call Type Description
Call by value This method copies the actual value of an
argument into the formal parameter of the function.
In this case, changes made to the parameter inside
the function have no effect on the argument.
Call by pointer This method copies the address of an argument
into the formal parameter. Inside the function, the
address is used to access the actual argument
used in the call. This means that changes made to
the parameter affect the argument.
Call by reference This method copies the reference of an argument
into the formal parameter. Inside the function, the
reference is used to access the actual argument
used in the call. This means that changes made to
the parameter affect the argument.
Here are two programs to understand the difference: First example is for Pass by
value:
#include <stdio.h>
int main()
{
int a = 10;
int b = 20;
t = p2;
p2 = p1;
p1 = t;
printf("Value of a (p1) = %d and value of b(p2) = %d\n", p1, p2 );
}
Here is the result produced by the above example. Here the values of a and b remain
unchanged before calling swap function and after calling swap function.
Before: Value of a = 10 and value of b = 20
Value of a (p1) = 20 and value of b(p2) = 10
After: Value of a = 10 and value of b = 20
Following is the example which demonstrate the concept of pass by reference
#include <stdio.h>
/* function declaration goes here.*/
void swap( int *p1, int *p2 );
int main()
{
int a = 10;
int b = 20;
t = *p2;
*p2 = *p1;
*p1 = t;
printf("Value of a (p1) = %d and value of b(p2) = %d\n", *p1, *p2 );
}
Here is the result produced by the above example. Here the values of a and b are
changes after calling swap function.
Before: Value of a = 10 and value of b = 20
Value of a (p1) = 20 and value of b(p2) = 10
After: Value of a = 20 and value of b = 10
Recursion
What is recursion? The simple answer is, it's when a function calls itself. But how
does this happen? Why would this happen, and what are its uses?
When we talk about recursion, we are really talking about creating a loop. Let's start
by looking at a basic loop.
1 for(int i=0; i<10; i++) {
2 cout << "The number is: " << i << endl;
3}
For those who don't yet know, this basic loop displays the sentence, "The number
is: " followed by the value of 'i'. Like this.
PROGRAMMING AND DATA STRUCTURES S3-141
The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
STRINGS
• In C language Strings are defined as an array of characters or a pointer to
a portion of memory containing ASCII characters. A string in C is a sequence of zero
or more characters followed by a NULL '\0' character:
• It is important to preserve the NULL terminating character as it is how C
defines and manages variable length strings. All the C standard library functions
require this for successful operation.
• All the string handling functions are prototyped in: string.h or stdio.h
standard header file. So while using any string related function, don't forget to include
either stdio.h or string.h. May be your compiler differes so please check before going
ahead.
• If you were to have an array of characters WITHOUT the null character
as the last element, you'd have an ordinary character array, rather than a string
constant.
• String constants have double quote marks around them, and can be
assigned to char pointers as shown below. Alternatively, you can assign a string
constant to a char array - either with no size specified, or you can specify a size, but
don't forget to leave a space for the null character!
char *string_1 = "Hello";
char string_2[] = "Hello";
char string_3[6] = "Hello";
int main() {
char array1[50];
char *array2;
return 0;
}
This will produce following result:
Now enter another string less than 50 characters with spaces:
hello world
C - Structured Datatypes
or an array of students as
struct student students[50];
Another way to declare the same thing is:
struct {
char firstName[20];
char lastName[20];
char SSN[10];
float gpa;
} student_a, student_b;
All the variables inside an structure will be accessed using these values as
student_a.firstName will give value of firstName variable. Similarly we can aqccess
other variables.
Pointers to Structs:
Sometimes it is useful to assign pointers to structures (this will be evident in the next
section with self-referential structures). Declaring pointers to structures is basically
the same as declaring a normal pointer:
struct student *student_a;
To dereference, you can use the infix operator: ->.
printf("%s\n", student_a->SSN);
typedef Keyword
There is an easier way to define structs or you could "alias" types you create. For
example:
typedef struct{
char firstName[20];
char lastName[20];
char SSN[10];
float gpa;
}student;
Now you can use student directly to define variables of student type without using
struct keyword. Following is the example:
student student_a;
You can use typedef for non-structs:
typedef long int *pint32;
pint32 x, y, z;
x, y and z are all pointers to long ints
Unions Datatype
Unions are declared in the same fashion as structs, but have a fundamental difference.
Only one item within the union can be used at any time, because the memory allocated
for each item inside the union is in a shared memory location.
Here is how we define a Union
EBD_7203
S3-144 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
union Shape {
int circle;
int triangle;
int ovel;
};
We use union in such case where only one condition will be applied and only one
variable will be used.
C - Working with Files
When accessing files through C, the first necessity is to have a way to access the
files. For C File I/O you need to use a FILE pointer, which will let the program keep
track of the file being accessed. For Example:
FILE *fp;
To open a file you need to use the fopen function, which returns a FILE pointer. Once
you've opened a file, you can use the FILE pointer to let the compiler perform input
and output functions on the file.
FILE *fopen(const char *filename, const char *mode);
Here filename is string literal which you will use to name your file and mode can have
one of the following values
w - open for writing (file need not exist)
a - open for appending (file need not exist)
r+ - open for reading and writing, start at beginning
w+ - open for reading and writing (overwrite file)
a+ - open for reading and writing (append if file exists)
Note that it's possible for fopen to fail even if your program is perfectly correct: you
might try to open a file specified by the user, and that file might not exist (or it might
be write-protected). In those cases, fopen will return 0, the NULL pointer.
Here's a simple example of using fopen:
FILE *fp;
fp=fopen("/home/tutorialspoint/test.txt", "r");
This code will open test.txt for reading in text mode. To open a file in a binary mode
you must add a b to the end of the mode string; for example, "rb" (for the reading
and writing modes, you can add the b either after the plus sign - "r+b" - or before
- "rb+")
To close a function you can use the function:
int fclose(FILE *a_file);
fclose returns zero if the file is closed successfully.
An example of fclose is:
fclose(fp);
To work with text input and output, you use fprintf and fscanf, both of which are
similar to their friends printf and scanf except that you must pass the FILE pointer
as first argument.
Try out following example:
#include <stdio.h>
main()
{
FILE *fp;
fp = fopen("/tmp/test.txt", "w");
fprintf(fp, "This is testing...\n");
fclose(fp;);
}
This will create a file test.txt in /tmp directory and will write This is testing in that
file.
PROGRAMMING AND DATA STRUCTURES S3-145
Here is an example which will be used to read lines from a file:
#include <stdio.h>
main()
{
FILE *fp;
char buffer[20];
fp = fopen("/tmp/test.txt", "r");
fscanf(fp, "%s", buffer);
printf("Read Buffer: %s\n", %buffer );
fclose(fp;);
}
It is also possible to read (or write) a single character at a time--this can be useful
if you wish to perform character-by-character input. The fgetc function, which takes
a file pointer, and returns an int, will let you read a single character from a file:
int fgetc (FILE *fp);
The fgetc returns an int. What this actually means is that when it reads a normal
character in the file, it will return a value suitable for storing in an unsigned char
(basically, a number in the range 0 to 255). On the other hand, when you're at the very
end of the file, you can't get a character value--in this case, fgetc will return "EOF",
which is a constnat that indicates that you've reached the end of the file.
The fputc function allows you to write a character at a time--you might find this useful
if you wanted to copy a file character by character. It looks like this:
int fputc( int c, FILE *fp );
Note that the first argument should be in the range of an unsigned char so that it
is a valid character. The second argument is the file to write to. On success, fputc
will return the value c, and on failure, it will return EOF.
Binary I/O
There are following two functions which will be used for binary input and output:
size_t fread(void *ptr, size_t size_of_elements,
size_t number_of_elements, FILE *a_file);
Now, if we talk in terms of C++ Programming, C++ classes provides great level
of data abstraction. They provide sufficient public methods to the outside world to
play with the functionality of the object and to manipulate object data, i.e., state
without actually knowing how class has been implemented internally.
In C++, we use classes to define our own abstract data types (ADT). You can use
the cout object of class ostream to stream data to standard output like this:
#include<iostream>
usingnamespace std;
int main()
{
cout <<"Hello C++"<<endl;
return0;
}
Here, you don't need to understand how cout displays the text on the user's screen.
You need to only know the public interface and the underlying implementation of cout
is free to change.
Access Labels Enforce Abstraction:
In C++, we use access labels to define the abstract interface to the class. A class may
contain zero or more access labels:
• Members defined with a public label are accessible to all parts of the
program. The data-abstraction view of a type is defined by its public
members.
• Members defined with a private label are not accessible to code that uses
the class. The private sections hide the implementation from code that uses
the type.
There are no restrictions on how often an access label may appear. Each access label
specifies the access level of the succeeding member definitions. The specified access
level remains in effect until the next access label is encountered or the closing right
brace of the class body is seen.
Benefits of Data Abstraction:
Data abstraction provides two important advantages:
• Class internals are protected from inadvertent user-level errors, which might
corrupt the state of the object.
• The class implementation may evolve over time in response to changing
requirements or bug reports without requiring change in user-level code.
By defining data members only in the private section of the class, the class author
is free to make changes in the data. If the implementation changes, only the class code
needs to be examined to see what affect the change may have. If data are public, then
any function that directly accesses the data members of the old representation might
be broken.
Designing Strategy:
Abstraction separates code into interface and implementation. So while designing
your component, you must keep interface independent of the implementation so that
if you change underlying implementation then interface would remain intact.
In this case whatever programs are using these interfaces, they would not be
impacted and would just need a recompilation with the latest implementation
PROGRAMMING AND DATA STRUCTURES S3-147
OOPS
Introduction
The object-oriented programming (OOP) is a different approach to programming.
Object oriented technology supported by C++ is considered the latest technology
in software development. It is regarded as the ultimate paradigm for the modelling
of information, be that data or logic.
Objectives
After going through this lesson, you would be able to:
l learn the basic concepts used in OOP
l describe the various benefits provided by OOP
l explain the programming applications of OOP.
Object-Oriented Programming
The object-oriented programming is a different approach to programming. It has been
created with a view to increase programmer's productivity by overcoming the
weaknesses found in procedural programming approach. Over the years many object-
oriented programming languages such as C++ and smalltalk have come up and are
becoming quite popular in the market. The major need for developing such languages
was to manage the ever-increasing size and complexity of programs.
Basic Concepts
The following are the basic concepts used in object-oriented programming.
l Objects
l Classes
l Data abstraction
l Modularity
l Inheritance
l Polymorphism
Objects
It can represent a person, a bank account or any item that a program can handle.
When a program is executed, the objects interact by sending messages to one
another. For example, if 'customer' and 'account' are two objects in a program, then
the customer object may send message to account object requesting for a bank
balance. Each object contains data and code to manipulate data. Objects can interact
without having to know details of each other's data or code. It is sufficient to know
the type of massage accepted and the type of response returned by the objects.
Classes
We have just mentioned that objects contain data and function or code to manipulate
that data. The entire set of data and code of 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 been defined, we can create any number of objects associated 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 fruit mango, will create an object mango
belonging to the class fruit.
Data Abstraction
Abstraction refers to the act of representing essential features without including the
background details. To understand this concept more clearly, take an example of
'switch board'. You only press particular switches as per your requirement. You need
not know the internal working of these switches. What is happening inside is hidden
from you. This is abstraction, where you only know the essential things to operate
on switch board without knowing the background details of switch board.
Data Encapsulation
Encapsulation is the most basic concept of OOP. It is the way of combining both
data and the functions that operate on that data under a single unit. The only way
to access the data is provided by the functions (that are combined along with the
data). These functions are considered as member functions in C++. It is not possible
EBD_7203
S3-148 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
to access the data directly. If you want to reach the data item in an object, you call
a member function in the object. It will 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. Data and its functions are said to be encapsulated into a single entity.
Modularity
The act of partitioning a program into individual components is called modularity. It
gives the following benefits.
l It reduces its complexity to some extent.
l It creates a number of well-defined, documented boundaries within the program.
Module is a separate unit in itself. It can be compiled independently though it has
links with other modules. Modules work quite closely in order to achieve the
program's goal.
Inheritance
It is the capability to define a new class in terms of an existing class. An existing
class is known as a base class and the new class is known as derived class. Number
of examples can be given on this aspect. For example, a motor cycle is a class in itself.
It is also a member of two wheelers class. Two wheelers class in turn is a member
of automotive class as shown in Fig. 8.1. The automotive is an example of base class
and two wheelers is its derived class. In simple words, we can say a motor cycle is
a two wheeler automotive.
C++ supports such hierarchical classification of classes. The main benefit from
inheritance is that we can build a generic base class, i.e., obtain a new class by adding
some new features to an existing class and so on. Every new class defined in that
way consists of features of both the classes. Inheritance allows existing classes to
be adapted to new application without the need for modification.
Polymorphism
Polymorphism is a key to the power of OOP. It is the concept that supports the
capability of data to be processed in more than one form. For example, an operation
may exhibit different behaviour in different instances. The behaviour depends upon
the types of data used in the operation. Let us consider the operation of addition.
For two numbers, the operation will generate a sum. If the operands are strings then
the operation would produce a third string by concatenation.
Fig.
PROGRAMMING AND DATA STRUCTURES S3-149
Benefits of OOP
OOP provides lot of benefits to both the program designer and the user.
Objectoriented approach helps in solving many problems related to software
development and quality of software product. The new technology assures greater
programmer productivity, better quality of software and lesser maintenance cost. The
major benefits are :
l Software complexity can be easily managed
l Object-oriented systems can be easily upgraded
l It is quite easy to partition the work in a project based on objects.
Programming Applications of OOP
OOP has become one of the programming buzzwords today. There appears to be a
great deal of excitement and interest among software programmers in using OOP.
Applications of OOP are gaining importance in many areas. OOP has been extensively
used in the development of windows and word based systems such as MS-Windows,
x-Windows etc. The promising application areas of OOP are:
(i) Multiple data structure: This is an application where the same data structure is
used many times. For example a window data structure is used multiple-times in a
windowing system.
(ii) Data in multiple programs: This is an application where the same operations are
performed on a data structure in different programs. For example, record validation in
an accounting system.
The other application areas of OOP are parallel programming, simulation and
modelling, AI and Expert systems, Neural Networks and CAD systems.
Linked Lists
A linked list contains a list of data .The Data can be anything: number, character,
array,structure, etc.Each element of the list must also link with the next element
therefore, a structure containing data and link is created.
The link is a pointer to the same type of structure
struct Node
{
int data ;
struct Node *next ;
};
This is called a self-referential pointer
1 Insertion
2 Deletion
3 Searching
n = malloc(sizeof(node));
n->data = val;
n->next = NULL;
return n;
}
Insertion at the beginning of the list
Create a new node (say q)
Make q->next point to head
Make head equal to q
list is empty, i.e., head is NULL
Make head equal to q
Delete after p
Call the next node, i.e., p->next as q
Make p->next equal to q->next
Delete q
Linked List: element definition and creation
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int data; // data of a node: list is made of these elements
struct Node *next; // link to the next node
} node;
node *create_node(int val)
{
node *n;
n = malloc(sizeof(node));
n->data = val;
n->next = NULL;
return n;
}
Displaying the data in the linked list
void print_list(node *h)
{ /*Display data in each element of the linked list*/
node *p;
p = h;
while (p != NULL)
{
printf("%d --> ", p->data);
p = p->next;
}
}
Inserting at end
int main()
{
EBD_7203
S3-152 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
node *head = NULL; // head maintains the entry to the list
node *p = NULL, *q = NULL;
int v = -1, a;
printf("Inserting at end: Enter the data value:\n");
scanf("%d", &v);
while (v != -1)
{
q = create node(v);
q->next = NULL;
free (P);
}
Print_list(head);/*Display the data in the list */
printf("Deleting after\n");
scanf("%d", &a);
p = head;
while ((p != NULL) && (p->data != a))
p = p->next;
if (p != NULL)
{
q = p->next;
if (q != NULL)
{
p->next = q->next;
free(q);
}
}
print_list(head); /*Display the data in the list*/
}
STACKS
A stack is simply a list of elements with insertions and deletions permitted at one
endcalled
the stack top. That means that it is possible to remove elements from a stack
in reverse order from the insertion of elements into the stack. Thus, a stack data
structure exhibits the LIFO (last in first out) property. Push and pop are the operations
that are provided for insertion of an element into the stack and the removal of an
element from the stack, respectively.
EBD_7203
S3-154 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Operations on stack:
The insertion of elements into stack is called PUSH operation.
The deletion of elements from stack is called POP operation.
POP operation:
Following actions taken place in POP:
Check the stack empty or not.
Remove the top element from the stack.
Return this element to the calling function or program.
Stack Push
stack top/head has the address of the first element
Function needs the address to the stack top/head to make changes to head
void push(node **head_address, int top)
{
node *q;
q = create_node(top); /*New element storing the new data*/
q->next = *head address; /*New element pointing to head*/
q >head_/ head /
*head_address = q; /*head pointing to new element*/
return;
}
Stack Pop
A queue is a container of objects (a linear collection) that are inserted and removed
according to the first-in first-out (FIFO) principle. An excellent example of a queue is
a line of students in the food court of the UC. New additions to a line made to the
back of the queue, while removal (or serving) happens in the front. In the queue only
two operations are allowed enqueue and dequeue. Enqueue means to insert an item
into the back of the queue, dequeue means removing the front item. The picture
demonstrates the FIFO access.
The difference between stacks and queues is in removing. In a stack we remove the
item the most recently added; in a queue, we remove the itemthe least recently added.
PROGRAMMING AND DATA STRUCTURES S3-155
Implementation
In the standard library of classes, the data type queue is an adapter class, meaning
that a queue is built on top of other data structures. The underlying structure for a
queue could be an array, a Vector, an ArrayList, a LinkedList, or any other collection.
Regardless of the type
of the underlying data structure, a queue must implement the same functionality. This
is achieved by providing a unique interface.
interface QueueInterface‹AnyType>
{
public boolean isEmpty();
public AnyType getFront();
public AnyType dequeue();
public void enqueue(AnyType e);
public void clear();
}
Each of the above basic operations must run at constant time O(1). The following
picture demonstrates the idea of implementation by composition.
Circular Queue
Given an array A of a default size (? 1) with two references back and front, originally
set to -1 and 0 respectively. Each time we insert (enqueue) a new item, we increase
the back index; when we remove (dequeue) an item - we increase the front index. Here
is a picture that illustrates the model after a few steps: 0 1 2 3 4 5
As you see from the picture, the queue logically moves in the array from left to right.
After several moves back reaches the end, leaving no space for adding new elements
However, there is a free space before the front index. We shall use that space for
enqueueing new items, i.e. the next entry will be stored at index 0, then 1, until front. front back
Such a model is called a wrap around queue or a circular queue 0 1 2 3 4 5
Finally, when back reaches front, the queue is full. There are two choices to handle
a full queue:a) throw an exception; b) double the array size.
The circular queue implementation is done by using the modulo operator (denoted
front back
%), which is computed by taking the remainder of division (for example, 8%5 is 3).
By using the modulo operator, we can view the queue as a circular array, where the
"wrapped around" can be simulated as "back % array_size". In addition to the back
and front indexes, we maintain another index: cur - for counting the number of
elements in a queue. Having this index simplifies a logic of implementation. back front
APPLICATIONS
The simplest two search techniques are known as Depth-First Search(DFS) and
Breadth-First Search (BFS). These two searches are described by looking at how the
search tree (representing all the possible paths from the start) will be traversed.
Deapth-First Search with a Stack
In depth-first search we go down a path until we get to a dead end; then we backtrack
or back up (by popping a stack) to get an alternative path.
Create a stack
Create a new choice point
Push the choice point onto the stack
• Pop the stack
• Find all possible choices after the last one tried
• Push these choices onto the stack
Return
Breadth-First Search with a Queue
In breadth-first search we explore all the nearest possibilities by finding all possible
successors and enqueue them to a queue.
Create a queue
Create a new choice point
Enqueue the choice point onto the queue
while (not found and queue is not empty)
EBD_7203
S3-156 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
• Dequeue the queue
• Find all possible choices after the last one tried
• Enqueue these choices onto the queue
Return
Queues
Queue operations are also called First-in first-out Operations
Enqueue: insert at the end of queue
Dequeue: delete from the beginning of queue
Code: similar to previous code on linked lists
Queue Application: Executing processes by operating system
Operating System puts new processes at the end of a queue.System executes
processes at the beginning of the queue
Circular Lists
The last element of a linked list points to the first element.
A reference pointer is required to access the list: head
Circular Lists
The list pointer can have the address of the last element.The tail/last element can be
accessed by the list pointer.The head/first element can be accessed from the tail/
lastelement (by list->next)
Provides flexibility in accessing first and last elements
Circular lists can be used for queues.
Useful in enqueue/dequeue operations without needing to
traverse the list.
Implementation
We implement a binary search tree using a private inner class BSTNode. In order to
support the binary search tree property, we require that data stored in each node is
Comparable:
public class BST <AnyType extends Comparable<AnyType>>
{
private Node<AnyType> root;
3
Insertion
9
The insertion procedure is quite similar to searching. We start at the root and
recursively go down the tree searching for a location in a BST to insert a new node.
1 5 12
If the element to be inserted is already in the tree, we are done (we do not insert
duplicates). The new node will always replace a NULL reference.
4 11 Example: Given a sequence of numbers:
before insertion 11, 6, 8, 19, 4, 10, 5, 17, 43, 49, 31
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 7 11
5 10 31 49
after insertion
PROGRAMMING AND DATA STRUCTURES S3-161
Searching
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 to Search). If the node does not
contain the key we proceed either to the left or right child depending upon
comparison. If the result of comparison is negative we go to the left child, otherwise
- to the right child. The recursive structure of a BST yields a recursive algorithm.
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;
is a leaf;
has only one child;
has two children.
If to Delete is not in the tree, there is nothing to delete. If to Delete node has only
one child the procedure of deletion is identical to deleting a node from a linked list
- we just bypass that node being deleted
8 8
3 9 3 12
1 5 12 1 5 11
4 11 4
Deletion of an internal node with two children is less straightforward. If we delete such
a node, we split a tree into two subtrees and therefore, some children of the internal
node won’t be accessible after deletion. In the picture below we delete 8:
8 5
3 swap data 9 3 9
1 5 12 1 4 12
4 11 11
before deletion after deletion
Deletion starategy is the following: replace the node being deleted with the largest
node in the left subtree and then delete that largest node. By symmetry, the node
being deleted can be swapped with the smallest node is the right subtree.
Non-Recursive Traversals
Depth-first traversals can be easily implemented recursively.A non-recursive
implementation is a bit more difficult. In this section we implement a pre-order traversal
as a tree iterator
EBD_7203
S3-162 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
public Iterator<AnyType> iterator()
{
return new PreOrderIterator();
}
Example where the PreOrderIterator class is implemented as an inner private class of the BST
public AnyType next() class
{ private class PreOrderIterator implements Iterator<AnyType>
Node cur = stk.peek(); {
if(cur.left != null) ...
{ }
stk.push(cur.left); The main difficulty is with next() method, which requires the implicit recursive stack
} implemented explicitly. We will be using Java’s Stack. The algorithm starts with the root
else and push it on a stack. When a user calls for the next() method, we check if the top
{ element has a left child. If it has a left child, we push that child on a stack and return
Node tmp = stk.pop(); a parent node. If there is no a left child, we check for a right child. If it has a right child,
while(tmp.right == null) we push that child on a stack and return a parent node. If there is no right child, we
{ move back up the tree (by popping up elements from a stack) until we find a node with
if (stk.isEmpty()) return cur.data; a right child. Here is the next() implementation as shown in example
tmp = stk.pop(); This example showed the output and the state of the stack during each call to next().
} Note, the algorithm works on any binary trees, not necessarily binary search trees..
stk.push(tmp.right);
} Output 1 2 4 6 5 7 8 3
return cur.data;
6
} 4 7
2 4 5 8
Stack 1 2 5 3
1 2 1 1
1 1
1
1
S P
G R O N
A E C A I
This has violated the condition that the root must be greater than each of its children.
So interchange the M with the larger of its children.
M P
G R O N
A E C A I
EBD_7203
S3-164 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The left subtree has now lost the heap property.
So again interchange the M with the larger of its children.
R P
G M O N
A E C A I
11
5 8
3 4 X
and we want to add the number 15 to the heap. We first place the 15 in the position
marked by the X. However, the heap property is violated since 15 is greater than 8,
so we need to swap the 15 and the 8. So, we have the heap looking as follows after
the first swap:
11
15
5 15
5 11
3 4 8
3 4 8 However the heap property is still violated since 15 is greater than 11, so we need
to swap again:
PROGRAMMING AND DATA STRUCTURES S3-165
which is a valid max-heap. There is no need to check the children after this. Before
we placed 15 on X, the heap was valid, meaning 11 is greater than 5. If 15 is greater
than 11, and 11 is greater than 5, then 15 must be greater than 5, because of
the transitive relation.
Delete :
The procedure for deleting the root from the heap (effectively extracting the maximum
element in a max-heap or the minimum element in a min-heap) and restoring the
properties is called down-heap (also known as bubble-down, percolate-down, sift-
down, trickle down, heapify-down, cascade-down and extract-min/max).
1. Replace the root of the heap with the last element on the last level.
2. Compare the new root with its children; if they are in the correct order, stop.
3. If not, swap the element with one of its children and return to the previous step.
(Swap with its smaller child in a min-heap and its larger child in a max-heap.)
So, if we have the same max-heap as before
11
5 8
3 4
5 8
Now the heap property is violated since 8 is greater than 4. In this case, swapping
the two elements, 4 and 8, is enough to restore the heap property and we need not
swap elements further:
5 4
The downward-moving node is swapped with the larger of its children in a max-heap
(in a min-heap it would be swapped with its smaller child), until it satisfies the heap
property in its new position. This functionality is achieved by the Max-Heapify function
as defined below in pseudo code for an array-backed heap A of length heap_length[A].
Note that “A” is indexed starting at 1, not 0 as is common in many real programming
languages.
EBD_7203
S3-166 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Max-Heapify (A, i):
left ¬ 2i
right ¬ 2i + 1
largest ¬ i
if left £ heap_length[A] and A[left] > A[largest] then:
largest ¬ left
if right £ heap_length[A] and A[right] > A[largest] then:
largest ¬ right
if largest ¹ i then:
swap A[i] « A[largest]
Max-Heapify(A, largest)
For the above algorithm to correctly re-heapify the array, the node at index i and its
two direct children must violate the heap property. If they do not, the algorithm will
fall through with no change to the array. The down-heap operation (without the
preceding swap) can also be used to modify the value of the root, even when an
element is not being deleted.
In the worst case, the new root has to be swapped with its child on each level until
it reaches the bottom level of the heap, meaning that the delete operation has a time
complexity relative to the height of the tree, or O(log n).
Building a heap :
A heap could be built by successive insertions. This approach requires O(n log n)
time because each insertion takes O(log n) time and there are n elements. However
this is not the optimal method. The optimal method starts by arbitrarily putting the
elements on a binary tree, respecting the shape property (the tree could be
represented by an array, see below). Then starting from the lowest level and moving
upwards, shift the root of each subtree downward as in the deletion algorithm until
the heap property is restored. More specifically if all the subtrees starting at some
height h (measured from the bottom) have already been “heapified”, the trees at
height h + 1 can be heapified by sending their root down along the path of maximum
valued children when building a max-heap, or minimum valued children when building
a min-heap. This process takes O(h) operations (swaps) per node. In this method
most of the heapification takes place in the lower levels. Since the height of the heap
is [lg(n)], the number of nodes at height is h.
é 2 lg n ù é n ù
£ [2(lg n - h) -1 ] = ê ú=ê ú
êë 2h +1 úû ë 2h +1 û
æ ¥ h ö
£ Oçnå ÷÷
ç h
è h=0 2 ø
= O(n)
This uses the fact that the given infinite series h / 2h converges to 2.
The exact value of the above (the worst-case number of comparisons during the heap
construction) is known to be equal to:
2n – 2s2(n) – e2(n),
where s2(n) is the sum of all digits of the binary representation of n and e2(n) is the
exponent of 2 in the prime factorization of n.
PROGRAMMING AND DATA STRUCTURES S3-167
1. Assume that the operators +, –, ×, are left associative and ^ print f(“%s”, p);
is right associative. The order of precedence (from highest The output of the program is
to lowest) is ^, ×, +, –. The postfix expression corresponding (a) gnirts (b) string
to the infix expression a + b × c – d ^ e ^ f is [2005, 2 marks] (c) gnirt (d) no output is printed
(a) abc × + def ^^ – (b) abc × + de^f^– 5. Consider the following C function: [2005, 2 marks]
(c) ab + c × d – e^f^ (d) – + a × bc ^^ def int f (int n)
2. The elements 32, 15, 20, 30, 12, 25, 16, are inserted one by one
{ static int i = 1;
in the given order into a max-heap. The resultant max-heap is
if (n > = 5) return n;
[2005, 2 marks]
n = n + 1;
32 32 i ++;
return f(n);
(a) 30 25 (b) 25 30
}
12 15 20 The value returned by f(1) is
15 12 20 16 16
(a) 5 (b) 6
32 32 (c) 7 (d) 8
6. Postorder traversal of a given binary search tree, T produces
(c) 30 25 (d) 25 30 the following sequence of keys
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
15 12 16 20 12 15 16 20 Which one of the following sequences of keys can be the
3. A circularly linked list is used to represent a queue. A single result of an in-order traversal of the tree T? [2005, 2 marks]
variable p is used to access the queue. To which node should (a) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
p point such that both the operations en-queue and de-queue (b) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
can be performed in constant time? [2005, 2 marks] (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
7. Consider the following C-program [2005, 2 marks]
double foo (double); /* Line 1 */
1. Which of the following comments are not true? 8. int i = 5; is a statement in a C program. Which of the following
1. C provides no input-output features are true?
2. C provides no file access features (a) During execution, value of i may change but not its
3. C borrowed most of its ideas from BCPL address
4. C provides no features to manipulate composite objects (b) During execution both the address and value may
(a) 1 only (b) 1, 2 and 3 change
(c) 1, 2, 3 and 4 (d) None of these (c) Repeated execution may result in different addresses
2. Any C program
for i
(a) must contain at least one function
(d) i may not have an associated address
(b) need not contain any function
9. The declaration
(c) needs input data
enum cities {bethlethem, jericho, nazareth = 1, jerusalem}
(d) None of the above
3. Preprocessing is typically done assign the value 1 to
(a) either before or at the beginning of the compilation (a) bethlehem (b) nazareth
process (c) bethlehem and nazareth (d) jericho and nazareth
(b) after compilation but before execution 10. The value of an automatic variable that is declared but not
(c) after loading initialized will be
(d) None of these (a) 0 (b) – 1
4. The purpose of the following program fragment. (c) unpredictable (d) None of these
b = s + b; 11. The following program fragment
s = b – s; int a = 4, b = 6;
b = b – s; printf (“%d”, a = = b);
where s, be are two integers is to (a) outputs an error message (b) prints 0
(a) transfer the contents of s to b (c) prints 1 (d) none of the above
(b) transfer the contents of b to s 12. x – = y + 1; means
(c) exchange (swap) the contents of s and b (a) x = x – y + 1 (b) x = – x – y – 1
(d) negate the contents of s and b
(c) x = – x + y + 1 (d) x = x – y – 1
5. Which of the following about conditional compilation is
13. The following program fragment
not true?
int x[ 5 ] [ 5 ], i, j;
1. It is taken care of by the compiler
2. It is setting the compiler option conditionally. for (i = 0; i < 5; ++i)
3. It is compiling a program based on a condition. for (j = 0; j < 5, j++)
4. It is taken care of by the pre-processor. x[i][j] = x[j][i];
(a) 2 only (b) 3 and 4 only (a) transposes the given matrix x
(c) 1 and 2 (d) All of the above (b) makes the given matrix x, symmetric
6. Lengths of the string “correct” and “correct string” are (c) doesn’t alter the matrix x
(a) 7, 14 (d) None of these
(b) 8, 14 14. Consider the statement
(c) 6, 13 int val [2][4] = {1, 2, 3, 4, 5, 6, 7, 8};
(d) implementation dependant 4 will be the value of when array declaration in the row-
7. For C preprocessor, which of the following is/are true? major order.
1. Takes care of conditional compilation (a) val [1] [4] (b) val [0] [4]
2. Takes care of macros (c) val [1] [1] (d) None of the above
3. Takes care of includes files 15. The maximum number of dimension an array can have in C is
4. Acts before compilation
(a) 3 (b) 4
(a) 1 and 2 (b) 3 only
(c) 5 (d) None of the above
(c) 1, 2 and 3 (d) All of the above
EBD_7203
S3-178 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
16. Consider the array definition (a) max (max (a, b), max (a, c))
int num [10] = {3, 3, 3}; (b) max (a, max (a, c))
Pick the correct answers. (c) max (max (a, b), max (b, c))
(a) num [9] is the last element of the array num (d) max (b, max (a, c))
(b) the value of num [8] is 3 25. void can be used
(c) the value of num [3] is 3 (a) as data-type of a function that returns nothing to its
(d) None of the above calling environment
17. Consider the following type definition. (b) inside the brackets of a function that does not need
typedef char x [10]; any argument
x myArray [5]; (c) in an expression and in a printf statement
What will size of (myArray) be? (Assume one character (d) both (a) and (b)
occupies 1 byte) 26. The following program,
(a) 15 bytes (b) 10 bytes main ()
(c) 50 bytes (d) 30 bytes {
18. If n has the value 3, then the statement a[++n] = n++; int i = 2;
(a) assigns 3 to a [5] { int i = 4, j = 5;
(b) assigns 4 to a [5] printf (“%d%d”, i, j);
(c) assigns 4 to a [4] }
(d) what is assigned is compiler-dependent printf (“%d%d”, i, j);
19. If a global variable is of storage class static, then }
(a) the static declaration is unnecessary if the entire source (a) will not compile successfully
code is in a single file (b) prints 4525
(b) the variable is recognized only in the file in which it (c) prints 25 25
defined (d) None of the above
(c) it results in a syntax error 27. The following program,
(d) both (a) and (b) main ()
20. The default parameter passing mechanism is {
(a) call by value (b) call by reference inc (); inc (); inc ();
(c) call by value result (d) none of these }
21. The storage class static can be used to inc()
(a) restrict the scope of an external identifier {
(b) preserve the exit value of variables static int x;
(c) provide privacy to a set of functions printf (“%d”, ++x);
(d) All of the above }
22. The following program (a) prints 012
main () (b) prints 123
{printf (“tim”); (c) prints 3 consecutive, but unpredictable numbers
main ();} (d) prints 111
(a) is illegal (b) keeps on printing tim 28. main ()
(c) prints tim once (d) None of the above {int a = 5, b = 2;
23. Consider the following program print f (“%d”, a +++b);
main () }
{putchar (‘M’); (a) results in syntax error
first (); (b) prints 7
putchar (‘m’);} (c) prints 8
first () (d) None of these
{ _________ } 29. The program fragment
second () int a = 5, b = 2;
{putchar (‘d’);} printf (“%d”, a +++++b);
If Madam is the required output, then the body of first () (a) prints 7 (b) prints 8
must be (c) prints 9 (d) none of these
(a) empty
30. If arr is a two dimensional array of 10 rows and 12 columns,
(b) second (); putchar (‘a’);
then arr [5] logically points to the
(c) putchar (‘a’); second (); printf(“%C”, ‘a’);
(a) sixth row (b) fifth row
(d) none of the above
(c) fifth column (d) sixth column
24. Max is a function that returns the larger of the two integers,
given as arguments. Which of the following statements does
not finds the largest of three given numbers?
PROGRAMMING AND DATA STRUCTURES S3-179
31. The statements 39. a ® b is syntactically correct if
int**a; (a) a and b are structures
(a) is illegal (b) a is a structure and b is a pointer to a structure
(b) is legal but meaningless (c) a is a pointer to a structure and b is a structure
(c) is syntactically and semantically correct (d) a is a pointer to a structure is which b is a field
(d) none of these 40. If a file is opened in r+ mode then
32. Consider the following declaration, 1. reading is possible
int a, * b = &a, **c = & b; 2. writing is possible
the following program fragment 3. it will be created if it does not exist
a = 4; (a) 1 is true (b) 1 and 3 are true
**c = 5 ; (c) 1 and 2 are true (d) 1, 2 and 3 are true
(a) does not change the value of a 41. The contents of a file will be lost if it is opened in
(b) assigns address of c to a (a) a mode (b) w mode and w + mode
(c) assigns the value of b to a (c) r + mode (d) a + mode
(d) assigns 5 to a 42. Bit field
33. Let x be an array. Which of the following operations are (a) is a field having many sub-fields
illegal? (b) is a structure declaring the sizes of the members in
1. + + x 2. x + 1 terms of bits
3. x + + 4. x * 2 (c) is a member of a structure whose size is specified in
(a) 1 only (b) 3 and 4 terms of bits
(c) 2, 3 and 4 (d) 1, 3 and 4 (d) none of these
34. Pick the correct answers. 43. The statement printf (“%d”, size of (“”)); prints
If x is an one dimensional array, then (a) an error message (b) 0
(a) &x[i] is same as x + i – 1 (c) garbage (d) 1
(b) * (x + i) is same as * (&x [i]) 44. The statement printf (“%d”, (a++)); prints
(c) *(x + i) is same as x[i] (a) the current value of a (b) the value of a + 1
(d) both (b) and (c) (c) an error message (d) garbage
35. Choose the correct statements 45. Consider the function
(a) An entire array can be passed as argument to a function. find (int x, int y)
(b) A part of an array can be passed as argument to a {return ((x < y) ? 0 : (x – y)); }
function. Let a, b be two non-negative integers. The call find (a, find
(c) Any change done to an array that is passed as an (a, b)) can be used to find the
argument to a function will be local to the function. (a) maximum of a, b
(d) Both (a) and (b) (b) positive difference of a, b
36. A pointer variable can not be (c) sum of a, b
(a) passed to a function as argument (d) minimum of a, b
(b) changed within a function 46. If abc is the input, then the following program fragment
(c) returned by a function char x, y, z;
(d) assigned an integer value printf (“%d”, scanf (“%c%c%c, &x, &y, &z)); results in
37. If func is a function needing three arguments a1, a2, a3, then (a) a syntax error (b) a fatal error
func can be invoked by (c) segmentation violation (d) printing of 3
(a) func (a1, a2, a3); (b) (*func) (a1, a2, a3); 47. Consider the statements
(c) *func (a1, a2, a3); (d) Both (a) and (b) putchar (getchar ());
38. The following program putchar (getchar ());
main () If
{ a
float a = .5, b = .7; b
if (b < = 7) is the input, the output will be
if (a < .5) (a) an error message (b) a/nb
printf (“IES”); (c) ab (d) a b
else 48. If y is of integer type then the expressions
printf (“PSU”); 3 * (y – 8)/9 and (y – 8) / 9*3
else yield the same value if
printf (“GATE”); (a) y must yield the same value
} (b) y must yield different values
(c) y may or may not yield the same value
output is
(d) None of these
(a) PSU (b) IES
(c) GATE (d) None of these
EBD_7203
S3-180 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
49. The program fragment 57. Consider the following flow chart.
int i = 263; T
F
putchar (i); a>b b>c a=1
(a) prints 263
(b) prints the ASCII equivalent of 263
(c) rings the bell F
(d) prints garbage
50. The following statement F
printf (“%f”, 9/5); b=2 c>d
prints
(a) 1.8 (b) 1.0 Which of the following does not correctly implements the
(c) 2.0 (d) none of these above flow chart?
51. The following loop (a) if (a > b) (b) if (a < = b)
for (putchar (‘c’); putchar (‘a’); putchar (‘r’)) putchar (‘t’); if (b > c) if (b > c)
outputs a = 1; a = 1;
else if (c > d) else if (c < = d)
(a) a syntax error (b) cartrt
b = 2; b = 2;
(c) catrat (d) catratratratrat...
(c) if (a > b) (d) if (a < = b)
52. The following program ; ;
main () else if (b > c) else if (b > c)
{ a = 1; a = 1;
int i = 5; else if (c < = d) else if (c > d)
if (i = = 5) return; b = 2; ;
else printf “i is not five”); else b = 2;
printf (“over”); 58. The following statement
} if (a > b)
results in if (c > b)
(a) a syntax error print f (“one”);
(b) an execution error else
(c) printing of over if (c = = a) printf (“two”);
(d) execution termination, without printing anything else print f (“three”);
53. The following program fragment else print f (“four”);
int i = 5; (a) results in a syntax error
do {putchar (i + 100); printf (“%d”, i – –):} (b) prints four if c < = b, can here print four
while (i); (c) prints two if c < = b, can never print two
results in the printing of (d) prints four if a < = b, can never print four
(a) i5h4g3f 2e1 (b) i4h3g2 fle0 59. The following program fragment
(c) an error message (d) none of these int x = 4, y = x, i;
for (i = 1; i < 4; ++ i)
54. The following statements
x + = x;
for (i = 3; i < 15; i + = 3) outputs an integer that is same as
{ printf (“%d”, i); (a) 8 * y (b) y * (1 + 2 + 3 + 4)
++i; (c) y * 4 (d) y * y
} 60. Consider the declaration
will result in the printing of static char hello {} = “hello” ;
(a) 3 6 9 12 (b) 3 6 9 12 15 The output of print f (“% s \ n”, hello);
(c) 3 7 11 (d) 3 7 11 15 will not be the same as that of
55. If a = 9, b = 5 and c = 3, then the expression (a – a/b * b % c) (a) puts (“hello”);
> a % b % c evaluates to (b) puts (hello);
(a) true (b) false (c) printf (“%s \ n”, “hello”);
(c) invalid (d) 0 (d) puts (“hello \ n”);
56. Consider the following program fragment 61. The following program
if (a > b) main ()
printf (“a > b”) {
else static int a[ ] = {7, 8, 9};
printf (“else part”); print f (“%d”, 2 [a] + a[2]);
printf (“a < = b”); }
then a < = b (a) results in bus error
will be printed if (b) results in segmentation violation error
(a) a > b (b) a < b (c) will not compile successfully
(c) a = = b (d) All of the above (d) None of these
PROGRAMMING AND DATA STRUCTURES S3-181
62. The following program (a) storage needed will be proportional to the size of the
main () data
{ (b) execution will be faster
static char a[3] [4] = {“abcd”, “mnop”, “fghi”}, (c) swapping process becomes easier and faster
putchar (**a); (d) All of the above
} 70. Consider the two declarations
(a) will not compile successfully void * voidPtr;
(b) results in run-time error char *charPtr;
(c) prints garbage Which of the following assignments are syntactically
(d) None of these correct?
63. The output of the following program is (a) voidPtr = charPtr (b) charPtr = voidPtr
main () (c) * voidPtr = * charPtr (d) * charPtr = voidPtr
{ static int x[ ] = {1, 2, 3, 4, 5, 6, 7, 8}, 71. Consider the declaration
int i; char x[ ] = “SUCCESS”;
for (i = 2; i < 6; ++i) char *y = “SUCCESS”;
x [x[i]] = x[i]; Pick the correct answers.
for (i = 0; i < 8; ++i) (a) The output of puts (x) and puts (y) will be the same.
print f (“%d”, x[i]); (b) The output of puts (x) and puts (y) will be different.
} (c) The output of puts (y) is implementation dependent.
(a) 1 2 3 3 5 5 7 8 (b) 1 2 3 4 5 6 7 8 (d) None of the above comments are true.
(c) 8 7 6 5 4 3 2 1 (d) 1 2 3 5 4 6 7 8 72. Consider three pegs A, B, C and four disks of different sizes.
64. Consider the following program Initially, the four disks are stacked on peg A, in orderof
main () decreasing size. The task is to move all the disks from peg A
{ int x = 2, y = 2; to peg C with the help of peg B. themoves are to be made
if (x < y) return (x = x + y); under the following constraints:
else printf (“z1”); [i] In each step, exactly one disk is moved from one peg to
printf (“z2”); another.
} [ii] A disk cannot be placed on another disk of smaller size.
Choose the correct statements If we denote the movement of a disk from onepeg to another
(a) The output is z2 by y ® y, where y, y are A, B or C, then represent the
(b) The output is z1z2 sequence of the minimum numberof moves to accomplish
(c) This will result in compilation error this as a binary tree with node labels of the form (y ® y)
(d) None of the above such that the in-ordertraversal of the tree gives the correct
65. A possible output of the following program fragment sequence of the moves.If there are n disks, what is the total
static char wer [ ] [5] = {“harmot”, “merli”, “axari”); number of moves required in terms of n. Answer can be an
printf ({“%d %d”, wer, wer [0], &wer [0] [0]); is expression in terms of n.
(a) 262164 262164 262164 (b) 262164 262165 262166 (a) 2n – 1 (b) 2n + 1
(c) 262164 262165 262165 (d) 262164 262164 262165 (c) 2 n – 1 (d) 2n – 3
66. The following program 73. The following sequence of operations is performed on a
main () stack :
{ int abc (); PUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP,
abc (); POP, POP, PUSH (20), POP.
(*abc) (); (a) 10 20 10 20 20 (b) 20 10 10 20 20
} (c) 20 20 10 10 20 (d) None of these
int abc () 74. Choose the false statements.
{printf (“come”);} (a) The scope of a macro definition need not be the entire
(a) results in a compilation error program.
(b) prints come come (b) The scope of a macro definition extends from the point
(c) results in a run time error of definition to the end of the file.
(d) prints come
(c) A macro definition may go beyond a line
67. The possible output of printf (“%d %d, wer [1], wer [1] + 1); is
(d) None of the above
(a) 162 163 (b) 162 166
75. Calloc (m, n); is equivalent to
(c) 162 166 (b) 162 165
68. The possible output of printf (“%d %d, wer, wer + 1); is (a) malloc (m*n, 0);
(a) 262 262 (b) 262 266 (b) memset (0, m*n);
(c) 262 263 (b) 262 265 (c) ptr = malloc (m*n); memset (p, 0, m*n)
69. While sorting a set of names, representing the names as an (d) ptr = malloc (m*n); strcpy (p, 0)
array of pointers is preferable to representing the name as a
two dimensional array of characters, because
EBD_7203
S3-182 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
76. The for loop 84. For loop in a C program, if the condition is missing
for (i = 0, i < 10; ++i) (a) it is assumed to be present and taken to be false
printf (“%d”, i &1); (b) it is assumed to be present and taken to the true
prints (c) it result in a syntax error
(a) 0101010101 (b) 0111111111 (d) execution will be terminated abruptly
(c) 0000000000 (d) 1111111111 85. Which of the following statements about for loop is/are
77. The output of the following program correct?
main () (a) Index value is retained outside the loop
{ int a = 1, b = 2, c = 3; (b) Index value can be changed from within the loop
printf (“%d”, a + = (a + = 3, 5, a)); (c) Goto can be used to jump, out of the loop
} (d) All of these
will be 86. If c is a variable initialised to 1, how many times will the
(a) 8 (b) 12 following loop be executed?
while ((c > 0). && (c < 60)) {
(c) 9 (d) 6
loop body
78. Consider the following program segment.
c + + ;}
char *a, *b, c [10], d[10];
(a) 60 (b) 59
a = b;
(c) 61 (d) 1
b = c;
87. The program fragment
c = d; int i = 263;
d = a; putchar (i);
Choose the statements having errors. prints
(a) No error (b) a = b; and b = c; (a) 263 (b) ASCII equivalent of 263
(c) c = d; and d = a; (d) a = b; and d = a; (c) rings the bell (d) garbage
79. Consider the following statements 88. If statement
# define hypotenuse (a, b) sqrt (a * a + b * b); b = (int *) **c;
The macro-call hypotenuse (a + 2, b + 3); is appended to the above program fragment, then
(a) Finds the hypotenuse of a triangle with sides a + 2 and (a) value of b is unaffected
b+ 3 (b) value of b will be the address of c
(b) Finds the square root of (a + 2)2 + (b + 3)2 (c) value of b becomes 5
(c) is invalid (d) None of these
(d) Finds the square root of 3*a + 4*b + 5 89. Consider the declarations:
80. Which of the following comments about arrays and pointers char first (int (*) (char, float));
is/are not true? int second (char, float);
1. Both are exactly same Which of the following function invocation is valid?
2. Array is a constant pointer (a) first (*second) (b) first (& second);
3. Pointer is an one-dimensional array (c) first (second); (d) None of these
4. Pointer is a dynamic array 90. Consider the declaration:
(a) 1, 3 and 4 (b) 1, 2, and 3 static struct {unsigned a : 5;
(c) 2, 3 and 4 (d) 1, 2, 3 and 4 unsigned b : 5;
81. Use of macro instead of function is recommended unsigned c : 5;
(a) when one wants to reduce the execution time unsigned d : }v = (1, 2, 3, 4);
(b) when there is a loop with a function call inside v occupies
(a) 4 words (b) 2 words
(c) when a function is called in many places in a program
(c) 1 word (d) None of these
(d) In (a) and (b) above
91. The value of ab if ab & 0 × 3f equals 0 × 27 is
82. Which of the following statements is (are) correct?
(a) 047 (b) 0 × 0f
(a) Enum variables can be assigned new values
(c) 0 × f 3 (d) 0 × 27
(b) Enum variables can be compared
92. A function can make
(c) Enumeration feature does not increase the power of C
(a) one throw
(d) All of these
(b) one throw of each scale type
83. For ‘C’ programming language,
(c) one throw of each programmer defined type
(a) constant expressions are evaluated at compile time
(d) as many throws of as many types as necessary.
(b) string constants can be concatenated at compile time
93. In the statement template << class T>>,
(c) size of array should be known at compile time
(a) T is a class (b) T is a scalar variable
(d) All of these
(c) either (a) or (b) (d) None of these
PROGRAMMING AND DATA STRUCTURES S3-183
94. In C programming language, which of the following type of 105. Following is a recursive function for computing the sum of
operators have the highest precedence integers from 0 to N.
(a) relational operators function sum (N : integer): integer
(b) equality operators begin
(c) logical operators if N = 0 then Sum = 0
(d) arithmetic operators else
95. In C programming language, which of the following end;
operators has the highest precedence? The missing line in the else part is
(a) unary + (b) * (a) Sum : = N + Sum (N)
(c) ³ (d) = = (b) Sum : = N + Sum (N – 1)
96. What will be the value of x and y after execution of the (c) Sum : = (N – 1) + Sum (N)
following statement (C language) n = = 5; x = n++; y = – x? (d) Sum : = (N – 1) + Sum (N – 1)
106. What is the value of F(4) using the following procedure?
(a) 5, 4 (b) 6, 5
function F(k : integer) : integer;
(c) 6, 6 (d) 5, 5
begin
97. C programming language provides operations which deal if (k < 3)
directly with objects such as then F: = k
(a) strings and sets else F : = F(k – 1) * F(k – 2) + F(k – 3)
(b) lists and arrays end;
(c) characters, integers, and floating point numbers (a) 5 (b) 6
(d) All of these (c) 7 (d) 8
98. C programming language by itself provides 107. Which of the following types of expressions does not require
(a) input facility precedence rule for evaluated?
(b) output facility (a) Full parenthesized infix expression
(c) both input and output facilities (b) Prefix expression
(d) no input and output facilities (c) Partially parenthesized infix expression
99. In what kind of storage structure for strings, one can easily (d) More than one of these
insert, delete, concatenate and rearrange substrings? 108. If space occupied by null terminated string “S1” and “S2” in
(a) Fixed length storage structure “c” are respectively “m” and “n”, the space occupied by
(b) Variable length storage with fixed maximum the string obtained by concatenating “S1” and “S2” is
(c) Linked list storage always
(d) Array type storage (a) less than m + n (b) equal to m + n
100. The time required to search an element in a linked list of (c) greater than m + n (d) None of these
length n is 109. Output of the following ‘C’ program is
(a) O (log2n) (b) O(n) main ()
(c) O(1) (d) O(n2) {
101. Consider a linked list of n element which is pointed by an printf (“\n%x”, – 1 >>4);
external pointer. What is the time taken to delete the element }
which is successor of the element pointed to by a given (a) ffff (b) 0fff
pointer? (c) 0000 (d) fff0
(a) O (1) (b) O (log2n) 110. If abc is the input, then following program fragment
(c) O (n) (d) O (n log2 n) char x, y, z;
102. Which of the following is a tabular listing of contents of printf (“%d”, scanf (“%c%c%c”, &x, &y, &z));
certain registers and memory locations at different times results in
(a) a syntax error (b) a fatal error
during the execution of a program?
(c) segmentation violation (d) printing of 3
(a) Loop program (b) Program trace
111. The rule for implicit type conversion in ‘C’ is
(c) Subroutine program (d) Byte sorting program
(a) int < unsigned < float < double
103. For a linear search in an array of n elements the time
(b) unsigned < int < float < double
complexity for best, worst and average case are......, ..... and
(c) int < unsigned < double < float
.... respectively
(d) unsigned < int < double < float
(a) O(n), O(1) and O(n/2) (b) O(1), O(n) and O(n/2)
112. Result of the execution of the following ‘C’ statements is
æ n -1 ö int i = 5;
(c) O/1, O(n) and O(n) (d) O(1), O(n) and ç ÷ do {putchar (i + 100); printf (“%d”, i– –);}
è 2 ø
104. Using the standard algorithm, what is the time required to while (i);
determine that a number n is prime? (a) i5hug3f 2e1 (b) 14h3g2f1e0
(a) Linear time (b) Logarithmic time (c) an error message (d) None of these
(c) Constant time (d) Quadratic time
EBD_7203
S3-184 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
113. A “switch” statement is used to 121. The expression 5 – 2 – 3 * 5 – 2 will evaluate to 18, if – is left
(a) switch between functions in a program associative and
(b) switch from one variable to another variable (a) * has precedence over *
(c) to choose from multiple possibilities which may arise (b) * has precedence over –
due to different values of a single variable (c) – has precedence over *
(d) to use switching variable (d) – has precedence over –
114. When a function is recursively called, all automatic variables 122. What is the output of this program?
(a) are initialized during each execution of the function 1. #include <iostream>
(b) are retained from the last execution 2. #include <functional>
(c) are maintained in a stack 3. #include <numeric>
(d) None of these
4. using namespace std;
115. For x and y are variables as declared below
double x = 0.005, y = – 0.01; 5. int myop (int x, int y)
what is the value of ceil (x + y), where ceil is a function to 6. {
compute ceiling of a number? 7. return x + y;
(a) 1 (b) 0 8. }
(c) 0.005 (d) 0.5
9. int main ()
116. The declarations
typedef float height [100]; 10. {
height men, women; 11. int val[] = {1, 2, 3, 5};
(a) define men and women as 100 element floating point 12. int result[7];
arrays 13. adjacent_difference (val, val + 7, result);
(b) define men and women as floating point variables
(c) define height, men and women as floating point 14. for (int i = 0; i < 4; i++)
variables 15. cout << result[i] <<’ ‘;
(d) are illegal 16. return 0;
117. A short integer occupies 2 bytes, an ordinary integer 4 bytes 17. }
and a long integer occupies 8 bytes of memory. (a) 1112 (b) 2111
If a structure is defined as (c) 1212 (d) None of these
struct TAB { 123. The C declaration
short a; int b [100];
int b; reserves ________ successive memory locations, each large
long c; enough to contain single integer.
}TABLE [10]; (a) 200 (b) 10,000
then total memory requirement for TABLE is (c) 100 (d) 10
(a) 14 (b) 140 124. Match List I with List II and select the correct answer from
(c) 40 (d) 24 the codes given below the lists:
118. If i, j, k are integer variable with values 1, 2, 3 respectively, List I List I
then what is the value of the expression A. m = malloc (5); m = NULL 1. Using doing long
((j + k) > (i + 5)) pointers
(a) 6 (b) 5 B. Free (n); n ® value = 5; 2. Using uninitialized
(c) 1 (d) 0 pointers
C. char* P, *P = ‘a’; 3. Lost memory
119. The expression a << 6 shifts all bits of a six places to the left.
Codes:
If a 0x6db7, then what is the value of a << 6?
A B C
(a) 0xa72b (b) 0xa2b (a) 1 2 3
(c) 0x6dc0 (d) 0x1111 (b) 3 1 2
120. The declaration (c) 3 2 1
union id { (d) 2 3 1
char colour [12]; 125. The average search time of hashing, with linear probing will
int size; } shirt, pant; be less if the load factor
denotes shirt and pant are variable of type id and (a) is for less than one (b) equals one
(a) each can have a value of colour and size (c) is for greater than one (d) None of these
(b) each can represent either a 12-character colour or a 126. argv is a/an
integer size at a time (a) array of character pointers
(c) shirt and pant are same as struct variables (b) pointer to an array of character pointers
(d) variable shirt and pant cannot be used simultaneously (c) array of strings
in a statement. (d) None of these
PROGRAMMING AND DATA STRUCTURES S3-185
127. In the following declarations: Which stacks are possible:
typedef struct { (a) All possible stacks with A, B, C, D, E and F
char name [20]; (b) No possible stacks with A, B, C, D, E and F
char middlename [5]; (c) Exactly and only those stacks which can be produced
char surname [20]; with SI alone
} NAME (d) Twice as many stacks can be produced with SI alone
NAME class [20]; 134. Consider the following tree
class is 1
(a) an array of 20 characters only
(b) an array of 20 names where each name consists of a
name, middlename and surname 3
2
(c) a new type
(d) none of these
128. What would be the values of i, x and c if
scanf (“%3d, %5f, %c”, &i, &x, &c) 4 5 6 7
is executed with input data 10b 256, 875bT?
If the post order traversal gives ab – cd* + then the label of
(a) i = 10, b = 56.875, C = T
the nodes 1, 2, 3, .... will be
(b) i = 100, b = 256.87, C = T
(a) +, –, *, a, b, c, d (b) a, –, b, +, *, d
(c) i = 010, b = 256.87, C = ‘5’
(d) i = 10, b = 256.8, C = ‘7’ (c) a, b, c, d, d, –, *, + (d) –, a, b, +, *, c, d
129. The five items : A, B, C, D and E are pushed in a stack, one 135. Consider the following tree
after the other starting from A. The stack is popped four
times and each element is inserted in a queue. Then two 6
elements are deleted from the queue and pushed back on
the stack. Now one item is popped from the stack. The
popped item is 4 12
(a) A (b) B
30
(c) C (d) D
130. Which of the following is an illegal array definition?
(a) type COLOGNE: (LIME, PINE, MUSK, MENTHOL); 1 5 10
var a : array [COLOGNE] of REAL; 11
(b) var a : array [REAL] of REAL;
(c) var a : array [‘A’.. ‘Z’] of REAL; If this tree is used for sorting, then a new number 8 should
(d) var a : array [BOOLEAN] of REAL; be places as the
131. Which of the following assertions is most strongly satisfied (a) left child of the node labeled 30
at the point marked [1]? (b) right child of the node labeled 5
(a) list [j] < list [j + 1] for all j such that item £ j < n (c) right child of the node labeled 30
(b) list [j] < list [j + 1] for all j such that item < j £ n (d) left child of the node labeled 10
(c) list [j] £ list [j + 1] for all j such that item £ j < n 136. The number of possible binary search trees with 3 nodes is
(d) list [j] < list [j – 1] for all j such that 1 < j £ item
(a) 12 (b) 13
132. Using Pop (SI, Item), Push (SI, Item), Read (Item), Print (Item),
(c) 5 (d) 15
the variables SI (stack) and Item, and given the input file:
A, B, C, D, E, F, < EOF > 137. You want to check whether a given set of items is sorted.
Which stacks are possible? Which of the following sorting methods will be the most
(a) 5 A (b) 5 efficient if it is already is sorted order?
4 B 4 (a) Bubble sort (b) Selection sort
3 C 3 D (c) Insertion sort (d) Merge sort
2 D 2 A 138. As part of the maintenance work, you are entrusted with the
1 E 1 F work of rearranging the library books in a shelf in proper
(c) 5 (d) 5 order, at the end of each day. The ideal choice will be
4 4 (a) bubble sort (b) insertion sort
3 F 3 C (c) selection sort (d) heap sort
2 D 2 E 139. Which of the following algorithms solves the all-pair shortest
1 B 1 B path problem?
133. Using Pop (SI, Item), Push (SI, Item), Getlist (Item), Pop (S2, (a) Dijkstra’s algorithm (b) Floyd’s algorithm
Item), Push (S2, Item), and the variables S1, S2 (stacks with (c) Prim’s algorithm (d) Warshall’s algorithm
Top 1 and Top 2) and Item and given the input file: 140. Which of the following expressions accesses the (i, j)th entry
A, B, C, D, E, F, < EOF > of a (m × n) matrix stored in column major form?
(a) n × (i – 1) + j (b) m × (j – 1) + i
(c) m × (n – j) + j (d) n × (m – i) + j
EBD_7203
S3-186 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
141. Sparse matrices have
(a) many zero entries (b) many non-zero entries +
(c) higher dimension (d) none of the above – !
142. Consider the graph in figure –
– e
A C b
1. a = – b and e = 0
B D
2. a = – b and e = 1
3. a = b and e = 0
Which of the following is a valid topological sorting?
4. a = b and e = 1
(a) A B C D (b) B A C D
(a) 2 only (b) 3 and 4
(c) B A D C (d) A B D C
(c) 1 and 2 (d) 1 and 4
143. For merging two sorted lists of sizes m and n into a sorted
list of size m + n. Find out the time complexity of this merging 150. Unrestricted use of goto is harmful, because it
process. (a) makes debugging difficult
(a) O(m) (b) O(n) (b) increases the running time of programs
(c) O(m + n) (d) O(log(m) + log (n)) (c) increases memory requirement of programs
144. A binary tree has n leaf nodes. The maximum numbers of (d) results in the compiler generating longer machine code
nodes of degree 2 in this tree is 151. The maximum degree of any vertex in a simple graph with n
(a) log2 n (b) n – 1 vertices is
(c) n (d) 2n (a) n (b) n – 1
145. The postfix expression for the infix expression (c) n + 1 (d) 2n – 1
A + B* (C + D)/F + D*E is: 152. The recurrence relation that arises in relation with the
(a) AB + CD + *F/D + E* (b) ABCD + *F / + DE* + complexity of binary search is
(c) A*B + CD? F*DE ++ (d) F*DE++ (a) T(n) = T(n/2) + k, where k is a constant
146. Stack is useful for implementing (b) T(n) = 2T(n/2) + k, where k is a constant
(a) recursion (b) breadth first search (c) T(n) = T(n/2) + log(n)
(c) depth first search (d) both (a) and (c) (d) T(n) = T(n/2) + n
147. A machine took 200 sec to sort 200 names, using bubble NUMERICAL TYPE QUESTIONS
sort. In 800 sec, it can approximately sort 153. The expression 4 + 6 / 3 * 2 – 2 + 7% 3 evaluates to
(a) 400 names (b) 700 names 154. Consider the following program segment.
(c) 750 names (d) 800 names i = 6720; j =4 ;
148. Which of the following is useful in implementing heap sort? while (i%j) = = 0)
(a) Stack (b) Set {i = i/j;
(c) List (d) Queue j = j + 1;
149. The expression tree given in Fig. evaluates to 1, if }
On termination j will have the value
155. If 7 bits are used to store a character, the percentage
reduction of needed storage will be
156. Consider the following program fragment.
d = 0;
for (i = 1; i < 31; ++i)
PROGRAMMING AND DATA STRUCTURES S3-187
for (j = 1; j < 31; ++k) while ((c = getchar( )) != EOF)
for (k = 1; k < 31; ++k) { if (isdigit(c))
if (((i + j + k) % 3) = = 0) push (c)
d = d + 1;
else if (c = = ‘+’) || (c = = ‘*’))
printf (“%d”, d);
{ m = pop( );
the output will be
n = pop( );
157. Suppose one character at a time comes as an input from a
are = (c = = ‘+’) ? n + m : n*m;
string of letters. There is an option either to (i) print the
incoming letter or to (ii) put the incoming letter on to a stack. push(r);
Also a letter from top of the stack can be popped out at any }
time and printed. The total number of total distinct words else if (c != ‘ ‘)
that can be formed out of a string of three letters in this flagError( );
fashion, is. Enter a value. }
158. #include<stdio.h> printf(“%c”, pop( ));
#define EOF -1 }
What is the output of the program for the following
void push(int); /* Push the argument on the stack */
input?
int pop(void); /* pop the top of the stack */ 52*332+*+
void flagError();
int main( )
{ int c, m, n, r;
EBD_7203
S3-188 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
PAST GATE QUESTIONS EXERCISE function and when the function foo (a, sum) is called
1. (a) a + b × c – d ^ e ^ f where a = 2048 and sum = 0 as per given conditions.
a+b×c–d^e f^ Then, the execution of the function takes in the following
a+b×c–def^ ^ manner.
a+bc×–d e f ^ ^ i) k= n % 10 => modulus operator will return the remainder.
abc× –d e f ^ ^ for example, if n=2048, then 2048 %10 will store the value
abc× +d e f ^ ^ 8 in k.
a b c × + d e f ^ ^– ii) j is declared as integer datatype in foo function.
the result is obtained. Therefore after division if the result contains decimal part,
2. (a) it will be truncated and only the integer part will be stored
3. (c) As given p is a single variable that is used to access the in j. For example if j=2048/10, (actual result = 204.8) then
queue and with the single variable it is not possible to 204 will be stored in j.
perform both the functions of enqueue and dequeue with iii) The sum variable declared in the main function will
a constant time since, insertion and deletion are not be used by the foo function.
operations that needs to be done from the opposite end 9. (a) We have to store frequencies of scores above 50. That is
of the queue rear and front respectively.
number of students having score 51, number of students
4. (b) The program undergoes normal execution upto line
having score 52 and so on. For that an array of size 50 is
number 7 since, no error is present til there but as soon
the best option.
as the execution goes to line 8 an error occurs as in this
the pointer s is assigned a character variable, i.e., p and 10. (b) Object Oriented Programming (OPP) is a programming
this assignment is not permissible in C language thus, paradigm. The language is object oriented as it use
the program produces a garbage value as an output or objects. Objects are the data structures that contain data
no output is returned. fields and methods together with their interactions.
5. (c) The iterations that the given code will undergo are: The main features of the Programming techniques are
From the given conditions we does not take into account 1. data abstraction
when n = 1 2. encapsulation
Iteration 1
N = 1 + 1 = 2 therefore, i = 2 3. modularity
Iteration 2 4. polymorphism
N = 2 + 2 = 4 therefore, i = 3 5. inheritance
Iteration 3 Therefore, the essential features are given by statements
N = 4 + 3 = 2 = 4 therefore, i = 4 (i) and (iv).
Hence, the value returned after three iterations is 7
11. (c) Languages needs declaration of any statement that we
When, i = 4 and it also fulfill the condition of n>=5
write before its use thus, the common property of both
6. (a) Inorder traversal of a BST always gives elements in
the languages is that both are declarative.
increasing order. Among all four options, (a) is the only
increasing order sequence. 12. (c) An abstract data type is a mathematical model for a certain
7. (c) Whenever the a function’s data type is not declared in class of data structures that have similar behaviour. An
the program, the default declaration is taken into abstract data type is indirectly defined by the operations
consideration. By default, the function foo in this is and mathematical constraints thus, is a user defined data
assumed to be of int type, then also it returns a double type, not a system defined, that can perform operations
type of value. This situation will generate compiler defined by it on that data.
warning due to this mismatch leading to unintended 13. (c) Syntax to declare pointer to a function =>datatype
results. (*pointer_variable)(list of arguments)
8. (d) sum has no use in foo(), it is there just to confuse. Function To make a pointer to a function =>pointer_variable =
foo() just prints all digits of a number. In main, there is function_name
one more printf statement after foo(), so one more 0 is
Note: don't use parenthesis of the function.
printed after all digits of n.
From the given code it is found that foo is a recursive To call (invoke) the function =>pointer_variable(list of
arguments)
PROGRAMMING AND DATA STRUCTURES S3-189
14. (b) For the given code only the statements S2 and S3 are
a
valid and thus, are true. Since, the code may generate a
segmentation fault at runtime depending on the
arguments passed as the arguments are passed by c
b
reference and also the swap procedure is correctly
implemented. g
d e f
15. (d) Both functions work1 &work2 performs the same task,
therefore S1 is true. In the postorder traversal, the sequence is debfgca.
In S2 it is asking about improvement in performance i.e. 20. (d) We follow, the following steps to obtain the value of f(5)
reduction in CPU time. When compared work2 will reduce
f(5)
the CPU time, because in work1 a[i+2] is computed twice
but in work2 a[i+2] is computed once and stored in t2, r=5
and then t2 is used. When we consider the performance f(3) + 2 = 18
in terms of reduction in CPU time, S2 is correct.
16. (c) The condition (i) is true if the last inserted element in c[] f(2) + 5 = 16
is from a[] and condition (ii) is true if the last inserted
element is from b[]. f(1) + 5 = 11
17. (a) The order in which insert and delete operations are
performed matters here.
f(0) + 5 = 6
The best case: Insert and delete operations are performed
alternatively. In every delete operation, 2 pop and 1 push
operations are performed. So, total m+ n push (n push for 1
insert() and m push for delete()) operations and 2m pop 21. (a) The algorithm for evaluating any postfix expression is
operations are performed. fairly straightforward:
The worst case: First n elements are inserted and then m 1. While there are input tokens left
elements are deleted. In first delete operation, n + 1 pop o Read the next token from input.
operations and n push operation are performed. Other o If the token is a value
+ Push it onto the stack.
than first, in all delete operations, 1 pop operation is o Otherwise, the token is an operator
performed. So, total m + n pop operations and 2n push (operator here includes both operators, and functions).
operations are performed (n push for insert() and m push * It is known a priori that the operator takes n arguments.
for delete()) * If there are fewer than n values on the stack
18. (c) A node is a leaf node if both left and right child nodes of (Error) The user has not input sufficient values in the
expression.
it are NULL.
* Else, Pop the top n values from the stack.
1) If node is NULL then return 0. * Evaluate the operator, with the values as arguments.
2) Else If left and right child nodes are NULL return 1. * Push the returned results, if any, back onto the stack.
3) Else recursively calculate leaf count of the tree using 2. If there is only one value in the stack
below formula. o That value is the result of the calculation.
Leaf count of a tree = Leaf count of left subtree + 3. If there are more values in the stack
o (Error) The user input has too many values.
Leaf count of right subtree Let us run the above algorithm for the given expression.
First three tokens are values, so they are simply pushed.
After pushing 8, 2 and 3, the stack is as follows
8, 2, 3
When ^ is read, top two are popped and power(2^3) is
calculated
8, 8
When / is read, top two are popped and division(8/8) is
performed
1
Example Tree Next two tokens are values, so they are simply pushed.
Leaf count for the above tree is 3. After pushing 2 and 3, the stack is as follows
19. (a) The inorder traversal sequence is dbeafcg and the 1, 2, 3
preorder traversal sequence is abdecfg so, the tree is When * comes, top two are popped and multiplication is
performed.
1, 6
EBD_7203
S3-190 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
22. (d) From the statement j = j*2 in the code we get to know that binary max-heap.
j increases in power of 2’s. Let us say that this statement Thus, under given cases the tree obtained is.
execute x times then, according to the question for while
25
loop
2^x < = n
Therefore, x < = log2n 14 16
And also for termination of while loop there will be an
extra comparison required. Thus, total number of
13 10
comparisons = x + 1 8 12
= [log2n] + 2
23. (b) The function rearrange() exchanges data of every node 28. (d) Always a greater element is deleted from the binary heap
with its next node. It starts exchanging data from the first first. The answer of previous question gave the array as
node itself. [25, 14, 16, 13, 10, 12, 8]
24. (d) The option chosen is So, when the greatest element, i.e., 25 is deleted the array
?1 is ((c = getchar ( ))! = ‘\n’) becomes [14, 16, 13, 10, 12, 8]
?2 is putchar (c); And next after second deletion the array becomes [14,
Because the operator ‘1=’ has higher priority than ‘=’ 13, 10, 12, 8]
operator so according to this C = getchar () should be Thus, the procedure for the obtaining the final tree is as
contained in brackets and when the string is reversed follows.
then the function putchar (c) is used so that the characters Replacing 25 with After heapifying
can be printed.
25. (b) The program gets executed in the following manner 12 16
Graphical Representation
c a 2000 14 14 12
4 b 1000 16
1000 2000 3000
13 10 8 13 10 8
ALGORITHM ANALYSIS
C
Ø Analysis, Asymptotic Notation
N
Ø Design: Greedy approach, Dynamic programming,
Divide-and-conquer
T Ø Connected components
E Ø
Ø
Spanning trees, Shortest paths
S
EBD_7203
S3-202 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ALGORITHM ANALYSIS AND DESIGN Output: Finds the location LOC of x in the array A
(by returning an index) or return LCO = 0 to indicate x is not
An Algorithm is a well defined computational procedure
present in A.
that takes input and produces output.
1. [Initialize] : Set K = 1 and LOC = 0.
An Algorithm is a finite sequence of instructions or steps
2. Repeat step 3 and 4 while (LOC = = 0 && K £ n)
(i.e. inputs) to achieve some particular output.
3. if (x = = A [K])
Any Algorithm must satisfy the following criteria (or
4 {
Properties)
5. LOC = K
1. Input: It generally requires finite number of inputs.
6. K = K + 1;
2. Output: It must produce at least one output.
7. }
3. Uniqueness: Each instruction should be clear and
8. if (LOC = = 0)
unambiguous.
9. printf ("x is not present in the given array A);
4. Finiteness: It must terminate after a finite number of steps.
10. else
"Analysis of algorithm" is a field in computer science
11. printf ("x is present in the given array A at location A
whose overall goal is an understanding of the complexity of
[LOC]);
algorithms (in terms of time Complexity), also known as
12. Exit [end of algorithm]
execution time & storage (or space) requirement taken by
Analysis of linear search algorithm : The complexity of the search
that algorithm. Suppose M is an algorithm, and suppose n is
algorithm is given by the number C of comparisons between x and
the size of the input data. The time and space used by the
array elements A[K].
algorithm M are the two main measures for the efficiency of
Best case: Clearly the best case occurs when x is the first element
M. The time is measured by counting the number of key
in the array A.
operations, for example, in case of sorting and searching
Worst case: Clearly the worst case occurs when x is the last
algorithms, the number of comparisons is the number of key
element in the array A or is not present in given array A (to ensure
operations. That is because key operations are so defined
this we have to search entire array A till last element). In this case,
that the time for the other operations is much less than or at
we have C (n)=n.
most proportional to the time for the key operations. The
Average case: Here we assume that searched element appear array
space is measured by counting the maximum of memory
A, and it is equally likely to occur at any position in the array. Here
needed by the algorithm.
the number of comparisons can be any of numbers 1,2 ,3
The complexity of an algorithm M is the function f(n), which
4………….n, and each number occurs with the probability p = 1/n
give the running time and/or storage space requirement of
the algorithm in terms of the size n of the input data. 1 1 1
C (n) = 1. + 2. + ...... .... + n.
Frequently, the storage space required by an algorithm is n n n
simply a multiple of the data size n. In general the term
1
"complexity" given anywhere simply refers to the running = (1 + 2 + ...... .... + n).
time of the algorithm. There are 3 cases, in general, to find n
the complexity function f(n): n(n + 1) 1 n + 1
1. Best case: The minimum value of for any possible = . =
2 n 2
input.
It means the average number of comparisons needed to find the
2. Worst case: The maximum value of for any possible
location of x is approximately equal to half the number of elements
input.
in array A. From above discussion, it may be noted that the
3. Average case: The value of which is in between
complexity of an algorithm in the average case is much more
maximum and minimum for any possible input.
complicated to analyze than that of worst case. Unless otherwise
Generally the average case implies the expected value
stated or implied, we always find and write the complexity of an
of f(n).
algorithm in the worst case.
To understand the Best, Worst and Average cases of an
algorithm, consider a linear array, where the array A contains There are three basis asymptotic (i.e., n ® ¥ ) notations
n-elements. Students may you are having some problem in which are used to express the running time of an algorithm in
understanding. Suppose you want either to find the location terms of function, whose domain is the set of natural numbers N =
LOC of a given element (say ) in the given array A or to send {1, 2, 3, ......}. These are :
some message, such as LOC=0, to indicate that does not • O (Big –'Oh') [This notation is used to express upper
appear in A. Here the linear search algorithm solves this bound (maximum steps) required to solve a problem]
problem by comparing given, one-by-one, with each element • W (Big –'Omega') [This notation is used to express
in A. That is, we compare with A[1], then lower bound i.e. minimum (at least) steps required to
A[2], and so on, until we find LOC such that x = A[LOC]. solve a problem]
Algorithm : (Linear search) • Q ('Theta') Notations. [Used to express both upper &
Input : A linear list A with n elements and a searching element lower bound, also called tight bound]
x. Asymptotic notation gives the rate of growth i.e.,
performance, of the run time for "sufficiently large
ALGORITHM ANALYSIS S3-203
input sizes" (i.e., n ® ¥ ) and is not a measure of the We say that the function f (n) = W( g (n))) [read as "f of n is big
particular run time for a specific input size (which
should be done empirically). O-notation is used to "Omega" of g of n"], if and only if there exist two positive constants
express the Upper bound (worst case); W-notation is C and n 0 such that
used to express the Lower bound (Best case) and Q- f (n) ³ C.g (n) : "n ³ n0
Notations is used to express both upper and lower
bound (i.e. Average case) on a function.
We generally want to find either or both an asymptotic
lower bound and upper bound for the growth of our
C.g(n)
function. The lower bound represents the best case No
growth of the algorithm while the upper represents f(n) Matter f(n) = W g(m)
the worst case growth of the algorithm.
F(n)
ASYMPTOTIC NOTATIONS
These notations are used to describe the Running time of an
algorithm, in terms of functions, whose domains are the set of
natural numbers, N = {1, 2, ……}. Such notations are convenient n0
for describing the worst case running time function. T(n) (problem n
size input size). The complexity function can be also be used to
Fig. 2
compare two algorithms P and Q that perform the same task. The
Note that for all values of f(n) always lies on or above g(n).
basic Asymptotic Notations are:
THE NOTATION q (Theta)
1. O(Big-"Oh") Notation. [Maximum number of steps to solve
a problem, (upper bound)] Q-Notation provides simultaneous both asymptotic lower bound
2. W (Big-"Omega") Notation [Minimum number of steps to and asymptotic upper bound for a given function.
solve a problem, (lower bound)] Let f(n) and g(n) are two positive functions, each from the set of
3. q (Theta) Notation [Average number of steps to solve a natural numbers (domain) to the positive real numbers. In some
problem, (used to express both upper and lower bound of a cases, we have f (n) = O( g ( n)) and f = W( g (n)) then
given )f(n)).
f (n) = Q( g (n)) .
THE NOTATION O (BIG 'Oh')
We say that the function f (n) = Q( g (n)) [read as "f of n is Theta"
Big 'Oh' Notation is used to express an asymptotic upper bound
(maximum steps) for a given function f(n). Let f(n) and g(n) are of g of n"], if and only if there exist three positive constants C1, C2
two positive functions, each from the set of natural numbers and n0 such that
(domain) to the positive real numbers. C1 .g (n) £ f (n) £ C2 .g (n) for all n ³ n0 ...(i)
We say that the function f(n) = O (g(n)) [read as "f of n is big "Oh" (Note that this inequality (1) represents two conditions to be
of g of n"], if there exist two positive constants C and N0 such
that satisfied simultaneously viz C1 .g (n) £ f (n) and f (n) £ C2 .g (n);
f (n) £ C.g (n) : "n ³ n0 clearly this implies
if f(n) = O (g (n)) and f = W (g(n)) then f(n) = Q (g(n)).
The intuition behind O-notation is shown in figure-1
The following figure-1 shows the intuition behind the Q-Notation.
c2g(n)
C.g(n)
No f(n)
f(n) Matter c1g(n)
F(n) f(n)
f(n) = q (g(n))
n0
n
Fig. 1 n0
For all values of n to the right of n 0, the value of f(n) is always lies n
on or below Cg(n). Fig. 3
THE NOTATION W (BIG 'Omega') Note that for all values of n to the right of the n0 the value of
O-Notation provides as asymptotic upper bound for a function; f(n) lies at or above C1g(n) and at or below C2.g(n).
W-Notation provides as asymptotic upper bound for a function; Hence inequality (1) simultaneously satisfied for C1 = 1,
W-Notation, provides an asymptotic lower-bound for a given C2 = 2 and n ³ 1 .
function. Hence f(n) = Q (g(n)).
EBD_7203
S3-204 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(ii) We can prove this by contradiction that no value of C1, C2 computational steps required to solve an instance of the
or n0 exist. problem excluding the space allocated to hold the input. In
Let other words, it is only the work space required by the
f(n) = Q (n2) = Þ C1.n2 £ 2n3 + 3n2 + 1 £ C2.n2 for all n ³ n0 algorithm. All definitions of order of growth and asymptotic
...(1) bounds pertaining to time complexity carry over to space
Left side inequality : C1.n2 £ 2n3 + 3n2 + 1; is satisfied for C1 complexity. It is clear that the work space cannot exceed the
= 1 and n ³ 1. running time of an algorithm, as writing into each memory
Right side inequality : 2n3 + 3n 2 + 1 £ C2.n2 cell requires at least a constant amount of time. Thus, if we
Þ n3 £ C2.n2 Þ n £ C2 for all n ³ n0; let T(n) and S(n) denote, respectively, the time and space
But for n = (C2 + 1), this inequality is not satisfied. complexities of an algorithm, then S(n) = O(T(n)).
(c) Worst case and average case analysis
Thus f (n) ¹ Q(n 2 ) .
Consider again Algorithm insertion sort. Let A[1::n] = ( 1; 2;
NOTIONS OF SPACE AND TIME COMPLEXITY : : : ; n), and consider all n! permutations of the elements in
A. Each permutation corresponds to one possible input.
The main objects of study in this field of computational complexity
The running time of the algorithm presumably differs from
include the time and space needed by an algorithm in order to
one permutation to another. Consider three permutations: a
deliver its output when presented with legal input.
in which the elements in A are sorted in decreasing order, c
(a) Order of growth
in which the elements in A are already sorted in increasing
First, when analyzing the running time of an algorithm, we
order and b in which the elements are ordered randomly.
usually compare its behavior with another algorithm that
Thus, input a is a representative of the worst case of all
solves the same problem, or even a different problem. Thus,
inputs of size n, input c is a representative of the best case
our estimates of times are relative as opposed to absolute.
of all inputs of size n and input b is between the two. This
Second, it is desirable for an algorithm to be not only machine
gives rise to three methodologies for analyzing the running
independent, but also capable of being expressed in any
time of an algorithm: worst case analysis, average case
language, including human languages. Moreover, it should
analysis and best case analysis. The latter is not used in
be technology independent, that is, we want our measure of
practice, as it does not give useful information about the
the running time of an algorithm to survive technological
behavior of an algorithm in general.
advances. Third, our main concern is not in small input
sizes; we are mostly concerned with the behavior of the
algorithm under investigation on large input instances. Worst case
n2 /2
In fact, counting the number of operations in some
"reasonable' implementation of an algorithm is more than
what is needed. As a consequence of the third factor above, n2 /4 Average case
Running time
(b) 1 a
a
2 g 3
b
d e
4 c 5 f h 6
c b f
7 d e 8 9 i j 10
Fig 10 : Finding strongly connected components.
Breadth-First Search
Unlike depth-first search, in breadth-first search when we visit a tree edges cross edges
vertex v we next visit all vertices adjacent to v. The resulting tree Figure 11 An example of breadth-first search traversal of an
is called a breadth-first search tree. This method of traversal can undirected graph
be implemented by a queue to store unexamined vertices. Algorithm Time Complexity : The time complexity of breadth-first search
BFS for breadth-first search can be applied to directed and when applied to a graph (directed or undirected) with n vertices
undirected graphs. Initially, all vertices are marked unvisited. The and m edges is the same as that of depth-first search, i.e., Q (n +
counter bfn, which is initialized to zero, represents the order in m). If the graph is connected or m > = n, then the time complexity
which the vertices are removed from the queue. In the case of is simply Q (m).
undirected graphs, an edge is either a tree edge or a cross edge. If
the graph is directed, an edge is either a tree edge, a back edge or SO RTING AND SEARCHING
a cross edge; there are no forward edges. Henceforth, in the context of searching and sorting problems, we
Algorithm for Breadth First Search will assume that the elements are drawn from a linearly ordered
Input : A directed or undirected graph G = (V, E). set, for example the set of integers.
Output: Numbering of the vertices in breadth-first search order. Let A[1..n] be a sequence of n elements. Consider the problem of
1. bfn ¬ 0 determining whether a given element x is in A. This problem can
2. for each vertex v ÎV be rephrased as follows. Find an index j; 1 £ j £ n, such that
3. mark v unvisited x = A[j] if x is in A, and j = 0 otherwise. A straightforward approach
4. end for is to scan the entries in A and compare each entry with x. If after j
5. for each vertex v ÎV comparisons, 1 £ j £ n, the search is successful , i.e., x = A[j], j is
6. if v is marked unvisted then bfs(v) returned; otherwise a value of 0 is returned indicating an
7. end for unsuccessful search. This method is referred to as sequential
Procedure bfs(v) search. It is also called linear search.
1. Q ¬ {v} ALGORITHM LINEAR SEARCH
2. mark v visited Input : An array A [1..n] of n elements of an element x.
Output : j if x = A [j], 1 £ j £ n, and 0 otherwise.
3. while Q ¹ {}
1. i¬1
ALGORITHM ANALYSIS S3-215
2. while (j < n) and ( x ¹ A[ j]) Merging two Sorted Lists
Suppose we have an array A[1..m] and three indices p; q and r,
3. j ¬j+1
with 1 p <q < r <m, such that both the sub arrays A[p..q] and A[q
4. end while
+ 1..r]are individually sorted in nondecreasing order. We want to
5. if x = A [j] then return j else return 0
rearrange the elements in A so that the elements in the subarray
Algorithm binary search gives a more formal description of this
A[p..r] are sorted in nondecreasing order. This process is referred
method.
to as merging A[p..q] with A[q + 1..r]. We maintain two pointers s
Input : An array A [1..n] of n elements sorted in nondecreasing
and t that initially point to A[p] and A[q + 1], respectively. We
order and an element x.
prepare an empty array B[p..r] which will be used as a temporary
Output : j if x = A [j], 1 £ j £ n, and 0 otherwise.
storage. Each time, we compare the elements A[s] and A[t] and
1. low ¬ 1; high ¬ n; j ¬ 0
append the smaller of the two to the auxiliary array B; if they are
2. while (low £ high) and (j = 0)
equal we will choose to append A[s]. Next, we update the pointers:
3. mid ¬ [(low + high)/2]
If A[s] <A[t], then we increment s, otherwise we increment t. This
4. if x = A [mid] then j ¬ mid
process ends when s = q +1 or t = r + 1.
5. else if x < A [mid] then high ¬ mid – 1
Algorithm MERGE
6. else low ¬ mid + 1
Input : An array A[1..m] of elements and three indices p, q and r,
7. end while
with 1 £ p £ q < r £ m, such that both the subarrays A [p..q] and A
8. return j
[q + 1..r] are sorted individually in nondecreasing order.
Example 2 : Suppose that we want to search for x = 35 or x = 100 in
Output : A [p..r] contains the result of merging the two subarrays
A [1..14] =
A [p..q] and A [q + 1..r].
1 4 5 7 8 9 10 12 15 22 23 27 32 35 1. comment : B [p..r] is an auxiliary array.
2. s ¬ p; t ¬ q + 1; k ¬ p
In each iteration of the algorithm, the bottom half of the array is
3. while s £ q and t £ r
discarded until there is only one element :
4. if A [s] £ A [t] then
12 15 22 23 27 32 35 ® 27 32 35 ® 35 . 5. B [k] ¬ A [s]
6. s¬s+1
Therefore, to compute the maximum number of element 7. else
comparisons performed by Algorithm binarysearch, we may 8. B [k] ¬ A [t]
assume that x is greater than or equal to all elements in the array to
9. t¬t+1
be searched. To compute the number of remaining elements in
10. end if
A[1..n] in the second iteration, there are two cases to consider
11. k ¬ k + 1
according to whether n is even or odd. If n is even, then the 12. end while
number of entries in A[mid + 1..n] is n=2; otherwise it is (n -1)/2. 13. if s = q + 1 then B [k..r] ¬ A [t..r]
Thus, in both cases, the number of elements in A[mid +1::n] is
14. else B [k..r] ¬ A [s..q]
exactly (n/2)
15. end if
In general, in the jth pass through the while loop, the number of
16. A [p..r] ¬ B [p..r]
remaining elements is [n/2j–1]. The iteration is continued until Let n denote the size of the array A[p::r] in the input to Algorithm
either x is found or the size of the subsequence being searched
merge, i.e., n = r ¡ p + 1. We want to find the number of comparisons
reaches 1, whichever occurs first. As a result, the maximum number
that are needed to rearrange the entries of A[p::r]. It should be
of iterations needed to search for x is that value of j satisfying the
emphasized that from now on when we talk about the number of
condition. comparisons performed by an algorithm, we mean element
[ n / 2 j -1 ] = 1. comparisons, i.e., the comparisons involving objects in the input
By the definition of the floor function, this happens exactly when data.
Let the two subarrays be of sizes n1 and n2, where n1 + n2 = n.
1 £ n / 2 j -1 < 2, The least number of comparisons happens if each entry in the
or smaller subarray is less than all entries in the larger subarray. For
2 j -1 £ n < 2 j , example, to merge the two subarrays,
or 2 3 6 and 7 11 13 45 57 .
t
j - 1 £ log n < j. the algorithm performs only three comparisons. On the other hand,
Since j is integer, we conclude that the number of comparisons may be as high as n - 1. For example,
j = ëlog nû + 1. to merge the two subarrrays.
We conclude that the maximum number of comparisons in a binary
2 3 66 and 7 11 13 45 57
search is ëlog nû + 1.
seven comparisons are needed. It follows that the number of
comparisons done by Algorithm merge is at least n1 and at most
n -1.
EBD_7203
S3-216 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Selection Sort each element A[i], 2 <i <n, is compared with each entry in the
Let A[1..n] be an array of n elements. A simple and straightforward subarray A[1..i-1]. The number of element comparisons performed
algorithm to sort the entries in A works as follows. First, we find by Algorithm insertion sort is between n-1 and n(n-1)/2.
the minimum element and store it in A[1]. Next, we find the minimum Quicksort
of the remaining n -1 elements and store it in A[2]. We continue This sorting algorithm has an average running time of Q(n log n).
this way until the second largest element is stored in A[n-1]. It is One advantage of this algorithm over Algorithm merge sort is that
easy to see that the number of element comparisons performed by it sorts the elements in place, i.e., it does not need auxiliary storage
the algorithm is exactly for the elements to be sorted.
n -1 n -1 Partitioning algorithm
n ( n - 1)
å ( n - i ) = ( n - 1) + ( n - 2) + ... + 1 = å i =
2
. Let A[low..high] be an array of n numbers, and x = A[low]. We
i =1 i =1 consider the problem of rearranging the elements in A so that all
Input : An array A [1..n] of n elements. elements less than or equal to x precede x which in turn precedes
Output : A [1..n] sorted in non-decreasing order. all elements greater than x. After permuting the elements in the
1. for i ¬ 1 to n – 1 array, x will be A[w] for some w; low £ w £ high. For example, if A
2. k¬ i
= 5 3 9 2 7 1 8 , and low = 1 and high = 7, then after
3. for j ¬ i + 1 to n {Find the ith smallest element}
4. if A[j] < A[k] then k ¬ j
5. end for rearranging the elements we will have 1 3 2 5 7 9 8
6. if k ¹ i then interchange A[i] and A[k] Thus, after the elements have been rearranged, w = 4. The action
7. end for of rearrangement is also called splitting or partitioning around x,
It is also easy to see that the number of element interchanges is which is called the pivot or splitting element.
between 0 and n -1. Since each interchange requires three element Input : An array of elements A [low..high].
assignments, the number of element assignments is between 0 Output : (1) A with its elements rearranged, if necessary, as
and 3(n - 1). The number of element comparisons performed by described above.
Algorithm selection sort is n(n-1)/2. The number of element (2) w, the new position of the splitting element A [low].
assignments is between 0 and 3(n - 1). 1. i ¬ low
Insertion Sort 2. x ¬ A[low]
This algorithm, which is shown below, works as follows. We begin 3. for j ¬ low + 1 to high
with the subarray of size 1, A[1], which is already sorted. Next, 4. if A [j] £ x then
A[2] is inserted before or after A[1] depending on whether it is 5. i ¬i+1
smaller than A[1] or not. Continuing this way, in the ith iteration, 6. if i i ¹ j then interchange A[i] and A[j]
A[i] is inserted in its proper position in the sorted subarray A[1::i 7. end if
-1]. This is done by scanning the elements from index i ¡ 1 down to 8. end for
1, each time comparing A[i] with the element at the current position. 9. interchange A [low] and A[i]
In each iteration of the scan, an element is shifted one position up 10. w ¬ i
to a higher index. This process of scanning, performing the 11. return A and w
comparison and shifting continues until an element less than or The number of element comparisons performed by the above
equal to A[i] is found, or when all the sorted sequence so far is algorithm is exactly n - 1. Thus, its time complexity is Q(n).
exhausted. Sorting Algorithm
Input : An array A [1..n] of n elements. In its simplest form, Algorithm quicksort can be summarized as
Output : A [1..n] sorted in non-decreasing order. follows.The elements A[low::high] to be sorted are rearranged
1. for i ¬ 2 to n using Algorithm split so that the pivot element, which is always
2. x ¬ A[i] A[low], occupies its correct position A[w], and all elements that
3. j¬i–1 are less than or equal to A[w] occupy the positions A[low::w - 1],
4. while (j > 0) and (A[j] > x) while all elements that are greater than A[w] occupy the positions
5. A [j + 1] ¬ A [j] A[w + 1::high]. The subarrays A[low::w - 1] and A[w+1::high] are
6. j¬j–1 then recursively sorted to produce the entire sorted array.
7. end while The formal algorithm is shown as Algorithm quicksort.
8. A [j + 1] ¬ x Input : An array A[1..n] of n elements.
9. end for Output : The elements in A sorted in non-decreasing order.
It is easy to see that the number of element comparisons is minimum 1. quicksort (A, 1, n)
when the array is already sorted in nondecreasing order. In this Procedure quicksort (A, low, high)
case, the number of element comparisons is exactly n - 1, as each 1. if low < high then
element A[i], 2 <i <n, is compared with A[i - 1] only. On the other 2. SPLIT (A [low..high], w) {w is the new position of A[low]}
hand, the maximum number of element comparisons occurs if the 3. quicksort (A, low, w – 1)
array is already sorted in decreasing order and all elements are 4. quicksort (A, w + 1, high)
distinct. In this case, the number of element comparisons is as 4. if A [j] £ x then
5. end if
ALGORITHM ANALYSIS S3-217
Heapsort
(a) i Given an array A[1..n], we sort its elements in nondecreasing order
¯ efficiently as follows. First, we transform A into a heap with the
property that the key of each element is the element itself, i.e.,
5 7 1 6 4 8 3 2
key(A[i]) = A[i], 1 <i <n. Next, since the maximum of the entries in
A is now stored in A[1], we may interchange A[1] and A[n] so that
j A[n] is the maximum element in the array. Now, the element stored
in A[1] may be smaller than the element stored in one of its children.
Therefore, we use Procedure shift-down to transform A[1..n –1]
i into a heap. Next, we interchange A[1] with A[n –1] and adjust the
(b)
¯ array A[1..n –2] into a heap. This process of exchanging elements
and adjusting heaps is repeated until the heap size becomes 1, at
5 1 7 6 4 8 3 2 which point A[1] is minimum.
Input : An array A[1..n] of n elements.
Output : Array A sorted in non-decreasing order.
j
1. MAKEHEAP (A)
2. for j ¬ n down to 2
i 3. interchange A[1] and A[j]
(c)
¯ 4. SIFT-DOWN (A[1..j – 1], 1)
5. end for
5 1 4 6 7 8 3 2 Algorithm heapsort sorts n elements in O(n log n) time and Q (1)
space.
Hashing
j
• The integer h(x) is called the hash value of key x
• A hash table for a given key type consists of
i – Hash function h
(d)
¯ – Array (called table) of size N
• When implementing a dictionary with a hash table,
5 1 4 3 7 8 6 2 the goal is to store item (k, o) at index i = h(k).
Example
• We design a hash table fora dictionary storing items
j
(SSN, Name), where SSN (social security number) is a
nine-digit positive integer
i • Our hash table uses an array of size N = 10,000 and the
(e)
¯ hash function
h(x) = last four digits of x
5 1 4 3 2 8 6 7
Hash Functions
• A Hash function is usually specified as the
j composition of two functions:
– Hash code map:
C : keys ® integers
i Compression map:
(f)
¯ : integers ® [0, N – 1]
2 1 4 3 5 8 6 7 • The hash code map is applied first, and the
compression map is applied next on the result, i.e.,
h(x) = h(c(x))
j • The goal of the hash function is to "disperse" the
keys in an apparently random way
Fig. 2 : An example of Quick sort Algorithm
The running time of Algorithm quicksort is Q(n2) in the worst COLLISION HANDLING
case. If, however, the median is always chosen as the pivot, then • Collisions occur when different elements are mapped
its time complexity is Q (n log n). The average number of to the same cell
comparisons performed by Algorithm quicksort to sort an array of • Collision handling Schemes : collisoin colliding
n elements is Q (n log n). items are stored in a sequence.
– open addresing the colliding item is placed in a
different cell of the table.
EBD_7203
S3-218 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
LINEAR PROBING community to refer to those problems for which there exist
Linear probing handles collisions by placing the colliding item in polynomial time algorithms as tractable, and those for which it is
the next (circularly) available table cell. unlikely that there exist polynomial time algorithms as intractable.
Each table cell inspected is referred to as a "probe" In this topicwe will study a subclass of intractable problems,
Colliding items lump together, causing future collisions to cause a commonly referred to as the class of NP-complete problems. This
longer sequence of Probes. class contains, among many others, hundreds of well-known
Search with Linear Probing problems having the common property that if one of them is
• Consider a hash table A that uses linear probing solvable in polynomial time, then all the others are solvable in
• find Element(k) polynomial time.
– We start at cell h(k) The Class P
– We probe consecutive locations until one of the The class of decision problems P consists of those decision
following occurs problems whose yes/no solution can be obtained using a
– An item with key k is found, or deterministic algorithm that runs in polynomial number of steps,
– An empty cell is found, or i.e., in O (n k) steps, for some nonnegative integer k, where n is the
– N cells have been unsuccessfully probed input size.
Algorithm find Element (k) sorting: Given a list of n integers, are they sorted in nondecreasing
i ¬ h(k) order?
p¬0 set disjointness: Given two sets of integers, is their intersection
repeat empty?
c ¬ A[i] shortest path: Given a directed graph G = (V;E) with positive
if c = Æ weights on its edges, two distinguished vertices and a positive
return NO_SUCH_KEY integer k, is there a path from s to t whose length is at most k?
else if c.key () = k 2-coloring: Given an undirected graph G, is it 2-colorable?, i.e., can
return c. element () its vertices be colored using only 2 colors such that no two
else adjacent vertices are assigned the same color? Note that G is 2-
i ¬ (I + 1) mod N colorable if and only if it is bipartite, that is, if and only if it does
p¬p+1 not contain cycles of odd length.
until p = N We say that a class of problems C is closed under complementation
return NO_SUCH_KEY if for any problem P Î C the complement of P is also in C. For
Performance of Hashing instance, the complement of the 2-colorable? Let us call this
• In the worst case, searches, insertions and removals problem NOT-2-COLOR. We can show that it is in P as follows.
on a hash table take O(n) time. Since 2-COLORING is in P, there is a determinsitic algorithm A
• The worst case occurs when all the keys inserted into which when presented with a 2-colorable graph halts and answers
the dictionary collide yes, and when presented with a graph that is not 2-colorable halts
• The load factor µ = n/N affects the performance of a and answers no. We can simply design a determinsitic algorithm
hash table for the problem NOT-2-COLOR by simply interchanging the yes
• Assuming that the hash values are like random and no answers in Algorithm A. This, informally, proves the
numbers, it can be shown that the expected number of following fundamental theorem :
probes for an insertion with open addressing is 1 / (1 – a) Theorem 10.1 The class P is closed under complementation.
• The expected running time of all the dictionary ADT The Class NP
operatious in a hash table is 0(1) The class NP consists of those problems p for which there exists
• In practice hashing is very fast provided the lead factor a deterministic algorithm A which, when presented with a claimed
is not close to 100% solution to an instance of p, will be able to verify its correctness
• Application of hash tables-small databases compilers in polynomial time. That is, if the claimed solution leads to a yes
Brown caches. answer, there is a way to verify this solution in polynomial time. In
order to define this class less informally, we must first define the
COMPLEXITY OF PROBLEMS concept of a nondeterministic algorithm. On input x, a
NP-complete Problems nondeterministic algorithm consists of two phases
When studying the theory of NP-completeness, it is easier to (a) The guessing phase : In this phase, an arbitrary string
restate a problem so that its solution has only two outcomes: yes of characters y is generated. It may correspond to a
or no. In this case, the problem is called a decision problem. In solution to the input instance or not. In fact, it may
contrast, an optimization problem is a problem that is concerned not even be in the proper format of the desired solution.
with the minimization or maximization of a certain quantity. It turns It may differ from one run to another of the
out that many of the interesting real world problems do not fall nondeterministic algorithm.
into this category, as their solution requires an amount of time (b) The verification phase : In this phase, a deterministic
that is measured in terms of exponential and hyper exponential algorithm defines two things. First, it checks whether
functions, e.g. n!. It has been agreed upon in the computer science the generated solution string y is in the proper format.
ALGORITHM ANALYSIS S3-219
If it is not, then the algorithm halts with the answer no. • NP is the class of decision problems that we can check
If, on the other hand, y is in the proper format, then or verify their solution using a deterministic algorithm
the algorithm continues to check whether it is a that runs in polynomial time.
solution to the instance x of the problem. If it is indeed NP-complete Problems
a solution to the instance x, then it halts and answers The term NP-complete" denotes the subclass of decision
yes; otherwise it halts and answers no. problems in NP that are hardest in the sense that if one of
Example: Consider the problem coloring. We show that this them is proven to be solvable by a polynomial time
problem belongs to the class NP in two ways. deterministic algorithm, then all problems in NP are solvable
(1) The first method is as follows. Let I be an instance of by a polynomial time deterministic algorithm, i.e., NP = P.
the problem coloring. For proving that a problem is NP-complete, we need the
Let s be a claimed solution to I. It is easy to construct a following definition.
deterministic algorithm that tests whether s is indeed a • Definition Let P and P¢ be two decision problems.
solution to I. It follows by our informal definition of the We say that P reduces to P¢ in polynomial time,
class NP that the problem coloring belongs to the class NP.
symbolized as P µ poly P¢ , if there exists a
(2) The second method is to construct a nondeterministic
algorithm for this problem. An algorithm A can easily determinsitic algorithm A that behaves as follows.
be constructed that does the following when presented When A is presented with an instance I of problem P,
with an encoding of a graph G. First, A \guesses" a it transforms it into an instance I¢ of problem P¢ such
solution by generating an arbitrary assignment of the that the answer to I is yes if and only if the answer to
colors to the set of vertices. Next, A verifies that the I¢ is yes. Moreover, this transformation must be
guess is a valid assignment. If it is a valid assignment, achieved in polynomial time.
then A halts and answers yes; otherwise it halts and • Definition A decision problem P is said to be NP-hard
answers no. First, note that according to the definition if for every problem P¢ in NP, P¢ µ poly P .
of a nondeterministic algorithm, A answers yes only if
• Definition A decision problems P is said to be
the answer to the instance of the problem is yes.
NP-complete if
Second, regarding the operation time needed, A spends
(1) P is in NP, and
no more than polynomial time in both the guessing
and verification phases. (2) for every problem P¢ in NP, P¢ µ poly P .
To this end, we have the following distinction between the Thus, the difference between an NP-complete problem P
two important classes P and NP: and an NP-hard problem P¢ is that P must be in the class NP
• P is the class of decision problems that we can decide whereas P¢ may not be in NP. ®
or solve using a deterministic algorithm that runs in
polynomial time.
EBD_7203
S3-220 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. An undirected graph G has n nodes. Its adjacency matrix is 7. A scheme for storing binary trees in an array X is as follows.
given by an n × n square matrix whose (i) diagonal elements Indexing of X starts at 1 instead of 0. The root is stored at
are 0’s and (ii) non-diagonal elements are 1’s. Which one of X[1].For a node stored at X[i], the left child, if any, is stored
the following is true? [2005, 1 mark] in X[2i] and the right child, if any in X[2i | 1]. To be able to
(a) Graph G has no Minimum Spanning Tree (MST) store any binary tree on n vertices the minimum size of X
(b) Graph G has a unique MST of cost n – 1 should be [2007, 2 marks]
(c) Graph G has multiple distinct MSTs, each of cost n – 1 (a) log2 n (b) n
(d) Graph G has multiple spanning trees of different costs (c) 2n + 1 (d) 2n – 1
2. Given two arrays of numbers a1,...an and b1, .... bn where 8. To implement Dijkstra’s shortest path algorithm on
each number is 0 or 1, the fastest algorithm to find the largest unweighted graphs so that it runs in linear time, the data
span (i, j) such that ai + ai + 1 + .... + aj = bi + bi + 1 + .... + bj, structure to be used as [2007, 2 marks]
or report that there is not such span, [2006, 2 marks] (a) queue (b) stack
(a) Takes O (3n) and W (2n) time if hashing is permitted (c) heap (d) B-Tree
(b) Takes O (n3) and W (n2.5) time in the key comparison 9. Consider a weighted complete graph G on the vertex set {v1,
model v2, .... vn} such that the weight of the edge (vi, vj) is 2|i – j|.
(c) Take Q (n) time and space The weight of a minimum spanning tree of G is
[2007, 2 marks]
(d) ( )
Take O n time only if the sum of the 2n elements is (a) n – 1 (b) 2n – 2
an even number
ænö
3. The median of n elements can be found in O(n) time. Which (c) ç ÷ (d) n 2
one of the following is correct about the complexity of quick è2ø
sort, in which median is selected as pivot. [2006, 2 marks] 10. In a binary max heap containing n numbers, the smallest
(a) q(n) (b) q (n log n) element can be found in time [2007, 2 marks]
(c) q (n2) (d) q (n3) (a) O (n) (b) O (log n)
(c) O (log log n) (d) O (1)
4. An element in ann array X is called a leader, if it is greater
11. Consider the polynomial p(x) = a0 + a1x + a2x2 + a3x3, where
than all elements to the right of it in X. The best algorithm to
find all leaders in an array [2007, 2 marks] a i ¹ 0, " i . The minimum number of multiplications needed
(a) solves it in linear time using a left to right pass of the to evaluate p on the input x is [2007, 2 marks]
array (a) 3 (b) 4
(b) solves it in linear time using a right to left pass of the (c) 6 (d) 9
array 12. Consider the following C code segment: [2007, 2 marks]
(c) solves it using divide and conquer in time q (n log n) int Is Prime (n)
{
(d) solves it in time q (n2)
int i, n;
5. Consider the following C program fragment in which i, j and for (i = 2, 9 < = sqrt (n); i + +)
n are integer variables. if (n % i = = 0)
for (i = n, j = 0, i > 0, i/ = 2, j + = i); {printf (“Not Prime\n”); return 0;}
Let val (j) denotes the value stored in the variable j after return 1;
termination of the for loop. Which one of the following is }
true? [2007, 2 marks] Let T(n) denotes the number of times the for loop is executed
(a) val (j) = q (log n) (b) val (j) = q
n by the program on input n. Which of the following is true?
(c) val (j) = q (n) (d) val (j) = q (n log n) (a) T (n) = O ( n ) and T ( n ) = W ( n )
6. Which of the following in place sorting algorithms needs the
minimum number of swaps? [2007, 2 marks] (b) T ( n ) = O ( n ) and T ( n ) = W (1)
(a) Quick sort (b) Insertion sort
(c) Selection sort (d) Heap sort (c) T(n) = O(n) and T ( n ) = W ( n )
(d) None of these
ALGORITHM ANALYSIS S3-221
13. An array of n numbers is given, where n is an even number. 21. The maximum number of binary trees that can be formed with
The maximum as well as the minimum of these n numbers three unlabelled nodes is [2007, 1 mark]
needs to be determined. Which of the following is true about (a) 1 (b) 5
the number of comparisons needed? [2007, 2 marks] (c) 4 (d) 3
(a) At least 2n – c comparisons, for some constant c, are 22. The height of a binary tree is the maximum number of edges
needed in any root to leaf path. The maximum number of nodes in a
(b) At most 1.5n – 2 comparisons are needed binary tree of height h is [2007, 1 mark]
(c) At least nlog2 n comparisons are needed (a) 2h – 1 (b) 2h–1 – 1
(d) None of the above (c) 2h + 1 – 1 (d) 2h + 1
14. Let w be the minimum weight among all edge weights in an 23. We have a binary heap on n elements and wish to insert n
undirected connected graph. Let e be a specific edge of more elements (not necessarily one after another) into this
weight w. Which of the following is false? [2007, 2 marks] heap. The total time required for this is [2008, 2 marks]
(a) There is a minimum spanning tree containing e (a) Q (log n) (b) Q (n)
(b) If e is not in a minimum spanning tree T, then in the (c) Q (n log n) (d) Q (n2)
cycle formed by adding e to T, all edges have the same 24. You are given the postorder traversal, P, of a binary search
weight. tree on the n elements 1, 2, ..., n. You have to determine the
(c) Every minimum spanning tree has an edge of weight w unique binary search tree that has P as its postorder traversal.
(d) e is present in every minimum spanning tree. What is the time complexity of the most efficient algorithm
15. Consider the process of inserting an element into a Max for doing this? [2008, 2 marks]
Heap, where the Max Heap is represented by an array. (a) Q (log n)
Suppose we perform a binary search on the path from the (b) Q (n)
new leaf to the root to find the position for the newly inserted (c) Q (n log n)
element, the number of comparisons performed is (d) None of the above, as the tree cannot be uniquely
[2007, 2 marks] determined
(a) Q (log2 n) (b) Q (log2 log2 n) –3
(c) Q (n) (d) Q (n log2 n) b e
16. A complete n-array tree is a tree in which each node has n 2 2
children or no children. Let l be the number of internal nodes 1 –5 1 1
and L be the number of leaves in a complete n-array tree. If L 25. a c h f
= 41, and l = 10, what is the value of n? [2007, 2 marks] 2 3 2 3
(a) 3 (b) 4 2 g
d
(c) 5 (d) 6
17. In an unweighted, undirected connected graph, the shortest Dijkstra’s single source shortest path algorithm when run
path from a node S to every other node is computed most from vertex a in the above graph, computers the correct
efficiently, in terms of time complexity, by [2007, 2 marks] shortest path distance to [2008, 2 marks]
(a) Dijkstra’s algorithm starting from S (a) only vertex (b) vertices a, e, f, g, h
(b) Warshall’s algorithm (c) vertices a, b, c, d (d) all the vertices
(c) Performing a DFS starting from S 26. The subset-sum problem is defined as follows: Given a set S
(d) Performing a BFS starting from S of n positive integers and a positive integer W, determine
18. Consider a hash table of size seven, with starting index zero, whether there is a subset of S whose elements sum to W.
and a hash function (3x + 4) mod 7. Assuming the hash table An algorithm Q solves this problem in O (nW) time. Which
is initially empty, which of the following is the contents of of the following statements is false? [2008, 2 marks]
the table when the sequence 1, 3, 8, 10 is inserted into the (a) Q solves the subset-sum problem in polynomial time
table using hashing? Note that ‘–’ denotes an empty location when the input is encoded in unary
in the table. [2007, 2 marks] (b) Q solves the subset-sum problem in polynomial time
(a) 8, _, _, _, _, _, 10 (b) 1, 8, 10, _, _, _, 3 when the input is encoded in binary
(c) 1, _, _, _, _, _, 3 (d) 1, 10, 8, _, _, _, 3 (c) The subset sum problem belongs to the class NP
19. The inorder and preorder traversal of a binary tree are (d) The subset sum problem is NP-hard.
d b e a f c g and a b d e c f g, respectively 27. Consider the Quick sort algorithm. Suppose there is a
The postorder traversal of the binary tree is [2007, 2 marks] procedure for finding a pivot element which splits the list
(a) d e b f g c a (b) e d b g f c a into two sub-lists into two-sub-lists each of which contains
(c) e d b f g c a (d) d e f g b c a at least one-fifth of the elements. Let T(n) be the number of
20. Which of the following sorting algorithm has the lowest comparisons required to sort n elements. Then
worst-case complexity? [2007, 1 mark] (a) T ( n ) £ 2T ( n / 5) + n [2008, 2 marks]
(a) Merge sort (b) Bubble sort
(c) Quick sort (d) Selection sort (b) T ( n ) < 2T ( n / 5) + T ( 4n / 5) + n
EBD_7203
S3-222 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ìn , n£3
ï
T (n) = í æ n ö
ïT ç 3 ÷ + cn, otherwise
î è ø
Which one of the following represents the time complexity
EBD_7203
S3-224 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
47. What will be the output of the following C program segment? m = m – 1
char inChar = ‘A’; [2012, 2 marks] }
switch (inChar) { }
case ‘A’ : prinf(“Choice A\n”); What is the worst case time complexity of a sequence of
case ‘B’ : n queue operations on an initially empty queue?
case ‘C’ : printf (“Choice B’): [2013, 2 Marks]
case ‘D’ : (a) Q(n) (b) Q(n + k)
case ‘E’ : (c) Q(nk) (d) Q(n2)
default : printf (“No Choice”);}
(a) No choice 53. Consider the following function:
(b) Choice A int unknown (int n) {
(c) Choice A choice B No choice int i, j, k=0;
(d) Program gives no output as it is erroneous for (i=n/2; i<=n; i++)
48. Which one of the following is the tightest upper bound for (j=2; j<=n; j=j*2)
that represents the number of swaps required to sort n k = k + n/2;
numbers using selection sort? [2013, 1 Mark] return (k);
(a) O(log n) (b) O(n) }
(c) O(n log n) (d) O(n2) The return value of the function is
[2013, 2 Marks]
49. Which one of the following is the tightest upper bound (a) Q(n2) (b) Q(n2 log n)
that represents the time complexity of inserting an object (c) Q(n3) (d) Q(n3 log n)
into a binary search tree of n nodes? [2013, 1 Mark]
(a) O(1) (b) O(log n)
(c) O(n) (d) O(n log n) 54. Consider the DFA A given below.
1
50. Which of the following statements are true?
1. The problem of determining whether there exists a
cycle in an undirected graph is in P. 1
2. The problem of determining whether there exists a
cycle in an undirected graph is in NP.
3. If a problem A is NP-complete, there exists a
non-deterministic polynomial time algorithm to solve 0 0
A. [2013, 1 Mark]
(a) 1, 2 and 3 (b) 1 and 2 only
(c) 2 and 3 only (d) 1 and 3 only
51. What is the time complexity of Bellman-Ford single-
source shortest path algorithm on a complete graph of n
vertices? [2013, 1 Mark]
2 2
0, 1
(a) Q(n ) (b) Q(n log n)
Which of the following are false?
(c) Q(n3) (d) Q(n3 log n) 1. Complement of L(A) is context-free.
52. Consider the following operation along the Enqueue
2. L(A) = L((11*0+0) (0+1)*0*1*).
and Dequeue operations on queues, where k is a global
3. For the language accepted by A, A is the minimal
parameter.
DFA.
Multi-Dequeue(Q){
4. A accepts all strings over {0, 1} of length at least 2.
m = k
[2013, 2 Marks]
while (Q is not empty) and (m > 0){ Dequeue(Q)
(a) 1 and 3 only (b) 2 and 4 only
(c) 2 and 3 only (d) 3 and 4 only
ALGORITHM ANALYSIS S3-225
1. Consider the graph in figure Draw the red-black tree after insertion of 12 into the tree.
1 2 3 (a) (b)
17 30
The third row in transitive closure of the above graph is 10 30 17 35
(a) 1, 1, 1 (b) 1, 1, 0
(c) 1, 0, 0 (d) 0, 1, 1 8 13 19 35 19
2. The minimum number of colours needed to colour a graph 10
having n(> 3) vertices and 2 edges is 12 13
(a) 3 (b) 4 8
(c) 2 (d) 1 12
3. Which of the following number of nodes can have a full
binary tree? (c) (d) None of the above
(a) 8 (b) 15 17
(c) 13 (d) 14
4. Consider this undirected graph and using Prim’s algorithm. 10 30
Construct a minimum spanning tree starting with node A.
8 13 19 35
49
B E
12
10 10 2
30
A 22 C G 7. The average total path length of a randomly built binary
search tree with n nodes is
7 4 5 (a) d (log2 n) (b) d (n log2n)
26
(c) d (n2) (d) d (n2 log2n)
D F
22 8. Consider the graph in which of the following is a valid
strong component?
5. For the undirected, weighted graph given below, which of A B
the following sequences of edges represents a correct (a) a, c, d
execution of Prim’s algorithm to construct a minimum
(b) a, b, d
spanning tree?
5 10 (c) b, c, d
a d g
1 3 (d) a, b, c D C
b 6 f 7 i 9. Let G be an undirected connected graph with distinct
3 8 edges weight. Let Gmax be the edge with maximum weight
6 8 and Gmin, the edge with minimum weight. Which of the
c e h following statements is false?
7 12
(a) Every minimum spanning tree of G must contain Gmin
(a) (a, b), (d, f), (f, c), (g, i), (d, a), (g, n), (c, e), (f, h) (b) If Gmax is in minimum spanning tree, then its removal
(b) (c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i) must disconnect G
(c) (d, f), (f, c), (d, a), (a, b), (c, e), (f, n), (g, h), (g, i) (c) No minimum spanning tree contains Gmax
(d) (h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e) (d) G has a unique minimum spanning tree
6. Consider the red-black tree in the adjoining figure. 10. Consider the directed weighted graph below:
30 Black node B
41 6 12 22
9
Red node A C
10 35 2 12
6
8 17 D E
5
15 10
13 19 7 F
EBD_7203
S3-226 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
We are interested in the shortest paths from A. What is the topological sorting of the given graph?
1. Output the sequence of vertices (a) ABCD (b) ABDC
— Identified by the Dijkstra’s (c) ADCB (d) BCDA
— Algorithm for snyti source shortest_path where 18. what is the order of the binary search algorithm?
the algorithm is stated at node A. (a) log n (b) n 2
2. Write down sequence of vertices in the shortest path (c) n log n (d) n 3
from A to E 19. A machine took 200 s to sort 200 names, using bubble
3. What is the cost of the shortest path from A to E? sort, in 800 s. How many names it can sort?
11. Let G be a directed graph whose vertex set is the set of (a) 500 (b) 600
numbers from 1 to 100. There is an edge from a vertex (c) 400 (d) 800
i to a vertex j, if either j = i + 1 or j = 3i. The maximum 20. A mchine needs a minimum of 100 s to sort 1000 names
number of edges in a path in G from vertex 1 to vertex v by quick sort what is the minimum time needed to sort 100
are names?
(a) 25 (b) 26 (a) 7.1 (b) 8.0
(c) 10 (d) 23 (c) 5.0 (d) 6.7
13. Consider the following graph : 21. Consider the hash table of size 11 that uses open
addressing with linear probing. Let h(k) = k mod 11 be the
a hash function used. A sequence of records with keys 43
36 92 87 11 47 11 13 14 is inserted into an initially empty
hash table, the bins of which are indexed from zero to ten,
c b f
what is the index of the bin into which the last record is
inserted?
h (a) 8 (b) 7
(c) 10 (d) 4
g
22. Consider a hash function that distributes keys uniformly.
What is the sequence of depth first traversals of the The hash table size is 20. After hashing of how many keys
above graph? will the probability that any new key hashed collides with
(a) abcghf (b) abfhgc an existing one exceed?
(c) afghbc (d) All of these (a) 10 (b) 7
14. Which of the following is true? (c) 5 (d) 4
1. In a DFS of undirected graph, every edge of G is 23. A sorting technique that guarantees, that records with the
either a tree edge or a cross edge. same primary key occurs in the same order in the sorted
2. In a DFS of graphs, if v is a disconnected of u then, list as in the original unsorted list is said to be
when u is disconnected, there must exists a path (a) stable (b) consistent
from u to v consisting entirely of gray vertices (c) external (d) linear
(a) 1 only (b) 2 only 24. The average number of comparisons performed by the
(c) Both (d) None of these merge sort algorithm, in merging two sorted lists of length
15. The problem of finding the set of vertices reachable from 2 is
a given vertex in a graph can be solved in time (a) 8/3 (b) 8/5
(a) O (|v|2) (b) O (|v| + |E|) (c) 11/7 (d) 11/16
(c) O (|V| |E|) (d) intractable 25. Consider a hashing function that resolves collision by
16. Which of the following is false? quadratic probing. Assume the address space is indexed
(i) An edge (u, v) is a forward edge if and only if from 1 to 8. Which of the following locations will never
d[u] £ d [v] £ f [v] £ f [u] be probed if a collision occurs at positions 4
(ii) An edge (u, v) is a cross edge if and only if (a) 4 (b) 5
d [u] < f [u] < d [v] < f [v] (c) 8 (d) 2
(iii) An edge (u, v) is a back edge if and only if 26. The time complexity of computing the transitive closure of a
d [v] < d [u] < f [u] < f [v] binary relation on a set of n element is known to be
(a) (i) and (iii) (b) (ii) and (iii)
(c) (iii) only (d) All of these (a) O (n) (b) O (n log n)
17. Consider the graph in figure: (c) O (n3/2) (d) O (n3)
(a) 10, 8, 7, 5, 3, 2, 1 (b) 10, 8, 7, 2, 3, 1, 5 36. Which of the following statements are TRUE?
(1) The problem of determining whether there exists a cycle
(c) 10, 8, 7, 1, 2, 3, 5 (d) 10, 8, 7, 3, 2, 1, 5
in an undirected graph is in P.
28. How many distinct binary search trees can be created out of (2) The problem of determining whether there exists a cycle
4 distinct keys? in an undirected graph is in NP.
(a) 5 (b) 14 (3) If a problem A is NP-Complete, there exists a non-
deterministic polynomial time algorithm to solve A.
(c) 24 (d) 42 (a) 1,2 and 3 (b) 1 and 2 only
29. In a complete k-array tree, every internal node has exactly k (c) 2 and 3 only (d) 1 and 3 only
children. The number of leaves in such a tree with n internal 37. Which one of the following is the tightest upper bound that
nodes is represents the time complexity of inserting an object into a
binary search tree of n nodes?
(a) nk (b) (n – 1) k + 1
(a) O(1) (b) O(log n)
(c) n(k – 1) + 1 (d) n (k – 1) (c) O(n) (d) O(n log n)
38. Which one of the following is the tightest upper bound that
ænö represents the number of swaps required to sort n numbers
30. Suppose T(n) = 2T ç ÷ + n, T(0) = T(1) = 1
è 2ø using selection sort?
(a) O(log n) (b) O(n)
Which one of the following is false? (c) O(n log n) (d) O(n^2)
(a) T(n) = O(n)2 (b) T(n) = q (n log n) 39. Which of the following statements is/are TRUE for an
undirected graph?
(c) T (n) = W (n2) (d) T(n) = O (n logn)
P: Number of odd degree vertices is even
31. Let G(V, E) be an undirected graph with positive edge weights. Q: Sum of degrees of all vertices is even
Dijkstra’s single source shortest path algorithm can be (a) P Only (b) Q Only
implemented using the binary heap data structure with time (c) Both P and Q (d) Neither P nor Q
complexity 40. Consider the following two functions. What are time
(a) O (|V|2) (b) O(|E| | + |V| + log |V|_ complexities of the functions?
int fun1(intn)
(c) O (|V| log |V|) (d) O((|E| + |V|_ log |V|) {
32. Suppose there are [log n] sorted lists of [n/log n_] elements if(n <= 1) returnn;
each. The time complexity of producing a sorted list of all return 2*fun1(n-1);
these elements is }
int fun2(int n)
(Hint: Use a heap data structure)
{
(a) O (n log log n) (b) q (n log n) if(n <= 1) return n;
return fun2(n-1) + fun2(n-1);
(c) W (n log n) (d) W (n3/2)
}
33. Which of the following statements is/are TRUE for an
(a) O(2^n) for both fun1() and fun2()
undirected graph? (b) O(n) for fun1() and O(2^n) for fun2()
P: Number of odd degree vertices is even (c) O(2^n) for fun1() and O(n) for fun2()
Q: Sum of degrees of all vertices is even (d) O(n) for both fun1() and fun2()
(a) P Only (b) Q Only
41. Match the following
(c) Both P and Q (d) Neither P nor Q
Group A Group B
34. Consider an undirected random graph of eight vertices. The
(1) Dijkstra's single (p) Dynamic Programming
probability that there is an edge between a pair of vertices is shortest path algo
1/2. What is the expected number of unordered cycles of (2) Bellmen Ford's single (q) Backtracking
length three? shortest path algo
(a) 1/8 (b) 1
(3) Floyd Warshell's all (r) Greedy Algorithm
(c) 7 (d) 8
pair shortest path algo.
35. What is the time complexity of Bellman-Ford single-source
(a) 1-r, 2-q, 3-p (b) 1-p, 2-p, 3-p
shortest path algorithm on a complete graph of n vertices? (c) 1-r, 2-p, 3-p (d) 1-p, 2-r, 3-q
(a) Q (n2) (b) Q (n2 Logn)
(c) Q (n )3 (d) Q (n3 Logn)
EBD_7203
S3-228 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Common Data for Questions 42 and 43: 42. The running time of f1 (n) and f2 (n) are
Consider the following C functions : (a) Q (n) and Q (n) (b) Q (2n) and Q(n)
int f1 (int n) (c) Q (n) and Q (2n) (d) Q (2n) and Q (2n)
{ 43. f1 (8) and f2 (8) return the values
if (n == 0 || n == 1) (a) 1661 and 1640 (b) 59 and 59
return n; (c) 1640 and 1640 (d) 1640 and 1661
else Statements for Linked Answer Questions 44 and 45:
return (2*f 1 (n – 1) + 3* f 1(n – 2)); The subset-sum problem is defined as follows. Given a set of n
} positive integers, s = {a1, a2, a3, ...., an}, and positive integer W,
int f2 (int n) is there a subset of S whose elements sum to W? A dynamic
program for solving this problem uses a 2-dimensional Boolean
{
array, X with n rows and W + 1 columns. X [i, j],
int i;
1 £ i £ n, 0 £ j £ W , is true if and only if there is a subset of {a1,
int X[N], Y[N], Z[N];
a2, .... ai} whose elements sum to j.
X[0] = Y[0] = Z[0] = 0
X[1] =1; Y[1] = 2; Z[1] = 3; 44. Which of the following is valid for 2 £ i £ n and a i £ j £ W ?
for (i = 2; i < = n; i++) { (a) X[i, j] = X[i – 1, j] Ú X[i, j – ai]
X[i] = Y[i – 1] + Z[i – 2]; (b) X[i, j] = X[i – 1, j] Ú X[i – 1, j – ai]
Y[i] = 2*X[i ]; (c) X[i, j] = X[i – 1, j] Ù X[i, j – ai]
Z[i] = 3*X[i ]; (d) X[i, j] = X[i – 1, j] Ù X[i – 1, j – ai]
} 45. Which entry of the array X, if true, implies that there is a
return X[n]; subset whose elements sum to W?
} (a) X [1, W] (b) X [n, 0]
(c) X[n, W] (d) X[n – 1, n]
ALGORITHM ANALYSIS S3-229
PAST GATE QUESTIONS EXERCISE 5. (c) Here after every iteration the value of i=i/2, & j is the
summation of these i till i reaches to 1.
1. (c) correctly solved
n
Given adjacency matrix of order 4 is 4*4 j = n + n / 2 + n / 2 2......n / 2 log 2
0 0 1 1 1 Sum of this series.
1 1 0 1 1 Would give ø(n) order.
2 1 1 0 1 6. (a) Heap is implemented using array & to find maximum or
3 1 1 1 0 minimum element in array we take only n maximum
comparison.
So complexity is ø(n)
7. (b) Right child & left child of element X[i] are shared in
array at X[2i+1] &X[2i] respectively & index is at X[1]
& X[2] & X[3] are its child. So till index 3 we stored 3
There can be many min spaning but all of n – 1 cost elements & so on. So we require the array of size n to
store n elements.
8. (c) Heap is used to implement Dijakstra’s shortest path
algorithm on unweighted graphs so that it runs on
linear time because of the property of heap discussed
below.
Heap is a data structures that allows the following:
1. Add: Heap allows the addition of an element with some
So on. priority associated with each element.
2. (c) Given that each number of 0 or 1. 2. Remove: The element with the highest priority is
Now, to achieve removed and returned.
ai + ai + 1 + ... + aj = bi + bi + 1 + ... + bj 3. Peak : Heap increases the priority of an element to the
We need to find the sum total of LHS and RHS and highest without removing the element from the list.
then have to compare. Now, to implement a heap, take a list of elements and
We need to do this from very starting like first we need according to the priority. The highest priority is O(n)
to check. time to implement the Dijakstra’s shortest path algorithm
Whether a1 = b1 on unweighted graphs.
If not then whether a1 + a2 = b1 + b2 9. (b) The minimum spanning tree is formed when
And so on .... Vi ¬ {1, 2, ....}
This will take n comparisons. Lets construct a tree on the basis of
Therfore, the fastest algorithm to find the largest span (vi, vj) is 2|i – j|
takes Q (n) time and space. Considering the maximum value (n) to be 4.
3. (c) In quick sort the piuot is found in logn time & this runs v1
for n times. So complexity of Quick sort is 0(nlogn) but 2 |2 – 1| 2 |3 – 2|
since given the median as piuot found in 0(n)
v2 v3
So for n elements to sort this algorithm will take 0(n2)
4. (c) In quick sort (divide & conquer) algorithm after every 2 |4 – 3|
run we being 1 element at its right place i.e. all the
v4
elements in the left are smaller & in the right are greater
As Vi is connected to Vi + 1,
than it.
The minimum weight of each edge = 2
So we can apply quick sorts divide & conquer method Therefore, the weight of tree with n – 1 edges
of complexity 0(nlogn) to do this, to check whether all = 2(n – 1) = 2n – 2.
elements in right are smaller than it or not.
EBD_7203
S3-230 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
10. (a) Time taken by binary max heap to identify the max BFS starting from S, traverses all the adjacent nodes,
element is O(1). Therefore, the time taken by binary & then their adjacent nodes, this calculates shortest
max heap to identify the smallest element is O(n).
path with min complexity. Hence (D) is correct option
11. (a) The minimum number of multiplications can be found
out by simplifying the given expression 18. (b) As given,
p(x) = a0 + x(a1 + a2x + a3x^2) Size of the hash table is 7.
® p(x) = a0 + x(a1 + (a3x + a2)x) Starting index = 0
Here we can see three multiplications Now, hash function h(x) = (3x + 4) mod 7
1. a3 *x ® h(x) = (3x + 4) mod 7
2. x(a2 + a3x) ® h(1) = (3.1 + 4) mod 7
3. x * (a1 + x(a2 + a3x)) h(1) = 7 mod 7 = 0 at the 0th location
Similarly, h(3) = 6th location
12. (b) The loop runs from 2 to n . So maximum iterations can
and h(8) = 0th location
be n. Since, 0th position is already occupied then the location
When n = 2 loop has only 1 iteration so. 1 &n are lower will be next location to it. So, h(8) will be 1st location.
& upper bounds respectively. Also h(10) = 6th location and the 6th position is
W(1) <= T(n) <= 0(n) occupied, so h(10) is hashed to 2nd position.
Diagrammatically.
13. (b) One possible way to do this is we select first element
as max & also min. Then we compare it with all others. 0 1
At most this would take 2n comparisons during linear 1 8
search. But if we use divide & conquer as for merge 2 10
sort we have. 3 –
T(n) 2T(n/2) + 2 for n > 2 4 –
T(n) = 3n/2 -2 5 –
= 1.5n – 2 6 3
14. (d) Minimum weight w 19. (a) In order d b e a f c g
Edge e preorder a b d e c f g
Weight w 1st element of pre order is root
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.
Now, when the edge, e is added to the minimum tree we
get a circuit. in preorder b is before d e. & c is before f g.
Therefore, to avoid the circuit, e cannot be included in
the minimum spanning tree.
15. (a) In a Max heap we insert 1 element this takes 0 (1) time
debfgca
since it is an array. Now to find correct position we
perform Binary search, & we know BS an array takes
20. (a) The complexities of worst case when all the elements
0(log2n) time
are reverse sorted for all algorithms are.
So (A) is correct option.
Norge 0(nlog2n)
16. (c) Each internal node has n children & so total nodes I#n
Quick 0( )
No. of leaf in them
Selection 0( )
I* n - 1
Bubble 0( )
I(n - 1)
Merge no has no effect of input nature since it keeps
But root can’t produce leaf
on dividing into
I(n - 1) + 1 = L
2 problems of size 4/2 so complexity is lower then other
n = L-1/ l + 1
three.
n=(41 -1 )/10 +1 =5
21. (b) It is given that n = 3
17. (d) Since the graph is unweighted and undirected so no
sense in using Dijikstra or Warshall also their
1 2n
n +1
(
Cn )
complexities are 0(n2) &0(n3)respectively.
ALGORITHM ANALYSIS S3-231
3 +1
( )
1 6
C3
So their sorted order would be in order. Using both
BST can be constructed in a linear scan. So it will take
1.6! only 4n time.
=5
4 ´ 3!3! 25. (d) We apply Dijkstra Algorithm.
Therefore, there are 5 trees that can be formed with
three unlabelled node.
1
2
Order a be f c h g d
a ® b= 1 ac= 3 ab= 6 ®
ae = ® 2 af= 0 a ® g = 3
ah ® = 2
3 4
n! ³ C2n for n £ n 0
Let us assume C = 1 and n = 4
24 ³ 24
³ 16
® g(n) = W (f(n)) ® second result
Therefore, the two results are
Statement (B), (C) & (D) are correct. h(n) = O(f(n)); g(n) = W (f(n))
32. (c) Applying BFS algorithm on the following figure
M N O
R Q P
min cent has 3 edges.
Let start form Q
Two edge & vertex disjoint paths are present can be
® Q comes in queue first
seen in two spanning trees but option (A) is false for Changing the status of the Q’s child to 1
K=2 2K – 2= i.e 2 edges Queue obtained, Q | M | N | P
should be there but it is not true. Changing the status of the M’s child to 1
Queue obtained, Q | M | N | P | R
29. (a) In B tree the data is stored at leaves only a particular
Changing the status of the N’s child to 1
node can have maximum. 3 keys, so when 4th insertion Queue obtained Q | M | N | P | R | O
comes first split is required, during 7th second split & The queue’s final status is as per the table below
so on, so for 10 insertions max. 3 splits are required.
Q M N O P R
We can prove it mathematically.
2 1 1 1 1
No. of split < = 1 + logm/2[n/2]
2 2 1 1 1
Here m order = 4 n = 10 b = 3
2 2 2 1 1 1
K <= 1+ log2 [10/3] = 1 + log 2[4]
K<= B
30. (b) Since all the elements are sorted so we can apply binary M N O
s 0 8 –4 7
2
7 7, s 2, t
9
y z
After pass 1
t 5 x
6 ¥
6 –2
–3 Weight = 1 + 1 + 2 + 3 = 7
8 45. (b) Min possible path from B to C so we draw all paths
s 0 –4 7
2 from B to C
7 ¥
B ¾® C = 12
7, s
9 B ¾® AC = 1 + 8 = 9
y z
After pass 2 B ¾® EC = 9 + 3 = 12
ALGORITHM ANALYSIS S3-235
THEORY OF COMPUTATION
O Ø
Ø
Context free languages and Push-down automata
N
T
E
N
T
S
EBD_7203
S3-240 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ALPHABET AND STRINGS
An alphabet is a finite non-empty set of symbols. It is denoted by a letter å.
• å = {0, 1} is a binary alphabet.
• å = {A, B, ........, Z; a, b, c, ........., z} is an english alphabet.
A string over an alphabet å is a sequence of any number of symbols from å.
• 0, 1, 11, 00 and 011 are strings over {0, 1}.
• Hey, Hello and Hi are strings over english alphabet.
If w is a string over å, the length of w, written as | w| is the number of symbols
that it contains
• Let å = {a, b, ..........., z}.
• |hello| = 5; |hey| = 3; |hi| = 2.
The string of length zero is called the empty string and is written as e. In other
words, e is a string containing no symbol.
OPERATIO NS ON STRINGS
1. Concatenation
Let string x of length a and string y of length b, the concatenation of x and
y, written as xy, is the string obtained by appending y to the end of x, as in
x1 x2, ........ xa y1 y2, ...... yb. and the length of concatenated string will be a + b.
• å being English alphabet, Hello. John = Hello John.
The concatenation of string x for n times, where n ³ 0 is denoted by xn.
• x0 = e, x1 = x, x2 = xx, .............
2. Substring
Let x and y be strings over an alphabet å. The string x is called substring of
y if there exist strings m and n over å such that y = mxn, m and n can be empty
strings. e is a substring of every string and for every string x, x is a substring
of x itself.
• e, concat, nation and concatenation are substring of concatenation.
3. Reverse
The reverse of string x, written as xr is the string obtained by writing x in the
opposite order.
• (hello)r = olleh; (concatenation)r = noitanetacnoc
The set of strings created from any number of symbols in an alphabet å
is denoted by å*.
• Let å = {0, 1}, å* = {e, 0, 1, 00, 01, 10, 11, .........}.
The set of strings created from at least one symbol in an alphabet å is
denoted by å+.
• Let å = {0, 1}, å+ = {0, 1, 00, 01, 10, 11, ............}.
L A NG U A G E
A language over an alphabet å is a set of strings over å. Let å = {0, 1} be the
alphabet.
• Le = {w Î å*| the number of 1’s in w is even}
The above language Le contains all the strings over å having even number
1’s. e, 0, 00, 11, 000, 101, 110, 1111, 0000, 1100, 0011, ............ are in Le.
BASIC operations like Complementation, Union, Intersection, Concatenation
can be applied on languages. We will look into it afterwards.
FINITE AUTOMATA
A finite automata is a 5-tuple (Q, å, d, q0, F), where
1. Q is a non-empty finite set called states.
2. å is a non-empty finite set called alphabet.
3. d : Q × å ® Q is the transition function.
4. q0 Î Q is the start state.
5. F Í Q is the set of accept states.
THEORY OF COMPUTATION S3-241
Let’s have a look at the diagram below, also called state diagram.
State diagram represents an automation say M. M is having three states, labelled q1, 0 1
q2, q3 which is nothing but Q = {q1, q2, q3}. The start state, q1 is indicated by the
arrow pointing at it from nowhere. The accept state, q2, is the one with a double circle. 1 0
The arrows going from one state to another are called transitions. When this automation q1 q q3
2
receives an input string, it processes that string and produces an output. The output
0, 1
is either accept or reject. If after reading the last symbol of string, automation is at
accept state then the output is accept, otherwise rejected. State diagram
For example, when the input is feeded at string 1101 to the machine M shown above,
the processing proceeds as follows:–
1. Start in state q1.
2. Read 1, follow transition from q1 to q2.
3. Read 1, follow transition from q2 to q2.
4. Read 0, follow transition from q2 to q3.
5. Read 1, follow transition from q3 to q2.
6. ACCEPT because M is in accept state q2 at the end.
Formally the above machine can be written as M = (Q, å, d, q1, F) where,
® Q = {q1, q2, q3} 0 1
® å = {0, 1} q1 q1 q 2
® d is described as
q 2 q3 q 2
® q1 is the start state, and
q3 q 2 q 2
® F = {q2}
• If A is the set of all strings that machine M accepts, we say that A is the
language of machine M and write L(M) = A. We say the M recognizes A or
that M accepts A.
• A machine may accept several strings, but it always recognizes only one
language. If the machine accepts no strings, it still recognizes one language
called empty language f.
• In the previous example,
A = {w|w contains at least one 1 and an even number of 0 s follow the last
1}.
• A language is called regular language if some finite automation recognizes it.
Language A defined above is a regular language because M recognizes A.
Designing Finite Automata (DFA)
Let’s look at a simple example to understand how to design an automation. Suppose
that the alphabet is {0, 1} and that the language consists of all strings with an odd
number of 1’s. We have to construct a finite automation M to recognize this language.
To construct the automation for this language, remember one thing that whether the
number of 1’s seen so far is even or odd and keep track of this information as read
new symbols. If you read 1, flip the answer, but if you read a 0, leave the answer as
it is. After this, we evaluate what are the finite list of possibilities. Here there are two.
One is when number of 1’s are even and other when they are odd. Now we assign
a state to each of the possibilities, say qeven and qodd. Next you need to assign the
transitions by seeing how to go from one possibility to another upon reading a
symbol. So, if state qeven represent the even possibility and qodd represent odd
possibility, you would set the transition to flip state on a 1 and stay put on is 0.
Finally, start state will be the state qeven because initially there are 0 number of 1’s
0 0
and 0 is an even number. Accept state will be qodd because you have to accept when
you have seen an odd number of 1s. In figure is the corresponding automata. 1
Note: In GATE examination, you will be asked either to determine the string accepted q even qodd
by automation or the correct design of automation for a given string. 1
EBD_7203
S3-242 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example 1. Consider a following deterministic finite state automaton M
1 0 0, 1
q0 0 q1 0 q2 1 q3
Let S denotes the set of seven bit binary string S in which the first, the fourth
and the last bits are 1. The number of string in S theat are accepted by M is
(a) 1 (b) 5
(c) 7 (d) 8
Sol. (c) The string S will be defined as
1xy1zw1 (7 digits)
Here, the values of x, y, z and w can be either 0 or 1.
As shown in figure the machine will jump to next state only after the receiving
input 0 or 1. So, the next value will be 0 thus S is fixed to
(replacing x) 10 y 1 z w 1 (State q1)
or (replacing x) 11 y 1 z w 1 (state q0)
For sequence 10 y z w 1 the machine is on state q2. Thus, we have two values
of S that is
(replacing y) 1001 z w 1 (State q3)
or (replacing y) 1011 z w 1 (State q0)
For string 1001 z w 1 the string will be
(replacing y) 1101 z w 1 (State q0)
or (replacing y) 1111 z w 1 (State q0)
For string 1001 z w (State q3) the machine is on state q3. Thus, the next string
will be
(replacing z) 10010 w 1 (State q3)
(replacing z) 10011 w 1 (State q3)
For string 1011 z w 1 (State q0)
The value of z can be only 0 otherwise the machine will not reach to final state
thus the string S will be
(replacing z) 10110 w 1 (State q1)
and 1111001 S (replacing z, w) for string 100 10w (state q3) teh value of w
will be so that the machine could reach final state. Thus, the string will be
(replacing z, w) 1001011 S
For string 10011 w 1 (State q3) the machine is on state q3. So, it is on final
state and the input w can be either 0 or 1. As both transactions are available
on final state. Thus, the string can be
or 1001101 S
1001111 S
Non-Deterministic Finite Automata (NFA)
So far, every step of a computation follows in a unique way from the preceding step.
When the machine is in a given state and reads the next input symbol, we know the
next state (using transition), i.e. it is determined. This is called deterministic computation.
In a non-deterministic machine, several choices may exist for the next state at any
THEORY OF COMPUTATION S3-243
point. Also, the automation can choose to make a transition from one state to another
without reading any symbol. This type of transition is shown below.
q1 e q2
0 1 e
q1 { q1} { q1, q 2 } f
q2 { q3 } f { q3 }
q3 f {q 4 } f
q4 {q4 } {q 4 } f
q1 1 q2 0, e q3 1 q4
a
E
a
E
E
E
b
a
E
a E E
E
b
b a
e
a 2 3
a, b
q0 q1
0/b
State Input 0
Next state Output
® q0 q1 a
q1 q0 b
Input
0 1
State
Next Next
Output Output
state state
q1 q3 0 q2 0
q2 q1 1 q4 0
q3 q2 1 q1 1
q4 q4 1 q3 0
Sol. Here, if any stae have same output for all input values like in our example, q1
state have output 1 only for both 0 and 1 input. thus, the state will be written
as it is. If state has different output for different input like for state q2 for input
0 output is 1 and for input 1 output is 0. In this case state q2 will be divided
in i parts. Where it is total number of inputs. Here q2 will be divided into two
parts q20 and q21. q20 will define the output 0 and q21 will define the output
1. Same thing will be done for state q4. Thus, the transition table will be written
as
State 0 1 Output
q1 q3 q2 1
q 20 q1 q 40 0
q 21 q1 q 40 1
q3 q 21 q1 0
q 40 q 41 q3 0
q 41 q 41 q3 1
Example 3. Convert the folllowing Moore machine into Mealy machine.
State 0 1 Output
q1 q1 q2 0
q2 q1 q3 1
q3 q1 q3 1
Sol. The conversion is simple. Copy the output associated with each state to the
place where state is written. Thus, the example output of q1 state is 0.
Thus, q, × 0 will generate the output 0.
And output of q2 state is then the transaction
q1 × 1 ® q2 will generate the output 1.
q1 × ® 1
And the new transaction table will be
State 0 1
Next state Output Next state Output
q1 q1 0 q2 1
q2 q1 0 q3 1
q3 q1 0 q3 1
Example 4. Convert the following Mealy machine into Moore machine.
0/z1 0/z2
q1 q2
0/z1
1/z1 1/z1
q1
1/z2
EBD_7203
S3-248 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Sol. The transition table of given Mealy machine will be as
State 0 1
Next state Output Next satate Output
q1 q2 z1 q3 z1
q2 q2 z2 q3 z1
q3 q2 z1 q3 z2
The corresponding Moore machine will be
0 1 Output
q1 q2z 1 q2z 1 z1
q2z 1 q2z 2 q3z 1 z1
q2z 2 q2z 2 q3z 1 z2
q3z 1 q2z 1 q3z 2 z1
q3z 2 q2z 1 q3z 2 z2
0
0 0
q 1/ ^ q2z1/z1 q2z2/z2
0
1
1
0 1
q3z2/z2 q3z2/z1 1
1
Example 5. Construct a minimum automaton equivalent to finite automaton described
by
State 0 1
® q0 q1 q5
q1 q6 q2
q2 q0 q2
q3 q2 q6
q4 q7 q5
q5 q2 q6
q6 q6 q4
q7 q6 q2
Sol. Step 1 Make separate set of final states and non-final states, i.e.,
{q0, q1, q3, q4, q5, q6, q7} {q2}
Step 2 Further in a given set check whether for two given state, the next state
for a given input belongs to same set. If yes then keep these two states in
same set. Other wise, these two state will be in different set. For example, states
q0 and q1 form set 1. State q1 for input 0 and q1 generates q6 for input 0.q1
and q6 belongs to same set. Now for input 1 q0 generates q5 and q1 generates
q2. q5 and q2 are in different set. q0 and q1 will be in different set.
Here, notice that q1 generates q1 for input 0 and q5 for input 1. q1 and q5 both
are intermediate states and belongs to set 1. Thus, all states that generate
intermediate states for both inputs 0 and 1 will be in set of q0 thus we will
have the 1 set as
{q0, q4, q6}
Next q1 generates state q6 for input 0 which is intermediate state and generates
state q2 for input 1 which intermediate state for input 0 and any final state for
input 1 will be set of q1, thus we will have a set
{q1, q7}
Similarly, q3 generates q2 for input 0 which belongs to set 2 and generate q6
THEORY OF COMPUTATION S3-249
for input 1 which belongs to set 1. Thus, all states that generate any state that
belongs to set 2 for input ‘0’ and any state that belongs to set 1 for input 1
will be in set of q3. Thus, we get set as
{q3, q5}
Thus, in next step we will get the set as
{ q0, q4, q6}, {q1, q7}, {q3, q5}, {q2} Þ Q2'
Applying the previously described process of this newly generated set Q2' ,
we get
{q0, q4} {q6} {q1, q7} {q3, q5}, {q2} Þ Q3'
By applying the same process, we get
{q0, q4} {q6} {q1, q7} {q3, q5} {q2} Þ Q4'
Q3' = Q4'
Thus, Q’ = [{q0, q4} {q6} {q1, q7} {q3, q5} {q2}]
The transaction table will be
State 0 1
® {q0, q4} {q1, q7} {q3, q5}
{q6} {q6} {q2}
{q1, q6} {q6} {q2}
{q3, q5} {q2} {q6}
{q 2} {q0, q4} {q2}
Here, the state q0 or q4 will be represented as {q0, q4} the state q3 or q5 will
be represented as {q3. q5} and state q1 or q7 or q5 will be represented as
{q3, q5} and state containing q0 will be represented as {q1, q7} the state
containing q0 will be considered as initial state and the state containing any
final state will be considered as final state.
CLOSURE PRO PERTI ES OF REGULAR LA NGUAGES
Regular languages are closed under the following operations:–
1. Union ® If A1 and A2 are regular, then A1 È A2 is also regular.
2. Intersection ® If A1 and A2 are regular, then A1 Ç A2 is also regular.
3. Concatenation ® If A1 and A2 are regular, then A1 o A2 is also regular.
4. Star ® If A is regular language, then A* is also regular.
REGU LA R EX PRESSI ON
The regular expressions are useful for representing certain sets of string in an
algebraic fashion. Formal definition of regular expressions is as follows:–
1. Any terminal symbol, i.e. symbols å including ^ and f are regular expression.
When, we view a in å as a regular expression, we denote it by a.
% % %
2. The union of two regular expressions R1 and R2 written as R1 + R2 also a
regular expression.
3. The concatenation of two regular expressions R1 and R2 written as R1 R2 is
also a regular expression.
4. The iteration of a regular expression R, written as R* is also a regular expression.
5. If R is a regular expression, then (R) is also a regular expression.
6. The regular expression over å are precisely those obtained successively by
the application of the rules 1 to 5 once or several times.
In regular expressions, the order of operation is closure (*), concatenation (•)
and then union (+).
For example, below are the regular expressions and their corresponding regular
language.
EBD_7203
S3-250 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
® 0*10* = {w| w contains a single 1}
® 1*(01*)* = {w| every 0 in w is followed by at least one 1}
® å*1å* = {w| w contains at least one 1}
Any regular expression can be converted into a finite automation that recognizes the
language, it describes and vice versa. Some basic conversions from regular expression
to finite automation (M) are shown below:–
• If r = e, M is
e
s f or s
• If r = f, M is s
S1 f1 r1
e
s
e r2
S2 f2
• If r = r1 . r2, then M is
S1 f1 e S2 f2
r1 r2
• If r = r1, then M is
e
e r1
S S1 f1
e
Using the above basic rules / examples, any regular expression can be converted into
a finite automata.
Let’s look at an example for better understanding
r = (ab È a)*
To convert the regular expression (ab È a)* into a finite automation, we will first
convert the regular expressions that are combined to get this one.
a a o
b
b o
a e b
ab o
a e b
e o
ab È a e
a
o
e
a e b
e o
(ab È a)* e
o e
a o
e
THEORY OF COMPUTATION S3-251
In this way, we can build NFA from a regular expression. Now let’s convert a DFA
into a regular language. For converting this, we have to follow a very simple procedure
shown below:–
R2
R1
qj
R3
qr R1R2*R 3 È R4 qr
qi qi
R4
We have to remove states one by one to get only two states and therefore
corresponding regular expression. Also, first we have to add two extra states, one
start and one accept. Then we can start removing other states. For example,
s 1 a
1 a
b Two extra
b
states
2 a, b e
a 2 aÈ b
s e a
s 1
a* b (a È b)* b (a È b)*
a
a
We assume implicity that the alphabet å does not contain the six symbols
e 0/ ( ) | *
Then, concretely speaking, the regular expressions over Î form a certain set
of strings over the alphabet obtained by adding these six symbols to Î.
However it makes things more readable if we adopt a slightly more abstract
syntax, dropping as many brackets as possible and using the convention that
– * binds more tightly than – –, binds more tightly than – | –.
So, for example, r|st* means (r|s(t)*), not (r|s)(t)*, or ((r|st))*, etc.
• u matches a Î å iff u = a
• u matches e iff u = e
• no string matches
• u matches r|s iff u matches either r or s
• u matches rs iff it can be expressed as the concatenation of two
strings, u = vw, with v matching r and w matching s
• u matches r* iff either u = e , or u matches r, or u can be expressed
as the concatenation of two or more strings, each of which matches
r
a
q1 q2
b
a b a
q3 b q4
a, b
Ecample 11. Construct the finite4 automata for regular expression (0 + 1)* (00 + 11)
( 0 + 1)*
(0 + 1)* (00 + 11)* (0 + 1)*
(0 + 1)*
(0 + 1)*
00 + 11
Þ
THEORY OF COMPUTATION S3-255
(0.1)*
(0 + 1)*
00 11
Þ
(0 + 1)* 0 0 (0 + 1)*
Sol.
1
1
Slide 31
Examples
def
(i) L1 = {anbn | n ³ 0} is not regular.
[for each l ³ 1,a f b f Î L1 is of length ³ l and has property (†) on
Slide 31.]
def
(ii) L2 = {w Î {a, b}* | w a palindrome} is not regular.
[For each l ³ 1, afbaf Î L1 is of lenght ³ l and has property (†).]
Terminals:
x ¢ + – * ( )
Non-terminals:
id op exp
Start symbol:
exp
Productions:
id ::= x | id¢
op ::= + | – | *
exp ::= id | exp op exp | (exp)
THEORY OF COMPUTATION S3-257
Push Down Automata
Push Down Automata are like non-deterministic finite automata but have an extra
component called a stack. The stack provides additional memory beyond the finite
automata provides.
Formally, a push down automata is a 6-tuple (Q, å, G, d, q0, F), where
1. Q is the set of states.
2. å is the input alphabet.
3. G is the stack alphabet.
4. d : Q × åe × Ge ® P (Q × Ge) is the transition function.
5. q0 Î Q is the start state, and
6. F Í Q is the set of accept states.
Below is the description of PDA that recognizes the language {0n 1n | n ³ 0}. Let M1
be (Q, å, G, d, q1, F), where
Q = {q1, q2, q3, q4}
å = {0, 1}
G = {0, $} $ = This signifies that stack is empty
F = {q1, q4} and
d is given by the following table, where in blank entries signify f.
Input 0 1 e
Stock 0 $ e 0 $ e 0 $ e
q1 {(q2, $)}
q2 {(q2, 0)} {(q3, e )}
q3 {(q3, e )} {(q4, e )}
q4
q1 e, e ® $ q2 0, e ® 0
1, 0 ® e CFL
q4 q3 1, 0 ® e
e, $ ® e
Regular
Languages
• A language is context free if and only if some push down automata recognizes
it.
• Every regular language is context free language.
q7
1 0 1 0 1 1 1 0 U U U ........
• The above diagram shows a TM with configuration 10101q7 110.
Let C1 and C2 be configuration of M. C1 yields C2 if M is in configuration
C2 after running M in configuration C1 for one step. Suppose d(q1, b) = (q2,
C, L), then aaq1 bb yields aq2 acb. Let w Î å* and M be a turing machine.
M accepts w if there are configs Co, Ci, ..........., Ck, s.t.
— Co = q0 w
— Ci yields Ci + 1 for i = 0, ........., k-1, and
— Ck contains the accept state qaccept.
• A Turing Machine M recognizes a language L if M accepts exactly those
strings in L.
• A language L is called recognizable or recursively enumerable if some TM
recognizes L.
• A TM decides a language L if M accepts all strings in L and rejects all strings
not in L.
• A language is called decidable or recursive if some TM decides L.
• L is decidable if and only if both L and Ø L are recognizable.
Example 12: Construct a Turing machine which will accept the set of strings over
å = {a, b} beginning with a ‘a’ and ending with a ‘b’.
Sol: M = (k, å, G, d, q0, F) where
a b a b b ........ x x a b b ........
K = {q0, q1, q2, q3}; F = {q3}
å = {a, b}; G = {a, b, X, b }
d is defined as follows:– q0 q2
d (q0, a) = (q1, X, R) x b a b b ........ x x x b b ........
d (q1, a) = (q1, X, R)
d (q1, b) = (q2, X, R) q1 q1
d (q2, a) = (q1, X, R) x x x x b ........ x x x x b ........
d (q2, b) = (q2, X, R)
d (q2, b ) = (q3, halt) q2 q3
THEORY OF COMPUTATION S3-259
Let us see how the machine accepts abab.
It can be seen that after initially reading ‘a’, the machine goes to state q1.
Afterwards, if it sees a ‘a’ it goes to state q1; if it sees ‘b’ it goes to q2. Hence
when it sees the leftmost blank symbol, if it is in state q2, it accepts as this
means that the last symbol read is a ‘b’.
Multitape Turing Machines
A multitape turing machine is like an ordinary turing machine with several tapes. The
transition function is changed to allow for reading, writing and moving the heads on
some or all of the tapes simultaneously.
• Every multitape turing machine has an equivalent single-tape turing machine.
Closure Properties of Recursive Languages
• If L is a recursive language over å, the L is recursive.
• If L1 and L2 be recursive languages over å. Then L1 È L2 is recursive.
• If L1 and L2 be recursive languages over å. The L1 Ç L2 is recursive.
Closure Properties of Recursively Enumerable Languages
• If L1 and L2 are recursively enumerable languages over å.
Then L1 È L2 is also recursively enumerable.
Regular Context Decidable Turing
• If L1 and L2 are recursively enumerable languages over å. Free Recognizable
Then L1 Ç L2 is also recursively enumerable.
• If L is a recursive language, then L is recursively enumerable.
• Relationship among classes of languages is shown below:–
Halting Problem
• If a machine loops on input <M, w>, i.e. M loops on w, then this machine does
not decide the corresponding language. If the algorithm had some way to
determine that M was not halting on w, it could reject. Hence, this type of
problem is called halting problem. In other words, language is undecidable.
• A language is decidable if it is Turing-recognizable and co-Turing-recognizable.
(We say this if it is the complement of a Turing-recognizable language).
EBD_7203
S3-260 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Consider the following two problems on undirected graphs: 6. Consider the machine M: [2006, 1 mark]
a — Given, G (V, E), does G have an independent set of size a
|V| – 4? b b
b — Given, G (V, E), does G have an independent set of size 5? a b b
Which one of the following is true? [2006, 1 mark]
(a) a is in P and b is NP-complete a a
(b) a is NP-complete b is in P
(c) Both a and b are NP-complete a, b
(d) Both a and b are in P
2. Consider the languages: [2006, 1 mark] The language recognized by M is
L1 = {WWR | W Î {0, 1)*} (a) {W Î (a, b)* | every a in W is followed by exactly two
L2 = {W # WR | W Î {0, 1)*} where # is a special symbol b’s}
L3 = {W W | W Î {0, 1)*} (b) {W Î (a, b)* | every a in W is followed by at least two
Which one of the following is true? b’s}
(a) L1 is a deterministic CFL (c) {W Î (a, b)* | W contains the substring abb}
(b) L2 is a deterministic CFL (d) {W Î (a, b)* | W does not contain aa as a substring}
(c) L3 is a CFL but not a deterministic CFC 7. Consider three decision problems P1, P2 and P3. It is known
(d) L3 is a deterministic CFL that P1 is decidable and P2 is undecidable. Which one of the
3. Let L1 be a recursive language, and let L2 be a recursively following is true? [2006, 1 mark]
enumerable but not a recursive language. Which one of the (a) P3 is decidable if P1 is reducible to P3
following is true? [2006, 1 mark] (b) P3 is undecidable if P3 is reducible to P2
(c) P3 is undecidable if P2 is reducible to P3
(a) L1 is recursive and L2 is recursively enumerable (d) P3 is decidable if P3 is reducible to P2’s complement
(b) L1 is recursive and L2 is not recursively enumerable 8. Consider the regular language L = (111 + 111111)*. The
minimum number of states in any DFA accepting this language
(c) L1 and L2 are recursively enumerable is [2006, 1 mark]
(a) 3 (b) 5
(d) L1 is recursive enumerable and L2 is recursive (c) 8 (d) 9
4. Consider the languages [2006, 1 mark] 9. Let L1 be a regular language, L2 be a deterministic context-
free language and L3 a recursively enumerable but not
{ } {
L1 = a n b n cm | n, m > 0 and L2 = a n b m cm | n, m > 0 } recursive language. Which one of the following statements
is false? [2006, 1 mark]
Which one of the following statements is false? (a) L1 Ç L2 is a deterministic CFL
(a) L1 Ç L2 is a context-free language (b) L2 Ç L1 is recursive
(b) L1 È L2is a context-free language (c) L1 Ç L2 is context-free
(c) L1 and L2 are context-free language (d) L1 Ç L2 Ç L3 is recursively enumerable
(d) L1 Ç L2 is a context-sensitive language 10. Consider the following statements about the context-free
5. Let Nf and Np denote the classes of languages accepted by grammar: [2006, 1 mark]
non-deterministic finite automata and non-deterministic push- G = {S ® SS, S ® ab, S ® ba, S ® Î}
down automata, respectively. Let Df and Dp denote the classes 1. G is ambiguous.
of languages accepted by deterministic finite automata and 2. G produces all strings with equal number of a’s and b’s.
deterministic push-down automata respectively. Which one 3. G can be accepted by a deterministic PDA.
of the following is true? [2006, 1 mark]
Which combination below expresses all the true statements
(a) Df Ì Nf and Dp Ì Np about G?
(b) Df Ì Nf and Dp = Np (a) 1 only (b) 1 and 3
(c) Df = Nf and Dp = Np
(c) 2 and 3 (d) 1, 2 and 3
(d) Df = Nf and Dp Ì Np
THEORY OF COMPUTATION S3-261
11. Let SHAM3 be the problem of finding a Hamiltonian cycle in 17. The minimum state automation equivalent to the above FSA
a graph G = (V, E) with |V| divisible by 3 and DHAM3 be the has the following number of states [2007, 2 marks]
problem of determining if a Hamiltonian cycle exists in such (a) 1 (b) 2
graphs. Which one of the following is true? [2006, 1 mark] (c) 3 (d) 4
18. Which of the following languages is regular?
(a) Both DHAM3 and SHAM3 are NP-hard
(b) SHAM3 are NP-hard but DHAM3 is not
(c) DHAM3 is NP-hard, and SHAM3 is not
(a) {WW | W Î{0,1} }
R +
[2007, 2 marks]
(d) L is regular 19. The language L = {0i21i | i ³ 0} over the alphabet {0, 1, 2} is
13. If s is a string over (0 + 1)* then let n 0(s) denotes the number (a) not recursive [2007, 2 marks]
of 0’s in s and n1(s) the number of 1’s in s. Which one of the
(b) is recursive and is a deterministic CFL
following languages is not regular? [2006, 1 mark]
(c) is a regular language
(a) L = {s Î (0 + 1)* | n0(s) is a 3-digit prime}
(b) L = {s Î (0 + 1)* | for every prefix s¢ of s, (d) is not a deterministic CFL but a CFL
| n0(s¢) – n1(s¢) £ 2} 20. A minimum state deterministic finite automaton accepting
(c) L = {s Î (0 + 1)* | n0(s) – n1(s)| £ 4 the language L = {W | W Î {0, 1}*, number of 0’s and 1’s in
(d) L = {s Î (0 + 1)* | n0(s) mod 7 = n 1(s) mod 5 = 0} W are divisible by 3 and 5, respectively as. [2007, 2 marks]
14. Let L1 = {0n+m1n0m |n, m ³ 0}, L2 = {0n+m1n + m0m |n, m ³ 0},
and L3 = {0n+m1n + m 0n + m |n, m ³ 0}. Which of these (a) 15 states (b) 11 states
languages is/are not context free? [2006, 1 mark] (c) 10 states (d) 9 states
(a) L1 only (b) L3 only 21. Which of the following is true? [2007, 1 mark]
(c) L1 and L2 (d) L2 and L3
15. Let S be an NP-complete problem and Q and R be two other (a) Every subset of a regular set is regular
problems not known to be in NP. Q is polynomial time (b) Every finite subset of a non-regular set is regular
reducible to S and S is polynomial time reducible to R. Which
(c) The union of two non-regular sets is regular
one of the following statements is true? [2006, 1 mark]
(a) R is NP-complete (b) R is NP-hard (d) Infinite union of finite sets is regular
(c) Q is NP-complete (d) Q is NP-hard 22. Which of the following problems is undecidable?
Common Data for Questions 16 and 17 :
(a) Membership problem for CFGs [2007, 1 mark]
Consider the following Finite State Automation:
(b) Ambiguity problem for CFGs
q3 (c) Finiteness problem for FSAs
(d) Equivalent problem for FSAs
a b 23. Which of the following are regular sets? [2008, 2 marks]
b b 1. {nm }
a n b 2m | n ³ 0, m ³ 0
a b 2. {a n bm | n = 2m}
q0
a
q1
a
q2
3. {a b | n ¹ m}
4. {xcy | x, y,Î {a, b} *}
(a) 1 and 4 (b) 1 and 3
16. The language accepted by this automation is given by the
regular expression [2007, 2 marks] (c) 1 only (d) 4 only
(a) b * ab * ab * ab (b) (a + b)* 24. Match the List I with List II and select the correct answer
(c) b* a (a + b)* (d) b * ab * ab * using the codes given below the lists. [2008, 2 marks]
EBD_7203
S3-262 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
List I List II (c) (d)
a b a b
E. Checking that P. L = {an b mcn d m |m ³ 1, m, ³ 1|}
identifiers are ®P Q S ®P S Q
declared before their
F. Number of formal Q. X ® XbX | XcX | dxf | g Q R S Q S R
parameters in the
R(F) Q P R(F) Q P
declaration of a
function agrees with S Q P S Q P
the number of actual
parameters in use of
27. Which of the following statements is false? [2008, 2 marks]
(a) Every NFA can be converted to an equivalent DFA
that function
(b) Every non-deterministic turing machine can be
G. Arithmetic R. L = {WcW | W Î (a | b)*} converted to an equivalent deterministic turing machine
expressions with (c) Every regular language is also a context-free language
matched pairs of (d) Every subset of a recursively enumerable set is
parentheses recursive
H. Palindromes S. X ® bXb |cXc| e
28. If L and L are recursively enumerable, then L is
(a) E - P, F - R, G - Q, H - S [2008, 1 mark]
(b) E - R, F - P, G - S, H - Q (a) regular (b) context-free
(c) E - R, F - P, G - Q, H - S (c) context-sensitive (d) recursive
(d) E - P, F - R, G - S, H - Q 29. Which of the following are decidable? [2008, 1 mark]
25. Which of the following statements are true? [2008, 2 marks] 1. Whether the intersection of two regular languages is
1. Every left-recursive grammar can be converted to a infinite.
right-recursive grammar and vice-versa. 2. Whether a given context-free language is regular.
2. All e-productions can be removed from any context- 3. Whether two push-down automata accept the same
free grammar by suitable transformations. language.
4. Whether a given grammar is context-free
3. The language generated by a context-free grammar all
(a) 1 and 2 (b) 1 and 4
of whose productions are of the form X ® W or X ®
(c) 2 and 3 (d) 2 and 4
WY (where, W is a string of terminals and Y is non- 30. Which of the following is true for the language {ap | p is a
terminal), is always regular. prime}? [2008, 1 mark]
4. The derivation trees of strings generated by a context- (a) It is not accepted by a turning machine
free grammar in Chomsky Normal Form are always (b) It is regular but not context-free
binary trees. (c) It is context-free but not regular
(a) 1, 2, 3 and 4 (b) 2, 3 and 4 (d) It is neither regular nor context-free, but accepted by a
(c) 1, 3 and 4 (d) 1, 2 and 4 turing machine
26. Given below are two finite state automata (® indicates the 31. 1
start state and F indicates a final state) [2008, 2 marks] 0
0 0
a b a b
®1 1 2 ®1 2 2 1
Y: Z:
The above DFA accepts the set of all strings over {0, 1} that
2 (F) 2 1 2 (F) 1 1
(a) begin either with 0 or 1 [2009, 2 marks]
Which of the following represents the product automation (b) end with 0
Z × Y? (c) end with 00
(d) contain the substring 00
(a) (b)
a b a b 32. Let L1 = L1 Ç L 2 , where L1 and L2 are languages as defined
below
®P Q R ®P S Q
Q R S Q R S
{ }
L1 = a m b m c a n b n | m, n ³ 0
{ }
List I List II
L1 = 0p1q | p, q Î N [2011, 2 marks]
P. Regular expression 1. Syntax analysis
L3 = {0 p1q 0 r | p, q, r Î N and p = q = r}
S. Register a llocation 4. Code optimization
(a) P - 4, Q - 1, R - 2, S - 3 (b) P - 3, Q - 1, R - 4, S - 2
(c) P - 3, Q - 4, R - 1, S - 2 (d) P - 2, Q - 1, R - 4, S - 3 Which of the following statements is not true?
35. Which one of the following is false? [2009, 1 mark] (a) Push Down Automata (PDA) can be used to recognize
(a) There is unique minimal DFA for every regular language L1 and L2
(b) Every NFA can be converted to an equivalent PDA (b) L1 is a regular language.
(c) Complement of every context-free language is recursive (c) All the three languages are context-free
(d) Every non-deterministic PDA can be converted to an (d) Turning machines can be used to recognize all the
equivalent deterministic PDA languages
36. Which one of the following languages over th e 43. A deterministic finite automation (DFA)D with alphabet c
alphabet {0 1} is described by the regular expression (0 + 1) = {a, b} is given below. [2011, 2 marks]
* 0(0 + 1) * ? [2009, 1 mark]
(a) The set of all strings containing the substring 00
b b a, b
(b) The set of all strings containing at most two 0’s p q r
(c) The set of all strings containing at least two 0’s
(d) The set of all strings that begin and end with either 0 or 1.
37. S ® aSa |bSb| a | b; The language generated by the above a a
grammar over the alphabet {a, b} is the set of
[2009, 1 mark] a, b a, b
(a) all palindromes s t
(b) all odd length palindromes
(c) strings that begin and with the same symbol Which of the following finite state machines is a valid minimal
(d) all even length palindromes DFA which accepts the same language as D?
38. Let W be any string of length n in {0, 1}*. Let L be the set of (a)
b b a, b
all sub-strings of W. What is the minimum number of states p q r
in a non-deterministic finite automaton that accept L?
[2010, 2 marks]
a a
(a) n – 1 (b) n
(c) n + 1 (d) 2n – 1
a, b
EBD_7203
S3-264 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
a, b (a) (b) bd + bc
s bd
(b) (c) bd + abcd (d) bd + bc + cd
a, b b 48. A list of n strings, each of length n, is sorted into lexicographic
p q
a order using the merge-sort algorithm. The worst case running
time of this computation is [2012, 2 marks]
r a, b (a) O (n log n) (b) O (n2 log n)
(c) O (n2 + log n) (d) O (n2)
a, b 49. The worst case running time to search for an element in a
(c) a, b
a, b balanced binary search tree with n2n elements is
b
p q r [2012, 1 mark]
(a) Q (n log n) (b) Q (n2n)
(d)
b (c) Q (n) (d) Q (log n)
p q 50. The recurrence relation capturing the optimal execution time
of the Towers of Hanoi problem with n discs is
[2012, 1 mark]
a a (a) T(n) = 2T (n – 2) + 2 (b) T(n) = 2T (n – 1) + n
(c) T(n) = 2T (n/2) + 1 (d) T(n) = 2T (n – 1) + 1
s a, b 51. Let W(n) and A(n) denote respectively, the worst case and
average case running time of an algorithm executed on an
44. Definition of a language L with alphabet {a} is given as
input of size n. Which of the following is always true?
following and n is a positive integer constant. What is the
[2012, 1 mark]
minimum number of states needed in a DFA to recognize L ?
(a) A(n) = W (W(n)) (b) A(n) = Q (W(n))
[2011, 2 marks]
(c) A(n) = O (W(n)) (d) A(n) = o (W(n))
(a) k + 1 (b) n + 1
(c) 2n + 1 (d) 2k + 1 52. Consider the languages L1 = F and L2 = {a}. Which one
45. Which of the following pairs have different expressive of the following represents L1 L2* È L1*?
power? [2011, 1 mark]
(a) Deterministic Finite Automata (DFA) and Non- [2013, 1 Mark]
deterministic Finite Automata (NFA) (a) {e} (b) F
(b) Deterministic Push Down Automata (DPDA) and Non- (c) a* (d) (e, a)
deterministic Push Down Automata (NPDA)
(c) Deterministic single-tape turing machine and non- 53. Which of the following statements is/are false?
deterministic single tape turing machine 1. For every non-deterministic Turing machine, there
(d) Single-tape turing machine and multi-tape turing exists an equivalent deterministic Turing machine.
machine 2. Turing recognisable languages are closed under
46. Let P be a regular language and Q be a context free language union and complementation.
such that Q Í P . For example, let P be the language 3. Turing decidable languages are closed under
represented by the regular expression p*q* and Q be intersection and complementation.
4. Turing recognisable languages are closed under
( Qn pn qn n Î N ) . Then which of the following is always union and intersection. [2013, 1 Mark]
(a) 1 and 4 only (b) 1 and 3 only
regular? [2011, 1 mark]
(c) 2 only (d) 3 only
(a) P Ç Q (b) P – Q 54. Which of the following is/are undecidable?
(c) å * - P (d) å * - Q 1. G is a CFG. Is L(G) = F?
47. What is the minimal form of the Karnaugh map shown below? 2. G is a CFG. Is L(G) = å*?
Assume that X denotes a don’t care term. [2012, 2 marks] 3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
ab [2013, 2 Marks]
cd 00 01 11 10
(a) 3 only (b) 3 and 4 only
00 1 X X 1 (c) 1, 2 and 3 only (d) 2 and 3 only
55. Which one of the following is TRUE ?
01 X 1
[2014, Set-1, 1 Mark]
11 (a) The language L = {anbn| ³ 0} is regular..
(b) The language L = {an| n is prime} is regular.
10 1 X (c) The language L = {w | w has 3k + 1b's for some k Î N
with S = {a, b}} is regular.
(d) The language L = {ww | wÎ S* with S = {0, 1}} is
regular.
THEORY OF COMPUTATION S3-265
56. Consider the finite automaton in the following figure. 60. Let A £ m B denotes that language A is mapping reducible
(also known as many-to-one reducible) to language B. Which
0,1 1 one of the following is FALSE?
[2014, Set-2, 1 Mark]
q0 1 q1 0,1 q2 0,1 q3 (a) If A £m B and B is recursive then A is recursive.
(b) If A £m B and A is undecidable then B is undecidable.
Which is the set of reachable states for the input string (c) If A £m B and B is recursively enumerable then A is
0011? [2014, Set-1, 1 Mark]
recursively enumerable.
(a) { q0, q1, q2} (b) {q0, q1}
(c) {q0, q1, q2, q3} (d) {q3} (d) If A £m B and B is not recursively enumerable then A
57. Let L be a language and L be its complement. Which one is not recursively enumerable.
of the following is NOT a viable possibility? 61. Let < M > be the encoding of a Turing machine as a string
[2014, Set-1, 2 Marks] over S = {0, 1}. Let L = {<M>| M is a Turing machine that
accepts a string of length 2014}. Then, L is
(a) Neither L nor L is recursively enumerable (r.e.). [2014, Set-2, 2 Marks]
(b) One of L and L is r.e. but not recursive; the other is (a) decidable and recursively enumerable
not r.e. (b) undecidable but recursively enumerable
(c) Both L and L are r.e. but not recursive. (c) undecidable and not recursively enumerable
(d) decidable but not recursively enumerable
(d) Both L and L are recursive.
62. Let L1 = {w Î {0, 1}*| w has at least as many occurrences of
58. Which of the regular expressions given below represent the (110)’s as (011)’s}. Let L2 = {w Î{0, 1}* | w has at least as
following DFA? [2014, Set-1, 2 Marks] many occurrences of (000)’s as (111)’s}. Which one of the
0 1 following is TRUE? [2014, Set-2, 2 Marks]
0
(a) L1 is regular but not L2
(b) L2 is regular but not L1
(c) Both L1and L2 are regular
1 (d) Neither L1 nor L2 are regular
63. The length of the shortest string NOT in the language (over
I 0*1(1+00*1)*
S= {a, b}) of the following regular expression is
II 0*1*1+11*0*1
______________. [2014, Set-3, 1 Mark]
III (0+1)*1
a*b* (ba)*a*
(a) I and II only (b) I and III only
(c) II and III only (d) I, II, and III S*
64. Let S be a finite non-empty alphabet and let 2 be the
59. If L1 = {an | n ³ 0} and L2 = {bn | n ³ 0}, consider power set of S*. Which one of the following is TRUE?
[2014, Set-2, 1 Mark] [2014, Set-3, 1 Mark]
(I) L1.L2 is a regular language
S*
(II) L1.L2 = {anbn | n ³ 0} (a) Both 2 and S* are countable
2S * is countable and S* is uncountable
Which one of the following is CORRECT?
(b)
(a) Only (I) (b) Only (II)
(c) Both (I) and (II) (d) Neither (I) nor (II) (c) 2S * is uncountable and S* is countable
S*
(d) Both 2 and S* are uncountable
EBD_7203
S3-266 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Context-free languages and regular languages are both (iii) Only L2 is accepted by deterministic PDA.
closed under the operations (s) of (a) only (i) (b) (i) and (ii)
(i) Union (ii) Intersection (iii) Concatenation (c) (i) and (iii) (d) All three
(a) (i) and (ii) only (b) (ii) and (iii) only 10. Let L1 and L2 are regular sets defined over the alphabet
(c) (i) and (iii) only (d) all of the above å * . Mark the false statement
2. Let r1 = ab*c* & r2 = ( a * b Ú c ) * and r3 = ( a Ú b Ú c ) * (a) L1 È L 2 is regular (b) L1 Ç L 2 is not regular
Then which of the following is true
(a) w = ac belongs to L(r 2) and L(r3) but not L(r1) (c) å * - L1 is regular (d) L1 * is regular
(b) w = ac belongs to L(r 3) only 11. Which of the following functions are computable with
(c) w = ac belongs to L(r 1), L(r2) and L(r3) turning Machine?
(d) w = ac belongs to L(r 1) and L(r3) but not L(r2) (a) n*(n – 1)*(n – 2)*...*2*1*
3. Let å = {a, b} (b) [log2 n]
r1 = a ( a Ú b ) * (c) n
22
r2 = b ( a Ú b) * (d) all of the above
Which of the following is true? 12. Let L1 = {anbncn, n ³ 0}
(a) L ( r1 ) = L ( r2 ) = å * (b) L ( r1 ) Ç L ( r2 ) = {l} L2 = {a2nb2nc2n, n ³ 0}
(c) L ( 1) ( 2 ) å
r È L r = * (d) L(r1) È L(r2) È {l} = S* L3 = {a2nb2ncn, n ³ 0}
4. Which of the following statements are true? (a) L1 Í L 2 and L3 Í L 2 (b) L2 Í L1 and L 2 Í L3
(i) abcd Î L((b * a)* (d*c*)*)
(ii) abcd Î L((d*c*b*a)*) (c) L2 Í L1 but L 2 Ë L3 (d) L1 Í L 2 and L 2 Í L3
(iii) abcd Î L((a*b*c*d)*) 13. Which of the following regular expression does not represent
(a) (i) and (iii) only (b) (ii) and (iii) only strings beginning with atleast one 0 and ends with at least
(c) (i) and (ii) only (d) all of the above one 1?
5. Which of the following regular expression corresponds to (a) 0*1* (b) 00*(0 + 1)*1
the language of all strings over the alphabet {a, b} that do (c) 0(0 + 1)*1 (d) None of the above
14. The following CFG
not end with ab.
S ® aS | bS | a | b
(a) (a + b)* (aa + ba + bb)
is equivalent to the regular expression
(b) (a + b)* (aa + ba + bb) + a + b + l 1. (a* + b*) 2. (a + b)+
(c) b*ab*a 3. (a + b) (a + b)* 4. (a + b)* (a + b)
(d) b*aab* (a) 2 and 3 only (b) 2, 3 and 4
6. How many minimum number of states are required in the (c) All of the above (d) 3 and 4 only
DFA{over the alphabet {a, b}) accepting all the strings with
15. The Moore machine has six tuples ( Q, å , D, d, l, d 0 ) .
the number of a’s divisible by 4 and number of b’s divisible
by 5? Which of the following is true?
(a) 20 (b) 9 (a) d is the output function
(c) 7 (d) 15 (b) d is the transition function S into Q
(c) l is the transition function S × Q into Q
7. How many states does the DFA constructed for the set of
(d) l is the output function mapping Q into D.
all strings ending with “00”, have?
(a) 2 (b) 3 16. Suppose r1 =Î , r2 = 0*1* , which of the following
(c) 4 (d) 5 statement is true about r1 and r 2?
8. Let X = {0, 1}, L = X* and R = {0n1n/n>0} then the language (a) r1 is not regular expression, while r2 is a regular
(b) r1 and r2 both are regular expression
L È R and R respectively
(a) Regular, Regular (b) Non regular, Regular (c) r1 is regular expression, but r 2 is not
(d) Neither r1 nor r2 are regular expressions
(c) Regular, Not regular (d) Not regular, Not Regular
9. Consider L1 = 0 1 , L2 = 0 c 1n
n n n 17. If L1 is regular and L2 is CFL over å * which of the following
Which of the following statements are correct? statement is incorrect?
(i) L1 and L2 are accepted by non-deterministic PDA. (a) L1 È L2is CFL (b) L1 Ç L 2is regular
(ii) L1 and L2 are accepted by deterministic PDA.
(c) L1 * is regular (d) None of the above
THEORY OF COMPUTATION S3-267
25. The statement, “ATM can’t solve halting problem” is
18. å * over {0, 1} and 2å * are respectively.
(a) True (b) False
(a) Uncountably infinite and uncountably infinite (c) Still a open question (d) None of these
(b) Countably infinite and uncountably infinite 26. Any given transition diagram has an equivalent
(c) Countably infinite and countably infinite (a) regular expression (b) NDFSM
(d) None of the above (c) DFSM (d) all of these
19. Which of the following languages is/are context free? 27. The FSM shown in the figure accepts
1. {a n bn cmdm | n ³ 1, m ³ 1}
2. {a n bmcmdn | n ³ 1, m ³ 1}
3. {a n bmcn dm | n ³ 1, m ³ 1} (a) all strings (b) no strings
a
S1 S3
a (a) all stings (b) no strings
Sc b a (c) Î-alone (d) none of these
29. CFLs are not closed under
b S2 S4
b (a) Union (b) Concatenation
(c) Closure (d) Intersection
a, b
L(M) = ? 30. The set A = {anbnan | n = 1, 2, 3...} is an example of a language
(a) L(M) = {words starting with aa or bb} that is
(b) L(M) = {words ending with aa or bb} (a) regular (b) not context-free
(c) L(M) = {words containing aa or bb as a subword} (c) context-free (d) none of these
(d) None of these 31. Consider the two regular languages L1 =(a + b)* a and L2 =
21. The regular expression for “Binary numbers that are b (a + b)*. The intersection of L1 and L2 is given by
multiples of two” is (a) (a + b)* ab (b) ab(a + b)*
(a) (0 | 1) * 1 (b) (0 | 1)*0 (c) a(a + b)* b (d) b(a + b)*a
(c) (1 | 0) * 1 (d) (1 | 0)*00 32. Which of the following languages over {a, b, c} is accepted
22. Which of the string is accepted by given NDFA? by deterministic push down automata?
a (a) {w | w is palindrome over {a, b, c}}
(b) {w wR | w Î {a, b, c}*}
(c) {anbncn | n ³ 0}
Start c (d) {wCwR | w Î{a, b}*}
33. Consider the FA shown in the figure given below, where
“–” is the start and “+” is the ending state.
The language accepted by the FA is
b
a
(a) c. ( a È b ) * (b) c.a * b *
(c) c.(ab)* (d) None of these b – + a
23. Consider the language b
L1 = {anbmcndm | n ³ 1, m ³ 1} and (a) (a + b)*b (b) (a + b)*a
L2 = {anbmcmdn | n ³ 1, m ³ 1} (c) a*b (d) a*b*
(a) Both L1 and L2 are context free 34. Regarding the power of recognizing the languages, which
(b) L1 is not context free but L2 is context free of the following statements is false?
(c) both are not context free (a) The NDFA are equivalent to DFA
(d) L1 is context free but L2 is not context free (b) NDPDA are equivalent to DPDA
24. The following GFG (c) NDTMs are equivalent to DTMs
S ® aS | bS | a | b and S ® aS| bS | a | b | l is equivalent to (d) Multiple tape TMs are equivalent to single tape TMs
regular expressions 35. If "w Î å * it can determined in finite time, whether or not
(a) (a + b) and l + a + b respectively
(b) (a + b) (a + b)* and (a + b)* respectively w Î L, the L is
(c) (a + b) (a + b) and (l + a + b)(l + a + b) respectively (a) decidable (b) undecidable
(d) None of these (c) non-deterministic (d) intractable
EBD_7203
S3-268 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
36. Consider the transition diagram of DFA as given below. 41. (a + b)*a (a + b)*
1 (a) strings of odd length having a at the middle
q0 q1 (b) all strings containing a and b
1
(c) all strings of odd length
(d) all strings containing atleast one ‘a’
0 0 0 0
42. Let L be the set of all strings over {0, 1} of length 6 or less.
1 Write a simple RE corresponding to L.
q2 q3 (a) (a + 1)* (b) (0 + 1)6
1 (c) (0 + 1 + Î)* (d) (0 + 1 + Î)6
Which is the language of the given DFA? 43. Given the R.E. described by the following NFA.
(a) L = {Î}
0
(b) L = {} 1 2
(c) L = {w|w has equal no. of 1’s and 0’s} Start q0 Î q1
Î
q2
(d) none of these
37. Let S = (0, 1), then an automation A accepting only those (a) (0 1 2)* (b) (0 + 1 + 2)*
words from S having an odd number of 1’s requires
(c) 0*1*2* (d) None of these
_________ states including the start state.
44. [(a + b) (a + b)]*
(a) 2 (b) 3
(c) 4 (d) 5 (a) all strings
38. Design an FSM to check whether a given unary number is (b) all strings of even length
divisible by 3. (c) all strings in which group of 2 symbols has both the
symbols same but grouping must be done left to right
q4 starting from first symbol
(a) 1 q1 (d) all strings in which group of 2 symbols has both the
q0
Start
symbols same but grouping must be done right to left
1
1 starting from last symbol.
45. If a DFA is represented by the following transition table,
q2 q3
then how many states does the corresponding minimal DFA
1 1 contains?
(b) q0 q1 q4
Start State Input
0 1
1 1
(start) ® A B C
q2 q3 B B D
1
1 1 C B C
(c) q0 q1 q3
Start D B E
(final) ® E B C
1 1 (a) 2 (b) 3
q2 (c) 4 (d) 5
46. G = {(a, b), {S}, S, {S ® b/Sa/aS/SS})
1 1
(d) q0 q1 q3 Which of the following are true?
Start
(i) aabbaa Î G
1 (ii) G is ambiguous
1 (iii) regular expression corresponding to G is ba*
q2
(a) (i) and (ii) only (b) (ii) and (iii) only
39. The given transition table is for the FSM that accepts a (c) (i) and (iii) only (d) all of the above
string if it ends with ‘aa’. Which is the final states? 47. Which languages does the following DFA accept?
b
d a b 1
a, b
start q0 q2 a
a
q0 q2 q1 0 3
q1 q2 q1 b
a
q2 q2 q0 b 2
(a) q 0 (b) q 1 (a) (ab)* (b) (ab + bb)*
(c) q 2 (d) can’t be determined (c) (ab + ba)* (d) (aa + bb)*
40. A minimum state DFA accepting the same language has 48. Which of the following statements are false?
how many states? (a) The regular expression (1 + 10)* denotes all strings of
(a) 1 (b) 2 0’s and 1’s beginning with ‘1’ and not having two
(c) 3 (d) 4 consecutive O’s
THEORY OF COMPUTATION S3-269
(b) The regular expression (0 + 1)*011 denotes all strings 1. (q0, 0) = (q1, X, R)
of O’s and 1’s ending with 011. 2. (q0, Y) = (q3, Y, R)
(c) The regular expression OO (1 + 10)* denotes all strings 3. (q1, 0) = (q1, 0, R)
of O’s and 1’s atleast two consecutive O’s 4. (q1, 1) = (q2, Y, L)
(d) The regular expression (O + Î) (1 + 10)* denotes all 5. (q1, Y) = (q1, Y, R)
strings of O’s and 1’s that do not have two consecutive 6. (q2, 0) = (q2, 0, L)
O’s 7. (q2, X) = (q0, X, R)
49. Which of the following languages can’t be accepted by a 8. (q2, Y) = (q2, Y, L)
deterministic PDA? 9. (q3, Y) = (q3, Y, R)
(a) The set of palindromes over alphabet {a, b} 10. (q3, B) = (q4, B, R)
(b) The set of strings of balanced parenthesis Which of the following is true about M?
(c) L = {WcWR | W in (0 + 1)*} (a) M halts on L having 100 as substring
(d) L = {0n 1n | n ³ 0} (b) M halts on L having 101 as substring
50. Which language does the following PDA accept (c) M halts on = 0n1n, n ³ 0
M = {{q0, q1}, {0, 1}, {z0, x}, d, q0, z0, f} and d is given by (d) M halts on L not having 1100 substring
d (q0, 0, z0) = (q0, xz0) 56. Consider the following regular grammar,
R1 = (a|b)*
d (q0, 0, x) = (q0, xx)
R2 = (a* | b*)*
d (q0, 1, x) = (q1, x)
R3 = (Î a | b*)*
d (q1, 1, x) = (q1, Î)
Minimized deterministic finite automata of which R1, R2 and
d (q1, Î, z0) = (q0, Î)
R3 are exactly same except state names?
(a) L = {0n 1n | n ³ 0} (b) L = {0n 1n | n ³ 1} (a) DFA for R1 and R2 are similar
(c) L = {0n 1n + 1 | n ³ 0} (d) L = {0n 1n + 1 | n ³ 1} (b) DFA for R2 and R3 are similar
51. Which of the following statement must always be true for A (c) DFAS for R1, R2 and R3 are different
and B? Suppose A and B are two sets of strings from S*, (d) DFAS for R1, R2 and R3 are similar
such that B Í A 57. Consider the following machine M
(i) if A is finite then, B is finite a
(ii) if A is regular then, B is regular b a a
(iii) if A is context free then, B is context free Start S
0 S1 a S2 S3
b
S4
(a) (i) only (b) (ii) only b
b b
(c) (iii) only (d) All three
52. Consider the following grammar G a
S ® aA, A ® (aA, bB), B® (bB, c, cC), C® (c, cC) Which is the language L(M) accepted by this machine?
Which of the following is L(G)? (a) L(M) = {Set of all words starting with aabb}
(a) L(G) = a*b*c* (b) L(G) = aa*b*c* (b) L(M) = {Set of all words having aabb as a subword}
(c) L(G) = aa*bb*cc* (d) L(G) = (abc)* (c) L(M) = {Set of all words ending with aabb}
53. Consider the following set of languages (d) L(M) = {Set of all words with exactly one occurance of
L1 = ambn | n = m2 aabb}
L2 = ambmcmdn |m, n, > 0 58. If L1 and L2 are a pair of complementary languages. Which
L3 = ambmcndn | m, n > 0 of the following statement is not possible?
Which of the above language is not context free? (a) Both L1 and L2 are recursive
(a) L1 and L3 (b) L2 and L3 (b) L1 is recursive and L2 is recursively enumerable but
(c) L1 and L2 (d) All L1, L2 and L3 not a recursive
54. L1 has the following grammar
(c) Neither L1 nor L2 recursively enumerable
S ® aB/BA
(d) One is recursively enumerable but not recursive, the
A ® bAA/aS/a
other is not recursively enumerable.
B ® b/bS/aBB
L2 has the following grammar 59. Consider the grammar consisting of 7 productions
S ® Sba/a S ® aA | aBB
Which of the following statement is true about? A ® aaA | l
B ® bB | bbC
L3 = L1 Ç L2 and L4 = L1L1 * ? C®B
(a) Both L3 and L4 are not context free After elimination of Unit, useless and l-productions, how
(b) L3 is context free but L4 is not many production remain in the resulting grammar?
(c) Both L3 and L4 are context free (a) 2 (b) 3
(d) L4 is context free, but not L3 (c) 4 (d) 5
55. Let M be a turing machine has Q = {q0, q1, q2, q3, q4} a set
60. Referring to Turing machine in previous question, what will
of states, input alphabets {0, 1}. The tape alphabets are {0,
1, B, X, Y}. The symbol B is used to represent end of input be the output when the input is I1 = 0100 and I2 = 0010?
string. The final state is q4. The transistions are as follows. (a) I1 = 0 and I2 = Blank (b) I1 = Blank and I2 = 0
(c) I1 = 1 and I2 = 1 (d) None of the above
EBD_7203
S3-270 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
61. Suppose L1 and L2 are two language over å * 70. P, Q, R are three languages. If P and R are regular and if PQ
= R, then
L = å * - ( ( å * - L1 ) È ( å * - L 2 ) ) (a) Q has to be regular (b) Q can not be regular
L1 and L2 are CFL. (c) Q need not be regular (d) Q has to be a CFL
Which of the following statement is true? 71. The Travelling Salesman Problem (TSP) is
1. L is necessarly CFL (a) NP but not NP complete
2. L may or may not be CFL (b) NP complete
3. L1 Í L1 (c) Neither NP nor NP-complete
(a) only 2 (b) 1 and 3 (d) None of these
(c) 2 and 3 (d) All are correct 72. Which of the following is false?
62. In string of length n, how many proper prefixes can be (a) PATH is a P class problem
generated (b) Djikstra’s algorithm is a problem in P
(a) 2n (b) n (c) CLIQUE is a NP class problem
(c) n(n + 1)/2 (d) n – 1 (d) RELPRIME is a NP class problem
63. The following CFG 73. If there is an NP-complete langauge L whose complement is
S ® aB | bA in NP, then the complement of any language in NP is in
A ® ba | aS | bAA (a) NP
(b) P
B ® b | bS | aBB
(c) Both (a) and (b)
generates strings of terminals that have
(d) None of these
(a) equal number of a’s and b’s
74. What is the regular expression for the language generated
(b) odd number of a’s and even number of b’s by S ® aS | bA, A ® d | ccA
(c) even number of a’s and even number of b’s (a) a*bd
(d) odd number of a’s and even number of a’s (b) a*(bd) (bcc)*d
64. The regular expression 0* (10*) denotes the same set as (c) a*b(cc)*d
(a) (1*0)*1* (b) 0 + (0 + 10)* (d) None of these
(c) (0 + 1)*10(0 + 1)* (d) None of the above 75. Consider the grammar S ® PQ | SQ | PS, P ® x, Q ® y. To get
65. Consider the following deterministic finite state automation string of n terminals, the number of productions to be used is
M. (a) n 2 (b) 2n
1 0 (c) 2n + 1 (d) 2n – 1
0, 1
76. Which of the following can be recognized by a DFA?
1 0
(a) The number of 1, 2, 4, --- 2n ---written in binary
1
(b) The number of 1, 2, 4, --- 2n ---written in unary
1 (c) The set of binary strings in which the number of 0’s is
Let S denote the set of seven bit binary strings in which the same as the number of 1’s
first, the forth and the last bits are 1. The number of strings (d) The set {0, 101, 11011, 111011, ---}
is S that are accepted by M is 77. Give a RE for the set of strings which are either all b’s or else
(a) 1 (b) 5 there is an ‘a’ followed by some b’s also containing Î.
(c) 7 (d) 8 (a) b* + ab* (b) (Î + a)b+
66. The diagoalization language, Ld is a (c) b* + ab* + Î (d) (Î + a)b+ + Î
(a) recursive language 78. Given an arbitary non-deterministic finite automaton (NFA)
(b) recursive enumerable but not recursive with N states, the maximum number of states in an equivalent
minimized DFA is at least.
(c) non-recursivity - enumerable (non-RE) language
(a) N 2 (b) 2N
(d) both (b) and (c) (c) 2N (d) N!
67. Time taken by one tape TM to simulate n moves of k-tape. 79. Consider a DFA over å = {a, b} accepting all strings which
TM is have number of a's divisible by 6 and number of b's divisible
(a) O(n) (b) O(nk) by 8. What is the minimum number of states that the DFA
(c) O(n ) 2 (d) none of these will have?
68. Which of the following is true? (a) 8 (b) 14
(a) PDA with 2 stacks is equivalent to TM (c) 15 (d) 48
(b) Regular expression can represents only some of the 80. Consider the following languages :
languages. L1 = {ww | w Î {a, b} * }
(c) Both (a) and (b) L2 = {wwR | w Î {a, b} * wR is the reverse of w}
(d) neither (a) nor (b) L3 = {02i | i is an integer}
69. L Î NP does not obviously imply that L4 = {0i2 | i is an integer}
(a) L’ Î NP (b) both (a) and (c) Which of the languages are regular?
(c) L’ Î P (d) none of these (a) Only L1 and L2 (b) Only L2, L3 and L4
(c) Only L3 and L4 (d) Only L3
THEORY OF COMPUTATION S3-271
81. Consider the following problem x. (a) G is not ambiguous
Given a Turing machine M over the input alphabet å, any (b) There exist x, y, Î L (G) such that xy Î / L(G)
state q of M.
(c) There is a deterministic pushdown automaton that
And a word w Î å* does the computation of M on w visit
the state q? accepts L (G)
Which of the following statements about x is correct? (d) We can find a deterministic finite state automaton that
(a) x is decidable accepts L(G)
(b) x is undecidable but partially decidable 88. Consider the following two statements :
(c) x is undecidable and not even partially decidable S1 : {02n| n ³ 1|} is a regular language
(d) x is not a decision problem S2 : {0m 1n 0m + n | m ³ 1 and n ³ 1|} is a regular language
82. The language accepted by a Pushdown Automaton in which
the stack is limited to 10 items is best described as Which of the following statements is incorrect?
(a) Context free (b) Regular (a) Only S1 is correct
(c) Deterministic Context free (d) Recursive (b) Only S2 is correct
83. Ram and Shyam have been asked to show that a certain (c) Both S1 and S2 are correct
problem P is NP-complete. Ram shows a polynomial time (d) None of S1 and S2 is correct
reduction from the 3-SAT problem to P, and Shyam shows 89. Which of the following statements true?
a polynomial time reduction from II to 3-SAT. Which of the (a) If a language is context free it can be always be accepted
following can be inferred from these reduction? by a deterministic push-down automaton.
(a) P is NP-hard but not NP-complete (b) The union of two context free language is context free.
(b) P is in NP, but is not NP-complete (c) The intersection of two context free language is context
(c) P is NP-complete free
(d) P is neither Np-hard, nor in NP (d) The complement of a context free language is context
84. Nobody knows yet if P = NP. Consider the language L
free
defined as follows
90. The smallest finite automaton which accepts the language
ì(0 + 1) * if P = NP {x|} length of x is divisible by 3} has
L=í
î O othervise (a) 2 states (b) 3 states
Which of the following statements is true? (c) 4 states (d) 5 states
(a) L is recursive 91. The C language is :
(b) L is recursively enumerable but not recu (a) A context free language
(c) L is not recursively enumerable (b) A context sensitive language
(d) Whether L is recursive or not will be known after we (c) A regular language
find out if P = NP (d) Parsable fully only by a Turing machine
85. If the strings of a language L can be effectivley enumerated 92. The language accepted by a Pushdown Automaton in which
in lexicographic (i.e., alphabetic) order, which of the the stack is limited to 10 items is best described as
following statements is true? (a) Context free (b) Regular
(a) L is necessarily finite (c) Deterministic Context free (d) Recursive
(b) L is regular but not necessarily finite 93. Ram and Shyam have been asked to show that a certain
(c) L is context free but not necessarily regular problem P is NP-complete. Ram shows a polynomial time
(d) L is recursive but not necessarily context free reduction from the 3-SAT problem to P, and Shyam shows
86. Consider the following deterministic finite state automaton a polynomial time reduction from to 3-SAT. Which of the
M.
following can be inferred from these reduction?
(a) P is a NP-hard but not NP-complete
(b) P is in NP, but is not NP-complete
(c) P is NP-complete
(d) P is neither Np-hard, nor in NP
94. Nobody knows yet if P = NP. Consider the language L
defined as follows
Let S denote the set of seven bit binary strings in which the ì(0 + 1) * if P = NP
first, the fourth, and the last bits are 1. The number of strings L=í
in S that are accepted by M is î O othervise
(a) 1 (b) 5 Which of the following statements is true?
(c) 7 (d) 8 (a) L is recursive
87. Let G = ({S}, {a, b} R, S be a context free grammar where (b) L is recursively enumerable but not recu
the rule set R is (c) L is not recursively enumerable
S®aSb|SS|e (d) Whether L is recursive or not will be known after we
Which of the following statements is true? find out if P = NP
EBD_7203
S3-272 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
95. If the strings of a language L can be effectively enumerated 99. Consider the NFAM shown below.
in lexicographic (i.e. alphabetic) order, which of the following
statements is true?
(a) L is necessarily finite
(b) L is regular but not necessarily finite
(c) L is context free but not necessarily regular
(d) L is recursive but not necessarily context free
96. Consider the following deterministic finite state automaton
M.
104. Consider three decision problem P1, P2 and P3. It is known (a) 00 11 22 (b) 11 22
that P1 is decidable and P2 is undecidable. Which one of (c) 21 (d) 22
the following is TRUE? Directions for 110, 111 and 112:
Consider the transition diagram of an DFA as given below:
(a) P3 is decidable if P1 is reducible to P3
(b) P3 is undecidable if P3 is reducible to P2
(c) PL3 is undecidable if P2 is reducible to P3
(d) P3 is decidable if P3 is reducible to P2’s complement
105. Consider the machine M
Y Z 31. (c) 1
No. of states of the product of Z and Y = 2 × 2 = 4 1 0
Now, the states as per the given options are P, Q, R
and S. The finite state automata is 0 0
q0 q1 q2
a b
1
®P S R
Q R S
State Input Output
R(F) Q P q0 to q0 1, 0 00
S Q P q1 to q0 1, 0 00
q2 to q0 1, 0 00
Table for Z × Y is
Therefore, the above DFA ends with 00.
a b
32. (c) It is given that L = L1 Ç L 2
® (1, 2) (2, 1) (2, 2)
Let’s first analyze the given language and check
(1, 2) (2, 2) (2, 1) whether it is context-free or not. The context-free
languages are defined as below–
(2, 1) (1, 1) (1, 2)
27. (d) Option (a) True: Non-deterministic finite automata can the language of all non-empty even-length strings. It
be converted into the deterministic finite automata. consists of
Option (b) True: With reference to option (a), same is 1. the entire first halves of which are a’s.
with the non-deterministic turing machine. 2. the entire second halves of which are b’s.
Option (c) True: Regular language is always context- L is generated by the grammar S ® aSb | ab, and is
free but the reverse is not true. accepted by the push-down automation M = ({q0, q1,
Option (d) False: We know that a set is a subset of qf}, {a, b}, {a, z), d q0, {qf}) where d is defined as
itself and hence, every subset of recursively enumerable
d(q0, a, z) = (q0, a)
set is not recursive.
d(q0, a, a) = (q0, a)
28. (b) As per the theorem, a language is recursive if that
d(q0, b, a) = (q1, x)
language and its complement are r ecursively
enumerable. Therefore, L is recursive. d(q1, b, a) = (q1, x)
29. (b) Statement 1 Decidable: The algorithm can be used to d(q1, l, z) = (qf, z)
check the finiteness/infiniteness on the DFA and also d (state1, read pop) = (state2, push)
the two given DFAs, a product DFA can be where z is initial stack symbol and x means pop action.
constructed. Here, in we are given, where a and b are of equal lengths
THEORY OF COMPUTATION S3-277
and followed by c which is of different length. This The common feature in the accepting languages can
definitely shows that the languages are context-free be seen that they consist of atleast two 0’s.
but not regular. 37. (b) Given grammar S ® aSabSbab.
33. (a) The initial state = 00 The strings generated through this grammar is
Final state required = 01 definitely palindromes,but not all it can only generate
palindromes of odd length only so (A) & (D) are false,
Let us construct the transition diagram for the given.
(B) is correct.
00 01 01
Also it can generate palindromes which start and end
0 0
0 1 2 with same symbol, but not all strings eg. aabababba.
Initial state Final state 38. (c) L is the set of all substrings of w where w ! {0,1})
We get the total number of states to be 3 when getting Any string in L would have length 0 to n, with any no.
the desired output. The transition diagram can further of 1’s and 0’s
The NDFA
be elaborated as below.
There can be 4 states 00, 01, 10, 11.
With this, the FSM can be designed as
0/1
1/0
00 01
1/1
a a
n – 1 discs n – 1 discs
a, b move from
s move from
A to B
B to C
b
EBD_7203
S3-280 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
S ¾¾ ® aS | bS | a | b | l are
® aS | bS | a | b and S ¾¾
respectively.
36. (d) The given FA accepts all combinations of even number
of 0’s and 1’s.
37. (a) The automation given below, accepts the words with
odd of 1’s.
The required languages are 0 0
L1 = (a + b) (a + b)* 1
L2 = (a + b)* Start Start
25. (a) ATM cannot solves the halting problem because it 1
cannot find in finite time that for the given word the clearly, the automation requires only 2 states. Hence
machine will halt or not the correct option is (a).
26. (d) Since every language can be represented through 38. (d) The unary number has a single symbol and the length
regular expression and its equivalent machine. Also of the string is its value. So we have to accept strings
for the every deterministic machine there exist its where, no of 1’s divisible by 3. On first symbols of
equivalent non-deterministic machine. number (i.e.), we will move to remainder 1 state, (q1)
27. (c) The FSM shown accept only Î. Also it is the starting when next input is received we move to remainder 2
as well as final state and no other input is there. state (q2) and on next we move to 0 remainder state (i.e.
28. (b) The FSM shown has no final states to accepts strings. q3) as shown in the choice (1).
Hence, it accepts no strings. 39. (b) Drawing the FSM for the given transition diagram
Hence, option (b) is correct. we can clearly see that if ‘q1’ is the final state then only
29. (d) It follows from the closure properties of CFL’s. CFL’s the given FSM can generate words which are all ending
are closed under È , concatenation & *, but not under with “aa”.
Ç and LC.
30. (b) For set A = {anbnan | n = 1, 2, 3....} A
the no. of comparisons are 2. first one for checking
a
No. of a = No. of b and, second one for again checking a
No. of b = No. of a’s following the b’s Start a q0 q1
As we know, a pda can do only one of these a
comparisons. Hence the given language is not context b b
free. b
31. (d) Here L1 = (a + b)* a is nothing but set of all strings of q2
a and b ending with a.
L2 = b(a + b)* is set of all strings of a & b starting with b
b.
The intersection of L1 and L2 is set of all strings starting 40. (c) The minimum state DFA accepting the above language
with b and ending with a. is
\ L1 Ç L 2 = b(a + b)*a
b a
32. (d) Here
a a
(a) is not correct because we can’t find the middle of Start q0 q1
palindrome, without guessing. b
(b) is also not correct because of same reason.
33. (b) This is a standard DFA for all strings ending with “a”. b
Hence the language is (a + b)*a. 41. (d) (a + b)* means all combination of ‘a’ and ‘b’. Hence ‘a’
34. (b) Regarding the power of recognizing of languages in (a + b)* a(a + b)* signifies that at least one ‘a’ must
(a) NDFA has same power as DFA be there.
(b) NDTMs are equivalent to DTMs 42. (d)
(c) Multiple tape TMs are equivalent to single tape 43. (c) Clearly 0’s followed by 1’s followed by 2’s being
TMs accepted so choice (c) 0*1*2* is correct.
Only DPDA Í NPDA in the power. 44. (b) (a + b) (a + b) generates all the 2 length strings aa, ba,
35. (a) Since "w Î å * whether or not w Î L , so L is ab & bb. So [(a + b)(a + b)]* will generates all the even
decidable. can be determined in finite time. length strings, including l.
THEORY OF COMPUTATION S3-283
45. (c) Drawing the dfa corresponding to the given transition (c) L = {WcWR/W in (0 + 1)*}
table. (d) L = {0n 1n | n ³ 0}
in each of the above the PDA can deterministically
0 separate the push and pop operations.
0 1 But it cannot do the same in case (a), since it has to
A B D guess middle of palindrome, In DPDA we can’t do
0 guessing. NDPA is required for this.
1 0
50. (b) The transition function
0
d ( q 0 , 0, z0 ) = ( q 0 , xz0 )
C 1 E represents that when input is 0, stack top is z0 and
current state is q0 than the stack top becomes xz0 and
1
state remains at q0.
The given set of transition functions checks for number
Use dfa minimisation algorithm
of 0’s followed by No. of 1’s. Whenever a “0” comes,
The corresponding minimum state dfa for this langauge
stack top become x and when the “1” come it is removed
can be constructed as
from stack Top. If at the end No input is left and stack
1 is empty than the word is accepted.
0
0
Hence, (b) L = {0n 1n | n ³ 1} is correct
1 1
q0 q1 q2 q3 51. (a) It is possible to have a subset of regular language which
0
is not regular and a subset of CFL which is not CFL,
1 0
but a subset of finite set has to be finite.
For example.
1. L = (0 + 1)* is regular. Let Ls = {0n 1n}
Only 4 states are needed.
46. (a) Two derivation trees are possible for aabba as given Here Ls Í L . But Ls is not regular.
below 2. L = (0 + 1)* is regular and hence also CFL. Consider
S S Ls = {0n 1n 0n | n ³ 0} Here Ls Í L , but Ls is not a CFL.
a S
a S 52. (c) The given grammar is right linear.
S S
S S S
a S a a
S
a a b
SS S a
b c
bb b a b c
S A B C
Therefore (i) and (ii) are both true. a
Choice (iii): ‘aba’ is also accepted by the given c
grammar. Therefore (iii) is false.
47. (b)
b x
1 a 3 a, b
Start a
0
b
a
b c
b
2 a b c
S A B C
Y, Y, R 65. (c) The strings with the first, 4th and 7th bits as ‘1’ will
look in the following format
56. (d) R1 = (a | b)* = (a + b)* ...(1) 1 _ _ 1 _ _ 1.
R2 = (a* | b*)* = (a* + b*) = (a + b)* ...(2) So, there can be 16 possible combinations for the
R3 = (Î | a | b*)* = (Î + a + b)* = (a + b)* ...(3) above format. But in the given DFA, only 7 strings of
these will be accepted. They are,
Clearly from (1), (2) and (3)
1. 1001001
57. (b) Clearly, we can observe that the minimum string
accepted is aabb. 2. 1001011
The corresponding L(M) = {W/W Î (a + b)* aabb 3. 1001101
(a + b)*} 4. 1001111
58. (b) The correct statement follows from following theorem: 5. 1011001
Theorem: If L1 and L2 is a pair of complementary 6. 1101001
language then either
7. 111001
· Both L1 and L2 are recursive.
66. (b) Diagonalization language, Ld is defined as
· Neither L1 and L2 are recursively enumerable.
Ld = {TM that accepts its own code}
· One is recursively enumerable but not recursive,
the other is not RE. Ld is clearly RE but not REC.
Option (b) is not possible, since if L1 is recursive, then 67. (c) Single tape turing machine can simulate n-moves of
k-tape TM in O(n2)
L2 = Lc1 will also be recursive. 68. (b) Since 0* (10*) = 0* (1*0*)* for
59. (c) B and C are useless, since they are not generating any (a) (1*0) 1* = (1*0*)1*
terminal.
THEORY OF COMPUTATION S3-285
(b) 0 + (0 + 10)* = 0 + (0* 1*0*) =(0*1*0*) Hence its running time is O(n) (its input is encoded in
(c) (0 + 1)* 10(0 + 1)* binary).
69. (b) L Î NP does not imply that L’ Î NP. Since, closure of Conclusion
NP under complementation is as yet unresolved RELPRIME € P
problem. Also L Î NP does not imply L’ Î P, unless L
73. (c) If there is an NP-complete language whose complement
Î P, which may or may not be so.
is in NP. Then the set NP = CO-NP which implies NP =
70. (c) P, Q and R be three languages P.
Let P = (a + b)* i.e. NP = CO-NP = P
Q = ab So complements of any language is NP will in NP as
Then PQ = (a + b)* ab = R well P.
Here P, Q and R are regular. So, both (a) & (b) are true choice (c) is correct.
Let P=f 74. (c) S ® a S/bA, A ® d/cc A
Q = {anbn | n ³ 0}
PQ = R = f a cc
Here P and R are regular but Q is not b d
S A x
So Q need not to be regular
71. (b) Proof : First, we have to prove that TSP belongs to NP. We can clearly see that X is a final state. And the
If we want to check a tour for credibility, we check that corresponding language regular expression is
the tour contains each vertex once. Then we sum the a*b(cc)*d
total cost of the edges and finally we check if the cost
75. (d) Let start with S and develop some string
is minimum. This can be completed in polynomial time
thus TSP belongs to NP. Secondly we prove that TSP 1. S ® PQ using S ® PQ
is NP-hard. One way to prove this is to show that 2. S ® xQ using P ® x
Hamiltonian cycle TSP (given that the Hamiltonian cycle
3. S ® xy using Q ® y
problem is NP-complete). Assume G = (V, E) to be an
instance of Hamiltonian cycle. An instance of TSP is Hence n = 2 and number of productions required is 3
then constructed. We create the complete graph = Now check n2 i.e. 22 ¹ 3 eliminates (a)
(V, P £ G¢E¢), where E¢ = {(i, j) : i, j Î Vand i ¹ j. Thus, the
2n = 2.2 = 4 ¹ 3 \ eliminates (a)
cost function is defined as:
2n + 1 = 2.2 + 1 = 8 ¹ 3 \ eliminates (b)
t(i , j ) = 10.1 Î/ Î j) (i, if 1, j) (i, if 0EE
2n – 1 = 2.2 – 1 = 3 = 3
Now suppose that a Hamiltonian cycle h exists in G. It
76. (a) For (a) we can construct a DFA
is clear that the cost of each edge in h is 0 in Gas each
edge belongs to E. Therefore, h has a cost of 0 in G ¢¢.
Thus, if graph G has a Hamiltonian cycle then graph G 1
A B
has a tour of 0 cost. ¢ 0
Conversely, we assume that G' has a tour h' of cost at 0 1
most 0. The cost of edges in E' are 0 and 1 by definition.
B 0,1
So each edge must have a cost of 0 as the cost of h' is
0. We conclude that h' contains only edges in E.
So we have proven that G has a Hamiltonian cycle if which will recognize the series
and only if G' has a tour of cost at most 0. 1, 2, 4, ....2n .... in binary as
Thus TSP is NP-complete. 1, 10, 100, 1000, ...
72. (d) Euclidean algorithmfor finding gcd(x, y):
ì 2n ü
function gcd(hx, yi) Choice (b) is í1 ; n ³ 0 ý
î þ
if (y = = 0) return x else return gcd(hy, x mod yi)
Choice (c) is {w | n 0 (w) = n3 (w)}
Theorem
Choice (d) is {1n 01n, n ³ 0}
The Euclidean algorithm called on input hx, yi runs in
time DFA’s cannot be constructed for b, c and d since these
are not regular languages.
O(log(x + y)).
EBD_7203
S3-286 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
77. (d) The required regular expression is 87. (c) (A) Incorrect since the production has same non
r = b+ + ab+ + Î terminal in both sides, so definitely ambiguous.
(B) Since S”SS this leads to conjunction of every
= (Î + a)b+ + Î
possible string to make a valid string in L(G).
r = b* + ab+ (C) Context free languages are accepted by push
78. (c) In DFA the no. of states are always more than NFA, so down automata so true.
if NFA has N states DFA will have 2N states. (D) The language is not regular so DFA is not
79. (c) The valid strings will be where no. of a's 6, 12, 18, 24 possible.
No. of b's = 8,16,24 88. (a) S1 can be represented using a DFA so it is regular S1 is
correct.
S2 can’t be represented by DFA but it requires PDA to
accept. So is S2 is CFG not regular. S2 is false.
89. (b) (A) It is not necessary at all.
(B) {an bn} U {an bn cn} = {an bn cn} always true
No. of states = 7 for a so correct.
(C) {an bn} I {an} = {an} not CFG so false.
(D) Not necessary.
90. (b)
No. of states = 9 Start & end are same (a) so the minimum no. of states
Total 9+7–1 = 15 required are 3.
1 subtracted due to 2 final states. If string traversal doesn’t stop at (a) then string length
80. (c) L1 would be accepted by PDA so can’t be regular. is not divisible by 3.
L2 similarly can’t be accepted by DFA so not regular. 91. (a) C language is context free language entirely based upon
L3 & L4 both require only finite no of zeros. the productions.
So both regular. 92. (b) Pushdown Automaton uses stock as data structure &
81. (a) Since it is possible to create a turing machine for the
languages accepted by PDA is regular.
problem, 20 this problem is decidable.
93. (c) A problem is said to be NP- complete, if it is both NP &
82. (b) Pushdown Automaton uses stock as data structure &
languages accepted by PDA is regular. NP hard.
83. (c) A problem is said to be NP- complete, if it is both NP & 3-SAT problem is NP complete so a reduction of
NP hard. 3-SAT problem is NP complete so a reduction 3-SAT problem to P & P to 30-SAT.
of 3-SAT problem to P & P to 30-SAT. So this infers that P is NP complete, since it is reducible
So this infers that P is NP complete, since it is reducible
to a NP complete problem.
to a NP complete problem.
84. (a) A language L is said to be recursive if there exists any 94. (a) A language L is said to be recursive if there exists any
rule todetermine whether an element belong to language rule to determine whether an element belong to
or not, if languagecan be accepted by turning machine. language or not, if language can be accepted by turning
So there exist the rules so L is recursive. machine.
85. (b) Since L can be effectively enumerated so L has to be So there exist the rules so L is recursive.
regular, but is doesn't mean that the decisions are finite.
95. (b) Since L can be effectively enumerated so L has to be
86. (c) The strings accepted by the given automata are of type.
Option regular, but is doesn’t mean that the decisions are finite.
12 34567 96. (c) The strings accepted by the given automata are of type.
1--1--1 Option
These four blank spaces can have 0 or 1, so total 12 34567
24 = 6 strings are possible, but the given automata does 1--1--1
not accept all of those.
These four blank spaces can have 0 or 1, so total 24 = 6
1. 1 1 1 1 0 0 1
2. 1 1 0 1 0 0 1 strings are possible, but the given automata does not
3. 1 0 1 1 0 0 1 accept all of those.
4. 1 0 0 1 0 0 1 1. 1 1 1 1 0 0 1
5. 1 0 0 1 0 0 1 2. 1 1 0 1 0 0 1
6. 1 0 0 1 1 0 1 3. 1 0 1 1 0 0 1
7. 1 0 0 1 1 1 1
THEORY OF COMPUTATION S3-287
4. 1 0 0 1 0 0 1 2. S ® bA ® abA– ® abbA– ® abbaB ® abbaa
5. 1 0 0 1 0 0 1 3. abbaB ® abbaaS ® abbaab
6. 1 0 0 1 1 0 1 From (2) option (D) is false also from (1), (2) & (3) (a),
7. 1 0 0 1 1 1 1 (b) & (d) are false.
97. (A) Incorrect since the production has same non terminal So only (C) satisfy
in both sides, so definitely ambiguous. 104. (c) P1 ® decidable
(B) Since S”SS this leads to conjunction of every possible P2 ® undecidable
string to make a valid string in L(G). If P1 or P2 is reducible to P3 then P3 also has same
(C) Context free languages are accepted by push down properties as P1 & P2.
automata so true. So if P2 is reducible to P3 then P3 is also undecidable.
98. (a) This turning machine starts at 90 if it doesn’t get any 105. (b) From the given FSM, it is clear that a not necessity
input symbol but B then it halts. followed by only 2b due to self loop at final state. But
So if (00 + 1) *is chosen then the M/C can halt. Option at least 2b’s are there. abb substring not always,
(b) is wrong. Similarly aa not always.
Option (c) & (d) are possible but not necessary. 106. (b) The rules here used will be.
Option (a) (0 + 1) * 1 or more occurrence of 0 or 1. All those languages which are recursive their
So 0, 1, 00, 01, 10, 11........are valid strings & the machine complements are also recursive.
doesn’t halt for them. So option (a) & (b) can be correct.
99. (a) L is accepted by M(NFA) but NFA M1 has Now languages which are recursively enumerable but
not recursive, their complements can’t be recursively
enumerable. So only option (b) is correct
107. (b) In all the options there is linear relationship among
strings so all CFL’s, but L1 & L3 can be accepted by
PDA, L2 can be accepted by deterministic CFL due to
presence of special symbol D which tells the middle of
the string, so deterministic.
So this accept L1. 108. (c) The given NFA when converted to NFA without Î-
L1 will accept not only L but also substrings of L. moves.
So L1 is a subset of L
100. (c) 3 SAT problem is both NP & NP hard so it is NP 0 1
2
complete, but 2 SAT problem is solvable in Polynomial 1
Start q0 q1 2 q2
time so it is in class P.
0 1
101. (a) Due to the 3 one’s in the upper edges & 3 one’s in
1 2
lower edges to reach to final state the no of 1’s is always 0
divisible by 3 & 0’s are always in pair in forward &
back edge so, no of zero’s is divisible by 2.
102. (b) Language {an bn cm + n / m, n ³ 1} is a context free Note: The previous state from which there is an Î-
language since it can be represented by pushdown Move, if it goes to the final state then it also becomes
automata, but it is not regular since DFA can’t count the final state as well.
the no. of a’s & b’s and then check the sum for 109. (c) From the above NFA we can clearly see that it accepts
occurrence of c. strings only if “0 followed by 1 followed by 2” i.e. strings
103. (c) S ® bS | aA |b like 2 followed by 0 or b and 1 followed by - are not
A ® bA | aB accepted. Clearly, (c) is the correct option.
B ® bB | aS | a 110. (b) 111. (c) 112. (b)
Let Na(w) & Nb(w) denote of a’s &b’s in strings.
113. (c) Since both A and B are nullable therefore S is also
Some valid strings are
nullable. Therefore all A, B and S are nullable.
1. S ® bS ® bbS ® bbb (any no. of b)
EBD_7203
S3-288 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
114. (d) 116. (b) val ((a(a + a*aa) + aaa)*) = val (a(a + a*aa) + aaa)*)
115. (b) Val (a, (a + a*aa)) = max (val (a), val (a + a* aa)) = max (val (a*a + a*aa)),
= max (0, val (a + *aa) val ((aaa)) + 1
val (a) = 0 = max (1, 0) + 1
= val (a + a*aa) =1+ 1=2
= max (val (a), val (a*aa)) 117. (a) Val (a*b*b*b*)* = val (a*b*b*b*) + 1
= max (0 val (a*aa)) = val (a* + b* + b* + b*) + 1
= val (a*aa) = max (val (a*), val (b*)) + 1
= max (val (a*), val (aa)) = max (val(a) + 1 +, val (b) + 1)) + 1
= max (val (a*), 0) = max (1, 1) + 1
= val (a*) =1+ 1=2
= val (a) + 1 = 0 + 1
=1
6
Page - 289 - 348
COMPILER DESIGN
C Ø Lexical Analysis
O Ø
Ø
Parsing
N Ø Runtime environments
T
Ø Intermediate and target code generation
E
N
T
S
EBD_7203
S3-290 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Compiler is a special program which reads a program in source language and
translates into an equivalent other language. Also it reports the errors in the source
program to its user, if there are any.
A typical phases of a compiler of compiling program consists of following phases,
1. Lexical Analysis, the stream of characters of the source program is read from
left-right and grouped together having collective meaning.
2. Syntax analysis, the syntactic or structural correctness is achieved in syntax
analysis phase.
3. Semantic Analysis, it checks for semantic errors and collects the information
for subsequent code-generation.
4. Intermediate code generation, some compilers generate an explicit intermediate
source program after syntax and semantic analysis.
5. Code optimization, this phase attempts to the intermediate code which
results in faster running machine code.
6. Code generation, this is the final phase of compiler which normally consists
of assembly code or machine code.
Symbol table management: An essential function of the compiler, which records the
identifiers used in source program and collect information of various attributes in the
identifier.
Error detection and reporting: When a program is compiled the errors can occur in
different phases of the compilation, these errors are reported. Even though there are
errors the compilers should try to scan the complete program and compile it.
LEXICAL ANALYSIS
This is the first phase of a compiler and this reads the input characters from left to
right and creates a sequence of tokens. These tokens are used by the parser for
syntax analysis.
The schematic representation is given below,
Token
Source Lexical To semantic
Program Analyser Parser Analysis
get next
token
Symbol
Table
The lexical analyzer sometimes is divided into two phases, scanning and lexical
analysis. The scanning involves simple tasks like removing blanks from the input
whereas the lexical analyzer does more complex operations.
The reasons for separating lexical analysis and parsing,
1. The design becomes simpler, this separation makes either of the phases
simpler.
2. The performance of the compiler is improved. The separate lexical analyzer
allows creating more efficient processor for the task.
3. Compiler portability is enhanced. The input peculiarities and other anomalies
is taken care by lexical analyzer.
Tokens, Patterns and Lexemes
Tokens are a sequence of characters with a collective meaning like constants (integer,
double, char, string etc) , operators, punctuations and reserved words.
Pattern: it is a description of the form that the lexemes of a token may take.
COMPILER DESIGN S3-291
The lexical analyzer takes an input program and produces a stream of tokens output.
For example, the lexical analyzer may recognize particular instances of token as 5 or
345 as integer constant token
“alex” or “Wilma” for a string constant token
Numtickets or queue for variable token Example of tokens
These kind of specific instances are called lexemes. A lexeme is the actual set of
characters which forms token, the token is the general class to which the lexeme Const pi = 3.14159;
belongs to. Token 1 : (const, –)
To have a better understanding, the following table is used. Token 2 : (identifier, ‘pi’)
Token 3 : (=, –)
Token Informal Description of Pattern Sample Lexeme Token 4 : (real number, 3.14159)
Token 5 : (:, –)
If Characters i& f If
E = M * C * * 2 cof
Lexeme Forward
Begin
EBD_7203
S3-292 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Specification of tokens
An alphabet is set of symbols.Letters, digits and punctuation are the typical examples
of symbols. Unicode is an important example which includes 1,00,000 characters from
alphabets around the world.
A string over an alphabet is a finite sequence of symbols drawn from that alphabet.
In language theory, “string” and “word” are generally used as synonyms for string.
A language denotes any set of strings over some fixed alphabet.
• Operation on languages (a set):
– union of L and M, L U M = {s|s is in L or s is in M}
– concatenation of L and M
LM = {st | s is in L and t is in M}
– Kleene closure of L,
– Positive closure of L,
• Example:
– L={aa, bb, cc}, M = {abc}
Regular Expression
Regular expression can be called as a notation which is used in describing all the
Example, languages that can be built from these operators applied to symbol of some alphabet.
If e = {a,b}, The two rules which form the basics are,
1. The regular expression a|b denotes 1. if e is a regular expression , then L(e) is {e} where e is the only sole member
{a,b} in empty string.
2. (a|b)(a|b) denotes {aa,ab,ba,bb} 2. If a is a symbol e, then regular expression L(a) = {a} that is the language with
3. a* denotes {e,a,aa,aaa…..} one string, length one and position one.
Regular Definitions
Example, The regular definition is a type of regular expression used for notational convenience.
The C identifiers consists of strings, If e is an alphabet of basic symbols, then a regular definition is a sequence of the
digits and underscores, the regular form,
definition for C identifiers is, d1 à r1
Letter_ à A|B|….|Z|a|b|…..|_ d2 à r2
Digit à0|1|2|…..|9 …
Idà letter_(letter|digit)* dnàrn
where, each di is a new symbol, not in e and not same as any other of the d’s and
• Examples: each ri is the regular expression over the alphabet e U {d1,d2,d3……di-1}
– let • Formal definition of Regular expression:
a|b Given an alphabet ,
(a | b) (a | b) – f is a regular expression that denote { }, the set that contains the empty
a* string.
(a | b)* – For each a Îå , a is a regular expression denote {a}, the set containing
a | a*b the string a.
– We assume that ‘*’ has the – r and s are regular expressions denoting the language (set) L(r ) and L(s ). Then
highest precedence and is » ( r ) | ( s ) is a regular expression denoting L( r ) U L( s )
left associative. Concatenation » ( r ) ( s ) is a regular expression denoting L( r ) L ( s )
has second highest precedence » ( r )* is a regular expression denoting (L ( r )) *
and is left associative and ‘|’ • Regular expression is defined together with the language it denotes.
has the lowest precedence Recognition of tokens
and is left associative
The piece of code which is given as the input to lexical analyzer matches for the
» (a) | ((b)*(c)) = a | b*c
pattern and returns the respective tokens. For example,
Stmtà if expr then stmt
| Elsestmt
| e
Exprà term relop term
| term
Term à id
| number
COMPILER DESIGN S3-293
In this the terms if, then, else, relop, id and number are the names of the tokens as
the lexical analyzer is concerned and these are the reserved words.
Transition diagrams
Transition diagrams have a collection of nodes, edges, where nodes are called stated.
Each state represents a state that could occur during scanning the input looking for
a lexeme that matches one of several patterns. Edges are directed from one state to
another state in the transition diagram and are labeled by a symbol or set of symbols,
certain subsets are called final states.
Transition proceeds from one state to another along the edges as per the next input
character. Every string or the input ends up at a final state is accepted. There would
be an error, if gets stuck and there is no transition for a given character.
Transition diagram
0 a 1 2 3
Start b b
b
NFA accepting (a/b)*abb
Symbol
Table
Position of Parser in Compiler model
Generally there are three types of parsers, universal parsing methods such as Cocke-
Younger-Kasami algorithm and Earley’s algorithm which can parse any grammar. The
commonly used parsers in the compilers are either top-down or bottom-up. As the
name suggests the top-down parser builds the parse trees from top to bottom i.e from
root to leaves and in the bottom up , the parse tree works up to the root. In both
the cases the input to the parsers is scanned left to right, one symbol at a time.
Syntax Error Handling
The different type of errors which comes up during programming can be categorized
into
– Lexical, like wrong spellings in an identifier, keyword, or operator
– Syntactic, for example arithmetic expression with unbalanced parenthesis
– Semantic, such as an operator applied to wrong operands
– Logical, such as infinity recursive call.
The error detection and recovery in a compiler happens around the syntax analysis
phase.
The error handler in the parser has simple goals like,
– It should report the error clearly and accurately
– It should recover from one error quickly so that it is able to detect
subsequent errors.
– It should not slow down the processing of correct programs.
Error recovery strategies
There are many strategies which a parser employs to recover from a syntactic error.
The following are some of the strategies,
1. Panic mode recovery, it discards the input symbols one at a time until a
designated synchronizing token is found.
2. Phase level recovery, once the error is detected parser performs local
correction on the remaining input. The choice of local correction is left to
the compiler designer.
Example : 3. Error productions, it employs rules for common errors.
Expr àexpr+term 4. Global correction, this strategy involves algorithms for choosing a minimal
Expr à term sequence of changes to obtain globally least cost correction. This is still a
Termàterm*factor theoretical strategy and it is too expensive to implement.
Factorà (expression)
Context free grammar
Factorà id
Op à + 1. Terminals are the basic symbols from which strings are formed. The word
Opà * ‘token’ is a synonym to ‘terminal’
In this grammar, the terminal symbols are 2. Non terminals are the syntactic variables that denote set of strings. For
id, +, * example expr, stmt are non-terminals.
And the non-terminal symbols are expr, 3. In a grammar, one non terminal is denoted as start symbol and set of strings
term, op denotes the language defined by grammar.
COMPILER DESIGN S3-295
4. The grammar production specifies the manner in which the terminals and
non-terminals can be combined to form strings.
Derivations
It starts with start symbol at each step a non- terminal is replaced with the body of
production Example :
Example
E
E ® E + E | E*E | (E) | – E | id
Derivation of – (id) is E ® – E ® – (E) ® – (id)
– E
Parse trees
Parse tree is the graphical representation of derivations. It filters out the non-terminal
replacement. There would be many- one relationship between parse tree derivations. ( )
Context free grammar vs Regular expression E
Grammars are a powerful notation than regular expression. Any construct that can be
described by a regular expression can be easily described by grammar but not vice E E
versa. +
Lexical rules are simple and do not need notation as powerful as grammars. Regular
expressions are more concise and easier to understand for tokens. More efficient
id id
lexical analyzers can be built from regular expressions than from grammars.
The grammar can be enhanced by the following few rules like, Parse tree Example for – (id + id)
1. Eliminating ambiguity, sometimes the grammar can be re-written to eliminate
ambiguity.
2. Eliminating left recursion
3. Left factoring is a method to delay the decision until more info is available.
Top down Parsing
For grammar S ® CAd
In top down, a parse tree is constructed for an input string from root which means
parse tree has been built in preorder(depth first). This also involves finding the left A ® ab|a
most derivation. And at each step of a top down parse, the production to be applied S S S
is determined. It matches the terminal symbols in production body with input string.
The top down Parsing further includes recursive descent parsing and backtracking, C A d C A d C A d
Recursive descent parsing, constructs a parse tree for the input string starting from a
roots and nodes are created in preorder. a b
(1) (2) (3)
First and Follow Steps in top-down Parse
First : For first(a) where a is any string of grammar symbols, to be the set of terminals
that begin strings that are derived 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 form. i.e the set of terminals a such
that there exists a derivation of the form SàaAab.
Consider grammar First Follow Example first and follow :
First (E) = First (T) = First (E') S ® cAd Find a derivation for
E ® TE' {(, id} {) $} A ® ab | a for w ® cad
E' ® +TE'/e {+ e} {) $} S S Backtrack S
T ® FT' {(id} {+) $} /|\ ® /|\ ® /|\
T' ® *FT'/e {*e} {+) $} cAd cAd cAd
F ® (E)/id {(id} {*+) $} / \ |
a b a
Predictive Parser: Generalities
• In many cases, by carefully writing a grammar–eliminating left
recursion from it and left factoring the resulting grammar–we can
obtain a grammar that can be parsed by a recursive-descent parser
that needs no backtracking.
EBD_7203
S3-296 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Such parsers are called predictive parsers.
Left Recursive Grammars I
• A grammar is left recursive if it has a nonterminal A such that there is
a derivation A ® Aa, for some string a
• Top-down parsers can loop forever when facing a left-recursive
rules. Therefore, such rules need to be eliminated.
• A left-recursive rule such as A ® A a | b can be eliminated by
replacing it by:
– A ®bR where R is a new non-terminal
– R®aR|e and e is the empty string
• The new grammar is right-recursive
Left-Recursive Grammars II
• The general procedure for removing direct left recursion–recursion
that occurs in one rule–is the following:
– Group the A-rules as
A ® Aa1 |… | Aam | b1 | b2 |…| bn
where none of the b’s begins with A
– Replace the original A-rules with
» A ® b1A’ | b2 A’ | … | bn A’
» A’ ® a1 A’ | a2 A’ | … | am A’
• This procedure will not eliminate indirect left recursion of the kind:
– A ® BaA
– B ® Ab
Direct or Indirect Left-Recursion is problematic for all top-down parsers.
However, it is not a problem for bottom-up parsing algorithms
Left-Recursive Grammars III
Here is an example of a (directly) left-recursive grammar
E ®E+T|T
T ®T*F|F
F ® (E) | id
This grammar can be re-written as the following non left-recursive grammar:
E ® T E’ E’ ® + TE’ | e
T ® F T’ T' ® * FT’ | e
F ® (E) | id
Left-Factoring a Grammar I
• Left Recursion is not the only trait that disallows top-down parsing.
• Another is whether the parser can always choose the correct Right
Hand Side on the basis of the next token of input, using only the first
token generated by the leftmost nonterminal in the current derivation.
COMPILER DESIGN S3-297
To ensure that this is possible, we need to left-factor the non left-recursive
grammar generated in the previous step.
Left-Factoring a Grammar II
Here is the procedure used to left-factor a grammar:
• For each non-terminal A, find the longest prefix a common to two or
more of its alternatives.
• Replace all the A productions:
A ® ab1 | ab2 … | abn | g
(where g represents all alternatives that do not begin with a)
– By:
A ® a A' | g
A' ® b1 | b2 | … | bn
Left-Factoring a Grammar III
• Here is an example of a common grammar that needs left factoring:
S ® iEtS | iEtSeS | a
E®b
( i stands for “if”; t stands for “then”; and e stands for “else”)
Left factored, this grammar becomes
S ® iEtSS’ | a
S’ ® eS | e
E®b
LL(1) Grammar
• A grammar whose passing table has no multiply-defined entries is said to be
LL(1).
• No ambigous or left-recussive grammar can be LL(1).
• A grammar G is LL(1) if whenever A ® a|b are two distinct productions, the
following three conditions hold.
1. For no terminal a do both a and b derive strings beginning with a.
2. At most one of a and b can derive the empty string.
3. If b derives the empty string, then a does not derive any string beginning
with a terminal in follow (A). Like wise, if a derives the empty string, then b
does not derive any string beginning with a terminal in follow (A).
Parsing table
Parsing table is a two dimensional array consisting of rows and columns where rows
are non-terminals and columns are the input symbols.M [A,a] where A is a non-
terminal and a is terminal or $. This gives the production rules to use.
Parsing table : For grammer s ® iEt ss'/E, s' ® es/E, E ® b
EBD_7203
S3-298 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Inp ut Sy mb ol
No n-Terminal
a b e i t $
s s®a
s' s' ® e s' ® e
s ' ® es
E E® b
• The predictive parser considers X, the symbol on top of the stack, and a, the
current input symbol. It uses, M, the parsing table.
– If X = a = $ ® halt and return success
– If X = a ¹ $ ® pop X off the stack and advance input pointer to the next
symbol
– If X is a non-terminal ® Check M[X,a]
» If the entry is a production rule, then replace X on the stack by the
Right Hand Side of the production
» If the entry is blank, then halt and return failure
Constructing the Parsing Table I: First and Follow
• First(a) is the set of terminals that begin the strings derived from a. Follow(A)
is the set of terminals a that can appear to the right of A. First and Follow are
used in the construction of the parsing table.
• Computing First:
– If X is a terminal, then First(X) is {X}
– If X ® e is a production, then add ? to First(X)
– If X is a non-terminal and X ® Y1 Y2 … Yk is 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)
Constructing the Parsing Table II: First and Follow
Computing Follow:
– Place $ in Follow(S), where S is the start symbol and $ is the input right
endmarker.
– If there is a production A ®aBb, then everything in First(b) except for
e is placed in Follow(B).
– If there is a production A ®aB, or a production A ®aBb where First(b)
contains e, then everything in Follow(A) is in Follow(B)
Example: E ® TE' E' ® +TE' | e
T ® FT' T' ® *FT' | e
F ® (E) | id
First(E) = First(T) = First(F) = {(, id} First(E') = {+, e} First(T') = {*, e}
Follow(E) = Follow(E') = {),$} Follow(F)={+,*,),$} Follow(T) = Follow(T') = {+,),$}
Constructing the Parsing Table III
Algorithm for constructing a predictive parsing table:
1. For each production A ® a of the grammar, do steps 2 and 3
2. For each terminal a in First(a), add A ® a to M[A, a]
3. If e is in First(a), add A ® a to M[A, b] for each terminal b in Follow(A). If
e is in First(a), add A ® a to M[A,b] for each terminal b in Follow(A). If e
is in First(a) and $ is in Follow(A), add A ® a to M[A, $].
4. Make each undefined entry of M be an error.
Bottom up Parsing
It gives a string of terminals. In this method, the parse tree is built from leaves and
working up towards the root. This is the reverse of right most derivation and used
for type of grammar called LR. LR parsers are difficult to build by hand, hence we
use automatic parser generators for LR grammars.
COMPILER DESIGN S3-299
Bottom up Parsing
Given,
E ® T ® T * F ® T * id ® F*id® id*id
F*id F*id T* F T E
id F id T * F
F T
F id T * F
id id
id F id
id
Shift reduce Parsing
This is a type of bottom up parsing. It consists of stacks which hold grammar
symbols,
Input buffer, which holds the rest of the string to be parsed. The handle always
appears on top of the stack.
Shift reduce Parsing
Actions in shift reduce Parsesr ® shift, reduce, accept, error.
For grammar E ® E + T|F
T ® T *F|F
F ® (e)|id
Stack INPUT Action
$ $id*id2$ Shift
$id *id12 $ reduce by F ® id
$F *id2$ reduce by T®F
$T *id2$ shift
$T* *id2$ shift
$T*id2 $ reduce by F ® id
$T*F $ reduce by T ® T*F
*T $ reduce by E®T
$E $ Accept
SYNTAX DIRECTED TRANSLATION
Syntax directed translation means driving the entire compilation process with the
syntax recognizer (parser). The parsing processes and parse trees are used to direct
semantic analysis and translation of source program.
The conceptual view of syntax-directed translation,
Input string à parse tree à dependency graph à evaluation order for semantic
rules
There are two notations for associating semantic rules with productions; they are
syntax-directed definitions and translation schemes.
Syntax directed definitions are high level specifications for translations. They hide the
implementation details and the user need not specify explicitly the order in which the
transaction takes place. Translation schemes indicate the order in which the semantic
rules are to be evaluated.
Syntax directed definitions (SDD)
This is a generalization of context free grammar in which each grammar symbol has
an associated set of attributes and rules. Attributes are associated with grammar
symbols and rules are associated with productions.
EBD_7203
S3-300 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
An attribute has a name and an associated value like a string , a number, a type, a
memory location, a register or strings. The strings may be long sequences of code,
which is the code in the intermediate language used by a compiler. Attributes are
evaluated by semantic rules attached to the production.
Example: Production Semantic rule
E à E1 + T E.code = E1.code || T.code|| ‘+’
Syntax directed translation schemes (SDT)
A SDT scheme is a context free grammar in which attributes are associated with
grammar symbols and they are placed within braces ({ }) and are inserted in the right
sides of the production. The position of the semantic action of the production body
determines the precision of the action taken by the parser.
Example: Eà E+T {print ‘+’} , the action is placed after the body of the production.
SDTs are more efficient than SDD’s as SDT indicates the order of the semantic action
which is associated with the production rule.
Attributes in syntax directed definition are further divided into synthesized attributes
and inherited attributes.
Synthesized attributes are extensively used in practice. The syntax directed definition
that uses synthesized attributes is called as S-attributed definition. A parse tree for
an S-attributed definition can always be interpreted by evaluating the semantic rules
bottom up, i.e from leaves to the root.
Inherited attributes are the one whose value at a node in a parse tree is defined in
terms of attributes at parent or sibling nodes in a parse tree.
Attribute Grammar, An SDD without side effects sometimes is called an attribute
grammar.
Evaluating an SDD at the nodes of a parse tree.
Parse tree helps us to understand the translation specified by SDD. The rules of SDD
is applied to construct the parse tree and evaluate the attributes at each of the nodes
of the parse tree using rules. A parse tree which shows the value of its attribute is
called annotated parsing tree.
Example : An annotated parse tree for 2*6+ 4n
Annotated parse tree for 2 * 6 + 4n
L.vol = 16
E.vol = 16 n
E.vol = 12 + T.vol = 4
T.vol = 12 F.vol = 4
F.vol = 2 digit.lexvol = 6
digit.lexvol = 2
An SDD does not ensure any definite order with either synthesized or inherited
attributes
Evaluation order for SDD’s
Dependency Graph : Using dependency graph we can determine the evaluation order
for attribute instances in a parse tree. With an annotated parse tree which shows the
value of the attributes, the dependency graphs help us to understand how the values
are computed.
COMPILER DESIGN S3-301
A dependency graph shows the flow of information in the parse tree. An edge in the
dependency graph from one attribute instance to another means the value of the first
is needed to evaluate the value of second.
The constraints of the edges implied semantic rules,
– Each attribute is associated with a node in the parse tree
– If in a semantic rule, a production p defines the value of synthesized attribute
A.b in terms of X.c , then the graph is having an edge from A.b to X.c
– An edge exists for inherited attributes too in similar conditions.
Example : for dependency graph for the annotated parse tree 3*5
Dependency graph for 3*5 T9 vol
F3 vol inh 5T
1 8 syn
inh 6T
1 7 syn
digit 1 lexvol * F4 vol
digit 2 lexvol
Syntax Tree
+
* 4
3 5 Example of SDD
Production
S-attributed Definitions
An SDD is S-attributed if every attribute is synthesized. S-attributed definitions is 1) L -> E n
evaluated in bottom up fashion in a parse tree and it can be implemented during 2) E -> E1 + T
bottom-up parsing as bottom up traversal corresponds to post order traversal and 3) E -> T
post order corresponds to the order in which an LR parser reduces a production body 4) T -> T1 * F
to its head. 5) T -> F
L-attributed definitions 6) F -> (E)
Between the attributes associated with production body, the edges in the dependency 7) F -> digit
graph can go from left to right but not right to left. Hence the name L-attributed. Following are the corresponding
Each attribute must be either semantic rules
– Synthesized attributes L.val = E.val
– Inherited attribute. It follows certain rules, E.val = E1.val + T.val
For a given production AàX1 X2…..Xn and there is an inherited attribute Xi.a E.val = T.val
associated with this production. Then the rule may use only, T.val = T1.val * F.val
1. Inherited attributes associated with head A. T.val = F.val
2. Either synthesized attribute or inherited attribute with the occurences F.val = E.val
X1 X2 …Xi-1 F.val = digit.lexval
Located to the left of Xi
3. There should not be any cycles in the dependency graph for the
occurrences of Xi formed by the attributes of Xi.
Controlled side effects :
Attribute grammar have no side effects and allow any evaluation order consistent
with dependency graph whereas translation schemes allows only left to right
evaluation and allow schematic actions to contain any fragment.
The ways to control the side effects ,
– To permit incidental side effects which do not disturb attribute evaluation
– Impose restrictions on allowable evaluation orders
EBD_7203
S3-302 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Application of Syntax-directed translations
1. Construction of Syntax trees
SDD’s are useful for construction of syntax trees. A syntax tree is a condensed
form of parse tree.
Eg:
Syntax tree for a + 2 * c
E. node
E. node
E. node * T. node
+ T. node id
T. node num
*
id
*
id
id to entry for c
num 2
to entry for a
This is represented by grammar
E ® E1 + T
E ® E1 – T
E®T
T ® (E)
T ® (id)
T ® num
Syntax trees are useful for constructs like expression, statements in a programming
language. They help compiler design by decoupling parsing from translation. Each
node of a syntax tree represents a construct; the children of the node represent the
meaningful components of the construct.
Application of syntax directed translation
Production Semantic Rule
1) E -> E1 + T E.node=new node('+', E1.node,T.node)
2) E -> E1 - T E.node=new node('-', E1.node,T.node)
3) E -> T E.node = T.node
4 ) T -> (E) T.node = E.node
5) T -> id T.node = new Leaf(id,id.entry)
6) T -> num T.node = new Leaf(num,num.val)
Syntax tree for L-attributed definition
Production __ Semantic Rules
1) E -> TE'
1. E.node=E'.syn
2) E' -> + TE1' E'.inh=T.node
2. E1'.inh=new node('+', E'.inh,T.node)
3) E' -> -TE1' E'.syn=E1'.syn
4) E' -> e 3. E1'.inh=new node('+', E'.inh,T.node)
E'.syn=E1'.syn
5) T -> (E) 4. E'.syn = E'.inh
6) T -> id 5. T.node = E.node
6. T.node=new Leaf(id,id.entry)
7) T -> num __ 7. T.node = new Leaf(num,num.val)
COMPILER DESIGN S3-303
Postfix translation schemes
SDT’s with all actions at the right ends of the production bodies are called postfix
SDT’s
1) Example:L -> E n {print(E.val);}
2) E -> E1 + T {E.val=E1.val+T.val;}
3) E -> T {E.val = T.val;}
4) T -> T1 * F {T.val=T1.val*F.val;}
5) T -> F {T.val=F.val;}
6) F -> (E) {F.val=E.val;}
7) F -> digit {F.val=digit.lexval;}
Parse-Stack implementation of postfix SDT’s
• 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 associate a record holding
its attributes
• Then in a reduction step we can execute the semantic action at the end of a
production to evaluate the attribute(s) of the non-terminal at the leftside of the
production
• And put the value on the stack in replace of the rightside of production
Example:
L -> E n {print(stack[top-1].val); top=top-1;}
E -> E1 + T {stack[top-2].val=stack[top-2].val+stack.val; top=top-2;}
E -> T
T -> T1 * F {stack[top-2].val=stack[top-2].val+stack.val; top=top-2;}
T -> F
F -> (E) {stack[top-2].val=stack[top-1].val; top=top-2;}
F -> digit
SDT’s for L-Attributed definitions
• We can convert an L-attributed SDD into an SDT using following two rules:
1. Embed the action that computes the inherited attributes for a nonterminal
A immediately before that occurrence of A. if several inherited attributes
of A are dependent on one another in an acyclic fashion, order them so
that those needed first are computed first.
2. Place the action of a synthesized attribute for the head of a production
at the end of the body of the production
Example :
S -> while (C) S1 L1=new();
L2=new();
S1.next=L1;
C.false=S.next;
C.true=L2;
S.code=label||L1||C.code||label||L2||S1.code
x : 15 Example :
y : 10 Global static area Calculate the GCD of two numbers
#include <stdio.h>
Int x,y;
Activation record
of main Int gcd(int u, intv)
{ if (v==0) then return u;
u : 15
Else return gcd(v,u%v);
v : 10 Activation record }
control link of first call of gcd
Main()
Return address
{
u : 10 Scanf (%d,%d, &x, &y);
v:5 Activation record Printf(“%d\n”, gcd(x,y));
control link of second call of gcd Return 0;
Fp Return address }
For the input x= 10 and y= 15
Free space Direction of
Sp
stack growth
Access to names
Access to names
Parameters and local variables can be accessed by offset from the pointer to the
a
activation record. The offset can be statically computed by the compiler and the
memory allocation to each declaration is fixed by its data type.
Example : b
Void f(intx, char c)
offset offset b
{ int a, double y; of a
…. control
} link
The activation record for call f would be
Assuming 2 bytes for integers, four bytes for addresses, one byte for character, and
eight bytes double precision floating point , the offset values would Return
CAP offset of y
Name Offset address
X +5
C +4
A -24
Y -32
Variable length data
The number of parameters may vary from call to call and size of array parameter or
a local variable may also vary. C compiler pushes the arguments in a reverse order
on to the stack and a first parameter is always located at a fixed offset from CAP.
Local temporaries and Nested declaration
Two or more complications for stack based environment during run time is local
temporaries and nested declaration
Local temporaries are the partial results that must be saved across the procedure calls,
X[i] = (i+j) *(i/k + f(K);
The three partial addresses that must be saved across the procedure call f are
X[i], (i+j) and i/k
COMPILER DESIGN S3-307
The runtime stack may appear as shown:-
(rest of stock)
Address of x [I]
Sp Result of I/j
New activation
record of call to f
Free space (about to created)
Local temporaries
Nested declaration
Consider the C code
(rest of stock)
x;
y;
Fp control link
a;
x;
Sp J;
Free space
EBD_7203
S3-308 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
There are two blocks A and B nested inside the procedure body p. The nested local
declaration need not be allocated till entered. Both A and B need to be allocated
simultaneously.
Dynamic Memory
The stack based environment is better than static environment, but has the problem
of dangling reference.
The dangling reference defect is explained below,
Consider the following C code,
Main()
{ int * a;
P; dangle ( );
}
Int * dangle ( )
{ int I =20;
Return & i;
}
‘i’ cannot be accessed after activation records of dangle is freed. The stack cannot Example of dynamic memory allocation
be accessed if the values of the local variables have to be retained after the activation Class A Object of class A in memory
records are closed. Hence the stack based environment is not suitable for general { Public
environment. The alternative solution for this is dynamic memory allocation. unit x, y; x
In this case the deallocation of activation records is done at arbitrary time during void fun, (1;
execution. The dynamic environment is complex as compared to stack based as it has virtual void g ();
to take care of keeping references and freeing unwanted areas of memory at arbitrary }; y
time. The concept is called garbage collection.
Dynamic memory in object oriented language Class B; Public A virtual function
{ Public table pointer
Object oriented language supports for objects, methods, inheritance. The dynamic
binding of an object in memory is combination of record and activation record with unit i;
instance variables as fields of record. This can be implemented using virtual function void fun, ();
return address
virtual void h ();
table. The table consists of list of pointers to method of each class.
}; B
Heap management
Heap Management
Heap is a linear block of memory which is used to handle pointer allocation and
deallocation. The two operations performed in heap are allocate and free. Allocate
operation takes the input of required memory in form of bytes and returns the pointer Next
to block of available memory of defined size. If no memory exists then it returns null
pointer. Free operation is used to free the allocated block of memory.
Different languages use different keywords to allocate and free the memory. Pascal Size of used area
uses new and dispose, C++ uses new and delete and C language uses malloc and
free as a part of standard library stdlib.h.
One way of implementing is maintaining a circular list of free blocks. This is easy to Size of free area
implement and maintain , it has few disadvantages. The pointer to free block may
not be given to malloc and user giving invalid pointer corrupts heap. Secondly there
can be smaller fragments of free blocks. It has to compact all free blocks to get a larger Used area
chunk of free block.
An efficient way of heap implementation is using circular linked list which keeps track
of allocated and free blocks. Heap consists of nodes, next pointers, pointer memptr.
Free area
Nodes have the information of free space and used space. The next pointer points
to next memory block in heap. Memptr points to block which has some free space.
Automated management of heap
Malloc and free are explicitly used for allocating and freeing space in C language.
Fully dynamic runtime environment automatically collects the free spaces of the
previous allocated blocks which are not used further for an explicit free call. This
process is called garbage collection.
COMPILER DESIGN S3-309
Garbage collection can be achieved by following methods,
1. Mark and sweep: The memory is not freed until malloc fails for insufficient
memory. When this happens, the mark process marks the memory block which
are not used anymore. In the sweep process, the marked blocks are cleared and
put into free list.
2. Stop and copy : The memory is divided into two halves and allocates storage
from one half at a time. During the marking process all the updated blocks are
stored in second half(The blocks whose values are changed). When all the
blocks in used area is copied, the used and unused halves of memory are
interchanged and process continues.
3. General garbage collection: The allocated objects that stay for a long time are
copied onto permanent space and not allocated during reclamation. This
reduces the time for searching as it reduces the space for new storage.
INTERMEDIATE CODE GENERATION
The front end analyses the source program and creates an intermediate code
representation. The back end makes use of this code and generates target code. This
enables to attach a back end for the new machine to an existing front end. This is
a typical scenario in analysis-synthesis model.
Logical representation of a compiler front end
The compiler front end is organized as shown in the diagram which includes static
checking, parsing and intermediate code generation. These are done sequentially.
Logical structure of a compiler front end
Static checking
This includes the syntactic checks like
– Control flow , eg: break statement with a loop construct
– Uniqueness checks, eg: labels in case statements
– Name related checks
Intermediate representation
The source program can be directly translated to target program without intermediate
code. However the benefits of intermediate code are,
– There will be a clear distinction between the machine independent and
machine dependent parts of compiler.
– It facilitates retargeting
– The application of machine independent code optimization techiniques.
There are various options for intermediate code language. They can be either
– Specific to the language being implemented
p-code for pascal and bytecode for java
– Language independent
3-address code
Intermediate representation can either be actual language or group of internal data
structures which is used by phases of compiler. In IR phase, the syntax tree which
is created during syntax and semantic analysis is linearized. These will be equivalent
to single or small number of machine instructions. The machine code is then
generated.
Syntax Trees
Syntax trees are suited for static type of checking and they are high level of IR. They
are natural hierarchical structure of the source program.
EBD_7203
S3-310 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example:
Syntax trees
DAG for the expression a + a * (b – c)
+
+ (b – c) * d is shown below
while if assg
+ id *
0 minus c t1
1 * b t1 t2
2 minus c t3
3 * b t3 t4
4 + t2 t4 t5
5 = t5 a
COMPILER DESIGN S3-311
Example,
– Triples: This representation has only three fields for each instruction op,arg1 Triples
and arg2. The result of operation x= y op z will be represented by its position op org1 org2
– Indirect triples: This consists of pointers to triples rather than the set of triples.
– Static single-assignment form: SSA form is an intermediate representation that 0 minus c
facilitates certain code optimizations.
1 * b (0)
Types
A type generally denotes a set of values or set of operations which are allowed on 2 minus c
the values. The applications of types are type checking and translation.
Type checking : this is a process of verifying fully typed program. The goal of type 3 * b (2)
checking is to ensure the operations are used with correct types. (1) (3)
4 +
Type System components
– Built in types 5 = a (4)
– Rules for constructing new types
– Rules to determine whether two types are equivalent
– Rules for inferring types of expressions.
Translation application of types
The storage needed for a type of name can be determined during the runtime. It
calculates the address denoted by an array reference, insert explicit type conversions
and choose the correct version of an arithmetic operator.
Declarations
D ® Tid; D | e
T ® Bc | record '{'D'}'
B ® int | float
C ® e | [num] c
declares just one at a time; D-generates a sequence of declarations T-generates basic,
array or record types, c-for 'component', generates strings of zero or more integers,
each integer surrounded by brackets.
SDT for computing types,
T ® BC {t = B type; w = B. width}
B ® int {B type = integer; B. width = 4}
B ® flint {B type = float; width = 8}
C ® e {C type = t; C. width = w;}
C ® [num] C1{array(num. value, C1. type); C. width = num. value × C1.width;}
Addressing array elements
The base address is associated with the array name. i.e the offset stored in the
identifier table is the address of the first element of the array. The indices and the
array bounds are used to compute the amount, which the address of the referenced
element differs from the base address. double
Type checking
float
Now the type checking is explained in detail. This includes several aspects,
– The language comes with a type system which consists of set of rules on long
the types.
– The compiler assigns a type expression to parts of the source program int
– The compiler checks the type usage in the program.
Rules for type checking short char
Symbol
Table
Absolute M M 1
Statements for Linked Answer Questions 1 and 2: 6. The grammar A ® AA | (A) | Î is not suitable for predictive-
Consider the following expression grammar. The semantic rules parsing because the grammar is [2005, 1 mark]
for expression evaluation are stated next to each grammar (a) ambiguous (b) left-recursive
production. [2005, 2 marks] (c) right-recursive (d) an operator grammar
E ® number E.val = number.val Statements for Linked Answer Questions 7 and 8:
| E ‘+’ E E(1).val = E(2).val + E(3).val 7. Which one of the following grammars generates the
| E ‘×’ E E(1).val = E(2).val × E(3).val
language
1. The above grammar and the semantic rules are fed to a yacc
tool (which is an LALR (1) parser generator) for parsing and L = {ai bj} i ¹ j]? [2006, 2 marks]
evaluating arithmetic expressions. Which one of the (a) S ® AC | CB (b) S ® aS | Sb |a| b
following is true about the action of yacc for the given C ® aC b |a|b
grammar? A ® aA | Î
(a) It detects recursion and eliminates recursion B ® bB | Î
(b) It detects reduce-reduce conflict and resolves (c) S ® AC | CB (d) S ® AC | CB
(c) It detects shift-reduce conflict and resolves the conflict C ® aC b | Î C ® aC b | Î
in favour of a shift over a reduce action A ® aA | Î A ® aA |a
(d) It detects shift reduce conflict, and resolves the conflict B ® Bb | Î B ® bB |b
in favour of a reduce over a shift action 8. In the correct grammar above, what is the length of the
derivation (number of steps starting from S) to generate the
2. Assume the conflicts in Part (a) of this question are resolved string albm with l ¹ m? [2006, 2 marks]
and an LALR(1) parser is generated for parsing arithmetic (a) max (l, m) + 2 (b) l + m + 2
expressions as per the given associativity properties does (c) l + m + 3 (d) max (l, m) + 3
the generated parser realize? 9. Consider the following C code segment: [2006, 2 marks]
(a) Equal precedence and left associativity; expression is for (i = 0, i < n; i ++) {
evaluated to 7 for (j = 0, j < n; j ++) {
(b) Equal precedence and left associativity; expression is
if (i % 2){
evaluated to 9
(c) Precedence of ‘x’ is higher than that of ‘+’ and both x + = (4 * j + 5 * i);
operators are left associative; expression is evaluated Y + = (7 + 4 * j); }}}
to 7 Which one of the following is false?
(d) Precedence of ‘+’ is higher than that of ‘×’ and both (a) The code contains loop invariant computation.
operators are left associative; expression is evaluated (b) There is scope of common sub-expression elimination
to 9 in this code
3. Consider line number 3 of the following C program: (c) There is scope of strength reduction in this code
int min () { /* Line 1 */ (d) There is scope of dead code elimination in this code
int I, N; /* Line 2 */ 10. Consider the following translation scheme:
fro (I = 0, I < N, I ++); /* Line 3 */ S ® FR [2006, 2 marks]
Identify the compiler’s response about this line while R ® *E{print (‘*’); R|e
creating the object-module. [2005, 2 marks] E ® F + E {print (‘+’); |F
(a) No compilation error (b) Only a lexical error F ® (S)| id {print (id. value);}
(c) Only syntactic errors
Here, id is a token that represents an integer and id value
(d) Both lexical and syntactic errors
4. Consider the grammar S ® (S) | a [2005, 2 marks] represents, the corresponding integer value. For an input
Let the number of states in SLR (1), LR(1) and LALR (1) ‘2 * 3 + 4’, this translation scheme prints.
parsers for the grammar be n1, n2 and n3 respectively. Which (a) 2 * 3 + 4 (b) 2 * + 3 4
of the following relationships holds good? (c) 2 3 * 4 + (d) 2 3 4 + *
(a) n1 < n2 < n3 (b) n1 = n3 < n2 11. Consider the following grammar: [2006, 2 marks]
(c) n1 = n2 = n3 (b) n1 ³ n3 ³ n2 S ® FR
5. Consider the grammar [2005, 2 marks] R ® *S|e
E ®E+n|E×n|n F ® id
For a sentence n + n × n, the handles in the right-sentential In the predictive parser table, M, of the grammar the entries
form of the reduction are M [S, id] and M[R, $] respectively.
(a) n, E + n and E + n × n (b) n, E + n and E + E × n (a) {S ® FR} and {R ® e] (b) {S ® FR} and {}
(c) n, n + n and n + n × n (d) n, E + n and E × n (c) {S ® FR} and {R ® *S}(d) {F ® id} and {R ® e}
EBD_7203
S3-318 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
12. Consider the following grammar. [2006, 1 mark] Which of the following is true?
S®S*E (a) Both P and Q are true
S®E (b) P is true and Q is false
E ®F+E (c) P is false and Q is true
E ®F (d) Both P and Q are false
F ® id
17. Consider the grammar with non-terminals N = {S, C, S1},
Consider the following LR (0) items corresponding to the
terminals T = {a, b, i, t, e} with S as the start symbol and the
grammar above.
1. S ® S * E following set of rules [2007, 2 marks]
2. E ® F. + E S ® iCtSS1 | a
3. E ® F + .E S1 ® eS | e
Given the items above, which two of them will appear in the C®b
same set in the canonical sets-of-items for the grammar? The grammar is not LL(1) because
(a) 1 and 2 (b) 2 and 3 (a) it is left recursive (b) it is right recursive
(c) 1 and 3 (d) None of these (c) it is ambiguous (d) it is not context-free
Statements for Linked Answer Questions 13 and 14 : 18. Which one of the following is a top-down parser?
Consider the CFG with {S, A, B} as the non-terminal alphabet, (a) Recursive descent parser [2007, 1 mark]
{a, b} as the terminal alphabet, S as the start symbol and the (b) Operator precedence parser
following set of production rules [2007, 2 marks] (c) An LR (k) parser
S ® aB S ® bA (d) An LALR (k) parser
B®b A®a 19. An LALR(1) parser for a grammar G can have shift-reduce
B ® bS A ® aS (S-R) conflicts, if and only, if [2008, 2 marks]
B ® aBB A ® bAA (a) the SLR (1) parser for G has S-R conflicts
(b) the LR (1) parser for G has S-R conflicts
13. Which of the following strings is generated by the grammar?
(c) the LR (0) parser for G has S-R conflicts
(a) aaaabb (b) aabbbb
(d) the LALR (1) parser for G has reduce-reduce conflicts
(c) aabbab (d) abbbba
20. Which of the following are true? [2008, 2 marks]
14. For the correct answer strings to Q. 27, how many derivation 1. A programming language which does not permit global
trees are there? variables of any kind and has no nesting of
(a) 1 (b) 2 procedures/functions, but permits recursive can be
(c) 3 (d) 4 implemented with static storage allocation
15. In a simplified computer, the instructions are 2. Multi-level access link (or display) arrangement is
OP Rj, Ri – Performs Rj OP Ri and stores the result in register needed to arrange activation records only, if the
Ri. programming language being implemented has nesting
OP m, Rj – Performs val OP Ri and stores the result in Rj. val of procedures/functions.
denotes the content of memory location m. 3. Recursion in programming languages cannot be
MOV m, Ri – Moves the content of memory location m to implemented with dynamic storage allocation
register Ri. 4. Nesting of procedures/functions and recursion require
a dynamic heap allocation scheme and cannot be
MOV, Ri, m – Moves the content of the register Ri to memory
implemented with a stack-based allocation scheme for
location m.
activation records.
The computer has only two registers, and OP is either ADD 5. Programming languages which permit a function to
or SUB. Consider the following basic block: return a function as its result cannot be implemented
t1 = a + b with a stack based storage allocation scheme for
t2 = c + d activation records
t3 = e – t2 (a) 2 and 5 (b) 1, 3 and 4
t4 = t1 – t3 (c) 1, 2 and 5 (d) 2, 3 and 5
Assume that all operands are initially in memory. The final 21. Some code optimizations are carried out on the intermediate
value of the computation should be in memory. What is the code because [2008, 1 mark]
minimum number of MOV instructions in the code generated (a) they enhance the portability of the compiler to other
for this basic block? [2007, 2 marks] target processors
(b) program analysis is more accurate on intermediate code
(a) 2 (b) 3
than on machine code
(c) 5 (d) 6 (c) the information from data flow analysis cannot be used
16. Consider the following two statements: [2007, 2 marks] for optimization
P: Every regular grammar is LL (1). (d) the information from the front end cannot be used for
Q : Every regular set has a LR (1) grammar. optimization
COMPILER DESIGN S3-319
22. Which of the following describes a handle (as applicable to 27. In a compiler, keyboards of a language are recognized during
LR-parsing) appropriately? [2008, 1 mark] (a) parsing of the program [2011, 1 mark]
(a) It is the position in a sentential form where, the next (b) the code generation
shift or reduce operation will occur (c) the lexical analysis of the program
(b) It is non-terminal whose production will be used for (d) data flow analysis
reduction in the next step 28. The lexical analysis for a modern computer language such
(c) It is a production that may be used for reduction in a as Java needs the power of which one of the following
future step along with a position in the sentential form machine models in a necessary and sufficient sense?
where, the next shift or reduce operation will occur [2011, 1 mark]
(d) It is a production p that may be used for reduction in a (a) Finite state automata
future step along with a position in the sentential form (b) Deterministic push down automata
where, the right hand side of the production may be (c) Non-deterministic push down automata
found. (d) Turing machine
23. Which of the following statements are true? [2009, 2 marks] Statements for Linked Answer Questions 29 and 30 :
1. There exist parsing algorithms for some programming For the grammar below, a partial LL (1) parsing table is also
languages whose complexities ar less than q (n3). presented along with the grammar. Entries that need to be filled
2. A programming language which allows recursive can are indicated as E1, E2 and E3. e is the empty string, $ indicates
be implemented with static storage allocation. end of input and | separates alternate right hand sides of
3. No L-attributed definition can be evaluated in the productions. [2012, 2 marks]
framework of bottom-up parsing.
S®aAbB|bAaB|e
4. Code improving transformations can be performed at
both source language and intermediate code level. A®S
(a) 1 and 2 (b) 1 and 4 B®S
(c) 3 and 4 (d) 1, 3 and 4
24. The grammar S ® aSa | bS| c is [2010, 2 marks] a b $
(a) LL (1) but not LR (1) (b) LR (1) but not LL (1) S E1 E2 S®e
(c) Both LL (1) and LR (1) (d) Neither LL (1) and LR (1)
A A®S A®S error
25. Which data structure in a compiler is used for managing
information about variables and their attributes? B B® S B® S E3
[2010, 1 mark]
29. The FIRST and FOLLOW sets for the non-terminals A and
(a) Abstract syntax-tree (b) Symbol table
(c) Semantic stack (d) Parser table B are
26. Consider two binary operators and ¯ with the precedence (a) FIRST (A) = {a, b, e} = FIRST (B)
of operator ¯ being lower than that of operator . Operator FOLLOW (A) = {a, b}
is right associative while operator ¯ is left associative. FOLLOW (B) = {a, b, $}
Which one of the following represents the parse tree for (b) FIRST (A) = {a, b, $}
expression (7 ¯ 3 4 3 ¯ 2) ? FIRST (B) = {a, b, e}
[2011, 2 marks] FOLLOW (A) = {a, b}
FOLLOW (B) = {$}
(a) ¯ (b) ¯ (c) FIRST (A) = {a, b, e} = FIRST (B)
7 2 FOLLOW (A) = {a, b}
¯ FOLLOW (B) = Æ
3
(d) FIRST (A) = {a, b,} = FIRST (B)
4 ¯ 7
FOLLOW (A) = {a, b}
2 3 FOLLOW (B) = {a, b,}
3 30. The appropriate entries for E1, E2 and E3 are
3
4 (a) E1 : S ® aAbB, A ® S
(c) (d) None of these E2 : S ® bAaB, B ® S
¯ E3 : B ® S
¯
(b) E1 : S ® aAbB, S ® e
7 E2 : S ® bAaB, S ® e
2 E3 : S ® e
(c) E1 : S ® aAbB, S ® e
3 E2 : S ® bAaB, S ® e
E3 : B ® S
3
4 (d) E1 : A ® S, S ® e
E2 : B ® S, S ® e
E3 : B ® S
EBD_7203
S3-320 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
31. What is the maximum number of reduce moves that can II. Psname (scourseno=107 Ù percent>90
be taken by a bottom-up parser for a grammer with no (Registration > no < Students))
epsilon-and unit-production (i.e. of type A ® e and A
® a) to parse a string with n tokens? [2013, 1 Mark] III. {T | $SÎ Students, $RÎ Regist ration
(S.rollno=R.rollno
n Ù R.courseno=107 Ù R.percent>90 Ù
(a) (b) n – 1
2 T.sname=S.sname)}
(c) 2n – 1 (d) 2n IV. {<SN> |$SR$RP (<SR, SN>Î Students Ù <SR, 107,
32. Consider the following two sets of LR(1) items of an
RP>Î Registration Ù RP>90)} [2013, 2 Marks]
LR(1) grammar.
X ® c.X, c/d X ® c.X, $ (a) I, II, III and IV (b) I, II and III only
X ® .cX, c/d X ® .cX, $ (c) I, II and IV only (d) II, III and IV only
X ® .d, c/d X ® .d, $ 36. Which one of the following is FALSE ?
Which of the following statements related to merging of [2014, Set-1, 1 Mark]
the two sets in the corresponding LALR parser is/are (a) A basic block is a sequence of instructions where
false? control enters the sequence at the beginning and exits
1. Cannot be merged since look aheads are different. at the end.
2. Can be merged but will result in S-R conflict. (b) Available expression analysis can be used for common
3. Can be merged but will result in R-R conflict. subexpression elimination.
4. Cannot be merged since goto on c will lead to two (c) Live variable analysis can be used for dead code
different sets. [2013, 2 Marks] elimination.
(a) 1 only (b) 2 only (d) x = 4 * 5 Þ x = 20 is an example of common
(c) 1 and 4 only (d) All of these subexpression elimiantion.
33. Consider the following languages: 37. A canonical set of items is given below
{
L1 = 0p 1q 0r | p, q, r ³ 0 | } S ® L. > R
Q ® R.
On input symbol < the set has [2014, Set-1, 2 Marks]
L2 = {0 p q
1 0 r p, q, r ³ 0, p ¹ r } (a) a shift-reduce conflict and a reduce-reduce conflict.
Which one of the following statements is false? (b) a shift-reduce conflict but not a reduce-reduce conflict.
[2013, 2 Marks] (c) a reduce-reduce conflict but not a shift-reduce conflict.
(a) L2 is context-free (d) neither a shift-reduce nor a reduce-reduce conflict.
(b) L1 Ç L2 is context-free 38. Consider the grammar defined by the following production
rules, with two operators * and +
(c) Complement of L2 is recursive
S®T*P
(d) Complement of L1 is context-free but not regular T®U|T*U
34. What is the logical translation of the following statement? P ®Q+P|Q
“None of my friends are perfect” Q ® Id
[2013, 2 Marks] U ® Id
Which one of the following is TRUE?
(a) $ x ( F ( x ) Ù Ø P ( x )) (b) $ x ( Ø F ( x ) Ù P ( x ) ) [2014, Set-2, 1 Mark]
(a) + is left associative, while * is right associative
(c) $ x ( Ø F ( x ) Ù Ø P ( x )) (d) Ø $ x ( F ( x ) Ù P ( x ) )
(b) + is right associative, while * is left associative
(c) Both + and * are right associative
35. Consider the following relational schema.
(d) Both + and * are left associative
Students (rollno: integer, sname: string)
39. Which one of the following is NOT performed during
Courses (courseno: integer, cname: string)
compilation? [2014, Set-2, 1 Mark]
Registration (rollno: integer, courseno: integer,
(a) Dynamic memory allocation
percent: real)
(b) Type checking
Which of the following queries are equivalent to this
(c) Symbol table management
query in English? (d) Inline expansion
“Find the distinct names of all students who score more 40. For a C program accessing X[i][j][k], the following
than 90% in the course numbered 107” intermediate code is generated by a compiler. Assume that
I. SELECT DISTINCT S.sname the size of an integer is 32 bits and the size of a character is
FROM Students as S, Registration as R 8 bits.
WHERE R.rollno = S.rollno AND R.courseno=107 t0 = i * 1024
AND R.percent > 90 t1 = j * 32
COMPILER DESIGN S3-321
t2 = k * 4 44. Consider the basic block given below.
t3 = t1 + t0 a=b+ c
t4 = t3 + t2 c=a+d
t5 = X[t4] d=b+c
Which one of the following statements about the source e=d-b
code for the C program is CORRECT? a=e+b
[2014, Set-2, 2 Marks] The minimum number of nodes and edges present in the
(a) X is declared as “int X[32][32][8]”. DAG representation of the above basic block respectively
(b) X is declared as “int X[4][1024][32]”. are [2014, Set-3, 2 Marks]
(c) X is declared as “char X[4][32][8]”. (a) 6 and 6 (b) 8 and 10
(d) X is declared as “char X[32][16][2]”. (c) 9 and 12 (d) 4 and 4
41. One of the purposes of using intermediate code in compilers 45. Which one of the following problems is undecidable?
is to [2014, Set-3, 1 Mark] [2014, Set-3, 2 Marks]
(a) make parsing and semantic analysis simpler. (a) Deciding if a given context-free grammar is ambiguous.
(b) improve error recovery and error reporting. (b) Deciding if a given string is generated by a given
(c) increase the chances of reusing the machine- context-free grammar.
independent code optimizer in other compilers. (c) Deciding if the language generated by a given context-
(d) improve the register allocation. free grammar is empty.
42. Which of the following statements are CORRECT? (d) Deciding if the language generated by a given context-
(1) Static allocation of all data areas by a compiler makes free grammar is finite.
it impossible to implement recursion. 46. Consider the following languages over the alphabet
(2) Automatic garbage collection is essential to implement S = {0, 1, c}:
recursion. L1 = {0n1n | n ³ 0}
(3) Dynamic allocation of activation records is essential L2 = {wcwr |w Î {0, 1}*}
to implement recursion. L3 = {wwr |w Î {0, 1}*}
(4) Both heap and stack are essential to implement Here, wr is the reverse of the string w. Which of these
recursion. [2014, Set-3, 1 Mark] languages are deterministic Context-free languages?
(a) 1 and 2 only (b) 2 and 3 only [2014, Set-3, 2 Marks]
(c) 3 and 4 only (d) 1 and 3 only (a) None of the languages
43. Consider a paging hardware with a TLB. Assume that the (b) Only L1
entire page table and all the pages are in the physical memory. (c) Only L1 and L2
It takes 10 milliseconds to search the TLB and 80 milliseconds (d) All the three languages
to access the physical memory. If the TLB hit ratio is 0.6, the
effective memory access time (in milliseconds) is
_________. [2014, Set-3, 2 Marks]
EBD_7203
S3-322 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Which is not true about syntax and semantic parts of a (a) 1 only (b) 1 and 2
computer language (c) 1, 2 and 3 (d) 4 only
(a) Syntax is generally checked by the programmer. 9. A compiler is
(b) Semantics is the responsibility of the programmer. (a) A program that places programs into memory and
(c) Semantics is checked mechanically by a computer. prepares them for execution
(d) Both (b) and (c) above (b) A program that automates the translation of assembly
2. Operator-precedence parsing method is a parsing method. language into machine language
Which of the following statement is false about it?
(c) program that accepts a program written in a high level
1. It is bottom-up parsing method
language and produces an object program.
2. It must contains Î -production.
3. It doesn’t contains two adjacent nonterminal symbols. (d) a program that appears to execute a source program as
(a) 1 only (b) 2 only if it were machine language
(c) 3 only (d) 1 and 3 only 10. Which of the following are language processors?
3. If conversion from one type to another type is done (a) assembler (b) compilers
automatically by the compiler then, it is called (c) interpreters (d) all of these
(a) implicit conversion (b) coercions 11. A programming language is to be designed to run on a
(c) both (a) and (b) (d) none of the above machine that does not have a big memory. The language
4. The term “environment” in programming language semantics should
is said as (a) prefer a 2 pass compiler to a 1 pass compiler
(a) function that maps a name to value held there (b) prefer an interpreter to a compiler
(b) function that maps a name to a storage location (c) not support recursion
(c) the function that maps a storage location to the value (d) all of the above
held there 12. The disadvantage of “compile and go” loading schemes
(d) none of the above (a) a portion of memory is wasted because the core
5. A non relocatable program is one which occupied by the assembler is unavailable to the object
(a) cannot be made to execute in any area of storage other program
than the one deisgnated for it at the time of its coding
(b) it is necessary to retranslate the user’s program deck
or translation.
every time it is run.
(b) consists of a program and relevant information for its
relocation (c) it is difficult to handle multiple segments, especially if
(c) can itself perform the relocation of its address sensitive the source programs are in different language and to
portions. produce orderly modular programs
(d) all of the above (d) all of the above
6. The linker 13. The task of the lexical analysis phase is
(a) is the same as loader (a) to parse the source program into the basic elements or
(b) is required to create a load module tokens of the language
(c) user source code as input (b) to build a literal table and an identifier table
(d) is always used before programs are executed (c) to build a uniform symbol table
7. Which of the following derivations does a top-down parser (d) all of the above
use while parsing as input string? The input is assumed to 14. Which table is a permanent data bases that has an entry for
be scaned in left to right order. each terminal symbol?
(a) Left most derivation (a) terminal table (b) literal table
(b) Left most derivation traced out in reverse (c) identifier table (d) reductions
(c) Right most derivation 15. The output of lexical analyser is
(d) Right most derivation traced out in reverse (a) a set of regular expressions
8. A simple two-pass assembler does which of the following (b) syntax tree
in the first pass?
(c) set of tokens
(1) It allocates space for the literals.
(d) strings of characters
(2) It computes the total length of the program.
(3) It builds the symbol table for the symbols and their 16. A compiler which allows only the modified section of the
values. source code to be recompiled is called as
(4) It generates code for all the load and stores register (a) incremental compiler (b) re-configurable compiler
instruction. (c) dynamic compiler (d) subjective compiler
COMPILER DESIGN S3-323
17. Which of the following system software resides in main $ denotes exponentiation. If the tree is traversed in preorder,
memory always? which, if any, of the expressions below is formed?
(a) text editor (b) assembler (a) + X * yz$ + xy*z (b) *yz + x$ + xy*z
(c) linker (d) all of the above (c) $ + *xyz* + xyz (d) $ + x*yz* + xyz
18. Pick the machine independent phase(s) of the compiler 26. A parser with the valid prefix property is advantageous
(a) syntax analysis because
(b) Lexical analysis (a) it detects error as soon as possible
(c) intermediate codegeneration
(b) it detects errors as and when they occur
(d) all of the above
(c) it limits the amount of errorneous output passed to the
19. Which of the following is used for grouping of characters
into tokens? next phase
(a) parser (b) code optimization (c) all of the above
(c) code generator (d) scanner 27. An ideal compiler should
20. A bottom-up parser generates (a) be small in size
(a) right-most derivation (b) produce object code that is smaller in size and executes
(b) right-most derivation in reverse faster
(c) left-most derivation (c) take less time for compiling
(d) left-most derivation in reverse (d) all of the above
21. A top-down parser generates 28. In case of symbol table, we need to be able to
(a) right-most derivation (i) determine whether a given name is in the table
(b) right-most derivation in reverse (ii) add a new name to the table
(c) left-most derivation (iii) add new information for a given name
(d) left-most derivation in reverse (iv) delete a name or group of names from the table
22. Which of the following expressions is represented by the
(a) (i), (ii), (iii), and (iv) (b) (ii), (iii) and (v)
parse tree?
(c) (iii) and (v) (d) (i), (iii) and (iv)
(*) 29. Which of the following class of statement usually produces
no executable code when compiled?
(a) Declaration statements
(b) Assignment statements
(+) C (c) Input and output statements
(d) Structural statements
30. How many tokens are contained in the following FORRTAN
statement:
A B
IF (NUMB EQ MAX) GOTO 500
(a) (A + B) * C (b) A + * BC (a) 8 (b) 10
(c) A + B * C (d) A * C + B (c) 22 (d) 24
23. Which of the following grammar is LR(1)?
31. Which of the following statement is false?
(a) A ® a A a (b) A ® a A a
(a) A sentence of a grammar should be derivable from the
A®bAb A®aAb
start state.
A®a A®c
A®a (b) A sentence of a grammar should be frontier of a
(c) A ® A + A (d) both (a) and (b) derivation tree, in which the root node has the start
A®a state as the label.
24. The value of k, in LR (k) cannot be (c) A sentence of a grammar is a sentential form without
(a) 0 (b) 1 any terminals.
(c) 2 (d) none of the above (d) Two different grammars may generate the same
25. Consider the adjacent binary tree: language.
32. Access time of the symbols table will be logarithmic, if it is
($) implemented by
(a) linear list (b) search tree
(c) hash table (d) self-organizing list
(+) (*)
33. A shift-reduce parser carries out the actions specified within
braces immediately after reducing, with the corresponding
X
(*) (+) Z rule of the grammar.
S ® xxW {print “1”}
S ® y {print “2”}
Y ZX Y
W ® Sz {print “3”}
EBD_7203
S3-324 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
What is the translation of “xxxxyzz”? 41. The parsing technique that avoids backtracking is
(a) 11231 (b) 11233 (a) Top-down parsing
(c) 23131 (d) 23321 (b) Recursive-descent parsing
34. Consider the following left-associative operators, in (c) Predictive parsing
decreasing order of precedence: (d) Both (b) and (c) above
– subtraction (highest precedence) 42. Consider the grammar.
* multiplication S ® (S) | a
$ exponentiation (lowest precedence) Let the number of states in SLR (1), LR (1) and LALR (1)
What is the result of the following expression? parsers for the grammar be n 1, n2 and n3 respectively. The
3–2*4$2 $3 following relationship holds good
(a) n1 < n2 < n3 (b) n1 = n3 < n2
(a) – 61 (b) 64
(c) n1 = n2 = n3 (d) n1 ³ n3 ³ n2
(c) 512 (d) 4096 43. Semantic errors can be detected
35. Which of the following cannot be used as an intermediate (a) at compile time only (b) at run-time only
code form? (c) both (a) and (b) above (d) none of the above
(a) Post fix notation (b) Three address codes 44. The graph that shows the basic blocks and their successor
(c) Syntax trees (d) Quadruples relationship is called
36. A language L is defined by L = {xn yn | n ³ 1}. Which of the (a) DAG (b) flow graph
following definitions generates the same languages as L? (c) control graph (d) Hamiltonian graph
(a) E ® x Ey | xy (b) (xy) | (x xyy) 45. For which of the following reasons, a compiler is preferable
(c) x+ y+ (d) All of the above to an interpreter?
37. A shift-reduce parser carries out the actions specified within (a) It can generate stand-alone programs that often take
braces immediately after reducing with the corresponding less time for execution.
rule of grammar (b) It is much helpful in the initial stages of program
S ® AS {print “1”} development.
S ® AB {print “2”} (c) Debugging can be faster and easier.
(d) If one changes a statement, only that statement needs
A ® a {print “3”}
recompilation.
B ® bC {print “4”}
46. Consider the grammar
B ® dB {print “5”} S ® ABSc/Abc
C ® c {print “6”} BA ® AB
This syntax directed translation scheme translates a language Bb ® bb
whose terminal symbols are a, b, c and d into another Ab ® ab
language whose terminal symbols are 1, 2, 3, 4, 5 and 6. Aa ® aa
What is the translation of “aadbc”? Which of the following sentences can be derived by this
(a) 333546 (b) 654211 grammar?
(c) 333645211 (d) 645233311 (a) abc (b) aab
38. Consider the following C fragment (c) abcc (d) abbc
fro (int x = 0; x <= n; x ++) 47. The grammar E ® E + E
Which type of error detected by the C compiler for the above E ® E * E | a, is
code? (a) ambiguous
(a) lexical error (b) syntactic error (b) unambiguous
(c) semantic error (d) logical error (c) depends on the given sentence
(d) none of the above
39. Consider the left-recursive grammar:
48. Which of the following expressions is represented by the
S ® Aa | b parse tree given below?
A ® Ac | bd (+)
When the left recursion is removed, the grammar will become
equivalent to the grammar.
(a) S ® bA’ (b) S ® Aa | b (*) F
A ® c | da S ® ad | bd | cA
(c) S ® Aa | b (d) S ® Aa | b
A (/)
A ® Ac | Aad | bd A ® bdA’
A ® cA’ | Î
40. Which of the following symbols table implementation is (+) E
based on the property of locality of reference?
(a) Hash table (b) Search tree B (–)
(c) Self-organizing list (d) Linear list
C D
COMPILER DESIGN S3-325
(a) A + B * C – D / E + F (b) A * (B + (C – D)) / E + F 55. Consider the following production for a grammar G
(c) A + B * C – D / (E + F) (d) A + B * (C – D) / (E + F) S ®0S0|00
49. In some programming languages, an identifier is permitted Which of the following is not generated by the grammar G?
to be a letter followed by any number of further letters or (a) 00 (b) 0000
digits. (c) on such that n is even (d) 0n such that n is odd.
Given that
D = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} 56. A shift reduce parser carries out the actions specified with
and L = {a, A, b, B, c, C, ... z, Z} in braces immediately after reducing the corresponding rule
Which of the following expressions below defines an of grammar.
identifier? A ® bbB {print “+”}
(a) (L U D)* (b) L (L U D)* A ® a {print “x”}
(c) (L.D)* (d) L.(L.D)* B ® Ac {print “–”}
50. The number of tokens in the following C statement What is the translation of bbbbacc using the syntax directed
printf (“i = %d, &i = %x”, i, &i);
translation scheme described by the above rules?
(a) 3 (b) 26
(a) * + – + * (b) * * – + –
(c) 10 (d) 21
(c) + * – + * (d) * – + – +
51. Consider the following grammar.
A ® BA' 57. Which of the following statement is correct about parsing?
A' ® + BA' | Î 1. Top-down parsing expands the start symbol to the
B ® CB’ required string needed whereas in bottom-up parsing
B' ® * CB' | Î reduces the syntax to the start symbol.
C ® (A) | id 2. Top-down parsing is implemented using the set of
The FOLLOW (B) is recursive procedures and implementation of bottom-
(a) {), $} (b) {+,), $} up parsing is done using the stacks and input buffer.
(c) {(, id} (d) {+, $} 3. Backtracking is required for both bottom-up and top-
52. Given the following expression grammar: down parsing implementation
E ®E*F|F+E|F (a) 1 and 3 only (b) 3 only
F ® F – F | id (c) 1 and 2 only (d) none of the above
Which of the following is true? 58. For the string aabbaa give the derivation tree using grammar
(a) *has higher precedence than + G = {{S, A}, {a, b}, {S ® aAS, S ® a, A ® SbA, A ® SS,
(b) – has higher precedence than * A ® ba}, S}
(c) + and – have same precedence (a) (b)
(d) + has higher precedence than * S S
53. In a context-free grammar
(a) Î can’t be right hand side of any production a S a S
A
(b) terminal symbols can’t be present in the left hand side A
of any production
(c) the number of grammar symbols in the left hand side is
a S a A S b A
not greater than that of in the right hand side
(d) all of the above
a a a b a a
54. In some phase of compiler b
Input
temp1: = inttoreal (60) (c) S (d) S
temp2: = id3 * temp1
temp3: = id2 + temp2 a
A S S b A
id1 : = temp3
Output
temp1 : = id3 * 60.0 A a
S b a a bb a a
id1 : = id2 + temp 1
where temp1, temp2, temp3 are temporary storage, id1, id2,
id3 are identifier inttoreal is converting int 60 to real number. a b a
The above phase is
59. Which of the following describes a handle (as applicable to
(a) code optimizer LR-parsing) appropriately?
(b) code generator (a) it is the position in a sentential form where the next
(c) intermediate code generator shift or reduce operation will occur
(d) none of the above (b) it is a non-terminal whose production will be used for
reduction in the next step
EBD_7203
S3-326 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(c) it is a production that may be used for reduction in a and initially it contains [S' ® T] which of the following is
future step along with a position in the sentential form not a closure?
where the next shift or reduce operation will occur. (a) S' ® . T (b) S' ® T .
(d) it is the production p that will be used for reduction in (c) T ® . T * F (d) F ® .id
the next step along with a position in the sentential 65. The grammar
form where the right hand side of the production may S ® TA
be found A ® Î | + TA
60. An LALR (1) parser for a grammar G can have shift-reduce T®i|n
(S-R) conflicts if and only if (a) is LL (1) (b) is LALR (1)
(a) the SLR (1) parser for G has S-R conflicts (c) LR (1) but not LALR (1) (d) is SLR (1)
(b) the LR (1) parser for G has S-R conflicts 66. Consider the grammar given below.
(c) the LR (0) parser for G has S-R conflicts A ® BA'
(d) the LALR (1) parser for G has reduce-reduce conflicts A' ® *BA' | Î
61. Consider the following grammars. B ® CB' | Î
G1 G2 B' ® *CB' | Î
S ® 0A | Î S ® AS C ® +Ad | id
A ® 1S S®Î The FIRST and FOLLOW of A are respectively
A ® XY (a) {+, id, *, Î } and {d, $} (b) {+, id} and {d, $}
X®0 (c) {+} and {d, $} (d) {id} and {d, *}
Y®1 67. Consider the following grammar.
Which of the following statements is not true? S ® Aa | bAc | dc | bda
(a) G2 is ambiguous A®d
(b) G1 corresponds to a regular language The above grammar is
(c) G1 corresponds to a language that can be recognized (a) not LALR (1) but SLR (1)
with an LR parser (b) both LALR (1) and SLR (1)
(c) G2 is in chomsky normal form
(c) LALR (1) but not SLR (1)
62. Consider the production
(d) neither LALR (1) nor SLR (1)
S ® aS | b
68. Consider the following statements.
The parsing automation is below:
a S1 : A regular grammar is always linear but not all linear
grammar are regular.
S2 : In LL grammar, the usage of productions rule can be
predicted exactly, by looking at a limited part of input.
S ® a.S
a Which of the above statements is/are correct?
S ® .aS S ® .aS (a) S1 is true and S2 is false
S ® b. S ® .b (b) S2 is true and S1 is false
(c) both S1 and S2 are true
(d) both S1 and S2 are false
b 69. Consider the syntax directed definition shown below.
b S
S ® id: = E {gen (id.place = E.place;);}
E ® E1 + E2 {t = newtemp ();
gen (t = E1.place + E2. place;);
S ® b. S ® aS. E.place = t}
E ® id {E.place = id.place;}
Which of the following stack contents causes the parser to
Here, gen is a function that generates the output code, and
reduce by some production?
newtemp is a function that returns the name of a new
(a) aaS (b) a
temporary variable on every call. Assume that ti's are the
(c) aa (d) bb
temporary variable names generated by newtemp.
63. Consider the following grammar production.
E ® E + E | E × E | (E) | id and id ® 0 | 1 | 2 | .... | 9 For the statement ‘X: Y + Z; the 3-address code sequence
The expression 3 + 2 × 5 is parsed by the shift-reduce parser generated by this definition is
then which of the following is not a handle for it? (a) X = Y + Z
(a) E + E (b) E × E (b) t1 = Y + Z; X t1
(c) E + E × E (d) 3 (c) t1 = Y; t2 = t1 + Z; X = t2
64. Consider a augmented grammar (d) t1 = Y; t2 = Z; t3 = t1 + t2; X = t3
S' ® T 70. Consider the grammar with the following translation rules
T®F|T*F and E as the start symbol.
F ® id | (T) E ® E1 # T {E, value = E1.value * T.value}
COMPILER DESIGN S3-327
|T {E.value = T.value} Which of the following is true for the above annotated tree?
T ® T1 & F {T.value = T1.value + F.value} (a) there is specific order for evaluation of attribute on
|F {T.value = F.value} parse tree.
F ® num {F.value = num.value} (b) any evaluation order that computes an attribute x after
Compute E.value for the root of the parse tree for the all other attribute that x depends on is acceptable
expression: 2 # 3 & 5 # 6 & 4. (c) both (a) and (b)
(d) none of the above
(a) 200 (b) 180
73. The DAG shown here represents
(c) 160 (d) 40
71. Consider the annotated parse tree. *
expr.t = 95 – 2+
+ –
expr.t = 95– term.t = 2
term.t a * d
expr.t = 9
–
2 b c
(a) a + (b * c) – d (b) a + b * c * b * c – d
5 +
term.t = 9 (c) (a + b) * (c – d) (d) (a + b * c) * (b * c – d)
74. Consider the following grammar with corresponding
synthesized attributes:
F ® .L {F.v = L.v}
9 L ® L B {L.len = L1.len + 1, L.v = L1.v + 2–L.len × B.v}
Which one of the following is correct syntax directed L ® B {L.len = 1, L.v = B.v/2}
definition of above parse tree? B ® 0 {B.v = 0}
Production Semantic Rule B ® 1 {B.v = 1}
(a) expr ® expr + term expr.t = expr.t | | term.t || ‘*’ If “F.val” gives the value of the binary fraction generated
expr ® expr + term expr.t = expr.t | | term.t || ‘+’ by F in the above grammar then what will be the value of
expr ® term expr.t = term.t F.val on input 101?
term ® . 9 term.t ® ‘9’ (a) .625 (b) .550
term ® 5 term.t ® ‘5’ (c) .710 (d) .485
term ® 2 term.t ® ‘2’ 75. The DAG shown here presented
(b) expr ® expr + term expr.t = expr.t | | term.t || ‘+’ +
expr ® expr – term expr.t = expr.t | | term.t || ‘–’
expr ® term expr = term
term ® 9 term.t ® ‘9’ * *
term ® 5 term.t ® ‘5’
term ® 2 term.t ® ‘2’
(c) both (a) and (b) + – +
(d) none of the above
72. Consider the following annotated parse tree.
x.num = y.num + z.num a
c d
b
(a) (a – b) * (a + b) + (c + d) * (c + d)
(b) (a – b) * (c + d) + (a – b) * (c – d)
(c) (a * b) + (c * d) * (a * b) + (c * d)
(d) (a + b) * (c + d) + (a – b) * (c + d)
76. Consider the DAG with V = {1, 2, 3, 4, 5, 6}, shown below
2
y.num = num y + z z.num = num 5
1 4
num num
6
3
EBD_7203
S3-328 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Which of the following is NOT a topological ordering? 80. Generation of intermediate code based on an abstract
(a) 1 2 3 4 5 6 (b) 1 3 2 4 5 6 machine model is useful in compilers because
(c) 1 3 2 4 6 5 (d) 3 2 4 1 6 5 (a) it makes implementation of lexical analysis and syntax
77. An inherited attribute is the one whose initial value at a analysis easier
parse tree node is defined in terms of (b) syntax-directed translations can be written for
(a) attributes at the parent and/or siblings of that node intermediate code generation
(b) attributes at children nodes only (c) it enhances the portability of the front end of the
(c) attributes at both children nodes and parent and/or compiler
siblings of that node (d) it is not possible to generate code for real machines
(d) none of the above directly from high level language programs
78. The intermediate code generated for the following syntax 81. Hash tables can contribute to an efficient average case
tree is solution for all of the following problems described below
+ except
(a) counting distinct values (b) dynamic dictionary
i –
(c) range search (d) symbol table lookup
82. Which of the following is not a type of three address
statements?
+ *
(a) copy statements
(b) index assignment statements
(c) pointer assignments
a
b c uminus (d) none of the above
83. For the graph given below, the postfix notation is
*
c d
(a) iac + cdb + – +
(b) iacb + cd uminus * – +
(c) iacb + cd * – + c
(d) none of the above +
79. The triple representation for following representation is:
x : = y* + – y * + z
(a) Op arg1 arg 2
(0) + z a b
(1) * y
(a) abc + * (b) abc +
( 2) + z (1) (c) ab + c* (d) abc* +
( 3) * y ( 2) 84. The post fix form of A – B / (C * D $ E) is
( 4) - ( 0) ( 3) (a) ABCDE $ */- (b) AB/C* DE$
( 5) := x ( 4) (c) ABCDE $ -/* (d) ABCDE /- * $
85. Consider the following statements
Op arg1 arg 2 S1 : Viable prefixes of grammar G are those prefixes of right-
(0) + z sentenial form that can appear on top of stack of a shift
(1) * y ( 0) reduce parsing.
( 2) + z S2 : Handle is sub-string that matches right side of production
whose reduction to non terminal on left side of production
(b) ( 3) * y ( 2) represents one step along the reverse of leftmost derivation.
( 4) - (1) ( 3) Which of the above statements is/are true?
( 5) := x ( 4) (a) S1 is true and S2 is false (b) S2 is true and S1 is false
(c) Both are true (d) Both are false
Op arg1 arg 2
86. Consider the following grammar
(0) + z E ®E+E
(1) * y ( 0) E ®E*E
( 2) + z (1) E ® (E)
E ® id
(c) ( 3) * y
if string id1 + id2 * id3 derivated from above grammar then
( 4) - ( 2) ( 3) which of the following represent the handle?
( 5) = x ( 4) (a) id1 + id2 (b) E * id3
(d) none of the above (c) id2 + id3 (d) None of the above
COMPILER DESIGN S3-329
87. ‘Divide by Zero’ is a What is the translation of xxxxyzz using the syntax directed
(a) lexical error (b) syntax error translation scheme described by the above rules?
(c) semantic error (d) none of the above (a) 23131 (b) 11233
88. In a bottom-up evaluation of a syntax directed definition, (c) 11231 (d) 33211
inherited attribute can 95. The grammar S ® AB, B ® ab, A ® aa, A ® a, B ® b is
(a) always be evaluated (a) unambiguous (b) ambiguous
(b) be evaluated only if definition is L-attributed (c) CSG (d) none of the above
(c) never evaluated 96. Consider the following syntax direction definition
(d) be evaluated only if the definition has synthesized A ® BC
attributes C.i = c(A.i) ...1
89. Consider the grammar B.i = b(A.s) ...2
S ® ABCc | ABc A.s = f(B.s) ...3
BA ® AB i for inherited, s for synthesized attribute
BC ® bb Which of the following is true?
AB ® ab (a) 1 is violating L attributed definition
Aa ® aa (b) 2 is violating L attributed definition
(c) 3 is violating L attributed definition
Which of the following sentence can be derivated by this
(d) None of the above
grammar?
97. Consider the following statements:
(a) abc (b) aab
S1: Static allocation bindings do not change at runtime.
(c) abcc (d) abbc
S2: Heap allocation allocates and de-allocates storage at
90. Consider the following grammar
run time.
S ® CC, C ® cC | d Which of the above statements is/are true?
The grammar is (a) S1 is true and S2 is false
(a) LL(1) (b) SLR (1) but not LL(1) (b) S2 is true and S1 is false
(c) LALR (1) but not SLR (1)(d) LR (1) but not LALR (1) (c) Both are true
91. Which of the following is not a regular grammars? (d) Both are false
(a) S ® Î , A ® aS | b (b) A ® abB | aB 98. Consider the following grammar
(c) A ® Ba | Bab (d) A ® aB | a, B ® Ab | b E ® E(E) E | E
92. What is printed by the print statements in the program P1 Which one of the following is true?
assuming call by reference parameter passing? 1. The grammar is ambiguous
Program P1( ) 2. The grammar is unambiguous
{ 3. The grammar will generate all strings have balanced
x = 10; parenthesis
y = 3; (a) 1 and 3 (b) 2 and 3
func1 (y, x, x); (c) 1 only (d) 2 only
print x; 99. Consider the following productions for a grammar.
print y; S ®iE tS|iEt SeS
} and configuration of the parser is as follows
func 1 (x, y, z) Stack Input
{
.... i E t S e...
y = y + 4;
The above production produces which of the following
z = x + y + z;
action?
}
(a) 10, 3 (b) 31, 3 (a) shift e (b) reduce the configuration
(c) 27, 7 (d) None of the above (c) shift/reduce conflict (d) reduce/reduce conflict
93. The above grammar is used to generate all valid arithmetic 100. Consider the following grammar:
expressions in a hypothetical language in which S ® Xa|C
(a) + has the highest precedence than * X ® X d|Se|e
(b) * has the highest precedence than + The non-terminal S is
(c) – has the highest precedence than + (a) immediate left recursive (b) left recursive
(d) / has the highest precedence than * (c) Both (a) and (b) (d) Neither (a) nor b
94. A shift reduce parser carries out the action specified within 101. Left factoring is
braces immediately after reducing with the corresponding (i) a grammar transformation
rule of grammar (ii) useful producing a grammar suitable for predictive
S ® xxW {print “1”} parsing
S ® y {print “2”} (a) (ii) only (b) (i) only
W ® Sz {print “3”} (c) Neither (i) nor (ii) (d) Both (i) and (ii)
EBD_7203
S3-330 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
102. Consider the following grammar for expressions:- 109. Which of the following features cannot be captured by CFG?
E ® EA|(E)| – E | id (a) Syntax of If then else statements
A®+|–|*|/| (b) Syntax of recursive procedures
Then which of the following statements is correct? (c) Whether a variable is declared before its use
(a) The above grammar representation can be converted (d) Matching nested parenthesis
into operator grammar by replacing terminal values
110. A top-down parser generates
(b) The above grammar expression is for an operator
grammar (a) left most derivation
(c) The above grammar expression is not an operator (b) right most derivation
grammar (c) right most derivation in reverse
(d) Both (a) and (c) (d) left most derivation in reverse
103. Which of the following statements is incorrect about 111. Shift reduce parsers are
parsing? (a) top-down parsers
(i) Top-down parsing expands the start symbol to the (b) bottom-up parsers
required string needed whereas in bottom-up parsing (c) top-down or bottom-up parsers
reduces the syntax to the start-symbol.
(d) None of the above
(ii) Top-down parsing is implemented using the set of
recursive procedures and implementation of bottom- 112. Compile time errors do not include
up parsing is done using the stacks and input buffer. (a) lexical error (b) syntactic error
(iii) Back tracking is required for the both bottom-up and (c) semantic error (d) None of these
top-down parsing implementation. 113. The language which are having many types, but the type of
(a) (i), (ii) (b) (iii) only every name and expression must be calculable at compile
(c) (i) and (iii) (d) None of these time is called
104. Consider the language L1 = {wcw | w is in (a|b)* then which (a) strongly typed (b) weakly typed
of the following statements is correct about L1? (c) dynamic typed (d) None of these
(i) L1 is not context free language. 114. Which of the following is correct about syntax directed
(ii) L1 consists of all words composed of a repeated string translation?
of a’s and b’s separated by c. (i) Evaluation of the semantic rules may generate codes
(iii) Identifiers recognizing L1 can be embedded in the save information in a symbol table, issue error message
problem of checking that identifiers are declared before or perform any other activities.
use.
(ii) The translations of the token stream in the result
(a) (i), (ii) and (iii) (b) (i) and (iii)
obtained by evaluating the semantic rules.
(c) (i) and (ii) (d) (ii) and (iii)
105. Which of the following is the disadvantages of an operator (a) (i) only (b) (ii) only
precedence parsing? (c) (i) and (ii) (d) Neither (i) nor (ii)
(i) Operator precedence parsing is hard to handle tokens 115. Which of the following is treated as restriction for translation
like the minus sign. routines that are invoked during parsing and routines must
(ii) One cannot always be sure that the parser accepts live?
exactly the desired language. (i) A grammar that is suitable for parsing and may not
(iii) Only a small class of grammars can be parsed using reflect the natural hierarchical structure of the
operator precedence techniques. constructs in the language.
(a) (i), (ii) and (iii) (b) (i) and (iii) (ii) The parsing method constrains the ordering which
(c) (ii) and (iii) (d) (i) and (iii) nodes in a parse tree are considered.
106. A hardware device that is capable of executing a sequence (a) (i) only (b) (ii) only
of instructions is known as (c) Both (i) and (ii) (d) Neither (i) nor (ii)
(a) CPU (b) ALU 116. Which of the following is incorrect about an error detection?
(c) CU (d) processor
(i) A simple compiler may stop all activities other than
107. Which of the following derivations do a top-down parser
lexical and syntactic analysis after the detection of the
use while parsing an input string? The input is assumed to
first error.
be scanned in left to right order.
(a) Left most derivation (ii) A more complex compiler may attempt to repair the
(b) Left most derivation traced out in reverse error that is transform the errorneous input into a similar
(c) Right most derivation but legal input on which normal processing can be
(d) Right most derivation traced out in reverse resumed.
108. The most powerful parsing method is (iii) No compiler can do true corrections.
(a) LL(1) (b) canonical LR (a) (i), (ii) and (iii) (b) (i) and (ii)
(c) SLR (d) LALR (c) (ii) and (iii) (d) None of these
COMPILER DESIGN S3-331
117. Which of the following is correct example about good 126. Which of the following cannot be used in stack allocation
reporting error methods? strategy?
(i) Missing right parenthesis in line 5 (i) The value of local name must be retained when an
(ii) Cryptic error ‘OH17’ activation ends.
(iii) ZAP not declared in procedure BLAH (ii) A called activation outliers the caller.
(iv) Missing declaration (a) (i) only (b) (ii) only
(a) (i), (ii) (iii) and (iv) (b) (ii) only (c) (i) and (ii) (d) Neither (i) nor (ii)
(c) (i) and (ii) (d) None of these 127. Which of the following is/are in correct about intermediate
118. Which of the following is correct? code representation?
(a) L-attributed definitions are class of syntax directed
(i) The indirect triples and quadruples are required about
definition whose attributes can always be evaluated in
the same amount of space.
depth first order
(ii) The indirect triples much efficient for recording of code
(b) Every S attributed definition is L attributed
as compared to quadruples.
(c) A syntax directed definition is L attributed if each
(a) (i) only (b) (ii) only
inherited attributed of Xj, 1 £ j £ n, on the right side of
A ® X1X2, ......... Xa, depends only on the inherited (c) (ii) and (i) (d) Neither (i) nor (ii)
attributed of A 128. Which of the following is correct about run time
(d) All of the above environment?
119. Which of the following can be corrected by using minimum (a) The allocation and deallocation of a data object are
hamming distance method? managed by the run time support package and design
(a) Syntactic error (b) Semantic error of the run time support package is influenced by the
(c) Data flow optimization (d) None of the above semantic of procedures
120. Advantage of using assembly language rather than machine (b) Each execution of a procedure is referred to as activation
language is that of the procedure and if procedure is recursive, several
(a) it is mnemonic and easy to read of its activation may be alive at the same time
(b) addresses are symbolic not absolute (c) Both (a) and (b)
(c) introduction of data to program is easier (d) Neither (a) nor (b)
(d) All of the above
129. Which of the following immediate code representative is
121. Which is a permanent database in the general model of
compiler? suitable for optimizing compiler?
(a) Literal table (b) Identifier table (i) Quadruples (ii) Triples
(c) Terminal table (d) Reductions (iii) Indirect triples
122. A linker reads four modules whose lengths be 300, 900, 1000 (a) (i), (ii) and (iii) (b) (i) and (iii)
and 600 words, respectively. If they are loaded in that order,
(c) (iii) and (ii) (d) (i) and (ii)
what are the relocation constants?
(a) 0, 300, 1500, 2700 (b) 0, 300, 1200, 2200 130. Heap allocation is required
(c) 300, 1200, 2200, 2800 (d) None of these (a) for language that supports recursion
123. Back-patching is useful for handling (b) for language that uses dynamic scope rules
(a) conditional jumps (b) unconditional jumps
(c) for language that supports dynamic data structure
(c) backward references (d) forward references
124. The best way to compare the different implementation of (d) None of the above
symbol table is to compare the time required to 131. The module loader performs which type of function?
(a) add a new name (a) Loading (b) Assembling
(b) make an inquiry (c) Relocation (d) Linking
(c) add a new name and make an inquiry
(d) All of the above 132. A system program that set up an executable program in
125. In programming language semantics, the term environment main memory ready for execution, is
refers to (a) assembler (b) linker
(a) a function that maps a storage location to the value (c) loader (d) text editor
held there
133. Three address code involves
(b) a function that maps a name to a storage location
(c) Both (a) and (b) (a) exactly 3 addresses (b) search trees
(d) Neither (a) nor (b) (c) hash tables (d) self organization lists
EBD_7203
S3-332 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
NUMERICAL TYPE QUESTIONS COMMON DATA & LINKED ANSWER TYPE QUESTIONS
134. The number of tokens in the following C statement : printf Common Data and Linked Answer Type Question
("i = %d, & i = %x", i, & i) ; Common data for Q. 140 and 141
135. A shift-reduce parser carriers out the actions specified within Consider the following expression grammar. The semantic rules
braces immediately after reducing with the corresponding for expression calculation are stated next to each grammar
rule of the grammar. production
S ® xxW {print "1"} E ® number E.Val = number.val
S ® y {print "2"} |E '+' E E(1) . val = E(2) . val + E(3) . val
W ® Sz {print "3"} |E '×' E E(1) . val = E(2).val × E(3) . val
What is the translation of 'xxxxyzz'? 140. The above grammar and the semantic rules are fed to a yacc
136. Consider the following left associative operators, in tool (which is an LALR (1) parser generator) for parsing and
decreasing order of precedence : evaluating arithmetic expressions. Which one of the
following is true about the action of yacc for the given
– subtraction (highest precedence)
grammar?
* multiplication
(a) it detects recursion and eliminates recursion
$ exponentiation (lowest precedence)
(b) it detects reduce-reduce conflict, and resolves
What is the result of the following expression?
(c) it detects shift-reduce conflict, and resolves the conflict
3–2*4$2 $3 in favor of a shift over a reduce action
137. A shift reduce parser carriers out the actions specified within (d) it detects shift-reduce conflict, and resolves the conflict
braces immediately after reducing with the corresponding in favor of a reduce over a shift action
rule of grammar 141. Assume the conflicts in Q. 136 are resolved and an LALR
S ® AS {print "1"} (1) parser is generated for parsing arithmetic expressions as
S ® AB {print "2"} per the given grammar. Consider an expression 3 × 2 + 1.
What precedence and associativity properties does the
A ® a {print "3"}
generated parser realize?
B ® bC {print "4"}
(a) equal precedence and left associativity; expression is
B ® dB {print "5"} evaluated to 7
C ® c {print "6"} (b) equal precedence and right associativity; expression
This syntax directed translation scheme translates a language is evaluated to 9
whose terminal symbols are a, b, c and d into another (c) precedence of ‘×’ is higher than that of ‘+’, and both
language whose terminal symbols are 1, 2, 3, 4, 5 and 6. operators are left associative; expression is evaluated
What is the translation of 'aaadbc'? to 7.
138. Consider the CFG with {S, A, B} as the non-terminal (d) precedence of ‘+’ is higher than that of ‘×’, and both
alphabets, {a, b} as the terminal alphabet, S as the start operators are left associative; expression is evaluated
to 9.
symbol and the following set of production rules
Common data for Q. 142 and 143.
How many derivation trees are there?
Consider the following grammar
139. Consider the CFG with {S, A, B} as the non-terminal S ® ABDh
alphabets, {a, b} as the terminal alphabet, S as the start B ® cC
symbol and the following set of production rules C ® bc | Î
S ® bA S ® aB D ® EF
A®a B®b E ®g| Î
F®f| Î
A ® aS B ® bS
142. What is the FOLLOW(E)?
S ® bAA B ® aBB (a) {f} (b) {g}
How many derivation trees are there? (c) {f, h} (d) none of the above
143. How many pair/pairs of elements has equivalent FOLLOW
sets?
(a) 0 (b) 1
(c) 2 (d) 3
COMPILER DESIGN S3-333
Common data for Q. 144 and 145 procedure q;
Production rule Translation rule begin x : = x + 1 end;
E®E#T {E. val = E1.val * T.val} .....I procedure r;
IT {E. val = T.val} .....II x : integer;
T®T&F _____________ .....III begin x: = 1; q; write (x) end;
IF {T.val = F.val} .....IV begin
F ® num {F. val = num) ..... V x: = 2;
144. If the expression 8#12&4#16&12#4&2 is evaluated to 512, r;
then which one of the following correctly represent the rule end;
III? 146. The output produced by calling P in a language with static
(a) T.val = T1.val * F.val (b) T.val = T1.val + F.val scope will be
(c) T.val = T1.val – F.val (d) none of the above (a) 1 (b) 2
145. The expression 10#8&6#9&4#5&2 will be evaluated to (c) 3 (d) 4
(a) 300 (b) 12740 147. The output produced by calling P in a language with dynamic
(c) 400 (d) none of the above scope will be
Common data for Q. 146 and 147 (a) 1 (b) 2
Consider the following procedure declaration (c) 3 (d) 4
procedure p;
x: integer;
EBD_7203
S3-334 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
PAST GATE QUESTIONS EXERCISE Here, the number of a = number of b, hence, it is not the
required grammar.
1. (c) Yace tool is used to create a LALR(1) parser. This parser
Option (b)
can detect the conflicts but to resolve the conflicts it
S ® as | Sb | a | b
actually prefers shift over reduce action.
S ® as ® abB
2. (b) The grammar has equal precedence and it is also
Here, number of a = number of b, hence it is not the
ambiguous. Since LALR(1) parser prefer shift over
required grammar.
reduce so + operation will be executed here before ). 2
Option (c)
+ 1 = 3 & 3 # 3 = 9 also the operators are right associative.
S ® AC | CB
Hence (b) is correct option.
C ® aC b| Î
3. (c) There are no lexical errors for C because all the wrong
spelled keywords would be considered as identifiers A ® aA | Î
until the syntax is checked. B ® Bb | Î
So the compiler would give syntax errors. S(C)B ® acbB ® ab
4. (b) The no. of states for SLR(1) &LALR(1) are equal so n 1 Here, number of a = number of b, hence it is not the
= n3, but CLR(1) or LR(1) will have no. of states greater required grammar.
than LALR &LR(0) both. Option (d)
5. (d) Given grammar S ® AC | CB
E"E+n C ® aC b| Î
E"E#n A ® aA | a
E"n B ® Bb | b
String = n + n # n Consider the production
Right sentential so right most non terminal will be used. S ® AC | CB
E"E#n {E " E # n} Applying, C ® Î
E+n#n {E " E + n} We get S ® A|B
n+n#n {E " n} Now, applying A or B, S generates a^n.b^n. So,
So during reduction the order is reverse. L = {aibj | i ¹ j}
So {E " n , E " E + n, E " E # n} Now, consider the production, S ® AC | CB. If the
6. (a) The grammar is definitely left & right recursive but it is production C ® acb is applied then, it generates
not suitable for predictive parsing because it is a^n,b^n.
ambiguous. Also predictive-parsing is possible for Now, applying either A or B it will give that number of
only LL(k). Ambigiousness also incorporates left a ¹ number of b.
recursion so a) 8. (a) It is very clear from the previous solution that the no.
Hence (A) is correct option. of steps required depend upon the no. of a' s & b ' s
7. (d) In the language which ever is higher & exceeds by 2 due to S " AC CB
& C "!
language L = {ai bj | i ¹ j}
So max(l , m) + 2
The expression i ¹ j indicates that language L is a
Hence (a) is correct
language in which number of a ¹ number of b.
9. (b) There is scope of common sub-expression elimination
Here, we need to search for a language in which number
in this code
of a ¹ number of b.
The expression 4*j is there in both the following lines
Considering the options:
x + = (4*j + 5*i);
Options (a)
y + = (7 + 4*j);
S ® AC | CB
10. (b) Input string 2 ) 3 + 4
C ® aCb | a| b
S " ER
A ® aA | Î
FR
B ® Bb | Î
idR {print(2)}
(a), S ® (C) B ® a(b) ® aBb ® ab
COMPILER DESIGN S3-335
id)ER {print())} 15. (b) Operations Variables Explanations
id) F+ER {print(+)}id) MOV b, R1 b is kept R1
id + ER {print(3)} id) id ) id +id ADD a, R1 a is added to whatever is
So 2 )+ 3 4 are printed present in R1 i.e. a is
11. (a) The predictive parser table is given as. added to be
No n ) id $ Þ t1 = a + b
termin al MOV d, R2 d is moved to R2
S S” FR ADD c, R2 c is added to whatever is
F F” id present in R2 i.e. is added
R R”)SR”! R”! to d
So at M [ S, id] = { S " FR} Þ t2 = c + d
M [ R,$] = {R "!} SUB e, R2 e – t 2 = t3
12. (c) The grammar is
SUB R1, R2 t1 – t3
S®S*E
S®E MOV R2, T4 t4 = t1 – t 3
E ®F+E This how, we obtain 3 MOV instruction in the code
E ®F generated for the basic block.
F ® id 16. (a) LL(1) parsers can recognize the regular grammars also
LR(0) items corresponding to the grammar above.
LL(1) is subset of LR(1) or CLR grammar so it also
1. S®S*E
2. E ® F. + E recognizes regular sets. So both accept regular grammar.
3. E ® F + .E P: regular can be left or right regular for left regular a
Now, S ® S * .E ...(i) left recursion elimination can be done.
S ® .E ...(ii)
E ®F+ .E ...(iii) Q: regular set is set of string represented by a regular
From Eqs. (i) and (iii), expression for which a dfa can be created so a LL(1)
We see that in both the productions, the Dot is left to parser is available so is LR(1) grammar.
E. Hence, belonging to the same set in canonical set of
17. (a) The grammar has production S " iCtSS1 here the right
items for the grammar.
13. (c) Let solve out to get the string generated by the hand side of grammar has the same symbol as left side.
grammar. So the grammar is left recursive. The grammar is not
S ® aB ambiguous.
S ® aaBB
18. (a) Top-down parsing is a technique to analyze unknown
S ® aabB
S ® aabbS data relationship. This is done by hypothesizing
S ® aabbaB general parser tree structures and then considering
S ® aabbab whether the known fundamental structures are
We get the string as aabbab. compatible with the hypothesis that was made earlier.
14. (b) The string received is aabbab.
We can total 2 derivation trees: Leftmost derivation and Recursive descent parser is a top down parser.
rightmost derivation. 19. (b) LALR parser is reduced form of CLR or LR(1) parser,
S S LALR parser uses the LR(1) items of CLR parser & of
any shift reduce conflicts are there then it is due to
LR(1) parser.
a a B
B 20. (a) I. Statement is false since global variables are
required for recursions with static storage. This
B a B is due to unavailability of stack in static storage.
a
B B
S II. This is true
b III. In dynamic allocation heap structure is used, so it
S b b
b B is false.
A a IV. False since recursion can be implemented.
b V. Statement is completely true. So only II & V are
a b true.
Hence (a) is correct option.
EBD_7203
S3-336 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
21. (b) Code optimizations are carried out on the intermediate First [c] Ç first [aSa] = (c) Ç (a) = f
code because program analysis is more accurte on As the above grammar is LL (1), also LR (1) because LL
intermediate code than on machine code. (1) grammar is always LR (1) grammar.
22. (d) It is a production p that may be used for reduction in 25. (b) Symbol table is a data structure used by a language
afuture step along with a position in the sentential form translator such as a compiler or interpreter, where each
where, the right hand side of the production may identifier in a program's source code is associated with
befound. information relating to its declaration or appearance in
A “handle” of a string is a substring that matches the the source, such as its type, scope level and sometimes
RHS of a production and whose reduction to the non- its location.
terminal (on the LHS of the production) represents one Symbol table
step along the reverse of a rightmost derivation toward In a symbol table is a data structure used by a language
translator such as a compiler or interpreter, where each
reducing to the start symbol.
identifier in a program's source code is associated with
If S ® * aAw ®* abw, then A ® b in the position
information relating to its declaration or appearance in
following a is a handle of abw.
the source, such as its type, scope level and sometimes
In such a case, it is suffice to say that the substring b
its location.
is a handle of abw, if the position of b and the
Implementation
corresponding production are clear. A common implementation technique is to use a hash
Consider the following grammar: table. A compiler may use one large symbol table for all
E ® E + E | E * E | (E) | id symbols or use separated, hierarchical symbol tables
and a right-most derivation is as follows: for different scopes. There are also trees, linear lists
E ® E + E ® E+ E * E ® E + E * id3 ® E + id2 * id3 ® and self-organizing lists which can be used to
id1 + id2 * id3 implement symbol table.It also simplifies the
23. (b) The time bounds for the parser are the same as those classification of literals in tabular format.
of the recognizer, while the space bound goes up to n An object file will contain a symbol table of the
3 in general in order to store the parse trees. In fact it identifiers it contains that are externally visible. During
would probably be most efficient to implementthe the linking of different object files, a linker will use
algorithm to do just a look-ahead of 1. To implement these symbol tables to resolve any unresolved
the full look-ahead for any k would be more costly references.
inprogramming effort and less efficient overall since A symbol table may only exist during the translation
so few programming languages need the extra look- process, or it may be embedded in the output of that
ahead. Improving transformations are performed on a process for later exploitation, for example, during an
target-specific representation of the program. for both interactive debugging session, or as a resource for
existing and proposed architectures, to gather trace formatting a diagnostic report during or after execution
information for code improvements are often applied of a program.
to a high-level intermediate languagethough it can be While reverse engineering an executable, many tools
applied to the source level also but it can impact the refer to the symbol table to check what addresses have
effectiveness of code improvements been assigned to global variables and known functions.
I. Statement is true since there are some parsers which If the symbol table has been stripped or cleaned out
take 0(n log2n) time for parsing. before being converted into an executable, tools will
II. Completely false, since there is no use of stack which find it harder to determine addresses or understand
is required for recursion. anything about the program.
III. False At that time of accessing variables and allocating
IV. True since both types of optimizations are applied memory dynamically, a compiler should perform many
works and as such the extended stack model requires
24. (c) S ® aSa | bS | C the symbol table.
The above grammar is LL (1) because, A C compiler that parses this code will contain at least
First [aSa] Ç first [bS] = (a) Ç (b) = f following symbol table entries:
First [bS] Ç first [c] = (b) Ç (c) = f
COMPILER DESIGN S3-337
Symbol name Type Scope 20000268 T A T91F_UndefHandler
Bar function, double extern
X double function parameter 20000284 T A T91F_LowLevelInit
Foo function, double global 200002e0 t A T91F_DBGU_CfgPIO
Count int function parameter 2000030c t A T91F_PIO_CfgPeriph
Sum double block local
I int for-loop statement 20000360 t A T91F_US_Configure
In addition, the symbol table will also contain entries 200003dc t A T91F_US_SetBaudrate
generated by the compiler for intermediate expression
2000041c t A T91F_US_Baudrate
values (e.g., the expression that casts the i loop variable
into a double, and the return value of the call to function 200004ec t A T91F_US_SetTimeguard
bar()), statement labels, and so forth. 2000051c t A T91F_PDC_Open
As another example, the symbol table of a small program
2000059c t A T91F_PDC_ Dis ableRx
is listed below. The table itself was generated using
the GNU binutils'nm utility. There is one data symbol, 200005c8 t A T91F_PDC_ Dis ableTx
(noted by the “D” type), and many functions (self 200005f4 t A T91F_PDC_SetNextTx
defined as well as from the standard library). The first
20000638 t A T91F_PDC_SetNextRx
column is where the symbol is located in the memory,
the second is “The symbol type” and the third is the 2000067c t A T91F_PDC_SetTx
name of the symbol. By passing suitable parameters, 200006c0 t A T91F_PDC_SetRx
the symbol table was made to sort on basis of address.
20000704 t A T91F_PDC_EnableRx
20000730 t A T91F_PDC_EnableTx
Example table 2000075c t A T91F_US_EnableTx
Print (1)
syntax error logical error
xx”xxW”z has both syntax and logical error
But, it will result in syntax error.
Print (3) Hence, (b) is correct option.
39. (d) S ® Aa | b
A ® Ac | bd
xxxx”Sz”z
Here, A ® Ac has left recursion removing it we have
Print (2) A ® bd A'
A' ® cA'
So, the resultant grammar is
xxxx”y”zz S ® Aa | b
Shift-reduce parser uses right most derivation in reverse S ® bd A'
order, in bottom-up fashion. Hence answer is “23131” A' ® cA' | Î
(c) option.
40. (a) Hash Table uses the property ‘Locality of Reference’.
34. (d) given that
41. (d)
EBD_7203
S3-342 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
42 (b) 49. (b) Since the necessary condition for an identifier is that it
43. (a) Semantic - may be detected at compile time, may also must starts with letter.
add checks in code for runtime After that any number of letter and digits can occur
Examples Hence, the correct expression is
Þ L(LUD)*
Division by 0
50. (c) Number of tokens in C statement is 10
Array index out-of-bounds
Printf ( “l = %d, & l = %x , i , & i ) ;
Dereference of NULL pointer
51. (b) A ® BA'
44. (b) program’s flow graph is used to determine those parts
A' ® Å BA' | Î
of a program to which a particular value assigned to a
B ® CB'
variable might propagate. The information gathered is B' ® *CB' | Î
often used by compilers when optimizing a program. C ® (A) | id
45. (a) A compiler compiles the program in one time while the First Follow
interpreter compiles it taking line by line. Hence, security A (, id $, )
checking is more in interpreter while compiler is fast in B (, id +, $, )
compilation.
A' + , Î $, )
Hence, it can generate stand-alone programs that often
B' * , Î +, $, )
takes less time for execution.
46. (a) The grammar C (, id *,+, $, )
52. (b)
S ®ABSc | Abc
E ®E*F|F+E|F
BA ® AB F ® F – F | id
Bb ® bb The operator at the bottom of the grammar reduction
Ab ® ab has the higher priority than the top level.
Aa ® aa Here
has the sentencial forms as Id
S Abc abc
ab – Decreasing priority
Hence, only “abc” can be derived.
47. (a) The given grammar
E ®E+E *, +
E ®E*E|a Hence, (b) is correct option.
is ambiguous since it has left recursion 53. (b) The context free grammar is represented as
Hence, (a) is the correct option. S®X
where S Î V (Single symbol non-terminal)
48. (b) (+) D ® (V U T)* (Any number of terminal and non-
terminals)
Hence, (b) is correct option.
(*) F
54. (a) Input
temp1: = inttoreal (60)
temp2: = id3*temp1
A (/) temp3: = id2 + temp2
id1 : = temp3
Output
(+) E temp1: = id3*60.0
id1 : id2 + temp1
B (–) The above phase is code optimization, because it is
optimizing the intermediate code using only storages
as temp1 and id1.
C D Hence, (a) is correct option.
55. (d) The given grammar
S ® 0S0/00
Hence, the given parse tree gives the expression generates the language
((A * ((B + (C – D))/E)) + F L = {0n : n is even}
Hence, (b) is the correct option. \ (d) is not possible.
COMPILER DESIGN S3-343
56. (d) A ® bbB {Print “+”} Because there exist only one parse tree.
A ® a {Print “*”} Hence, (a) is correct option.
B ® Ac {Print “–”}
Input: a
bbbbacc
{Print “+”} S ® a.S
62. (a) a
A (5) S ® .aS S ® .aS S ® aS|b
b {Print “–”} S ® .b S ® .b
b B
(4)
{Print “+”} A
(2) C
b b S
b b B {Print “–”}
(2)
A C
{Print “*”}
S ® b. S ® aS.
(1) a
The above syntax tree prints Some possible stack contents are
*–+–+ aaS, ab, b, etc.
Hence, (d) is correct option. Hence, (a) is correct option.
57. (c) 63. (c)
58. (c) S ® aAs, S ® a, A ® SbA, A ® SS, A ® ba 64. (b) S' ® T
Input: T ® F| T * F
aabbaa F ® id| (T)
(a) S' ® .T is the initial state
S (b) S ® T. is not possible since T will further be
reduced to F| T * F
a S (c) + ® T * F is valid
A
(d) F ® .id is also valid
a
65. (a) S ® TA
S b A A ® + TA | Î
first (+ TA) Ç first (Î) = f ...(1)
a first (+ TA) Ç follow (A) = f ...(2)
b a
[follow(A) = follow(S) = $]
first (Î) Ç follow (A) = f ...(3)
from (1), (2) and (3) we have
59. (d) A handle may be described as the sentencial form given Given grammar is LL (1)
by the bottom up parser from left to right in reverse 66. (a) A ® BA'
order. A' ® *BA'| Î
Hence, (d) is the correct option. B ® CB'| Î
60. (b) LALR (1) parser for a grammar, G can have shift-reduce B' ® *CB'| Î
(S – R) conflicts if and only if there is a S – R conflict in C ® +Ad| id
its immediate sub-parsers (e.g. LR (1)). If LR (0) has first (A) = first (B)
S – R conflicts then they may get removed in LR (1), first (B) = first (C), Î
hence there will be no S – R conflict in LALR (1). first (C) = +, id
61. (a) Here grammar, G2 is not ambiguous \ first (A) = {+, *, id, Î}
S ® AS | Î follow (A) = first(d), $ = d, $
A ® XY \ follow (A) = {d, $}
S
X®0 67. (c)
Y®1
68. (c) A right regular grammar (also called right linear
A S grammar) is a formal grammar (N, å, P, S) such that all
the production rules in P are of one of the following
X Y
forms:
A S
1. B ® a - where B is a non-terminal in N and a is a
X Y
terminal in å
0 1 Î 2. B ® aC - where B and C are in N and a is in å
0 1
EBD_7203
S3-344 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
3. B ® e - where B is in N and e denotes the empty
string, i.e. the string of length 0.
#
A context-free grammar (CFG) is a formal grammar in
which every production rule is of the form # & F
V®w
F
where V is a single nonterminal symbol, and w is a & F
16 + 10 = 160
string of terminals and/or nonterminals (w can be F F
empty). A formal grammar is considered “context free”
when its production rules can be applied regardless of
num num num num num
the context of a nonterminal. It does not matter which (2) (3) (5) (6) (4)
symbols the nonterminal is surrounded by, the single LL “ left to right left most derivation no ambignity should be
nonterminal on the left hand side can always be replaced there
by the right hand side. SLR or LR(0) L to R reverse right sentential form
69. (d) In 3-address code we use temporary variables to reduce create LR(0) items.
CLR or LR(1) create LR(1) items no bound
complex instructions so here LALR reduced CLR if while reducing any conflict
t1 = Y t2 = Z found then not
t 3 = t 1 + t2 LALR
x = t3 Hence (c) is correct option.
70. (c) Parse Tree would be 71. (b)
72. (b)
E 73. (d)
E # T *
# T & F
E T –
T T F
& F
1st IInd
F F a * d
#
E T
T T & F
2 + 8 = 1G
F F
79. (c)
num num num
(2) (3) (5) 80. (a)
COMPILER DESIGN S3-345
81. (c) It’s O(1) time [constant time] for each lookup operation. 83. (c) The postfix notation (LRN) is ab + c*
Since you need to lookup the values of only two keys, Hence, correct option is (c)
that part only takes constant time. So then you have all
of the values for the two keys. All that is left is checking
which values are in common, which would take a lot
less time than.
82. (d) The types of three-address statements used in compiler
project are -
(1) For binary arithmetic and logical operators “op”,
assignment statement is of the form x = y op z.
84. (a) A – B/(C*D$E) can be represented as tree
(2) Unary operation takes place in the form x = op y,
where op is a unary operator. Unary operation –
includes unary minus, logical negation, pointer
operation, one’s complement and coversion
operators (e.g. converts integer number to floating A /
point number).
(3) Copy assignments of the form x = y.
B *
(4) Conditional jumps such as if(x relop y) { ... }. Here
relop could be one of (==, !=, <, >, <=, >=). This
instruction executes statements in curly braces if
C $
the condition is true, otherwise jumps to the next
statement after curly braces.
(5) For Response_Write (See - 1.1.6), the each D E
parameter is passed using PARAM code, and
finally RESPONSE_WRITE causes the actual web The postfix expression is
output. For example, the C code fragment - ABCDE$*/-
Response_Write(“The value of x “, x, 85. (a) “Handle” is a substring that matches the right side of a
“<BR>”); production and whose reduction to the nonterminal
generates following intermediate code - on the left side of the production represents one step
along the reverse of right most derivation.
PARAM “The value of x ”
86. (d) E ® E + E ® E + E * E ® E + E * id3 ® E + id2 * id3 ®
PARAM x id1+ id2 * id3
PARAM “<BR>” Here E + E, E * E, id1, id2 and id3 are the handles.
RESPNONSE_WRITE 87. (c) It is a sematic error (run-time error)
88. (d) Inherited attribute can be evaluated only if definition
To get input from web, one PARAM code is passed has synthesized attribute.
with desired value to be accessed, followed by 89. (a) S ® ABc ® abc
90. (a) Parsing table of given grammar is
REQUEST_QUERYSTRING code. For example, the C
Non Input Symbol
code fragment -
Terminal c d
x = Request_QueryString(“var_x”); S S ® CC S ® CC
generates the following intermediate code - C C ® cC C®d
PARAM “var_x” So grammar is LL(1)
REQUEST_QUERYSTRING 91. (d) Mixup notation of left linear and right linear grammar is
ASSIGN x not allowed in regular grammar.
Request_QueryString 92. (b) Actual output will be x = 31 and y = 3
93. (a) + has higher precedence than *. To check this consider
id + id * id and id * id + id4
(6) Address and pointer assignments of the form x = In both parse trees, + derives after *. Hence + has
&y, x = *y, and *x = y. higher precedence than*.
EBD_7203
S3-346 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
E
99. (c)
100. (b) Left recursive
X For immediate left recursion it should be of form
A ® Aa|b
X * T
For general left recursion
F
A ® Ba|b
T
B ® Ag|f
T + F id 101. (d) Left factoring provides a new grammar (transformed
grammar) and the new grammar is suitable for predictive
F id parsing.
102. (d) Operator grammar contains only a single non-terminal
id on the right side of the production.
94. (a) RMD of xx7xyzz 103. (b) In bottom-up parsing backtracking is not possible. As
S® xxw 1 well as if we consider top-down parsing backtracking
® xxSz 3 is possible.
® xxxxWz 1 104. (b)
® xxxxSzz 3 105. (c) Operator precedence parsing works only on small class
® xxxxyzz 2
of grammar and does not provide the surity that desired
shift reduce parser takes RMD in reverse. It will be
language will be accepted.
23131.
95. (b) Consider the string aab. This string can be produced 106. (a) The CPU is linked to main memory, peripheral equipment
in two different ways: S ® AB ® aab ® aab and S ® (including input/output devices), and storage units.
AB ® aB ® aab. The control unit integrates computer operations. It
Hence G is ambiguous.
selects instructions from the main memory in proper
A
sequence and sends them to the instruction-decoding
96. (b) unit, which interprets them so as to activate functions
B C
According to L attributed definition, B’s attributes can of the system at appropriate moments.
depend on inherited attributes of A but not on 107. (a) Left most derivation.
synthesized attributes of A. In top-down parsing, we always do left most derivation.
97. (c) Static allocation bindings do not change at runtime. 108. (b) Canonical LR.
Static binding: occurs before runtime and does not It is the strongest parsing method that parse every
change during program execution Heap allocation type of grammar
allocates and de-allocates storage at run time because 109. (c) Whether a variable is declared before it use, all other
dynamic binding: occurs during runtime or changes feature are captured by CFG.
110. (a) Left most derivation.
during runtime
98. (a) The grammar is ambiguous, the string Top-down parsing, always gives left most derivation.
( ) ( ) having two parse tree 111. (b) Bottom-up parsers.
S Shift-reduce parsing is the type of bottom-up parsers.
112. (a) A “compile-time” error is one which prevents your code
(S) from compiling. Compile-time errors are divided into
S S
three categories:
(a) Î
Î S ( )S 1. Lexical: These generally occur when disallowed
characters are included code (e.g. int #people =
Î Î 10;).
S
2. Syntactical: These occur when code is “out of
(S) order” (e.g. for (int i=0; i++; i<10)).
S S
3. Semantic: These occur when the meaning of code
Î
(b) S (S )S Î is unclear (e.g. two variables with the same name).
Note that the exact wording of these errors may vary,
Î Î
Î depending on which development environment using.
The grammar generates balanced parenthesis Errors in a computer program can be classified
COMPILER DESIGN S3-347
according to when they are detected and, if they are must be passed down from parent nodes to children
detected at compile time, what part of the compiler nodes of the abstract syntax tree during the semantic
detects them.
analysis of the parsing process, are a problem for
(a) A lexical error, detected by the scanner.
(b) A syntax error, detected by the parser. bottom-up parsing because in bottom-up parsing, the
(c) A static semantic error, detected (at compile-time) parent nodes of the abstract syntax tree are created
by semantic analysis. after creation of all of their children. Any S-attributed
(d) A dynamic semantic error, detected (at run-time) grammar is also an L-attributed grammar. L-attributed
by code generated by the compiler
grammars are a special type of attribute grammars. They
In lexical scoping (or lexical scope; also called static
scoping or static scope), if a variable name’s scope is allow the attributes to be evaluated in one left-to-right
a certain function, then its scope is the program text of traversal of the abstract syntax tree. As a result,
the function definition: within that text, the variable attribute evaluation in L-attributed grammars can be
name exists, and is bound to the variable’s value, but incorporated conveniently in top-down parsing. Many
outside that text, the variable name does not exist. By
programming languages are L-attributed. Special types
contrast, in dynamic scoping (or dynamic scope), if a
variable name’s scope is a certain function, then its of compilers, the narrow compilers, are based on some
scope is the time-period during which the function is form of L-attributed grammar. These are comparable
executing: while the function is running, the variable with S-attributed grammars.
name exists, and is bound to its variable, but after the
119. (a) Syntactic error can be corrected by using minimum
function returns, the variable name does not exist.
hamming distance method
113. (a) The language which are having many types, but the
120. (a) Assembly language is more human-readable than
type of every name and expression must be calculable
machine language and machine language run very fast
at compile time is called strongly typed.
121. (c) terminal table
114. (b) The translations of the token stream in the result
In a compiler: a data structure used by the compiler to
obtained by evaluating the semantic rules is called
keep track of identifiers used in the source program.
syntax related translation. A syntax-directed translation
This is a compile-time data structure. Not used at run
scheme (SDTS) is a context-free grammar with program
time.
fragments, called semantic actions, embedded within
122. (b) Initially the value is 0 then it is incremented to 300 then
production bodies. SDTSs are useful for implementing
further increment of 900, 1000, respectively.
syntax-directed definitions
115. (c) 123. (d) Back-patching is useful for handling forward
116. (c) (i) A more complex compiler may attempt to repair references. Forward referencing is usually used in
the error that is transform the errorneous input assembly language. Forward referencing is usually
into a similar but legal input on which normal used in assembly language. In forward referencing
processing can be resumed: variable or label is referenced before it is declared.
Different problems can be solved using One Pass or
Due to the extra time and space needed for
Two Pass forward referencing. In One Pass forward
compiler analysis and optimizations, some
referencing source program is translated instruction
compilers skip them by default. Users have to use
by instruction. Assembler leave address space for label
compilation options to explicitly tell the compiler
when it is referenced and when assembler found the
which optimizations should be enabled
declaration of label, it uses back patching.
(ii) No compiler can do true corrections: A good
124. (c)
compiler should be able to detect as many errors
125. (b) In programming language semantics, the term
as possible in various ways and also recover from
environment refers to a function that maps a name to a
them.
storage location. In programming language semantics,
117. (a)
the term “environment” refers to a function that maps
118. (b) S-Attributed Grammars are a class of attribute grammars
a name to a storage location, and term “state” refers to
characterized by having no inherited attributes, but
a function that maps a storage location to the value
only synthesized attributes. Inherited attributes, which
held there.
EBD_7203
S3-348 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
environment state 131. (a) Loader loads all the storage contents in the memory
needed for program execution.
132. (c)
133. (a)
name storage Value 134. 10
135. 23131
126. (c) Stack allocation cannot be used if
136. 4096
– Local names must be retained after
137. 333645211
activation ends
138. 2
– Activation outlives caller
139. 139.2
127. (c) A three-address statement is an abstract form of
intermediate code. In a compiler, these statements can 140. (c) its the basic specification of Yacc that in case of S-R
be implemented as records with fields for the operator conflicts by default it will shift and in case of R-R
and the operands. Three such representations are conflict it will reduce by earlier grammar so option c)
quadruples, triples, and indirect triples. 141. (b) The grammar has equal precedence and it is also
Quadruples ambiguous. Since LALR(1) parser prefer shift over
A quadruple is a record structure with four fields, which reduce so + operation will be executed here before ).
we call op, arg l, arg 2, and result. 2 + 1 = 3 & 3 # 3 = 9 also the operators are right
Triples associative.
To avoid entering temporary names into the symbol Hence (b) is correct option.
table. We might refer to a temporary value bi the
142. (c) S ® ABDh
position of the statement that computes it. If we do so,
three-address statements can be represented by B ® cC
records with only three fields: op, arg 1 and arg2. C ® bc|Î
Using the quadruple notation, the symbol table D ® EF
interposes an extra degree of indirection between the
computation of a value and its use. If we move a E ® g|Î
statement computing x, the statements using x require F ® f|Î
no change. However, in the triples declaration. moving follow(E) = first (F)
a statement that defines a temporary value requires us
= f, Î
to change all references to that statement in the arg 1
and arg2 arrays. This problem makes triples difficult to since Î cannot be taken
use in an optimizing compiler. follow (E) = first (F) excluding Î, follow D
Indirect triples present no such problem. A statement follow (D) = first (h) = h
can be moved by reordering the statement list. Since
\ follow (E) = {f, h}
pointers to temporary values refer to the r>p-arg 1-
arg2 array(s), which are not changed, none of those
143. (c)
pointers need be changed. Thus, indirect triples look First Follow
very much like quadruples as far as their utility is c $
S
concerned. The two notations require about the same
amount of space and they are equally efficient for B c g, f, h
reordering of code. ~s with ordinary triples. Allocation C b g, f, h
of storage to those temporaries needing it must be
deferred in the code generation phase. However, D g, f, Î h
indirect triples can save some space compared with E g, Î h, f
quadruples if the same temporary value is used more
F f, Î h
than once.
128. (b) Each execution of a procedure is referred to as an Here 2 pair/pairs of elements has equivalent follow sets.
activation of the procedure. If the procedure is recursive, Hence, option (c) is correct.
several of its activation may be alive at the same time. 144. (c)
129. (a) Quadruples, triples, indirect triples all are the 145. (a)
representation of intermediate code.
146. (a) In a language with static scope the output would be 1
130. (c) Heap allocation is required for language that supports
dynamic data structure to allow the size of the data 147. (b) In a language with dynamic scope the output would be
structures to increase. 2
7
Page - 349 - 414
OPERATING SYSTEM
C Ø Processes
O Ø
Ø
Threads
Inter-process communication
T
Ø CPU scheduling
E Ø File systems
N
Ø I/O systems
T
S
EBD_7203
S3-350 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
OP ERATING SYSTEM
An operating system is a program that acts as an interface between the user and the
computer hardware and controls the execution of all kinds of programs.
PROCESSES
• A process is an instance of a program in execution.
• Batch systems work in terms of "jobs". Many modern process concepts are still
expressed in terms of jobs, ( e.g. job scheduling ), and the two terms are often
used interchangeably.
The Process
Process memory is divided into four sections as shown in Figure below:
• 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.
max • The heap is used for dynamic memory allocation, and is managed via calls
stack
to new, delete, malloc, free, etc.
• The stack is used for local variables. Space on the stack is reserved for
local variables when they are declared ( at function entrance or elsewhere,
depending on the language ), and the space is freed up when the variables
go out of scope. Note that the stack is also used for function return values,
heap and the exact mechanisms of stack management may be language specific.
data • Note that the stack and the heap start at opposite ends of the process's
free space and grow towards each other. If they should ever meet, then
text
either a stack overflow error will occur, or else a call to new or malloc will
0
Process in memory
fail due to insufficient memory available.
When processes are swapped out of memory and later restored, additional
information must also be stored and restored. Key among them are the program
counter and the value of all program registers.
Process State
Processes may be in one of 5 states, as shown in Figure
• New - The process is in the stage of being created.
• Ready - The process has all the resources available that it needs to run,
but the CPU is not currently working on this process's instructions.
• Running - The CPU is working on this process's instructions.
• Waiting - The process cannot run at the moment, because it is waiting for
some resource to become available or for some event to occur. For example
the process may be waiting for keyboard input, disk access request, inter-
process messages, a timer to go off, or a child process to finish.
• Terminated - The process has completed.
Process Control Block
For each process there is a Process Control Block,
new admitted interrupt exit terminated PCB, which stores the following (types of) process-
specific information.
Process State - Running, waiting, etc., as
ready running discussed above.
Process ID, and parent process ID.
CPU registers and Program Counter -
scheduler dispatch These need to be saved and restored when swapping
I/O or event completion I/O or event wait
processes in and out of the CPU.
waiting
CPU-Scheduling information - Such as priority
information and pointers to scheduling queues.
Diagram of process state
OPERATING SYSTEM S3-351
Memory-Management information - E.g. page tables or segment tables. process state
Accounting information - user and kernel CPU time consumed, account
numbers, limits, etc. process number
I/O Status information - Devices allocated, open file tables, etc. program counter
THREADS registers
A thread is a basic unit of CPU utilization, consisting of a program counter, a
stack, and a set of registers, ( and a thread ID. ) memory limits
Traditional (heavyweight ) processes have a single thread of control - There is list open files
one program counter, and one sequence of instructions that can be carried out
at any given time.
Multi-threaded applications have multiple
Process control block (PCB)
threads within a single process, each having
their own program counter, stack and set of
code data files code data files
registers, but sharing common code, data,
and certain structures such as open files.
registers stack registers registers registers
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
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.
OPERATING SYSTEM S3-357
Conditions for Deadlock
Three policy conditions are necessary for deadlock to be possible.
(i) Mutual exclusion : Only one process may use a resource at one time.
(ii) Hold and wait: A process may hold some resources while waiting for others.
(iii) No preemption: No process can be forced to release a resource.
(iv) Circular wait: A closed chain of processes exists, such that each process is
blocked waiting for a resource held by another process in the set.
Three approaches exist for dealing with deadlock:
(i) Prevention involves adopting a static policy that disallows one of the four
conditions above.
(ii) Avoidance involves making dynamic choices that guarantee prevention.
(iii) Detection and recovery involves recognising when deadlock has occurred, and
trying to recover.
Deadlock Prevention
We can prevent deadlock from occurring by adopting either an indirect policy that
disallows one of the three necessary conditions, or a direct policy that disallows sets
of processes that can exhibit a circular wait.
Deadlock Avoidance
• Deadlock avoidance. Simplest algorithm - each process tells max number of
resources it will ever need. As process runs, it requests resources but never
exceeds max number of resources. System schedules processes and allocates
resoures in a way that ensures that no deadlock results.
• Example: system has 12 tape drives. System currently running P0 needs max 10
has 5, P1 needs max 4 has 2, P2 needs max 9 has 2.
• Can system prevent deadlock even if all processes request the max? Well, right
now system has 3 free tape drives. If P1 runs first and completes, it will have
5 free tape drives. P0 can run to completion with those 5 free tape drives even
if it requests max. Then P2 can complete. So, this schedule will execute without
deadlock.
• If P2 requests two more tape drives, can system give it the drives? No, because
cannot be sure it can run all jobs to completion with only 1 free drive. So, system
must not give P2 2 more tape drives until P1 finishes. If P2 asks for 2 tape drives,
system suspends P2 until P1 finishes.
• Concept: Safe Sequence. Is an ordering of processes such that all processes can
execute to completion in that order even if all request maximum resources.
Concept: Safe State - a state in which there exists a safe sequence. Deadlock
avoidance algorithms always ensure that system stays in a safe state.
• Avail[j] = number of resource j available
• Max[i,j] = max number of resource j that process i will use
• Alloc[i,j] = number of resource j that process i currently has
• Need[i,j] = Max[i,j] - Alloc[i,j]
Notation: A<=B if for all processes i, A[i]<=B[i].
Safety Algorithm: will try to find a safe sequence. Simulate evolution of system
over time under worst case assumptions of resource demands.
• 1: Work = Avail;
• Finish[i] = False for all i;
• 2: Find i such that Finish[i] = False and Need[i] <= Work
• If no such i exists, goto 4
• 3: Work = Work + Alloc[i]; Finish[i] = True; goto 2
• 4: If Finish[i] = True for all i, system is in a safe state
Now, can use safety algorithm to determine if we can satisfy a given resource
demand. When a process demands additional resources, see if can give them
EBD_7203
S3-358 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
to process and remain in a safe state. If not, suspend process until system can
allocate resources and remain in a safe state. Need an additional data structure:
• Request[i,j] = number of j resources that process i requests
Here is deadlock detection algorithm is very similar to safe state detection
algorithm.
1: Work = Avail;
Finish[i] = False for all i;
2: Find i such that Finish[i] = False and Request[i] <= Work
If no such i exists, goto 4
3: Work = Work + Alloc[i]; Finish[i] = True; goto 2
4: If Finish[i] = False for some i, system is deadlocked.
Moreover, Finish[i] = False implies that process i is deadlocked.
When to run deadlock detection algorithm? Obvious time: whenever a process
requests more resources and suspends. If deadlock detection takes too much
time, maybe run it less frequently.
Deadlock Detection and Recovery
Both prevention and avoidance of deadlock lead to conservative allocation of
resources, with corresponding inefficiencies. Deadlock detection takes the opposite
approach:
• make allocations liberally, allowing deadlock to occur (on the assumption that
it will be rare),
• apply a detection algorithm periodically to check for deadlock, and
• apply a recovery algorithm when necessary.
The detection algorithm can be applied at every resource allocation, or less frequently,
depending on the trade-off between the likelihood of deadlock occurring
and the cost of the algorithm. Detection algorithms are broadly similar to the
avoidance algorithms discussed previously, and are able to identify which processes
are deadlocked under the current resource allocation.
CPU SCHEDULING
Almost all programs have some alternating cycle of CPU number crunching and
waiting for I/O of some kind. (Even a simple fetch from memory takes a long time
load store
relative to CPU speeds.)
add store CPU burst
read from file In a simple system running a single process, the time spent waiting for I/O is
wasted, and those CPU cycles are lost forever.
A scheduling system allows one process to use the CPU while another is
wait for I/O I/O burst waiting for I/O, thereby making full use of otherwise lost CPU cycles.
The challenge is to make the overall system as "efficient" and "fair" as possible,
store increment subject to varying and often dynamic conditions, and where "efficient" and
index CPU burst "fair" are somewhat subjective terms, often subject to shifting priority policies.
write to file CPU-I/O Burst Cycle
I/O burst
Almost all processes alternate between two states in a continuing cycle, as
wait for I/O
shown in Figure
• A CPU burst of performing calculations, and
• An I/O burst, waiting for data transfer in or out of the system.
load store
CPU burst CPU bursts vary from process to process, and from program to program,
add store
read from file CPU Scheduler
Whenever the CPU becomes idle, it is the job of the CPU Scheduler ( a.k.a. the
short-term scheduler ) to select another process from the ready queue to run
wait for I/O I/O burst next.
The storage structure for the ready queue and the algorithm used to select the
next process are not necessarily a FIFO queue. There are several alternatives
to choose from, as well as numerous adjustable parameters for each algorithm,
Fig. Alternating sequence of which is the basic subject of this entire chapter.
CPU and I/O bursts
OPERATING SYSTEM S3-359
Preemptive Scheduling
CPU scheduling decisions take place under one of four conditions:
1. When a process switches from the running state to the waiting state, such
as for an I/O request or invocation of the wait( ) system call.
2. When a process switches from the running state to the ready state, for
example in response to an interrupt.
3. When a process switches from the waiting state to the ready state, say at
completion of I/O or a return from wait( ).
4. When a process terminates.
For conditions 1 and 4 there is no choice - A new process must be selected.
For conditions 2 and 3 there is a choice - To either continue running the current
process, or select a different one.
If scheduling takes place only under conditions 1 and 4, the system is said to
be non-preemptive, or cooperative. Under these conditions, once a process
starts running it keeps running, until it either voluntarily blocks or until it
finishes. Otherwise the system is said to be preemptive.
Windows used non-preemptive scheduling up to Windows 3.x, and started
using pre-emptive scheduling with Win95. Macs used non-preemptive prior to
OSX, and pre-emptive since then. Note that pre-emptive scheduling is only
possible on hardware that supports a timer interrupt.
Note that pre-emptive scheduling can cause problems when two processes
share data, because one process may get interrupted in the middle of updating
shared data structures. Chapter 6 will examine this issue in greater detail.
Preemption can also be a problem if the kernel is busy implementing a system
call ( e.g. updating critical kernel data structures ) when the preemption occurs.
Most modern UNIXes deal with this problem by making the process wait until
the system call has either completed or blocked before allowing the preemption
Unfortunately this solution is problematic for real-time systems, as real-time
response can no longer be guaranteed.
Some critical sections of code protect themselves from concurrency problems
by disabling interrupts before entering the critical section and re-enabling
interrupts on exiting the section. Needless to say, this should only be done in
rare situations, and only on very short pieces of code that will finish quickly,
( usually just a few machine instructions. )
Dispatcher
The dispatcher is the module that gives control of the CPU to the process
selected by the scheduler. This function involves:
• Switching context.
• Switching to user mode.
• Jumping to the proper location in the newly loaded program.
The dispatcher needs to be as fast as possible, as it is run on every context
switch. The time consumed by the dispatcher is known as dispatch latency.
Scheduling Criteria
There are several different criteria to consider when trying to select the "best"
scheduling algorithm for a particular situation and environment, including:
• CPU utilization - Ideally the CPU would be busy 100% of the time, so as
to waste 0 CPU cycles. On a real system CPU usage should range from 40%
( lightly loaded ) to 90% ( heavily loaded. )
• Throughput - Number of processes completed per unit time. May range
from 10 / second to 1 / hour depending on the specific processes.
• Turnaround time - Time required for a particular process to complete, from
submission time to completion. ( Wall clock time. )
• Waiting time - How much time processes spend in the ready queue waiting
their turn to get on the CPU.
EBD_7203
S3-360 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
( Load average - The average number of processes sitting in the ready queue
waiting their turn to get into the CPU. Reported in 1-minute, 5-minute, and
15-minute averages by "uptime" and "who". )
• Response time - The time taken in an interactive program from the issuance
of a command to the commence of a response to that command.
In general one wants to optimize the average value of a criteria ( Maximize CPU
utilization and throughput, and minimize all the others. ) However some times
one wants to do something different, such as to minimize the maximum response
time.
Sometimes it is most desirable to minimize the variance of a criteria than the
actual value. i.e. users are more accepting of a consistent predictable system
than an inconsistent one, even if it is a little bit slower.
Scheduling Algorithms
Process Arrival Time Execute Time Service Time
We'll discuss five major scheduling algorithms here
P0 0 5 0 which are following
P1 1 3 5 First Come First Serve (FCFS) Scheduling
Shortest-Job-First (SJF) Scheduling
P2 2 8 8
Priority Scheduling
P3 3 6 16 Round Robin(RR) Scheduling
Multilevel Queue Scheduling
P0 P1 P2 P3 First Come First Serve (FCFS)
Jobs are executed on first come, first serve
basis.
0 5 8 16 22 Easy to understand and implement.
First come first serve Poor in performance as average wait time is
high.
Process Arrival Time Execute Time Service Time Wait time of each process is following
Process Wait Time : Service Time - Arrival Time
P0 0 5 0
P0 0 - 0 = 0
P1 1 3 3 P1 5 - 1 = 4
P2 2 8 8 P2 8 - 2 = 6
P3 3 6 16 P3 16 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.55
Shortest Job First (SJF)
P0 P1 P2 P3
Best approach to minimize waiting time.
Impossible to implement
0 3 8 16 22
Processer should know in advance how much
time process will take.
Shortest Job First
Wait time of each process is following
Process Wait Time :
Service Time - Arrival Time
Process Arrival Time Execute Time Priority Service Time P0 3-0=3
P1 0-0=0
P0 0 5 1 0
P2 16 - 2 = 14
P1 1 3 2 3 P3 8-3=5
P2 2 8 1 8 Average Wait Time: (3+0+14+5) / 4 = 5.50
P3 3 6 3 16 Priority Based Scheduling
Each process is assigned a priority.
P3 P1 P0 P2 Process with highest priority is to be
executed first and so on.
Processes with same priority are
0 6 9 14 22 executed on first come first serve
Priority Based Scheduling basis.
OPERATING SYSTEM S3-361
Priority can be decided based on
memory requirements, time
requirements or any other resource
requirement. Process Arrival Time Execute Time
Wait time of each process is following
P0 0 5
Process Wait Time :
P1 1 3
Service Time - Arrival Time
P0 0 - 0 = 0 P2 2 8
P1 3 - 1 = 2 P3 3 6
P2 8 - 2 = 6
P3 16 - 3 = 13 P0 P1 P2 P3 P0 P2 P3 P2
Average Wait Time: (0+2+6+13) / 4 = 5.25
Round Robin Scheduling
Each process is provided a fix time 0 3 6 9 12 15 18 21 24
Round Robin Scheduling
to execute called quantum.
Once a process is executed for given time period. Process is
preempted and other process executes for given time period.
Context switching is used to save states of preempted
processes.
Wait time of each process is following
ProcessWait Time: Service Time - Arrival Time
P0 (0-0) + (12-3) = 9
P1 (3-1) = 2
P2 (6-2) + (15-9) = 10
P3 (9-3) + (18-12) = 12 Highest priority
Average Wait Time: (9+2+10+12) / 4 = 8.25 System Processes
Multi Queue Scheduling
Interactive Processes
Multiple queues are maintained for processes.
Each queue can have its own scheduling
Interactive Edit Processes
algorithms.
Priorities are assigned to each queue.
Batch Processes
The following subsections will explain several
common scheduling strategies, looking at only a Lowest priority
User Processes
single CPU burst each for a small number of
processes. Obviously real systems have to deal Multi Queue Scheduling
with a lot more simultaneous processes executing
their CPU-I/O burst cycles.
MEMORY MANAGEMENT
Memory management is the functionality of an operating system which handles or
manages primary memory. Memory management keeps track of each and every
memory location either it is allocated to some process or it is free. It checks how much
memory is to be allocated to processes. It decides which process will get memory at
what time. It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
Memory management provides protection by using two registers, a base register and
a limit register. The base register holds the smallest legal physical memory address
and the limit register specifies the size of the range. For example, if the base register
holds 300000 and the limit register is 1209000, then the program can legally access
all addresses from 300000 through 411999.
EBD_7203
S3-362 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Instructions and data to memory addresses can be done in following
ways
Operating System Compile time – When it is known at compile time
where the process will reside, compile time
251000 binding is used to generate the absolute code.
Process 1 Load time – When it is not known at compile time
where the process will reside in memory, then the
300000 300000
compiler generates re-locatable code.
Process 2 base
Execution time – If the process can be moved
420000 120000 during its execution from one memory segment to
limit another, then binding must be delayed to be done
Process 3
at run time
650000 Dynamic Loading
Empty Space In dynamic loading, a routine of a program is not loaded until it is
called by the program. All routines are kept on disk in a re-locatable
1280000
load format. The main program is loaded into memory and is executed.
Other routines methods or modules are loaded on request. Dynamic
loading makes better memory space utilization and unused routines
are never loaded.
Dynamic Linking
Linking is the process of collecting and combining various modules of code and data
into a executable file that can be loaded into memory and executed. Operating system
can link system level libraries to a program. When it combines the libraries at load
time, the linking is called static linking and when this linking is done at the time of
execution, it is called as dynamic linking.
In static linking, libraries linked at compile time, so program code size becomes bigger
whereas in dynamic linking libraries linked at execution time so program code size
remains smaller.
Logical versus Physical Address Space
An address generated by the CPU is a logical address whereas address actually
available on memory unit is a physical address. Logical address is also known a
Virtual address.
Virtual and physical addresses are the same in compile-time and load-time address-
binding schemes. Virtual and physical addresses differ in execution-time address-
binding scheme.
The set of all logical addresses generated by a program is referred to as a logical
address space. The set of all physical addresses corresponding to these logical
addresses is referred to as a physical address space.
The run-time mapping from virtual to physical address is done by the memory
management unit (MMU) which is a hardware device. MMU uses following
mechanism to convert virtual address to physical address.
The value in the base register is added to every address generated by a user
process which is treated as offset at the time it is sent to memory. For example,
if the base register value is 10000, then an attempt by the user to use address
location 100 will be dynamically reallocated to location 10100.
The user program deals with virtual addresses; it never sees the real physical
addresses.
OPERATING SYSTEM S3-363
Swapping
Swapping is a mechanism in which a process can be swapped temporarily out of main
memory to a backing store , and then brought back into memory for continued
execution.
Backing store is a usually a hard disk drive or any other secondary storage which
fast in access and large enough to accommodate copies of all memory images for all
users. It must be capable of providing direct access to these memory images.
Major time consuming part of swapping is transfer time. Total transfer time is directly
proportional to the amount of memory swapped. Let us assume that the user process
is of size 100KB and the backing store is a standard hard disk with transfer rate of
1 MB per second. The actual transfer of the 100K process to or from memory will take
100KB / 1000KB per second
= 1/10 second
= 100 milliseconds
Memory Allocation
Main memory usually has two partitions
Low Memory – Operating system resides in this memory.
High Memory – User processes then held in high memory.
Operating system uses the following memory allocation mechanism.
Operating
System S.N. Memory Allocation Description
Swap
1 out 1 Single-partition In this type of allocation, relocation-register scheme is
process P0
allocation used to protect user processes from each other, and from
User Space Swap
2 in changing operating-system code and data. Relocation
process P1
register contains value of smallest physical address
whereas limit register contains range of logical addresses.
Main Memory Backing Store Each logical address must be less than the limit register.
Swapping
2 Multiple-partition In this type of allocation, main memory is divided into a
allocation number of fixed-sized partitions where each partition
should contain only one process. When a partition is
a process is selected from the input queue and is loaded
into the free partition. When the process terminates, the
partition becomes available for another process.
Fragmentation
As processes are loaded and removed from memory, the free memory space is broken
into little pieces. It happens after sometimes that processes can not be allocated to
memory blocks considering their small size and memory blocks remains unused. This
problem is known as Fragmentation.
Fragmentation is of two types
1 External Total memory space is enough to satisfy a request or to reside
fragmentation a process in it, but it is not contiguous so it can not be used.
2 Internal Memory block assigned to process is bigger. Some portion of
fragmentation memory is left unused as it can not be used by another
process.
External fragmentation can be reduced by compaction or shuffle memory contents to
place all free memory together in one large block. To make compaction feasible,
relocation should be dynamic.
EBD_7203
S3-364 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
f 00000 Paging
CPU p d f d
External fragmentation is avoided by using paging technique. Paging is a
f 11111 technique in which physical memory is broken into blocks of the same size called
p pages (size is power of 2, between 512 bytes and 8192 bytes). When a process
is to be executed, it's corresponding pages are loaded into any available memory
User
frames.
Space
f Logical address space of a process can be non-contiguous and a process is
Physical
Memory allocated physical memory whenever the free memory frame is available. Operating
Page table system keeps track of all free frames. Operating system needs n free frames to run
a program of size n pages.
Address generated by CPU is divided into
Page 0 0 Page number (p) – page number is used as an index into a page table which
0 1
contains base address of each page in physical memory.
Page 1 1 4 1 Page 0 Page offset (d) – page offset is combined with base address to define the
2 3 physical memory address.
Page 2 Segmentation
3 7 2
Segmentation is a technique to break memory into logical pieces where each piece
Page
Page 3 Table represents a group of related information. For example ,data segments or code
3 Page 2
segment for each process, data segment for operating system and so on.
Logical Segmentation can be implemented using or without using paging.
Memory Page 1
4 Unlike paging, segment are having varying sizes and thus eliminates internal
fragmentation. External fragmentation still exists but to lesser extent.
5 Address generated by CPU is divided into
Segment number (s) – segment number is used as an index into a segment table
6 which contains base address of each segment in physical memory and a limit
of segment.
Page 3 Segment offset (o) – segment offset is first checked against limit and then is
7
combined with base address to define the physical memory address.
Physical Virtual memory is a technique that allows the execution of processes which are not
Memory
Paging Table Architecture completely available in memory. The main visible advantage of this scheme is that
programs can be larger than physical memory. Virtual memory is the separation of user
logical memory from physical memory.
OS Code OS Data OS Stack This separation allows an extremely large virtual memory to be provided for
programmers when only a smaller physical memory is available. Following are the
situations, when entire program is not required to be loaded fully in main memory.
User written error handling routines are used only when an error occured in the
data or computation.
P1 Data P2 Code
Certain options and features of a program may be used rarely.
Many tables are assigned a fixed amount of address space even though only
P1 Code
a small amount of the table is actually used.
The ability to execute a program that is only partially in memory would counter
P2 Data many benefits.
Less number of I/O would be needed to load or swap each user program into
Logical Address Space memory.
A program would no longer be constrained by the amount of physical memory
that is available.
limit base
CPU S O
Each user program could take less physical memory, more programs could be
Logical run the same time, with a corresponding increase in CPU utilization and
Address
Segment Table throughput.
Physical
Yes
+ Address Virtual memory is commonly implemented by demand paging. It can also be
0 < limit
implemented in a segmentation system. Demand segmentation can also be used
No
Error
to provide virtual memory.
Address generation by CPU
OPERATING SYSTEM S3-365
Demand Paging
Page 0
A demand paging system is quite similar to a paging system with Page 1
swapping. When we want to execute a process, we swap it into Page 2
memory. Rather than swapping the entire process into memory,
however, we use a lazy swapper called pager.
When a process is to be swapped in, the pager guesses which pages o
o
will be used before the process is swapped out again. Instead of
swapping in a whole process, the pager brings only those necessary o
pages into memory. Thus, it avoids reading into memory pages that will Memory
not be used in anyway, decreasing the swap time and the amount of Map
physical memory needed. Physical Backing Store
Page n
Memory
Hardware support is required to distinguish between those pages that Virtual
are in memory and those pages that are on the disk using the valid- Memory Virtual Memory
invalid bit scheme. Where valid and invalid pages can be checked by
checking the bit. Marking a page will have no effect if the process
never attempts to access the page. While the process executes and
accesses pages that are memory resident, execution proceeds normally. Program Swap out 0 1 2 3
A
Access to a page marked invalid causes a page-fault trap. This trap is 4 5 6 7
the result of the operating system's failure to bring the desired page
8 9 10 11
into memory. But page fault can be handled as following
12 13 14 15
Step Description
Step 1 Check an internal table for this process, to determine 16 17 18 19
Swap in
whether the reference was a valid or it was an invalid Program
B 20 21 22 23
memory access.
Step 2 If the reference was invalid, terminate the process. If it Main Memory Backing Store
was valid, but pagehave not yet brought in, page in the Demand Paging
latter.
Page is on
Step 3 Find a free frame. backing store
3
Step 4 Schedule a disk operation to read the desired page into Operating
System
the newly allocated frame.
reference 2
Step 5 When the disk read is complete, modify the internal table trap
1
kept with theprocess and the page table to indicate that
Load i
the page is now in memory. M 6
Step 6 Restart the instruction that was interrupted by the illegal Free frame
Restart
address trap. Theprocess can now access the page as 5 4
instruction
Reset page
though it had always been in memory. table Bring in
Therefore, the operating system reads the desired page Physical missing
into memory andrestarts the process as though the page Memory page
had always been in memory. Page Fault Trap
Advantages
Following are the advantages of Demand Paging
Large virtual memory.
More efficient use of memory.
Unconstrained multiprogramming. There is no limit on degree of
multiprogramming.
Disadvantages
Following are the disadvantages of Demand Paging
Number of tables and amount of processor overhead for handling page
interrupts are greater than in the case of the simple paged management
techniques.
Due to the lack of an explicit constraints on a jobs address space size.
EBD_7203
S3-366 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Page Replacement Algorithm
Page replacement algorithms are the techniques using which Operating System
decides which memory pages to swap out, write to disk when a page of memory needs
to be allocated. Paging happens whenever a page fault occurs and a free page cannot
be used for allocation purpose accounting to reason that pages are not available or
the number of free pages is lower than required pages.
When the page that was selected for replacement and was paged out, is referenced
again then it has to read in from disk, and this requires for I/O completion. This
process determines the quality of the page replacement algorithm: the lesser the time
waiting for page-ins, the better is the algorithm. A page replacement algorithm looks
at the limited information about accessing the pages provided by hardware, and tries
to select which pages should be replaced to minimize the total number of page misses,
while balancing it with the costs of primary storage and processor time of the
algorithm itself. There are many different page replacement algorithms. We evaluate
an algorithm by running it on a particular string of memory reference and computing
the number of page faults.
Reference String
The string of memory references is called reference string. Reference strings are
generated artificially or by tracing a given system and recording the address of each
memory reference. The latter choice produces a large number of data, where we note
two things.
For a given page size we need to consider only the page number, not the entire
address.
If we have a reference to a page p, then any immediately following references
to page p will never cause a page fault. Page p will be in memory after the first
reference; the immediately following references will not fault.
For example, consider the following sequence of addresses - 123,215,600,1234,76,96
If page size is 100 then the reference string is 1,2,6,12,0,0
disk disk
User process
stream head
read queue write queue
device
1. Consider three processes, all arriving at time zero, with total 5. A computer system supports 32-bit virtual addresses as well
execution time of 10, 20 and 30 units, respectively. Each as 32-bit physical addresses. Since, the virtual address space
process spends the first 20% of execution time doing IN/ is of the same size as the physical address space, the
OUT, the next 70% of time doing computation, and the last operating system designers decide to get rid of the virtual
10% of the time doing IN/OUT again. The operating system memory entirely. Which one of the following is true?
uses a shortest remaining compute time first scheduling (a) Efficient implementation of multi-user support is no
algorithm and schedules a new process either when the longer possible [2006, 1 mark]
running process gets blocked an IN/OUT or when the running (b) The processor cache organization can be made more
process finishes its compute burst. Assume that all IN/OUT efficient now
operations can be overlapped as much as possible. For what (c) Hardware support for memory management is no longer
percentage of time does the CPU remain idle? [2005, 2 marks] needed
(a) 0% (b) 10.6% (d) CPU scheduling can be made more efficient now
(c) 30.0% (d) 89.4% 6. Consider three processes (process id 0, 1, 2 respectively)
2. Consider three CPU-intensive processes, which require 10, with compute time bursts 2, 4 and 8 time units. All processes
20 and 30 time units and arrive at times 0, 2 and 6, respectively. arrive at time zero. Consider the Longest Remaining Time
How many context switches are needed, if the operating First (LRTF) scheduling algorithm. In LRTF ties are broken
system implements a shortest remaining time first scheduling by giving priority to the process with the lowest process id.
algorithm? Do not count the context switches at time zero The average turn around time is [2006, 1 mark]
and at the end. [2006, 1 mark] (a) 13 unit (b) 14 unit
(a) 1 (b) 2 (c) 15 unit (d) 16 unit
(c) 3 (d) 4 7. List I contains some CPU scheduling algorithms and List II
3. The atomic fetch-and-set x, y instruction unconditionally contains some applications. Match entries in List I to entries
sets the memory location x to 1 and fetches the old value of in List II using the codes given below the lists.
x in y without allowing any intervening access to the memory
location x. Consider the following implementation of P and V
List I List II
functions on a binary semaphore S. [2006, 2 marks]
void P (binary_semaphore *S) { Guaranteed
P. Gang Scheduling 1.
unsigned y; Scheduling
unsigned *x = & (S -> value); Rate Monotonic Real-time
do { Q. 2.
Scheduling Scheduling
fetch-and-set x, y;
R. Fair Share 3. Thread Scheduling
} while (y);
} Codes [2007, 1 mark]
void V (binary_semaphore *S) {
(a) P - 3, Q - 2, R - 1 (b) P - 1, Q - 2, R - 3
s - > value = 0;
(c) P - 2, Q - 3, R - 1 (d) P - 1, Q - 3, R - 2
}
Which one of the following is true? 8. Consider the following statements about user level threads
(a) The implementation may not work, if context switching and kernel level threads: [2007, 1 mark]
is disabled in P Which one of the following statements if false?
(b) Instead of using fetch-and-set, a pair of normal load/ (a) Context switch time is longer for kernel level threads
store can be used than for user level threads
(c) The implementation of V is wrong (b) User level threads do not need any hardware support
(d) The code does not implement a binary semaphore (c) Related kernel level threads can be scheduled on
4. A CPU generates 32-bit virtual addresses. The page size is 4 different processors in a multi-processor system
kbyte. The processor has a transition look-aside buffer (TLB) (d) Blocking one kernel level thread blocks all related
which can hold a total of 128 page table entries and is 4-way threads
set associative. The minimum size of the TLB tag is 9. An operating system uses Shortest Remaining Time First
(a) 11 bit (b) 13 bit [2006, 1 mark] (SRTF) process scheduling algorithm. Consider the arrival
(c) 15 bit (d) 20 bit times and execution times for the following processes
EBD_7203
S3-382 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(a) it does not ensure mutual exclusion
Process Execution time Arrival time (b) it does not ensure bounded waiting
P1 20 0 (c) it requires that processes enter the critical section in
P2 25 15 strict alternation
P3 10 30 (d) it does not prevent deadlocks, but ensures mutual
exclusion
P4 15 45
Statements for Linked Answer Questions 13 & 14
Which is the total waiting time for process P2? A process has been allocated 3 page frames. Assume that none of
[2007, 2 marks] the pages of the process are available in the memory initially. The
(a) 5 (b) 15 process makes the following sequence of page references
(c) 40 (d) 55 (reference string) [2007, 2 marks each]
10. A virtual memory system uses First In First Out (FIFO) page 1, 2, 1, 3, 7, 4, 5, 6, 3, 1
replacement policy and allocates a fixed number of frames to 13. If optimal page replacement policy is used, how many page
a process. Consider the following statements: faults occur for the above reference string?
P: Increasing the number of page frames allocated to a (a) 7 (b) 8
process sometimes increases the page fault rate. (c) 9 (d) 10
Q: Some programs do not exhibit locality of reference. 14. Least Recently Used (LRU) page replacement policy is a
Which one of the following is true? [2007, 2 marks] practical approximation to optimal page replacement. For the
(a) Both P and Q are true, and Q is the reason for P above reference string, how many more page faults occur
(b) Both P and Q are true, and Q is not the reason for P with LRU than with the optimal page replacement policy?
(c) P is false but Q is true (a) zero (b) 1
(c) Both P and Q are false (c) 2 (d) 3
11. A single processor system has three resources types X, Y 15. Which of the following is not true for deadlock prevention
and Z, which are shared by three processes. There are 5 and deadlock avoidance schemes? [2008, 1 mark]
units of each resources type. Consider the following (a) In deadlock prevention, the request for resources is
scenario, where the column alloc denotes the number of units always granted, if the resulting state is safe
of each resource type allocated to each process, and the (b) In deadlock avoidance, the request for resources is
column request denotes the number of units of each resource
always granted, if the resulting state is safe
type requested by a process in order to complete execution.
(c) Deadlock avoidance is less restrictive than deadlock
Which of these processes will finish last?
prevention
alloc request (d) Deadlock avoidance requires knowledge of resource
X Y Z X Y Z requirement a priori
P0 1 2 1 1 0 3 16. A process executes the following code
P1 2 0 1 0 1 2 for (i = 0; i < n; i ++) for ();
P2 The total number of child processes created is
2 2 1 1 2 0
(a) n (b) 2n – 1 [2008, 1 mark]
[2007, 2 marks] (c) 2 n (d) 2n + 1 – 1
(a) P0 17. A process uses 36 bit physical addresses and 32 bit virtual
(b) P1 addresses, with a page frame size of 4 kbyte. Each page table
(c) P2 entry is of size 4 byte. A three level page table is used for
(d) None of the above, since the system is in a deadlock virtual to physical address translation, where the virtual
12. Two processes P1 and P2, need to access a critical section of address is used as follows
code. Consider the following synchronization construct used Bit 30-31 are used to index into the first level page table
by the processes: Bit 21-29 are used to index into the second level page table
/* P1 */ /* P2 */ Bit 12-20 are used to index into the third level page table, and
while (true) { while (true){ Bit 0-11 are used as offset within the page
wants1 = true; wants2 = true; The number of bits required for addressing the next level
while while (wants 1 = = true); page table (or page frame) in the page table entry of the first,
(wants2 = = true); /* Critical second and third level page tables are respectively
/* Critical Section */ [2008, 2 marks]
Section */ wants2 = false; (a) 20, 20 and 20 (b) 24, 24 and 24
wants1 = false; } /* Remainder section */ (c) 24, 24 and 20 (d) 25, 25 and 24
} (/* Remainder Section) 18. A multilevel page table is preferred in comparison to a single
Here, wants1 and wants2 are shared variables, which are level page table for translating virtual address to physical
initialized to false, address because [2008, 1 mark]
Which one of the following statements is true about the (a) it reduces the memory access time to read or write a
above construct? [2007, 2 marks] memory location
OPERATING SYSTEM S3-383
(b) it helps to reduce the size of page table needed to (a) 95 ms (b) 119 ms
implement the virtual address space of a process (c) 233 ms (d) 276 ms
(c) it is required by the translation look-aside buffer 24. In the following process state transition diagram for a
(d) it helps to reduce the number of page faults in page uniprocessor system, assume that there are always some
replacement algorithms processes in the ready state. [2009, 2 marks]
19. Which of the following system calls results in the sending of
SYN packets? [2008, 2 marks] B
(a) Socket (b) Bind A
Start Ready D
(c) Listen (d) Connect Running Terminated
20. In which one of the following page replacement policies, C
Belady’s anomaly may occur? [2009, 1 mark]
(a) FIFO (b) Optimal E F
(c) LRU (d) MRU
21. The essential content(s) in each entry of a page table is/are Blocked
(a) virtual page number [2009, 2 marks]
(b) page frame number Now consider the following statements:
(c) both virtual number and page frame number 1. If a process makes a transition D, it would result in
(d) access right information another process making transition A immediately.
22. Consider a system with 4 types of resources R1 (3 units), R2 2. A process P2 is blocked state can make transition E
(2 unit), R3 (3 unit), R4 (2 unit). A non-pre-emptive resource while another process P1 is in running state.
allocation policy is used. At any given instance, a request is 3. The operating system uses pre-emptive scheduling.
not entertained if it cannot be completely satisfied. Three 4. The oper ating system uses n on-pre-emptive
processes P1, P2, P3 request the resource as follows, if scheduling.
executed independently. [2009, 2 marks] Which of the above statements are true?
(a) 1 and 2 (b) 1 and 3
Process P1; Process P2; Process P3; (c) 2 and 3 (d) 2 and 4
t = 0: requests 2 unit t = 0: requests 2 unit t = 0: requests 1 25. The enter _CS() and leave_CS() functions to implement
of R2 of R3 unit of R4 critical section of a process are realized using test-and-set
t = 1: requests 1 unit t = 2: requests 1 unit t = 2: requests 1 instruction as follows [2009, 2 marks]
void enter_CS(X)
of R3 of R4 unit of R1
{
t = 3: requests 2 unit t = 4: requests 1 unit t = 5: requests 1
while (test-and-sex (X));
of R1 of R1 unit of R1
}
t = 5: releases 1 unit void leave_CS(X)
t = 6: releases 1 unit t = 7: requests 1
of R2 and 1 unit of {
of R3 unit of R2
R1 X = 0;
t = 8: requests 1 }
t = 8: Finishes In the above solution, X is a memory location associated
unit of R3
t = 7: releases 1 unit with the CS and is initialized to 0. Now, consider the following
t = 9: Finishes statements:
of R3
1. The above solution to CS problem is deadlock-free.
t = 8: releases 2 unit
2. The solution is starvation-free.
of R4 3. The processes enter CS in FIFO order.
t = 10; Finishes 4. More than one processes can enter CS at the same
time.
Which one of the following statements is true, if all three Which of the above statements is true?
processes run concurrently starting at time t = 0? (a) 1 only (b) 1 and 2
(a) All processes will finish without any deadlock (c) 2 and 3 (d) 4 only
(b) P1 and P2 will be in deadlock 26. The data blocks of a very large file in the Unix file system are
(c) P1 and P3 will be in deadlock allocated using [2009, 2 marks]
(d) All three processes will be in deadlock (a) contiguous allocation
23. Consider a disk system with 100 cylinders. The requests to (b) linked allocation
access the cylinders occur in following sequence (c) indexed allocation
4, 34, 10, 7, 19, 73, 2, 15, 6, 20
(d) an extension of indexed allocation
Assuming that the head is currently at cylinder 50, what is
27. The P and V operations on counting semaphores, where s is
the time taken to satisfy requests, if it takes 1 ms to move
a counting semaphore, and defined as follows
from one cylinder to adjacent one and shortest seek time
P(s): s = s – 1;
first policy is used? [2009, 2 marks]
if s < 0 then wait;
EBD_7203
S3-384 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
V(s): s = s + 1; 31. Which of the following statements are true?
if s < = 0 then we ke up a process waiting on s; I. Shortest remaining time first scheduling may cause
Assume that Pb and Vb the wait and signal operations on starvation.
binary semaphores are provided. Two binary semaphores II. Pre-emptive scheduling may cause starvation.
Xb and Yb are used to implement the semaphore operations III. Round robin is better than FCFS in terms of response
P(s) and V(s) as follows time [2010, 2 marks]
P(s) : Pb(Xb); (a) I only (b) I and III
s = s – 1; (c) II and III (d) I, II and III
if (s < 0) { 32. The following program consist of 3 concurrent processes
Vb (Xb); and 3 binary semaphores. The semaphores are initialized as
Pb (Yb); S0 = 1, S1 = 0, S2 = 0 [2010, 2 marks]
}
else Vb (Xb); Process P0 Process P1 Process P2
V(s): Pb (Yb);
s = s + 1; wait (S0); wait (S 1); wait (S1);
if (s < = 0) Vb (Yb); print '0' release (S0); release (S0);
Vb(Xb); release (S1 )
The initial values of Xb and Yb are respectively release (S2);
[2009, 2 marks]
(a) 0 and 0 (b) 0 and 1 }
(c) 1 and 0 (d) 1 and 1
How many times will process P print ‘0’?
28. Which of the following statements about synchronous and
(a) Atleast twice (b) Exactly twice
asynchronous IN/OUT is not true? [2009, 2 marks]
(a) An ISR is invoked on completion of IN/OUT in (c) Exactly thrice (d) Exactly once
synchronous IN/OUT but not in asynchronous IN/ 33. A system has n resources R0, ..... Rn – 1, and k processes P0,
OUT .... Pk–1. The implementation of the resources request logic
(b) In both synchronous and asynchronous IN/OUT, an of each process Pi, is as follows if (i% 2 = = 0) {
ISR (Interrupt Service Routine) is involved after if (i < n) request Ri;
completion of the In/OUT if (i + 2 < n) request Ri + 2;
(c) A process making a synchronous IN/OUT call waits }
until IN/OUT is complete, but a process making an else {
asynchronous IN/OUT call does not wait for if (i < n) request Rn – i;
completion of the IN/OUT if (i + 2 < n) request Rn – i – 2;
(d) In the case of synchronous IN/OUT, the process }
waiting for the completion of IN/OUT is woken up by In which one of the following situations is a deadlock
the ISR that is invoked after the completion of IN/OUT possible? [2010, 2 marks]
29. Consider the methods used by processes P1 and P2 for (a) n = 40, k = 26 (b) n = 21, k = 12
accessing their critical sections whenever needed, as given (c) n = 20, k = 10 (d) n = 41, k = 19
below. The initial values of shared Boolean variables S1 and 34. A thread is usually defined as a ‘light weight process’
S2 are randomly assigned. because an Operating System (OS) maintains smaller data
structures for a thread than for a process. In relation to this,
Methods used by P1 Methods used by P2
which of the following is true? [2011, 1 mark]
while (S1 == S2); while (S 1 ! = S 2) (a) On perthread basis, the operating system maintains
Critical Section Critical Section only CPU register state
S1 = S2 ; S2 = not (S1); (b) The operating system does not maintain a separate
stack for each thread
Which one of the following statements describes the (c) On perthread basis, the operating system does not
properties achieved? [2010, 1 mark]
maintain virtual memory state
(a) Mutual exclusion but not progress
(d) On per thread basis, the operating system maintains
(b) Progress but not mutual exclusion
only scheduling and accounting information.
(c) Neither mutual exclusion nor progress
(d) Both mutual exclusion and progress 35. Let the time taken to switch between user and kernel modes
30. A system uses FIFO policy for page replacement. It has 4 of execution be t1 while the time taken to switch between
frames with no page loaded to begin with. The system first two processes be t2. Which of the following is true?
accesses 100 distinct pages in same order and then accesses (a) t1 > t2 [2011, 1 mark]
the same 100 pages but now in the reverse order. How many (b) t1 = t2
page faults will occur? [2010, 1 mark] (c) t1 < t2
(a) 196 (b) 192 (d) Nothing can be said about the relation between t1 and
(c) 197 (d) 195 t2
OPERATING SYSTEM S3-385
36. A computer handles several interrupt sources of which of 128 byte and the size of each disk block address is 8 byte.
the following are relevant for this question? The maximum possible file system is [2012, 2 marks]
Interrupt from CPU temperature sensor (a) 3 kbyte
Interrupt from Mouse (b) 35 kbyte
Interrupt from Keyboard (c) 280 kbyte
Interrupt from Hard Disk [2011, 1 mark] (d) dependent on the size of the disk
(a) Interrupt from Hard Disk 42. Fetch_And_Add (X, i) is an atomic Read-Modify-Write
(b) Interrupt from Mouse instruction that reads the value of memory location X ,
(c) Interrupt from Keyboard increments it by the value i and returns the old value of X. It
(d) Interrupt from CPU temp sensor is used in the pseudocode shown below to implement a busy-
37. An application loads 100 libraries at startup. Loading each wait lock. L is an unsigned integer shared variable initialized
library requires exactly one disk access. The seek time of the to 0. The value of 0 corresponds to lock being available,
disk to a random location is given as 10 ms. Rotational speed
while any non-zero value corresponds to the lock being not
of disk is 6000 rpm. If all 100 libraries are loaded from random
available.
location on the disk, how long does it take to load all libraries?
AcquireLock (L) {
(The time to transfer data from the disk block once the head
while (Fetch_And_Add (L, 1))
has been positioned at the start of the block may be
L = 1;
neglected? [2011, 2 marks]
(a) 0.50 s (b) 1.50 s }
(c) 1.25 s (d) 1.00 s ReleaseLock (L) {
38. Consider the following table of arrival time and burst time for L= 0
three processes P0, P1 and P2. }
This implementation [2012, 2 marks]
Process Arrival time Burst time (a) fails as L can overflow
P0 0 ms 9 ms (b) fails as L can take on a non-zero value that lock is
P1 1 ms 4 ms actually available
(c) works correctly but may starve some processes
P2 2 ms 9 ms
(d) works correctly without starvation
The pre-emptive shortest job first scheduling algorithm is 43. Consider the 3 processes, P1, P2 and P3 shown in the table:
used. Scheduling is carried out only at arrival or completion
of processes. What is the average waiting time for the three Arrival Time units
Process
processes? [2011, 2 marks] time required
(a) 5.0 ms (b) 4.33 ms P1 0 5
(c) 6.33 ms (d) 7.33 ms P2 1 7
39. A process executes the code
P3 3 4
fork ();
fork (); The completion order of the 3 processes under the policies
fork (); FCFS and RR2 (Round Robin scheduling with CPU quantum
The total number of child processes created is 2 time units) are [2012, 2 marks]
[2012, 1 mark] (a) FCFS: P1, P2, P3 RR2 : P1, P2, P3
(a) 3 (b) 4
(b) FCFS: P1, P3, P2 RR2 : P1, P3, P2
(c) 7 (d) 8
(c) FCFS: P1, P2, P3 RR2 : P1, P3, P2
40. Consider the virtual page reference string:
1, 2, 3, 2, 4, 1, 3, 2, 4, 1 (d) FCFS: P1, P2, P3 RR2 : P1, P2, P3
On a demand paged virtual memory system running on a Statement for Linked Answer Questions 44 & 45
computer system that has main memory size of 3 page frames A computer has a 256 kbyte. 4-way set associative, write back
which are initially empty. Let LRU FIFO and OPTIMAL data cache with block size of 32 byte. The processor sends 32 bit
denote the number of page faults under the corresponding addresses to the cache controller. Each cache tag directory entry
page replacement policy. Then, [2012, 2 marks] contains, in addition to address tag, 2 valid bit, 1 modified bit and
(a) OPTIMAL < LRU < FIFO 1 replacement bit.
(b) OPTIMAL < FIFO < LRU 44. The number of bits in the tag field of an address is
(c) OPTIMAL = LRU (a) 11 (b) 14 [2012, 2 marks]
(c) OPTIMAL = FIFO (c) 16 (d) 27
41. A file system with 300 Gbyte disk uses a file descriptor with 45. The size of the cache tag directory is [2012, 2 marks]
8 direct block addresses, 1 indirect block address and 1 (a) 160 kbit (b) 136 kbit
doubly indirect block address. The size of each disk block is (c) 40 kbit (d) 32 kbit
EBD_7203
S3-386 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
46. A scheduling algorithm assigns priority proportional to employ two binary semaphores R and S, both initialized
the waiting time of a process. Every process starts with to zero. The array a is shared by the two processes. The
priority zero (the lowest priority). The scheduler re- structures of the processes are shown below.
evaluates the process priorities every T time units and Process X:
decides the next process to schedule. Which one of the private i;
following is TRUE if the processes have no I/O operations for (i=0; i<n; i++) {
and all arrive at time zero? [2013, 1 Mark] a[i] = f(i);
(a) This algorithm is equivalent to the first-come- ExitX(R, S);
first-serve algorithm }
(b) This algorithm is equivalent to the round-robin Process Y:
algorithm private i;
(c) This algorithm is equivalent to the shortest-job-first for (i=0; i<n; i++) {
algorithm EntryY(R, S);
(d) This algorithm is equivalent to the shortest-remaining- b[i] = g(a[i]);
time-first algorithm }
47. Three concurrent processes, X, Y and Z execute three Which one of the following represents the correct
different code segments that access and update certain implementations of ExitX and EntryY?
shared variables. Process X executes the P operation [2013, 2 Marks]
(i.e. wait) on semaphores a, b and c; process Y executes (a) ExitX(R, S) {
the P operation on semaphores b, c and d; process Z P(R);
executes the P operation on semaphores c, d and a before V(S);
entering the respective code segments. After completing }
the execution of its code segment, each process invokes EntryY(R, S) {
the V operation (i.e. signal) on its three semaphores. P(S);
All semaphores are binary semaphores initialized to one. V(R);
Which one of the following represents a deadlock-free }
order of invoking the P operations by the processes? (b) ExitX(R, S) {
[2013, 1 Mark] V(R);
(a) X: P(a)P(b)P(c) Y: P(b)P(c)P(d) Z: P(c)P(d)P(a) V(S);
(b) X: P(b)P(a)P(c) Y: P(b)P(c)P(d) Z: P(a)P(c)P(d) }
(c) X: P(b)P(a)P(c) Y: P(c)P(b)P(d) Z: P(a)P(c)P(d)
EntryY(R, S) {
(d) X: P(a)P(b)P(c) Y: P(c)P(b)P(d) Z: P(c)P(d)P(a)
P(R);
48. A shared variable x, initialised to zero, is operated on by
P(S);
four concurrent processes W, X, Y, Z as follows. Each of
}
the processes W and X reads x from memory, increments
(c) ExitX(R, S) {
by one, stores it to memory and then terminates. Each of
P(S);
the processes Y and Z reads x from memory, decrements
V(R);
by two, stores it to memory and then terminates. Each
}
process before reading x invokes the P operation (i.e.
EntryY(R, S) {
wait) on a counting semaphore S and invokes the V
V(S);
operation (i.e. signal) on the semaphore S after storing x
P(R);
to memory. Semaphore S is initialised to two. What is the
}
maximum possible value of x after all processes complete
(d) ExitX(R, S) {
execution? [2013, 2 Marks]
V(R);
(a) –2 (b) –1
P(S);
(c) 1 (d) 2
}
49. A certain computation generates two arrays a and b such
EntryY(R, S) {
that a[i] = f(i) for 0 £ i < n and b[i] = g(a[i]) for 0 £ i < n.
V(S);
Suppose this computation is decomposed into two
P(R);
concurrent processes X and Y such that X computes the
}
array a and Y computed the array b. The processes
OPERATING SYSTEM S3-387
50. Suppose a disk has 201 cylinders, numbered from 0 to 200. Using the shortest remaining time first scheduling algorithm,
At some time the disk arm is at cylinder 100, and there is a the average process turnaround time (in msec) is
queue of disk access requests for cylinders 30, 85, 90, 100, ____________________. [2014, Set-1, 2 Marks]
105, 110, 135 and 145. If Shortest-Seek Time First (SSTF) is 54. Assume that there are 3 page frames which are initially empty.
being used for scheduling the disk access, the request for If the page reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, the
cylinder 90 is serviced after servicing ____________ number of page faults using the optimal replacement policy
number of requests. [2014, Set-1, 1 Mark] is__________. [2014, Set-1, 2 Marks]
55. Three processes A, B and C each execute a loop of 100
51. Which one of the following is FALSE?
iterations. In each iteration of the loop, a process performs
[2014, Set-1, 1 Mark]
a single computation that requires tC CPU milliseconds and
(a) User level threads are not scheduled by the kernel.
then initiates a single I/O operation that lasts for t io
(b) When a user level thread is blocked, all other threads
milliseconds. It is assumed that the computer where the
of its process are blocked. processes execute has sufficient number of I/O devices and
(c) Context switching between user level threads is faster the OS of the computer assigns different I/O devices to
than context switching between kernel level threads. each process. Also, the scheduling overhead of the OS is
(d) Kernel level threads cannot share the code segment. negligible. The processes have the following characteristics:
52. An operating system uses the Banker’s algorithm for Process id tc tio
deadlock avoidance when managing the allocation of three A 100 ms 500 ms
resource types X, Y, and Z to three processes P0, P1, and P2. B 350 ms 500 ms
The table given below presents the current system state. C 200 ms 500 ms
Here, the Allocation matrix shows the current number of The processes A, B, and C are started at times 0, 5 and 10
resources of each type allocated to each process and the milliseconds respectively, in a pure time sharing system
Max matrix shows the maximum number of resources of each (round robin scheduling) that uses a time slice of 50
type required by each process during its execution. milliseconds. The time in milliseconds at which process C
would complete its first I/O operation is ___________.
Allocation Max [2014, Set-2, 2 Marks]
56. A computer has twenty physical page frames which contain
X Y Z X Y Z
pages numbered 101 through 120. Now a program accesses
P0 0 0 1 8 4 3 the pages numbered 1, 2, ..., 100 in that order, and repeats
P1 3 2 0 6 2 0 the access sequence THRICE. Which one of the following
P2 2 1 1 3 3 3 page replacement policies experiences the same number of
page faults as the optimal page replacement policy for this
There are 3 units of type X, 2 units of type Y and 2 units of program? [2014, Set-2, 2 Marks]
type Z still available. The system is currently in a safe state. (a) Least-recently-used (b) First-in-first-out
Consider the following independent requests for additional (c) Last-in-first-out (d) Most-recently-used
resources in the current state: 57. A system uses 3 page frames for storing process pages in
REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z main memory. It uses the Least Recently Used (LRU) page
REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z replacement policy. Assume that all the page frames are
Which one of the following is TRUE? initially empty. What is the total number of page faults that
[2014, Set-1, 2 Marks] will occur while processing the page reference string given
(a) Only REQ1 can be permitted. below? [2014, Set-3, 1 Mark]
(b) Only REQ2 can be permitted. 4, 7, 6, 1, 7, 6, 1, 2, 7, 2
(c) Both REQ1 and REQ2 can be permitted. 58. An operating system uses shortest remaining time first
scheduling algorithm for pre-emptive scheduling of
(d) Neither REQ1 nor REQ2 can be permitted.
processes. Consider the following set of processes with
53. Consider the following set of processes that need to be
their arrival times and CPU burst times (in milliseconds):
scheduled on a single CPU. All the times are given in
milliseconds. Process Arrival Time Burst Time
P1 0 12
Process Name Arrival Time Execution Time P2 2 4
A 0 6 P3 3 6
B 3 2 P4 8 5
C 5 4
The average waiting time (in milliseconds) of the processes
D 7 6
is _________. [2014, Set-3, 2 Marks]
E 10 3
EBD_7203
S3-388 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Spatial locality refers to the problem that once a location is 10. A computer system has 4 K word cache organized in a block-
referenced set-associative manner, with 4 blocks per set, 64 words per
(a) it will not be referenced again block. The number of bits in the SET and WORD fields of the
(b) it will be referenced again main memory address format is
(c) a nearby location will be referenced soon (a) 15, 4 (b) 6, 4
(d) none of these (c) 7, 2 (b) 4, 6
2. Page fault occurs when 11. A computer installation has 1000 K of main memory. The
(a) the page is corrupted by application software jobs arrive and finish in the following sequence.
(b) the page is main memory Job 1 requiring 200 K arrives
(c) the page is not in main memory Job 2 requiring 350 K arrives
(d) the tries to divide a number by 0 Job 3 requiring 300 K arrives
3. Concurrent processes are processes that Job 1 finishes
(a) do not overlap in time Job 4 requiring 120 K arrives
(b) overlap in time Job 5 requiring 150 K arrives
(c) are executed by a processor at the same time Job 6 requiring 80 K arrives
Among best fit and first fit, which performs better for this
(d) none of these
sequence?
4. Which of the following are real-time systems?
(a) first fit (b) best fit
1. An on-line railway reservation system
(c) both perform the same (d) none of the these
2. A process control system The next 4 questions are based on the following information
3. Aircraft control system Consider a set of processes whose arrival time, CPU time needed
4. Payroll processing system and the priority are given below.
(a) 1 and 2 (b) 3 and 4
(c) 2 and 3 (d) 1, 2, 3 and 4
Process Arrival Time CPU Time
5. Dijkstra’s banking algorithm in an operating system solves Priority
Priority (in ms) Needed (in ms)
the problem of
(a) deadlock avoidance (b) deadlock recovery P1 0 10 5
(c) mutual exclusion (d) context switching
6. Kernel is P2 0 5 2
(a) considered as the critical part of the operating system P3 2 3 1
(b) the software which monitors the operating system
(c) the set of primitive functions upon which the rest of P4 5 20 4
operating system function are built up.
P5 10 2 3
(d) none of these
7. In a time-sharing operating system, when the time slot given
Note: Smaller the number, higher the priority
to a process is completed, the process goes from the
12. If the CPU scheduling policy is FCFS, the average waiting
RUNNING state to the
time will be
(a) BLOCKED state (b) READY state
(a) 12.8 ms (b) 8 ms
(c) SUSPENDED state (b) TERMINATED state (c) 16 ms (d) none of the above
8. If there are 32 segments, each of size 1 k bytes, then the 13. If the CPU scheduling policy is SJF, the average waiting time
logical address should have (without pre-emption) will be
(a) 13 bits (b) 14 bits (a) 12.8 ms (b) 6.8 ms
(c) 15 bits (d) 16 bits (c) 17 ms (d) none of these
9. In a paged segmented scheme of memory management, the 14. If the CPU scheduling policy is SJF with pre-emption, the
segment table itself must have a page table because average waiting time will be
(a) the segment table is often too large to fit in one page (a) 8 ms (b) 14 ms
(b) each segment is spread over a number of pages (c) 5.6 ms (d) none of these
(c) segment tables point to page tables and not to the 15. If the CPU scheduling policy is priority scheduling with pre-
physical location of the segment emption, the average waiting time will be
(d) the processor’s description base register points to a (a) 19 ms (b) 7.6 ms
page table. (c) 8 ms (d) none of these
OPERATING SYSTEM S3-389
16. Distributed systems should 26. Consider the following statements:
(a) meet prescribed time constraints S1 : The OS is designed to maximize the resource utilization.
(b) aim better resource sharing S2 : The control program manages the system programs.
(c) aim better system utilization Which of the above statements is/are true?
(d) aim low system overhead (a) S1 is true S2 is false (b) S2 is true and S1 is false
17. Which of the following are single-user operating system? (c) both S1 and S2 are true (d) both S1 and S2 are false
1. MS-DOS 2. UNIX 27. Program counter specifies
3. XENIX 4. OS2 (a) the current instruction to execute
(a) 1 and 2 (b) 2 and 4 (b) the previous instruction to execute
(c) 1 and 3 (d) None of these (c) the next instruction to execute
18. Supervisor call (d) the last instruction to execute
(a) is a called made by the supervisor of the system 28. Process Control Block (PCB) of all running process reside in
(b) is a call with control functions which of the following?
(c) are privileged calls that are used to perform resource (a) RAM (b) Harddisk
management functions, which are controlled by the (c) Cache (d) None of these
operating system 29. If a system contains n processors and n processes then
(d) is a call made by someone working in root directory what will be maximum and minimum processes in running
19. Semaphores are used to solve the problem of state respectively.
1. race condition (a) n, n (b) n, 0
2. process synchronization (c) n2, 0 (d) n2, n2
3. mutual exclusion 30. Match List-I with List-II select the correct answer using the
4. none of these codes given below the lists:
(a) 1 and 2 (b) 2 and 3 List-I List-II
(c) All of the above (d) None of these A. run ® ready 1. not possible
20. Sector interleaving in disks is done by B. run ® blocked 2. when a process
(a) the disk controller terminates itself
(b) the disk manufacturer
C. blocked ® run 3. when a process time
(c) programmer
quantum expires
(d) the OS
D. run ® terminated 4. when a process issues
21. Which of the following is a service not supported by the
an input/output request
operating system?
Codes:
(a) Protection (b) Accounting
A B C D
(c) Compilation (d) I/O operation
(a) 1 4 3 2
22. Locality of reference implies that the page reference being
(b) 2 1 3 4
made by a process
(c) 3 4 1 2
(a) will always be to the page used in the previous page
reference (d) 1 4 3 2
(b) is likely to be one of the pages used in the last few 31. In a lottery scheduler with 40 tickets. How we will distribute
page references the tickets among 4 processes P1, P2, P3 and P4 such that
(c) will always be one of the pages existing in memory each process gets 10%, 5%, 60% and 25% respectively.
(d) will always leads to a page fault P1 P2 P3 P4
23. Thrashing (a) 12 4 70 30
(a) reduces page I/O (b) 7 5 20 10
(b) decreases the degree of multiprogramming (c) 4 2 24 10
(c) implies excessive page I/O (d) 8 5 40 30
(d) improves the system performance 32. Starvation can be avoided by which of the following
24. When an interrupt occurs, an operating system statements.
(a) ignores the interrupt 1. By using shortest job first resource allocation policy.
(b) always changes the state of the interrupted process 2. By using first-come, first serve resource allocation
after processing the interrupt policy.
(c) always resumes execution of the interrupted process (a) 1 only (b) 2 only
after processing the interrupt (c) 1 and 2 only (d) none of these
(d) may change the state of the interrupted process to 33. If a system contains CPU bound processes then which of
“blocked” and schedule another process the following scheduling algorithm produces maximum
25. A system with multiple CPU’s is called efficiency of the CPU:
(a) time sharing system (b) desktop system (a) FIFO (b) round robin
(c) client-server system (d) parallel system (c) SJF (d) priority
EBD_7203
S3-390 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
34. The time interval between the time of submission of a process 39. Which of the following is NOT true of deadlock prevention
to the time of completion of a process is known as which of and deadlock avoidance schemes?
the following? (a) In deadlock prevention, the request for resources is
(a) waiting time (b) response time always granted if the resulting state is safe
(c) turn around time (d) none of these (b) In deadlock avoidance, the request for resources is
35. The jobs are assumed to have arrived at time 0 and in the always granted if the resulting state is safe
order p, q, r, s, t. Calculate the departure time for job p if (c) Deadlock avoidance is less restrictive than deadlock
scheduling is round-robin with time slice of 1. prevention.
(d) Deadlock avoidance requires knowledge of resource
Job ID CPU Burst Time requirements a priori.
p 4 40. Consider we have four processes P1, P2, P3 and P4 and
q 1 consider the following table. Consider the a < b < c < d where
r 8 a, b, c and d is the execution time of P1, P2, P3 and P4
s 1 respectively.
t 2
Process Execution Time
(a) 16 (b) 10 P1 a
(c) 11 (d) 12
P2 b
36. Process CPU Burst time Arrive time P3 c
P1 5 0 P4 d
What is the average turn around time when shortest job first
P2 3 1 CPU scheduling algorithm is used?
P3 4 2 (a) (3a + 4b + c + d)/4 (b) (4a + 3b + 2c + d)/4
(c) (a + 2b + 3c + 4d)/4 (d) None of these
P4 1 3 41. Peterson’s algorithm is the solution of which of the following
Above process arrive in the order P1, P2, P3 and P4 are served problem.
in FCFS order. The average turn around time is _____ and (a) deadlock (b) mutual exclusion
average waiting time is ______. (c) trashing (d) paging
(a) 4.5 millisec, 6.25 millisec (b) 3.5 millisec, 4.75 millisec 42. Suppose we have a system in which processes is in hold and
wait condition then which of the following approach prevent
(c) 8 millisec, 4.75 millisec (d) 4.75 millisec, 8 millisec
the deadlock.
37. Consider the following performance table for FCFS
(a) Request all resources initially
scheduling. For this batch of processes, the throughout will (b) Spool everything
be ..... (c) Take resources away
Position in Job arrival Job completion (d) Order resources numerically
batch time (Ai) time (Ci ) 43. Referring to below system state diagram how may resources
1 3 8 are available?
2 8 10 P
1
3 10 16
4 12 18
5 15 29 R1 R2
(a) 0.184 (b) 0.192
(c) 0.269 (d) 0.238
38. An operating system makes use of Banker’s algorithm to P2
allocate 12 printers. Printers will be allocated to a process
requesting them only if three are enough available printers 1. One instance of resource of R1
to allow it to run to completion. 2. Two instance of resource of R2
User 1 using 7 printers and will need at most a total of 10 (a) Only 1 (b) Only 2
printers. (c) Both and 2 (d) Neither 1 nor 2
User 2 using 1 printer and will need at most 4 printers. User 3 44. Suppose that a certain computer will paged virtual memory
is using 2 printers and will need at most 4 printers. Each user has 4 KB pages, a 320 bit byte-addressable virtual address
is currently requesting 1 more printer. Which of the following space and, 30 bit byte-addressable physical address space.
is true? The system manages an inverted page table. Where each
(a) The operating system will grant a printer to User 1 only entry includes the page number plus 12 overhead bits. How
(b) The operating system will grant a printer to User 2 only big is the basic inverted page table including page number
(c) The operating system will grant a printer to User 3 only and overhead bits?
(d) The operating system will not grant any more printers (a) 210 B (b) 220 B
(c) 2 B 30 (b) 232 B
until some are relinquished
OPERATING SYSTEM S3-391
45. Which of the following statements is true? Codes
(a) Segmentation is faster than paging A B C D A B C D
(b) Paging is faster than segmentation (a) 2 5 1 4 (b) 3 2 4 1
(c) Paging and segmentation both having equal speed (c) 2 1 4 5 (d) 3 1 4 2
(d) None of these 53. In a multi-user operating system, 20 requests are made to
46. Disk requests come to a disk driver for cylinders 98, 183, 37, use a particular resource per hour, on an average. The
122, 14, 124, 65, 67 in that order at a time when the disk drive probability that no requests are made in 45 minutes is
is reading from cylinder 53. The total seek time, if the disk (a) e –15 (b) e –5
arm scheduling algorithm is shortest seek time first, is (c) 1 – e –5 (d) 1 – e–10
(a) 236 (b) 331 54. In which of the following scheduling policies does context
(c) 299 (d) None of these switching never take place?
47. What is the reference count field in the inode? 1. Round-robin
(a) It counts the number of processes currently executing 2. Shortest job first (non pre-emptive)
in the inode
3. Pre-emptive
(b) It counts the number of hard links presently pointing
4. First-come-first-serve
at a particular node
(c) It count the size of memory required by the inode (a) 4 only (b) 1 and 3
(d) None of these (c) 2 and 3 (d) 2 and 4
48. On a system using paging and segmentation, the virtual 55. To obtain better memory utilization, dynamic loading is used.
address space consists of up to 8 segments where each With dynamic loading, a routine is not loaded until is called
segment can be upto 229 bytes long. The hard ware pages for. For implementing dynamic loading.
each segment into 256 bytes pages. How many bits in the (a) special support from hardware is essential
virtual address specify the page number? (b) special support from operating system is essential
(a) 32 (b) 3 (c) special support from both hardware and operating
(c) 8 (d) 21 system are essential
49. Given reference to the following page by a program (d) user programs can implement dynamic loading without
0, 9, 0, 1, 8, 1, 8, 7, 8, 7, 1, 2, 8, 2, 7, 8, 2, 3, 8, 3 any special support from the operating system or the
If the program contains 3 page frames. How many page fault hardware
will occur in optimal page replacement policy? 56. In which of the following directory system, is it possible to
(a) 4 (b 5 have multiple complete paths for a file, starting from the root
(c) 6 (d) 7 directory?
50. Determine the page faults when FIFO is applied to the (a) Single level directory
following string with 3 frames 2, 4, 3, 1, 5, 3, 2, 5, 3, 1, 4, 2 (b) Two level directory
(a) 10 (b) 12 (c) Three structured directory
(c) 9 (d) 7 (d) Acyclic graph directory
51. In pages memory, the page hit ratio is unity. The time required 57. Which of the following is true?
to access a page in primary memory is 20 ns, then the average (a) The linkage editor is used to edit programs which have
time required to access page is to be later linked together.
(a) 14 ns (b) 20 ns (b) The linkage editor links object modules during
(c) 6 ns (b) 10 ns compiling or assembling.
52. Match List-I with List-II select the correct answer using the (c) The linkage editor links object modules and resolves
codes given below the lists: external references between them before loading
List - I (d) The linkage editor resolves external references between
A. Next fit the object modules during execution time.
B. Buddy system 58. Which of the following is true?
C. Best fit (a) Overlays are used to increase the size of physical
D. First fit memory.
List - II
(b) Overlays are used to increase the logical address space.
1. The memory is divided into a number of small size
(c) When overlays are used, the size of a process is not
memory and required number of memories are allocated
limited to the size of physical memory.
to the needed segment.
(d) Overlays are used whenever the physical address space
2. When process and holes are kept on a list stored by
address then, this algorithm is faster. is smaller than the logical address space.
3. It chooses the hole from the list, from the place where 59. A computer system has 6 tape drives, with ‘n’ processes
it left off last time while searching hole. completing for them. Each process may need 3 tape drives.
4. When process and holes are kept on a list sorted on The maximum value of ‘n’ for which the system is guaranteed
size then this algorithm is faster. to be deadlock free is
5. We choose the hole into which needed segment will (a) 2 (b) 3
fit. (c) 4 (d) 1
EBD_7203
S3-392 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
60. At a particular time of computation, the value of a counting 69. A system has 3 processes sharing 4 resources. If each process
semaphore is 7. Then 20 P operation and ‘x’ V operation were needs a maximum of 2 units then, deadlock
completed on this semaphore. If the final value of the (a) can never occur (b) may occur
semaphore is 5, x will be (c) has to occur (d) none of the these
(a) 15 (b) 22 70. A process refers to 5 pages, A, B, C, D and E in the order - A,
(c) 18 (d) 13 B, C, D, A, B, E, A, B, C, D, E. If the page replacement algorithm
61. In a paged memory, the page hit ratio is 0.35. The time required is FIFO, the number of pages which transfer with an empty
to access a page in secondary memory is equal to 100 ns. internal store of 3 frames is
The time required to access a page in primary memory is 10 (a) 8 (b) 10
ns. The average time required to access a page is (c) 9 (d) 7
(a) 3.0 ns (b) 68.0 ns 71. Disk requests come to a disk driver for cylinders 10, 22, 20, 2,
(c) 68.5 ns (d) 78.5 ns 40, 6 and 38, in that order at a time when the disk drive is
62. Suppose that a process spends a fraction p of its time in I/O reading from cylinder 20. The seek time is 6 ms per cylinder.
wait state. With n processes in memory at once, the The total seek time, if the disk arm schedulling algorithm is
probability that all n processes are waiting for I/O is first-come-first-served is : –
(a) 1/p (b) 1/pn (a) 360 ms (b) 876 ms
(c) 1 – pn (d) p n (c) 850 ms (d) 900 ms
63. Determine the number of page faults when references to 72. A certain moving arm disk storage with one head has
pages occur in order - 1, 2, 4, 5, 2, 1, 2, 4. Assume that the following specifications:
main memory can accommodate 3 pages and the main memory Number of tracks/recording surface = 200
already has the pages 1 and 2, with page 1 having been Disk rotation speed = 2400 rpm
brought earlier than page 2. (Assume LRU algorithm is used).
Track storage capacity = 62500 bits
(a) 3 (b) 5
The average latency time (assume that the head can move
(c) 4 (d) None of these
from one track to another only by traversing the entire track)
64. Working set (t, k) at an instant of time t, is the set of is
(a) k future references that the operating system will make (a) 2.5 s (b) 2.9 s
(b) future references that the operating system will make (c) 3.1 s (d) 3.6 s
in the next ‘k’ time units. 73. Consider the resource allocation graph in figure
(c) k references with high frequency
(d) pages that have been referenced in the last k time units P1 P0
65. If the property of locality of reference is well pronounced a
program R1 R2 R3
1. the number of page faults will be more
2. the number of page faults will be less
3. the number of page faults will remains the same
4. execution will be faster
(a) 1 and 2 (b) 2 and 4 P3 P2
(c) 3 and 4 (d) None of these
66. Disk requests come to a disk driver for cylinders in the order This system is in a deadlock state. This remark is
10, 22, 20, 2, 40, 6 and 38, at a time when the disk drive is (a) true
reading from cylinder 20. The seek time is 6 ms per cylinder. (b) false
The total seek time, if the disk arm scheduling algorithm is (c) impossible to determine
first-come-first-served is (d) unpredictable
(a) 360 ms (b) 850 ms 74. A memory page containing a heavily used variable that was
(c) 900 ms (d) None of these initialized very early and is in constant use is removed, when
67. How many pages faults occur for optimal page replacement the page replacement algorithm used is
following reference string, with four page frames? (a) LRU (b) FIFO
1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2 (c) LFU (d) None of these
(a) 14 (b) 13 75. The address sequence generated by tracing a particular
(c) 11 (d) 12 program executing in a pure demand paging system with 100
68. Consider a system having ‘m’ resources of the same type. records per page, with 1 free main memory frame is recorded
These resources are shared by 3 processes A, B, C, which as follows. What is the number of page faults?
have peak time demands of 3, 4, 6 respectively. The minimum 0100, 0200, 0430, 0499, 0510, 0530, 0560, 0120, 0220, 0240,
value of ‘m’ that ensures that deadlock will never occur is 0260, 0320, 0370
(a) 11 (b) 12 (a) 13 (b) 8
(c) 13 (d) 14 (c) 7 (d) 10
OPERATING SYSTEM S3-393
76. Each process Pi, i = 1, 2, 3, ..... 9 is coded as follows: 81. Consider the following code
repeat Void main () {
P(mutex) ...
{critical section} for (int k = 1; k < = 5; k++){
V(mutex) pid [k] = fork ();]
forever }
The code for P10 is identical except that is uses V (mutex) In the given code all fork () statements executed successfully
instead of P (mutex). What is the largest number of processes and all pid variables initialized to 0. What will be the total
that can be inside the critical section at any moment? number of processes created by the above code?
(a) 1 (b) 2 (a) 1 (b) 5
(c) 3 (d) None of these
(c) 16 (d) 32
77. A process executes the following code:
82. Consider the following:
for (i = 0; i < n; i++) fork ();
The total number of child processes created is int numreader = 0;
(a) n (b) 2n – 1 mutex = semaphore (1);
(c) 2 n (d) 2n + 1 – 1 roomempty (1);
78. While designing a kernel, an operating system designer must Reader Code Writer Code
decide whether to support kernel-level or user-level threading. r1: mutex.wait () w1: roomempty wait;
Which of the following statements is/are true? r2: numreader + = 1; w2 :/* Critical Write
1. Kernel-level threading may be preferable to user-level Section*/
threading because storing information about user-level r3: if (numreader = = 1) w3:roomempty.signal ();
threads in the process control block would create a r4: roomempty.wait ();
security risk. r5: mutex.signal ();
2. User-level threading may be preferable to kernel-level r6: /*Critical Reader Section*/
threading because in user-level threading, if one thread r7: mutex.wait ();
blocks on I/O, the process can continue. r8: numreader – = 1
(a) 1 only (b) 2 only r9: if (numreader = = 0)
(c) 1 and 2 only (d) none of these r10: roomempty.signal();
79. Which of the following should be allowed only in kernel
r11: mutex.signal();
mode?
1. Changing mapping from virtual to physical address. The above code is a proposed solution of the Readers/Writer
2. Mask and unmask interrupts problem.
3. Disabling all interrups Consider which of the following statements is/are true?
4. Reading status of processor 1. The code allow several writers to execute in the writer
5. Reading time of day critical area at the same time
(a) 1, 2 and 3 (b) 1, 2, 4 and 5 2. The code allow several readers to execute in the readers
(c) 2, 3 and 5 (d) all of the above critical area at the same time
80. Consider a queue between the two processes indicated (a) 1 only (b) 2 only
below. (c) 1 and 2 both (d) none of these
N is the length of queue and e, f and b are semaphore. 83. Consider the following statements about user level threads
init: e : = N; f = 0 b : = 1 and kernel level threads. Which one of the following
Process 1: Process 2: statements is FALSE?
loop loop (a) Context switch time is longer for kernel level threads
p(e) p(f) than for user level threads
p(b) p(b) (b) User level threads do not need any hardware support
enqueue dequeue (c) Related kernel level thread can be scheduled on different
V(b) V(b) processors in a multiprocessor system
V(f) V(e)
(d) Blocking one kernel level thread blocks all related
end loop end loop
threads
Which of the following statements is.are true?
1. The purpose of semaphore f is to ensure that dequeue 84. Consider a system contains two types of processes CPU
is not executed on an empty queue. bound processes and I/O bound processes what will be the
2. The purpose of semaphore e is to ensure that deadlock sufficient condition when ready queue become empty.
does not occur. (a) if all processes are CPU bound
3. The purpose of semaphore b is to provide mutual (b) if all processes are I/O bound
exclusion for queue operations. (c) if half of the processes are CPU bound and half are I/O
(a) 1 only (b) 2 only bound
(c) 1 and 3 only (d) 2 and 3 only (d) none of these
EBD_7203
S3-394 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
85. Consider following set of process with the CPU burst time 90. Processes P1 and P2 use critical_flag in the following routine
given in milliseconds, arrival time and priority. to achieve mutual exclusion. Assume that critical_flag is
initialized to FALSE in the main program.
Process Arrival Burst time Priority get_exclusive_access()
A 0 8 4 { if (critical_flag = = FALSE) {
critical_flag = TRUE ;
B 1 4 3 critical_region () ;
critical_flag = FALSE ;
C 2 6 1 }
}
D 3 1 2
Consider the following statements:
Average turn around time using preemptive is ..... and using 1. It is possible for both P1 and P2 to access critical_region
non-preemptive is... concurrently.
(a) 12.5 ms, 10.5 ms (b) 11.5 ms, 13.5 ms 2. This may lead to a deadlock.
(c) 10.5 ms, 12.5 ms (d) 13.5 ms, 11.5 ms Which of the following holds?
86. Multilevel feedback queue scheduling (a) 1 is false and 2 is true (b) Both 1 and 2 are false
(a) allows to select a process and load it to memory for (c) 1 is true and 2 is false (d) Both 1 and 2 are true
execution 91. The following is a code with two threads, producer and
(b) allows to select a process, that are ready to execute consumer, that can run parallel, Further, S and Q are binary
and allows CPU to one of them. semaphore equipped with the standards P and V operations.
(c) does not allow a process to move between queues semaphore S = 1, Q = 0
(d) allows processes which are permanently assigned to a integer x;
queue on the entry to the system.
producer : consumer
87. If the time slice used in the round-robin scheduling policy is
more than maximum time required to execute any process. while (true) do while (true) do
Then the policy will P(S) P(Q)
x = produce () : consume (x);
(a) degenerate the shortest job first
(b) degenerated the priority scheduling V(Q); V(S);
(c) degenerated to first come first serve done done
(d) none of these Which of the following is true about above program?
88. Suppose there are five process in the ready queue as shown (a) The process can deadlock.
below. (b) Some of the threads can starve.
i T( Pi) Priority (c) Some of the items produced by the producer may be
lost.
0 350 5
(d) Values generated and stored in ‘x’ by the producer will
1 125 2 always be consumed before the producer can generate
a new value.
2 475 3 92. Match List I with List- II select the correct answer using the
3 1 codes given below the lists:
250
List I List II
4 75 4 A. Inconsistency 1. requires the recognition
If FCFS, SJF and priority scheduling algorithms are used, for of unsafe states
which algorithm is the average time is the minimum? Assume B. Deadlock resolution 2. a message received by
lower integer indicates higher priority. Assume all arrives at Pj from Pi that is not
time zero. shown as sent by Pi.
(a) FCFS (b) SJF C. Deadlock avoidance 3. a message sent by Pi to
(c) Priority scheduling (d) None of these Pj (m ij) that does not
89. The sequence.......... is a non-preemptive scheduling belong to the set of
sequence for the following jobs which leaves the CPU idle messages received by
for ..... unit(s) of time Pj.
D Transit 4. always requires the
Job Arrival Burst Time abortion of one of more
1 0.0 9 executing processes.
Codes:
2 0.6 5 A B C D
(a) 3 1 4 2
3 1.0 1
(b) 2 4 1 3
(a) {3, 2, 1}, 1 (b) {2, 1, 3}, 0 (c) 3 4 1 2
(c) {3, 2, 1}, 0 (d) {1, 2, 3}, 5 (d) 2 1 4 3
OPERATING SYSTEM S3-395
93. Consider: (a) Efficient implementation of multi-user is no longer
P = {P1, P2, P3} possible
R = {R1, R2, R3, R4} (b) The processor cache organized can be made more
One instance of resource type R1, two instances of resources efficient now.
type R2, one instances of resource type R3 and three instances (c) Hardware support for memory management is no longer
of resource type R4. The situation is P1 is holding one needed
instance of R2 and waiting for an instance R1, P2 is holding (d) CPU scheduling can be made more efficient now
an instance of R1, one instance of R2 and waiting for an 100. Consider a swapping system in which memory consists of
instance of R3 and P3 is holding an instance of R3. hole sizes in following order:
(a) Deadlock will not occur 10 KB, 4 KB, 17 KB, 18 KB, 7 KB, 9 KB, 12 KB, 15 KB, 20 KB
(b) Deadlock will occur Which hole is taken for segment request of 12 KB
(c) All the instances of R4 are held by the processes (i) By using first fit
(d) All the instances of R2 are not allotted (ii) By using best fit
94. Which of the following is the solution of priority inversion (iii) By using worst fit
problem? (a) 17 KB, 17 KB, 20 KB (b) 17 KB, 12 KB, 17 KB
(a) Kill the higher-priority process (c) 17 KB, 12 KB, 20 KB (d) 17 KB, 18 KB, 12 KB
(b) Kill the lower-priority process 101. A disk has 200 tracks (numbered 0 through 199). At a given
(c) Priority-Inheritance protocol time, it was servicing the request of reading data from track
(d) Semaphore 120, and at the previous request, service was for track 90.
95. Let R1,R2, R3 be reader processes and let W1 and W2 be The pending requests (in order of their arrival) are for track
writer processes requesting shared data. If R1 is selected for numbers, 30, 70, 115, 130, 110, 80, 20, 25.
access. How many times will the head change its direction for the
Which of the statement is/are correct? disk scheduling policies SSTF (shortest Seek Time First) and
1. Mutual exclusion is necessary for R2 and R3 FCFS (First Come First Serve)
2. No mutual exclusion is necessary for R2 and R3 (a) 2 and 3 (b) 3 and 3
3. Mutual exclusion must be there for W1 and W2 (c) 3 and 4 (d) 4 and 4
4. No mutual exclusion must be there for W1 and W2 102. A hard disk system has the following parameters:
(a) 1 and 1 only (b) 2 and 3 only Number of track = 500
(c) 3 and 4 only (d) 1 and 4 only Number of sectors/track = 100
96. In page fault service time is 50 milliseconds and memory Number of bytes/sector = 500
access time is 100 nanoseconds, then what will be the Time taken by the head to move from one track to adjacent
effective access time, if the probability of page fault is p.
track = 1 ms
(a) (500000 + 100p) nanoseconds
Rotation speed = 600 rpm.
(b) (100 + 500000 × p) nanoseconds
What is the average time taken for transferring 250 bytes
(c) 10–7 – 10–7 p (500000) seconds
from the disk?
(d) 10–7 + 49.9 × 103 p seconds
97. Consider a system with 1 K pages and 512 frames and each (a) 300.5 ms (b) 255.5 ms
page is of size 2 KB. How many bits are required to represent (c) 255 ms (d) 300 ms
the virtual address space Memory is 103. In a particular Unix OS, each data block is of size 1024 byes,
(a) 20 bits (b) 21 bits each node has 10 direct data block addresses and three
(c) 11 bits (d) None of these additional addresses: one for single indirect block, one for
98. Consider a system with a two-level paging scheme in which double indirect block and one for triple indirect block. Also,
a regular memory access takes 150 nanoseconds, and each block can contain addresses for 128 blocks. Which one
servicing a page fault takes 8 milliseconds. An average of the following is approximately the maximum size of a file in
instruction takes 100 nanoseconds of CPU time, and two the file system?
memory accesses. The TLB hit ratio is 9% and the page fault (a) 512 MB (b) 2 GB
rate is one in every 10,000 instructions. What is the effective (c) 8 GB (d) 16 GB
average instruction execution time? 104. There are five virtual pages, numbered from 0 to 4.
(a) 645 nanoseconds The page are referenced in the following order
(b) 1050 nanoseconds 012301 401234
(c) 1215 nanoseconds If FIFO page replacement algorithm is used then find
(d) 1230 nanoseconds 1. Number of page replacement faults that occurs if 3 page
99. A computer system supports 32-bit virtual addresses as well frames are present.
as 32-bit physical addresses. Since the virtual address space 2. Number of page faults that occur if 4 page frames are
is of the same size as the physical address space, the present.
operating system designers decide to get rid of the virtual (a) 10, 9 (b) 9, 10
memory entirely. Which one of the following is true? (c) 9, 8 (d) 10, 11
EBD_7203
S3-396 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
105. Determine T(True) F(False) of the following statements: 112. Pre-emptive scheduling is the strategy of temporarily
1. The translation look a side buffer is a software data suspending a running process
structure that support the virtual memory address (a) before the CPU time slice expires
translation operation. (b) to allow starving process to run
2. Demand paging requires the programmer to take specific (c) when it request I/O
action to force the operating system to lead a particular (d) None of these
virtual memory page. 113. In Round-Robin CPU scheduling, as the time quantum is
3. A page frame is portion of the main memory. increased, the average turn around time
(a) (1) – F, (2) – F, (3) – T (a) increases (b) decreases
(b) (1) – F, (2) – T, (3) – F (c) remains constant (d) varies irregularly
(c) (1) – T, (2) – F, (3) – T 114. FIFO scheduling is
(d) (1) – T, (2) – T, (3) – T (a) pre-emptive scheduling
106. Consider the following system state:
(b) Non-pre-emptive scheduling
Process Max Allocated (c) deadline scheduling
P1 7 2 (d) fare-share scheduling
P2 6 2 NUMERICAL TYPE QUESTIONS
P3 7 4 115. Given references to the following pages by a program
Total resources are 11. The system will be in a safe state if 0, 9, 0, 1, 8, 1, 8, 7, 8, 7, 1, 2, 8, 2, 7, 8, 2, 3, 8, 3
(a) process P1 is allocated one additional resource How many page faults will occur if the program has been
(b) process P2 is allocated two additional resources three page frames available to it and uses an optimal
(c) process P3 is allocated three additional resources replacement?
(d) process P2 is allocated one additional resource 116. A demand paging system takes 100 time units to service a
107. An interrupt handler is a page fault and 300 time units to replace a dirty page. Memory
(a) location in memory that keeps track of recently access time is 1 time unit. The probability of a page fault is p.
generated interrupts In case of page fault, the probability of page being dirty is
(b) peripheral device also p, it is observed that the average access time is 3 times
(c) utility program units. Then the value of p is
(d) special numeric code that indicates the priority of a 117. Assume that ‘C; is counting semaphore.
request Consider the following program segment:
108. The time complexity of Banker’s algorithm to avoid deadlock C = 10;
having n processes and m resources is P (C);
(a) O(m × n) (b) O(m + n) V (C);
(c) O (m2 × n) (d) O(n2 × m) P (C);
109. How many process will be created when we run this program? P (C);
main ( ) P (C);
{ printf(“H”); V (C);
fork ( ); P (C);
fork ( ); P (C);
} What is the value of ‘C’ at the end of the above program
(a) 2 (b) 3 execution?
(c) 4 (d) 1
118. Consider the following set of processes with the arrival times
110. What is the output of the following program?
and the CPU-burst times in milli seconds.
main ( )
Process Arrival Burst time
{ int a = 10;
if ((fork ( ) = = 0)) P1 0 5
a++; P2 1 3
print(“%d/n”,a); P3 2 3
} P4 4 1
(a) 10 and 11 (b) 10 What is the average turn-around time for these processes
(c) 11 (d) 11 and 11 with the pre-emptive shortest, remaining time first scheduling
111. Some cmputer system support dual mode operations, the algorithm
user mode and the supervisor mode. 119. Consider the 23 bit logical address specified as
These refer to the modes
Segment Page Words
(a) by which user program handle their data
(b) by which operating system executes its program 5 bits 9 bits 9 bits
(c) in which the processor and the associated hardware The size of the largest segment is
operate 120. Consider an address of 16 bit, with 4 bit as segment number,
(d) of memory access then maximum possible segment size is....
OPERATING SYSTEM S3-397
121. Assume a machine with 64 MB physical memory and 32 bits 128. How many bits in the virtual address specify the entire virtual
virtual address space. If the page size is 4 KB, what is the address?
approximate size of the page table? (a) 8 bits (b) 16 bits
122. Consider a system with 80% hit ratio, 50 ns time search the
(c) 32 bits (d) 64 bits
associative registers, 750 ns to access memory. Find the
Common data of Question 129 and 130:
effective access time.
123. In a simple paging system with 224 bytes of physical memory, A system uses a two level page table has 212 bytes pages and 32-
256 pages of logical address space, and a page size of 210 bit virtual addresses. The first 8-bit of the address serve as a index
bytes, how many bits are in logical address. into the first level page table.
124. On a system using segmentation, following is the segment 129. How many bits specify the second-level table?
table (a) 8 bits (b) 10 bits
(c) 12 bits (d) 16 bits
Segment Base Length 130. How many entries in a level-one page table?
0 330 124 (a) 24 (b) 28
(c) 216 (d) 232
1 876 211
Linked Answer Type Q. 131 and Q. 132
2 111 99 131. A system contains 16 MB of primary memory and fixed
3 498 302 partitions, all of the size 65536 bytes. What is the minimum
number of bits needed in an entry in the process table to
Complete the physical address for the logical address 3,222 record all of the partitions.
(a) 8 bits (b) 16 bits
COMMON DATA LINKED ANSWER TYPE QUESTIONS
(c) 32 bits (d) 64 bits
Common data for Q. 125 and 126. 132. What is the size of limit register?
The following shows the details of four processes under
(a) 8 bits (b) 16 bits
preemptive priority scheduling algorithm. A large priority number
(c) 32 bits (d) 64 bits
indicates higher priority.
Linked Answer Type Q. 133 and Q.134
Consider a paging system with 16 MB of physical memory, 256
Process Arrival time Burst time Priority
pages of logical address space and a page size of 1 KB.
A 0.0000 4 3 133. How many bits are in logical address space
B 1.0001 3 (a) 8 bits (b) 16 bits
4
(c) 18 bits (d) 16 bits
C 2.0001 3 6 134. A page frame needed how many memory space?
D 3.0001 5 5 (a) 1 KB (b) 2 KB
(c) 16 KB (d) 3 KB
125. What is turn around time (rounding to the nearest hundredth) Common data of Question 135 to 137
for process ‘B’?
Consider a virtual memory of 256 terabytes. The page size is 4K.
(a) 7 (b) 11
This logical space is mapped into a physical memory of 256
(c) 15 (d) None of these
megabytes.
126. What is the average turn around time (rounding to the nearest
hundredth). 135. How many bits are there in the virtual memory?
(a) 9 (b) 9.50 (a) 28 (b) 48
(c) 10.5 (d) None of these (c) 38 (d) 58
Common data of Question 127 and 128: 136. How many pages are there in the virtual memory?
Consider a system using paging and segmentation. The virtual (a) 64 gigapages (b) 32 terapages
address space consist of up to 8 segments and each segment into
(c) 64 megapages (d) 256 kilopages
28 byte pages.
127. How many bits in the virtual address specify the offset with 137. Given the address: ) 0 × 034F48AC5345 what is the page
in page? offset (in decimal)?
(a) 8 bits (b) 16 bits (a) 837 (b) 709
(c) 32 bits (d) 64 bits (c) 345 (d) 563
EBD_7203
S3-398 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
PAST GATE QUESTIONS EXERCISE 6. (b) Context switches are required only at the time during
the switching over to some other process. Let the three
1. (b) Let three processes be p0, p1 and p2. Their execution given processes be P1, P2 and P3.
time is 10, 20 and 30 respectively. p0 spends first 2 time
Process Arrival time Burst time
units in I/O, 7 units of CPU time and finally 1 unit in I/ P1 0 10
O. p1 spends first 4 units in I/O, 14 units of CPU time P2 2 20
and finally 2 units in I/O. p2 spends first 6 units in I/O, P3 6 30
21 units of CPU time and finally 3 units in I/O. The gantt chart for SRTF scheduling algorithm is
idle p0 p1 p2 idle
P1 P2 P3
0 2 9 23 44 47
0 10 30 60
Total time spent = 47 So, there are only two context switches required, i.e., at
Idle time = 2 + 3 = 5 the time unit 10 context switch from P1 to P2 and at the
Percentage of idle time = (5/47) × 100 = 10.6 % time unit 30 context switch from P2 to P3.
2. (a) Gantt chart for LRTF CPU scheduling algorithm is 7. The correct matching is shown
P0 P1 P 2 P2 P2 P2 P 2 P1 P2 P 1 P2 P0 P1 P2 Group 1 Group 2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
P. Gang Scheduling 1. Thread Scheduling
Turn around time P0 = 12 – 0 = 12
Rate Monotonic
P1 = 13 – 0 = 13 Q. 2. Real-time Scheduling
Scheduling
P2 = 14 – 0 = 14
Fair Share Guaranteed
12 + 13 + 4 R. 3.
Average = = 13. Scheduling Scheduling
3
8. (d) Blocking one kernel level threads does not block all
3. (c) When the system has same number of bits supporting
related threads. In kernel level threads, in blocking
virtual addresses and physical addresses, i.e., 32 bit, system call, it can happen with the kernel that another
then the conversion from virtual to physical that is thread is scheduled while kernel is executing.
done by MMU (Memory Management Unit) is not 9. (b) Gantt chart for SRTF is
required in such cases. Thus, no hardware support is
P1 P2 P3 P4 P5
required.
4. (a) We know that 4 kbyte page size requires 12 bit as 4 0 20 30 40 55 70
Waiting time for process P2 is given as
kbyte = 4 × 210 = 212 byte so 12 bit
(20 – 15) + (40 – 50), i.e., 15
number of pages = 128 = 27 so 7 bit required for page 10. (b) As we know that in case of Belady’s anomaly, the
table entry. increase in number of pages results in increase of page
The memory cell out of 4-way associative memory fault rate so both P and Q are true but Q is not the
requires 2 bit and 4 kbyte page required 12 bit. reason for P.
Therefore, total bits required = 7 + 12 + 2 = 21 bit. 11. (c) From the given matrix we found that the number of
available resources of X, Y and Z types are 0, 1, 2
TLB minimum size = 32 – 21 = 11 bit.
respectively. Therefore, P1 will avail these resources
5. (a) The P and V functions are given from that we determine first and after release the resources available will be (2,
that fetch and set instructions always set the memory 1, 3) which will be used by P0 as its request is of 1, 0, 3
location x to 1 and fetch the old value of x into y. S resources. After P 0 releases the resources, the
takes only 2 values either 0 or 1 when S is initialized to availability becomes (3, 3, 4) and P2 will use these
0, statement 3 will start at location x with this value and resources then as per its requirements. Thus, P2
fetch-set instruction change the value of x from 0 to 1 finishes in the last.
12. (d) Wants2 enters the critical section, if process P1’s
and y becomes 0. If more than 2 processes were there
variable wants1 is true and if wants2 is true then wants1
and context switching was disabled in P then this won’t enters critical section. In both cases, there will be
work properly. deadlock but no mutual exclusion.
OPERATING SYSTEM S3-399
13. (a) Optimal page replacement policy replaces the page 2) The server acknowledges this request by sending
which will not be used for longest time SYN-ACK back to the client.
Page frames 3) The client responds with an ACK, and the
connection is established.
3 3 3 3 3 3 3 20. (a) In Belady’s anomaly, if number of frames are increased
then number of page faults increases.
2 2 2 7 4 5 6 6 6 This behaviour found only with FIFO.
The First In, First Out (FIFO) page replacement
1 1 1 1 1 1 1 1 1 1 algorithm is a low-overhead algorithm. In FIFO, the
1 2 1 3 7 4 5 6 3 1 operating system keeps track of all the pages in memory
in a queue. The queue is managed in a way that the
Page most recent arrival is placed at the back, and the earliest
F F F F F F F
faults arrival in front. T the time of page replacement, oldest
page is selected to get replaced.
Total number of page fault = 7 Practical implementation of FIFO is not very good as
14. (c) LRU replaces the page which is used least recently. the algorithm experiences Belady’s anomaly.
Page frames In FIFO when the number of frames increases then, the
number of page faults also increases and this behaviour
3 3 3 5 5 5 1 is found by Belady’s anomaly. Thus, FIFO have this
Belady’s anomaly, e.g., in FIFO for three frames the
2 2 2 7 7 7 6 6 6
reference string
1 1 1 1 1 4 4 4 3 3 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
There are 9 page faults and for four frames for the
1 2 1 3 7 4 5 6 3 1 reference string there will be 10 faults.
F F F F F F F F F
21. (b) A page table is the data structure used to store the
Total number of page faults = 9 mapping between virtual addresses and physical
Therefore, an increase of 2 is there (9 – 7) in LRU than addresses. A page table is used by a virtual memory
in optimal. system in a computer operating system. Virtual
15. (a) Deadlock prevention does not guarantee the state that addresses are the addresses which are unique to the
the state would be safe when the request for resources accessing process while physical addresses are the
is granted instead it is guaranteed by deadlock addresses that are unique to the CPU, i.e., RAM. Page
avoidance and there will be no deadlock at that time. frame number is essential content in each of the page
16. (b) We know that the total number of processes is 2n but table. Virtual page number may not be store entirely in
we subtract the main process therefore, total number the page table and thus, cannot be considered as the
of children = 2 (n – 1). essential content.
17. (b) From the given conditions, it is concluded that the
equivalent number of bits are required for the three 22. (a) R2 - 2 R3 - 2 R4 - 1
levels of page, i.e., 24. t=0
un its u nits un its
Therefore,
R2 - 2 R3 - 3 R4 - 2 R1 - 1
Number of bits required for first lent = 24 t=2
Number of bits required for second lent = 24 un its u nits un its u nit
Number of bits required for third lent = 24 R2 - 2 R3 - 3 R4 - 2 R1 - 4
t=3
18. (b) As we know that the use of multilevel page table un its u nits un its units
reduces the size of the page table needed to implement R2 - 2 R3 - 3 R4 - 2 R1 - 5
t=4
the virtual address space of a process. un its u nits un its units
19. (d) socket() creates a new socket of a certain socket type, R2 - 1 R3 - 3 R4 - 2 R1 - 2
t=5
identified by an integer number, and allocates system un its u nits un its u nits
resources to it. R2 - 1 R3 - 2 R4 - 2 R1 - 2
bind() is typically used on the server side, and t=6
un its u nits un its u nits
associates a socket with a socket address structure, R2 - 2 R3 - 1 R4 - 2 R1 - 2
i.e. a specified local port number and IP address. t=7
un its u nits un its u nits
listen() is used on the server side, and causes a bound
TCP socket to enter listening state. R2 - 2 R3 - 1 R4 - 3 R1 - 1
t=8
connect() is used on the client side, and assigns a free un its u nits units u nit
local port number to a socket. In case of a TCP socket, t=9
it causes an attempt to establish a new TCP connection.
When connect() is called by client, following three way The Bolded line show that at that time the requirement
handshake happens to establish the connection in TCP. of resource is less than avaiability but it does not cause
1) The client requests a connection by sending a SYN dead lock.
(synchronize) message to the server. All process finish without any dead lock
EBD_7203
S3-400 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
23. (b) Requests 4 34 10 7 Total
19 73 2 15 6 20 100 (Direct access) + 96 (Reverse access) = 196
Current 50 34 20 19 Alternate method
15 10 7 6 4 2 Fault of n pages = 2n – 4
Next access 34 20 19 15 So, for 100 pages = 2 × 100 – 4 = 196
10 7 6 4 2 73 31. (d)
Difference 16 14 1 4 32. (a) P0 uses a semaphore. Hence, anything whose value is
5 3 1 2 2 71 1, P0 will print ‘0’.
Therefore, total moves After the release of S1 and S2, we observe that either
= 16 + 14 + 1 + 4 + 5 + 3 + 1 + 2 + 2 + 71 = 119 ms P1 or P2 will release S0 so that it print ‘0’ at least 2
24. (c) I is false. If a process makes a transition D, it would times.
result in another process making transition B, not A. Therefore, it is concluded that neither P1 nor P2 will
II is true. A process can move to ready state when I/O go, it is the P0 that prints ‘0’ 2 times atleast.
completes irrespective of other process being in 33. (b)
running state or not. 34. (a) Threads are called 'light weight process' because they
III is true because there is a transition from running to only need storage for stack and registers. They don't
ready state. need separate space for other things like code segment,
IV is false as the OS uses preemptive scheduling global data, etc
25. (a) The given program initializes the memory location X to 35. (c) t1 < t2
0 in the test and set instruction and in the function Process switching involves mode switch. Context
leave_CS(). switching can occur only in kernel mode.
\ Above solution is deadlock free. 36. (d) We know that mouse pointer movements are more
26. (d) Indexed allocation is used for the efficient direct access frequent than keyboard ticks. So its obvious that its
good use of disk space. However, it cannot allocate data transfer rate is higher than keyboard. Delaying a
CPU temperature sensor could have serious
very large files. Thus, the data blocks of very large file
consequences, overheat can damage CPU circuitry.
in unix system are allocated using an extension of
From the above information we can conclude that
indexed allocation or EXT2 file system.
priorities are : CPU temperature sensor > Hard Disk >
27. (c) From the given code we get that P(S) and V(S),
Mouse > Keyboard
decrement and increment the value of semaphore
37. (b) 6000 rotations ............. 60 sec
respectively. So, from the given conditions we conclude
1 rotation ............. 10 ms
that to avoid mutual exclusion in the value of Xb should \ Rotational latency = 5 ms
be 1 and that of Yb should be 0. Time for one disk access = 15 ms
28. (b) This is so because we know that an Interrupt Service Time to load all libraries = 15 ´ 100 = 1500 ms = 1.5 s
Routine (ISR) is invoked before the completion of IN/ 38. (a) Process P0 is allocated processor at 0 ms as there is no
OUT irrespective of its type whether asynchronous or other process in ready queue. P0 is preempted after 1
synchronous. ms as P1 arrives at 1 ms and burst time for P1 is less
29. (a) As per the methods provided in process 1 and process than remaining time of P0. P1 runs for 4ms. P2 arrived at
2, th e process 1 and process 2 can not exist 2 ms but P1 continued as burst time of P2 is longer than
simultaneously in the critical section. So, when the P1. After P1 completes, P0 is scheduled again as the
process 1 is in the critical section, process 2 is not and remaining time for P0 is less than the burst time of P2.
thus, the condition of mutual exclusion is satisfied but P0 waits for 4 ms, P1 waits for 0 ms amd P2 waits for 11
not progress. ms. So average waiting time is (0+4+11)/3 = 5.
30. (a) The First In First Out (FIFO) page replacement 39. (c) A process executes the code and works as follows:
algorithm is a low-overhead algorithm. In FIFO, the The number of child processes created = 2n – 1
operating system keeps track of all the pages in memory = 23 – 1 = 8 – 1 = 7
in a queue. The queue is managed in a way that the where, n = 3 Q 3 fork () are executing.
most recent arrival is placed at the back, and the earliest 40. (b) Reference string:
arrival in front. T the time of page replacement, oldest 1, 2, 3, 2, 4, 1, 3, 2, 4, 1
page is selected to get replaced. Practical 3 page frames.
implementation of FIFO is not very good as the FIFO
algorithm experiences Belady’s anomaly.
Given are 4 page frames. 1 2 3 2 4 1 3 2 4 1
The 100 pages are accessed in some order ® 1 to 100 1 1 1 1 4 4 4 4 4 4
pages will get 100 faults. Input 2 2 2 2 1 1 1 1 1
Now, after the pages are accessed, they are to be
accessed in reverse order. But in reverse, there won’t 3 3 3 3 3 2 2 2
be any fault for page numbers 100, 99, 98, 97. Page P P P X P P X P X X
Therefore, all page frames are occupied. Now, for faults
remaining 96 accesses, 96 faults would occur. There are 6 page faults.
OPERATING SYSTEM S3-401
Optimal Order P1 ® P2 ® P3
Round robin Here, not P2 because in the ready queue
1 2 3 2 4 1 3 2 4 1
P2 comes later than P3.
1 1 1 1 1 1 1 1 1 1
Input 2 2 2 4 4 4 4 4 4 P1 P2 P1 P3 P2 P1 P3 P2 P2
3 3 3 3 3 2 2 2 0 2 4 6 8 10 11 13 15 16
Page P P P X P X X P X X
faults Here, not P3 because in the ready queue P1 comes first
There are 5 page faults. than P3.
LRU Order P1 ® P3 ® P2
Cache size
1 2 3 2 4 1 3 2 4 1 44. (c) Number of blocks in the cache (c) =
Block size
1 1 1 1 4 4 4 2 2 2 256 13
Input 2 2 2 2 2 3 3 3 1 = =2
32
3 3 3 1 1 1 4 4 Number of blocks in main memory
Page P P P X P P P P P P
Main memory size 232 B
faults ( m) = = = 227
There are 9 page faults. Block size 32B
Hence, OPTIMAL < FIFO < LRU Number of blocks in each set (S) = 4
41. (b) Total number of possible addresses stored in a disk
Number of tag bits = log m – log c + log S
block = 128/8 = 16
= 27 – 13 + 4 = 16 bit
Maximum number of addressable bytes due to direct
45. (b) Number of tag bits = 16
address block = 8 × 128
Number of valid bits = 2
Maximum number of addressable bytes due to 1 single
indirect address block = 16 × 128 Number of modified bits = 1
Maximum number of addressable bytes due to 1 double Number of replacement bits = 1
indirect address block = 16 × 16 × 128 Total bits in each entry = 16 + 2 + 1 + 1 = 20 bit
The maximum possible file size Each entry is attached to each cache block
= 8 × 128 + 16 × 128 + 16 × 16 × 128 = 35 Kbyte Number of cache blocks are = 213
42. (b) Take closer look the below while loop. Tag directory size = Number of cache blocks
while (Fetch_And_Add(L,1)) × Each entry size
L = 1; // A waiting process can be here just after = 213 × 20 bit = 20 × 160 bit = 160 kbit
// the lock is released, and can make L = 1. 46. (b) Process scheduling is independent of the time it
Consider a situation where a process has just released the lock takes for a process to execute. Thus, shortest-job-
and made L = 0. Let there be one more process waiting for the lock, first algorithm and shortest remaining-time-first
means executing the AcquireLock() function. Just after the L was algorithm can be discarded
made 0, let the waiting processes executed the line L = 1. Now, the (i.e., option c and d)
lock is available and L = 1. Since L is 1, the waiting process (and Initially as all the processes arrive simultaneously
any other future coming processes) can not come out of the while the waiting time for each process = 0
loop. Any of the processes can be scheduled first say P1.
The above problem can be resolved by changing the AcuireLock() Since, the scheduler re-evaluates the process priorities
to following. every T time units.
AcquireLock(L){ After T units of time,
while (Fetch_And_Add(L,1)) Waiting time of P1 = 0 and waiting time of all the
{ // Do Nothing }
others = T.
}
Thus, in priority all other processes supercede P1
43. (c) Arrival Time units and hence other processes get scheduled thereafter.
Process Once, every process gets scheduled one time each
time required
P1 0 5 for T time units all the processes will have same
waiting time i.e., (n – 1)T, where n is the process
P2 1 7
number.
P3 3 4 On the basis of analysis this is Round Robin with
FCFS: preemptions at periods of T.
Option (a) is incorrect because scheduling is
P1 P2 P3
independent of the arrival time of the processor.
0 5 12 16
EBD_7203
S3-402 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
47. (b) Three concurrent processes X, Y and Z execute three
different code segments that access and update X Y Z
certain shared variables. P(a) P(c) . P( c) .
Processes P(b) P(b) P(d )
P(c) . P(d) P(a )
X Y Z
The sequence of variable P(c) and P(a) are
P(a) P(b) P(c) . opposite in Z and X. So, deadlock may occur (Not
P(b) P(c) . P(d) Acceptable)
P(c) . P(d) P(a) Hence, the answer is (b).
48. (d) Each of the processes W and X reads x from memory
(a) X : P(a) P(b) P(c) and .increment x by .1.
Y : P(b) P(c) P(d) Each of the processes Y and Z reads x from memory,
Z : P(c) P(d) P(a) and decrement by 2.
Suppose X first executes P(a) and P(b) and then 1. Start with X and perform P(S) then S = 1 read
switches to process Z, where P(c) and P(d) are x=0x=x+1=1
executed and wait for P(a), Then again process 2. Then Y will perform P(S) then S = 0 read X = 0
switches to X and then wait for P(c). x = x–2 = –2 then store x. V(S),S = 1
\ Process X is waiting for C which is occupied 3. Then Z will perform P(S) then S = 0, read x = – 2 x
= x – 2 = – 4 then store x, V(S).S = 1.
by Z and Z is waiting for a which is occupied by
4. Then x will store x.V(S), S =2, X = 1
process X.
5. Then W will perform P(S),S =1, read x = 1
So, neither can execute and deadlock occurs.
x = x + 1 = 2, store x, V(S),S = 2, x = 2
(Not Acceptable) Hence, answer is option (d)
(b) X : P(b) P(a) P(c) 49. (c) Option (a) Suppose process X executes Exit X then
Y : P(b) P(c) P(d) it will wait for R, and then process Y executes Entry
Z : P(a) P(c) P(d) Y then it will wait for S. Since, initially both binary
semaphores are 0, no one will increment it and both
X Y Z process will be stuck up in a deadlock.
P(b) P(b) P(a) \ Option (a) is incorrect.
P(a) P(c) . P(c) . Option (b) Here if process X executes for n times
repeatedly it will set both semaphores to 1 (since
P(c) . P(d) P(d) only two values are possible) and after that process
Execution can be carried out in a proper way Y executes. First time it passes the Entry Y and make
without deadlock occurance and no wait for any both semaphores to 0.
And on second time it finds both semaphores to 0 and
variable in the processer. (Acceptable)
cannot pass the Entry Y barrier. Hence it will get stuck.
(c) X : P(b) P(a) P(c)
So, option (b) is wrong.
Y : P(c) P(b) P(d) Option (c) Considering any sequence of operation of
Z : P(a) P(c) P(d) process X and process Y, first process X will wait for
S which is increment by process Y and then process
X Y Z Y waits for R which is incremented by process X.
P(b) P(c) . P(a ) There is no sequence of operation in which the value
P(a) P(b) P( c) . of R or S overlaps.
P(c) . P(d) P(d ) \ Both processes execute one after another.
So, option (c) is correct.
The sequence of variable P(b) and P(c) are Option (d) Suppose first process X executes it sets
reverse and opposite [i.e., P(b) P(c) P(a) and P(a) R = 1 and then waits for S. Now after that process
P(b) P(c)] Y executes. It first sets S = 1 and decrement R = 0.
So, deadlock may occurs in X and Y respectively It comes again and then again sets S = 1 (i.e., it
overlaps the value of S) and then again wait for R.
(Not Acceptable)
Clearly hence one iteration of process X is lost due
(d) X : P(a) P(b) P(c)
to overlapping of value of S, and after n – 1 iteration
Y : P(c) P(b) P(d) process X will be stuck.
Z : P(c) P(d) P(a) So option (d) is wrong.
OPERATING SYSTEM S3-403
50. No. of Requests = 3 The first column of the table indicates the running time.
Remember that in SSTF algo the request with shortest Each entry in the table indicates the remaining execution
seek fine from “current Head Position” is serviced first.
We prepare the following table: time of that process at that time. Here a ‘–’ indicates that a
process has not arrived and a ‘zero’ indicates that the
Current Nearest Nearest Request with process has finished.
Head Left Right Shortest seek time
Position Request Request (& Hence serviced) The last column indicates the process selected for execution
100 100 100 100 that has shortest remaining execution time; these are marked
Initially with red circles.
100 90 105 105
Using the Gantt chart, the arrival time, termination time and
105 90 110 110
turnaroud time of different processes is as follows:
110 90 135 90
Process Arrival Termination Turnaround
Initially Head is of 100, so it services Request for 100 Time Time Time (m sec)
itself. Then 105 is serviced because it is nearest to 100. A 0 8 8
Now as head is at 105, Request for ‘110’ is serviced as it
is nearer than 90. Finally as head is on 110, out of two B 3 5 2
nearest requests viz. 90 & 135, ‘90’ is serviced since it is C 5 12 7
nearer than “135”. 80, ‘90’ is serviced after servicing 3 D 7 21 14
Requests. E 10 15 5
51. (d) (a) is correct as user Perel threads are managed
Total turnaround item of all processes = 36 m sec.
without kernel support.
36
(b) In many one model, it one thread makes a Average turnaround time = = 7.2 m sec.
blocking system call, the entire process is 5
blocked so all its threads are also blocked. 54. 7 page faults
(c) User Level threads are faster to (reate & manage Explanation: The given reference string is:
than kernel threads as no intervention from 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6.
kernel is required, so the context switch in them
is also faster. Available no. of frames = 3.
(d) As all threads share code & data including We know that in the optimal replacement policy, when a
kernel level threads, so this option is ‘FALSE’. page fault occurs, the required page is loaded from secondary
52. (b) Only REQ2 can be permitted. memory and “that page in main memory will be replaced
53. 7.2 milli seconds
As we know, in the shortest remaining time first algorithm, which will not be used for the longest period of time”. Use
at a given time t, process p is scheduled if its remaining of this algorithm guarantees the lowest possible page fault
execution time is minimum among all processes. (Note that rate for a fixed number of frames. Furthermore, this algorithm
this algo is applicable only when all processes declare their also does not suffer with Belady’s Anomaly.
execution time in advance before they begin).
Required page
Now the Gantt chart for the given processes is as follows:
Frames
0 3 5 7 8 10 12 15 21
Page fault (Y/N)
A B A A C C E D
43. (b) From the given RAG we can observe that process P1 Hence, option (d) is correct.
holding resource R1 and requesting for resource R2.
50. (c) Page frames
Process P2 is requesting for resource R1 and Resource
R2. 2121
4554
hence at the given time both the instances of resource
R2 are available. 3332
44. (b) Virtual address space = 232 Bytes
Page sequence
Physical address spaces = 230 Bytes
2, 4, 3, 1, 5, 3, 2, 5, 3, 1, 4, 2
Page size = 4 KB = 212 Bytes
Page faults
30 2, 4, 3, 1, 5, 2,1, 4, 2
2 18
No. of frames in physical memory = 12 = 2 Page hit
2
3, 5, 3
No. of Bits in each page table entry
\ No. of page faults = 9
Page Number Overhead (Offset) 51. (b) Page hit ratio = 1
Ma = 20 ns.
20 bits 12 bits
Since page hit ratio = 1
Page table size = No. of frames × (20+ 12) bits
\ Memory access time for one page = 20 ns.
= 218 × 32 bis = 218 × 32/8 bytes » 218 × 22 bytes Hence, option (b) is correct.
» 220 bytes 52. (d)
EBD_7203
S3-408 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
53. (a) The arrival pattern is a Poission distribution. 62. (d) Considering that a process spends a fraction p of its
time in I/O wait state. As n processes are there is
T
P(k requests) = e -m ( mT ) k / K! memory at once, then
Probability that all n processes are waiting for I/O =
Here k = 0, m = 20, T = 3/4 p*p*p*...p (n times) = pn
So required probability is e–15 Note:Moreover, the CPU utilization is given by the
54. (d) Context switching takes place when a process is formula CPU utilization = 1 – pn.
preempted (forcefully) and another process goes into 63. (c) 1, 2, 4, 5, 2, 1, 2, 4
the running state. In FIFO and SJF (non-preemptive)
Since 1 and 2 are already in the memory which can
techniques, the processes finishes their execution then
accommodate 3 pages
only their context is switched to other processes.
55. (d) In case of dynamic loading, memory management unit 154
converts logical address to physical address at the 222
time of execution. No. of page faults = 4
41
In doing their user programs do not need any support
from the O.S. or the hardware. Hence option (c) is correct
56. (d) In Acyclic Graph directory file can be accessed using 64. (d) Working set at time 't' represents the pages which are
different paths from the same root directory, this can referenced by an application when the application is in
be done with the helps of soft links. a particular state at time 't'. the set of k refrences with
57. (c) The automatic call library contains object modules to high frequency
be used as secondary input to the linkage editor to 65. (b) If the property of locality of reference is well
resolve external symbols left undefined. pronounced then the page to be accessed will be
58. (c) By using the overlays we can execute much greater founding the memory more likely and hence page faults
processes simultaneously which cannot be execute and will be less. Also since access time will be only of the
reside in the memory at the same time. In this the upper level in the memory hierarchy hence execution
will be faster.
process to be executed process brought to memory
only when it is needed at the time of execution. Hence option (b) is correct.
59. (a) 2 process can never lead to deadlock as the peak time 66. (d) The disk drive has to traverse totally 146 cylinders
demand of 6(3 + 3) tape drives can be satisfied. But 3 (verify). So, seek time is 6 × 146 = 876 ms.
processes can lead to a deadlock if each hold 2 drives 67. (c)
and then demand one more. 68. (a) Consider the peak demand situation of resources
60. (c) Each P operation will decrease the semaphore value by (A,B,C)=(3,4,6).
1 and V operation increases it by 1. If x is 18, then 7 P An allocation that cannot completely satisfy the
operations will make semaphore value 0. If this is resouce requirements of even one process .
followed by 7 V operations the value comes back to 7. With number of shared resources m = 7, the following
So, after 18 P and 18 V operations, the value of the resource allocation (for example)among 3 process A,B,C
semaphore will be 7. The remaining 2 P operations result (2,3,2).Process A holding 2 resources and waiting for
in the semaphore value 5. 1, Process B holding 3 resource and waiting for 1 and
61. (c) Hit ratio = 0.35 process C holding 2 resources and waiting for 4 more
resources. This is a deadlock situation.
Time (secondary memory) = 100 ns
With number of shared resources m = 9, the following
T (main memory) = 10 ns resource allocation (for example)among 3 process A,B,C
Average access time = h(T) + (1 – h) (2,3,4).Process A holding 2 resources and waiting for
= 0.35 × 100 + (0.65) × 100 1, Process B holding 3 resource and waiting for 1 and
process C holding 4 resources and waiting for 2 more
= 3.5 + 65 = 68.5 ns
resources. This is a deadlock situation.
OPERATING SYSTEM S3-409
With number of shared resources m = 10, the following critical section as it uses V (mutex) instead of P (mutex)
resource allocation (for example)among 3 process A,B,C to get into the critical section. As a result of this, mutex
(2,3,5).Process A holding 2 resources and waiting for will be incremented by 1. Now any one of the 9
1, Process B holding 3 resource and waiting for 1 and processes Pi, i =1, 2, 3, .... 9 (excepting the one that is
process C holding 5 resources and waiting for 1 more already inside the critical section) can get into the
resource. This is a deadlock situation. critical section after decrementing the mutext to 0. None
But for m >=11 , the resource allocation is deadlock of the remaining processes can get into the critical
free. section. If the mutex is initialized to 0, only 2 processes
69. (a) At least one process will be holding 2 resources in can get into the critical section. So the largest number
case of a simultaneous demand from all the processes. of processes is 3.
That process will release the 2 resources, thereby 77. (b) A fork () call creates the child processes for the
avoiding any possible deadlock. following loop creates 2n – 1 child processes, excluding
the parent process. And including parent it is 2n.
70. (c) The first 3 reference A, B, C fills the internal storage
with A, B, C in 3 page transfers. Now the next reference 78. (a) Kernel level threading may be preferable to user level
D results in a page fault. So page A is downloaded and threading because storing information about user level
thread in a PCB would create a security risk i.e. with
D takes its place after a page transfer. So, the internal
each access to the non-critical services. We are going
store has D, E and C. The next reference is A - results in
to the domain where both critical and non-critical
a page fault. So, a page transfer takes place and swaps
services are residing. Any harm in this domain may
B and A. Continuing this way, we find totally 9 page
creates problems to the critical services. Hence Kernel
transfers are necessary. level threading is preferable.
71. (b) The disk drive has to traverse totally 146 cylinders 79. (a) Only critical services must resides in the kernel. All
(verify). So, seek time is 6 ´ 146 = 876 ms. services mentioned except reading status of processors
72. (a) To cover 2400 × 62500 bits, 60s are needed. Average and reading time of the day are critical.
latency time is the time needed to traverse 100 tracks hence option (a) is correct.
i.e. 100 × 62500 bits, which is 2.5 s. 80. (c) The mutex ensures we lock the queue, the f semaphore
73. (b) The system is not in deadlock state, if the following ensures that we do not dequeue the queue before it
sequence of fulfillment of request of the processes is made. has an element.
81. (d) The given code creates 2n – 1 child process here n = 5.
P2 ® P0 ® P1 ® P3
Together with parent process the total makes up to 32.
74. (b) Since the page is used heavily then it can not be 82. (d) All writers, once added to the queue, shall be kept
removed if LFU used, since it is in constant used, hence waiting longer than absolutely necessary in this
it can’t be removed if LRU is used. Using FIFO only it situation as given . All readers shall be kept waiting if
can be removed effectively. the share is currently opened for reading.
75. (c) When it tries to access 0100, it results in a page fault as 83. (d) Since kernel level threads are managed by kernel,
the memory is empty right now. So, it loads the second blocking one thread doesn't cause all related threads
page (which has the addresses 100 – 199). Trying to to block. It's a problem with user level threads
access 200 will result in a page fault, as it is not in 84. (b) I/O is many orders of magnitude slower than cpu.
memory right now. So the third page with the addresses therefore favouring I/O bound process won't actually
from 200 to 299 will replace the second page in memory. give them more execution time than a cpu bound
Trying to access 430 will result in another page fault. process, because they're just going to block again on
Proceeding this way, we find trying to access the the next i/o transaction. favouring them gives them a
chance to operate when the i/o requests appear (system
addresses 0510, 0120, 0220 and 0320 will all result in
is more responsive, and I/O utilisation is higher as
page faults. So, altogether 7 page faults.
requests are re-issued faster); it also decreases the
76. (c) Let the mutex be initialized to 1. Any one of the 9 probability of packet loss, as the i/o buffers are given
processes Pi, i = 1, 2, 3, .......9 can get into the critical more chances to be read.
section after executing P (mutex) which decrements the Hence it is generally it generally correct to favour I/O
mutex value to 0. At this time P10 can enter into the bound processes over CPU-bound processes
EBD_7203
S3-410 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
85. (c) For non preemptive SJF scheduling
A A A A A A A A C C C C C C D B B B B
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
But the no. of child processes = 22 – 1 = 3 here the access time C = (1 – p) ´ 100 time units
finaly average access time
110. (a) Parent process prints 10 and child process prints 1.
= (1 – p) ´ A + p ´ (B + C)
111. (c) CPU modes (also called processor modes,CPU
states,CPU privilege levels and other names) are so, (1 – p) ´ 1 + p ´ [(1 – p) ´ 100 + p ´ 300] = 3
operating modes for the central processing unit of some by evaluating p = 0.514
OPERATING SYSTEM S3-413
117. No. of P(C) wait process = 6 i.e. decrement 123. Physical memory size = 224 bytes
No. of V(C) signal process = 2 i.e. increment space size = 210 bytes
Therefore value of ‘C’ at the end of program execution Logical address space = 256 pages = 256 × 210 = 218
= Initial value – No. of P(C) + No. of V(C) no. of bits required = 18 bits
= 10 – 6 + 2 = 6
124. The physical address for the logical address 3, 222
118. Process will be executed as
represents that 222th location byte of segment 3
12 + 3 + 6 + 1 A 0.0000 4 3
Average turn around time = = 5.5
2 B 1.0001 3 4
C 2.0001 3 6
119.
Segment Page Words D 3.0001 5 5
5 bits 9 bits 9 bits 125. (b)
23 bits, the remaining bits = 23 – 5 = 18 bits. 0 1.0001 2.0001 3.0001 4.00015.0001 6.0001 7.0001 8.0001 9.000110.000111.0001 12.000113.000114.000115.0001
The size of largest segment is hence = 2 18 words which Turn around time for process ‘B’ = Completion time – Arrival time
equal to 256 K words. = 12.0001 – 1.001 = 11
120. Since four bits are used as segment number out of 16 Hence (b) is the correct option.
bits, a maximum of 12 bits can participate in the segment 126. (a) Average turn around time
size, which is equal to 212 = 4096.
121. Size of main memory = 64 MB å Turnaround time for each process
=
Number of processes
Size of virtual memory = 232 B
232 15 + 11 + 3 + 7 36
No. of pages = = 220 pages = = =9
212 4 4
But each entry has both a virtual address & 127. (a) Virtual address space = 8 × 229 bytes
corresponding physical address. Total bits in each entry = 232 bytes
= 32 + 26 (Physical) = 58 = 58/8 = 8Bytes. So total Size of segment
memory = 8 ´ 1 MB = 8 MB No. of pages with each segment =
Size of page
122. Hit ratio, h = 80% = 0.8
2 29
Ta = 50 ns, Tm = 750 ms = Bytes = 2 21 Bytes
8
2
Effective access time
Offset within the page = 8 (for 28 bytes)
= (Ta + ma) × h + (1 – h) (Ta + 2 ma)
128. (c) Size of main memory = 64 MB
Effective access time = (Ta + ma) × h + (1 – h)(Ta + 2ma)
Size of virtual memory = 232 B
= 0.8 × (50 + 750) + 0.2 × (50 + 1500)
each entry has both a virtual address & corresponding
= 0.8 × 800 + 0.2 × 1550 = 640 + 310 = 950 ns
EBD_7203
S3-414 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
physical address. Total bits in each entry=32 + 26 bits 133. (c) Physical memory size = 16 MB = 224 Bytes
where 32 represents the bits in the entire virtual address. Page size = 1 KB = 210 Bytes
Virtual address space = 256 Pages = 256 × 1 KB
232 B
129. (c) No. of pages = = 220
212 B = 218 Bytes
No. of bits to identify each address in logical address
Now since first 8 bits of the address serve as a index into the
space of 218 Bytes = 18 bits.
first level page table
134. (a) No. of bits to identify each frame in physical memory
are equal to the no. of bits to identify each page in
8 bits 12 bits
logical memory, because size is equal to frame size.
Page Number Next Level 135. (b) Virtual address space = 256 terabytes
Indexing
= 256 × 240 bytes
20 bits = 248 bytes
(1 terabyte = 240 bytes)
No. of bits specify the second level index = 12 bits.
\ No of bits represent the virtual memory = 48 bits.
130. (b) No. of entries in level-one page table Hence (b) is the correct option.
= No. of addresses specified by index bits 136. (a) Page size = 4 K = 212 Bytes
= 28 entries.
2 48 B
131. (a) Primary memory size = 16 MB = 224 Bytes No. of pages in virtual memory = = 236
12
2 B
Partition size = 65536 Bytes = 216 Bytes
Þ 26. 230 pages = 64 giga pages.
224 Bytes 137. (a) For the address 0 × 034F48AC5345
No. of partitions = 16 = 28 Page offset = 12 bits {Page size = 212 B}
2 Bytes
Hence number of bits needed in an entry in the process Page No. (36 bits) Offset (12 bits)
table to record all of the partition = 8 bits.
Hence, option (a) is correct. 48 bits
132. (b) Size of limit register is no. of bits to identify size of \ The last 3 bits of the address in Hexadecimal
prime memory minus no. of bits to identify the size of represents the page offset
one entry in the process table.
= (345)16. = (3 × 162 + 4 × 161 + 5 × 160) 10= (837)10.
That is 24 – 8 = 16 bits. Hence (a) is the correct option.
8
Page - 415 - 476
DATABASES
C Ø ER-model
O Ø
Ø
Relational model (relational algebra, tuple calculus)
T
Ø File structures (sequential files, indexing, B and B+ trees)
E
N
T
S
EBD_7203
S3-416 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
DATABASE MANAGEMENT SYSTEM
Database Management Systems are specially designed software which is used to create and maintain
a database. It acts as an interface between users and a database or multiple databases.
The important processes catered by existing DBMS are as below:
• Defining or constructing a data structure which is also called as data definition such as creating
a table, deleting a table or modifying the existing one.
• Updating like inserting a record into a table, deleting or modifying a record.
• Retrieval or extracting information from the database by user queries for user applications,
reporting or any other business purposes.
• Administration includes the activities like enforcing data security, maintaining data integrity,
data backup and recovery, granting & revoking accesses, performance monitoring, disaster
management etc. These activities are generally carried out by a DBA (database administrator).
Components of Database System :
The database system can be divided into four components.
Users • Users : Users may be of various type such as DB administrator, System
developer and End users.
• Database application : Database application may be Personal, Departmental,
Enterprise and internal.
Database • DBMS : Software that allows users to define, create and manages database
Applications access. Ex : Mysql, Oracle etc.
• Database : Collection of logical data.
Functions of DBMS :
Data Base Management System (Dbms)
• Provides data independence
• Concurrency Control
Database • Provides Recovery services
• Provides Utility services
• Provides a clear and logical view of the process that manipulates data.
Advantages of DBMS :
• Segregation of application program.
• Minimal data duplicacy.
• Easy retrieval of data
• Reduced development time and maintainance need.
Disadvantages of DBMS :
• Complexity
• Costly
Department • Large in size
No. Name
DATABASE MODEL
A Database model defines the logical design of data. The model describes the
Course Student
relationships between different parts of the data. In history of database design,
no. name unit id name course
three models have been in use.
id Name Professor Database Model
Example of Hierarchical Movel It refers to a set of concepts to describe the structure of a database and certain
constraints that the database should obey.
Department Student
no. name name course student
Categories of data models
id
• Conceptual (high-level, semantic) data models: Provide concepts that are
Course Professor close to the way many users perceive data. (Also called entity-based or
No. Name Unit id Name object-based data models.)
• Physical (low-level, internal) data models: Provide concepts that describe
Example of Network Model details of how data is stored in the computer.
DATABASES S3-417
• Implementation (representational) data models: Provide concepts that fall between the
above two, balancing user views with some computer storage details.
Database Schema: The description of a database. Includes descriptions of the database
structure and the constraints that should hold on the database.
Schema Diagram: A diagrammatic display of (some aspects of) a database schema.
Database Instance: The actual data stored in a database at a particular moment in time. Also
called database state (or occurrence).
(i) Hierarchical Model
In this model each entity has only one parent but can have several children . At the top of
hierarchy there is only one entity which is called Root.
(ii) Network Model: In the network model, entities are organised in a graph, in which some entities
can be accessed through several path
(iii) Relational Model
In this model, data is organised in two-dimesional tables Department Professor
called relations. The tables or relation are related to each No. Name No. Name Dept No. Courses
other.
Course Student
ENTITY RELATIONSHIP MODEL
No. Dept No. Prof ID Unit Id Name Course
E-R model is a very popular conceptual data model which is used
to develop conceptual design of databases. This data model
describes or perceives the real world data in form of entities.
Example of Relational Model
Entity and Entity Sets:
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 concrete and a physical existence (e.g.: person, place) or it can be abstract
or conceptual existence like loan, course.
Entity set is a collection of entities of a particular entity type at any point of time.
For example: A firm is having many employees, these are defined as entities(e1, e2, e3, .en) and all Employee
these entities are having same attributes under entity type employee. The set of students
(e1,e2,e3……) is entity set.
• Entities Name
Student
(ATTRIBUTE)
• Relationships among entities Symbols used in E-R Diagram (ENTITY)
• Entity – rectangle
• Attribute – oval
Enrolled Course
• Relationship – diamond (RELATIONSHIP) (ENTITY)
• Link – line
EBD_7203
S3-418 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
First Last
SSN 2. Ellipse Attributes
UNION
INTERSECTION Example
R
A 1
B 2
D 3
F 4 R INTERSECTION S
E 5
A 1
S D 3
A 1
C 2
D 3
E 4
Intersection
DATABASES S3-423
DIFFERENCE Example
R
A 1 R DIFFERENCE S
B 2
D 3 B 2
F 4 F 4
E 5 E 5
S
A 1
S DIFFERENCE R
C 2
D 3 C 2
E 4 E 4
DIFFERENCE
Cross Product Operation
The cross product operation combines the elements in two relations. The Cross product of relation
A and B can be denoted as A × B. The cross product combines the tuples in A and B in a combinatorial
manner, i.e. every tuple in A will be combined with every in relation B. The cross product is also called
as Cartesian product. Here the attributes and domains of the two relation need not be compatible.
Example,
s branch_name='bangalore' (Depositor × Borrower)
The result set contains all the combination of the tuples in depositor with borrower.
Renaming Operation Example of renaming
The rename operation is denoted by lowercase Greek letter rho(r). operation :
The rename operation can be expressed by the following, rA ( R) changes the name of the relation rdeposit or _loan
to A (depositor) - the
rA(c1,c2,c3…..cn)( R ) changes the name of the relation to A and the column names to c1,c2,c3,…cn. depositor relation
CARTESIAN PRODUCT operation changed to
The Cartesian Product is also an operator which works on two sets. It is sometimes called the CROSS depositor_loan.
PRODUCT or CROSS JOIN.
It combines the tuples of one relation with all the tuples of the other relation.
CARTESIAN PRODUCT example
R R CROSS S
A 1 A 1 A 1 F 4 A 1
B 2 A 1 C 2 F 4 C 2
D 3 A 1 D 3 F 4 D 3
F 4 A 1 E 4 F 4 E 4
E 5 B 2 A 1 E 5 A 1
B 2 C 2 E 5 C 2
S
B 2 D 3 E 5 D 3
A 1 B 2 E 4 E 5 E 4
C 2
D 3 A 1
D 3
D 3 C 2
E 4
D 3 D 3
D 3 E 4
CARTESIAN PRODUCT
JOIN Operator
JOIN is used to combine related tuples from two relations:
• In its simplest form the JOIN operator is just the cross product of the two relations.
• As the join becomes more complex, tuples are removed within the cross product to make
the result of the join more meaningful.
EBD_7203
S3-424 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
• JOIN allows you to evaluate a join condition between the attributes of the relations on
which the join is undertaken.
The notation used is
R JOINjoin condition S
JOIN Example
R JOIN S
R ColA ColB R. ColA = S. SColA
A 1 A 1 A 1
B 2 D 3 D 3
D 3 E 5 E 4
F 4
E 5
R JOIN S
S R. ColB = S. SColB
SColA SColB
A 1 A 1 A 1
C 2 B 2 C 2
D 3 D 3 D 3
E 4 F 4 E 4
Equi join
A special case of join condition where the join condition is only between the equalities, like
employee.dept_no = department.dept_num. There is equality between 2 fields of employee and
department.
The comparison operator used in equijoin is =. The common attribute in both the relations is refined
and the result set contains only one field. The above example is an equi join.
Equi join is represented by R S where R & S are two relations.
Natural Join
Invariably the JOIN involves an equality test, and thus is often described as an equi-join. Such joins
result in two attributes in the resulting relation having exactly the same value. A ‘natural join’ will
remove the duplicate attribute(s).
• In most systems a natural join will require that the attributes have the same name to identify
the attribute(s) to be used in the join. This may require a renaming mechanism.
• If you do use natural joins make sure that the relations do not have two attributes with
the same name by accident.
OUTER JOINs
Notice that much of the data is lost when applying a join to two relations. In some cases this lost
data might hold useful information. An outer join retains the information that would have been lost
from the tables, replacing missing data with nulls.
There are three forms of the outer join, depending on which data is to be kept.
• LEFT OUTER JOIN - keep data from the left-hand table
• RIGHT OUTER JOIN - keep data from the right-hand table
• FULL OUTER JOIN - keep data from both tables
DATABASES S3-425
OUTER JOIN example 1
S
R FULL OUTER JOIN
R ColA ColB R. ColA = S. SColA
A 1 A 1 A 1
B 2 D 3 D 3
D 3 E 5 E 4
F 4 B 2 - -
E 5 F 4 - -
- - C 2
S SColA SColB
A 1
C 2
D 3
E 4
Division Operation
The division operator is helpful in certain kind of queries and is denoted
by ÷.
The division can be explained by,
For two relations A and B, A(Z) ÷ B(X) , where is subset of X and Y
would be Y = Z-X È Y, hence Y is the set of attributes of X that are not
present in Y. Example, select the
RELATIONAL CALCULUS name of the employees
whose department is
Relational calculus is an alternative form of relational algebra which is non-procedural or declarative
'Finance', the tuple
language where it is not required to be concerned about the procedure to obtain the result rather the
calculus expression as,
output is obtained without knowing the method of retrieval. Sql is a very good example of a
{t.employee_name|
declarative language. The variants of the calculus to be explained Tuple relational calculus(TRC)and
Employee(t) and
domain relational calculus (DRC) Variables in TRC take on tuples as values and the variables range
t.department =
over column values in DRC.
'Finance'}
EBD_7203
S3-426 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Atoms
For the construction of the formulae we will assume an infinite 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 defines
a type assignment that assigns headers to some tuple variables. We then define the set of atomic
formulas A[S,type] with the following rules:
1. if v and w in V, a in type(v) and b in type(w) then the formula “v.a = w.b” is in A[S,type],
2. if v in V, a in type(v) and k denotes a value in D then the formula “ v.a = k “ is in A[S,type],
and
3. if v in V, r in R and type(v) = h(r) then the formula “r(v)” is in A[S,type].
Examples of atoms are:
• (t.age = s.age) — t has an age attribute and s has an age attribute with the same value
• (t.name = “Codd”) — tuple t has a name attribute and its value is “Codd”
• Book(t) — tuple t is present in relation Book.
The formal semantics of such atoms is defined given a database db over S and a tuple variable binding
val : V -> TD that maps tuple variables to tuples over the domain in S:
1. “v.a = w.b” is true if and only if val(v)(a) = val(w)(b)
2. “v.a = k” is true if and only if val(v)(a) = k
3. “r(v)” is true if and only if val(v) is in db(r)
Formulas
The atoms can be combined into formulas, as is usual in first-order logic, with the logical operators
Ù (and), Ú (or) and ¬ (not), and we can use the existential quantifier ($) and the universal quantifier
( ") to bind the variables. We define the set of formulas F[S,type] inductively with the following rules:
1. every atom in A[S,type] is also in F [S,type]
2. if f1 and f2 are in F [S,type] then the formula “ f1 Ù f2” is also in F [S,type]
3. if f1 and f2 are in F [S,type] then the formula “ f1 Ú f2” is also in F [S,type]
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 the formula
“ $ v : H ( f )” is also in F[S,type], where type[v->H] denotes the function that is equal to type
except that it maps v to H,
6. if v in V, H a header and f a formula in F[S,type [v->H]] then the formula
“ "v : H ( f )” is also in F[S,type]
Examples of Formulas:
• t.name = “C. J. Date” Ú t.name = “H. Darwen”
• Book(t) Ú Magazine(t)
• " t : {author, title, subject} ( ¬ ( Book(t) Ù t.author = “C. J. Date” Ù ¬ ( t.subject = “relational
model”)))
DATABASES S3-427
Note that the last formula states that all books that are written by C. J. Date have as their subject
the relational model. As usual we omit brackets if this causes no ambiguity about the semantics of
the formula.
We will assume that the quantifiers quantify over the universe of all tuples over the domain in the
schema. This leads to the following formal semantics for formulas given a database db over S and
a tuple variable binding val : V -> TD:
1. “ f1 Ù f2 ” is true if and only if “ f1” is true and “ f2” is true,
2. “ f1 Ú f2” is true if and only if “ f1” is true or “ f2” is true or both are true,
3. “ ¬ f ” is true if and only if “ f ” is not true,
4. “ $ v : H ( f )” is true if and only if there is a tuple t over D such that
dom(t) = H and the formula “ f ” is true for val[v->t], and
5. “ " v : H( f )” is true if and only if for all tuples t over D such that dom(t) = H the formula “
f ” is true for val[v->t].
Domain relational Calculus
Domain relational calculus is another variation of relational calculus which is equivalent to tuple
calculus and relational algebra. In domain calculus the variables range over single values from
domains of attributes unlike tuple calculus where the variable ranges over tuples.
An expression of domain relational calculus is of the form,
{< x1, x2, x3….. xn > | P(x1, x2, x3….., xn)}
Where x1, x2, x3 are the domain variables and P is the condition or formula of the domain
relational calculus.
Example:
Find the emp name, address and salary for employees where salary is more than 2000
{<n,a,s> | <n,a,s> Employees A s>2000}
The query language based on domain relational calculus is QBE.
DATABASE DESIGN (INTEGRITY CONSTRAINTS, NORMAL FOR MS)
Integrity constraints
This ensures the data consistency there are changes made to the database. It prevents invalid entry
of information.
The integrity constraints fall into following categories,
Domain constraints:
The attributes are declared to accept certain type of domain values. These are the basic form
of integrity constraints. The constraints are checked when new data is added into the tables.
A domain can be created using create domain command. Several attributes can have same
domain. Student name and subject name can have same domain as character.
Check clause: it is used to restrict a domain to have particular value or check value is not null.
For example: create domain accnt_typechar(20) constraint acct_type check (value in
(‘checking’,’Savings’)
Referential Integrity:
This is a database concept which ensures the consistency of the relationship among tables.
When table A is having foreign key to another table B, the concept of referential integrity
states that, a record cannot be added to table A unless there is a corresponding record in table
B.
The same applies for updating or deleting records from table B. The techniques used for these
operations are called update cascading, delete cascading which ensures that changes made to
the table B are reflected in primary table.
For example : Consider 2 tables employees and managers. An attribute in employee table
managed_by which is a foreign key points to the employee’s manager in manager’s table. The
referential integrity enforces the following:
The attribute in
1. A record added to employee table should point to a valid record in manager’s table
2. When a primary key in manager’s table changes, the changes should reflect in all corresponding
records in employee table using cascading update.
3. Similarly, when a record in managers table is deleted, all the corresponding records in employee
table will be deleted using delete cascading.
EBD_7203
S3-428 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Before starting the normal forms it is important to understand the types of dependencies as explained
below.
Functional dependency
Example: {emp_id) ->
An attribute is said to be functional dependent on a set of attributes of A, if each value of A is
{emp_name}
associated with one B value and be denoted as A->B. In other words, a relationship that by knowing
the value of one attribute or set of attributes can state the value of another attribute in same table.
Trivial Functional dependency
Example: When a functional dependency of an attribute on a collection of attributes that includes itself in the
{emp_id,emp_addr} -> collection.
{emp_addr}
Full functional dependency
An attribute B is said to be FFD on A, if it is functionally dependent on A and not functionally
dependent on any attributes present in A
Transitive dependency:
It is an indirect dependency between 2 attributes. It can be written as A->C is true only because A-
>B and B->C.
NOR MALIZATION
Normalization is a process of organizing the data in such a way that data is easily accessed, managed
and modified. In other words, the large tables are divided into smaller tables and defining relationship
between them. The DBMS normalization reduces the data redundancy, removes data anomalies (like
updating anomaly, insertion anomaly, deletion anomaly) and stores minimal amount of information.
The normalization reduces the complexities in data manipulation in addition, deletion or modification
of a record, if a change is applied on a field in a single table and the change reflects in rest of the
database using defined relationship.
Normal forms:
The commonly used four normal forms are first(1NF), second(2NF), third(3NF) and Boyce Codd
normal form(BCNF). The other normal forms are fourth(4NF) and fifth(5NF).
First normal form:-
The row of data in a table should not contain repeated group of data i.e. each column should
have unique value. Each record in a table should have a unique identifier, primary key.
Non-Normalized table :
Address table:
Example of rename 3. AND &OR : are used normally when there are multiple conditions to be specified in
operation: Old column the query.
name as new column name Example: select emp_no, emp_name from employees where emp_name = ‘Alex’ and
Select customer_name as emp_sal> 10000
c_name 4. NOT : The rows get selected where the specified condition is false.
From customer as c Example: select emp_name, emp_no from emp where NOT dept = ‘HR’
Where c.c_name = ‘alex’ Comparison keywords:
1. LIKE : This operator is used to compare the column value with a specified
pattern. For comparison, 2 wildcard characters ‘%’ &’_’.
Example of all operation : select 2. IN : This compares a column in list of values or value specified in a subquery.
ALL branch_name from branch 3. IS NULL : it displays the rows where the specified column is null
DCL Commands
Example of LIKE: for
1. ORDER BY clause: This is used to arrange or sort the result set either in ascending or
employees, whose
descending orders by using keywords ASC,DESC.
name starts with ‘M’
Example : select emp_id, emp_name from employees where dept= ‘Finance’
Select * from employee
Order by emp_nodesc
where emp_name LIKE
2. GROUP BY AND HAVING clause
‘M%’
Group by is used with conjunction to group functions to retrieve grouped data according to
one or more columns.
Example of IN : Having clause is used as a ‘where’ condition when group by is used.
Students who selected Example: select subj, avg(marks) from students
both physics and Group by subj
maths for curriculum Having subj = ‘physics’
Select s_name from DDL commands
students where
subject in (‘Physics’, The SQL supports the DDL operations are used to create, modify and delete database objects.
‘Chemistry’) 1. CREATE statement
Create - To make a new database, table, index, or stored procedure.
A CREATE statement in SQL creates an object in a relational database management system
(RDBMS).
CREATE TABLE statement
A commonly used CREATE command is the CREATE TABLE command. The typical usage is:
CREATE TABLE [table name] ( [column definitions] ) [table parameters].
column definitions: A comma-separated list consisting of any of the following
• Column definition: [column name][data type]{NULL | NOT NULL}{column options}
• Primary key definition: PRIMARY KEY ( [comma separated column list] )
• Constraints: {CONSTRAINT}[constraint definition]
• RDBMS specific functionality
For example, the command to create a table named employees with a few sample columns would
be:
CREATETABLE employees (
id INTEGERPRIMARYKEY,
first_name VARCHAR(50)NULL,
last_name VARCHAR(75)NOTNULL,
dateofbirth DATENULL
);
Note that some forms of CREATE TABLE DDL may incorporate DML (data manipulation
language)-like constructs as well, such as the CREATE TABLE AS SELECT (CTAS) syntax of
SQL.[2]
2. DROP statements
Drop - To destroy an existing database, table, index, or view.
A DROP statement in SQL removes an object from a relational database management system
(RDBMS). The types of objects that can be dropped depends on which RDBMS is being used, but
most support the dropping of tables, users, and databases. Some systems (such as PostgreSQL) allow
DROP and other DDL commands to occur inside of a transaction and thus be rolled back. The typical
usage is simply:
DATABASES S3-431
DROP objecttypeobjectname.
For example, the command to drop a table named employees would be:
DROPTABLE employees;
The DROP statement is distinct from the DELETE and TRUNCATE statements, in that DELETE and
TRUNCATE do not remove the table itself. For example, a DELETE statement might delete some (or
all) data from a table while leaving the table itself in the database, whereas a DROP statement would
remove the entire table from the database.
3. ALTER statements
Alter - To modify an existing database object.
An ALTER statement in SQL changes the properties of an object inside of a relational database
management system (RDBMS). The types of objects that can be altered depends on which
RDBMS is being used. The typical usage is:
ALTER objecttypeobjectnameparameters.
For example, the command to add (then remove) a column named bubbles for an existing table
named sink would be:
ALTERTABLE sink ADD bubbles INTEGER;
ALTERTABLE sink DROPCOLUMN bubbles;
• CREATE - Used to create a new table, a view of a table, or other object in database.
• ALTER - Used to modify an existing database object, such as a table.
• DROP - Used to delete an entire table, a view of a table or other object in the
database.
Data Control Language (DCL)
• GRANT - Used to give a privilege to someone.
• REVOKE - Used to take back privileges granted to someone.
4. Truncate : These command permanently removes the rows of the table from the database and
noclauses can be appended to this command.
Example : Truncate table table-name
DML commands
SQL supports querying, inserting, deleting updating of records in a table. These operations can be
performed using DML commands.The DML commands are Insert, update,delete.
1. Insert : used to add new rows into a table
Insert into students(s_rollnumber,s_name,addr1,gender,email) values
(123, ‘amar’,’abc..’, ‘M’,’amar@gmail.com’)
2. Update : used to update the value of an attribute in a row.
Update students set email =’amar123@gmail.com’
Where s_rollnumber = 123
3. Delete : used to delete rows from the table
Delete from students where s_rollnumber = 123
Nested queries:
A query within a query or a query nested in a larger query is called a subquery. A subquery can be
added in SELECT, FROM OR WHEREclauses. It can be nested inside a select, insert , update or delete
statements. A subquery can be treated as inner query and other query is the outer query.
Example: select s_rollnumber, s_name from students
where first_name in (select first_name from students where subj = ‘Maths’)
SQL joins :
SQL joins are generally used to combine rows from different tables bassed on a common field among
tables. SQL joins can be used in ‘where’ clause of select, update, insert and delete commands.
1. Inner join or equi join: The query with inner join eturns all rows from different tables which
satisfies the join condition. It returns the rows when there is atleast one match in both tables.
Example: selectcust_id, cust_name, order_id,order_date from customer c,orders o
Where c.cust_id = o.cust_id
2. Left outer join : it returns all rows from left table and matched rows from right table.
Example:select cust_id, cust_name, order_id,order_date from customer c
left outer join orders o on c.cust_id = o.cust_id
This returns all rows from customer table and matched rows from order table.
EBD_7203
S3-432 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
3. Right outer join : it returns all rows from right table and matching rows from left table.
Example: select cust_id, cust_name, order_id,order_date from customer c
right outer join orders o on c.cust_id = o.cust_id
This returns all rows from order table and matched rows from customer table.
4. Full join: This returns all rows from both the tables and fills in nulls for missing matches on
either sides.
Eg: select cust_id, cust_name, order_id,order_date from customer c
full outer join orders o on c.cust_id = o.cust_id
order by o.cust_id
FILE STRUCTURES (SEQUENTIAL FILES, INDEXING, B AND B+ TREES)
Data in DBMS is stored on the storage devices like disks or tapes. The data on the disk is stored
on smaller storage disk space unit called pages. The availability of space on the disks is managed
by disk space manager, the file manager requests disk space manager to obtain and relinquish space
on disk.
The file management layer frees the space in the form of unit pages and this layer is responsible for
keeping track of pages in a file and for arranging records within pages.When a record is required for
processing, the record should be fetched from the main memory. The file manager identifies the page
on which the record resides and issues a request for the page to buffer manager. The buffer manager
fetches that particular page into a region called buffer pool on main memory and tells the file manager,
the location of the requested page.
The Memory hierarchy
Memory in a computer system is arranged in hierarchy, at top it is primary storage which consists
of cache and main memory. This provides very fast access to data. The next is secondary storage
devices which include magnetic disks, these are slower compared to primary storage. Tertiary storage
includes optical disks and tapes are the slowest of storage devices.
Though the data access from primary storage is faster than data access from secondary storages,
slower storage devices such as tapes, disks play a pivotal role in data storage because the amount
of data stored on these is large. The systems with 32-bit addressing, only 2 raised 32 bytes can be
directly accessible from main memory. The number of data objects exceeds this number and data must
be maintained across program execution. The data on primary storage is generally volatile and the
data on the secondary storage devices retains the data when the computer is restarted, is non-volatile.
The secondary storage device tapes are relatively inexpensive and store large amount of data. These
can be used for archival storage of amount where the data has to be maintained for a long period
of time and the data access in that frequent. The main drawback of tapes is that they are sequential
access devices, cannot access a given location on tape. I.e. to access the last byte on a tape, we
would have to go through the entire tape first.
Magnetic Disks
Magnetic disks provide the bulk secondary storage for modern computer systems and a large
database requires hundreds of disks for the storage.
Physically, the disks are relatively simple and contain number of disk platters. These platters are made
up of rigid material or glass and are covered with magnetic recording material covered on both
sides.(e.g.: hard disk or floppy disk) Each disk platter has a flat circular shape.
The disk surface is logically divided into tracks which are further divided into sectors. A sector is
a smallest unit of information which can read from or written into on the disk. The read-write head
stored the information on a sector, the disk surface may contain hundreds of concentric tracks
containing thousands of sectors.
A disk has number of platters, read and write heads of tracks are mounted on a single assembly and
move together, this single assembly is called disk arm. The disk arms and disk platters are together
known as head-disk assemblies. The tracks of all the platters together is called cylinder.
In a magnetic disc, read-write heads are placed as close as possible to the disk surface to increase
the recording density. The head typically floats only microns from the disk surface and this creates
a small breeze. The head assembly is shaped in such a way that this breeze keeps the head floating
above the disk surface.
A disk controller acts as an interface between computer system and hardware of the disk drive. It
DATABASES S3-433
implements the high level commands to read or write a sector by moving the disk arm to the correct
track and transferring data to from the disk surfaces. The disk controller attaches the checksum to
each sector and is computed when the data is written to the sector. The checksum is again computed
when the read back and both check sum are compared. If the data are corrupted there is high chance
of the calculated checksums doesn’t match and that reports an error.
A block is continuous sequence of sectors from a single track on a platter.
Disks performance measures
Access time: when a read or write requested is given to when the data transfer begins.
Seek time : the time taken to move the disk heads to the tracks where the desired block of data is
present.
Rotational delay: Once the seek has initialized, the time spent for the required sector to appear under
head.
Transfer time: This is the time taken to read or write the data in the block after positioning of the
head.
Performance Implications
Data should be present in memory for DBMS to operate on it.
To read or write a single item on a block, the entire block is transferred.
The transfer time varies depending on the location of a data.
RAID (Redundant arrays of independent disks)
Disks are the potential bottlenecks for performance and storage system reliability. A variety of disk
organization techniques to improve the performance and reliability is collectively called as RAID.
Improving the performance by data striping
In data striping, the bits of each byte of data are spilt across the multiple disks. For example the array
of multiple disks is treated as single disk. In such organization, every disk participation in data access,
so that the multiple disks can be accessed in the same time as it takes to access single disk.
The RAID levels
RAID level 0 refers to disk arrays of data striping of data at block level but without any redundancy.
RAID level 1 refers to disk arrays of data striping at block level which involves disk mirroring.
RAID level 2, this is bit level striping with dedicated with hamming code parity, the data is striped
in such a way each sequential bit is on a different drive.
RAID level 3, this is block level striping with dedicated with code parity except that data is striped
in such a way each sequential byte is on a different drive.
RAID level4, this is block level parity and all are parity data are stored on a single drive.
RAID level5, this is block level parity and all are parity data are stored on a multiple drive, but one
to operate on data. The array would not be destroyed on a single drive failure.
RAID level6, this is a block level parity with double distributed parity and has tolerance unto 2 failed
drives.
Disk Space Management
Disk space manager manages space on disk, it supports the concept of page the unit used to store
data. It allocates and deallocates a page and read or write a page.
Keeping track of free blocks
A data base grows and shrinks as the data is entered and removed from the database. The disk
manager keeps track of which pages of the block is in use or free. One way to keep track of free space
is to maintain the list of free blocks as the space is deallocated. Another way to keep track of free
blocks is to maintain a bitmap with one bit to indicate whether the block is in use or not.
Using OS file systems to manage disk space
Operating systems also manages disk space where a database is mapped into different files which
are maintained by underlying operating system. These files are partitioned into blocks, which are the
units of both storage and data transfer. A major goal of the dbms is to minimize the number of block
transfer between memory and disk.
The database files can entirely reside on OS files and the disk space manager takes care of managing
space in these files.
EBD_7203
S3-434 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Buffer Manager
When a program in data base systems make a request for a block in a disk from buffer manager, the
buffer manager pass on the address of the free block available on the main memory to the requester.
If the block is unavailable the buffer manager first allocates the space in the buffer for the block by
throwing away some other block if necessary and then passes on the address to the requester.
The buffer manager uses the following techniques to serve the database systems in a better way,
• Buffer replacement strategy:when there is no space in the buffer, a block must be removed from
the buffer before a new one can come in. Most of the OS uses LRU (least recently used) scheme,
to release the block which was used least recently and it will be removed from the buffer.
• Pinned Blocks: In most recovery systems, a block cannot be written back into the disk when
update on that block is in progress. A block which is not allowed to written in the disk is called
pinned block. This feature is essential for the systems which are prone to crashes.
• Forced output of blocks: in some situations it is required to write back the block to the disk
though the buffer space it occupies is not needed, this forced write is called forced output of
a block.
Files and Indexes
The information is represented in the form of records and these records are stored in the memory i.e.
in pages. These records are logically organized into files. A file of records is a collection of records
that may extend to several pages. Each record has a unique identifier called record id or rid in short
and page containing a particular can be accessed by using this rid. A basic file structure called heap
file contains records in random order and supports the retrieval of the records by using rid.
Organization of records in files
Heap files
The data in a heap file is unordered and the data can be retrieved using the unique identifier of every
record in the file and every page in the file is of same size. The operations supported on a heap file
are create file, destroy file, insert record, delete record, get a record with a given rid and scan all the
records in the file.
We must keep track of the pages in each heap file in order to support scan and fid free space available.
The two alternatives to maintain the information is discussed below.
Sequential file organization
Sequential file organization
Multitable clustering
Store several relations in one file using a multitable clustering file organization.
Customer_name account_number
Hayes A-102
Hayes A-220
Hayes A-503
Turner A-305
DATABASES S3-435
A sequential file organization is better way of processing records in sorted order based on some
search key, sometimes this search key may be a primary key or a super key or not. To allow
the faster access of records the records are linked together by using pointers. The pointer in
each record points to the next key in the sorted order. To reduce the number of accesses to
different the records are physically stored as close as possible.
Clustering file organization
A cluster file organization stores the data from two or more relations in a same block. This kind
of file organization allows us to read records that would satisfy join condition and data read
from only one block. The records in the cluster file organization are chained together using
pointers. When clustering is to be used it depends on the query types which are used
frequently. This is decided by the database designer. Clustering is very useful in improving
performance when used carefully.
Data dictionary storage
A relational database system needs to maintain the data about the realtions and schema in the
database and this is called a data dictionary and the types of information stored are, name of
the relations, name of attributes its domain and length, name of views, integrity constraints,
authorized users, etc.
Indexes
An index is an auxiliary data structure which is used to speed up the record search. An attribute or
set of attributes can be used as a search key used to look up the records. The indexes are used to
gain faster random access to records on a file. There are two kinds of indices,
1. Ordered indices – this is based on a sorted order of the values. The file containing the records
is sequentially ordered based on a primary index which can be a primary key or a super key.
There are two types of ordered indices,
Dense index: Every search key value will have an index record in the file. In a dense index, the
primary index will contain the search key value and pointer to the first record with the search
key value. The rest of the records would be arranged sequentially with the same search value.
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 following
the pointers the desired record is found.
B+ tree index files
B+ tree is efficient disk based structure which stores value of key or value in pair. B+ tree supports
faster record search, fast record 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+ tree has leaf nodes and interior nodes.
The two nodes can be distinguished as below,
Leaf nodes store the data in the form of pair (key, value) and these leaf nodes are organized in the
form of linked list of pages.
EBD_7203
S3-436 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example: Interior nodes are in the form of a tree structure starting from root node and the structure
of the interior node is as shown below which a sequence of pointers and keys. The definition of
neighboring pointers
Given a key ki, the page pointer before ki is defined as prior ki and the page pointer after ki next_ki,
defined as
p.priorki = p.pointers [i]
p.nextki = p.pointers[i] +1
Constraints and properties of a B+ tree,
Keys are sorted in the nodes, if k is a node and all the keys in the node should be sorted.
Leaf Nodes and interior nodes are sorted in B+ tree. The linked lists of leaf node are sorted
which allows efficient traversal of key between leaf nodes.
The tree is balanced, so that all the paths from root node to leaf nodes must be of equal length.
The nodes are sufficiently filled
B+ tree search and insertion
B+ tree searching uses the direct tree traversal algorithm.
Insertion into B+ tree is bit tricky and B+ tree insertion as to deal with node overflows and underflows.
The insertion algorithm initially looks for the right node to insert and tries to insert in the leaf node.
B+ tree is also very efficient for deletion also, it is just a mirror reversal of insertion.
If a sequential file sorted by a key, the data in the sequential file can be bulk loaded into B+ tree.
B+ tree is used for sorting in disk based sorting.
2. Hash indices- The values are distributed in different buckets, and the bucket to which the value
is determined using hash function.
B tree index files:
B tree indexes are similar to B+ tree indices. The different between 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.
The advantages are, it doesn’t contain any redundant storage and some searches will be faster. The
disadvantages are, as the leaf nodes and non-leaf nodes are of different size, it complicates storage.
When deletion happens in non-leaf node, it becomes more complicated.
TRANSACTIONS
Generally, the operations performed on database appear to be a single instance of work from user’s
point of view. For example, when a transaction is performed to transfer money from one account to
another, it appears to single piece of work but involves several operations to complete the transaction.
Hence transaction can be defined as single logical unit of work which consists of collection of
operations. The transactions must be either completed or aborted, no intermediate states are accepted.
A database always ensures the proper execution of transactions concurrently without introducing any
inconsistency in the system despite failures.
Transaction concept
A transaction is initiated by a user program written in a high level language or programming language.
(e.g.: java, COBOL, C, C++...). The transaction is delimited by statements of the form begin transaction
and end transaction. The transactions of all operations which appear between these two statements.
Consider the following example of transferring Rs. 500 from account A to account B. This transaction
can be defined as
1. Read (A);
2. A: = A-500;
3. Write (A);
4. Read (B);
5. B: = B+500;
6. Write (B);
The following are the properties of the transactions maintained by database systems to ensure
integrity of data,
Atomicity: Either all operations must be completed or incomplete operations should be
aborted.For example, if a transaction fails after step 3 before step 6, the system ensures that the
database is not updated with the changes or else it will result in inconsistency in the database.
DATABASES S3-437
Consistency: The consistency of execution is maintained though the transactions are executed
in isolation. The sum of account A and B remains unchanged by execution of transaction.
Isolation:The transaction data cannot be reused until the transactions are executed. If it happens
that in between step 3 and step 6, the value will be from an inconsistent database. This issue
can be addressed by running transactions serially one after the other.
Durability: when the transactions are successfully completed and changes made in the database
persist even if there are system failures.I.e. once the transaction of money transfer is completed
the changes persist despite of system failures.
Transaction State:
1. A transaction would always be present in one of the following states:
2. Active state, this is the initial state of the transaction and it stays in this state
while it is executing
partially
3. Partially committed, A transaction is partially committed when the final statement committed committed
is executed
4. Failed, this is the state when normal execution is interrupted and can no longer
proceed. active
5. Aborted, the state after the transaction has been rolled back and database is
restored to the state prior to start of the transaction. There are two actions to
be taken after the transaction is aborted, either restart the transaction or kill the failed aborted
transaction. States of transaction
6. Committed, the state when transaction is successfully completed.
Transactions and schedules
DBMS recognizes the transactions as a series or list of actions. The actions that can be executed
by a transaction include reads and writes. In addition to read and write, each transaction should
specify the final action either by committing or aborting.
Schedule: The execution sequences can be described as schedule.
Complete schedule: a schedule which contains either commit or abort for each transaction which
is listed in it.
Serial schedule: when the actions of different transactions are not interleaved and are executed
from start to finish one by one.
Concurrent execution of transactions
The DBMS interleaves the actions of multiple transactions to improve performance in terms of
increased throughput, improved response time. i.e. when one transaction is waiting to be read from
the disk, meanwhile CPU can process other transaction. Overlapping I/O and CPU activity reduces
the amount of time the CPU time is idle.
Serializability
The major goal of the concurrency control is to generate schedules using serializabiltiy property.
Serializability of schedule means equivalence to some serial schedule withsame transactions. The
transactions are sequential and no two transactions overlap in time and are completely isolated from
each other. There will be no concurrent access to the data by two transactions at the same time.
The transaction management subsystem of dbms generally consists of,
Transaction Manager: This coordinates transactions on behalf of application program and
communicates with scheduler.
Scheduler: This implements a strategy of concurrency control.
Recovery Manager: recovery handles failure and helps to maintain consistency
Buffer Manager: It takes care of transferring data between disk storage and main memo
File Manager: this manipulates the underlying files and manages the allocation of space on disk.
Access Manager: The requests are sent from file manager to access manager to manage the input
and output data.
System manager: An appropriate method to read or write data through system manager.
EBD_7203
S3-438 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Advantages of Concurrent Execution of Transaction
The DBMS interleaves the actions of different transactions to improve performance of system as discussed
below:
• Improved Throughput: Consider that transaction are performed in serial order and active
transaction is waiting for a page to be read in from disk, then instead of waiting for a page,
it can process another transaction. This is because Input/Output activity can be done in parallel
with the CPU activity. The overlapping of Input/Output activities of CPU reduces the amount
of time disks and processors are idle and increases system throughput (the average number of
transaction completed in a given time.)
• Reduced Waiting time: Interleaved execution of a short transaction with a long transaction
usually allows the short transaction to complete quickly. In serial execution a short transaction
could get stuck behind a long transaction leading to unpredictable delays in response time or
average time taken to complete a transaction.
CONCURRENCY CONTROL
Concurrency control coordinates simultaneous transaction execution in multiprocessing database. It
ensures serializability of transactions and handles potential problems like lost updates, uncommitted
data, and inconsistent retrievals.
Lock based protocols
The most method used to implement serializability is to allow a transaction to access data item only
if it is holding a lock. In other words, lock is mechanism to control concurrent access of data item.
The lock to the data items is of two types,
1. Exclusive mode(X):- Data item can be both read and written. If T1 is a transaction which has
acquired an exclusive mode lock on data item Q, then T1 can both read and write Q.
2. Shared mode (S):- Data item can only be read. If T1 is a transaction which has acquired a shared
mode lock on data item Q, then T1 can only read and cannot write Q.
Locks are generally requested to concurrency control manager and transactions proceeds when the
request is granted. Any number of transactions can hold shared locks on an item, if a transaction
holds an exclusive on a data item, no other transaction can hold lock on that item unless the lock
is released.
Example: T1: lock-S (A); Read (A);
Unlock (A); Display (A);
Pitfalls of lock based protocol
• Dead lock, when the transactions are waiting each other releases the locks to proceed execution.
This can be handled by rolling back one of the transactions and releasing the lock.
• Starvation, this can happen when concurrency manager is designed badly.
For example, a transaction may be waiting to hold an exclusive on an item whereas the other
transactions are given S locks on the same item.
The two phase locking protocol
This protocol involves or requires that each transaction issues lock or releases it in two phases
namely,
• Growing phase, the transaction may obtain lock but may not release the locks.
• Shrinking Phase, here the transaction may release locks but may not obtain locks.
Implementation of locking
A lock manager may be implemented as a separate process where the transactions send their requests
to obtain or release locks. The lock manager answers the request by granting or asking a transaction
to roll back in case of dead lock. The transaction waits till is request is answered, Lock manager
maintains a data structure called lock table which contains a record of granted locks and other
requests.
DATABASES S3-439
Graph based protocol
This is an alternative of two phase locking. Tree locking protocol is the simplest form graph based
protocol. It is used to employ the exclusive lock when DB item is in the form of a tree and tree locking
protocol is serializable. It can employ only exclusive locks and ensures no dead lock.
Timestamp-based protocols
In timestamp based protocol, a timestamp is issued for the transactions entering the system, if
transaction T1 is having timestamp T1S, a new transaction T2 is having T2S timestamp where
T2S<T1S. The protocol ensures concurrent execution such that time stamp determines serializability.
This protocol maintains timestamp Q, W-timestamp (Q) is the largest time stamp of any transaction
where write is executed successfully. Similarly R-timestamp (Q) is for read executed successfully. This
ensures that the transactions are executed in the order of the timestamp and there is no conflict in
the execution.
Thomas’s write rule is a rule for time based protocol, can be summarized that it ignores outdated
writes.
Validation based protocol
In this execution of transaction in three phase,
1. Read and execution phase: A transaction writes to temporary local variables.
2. Validation phase: A validation test is carried out on local variables to determine whether they
can be written without violating serializability.
3. Write phase: If the local variables are validated, the updates are done in the database or else
transaction is rolled back.
Recovery system
The following are types of the failure,
– Transaction failure
– System crash
– Disk failure
The recovery manager is responsible to bring the database into a consistent state when a dbms
crashes and restarted. This ensures durability and atomicity. The transactions which are not
committed would be undone. Redos action is taken on transactions which are committed. Recovery
manager maintains log during normal execution which is helpful during crash recovery.
This log consists of records which are written sequentially and stores modifications of the database.
The undo/redo action depends upon the buffer manager. All log related activities like cc related
activities, lock/unlock, dealing with deadlocks arehandled by DBMS transparently.
ARIES recovery
There are three phases in Aries recovery
– Analysis: scan the log file to identify all active acts and dirty pages in the buffer pool.
– Redo: redo all updates in the dirty pages present in the buffer pool.
– Undo: the transactions which were active during crash will be undone.
Finally the updates which are committed would be reflected in the database.
EBD_7203
S3-440 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. Consider a relational schema R = (A, B, C, D, E, H) on which 6. Which one of the following statements about normal forms
the following functional dependencies hold: {A ® B, BC ® is false? [2005, 1 mark]
D, E ® C, D ® A}. What are the candidate keys of R? (a) BCNF is stricter than 3 NF
[2005, 1 mark] (b) Lossless, dependency-preserving decomposition into
(a) AE, BE (b) AE, BE, DE 3NF is always possible
(c) AEH, BEH, BCH (d) AEH, BEH, DEH (c) Lossless, dependency-preserving decomposition into
2. The relation book (title, price) contains the titles and prices BCNF is always possible
of different books. Assuming that no two books have the (d) Any relation with two attributes is in BCNF
same price, what does the following SQL query list? 7. Which one of the following is a key factor for preferring B+
select title trees to binary search trees for indexing database relations?
from book as B [2005, 1 mark]
where (select count (*) (a) Database relations have a large number of records
from book as T (b) Database relations are sorted on the primary key
where T. price > B. price) < 5 [2005, 1 mark] (c) B+ trees require less memory than binary search trees
(a) Title of four most expensive book (d) Data transfer from disks is in blocks
(b) Title of fifth most inexpensive book 8. The following functional dependencies are given
(c) Titles of fifth most expensive book AB ® CD, AF ® D, DE ® F, C ® G, F ® E, G ® A
(d) Titles of five most expensive book Which one of the following options is false? [2007, 1 mark]
(a) {CF}+ = {ACDEFG} (b) {BG}+ = {ACDG}
3. The following table has two attributes A and C where A is +
(c) {AF} ={ACDEFG} (d) {AB}+ = {ACDFG}
the primary key and C is the foreign key referencing a with
9. Consider the relation enrolled (student, course) in which
on-delete cascade.
(student, course) is the primary key, and the relation paid
A C (student, amount) where student is the primary key. Assume
2 4 to null values and no foreign keys or integrity constraints.
3 4 Assume that amounts 6000, 7000, 8000, 9000 and 10000 were
4 3 each paid by 20% of the students. Consider these query
5 2
plans (Plan1 on the left, Plan2 on right) to “list all courses
taken by students who have paid more than x”:
7 2
Enrolled Paid Enrolled Paid
9 5
6 4
The set of all tuples that must be additionally deleted to
preserve referential integrity when the tuple (2, 4) is deleted Probe index
Sequential
scan, select Probe index Sequential
is [2005, 1 mark] on student on student scan
amount > x
(a) (3, 4) and (6, 4) (b) (5, 2) and (7, 2)
(c) (5, 2), (7, 2) and (9, 5) (d) (3, 4), (4, 3) and (6, 4)
4. Let E1 and E2 be two entities in an E/R diagram with simple
single valued attributes. R1 and R2 are two relationship
Indexed nested loop join Indexed nested loop join
between E1 and E2, where R1 is one-to-many and R2 is many-
to-many. R1 and R2 do not have any attributes of their own.
What is the minimum number of tables required to represent
this situation in the relational model? [2005, 2 marks]
(a) 2 (b) 3 Project on course Select on amount > x
(c) 4 (d) 5
5. Let r be a rational instance with schema R = (A, B, C, D). We
define r1 = PA, B, C (r) and r2 = PA, D (r). Let s = r1 * r2 where
* denotes natural join. Given that the decomposition of r Project on course
into r1 and r2 is lossy, which one of the following is true?
[2005, 1 mark]
(a) s Ì r (b) r È s = r
(c) r Ì s (d) r * s = s
DATABASES S3-441
A disk seek takes 4 ms, disk data transfer bandwidth is 300 3. Query1 is a correct implementation of the specification
MB/s and checking a tuple to see if amount is greater than x but Query2 is not.
takes 10 ms. Which of the following statements is correct? 4. Neither Query1 nor Query2 is a correct implementation
[2007, 1 mark] of the specification.
(a) Plan1 and Plan2 will not output identical row sets for 5. Assigning rank with a pure relational query takes less
all database time than scanning in decreasing balance order
(b) A course may be listed more than once in the output of assigning ranks using ODBC.
Plan1 for some databases Which two of the above statements are correct?
(c) For x = 5000, Plan 1 executes faster than Plan 2 for all [2007, 1 mark]
databases (a) 2 and 5 (b) 1 and 3
(b) For x = 9000, Plan 1 executes slower than Plan 2 for all (c) 1 and 4 (d) 3 and 5
databases 12. Consider the following schedules involving two transactions.
10. Consider the relation enrolled (student, course) in which Which one of the following statements is true?
(student, course) is the primary key, and the relation paid S1: r1(X); r1(Y); r2(X); r2(Y); w2 (Y); w1(X)
(student, amount) where student is the primary key. Assume S2: r1(X); r2(X); r2(Y); w2 (Y); r1(Y); w1(X) [2007, 1 mark]
no null values and no foreign keys or integrity constraints. (a) Both S1 and S2 are conflict serializable
Given the following four queries: [2007, 1 mark] (b) S1 is conflict serializable and S2 is not conflict
Query1: Select student from enrolled where student in (select serializable
student from paid) (c) S1 is not conflict serializable and S2 is conflict
Query2: Select student from paid where student in (select serializable
student from enrolled) (d) Both S1 and S2 are not conflict serializable
Query3: select E.student from enrolled E, paid P where 13. The order of a leaf node in a B+ tree is the maximum number
E.student = P.student of (value, data record pointer) pairs it can hold. Given that
Query4: Select student from paid where exits the block size is 1 kbyte, data record pointer is 7 byte long,
(select * from en rolled where enrolled.studen t = the value field is 9 byte long and a block pointer is 6 byte
paid.student) long, what is the order of the leaf node? [2007, 1 mark]
Which one of the following statements is correct? (a) 63 (b) 64
(a) All queries return identical row sets for any database (c) 67 (d) 68
(b) Query2 and Query4 return identical row sets for all 14. Which one of the following statements is false?
databases but there exist databases for which Query1 [2007, 1 mark]
and Query2 return different row sets (a) Any relation with two attributes is in BCNF
(c) There exist databases for which Query3 returns strictly
(b) A relation in which every key has only one attribute is
fewer rows than Query2
in 2NF
(d) There exist databases for which Query4 which
(c) A prime attribute can be transitively dependent on a
encounter an integrity violation at runtime
key in a 3NF relation
11. Consider the relation account (customer, balance) where
(d) A prime attribute can be transitively dependent on a
customer is a primary key and there are no null values. We
key in a BCNF relation
would like to rank customers according to decreasing balance.
15. Consider the table employee (empld, name, department,
The customer with the largest balance gets rank 1. Ties are
salary) and the two queries Q1, Q2 below. Assuming that
not broken but ranks are skipped: if exactly two customers
have the largest balance they each get rank 1 and rank 2 is department 5 has more than one employee, and we want to
not assigned. find the employees who get higher salary than anyone in the
department 5, which one of the statements is true for any
select A. customer, count (B.customer) arbitrary employee table? [2007, 1 mark]
Query1 : from account A, account B Q1 : Select e.empld
From employee e
where A. balance < = B. balance
Where not exists
group by A. customer (Select * From employee s where s.department = “5” and
select A. customer + 1, count (B.customer) s.salary > = e.salary)
Query2 : from account A, account B Q2 : Select e.empld
where A. balance < B. balance From employee e
group by A. customer Where e.salary > Any
(Select distinct salary from employee s Where s.department
Consider these statements about Query1 and Query2. = “5”)
1. Query1 will produce the same row set as Query2 for (a) Q1 is the correct query
some but not all databases. (b) Q2 is the correct query
2. Both Query1 and Query2 are correct implementation of (c) Both Q1 and Q2 produce the same answer
the specification. (d) Neither Q1 nore Q2 is the correct query
EBD_7203
S3-442 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
16. Consider the table employee (empld, sex, SupervisorName) 19. The minimum number of tables needed to represent M, N, P,
with name as the key. supervisor Name gives the name of the R1, R2 is [2008, 2 marks]
supervisor of the employee under consideration. What does (a) 2 (b) 3
the following tuple relational calculus query produce? (c) 4 (d) 5
{e.name | employee (e) ^} [2007, 1 mark] 20. Which of the following is a correct attribute set for one of
table for the correct answer to the above question?
( "x ) ¬employee (x) Ú x. supervisor Name ¹ e, name Ú x. sex [2008, 2 marks]
= “male”]} (a) {M1, M2, M3, P1} (b) {M1, P1, N1, N2}
(a) Name of the employees with a male supervisor (c) {M1, P1, N1} (d) {M1, P1}
(b) Name of the employees with no immediate male 21. Consider a file of 16384 records. Each record is 32 byte long
subordinates and its key field is of size 6 byte. The file is ordered on a non-
(c) Name of the employees with no immediate female key field, and the file organization is unspanned. The file is
subordinates stored in a file system with block size 1024 byte, and the size
(d) Name of the employees with a female supervisor of a block pointer is 10 byte. If the secondary index is built
17. Information about a collection of students is given by the on a key field of the file, and a multi-level index scheme is
relation studinfo (studld, name, sex). The relation enroll used to store the secondary index, the number of first-level
(studld, courseld) gives which student has enrolled for (or and second-level blocks in the multi-level index are
taken) what course(s). Assume that every course is taken by respectively [2008, 2 marks]
at least one male and at least one female student. What does (a) 8 and 0 (b) 128 and 6
the following relational algebra expression represent? (c) 256 and 4 (d) 512 and 5
Pcourseld (P studld (ssex = “female” (studinfo) × pcourseheld 22. Consider the following relational schemas for a library
(enroll)) – enroll) [2007, 1 mark] database:
(a) Courses in which all the female students are enrolled Book (Title, Author, Catalog_no, Publisher, Year, Price)
(b) Courses in which a proper subset of female students Collection (Title, Author, Catalog_no)
are enrolled within the following functional dependencies
(c) Courses in which only male students are enrolled 1. Title, Author ® Catalog_no
(d) None of the above 2. Catalog_no ® Title Author Publisher Year
18. Consider the following log sequence of two transactions on 3. Publisher Title Year ® Price
a bank account, with initial balance 12000, that transfer 2000 Assume {Author, Title} is the key for both schemas. Which
to a mortagage payment and then apply a 5% interest. of the following statements is true? [2008, 2 marks]
1. T1 start [2007, 1 mark] (a) Both Book and Collection are in BCNF
2. T1 B old = 1200 new = 10000 (b) Both Book and Collection are in 3 NF only
3. T1 M old = 0 new = 2000 (c) Book is in 2 NF and Collection is in 3 NF
4. T1 commit (d) Both Book and Collection are in 2 NF only
5. T1 start 23. Let R and S be two relations with the following schemas.
6. T2 B old = 10000 new = 10500 R(P . Q, R1, R2, R3)
7. T2 commit S (P . Q, S1, S2)
Suppose the database system crashes just before log record Where {P, Q}is the key for both schemas. Which of the
is written. When the system is started, which one statement following queries are equivalent? [2008, 2 marks]
is true of the recovery procedure? 1. Pp (R S)
(a) We must redo log record 6 to set B to 10500
2. Pp (R) Pp (S)
(b) We must redo log record 6 to set B to 10000 and the
3. Pp(PP, Q (R) Ç PP, Q (S))
redo log records 2 and 3.
(c) We need not redo log records 2 and 3 because 4. Pp(PP, Q (R) PP, Q (R) – PP, Q (S)))
transaction T1 has committed (a) 1 and 2 (b) 1 and 3
(d) We can apply redo and undo operations in arbitrary (c) 1, 2 and 3 (d) 1, 3 and 4
order because they are idempotent 24. A clustering index is defined on the fields which are of type
(a) non-key and ordering [2008, 1 mark]
Statements for Linked Answer Questions 19 and 20 : (b) non-key and non-ordering
Consider the following ER diagram: (c) key and ordering
(d) key and non-ordering
M1 M2 M3 P1 P2 N1 N2 25. Assume that, in the suppliers relation above, each supplier
and each street within a city has a unique name, and (sname,
city) forms a candidate key. No other functional dependencies
are implied other than those implied by primary and candidate
keys. Which one of the following is true about the above
M R1 P R2 N schema?
DATABASES S3-443
(a) The schema is in BCNF Which of the above schedules are conflict-serializable?
(b) The schema is in 3 NF but not in BCNF (a) S1 and S2 (b) S2 and S3
(c) The schema is in 2 NF but not in 3 NF (c) S3 only (d) S4 only
(d) The schema is not in 2 NF 30. The following functional dependencies hold for relations R
26. Consider the following relational query on the above (A, B, C) and S (B, D, E) [2010, 2 marks]
database: B ® A,
SELECT S. sname A®C
FROM Suppliers S The relation R contains 200 tuples and the relation S contains
WHERE S. sid NOT IN (SELECT C.sid 100 tuples. What is the maximum number of tuples possible
FROM Catalog C in the natural join R S?
WHERE C.pid NOT IN (SELECT (a) 100 (b) 200
P.pid (c) 300 (d) 2000
FROM Parts P 31. Consider the following schedules for transactions T1, T2
WHERE P. colour <> ‘blue’)) and T3: [2010, 2 marks]
Assume that relations corresponding to the above schema
are not empty. Which one of the following is the correct T1 T2 T3
interpretation of the above query> [2009, 1 mark] Read (X)
(a) Find the names of all suppliers who have supplied a Read (Y)
non-blue part Read (Y)
(b) Find the names of all suppliers who have not supplied Write (Y)
a non-blue part Write (X)
(c) Find the names of all suppliers who have supplied only Write (X)
blue part Read (X)
(d) Find the names of all suppliers who have not supplied Write (X)
only blue part
27. Let R and S be relational schemas such that R = {a, b, c} and Which one of the schedules below is the correct serialization
S = {c}. Now consider the following queries on the database: of the above?
1. pR – S (r) – pR – S (pR – S (r) × S – pr – S, S (r)) (a) T1 ® T3 ® T2 (b) T2 ® T1 ® T3
(c) T2 ® T3 ® T1 (b) T3 ® T1 ® T2
{ (
2. t | t Î pR -S ( r ) Ù "u Î s $Ú Î r ( u = v [s ] Ù t = v [ R - S] ) )} 32. Which of the following concurrency control protocols ensure
both conflict serializability and freedom from deadlock?
3. { t | t Î pR -S ( r ) Ù "u Î s ( $u Î s ( u = v [s ] Ù t = v [ R - S ]) )} 1. 2-phase locking [2010, 1 mark]
4. Select R.a, R. b 2. Time-stamp ordering
From R, S (a) 1 only (b) 2 only
Where R.c = S.c (c) Both 1 and 2 (d) Neither 1 nor 2
Which of the above queries are equivalent? [2009, 1 mark] 33. A relational schema for a train reservation database is given
(a) 1 and 2 (b) 1 and 3 below.
Passenger (pid, pname, age)
(c) 2 and 4 (d) 3 and 4
Reservation (pid, class, tid)
28. The following key values are inserted into a B+ tree in which
Table: Passenger
order of the internal nodes is 3, and that of the leaf nodes is
2, in the sequence given below. The order of internal nodes pid pname Age
is the maximum number of tree pointers in each node, and the
0 Sachin 65
order of leaf nodes is the maximum number of data items that
can be stored in it. The B+ tree is initially empty. 1 Rahul 66
10, 3, 6, 8, 4, 2, 1 2 Sourav 67
The maximum number of times leaf nodes would get split up 3 Anil 69
as a result of these insertions is [2009, 1 mark]
(a) 2 (b) 3 Table : Reservation
(c) 4 (d) 5
29. Consider two transactions T1 and T2, and four schedules pid class tid
S1, S2, S3, S4 of T1 and T2 are given below: [2009, 1 mark] 0 AC 8200
T1 : R1 [x] W1 [x] W1 [y] 1 AC 8201
T2 : R2 [x] R2 [y] W2 [y] 2 SC 8201
S1 : R1 [x] R2 [x] R2 [y] W1[x] W1[y] W2[y]
5 AC 8203
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] 1 SC 8204
S4 : R2 [x] R2 [x] R1 [x] W1[x] W1[y] W2[y] 3 AC 8202
EBD_7203
S3-444 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
What pids are returned by the following SQL query for the (c) Hashing will outperform ordered indexing on Q1 but
above instance of the tables? not on Q2.
SELECT pid (d) Hashing will outperform ordered indexing on Q2 but
FROM Reservation not on Q1.
WHERE class = AC AND 38. Consider a relational table with a single record for each
EXISTS (SELECT * registered student with the following attributes:
FROM Passenger 1. Registration_Number: Unique registration number for
WHERE age > 65 AND each registered student
Passenger.pid = Reservation.pid) [2010, 1 mark] 2. UID: Unique Identity Number, unique at the national
(a) 0, 1 (b) 1, 2 level for each citizen
(c) 1, 3 (d) 1, 5 3. Bank Account_Number: unique account number at the
34. Consider a B+ tree in which the maximum number of keys in bank. A student can have multiple accounts or joint
a node is 5. What is the minimum number of keys in any non- accounts. This attributes stores the primary account
root node? [2010, 1 mark] number
(a) 1 (b) 2 4. Name: Name of the Student
(c) 3 (d) 4 5. Hostel_Room: Room number of the hostel
35. Consider a database table T containing two columns X and Which of the following options is incorrect? [2011, 1 mark]
Y each of type integer. After the creation of the table, one (a) Bank Account_Number is a candidate key
record (X = 1, Y = 1) is inserted in the table. Let M X and MY (b) Registration Account_Number can be primary key
denote the respective maximum values of X and Y among all (c) UID is a candidate key if all students are from the same
records in the table at any point in time. Using Mx + 1, 2*MY country
+ 1 respectively. It may be noted that each time after the (d) If S is a superkey such that S UID Ç is NULL then S
insertion, values of MX and MY change. What will be the UID is also a super key
output of the following SQL query after the steps mentioned
above the carried out? Common Data for Questions 39 and 40 :
SELECT Y FROM T WHERE X = 7; [2011, 1 mark] Consider the following relations A, B and C:
(a) 127 (b) 255
A
(c) 190 (d) 257
36. Database table by name Loan_Records is given below. Id Name Age
Borrower Bank_Manager Loan_Amount 12 Arun 60
Ramesh Sunderajan 100000.00 15 Shreya 24
Suresh Ramgopal 5000.00 99 Rohit 11
Mahesh Sunderajan 7000.00
B
What is the output of the following SQL query?
SELECT count (*) Id Name Age
FROM ( 15 Shreya 24
(SELECT Borrower. Bank_Manager FROM Loan_Records) 25 Hari 4
AS S
98 Rohit 20
NATURAL JOIN
(SELECT Bank_Man ager, Loan_Amount FROM 99 Rohit 11
Loan_Records) As T); [2011, 1 mark]
(a) 3 (b) 9 C
(c) 5 (d) 6 Id Name Age
37. Consider a relational table r with sufficient number of records, 10 2200 2
having attributes A1, A2, ... An, let let 1 £ p £ n . Two queries 99 2100 1
Q1 and Q2 are given below.
Q1 = p A .....A where c is constant.
1 p 39. How many tuples does the result of the following SQL query
contain? [2012, 2 marks]
1 p (
Q 2 = p A .....A sc £ A p £ c 2
1 ) and c 1 and c 2 are SELECT A. Id
constants. FROM A
Which of the following statements is true? [2011, 1 mark] WHERE A. Age > ALL (SELECT B. Age
(a) Ordered indexing will always outperform hashing for FROM B
both queries WHERE B. Name = ‘Arun’)
(b) Hashing will always outperform ordered indexing for (a) 4 (b) 3
both queries (c) 0 (d) 1
DATABASES S3-445
40. How many tuples does the result of the following relational R. All attributes used in the GROUP BY clause must
algebra expression contain? Assume that the schema of appear in the SELECT clause
A È B is the same as that of A. [2012, 2 marks] S. Not all attributes used in the GROUP BY clause need
to appear in the SELECT clause
( A È B) A.ld >40Ú C.ld<15C (a) P and R (b) P and S
(a) 7 (b) 4 (c) Q and R (d) Q and S
(c) 5 (d) 9 46. An index is clustered, if [2013, 1 Mark]
41. Consider the following transactions with data items P and Q (a) it is on a set of fields that form a candidate key
initialized to zero: [2012, 2 marks]
(b) it is on a set of fields that include the primary key
T1 : read (P);
read (Q); (c) the data records of the file are organised in the same
if P = 0 then Q = Q + 1; order as the data entries of the index
write (Q); (d) the data records of the file are organised not in the
T2 : read (Q); same order as the data entries of the index
read (P); 47. Which one of the following is not logically equivalent to
if Q = 0 then P = P + 1; Ø $x ( " y ( a ) Ù " z ( b ) ) ? [2013, 2 Marks]
write (P);
Any non-serial interleaving of T1 and T2 for concurrent (a) "x ( $z ( Øb) ® "y ( a ) )
execution leads to
(a) a serializable schedule (b) "x ( "z ( b ) ® $ y ( Ø a ) )
(b) a schedule that is not conflict serializable
(c) a conflict serializable schedule (c) "x ( "y ( a ) ® $ z ( Ø b ) )
(d) a schedule for which a precedence graph cannot be
(d) "x ( $ y ( Ø a ) ® $ z ( Ø b ) )
drawn
42. Suppose R1 (A, B) and R2 (C, D) are two relation schemas.
48. The line graph L(G) of a simple graph G is defined as
let r1 and r 2 be the corresponding relation instances. B is a
follows:
foreign key that refers to C in R2. If data in r 1 and r2 satisfy
• There is exactly one vertex v(e) in L(G) for each
referential integrity constraints, which of the following is
always true? [2012, 2 marks] edge e in G.
• For any two edges e and e¢ in G, L(G) has an edge
(a) P B ( r1 ) - P C ( r2 ) = Æ between v(e) and v ( e¢ ) , if and only if e and e¢ are
(b) P C ( r2 ) - P B ( r1 ) = Æ incident with the same vertex in G.
Which of the following statements is/are true?
(c) P B ( r1 ) - P C ( r2 ) P. The line graph of a cycle is a cycle.
Q. The line graph of a clique is a clique.
(d) P B ( r1 ) - P C ( r2 ) ¹ Æ R. The line graph of a planar graph is planar.
43. Which of the following is true? [2012, 1 mark] S. The line graph of a tree is a tree.
(a) Every relation in 3NF is also in BCNF [2013, 2 Marks]
(b) A relation R is in 3 NF if every non-prime attribute of R (a) P only (b) P and R only
is fully functionally dependent on every key of R. (c) R only (d) P, Q and S only
(c) Every relation in BCNF is also in 3 NF 49. Consider the relation scheme R = (E, F, G, H, I, J, K, L, M, N)
(d) No relation can be in both BCNF and 3NF and the set of functional dependencies {{E, F} ® {G}, {F}
44. Given the basic ER and relational models, which of the ® {I, J}, {E, H} ® {K, L}, {K} ® {M}, {L} ® {N}} on R.
following is incorrect? [2012, 1 mark] What is the key for R ? [2014, Set-1, 1 Mark]
(a) An attribute of an entity can have more than one value (a) {E, F} (b) {E, F, H}
(b) An attribute of an entity can be composite (c) {E, F, H, K, L} (d) {E}
(c) In a row of a relational table. an attribute can have more 50. Given the following statements:
than one value S1: A foreign key declaration can always be replaced by
(d) In a row of a relational table. an attribute can have an equivalent check assertion in SQL.
exactly one value or a null value S2: Given the table R(a,b,c) where a and b together form
45. Which of the following statements are true about an SQL the primary key, the following is a valid table definition.
query? [2012, 1 mark] CREATE TABLE S (
P. An SQL query can contain HAVING clause even if it a INTEGER,
does not have a GROUP BY clause d INTEGER,
Q. An SQL query can contain HAVING clause only if it e INTEGER,
does not have a GROUP BY clause PRIMARY KEY (d),
FOREIGN KEY (a) references R)
EBD_7203
S3-446 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Which one of the following statements is CORRECT? (a) It executes but does not give the correct result.
[2014, Set-1, 1 Mark] (b) It executes and gives the correct result.
(a) S1 is TRUE and S2 is FALSE. (c) It generates an error because of pairwise comparison.
(b) Both S1 and S2 are TRUE. (d) It generates an error because the GROUP BY clause
(c) S1 is FALSE and S2 is TRUE. cannot be used with table joins in a subquery.
(d) Both S1 and S2 are FALSE. 55. A FAT (file allocation table) based file system is being used
51. Consider the following three statements about link state and the total overhead of each entry in the FAT is 4 bytes in
and distance vector routing protocols, for a large network size. Given a 100 × 106 bytes disk on which the file system is
with 500 network nodes and 4000 links. stored and data block size is 103 bytes, the maximum size of
[S1] The computational overhead in link state protocols is a file that can be stored on this disk in units of 106 bytes is
higher than in distance vector protocols. ____________. [2014, Set-2, 1 Mark]
[S2] A distance vector protocol (with split horizon) avoids 56. The maximum number of superkeys for the relation schema
persistent routing loops, but not a link state protocol. R(E, F, G, H) with E as the key is _____.
[S3] After a topology change, a link state protocol will 57. Given an instance of the STUDENTS relation as shown
converge faster than a distance vector protocol. below : [2014, Set-2, 1 Mark]
Which one of the following is correct about S1, S2, and S3? Student Student
Student Name Student Email CPI
[2014, Set-1, 1 Mark] ID Age
(a) S1, S2, and S3 are all true. 2345 Shankar shankar@math X 9.4
(b) S1, S2, and S3 are all false. 1287 Swati swati@ee 19 9.5
(c) S1 and S2 are true, but S3 is false.
(d) S1 and S3 are true, but S2 is false. 7853 Shankar shnkar@cse 19 9.4
52. Consider the following four schedules due to three 9876 Swati swati@mech 18 9.3
transactions (indicated by the subscript) using read and 8765 Ganesh ganesh@civil 19 8.7
write on a data item x, denoted by r(x) and w(x) respectively. For (StudentName, StudentAge) to be a key for this instance,
Which one of them is conflict serializable? the value X should NOT be equal to _____________ .
[2014, Set-1, 2 Marks] 58. Consider the following schedule S of transactions T1, T2,
(a) r1 (x); r2(x); w1 (x); r3(x); w2(x) T3, T4. [2014, Set-2, 2 Marks]
(b) r2 (x); r1(x); w2 (x); r3(x); w1(x)
(c) r3 (x); r2 (x); r1 (x); w2(x); w1(x) T1 T2 T3 T4
(d) r2 (x); w2(x); r3 (x); r1(x); w1(x) Reads (X)
53. Given the following two statements: Writes (X)
S1: Every table with two single-valued attributes is in 1NF, Commit
2NF, 3NF and BCNF.
Writes (X)
S2: AB ® C, D ® E, E ® C is a minimal cover for the set
Commit
of functional dependencies AB ® C, D ® E, AB ® E,
Writes (Y)
E ® C.
Reads (Z)
Which one of the following is CORRECT?
[2014, Set-1, 2 Marks] Commit
(a) S1 is TRUE and S2 is FALSE. Reads (X)
(b) Both S1 and S2 are TRUE. Reads (Y)
(c) S1 is FALSE and S2 is TRUE. Commit
(d) Both S1 and S2 are FALSE. Which one of the following statements is CORRECT?
54. Given the following schema: (a) S is conflict-serializable but not recoverable
employees (emp-id, first-name, last-name, hire-date, dept- (b) S is not conflict-serializable but is recoverable
id, salary) (c) S is both conflict-serializable and recoverable
departments (dept-id, dept-name, manager-id, location-id) (d) S is neither conflict-serializable nor is it recoverable
You want to display the last names and hire dates of all 59. Consider a join (relation algebra) between relations r (R)and
latest hires in their respective departments in the location s (S) using the nested loop method. There are 3 buffers each
ID 1700. You issue the following query: of size equal to disk block size, out of which one buffer is
SQL > SELECT last-name, hire-date reserved for intermediate results. Assuming size
FROM employees (r (R))<size(s (S)), the join will have fewer number of disk
block accesses if [2014, Set-2, 2 Marks]
WHERE (dept-id, hire-date) IN
(a) relation r (R) is in the outer loop.
(SELECT dept-id, MAX (hire-date)
(b) relation s (S) is in the outer loop.
FROM employees JOIN departments USING (dept-id)
(c) join selection factor between r (R) and s (S) is more
WHERE location-id = 1700
than 0.5.
GROUP BY dept-id),
(d) join selection factor between r (R) and s (S) is less
What is the outcome? [2014, Set-1, 2 Marks] than 0.5.
DATABASES S3-447
60. Consider the procedure below for the Producer-Consumer w1(X); w1(Z)
problem which uses semaphores: [2014, Set-2, 2 Marks] S2: r1(X); r3(Y); r2(Y); r3(X); r1(Z); r2(Z); w3(Y); w1(X);
semaphore n = 0; w2(Z); w1(Z)
semaphore s = 1; Which one of the following statements about the schedules
void producer() void consumer() is TRUE?
{ { (a) Only S1 is conflict-serializable.
while(true) while(true) (b) Only S2 is conflict-serializable.
{ { (c) Both S1 and S2 are conflict-serializable.
produce(); semWait(s); (d) Neither S1 nor S2 is conflict-serializable.
semWait(s); semWait(n); 65. Consider the relational schema given below, where eId of
addToBuffer(); removeFromBuffer();
the relation dependent is a foreign key referring to empId of
semSignal(s); semSignal(s);
the relation employee. Assume that every employee has at
semSignal(n); consume();
least one associated dependent in the dependent relation.
} }
} } employee (empId, empName, empAge)
Which one of the following is TRUE? dependent(depId, eId, depName, depAge) Consider the
(a) The producer will be able to add an item to the buffer, following relational algebra query:
but the consumer can never consume it. P empId (employee)- P empId (employee|X|(empId = eID)^.(empAge .
(b) The consumer will remove no more than one item from
dependent)
the buffer. depAge)
The above query evaluates to the set of empIds of
(c) Deadlock occurs if the consumer succeeds in acquiring
employees whose age is greater than that of
semaphore s when the buffer is empty.
(d) The starting value for the semaphore n must be 1 and [2014, Set-3, 2 Marks]
not 0 for deadlock-free operation. (a) some dependent.
61. SQL allows duplicate tuples in relations, and (b) all dependents.
correspondingly defines the multiplicity of tuples in the (c) some of his/her dependents.
result of joins. Which one of the following queries always (d) all of his/her dependents.
gives the same answer as the nested query shown below: 66. A system contains three programs and each requires three
select * from R where a in (select S.a from S) tape units for its operation. The minimum number of tape
[2014, Set-2, 2 Marks] units which the system must have such that deadlocks never
(a) select R.* from R, S where R.a=S.a arise is _________. [2014, Set-3, 2 Marks]
(b) select distinct R.* from R, S where R.a = S.a 67. Consider the following relational schema:
(c) select R.* from R, (select distinct a from S) as S1 where employee (empId,empName,empDept)
R.a = S1.a customer(custId,custName,salesRepId,rating)
(d) select R.* from R,S where R.a=S.a and is unique R
62. What is the optimized version of the relation algebra salesRepId is a foreign key referring to empId of the
expression p A1 (p A2 (s F1 (s F 2 (r )))) , where A1, A2 are sets employee relation. Assume that each employee makes a sale
of attributes in r with A1 Ì A2 and F1, F2 are Boolean to at least one customer. What does the following query
expressions based on the attributes in r ? return?
[2014, Set-3, 1 Mark] SELECT empName
FROM employee E
(a) p A1(s( F1ÙF 2) (r )) (b) p A1(s( F1Ú F 2) ( r ))
WHERE NOT EXISTS (SELECT custId
(c) p A2 (s( F1ÙF 2) (r )) (d) p A2 (s( F1Ú F 2) (r )) FROM customer C
WHERE C. salesRepId =
63. A prime attribute of a relation scheme R is an attribute that
appears [2014, Set-3, 1 Mark] E.empId
(a) in all candidate keys of R. AND C.rating < > ‘GOOD’);
(b) in some candidate key of R. [2014, Set-3, 2 Marks]
(c) in a foreign key of R. (a) Names of all the employees with at least one of their
(d) only in the primary key of R. customers having a ‘GOOD’ rating.
64. 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.
EBD_7203
S3-448 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. If every non-key attribute is functionally dependent on the 7. Manager’s salary details are hidden from the employee. This
primary key, then the relation will be in is
(a) first normal from (b) second normal form (a) Con-ceptual level data hiding
(c) third normal form (d) fourth normal form (b) physical level data hiding
2. What are the potential problems when a DBMS executes (c) external level data hiding
multiple transactions concurrently? (d) none of the above
1. The lost update problem 8. Assume transaction A holds a shared lock R. If transaction
2. The dirty read problem B also requests for a shared lock on R, it will
3. The unrepealable read problem
(a) result in a deadlock situation
4. The phantom problem.
(b) immediately be granted
(a) 3 and 4 only (b) 1, 2 and 4 only
(c) immediately be rejected
(c) 2 and 3 only (d) All of 1,2, 3 and 4
(d) be granted as soon as it is released by A
3. In airline reservation system, the entities are date, flight
9. A specific example where physical data independence would
number, place of departure, destination, type of plane and
seats available. The primary key is not hold is
(a) flight number (a) when data file is changed from an unordered file to a
(b) flight number + place departure sorted file.
(c) flight number + date (b) when an additional access structure, (example, an index)
(d) flight number + destination is created for a relation.
4. For a database relation R(a, b, c, d) where the domains of a, b, (c) when DBA decides to store the data in a B+ tree.
c and d include only atomic values, only the following (d) when the user writes an application program to join
functional dependencies and those that can be inferred from tables.
them hold. 10. Data independency in DBMS is known as
a®c (a) Data modeling (b) Data hiding
b®d (c) Data capturing (d) Data consistency
The relation is in 11. A data dictionary doesn’t provide information about
(a) first normal form but not in second normal form (a) where data is located
(b) second normal form but not in third normal form (b) the size of the disk storage disk
(c) third normal form (c) who owns or is responsible for the data
(d) none of the above (d) how the data is used
5. E-R modeling technique is a
12. The database administrator is, in effect, the coordinator
(a) top-down approach
between the ________ and the________.
(b) bottom-up approach
(a) DBMS; database
(c) left-right approach
(b) application program; database
(d) both top-down and bottom-up
(c) database, users
6. Choose the correct statement.
(a) Network models are complicated by physical keys, but (d) application programs; users
the relational model is faster because it uses logical 13. What does the data dictionary identify?
keys. (a) Field names (b) Field types
(b) Network models are complicated by logical keys, but (c) Field formates (d) All of the above
the relational model is faster because it uses physical 14. Which is one function of a database management system
keys. (DBMS)?
(c) Network model are complicated by logical keys, but the (a) Ensuring usability
relational model is slower because it uses physical keys. (b) Identifying what a user needs
(d) Network model are complicated by physical keys but (c) Deciding what to do with legacy systems
the relational model is slower because it uses logical (d) Preventing errors arising, while enabling multiple,
keys. simultaneous users
DATABASES S3-449
15. Consider the following DAG, the corresponding three 18. For relation R(A, B, C, D, E, F) the set of FDs is
address code for the same is (A ® C, B ® D, C ® E, D® E, E ® A, F ® B)
Assign What is the candidate key for R-
(a) A (b) C
(c) D (d) F
a + 19. A relation (from the relational database model) consists of a
set of tuples, which implies that
* (a) relational model supports multi-valued attributes whose
values can be represented in sets.
(b) for any two tuples, the values associated with all of
b uminus their attributes may be the same.
(c) for any two tuples, the value associated with one or
(a)t1 : = – c c more of their attributes must differ.
t2 : b * t1 (d) all tuples in particular relation may have different
t5 : = t2 + t2 attributes.
a : = t5 20. Which of the following statements is correct with respect to
(b) t1 : = – c entity integrity?
t2 : b * t1 (a) Entity integrity constraints specify that primary key
t5 : t2 + t1 values can be composite.
a : t5
(b) Entity integrity constraints are specified on individual
(c) t1 : – c
relations.
t2 : = t1 * b
(c) Entity integrity constraints are specified between weak
t5 : = t1 + t2
entities.
a = a5
(d) When entity integrity rules are enforced, a tuple in one
(d) None of the above
relation that refers to another relation must refer to an
16. Consider the following Entity Relationship Diagram (ERD).
existing tuple.
QualifiedDate
21. Consider a banking database with the following table with
three attributes loans (br_name, loan_no, amount).
Find the appropriate query for the given statement below.
PERSON
M QUALIFICATION N EXAM
“Find the loan number for each loan of an amount greater
than 20000”
Name NID ExamID ExamName (a) {t | t Î loans ^ t [amount] > 20000} where ‘t’ is a tuple
(b) {t | $ s Î loans (t [loan_no] = S[loan_no] ^ [amount] >
Which of the following possible relations will not hold if the 20000}
above ERD is mapped into a relation model? (c) {t | " s Î loans (t [loan_no] = S[loan_no] ^ [amount] >
(a) Person (NID, Name) 20000}
(b) Qualification (NID, ExamID, Qualified Date) (d) None of the above
(c) Exam (ExamID, NID, ExamName) 22. Let R (a, b, c) and S (d, e, f) be two relations in which d is the
(d) Exam (ExamID, ExamName) foreign key of S that refers to the primary key of R. Consider
17. The following diagram represents the dependent entity from
the following four operations R and S.
an Entity Relationship Diagram.
(a) Insert into R (b) Insert into S
(c) Delete from R (d) Delete from S
Name Age 23. Let r and s be two relations over the relation schemes R and
S respectively and let A be an attribute in R. Then the
DEPENDENT relational algebra expression sA=a (r s) is always equal to
Address (a) sA=a (r) (b) r
Gender (c) sA=a (r) s (d) None of the above
BirthDate 24. Which of the following is wrong ?
Relationship
(a) pL1ÈL2 (E1 q (
E2) = pL1 ( E1 ) ) q ( pL
1
( E2 ) )
Select the characteristics which are not represented by the
above diagram. (b) sP ( E1 - E2 ) = sP ( E1 ) - E 2
(a) BirthDate is a derived attribute.
(b) Gender is an atomic attribute. (c) (
sq1 ^ q2 ( E ) = sq1 sq2 ( E ) )
(c) Address is a multi valued attribute.
(d) Name is a key attribute. (d) E1 q E2 = E 2 q1 E 1
EBD_7203
S3-450 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
25. Which of the following statements concerning relational (a) (i) and (ii) (b) (ii) and (iii)
database is true? (c) (i) and (iii) (d) (i), (ii) and (iii)
(a) A foreign key field may be null. 31. Consider a schema R (A, B, C, D) and functional depedencies
(b) A primary key field may be null A ® B and C ® D. Then the decomposition of R into
(c) All relations must be in at least third normal form R1 (AB) and R2 (CD) is
(d) The primary key fields of a relation must be adjacent (a) dependency preserving and lossless join
26. Select the relational expression which could possibly return (b) lossless join but not dependency preserving
the following result. (c) dependency preserving but not lossless join
a c (d) not dependency preserving and not lossless join
32. Match the following
1 2
2 3
rh,x,m(Student))
Manager Engineer Secretary (a) names of girl students with the higher marks
(b) names of girl students with more marks than some boy
Choose the best design
student
(a) 1, 4, 6 and 8 (b) 1, 4 and 7
(c) names of girl students with marks not less than some
(c) 1, 3, 5, 6 and 8 (d) 2, 5 and 8
62. Consider the following entity relationship diagram (ERD), boy student
where two entities E1 and E2 have a relation R of cardinality (d) names of girl students with more marks than all the boy
1: m, students
68. Consider a selection of the form SA<100(r), where r is a relation
1 m with 1000 tuples. Assume that the attribute values for A
E1 R E2
among the tuples are uniformly distributed in the interval
[0, 500]. Which one of the following options is the best
The attributes of E1 are A11, A12 and A13 where A11 is key estimate of the number of tuples returned by the given
attribute. The attributes of E2 are A21, A22, and A23 where
selection query?
A21 is the key attribute and A23 is a multi-valued attribute.
Relation R does not have any attribute. A relational database (a) 50 (b) 100
containing minimum number of tables with each table (c) 150 (d) 200
satisfying the requirements of the third normal form (3NF) is 69. Consider the following relation schemas:
designed from the above ERD. The number of tables in the b-Schema = (b-name, b-city, asssets)
database is a-Schema = (a-num, b-name, bal)
(a) 2 (b) 3 d-Schema = (c-name, a-number)
(c) 5 (d) 4 Let branch, account depositor be respectively instance of
63. Which of the following query transformation (i.e. replacing the above schemas. Assume that account and depositor
the LHS expression by the RHS expression) is incorrect? relations are much bigger than the branch relation.
R1 and R2 are relations, C1, C2 are selection conditions and Consisder the following query:
A1, A2 are attributes of R1. P c-name(sb-city= “Agra”A bal<0 (branch (account
(a) ( )
pA 2 sC1 ( R1 ) ® sC1 p A 2 ( R1 ) ( ) depositor)))
Which one of the following quries is the most efficient
(b) s C1 (pA 1
( R1 )) ® p A1 ( s C1 ( R1 ) ) version of the above query?
(a) Pc-name(sbal < 0(sb-city= “Agra”branch (account
(c) sC1 ( R1 È R 2 ) ® s C1 ( R1 ) È s C1 ( R 2 ) depositor)
(b) Pc-name(sb-city= “Agra”branch (sbal<0account
(d) ( )
sC1 sC1 ( R1 ) ® sC2 sC 2 ( R 2 ) ( ) depositor))
64. With the help of which of the following relations operation (c) P c - n a m e ( s b - c i t y = “ A g r a ” b r a n c h s b - ci t y =
set we can perform division on relations? “Agra”Dbal<0 account depositor)
(a) {p, x(mul), –} (b) {s, x(mul), –} (d) P c - n a m e ( s b - c i t y = “ A g r a ” b r a n c h ( s b-cit y=
(c) {x(mul), –} (d) {x(mul)} “Agra”Dbal<0 account depositor))
EBD_7203
S3-454 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
70. R (A, B, C, D) with FD’s CD ® E;
F (A ® B, A ® C, A ® D) and B ® D;
R1 (A, B, D) with FD’s E ® A}
F1 (A ® B, A ® D) and then candidate keys for R is_______
R2 (B, C) with FD’s (a) A, B (b) A, B, C
F2 = ({}) (c) A, E, CD (d) A, B, D
then find which statements is true: 75. A given relation is known to be in third normal form. Select
(a) This is not dependency-preserving relation the statement which can be interred from this.
(b) This is dependency-preserving relation (a) All attributes contributes to the primary key
(c) This is partially dependency preserving relation (b) Each non-key attribute determine the primary key
(d) This is non-descomposable relation with full (c) Each non-key attribute is determine by the primary key
dependency preserving. (d) Every determinant is a candidate key
71. R = (A, B, C, D, E, F) 76. Consider a relation R with five attributes V, W, X, Y and Z.
R1 = (A, B) The following functional dependencies hold: VY ® W,
R2 = (C, D, E) WX ® Z, and ZY ® V. Which of the following is a
R3 = (A, C, F) candidates key for R?
(a) VXZ (b) VXY
F = {A ® B;
(c) VWXY (d) VWXYZ
C ® DE;
77. Consider the following functional dependencies
A ® C F; }
{a, b ® c, d;
Does the above FD’s has lossless join properly?
a, c ® b, d}
(a) Yes (b) No
Which of the following relation schemas might be the result
(c) Data insufficient (d) Cannot be determine
of normalising R (a, b, c, d)?
72. Which of the following list repersents the MVDs (Mean Value
(a) The schema R1 (a, b, c) R2 (a, b, d)
Dependencies) satisfied by a relation R(A, B, C) that has the
(b) The schema R1 (a, b) R2 (a, c) R3 (b, d)
following tuples: (a1, b1, c1), (a1, b1, c2), (a2, b1, c1, (a2, b1, c3). (c) The schema R1 (a, b) R2 (b, c) R3 (c)
(a) A ® ® B, B ® ® C, A ® ® BC, AB ® ® C, (d) The schema R (a, b, c, d)
AC ® ® B, B ® ® AC, BC ® ® A, C ® ® AB 78. Consider the following database and answer the questions
(b) A ® ® B, A ® ® C, A ® ® BC, AB ® ® C, as below
AC ® ® B, B ® ® AC, BC ® ® A, C ® ® AB Student
(c) B ® ® A, A ® ® C, A ® ® BC, AB ® ® C,
AC ® ® B, B ® ® AC, BC ® ® A, C ® ® AB S# SNAME STATUS CITY
(d) None of othe above S1 Smith 20 London
73. From the following instance of a relation schema R (A, B, C)
S2 John 10 Paris
we can conclude that:
S3 Clark 20 London
A B C PART
1 1 1
1 1 0 P # PNAME COLOR WEIGHT CITY
2 3 2 P1 Nut Re d 12 London
2 3 2 P2 Bolt Green 17 Paris
P3 Screw Blue 17 Rome
(a)A functionally determines B and B functionally
Project
determines C
(b) A functionally determines B and B does not functionally J # JNAME CITY
determine C
J1 Sorter Paris
(c) A does not functionally determine C
(d) All of the above are correct J2 Display Rome
74. Consider the following declaration: 1. UPDATE project J1, set CITY to New York.
F : set of functional depedencies 2. UPDATE part P3, set P# to P4
R : relation of functional dependencies Are the above quaries accepted or rejected?
R : (A, B, C, D, E) (a) Accept, Accept (b) Reject, Accept
F : {A ® BC; (c) Accept, Reject (d) Reject, Reject
DATABASES S3-455
79. The following table gives details of employees in a company 82. There are two relations X and Y, Relation X has arity 1 and
department cardinality 2, relation Y has arity 3 and cardinality 4. Indicate
Emp _ ID Job Salary Des _ ID the result of the SQL statement SELECT COUNT (*) FROM
X, Y.
110 Designing 25000 SW
(a) 4
115 Calibrating 19000 QA (b) 6
120 Programming 26000 SW (c) 8
135 QualityAssuring 18000 QA (d) Can not be calculated from given information
150 Consulting 45000 CO 83. Which of the following concurrency control protocol ensures
both conflict serializability and freedom from deadlock?
168 Consulting 35000 CO
(i) 2 phase locking (ii) Time stamp ordering
188 Analysis and Design 22000 SW (a) (i) only (b) (i) and (ii)
Which of the following SQL statement gives the average (c) (ii) only (d) None of the above
Salary for each designation ID (Des_ID)? 84. Consider the relation enrolled (student, course) in which
(a) SELECT AVG (Salary) FROM Employee (student, course) is the primary key, and the relation paid
(b) SELECT Des_ID, AVG (Salary) FROM Employee (student, amount) where student is the primary key. Assume
ORDER BY Des_ID no null values and no foreign keys or integrity constraints.
(c) SELECT Des_ID, Salary FORM Employee GROUP BY Assume that amounts 6000, 7000, 8000, 9000 and 10000 were
Des_ID each paid by 20% of the students. Considet these query
(d) SELECT Des_ID, AVG (Salary FROM Employee GROUP plans (Plan 1 on left, Plan 2 on right) to “list all courses taken
BY Des_ID) by students who have paid more than x,”
80. Consider the relations, Enrolled Paid Enrolled Paid
Supplier (S_no, S_name, city) and
Item (Item _ no, name, Item_Brand, S_no) Probe index Sequential Probe index Sequential
Which of the following SQL statement gives suppliers names on student scan, select on student scan
who have submitted at least one ‘Nestle’ brand item? amount > x
(a) SELECT S_name FROM Supplier S Item I WHERE I
( Item_Brand = Nestle) Indexed nested loop join Indexed nested loop join
(b) SELECT S_name FROM Supplier S WHERE S_no IN
(SELECT S_no From Item WHERE Item_Brand = Nestle) Project on course Select on amount > x
(c) SELECT S_name FROM Supplier S WHERE Item_Brand
= Nestle)
(d) SELECT S_name FROM Supplier WHERE S_no Project on course
EXISTS (SELECT S_no From Item WHERE Item_Brand
= Nestle) A disk seek takes 4 ms, disk data transfer bandwidth is 300
81. Consider the following employee table. MB/s and checking a tuple to see it amount is greater than
x takes 10 ms. Which of the following statements is correct?
E _ No Job Salary Dept _ No
(a) Plan 1 and 2 will not output identical row sets for all
178 System Analyst 25000 10 database
179 Software Engineer 30000 10 (b) A course may be listed more than once in the output of
180 QualityAssurer 21000 20 Plan 1 for some database
(c) For x = 5000, Plan 1 executes faster than Plan 2 for all
181 Technical Writer 17000 30
database
Associate (d) For x = 9000, Plan 1 executes slower than Plan 2 for all
182 20000 10
Software Engineer database
Which of the following statements gives the list of 85. Consider the table employee (empId, name, department,
departments having average salary greater than 20000 from salary) and the two queries Q1, Q2 below. Assuming that
employee table? department 5 has more than one employee, and we want to
(a) SELECT Dept_No, AVG (Salary) FROM Employee find the employees who get higher salary than anyone in the
ORDER BY Dept_No HAVING AVG (Salary > 20000 department 5, which one of the statements is TRUE for any
(b) SELECT Dept_No, AVG (Salary) FROM Employee arbitrary employee table?
HAVING AVG (Salary > 20000 Q1 : Select e. empID
(c) SELECT Dept_No, AVG (Salary) FROM Employee From employee e
GROUP BY Dept_No HAVING AVG (Salary > 20000 Where not exists
(d) SELECT Dept_No, AVG (Salary) FROM Employee (Select * From employee s Where s department = “5”
WHERE AVG (Salary > 20000 and s.salary > = e.salary)
EBD_7203
S3-456 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Q2 : Select empId 89. Which of the following relational calculus expressions is
From employee e not safe?
Where e. salary > Any
(Select distinct salary From employee s Where s,
(a) {r | $u Î R1 (t[ A]) = u[ A] $ Ø$s Î R2 (t[ A] = s[ A])}
department = “5”) (b) {r | "u Î R1(u[ A]) = " x " Þ $s Î R2 (t[ A]
(a) Q1 is the correct query
(b) Q2 is the correct query = s[ A]$ s[ A] = u[ A]))} ]
(c) Both Q1 and Q2 produce the same answer
(d) Neither Q1 nor Q2 is the correct query
(c) {t | Ø(t Î R1)}
86. An athlectics meeting involves several competitors who (d) {t | $u Î R1 (t[ A] = u[ A]$ $s Î R2 9t[ A] = s[ A])}
participate in a number of events. The database is intended
to record who is to take part in which event and to record the 90. Relation R with an associated set of functional
outcome of each event. As results become available the dependencies, F, is decomposed into BCNF. The
winner attribute will be updated with cid of the appropriate redundancy (arising out of functional dependencies) in the
competitor. resulting set of relations is.
Competitor (cid, name nationality) (a) Zero
Even (eid, description) (b) More than zero but less than that of an equivalent
Competes (cid, eid) 3NF decomposition
(c) Proportional to the size of F+
Cometitor (d) Indetermined
cid name nationality 91. AB+-tree index is to be built on the Name attribute of the
01 Pat British relation STUDENT . Assume that all student names are of
02 H ilary British length 8 bytes, disk blocks are of size 512 bytes, and index
03 Sven Swedish
pointers are of size 4 bytes. Given this scenario, what
04 Pierre French
would be the best choice of the degree (i.e. the number of
pointers per node) of the B+-tree ?
Competes (a) 16 (b) 42
Event cid eid (C) 43 (d) 44
eid Descript ion 01 01 92. From the following instance of relation schema R(A,B,C),
01 running 02 01 we can
02 j umping 03 02
conclude that :
03 t hrowing 04 02
04 03
A B C
Identify the result of the following SQL statement. 1 1 1
SELECT eid FROM Competes, Competitor
1 1 0
WHERE Competes. cid = Competitor, cid
AND nationality = ‘Swedish’; 2 3 2
(a) 0 1 (b) 0 2 2 3 2
(c) 04 (d) 0 3
87. Consider a schema R(A,B,C,D) and functional dependencies (a) A functionally determines B and B functionally
A – ® Band C ® D. Then the decomposition of R intoR1(AB) determines C
and R2(CD)is (b) A functionally determines B and B does not
(a) Dependency preserving and lossless join functionally determines C .
(b) Lossless join but not dependency preserving (c) B does not functionally determines C
(d) A does not functionally B and B does not functionally
(c) Dependency preserving but not lossless join
determines.
(d) Not dependency preserving and not lossless join
93. Which of the following scenarios may lead to an
88. Suppose the adjacency relation of vertices in a graph is
irrecoverable error in a database system?
represented in a table Adj (X,Y). Which of the following
(a) A transaction writes a data item after it is read by an
queries cannot be expressed by a relational algebra uncommitted transaction
expression of constant length ? (b) A transaction read a data item after it is read by an
(a) List all vertices adjacent to a given vertex. uncommitted transaction
(b) List all vertices which have self loops (c) A transaction read a data item after it is written by
(c) List all vertices which belong to cycles of less than an committed transaction
three vertices (d) A transaction read a data item after it is written by
(d) List all vertices reachable from a given vertex an uncommitted transaction
DATABASES S3-457
94. Consider the following functional dependencies in a (c) the average salary of male employees is more than
database: the average salary of employees in the same
Data_of_Birth ® Age Age ® Eligibility department
Name ® Roll_number Roll_number ® Name (d) the average salary of made employees is more than
Course_number ® Course_name Course_number ® the average salary in the company
Instructor (Roll_number, Course_number) ® Grade 98. The following table has two attributes A and C where A
The relation (Roll) number, Name, Date_of_birth, Age) is is the primary key and C is the foreign key referencing A
(a) in second normal normal form but not in third normal with on-delete cascade
form
(b) in third normal form but not in BCNF A C
(c) in BCNF 2 4
(d) in none of the above
3 4
95. Consider a relation geq which represents “greater than or
4 3
equal to”, that is, (x,y) ! geq only if y # x:
5 2
Create table gaq
(Ib integer not null 7 2
ub integer not null 9 5
primary key Ib 6 4
foreign key (ub) references geq on delete cascade):
Which of the following is possible if a tuple (x,y) is deleted ? The set of all tuples that must be additionally deleted to
(a) A tuple (z,w) with z >y is deleted preserve referential integrity when the tuple (2,4) is deleted
(b) A tuple (z,w) with z >x is deleted is:
(c) A tuple (z,w) with w <x is deleted (a) (3,4) and (6,4) (b) (5,2) and (7,2)
(d) The deletion of (x,y) is prohibited (c) (5,2)(7,2) and (9,5) (d) 1
96. It is desired to design an object-oriented employee record 99. The relation book (title, price) contains the titles and prices
system for a company. Each employee has a name, unique of different books. Assuming that no two books have the
id and salary. Employees belong to different categories same price, what does the following SQL
and their salary is determined by their category. The
select title
functions get Name., getld and compute Salary are
required. Given the class hierarchy below, possible locations from book as B
for these functions are: where (select count(*)
(i) getld is implemented in the superclass from book as T
(ii) getld is implemented in the suclass where T. price>B.Price)<5
(iii) getName is an abstract function in the superclass (a) Titles of the four most expensive books
(iv) getName is implemented in the superclass (b) Title of the fifth most inexpensive book
(v) getName is implemented in the subclass (c) Title of the fifth most expensive book
(vi) getSalary is an abstract function in the superclass (d) Titles of the five most expensive books
(vii) getSalary is implemented in the superclass
100. Consider a banking database with the following table with
(viii) getSalary is implemented in the subclass
Choose the best design three attributes loans (br_name, loan_no, amount)
(A) (i),(iv),(vi),(viii) (B) (i),(iv),(vii) Find the appropriate query for the given statements below.
(C) (i),(iii),(v),(vi),(viii) (D) (ii),(v),(viii) Find the loan number for each loan of an amount greater
97. The employee information in a company is stored in the than 20000
relation (a) {t | t Î loans Ç t [amount] > 20000] where, t is a tuple
Employee (name, sex, salary, deptName) (b) {t | $ S Î loans (t [loan_no] = S [loan_no] Ç [amount]
Consider the following SQL query > 20000)}
select deptname
(c) {t | " S Î loans (t [loan_no] = S [loan_no] Ç
from Employee
[amount > 20000}
where sex=‘M’
group by deptName (d) None of the above
having avg (salary)> 101. Let R (a, b, c) and S(d, e, f) be two relations in which d
(select avg(salary)from Employee) is the foreign key of S that refers to the primary key of R.
It returns the names of the department in which Consider the following four operations R and S :
(a) the average salary is more than the average salary in 1. Insert into R
the company 2. Insert into S
(b) the average salary of male employees is more than 3. Delete from R
the average salary of all male employees in the
4. Delete from S
company
EBD_7203
S3-458 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Which of the following is true about the referential Which of the following possible relation will not hold, if
integrity constraint above? the above ERD is mapped into a relation model?
(a) None of 1, 2, 3 or 4 can cause its violation (a) Person (NID, Name)
(b) All of 1, 2, 3 and 4 cna cause its viole (b) Qualification (NID, Exam_ID, Qualification)
102. Relation R has attributes ABCDEFGHIJ and satisfies FDs (c) Exam (Exam ID, NID, Exam_name)
ABD ® E (d) Exam (Exam ID, Exam_name)
C ® J 108. The following diagram represents the dependent entity
AB ® G from an entity relationship diagram :
CI ® I
Name Age
B ® F
G ® HI
Find candidate key. Dependent
Gender
(a) A, B, C, I (b) A, B, C, D, G
(c) A, B, C, D, E (d) A, B, C, D
103. For the given relation instance, the best normal form is
Birth date Relationship Address
ABCDE F
Select the characteristics which are not represented by the
above diagram.
(a) Birth date is a derived attribute
(b) Gender is an atomic attribute
(a) 1 NF (b) 2 NF (c) Address is a multi valued attribute
(c) 3 NF (d) BCNF (d) Name is a key attribute
104. Consider a relation schema R1 = {N, R, C, T, Z) on 109. For relation R (A, B, C, D, E, F) the set of FDs is
which of the following functional dependencies hold {A ® C, B ® D, C ® E, D ® E, F ® A, F ® B}
{N ® RCT, RCT ® Z, Z ® CT}, then what is/are the What is the candidate key for R?
candidate keys of R1? (a) A (b) C
(a) N (b) R (c) D (d) F
(c) Z, N (d) C, T 110. What are the potential problems when a DBMS executes
105. A relation (from the relational database model) consists of multiple transactions concurrently?
a set of tuples, which implies that 1. The lost update problem
(a) relational model supports multi values attributes 2. The dirty read problem
whose values can be represented in sets 3. The unrepeatable read problem
(b) for any two tuples, the values associated with all of 4. The phantom problem
their attributes may be the same (a) 3 and 4 (b) 1, 2 and 4
(c) for any two tuples, the value associated with one or (c) 2 and 3 (d) All of these
more of their attributes must differ
(d) all tuples in a particular relation may have different NUMERICAL TYPE QUESTIONS
attributes 111. An employee record has the following structure
106. Select the correct statement from the following on referential struct employee {
integrity. int eno;
(a) Referential integrity constraints check whether the char name[22];
primary key values are unique float salary;
(b) Referential integrity constraints are specified between char dept[10];};
two relations in a scheme Enter the record size R in bytes. Enter the value.
(c) Referential integrity constraints check whether an 112. In the above structure If the file has 500 records, calculate
attribute value lies in the given range the blocking factor bfr and the number of blocks b,
(d) Referential integrity constraints are specified between assuming an unspanned organization with block size B =
entities having recursive relationships 512 bytes. Enter the value (Can be in decimal points also).
107. Consider the following entity relationship diagram : 113. What is the unused space in each block in the above
organization. Enter the value in bytes.
Qualified date 114. In the above organization enter the Unused space in the
last block. Enter the value in bytes.
M N 115. The order of an internal node in a B+ tree index is the
Person Qualification Exax
maximum number of children it can have. Suppose that a
child pointer takes 6 bytes, the search filed value takes 14
Name NID Exam_id Exam_name bytes, and the bloc size is 512 bytes. What is the order of
the internal node ? Enter a whole number value.
DATABASES S3-459
116. The order of an internal node in a B+ tree index is the Common data for Questions No. 123 and 124 :
maximum number of children it can have. Suppose that a Consider a relation R = (A, B, C, D, E, F, G) satisfies following
child pointer takes 6 bytes, the search field value takes 14 functional dependencies (A ® B, BC ® DBC ® |E|, AEF ® G}
bytes, and the block size is 512 bytes. Waht is the order 123. What will be the closure of {A, C}+?
of the internal node?
(a) {A, B, C} (d) {A, B, C, D, E}
117. A B+ tree index is to be built on the Name attributes of the
(c) {C, D, E, F, G} (d) {A, B, E, F, G}
relation STUDENT. Assume that all student names are of
length 8 byte, disk blocks are of size 512 byte and index 124. Which of the following functional dependency implies this
pointers are of size 4 bytes. Given this scenario, what set?
would be the best choice of the degree (i.e., the number (a) ACF ® DG (b) DG ® ACF
of pointers per node) of the B+ tree? (c) F ® DGE (d) F ® A
118. Consider a selection fo the form SAS100 (r), where r is a Common Data for Questions 125, 126, 127 and 128
relation with 1000 tuples. Assume that the attribute values Branch-scheme = (Branch - name, assets, branch-city).
for A among the tuples are uniformly distributed in the Customer-scheme = (Customer-name, street, customer-city)
interval [0,500]. Which one of the following options is the Deposit-Scheme = (Branch-name, account-number, customer-
best estimate of the number of tuples returned by the name, balance)
given selection query?
Borrow-scheme = (Branch-name, load-number, customer-name,
119. The minimum numbers of table needed to represent
amount)
M, N, P, R1, R2 is
Client-scheme = (customer-name, banker-name)
125. Using relational algebra, the query that finds customers who
M1 M2 M3 P1 P2 N1 N2 have a balance of over 1000 is
(a) pcustomer_name (sbalance > 1000 (Deposite))
(b) scustomer_name (pbalance > 1000 (Deposite))
(c) pcustomer_name (sbalance > 1000 (borrow))
R1 R2 (d) scustomer_name (pbalance > 1000 (borrow))
M P N
126. Which of the following quries finds the clients of banker
Agassi and the city they live in?
120. Consider the following Entity Relationship Diagram (ERD), (1) pclient,Customer_name.customer_City (s client.Customer.
where two entries E1 and E2 have a relation R of cardinality name = Customer. Customer_name (sBanker-name = “Agassi”
(Client ×Customer))
1:m
(2) pcustomer name.Customer.Customer_City
m (sBanker-name = “Agassi” (Client ×Customer))
E1 1 R E2 (3) pclient,Customer_name.customer_City
(s Banker-name = “Agassi” (s client.Customer.name =
The attributes of E1 are A11 and A13, where A11 is key
Customer.
attribute. The attributes of E2 are A21, A22 and A23, where, Customer_name (Client ×Customer))
A21 is the key attribute and A23 is a multivalued attribute. (4) pCustomer_name.customer_City(s Banker-name = “Agassi”
Relation R does not have any attribute. A relational (Client ×Customer))
database containing minimum number of tables with each (a) 1 and 3
table satisfying the requirements of the third normal form (b) 2 and 3
(3 NF) is designed from the above ERD. The number of (c) 1 and 4
(d) None of these
tables in the database is
127. Which of the following tuple relational calculus finds all
Common Data Linked Answer Type Questions 121 and 122: customers who have a loan amount of more than 1200?
Entity set TRANSACTION has the attributes transaction number, (a) (t (Customer_name) |t eborrow A t [amount] > 1200}
date, amount, Entity set ACCOUNT has the attributes account (b) (t | t(Customer_name) eborrow A t [amount] > 1200}
number, customer name, balance. (c) (t | $ s eborrow A s [amount] > 1200}(t [Customer_name)
121. Which is the discriminator of the weak entity ? = s [Customer_name]
(a) Account number (b) Transaction number (d) None of the above
(c) {account number, date} (d) date 128. Which of the following Domain relational calculus finds all
122. Which is the primary key of the weak entity? customers who have a loan amount of over 1200?
(a) Account number (a) {<C>| $ b, 1, a (< b, 1, c, a > a > e borrow V a > 1200)}
(b) {Account number, transaction number} (b) {<C>| $ b, 1, a (< b, 1, c, a > a > e borrow A a > 1200)}
(c) {Account number, date} (c) {<C>| $ <b, 1, c, a > e borrow A a > 1200)}
(d) {Transaction number, date} (d) {<C>| b, 1, c, a > e borrow A a > 1200)}
EBD_7203
S3-460 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
cycles.
T1 R1x W1x W1y
Here, we can see that S1 and S4 are not conflict
S1 serializable but S2 and S3 are conflict serializable.
T2 R2x R2y W2x 30. (a) B ® A where R (A, B, C) and S (B, D, E), A ® C
T1 R2x W1x 31. (a) The solution can be obtained by checking with all the
W1y
S3 available options.
The correct serialization is T1 ® T3 ® T2.
T2 R2x R2y W2x This will result in same result as in the given schedule
and will not conflict in read write operation of same
data items.
T1 R1x W1x W1y
S4 32. (b) Time stamp ordering ensures both conflict serializability
and freedom from deadlock as timestamp-based
T2 R2x R2y W2x concurrency control is a non-lock concurrency control
method. The method is employed in relational databases
Schedule S2 to safely handle transactions. It uses the timestamps
for the same.
T1 T2
R[x] 33. (c) The solution is best understood in steps
R[x] 1. select the process Id from reservation whose class is
R[y] AC the condition is satisfied by 0, 1, 5, 3
W[x]
2. select a passenger whose age > 65 and the pld of
W[y]
W[y] passenger id = pld of reservation id passenger whose
ages > 65 are those of pld 1, 2, 3
S T R(P)
Borrower Bank manager Bank manager Loan amount R(Q) R(Q)
Ramesh Sunderajan Sunderajan 10000.00 R(P)
Suresh Ramgopal Ramgopal 5000.00
W(Q)
Mahesh Sunderjan Sunderajan 7000.00 W(P)
S T
e1
Hence, option (a) is correct.
e5
Attributes can be composite also, Hence, option
(b) is also correct. In the relational table, any attribute
e2
can contain only one value which can be null. Hence,
option (d) is also correct but by the definition of 1 NF, e3 e4
any attribute in the relational table can contain only
V(e4), V (e5) will form a clique
one value not more than one values. Hence option (c)
A planar graph cannot have a K5
is false or incorrect.
\ Through G is planar L (G) is not a Planar graph
EBD_7203
S3-466 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
So, R is false. 51. (d) S1, S3 are true, but S2 is false.
(S) The line graph of a tree is a tree. S1 is true as the link state Routing uses “Dijkstra’s
Let 'T' be an example tree, and L{T) is its line graph. Algorithm” to compute new routes which has high
In L(T) :e1,e2,e3 will form a K3 (D le) computation complexity.
‘S2’ is false as Distance vector routing suffers from
Two-node loop problem.
S3 is true as in link state routing each node has the
entire topology of the domain.
52. (d) rQ (x); w2 (x); r3 (x); r1 (x); w1 (x) is conflict
serializable.
e1 e2 e3 Conflicting Instructions: Two instructions are said to
be conflicting instructions if they are performed on the
i.e. a 3 – cycle. same data item and atleast one of them is “write”
Tree is an acyclic graph i.e., does not have a cycle. instruction.
So, L(T) is not a tree. Serial schedule : A schedule is called a serial schedule
So, S is false if it consists of a sequence of instructions from various
\ Answer is "P" only i.e., Option (a). transactions, where the instructions belonging to one
49. (b) We know that K is a key for Relation schema R it single transaction appear together in that schedule.
K ® R; i.e. K functionally determines each & every Conflict serializable schedule: A schedule is called
attribute of R. This is definition off key using conflict serializable if it can be transformed into a “serial
functional dependency. schedule” using valid swap operation where valid swap
Now, the Given Relation-Schema is R (E, F, G, H, I, J, denotes the swapping of any two “Non-conflicting”
K, L, M, N) and the Given functional dependencies: instructions.
{E, F}®{G} (i) {K}®{M} (iv) (a) r1 (x); r2 (x); w1 (x); r3 (x); w2 (x); is not conflict
{F}®{I, J} (ii) {L}®{N} (v) serializable because w1 (x); cannot be swapped either
{E, H}®{K, L} (iii) with r2 (x); or r3 (x).
Now we need to find function dependency whose (b) It is also not conflict serializable as w2 (x) cannot be
right side is R. swapped with r1 (x) or r3 (x).
(a) {E, F} Cannot be a key as it determines only ‘G’ (c) Same here as w2 (x) and r1 (x) are conflicting.
(b) {E, F, H} is a key: (d) It is conflict serializable as if we swap r3 (x) with r1 (x)
· using Transitivity on (i) and (ii) we get which are Non-conflicting, we get r2 (x); w2 (x); r1 (x);
{E, F}®{G, I, J} .......(vi) r3 (x) ; w3(x)
· using preudotransitivity on (iii) and (vi) we get Which is a SERIAL SCHEDULE.
{E, F, H}®{G, I, J, K, L} ........(vii) 53. (a) S1 is true and S2 is false.
· using Decomposition on (vii) we get S1: Every table with two single valued attributes is in
{E, F, H}®{K} and {E, F, H}®{L} 1 NF, 2NF, 3NF and BCNF
Combining above with (iv) and (v) respectively S1 is trially true by the definition of all normal forms.
{E, F, H} ®{M} and {E, F, H} ®{N} S2 : AB ® C, D ® E, E ® C is a minimal cover for the set
Now, finally performing union of these with (vii) we of functional dependencies
get: AB ® C, D® E, AB ® E, E ® C.
{E, F, H} ®{G, I, J, K, L, M, N} ...........(viii) It is clearly false as any combination of the functional
Also {E, F, H}®{E, F, H} is trivial, combine this with dependencies AB® C, D ® E, E® C cannot generate
(viii) using union, we get: the func. dependency AB® E. Since AB®E cannot
{E, F, H} ®{E, F, G, H, I, J, K, L, M, N} be inferred, the given set cannot be the minimal cover.
Þ {E, F, H} ® R So, S2 is false.
So, {E, F, H} is a key of R. Finally, S1 is true and S2 is false.
(C) {E, F, H, K, L} is a super key but not a key since it 54. (b) It executes and gives the correct result. As we see
is not minimal (i.e. contains extra attributes) there is nothing wrong with the Given query so it
& (D) {E} cannot be a key of R clearly. displays the expected result.
50. (d) Both S1 and S2 are false. 55. ()
DATABASES S3-467
56. 8 Maximum no. of super keys = 2n–1 66. 7
= 24–1 = 23 = 8
57. 19 Age cannot be 19 as (Student Name, Student Age) is Maximum Allocate Need Available
-3 2 1 1
a key.
-3 2 1
58. (c) S is both conflict - serializable and recoverable.
-3 2 1
59. (a)
60. (c) Consumer executes wait (S), then wait (n) and goes to From the above data, after allocating 2 units of tape to
sleep by decreasing n value. each process, with 1 available unit any of the 3 process
After the consumer sleep, producer goes to the sleep can be satisfied in such a way, that no dead lock will be
by executing wait (s). there.
Dead lock occurs if the consumers succeeds in Therefore it is 7 unit tapes.
aquiring semaphore S when the buffer is empty. 67. (d)
61. (c) The one that give same answer is :
select R. * from R, (select distinct a from S) as S1 PRACTICE EXERCISE
where R.a = S1. 1. (c) Consider X ® A
62. (a) P A1 (P A2 (s F1 (s F2 (r)))) Since X is a non key attribute and A is the prime attribute
which in turn is consisting of prime attributes the given
= P A1 (P A 2 (s(F1 Ù F2 )(r))) relation is free from transitive dependency and hence
the given relation will be in 3 NF
Q A1 Ì A 2 , final relation will be displaying values
2. (d) Problems due to the Concurrent Execution of
for attributes present in set A. Transactions
P A1 (s(F1 Ù F2 )(r)) 1. The Lost Update Problem: Two transactions
accessing the same database item have their
63. (b) A prime attribute of a relation scheme R is an
operations interleaved in a way that makes the
attribute that appears in some candidate key of R1
database item incorrect
others are non-prime or non-key attributes. 2. The Incorrect Summary or Unrepeatable Read
64. (a) Precedence graph Problem: One transaction is calculating an
aggregate summary function on a number of
S1 S2 records while other transactions are updating
some of these records.
T1 T2 T3 T1 3. The Temporary Update (Dirty Read) Problem:
One transaction updates a database item and
then the transaction fails. The updated item is
accessed by another transaction before it is
T3 No cycle T2 cycle changed back to its original value.
4. The Phantom problem: First transaction reads a
set of rows; second transaction inserts a row;
\ S1 is conflict serializable first transaction reads the rows again and sees
65. (d) the new row
A 3. (c) The primary key is used to identify uniquely each and
every entity. In which no attribute is redundant. By
p (employee) – p (employee) dependent using the flight number and data we can identify the
information regarding any plane.
(emp Id = eID) Ù (emp Age £ dep Age) 4. (a) Since for Database relation R(a, b, c, d) all values are
atomic and
a®c
A gives the set of empIds of those employees b®d
whose age is less than or equal to the age of some Here neither of a, b, c, d are primary key.
of his/her dependents. The primary key is ‘ab’ prime attributes = {a, b}
Set of empIds of all employees - set of empIds here pert of key (a in a ® c and in b in b ® d) is
obtained from part A gives the set of empIds of dependent on non key hence there is a partial
employees whose age is greater than that of all of dependency and the relation is not in 2NF
his/her dependents.
EBD_7203
S3-468 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
5. (a) E-R modeling technique is a top-down approach. It is a integrity, dealing with concurrency control, and
graphical technique, which is used to convert the recovering information if the system fails.
requirement of the system to graphical representation, 15. (a) Because in all other cases the addition being performed
so that it can become well understandable. It also is incorrect.
provides the framework for designing of database. Assign
6. (a) 7. (c)
8. (a) Since transaction A holds only a shared lock R, Hence a +
any number of transaction can read the data from the
requested item using shared locking. Hence B’s request *
will be fulfilled immediately.
9. (d) A specific example where physical data independence b uminus
would not hold is when the user writes an application
program to join tables because Join, which builds a c
new table from two specified tables. t1 = * (– c)
10. (a) Data independency in DBMS is known as Data Then the result is added to the result
Modelling.
t2 = t1 + t1 .
11. (b) A data dictionary doesn’t provide information about )
Then the assignment is done.
the size of the disk storage disk.
16. (c) For the given entity relationship diagram (ERD), the
Tablespaces logically organize data that are physically
attributes of the relation qualification i.e. qualified date
stored in datafiles because this information about tables
must be included when any relationship between
is not update in the data dictionary.
person and exam is required. In (c) the keys of both the
12. (c) The database administrator is, in effect, the coordinator
entities are mentioned but qualified data must be
between the database and the users. Database
mentioned hence the relation Exam (Exam Id, NID, Exam
administrators (DBAs) use specialized software to store
Name) is not accessible.
and organize data, such as financial information and
customer shipping records. They make sure that data 17. (d) Elipse with underlined attribute is known as key
are available to users and are secure from unauthorized attribute.
access. 18. (d)
13. (d) Typical fields or items found in a Data Dictionary: 19. (c) A relation (from the relational database model) consists
• entity or form name or ID of a set of tuples, which implies that for any two tuples,
• field name (such as RDBMS field name) the value associated with one or more of their attributes
• field title (defaults to field name if blank) must differ. A relation is defined as a set of tuples that
• field type or format code have the same attributes. A tuple usually represents
• dimension(s) such as min and max values, an object and information about that object. Objects
display width, or number of decimal places. are typically physical objects or concepts. A relation
• display or tab order is usually described as a table, which is organized into
• coordinates on screen (if positional UI) rows and columns. All the data referenced by an attribute
• default value (for adds) are in the same domain and conform to the same
• prompt type (entry box, drop-down, combo- constraints.
box, check-box, range, etc.)
20. (b) According to entity integrity primary key of relation
• is required (Boolean)
should not contain null values.
• is read-only (Boolean)
• reference to parent or containing widget/form 21. (b) Loans (br_ name, loan_no, amount)
• list source (if a drop-down list. Could be a For the query “find the loan number for each loan of an
handler or query expression) amount greater than 2000.”
• various event handlers we have to check for each loan to find a loan number
14. (d) Database management system (DBMS) prevents errors which is greater than 20,000
arising, while enabling multiple, simultaneous users.
clearly, (b) {t | $ s Î loans (t [loan_no] = S[loan_no] ^
Registering and monitoring users, enforcing data
[amount] > 20000}
security, monitoring performance, maintaining data
DATABASES S3-469
22. (d) Referential integrity constraint 28. (a) For the given relation instance we have the FD set as
In relational model, two relation we related to each other AB ® C
over the basis of attributes. Every value of referencing A®D
attribute must be null or be available in the referenced B ® EF
attribute.
Hence candidate is AB
O Ø
Ø
Data flow diagrams
E
N
T
S
EBD_7203
S3-478 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
INFORMATION GATHERING
The Information system designed for an organization must meet the requirements of the
end users of the organization. To obtain what an end user expects from the Information
System the designer must gain complete knowledge of the organization’s working. The
main purpose of gathering information is to determine the information requirements of
an organization. Information requirements are often not stated precisely by management.
It is the analyst’s responsibility to prepare a precise Systems Requirements Specifications
(SRS), which is easily understood (SRS) by users, as SRS document is a vital document
before starting a project.
Information Gathering Strategies
A strategy should be evolved by the analyst to gather information. The strategy consists
of identifying information sources, evolving a method of obtaining information from the
identified sources and using an information flow model of organization.
Information Sources
The main sources of information are users of the system, forms and documents used in
the organization, procedure manuals, rule books etc, reports used by the organization
and existing computer programs(If Any).
Feasibilty Analysis
Feasibility analysisis used to assess thestrengths and weaknesses of a proposed project
and give directions of activities that shall improve a project and achieve desired results.
Sometimes referred to by terms such as “project initiation,” feasibility analysis determines
whether or not to do a project. If a project exists, someone has made some decisions
about it. Some organizations submit the feasibility analysis results to a steering committee,
which is charged with determining which proposed projects will be performed. Steering
committees typically consist of senior executives with budgetary authority over the
various areas competing for scarce project resources.
Who does feasibility analysis and when?
In many organizations, the project is created as a record-keeping entity, and then the
feasibility analysis is performed as its first phase. If the analysis fails to show feasibility,
that's the end of the project. When feasibility analysis is considered a part of the project,
it's more common for the project manager or a business analyst to perform it.When a
business analyst is assigned to do a feasibility analysis, it's often before a project
manager has been assigned to the project. Consequently the business analyst also has
to be project manager for the feasibility analysis phase, which is essentially a sub-
project.
Requirement Analysis
The requirements determination activity is the most difficult part of information systems
analysis. Requirements determination addresses the gathering and documenting of the
true and real requirements for the information system being developed. “What must the
system do?” during the requirements determination activity. Once information systems
development progresses to the design activities, the systems analyst and the
programmers focus their attention primarily on the question, “How does the system do
what it is supposed to do?”
Understanding And Doing Requirements Determination
Requirements Determination Sub-activities
1. Requirements Anticipation. The systems analyst hypothesizes that particular
requirements are relevant based on his or her previous experience with other similar
systems and knowledge about the problem domain.
2. Requirements Elicitation. The systems analyst uses this activity to gather the essential
requirements from the user employing a variety of techniques, such as interviews,
questionnaires, group brainstorming meetings, and voice and e mail.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-479
3. Requirements Assurance. The systems analyst uses the activity of requirements
assurance to validate and verify the requirements with the user as being the real and
essential requirements. A user walk through in which the systems analyst and the user
together review documented requirements in detail is one assurance technique.
4. Requirements Specification. This is the activity that the systems analyst uses to
explicitly catalog and document the requirements either during or after the elicitation and
assurance activities. This is the activity most often associated with automated computer
aided software engineering (CASE) technology, which is discussed later in the book.
Methods Used To Gather An Information System's Requirements
To customize the system requirements to the problems at hand, however, individual
requirements are always necessary. Within the individual category, common methods
include:
(1) interviews,
(2) observation,
(3) questionnaires or surveys, and
(4) creating a prototype of the information system in order to obtain feedback from
the potential users of the system.
Interviews involve at least one systems analyst and at least one user conversing about
the information system's requirements. Interviewing for requirements is similar to your
interviewing for a job position or a television talk show host interviewing a guest.
Observation is the act of the systems analyst going to a specific location to observe the
activities of the people and machinery involved in the problem domain of interest.
Questionnaires are feedback forms designed to gather information from large groups of
people.
Creating a prototype of the information system can be done on an individual level or in
a group setting. The idea is to explore system alternatives by developing small working
models of the proposed system so that user reactions can be gathered. Sometimes
prototyping is done in conjunction with joint application development (JAD) or rapid
analysis techniques of any type. Essentially, JAD and rapid analysis techniques are
facilitated groups of users that collaborate in concentrated work sessions to define
needed system functions, screens, reports, expectations, and data elements.
Feedback to the User
Context diagrams and data flow diagrams are the primary tools to diagram system
processes because these two diagrams are often more easily understood by the user.
Similarly, object technology is currently exploring notation and symbols that can be
used both by the systems analyst to document the essence of the system and by the
user to verify that the systems analyst has indeed gathered the essence of the information
system accurately.
Requirement Ambiguity
The three most common sources of requirements ambiguity are (1) missing
requirements, (2) ambiguous words, and (3) introduced elements. Missing requirements
are simply those things that are needed and necessary for the success of the information
system but are not included for a variety of reasons.Words that have a significant
amount of flexibility as to their interpretation and exact meaning are called ambiguous
words. With best intentions, the systems analyst and even the programmer may make
some decisions that affect the system without first getting the approval of the user. It
could be something as simple as printing the date at the beginning of a report ,known as
requirement ambiguity caused by introduced elements.
SYSTEM REQUIREMENTS SP ECIFI CATI ON (SRS)
SRS is obtained after excessive discussions with the user. System requirements
specification specifies what Information requirements will be provided. It does not specify
how the system will be designed. Developing SRS is most important and difficult task of
a Systems analyst
EBD_7203
S3-480 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
How SRS is Developed
Analyst examines the current system, finds out the shortcomings of the system as seen
by the user. He then develops an SRS which is understandable by the user and which
can be used for detailed design of the system.
Ideal characteristics of SRS
• Complete and Unambiguous.
• Specifies operational, tactical, and strategic information requirements
• Eliminates possible later disputes between users and Analyst
• Uses Graphical aids understood by users who are not computer literate and will
also be useful in design.
• Jargon Free.
DEVELOPING A DOCUMENT FLOW DIAGRAM
Example Word Statement
“Our company receives many items from several vendors each accompanied by a delivery
note. A receiving office receives the item
and checks the delivery note with
corresponding order. Any discrepancy is
reported to purchase office. The items
received along with items received note
(with details of items) is sent to the
inspection office.”
Entities Identified – Vendors, Receiving
office, Inspection office
Documents Indentified - Delivery note,
discrepancy note, Items
Received note.
Using these a document flow diagram is
drawn.
The diagram is interpreted as follows:
(1) Vendors deliver items to receiving office accompanied by a delivery note
(2) Receiving Office sends items to inspection office along with an items received
note
(3) Receiving office sends discrepancy note to Purchase office
ENTITIES: Vendor, Receiving office, Inspection office and purchase office
DOCUMENTS: Delivery note, Items received note and discrepancy note.
DATA FLOW DIAGRAM (DFD)
DFD has entities and data flows, DFD specifies processing performed by some of the
entities. It specifies which entities generate documents and also indicate their flow. Data
stores which are referred while processing
data and in which processed data may be
written or stored are also represented in
the Diagram.
• Entities are, originators of data and
“consumers” of data
• Vendor, Inspection office and
purchase office are entities in the
diagram
• Data flows are delivery note, items
received note and discrepancy note
• A circle is used to depict a process
• A pair of parallel lines depict a store
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-481
Data Elements in the Data Flow:
Delivery note:
Order no,Vendor code,Vendor name and address,Item name, Item code,Delivery
date,Quantity supplied,units.
Items Received note:
Order no,Item name,Item code,Delivery date,quantity,supplied,units.
Discrepancy note:
Order no,Vendor code,Vendor name and address,Item name, Item code,Order date,
Delivery date,quantity supplied,units, excess/deficiency,No of days late/early.
Receiving office order file
Order no,Order date,Item name,Item code,Vendor code,Vendor Name and
address,Quantity ordered,delivery period.
Modularizing Requirements Specifications
SRS Document now consists of Document flow diagrams(as many as needed), Data
Flow Diagrams, Data elements of each data flow and Data store, processing rules carried
out in each circle of DFD, a descriptive statement of operational, tactical, strategic
information will be provided, a data dictionary which consolidates all data elements in
the document and data store.
Process Specifications
The methods available for documenting and analyzing the logic of structured decisions
include structured English, decision tables, and decision trees. Process specifications
are not created for
• Physical input and/or output processes
• Processes that represent simple data validation
• Processes for which prewritten code already exists
Process Logic
Process descriptions may exist on a form or within a CASE tool repository.Process logic
may be represented as
1. Structured English
2. A decision table
3. A decision tree
i. A formula
ii. Any combination of the above
Process Specification Format
Process specifications link the process to the DFD and the data dictionary.The following
information should be entered:The process number, which must match the process ID
on the data flow diagram.This allows an analyst to work or review any process and easily
locate the data flow diagram containing the process.The process name, the same as
displays within the process symbol on the DFD.A brief description of what the process
accomplishes.A list of input and output data flow, using the names found on the data
flow diagram.Data names used in the formulae or logic should match the data dictionary,
for consistency and good communication.An indication of the type of process, whether
it is batch, online or manual.All online processes require screen designs.All manual
processes should have well-defined procedures for employees performing the process
tasks.If the process has prewritten code for it, include the name of the subprogram or
function.A description of the process logic.This should state policy and business rules,
not computer language pseudocode .A reference to further information, such as a
structured English description, a decision table or tree depicting the logic.List any
unresolved issues.These form the basis of the questions used for a follow-up interview.
EBD_7203
S3-482 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
How Process Specifications Relate to the Data Flow Diagram
Structured
English
IF construction
THEN deduc
ENDIF
IF replacement
THEN add 1
ENDIF
IF owner choose
THEN add 1
ENDIF
Decision
Table
Process Rules
1 2 3 4
Process Specification Y – N –
Form Y Y Y N
X
X
X
Decision Tree
Example:
Number 1
Name Add Customer Order
Description Key and add the Customer Order.
The order should be edited for correct information.
Customer and Item master files are updated.
Input Data Flow
Customer Order Form from the Customer
Customer Record from data store D1, Customer Master File
Item Record from data store D2, Item Master File
Output Data Flow
Pending Order to data store D3, Order File
Backordered Item Record to the Inventory Control Department
Updated Customer and Item records
Type of process Online
Structured English
• Used when the process logic involves formulas or iteration, or when structured
decisions are not complex .Based on structured logic and simple English
statements such as add, multiply, and move.Express all logic in terms of sequential
structures, decision structures, case structures, or iterations
• Use and capitalize accepted keywords such as IF, THEN, ELSE, DO, and PERFORM
• Indent blocks of statements to show their hierarchy (nesting) clearly
• Underline words or phrases that have been defined in a data dictionary
• Clarify the logical statements
Conditions and Actions
Conditions, condition alternatives, actions, and action rules must be known in order to
design systems for structured decisions.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-483
Decision Tables
Decision tables provide a way to examine, describe, and document decisions using a
table.Decision tables help analysts ensure completeness and accuracy.
Customer Checkout Decision Table
Rules
Conditions and Actions 1 2 3 4
Under $50 Y Y N N
Pays be check with two forms of ID Y N Y N
Uses credit card N Y N Y
Complete the sale after verifying signature. X
Complete the sale. No signature needed. X
Call supervisor for approval. X
Communicate electronically with bank for credit X
card authorization.
Decision Trees
Decision trees are used when complex
branching occurs in a structured decision Complete the sale after verifying signature.
Check 3
process.Identify all conditions and actions
and their order and timing (if they are Under $50 2 Credit Card
Complete the sale. No signature needed.
critical).Begin building the tree from left to 4
right, making sure you list all possible 1
alternatives before moving to the right. ≥ $50 Call supervisor for approval.
Drawing a Decision Tree to Show the Check 6
Noncash Purchase Approval Actions for a 5 Credit Card Communicate electronically with bank for
Department Store credit card authorization.
7
INPUT/ OUTPUT DESIGN
Software Design:Deriving a solution which satisfies software requirements.
Stages of Design
Evaluate possible solutions and choose the most appropriate depending on the designer’s
experience and available resources.Describe solution abstractions such as use of graphical,
formal or other descriptive notations to describe the components of the design.
Design Phases
• Architectural design: Identify sub-systems.
• Abstract specification: Specify sub-systems.
• Interface design: Describe sub-system interfaces.
• Component design: Decompose sub-systems
into components.
• Data structure design: Design data structures to hold problem data.
• Algorithm design: Design algorithms for problem functions.
The goal of system design is to decode,What the modules are,What the modules should
be,How the modules interact with one-another.
Procedural Abstraction: The most obvious design methods involve functional
decomposition.This leads to programs in which procedures represent distinct logical
functions in a program.
Object-oriented design
The system is viewed as a collection of interacting objects. The system state is
decentralized and each object manages its own state. Objects may be instances of an
object classand communicate by exchanging methods.
We can identify five criteria to help evaluate modular design methods:
• Modular decomposability;
• Modular composability;
• Modular understandability;
• Modular continuity;
• Modular protection
EBD_7203
S3-484 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Modular Decomposability
This criterion is met by a design method if the method supports the decomposition of a
problem into smaller sub-problems, which can be solved independently.
Top-down Design
In principle, top-down design involves starting at the uppermost components in the
hierarchy and working down the hierarchy level by level.
Modular Composability
A method satisfies this criterion if it leads to the production of modules that may be
freely
Five principles for Good Design
1. Linguistic modular units:A programming language (or design language) should
support the principle of linguistic modular units.Modules must correspond to
linguistic units in the language used like the Java methods and classes.
2. Few interfaces:This principle states that the overall number of communication
channels between modules should be as small as possible.Every module should
communicate with as few others as possible.
3. Small interfaces(Loose coupling):This principle states that if any two modules
communicate, they should exchange as little information as possible.
4. Explicit interfaces:If two modules must communicate, they must do it so that we
can see it.If modules A and B communicate, this must be obvious from the text of
A or B or both.
Tight Coupling
5. Information hiding:All information about a module, (and particularly how the
module does what it does) should be private to the module unless it is specifically
declared otherwise.The default Java rule:Make everything private .
Module A Module B
Coupling
It is the measure of the strength of the inter-connections between system components.
Module C Module D
Loose coupling means component changes are unlikely to affect other components.Shared
variables or control information exchange lead to Tight coupling. Loose coupling can be
Shared data achieved by state decentralization (as in objects) and component communication via
area parameters or message passing. Coupling and Inheritance.
Loose Coupling Object-oriented systems are loosely coupled because there is no shared state and objects
communicate using message passing.However, an object class is coupled to its super-
classes. Changes made to the attributes or operations in a super-class propagate to all
Module A sub-classes.
A’s data • Types of Coupling
– Content coupling (high)
Content coupling is when one module modifies or relies on the internal
Module B Module C workings of another module (e.g., accessing local data of another module).
Therefore changing the way the second module produces data (location,
B’s data C’s data type, timing) will lead to changing the dependent module.
– Common coupling
Common coupling is when two modules share the same global data (e.g., a
Module D global variable). Changing the shared resource implies changing all the
D’s data modules using it.
– External coupling
External coupling occurs when two modules share an externally imposed
data format, communication protocol, or device interface.
– Control coupling
Control coupling is one module controlling the flow of another, by passing
it information on what to do (e.g., passing a what-to-do flag). Stamp coupling
(Data-structured coupling). Stamp coupling is when modules share a
composite data structure and use only a part of it, possibly a different part
(e.g., passing a whole record to a function that only needs one field of it).
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-485
This may lead to changing the way a module reads a record because a field,
which the module doesn't need, has been modified.
– Data coupling
Data coupling is when modules share data through, for example, parameters.
Each datum is an elementary piece, and these are the only data shared (e.g.,
passing an integer to a function that computes a square root).
– Message coupling (low)
This is the loosest type of coupling. It can be achieved by state
decentralization(as in objects)and component communication is done via
parameters or message passing.(see Message passing).
– No coupling
Modules do not communicate at all with one another.
Conceptual model of coupling
C OH E S IO N
A measure of how well a component “fits together”.A component should implement a
single logical entity or function.Various levels of cohesion have been identified
· Coincidental cohesion (weak)
– Parts of a component are simply bundled together.
· Logical association (weak)
– Components which perform similar functions are grouped.
· Temporal cohesion (weak)
– Components which are activated at the same time are grouped.
· Communicational cohesion (medium)
– All the elements of a component operate on the same input or produce the
same output.
· Sequential cohesion (medium)
– The output for one part of a component is the input to another part.
· Functional cohesion (strong)
– Each part of a component is necessary for the execution of a single function.
· Object cohesion (strong)
– Each operation provides functionality which allows object attributes to be
modified or inspected.
EBD_7203
S3-486 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Types of Cohesion
Coincidental cohesion:
A module is said to have coincidental cohesion, if it performs a set of tasks that relate to
each other very loosely, if at all. In this case, the module contains a random collection of
functions. It is likely that the functions have been put in the module out of pure
coincidence without any thought or design. For example, in a transaction processing
system (TPS), the get-input, print-error, and summarize-members functions are grouped
into one module. The grouping does not have any relevance to the structure of the
problem.
Logical cohesion:
A module is said to be logically cohesive, if all elements of the module perform similar
operations, e.g. error handling, data input, data output, etc. An example of logical cohesion
is the case where a set of print functions generating different output reports are arranged
into a single module.
Temporal cohesion:
When a module contains functions that are related by the fact that all the functions must
be executed in the same time span, the module is said to exhibit temporal cohesion. The
set of functions responsible for initialization, start-up, shutdown of some process, etc.
exhibit temporal cohesion.
Procedural cohesion:
A module is said to possess procedural cohesion, if the set of functions of the module
are all part of a procedure (algorithm) in which certain sequence of steps have to be
carried out for achieving an objective, e.g. the algorithm for decoding a message.
Communicational cohesion:
A module is said to have communicational cohesion, if all functions of the module refer
to or update the same data structure, e.g. the set of functions defined on an array or a
stack.
Sequential cohesion:
A module is said to possess sequential cohesion, if the elements of a module form the
parts of sequence, where the output from one element of the sequence is input to the
next. For example, in a TPS, the get-input, validate-input, sort-input functions are grouped
into one module.
Functional cohesion:
Functional cohesion is said to exist, if different elements of a module cooperate to
achieve a single function. For example, a module containing all the functions required to
manage employees' pay-roll exhibits functional cohesion. Suppose a module exhibits
functional cohesion and we are asked to describe what the module does, then we would
be able to describe it using a single sentence.
SOFTWARE LIFE CYCLE MODELS
The software life cycle is a general model of the software development process, including
all the activities and work products required to develop a software system. A software
life cycle model is a particular abstraction representing a software life cycle. Such a
model may be:
· activity-centered — focusing on the activities of software development
· entity-centered — focusing on the work products created by these activities
These are complementary views: activities produce work products.
A software life cycle model is often referred to as a software development life cycle
(SDLC).
IEEE 1074 Standard for Developing Life Cycle Processes
The IEEE standard 1074 seeks to establish a common framework for developing life cycle
models. It describes the activities and processes needed for the development and
maintenance of software, and provides examples for typical situations.
The standard divides the set of activities into processes, and processes into process
groups.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-487
Implementation Phase/Support
This Phase will provide users with the documentation and training required to use the
system effectively. Data Conversion will only occur once, but user documentation will
be required. Deployment of the product will be carried out, on the hardware that is going
to be used in production (on live systems). Deployment itself requires a careful planning.
Once the product is deployed, initial data will be populated and user training will happen.
Release to Production and warranty Period
When the clients do the acceptance testing and find no problems, then they will accept
the software and now they have to start using the software in their real office. It may be
a real bank for a banking application. During the acceptance testing also, there may be
some bug fixing done to the software. Before the software is put into production (real
time environment), the SDU must release the latest versions of the software, which has
no known bugs to the client. This may be in a CD or tape or an Internet download. The
clients will then install the latest software in their production system and will start using.
This is called go-live process.
In the same way every product has a guarantee period software also has a warranty
period. Normally it will be a 60-day or a 90-day warranty period for most kinds of software.
Depending upon the complexity and size of the software the warranty period may be
extended or shortened. During this warranty period, in case of any problems, the SDU
EBD_7203
S3-498 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
has the responsibility to rectify the problem, at no charges. Again, it depends upon the
contract, whether to charge for the fix or not and may vary from industry to industry.
Maintenance Phase
After the warranty period, the software enters the maintenance phase. During the
maintenance phase, 3 things happen to the software. They are :
· Bug fixing
· Upgrade
· Enhancement
During the maintenance phase, because of some untested scenarios, the software may
give errors or logical problems. This has to be fixed. This is same as any other bug fixing.
This is similar to any repair work done to a vehicle, by its owner.
In the software field, the software versions are constantly changing and the applications
may have to keep themselves upgraded to the newer versions of the software. For
example, the anti-virus software must be constantly upgraded to address new viruses,
which come very day.If the operating system version charges, it may necessitate to
introduce some changes in the programs. So, this kind of upgrade works to the existing
software applications, because of operating system or environmental changes or hardware
changes may have to be incorporated.
Any software is not all complete and there are enough rooms to add new features to an
existing software. So, new modules are to be added to the existing system to address
this. This is enhancement.
After some time, the software may become obsolete and will reach a point that it cannot
be used. At that time, it will be replaced by another software which is superior to that.
This is the end of the software. The software will reach its end, when the maintenance
cost of the software becomes more than the new software available. Software can become
obsolete when the company does not upgrade it to work on new environments such as
databases or operating systems. When the software becomes incompatible with the
environment, users will move on to another software, dumping the existing one.
CMM LEVEL
Maturity Level Details:
Maturity levels consist of a predefined set of process areas. The maturity levels are
measured by the achievement of the specific and generic goals that apply to each
predefined set of process areas.
Maturity Level 1 - Initial
At maturity level 1, processes are usually ad hoc and chaotic. The organization usually
does not provide a stable environment. Success in these organizations depends on the
competence and heroics of the people in the organization and not on the use of proven
processes.
Maturity level 1 organizations often produce products and services that work; however,
they frequently exceed the budget and schedule of their projects.
Maturity level 1 organizations are characterized by a tendency to over commit, abandon
processes in the time of crisis, and not be able to repeat their past successes.
Maturity Level 2 - Managed
At maturity level 2, an organization has achieved all the specific and generic goals of the
maturity level 2 process areas. In other words, the projects of the organization have
ensured that requirements are managed and that processes are planned, performed,
measured, and controlled.
The process discipline reflected by maturity level 2 helps to ensure that existing practices
are retained during times of stress. When these practices are in place, projects are
performed and managed according to their documented plans.The work products and
services satisfy their specified requirements, standards, and objectives.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-499
Maturity Level 3 - Defined
A critical distinction between maturity level 2 and maturity level 3 is the scope of standards,
process descriptions, and procedures. At maturity level 2, the standards, process
descriptions, and procedures may be quite different in each specific instance of the
process (for example, on a particular project). At maturity level 3, the standards, process
descriptions, and procedures for a project are tailored from the organization's set of
standard processes to suit a particular project or organizational unit. The organization's
set of standard processes includes the processes addressed at maturity level 2 and
maturity level 3. As a result, the processes that are performed across the organization are
consistent except for the differences allowed by the tailoring guidelines.
Maturity Level 4 - Quantitatively Managed
Quantitative objectives for quality and process performance are established and used as
criteria in managing processes. Quantitative objectives are based on the needs of the
customer, end users, organization, and process implementers. Quality and process
performance are understood in statistical terms and are managed throughout the life of
the processes. At maturity level 4, the performance of processes is controlled using
statistical and other quantitative techniques, and is quantitatively predictable. At maturity
level 3, processes are only qualitatively predictable.
Maturity Level 5 - Optimizing
Processes are continually improved based on a quantitative understanding of the common
causes of variation inherent in processes.The effects of deployed process improvements
are measured and evaluated against the quantitative process-improvement objectives.
Both the defined processes and the organization's set of standard processes are targets
of measurable improvement activities.A critical distinction between maturity level 4 and
maturity level 5 is the type of process variation addressed. At maturity level 4, processes
are concerned with addressing special causes of process variation and providing
statistical predictability of the results. Though processes may produce predictable
results, the results may be insufficient to achieve the established objectives. At maturity
level 5, processes are concerned with addressing common causes of process variation
and changing the process (that is, shifting the mean of the process performance) to
improve process performance (while maintaining statistical predictability) to achieve the
established quantitative process-improvement objectives.
Note: As we up go different levels in maturity level the previous maturity levels are
achieved by the company/organization structure.
EBD_7203
S3-500 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. The coupling between different modules of a software is 5. The following is comment written for a C function
categorized as follows [2009, 1 mark] /* This function computes the roots of a quadratic equation.
1. Content coupling 2. Common coupling a.x^2 + b.x + c = 0. The function stores two real roots.
3. Control coupling 4. Stamp coupling in *root1 and *root2 and returns the status of validity of
5. Data coupling roots. It handles four different kinds of cases.
1. When coefficient a is zero irrespective of discriminant
Coupling between modules can be ranked in the order of
2. When discriminant is positive
strongest (least desirable) to weakest (most desirable) as 3. When discriminant is zero
follows 4. When discriminant is negative
(a) 1, 2, 3, 4, 5 (b) 5, 4, 3, 2, 1 Only in cases 2 and 3, the stores roots are valid.
(c) 1, 3, 5, 2, 4 (d) 4, 2, 5, 3, 1 Otherwise 0 is stored in the roots. the function returns 0
2. Which of the following statements are true? when
[2010, 2 marks] the roots are valid and – 1 otherwise.
1. The context diagram should depict the system as a The function also ensures root 1 > = root 2.
single bubble. int get_QuadRoots float a, (float b, float c, float * root1, float
2. External entities should be identified clearly at all levels * root2);
of DFDs */
3. Control information should not be represented in a DFD. A software test engineer is assigned the job of doing Block
4. A data store can be connected either to another data Box testing. He comes up with the following test cases, many
store or to an external entity. of which are redundant.
(a) 2 and 3 (b) 2 and 3
Input set Expected Output set
(c) 1 and 3 (d) 1, 2 and 3 Test case
a bc Root 1 Root 2
Return value
3. What is the appropriate pairing of items in the two columns T1 0.0 0.0 7.0 0.0 0.0 –1
listing various activities encountered in a software life cycle? T2 0.0 1.0 3.0 0.0 0.0 –1
[2011, 2 marks] T3 1.0 2.0 1.0 – 1.0 – 1.0 0
T4 4.0 - 12.0 9.0 1.5 1.5 0
P. Requirements 1. Module Development T5 1.0 - 2.0 - 3.0 3.0 – 1.0 0
Capture and Integration T6 1.0 1.0 4.0 0.0 0.0 –1
Q. Design 2. Domain Analysis Which one of the following options provides the set of non-
R. Implementation 3. Structural and redundant tests using equivalence class partitioning
Behavioral Modeling approach from input perspective for Black Box testing?
S. Maintenance 4. Performance [2011, 2 marks]
(a) T1, T2, T3, T6 (b) T1, T3, T4, T5
(c) T2, T4, T5, T6 (d) T2, T3, T4, T5
(a) P - 3, Q - 2, R - 4, S - 1 (b) P - 2, Q - 3, R - 1, S - 4 6. Which of the following is not desired in a good Software
(c) P - 3, Q - 2, R - 1, S - 4 (d) P - 2, Q - 3, R - 4, S - 1 Requirement Specifications (SRS) document?
4. The cyclomatic complexity of each of the modules A and B (a) Functional Requirements [2011, 1 mark]
shown below is 10. What is the cyclomatic complexity of the (b) Non-Functional Requirements
sequential integration shown on the right hand side? (c) Goals of Implementation
[2010, 1 mark] (d) Algorithms for Software Implementation
7. A company needs to develop digital signal processing
software for one of its newest inventions. The software is
expected to have 40000 lines of code. The company needs to
A determine the effort in person-months needed to develop
B this software using the basic COCOMO model. The
A
multiplicative factor for this model is given as 2.8 for the
software development on embedded systems, while the
B exponentiation factor is given as 1.20. What is the estimated
(a) 19 (b) 21 effort in person months? [2011, 1 mark]
(c) 20 (d) 10 (a) 234.25 (b) 932.50
(c) 287.80 (d) 122.40
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-501
8. A company needs to develop a strategy for software product (3) Component-based (c) Explicit recognition
development for which it has a choice of two programming software engineering of risk
languages L1 and L2. The number of Lines OF Code (LOC)
developed using L2 is estimated to be twice the LOC (4) Spiral development (d) Inflexible patitioning
developed with L1. The product will have to be maintained of the project into
for 5 years. various parameters for the company are given in stages
the table below. [2011, 1 mark] [2014, Set-1, 1 Mark]
Parameter Language L1 Language L2
(a) 1-a, 2-b, 3-c, 4-d (b) 1-d, 2-a, 3-b, 4-c
Man years needed for LOC/10000 LOC/10000 (c) 1-d, 2-b, 3-a, 4-c (d) 1-c, 2-a, 3-b, 4-d
development 10. Which one of the following is TRUE?
Development ` 10,00,000 ` 7,50,000 [2014, Set-2, 1 Mark]
cost per year (a) The requirements document also describes how the
Maintenance time 5 yr 5 yr requirements that are listed in the document are
Cost of maintenance ` 1,00,000 ` 50,000 implemented efficiently.
per year (b) Consistency and completeness of functional
Total cost of the project includes cost of development and requirements are always achieved in practice.
maintenance. What is the LOC for L1 for which the cost of (c) Prototyping is a method of requirements validation.
the project using L1 is equal to the cost of the project using (d) Requirements review is carried out to find the errors in
L2? system design.
(a) 4000 (b) 5000
11. In the context of modular software design, which one of the
(c) 4333 (d) 4667
9. Match the following : following combinations is desirable?
(1) Waterfall model (a) Specifications can be [2014, Set-3, 1 Mark]
developed (a) High cohesion and high coupling
incrementally (b) High cohesion and low coupling
(2) Evolutionary model (b) Requirements
compromises are (c) Low cohesion and high coupling
inevitable (d) Low cohesion and low coupling
1. Which is NOT the part of operating procedure manuals? 6. Which model is most popular for student’s small projects?
(a) User manuals (b) Operational manuals (a) Waterfall model (b) Spiral model
(c) Documentation manuals (d) Installation manuals (c) Quick and fix model (d) Prototyping model
2. To produce a good quality product, process should be 7. If limited user participation is available, which model is to be
(a) Complex (b) Efficient selected?
(c) Rigorous (d) None of the above (a) Waterfall model
3. Infrastructure software are covered under (b) Spiral model
(a) Generic products (c) Iterative enchancement model
(b) Customised products (d) any of the above
(c) Generic and Customised products 8. Which one is the most important feature of spiral model?
(a) Quality management
(d) none of the above
(b) Risk management
4. Management of software development is dependent on
(c) Performance manangement
(a) people (b) product
(d) Efficiency management
(c) process (d) all of the above
9. Statistically,the maximum percentage of errors belongto the
5. Software engineering approach is used to acheive: following phase of SDLC
(a) Better performance of hardware (a) Coding
(b) Error free software (b) Design
(c) Reusable software (c) Specifications
(d) Quality software product (d) Installation and maintenance
EBD_7203
S3-502 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
10. Which one is not a step of requirement engineering? 23. ‘FAN IN’ of a component A is defined as
(a) Requirements elicitation (a) Count of the number of components that can call, or
(b) Requirements analysis pass control, to component A
(c) Requirements design (b) Number of components related to component A
(d) Requirements documentation (c) Number of components dependent on component A
11. Which is not a type requriements under quality function (d) None of the above
deployment 24. Minimal implementation of any alogrithm was given the
(a) Normal requriements (b) Abnormal requirements following name by Halstead:
(c) Expected requirements (d) Exiciting requirements (a) Volume (b) Potential volume
12. The DFD depicts (c) Effective volume (d) none of the above
(a) Flow of data (b) Flow of control 25. Program volume of a software product is
(c) Both (a) and (b) (d) None of the above (a) V = N log2 n (b) V = (N/2) log2 n
13. IFPUG Stand for (c) V = 2N log2 n (d) V = N log2 n + 1
(a) Initial function point uniform group 26. Software Quality is
(b) International function point uniform group (a) Conformance to requirements
(c) International function point user group (b) Fitness for the purpose
(d) Initial function point user group (c) Level of satisfaction
14. COCOMO-II estimation model is based on (d) All of the above
(a) Complex approach (b) Algorithmic approach 27. Defect rate is
(c) Bottom up approach (d) Top down approach (a) number of defects per million lines of source code
15. Which one is not a Category of COCOMO-II? (b) number of defects per function point
(a) End user programming (b) Infrastructure sector (c) number of defects per unit of size of software
(c) Requirement sector (d) System integration (d) All of the above
16. In Putnam resource allocation model, Rayleigh curve is 28. The second level of quality attributes in McCall quality model
modeled by the equation are termed as
2 2
(a) m(t) = 2at e–at (b) m(t) = 2Kt e–at (a) quality criteria (b) quality factors
–at2 –at2
(c) m(t) = 2Kat w (d) m(t) = 2Kt e (c) quality guidelines (d) quality specifications
17. In Putnam resource allocation model, technology factor ‘C’ 29. In basic execution time model, failure intensity is given by
is defined as
æ m2 ö æ m ö
(a) C = SK -1/ 3 t d-4/ 3 (b) C = SK1/ 3 t d4/ 3 (a) l ( m ) = l0 ç 1 - ÷ (b) l ( m ) = l0 ç 1 - ÷
ç V0 ÷ V
è ø è 0ø
(c) C = SK1/ 3 t d-4/ 3 (d) C = SK-1/ 3 t 4d / 3
18. Temporal cohesion means æ V ö æ V ö
(c) l ( m ) = l0 ç 1 - 0 ÷ (d) l ( m ) = l0 ç 1 - 0 ÷
(a) Cohesion between temporary variables m ø ç m2 ÷
è è ø
(b) Cohesion between local variable
(c) Cohesion with respect to time 30. In Basic execution time model, aditional time requried achieve
(d) Coincidental cohesion a failure intensity objective (Dt) is given as
19. Functional cohesion means
l0 æl ö l0 æl ö
(a) Operations are part of single functional task and are (a) Dt = Ln ç F ÷ (b) Dt = Ln ç P ÷
placed in same procedures V0 è lP ø V0 è lF ø
(b) Operations are part of single functional task and are
placed in multiple procedures V0 æl ö V0 æl ö
(c) Dt = Ln ç F ÷ (d) Dt = Ln ç P ÷
(c) Operations are part of multiple tasks l0 è lP ø l0 è lF ø
(d) None of the above
20. The module in which instructions are related through flow of 31. What is software engineering?
control is (a) Set of computer programs, procedures and possibly
(a) Temporal cohesion (b) Logical cohesion associated document concerned with the operation of
(c) Procedural cohesion (d) Functional cohesion data processing.
21. Language level is defined as (b) Software engineering is Design, Coding, Development
(a) l = L3V (b) l = LV (c) Software engineering implement a single independent
(b) l = LV* (d) l = L2V function
22. Program weakness is (d) Software engineering is the establishment and use of
(a) WM = LV ´ g (b) WM = LV / g sound engineering practice in order to produce
economical and reliable software that will perform
(c) WM = LV + g (d) None of the above efficiently on real machine
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-503
32. The most important feature of spiral model is 45. Adaptive maintenance is related to
(a) requirement analysis. (a) Modification in software
(b) risk management. (b) Modification in software due todemand of new
(c) quality management. functionalities
(d) configuration management. (c) Modification in software due to increase in complexity
33. Which level of CMM is for basic project managment? (d) Modification in software in software too mtach change
(a) Initial (b) Repeatable in the everchanging environment
(c) Defined (d) Managed 46. Perfective maintenance refers to enhancements
34. The worst type of coupling is (a) Making the produce better
(a) Data coupling. (b) Making the product faster and smaller
(b) control coupling. (c) Making the product with new functionalities
(c) stamp coupling. (d) All of the above
(d) content coupling. 47. The purpose of regression testing is to
35. For a function of n variables,boundary value analysis yields: (a) increase confidence in the correctness of the modified
(a) 4n + 3 test cases (b) 4n + 1 test cases program
(c) n + 4 test cases (d) None of the above (b) locate errors in the modified program
36. For a function of n variables robustness testing boundary (c) preserve the quality and reliability of software
value analysis yields: (d) all of the above
(a) 4n + 1 (b) 4n + 3 48. Legacy systems are
(c) 6n + 1 (d) None of the above (a) old systems (b) new systems
37. Decision tables are useful for describing situations in which (c) undeveloped systems (d) none of the above
(a) An action is taken under varying sets of conditions 49. Which one is not a user documentation?
(b) Number of combinations of actions are taken under (a) Beginner’s guide (b) Installation guide
varying sets of conditions (c) SRS (d) System adminstration
(c) No action is taken under varying sets of conditions 50. IEEE 830-1993 is a IEEE recommended standard for
(d) None of the above (a) Software requirement specification.
38. One weakness of boundary value analysis and equivalence (b) Software design.
partitioning is (c) Testing.
(a) They are not effective (d) Both (A) and (B)
(b) They do not explore combinations of input 51. The proces of transforminga model into source code is
circumstances (a) Reverse Engineering (b) Forward engineering
(c) They explore combinations of input circumstances (c) Re-engineering (d) Restructing
(d) None of the above 52. Application software
39. Cyclomatic complexity is denoted by (a) is used to control the operating system
(a) V(G) = e – n + 2P (b) includes programs designed to help programmes
(b) V(G) = P + 1 (c) performs a specific task for computer users
(c) V(G) = number of regions of the graph (d) All of the above
(d) All of the above 53. The set of activities involved in carrying out an information
40. In data flow testing, objective is to find system is called
(a) All dc-paths that are not du-paths (a) software development cycle
(b) All du-paths (b) software development life cycle
(c) All du-paths that are not dc-paths (c) software design cycle
(d) All dc-paths (d) system development activities
41. The overhead code required to be written for unit testing is 54. The first step in SDLC is
called (a) requirement analysis
(a) Drivers (b) Stubs (b) system analysis
(c) Scaffolding (d) None of the above (c) preliminary investigation
42. Integration testing techniques are (d) system design
(a) Topdown (b) Bottom up 55. The prototype built initial version is called
(c) Sandwich (d) All of the above (a) parallel system (b) cut-over system
43. Top down approach is used for (c) phase-in system (d) pilot system
(a) Development (b) Identification of faults 56. The document prepared after system analysis is
(c) Validation (d) Functional Testing (a) system requirement specification
44. Regression testing is primarily related to (b) requirement determination document
(a) Functional testing (b) Data flow testing (c) testing manual
(c) Development testing (d) Maintence testing (d) analysis document
EBD_7203
S3-504 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
57. One of the fault base testing techniques is 71. A term XYZ is working on a software project. They have
(a) unit testing. (b) beta testing. divided the project in 5 major functionalities along with their
(c) Stress testing. (d) mutation testing. estimates of the size of each functionality
58. Structured English is otherwise called as
Functionality Optimistic Most Pessimistic
(a) pseudo design
(b) program design language 1. 25 30 45
(c) code language 2. 30 35 40
(d) program language 3. 15 20 25
59. Prototyping paradigm can be called as 4. 20 22 25
(a) use case diagram (b) object oriented design 5. 16 21 20
(c) structuring (d) throw way prototyping
60. Changes made to an information system to add the desired (i) Find the expected value of LOC for functionality.
but not necessarily the required features is called (a) 31.60 (b) 30.33
(a) Preventative maintenance. (c) 30 (d) None of these
(b) Adaptive maintenance. (ii) Find the estimate (in terms of KLOC) for the whole
(c) Corrective maintenance. project.
(d) Perfective maintenance. (a) 125 KLOC (b) 130 KLOC
61. Design phase in SDLC includes (c) 134 KLOC (d) Cannot be determined
(a) user interface design (iii) Find the cost of entire project when the arrange cost
(b) project report design for this type of project is $250 per KLOC.
(c) test case design (a) Can’t be determined (b) $32500
(d) quality design (c) $25000 (d) $12650
62. The input design should not required forces mainly on 72. Match the following:
(a) user friendly design Basic Measures Description
(b) graphic usage 1. Budgeted cost of work (A)The sum of estimated
(c) data effort for each work task
(d) innovation that was scheduled to be
63. Case tools are used mainly for completed by the speci-
(a) ease (b) revision fied time.
(c) reusability (d) research 2. Budgeted cost of work (B) The sum of the estimated
64. Basis path testing falls under scheduled efforts for the work tasks
(a) system testing (b) white box testing that h ave been
(c) black box testing (d) unit testing completed
65. SRS is prepared at the culmination of the
3. Budgeted cost of work (C) The estimated effort for
(a) requirement determination
performed each work task
(b) analysis
(a) 1-(C), 2-(A), 3-(B) (b) 1-(C), 2-(B), 3-(A)
(c) design
(c) 1-(B), 2-(A), 3-(C) (d) 1-(A), 2-(C), 3-(B)
(d) development
73. Match the following:
66. The number of occurrence of objects in a given relationship
1. Project risks (A) Maintenance problems
is
2. Technical risks (B) Requirement problems
(a) modality (b) numeric constant
3. Business risks (C) Losing budgetary or
(c) cardinality (d) correlation constant
personal commitment
67. Errors occurring at one location and propagate through a
system in called (a) 1-(B), 2-(A), 3-(C) (b) 1-(A), 2-(C), 3-(B)
(a) parallel errors (b) phase-in errors (c) 1-(C), 2-(B), 3-(A) (d) None of these
(c) ripple effect (d) cascading 74. Find the odd man out.
68. The primary activity during data design is Software configuration management, software, quality
(a) logical representation assurance, software project planning, process change
(b) physical representation management
(c) preliminary investigation (a) Processes change management
(d) feasibility study (b) Software project planning
69. When a segment of a DFD exhibits data flow, it is called (c) Software quality assurance
(a) transform flow (b) incoming flow (d) Software configuration management
(c) information flow (d) overall flow 75. Match the following:
70. The path in which data flow is depicted is called 1. Identification (A) helps to ensure that the
(a) flow path (b) action path change has been
(c) data path (d) information path properly implemented
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-505
2. Version (B) manages different 82. In a software project, Cocomo is used to estimate
versions of configuration (a) effort and duration based on the size of the software
object (b) size and duration based on the size of the software
3. Configuration audit (C) naming each software (c) effort and cost based on the duration of the software
configuration item (d) size, effort and duration based onthe cost of the software
(D) Takes final decision on 83. To carry out white box testing of a program, in flow chart
the status and priority of representation is obtained as shown in the figure below.
change
(a) 1-(B), 2-(D), 3-(A) (b) 1-(C), 2-(C), 3-(A) S=0
(c) 1-(C), 2-(B), 3-(A) (d) 1-(C), 2-(B), 3-(D)
76. If an error happens every 2 days, what is the probability that
the system will not fail for 4 days? i=1
(a) 0.5 (b) 0.25
(c) 0.375 (d) 0.0625
77. A software configuration management tool helps in i>R
(a) keeping track of the schedule based on the milestones
reached
(b) maintaining different versions of the configuration items
(c) managing manpower distribution by changing the
project structure i>R
(d) All of the above
78. A software organization has been assessed to SE1 CMM
Read f
level -4. Which of the following does the organization need S=S+i
to practice beside process change management and
technology change management in order to achieve level-5?
S=S+F
(a) Defect detection (b) Defect prevention
(c) Defect isolation (d) Defect propagation
79. A software project involves execution of 5 tasks T 1, T2, T3,
T4 and T5 of duration 10, 15, 18, 30 and 40 days respectively
i=i+1
T2 and T4 can start only after T1 completes. T3 can start
after T2 completes. T4 can slack time of the task T3 in days?
(a) 0 (b) 3
(c) 18 (d) 30
Print, S
80. Match the following:
1. Coupling (A) strength of relations
within a module
2. Span of control (B) number of instructions For basis path based testing this program, its cyclomatic
composing a module complexity is
3. Size (C) number of modules (a) 4 (b) 4
subordinate to calling (c) 3 (d) 2
module 84. Consider the following program module int model (int x,int y)
(D) The strength of relation while (x! = y) {
between modules if (x >y)
(a) 1-(C), 2-(A), 3-(B) (b) 1-(B), 2-(A), 3-(C) x = x-y;
(c) 1-(C), 2-(B), 3-(A) (d) 1-(A), 2-(C), 3-(B) else
81. Match the following: {
A B y = y-x;
1. Consistency (A) comparable actions }
have return x;
comparable effects }
2. Minimal Surprise (B) the underlying What is a cyclomatic complexity of the above module?
implementation of the (a) 1 (b) 2
files and data structures (b) 3 (d) 4
should be hidden from 85. What are commonly used to predict the performances of an
user unknown system on a known or atleast will defined task or
3. User Familiarity (C) command punctuation
workload?
should be similar
(a) 1-(C), 2-(A), 3-(B) (b) 1-(B), 2-(A), 3-(C) (a) Benchmrks (b) Test cases
(c) 1-(C), 2-(B), 3-(A) (d) 1-(A), 2-(C), 3-(B) (c) Programmers (d) Beta testing methods
EBD_7203
S3-506 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
86. According to PUTMAN, project effort is inversely 96. Using public key cryptography, X adds a digital signature s
proportional to the fourth power of development time, to message M, encrypts <M, s>, and sends it to Y, where it
doubling the development schedule for a 100 person-month is decrypted. Which one of the following sequences of keys
project would reduce the project effort to is used for the operations?
(a) 50 PM (b) 7.16 PM (a) Encryption: X’s private key followed by Y’s private
(c) 25 PM (d) 6.25 PM key; Decryption: X’s public key followed by Y’s public
87. The two phases in documentation testing are key
(a) task testing, behavioral testing (b) Encryption: X’s private key followed by Y’s public key;
Decryption: X’s public key followed by Y’s private key
(b) review and inspection, live test
(c) Encryption: X’s public key followed by Y’s private key;
(c) alpha testing, beta testing
Decryption: Y’s public key followed by X’s private key
(d) documentation testing, quality testing
(d) Encryption: X’s private key followed by Y’s public key;
88. Errors may be found by outside during Decryption: Y’s private key followed by X’s public key
(a) alpha testing (b) white box testing 97. The different types of software maintenance systems are
(c) beta testing (d) Both (a) and (b) (a) Corrective maintenance
89. Top-down design does not require (b) Adaptive maintenance
(a) stepwise refinement (b) flow charting (c) Perfective maintenance
(c) loop invariants (d) modularity (d) All the above
90. Acceptance testing is 98. The main design activities in the software design process
(a) making sure that the new program do in fact process are
certain transactions according to specifications. (i) System specification iii) Component design
(b) running the system with line data by the actual user (ii) interface design iv) algorithm design
(c) is checking the logic of one or more programs in the (a) ii, iii and iv only (b) i, ii and iii only
candidates system (c) i, iii and iv only (d) All i, ii, iii and iv
(d) testing change made in an existing or a new program 99. Waterfall model is not suitable for ?
91. The advantage of better testing in software development is (a) Small Projects
in (b) Complex Projects
(a) interactive (b) prototyping (c) Accommodating change
(c) waterfall model (d) All of these (d) None of Above
92. Sequential or series testing is 100. Milestones are used to ?
(a) testing changes made in an existing or a new program (a) Know the cost of the project
(b) is checking the logic of one or more program in the (b) Know the status of the project
candidate system (c) Know the user expectations
(c) making sure that the new programs do in fact process (d) None of the above
certain transactions according to specifications 101. Black box testing sometimes called ?
(d) running the system with line data by the actual user (a) Data Flow testing (b) Loop Testing
93. All the modules of the system are integrated and tested as (c) Behavioral Testing (d) Graph Based Testing
complete system in the case of 102. Which of the following is a type of testing ?
(a) Bottom up testing (b) Top-down testing (a) Recovery Testing (b) Security Testing
(c) Sandwich testing (d) Big-Bang testing (c) Stress Testing (d) All of above
94. The model in which the requirements are implemented by 103. The objective of testing is ?
category is (a) Debugging (b) To uncover errors
(a) Evolutionary Development Model (c) To gain modularity (d) To analyze system
(b) Waterfall Model 104. ...... is a black box testing method ?
(c) Prototyping (a) Boundary value analysis
(d) Iterative Enhancement Model (b) Basic path testing
95. SRD stands for (c) Code path analysis
(a) Software requirements definition (d) None of above
(b) Structured requirements definition 105. Structured programming codes includes ?
(c) Software requirements diagram (a) sequencing (b) alteration
(d) Structured requirements diagram (c) iteration (d) All A, B and C
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-507
106. Match the following: printf("even");
1. Document re-structuring (A) review data structure } else {
2. Code re-structuring (B) update internal code printf("odd");
3. Data re-structuring (C) useful and relevant }
document are developed }
(a) 1-(A), 2-(B), 3-(C) (b) 1-(C), 2-(B), 3-(A) }
(c) 1-(C), 2-(A), 3-(B) (d) 1-(A), 2-(C), 3-(B) 112. Calculate the cyclomatic complexity of the program below.
107. Which of the following is not a KPA (Key Process Area) IF A = 354
required for obtaining maturity level 4 (managed)? THEN IF B > C
(a) Process change management THEN A = B
(b) Software quality management ELSEA= C
(c) Quantitative process ENDIF
(d) Both (a) and (c) ENDIF
108. What is a measure of the number functions that call some
Print A
other functions (x) and what is the number of functions
113. Given that lines of code is 200 KLOC for an organization's
which are called by function (x)?
online system , calculate the effort in person months for
(a) Cohesion, Coupling
(b) Fan-out, Fan-in Embedded modes of basic Cocomo.
(c) Reference index, Net procedure calls 114. Using the following table for reference, calculate the effort in
(d) None of the above person months , development time and the average number
109. Arrange the following in descending order of number of of people required for a small firm having 10KLOC for the
communication paths. their unit.
1. Democratic teams Organic - small to medium size, familiar project
2. Chief programmer teams Person-months = 2.4(KLOC)1.05
3. Controlled decentralized team Development-time = 2.5(PM).38
(a) 1, 2 and 3 (b) 2, 1 and 3 115. What is the availability of a software with the following
(c) 3, 2 and 1 (d) 1, 3 and 2 reliability figures?
110. Let M be a node that represents a if-then-else node in a Mean Time Between Failure (MTBF) = 25 days
program graph. Let the number of paths from its. If part of
Mean Time to Repair (MTTR) = 6 hr
the end node is y, and from the else part to the end node is
z. If the number of paths from the start node to the node M 116. The availability of a complex software is 90% its Means
is x, then the total number of paths through M is Time Between Failure (MTBF) is 200 days. Because of the
(a) xy + z (b) xz + y critical nature of the usage, the organization deploying the
(c) x + y + z (d) x(y + z) software further enhanced it to obtain an availability of 95%.
In the process the Mean Time To Repair (MTTR) increased
NUMERICAL TYPE QUESTIONS by 5 days. What is MTBF of the enhanced software ?
111. What is the cyclomatic complexity of the following program? 117. Assuming that the tests are representative of the operational
void func(i) { situation, calculate the reliability of a software system that
while (i<10) { has 10 errors in 200 cases.
i++; 118. According to PUTMAN, project effort is inversely
printf("i is %d", i); proportional to the fourth power of development time,
if (i%2 == 0) { doubling the development schedule for a 100 person-month
project would reduce the project effort to
EBD_7203
S3-508 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Initiation Step II
Step I
The answer of the match of the following can be obtained 5. (c) Test cases T1 and T2 both are examples of a = 0. Thus,
from the above figure. We know that the software T1 and T2 are redundant.
development is a process which is done stepwise. The left For T3 discriminant 62 – 4ac = 4 – 4 = 0
hand side of the match the following is mentioned in the For T4 discriminant 62 – 4ac = (– 12)2 – 4 × 9 × 4
figure above along with the step. With this we can assume = 144 – 144 = 0
the answer. For T5 discriminant 62 – 4ac = (– 2)2 – (– 3) × 4 × 1
4. (a) Individual cyclomatic complexity = 10 = 4 + 12 = 16 > 0
Now, in the cases of sequential integration, the general Thus T5 is example of discoinminant > 0
behaviour is that the complexity is decreased than the For T6 discriminant 62 – 4ac = (1)2 – 4 × 1 × 4
two independent modules. This decrease is unitary and = 1 – 16 = – 13
hence the answer is 19 (10 + 10 – 1 = 19). Thus T6 is example of discriminant < 0.
means T3 and T4 are also redundant.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-509
6. (d)Algorithm for software implementation As shown in the above diagram the documentation
7. (a)Effort (person per month) manuals are not part of the procedure manuals.
= a × (kLOC)6 [6 = exponent a = multiplicative value,]
= 2.8 × (40)1.20 2. (b) An efficient process is required to produce good quality
= 234.22 person per month products.
8. (a) Suppose, LOC of project L1 is x. 3. (a) Generic products are developed for anonymous
The LOC of project L2 is 2x. customers. The target is generally the entire world and
Cost of project L1 many copies are expected to be sold. Infrastructure
= Development cost + Maintenance cost software like operating systems, compilers, word
= Manyears × Development cost/year + Maintenance processors etc are covered under this category.
time × Maintenance cost/year
4. (d) 3 P’s as it is known
x
= ´ 1000000 + 5 ´ 100000 People- The primary element of any project is the people.
10000
= 100 x + 500000 People gather requirements, people interview users
Cost of project L2, (people), people design software, and people write
= Development cost + Maintenance cost software for people. No people , no software
2x Process- Process is how we go from the beginning to
= ´ 750000 + 5 ´ 50000 the end of a project. All projects use a process. Many
10000
= 100 × x + 500000 = 150 × x + 250000 project managers, however, do not choose a process
100 × x + 250000 = 150 × x based on the people and product at hand
50 x = 250000 Product- The product is the result of a project. The
x = 5000 desired product satisfies the customers and keeps them
9. (b) 1–d, 2–a, 3–b, 4–c coming back for more
In Evolutionary model softwares evolve so
specification can be developed incrementally. 5. (d) In the context of software engineering, software quality
In waterfall model inflexible partitioning of the project refers to two related but distinct notions that exist
into stages need to be done. wherever quality is defined in a business context:
10. (c) Prototyping is a method of requirements validation · Software functional quality reflects how well it
11. (b) In the content of modular software design these
should be high cohesion, since cohesion is measure complies with or conforms to a given design,
of internal strength within a module. The coupling based on function al requiremen ts or
is measure of interdependency among modules, so specifications. That attribute can also be described
it should be low. as the fitness for purpose of a piece of software
PRACTICE EXERCISE or how it compares to competitors in the
marketplace as a worthwhile product
1. (c) · Software structural quality refers to how it meets
Acts
and
non-functional requirements that support the
Regulations delivery of the functional requirements, such as
robustness or maintainability, the degree to which
the software was produced correctly.
6. (c) This is basically an adhocapproach to maintaining
Central Collective
Government Agreements software. It is a firefighting approach, waiting for the
Directives
problem to occur and then trying to fix itas quickly as
possible
Organization 7. (d)
Policy
Manual 8. (b) Spiral Model addresses the problem of requirements
engineering through development of prototypes, and
it addresses the need for risk management.
9. (c) The SDLC must be designed in such a way as to take
Department maximum advantage .Rework occurs due to such things
Policy &
Procedure
as errors and changes in scope and while preparing
Manuals specifications.This is usually defined as a percentage,
qualified.
10. (c) The activities involved in requirements engineering
vary widely, depending on the type of system being
developed and the specific practices of the
organization(s) involved.
Computer Operations & Field
User
Training
Manuals Maintenance Guides
Reference
Manuals
1. Requirements inception or requirements elicitation -
Manuals Manuals
2. Requirements identification - identifying new
requirements
EBD_7203
S3-510 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
3. Requirements analysis and negotiation - checking 1. Initial. The software process is characterized as
requirements and resolving stakeholder conflicts ad hoc, and occasionally even chaotic. Few
4. Requirements specification (Software processes are defined, and success depends on
Requirements Specification) - documenting the individual effort and heroics.
requirements in a requirements document 2. Repeatable. Basic project management processes
5. System modeling - deriving models of the system, are established to track cost, schedule, and
often using a notation such as the Unified functionality. The necessary process discipline
Modeling Language is in place to repeat earlier successes on projects
with similar applications.
6. Requirements validation - checking that the
3. Defined. The software process for both
documented requirements and models are
management and engineering activities is
consistent and meet stakeholder needs
documented, standardized, and integrated into a
7. Requirements management - managing changes standard software process for the organization.
to the requirements as the system is developed All projects use an approved, tailored version of
and put into use the organization's standard software process for
These are sometimes presented as chronological stages developing and maintaining software.
although, in practice, there is considerable interleaving 4. Managed. Detailed measures of the software
of these activities. process and product quality are collected. Both
11. (b) the software process an d pr oducts are
12. (a) A data flow diagram (DFD) is a graphical representation quantitatively understood and controlled.
5. Optimizing. Continuous process improvement is
of the “flow” of data through an information system,
enabled by quantitative feedback from the process
modeling its process aspects.
and from piloting innovative ideas and
13. (c) 14. (b) 15. (c) 16. (c) 17. (a) technologies.
18. (c) Temporal cohesion is when parts of a module are 34. (d)
grouped by when they are processed - the parts are 35. (b) Boundary value analysis Boundary value analysis can
processed at a particular time in program execution (e.g. be applied on the input variables and on the kinds of
a function which is called after catching an exception ranges (output).In the case of basing the analysis on
which closes open files, creates an error log, and notifies the input, we hold all but one of the variables at the
the user.In temporal cohesion elements must be used nominal value and let the remaining variable assume
at approximately the same time. min, min+, nom, max-& max. (5 cases for each var.)In
19. (a) Functional cohesion meansFunctional cohesion is when this case all variables will be held at their nominal values
parts of a module are grouped because they all n times, where n=number of variables being tested.It is
contribute to a single well-defined task of the module useless to repeat the test n times when we could only
(e.g. tokenizing a string of XML). do it once.Therefore we have 5 cases -nominal = 4 cases
for each variable = 4n test cases for all variables We
20. (c) 21. (d) 22. (a) 23. (a) 24. (b) then add the test case where all varsare nom.Thus for
25. (a) It follows from the definitions of length and vocabulary a function of n variables, boundary value analysis yields
that anyprogram must consist of N non-random 4n+1 test cases.
selections from a list of n items.Assuming that the 36. (c) 37. (b) 38. (b) 39. (d)
selection process approximates a binary search, then 40. (d) Steps for Data Flow Testing
the total number of mental comparisons required would Draw the Program flow graph
equal the programvolume which is defined as
· Find the DD path Graph
V = Nlog2n
· Prepare a table for define/use status of all variable
26. (d) 27. (d) 28. (a) 29. (b)
· Find all du-paths
30. (d) 31. (d) 32. (b)
· Identify du paths that are not dc paths
33. (b) The Capability Maturity Model for Software describes
41. (c)
the principles and practices underlying software
process maturity and is intended to help software 42. (d) Different Types of Integration Testing are
organizations improve the maturity of their software · Big Bang Testing
processes in terms of an evolutionary path from ad · Top-down Testing
hoc, chaotic processes to mature, disciplined software · Bottom-up Testing
processes. The CMM is organized into five maturity
· Performance vs. Load vs. Stress Testing
levels:
· Sandwich Testing
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-511
43. (b) Top-down methodology, based upon fault tree 67. (c) correctErrors occurring at one location and propagate
analysis, that has been used to identify potential high- through asystem in called ripple effect.Any error that
consequence faults. occurs into the propagation makes the system fails.
44. (d) Regression testing is primarily related to maintence Which is also called RIPPLE EFFECT ANALYSIS,
testing. When a particular problem is identified, the 68. (a) 69. (a) 70. (a)
programs will be debugged and the fix will be done to 71. (i) (a) We know that expected value of S (for LOC) is
the program. To make sure that the fix works, the calculated as
program will be tested again for that criteria. Regression
S = (Sopt + 4Sm + Spess)/6
test will make sure that one fix does not create some
other problems in that program or in any other interface. S = (Smax + 4Sbest + guess + Smin)/6
So, a set of related test cases may have to be repeated = (20 + 4 × 30 + 50)/6 = 190/6 = 31.6 KLOC
again, to make sure that nothing else is affected by a (ii) (c) Using the the same formula as used in previous
particular fix. problem, we will first find the expected value of LOC
45. (d) Adaptive includes modifying the software to match S = (10 + 4 × 15 + 25)/6
changes in the ever changing environment. S = 96/6 =15.8/ KLOC
46. (d) Perfective maintenance is a system of making data input Effort required = 15.8/5 = 3.16 PM = 3 PM
screen a better one to deal with. It has a more advance (iii) (b) First we will find the expected value of LOC for both
system to work with, correcting error in a more unique the project combined
and perfect way. S = S1 +S2.
47. (d) = (15 + 4 × 20 + 25)/6 + (10 + 4 × 12 + 14)/6
48. (a) Legacy systems are obsolete computer system that may = 120/6 + 72/6 = 32 KLOC
still be in use because its data cannot be changed to \ Cost is 20$ for 100 LOC
newer or standard formats 200$ for 1000 LOC
49. (c) 50. (a) i.e.,100$ KLOC
\ Expected cost of sub-parts 5 and 6
51. (b) The proces of transforminga model into source code is
= 32 × 200 = 6400$
Forward engineering which is used to transform models
72. (c) 73. (a)
into other models or into code and documentation.
74. (d) See project planning and management for details in the
52. (a) Applications Software does the specific things you want theory you will find that the a, b and c option are part
the computer to do, Whereas the Operating System is of the above while option d software configuration
general instructions to the computer for controlling. management falls under different genre .
53. (c) 54. (b) 55. (d) 56. (a) 57. (d) 58. (b) 75. (a)
59. (d) Throwaway prototyping 76. (c) The overall risk exposure is determined using the
Also called close-ended prototyping.Throwaway or following relationship
Rapid Prototyping refers to the creation of a model RE = P × C
that will eventually be discarded rather than becoming where, P is the probability of occurrence of risk and is
part of the final delivered software. After preliminary the project should the risk occur.
requirements gathering is accomplished, a simple \ RE = 60% × 120,00 = $16000
working model of the system is constructed to visually 77. (d) Reliability is the probability that not failing in a specified
show the users what their requirements may look like length of time. This is usually denoted by [R(n)] where
when they are implemented into a finished system. n is days, then R(1) is the probability of not failing in 1
days. If we know R(1),then the probability that we can
60. (d) execute for n days without failure is
61. (a) User Interface or UI Development is a very important R(n) = R(1)n.
part of software development life cycle. Starting from a Here, an error happen every two days
small web site development to application or software F(1) = 0.5
development, User Interface plays a very important R(1) = 1 – F(1) = 1– 0.5 = 0.5
role. R(4) = R(1)4 = (0.5)4 = 0.0625
62. (a) So, the probability that the system will not fail for 4
63. (c) CASE tools are mainly suitable for evaluation in days is 0.0625.
industrial environments .The ease with which new users 78. (b) A critical distinction between maturity level 4 and
can construct a mental model of the CASE tool is the maturity level 5 is the type of process variation
main advantage of a case tool. addressed. At maturity level 4, processes are concerned
with addressing special causes of process variation
64. (b) 65. (b) 66. (c)
and providing statistical predictability of the results.
EBD_7203
S3-512 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Though processes may produce predictable results,
the results may be insufficient to achieve the
established objectives. At maturity level 5, processes C I=1
are concerned with addressing common causes of While C do S; For loop:
process variation and changing the process (that is, F for I = 1 to n do S;
shifting the mean of the process performance) to T S
S yes
improve process performance (while maintaining
statistical predictability) to achieve the established I <= n
quantitative process-improvement objectives. no
Level 5 CMM Key performance area is Defect
Prevention.
79. (b) 80. (b) 81. (a) S1 Do loop:
82. (c) In a software project, Cocomo is used to estimated effort
and cost based on the duration of the software. do S1 until C;
83. (a) First understand the concept of cyclomatic comlexity F
Cyclomatic complexity is a software metric -> provides C
a quantitative measure of the global complexity of a
T
program.
When this metric is used in the context of the basis
path testing, the value computed for cyclomatic Example
complexity defines the number of independent paths
in the basis set of a program.
Three ways to compute cyclomatic complexity: 1 node
· The number of regions of the flow graph
correspond to the cyclomatic complexity.
· Cyclomatic complexity, V(G), for a flow graph G is edge 3
2
defined as
V(G) = E - N + 2
where E is the number of flow graph edges and N
4
is the number of flow graph nodes.
· Cyclomatic complexity, V(G) = P + 1
where P is the number of predicate nodes
contained in the flow graph G. 5
6
C
If C Then S1 else S2;
Sequential
statement block
S1 S2 7
C Case C of
In the above example
C No. of regions = 4
L1 : S1; If C Then S1; (considering the universal region)
S1 Sn L2 : S2;
… No. of edges = 9
Kn : Sn; S1
end; No. of nodes = 7
No. of predicate nodes = 3
V(G) = 3 + 1 = 4
V(G) = 9 - 7 + 2 = 4
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-513
84. (c) In basic path testing the value of the complexity measure 111. 3 The flow graph can be drawn as follows
is equal to the cyclomatic complexity of the flow graph
if all the edges were undirected instead of direction.
So, cyclomatic complexity = e – n + 2
where, e is the number of edges
n is the number of nodes
e = 10 n = 9
Cyclomatic complexity = 10 – 9 + 2 = 3
85. (a) Benchmarks are commonly used to predict the
performance of an unknown system on a known, or at
least well-defined, task or workload.
86. (d) There are X number of paths from the root node to the
node M. Since,the node M represents a if-then-else
statement. It can take either true case or false. So, the
total number of paths will be
x(y + z)
87. (d) 88. (b) 89. (c) 90. (c) 91. (b) 92. (a)
93. (d) 94. (a) 95. (b) 96. (d) 97. (d) 98. (d)
99. (c) Waterfall model does not accommodate any change V(G) = 2 decisions + 1 = 3
that's why this model is used in those situations where 112. 3
requirements are well understood.
100. (a) Milestones are used to measure the process or status If A = 354
of the project
101. (c) Black box testing is a method that tests for the
functionality of an application.
102. (d) Recovery testing is a method for testing how well a If B > C
software can recover from crashes. Security testing
ensures that the software protects the data and
performs its all functions. Stress testing determines the
robustness of software. A= C A= B
103. (b) The main objecting of testing is to make the software
error free.
104. (a) In boundary value analysis, we choose an input from ENDIF
test cases from an equivalence class such that the input
lies on the edge of equivalence class.
105. (d) These three constructs are sufficient to program any ENDIF
algorithm. Moreover, as far as possible single entry
single exit control constructs are used.
106. (b) Print A
107. (a)
108. (d)
Control flow of a simple program
109. (d) The control flow shows seven nodes (shapes) and
110. (d) There are X number of paths from the root node to th eight edges (lines), thus using the formal formula the
node M. Since, the node M represents a if-then-else cyclomatic complexity is 8-7 + 2 = 3.
statement. It can take either true case or false. So, the total Alternatively we can calculate the cyclomatic
number of paths will be complexity using the decision points rule. Since there
are two decision points, the cyclomatic complexity is
x( y + z ) 2 + 1 = 3.
EBD_7203
S3-514 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
113. 2077 MTBF1 = MTTF1 + MTTR1
Mode Effort Formula 200 = MTTF1 + X
Organic E = 2.4*(S1.05) MTTF1 = 200 – X
Semidetached E = 3.0*(S1.12)
é MTTF1 ù
Embedded E = 3.6 * (S1.20) A1 = ê ú ´100%
Size = 200 KLOC ë MTTF1 + MTTR1 û
Organic – E = 2.4 × (2001.05) = 626 staff-months
Semidetached – E = 3.0 × (2001.12) = 1133 staff-months é 200 - X ù
90 = ê ú ´ 100 Þ 200 - X = 180°
Embedded – E = 3.6 × (2001.20) = 2077 staff-months ë 200 - X + X û
114. 3 X = 20
Using organic model: MTTR1 = 20
Person-months = 2.4(10)1.05 = 26.9 Person-months Case II
Development-time = 2.5(26.9).38 = 8.7 Months Availability A2 = 95%
Average People = 26.9 PM/8.7 Months = 3 People Mean Time To Repair (MTTR2) = X + 5 = 25
COMPUTER NETWORKS
O Ø
Ø
LAN technologies (Ethernet, Token ring)
N Ø Routing Algorithms
T Ø
Ø
Congestion Control
E Ø
smtp, pop, ftp, http)
T
S
EBD_7203
S3-516 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
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
Layer 1 – Physical - Physical layer defines the cable or have to break large datagrams, larger than MTU, into smaller
physical medium itself, e.g., thinnet, thicknet, unshielded packets and host receiving the packet will have to reassemble
twisted pairs (UTP). All media are functionally equivalent. The the fragmented datagram. The Internetwork Protocol identifies
main difference is in convenience and cost of installation and each host with a 32-bit IP address. IP addresses are written as
maintenance. Converters from one media to another operate at four dot-separated decimal numbers between 0 and 255, e.g.,
this level. 129.79.16.40. The leading 1-3 bytes of the IP identify the
Layer 2 – Data Link - Data Link layer defines the format of data network and the remaining bytes identify the host on that
on the network. A network data frame, aka packet, includes network.
checksum, source and destination address, and data. The Even though IP packets are addressed using IP addresses,
largest packet that can be sent through a data link layer defines hardware addresses must be used to actually transport data
the Maximum Transmission Unit (MTU). The data link layer from one host to another. The Address Resolution Protocol
handles the physical and logical connections to the packet’s (ARP) is used to map the IP address to it hardware address.
destination, using a network interface. A host connected to an Layer 4 - Transport - Transport layer subdivides user-buffer
Ethernet would have an Ethernet interface to handle connections into network-buffer sized datagrams and enforces desired
to the outside world, and a loopback interface to send packets transmission control. Two transport protocols, Transmission
to itself. Ethernet addresses a host using a unique, 48-bit Control Protocol (TCP) and User Datagram Protocol (UDP), sits
address called its Ethernet address or Media Access Control at the transport layer. Reliability and speed are the primary
(MAC) address. MAC addresses are usually represented as six difference between these two protocols. TCP establishes
colon-separated pairs of hex digits, e.g., 8:0:20:11:ac:85. This connections between two hosts on the network through
number is unique and is associated with a particular Ethernet ‘sockets’ which are determined by the IP address and port
device. Hosts with multiple network interfaces should use the number. TCP keeps track of the packet delivery order and the
same MAC address on each. The data link layer’s protocol- packets that must be resent. Maintaining this information for
specific header specifies the MAC address of the packet’s each connection makes TCP a stateful protocol. UDP on the
source and destination. When a packet is sent to all hosts other hand provides a low overhead transmission service, but
with less error checking. NFS is built on top of UDP because
(broadcast), a special MAC address (ff:ff:ff:ff:ff:ff) is used.
of its speed and statelessness. Statelessness simplifies the
Layer 3 – Network- NFS uses Internetwork Protocol (IP) as its
crash recovery.
network layer interface. IP is responsible for routing, directing
datagrams from one network to another. The network layer may
COMPUTER NETWORKS S3-517
Layer 5 - Session - The session protocol defines the format of TCP/IP Network Model
the data sent over the connections. The NFS uses the Remote TCP/IP is designed around a simple four-layer scheme. It does
Procedure Call (RPC) for its session protocol. RPC may be built omit some features found under the OSI model. Also it
on either TCP or UDP. Login sessions uses TCP whereas NFS combines the features of some adjacent OSI layers and splits
and broadcast use UDP. other layers apart. The four network layers defined by TCP/IP
Layer 6 - Presentation - External Data Representation (XDR) model are as follows.
sits at the presentation level. It converts local representation of Layer 1 – Link - This layer defines the network hardware and
data to its canonical form and vice versa. The canonical uses device drivers.
a standard byte ordering and structure packing convention, Layer 2 – Network- This layer is used for basic communication,
independent of the host. addressing and routing. TCP/IP uses IP and ICMP protocols at
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,
rlogin, talk, ftp, ntp and traceroute.
Difference between OSI & TCP/IP Model:
OSI TCP/IP
OSI makes the distinction between TCP/IP does not originally clearly
services, interfaces, and protocol. distinguish between services, interface, and
protocol.
The OSI model was devised before the TCP/IP model was just a description of the
protocols were invented. It can be made existing protocols. The model and the
to work in diverse heterogeneous protocol fit perfectly.
networks
The OSI model supports both The TCP/IP model has only one mode in
connectionless and connection-oriented the network layer (connectionless) but
communication in the network layer, but supports both modes in the transport layer,
only connection-oriented giving the user choice.
communication in the transport layer.
OSI has seven layers: Application; TCP/IP has four layers: Application;
Presentation; Session; Transport; Transport; Internet; Host-to-network
Network; Data link; Physical
Preamble Start of Frame Delimiter Dest. Address Source Address Length 802.2 Header + Data Frame Checksum
(7 bytes) (1 byte) (2/6 bytes) (2/6 bytes) (2 bytes) (46-1500 bytes) (4 bytes)
Preamble :Each frame starts with a preamble of 7 bytes, each byte containing the bit pattern 10101010. Manchester encoding
is employed here and this enables the receiver’s clock to synchronize with the sender’s and initialise itself.
Start of Frame Delimiter :This field containing a byte sequence 10101011 denotes the start of the frame itself.
Dest. Address :The standard allows 2-byte and 6-byte addresses. Note that the 2-byte addresses are always local addresses
while the 6-byte ones can be local or global.
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.
Source Address :Refer to Dest. Address. Same holds true over here.
Length : The Length field tells how many bytes are present in the data field, from a minimum of 0 to a maximum of 1500.
The Data and padding together can be from 46bytes to 1500 bytes as the valid frames must be at least 64 bytes long, thus
if data is less than 46 bytes the amount of padding can be found out by length field.
Data :Actually this field can be split up into two parts - Data(0-1500 bytes) and Padding(0-46 bytes).
Reasons for having a minimum length frame :
• To prevent a station from completing the transmission of a short frame before the first bit has even reached the far
end of the cable, where it may collide with another frame. Note that the transmission time ought to be greater than
twice the propagation time between two farthest nodes.
transmission time for frame > 2*propagation time between two farthest nodes
• When a transceiver detects a collision, it truncates the current frame, which implies that stray bits and pieces of frames
appear on the cable all the time. Hence to distinguish between valid frames from garbage, 802.3 states that the minimum
length of valid frames ought to be 64 bytes (from Dest. Address to Frame Checksum).
Frame Checksum : It is a 32-bit hash code of the data. If some bits are erroneously received by the destination (due to
noise on the cable), the checksum computed by the destination wouldn’t match with the checksum sent and therefore the
error will be detected. The checksum algorithm is a cyclic redundancy checksum (CRC) kind. The checksum includes the
packet from Dest. Address to Data field.
Ethernet Frame Structure
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
A method to combine a data frame with ACK. Station A
value of R, the frame is accepted, otherwise rejected.
and B both have data to send.Instead of sending
separately, station A sends a data frame that includes an
ACK.Station B does the same thing.Piggybacking saves
bandwidth
Go-Back-N ARQ
We can send up to W frames before worrying about
ACKs.We keep a copy of these frames until the ACKs
arrive.This procedure requires additional features to be
added to Stop-and-Wait ARQ.
Sequence Numbers
Frames from a sender are numbered sequentially.We need
to set a limit since we need to include the sequence
number of each frame in the header.If the header of the
frame allows m bits for sequence number, the sequence
numbers range from 0 to 2m - 1. for m = 3, sequence
numbers are: 1, 2, 3, 4, 5, 6, 7.We can repeat the sequence
number.Sequence numbers are:
COMPUTER NETWORKS S3-523
Acknowledgement Selective Repeat ARQ, sender and receiver windows
Receiver sends positive ACK if a frame arrived safe and Go-Back-N ARQ simplifies the process at the receiver site.
in order. If the frames are damaged/out of order, receiver Receiver only keeps track of only one variable, and there is no
is silent and discards all subsequent frames until it need to buffer out-of-order frames, they are simply
receives the one it is expecting.For example, suppose the discarded.However, Go-Back-N ARQ protocol is inefficient for
sender has sent frame 6, but the timer for frame 3 expires noisy link. It bandwidth inefficient and slows down the
(i.e. frame 3 has not been acknowledged), then the sender transmission.In Selective Repeat ARQ, only the damaged frame
goes back and sends frames 3, 4, 5, 6 again. Thus it is is resent.It is more bandwidth efficient but more complex
called Go-Back-N-ARQ.The receiver does not have to processing at receiver.It defines a negative ACK (NAK) to
acknowledge each frame received, it can send one report the sequence number of a damaged frame before the
cumulative ACK for several frames. timer expires.
Go-Back-N ARQ, normal operation Selective Repeat ARQ, lost frame
The sender keeps track of the outstanding frames and
updates the variables and windows as the ACKs arrive.
Desirable
burstiness of traffic
– e.g. when a virtual circuit is set up, the user and the
Congested subnet first agree certain traffic shape for that circuit.
Monitoring traffic flow, called traffic policing, is left
to the subset
– Agreeing to a traffic shape and policing it afterward
are easier with virtual circuit subnets, but the same
Packets sent
ideas can be applied to datagram subnet at transport
Causes: The bursty nature of traffic is the root cause ? When
layer.
part of the network no longer
Leaky Bucket / Token Bucket
can cope a sudden increase of traffic, congestion builds upon.
Other factors, such as lack of Leaky bucket: consists of a finite queue
bandwidth, ill-configuration and slow routers can also bring up – When a packet arrives, if there is a room on the
congestion. queue its joins the queue; otherwise, it is discarded
Solution: congestion control, and two basic approaches – At every (fixed) clock tick, one packet is transmitted
Open-loop: try to prevent congestion occurring by good unless the queue is empty
design It eliminates bursts completely packets passed to the
Closed-loop: monitor the system to detect congestion, subnet at the same rate
pass this information to where action can be taken, and This may be a bit overdone, and also packets can get lost
adjust system operation to correct the problem (detect, (when bucket is full)
feedback and correct) Token bucket: Tokens are added at a constant rate. For
Open-Loop Congestion Control a packet to be transmitted, it must capture and destroy
one token
Prevention: Different policies at various layers can affect
(a) shows that the bucket holds three tokens with five
congestion, and these are summarised in the table
packets waiting to be transmitted
Transport Retransmission policy (b) shows that three packets have gotten through but
the other two are stuck waiting for tokens to be
Out-of-order caching policy
generated
Acknowledge policy
Unlike leaky bucket, token bucket allows saving, up to
Flow control policy maximum size of bucket n. This means that bursts of up
Timeout determination to n packets can be sent at once, giving faster response
Network Virtual circuit versus datagram to sudden bursts of input
Packet queueing, service & service policy An important difference between two algorithms: token
bucket throws away tokens when the bucket is full but
Packet discard policy
never discards packets while leaky bucket discards
Routing algorithm packets when the bucket is full.
Packet lifetime management Let token bucket capacity be C (bits), token arrival rate r
Data link Retransmission policy (bps), maximum output rate M (bps), and burst length S
Out-of-order caching policy (s)
– During burst length of S (s), tokens generated are rS
Acknowledgement policy
(bits), and output burst contains a maximum of C +
Flow control policy rS (bits)
COMPUTER NETWORKS S3-529
– Also output in a maximum burst of length S (s) is M A Congestion
· S (bits), thus
C
C + rS = MS or d =
M -r
Token bucket still allows large bursts, even though the B
maximum burst length S can be regulated by careful
selection of r and M
• One way to reduce the peak rate is to put a leaky
bucket of a larger rate (to avoid discarding packets) Congestion
after the token bucket. (a)
A
Faucet
Host
computer
Packet B
Unregulated
flow Virtual
Leaky
bucket The bucket circuit
Water holds packets (b)
Interface Regulated
containing
e.g. Normally, when router A sets a connection to B, it
flow
a leaky bucket would pass through one of the two congested routers, as
Water drps out
of the hole this would result in a minimum-hop route (4 and 5 hops
at a constant rate
Network respectively). To avoid congestion, a temporary subnet is
(a) (b) redrawn by eliminating congested routers. A virtual circuit
can then be established to avoid congestion
Host
• Negotiate quality of connection in advance, so that
Host
computer computer network provider can reserve buffers and other
resources, guaranteed to be there.
Choke Packets
This closed-loop congestion control is applicable to both
One token is added The bucket
to the bucket holds tokens virtual circuits and datagram subnets
every DT B C B C
A D A D
Heavy flow
E F E F
Networks Networks
Choke packets in WANs (a) basic, (b) hope-by-hope
e
(a) (b)
e
ok
ok
Ch
Ch
Ch
ok
ok
e
e
congestion control.
The basic principle is obvious: When setting up a virtual
circuit, make sure that congestion can be avoided. Reduced
• Admission control: Once congestion has been flow
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
EBD_7203
S3-532 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
IP/IPV4: INTERNET PROTOCOL OVERVIEW Type-of-Service- Indicates the quality of service desired
The Internet Protocol (IP) is a network-layer (Layer 3) protocol by specifying how an upper-layer protocol would like a
in the OSI model that contains addressing information and current datagram to be handled, and assigns datagrams
some control information to enable packets being routed in various levels of importance. This field is used for the
network. IP is the primary network-layer protocol in the TCP/IP
assignment of Precedence, Delay, Throughput and
protocol suite. Along with the Transmission Control Protocol
(TCP), IP represents the heart of the Internet protocols. IP is Reliability.
equally well suited for both LAN and WAN communications. Total Length- Specifies the length, in bytes, of the entire
IP (Internet Protocol) has two primary responsibilities: providing IP packet, including the data and header. The maximum
connectionless, best-effort delivery of datagrams through a length could be specified by this field is 65,535 bytes.
network; and providing fragmentation and reassembly of Typically, hosts are prepared to accept datagrams up to
datagrams to support data links with different maximum-
576 bytes.
transmission unit (MTU) sizes. The IP addressing scheme is
integral to the process of routing IP datagrams through an Identification- Contains an integer that identifies the
internetwork. Each IP address has specific components and current datagram. This field is assigned by sender to help
follows a basic format. These IP addresses can be subdivided receiver to assemble the datagram fragments.
and used to create addresses for subnetworks. Each computer Flags - Consists of a 3-bit field of which the two low-order
(known as host) on a TCP/IP network is assigned an unique
(least-significant) bits control fragmentation. The low-
logical address (32-bit in IPv4) that is divided into two main
parts: the network number and the host number. The network order bit specifies whether the packet can be fragmented.
number identifies a network and must be assigned by the The middle bit specifies whether the packet is the last
Internet Network Information Center (InterNIC) if the network is fragment in a series of fragmented packets. The third or
to be part of the Internet. An Internet Service Provider (ISP) can high-order bit is not used.
obtain blocks of network addresses from the InterNIC and can Fragment Offset - This 13 bits field indicates the position
itself assign address space as necessary. The host number
identifies a host on a network and is assigned by the local of the fragment’s data relative to the beginning of the data
network administrator. in the original datagram, which allows the destination IP
When you send or receive data (for example, an e-mail note or process to properly reconstruct the original datagram.
a Web page), the message gets divided into little chunks called Time-to-Live - It is a counter that gradually decrements
packets. Each of these packets contains both the sender’s down to zero, at which point the datagram is discarded.
Internet address and the receiver’s address.Because a message
This keeps packets from looping endlessly.
is divided into a number of packets, each packet can, if
necessary, be sent by a different route across the Internet. Protocol- Indicates which upper-layer protocol receives
Packets can arrive in a different order than the order they were incoming packets after IP processing is complete.
sent in. The Internet Protocol just delivers them. It’s up to Header Checksum- Helps ensure IP header integrity. Since
another protocol, the Transmission control Protocol (TCP) to some header fields change, e.g., Time To Live, this is
put them back in the right order. recomputed and verified at each point that the Internet
All other protocols within the TCP/IP suite, except ARP and
RARP, use IP to route frames from host to host. header is processed.
There are two basic IP versions, IPv4 and IPv6. Source Address-Specifies the sending node.
Protocol Structure - IP/IPv4 Header (Internet Protocol Destination Address-Specifies the receiving node.
version 4) Options- Allows IP to support various options, such as
security.
4 8 16 32 bits Data - Contains upper-layer information.
Version IHL Type of service Total length
APPLICATION LAYER PROTOCOL
Identification Flags Fragment offset
Application layer protocols govern various processes, such as
Time to live Protocol Header checksum the process for downloading a web page, or for sending e-mail.
Source address The application protocol directs how these processes are done.
Destination address
Layering
Option + padding An application protocol is layered on top of a transport
Data protocol. The application protocol provides the bytes that carry
Version -the version of IP currently used. the messages and the responses for various processes, and the
IP Header Length (IHL) - datagram header length. Points transport protocol helps reliably transport the bytes and makes
to the beginning of the data. The minimum value for a sure they arrive in order.
correct header is 5.
COMPUTER NETWORKS S3-533
3 g z mod n
4 The Concept of Key Distribution Centre (KDC)
g y mod n
When A wants to communicate with B, it sends a message
encrypted in it’s key to the KDC. The KDC then sends a
User Interceptor User
common key to both A and B encrypted in their respective keys.
A and B can communicate safely using this key. There is a
Security problem with the Diffie-Hellman Key Exchange
problem with this implementation also. It is prone to replay
There must be some solution to this problem. The solution can
be such so that we may not be able to communicate further ( attack. The messages are in encrypted form and hence would
because our keys are different ) but atleast we can prevent C not make sense to an intruder but they may be replayed to the
from looking at the data. We have to do something so that C listener again and again with the listener believing that the
cannot encrypt or decrypt the data. We use a policy that A only messages are from the correct source. To prevent this, we can
sends half a packet at a time. C cannot decrypt half a packet use:
and so it is stuck. A sends the other half only when it receives Timestamps: which however don’t generally work because
a half-packet from B. C has two options when it receives half of the offset in time between machines. Synchronization
a packet: over the network becomes a problem.
1. It does not send the packet to B at all and dumps it. In Nonce numbers: which are like ticket numbers. B accepts
this case B will anyway come to know that there is some a message only if it has not seen this nonce number
problem and so it will not send it’s half-packet. before.
2. It forwards the half-packet as it is to B. Now when B There is a central trusted node called the Key Distribution
sends it’s half-packet, A sends the remaining half. When Center ( KDC ). Every node has a key which is shared between
B decrypts this entire packet it sees that the data is junk it and the KDC. Since no one else knows node A’s secret key
EBD_7203
S3-536 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
KA, KDC is sure that the message it received has come from A. RA, RB and RA2 are nonce numbers. RA is used by A to
When A wants to communicate with B it could do two things: communicate with the KDC. On getting the appropriate reply
1. A sends a message encrypted in it’s key KA to the KDC. from the KDC, A starts communicating with B, whence another
The KDC then sends a common key KS to both A and B nonce number RA2 is used. The first three messages tell B that
encrypted in their respective keys KA and KB. A and B the message has come from KDC and it has authenticated A.
can communicate safely using this key. The second last message authenticates B. The reply from B
2. Otherwise A sends a key KS to KDC saying that it wants contains RB, which is a nonce number generated by B. The last
to talk to B encrypted in the key KA. KDC send a message message authenticates A. The last two messages also remove
to B saying that A wants to communicate with you using the possibility of replay attack.
KS. However, the problem with this scheme is that if somehow an
There is a problem with this implementation. It is prone to
intruder gets to know the key KS ( maybe a year later ), then
replay attack. The messages are in encrypted form and hence
he can replay the entire thing ( provided he had stored the
would not make sense to an intruder but they may be replayed
packets ). One possible solution can be that the ticket contains
to the listener again and again with the listener believing that
the messages are from the correct source. When A send a a time stamp. We could also put a condition that A and B
message KA(M), C can send the same message to B by using should change the key every month or so. To improve upon the
the IP address of A. A solution to be used is to use the key only protocol, B should also involve KDC for authentication. We
once. If B sends the first message KA(A,KS) also along with look at one possible improvement here which is a different
K(s,M), then again we may have trouble. In case this happens, protocol.
B should accept packets only with higher sequence numbers. Otway-Rees Key Exchange Protocol
To prevent this, we can use: Here a connection is initiated first. This is followed by key
Timestamps which however don’t generally work because generation. This ensures greater security. B sends the message
of the offset in time between machines. Synchronization
sent by A to the KDC and the KDC verifies that A, B, R in the
over the network becomes a problem.
two messages are same and RA and RB have not been used for
Nonce numbers which are like ticket numbers. B accepts
some time now. It then sends a common key to both A and B.
a message only if it has not seen this nonce number
before.
In general, 2-way handshakes are always prone to attacks. So A, B, R, KA (A, B, R, RA )
we now look at an another protocol.
Needham-Schroeder Authentication Protocol
This is like a bug-fix to the KDC scheme to eliminate replay
attacks. A 3-way handshake (using nonce numbers) very similar A, B, KA (A, B, R, RA ),
to the ubiquitous TCP 3-way handshake is used between KB (A, B, R, RB)
communicating parties. A sends a random number RA to KDC.
KDC send back a ticket to A which has the common key to be A B
used.
KDC KB (RB , KS )
RA (A, B)
KDC
KA (RA , KS )
KA (RA, B, KS , KB (A, KS ))
2. <————KAB(RA), RB 5. <—————KAB(RA)
Fig: -way handshake in Challenge-Response Protocol
3. KAB(RB)—————> On initiating a connection B challenges A by sending it a
random number RB and expects an encrypted reply using the
Unfortunately this scheme is so simple that this will not work. pre-decided key KAB. When A sends back KAB(RB), B becomes
This protocol works on the assumption that there is a unique sure that it is talking to the correct A, since only A knows the
connection between A and B. If multiple connections are shared key. Now A challenges B by sending it a random number
possible, then this protocol fails. In replay attack, we could RA, and expects an encrypted reply using the pre-decided key
repeat the message KAB(M) if we can somehow convince B that KAB. When B sends back KAB(RA), A becomes sure that it is
I am A. Here, a node C need not know the shared key to talking to the correct B, since only B knows the shared key.
communicate with B. To identify itself as A, C just needs to However in this case also, if we have a node C in the middle,
send KAB(RB1) as the response to the challenge-value RB1 then C can pose as B and talk to A. So C can do replay attack
given by B in the first connection. C can remarkably get this by sending messages which it had stored some time ago.
value through the second connection by asking B itself to
provide the response to its own challenge. Thus, C can verify FIREWALL
itself and start communicating freely with B. Firewall is achoke point of control and monitoring that
Thus, replay of messages becomes possible using the second interconnects networks with differing trust and imposes
connection. Any encryption desired, can be obtained by restrictions on network services.Only authorized traffic is
sending the value as RB2 in the second connection, and allowed for auditing and controlling access.
obtaining its encrypted value from B itself. Classification of Firewall
A B
st Characterized by protocol level it controls in
1 Connection: A, RA—————>
1. Packet filtering
<————KAB(RA), RB1
2. Circuit gateways
2nd Connection: A, RB1—————>
3. Application gateways
<—— KAB(RB1), RB2
4. Combination of above is dynamic packet filter
1st Connection: KAB(RB1)————>
We could send KAB(RA,RB) in the second message instead of Packet Filters
KAB(RA) and RA. It may help if we keep two different keys for
different directions. So we share two keys one from A to B and
the other from B to A. If we use only one key, then we could
use different number spaces ( like even and odd) for the two
directions. Then A would not be able to send RB. So basically
we are trying to look at the traffic in two directions as two
different traffics. This particular type of attack is called
reflection attack.
5 - way handshake
We should tell the sender that the person who initiates the
Packet filter uses Uses transport-layer information only such
connection should authenticate himself first. So we look at
as IP Source Address, Destination Address,Protocol/Next
another protocol. Here we are using a 5-way handshake but it
Header (TCP, UDP, ICMP, etc),TCP or UDP source & destination
is secure. When we combine the messages, then we are
ports,TCP Flags (SYN, ACK, FIN, RST, PSH, etc) and ICMP
EBD_7203
S3-538 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
message type. packets.All incoming traffic s directed to firewall and all
Packet filters are used for Filtering with incoming or outgoing outgoing traffic appears to come from firewall. Polices are
interfacesE.g., Ingress filtering of spoofed IP addresses and embedded in proxy programs.There are 2 types of proxies.
egress filtering. It permits or denies certain services and Application-level gateways/proxies,tailored to http, ftp, smtp,
requires intimate knowledge of TCP and UDP port utilization on etc. and circuit-level gateways/proxies that working on TCP
a number of operating systems. level.
How to Configure a Packet Filter Firewalls - Application Level Gateway (or Proxy)
1. First Start with a security policy
2. Specify allowable packets in terms of logical expressions
on packet fields
3. Rewrite expressions in syntax supported by your
vendor
In the following example suppose we want to allow
inbound mail (SMTP, port 25) but only to our gateway
machine. Also suppose that mail from some particular
site SPIGOT is to be blocked.
Application-Level Filtering
Then we configure the filter as follows Application level filtering has full access to protocol .The user
requests service from proxy and proxy validates requests as
legal ,it then actions request and returns result to user .It needs
separate proxies for each service E.g., SMTP (E-Mail),NNTP
(Net news),DNS (Domain Name System),NTP (Network Time
Protocol).
Security & Performance of Packet Filters
App-level Firewall Architecture
Degradation depends on number of rules applied at any point.It
orders rules so that most common traffic is dealt with first. In
this packet filtering method correctness is more important than
speed.
Port Numbering
For TCP connection server port is number less than 1024 and
client port is number between 1024 and 16383.For permanent Firewalls - Circuit Level Gateway
assignment Ports <1024 are assigned permanently 20,21 for FTP
,23 for Telnet and 25 for server SMTP and 80 for HTTP. The
Variable uses Ports >1024 that must be available for client to
make any connection which presents a limitation for stateless
packet filtering for eg, if client wants to use port 2048, firewall
must allow incoming traffic on this port.
Firewalls - Stateful Packet Filters
A traditional packet filter makes filtering decisions on an
individual packet basis and does not take into consideration
any higher layer context. A stateful inspection packet filter
tightens up the rules for TCP traffic by creating a directory of
outbound TCP connections, and will allow incoming traffic to
high-numbered ports only for those packets that fit the profile
of one of the entries in this directory. Hence they are better able
Circuit-level Gateway are a stand-alone system and have pecialized
to detect bogus packets sent out of context.
function performed by an Application-level Gateway.It sets up
Firewall Gateways two TCP connections and the gateway typically relays TCP seg-
Gateway is like a NAT box, ie, a home router.Firewall runs a set ments from one connection to the other without examining the
of proxy programs.The Proxies filter incoming and outgoing contents.
COMPUTER NETWORKS S3-539
Bastion Host If routers only support outgoing filtering, we need two:
It is a highly secure host system that is potentially exposed to One to use ruleset that protects against compromised gateways
“hostile” elements .Hence is secured to withstand this .It is trusted and one to use ruleset that guards against address forgery and
to enforce trusted separation between network connections.It restricts access to gateway machine.An input filter on one port is
runs on both circuit / application level gateways .It also helps you exactly equivalent to an output filter on the other port.
install/modify servicesthat you want. Routing Filters
Routers need to be able to control what routes they advertise
over various interfaces.Packet filters obviate the need for route
filters.
Asymmetric Routes
Both sides of the firewall know nothing of one another's topol-
ogy. In order to overcome this one should maintain full knowl-
edge of the topology.
Distributed Firewalls
In this firewall a central management node sets the security policy
enforced by individual hosts.It is a combination of high-level
policy specification with file distribution mechanism.The main
Dynamic Packet Filters advantages are Lack of central point of failure,ability to protect
These are most common and provide good administrators protec- machines outside topologically isolated space However the dis-
tion and full transparency.Network is given full control over traf- advantage is that they are harder to allow in certain services,
fic.
whereas it's easy to block.
Network Topology
Distributed Firewalls Drawback
Filter Rule: Open access to Net 2 means source address from Net
3.Why not spoof address from Net 3? Allowing in certain services it works if and only if you're sure the
address can't be spoofedand hence requires anti-spoofing pro-
tection and must maintain ability to roam safely.
EBD_7203
S3-540 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY