Sei sulla pagina 1di 1045

GATE

Computer Science & Information Technology


Masterpiece with 10 Practice Sets
EBD_7203
• Corporate Office : 45, 2nd Floor, Maharishi Dayanand Marg, Corner Market,
Malviya Nagar, New Delhi-110017
Tel. : 011-26692293 / 26692294
How to access the ebook(s)?
Educore

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.

For further information about the books from DISHA,


Log on to www.dishapublication.com or email to info@dishapublication.com
CONTENTS
• Solved Paper 2017 [Set-1] 2017-1-20

• Solved Paper 2017 [Set-2] 2017-21-40

• Solved Paper 2016 [Set-1] 2016-1-12

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

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

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

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

Section 1 - General Aptitude S1 (1-124)

Part A - Verbal Ability S1(1-54)

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

Part B - Numerical Ability S1 (55-124)

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

Section 2 - ENGINEERING MATHEMATICS (1-132)


S2

1. Mathematical Logic 1 - 10

2. Probability 11 - 28

3. Set Theory & Algebra 29 - 46

4. Combinations 47 - 56
EBD_7203
5. Graph Theory 57 - 66

6. Linear Algebra 67 - 90

7. Numerical Methods 91 - 102

8. Calculus 103 - 132

Section 3 - TECHNICAL SECTION (1-599)


S3

1. Digital Logic 1 - 46

2. Computer Organization and Architecture 47 - 118

3. Programming and Data Structures 119 - 200

4. Algorithm Analysis 201 - 238

5. Theory of Computation 239 - 288

6. Compiler Design 289 - 348

7. Operating System 349 - 414

8. Databases 415 - 476

9. Information System and Software Engineering 477 - 514

10. Computer Networks 515 - 568

11. Miscellaneous Topics 569- 599

6 PAPER BASED PRACTICE SETS PS (1-72)


1. Practice Set-1 PS-1 - PS-12

2. Practice Set-2 PS-13 - PS-24

3. Practice Set-3 PS-25 - PS-36

4. Practice Set-4 PS-37 - PS-48

5. Practice Set-5 PS-49 - PS-60

6. Practice Set-6 PS-61 - PS-72

4 ONLINE PRACTICE SETS


PREFACE
With an aim to provide the best possible material to the students to prepare for the GATE, GATE Masterpiece is a one
of its kind for the preparation of Computer Science & Information Technology Exams and a result of many years of
research. The unique feature of this book is that it has Numerical Answer Type Questions which have been added by
the IITs. Also, book has come with 10 practice sets on the Gate pattern.

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.

1. General Aptitude - Covering Verbal Ability and Numerical Ability


2. Engineering Mathematics
3. Technical Section
4. 10 offline & online Practice Sets

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

Information System and


- - - - - - 6 0 2 1 3 - -
Software Engineering

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

5. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.

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

if (x) { (c) V ® W (d) V ® W


x = (int *) malloc (sizeof (int) ) ; V®X W®X
if (NULL == x) return; Y®V Y®V
x = assignval (x, 10) ; Y®X Y®X
} Y®Z Y®Z
printf ( “%d\n” , *x); 17. Consider the following grammar:
free ( x ) ;
} P ® xQRS
The code suffers from which one of the following problems: Q ® yz | z
(a) compiler error as the return of malloc is not typecast R ® w|ε
appropriately S®y
(b) compiler error because the comparison should be
made as x == NULL and not as shown What is FOLLOW(Q)?
(c) compiles successfully but execution may result in (a) {R} (b) {w}
dangling pointer (c) {w, y} (d) {w, $}
(d) compiles successfully but execution may result in 18. Threads of a process share
memory leak (a) global variables but nor heap.
14. Consider a TCP client and a TCP server running on two (b) heap but nor global variables.
different machines. After completing data transfer, the TCP (c) neither global variables nor heap.
client calls close to terminate the connection and a FIN (d) both heap and global variables.
segment is sent to the TCP server. Server-side TCP responds 19. Let X be a Gaussian random variable with mean 0 and
by sending an ACK which is received by the client-side TCP. variance s2. Let Y = max (x, 0) where max (a,b) is the maximum
As per the TCP connection state diagram (RFC 793), in which of a and b . The median of Y is _______.
state does the client-side TCP connection wait for the FIN 20. Let T be a tree with 10 vertices. The sum of the degrees of all
from the server-side TCP? the vertices in T is _______.
(a) LAST-ACK (b) TIME-WAIT 21. Consider the Karnaugh map given below, where X represents
(c) FIN-WAIT-1 (d) FIN-WAIT-2 “don’t care” and blank represents 0.
15. A sender S sends a message m to receiver R. which is digitally
signed by S with its private key. In this scenario, one or more
of the following security violations can take place. ba 00 01 11 10
dc
(I) S can launch a birthday attack to replace m with a
fraudulent message.
00 X X
(II) A third party attacker can launch a birthday attack to
replace m with a fraudulent message.
(III) R can launch a birthday attack to replace m with a 01 1 X
fraudulent message.
Which of the following are possible security violations? 1
11 1
(a) (I) and (II) only
(b) (I) only
(c) (II) only 10 X X
(d) (II) and (III) only
16. The following functional dependencies hold true for the Assume for all inputs (a, b, c, d), the respective complements
relational schema R{V,W,XtY,Z}
(a, b, c, d ) are also available. The above logic is implemented
V®W
VW ® X using 2-input NOR gates only. The minimum number of gates
required is _______.
Y ® VX
22. Consider the language L given by the regular expression (a
Y®Z
+ b) *b (a + b) over the alphabet {a.b}. The smallest number
Which of the following is irreducible equivalent for this set of states needed in a deterministic finite-state automaton
of functional dependencies? (DFA) accepting L is _______.
(a) V ® W (b) V ® W 23. Consider a database that has the relation schema EMP
V®X W®X (EmpId. EmpName, and DeptName). An instance of the
Y®V Y®V schema EMP and a SQL query on it are given below.
Y®Z Y®Z
EBD_7203
2017 -4 SOLVED PAPER - 2017
Which of the above statements is/are necessarily true?
EMP (a) (I) only
EmpId EmpName DeptName (b) (II) only
1 XYA AA (c) both (I) and (II)
2 XYB AA (d) neither (I) nor (II)
3 XYC AA 27. A multithreaded program P executes with x number of threads
4 XYD AA and uses y number of locks for ensuring mutual exclusion
5 XYE AB while operating on shared memory locations. All locks in the
6 XYF AB program are non-reentrant, i.e, if a thread holds a lock l, then
7 XYG AB it cannot re-acquire lock l without releasing it. If a thread is
8 AC unable to acquire a lock, it blocks until the lock becomes
XYH
available. The minimum value of x and the minimum value
9 XYI AC
of y together for which execution of P can result in a deadlock
10 XYJ AC are:
11 XYK AD (a) x = 1, y = 2 (b) x = 2, y = l
12 XYL AD (c) x = 2, y = 2 (d) x = l, y = 1
13 XYM AE
x 7 - 2 x5 + 1
28. The value of lim 3
SELECT AVG(EC.Num) x ®1 x - 3 x2 + 2
FROM EC (a) is 0 (b) is-1
WHERE (DeptName, Num) IN (c) is 1 (d) does not exist
(SELECT DeptName, COUNT(Empld) AS 29. Let p, q, and r be propositions and the expression (p ® q)
EC(DeptName, Num) ® r be a contradiction. Then, the expression (r ® p) ® q is
FROM EMP
(a) a tautology.
GROUP BY DeptName)
(b) a contradiction.
The output of executing the SQL query is_______. (c) always TRUE when p is FALSE.
24. Consider the following CPU processes with arrival times (in (d) always TRUE when q is TRUE.
milliseconds) and length of CPU bursts (in milliseconds) as 30. Let u and v be two vectors in R2 whose Euclidean norms
given below : satisfy || u || = 2 || v ||. What is the value of a such that w =
u + av bisects the angle between u and v?
Process Arrival time Burst time (a) 2 (b) 1/2
P1 0 7 (c) 1 (d) –1/2
P2 3 3 31. Let A be n × n real valued square symmetric matrix of rank
P3 5 5 n n
P4 6 2 2 with å å Aij2 = 50 . Consider the following statements.
i =1 j =1
If the pre-emptive shortest remaining time first scheduling
algorithm is used to schedule the processes, then the (I) One eigenvalue must be in [–5, 5]
average waiting time across all processes is _______ (II) The eigenvalue with the largest magnitude must be
milliseconds. strictly greater than 5
25. Consider a two-level cache hierarchy with LI and L2 caches. Which of the above statements about eigenvalues of A is/
An application incurs 1.4 memory accesses per instruction are necessarily CORRECT?
on average. For this application, the miss rate of L1 cache is (a) Both (I) and (II)
0.1; the L2 cache experiences, on average. 7 misses per 1000 (b) (I) only
instructions. The miss rate of L2 expressed correct to two (c) (II) only
decimal places is________. (d) Neither (1) nor (II)
32. A computer network uses polynomials over GF(2) for error
checking with 8 bits as information bits and uses x3 + x + 1 as the
QUESTION 26 TO 55 CARRY TWO MARKS EACH generator polynomial to generate the check bits. In this
network, the message 01011011 is transmitted as
26. Let G = (V, E) be any connected undirected edge-weighted (a) 01011011010 (b) 01011011011
graph. The weights of the edges in E are positive and distinct. (c) 01011011101 (d) 01011011100
Consider the following statements: 33. Consider a combination of T and D flip-flops connected as
(I) Minimum Spanning Tree of G is always unique, shown below. The output of the D flip-flop is connected to
(II) Shortest path between any two vertices of G is always the input of the T flip-flop and the output of the T flip-flop
unique. is connected to the input of the D flip-flop.
SOLVED PAPER - 2017 2017-5

37. Consider the context-free grammars over the alphabet {a, b, c}


given below. S and T are non-terminals.
G1: S ® aSb/T, T ® CT|Î
G2 : S ® bSa\T, T ® cT|Î
T Q1 D Q0 The language L(G1) Ç L(G2) is
Flip- Flip- (a) Finite.
Flop Flop (b) Not finite but regular.
(c) Context-Free but not regular.
(d) Recursive but not context-free.
Clock 38. Consider the following languages over the alphabet
Initially, both Q1 and Q1 are set to 1 (before the 1st clock cycle). å = {a, b, c}.
The outputs Let L1 = { an bn cm | m,n ³ 0} and L2 = { am bn cn | m, n ³ 0}.
(a) Q1Q0 after the 3rd cycle are 11 and after the 4th cycle are Which of the following are context-free languages?
00 respectively I. L1 È L2
(b) Q1Q0 after the 3rd cycle are 11 and after the 4th cycle are I. L1 Ç L2
01 respectively (a) I only (b) II only
(c) Q1Q0 after the 3rd cycle are 00 and after the 4th cycle are (c) I and II (d) Neither I nor II
11 respectively 39. Let A and B be finite alphabets and let # be a symbol outside
(d) Q1Q0 after the 3rd cycle are 01 and after the 4th cycle are both A and B. Let f be a total function from A* to B*. We say
01 respectively f is computable if there exists a Turing machine M which
34. If G is a grammar with productions given an input x in A*. always halts with f(x) on its tape. Let
S ® SaS | aSb | bSa | SS | Î Lf denote the language {x # f(x)| x Î A*}. Which of the
where S is the start variable, then which one of the following following statements is true:
strings is not generated by G? (a) f is computable if and only if Lf is recursive.
(a) abab (b) aaab (b) f is computable if and only if L f is recursively
(c) abbaa (d) babba enumerable.
35. Consider The following two functions. (c) If f is computable then L f is recursive, but not
void fun1(int n) { void fun 2 (int n) { conversely.
if (n == 0) return; if (n == 0) return; (d) If f is computable then Lf is recursively enumerable, but
printf (“%d”, n) ; printf (“%d”, n) ; not conversely.
fun2(n - 2); funl ( ++n); 40. Recall that Belady’s anomaly is that the page-fault rate may
printf (“%d”, n); printf (“%d”, n); increase as the number of allocated frames increases. Now,
} } consider the following statements:
The output printed when funl (5) is called is SI : Random page replacement algorithm (where a page
(a) 53423122233445 (b) 53423120112233 chosen at random is replaced) suffers from Belady’s anomaly
(c) 53423122132435 (d) 53423120213243 S2 : LRU page replacement algorithm suffers from Belady’s
36. Consider the C functions foo and bar given below: anomaly
int foo (int val) { Which of the following is CORRECT?
int x = 0; (a) S1 is true, S2 is true
while (val > 0) { (b) S1 is true, S2 is false
x = x + foo (val--); (c) S1 is false. S2 is true
} (d) SI is false. S2 is false
return val; 41. Consider a database that has the relation schemas
} EMP(EmpId, EmpName, DeptId), and DEPT(DeptName,
int bar (int val) { DeptId). Note that the DeptId can be permitted to be NULL
int x = 0; in the relation EMP. Consider the following queries on the
while (val > 0) { database expressed in tuple relational calculus.
x = x + bar (val–l); (I) {t | $u Î EMP(t[EmpName] = u[EmpName] Ù " vÎ
} DEPT(t[DeptId] ¹ v[DeptId]))}
return val; (II) {t | $u Î EMP(t[EmpName] = u[EmpName] Ù$vÎ
} DEPT(t[DeptId] ¹ v[DeptId]))}
Invocations of foo (3) and bar (3) will result in: (III) {t | $u Î EMP(t[EmpName] = u[EmpName] Ù$vÎ
(a) Return of 6 and 6 respectively. DEPT(t[DeptId] = v[DeptId]))}
(b) Infinite loop and abnormal termination respectively. Which of the above queries are safe?
(c) Abnormal termination and infinite loop respectively. (a) (I) and (II) only (b) (I) and (III) only
(d) Both terminating abnormally. (c) (II) and (III) only (d) (I), (II) and (III)
EBD_7203
2017 -6 SOLVED PAPER - 2017
42. In a database system, unique timestamps are assigned to
each transaction using Lamport’s logical clock. Let TS( T1) CR
and TS(T2) be the timestamps of transactions T1 and T2 StudentName CourseName
respectively. Besides, T1 holds a lock on the resource R and SA CA
T2 has requested a conflicting lock on the same resource R. SA CB
The following algorithm is used to prevent deadlocks in the SA CC
database system assuming that a killed transaction is SB CB
restarted with the same timestamp. SB CC
if TS(T2) < TS(T1) then SC CA
T1 is killed SC CB
else T2 waits. SC CC
Assume any transaction that is not killed terminates SD CA
eventually. Which of the following is true about the database SD CB
system that uses the above algorithm to prevent deadlocks SD CC
? SD CD
(a) The database system is both deadlock-free and SE CD
starvation-free. SE CA
(b) The database system is deadlock-free, but not SE CB
starvation-free. SF CA
(c) The database system is starvation-free, but not SF CB
deadlock-free. SF CC
(d) The database system is neither deadlock-free nor
starvation-free. The following query is made on the database.
43. Consider the following grammar: T1 ¬p CourseName (sStudentName= ‘SA’ (CR))
stmt - > if expr then expr else expr; stmt | o T2 ¬ CR ¸ T1
expr - > term relop term | term The number of rows in T2 is _______.
term - > id | number 47. The number of integers between 1 and 500 (both inclusive) that
id - > a| b|c are divisible by 3 or 5 or 7 is ________.
number - > [0-9] 48. Let A be an array of 31 numbers consisting of a sequence of
where relop is a relational operator (e.g., < , > , ...), o refers to 0’s followed by a sequence of l’s. The problem is to find the
the empty statement, and if, then, else are terminals. smallest index i such that A[i] is 1 by probing the minimum
Consider a program P following the above grammar number of locations in A. The worst case number of probes
containing ten if terminals. The number of control flow paths performed by an optimal algorithm is _____.
in P is ________. For example, the program 49. Consider a RISC machine where each instruction is exactly
if e1 then e2 else e3 4 bytes long. Conditional and unconditional branch
has 2 control flow paths, e1 ® e2 and e1 ® e3. instructions use PC-relative addressing mode with Offset
44. In a RSA cryptosystem, a participant A uses two prime specified in bytes to the target location of the branch
numbers p = 13 and q =17 to generate her public and private instruction. Further the Offset is always with respect to the
keys. If the public key of A is 35, then the private key of A address of the next instruction in the program sequence.
is ________ . Consider the following instruction sequence
45. The values of parameters for the Stop-and-Wait ARQ Instr. No. Instruction
protocol are as given below: i : add R2, R3, R4
Bit rate of the transmission channel = 1 Mbps. i+1: sub R5, R6, R7
Propagation delay from sender to receiver = 0.75 ms. i+2: cmp Rl, R9, R10
Time to process a frame = 0.25 ms. 1+3: beq Rl, Offset
Number of bytes in the information frame = 1980. If the target of the branch instruction is i, then the decimal
Number of bytes in the acknowledge frame = 20. value of the Offset is ______.
Number of overhead bytes in the information frame = 20. 50. Instruction execution in a processor is divided into 5 stages.
Assume that there are no transmission errors. Then, the Instruction Fetch (IF). Instruction Decode (ID). Operand
transmission efficiency (expressed in percentage) of the Fetch (OF). Execute (EX), and Write Back (WB). These
Stop-and-Wait ARQ protocol for the above parameters is
stages take 5, 4, 20, 10, and 3 nanoseconds (us) respectively.
_______ (correct to 2 decimal places).
A pipelined implementation of the processor requires
46. Consider a database that has the relation schema
buffering between each pair of consecutive stages with a
CR(StudentName. CourseName). An instance of the schema
delay of 2 ns. Two pipelined implementations of the
CR is as given below.
processor are contemplated:
SOLVED PAPER - 2017 2017-7

(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

2. (b) The given statement F : " x ($y R( x, y))


So, (AX = b) has infinity many solutions one of which
will be jn, where jn donates a, n-dim vector of all 1.
1. " x ($ y R ( x, y )) ¾¾
® $y ($x R( x, y)) is correct. Hence option (c) is correct.
4. (b) The correct arrangement of the given functions in
Since $y ($x R( x, y)) º $x ($y R( x, y))
increasing order of asymptotic complexity is.

º "x ($ y R( x, y)) 100


, 10, log 2 n, n , n because the complexity order
n
2. " x ($ y R( x, y )) ¾¾
® $y (" x R( x, y)) is incorrect, 100
is < 10 < log 2 n < n < n . Hence the option (b) is
n
because $y (it is stronger when it is outside).
correct.
5. (c) The given algorithms related to the Design Paradigms
3. " x ($y R ( x, y )) ¾¾
®" y $x R ( x, y ) is incorrect,
accordingly such as :
because R(x, y) may not be symmetric in x and y. 1. Kruskal’s Algorithms uses the greedy approach to find
the Minimum Spanning Tree (MST) of a connected
4. " x ($ y R( x, y )) ¾¾
®(Ø $ x " y Ø R( x, y)) is correct because graph.
2. Quick sort follow divide and conquer strategy by
Ø ($x " y Ø R( x, y)) º (Ø $x )(Ø" y )(Ø (Ø R( x, y))) dividing the input array according to pivot element.
3. Floyd Warshal Algorithm is used to find the shortest
(Ø ($x )(" y )Ø (Ø R( x, y))) º " x ($ y R( x, y)) path between every pair of vertices and it follows
dynamic programming strategy.
\Ø ($x ) = "x , Ø (" y ) = $y , ØØ R(x, y) = R( x, y) 6. (b) Since there are 15 nodes, hence the minimum height of
the tree will be 3 (when tree will be balanced).
So, it will be reduced to
Height - 0
" x ($ y R( x, y)) ¾¾
®" x $ y R( x, y)
Height - 1
Min. Max.
which is trivially correct. Height - 2
Height Height

So correct answer is I and IV only. Height - 3

Hence option (b) is correct. Total Nodes = 15


EBD_7203
2017 -10 SOLVED PAPER - 2017
Min. height = floor (log2N) An XOR operation on these two bits can quickly
= floor (log215) = 3 determine whenever overflow occurred.
The maximum height will be when the tree is skew tree, which ( A7 × B7 × S7 + A7 × B7 × S7 ) is 1.
will give rise to height 14 either it will be left or right skewed
tree. Hence option (b) is correct. Therefore, ( ( A7 × B7 ) Å S7 = 1) has overflowed, Hence
7. (d) As given that i = (n – g) option (c) is correct.
The range of decimal value for X is find by the help of 10. (c) The given context free Grammar
Max. value. S = {a, b, c} with S as the start symbol.
Max. value = i + f
S ® abScT / abcT
where i = (n – f).
T ® bT / b
Then
The minimum length string generated by the gramber
Max. value
is 1.
= 111 ..... 1 (i times) + 1111 .....1 (f times)
Consider first case ( S ® abcT ) then ( S ® abcb) .
i é1 1 1 ù
= 2 - 1 + ê 1 + 2 + .... f ú Hence all the variable s are greater than 1.
ë2 2 2 û Consider second case
(2 f - 1) æ 1 ö S ® abScT
= (2i - 1) + = ç 2i - 1 + 1 - f ÷
2 f è 2 ø ® ababScTcT
= (2i – 2–f ) ® ababScTcTcT
Now, let n = 5 b/t, f = 2 b/t, ..............................
i = (n – f ) = (5 – 2) = 3 b/t ..............................
Min. value = 0 0 .... 0 (i times) + 0 0 0 .... (f times) = 0
® (ab)n (CT )n
Max. value = 1 1 1 1 .... (i times) + 1 1 1 1 .... (f times)
= (2i – 2–f ) = (23 – 2–2) Here T can generate any number of b’s string with
= (8 – 0.25) = 7.75. single b, so (T = bm)
Hence the range of decimal value for X is (0 to 2i – 2–f), Hence, the language is
so option (d) is correct. L = [(ab)n (cb m )n | m, n ³ 1]
8. (b) According to the given C program. It used two linked Hence option (c) is correct.
lists. After the code execution, list ‘m’ will be appended 11. (d) Since direct access is possible with only index-
to the end of list ‘n’ due to pointer ‘p’. Move to last addressing mode. So, option (d) is correct.
node of the list but in some cases it may dereference to 12. (b) Consider all options.
null pointer.
1. In option (a), p1 and q1 are initialized twice or used
m n p again for temporary storage, which is not allowed under
static single assignment.
X X
2. In option (b), there is no initialization again of the
Head 1 Tail 1 Head 2 Tail 2 variables and all the statement are correct.
9. (c) Overflow flag indicates an overflow condition for a 3. In option (c), the second line statement is not correct.
signed operation. Overflow for signed number occurs It should be
when the carry-in into the MSB is nto equal to carryout. q1 = p1 * C.
And P2, P4, q3 are not initialized anywhere.
So, A Þ A7 A6 .......... A0
4. In option (d), the second line statements is not correct.
B Þ B7 B6 .......... B0 It should be
q1 = P1 * C
Sum ® S7 S6 .......... S0 So, option (b) is correct.
Carry ® C7 C6 .......... C0 13. (d) Consider all options.
For positive number whenever there is a overflow 1. In option (a), we don’t need to cast the, result as void * is
automatically and safely promoted to any other pointer
A7 B7 S 7 is 1. type in this case. So it is not correct.
For negative numbers whenever there is a overflow 2. In option (b), it is discarded for obvious reason, so it is
A7 B7 S 7 is 1. also not correct.
SOLVED PAPER - 2017 2017-11

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

11 1 1 (P1 = 7) (P1 = 4) (P1 = 4) (P1 = 4) (P1 = 4) (P3 = 5) (P3 = 0)


(P2 = 3) (P2 = 1) ( P2 = 0) (P3 = 5) (P1 = 0)
10 × × (P3 = 5) (P3 = 5) (P4 = 0)
(P4 = 2)

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.

2 Now, if (q = 1) true then (r ® P ) is also


3 5
true for both value of P.

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

And, P(A) = 2 but eigen values of A are 0, –5, 5.


Clock T -Flip D -Flip
So, the eigen value with the largest magnitude is not flop (Q1) flop (Q0)
cycle
greater than 5.
0 1 1 (initially both set to 1)
é5 0 ù 1 0 1
For n = 2 and A = ê ú Þ eigen values = 5, 5. 2 1 0
ë0 5 û
3 1 1
Thus, one eigen value must be in [–5, 5] and largest
4 0 1
eigen value magntidue is not greater than 5.
So, (II) statement is false. By using :-
Hence option (b) is correct. T-flip flop D flipflop
32. (c) The given generator polynomial (LRC)
G( X ) = X 3 + X + 1 A B T A B D
0 0 0 0 0 0
Þ 1× X 3 + 0 × X 2 + 1× X 2 + 1× X 0
0 1 1 0 1 1
G( X ) Þ 1 0 1 1 1 0 1 1 0 0
Given message m(X) = 0 1 0 1 1 0 1 1. 1 1 0 1 1 1
Then
Q1, Q0 after 3rd clock pulse : 11, and Q1, Q0 after 4th
clock pulse : 01.
extrabits Hence, option (b) is correct.
34. (d) The given grammar with productions,
1011 01011011000 01000011
S ® SaS | aSb | bSa | SS | Î
0000
01011 Now consider,
1011 S ® aSb | bSa | SS | Î
00000 This grammar generates all strings with equal number
0000 of ‘a’ and ‘b’.
00001 Now, S ® SaS can only generate strings where ‘a’ is
0000 more than ‘b’. Since on left and right of ‘a’ in SaS, S
will have only strings with na = nb or na > nb.
00011
Now consider each options
0000
1. S ® SS ® aSbS ® abS ® abaSb ® abab, when, S ® Î
00110
0000 2. S ® aSb ® aSaSb ® aaaSb ® aaab, when S ® Î
01100 3. S ® SS ® aSbS ® abS ® abbSa ® abbSaSa
1011
® abbaa, when (S ® Î)
01110
4. “babba” which is a string with nb > na is not possible
1011 to generate by the given grammar.
0101 Hence, option (d) is correct.
SOLVED PAPER - 2017 2017-15

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

{a nb n cn | n ³ 0} is a non context free language. e5 e5 e5 e5


Hence, option (a) is correct.
EBD_7203
2017 -16 SOLVED PAPER - 2017
These four control flow are : 46. (4) The given query is made on the database are :
(1) e1 ® e2
1. T1 ¬¾
¾ Õ Course name
( sStudent name='SA' (CR))
(2) e1 ® e3 For T1 Result : find out the course name for the student
(3) (e2 if e4 ) ® e5 name is ‘SA’ i.e.

(4) (e3 if e4 ) ® e5 Course Name


So, for (10 “if statements”), 210 = 1024. CA
Control flow path are possible. Hence, answer is 1024. CB
44. (11) As given data P = 13, q = 17, e = 35, d = ? CC
As per RSA Algorithm.
n = P × q = 13 × 17 = 221 So, T1 = {CA, CB, CC}
By using RSA formula The number of rows in T1 is 3.
f(n) = (P – 1) (q – 1) = 12 × 16 = 192. 2. T2 ¬¾
¾ (CR ¸ T1 )
To find out the private key of A, then take Modulas
operater for RSA formula. For T2 Result : find out the student name for which
(d × e) mod f(n) = 1 every course name of T1 are {CA, CB, CC} is :
(d × 35) mod (192) = 1
d = 11, Hence, answer is 11. Student Name
45. (89.33) Given data : SA
B = 1 Mbps, Tprocess = 0.25 ms, TPt = 0.75 ms SC
LIF = 1980 bytes, L(Overhead) = 20 bytes, LAF = 20 bytes SD
Efficiency ( h ) = ? SF
As we know that,
So, T2 = {SA, SC, SD, SF}
Data size Hence, the number of rows in T2 is 4.
Transmission time of data =
Bandwidth 47. (271) To find the number of integer between 1 and 500 that
are divisible by 3, 5, 7 and make the three set A, B, C.
( L + LAf ) (1980 + 20) bytes
So, TX = L = If = Set A is the set of all number between 1 to 500 which
B B 1´106 (bits/sec) divisible by 3.
Set B is the set of all number between 1 to 500 which
(Q1 byte = 8 bit)
divisible by 5.
2000 ´ 8 (bits) Set C is the set of all number between 1 to 500 which
=
106 (bits/sec) divisible by 7.
Take union of these three sets using union formula
TX = 16 m sec
then, n( A È B È C ) = n( A) + n( B ) + n(C ) - n( A Ç B)
Propagation time = 0.75 m sec.
- n( A Ç C ) - n ( B Ç C )
L 20 ´ 8 bits
Transmission time of TACK = AF =
B 10 6 +n( A Ç B Ç C )

\ TACK = 0.16 m sec. é 500 ù é 500 ù é 500 ù é 500 ù


=ê ú+ê ú+ê ú-ê ú
Then transmission efficiency of stop and wait ARQ. ë 3 û ë 5 û ë 7 û ë 15 û
TX
Þ é 500 ù é 500 ù é 500 ù
(TX + TACK + 2TPt + TProcess ) -ê ú-ê ú-ê ú
ë 21 û ë 35 û ë 105 û
16 = 166 + 100 + 71 – 33 – 23 – 14 + 4
=
(16 + 0.16 + 2 ´ 0.75 + 0.25) = 271.
So, the total number between 1 to 500 which is divisible
16 by 3, 5 or 7 is 271.
= = 0.8933 = 89.33% , Hence answer is 89.33%
17.91
SOLVED PAPER - 2017 2017-17

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

Inst No. 256


Number of sets (S) = = 128
I1 0000 – 0003 2
I2 0004 – 0007 Consider Ist Time Access for given sequence :-
I3 0008 – 0011 {0, 128, 256, 128, 0, 128, 256, 128}.
I4 0012 – 0015
0016
Block ID Type Content
Valid - PC 0 Comp uls ory M is s 0
128 Comp uls ory M is s 0 - 128
where, 256 Comp uls ory M is s 128-256
I4 is as branch instruction I1 as a target location. 128 h it 256-128
So, PC-relative addressing mode is: 0 Co n flict M is s 128 - 0
(EA) = (PC) + relative value 128 h it 0 - 128
Relative value = (EA) – (PC) = 0000 – 0016 = –16.
256 Co n flict M is s 128 - 256
50. (1.508) Given for Native pipeline,
128 h it 256 - 128
the number of stages (k) = 5.
tP1 = Max(Stage delay + buffer delay)
So, the Number of conflict Miss in set 1 is = 2
Buffer delay = 2nS Similarly conflict for given rest sequence
Stage delay = 5, 4, 20, 10, 3 {1, 129, 257, 129, 1, 129, 257, 129}.
So, The number of conflict miss in set 2 is 2, then total number
of conflict misses in both set for 1st time access is:
tP1 = Max((5 + 2), (4 + 2), (20 + 2), (10 + 2), (3 + 2))
= (2 + 2) = 4.
= Max (7, 6, 22, 12, 5) Consider 2nd time access for the given sequence
Maximum value is 22. {0, 128, 256, 128, 0, 128, 256, 128}.
t P1 = 22 n sec.

Number of instruction (n) = 20


So, execution time for native pipeline (NP).
Then,
EBD_7203
2017 -18 SOLVED PAPER - 2017

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 :

Let R1 and R2 be two registers Set Associative


14 bits 12 bits
Load R1 ¬¾
¾b
TAG OFFSET
Load R2 ¬¾
¾c
(10 bits + 4 bits)
SOLVED PAPER - 2017 2017-19

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

( Q 10 is static) so, count = 6 return (6);


X = 14
So, the required length of TAG field in Set Associative X = (10 + 6) + total (1);)
mapped is = 14. ( Q 10 is static) so, count = 7 return (7);
55. (23) Count in the function Total is static :
= 16 + total (1);
i Count Total (i)
( Q 16 is static), so count = 16 + 7 = 23 (static)
5 0 2
(Q7 is static)
4 2 3 = (2 + 1)
Hence in the function Total count static is : 23.
3 3 5 = (3 + 2)
56. (c)
2 5 6 = (5 + 1)
57. (d)
1 6 7 = (6 + 1)
Total : 23 58. (c) Murali
Check out the running code with comments
for (i = 5; i > 0; i – –)
x = x + total (5) ; Arul Rahul
While (5) (\ v = 5)
Count = Count + V & 1
Srinivas
= Count + 5 & 1 (5 & 1 = 1)
Count = Count + 1 (Count = 1)
EBD_7203
2017 -20 SOLVED PAPER - 2017
59. (d) 162 = 2 × 3 × 3 × 3 × 3 63. (b) When x > y then |x – y | = x – y ...(i)
to make it a perfect cube we need to multiply 162 with 4 When x < y |x – y | = y – x ...(ii)
× 9 = 36 Taking equation (i) (x > y)
60. (c) In a k digit number 0, 5 and 9 are not allowed than
x + y - (x - y) 2y
remaining digits to be filled = 1, 2, 3, 4, 7, 8 i.e, 7 digit =
2 2
k
æ 7ö k = y minimum of (x, y) as x > y
Probability = ç ÷ ie (0.7)
è 10 ø Taking equation (ii) (x < y)
61. (b) x + y - (y - x) 2x
= =x
62. (a) Sitting arrangement will be like the following figure 2 2
L (w) minimum of (x, y) as x < y
R(w)
64. (d) Total number of ways of 4 people and 4 colour = 4 × 4 = 16
L(w) R(m) Now, Arun dislikes red and Shweta dislikes white
Then, according to question
? R(m) Number of ways = 16 – 2 = 14 ways.
65. (c) Figure shows a hill station with peak P under a contour
In place of ‘?’ the place will be filled by left handed man of 550. At floods the water level is 525m. So, village R,S
According to question and T which are under a contour of 500 they will sub
So, there are 2 women. merge.
2017
SET - 2
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 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

5. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.

TECHNICAL 3. Match the algorithms with their time complexities:


Algorithm Time complexity
QUESTION 1 TO 25 CARRY ONE MARK EACH (P) Towers of Hanoi with n disks (i) Q (n2)
(Q) Binary search given n sorted (ii) Q(n log n)
1. The representation of the value of a 16-bit unsigned numbers
integer X in hexadecimal number system is BCA9. (R) Heap sort given n numbers at (iii) Q(2n)
The representation of the value of X in octal number
the worst case
system is
(a) 571244 (b) 736251 (S) Addition of two n × n matrices (iv) Q (log n)
(c) 571247 (d) 136251 (a) P ® (iii), Q ® (iv), R ® (i), S ® (ii)
2. Match the following: (b) P ® (iv), Q ® (iii), R ® (i), S ® (ii)
(P) Static char var; (i) Sequence of memory (c) P ® (iii), Q ® (iv), R ® (ii), S ® (i)
locations to store addresses (d) P ® (iv), Q ® (iii), R ® (ii), S ® (i)
(Q) m = malloc (10); (ii) A variable located in data 4. Let L1 L2 be any two context-free languages and R be any
m = NULL; section of memory regular language. Then which of the following is/are
(R) char * ptr [10]; (iii) Request to allocate a CPU CORRECT?
register to store data I. L1 È L2 is context-free.
(S) register int var 1; (iv) A lost memory which cannot II. L1 is context-free.
be freed III. L1 – R is context-free.
(a) P ® (ii), Q ® (iv), R ® (i), S ® (iii)
IV. L1 Ç L2 is context-free.
(b) P ® (ii), Q ® (i), R ® (iv), S ® (iii)
(a) I. II and IV only (b) I and III only
(c) P ® (ii), Q ® (iv), R ® (iii), S ® (i)
(d) P ® (iii), Q ® (iv), R ® (i), S ® (ii) (c) II and IV only (d) I only
EBD_7203
2017 -22 SOLVED PAPER - 2017
5. Match the following according to input (from the left 11. Let p, q, r denote the statements “It is raining”. “It is
column) to the compiler phase (in the right column) that cold”, and “It is pleasant”. respectively. Then the
processes it: statement “It is not raining and it is pleasant, and It is
(P) Syntax tree (i) Code generator not pleasant only if it is raining and it is cold” is
(Q) Character stream (ii) Syntax analyzer represented by
(R) Intermediate (iii) Semantic analyzer (a) (Ø p Ù r) Ù (Ø r ® (p Ù q))
representation (b) (Ø p Ù r) Ù (p Ù q) ® Ø r)
(S) Token stream (iv) Lexical analyzer (c) (Ø p Ù r) Ú (p Ù q) ® Ø r)
(a) P ® (ii), Q ® (iii), R ® (iv), S ® (i) (d) (Ø p Ù r) Ú (r ® (p Ù q))
(b) P ® (ii), Q ® (i), R ® (iii), S ® (iv) 12. Given the following binary number in 32-bit (single
(c) P ® (iii), Q ® (iv), R ® (i), S ® (ii) precision) IEEE-754 format:
(d) P ® (i), Q ® (iv), R ® (ii), S ® (iii) 00111110011011010000000000000000
6. Which of the following statements about parser is/are The decimal value closest to this floating-point number is
CORRECT? (a) 1.45 × 101 (b) 1.45 × 10–1
I. Canonical LR is more powerful than SLR. (c) 2.27 × 10 –1 (d) 2.27 × 101
II. SLR is more powerful than LALR. 13. A circular queue has been implemented using a singly
III. SLR is more powerful than Canonical LR. linked list where each node consists of a value and a
(a) I only (b) II only single pointer pointing to the next node. We maintain
(c) III only (d) II and III only exactly two external pointers FRONT and REAR pointing
7. Which of the following is/are shared by all the threads in to the front node and the rear node of the queue,
a process? respectively. Which of the following statements is/are
I. Program counter CORRECT for such a circular queue, so that insertion
II. Stack and deletion operations can be performed in 0 (1) time?
III. Address space I. Next pointer of front node points to the rear node.
IV. Registers II. Next pointer of rear node points to the front node.
(a) I and II only (b) III only (a) I only (b) II only
(c) IV only (d) III and IV only (c) Both I and II (d) Neither I nor II
8. In a file allocation system, which of the following allocation 14. Consider the following function implemented in C:
scheme(s) can be used if no external fragmentation is void printxy (int x, int y) {
allowed? int *ptr;
I. Contiguous x = 0;
II. Linked ptr = &x;
III. Indexed y = *ptr;
(a) I and III only (b) II only *ptr = 1;
(c) III only (d) II and III only printf (“%d, %d”, x,y);
9. Consider the following statements about the routing }
protocols. Routing Information Protocol (RIP) and Open The output of invoking printxy (1,1) is
Shortest Path First (OSPF) in an IPv4 network. (a) 0, 0 (b) 0, 1
I: RIP uses distance vector routing (c) 1, 0 (d) 1, 1
II: RIP packets are sent using UDP 15. The Breadth First Search (BFS) algorithm has been
III: OSPF packets are sent using TCP implemented using the queue data structure Which one of
IV: OSPF operation is based on link-state routing the following is a possible order of visiting the nodes in
Which of the statements above are CORRECT? the graph below?
(a) I and IV only (b) I, II and III only
(c) I, II and IV only (d) II, III and IV only M N O
æ πx ö æ 1ö 1
10. If f(x) = R sin çè ÷ø + S, f ’ çè ÷ø =
2 2 2 and ò0 f (x)dx

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

S ® XY 21. Consider the set X = {a,b,c,d,e} under the partial ordering


X ® aX | a R = {(a, a), (a, b), (a, c), (a, d), (a, e), (b, b), (b, c), (b, e),
Y ® aYb |Î (c, c), (c, e), (d, d), (d, e), (e, e)}.
(a) {ambn | m ³ n, n > 0 } The Hasse diagram of the partial order (X, R) is shown
(b) {ambn | m ³ n, n ³ 0 } below.
(c) {ambn | m > n, n ³ 0 } e
(d) {ambn | m > n, n > 0 }
17. An ER model of a database consists of entity types A and
B. These are connected by a relationship R which does
not have its own attribute. Under which one of the c
following conditions, can the relational table for R be d
merged with that of A?
(a) Relationship R is one-to-many and the participation
of A in R is total.
(b) Relationship R is one-to-many and the participation b
of A in R is partial.
(c) Relationship R is many-to-one and the participation a
of A in R is total.
(d) Relationship R is many-to-one and the participation The minimum number of ordered pairs that need to be
of A in R is partial. added to R to make (X, R) a lattice is _______.
18. Consider socket API on a Linux machine that supports
connected UDP sockets. A connected UDP socket is a é1 1 -1ù é -1 -2 -1ù
ê 2 -3 4 ú ê 6 12 6 ú
UDP socket on which connect function has already been 22. Let P = ê ú and Q = ê ú be two
called. Which of the following statements is/are êë 3 -2 3 úû êë 5 10 5 úû
CORRECT?
I. A connected UDP socket can be used to communicate matrices. Then the rank of P + Q is _______.
with multiple peers simultaneously. 23. G is an undirected graph with n vertices and 25 edges
II. A process can successfully call connect function such that each vertex of G has degree at least 3. Then the
again for an already connected UDP socket. maximum possible value of n is _______.
(a) I only (b) II only 24. Consider a quadratic equation x2 — 13x + 36 = 0 with
(c) Both I and II (d) Neither I nor II coefficients in a base b. The solutions of this equation in
19. Consider the following tables T1 and T2. the same base b are x = 5 and x = 6. Then b = _______.
25. The minimum possible number of states of a deterministic
finite automaton that accepts the regular language L =
T1 T2 { w1aw2|w1,w2 Î{a, b}*, | w1| = 2, |w2| ³ 3} is ________.
P Q R S
2 2 2 2 QUESTION 26 TO 55 CARRY TWO MARKS EACH
3 8 8 3
7 3 3 2 26. P and Q are considering to apply for a job. The probability
5 8 9 7 1
6 9 5 7 that P applies tor the job is , the probability that P
4
8 5 7 2
1
9 8 applies for the job given that Q applies for the job is ,
2
and the probability that Q applies for the job given that
In table Tl, P is the primary key and Q is the foreign key
1
referencing R in table T2 with on-delete cascade and on- P applies for the job is . Then the probability that P
update cascade, In table T2, R is the primary key and S 3
is the foreign key referencing P in table Tl with on-delete does not apply for the job given that Q does not apply
set NULL and on-update cascade. In order to delete record for the job is
{3,8} from table Tl. the number of additional records that 4 5
need to be deleted from table Tl is________. (a) (b)
5 6
20. The maximum number of IPv4 router addresses that can
be listed in the record route (RR) option field of an IPv4 7 11
(c) (c)
header is _________. 8 12
EBD_7203
2017 -24 SOLVED PAPER - 2017
(a) E ® E – T | T (b) E ® TE’
27. If w, x, y, z are Boolean variables, then which one of the
T®T+F|F E’ ® –TE’ | Î
following is INCORRECT?
F ® (E) | id T®T+F|F
(a) wx + w(x + y) + x(x + y) = x + wy
F ® (E) | id
(b) wx ( y + z) + wx = w + x + yz (c) E ® TX (d) E ® TX | (TX)
X ® –TX | Î X ® –TX | +TX | Î
(c) (wx ( y + xz ) + wx ) y = xy T ® FY T ® –id
(d) (w + y)(wxy + wyz) = wxy + wyz Y ® +FY | Î
28. Given f(w, x,y, z) = åm(0,l,2,3,7,8,10) + åd (5,6,ll,l5), where E ® (E) | id
d represents the don’t-care condition in Karnaugh maps. 33. A system shares 9 tape drives. The current allocation and
Which of the following is a minimum product-of-sums maximum requirement of tape drives for three processes
(POS) form of f (w,x,y,z)? are shown below:
f = (w + z )(x + z) Process Current Allocation MaximumRequirement
(a)
P1 3 7
(b) f = (w + z)(x + z) P2 1 6
P3 3 5
(c) f = (w + z)(x + z) Which of the following best describes current state of the
system?
(d) f = (w + z )(x + z)
(a) Safe, Deadlocked
29. In a two-level cache system, the access times of L1 and (b) Safe, Not Deadlocked
L2 caches are 1 and 8 clock cycles, respectively. The miss (c) Not Safe, Deadlocked
penalty from the L2 cache to main memory is 18 clock (d) Not Safe, Not Deadlocked
cycles. The miss rate of L1 cache is twice that of L2. The 34. Consider a binary code that consists of only four valid
average memory access time (AMAT) of this cache system codewords as given below:
is 2 cycles. The miss rates of L1 and L2 respectively are: 00000,01011,10101,11110
(a) 0.111 and 0.056 (b) 0.056 and 0.111 Let the minimum Hamming distance of the code be p and
(c) 0.0892 and 0.1784 (d) 0.1784 and 0.0892
the maximum number of erroneous bits that can be
30. Consider the recurrence function
corrected by the code be q. Then the values of p and q
ïì2T ( n ) + 1, n> 2 are
T ( n) = í (a) p=3 and q=1
ïî 2, 0 < n£2
(b) p=3 and q=2
Then T(n) in terms of Q notation is (c) p=4 and q=1
(a) Q (log log n) (b) Q (log n) (d) p=4 and q=2
35. Consider two hosts X and Y, connected by a single direct
(c) Q( n ) (d) Q (n) link of rate 106 bits/sec. The distance between the two
31. For any discrete random variable X. with probability mass hosts is 10,000 km and the propagation speed along the
function link is 2 × 108 m/sec. Host X sends a file of 50,000 bytes
N as one large message to host Y continuously. Let the
P{X = j) = pj, Pj ³ 0, j Î{0,....,N}, and å Pj = 1 . define transmission and propagation delays be p milliseconds
and q milliseconds, respectively. Then the values of p and
j =0
q are
N (a) p=50 and q=100
the polynomial function gx (z) = å Pj z j . For a certain (b) p=50 and q=400
(c) p=100 and q=50
j =0
(d) p=400 and q=50
discrete random variable Y. there exists a scalar b Î [0, 1]
such that gy (z) = (l – b + bz)N. The expectation of Y is 36. The pre-order traversal of a binary search tree is given
(a) Nb (l – b) by 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20. Then the post-
(b) Nb order traversal of this tree is:
(c) N (l – b) (a) 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20
(d) Not expressible in terms of N and b alone (b) 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12
32. Consider the following expression grammar G : (c) 7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12
E®E–T|T (d) 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12
T®T+F|F 37. Consider the C program fragment below which is meant to
F ® (E) | id divide x by y using repeated subtractions. The variables
Which of the following grammars is not left recursive, but x, y, q and r are all unsigned int.
is equivalent to G? while (r > = y) {
SOLVED PAPER - 2017 2017-25

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

1. (d) X = (B C A 9)16 2. L1 is not context-free because CFL are not closed


The ASC1 I value of A, B, C are 10, 11, 12 respectively under complement operation. So, it is incorrect.

(
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

9. (c) Consider each option. 11. (a) As given statements are :-


1. RIP use distance vector routing protocol because RIP p : "It is raining"
is one of the oldest DVR protocol which employ the q : "It is cold"
hop count as a routing metric table. So, it is correct. r : "It is pleasant".
2. RIP packets are sent using UDP, because UDP (User Then, the statement is:-
Datagram Protocol) work as a transport Protocol to
send the RI packets. So, it is correct. "It is not raining and it is pleasant" Þ (Ø p Ù r)
3. OSPF (Open Shortest Path First) packets are not sent And "It is not pleasant only if it is raining and it is cold"
using (TCP) because OSPF does not use a transport Þ Ø r ® ( p Ù q)
protocol, such as UDP ¹ TCP, so OSPF neither uses
TCP or UDP. So, it is not correct. (Ø p Ù r ) Ù (Ø r ® ( p Ù q))
4. OSPF operation is based on link-state routing because Hence, option (a) is correct.
OSPF is a routing protocol which uses Link State 12. The given binary number in 32-bits
Routing (LSR) and works within a single autonomous [00111110011011010000000000000000]
system. So, it is correct.
It can be formated as
Hence, option (C) is correct.
1 bit 8 bits 23 bits
10. (d) Given function :
0 01111100 11011010000000000000000
é px ù Sign Exponent Bits (Mantissa Bits)
f ( x) = R sin ê ú + S Bit
ë 2û \ (Sign = 0 (+ve)) {Number is positive}
So, biased exponent bits = 01111100 = 124
Rp é px ù
f '( x ) = cos ê ú E = 124 – 127 = –3 [\ Excess = 127]
2 ë 2û
(\ biase = 2 – 1, where (n = 8), So biase is = 27 – 1 = 128 – 1 = 127)
n – 1

æ1ö 1 Mantissa bit = 11011010000000000000000


Given f ' ç ÷ = 2, Put X = in f '(X)
è2ø 2 Normal Mantissa = 1 . M = 1 . 1101101
Data = Signbit . Mantissa . 2+[exponent bit]
é 1 ù Rp é pù Þ +1 .1101101.2–3
then, f ' ê ú = cos ê ú
ë2û 2 ë4û Mantissa align to right upto 3 times.
Rp ¯
2= +0.0011101101
2 2
¯
4 0.228
R=
p ¯
2.28 × 10–1 @ 2.27 × 10–1
1
2R é æ pX ö ù Hence option (c) is correct.
Given ò f ( x) dx =
0
p êQ f ( x) = R sin ç 2
ë è
÷ + Sú
ø û 13. (b) In circular queue next pointer of Rear node pointing to
the Front Node will lead to insertion in a queue is always
1
from REAR and deletion is always from FRONT node
-2R é æ pX öù 1 2R in Q(1) time.
cos ç ÷ ú + S ( X )0 =
p ëê è 2 øû0 p Front Rear
Head
A B C D
-2 R é p ù 2R
Then, cos - cos 0 ú + S (1 - 0) =
p êë 2 û p Hence, option (B) is correct.
14. (c) int * Ptr;
-8 2´4 æ 4ö
(0 - 1) + S = 2 Put ç R = ÷ X = 0;
p2 p è pø
Ptr
S =0
0
Hence, option (d) is correct . ×
EBD_7203
2017 -30 SOLVED PAPER - 2017
Ptr = & X m > n, because at least one will be attached on left of
Y = *Ptr ambn.
Þ (Y = 0) So, option (c) is correct.
*Ptr = 1; 17. (c) In one to many or many to one participation, relation is
merged in table which is on many side and if there
Ptr participation then relation is merged in that side consider
entity set A, B in the relationship set R.
1
Relation R merge with that of A and B.
×
Þ (X = 1)
A R B
So, the output of invoking print XY(1, 1) is M I
Þ (1, 0) According to the above figure.
Hence, option (c) is correct. Many to one relationship set can merge towards entity
15. (d) The Breadth First Search (BFS) algorithm has been set 'A' & Participation towards A side can be total.
implemented using the queue data structure. Hence option (c) is correct.
BSF : Start at root (root can be select as an arbitrary 18. (b) A process can successfully call connect function again
node of a graph, sometimes refered to as search key) for an already connected UDP socket for one of two
and explore the neighbor node first, before moving to reasons :
next level neighbours so let P is root Node.
(1) To specify a new IP address and Port.
Given graph :-
(2) To unconnect the socket.
5 4 A connected UDP socket have two function (1) Bind
M N O 2 ( ) function used to create local address.
(2) Connect ( ) function is specifying remote address.
Where as,
6 1 A unconnected UDP socket has only just a Bind ( )
R Q P function.
3
So, option (b) is correct.
Consider each options :
(i) MNOPQR 19. (0) As given that, Q ® R (Primary Key)
® After M and N vertices the vertex O can not be traversed. S ® P (Primary Key)
(ii) NQMPOR Entry to be deleted – P(3) and Q (8) in T1 table
® After visiting vertex M, vertex, O and P can not be Q can be deleted directly.
traversed. Now, S ® P but the relationship given is on delete
(iii) QMNROP set Null, therefore when we delete 3 from T1, the entry
® After N either of the vertices O or P can not be traversed. in T2 having 3 will be NULL.
(iv) POQNMR Consider the tables T1 and T2 :
® After N, Both M and R should be traversed.
So, option (d) is correct.
16. (c) The given grammar with S as start symbol is
T1 T2
S ® XY
P Q R S
X ® ax|a Þ X ® (a m | m ³ 1)
2 2 2 2
Y ® ayb|E Þ Y ® (a n bn | n ³ 0) 3 8 8 3 Null
7 3 3 2
S ® XY 5 8
6 9 9 7
S ® {a mb n | m > n, n ³ 0} 8 5 5 7
because, from Non terminal X we can generate any 9 8 7 2
number of a's including a single 'a' and from Y equal
No other record need to delete because of deletion of
number of a's and b's.
(3, 8) record from T1.
Hence L = {a m bn | m > n, n ³ 0} Hence, 0 is correct answer.
SOLVED PAPER - 2017 2017-31

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 )

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,

(P + Q) = (-16 + 16) = 0 L = {W1 aW2 | W1,W2 Î{a, b}*, | W1 |= 2, | W2 |³ 3} is

Now, The regular expression for L is


= (a + b)(a + b)a(a + b)(a + b)(a + b)(a + b) *
é0 -1ù
Take 2 × 2 Minor Matrix = ê ú The minimal DFA accepting L is :
ë8 9 û
a, b
Minor |P + Q| = 8 ¹ 0
So, rank of (P + Q) is 2. Hence 2 is correct answer. a, b a, b
a a, b a, b a, b
23. (16) If every vertex has degree at least 3 then, b
the maximum possible value of n
a, b
where (n is the vertices), given edge (E) = 25
Hence, the minimum number of state are 8.
EBD_7203
2017 -32 SOLVED PAPER - 2017
26. (4/5) Let A, B the events denotes that P, Q respectively applies 27. (c) As, given that : w, x, y, z are Boalean variables.
for a job. Consider each options.
1 é Aù 1 éBù 1 (1) wx + w(x + y) + x (x + y) = x + wy
As given that, P ( A) = , P ê ú = , P ê ú = then
4 B
ë û 2 ë Aû 3 take, L.H.S. Þ wx + w(x + y) + x (x + y)
P( A Ç B) = ? Q ( xx ® x )
æ A ö P( A Ç B) 1 Þ (wx + wx) + wy + x + xy
\Pç ÷ = =
èBø P(B) 2 Q ( wx + wx ® wx )
é B ù P( A Ç B) 1 Þ x (w + 1 + y) + wy Q [1 + x = 1]
Pê ú = =
ë Aû P ( A) 3 Þ x [w + 1] + wy Q [1 + y] = 1
Þ x + wy Q [1 + w] = 1
1
P ( A Ç B ) = * P ( A) L.H.S. = R.H.S. So, it is correct.
3
1 (2) wx ( y + z ) + wx = w + x + yz
\ P( A) =
4
Take, L.H.S. = wx × ( y + z ) + wx
æ 1ö
ç P( A Ç B) = ÷ By apply De'Morgan theorem
è 12 ø
So, P ( B) = 2* P( A Ç B ) = wx + ( y + z ) + wx Q[x + y = x × y ]

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)

Put P(A), P(B), P ( A Ç B) in this equation L.H.S. = xy

é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

28. (a) The given function


æ 1 ö
X =ç ÷
f ( w, x, y, z ) = å m
(0, 1, 2, 3, 7, 8, 10) è 2 L1 ø
....(3)

(Miss Palenality L1) = 8 + X . (18)


+ å (5, 6, 11, 15)
d L1 = 8 + 18 X ...(4)

= Õ M
(4, 9, 12, 13, 14) × d (5, 6, 11, 15) From eq. (3) put (L1) value to eq. (4)

where d represent don't care. æ 1 ö


L1 = ç ÷
Now by, Karnaugh maps. è 2X ø

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

or (Hit time) Hence option (a) is correct.

Miss penality L2 = 18 clock cycles 30. (b) T( n ) = 2T n + 1 ...(i)


(TAvg = 2 cycles)
Put n = 2k in equation (1)
Miss Rate (L1 = 2X)
taking log both side at base 2.
Miss Rate (L2 = X)
As we know that, log2 n = log 2 2k
TAverage = Hit time L1 + (Miss Rate L1 logn2 = k
× Miss Palenality L1) ...(1)
Miss Palenality L1 = Hit time L2 + (Miss Rate L2 k = log n2
× Miss Palenality L2) ....(2)
Put the given values in equation (1) and (2). T (2k ) = 2T (2k ) + 1
2 = 1 + 2 × (Miss Palenality 4)
= 2T [2k / 2 ] + 1
1 = 2 × (L1)
EBD_7203
2017 -34 SOLVED PAPER - 2017
33. (b) As given table is:
ék ù
Assume, T [2k ] = d(k ), T [2 k / 2 ] = d ê ú
ë2û Proces Current Maximum Remainin Current
s Allocation Requiremen g Need Avialable
ék ù
d[k ] = 2d ê ú + 1 P1 3 7 7 – 3 = 4 9 – 7 = 12
ë2û
P2 1 6 6– 1=5 5
Using first case of second rule of Masters Theorm. If P3 3 5 5– 3=2 8
k
(n logb a = n ) There are total 9 tape drives.
Then T (n) = Q[nk log(n)] So according to the above table we can see that, it
have currently allocated 7 tape drive, so currently
d( k ) = Q ( k ) available tape drive
Þ 9 – 7 = 2.
T [2k ] = Q(k )
So, P3 can use it and after using, it will release 3 then
new resources are available = 5, then P1 can use it and
T [ n] = Q[log n2 ] it will release 3, so new available resources = 8, and
lastly P2 can use it so all the process are in 'SAFE
Hence, option (b) is correct.
STATE' and there will be No 'DEADLOCK'.
31. (b) g y ( z ) = ((1 - b) + b z ) N Then we can get the following 2 safe sequence
If g y(z) is expanded, we would get a bionomial (1) <P3, P2, P1> (2) <P3, P1, P2>.
distribution with n = N and P = b. So, system is in safe state from (P3®P1®P2) and no
deadlocked.
So, the E[ y ] = nP = N b
Hence, option (b) is correct.
Hence option (B) is correct.
34. (a) As given that Code = 00000, 01011, 10101, 11110
32. (c) E ® E -T |T Let Code 1 is 0 0 0 0 0
T ®T + F | F Code 2 is 0 1 0 1 1
Code 3 is 1 0 1 0 1
F ® ( E ) | id
Code 4 is 1 1 1 1 0
Using the rule for removal of left recursion is Then the hamming distance between code 1 and code
2 is (3), because only three different digit between two
A ® Aa / b code. Similarly :
A ® bA ' hamming distance between (Code 1 and Code 3),
A ' ® a A '/ Î (Code 1 and Code 4), (Code 2 and Code 3), (Code 2 and
Code 4), (Code 3 and Code 4) are 3, 4, 4, 3, 3 respectively.
Then, the given grammar is written as :-
So, as per given data, minimum hamming distance of all
E ' ® -TE '/ Î code words is (P) considered as hamming distance is
= 3, (P = 3).
E ® +TE '
Now, the maximum number of erroneous bits that can be
T ' ® + FT '/ Î corrected (Code q), by the Hamming Code is = (2q + 1).
T ® FT ' According to hamming code,
F ® ( E ) | id Minimum hamming distance of all the code word equal
to the Maximum number of erroneous bits that can be
Now by putting E ' as X and T ' as Y, then corrected by the hamming code is
X ® -TX / Î 3 = (2q + 1)
E ® TX 3 – 1 = 2q

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

35. (d) As given that Let q = quotient and r = remainder.


B (Bandwidth) = 106 bits/sec So to divide a number with repeated subtraction,
D (Distance) = 10,000 Km = 104 × 103 m = 107 m quotient should be initialized to zero and should be
incremented for each subtraction.
V (Velocity) = 2 × 108 m/s
So, initially q = 0, then
L(Data size) = 50,000 bytes = 50000 × 8 bits
X = (Y*0 + r)
Data size (r = X)
Transmission time (P) =
Bandwidth
Since y is subtracted from reach time in given code. In,
statement one and q incremented by 1, to avoid
50,000 × 8 bits
= undefined behavior. In statement two and the value of
106 bits/sec y should be greater than zero.
P = 400 m/sec. Therefore (q = = 0) & & (r = = X) & & (y > 0).
Distance Hence, option (c) is correct.
Propagation time (V) = 38. (c) In the given program,
Velocity
First loop will execute 'n' times and the inner loop (j),
10000×103 m will execute Q(n log (n)) times because for (i = 1), j will
= run from 1 to n by incrementing by '1' in each step j will
2 ´ 108 m/sec
run for n times, for (i = 2).
= 50 × 105 – 8 sec Similarly j will run from 1 to n by incrementing by '2', in
(q = 50 m/sec.) = 50 × 10–3sec each step j will run for (n/2) times and so on.
Hence option (d) is correct. Then the time complexity
36. (b) The given pre-order traversal of a binary search tree is
n n n n
Pre order is : (Root, left, Right) Tn = + + + ..... ....log( n - 1)
1 2 3 (n - 1)
Pre order : 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20
In order is : (Left, Root, Right), é1 1 1 1 ù
= n ê + + + ..... ú - log( n - 1)
So in order of given sequence is : 2, 6, 7, 8, 9, 10, 12, 15, ë 1 2 3 ( n - 1) û
16, 17, 19, 20.
= n log (n – 1) – log (n – 1)
Then tree will be :
= n log (n – 1)
12 \ By neglected negative terms

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

Consider, (q2 , a) = (q2 , Î a) = {q1 , q2 q0 }.


+ +
Q1 Q0 Q1 Q0 T1 T0
(q2 , ab) = (q1 , b) = {q0 , q3 , q2 }
0 0 0 1 0 1
(q2 , b) = {q0 , q2 } 0 1 1 0 1 1
1 0 1 1 0 1
(q0 , b) = {q0 , q2 } .
1 1 1 1 0 0
(q2 , aba) = (q0 , a) = {q1 , q2 , q0 }
By using T flipflops, the counter is build as a
(q1 , a) = {q2 , q0 } synchronous sequential circuit.
Then the expression for T1 and T0 are,
(q2 , a) = {q1 , q2 , q0 }
T1 = Q1Q0
(q3 , a ) = {q3 }
T2 = (Q1Q0 ) + (Q1Q0 ) + (Q1Q0 )
Then, dˆ (q2 , aba) = {q1 , q2 , q0 }
= ( Q0 (Q1 + Q1 ) + Q1Q0 )
= {q0 , q1 , q2 }
T2 = (Q1 + Q0 )
Hence option (c) is correct.
Hence option (b) is correct.
40. (d) Consider the given languages.
43. (3) The initial contents of the Array is :-
L1 = {aP|P is a Prime Number},

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

(1 - z ) -3 = (1 + z )*(1 + 3C1 z + 4C2 z 2 + 5C3 z 3 + ......¥) 0.25 0.34 0.19 0.22


0 1
Q S P
a0 is first term in the expansion of above series and a3
0.08 0.17
is the fourth term or coefficient of z3.
Then, we find the value of a0 and a3, so T R
a0 (coefficient of z0) = 1 So, number of bit required for each alphabet :
T = 3 bit, R = 3 bit, Q = 2 bit, S = 2 bit, P = 2 bit
a3 (coefficient of z3) = 5C3 + 4C2
Then, average length per character is
= 10 + 6 = 16 = (number of bits * frequency of occurance of each
Then, a3 – a0 = 16 – 1 = 15. alphabets)
Hence 15 is correct answer. = 3 * 0.08 + 3 * 0.17 + 2 * 0.34 + 2 * 0.19 + 2 * 0.22
48. (54) Given poisson distribution. = 2.25 bits
E(X) = V(X) = l And, average length for 100 character = 2.25 * 100 = 225 bits.
So, E(X) = V(X) = 5 Hence, 225 bits is correct answer
51. (29)
then we find E[( X + 2)2 ] = E ( X 2 ) + 4 E ( X ) + 4
We know that Process Arrival Time Burst Time Priority
P1 0 11 2
(QV ( X ) = E ( X 2 ) - ( E ( X ))2 )
P2 5 28 0
So, putting the value of V(X) and E(X) in above equation
P3 12 2 3
Then, 5 = E(X2) – (5)2 P4 2 10 1
E(X2) = 25 + 5 = 30 P5 9 16 4
So, E[( X + 2)2 ] = E ( X 2 ) + 4 E ( X ) + 4 Total 28 67

= 30 + 4 × 5 + 4 = 54 Gantt chart for above problem looks like :


Hence, 54 is correct answer. P1 P4 P2 P 4 P1 P3 P5
49. (52) As given that : Search key = 8 bytes 0 2 5 33 40 49 51 67

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.

GENERAL APTITUDE (a) zentaga (b) tagafer


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

22. Consider the following C program: 26. Which of the following languages is generated by the given
void f (int, short); grammar?
void main () S ® aS | bS | e
{ int i = 100;
(a) {anbm |n, m > 0}
short s = 12;
(b) {w Î {a, b}*|w has equal number of a’s and b’s}
short *p = &s;
__________ ; // call to f () (c) {an|n > 0} È {bn | n > 0} È {anbn|n > 0}
} (d) {a,b}*
Which one of the following expressions, when placed in the 27. Which of the following decision problems are undecidable?
blank above, will NOT result in a type checking error? I. Given NFAs N1 and N2, is L(N1) Ç L(N2) = F?
(a) f (s,*s) (b) i = f (i, s) II. Given a CFG G = (N, S, P, S) and a string x Î S*, does
x Î L(G)?
(c) f (i,*s) (d) f (i,*p)
III. Given CFGs G1 and G2 is L(G1) = L(G2)?
23. The worst case running times of Insertion sort, Merge sort
and Quick sort, respectively, are: IV. Given a TM M, is L(M) = F?
(a) I and IV only (b) II and III only
(a) Q (n log n), Q (n log n), and Q (n2)
(c) III and IV only (d) II and IV only
(b) Q (n2), Q (n2), and Q (n log n)
28. Which one of the following regular expressions represents
(c) Q (n2), Q (n log n), and Q (n log n) the language: the set of all binary strings having two
(d) Q (n2), Q (n log n), and Q (n2) consecutive 0s and two consecutive 1s?
24. Let G be a weighted connected undirected graph with distinct (a) (0+1)*0011(0+1)*+(0+1)*1100(0+1)*
positive edge weights. If every edge weight is increased by (b) (0+1)*(00(0+1)*11+11(0+1)*00)(0+1)*
the same value, then which of the following statements is/ (c) (0+1)*00(0+1)*+(0+1)*11(0+1)*
are TRUE? (d) 00(0+1)*11+11(0+1)*00
P: Minimum spanning tree of G does not change 29. Consider the following code segment:
Q: Shortest path between any pair of vertices does not change x = u – t;
(a) P only (b) Q only y = x * v;
(c) Neither P nor Q (d) Both P and Q x = y + w;
25. Consider the following C program: y = t – z;
#include <stdio.h> y = x * y;
void mystery (int *ptra, int *ptrb){ The minimum number of total variables required to convert
the above code segment to static single assignment form
int *temp; is __________.
temp = ptrb; 30. Consider an arbitrary set of CPU-bound processes with
ptrb = ptra; unequal CPU burst lengths submitted at the same time to a
computer system. Which one of the following process
ptra = temp;
scheduling algorithms would minimize the average waiting
} time in the ready queue?
int main() { (a) Shortest remaining time first
int a=2016, b=0, c=4, d=42; (b) Round-robin with time quantum less than the shortest
mystery (&a, &b); CPU burst

if (a < c) (c) Uniform random


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

45. What will be the output of the following C program? 50. G = (V,E) is an undirected simple graph in which each edge
void count (int n){ has a distinct weight, and e is a particular edge of G. Which
static int d=1; of the following statements about the Minimum Spanning
Trees (MSTs) of G is/are TRUE?
print f (“%d”, n); I. If e is the lightest edge of some cyclein G, then every
print f (“%d”, d); MST of G includes e
d++;
II. If e is the heaviest edge of some cyclein G, then
if (n>1) count (n – 1);
every MST of G excludes e
print f (“%d”, d);
} (a) I only (b) II only
void main( ){ (c) both I and II (d) neither I nor II
count(3); 51. Let Q denote a queue containing sixteen numbers and S be
} an empty stack. Head (Q) returns the element at the head of
(a) 3 1 2 2 1 3 4 4 4 (b) 3 1 2 1 1 1 2 2 2 the queue Q without removing it from Q. Similarly Top (S)
(c) 3 1 2 2 1 3 4 (d) 3 1 2 1 1 1 2 returns the element at the top of S without removing it from
46. What will be the output of the following pseudo-code when S. Consider the algorithm given below.
parameters are passed by reference and dynamic scoping is
assumed?
a = 3; while Q is not Empty do
void n(x) {x = x * a; print(x);} if S is Empty OR Top(S) £ Head(Q) then
x := Dequeue(Q);
void m(y) {a = 1; a = y – a; n(a); print(a);} Push(S, x);
void main( ) {m(a);} else
x := Pop(S);
(a) 6, 2 (b) 6, 6 Enqueue(Q, x);
(c) 4, 2 (d) 4, 4 end
end
47. An operator delete (i) for a binary heap data structure is to
be designed to delete the item in the i-th node. Assume that
the heap is implemented in an array and i refers to the i-th
index of the array. If the heap tree has depth d (number of The maximum possible number of iterations of the while loop
edges on the path from the root to the farthest leaf), then in the algorithm is _________.
what is the time complexity to re-fix the heap efficiently after 52. Consider the following context-free grammars:
the removal of the element?
G1: S ® aS | B, B ® b | bB
(a) O (1)
G2: S ® aA | bB, A ® aA | B | e, B ® bB | e
(b) O (d) but not O (1)
Which one of the following pairs of languages is generated
(c) O (2d) but not O (d)
by G1 and G2, respectively?
(d) O (d 2d) but not O (2d)
(a) {ambn|m > 0 or n > 0} and {ambn|m > 0 and n > 0}
48. Consider the weighted undirected graph with 4 vertices,
where the weight of edge {i, j} is given by the entry Wi j in (b) {ambn|m > 0 and n > 0} and {ambn|m > 0 or n ³ 0}
the matrix W. (c) {ambn|m ³ 0 or n > 0} and {ambn|m > 0 and n > 0}

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


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

(a) {m, K+B (H(m))} (b) {m, K–B (H(m))} output at a rate of 10 megabytes per second. The token
(c) {m, K–A (H(m))} (d) {m, K+A (m)} bucket is currently full and the machine needs to send 12
63. An IP datagram of size 1000 bytes arrives at a router. The mega bytes of data. The minimum time required to transmit
router has to forward this packet on a link whose MTU the data is _______ seconds.
(maximum transmission unit) is 100 bytes. Assume that the 65. A sender uses the Stop-and-Wait ARQ protocol for reliable
size of the IP header is 20 bytes. transmission of frames. Frames are of size 1000 bytes and
The number of fragments that the IP datagram will be the transmission rate at the sender is 80 Kbps (1Kbps =
divided into for transmission is __________ . 1000 bits/second). Size of an acknowledgement is 100
64. For a host machine that uses the token bucket algorithm bytes and the transmission rate at the receiver is 8Kbps.
for congestion control, the token bucket has a capacity The one-way propagation delay is100 milliseconds.
of 1 megabyte and the maximum output rate is 20 Assuming no frame is lost, the sender throughput is
megabytes per second. Tokens arrive at a rate to sustain ________ bytes/second.
EBD_7203
2016 -8 SOLVED PAPER - 2016

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


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

15. 15 22. (d)


Given that 2 + -1 and 3 are two Eigen values of 3 × 3 real ‘i’ is integer and *P is value of a pointer to short.
23. (d)
matrix. That is (2 + i) and 3 are Eigen values. But (2 – i) is also
The worst case running times of Insertion sort is O(n 2),
an Eigen value ( Q complex roots occur in pair only)
because of the series of swaps required for each insertion.
determinant of p = Product of Eigen values = (2 + i) × (2 – i)
Merge sort is O(n log n) as merge sort always divides the
× 3 = 5 × 3 = 15
array in two halves and take linear time to merge two halves
16. (a) x #0 = x; and Quick sort is O(n2).
x #1 = x; 24. (a) The shortest path may change. The reason is, there
may be different number of edges in different paths
x # x = 0; from s to t. For example, let shortest path be of weight
10 and has 5 edges. Let there be another path with 2
x # x = 1.
edges and total weight 25. The weight of the shortest
This function # basically represents XOR.
path is increased by 5*10 and becomes 10 + 50. Weight
17. – 11 of the other path is increased by 2*10 and becomes 25
1111 1111 1111 0101
+ 20. So the shortest path changes to the other path
2’s complement 0000 0000 0000 1011 with weight as 45.
11 and Ist bit is 1 The Minimum Spanning Tree doesn't change.
So result is –11
Remember the Kruskal's algorithm where we sort the
18. 3 edges first. If we increase all weights, then order of
Let output of 3 flip-flops be S1, S2, S3. edges won't change.
S1 S2 S3 25. 2016
As in C, parameters are passed by value - even if they are
pointers. So, here the pointer values are exchanged within
the function only (one can use * operator to exchange the
values at the location of the pointers and this will affect the
A B C values in main). So, there will be no change in a, b, c, d. The
output of the program is 2016.
26. (d)
S1 S2 S3 A B C 27. (c) There is no known algorithm to verify whether the
1 0 0 1 0 0 language accepted by TM is empty or not. Similarly
there is no algorithm to verify whether language of
0 0 1 0 0 1
CFG’s are equivalent.
1 0 1 1 0 0 28. (b) Option (a) contains 00 and 11 consecutively which
0 1 0 0 1 0 does not fulfill the required condition. Option (c) does
1 1 0 1 0 0 not give assurance that both 00 and 11 will be exist in
0 1 1 0 1 1 the string.
According to option (d), string should start with 11
So, if one takes BC as final output, then it can generate the and ends with 00 or vice versa. Hence option (b) is the
sequence 0 ® 1 ® 0 ® 2 ® 0 ®3. Hence the answer is 3. correct answer.
19. 31 29. 10
Maximum memory = 4 GB = 232 bytes 30. (a) SRTF is the preemptive SJF which generates less
Size of a word = 2 bytes average waiting time in which jobs are schedule
Therefore, Number of words = 232/2 = 231 according to shortest remaining time.
So, we require 31 bits for the address bus of the processor. 31. (b) Super key = Candidate key + other attributes. But
20. (a) We can use circular array to implement both O(1) time. option (b) does not include Y which is part of candidate
21. 6 Key.
The different topological orderings will be as follows: 32. (d) ‘D’ stands for Durability, not deadlock-freedom.
(1) a b c d e f 33. (a) The candidate key is (volume, number, start page, end
(2) a d e b c f page), (Volume, number) ® year is a partial dependency.
(3) a b d c e f But it does not follow 2NF.
(4) a d b c e f 34. (c) DHCP is not used to resolve one form of address to
(5) a b d e c f another. DHCP is used to assign IP dynamically. All
(6) a d b e c f others are used to convert one address to other.
EBD_7203
2016 -10 SOLVED PAPER - 2016
35. (c) TCP is stateful as it maintains connection information
across multiple transfers, but TCP is not an application æ ö
1æ 1 æ1ö ö 1ç 1 ÷ 1 4 1
2
layer protocol. Of the given protocols, only FTP and ç1 + + + ..... ÷ = ç ÷= ´ =
POP3 are stateful application layer protocols. = 4 ç 4 çè 4 ÷ø ÷ 4ç 1 4 3 3
è ø ç 1 - ÷÷
36. 10 è 4ø
(x3 + x4 + x5 + x6 + ....)3 = 0.33
= x9 (1 + x + x2 + .......)3 40. (d)
= x9 ((1 – x)–1)3
= x9 (1 – x)–3 The output of first multiplexer is Y1 = P0 + PR = PR
The output of second multiplexer is
¥
( n + 1)( n + 2 ) x n
=x å
9
2 X = QR + QY1 = QR + QPR
n=0
To find the coefficient of x12, put n = 3 Þ QR + PQR
4´5 41. 456
= = 10 Number of times the DMA controller needs to get the control
2
of the system bus from the processor to transfer the file
37. 198 from the disk to main memory =
The given recurrence relation can be written as
an – an–1 = 6n2 + 2n ...(i) 29154kB
Þ Þ 455.53125 = 456
Hence, the characteristic equation is m – 1 = 0, m = 1 216 byte
and complementary solution = a (n1) = C1 (1) n = C1 42. 33.33
Old design tp = 800
(b)
(2
)
Let the particular solution be a n = An + Bn + C n ...(ii) New design tp = 600
800 - 600
(... RHS is second degree polynomial and 1 is root) Throughput = ´ 100% = 33.33%
By putting an = (An 2 + Bn + C)n in (1) and solving A = 600
2, B = 4, C = 2 43. (b)
44. (d)
General solution is a n = a (c) (b) 2
n + a n = C1 + (2n + 4n + 2) n P[a] will have the maximum value of the array, when a = b.
Given a1 = B Þ B = C1 + B Þ C1 = 0 45. (a)
Given a99 = K × 104
Þ [2(99)2 + 4(99) + 2]99 = 2[(100 – 1)2 + 2(100 – 1) +
(100 – 1)]
= 104(198) = K × 104 main()
K = 198
38. 2 Count (3)
In the given properties, we can observe that f(1) = f(2)
= f(3) = f(4) = f(6) = f(7) and f(5) = f(10) = f(15) = ....
Obviously, the range of f(x) will contain two distinct Pr(4)
elements only. Pr(3) Pr(1) Count (2)
39. 0.33
From the given steps the probabilities of y are
2 Pr(4)
1 æ 1 öæ 1 ö æ 1 ö 1 Pr(2) Count (1)
, ç ÷ç ÷ , ç ÷ ,...... Pr(2)
4 è 4 øè 4 ø è 4 ø 4
Hence, Required probability
Pr(4)
1 æ 1 1 ö ææ 1 ö 1 ö
2
Pr(1) Pr(3) Count (0)
= 4 ç 4 4 ÷ ç ç 4 ÷ ´ 4 ÷÷ + .....
+ ´ + ç
è ø èè ø ø
2 3 Output will be 312213444.
1 æ1ö æ1ö 46. (d)
= + ç ÷ + ç ÷ + .....
4 è4ø è4ø Dynamic scoping refers to definition of free variable in the
reverse order of calling sequence.
SOLVED PAPER - 2016 2016-11

47. (b)
48. 12 print (1)
3
56. (c)
8 S¢
d b

2 print (3)
5 x 5 a A 2

a c b
8 Print (2)(1) s
The shortest path (excluding x) from 2 to 3 is of weight 12
(2–1–0–3). a
49. 7
57. 384
4 4 Size of memory = 240, Page size = 16KB = 214, No. of pages
= Size of Memory/page size = 240/214 = 226, Size of page
1 table = 226 * 48/8 bytes = 26*6 MB = 384 MB
1 3
5 6 Þ 58. 165
The head movement would be :
2 2
63 => 87 24 movements
50. (b) I is NOT true. Suppose in a rectangular with sides (1, 2,
87 => 92 5 movements
4, 5) and 3 is the weight of the diagonal connecting
vertex between (4, 5) and (1, 2), here e = 3 is the lightest 92 => 121 29 movements
edge of some cycle in G but in MST it is not including. 121 => 191 70 movements
II is true. Let the heaviest edge be e. Suppose the 191 => 10 0 movement
minimum spanning tree which contains e. If we add 10 => 11 1 movement
one more edge to the spanning tree we will create a
11 => 38 27 movements
cycle. Suppose we add edge e' to the spanning tree
which generated cycle C. We can reduce the cost of 38 => 47 9 movements
the minimum spanning tree if we choose an edge other Total head movements = 165
than e from C for removal which implies that e must not 59. 1
be in minimum spann ing tree and we get a a1a2........a20 a1a2...........a20
contradiction. LIFO
51. 256
... n = 16 0 a1
Therefore, maximum number of iterations will be n2 = 256 1 a2
52. (d) In G1, there will be atleast 1 b because S->B and B->b. 2 a3
But no. of A's can be 0 as well and no. of A and B are 3 a4
independent. In G2, either we can take S->aA or S->bB. 4 a5
So it must have atleast 1 a or 1 b. So option (d) is 5 a6
correct. 6 a7 a11 a12 a13 a14 a15 a16 a17 a18 a19 a 20
53. (d) Initial state is also the final state. 7 a8
So an is also accepted. 8 a9
54. (c) 9 a10
55. 9
2 – 5 + 1 – 7 * 3 Þ 2 – (5 + 1) – 7 * 3 For first a1 to a20, The no. of page faults = 20
Þ 2 – 6 – 7 * 3 Þ 2 – (6 – 7) * 3 Þ 2 – (–1) * 3 Now a1 to a9, Hit again a10 to a20 replace only 9th position,
Þ (2 + 1) * 3 Þ 3 * 3 = 9 so no. of page faults = 11. S0, total no. of page faults = 31
EBD_7203
2016 -12 SOLVED PAPER - 2016
Optimal 63. 13

0 a1 1000 Bytes MTU


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

Hash L 1000Bytes
M Tx ( msg ) = = = 100 ms
Function Bs 10 ´103 BPS

LA 100Bytes
TA ( Ack ) = = = 100 ms
Senders Private BR 1´103 BPS

Key (KB ) H(m) Tp =100 ms
\ Channel Utilization
Tn 100 ms 1
K -B (H (m )) = T + T + 2T = 100 ms + 100 ms + 200 ms = 4
Digital Signature n ack p
generator
1
\ Throughput = h × B = × 10 × 103 = 2.5 Kbps
+ M Å K -B (H (m)) 4
(or 2500 bps)
SOLVED PAPER - 2016 2014-13

2016
SET - 2
Duration: 3 hrs Maximum Marks: 100

INSTRUCTIONS
1. There are a total of 65 questions carrying 100 marks.
2. This question paper consists of 2 sections, General Aptitude (GA) for 15 marks and the subject specific
GATE paper for 85 marks. Both these sections are compulsory.
3. The GA section consists of 10 questions. Question numbers 1 to 5 are of 1-mark each, while question numbers 6 to
10 are of 2-marks each. The subject specific GATE paper section consists of 55 questions, out of which question
numbers 11 to 35 are of 1-mark each, while question numbers 36 to 65 are of 2-mark each.
4. Questions are of multiple choice type (MCQ)or numerical answer type. A multiple choice type question will have four
choices for the answer with only one correct choice. For numerical answer type questions, the answer is a number
and no choices will be given.
5. Questions not attempted will result in zero mark. Wrong answers for multiple choice type questions will result in
1
NEGATIVE marks. For all 1 mark questions mark will be deducted for each wrong answer. For all 2 marks questions,
3
2
mark will be deducted for each wrong answer..
3
6. There is NO NEGATIVE MARKING for questions of NUMERICAL ANSWER TYPE.

GENERAL APTITUDE 4. Pick the odd one from the following options.
(a) CADBE (b) JHKIL
QUESTION 1 TO 5 CARRY ONE MARK EACH (c) XVYWZ (d) ONPMQ
5. In a quadratic function, the value of the product of the
1. The man who is now Municipal Commissioner worked as
____________________. a n + bn
roots (a, b) is 4. Find the value of
(a) the security guard at a university a - n + b- n
(b) a security guard at the university
(a) n4 (b) 4n
(c) a security guard at university
(c) 22n-1 (d) 4n-1
(d) the security guard at the university
2. Nobody knows how the Indian cricket team is going to QUESTION 6 TO 10 CARRY TWO MARKS EACH
cope with the difficult and seamer-friendly wickets in 6. Among 150 faculty members in an institute, 55 are
Australia. connected with each other through Facebook® and 85 are
Choose the option which is closest in meaning to the connected through WhatsApp®. 30 faculty members do
underlined phrase in the above sentence. not have Facebook® or WhatsApp® accounts. The
(a) put up with (b) put in with number of faculty members connected only through
Facebook® accounts is ______________.
(c) put down to (d) put up against
(a) 35
3. Find the odd one in the following group of words.
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

Miss rate (%)


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

Proces s Arrival Time Burs t Time


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

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


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

1. (b) 10. (c)


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

Statement III is true. 23. (d)


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

( )
-1 T T 1 that no. of a’s should be equal to no. of b’s, but order
Now, A = A -1 = A -1 = = 0.125
8 of a’s and b’s is different here, it is (ab)*, which will
require no extra memory to be accepted. (Finite
17. –1
Automaton can be built for this language). Hence L2 is
18. (c) regular language. Therefore Q is True.
19. 1
28. (d) Statement (IV) : L2 may or may not be context free
X = –216 – 1 to +216 – 1 – 1
Y = –216 – 1 – 1 to +216 – 1 – 1 because CFL are not closed under complementation.
So it is not true.
Therefore, X – Y = 1
29. (b)
20. 16 6 bits are needed for 40 distinct instructions (because,
30. (d) When the rate of page fault increases even after the
32 < 40 < 64) 5 bits are needed for 24 general purpose
increasing number of allocated frames, then this
registers (because, 16 < 24 < 32) 32-bit instruction word
situation is called “Belady’s Anamoly”. In the given
has an opcode(6 bit), two register operands(total 10
options, it’s occurring in FIFO only.
bits) and an immediate operand (x bits). The number of
31. (a) In B and B+ trees, all the leaf nodes will be at same
bits available for the immediate operand field => x = 32
level.
– (6 + 10) = 16 bits
32. (a)
33. (a) In the process of digital signature generation, by using
sender’s private key, one can encrypt the message and
in the process of verification, by using sender’s public
key, one can decrypt the message.
21. 31 34. (d)
35. (c) When a web browser requests any web page from a
remote server then that request (URL address) is
mapped to IP Address usin g DNS, th en TCP
It would be node number 31 for given distance 4. synchronisation occurs. Finally HTTP verifies that the
22. 30 address exists in the web server or not.
The address of i and value of j are passed to the function of 36. (b) R is reflexive as every ordered pair is related to itself.
f. f modifies i’s value to 20. j’s value remains same (as its (a, b) R (a, b) since a £ a or b £ b
value is passed not the reference). The value printed by the
It is not transitive as (2, 4) R (3, 2) and (3, 2) R(1, 3) but
program will be i + j = 20 + 10 = 30.
(2, 4) R (1, 3).
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.

GENERALAPTITUDE (c) Flippancy – Lightness


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

14. The height of a tree is the length of the longest root-to-leaf 21. Which of the following statements is/are FALSE?
path in it. The maximum and minimum number of nodes in I. XML overcomes the limitations in HTML to support a
a binary tree of height 5 are structured way of organizing content.
(a) 63 and 6, respectively II. XML specification is not case sensitive while HTML
(b) 64 and 5, respectively specification is case sensitive.
(c) 32 and 6, respectively III. XML supports user defined tags while HTML uses pre-
(d) 31 and 5, respectively
defined tags.
15. Match the following:
IV. XML tags need not be closed while HTML tags be
P: Prim’s algorithm for minimum spanning tree
closed
Q: Floyd – Warshal algorithm for all pairs shortest paths
R: Mergesort (a) II only (b) I only
S: Hamiltonian circuit (c) II and IV only (d) III and IV only
(I) Backtracking (II) Greedy method 22. A file is organized so that the ordering of data records is the
(III) Dynamic programming same as or close to the ordering of data entries in some index.
(IV) Divide and conquer Then that index is called
(a) P-III, Q-II, R-IV, S-I (a) Dense (b) Sparse
(b) P-I, Q-II, R-IV, S-III (c) Clustered (d) Unclustered
(c) P-II, Q-III, R-IV, S-I 23. Which of the following is/are correct inorder traversal
(d) P-II, Q-I, R-III, S-IV sequence(s) of binary search tree(s)?
16. Which one of the following is NOT equivalent to p«q? I. 3, 5, 7, 8, 15, 19, 25 II. 5, 8, 9, 12, 10, 15, 25
(a) (Øpvq)^(p^Øq) (b) (Øpvq) ^(q®p)
III. 2, 7, 10, 8, 14, 16, 20 IV. 4, 6, 7, 9, 18, 20, 25
(c) (Øp^q)v(p^Øq) (d) (Øp^Øq) v(p^q)
(a) I and IV only (b) II and iii only
17. SELECT operation in SQL is equivalent to
(c) II and IV only (d) II only
(a) the selection operation in relational algebra
(b) the selection operation in relational algebra, except that 24. Suppose two hosts use a TCP connection to transfer a large
SELECT in SQL retains duplicates file. Which of the following statements is/are FALSE with
(c) the projection operation in relational algebra respect to the TCP connection?
(d) the projection operation in relational algebra, except I. If the sequence number of a segment is m, then the
that SELECT in SQL retains duplicates sequence number of the subsequent segment is always
18. For any two languages L1 and L2 such that L1 is context-free m + 1.
and L2 is recursively enumerable but not recursive, which of II. If the estimated round trip time at any given point of
the following is/are necessarily true? time is t sec the value of the retransmission timeout is
I. L1 (complement of L1) is recursive always set to greater than or equal to t sec.
III. The size of the advertised window never changes
II. L2 (complement of L2) is recursive
during the curse of the TCP connection.
III. L1 is context – free IV. The number of unacknowledged bytes at the sender is
always less than or equal to the advertised window.
IV. L1 È L2 is recursively enumerable
(a) III only (b) I and III only
(A) I only (B) III only
(c) I and IV only (d) II and IV only
(C) III and IV only (D) I and IV only
25. For computers based on three-address instruction formats,
19. For a set A, the power set of A is denoted by 2A. If A = {5,
each address field can be used to specify which of the
{6}, {7}}, which of the following options are TRUE?
I. fÎ 2A II. f Î 2A following.
III. {5, {6}} Î 2A IV. {5{6}} Í 2A S1: A memory operand
(a) I and III only (b) II and III only S2: A processor register
(c) I, II and III only (d) I, II and IV only S3: An implied accumulator register
20. Consider a 4-bit Johnson counter with an initial value of (a) Either S1 or S2 (b) Either S2 or S3
0000. The counting sequence of this counter is (c) Only S2 and S3 (d) All of S1, S2 and S3
(a) 0, 1, 3, 7, 15, 14, 12, 8, 0 26. Consider a system with byte–addressable memory, 32-bit
(b) 0, 1, 3, 5, 7, 9, 11, 13, 15, 0 logical addresses, 4 kilobyte page size and page table entries
(c) 0, 2, 4, 6, 8, 10, 12, 14, 0 of 4 bytes each. The size of the page table in the system in
(d) 0, 8, 12, 14, 15, 7, 3, 1, 0 megabytes is ______.
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® Î, ^ ® Î

Roll No. Student Name


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

55. Consider the following C function. 60. Consider the following C program segment.
int fun1 (int n) while (first <= last)
{ {
int i, j, k, p, q = 0; if (array[middle] < search)
for (i = 1; i < n; ++i) first = middle + 1;
{ else if (array[middle] = = search)
p = 0; found = TRUE;
for(j = n; j > 1; j = j/2) else last = middle – 1;
++p; middle = (first + last)/2;
for(k =1; k < p; k = k*2) }
++q; if (first > last) notPresent = TRUE;
}
return q; The cyclomatic complexity of the program segment is
} ______.
Which one of the following most closely approximates the 61. Consider a max heap, represented by the array: 40, 30, 20,
return value of the function fun1? 10, 15, 16, 17, 8, 4.
(A) n3 (B) n(log n)2
Array Index 1 2 3 4 5 6 7 8 9
(C) n log n (D) n log(log n)
Value 40 30 20 10 15 16 17 8 4
56. Consider a non-pipelined processor with a clock rate of 2.5
gigahertz and average cycles per instruction of four. The Now consider that a value 35 is inserted into this heap. After
same processor is upgraded to a pipelined processor with five insertion, the new heap is
stages; but due to the internal pipelined delay, the clock speed (a) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
is reduced to 2 gigahertz. Assume that there are no stalls in (b) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
the pipeline. The speed up achieved in this pipelined (c) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
processor is _____. (d) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
57. Consider an Entity-Relationship(ER) model in which entity 62. Suppose the following disk request sequence (track numbers)
sets E1 and E2 are connected by an m: n relationship R12. E1 for a disk with 100 tracks is given: 45, 20, 90, 10, 50, 60, 80,
and E3 are connected by a 1: n (1 on the side of E 1 and n on 25, 70. Assume that the initial position of the R/W head is on
the side of E3) relationship R13. track 50. The additional distance that will be traversed by the
E1 has two single-valued attributes a11 and a12 of which a11 R/W head when the Shortest Seek Time First (SSTF)
is the key attribute. E2 has two single-valued attributes a21 algorithm is used compared to the SCAN (Elevator)
and a22 of which is the key attribute. E3 has two single-valued algorithm (assuming that SCAN algorithm moves towards
attributes a31 and a32 of which a31 is the key attribute. The 100 when it starts execution) is ______ tracks.
relationships do not have any attributes. 63. Consider a LAN with four nodes S1¸S2, S3 and S4. Time is
If a relational model is the derived from the above ER model, divided into fixed-size slots, and a node can begin its
then the minimum number of relations that would be transmission only at the beginning of a slot. A collision is said
generated if all the relations are in 3NF is _______.
to have occurred if more than one node transmit in the same
99 slot. The probability of generation of a frame in a time slot
1
58. å x(x + 1)
= ______________ .
by S1, S2, S3 and S4 are 0.1, 0.2, 0.3 and 0.4, respectively.
x =1
The probability of sending a frame in the first slot without any
59. Let a n represent the number of bit strings of length n
collision by any of these four stations is ________.
containing two consecutive 1s. What is the recurrence
64. An algorithm performs (log N)1/2 find operations, N insert
relation for an?
operations, (log N)1/2 delete operations, and (log N)1/2
(A) an–2+ an–1+2n–2
decrease-key operations on a set of data items with keys
(B) an–2+2an–1+2n–2
drawn form a linearly ordered set. For a delete operation, a
(C) 2an–2+a n–1+2n–2
pointer is provided to the record that must be deleted. For the
(D) 2an–2+2an–1+2n–2
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

GENERAL APTITUDE TECHNICAL SECTION


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

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


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

él l11u12 ù
g ( h ( x )) h (x) = ê 11 ú
= ël21 l21u12 + l22 û
h ( g ( x )) g (x)
\ l11 = 2;l11u12 = 2 Þ u12 = 1
31. (d) HTTP (Hyper Text Transfer Protocol) and SMTP l21 = 4; l21u12 + l22 = 9 Þ l22 = 5
(Simple Message Transfer Protocol) protocols can use
several TCP associations between the same client and 15
the server. B E
10 4
32. (b) If we judge a single string of binary search tree, then
we have to sketch all the nodes for insertion or deletion
2 7 F
in worst case hence θ (n) for both. A
36. 69
33. –5 In function "main ()" 9 6
D
f1 is called by value, so local variables a, b, c of f1 are C
16
customized but not the local variables a, b, c of main
function.
f2 is called by reference. Total sum = 10 + 9 + 2 + 15 + 7 + 16 + 4 + 6 = 69
int main () { 37. 14020
int a = 4, b = 5, c = 6 Given that
f1(a, b) Seek time = 4ms
f2(&b, &c) 60s ® 10000 rotations
printf ("%d", c-a-b); 60s ® 10000 rotations
}
60
f2(int *a, int *b) = 6ms ¬ 1 rotation time
{ 10000
int c; 1
c = * a; c 5 \ Rotational Latency = ´ 6ms = 3ms
2
* a = b; [will change 'b' value of main to c value of
1 track ® 600 sectors
main]
6ms ¬ 600 sectors (1 rotation means 600 sectors or 1 track)
*b = c; [will change 'c' value of main to c value of f2]
} 6ms
34. (d) Condition coverage is also known as predicate coverage 1 sector ® = 0.01ms
600
in which each of the Boolean expression estimated to 2000 sector ® 2000 (0.01) = 20 ms
both true and false.Which is nothing but white-box \ Total time
testing, which tests internal structures of a function? needed to read the entire tile is = 2000 (4 + 3) + 20
Hence = 8000 + 6000 + 20
P matches with III. = 14020 ms
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

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


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

CPIold 1 99
= = 1- = = 0.99
CFold 100 100
=
CPI new
59. (a)
CFnew
60. 5
(where CF is clock frequency and CPI is cycles per 61. (b)
intruction. So, CPI/CF gives time per instruction)
40
4
= 2.5 = 3.2
1
2 30 20

Without pipelining an instruction was taking 4 cycles.


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

the CPI assuning no stalls.


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

40
E1 R12 E1
m n

30 20
R13
n
10 16 17
15

E3

8 4 35

a31 a32
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

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


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

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


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

15. (a) 3 – SAT Þ NPC problem requirements and may include a set of use cases that
Q1 £ p describe interactions the user will have with the
3 – SAT £ p software.
Q2 £ p £ p 22. (d)
Hence ® Q1 is in NP £ p
but Q2 is not given in NP f00(ABCDE)
Therefore, Q2 is in NP-Hard.
16. 6
f00(BCDEFGH) print(A)(4)
9

5 13 17 f00(CDEFGH) print(B)(3)

1 3 5 7 9 11 13 15 17

f00(DEFGH) print(C)(2)
17. (a)
18. 14 Average read access time = [(0.8) (5) + (0.2)(50)] ns.
= 4 + 10 = 14 ns
19. 12 Given, B = 106 bps f00((space)EFGH) print(D)(1)
L = 1000 bytes
if condition fails & returns controls
h = 25%
\ DCBA will be pointed
Tp = ?
23. (*) It might be "WRONG" question.
1 N = 2 Þ P1 P2 No. of resources = 6
In stop-and-wait, h =
1 + 2a 2 2
1 1
1 1
Þ = Þ 1 + 2a = 4 Each process can request atmost 2
4 1 + 2a
N = 3 Þ P1 P2 P3
3 2 2 2
2a = 3; a = N = 4 Þ P1 P2 P3 P4
2
1 1 1 1
3 1 1
L 8 ´ 10
Tx = = = 8ms Therefore, no option leads to dead lock.
B 106
24. (a) Basic COCOMO model takes the form
TP 3 Effort applied (E) = ab (kLoc) b b
=
TX 2 ; 2TP = 3T
Development time (D) = cb (E)db
2Tp = 24ms 25. (b) The correct order in which a server process must
Tp = 12ms invoke the function calls is bind, listen, accept and
20. (b) The consistency property ensures that the database recv. First three are used in connection establishment
remains in a consistent state before the (start of the phase and recv is used in data transfer phase.
transaction and after the transaction is over. Here sum 26. (c) Option (a) is false when CFG contains cycle
of the accounts x & y should remain same before & Option (b) is false as CFG can contain cycle
after execution of the given transactions which refers Option (d) is false as a single node can contain block
to the consistency of the sum. of statements.
21. (d) SRS is a description of a software system to be 27. 19 Let the number of vertices of a binary tree with ‘p’
developed, laying out functional & non-functional leaves be n then the tree has–
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

3 4 45 54. 6.1 60sec ® 15000 rotations


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

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


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

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


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

PAS 232
1 2 3 4 5 6 7 8 9 10 11 12 13 \ No.of frames = = 13 = 219 frames.
P.S 2
I O P P P W
I O - - P P P P P W So, it is given that each page table entry contains a
I - - O - - - - P W valid bit, a dirty bit, 3 permission bits. Þ 5 bits are
I - - O - - - - P W reserved.
SOLVED PAPER - 2015 2015-27

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


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

24 ´ 220 ´ 8
Þn= = 223 pages
24
Carry = 2.4 m sec
Length of the virtual address = 23+13=36 bits
A G2 G2 Sum = 4.8 m sec
H.A1 H.A2
56. (a) B

C Carry = 4.8 m sec

357 kB 491kB 468kB 201kB

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


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

380 c4 s3 c3 s2 c2 s1 c1 s0
\ Probability of a function f being one-one is
400
i.e., 0.95
Here sum and carry delay is same= 4.8 μ sec
So, Ttotal = (4 × 4.8) m sec
= 19.2 m sec
8880 Bytes MIU 63. (b) Since, every edge in a tree is bridge
58. (c)
1500B \ (a) is false
Since, every edge in a complete graph kn (n ³ 3) is not
a bridge Þ (c) is false
Let us consider the following graph G:
(1) (2) (3) (4) (5) (6) (7)
DL 0 - 1471 1472 - 2951 2952 - 4431 4432 - 5911 5912 - 7391 7392 - 8871 8872 - 8879
HL 28 20 20 20 20 20 20
8872
e
OFFSET = 1109
8

59. (d)
60. (a) This graph has a bridge i.e., edge ‘e’ and a cycle of
61. (a) As T1 & T3 are not yet committed they must be
length ‘3’
undone. The transactions which are after the latest
\ (d) is false
checkpoint must be redone. So T2 must be redone. No
Since, in a cycle every edge is not a bridge
need to redo the records which are before last
\ (b) is true
checkpoint, so T4 need not be redone.
62. 19.2 64. (c) Dijkstra shortest path algorithm find next node by
choosing minimum distance hence greedy approach.
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.

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


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

120

110

100

90

80

70

60

50

40

30

20

10

0
2000 2001 2002 2003 2004 2005 2006 2007

Export Import

9. Most experts feel that in spite of possessing all the technical III. He failed to make many of his good starts count.
skills required to be a batsman of the highest order, he is IV. Improving his technical skills will guarantee success.
unlikely to be so due to lack of requisite temperament. He (a) (III) and (IV) (b) (II) and (III)
was guilty of throwing away his wicket several times after (c) (I), (II), and (III) (d) (II) only
working hard to lay a strong foundation. His critics pointed 10. The head of a newly formed government desires to appoint
out that until he addressed this problem, success at the highest five of the six selected members P, Q, R, S, T, and U to
level will continue to elude him. portfolios of Home, Power, Defense, Telecom, and Finance.
Which of the statement (s) below is/are logically valid and U does not want any portfolio if S gets one of the five. R
can be inferred from the above passage? wants either Home or Finance or no portfolio. Q says that if
I. He was already a successful batsman at the highest S gets either Power or Telecom, then she must get the other
level. one. T insists on a portfolio if P get one.
II. He has to improve his temperament in order to become Which is the valid distribution of portfolios?
a great batsman. (a) P – Home, Q – Power, R – Defense,
S – Telecom, T – Finance
SOLVED PAPER - 2015 2015-31

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


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

be the set of all elements in T which are not in R. Which one QUESTION 36 TO 65 CARRY TWO MARKS EACH
of the following is true? 36. Consider the following C program:
(a) " X Î U (|X| = |X'|) # include<stdio.h>
(b) $ X Î U $ Y Î U (|X| = 2, |Y| = 5 and X Ç Y = 0) int main ( )
(c) " X Î U " Y Î U (|X| = 2, |Y| = 3 and X / Y = 0) {
(d) " X Î U " Y Î U (X/Y = Y'/X') int i, j, k = 0;
33. In a room there are only two types of people, namely Type 1 j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
and Type 2. Type 1 people always tell the truth and Type 2 k –= – –j;
people always lie. You give a fair coin to a person in that for (i = 0; i < 5: i++)
room, without knowing which type he is from and tell him to {
switch (i + k)
toss it and hide the result from you till you ask for it. Upon
{
asking, the person replies the following
case 1:
“The result of the toss is head if and only if I am telling the truth.”
case 2: printf (“\ n%d”, i+k);
Which of the following options is correct?
case 3: printf (“\n%d”, i+k);
(a) The result is head
default: printf (“\n%d”, i+k);
(b) The result is tail
}
(c) If the person is of Type 2, then the result is tail
}
(d) If the person is of Type 1, then the result is tail
return 0;
34. Consider a software project with the following information
}
domain characteristics for calculation of function point metric.
The number of time printf statement is executed is ______.
Number of external inputs (I) = 30
37. Suppose Xi for i = 1, 2, 3 are independent and identically
Number of external output (O) = 60
distributed random variables whose probability mass
Number of external inquiries (E) = 23
functions are Pr[Xi = 0] = Pr[Xi = 1] 1/2 for i = 1, 2, 3.
Number of files (F) = 08
Define another random variable Y = X1 X2 Å X3, where Å
Number of external interfaces (N) = 02
denotes XOR. Then Pr[Y = 0|X3 = 0] = ______.
It is given that the complexity weighting factors for I, O, E,
38. If the following system has non – trivial solution
F and N are 4, 5, 4, 10 and 7, respectively. It is also given that,
px +qy + rz = 0
out of fourteen value adjustment factors that influence the
qx + ry + pz = 0
development effort, four factors are not applicable, each of
rx + py +qz = 0
the other four factors have value 3, and each of the remaining
then which one of the following options is TRUE?
factors have value 4. The computed value of function point
(a) p – q +r = 0 or p = q = – r
metric is _______.
(b) p + q – r = 0 or p = – q = r
35. In a web server, ten WebPages are stored with the URLs of
(c) p + q +r = 0 or p = q = r
the form http://www.yourname.com/var.html; where, var is
(d) p – q +r = 0 or p = – q = – r
a different number from 1 to 10 for each Webpage. Suppose,
39. Language L1 is polynomial time reducible to language L2.
the client stores the Webpage with var = 1 (say W1) in local
Language L3 is polynomial time reducible to L2, which in
machine, edits and then tests. Rest of the WebPages remains
turn is polynomial time reducible to language L4. Which of
on the web server. W1 contains several relative URLs of the
the following is/are true?
form “var.html” referring to the other WebPages.
I. if L4 Î P, then L2 Î P
Which one of the following statements needs to be added in
II. if L1 Î P or L3 Î P, then L2 Î P
W1, so that all the relative URLs in W1 refer to the
III. L1 Î P, if and only if L3 Î P
appropriate WebPages on the web server?
IV. if L4 Î P, then L1 Î P and L3 Î P
(a) <a href: “http://www.yourname.com/”,
(a) II only (b) III only
href: “…var.html”>
(c) I and IV only (d) I only
(b) <base href: “http://www.yourname.com/ ”> 40. Consider the following partial Schedule S involving two
(c) <a href: “http://www.yourname.com/”> transactions T1 and T2. Only the read and the write
(d) <base href: “http://www.yourname.com/”, range operations have been shown. The read operation on data item
“…var.html”>
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

GENERAL APTITUDE QUESTIONS 2


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

(SACK) mechanism, combined with a selective repeat 23. (b) X be an eigen vector corresponding to eigen value l =1,
retransmission policy, can help to overcome these then
limitations. The receiving TCP sends back SACK AX = lX Þ (A - I) X = 0
packets to the sender informing the sender of data that
has been received. The sender can then retransmit é0 -1 2 ù é x ù
ê0 0 0 ú ê y ú
only the missing data segments. ê úê ú =0
III: TCP work as a message stream. This is FALSE êë1 2 0 úû êë z úû
statement.
In TCP, Data is read as a byte stream, no distinguishing Þ – y + 2z = 0 and x + 2y = 0
indications are transmitted to signal message (segment) x
boundaries. Þ y = 2z and =y
-2
x x y z
\ = y = 2z Þ = = a(say)
-2 -4 2 1
18. (b) 71
æ -4ö
ç 2÷
84 Þ X = ç ÷ a; a ¹ 0
65 è 1ø
\ Eigen vector are {a (– 4, 2, 1) |a ¹ 0, a Î R|}
24. (c)
69 83

1 2 3 4 10

67

19. (b) X # Y = X¢ + Y¢ S
S1. L.H.S. R.H.S.
= (P # Q) # R P # (Q # R)
(P # Q)¢ + R¢ P¢ + (Q # R)¢ P
= (P¢ + Q¢)¢ + R¢ P¢ + (Q¢ + R¢)¢
= PQ + R¢ P¢ + QR After *P = '0', array will become
PQ + R¢ ¹ P¢ + QR
Hence S1 is false
S2. Q # R = Q¢ + R¢ ...(I) 1 2 0 4
R # Q¢ = R¢ + Q¢ = Q¢ + R¢ ...(II)
I and II both are equal. Therefore, S2 is true
20. (c) X = sum of the cubes of first n natural numbers

n 2 (n + 1)2 S
= which is q(n4), O (n5) & W (n3).
4
21. (d) Number of processes which are in running processes and we are pointing string S which is 1204.
will be atmost n as there are n processors. Maximum
number of processes that will be in ready state is 6
independent of number of processors. 5 60 60 10
25. (c) 10 10 15 15 15 15
22. (a) 4 12 4 Þ E 201 F
10 5 + 60 6
cache cache
word word
TAG block TAG block
offset offset 8
offset offset
150 150 142
* 8 –
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

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


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

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


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

(i) FcFs
Process AT BT LT TAT
A 0 3 3 3
B 1 6 9 8
Program Y : C 4 4 13 9
Cyclomatic complexity = 10 – 8 + 2 = 4 D 6 2 15 9
Program Z : 29
= 7.25
4
Gantt chart
X
A B C D

0 3 9 13 15
(ii) SJF
Y
Process AT BT LT TAT
Total number of edges = X+Y+1 Þ 20 A 0 3 3 3
Total number of vertices = 15 B 1 6 9 8
Hence cyclomatic complexity = 20 – 15+2 = 7 C 4 4 15 11
42. 175 Transmission time for 5000 bits = Time for 500 bits to D 6 2 11 5
5000 27
travel = = 50 microseconds = 6.75
107 4
Gantt chart
So, after 50 microseconds the packet is completely
transmitted. But the packet must reach at the other and A B D C
this happens exactly after propagation delay which is 9
0 3 11 15
20 microseconds. So, the switch receives packet after
50 + 20 = 70 microseconds. B- 6 C-9 D -2
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)

In function main x will be updated as follows


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

01 1 1* 0 1* g(0) g(–2)

11 Total calls = 25
0 0 0 0
59. (a)
10 0 0 0 1* 60. (c) Since p – q ¹ q – p
\ (p, q) R (p, q)
Þ R is not reflective
There are three groups, and all the containing esential- Let (p, q) R (r, s) then p – s = q – r
1, so all are prime implicants as well as essential prime Þr–q=s–p
implicants also. Þ (r, s) R (p, q)
55. (c) Þ R is symmetric
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

HINTS & SOLUTIONS


1. (d) Since the ‘basic facilities’ are in plural, the use of ‘a 35. (d)
minimum is wrong. Instead, it should be ‘the minimum’. 36. (a) In order to express any unfulfilled wish, condition,
2. (b) The correct usage should be ‘deaf’ instead of ‘a deaf’, desire, supposition, etc, ‘were is used.
because the usage of ‘a’/‘an’ is not done before an 37. (b) Instead of ‘am’, ‘are’ is the correct option. Since ‘you’
adjective. and ‘are’ joined by the conjunction ‘and’ hence they
3. (a) ‘Little’ has to be replaced with ‘the little’ because ‘little make the plural and will take ‘are’ which as also plural.
means ‘almost none’ while ‘the little’ expresses ‘how 38. (c) The correct usage is ‘everyone comes forward’.
small an amount there is, that is possible. 39. (c) ‘and they are’ is the correct answer since the subject
4. (b) ‘Furniture’ is always used in singular. Hence, adding– s ‘Scotsmen’ is in plural hence the pronoun ‘they should
is not correct. be used’.
40. (c) ‘their’ has to be replaced with ‘its’.
5. (c) Since ‘poor’ is an adjective hence, cannot be used in
41. (a) ‘broke’ should be replaced with ‘had broken’.
this context. However, ‘the poor’ means ‘people who
42. (b) ‘Measles is’ should be used because it is in ‘singular’.
are poor’ so, here it should be ‘poor people’.
Secondly, with ‘either’, it should be ‘or’ and not ‘and’.
6. (a) Instead of ‘a man’, the correct usage should be ‘the 43. (a) Since the ‘athletes’ is in plural, it should also take the
man’ because ‘a man’ here expresses ‘some certain man’ plural form of ‘be’ i.e. ‘were’.
while it points out ‘the human being.’ 44. (b) The sentence has two errors. First, it should take ‘has’
7. (c) ‘Sign’ means a piece of paper, metal or wood with words instead of ‘have’ with ‘every man and woman of the
that gives information warnings or instructions. Hence, village’. Secondly, ‘everything about his prenatal
it should be ‘signature’. existence’ is correct and not ‘everything on.....’.
8. (a) ‘Cousin brother’ is wrong. It should be ‘cousin’ only. 45. (c) The correct structure of the sentence is – If Mahatma
9. (b) ‘One of’ is always followed by a plural noun but a Gandhi were alive, he would start weeping to see the
singular verb: One of the doors was open. present condition of India.
10. (b) The adjective ‘happy takes preposition ‘with, about, 46. (a) ‘A body of volunteers’ is in singular, hence it should
in, happy doing something....etc, hence ‘happy at’ is have ‘has been organized’ and not ‘have been.....’.
wrong and it should be ‘happy about’. 47. (c) The sentence (a) has the error – most of the news ....
11. (e) have been communicated while it should be ‘has been
12. (a) Here ‘bathe’ is a verb, hence it should be replaced with ....’ sentence (b) should be structured as – ‘Not only
a noun i.e. ‘bath’. the doctor but also the nurses .... are very kind’ because
13. (a) The correct usage should be ‘The edge of this blade’, the nurses is in plural and it should agree with the verb
because with an inanimate noun, we use the ‘of + noun ‘be’.
form. 48. (c) Sentence (a) has the error of preposition. With the noun
The cover of the book (rather than the book’s cover). ‘amendment’ the preposition ‘to’ is used and not ‘on’.
In sentence (b) instead of adjective ‘pitiable’, the noun
14. (e) 15. (a) 16. (e)
‘pity;’ is to take place because when you are
17. (b) disappointed about something then you say, “It is a
18. (c) It should be ‘an indecent’ and not ‘an indecently’ pity’ .... ‘It is pity’ .... etc.
because the sentence demands an adjective not an 49. (c) In sentence (a) the subject ‘an ordinary man’ is in
adverb. singular hence, it should take singular verb ‘does’ and
19. (d) .... ‘the number of books is fewer’ is the correct answer. not ‘do’. In sentence (b) the noun ‘observations’ is in
20. (d) ‘He came the second time’ is the correct usage. plurals, so it should take the auxiliary verb ‘have’ and
21. (c) The correct usage is ‘of the three...... not ‘has’.
22. (d) ‘at regular intervals’ is the right option. 50. (d) Both sentences are correct. In sentence (a) Seema’ the
23. (c) Since ‘quickly’ is an adverb, it should be replaced with third person / singular number agrees with the auxiliary
an adjective. i.e. ‘quick’. verb ‘has’ and in sentence (b) the expressions beginning
24. (c) with ‘None of ....’ can take both singular and plural
25. (a) ‘It being a rainy day’ is the correct replacement. ‘auxiliaries’.
26. (b) 27. (a) 28. (b) · None of the newspapers have arrived yet
(or..... has arrived....)
29. (c) 30. (c) 31. (a)
· None of my friends phones me any more
32. (d) 33. (b) (or.... phone me....).
34. (d) ‘of the same age’ is the correct expression. In choice 51. (d)
(a) it is in objective case ‘me’ which is not appropriate, 52. (c) Since “European” starts with constant sound, it
choice (b) ‘equally old’ is also not suitable, nor is should be “a European”.
‘equally older’. 53. (d) lost consciousness.
2 Sentence Completion
WORD USAGE
FILL IN THE BLANKS OR SENTENCE COMPLETION

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

HINTS & SOLUTIONS


1. (a) The word ‘sceptical’ means suspicious or doubtful. 13. (b) Reliable means something that can be trusted,
2. (a) The word ‘inflict’ means burden someone with or inadequate insufficient, novel is of a new kind and
impose. specious means false or misleading. According to the
sentence the expert is able to trace the descent of fossil,
3. (d) The word ‘inherit’ means become heir to or take over.
so, it cannot seem reliable, what is would seem will be
4. (b) The word ‘probably’ means likely (very/most). a word opposite to sufficient or reliable and that is
5. (a) Vague notion is a right choice. Imagination is in itself inadequate.
vague (unclear). While expressions cannot be vague. 14. (c) Since, there is a but between the two parts of the
Theory is out of place for the context. Thoughts can sentence, the passive words should be antonyms. (a)
be vague or unclear or unstable. and (d), thus, get eliminated never - also do not fit the
6. (c) Remorse is an emotion/action/feeling after the crime is sense of the sentence properly thus, not - always are
done. Hatred is for the other people who saw/hear/ the most suitable fillers for the given sentence.
gone through crime but certainly not for the prisoner. 15. (c) An analysis must be careful, it may or may not be
Crime is done in anger and a cause. Obstinacy is detailed and final. It certainly should bot be random,
stubbornness. Only emotion that suits the context is thus, (a) is eliminated of the remaining careful is the
Remorse. most appropriate choice for this sentence.
7. (c) If it would have been 'security' then it would have 16. (c) Enthralling is something that will excite, accomplished
been 'provided' in the statement not 'subjected'. is skilled and so is masterful, pedestrian means
Exercise does not fit. Violation (to breech) is also out ordinary. The sentence says that everyone was amazed
of place. Use of 'physical' in statement indicates that the speaker was an ordinary speaker and not a
'violence'. It fits best in the blank. skilled speaker.
8. (c) War is a negative word and it is synonym with mass 17. (d) Dismantle (to disassemble or pull down; take apart) is
destruction, death h ence certainly has grim the right usage in the context of the passage.
consequences. Happy, Pleasing, exciting all have 18. (d) 'Professionals focus their energies' is the best choice.
positive sense; so can not be linked with war. Further an image is portrayed.
9. (a) Eminent means very respected or famous in one’s 19. (b) The only word which goes well with straightforward
profession or field, petulant means peevish or irritable, and honest is up-front. Durable is used for a thing not
pathological refers to disease and amiable means a person.
friendly. 20. (c) 'to listen attentively and sensitively' and 'trust you
10. (a) Mandatory means compulsory, pertinent means with their feelings' is the right usage.
relevant and sagacious is showing wisdom, while 21. (d) In the context of the text, continuing education seems
constructive means useful and positive. to be the best usage. As the world is changing very
11. (c) Equivocal means ambiguous or vague, pervasive means fast so one has to continuously upgrade himself as
something to be found everywhere, inseparable are per the new requirements.
things that cannot be separated from each other and 22. (a) There cannot be a subject in the first part of the
autonomous means independent is followed by a ‘but’ sentence as the same subject is given on the second
so the noun or adjective that follows should be part so (c) and (d) are eliminated. To study is the
opposite in meaning to Independent. Thus, inseparable infinitive verb which will not be used here, because
is the right answer. it suggests the action which is the affect and not the
12. (c) The sense of sentence says that Europeans came to cause. e.g. ‘To gain something you have to lose
India for A but after this they did B. So, A is the first something else’.
choice. Now, of the given words, we can choose the By studying is the right answer because this gives
word synonymous with first, basically suggests the the cause for the verb in the latter part of the
chief ground reason, fundamentally means essentially, sentence.
primarily means apparently. Primarily, therefore, is the 23. (c) Modals such as must or should cannot be used with
most apt answer for this sentence. ‘hope’.
EBD_7203
S1-22 GENERAL APTITUDE FOR GATE
24. (d) ‘because’ cannot be used as the conjunction in this 33. (c) The best option for the first blank is obtrudes which
sentence because for the sentence to be complete it means to make something noticed especially in a way
should be followed by an ‘of’, i.e., because of their, that is not wanted. Also offends is the right word for
since this is not the option ‘of their’ is the most the second blank which is clear from the meaning of
appropriate use. the word obtrude (making noticeable in an unwanted
25. (a) The confusion is between (a) & (b), but ‘want’ is way).
usually followed by the to + verb form and not verb 34. (d) Withholding rewards will encourage negative
+ ing form. behaviour instead of fostering (bringing about)
26. (a) Among the given options, (a) seems to be most genuine interest.
appropriate in the context of the sentence. 35. (b) Expert professionals are having to train, and students
27. (d) From the second part of the sentence it is clear that the supplant (replace) teachers.
author is taking about unequal benefits, so only 36. (d) The touts persuade the people to sell illegally thereby
equally or uniformally suit the first blank. Clearly making a profit, not caring about either the poor or the
percolate (which means filter) is the right word for the trees.
second blank. 37. (d) Obtrude means forcing on someone, thus, when
28. (c) Exhausted is the correct word for the second blank as punctuation obtrudes it is because it offends.
reserves are exhausted and not completed or 38. (b) The need of lesser fiscal policy to stimulate demand is
augmented or destroyed. Further depleted fills the first greater than the need to control budget deficit.
blank correctly - ‘as the words supply of coal is being 39. (c) The pair of words guide and facing fit right in, the rest
depleted.’ do not make sense.
29. (c) The use of the word over-gazed clearly tells that the 40. (b) The most appropriate word for the second blank would
native vegetation is under threat, which means the be detrimental as the use of the word insisted indicates
goats must have thrived or propagated. Hence (c) is that they should be a negative word in the second
the correct option. blank. Further as the sentence shows a contrast so
30. (d) Salutary, which means having a good effect on although is a better choice for the first blank.
somebody, though often seeming unpleasant, is the 41. (b)
appropriate choice for the first blank. Further reiterated 42. (a)
rightly fills the second blank. 43. (b) Tone of the sentence clearly indicates a word that is
31. (b) In the context of the sentence, denouncing (criticizing similar to understated is needed for the blank.
somebody that you think is wrong) is the right word Alternatively, word should be antonym of strong (fail
for the first blank. Also debunking (showing that an to make strong impression). Therefore, best choice is
idea/ a belief is false) is the right choice for the second restrained which means controlled/reserved/timid.
blank. Ridiculing and moking are not the right words 44. (c) Contemplate is a transitive verb and hence is followed
as they mean unkind comments that make fun of by a gerund. Hence the correct usage of contemplate
somebody. Castigating (criticizing somebody severely) is verb + ing form.
can also be the right fit in the first blank but 45. (d)
strengthening doesn’t fit in the second blank.
46. (b)
32. (b) The correct choice for the first blank is pessimistic and 47. (a)
for the second blank is confusion. The use of the word 48. (c) Mediocre means Anerge.
pessimistic in the first blank means that the analysis of 49. (b)
the coach’s report was not pessimistic and can’t be 50. (c) had known, could have
clearly understood (hence creating a situation of
confusion). Sanguinary (which means involving killing u u u
and blood) is too harsh a word to be used in the first
blank. Malicious (which means feeling of hatred for
somebody) cannot be used with analysis of a report.
3 Synonyms and Antonyms
This is the other very important area of the vocabulary section. STRATEGY 2
This section tests widely and exhaustively one’s knowledge of If you cannot find a correct antonym in the given option think of
the language and word power, but goes beyond that to test your the antonyms you know of and subsequently check if there is
ability to remember words with similar meanings or opposite any word in the given options which is synonymous to the
meanings. Or, alternately, to discover the similarity or proximity antonyms in your mind. For example
between the meaning of the given word with one of those in the Industrious
options. (a) stupid (b) harsh (c) indolent (d) complex
These exercises can get confusing sometimes because more than If you don’t know any of the words given as options think of
one option may appear as the right answer or none of them may antonyms you could think of, like lazy, idle. Now think of
look like the right answer. For such questions a student may synonyms of lazy and you will know indolent is a synonym of
consider the following strategies. lazy. So it will be the antonym to industrious. Formula ®
STRATEGY 1 SYNONYM of ANTONYM is another ANTONYM.
If you do not know the meaning of the given word, think of a STRATEGY 3
context in which you might have used it, that may help you to Look at the part of speech of the given verb. A word may exist in
figure out the meaning, for example, in the question find the word various parts of speech. For example precipitate exists as a verb
nearest in meaning to which means send rapidly into a certain state and also as a noun,
Magnify precipitate, which means a substance deposited from a solution.
(a) Forgive (b) diminish (c) swell (d) extract Polish
Now if you do not know what magnify means think of a magnifying (a) ruthlessness (b) honesty (c) indolence (d) gaucheness
glass and what it does. It expands or makes a thing look bigger. Now is this the verb polish or noun polish. Since all options are
So the right answer will be (c). nouns, this cannot be the verb polish related to shoes but noun
polish which means culture and sophistication and the antonym
to this would be gaucheness.
EBD_7203
S1-24 GENERAL APTITUDE FOR GATE

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

HINTS & SOLUTIONS


SYNONYMS 20. (c) Once I fall ill, it takes me long to recuperate. That is, I
1. (b) counsel also means ‘legal adviser’. take a long time to recover my health or strength after
2. (c) abject means helpless, miserable, despicable situation, I have been ill. Convalesce is another synonym of
obstruct means to hinder, abstract is the literal opposite recuperate. Convalescence is the period or process of
of concrete, real. becoming healthy and well again after an illness or
3. (d) sight means scene, sue means to file a Suit. operation.
4. (c) cemetery means graveyards, hierarchy means a system 21. (b) When a cyclone affects an area, the people are deprived
of society in which people are graded into different of their belongings. You then give them money, clothes,
classes according to certain norms, harmony is when food etc. Such gifts to the poor and needy are called
many things work together in the same mode. alms. Since they are given out of charity (kindness
and tolerance), these gifts are also known as charity.
5. (d) illicit means not sanctioned by law, elicit means to draw
a response with difficulty, illegitimate means illegal/ 22. (b) You are familiar with the word tenuous. Attenuate also
unlawful comes from the same Latin root tenuis (= thin). If you
attenuate something, you make it slender or thin; you
6. (b) imperial means of an empire or its rulers, adamant means
reduce it in force or value.
firmly or stubbornly, determinedly.
23. (a) Mohan and Yadu were friends. One day, however,
7. (c) judicious means having good sense, momentous
Mohan went to a cricket match alone. There was only
means most important, pragmatic means practical,
one ticket available and he did not want to miss the
treating in a sensible and realistic way.
match for the sake of his friend. When Yadu came to
8. (c) Verbose means using or containing more words than
know of this, he felt aggrieved. Out of vindictiveness,
are needed, ambiguous means having more than one
Yadu bought only one ticket for the next match and
meaning.
left Mohan alone. In other words, Yadu took a revenge
9. (c) fickle means unstable, often changing, not constant,
on Mohan.
not faithful, Insipid means tasteless
24. (d) If you are discomfited by something, it causes you to
10. (d) Vigil
feel slightly embarrassed or confused. In other words,
11. (a) Affinity it, frustrates you.
12. (b) Fatigued 25. (b) Wrath is extreme anger.
13. (c) heritage 26. (c) If you abstain from something, you deliberately do
14. (c) credulous not do it. Abstinence, however, is a particular kind of
15. (c) Onslaught means ‘attack’; arrogant means ‘full of abstaining —that from alcoholic drink, sex etc, often
pride’ for health or religious reasons. If you abstain from
16. (c) Obvious means ‘clear’, ‘atrocious’ means ‘cruel’, drinking, you do not get drunk. Abstinence does not
ferocious means full of anger. refer to “drink” only,
17. (b) Classical music today is in need of patronage. Earlier, 27. (c) An erudite person is scholarly. He or she is full of learning.
its patrons were the maharajas. Classical musicians Now, where does a learned person get his or her learning
were honoured in the royal courts. They were given all from? From the world of education or books. In other
the support necessary to let their art flourish. words, the person has an academic orientation.
18. (d) How did you traverse the river? That is, how did you 28. (d) A taciturn person is not dumb. A dumb person can’t
go from one side of it to the other? In other words, speak. A taciturn person can speak but does not want
how did you cross it? If you traverse an area of land or to. In other words, he maintains a reserve.
water, you go across it. Traverse is a literary word. 29. (c) As an adjective, animate simply means “having life”.
19. (b) Raja Ram Mohan Roy was the founder of Brahmo Samaj. For example: Plants and animals are animate objects.
In other words, he established it. (5) is thus rejected because boisterous means “lively,
cheerful”. Now, as a verb: If you animate something,
EBD_7203
S1-30 GENERAL APTITUDE FOR GATE
you make it lively or more cheerful. Thus you put 40. (a) In philosophy, dialectics is a method of reasoning and
energy into it. In other words, you energise it. Note: reaching conclusions by considering theories and
Boisterous is a synonym of the adjective animated. ideas together with ones that contradict them. Such
30. (a) If someone is niggardly, he shows lack of generosity. contradictions lead to argumentation and often
Thus generous (2) would be its antonym. But we are degenerate into arguments.
looking for a synonym. None of the words is a fit 41. (d) When a seed germinates, it puts forth shoots. In other
synonym. In such cases we go for the word closest in words, it sprouts.
meaning. Both penurious (very poor) and niggardly 42. (c) Efficacy is effectiveness Efficiency is the ability to do
imply a lack of money, though in different senses. a thing successfully. Your efficacy is judged by how
31. (d) One who is blithe is carefree and cheerful. efficient you are.
32. (d) You are captivated by something attractive; It 43. (a) John D Rockefeller was an oil magnate. Onassis was a
fascinates you. shipping tycoon. Both Rockefeller and Onassis were
big businessmen, their spheres being oil (petroleum)
33. (d) I have lost my reputation and nothing can redeem it.
and shipping respectively. Both magnate and tycoon
That is, much though I may try, no good action on my
refer to businessmen who have made it big, their
part can bring my lost reputation back. In other words,
success making them rich and powerful.
I cannot recover my reputation.
44. (d) A facet of something is a single part or aspect of it.
34. (d) That which is bland is rather dull and unexciting.
45. (a) Violence in films has a pernicious influence on our
Doordarshan is infamous for its bland presentations
children. That is, the influence is harmful. Similarly, a
of sports events. Similarly, food can be bland. That is,
deadly situation has harmful consequences. Is heinous
it has very little flavour. In other words, it is tasteless.
a synonym of pernicious? No. Heinous crimes are
35. (a) A visionary is one who has vision for the future. He extremely evil and horrible. When one calls a crime
comes up with strong, original ideas. He can foresee heinous, one is rather disgusted with its horror than
the changes to come and shapes the future, bringing concerned about its harmfulness.
about an improvement. All visionary ideas are dreams 46. (c) If you persuade me to do something, you try to
at one stage. But all dreams do not mature. Most of convince me that it should be done.
them remain pipedreams. Only those few that are 47. (d) When you fortify a place, you make it as if it were a
backed up by the necessary, practical considerations fort. A fort has a wall or ditch round it and is not easy
turn into visionary ideas. to attack. Thus, if you fortify something, you
36. (b) When a law is revoked, it stands cancelled. We can strengthen it.
also say that the law has been repealed. 48. (d) There has been a phenomenal increase in the number
37. (d) When an army operation was launched to bomb the of dish antennas in recent years. That is, the rise in
terrorists, they took the army chief hostage in reprisal. number is much, much more than ordinarily expected.
That is, they mounted pressure on the army because The increase is thus extraordinary — “more than
the army mounted pressure on them. In other words, ordinary”.
they retaliated. 49. (b) A paradigm is a model for something which explains it
38. (b) If you are fastidious, you pay great attention to details. or shows how it can be produced.
You like everything to be very neat, accurate, and 50. (c) Government servants are not allowed to receive money
orderly. A dainty object is small, delicate and pretty. from any other job. Suppose an income-tax officer
The nearness of meaning lies in that fastidious persons desired to edit this book. He would then have to be the
like things to be dainty. honorary editor of this book. That is, he cannot receive
39. (b) If A is the cause of B, you attribute B to A. usually; if B any payment as wages for editing the book. An
is something bad (blame, charge etc.), we use impute honorary job is thus unpaid for.
instead of attribute. Sample the following : When Sri 51. (d) Your faculties are your physical and mental abilities.
Lanka beat Pakistan, the Sri Lankans attributed their We have all been endowed with the faculty of
success to their batsmen. The Pakistanis imputed the imagination. Most of us, however, kill it through an
exercise of constant neglect.
blame of their defeat to their sloppy fielding.
SYNONYMS AND ANTONYMS S1-31
52. (b) If you visualise something, you imagine what it is like 74. (c) Concert means together.
by forming a mental picture of it. You may visualise 75. (a) Mitigate means to heal, to reduce, to release someone
future events as well, your wedding for example. You of his sufferings.
thus foresee your wedding. 76. (c) evasive means careless, stupid means foolish.
53. (a) From Akbar to Aurangzeb, every Mughal emperor went 77. (c) Resolved is determined.
on annexing one kingdom or another to what they
78. (a) Apposite is suitable, pertinent, relevant.
inherited. In other words, each of them added to his
father’s empire. 79. (d) Sturdy means strong, brisk means energetic. Buoyant
is cheerful; not easily depressed.
54. (d) A menage is a group of people living together in one
house. In other words, a household. 80. (d) Infirm is feeble or weak in body or health.
55. (d) If you are in a dilemma, you do not know what to do. In 81. (d)
other words, you are in confusion. 82. (a) Inexplicable means not explicable; that cannot be
56. (b) A rigmarole is a lengthy and complicated procedure explained, understood, or accounted for. So the best
which you do not like. synonyms here is incomprehensible.
57. (d) If you ascend, you go up. If you descend, you go 83. (a)
down. If you transcend, you go across. In other words, 84. (b) Nadir means the lowest or most unsuccessful point in
you cross. a situation.
58. (d) An imperative is something that is extremely important 85. (a) eradicate - destroy utterly
and must be done. In other words, it is a necessity. distrot - misrepresent
saturate - soak completely
Revision of obsolete laws has become an imperative
utilize - use
for the 50-year-old country. 86. (c)
59. (b) Certain categories of companies have been exempted ANTONYMS
from paying tax. That is, they do not have to shoulder 1. (b) Exonerate means declared free from blame, to implicate
the burden of tax-paying. In other words, their burden means to show that someone is involved in something
has been relieved. especially a crime, to appease means to pacify, to adore
60. (c) If something is firm, it is strong enough to maintain its means to love deeply and respect highly.
balance. Infirmity therefore suggests weakness. 2. (d) Fascinating means charming, fanaticism means
61 (d) madness, especially in religious or political matters,
62. (d) Filth means dirt, Lewd means characterless. A chaste indolence means laziness.
person does not have sex with anyone or has it only 3. (d) Modest means humble, awkward means clumsy,
with his or her spouse. celebrated means distinguished.
63. (a) Inheritant means qualities taken from forefathers. 4. (b) Credulity
64. (a) Angularity 5. (a) Roost
65. (d) Peak. Summit is the highest point. 6. (d) offend means not to show proper respect or make
66. (d) Alienate means to withdraw. someone angry, so the opposite will be respect.
67. (a) Mendacious is something untruthful 7. (c) Indict means to charge someone with a crime or
68. (b) Ostracised is shutout from the society. something wrong. Accuse also means the same, acquit
69. (a) Spurions is False means to free of charge.

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.

3. OBJECT : ACTION 9. WORKER : ARTICLE CREATED


Gun : Fire ® you fire a gun Carpenter : furniture ® carpenter makes wooden furniture
Violin : play ® you play a violin compose : music ® a composer composes or creates music
In this, one term is an object and the other action undertaken In this relation, the first word is the doer and the second is
with the help of that object. the professional work done by the first.
EBD_7203
S1-36 GENERAL APTITUDE FOR GATE
10. SYMBOL : QUALITY TIP 2
Olive leaf : Peace ® an olive leaf is a symbol of peace.
Always be careful about apparent and easy similarity.
Red : passion ® the colour red symbolises passion.
These are only to deceive the student as you would be
In this relation the first word is a symbol, and the second is
attracted by these options. Always confirm all the options
the meaning represented by the symbol.
and be highly careful while considering an obvious
11. CLASS : MEMBER answer.
mammal : man ® man belongs to the class of mammals.
Doggerel : Poem ® Doggerel is a class of poem which is e.g. STUTTER : SPEECH
bad in quality. ® Blare : hearing
In this relation the first word is a member belonging to the ® Aroma : smelling
class denoted by the second word. ® Astigmatism : sight
® Novocaine : Touch
12. ACTION : SIGNIFICANCE
Stutter is a defect of speech, so the relation between the
Blush : embarrassement ® if one blushes, that signifies
two is that of defect. But Blare and hearing are closely related
that the person is embarrased.
since blare means a harsh sound. This may attract the
Spasm : pain ® a spasm indicates that the person is in pain
student, but this is not a relation of defect. This relation is
In this relation the first word is an action and the second is
in the third option, astigmatism is a defect of sight. So always
what that action signifies.
avoid giving into the temptation of obviously correct
Although most of the questions asked in a competitive exam can answers.
be solved with the help of the given relationships for subtle
questions a student should apply reasoning to figure out the TIP 3
relation between the given words. Following are certain tips that Sometimes a word has two meanings, while what may
would help a student to attempt analogy questions. first come to your mind will be the more frequent use of
that word, if you cannot find a logical relation between
TIP 1
the two words, go beyond the obvious meaning and link
The first and foremost step while attempting an analogy the word with the other meaning of the second word.
question should be to DEFINE THE RELATIONSHIP. To
avoid any errors first define the relationship on paper ANNEX : BUILDING
or in your mind before searching for options. Once you ® Postscript : letter
have defined the relationship analyse the given pairs ® Lyric : song
in the light of the relationship. ® paragraph : text
1 ANXIOUS : REASSURANCE ® hill : mountain
® resentful : gratitude The common meaning of annex is to add, append or take
® perplexed : classification possession. But with this meaning a logical relationship
® insured : imagination cannot be built with building. So one must refer to the other
® vociferous : suppression meaning of annex, which is a supplementary building.
First, the relationship can be defined as ‘need’ i.e, an anxious Similarly the relation of supplement also exists between
person needs reassurance and then you can check the given postscript and letter.
pairs to find out that ‘a perplex person needs classification’.
Thus this will be the right analogy MAROON : SAILOR
® Red : Ship
2. SIMMER : BOIL ® Crimson : flower
® Cook : Fry
® Stranded : Tourist
® Chill : Freeze
® Colour : Dress
® Roast : Stew Maroon also has two meanings the colour ‘maroon’ and the
® Slice : Cut
verb maroon which means being left alone or abandoned.
Now, establish the relation between the two given words. It
Obviously the second meaning will make a logical relation
is that of degree. Simmer is the lower degree of boil. Just as with sailor, a sailor is marooned just as a tourist is stranded.
chill is the lower degree of freeze.
VERBAL ANALOGIES/ CONTEXUAL USAGE S1-37

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

HINTS & SOLUTIONS


ANALOGIES degree. Similarly testimony means a statement under
1. (d) Relation - Cause - effect; oath. The difference here is also that of degree. While
Bacteria causes illness, as fire causes explosion, other pairs either differ in meaning or manner but not
laceration means tearing of flesh and it may be in degree.
caused by a knife, but that is only an accidental effect 14. (b) The relation between the two words is that of
and not a permanent cause. chronology, prehistory came before medieval times just
2. (a) Relation - different kinds of writing forms; stanza and as present comes before future. Even though Akbar
chapter are also different kin ds of styles of came before British and Shakespeare before Tennyson
composition different from each other, clause is a part these are people while the given pair of words are
of a sentence and some art can be fiction. divisions of time.
3. (c) Relation - degree of intensity; just as gulp is higher 15. (d) The relation between the pair is that of degree.
in degree of intensity to sip, push is higher in degree Stentorian means very loud just as resplendent means
of intensity to touch. very bright. Other pair do not have a relationship of
4. (d) Relation - Property - effect; i.e. ‘something which is degree.
fragile cracks,’ similarly something that is pliable 16. (a) The relation between the two words is that of
bends. Cemetery is burial ground, irreducible is what component and whole, like a building is made of many
cannot be reduced. storeys, a book is made of many chapters, a sentence
5. (a) Relation - Collection - Unit is although not made of many adjectives, it also has
Collection of flowers is a bouquet, just as beads collect other different components, same for tree-stem and
to form a necklace. elephant-tusk.
6. (c) Relation - Preceding event - succeeding event; as 17. (d) The relation between the two words is that of degree.
Rehearsal precedes performance, engagement Alleviate means the same as ease but higher in degree,
precedes marriage, appetite means desire, it may or just as interrogate is higher in degree to question.
may not be succeeded by satisfaction and these Repudiate means to reject or disown and allocate
cannot be counted as events, whereas the given means to assign. No other pair has a similar relationship.
words are events not feelings, applause means 18. (b) The relation between the two words is synonyms.
appreciation. Secret and Clandestine are synonyms just as covert
7. (d) Relation - Part - Whole; room is an essential unit of and stealthy are synonyms, furtive means stealthy,
a housing entity, cockpit is also an essential unit of overt means obvious.
a plane, cabin is not an exclusive unit of ship similarly 19. (c) Relation between the words is of antonym. Limpid
wheel is not an exclusive unit of car. means clear and murky means dark, unclear. Dazed
8. (b) Relation effect : Cause; means stunned or bewildered, clouded means unclear
Just as sorrow is caused by death happiness is or confused. Obscure means indirect, indistinct and
caused by birth. vague means not clear, nebulous means indistinct.
9. (b) Relation - binding thing - binded subject; Gloomy and bright are also antonyms.
Like a prisoner is chained with handcuffs, dog is 20. (c) Drama is done for audience and the two are intrinsically
chained by a leash. connected just as Art is for the gaze of the critic. Brawl
10. (d) Relation - surrounded object - surroundings; an island is a fight.
is a piece of land surrounded by water on all sides 21. (a) The given words are two different states of matter —
as an oasis is surrounded by desert on all sides. Liquid and gas. Serum and fume also are in different
11. (c) Relation - object/events - figurehead; as a director states of matter like liquid and gas. Arid means dry and
is the head who takes care of proper execution of a humid means moist.
drama, an editor is the responsible person to look 22. (b) Relation between the two words is of antonyms.
after publishing of a magazine. Sceptic is a person with doubt and pious is the person
12. (a) Relation - emotion - person with opposite emotion; with faith. Atheist is a person who does not believe in
for all other three options, the feelings in both the god, hence there is no doubt. Iconoclast is a person
words means the same, optimist means hopeful, who attacks cherished belief.
diligence means working carefully, sage is a wise, holy 23. (b) Fission means breaking while fusion is combining.
man. Separation and togetherness also have the same
13. (a) Perjury means to swear falsely under oath. The relation to each other. Intrusion means to come
relationship between the two words therefore is of uninvited and extrusion is to squeeze out.
EBD_7203
S1-42 GENERAL APTITUDE FOR GATE
24. (b) Reaction is in response to an action just as a defence be a positive quality for technology as in the given
is in response to an assail. All other pairs have a relation. Sturdy is a positive quality of physique. Silk
different relationship. is a noun and not an adjective. Noble is not an
25. (b) Dulcet means sounding sweet, roucous means loud adjective used with intellect.
and harsh, the two words are thus antonyms. Palliative 40. (d) Relation - Prey - Predator;
means to excuse and exacerbate means to irritate or Plant is attacked by a parasite just as sailors are
make worse, crazy and sane are antonyms. attacked by pirates. Transient is an adjective not a
26. (a) Malapropism means comical confusion of words, noun as the first word of given pair, it means
similarly anachronism is related to time, ellipsis is a something that does not last forever.
kind of punctuation. Catechism is a series of questions. 41. (b) Relation - Person - Workplace;
27. (d) Posterior means the rear and anterior means the front. Curator is the person who takes care of the museum.
28. (a) Relation is of component to whole. Words together 42. (b) Relation - person - quality;
constitute a dictionary. Letter also constitute an Valour means bravery and cynic is a person who
alphabet just as soldiers form a platoon, but in these doubts constantly the motives and intensions of
pairs the relation is inverted whole : component. people around him .
43. (d) Relation - thing - place where it is kept;
29. (c) The given pair are homophones, i.e., they have the
Vault is a kind of locker where cash is placed. Account
same sound, same as rain & reign.
is not really a place in which money is put.
30. (d) Doggerel is written by a poet just as symphony is
44. (d) Relation - thing - its characteristic quality; as wool
made by a composer but Doggerel is a bad poem just
gives warmth, the spring has elasticity, it is the
as pulp fiction is bad writing by a novelist. characteristic defining quality of spring.
31. (d) Relation - worker - place of working; a designer does 45. (b) Relation - symbol - quality symbolised; as torch
not work in a design but works on a design. suggests liberty, scale is a symbol of justice.
32. (b) Relation - person - place of living; 46. (a) Relation - nurturing place - nurtured subject.
hermit and monks are synonymous words which 47. (c) Relation - milder action - high intensity action; just
mean a holy man. Coop is the place where a hen lives as whisper is lower in intensity to speak, brush is
and kennel is a dog’s house. lower in intensity to touch. Brush means to touch
33. (d) Relation - Synonyms; lightly in passing.
Vestment means the dress worn by a priest while 48. (c) Relation - collector - collected things;
solemn means serious, all other pairs are synonyms. Philatelist is the person who collects stamps and
34. (d) Relation - horns - animal; mane means long hair on numismatist is one who collects coins. Astrologer
the neck of the lion, hoofs means a part of the foot is the person who studies the movements of stars and
of a horse. planets.
35. (d) Relation - Place of nurture - nurtured object; 49. (c) Relation - arbiter - situation;
incubator is where the infants are kept to save their As an umpire is in a match, the moderator is in a
lives. Though wine is kept in coolers to cool it, it is debate, he acts as a judge of whether the rules were
not the place where it is nurtured or saved from any followed or not.
danger, hive is the house of the bee but not a 50. (b) Relation - object - function;
nurturing place, where it is kept specifically to be Pendant is a locket worn in a neck, pry means to force
protected and nurtured. Greenhouse is where young out or open by leverage, travel is a small spade like
plants are kept to help them grow and prevent their tool.
death. 51. (d) Relation - offspring - adult;
36. (c) Relation - Opposite action - Condition; Ruffle means Aster is a kind of plant.
to confuse or mix, composure is a state of calmness 52. (d)
and control. Flounce means to go in an impatient CONTEXUAL USAGE
irritated manner, turmoil means state of confusion.
1 (c) 11 (d) 21 (a) 31 (a)
37. (a) Relation - State - Opposite quality; indigents means
2 (a) 12 (c) 22 (c) 32 (c)
needy or poor and wealth means money or other
3 (b) 13 (c) 23 (d) 33 (c)
assets. Emaciated means extremely thin, weak
4 (a) 14 (c) 24 (a) 34 (c)
nourishment is fulfilment. Content means satisfied
5 (c) 15 (a) 25 (b) 35 (b)
and happy and smug means self satisfied, or self
6 (d) 16 (a) 26 (c) 36 (d)
pleased, same as complacency.
7 (c) 17 (c) 27 (a) 37 (c)
38. (b) Relation - similar meaning;
8 (d) 18 (b) 28 (c) 38 (a)
Rout means a terrible defeat, grief means sorrow,
9 (d) 19 (c) 29 (c) 39 (c)
triumph means success.
10 (b) 20 (d) 30 (b) 40 (b)
39. (b) Relation - Noun - its quality;
41. (a)
Inept means unsuitable or unskillful, which will not
u u u
5 Critical Reasoning and
Verbal Deduction
Critical Reasoning (CR) is ability to reason clearly to evaluate Strategy to Crack Critical Reasoning Questions
and judge arguments. You are using this skill a lot during your This strategy is not the easiest way to do CR (the easiest would
everyday life while reading newspapers or watching movies. When be read-and-answer), but it lets you get the most questions right
you think that the movie is pushing the limit of the Reasonable or spending less time per correct answer.
1. Read the questions first; this is needed so that you would
the news sounds less reasonable than the movie that was pushing
know what to look for and what to do: find an assumption,
the limit, you are using your Critical Reasoning skills to produce
strengthen/weaken, infer something or else; do not worry
these conclusions. The argument you meet can be anything from about the details in the question, read for keywords, such
a classical argument to an advertisement or a dialog. Critical as strengthen, deny, or explain. [Use symbols for
Reasoning questions will ask you to manipulate the argument to convenience, e.g. + for strengthen or – for weaken].
weaken/strengthen it, find the conclusion, assumption, 2. Read the passage very attentively because in contrast to
explanation, do an inference or supplement a statement, etc. Reading Comprehension, there is very little text here and
Whatever it is that you have to do, you will need 2 things to mostly everything is important; try to read only once.
succeed: know the basic structure of arguments and clearly Reread if required.
understand the argument. As you read, look for the problem in the passage (evaluate
how convincing it is)
In general, most of them, arguments consist of evidence, usually
3. Paraphrase (reword) the passage. It is a very important
2 pieces, a conclusion - the main point of an argument, and an step because when you do a paraphrase, you check whether
assumption - the bridge between the evidence and conclusion. you understood the passage and at the same time you
The majority of the arguments you encounter on the test will be 3 extract the skeleton of the argument, making it easier to
step arguments: identify the conclusion and the assumption. Very often,
Evidence 1 + Evidence 2 = Conclusion. the paraphrase of the passage will be pretty close to the
sumptio conclusion. It is not surprising, since the conclusion is the
As n
main point and evidence just supports it.) Your paraphrase
should be as close to the text and as simple as possible so
E1 + E2 = C that you would understand it easily and at the same time
Example 1 : Last week Mike was detained for shoplifting at a could fully trust it. Do not make it too general nor too
detail oriented. When you do a paraphrase, do it in three
groceries store near his house, but he has been a Christian for 10
steps: Evidence1, Evidence2, and Conclusion; put
years, therefore, the police must have been wrong accusing him
“therefore” word before you start your conclusion, this
in stealing. will help you to set it off.
Note : There are two pieces of evidence: ‘Mike was accused of 4. Read the question again (now with more understanding of
stealing’ and that ‘he is a Christian’. The conclusion is that ‘the what is being asked; reading the question 2 times, it will
police are wrong’. Therefore, our huge assumption here is that ‘a also help you to make sure your answer exactly what is
Christian could not have stolen anything.’ stated and that you understand the question.)
Example 2. There are a lot of mosquitoes outside today, please 5. Answer before reading the answer choices. There are two
do not turn on the light in the room because a lot of them will fly reasons for this :
in. (i) if you can think of the correct answer or at least the
general direction that the answer choice needs to be,
Note : Here the evidences are ‘there are a lot of mosquitoes outside
you will identify it among the wrong choices much
today’ and ‘do not turn on the light’. The conclusion is that
faster, thus spend less time reading the answers,
‘Many will fly in’ and the assumption is ‘mosquitoes will approach which usually take 30 seconds to cover.
the light.’ (ii) Often students are seduced by the author’s wording.
There is no set scheme for structure in CR, but since the majority One reads a few words that were used in the passage
of the arguments are only a few sentences long, the conclusion and the brain identifies this choice with the passage,
usually comes in the first or the last sentence. However, some of thus making it seem more right that it needs to be.
the arguments encountered will not have a conclusion at all or will The more problems you practice with, the more chance
have just an implied one. is you will guess the right answer even before reading
it.
EBD_7203
S1-44 GENERAL APTITUDE FOR GATE
6. Go through the answers, first time scan them for YOUR are increased when federal matching grants are made
answer choice (usually you will guess correctly in 60-70% available.
of cases), if you did not find it, reread them more attentively. Question :
7. Draw a grid to eliminate the wrong answers easier. Use Which of the following can be correctly inferred from the
“ü” for a sure answer, “û” for a definitely wrong answer statements above?
choice, and “?” for an answer that may be right or Options :
questionable. This will help to concentrate only on a few (a) Areas with little vandalism can never benefit from visual
answer choices and will prevent you from reading same deterrence.
answers several times if you get confused or keep having (b) Communities that do not increase their police patrols
troubles locating the right answer. are at higher risk for crimes of opportunity late at night.
Types of Critical Reasoning Questions (c) Federal matching grants for police patrols lower the
Critical reasoning questions will ask you to: rate of crimes of opportunity in some communities.
1. Identify the inference / Must be true question (d) Only federal matching grants are necessary to reduce
2. Identify the assumption. crime in most neighborhoods.
3. Strengthen an argument. Sol. : (c) (c) is a summary of the information provided; it is the
4. Weaken an argument. logical end of a chain of reasoning started in the
5. Select the best conclusion / Main Point stimulus argument. The sequence of events goes like
6. Identify the paradox this :
7. Evaluation/ Reasoning Increased funding ® Increased visual deterrence ®
8. Identify a parallel argument/Structure. Lower crime
The last statement could be mapped as follows:
1. IDENTIFY THE INFERENCE / MUST BE TRUE
Federal grants ® Increased patrol funds
QUESTION
(c) makes the chain complete by correctly stating that
These type of questions are extremely common. An
federal grants can lead to lower crime in some
Inference means the same thing as “must be true”.
Conclusions differ from inferences in that conclusions communities. Now the logical chain becomes:
are the result of premises and inferences are something Federal grants ® Increased funding ® Increased
that must be true. The following are the typical Inference visual deterrence ® Lower crime
(Must be true) based Questions: The other answer choices may not be correctly inferred
• If the statements above are true, which of the because they go beyond the scope of the argument.
following must also be true? They may be objectively, factually correct, or they may
• Which of the following is [implied, must be true, be statements that you would tend to agree with.
implicit, most reasonably drawn] in the passage However, you are limited to the argument presented
above? when choosing a correct answer.
• Which of the following inferences is best supported 2. IDENTIFYTHE ASSUMPTION.
by the statement made above? An assumption is an unstated premise that supports the
How to tackle “Identify the inference / Must be true author’s conclusion. It’s the connection between the
questions”: stated premises and the conclusion. An assumption is
• Read the stimulus and look for the argument. something that the author’s conclusion depends upon.
• Note that Must Be True questions may not contain Assumption questions are extremely common and have
an argument. They may just be a series of facts. types that look like this:
Nevertheless, try to find the argument. • Which of the following most accurately states a
• Avoid choices which contain absolute statements - hidden assumption that the author must make in order
never, always, none, only etc. Although these words to advance the argument above?
might appear in some correct choice, you should be • Which of the following is an assumption that, if true,
very sure about them. would support the conclusion in the passage above?
• Some of the options can be eliminated as they go How to approach “Identify the assumption Questions”
beyond the scope of the passage. Note that an • Look for gaps between the premises and the
inference can be based on only some of the conclusion. Ask yourself why the conclusion is true.
information provided and not the complete passage. Before you progress to the answer choices, try to get
feel of what assumption is necessary to fill that gap
Example 1 : Stimulus Argument between the premises.
Increases in funding for police patrols often lower the rate • Beware of extreme language in the answer choices of
of crimes of opportunity such as petty theft and vandalism assumption questions. Assumptions usually are not
by providing visual deterrence in high-crime neighborhoods. extreme. “Extreme” answer choices usually contain
Levels of funding for police patrols in some communities phrases such as always, never, or totally.
CRITICAL REASONING AND VERBAL DEDUCTION S1-45
5. CONCLUSION / MAIN POINT QUESTION • Some of the options given can be out of the scope of
In Main Point / Conlcusion questions, you have to identify the passage.
the conclusion of an argument. You are trying to find the • Knock out answers with extreme wording. Main Point
author’s point and should approach this question in a similar answers typically do not use only, always, never, best
way to the reading comprehension main point questions. or any strong words that leave little room.
They come in several different formats:
7. EVALUATION/ REASONING BASED QUESTIONS
• The main point of the passage is that...
Reasoning questions ask you to describe how the argument
• Which of the following statements about... is best was made, not necessarily what it says. These questions
supported by the statements above? are closely related to assumption, weakening, and
• Which of the following best states the author ’s strengthening questions. The correct answer identifies a
conclusion in the passage above? question that must be answered or information that must be
• Which of the following conclusions can be most gathered to determine how strong the stimulus argument is.
properly drawn from the data above? The information will be related to an assumption that the
The conclusion of arguments in Main Point questions is author is making. Another type of question that you will
usually not directly stated. To find the conclusion, identify encounter asks you to identify a flaw in the stimulus
the premises and then identify the conclusion drawn from argument. The question tells you that there is a problem
the premises. Main Point questions differ from the other with the logic of the argument. You just have to choose the
Critical Reasoning questions in that the argument in the answer that describes the flaw. Here are some examples of
the ways in which these questions are worded:
stimulus is usually valid. (In most other Critical Reasoning
• How does the author make his point?
questions the reasoning is flawed.) Conclusion questions
• A major flaw in the argument above is that it...
require you to choose the answer that is a summary of the • A’s response has which of the following relationships
argument. to B’s argument?
How to approach “Main Point Questions”: How to approach Reasoning Questions
• Main Point answers must be within the scope of the • Read the argument and find the conclusion.
passage. • State the reasoning in your own words.
• Your opinions or information outside of the passage • Check whether the reasoning given in the various
are always outside of the scope. options fall in line with the reasoning described above.
EBD_7203
S1-46 GENERAL APTITUDE FOR GATE

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

HINTS & SOLUTIONS


1. (d) Answer choice (d) can be easily, directly, and correctly 12. (d) The first statement uses the word ‘always’, which
inferred from the statement that the dogs bark and howl makes it out of context as per the argument presented.
every time their owner lets them outside. The rest of Similarly the second statement is useless as it also uses
this passage is “decoy” material, as discussed in the the word ‘always’. The third statement is not correct
preparation techniques and tips webpage. as it talks only about the trade deficit only and surplus
2. (a) (a) is the correct choice as the passage says that is not mentioned.
“efficiency is present everywhere, this makes it all 13. (c) Statement (a) is true as the goods will be sold earlier so
pervading”. The passage does not suggest that the cost of stocking will be reduced. (b) is clearly true
efficiency does not pay or can be more of a torture. as is directly mentioned in the passage. (d) is correct
3. (b) (b) is the only option as according to the passage as it is clear from the last sentence of the passage that
designations can be forgotten and even a subordinate even a small profit is good enough for these stores.
like a sales engineer can question the CEO. Only (c) conclusion can not be drawn from the passage.
4. (a) The passage refers to disunity of activists and local 14. (b) This passage is a typical example of Response to Stimuli.
indifference to India’s architectural treasures. Thus (a) Clearly the cat starts salivating when the bell rungs
comes across as a best choice as a situation it created because she has related the ringing of bell with food in
in which antique dealers can thrive. Other options are the back of her mind.
clearly not suggested may appear correct but is not at 15. (c) “Some foresee more personal satisfaction ... while
apt as (a).
others ....” make it clear that social incentive motivate
5. (b) (b) comes across as the only logical inference from the investers just as much as financial rewards is implicit
passage where it is shown that animals in general can in the statements.
function when they are in their normal social
16. (b) To call men intelligent who are strikingly so must be
environment as explained through the examples of bees,
to use the concept with undue imprecision.
ants, elephant & beavers who cannot work properly
when separated or invaded by humans 17. (b) Only (b) supports the conclusion, as only in this option
the Government has undermined the decision of the
6. (b) Infering from the passage (b) supports Szymanski’s
conclusion because the passage suggests that clubs Central Bank.
that had spend more on hiring white players should 18. (b) Second last sentence mentions certain types of
have finished higher. However, there is pay personalities but gives no clue about degree of strength
discrimination. So high pay may not mean good in personality. So, (a) is ruled out. Sentence 4 indicates
performance. towards (b). Last sentence says psychological
7. (d) (d) is the only choice which make sense since the dependence is great with heroine and morphine, but
Minister in charge of prisons would be influenced by doesn’t specify which one has greater effect. hence (c)
incidence of disturbance as he had already fears of is ruled out. Safety doesn’t mean lack of dependence
tensions snapping and have recommended an amnesty only, so (d) is ruled out.
policy to his government. 19. (a) Option (b) supports the argument. (c) and (d) discuss
8. (a) (a) is the only option that make sense as the passage totally unrelated issues.
catagorically mentions that the Central Bank does not 20. (a) The “Hope of pursuing” is shattered if option (a)
have the right pursue a monitary policy without happens.
coordination with the central government. 21. (b) It is the correct choice. It best summarises the points
9. (d) Option (d) is essential for basic conclusion. made in the passage and the advice given. The other
10. (a) The “Hope of pursuing” is shattered if option (a) options state one or the other thing incorrectly. In (a)
happens. the second statement is clearly wrong. In (c) & (d)
11. (c) Option (c) would most seriously weaken theory being statement 1 covers only one aspect of the passage. In
tested because it negates the study completely. second statement, ‘learn to not make enemies’ is not
talked about in the passage.
EBD_7203
S1-54 GENERAL APTITUDE FOR GATE
22. (c) (a) is clearly the correct option. (b), (c) and (d) are only 25. (d)
inferences but not the summary. (a) covers the complete 26. (c) Given passage clearly deals with how to deal with
scope of the passage. It offers the essence or the bereavement and grief and so after the tragedy occurs
thematic of the passage while others merely offer and not about precautions. Therefore, irrespective of
citations. the causes of death, a school student rarely gets into
23. (b) Option (b) is the answer because it talks about scientists details of causes – which is beyond the scope of the
being unsure about rapid shifts in earth’s climate and context. Rest all are important in dealing with grief.
how finding a definitive answer will help them to predict 27. (d) Gender is not mentioned in the advertisement and (b)
the future climatic changes. Option (a) cannot be the clearly eliminated.
answer as it talks about research in general and the 28. (d)
paragraph gives more emphasis on finding a “definitive 29. (c)
answer” in terms of climate change. Option (c) is not 30. (c) The whole passage descr ibe the physical
considered as it gives emphasis only on research done characteristics of the Palghat GAP and its significant
in Germany. Option (d) is also ruled out because it impacts on weather patterns in neighbouring parts of
Tamil Nadu and Kerala, Hence, (c) option is correct.
specifically gives more importance to scientists of
31. (b)
Germany.
32. (a)
24. (a) (c) is the most appropriate option. Option (a) doesn’t 33. (b)
talk about the expanding commercial-industrial 34. (d)
economy. (b) does not explain the effect of the u u u
struggles i.e. ‘a new conflict’, (d) is not correct as it
talks specifically only of raw materials for expanding
economy. Further it says local communities are creating
new type of conflict, which is wrong.
PART-B: NUMERICAL ABILITY

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

HINTS & SOLUTIONS


1. (c) Let the numbers be x and 4x.
Then, 84 ´ 21 = x ´ 4x Opting other
subjects 10
or 4 x 2 = 1764
or x 2 = 441 or x = 21 Total no. of students = 15 + 5 + 12 + 10 = 42
Þ 4x = 4 × 21 = 84 8. (c) Let the number be x.
Thus the larger number = 84 Now, x + 13x = 112
2. (d) Let the number be x. 112
or 14x = 112 or x= =8
14
x x
Now - =3 9. (a) Let x = 1 × 2 × 3 × 4 = 24
3 4 Therefore, n = 1 + 24 = 25 = odd
Clearly, n is an odd integer and a perfect square.
x
or = 3 or x = 36 This is true for all values of x (product of any four
12 consecutive integers).
3. (b) Let us check each of the options here starting with 10. (d) A number is divisible by 11 if the difference between
(a) the sum of digits at even places and odd places is
either 0 or divisible by 11.
13 11 133 \ Number 3, 4, 5, 6, 7 is not a multiple of 11 as
(a) + = <5
5 6 30 (3 + 5 + 7) – (4 + 6) = 5 is not a divisible of 11.
11. (a) Given : The product of the first of the three prime
11 8 65 numbers is 385.
(b) + = >5
4 3 12 having 5 at unit’s place. Which is possible only
4. (b) A three digit number to be exactly divisible by 5 must when atleast one prime number contains a digit 5 at
have either 0 or 5 at its units place. unit’s place. Such a prime number is 5 only.
Also 5 × 7 × 11 = 385 and 7 × 11 × 13 = 1001
Such numbers will be 100, 105, 110, ..........., 995.
Hence, 5 is the required prime number.
First term = 100, last term = 995 12. (a) Clearly, 1000 + 1> 1000 × 1
Let the required number be n. Hence, the required positive integer is 1.
To find the value of n, we may use the following 3
formula of arithmetic progression, 13. (a) Number of women = 120 ´ = 72
5
Tn = a + (n – 1) d …(1)
Number of men = 48
Where d = common difference = 5
Þ number of married persons = 80
Tn = 995 and the number of unmarried persons
a = 100 = (120 – 80) = 40
Hence from (1) If all the men are assumed to be married, then the
995 = 100 + (n – 1) 5 number of married women could be 80 - 48 = 32
Þ 5n = 900 Þ maximum number of unmarried women
n = 180 = 72 - 32 = 40
5. (a) 25 ´ 92 = 32 ´ 81 = 2592 . 1089 + 1
14. (a) Number of odd numbered pages = = 545
\ Difference = 25 × 92 – 2592 2
= 2592 – 2592 = 0 15. (b) Let p = 5, 7,11,13, ............
Hence, the numerical difference is 0. For p = 5, (p2 - 1) = 24
6. (a) The numbers– 264, 396, 792, and 6336 are divisible by
132. For p = 7, (p2 - 1) = 48
7. (b) For p = 11, (p2 - 1) = 120
15 5 12 For p= 13, (p2 - 1) = 168
...................................................................
...................................................................
...................................................................
Opting only Opting Opting only Clearly, all the above numbers are divisible by 24.
Physics both Maths
NUMBER SYSTEM S1-63
16. (d) Let each of them had x bullets after division. Then, 24. (b) In this question, the desired number should be divisible
total number of bullets they had after using 4 bullets by 7 and only 301 among all the options is divisible by
each = (x - 4) + (x - 4) + (x - 4) = 3x - 12 7. Also remainder is 1 when it is divided by 3, 4, 5 or 6.
25. (c) Total no. of cats and dogs = 55 .............. (1)
Now, 3x - 12 = x or x = 6
Out of these, 1/5 of cats + 1/4 of dogs had been adopted.
Original no. of bullets = 6 × 3 = 18
It means that number of cats must be divisible by 5 and
17. (b) LCM of 6, 5, 7, 10 and 12 = 420 seconds
number of dogs must be divisible by 4.
420 This condition follow, if cat, C = 15, dog, D = 40
= = 7 minutes .
60 or C = 35, D = 20.
Therefore, in one hour (60 minutes), then will fall In other cases, (1) will not be satisfied.
If C = 15, D = 40, then 3 + 10 = 13 pets were adopted.
æ 60 ö
together 8 times ç ÷ excluding the one at the start. If C = 35, D = 20, then 7 + 5 = 12 pets were adopted.
è 7 ø But 13 > 12.
18. (b) HCF = 22 × 32
LCM = 24 × 35 × 52 × 72 1 1 1
26. (b) + + .... +
Ist number = 23 × 34 × 5 1+ 2 2+ 3 120 + 121
2nd number = 24 × 32 × 52
observing the above situation, we conclude that the ( 2 - 1) ( 3 - 2) ( 4 - 3)
= 2 2
+ 2 2
+ +
third number must be ( 2) - ( 1) ( 3) - ( 2) ( 4) 2 - ( 3) 2
x = 22 ´ 32 ´ 33 ´ 7 2 = 22 ´ 35 ´ 7 2
( 121 - 120)
19. (b) I is false as sum of two negative integers is always .............. +
negative. ( 121)2 - ( 120) 2
II is true, as product of two negative integers is
always positive. = ( 2 - 1) + ( 3 - 2 ) + ( 4 - 3 ) +
III is not always true as x –y can be positive or
negative according as x > y or x < y. ............ + ( 120 - 119) + ( 121 - 120)
20. (d) Product of numbers = HCF × LCM = - 1 + 121 = 11 - 1 = 10
4800 ´ 160 27. (a) The given number is 1234...........2829
Þ The other number = = 1600
480 Sum of the digits = 435
21. (c) A number is divisible by 8 if the number formed by 435 is not divisible by 9. If we subtract 3 from the
the last three digits is divisible by 8. given number, then the sum of the digits of the new
i.e., 58N is divisible by 8. number is 432, which is divisible by 9. Hence the
Clearly,N = 4 given number remains 3 as remainder when divided
Again, a number is divisible by 11 if the difference by 9.
between the sum of digits at even places and sum of 28. (a) Product of the numbers
digits at the odd places is either 0 or is divisible by = HCF × LCM = 21 × 4641
11. = 21 × 3 × 7 × 13 × 17
i.e. (M + 9 + 4 + 4 + 8) - (3 + 0 + 8 + 5 + N) = 3 × 7 × 3 × 7 × 13 × 17
The required numbers can be
= M + 25 - (16 + N)
3 × 7 × 13 and 3 × 7 × 17 = 273 and 357
= M - N + 9 must be zero or it must be divisible by 29. (c) T = P + 4 = 9; N = T – 3 = 6.
11 30. (d) On dividing we find that when
i.e. M - N = 2 Þ M = 2 + 4 = 6 Quotient is 9999 and remainder is 1110.
Hence, M = 6, N = 4 31. (a) Let the Number be N
22. (c) Let the numbers be 7x and 8x. \ N = 765x + 42
Their HCF = x 765 is divisible by 17
Now, LCM × HCF = Product of Numbers \ if N is divided by 17, remainder will be 42 – 34 = 8.
i.e. or x = 5 32. (c) The traffic lights will again change at three different
Hence, the numbers are 35 and 40. road crossings simultaneously after the LCM of 48, 72
23. (d) The series obtained and 108
= 4 ´ 2 + 3 , 4 ´ 5 + 3 , 4 ´ 8 + 3 , 4 ´11 + 3 ...... i.e., after every (432 sec) 7 minutes and 12 seconds, i.e.
= 11, 23, 35........ the earliest at 8 : 27 : 12 hours.
EBD_7203
S1-64 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)

a 9 9 27 Þ 4 S n2 = 22 (12 + 22 + 32 + ..... + n2)


We know, S ¥ = = = =
1- r æ 1ö 4 4 4n(n + 1)(2n + 1) 2 n( n + 1)(2 n + 1)
1- ç - ÷ = =
è 3ø 3 6 3
52. (b) If n is odd, the required sum is
2 +1 1 1
48. (a) , , ...........
2 -1 2( 2 - 1) 2 12 + 2.22 + 32 + 2.4 2 + ...... + 2.( n - 1) 2 + n 2

1 (n - 1)(n - 1 + 1)2
Common ratio of the series =
2( 2 + 1) = + n2
2

æ 2 +1ö æ ö [Q (n–1) is even


a 1
\ sum = =ç ÷ / çç 1 - ÷
ç ÷
1– r è 2 - 1 ø è 2( 2 + 1) ÷ø \ using given formula for the sum of (n–1) terms.]

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 54. (b) We have S = 2 + 4 + 7 + 11 + 16 + .... + Tn


= [ (10 + 102 +103 + ....+ 10n) – n]
9
Again S = 2 + 4 + 7 + 11 + 16 + .... + Tn-1 + Tn
8 é10(10 - 1) - n ù
n
Subtracting , we get
= ê ú
9 ëê 10 - 1 ûú 0 = 2 + {2 + 3 + 4 + 5 + .... + (Tn - Tn -1 )} - Tn

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

SET n(A1 È A 2 È ..... È A n ) = n(A1) + n(A 2 ) + ..... + n(A n )


A set is a collection of well-defined objects. The members OPERATIONS ON SETS
of a set are called element of set. (i) Union of Sets : Let A and B be two sets. The union of A and
If x is an element of the set A, we write xÎA B is the set of all those elements which belong to A or B or
If x is not an element of the set A, we write x Ï A A and B both. Symbolically we write AÈB which is read as
“ A union B”
TYPES OF SET :
(ii) Intersection of Sets : Let A and B are two sets. The
• Empty set or Null Set or Void Set : intersection of the sets A and B is the set of all those
A set which does not contain any element is called the elements which belong to both A and B. Symbolically, we
empty/null set. A null set is denoted by f or {}. write AÇB,
• Singleton Set : (iii) Difference of Sets : Let A and B are two sets. The difference
A set containing only one element is called a singleton set. of the sets A and B, in this order, is the set of elements
• Finite and Infinite sets : which belong to A but not to B. Symbolically, we write
A– B
A set which is empty or consists of a definite number of
elements is called FINITE otherwise it is called an infinite (iv) Complement of a Set : Let U be the universal set and A is a
set. subset of U. The complement of the set A, denoted by A' or
Ac is the set of all those elements of U which are not the
Equal sets :
elements of A.
Given two sets A and B. If every element of A is also an
(v) De morgan’s laws
element of B and vice versa, the sets A and B are said to be
equal and we write A = B. (a) (A È B)' = A' Ç B'

Equivalent sets : (b) (A Ç B)' = A' È B'

Given two sets A and B. If number of elements of A is equal (c) A – (B È C) = (A – B) Ç (A – C)


to number of elements of set B and we write A Û B. (d) A – (B Ç C) = (A – B) È (A – C)
Cardinal number of a set
If a finite set A consists of n distinct elements then we write
n (A) = n or O (A) = n. It is called the CARDINAL NUMBER,
or CARDINALITY or ORDER of the set A. For example if
A = {10, 25, 30, 45, 55}then n(A) = 5. The cardinality of a void
set is zero and the cardinality of a singleton set is 1.
EBD_7203
S1-70 GENERAL APTITUDE FOR GATE

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

(a) 8 2 (b) 2 5 (c) (x – 1)(2x – 5) = 0(d) 2 x 2 - 3x + 4 = 0


16. Which of the following is a quadratic equation ?
(c) 6 3 (d) 3 7
1
7. At the first stop on his route, a driver uploaded 2/5 of the (a) x2 + 2x + 3 = 0
packages in his van. After he uploaded another three
packages at his next stop, 1/2 of the original number of (b) ( x - 1)(x + 4) = x 2 + 1
packages remained. How many packages were in the van
before the first delivery? (c) x 4 - 3x + 5 = 0
(a) 25 (b) 10
(c) 30 (d) 36 (d) (2x + 1)(3x - 4) = 2x 2 + 3
8. Ram’s age was square of a number last year and it will be 17. In a survey it was found that 65% of the people watched
cube of a number next year. How long must be wait before news on TV, 40% read newspaper, 25% read newspaper
his age is again the cube of a number? and watched TV both. What percentage of people neither
(a) 39 years (b) 38 years watched TV nor read news paper?
(c) 10 years (d) 64 years (a) 0% (b) 5%
9. If (x – 3) (2x + 1) = 0, then the possible values of |2x + 1 (c) 10% (d) 20%
are :
(a) 0 only (b) 0 and 3 18. If 2x 2 - 7xy + 3y 2 = 0 , then the value of x : y is :
1 (a) 3 : 2 (b) 2 : 3
(c) - and 3 (d) 0 and 7 (c) 3 : 1 or 1 : 2 (d) 5 : 6
2
ALGEBRA S1-71

1 27. Given t = 2 + 3 4 + 3 2 , determine the value of


19. A’s age is th of B’s age. It will be twice of C’s age after
6
t 3 - 6t 2 + 6t - 2 .
10 years. If C’s eighth birthday was celebrated two years
ago, then the present age of A must be : (a) 0 (b) 1
(c) 6 (d) None of these
(a) 5 years (b) 10 years
28. If a + b + c = 0, then find the value of
(c) 15 years (d) 20 years
a2 b2 c2
2
1 + + .
æ 1ö
a 2 - bc b 2 - ca c 2 - ab
20. If ç a + ÷ = 3 , then what is the value of a 3 + ?
è a ø a3 (a) 0 (b) 1
(c) 6 (d) None of these
10 3 29. In a committee, 50 people speak French, 20 speak Spanish
(a) (b) 0
3 and 10 speak both Spanish and French. The number of
persons speaking at least one of these two languages is:
(c) 3 3 (d) 6 3 (a) 60 (b) 40
21. In a group of 15 women, 7 have nose studs, 8 have ear (c) 38 (d) None of these
rings and 3 have neither. How many of these have both 30. Out of 800 boys in a school, 224 played cricket; 240-played
nose studs and ear rings? hockey and 336 played basketball. Of the total, 64 played
(a) 0 (b) 2 both basketball and hockey; 80 played cricket and basketball
(c) 3 (d) 7 and 40 played cricket and hockey; 24 played all the three
22. All the students of a batch opted Psychology, Business games. The number of boys who did not play any game is :
or both. 73% of the students opted Psychology and 62% (a) 160 (b) 240
opted for Business. If there are 220 students, how many (c) 216 (d) 128
of them opted for both Psychology and Business ? 31. The average temperature for the first four days of a week is
(a) 60 (b) 50 40.2°C and that of the last four days is 41.3°C. If the average
(c) 72 (d) None of these temperature for the whole week is 40.6°C, then the
temperature on the fourth day is :
23. In a certain town, 25% families own a phone, 15% own a car
(a) 40.8°C (b) 38.5°C
and 65% own neither a phone nor a car. 2,000 families own
(c) 41.3°C (d) 41.8°C
both a car and a phone. Consider the following statements
32. Which of the following expressions are different in value?
in this regard:
(A) (2x + 3y)2
I. 10% families own both a car and a phone. (B) (2x + y)2 + 8y (x + y)
II. 35% families own either a car or a phone. (C) (2x – y)2 – 8y (x + y)
III. 40,000 families live in the town. (D) 22 (x + y)2 + 4xy + 5y2
Which of the above statements are correct ? (a) A and B (b) B and C only
(a) I and II (b) II and III (c) A, B and D only (d) B and D only
(c) I and III (d) I, II and III
x 5
24. There are two examination rooms A and B. If 10 candidates 33. If 3x – 5y = 5 and = , then what is the value of x – y?
are sent from room A to room B, the number of candidates x+ y 7
in each room is the same, while if 20 are sent from room (a) 9 (b) 6
B to room A, the number of candidates in room A becomes (c) 4 (d) 3
double the number in room B. The number of candidates 34. Which of the following values of x will satisfy the
in each room are, respectively : inequality x2 – x – 6 > 0 ?
(a) 80 and 100 (b) 100 and 80 (a) x < – 2 or x > 3 (b) – 2 < x < 3
(c) 80 and 120 (d) 100 and 60 (c) – 3 < x < 2 (d) x > – 2 or x < 3
25. If x + y > 5 and x – y > 3, then which of the following 35. If A and B are positive integers such that 9A2 = 12A + 96
inequalities gives all the possible values of x ? and B2 = 2B + 3, then which of the following is the value
(a) x > 3 (b) x > 4 of 5A +7B?
(a) 31 (b) 41
(c) x > 5 (d) x < 5
(c) 36 (d) 43
26. 40% of the students in a college play basketball, 34% of
36. A two-digit number is seven times the sum of its digits.
the students play tennis and the number of students who
If each digit is increased by 2, the number thus obtained
play both the games is 234. The number of students who
is 4 more than six times the sum of its digits. Find the
neither play basketball nor tennis is 52%. Determine the
number.
total number of students in the college. (a) 42 (b) 24
(a) 750 (b) 960 (c) 48 (d) Data inadequate
(c) 900 (d) 850
EBD_7203
S1-72 GENERAL APTITUDE FOR GATE
37. If 2x + 3y = 26; 2y + z = 19 and x + 2z = 29, what is the 45. A town has total population of 25,000 out of which 13,000
value of x + y + z ? read “The Time of India” and 10,500 read “ The Hindustan
(a) 18 (b) 32 Times”. 2,500 read both papers. The percentage of
(c) 26 (d) 22 population who read neither of these newspapers is
38. The sum of four numbers is 64. If you add 3 to the first (a) 16% (b) 18%
number, 3 is subtracted from the second number, the third (c) 20% (d) 25%
is multiplied by 3 and the fourth is divided by 3, then all 46. In an examination, a pupil’s average marks were 63 per paper.
the results are equal. What is the difference between the
If he had obtained 20 more marks for his Geography paper
largest and the smallest of the original numbers?
and 2 more marks for his Histroy paper, his average per
(a) 32 (b) 27 paper would have been 65. How many papers were there in
(c) 21 (d) Cannot be determined the examination?
39. If xabc = xaxbxc and x are all positive integers, then (a) 8 (b) 9
a2 + b2 + c2 = ?
(c) 10 (d) 11
(a) 12 (b) 14
47. 25 persons are in a room. 15 of them play hockey, 17 of them
(c) 29 (d) cannot be determined play football and 10 of them play both hockey and football.
1 1 1
Then the number of persons playing neither hockey nor
40. + + =? football is [GATE 2010, 1 mark]
(b -a) (c -a) (a - b) (c - b) (b - c)
1+ x +x 1+ x +x 1+ x + x (a -c)
(a) 2 (b) 17
(a) 0 (b) 1
(c) 13 (d) 3
(c) xa – b – c (d) None of these
48. Hari (H), Gita (G), Irfan (I) and Saira (S) are siblings (i.e.,
41. The fourth root of 28 + 16 3 is- brothers and sisters). All were born on 1st January. The age
difference between any two successive siblings (that is born
(a) 4 + 2 3 (b) 2 2 + 3
one after another) is less than 3 years. Given the following
(c) 3 +1 2 (d) 3 – facts: [GATE 2010, 1 mark]
42. If mxm – nxn = 0, then what is the value of I. Hari’s age + Gita’s age > Irfan’s age + Saira’s age
II. The age difference between Gita and Saira is 1 year.
1 1
+ terms of xn ? However, Gita is not the oldest and Saira is not the youngest
xm + x n xm - xn
III. There are no twins.
2mn 2mn In what order were they born (oldest first)?
(a) n 2 2 (b) n 2 2 (a) HSIG (b) SGHI
x (n - m ) x (n + m )
(c) IGSH (d) IHSG
2mn 2mn 49. The variable cost (V) of manufacturing a product varies
(c) (d)
x n (m 2 - n 2 ) x n (m 2 + n 2 ) according to the equation V = 4q, where q is the quantity
produced. The fixed cost (F) of production of same product
1 reduces with q according to the equation F = 100/q. How
43. If x = 2 + then the value of x is
1 many units should be produced to minimize the total cost
2+
1 (V + F)? [GATE2011, 2 marks]
2+
2 + ........ (a) 5 (b) 4
(c) 7 (d) 6
(a) 2 –1 (b) 2 +1 50.5. A political party orders an arch for the entrance to the ground
(c) 3 (d) None in which the annual convention is being held. The profile of
the arch follows the equation y = 2x – 0.1x2, where y is the
mx 2 + 3x + 4 height of the arch in meters. The maximum possible height
44. If < 5 for all x Î R, then
x 2 + 2x + 2 of the arch is [GATE 2012, 2 marks]
71 (a) 8 meters (b) 10 meters
(a) m > 5 (b) m <
24 (c) 12 meters (d) 14 meters
(c) m = 5 (d) None of these
ALGEBRA S1-73
51. Which of the following assertions are CORRECT? 53. The roots of ax2 + bx + c = 0 are real and positive. a, b and c
P : Adding 7 to each entry in a list adds 7 to the mean of are real. Then ax2 + b|x| + c = 0 has
the list [GATE 2014, Set-1, 1 Mark]
Q : Adding 7 to each entry in a list adds 7 to the standard (a) no roots (b) 2 real roots
deviation of the list (c) 3 real roots (d) 4 real roots
R : Doubling each entry in a list doubles the mean of the
list 54. The value of 12 + 12 + 12 + ... is
S : Doubling each entry in a list leaves the standard [GATE 2014, Set-2, 1 Mark]
deviation of the list unchanged[GATE 2012, 2 Marks]
(a) 3.464 (b) 3.932
(a) P, Q (b) Q, R
(c) 4.000 (d) 4.444
(c) P, R (d) R, S
55. Consider the equation : (7526)8 – (Y)8 = (4364)8, where (X)N
52. The cost function for a product in a firm is given by 5q2, to the base N. Find Y. [GATE 2014, Set-3, 2 Marks]
where q is the amount of production. The firm can sell the
(a) 1634 (b) 1737
product at a market price of ` 50 per unit. The number of
units to be produced by the firm such that the profit is (c) 3142 (d) 3162
maximized is [GATE 2012, 1 Mark]
(a) 5 (b) 10
(c) 15 (d) 25
EBD_7203
S1-74 GENERAL APTITUDE FOR GATE

HINTS & SOLUTIONS


1. (a) 1.236 ´ 1015 - 5.23 ´ 1014 3 7 = 3 × 2.64 = 7.92
14
= 1014 (12.36 - 5.23) = 7.13 ´ 10 and 8 2 = 8 × 1.41 = 11.28
2 2
- - -2 Clearly, 8 2 is the largest.
æ -1 ö 3 æ -1ö 3 æ 1ö
2. (d) ç ÷ = çç 3 ÷÷ = ç- ÷ = (-6)2 = 36 7. (c) Let the total number of packages be x.
è 216 ø è6 ø è 6ø
2
After uploading x packages remaining packages are
( )
1/ 3
3. (b) 3 3
0.000064 = 0.008 = (0.2 ) 3
= 0.2 5
2 3
x– x= x
4. (c) Let 28 - 10 3 = x - y 5 5
According to the question,
Þ 28 - 10 3 = x + y - 2 xy
1
Þ x + y = 28, xy = 75 When he uploaded another 3 packages then of
2
Therefore, original no. of packages remained.
( x - y) 2 = ( x + y) 2 - 4xy = 784 - 300 = 484 3x x 3 1x
\ –3= Þ x – =3
Þ x – y = 22 or x = 25, y = 3 5 2 5 2
Thus, Þ 6x – 5x = 30 Þ x = 30
28 - 10 3 = 25 - 3
8. (b) Let the present age of Ram be 26 yr.
Again, let 7+4 3 = p+ q Last year Ram’s age = 26–1 = 25 yr
which is square of number 5.
Þ 7 + 4 3 = p + q + 2 pq Now, next year Ram’s age will be = 26 +1 = 27 yr
Þ p + q = 7 , pq = 12 which is cube of number 3.
Thus, adding 38 and 26, we’ll get 64 which is cube of
Þ p – q = 1 or p = 4, q = 3 number 4.
Thus, 7+4 3 = 4+ 3 9. (d) (x – 3) (2x + 1) = 0 Þ (x – 3) = 0 or (2x + 1) = 0
1 1
when x – 3 = 0, x = 3
-
Now, (28 - 10 3) 2 - (7 + 4 3) 2 1
when 2x + 1 = 0 Þ x =-
2
1 4- 3
= 25 - 3 - = 25 - 3 - 1
4+ 3 1 When x = 3, then (2x + 1) = 7 and when x = - ,
2
= 25 - 4 = 5 - 2 = 3 then 2x + 1 = 0,
9+ 2 6- 2
5. (c) + Possible values of (2x + 1) are 0 and 7.
5+ 3 5- 3 10. (b) Using (a + b )3 = a3 + b3 + 3ab(a + b)
9( 5 - 3) + 2( 5 - 3) + 6( 5 + 3) - 2( 5 + 3) 3
= æ 1ö 3 1 æ 1ö
( 5 + 3)( 5 - 3) ç x + ÷ = x + 3 + 3ç x + ÷
è xø x è xø
1
= (9 5 - 9 3 + 10 - 6 + 6 5 + 6 3 - 10 - 6) æ 1 ö
2 Þ (5)3 = çç x 3 + ÷÷ + 15
1 è x3 ø
= (15 5 - 3 5 - 2 3)
2 1
or x 3 + = 125 - 15 = 110
1 x3
= [15 ´ 2.236 - 3 ´ 1.732 - 2 ´ 2.449]
2 11. (c) Let father’s, mother’s and daughter’s present age be
F, M, D respectively.
1
= [33.540 - 5.196 - 4.898] = 11.723 We have, F = M + 5, M = 3D and D = 10
2
Þ M = 3 × 10 = 30 years and F = 30 + 5 = 35 years
6. (a) 2 5 = 2 × 2.23 = 4.46 The father’s age at the time of birth of the daughter
= 35 – 10 = 25 years
6 3 = 6 × 1.73 = 10.38
ALGEBRA S1-75

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

23. (b) Phone Car b 2 + c 2 + 2bc + b 2 + c 2 2( b 2 + c 2 + bc)


25% 15% = = =2
b 2 + c 2 + bc b 2 + c 2 + bc
29. (a) French Spanish
8000 2000 4000 speaking speaking
20% 5% 10%

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%

14% 8% = 800 – 160 – 216 – 128 – 40 – 16 – 24 – 56 = 160.


31. (d) Temperature on the fourth day
40% 34%
= 40.2 × 4 + 41.3 × 4 – 40.6 × 7
234 = 160.8 + 165.2 – 284.2 = 41.8°C
Let the number of students be 100. 32. (b) All others are equal except (C).
Then number of students who play both the games 33. (d) 3x – 5y = 5 ...(i)
= (34 + 40) – (48) = 26 x 5
If 26 students play both the games, then the total And = Þ 7x = 5x + 5y
x+ y 7
number of students = 100
Therefore, if 234 students play both the games, then Þ 2x = 5y ... (ii)
100 From (i) and (ii), x = 5 and y = 2
the total number of students = ´ 234 = 900 \ x–y=3
26 34. (a) x2 – x – 6 > 0
27. (a) t-2 = 3 4 +3 2 ....(i) or, x2 – 3x + 2x – 6 > 0
Using (a + b)3 = a3 + b3 + 3ab(a + b) or, x(x – 3) + 2(x – 3) > 0
or, (x – 3) (x + 2) > 0
(t - 2)3 = 4 + 2 + 3 3 4 3 2( 3 4 + 3 2) or, x = 3 or – 2
\ x < – 2 or x > 3
Þ t 3 - 8 - 6t 2 + 12t = 6 + 6( 3 4 + 3 2)
35. (b) 9A2 = 12A + 96 Þ 3A2 – 4A – 32 = 0
Þ t3 – 8 – 6t2 + 12t = 6 + 6(t – 2) [Using (i)]
Þ t3 – 6t2 – 8 + 12t = 6 + 6t – 12 4 ° 16 ∗ 384 8
[ A = < 4, ,
Þ t3 – 6t2 + 6t – 2 = 0 6 3
B2 = 2B + 3 Þ B2 – 2B – 3= 0
28. (d) a + b + c =0 Þ a 2 = (b + c) 2
or a = – b – c 2 ° 4 ∗12
[ B= < 3, ,1
(b + c) 2 b2 c2 2
Now, + + [ 5 A + 7B = 5 × 4 + 7 × 3 = 20 + 21= 41
a 2 - bc b 2 - ca c2 - ab 36. (a) Let the two-digit number be l0 x + y.
(b + c) 2 b2 c2 10 x + y = 7(x + y) Þ x = 2y...(i)
= + + 10 (x + 2) + y + 2 = 6 (x + y + 4) + 4
(b + c)2 - bc b 2 + c(b + c) c 2 + b(b + c)
or 10x + y + 22 = 6x + 6y + 28 Þ 4x – 5y = 6 ... (ii)
( b + c) 2 b2 c2 Solving equations (i) and (ii), we get x = 4 and
= + + y=2
b 2 + c 2 + bc b 2 + c 2 + bc c 2 + b 2 + bc
ALGEBRA S1-77
37. (d) On solving equation we get
æ m m ö
x = 7, y = 4, z = 11 = çç + ÷
n
è x (n + m) x (n - m) ÷ø
n
38. (a) Let the first, second, third and fourth numbers be a, b,
c and d respectively. m æ 1 1 ö 2mn
= +
n çn+m n-m÷ = n
According to the question, x è ø x (n 2 - m 2 )
a + b + c + d = 64 ....(i)
1
d 43. (b) We can write given expression as x = 2 +
and a + 3 = b – 3 = 3c = x
3
i.e., a + 3 = b – 3 Þ b = a + 6 ....(ii) Þ x2 – 2x – 1 = 0 Þ x = 1 ± 2

a+3 Q x>2 Þ x=1+ 2


Also, c = and d = 3 ( a + 3)
3
mx 2 + 3x + 4
Solving the above eqns, we get 44. (b) Given, <5
x 2 + 2x + 2
a = 9, b = 15, c = 4 and d = 36
Þ (m – 5) x2 – 7x – 6 < 0
\ Difference between the largest and the smallest
numbers = 36 – 4 = 32 It holds for all x if m – 5 < 0 and 49 + 24 (m – 5) < 0
39. (b) xabc = xaxbxcÞ xabc = xa + b + c Þ abc = a + b + c. This 71
happens for positive integer value of a, b, c, only when Þ m < 5 and m <
24
a, b, c take value of 1, 2 & 3. 45. (a) From the venn diagram
Hence, a2 + b2 + c2 = 12 + 22 + 32 = 1 + 4 + 9 = 14.
40. (b) Given exp. d
HT TI
1 1 1
= + + a b c
æ x b xc ö æ xa x c ö æ xb xa ö
çç1 + a + a ÷÷ çç 1 + b + b ÷÷ çç 1 + + ÷
è x x ø è x x ø è xc x c ÷ø

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

Ratio of male to female students


3.5
more get a discount of 5% on the total fare. If the one way
3
single person fare is Rs 100, a group of 5 tourists purchasing
round-trip tickets will be charged Rs ________ 2.5
[GATE 2014, Set-1, 2 Marks] 2
37. In a survey, 300 respondents were asked whether they own
1.5
a vehicle or not. If yes, they were further asked to mention
whether they own a car or scooter or both. Their responses 1
are tabulated below. What percent of respondents do not 0.5
own a scooter?
0
Men Women 2008 2009 2010 2011 2012
Car 40 34 39. The Gross Domestic Product (GDP) in Rupees grew at 7%
Own vehicle Scooter 30 20 during 2012-2013. For international comparison, the GDP is
Both 60 46 compared in US Dollars (USD) after conversion based on
D o not own vehicle 20 50 the market exchange rate. During the period 2012-2013 the
exchange rate for the USD increased from Rs. 50/ USD to
38. The ratio of male to female students in a college for five Rs. 60/ USD. India’s GDP in USD during the period 2012-
years is plotted in the following line graph. If the number of 2013 [GATE 2014, Set-3, 2 Marks]
female students doubled in 2009, by what percent did the (a) increased by 5 % (b) decreased by 13%
number of male students increase in 2009? (c) decreased by 20% (d) decreased by 11%
[GATE 2014, Set-2, 2 Marks]
PERCENTAGE & ITS APPLICATIONS S1-83

HINTS & SOLUTIONS


1. (a) Let the original price be x and sale be of y units. 7. (a) Quantity of Pizza Mohan took during the week
Then, the revenue collected initially = x × y
Now, new price = 0.8x, new sale = 1.8 y 1 1 1 1 1 1 1 127
= + + + + + + =
Then, new revenue collected = 1.44xy 2 4 8 16 32 64 128 128
Therefore, % of Pizza he took during the week
0.44 xy
% increase in revenue = ´ 100 = 44%
xy 127
= ´ 100 = 99.22%
2. (c) Let the number of boys be x. Then, the number of 128
girls = ( x + 15) 8. (b) Let the original number be 100.
Then, the new number = 100 × 1.1 × 0.9 = 99
New number of girls = ( x + 15) ´ 1.1 i.e. the number decreases by 1%.
New number of boys = x ´ 1.16
x´a b´ y
Then, 1.1( x + 15) = 1.16 x + 9 9. (b) = Þ ax = by ...(i)
100 100
Þ 1.16 x - 1.1x = 16.5 - 9 = 7.5 Let C% of y = D% of x
7.5
or 0.06 x = 7.5 or x= = 125
0.06 C ax D
Number of boys = 125 then ´ = x [using (i)]
Number of girls = 140 100 b 100
Þ Number of students = 265 ac
3. (d) Let the CP of the article be ` 100. ÞD=
b
1
SP at a gain of 12 % = 100 + 12.5 = ` 112.50 20
2 10. (b) 40 % of boys = Þ 40% of boys = 10 girls
2
SP at a gain of 25% = ` 125
If SP is ` 12.5 more, then CP = 100. Total no. of boys = 25
Therefore, if SP is ` 22.50 more, then CP \ Total number of students = 25 + 20 = 45
11. (b) Total no. of machine parts in both the shipments
100
= ´ 22.5 = ` 180 = (120 + 80) = 200
12.5
Total defective machine parts in both the shipments
4. (b) Let B’s salary be ` 100, = 120 × 5% + 80 × 10% = 6 + 8 = 14
then A’s salary = ` 125
14
125 - 100 25 Therefore, required % = ´ 100 = 7%
% lesser = ´ 100 = ´100 200
125 125
12. (b) Total population 2,96,000
1 Literates (50%) 1,48,000
= ´100 = 20%
5 Males 1,66,000
5. (b) Seats in executive class = 50 Literate Males (70% of males) 1,16,200
Seats in chair cars = 450
Literate females 31,800
Total booked seats = 425
Booked in executive class = 48 13. (c) According to the question 35% of families own either a
Therefore, seats booked in chair cars = (425 – 48) phone or a car or both.
= 377 P
Empty seats in chair cars = 450 – 377 = 73 \ 20 5 10 C i.e. 5% of families own both a car and a
6. (c) Total numbers of inhabitants = 1000 phone. From the question, 2000 people have both car
No. of males = 600 and phone.
No. of females = 400
\ 5% of people = 2000.
Number of literate males = 20% of 600 = 120
If the total no. of people = x
Total number of literates = 250
Total number of literate females = 130 5
then, x = 2000 Þ x = 40, 000.
130 100
\ % of female literates = ´ 100 = 32.5 Hence statements B and C are correct.
400
EBD_7203
S1-84 GENERAL APTITUDE FOR GATE

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

TIME AND WORK • If n men or m women can do a piece of work in X days,


• If A can do a piece of work in X days, then A’s one day’s then N men and M women together can finish the work in
1 nmX
work = th part of whole work. days.
X nM + mN
• If ‘M1’ persons can do ‘W1’ works in ‘D1’ days and ‘M2’
1 persons can do ‘W2’ works in ‘D2’ days then
• If A’s one day’s work = th part of whole work, then A
X M1D1W2 = M2D2W1
can finish the work in X days. If T1 and T2 are the working hours for the two groups
• If A can do a piece of work in X days and B can do it in Y then
days then A and B working together will do the same work M1D1W2T1 = M2D2W1T2
Similarly,
XY
in days. M1D1W2T1E1 = M2D2W1T2E2, where E1 and E2 are the
X+Y
efficiencies of the two groups.
• If A, B and C can do a work in X, Y and Z days respec- • If A is n times as efficient as B, i.e. A has n times as much
tively then all of them working together can finish the
work in 1
capacity to do work as B, A will take of the time taken by
n
XYZ
days. B to do the same amount of work.
XY + YZ + XZ
• If A and B together can do a piece of work in X days and PIPE AND CISTERNS
A alone can do it in Y days, then B alone can do the work The same principle of Time and Work is employed to solve the
in problems on Pipes and Cisterns. The only difference is that in
XY this case, the work done is in terms of filling or emptying a
days. cistern (tank) and the time taken is the time taken by a pipe or a
Y–X
leak (crack) to fill or empty a cistern respectively.
• A and B can do a work in ‘X’ and ‘Y’ days respectively.
Inlet : A pipe connected with a tank (or a cistern or a reservoir)
They started the work together but A left ‘a’ days before
is called an inlet, if it fills it.
completion of the work. Then, time taken to finish the
Outlet : A pipe connected with a tank is called an outlet, if it
work is
empties it.
Y(X + a)
X+Y • If a pipe can fill a tank in x hours, then the part filled in 1
• If ‘A’ is ‘a’ times efficient than B and A can finish a work 1
hour =
in X days, then working together, they can finish the work x
aX • If a pipe can empty a tank in y hours, then the part of the
in days.
a +1 full tank emptied in 1 hour =
1
.
• If A is ‘a’ times efficient than B and working together they y
finish a work in Z days then, time taken by A = • If a pipe can fill a tank in x hours and another pipe can
empty the full tank in y hours, then the net part filled in 1
Z(a + 1)
days. and time taken by B = Z(a + 1) days.
a æ1 1ö
hour, when both the pipes are opened = ç x – y ÷ .
• If A working alone takes ‘x’ days more than A and B together, è ø
and B working along takes ‘y’ days more than A and B \ Time taken to fill the tank, when both the pipes are
together then the number of days taken by A and B working
xy
opened = .
together is given by [ xy] days. y–x
EBD_7203
S1-88 GENERAL APTITUDE FOR GATE
• If a pipe can fill a tank in x hours and another can fill the
æm ö
same tank in y hours, then time taken to fill the tank Change in time = ç - 1÷ × t1; for n > m
èn ø
xy
= , when both the pipes are opened
y+x æ nö
= ç 1 - ÷ × t1; for m > n
• If a pipe fills a tank in x hours and another fills the same è mø
tank is y hours, but a third one empties the full tank in z • If first part of the distance is covered at the rate of v1 in time
hours, and all of them are opened together, then net part t1 and the second part of the distance is covered at the rate
é1 1 1ù
filled in 1 hr = ê + – ú æ v1t 2 + v2 t 2 ö
ëx y zû of v2 in time t2, then the average speed is ç t + t
è 1 2 ÷ø
xyz Relative Speed : When two bodies are moving in same direction
\ Time taken to fill the tank = hours.
yz + xz – xy with speeds S1 and S2 respectively, their relative speed is the
• Two filling pipes A and B opened together can fill a cistern in difference of their speeds.
t minutes. If the first filling pipe A alone takes X minutes i.e. Relative Speed = S1 – S2
more or less than t and the second fill pipe B along takes Y When two bodies are moving in opposite direction with speeds
minutes more or less than t minutes, then t is given by S1 and S2 respectively, their relative speed is the sum of their
speeds.
[t = xy] minutes.
i.e. Relative Speed = S1 + S2
SPEED AND DISTANCE • If two persons (or vehicles or trains) start at the same time
in opposite directions from two points A and B, and after
The rate at which any moving body covers a particular distance
is called its speed. crossing each other they take x and y hours respectively
Distance = Speed × time to complete the journey, then
Unit : SI unit of speed is metre per second (mps). It is also Speed of first y
measured in kilometers per hour (kmp) or miles per hour (mph). =
Speed of second x
Conversion of units :
(i) 1 hour = 60 minutes = 60 × 60 seconds. • A man covers a certain distance D. If he moves S1 speed
1 km = 1000 m faster, he would have taken t time less and if he moves S 2
1 km = 0.6214 mile speed slower, he would have taken t time more. The
Þ 1 mile = 1.609 km, i.e., original speed is given by
8 km = 5 miles
2 ´ (S1 ´ S2 )
1 yard = 3 feet
S2 ~ S1
1 foot = 12 inches
5 • If a person with two different speeds U & V cover the
1 km/h = m/sec, same distance, then required distance
18
U´V
18 = ´ Difference between arrival time
1 m/sec = km/h U~V
5
U´V
1 miles/hr =
22
ft/sec Also, required distance = Total time taken ´
U+V
15
Total Distance TRAINS
(ii) Average speed =
Total time A train is said to have crossed an object (stationary or moving)
• If a certain distance (d), say from A to B, is covered at ‘a’ only when the last coach of the train crosses the said object
km/hr and the same distance is covered again say from B to completely. It implies that the total length of the train has
A in ‘b’ km/hr, then the average speed during the whole crossed the total length of the object.
journey is given by : • Time taken by a train to cross a pole/a standing man
æ 2ab ö km Length of train
Average speed = ç ÷ = .
è a + b ø hr Speed of train
• If a body travels a distance ‘d’ from A to B with speed ‘a’ in
• Time taken by a train to cross platform/bridge etc. (i.e. a
time t1 and travels back from B to A i.e., the same distance
stationary object with some length)
m
with of the usual speed ‘a’, then the change in time taken length of train + length of platform/bridge etc.
n = .
speed of train
to cover the same distance is given by :
TIME AND WORK & SPEED AND DISTANCE S1-89
• When two trains with lengths L1 and L2 and with speeds BOATS AND STREAM
S1 and S2 respectively, then Stream : It implies that the water in the river is moving or
(a) When they are moving in the same direction, time flowing.
taken by the faster train to cross the slower train Upstream : Going against the flow of the river.
L1 + L 2 Downstream : Going with the flow of the river.
= .
difference of their speeds Still water : It implies that the speed of water is zero (generally,
in a lake).
(b) When they are moving in the opposite direction, time
taken by the trains to cross each other Flow of water
L1 + L 2 Boat
= . Up stream
sum of their speeds Down stream
Boat
• Suppose two trains or two bodies are moving in the same
direction at u km/hr and v km/hr respectively such that u > v,
Let the speed of a boat (or man) in still water be
then
X m/sec and the speed of the stream (or current) be Y m/
their relative speed = (u – v) km/hr. sec. Then,
If their lengths be x km and y km respectively, then time taken • Speed of boat with the stream (or downstream or D/S)
by the faster train to cross the slower train (moving in the = (X + Y) m/sec.
æx+yö • Speed of boat against the stream (or upstream or U/S)
same direction) = ç ÷ hrs. = (X – Y) m/sec.
è u-vø
• Speed of boat in still water is
• Suppose two trains or two bodies are moving in opposite
directions at u km/hr and v km/hr, then their relative speed (X + Y) + (X – Y) Upstream + Downstream
X= =
= (u + v) km/hr. 2 2
If their lengths be x km & y km, then : • Speed of the stream or current is
(X + Y) – (X – Y) Downstream - Upstream
æx+yö Y= =
time taken to cross each other = ç ÷ hrs. 2 2
èu+vø • A man can row X km/h in still water. If in a stream which is
• If a man is running at a speed of u m/sec in the same direction flowing of Y km/h, it takes him Z hours to row to a place
in which a train of length L meters is running at a speed and back, the distance between the two places is
v m/sec, then (v – u) m/sec is called the speed of the train
Z(X 2 – Y 2 )
relative to man. Then the time taken by the train to cross the
2X
L • A man rows a certain distance downstream in X hours and
man = seconds
v-u returns the same distance in Y hours. If the stream flows
• If a man is running at a speed of u m/sec in a direction opposite at the rate of Z km/h, then the speed of the man in still
to that in which a train of length L meters is running with a water is given by
speed v m/sec, then (u + v) is called the speed of the train Z(X + Y)
km / hr
relative to man. Y–X
Then the time taken by the train to cross the man • And if speed of man in still water is Z km/h then the speed
of stream is given by
L
= seconds. Z(Y – X)
v+u km / hr
X+Y
EBD_7203
S1-90 GENERAL APTITUDE FOR GATE

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

HINTS & SOLUTIONS


1. (b) Let the distance between the two stations be x km. 6. (d) Part of the tank filled by the three pipes working

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.

1 Then, the distance up to 12th pole = 11 x m


41. (b) X’s one day’s work = th work .
15
11x
Speed = m/s
24
1 1 1
Y’s one day’s work = + 50% of = th work
Time taken to covers the total distance of 19x
15 15 10

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 û

112 32 4 ´ 5 é10 – (–5) ù [Here, –ve sign indicates


+ = 8 hrs. d=
15 60 60 êë 5 – 4 úû before the schedule time]

Þ d = 5 km
1
\ due to leakage, filled part in one hour =
8

\ part of cistern emptied, due to leakage in one hour


TIME AND WORK & SPEED AND DISTANCE S1-99
(47-48)
8500
Let the speeds of train A and B be VA and VB respectively. Þ 500 x =
3

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

part filled by A in x min + part filled by B in (x – 1) min +


1
part filled by C in (x – 2)min = 1 =
30 ´10

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


Þ + + =1
3 4 6 skilled and 5 unskilled

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

2800 = 4n + e 53. (c)

where, n = normal 54. (b) First taken sum

3000 = 10n + e Arrange the multiple of 10

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)

RATIO 7. If we have two equations containing three unknowns as


Ratio is strictly a mathematical term to compare two similar quan- a1x + b1y + c1z = 0 and ... (i)
tities expressed in the same units. a2x + b2y + c2z = 0 ... (ii)
The ratio of two terms ‘x’ and ‘y’ is denoted by x : y. then, the values of x, y and z cannot be resolved without
The numerator of the ratio is called the antecedent (x) and the having a third equation.
denominator is called the consequent (y) of the ratio.
However, in the absence of a third equation, we can find
Comparison of two or more ratios
Two or more ratios may be compared by reducing the equivalent the proportion x : y : z.
fractions to a common denominator and then comparing the This will be given by
magnitudes of their numerator. b1c2 – b2c1 : c1a2 – c2a1 : a1b2 – a2b1.
Compound ratio : Ratios are compounded by multiplying together To divide a given quantity into a given ratio.
the antecedents for a new antecedent and the consequents for Suppose any given quantity a, is to be divided in the ratio
a new consequent. m : n.
Let one part of the given quantity be x then the other part will
a´c be a – x.
The compound of a : b and c : d is , i.e., ac : bd.
b´d • In any 2-dimensional figures, if the corresponding sides
PROPERTIES are in the ratio x : y, then their areas are in the ratio
x2 : y2.
a c b d • In any two 3-dimensional figures, if the corresponding
1. If = then = , i.e., the inverse ratios of two
b d a c sides are in the ratio x : y, then their volumes are in the
equal ratios are equal. The property is called Invertendo. ratio x3 : y3.
• If the sum of two numbers is A and their difference is
a c a b a, then the ratio of numbers is given by A + a : A – a.
2. If = then = , i.e., the ratio of antecedents and
b d c d
PROPORTION
consequents of two equal ratios are equal. This property
is called Alternendo. When two ratios are equal, the four quantities composing them
are said to be in proportion.
a c a +b c+d
3. If = , th en = . This property is
b d b d a c
If = , then a, b, c, d are in proportions.
called Componendo. b d

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

Some Examples : Quantity of a b - d


=
Quantity of b d - a
1. More men, less time
2. Less men, more hours Price of the Mixture :
3. More speed, less taken time to be covered distance • When quantities Qi of ingredients Mi’s with the cost Ci’s
are mixed then cost of the mixture Cm is given by
PARTNERSHIP
A partnership is an association of two or more persons who invest å Ci Q i
Cm =
their money in order to carry on a certain business. å Qi
A partner who manages the business is called the working partner Alligation Rule for Compound Mixture : Remember that in
and the one who simply invests the money is called the sleeping compound mixture, same mixtures i.e. mixtures of same
partner. ingredients are mixed together in different proportion to make
Partnership is of two kinds : a new mixture.
(i) Simple (ii) Compound. Let Mixture 1 has ingredients A and B in ratio a : b
Simple partnership : If the capitals is of the partners are invested and Mixture 2 has ingredients A and B in ratio x : y.
for the same period, the partnership is called simple. Now, M unit of mixture 1 and N unit of mixture 2 are mixed to
Compound partnership : If the capitals of the partners are invested form compound mixture. Then, in the resultant mixture, the
for different lengths of time, the partnership is called compound. ratio of A and B is
• If the period of investment is the same for each partner, then
æ a ö æ x ö
the profit or loss is divided in the ratio of their investments. Mç ÷ + Nç ÷
Quantity of ingredient A q A èa+bø è x+ yø
If A and B are partners in a business, then (i) = =
Quantity of ingredient B q B æ b ö æ y ö
Loss of A
Mç ÷ + Nç ÷
Investment of A Pr ofit of A
= or = èa+bø è x+ yø
Investment of B Pr ofit of B Loss of B
RATIO & PROPORTION, PARTNERSHIP & MIXTURE (ALLIGATIONSS1-103
)
And, Removal and Replacement
qA (i) Let a vessel contains Q unit of mixture of ingredients A and
Quantity of A in resultant mixture = ´ (M + N) B. From this, R unit of mixture is taken out and replaced by
qA + q B
an equal amount of ingredient B only.
qB If this process is repeated n times, then after n operations
Quantity of B in resultant mixture = ´ (M + N)
qA + q B n
Quantity of A left æ Rö
(ii) When qA and qB are known and M and N have to be found = ç1 - ÷
Quantity of A originally present è Q ø
out
and Quantity of B left = Q – Quantity of A Left
(ii) Let a vessel contains Q unit of ingredient A only. From this
æ x ö æ qA ö
ç ÷-ç ÷ R unit of ingredient A is taken out and replaced by an equal
Quantity of mixture 1 Q1 è x + y ø è q A + q B ø amount of ingredient B.
= =
Quantity of mixture 2 Q2 æ q A ö æ a ö If this process is repeated n times, then after n operations,
ç ÷-ç ÷
è qA + qB ø è a + b ø n
æ Rö
Quantity of A left = Q ç1 - ÷
And, è Qø
Quantity of mixture 1 Quantity of B = 1 – Quantity of A left
Q1 NOTE : A mixture contains A and B in the ratio a : b. If x litres of
= × Quantity of resultant mixture B is added to the mixture, A and B become in the ratio
Q1 + Q 2
ax
Quantity of mixture 2 a : c. Then the quantity of A in the mixture is given by
c-b
Q2 bx
= × Quantity of resultant mixture and that of B is given by .
Q1 + Q 2 c-b
EBD_7203
S1-104 GENERAL APTITUDE FOR GATE

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

Ratio of male to female students


3.5
[GATE 2013, 2 Marks]
3
(a) 16,500 (b) 15,180
(c) 11,000 (d) 10,120 2.5
53. The table below has question-wise data on the performance 2
of students in an examination. The marks for each question
1.5
are also listed. There is no negative or partial marking in the
examination. [GATE 2014, Set-3, 1 Mark] 1
0.5
A ns wered A ns wered Not
Q No. M arks 0
Correctly W rong ly A ttempted
1 2 21 17 6 2008 2009 2010 2011 2012
2 3 15 27 2
[GATE 2014, Set-3, 2 Marks]
3 2 23 18 3
(a) 1: 1 (b) 2 : 1
What is the average of the marks obtained by the class in (c) 1.5 : 1 (d) 2.5 : 1
the examination?
(a) 1.34 (b) 1.74
(c) 3.02 (d) 3.91
EBD_7203
S1-108 GENERAL APTITUDE FOR GATE

HINTS & SOLUTIONS


1. (a) Let the prices of two houses A and B be ` 4x and
3
` 5x, respectively for the last year. 6. (d) The number of police involved = ´ 135 = 81
Then, the prices of A this year = ` (1.25 × 4x) and 5
that of B = `(5x + 50,000) \ Required number of supporters = 81 ´ 9 = 729
This year, Ratio of their prices = 9 : 10 7. (d) Tonic = 30 litres, Water = 10 litres
10 + x 2
1.25 ´ 4x 9 Let x litres of water be added, then =
\ = 40 + x 7
5x + 50,000 10
Þ 70 + 7x = 80 + 2x Þ 5x = 10 Þ x = 2 litres.
Þ 50x - 45x = 450000 Þ 5x = 4,50,000 8. (a) Volume of the cube = 10 × 10 × 10 = 1000 cm3
Þ x = 90,000
1000
Hence, the price of A last year was Area of the sheet = = 2000cm 2
4x = ` 3,60,000 0.5
2. (b) Ratio of investment Let the sides be x and 5x.
= 3500 : 4500 : 5500 = 35 : 45 : 55 = 7 : 9 : 11 Þ x ´ 5x = 2000 Þ 5x 2 = 2000
Since, Ratio of investment is same as ratio of profit.
Þ x2 = 400 Þ x = 20 cm
\ Ratio of profit = 7 : 9 : 11
\ Sides are 20 cm and 100 cm
Now, profit = `405
9. (c) Let the ages of two persons be X and Y respectively
7 X 5 X – 16 3
\ A’s share = ´ 405 =` 105 \ = and =
27 Y 7 Y – 16 5
3. (a) Let us work with the options. On solving we get X = 40, Y = 56.
For (a), total cost = 7 ´ 480 + 2 ´130 = 3620
5
For (b), total cost = 7 ´ 480 + 3 ´130 = 3750 10. (b) In the mixture, milk = ´ 28 = 20 litres, and
7
For (c), total cost = 2 ´ 480 + 7 ´130 = 1870
Hence, option (a) is correct. 2
Water = ´ 28 = 8 litres
4. (b) Let x and y be two containers. 7
Ratio of milk to water in container x = 5: 1 2 ltrs of water is added, Hence the new ratio of
and ratio of milk to water in container y = 7 : 2
It is given that quantity of milk should be 80% in new Milk 20 20
= = = 2 :1
mixture. This means that quantity of water will be 20% Water 8 + 2 10
that quantity of water will be 20% 11. (b) Water Milk Total.
\ Ratio of milk to water in new mixture =80 : 20 = 4:1. 1st vessel 6 7 13
2nd vessel 5 9 14
5 7 1 2y
\ x+ y: x+ = 4 :1 3rd vessel 8 7 15
6 9 6 9 LCM of 13, 14 & 15 = 2730
Increase value of total to 2730 as follows.
5x 7y
+ 1st vessel 1260 1470 2730
Þ 6 9 =4 2nd vessel 975 1755 2730
x 2y 1
+ 3rd vessel 1456 1274 2730
6 9 Total 3691 4499 8190
15x + 14y 4 \ Required ratio =
3691
Þ = Þ 15x + 14y = 12x + 16y
3x + 4y 1 4499
Alternate method is dividing options by 13, 14 & 15.
Þ 3x = 2y Þ x : y = 2 : 3
5. (a) Let Sanjay invest ` x in the business. 12. (d) Milk Water
To start with 40 litres
Since, at the end of the year Rahul and Sanjay both get
After 1st operation 36 litres 4 litres
equal amount as profit
4 4
Then, 8000 ´ 12 = 1
After 2nd operation 36 – ×36 4– ×4+4
40 40
x´6 1
= 32.4 litres = 4 – 0.4 + 4
\ x = ` 16, 000 = 7.6 litres
RATIO & PROPORTION, PARTNERSHIP & MIXTURE (ALLIGATIONSS1-109
)

[ (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 !

B A 2. Number of permutations of n things taking r at a time, in


A B E n -1
C which a particular thing never occurs = Pr .
3. Number of permutations of n different things taking all at a
E C D time, in which m specified things always come together
D
(iv) (v) = m!(n - m + 1)! .
4. Number of permutations of n different things taking all at a
we see that arrangements in all figures are same. time, in which m specified things never come together =
\ The number of circular permutations of n different things
n!- m!(n - m + 1)!
n
Pn 5. The number of permutations of 'n' things taken all at a time,
taken all at a time is = (n – 1) !, if clockwise and
n when 'p' are alike of one kind, 'q' are alike of second, 'r' alike
anticlockwise orders are taken as different. n!
(ii) Arrangements of beads or flowers (all different) around a of third, and so on = .
p! q! r!
circular necklace or garland:
Consider five beads A, B, C, D and E in a necklace or five 6. The number of permutations of 'n' different things, taking 'r'
flowers A, B, C and D, E in a garland etc. If the necklace or at a time, when each thing can be repeated 'r' times = nr
EBD_7203
S1-114 GENERAL APTITUDE FOR GATE
COMBINATION 7. The number of ways of dividing 'm + n' things into two
Each of the different selections that can be made with a given groups containing 'm' and 'n' things respectively
number of objects taken some or all of them at a time is called a (m + n)!
combination. = m + nCm nC
n
=
m!n!
• The number of combinations of 'n' dissimilar things taken 'r'
at a time is denoted by nCr or C(n, r). It is defined as, PROBABILITY
n! Random Experiment : It is an experiment which if conducted
nC =
r r!(n - r)! repeatedly under homogeneous condition does not give the same
result.
NOTE :
• The total number of possible outcomes of an experiment in
n
• C0 = 1, n Cn = 1 ; n Pr = r! n C r any trial is known as the exhaustive number of events.
For example
n
• C r = n Cn -r In throwing a die, the exhaustive number of cases is 6 since
any one of the six faces marked with 1, 2, 3, 4, 5, 6 may come
• n
C r -1 + n C r = n +1C r uppermost.
• nC = nC Þ x + y = n
x y • Events are said to be mutually exclusive if no two or more
• nC = nC = n+1C
r r+1 r of them can occur simultaneously in the same trial.
n For example,
• nC = . n–1C In tossing of a coin the events head (H) and tail (T) are
r r r–1
mutually exclusive.
nC =
1 • The favourable cases to an event are the outcomes, which
• r (n – r + 1) nCr–1 entail the happening of an event.
r
• nC = nC For example,
1 n–1 = n
In the tossing of a die, the number of cases which are
Conditional Combinations favourable to the “ appearance of a multiple of 3” is 2, viz, 3
1. Number of combinations of n distinct things taking r (£ n ) and 6.
• Events are said to be independent if the happening (or non-
at a time, when k (0 £ k £ r) particular objects always occur happening) of one event is not affected by the happening
n -k or non-happening of others.
= C r -k .
Classical definition of probability
2. Number of combinations of n distinct objects taking r(£ n)
If there are n-mutually exclusive, exhaustive and equally likely
at a time, when k (0 £ k £ r) particular objects never occur outcomes to a random experiment and ‘m’ of them are favourable
to an event A, then the probability of happening of A is denoted
= n -k
Cr .
m
by P (A) and is defined by P(A) = .
3. Number of selections of r things from n things when p n
particular things are not together in any selection
No. of elementary events favourable to A
= nCr – n – pCr – p P (A) =
Total no. of equally likely elementary events
4. Number of selection of r consecutive things out of n things
in a row = n – r + 1 m
Obviously, 0 £ m £ n , therefore 0 £ £ 1 so that
n
5. Number of selection of r consecutive things out of n things
along a circle 0 £ P(A) £ 1.
P(A) can never be negative.
ìn, when r < n • Since, the number of cases in which the event A will not

î1, when r = n happen is ‘n – m’, then the probability P ( A ) of not
6. The number of Combinations of 'n' different things taking happening of A is given by
some or all at a time
n-m m
P(A) = = 1 - = 1 - P(A)
n n n n n
= C1 + C 2 + C 3 + .............. + C n = 2 - 1 n n

Þ 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ø

(iii) The event “ Not - A” denoted by A , which occurs of A relative to B.


when and only when A does not occur. Thus æ A ö P(A Ç B) æ B ö P(A Ç B)
Also, P ç ÷ = and P ç ÷ =
P(A ) = Probability of non-occurrence of the event A. è Bø P(B) è Aø P(A)

(iv) A Ç B denotes the “ non-occurrence of both A and B”. Multiplication theorem


(v) “A Ì B” denotes the “ occurrence of A implies the If A and B are two events, then
occurrence of B”.
P(A Ç B) = P (A) P (B/A), if P (A) > 0
Addition Theorem on probability
= P (B) P (A/B) if P (B) > 0
1. Addition Theorem : If A and B are two events associated
From this theorem we get
with a random experiment, then
P(A È B) = P(A) + P(B) - P(A Ç B) P ( A Ç B) P(A Ç B)
P( B / A) = and P(A / B) =
2. Addition theorem for three events : If A, B, C are three P( A ) P(B)
events associated with a random experiment, then If A and B are two independent events, then
P(A È B È C) = P(A) + P(B) + P(C) - P(A Ç B) P(A / B) = P(A) and P(B / A) = P(B) and
- P(B Ç C) - P(A Ç C) + P(A Ç B Ç C)
therefore P(A Ç B) = P(A )P(B)
EBD_7203
S1-116 GENERAL APTITUDE FOR GATE

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

(a) 0.2 (b) 0.1 (c) 4 ç ÷ç ÷ (d) None of these


è 5 øè 5 ø
(c) 0.06 (d) 0.25
4. A bag contains 2 red, 3 green and 2 blue balls. 2 balls are to 10. There are three prizes to be distributed among five students.
be drawn randomly. What is probability that the balls drawn If no student gets more than one prize, then this can be
contain no blue ball ? done in :
5 10 (a) 10 ways (b) 30 ways
(a) (b)
7 21 (c) 60 ways (d) 80 ways
11. Two dice are tossed. The probability that the total score is a
2 11
(c) (d) prime number is :
7 21
5. The letters B, G, I, N and R are rearranged to form the word (a)
1 5
(b)
‘Bring’. Find its probability. 6 12
1 1 1 7
(a) (b) (c) (d)
120 54 2 9

1 5 2 12. There are 6 positive and 8 negative numbers. Four numbers


(c) (d) ´4
24 5 are chosen at random and multiplied. The probability that
the product is a positive number is:
7
6. If the probability that A will live 15 years more is and that
8 500 503
(a) (b)
1001 1001
9
B will live 15 years more is , then what is the probability
10 505 101
(c) (d)
that both will survive after 15 years? 1001 1001
1 63 13. In an examination paper there are two sections each
(a) (b)
20 80 containing 4 questions. A candidate is required to attempt 5
1
questions but not more than 3 questions from any particular
(c) (d) None of these section. In how many ways can 5 questions be selected ?
5
(a) 24 (b) 48
7. A box contains 6 white balls and 7 black balls. Two balls are
drawn at random. What is the probability that both are of (c) 96 (d) None of these
the same colour ? 14. A brother and sister appear for an interivew against two
vacant posts in an office. The probability of the brother’s
5 6
(a) (b) 1
13 13 selection is 1 and that of the sister’s selection is . What
5 3
7 6
(c) (d) is the probability that one of them is selected ?
13 7
PERMUTATION AND COMBINATION & PROBABILITY S1-117

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

to destroy half of the body mass in


1000

(milligrams of microbe required


that all are white ? P (50 mm)
800
1 1
(a) (b)
256 16

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

HINTS & SOLUTIONS


1. (c) Required probability 8. (a) Let there be n teams participating in the championship.
= Probability that a ball from bag A is red and both the Then, total no. of matches = nC2 = 153
balls from bag B are black + Probability that ball from n! 1
bag A is black and one black and one red balls are or = ( n –1) ´ n = 153
2!(n – 2)! 2
drawn from bag B
or n2 – n – 306 = 0 or (n – 18) (n + 17) = 0
4 7 5
C C C 3 C1 ´ 7 C1 or n = 18 [ n ¹ - ve]
= 9 1 ´ 10 2 + 9 1 ´ 10
C1 C2 C1 C2 1
9. (c) Probability of a student being not a swimmer =
5
4 7 5 7 7
= ´ + ´ = Probability of a student being a swimmer
9 15 9 15 15
2. (c) Number of elements in the sample space æ 1ö 4
= ç1 – ÷ =
= 6 × 6 = 36 è 5ø 5
The sample space is given by 4
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6) Required probability = 5 C4 ´ æç 1 ÷ö æç 4 ö÷
(2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6) è 5ø è 5ø
······························· 10. (c) It is a question of arrangement without repeatitions.
······························· Required no. of ways = 5 × 4 × 3 = 60
······························· 11. (b) Total no. of outcomes when two dices are thrown = n
(6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6) (S) = 36 and the possible cases for the event that the
3. (c) Required probability sum of numbers on two dice is a prime number, are
= P (A) × P (B) = 0.2 × 0.3 = 0.06 (1, 1), (1, 2), (1, 4), (1, 6), (2, 1), (2, 3), (2, 5), (3, 2), (3, 4),
4. (b) 2 balls can be drawn in the following ways (4, 1), (4, 3), (5, 2), (5, 6), (6, 1), (6, 5)
1 red and 1 green or 2 red or 2 green Number of outcomes favouring the event = n (A) = 15
2 n ( A) 15 5
C1 ´3 C1 2
C2 3
C2 Required probability = = =
Required probability = 7
+
7
+
7 n(S ) 36 12
C2 C2 C2
12. (c) Total no. of numbers = 6 positive + 8 negative = 14
6 1 3 10 Þ n(S) = 14C4
= + + =
21 21 21 21 The product of four numbers could be positive when,
5. (a) There are a total 5 letters. The probability that B gets (a) all the four numbers chosen are positive or
(b) all the four numbers chosen are negative or
1 (c) two of the chosen numbers are positive and two
first position is . The probability that R gets second
5 are negative.
1 6 8 6
position is . C4 C4 C2 ´ 8C2 505
4 Required Prob. = 14 + 14 + 14 =
Working as same, probabilities for I, N and G are C4 C4 C4 1001
1 1 1 13. (b) Under the given restrictions, 5 questions can be
, , , respectively.. selected in the following ways :
3 2 1
2 questions from the first section and 3 questions from
Hence, the required probability the second section
1 1 1 1 1 1 or
= ´ ´ ´ ´ =
5 4 3 2 1 120 3 questions from the first section and 2 questions from
the second section.
7 9 63
6. (b) Required Prob. = ´ = Required no. of ways = 4C2 × 4C3 + 4C3 × 4C2
8 10 80 = 24 + 24 = 48
7. (b) Two white balls can be selected in the following ways 14. (b) One of them can be selected in the following ways.
Both the balls are white Brother is selected and sister is not selected.
or or
Both the balls are black Brother is not selected and sister is selected.
Hence, the required probability
Required probability = 1 ´ 2 + 4 ´ 1
6
C2 7
C2 15 21 36 6 5 3 5 3
= + = + = =
13 13 78 78 78 13 2 4 6 2
C2 C2 = + = =
15 15 15 5
PERMUTATION AND COMBINATION & PROBABILITY S1-121
15. (c) In MATHEMATICS, the consonants M and T are 20. (b) Total number of possible arrangements for 4 boys and
repeated two times each. 3 girls in a queue = 7!
Also the vowel A is repeated two times. When they occupy alternate positions the arrangement
Since there are four vowels, A, A, E and I; A being would be like
B G B G B G B
4
repeated, therefore vowels can be arranged in Thus, total number of possible arrangements
2
= 12 ways. 4´ 3´ 2 3´2
= ´
Now remaining 7 consonants, with M, T being repeated, For boys For girls
7 4 ´ 3´ 2 ´ 3´ 2
can be written in = 7 × 6 × 5 × 3 × 2 = 1260 ways. Required probability =
2´ 2 7!
Now four vowels together can take any of the 8 places
as shown below: 4 ´ 3´ 2´ 3´ 2 1
= =
VC VC VC VC VC VC VC V 7 ´ 6 ´ 5 ´ 4 ´ 3 ´ 2 35
\ Total number of ways in which the letters of the 21. (c) There are 55 girls and 45 boys in the college.
word MATHEMATICS can be arranged such that Out of 45 boys, 36 are studying Statistics and 9 are not
vowels always come together = 1260 × 8 × 12 = 120960. studying statistics.
\ The probability that a boy picked up at random is
1 4 1 6 10 2
16. (b) Required Probability = ´ + ´ = = 9 1
7 5 5 7 35 7 not studying Statistics = = .
17. (d) Chance of selecting an eleven out of 15 members 45 5
(including 5 bowlers) such that atleast 3 bowlers are 22. (d) The required probability
included 5
C2 + 4C2 10 + 6 16 4
10
C8 ´ 5C3 + 10C7 ´ 5C4 +10 C6 ´ 5C5 = 9
= = =
= C2 36 36 9
15
C11 23. (b) India will play 2 match with West Indies & Australia
10 5 10 5 10 \ India will play 4 match
C2 ´ C2 + C3 ´ C1 + C4 ´ 1 Now, given , Prob (getting 0) = 0.45,
= 15
C4 Prob (getting 1) = 0.05 and
Prob (getting 2) = 0.50
45 ´ 10 + 120 ´ 5 + 210 1260 12 Now, to getting at least 7 points, we have two favourable
= = =
1365 1365 13 cases.
18. (a) 6 men can be sit by 5! ways and on remaining 6 seats, \ Total favourable no. of Cases
5 women can sit by 6C5 ways . = P(2) + P(2) + P(2) + P(1)
\ Required number of ways = 5! × 6P5 = 6! × 5! = 3(0.50)+ 0.05 = 1.55
and total no. of favourable cases in Case - II
M1
= P(2) + P(2) + P(2)+ P(2) = 4[P(2)] = 4 ´ 0.5 = 2
W5
\ Required Prob = Prob in Case I + Prob in Case II
1.55 2 3.55
M6 M2 = + = = 0.8875
4 4 4
2
C1 ´ 3C1 ´ 4C1
W4 W1 24. (d) Required probability =
9
C3

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

38. (c) We have P(A È B) = 0.7 and P(A Ç B) = 0.2 1 1


\ £p£
2 2
Now, P(A È B) = P(A) + P(B) - P(A Ç B) [The intersection of above four intervals]
Þ P(A) + P(B) = 0.9 Þ 1 - P( A) + 1 - P( B) = 0.9 1
\p =
Þ P(A ) + P( B) = 1.1 2
39. (b) Only one of A and B can be alive in the following, 43. (a) Let A, B and C be the events that the student is
mutually exclusive ways. successful in tests I, II and III respectively.
E1 A will die and B will live Then P (The student is successful)
E2 B will die and A will live = P(A) P(B){1 - P(C)} + P(A){1 - P(B)}P(C) +
So, required probability = P(E1) + P (E2)
P(A)P(B)P(C)
= p(1 - q) + q (1 - p) = p + q - 2pq.
æ 1ö 1 1
40. (a) \ S = {1, 2, 3, 4, 5, 6} ´ {1, 2, 3, 4, 5, 6} = p . q ç1 - ÷ + p(1– q) +p.q
è 2 ø 2 2
\ n (S) = 36
& Let E1 º the event that the sum of the numbers 1 1 1
= pq + p (1 - q ) + pq
coming up is 9. 2 2 2
& E2 º the event of occurrence of 5 on the first die.
1 1
E1 º {(3, 6), (6, 3), (4, 5), (5, 4)} = (pq + p - pq + pq) = (pq + p)
2 2
\n(E1 ) = 4 and
1 1
E 2 = {(5,1), (5, 2), (5, 3), (5, 4), (5, 5), (5, 6)} \ = (pq + p) Þ 1 = pq + p
2 2
\ n (E 2 ) = 6
44. (a) Since P(A È B È C) ³ 0.75 , therefore
E1 Ç E 2 = {(5, 4)} \ n (E1 Ç E 2 ) = 1
0.75 £ P(A È B È C) £ 1
n (E1 Ç E 2 ) 1 Þ 0.75 £ P(A ) + P(B) + P(C) - P(A Ç B) - P(B Ç C) -
Now, P(E1 Ç E 2 ) = =
n (S) 36
P(A Ç C) + P(A Ç B Ç C) £ 1
n (E 2 ) 6 1
and P(E 2 ) = = = Þ 0.75 £ 0.3 + 0.4 + 0.8 - 0.08 - P(B Ç C) -
n (S) 36 6
\ Required Probability 0.28 + 0.09 £ 1
Þ 0.75 £ 1.23 - P(B Ç C) £ 1
1
æ E1 ö P (E1 Ç E 2 ) 36 1 Þ - 0.48 £ -P(B Ç C) £ -0.23
= Pçç ÷÷ = = =
è E2 ø P( E 2 ) 1 6 Þ 0.23 £ P(B Ç C) £ 0.48.
6
45. (a) Since, A and B are independent events.
41. (b) A and B will contradict each other if one of the events
A Ç B' or A'ÇB occurs. The probability of this \P(A Ç B) = P(A )P(B)
happening is Further since, A Ç C, B Ç C, A Ç B Ç C are subsets
P[(A Ç B' ) È (A'ÇB) = P(A Ç B' ) + P(A'ÇB) of C, we have
= P(A)P(B' ) + P(A )P(B), P(A Ç C) £ P (C) = 0
EBD_7203
S1-124 GENERAL APTITUDE FOR GATE
Favourable cases, x B1y B2 z B3 t
P(B Ç C) £ P(C) = 0
If x, y, z and t be the number of white balls to be places
and P(A Ç B Ç C) £ P(C) = 0 as shown above then 0 £ x, t £ 5 1 £ y, z £ 6
Þ P(A Ç C) = 0 = P(A)P(C) \ number of favourable cases
= coefficient of x7 in (1 + x +x2 +....+x5)2 (x + x2 + ...+x6)2
P(B Ç C) = 0 = P(B)P(C) = coeff. of x7 in x2 (1 + x + x2 +...+ x5)4
P(A Ç B Ç C) = 0 = P (A)P(B)P(C) . æ 1- x 6 ö
4

Clearly A, B, C are pairwise independent as well as = coeff. of x in çç


5 ÷
÷
è 1- x ø
mutually independent. Thus, A,B,C are independent
events. = coeff. of x5 in (1 – x)–4 = 8C5 = 56
46. (b) No. of ways in which a sum of 10 or more than 10 is : 56 7
\ Desired probability = =
(4, 6), (5, 5), (5, 6), (6, 4), (6, 5), (6, 6) 120 15
Number of favourable cases = 6 51. (c) Case 1 : First digit = 3 Þ 3...
Total number of cases = 36 Rest 3 digits may by combination of
234 ® 3!
6 1
\ Probability = = 223 ®3!/2!
36 6 224®3!/2!
47. (a) Total number of balls = 5 + 7 + 8 = 20 332 ® 3!/2!
Probability that the first ball drawn is white 334 ® 3!/2!
5
C1 1 442 ® 3!/2!
= 20
= 443 ® 3!/2!
C1 4
444 ® 1
If balls are drawn with replacement, all the four events \ Total combinations = 25
will have equal probability. Case 2 : First digit = 4 Þ 4...
Therefore, required probability Rest 3 digits may be combination of
1 1 1 1 1 234 ® 6
= ´ ´ ´ = 223 ® 3
4 4 4 4 256
224 ® 3
48. (c) Probability of occurence of head in a toss of a coin is
332 ® 3
1/2.
334 ® 3
Required probability = Prob[Head appears once] + 442 ® 3
Prob.[Head appears thrice] + Prob.[Head appears five 443 ® 3
times] 444 ® 1
5 5 5 333 ® 1
æ1ö æ1ö æ1ö
= 5C1 ç ÷ + 5C3 ç ÷ + 5 C5 ç ÷ \ Total combinations = 26
è2ø è2ø è2ø \ Required answer = 25 + 26 = 51
52. (d) By observation of the table, we can say S
5
æ1ö 16 1
= ç ÷ [5 + 10 + 1] = = P Q R S
2
è ø 32 2
Requirement 800 600 300 200
49. (a) P (A È B) = P (A) + P (B) – P (A Ç B);
Potency 0.4 0.5 0.4 0.8
3 1
Þ =1 – P( A ) + P(B) – 53. (b) X Y
4 4
Supply 60% 40%
2 2 Reliable 96% 72%
Þ 1 = 1 – 3 + P(B) Þ P(B) = 3 ; Overall 0.576 0.288
0.288
2 1 5 \ P(X) = = 0.334
Now, P( A Ç B ) = P(B) – P ( A Ç B ) = – = . 0.576 + 0.288
3 4 12
54. (d)
50. (b) Total number of ways of arranging the balls
10!
= = 120
3! 7!
SECTION-2 : ENGINEERING MATHEMATICS

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

22. [P ® Q Û (Ø Q ® Ø P) An argument p1, p2, ...pn q is true provided q is true


^

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

(b) "x : gold ( x ) Þ glitters( x )


EBD_7203
S2-6 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

1. For the following statements: where E(x) : x is an even number


D(x) : x is divisible by 2
(i) $x , x 2 = 1 (ii) "x,| x |= x
5. (i) p Ú ~ p is a tautology
(iii) $x, x + 4 = x (ii) ( p ® q) « (~ p Ú q )
Which of the following is correct ? Which of the following is true ?
(a) (i) is true; (ii) and (iii) are false (a) (i) true, (ii) false (b) (i) false, (ii) true
(b) (i) and (ii) are true; (iii) is false (c) (i) true, (ii) true (d) (i) false, (ii) false
(c) (i) and (iii) are true; (ii) is false 6.
(d) None of these
(i) p ® (q ® r ) Û p ® (~ q Ú r ) Û ( p Ù q) ® r
2. Given P = {2, 3, 4, 5, 6}, and the statements :
(i) ("x Î P )( x + 3 < 10) (ii) ("x Î P )( x + 2 £ 7) (ii) [~ p Ù (~ q Ù r )] Ú (q Ù r ) Ú ( p Ù r ) Û r
Which of the following is true ?
(iii) ($x Î P)( x + 3 = 10) (iv) ($x Î P)( x + 2 < 7)
(a) (i) true, (ii) false (b) (i) false, (ii) true
Which of the following is true (c) (i) true, (ii) true (d) (i) false, (ii) false
(a) (i) true, (ii) false, (iii) true, (iv) false 7. Which of the following are tautologies?
(b) (i) true, (ii) false, (iii) false, (iv) true (a) ((P Ú Q) Ù Q) « Q
(c) (i) true, (ii) true, (iii) false, (iv) false (b) (P Ú (P ® Q)) ® P
(d) (i) false, (ii) true, (iii) true, (iv) false (c) ((P Ú Q) Ù P) ® Q
3. Negative of "x, x 2 = x is (d) ((P Ú Q) Ù P) ® Q
(a) x2 = x (b) x = – x2 8. What can we correctly say about proposition P1:
2
(c) x ¹ x (d) None P1 : (p Ú q) Ù (q ® r) Ú (r Ú p)
4. Symbolise expression of “every even number is divisible (a) P1 is tautology
by 2,” using quantifier is
(b) P1 is a contradiction
(a) ("x)[ E ( x ) ® D( x )] (b) ("x)[ D( x ) ® E ( x )] (c) If p is true and q is false and r is true, then P1 is true
(c) ("x)[ D( x ) ®
/ E ( x )] (b) None (d) If p is true and q is true and r is false, then P1 is true
MATHEMATICAL LOGIC S2-7

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

Also as given exactly two of p, q and r are to be true, so we


3. (c) ~ "x, x 2 = x º "x ~ ( x 2 = x) º "x, x 2 ¹ x
need to consider only three combinations as above.
We see that only option (B) (~ (p « q) Ù r) Ú (p Ù qÙ ~ r) 4. (a) E ( x) : x is an even number ; D ( x) : x is divisible by 2.
is true in all three cases when exactly two of p, q and r are
("x )[ E ( x ) ® D( x)]
true.
15. (d) g : mobile in good 5. (c)
c : mobile in cheap. (i) The truth table is
P : Good mobile phones are not cheap
» g ® Øc » (Øg Ú Øc) p ~q pÚ ~ p
Q : cheap mobile phones are not good 1 0 1
» c ® Øg » (Øc Ú Øg) 0 1 1
\ Both P and Q are equivalant
\ L, M and N are correct Hence pÚ ~ p is a tautology..
16. (d) (ii) The truth table is
PRACTICE EXERCISE
1. (a) p q p ® q ~ p ~ p Ú q ( p ® q ) « (~ p Ú q )
1 1 1 0 1 1
(i) If x0 = 1 , then x0 2 = 1 , therefore the given statement
1 0 0 0 0 1
is true. 0 1 1 1 1 1
(ii) If x0 = -3 , then | x0 |¹ x0 , therefore the given 0 0 1 1 1 1
statement is false.
(iii) As there is no solution to x + 4 = x , the given Hence ( p ® q) « (~ p Ú q) is true.
statement is false.
6. (c)
2. (b)
(i) By conditional equivalence q ® r Û ~ q Ú r
(i) True, for each number in P satisfies x + 3 < 10
Replacing q ® r by ~ q Ú r , we get p ® (~ q Ú r )
(ii) False, for if x0 = 6 , then x0 + 2 is not £ 7
which is equivalent to ~ p Ú (~ q Ú r ) by the same rule.
(iii) False, for no number in P is a solution to x + 3 = 10

(iv) True, for if x0 = 2 then x0 + 2 < 7 is a solution.


EBD_7203
S2-10 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

Thus ~ p Ú (~ q Ú r ) Û (~ pÚ ~ q) Ú r 7. (a) ((P Ú Q) Ù Q) « Q


(P + Q) · Q
Û ~ ( p Ù q) Ú r
PQ + Q
Û ( p Ù q) ® r Q. (P + 1)
Q
(ii) [~ p Ù (~ q Ù r )] Ú (q Ù r ) Ú ( p Ù r )
8. (c) (p Ú q') Ù (q' + r) Ú (r Ú p)
Û [~ p Ù (~ q Ù r )] Ú (q Ú p) Ù r (p + q'). (q' + r) + (r + p)

Û [~ p Ù ~ q Ù r )] Ú (q Ú p) Ù r pq' + pr + q' + rq' + r + p


q' + r + rq' + p
Û [~ ( p Ú q) Ù r )] Ú (q Ú p) Ù r q' + r + p
Û [~ ( p Ú q) Ú ( p Ú q)] Ù r
Û 1Ù r Û r
2 Probability
INTRODUCTI ON Baye’s Theorem
Probability is the measure of degree of certainity or uncertainity If B1, B2, B3,...... Bn are mutually exclusive and exhaustive random
of occurrence of an event. The set of all possible outcomes is events whose individual probabilities are greater than zero, and A
called sample space of that experiment and is denoted by S. be an event within these events. (P(A) > 0), then,
Example : æA
ö
Pç÷ . P(E i )
Sample space of tossing a coin : S = {H, T} H-head, T-tail. æB ö è Bi
ø
Pç i ÷ =
Sample space tossing 2 coins : S = {(H, H), (H, T), (T, H), (T, T)} èAø n
æAö
Sample space of following a die : S {1, 2, 3, 4, 5, 6} å P ç B ÷ P(Bi )
i =1 è i ø
Probability of an event is denoted by P(E).
0 £ P(E) £ 1 Sample Problem
Probability of sample space, P(S) = 1. There are two bags A and B having 2 white and 1 black ball
in bag A and 1 white and 3 black balls in bag B. A bag is
Notations Used in Probability chosen at random and two balls are drawn. The balls were
· Probability of happening of events A or B : P(A È B) or one white and one black ball. What is the probability that it
P(A + B). is from bag B ?
· Probability of happening of events A and B : P(A Ç B) or 1
P(AB). Sol. Probability of choosing a bag = P(A) = P(B) =
2
Mutually exclusive events Let X be probability of choosing 2 balls.
Event whose occurrences is independent of occurrence of another We have to find P(B/X)
events is said to be mutually exclusive. They don’t occur By Baye’s theorem
simultaneously i.e. A Ç B = f æXö
E.g. : tossing a coin, throwing a die. P ç ÷ . P(B)
è Bø
P(B/X) =
Equally likely events æXö æXö
P ç ÷ . P(A) + P ç ÷ . P(B)
If an event cannot happen in performance to other such events is èAø è Bø
said to be equally likely. æ ö
X
Pç ÷
Independent events èBø æ 1ö
= ç P(A) = P(B) = ÷
Two events are said to be independent if happening or failure of æXö æXö è 2ø
Pç ÷ + Pç ÷
one does not effect the happening or failure of the others. èAø èBø
2!
Exhaustive events 2 ´1 2
æXö C1 ´ 1C1 1!1! 2
Set of events which includes all possible events is said to be Pç ÷ = = =1=
exhaustive. èAø 3
C2 3! 3 3
2 !1! 1
Addition law of probability
3! 3
P(A) and P(B) are probabilities of two events A and B, then 1 3 1´
æXö C1 ´ C1 2! 1
P(A È B) = P(A) + P(B) – P(A Ç B) Pç ÷ = = =
For mutually exclusive events P(A Ç B) = 0. è Bø 4
C2 4! 3´ 4
2!2! 2
Law of total probability
3 1
If B1, B2,...... Bn are mutually exclusive events and an event A = =
occurs only if Bi occurs, then : 6 2
Probability of occurrence of A is given by 1 1
æ Bö 2 = 2
n
æAö Pç ÷ =
P(A) = å P ç ÷ P(Bi ) èXø 2 1 4+3
+
i=1 è Bi ø 3 2 6
P(A/Bi)-Probability of occurrence of A when Bi has already 1 6 3
= ´ =
happened. 2 7 7
EBD_7203
S2-12 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Conditional probability L-lower limit of median class
æ Bö
N-total frequency = S fi
P(AB) = P(A) . P ç ÷ h -width of median class.
èAø
æBö C-cumulative frequency upto class preceding median class
P ç ÷ . P(A) f -cumulative frequency of median class
æAö èAø
Pç ÷ = Mode : It is the value that occur most frequently or it is the value
è Bø P(B)
Consider one event B which occurs after occurrence of event A, with maximum frequency.
then fi - f i -1
P(B Ç A) mode = ×h
æ Bö ( fi - f i -1 ) + ( fi - fi +1 )
Pç ÷ =
èAø P(A)
L-lower limit of class certaining mode
number of elements in A Ç B
= fi-maximum frequency
no of elements in A fi–1-frequency preceding fi
æ Bö fi+1-frequency just after fi
i.e., P(B Ç A) = P(A) . P ç ÷
èAø h-size of model class
[Multiplication theorem of conditional probability]
Points to be noted
Sample Problem · For asymmetric distribution : mean = medians = mode
If a pair of die is thrown and the sum of numbers that · For normal distribution : mean – mode
appeared is 7. Find the probability that one of dice shows 3.
Sol. Total elements in sample space = 6 × 6 = 36 = 3(mean – median).
Sample spaces of occurred sum of 7;(B) = {(1, 6), (2, 5),
Sample Problem
(3, 4), (4, 3), (5, 2), (6, 1)}
Sample space of occurrence of one element as 3 = [(1, 3) 1. Find the median and mode of following data.
(2, 3) (3, 3) (4, 3) (5, 3) (6, 3), (3, 1) (3, 2) (3, 4) (3, 5), Age group 0-10 10-20 20-30 30-40 40-50
(3, 6)]
No. of people 5 7 9 6 8
(A Ç B) = {(3, 4), (4, 3)}
6 11 Age No. of Cumulative
P(B) = P(A) =
36 36 group people frequency
2 0-10 5 5
P(A Ç B) =
36 10-20 7 12
2 Sol. 20-30 9 21
æAö P(A Ç B) 36
Pç ÷ = = 30-40 6 27
è Bø P(B) 6
40-50 8 35
2 1 36
= = N = 35
6 3 Median class : 20 – 30
Mean, Median, Mode æN ö
Mean : It is the average or arithmetic mean of observed values. ç -C÷
For normal distribution, Median = L + è 2 ø´h
f
x1 + x2 + ...... xn æ 35 ö
mean x =
n ç - 12 ÷
For frequency distribution, mean = 20 + è 2 ø ´10
21
f1 x1 + f 2 x2 + ...... + f n xn = 20.62
x =
f1 + f 2 + ...... + f n Mode
n
Max frequency = a
å fi xi
\ Modal class is 20 – 30 \ a = 20
i =1
n C( fi - fi -1 )
= Mode = a +
å fi ( f i - f i -1 ) + ( fi - fi +1 )
i =1
10(9 - 7)
Median : Median is the middle term in the collected data. In case = 20 +
(9 - 7) + (9 - 6)
of even number of terms, take average of middle terms.
æN ö 10 ´ 2
çè - C÷ø = 20 + = 24
2+3
median = L + 2 ´h
f
PROBABILITY S2-13
Standard Deviation Normal Distribution
It is the square root of mean of squared of the difference of values A continuous random variable X follow normal distribution if its
from their arithmetic mean. It is denoted by s. probability density function f (x) is given by:

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

4. Which one of the following statements is not true? 1


[2005, 1 mark] æ 2nö 1
(c) (d)
(a) The measure of skewness is dependent upon the çè n ÷ø 2
amount of dispersion
(b) In a symmetric distribution, the value of mean, mode 9. There are 25 calculators in a box. Two of them are defective.
and median are the same Suppose 5 calculators are randomly picked for inspections
(c) In a positive skewed distribution mean > median > (i.e., each has the same chance of being selected), what is
mode the probability that only one of the defective calculators
(d) In a negative skewed distribution, mode > mean > will be included in the inspection? [2006, 1 mark]
median 1 1
5. Two fair dice are rolled and the sum r of the numbers (a) (b)
2 3
turned up is considered [2006, 2 marks]
1 1 1
(a) Pr (r > 6) = (c) (d)
4 5
6
ær ö 5 10. An examination consists of two papers, Paper 1 Paper 2.
(b) Pr çè is an integer ÷ø = The probability of failing in Paper 1 is 0.3 and that in paper
3 6
2 is 0.2. Given that a student has failed in Paper 2, the
æ r ö 5
(c) Pr çè r = 8 | is an integer ÷ø = probability of failing in Paper 1 is 0.6. The probability of a
4 9
student failing in both the paper is [2007, 1 mark]
æ r ö 1 (a) 0.5 (b) 0.18
(d) Pr ç r = 6 | is an integer ÷ =
è 5 ø 18 (c) 0.12 (d) 0.06
PROBABILITY S2-15
11. A loaded dice has following probability distribution of 17. If probability density function of a random variable X is
occurrences [2007, 1 mark] f ( x) = x 2 for -1 £ x £ 1 and f ( x) = 0 for any other
Dice value 1 2 3 4 5 6 æ 1 1ö
values of x, then the percentage probability P çè - £ x £ ÷ø
1 1 1 1 1 1 3 3
Probability is [2008, 1 mark]
4 8 8 8 8 4 (a) 0.247 (b) 2.47
If three identical dice as the above are thrown, the probability (c) 24.7 (d) 247
18. The standard normal probability function can be
of occurrence of values 1, 5 and 6 on the three dice is
approximated as [2009, 2 marks]
(a) same as that of occurrence 3, 4, 5
(b) same as that of occurrence 1, 2, 5 1
F(X N ) =
1 + exp(-1.7255 X N | X N |0.12 )
1 5
(c) (d) where X N = standard normal deviate, if mean of standard
128 8
12. The standard deviation of spot speed of vehicles in, a deviations of annual precipitation are 102 cm and 27 cm
highway is 8.8 km/h and the mean speed of the vehicles is respectively, the probability that the annual precipitation
will be between 90 cm and 102 cm is
33 km/h the coefficient of variation in speed is (a) 66.7% (b) 50.0%
[2007, 1 mark] (c) 33.3% (d) 16.7%
(a) 0.1517 (b) 0.1867 19. A fair coin is tossed 10 times. What is the probability that
(c) 0.2666 (d) 0.3646 only the first two tosses will yield heads? [2009, 1 mark]
13. Let X be a random variable following normal distribution 2 2
æ 1ö 10 æ 1ö
with mean +1 and variance 4. Let, Y be another normal (a) çè ÷ø (b) C2 ç ÷
variable with –1 and variance unknown, if 2 è 2ø
10 10
P ( X £ -1) = P(Y ³ 2), the standard deviation of Y is æ 1ö 10 æ 1ö
(c) çè ÷ø (d) C2 ç ÷
(a) 3 (b) 2 [2008, 2 marks] 2 è 2ø
(c) 2 (d) 1 20. An unbalanced dice (with 6 faces, number from 1 to 6) is
thrown. The probability that the face value is odd is 90% of
14. A person on a trip has a choice between private car and the probability that the face value is even. The probability
public transport. The probability of using a private car is of getting any even numbered face is the same. if the
0.45.While using public transport, further choice available probability that the face is even given that it is greater than
are bus and metro, out of which the probability of commuting 3 is 0.75, which one of the following option is closest to the
by a bus is 0.55. In such a situation, the probability (rounded probability that the face value exceeds 3? [2009, 1 mark]
up to two decimals) of using a car, bus and metro, (a) 0.4533 (b) 0.468
respectively would be [2008, 2 marks] (c) 0.485 (d) 0.492
21. Assume for simplicity that N people, all born in April (a
(a) 0.45, 0.30 and 0.25 (b) 0.45, 0.25 and 0.30 month of 30 days) are collected in a room. Consider, the
(c) 0.45, 0.55 and 0 (d) 0.45, 0.35 and 0.20 event of atleast two people in the room being born on the
15. Aishwarya studies either computer science or mathematics same date of the month, even in different years, e.g., 1980
every day. If she studies computer science on a day, then and 1985. What is the smallest N. So that the probability of
the probability that she studies mathematics the next day is this event exceeds 0.5? [2009, 1 mark]
0.6. If she studies mathematics on a day, then the probability (a) 20 (b) 7
that she studies computer science the next day is 0.4. Given (c) 15 (d) 16
22. Consider a company that assembles computers. The
that Aishwarya studies computer science on Monday, what
probability of a faulty assembly of any computer is p. The
is the probability that she studies computer science on company therefore, subjects each computer to a testing
wednesday? [2008, 1 mark] process. This testing process gives the correct result for
(a) 0.24 (b) 0.36 any computer with a probability of q. What is the probability
(c) 0.4 (d) 0.6 of a computer being declared faulty? [2010, 1 mark]
16. X is a uniformly distributed random variable that takes value (a) pq + (1 – p)(1 – q) (b) (1 – q)p
between 0 and 1. The value of E[X3] will be (c) (1 – p)q (d) pq
23. Two coins are simultaneously tossed. The probability of
[2008, 1 mark]
two heads simultaneously appearing is [2010, 1 mark]
1
(a) 0 (b) 1 1
8 (a) (b)
8 6
1 1
(c) (d) 1 1
4 2 (c) (d)
4 2
EBD_7203
S2-16 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
24. A fair dice is tossed two times. The probability that the 29. Suppose p is the number of cars per minute passing
second toss results in a value that is higher than the first through a certain road junction between 5 pm and 6 pm
toss is [2011, 1 mark] and p has a poisson distribution with mean 3. What is
the probability of observing fewer than 3 cars during any
2 2 given minute in this interval? [2013, 1 mark]
(a) (b)
36 6
8 9
(a) (b)
(c)
5
12
(d)
1
2
( 2e )
3
( 2e )
3

25. A deck of 5 cards (each carrying a distinct number from 1 to


17 26
5) is shuffled throughly. Two cards are then removed one at (c) (d)
a time from the desk. What is the probability that the two ( 2e )
3
( 2e )
3

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

(a) x (b) x+l a2


(c) is a positive integer
(c) (d) None of these a+b
lx
3. X is a continuous random variable with probability density (d) None of these
function given by 8. A bag contains three white, two black and four red balls. If
f ( x) = kx(0 £ x < 2) = 2k (2 £ x < 4) four balls are drawn at random with replacement, the
probability that the sample contains just one white ball is
= - kx + 6k (4 £ x < 6)
32 11 32
The value of k and mean value of X are (a) (b) (c) (d) None of these
81 2 93
1 1 9. Suppose that X has a Poisson distribution. If
(a) k= , mean = 3 (b) k= , mean = 3
8 4
P(X = 1) = 0.3 , and P(x = 2) = 0.2 then P(X = 0)=
1 (a) e 1/3 (b) e –3/2 (c) e –4/3 (d) 0.5
(c) k = , mean =2 (d) None of these
5
10. Suppose that the probability that an item produced by a
4. The frequency distribution of a measurable characteristic particular machine is defective equals 0.2. If 10 items
varying between 0 and 2 is as under produced from this machine are selected at random, the
probability that not more than one defective is found is
f ( x ) = x 3 , 0 £ x £ 1 = (2 - x)3 , 1 £ x £ 2
Standard deviation and mean deviation about the mean are 1 2 3
(a) 2 (b) 2 (c) (d) None of these
e e e2
1 1 1 2
(a) , (b) , 11. A machine is producing 4% defective products. Find the
15 5 15 5
probability of getting exactly 4 defectives in a sample of 100
2 1 is [Given log 2 = 0.30102, log 3 = 0.4771, log e = 0.4343,
(c) , (d) None of these antilog (.2908) =1.954]
15 5
(a) 0.1954 (b) 0.5419 (c) 0.9154 (d) None of
5. If probability of a bad reaction from a certain injection is these
0.001. The chance that out of 2,000 individuals more than
two will get a bad reaction is 12. If E and F are the complementary events of events E and F
(a) 0.68 (b) 0.32 respectively and if 0 < P(F) < 1, then
(c) 0.41 (d) None of these
(a) P(E \ F) + P( E \ F) = 1
6. Let X be the number of times heads occur in n tosses of a
fair coin. If P (X = 4), P(X=5) and P(X = 6) are in A.P., then (b) P(E \ F) + P(E \ F ) = 1
value of n is
(a) 7 or 14 (b) 10 or 14 (c) P( E \ F) + P(E \ F ) = 1

(c) 12 or 7 (d) None of these (d) P(E \ F ) + P( E \ F ) = 1


EBD_7203
S2-18 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
13. A bag contains three white, two black and four red balls. If 21. If A and B are two events such that P(A) > 0, and P( B) ¹ 1 ,
four balls are drawn at random with replacement, the
probability that the sample contains just one white ball is æ Aö
then P ç ÷ is equal to
è Bø
16 8 32 4
(a) (b) (c) (d) A A
81 81 81 81 (a) 1 – P ( ) (b) 1 – P( )
B B
14. One hundred identical coins, each with probability p of
showing up heads, are tossed. If 0 < p < 1 and the probability 1 – P( A È B) P ( A)
(c) (d)
of heads showing on 50 coins is equal to that of heads P( B ) P ( B)
showing on 51 coins. The value of p is 22. Let X be a normal random variable with mean 1 and
variance 4. The probability P{X < 0} is
1 49 50 51
(a) (b) (c) (d) (a) 0.5
2 101 101 101
(b) greater than zero and less than 0.5
15. The probability of a man hitting a target is 1/4. The number (c) greater than 0.5 and less than 1.0
of times he must shoot so that the probability he hits the
(d) 1.0
target, at least once is more than 0.9, is
23. A fair coin is tossed till a head appears for the first time.
[use log 4 = 0.602 and log 3 = 0.477]
The probability that the number of required tosses is odd,
(a) 7 (b) 8 (c) 6 (d) 5 is
16. Suppose X is a random variable which takes values (a) 1/3 (b) 1/2
0, 1, 2, 3, ... and P(X = r) = pqr, where 0 < p < 1, q = 1 – p and (c) 2/3 (d) 3/4
r = 0, 1, 2, ... then :
24. Which of the following is correct?
(a) P(X ³ a ) = q a
(a) If P ( A) > 0 , P ( B) > 0 and P ( A / B ) = P ( B / A) ,

(b) P(X ³ a + b | X ³ a ) = P(X ³ b) then P ( A) = P ( B)


(b) If A and B mutually exclusive, then
(c) P(X = a + b | X ³ a ) = P(X = b)
P ( A / B ) = P ( A) / (1 - P(b))
(d) All of the above
17. If the mean of a binomial distribution is 25, then its standard (c) If A and B are independent, then
deviation lies in the interval given below P ( A È B ) = 1 - P( A).P( B )
(a) [0, 5) (b) (0, 5] (c) [0, 25) (d) (0, 25]
(d) All of these
18. It is given that the events A and B are such that
25. Which of the following is correct?
1 1 2 (a) P ( A È B / C ) = P ( A / C ) + P( B / C ) - P ( A Ç B / C )
P ( A) = , P( A | B ) = and P ( B | A) = . Then P(B) is
4 2 3
(b) P ( A Ç B / C ) + P ( A Ç B / C ) = P( A / C )
1 1 2 1
(a) (b) (c) (d) (c) If A and B are independent, then A and B are also
6 3 3 2
independent.
19. If C and D are two events such that C Ì D and P(D) ¹ 0, (d) All of these
then the correct statement among the following is
26. S.D. of n observation a1, a2 , a3 ,..........an is s, then If S.D.
(a) P (C | D ) ³ P (C ) (b) P (C | D ) < P (C )
of the observations la1 , la2 , la3 ,......lan is
P( D )
(c) P (C | D) = (d) P (C | D ) = P (C ) (a) ls (b) -ls
P (C )
20. Two aeroplanes I and II bomb a target in succession. The (c) |l|s (d) s
probabilities of I and II scoring a hit correctly are 0.3 and 0.2, 27. A coin is tossed independently 4 times. The probability
respectively. The second plane will bomb only if the first of the event ‘the no. of times heads show up is more than
misses the target. The probability that the target is hit by the no. of times tail shows up’ is
second plane is
(a) 1/16 (b) 1/8
(a) 0.2 (b) 0.7 (c) 0.06 (d) 0.14.
(c) 1/4 (d) 5/16
PROBABILITY S2-19
28. Consider two events E1 and E2 such that probability of E1, 29. If A and B are mutually exclusive and
1 P ( A È B )= P( A) + P ( B) , then P ( A / A È B) =
Pr(E1) = ,
2
P ( A) P ( A)
(a) (b)
1 P ( A) + P ( B ) P ( A) - P ( B )
probability of E2, Pr ( E2 ) = and probability of E1 and
3
P( B)
1 (c) (d) None of these
E2 , Pr ( E1 and E2 ) = P ( A) + P ( B )
5
30. If sum and product of the mean and variance of a binomial
Which of the following statements (s) is/are True?
distribution are 24 and 18 respectively, then distribution is
2 12 16
(a) Pr ( E1 or E2 ) is æ 1 1ö æ 1 3ö
3 (a) çè + ÷ø (b) çè + ÷ø
7 8 4 8
(b) Events E1 and E2 and E3 are independent
24 32
(c) Events E1 and E2 are not independent æ 1 5ö æ 1 1ö
(c) çè + ÷ø (d) çè + ÷ø
6 6 2 2
æE ö 4
(d) Pr ç 1 ÷ =
è E2 ø 5
EBD_7203
S2-20 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

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)

3 1 5. (c) If two fair dice rolls the probability distribution of r,


= = where r is the sum of the numbers on each dice is
6 2
given by
3. (d) Given, P and Q are two random events, then
(a) Independence of P and Q r 2 3 4 5 6 7 8 9 10 11 12
Probability ( P Ç Q ) = Probability (P). Probability (Q) 1 2 3 4 5 6 5 4 3 2 1
If two events P and Q are mutually disjoint, then P( r )
36 36 36 36 36 36 36 36 36 36 36
probability ( P Ç Q ) = 0
The above table has been obtained by taking all
So, option (a) is incorrect. different ways of obtaining a particular sum.
(b) For two events P and Q Example A sum of six can be obtained by (1, 5), (2, 4), (3, 3),
Probability ( P È Q) = Probability (P) + Probability (Q) (4, 2), (5, 1)
– Probability ( P Ç Q) 6
\ P ( x = 6) =
Here, Probability ( P È Q) £ Probability (P) 36
+ probability (Q) (a) Probability (r > 6) = Probability (r ³ 7)
So, option (c) is incorrect. 6 5 4 3 2 1 7
(c) There is no relationship between mutually exclusive = + + + + + =
and independent for two random variables P and Q. 36 36 36 36 36 36 12
So, option (c) is incorrect. Option (a) is wrong.
(b) Probability (r/3 is an integer)
(d) And Probability ( P Ç Q) £ Probability (P), which = Probability (r = 3) + Probability (r = 6)
is true for every events. + probability (r = 9) + Probability (r = 12)
So, option (d) is correct.
2 5 4 1 1
= + + + =
4. (d) (a) The measure of skewness depends upon the 36 36 36 36 3
quartiles and moments which include in dispersion. \ Option (b) is wrong
(b) In symmetric distribution, the value of mean, mode (c) Probability of (r/4 is an integer)
and median are all same. = Probability (r = 4) + Probability (r = 8)
i.e., (mean x ) = M0 (mode) = Md (median) + Probability (r = 12)
(c) In a positively skewed distribution, 3 5 1 9 1
mean > median > mode = + + = =
36 36 36 36 4
5
and Probability (r = 8) =
36
æ r ö
Then, probability çè r = 8 | is an integer ÷ø
4

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

14. (a) Probability of private car = 0.45 ò f ( x) = 2 ò f ( x ) dx, if f ( x ) is even,


Probability of bus or Public transport = 0.55 -a 0
Since, a person has a choice between private car and 1/3 1/3
public transport. é x3 ù
= 2 ò x 2 dx = 2 ê ú
Then, probability of public transport ëê 3 ûú 0
0
= 1 – probability of private car
= 1 – 0.45 = 0.55 2 1 2
= ´ =
Now, probability of bus 3 27 81
= Probability of bus and public transport 2
= (Probability of bus or public transport) Probability of percentage = ´100 = 2.47%
× (Probability of public transport) 81
PROBABILITY S2-23
18. (d) Given, mean (µ) = 102 cm 21. (b) Let N people in room.
Standard deviation s = 27 cm So, number of events that atleast two people in room
born at same date NC2.
æ x -m x -m ö
Also, P (x1 £ x £ x 2 ) = P ç 1 £z£ 2
s ÷ø
N
è s C2 ´ N C3 ´ ..... ´ NC N
\ 0.5 ³ ÞN=7
N!
æ 90 - 102 102 - 102 ö 22. (a) Let F and C denote event of faulty assembly of
P (90 £ x £ 102) = P ç £z£
è 27 27 ÷ø computer and the testing process giving correct result
respectively.
æ -12 ö P(F) = p
= Pç £ z £ 0÷
è 27 ø P(C) = q
Required probability
= P(-0.44 £ z £ 0)
= P(F Ç C) + P(F'Ç C')
= P(F)P(C) + P(F¢).P(C¢)
= pq + (1 – p)(1 – q)
23. (c) The total number of exhaustive cases
n = [(H, H), (H, T), (T, H), (T, T)]
– 0.44 Total number of favourable case = {(H, H)} = m
The standard area is given by F(0) – F(–0.44) m 1
Thus, probability = =
1 1 n 4
= -
1 + exp(0) 1 + exp[ -1.7255( -0.44)( -0.44)0.12 ] 24. (c) Total number of causes = 36
Total number of favourable causes
1 1 = 5 + 4 + 3 + 2 + 1 = 15
= -
1 + 1 1 + exp(0.6879) 15 5
Probability = =
= 0.5 – 0.3345 = 1.655 ; 16.55% 36 12
= 16.7% 25. (d) The combination of card will be
19. (c) All the 10 tosses are independent of each other (1, 5), (2, 5), (3, 5), (4, 5), (1, 4), (2, 4), (3, 4), (1, 3), (2, 3),
(1, 2) Þ 10
2 8 10
æ1ö æ1ö æ1ö Number of combinations that the difference between
\ Required probability = ç ÷ ç ÷ = ç ÷
è2ø è2ø è2ø numbers is 1.
(4, 5), (3, 4), (2, 3), (1, 2)
20. (b) Let P (face value even) = x
\ P (face value odd) = 0.9x 4 2
Probabilities = =
Now, since x + 0.9x = 1 10 5
1 26. (c) One ball is drawn at random from each container,
x= = 0.5263 probability that one ball is red and other is blue.
1.9
4 3
Given, P(2) = P(4) = P(6) C1 C1
P( R) = , P( B) =
Now, P(2) + P(4) + P(6) = x 7 7
C1 C1
x Each event is mutually independent
P(2) = P(4) + P(6) =
3 4
C1 ´ 3C1 12
P ( R ) ´ P( B) = =
0.5263 7
C1 ´ C17 49
= = 0.1754
3
27. (a) There will be three combination of output
æ even ö P(even Ç face > 3) Coin1 Coin 2
Pç ÷= H H
è face > 3 ø P(face > 3)
H T
[P(4) + P(6)] ´ 2 T H
= Thus, for both head probabilites will be P(HH) = 1/3
0.75
28. (c) Required probability
2 ´ 0.1754 P(a < X £ b) = P(a £ X £ b)
= = 0.4677
0.75 b

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

2. (b) When each item is increased by l, then mean is also êë 0 1 úû


increased by l.
3. (a) Since total probability is unity ì 61 4 2 2 ü
ïx 2 (2 - x) 1 ï
6
= 2í + -x + ò x(2 - x 4 )dx ý
ïî 6 0 4 2 ïþ
\ ò f ( x) dx = 1 1 1

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) P(F) 1


= = =1 Þ n (0.602 - 0.477) ³ 1 Þ n ³ =8
P(F) P(F) 0.125
Therefore the least number of trials required is 8.
P(E Ç F) P(E Ç F)
B. P (E / F) + P (E/ F ) = + ¥
pq a
P(F) P(F) 16. (d) We have, P(X ³ a ) = å pq x =
1- q
= qa
x =a
P(E Ç F) P(E Ç F)
= + ¹1 P[(X ³ a + b) Ç (X ³ a )]
P(F) 1 - P(F) Next, P(X ³ a + b | X ³ a ) =
P( X ³ a )
P(E Ç F) P(E Ç F)
C. P ( E / F) + P (E/ F ) = + P ( X ³ a + b) q a + b
P(F) P(F) = = = q b = P(X ³ b)
P (X ³ a ) q a

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

P(E Ç F) + P(E Ç F) P(F) 17. (a) Standard deviation s = npq ³ 0


= = =1
P(F) P(F)
Now mean = np =25 and q < 1
So (a) and (d) are the correct options.
13. (c) The probability p of getting a white ball in a single So s = npq < np = 5 \ 0£s<5

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

Join = LUB b = a Å b = join = LUB

(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

16. If P = {x Î R : f (x ) = 0} and 21. If f(x) = 2x. then f(0), f(1), f(2),.......are in :


(a) A.P. (b) G. P.
Q = {x Î R : g ( x) = 0} then P Ç Q is (c) H.P. (d) arbitrary
(a) {x Î R : f ( x ) – g (x ) = 0} 22. If the sets A and B are defined as :

(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

(d) none of these. B = {( x, y) : y = - x, Î R} , then


17. Let function f : R ® R be defined by f(x) = 2x + sin x for (a) A Ç B = A (b) A Ç B = B
x Î R , then f is (c) A Ç B = f (d) none of these
(a) one-to-one and onto é 1 ù
23. Range of the function f defined by f ( x ) = ê ú (where
(b) one-to-one but NOT onto ë sin{x} û
(c) onto but NOT one-to-one [.] and {. } respectively denote the greatest integer and the
(d) neither one-to-one nor onto fractional part functions) is
(a) I and set of integers
-1 p (b) N, the set of natural numbers
18. Domain of definition of the function f ( x ) = sin (2 x ) +
6 (c) W, the set of whole numbers
for real valued x, is (d) {2, 3, 4, .....}
24. The period of the function
é 1 1ù é 1 1ù
(a) ê- , ú (b) ê- , ú px
ë 4 2û ë 2 2û f ( x ) = 3x + 3 - [3x + 3] + sin ,
2
æ 1 1ö é 1 1ù where [ x ] denotes the greatest integer £ x , is
(c) ç - , ÷ (d) ê- , ú
è 2 9ø ë 4 4û (a) 4 (b) 1
(c) 2 (d) non-periodic
x2 + x + 2 25. If f ( x + y, x - y) = xy , then the arithmeic mean of f(x, y)
19. Range of the function f ( x ) = ; x Î R is
x2 + x +1 and f(y, x) is
(a) y (b) x
æ 11ù (c) 0 (d) None of these
(a) (1, ¥ ) (b) ç1, ú
è 7û
26. If f ( x + y) = f (x ) + f ( y) - xy - 1 for all x , y Î R and

æ 7ù æ 7ù f (1) = 1 then f (n ) = n, n Î N is true if


(c) ç1, 3 ú (d) ç1, 5 ú (a) n = 1 (b) n = 1 and n = 2
è û è û
(c) n is odd (d) any value of n
ax + d
20. If f ( x ) = and f [f (x )] = x for all x, then:
cx + b
(a) a = b (b) c = d
(c) a + b = 0 (d) c + d = 0
EBD_7203
S2-42 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

PAST GATE QUESTIONS EXERCISE 6. (c) X = (E Ç F) – (F Ç G)


= (E Ç F) Ç (F Ç G)¢
1. (b) X : (P Ú Q) ® R
= (E Ç F) Ç (F¢Ç G¢)
Y : (P ® R) Ú (Q ® R)
= (E Ç F Ç F¢) È (E Ç F Ç G¢)
X : P + Q ® R º (P + Q)¢ + R = P¢ Q¢ + R
= E Ç F Ç G¢
Y : (P¢ + R) + (Q¢ + R) º P¢ + Q¢ + R
Y = (E – (E Ç G)) – (E – F)
Clearly, X ¹Y
= (E Ç (E Ç G¢)) – (E Ç F¢)
Consider X ® Y
= (E Ç (E¢ È G¢) Ç (E Ç F¢)¢
º (PQ)¢ + R) ® (P¢ + Q¢ + R)
= (E Ç E¢) È (E Ç G¢) Ç (E È F)
º (P¢Q¢ + R)¢ + P¢ + Q¢ + R
= (E Ç G¢) Ç (E¢È F)
º (P¢ Q¢)¢ R¢ + P¢ + Q¢ + R
= (E Ç G ¢ Ç E¢) È (E Ç G¢Ç F)
º (P + Q) R¢ + P¢ + Q¢ + R
= E Ç F Ç G¢
º PR¢ + QR¢ + P¢ + Q¢ + R
Þ X= Y
º (PR¢ + R) + (QR¢ + Q¢) + P¢
7. (c) The set S = {1, 2, 4, 7, 8, 11, 13, 14} is a group under
º (P + R) (R¢ + R) + (Q + Q¢) × (R¢ + Q¢) + P¢ multiplication modulo 15.
º P + P¢ + R + R¢ + Q¢ The identity element for this group is e = 1
= 1 + 1 + Q¢ º 1 Since, " x ÏS, 1. x and 15 = x
\ X ® Y is a tautology. Now, let the inverse of 4 be 4–1.
2. (c) The set S = {1, 2, 4, 7, 8, 11, 13, 14} is a group under Now, (4. 4–1) mod 15 = e = 1
multiplication modulo 15.
Now, (4. 4) mod 15 = 1
The identity element for this group is e = 1 since,
Since, (4. 4) mod 15 = 1
"x ÎS,1× x mod 15 = x \ 4–1 = 4 (This inverse is unique)
Now, let the inverse of 4 be 4–1. Similarly, let the inverse of 7 by 7–1
Now, (4·4) mod 15 = 1 (7. 7–1) mod 15 = 1
\ 4–1 = 4 (This inverse is unique) Putting each element of set as 7–1 by trial and error, we get
Similarly, let the inverse of 7 be 7–1. (7.13) mod 15 = 91 mod 15 = 1
(7·7–1) mod 15 = 1 7–1 = 13
–1
Putting each element of set as 7 by trial and error, So, 4 and 7–1 are respectively 4 and 13.
–1
we get
8. (b) a
(7·13) mod 15 = 91 mod 15 = 1
\ 7–1 = 13
–1 –1
So, 4 and 7 are respectively 4 and 13.
3. (a) X = (A – B) – C
= (A Ç B¢) Ç C ¢ b e d
= A Ç B¢ Ç C¢
Y = (A – C) – (B – C)
= (A – C¢) – (B Ç C¢)
= (A Ç C¢) Ç (B Ç C¢)¢ c
= (A Ç C¢) Ç (B¢ È C) The poset [{a, b, d, e}, £ 1] is a lattice (since, every pair
= (A Ç C¢ Ç B¢) È (A Ç C¢ Ç C) of element has LUB and GLB) but it is not a distributive
= A Ç B¢ Ç C¢ lattice. Because distributive lattice satisfying the
\ X= Y following conditions. For any x, y, z
4. (a) (x, y) R (u, v) if x < u and y > v (x, x) R, (x, x) x Ù (y Ú z) = (x Ù y) Ú (x Ùz)
sincex </ x adn x >/ x. x Ú (y Ù z) = (x Ú y) Ù (x Úz)
So. R is not reflexive. ` where, Ù and Ú are meet and join operations but for
\ is neither a partial order, nor an given poset [{a, b, c, d, e}, £ 1]
equivalence relation. b Ù (c Ú d) = b Ù a = b
5. (b) Here, n = mC3 (b Ù c) Ú (b Ù d) = e Ú e = e
and f (1) = f (2)... = f (m) = m–1C2 So, it is not distributive. (Also, element b has 2
m
complements c and d, which is not possible in the
distributive lattice, since in a distributive lattice,
Þ å f (i) = mm –1C 2 complement if it exist, is always unique).
i =1
= 3 × m C3 = 3 × n = 3n
SET THEORY & ALGEBRA S2-43
9. (a) X = (A – B) – C 15. (a) Group properties are closure, associativity, existence of
= (A Ç B¢) Ç C¢ identity and existence of inverse for every element.
= A Ç B¢ Ç C¢ Commutativity is not required for a mathematical
Y = (A – C) – (B – C) structure to become a group.
= (A Ç C¢) – (B Ç C¢) 16. (c) Let the set
= (A Ç C¢) Ç (B Ç C¢)¢ S = {a, b, c, d, e}
= (A Ç C ¢) Ç (B ¢È C) Relation is subset of S × S
There are totally 52 = 25 ordered pairs in S × S including
= (A Ç C¢ÇB¢) È (A Ç C¢Ç C)
five ordered pairs (a, a), (b, b), (c, c), (d, d) and (e, e) that
= A Ç B¢Ç C¢
must be included in order to find reflexive
\ X= Y \ Total number of reflexive relation on S
10. (a) Let A = {1, 2, 3, 5, 7, 8, 9} S = 225–5 = 220
Construct the table for any x, y Î A such that 17. (a) Here, we have onlyh one operation given.
x * y = (x. y) mod 10
Therefore, given options viz; ring, integral domain
· 1 2 3 5 7 8 9 and field are ruled out.
As it requires two binary operations.
1 1 2 3 5 7 8 9
Alternative Method
2 2 4 6 0 4 6 8
(i) For all a, b, Î S
3 3 6 9 5 1 4 7
a×bÎS
5 5 0 5 5 5 0 5 a*bÎS
7 7 4 1 5 9 6 3 i.e.,
8 8 6 4 0 6 4 2 \ Closure property hold son set S.
9 9 8 7 5 3 2 1 (ii) × is an associative operation.
(iii) 1 Î S is the identity element.
We know that 0 ÏA. So, it is not closed. Therefore, (iv) 1–1 = 1, w–1 = (w2) –1 = w
option (a) is true. \ Inverse axiom is satisfied on given set.
The identity element = 1 \ (S, *) is a group
\ (2. 2–1) mod 10 = 1 18. (a) A binary operation Å on a set of integers is defined
From the table we see that 2–1 does not exist
as x Å y = x2 + y2
Since, (3.7) mod 10 = 1
x Å y = x2 + y2
\ 7 is the inverse of 3 and 7 Î A. y Å x = y2 + x2
11. (d) Let n (X) denotes the number of elements of set X.
= x2 + y2 (Q Addition is commutative)
Given, n (X) = x
\ Å is commutative.
n (Y) = y
(x Å y) Å z = (x2 + y2) Å z = (x2 + y2)2 + z2
n (Z) = z
x Å (y Å z) = x Å (y2 + z2) = x2 + (y2 + z2)2
n (E) = Number of all subsets of W
Clearly, (x Å y) Å z ¹ x Å (y Å z)
= Number of all subsets of X × Y
\ Å is not associative.
= 2n(X).n(Y)=2xy
Hence, Å is commutative but not associative.
Therefore, the number of functions from Z to E
19. 16
= [n (E)]n(Z)
The value of log2 log2 N is 16.
= (2xy)z = 2xyz
12. (b) Let S = {1, 2, 3,..., n} be a set of n elements number of We know that the total no. of functions f : A ® B
ordered pairs in the smallest equivalent relation on S is = (Cardinality of B) (Cardinality of A) = |B||A|
n, it must contain all the reflexive elements viz., Now for the given questions:
{(1, 1), (2, 2), (3, 3), ...., (n, n)} {0, 1}4 represents all 4-tubles on the set {0, 1},
and the largest equivalence relation on S has n × n = n2 e.g. (1, 0, 1, 0,), (1, 1, 1, 0) etc.
ordered pairs. Total no. of 4-tubles on {0, 1} = 24 = 16
13. (d) Q Qc È Rc = (Q Ç R)c (Since each element of four tuble has 2 choice)
and (P Ç Q Ç R) È (Pc Ç Q Ç R) = Q Ç R Total no. of functions f : {0, 1}4 ® {0, 1} = 216 (|B||A|)
Therefore, (P Ç Q Ç R) È (Pc Ç Q Ç R) È Qc È Rc A B
= (Q Ç R) È (Q Ç R)c Set S contains all these functions, so cardinality (S) = 216
= U (Universal set) Now, N denotes the no. of func. g: S ® {0, 1}.
14. (d) Given, R = {x, y}, (x, z), (z, x), (z, y)} on set {x, y, z} Þ N = |{0, 1}||s| = 22
16

Now, since (x, y) ÎR and (y, x) Ï R, R is not symmetric. 16


Also since (x, z) Î R and (z, x) Î R, R is not anti-symmetric Þ N = 22
either.
\ R is neither symmetric nor anti-symmetric. Þ log2log2 2 2 ( ) = 16
16
EBD_7203
S2-44 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
20. 89 PRACTICE EXERCISE
A 10 percent will be a sequence of any no. of 1s and 2s such
that sum is 10. 1. (a) bN = {bx : x ÎN}
p.g. (1, 1, 2, 2, 1, 1, 2) is a 10 pennant. cN = {cx : x ÎN}
I. When sequence contains all 1s: \ bN Ç cN = {x : x is multiple of b and c both}
no. of such pennants = 1 (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) = { x: x is multiple of l.c.m. of b and c }
II. When sequence contains Eight 1s and one ‘2’ : (8 × 1, 1
× 2) = { x : x is multiple of b c}
[given b and c are relatively prime \ l.c.m. of b and
9!
no. of such pennants = 9C1 = =9 c = bc]
1!8! \ bN Ç cN = {bc x : x ÎN} = dN (Given)
III. When sequence contains six 1s and Two 2s :
6 × 1, 2 × 2 (e.g. 1, 1, 1, 1, 1, 1, 2, 2,) \ d = bc.
18! 2. (d) (a) x Î A - B Û x Î A and x Ï B
no. of pennants = 18C2 = = 28
2!6! Û x Î A and x Î B' Û x Î A Ç B'
IV. When sequence contains 4 1s and 3 2s:-
4 × 1, 3 × 2 (e.g. (1, 1, 1, 1, 2, 2, 2)) \ A – B = A Ç B¢ ...(i)
x ÎA and x ÎB¢
7!
no. of pennants = 7C3 = = 35 Û x ÏA¢ and xÎB¢ Û xÎB¢ and xÏA¢
3!4! Û xÎB¢–A¢
V. When sequence contains 2 1s and 4 2s :
2 × 1, 4 × 2 (e.g. (1, 1, 2, 2, 2, 2,)) \ A – B = B¢ – A¢ ...(ii)
Clearly (a) is not correct. Also from (i) (c) is not correct.
6!
no. of pennants = 6C4 = = 15 Next let xÎA – (A – B)
4!2! Û xÎA and xÏA – B
VI. When sequence contains 5 2s and no. 1s:
no. of pennants = 1 (i.e. (2, 2, 2, 2, 2))
Total no. of 10 pennants
= 1 + 9 + 28 + 35 + 15 + 1 = 89.
Û xÎA and [x ÏA or x ÎB]
21. (b) (a « c) ® (~ b ® (a Ù c))
22. (a) Nullset is larger than any other set.
Universal set is smaller than any other set. A – (A – B) = A Ç B
23. (d) f : X ® Y defined as f (a) = 1, f(b) = 1, f(c) = 2 Û [xÎA and x ÏA] or [ x ÎA and xÎB]
where, X = {a, b, c} \ A – (A – B) = f È (A Ç B) = A Ç B
Y = {1, 2} \ (b) is also incorrect
Let A = {a, c}, B = {b, c} be subsets of X
The result (d) is correct as can be seen in the following
(A) | f (A È B) |= 2 Venn diagram
| f (A) |= 2 :| f (B) |= 2
\ (A) is false U
A B
(B) f (A Ç B) = {i}
f(A) = {1, 2) ; f{B} = {1, 2} A-B BÇA B-A
f(A) Ç f (B) = {1, 2}
\ (B) is false.
(C) | f (A Ç B) |= 1
\ (C) is false.
(D) is true A È B = (A – B) È (A Ç B) È (B – A)
24. 2 3. (a) Let U be the set of consumers questioned X, the set of
Let the vector space, V be {a, b, c, d, e, f} consumers who liked the product A and Y, the set of
For smallest possible dimension of V1 Ç V2 , consumers who liked the product B. Then n (U) = 1000,
V1 = {a, b, c, d} and V2 = {c, d, e, f} n (X) = 720, n (Y) = 450
\ V1 Ç V2 = {c,d} n (XÈY) = n (X) + n (Y) – n (XÇY) = 1170 – n (XÇY)
\ Smallest possible dimension = 2 \ n (X Ç Y) = 1170 – n (X È Y)
25. (b) Consider a function as : Clearly n (X Ç Y) is least
f (0) = 1, f (1) = 0, f (2) = 3, f (3) = 2, ...., f (2012) = 2013, When n (X È Y) is maximum.
f (2013) = 2012 and f (2014) = 2014
Clearly f (f (i)) = i for 0 < i < 2014 Now, XÈY Ì U
Here f (i) ¹ i for every i and f (i) = i for some i \ n(XÈY) £ n (U) = 1000
Also f is onto \ the maximum value of n (XÈY) is 1000.
Hence, only Q and R are true Thus the least value of n (XÇY) is 170
SET THEORY & ALGEBRA S2-45
4. (a) See the following Venn diagram Þ a º a (mod m)
I M F Thus, a º a (mod m) for all a Î I.
23 So ‘congruence modulo m’ is reflexive.
4–x
Symmetry : Let a, b ÎI such that a º b (mod m).
x
29 Then, a º b (mod m) Þ a – b is divisible by m
W Þ a – b = l m for l Î I Þ b – a = (–l) m
n (I) = 29 + 23 = 52 Þ b – a is divisible by m [\ l Î I Þ - lÎ I]
n (F) = 100 - 52 = 48 Þ b º a (mod m)
So, ‘congruence modulo m’ is symmetric on I.
n (m È D ) = n ( m ) + n ( D ) - n ( m Ç D ) Transitivity : Let a, b, c, Î I such that a º b (mod m) and
24 = 23 + 4 - n (m Ç D) b º c (mod m). Then, a º b (mod m) Þ a – b is divisible by
m
\ n ( m Ç D) = 3 Þ a – b = l1m for some l1ÎI
\ n( W Ç D) = 4 - 3 = 1 b º c (mod m) Þ b – c is divisible by m
5. (b) C stands for set of students taking economics Þ b – c = l2 m for some l2ÎI
\ (a – b) + (b – c) = l1m + l2m = (l1 + l2) m
E C Þ a – c = l3 m, where l3= l1+l2Î I. Þ a º c (mod m)
a b c
g Thus, a º b (mod m) and b º c (mod m) Þ a º c (mod m).
d e So, ‘congruence modulo m’ is transitive on I.
Hence, ‘congruence modulo m’ is an equivalence relation
f
on I.
M 9. (a) Consider the following example Let A = {1, 2, 3} and
a + b + c + d + e + f + g = 40; a + b + d + g = 16 R = {(1, 1), (1,2)} and S = {(2, 2), (2, 3)}
b + c + e + g = 22; d + e + f + g = 26 Clearly R and S are transitive relations on A . Now
b + g = 5; e + g = 14; g = 2 R È S = {(1, 1), (2, 2), (1, 2), (2, 3)}
Go by backward substitution R È S is not transitive as (1,3) ÏRÈS.
e = 12, b = 3, d + f = 12, c + e = 17 Þ c = 5; a + d = 11 10. (b) We have (x, y) Î R iff x + y < 6
a +d + f = 18 Þ f = 7 \ d = 12 – 7 = 5 Given the value x = 1, we get possible values of y = 1, 2, 3, 4.
6. (a) Thus 1R1, 1R2, 1R3, 1R4. Similarly we may find other
F values. The set of such ordered pairs is
f b H
a R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2),
g
e d (2, 3), (3, 1), (3, 2), (4, 1)}
c
B \ n (R ) = 10
11. (b) We have domain of R = the set of first components of
a + e + f + g = 285, b + d + f + g = 195 the ordered pairs in R = {0, 0, 1, 2, 2, 2, 1, 0, 0} = {0, 1, 2}
c + d + e + f = 115, e + g = 45, f + g = 70, d + g = 50 range of R = the set of second components of the ordered
a + b + c + d + e + f + g = 500 – 50 = 450 pairs in R
As in previous question, we obtain = {0, 1, 1, 1, 2, 0, 0, 2, 1} = {0, 1, 2}
a + f = 240, b + d = 125, c + e = 65 12. (d) For a set S, the partition of S is a set of subsets of S, such
a + e = 215, b + f = 145; b + c + d = 165 that they are pair-wise disjoint and their union is S.
a + c + e = 255; a + b + f = 335 In the options (a) & (b), the subsets are not disjoint.
Solving we get In the option (c), the subsets are disjoints but their union
b = 95, c = 40, a = 190 , d = 30, e = 25, f = 50 and g = 20 is not equal to the given set.
7. (b) R is reflexive since any point is at distance O from itself Only the option (d) meets with both the requirements.
so that it is within 1 cm from itself. 13. (d) To make it reflexive. we need to add (2, 2), (3, 3), (4, 4).
R is symmetric since if a point a is within 1 cm from To make symmetric it requires (3, 2), (4, 3) to be added
another point b, then b is also within 1 cm from a. to make transitive (2, 4) and (4, 2) must be added so,
R is not transitive. Let a, b, c, be three points in a straight the relation
lines in this order such that distance between a and b is R = {(2, 2), (3, 3), (4, 4), (2, 3) (3, 2), (3, 4), (4, 3), (2, 4) (4, 2)}.
1 2 14. (a) The smallest equivalence relation is the identity
cm and distance between b and c is cm. Then aRb relation
2 3
R1 = {(a, a), (b, b), (c, c)}
and bRc. But (a, c) ÏR since the distance between a and
Then two ordered pairs of two distinct elements can be
æ1 2ö 7 added to give three more equivalence relations
c is ç + ÷ = cm > 1cm. R2 = {(a, a), (b, b), (c, c), (a, b), (b, a)}
è2 3ø 6
Similarly R3 and R4. Finally the largest equivalence
8. (a) We observe the following properties relation i.e, the universal relation
Reflexivity : Let a be an arbitary integer. Then, R5 = { (a, a), (b, b), (c, c), (a, b), (b, a), (a, c), (c, a), (b, c),
a – a = 0 = 0 × m Þ a – a is divisible by m (c, b)}
EBD_7203
S2-46 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
21. (b) Given f(x) = 2x
1
15. (d) Q| a - a |= 0 < Þ aR/ a , so, relation is not reflexive \ f(0) = 20 = 1, f(1) = 21 = 2,
2 f(2) = 22 = 4 and so on
1 1 Clearly 1, 2, 4, .....are in G.P.
If | a - b |³ then | b - a |=| a - b |³ i.e. f(0), f(1), f(2),.........are in G.P.
2 2 22. (c) The two curves
So, aRa Þ bRa , i.e the relation is symmetric.
1
Clearly the relation is not transitive as y= and y = -x
x
1
| 2 - 4 |= 2 ³ Þ 2R 4 Y
2 y = –x
9 7 1 9 9 1 1 5 1
4- = ³ Þ 4 R but 2 - = < Þ 2 R y=
4 4 2 4 4 4 2 4 x
Hence at least 7 pairs must be added O X
16. (c) (a) and (b) cannot be correct, see the previous solution. intersect at the point, –1
y=
Also, we know that x2 + y2 = 0 iff x = y = 0 x
\ (f ( x ) )2 + (g ( x ) )2 = 0 Û f ( x ) = 0 and g ( x ) = 0

{
\ 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

(a, a) (a, b) (a, a) (a, b) Sample Problem


(a, b) (a, c) (a, b) (a, c) How many different words can be formed with the letters of
(a, c) (b, a) (a, c) (b, c) the world MISSISSIPPI.
(b, a) (b, c) (b, b) Sol. In the word MISSISSIPPI, there are 4 I's, 4S's and 2P's.
(b, b) (c, a) (b, c) (11)!
Thus required number of words = = 34650
(b, c) (c, b) (c, c) 4! 2! 4!
(c, a) RESULT - 4 : To find the number of Permutations of 'n' different
(c, b) things, taking 'r' at a time, when each thing can be repeated 'r'
(c, c) times:
In the problem we have to fill 'r' vacant places with 'n' things with
PERMUTATIONS repetition. Obviously, each place can be filled in 'n' ways, leaving
Each of the arrangements, which can be made by taking, some or again n ways for the other place.
all of a number of things is called a PERMUTATION. Hence, the number of ways of filling r-places with 'n' things = n
RESULT - 1 : To find the number of permutations of 'n' things × n × n × ....... × n (r factors) = n r
taken 'r' at a Time :
Sample Problems
The problem is equivalent to filling 'r' places with 'n' different things.
The first place can be filled in 'n' ways, as any one of the 'n' 1. In how many ways can 5 prizes be given away to 4 boys,
things may be taken. when each boy is eligible for all the prizes?
COMBINATORICS S2-49
Sol. Any one of the prizes can be given in 4 ways; then any one CONDITIO NAL PERMUTATIONS
of the remaining 4 prizes can be given again in 4 ways, since 1. Number of permutations of n things taking r at a time, when
it may even be obtained by the boy who has already received a particular object is to be always included in each =
a prizes.
Hence 5 prizes can be given 4 × 4 × 4 × 4 × 4 = 45 ways. r . n -1Pr -1 .
2. How many numbers of 3 digits can be formed with the digits 2. Number of permutations of n things taking r at a time, when
1, 2, 3, 4, 5 when digits may be repeated? n -1
a particular object is never taken in any arrangement = Pr .
Sol. The unit place can be filled in 5 ways and since the
repetitions of digits are allowed, therefore, tenth place can 3. Number of permutations of n different things taking all at a
be filled in 5 ways. time, when m specified things always come together
Furthermore, the hundredth place can be filled in 5 ways = m!(n - m + 1)! .
also.Therefore, required number of three digit numbers is 4. Number of permutations of n different things taking all at a
5 × 5 × 5 = 125. time, when m specified things never come together
RESULT - 5 : Number of circular permutations of 'n' distinct = n!- m!(n - m + 1)!
objects : 5. Number of permutations of n different things taking r at a
Suppose the required number of permutations is 'x'. Since each time, in which two specified objects always occur together
circular permutation corresponds to 'n' linear permutations
depending on where (out of the 'n' positions) we start. = 2! ( r - 1) n - 2 Pr - 2
Therefore the total number of linear permutations is xn. 6. Number of ways of arranging n objects on a circle taking r at
But the number of linear permutations is n!. a time
n! n
Pr
Therefore, xn = n! Þ x = Þ x = (n - 1)! = , if clockwise and anticlockwise arrangements are
n r
Thus the total number of circular permutations of 'n' distinct distinct
things is (n – 1)!.
n
If no distinction is made between anti-clockwise and clockwise Pr
= , if clockwise and anticlockwise arrangements cannot
1 2r
arrangements, then the number of permutations is (n – 1)! be distinguished.
2
Sample Problem COMBINATIONS :
1. Number of different permutations, each containing all letters Each of the selections that can be made with a given number of
of the word "STATESMAN" is objects taken some or all of them at a time is called a
(a) 90720 (b) 45360 COMBINATION.
(c) 22680 (d) None of these RESULT-1 : To find the number of combinations of 'n' dissimilar
Sol. (b) "STATESMAN" things taken 'r' at a time :
Total number of letters = 9, Let the required number of selections be 'x'.
Number of S's = 2, Number of T's = 2, Number of A's = 2 Consider one of these 'x' ways. there are 'r' things in this selection
\ Required number of permutations which can be permutated in r! ways.
9! Thus, each of the 'x' selections gives r! permutations.
= = 45360
(2)! (2)! (2)! Consequently, the total number of permutations of 'n' things
2. Numbers which can be formed with digits 1, 2, 3, 4, 3, 2, 1 taken 'r' at time is x (r!).
using all digits so that odd digits occupy always the odd But this number is also nPr.
place are
1 n n!
(a) 6 (b) 12 \ x (r!) = n Pr Þ x = Pr = = n Cr
(c) 15 (d) 18 r! r!(n - r )!
Sol. (d) The number formed with the given digits will be 7 digit Thus, the total number of combinations of 'n' dissimilar things
number, which will have 4 odd positions and 3 even taken 'r' at a time is nCr.
positions. The number of combinations of 'n' dissimilar things taken all at a
The odd digits having two 1's alike and two 3's alike can be time = nCn = 1.
4! RESULT-2 : To find the number of Combinations of 'n' different
arranged in the four odd positions in = 6 ways.
(2)! (2)! things taking some or all at a time : Out of 'n' things, 1 thing can
The even digits having two 2's alike can be arranged in the be selected in nC1 ways; 2 things can be selected in nC2 ways, 3
3! things can be selected in nC3 ways and so on.
three even positions in = 3 ways
2! Hence the total number of combinations is
Hence the number of numbers by fundamental principle of
n
counting = 6 × 3 =18. C1 + n C 2 + n C 3 + .............. + n C n = 2 n - 1
EBD_7203
S2-50 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
RESULT-3 : The number of selections of some or all out of (p + RESULT-2 : The total number of ways to divide 'n' identical
q + r + ..... ) things out of which p are alike of one kind, q - alike things among 'r' persons when each gets at least one thing is
of second kind and so on : n -1
C r -1
The total number of required ways
= (p + 1) (q + 1) (r + 1) ...... – 1 RESULT-3 : The total number of selections of 'r' things from 'n'
RESULT-4 : The number of selections of one or more things things where each thing can be repeated as many times as one
from 'p' identical things of one kind, 'q' identical things of a can is n + r -1
Cr .
second kind, 'r' identical things of a third kind and 'n' different
things DERAGEMENTS
The total number of required ways Any change in the given order of the things is called a
= (p + 1) (q + 1) (r + 1) 2n – 1 DERAGEMENT.
RESULT-5 : The number of ways of dividing 'm + n' things into If n things form an arrangements in a row, the number
two groups containing 'm' and 'n' things respectively : of ways in which they can be deraged so that no one
This is equivalent to finding the number of combination of 'm + n' of them occupies its original place is
things by taking 'm' at a time. Thus, é 1 1 1 1ù
n! ê1 - + - + ........( -1) n ú
m+n (m + n )! ë 1! 2! 3! n!û
The required number of groups = Cm =
m! n!
CONDITIONAL COMBINATIONS
If m = n, the groups are equal and in this case the number of 1. Number of combinations of n distinct things taking
(2m)! (2m )! r (£ n ) at a time, when k (0 £ k £ r) particular objects
different ways of distribution = m! m! 2! =
( m! ) 2 2! n -k
always occur = C r -k .
If however, the order of group is important (e.g., 2m things divided
2. Number of combinations of n distinct objects taking r(£ n)
(2m )!
equally between two persons), the number of divisions = at a time, when k (0 £ k £ r) particular objects never occur
( m!) 2
= n -k
Sample Problem Cr .
1. A father with 8 children takes 3 at a time to the Zoological 3. Number of selections of r things from n things when
Gardens, as soon as he can without taking the same 3 p particular things are not together in any selection
children together more than once. The number of times he = nCr – n – pCr – p
will go to the garden is 4. Suppose a number N, is expressed in prime factorisation as
(a) 336 (b) 112 following
(c) 56 (d) None of these
N = p1a1 p a2 2 p 3a 3 ..........p amm
Sol. (c) The number of times he will go to the garden is same as
the number of ways of selecting 3 children from 8. where p 1 , p 2 , p 3 , ........, p m are prime integers and
So, the required number = 8C3 = 56. a1, a 2 , a 3 ,.....,a m are any positive integers. Then
2. Out of 7 consonants and 4 vowels, how many words can be (i) Total number of all divisors of
made each containing 3 consonants and 2 vowels?
(a) 120 (b) 25200 N = (a1 + 1) (a 2 + 1) .........(a m + 1)
(c) 4200 (d) None of these 0 1 2 a
Sol. (b) The no. of ways of selecting 3 out of 7 consonants (ii) Sum of all divisors = (p1 + p1 + p 2 + ... + p1 1 )
= 7C3 = 35 a
´ (p 02 + p12 + p 22 + ... + p 2 2 )...(p0m + p1m + p 2m + ... + pamm )
The no. of ways of selecting 2 out of 4 vowels = 4C2 = 6
Now these five letters after selection can be arranged among é p a1 +1 - 1 ù é p a 2 +1 - 1ù é p a m +1 - 1 ù
themselves in 5P5 i.e., 120 ways. ê 1 úê 2 ú ........... ê m ú
= ê p - 1 úê p - 1 ú
Hence the required no. of words = 35 × 6 × 120 = 25200. ë 1 ûë 2 û êë p m - 1 úû

MULTINOMIAL THEOREM 5. Number of selection or r consecutive things out of


Use of expansion to evaluate number of combination n things in a row = n – r + 1
6. Number of selection of r consecutive things out of
RESULT-1 : The total number of ways of dividing 'n' identical
n things along a circle
things among 'r' persons, each of whom can receive 0,1,2 are
more ( £ n ) things is n + r -1 ìn, when r < n
C r -1 (Alternatively, n identical balls =í
to be distributed in r boxes, when blank box is allowed). î1, when r = n
COMBINATORICS S2-51
7. Number of selection of r things (r < n) out of GENERATING FUNCTION
n identical things = 1. The generating function for the sequence a 1, a2, ...., ar, .... of real
8. Number of selection of zero or more things out of numbers of a numeric functions (a0, a1, a2, ...ar,...) is the infinite
n identical things = n + 1. series.
9. Number of selection of one or more things out of A(z) = a0 + a1z + a2z2 + ...+ arzr + ...
n identical things = n. n
C O U NT I N G A(z) = å a r z r
r =1
Basic Counting Rules.
There are two basic counting rules which can be used to solve Some Results
many different counting problems. 1. Let a and b are any two discrete numeric functions and b =
(i) Sum Rule : If first task can be done in n 1 ways and a second aa, then
task in n2 ways, and if these tasks are such that they cannot B(z) = a A(z)
where B(z) is the generating function corresponding to
be done at the same time, then there are n 1 + n2 ways to do
numeric b and A(z) is that of a.
either task.
e.g., The generating function of the numeric function
(ii) Product Rule : Whenever a procedure can be broken down a r = 5 × 2r r ³ 0
into two tasks and then there are n1 ways to do the first task
and n2 ways to do the next task after the first task has been 1
is A(z) = 5 ×
done, then there are n 1n2 ways to do the procedure. 1 - 2z
2. For any three discrete numeric functions a, b and c, if c = a + b,
Sample Problem
then C(z) = A(z) + B(z) is the generating function
1. How many one-one functions are there from a set with m representation.
elements to one with n elements ? e.g., The generating function of the numeric function
Sol. ar = 1r + 2r (r ³ 0)
Whenever m > n, there are no one-one functions from a set 1 1
with m elements to a set with n elements. is A(z) = +
1 - z 1 - 2z
Let us say m £ n. If elements in the domain are assumed to 3. Let a be a numeric function and A(z) its generating function.
be a1, a2, ... an, then there are n ways to choose value of the Let b be a numeric function such that
function at a1. br = arar
Since the function is one-one, there are only (n – 1) ways to Then, the generating function of b is
¥ ¥
pick up for a2, as value of the function. In function general B(z) = å b r z r = å (a r a r )z r
value can be chosen in n – k + 1 ways for ak. Applying r =0 r =0
product rule, there are n(n – 1) ............. (n – k + 1) one-one ¥

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 2 1 2 According to step 1, we choose vertex v1.


Now edge with smallest weight incident on v1 is e = v1, v3
v4 3 v3 v4 3 v3 so we choose e = v1, v3 (or e = v1, v5).
Choose e = v4v5 Choose e = v1v4
v1
Since vertices are 5 and we have choosen 4 edges stop,
3 4
minimal spanning tree of graph is
v5 3 3
v5 v2
v1 3

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

Now, w(v4, v5) = 2. We choose e = v4, v5 k(G) = 2


Fig. Connectivity of graph (by deleting u and v)
v1
3 4
3 3 A simple graph G is called n-connected (n ³ 1) if
v5 v2
3 k(G) ³ n.
2 1 2 Let u and v be two vertices of a graph G. A collection
{P(1)......p(n)} of u – v paths is said to be internally disjoint if,
v4 3 v3 given any distinct pair P(i) and P(j) in the collection, u and v are
The minimal spannign tree is the only vertices P(i) and P(j) have in common.
v1 ISOMORPHISM OF GRAPHS
3 Let G(V, E) and G*(V*, E*) are graphs and f : V ® V* is a one-to-
v5
v2 one correspondence beta sets of vertices such that [u, v] is an
edge of G if and only if {f (u), f(v)} is an edge of G*. Then f is
2 1 2 isomorphism between G and G*, and G and G* are called
v4 v3 isomorphic graphs. Normally, we do not distinguish between
isomorphic graphs (even though their diagrams may “look
different”).
CUT VERTICES AND CONNECTIVITY
Cut vertex is analogue of a bridge. A vertex v of a graph is called Sample Problem
a cut vertex of G if Figure shows ten graphs pictured as letters. Which of the
w(G – v) > w(G), ten graphs are isomorphic to M?
Where w(G) are number of components in graph G, i.e. a cut
vertex breaks a graph into a subgraph having more connected
components, then G has

G–V

Sol. M consists of five vertices in a single line. Thus S, V and Z


w (G) = 1 w (G – v) = 3 (and M itself) are isomorphic to M.
Fig. Graph after deleting cut vertex v
EBD_7203
S2-60 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
MATCH IN GS Problem of distinct representatives
Let four appliants a1, a2, a3, and a4 are available to fill six vacant
positions p1, p2, p3, p4, p5 and p6.
s1
Applicant a1 is qualified to fill position P2 or p5.
c1 s2
Applicant a2 can fill p2 or p5.
Applicant a3 is qualified for p1, p2, p3, p4, p5, or p6.
v1 c2 s3 v2
Applicant a4 can fill jobs p2 or p6.
This situation is represented by the graph in figure below. s4
c3
p1 s5
a1 p2 Committees
p3 Senators
a2 v2
v1 p4 Fig. Membership of committees
a3
p5
a4 p6 Five senators s1, s2, s3, s4 and s5 are memebrs of three committees,
c1, c2, and c3. The membership is shown in the figure.
Positions
Applicants One member from each committee is to be represented in a super
Fig. (a) Bipartite graph
committee. Is it possible to send one distinct representative from
The vacant positions and applicants are represented by vertices. each of the committees?
The edges represent the qualifications of each applicant for filling
This problem is one of finding a complete matching of a set V 1
different positions. The graph clearly is bipartite, the vertices
falling into two sets into set V2 in a bipartite graph.
V1 = {a1, a2, a3, a4} and V2 = {p1, p2, p3, p4, p5, p6}. The most Now, use Theorem 1 and check if r vertices from V1 are collectively
likely questions one is to ask in this situation are : adjacent to at least r vertices from V2, for all values of r.
Is it possible to hire all the applicants and assign each a position Result is shown in the table below (ignore last column for the
for which he is suitable? time being).
If the answer is no, what is the maximum number of positions
that can be filled from the given set of applicants? V1 V2 r -q
This is a problem of matching (or assignment) of one set of r = 1 {c1} {s1 , s 2 } -1
vertices into another. More formally, a matching in a graph is a {c 2 } {s1 , s3 , s 4 } -2
subset of edges in which no two edges are adjacent. A single
{c3 } {s3, s 4 , s5 } -2
edge in a graph is obviously a matching.
r = 2 {c1 , c2 } {s1 , s 2 , s3 , s 4 } -2
Maximal Maching
{c 2 , c3 } {s1 , s3 , s 4, s5 } -2
It is a matching to which no edge in the graph can be added.
e.g. in a complete graph of three vertices (i.e. a triangle) any single {c3 , c1} {s1 , s 2 , s3 ,s 4 , s5 } -3
edge is a maximal matching. The edges shown by heavy lines. r = 3 {c1 , c2 , c3 } {s1 , s 2 , s3 , s 4 , s5} -2

Thus for this example, condition for the existence of a complete


matching is satisfied as stated in Theorem 1. Hence, it is possible
to from the super committee with one distinct representative
(a) (b) from each committee.
Fig. Graph and two of its maximal matchings.
The problem of distinct representatives just solved was a small
Clearly, a graph may have many different maximal matchings and one.
of different sizes. Among these, the maximal matchings with the A large problem would have become unwieldy, if there are M
largest number of edges are called largest maximal matchings. vertices in V1. Theorem 1 requires that we take all 2M–1 nonempty
In Fig. (b), a largest maximal matching is shown in heavy lines. subsets of V1 and find the number of vertices of V2 adjacent
The number of edges in a largest maximal matching called collectively to each of these. In most cases, however, folowing
matching number of the graph. simplified version of Theorem 1 will suffice for detection of a
complete matching in any large graph.
Theorem 1 :
Theorem 2 :
A complete matching of V1 into V2 in a bipartite graph exists if
and only if every subset for vertices in V1 is collectively adjacent In a bipartite graph, a complete matching V 1 into V2 exists if (but
to or more vertices in V2 for all values of r. not only if) there is a positive integer m for which the following
condition is satisfied :
GRAPH THEORY S2-61
Degree of every vertex in V1 ³ m ³ degree of every vertex in V2. Theorem 3 :
In the bipartite graph of above figure, A covering g of a graph is minimal if and only if g contains no
Degree of every vertex in V1 ³ 2 ³ degree of every vertex in V2. paths of length three or more.
Therefore, there exists a complete matching.
In the bipartite graph, no such number is found, because
degree of p2 = 4 > degree of a1.
COVERINGS
(a) (b) (c) (d)
In a graph G a set g of edges is said to cover G if every vertex in
Fig. Star graphs of one, two, three, and four edges.
G is incident on at least one edge in g. A set of edges that covers
a graph G is called edge covering, covering subgraph, or simply Let graph in the above figure represents street map of a part of a
a covering of G. city, each of the vertices is a potential trouble spot and must be
e.g. a graph G is trivially its own covering. Spanning tree in a kept under the surveillance of a patrol car. How will you assign a
connected graph (or a spanning forest in an unconnected graph) minimum number of patrol cars to keep every vertex covered?
is another covering. Hamiltonian circuit (if it exists) in a graph is The answer is a smallest minimal covering. The covering shown
also a covering. in Fig. (a) is an answer, and it requires six patrol cars. Clearly,
since there are 11 vertices and no edge can cover more than two,
less than six edges cannot cover the graph.
Detection of Planarity
Every subgraph of a planar graph is planar and that every graph
which has non-planar graph is also non-planar. A disconnected
graph is planar iff each of its components is planar. Similarly, in a
(a) (b)
separable graph, planarity of each block can be considered
Fig. Graph and two of its minimal coverings
independently. Thus, a separable graph is planar iff each of its
block is planar. Thus, we need to consider only non-separable
Here we shall investigate minimal covering-a covering from which
connected graph.
no edge can be removed without destroyed its ability to cover
the graph. Colouring of Graphs
• Covering exists for a graph if and only if the graph has no A colouring of a graph G is an assignment of colours to its vertices
isolated vertex. such that no adjacent vertices have the same colour. A given
énù graph can be properly coloured in many different ways. We are
• Covering of an n-vertex graph will have at least ê ú edges. finding the minimum number of colours with which a given graph
ê 2ú
can be properly coloured.
( éê x ùú denotes smallest integer not less than x.)
e.g., There are three different proper colouring of a graph with
• Every pendant edge in a graph is included in every covering different number of colours.
of the graph.
• Every covering contains a minimal covering. Yellow Yellow Red
• If we denote remaining edges of a graph by (G – g), the set
of edges g is a covering if and only if, for every vertex v. Green Green Yellow
degree of vertex in (G – g) £ (degree of vertex v in G) –1 Red Blue Red Blue Red Blue
• No minimal covering can contain a circuit, for which we
can always remove an edge form a circuit without leaving Pink Yellow Yellow
any of the vertices in the circuit uncovered. Therefore a Five colours are used Four colours are used Three colours are used
minimal covering of an n-vertex graph can contain no more
than n-edges.
• A graph in general has many minimal coverings, and they
may be of different sizes (i.e. consisting of different
numbers of edges). The number of edges in a minimal
covering of the smallest size is called covering number of
the graph.
EBD_7203
S2-62 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

1. Which of the following graphs is not planar? a1


[2005, 1 mark] p1
a2

(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 } ,

p2 = {ab, cd }, p3 = {abc, d }, p4 = {a, b, c, d }


Let < be partial. k4
Q3
Order on the set of partitions S¢ = (p1, p2, p3, p4) defined as
follows : pi < pj if and only if pi refines pj. The poset Which one of the following statements is true in relation to
diagram for (S¢, <) is [2007, 1 mark] these graphs? [2011, 1 mark]
GRAPH THEORY S2-63
(a) K4 is planar while Q3 is not (a) 3 (b) 4
(b) Both K4 and Q3 are planar (c) 5 (d) 6
(c) Q3 is planar while K4 is not
(d) Neither K4 nor Q3 is planar 14. Which of the following statements is/are true for
11. Which of the following graphs is isomorphic to given graph? undirected graphs?
[2012, 2 marks] P: Number of odd degree vertices is even.
Q: Sum of degrees of all vertices is even.
[2013, 1 mark]
(a) P only (b) Q only
(c) Both P and Q (d) Neither P nor Q
15. The maximum number of edges in a bipartite graph on 12
vertices is _________________. [2014, Set-2, 1 Mark]
16. The number of distinct minimum spanning trees for the
weighted graph below is _____ [2014, Set-2, 2 Marks]
(a) (b)
2

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]

1. Degree of each vertex in Kn is V = {P1, P2, P3, P4, P5}


(a) n (b) n – 1 There are six edges and thus six pairs of vertices; hence
E = [{P1, P4}, {P2, P3}, {P2, P4}, {P2, P5}, {P4, P5}, {P3, P5}]
(c) n – 2 (d) 2n – 1 3. Degree of vertex P3 will be
2. If G and G° are isomorphic graphs, then number of connected (a) 1 (b) 2
components of G° if G has connected components, are (c) 3 (d) None of these
(a) 4 (b) 6 4. Degree of vertex P5 will be
(c) 8 (d) 10 (a) 1 (b) 2
Common Data Qs. 3-4: (c) 3 (d) 4
P2 5. If n is an isolated vertex in a graph (multigraph) G, then what
P1 is its degree?
(a) 0 (b) 1
(c) 2 (d) 3
P4 6. Let G be an arbitrary graph with n nodes and k components.
P3 If a vertex is removed from G, the number of components in
the resultant graph must necessarily lie between
P5 (a) k and n (b) k – 1 and k + 1
There are five vertices, so (c) k – 1 and n – 1 (d) k + 1 and n – k
EBD_7203
S2-64 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

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

a11 a12 a13 b1 a12 a13 Sample Problem


b2 a22 a23 é1 2ù
D = a21 a22 a23 , D1 =
Find eigen values and eigen vectors of matrix A = ê
a31 a32 a33 b3 a32 a33 ë5 4úû
Sol. Charac. equation, | A – lI | = 0
a11 b1 a13 a11 a12 b1
1- l 2
D2 = a21 b2 a23 , D3 = a21 a22 b2 =0
5 4-l
a31 b3 a33 a31 a32 b3
(1 – l) (4 – l) – 10 = 0
2
D D D l – 5l + 4 – 10 = 0
Solution of equation is : x = 1 , y = 2 , z = 3 2
D D D l – 5l – 6 = 0
(l – 1) (l + 6) = 0
Eigen Values and Eigen Vectors
\ Eigen values are – 6, 1
For an n × n matrix A and a scalar l, characteristic matrix of A is
A – lI. The equations | A – lI | = 0 is called characterisic equation Eigen vector x is
and its roots is called eigen values. given (A –l I) X = 0
For eigen values (l) of matrix A, there is a non zero vector X such when l = – 6
that AX = lX is called characteristic vector (eigen vector) of A.
é7 2ù é x ù é0ù
Relations between Eigen values and Eigen vector ê5 10 úû ê y ú = ê0ú
· l is a eigen values of a matrix A if and only if there exists a ë ë û ë û
non-zero vector X such that x y
AX = l X 7x + 2y = 0 Þ = ; 5x + 10y = 0 Þ x + 2y = 0
-2 7
· If X is a characteristic vector of a matrix A corresponding to
the characteristic value l, then KX is also a characteristic vector x y
Þ =
of A corresponding to the same characteristic value l. Here K is -2 1
any non-zero scalar. when l = 1
· If X is a eigen vector of a matrix A, then X cannot correspond
to more than one eigen value of A. é0 2ù é x ù é0ù
ê5 =
3 úû êë y úû êë 0úû
· Eigen vectors corresponding to distinct characteristic roots Eigen vectors : (– 2, 7)
ë
of a matrix are linearly independent.
(– 2, 1)
Properties of Eigen Values x y
· Sum of eigen values is equal to sum of element of principal y = 0, 5x + 3y = 0 Þ =
-3 5
diagonal of the matrix i.e.
· Product of eigen values = determinant of the matrix. Eigen vector (– 3, 5)
EBD_7203
S2-72 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

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ú

(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

8. The system of equation x + y + z = 1, 2x + 3y + 4z = 1,


é 1 2 3ù 4x + 5y + 6z = 2 has
1. Find rank of the matrix ê1 3 5ú . (a) unique solution (b) infinite solution
ê ú
ëê 2 5 8úû (c) no solution (d) none of these
(a) 1 (b) 2
é1 1 1ù
(c) 3 (d) 0 ê ú
9. The eigen values of the following matrix is ê1 1 1ú
é 4 2 1 3ù êë1 1 1úû
2. Find rank of the matrix ê 6 3 4 7ú . (a) 1, 1, 1 (b) 1, 0, 0
ê ú
êë 2 1 0 1úû (c) 3, 0, 0 (d) 0, 0, 0
(a) 0 (b) 1
é1 2 3ù
(c) 2 (d) 3 10. What is sum of eigen values of the matrix is ê 4 5 6ú
ê ú
é3 0 0 0ù êë7 8 9 úû
ê0 0 0 0ú
3. Find rank of the matrix ê ú. (a) 1 (b) 5
ê0 0 2 0ú (c) 9 (d) 15
ê ú
ë0 0 0 –2û
é 1 2ù
11. What is the inverse of matrix is ê ú
(a) 0 (b) 1 ë 4 3û
(c) 2 (d) 3
é 3 – 4ù é 3 –2 ù
é 4 –2ù (a) ê –2 1 ú (b) ê ú
4. The eigen values of matrix ê ú are ë û ë– 4 1 û
ë –2 1 û
(a) 1, 4 (b) –1, 2 é 3 2 ù é 3 4 ù
ê– 5 ê– 5 ú
(c) 0, 5 (d) 4, 2 (c) 5 ú (d) ê 5 ú
ê ú
If l is eigen value of matrix A, then eigen value of matrix ê 4 1 ê 2 1
– ú
5. – ú êë 5
A–1 is ëê 5 5 ûú 5 úû

1 12. A–1 is equal to


(a) l (b)
l adj A
(a) |A| . adj A (b)
(c) l2 (d) l A
6. Consider the matrices X(4 × 3), Y(4 × 3) and P(2 × 3). The
A
(c) (d) (adj A)T
( )
T
order of é P X T Y P ùú is
–1 T adj A
êë û
13. The co-factors of diagonal elements in the matrix
(a) 2 × 2 (b) 3 × 3
(c) 4 × 3 (d) 9 × 3 é1 2 5ù
ê 2 3 6ú
7. The equation x + y + z = 2, x + 2y + 3z = 7, x + 4y + 7z = 17 ê ú are
are ëê 2 1 2úû
(a) consistent with unique solution
(a) 0, –8, –1 (b) 0, 8, 1
(b) consistent with infinite solution
(c) 1, 3, 6 (d) 1, 2, 2
(c) inconsistent
(d) none of these
LINEAR ALGEBRA S2-75
14. For three 3 × 3 square matrices A, B and C; (ABC)–1 is 21. If A, B and C are three 3 × 3 square matrices, then (ABC)–1
equal to is equal to
(a) A–1 B–1 C–1 (b) C–1 B–1 A–1 (a) A–1 B–1 C–1 (b) C–1 B–1 A–1
(c) A–1 C–1 B–1 (d) B–1 C–1 A–1 (c) A–1 C–1 B–1 (d) B–1 A–1 C–1

é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

(a) 7 (b) 12 24. Real numbers [A]3 × 1, [B]3 × 3, [C]3 × 5, [D]5 × 3,


[E]5 × 5 and [F]5 × 1 are given. The matrices [B] and [F]
(c) 3 (d) 2
are symmetric. Following statements are made with
é1 2 0ù respect of these matrices.
19. For what value of x matrix is A = ê 2 3 1 ú is singular? I. Matrix product [F]T [C]T [B] [C] [F] is a scalar.
ê ú
êë 2 0 x úû II. Matrix product [D]T [F] [D] is always symmetric.
With reference to above statements, which of the
(a) 0 (b) 2
following applies?
(c) 3 (d) 4
(a) Statement I is true but II is false
é1 2 ù (b) Statement I is false but II is true
20. Find the inverse of the matrix ê ú.
ë5 8û (c) Both the statements are true
(d) Both the statements are false
é 1 2ù é –4 1 ù
(a) ê5 8ú (b) ê ú
ë û ê 5 – 1ú é 1 2 –1ù
ë2 2û 25. Rank of matrix A = êê 1 1 0 úú .
êë 4 1 3 úû
é4 1ù é –4 1 ù
(c) ê5 (d) ê ú
ê 1 úú ê 5 1ú (a) 3 (b) 2
ë2 2û ë 2 2û (c) 1 (d) 0
EBD_7203
S2-76 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

é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úû

27. The equations ax + by = 0 and cx + dy = 0 has non trivial


solution if é 2 2 -2 ù é 12 1
2
–1

ê –2 2 –2ú ê –1 1 –1 ú
(a) ab = cd (b) ac = bd (c) ê ú (d) ê 2 2 2ú
(c) ad = bc (d) none of these êë 0 2 2 úû êë 0 0 1 úû
28. 2x + 3y = 2 35. The rank of the following (n + 1) × (n + 1) matrix, where
3x + 4y = 2
x + 3y = 4 é1 a a 2 .....a n ù
ê ú
These system of equations has ê1 a a 2 .....a n ú
a is a real number is ê ú
(a) unique solution (b) no solution êM M M ú
ê ú
(c) two solutions (d) infinite solutions ë1 a a 2 .....a n û
29. How many addition and multiplication operations are
needed to find product of matrix A(m × n) and B(n × q)? (a) 1 (b) 2
(c) n (d) depends on value of n
(a) mnp, mnp (b) mn2p, (n + 1)
(c) mn2p (n – 1) (d) mnp, (n – 1) é0 1 0ù
30. What is the rank of the 3 × 3 formed by multiplying a 36. ê
Given matrix A = ê 0 0 1 úú . Its eigen values are
(3 × 1) column matrix and a (1 × 3) row matrix? êë –6 –11 –6 úû
(a) 3 (b) 2
–1, –2, and _____.
(c) 1 (d) 0
é1ù
é a 1ù
31. The eigen values of the matrix ê ú are: 37. The vector êê 2 úú can eigen vector of
ë a 1û
ëê –1ûú
(a) (a + 1), 0 (b) a, 0
(c) (a – 1), 0 (d) 0, 0 é –2 2 –3ù
32. A 5 × 7 matrix has all its entries equal to 1 then rank of A = êê 2 1 –6 úú
. One of the eigen values of A is
matrix is êë –1 –2 0 úû

(a) 7 (b) 5 (a) 1 (b) 2


(c) 1 (d) 0 (c) 5 (d) –1
33. The number of linearly independent solution of the system
é2 0 0 –1ù
ê0 1 0 0 úú
é 1 0 2ù é x1 ù 38. A=ê . The sum of the eigen values of
of equations ê 1 –1 0ú ê x2 ú = 0 is equal to ê0 0 3 0ú
ê úê ú ê ú
êë 2 –2 0úû êë x3 úû ë –1 0 0 4û
matrix A is
(a) 1 (b) 2
(a) 10 (b) – 10
(c) 3 (d) 0 (c) 24 (d) 22
LINEAR ALGEBRA S2-77

é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

é 6 2ù é4 6ù é cos 2 q cos q sin q ù


(a) ê2 6ú (b) ê 6 4ú A =ê ú and
ë û ë û êëcos q sin q sin 2 q úû

é 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

PAST GATE QUESTIONS EXERCISE


é0 0 1ù
1. (c) Given equations are ê 0 1 0ú
x + 2y + 3z = 4 A –1 = ê ú
2x + 3y + 8z = 7 êë1 0 0úû
x – y + 9z = 1
é 2 1 – iù
é 1 2 3 : 4ù 4. (d) Since A = ê ú
ê2 3 8 : 7ú ë1 + i 6 û
Here [A : B] = ê ú
êë 1 –1 9 : 1 úû é 2 1 + iù
A=ê ú
ë1 – i 6 û
é 1 0 0 : 0 ù C 2 ® C2 –2C1
~ êê 2 –1 2 : –1úú C3 ® C3 –3C1 ( A ) T = éê
2 1 - iù
=A
êë 1 –3 6 : –3úû C4 ® C4 –4C1 ë1 + i 6 úû
\ A* = A
é1 0 0 : 0ù Hence A is a Hermitian matrix.
~ êê 2 –1 2 : –1úú , R 3 ® R 3 –3R1 é0 a bù
êë –5 0 0 : 0 úû ê ú
5. (b) Let A = ê – a 0 c ú be non null skew symmetric
r (A : B) = 2 ëê –b – c 0úû
Also r (A) = 2
matrix. Hence at least one out of a, b, c must not be
r (A : B) = r (A)
zero.
= 2 < 3 (number of variables)
Let a ¹ 0 Then
Hence, given equations are consistent and have infinite
solutions. é 0 aù 2
2. (b) Let A and B be orthogonal, then ê – a 0 ú = a ¹0
ë û
AA¢ = i and BB¢ = I
Now, (AB) (AB)¢ = (AB) (B¢A¢) = A (BB¢) A¢ Hence rank is 2. Thus in any case rank cannot be 1.
= A (I) A¢ = AA¢ = I
é1 3 4ù
Similarly, (AB)¢ (AB) = I ê ú
Hence AB is orthogonal 6. (c) Let A = ê1 3 5 ú
êë1 3 4úû
é0 0 1ù
ê ú R2 ® R2 – R1
3. (b) A = ê0 1 0ú R3 ® R3 – R1
ëê1 0 0úû
é1 3 4ù
C11 = 0 C22 = -1 C33 = 0 A = êê0 0 1 úú
C12 = 0 C23 = 0 êë0 0 0 úû
C13 = -1 C31 = -1
3 4
C21 = 0 C32 = 0 Minor = =3¹0
0 1
|A| = –1
So Rank = 2
T 7. (a) For symmetric matrix,
é 0 0 -1ù
ê ú (AB)¢ = AB;
A–1 = (-1) ê 0 -1 0 ú B¢A¢ = AB
êë -1 0 0 úû It is true only if A¢ = A
and B¢ = B
é 0 0 -1ù \ BA = AB (which is given)
(-1) ê 0 -1 0 ú Hence AB will be symmetric if A and B are symmetric.
A–1 = ê ú
êë -1 0 0 úû 8. (b)
LINEAR ALGEBRA S2-81
9. (a) If A is n × n ordered determinant
|KA| = Kn |A| é 2 –2 –4 ù
A = ê –1 3 4 ú
hence n = 4 12. (d) Since ê ú
Þ | 2A | = 24 Þ| A | = 16 | A | êë 1 –2 –3úû
10. (a) det A = |A|
therefore
= 5 [3 – 0] – 0 [0 – 2] + 2 [0 – 6]
= 15 – 12 = 3 é 2 –2 –4ù é 2 –2 –4 ù
A.A= êê –1 3 4 úú ´ êê –1 3 4 úú
é 3 0 –6 ù
ê0 1 0ú êë 1 –2 –3úû êë 1 –2 –3úû
Adj A = ê ú
êë –6 0 15 úû
é 2 –2 –4ù
= êê –1 3 4 úú = A
AdjA
\ A –1 = êë 1 –2 –3úû
|A|
\ A2 = A
é 3 0 –6 ù é 1 0 –2ù Hence A is an idempotent matrix.

= ê 0 1 0 ú = ê 0 1/ 3 0 úú
ú ê
é1 1 ù
3 13. (d) A=ê
êë –6 0 15 úû êë –2 0 5 úû ú
ë1 -1û 2 ´ 2
11. (a) Given equations are
A - lI = 0
– 2x + y + z = a
The determinant of the given matrix
x – 2y + z = b
x + y – 2z = c æ é1 1 ù é1 0 ùö
det ç ê ú -lê ú÷ = 0
Augmented matrix, è ë1 -1û ë0 1ûø

é –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

1 This is identity Matrix, Determinant of Identity matrix


is also its eigen value. But this does not implies is 1.
l1
|li | = 1 for all i. 1 0 0 0
24. (b) Order of [F]T [C]T is (1 × 5) (5 × 3) = (1 × 3)
0 1 0 0
Order of [F]T [C]T [B] = (1 × 3) (3 × 3) = (1 × 3) \ =1
Order of [F]T [C]T [B] [C] = (1 × 3) (3 × 5) = (1 × 5) 0 0 1 0
Order of [F]T [C]T [B] [C] [F] = (1 × 5) (5 × 1) = (1 × 1) 0 0 0 1
\ it is not scalar.

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

= 1(3 – 0) – 2(3 – 0) – 1(1 – 4) 2 3 2


=3–6+3=0
28. (a) 3 4 2
1 2 1 3 4
= 1 – 2 = –1
1 1
\ Rank of [A] = 2. = 2(16 – 6) – 3(12 – 2) + 2(9 – 4)
= 2 × 10 – 3 × 10 + 2 × 5
1 0 0 0 = 20 – 30 + 10 = 0
32 1 0 0 \ it has unique solution.
26. (b) 29. (d)
63 60 1 0
52 31 16 1
éa ù
30. (d) Column matrix be A = ê b ú and row matrix
1 0 0 0 ê ú
R ® R 2 - 32 R1 êë c úû
0 1 0 0 2
R ® R 3 - 63 R 3
0 60 1 0 3 be B = [d e f]
R 4 ® R 4 - 52 R 4
0 31 16 1
éa ù é ad ae af ù
ê ú ê bd be bf ú
1 0 0 0 (AB) = ê b ú [ d e f ] = ê ú
0 1 0 0 ëê c ûú ëê cd ce cf úû
R ® R 3 ® 60 R 2
0 0 1 0 3
0 31 16 1 ad ae
|AB| = 0 (try it yourself);
bd be
1 0 0 0
= abed – abed = 0.
0 1 0 0
R ® R 4 - 31 R 2 é a 1ù
0 0 1 0 4
31. (a) A = ê ú
0 0 16 1 ë a 1û
|A–lI| = 0
1 0 0 0
a–l 1
0 1 0 0 =0
R ® R 4 - 16 R 3 a 1– l
0 0 1 0 4
0 0 0 1
l 2 – (a + 1)l + 0 = 0
\ l = 0, a + 1
EBD_7203
S2-86 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
36. Sum of eigen values = sum of diagonal elements
é1 1.........1ù \ (– 1) + (–2) + x = – 6
ê1 1.........1úú \ x = – 3.
32. (c) A= ê \ Other eigen value is – 3
êM 1.........1ú
ê ú 37. (c) AX = lX l is eigen value of A
ë1 1.........1û5 ´ 7
é –2 2 –3ù é 1 ù
AX = êê 2 1 –6úú êê 2 úú
Apply R2 – R1, R3 – R1, R4, – R1, R5 – R1
we get,
êë –1 –2 0 ûú êë –1úû
é1 1 1.....1ù
ê0 0 0.....0úú é5ù é1ù
ê
ê0 0 0.....0ú = êê10 úú = 5 êê 2 úú
= lX
ê ú êë –5úû êë –1úû
êM M M ú
êë0 0 0.....0úû \ l=5
38. (a) sum of eigen values = sum of diagonal elements =
Rank = no.of non- zero rows = 1 10
é1 0 2ù é x1 ù é0ù adjA
ê1 –1 0 ú ê x ú = ê0ú 39. (a) A –1 =
ê ú ê 2ú ê ú
|A|
33. (a)
êë 2 –2 0 úû êë x3 úû êë0úû or you can use a calculator.
40. (a) Eigen values of matrix s2 are 12 and 52 is 1 and 25
R2 ® R2 – R1, R3 ® R3 – 2R1 41. (c) Given E F = G
é1 0 2 ù é x1 ù é0ù \ F = E–1 G
ê 0 –1 –2ú ê x ú = ê0ú G=I
ê ú ê 2ú ê ú \ F = E–1
êë 0 –2 –4úû êë x3 úû êë0úû 42. (b) Eigen values = 2, 2
(triangular matrix)
R3 ® R3 – 2R2
é2 – l 1 ù
é1 0 –2ù é x1 ù é0ù [A – lI] = ê 0
ê 0 –1 –2ú ê x ú = ê0ú ë 2 – l úû
ê úê 2ú ê ú
êë 0 0 0 úû êë x3 úû êë0úû é0 1ù
where l = 2, [A – lI] = ê 0 0 ú
rank (A) = P (A) = 2; n = 3 ë û
\ No. of independent solution No. of linearly independent eigen vector of A
=n–r =1 = no. of variables – p(A – lI)
=2–1=1
é1 –1 0ù 43. (a) mT = m–1
34. (d) s = êê1 1 1úú Þ mmT = I
êë0 0 1úû
é3 4ù é3 ù
ê5 xú
|s| = 1 (1 + 1) = 2 ¹ 0 5ú ê5 é1 0ù
ê úê ú=
êx 3ú ê4 3 ú êë0 1 úû
é 1 1 –1ù êë 5 úû ëê 5 5 ûú
adj (s ) = êê –1 1 –1úú
\ x = – 4/5
êë 0 0 2 úû
é1 1 0 ù é1 1 0 ù
é –1 1 –1 ù 44. (c) A = êê 0 1 –1úú = ê0 1 –1ú R 3 ® R 3 – 2R1
ê2 2 ê ú
2ú êë 2 1 1 úû êë0 –1 1 úû
ê ú
adj ( s) ê –1 1 –1 ú
s –1 = =
|s| ê2 2 2ú é1 1 0 ù
ê ú
ë0 0 1û = êê0 1 –1úú R 3 ® R 3 + R 2
35. (a) Apply R2 – R1, R3 – R1, R4 – R1.... êë0 0 0 úû
Then these is only one non zero row ie, R1. P (A) = 2, n = 3
\ Rank of A, P (A) = 1 \ infinite solution (P(A) < n)
LINEAR ALGEBRA S2-87
45. (c) cos 2x = cos2x – sin2x. 2x1 –2 x2 = 0
= cos2 x + (–1) sin 2x. & x1 – x2 = 0
\ They are linearly dependent \ x1 = x2
\ There are infinte no. of solutions
é1 + b b 1ù
46. (a) D = ê b 1 + b 1úú
ê é 1 2 1 4ù é1 2 1 4 ù
êë 1 53. (c) ê2 1 2 5ú ê ú R 2 –2R 2
2b 1úû ê ú = ê0 –3 0 –3ú R –R
3 1
ëê 1 –1 1 1 úû êë0 –3 0 –3úû
c1 ® c1 + c2 + c3

é 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 úû

Q c1 and c3 are proportional P(A:B) = P(A) = 2 < 3


D=0 \ infinite number of solution.

é –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.

L-U DECOMPOSITION METHOD


Sample Problems
The coefficient matrix A of the system of equations AX = B is
1 Find a root of the equatrion x3 – 8x – 5 = 0, using the secant
decomposed into the product of a lower triangular matrix L and
method.
an upper triangular matrix U, so that
EBD_7203
S2-92 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
A = LU ...(i)
1 3 1 5
é l11 0 0 ...0 ù Þ l 21 = , l31 = , m 22 = , m 23 = , l32 = -7, m33 = 18
2 2 2 2
êl 0 ... 0 úú
ê 12 l 22 Thus, we get
where L = ê l13 l23 l33 ... 0 ú A = LU
ê ú
ê : : : : : ú
êl1n l 2n l3n ... lnm úû é 1 0 0ù é2 3 1 ù
ë
= ê1/ 2 1 0ú ê0 1/ 2 5/ 2 ú
ém11 m 21 m31 ... m n1 ù ê úê ú
ê 0 m ú êë3/ 2 -7 1úû ëê0 0 18 ûú
ê 22 m32 ... m n2 ú
and U=ê 0 0 m33 ... m n3 ú The given system is
ê ú AX = B
ê : : : : : ú
êë 0 0 0 : m nn úû Þ LUX = B ...(i)
Using the matrix multiplication and comparing corresponding Let UX = y, so that Eq. (i) becomes
elements in Eq (i), we obtain LY = B
li1m1j + li2m2j + ... + lin mnj = aij , 1£ j £ n
é 1 0 0ù é y1 ù é9ù
Where, lij = 0 j > i and µif = 0 (i > j) ê1/ 2 1 0ú ê y ú = ê6ú
To produce a unique solution, it is convenient to choose either ê ú ê 2ú ê ú which gives
êë3/ 2 -7 1úû êë y3 úû êë8úû
µii = 1 or lii = 1; 1 £ i £ n
(i) when we choose lii = 1, the method is called the
Doolittle’s method 3
y1 = 9, y2 = , y3 = 5 [by forward substitution]
(ii) when we choose µii = 1, the method is called the 2
Crout’s method. Now, UX = Y
The given system of equation is
é2 3 1 ù é x1 ù é 9 ù
AX = B ...(ii)
ê 0 1/ 2 5/ 2ú ê x ú = ê3/ 2ú
Þ LUX = B [by Eq. (i)] ...(iii) ê ú ê 2ú ê ú
Let UX = Y, then Eq. (iii) becomes ëê 0 0 18 ûú êë x 3 úû ëê 5 ûú
LY = B ...(iv)
which gives by back substitution
The unknowns y1, y2, y3, ......, yn in Eq. (iv) are determined by
forward substitution and the unknowns x1, x2, x3, ......, xn in 35 29 5
x1 = , x2 = , x3 =
UX = Y are obtained by back substitution. 18 18 18
1. The method fails if any of the diagonal elements lii or
µii is zero BISECTION METHOD
2. L-U decomposition is guaranteed when the matrix A This method is based on the repeated application of intermediate
is positive definite. value property.
Let the function f(x) be continuous between a and b. For
Sample Problem
definiteness, let f(a) be negative and f(b) be positive.
Solve the following system of equations by the LU
factorization method. 1
Then, the first approximation to the root is x1 = (a + b).
2x + 3y + z = 9 2
x + 2y + 3z = 6 If f(x1) = 1, then x1 is the root of f(x) = 0 otherwise, the root lies
3x + y + 2z = 8 between a and x1 or x1 and b according as f(x1) is positive or
Sol. We choose lii = 1 and write negative. Then, we bisect the interval as before and continue the
0ù ém11 m12 m13 ù process until the root is found to desired accuracy. In the figure
é 2 3 1ù é 1 0
ê 1 2 3ú = ê l úê ú f(x1) is positive so that the root lies between a and x1. Then,
1 0ú ê 0 m 22 m 23 ú
ê ú ê 21
1
ëê 3 1 2úû êë l31 l32 0úû êë 0 0 m33 úû second approximation to the root is x 2 = (a + x1 ). If f(x2) is
2
é m11 m12 m13 ù
ê ú negative. The root lies between x 1 and x 2. Then, the third
= êl21m11 l 2m12 + m 22 l21m13 + m 23 ú
êël31m11 l31m12 + l32 m 22 l31m13 + l32 m 23 + m33 úû 1
approximation to root is x 3 = (x1 + x 2 ) and so on.
2
Equating, we get µ11 = 2, µ12 = 3, µ13 = 1
NUMERICAL METHODS S2-93
Y Since, h is small, neglecting h2 and higher powers of h,
we get
f(x0) + h f (x0) = 0
f ( x0 )
y = f(x) f(b) or h=- ...(i)
f' ( x0 )
A better approximation than x0 is therefore given by x1, where
f ( x0 )
a x2 x1 = x0 -
X f' ( x0 )
O f(a) x3 x1
Successive approximation are given by x2, x3, ..., xn + 1,
We observe that this method uses only the end points of the f ( xn )
xn +1 = xn -
interval [an, bn] for which f(an) f(bn) < 0 and not the values of f(x) f' ( xn ) (n = 0, 1, ...) ...(ii)
at these end points to obtain the next approximation to the root. which is the Newton-Raphson formula.
Note : The order of convergence of Bisection method is 1/2, so
the bisection method is linearly convergent. Remarks
1. This method is useful in cases of large value of f '(x), i.e.
Sample Problem when the graph f(x) while crossing the X-axis is nearly
Find the root of the equation x3 – 4x – 9 = 0 using Bisection vertical.
method in four stages. 2. If f ' (x) is zero or nearly 0, the method fails.
Sol. f(x) = x3 – 4x – 9 3. Newton’s formula converges provided the initial
Since, f(2.706) = –0.009488 i.e., (–)ve approximation x0 is chosen sufficiently close to the root.
f(2.707) = 0.008487 i.e. (+)ve This method is also called the method of tangents.
Hence, the root lies between 2.706 and 2.707. 4. This method is also used to obtain complex root.
\ First approximation to the root is Note : The order of convergence of Newton-Rephson method is
2.706 + 2.707 2, i.e., Newton-Raphson method is quadratic convergent.
x1 = = 2.7065
2
Sample Problem
Now, f(x1) = – 0.00050525 i.e.m (–)ve
Find the real root of x log10 x = 1.2 correct to five decimal
Hence, the root lies between 2.7065 and 2.707.
places by Newton-Raphson method.
\ Second approximation to the root is
Sol. f(x) = x log10 x – 1.2
2.7065 + 2.707
x2 = = 2.70675 f (1) = – 1.2 = (–) ve
2 f (3) = 3 log10 3 – 1.2 = (+) ve
f(x2) = 0.003992 i.e., (+)ve
So, a root of f (x) = 0 lies between 1 and 3.
Hence, the root lies between 2.7065 and 2.70675.
Let us take x0 = 2
\ Third approximation to the root is
Also, f ' (x) = log10 x + log10 e = log10 x + 0.43429
2.7065 + 2.70675
x3 = = 2.706625 Newton’s iteration formula gives
2
f(x3) = 0.001744 i.e., (+)ve f ( xn )
xn +1 = xn -
Hence, the root lies between 2.7065 and 2.706625. f' ( xn )
\ Fourth approximation to the root is xn log10 xn - 1.2
= xn -
2.7065 + 2.706625 log10 xn + 0.43429
x4 = = 2.7065625
2 0.43429 xn + 1.2
Hence, the root is 2.706 correct to three decimal places. =
log10 xn + 0.43429
NEWTON-RAPHSON METHOD Putting n = 0 the Ist approximation is
Let x0 be an approximate root of f(x) = 0 and let x1 = x0 + h be the x1 = 2.81 (Q x0 = 2) ...(i)
correct root so that Similarly, putting n = 1, 2, 3, 4 in Eq. (i), we get
f(x1) = 0 x2 = 2.741, x3 = 2.74064, x4 = 2.74065, x5 = 2.74065
Expanding f(x0 + h) by Taylor’s series, we get Clearly, x 4 = x5
Hence, the required root is 2.74065 correct to five decimal
h2
f ( x0 ) + hf' ( x0 ) + f'' ( x0 ) + ... = 0 places.
2!
EBD_7203
S2-94 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
NUMERICAL INTERGRATION Trapezoidal rule is a numerical method that approximates
The process of evaluating a definite integral from a set of value of a definite integral.
b
tabulated values of the integrand f(x) is called numerical
integration. This process when applied to a function of a single Consider the definite integral ò f ( x)dx.
a
variable is called quadrature. Assume that f(x) is continuous on [a, b] and divide [a, b]
1. Newton-Cote’s quadrature formula into n subintervals of equal length
b b-a
Dx =
Let I = ò f ( x )dx n
a
using n + 1 points x0 = a, x1 = a + Dx, x2 = a + 2Dx,....., xn =
where f(x) takes the values y0, y1, y2, ..........., yn. For x = x0, a + nDx = b.
x1, x2....xn divide the interval (a, b) into n-sub-intervals of Compute value of f(x) at these points.
width h, so that
x0 = a, x1 = x0 + h, x2 = x0 + 2h, ........., xn = x0 + nh = b. y0 = f ( x0 ), y1 = f ( x1 ), y2 = f ( x2 ), ..., yn = f ( xn )
Approximate integral by using n trapezoids formed by
x0 + nh
using straight line segments between points (xi – 1, yi – 1)
Then I= ò f ( x)dx and (xi, yi) for 1 £ i £ i n as shown in the figure below.
x0

Putting x = x0 + rh y

Þ dx = hdr
n
\ I = h ò f ( x0 + rh)dr
0

By Newton's forward interpolation formula yn–2 y


n–1
y0 yn
y1 y2 y3
n
é r ( r - 1) 2 r (r - 1)( r - 2) 3 ù
I = h ò ê y0 + r Dy0 + D y0 + D y0 + ...údr z
2! 3! ... ...
0ë û a = x0 x1 x2 x3 xn–2 x n–1 x = b
Dx n

Area of a trapezoid is obtained by adding areas of a


é r (r - 1) 2 r (r - 1)(r - 2) 3 ù
I = h ê y0 + r D 0 + D y0 + D y0 + ...údr rectangle and triangle.
ë 2! 3! û
1 ( y + y ) Dx
Integrating term by term, we get A = y0Dx + ( y1 - y0 )Dx = 0 1
2 2
x0 + nh
é n n(2 n - 3) n(n - 2) ù
ò f ( x)dx = nh ê y0 + Dy0 +
êë 2 12
D y+
24
D y + ...ú
úû
y1 – y0
x0
y1
y0
y0
é n n(2n - 3) 2 n (n - 2) 2 3 ù
f ( x )dx = nh ê y + Dy + D y+ D y + ...ú ...(i)
ëê 2 12 24 ûú Dx Dx

2. Trapezoidal Rule Adding area of the n trapezoids, the aproximation obtained


For definite integrals such as is
b
1 1 ( y0 + y1 )Dx ( y1 + y2 ) Dx ( y2 + y3 ) Dx
ò
3
1 - x dx or òe
-x 2
dx ò f ( x)dx » 2
+
2
+
2
0
0 0
( yn -1 + yn )Dx
fundamental theorem of calculus cannot be used to evaluate +... +
2
them since there are no elementary functions that are which simplifies to the trapezoidal rule formula.
2
antiderivatives of 1- x3 or e - x . Approximation b
Dx
methods are used for such integrals. ò f ( x)dx » 2
( y0 + 2 y1 + 2 y2 + ... + 2 yn -1 + yn )
a
NUMERICAL METHODS S2-95
Sample Problem x0 + 3h
æ 3 3 1 ö
5
ò f ( x) dx = 3h ç y0 + Dy0 + D 2 y0 + D 3 y0 ÷
è ø
ò
2 2 4 8
1. Use trapezoidal rule with n = 8 to estimate 1 + x dx. x0
1
5 -1 3h
Sol. For n = 8, Dx = = 0.5. = ( y0 + 3 y1 + 3 y2 + y3 )
8 8
Compute the values of y0, y1, y2, ... ,y8. x0 + 6 h
3h
x 1 1.5 2 2.5 3 3.5 4 4.5 5 Similarly, ò f ( x ) dx = ( y + 3 y4 + 3 y5 + y6 )
8 3
x0 + 3h
2
y = 1+ x 2 3.25 5 7.25 10 13.25 17 21.25 26 Adding all such expressions form x0 to x0 + nh, where n is
Therefore, a multiple of 3, we get
5 x0 +nh
0.5 3h
ò 1 + x 2 dx »
2
( 2 + 2 3.25 + 2 5 + 2 7.25 + 2 10 ò f ( x)dx = [( y + y ) + 3( y1 + y2 + y4 + y5 + ... + yn -1)
8 0 n
1 x0
+2 13.25 + 2 17 + 2 21.25 + 26) +2( y3 + y6 + yn -3 )]
» 12.76
2. Following points were found empirically. Sample Problem
6
x 2.1 2.4 2.7 3.0 3.3 3.6 dx 1
y 3.2 2.7 2.9 3.5 4.1 5.2 Evaluate ò 1 + x2 by using Trapezoidal rule, Simpson's
3
0
3.6 3
Use the trapezoidal rule to estimate ò y dx. rule, and Simpson's
8
rule,
2.1 Sol. Divide the interval (0, 6) into six parts each of width h = 1.
Sol. By inspection, Dx = 0.3
3.6 1
0.3 The value of f ( x) = are given below :
\ ò ydx » (3.2 + 2(2.7) + 2(2.9) + 2(3.5) + 2(4.1) + 5.2) 1 + x2
2.1
2
» 5.22
x 0 1 2 3 4 5 6
3. Simpson's one-third rule
Putting n = 2 in equation (i) above and taking the curve f ( x) 1 0.5 0.2 0.1 0.0588 0.0385 0.027
through (z0 z0) (z1, y1) and (z2, y2) as a parabola, i.e. a y0 y1 y2 y3 y4 y5 y6
polynomial of second order os that differences of order
higher than second vanish, we get (i) By Trapezoidal rule.
x0 + 2 h 6
æ 1 ö dx h
ò f ( x ) dx = 2 h ç y0 + Dy0 + D 2 y0 ÷
è 6 ø
ò 1 + x2 = [( y0 + y6 ) + 2( y1 + y2 + y3 + y4 + y5 )]
2
x0 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

PAST GATE QUESTIONS EXERCISE 4. (d) f (x) = x2 – 13 = 0, f¢ (x) = 2x


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

e xk –1 e xk .xk – e xk + 1 3 +1
xk +1 = xk – = ...(i) 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

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.

13. (a) Let f (x) = x3 + 4x – 9 = 0 y0 y1 y2


f ¢(x) = 3x2 + 4 = 0 18. (c) x 1 2 3 (h =1)
Now, Newton-Raphson method y 1 0.5 0.33

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

2. lim [ f ( x) ± g ( x)] = lim f ( x ) ± lim g ( x ) f ( x) f ¢( x )


x® a x®a x ®a lim = lim
x® a f( x ) x® a f ¢ ( x )
lim f ( x )
f ( x ) x ®a æ ö If still f ¢ (x) and f¢ (x) has value zero at x = a, then
lim =
3. x® a g ( x ) lim g ( x ) çè lim g ( x) ¹ 0÷ø
x®a f ( x) f ¢¢( x )
x ®a
lim = lim and goes on.
x® a g ( x ) x® a ¢¢ ( x)
g
Important Limits
sin x tan x Sample Problem
1. lim = lim = lim cos x = 1
x®0 x x ®0 x x® 0 sin x 0
1. lim =
x x®0 x 0
æ 1ö
2. lim (1 + x )1/ x = lim ç 1 + ÷ = e Sol. By L’ Hospital Rule
x®0 x®¥ è xø
sin x cos x 1
loga (1 + x) lim = lim = =1
3. lim = log a e x®0 x x ®0 x 1
x®0 x
loge (1 + x) x 2 + x - sin x 0
2. lim =
4. lim = loge e = 1 x®0 x2 0
x®0 x
Sol. By L’ Hospital Rule
(1 + x) n –1
5. lim = n x 2 + x - sin x 2 x + 1 - cos x 0
x® 0 x Þ lim 2
= lim =
x®0 x x® 0 2x 0

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. Rolle’s theorem 9. ò sec x dx = log (sec x + tan x)


If a function f (x) is continuous in a closed interval [a, b] i.e.
a £ x £ b, and derivable in open interval (a, b) i.e. a < x < b, 10. ò cot x dx = log sin x.
and if f (a) = f (b), then there exist atleast one real c in (a, b)
such that f ¢(c) = 0 11. ò sec x tan x dx = sec x
2. Lagrange’s first mean value theorem
If a function f (x) is continuous in closed interval [a, b] and 12. ò cosec x cot x dx = – cosec x.
f ’(x) exist in open interval (a, b) then there exist atleast one
x
value of c such that, 13. ò cosec x dx = log (cosec x – cot x) = log tan 2
f (b ) – f ( a )
f ¢ (c) = 1
b–a ò dx = sin –1 x = – cos –1 x
14. 2
3. Cauchy’s mean values theorem 1– x
If two functions f (x) and g (x) are continuous in closed
1 –1 x
interval [a, b] and f ¢ (x) and g¢(x) both exist in open interval
(a, b) and g¢(x) ¹ 0, then there exist a point c such that
15. ò 1 + x 2 dx = tan
CALCULUS S2-105

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 ø

u is first function, v is second function. To find first function ¶ 2u ¶ 2u ¶ 2u


out of two we follow ‘ILATE’ rule. Similarly we have partial derivatives 2 , ¶y¶x , ¶x¶y
¶y
I-Inverse, L-Log function , A-Algebr aic funtion ,
T- Trignomatric function, E-Exponential function.
MAXIMA AND MINIMA
Sample Problem To find maximum and minimum values of function f (x)
–1
• Find f ¢(x) and take f ¢ (x) = 0 and find the roots.
e sin x
• Then find f ¢¢ (x) for each of these roots.
Calculate the integral ò dx
If f ¢¢ (a) > 0, f (a) is minimum value of f (x)
1 + x2
If f ¢¢ (a) < 0, f (a) is maximum value of f (x)
Sol. Let sin–1x = y
If f ¢¢ (a) = 0, f (a) is not maximum or minimum value.
Differentiate w.r.t. x
CU RL
dy 1
= Curl of a continuously differentiable vector point function F is
dx 1+ x2 defined by:
EBD_7203
S2-106 GATE – ELECTRONICS & COMMUNICATION ENGINEERING
resolved part of Ñf in the direction N¢.
¶F ¶F ¶F
Curl F = D × F = i ´ + j´ +k´ Since Ñf. N¢ = | Ñf | cos a £ | Ñf |
¶x ¶y ¶z If follows that Ñf gives the maximum rate of change of f.
If F = fi + fj + yk, then Vector Identities
F=D×F (i) grad (U + V) = grad U + grad V,
æ ¶ ¶ ¶ö i.e. Ñ ( U + V ) = ÑU + ÑV
= çè i. ¶x + j ¶y + k. ¶z ø÷ ´ (fi + fj + yk)
æ ® ®ö
(ii) div ç A + B ÷ = div A + div B ,
i j k ç ÷
è ø
¶ ¶ ¶
i.e. Ñ.A + Ñ.B
= ¶x ¶y ¶z
f f y æ ® ®ö
(iii) curl ç A + B ÷ = curl A + curl B,
è ø
æ ¶y ¶f ö æ ¶y ¶f ö æ ¶f ¶f ö
= iç - ÷ - jç - ÷+kç - ÷
è ¶y ¶z ø è ¶y ¶z ø è ¶x ¶y ø i.e. Ñ ´ ( A + B) = Ñ ´ A + Ñ ´ B

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

æ ¶f ¶f ¶y ö (xi) Ñ. ( Ñ ´ A ) = 0, i.e. div of the curl A = 0


div F = çè i. ¶x + j ¶y + k . ¶z ø÷
2
(xii) Ñ ´ ( Ñ´ A ) = Ñ (Ñ.A ) - Ñ A
Directional Derivative
If dr denotes the length PP¢ and N¢ is a unit vector in the direction æ f ö gÑf - f Ñg
Note: (i) Ñç ÷ = ; Ñ ( f.g ) = f Ñg - gÑf
df æ ¶f ö
è gø g2
PP¢, then the limiting value of as dr ® 0 ç i.e., ÷ is known
dr è ¶r ø
æ® ®ö
as the directional derivative of f at P along the direction PP¢. (ii) div ç r ´ a ÷ = 0 , if ar is a constant vector
ç ÷
è ø
dn dn
Since dr = =
cos a N.N ¢ æ ® ®ö
(iii) r r
curl ç r ´ a ÷ = -2a , if a is a constant vector
¶f é df ù è ø
\ = Lt N. N¢ ú = N¢. ¶f N = N¢ . Ñf
¶r dr ® 0 êë dn û ¶n (iv) if div f = 0, then f is called solenoidal.
Thus the directional derivation of f in the direction of N¢ is the
CALCULUS S2-107
Sample Problem 3. Find the angle between the surfaces
x2 + y2 + z2 = 9 and z = x2 + y2 – 3 at the point (2, – 1, 2).
1. If Ñu = 2r 4 R, find u. Sol. Let f1 = x2 + y2 + z2 – 9 = 0 and f2 = x2 + y2 – z – 3 = 0
Then, N = Ñf at (2, – 1, 2) = (2xiˆ + 2yjˆ + 2zk) ˆ at
( )
2 1 1
Sol. We have Ñu = 2 x 2 + y 2 + z 2 R
(2, – 1, 2) = 4iˆ - 2ˆj + 4kˆ
é
êQ r =
ë
( x 2 + y2 + z2 ) ùúû and N 2 = Ñf 2 at (2, – 1, 2) = (2xiˆ + 2yjˆ - k)
ˆ at (2, – 1, 2)

= 4iˆ - 2ˆj - kˆ

( ) ( xiˆ + yjˆ + zkˆ )


2
= 2 x 2 + y2 + z2 ...(i) Since the angle q between the two surfaces at a point is the
angle between their normals at that point and N1, N2 are the
normals at (2, – 1, 2) to the given surfaces, therefore
¶u ˆ ¶u ˆ ¶u ˆ
But Ñu = i+ j+ ...(ii)
( )( )
k
¶x ¶y ¶z N1.N 2 4iˆ - 2ˆj + 4kˆ 4iˆ - 2ˆj - kˆ
cos q = = .
Comparing (i) and (ii), we get n ln 2 (16 + 4 + 16) (16 + 4 + 1)

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

Sol. A vector normal to the given surface is Ñ xy3z2 -4 ( ) Sol. f ( x ) = 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

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

then ò F(R).dR = ò (f dx + fdy + ydz). and continuous functions u = f ( t ) and v = y ( t )


C C of a real parameter represent a curve C on this surface S.
Parametric representation of the circular cylinder.
Two other types of line integrals are ò F ´ dR and ò F dR which x2 + y2 = a2, – 1 £ z £ 1, (radius a and height 2) is
C C
are both vectors. R (u, v) = a cos u ˆi + a sin u ˆj + vkˆ
(1) Circulation: If F represents the velocity of a fluid particle where parameters u and v vary in the rectangle
0 £ u £ 2p and -1 £ v £ 1 .
then the line integral ò F. dR is called the circulation of F
Also u = t, v = bt represent a circular helix on this circular cylinder.
C
The equation of the circular helix is
around the curve. When the circulation of F around every
closed curve in a region E vanishes, F is said to be irrotational R = a cos t ˆi + a sin t ˆj + bt k.
ˆ
in E. Differentiating R = R (u, v), with respect to t, we get
(2) Work: If F represents the force acting on a particle moving
dR ¶R du ¶R dv
along an arc AB then the work done during the small = . + . .
displacement dR = F . dR. dt ¶u dt ¶v dt
\ the total work done by F during the displacement from A æ ¶R ö æ ¶R ö
The vectors ç ÷ and ç ÷ are tangential to S at P and
B è ¶u ø è ¶v ø
to B is given by the line integral ò F . dR. determine tangent plane of S at P.N
A
æ ¶R ö æ ¶R ö
Sample Problem ç ÷´ç ÷ ( ¹ 0 ) gives a normal vector N of S at P.
è ¶u ø è ¶v ø
A vector field is given by F = sin yiˆ + x 2 (1 + cos y)ˆj. Evaluate Smooth surface
the line integral over a circular path given by x2 + y2 = a2, z = 0. If S has a unique normal at each of its points whose direction
Sol. As the particular moves in xy-plane (z = 0), let R = xiˆ + yjˆ so depends continuously on the points of S, then the surface S is
called a smooth surface. If S is not smooth but can be divided into
that dR = dxiˆ + dyj.
ˆ Also the circular path is x = a cos t, y = a finitely many smooth portions, then it is called a piecewise smooth
sin t, z = 0 where t varies from 0 to 2p. surface. e.g. surface of sphere is smooth while the surface of a
cube is piecewise smooth.
\ Ñò F.dR = Ñò éësin yiˆ + x (1 + cos y ) ˆjùû ( dxiˆ + dyjˆ) Orientable and Non-orientable surfaces
C C
A surface S is said to be orientable or two sided if the positive
normal direction at any point P of S can be continued in a unique
Ñò éësin ydx + x (1 + cos y ) dy ùû
2
=
and continuous way to the entire surface. If positive direction of
C
the normal is reversed as we move around a curve on S passing
through P, then the surface generate is non-orientable.
Ñò éë( sin y dx + x cos y dy ) + x dy ù
2
= û
C Surface Integral
Consider a continuous function F(R) and a surface S. Divide S
Ñò éëd ( x sin y ) + x dy ù
2
= û into a finite number of sub-surfaces. Let the surface element
C surrounding any point P(R) be dS which can be regarded as a
2p vector; its magnitude being the area and its direction that of the
ò éëd {a cos t sin ( a sin t )} + a cos t dt ùû
= 2 2 outward normal to the element.
0
Consider the sum SF(R). dS, where the summation extends over
all the sub-surfaces. The limit of this sum as the number of sub-
2 2p surfaces tends to infinity and the area of each
2p a
= a cos t sin ( a sin t ) 0
+ ò (1 + cos 2t ) dt sub-surface tends to zero, is called the normal surface integral of
2 F(R) over S and is denoted by
0

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

Z Hence (i) gives ò F.N ds = 0 + 0 + 0 + 72 + 108 = 180


S
C
GREEN’S THEOREM IN THE PLA NE
D
If f(x, y), y(x, y), fy and yx be continuous in a region E of the
3 xy-plane bounded by a closed curve C, then
Y

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

S4 S4 Similarly, it can be shown that


¶y
3 9- z2 3 òò ¶x dxdy = ò y(x, y)dy
( )
...(3)
2
= ò 2x y ds = ò ò 8y dy dz = 4ò 9 - z 2 dz = 72 E C
On subtracting (2) from (3), we get (1).
S4 0 0 0
CALCULUS S2-113
This result can be extended to regions which may be divided into STOKE’S THEOREM (Relation between line
a finite number of sub-regions such that the boundary of each is and surface integrals)
cut at the most in two points by any line parallel to either axis. The close line integral of any vector A integral over any close
Applying (1) to each of these sub-regions and adding the results, curve C is always equal to the surface integral of the curl of
the surface integrals combine into an integral over the whole vector A integrated over the surface area S which is enclosed by
region; the line integrals over the common boundaries cancel (for the closed curve C
each is covered twice but in opposite directions), whereas the
remaining line integrals combine into the line integral over the Ñò ( A ).dl = òò (Ñ ´ A ) ds
external curve C. C S
Green’s theorem in a plane as a special case of Stokes theorem.
Sample Problem Let F = fI + yJ be a vector function which is continuously
differentiable in a region S of the xy-plane bounded by a closed
Using Green’s theorem, evaluate
curve C. Then
ò éë( y - sin x ) dx + cos xdy ùû where C is the plane triangle ò F.dR = ò ( f ˆi + yˆj).(dxiˆ + dyj)
ˆ =
ò ( fdx + y dy)
C
C C C
2
enclosed by the lines y = 0, x = p/2 and y = x ˆi ˆj kˆ
p æ ¶y ¶f ö
and curl F. N = ¶/¶x ¶/¶y 0 = K ç -
Sol. Here f = y – sinx and Y = cos x. è ¶x ¶ x ÷ø
f y 0
Y B

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

By Green’s theorem ò éë( y - sin x ) dx + cos xdy ùû 2z = x2 + y2 bounded by z = 2, evaluate òò ( Ñ ´ F) . dS using


C Stoke’s theorem. S

æ ¶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
=–

í 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. For the function f (x) = x2 e–x, the maximum occurs when x


x - sin x
is equal to [2005, 2 marks] 8. lim equals [2008, 2 marks]
(a) 2 (b) 1 x ®¥ x + cos x
(c) 0 (d) –1 (a) 1 (b) –1
2. Changing the order of the integration in the double integral (c) ¥ (d) –¥
8 2 s q 9. A cubic polynomial with real coefficients [2009, 2 mark]
I =ò f ( x, y )dy dx leads to I = ò ò f ( x, y )dx dy.
0 òx / 4 r p (a) Can possibly have no extrema and no zero crossing
(b) may have upto three extrema and upto two zero
What is q? [2005, 1 mark]
(a) 4y (b) 2 crossings
(c) x/4 (d) None of these (c) cannot have more than two extrema and more than
three zero crossings
2 x2 – 7 x + 3 (d) Will always have an equal number of extrema and zero
3. If f ( x ) = then lim f ( x ) will be crossing
5 x 2 –12 x – 9 x ®3
1 5 2
– sin x
(a) (b) [2006, 1 mark] 10. The lim 3 is [2010, 1 mark]
3 18
x®0 x
2 2
(c) 0 (d) (a) (b) 1
5 3
p / 3 it
1 1
(c) (d)
4. Assuming i = –1 and t is a real number ò0 e dt is 4 2
[2006, 1 mark] ¥ –3
11. If S = ò1 x dx then, S has the value [2010, 1 mark]
1 1
3 i 3 i (a) – (b)
(a) + (b) – 3 4
2 2 2 2
1
1 3 1 æ 3ö (c) (d) 1
+i + + i ç1 – 2
(c) ÷ (d) 0
2 2 2 è 2 ø x 1
12. The value of the quantity P, where P = ò xe dx is equal to
æ x2 ö 0
e x – ç1 + x + ÷ (a) 0 (b) 1 [2010, 1 mark]
5. lim è 2 ø is equal to [2007, 1 mark]
x ®0 3 1
x (c) e (d)
1 e
(a) 0 (b) 2n
6 æ 1ö
1 13. What is the value of lim ç1 - ÷ ? [2010, 2 marks]
n®¥ è nø
(c) (d) 1
3 (a) 0 (b) e –2
6. Consider the following two statements about the function –1/2
(c) e (d) 1
f(x) = |x| : [2007, 2 marks]
14. What is the value of the definite integral
P : f(x) is continuous for all real values of x.
Q. f(x) is differentiable for all real values of x. a x
Which of the following is true. ò0 x+ a–x
dx ? [2011, 1 mark]
(a) P is true and Q is false (b) P is false and Q is true
(c) Both P and Q are true (d) Both P and Q are false a
(a) 0 (b)
2
x1/ 3 – 2 (c) a (d) 2a
7. The value of lim is [2008, 1 mark] 15. Consider the function f (x) = sin (x) in the interval x Î [p/4,
x ®8 x – 8
7p/4]. The number and location(s) of the local minima of
1 1 this function are [2012, 1 mark]
(a) (b)
16 12 (a) one, at p/2 (b) one, at 3p/2
1 1 (c) two, at p/2 and 3p/2 (d) two, at p/4 and 3p/2
(c) (d)
8 4
EBD_7203
S2-116 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
16. Which one of the following functions is continuous at x = 3? (a) There exists a y in the interval (0, 1), f (y) = f (y + 1)
[2013, 1 Mark] (b) For every y in the interval (0, 1), f (y) = f (2 – y)
(c) The maximum value of the function in the interval
ì 2, if x = 3 (0, 2) is 1
(a) ï
f ( x ) = ï x – 1, if x > 3 (d) There exists a y in the interval (0, 1) such that f (y)
í = – (2 – y)
ï x + 3 , if x < 3
ïî 3 19. A non-zero polynomial f(x) of degree 3 has roots at x =1,
x = 2 and x = 3. Which one of the following must be TRUE?
x=3 [2014, Set-2, 1 Mark]
ì 4, if
(b) f (x) = í (a) f (0) f (4) < 0 (b) f (0) f (4) > 0
î8 – x, if x¹3 (c) f (0) + f (4) > 0 (d) f (0) + f (4) < 0
20. The number of distinct positive integral factors of 2014 is
ì x + 3, if x£3
(c) f (x) = í _________________________ [2014, Set-2, 2 Marks]
î x – 4, if x>3
2p

1
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

(a) 13.5 (b) 27.0 10


(c) 40.5 (d) 54.0 (b) Is a maximum equal to
3
r r
6. The inner (dot) product of two vectors P and Q is zero. 8
The angle (degrees) between the two vectors is (c) Is a minimum equal to
3
(a) 0 (b) 5
(c) 90 (d) 120 8
(d) Is a maximum equal to
7. For a scalar function f (x, y, z) = x2 + 3x2, the gradient at 3
the point P(1, 2, –1) is 12. For an analytic function, f(x + iy) = u(x, y) + iv(x, y), u is
r r r r r r given by u = 3x2 – 3y2. The expression for v, considering
(a) 2i + 6 j + 4k (b) 2i + 12 j – 4k K to be a constant is
r r r (a) 3y2 – 3x2 + K (b) 6x – 6y + K
(c) 2i + 12 j + 4k (d) 56
(c) 6y – 6x + K (d) 6xy + K
EBD_7203
S2-118 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
13. What should be the value of l such that the function
x3 + x 2
p 18. The value of function f(x) = lim is
defined below is continuous at x = ? x®0 2x 3 – 7x 2
2
1
ì l cos x p (a) zero (b) –
ï p if x ¹ 7
2
ï –x 1
f(x) = í 2 (c) (d) infinite
ï p 7
ï 1 if x = 19. If P, Q and R are three points having co-ordinates
î 2
(3, –2, 1), (1, 3, 4), (2, 1, –2) in XYZ plane, then the
2 distance from point P to plane OQR (O being origin of co-
(a) 0 (b) ordinate system) is given by
p
(a) 3 (b) 7
p (c) 5 (d) 9
(c) 1 (d)
2 20. For what values of x, the function f(x) = x3 – 9x2 + 24x + 4
has maximum and minimum value?
14. What is the value of the definite integral,
(a) 2, 4 (b) 2, 2
a (c) 4, 2 (d) 4, 4
x
ò x + a – x
dx? 21. A rail engine accelerates from its stationary position for
0 8 seconds and travel a distance of 280 m. According to
a mean value theorem, the speedo meter at certain time
(a) 0 (b) during acceleration must read exactly (in km/h)
2
(a) 0 (b) 8
(c) a (d) 2a
(c) 75 (d) 126
r r
15. If a and b are two arbitrary vectors with magnitudes 22. The function f(x) = 2x3 – 3x2 – 36x + 2 has its maxima at
r 2 (a) x = – 2 (b) x = 0
r
a and b, respectively, a ´ b will be equal to (c) x = 3 (d) both x = – 2 and x = 3
r r r
(a) a2 b2 – ar × b ( ) sin x
2
(b) ab – a × b 23. lim is not equal to
x ®0 x
r r r r
( )
2
(c) a2 b2 + a×b (d) ab + a × b sec x
(a) lim cos x (b) lim
x ®0 x ®0 x
x 2 x3 x 4
16. The infinite series 1 + x + + + + ... tan x
2! 3! 4! (c) lim (d) 1
corresponds to x ®0 x
(a) sec x (b) ex
p
(c) cos x (d) 1 + sin2 x 24. Limit of the series as x approaches is
17. For the parallelogram OPQR shown in the sketch, 2
uuur uuur
OP = aiˆ + bjˆ and OR = ciˆ + dj.
ˆ The area of the x3 x5 x 7
f(x) = x – + – + .....
parallelogram is 3! 5! 7!

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 56. The temperature field in a body varies according to the


x equation T (x, y) = x3 + 4xy. The direction of fastest variation
45. The value of the quantity, where p= ò xe dx is
in temperature at the point (1, 0) is given by
0
(a) 0 (b) 1 (a) 3iˆ + 8 ˆj (b) iˆ
(c) e (d) 1/e
46. Consider the function f (x) = (x2 – 4)2 where x is a real (c) 0.6iˆ + 0.8 ˆj (d) 0.5iˆ + 0.866 ˆj
number . Then the function has.
(a) only one minimum (b) only 2 maxima 57. A triangle ABC consists of vertex points
(c) 3 minima (d) 3 maxima A (0, 0), B (1, 0) and C (0, 1)

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

PAST GATE QUESTIONS EXERCISE é p pù


ê cos 3 + i sin 3 ú é cos 0 + i sin 0 ù
1. (a) f (x) = x2e–x =ê ú–
f ¢ (x) = x2 (– e–x) + e–x × 2x ë i û ëê i ûú
= e–x (2x – x2)
Putting f ¢ (x) = 0, 1 3 1 3
+i –1 – i + i2 é i
e–x (2x – x2) = 0 2 2 i 2 2 3ù
= ´ = = – ê– – ú
e–x x(2 – x) = 0 i i i 2 ë 2 2û
x = 0 and x = 2 are the stationary points.
f ¢¢ (x) = e–x (2 – 2x) + (2x – x2) (– e–x) é 3 iù
=ê + ú
= e–x [2 – 2x – (2x – x2)] ë 2 2û
= e–x (x2 – 4x + 2)
At x = 0, f ¢ (0) = e–0 (0 – 0 + 2) = 2 æ x2 ö
Since, f ¢¢ (0) = 2 is > 0, at x = 0, at x = 0, we have a e x – ç1 + x + ÷ é0 ù
5. (b) lim è 2 ø êë 0 by L' Hospital rule úû
minima.
Now, at x = 2
x ®0 x3
f ¢¢ (2) = e–2 (22 – 4 × 2 + 2)
e x – (1 + x ) é0 ù
= – 2e–2 < 0 = lim êë 0 Form úû
x ®0 2
\ At x = 2, we have a maxima. 3x

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

(0, 0) x (8, 0) X-axis y


Starting value of x is zero and the final value of x is 8
but we want the result of first integration in terms of y,
so that we can integrate the result with respect to y to
get the final result. So, limits are from 0 to 4 y. and
integration limit for y is from 0 to 2. x' x
8 2 2 4y 0
So ò0 òx \4 f ( x, y )dy dx = ò0 ò0 f ( x, y ) dx dy
f(x) is continous for all real values of x
s q
=ò ò p f ( x, y)dx dy lim | x |= lim | x |= 0
r
x ® 0- x ®0+
Hence, r = 0, s = 2, p = 0 and q = 4y
2 x2 – 7 x + 3 é0 ù | x | -0
lim = Left derivative = lim- = -1
3. (b)
x ®3 2 êë 0 From úû x®0 x
5 x – 12 x – 9
4x – 7 5
lim = = [By L’ Hospital rule] | x | -0
x ®3 10 x –12 18 Right derivative = lim+ =1
x®0 x
ée it ù p / 3 p/3
p / 3 it é cos t + i sin t ù Þ Left derivative ¹ Right derivative
4. (a) ò0 e dt = ê ú
ë i û0

ë i úû
0 \ f(x) is not differentiable at x = 0.
CALCULUS S2-123

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

3x (symmetric on both sides)


5. (a) ò ò ( 6 – x – y ) dx dy L/2
æ 8hx ö
2 L/2
64 h 2 x 2
00
= 2 ò 1+ ç
è L2 ø
÷ dx = 2 ò 1+
L2
dx.
x 0 0
3x 3æ ö
y2
= ò ò ( 6 – x – y ) dy dx = ò çç 6 y – xy – 2
÷ dx
÷
11. (a) f(x, y) = 4x2 + 6y – 8x – 4y + 8
00 0è ø0 Maximum and minimum values of f(x, y)
3 ¶f ¶f
3
æ 3x 2 ö æ 6x 2 3x 3 ö = 0, =0
= ò0 çè 6x –
2 ÷ø
dx = çè 2 – 3x 2 ÷ø dx ¶x ¶y
0
Þ 8x – 8 = 0, 12y – 4 = 0
27 1
= 27 – = 13.5.
2 Þ x = 1, y =
3
6. (c) P . Q = P – Q . cos q = 0
¶2f
\ cos q = 0 r= =8
¶x 2
\ q = 90°.
¶f ¶f ¶f ¶ 2f
7. (b) Ñ . f = i + j +k s= =0
¶x ¶y
¶x ¶y ¶z
= i × (2x) + j × (6y) + k × (4z) ¶2f
= 2 (xi + 3yj + 2zk) t= = 12
¶y 2
At P (1, 2, –1)
Ñ . f = 2i + 12j – 4k. rt – s2 = 8 × 12 – 0 = 96 (+ve) (minima)
(rt – s2) and r is positive.
¶f ¶f ¶f
8. (b) Ñ . f = i + j +k æ 1ö
¶x ¶y ¶z \ it is minimum at ç1, ÷ .
è 3ø
= i × (2x) + j × (6y) + k × (4z)
At (1, 2, –1) 2
æ 1ö æ 1ö æ 1ö
Ñ . f = 2i + 12j – 4k f ç1, ÷ = 4(1)2 + 6 ç ÷ – 8(1) – 4 ç ÷ + 8
è 3ø è 3 ø è 3ø
a i – j + 2k i – j + 2k
â = = = 2 4 10
a 6
12 + ( –1) + 22
2 =4+ –8– +8= .
3 3 3
Directional derivative = Ñ . f × â 12. (d) u = 3x2 – 3y2
2 – 12 – 8 ¶u ¶v
= = – 3 6. =
6 ¶x ¶y

æ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

(Apply L¢Hospitable Rule again) 1


ò (e )
1+ y
Similarly going on, we get, = – e0 + y dy
a ( a – 1) ( a – 2) ..... x 0 0
a!
lim = . 1
b ( b – 1) ( b – 2) ..... x
ò (e ) ( )
x ®0 0 b! 1
1+ y
= – e y dy = e1 + y – e y

Ñò ( 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 ®¥

div V= ¶ [–( x cos xy + y )] + ¶ [ y cos xy ]


1
x x x 1
45. (b) p= ò xe dx = [ xe – e ]0 = 1 ¶x ¶y
0
46. (b) f (x) = (x2 – 4)2 ¶
f ¢(x) = 2(x2 – 4) × 2x = 0 + [sin z 2 + x 2 + y 2 ]
¶x
Þ x = 0, z – 2
f ¢¢(x) = 4 (3x2 – 4) = 2z cos z2
f ¢¢(0) = – 16 < 0 (max) 51. (a) f (x) = x2e–x
f ¢¢(2) = 32 > 0 f ¢(x) = e–x[– x2 + 2x] = 0
f ¢¢(– 2) = 32 > 0 Þ x = 0, 2
47. (d)
f ¢¢ (x) = e–x [x2 – 2x – 2x + 2]
48. (a) r = xi + yj + zk
f ¢¢ (0) = 2 (> 0) (minimum)
¶F1 ¶F2 dF3
div r = + + = 1 + 1+ 1 = 3 f ¢¢(2) = e–2 [–2] (< 0) (max)
¶x ¶xy ¶z
49. (d) Equation of line: 2
52. (c) Ñu = xi + yj
(0, 2); (2, 0) 3
y –y Ñu = i + 2j
y – y1 = 2 1 ´ ( x – x1 )
x2 – x1 |Ñu| = 1+ 4 = 5
CALCULUS S2-129
53. (b) Given function is f (x) = 3x4 – 4x2 + 5 57. (b) Equation of the straight line joining (1, 0) and (0, 1) is
(i) f (x) is continuous in every real interval x + y = 1, y = 1 – x
(ii) f ¢(x) exist in any real interval
(iii) f (–1) = 3 (–1)4 – 4 (–1)2 + 5 = 4 (0, 1)
Also f ¢(c) = f(1) = 3 (1)4 – 4 (1)2 + 5 = 4
f(–1) = f (1), 12c3 – 8c = 0
(x, y)
2
Þ c = 0, c = ±
3 x+ y=1
\ c Î[–1, 1] (0, 0) (1, 0)
Hence all the condition of Rolle’s Theorem are satisfied
in the interval [–1, 1] 1 1- x
(a) Let f(x) = –x3 + 6x2 + 2x + 1
Consider òò 2xdxdy = ò 2xdx ò
54. dy
Slope of the function is, 0 0
f ¢(x) = – 3x2 + 12x + 2 = F(x) (say)
1 1 1
Now to find minimum or maximum of F (x). 1- x
= ò 2xdx ( y ) 0 = ò 2xdx(1 - x) = ò (2x - 2x 2 )dx
\ F¢ (x) = – 6x + 12
0 0 0
and F¢¢ (x) = – 6
Since, limits of the integral are now between 0 and 1
For maxima and minima
F¢ (x) = 0 1
Þ x=2 ( 2)
\ òò 2xdxdy = ò 2x - 2x dx
\ F¢¢(2) = – 6 < 0 0

Hence F (x) (slope) is maximum at x = 2 1


\ Maximum slope = F(2) = – 3(2)2 + 12(2) + 2 = 14 é 2x 3 ù 2 1
= êx 2 - ú = 1- =
55. (d) f(x) = x5 – 5x4 + 5x3 – 1 ë 3 û0 3 3
f ¢(x) = 5x4 – 20x3 + 15x2 58. (c) f = 2x2 + 3y2 + 5z2
f ¢¢(x) = 20x3 – 60x2 + 30x At point (1, 1, –1), Ñf = i. 4x + j. 6y + k. 10z
f’’(x) = 60x2 – 120 x + 30 Given : x = 1, y = 1, z = –1
for maximum and minimum f ¢(x) = 0
\ | Ñf |= (4)2 + (6)2 + (–10)2 = 152
\ x4 – 4x3 + 3x2 = 0
Þ x2 (x – 1) (x – 3) = 0 p/2
\ x = 0, 1, 3 p/2 p/2
ò [cos( x + y )]0p / 2 dy
59. (d) ò0 ò0 sin (x + y) dx.dy =
f ¢¢ (0) = 0 0
f ¢¢¢(0) = 30 ¹ 0
p/ 2
\ f (x) is neither maximum nor minimum at x = 0 é æp öù
= êsin y – sin ç + y ÷ ú
f ¢¢¢(1) = 20 – 60 + 30 = – 10 < 0 ë è2 øû0
\ f (x) is maximum at x = 1 = (1 – 0) – (0 –1) = 2
f ¢¢(3) = 540 – 540 + 90 = 90 > 0
\ f (x) is maximum at x = 3
1
Hence there is one maximum and one minimum for f (x). 60. (i) y = cos x cos 2x cos 3x = cos x (cos 5x + cos x)
2
56. (c) Given T = x3 + 4xy
1 1
¶T = (2 cos x cos 5x + 2 cos2 x) = [(cos 6x + cos 4x)
Þ = 3x2 + 4 y 4 4
¶x
+ (1 + cos 2x)]
æ ¶T ö æ ¶T ö 1
= 3, Þ ç ÷ =4 = (1 + cos 2x + cos 4x + cos 6x)
\ çè ¶y ÷ø è ¶y ø (1,0) 4
(1,0)
Hence direction of fastest variation in temperature at 1 n
\ yn = [2 cos (2x + np/2) + 4n cos (4x + np/2)
4
(1, 0) is given by 3iˆ + 4 ˆj or 0.6iˆ + 0.8 ˆj
+ 6n cos (6x + np/2)]
EBD_7203
S2-130 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

1 d ( x x ) / dx.(1 + log x) + x x (1/ x ) – 0


(ii) cos2 x sin x = cos x (sin x cos x) = cos x. sin 2x = Lt
2 x ®1 1/ x 2
1 1
= (2 sin 2x cos x) = (sin 3x + sin x) x x (1 + log x ) 2 + x x (1/ x )
4 4 = Lt
x ®1 x –2
1 [By (i)]
\ Dn (e2x cos2 x sin x) = [Dn (e2x sin 3x)
4
+ Dn (e2x sin x)] 1(1 + 0)2 + 1.1
= =2
1 2 1
= [(2 + 32)n/2sin (3x + n tan–1 3/2) 64. Using the expansions of ex, sin x and log (1 – x), we get
4
e x sin x – x – x 2
+ (22 + 12)n/2 sin 1 )]
(x + n tan–1 Lt
x ®0 x 2 + x log(1 – x)
2
1 1
= [(13)n/2 sin (3x + n tan–1 3/2) + (5)n/2 sin(x + n tan–1 )]. æ 1 2 1 3 öæ 1 3 ö 2
4 2 çè1 + x + x + x + ...÷ø çè x – x + ...÷ø – x – x
2! 3! 3!
61. Take u = ex and v = (2x + 3)3, so that un = ex for all = Lt
integral values of n, and v1 = 6 (2x + 3)2, v2 = 24 (2x + x ®0 æ 1 1 ö
x 2 + x ç – x – x 2 – x3 – ...÷
3), v3 = 48, v4, v5 etc. are all zero. è 2 3 ø
\ By Leibnitz’s theorem,
(uv)n = un v + nC1 un–1v1 + nC2un–2v2 + nC3un–3v3 æ 2 1 3 4 ö 2
ç x + x + x – 0.x + ... ÷ – x – x
i.e., [ex (2x + 3)3]n = ex (2x + 3)3 + nex [6 (2x + 3)2] è 3 ø
= Lt
n (n – 1) x n(n – 1)(n – 2) x x ®0 æ 1 1 ö
+ e [24(2 x + 3)] + e [48] x 2 – ç x 2 + x 3 + x 4 + ... ÷
1.2 1.2.3 è 2 3 ø
= ex {(2x + 3)3 + 6n (2x + 3)2 + 12n (n – 1) (2x + 3) + 8n 1 3 1
(n – 1) (n – 2)}. x – 0.x 4 + ... + ...
3 2
1 æ 1 öæ 3 ö 3 = Lt 3 = Lt =– .
1 1 1 1 3
62. (b) f(a) = 0, f (b) = ç – ÷ç – ÷ = x ®0
– x3 – x 4 – ... x ®0
– – x – ...
2 è 2 øè 2 ø 8 2 3 2 3
f ¢(x) = 3x2 – 6x + 2, f ¢(c) = 3c2 – 6c + 2
65. (i) Let y = Lt (sin x) tan x
3 æ1 ö x ®p / 2
Substituting in (i), – 0 = ç – 0 ÷ (3c2 – 6c + 2)
8 è2 ø
Lt log sin x
or 12c2 – 24c + 5 = 0 \ log y = tan x log sin x x = Lt
x ®p / 2 x ®p / 2 cot x
24 ± (24)2 –12 ´ 5 ´ 4
whence c = = 1± 0.764 = 1.764 æ 0ö
24 ç form ÷
è 0ø
; 0.236.
Hence c = 0.236, since it only lies between 0 and 1/2. (1/ sin x) cos x
= Lt = – Lt (sin x cos x) = 0
xe x – log(1 + x) æ 0ö x ®p / 2– cosec 2 x x®p / 2
63. (i) Lt ç form ÷ Hence y = e0 = 1.
x ®0 x2 è 0ø
66. Here u is not a homogeneous function. We therefore,
( xe x + e x .1) – 1/(1 + x ) æ 0ö write
Lt ç form ÷
x ®0 2x è 0ø x + 2 y + 3z 1 + 2( y / x ) + 3( z / x )
w = sin u = = x –7 .
8 8 8
xe x + e x + e x + 1/(1 + x )2 0 + 1 + 1 + 1 1 æ 0ö x +y +z 1 + ( y / x)8 + ( z / x)8
Lt = =1 . ç form ÷ Thus w is a homogeneous function of degree – 7 in x,
x ®0 2 2 2 è 0ø
y, z. Hence by Euler’s theorem
xx – x
(ii) Lt ¶w ¶w ¶w
x ®1 x –1– log x x +y +z = (–7)w ...(i)
¶x ¶y ¶z
x
d ( x ) / dx – 1 ¶w ¶u ¶w ¶u ¶w ¶u
= Lt Let y = x x so that
x ®1 1 – 0 – 1/ x But ¶x = cos u ¶x , ¶y = cos u , = cos u
¶y ¶z ¶z
log y = x log x
x x (1 + log x) –1 ¶u ¶u ¶u
= Lt 1 dy 1 \ (i) becomes x cos u + y cos u + z cos u = – 7 sin u
x ®1 1– x / x \ = x. + 1.log x
y dx x ¶x ¶y ¶z
æ 0ö d x ¶u ¶u ¶u
çè form ÷ø or ( x ) = x x (1 + log x) ... (i) or x +y +z = –7 tan u.
0 dx ¶x ¶y ¶z
CALCULUS S2-131
67. Let u = 2xy – 3x2y, so that
4 sin 3 x cos x 3
du ¶u dx ¶u dy ò sin x dx = – + ò sin 2 x dx ...(a)
dx dy 4 4
= . + . =(2y –6xy) + (2 x – 3 x 2 ) ...(i)
dt ¶x dt ¶y dt dt dt
sin x cos x 1
ò sin
2
when x = 3 and y = 1, dx/dt = 2, and u is neither x dx = – + ò (sin x) 0 dx
2 2
increasing nor decreasing, i.e., du/dt = 0.
0
\ (i) becomes 0 = (2 – 6 × 3) 2 + (2 × 3 – 3 × 9)
dy But ò (sin x) dx = ò dx = x.
dt
sin x cos x x
ò sin
2
\ xdx = – +
dy 32 2 2
or =– cm/sec. Thus y is decreasing at the rate of
dt 21 Substituting this in (a), we get
32/21 cm/sec.
4 sin 3 x cos x 3 æ sin x cos x x ö
p dx p ò sin x dx = –
4
+ ç–
4è 2
+ ÷

68. We have ò0 a + b cos x = ...(i)
a – b2
2
(ii) We know that
Differentiating both sides of (i) w.r.t. a,
p ¶ æ 1 ö ¶ ì p
üï p/2 (n –1)(n – 3)(n – 5)... æ p ö
ò0 cos n x dx =
ò0 ¶a çè (a + b cos x) ÷ø dx = ¶a ïí 2 2 ý n(n – 2)(n – 4)... è 2
ç if n is even ÷
ø
ïî (a – b ) þï
Putting n = 6, we get
p – dx æ 1ö 2 5.3.1 p 5p
ò0 (a + b cos x)2 = p çè – 2 ÷ø (a – b 2 ) –3 / 2 .2 a p/2
cos 6 x dx =
i.e. ò0 = .
6.4.2 2 32
70. Putting x = a sin q, we get
p dx -p a
\ ò0 (a + b cos x)2 = (a 2 – b 2 )3/ 2 a xn p / 2 (asin q) n
ò0 dx = ò
0 a cos q (a cos q) dq
Now differentiating both sides of (i) w.r.t b, (a 2 – x 2 )
p –2 æ 1ö
ò0 –(a + b cos x) .cos x dx = p ç – ÷ (a2 – b2)–3/2. (–2b)
è 2ø = an ò
p/2
sin n q d q
0

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 øþ
.

ì sin x cos3 x 1 ü Taking logs of both sides,


í– + (2 x + sin 2 x) ý
î 4 16 þ log P = Lt 1 ìílog æç1 + 1 ö÷ + log æç1 + 2 ö÷ + ... + log æç1 + n ö÷ üý
(ii) Putting t = tan q, so that n ®¥ 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

C Ø Number systems, Number conversions

O Ø

Ø
Binary Arithematic, Signed numbers

Digital Logic gates, Boolean Algebra

N Ø Canonical normal forms Karnaugh maps.

T Ø

Ø
Digital IC families

Multiplexer, Demultiplexer, FlipFlops, Counters

E Ø ADC and DAC, Sample and Hold circuit

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

Number Base or Symbol used Weight assigned example


System radix (b) (di or d –f) to position
Binary 2 0,1 2 –i 2 –f 1011.11
–i –f
Octal 8 0,1,2,3,4 8 8 3567.25
–i –f
Decimal 10 0,1,2,3,4,5 10 10 3974.57
–i –f
Hexadecimal 16 0,1,2,3,4,5,6,7,8 16 16 3FA9.56
A,B,C,D,E,F

Binary Number System


The number system with base (or radix ) two is known as the binary number system. Only
two symbols are used to represent numbers in this system and these are 0 and 1, these
are known as bits. It is a positional system, that is every position is assigned a specific
weight left - most bit is known as Most Significant Bit (MSB) and the right - most bit is
known as the Least Significant Bit (LSB). Any number of 0s can be added to the left of
the number without changing the value of the number. A group of four bits is known as
nibble and a group of eight bits is known as a byte. Table 2 shows binary numbers and
their equivalent decimal numbers.
Table 2 : 4-bit binary numbers and their corresponding decimal numbers.
Binary Number Decimal Number
B3 B2 B1 B0 D1 D0
0 0 0 0 0 0
0 0 0 1 0 1
0 0 1 0 0 2
0 0 1 1 0 3
0 1 0 0 0 4
0 1 0 1 0 5
0 1 1 0 0 6
0 1 1 1 0 7
1 0 0 0 0 8
1 0 0 1 0 9
1 0 1 0 1 0
1 0 1 1 1 1
1 1 0 0 1 2
1 1 0 1 1 3
1 1 1 0 1 4
1 1 1 1 1 5
DIGITAL LOGIC S3-3
Octal Number System
It is one of the popular number system. There are 8(23) combinations of 3-bit binary
numbers. Therefore, sets of 3-bit binary number can be conviently represented by octal
numbers with base 8.
Hexadecimal Number System
Hexadecimal means 16. These are 16 combinations of 4-bit binary numbers and sets of
4-bit binary number can be entered in the microprocessor in the form of hexadecimal
digits.
Since 16 digits are used, the heights are in powers of 16. The decimal equivalent of a
hexadecimal string equals sum of all hexadecimal digits multiplied by their weights.
e.g., (F 8 E · 2 B)16 = F × 162 + 8 × 161 + E × 160 + 2 × 16–1 + B × 16–2
= 15 × 162 + 8 × 161 + 14 × 16 + 2 × 16–1 + 11 × 16–2
2 11
= 3840 + 128 + 14 + + = (3982.16796875)10.
16 256
NUMBER CONVERS IONS
Binary-Decimal Conversion
Any binary number can be converted into its equivalent decimal number using the
weights assigned to each bit position. Since only two digits are used, the weights are
powers of 2. these weights are 20 (Units), 21 (twos), 22 (fours) 23 (eights) and 24 (sixteen).
If longer binary number involved, the weights continue in ascending powers of 2.
The decimal equivalent of a binary number equals the sum of all binary number equal
the sum of all binary digits multiplied by their weights.
Example 1: Find the decimal equivalent of binary number 11111.
Solution:
The equivalent decimal number is,
= 1 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 1 × 20
= 16 + 8 + 4 + 2 + 1 = ( 31 )10
Decimal-to Binary Conversion
Any decimal number can be converted into its equivalent binary number. For integers,
the conversion is obtained by continuous division by 2 and keeping track of the
remainders, while for fractional parts, the conversion is effected by continuous
multiplications by 2 and keeping track of the integers generated.
Example 2: Express the 25.5 decimal number in the binary form.
Solution:
Integer Part:
Thus, (25)10 = (11001)2
2 25
2 12 — 1
2 6 —0
2 3 —0
2 1 —1
2 0 —1
Read down to up
Fraction part
0 . 5
´ 2
1 . 0
i.e., 0.510 = 0.12
Therefore 25.510 = 11001.12
EBD_7203
S3-4 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Decimal-Octal Conversion
This can be achieved by dividing the given decimal number repeatedly by 8, until a
quotient of 0 is obtained.
Example 3 : Convert conversion (444.499)10.
Solution :
Division Generated Remainder
444 / 8
55/ 8 ® 4
6/8 ® 7
0/8 ® 6
On reading the remainders from bottom to top, the decimal (444)10 ® (674)8. Now,,
fractional conversion
Multiplication Generated Integer
0.499 ´ 8 = 3.992 3
0.992 ´ 8 = 7.936 7
0.936 ´ 8 = 7.488 7
0.488 ´ 8 = 3.904 3
The process gets terminated when significant digits are acquired. Thus, octal
equivalent is (444.499)10 = (674.3773)8
Octal-Binary Conversion
It can be explained through the following example: To convert (377)8 into binary, replace
each significant digit by its 3-bit binary equivalent.
(377)8 = 3 7 7
= 011 111 111
Thus, (377)8 = (011111111)2
Binary-Hexadecimal Conversion
e.g., (10100110111110)2 = (0010 1001 1011 1110)2 = (2 9 B E)16 × 1
Hexadecimal-Binary Conversion
It can be explained through an example. To convert (1D5)16 into binary, replace each
significant digit by its 4-bit binary equivalent.
(1D5)16 = 1 D 5
= 0001 1101 0101
Thus, (1D5)16 = (000111010101)2
BINARY ARITHMETIC
Table 3 will illustrates the all four mathematical operations.
Table 3

Addition Subtraction Multiplication Division

0+0=0 0– 0=0 0×0 =0 0/1 = 0


0+1=1 1– 0=1 0×0=0 1/1 = 1
1+0=1 1– 1=0 1×0=0 0/0 = No
1 + 1 = 10 10 – 1 = 1 1×1=1 1/0 = No

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ïþ ïþ

Q. Write 2421 weighted code.

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

(B) Gray to Binary:-


G3 G2 G1 G0
1 1 1 0

B3 B2 B1 B0
1 0 1 1
DIGITAL LOGIC S3-7
G3 B3

G2 B2

G1 B1

G0 B0

DIGITAL LOGICAL GATES


OR Gate: Its symbol is given in the fig. 1(a) & its truth table is 4(a)
Table 4(a)

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

CANONICAL NORMAL FORMS


Sum of Products (SOP) Method
It is an expression which denotes the logical sum of two or more logical product terms.
It is basically an OR operation of AND operated variables such as
Y = PQ + QR + PR, or Y = PQ + P R + QR
DIGITAL LOGIC S3-9
Product of Sums (POS) Method
It is an expression which denotes the logical product of two or more logical sum terms.
It is basically an AND operation of OR operated variables such as
Y = (P + Q)(Q + R)(R + P ), or
Y = (P + Q + R)(P + R )

Karnaugh Map (K-Map) Simplification A AB


B 0 1 00 01 11 10
It is a technique for simplifying & manipulating switching expressions. It is a modified C
0 0 2 0 0 2 6 4
form of a truth table where information contained either in truth table or in POS or in
SOP form is represented on the K-map. 1 1 3 1 1 3 7 5
Fig. 4 (a) : Two Fig. 4 (b) : Three
Basic Rules variable Variable
• In an s-variable K-map, there are are 2s cells. AB
00 01 11 10
• Each cell represents one combination of s-variables. CD
00 0 4 12 8
• Each single cell that contains a ‘1’ represents a minterm in the function & each
minterm can be thought of as a ‘product’ term with s variables. 01 1 5 13 9
• Each single cell that contains a ‘0’ represents a maxterm in the function & each 11 2 7 15 11
maxterm can be thought of as a ‘sum’ term with s variables. 10 3 6 14 10
• To combine variables, use groups of 2, 4, 8 etc. Fig. 4 (c) : Four variable
• Thus, K-maps are tables of rows & columns with either 1’s or 0’s of SOP & POS
Table 7
representation
The decimal codes are given inside each cell at the bottom right corner (which is basically P Q R
a combination of corresponding variables). 0 0 1
The K-map for 2, 3 & 4 variables can be drawn as shown in fig. 4 (a), 4 (b), 4 (c). 0 1 0
1 0 1
For example R = PQ + PQ , thus its truth table in table 7 & graph in fig. 4 (d) will be 1 1 0
drawn as shown :
Q
Don’t Care Conditions P 0 1
• Functions that have unspecified output for some input combinations are called 0 1 0
0 1
incompletely specified functions. 1 1 0
2 3
• Unspecified minterms of a functions are called 'don't care' conditions. We simply Fig. 4 (d)
don't care whether the value of 0 or 1 is assigned to F for a particular minterm.
• Don't care conditions are represented by X in the K-Map table.
Don't care conditions play a central role in the specification and optimization of
logic circuits as they represent the degrees of freedom of transforming a network
into a functionally equivalent one.
EBD_7203
S3-10 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
DIGITAL IC FAMILIES
+ (a) Resistor Transistor Logic
• It is a digital circuit which has registers as input network & bipolar junction
transistors as the switching device.
B
C • Here an RTL NOR gate in fig. 5 (a) with its symbol in fig. 5 (b) is shown, where
A Q1 Q2 we have taken two inputs.
• When input A is on or gets high, Q1 will be conducting in nature, pulling the
output pin C to the ground. Whereas when input B is on or gets high , Q2
Fig. 5 (a) : Schematic diagram will be conducting in nature, pulling the output pin C to the ground.
A • Characteristics of RTL family:
B C
- High power dissipation.
Fig. 5 (b) : Symbol - Poor noise immunity.
- Low speed of operation.
(b) Transistor-Transistor -logic (TTL)
1.6 K 130 W • TTL is introduced to overcome the low speed problem of DTL.
4K
• If both the inputs, A and B are high, then Q1 has no emitter current, but its
Q3 base collector junction is forward biased and constitutes the base current to
A the Q2. This will result in the transfer of base current to Q4, causing it to
Q2
B Q1 conduct. On the other side, Q2 collector will go low causing Q3 to be cut-off.
C
Therefore, in this condition, Q4 is conducting and Q3 is cut-off.
Q4
1K • Secondly, if any of A or B goes low, Q1 will conduct the emitter current,
saturating it and pulling Q2 base to the ground. This will cause Q3 to
conduct and Q4 to be cut-off. Logically, these families are developed to
Fig. 5 (c) : Schematic diagram conduct only in the on and off conditions. This means that the output line
always has low impedance, reducing the effect of noise.
A The fig. 5(c) shows the NAND gate TTL and 5 (d) schematic diagram of TTL
C
B circuit.
Fig. 5 (d) : Symbol (c) Emitter-Coupled-Logic (ECL)
• This is the fastest logical family and the only family that does not operate
NOR OR
C fully saturated or cut-off, preventing the adverse effects of diffusion
D VCC
capacitance.
• When A goes high, causing Q2 Collector to be low, which lowers down the
315 300 base and emitter (both) of Q1 generates a low NOR gate Output. At the same
Q5
Q1 Q6 time, Q4 emitter goes high, tending to cut it off and Q5 base goes high as well
D1 as Q5 emitter and consequently the OR output. D1 and D2 provide the
Q3 Q4 constant voltage supply to Q6 base and therefore a constant voltage to the
Q2 D2 Q4 base to operate it in Common base Amplifier mode.
2.43 K The fig. 5 (e) shows the Schematic diagram and 5 (f) symbol of ECL
(d) Complementary Metal Oxide Semiconductor (CMOS)
A B -VCC • This logical family is mostly used in chip designing, as it 5 (g) is the most
Fig. 5 (e) : Schematic diagram power consuming logical family and carries less space. Figure show the
schematic diagram of CMOS. According to the figure, working can be
A explained as -
C
B • When A and B both inputs are high, then Q1 and Q2 get cut-off whereas Q3
NOR and Q4 are ON, which takes C to ground.
• When A goes ground, Q1 conducts and Q3 is in OFF mode, so that C goes
A HIGH.
D
B • When B goes ground, Q4 will be Cut-off and Q2 is turned ON, which leads C
OR high.
Fig. 5 (f) : Symbols
DIGITAL LOGIC S3-11
From above discussion, it is clear that just like TTL, in CMOS one transistor is
always conducting.
VDD
Q1
Q2
C
Q3
A
A
C
B B
Q4
Fig. 5 (g): Schematic diagram Fig. 5 (h) : Symbol
Specification Table for Logical Family Devices
Specification RTL TTL CMOS
Power supply 3.8 Volts +5 Volts 3-15 Volts
Propagation delay 12 nsec 15 nsec 25 nsec

Power Dissipation 30-100 mW 100 mW 10 nW

Noise Margin 0.2 Volts 0.4 Volts 45%of VD D

Fan Out 4 10 >50

MULTIPLEXER m select signals

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

Fig. 7 (b) : 1-to-4 demultiplexer FLIP FLOPS


• It is an electronic circuit that has two stable states & can be used to store state
A1 information. It is basically a bistable multivibrator or latch or toggle.
Q • It can either be simple or clocked (synchronous or edge triggered).
• It can store information either in 1 or in 0 form.
• It has two outputs; Q and Q shown in fig. 8 (a) which are always complement of
Q
A2 each other.
Fig. 8 (a) : Basic Memory Cell • In set state, Q is HIGH (logic 1) and Q is low (logic 0);
In reset state, Q is HIGH (logic 1) and Q is low (logic 0);
For a flip flop to act as a memory devices it should retain information stored in it.
• It is of 4 basic types: S-R, J-K, D & T.
(a) S-R (Set-Reset) Flip-flops
• It has two inputs: set & reset & two outputs: Q & Q .

• The two outputs Q & Q are complement to each other..


• It can be designed by using NOR gates or NAND gates.
• Here we have created an S-R flip flop using NOR gates with its symbol as
shown in the fig. 8 (b) and 8 (c)
Table 10
R(Reset)
Inputs Outputs 1 Q
Actions
S R Qn+1 Q n+ 1 R Q
S Q
0 0 Qn Qn No Change
S(Set) 2 Q
0 1 0 1 Reset
1 0 1 0 Set
½ 7402
1 1 ? ? Forbidden Fig. 8 (b) : Block diagramFig. 8 (c) : NOR based S-R flip-flop
• Feedback is developed as there is a cross-coupled connection from the output
of one gate to the input of the other gate, thus classified as asynchronous
sequential circuits.
• Its truth table can be made as shown in Table 10.
(b) Clocked S-R Flip-flop
The clocked SR flip-flop shown in fig. 8 (d) consists of a basic NOR flip-flop and
R two AND gates. The outputs of the two AND gates remain at 0 as long as the
Q clock pulse (or CP) is 0, regardless of the S and R input values. When the clock
CP pulse goes to 1, information from the S and R inputs passes through to the basic
(clock pulse) flip-flop. With both S = 1 and R = 1, the occurrence of a clock pulse causes both
Q¢ outputs to momentarily go to 0. When the pulse is removed, the state of the flip-
S
Fig. 8 (d) : Clocked S-R Flip-flop flop is indeterminate, i.e., either state may result, depending on whether the set or
reset input of the flip-flop remains a 1 longer than the transition to 0 at the end of
the pulse.
DIGITAL LOGIC S3-13

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.

GET GET GET

CLR CLR CLR

Fig. 9 (d) : Asynchronous counter


EBD_7203
S3-16 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ANALOG TO DIGITAL CONVERTER (A/D)
Clear • It is a device that converts a continuous physical quantity (usually voltage) to a
Clock Binary
digital number that represents the quantity’s amplitude.
Counter MSB • It involves two basic steps: quantizing & encoding.
Digital Quantizing: Breaking down of analog values into finite states.
output
– LSB
Encoding: Assigning a digital number to each state & matching it to the input
D/A
+ signal.
VS • There are two ways to improve its accuracy:
Analog input
A/D converter using a counter Either by increasing the resolution which improves the accuracy in measuring the
Fig. 10 : A/D converter using a counter
amplitude of the analog signal.
By increasing the sampling rate which increases the maximum frequency that can
be measured.
• They are of six types: simultaneous or flash type, counter type, continuous type,
successive approximation type, single slope type & dual slope type.
Fig. 10 shows a A/D converter.
DIGITAL TO ANALOG CONVERTER
a0 a1 a2 an–2 an–1 • It involves transforming the binary values 0’s & 1’s into an analog signal which
represents the binary data.
2R 2R 2R 2R 2R
• It involves two steps: sampling & quantizing.
Vout Sampling: Measurement at regular intervals of the amplitude of varying waveform.
R R R R
Fig. 11: n-bit R-2R ladder Quantizing: Breaking down of analog value into finite states.
It is used for the generation of audio signals.
• There are two types of D/A converters: resistive divider & R-2R ladder type.
Fig. 11 shows a n-bit R-2R ladder.
SAMPLE & HOLD CIRCUIT
S Sample & hold circuit is a device that is generally used to convert analog signal into its
Vi V0 digitised form i.e. when an analog signal is applied at the input terminal of sample &
hold circuit, it assigns a digital level to every pulse with the help of the switch. The
C output so generated by sample and hold circuit is used to convert data into digital
signals by means of analog-to-digital convertor (A/D). The fig. 12 (a) shows the schematic
(a) Schematic diagram circuit arrangement of the sample and hold circuit, in which a switch is connected in
series with a capacitor. In practical experimentation, the switch can be a relay, BJT or
V0 - MOSFET controlled gating signal. According to the fig. 12 (b), MOSFET is used as a
V0 switch because MOSFET is an excellent chopper due to its offset voltage, which is less
Vi +
C LM102 than BJT’s.
C
Control gate Working: When a negative pulse is applied to switch, p-channel MOSFET will turn it
ON, which causes the capacitor to hold the charge with constant time w.r.t input voltage.
(b) Practical diagram
Whereas in absence of negative pulse, the switch is OFF and capacitor is isolated from
Fig. 12 : Sample-and-hold circuit
the circuit.
MULTIVIBRATOR
• It is basically a two-stage switching electronic circuit in which the output of the
first stage is fed to the input of the second stage & vice versa.
• Here, output of two stages are complement to each other.
• It is of three types: astable, monostable & bistable.
(a) Astable Multivibrator :
+VCC • It is also known as free running multivibrator.
• It generates square waves without any external triggering pulse.
R • This multivibrator does not have stable states i.e., have two quasi stable
RC1 C 1 R2 C2 Rc2 states where it switches back & forth from one state to each other.
1
VC1 + - - + Vc2 • The time period of switching of each stage depends upon the discharge of a
Q1 Q2 capacitive circuit.
• Its electronic circuit is shown in the fig. 13 (a)
Fig. 13(a) : Astable Multivibrator • It is used as a square wave generator, voltage to frequency converter, used
in construction of digital voltmeters etc.
DIGITAL LOGIC S3-17
(b) Monostable Multivibrator : +VCC
• It is also known by the name of monoshot or one-shot multivibrator or
RC1 R C1 R
univibrator. IC1 C c2
VC1 + - IR2
• This multivibrator has one stable state & one quasi-stable state. V
R1IR1 c2
• The time duration for which this multivibrator resides in the stable state is Q1 R2 IB2 Q2
C2
obtained by time taken for discharging an RC circuit. - V
• This multivibrator changes its state when the trigger pulse is applied. Input + BB
• Its electronic circuit is shown in the fig. 13 (b). trigger
pulse
• It is used for generating a uniform width pulse, to generate clean & sharp
Fig. 13 (b) : Monostable Multivibrator
pulses from distorted pulses, as a time delay unit etc. +VCC
(c) Bistable Multivibrator
• It is also known as flip flops or Eccles-Jordan circuit. I1 C1 C2 I2
RC1 R
• This multivibrator has two stable states. I4 c2
IC1 I3 R1 R Ic2
• Switching from one state to the other takes place due to the applied trigger IB2 2
Q1 Q2
pulse. I5 I6
R3 R4
• Its electronic circuit is shown in the fig. 13 (c).
• It act as memory element in shift registers, counters, can be utilize as frequency Set Reset
divider etc. -VBB
Fig. 13 (c) : Bistable Multivibrator
SCHMITT TRIGGER +VCC
• It acts as a wave shaping circuit where a square wave can be generated from a sine
IC1+I1 IC2=IE
wave input. RC1 C1 Rc2
• The electronic circuit is a bistable circuit where two transistor switches are Vout
I1 R1
connected regeneratively. RB
Q2
Q1
IB2
• The two transistors used here are identical to each other which get coupled Vin I2

through an emitter resistor.


IE RE R2
• Its electronic circuit is shown in the fig. 14.
It can be used as a voltage comparator, used for wave shaping circuits.
Fig. 14 : Schmitt trigger
DE CO D ER
Þ Decoder is combinational ckt which have many i/p and many o/p.
Þ It is used to convert binary data to other code (binary to ****)
eq. Binary to octal (3 × 8)
BCD to Decimal (4 × 10)
Binary to Hexadecimal
BCD to seven segment
Þ 2 to 4 decoder is minimum possible decoder.
2 × 4 Decoder:-

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

Parallel Data Input


Fig. 16 (a)
Also, the directional movement of the data through a shift register can be either to the
left, (left shifting) to the right, (right shifting) left-in but right-out, (rotation) or both left
and right shifting within the same register thereby making it bidirectional. In this tutorial
it is assumed that all the data shifts to the right, (right shifting).
Serial-in to Parallel-out (SIPO)
4-bit Serial-in to Parallel-out Shift Register
4-bit Parallel Data Output

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

4-bit Parallel Data Input


Fig. 16 (f)
DIGITAL LOGIC S3-23
The PIPO shift register is the simplest of the four configurations as it has only three
connections, the Parallel Input (PI) which determines what enters the flip-flop, the Parallel
Output (PO) and the sequencing clock signal (Clk).
Similar to the Serial-in to Serial-out shift register, this type of register also acts as a
temporary storage device or as a time delay device, with the amount of time delay being
varied by the frequency of the clock pulses. Also, in this type of register there are no
interconnections between the individual flip-flops since no serial shifting of the data is
required.
EBD_7203
S3-24 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

1. Consider the following circuit involving a positive edge


triggered D flip-flop: [2006, 2 Marks] (a) (
Cout a n -1 Å bn -1 )
(b) a n -1bn -1 c n -1 + a n -1bn -1cn -1
A
(c) Cout Å Cn -1
X
D Q (d) a n -1 Å b n -1 Å cn -1
Y 4. Consider a Boolean function f(w, x, y, z). Suppose that
exactly one of its inputs is allowed to change at a time.
If the function happens to be true for two input vectors i 1 =
CLK (w1, x1, y1, z1) and i2 = (w2, x2, y2, z2), we would like the
Q’ function to remain true as the input changes from i1 to i2
(i 1 and i 2 differ in exactly one bit position) without
becoming false momentarily. Let f (w, x, y, z) = S(5, 7, 11,
12, 13, 15) which of the following cube covers at f will
Consider the following timing diagram, Let Ai represents ensure that the required property is satisfied?
the logic level on the line A in the ith clock period.
(a) wxz, wxy, xyz, xyz, wyz [2006, 2 Marks]
(b) wxy, wxz, xyz
CLK (c) wx yz, xz, wxyz
0 1 2 3 4 5 (d) xzy, xyz, wxz, wxz, xyz, xyz
X 5. Given two three bit numbers a2a1a0 and b2b1b0 and c the
carry in the function that represents the carry generate
function when these two numbers are added is
Let A’ represents the complement of A. The correct output [2006, 2 Marks]
sequence on Y over the clock period 1 through 5 is (a) a2b2 + a2a1b1 + a2a1a0b0 + a2a0b1b0 + a1b2b1 + a1a0b2b0
(a) A 0 A1A1' A 3A 4 (b) A 0 A1A '2 A 3 A 4 + a0b2b1b0
(b) a2b2 + a2b1b0 + a2a1b1b0 + a1a0b2b1 + a1a0b2 + a1a0b2b0
(c) A1A 2 A 2' A 3 A 4 (d) A1A '2 A 3 A 4 A 5' + a2a0b1b0
2. Consider the following circuit:
(c) a 2 + b 2 + ( a 2 Å b 2 ) ( a1 + b1 + ( a1 Å b1 ) ( a 0 + b0 ) )
X
(d) a 2b2 + a 2a1b1 + a 2a1a 0 b0 + a 2a 0 b1b0
+ a1 b2 b1 + a1a 0 b2b0 + a 0 b2b1b0
Y f
6. x

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]

(c) ( PQ + R ) (d) (PQ + R)


38. Consider the 4-to-1 multiplexer with two select lines S1
and S0 given below.
31. The truth table
X Y f(X, Y) 0 0

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) both switches are closed


A (b) both switches are open
B Z (c) only one switch is closed
(d) LED does not emit light irrespective of the switch
C positions
5. A combinational circuit has input A, B and C and its K-
map is as shown in figure. The output of the circuit is
(a) A+ B+C (b) ABC given by
BC
(c) AB + BC + AC (d) Above all 00 01 11 10
3. The truth table of a circuit is shown in figure
00 1 1
A
01 1 1
A B C Z
0
0
0
0
0
1
1
0
(a) ( AB + AB) C (b) ( AB + AB ) C
0 1 0 1 (c) ABC (d) A Å B Å C
0 1 1 1 6. f ( x 2 , x1 x 0 ) = ?
1 0 0 1 3 to 8 D0
1 0 1 1 Decoder
x0 I0 D1
1 1 0 1 D2
1 1 1 1 x1 I1 D3 f
D4
x1 I2 D5
The Boolean expression for Z is
D6
(a) ( A + B)( B + C) (b) ( A + B )( B + C ) D7
(a) P (1, 2, 4,5, 7 ) (b) å (1, 2, 4,5, 7 )
(c) ( A + B)( B + C) (d) Above all (c) å ( 0, 3, 6 ) (d) None of these
EBD_7203
S3-30 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
7. The logic circuit shown in figure implements
(a) (b)
3 to 8 D0
Decoder (c) (d)
x0 I0 D1
D2 11. A 4-bit ripple counter and a 4-bit synchronous counter are
x1 I1 made using flip flops having a propagation delay of 10 ns
D3
each. If the worst case delay in the ripple counter and the
D4 z synchronous counter be R and S respectively, then
x1 I2 D5 (a) R = 10 ns, S = 40 ns (b) R = 40 ns, S = 10 ns
D6 (c) R = 10 ns, S = 30 ns (d) R = 30 ns, S = 10 ns
EN D7 12. An AB flip-flop is constructed from an SR Flip-flop as
shown in figure. The expression for next state Q+ is
D
A
S Q

(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

All J.K. Input are HIGH


Vi

CLK (a) 24 (b) 48


(c) 25 (d) 36
DIGITAL LOGIC S3-31
16. The frequency of the pulse at z in the network shown in 22. The output ‘F’ of the multiplexer circuit shown in the figure
figure is will be
y
10 Bit Ring w 4-Bit Parallel x Mod - 25 4-Bit Johnson z
Counter Counter Ripple Counter Counter C
MUX
C
(a) 10 Hz (b) 160 Hz C F
(c) 40 Hz (d) 5 Hz SELECT
C
17. The 8-bit shift-left shift register and D flip-flop shown in
the figure is synchronized with the same clock. The D flip- B
flop is initially cleared. The circuit acts as A
b7 b6 b5 b4 b3 b2 b1 b0
(a) AB + BC + CA + B C
D Q (b) A Å BÅ C
CLK
Q (c) AÅB
(d) A BC + ABC + A BC + ABC
(a) Binary to 2’s complement converter 23. In the circuit shown below, the outputs Y1 and Y2 for the
(b) Binary to Gray code converter given initial condition Y1 = Y2 = 1 and after four input
(c) Binary to 1’s complement converter pulses will be
(d) Binary to Excess - 3 Code converter
18. The Boolean expression X (P, Q, R) = p (0, 5) Y2
Y1
is to be realized using only two 2-input gates. Which are Q Q
these gates? J J
(a) AND and OR (b) NAND and OR
(c) AND and XOR (d) OR and XOR
19. A master slave configuration consists of two identical flip- K Q K Q
flops connected in such a way that the output of the master
is input to the slave. Which one of the following is correct?
(a) Master is level triggered and slave is edge triggered. (a) Y1 = 1, Y2 = 0 (b) Y1 = 0, Y2 = 0
(b) Master is edge triggered and slave is level triggered. (c) Y1 = 0, Y2 = 1 (d) Y1 = 1, Y2 = 1
(c) Master is positive edge triggered and slave is negative 24. Which one of the following statements is not correct?
edge triggered. Conversion of EXCESS-3 code to BCD can be achieved
(d) Master is negative edge triggered and slave is positive by using
edge triggered.
(a) Discrete gates (b) 4 : 16 demultiplexer
20. The minimized expression for the given K map (X: don’t
(c) A 4-bit full adder (d) A 4-bit half adder
care) is
AB 25. The minimised form of the logical expression
00 01 11 10
CD
ABC + ABC + ABC + ABC is
00 0 0 1 1
(a) AC + BC + AB (b) AC + BC + AB
01 0 1
(c) AC + BC + AB (d) AC + BC + AB
11 1
26. Consider the following:
10 1 0 1 1 Any combinational circuit can be built using
(a) A + B (b) B + AC 1. NAND gates 2. NOR gates
3. EX-OR gates 4. Multiplexers
(c) C + AB (d) ABC
21. The function ‘F’ implemented by the multiplexer chip Which of these are correct?
shown in the figure is (a) 1, 2 and 3 (b) 1, 3 and 4
0 1 0 1 (c) 2, 3 and 4 (d) 1, 2 and 4
27. Figure shows a mod-K counter, here K is equal to

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 +

(a) 0000 (b) 0101


K0 Q0' K1 Q'1 K2 Q'2 (c) 1010 (d) 1111
CLK 38. Addition of all gray code to convert decimal (0 – 9) into
CLK CLK
gray code is
Clock (a) 129 (b) 108
(c) 69 (d) 53
fc fc 39. Determine parity checker output from the below figure. If
(a) (b) input is 11111 (D4D3D2D1D0) & 10000 (D4D3D2D1D0)
8 6

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

59. A certain 12-bit BCD digital-to-Analog converter has a full


scale output of 9.99 V. The converter step size is
60. What is the largest value of output voltage from an eight bit
DAC that produces 1.0 V for a digital input of 00110010?
61. The number of unused states in a 4-bit Johnson counter is
(a) an adder circuit (b) a subtractor circuit COMMON DATA & LINKED ANSWER TYPE QUESTIONS
(c) a comparator circuit (d) a parity generator circuit
54. Consider the following statements regarding registers and Statements for Linked Answer Questions 62 and 63
latches: Two products are sold from a vending machine, which has two
1. Registers are made of edge-triggered FFS, whereas push buttons P1 and P2. When a button is pressed, the price
latches are made from level-triggered FFS. of the corresponding product is displayed in a 7-segment
2. Registers are temporary storage devices whereas display.
latches are not. If no buttons are pressed, 0 is displayed, signifying ‘RS 0’.
3. A latch employs cross-coupled feedback connections. If only P1 is pressed, 2 is displayed, signifying ‘RS 2’.
4. A Register stores a binary word whereas a latch does
If only P2 is pressed, 5 is displayed, signifying ‘RS 5’.
not.
Which of these statements given above are correct? If both P1 and P2 are pressed, E is displayed, signifying ‘Error’.
(a) 1 and 2 (b) 1 and 3 The names of the segments in the 7-segment display, and the
(c) 2 and 3 (d) 3 and 4 glow of the display for 0, 2, 5 and E, are shown below.
55. A 1-bit full adder takes 20 ns to generate carry-out bit and
40 ns for the sum bit. What is the maximum rate of addition
per second when four 1-bit full adders are cascade?
(a) 107 (b) 1.25 × 107
(c) 6.25 × 10 6 (d) 105

NUMERICAL TYPE QUESTIONS Consider


(i) push button pressed/not pressed is equivalent to logic 1/
56. The ideal inverter in figure has a reference voltage of 2.5 0 respectively.
V. The forward voltage of the diode is 0.75 V. The
maximum number of diode logic circuit that may be (ii) a segment glowing/not glowing in the display is equivalent
cascaded ahead of the inverter without producing logic to logic 1/0 respectively.
error, is 62. If segments a to g are considered as functions of P1 and
P2, then which of the following is correct?
+5V +5V+5V (a) g = P1 + P2 ,d = c + e (b) g = P1 + P2, d = c + e

(c) g = P1 + P2 ,e = b + c (d) g = P1 + P2, e = b + c


63. What are the minimum numbers of NOT gates and 2-
+5V
input OR gates required to design the logic of the driver
A Z for this 7-segment display?
(a) 3 NOT and 4 OR (b) 2 NOT and 4 OR
B (c) 1 NOT and 3 OR (d) 2 NOT and 3 OR
C Statement for Linked Answer Questions 64 and 65
D
In the following circuit, the comparator output is logic “1” if
n Stage of Diode Logic V1 > V2 and is logic “0” otherwise. The D/A conversion is done
DIGITAL LOGIC S3-35
3
as per the relation VDAC = å 2 bn
n -1
Volts, where b3(MSB), b2, P
r =0 Q
b1 and b0 (LSB) are the counter outputs.
The counter starts from the clear state. Q
4bit
D/A converter P Q

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

PAST GATE QUESTIONS EXERCISE 3. (c) Let


1. (a) Considering the inputs in the diagram, the equation for A = a n -1a n -2 ....a 0
D flip-flop comes out to be
B = b n -1bn -2 ....b0
D = ( Ai X ') ' ( X 'Q') '
C = cn -1cn -2 ....c0
(
D = A i' + X + X + Q ) Also, let the overflow condition be 0.
Then, 0 = a 'n -1 b 'n -1 cn -2 + a n -1bn -1c 'n -2
D = Ai' + X + Q
Now, we have to check the response over different clock Also, it is known that cn–1 is Cout
period that Clock period 0 through Clock period 5. Hence, 0 = Cout Å Cn -1

i.e., Overflow condition is 0 = Cout Å Cn -1


Clock X Q=0 Q=1 Ai Y 4. (a) The problem is solved in two steps:
0 1 0 1 A0' A0' 1. Draw the K map
1 1 0 1 A1' A0' 2. Check the cube covers from the different options
1. K map is as follows
2 0 0 1 A2' A1
3 1 0 1 A3' A1'
wx
4 1 0 1 A4' A3 00 01 11 10
yz
5 0 0 1 A5' A4'
00 0 0 0 0
Therefore, the correct sequence on Y over clock period
01 0 0
0 through 5 is A '0 , A 0' , A1 , A1' , A 3 , A '4 1 1
And clock period 1 throug 5 is A 0 , A1 , A1' , A 3 , A 4
2. (c) As in the circuit, lets draw how the input is fed and 11 1 1 1 0
output is obtained.
F = XY × YZ Þ XY + YZ = F 10 0 0 1 0

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

(0.5)10 = (0.1)2 and (0.1) º (1) ´ 2 - 1 00 1 00 1


In normalized form, left bit to the decimal point should 01 1 1 01 1 1
be 1. 11 1 1 11 1 1
0.1 º 1.0 ´ 2-1 10 1 1 10 1 1
Here, exponent value º (– 1).
Mantissa value = all 0’s Minterm: PQ Minterm: QR
DIGITAL LOGIC S3-41
This question can be easily solved by comparing it to
PQ the standard diagram of the multiplexer:
RS 00 01 10
00 1 0 ® I0 0
01 1 1 PQ
1 ® I1
11 1 1 Y
R ® I2 PQR
10 1 1
Minterm: QS R ® I3
PQR
So, the Minimal sum of products form of F is as Q ® S0
follows:
PQ + QR + QS P ® S1
37. 5
We know that how to convert a number of a given base Now, note the output of each AND Gate written
‘b’ to base 10; for example: individually final output is Y = 0 + PQ + PQR + PQR
(4102.3)6 = (4 × 63) + (1 × 62) + (0 × 61) + (2 × 60) The K-Map of this is as follows:
+ (3 × 6–1)
Now, we also know that if an equation holds for base ‘b’ PQ
R 00 01 10
it will hold for any base ‘b’ if all numbers of the equation
are converted to b' (both sides of the equation). 0 1 1
The given equation is: 1 1 1
312
= 13.1 OR (312)b = (13.1)b Using Above K - Map the minimal sum-of-product
20 (20)b
form is: QR + PQ + PQR
Let the base of the given equation is ‘b’. We shall convert
all numbers from base ‘b’ to base ‘10’ as follows: 39. (d) A function F is self dual if it has equal numbers of min
terms and max terms, also mutually exclusive terms are
(3 ´ b2 ) + (1´ b1 ) + (2 ´ b0 ) not to be included.
= (1´ b1 ) + (3 ´ b0 ) + (1´ b -1 )
1 0
(2 ´ b ) + (0 ´ b ) 2n
The number of mutually exclusive terms is = 2n–1
2
3b2 + b + 2 1
Þ = b +3+ No. of functions possible by taking any of the one
2b b
terms from the above mentioned mutually exclusive
2
æ b 2 + 3b + 1 ö pair = 22
n -1

Þ 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

P1 = QS there can’t be both input HIGH and NAND. So LED


doesn’t emit light.
P2 = QS
\ F (P, Q, R, S) = P1 + P2 5. (d) ABC + ABC + ABC + ABC
= QS + QS
( ) (
= C AB + AB + C AB + AB )
42. (c) y = xb + xa
x is working as a selection line. ( ) (
= C AB + AB + C AB + AB = A Å B Å C )
Two input lines are a and b
\ function F (x, y, a, b) can be implemented using
6. (b) f = å m ( 0,3, 6 ) = å m (1, 2, 4, 5, 7 )
(2 × 1) multiplexer as follows.

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

P.S. FFinputs N.S. = C + B + A = ABC


Q2 Q1 Q0 J 2 K2 J1 K1 J0 K0 Q+2 Q1+ Q0+ 9. (d) (
Z = ABC + AB + AB + AB = A BC + B + A B + B ) ( )
(Q1 ) (Q0 ) (Q2 ) (Q2 ) (Q1 ) (Q0 ) = A ( B + C) + A = A + B + C
0 0 0 1 0 0 1 0 1 1 0 0 10. (a) At first edge of clock, D is HIGH. So Q will be high till
1 0 0 1 0 1 0 0 1 1 1 0 2nd rising edge of clock. At 2nd rising edge. D is low
1 1 0 0 0 1 0 1 1 1 1 1 so Q will be LOW till 3rd rising edge of clock. At 3rd
44. (d) rising edge. At 4th rising edge D is HIGH so Q will be
HIGH till 5th rising edge. At 5th rising edge, D is LOW,
so Q will be LOW till 6th rising edge.
PRACTICE EXERCISE 11. (b) Propagation delay if 4-bit ripple counter
R = 4 × tpd = 40 ns
1. (c) 42 in a byte 00101010 In synchronous counter, all F/Fs are given clock
42 in a word 000000000101010 simultaneously.
– 42 in a byte 11010110 So S = 10 ns
– 42 in a word 1111111111010110
2. (d) Z = A + AB( + BC + C ) 12. (c) A B S R Q Q+
(
= A+ A+B+B+C +C = A+B+C ) 0 0 1 0 0 1 Q+ = AB + AQ = AB + BQ
ABC = A + B + C 0 0 1 0 1 1
AB + BC + AC = A + B + B + C + A + C = A + B + C 0 1 0 1 0 0
0 1 0 1 1 0
3. (b) ( A + B)( B + C) = ( A B)( BC) = A BC 1 0 0 0 0 0
1 0 0 0 1 1
( A + B) ( B + C) = ( A + B) + ( B + C) = A + B + C 1 1 1 1 0 x
1 1 1 1 1 x
( A + B) ( B + C ) = ( A + B ) + ( B + C )
= AB + B + C = A + B + C 13. (b) Output of 1st XOR = X1 + X1 = X
From truth table Z = A + B + C Output of 2nd XOR = X X + X X = 1
4. (d) Output of NAND must be LOW for LED to emit light. So after 4, 6, 3 .........20 XOR output will be 1
So both input to NAND must be HIGH. If any one or 14. (b) It is a down counter because 0 state of previous FFs
both switch are closed, output of AND will be LOW. If change the state of next FF. You may trace the following
both switch are open, output of XOR will be LOW. So sequence, let initial state be 0 0 0
DIGITAL LOGIC S3-43

FFC FFB FFA F = B(A + A)


+ + + F= B
JKC JKB JKA C B A
111 111 111 111 22. (d) A B C F
000 000 110 110
000 110 111 101 0 0 0 C 0
000 001 110 100 0 0 1 C 1
111 111 111 011 0 1 0 C 1
001 000 110 010 0 1 1 C 0
001 110 111 001
1 0 0 C 1
000 001 110 000
1 0 1 C 0
15. (a) It is a 5 bit ripple counter. At 11000 the output of NAND
gate is LOW. This will clear all FF. So it is a Mod-24 1 1 0 C 0
counter. Note that when 11000 occur, the CLR input is 1 1 1 C 1
activated and all FF are immediately cleared. So it is a
MOD 24 counter not MOD 25. Given
16. (d) 10-bit counter is a MOD-10, so it divides the 160 kHz
input by 10. Therefore, w = 16 kHz. The four bit parallel C A B O/p
MUX
counter is a MOD-16. Thus, the frequency at x = 1 kHz. C
The MOD-245 ripple counter produces a frequency at C F 0 0 C ® A BC
y = 40 Hz. (1 kHz/25 = 40 Hz). The four-bit Johnson C SELECT 0 1 C ® ABC
counter is a MOD-8. This, the frequency at z = 5 Hz.
A 1 0 C ® ABC
17. (b) The output of XOR gate is Z = bi +1 Å bi and this
1 1 C ® ABC
output shift the register to left, B
Initially Z = 0
After 1st clock Z = b7 Å 0 = b7 So, F = A BC + ABC + A B C + ABC
After 2nd clock Z = b7 Å b6 23. (d) After 1st pulse Y1 = 0 Y2 = 1
3rd clock Z = b6 Å b5 After 2nd pulse Y1 = 0 Y2 = 0
4th clock Z = b5 Å b4 After 3rd pulse Y1 = 1 Y2 = 0
18. (d) The Boolean expression After 4th pulse Y1 = 1 Y2 = 1
X(P, Q, R) = p(0.5) 24. (d) Half-adder is a 1-bit adder circuit.
OR and XOR only two points gates. BC
19. (a) A BC BC BC BC
20. (a) AB 1 1 1
A
CD 00 01 11 10 25. (a)
A 1
00 1 1
F = A.C + AB + BC
01 1
26. (d) NAND & NOR are universal gates, so along with MUX
11 1 they can be used to implement any combinational
circuit.
10 1 1 1
27. (c) J A = QB K A = 1 J B = QA K B = 1 QA QB
X X X X X 0 ü
BC ï
1 1 0 1 1 0 ý MOD - 3
The expression is Y = A + BC ï
1 1 1 1 0 0 þ
0 1 0 1 0 0
21. (b) A B F
28. (b)
0 0 A.B.0
0 1 29. (d) J 0K 0 J1K1 Q0 Q1
A.B.1
1 0 11 0 1 0 0 Initially
A.B.0 11 1 0 1 0 1st pulse
1 1
A.B.1 0 1 0 1 0 1 2nd pulse
11 0 1 0 0 3rd pulse
F = A.B.0 + A.B.1 + A.B.0 + A.B.1
11 1 0 1 0 4th pulse
F = A.B + A.B 0 1 0 1 0 1 5th pulse
EBD_7203
S3-44 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
After 4th pulse, output is same as after 1st one. So, (For Input 111111 (D4 D3 D2 D1 D0)
sequence gets repeated. So output after 3rd pulse Similarly
would be same as after 3rd pulse, i.e. (0, 0). (For Input 10000 (D4 D3 D2 D1 D0)
30. (b) These stage Johnson ring counter is a MOD-6 counter: E = 1 (Error)
Q0Q1Q2 will follow the normal sequence as expected 40. (d) May be 3, 3 + 16, 3 + 16 + 16 or 3 + 16 + 16 + 16
i.e. 10kHz
000 ® 001 ® 011 ® 111 41. (a) fQ3 = = 625Hz
16
RB
­ ¬¾ ¾ 100 ¬ 110 ¬¾ ¾ 42. (b) Duty cycle = R + 2R
31. (c) The circuit must consist of at least MOD -6 counter as A B
it will from (0000) to (0101) i.e. 6 states (minimum). 750
Þ RA = - 2 ´ 750 = 1.5 kHz
32. (d) 0.25
33. (a) Y Z + X Z + X Y = Y Z ( X + X ) + X Z ( Y + Y ) + X Y ( Z + Z) tp 0.25 ´ 10-6
and C = = = 480 pF
= XY Z + X Y Z + X ZY + X YZ 0.693R B 0.693 ´ 750
34. (b) 43. (a) Output = Y1.Y2 = AB. CD
35. (a) MOD-12, 4FFs = 4 × 60 = 240 ns
44. (a) Metastability in D-Flip flop occurs when set-up time of
tpd of NAND = 25 ns
input data is not met.
total tpd = 265 ns
45. (b) 12, 64, 8 and 0 are all power of 8. The proceeding number
1 1 is translatable in second to an octal number
So, fc = = = 3.774 MHz
3 × 83 + 7 × 8 2 + 5 × 8 1 + 3 × 8 0
t pd 265 ´ 10-9
37538 = 011 111 101 0112
36. (d) After 16 × 2 = 32 pulse ‘0000’ 46. (b) A - 3, B - 4, C - 1
After 37 pulses 47. (d) The Boolean expression is
0110 – 0101 = 0001
37. (c) Sin A B C D
( ) (
A B + C + AB + A + B C )
1 0 1 1 0 = AB + AC + AB + AC + BC
0 1 0 1 1 ( ) (
= AB + AB + AC + AC + BC )
1 0 1 0 1
= B + A + BC = A + B + C
1 0 1 0
48. (a) Carry look ahead adder is faster since the carry is
38. (d) generated in parallel at all stages of addition rather
Decimal BCD Gray Code than sequentially as in ripple adders.
0 0 0 0 0 0 0 0 0 0 49. (a) It is a shift register.
1 0 0 0 1 0 0 0 1 1 50. (a)
2 0 0 1 0 0 0 1 1 3 (i) Interface: The common boundary
3 0 0 1 1 0 0 1 0 2 between various sections and
4 0 1 0 0 0 0 4 0 6 sub-section
5 0 1 0 1 0 1 1 0 7 (ii) Bit: A binary digit
6 0 1 1 0 0 1 1 1 5 (iii) Baud Speed: A measure of rate of data
7 0 1 1 1 0 1 0 1 4 transmission.
8 1 0 0 0 1 1 0 0 12 51. (c) One mod-13 counters followed by the mode - 6 counter
9 1 0 0 1 1 1 0 1 13 will result in mod-N counter where N is divisible by
+ 53 both 13 and 6 i.e. 78.
39. (a) 1 MOD 78
E = 1 (Error) MOD 3 A0 MOD 6
A0 OUTPUT
1
A6 COUNTER A 6 COUNTER
1 0
52. (a) y = C + A, y = A 'C'
1 0
1
0
DIGITAL LOGIC S3-45
60. (00110010)2 = 5010
53. (c) X Y 1.0 V = K × 50 Þ K = 20 m
F1 the largest output for input (11111111)2 = 25510
Vout(Max) = 20 mV × 255 = 5.10 V
61. Johnson counter is 2N – 1 counter
F2
where, N = Number of bits
2 × 4 = 8 states (used)
Total States = 2N = 16
F3
Remaining states 16 – 8 = 8 states

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

COMPUTER ORGANIZATION AND


ARCHITECTURE

C Ø Machine instructions and addressing modes

O Ø

Ø
ALU and data-path

CPU control design

N Ø Memory interface

T
Ø I/O interface (Interrupt and DMA mode)

Ø Instruction pipelining

E Ø Cache and main memory

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

Name Mnemonic Operation


Load LD Transfers data from a memory location
to a processor register
Store ST Transfers data from a processor register
to a memory location
Move MOV Transfers data between register-register
OR between Memory-Register
Exchange XCH Swaps data between register-register
OR between Memory-Register
Input IN IN read from a part.
Output OUT OUT write to part.
Push PUSH Pushes the data from a register onto
a memory stack
Pop POP Pops the data from a memory stack
and store it onto a register
Mnemonics are symbols used to represent various instructions. An instruction
can be specified in various addressing modes. As a specific case, the immediate
mode is recognized from a pound sign ‘#’ placed before the operand. For example
the LOAD to AC instruction can be used in eight different addressing modes as
follows:
COMPUTER ORGANIZATION AND ARCHITECTURE S3-49
Eight Addressing Modes for the Load Instruction

Mode Assembly Convention Register Transfer


Direct address LD ADR AC ¬ M[ADR]
Indirect address LD @ADR AC ¬ M[M[ADR]J
Relative address LD $ADR AC ¬ M[PC + ADR]
Immediate operand LD #NBR AC ¬ NBR
Index addressing LD ADR(X) AC ¬ M[ADR + XR]
Register LD R1 AC ¬ R1
Register indirect LD (R1) AC ¬ M[R1]
Autoincrement LD (R1) + AC ¬ M[R1], R1 ¬ R1 + 1
Abbreviations used has meaning as follows : ADR=address, NBR=number/operand,
X=index register, AC=Accumulator, R1=General purpose register, @=indirect
addressing mode, $=relative address to the PC,
2. Data Manipulation Instructions:
Data manipulation instructions perform various operations on data and provide
the computational capabilities for the computer. We can further classify the Data
Manipulation Instructions in following 3 types :
I. Arithmetic Instructions:
It includes addition, subtraction, multiplication, and division. Following table
shows various arithmetic instructions in a typical computer:
Typical Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with carry ADDC
Subtract with borrow SUBB
Negate (2’s complement) NEG

Overflow and Underflow :


If increment operation is applied to an n-bit register whose all 1111 1111 1111 1111
bits contain ‘1’, the result after increment operation would not +1
fit into that register. After increment all bits of the register will 1 0000 0000 0000 0000
contain ‘0’.This is called overflow of the data.
(Overflow of the data)
Similarly, If decrement operation is applied to an n-bit register
whose all bits contain ‘0’, the operation needs a borrow that is
1 0000 0000 0000 0000
not available due to all 0s. After decrement all bits of the register
-1
will contain ‘1s’. This is called underflow of the data .
(Underflow of the data) 1111 1111 1111 1111
The arithmetic instructions may have different variants on a typical computer.
For example the “ADD” instruction may have following 3 variants : For binary
integers, For floating-point operands, and For decimal operands. Carry resulting
EBD_7203
S3-50 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
from any arithmetic instruction (like as discussed in OVERFLOW) is stored in
a special “Carry Flip-Flop” that enables the system to use it for the instruction
“Add with Carry” that performs the addition of two operands along with the
previous carry. Similarly, the “subtract with borrow” instruction subtracts
two words and a borrow which may have resulted from a previous subtract
operation. The negate instruction forms the 2’s complement of a number,
effectively reversing the sign of an integer when represented in the signed-
2’s complement form.
II. Logical and Bit Manipulation Instructions:
Logical instructions include bitwise AND, bitwise OR etc. Logical and bit
manipulation instructions in a typical computer are as follows :
Typical Logical and Bit Manipulation Instructions
Name Mnemonic
Clear CLR
Complement COM
AND AND
OR OR
Exclussive-OR XOR
Clear carry CLRC
Set carry SETC
Complement carry COMC
Enable interrupt EI
Disable interrupt DI

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 :

Bit Not Bit R1 R2 R1 AND R2 R1 OR R2 R1 XOR R2


0 1 0 0 0 0 0
1 0 0 1 0 1 1
Example : 1 0 0 1 1
MOV BL, 01010111B 1 1 1 1 0
AND BL, 11110000B
Result in BL : 01010000B
Other bit manipulation instruction has following effects :
· Clear Carry (CLRC) : clear the carry bit to 0
· Set Carry (SETC) : Sets the carry bit to 1
· Complement Carry(COMC) : inverts the value of the carry bit
· Enable Interrupt : enables the interrupt mode
· Disable Interrupt : disables the interrupt mode
III. Shift Instructions:
These instructions are used to move the bits of a Memory Word or register in a
particular directions. Shift instructions have many variants like : logical shifts,
arithmetic shifts, or circular shifts. In either case the shift may be to the right or to
the left. Various shift instructions in a typical computer are as follows :
COMPUTER ORGANIZATION AND ARCHITECTURE S3-51
Typical Shift Instructions
Name Mnemonic
Logical shift right SHR
Logical shift left SHL
Arithmetic shift right SHRA
Arithmetic shift left SHLA
Rotate right ROR
Rotate left ROL
Rotate right through carry RORC
Rotate left through carry ROLC

(a) Logical Shifts :


These instructions insert 0 at the last bit position and shift all the bits of the
Example :
memory word in specified direction by one bit position.
1. Logical Shift Right:
(b) Arithmetic shifts :
Before shift : 1001 1010 0110 1111
These instructions are meant for signed-2’s complement numbers. These
After Shift : 0100 1101 0011 0111
instructions preserve the sign bit in the leftmost position.
2. Logical Shift left :
In case of Arithmetic shift right(SHRA), while shifting of individual bits , the
Before shift : 1001 1010 0110 1111
sign bit is also shifted to the right together with the rest of the number, but the
After Shift : 0011 0100 1101 1110
sign bit itself remains unchanged. In case of arithmetic shift-left (SHLA) 0 is
inserted at the last bit position and is identical to the logical shift-left instruction.
(c) Circular Shifts :
These instructions treat the bit sequence as a circular list. It means that the
rightmost bit position is treated adjacent to the leftmost bit. Concept is similar
to a circular queue, in which the elements that get deleted from one end of the
queue inserted at the other end of the queue. Another variants of circular
shifts are RORC and ROLC. A rotate-left through carry (RORC) instruction
transfers the carry bit into the rightmost bit position of the register, transfers
the leftmost bit position into the carry, and at the same time, shifts the entire
register to the left. Similar concept could be applied to the ROLC as well.
Following examples will make circular shifts more clear :

Before Shift 1 0 0 1 0 0 1 0

After Rotate right (ROR) 0 1 0 0 1 0 0 1


After Rotate left (ROL) 0 0 1 0 0 1 0 1

Before Shift 1 0 0 1 0 0 1 0 Carry = 0


After RORC 0 1 0 0 1 0 0 1 0
After ROLC 0 0 1 0 0 1 0 0 1

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

CPU CONTROL DESIGN


Design of Control Unit
The bits of the microinstructions consist of various fields. These fields include
opcode field, mode field and address field. The opcode field provides control Opcode Mode field Address field
bits to perform some microoperations like addition, complement etc. in the
(A Typical Instruction Format)
system. The mode field bits specify the addressing mode using which the
address field is to be interpreted. The address field is used to specify the
operand, or the address of the operand either directly or indirectly. Opcode (9-bits)
The number of bits in the Opcode field can be reduced by
grouping mutually exclusive variables into fields and 3 Bits 3 Bits 3 Bits
encoding the k bits in each field to provide 2 k
F1 F2 F3
microoperations. Each field requires a decoder to produce
the corresponding control signals. This method requires
additional hardware outside to the control memory. As the 3 × 8 decoder 3 × 8 decoder 3 × 8 decoder
signals passes through this additional hardware, it increases
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
the delay time of the control signals.
The nine bits of the Opcode field are divided into three
subfields of three bits each. The control memory output of AND
each subfield must be decoded to provide the distinct ADD
DRTAC Arithmetic
microoperations. The outputs of the decoders are connected logic shift
to the appropriate inputs in the processor unit. Above Figure unit
shows the three decoders. Each of the three fields of the
DRTAR
PCTAR

microinstruction presently available in the output of control From From


memory are decoded with a 3 x 8 decoder to provide eight PC DR(0 – 10) Load
outputs. Each outputs is connected to the proper circuit to AC
initiate the corresponding microoperation As shown in
0 1
above Fig, outputs 5 and 6 of decoder F1 are connected to Select
Multiplexers
the load input of AR so that when either one of these outputs
is active, information from the multiplexers is transferred to
AR. The multiplexers select the information from DR when
Load
output 5 is active and from PC when output 5 is inactive.
AR Clock
The transfer into AR occurs with a clock pulse transition
only when output 5 or output 6 of the decoder is active. Decoding of microoperation fields
EBD_7203
S3-56 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The other outputs of the decoders that initiate transfers between registers must be
connected in a similar fashion. The control signals come from the outputs of the decoders
associated with the symbols AND, ADD, and DRTAC, respectively. The other outputs
of the decoders that are associated with an AC operation must also be connected to the
arithmetic logic shift unit in a similar fashion.
Microprogram Sequencer
A Microprogrammed control unit mainly consists of control memory and the circuits that
select the next address. The address selection part is called a microprogram sequencer.
The purpose of a microprogram sequencer is to present
External an address to the control memory so that next
(MAP) microinstruction may be fetched from memory and
executed. The next-address logic of the sequencer
determines the specific address source to be loaded
3 2 1 0 into the control address register. The present
I0 Input Load
I1 logic S1 MUX 1 SBR microinstruction supplies the information to the
T S0 microsequencer about how the next address will be
selected. Some sequencers provide an output register
which can function as the address register for the
1 Incrementer control memory. The internal structure of a
I MUX 2 Test
microsequencer is shown in figure below :
S
Z Select The control memory is included in the diagram to show
Clock CAR the interaction between the sequencer and the memory
attached to it. The circuit contains two multiplexors.
The first multiplexer selects an address from one of
four sources and routes it into a control address register
CAR. The second multiplexer tests the value of a
selected status bit and the result of the test is applied
Control memory
to an input logic circuit. The address for the control
Microops CD BR 64
64 4744 8 678 678 4AD
744 8 memory is provided at the output of CAR. The content
of CAR is incremented and applied to one of the
multiplexer inputs and to the subroutine register SBR.
The other three inputs to multiplexer number 1 come
14 4244 3
from the address field of the present microinstruction,
from the output of SBR, and from an external source
that maps the instruction. The CD (condition) field of
the microinstruction selects one of the status bits in
Microprogram sequencer for a control memory the second multiplexer. If the bit selected is equal to 1,
the T (test) variable is equal to 1; otherwise, it is equal
to 0. The T value together with the two bits from the BR (branch) field goes to an input
logic circuit. Typical sequencer operations are: increment, branch or jump, call and return
from subroutine, load an external address, push or pop the stack, and other address
sequencing operations. With three inputs, the sequencer can provide up to eight address
sequencing operations. The input logic circuit in above figure has three inputs, I0, I1,
and T, and three outputs, S0, S1, and L. Variables S0 and S1 select one of the source
addresses for CAR. Variable L enables the load input in SBR. The binary values of the
two selection variables determine the path in the multiplexer. For example, with S1 S0 =
10, multiplexer input number 2 is selected and establishes a transfer path from SBR to
CAR. Note that each of the four inputs as well as the output of MUX 1 contains a 7-bit
address. The following is the truth table for the input logic circuit:
COMPUTER ORGANIZATION AND ARCHITECTURE S3-57

BR Input MUX 1 Load SBR


Field I1 I0 IT S1S0 L
0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 0
0 1 0 1 0 0 0 0
0 1 0 1 1 0 1 1
1 0 1 0 × 1 0 0
1 1 1 1 × 1 1 0
Input Logic Truth Table for Microprogram Sequencer
Inputs I1 and I0 are identical to the bit values in the BR field. The bit values for S1 and So
are determined from the stated function and the path in the multiplexer that establishes
the required transfer. The subroutine register is loaded with the incremented value of
CAR during a call microinstruction (BR = 01) provided that the status bit condition is
satisfied (T = 1).
Example 1: The instruction format of a CPU is

OP CODE MODE Reg R

One memory word


Mode and Reg R together specify the operand. Reg R specifies a CPU register and
Mode specifies an addressing mode. In particular, Mode = 2 specifies that the
register Reg R contains the addrress of the operand, after fetching the operand, the
contents of Reg R are incremented by 1’.
An instruction at memory location 2000 specifies Mode = 2 and Reg R refers to
program counter (PC).
(i) What is the address of the operand ?
(ii) Assuming that this is a non-jump instruction, what are the contents of PC
after the execution of the instruction ?
Sol.
(i) Address of the operand is the content of PC
(ii) 2001
Method :

Register R
Upcode Mode = 2 Reg R Address of the operand
Memory

Operand

2000 Upcode Mode = 2 Reg R = PC


PC 2000

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

Memory connection to the CPU


This configuration gives a memory capacity of 512 bytes (128x4) of RAM and 512 bytes
of ROM.
The low order bits (1-7) in the address bus are used to select one of 128 possible bytes
addresses.
The bits 8 and 9 in the address bus are used to select a particular RAM chip using a 2x4
decoder. The output of the decoder is connected to CS1 input of every RAM chip.
Following table shows how a particular RAM chip is selected based on values of 8th and
9th bits in the address bus :
COMPUTER ORGANIZATION AND ARCHITECTURE S3-59
th th
8 bit in address bus 9 bit in address bus RAM chip Selected
st
0 0 1 RAM Chip
0 1 2nd RAM Chip
1 0 3rd RAM Chip
1 1 4th RAM Chip
Address bus lines 1 to 9 are applied to the input address of ROM without going through
the decoder. The 10th bit in the address bus is used to decide that operation is performed
on RAM or ROM. It is clear from above figure that if 10th bit is 0, inputs in all RAM chips
will become 0 and all RAM Chips will be enabled, however input in ROM chip will
become 1 and it will be in high impedence state. In other case if 10 th bit is 1, inputs in all
RAM chips will become 1 and all RAM Chips will be disabled, however input in ROM
will become 0 and ROM will be enabled. This can be tabulated as follows :

Value of 10 th bit in address bus Active Chip


0 RAM
1 ROM
The RD (READ) and WR (WRITE) outputs that work as the control signal are applied at
the inputs of each RAM chip. The CS1 input in the ROM is connected to the RD control
line for the ROM chip to be enabled only during a READ operation.
The data bus of the ROM is unidirectional with only capability to perform READ operation
(output data). On the other hand, the data bus connected to the RAMs is bidirectional
i.e. it can transfer information both from CPU to Memory (Write Operation) and from
Memory to CPU(READ Operation).
When the 10th bit is equal to 0, i.e. when RAM is enabled the operations on different
inputs can be summarized by the following table :
CS1 CS2 RD WR Memory function State of data bus
0 0 × × Inhibit High-impedance
0 1 × × Inhibit High-impedance
1 0 0 0 Inhibit High-impedance
1 0 0 1 Write Input data to RAM
1 0 1 × Read Output data from RAM
1 1 × × Inhibit High-impedance

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

Instruction Operand Operand


fetch fetch store

Multiple Multiple
operands results

Instruction Instruction Operand Operand


Data Interrupt
address operation address address Interrupt
operation check
calculation decoding calculation calculation

Instruction complete, Return for string No intertupt


fetch next instruction or vector data

Instruction Cycle State Diagram


In above figure the instruction cycle has been divided in separate tasks. This is similar to
a factory assembly line. So we may apply the concept of pipelining. We can subdivide
the instruction processing into two stages: fetch/decode and
execute instruction. There are times during the execution of an Instruction Instruction Result
instruction when main memory is not being accessed. This time Fetch Execute
could be used to fetch the next instruction in parallel with the
execution of the current one. Consider the following figure : (a) Simplified view
The first stage fetches an instruction. In the next step, while the
Wait New address Wait
second stage is executing this instruction, the first stage takes
advantage of any unused memory cycles to fetch the next
instruction. If the fetch and execute stages were of equal duration, Instruction Instruction Result
the instruction cycle time would be halved. However, there are two Fetch Execute
problem that may arise : firstly, the execution time will generally be
longer than the fetch lime. Execution will involve reading and storing
operands and then executing it. Thus, the fetch stage may have to Discard (b) Expanded view
wait for some time before it can proceed further. And secondly, a Two-Stage Instruction Pipelines
conditional branch instruction makes the address of the next
instruction to be fetched unknown. In this case the fetch stage must wait until it receives
the next instruction address from the execute stage
The execute stage may then have to wait while the next instruction is fetched. The
common approach is to let the fetch stage get the next instruction in memory after the
branch instruction. If the branch is not taken, no time is lost. If the branch is taken, the
fetched instruction must be discarded and a new instruction fetched. While these factors
reduce the potential effectiveness of the two-stage pipeline, some speedup occurs.
Now, if we further subdivide these two stages into smaller parts, we may achieve more
speedup. Let us consider the following decomposition of the instruction processing.
• Fetch instruction (FI : Read the next instruction)
• Decode instruction (DI : decoding the opcode and operands specified)
• Calculate effective address of each operand (CO : it may include register indirect,
indirect, or other forms of address calculation)
EBD_7203
S3-64 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
• Fetch operands from memory (FO)
• Execute instruction (EI : Perform the indicated operation and store the result)
• Write operand (WO : Store the result in memory)
This division leads to almost equal duration of various stages. Following Figure shows
that a six-stage pipeline can reduce the execution time for 9 instructions from 54 time
units to 14 time units.
Time
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 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

Timing Diagram for Instruction Pipeline Operation


If the six stages are not of equal duration, there will be some waiting involved at various
pipeline stages, as discussed before for the two-stage pipeline. Another difficulty is the
conditional branch instruction, which can invalidate several instruction fetches. Following
Figure illustrates the effects of the conditional branch.
Time Branch Penalty

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

The Effect of a Conditional Branch on Instruction Pipeline Operation


COMPUTER ORGANIZATION AND ARCHITECTURE S3-65
In the Figure time diagram for instruction pipeline operation, assume that instruction 3 is
a conditional branch to instruction 15. Until the instruction is executed, there is no way
of knowing which instruction will come next. The pipeline, in this example simply loads
the next instruction in sequence (instruction 4) and proceeds as discussed above. In
Figure 3, the branch is not taken, and we get the full performance benefit of the pipelining.
In-Figure 4, the branch is taken. This is not determined until the end of time t=7. Here, the
pipeline is cleared of the instructions and at time t=8, instruction 15 enters the pipeline.
No instructions complete during time units 9 through 12; this is the performance penalty
incurred. Following flowchart indicates the logic needed for pipelining to account for
branches and interrupts :

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.

Speed from pipelining = Average instruction time unpiplined


Average instruction time piplined

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

(CPU execution time)Cache 2.7 ´ IC ´ clock cycle


= = 1.35
CPU execution time 2.0 ´ IC ´ clock cycle

Hence machine with no cache misses is 1.35 times faster.


Hit Ratio: The ratio of the number of hits divided by the total CPU references to memory
(hits plus misses) is the hit ratio.
Hit ratio = (no. of cache hits) / (Total no. of memory references)
COMPUTER ORGANIZATION AND ARCHITECTURE S3-69
A hit ratio of 0.8 means that 80 percent of total times the CPU would find the required
memory word in cache itself.
Applying the locality principle, main memories and caches are divided up into fixed-size
blocks. For cache memory these blocks are called “cache lines”. When a cache miss
occurs, the entire cache line is loaded from the main memory into the cache, not just the
word needed. For example, with a 64-byte line size, a reference to memory address 260
will pull the line consisting of bytes 256 to 319 into one cache line. Now, some of the
other words in the cache line will be needed shortly preventing further cache misses.
Example 6 : Let in a computer the cache has access time of 5 ns, main memory has access
time of 20 ns, and the hit ratio is 90%.
Sol. Then the average access time is calculated as follows :
Average access time = (Hit ratio × Cache access time) + (1-Hit ratio) × (cache
access time + main memory access time)
So, in above example, Average access time = 0.9 × 5ns + 0.1 × (5ns + 20ns) = 7 ns
Example 7 : When a cache is 10 times faster than main memory and cache can be used
70% of the time, how much speed we gain by using the cache ?
Sol. Let M = Main memory access time
C = Cache memory access time = M/10 (given)
Total access time using cache = 0.7 + 0.1 M Three types of mapping functions are
commonly used :
M 1. Direct Mapping
= 0.7 + 0.1M = 0.17 M
10 2. Associative Mapping
3. Set-Associative Mapping
Speed up M
= = 5.8
0.19M
Mappings Functions
For all three cases we consider the
As the size of cache is smaller it can occupy less number of words than main memory. So,
following configuration:
we need a mapping function to select where a main memory block go in cache memory.
· Cache Block size=4 bytes and data
We also need to ensure that the word can be searched in the cache in very less time. The
transformation of data from main memory to cache memory is referred to as a mapping can be transferred in multiples of
process. blocks,
1. Direct Mapping : · Cache size = 64 KB, hence cache
In this technique each block of main memory can only go to a single fixed position contains 2 14 Blocks (called
in cache. A single block of cache is a possible candidate for few fixed blocks of “Cache Lines”)
main memory. · Main memory block size = 4 bytes
This mapping is expressed as : · Main memory size = 16MB, hence
i = j modulo m where, i = cache block number main memory contains 222 Blocks
j = main memory block number · Each byte of main memory is
directly addressable by a 24-bit
m = number of blocks in cache
address (as 224 = 16M)
This mapping can be implemented by dividing the 24-bits of address into three
parts. The least significant w-bits are used to identify a word within a block. The
remaining s-bits are used to identify a main memory block among 2s blocks. This
field of s-bits is again divided into two parts for cache : r-bits line field(least
significant) and s-r bits tag field (most significant). The line field identifies one
cache line among 2r lines of cache.
EBD_7203
S3-70 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

• 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 :

Cache Line S tarting memory addres s of block


0 000000, 010000, …………………….., FF0000
1 000004, 010004, …………………….., FF0004
. .
. .
. .
14 00FFFC, 01FFFC, …………………….., FFFFFC
2 -1

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

When the cache is s+w


full and a block need
to be stored in cache, 64444 4744444 8 Cache Main memory
Memory address Tag Data W0 ü
the question arises Tag ü W1 ï
Word ï
which block in the ý L0 W2 ý B0
s
ïþ W3 ïþ
cache it would replace ? w
Many replacement
algorithms have been
ü
studied to maximize ï
w ý Lj
the hit ratio. Common ïþ s
w4j ü
replacement Compare w w(4j+1) ïï
w(4j+2) ý Bj
algorithms are : ï
(Hit in cache) w(4j+3) ïþ
FIFO(First in first ü
s ï
ý Lm – 1
out): The block that is
ïþ
oldest in the cache
becomes the victim, (Miss in cache)
Fully Associative Cache Organization
even if it is still being
used.
LRU (Least recently used): The block becomes the victim that was last used at time
t, and all other blocks are used atleast once after time t.
MRU(Most recently used) : It is based on the principle that the block that are old
in cache will continue to be used, So in this case the latest used block becomes the
victim.
• Address length = (s + w) bits
The disadvantage of Associative mapping is that implementation is complicated
• Number of addressable units
as extra logic circuits are required to examine the tags of all cache lines in parallel.
= 2s + w words or bytes
2. Set Associative Mapping : • Block size = line size = 2w words or
To overcomes the problems arising from above two techniques, Set associative bytes
• Number of blocks in main memory
mapping has been developed. This combines the simplicity of direct mapping with
2s + w
the power of the associative mapping. In this case, the cache is divided into v sets, = = 2s
2w
each containing k lines. • Number of lines in set = k
m=vxk • Number of sets V = 2x
• Number of lines in cache = kv = k × 2d
I = j modulo v Where, i=cache set number ; j = main memory block number ; • Size of tag = (s – d) bits
m = number of cache lines
This system is called k-way set associative mapping. In this case, one block Bi of
main memory can be mapped to any of the lines of set i. The address is divided into
three fields : Tag, Set and Word. The d-bits (Set Bits) specify one of the 2d sets. The
s-bits of the tag and set field specify one of the 2s blocks of main memory.
EBD_7203
S3-72 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The k-way set associative logic is explained in following example :
s+w

64444 4744444 8 Cache Main memory


Memory address Tag Data
B0
Tag Set Word F0 ü
ï B1
s d d w F1 ï
ï
ï
ý set q
ï
ï
ï
s–d Fk – 1 ï
þ
ì Fk ü s+w
ï ï Bj
ï ï
ï ï
Compare ï Fk + 1 ï
í ý set 1
ï ï
ï ï
ï ï
(Hit in cache) ï F2k – 1 ï
î þ

(Miss in cache)
K-way set associative logic

Three Major Placement Schemes

Number of Tag and Index Bits


Each word in cache has unique index (local addr.)Number of index bits = log2w
Index bits are shared with block offset when a block contains more words than 1
Assume partitions of w words each in the main memory.
W/w such partitions, each identified by a tag Number of tag bits = log2(W/w)
Where Size of main memory =W words and Cache size= w words.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-73
Example 8: A More realistic cache.Consider 4 GB, byte-addressable main memory:
1G words; byte address is 32 bits wide: b …b b …b b b . Each word is 32 bits
31 16 15 2 1 0
wide
Assume that cache block size is 1 word (32 bits data) and it contains 64 KB data, or
16K words, i.e., 16K blocks.
Sol: Number of cache index bits = 14, because 16K = 214
• Tag size = 32 – byte offset – #index bits = 32 – 2 – 14 = 16 bits
Cache requires, for each word:
• 16 bit tag, and one valid bit
• Total storage needed in cache
= #blocks in cache × (data bits/block + tag size + valid bits)
= 214(32+16+1) = 16×210×49 = 784×210 bits = 784 Kb = 98 KB
Physical storage/Data storage = 98/64 = 1.53
Example 9: Consider 4 GB, byte-addressable main memory.1Gwords; byte address is 32
bits wide: b31…b16 b15…b2 b1 b0 .Each word is 32 bits wide.Assume that cache block
size is 4 words (128 bits data) and it contains 64 KB data, or 16K words, i.e., 4K blocks.
Number of cache index bits = 12, because 4K = 212
Tag size = 32 – byte offset – #block offset bits – #index bits
= 32 – 2 – 2 – 12 = 16 bits
Cache requires, for each word:
• 16 bit tag, and one valid bit
• Total storage needed in cache
= #blocks in cache × (data bits/block + tag size + valid bit)
= 212(4×32+16+1) = 4×210×145 = 580×210 bits =580 Kb = 72.5 KB
Physical storage/Data storage = 72.5/64 = 1.13
Cache size equation
Simple equation for the size of a cache:
(Cache size) = (Block size) × (Number of sets)
× (Set Associativity)
• Can relate to the size of various address fields:
(Block size) = 2(# of offset bits)
(Number of sets) = 2(# of index bits)
(# of tag bits) = (# of memory address bits)
– (# of index bits) – (# of offset bits)

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

Cache Performance Formulas


Useful formulas for analyzing ISA/cache interactions :
(CPU time) = [(CPU cycles) + (Memory stall cycles)]
× (Clock cycle time)
(Memory stall cycles) = (Instruction count) ×
(Accesses per instruction) × (Miss rate) × (Miss penalty)
You Can split access time into instructions & data:
Avg. mem. acc. time =
(% instruction accesses) × (inst. mem. access time) + (% data accesses)
× (data mem. access time)
Another simple formula:
CPU time = (CPU execution clock cycles + Memory stall clock cycles) ×
cycle time
Useful for exploring ISA changes
Can break stalls into reads and writes:
EBD_7203
S3-76 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Memory stall cycles =
(Reads × read miss rate × read miss penalty) + (Writes × write miss rate ×
write miss penalty)
Factoring out Instruction Count
CPU time = IC ´ Clock cycle time ´

( CPIexec + Accesses ´ Miss rate ´ Miss penalty )


Accesses Misses
´ Miss rate ®
instruction instruction
SECONDARY MEMO RY
The size of the main memory is very small if large data need to be stored in it. Further, the
main memory is volatile in nature i.e. the contents are lost when power supply
is stopped. To overcome these another memory is used in a computer system
called secondary memory. This is large as well as non-volatile in nature.
Memory Hierarchies
Following diagram shows memory hierarchy in a modern computer system :

Registers

Cache
Faster
Speed
Bigger
Main memory Capacity

Magnetic disk

Tape Optical disk

A five-level memory hierarchy

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

A disk with four platters


A

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

A short jump to four memory locations beyond the address


of the next instruction is shown below.
– when the microprocessor executes
a short jump, the displacement is sign-extended and
added to the instruction pointer (IP/EIP) to generate the
jump address within the current code segment.
– The instruction branches to this new address for the next
instruction
in the program.When a jump references an address, a
label normally identifies the address. The JMP NEXT
instruction is an example.it jumps to label NEXT for the
next instruction very rare to use an actual hexadecimal
address with any jump instruction The label NEXT must
be followed by a colon (NEXT:) to allow an instruction to
reference itif a colon does not follow, you cannot jump to
it the only time a colon is used is when the label is used with a jump or call
instruction.
Near Jump
A near jump passes control to an instruction in the current code segment located within
±32K bytes from the near jump instruction.
– distance is ±2G in 80386 and above when operated in protected mode
– Near jump is a 3-byte instruction with opcode followed by a signed 16-bit
displacement.
Signed displacement adds to the instruction pointer (IP) to generate the
– jump address. because signed displacement is ±32K, a near jump can jump to
any memory location within the current real mode code segment .
– A near jump that adds the displacement (0002H) to the contents of IP.

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

CALLs with Register Operands


• An example CALL BX, which pushes the contents of IP onto the stack.
– then jumps to the offset address, located in register BX, in the current code
segment
Always uses a 16-bit offset address, stored in any 16-bit register except segment
registers.
CALLs with Indirect Memory Addresses
• Particularly useful when different subroutines need to be chosen in a program.
– selection process is often keyed with a number that addresses a CALL
address in a lookup table
COMPUTER ORGANIZATION AND ARCHITECTURE S3-85
• Essentially the same as the indirect jump that used a lookup table for a jump
address.
RET
• Removes a 16-bit number (near return) from the stack placing it in IP, or
removes a 32-bit number (far return) and places it in IP & CS.
– near and far return instructions in procedure’s PROC directive
– automatically selects the proper return instruction
Figure below shows how the CALL instruction links to a procedure and how
RET returns in the 8086–Core2 operating in the real mode
The effect of a near return instruction on the stack and instruction pointer.

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

1. A 5 stage pipelined CPU has the following sequence of (a) 3 (b) 4


stages (c) 5 (d) 6
IF : Instruction fetch from instruction memory Statements for Linked Answer Questions 5 and 6:
RD : Instruction decode and register read Consider the following data path of a CPU:
EX : Execute: ALU operations for data and address
computation
MAR MDR
MA : Data memory access : for write access, the register
read at RD stage is used
WB : Register write back
Consider the following sequence of instructions:
I1 : L R0 loc 1; R0 < = M [loc1]
I2 : A R0 ; R0; R0 < = R0 + R0
I3 : S R2 ; R0; R2 < = R2 – R0 S T
Let each state takes on clock cycle. IR PC GPRs
What is the number of clock cycles taken to complete the
above sequence of instructions starting from the fetch of
I1 ? [2005, 1 mark] ALU
(a) 8 (b) 10
(c) 12 (d) 15
2. Consider a direct mapped cache of size 32 kbyte with block
The ALU, the bus and all the registers in the data path are of
size 32 byte. The CPU generates 32 bit address. The number
identical size. All operations including incrementation of the PC
of bits needed for cache indexing and the number of tag bits
and the GPRs are to be carried out in the ALU. Two clock cycles
are respectively [2005, 1 mark]
are needed for memory bus into the MDR.
(a) 10, 17 (b) 10, 22
5. The instruction “ADD R0, R1” has the register transfer
(c) 15, 17 (d) 5, 17
interpretation R0 < = R0 + R1. The minimum number of clock
3. Match each of the high level language statements given on
cycles needed for execution cycle of this instruction is
the left hand side with the most natural addressing mode
[2005, 1 mark]
from those listed on the right hand side. [2005, 1 mark]
(a) 2 (b) 3
(c) 4 (d) 5
List - 1 List - II
6. The instruction “CALL Rn, sub” is a two word instruction.
P. A[l] = B[l] 1. Indirect addressing Assuming that PC is incremented during the fetch cycle of
the first word of the instruction, its register transfer
Q. while (* A ++); 2. Indexed addressing
interpretation is
R. int temp = * x; 3. Auto increment Rn < = PC + 1
PC < = M [PC]
(a) P - 3, Q - 2, R - 1 (b) P - 1, Q - 2, R - 3 The minimum number of CPU clock cycles needed during
(c) P - 2, Q - 4, R - 1 (d) P - 1, Q - 2, R - 3 the execution cycle of this instruction is [2005, 1 mark]
4. Consider a three word machine instruction: (a) 2 (b) 3
ADD A[R0], @ B (c) 4 (d) 5
The first operand (destination) “A[R0 ]” uses indexed 7. Increasing the RAM of a computer typically improved
addressing mode with R0 as the index register. The second performance because [2005, 1 mark]
operand (source) “@B” uses indirect addressing mode. A (a) virtual memory increases
and B are memory addresses residing at the second and the (b) larger RAM are faster
third words, respectively. The first word of the instruction (c) fewer page faults occur
specifies the opcode, the index register designation and the (d) fewer segmentation faults occur
source and destination addressing modes. During execution 8. What is the swap space in the disk used for?
of ADD instruction, the two operands are added and stored (a) Saving temporary HTML pages [2005, 1 mark]
in the destination (first operand). (b) Saving process data
The number of memory cycles needed during the execution (c) Storing the super-block
cycle of the instruction is [2005, 1 mark] (d) Storing device drivers
EBD_7203
S3-90 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
9. Normally user programs are prevented from handling I/O but two accesses to the same bank must be serialized. A
directly by I/O instructions in them. For CPUs having explicit cache block access may involve multiple iterations of parallel
I/O instructions, such I/O protection is ensured by having bank accesses depending on the amount of data obtained
the I/O instructions privileged. In a CPU with memory by accessing all the k banks is parallel. Each iteration requires
mapped I/O, there is no explicit I/O instruction. Which one decoding the bank numbers to be accessed in parallel and
of the following is true for a CPU with memory mapped I/O?
[2005, 1 mark] k
this takes ns. The latency of one bank access is 80 ns. If
(a) I/O protection is ensured by operating system 2
routine(s) c = 2 and k = 24, the latecy of retrieving a cache block starting
(b) I/O protection is ensured by a hardware trap at address zero from main memory is [2006, 2 marks]
(c) I/O protection is ensured during system configuration (a) 92 ns (b) 104 ns
(d) I/O protection is not possible (c) 172 ns (d) 184 ns
10. Which one of the following is true for a CPU having a single Statements for Linked Answer Questions 14 and 15 :
interrupt request line and a single interrupt grant line? Consider a machine with a byte addressable main memory of 216
[2005, 1 mark] byte. Assume that a direct mapped data cache consisting of 32
(a) Neither vectored interrupt nor multiple interrupting lines of 64 byte each is used in the system. A 50 × 50 two-
devices are possible
dimensional array of bytes is stored in the main memory starting
(b) Vectored interrupt are not possible but multiple
from memory location 1100H. Assume that the data cache is initially
interrupting devices are possible
empty. The complete array is accessed twice. Assume that the
(c) Vectored interrupt and multiple interrupting are both
contents of the data cache do not change in between the two
possible
(d) Vectored interrupt is possible but multiple interrupting accesses.
devices are not possible 14. How many data cache misses will occur in total?
11. Consider a new instruction named branch-on-bit-set [2007, 2 marks]
(mnemonic bbs). The instruction “bbs reg, pos, label” jumps (a) 48 (b) 50
to label if bit in position pos of register operand reg is one. (c) 56 (d) 59
A register is 32 bit wide and the bits are numbered 0 to 32, 15. Which of the following lines of the data cache will be
bit in position 0 being the least significant. Consider the replaced by new blocks in accessing the array for the second
following emulation of this instruction on a processor that time? [2007, 2 marks]
does not have bbs implemented. (a) line 4 to line 11 (b) line 4 to line 12
tem ¬ reg and mask (c) line 0 to line 7 (d) line 4 to line 8
Branch to lable if temp is non-zero Consider Data for Questions 16, 17 and 18
The variable temp is a temporary register. For correct Consider the following program segments. Here R1, R2 and R3 are
emulation, the variable mask must be generated by
purpose registers.
(a) mask ¬ 0 × 1 << pos [2006, 2 marks]
Instruction Operation Instruction size
(b) mask ¬ 0 × ffffffff << pos
(number of words)
(c) mask ¬ pos
(d) mask ¬ 0 × f MOV R1, 3000 R1 ¬ M [3000] 2
12. A CPU has a five-stage pipeline and runs at 1 GHz frequency. LOOP MOV R2, R3 R2 ¬ M [R3] 1
Instruction fetch happens in the first stage of the pipeline. ADD R2, R2 ¬ R1 + R2 1
A conditional branch instruction computes the target MOV R3, R2 M[R3] ¬ R2 1
addresses and evaluates the condition in the third stage of INC R3 R3 ¬ R3 + 1 1
the pipeline. The processor stop fetching new instructions DEC R1 R1 ¬ R1 – 1 1
following a conditional branch until the branch outcome is BNZ LOOP Branch on not zero 2
known. A program executes 109 instructions out of which HALT Stop 1
20% are conditional branches. If each instruction takes one Assume that the content of memory location 3000 is 10 and the
cycle to complete on average, the total execution time of the content of the register R3 is 2000. The content of each of the
program is [2006, 2 marks] memory locations from 2000 to 2010 is 100. The program is loaded
(a) 1.0 s (b) 1.2 s
from the memory location 1000. All the numbers are in decimal.
(c) 1.4 s (d) 1.6 s
16. Assume that the memory is word addressable. After the
13. A CPU has a cache with block size 64 byte. The main memory
execution of this program, the content of memory location
has k banks, each bank being c byte wide. Consecutive
c-byte chunks are mapped on consecutive banks with 2010 is [2007, 2 marks]
wrap-around. All the k blanks can be accessed in parallel, (a) 10 (b) 11
(c) 20 (d) 21
COMPUTER ORGANIZATION AND ARCHITECTURE S3-91
17. Assume that the memory is word addressable. After the Statement for Linked Answer Questions 23 and 24 :
execution of this program, the content of memory location Delayed branching can help in the handling of control hazards.
2010 is [2007, 2 marks] 23. For all delayed conditional branch instructions, irrespective
of whether the condition evaluations to true or false.
(a) 100 (b) 101
[2008, 2 marks]
(c) 102 (d) 110
(a) the instruction following the conditional branch
18. Assume that the memory is byte addressable and the word instruction in memory is executed
size is 32 bit. If an interrupt occurs during the execution of (b) the first instruction in the fall through path is executed
the instruction INC R3, what return address will be pushed (c) the first instruction in the taken path is executed
on to the stack? [2007, 2 marks] (d) the branch taken longer to execute than any other
(a) 1005 (b) 1020 instruction
(c) 1024 (d) 1040 24. The following code is to run on a pipelined processor with
19. Consider a pipelined processor with the following four stages one branch delay slot: [2008, 2 marks]
IF : Instruction Fetch l1: ADD R2 < R7 + R8
ID : Instruction Decode and Operand Fetch l2: SUB R4 ¬ R5 – R6
EX : Execute l3: ADD R1 ¬ R2 + R3
WB : Write Black l4: STORE Memory [R4] ¬ R1
The IF, ID and WB stages take 1 clock cycle each to complete BRANCH to Label if R1 = 0
the operation. Which of the instructions I1, I2, I3 or I4 can legitimately
· The number of clock cycle for the EX stage depends occupy the delay slot without any other program
on the instruction. the ADD and SUB instructions need 1 modification?
clock cycle and the MUL instruction needs 3 clock cycles (a) I1 (b) I2
in the EX stage. Operand forwarding is used in the pipelined (c) I3 (d) I4
processor. What is the number of clock cycles taken to Common Data for Questions 25, 26 and 27 :
complete the following sequence of instructions: Consider a machine with a 2-way set associative data cache of
size 64 kbyte and block size 16 byte. The cache is managed using
[2007, 2 marks]
32 bit virtual addresses and the page size is 4 kbyte. A program to
ADD R2, R1, R0 R2 ¬ R1 + R0 be run on this machine begins as follows.
MUL R4, R3, R2 R4 ¬ R3 * R2 double ARR [1024] [1024]
SUB R6, R5, R4 R6 ¬ R5 – R4 int i, j;
(a) 7 (b) 6 /* Initialize array ARR to 0.0 */
(c) 10 (d) 14 for (i = 0; i < 1024; i ++)
for (j = 0; j < 1024; j ++)
20. A CPU has 24-bit instructions. A program starts at address
ARR [i] [j] = 0.0;
300 (in decimal). Which one of the following is a legal The size of double is 8 byte. Array ARR is located in memory
program counter (all values in decimal)? [2007, 1 mark] starting at the beginning of virtual page 0 × FF000 and stored in
(a) 400 (b) 500 row major order. The cache is initially empty and no pre-fetching
(c) 600 (d) 700 is done. The only data memory references made by the program
21. Consider a disk pack with 16 surfaces, 128 tracks per surface are those to array ARR.
and 256 sectors per track. 512 byte of data are stored in a bit 25. The total size of the tags in the cache directory is
[2008, 2 marks]
serial manner in a second. The capacity of the disk pack and
(a) 32 kbit (b) 34 kbit
the number of bits required to specify a particular section in
(c) 64 kbit (d) 68 kbit
the disk are respectively [2007, 1 mark] 26. Which of the following array elements has the same cache
(a) 256 Mbyte, 19 bit (b) 256 Mbyte, 28 bit index as ARR [0] [0] ? [2008, 2 marks]
(c) 512 Mbyte, 20 bit (b) 64 Gbyte, 28 bit (a) ARR [0] [4] (b) ARR [4] [0]
22. Consider a 4-way set associate cache consisting of 128 lines (c) ARR [0] [5] (d) ARR [5] [0]
with a line size of 64 words. The CPU generates a 20-bit 27. The cache hit ratio for this initialization loop is
address of word in main memory. The number of bits in the [2008, 2 marks]
(a) 0% (b) 25%
TAG, LINE and WORD fields are respectively.
(c) 50% (d) 75%
[2007, 1 mark]
(a) 9, 6, 5 (b) 7, 7, 6
(c) 7, 5, 8 (d) 9, 5, 6
EBD_7203
S3-92 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
28. Which of the following must be true for the REF (Return Which one of the following memory blocks will not be in
From Exception) [2008, 2 marks] cache if LRU replacement policy is used? [2010, 2 marks]
1. It must be a TRAP instruction. (a) 3 (b) 8
2. It must be a privileged instruction. (c) 129 (d) 216
3. An exception cannot be allowed to occur during 36. Consider a 4 stage pipeline processor. The number of cycles
execution of an REE instruction. needed by the four instructions I1, I2, I3, I4 in stages S1, S2,
(a) 1 only (b) 2 only S3, S4 is shown below.
(c) 1 and 2 (d) 1, 2 and 3
29. Which of the following is/are true of the auto-increment S1 S2 S3 S4
addressing mode? [2008, 2 marks] I1 2 1 1 1
1. It is used in creating self-relocating code.
I2 1 3 2 2
2. If it is included in an Instruction Set Architecture, then
an additional ALU is required for effective address I3 2 1 1 3
calculation. I4 1 2 2 2
3. The amount of increment depends on the size of the
data item accessed. What is the number of cycles needed to execute the following
(a) 1 only (b) 2 only loop? [2010, 2 marks]
(c) 3 only (d) 2 and 3 For (i = 1 to 2) {I1; I2; I3; I4;}
30. For a magnetic disk with concentric circular tracks, the seek (a) 16 (b) 23
latency is not linearly proportional to the seek distance due (c) 28 (d) 30
to [2008, 1 mark] Statements for Linked Answer Questions 37 and 38 :
(a) non-uniform distribution of requests The computer system has an L1 L2 cache, an L2 cache and a main
(b) arm starting and stopping inertia memory unit connected as shown below. The block size in L1
(c) higher capacity of tracks on the periphery of the platter cache is 4 words. The block size in L2 cache is 16 words. The
(d) use of unfair arm scheduling policies memory access times are 2 ns, 20 ns and 200 ns, for L1 cache, L2
31. A CPU generally handles an interrupt by executing an
cache and main memory unit respectively.
interrupt service routine [2009, 1 mark]
(a) as soon as an interrupt as raised
(b) by checking the interrupt register at the end of fetch Data bus Data bus
L1 L2 Main
cycle
(c) by checking the interrupt register after finishing the Cache Cache memory
execution of the current instruction 4 words 4 words
(d) by checking the interrupt register at fixed time intervals.
32. How many 32 k × 1 RAM chips are needed to provide a 37. When there is a miss in L1 cache and a hit in L2 cache, a
memory capacity of 256 kbyte? [2009, 1 mark] block is transferred from L2 cache to L1 cache. What is the
(a) 8 (b) 32 time taken for this transfer? [2010, 2 marks]
(c) 64 (d) 128 (a) 2 ns (b) 20 ns
Common Data for Questions 33 and 34 : (c) 22 ns (d) 88 ns
A hard disk has 63 sectors per track, 10 platters each with 2
38. When there is a miss in both L1 cache and L2 cache, first a
recording surfaces and 1000 cylinders. The address of a sector is
given as a triple (c, h, s), where c is the cylinder number, h is the block is transferred from main memory to L2 cache, and then
surface number and s is the sector number. Thus, the 0th sector is a block is transferred from L2 cache to L1 cache. What is the
total time taken for these transfer? [2010, 2 marks]
addressed as 0, 0, 0 , the 1st sector as 0, 0,1 , and so on.
(a) 222 ns (b) 888 ns
33. The address < 400, 16, 29 > corresponds to sector number (c) 902 ns (d) 968 ns
[2010, 2 marks]
39. A 5-stage pipelined processor has Instruction Fetch (IF),
(a) 505035 (b) 505036
(c) 505037 (d) 505038 Instruction Decode (ID), Operand Fetch (OF), Perform
34. The address of the 1038th sector is [2010, 2 marks] Operation (PO) and Write Operand (WO) stages. The IF,
(a) < 0, 15, 31> (b) < 0, 16, 30> ID, OF and WO stages take 1 clock cycle each for any
(c) < 0, 16, 31> (d) < 0, 17, 31> instruction. The PO stage takes 1 clock cycle for ADD and
35. Consider a 4-way set associative cache (initially empty) with SUB instructions, 3 clock cycles for MUL instruction, and 6
total 16 cache blocks. The main memory consists of 256 clock cycles for DIV instruction respectively. Operand
blocks and the request for memory block is in the following forwarding is used in the pipeline. What is the number of
order: clock cycles needed to execute the following sequence of
0, 255, 1, 4, 3, 8, 133, 159, 216, 129, 63, 8, 48, 32, 73, 92, 155 the instructions? [2010, 2 marks]
COMPUTER ORGANIZATION AND ARCHITECTURE S3-93
Instruction Meaning of instruction 43. Consider an instruction pipeline with four stages (S1, S2, S3
I0: MUL R2, R0,R1 R2 ® R0 * R1 and S4) each with combinational circuit only. The pipeline
registers are required between each stage and at the end of
I1: DIV R5, R3, R4 R5 ® R3 / R4
the last stage. Delays for the stages and for the pipeline
I2: ADD R2, R5, R2 R2 ® R5 + R2 registers are as given in the figure [2011, 2 marks]
I3: SUB R5, R2, R6 R5 ® R2 – R6
(a) 13 (b) 15
State Pipeline State Pipeline State
(c) 17 (d) 19 S1 register S2 register S3
40. A main memory unit with a capacity of 4 megabyte is built Þ delay Þ Þ delay Þ
delay delay delay
using 1 M × 1 bit DRAM chips. Each DRAM chip has 1 5ns 1 ns 6ns 1 ns 11ns
rows of cells with 1 k cells in each row. The time taken for a
single refresh operation is 100 ns. The time required to
perform one refresh operation on all the cells in the memory
unit is [2010, 1 mark] Pipeline State Pipeline
(a) 100 ns (b) 100 * 2 ns10
/ delay Þ S 4 Þ register
(c) 100 * 220 ns (d) 3200 * 220 ns 1 ns delay delay
8ns 1 ns
41. On a non-pipelined sequential processor, a program segment,
which is a part of the interrupt service routine, is give to
transfer 500 byte from an I/O device to memory What is the approximate speed up of the pipeline in steady
Initialize the address register state under ideal conditions when compared to the
Initialize the count to 500 corresponding non-pipeline implementation?
LOOP: Load a byte from device (a) 4.0 (b) 2.5
Store in memory at address given by address register (c) 1.1 (d) 3.0
Increment the address register 44. A computer handles several interrupt sources of which of
Decrement the count the following are relevant? [2012, 1 mark]
If count! = 0 goto LOOP Interrupt from CPU temperature sensor
Assume that each statement in this program is equivalent Interrupt from Mouse
to a machine instruction which takes one clock cycle to Interrupt from Keyboard
executive if it is a non-load/store instruction. The load-store Interrupt from Hard disk
instructions take two clock cycles to execute. The designer (a) Interrupt from Hard disk
of the system also has an alternate approach of using the (b) Interrupt from Mouse
DMA controller to implement the same transfer. The DMA (c) Interrupt from Keyboard
controller required 20 clock cycles for initiallization and other (d) Interrupt from CPU temperature sensor
overheads. Each DMA transfer cycle takes two clock cycles 45. Consider a hypothetical processor with an instruction of
to transfer one byte of data from the device to the memory. type LW (R1), 20 (R2). which during execution reads a 32-bit
What is the approximate speed up when the DMA controller word from memory and stores it in a 32-bit register R1. The
based design is used in place of the interrupt driven program effective address of the memory location is obtained by the
based input-output? [2011, 2 marks] addition of constant 20 and the contents of register R2.
(a) 3.4 (b) 3.5 Which of the following best reflects the addressing mode
(c) 3.3 (d) None of these implemented by this instrument for the operand in memory?
42. An 8 kbyte direct mapped write-back cached is organized as (a) Immediate addressing [2012, 1 mark]
multiple blocks, each of size 32 byte. The processor (b) Register addressing
generates 32-bit addresses. The cache controller maintains (c) Register indirect scalled addressing
the tag information for each cache block comprising of the (d) Base indexed addressing
following– 46. Let the page fault service time be 10 Ms in a computer with
1 Valid bit average memory access time being 20 ns. If one page fault is
1 Modified bit generated for every 106 memory accesses, what is the
As many bits as the minimum needed to identify the memory effective access time for the memory? [2012, 1 mark]
block mapped in the cache. (a) 21 ns (b) 30 ns
What is the total size of memory needed at the cache (c) 23 ns (d) 35 ns
controller to store metadata (tags) for the cache? 47. The amount of ROM needed to implement a 4 bit multiplier
[2011, 2 marks] is [2012, 1 mark]
(a) 4864 bit (b) 6144 bit (a) 64 bit (b) 128 bit
(c) 6656 bit (d) 5376 bit (c) 1 k bit (d) 2 k bit
EBD_7203
S3-94 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
48. Register renaming is done in pipelined processors each stage and the delay of each buffer is 1 ns. A
[2012, 1 mark] program consisting of 12 instructions I1, I2, I3, ..., I12 is
(a) as an alternative to register allocation at comptile time executed in this pipelined processor. Instruction I4 is the
(b) for efficient access to function parameters and local only branch instruction and its branch target is I9. If the
variables branch is taken during the execution of this program, the
(c) to handle certain kinds of hazards time (in ns) needed to complete the program is
(d) as part of address translation [2013, 2 Marks]
(a) 132 (b) 165
49. In a k-way set associative cache, the cache is divided (c) 176 (d) 328
into v sets, each of which consists of k lines. The lines Common Data for Questions 54 and 55:
of a set are placed in sequence one after another. The following code segment is executed on a processor which
The lines in set s are sequenced before the lines in set allows only register operands in its instructions. Each
(s + 1). The main memory blocks are numbered 0 instruction can have atmost two source operands and one
onwards. The main memory block numbered j must be destination operand. Assume that all variables are dead after
mapped to any one of the cache lines from this code segment. [2013, 2 Marks]
[2013, 1 Mark] c = a + b;
(a) (j mod v) * k to (j mod v) * k + (k – 1) d = c * a;
(b) (j mod v) to (j mod v) + (k – 1) e = c + a;
(c) (j mod k) to (j mod k) + (v – 1) x = c * c;
(d) (j mod k) * v to (j mod k) * v + (v – 1) if (x > a) {
50. Consider the following sequence of micro-operations. y = a * a;
MBR ¬ PC }
MAR ¬ X else {
PC ¬ Y d = d * d;
Memory ¬ MBR e = e * e;
Which one of the following is a possible operation }
performed by this sequence? [2013, 2 Marks] 54. Suppose the instruction set architecture of the processor
has only two registers. The only allowed compiler
(a) Instruction fetch
optimization is code motion, which moves statements
(b) Operand fetch
from one place to another while preserving correctness.
(c) Conditional branch What is the minimum number of spills to memory in the
(d) Initiation of interrupt service compiled code? [2013, 2 Marks]
51. Consider a hard disk with 16 recording surfaces (0-15) (a) 0 (b) 1
having 16384 cylinders (0-16383) and each cylinder (c) 2 (d) 3
contains 64 sectors (0-63). Data storage capacity in each 55. What is the minimum number of registers needed in the
sector is 512 bytes. Data are organised cylinder-wise and instruction set architecture of the processor to compile
the addressing format is < cylinder number, surface this code segment without any spill to memory? Do not
number, sector number >. A file of size 42797 KB is stored apply any optimization other than optimizing register
in the disk and the starting disk location of the file is allocation. [2013, 2 Marks]
< 1200, 9, 40 >. What is the cylinder number of the last (a) 3 (b) 4
sector of the file, if it is stored in a contiguous manner? (c) 5 (d) 6
[2013, 2 Marks]
Statement for Linked Answer Questions 56 and 57:
(a) 1281 (b) 1282
A computer uses 46-bit virtual address, 32-bit physical address
(c) 1283 (d) 1284
and a three-level paged page table organisation. The page
52. A RAM chip has a capacity of 1024 words of 8 bits each table base register stores the base address of the first-level
(1K × 8). The number of 2 × 4 decoders with enable line table (T1), which occupies exactly one page. Each entry of T1
needed to construct a 16K × 16 RAM from 1K × 8 stores the base address of a page of the second-level table
RAM is [2013, 2 Marks] (T2). Each entry of T2 stores the base address of a page of the
(a) 4 (b) 5 third-level table (T3). Each entry of T3 stores a page table entry
(c) 6 (d) 7 (PTE). The PTE is 32 bits in size. The processor used in the
53. Consider an instruction pipeline with five stages without computer has a 1 MB 16-way set associative virtually indexed
any branch prediction: Fetch Instruction (FI), Decode physically tagged cache. The cache block size is 64 bytes.
Instruction (DI), Fetch Operand (FO), Execute Instruction
(EI) and Write Operand (WO). The stage delays for FI, 56. What is the size of a page in KB in this computer?
[2013, 2 Marks]
DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns,
(a) 2 (b) 4
respectively. There are intermediate storage buffers after
(c) 8 (d) 16
COMPUTER ORGANIZATION AND ARCHITECTURE S3-95
57. What is the minimum number of page colours needed to 65. Consider a main memory system that consists of 8 memory
guarantee that no two synonyms map to different sets in modules attached to the system bus, which is one word
the processor cache of this computer? [2013, 2 Marks] wide. When a write request is made, the bus is occupied for
(a) 2 (b) 4 100 nanoseconds (ns) by the data, address, and control
(c) 8 (d) 16 signals. During the same 100 ns, and for 500 ns thereafter,
58. A machine has a 32-bit architecture, with 1-word long the addressed memory module executes one cycle accepting
instructions. It has 64 registers, each of which is 32 bits and storing the data. The (internal) operation of different
long. It needs to support 45 instructions, which have an memory modules may overlap in time, but only one request
immediate operand in addition to two register operands. can be on the bus at any time. The maximum number of
Assuming that the immediate operand is an unsigned integer,
stores (of one word each) that can be initiated in 1 millisecond
the maximum value of the immediate operand is ______ .
is ____________ [2014, Set-2, 2 Marks]
[2014, Set-1, 1 Mark]
59. Consider a 6-stage instruction pipeline, where all stages are 66. Consider the following processors (ns stands for
perfectly balanced. Assume that there is no cycle-time nanoseconds). Assume that the pipeline registers have zero
overhead of pipelining. When an application is executing latency.
on this 6-stage pipeline, the speedup achieved with respect P1: Four-stage pipeline with stage latencies 1 ns, 2 ns, 2 ns,
to non-pipelined execution if 25% of the instructions incur 2 1 ns.
pipeline stall cycles is ______________________. P2: Four-stage pipeline with stage latencies 1 ns, 1.5 ns, 1.5
[2014, Set-1, 2 Marks] ns, 1.5 ns.
60. An access sequence of cache block addresses is of length P3: Five-stage pipeline with stage latencies 0.5 ns, 1 ns, 1
N and contains n unique block addresses. The number of ns, 0.6 ns, 1 ns.
unique block addresses between two consecutive accesses P4: Five-stage pipeline with stage latencies 0.5 ns, 0.5 ns, 1
to the same block address is bounded above by k. What is ns, 1 ns, 1.1 ns.
the miss ratio if the access sequence is passed through a Which processor has the highest peak clock frequency?
cache of associativity A ³ k exercising least-recently-used [2014, Set-3, 1 Mark]
replacement policy? [2014, Set-1, 2 Marks] (a) P1 (b) P2
(a) n/N (b) 1/N (c) P3 (d) P4
(c) 1/A (d) k/n 67. An instruction pipeline has five stages, namely, instruction
61. A 4-way set-associative cache memory unit with a capacity fetch (IF), instruction decode and register fetch (ID/RF),
of 16 KB is built using a block size of 8 words. The word instruction execution (EX), memory access (MEM), and
length is 32 bits. The size of the physical address space is register writeback (WB) with stage latencies 1 ns, 2.2 ns, 2
4 GB. The number of bits for the TAG field is _____.
ns, 1 ns, and 0.75 ns, respectively (ns stands for
[2014, Set-2, 1 Mark]
nanoseconds). To gain in terms of frequency, the designers
62. In designing a computer’s cache system, the cache block
(or cache line) size is an important parameter. Which one of have decided to split the ID/RF stage into three stages (ID,
the following statements is correct in this context? RF1, RF2) each of latency 2.2/3 ns. Also, the EX stage is
[2014, Set-2, 2 Marks] split into two stages (EX1, EX2) each of latency 1 ns. The
(a) A smaller block size implies better spatial locality new design has a total of eight pipeline stages. A program
(b) A smaller block size implies a smaller cache tag and has 20% branch instructions which execute in the EX stage
hence lower cache tag overhead and produce the next instruction pointer at the end of the
(c) A smaller block size implies a larger cache tag and EX stage in the old design and at the end of the EX2 stage
hence lower cache hit time in the new design. The IF stage stalls after fetching a branch
(d) A smaller block size incurs a lower cache miss penalty instruction until the next instruction pointer is computed.
63. If the associativity of a processor cache is doubled while All instructions other than the branch instruction have an
keeping the capacity and block size unchanged, which one average CPI of one in both the designs. The execution times
of the following is guaranteed to be NOT affected? of this program on the old and the new design are P and Q
[2014, Set-2, 2 Marks] nanoseconds, respectively. The value of P/Q is
(a) Width of tag comparator __________. [2014, Set-3, 2 Marks]
(b) Width of set index decoder
68. The memory access time is 1 nanosecond for a read operation
(c) Width of way selection multiplexor
with a hit in cache, 5 nanoseconds for a read operation with
(d) Width of processor to main memory data bus
64. The value of a float type variable is represented using the a miss in cache, 2 nanoseconds for a write operation with a
single-precision 32-bit floating point format of IEEE-754 hit in cache and 10 nanoseconds for a write operation with
standard that uses 1 bit for sign, 8 bits for biased exponent a miss in cache. Execution of a sequence of instructions
and 23 bits for mantissa. A float type variable X is assigned involves 100 instruction fetch operations, 60 memory
the decimal value of –14.25. The representation of X in operand read operations and 40 memory operand write
hexadecimal notation is [2014, Set-2, 2 Marks] operations. The cache hit-ratio is 0.9. The average memory
(a) C1640000H (b) 416C0000H access time (in nanoseconds) in executing the sequence of
(c) 41640000H (d) C16C0000H instructions is __________. [2014, Set-3, 2 Marks]
EBD_7203
S3-96 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

1. The most appropriate matching for the following pairs : Codes


X : Indirect addressing 1. Loop A B C D
Y : Intermediate addressing 2. Pointers (a) 1 2 3 4
Z : Auto decrement addressing 3. constants (b) 4 2 3 1
(a) X-3, Y-2, Z-1 (b) X-1, Y-3, Z-2 (c) 3 2 1 4
(c) X-2, Y-3, Z-1 (d) X-3, Y-1, Z-2 (d) 2 3 4 1
2. Addressing mode facilitate access to an operand whose 9. Stack adressing is same as
location is defined in relative to the beginning of the data (a) relative addressing (b) zero addressing
structure in which it appears
(c) virtual addressing (d) indirect addressing
(a) absolute (b) immediate
10. Match the following :
(c) index (d) indirect
3. Which of the following addressing modes are suitable for a. Immediate address 1. local variables
program relocation time? mode
1. Absolute addressing 2. Based addressing b. Direct address mode 2. Relocatable program
3. Relative addressing 4. Indirect addressing c. Indirect, address 3. Pointers
(a) 1 and 4 (b) 1 and 2 mode
(c) 1, 2 and 4 (d) 2 and 3 d. Index address mode 4. Locality of references
4. The following program starts at location 0100 H e. Base address mode 5. Arrays
LX1 SP, 00FF f. Relative address 6. Constant operands
LXI H, 0701 mode
A, 20H (a) a-6, b-1, c-3, d-5, e-2, f-4
The content of accumulator when the program counter (b) a-5, b-4, c-6, d-3, e-1, f-2
reaches 0109 H is (c) a-3, b-5, c-2, d-4, e-1, f-6
(a) 20 H (b) 02 H (d) a-6, b-5, c-2, d-3, e-1, f-4
(c) 00 H (d) FF H 11. Programming that actually controls the path of the data
5. Which of the following instructions is an example of within the computer is called
direct addressing mode? (a) micro programming
(a) MOV A, B (b) 2050 (b) system programming
(c) 05 (d) HLT
(c) assemble language
6. If a cache access requires one clock cycle and handling
(d) machine language programming
cache misses stalls the processor for an additional five
cycles, which of the following cache hit rates comes 12. The control signal indicates
closest to achieving an average memory access of 2 (a) whether a data is read into or written out to memory
cycles? (b) whether CPU is accessing memory of input/output
(a) 75% (b) 80% device
(c) 83% (d) 86% (c) whether input/output device or memory is ready to
7. An instruction is stored at location 300 with its address transfer data
field at location 301 the address field has value 400. A (d) All of the above
processor register R1 contains the number 200. Evaluate 13. LRU is an effective cache replacement strategy primarily
the effective address, matching the following addressing because programs
modes to their respective address. (a) exhibit locality of reference
a. Direct 1. 702 (b) usually have small working sets
b. Immediate 2. 200 (c) read data much more frequently than write data
c. Relative 3. 400 (d) None of these
d. Register indirect 4. 600 14. The CPU of a computer takes instruction from the memory
e. Index (R1 is indirect) 5. 300 and executes them. This process is called
(a) a-3, b-5, c-1, d-2, e-4 (b) a-3, b-4, c-2, d-1, e-5 (a) load cycle (b) time sequencing
(c) a-3, b-3, c-2, d-1, e-4 (d) a-4, b-3, c-1, d-5, e-2 (c) fetch-execute cycle (d) clock cycle
8. Match the following in context of an 8085 µP
15. An interrupt can be temporarily ignored by the counter is
A. DAA 1. Program control instruction
called
B. LXI 2. Data movement instruction
C. RST 3. Interrupt instruction (a) vectored interrupt (b) non-maskable interrupt
D. JMP 4. Instruction (c) maskable interrupt (d) low priority interrupt
COMPUTER ORGANIZATION AND ARCHITECTURE S3-97
16. Match List I with List II and select the correct answer 25. Microprogramming is a technique for
from the codes given below the lists. (a) writing small programs effectively
List I List II (b) programming output/input routines
A A shift register 1. for code conversion (c) programming the microprocessor
can be used (d) programming the control steps of a computer
B. A multiplexer 2. to generate memory chip 26. The device which is used to connect a peripheral to bus
can be used select is called
C. A decoder 3. for parallel to serial (a) control register (b) communication protocol
can be used conversion
(c) interface (d) None of the above
4. as many to one switch
27. Comparing the time T1 taken for a single instruction on
5. for analog to digital
a pipelilned CPU with time T2 taken on a non-pipelined
conversion
but identical CPU, we can say that
Codes
A B C A B C (a) T1 £ T2
(a) 3 1 2 (b) 4 3 2 (b) T1 ³ T2
(c) 3 4 2 (d) 2 3 4 (c) T1 < T2
17. When a subroutine is called, then address of the (d) T1 is T2 plus line taken for one instruction fetch cycle
instruction following the CA1 instruction is stored in the 28. Branch instructions are handled in pipeline usinig
(a) stack pointer (b) program counter (a) prefetch target instruction strategy
(c) accumulator (d) stack (b) loop Greffer strategy
18. The sequence of events that happens during a typical (c) Both (a) and (b)
fetch operation is (d) None of the above
(a) PC ® MAR ® Memory ® MDR ® 1R 29. What is the speed up factor of n-stage pipelined
(b) PC ® Memory ® MDR ® 1R (a) (n + 1) (b) (n – 1)
(c) PC ® Memory ® 1R (c) 2n (d) n
(d) PC ® MAR ® Memory ® 1R 30. A computer system has a 4k word cache organized in
19. Any instruction should have atleast blocked set associative manner with 4 blocks per set, 64
(a) 2 operands (b) 1 operands words per block. The numbers of bits in the SET and
(c) 3 operands (d) None of these WORD fields of the main memory address format are
20. In ............ the total address space exceeds the size of (a) 15, 40 (b) 7, 2
physical memory.
(c) 6, 4 (d) 4, 6
1. paging
31. What is the minimum size of ROM required to store the
2. segmentation
complete truth table of an 8-bit × 8-bit multiplier?
(a) 1, 2 (b) 1
(a) 32k × 16 bit (b) 64k × 16 bit
(c) 2 (d) None of these
(c) 16k × 32 bit (d) 64k × 32 bit
21. The ability temporarily halt the CPU and use this time to
32. A hard disk has 63 sectors per stract, 10 platters each with
send information on buses is called
2 recording surface and 1000 cylinders. The address of a
(a) direct memory access (b) vectoring the interrupt
sector is given as a triple <c, h, c>, where c is the cylinder
(c) palling (d) cycle stealing
number, h is the surface number and s is the sector
22. Microprogram is
number. Thus, the 0th sector is addressed as <0, 0, 0>, the
(a) the name of source program in micro computers
1st sector as < 0, 0, 1> and so on
(b) the set of instructions indicating the primitive
(a) 50 50 35 (b) 50 50 36
operations in a system
(c) 50 50 37 (d) 50 50 38
(c) primitive form of macros used in assembly language
programming 33. Consider the following register-transfer language
(d) program of very small size R 3 ¬¾¾ R 3 + M(R1 + R 2 )
23. Which of the following units is responsible for where R1, R2 are the CPU registers and M is a memory
coordinating various operations using timing signals? location in primary memory. Which addressing mode is
(a) ALU (b) control unit suitable for above register-transfer language?
(c) Memory unit (d) I/O unit (a) immediate (b) indexed
24. The register which contains the data to be written into or (c) direct (d) displacement
read out of the addressed location is called 34. In a 16-bit instruction code format 3 bit operation code,
(a) memory addressed register 12 bit address and 1 bit is assigned for address mode
(b) memory data register designation. For indirect addressing, the mode bit is
(c) program counter (a) 0 (b) 1
(d) index register (c) pointer (d) off-set
EBD_7203
S3-98 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
35. What does CISC and RISC means? 44. Consider an (n + k) bit instruction with a k-bit opcode and
(a) common instruction set controller and rare instruction single n-bit address. Then this instruction allow _______
set controller operations and _______ addressable memory cells.
(b) complex instruction set controller and reduced (a) 2k, 2n+ k (b) 2n+ k, 2n+ k
k
(c) 2 , 2 n (d) 2n+ k, 2n+ 1
instruction set controller
(c) compiled instruction set source code and recompiled 45. Which of the following statements is false with regard to
instruction source code fully associative and direct mapped cache organizations?
(d) None of the above (a) Direct mapped caches do not need a cache block
36. The computer performs all mathematical and logical replacement policy, whereas fully associative caches
operations inside its do.
(a) memory unit (b) central processing unit (b) In a fully associative cache, the full address is stored
(c) output unit (d) visual display unit alongside the data block.
37. Match List-I with List-II and select the correct answer (c) A direct mapped cache is organized according to an
using the codes given below the lists : ‘index’, and the ‘tag’ part of the memory address is
List-1 List-II stored alongside the data block.
A. Regs[R4] ¬ Regs[R4] 1. immediate (d) Direct mapped caches may produce more misses if
+ Regs[R3] programs refer to memory words that occupy a single
B. Regs[R4] ¬ Regs[R4] + 3 2. register tag value.
C. Regs[R4] ¬ Regs[R4] 3. displacement 46. The register which holds the address of the location to or
+ Mem[Regs[R1]] from which data are to be transferred is known as
Codes (a) index register
A B C (b) instruction register
(a) 3 2 1 (c) memory address register
(b) 2 1 3 (d) memory data register
(c) 1 2 3 47. If increasing the block size of a cache improves
performance it is primarily because programs
(d) 3 1 2
(a) exhibit locality of reference
38. Pipelining improves CPU performance due to
(b) usually have small working sets
(a) reduced memory access time
(c) read data much more frequently than write data
(b) increased clock speed
(d) None of these
(c) the introduction of parallelism
48. Consider the following program:
(d) additional funcional units
integer A[1000];
39. A 32-bit address bus allows access to a memory of for i = 1 to 1000
capacity for j = 1 to 1000
(a) 64 Mb (b) 6 Mb A[i] = A[i] + 1
(c) 1 Gb (d) 4 Gb When the above program is compiled with all compiler
40. The read/write line optimizations turned off and run on a processor with a 1K
(a) belongs to the data bus byte fully-associative write-back data cache with 4-word
(b) belongs to the control bus cache blocks, what is the approximate data cache miss
(c) belongs to the address bus rate? (Assume integers are one word long and a word is
(d) CPU bus 4 bytes.)
41. Which of the following lists memory types from highest (a) 0.0125% (b) 0.05%
lowest access speed? (c) 0.1% (d) 5%
(a) secondary storage, main memory, cache, registers 49. Match List-I with List-II using memory hierarchy from top
(b) registers, cache, secondary storage, main memory to down and select the correct answer using the codes
(c) registers, cache, main memory, secondary storage given below the lists.
(d) cache, registers, main memory, secondary storage List-I List-II
42. _______ improve system performance by temporarily A. Size 1. Increases
storing data during transfers between devices processes B. Cost/bit 2. Decreases
that operate at different speeds. C. Access time 3. No change
(a) cache (b) controllers D. Frequency of access
(c) buffers (d) registers Codes
43. Which of following registers processor used for fetch and A B C D
execute operations? (a) 1 1 2 2
1. Program counter 2. Instruction register (b) 2 1 2 1
3. Address register (c) 2 2 1 1
(a) 1 and 3 (b) 1 and 2 (d) 1 2 1 2
(c) 2 and 3 (d) 1, 2 and 3
COMPUTER ORGANIZATION AND ARCHITECTURE S3-99
50. A computer system has 4K-word cache organized in a 3. It syas that the bytes of a word be interleaved on
block-set-associative manner, with 4 blocks per set, 64 several physical memory modules for better
words per block. Memory is word addressable. The performance.
number of bits in the SET and WORD fields of the main Which of them is/are true?
memory address format is (a) Only 1 is true (b) Only 2 is true
(c) Only 3 is true (d) Only 1 nad 2 are true
(a) 15, 4 (b) 6, 4
56. The sequence of events that happen during a typical
(c) 7, 6 (d) 4, 6 fetch operation is
51. Which of the following units can be used to measure the (a) PC ® MAR ® Memory ® MDR ® IR
speed of a computer (b) PC ® Memory ® MDR ® IR
(a) SYPS (b) MIPS (c) PC ® Memory ® IR
(c) BAUD (d) None of these (d) PC ® MAR ® Memory ® IR
52. Consider the following I/O instruction format for IBM 370 57. A cache has a hit rate of 95 percent, 128 byte lines and
I/O channel a cache hit latency of 5ns. The main memory takes 100 ns
Operation Code Channel Address Device Address to return the first word (32 bits) of a line, and 10 ns to
return each subsequent word.
Then operation code specifies
What is Tmins for this cache ? (Assume that the cache
1. test I/O
2. test channel waits until the line has been fetched into the cache and
3. store channel identification then reexecutes the memory operation, resulting in a
4. halt device cache hit. Neglect the time required to write the lines into
(a) Only 1 and 4 (b) Only 2 and 3 the cache once has been fetched from the main memory.
(c) 1, 2, 3 and 4 (d) 1, 3 and 4 Also assume that the cache takes the same amount of
53. Match List-I with List-II and select the correct answer time to detect that a mass has occured as to handle a
using the codes given below the lists : cache hit.)
List-I List-II (a) 410 ns (b) 420 ns
A. 0-address instruction 1. T = TOP (T – 1) (c) 240 ns (d) 540 ns
B. 1-address instruction 2. Y = Y + X 58. Both’s coding in 8-bits for the decimal number –57 is
C. 2-address instruction 3. Y = A – B _______.
D. 3-address instruction 4. ACC = ACC – X (a) 0 – 100 + 1000 (b) 0 – 100 + 100 – 1
Codes (c) 0 – 1 + 100 – 10 + 1 (d) 00 – 10 + 100 – 1
A B C D 59. Daisy Chained and independent Request bus arbitration
(a) 1 2 3 4 requires _______ respectively. (Where N stands for
(b) 3 2 4 1 number of Bus Master Devices in the configuration).
(c) 2 3 1 4
(a) 2 and 7 signal lines
(d) 1 4 2 3
(b) 3 and 2N signal lines
54. Find the average access time experienced by the CPU in
a system with two levels of caches. (c) 2N and 2N signal lines
If h1 : is the hit rate in the primary cache (d) 3 and 2N signal lines
h2 : is the hit rate in the secondary cache
c1 : is the time to access information in the primary 60. In which addressing mode, the effective address of the
cache operand in gererated by adding a constant value to the
c2 : is the time to access information in the secondary contents of a register?
cache (a) absolute mode (b) indirect mode
M : is the time to access information in the main (c) immediate mode (d) index mode
memory 61. Match List-I with List-II and select the correct answer
(a) h1c1 + h2c2 + (1 – h1h2)M using the codes given below the lists.
(b) h1c1 – h2c2 + (1 – h1h2)M List I List II
(c) h1c1 + (1 – h2)h1c2 + (1 – h1)(1 – h2)M A. A[1] = B[1]; 1. indirect addressing
(d) h1c1 + (1 – h1)h2c2 + (1 – h1)(1 – h2)M B. while [*A++]; 2. indexed addressing
55. The following are three statements about the “locality of C. int temp = *X 3. Autoincrement
reference” principle used in memory system –
Codes
1. It says that it is more likely that an already accessed
A B C
memory location is accessed further, and it is more
likely that surrounding (adjacent) memory locations (a) 3 2 1
will also be accessed. (b) 1 3 2
2. It is an observation that equally widely used to (c) 2 3 1
implement virtual memory and cache memory systems. (d) 1 2 3
EBD_7203
S3-100 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
62. The memory locations 1000, 1001 and 1020 have data (c) A CPU register is used to hold a binary value temporarily
values 18, 1 and 16 respectively before the following for storage, for manipulation, and/or for simple
program is executed calculations.
MOVI Rs, 1; Move immediate (d) The control units are programmed and not hardwired.
LOAD Rd. 1000(Rs); Load from memory 67. The following are four statements about Reduced Instruction
ADD Rd, 1000; Add immediate Set Computer (RISC) architectures.
STORE (Rd), 20; Store immediate 1. The typical RISC machine instruction set is small, and
Which of the statements below is TRUE after the program is usually a subject of a CISC instruction set.
is executed ? 2. No arithmetic or logical instruction can refer to the
memory directly.
(a) memory location 1000 has value 20
3. A comparatively large number of user registers are
(b) memory location 1020 has value 20
available.
(c) memory location 1021 has value 20 4. Instructions can be easily decoded through hard-wired
(d) memory location 1001 has value 20 control units.
63. The microinstructions stored in the control memory of a 68. The performance of a pipelined processor suffers if
processor have a width of 26 bits. Each microinstruction ________.
is divided into three fields; a mono-operation field of 13 (a) the pipeline stages have different delays
bits, a next address field (X) and a MUX select field (Y).
(b) consecutive instructions are dependent on each other
There are 8 status bits in the inputs of the MUX.
(c) the pipeline stages share hardware resources
(d) all of the above
Load 69. Consider the following organization of main memory and
Control cache memory.
Address Register Main memory: 64K × 16
Increment Cache memory: 256 × 16
Memory is word-addressable and block size is of 8 words.
Control Determine the size of tag field if direct mapping is used for
Memory transforming data from main memory to cache memory.
MUX (a) 5 bits (b) 6 bits
Y 13
(c) 7 bits (d) 8 bits
Status Bits 8 Micro-operations
X 70. Match List-I with List-II and select the correct answer using
the codes given below the lists:
List - I List - II
How many bits are there in the X and Y fields, and what
A. Stack overflow 1. Software interrupt
is the size of the control memory in number of words?
(a) 10, 3, 1024 (b) 8, 5, 256 B. Supervisor call 2. Internet interrupt
(c) 5, 8, 2048 (d) 10, 3, 512 C. Invalid opcode 3. External interrupt
64. Microinstruction length is determined by __________ D. Timer 4. Mach ine check
1. The maximum number of simultaneous micro operations interrupt
that must be specified. A B C D
2. The way in which the control information is represented (a) 2 3 4 1
or encoded. (b) 2 1 4 3
3. The way in which the next microinstruction address is
(c) 3 1 2 4
specified.
(a) 1 and 2 (b) 2 and 3 (d) 3 1 4 2
(c) 1 and 3 (d) All of the above 71. Consider a CPU has 8 general-purpose registers R0, R1, ...,
65. Suppose a cache is 10 times faster than main memory and R7 and supports the following operation.
suppose that the cache can be used 70% of the time. How ADD Ra, Rb, Rc Add Ra to Rb and store the result to Rc.
much speed up do we gain by using the cache? MUL Ra, Rb, Rc Multiply Ra to Rb and store the result to Rc.
(a) 0.37 (b) 2.7 An operation normally takes one clock cycles, an operation
(c) 3.7 (d) 0.27 takes two clock cycles if it produces a result required by the
66. Following are some statements associated with immediately following operations. Consider the expression
microprocessors. Identify the false statement. XY + XYZ + YZ, where variables X, Y and Z are initially
(a) The control unit is the component of the CPU that located in the registers R0, R1 and R2. If contents these
implements the microprocessors instruction set. registers must not be modified, what is the minimum number
(b) The instruction received by the CPU is decoded by the of clock cycles required for an operation sequence that
arithmetic logic unit. computes the value of XY + XYZ + YZ?
COMPUTER ORGANIZATION AND ARCHITECTURE S3-101
(a) 4 (b) 5 of storage then the instruction sequence as a whole
(c) 6 (d) 7 requires a total of 40 bytes of storage.
72. In a two level memory hierarchy, the access time of the 2. At the end of execution, z contains the same value as
cache memory is 12 nanoseconds and the access time of the y.
main memory is 1.5 microseconds. The hit ratio is 0.98. What 3. At the end of execution, the stack is empty.
is the average access time of the two level memory system? (a) 1 only (b) 2 only
(a) 13.5 nsec (b) 42 nsec (c) 2 and 3 only (d) 1 and 3 only
(c) 7.56 nsec (d) 41.76 nsec 77. A CPU has an arithmetic unit that adds bytes and then sets
its V, C and Z flag bits as follows. The V-bit is set if arithmetic
73. The word length of a CPU is defined as
overflow occurs (in 2’s complement arithmetic). The C-bit is
(a) the maximum addressable memory size set if a carryout is generated from the most significant bit
(b) the width of a CPU register (integer or float point) during an operation. The Z-bit is set if the result is zero.
(c) the width of the adress bus What are the values of the V, C and Z flag bit after 8-bit byte
(d) the number of general purpose CPU registers 1100 1100 and 1000 1111 are added?
74. The following diagram shows, which addressing mode? V C Z
(a) 0 0 0
(b) 1 1 0
Lower Higher
Opcode Address (c) 1 1 1
Address
(d) 0 1 0
Memory 78. The following are the some of the sequences of operations
in instruction cycle, which one is correct sequence?
(a) : PC ® Address register
Operand Data from memory ® Data register
Data register ® IR
PC + 1 ® PC
(a) immediate addressing mode
(b) : Address register ® PC
(b) indirect addressing mode
Data register ® Data from memory
(c) extended addressing mode
Data register ® IR
(d) none of the above
PC + 1 ® PC
75. A certain computer system design has a single CPU, a two- (c) : Data from memory ® Data register
level cache, and supports memory mapped I/O for output- PC ® Address register
only controllers. Which of the following is true? Data register ® IR
(a) The design i impossible, since memory mapped I/O will PC + 1 ® PC
prevent cache coherence. (d) None of these
(b) In two-level caches, the L1 cache is generally built from 79. Match List-I with List-II and select the correct answer using
SRAM. the codes given below the lists:
(c) In two-level caches, the L1 cache is generally larger List-I List-II
than L2 cache. A. MOV X, R1 1. Three-address
(d) In two-level caches, the L2 cache generally has a lower instruction
latency than the L1 cahche. B. STORE X 2. Zero-address instruction
76. Consider the following sequence of instructions intended C. POPX 3. Three-address
for execution on a stack machine. Each arithmetic operation instruction
pops the second operand, then pops the first operand, 4. Two-address
operates on them, and then pushes the result back onto the instruction
stack A B C
push b (a) 4 3 2
push x (b) 3 2 1
add (c) 2 3 4
pop c (d) None of these
push c 80. Pipelined operation is interrupted whenever two operations
push y being attempted in parallel need same hardware component.
add Such a conflict can occur if ___________.
push c (a) The execution phase of an instruction requires access
sub to the main memory, which also contains the next
pop z instruction that should be fetched at the same time
Which of the following statements is/are true? (b) The prefetch phase of an instruction requires access
1. If push and pop instructions each require 5 bytes of to the main memory, which also contains the next
storage, and arithmetic operations each require 1 byte instruction that should be fetched at the same time.
EBD_7203
S3-102 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(c) The decode phase of an instruction requires access to 2. The Instruction Set Architecture (ISA) level defines
the main memory, which also contains the next the characteristics of the CPU.
instruction that should be fetched at the same time. 3. One of the functions of the operating system machine
(d) None of these level is to enfore a separation between the users tasks
81. Consider the unpipelined machine with 10 ns clock cycles. and the privileged tasks.
It uses four cycles for ALU operations and branches, Which of the following statement(s) is/are true about the
whereas five cycles for memory operations. Assume that multilevel machine view point?
the relative frequencies of there operations are 40%, 20%, (a) Only 1 is true (b) Only 1 and 3 are true
40% respectively. Suppose that due to clock skew and setup, (c) Only 3 is true (d) All are true
pipelining the machine adds 1 ns overhead to the clock. 88. In a general purpose computer system the CPU, the main
How much speed up in the instruction executed rate will we memory and the cache may be interconnected via one or
gain from a pipeline? more shared system bus(es). However, input/output devices
(a) 5 times (b) 8 times (eg. Hard disk, network interfaces) may only be connected
(c) 4 times (d) 4.5 times to the system bus through an I/O controller. The following
82. Consider the following situation and fill in the blanks: are four statements regarding the requirement for an I/O
The computer starts the tape moving by issuing a comman; controller.
the processor then monitors the status of the tape by means 1. The capacities of I/O devices are magnitude order
of a ___________. When the tape is in the correct position, larger than that of main memory and hence direct
the processor issues a __________. interfacing is impossible.
(a) Data input, status, data output command 2. The response times of I/O devices are magnitude order
(b) Data input, status control command slower than that of CPU and hence direct interfacing is
(c) Control, status, data output command impossible.
(d) Control, status, data input command 3. It is always better to off load the I/O processing to a
83. Asynchronous data transfer between two independent units secondary processor on the I/O controller board then
requires that control signals be transmitted between the to depend on the primary CPU for I/O processing.
communicating units to indicate the time at which data is 4. The variety of I/O devices in the market requires that a
being transmitted, way of achieving this __________. separate I/O controller exist for each device.
(a) Is by means of a strobe pulse from one of the unit What statement(s) best explain the requirement for an I/O
(b) Is by means of handshaking controller?
(c) Both (a) and (b) (a) Only 1 is true (b) Only 3 is true
(d) None of these
(c) Only 2 and 3 are true (d) Only 2, 3 and 4 are true
84. For interval arithmetic best rounding technique use is
89. A certain processor executes the following set of machine
__________ .
instructions sequentially.
(a) Rounding to plus and minus infinity
MOV R0 # 0
(b) Rounding to zero
(c) Rounding to nearest MOV R1, 100 (R0)
(d) None of these ADD R1, 200 (R0)
85. The percentage of times that a page number is found in the MOV 100 (R0), R1
associative register is called the hit ratio. Assuming that memory location 100 contains the value 35
Assume it takes 50 nanoseconds to search the associative (Hex), and the memory location 200 contains the value A4
registers and 100 nanoseconds to access main memory. (Hex), what could be said about the final result?
What is the percentage of slowdown in memory-access time (a) Memory location 100 contains value A4
if the hit ratio is 90%? (b) Memory location 100 contains value D4
(a) 24 (b) 40 (c) Memory location 100 contains value D9
(c) 45 (d) 60 (d) Memory location 200 contains value 35
86. An IOSA defines 2 different instruction formats. In the first 90. An 8-Bit DMA Device is operating is Cycle Stealing Mode
format, 6 bits are used for the opcode, among these opcode (Single Transfer Mode). Each DMA cycle is of 6 clock states
bit patterns, three are used as special patterns. When any and DMA clock is 2 MHz. Intermediate CPU machine cycle
of these three patterns appear in the opcode field, the takes 2 mS, determine the DMA Data Transfer Rate
instruction is encoded using the second format, and the (a) 100 Kbytes/sec (b) 200 Kbytes/sec
actual opcode is present in another 6-bit field. How many (c) 350 Kbytes/sec (d) None of the above
unique opcodes can this ISA support? 91. Determine the width of Micro-instruction having following
(a) 64 (b) 253 Control signal field, in a Vertical Micro-programmed Control
(c) 254 (d) 189 Unit
87. Consider the following three statements. 1. Next address field of 7 bits
1. A multilevel view of a computer system simplifies the 2. ALU function field selecting 1 out of 13 ALU function
design of a complex system by identifying specific 3. Register-in field selecting 1 out of 13 ALU function
functionalities for each level.
COMPUTER ORGANIZATION AND ARCHITECTURE S3-103
4. Register-out field selecting 1 out of 8 registers device under interrupt mode over operating it under program
5. Shifter field selecting no shift, right shift or left shift controlled mode?
6. Auxiliary control field of 4 bits (a) 15 (b) 25
(a) 22 (b) 23 (c) 35 (d) 45
(c) 24 (d) 25
92. Which one of the following is true for a CPU having a single 97. Consider a disk drive with the following specifications: 16
interrupt request line and a single interrupt grant line? surfaces, 512 tracks/surface, 512 sectors/track, 1 KB/sector,
(a) Neither vectored interrupt nor multiple interrupting rotation speed 3000 rpm. The disk operated in cycle stealing
devices are possible mode whereby whenever one byte word is ready it is sent to
(b) Vectored interrupts are not possible but multiple the memory; similarly, for writing, the disk interface reads a
interrupting devices are possible 4 byte word from the memory in each DMAcycle. Memory
(c) Vectored interrupts and multiple interrupting devices cycle time is 40 nsec. The maximum percentage of time that
are both possible. the CPU gets blocked during DMA operation is
(d) Vectored interrupts is possible but multiple interrupting
(a) 10 (b) 25
devices are not possible.
93. When multiplicand Y is multiplied by multiplier X = xn – 1 (c) 40 (d) 50
xn – 2... x0 using bit-pair recording in Booth’s algorithm, 98. We have two designs D1 and D2 for a synchronous pipeline
partial products are generated according to the following processor. D1 has 5 pipeline stages with execution times of
table. 3 nsec, 2 nsec, 4 nsec, 2 nsec and 3 nsec while the design D2
has 8 pipeline stages each with 2 nsec execution time. How
Row xi + 1 xi xi – 1 Partial product much time can be saved using design D2 over design D1 for
1 0 0 0 0 executing 100 instructions?
2 0 0 1 Y (a) 214 nsec (b) 202 nsec
3 0 1 0 Y (c) 86 nsec (d) 200 nsec
4 0 1 1 2Y 99. Which of the following is true in case of lockup free cache?
5 1 0 0 ? 1. A cache structure allows a CPU to access a cache while
6 1 0 1 –Y a hit is being serviced.
7 1 1 0 –Y 2. A cache structure allows a CPU to access a cache while
8 1 1 1 ? a miss is being serviced.
3. A cache that can support multiple outstanding misses.
The partial products for rows 5 and 8 are 4. A cache that can support multiple outstanding hits.
(a) 2Y and Y (b) – 2Y and 2Y
(c) – 2Y and 0 (d) 0 and Y (a) Only 1 and 4 (b) Only 2 and 3
94. A cache contains n blocks and main memory contains m (c) Only 1 (d) Only 2
blocks. If k way set associative maping is used than what 100. Suppose that an unpipelined processor has a cycle time of
will be number of TAG bits– 25 ns, and that its data path is made up of modules with
mk m latencies of 2, 3, 4, 7, 3, 2 and 4 ns (in that order). In pipelining
(a) log 2 (b) log 2 this processor, it is not possible to rearrange the order of
n n
the modules (for examples, putting the register read stage
nk mn before the instruction decode stage) or to divide a module
(c) log 2 (d) log 2
m k into multiple pipeline stages (for complexity reasons). Given
95. In a vectored interrupt pipeline latches with 1 ns latency: If the processor is divided
(a) the branch address is assigned to a fixed location in into the rewest number of stages that allow is to achieve the
memory minimum latency from part 1, what is the latency of the
(b) the interrupting source supplies the branch pipeline?
information to the processor through an interrupt (a) no latency (b) 35 ns latency
vector (c) 40 ns latency (d) 56 ns latency
(c) the branch address is obtained from a register in the
processor NUMERICAL TYPE QUESTIONS
(d) none of the above
101. A 4-stage pipeline has the stage delays as 150, 120, 160
96. A device with data transfer rate 10 KB/sec is connected to a
and 140 ns respectively. Registers that are used between
CPU. Data is transferred byte-wise. Let the interrupt
the stages have a delay of 5 ns. Assuming constant
overhead be 4 msec. The byte transfer time between the
device interface register and CPU or memory is negligible. locking rate the total time required to process 1000 data
What is the minimum performance gain of operating the items on this pipeline in
EBD_7203
S3-104 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
102. A non-pipeline sysem takes 40 ns to process a task. The 118. A computer employ chips of 256 × 8 and ROM chips of
same task can be processed in a 6-segment pipeline with 1024 × 8. The computer system needs 2k byte of RAM,
a clock cycle of 10 s. Determine the speed up ratio of the 4K. bytes of ROM and four interface units, each with four
pipeline for 100 tasks.
register. A memory mapped 1/0 configuration is used. The
103. The refreshing rate of dynamic RAMs is in the range of
___________µs. two highest order bits of the address assigned 00 for
104. Consider a small two-way set associative cache memory, RAM, 01 for ROM, and 10 for interface registers. How
consisting of four blocks, for choosing the block to be many RAM and ROM chips are required?
replaced. Use the least recently scheme. The number of 119. In a non-pipelined single-cycle-per-instruction processor
cache misses for the following sequence of block with an instruction cache, the average instruction cache
addresses 8, 12, 0, 12, 8 is
miss rate is 5%. It takes 8 clock cycles to fetch a cache
105. In a virtual memory system, size of virtual address is
32-bit, size of physical adress is 30-bit, page size is 4 kb line from the main memory. Disregarding data cache
and size of each page table entry in 32-bit. The main misses, what is the approximate average CPI (cycles per
memory is byte addressable. Which one of the following instruction)?
is the maximum number of bits that can be used for
COMMON DATA & LINKED ANSWER TYPE QUESTIONS
storing protection and other information in each page
table entry? Common data for Q. 120 and Q. 121
106. When cache is faster than main memory and cache can be
used 90% of the time, how much speed we gain by using The mapping function is implemented using the address. For
the cache? purpose of cache access. each main memory address can be
107. What will be average cost per bit for a system with main viewed as consisting of three fields.
memory of 1024 cost, 100 units and secondary memory of The least significant ‘w’ bits identify a unique word or byte within
4096 cost, 10 units.
a block of main memory. The remaining ‘s’ bits specify one of the
108. An 8 bit register R contain the binary value 10011100 what
is the register value after an arithmetic shift right? Starting 2s blocks of main memory. The cache logic interprets these ‘s’ bits
from the initial number 10011100, determine the register as a tag of ‘s–r’ bits and a line field of ‘r’ bits.
value after an arithmetic shift left. Enter the binary digit. 120. With above information, number of lines in cache equals to
__________.
109. How many memory chips of 128 × 8 are needed to provide
memory capacity of 4096 × 16. (a) 2r (b) 2r + w
110. How many 128 × 8 RAM chips are needed to provide a (c) 2s + w (d) undetermined
memory capacity of 2048 bytes?Enter a value.
121. With the above information, the size of tag equals to
111. How many lines of the address bus must be used to
access 2048 bytes of memory ? Enter a value. ___________.
112. If a disk spins at 10,000 rpm what is the average rational (a) r bits (b) (s + w) bits
latency time of a request? If a given track on the disk has (c) s bits (d) (s – r) bits
1024 sectors, what is the transfer time for a sector?
113. In a cache with 64 byte cache lines how may bits are used Common data for Qs. 122 to 124.
to determine which byte within a cache line an address Consider a machine with a byte addressable main memory of
points to? 216 bytes. Assume that a direct mapped data cache consisting of
114. For a cache with a capacity of 32 KB, How many lines 32 lines of 64 bytes each is used in the system. A 50 × 50 two-
does the cache hold for line lengths of 32, 64 or 128 dimensional array of bytes is stored in the main memory starting
bytes? from memory location 1100 H. Assume that the data cache is
115. If a cache has a capacity of 16KB and a line length of 128
initially empty. The complete array is accessed twice. Assume
bytes, how many sets does the cache have if it is 2-way,
4-way, or 8-way set associative? that the contents of the data cache do not change in between the
116. If a cache memory has a hit rate of 75 percent, memory two accesses.
request take l2ns to complete if they hit in the cache and 122. How many data cache misses will occur in total?
memory request that miss in the cache take 100 ns to (a) 48 (b) 50
complete, what is the average access time of cache? (c) 56 (d) 59
117. In a two level memory hierarchy, if the cache has an access 123. Which of the following lines of the data cache will be
time of ns and main memory has an access time of 60ns,
replaced by new blocks in accessing the array?
what is the hit rate in cache required to give an average
(a) line 4 to line 11 (b) line 4 to line 12
access time of 10ns?
(c) line 0 to line 7 (d) line 0 to line 8
COMPUTER ORGANIZATION AND ARCHITECTURE S3-105
124. A cache line is 64 Bytes. The main memory has latency 32 130. What is the average memory stalls per instruction?
ns and bandwidth 1 G.Bytes/s. The time required to fetch (a) 3.4 clock cycles (b) 3.5 clock cycles
the entire cache line from the main memory is (c) 3.6 clock cycles (d) 4.5 clock cycles
(a) 32 ns (b) 64 ns Common Data Questions for 131 and 132.
(c) 96 ns (d) 128 ns Consider an unpipelined processor assume that it has a 1 ns clock
Common data for Q. 125 and 126 cycles and that it uses 4 cycles for ALU operation and branches
Let a cache has 126 llines, each with 16 words and is is 2-way
and 5 cycles for memory operations. Assume that the relative
set associative. Suppose the main memory has 16-bit address.
frequencies of these operations are 40%, 20% and 40%
Both cache and main memory are word addressable.
respectively. Suppose due to clock skew and setup, pipelining
125. How many bits are in the “tag” field in the cache?
the processor adds 0.2 ns of overhead to the clock. Ignore any
(a) 6 (b) 8
latency impact.
(c) 5 (d) 7
131. What is the average instruction execution time for
126. Now suppose we want to read or write a word at the
unpipelined processor?
memory address 357 A. Under the above set-associative
(a) 3.4 ns (b) 4.4 ns
mapping technique what will be the “tag” field in decimal?
(c) 3.1 ns (d) 1.2 ns
(a) 6 (b) 26
132. What speedup gain after pipelined the processor?
(c) 13 (d) 53
(a) 3.4 ns (b) 3.8 ns
Common Data Questions for 127 and 128.
(c) 3.7 ns (d) 1.2 ns
Consider an accumulator-based CPU supports only single address
instruction. The CPU supports the following instructions. Common Data for Q. 133 and Q 134
LOAD A Load A from memory into accumulator AC. Consider the following assembly language program for a
STORE A Store contents of accumulator AC in memory location hypothetical processor. A, B and C are 8 bit integers. The meaning
M of various instructions are shown as comments.
ADD B Load B into data register (DR) and add to accumulator. MOV B, # 0; B¬0
MOV A, B Move content of B to A. MOV C, # 8; C¬8
SUB A, B Subtract B from A.
Z : CMP C, # 0; compare C with 0
127. Assume CPU uses the memory referencing and each
instruction LOAD, STORE and ADD takes on clock cycle. JZX; jump to X if zero flag is set
To computer Z = X + Y CPU takes how many minimum SUBC, # 1; C ¬C–1
number of clock cycles? LRCA, # 1; Left rotate A through carry by one
(a) 2 (b) 3 bit. Thus if the initial value of A
(c) 4 (d) 5 and the carry flag are a7a6....a0 and
128. How many minimum clock cycles are needed when c0 respectively, their values after
accumulator becomes O. If each instruction takes one clock the execution will be a6a5 ..... a0c0
cycles? and a7 respectively.
(a) 0 (b) 1
JC Y; Jump to Y if carry flag is set
(c) 2 (d) 3
Common Data Questions for 129 and 130. JMP Y; Jump to Z
Suppose a CPU contains 1000 memory references there are 40 Y: ADD B, # 1 B¬B+1
misses in L1 cache (First Level Cache) and 20 misses in the L2 JMP Z; Jump to Z
cache (Second Level Cache). Assume miss penalty from the L2 X:
cache to memory is 100 clock cycles the hit time of L2 cache is
133. If the initial value of register A is A0, the value of register B
10 clock cycles, the hit time of L1 cache is 1 clock cycle and there
after the program execution will be
are 1.5 memory references per instruction.
129. What is the average memory access time? (a) The number of 0 bits in A
(a) 3.4 clock cycles (b) 3.5 clock cycles (b) The number of 1 bits in A
(c) 5.3 clock cycles (d) 1.8 clock cycles (c) A 0
(d) 8
EBD_7203
S3-106 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
134. Which of the following instructions should be inserted at The, ALU, the bus and all the registers in the data path are
location X to ensure that the value of register A after program of identical size. All operations including incrementation of
execution is the same as its initial value? the PC and the GPRs are to be carried out in the ALU. Two
clock cycle are needed for memory read operation – the first
(a) NOP (b) LRC A, # 1 one for loading address in the MAR and the next one for
(c) ADD A, # 1 (d) RRC A, # 1 loading data from the memory but into the MDR.
Common data for Q. 135 and Q. 136 135. The instruction “add R0, R1” has the register transfer
Consider the following data path of a CPU interpretation R0 < = R0 + R1. The minimum number of clock
cycles needed for execution cycle of this instruction is
MAR MDR
(a) 2 (b) 3
(c) 4 (d) 5
136. The instruction “call Rn, sub” is a two word instruction.
Assuming that PC is incremented during the fetch cycle of
the first word of the instruction, its register transfer
interpretation is
Rn < = PC + 1;
S T PC < = M [PC]
IR PC The minimum number of CPU clock cycles needed during
GPRs the execution cycle of this instruction is
ALU (a) 2 (b) 3
(c) 4 (d) 5
COMPUTER ORGANIZATION AND ARCHITECTURE S3-107

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)

1. (c) 2. (c) 3. (c) Thus required bits for word = 12 – (4 + 2) = 6


31. (b) The combination of input data will be 28. The
4. (a) Here [X] command will require 3 address spaces
combination of two 8-bit data will be
because the instruction contains address 00FF or
0701 which is 16-bit data. Thus the address will be as 28 × 28 = 216
Thus, 216 bit memory location will be required to
Adress
store all combination of words.
0100 LXI SP, 00FF
216 bits = 26 k = 64 k memory
0103 LXI H, 0701 and 216 bit will be required to store the result of each
0106 MVI A, 20 H multiplication thus total memory will be 64k × 16 bit
0199 ..... 32. (c) The address <400, 16, 29> corresponds to sector
Here, MVI A, 20 means 20 is to be stored in number
accumulator. Thus A ¬ 20 H 400 × 2 × 10 × 63 + 16 × 63 + 29 = 50 50 37
Thus the content of accumulator will be 20 H 33. (b) The Register Transfer Language (RTL) is
5. (c) MVI05 as 05 is data that is directly given in the R3 ¬ R3 + M[R1 + R2]
instruction. In the given statement R1 is the base of an array and
6. (b) 2 cycle average access = (1 cycle for cache) + R2 represents an index so indexed addressing mode
(1 - hit rate)(5 cycles stall) => hit rate = 80% is suitable for given RTL.
34. (b) The instruction format is as follow
7. (b) In direct mode address is given in the instruction
which is 400 means 0-3. Mode opcode address address designer
In immediate addressing mode data is given in the 1 bit 3 bit 12 bit 1
instruction that is data is 400 which is stored at 301.
Now Mode = 1 if indirect addressing
8. (b) 9. (b) 10. (a) 11. (a) 12. (d)
Mode = 0 if direct addressing
13. (a) Locality implies that the probability of accessing a 35. (d) CISC – Complex instruction set computer
location decreases as the time since the last access
RISC – Reduced instruction set computer
increases. By choosing to replace locations that
36. (b)
haven't been used for the longest time, the least-
recently-used replacement strategy should, in theory, 37. (b) (i) Regs [R4] ¬ Regs [R4] + Regs [R3]
be replacing locations that have the lowest probability Here contents of Regs [R4] and [R3]
of being accessed in the future. are added and placed into Register [R4]
14. (c) 15. (c) 16. (c) 17. (a) 18. (a) 19. (b) which is a register operation.
20. (b) 21. (d) 22. (b) 23. (b) 24. (b) 25. (d) (ii) Regs [R4] ¬ Regs [R4] + 3
Here 3 is data instead of address
26. (b) 27. (a)
Hence, it is a immediate mode.
28. (a) Prefetch target instruction strategy
Hence (b) is correct option
29. (d) Speed up factor of a pipeline 38. (c) In pipelining, a number of functional units are
= Number of stages in pipelines = n employed in sequence to perform a single computation.
30. (d) Total word in a set = 64 × 4 = 26 × 22 = 28 39. (d) 2^width of the address bus x the data bus
= Maximum amount of addressable memory.
4 ´ 210 32 bit system with a 32-bit address bus width and a
Number of sets in cache = = 4 ´ 2 2 = 16 = 2 4
28 32-bit data bus width. 2^32 x 32 = 13743895350Bytes
= 128GB, hence a 32 bit system can only address
Thus the cache will have 16 sets which will requires
4GB of memory.
4-bit.
40. (b) 41. (c) 42. (c) 43. (d) 44. (c)
Total memory size = 4 k = 4 × 210 = 212
45. (d) 46. (c)
Available address bits = 12
47. (a) Increased block size means that more words are
Required bits for set = 4 fetched when filling a cache line after a miss on a
EBD_7203
S3-114 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
particular location. If this leads to increased miss penalty of the primary cache. A workstation
performance, then the nearby words in the block computer may include a primary cache with the
must have been accessed by the program later on, ie, capacity of tens of kilobytes and a secondary cache
the program is exhibiting locality. of several megabytes.
48. (a) Considering only the data accesses, the program tavg = h1c1 + (1 – h 1)h2c2 + (1 – h 1)(1 – h2)M
performs 1,000,000 reads and 1,000,000 writes. Since The number of misses in the secondary cache, given
the cache has 4-word blocks, each miss brings 4 by the term (1 – h1)(1 – h2).
words of the array into the cache. So accesses to the
55. (d) 56. (a)
next 3 array locations won't cause a miss. Since the
cache is write-back, writes happen directly into the 57. (b) The cache has 128-byte lines, which is 32 words.
cache without causing any memory accesses until Using the specified memory timings, the cache
the word is replaced. So altogether there are 250 spends 5 ns detecting that a miss has occurred and
misses (caused by a read of A[0], A[4], A[8], ...), for 100 ns + 31(10 ns) = 410 ns fetching a line from the
a miss rate of 250/2,000,000 = 0.0125% main memory into the cache. The cache then
reexecutes the operation that caused the miss, taking
49. (d)
5 ns. This gives a cache miss time of 420 ns.
50. (d) There are 64 words in a block. So the 4k cache has
58. (b) – 1 × 2° + 1 × 23 – 1 × 26 = –1 + 8 – 64 = – 57
(4 × 1024)/64 = 64 blocks. Since 7 set has 4 blocks,
there are 16 sets. 16 sets needs 4 bits for 59. (d) Daisy chained arbitration scheme requires 3 lines
representation. In a set there are 4 blocks, which irrespective of the number of devices. A pair of REQ/
needs 2 bits. Each block has 64 words. So the word GRANT lines are required in the case of independent
field has 6 bits. request type arbitration and so for N devices 2N
lines.
51. (b)
60. (d) In index Addressing mode, the effective address of
52. (c) The operation code specifies one of eight input out
the operand is generated by adding an index values
put instructions. Start input/output, start input/
to the address given in the instruction. The index
output fast release, test input/output, clear input/
value is held in a register called index register.
output, halt input/output, halt device, test channel
and store channel identification. EA = A + A
¯ ¯
53. (d) 3 address institruction modifier contents of index register

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

PROGRAMMING AND DATA


STRUCTURES

C Ø Programming in C

O Ø

Ø
Functions, Recursion

Parameter Passing

N Ø Scope, Binding

T
Ø Abstract data types, Arrays, Stacks

Ø Queues, Linked Lists

E Ø Trees, Binary search trees

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:

Header Files Purpose Functions Declared


printf(), scanf(), getchar(),
Used for standard input and output (I/O)
stdio.h putchar(), gets(), puts(), getc(),
operations.
putc(), fopen, fclose(), feof()
Contains declaration for console I/O
conio.h clrscr(); exit()
functions
Used for character-handling or testing
ctype.h isupper(), is lower, isalpha()
characters.
Declares mathematical functions and pow(), squr(), cos(), tan(), sin(),
math.h
macros log()
Used for number conversions, storage
stdlib.h rand(), srand()
allocations.
streln(), strcpy(), strcmp(), stract(),
string.h Used for manipulating strings
strlwr(), strupr(), strrev()
EBD_7203
S3-122 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Data Type
Data type determines the kind of data which is going to be stored in the variable
declared to of that type. It plays major role to declare variables. It prevents invalid
data entry in the program. The biggest advantage of data types is efficient use of
memory space. Data type can be classified into following sub-heads.

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

extern int count;

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 ++

First File: main.cpp


#include <iostream>

int count ;
extern void write_extern();

main()
{
count = 5;
write_extern();
}
Second File: support.cpp
#include <iostream>

extern int count;

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

The mutable Storage Class


The mutable specifier applies only to class objects That is, a mutable member can be
modified by a const member function.
PROGRAMMING AND DATA STRUCTURES S3-125

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};

printf("RED = %d\n", RED);


printf("YELLOW = %d\n", YELLOW);
printf("GREEN = %d\n", GREEN);
printf("BLUE = %d\n", BLUE);
return 0;
}

This will produce following results

RED = 5
YELLOW = 6
GREEN = 4
BLUE = 5

C - Operator Types

What is Operator? Simple answer can be given using expression 4 + 5 is equal to


9. Here 4 and 5 are called operands and + is called operator. C language supports
following type of operators.
C++ is rich in built-in operators and provides the following types of operators:

• 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

Operator Des cription Example


+ A d ds two op erand s A + B will giv e 30

- Su btracts s econ d o peran d fro m the firs t A - B will giv e -10

* M ultip ly b oth o p eran ds A * B will giv e


200
/ Divide n umerator b y d enu merator B / A will giv e 2
% M od u lus Operator and remain der of after an B % A will g ive 0
integer d ivis ion

Logical (or Relational) Operators:


There are following logical operators supported by C language
Assume variable A holds 10 and variable B holds 20 then:
Show Examples
PROGRAMMING AND DATA STRUCTURES S3-127

Operator Description Example


== Checks if the value of two operands is equal or (A == B) is not true.
not, if yes then condition becomes true.
!= Checks if the value of two operands is equal or (A != B) is true.
not, if values are not equal then condition
becomes true.
> Checks if the value of left operand is greater (A > B) is not true.
than the value of right operand, if yes then
condition becomes true.
< Checks if the value of left operand is less than (A < B) is true.
the value of right operand, if yes then condition
becomes true.
>= Checks if the value of left operand is greater (A >= B) is not true.
than or equal to the value of right operand, if
yes then condition becomes true.

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

Operator Description Example


& Binary AND Operator copies a bit to the (A & B) will give 12 which is
result if it exists in both operands. 0000 1100
| Binary OR Operator copies a bit if it exists (A | B) will give 61 which is
in eather operand. 0011 1101
^ Binary XOR Operator copies the bit if it is (A ^ B) will give 49 which is
set in one operand but not both. 0011 0001
~ Binary Ones Complement Operator is unary (~A ) will give -60 which is
and has the efect of 'flipping' bits. 1100 0011
<< Binary Left Shift Operator. The left A << 2 will give 240 which is
operands value is moved left by the number 1111 0000
of bits specified by the right operand.

>> 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:

Operator Description Example


= Simple assignment operator, Assigns C = A + B will assigne
values from right side operands to left value of A + B into C
side operand
+= Add AND assignment operator, It adds C += A is equivalent to
right operand to the left operand and C =C+A
assign the result to left operand

-= Subtract AND assignment operator, It C -= A is equivalent to


subtracts right operand from the left C =C-A
operand and assign the result to left
operand
*= Multiply AND assignment operator, It C *= A is equivalent to
multiplies right operand with the left C =C*A
operand and assign the result to left
operand
/= Divide AND assignment operator, It C /= A is equivalent to
divides left operand with the right C =C/A
operand and assign the result to left
operand
%= Modulus AND assignment operator, It C %= A is equivalent to
takes modulus using two operands and C =C%A
assign the result to left operand
<<= Left shift AND assignment operator C <<= 2 is same as C =
C << 2
>>= Right shift AND assignment operator C >>= 2 is same as C =
C >> 2
&= Bitwise AND assignment operator C &= 2 is same as C =
C &2
^= bitwise exclusive OR and assignment C ^= 2 is same as C = C
operator ^2
|= bitwise inclusive OR and assignment C |= 2 is same as C = C |
operator 2
PROGRAMMING AND DATA STRUCTURES S3-129
Misc Operators
There are few other operators supported by C Language.

O perator Des cription Example


s izeo f() Retu rn s th e s ize o f an v ariab le . s izeo f(a), wh ere a is in terg er, will
retu rn 4.
& Retu rn s th e ad d res s o f an & a; will g iv e actau l ad d res s o f
v ariab le. th e v ariab le.
* Po in ter to a v ariab le . * a; will p o in ter to a v ariab le.
?: Co n d itio n al Exp res s io n If Co n d itio n is tru e ? T h en v alu e
X : Oth erwis e v alu e Y
Operators Categories:
All the operators we have discussed above can be categorised into following
categories:
• Postfix operators, which follow a single operand.
• Unary prefix operators, which precede a single operand.
• Binary operators, which take two operands and perform a variety of
arithmetic and logical operations.
• The conditional operator (a ternary operator), which takes three operands
and evaluates either the second or third expression, depending on the
evaluation of the first expression.
• Assignment operators, which assign a value to a variable.
• The comma operator, which guarantees left-to-right evaluation of comma-
separated expressions.
Precedence of C Operators:
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
precedenace than + so it first get 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 precedenace operators
will be evaluated first.

C a tego ry O pera tor A sso cia tivi ty


Po stfix () [] -> . ++ - - Left to rig ht
Unary + - ! ~ ++ - - (ty pe) * & sizeof R igh t to left
M ultiplicati */% Left to rig ht
ve
A dd itiv e +- Left to rig ht
Shift <<> > Left to rig ht
Relatio n al <<= >>= Left to rig ht

Eq u ality == != Left to rig ht


Bitwis e & Left to rig ht
AND
Bitwis e ^ Left to rig ht
XOR
Bitwis e | Left to rig ht
OR
Lo g ical && Left to rig ht
AND
Lo g ical || Left to rig ht
OR
Co nd itio nal ?: R igh t to left

Assig nm ent = += -= * = /= % = >>= <<= & = ^ = |= R igh t to left

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.

Categor y Operator Associativity


Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & sizeof Right to l eft
Multiplicative */% Left to right
Additive +- Left to right
Shift <<>> Left to right
Relational <<= >>= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to l eft
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to l eft
Comma , Left to right

C - Flow Control Statements


C provides two sytles of flow control:
• Branching
• Looping
Branching is deciding what actions to take and looping is deciding how many times
to take a certain action.
Branching:
Branching is so called because the program chooses to follow one branch or another.
if statement
This is the most simple form of the branching statements.
It takes an expression in parenthesis and an statement or block of statements. If the
expression is true then the statement or block of statements gets executed otherwise
these statements are skipped.
NOTE: Expression will be assumed to be true if its evaluated values is non-zeroif
statements take the following form.
Syntax:
if (expression)
statement;
or
if (expression)
{
Block of statements;
}
if condition is true ? then X return value : otherwise Y value;
PROGRAMMING AND DATA STRUCTURES S3-131
? : Operator
The ? : operator is just like an if ... else statement except that because it is an operator
you can use it within expressions.
? : is a ternary operator in that it takes three values, this is the only ternary operator
C has.
? : takes the following form:
switch statement:
The switch statement is much like a nested if .. else statement. Its mostly a matter
of preference which you use, switch statement can be slightly more efficient and
easier to read.
Syntax:
switch( expression )
{
case constant-expression1: statements1;
[case constant-expression2: statements2;]
[case constant-expression3: statements3;]
[default : statements4;]
}
Using break keyword:
If a condition is met in switch case then execution continues on into the next case
clause also if it is not explicitly specified that the execution should exit the switch
statement. This is achieved by using break keyword.

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:

for( expression1; expression2; expression3)


{
Single statement
or
Block of statements;
}

In the above syntax:


• expression1 - Initialise variables.
• expression2 - Condtional expression, as long as this condition is true, loop
will keep executing.
• expression3 - expression3 is the modifier which may be simple increment of
a variable.
EBD_7203
S3-132 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
do...while loop
do ... while is just like a while loop except that the test condition is checked at the
end of the loop rather than the start. This has the effect that the content of the loop
are always executed at least once.
Basic syntax of do...while loop is as follows:
Syntax
Do
{
Single statement
or
Block of statements;
}while(expression);
break and continue statements
C provides two commands to control how we loop:
• break -- exit form loop or switch.
• continue -- skip 1 iteration of loop.
There may be a situation, when you need to execute a block of code several number
of times. In general statements are executed sequentially: The first statement in a
function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more
complicated execution paths.

C++ programming language provides the following types of loop to handle looping
requirements.

Loop Type Description


while loop Repeats a statement or group of statements while a
given condition is true. It tests the condition before
executing the loop body.
for loop Execute a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
do...while loop Like a while statement, except that it tests the condition
at the end of the loop body
nested loops You can use one or more loop inside any another while,
for or do..while loop.
Loop Control Statements:
Loop control statements change execution from its normal sequence. When execution
leaves a scope, all automatic objects that were created in that scope are destroyed.
C++ supports the following control statements.
Control Statement Description
break statement Terminates the loop or switch statement and transfers
execution to the statement immediately following the
loop or switch.
continue statement Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.
goto statement Transfers control to the labeled statement. Though it is
not advised to use goto statement in your program.
C - Input and Output
Input : In any programming language input means to feed some data into program.
This can be given in the form of file or from command line. C programming language
provides a set of built-in functions to read given input and feed it to the program as
per requirement.
Output : In any programming language output means to display some data on screen,
printer or in any file. C programming language provides a set of built-in functions to
output required data.
PROGRAMMING AND DATA STRUCTURES S3-133
printf() function
This is one of the most frequently used functions in C for output.
scanf() function
This is the function which can be used to to read an input from the command line.
C - Pointing to Data
A pointer is a special kind of variable. Pointers are designed for storing memory
address i.e. the address of another variable. Declaring a pointer is the same as
declaring a normal variable except you stick an asterisk '*' in front of the variables
identifier.
• There are two new operators you will need to know to work with pointers.
The "address of" operator '&' and the "dereferencing" operator '*'. Both are
prefix unary operators.
• When you place an ampersand in front of a variable you will get it's
address, this can be stored in a pointer variable.
• When you place an asterisk in front of a pointer you will get the value at
the memory address pointed to.
Pointers and Arrays
The most frequent use of pointers in C is for walking efficiently along arrays. In fact,
in the implementation of an array, the array name represents the address of the zeroth
element of the array, so you can't use it on the left side of an expression. For example:
char *y;
char x[100];
y is of type pointer to character (although it doesn't yet point anywhere). We can
make y point to an element of x by either of
y = &x[0];
y = x;
Since x is the address of x[0] this is legal and consistent. Now `*y' gives x[0]. More
importantly notice the following:
*(y+1) gives x[1]
*(y+i) gives x[i]
and the sequence
y = &x[0];
y++;
leaves y pointing at x[1].
Arrays
C programming language provides a data structure called the array, which can store
a fixed-size sequential collection of elements of the same type. An array is used to
store a collection of data, but it is often more useful to think of an array as a collection
of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and
number99, you declare one array variable such as numbers and use numbers[0],
numbers[1], and ..., numbers[99] to represent individual variables. A specific element
in an array is accessed by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds
to the first element and the highest address to the last element.
First Element Last Element

Numbers[0] Numbers[1] Numbers[2] Numbers[3] ......

int - data type


int is used to define integer numbers.
{
int Count;
Count = 5;
}
float - data type
EBD_7203
S3-134 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
float is used to define floating point numbers.

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

C/C++ Arrays in Detail


Arrays are important to C and should need lots of more details. There are following
few important concepts related to array which should be clear to a C programmer:
Concept Description
Multi-dimensional arrays It supports multidimensional arrays. The simplest
form of the multidimensional array is the two-
dimensional array.
PROGRAMMING AND DATA STRUCTURES S3-137
Passing arrays to functions You can pass to the function a pointer to an array
by specifying the array's name without an index.
Return array from a function It allows a function to return an array.
Pointer to an array You can generate a pointer to the first element of
an array by simply specifying the array name,
without any index.
POINTERARITHMETIC
C is one of the few languages that allows pointer arithmetic. In other words, you
actually move the pointer reference by an arithmetic operation. For example:
int x = 5, *ip = &x;

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.

Generic Pointers: ( void Pointer )


When a variable is declared as being a pointer to type void it is known as a generic
pointer. Since you cannot have a variable of type void, the pointer will not point to
any data and therefore cannot be dereferenced. It is still a pointer though, to use it
you just have to cast it to another kind of pointer first. Hence the term Generic pointer.
This is very useful when you want a pointer to point to data of different types at
different times.
NOTE-1 : Here in first print statement, the_data is prefixed by *(int*). This is called
type casting in C language.Type is used to caste a variable from one data type to
another datatype to make it compatible to the lvalue.
NOTE-2 : lvalue is something which is used to left side of a statement and in which
we can assign some value. A constant can't be an lvalue because we can not assign
any value in contact. For example x = y, here x is lvalue and y is rvalue.
However, above example will produce following result:
the_data points to the integer value 6
the_data now points to the character a
POINTERS
A pointer is a variable whose value is the address of another variable. Like any
variable or constant, you must declare a pointer before you can work with it. The
general form of a pointer variable declaration is:
type *var-name;
Here, type is the pointer's base type; it must be a valid C++ type and var-name is the
name of the pointer variable. The asterisk you used to declare a pointer is the same
asterisk that you use for multiplication. However, in this statement the asterisk is
being used to designate a variable as a pointer. Following are the valid pointer
declaration:
int*ip;// pointer to an integer
double*dp;// pointer to a double
float*fp;// pointer to a float
char*ch // pointer to character
The actual data type of the value of all pointers, whether integer, float, character, or
otherwise, is the same, a long hexadecimal number that represents a memory address.
The only difference between pointers of different data types is the data type of the
variable or constant that the pointer points to.
EBD_7203
S3-138 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
C - Using Functions
A function is a module or block of program code which deals with a particular task.
Making functions is a way of isolating one block of code from other independent
blocks of code.
Functions serve two purposes.
• They allow a programmer to say: `this piece of code does a specific job
which stands by itself and should not be mixed up with anyting else',
• Second they make a block of code reusable since a function can be
reused in many different contexts without repeating parts of the program
text.
A function can take a number of parameters, do required processing and then
return a value. There may be a function which does not return any value.
Consider the following code
int total = 10;
printf("Hello World");
total = total + l;
To turn it into a function you simply wrap the code in a pair of curly brackets to
convert it into a single compound statement and write the name that you want to
give it in front of the brackets:
Demo()
{
int total = 10;
printf("Hello World");
total = total + l;
}
curved brackets after the function's name are required. You can pass one or more
paramenters to a function as follows:
Demo( int par1, int par2)
{
int total = 10;
printf("Hello World");
total = total + l;
}
By default function does not return anything. But you can make a function to
return any value as follows:
int Demo( int par1, int par2)
{
int total = 10;
printf("Hello World");
total = total + l;

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>

/* function declaration goes here.*/


void swap( int p1, int p2 );

int main()
{
int a = 10;
int b = 20;

printf("Before: Value of a = %d and value of b = %d\n", a, b );


swap( a, b );
printf("After: Value of a = %d and value of b = %d\n", a, b );
}
EBD_7203
S3-140 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
void swap( int p1, int p2 )
{
int t;

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;

printf("Before: Value of a = %d and value of b = %d\n", a, b );


swap( &a, &b );
printf("After: Value of a = %d and value of b = %d\n", a, b );
}

void swap( int *p1, int *p2 )


{
int t;

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";

Reading and Writing Strings:


One possible way to read in a string is by using scanf. However, the problem with
this, is that if you were to enter a string which contains one or more spaces, scanf
would finish reading when it reaches a space, or if return is pressed. As a result, the
string would get cut off. So we could use the gets function
A gets takes just one argument - a char pointer, or the name of a char array.A puts
function is similar to gets function in the way that it takes one argument - a char
pointer. This also automatically adds a newline character after printing out the string.
#include <stdio.h>

int main() {
char array1[50];
char *array2;

printf("Now enter another string less than 50");


printf(" characters with spaces: \n");
gets(array1);

printf("\nYou entered: ");


puts(array1);

printf("\nTry entering a string less than 50");


printf(" characters, with spaces: \n");
EBD_7203
S3-142 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
scanf("%s", array2);

printf("\nYou entered: %s\n", array2);

return 0;
}
This will produce following result:
Now enter another string less than 50 characters with spaces:
hello world

You entered: hello world

Try entering a string less than 50 characters, with spaces:


hello world

You entered: hello


String Manipulation Functions
• char *strcpy (char *dest, char *src) - Copy src string string into dest string.
• char *strncpy(char *string1, char *string2, int n) - Copy first n characters
of string2 to stringl .
• int strcmp(char *string1, char *string2) - Compare string1 and string2 to
determine alphabetic order.
• int strncmp(char *string1, char *string2, int n) - Compare first n characters
of two strings.
• int strlen(char *string) - Determine the length of a string.
• char *strcat(char *dest, const char *src); - Concatenate string src to the
string dest.
• char *strncat(char *dest, const char *src, int n); - Concatenate n chracters
from string src to the string dest.
• char *strchr(char *string, int c) - Find first occurrence of character c in
string.
• char *strrchr(char *string, int c) - Find last occurrence of character c in
string.
• char *strstr(char *string2, char string*1) - Find first occurrence of string
string1 in string2.
• char *strtok(char *s, const char *delim) - Parse the string s into tokens
using delim as delimiter.
C++ supports a wide range of functions that manipulate null-terminated strings:
S.N. Function & Purpose
1 strcpy(s1, s2);
Copies string s2 into string s1.
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.
5 strchr(s1, ch);
Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);Returns a pointer to the first occurrence of string s2 in string s1.

C - Structured Datatypes

• A structure in C is a collection of items of different types. You can think


of a structure as a "record" is in Pascal or a class in Java without methods.
PROGRAMMING AND DATA STRUCTURES S3-143
• Structures, or structs, are very useful in creating data structures larger and
more complex than the ones we have discussed so far.
• Simply you can group various built-in data types into a structure.
Following is the example how to define a structure.
struct student {
char firstName[20];
char lastName[20];
char SSN[9];
float gpa;
};
Now you have a new datatype called student and you can use this datatype define
your variables of student type:
struct student student_a, student_b;

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

size_t fwrite(const void *ptr, size_t size_of_elements,


size_t number_of_elements, FILE *a_file);
Both of these functions deal with blocks of memories - usually arrays. Because they
accept pointers, you can also use these functions with other data structures; you can
even write structs to a file or a read struct into memory.
Abstract Data types
C is not object-oriented, but we can still manage to inject some object-orientedprinciples
into the design of C code. For example, a data structure and its operationscan be
packaged together into an entity called an Abstract data type. There's a clean,simple
interface between the abstract data type and the program(s) that use it. The
lower-level implementation details of the data structure are hidden from view of
therest of the Program.
Example:-
stack: operations are "push an item onto the stack", "pop an item from the stack",
"ask if the stack is empty"; implementation may be as array or linked list queue:
operations are "add to the end of the queue", "delete from the beginning of the
queue", "ask if the queue is empty"; implementation may be as array or linked list
or heap.
search structure: operations are "insert an item", "ask if an item is in the structure",
and "delete an item"; implementation may be as array, linked list, tree, hash table.
EBD_7203
S3-146 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Data abstraction refers to, providing only essential information to the outside world
and hiding their background details, i.e., to represent the needed information in
program without presenting the details.
Data abstraction is a programming (and design) technique that relies on the
separation of interface and implementation.

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

Uses and Operations on Linked Lists


Linear linked list: last element is not connected to anything
Circular linked list: last element is connected to the first
Dynamic: Size of a linked list grows or shrinks during the
execution of a program and is just right
Advantage: It provides flexibility in inserting and deleting
elements by just re-arranging the links
Disadvantage: Accessing a particular element is not easy
There are three major operations on linked lists

1 Insertion
2 Deletion
3 Searching

Linked list: chain of nodes


A linked list is simply a linear chain of such nodes.The beginning of the list is
maintained as a pointer to the firstelement (generally called head)
Space for an element is created using a pointer (say q)
q = (struct Node *) malloc (size of (struct Node) );
EBD_7203
S3-150 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
q->data is the desired value
q->next is NULL
A list element's members are accessed using the pointer (q)
to the list element
data using q->data
next element pointer using q->next
Moving to next element is done using pointers
q = q?next;

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;
}
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

Insertion at end of list


Create a new node (say q)
Find the last element (say p)
Make p->next point to q
if list is empty, i.e., head is NULL
Make head equal to q

Deletion at the beginning of the list


Make p equal to head
Make head equal to head->next
Delete p (by using free)
If list is empty, i.e., head is NULL
Nothing to do
If list contains only one element
Delete head
head is now NULL

Deletion from the end of the list


Find the last element (say p)
While finding p, maintain q that points to p
q is the node just before p, i.e., q->next is p
PROGRAMMING AND DATA STRUCTURES S3-151
Make q->next NULL
Delete p (by using free)
If list is empty, i.e., head is NULL
Nothing to do
If list contains only one element
Delete head
head is now NULL

Searching a node (insert after, delete after)


Make p equal to head
While p->data not equal to the data that is being searched,
make p equal to p->next
Using search, insert after and delete after operations can be
implemented
Insert after p
Create a new node q
Make q->next equal to p->next
Make p->next 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);

create_if (head == NULL)


head = q;
else /*non empty list*/
{
p = head;
while (p->next != NULL)
p = p->next;
p->next = q;
}
scanf("%d", &v);
}

print_list(head); /*Display the data in the list*/

Inserting at the beginning


printf("Inserting at beginning\n");
scanf("%d", &v);
while (v != -1)
{
q = create_node(v);
q->next = head;
head = q;
scanf("%d", &v);
}

print_list(head); /*Display the data in the list*/

Inserting after an element


printf("Inserting after\n");
scanf("%d", &v);
while (v != -1)
{
q = create_node(v);
scanf("%d", &a);
p = head;
while ((p != NULL) && (p->data != a))
p = p->next;
if (p != NULL)
{
q->next = p->next;
p->next = q;
}
scanf("%d", &v);
}
print_list(head); /*Display the data in the list*/
PROGRAMMING AND DATA STRUCTURES S3-153
Deleting from the end
printf("Deleting from end\n");
if (head != NULL)
{
p = head;
while (p->next != NULL)
{
q = p;
p = p->next;
}

q->next = NULL;
free (P);
}
Print_list(head);/*Display the data in the list */

Deleting from the beginning


printf("Deleting from beginning\n");
if (head != NULL)
{
p = head;
head = head->next;
free(p);
}
/*Empty list: i.e. head==NULL, do nothing*/
print_list(head); /*Display the data in the list*/

Deleting after an element

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

int pop(node **head_address)


{
node *p, *head;
int top;
head = *head_address; /*head has address of the first element*/
if (head != NULL)
{
p = head; //p: address of stack top element in stack
top = p->data; //data in stack top/first element
head = head->next; //head now has address of 2nd element in stack
free(p); //remove the first element in stack
}
else
top = -1; //-1 denotes invalid value or empty list
*head_address = head; /*reflect the changes to head outside*/
return top;
}
QUEUE

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.

ARITHMETIC EXPRESSION EVALUATION


An important application of stacks is in parsing. For example, a compiler must parse
arithmetic expressions written using infix notation:
1 + ((2 + 3) * 4 + 5)*6
We break the problem of parsing infix expressions into two stages. First, we convert
from infix to a different representation called postfix. Then we parse the postfix
expression, which is a somewhat easier problem than directly parsing infix.
PROGRAMMING AND DATA STRUCTURES S3-157
Converting from Infix to Postfix. Typically, we deal with expressions in infix notation
2+5
where the operators (e.g. +, *) are written between the operands (e.q, 2 and 5). Writing
the operators after the operands gives a postfix expression 2 and 5 are called
operands, and the '+' is operator. The above arithmetic expression is called infix, since
the operator is in between operands. The expression 2 5 + Writing the operators
before the operands gives a prefix expression +2 5 Suppose you want to compute the
cost of your shopping trip. To do so, you add a list of numbers and multiply them
by the local sales tax (7.25%): 70 + 150 * 1.0725
Depending on the calculator, the answer would be either 235.95 or 230.875. To avoid
this confusion we shall use a postfix notation
70 150 + 1.0725 *
Postfix has the nice property that parentheses are unnecessary.
Now, we describe how to convert from infix to postfix.
1. Read in the tokens one at a time
2. If a token is an integer, write it into the output
3. If a token is an operator, push it to the stack, if the stack is empty. If the stack
is not empty, you pop entries with higher or equal priority and only then you
push that token to the stack.
4. If a token is a left parentheses '(' , push it to the stack
5. If a token is a right parentheses ' )', you pop entries until you meet '(' .
6. When you finish reading the string, you pop up all tokens which are left there.
7. Arithmetic precedence is in increasing order: '+', '-', '*', '/';
Evaluating a Postfix Expression. We describe how to parse and evaluate a postfix
expression.
1. We read the tokens in one at a time.
2. If it is an integer, push it on the stack
3. If it is a binary operator, pop the top two elements from the stack, apply the
operator, and push the result back on the stack.
Consider the following postfix expression
593+42**7+*
Here is a chain of operations
Stack Operations Output Suppose we have an infix
push(5); 5 expression:2+(4+3*2+1)/3. We read the
push(9); 5 9 string by characters.
push(3); 5 9 3 '2' - send to the output.
push(pop( ) + pop( )) 5 12 '+' - push on the stack.
'(' - push on the stack.
push(4); 5 12 4
'4' - send to the output.
push(2); 5 12 4 2
'+' - push on the stack.
push(pop( ) * pop( )) 5 12 8 '3' - send to the output.
push(pop( ) * pop( )) 5 96 '*' - push on the stack.
push(7) 5 96 7 '2' - send to the output.
push(pop( ) + pop( )) 5 103
push(pop( ) * pop( )) 515
Note, that division is not a commutative operation, so 2/3 is not
the same as 3/2.
EBD_7203
S3-158 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
T R EE S
A tree is a data structure that is made of nodes and pointers, much like a linked
list. The difference between them lies in how they are organized:
In a linked list each node is connected to one “successor” node (via next
pointer), that is, it is linear.
In a tree, the nodes can have several next pointers and thus are not linear.
The top node in the tree is called the root and all other nodes branch off from
Root this one.
Every node in the tree can have some number of children. Each child node can
Level 0 in turn be the parent node to its children and so on.
A common example of a tree structure is the binary tree.
A binary tree is a tree that is limited such that each node has only two children.
If n1 is the root of a binary tree and n2 is the root of its left or right tree, then
Level 1
n1 is the parent of n2 and n2 is the left or right child of n1.
A node that has no children is called a leaf.
The nodes are siblings if they are left and right children of the same parent.
The level of a node in a binary tree:
Level 2 • The root of the tree has level 0
• The level of any other node in the tree is one more than the level of its
parent.
Types of Binary Tree:-
Level 3 1. Strictly Binary Tree
• If every non leaf node in a binary tree has non empty left and right sub
trees, the tree is termed as strictly binary tree
A Every non leaf node has degree 2.
A strictly binary tree with n leaves has (2n-1) nodes.
Thus a strictly binary tree has odd number of nodes.
2. Complete Binary Tree
B C A complete binary tree of depth d is the binary tree of depth d that contains
exactly 2l at each level l between 0 and d.
Thus the total number of nodes in complete binary tree are 2d+1-1 where leaf
nodes are 2d and non leaf are 2d-1.
Because a complete binary tree is also a strictly binary tree , thus if it has n
D E
leaves then it has 2n-1 nodes. Also follows from this is the previous assertion
that if n=2d then total nodes are
d d+1
2*2 -1=2 -1
F G
3. Atmost complete Binary Tree
A binary tree of depth d is an almost complete binary tree if:
• At any node in the tree with a right descendent at level d, node must have
a left son and every left descendent of node is either a leaf at level d or
has two sons.
i.e. the tree must be left filled.
Note : ACBT property says that if there are n nodes in the tree then leaf node
have numbers
[(n/2)+1][(n/2)+2]———n
ACBT with n leaves has 2n nodes if it is not a SBT
An ACBT which is also an SBT has 2n-1 nodes for n leaves
Also an ACBT is an SBT if the number of node are odd
An ACBT of depth d is intermediate between the complete binary tree of depth,
t d-1 that contains 2d-1 nodes , and the complete binary tree of depth d, which
contains 2d+1-1 nodes
PROGRAMMING AND DATA STRUCTURES S3-159
Implementation
A binary tree has a natural implementation in linked storage. A separate pointer
is used to point the tree (e.g. root)
root = NULL; // empty tree
Each node of a binary tree has both left and right subtrees which can be reached
with pointers: left_child data right_child
struct tree_node{
int data;
struct tree_node *left_child;
struct tree_node *right_child;
};
Traversal of Binary Trees:
Linked lists are traversed from first to last sequentially. However, there is no such
natural linear order for the nodes of a tree. Different orderings are possible for
traversing a binary tree. Three of these traversal orderings are:
Preorder traversal (also known as depth – first order)
Inorder traversal (a.k.a. symmetric order)
Postorder traversal (a.k.a end order)
These names are chosen according to the step at which the root node is visited.
• With preorder traversal the node is visited before its left and right subtrees,
• With inorder traversal the root is visited between the subtrees,
• With postorder traversal the root is visited after both subtrees.
Binary Tree Traversal >> Preorder Traversal
Preorder traversal of a binary tree consists of following three recursive operations.
a. Visit the root.
b. Traverse the left sub-tree in preorder.
c. Traverse the left sub-tree in preorder.
void doPreOrder(nodeptr &tree){
nodeptr p = tree;
if(p!= null){
printf(“%d”, p->key);
doPreOrder(p->left);
doPreOrder(p->right);
}
}
Binary Tree Traversal >> Inorder Traversal
Inorder traversal of a binary tree consists of following three recursive operations.
a. Traverse the left sub-tree in inorder.
b. Visit the root.
c. Traverse the left sub-tree in inorder.
void doInOrder(nodeptr &tree){
nodeptr p = tree;
if(p!= null){
doInOrder(p->left);
printf(“%d”, p->key);
doInOrder(p->right);
}
}
Binary Tree Traversal >> Postorder Traversal
Postorder traversal of a binary tree consists of following three recursive operations.
a. Traverse the left sub-tree in postorder.
b. Traverse the left sub-tree in postorder.
c. Visit the root.
void doPostOrder(nodeptr &tree){
nodeptr p = tree;
if(p!= null){
doPostOrder(p->left);
doPostOrder(p->right);
printf(“%d”, p->key);
}
}
EBD_7203
S3-160 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
BINA RY SEARCH TREE:-
BST is a binary tree. For each node in a BST, the left subtree is smaller than it; and
the right subtree is greater than it. A binary search tree (BST), sometimes also called
an ordered or sorted binary tree, is a node-based binary tree data structure which has
the following properties:
The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the
node’s key.
The left and right subtree must each also be a binary search tree.
There must be no duplicate nodes.

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;

private class Node<AnyType>


{
private AnyType data;
private Node<AnyType> left, right;

public Node(AnyType data)


{
left = right = null;
this.data = data;
}
}
8 ...

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

before deletion after deletion

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

2 3 A non-recursive preorder traversal can be eloquently implemented in just three lines


of code. If you understand next()’s implementation above, it should be no problem
4 5 to grasp this one:
public AnyType next()
6 7 8 {
if (stk.isEmpty()) throw new java.util.NoSuchElementException();
Node cur = stk.pop();
if(cur.right != null) stk.push(cur.right);
if(cur.left != null) stk.push(cur.left);
return cur.data;
}
Note, we push the right child before the left child.
Level Order Traversal
Level order traversal processes the nodes level by level. It first processes the root,
and then its children, then its grandchildren, and so on. Unlike the other traversal
methods, a recursive version does not exist.
A traversal algorithm is similar to the non-recursive preorder traversal algorithm. The
only difference is that a stack is replaced with a FIFO queue.
PROGRAMMING AND DATA STRUCTURES S3-163
BINAR Y HEAP S
A binary tree is completely full if it is of height, h, and has 2h+1-1 nodes.
A binary tree of height, h, is complete iff
a. it is empty or
b. its left sub tree is complete of height h-1 and its right sub tree is completely full
of height h-2 or
c. Its left sub tree is completely full of height h-1 and its right sub tree is complete
of height h-1.
A complete tree is filled from the left:
all the leaves are on
• the same level or
• two adjacent ones and
All nodes at the lowest level are as far to the left as possible.
Heaps
A binary tree has the heap property iff
a. it is empty or
b. The key in the root is larger than that in either child and both sub trees have the
heap property.
A heap can be used as a priority queue: the highest priority item
is at the root and is trivially extracted. But if the root is deleted, we T
are left with two sub-trees and we must efficiently re-create a single
tree with the heap property.
The value of the heap structure is that we can both extract the S P
highest priority item and insert a new one in O(logn) time.
How do we do this?
Let’s start with this heap. G R O N
A deletion will remove the T at the root.
To work out how we’re going to maintain the heap property, use
the fact that a complete tree is filled from the left. So that the A E C A I M
position which must become empty is the one occupied by the M.
Put it in the vacant root position.

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

This tree is now a heap again, so we’re finished.


We need to make at most h interchanges of a root of a subtree with one of its children
to fully restore the heap property. Thus deletion from a heap is O(h) or O(logn).
Heap operations :
Both the insert and remove operations modify the heap to conform to the shape
property first, by adding or removing from the end of the heap. Then the heap
property is restored by traversing up or down the heap. Both operations take O(log n)
time.
Insert :
To add an element to a heap we must perform an up-heap operation (also known
as bubble-up, percolate-up, sift-up, trickle up, heapify-up, or cascade-up), by following
this algorithm:
1. Add the element to the bottom level of the heap.
2. Compare the added element with its parent; if they are in the correct order, stop.
3. If not, swap the element with its parent and return to the previous step.
The number of operations required is dependent on the number of levels the new
element must rise to satisfy the heap property, thus the insertion operation has a time
complexity of O(log n).
As an example, say we have a max-heap

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

We remove the 11 and replace it with the 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 û

Therefore, the cost of heapifying all subtrees is:


[lg n ]
n æ lg n h ö
å h+1 O (h) = O çnå
ç
÷
h +1 ÷
h= 0 2 è h= 0 2 ø

æ ¥ 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 */

Front Rear int main () {


double da, db;
// input da
p P db = foo (da);
}
double foo (double a) {
(a) Rear node return a;
(b) Front node The above code compiled without any error or warning. If
(c) Not possible with a single pointer (d) Line 1 is deleted, the above code will show
(d) Node next to front (a) no compile warning or error
4. Consider the following C program segment: [2005, 2 marks] (b) some compiler-warnings not leading to unintended
char p [20] results
char *s = “string”; (c) some compiler-warnings due to type-mismatch
int length = strlen (s); eventually leading to unintended results
for (i = 0; i < length, i++) (d) compiler errors
p[i] = s [length – i];
EBD_7203
S3-168 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
8. Consider the following C-program: [2005, 2 marks] (c) A pointer to a function that takes an integer pointer as
void foo (int n, int sum) { argument and returns an integer
int k = 0, j = 0 (d) A function that takes an integer pointer as argument
if (n = = 0) return; and returns a function pointer
k = n% 10, j = n/10; 14. Consider this code to swap integers and these five
sum = sum + k; statements:
foo (j, sum); The code [2006, 2 marks]
printf (“%d”, k);
} void swap (int *px, int *py) {
int main () { *px = *px – *py;
int a = 2048, sum = 0; *py = *px + *py;
foo (a, sum);
*px = *py – *px;
printf (“%d\n”, sum);
What does the above program print? }
(a) 8, 4, 0, 2, 14 (b) 8, 4, 0, 2, 0
(b) 2, 0, 4, 8, 14 (d) 2, 0, 4, 8, 0 S1 : will generate a compilation error
9. A program P reads in 500 integers in the range [0, 100] S2 : may generate a segmentation fault by runtime
representing the scores of 500 students. It then prints the depending on the arguments passed
frequency of each score above 50. What would be the best S3 : correctly implements the swap procedure for all input
way for P to store the frequencies? [2005, 1 mark] pointers referring to integers stored in memory locations
(a) An array of 50 numbers accessible to the process
(b) An array of 100 numbers S4: implements the swap procedure correctly for some but
(c) An array of 500 numbers not all valid input pointers
S5 : may add or subtract integers and pointers
(d) A dynamically allocated array of 550 numbers
(a) S1 only (b) S2 and S3
10. Which one of the following are essential features of an
(c) S2 and S4 (d) S2 and S5
object-oriented programming language? [2005, 1 mark] 15. Consider these two functions and two statements S1 and S2
1. Abstraction and encapsulation about them. [2006, 2 marks]
2. Strictly - typedness
3. Type-safe property coupled with sub-type rule int work1 (int*a, int i, int j)
4. Polymorphism in the presence of inheritance {
(a) 1 and 2 (b) 1 and 4 int x = a[i + 2];
(c) 1, 2 and 4 (d) 1, 3 and 4 a[j] = x + 1;
11. A common property of logic programming languages and return a[i + 2] – 3;
functional languages is [2005, 1 mark] }
(a) both are procedural languages
(b) both are based on l-calculus
(c) both are declarative int work2 {int *a, int i, int j)
(d) both use Horn-clauses {
int t1 = i + 2
12. An Abstract Data Type (ADT) is [2005, 1 mark] int t2 = a[t1]
(a) same as an abstract class a[j] = t2 + 1;
(b) a data type that cannot be instantiated return t2 – 3;
(c) a data type for which only the operations defined on it }
can be used, but none else
(d) All of the above S1: The transformation form work1 to work2 is valid, i.e., for
13. What does the following C-statement declare? any program state and input arguments, work2 will compute
int (*f) int*); [2005, 1 mark] the same output and have the same effect on program state
(a) A function that takes an integer pointer as argument as work 1.
and returns an integer S2: All the transformations applied to work1 to get work2 will
(b) A function that takes as argument and returns an integer always improve the performance (i.e., reduce CPU time) of
pointer work2 compared to work1
PROGRAMMING AND DATA STRUCTURES S3-169
(a) S1 is false and S2 is false }
(b) S1 is false and S2 is true int GetValue (struct CellNode *ptr) {
(c) S1 is true and S2 is false int value = 0
(d) S1 is true and S2 is true if (ptr ! = NULL)
16. Consider the following C-function in which a[n] and b[m] are if ((ptr - > leftChild = = NULL) &&
two sorted integer arrays and c[n + m] be another array. (ptr -> rightChild == NULL){
void xyz (int a [ ], int b [ ], int c [ ]) [2006, 2 marks] value = 1;
{ else
int i, j, k; value = value + GetValue (ptr -> leftChild)
i = j = k = 0; + GetValue (ptr -> rightChild);
while ((i < n) && (j < m)) }
if (a [i] < b [j] c [k++] = a[i++]; return (value);
else c[k++] = b[j++]; }
} The value returned by GetValue when a pointer to the root of
Which of the following conditions hold(s) after the a binary tree is passed as its argument is
termination of the while loop? (a) the number of nodes in the tree
(i) j < m, k = n + j – 1 and a [n – 1] < b[j], if i = n (b) the number of internal nodes in the tree
(ii) i < n, k = m + i – 1 and b [m – 1] £ a[i], if j = m (c) the number of leaf nodes in the tree
(a) only (i) (d) the height of the tree
(b) only (ii) 19. The inorder and preorder traversal of a binary tree are
(c) either (i) or (ii) but not both d b e a f c g and a b d e c f g, respectively
(d) neither (i) nor (ii) The postorder traversal of the binary tree is [2007, 2 marks]
17. An implementation of a queue Q, using two stacks S1 and S2 (a) d e b f g c a (b) e d b g f c a
is given below [2006, 2 marks] (c) e d b f g c a (d) d e f g b c a
void insert (Q, x) { 20. Consider the following C function: [2007, 2 marks]
push (S1, x); int f (int n)
} {static int r = 0;
void delete (Q) { if (n < = 0) return 1;
if (stack-empty (S2)) then if (n > 3)
if (stack-empty (S1)) then { {r = n;
print (“Q is empty”); return f (n – 2) + 2;
return; }
} return f(n – 1) + r;
else while (! (stack-empty (S1))) { }
x = pop (S1); What is the value of f(5)?
push (S2, x); (a) 5 (b) 7
} (c) 9 (d) 18
x = pop (S2); 21. The following postfix expression with single digit operands
} is evaluated using a stack: [2007, 2 marks]
Let n insert and m(£ n) delete operations be performed in an 823^/23*+51*-
arbitrary order on an empty queue Q. Let x and y be the Note that ^ is the exponentiation operator. The top two
number of push and pop operations performed respectively elements of the stack after the first * is evaluated are
in the process. Which one of the following is true for all m (a) 6, 1 (b) 5, 7
and n? (c) 3, 2 (d) 1, 5
(a) n + m £ x < 2n and 2m £ y £ n + m 22. Consider the following segment of C-code [2007, 1 mark]
int j, n;
(b) n + m £ x £ 2n and 2m £ y £ 2n j = 1;
(c) 2m £ x < 2n and 2m £ y £ n + m while (j < = n)
j = j*2;
(d) 2m £ x < 2n and 2m £ y £ 2n
The number of comparisons made in the execution of the
18. Consider the following C program segment where CellNode loop for any n > 0 is
represents a node in a binary tree: [2007, 2 marks]
(a) [log2 n] + 1 (b) n
struct Cell Node {
(a) [log2 n] (b) [log2 n] + 1
struct Cell Node *leftChild;
int element;
struct CellNode *rightChild;
EBD_7203
S3-170 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
23. The following C function takes a single-linked list of integers }
as a parameter and rearranges the elements of the list. The (a) 18 (b) 19
function is called with the list containing the integers 1, 2, 3, (c) 21 (d) 22
4, 5, 6, 7 in the given order. What will be the contents of the 26. Which combination of the integer variables x, y and z makes
list after the function completes execution? [2008, 2 marks] the variable a get the value 4 in the following expression?
struct node { a = (x > y)? ((x > z)? x : z) : ((y > z)? y : z) [2008, 1 mark]
int value; (a) x = 3, y = 4, z = 2
struct node *next; (b) x = 6, y = 5, z = 3
}; (c) x = 6, y = 3, z = 5
void rearrange (struct node *list){ (d) x = 5, y = 4, z = 5
struct node *p, *q; Statements for Linked Answer Questions 27, 28 and 29:
int temp;
Consider a binary max-heap implemented using an array:
if (!list | | !list -> next) return;
27. Which one of the following array represents a binary max-
p = list, q = list –> next;
heap? [2009, 1 mark]
while (q){
temp = p - > value; p -> value = q - > value; (a) {25, 12, 16, 13, 10, 8, 14}
q - > value = temp; p = q - > next; (b) {25, 14, 13, 16, 10, 8, 12}
q = p?p -> next: 0; (c) {25, 14, 16, 13, 10, 8, 12}
}
} (d) {25, 14, 12, 13, 10, 8, 16}
(a) 1, 2, 3, 4, 5, 6, 7 (b) 2, 1, 4, 3, 6, 5, 7 28. What is the content of the array after two delete operations
(c) 1, 3, 2, 5, 4, 7, 6 (d) 2, 3, 4, 5, 6, 7, 1 on the correct answer to the previous question?
24. Choose the correct option to fill ? 1 and ?2 so that the program [2009, 1 mark]
below prints an input string in reverse order. Assume that (a) {14, 13, 12, 10, 8} (b) {14, 12, 13, 8, 10}
the input string is terminated by a newline character. (c) {14, 13, 8, 12, 10} (d) {14, 13, 12, 8, 10}
void recerse (void){ [2008, 2 marks] 29. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an
int c; initially empty hash table of length 10 using open addressing
if (?1) reverse (); with hash function h(k) = k mod 10 and linear probing. What
?2 is the resultant hash table? [2009, 1 mark]
}
(a) 0 (b) 0
main ( ) {
printf(“Enter Text”); printf(“/n”); 1 1
reverse ( ); printf(“/n”) 2 2 2 12
(a) ?1 is (getchar ( )! = ‘\n’)
3 23 3 13
?2 is getchar (c);
4 4
(b) ?1 is (c = getchar ( ))! = ‘\n’)
?2 is getchar (c); 5 15 5 5
(c) ?1 is (c! = ‘\n’) 6 6
?2 is putchar (c); 7 7
(d) ?1 is (c = getchar ( ))! = ‘\n’) 8 18 8 18
?2 is putchar (c);
9 9
25. What is printed by the following C program? [2008, 2 marks]
int f (int x, int * py, int ** ppz)
{ (c) 0 (d) 0
int y, z; 1 1
**ppz + = 1; z = *ppz; 2 12 2 12, 2
*py + = 2; y = *py;
3 13 3 13, 3, 23
x + = 3;
4 2 4
return x + y + z;
} 5 3 5 5, 15
void main () 6 23 6
{ 7 5 7
int c, *b, **a, 8 18 8 18
c = 4; b & c; a = & b
9 15 9
printf(“%d”, f(c, b, a));
PROGRAMMING AND DATA STRUCTURES S3-171
30. What is the maximum height of any AVL-tree with 7 nodes? (a) 10 (b) 20
Assume that the height of a tree with a single node is 0. (c) 30 (d) 40
[2009, 1 mark] 34. The following program is to be tested for statement coverage.
(a) 2 (b) 3 begin [2010, 2 marks]
(c) 4 (d) 5 if (a = = b) {S1; exit;}
else, if (c = = d) {S2;}
31. Consider the program below: [2009, 1 mark]
else {S3; exit;}
#include < stdio.h >
S4;
int fun (int n, int * f_p){
end
int t, f;
if (n < = 1) { The test cases T1, T2, T3 and T4 given below are expressed
in terms of the properties satisfied by the values of variables
*f_p = 1
a, b, c and d. The exact values are not given.
return 1;
T1: a, b, c and d are all equal
}
T2: a, b, c and d are all distinct
t = fun (n – 1, *f_p);
T3: a = b and c! = d
f = t + *f_p;
*f_p = t; T4: a! = b and c = d
return f; Which of the test suites given below ensures coverage of
statements S1, S2, S3 and S4?
}
(a) T1, T2, T3 (b) T2, T4
int main () {
int x = 15; (c) T3, T4 (d) T1, T2, T4
printf (“% d\n”, fun (5, & x)); 35. The program below uses six temporary variables a, b, c, d, e,
f. [2010, 2 marks]
return 0;
a= 1
}
The value printed is b = 10
(a) 6 (b) 8 c = 20
(c) 14 (d) 15 d=a+b
Statements for Linked Answer Questions 32 and 33 : e=c+d
A hash table of length 10 uses open addressing with hash function f= c+ e
h(k) = k mod 10, and linear probing. After inserting 6 values into b=c+e
an empty has table, the table is as shown below. e=b+f
0 d=5+e
1 return d + f
2 42 Assuming that all operations take their operands from
registers, what is the minimum number of registers needed to
3 23
execute this program without spilling?
4 34
(a) 2 (b) 3
5 52
(c) 4 (d) 6
6 46 36. The following C function takes a simply-linked list as input
7 33 argument. It modifies the list as input argument. It modifies
8 the list by moving the last element to the front of the list and
returns the modified list. Some part of the code is left blank.
9
type def struct node { [2010, 2 marks]
32. Which one of the following choices gives a possible order in int value;
which the key values could have been inserted in the table? struct node *next;
(a) 46, 42, 34, 52, 23, 33 [2010, 2 marks] } Node*;
(b) 34, 42, 23, 52, 33, 46 Node *move_to_front (Node *head) {
(c) 46, 34, 42, 23, 52, 33 Node *p, *q;
(d) 42, 46, 33, 23, 34, 52 if (head = = NULL | | (head -> next = = NULL)) return head;
33. How many different insertion sequences of the key values q = NULL; p = head;
while (p - > next ! = NULL) {
using the same hash function and linear probing will result
q = p;
in the hash table shown above? [2010, 2 marks]
EBD_7203
S3-172 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
p = p - > next; 41. What is the return value of the function foo, when it is called
} as foo (513, 2)? [2011, 2 marks]
return head; (a) 9 (b) 8
} (c) 5 (d) 2
Choose the correct alternative to replace the blank line. 42. What is the return value of the function foo, when it is called
(a) q = NULL; p - > next = head; head = p; as foo (345, 10)? [2011, 2 marks]
(b) q - > next = NULL; head = p; p - > next = head; (a) 345 (b) 12
(c) head = p; p -> next = q; q -> next = NULL; (c) 5 (d) 3
(d) q-> next = NULL; p-> next = head; head = p; 43. Consider evaluating the following expression tree on a machine
37. What is the value printed by the following C program? with load store architecture in which memory can be accessed
#include < stdio.h> [2010, 2 marks] only through load and store instructions. The variables a, b, c,
int f (int *a, int n) d and e are initially stored in memory. The binary operators
{ used in this expression tree can be evaluated by the machine
if (n < = 0) return 0; only when the operands are in registers. The instructions
else if (*a % 2 = = 0) return *a + f(a + 1, n – 1); produce result only in a register. If no intermediate results can
else return *a – f(a + 1, n – 1); be stored in memory, what is the minimum number of registers
} needed to evaluate this expression? [2011, 2 marks]
int main () +
{
int a [ ] = {12, 7, 13, 4, 11, 6}; – –
print f (“%d, f(a, 6));
return 0, a
} b e +
(a) – 9 (b) 5
(c) 15 (d) 19 c d
38. Which languages necessarily need heap allocation in the (a) 2 (b) 9
runtime environment? [2011, 2 marks] (c) 5 (d) 3
(a) Those that support recursion 44. We are given a set of n distinct elements and an unlabelled
(b) Those that use dynamic scoping binary tree with n nodes. In how ways can we populate the
(c) Those that allow dynamic data structures tree with the given set so that it becomes a binary search tree?
(d) Those that use global variables (a) 0 (b) 1 [2011, 2 marks]
39. What does the following program print? [2011, 2 marks]
#include < stdio.h > 1 2n
(c) n! (d) Cn
void f (int *p, int *q) n +1
p = q; 45. Which of the given options provides the increasing order of
*p = 2; asymptotic complexity of functions f1, f2, f3 and f4?
} f1(n) = 2n, f2(n) = n 3/2, f3(n) = nlog2 n, f4(n) = n log2n
int i = 0, j = 1; [2011, 2 marks]
int main () { (a) f3, f2, f4, f1 (b) f3, f2, f1, f4
f(&i, &j);
printf(“%d%d/n”, i, j); (c) f2, f3, f1, f4 (d) f2, f3, f4, f1
} 46. Four matrices M1, M2, M3 and M4 are of dimensions p.q,
(a) 2 2 (b) 2 1 q.r, r.s and s.t respectively can be multiplied in several ways
(c) 0 1 (d) 0 2 with different number of total scalar multiplications. For
40. In a binary tree with n nodes, every node has an odd number example, when multiplied as (M1 × M2) × (M3 × M4) the total
of descendant. Every node is considered to be its own number of scalar multiplications, is pqr + rst + prt. When
descendant. What is the number of nodes in the tree that multiplied as (((M1 × M2) × M3) × M4) the total number of
have exactly one child? [2010, 1 mark] scalar multiplications is pqr + prs + pst. If p = 10, q = 100, r =
(a) 0 (b) 1 20, s = 5 and t = 80, then the minimum number of scalar
(c) (n – 1)/2 (d) n – 1 multiplications needed is [2011, 2 marks]
Common Data for Questions 41 and 42 (a) 248000 (b) 44000
Consider the following recursive C function that takes two (c) 19000 (d) 25000
arguments unsigned into foo (unsigned int, n, unsigned int r) { 47. What does the following fragment of C-program print?
if n > 0 return n% foo (n/r, r); char c[ ] = “GATE 2011” [2011, 1 mark]
else return 0, char * p = c;
} printf (“%s”, p + p[3] – p[1];
(a) GATE 2011 (b) E 2011
(c) 2011 (d) 011
PROGRAMMING AND DATA STRUCTURES S3-173
48. An algorithm to find the length of the longest monotonically 52. Consider the program given below, in a block-structured
increasing sequence of numbers in an array A[0 – n] is given pseudo-language with lexical scoping an nesting of
below. procedures permitted.
Let Li denotes the length of the longest monotonically Program main;
increasing sequence starting at index i in the array. Var ......
Initialize Ln–1 = 1 Procedure A1;
Var .....
For all i such that 0 £ i £ n - 2
Call A2;
ì1 + Li +1,if A [ i ] < A [ i + 1]ü End A1
Li = í ý Procedure A2;
î 1, otherwise þ Var ...
Finally the length of the longest monotonically increasing Procedure A21;
sequence is Max L, L, ... L. Var....
Which of the following statements is true? [2011, 1 mark] Call A1;
(a) The algorithm uses dynamic programming paradigm End A21
(b) The algorithm has a linear complexity and uses branch Call A21;
and bound paradigm End A2;
(c) The algorithm has a non-linear polynomial complexity Call A1;
and uses branch and bound paradigm End main.
(d) The algorithm uses divide and conquer paradigm. Consider the calling chain:
Main ® A1 ® A2 ® A21 ® A1
49. A max-heap is a heap where the value of each parent is greater
The correct set of activation records along with their access
than or equal to the value of its children. Which of the links is given by [2012, 2 marks]
following is a max-heap? [2011, 1 mark]
(a) (b) 10 53. Consider the directed graph shown in the figure below. There
10 are multiple shortest paths between vertices S and T. Which
8 6 one will be reported by Dijkstra’s shortest path algorithm’?
8 6 Assume that in any iteration, the shortest path to a vertex v
5 4 5 1 2 is updated only when a strictly shorter path to v is discovered.
4 2 [2012, 2 marks]
1 2
E 2
(c) 10 (d) 5 G
C 1
1
A 4 3
5 6 2 8 3
4 D 3
7 O
4 8 2 1 4 6 10 S 5 T
1 3 4
5
50. Let G be a weighted graph with edge weights greater than 3
B F
one and G be the graph constructed by squaring the weights (a) SDT (b) SBDT
of edges in G. Let T and T’ be the minimum spanning trees of (c) SACDT (d) SACET
G and G’ respectively, with total weights t and t’. Which of
the following statements is true? [2012, 2 marks] (a) Main (b)
Main
(a) T’ = T with total weight t’ = t2
(b) T’ = T with total weight t’ = t2 A1 A1
(c) T’ ¹ T but total weight t’ = t2 A2 A2
(d) None of the above
51. Suppose a circular queue of capacity (n – 1) elements is A21 A21
implemented with an array of n elements. Assume that the Prame
insertion and deletion operations are carried out using REAR
A1 Prame A1
pointer Access pointer Access
and FRONT as array index variables, respectively. Initially links links
REAR = FRONT = 0. The conditions to detect queue full and
(c) (d) Main
queue empty are [2012, 2 marks] Main
(a) full (REAR + 1) mod n = = FRONT
Prame A1 A1
empty: REAR = = FRONT pointer
(b) full (REAR + 1) mod n = = FRONT A2 A2
empty: (FRONT + 1) mod n = = REAR Access
(c) full (REAR = = FRONT A21 links A21
empty: (REAR + 1) mod n = = REAR Prame A1
(d) full (FRONT + 1) mod n = = REAR pointer Access
empty: (REAR = = FRONT links
EBD_7203
S3-174 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
54. The height of a tree is defined as the number of edges on the 58. What is the return value of f(p,p), if the value of p is
longest path in the tree. The function shown in the below in initialized to 5 before the call? Note that the first
invoked as height (root) to compute the height of a binary parameter is passed by reference, whereas the second
tree rooted at the tree pointer root. [2012, 2 marks] parameter is passed by value. [2013, 2 Marks]
{ if (n = = NULL) return – 1; int f (int &x, int c) {
if (n ® left = = NULL) c = c – 1;
if (n ® right = = NULL) return 0; if (c==0) return 1;
else return B1 ; // Box 1 x = x + 1;
return f(x,c) * x;
else {h1 = height (n ® left); }
if (n ® right = NULL) return (1 + h1); (a) 3024 (b) 6561
else {h2 = height (n ® right);
(c) 55440 (d) 161051
return B2 ; // Box 1
Common Data for Questions 59 and 60:
} The procedure given below is required to find and replace
} certain characters inside an input character string supplied in
} array A. The characters to be replaced are supplied in array
The appropriate expressions for the two boxes B1 and B2 are oldc, while their respective replacement characters are
(a) B1 : (1 + height (n ® right) supplied in array newc. Array A has a fixed length of five
B2 : (1 + max (h1, h2) characters, while arrays oldc and newc contain three
(b) B1 : (height (n ® right) characters each. However, the procedure is flawed.
B2 : (1 + max (h1, h2)
void find_and_replace (char *A, char *oldc,
(c) B1 : (height (n ® right)
char *newc)
B2 : max (h1, h2)
(d) B1 : (1 + height (n ® right) {
B2 : max (h1, h2) for (int i=0; i<5; i++)
for (int j=0; j<3; j++)
55. The number of elements that can be sorted in Q(log n) if (A[i]==oldc[j])
time using heap sort is [2013, 2 Marks] A[i] = newc[j];
(a) Q(1) (b) Q ( log n ) }
The procedure is tested with the following four test cases.
1. oldc = “abc”, newc = “dab”
æ log n ö 2. oldc = “cde”, newc = “bcd”
(c) Qç (d) Q(log n)
è log log n ÷ø 3. oldc = “bca”, newc = “cda”
4. oldc = “abc”, newc = “bac”
56. Consider the following function:
int unknown (int n) { 59. The tester now tests the program on all input strings of
int i, j, k=0; length five consisting of characters ‘a’, ‘b’, ‘c’,
for (i=n/2; i<=n; i++) ‘d’ and ‘e’ with duplicates allowed. If the tester carries
for (j=2; j<=n; j=j*2) out this testing with the four test cases given above,
k = k + n/2; how many test cases will be able to capture the flaw?
return (k); [2013, 2 Marks]
} (a) Only 1 (b) Only 2
The return value of the function is (c) Only 3 (d) All four
[2013, 2 Marks] 60. If array A is made to hold the string “abcde”, which of
2 2
(a) Q(n ) (b) Q(n log n) the above four test cases will be successful in exposing
(c) Q(n3) (d) Q(n3 log n) the flaw in this procedure? [2013, 2 Marks]
57. The pre-order traversal sequence of a binary search tree (a) 2 only (b) 4 only
is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the (c) 3 and 4 only (d) None
following is the post-order traversal sequence of the
same tree? [2013, 2 Marks] 61. Consider the following program in C language :
(a) 10, 20, 15, 23, 25, 35, 42, 39, 30 #include <stdio.h>
(b) 15, 10, 25, 23, 20, 42, 35, 39, 30 main ()
(c) 15, 20, 10, 23, 25, 42, 35, 39, 30 {
(d) 15, 10, 23, 25, 20, 35, 42, 39, 30 int i;
int *pi = &i;
scanf ("%d", pi);
PROGRAMMING AND DATA STRUCTURES S3-175
printf ("%d\n", i + 5); 65. Consider the function func shown below:
} int func(int num) {
Which one of the following statements is TRUE ? int count = 0;
[2014, Set-1, 1 Mark] while (num) {
(a) Compilation fails count++;
(b) Execution results in a run-time error. num>>= 1;
(c) On execution, the value printed is 5 more than the }
address of variable i. return (count);
(d) On execution, the value printed is 5 more than the }
integer value entered. The value returned by func (435) is __________.
62. There are 5 bags labeled 1 to 5. All the coins in a given bag [2014, Set-2, 1 Mark]
have the same weight. Some bags have coins of weight 10 66. Suppose n and p are unsigned int variables in a C program.
gm, others have coins of weight 11 gm. I pick 1, 2, 4, 8, 16 We wish to set p to nC3. If n is large, which one of the following
coins respectively from bags 1 to 5. Their total weight comes statements is most likely to set p correctly?
out to 323 gm. Then the product of the labels of the bags [2014, Set-2, 1 Mark]
having 11 gm coins is _____ . [2014, Set-1, 2 Marks] (a) p = n*(n–1)*(n–2) / 6;
63. Consider the following pseudo code. What is the total (b) p = n*(n–1) / 2*(n–2) / 3;
number of multiplications to be performed? (c) p = n*(n–1) / 3*(n–2) / 2;
[2014, Set-1, 2 Marks] (d) p = n * (n-1) * (n–2) / 6.0;
D=2 67. A priority queue is implemented as a Max-Heap. Initially, it
for i = 1 to n do has 5 elements. The level-order traversal of the heap is: 10,
for j = i to n do 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the
for k = j + 1 to n do heap in that order. The level-order traversal of the heap after
D = D*3 the insertion of the elements is: [2014, Set-2, 1 Mark]
(a) Half of the product of the 3 consecutive integers. (a) 10, 8, 7, 3, 2, 1, 5 (b) 10, 8, 7, 2, 3, 1, 5
(b) One-third of the product of the 3 consecutive integers. (c) 10, 8, 7, 1, 2, 3, 5 (d) 10, 8, 7, 5, 3, 2, 1
(c) One-sixth of the product of the 3 consecutive integers. 68. Consider the expression tree shown. Each leaf represents a
(d) None of the above. numerical value, which can either be 0 or 1. Over all possible
64. Consider the following C function in which size is the choices of the values at the leaves, the maximum possible
number of elements in the array E: value of the expression represented by the tree is ___.
int MyX(int*E, unsigned int size)
{
int Y = 0;
int Z;
int i, j, k;
for (i = 0; i < size; i++)
Y = Y + E[i];
for (i = 0; i < size; i++)
for (j = i; j < size; j++)
{
Z = 0; 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
for (k = i; k <= j; k++)
Z = Z + E[k]; [2014, Set-2, 2 Marks]
if (Z > Y) 69. Consider the following function
Y = Z; double f(double x){
} if( abs(x*x – 3) < 0.01) return x;
return Y; else return f(x/2 + 1.5/x);
} }
The value returned by the function MyX is the Give a value q (to 2 decimals) such that f(q) will return
[2014, Set-1, 2 Marks] q:_____. [2014, Set-2, 2 Marks]
(a) maximum possible sum of elements in any sub-array 70. Suppose a stack implementation supports an instruction
of array E. REVERSE, which reverses the order of elements on the stack,
(b) maximum element in any sub-array of array E. in addition to the PUSH and POP instructions. Which one
(c) sum of the maximum elements in all possible sub-arrays of the following statements is TRUE with respect to this
of array E. modified stack? [2014, Set-2, 2 Marks]
(d) the sum of all the elements in the array E.
EBD_7203
S3-176 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(a) A queue cannot be implemented using this stack. A [j] [i] = Temp – C;
(b) A queue can be implemented where ENQUEUE takes }
a single instruction and DEQUEUE takes a sequence for i = 1 to n do
of two instructions. for j = 1 to n do
(c) A queue can be implemented where ENQUEUE takes output (A [i] [j]);
a sequence of three instructions and DEQUEUE takes (a) The matrix A itself
a single instruction. (b) Transpose of the matrix A
(d) A queue can be implemented where both ENQUEUE (c) Adding 100 to the upper diagonal elements and
and DEQUEUE take a single instruction each. subtracting 100 from lower diagonal elements of A
71. Consider the C function given below. (d) None of the above
int f(int j) 73. The minimum number of arithmetic operations required to
{ evaluate the polynomial P(X) = X5 + 4X3 + 6X + 5 for a given
static int i = 50; value of X, using only one temporary variable is _____.
int k; [2014, Set-3, 1 Mark]
if (i == j) 74. Consider the following rooted tree with the vertex labeled P
{ as the root :
printf(“something”);
k = f(i);
P
return 0;
}
else return 0;
}
Q R
Which one of the following is TRUE?
[2014, Set-2, 2 Marks]
(a) The function returns 0 for all values of j.
(b) The function prints the string something for all values
of j. U V
(c) The function returns 0 when j = 50. T
S
(d) The function will exhaust the runtime stack or run into
an infinite loop when j = 50.
72. Let A be a square matrix of size n × n. Consider the following
pseudocode. What is the expected output ? W
[2014, Set-3, 1 Mark]
c = 100;
The order in which the nodes are visited during an in-order
for i = 1 to n do
traversal of the tree is [2014, Set-3, 1 Mark]
for j = 1 to n do
(a) SQPTRWUV (b) SQPTUWRV
{
(c) SQPTWUVR (d) SQPTRUWV
Temp = A [i] [j] + C;
A [i] [j] = A [j] [i];
PROGRAMMING AND DATA STRUCTURES S3-177

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

x 4 py 1000 ppz 2000 Replacing 16 by 8 After heapifying

5000 6000 7000 8 14


Now, considering
int y, z;
**ppy + = 1; z = *ppz = 6 14 12 13 12
*py + = 2; y = *py = 6
x=4+3=7 8
13 10 10
return x + y + z;
and 29. (c) 12 mod 10 = 2
c = 4; b & c; a = &b; 18 mod 10 = 8
printf (“%d”, f(c, b, a)), 13 mod 10 = 3
From the code, 2 mod 10 = 2 collision
The output is printed as 6 + 6 + 7 = 19. (2 + 1) mod 10 = 3 again collision
(using linear probing)
26. (a) The operator “?:” in C is the ternary operator which means
(3 + 1) mod 10 = 4
that, if the expression is exp 1? exp2 : exp3, so it means, if
3 mod 10 = 3 collision
exp1 is true then exp2 is returned as the answer else exp3
(3 + 1) mod 10 = 4 again collision
is the required answer.
(using linear probing)
So, in the given expression let us consider x = 3, y = 4,
(4 + 1) mod 10 = 5
z = 2,
23 mod 10 = 3 collision
Then, expression becomes a
(3 + 1) mod 10 = 4 collision
= (3 > 4)? ((3 > 2)? 3:2): ((4>2?4:2)
(4 + 1) mod 10 = 5 again collision
From this, we get that 3>4 is false so we go for the else
(using linear probing)
part of the statement which is 4>2 and is true thus, the
(5 + 1) mod 10 = 6
answer is 4, the true part of the statement.
5 mod 10 = 5 collision
27. (c) Suppose that we have a node x, then for the condition 1
(5 + 1) mod 10 = 6 again collision
< = x < = n/2 and A[x] > = A[2x + 1] where 2x and 2x + 1 are
(6 + 1) mod 10 = 7
left child and right child of the node x respectively of a
15 mod 10 = 5 collision
PROGRAMMING AND DATA STRUCTURES S3-191
(5 + 1) mod 10 = 6 collision 33. (c) In a valid insertion sequence, the elements 42, 23 and 34
(6 + 1) mod 10 = 7 collision must appear before 52 and 33, and 46 must appear before
(7 + 1) mod 10 = 8 collision 33.
(8 + 1) mod 10 = 9 collision Total number of different sequences = 3! x 5 = 30
So, resulting hash table In the above expression, 3! is for elements 42, 23 and 34
as they can appear in any order, and 5 is for element 46 as
0 it can appear at 5 different places.
1 34. (d) In a given program we take the test cases and apply.
2 12 First take T1, if all value equal means
a=b=c=d
3 13
So, due to T1, a = b condition satisfied and S1 and S4
4 2 executed.
5 3 So, from T2 when all a, b, c, d distinct.
6 23 S1, S2 not execute, S3 execute.
from T3 when a = b then, S1 execute but c = d so, S2 not
7 5
execute but S3 and S4 execute but we have no need of T3
8 18 because we get all result from above two.
9 15 By using T4. If a! = b and c = d
So, S1 not execute and S2 and S4 execute so all of S1, S2,
30. (b) AVL trees are binary trees with the following restrictions.
S3, S4 execute and covered by T1, T2 and T4.
1) the height difference of the children is at most 1.
2) both children are AVL trees 35. (b) Let AX, BX, CX be three registers used to store results
a of temporary variables a, b, c, d, e, f.
/ \ a(AX) = 1
/ \ b(BX) = 10
b c c(CX) = 20
/ \ / d(AX) = a(AX) + b(BX)
/ \ / e(BX) = c(CX) + d(AX)
f(AX) = c(CX) + e(BX)
d e g
b(BX) = c(CX) + e(BX)
/
e(BX) = b(BX) + f(AX)
/
d(CX) = 5 + e(BX)
h
return d(CX) + f(AX)
31. (b) The program calculates nth Fibonacci Number. The
Thus, only 3 registers can be used without any
statement t = fun ( n-1, fp ) gives the (n-1)th Fibonacci
number and *fp is used to store the (n-2)th Fibonacci overwriting of data.
Number. Initial value of *fp (which is 15 in the above 36. (d) When the while loop ends, q contains address of second
prgram) doesn't matter. Following recursion tree shows last node and p contains address of last node. So we
all steps from 1 to 10, for exceution of fun(5, &x). need to do following things after while loop.
(1) fun(5, fp) (i) Set next of q as NULL (q->next = NULL).
/ \ (ii) Set next of p as head (p->next = head).
(2) fun(4, fp) (10) t = 5, f = 8, *fp = 5 (iii) Make head as p ( head = p)
Step (ii) must be performed before step (iii). If we change
/ \
head first, then we lose track of head node in the original
(3) fun(3, fp) (9) t = 3, f = 5, *fp = 3
linked list.
/ \
37. (c) f() is a recursive function which adds f(a+1, n-1) to *a if
(4) fun(2, fp) (8) t = 2, f = 3, *fp = 2
*a is even. If *a is odd then f() subtracts f(a+1, n-1) from
/ \
(5) fun(1, fp) (7) t = 1, f = 2, *fp = 1 *a. See below recursion tree for execution of f(a, 6).
/ f(add(12), 6) /*Since 12 is first element. a contains address
(6) *fp = 1 of 12 */
32. (c) The sequence (A) doesn't create the hash table as the |
element 52 appears before 23 in this sequence. |
The sequence (B) doesn't create the hash table as the 12 + f(add(7), 5) /* Since 7 is the next element, a+1
element 33 appears before 46 in this sequence. contains address of 7 */
|
The sequence (C) creates the hash table as 42, 23 and 34
|
appear before 52 and 33, and 46 appears before 33.
7 - f(add(13), 4)
The sequence (D) doesn't create the hash table as the
|
element 33 appears before 23 in this sequence.
|
13 - f(add(4), 3)
|
EBD_7203
S3-192 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
| 44. (b) It is stated that there is a binary tree and we have populate
4 + f(add(11), 2) the tree with n elements. Sorting the n elements in the
| increasing order,and placing them in the inorder traversal
| nodes of the binarytree makes it only BST possible.
11 - f(add(6), 1) 45. (c) For n = 8
| f1(n) = 2n = 28 = 256
| f2(n) = n 3/2 = 83/2 = 8 ´ 8 ´ 8 = 8 × 2 2 = 16 2
6+0 f3(n) = n log2 n(= 8 log2 8 = 8 × 3 = 24
So, the final returned value is 12 + (7 - (13 - (4 + (11 -
f4(n) = n log 2 n = 8log2 8 = 83 = 64 × 8 = 512
(6 + 0))))) = 15
38. (c) linked data structures allow more flexibility in and the Þ f2, f3, f1, f4
implementation of these linked data structure is through 46. (c) M1 × M2 × M3
dynamic data structures For (M1 × M2) × M3 = (p × q × r) + (p × r × s)
39. (d) * p points to i and q points to j */ = (10 × 100 × 20) + (10 × 20 × 5)
void f(int *p, int *q) = 20000 + 1000 = 21000
{ M1 × (M2 × M3) = (p × q × s) + (q × r × s)
= (10 × 100 × 5) + (100 × 20 × 5)
p = q; /* p also points to j now */
M1 × (M2 × M3) < (M1 × M2) × M3
*p = 2; /* Value of j is changed to 2 now */ = (10 × 100 × 5) + (100 × 20 × 5)
} M1 × (M2 × M3) < (M1 × M2) × M3
40. (a) Such a binary tree is full binary tree (a binary tree where This, (M1 × (M2 × M3)) M4 = 15000 + p × s × t
every node has 0 or 2 children). = 15000 + 10 × 5 × 80
41. (d) = 15000 + 4000 = 19000
47. (c) 2011 charc[] = "GATE2011";
p now has the base address string "GATE2011"
char*p =c;
p[3] is 'E' and p[1] is 'A'.
p[3] - p[1] = ASCII value of 'E' - ASCII value of 'A' = 4
So the expression p + p[3] - p[1] becomes p + 4 which is
base address of string "2011
48. (a) The algorithm has dynamic programming paradigm as i
has been chosen randomly.
49. (b) A binary tree is max-heap if it is a complete binary tree (A
complete binary tree is a binary tree in which every level,
except possibly the last, is completely filled, and all nodes
are as far left as possible) and it follows the max-heap
property (value of each parent is greater than or equal to
the values of its children).
(a) is not a max-heap because it is not a complete binary
tree
(b) is a max-heap because it is complete binary tree
and follows max-heap property.
(c) is not a max-heap because 8 is a child of 5 in this
1+1=2 tree, so violates the max-heap property.
(d) is not a max-heap because 8 is a child of 5 in this
42. (b) tree, so violates the max-heap property. There are
many other nodes in this tree which violate max-
heap property in this tree.
50. (d) Squaring the weights of the edges in a weighted graph
will not change the minimum spanning tree. Assume the
opposite to obtain a contradiction. If the minimum
spanning tree changes then at least one edge from the
old graph G in the old minimum spanning tree T must be
replaced by a new edge in tree T' from the graph G' with
5 + 4 + 3 = 12 squared edge weights. The new edge from G' must have
43. (d) R1 ¬ c, R2 ¬ d, R2 ¬ R1 + R2, R1 ¬ e, R2 ¬ R1-R2 a lower weight than the edge from G. This implies that
Now to calculate the rest of the expression we must load there exists some weights C1 and C2 such that C1 < C2
a and b into the registers but we need the content of R2 and C12 >= C22. This is a contradiction.
later. Sums of squares of two or more numbers is always smaller
So we must use another Register. than square of sum.
R1 ¬ a, R3 ¬ b, R1 ¬ R1-R3, R1 ¬ R1+R2 Example: 22 + 22 < 42
PROGRAMMING AND DATA STRUCTURES S3-193
51. (a) FRONT points to the first element that we can remove
and then we increment FRONT REAR points to the first æ log n ö
empty space in queue so we insert an element and Hence, answer is (c) Q ç log log n ÷
è ø
increment REAR so now initially queue is empty F=R=0
insert A (AT 0th index) --> increment REAR (REAR =1 56. (b) The return value of the function is q (n2 log n)
FRONT=0) now if we want to delete A we have FRONT
pointing at that location so we delete A and increment n
The outer for loop goes + 1 iterations.
FRONT (REAR=1 FRONT=1 queue empty) 2
52. (d) Link to activation record of closest lexically enclosing The inner for loop runs independent of the outer
block in program text. It depends on the static program loop.
text
53. (d) Dijkstra's Algorithm picks nodes as follows: n
B(3) from S And for each inner iteration, gets added to k.
2
A(4) from S
C(5) from A n
E(6) from C \ × # outer loops × # inner loops per outer loop.
2
D(7) from S or B
G(8) from E # Inner loops = q (log n) [Q 2q(log n) = q (n)]
T(10) from D or E
n én ù
Thus the shortest path to T is SBDT, SDT or SACET. \ ´ ê + 1ú .q(log n) = q(n2 log n)
But because of "the shortest path to a vertex v is updated 2 ë2 û
only when a strictly shorter path to v is discovered", 57. (d)
when E is visited, T's prior node for the shortest path will 58. (b) Return value f (p, p) if the value of p is intialized to
be set as E and not changed again. 5 before the call.
Thus the answer is SACET.
Since, reference of p is passed as 'x'
54. (a) The box B1 gets executed when left subtree of n is NULL
and right sbtree is not NULL. In this case, height of n will Thus, any change in value of x in f would be
be height of right subtree plus one. reflected globally.
The box B2 gets executed when both left and right The recursion can be broken down as
subtrees of n are not NULL. In this case, height of n will 5 5
be max of heights of left and right sbtrees of n plus 1. f ( x, c )
55. (c) The number of elements that can be sorted in Q
6 4
æ log n ö x * f ( x, c )
(log n) time using heap sort is Q ç log log n ÷
è ø 7 3
Consider the number of elements is "k", which can x * f ( x, c )
be sorted in q (k log k) time. 8 2
Analyzing the options in decreasing order of x * f ( x, c )
complexity since we need a tight bound i.e., q.
9 1
æ log n ö x * f ( x, c )
i.e., q (log n), Q ç , Q( log n ), Q(1)
è loglog n ÷ø 59. (c) Analyzing the flow in the function. Fix an 'i' in the
So if k Î Q (log n) time required for heap sort is O outer loop.
(k log k) i.e., Suppose A[i] = old c[0], then A[i] is set to new c[0]
q (log n × log log n), But this is not in Q (log n) [j = 0].
Now suppose that old c[1]= new c[0]
æ log n ö Þ A[i] = old c[1] (after the j = 0th iteration)
If k Î Q ç log log n ÷ time required for Heap Sort
è ø which means in the next iteration with j = 1; A[i]
again gets changed form new c[0] (or old c[1]) to new
æ log n æ log n ö ö c[1] which is incorrect.
Qç ´ log ç ÷
è log log n è log log n ÷ø ø The current loop should "break" after a match is
found and A[i] is replaced.
æ é æ log n ö ùö The inner loop should look like
ç ê log ç ú÷ for (int j = 0; j < 3, j + +)
è log log n ÷ø ú÷
i.e., Q log n ´ ê
ç if (A [i] = = old c[j])
ç ê log log n ú÷
ê 1 424 3 ú÷ A[j] = new c [j];
ç
è êë £1 úûø break;
The above flow is exposed by the test cases 3 & 4
So, this is in Q (log n)
only. For test 1 and test 2, the expected output is
EBD_7203
S3-194 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
produced by the code. Multiplying these label numbers we get
Test 3 Expected A after replacements 1 × 3 × 4 = 12.
= "abcde" ® "acdde" 63. (c) One-sixth of the product of the 3 consecutive integers.
result from code = "abcde" ® "addde" 64. (a)
Test 4 Expected "abcde" ® "bacde" Clearly the code segment: for (i = 0; i < size; i + +) Y = Y + E
result form code "abcde" ® "abcde". [i]
\ Answer is 3 and 4 only (c) Computes the sum of all element in the array E.
60. (b) The FLAWS are identified by a test case of the Note : As the array E may contain negative elements, the
following kind. sum of elements of subarray of E may be greater than the
old c = O1 O2 O3 sum of all elements in the array E.
new c = n1n2n3 Now, comes the nested i, j, k loops:
‘i’ changes the starting of the subway.
æ n1 = O2 ö æ n2 = O3 ö ‘j’ changes the end position of the subarray.
with ç n ¹ n ÷ or ç n ¹
÷
n3 ø ‘k’ loop is used to compute sum of elements of the particular
è 1 2ø è 2
subarray.
Hence, the answer is (b) only two.
The sum of subarray is stored in z and is compared to the
1 (Q c = 0 in this call) earlier max sum Y. Finally the larger sum gets stored in Y.
\ Answer is = x4 * x * x * x. i = 0, j = 14
The final value of x = 9 i = 0, j = 2
\ 94 = 6561 i.e., Option (b) i = 0, j = 1
61. (d) We concentrate on following code segment: i = 0, j = 0
® int *Pi = & i ;
Nothing wrong as ‘Pi’ is declared as integer pointer 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
and is assigned the address of ‘i’ which is an “int”. size = 15
® scanf (“%d”, Pi); i = 2, j = 2
We know that scanf ( ) has two arguments: i = 2, j = 3
First is control string (“%d” in this case), telling it i = 2, j = 4
what to read from the keyboard. ..
Second is the address where to store the read item. ..
i = 2, j = 14 .
So, ‘Pi’ refers to the address of “i”, so the value
scanned by scanf ( ) will be stored at the address of This can be easily seen how sum of subarray is computed
‘i’. with different values of i and j.
Above statement is equivalent to: 65. 9
scanf (“%d”, & i); 435 Þ 110110011
Finally the best statement: num > > 1
printf (“%d\n”, i + 5); Thus a num is shifted one bit right every time while loop is
It prints the value 5 more than the value stored in i. executed.
So, the program executes successfully and prints the While loop is executed 9 times successfully, and 10th time
value 5 more than the integer value entered by the num is zero.
user. \ Count is incremented 9 times.
62. 12 66. (b) P = nC3
No. of Bag = 5 n(n - 1)(n - 2)
All coins in a bag have same weight. =
6
Labels: 1 2 3 4 5
If we multiply, n, (n – 1) and (n – 2) together, it may go
No. of coins 1 2 4 8 16 beyond the range of unsigned integer. (\ option (A)
and (D) are wrong)
As total weight is 323, the Bag with label 1 must contain
For all values of n, n(n – 1)/2 will always be an integer
coins of 11 gm to make the total odd.
If we remove it the remaining weight = 323 – 11 = 312 gm value
Label: 2 3 4 5 But for n(n – 1)/3, it is not certain.
Take options (b)
No. of coins: 2 4 8 16
Weights: (I): 10 11 11 10 n(n - 1) / 2 (n - 2) / 3
Total weight = (2 × 10) + (4 × 11) + (8 × 11) + (16 × 10) P= ´
P1 P2
= 20 + 44 + 88 + 160
= 312
So, label 1, 3, 4 contains coins of 11 gm.
PROGRAMMING AND DATA STRUCTURES S3-195
P1 will be having no error, thus P will be more accurate (iii) t = x2 (Retrieve x2 from memory)
Option (c) (iv) t = t * x (Evaluate x3 and store in memory)
(v) t = t * (x2 + 4) (Evaluate x3 (x2 + 4) and store in
n(n - 1) / 3 (n - 2) / 2
P= ´ memory)
P1 P2 (vi) t = 6 * x (Evaluate 6x and store in memory)
There is possibility of truncation in P1, the accuracy (vii) t = t + 5 (Evaluate (6x + 5) and store in memory)
of P is less (viii) t = t + x3 (x2 + 4) (Retrieve x2 (x2 + 4) from memory
and evaluate {x3 (x2 + 4) + 6x + 5}
10 For the above steps, total number of arithmetic operation
is 7
7 i.e., 4 multiplications and 3 additions.
8
67. (a) 74. (a) The in order transversal is as :
2 1 5 left, root, middle, right
3 \ Nodes are visited in SQPTRWUV order.

After insertion of elements, PRACTICE EXERCISE


level - order tansvasal is : 1. (d) BCPL: Basic Combined Programming Language primary
10, 8, 7, 3, 2, 1, 5 used for system software and called simply B.
68. 6 2. (a) Functions can return any type supported by C (except
for arrays and functions), including the pointers,
6 structures and unions
+ 3. (a) a preprocessor is a program that processes its input
data to produce output that is used as input to another
3 3 program. The output is said to be a preprocessed form
– of the input data, which is often used by some
+
subsequent programs like compilers
2 –1 2 4. (c) 5. (b)
1
+ – – + 6. (a) Blank space between the “.” (double quotes)
increments the length by ‘1’, ‘correct’ has length seven
1 1 0 1 1 0 1 1 and ‘correct string’ has length 14.
Hence option (a) is correct.
69. 1.72 to 1.74 7. (d) The C Preprocessor is a part of the C compilation
process that recognizes special statements, analyses
x 1.5 them (before compilation) and acts on them as required.
f(g) + q Þ + =x
2 x The preprocessor can be used to make programs more
efficient, more readable, and more portable to multiple
x2 + 3 systems.
Þ = x Þ x2 + 3 = 2 x2
2x 8. (c)
Þ x2 = 3 Þ x = 1.73 9. (d) enum keyword assigns the integer values in ascending
70. (c) The queue can be implemated where ENQUEUE takes order if not specified, here bethlehem will be assigned
a sequence of three instructions (reverse, push, zero, jericho will assigned ‘1’ nazareth is already ‘1’
reverse) and DEQUEUE takes a single instruction and then increasing ‘1’ we, get Jerusalem as ‘2’ hence
(pop). (d) is correct option.
71. (d) When j = 50, j (50), the function goes to an infinite 10. (c) The value of automatic variable that is declared but
loop by calling f(i) recursively for i = j = 50 not initialized can give garbage value although some
72. (a) For the given pseudo code, each element of the implementations or compilers give it default value as
upper triangle is interchanged by the corresponding zero, hence value is unpredictable.
11. (b) The given program fragment checks the condition
element in lower triangle and later the lower triangular
a = = b (a = 4, b = 6) hence condn becomes false and
element is interchanged by the upper triangular
returns zero.
once. Thus the final output matrix will be same as 12. (d) 13. (b)
that of input matrix A. 14. (d) int val [2] [4] = {1, 2, 3, 4, 5, 6, 7, 8} is a 2-dimensional
73. 7 array
P (x) = x5 + 4x3 + 6x + 5
= x3 (x2 + 4) + 6x + 5 1 2 3 4
Now using only one temporary variable ‘t’ 5 6 7 8
(i) t = x * x (Evaluate x2 and store in memory)
(ii) t = t + 4 (Evaluate (x2 + 4 ) and store in memory) treating the array declaration in the row-major ‘4’ comes
EBD_7203
S3-196 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
under the first row and fourth column which has the value in increment. So, to add a++ and ++b, use
index value val [0] [3] hence (d) is correct option. parenthesis or blanks to tokenize the way you intended.
15. (d) The standard recommends the implementations to 30. (a) Consider arr [10][12] here arr [5] is logically pointing to
accept at least 256 (ISO 14882, B.2), but they may the 6th row of the array this comes from the definition
support less or more: of the two-dimensional array.
16. (a) Of the option (a), (b), (c), (d) the array index value start 31. (c) The statement int*b corresponds to a integer pointer
from zero and ends with ‘g’, since array has only three which will contain address of some other variable.
elements, the remaining values are treated as zero or Similarly int **a will contain the address of some pointer
garbage value only option (a) is satisfying the variable which is linked any other variable holding any
condition. value (like int *b holding address of some variable)
17. (c) Here by using typedef we are making a new data type hence, it is semantically and syntactically correct.
of x having size equal to 10 bytes (size of one character 32. (d) **C = 5, essentially means a = 5, as can be seen with
is 1 byte). In x my Array (s) we are declaring my Array the following pictorial representation of the given
of size ‘5’ of the data type x hence size of my Array declarations.
becomes 5 × 10 = 50 bytes.
18. (d) Address Value Name
19. (d) If global variables are by default static then it means
100 4 a
that we would be able to access them in a single file.But
we can use global variables in different files as well.
20. (a) The procedure cannot change the variable or any of its 120 100 b
members.
21. (d)
22. (b) In the body of ‘main’ () the printf statement prints ‘tim” 135 120 c
followed by calling of the main () itself which in turn
again “tim” and call main () this process never ends 33. (d) If x is an array then ++X, X++, X*2 are trying to modify
and keeps on printing ‘tim’ the address (X represent the base address of array)
23. (c) Since ‘Madam’ is the required o/P, the function first (), which is illegal. While X + 1 is equivalent to * (X [0] +
should print ‘a’ call the function second (), that prints 1) hence it is legal.
the ‘d’ and print ‘a’ again. 34. (d) num[i] is same as *(num+i) and num[i ] is same as
Hence (c) is the correct option. *(&num[i]) , hence both b and c are correct
24. (b) For the option (b) only ‘a’ and ‘c’ are compared but not 35. (d) Choose the correct statements
‘b’ hence largest of there nos. is on consideration of We have seen how individual values (variables and
only a & c. pointers) can be passed to functions. Now let us see
25. (d) We have already seen examples of its use when we how we can pass an entire array to a function.
have defined functions that return no value, i.e. Suppose an array is defined as:
functions which only print a message and have no #define MAXSIZE 100
value to return. Such a function is used for its side int myarr[MAXSIZE];
effect and not for its value. In the function declaration In order to pass the array myarr to a function foonction
and definition, we have indicated that the function does one may define the function as:
not return a value by using the data type void to show int foonction ( int A[MAXSIZE] , int size )
an empty type, i.e. no value. Similarly, when a function
{
has no formal parameters, the keyword void is used in
the function prototype and header to signify that there ...
is no information passed to the function. }
26. (a) This given program will not compile successfully. The This function takes two arguments, the first is an array
scope of the variable ‘j’ is the single ‘printf’ statement of size MAXSIZE, and the second an integer argument
that follows it. So, the last statement that involves ‘j’ named size. Here this second argument is meant for
will complain about the undeclared identifier ‘j’. passing the actual size of the array. Your array can
27. (b) By default x will be initialized to 0. Since its storage hold 100 integers
class is static, it preserves its exit value (and forbids C++ does not allow to pass an entire array as an
reinitialization on re-entry). So, 123 will be printed. argument to a function. However, You can pass a
28. (b) The compiler will tokenize a +++b as a, ++, +, b. So, pointer to an array by specifying the array's name
a +++ b is equivalent to a +++b, which evaluates to 7. without an index.
29. (d) a +++++ b will be tokenized to a, ++, ++, ++, +, b. The If you want to pass a single-dimension array as an
compiler (parser), while grouping the tokens to argument in a function, you would have to declare
expression, finds the second ++, applied to a++, an function formal parameter in one of following three
integer. Since ++ and ++b operator needs address (i.e., ways and all three declaration methods produce similar
L-value), it will display the error message – Invalid I results because each tells the compiler that an integer
PROGRAMMING AND DATA STRUCTURES S3-197
pointer is going to be received. float b;
Way-1 };
Formal parameters as a pointer as follows: int main(){
void myFunction(int*param) struct name *ptr,p;
{ ptr=&p; /* Referencing pointer to memory
. address of p */
. printf("Enter integer: ");
. scanf("%d",&(*ptr).a);
} printf("Enter number: ");
Way-2 scanf("%f",&(*ptr).b);
Formal parameters as a sized array as follows: printf("Displaying: ");
void myFunction(int param[10]) printf("%d%f",(*ptr).a,(*ptr).b);
{ return 0;
. }
. In this example, the pointer variable of type struct name
. is referenced to the address of p. Then, only the
} structure member through pointer can can accessed.
Way-3 Structure pointer member can also be accessed using
Formal parameters as an unsized array as follows: -> operator.
void myFunction(int param[]) (*ptr).a is same as ptr->a
{ (*ptr).b is same as ptr->b
. 40. (c) r + = reading mode (only reading, writing possible).
. 41. (b) 42. (c)
. 43. (d) printf (“%d”, size of (“ ”));
} *size of (“ ”) is pointing to the integer equivalent of “
36. (d) We must associate a pointer to a particular type: You ” which is equal to ‘1’.
can't assign the address of a short int to a long Hence correct option is (d).
int.pointer is a variable and thus its values need to be 44. (a) printf (11%d”, (a ++)); this given statement post-
stored somewhere. increments ‘a’ which means ‘a’ is printed first then it
A pointer is definitely NOT an integer. is incremented.
37. (d) 45. (d) The function definition
find (int x, int y)
38. (a) a = .5, b = .7 then the first ‘if’ becomes false it goes to
{return ((x < y)? 0 : (x – y));}
‘else’ portion hence the result is “PSU”.
determines the greater between the two x and y and
39. (d) Pointers can be accessed along with structures. A
gives 0 if x is minimum else gives (x – y) as result.
pointer variable of structure can be created as below:
Now, the function call
struct name { (a, find (a, b))
member1; is a rested call. first it calculate find (a, b). Then it
member2; gives the minimum of two.
. Hence, it is used to find the minimum of a, b.
. 46. (d) The scanf function returns the number of successful
}; matches. i.e., 3 in this case. a, b and c.
-------- Inside function ------- 47. (b) The input is actually a/nb. Since we are reading only
struct name *ptr; two characters, only a and \ n will be read and printed.
Here, the pointer variable of type struct name is 48. (b) If y = 11, the expression 3* (y – 8)/9 becomes 3*3/9.
created. Which evaluates to 1. But the expression (y – 8) /9*3
Structure's member through pointer can be used in becomes 3/9*3, which evaluates to 0 (since 3/9 is 0).
two ways: 49. (c) 263 in binary form is 100000111. If one tries to print an
1. Referencing pointer to another address to access integer as a character, only the last 8 bits will be
memory considered – the rest chopped off. So, in this case the
2. Using dynamic memory allocation ASCII value of 00000111 (i.e., decimal 7) will be printed.
Consider an example to access structure's member Look in the ASCII table. It is ringing a bell!
through pointer. 50. (d) 9/5 yields integer 1. Printing 1 as a floating point number
#include <stdio.h> prints garbage.
struct name{
int a;
EBD_7203
S3-198 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
51. (d) Here the loop initializes with the printing of ‘c’ followed 72. (a)
by printing of ‘a’ then its prints ‘t’. after the first
iteration is over it prints ‘r’. then ‘a’ and then ‘t’.
This process continues.
hence o/p is catratratratrat....
52. (d) Initially i = 5 then ‘if’ condition is true and it returns to
main () without executing any other statement. Hence
nothing is printed.
53. (a) putchar (105) will print the ASCII equivalent of 105
i.e., ‘i’. The printf statement prints the current value of
i, i.e. 5 and then decrements it. So, h4 will be printed in
the next pass. This continues until ‘i’ becomes 0, at
which point the loop gets terminated.
54. (c) i + = 3 is equivalent to i = i + 3.
In the body of loop ‘p’ is incremented by ‘1’. Hence For one disk the steps involved is A->C ie 1 step
total of 4 is incremented overall in the current value of For two disks the steps involved are A->B,A->C,B-
‘i’. >C ie 3steps
hence 3 7 11 is printed.
For three disks the steps involved are A->C,A->
55. (a)
B,C->B,A->C,B->A,B->C,A->C ie 7steps
56. (d) The else clause has no brackets i.e., {and }. This means
For 4 disks the steps involved are A->B,A->C,B-
the else clause is made up of only one statement. So
printf (“a < = b”); will be executed anyway, i.e., if a > >C,A->B,C->A,C->B,A->B,A->C,B->C,B->A,C->A,B
b or a < = b. Hence. answer. >A,A-
57. (a) 58. (d) >B,A->C,B->C i.e. 15 steps
59. (a) For a given program fragment, gives the O/P as a So, for 1 disk 21 – 1 = 1
integer i.e. same as 8 * y. 2 disks 22 – 1 = 3
60. (d) The given ‘printf’ statement prints’ hello followed by / 3 disks 23 – 1 = 7
n (new line). ‘puts’ function can not print hello/n’ at 4 disks 24 – 1 = 15
the same time, using the single ‘puts’ function. n disks 2n – 1 (By induction)
61. (d) a[2] will be converted to * (a + 2). 73. (c) 20 20 10 10 20
* (a + 2) can as well be written as * (2 + 1). String Status of stack Status of
* (2 + a) is nothing but 2 [a]. So, a [2] is essentially array(output)
same as 2 [a], which is same as Push(10) 10
* (2 + a). So, it prints 9 + 9 = 18. Some of the modern Push(20) 10 20
compilers don’t accept 2[a]. Pop 10 20
62. (d) * a points to the string “abcd”. ** a is the first character
Push(10) 10 10 20
of “abcd”, which is the character ‘a’.
Push(20) 10 10 20 20
63. (a)
Pop 10 10 20 20
64. (b) 2 < 2 it conduction false so if go to else part and output
Pop 10 20 20 10
Z1 Z2.
Pop 20 20 10 10
65. (a)
Push(20) 20 20 20 10 10
66. (b) The function abc can be invoked as abc () or (*abc) ().
Pop 20 20 10 10 20
Both are two different ways of doing the same thing.
74. (d) 75. (c)
67. (a) It is not pointer so wer [1] = 162 and wer [1] + 1 = 162 76. (a) The binary representation of odd numbers will have a
+ 1 = 163. 1 as the least significant digit. So, an odd number
68. (b) 69. (d) ANDed with 1, produces a 1. Even number end with 0.
70. (a) character pointer can be assigned to a void pointer So, an even number Anded with 1, produces a 0. This
but reverse is not true. for loop generates even an d odd numbers
alternatively. So, it prints alternate 0’s and 1’s.
71. (a) The declaration char x [ ] = “success”; are equivalent 77. (a)
hence O/P of ‘puts (x)’ and ‘puts (y)’ will be the same.
PROGRAMMING AND DATA STRUCTURES S3-199
78. (c) In the given program fragment, the initialisation c = d
and d = a are invalid. Because it is trying to assign
+
pointer to the pointer.
79. (d) The macro call will be expanded as
sqrt (a + 2 * a + 2 + b + 3 * b + 3) – *
i.e. sqrt (3 * a + 4 * b + 5). Hence the answer.
80. (d) Array and pointer are same in implementation. By
using pointer we can access any of the index array.
Array is a constant pointer and pointer is a one a b c d
dimensional dynamic array.
81. (d) hence (a) is the correct option.
82. (d) 83. (d) 84. (b) 85. (d) 86. (b) 135. (d) Since the tree is used for sorting hence taking
87. (c) 263 in binary form is 100000111. If one tries to print an
integer as a character, only the last 8 bits will be INORDER TRAVERSAL (Left-Root-Right) we have 8
considered – the rest chopped off. So, in this case the placed at the left child of the node labeled 10.
ASCII value of 00000111 (i.e., decimal 7) will be printed. Hence (d) is the correct option.
Look in the ASCII table. It is ringing a bell! 136. (c) No. of possible binary search trees with n nodes =
88. (c) 89. (c) 90. (d) 2n C
91. (d) Let ab be O × MN. N & f should yield 7 i.e., N & 1111 n
should produce 0111. So, N should be 0111, i.e., 7. n +1 2 ´ 3C 6C
3
Similarly, M can be found to be 2. So, ab is 0 × 27. \ for 3 nodes = = 3 =5
92. (d) 93. (a) 94. (d) 95. (a) 96. (a) 3 +1 4
97. (c) 98. (d) 99. (c) 100. (b) 101. (a) 137. (c) Insertion sort in best case = O(n)
102. (b) 103. (c) 104. (a) 105. (b) 106. (a) and bubble sort = O(n2); selection sort = O(n2); merge
107. (d) 108. (a) 109. (a) 110. (d) 111. (a) sort = O (nlogn)
112. (a) 113. (c) 114. (a) 115. (a) 116. (a) 138. (b)
117. (b) 118. (c) 119. (c) 120. (b)
139. (b) Dijkstra’s algorithm solves single source shortest path
121. (c) 5 – 2 – 3 * 5 – 2 will yield 18, if it is treated as (5 – (2 –
3)) * (5 – 2). i.e., if – has precedence over* and if it problem.
associates from the right. Warshall’s algorithm finds transitive closure of a given
122. (a) 1112 graph.
In this program, We are calculating the adjacent Prim’s algorithm constructs a minimum cost spanning
difference of the given range by using function tree for a given weighted graph.
adjacent_difference.Output:$ g++ gnl.cpp$ a.out1 1 1 2 140. (b) 141. (a)
123. (c) 124. (d) 125. (a) 126. (a)
142. (d) In topological sorting we have to list out all the nodes
127. (b) 128. (d) 129. (d) 130. (b) 131. (c)
132. (c) 133. (a) in such a way that whatever there is an edge
134. (a) Post order traversal = ab – cd* + as we know that post connecting i and j, i should precede j in the listing. For
order traversal goes in the order of some graphs, this is not at all possible, for some this
LEFT CHILD ® RIGHT CHILD ® PARENT (ROOT) can be done in more than one way. Option (d) is the
only correct answer for this question.
143. (c) Each comparison will append one item to the existing
merge list. In the worst case one needs m + n – 1
1 comparisons which is of order m + n.
144. (b) It can be proved by induction that a strictly binary
2 3
tree with ‘n’ leaf nodes will have a total of 2n – 1
RC nodes. So, number of non-leaf nodes is (2n – 1) – n =
LC Root Root n – 1.
4 5 6 7 145. (b) 146. (d)
LC RC LC RC 147. (a) For sorting 200 names bubble sort makes 200 × 199/2 =
19900 comparisons. The time needed for 1 comparison
is 200 sec (approximately). In 800 sec it can make 80,000
comparisons. We have to find n, such that n(n – 1)/2
Hence, Label of 4, 5, 2 will be a, b, – respectively
= 80,000. Solving, n is approximately 400.
Label of 6, 7, 3 will be c, d, * respectively
148. (a)
Label of 1 will be +
149. (c) The corresponding expression is – (– a – b) + e!. This
is 1 if a = – b and e is either 1 or 0, since 1! = 0! = 1.
EBD_7203
S3-200 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
150. (a) 151. (b) 152. (a) and c take one of the 10 values, – 3, 6, 9, ..... 30,
153. 4 + 6 / 3 * 2 – 2 + (7 % 3) independent of the one another. So, there are 10 × 10
4 + (6/3)*2 – 2 + 1 × 10 = 1000 ways this can happen. Another possibility
4 + (2 * 2) – 2 + 1 is that a, b and c all leave a remainder 1 so that a + b +
(4 + 4) – 2 + 1 c is evenly divisible by 3. Considering all the different
8–2+1 possibilities and adding, we get 9000. That will be the
=7 integer that gets printed.
154. Step-1 157. (b) Total no of distict word can be 5.
i = 6720; j = 4; i % j = 0 because total no words starting with a would be 2.
(abc ,acb)
6720
i= = 1680 Total no of words starting with 2 (bca,bac)
4
Total no of words starting with c will be 1 (cba) because
j= 5 to print c as first letter we have to push a and b in
Step-2 stack
i = 1680; j = 5 i % j = 0 So total no of words formed = 2+2+1
i = 336; j = 6 158. (a) 25
Step-3 push(5)
i = 336; j = 6 i % j = 0 2. push(2)
i = 56; j = 7 3. m = 2;n=5 ;r=5*2
Step-4 4. push(r) /*push(10)*/
i = 56; j = y i % j = 0 5. push(3)
i = 8; j = 8 6. push(3)
Step-5 7. push(2)
i = 8; j = 8 i % j = 0 8. m=2; n= 3;r=3+2
i = 1; j = 9 9. push(r) /* push(5)*/
Step-6 10. r=5*3
i = 1; j = 9 i % j = 0 11. push(r) /*push(15)*/
hence on termination j = 9 12. m=15;n = 10;r=15+10
155. For each 8 bits one can save 1 bit. So percentage 13. push(r)
reduction will be 1/8* 100 i.e., 12.5% 14. printf(“%d”,pop());
156. a + b + c % 3 will be 0 if a + b + c is a multiple of 3. This Which will print 25
will happen in one of the following ways. All three – a,
b and c are multiples of 3. This can only happen if a, b
4
Page - 201 - 238

ALGORITHM ANALYSIS

C
Ø Analysis, Asymptotic Notation

Ø Notions of space and time complexity

O Ø Worst and average case analysis

N
Ø Design: Greedy approach, Dynamic programming,
Divide-and-conquer

Ø Tree and graph traversals

T Ø Connected components

E Ø

Ø
Spanning trees, Shortest paths

Hashing, Sorting, Searching

N Ø Asymptotic analysis (best, worst, average cases) of


time and space, upper and lower bounds

T Ø Basic concepts of complexity classes - P, NP,


NP-hard, NP-complete

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

we can go a giant step further: A precise count of the number a


of all operations is very cumbersome, if not impossible, and
since we are interested in the running time for large input
sizes, we may talk about the rate of growth or the order of b
growth of the running time. For instance, if we can come up n Best case
with some constant c > 0 such that the running time of an c
algorithm A when presented with an input of size n is at
Input size
most cn2, c becomes inconsequential as n gets bigger and
bigger. Furthermore, specifying this constant does not bring
about extra insight when comparing this function with Performance of insertion sort algorithm in worst, average
another one of different order, say dn3 for an algorithm B and best case.
that solves the same problem. To see this, note that the ratio WORST CASE ANALYSIS
between the two functions is dn/c and, consequently, the In worst case analysis of time complexity we select the maximum
ratio d/c has virtually no effect as n becomes very large. cost among all possible inputs of size n. As stated above, for any
The same reasoning applies to lower order terms as in the positive integer n, Algorithm Insertion sort requires W (n2) to
function f(n) = n2 log n + 10n 2 + n. Here, we observe that the process some inputs of size n (e.g. input a in Fig. ). For this reason,
larger the value of n the lesser the significance of the we say that the running time of this algorithm is W (n2), in the
contribution of the lower order terms 10n 2 and n. Therefore, worst case. Since the running time of the algorithm is W (n2) in the
we may say about the running times of algorithms A and B worst case we also say that the running time of the algorithm is O
above to be "of order" or "in the order of" n 2 and n3 , (n2) in the worst case. Consequently, we may use the stronger Q
respectively. Similarly, we say that the function f(n) above -notation and say that the running time of the algorithm is Q (n2)
is of order n2 log n. in the worst case. Clearly, using the Q-notation is preferred, as it
(b) Space Complexity gives the exact behaviour of the algorithm in the worst case. In
We define the space used by an algorithm to be the number other words, starting that Algorithm INSERTIONSORT has a
of memory cells (or words) needed to carry out the
ALGORITHM ANALYSIS S3-205
running time of Q (n2) in the worst case implies that it is also W 5. move y from Y to X.
(n 2 ) in the worst case, whereas stating that Algorithm 6. update the labels of those vertices in Y that are adjacent to y.
INSERTIONSORT runs in O (n2) in the worst case does not. Note 7. end while
that for any value of n there are input instances on which the
algorithm spends no more than O (n) time (e.g. input c in Fig. ). 1 ¥
It turns out that under the worst case assumption, the notions of 2 4
upper and lower bounds in many algorithms coincide and, 3
1 15
consequently, we may say that an algorithm runs in time Q (f(n)) 0 ¥
in the worst case. 1 9 4 13 6
Average case analysis (a)
In this method, it is necessary to know the probabilities of all 12 4
5
input occurrences, i.e., it requires prior knowledge of the input 3 5
distribution. However, even after relaxing some constraints 12 ¥
including the assumption of a convenient input distribution, e.g.
uniform distribution, the analysis is in many cases complex and
lengthy. 1 4
DESIGN: GREEDY APPROACH 2
3
1 15
Greedy algorithms are usually designed to solve optimization ¥
0
problems in which a quantity is to be minimized or maximized.
1 9 4 13 6
However, unlike dynamic programming algorithms, greedy
algorithms typically consist of an iterative procedure that tries to (b)
find a local optimal solution. In some instances, these local optimal 12 4
5
solutions translate to global optimal solutions. In others, they fail 3 5
to give optimal solutions. A greedy algorithm makes a correct 10 ¥
guess on the basis of little calculation without worrying about the
future. Thus, it builds a solution step by step.
1 4
The Shortest Path Problem
2 4
Let G = (V,E) be a directed graph in which each edge has a 3
1 15
non-negative length, and a distinguished vertex s called the 0 19
source. The single-source shortest path problem, or simply the 9 4
1 13 6
shortest path problem, is to determine the distance from s to every
other vertex in V , where the distance from vertex s to vertex x is (c)
12 5 4
defined as the length of a shortest path froms to x. For simplicity,
we will assume that V = {1, 2; : : : ; n} and s = 1. This problem can 3 5
be solved using a greedy technique known as Dijkstra's algorithm. 8 17
Initially, the set of vertices is partitioned into two sets X = {1} and
Y = {2, 3; : : : ; n}. The intention is that X contains the set of
1 4
vertices whose distance from the source has already been
determined. At each step, we select a vertex y Î Y whose distance 2
3
from the source vertex has already been found and move it to X. 1 15
0 19
Associated with each vertex y in Y is a label ¸[y], which is the
length of a shortest path that passes only through vertices in X. 1 9 4 13 6
Once a vertex y Î Y is moved to X, the label of each vertex w Y (d)
that is adjacent to y is updated indicating that a shorter path to w. 12 4
5
via y has been discovered. Throughout this selection, for any 3 5
vertex v Î V, d [v] will denote the distance from the source vertex 10 13
to v. As will be shown later, at the end of the algorithm, d [v] = l [v]
for each vertex v Î V. A sketch of the algorithm is given below..
1. X ¬ {1}; Y ¬ V – {1}
2. For each vertex v Î Y if there is an edge from 1 to v then let
l [v] (the label of v) be the length of that edge; otherwise let
l [v] = ¥ .
Let l [1] = 0
3. while Y ¹ {}
4. Let y Î Y be such that l [y] is minimum.
EBD_7203
S3-206 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
MINIMUM COST SPANNING TREES (KRUSKAL'S
1 4 ALGORITHM)
2 4 Let G = (V, E) be a connected undirected graph with weights on its
3
1 15 edges. A spanning tree (V, T) of G is a subgraph of G that is a tree.
0 17 If G is weighted and the sum of the weights of the edges in T is
(e) 1 9 4 13 6 minimum, then (V, T) is called a minimum cost spanning tree or
simply a minimum spanning tree.
12 4 We will assume throughout this section that G is connected. If G
5
3 5 is not connected, then the algorithm can be applied on each
8 13 connected component of G. Kruskal's algorithm works by
maintaining a forest consisting of several spanning trees that are
gradually merged until finally the forest consists of exactly one
1 4 tree: a minimum cost spanning tree. The algorithm starts by sorting
2 the edges in non-decreasing order by weight. Next, starting from
3 the forest (V, T) consisting of the vertices of the graph and none
1 15
0 17 of its edges, the following step is repeated until (V, T) is transformed
9 4 13 into a tree: Let (V, T) be the forest constructed so far, and let e Î E-
1 6
T be the current edge being considered. If adding e to T does not
(f) create a cycle, then include e in T; otherwise discard e. This process
12 4
5 will terminate after adding exactly n -1 edges. The algorithm is
3 5
summarized below.
8 13 1. Sort the edges in G by non-decreasing weight.
2. For each edge in the sorted list, include that edge in the
Fig 4 (a to f) : An example of Dijkstra's algorithm
spanning tree T if it does not form a cycle with the edges
IMPLEMENTATION OF SHORTEST PATH ALGORITHM currently included in T; otherwise discard it.
A more detailed description of the algorithm is given in Algorithm Example
dijkstra. We will assume that the input graph is represented by Consider the weighted graph shown in Fig. 5(a). As shown in Fig.
adjacency lists, and the length of edge (x; y) is stored in the vertex 5(b), the first edge that is added is (1, 2) since it is of minimum
for y in the adjacency list for x. We will also assume that the length cost. Next, as shown in Figs. 5(c)-(e), edges (1, 3), (4, 6) and then
of each edge in E is nonnegative. The two sets X and Y will be (5, 6) are included in T in this order. Next, as shown in Fig. 5(f), the
implemented as Boolean vectors X[1::n] and Y [1::n]. Initially, edge (2, 3) creates a cycle. and hence is discarded. For the same
X[1] = 1 and Y [1] = 0, and for all i,2 < = i < = n, X[i] = 0 and Y [i] = 1. reason, as shown in Fig. 5(g), edge (4, 5)is also discarded. Finally,
Thus, the operation X ¬ X È { y} is implemented by setting edge (3, 4) is included, which results in the minimum spanning
tree (V, T) shown in Fig. 5(h).
X[y] to 1, and the operation Y ¬ Y - { y} is implemented by
setting Y [y] to 0. 2 11 4
Algorithm DIJKSTRA 1 3
Input : A weighted directed graph G = (V, E), where V = {1, 2, ..., n}. 6 9 7
(a) 1 6
Output : The distance from vertex 1 to every other vertex in G.
1. X = {1}; Y ¬ V – {1}; l [1] ¬ 0 2 4
13
2. for y ¬ 2 to n 3 5
3. if y is adjacent to 1 then l [y] ¬ length [1, y]
4. else l [y] ¬ ¥
5. end if 2 4
6. end for 1
7. for j ¬ 1 to n – 1 (b) 1 6
8. Let y Î Y be such that l [y] is minimum
9. X ¬ X È { y} {add vertex y to X}
3 5
10. Y ¬ Y - { y} {delete vertex y from Y}
11. for each edge (y, w)
2 4
12. if w Î Y and l [y] + length [y, w] < l [w] then
1
13. l [w] ¬ l [y] + length [y, w]
14. end for (c) 1 6
15. end for
2
3 5
ALGORITHM ANALYSIS S3-207
7. Let (x, y) be the next edge in E.
2 4 8. if FIND (x) ¹ FIND (y) then
1 3 9. Add (x, y) to T
(d) 1 6 10. UNION (x, y)
11. end if
2 12. end while
3 5 Minimum Cost Spanning Trees (Prim's Algorithm)
As in the previous section, we will assume throughout this section
2 4 that G is connected. If G is not connected, then the algorithm can
1 3 be applied on each connected component of G.
This is another algorithm for finding a minimum cost spanning
(e) 1 6 tree in a weighted undirected graph that has a totally different
4 approach from that of Algorithm kruskal. Prim's algorithm for
2
3 5 finding a minimum spanning tree for an undirected graph is so
similar to Dijkstra's algorithm for the shortest path problem. The
algorithm grows the spanning tree starting from an arbitrary vertex.
2 4 Let G = (V, E), where for simplicity V is taken to be the set of
1 3 integers {1, 2, n} The algorithm begins by creating two sets of
6 vertices: X = {1} and Y = {2, 3, n} It then grows a spanning tree,
(f) 1 6
one edge at a time. At each step, it finds an edge (x; y) of minimum
2 4 weight, where x Î X and y Î Y and moves y from Y to X. This
3 5 edge is added to the current minimum spanning tree edges in T.
This step is repeated until Y becomes empty. The algorithm is
outlined below. It finds the set of edges T of a minimum cost
2 4 spanning tree.
1 3
1. T ¬ {}; X ¬ {1}; Y ¬ V – {1}
(g) 1 7 6 2. while Y ¹ {}
3. Let (x, y) be of minimum weight such that x Î X and y ÎY .
2 4
3 5 4. X ¬ X È { y}
5. Y ¬ Y - { y}
2 4 6. T ¬ T È {( x, y )}
1 3
7. end while
(h) 1 9 6
2 4
2 4 11 3
1
3 5
(a) 1 6 9 7 6
Fig 5(a to h) : An example of Kruskal's algorithm 2 13 4
Implementation of Kruskal's algorithm 3 5
First, the set of edges is sorted in non-decreasing order by weight.
Next n singleton sets are created, one for each vertex, and the set
of spanning tree edges is initially empty. The while loop is executed 2 4
11 3
until the minimum cost spanning tree is constructed. 1
ALGORITHM : KRUs KAL 6
(b) 1 9 7 6
Input : A weighted connected undirected graph G = (V, E) with n
vertices. 2 4
13
Output : The set of edges T of a minimum cost spanning tree for 3 5
G.
1. Sort the edges in E by non-decreasing weight.
2. for each vertex v ÎV
3. MAKESET ({v})
4. end for
5. T = {}
6. while|T| < n – 1
EBD_7203
S3-208 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
4. N [y] ¬ 1
2 4 5. C [y] ¬ c [1, y]
11 3 6. else C [y] ¬ ¥
1
7. end if
(c) 1 6 9 7 6 8. end for
4 9. for j ¬ 1 to n – 1 {find n – 1 edges}
2 13
3 5 10. Let y ÎY be such that C [y] is minimum
11. T ¬ T È {( y, N [ y ])} {add edge (y, N [y]) to T}

2 4 12. X ¬ X È { y} {add vertex y to X}


11 3
1 13. Y ¬ Y – {y} {delete vertex y from Y}
6 9 7 14. for each vertex w Î Y that is adjacent to y
(d) 1 6
15. if c [y, w] < C [w] then
2 13 4 16. N [w] ¬ y
3 5 17. C [w] ¬ c [y, w]
18. end if
19. end for
2 4 20. end for
11 3
1 Time Complexity: It follows that the time complexity of the
(e) 1 6 9 7 6 algorithm is
Q (m + n2) = Q (n2).
2 13 4 A linear time algorithm for dense graphs
3 5
Now we improve on Algorithm prim in order to lower its Q (n2)
time complexity to O(mlog n) for graphs . As in Algorithm shortest
path, the basic idea is to use the min-heap data structure to
2 4 maintain the set of bordering vertices so that the vertex y in Y
1 3 incident to an edge of lowest cost that is connected to a vertex in
V ---Y can be extracted in O(log n) time. The modified algorithm is
(f) 1 9 6 given as Algorithm mst.
Input: A weighted connected undirected graph G = (V, E), where
2 4
3 5 V = {1, 2, ..., n}.
Output : The set of edges T of a minimum cost spanning tree for
Fig. 6 (a to f) : Prim’s Algorithm G. Assume that we have an empty heap H at the beginning.
1. T ¬ {}; Y ¬ V – {1}
The vertices to the left of the dashed line belong to X, and those 2. for y ¬ 2 to n
to its right belong to Y . First, as shown in Fig. 6(a), 3 if y is adjacent to 1 then
X = {1}and Y = {2, 3, 6}. In Fig. 6(b), vertex 2 is moved from Y to X 4. N [y] ¬ 1
since edge (1, 2) has the least cost among all the edges incident to 5. key [y] ¬ c [1, y]
vertex 1. This is indicated by moving the dashed line so that 1 and 6. INSERT (H, y)
2 are now to its left. As shown in Fig. 6(b), the candidate vertices 7. else key (y) ¬ ¥
to be moved from Y to X are 3 and 4. Since edge (1; 3) is of least 8. end if
cost among all edges with one end in X and one end in Y , 3 is 9. end for
moved from Y to X. Next, from the two candidate vertices 4 and 5 10. for j ¬ 1 to n – 1 {find n – 1 edges}
in Fig. 6(c), 4 is moved since the edge (3; 4) has the least cost. 11. y ¬ DELETEMIN (H)
Finally, vertices 6 and then 5 are moved from Y to X as shown in 12. T ¬ T È {( y, N [ y ])} {add edge (y, N [y]) to T}
Fig. 6(e). Each time a vertex y is moved from Y to X, its 13. Y ¬ Y – {y} {delete vertex y from Y}
corresponding edge is included in T, the set of edges of the
14. for each vertex w Î Y that is adjacent to y
minimum spanning tree. The resulting minimum spanning tree is
15. if c [y, w] < key (w) then
shown in Fig. 6(f).
16. N [w] ¬ y
Implementation of Prim's algorithm
17. key (w) ¬ c [y, w]
Input: A weighted connected undirected graph G = (V, E), where
18. end if
V = {1, 2, ..., n}.
Output : The set of edges T of a minimum cost spanning tree for G. 19. if w Ï H then INSERT (H, w)
1. T ¬ {}; X ¬ {1}; Y ¬ V – {1} 20. else SIFTUP (H, H–1 (w))
2. for y ¬ 2 to n 21. end for
3 if y adjacent to 1 then 22. end for
The heap H initially contains all vertices adjacent to vertex
ALGORITHM ANALYSIS S3-209
1. Each vertex y ÎY is assigned a key which is the cost of the f(n) = f (n – 1) + f (n – 2)
edge connecting y to 1 if it exists; otherwise that key is set to ¥ . = 2 f (n – 2) + f (n – 3)
Each iteration of the for loop starts by extracting that vertex y with = 3 f (n – 3) + 2 f (n – 4)
minimum key. They key of each vertex w in Y adjacent to y is then = 5 f(n – 4) + 3 f(n – 5)
updated. Next, if w is not in the heap, then it is inserted; otherwise This leads to a huge number of identical calls. If we assume that
it is sifted up, if necessary. The function H–1 (w) returns the
position of w in H. This can be implemented by simply having an computing f(1) or f(2) requires a unit amount of time, then the time
array that has for its jth entry the position of vertex j in the heap. complexity of this procedure can be stated as
As in Algorithm SHORTESTPATH, the running time is dominated
by the heap operations. There are n – 1 DELETEMIN operations, ì 1 if n = 1or n = 2
n – 1 INSERT operations and at most m – n + 1 SIFTUP operations. T(n) = íT (n - 1) + T ( n - 2) if n ³ 3.
î
Each one of these operations takes O (log n) time using binary
heaps which results in O (m log n) time in total. The running time required to compute f(n) is exponential in the
If we use a d-heap, the running time is improved as follows. Each value of n. Anobvious approach that reduces the time complexity
DELETEMIN takes O (d logdn) time, and each INSERT or SIFTUP drastically is to enumerate the sequence bottom-up starting from
operation requires O (logdn) time. Thus, the total running time is f1 until fn is reached. This takes Q(n) time and Q(1) space; a
O (nd logd n + m logd n). If we choose d = [2 + m/n], the time bound substantial improvement.
becomes O (m log[2+m/n] n). If m ³ n1+e for some e > 0 that is not Matrix Chain Multiplication
too small, i.e., the graph is dense, then the running time is Suppose we want to compute the product M1M2M3 of three
O (m log [2+m/n]n) = O (m log [2+n]n) matrices M1, M2 and M3 of dimensions 2 × 10, 10 × 2 and
æ 2 × 10, using the standard method of matrix multiplication. If
log n ö
= çm ÷ we multiply M1 and M2 and then multiply the result by M3,
è log(2 + n)Î ø
the number of scalar multiplications will be 2 × 10 × 2 + 2 ×
æ log n ö 2 × 10 = 80. If, instead, we multiply M1 by the result of
= Oçm ÷ multiplying M2 and M 3 , then the number of scalar
è log nÎ ø
multiplications becomes 10 × 2 × 10 + 2 × 10 × 10 = 400. Thus,
æ mö carrying out the multiplication M1(M2M3) costs five times
= O çè ÷ø . the multiplication (M1M2)M3.
Î
Consider for example the brute-force method that tries to
DYNAMIC PROGRAMMING compute the number of scalar multiplications of every
This technique resorts to evaluating the recurrence in a possible order. For instance, if we have four matrices
bottom-up manner, saving intermediate results that are used later M1,M2,M3 and M4, the algorithm will try all the following
on to compute the desired solution. This technique applies to five orderings:
many combinatorial optimization problems to derive efficient (M1(M2(M3M4))),
algorithms. It is also used to improve the time complexity of the (M1((M2M3)M4)),
brute-force methods to solve some of the NP-hard problems. For ((M1M2)(M3M4)),
example traveling salesman problem can be solved in time O (n22n)
((M1M2)M3)M4)),
using dynamic programming, which is superior to the Q (n!) bound
((M1(M2M3))M4).
of the obvious algorithm that enumerates all possible tours. The
two simple examples that follow illustrate the essence of this design THE DYNAMIC PROGRAMMING ALGORITHM
technique.
In this figure, diagonal d is filled with the minimum costs of
Example : One of the most popular examples used to introduce
multiplying various chains of d + 1 consecutive matrices. In
recursion and induction is the problem of computing the Fibonacci
sequence: particular, diagonal 5 consists of exactly one entry which
f1 = 1; f2 = 1; f3 = 2; f4 = 3; f5 = 5; f6 = 8; f7 = 13; : : : : represents the minimum cost of multiplying the six matrices, which
Each number in the sequence 2; 3; 5; 8; 13; : : : is the the sum of the is the desired result. In diagonal 0, each chain consists of one
two preceeding, numbers. Consider the inductive definition of matrix only, and hence this diagonal is filled with 0's. We fill this
this sequence: triangular table with costs of multiplication diagonalwise, starting
if =
n 1or= at diagonal 0 and ending at diagonal 5. First, diagonal 0 is filled
ì 1 n 2
f(n) = í with 0's, as there are no scalar multiplications involved. Next,
î f ( n - 1) + f ( n - 2) if n ³ 3. diagonal 1 is filled with the costs of multiplying two consecutive
The definition suggests a recursive procedure that looks like the matrices. The rest of the diagonals are filled using the formula
following (assuming that the input is always positive).
stated above and the values previously stored in the table.
1. Procedure f (n)
Specifically, to fill diagonal d, we make use of the values stored in
2. if (n = 1) or (n = 2) then return 1
3. else return f(n – 1) + f(n – 2) diagonals{ 0; 1; 2; : : : ; d -1.}
To see this just expand the recurrence.
EBD_7203
S3-210 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
11. end for
d=0 d=1 d=2 d=3 d=4 d=5 12. end for
i 13. end for
14. return C [1, n]
C[1, 1] C[1, 2] C[1, 3] C[1, 4] C[1, 5] C[1, 6] 1
The All-Pairs Shortest Path Problem
Let G = (V, E) be a directed graph in which each edge (i, j) has a
C[2, 2] C[2, 2] C[2, 4] C[2, 5] C[2, 6] 2 non-negative length l [i, j]. If there is no edge from vertex i to
vertex j, then l [i, j] = ¥ . The problem is to find the distance from
3 each vertex to all other vertices, where the distance from vertex x
C[3, 3] C[3, 4] C[3, 5] C[3, 6] to vertex y is the length of a shortest path from x to y. For simplicity,
we will assume that V = {1, 2, ..., n}. Let i and j be two different
C[4, 4] C[4, 5] C[4, 6] 4 k
vertices in V. Define d i , j to be the length of a shortest path from
i to j that does not pass through any vertex in {k + 1, k + 2, ..., n}.
C[1, 1] C[1, 1] 5 Thus, for example, d i0, j = l [i, j], d i1, j is the length of a shortest
path from i to j that does not pass through any vertex except
C[6, 6] 6
possibly vertex 1, d i2, j is the length of a shortest path from i to j,
that does not pass through any vertex except possibly vertex
Fig 7. Matrix chain multiplication 1, d2i,j is the length of a shortest path from i to j that does not pass
As an example, the computation of C[2; 5] is the minimum of the throught any vertex except possibly vertex 1 or vertex 2 or both,
following three costs (see fig. 7):
(1) The cost of computing M2, 2 (which is 0) plus the cost of and so on. Then, by definition d in, j is the length of a shortest path
computing M3, 5 plus the cost of multiplying M2, 2 by M3, 5. from i to j. i.e., the distance from i to j. Given this definition, we can
(2) The cost of computing M2, 3 plus the cost of computing
M 4, 5 plus the cost of multiplying M2, 3 by M 4, 5. compute d ik, j recursively as follows :
(3) The cost of computing M2, 4 plus the cost of computing
ìïl[i, j ] if k = 0
M5, 5 (which is 0) plus the cost of multiplying M2, 4 by M5, 5.
d ik, j = í k -1 k -1 k -1 .
To complete any other entry C[i, j] in the table other than main ïîmin{di , j , di , j + di, j } if 1 £ k £ n
diagonal, we do the following. First, we draw two directed vectors
The following algorithm, which is due to Floyd, proceeds by
one from C[i, j] to C[i, j – 1] and one from C[i + 1, j] to C[j, j]. Next,
we complete the cost of multiplying each pair of matrices as we solving the above recurrence in a bottom-up fashion. It uses n +
follow the two arrows starting from the pair C[i, i] and C[i + 1, j] to 1 matrices D0;D1; : : : ; Dn of dimension n × n to compute the
the pair C[i, j – 1] and C[j, j]. Finally, we select the minimum cost lengths of the shortest constrained paths.
and store it in C[i, j]. Initially, we set D0 [i, i] = 0, D0 [i, j] = l [i, j] if i ¹ j and (i, j) is an
In general, multiplying a chain of n matrices gives rise to a edge in G; otherwise D0 [i, j] = ¥ . We then make n inerations such
triangular table of ‘n’ rows and n columns similar to the one shown that after the kth iteration, Dk [i, j] contains the value of a shortest
in Fig. 7. length path from vertex i to vertex j that does not pass through
The formal algorithm that produces such a table is given as in any vertex numbered higher than k. Thus, in the kth interation, we
below Algorithm.
compute Dk [i, j] using the formula
Input : An array r [1..n + 1] of positive integers corresponding to
Dk [i, j] = min {Dk–1 [i, j], Dk–1 [i, j] + Dk–1 [k, j]}.
the dimensions of a chain of n matrices, where r [1..n] are the
Algorithm Flyod
number of rows in the n matrices and r [n + 1] is the number of
columns in Mn Input : An n × n matrix l [1..n, 1..n] such that l [i, j] is the
Output : The least number of scalar multiplications required to length of the edge (i, j) in a directed graph G = ({1, 2, ..., n},
multiply the n matrices E).
1. for i ¬ 1 to n {Fill in diagonal d0} Output : A matrix D with D [i, j] = the distance from i to j.
2. C [i, i] ¬ 0 1. D¬l {copy the input matrix l into D}
3. end for 2. for k ¬ 1 to n
4. for d¬ 1 to n – 1 {Fill in diagonals d1 to dn–1} 3. for i ¬ 1 to n
5. for i ¬ 1 to n – d {Fill in entries in diagonal d1} 4. for j ¬ 1 to n
6. j¬i+d 5. D [i, j] = min {D [i, j], D [i, k] + D [k, j]}
7. comment: The next thee lines compute C [i, j] 6. end for
8. C [i, j] ¬ ¥ 7. end for
9. for k ¬ i + 1 to j 8. end for
10. C [i, j] ¬ min {C [i, j], C [i, k – 1] + C [k, j] + r [i] r [k] r [j + 1]}
ALGORITHM ANALYSIS S3-211
The Knapsack Problem 5. V [0, j] ¬ 0
The knapsack problem can be defined as follows. Let U = {u 1; u2; 6. end for
: : : ; un} be a set of n items to be packed in a knapsack of size C. 7. for i ¬1 to n
For 1 <j <n, let sj and vj be the size and value of the jth item, 8. for j ¬ 1 to C
respectively, where C and sj; vj ; 1 <j <n, are all positive integers. 9. V [i, j] ¬ V [i – 1, j]
The objective is to fill the knapsack with some items from U whose 10. if si £ j then V [i, j] ¬ max {V [i, j], V [i – 1, j – s1] + v1}
total size is at most C and such that their total value is maximum. 11. end for
Assume without loss of generality that the size of each item does 12. end for
not exceed C. More formally, given U of n items, we want to find a 13. return V [n, C]
subset S Ì U such that
DIVIDE AND CONQU ER
å vi In its simplest form, a divide-and-conquer algorithm divides the
ui ÎS problem instance into a number of subinstances, recursively
is maximized subject to the constraint solves each subsistences parately, and then combines the
solutions to the subinstances to obtain the solution to the original
å si £ C.
problem instance.
ui ÎS
Example: A straightforward algorithm might look like the one below.
This version of the knapsack problem is sometimes referred to in It returns a pair (x; y) where x is the minimum and y is the maximum.
the literature as the 0/1 knapsack problem. This is because the 1. x ¬ A[1]; y ¬ A [1]
knapsack cannot contain more than one item of the same type. 2. for i ¬ 2 to n
Another version of the problem in which the knapsack may contain 3. if A [i] < x then x ¬ A [i]
more than one item of the same type. 4. if A [i] > y then y ¬ A [i]
We derive a recursive formula for filling the knapsack as follows. 5. end for
Let V [i; j] denote the value obtained by filling a knapsack of size 6. return (x, y)
j with items taken from the first i items {u1; u2; : : : ; ui} in an Clearly, the number of element comparisons performed by this
optimal way. Here the range of i is from 0 to n and the range of j is method is 2n-2. However, using the divide and conquer strategy,
from 0 to C. Thus, what we seek is the value V [n;C]. Obviously, V we can find both minimum and maximum in only (3n/2) -2 element
[0; j] is 0 for all values of j, as there is nothing in the knapsack. On comparisons. The idea is very simple: Divide the input array into
the other hand, V [i; 0] is 0 for all values of since nothing can be two halves A[1…..n/2] andA[(n/2) + 1…n], find the minimum and
put in a knapsack of size 0. For the general case, maximum in each half and return the minimum of the two minima
when both i and j are greater than 0, we have the following and the maximum of the two maxima.
observation, which is easy to prove:
Observation: V [i; j] is the maximum of the following two quantities: BINARY SEARCH
• V [i – 1, j]; The maximum value obtained by filling a The algorithm is as follows
knapsack of size j with items taken from {u1, u2,..., ui–1} Input : An array A [1..n] of n elements sorted in non-decreasing
only in an optimal way. order and an element x.
• V [i – 1, j – si] + vi; The maximum value obtained by Output : j if x = A [j], 1 £ j £ n, and 0 otherwise.
filling a knapsack of size j – si with items taken from 1. binarysearch (1, n)
{u1, u2,..., ui–1} in an optimal way plus the value of Procedure binarysearch (low, high)
item ui. This case applies only if j ³ si and it amounts 1. if low > high then return 0
to adding item ui to the knapsack. 2. else
V [i, j] = 3. mid ¬ [(low + high)/2]
4. if x = A [mid] then return mid
ì0 if i = 0 or j = 0
ï 5. else if x < A [mid] then return binary search (low, mid–1)
V [i - 1, j ] if j < si
=í 6. else return binarysearch (mid + 1, high)
ïmax{V [i - 1, j ],V [i - 1, j - s ] + v } if i > 0and j ³ s 7. end if
î i i i
We will assume that each three-way comparison counts as one
Knapsack Algorithm comparison. First, note that if n = 0, i.e., the array is empty, then
Input : A set of items U = {u1, u2,..,un} with sizes s1, s2,..,sn and the algorithm does not perform any element comparisons. If n = 1,
values v1, v2,..,vn and a knapsack capacity C. the else part will be executed and, in case x ?A[mid], the algorithm
Output : The maximum value of the function å u Îs v1
i
subject to will recurse on an empty array. It follows that if n = 1, then exactly
one comparison is performed. If n >1, then there are two
å u Îs s1 £ C
i
for some subset of items S Í U . possibilities: If x = A[mid], then only one comparison is performed;
1. for i ¬ 0 to n otherwise the number of comparisons required by the algorithm is
2. V [i, O] ¬ 0 one plus the number of comparisons done by the recursive call on
3. end for either the first or second half of the array.
4. for j ¬ 0 to C Then C(n) can be expressed by the recurrence
EBD_7203
S3-212 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
The algorithm for such a traversal can be written using recursion
ì1 if n = 1
C (n) £ í as shown in Algorithm DFS or a stack.
î1 + C ([ n / 2]) if n ³ 2. Input : A (directed or undirected) graph G = (V, E).
Let k be such that 2k–1 £ n < 2k, for some integer k ³ 2. If we Output: Preordering and postordering of the vertices in the
expand the above recurrence, we obtain corresponding depth-first search tree.
C (n) £ 1 + C ([n / 2]) 1. predfn ¬ 0; postdfn ¬ 0
£ 2 + C ([n/4]) 2. for each vertex v ÎV
M 3. mark v unvisited
£ (k – 1) + C ([n/2k–1]) 4. end for
= (k – 1) + 1 5. for each vertex v ÎV
= k, 6. if v is marked unvisted then dfs(v)
since [[n/2]/2] = [n/4] etc. and [n –2k–1] = 1 7. end for
(since 2k–1 £ n < 2k). Taking the logarithms of the inequalities. Procedure dfs(v)
2k -1 £ n < 2k 1. mark v visited
and adding 1 to both sides yields 2. predfn ¬ predfn + 1
3. for each edge (v, w) Î E
k £ log n + 1 < k + 1. 4. if w is marked unvisited then dfs(w)
or 5. end for
k = [log n] + 1, 6. postdfn ¬ postdfn + 1
since k is integer. It follows that The case of undirected graphs
C (n) £ [log n] + 1. Let G = (V, E) be an undirected graph. As a result of the traversal,
We have, in effect, proved the following theorem : the edges of G are classified into the following two types:
In general, the divide and conquer paradigm consists of the Tree edges: edges in the depth-first search tree. An edge (V,W) is
following steps. a tree edge if w was first visited when exploring the edge (V,W).
(a) The divide step. In this step of the algorithm, the input is Back edges: All other edges
partitioned into p >1 parts, each of size strictly less than n,
the size of the original instance. The most common value of (a)
p is 2, although other small constants greater than 2 are not d a i
uncommon.
(b) The conquer step. This step consists of performing p
recursive call(s) if the problem size is greater than some c b g h
predefined threshold n0. This threshold is derived by
mathematical analysis of the algorithm. f j
e
(c) The combine step. In this step, the solutions to the p
recursive call(s) are combined to obtain the desired output.
GRAPH TRAVERSAL tree edges back edges
In some graph algorithms such as those for finding shortest paths
or minimum spanning trees, the vertices and edges are visited in (b) 1,10 a
an order that is imposed by their respective algorithms.
Depth-First Search
Let G = (V, E) be a directed or undirected graph. A depth first 2, 9 b
search traversal of G works as
follows. First, all vertices are marked unvisited. Next, a starting f
3,3 c
vertex is selected, say v Î V , and marked visited. Let w be any 6,8
vertex that is adjacent to v. We mark w as visited and advance to 7, 7 g
another vertex, sayx, that is adjacent to w and is marked unvisited.
Again, we mark x as visited and advance to another vertex that is
d 4, 2
adjacent to x and is marked unvisited. This process of selecting 8,6 h
an unvisited vertex adjacent to the current vertex continues as e 5, 1
deep as possible until we find a vertex y whose adjacent vertices
have all been marked visited. At this point, we back up to the most 9,5 i
recently visited vertex, say z, and visit an unvisited vertex that is
adjacent to z, if any. Continuing this way, we finally return back to
the starting vertex v. This method of traversal has been given the 10,4 j
name depth-first search, as it continues the search in the forward Fig 8 : An example of depth first search traversal of an
(deeper) direction. undirected graph
ALGORITHM ANALYSIS S3-213
Figure 8 (b) illustrates the action of depth-first search traversalon
the undirected graph shown in Fig. 8(a). Vertex a has been selected
1,4 a
as the start vertex. The depth-first search tree is shown in Fig. 8(b)
with solid lines. Dotted lines represent back edges. Each vertex in
the depth-first search tree is labeled with two numbers: predfn
and postdfn. Note that since vertex e has postdfn = 1, it is the first 2,3 b c 5,6
vertex whose depth-first search is complete. Note also that since (b)
the graph is connected, the start vertex is labeled with predfn = 1
and postdfn = 10, the number of vertices in the graph. e
The case of directed graphs
In depth-first search traversal of directed graphs, however, the 3,1
edges of G are classified into four types: 4,2 f d 6,5
• Tree edges: edges in the depth-first search tree. An
edge (v, w) is a tree edge if w was first visited when
exploring the edge (v, w).
• Back edges: edges of the form (v, w) such that w is an 1,4 a
ancestor of v in the depth-first search tree (constructed
so far) and vertex was marked visited when (v, w) was
explored. 2,2 f c 5,6
• Forward edges: edges of the form (v, w) such that w is
a descendant of v in the depth-first search tree (c)
(constructed so far) and vertex wwas marked visited
when (v, w) was explored. b
• Cross edges: All other edges. 4,3
Fig. 9 (b) illustrates the action of depth-first search traversal on
the directed graph shown in Fig. 9(a). vertex a, the vertices a, b, e 3,1 e d 6,5
and f are visited in this order. When Procedure dfs is initiated
again at vertex c, vertex d is visited and the traversal is complete Fig 9 : An example of depth-first search traversed of a
after b is visited from c. We notice that the edge (e, a) is a back directed graph.
edge since e is a descendant of a in the depth-first search tree, Time complexity of depth-first search
and (e, a) is not a tree edge. On the other hand, edge (a, f) is a Hence, the total number of times this step is executed is equal to
forward edge since a is an ancestor of f in the depth-first search the number of edges in the case of directed graphs and twice the
tree, and (a, f) is not a tree edge. Since neither e nor f is an ancestor number of edges in the case of undirect edgraphs. Consequently,
of the other in the depth-first search tree, edge (f, e) is a cross the cost of this step is Q (m) in both directed and undirected
edge. The two edges (c, b) and (d, e) are, obviously, cross edges; graphs. It follows that the running time of the algorithm is Q (m + n).
each edge connects two vertices in two different trees. Visiting If the graph is connected or m, n then the running time is simply Q
vertex b, both edges (a, b) and (a, f) would have been tree edges. (m).
In this case, the result of the depth-first search traversal is shown STRONGLY CONNECTED COMPONENTS
in Fig. 9.
Given a directed graph G = (V, E), a strongly connected component
in G is a maximal set of vertices in which there is a path between
(a) c b a each pair of vertices.
Algorithm
Input : A directed graph G = (V, E).
Output: The strongly connected components in G.
1. Perform a depth-first search on G and assign each vertex its
d e f
corresponding postdfn number.
2. Construct a new graph G' by reversing the direction of edges
tree edges forward edges in G.
back edges cross edges 3. Perform a depth first search on G' starting from the vertex
with highest postdfn number. If the depth-first search does
not reach all vertices, start the next depth-first search from
the vertex with highest postdfn number among the remaining
vertices.
4. Each tree in the resulting forest corresponding to a strongly
connected component.
If we reverse the direction of the edges in G, we obtain
EBD_7203
S3-214 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
G'which is shown in fig. 10(a). Starting from vertex c in G' a 4. v ¬ PoP (Q)
depth-first search traversal yields the tree consisting of 5. bfn ¬ bfn + 1
vertex c only. Similarly, applying depth-first search on the 6. for each edge (v, w) Î E
remaining vertices starting at vertex d results in the tree 7. if w is marked unvisited then
consisting of only vertex d. Finally, applying depth-first 8. Push (w, Q)
search on the remaining vertices starting at vertex a yields 9. mark w visited
the tree whose vertices are a, b, e and f. The resulting forest 10. end if
is shown in fig. 10(b). Each tree is the forcast corresponds 11. end for
to a strongly connected component. Thus G contains three 12. end while
strongly connected components. Fig. 11 illustrates the action of breadh-first search trasvers when
applied on the graph shown in fig. 8 starting from vertex a. After
(a) c b a popping of vertex a, vertices b and g are pushed into the queue
and marked visited. Next, vertex b is removed from the queue, and
its adjacent vertices that have not yet been visited, namely c and
f, are pushed into the queue and marked visited. This process of
pushing vertices into the queue and removing them later on is
d e f continued until vertex j is finally removed from the queue. At this
point, the queue becomes empty and the breadth-first search
tree edges back edges traversal is complete. In the figure, each vertex is labeled with its
bfn number, the order in which that vertex was removed from the
cross edges queue.

(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

T ( n ) £ 2T ( 4n / 5) + n Statements for Linked Answer Questions 34 and 35:


(c)
A sub-sequence of a given sequence is just the given sequence
(d) T ( n ) £ 2T ( n / 2 ) + n with some elements (possibly none or all) left out. We are given
28. G is a graph on n vertices and 2n – 2 edges. The edges of G two sequence X[m] and Y[n] of lengths m and n, respectively,
can be partitioned into two-edge-disjoint spanning trees. with indices of X and Y starting from 0.
Which of the following is not true for G? [2008, 2 marks] 34. We wish to find the length of the Longest Common Sub-
(a) For every subset of k vertices, the induced subgraph sequence (LCS) of X[m] and Y[n] as l(m, n), where an
has at most 2k – 2 edges incomplete recursive definition for the function l (i, j) to
(b) The minimum cut in G has at least two edges compute the length of the LCS of X[m] and Y[m] is given
(c) There are two edge-disjoint paths between every pair below
of vertices l(i, j) = 0 either i = 0 or j = 0
(d) There are two vertex-disjoint paths between every pair = expr 1, if i, j > 0 and X[i – 1] = [j – 1]
of vertices. = expr 2, if i, j > 0 and X[i – 1] = Y[j – 1]
29. A B-tree of order 4 is built from scratch by 10 successive Which one of the following options is correct?
insertions. What is the maximum number of node splitting (a) expr 1 º l (i – 1, j) + 1 [2009, 2 marks]
(b) expr 1 º l (i, j – 1)
operations that may take place? [2008, 2 marks]
(c) expr 2 º max {(l (i –1, j) , l (i, j – 1)}
(a) 3 (b) 4
(d) expr 2 º max {(l (i –1, j – 1) , l (i, j)}
(c) 5 (d) 6
35. The values of (i, j) could be obtained by dynamic programming
30. The minimum number of comparisons required to determined
based on the correct recursive definition of l (i, j) of the form
if an integer appears more than n/2 times in a sorted array of
given above, using an array L [M, N], where M = m + 1 and N
n integers is [2008, 2 marks]
= n + 1, such that L [i, j] = l (i, j).
(a) Q(n) (b) Q (log n)
Which one of the following statements would be true
(c) Q (log *n) (d) Q (1)
regarding the dynamic programming solution for the recursive
31. Consider the following functions:
definition of (i, j)? [2009, 2 marks]
f(n) = 2n
(a) All element L should be initialized to 0 for the values of
g(n) = n!
(i, j) to be properly computed
h(n) = n logn
(b) the values of l (i, j) may be computed in a row major
Which of the following statements about the asymptotic
order or column major order of L(M, N)
behaviour of f(n), g(n) and h(n) is true? [2008, 2 marks]
(c) the values of l (i, j) may be computed in a either row
(a) f(n) = O(g(n)); g(n) = O(h(n))
major order or column major order of L (M, N)
(b) f(n) = W(f(n)); g(n) = O(h(n))
(d) L[p, q] needs to be computed before L[r, s] if either
(c) g(n) = O(f(n)); h(n) = O(f(n))
p < r or q < s
(d) h(n) = O(f(n)); g(n) = W(f(n))
36. Consider the following statements about the cyclomatic
32. The Breadth First Search algorithm has been implemented complexity of the control flow graph of a program module.
using the queue data structure. One possible order of visiting Which of these are true? [2009, 2 marks]
the nodes of the following graph is [2008, 1 mark] I. The cyclomatic complexity of a module is equal to the
M N O maximum number of linearly independent circuits in
the graph.
II. The cyclomatic complexity of a module is the number
of decisions in the module plus one, where a decision
is effectively any conditional statement in the module.
III. The cyclomatic complexity can also be used as a
R Q P number of linearly independent paths that should be
(a) MNOPQR (b) NQMPOR tested during path coverage testing.
(c) QMNPRO (d) QMNPOR (a) I and II (b) II and III
33. The most efficient algorithm for finding the number of (c) I and III (d) I, II and III
connected components in an undirected graph on n vertices 37. In quick sort, for sorting n elements, the (n/4) the smallest
and m edges has time complexity [2008, 1 mark] element is selected as pivot using an O(n) time algorithm.
(a) Q (n) (b) Q (m) What is the worst case time complexity of the quick sort?
[2009, 2 marks]
(c) Q (m + n) (d) Q (mn)
(a) q (n) (b) q (n log n)
(c) q (n2) (d) q (n2 log n)
ALGORITHM ANALYSIS S3-223

38. Consider the following graph: [2009, 2 marks] of the algorithm?


(a) Q(n) (b) Q(n log n)
b e (c) Q(n ) 2 (d) Q(n2 log n)
2 5
5 41. Let pA be a problem that belongs to the class NP. Then,
6 6 which one of the following is true? [2009, 1 mark]
a d 3 g (a) There is no polynomial time algorithm for pA
6 (b) If pA can be solved deterministically in polynomial time,
5 4
3 then P = NP
c f
6 (c) If pA is NP-hard, then it is NP-complete
(d) pA may be undecidable
Which one of the following is not the sequence of edges 42. Which of the following statements is/are correct regarding
added to the minimum spanning using Kruskal’s algorithm? Bellman-Ford shortest path algorithm?
(a) (b, e) (e, f) (a, c) (b, c) (f, g) (c, d) P. Always finds a negative weighted cycle, if one exists.
(b) (b, e) (e, f) (a, c) (f, g) (b, c) (c, d) Q. Finds whether any negative weighted cycle is reachable
(c) (b, e) (a, c) (e, f) (b, c) (f, g) (c, d) from the source. [2009, 1 mark]
(d) (b, e) (e, f) (b, c) (a, c) (f, g) (c, d) (a) P only (b) Q only
39. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an (c) Both P and Q (d) Neither P nor Q
initially empty hash table of length 10 using open addressing 43. What is the number of swaps required to sort n elements
using selection sort, in the worst case? [2009, 1 mark]
with has function h(k) = k mod 10 and linear probing. What is
(a) q (n) (b) q (n log n)
the resultant has table? [2009, 2 marks]
(c) q (n2) (d) q (n2 log n)
Common Data for Questions 44 and 45
(a) 0 (b) 0
Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}.
1 1 Entry Wij in the matrix W below is the weight of the edge {i, j}
2 2 2 12
3 23 3 13 æ 0 1 8 1 4ö
ç ÷
4 4 ç 1 0 12 4 9÷
5 15 5 5 ç 8 12 0 7 3÷
6 6 W= ç 1 4 7 0 2÷
÷
ç
7 7 ç 4 9 3 2 0 ÷ø
è
8 18 8 18
9 9 44. What is the minimum possible weight of a spanning tree T in
this graph such that vertex 0 is a leaf node in the tree T?
[2010, 2 marks]
(c) 0 (d) 0 (a) 7 (b) 8
1 1 (c) 9 (d) 10
2 12, 2 45. What is the minimum possible weight of a path P from vertex
2 12
13, 3, 1 to vertex 2 in this graph such that P contains at most 3
3 13 3 edges? [2010, 2 marks]
23
(a) 7 (b) 8
4 2 4
(c) 9 (d) 10
5 3 5 5, 15
46. Two alternative packages A and B are available for processing
6 23 6 a database having 10k records. Package A requires 0.0001 n2
7 5 7 time units and package B requires 10n log10n time units to
8 18 8 18 process n records. What is the smallest value of k for which
9 15 9 package B will be preferred over A? [2010, 1 mark]
(a) 12 (b) 10
40. The running time of an algorithm is represented by the (c) 6 (d) 5
following recurrence relation [2009, 2 marks]

ì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 C 27. A priority-queue is implemented as a max-heap. Initially, it


has 5 elements. The level-order traversal of the heap is given
below.
Two new elements 1 and 7 are inserted in the heap in that
order. The level-order traversal of the heap after the insertion
B D of the element is
ALGORITHM ANALYSIS S3-227

(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

Since there is no - ve cycle so Dijkstra gives correct


5
22. (c) This is a formula to calculate the total number of nodes. result for all vertices.
It is 2h + 1 – 1. 26. (b) W is an integer so the time taken by the algorithm is
Let consider some examples to prove this.
Q (n) only. Since subset problem is NP complete, it
1. Simplest could be taking the binary tree of h (height)
= 0. should be in class NP & NP hard, so option (C) & (D)
Now, the binary tree of height h will have only 1 node. are true.
Using unary integer the algorithm will be solved in Q (n)
time but using binary it would take more time depending
Using formula 2 ^ (0 + 1) – 1 = 1. Hence, the formula is
correct. upon no. of bits.
2. Binary tree of h (height) = 2 27. (b) Pivot element is found in Quick sort in every iteration
all the elements to its left are smaller than & all in the
1 right are greater than it. So if 1/5th of sorted sequence
is the pivot. So sequence is divided into 1/5th & 4/5th
2 3 of the sequence. So recursion will be
T(n) = T(n/5) + T(4n/5) + n
7 28. (d) Consider this graph with n = 4
4 5 6
Using formula 2 ^ (2 + 1) – 1 = 7. Hence, the formula is
correct.
23. (b) Heaps are implemented as simple arrays, to insert n
more elements each element take Q(1) time. So total
time would be Q(n).
24. (b) To construct a BST from post order we also require
in-order traversal since given the elements are 1 2.......n Two spanning trees
EBD_7203
S3-232 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

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

search here efficiently. In BS the size of array required


to compare reduces by n/2 in every iteration.
Here since the sequence is sorted so the same element
R Q P
would come Consecutive.
31. (d) Since
f(n) = 2n 33. (c) The algorithm we use for finding the number of
g(n) = n! connected components in an undirected graph on n
h(n) = n logn vertices is to calculate articulation point detection
It can also be shown as algorithm.
f(n) = O (2n) This articulation point divides the graph into 2
g(n) = O(n!)
h(n) = O (nlogn) connected components.
Now, Complexity of this algorithm is same as 1 DFS run
As per the asymptotic order of function n log n £ C2 n 0(m + n) since
for all n ³ n 0 DFS is the basis of articulation point.
Let us assume C = 1 and n 0 = 2 34. (c) LCS problem is solved using dynamic programming in
It comes out to be 2 log 2 ³ 22 which every row is dependent upon previous rows &
® h(n) = O(f(n)) ® one result
columns. If two literals at ith row & jth column doesn’t
Now,
g(n) = n! & f(n) = 2n match then.
As per the asymptotic order of function
ALGORITHM ANALYSIS S3-233

Eve fill l[i, j] with max [L[i–1,j],[I ,j –1]] i.e max of


previous cell in row & column.
So expr 1 =L[i–1, j–1]+1
(c)
expr 2 =max([l[i–1,j],L[i,j –1]])
35. (d) During solution through dynamic programming option
(B) & (C) are incorrect since the solution is done in row
major order. But not in column major order.
(A) is true but not necessary.
(D) is correct eg. (d)
L[4, 5] require
L[3, 4]L[3, 5] here (3, 4), (3, 5) & (4, 4)
L[4, 4]L[4, 5] need to be calculated before [4, 5]
(A, C) can’t be taken after (B, C).
So L[p, q] required to be calculated before L[r, s] if
Hence (D) is correct option.
p < r or q < s. 39. (c) Enter the keys and check if the collision occurs. If the
36. (b) Statement I is incorrect. collision occurs then at what point.
The cyclomatic complexity of the module is not equal Key 12
to maximum number of linearly independent circuits in 12 mod 10 = 2
the graph. Key 18
Statement II is correct. 18 mod 10 = 8
The cyclomatic complexity of a module is the number Key 13
of decisions in the module plus one, where a decision 13 mod 10 = 3
is effectively any conditional statement in the module. Key 2
Statement III is correct. 2 mod 10 = 2 ® Collision occurred
The cyclomatic complexity can also be used as a (2 + 1) mod 10 = 3 ® Collision
number of linearly independent paths that should be (3 + 1) mod 10 = 4
tested during path coverage testing. Key 3
37. (b) Pivot in guide sort is the index which is sorted in that 3 mod 10 = 3
run, all the elements in its left are smaller than it & (3 + 1) mod 10 = 4 ® Collision
elements greater than it are on its right side. (4 + 1) mod 10 = 5
Key 23
So the recursion becomes. 23 mod 10 = 3 ® Collision
T(n) = T(n/4) + T(3n/4) + n (3 + 1) mod 10 = 4 ® Collision
Solution to this recursion is Q (nlogn) (4 + 1) mod 10 = 5 ® Collision
38. (d) Kruskal’s algorithm, arranging edges in ascending (5 + 1) mod 10 = 6
Key 5
order. 5 mod 10 = 5 ® Collision
{2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6} (5 + 1) mod 10 = 6 ® Collision
(6 + 1) mod 10 = 7
Key 15
15 mod 10 = 5 ® Collision
(5 + 1) mod 10 = 6 ® Collision
(a) (6 + 1) mod 10 = 7 ® Collision
(7 + 1) mod 10 = 8 ® Collision
(8 + 1) mod 10 = 9
This gives us the following has table
0
1
2 12
3 13
4 2
(b) 5 3
6 23
7 5
8 18
9 15
EBD_7203
S3-234 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

40. (a) For n < = 3 T(n) = n t 5 x


i.e Q (n) 6 4
6 –2
For n > 3 –3
T(n) = T(n/3) + Cn
This can be solved by Master’s Theorem s 0 8 –4 7
a = 1 b = 2 logba = log31= 0 2
f (n) = Cn 7 2, t
7, s
n logba < f(n) 9
n0 < f(n) y z
So, T (n) = q(f(n)) case III After pass 3
= q(Cn) The order of edges examined in each pass
= q(n) (t, x), (t, z), (x, t), (y, x), (y, t), (y, z), (z, x), (z, s), (s, t),
Whole complexity ¥ n (s, y).
T(n) =Q(n)+Q(n) 43. (c) In selection sort the worst case would be when the
= q(n) elements are reverse sorted, here the algorithm selects
Hence (a) is correct option. the min element the first element, and during linear scan
41. (c) Problems which are both NP &NP hard are called NP
if element found min then a swap takes place.
complete problems. So option (C) is correct option.
(a) Can’t be correct since P€NP, so there can be any So during n iterations maximum.
Algorithm with P time. n swap can occur in each iteration.
(b) Is not true, if some solved deterministically but if No. of swaps = n[n + (n – 1) + (n – 2) ............1]
not NP complete then can’t be P=NP. = Q(n2) is correct option.
(d) Is not correct because some problems which are
44. (a) let {0,1,2,3,4} be {a,b,c,d,e}
NP decidable under certain conditions.
42. (b) The Bellman-Ford algorithm solves the single-source
shortest paths problem for a graph. This is done with
both positive and negative edge weights.
Let pictorially understands the concept of the Bellman-
Ford algorithm.
t 5 x
¥ ¥
6 –2
–3
Drawing spanning true using Prim’s Algorithms start
s 0 8 –4 7
2 with a
7 ¥ ¥ (A) &(a,b),(a,c),(a,d),(a,e) (a,b) = 1
y 9 z (B) &(a,c), (a,d), (a,e), (b,c), (b,d), (b,e) (a,d) = 1
Initialization (D) &(a,c), (a,e), (b,c), (b,d), (b,e), (c,d) (d,e) = 2
t 5 x (E) &(a,c), (a,e), (b,c), (b,d), (b,e), (c,d), (c,e) (c,e) = 3
2 4
6 –2
–3

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

B ¾® EC = 4 + 2 + 3 = 9 Total complexity of n operations = a + b


B ¾® A EC = 1 + 4 + 3 = 8 £a+a [From ...(i)]
£n+n [From ... (ii)]
This is min path.
£2 n
Hence (b) is correct option. \ Worst Case Time Complexity of 'n' operations is
10n log10 n 10log10 (a) q (n).
46. (c) = = approx 106 53. (b) The return value of the function is q (n2 log n)
2 0.001
0.0001 n
n
Therefore, the value of k comes out to be 6. The outer for loop goes + 1 iterations.
47. (c) In switch case statements, there can be more cases, 2
The inner for loop runs independent of the outer
which case satisfied the condition will be executed, so loop.
we have to add break statement after every case in n
switch. If there is no break statement then all switch And for each inner iteration, gets added to k.
2
cases will be executed and default case will also be
n
executed. \ × # outer loops × # inner loops per outer loop.
In the given program, there is no error so, case A is 2
executed then case B and then case C and then case D # Inner loops = q (log n) [Q 2q(log n) = q (n)]
and E and finally the default case will be executed and n én ù
print. \ ´ ê + 1ú .q(log n) = q(n2 log n)
2 ë2 û
Choice A
1
Choice B No choice 1
48. (b) The tightest upper bound that represents the number 54. (d)
of swaps required to sort n numbers using selection
sort are O (n). 0 0
49. (c) The tightest upper bound that represents the time
complexity of inserting an object into a binary search
tree with n nodes is O (n).
50. (a) Using Depth First search Algorithm to check if there
is a cycle in an undirected graph. Whenever a back 0,1
edge is encountered in DFS then gives undirected 1. Complement of L(A) is context free-true
graph which has a cycle. As there exist a DFA, L(A) is regular. Regular
1. Also if there is a cycle in the undirected graph, languages are closed under complement.
we must encounter a back edge in DFS. DFS can be \ Complement of L(A) is regular and therefore
done a O (| E | + | V |) time for graph G = (V, E). So context free.
it can be in P. 2. L(A) = L ((11 * 0 + 0) (0 + 1) * 0 * 1*) – true
2. P Í NP, This is also in NP. AS L (A) = L ((11 * 0 + 0) * (0 + 1) * ) is
Equivalent to L ((11* 0 + 0) (0 + 1) * 0 * 1 * )
3. NP-complete problem A Î NP by definition 3. For the language accepted by A,
every problem in NP can be solved in polynomial A is minimal DFA – false
time using non-deterministic turing machine. So, Minimal DFA
answer is (a) i.e., 1, 2, 3 are true.
1 0 0, 1
51. (c) The time complexity of Bellman-Ford algorithm on a 0
graph with n vertices and m edges is O (nm).
For a complete graph, m = nC2 = O (n2) 4. A accepts all strings over {0,1} of length atleast
(Since there is an edge between all pair of vertices) 2-false.
\ The complexity = O (n2 . n) The given DFA A accepts the string "0".
= O (n3) Ans (d) 3 and 4 only false
\ Solution is (c).
52. (a) To compute the worst case time complexity of a PRACTICE EXERCISE
sequence of n queue operations on an initially empty 1. (d) Third row corresponds to node 3. From 3 to 1, there
queue is q (n). is no path, so the entry (3,1) should be zero, since
Complexity of a squence of 'n' queue operations = there is a path from 3 to 2 and also from 3 to 3 (i.e.,
Total complexity of Enqueue operations (a) + Total 3®2 ®3) the third row should be 0, 1, 1.
complexity of Dequeue operations (b). 2. (c)
Total complexity of Dequeue operations (b) £ Total 3. (b) Number of nodes of fully binary tree is 2n – 1 = 15
complexity of Enqueue operations 2n = 16
b£a ...(i) n=4
Total complexity of queue operations (a) £ n ...(ii) i.e., 15 nodes can form full binary tree.
EBD_7203
S3-236 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
4. In Prim’s alogorithm, the edge with smallest weight 8. (d) Strong component in a given graph in the maximal
added first, so sequence of addition of edge in set of vertices such that for any two vertices i, j in
spanning tree so that cycle does not exist will be the set, there is a path connecting i to j. Obviously
E E vertex d cannot be in the maximal set (as no vertex
2 2 can be reached starting from vertex d)
E
G G
2 G F C 4
9. (c) For any undirected connected graph G with Gmax
5
and Gmin be the maximum and minimum weight of the
F
B E edges. Every minimum spanning tree must contain
Gmax. It may happen that Gmax be the only weighted
A 10
2 edge joining two vertices.
7
22 G
D 5 10. A B C D E F
4 A 0 6 9 ¥ 2 7
C F A, E 0 6 8 7 — 7
Hence, sequence = (E, G), (C, F), (F, G), (A, D), A, E, B — — 8 7 — 7
(A, D), (A, B), (A, C) A, E, B, D — — 8 — — 7
5. (c) 6. (c) A, E, B, D, F — — 8 — — —
7. (b) Average node depth in a randomly built binary A, E, B, D, F, C — — — — — —
search tree In this problem, we prove that the
average depth of a node in a randomly built binary The required output sequence is AE, B, D, F, C
search tree with n nodes is O(lg n). We shall use (1) A, E (2) 2 units
reveals a surprising similarity between the building (3) Program syntax erron
of a binary search tree and the execution of 11. (d) There is an edge from a vertex i to a vertex j if either
RANDOMIZED QUICK SORT. We define the total j = i + 1or J = 3i
path length P(T) of a binary tree T as the sum, over So, possible set of edge is
all nodes x in T, of the depth of node x, which we 1 ® 2 ® 3 ® 4 ® 5 ® 6 ® 7 ® 8 ® 9 ® +...¥
denote by d(x, T).
a. Argue that the average depth of a node in T is So, minimum number of edges in a path from vertex
1 1 1 to vertex 100 is
å d ( x, T ) = n P(T ).
n xÎT ® 3 ® 9 ® 27 ® 81
11442443 ® 82 4®24444
...99 ® 100
1444 3
Thus, we wish to show that the expected value of P(T) So total = 4 + 19 = 23
is O(n lg n). 13. (d) The sequence of depth first traversal of the above
b. Let TL and TR denote the left and right subtrees graph are
of tree T, respectively. Argue that if T has n nodes, (a) abcghf (b) a b f c n g c
then (c) afghbc
P (T ) = P (TL ) + P(TR ) + n - 1. 14. (d) 1. First statement : In a DFS of an undirected
c. Let P(n) denote the average total path length of a graph every edge is either a tree edge or a back
randomly built binary search tree with n nodes. edge.
Show that In a DFS of a directed graph no cross edge
goes to a higher numbered or rightward vertex.
1 n -1
P ( n) = å ( P(i) + P(n - i - 1) + n - 1).
n i =0
2. Second statement :In a DFS of an undirected
graph we assign a direction to each edge from
d. Show how to rewrite P(n) as
the vertex which discover it. In a DFS of a
2 n -1 directed graph no cross edge goes to a higher
P ( n) = å P(k ) + Q(n).
n k =1 numbered or rightward vertex.
e. Recalling the alternative analysis of the 15. (b) for the large digraphs the space used is proportional
randomized version of quicksort given in Problem to V^2 and time proportional to O (V + E).
7-3, conclude that P(n) = O(n lg n). 16. (a) (i) First statement is False because a tree/forward
At each recursive invocation of quicksort, we choose edge if and only if d[u] <d[v] <f [v] <f [u],
a random pivot element to partition the set of elements
(iii) Third statement is False An edge (u, v) is a
being sorted. Each node of a binary search tree
partitions the set of elements that fall into the subtree back edge if and only if d[v] <d[u] <f [u] <f [v],
rooted at that node. Note : An edge (u, v) is a cross edge if and only if
d[v] <f [v] <d[u] <f [u].
ALGORITHM ANALYSIS S3-237

17. (b) In topological sorting, we have to list out all the


nodes in such a way that whenever there is an edge 10
connecting i and j, i should precede j in the listing.
For some graphs, this is not at all possible for same
8 5
this can be done in more than one way. So,
topological sorting will be ABDC.
18. (a) Let there be n item to be searched. After the first 3 2 1 Inserting 1
search the list is divided into two, each of length here
n/2. After the next search 2 lists, each of length n/4
and so on. This successive division has to stop 10
when the length of list becomes 1. Let it happen after
k steps. After the k steps. n/2k = 1. Solving n = 2k. 5
8
Hence, order is log(n).
19. (c) For sorting 200 names bubble sort makes 200 × 199/2 7
= 19900 comparison. The time needed for 1 3 2 1
comparison is 200 s (approximately). In 800 s. It can
make 80000 comparison we have to find n, such that
Inserting 7 here
n(n – 1)/2 = 80000. Solving n is approximately 400.
20. (d) In the best case quick sort algorithm makes n log (n) 10
comparison. So 1000 × log (1000) = 9000 comparisons.
which takes 100s. To sort 100 names a minimum of Value swapped as
100 (log 100) = 600. Comparisons are needed. This 8 7 per algorithm
takes 100 × 600/9000 = 6.7s
21. (b) 22. (b) 23. (a) 24. (a) 25. (a) 5
3 2 1
26. (d) In mathematics, the transitive closure of a binary relation
R on a set X is the smallest transitive relation on X that Therefore, the level order traversal comes out to be 10,
contains R. If the original relation is transitive, the 8, 7, 3, 2, 1, 5
transitive closure will be that same relation; otherwise, 28. (b) The number of keys are per given are 4
the transitive closure will be a different relation. Applying the direct formula
In computer science the concept of transitive closure Bn = 1/(n + 1) × (2n!/ n!n!)
can be thought of as constructing a data structure that Where, Bn is number of binary trees and n is the number
makes it possible to answer reachability questions. That of keys.
is, can one get from node a to node other node b in one ® Bn = 1/(4 + 1) × (8!/4!4!)
or more hops? A binary relation tells you only that ® Bn = 1/5 × (8 × 7 × 6 × 5 × 4!)/4!4!
node a is connected to node b, and that node b is ® Bn = 8 × 7 × 6/(4 × 3 × 2)
connected to node c, etc. After the transitive closure is ® Bn = 56/4
constructed in an O(1) operation one may determine ® Bn = 14
that node c is reachable from node a. The total number of binary trees with n = 4 is 14.
29. (c) Let us consider a binary tree. In a binary tree number of
Warshall’s algorithm can be used to construct the leaves – 1 = number of nodes.
Transitive closure of directed graphs (). In Warshall’s In a k ary tree where each node has k children, this
original formulation of the algorithm, the graph is implies that k – 1 key have no leaves.
unweighted and represented by a Boolean adjacency Now, it is given that number of nodes are n, therefore
matrix. Then the addition operation is replaced by number of leaves will be n(k – 1) + 1.
logical conjunction (AND) and the minimum operation ænö
by logical disjunction (OR). 30. (b) Since, T ( n ) = 2T ç ÷ + n
è2ø
27. (d) Initial level order traversal with 10, 8, 5, 3, 2 T(0) = T(1) = 1
T(n) can be further computed as
10
log n log n
T (n) = n å ( 2 / 2) Ù i ® T ( n ) = n å (1) Ù i
5 i =0 i =0
8
® T(n) = Q (n log n)
31. (b) According to the Dijkstra’s algorithm for shortest single
3 2 source shortest path.
Now, let us insert the values
EBD_7203
S3-238 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Total updates of edges (E) needs time = O (log V) In a graph with three nodes, r u and v, with edges (r; u)
Therefore, total spend time = O (|E| log |V|) and (r; v), and r is the starting point for the DFS, u and
Now, if E is less than |V| Ù 2 v are siblings in the DFS tree, neither as the ancestor of
Time complexity = O (E + V log V) the other.v.
32. (a) As per the hint given along the question, use a heap 41. (c) Dijkstra is a greedy algorithm where we pick the
data structure. minimum distant vertex from not yet finalized vertices.
It is also given that Bellman Ford and Floyd Warshell both are Dynamic
There are [log n] sorted list of [n/log n_] elements each. Programming algorithms where we build the shortest
We know that construction of heap takes O (log log n) paths in bottom up manner
time. Therefore in worst case, the time complexity is O 42. (b) As we can observe f(1) is a recursive function, the
(n log log n) (as elements are [n/ log n_] recurrence equation can be further observed as
33. (c) Q is true: Since the graph is undirected, every edge ® T(n) = 2T (n – 1) + 3T (n – 3)
increases the sum of degrees by 2. It shows that the solution to the equation has 2^n.
P is true: If we consider sum of degrees and subtract all Also, f2 has a loop from 2 to N. Therefore, the average
even degrees, we get an even number (because Q is running time comes out to be Q(2n) and Q (n).
true). So total number of odd degree vertices must be 43. (c) For f(1), we are given that
even. (2 * f1 (n – 1) + 3* f1(n – 2))
34. (c) A cycle of length 3 can be formed with 3 vertices. There For f(2), we are given that
can be total 8C3 ways to pick 3 vertices from 8. The X[0] = Y[0] = Z[0] = 0;
probability that there is an edge between two vertices X[1] = 1; Y[1] = 2; Z[1] = 3;
is 1/2. So expected number of unordered cycles of And for loop we are given that:
length 3 = (8C3)*(1/2)^3 = 7 X[i] = Y[i – 1] + Z [i – 2];
35. (c) Time complexity of Bellman-Ford algorithm is Q (VE) Y[i] = 2 * X[i];
where V is number of vertices and E is number edges If Z[i] = 3 * X[i];
the graph is complete, the value of E becomes Q (V2) . Calculating f(1)
So overall time complexity becomes Q (V3) f(n) = (2 * f1(n – 1) + 3 * f1(n – 2))
36. (a) 1 is true because cycle detection can be done in f(2) = (2 * f1 (2 – 1) + 3 * f1(2 – 2))
polynomial time using DFS (See this). ® f(2) = (2 * 1 * 3 * 0) = 2
2 is true because P is a subset of NP. Similarly,
3 is true because NP complete is also a subset of NP f(3) = 7
and NP means Non-deterministic Polynomial time f(4) = 20
solution exists. f(5) = 61
37. (c) The worst case occurs for a skewed tree. In a skewed f(6) = 182
tree, when a new node is inserted as a child of f(7) = 547
bottommost node, the time for insertion requires f(8) = 1640
traversal of all node. For example, consider the following Therefore, f1(8) returns 1640.
tree and the case when something smaller than 70 is f2(8) will also return the same value as f2(n) is the non-
inserted. recursive function of f1(n)
100 44. (b) The subset sum problem given above is a NP complete
/ problem as this problem is the problem in which both
90 NP (verifiable in non-deterministic polynomial time) and
/ NP-hard (any NP-problem can be translated into this
80 problem).
/ Now, here x is a Boolean array that contains
70 N rows
38. (b) Selection sort requires only O(n) swaps. W + 1 columns
39. (c) Q is true: Since the graph is undirected, every edge Also ith row determines the elements of subset S and
increases the sum of degrees by 2. jth column determines the corresponding weight.
P is true: If we consider sum of degrees and subtract all Given is 2 £ i £ n and a i £ j £ W
even degrees, we get an even number (because Q is
Let subset S = {a1, a2, a3, ... ai}
true). So total number of odd degree vertices must be
And weight is given as W
even.
® X [i, j] = X [i – 1, j] Ú X[i – 1, j – ai]
40. (b) Time complexity of fun1() can be written as
45. (c) X[n, W] is true as in the previous question, the weight
T(n) = T(n-1) + C which is O(n)
W of subset S is found which contains the n elements.
Time complexity of fun2() can be written as
T(n) = 2T(n-1) + C which is O(2^n)
5
Page - 239 - 288

THEORY OF COMPUTATION

C Ø Regular languages and finite automata

O Ø

Ø
Context free languages and Push-down automata

Recursively enumerable sets and Turing machines, Undecidability.

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)

In this case the value of w will also be 0 to jump to state q3 so that on


receiving 1 to machine could jump on final state. Thus the string will be
(replacing w) 1011001 S.
For string 1101 z w 1 (state q0) the value of z will be 0 and w will also be 0.
So that the machine could reach to (replacing z, w) 1101001 S

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

Formally, a non-deterministic finite automation is a 5-tuple (Q, å, d, q0, F), where


1. Q is a non-empty finite set of states.
2. å is a non-empty finite alphabet.
3. d: Q × åe ® P(Q) is the transition function. Also, Q × å Þ 2Q.
4. q0 Î Q is the start state.
5. F Í Q is the set of accept states.
For example, NFA drawn below can be formally written as:–
1. Q = {q1, q2, q3, q4}
2. å = {0, 1}
3. d is given as

0 1 e
q1 { q1} { q1, q 2 } f
q2 { q3 } f { q3 }
q3 f {q 4 } f
q4 {q4 } {q 4 } f

4. ql is the start state.


5. F = {q4}
0, 1 0, 1

q1 1 q2 0, e q3 1 q4

Step of type (i): a

Step of type (i): b

Step of type (ii): a/b

a
E

Step of type (iv): (a/b)*


EBD_7203
S3-244 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

a
E
E

E
b

Step of type (iii): (a/b)*a

a
E
a E E

E
b

Figure 1 : Steps in constructing an NFAE for (a|b)*a


Some important points to remember:
1. Any DFA is also an NFA.
2. For each NFA, there exist an equivalent DFA.
3. Taking into account above two points, a language is regular if and only if some
NFA recognizes it.
4. If n is the number of states in NFA, then the equivalent DFA will have 2n state
including f state.
Converting NFA to DFA
Let’s have a look at the NFA(N) below that we will be converting in DFA(D).

b a
e

a 2 3
a, b

To construct a DFA(D) that is equivalent to N, we first need to determine D’s states.


Since N is having 3 states, D’s states will be 23 = 8. Now label each of D’s state with
the subset of N’s state. Thus D’s state set is
{f, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
The start state of D is the state that are reachable from 1 by travelling along e arrows.
An e arrow goes from 1 to 3, so start state is {1, 3}. Accept states of D are the states
containing N’s accept state, i.e. {{1}, {1, 2}, {1, 3}, {1, 2, 3}}. Now, we determine D’s
THEORY OF COMPUTATION S3-245
transition function. In D, state {2}
goes to {2, 3} on input a, because a b
in N, state Z goes to both 2 and 3 a, b f {1} {2} {1, 2}
on input a and we can’t go farther
from 2 or 3 along e arrows. State
{2} goes to {3} on input b. Similarly,
state {1} goes to f on input a, b b b
b (a) a,
because no a arrows exit it in N. a
Continuing in this way, we obtain
the diagram of D. a
The above DFA can be simplified
a
by removing the unwanted states. {3} {1, 3} a {2, 3} {1, 2, 3}
In this case, they are {1} and {1, 2}
because there are no arrows b b
pointing at these states and also
none of them are start state and Diagram of D
hence they can’t be reached. So,
the simplified DFA will be (a)
a, b
FINITE AUTOMATA WITH OUTPUTS
Under finite automata we have two other machines. (a) Mealy
a b
machine and (b) Moore machine. These machines produces some {1, 3} {3} f
output also at every state.
(i) Mealy Machine
A mealy machine is a tuple b
(Q, S, D, d, l, q0) where b b
a
Q = finite set of states
S = finite non-empty set of input alphabets a
D = the set of output alphabets
a
d = transition function defined as Q × S ® Q. {2} {2, 3} {1, 2, 3}
l = the output function defined as S × Q ® D means at any
b
state the value of current state and current input defines
the output Simplified DFA
q0 = initial state
0/a

q0 q1

0/b

Here, in the given mealy machine when input 0 is applied to state q0 it


produces output a and when 0 is applied to state q1 it produces the output
b. The transition table will be represented as

State Input 0
Next state Output
® q0 q1 a
q1 q0 b

In case of Mealy machine output is ^ if input is ^.


(ii) Moore Machine
Moore machine is a set of six tuples (Q S, D, l q0) where,
Q = set of states
S = set of inputs
EBD_7203
S3-246 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
D = set of outputs
0
d = transition function defined as Q × S ® Q
l = output function defined as Q ® D means only the current state of
q0/a q1/b automata will define the output
q0 = the initial state
0 As we can illustrate the Moore machine in following example.
Herre, q0 state will generate output a and q1 state will generate output b. The
transition table will be given as

State Input = 0 Output


q0 q1 a
q1 q0 b
Finite automata from regular expressions
Given a regular expression r, over an alphabet å say, we wish to construct a DFA
M with alphabet of input symbol å and with the property tht for each u Î å*, u
matches r iff u is accepted by M–so that L(r) = L(M).
Note that by the Theorem on Slide 18 it is enough to construct an NFAE N
with the property L(N) = L(r). For then we can apply the subset construction to N
to obtain a DFA M = PN with L(M) = L(PN) = L(N) = L(r). Working with finite automata
that are non-deterministic and have e-transitions simplifies that construction of a
suitable finite automaton from r.
Let us fix on a particular alphabet å and from now on only consider finite
automata whose set of input symbols is å. The construction of an NFAE for each
regular expression r over å proceeds by recursion on the syntactic structure of the
regular expression, as follows.
(i) For each atomic form of regular expression, a (a Î å), e, and 0 , we give
an NFAE accepting just the strings matching that regular expression.
(ii) Given any NFAEs M1 and M2, we construct a new NFAE, Union (M1,
M2) with the property
L(Union (M1, M2)) = {u | u Î L(M1) or u Î L(M2)}.
Thus L(r1|r2) = L(Union (M1, M2)) when L(r1) = L(M1) and L(r2) = L(M2).
(iii) Given any NFAEs M1 and M2 , we construct a new NFAE, Concat
(M1, M2) with the property.
L(Concat(M1, M2)) = {u1u2 | u1 Î L(M1) and u2 Î L(M2)}.
Thus L(r1r2) = L(Concat (M1, M2)) when L(r1) = L(M1) and L(r2) = L(M2).
(iv) Given any NFAE M, we construct a new NFAE, Star (M) with the property
L(Star(M)) = {u1u2...un | n ³ 0 and each ui Î L(M)}.
Thus L(r*) = L(Star(M)) when L(r) = L(M).
Thus starting with step (i) and applying the constructions in steps (ii)-(iv) over
and over again, we eventually build NFAEs with the required property for
every regular expression r.
Put more formally, one can prove the statement
for all n ³ 0, and for all regular expressions of size £ n, there exists an
NFAE M such that L(r) = L(M)
by mathematical induction on n, using step (i) for the base case and steps (ii)-
(iv) for the induction steps. Here we can take the size of a regular
expression to be the number of occurrences of union (– | –),
concatenation (– –), or star (–*) in it.
THEORY OF COMPUTATION S3-247
Example 2. Convert the following Mealy machine to Moore machine.

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

• If r = {a} for some a Î å, M is


a
s f
• If r = r1 + r2, then M is

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

Properties (Identities) of regular expression


1. f+ R= R
2. f R + Rf = f
3. ^R = R ^ = R
4. ^ * = ^ and f * = ^
5. R+R=R
6. R*R*=R*
7. RR * = R * R
8. (R*)* = R*
9. ^ + RR * = ^ + R * R = R*
10. (PQ) * P = P (QP) *
11. (P + Q)* = (P * Q*) = ( P* + Q*)*
12. (P + Q) R = PR + QR and R (P + Q) = RP + RQ
Arden’s Theorem
Let P and Q be two regular expressions over S. If P does not contain Ù, then the
following equation in R, namely
R = Q + RP
has a unique solution, i.e., R = QP*
equivalence of two regular expressions
Prove that (1 + 00* 1) + (1 + 00*1) (0 +10 * 1) * (0 + 10 * 1)
is equal to 0 * 1(0 + 10 * 1)*
Þ (1 + 00* 1) + (1 + 00 *1) (0 + 10* 1)* (0 + 10 * 1)
Þ (1 + 00 * 1) Ù + (1 + 00 * 1) (0 + 10 * 1) * (0 + 10* 1)
{R . Ù = R}
EBD_7203
S3-252 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
= (1 + 00 * 1) (Ù + (0 + 10 * 1) (0 + 10 * 1))
= (1 + 00 * 1) (0 + 10 * 1)* (ÙRR* = R*)
= (Ù. 1 + 00 * 1) (0 + 10 * 1) *
= (Ù + 00 *) Ù (0 + 10* 1)*
= 0* 1(0 + 10 * 1)*
= R.H.S.

Regular expressions over an alphabet å

• each symbol a Î å is a regular expression


• e is a regular expression
• is a regular expression
• if r and s are regular expressions, then so is (r|s)
• if r and s are regular expressions, then so is r|s
• if r is a regular expression, then so is (r)*
Every regular expression is built up inductively, by finitely many
applications of the above rules.

(N.B. we assume e, , (, ), |, and * are not symbols in å.)

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.

Matching strings to regular expressions

• 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

The definition of ‘u matches r*, on Slide 6 is equivalent to saying


for some n ³ 0, u can be expressed as a concatenation of n strings,
u = u1u2....un, where each ui matches r.
THEORY OF COMPUTATION S3-253
The case n = 0 just means that u = e (so e always matches r*); and the case
n = 1 just means that u matches r (so any string matching r also matches r*). For
example, if å = {a, b, c} and r = ab, then the strings matching r* are
e, ab, abab, ababab, etc.
Note that we didn’t include a regular expression for the ‘*’ occurring in the
UNIX examples on Slide 1. However, once we know which alphabet we are referring
to, å = {a1, a2,....,an} say, we can get the effect of * using the regular expression
(a1|a2|...|an)*

Examples of matching, with å = {0, 1}

• 0|1 is matched by each symbol in å


• 1(0|1)* is matched by any string in å* that starts with a ‘1’
• ((0|1)*(0|1))* is matched by any string of even length in å*
• (0|1)*(0|1)* is matched by any string in å*
• (e|0)(e|1)|11 is matched by just the strings e, 0, 1, 01, and 11
• 1|0 is just matched by 0

Examples based on Design of regular expression


Example 6. Design a regular expression for inputs a and b {a, b} that contains exactly
2 a’s.
Sol. Here, the description defines that there will be only 2 a’s. In between number
of b’s is not defined so b can be present in string or b may not be present
in the string. This can be represent as b * thus,
R = b * ab * ab *
Example 7. Design a regular expression for inputs a and b that contains atleast 2a’s.
Sol. Here at least 2a’s should be there in string irrespective of position. For string
length more than 2 the sequence of a, b is not defined. If the sequence and
length of inputs a, b are not defined it is represented as
(a + b) *
Thus regular will be written as
(a + b)* a (a + b)* b (a + b)
Example 8. Design a regular expression over strings a and b that contains at most
2 a’s.
Sol. Here, the string can have either 1 a or 2 a’s or string will have no a’s.
For string containing 2 a’s regular expression will be
b* ab* ab*
For string containing 2 a’s the regular expression will be b* ab* ab* for string
containing no as the regular expression will be.
Thus, the regular expression for language containing at most 2 a’s will be
R = b* ab* + b* ab* ab* + b*
Example 9. Find the regular expression containing the sub-string aa.
Sol. The regular expression will be as
(a + b)* aa(a + b)*
Rules for Regular Expressions
1. RÈf=R
2. Roe=R
3. f* = e
4. e* = e
EBD_7203
S3-254 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example 10. Find the regular expression defined by following DFA

a
q1 q2
b

a b a

q3 b q4
a, b

Sol. The equations for states will be


q1 = Ù+ q2b + q3a
q2 = q1a
q3 = q1b
q4 = q3b + q2a + q4a + q4b
For final state q1 equation is
q1 = Ù + q 2 b + q 3 a
= Ù + q1ab + q1ba
(By putting value q2 = q1a and q3 = a1b)
= Ù + q1 (ab + ba)
q1 = Ù (ab + ba)*
(ab + ba)*
(By Arden theorem Q = Ù, p = (ab + ba), R = Q + RP has solution R = QP*)
Construction of Finite Automata from Regular Expression
For regular expression (a + b) the FA will be
a
a, b
or
b
For regular expression ab the FA will be
a b

For regular expression a* the FA will be


a

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

PUMP ING LEMMA


If A is a regular language, then there is a number P (the pumping length) where, if
S is any string in A of length at least P, then S may be divided into three pieces,
S = xyz, satisfying the following conditions:–
1. For each i ³ 0, xy2z Î A
2. | y| > 0, and
3. | xy| £ P.
• If a language does not satisfy these conditions, then it is a non-regular
language.

How to use the Pumping Lemma to prove


that a language L is not regular

For each l ³ 1, find some w Î L of length ³ l so that

no matter how w is split into three, w = u1vu2,


(†)
with length (u1v) £ l and length (v) ³ 1.
there is some n ³ 0 for which u1vnu2 is not in L.

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

(iii) L3 = {ap | p prime} is not regular.


def
[For each l ³ 1, we can find a prime p with p > 2l and then ap Î L3
has length ³ l and has property (†).]
EBD_7203
S3-256 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
CONTEXT FREE LA NGUAGES
The class of context free languages generalizes the class of regular languages, i.e.
every regular language is a context free language. The reverse of this is not true.
Informally, a context free language (CFL) is a language generated by a context free
grammar (CFG). A CFG is a set of rules for deriving (or generating) strings (or
sentences) in a language.
Informally, a CFG consists of:–
— A set of replacement rules, each having a LHS and a RHS.
— Two types of symbols, variables and terminals.
— LHS of each rule is a single variable (no terminals).
— RHS of each rule is string of zero or more variables and terminals.
— A string consists of only terminals.
Formally, a CFG is a 4-tuple (V, å, R, S), where
1. V is a finite set called variables.
2. å is a finite set, disjoint from V, called terminals.
3. R is a finite set of rules, with each rule being a variable and a string of variables
and terminals.
4. S Î V is the start variable.
For example,
G = ({S}, (a, b), R, S), set of rules R is,
S ® a S b | S S | e. This can be also written as
S®aSb
S®SS
S®e
This grammar generates strings such as abab, aaabbb and aababb.
• All the strings generated by the grammar constitute the language of the
grammar and is called context free language (CFG).
Chomsky Normal Form
A context free grammar is in Chomsksy Normal Form if every rule is of the form.
A ® BC
A®a
where, a is any terminal and A, B and C are any variables except B and C may not
be the start variable. In addition, the rule S ® e, where S is the start material is
allowed.
Backus Naur Form
It is quite likely that the same non-terminal will appear on the left-hand side of several
productions in a context-free grammar. Because of this, it is common to use a more
compact notation for specifying productions, called Backus-Naur Form (BNF), in
which all the productions for a given non-terminal are specified together, with the
different right-hand sides being separated by the symbol ‘|’. BNF also tends to use
the symbol ‘;;=’ rather than ‘®’ in the notation for productions. An example of a
context-free grammar in BNF is given
Example of Backus-Naur Form (BNF)

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

We can also use a state diagram to describe a PDA, as shown below:–

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.

Pumping Lemma for CFL


If A is a CFL, then there is a number P (the pumping length) where, if S is any string
in A of length at least P, then S may be divided into five pieces S = uvwxy satisfying
the conditions:–
1. for each i ³ 0, uv2wx2y Î A,
2. | vx| > 0, and
3. | vwx | £ P.
EBD_7203
S3-258 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
TU RING M ACHINES
A turing machine is a 7-tuple (Q, å, G, d, q0, qaccept, qreject), where
1. Q is the set of states.
2. å is the input alphabet not containing the blank symbol, .
3. G is the tape alphabet, where Î G and å Í G.
4. d : Q × G ® Q × G × {L, R} is the transition function.
5. q0 Î Q is the start state.
6. qaccept Î Q is the accept state.
7. qreject Î Q is the reject state, where qreject ¹ qaccept.
Initially M (turing machine) receives its input w Î å* on the leftmost n squares of
the tape and rest of the tape is blank, i.e. filled with blank symbol. The head starts
from the leftmost square of the tape. Once M has started, the computation proceeds
according to the rules described by the transition function. If M ever tries to move
its head to the left off the left hand end of the tape, the head stays in the same place
for that move, even though the transition function indicates L. The transition continues
until it enters either the accept or reject states at which point it halts. If neither occurs,
M goes on forever. As a TM computes, changes occur in the current state, current
tape content and current head location. A setting of these three items is called a
CONFIGURATION.

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) Neither DHAM3 nor SHAM3 is NP-hard


12. For S Î (0 + 1) * let d(s) denotes the decimal value of s (e.g.,
(b) {WW X | X, W Î{0,1} }
R +

d(101) = 5) [2006, 1 mark]


Which one of the following statements is true? (c) {WXW | X, W Î {0,1} }
R +

(a) L is recursively enumerable but not recursive


(b) L is recursively but not context-free
(c) L is context-free but not regular
(d) {XWW | X, W Î {0,1} }
R +

(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

R(F) Q P R(F) Q P L 2 = {a i b jck | i, j, k ³ 0}

S Q P S P Q Then L is [2009, 2 marks]


THEORY OF COMPUTATION S3-263
(a) not recursive 39. Consider the languages L1 = {0i1j | i ¹ j}, L2 = {0i1j | i = j},
(b) regular L3 = {0i1j | i = 2j + 1 j}, L4 = {0i1j | i ¹ 2j}. Which one of the
(c) context-free but not regular following statements is true? [2010, 2 marks]
(d) recursively enumerable but not context-free (a) Only L2 is context-free
33. Given the following state table of an FSM with two states A (b) L2 and L3 are context-free
and B, one input and one output (c) L1 and L2 is context-free
Present Present Input Next Next Output (d) All are context free
State A State B State A State B 40. Let L = {W Î (0, 1) * | W has even number of 1s}, i.e., L is the
0 0 0 0 0 1 set of all bit strings with even number of 1’s. Which one of
0 1 0 1 0 0 the regular expressions below represents L?
1 0 0 0 1 0 [2010, 2 marks]
1 1 0 1 0 0 (a) (0* 10* 1)* (b) 0 * (10* 10*)*
0 0 1 0 1 0 (c) 0 * (10 *1)* 0* (d) 0 * 1(10 * 1) * 10 *
0 1 1 0 0 1 41. Let L1 be a recursive language. Let L2 and L3 be languages
1 0 1 0 1 1
that are recursively enumerable but not recursive. Which of
1 1 1 0 0 1
the following statements is not necessarily true?
If the initial state is A = 0, B = 0, what is the minimum length
[2010, 1 mark]
of an input string, which will take the machine to the state
A = 0, B = 1 with output = 1? [2009, 2 marks] (a) L2 – L1 is recursively enumerable
(a) 3 (b) 4 (b) L1 – L3 is recursively enumerable
(c) 5 (d) 6 (c) L 2 Ç L1 is recursively enumerable
34. Match all items in List I with correct options from those
(d) L 2 È L1 is recursively enumerable
given in List II [2009, 1 mark]
42. Consider the languages, L1, L2 and L3 as given below

{ }
List I List II
L1 = 0p1q | p, q Î N [2011, 2 marks]
P. Regular expression 1. Syntax analysis

L 2 = {0 p1q | p, q Î N and p = q} and


Q. Push-down automata 2. Code generation
R. Dataflow analysis 3. Lexical 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

4. {a m bn cmdn | n ³ 1, m ³ 1} (c) Î-alone (d) none of these


28. The FSM shown in the figure accepts
(a) 1 and 2 (b) 3 and 4
(c) 2 and 4 (d) 1, 2, 3 and 4 a, b
20. Consider the machine M shown below
a, b

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.

Let the language accepted by M be L. Let L1 be the language


accepted by the NFAM 1 , obtained by changing the
accepting state of M to a non-accepting state and by
changing the non-accepting state of M to accepting states.
Which of the following statements is true?
(a) L1 = {0, 1}* – L (b) L1 = {0, 1}*
Let S denote the set of seven bit binary strings in which the (c) L1Í L (d) L1 = L
first, the fourth, and the last bits are 1. The number of strings 100. The problems 3-SAT and 2-SAT are
in S that are accepted by M is (a) both in P
(a) 1 (b) 5 (b) both NP-complete
(c) 7 (d) 8 (c) NP-complete and in P respectively
97. Let G = ({S}, {a, b} R, S be a context free grammar where the (d) undecidable and NP-complete respectively
rule set R is 101. The following finite state machine accepts all those binary
strings in which the number of 1’s and 0’s are respectively
S®a S b|S S|e
Which of the following statements is true?
(a) G is not ambiguous
(b) There exist x, y, Î L (G) such that xy Î / L(G)
(c) There is a deterministic pushdown automaton that
accepts L(G)
(d) We can find a deterministic finite state automaton that
accepts L(G)
98. A single tape Turing Machien M has two states q0 and q1,
of which q0 is the starting state. The tape alphabet of M is
{0, 1, B} and its input alphabet is {0, 1}. The symbol B is the
blank symbol used to indicate end of an input string. The (a) divisible by 3 and 2 (b) odd and even
transition function of M is described in the following table (c) even and odd (d) divisible by 2 and 3
102. The language {am bm+n| m, n £ 1} is
0 1 B (a) regular
0 1,1,R (b) context-free but not regular
q q Q1,1,R Halt (c) context sensitive but not context free
q1 q1,1R Q 0,1,L qH0, B, L (d) type-0 but not context sensitive
103. Consider the flowing grammar C
The table is interpreted as illustrated below. S ® bS | aA | b
The entry (q1,1,R) in row q0 and column 1 signifies that if M A ® bA | aB
B ® bB | aS | a
is in state q0 and reads 1 on the current tape square, then it
Let Na (W) and Nb (W) denote the number of a’s and b’s in
writes 1 on the same tape square, moves its tape head one
a string W respectively. The language L(G) Í {a, b}+
position to the right and transitions to state q1.
generated by G is
Which of the following statements is true about M? (a) {W | Na (W) > 3Nb (W)}
(a) M does not halt on nay string in (0 + 1) +
(b) {W | Nb (W ) > 3N a (W )}
(b) M dies not halt on any string in (00 + 1)*
(c) M halts on all string ending in a 0 (c) {W | N a (W ) = 3k , k Î{0,1, 2,...}}
(d) M halts on all string ending in a 1
(d) {W | Nb (W ) = 3k , k Î {0,1,2,...}}
THEORY OF COMPUTATION S3-273

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

110. Which should be the final state(s) of the DFA if it should


accept strings starting with ‘a’ and ending with ‘b’?
(a) q 0 (b) q 1
(c) q0, q1 (d) q 3
111. Which of the following strings will be accepted it q0 and q1
are accepting states?
1. ababab 2. babaaa 3. aaaba
The language recognised by M is
(a) {W Î {a, b}* / every a in w is followed by exactly two (a) 1, 2 (b) 2, 3
b's} (c) 1, 3 (d) None of these
(b) {W Î {a, b}* / every a in w is followed by at least two 112. Which of the following represents the set of accepting states
b's} if the language to be accepted contains strings having the
(c) {W Î {a, b}* / w contains the substring ‘abb’ same starting and ending symbols?
(d) {W Î {a, b}* / w does not contain ‘aa’ as a substring} (a) {q0} (b) {q0, q3}
106. Let L1 be a recursive language, and let L2 be a recursively (c) {q3} (d) {q3, q1}
enumerable but not a recursive language. Which one of the Directions for 113 and 114:
following is TRUE? Consider grammar G
(a) L1 is recursive and L2 is recursively enumerable S ® AB, A ® aAA/Î, B ® bBB/Î.
113. Find the nullable symbols in the given grammar
(b) L1 is recursive and L2 is not recursively enumerable (a) A (b) B
(c) L1 and L2 are recursively enumerable (c) A, B and S (d) A and B
(d) L1 is recursively enumerable and L2 is recursive 114. If G1 is constructed from G, after eliminating Î-productions,
then G1 is given by
107. Consider the languages
(a) S ® AB (b) S ® AB | A | B
L1 = {WW R | W Î{0,1}*} A ® aAA | aA A ® aAA | aA
B ® bBB | bA B ® bBB | bB
L2 = {W #W R | W Î{0,1}*}, where # is a special symbol (c) S ® AB (d) S ® AB | A | B
L3 = {WW | W Î{0,1}*} A ® aAA | aA | a A ® aAA | aAa
Which one of the following is TRUE? B ® bBB| bB | b B ® bBB | bB | b
(a) L1 is a deterministic CFL Directions for 115, 116 and 117
(b) L2 is a deterministic CFL The ‘value’ of a R.E. r over å , denoted by val(r), is defined as
(c) L3 is a CFL, but not a deterministic CFL follows:
(d) L3 is a deterministic CFL 1. val (f) = 0
2. val (Î) = 0
Directions for 108 and 109:
Consider the following NFA with Î moves. 3. val (a) = 0, "a Î å
4. val ((rs)) = val ((r + s)) = max (val(r), val(s))
5. val ((r*)) = val (r) + 1
Find the value of the following R.E.
115. (a(a + a*aa))
108. If the given NFA is converted to NFA without Î-moves, (a) 0 (b) 1
which of the following denotes the set of final states? (c) 2 (d) None of these
(a) {q2} 116. (a(a + a*aa) + aaa)*
(b) {q1, q2 } (a) 1 (b) 2
(c) {q0, q1, q2} (c) 3 (d) 4
(d) can’t be determined
109. Which of the following strings will not be accepted by the 117. (a*b*b*b*) where å = {a, b}
given NFA? (a) 2 (b) 3
(c) 4 (d) none of these
EBD_7203
S3-274 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

PAST GATE QUESTIONS EXERCISE (A) L1 I L2 is CFL is true


1. (a) (B) L3 I L1 is recursive, not necessary so false.
2. (b ) In all the options there is linear relationship among (C) & (D) are also true.
strings so all CFL’s , but L1 & L3 can be accepted by 10. (b) Due to S ® S this Grammar is ambiguous right hand
PDA, L2 can be accepted by deterministic CFL due to side has twoNon terminals. Also the strings like aaabbb
presence of special symbol D which tells the middle of have equal no. of a’s & b’s but can’t be produced by
the string, so deterministic. this grammar. So 2 is false.
3. (b ) The rules here used will be. Statement 3 is true since it is a CFG so accepted by
All those languages which are recursive their PDA.
complements are also recursive. 11. (a) There is a difference between SHAM3 and DHAM3
So option (A) & (B) can be correct. that SHAM3 is used for finding a Hamiltonian cycle in
Now languages which are recursively enumerable but a graph but DHAM3 is the problem of determining if a
not recursive, their complements can’t be recursively graph exists in a Hamiltonian cycle. Also it is given
that |V| is divisible by 3, hence the problem can be
enumerable.
reduced from 3 SAT which further determines that
So only option (B) is correct
SHAM3 and DHAM3 are NP hard.
Hence (B) is correct option
12. (d) Given that, d(s) mod 5 = 2 and d(s) mod 7 ¹ 4}
4. (a) L1 and L2 are context-free languages and therefore
Both the languages are regular languages, since there
L1 Ç L 2 may or may not be context-free, since CFLs exists deterministic finite automata for both of them.
are not closed under intersection. Now, let us look at We also have an algorithm to check the regular nature
L1 Ç L 2 . of the language therefore L is regular.
L1 Ç L 2 = {anbncn | n > 0} 13. (c) Option (A), (B) & (D) can be accepted by DFA, & there
which is clearly not context-free but is context sensitive. is no linear relationship between the no. of 0’s &1’s in
5. (d) We know that, the languages accepted by non- the string but in (C)n0(S) - n1(S) <=4 can’t be accepted
deterministic finite automata are also accepted by by DFA, we require a PDA.
deterministic finite automata. This may not be in the So not regular.
case of context-free languages. 14. (d) The language is context free or not, this can be proved
by finding out the grammar for all the languages.
Therefore, Df = Nf and Dp Ì N p
6. (b) a is followed by two or more than 2b’s so the language { }
L1 = 0 n + m1n 0 m | n, m ³ 0
recognized by M is {W Î {a, b} * | . The production for L1 as follows:
7. (c) Option (c) S ® 0S0 0A1 e
According to the option, P2 is reducible to P3.
Also it gives that P2 is undecidable. A ® 0A1 e
From (a) and (b) ; Now, we need to apply these values of the production
P3 is undecidable. individually to generate
8. (d) Given language L = (1111 + 11111)*. Here, we can see
that more than eight 1’ can be generated by the 0 n + m n 0m
combination of 111 and 11111. Therefore, number of
states = 8 + 1 = 9. that is,
These can be represented as 0m0n1n0m ® To prove
1 1 1 1 1
Applying 0S0 (m times)
1
S ® 0 S0, S ® 0mS0m
1 Applying, S ® 0A1
® S ® 0m 0A1 0m
Here applying, A ® 0 A1, n – 1 times
1
S ® 0m 0 0n–1 A1n–1 10m
1
® S ® 0m 0n1n0m
Hence, proved, so L1 is context-free.
9. (b) L1 is regular language Going through the same procedure, we can see that
L2 is CFL. two comparisons are made in the L2 language, So it is
L3 is recursively enumerable but not REC. not context-free.
THEORY OF COMPUTATION S3-275
L3 ® Going through the same procedure again, we can 21. (b) Finite subset of non-regular set is regular as we know
see that two comparisons are made in the L3 language, that Pumping Lemma can be applied on all the finite
so it is not context free. sets that states that all finite sets are regular. Infinite
15. (a) S is NP complete and a NP complete problem is union of finite set is not regular because regular sets
reducible to some unknown problem then that problem can never be closed under infinite union.
is also NP complete. So S ® D, R the R is NP complete. 22. (b) Finite state automata (FSA) has no undecidability CFL
16. (b) The FSA as obtained in the previous question is b* a membership problem is also decidable.
(a + b)* So option (B) i.e Ambiguity of CFL cannot be
The minimum number of states are thus given by decidable.
b a, b 23. (a) Lets gather some knowledge for the regular expressions
before going to True or False. The regular sets are
defined in such a way that they have to follow some
q0 q1 conventions. Conventions on regular expressions
a
q0 and q1 are the state: that are required at most and 1. Bold face is not used for regular expressions when the
hence the minimum number of states is 2 (q0 and q1). expression is not confusing. So, for example, (r + s) is
17. (c) The behaviour as per the given PDA is an seen below used instead (r + s).
q0 to q1 ® b*a 2. The operation * has precedence over concatenation,
q1 to q2 ® (a + b) * which further has precedence over union (+). Thus,
Regular expression = b * a (a + b)* the regular expression (a + b(c*))) is written as a + bc*.
18. (c) Lets study the regular language. 3. The concatenation of k r’s, where r is regular expression,
Convenstions on regular expressions is written as rk. Thus, for example rr = r2. The language
1. Bold face is not used for regular expressions when the corresponding to rk is Lkr , where Lr is language
expression is not confusing. So, for example, (r + s) is
corresponding to the regular expression r. For a
used instead (r + s).
2. The operation * has precedence over concatentation, recursive definition of Lkr .
which further has precedence over union (+). Thus, 4. The (r+) is used as a regular expression to represent
the regular expression (a + b(c*))) is written as a + bc*.
3. The concatenation of k r’s, where r is regular expression, L+r .
is written as rk. Thus, for example rr = r2. The language Based on the concept, only 1 and 4 are found to be
corresponding to r k is Lkr , where Lr is language regular since in 1, L can be written as a* (bb)* and 4, (a
corresponding to the regular expression r. For a + b) * c(a + b)* can be written for the 4.
24. (c) The matched sequence is as given
recursive definition of Lkr .
4. The (r+) is used as a regular expression to represent List I List II
L+r . E. Checking that identifiers R. L = {WCW | W Î (a | b)*}
Since, language L can be expressed as are declared before their
r = [0 (0 + 1) * 0] + [1 (0 + 1) * 1] use.
and follows the above convention, therefore is regular F. Number of formal P. L = {anbmcndm |m ³ 1, m, ³ 1|}
19. (b) L = {Oi i2li | i > 0}, this language can’t be accepted parameters in the
byDFA to regular, but it is recursive & can be declaration of a function
accepted by PDA to CFL. agrees with the number
20. (a) It is given that the 0’s and 1’s are divisible by 3 and 5 of actual parameters in
and we know that 3 and 5 do not have any factor other use of that function
than themselves or 1 i.e., these cannot be further
breakdown. G. Arithmetic expressions Q. X ® XbX | XcX | dxf | g
Therefore, number of states = 3 × 5 = 15 with matched pairs of
The schematic representation is as follows: parentheses
1 H. Palindromes S. X ® bXb |cXc| e
1 1 1 1
1 2 3 4 5 25. (d) Statement 1 True: Left recursive and right recursive
0 0 grammar can be converted into each other.
0 0 0 0
0 0 0 Statement 2 True: All e-productions can be removed
from many context-free grammar by suitable
0 6 1 7 1 8 1 9 1 10 transformations.
Statement 3 False: The language is not always regular
0 0
0 0 0 since given the property of the context-free grammar
that the right side of the productions have any one of
1 1 1
11 12 13 14 1 15 the following.
X X X X X
EBD_7203
S3-276 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
1. single-terminal Statement 2 Undecidable: It is not decidable since the
2. non-terminal followed by a terminal language is context-free.
3. l Statement 3 Undecidable: It is also undecidable that
Statement 4 False: The derivation trees in CNF are whether two push-down automata accept the same
binary trees. language.
26. (a) Given: Transition table for Y and Z Statement 4 Decidable: If the LHS of each production
The number of states of Z = 2 has one and only one variable then it is a context-free
The number of states of Y = 2 grammar.
Z× Y 30. (d) (d) {aPPis a prime no.}
a b a, b This prime no. is extra constraint so this language is
a neither LFG nor RG but it can be accepted by turing
1 2 1 2 machine.
b a, b

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)

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


n n
{ }
A context-free language is L = a b : n ³ 1 that is

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

1/1 1/1 0/0 Here n = 4


So to accept all the substrings the no. of states
required are n + 1 = 4 + 1 = 5
11 0/0 10 Hence (c) is correct option.
39. (d) These sort of languages are accepted by PDA, so all
The desired output is obtained with the input string should be context free languages. L2 & L3 are definitely
101, however, the concern is number of states which CFL since accepted by stockof PDA.
we found to be 3. And also L1 & L4 are linear comparisons of i & j so can
34. (b) Regular expressions are meant for lexical analysis to also be represented using PDA. So all are context free
define tokens.Pushdown Automata is used to accept languages.
context free language which are used for syntax 40. (b) It is given that L is the set of all bit strings with even
analysis. number of 1’s so the regular expression should exhibit
Data flow analysis is a technique for code optimization. the same.
Register allocation is used for code generation. Now, the min string should be e and the string should
be e, 0, 11, 101, ...
So P-3, Q-1, R-4, S-2.
The string obtained from such expression is 0* (10* 10
35. (d) (a) true, since minimal DFA for every regular language
*)*
is possible.
41. (b) L1 ® recursive
(b) true, NFA can be converted into an equivalent
L2,L3 ® recursively enumerable but not recursive.
PDA. So L1 can be recursive enumerable.
(c) CG’S are not recursive but their complements are. RE - RE = RE
(d) false, since non deterministic PDA represents, non So L1 - L3 is recursively enumerable.
deterministic
CFG, since NDCFG and CFG are proper subsets so 42. (c) { }
L1 = 0 p1q | p, q Î N is regular language
conversion required.
36. (c) We are given with the relation
(0 + 1) * 0(0 + 1)* 0(0 + 1)*
{ }
L2 = 0p1q | p, q Î N and p = q is context-free
language
Here, the accepting languages are
L = {00, 000, 100, 001, 010, 0000, 0001, 1000, 1001, 0100, { }
L3 = 0p1q 0 r | p, q, r Î N and p = q = r is not
1100, 0010, 0011, 0110, 0101, 1010, ...}
context-free.
EBD_7203
S3-278 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
43. (a) As state (s) and (t) both are final states and accepting that the smallest disc is at the top position and the
a* + b*, we can combine both states and we will get largest disc is at the lowest position.
Mo
ve f
b b r om
p q r a, b A to C

a a
n – 1 discs n – 1 discs
a, b move from
s move from
A to B
B to C

Peg A Peg B Peg C


44. (b) As n is constant atleast n + 1 states will required to
design ank. For this, we can recursion algorithm. Firstly, we have
45. (b) DPDA and NPDA because an NPDA cannot be to move all upper n – 1 discs from peg A to B, then last
converted into DPDA. largest disc moved from peg A to C, then again (n – 1)
46. (c) å * - P and å * - P is the complement of P and discs moved from peg B to C.
Algorithm
complement of regular language is also regular.
function (n, A, B, C)
47. (b) {
ab function (n – 1, A, C, B);
cd 00 01 11 10
A®C
00 1 X X 1 function (n – 1, B, A, C);
01 X 1 }
Then, the recurrence relation for this problem is
11 T(n) = 2T(n – 1) + 1
51. (c) As we have given,
10 1 X
A(n) ® Average case complexity
W(n) ® Worst case complexity
As we know that average case will always be less than
b 'c'+ b ' d ' or bc + bd
or equal to worst case complexity.
48. (b) Given, there are n strings and length of each string is n.
A (n) £ W (n)
Normal recurrence relation for merge sort is
T(n) = 2T (n/2) + Cn Consider option (a):
Here, we need n comparisons to compare two strings A(n) = W (W(n))
i.e., 2 elements of set. \ It says W(n), worst case complexity is less than the
So, recurrence relation will be average case complexity which is wrong because W
T(n) = 2T (n/2) + Cn2 asymptotic notation shows (³) sign. Hence, this option
By solving this using master method, we will get is false.
T(n) = O (n2) Consider option (b)
49. (c) Time complexity to search an element in a balanced A(n) = q (W(n))
binary search tree is \ It says A(n), worst case complexity is same as worst
= log [number of elements in binary search tree] case complexity because q notation shows equality
= log [n × 2n] sign. Hence, this is false.
= log n + log 2n Consider option (c)
= log n + n log 2 A(n) = O (W(n))
\ It says that average case complexity A(n) is less
= log n + n (Q while log2 2 = 1) than or equal to W(n) worst case complexity. Hence,
= q (n) this option is correct.
50. (d) Tower of Hanoi problem with n discs are follows: Consider option (d)
We have given n discs in peg A and we have to move A(n) = O (W(n))
all n discs from A to C peg. We will take help of extra \ It says that A(n) is strictly less than W (n), so this
peg B and we arrange all the n discs in peg C as follows option is false.
THEORY OF COMPUTATION S3-279
52. (a) Considering the languages L1 = f and L2 = {a} q0 is the initial state. q4 is the final state.
For all languages L it is known that f . L = f FA state remains same when input symbol is “a” at
Suppose, $ a string s Î f.L any point of time.
When 1st ‘b’ is read, state is changed from q0 to q1.
$ s' such that s = s' . s" When 2nd ‘b’ is read, state is changed from q1 to q2.
and s¢Î fs¢¢Î L When 3rd ‘b’ is read, state is changed from q2 to q3.
But s¢Î f Q f is an empty language. & when 4th ‘b’ is read, state is changed from q3 to
q4.
\ f. L= f
If no more ‘b’ is encountered, the string is accepted
{e} Í L* for all languages L.
when last input symbol is read.
As it means taking letters from the language and
However if 5th “b” is there is string, state is changed
concatenating them ‘0’ times creating a ‘0’ length
from q1 to q2 so that to accept the string 2 more bs
string which is possible for all languages.
must be there in the string at least.
\ e is in f*
Continuing in this way only those strings are
L1 . L2 = f
and L1 = {e} accepted that has 3k + 1 (k Î N ) number of b’s. (i.e.
L1 . L2 * È L*1 = (L1 . L2) È L*1 4, 7, 10 ... number of b’s).
\ f È {e} = {e} 56. (a) Following paths can be taken by the finite Automaton
53. (c) 1. Non-deterministic Turing Machine can be for the input string “0011”:––
simulated by a deterministic Turing Machine with 0 rq0 uuuuuuuuu
q0 uuuuuuuuu 1 q0 uuuuuuuur
0 rq0 uuuuuuuur 1 q0
exponential time true.
2. Turing recongnizable language are “not” closed Reachable states
under complementation. For any Turing recognizable {q0 }
language the Turing Machine ‘T’ recognizing ‘L’ may
not terminate on inputs 0 rq0 uuuuuuuuu
q0 uuuuuuuuu 0 rq0 uuuuuuuur
1 q0 uuuuuuuur
1 q1
x Ï L - False {q0, q1}
3. Turing decidable languages are CLOSED under
0 rq0 uuuuuuuuu
q0 uuuuuuuuu 1 q1 uuuuuuuur
0 rq0 uuuuuuuur 1 q2
union and complementation. It is easy to determine
if turing machine is decidable-True (q0, q1, q2)
So, answer is option (c) only 2. We note that no other path is possible for the input
54. (d) 1. G is a CFG. Is L(G) = f? string “0011”.
Decidable So, finally union of all three cases gives us the set
2. G is a CFG. Is L(G) = S * ? of Reachable states which is {q0, q1, q2}
Undecidable
57. (c) Both L and L are recursively enumerable but not
3. M is a Turing Machine. Is L (M) regular?
recursive.
Undecidable.
4. A is a DFA and N is an NFA. Is L(A) = L(N)? Set of recursive languages is subset of the set of
Decidable. recursively enumerable languages.
Hence, the correct answer is (d) 2 and 3 only. So, if a language is recursive, It must be R.E. also.
55. (c) We know that a language L is regular if an equivalent (A) May be true as a language L and its complement L
finite Automaton can be constructed for it.
need not be recursively enumerable.
DFA can be constructed for L as follows:–
Note that L contains the strings that has 3k + 1 (B) May be true if L is r.e. but not recursive and L is not
number of b’s (that is 4, 7, 10, .......n ...... no. of b’s recursively enumerable
and any no. of a’s)
(D) May be true as L and L both can be recursive.
a a a a a However (C) is not possible because if Both L and L
are recursively enumerable than by a well known
q0 q1 q2 q3 q4 theorem of complexity theory either L or L has to be
b b b b
recursive.

b
EBD_7203
S3-280 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

58. (d) I, II and III. PRACTICE EXERCISE


Given DFA : 1. (c) Regular and context free languages are both closed
under union and concatenation while only regular is
O O closed under intersection.
1
\ Ans is (c)
2. (d) ac Î L(r1), since we can take b* as Î and c* as c
q0 q1
ac Î L(r 3 ), since ( a È b È c) * includes all
combinations of a, b, c.
1
ac Ï L ( r2 ) since when ever (a* b + c)* is taken to
(I) 0*1 (1 + 00 * 1)* it represents the given DFA include a, “a is always followed by b”.
using following transition:
a*b = b, ab, aab, .... & so on.
O* :– 1 q0 ® q0
\ Ans is (d)
1 :– q0 ® q1
3. (d) L(r1) is the Language starting with ‘a’.
(1 + 00 * 1) * :– q1 ® q0 ® q0 ® q1
L(r2) is the Language starting with ‘b’.
(1 +) (0) (0*) (1)
So, the string is accepted. Since any word belonging to å * either starts with “a”
(II) 0 * 1 * 1 + 11 * 0 * 1 :- or starts with “b” or is “l”, therefore
Following transition occurs :–
L ( r1 ) Ç L ( r2 ) Ç {l} = å *
0 * :– q0 ® q0
1 * :– q0 ® q0 (if 1 is absent) or 1 * : q0 ® q1 (if 1 is present) So, Ans is (d)
(1 + 11*) : q0 ® q1 q1 ® q1 4. (d) Note that
0 * :– q1 ® q1 (if 0 is absent) q1 ® q0 (if 0 is present) (b*a*) = (a*b*)* = (a* + b*)* = (a + b)*
1 :– q1 ® q1 q0 ® q1 so for (a) L ((b*a*)* (d*c*)* gives all the combinations
final state is q1 , this string is also accepted. of a and b followed by all the combinations of c & d.
(III) (0 + 1) * 1 :– Following transition occurs :– for (b) L((d*c*b*a*)*) = (a + b + c + d)*
(0 + 1) * :– q0 ® q0 ® q1 for (c) L((a*b*a*c*d*)*) = (a + b + c + d + a*)*
(0 +) (1) = (a + b + c + d)*
1 :– q1 ® q1 5. (b) Choice ‘a’ is incorrect since it does not include the
Ans final state is q1, so this string is also accepted. Hence string “a”, “b” and “l” (all of which do not end
(d) is true. with ab).
59. (a) None of choices ‘c’ or ‘d’ accept the string ‘a’, So they
60. (d) If B is not recursively enumerable then A need not be can’t be represent specified language.
recursively enumerable. 6. (a) For DFA accepting all the strings with number of ‘a’
61. (b) The language is recursive enumerable and it is
divisible by 4, four states are required similarly for DFA
undecidable
accepting all the strings with number of b’s divisible
62. (a) L1 is regular but L2 is not
by 5, five states are required and for their combination,
63. 3
states will be multiplied So 5 × 4 = 20 states will be
a * b * (ba) * a *
required.
Length O is present (as it accepts Î)
7. (b) The DFA will be
Length 1 is present (a, b)
Length 2 is present (aa, ab, ba, bb)
Length 3 is not present (bab not present) 1 0 0
Start
\ it is 3
1
64. (c) S* is countabily finite
1
2S * is power set of S*
The powerset of countabily infinite set is For these kind of problems the required number of
uncountable states are always equival to “the length of the string
\ 2S* is uncountable and S* is countable. that it is ending with” + 1
THEORY OF COMPUTATION S3-281
8. (c) Since L = X* = {0, 1}* = (0 + 1)* & R = {0n 1n | n > 0}, (a) L1 È L 2 is CFL
LUR produces (0 + 1)* which is regular language and R
(b) L1 Ç L 2 is not regular
is not regular as there is no regular expression for that.
(c) L1 * is regular
9. (b) Since L1 and L2 both are accepted by deterministic
Hence the correct Ans. is (b)
PDA (in both cases, no guessing is required for the
18. (b) Since å * is all the combinations of 0 and 1 and yet it
push and pop operations while operating the stack)
since these languages are accepted by DPDA, it will is enumerable and belongs to the category of countably
also be accepted by NPDA. infinite. But for 2å * which is the power set of
10. (b) Regular languages are closed under union, intersection, å * which is infinite. By diagonalisation argument,
complementation, kleen closure, concatenation. power set of any countably infinite set is always
According to closure properties so all of a, b, c, & d are
uncountable, hence 2å * belongs to uncountably
regular. Notice that, S* – L1 = Lc1 so, set L1 Ç L 2 is infinite set.
19. (a) Here for the languages (i) and (ii) we can design a PDA
also regular. Hence they are CFL.
11. (d) All of the above functions are total recursive functions. In (iii) and (iv) we cannot conclude that no(a) = no(c)
The total recursive functions are like recursive and no(b) = no(d) using only one stack memory so
language. Turing machine halts on each and every input they can’t CFL.
of recursive language. All of the above functions are 20. (c) Only option (c) satisfies the given machine, hence L(M)
turing computable. = {words containing aa or bb as a subword}
21. (b) Binary no. that are multiples of two is
12. (c) L1 = {anbncn, n ³ 0} = {l, abc, a2b2c2, ....}
L = {0, 10, 100, 1000, 110, 100, ...}
L2 = {a2nb2nc2n, n ³ 0} = {l, a2b2c2, a4b4c4, ....}
i.e. strings ending with 0
L3 = {a2nb2ncn, n ³ 0} = {l, a2b2c2, a4b4c2, ....} \ (b) (0/1)* 0 is the correct answer.
as we can easily see that
a
(i) L1 contains all the words generated by L2 and also it
contains some extra strings also.
Start c
22. (a) T
\ L1 Ê L 2 ( or L2 Í L1 )
(ii) Since only l is common in L2 and L3
b
Hence L 2 Ë L3
The language generated by the above DFA is starting
13. (a) 1. 0*1* does not ensure at least one 0 at the with c followed by any no. of a’s & b’s.
beginning and one 1 at the end.
2. 00*(0 + 1)*1 ensures the specified condition. Hence L = c ( a È b ) *
3. 0(0 + 1)*1 ensures the specified condition. 23. (b) Since L1 cannot be recognized by PDA but L2 can be
14. (b) The given grammer is context-free. It is not proper since recognized by a PDA. L1 is not context free but L2 is
context free.
it includes an ?-production. A typical derivation in this
For L2 = {anbmcmdn | n ³ 1, m ³ 1}
grammar is
a’s are pushed into stack, then b’s are pushed then b’s
S ® aSa ® aaSaa ® aabSbaa ® aabbaa. are popped from the stack checking with each arrival
This makes it clear that L(G) = {wwR : w Î {a, b}*}. of corresponding c. After all b’s are popped and if no.
The language is context-free. of b’s popped = no. of c’s arrived then, as a will be at
15. (d) According to the definition of Moore machine (d) is top of stack, when the first d arrives.
the only correct option. So, no of b’s = no. of c’s [m = m]. Similarly when d’s
arrive, we can check that
16. (b) 1. r1 =Î is a regular expression representing a set
No. of a’s = No. of d’s [n = n], by poppping an a for
{Î}. It is a regular expression. every d and checking that at end of input stack is empty.
2. r2 = 0*1* is a regular expression. This can’t be done in the case of L1, since after pushing
17. (b) Since L1 and L2 are regular and context free languages a’s & then b’s, when c’s appear in input, they have to
respectively CFL are closed under regular È, Ç , be compared with a’s which are unfortunately at the
bottom of the stack and cannot be popped to do a
therefore comparison.
EBD_7203
S3-282 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
24. (b) The DFA’s construction for the grammars

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

We can clearly see that any no. of loops of “ab” and a


“bb” can be accepted and ‘0’ is the accepting state.
48. (c) The given regular expression 00(1 + 10)* is not
complete to denotes all strings of 0’s and 1’s with 53. (c) L1 = ambn | n = m2
atleast two consecutive 0’s. L2 = ambmcmdn | m, n > 0
The correct regular expression must be
L3 = ambmcndn | m, n > 0
(0 + 1)*00 (0 + 1)*
49. (a) Deterministic PDA can accept In L1, n = m2 cannot be checks in stack as m2 is a
(b) The set of all strings of balanced parenthesis. nonlinear function. Hence it is not CFL.
EBD_7203
S3-284 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
L2 requires 2 comparisons on no. as itself. Therefore the remaining productions left after removing
Þ no. of a’s = no. of b’s and no. of c’s. This cannot useless, unit and l-productions
be done by single stack. S ¾¾
® aA | a, A ¾¾
® aa | aaA
L3 requires 2 comparisons, but only one at a time is 60. (a) The TM carries out the functions of (m – n) in (0 m 10n)
required
® when m ³ n, the output is difference between m and n.
Þ no. of a’s = no. of b’s and no. of c’s = no. of d’s.
® when m < n, the output is blank.
This cannot be done by single stack.
61. (c)
54. (c) L1 and L2 are context free languages. We can see that
L2 is in fact a regular language having regular 62. (b) Suppose, S = aaab, | s | = 4 . The prefixes are
expression a(ba)*. Sp = {l, a, aa, aaa, aaab}. Here aaab is not a proper
L1 is a language containing strings having equal prefix.
number of a’s and b’s Note: The proper prefix of string S is a prefix, which is
not same as string S.
Þ L3 = L1 Ç L 2 is a context free language.
A string of length 4 has 4 proper prefixes. A string of
Q class of context free languages is closed under length 5 has 5 proper prefixes. For a string of length n,
concatenation and kleene closure. Therefore L4 = therefore we can have ‘n’ proper prefixes.
L1.L1* is a context free.
63. (a) The following CFG
55. (c) Drawing the equivalent turing machine we have
S ® aB | bA
A ® ba | aS | bAA
0, 0, R
Y, Y, R B ® b | bS | aBB
0, X, R
q0 q1 q2 0, 0, L by observing the given CFG we can see that with each
1, Y, L Y, Y, L non-terminal, number of a’s and b’s get equalled.
Y, Y, R The language is the strings of terminals that have equal
X, X, R number of a’s and b’s
64 (a) Rule: a* (a*b)* = a*(ba*)* ¹ (a + b)*
q3 q4
B, B, R So, 0* (10*) * = 1* ( 01*) *

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

Syntax Directed Translation

N Ø Runtime environments

T
Ø Intermediate and target code generation

Ø Basics of code optimization

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

Interaction between lexical analyzer and Passer

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

Else Characters e,l,s,e Else

Comparison operators < or > or <= or >= or == <,>

Number Any numeric constants 0,180,3.14

Literal Any character within “ “, except “ “compiler design”

Id Letter followed by letters and digits Pi, count

Attributes for token


When more than one lexeme can match a pattern, the lexical analyzer should give the
additional information of the lexeme that matched to the subsequent phase of the
compiler. Thus, the lexical analyzer returns not only the token name to the parser but
an attribute value that describes the lexeme represented by the token in many cases.
When a token is a simple construct like a left parenthesis, comma, dot, the
representation of that token is an integer code. And when a token is little more
complex like an identifier or a constant then representation of a token is a pair
consisting of an integer and a pointer to a table. The integer code gives the token
type and the pointer, points to the value of that token in the table.
Lexical errors
The lexical analyzer cannot identify if there is source-code error. For instance, if the
string fi is encountered in a C program for the first time in the context, a lexical
analyzer cannot say whether fi is a misspelling of keyword if or an undeclared
identifier.
Buffer Pairs
The amount of time taken to process characters and large numbers of characters that
must be processed during compilation of a large process program creates overhead.
To reduce this overhead to process a single input character, there are specialized
buffering techniques. This involves two buffers that are alternately reloaded. Each
buffer is of same size N which is usually size of the disk block.
Two pointers to the pointers are maintained,
1. Pointer Lexime begin – marks the beginning of the current lexime
2. Pointer forward scans forward for the exact match

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

Start state Final state


a

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

Start state b Final state Lex Specification


b
DIGITS [0 - 9] ü
0 a 1 2 3 ï
Start b b ------------------ ý Lex definition
a ï
a ------------------ þ
a
DFA accepting (a/b)*abb %%
ü
expression ï
Finite automata ïï
Finite automata is similar to transition diagrams which have states and labeled edges integer ý Translation rules
ï
and there will be one unique state and one or more final states. action ï
Finite automata can be further divided into, printf(”INT”); ïþ
1. Nondeterministic finite automata (NFA) can have multiple paths and have e
labeled edges. These edges are called e - transitions. Some of the characters ------------------
ü
can label 2 or more edges out of the same state. Example, ------------------
ï
2. Deterministic finite automata(DFA) , no edges are labeled with e and each ï
%% ï
character can label at most one edge out of same state. DFA has one unique ï
path. char getchar() ý User’s functions
ï
{________ ï
LEX
ï
Lex is a program generator. It takes lexical specification as input and gives a lexical } ïþ
processor written in C language.
Implementation of Lex,
Lex spec à NFA à DFAà Transition tables + actions àyylex( )

Expression is a regular expression and action is a piece of code of C programming.


SYNTAX ANALYSIS OR PARSING
Syntax Analysis is the second phase of the compiler after Lexical Analysis. It is also
called as hierarchical analysis or Parsing.
The role of Parser
The parser obtains a string of tokens from lexical analyzer and verifies that the string
can be generated by the grammar for the source language.
EBD_7203
S3-294 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
It groups Tokens of Source program into grammatical production and generates
parsing tree.
The schematic representation of parser can be shown as below,
Token
Source Lexical Parse Rest of Intermediate
Program Analyser Parser
Tree Front end Representation
get next
token

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

T.vol = 2 * F.vol = 6 digit.lexvol = 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

Sol: S -> while ( {L1=new();L2=new();C.false=S.next;C.true=L2;}


C) {S1.next=L1;}
S1{S.code=label||L1||C.code||label||L2||S1.code;}
EBD_7203
S3-304 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Example:
Steps to construct parse tree for a+2*c
Sol: Steps in the construction of syntax tree
(1) S1 = new leaf (id, entry a);
(2). S2 = new leaf (num 2);
(3) S3 = new node (+, S1, S2);
(4) S4 = new leaf (id, entry c);
(5) S5 = new node (*, S3, S4);
Dependency graph for a + 2 * c with L-attributed SDD
E¢ 13 node
1/2
E¢ syn
5 inh
T 2 node E¢ 1.1 syn
+ inh 6
T 4 node 10 syn
id 1 entry 9 inh E1
8 node
* T
num 3 vol E

Syntax Directed Schemes


SDT is a complementary notation of SDD. SDT is a context free grammar with program
fragments called semantic actions embedded with production bodies. SDT can be
implemented by building a parse tree and performing actions in a left to right depth-
first order i.e during a pre-order traversal.
Postfix translation schemes
Each semantic action can be placed at the end of the production and executed along
Example for implementing desk with reducing the body to the head of the production. This type of SDT is called
calculator postfix SDT.
Postfix translation schemes RU NTI ME ENV IR ONMENT
Eg., To implement the disk calculator
L ® Em {Print (E.vol)} These were completely language independent, i.e. independent of target language.
E ® E1 + T {E.vol = E1.vol + T.vol)} The runtime environment which concentrates on target machines memory structures
E ® T {E.vol = T.vol)}; and maintenance of memory is explained in this topic.
T ® T1 * F {T. vol = T1.vol × F.vol}; There are mainly three types of environment,
T ® F {T. vol = F.vol}; - Static environment used in language like FORTRAN 77
F ® (E) {F.vol = E.vol}; - Stack based environment used in languages like Pascal, C,C++
F ® digit {F.vol = digit.lexvol;} - Fully dynamic environment used in LISP language
The following steps are involved to Including to these there can be hybrid environments. The environment takes care of
implement properties like scoping, procedure calls and parameter passing mechanisms. The
– Parser Stack implementation of
allocation and de allocation of memory objects is managed by the runtime support
postfix SD'T
packages consisting of routines loaded with generated target code.
• Semantic analysis during
Parsing Memory organization during program execution
• SDT for infix-prefix translation The memory for program execution is broadly divided into two areas called data area
during Parsing and program area. The data area is used to store user data. It stores global or static
• Constructing Parse tree with constants or literals. Generally the content of the program area do not change during
actions enludeded program execution.
– Eliminating left recursions from Example:
SDT's Printf(“The solution is = %d”,234);
– SDT's for c-attributed definitions In the example the constant 234 and the string “The solution is=” is stored in global
– SDD for typesetting of bores in area. For the local variables whose value changes during the execution should be
calculated stored locally and for this purpose the stacks are used.
– Implementary control statements The runtime is divided into following parts,
COMPILER DESIGN S3-305
– Code area to store target code
– Static data area to store global and local variables Code Area
– Stack area to store activation records
– Heap used to dynamic memory allocation Global
Stack and heap have separate memory blocks or sometimes may share same memory static area
area.
Activation record Stack
Activation record is one of the important units of memory allocation for function or
procedure calls. Whenever the function is called the activation record of that function
is created and stored on stack. The runtime environment decides the sequence of
operations that must be performed when a function is called. Free space
The components of activation record are
– Return value - The value which will be returned by the function after
performing some action. This value will be stored in this.
– Actual parameters – These are used to send the inputs to the function from Heap
caller functions
– Optional control link- pointer to the activation record of the caller function
– Optional access link- pointer to caller local data area to access global data Different memory Areas for
– Machine status – values of program counter, machine registers, etc Runtime environment
– Local data of function
– Temporaries
Static runtime environment Code for main
The data is stored in fixed memory locations during the execution of the program in
static runtime environment. The languages which use this runtime environment do not
have the concepts of pointer variables, dynamic memory allocation and recursive Code for function i
functions.
The global variables and other variables are allocated statically. Each procedure has Code for function n
only a single activation record. All variable, whether local or global can be accessed
via fixed address.
The memory organization of static environment is as shown below, Global data
The calling sequence of the function is,
– Each argument is computed and stored in its appropriate parameter location. Activation record for function i
– The return address is saved and jump to the begging of the caller function.
– On return, a simple jump to the return address.
Example:
Int a = 20;
Main()
{ int x, y; Activation record for function n
Y =a;
Memory organization
X= fun(g); for static environment
Printf (“x= %d”, x);
Int fun(int a)
{
a Global variables
Int b;
B = a*10;
Return b; x
} Activation
Memory allocation for the above example shown in side fig. record of main
y
Stack based environment
The machine which supports stack based environments stores the activation records Activation
a
for procedure call in the stack manner than static way. This kind of allocation is record of function
efficient when there are recursive calls and local variables are allocated new values
at every execution. Every procedure is having a new activation records on the call
Return
stack any time. New activation records are pushed on the top of stack at every address
function call. b
EBD_7203
S3-306 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
This environment requires three pointers,
– Pointer to access current activation records to access local variables and the
pointer is called current activation pointer.
– Pointer to previous activation record
– Stack pointer which points to top of the stack.

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)

control link Activation record of


return address procedure containing
the expression
fp

Address of x [I]

Result of I + j Stack of temporaries

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

return address Activation record to call P

a;

I; Allocated area for block 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

Token Abstrat Static Decorated Intermediate


Parser Intermediate
stream syntax tree checker Abstrat code generator code
syntax tree

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 *

id id Cond Body Cond Then else LHS RHS


+ *
d
DAG (Directed Acyclic graph)- It’s variant of syntax tree.
*
A DAG identifies the common sub expression of the given expression. A DAG has
a
leaves corresponding to atomic operands and interior nodes corresponding to

operators. DAG gives clues to compiler to generate efficient code to evaluate the
b c expression.
Example: Three address Code (TAC)
Three Address code TAC is a statement containing at most 3 addresses or operands.
For the alone DAG, TAC can be written The general form is x:= y op z where op stands for operator. X is the result, y and
as, z are the operands which may be variables, constants or temporaries. TAC is the linear
representation of a binary syntax tree.
T1 = b – c
T2 = a * t Addresses and Instructions
T3 = a + t2 In TAC, the addresses may be one of the following,
T4 = t1 * d – A name, is a symbol table index.
T5 = t3 – t4 – A constant
– A compiler generated temporaries to evaluate the expressions.
Instructions, the instructions in TAC includes
– Symbolic label will be used which alters the flow of control.
L : x1= x2 op x3
– Assignment instructions
X= y op z
– Unary assignments
– Copy instructions
– Unconditional jump
– Conditional jumps
– Procedure calls
– Functional calls
– Indexed copy instructions
– Address and pointer instructions
Three address code representation
The representation includes
– Quadruples: In this representation, for a given instruction includes op,
arg1,arg2 and result.
Example a = b * – c + b * – c

op org1 org2 result

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

There are two forms of type checking, byte


1. Type synthesis is where the types of parts are used to infer the type of
whole. Example, integer + real = real
2. Type inference is where the type construct is determined from usage. This
permits the language where the names need not be declared.
EBD_7203
S3-312 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Type conversions
The type system offers the programmer the functions explicitly convert between
selected types. This is offered by the compiler and is called type coercion. For
example,
Control Flow
This includes the study of Boolean expression and has following two rules,
1. They can treated as normal integers or real, can be declared as Boolean
variables and they are Boolean constants or operators.
2. They are used in certain statements which alter normal flow of control.
Short-circuit code
This is also called jumping code. In this we just generate jumps to either true branch
or false branch for operators like AND, OR or NOT.
Example:
Short circuit code
if (x<100 II x>200 & & x ! = y) x = 0;
if x < 100 goto L2
if false * > 200 goto L1
if False x ! = y goto L1
L2 : x = 0
4:
Source Backpatching:
if a or b then In backpatching the list of statements for true and false of Boolean expression are
if c then separately maintained. Once a specific statement is encountered, the compiler
x= y+ 1 backpatches the address or statement number.
Translation The following functions which are used are,
if a go to L1 Make list(i) – this creates a list containing only i. this returns the pointer to the newly
if b go to L1 created list.
go to L3 Merge(p1,p2) – Concatenates the lists p1 and p2 and returns the pointer to the new
L1 : if c go to L2 concatenated list.
go to L3 Backpatch(p,i) – inserts I as the target label on the list pointed by p.
L2 : x = y + 1
L3 : After Backpatching
100 : if a go to 103
CO DE G ENERATI ON
101 : if b go to 103 The final phase of our compiler is code generation and it takes the input from
intermediate code generation phase and produces an equivalent target program.
The schematic representation of position of code generator,

Source Front Intermediate Code Intermediate Code TAK4


Program end code optimizer code optimizer AK09 KAH

Symbol
Table

Issues in the design of a code generator


The details are dependent on the target language but the issues like memory
management, instruction selection, register allocation and evaluation order are
inherent in almost code generations.
Input to the code generator
The input to the code generator comes from intermediate code generation phase with
information in the symbol table which determines the runtime addresses of the data
COMPILER DESIGN S3-313
objects. There are several choices for the intermediate language including linear
representations like postfix notation, three address representations like quadruples,
triples and virtual machine representation like syntax trees and dags
Target programs
The output of the code generator is the target program. The output may be of any form,
absolute machine language, relocatable machine language or assembly language.
Getting an absolute machine language as output has the advantage that it can be
placed in a location in memory and immediately executed.
Producing a relocatable machine language as output allows the subprograms to be
compiled separately. A set of relocatable modules can be linked together and can be
executed using a link loader.
Producing an assembly language makes the process of code generation easier. The
symbolic instructions can be generated and the macro facilities of the assembler can
be used to generate code.
Memory management Target Program Code
Mapping of the names in the source program to the addresses of the data object in The back-end code generator of a
runtime memory is done cooperatively by the front end and the code generator. compiler may generate different forms
Instruction selection of code, depending on the requirements:
• Absolute mach ine code
The uniformity and completeness of the instruction set are important factors. If the
(executable code)
target machine doesn’t support different data type then each exception should be
• Relocatable machine code (object
handled in a special way. Instruction speeds and machine idioms are also important
files for linker)
factors. For each type of TAS we can design a code skeleton that outlines the target
• Assembly language (facilitates
code.
debugging)
Register allocation • Byte code forms for interpreters
The instructions having register operands are shorter and faster than the operands (e.g. JVM)
used in memory. An efficient utilization of register is important in generation good
code.
The use of registers usually has two sub problems
1. During register allocation, the set of variables that will reside in registers are
selected at a point in the program.
2. During subsequent register assignment, we pick the specific registry that a
variable will reside in.
Choice of evaluation order
The order in which the computations are done can affect the efficiency of target code.
Some computations require lesser registeres to hold the values generated in
intermediate code generation. The code would be generated for three address
statements in the same order produced by intermediate code generator.
Basic blocks and flow graphs
A graphic representation of three address statements is called a flow graph. It is
useful in understanding code generation algorithms. Nodes in the flow graph
represent computation and the edge represents the flow of control.
Basic blocks
A basic block is a sequence of consecutive statements in which the control flow Example :
enters the beginning and leaves the end without a possibility of halt or branching x1 = a * a
except for the end. x2 = a * b
The algorithm used to partition of a sequence into basic blocks, x3 = z * t2
Algorithm: Partition into basic blocks x4 = x1 + x2
Input: A sequence of three address statement x5 = b * b
Output: A list of basic blocks x6 = t4 + t5
EBD_7203
S3-314 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Method:
1. First determine the set of leaders, the first statement of basic blocks.
The rules used are as below,
– The first statement is a leader.
– Any statement that is target of a conditional or unconditional goto is
a leader.
– Any statement that immediately follows a go to or conditional go to
is a leader.
2. For each leader, its basic block consists of the leader and all the statements
upto next leader excluding next leader or the end of the program.
Transformations of basic blocks
A basic block computes a set of expressions and two basic blocks are said to be
equivalent if they compute the same set of instructions. A number of transformations
can be applied to the basic blocks without changing the value of expressions
computed by the block. The two important classes are structure preserving
transformation and algebraic transformation.
The primary structure preserving transformations on basic blocks are,
1. Common sub-expression elimination
2. Dead code elimination
Suppose x is dead and never to be used then the expression x:=y+z appears
in a basic block can be safely removed without affecting a basic block
3. Renaming of temporary variables
Consider a statement t:=a+b where t is a temporary. If the statement is
changed to u:=a+b where u is a new temporary variable. The change all uses
the value u in place of t , the value of basic blocks remains the same.
4. Interchange of two adjacent statements
Suppose we have a block with two adjacent statements,
T1:= a+b
T2:= x+y
Then we can interchange the two statements without affecting the value of a block.
Instructions and address mode of target machine
The target machine characteristics are
1. Byte addressable
· Two operand instructions
· Op, source, destination
· Several addressing codes
· Example opcodes: MOV,ADD, SUB, MULT
Table to show the mode and addresses
Addressing modes and extra costs

Mode Form Address Extra cost

Absolute M M 1

l Machine is a simple processor with


Register R R 0 fixed instruction costs Define the
cost of instruction = It cost (source-
Indexed K(R) K+ 1
contents (R)
mode) + cost (destination mode)

Indirect *R Contents (R) 0


Register
Indirect *K(R) Cont (K) 1
Indexed + cont (R)
COMPILER DESIGN S3-315
Example : to generate target code for the source language
(a – b) + (b – c) + (a – c)
The SAC for this can be written as
t:=a–b
u:=b–c
v:=t+u
w = v + u || d
The code sequence generated by simple code generation alogarithm.
Statements Generated code Reg Des AdDes
Registers empty
® t:=a–b Mov a, R0 R0 contains t t in R0
SUB b, R0
® u:=b–c Mov b, R1 R0 has t t in R0
SUB c, R1 R1 has u u in R1
® v:=t+u ADD R1, R0 R0 has v u in R1
R1 has u v in R0
® d:=v+u ADD R1, R0 R0 contain d d in R0
d in R0 & memory

THE BASICS OF CODE OPTIMIZATION


The optimized code executes faster, provides efficient memory storage and yields
better performance. Compilers can be designed to provide code optimizations. User
should focus on the optimizations which are not provided by the compiler like
choosing a faster or less memory usage algorithm.
The code optimizer sits between the front end and the code generator. This works at
intermediate code generator stage, it can perform control flow analysis and data flow
analysis. And does transformations to improve the intermediate code.
Compiler code optimizations:
Optimization provided be a compiler are as below:
– Inlining small functions: this involves in repeatedly inserting the function
code instead of calling it. This reduces the calling overhead and enables
further optimizations. Inlining large function will make the executable large.
– Code hoisting: this involves in moving computation s outside the loop and
this saves computing time.
Example:
[(20) * PI] is an invariant expression and need not be computed 100 times.
Do I = 1, 100
ARRAY (I) 2.0 * P1 * 1
END Do
Using a temporary variable t, it can be transformed to
t = 2 * 0 * P1
DoI = 1, 100
ARRAY (1) = t * I
END Do
x = A * LOG (y) + (LOG (y) * * 2)
Introduce an explicit temporary variable t :
t : LOG (y)
x = A * t + (t * * 2)
This saves the heavy function call, by an elimination of common sub-
expression LOG (y).
EBD_7203
S3-316 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
– Dead store elimination: If the compiler detects variables which are never
used , it may safely ignore many of the operations that compute their values.
– Eliminating common sub expression
– Loop unrolling: Loop exit checks costs CPU time. This tries to get rid of all
checks or atleast minimize the number of checks. If it is known that the loop
is only performed a certain number of time, it can be unrolled.
Example:
Loop unrolling
| | old loop
for (int i = 0; i < 3; i + +)
{ color, map [n + i] = i;
}
| | unrolled version
int i = 0;
Color map [n + i] = i;
i + +;
Color map [n + i] = i,
i + +;
Color map [n + i] = i;
– Loop optimizations which include code motion, induction variable elimination
and reduction in strength.
Code motion
Any code inside a loop which computes the same value can be moved before the
loop.
COMPILER DESIGN S3-317

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

Addres s Type Name 20000788 T __aeab i_ uidiv

00000020 a T_BIT 20000788 T __udiv si3

00000040 a F_BIT 20000884 T __aeabi_uidivmod

00000080 a I_BIT 2000089c T __aeab i_ id iv0

20000004 t irqv ec 2000089c T __aeab i_ ld iv0

20000008 t fiqv ec 2000089c T __ div0

2000000c t InitRes et 200009a0 D _data

20000018 T _main 200009a0 A _etext

20000024 t End 200009a0 D holaamigo sh

20000030 T A T91F_US3_CfgPIO_us eB 200009a4 A __bs s _end__

2000005c t A T91F_ PIO_CfgPerip h 200009a4 A _ _bs s_ start

200000b 0 T main 200009a4 A __ bs s_s tart__

20000120 T A T91F_DBGU_Printk 200009a4 A _edata

20000190 t A T91F_US_TxReady 200009a4 A _end


26. (b) Let us consider the given expression (7¯3­4­3¯2).
200001c0 t A T91F_US_Pu tChar
Since the precedence of ­ is higher, the sub-expression
200001f8 T A T91F_Sp urious Handler (3­4­3) will be evaluated first. In this sub-expression,
4­3 would be evaluated first because ­ is right to left
20000214 T A T91F_DataA bo rt
associative. So the expression is evaluated as
20000230 T A T91F_ FetchA bort ((7¯(3­(4­3)))¯2). Also, note that among the two ¯
operators, first one is evaluated before the second one
2000024c T A T91F_Undef
because the associativity of ¯ is left to right.
27. (c) In a compiler, keyboards of a language are recognized
during the lexical analysis of the program. Typically,
EBD_7203
S3-338 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
the lexical analysis phase of compilation breaks the (b) L1 Ç L2 is context Free – true
input text up into sequences of lexemes that each Here L1 Ç L2 = L2 which is context Free.
belongs to some particular token type that's useful in (c) Complement of L2 is recursive – true
later analysis. Consequently, keywords are usually first L2 is Context-Free language
recognized during lexical analysis in order to make
Complement of CFL may or may not be CFL.
parsing easier. Since parsers tend to be implemented
Complement by CFL is definately recursive.
by writing context-free grammars of tokens rather than
of lexemes (that is, the category of the lexeme rather (d) Complement of L1 is Context Free, but not regular
than the contents of the lexeme), it is significantly easier false.
to build a parser when keywords are marked during
L1 = {0p qq 0r }
lexing. p,q,r ³ 0
28. (a) Lexical analysis is the first step in compilation. In lexical
analysis, program is divided into tokens. Lexical 0 0
analyzers are typically based on finite state automata. 0 1 0
Tokens can typically be expressed as different regular
expressions:
An identifier is given by [a-zA-Z][a-zA-Z0-9]* 1
The keyword if is given by if.
0, 1
Integers are given by [+-]?[0-9]+.
29. (a) First (S) = first (aAbB) È First (bAaB) È Î Which is regular,
= {a} È {b} È Î
0 1 0
= {a, b,Î} 0 1 0
L1=
First (A) = First S = {a, b,Î}
1
First (B) = First S = {a, b,Î}
Follow (S) = {$} È follow (A) È follows (B) Regular
Follow (A) = {a, b} Hence, the answer is (d).
Follow (B) = Follow (S) = {$, a, b} 34. (d) Statement "None of my friends are perfect." The
30. (c) Entry E for [S, a] = {S ® aAbB, S ® Î } statement means that of all the friends that I have,
S ® aAbB none of them are perfect.
First (aAbB) = {a} Hence, if we consider only a friend and if any of them
S ® aAbB being perfect the logical representation would be
First (bAaB) = {b}
Put (S ® Î ) production as per follow (S) $´ ( F ( x ) Ù P ( x))
Follow (S) = {a, b, $} Now we need to negate this statement since none of
Hence, (S ® Î ) will come in [S, a], [S, b] and [S, $] the friends is perfect
Entry E2 for [S, b] = {S ® bAaB, S ® Î } Ø$´ ( F ( x) Ù P ( x))
Entry E3 for [B, $] = {B ® S} 35. (a) “Find the distinct names of all students who score
Production {B ® S} will come in as per more than 90% in the course numbered 107”.
First (S) = {a, b, Î } 1. SQL Query Condition would give all sname
Hence, put B ® S in [B, a] [B, b] having score > 90 and attending course no. 107
First (S) contains Î so consider [S, $] and
Put [B ® S] in [S, $] DISTINCT S.sname will give distinct student
31. (c) The maximum number of reduce moves that can be names, true
taken by a bottom-up parser for a grammar with no 2. Relational Algebra psname gives projection of all
epsilon and unit production (i.e., of type A ® e and students meeting the condition and p gives
A ® a) to parse a string with n taken (c) 2n – 1 DISTINCT value, true
32. (d) 3. Tuple Calculus Gives DISTINCT student name
33. (d) L1 = {0p1q,0r| p, q, r ³ 0} having score > 90 and course No is 107. true
L2 = {0p1q0r| p, q, r ³ 0, p ¹ r} 4. Domain Calculus Domain Calculus is equivalent
(a) L2 is context Free – true to relational algebra and provide distinct value
We can accept, or reject L2 with single stack. for the query. true.
Insert P 0's into stack skip q 1's. Hence, all queries are equivalent to this query in
For each 0 corresponding to r, remove 0 from stack. English, (a) I, II, III and IV.
COMPILER DESIGN S3-339
36. (d) The statement:–
x = 4 × 5 Þ x = 20 + d, a
‘is an example of common subexpression elimination.] c, e
is False. + a
Explanation:
+
Common Subexpression elimination is a compiter
optimization that searches for instances of identical
expressions (that evaluate to same value) and
analyses whether it is worthwhile replacing them d c b
with a single variable holding the computed value.
example: The maximum number of nodes and edges is (6, 6)
Z1 = (x + y) + 1; 45. (a) There is no algorithm for ambiguity of CFG
Z2 = (x + y) + b; 46. (c) L1 and L2 have deterministic push down automata
Z3 = (x + y) + c; but for L3 only not-deterministic PDA is possible.
Above code segment may be transformed to: So L3 is not deterministic.
tmp = x + y;
Z1 = tmp + a; PRACTICE EXERCISE
Z2 = tmp + b;
Z3 = tmp + c; 1. (d) Syntax analysis checks for the syntax of the source
So, the addition (x + y) is performed only once. program while the semantic analysis, deals with
checking of semantic (meaning) of the source program
It is worth noting that the given option (D)
output by syntax analysis phase and input to semantic
x = 4 × 5 Þ x = 20 analysis phase.
is called the “constant folding” technique of compiler Note: The syntax checking is responsibility of the
optimization. programmer while semantic analysis is checked at the
37. (d) Neither a shift reduce nor a reduce-reduce conflict. runtime.
38. (b) + is right associative (with right recursion from S) 2. (b)
is left associative (with left recursion from T) 3. (c) If conversion from one type to another type is
39. (a) Dynamic memory allocation is not performed during doneautomatically by the compiler then, it is called
compilation. implicit conversion and coercions. Each programming
language has its own rules on how types can be
It is performed during sun time not during complete
converted. In general, both objects and fundamental
time data types can be converted. In most languages, the
40. (a) X is declared as “int × [32] [32] [8]” word coercion is used to denote an implicit conversion,
41. (c) Intermediate code makes it easy to retarget the either during compilation or during run time.
compiler to generate code for newer and different 4. (b) The term “environment” in programming language
processors.
semantics is said as function that maps a name to a
42. (d) Heap is essential to allocate memory for data
structures at runtime, not for recurssion storage location. In programming languages, a closure
43. 122 (also lexical closure or function closure) is a function
Tave = H1 × (TTLB + TM) + (1 – H1) × (TTLB + 2 × TM) or reference to a function together with a referencing
TTLB = 10 ms environment—a table storing a reference to each of
TM = 30 ms
the non-local variables (also called free variables or
H1 = 0.6
Tave = 0.6 X ( 10 + 80) + (1 – 0.6) (10 + 2X80) upvalues) of that function.
= 0.6 X 90 + 0.4X 170 5. (a)
= 122 ms 6. (b) A compiler reads, analyses and translates code into
44. (a) The given block is either an object file or a list of error messages. A linker
combines one or more object files and possible some
a=b+c
library code into either some executable, some library
c=a+d=b+c+d or a list of error messages. A loader reads the executable
d=b+c code into memory, does some address translation and
= b + b + c + d = 2b + c + d tries to run the program resulting in a running program
e=d–b=b+b+c+d–b=b+c+d or an error message (or both).
a = e + b = b + b + c + d = 2b + c + d 7. (a)
Therefore e and c are same, a and d are same. 8. (c) Simple two-pass assembler
The DAG generated is as follows : (1) Allocates space for the literals.
(2) Computers the total length of program (syntax analysis)
(3) Builds the symbol table for the symbols and their values
EBD_7203
S3-340 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
9. (c) 20. (b) BOTTOM-UP PARSING constructs a parse tree for an
10. (a) An assembler is a program that takes basic computer input string beginning at the leaves and working up
instructions and converts them into a pattern of bits towards the root.
that the computer’s processor can use to perform its • To do so, bottom-up parsing tries to find a
basic operations. Some people call these instructions rightmost derivation of a given string backwards.
assembler language and others use the term assembly • Bottom-up parsing is also called shift-and-reduce
language parsing where
11. (d) Since the programming language is to be designed to
– shift means read the next token,
run on a machine that does not have a big memory.
Therefore pass-2 (multiphase), which uses less space – reduce means that a substring b matching
is preferred also instead of using a compiler we use an the right side of a production A b is
interpreter which scans the program line by line hence replaced by A.
uses less memory at compiler time for each instance.
Also it does not support recursion. 21. (c) Top-down parsing (LL) : In top down parsing, we just
12. (b) In this scheme, an assembler runs in one portion of start with the start symbol and compare the right side
memory and assembled machine instructions and data of the different productions against the first piece of
are directly placed into their assigned memory locations
as soon as they are assembled. When an assembly is input to see which of the productions should be used.
completed, the assembler causes the transfer to the A top down parser is called LL parser because it parses
starting instruction of a program. This is a simple the input from Left to right, and constructs a Leftmost
solution used by WATFOR FORTRAN compiler and
several other language processors. The compile and derivation of the sentence.
go loader scheme is shown below. 22. (a) (.)
Disadvantages:
1. A portion of memory is wasted because the
memory occupied by an assembler is unavailable
(+) C
to the object program.
2. It is necessary to retranslate the users program
every time it is run.
3. It is difficult to handle multiple segments A B
especially if the source programs are in different
By applying inorder traversal we have (A + B) * C
languages (i.e one subroutine in FORTRAN and
23. (d)
other in C/C++ and still other in assembly
24. (d) The algorithms which generate parsers from grammars
language). This disadvantage makes it difficult to
get to “conflict”points when they need to disambiguate
produce orderly modular programs.
the grammar, and at those points one can essentially
13. (a) The task of the lexical analysis phase is to parse the
iterate to find k (and then take the max k over all the
source program into the basic elements or tokens of
points to determine k for a given grammar). In some
the language. The lexical analyze is the first phase of a
cases, you can easily establish that there is no such k.
compiler. Its main task is to read input characters and
However, there are other cases where the existence of
produce as output a sequence of tokens that the parser
k cannot be easily proven or disproven. There are ways
uses for the next phase, the syntax analysis of constructing grammars such that if you can prove
14. (a) they are non-ambiguous (and have a k, such that they
15. (c) The output of lexical analyser is set of tokens. are LR(k), you can show that certain arbitrary Turing
16. (a) A compiler which allows only the modified section of machines halt.
Normally LR(k) parsers are restricted to deterministic
the source code to be recompiled is called as incremental context-free languages. LR(k) grammars may have
compiler . An incremental compiler is one that can “grammar conflicts”.
recompile only those portions of a program that have 25. (d)
($)
been modified.
17. (c)
18. (d) Machine independent phase of compiler
(i) Lexical analysis (+) (*)
(ii) Syntax analysis
(iii) Intermediate code generation
19. (d) scanner is used for grouping of characters into tokens X (*) (+) Z
which represents a group of characters forming basic,
atomic chunk of syntax; of a word. Y ZX Y
COMPILER DESIGN S3-341
The preorder expansion can be represented as –
RLR
Priority
* decreases
Root Left Right
child child
$ + X * YZ * + XYZ $
26. (a) Limits the amount of erroneous output passed to the Now the expression can be prioritize as
text phase ((((3 – 2) * 4) $ 2) $ 3)
27. (d) Þ (((1 * 4) $2) $3) Þ (4 × 4) $ 3 Þ 16 × 16 × 16
Þ 163 = 4096
28. (a) Symbol table is used to fill entries needed to manage
Hence, (d) is correct option.
the symbol table. 35. (d) Quadruples
29. (d) – has 4 fields, called op, arg1, arg2, and result
30. (a) The given statement can be broken into – often used in compilers that perform global
IF ( NUMB EQ MAX ) GOTO 500 optimization on intermediate code.
\ Number of tokens = 8 – easy to rearrange code since result names are
31. (c) A sentence is the yield of the sentencial form generated explicit.
by the grammar.
It must terminate to a terminal.
36. (a) {
L = x n yn | n ³ 1 }
Hence Only option (a) correctly checks for the number of x
aBcd, aB, Da are not sentence equals to number of y with a minimum of x = y = 1.
but abcde, abbc are sentence 37. (c) The syntax directed tree for the given grammar can be
Hence, (c) is correct option. represented as
32. (b) binary search tree for given input “aaadbc”
» On average, searching takes S {Print “1”}
» O(log(n)) time. {Print “1”}
S
» However, names in programsare not chosen A
{Print “3”} {Print “2”}
randomly S
{Print “3”} {Print “5”}
a A
B
33. (c) “3”} {Print “4”}
Print (1) Print A
a { B
d {Print “6”}
a b C
c
“xxW” Output printed will be
333645211
Print (3)
38. (b) Although the statement

xx “Sz” fro (int x = 0; x < = n; x ++)

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

num num num num num


(2) (3) (5) (6) (4) c
b
Now we evaluate bottom up
The above DAG represents
T T (a + b * C) * (b * C – d)
T F T & F Hence, (d) is correct option.
& 74. (a) 75. (d) 76. (d) 77. (a)
F 3+5=8 F 78. (b) The intermediate code generated is
iacb + cd uminus * – +
num num num num
(3) (5) (6) (4)
6 + 4 = 10

#
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

N Ø Synchronization & Deadlock

T
Ø CPU scheduling

Ø Memory management and virtual memory

E Ø File systems

N
Ø I/O systems

Ø Protection and Security

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

Benefits stack stack stack


There are four major categories of benefits to
multi-threading:
1. Responsiveness - One thread may
provide rapid response while other thread thread
threads are blocked or slowed down
doing intensive calculations.
2. Resource sharing - By default threads
share common code, data, and other
resources, which allows multiple tasks
to be performed simultaneously in a single-threaded process multithreaded process
single address space.
3. Economy - Creating and managing threads (and context switches between
them) is much faster than performing the same tasks for processes. Note : That single threaded processes
4. Scalability, i.e. Utilization of multiprocessor architectures - A single can still benefit from multi-processor
threaded process can only run on one CPU, no matter how many may be architectures when there are multiple
available, whereas the execution of a multi-threaded application may be processes contending for the CPU, i.e.
split amongst available processors. when the load average is above some
certain threshold.
Multithreading Models
There are two types of threads to be managed in a modern system: User threads
and kernel threads.
User threads are supported above the kernel, without kernel support. These are
the threads that application programmers would put into their programs.
Kernel threads are supported within the kernel of the OS itself. All modern OSes
support kernel level threads, allowing the kernel to perform multiple simultaneous
tasks and/or to service multiple kernel system calls simultaneously. user thread
In a specific implementation, the user threads must be mapped to kernel threads,
using one of the following strategies.
Many-To-One Model
In the many-to-one model, many user-level threads are all mapped onto a single
kernel thread.
Thread management is handled by the thread library in user space, which is very
efficient.
However, if a blocking system call is made, then the entire process blocks, even
if the other user threads would otherwise be able to continue. k kernel thread
Because a single kernel thread can operate only on a single CPU, the many-to- Many-to-one model
one model does not allow individual processes to be split across multiple CPUs.
EBD_7203
S3-352 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
One-To-One Model
user thread The one-to-one model creates a separate kernel thread to handle each user
thread.
One-to-one model overcomes the problems listed above involving blocking
system calls and the splitting of processes across multiple CPUs.
k k k k kernel thread However the overhead of managing the one-to-one model is more
significant, involving more overhead and slowing down the system.
One-to-one model
Many-To-Many Model
The many-to-many model multiplexes any number of user threads onto an
equal or smaller number of kernel threads, combining the best features of
the one-to-one and many-to-one models.
user thread Users have no restrictions on the number of threads created.
Blocking kernel system calls do not block the entire process.
Processes can be split across multiple processors.
Individual processes may be allocated variable numbers of kernel threads,
depending on the number of CPUs present and other factors.
Thread Libraries
Thread libraries provide programmers with an API for
k k k kernel thread creating and managing threads.
Thread libraries may be implemented either in user space
Many-to-many model or in kernel space. The former involves API functions
implemented solely within user space, with no kernel
support. The latter involves system calls, and requires a
kernel with thread library support.
There are three main thread libraries in use today:
user thread 1. POSIX Pthreads - may be provided as either a user or kernel
library, as an extension to the POSIX standard.
2. Win32 threads - provided as a kernel-level library on
Windows systems.
3. Java threads - Since Java generally runs on a Java Virtual
Machine, the implementation of threads is based upon
k k k
whatever OS and hardware the JVM is running on, i.e. either
k kernel thread
Pthreads or Win32 threads depending on the system.
Two-level model
Thread Cancellation
Threads that are no longer needed may be cancelled by another thread in one
of two ways:
1. Asynchronous Cancellation cancels the thread immediately.
2. Deferred Cancellation sets a flag indicating the thread should cancel itself
when it is convenient. It is then up to the cancelled thread to check this
flag periodically and exit nicely when it sees the flag set.
( Shared ) resource allocation and inter-thread data transfers can be problematic
with asynchronous cancellation.
Thread-Local Storage
Most data is shared among threads, and this is one of the major benefits of
using threads in the first place.
However sometimes threads need thread-specific data also.
Most major thread libraries ( pThreads, Win32, Java ) provide support for
thread-specific data, known as thread-local storage or TLS. Note that this is
more like static data than local variables,because it does not cease to exist when
the function ends.
INTERPROCESS COMMUNICATION
Processes executing concurrently in the OS may be either independent
processes or cooperating processes.
OPERATING SYSTEM S3-353
• A process is independent if it cannot affect or be affected by the other
processes executing in the system. Any process that does not share data
with any other process is independent.
• A process is cooperating if it can affect or be affected by the other
processes executing in the system. Clearly, any process that shares data
with other processes is a cooperating process.
There are several reasons for providing an environment that allows process
cooperation:
• Information sharing. Since several users may be interested in the same
piece of information (for instance, a shared file), we must provide an
environment to allow concurrent access to such information.
• Computation speedup. If we want a particular task to run faster, we must
break it into subtasks, each of which will be executing in parallel with the
others. Notice that such a speedup can be achieved only if the computer
has multiple processing elements (such as CPUs or I/O channels).
• Modularity. We may want to construct the system in a modular fashion,
dividing the system functions into separate processes or threads.
• Convenience. Even an individual user may work on many tasks at the same
time. For instance, a user may be editing, printing, and compiling in parallel.
• Cooperating processes require an interprocess communication (IPC)
mechanism that will allow them to exchange data and information.
There are two fundamental models of interprocess communication:
• Shared Memory. A region of memory that is shared by cooperating
processes is established. Processes can then exchange information by
reading and writing data to the shared region.
• Message Passing. Communication takes place by means of messages
exchanged between the cooperating processes. The two communications
models are contrasted in Fig
• Both of the models just discussed are common in OSs, and many systems
implement both. process A M process A
• Message passing is useful for exchanging smaller amounts of data, 1
because no conflicts need be avoided. Message passing is also easier to process B M shared
process B 2
implement than is shared memory for intercomputer communication.
• Shared memory allows maximum speed and convenience of communication, 1
2
as it can be done at memory speeds when within a computer. Shared
memory is faster than message passing, as message-passing systems are
typically implemented using system calls and thus require the more time- kernel M kernel
consuming task of kernel intervention.
(a) (b)
• In contrast, in shared-memory systems, system calls are required only to
Communications models
establish shared-memory regions. Once shared memory is established, all (a) Message passing (b) shared memory
accesses are treated as routine memory accesses, and no assistance from
the kernel is required.
Shared-Memory Systems
Interprocess communication using shared memory requires communicating
processes to establish a region of shared memory. Typically, a shared-memory
region resides in the address space of the process creating the shared-memory
segment.
Other processes that wish to communicate using this shared-memory segment
must attach it to their address space.
Recall that, normally, the OS tries to prevent one process from accessing another
process's memory. Shared memory requires that two or more processes agree to
remove this restriction. They can then exchange information by reading and
writing data in the shared areas.
The form of the data and the location are determined by these processes and
are not under the OS's control. The processes are also responsible for ensuring
that they are not writing to the same location simultaneously.
EBD_7203
S3-354 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
To illustrate the concept of cooperating processes, let's consider the producer-
consumer problem, which is a common paradigm for cooperating processes. A
producer process produces information that is consumed by a consumer
process.
One solution to the producer-consumer problem uses shared memory. To allow
producer and consumer processes to run concurrently, we must have available
a buffer of items that can be filled by the producer and emptied by the consumer.
This buffer will reside in a region of memory that is shared by the producer and
consumer processes. A producer can produce one item while the consumer is
consuming another item.
The producer and consumer must be synchronized, so that the consumer does
not try to consume an item that has not yet been produced.
Two types of buffers can be used.
1. The unbounded buffer places no practical limit on the size of the buffer.
The consumer may have to wait for new items, but the producer can always
produce new items.
2. The bounded buffer assumes a fixed buffer size. In this case, the consumer
must wait if the buffer is empty, and the producer must wait if the buffer
is full.
CONCURRENCY, SYNCHRONIZATIO N & DEADLOCK
Process management in operating systems can be classified broadly into three
categories:
Multiprogramming involves multiple processes on a system with a single
processor.
Multiprocessing involves multiple processes on a system with multiple
processors.
Distributed processing involves multiple processes on multiple systems.
All of these involve cooperation, competition, and communication between
processes that either run simultaneously or are interleaved in arbitrary ways to
give the appearance of running simultaneously.
Concurrent processing is thus central to operating systems and their design.
Principles and Problems in Concurrency
Concurrency is the interleaving of processes in time to give the appearance of
simultaneous execution. Thus it differs from parallelism, which offers genuine
simultaneous execution. However the issues and difficulties raised by the two overlap
to a large extent:
• sharing global resources safely is difficult;
• optimal allocation of resources is difficult;
• locating programming errors can be difficult, because the contexts in which
errors occur cannot always be reproduced easily.
Parallelism also introduces the issue that different processors may run at different
speeds, but again this problem is mirrored in concurrency because different processes
progress at different rates.
A Simple Example
The fundamental problem in concurrency is processes interfering with each other
while accessing a shared global resource. This can be illustrated with a surprisingly
simple example:
chin = getchar();
chout = chin;
putchar(chout);
Imagine two processes P1 and P2 both executing this code at the "same" time,
with the following interleaving due to multi-programming.
OPERATING SYSTEM S3-355
1. P1 enters this code, but is interrupted after reading the character x into chin.
2. P2 enters this code, and runs it to completion, reading and displaying the
character y.
3. P1 is resumed, but chin now contains the character y, so P1 displays the wrong
character.
The essence of the problem is the shared global variable chin. P1 sets chin, but this
write is subsequently lost during the execution of P2. The general 2 solution is to
allow only one process at a time to enter the code that accesses chin: such code is
often called a critical section. When one process is inside a critical section of code,
other processes must be prevented from entering that section. This requirement is
known as mutual exclusion.
Mutual Exclusion
Mutual exclusion is in many ways the fundamental issue in concurrency. It is the
requirement that when a process P is accessing a shared resource R, no other process
should be able to access R until P has finished with R. Examples of such resources
include files, I/O devices such as printers, and shared data structures.
There are essentially three approaches to implementing mutual exclusion.
• Leave the responsibility with the processes themselves: this is the basis of most
software approaches. These approaches are usually highly error-prone and
carry high overheads.
• Allow access to shared resources only through special-purpose machine
instructions:
i.e. a hardware approach. These approaches are faster but still do not offer a complete
solution to the problem, e.g. they cannot guarantee the absence of deadlock and
starvation.
• Provide support through the operating system, or through the programming
language. We shall outline three approaches in this category: semaphores,
monitors, and message passing.
Semaphores
The fundamental idea of semaphores is that processes "communicate" via global
counters that are initialised to a positive integer and that can be accessed 3 only
through two atomic operations:
semSignal(x) increments the value of the semaphore x.
semWait(x) tests the value of the semaphore x: if x > 0, the process decrements x and
continues; if x = 0, the process is blocked until some other process performs a
semSignal, then it proceeds as above.
A critical code section is then protected by bracketing it between these two
operations:
semWait (x);
<critical code section>
semSignal (x);
In general the number of processes that can execute this critical section simultaneously
is determined by the initial value given to x. If more than this number try to enter the
critical section, the excess processes will be blocked until some processes exit. Most
often, semaphores are initialised to one.
Deadlock
Deadlock is defined as the permanent blocking of a set of processes that either
compete for global resources or communicate with each other. It occurs when each
process in the set is blocked awaiting an event that can be triggered only by another
blocked process in the set.
Consider Figure , in which both processes P and Q need both resources A and B
simultaneously to be able to proceed.
Thus P has the form get A, ... get B, ..., release A, ..., release B, and Q has the form
get B, ... get A, ..., release B, ..., release A.
EBD_7203
S3-356 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

Progress
of Q 1 2
Release
A P and Q
A wait A
Required Release
B
Get A
B deadlock
Required 3 inevitable P and Q
wait B
5
Get B
4
6

Get A Get B Release A Release B Progress


of P
= both P and Q want resource A A
= both P and Q want resource B Required
B Required
= deadlock-inevitable region
= possible progress path of P and Q.
Horizontal portion of path indicates P is excuting and Q is waiting.
Vertical portion of path indicates Q is executing and P is waiting.
Example of Deadlock
The six paths depicted in above correspond to the following.
1. Q acquires both resources, then releases them. P can operate freely later.
2. Q acquires both resources, then P requests A. P is blocked until the resources are released, but can then operate freely.
3. Q acquires B, then P acquires A, then each requests the other resource. Deadlock is now inevitable.
4. P acquires A, then Q acquires B, then each requests the other resource. Deadlock is now inevitable.
5. P acquires both resources, then Q requests B. Q is blocked until the resources are released, but can then operate freely.
6. P acquires both resources, then releases them. Q can operate freely later.
Contrast the above example with the situation where P does not need the resources simultaneously: P has the form get A, ...
release A, ..., get B, ..., release B, and Q is defined as before.
Progress
of Q
1 2 3
Release
A
4

A Release P and Q
Required B wait A
P and Q
Get A
wait B
B
Required
5
Get B
6

Progress
Get A Release A of P
Get B Release B

A Required B Required
= both P and Q wait resource A
= possible progress path of P and Q.
= both P and Q wait resource B Horizontal portion of path indicates P is excuting
and Q is waiting.
VErtical portion of path indicates Q is executing
and P is waiting.
Example of No Deadlock
Again the six paths show the possible execution sequences.
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

Reference String : 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 First In First Out (FIFO) algorithm


Misses :× × × × × × × × × Oldest page in main memory is the one which will be selected
for replacement.
0 4 4 4 4 2 Easy to implement, keep a list, replace pages from the tail and
2 4 2 0 0 3 0 1 0 2 0 add new pages at the head.
1 1 1 3 3 3
Optimal Page algorithm
6 6 6 6 1 1
An optimal page-replacement algorithm has the lowest page-
Fault Rate = 9/12 = 0.75 fault rate of all algorithms. An optimal page-replacement
First in First out (F1,F0) algorithm exists, and has been called OPT or MIN.
Reference : 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 Replace the page that will not be used for the longest period
String
Misses : × × × × × × of time . Use the time when a page is to be used.
0 0 3 Least Recently Used (LRU) algorithm
2 4 2 3 2
Page which has not been used for the longest time in main
1 1 1
6 4 4 memory is the one which will be selected for replacement.
Easy to implement, keep a list, replace pages by looking back
Fault Rate = 6/12 = 0.50
Optimal Page Algorithm
into time.
Reference String : 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 Page Buffering algorithm
Misses :× × × × × × × × To get process start quickly, keep a pool of free frames.
On page fault, select a page to be replaced.
0 4 4 4 2
2 4 2 0 0 3 0 2 0
Write new page in the frame of free pool, mark the page table
1 1 1 1 1 and restart the process.
6 6 6 3 3 Now write the dirty page out of disk and place the frame
Fault Rate = 8/12 = 0.67 holding replaced page in free pool.
OPERATING SYSTEM S3-367
Least Frequently Used (LFU) algorithm
Page with the smallest count is the one which will be selected for replacement.
This algorithm suffers from the situation in which a page is used heavily during
the initial phase of a process, but then is never used again.
Most Frequently Used (MFU) algorithm
This algorithm is based on the argument that the page with the smallest count
was probably just brought in and has yet to be used.
FILE SYSTEM
1. File System is a method for storing and organizing computer files and the data
they contain, to make it easy to find and access.
2. It may use a data storage device such as hard disk or CD-ROM and involve
maintaining the physical location of the files.
3. Mostly File System make use of an underlying data storage device that offers
access to an array of fixed-size blocks called Sectors, generally of 512 bytes
each.
4. They typically have directories which associates filename with files.
5. Examples are FAT (File Allocation Table), NTFS, etc.
Types of File Systems:
1. Disk File Systems:
It is a file system designed for the storage of files on a data storage device, most
commonly a disk drive, which might be directly or indirectly connected to the
computer.
Example: FAT, FAT32, NTFS, HFS,etc.
2. Flash File Systems:
It is a file system designed for storing files on flash memory devices.
Example: JFFS2, YAFFS.
3. Database File Systems:
It is a new concept of file management in which Instead of hierarchical
structured management, files are identified by their characteristics, like type of
file, topic, author or similar metadata.
4. Transactional File Systems:
This a special kind of file system in that it logs events or transactions to files.
Each operation that you do may involve changes to a number of different files
and disk structures. It is important that they all be executed at the same time.
For example, file system used in bank's that sends money to other bank
electronically. This type of file system are synchronized and are fault tolerant
nad having a high degree of overhead.
5. Network File System:
This type of file system acts as a client for a remote file access protocol,
providing access to files on a server. Example: NFS, FTP, etc.
6. Special Purpose File System:
This type of file system includes systems where the files are arranged
dynamically by software. These are most commonly used by file-centric OS's
such as UNIX.
File Attributes:-
1. File name - The symbolic file name is the only information kept in human-
readable form.
2. Identifier - This unique tag, usually a number, identifies the file within the file
system; it is the non-human-readable name for the file.
3. File Type - This information needed for the systems that support different types
of files.
4. Location - This information is a pointer to a device and to the location of the
file on that device.
EBD_7203
S3-368 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
5. Size - The current size of the file(in bytes, words, or blocks) and possibly the
maximum allowed size are included in this attribute.
6. Current position: This is a pointer to current 'read or write' position in the file.
7. Protection: Access - control information controls that can do reading, writing,
executing, and so on.
8. Usage Count: This value indicates the number of processes that are currently
using (have opened) this file.
9. Time, date and process identification: This information may be kept for creation,
last modification and last use.
File Operation:
Creating a file : Two steps are necessary to create a file. First, space on the
file system must be found for the file. Second, an entry for the new file must
be made in the directory.
Writing a file : To write a file, we make a system call specifying both the name
of the file and the information to be written to the file. Given the name of the
file, the system searches the directory to find the file’s location. The system
must keep a write pointer to the location in the file when the next write is to
take place. The write pointer must be updated whenever a write occurs.
Reading a file : To read from a file, we use a system call that specifies the name
of the file and where (in memory) the next block of the file should be put. Again,
the directory is searched for the associated entry, and the system needs to keep
a read pointer to the location in the file where the next read is to take place.
Once the usually either reading from or writing to a file, the current operation
location can be kept as a per-process current-file-position pointer. Both the
read and write operations use this same pointer saving space and reducing
system complexity.
Reposition within a file : The directory is searched for the appropriate entry,
and the current-file-position pointer is repositioned to a given value.
Repositioning within a file need not involve any actual I/O. This file operation
is also known as a file seek.
Deleting a file : To delete a file, we search the directory for the named file.
Having found the associated directory entry, we release all file space, so that
it can be reused by other files, and erase the directory entry.
Truncating a file : The user may want to erase the contents of a file but keep
its attributes. Rather than forcing the user to delete the file and then recreate
it, this function allows all attributes to remain unchanged —except for file length
—but lets the file be reset to length zero and its file space released.
File Access Methods:
(1) Sequential Access:
Sequential access is based on the tape model of a file. Information in the file
is processed in order, one record after the other. A read operation reads the next
portion of the file and automatically advances the file pointer. A write operation
appends to the end of the file and the file pointer.
(2) Direct Access:
Direct access is based on a disk model of a file. For direct access, the file is
viewed as a numbered sequence of block or records. There is no restriction on
the order of reading and writing for a direct access file.
(3) Other Access Methods:
This method is built on the top of direct access method. It involves the
construction of an index for a file. The index contains pointers to the various
blocks. To find an entry in the file, the index is searched first and the pointer
is then used to access the file directly to find the desired entry.
OPERATING SYSTEM S3-369
File Allocation Methods
1. Contiguous Allocation:- This method requires each file to occupy a setoff
contiguous address on the disk. Disk address defines a linear ordering on the
disk. The difficulty with contiguous allocation is finding space for a new file.
It also suffers form external fragmentation.
2. Linked Allocation:- In linked allocation, each file is a linked list of disk blocks.
The directory contains a pointer to the first (optionally the last) block of the file.
There is no external fragmentation with linked allocation. Any free block is used
to satisfy a request. The problem with it is that it is inefficient to support direct-
access, it is effective only for sequential-access files.
3. Indexed Allocation:- This allocation method is the solution to the problem of
both contiguous and linked allocation. This is done by bringing all the pointers
together into one location called the index block. Each file has its own index
block, which is an array of disk sector of addresses. The directory contains the
address of the index block of a file.
Disk/Free Space Management:
Since there is only a limited amount of disk space, it is necessary to reuse the space
from deleted files for new files. To keep track of free disk space, the system maintains
a free-space list which records all disk blocks that are free.
Free-space list can be implemented as:
(1) Bit-Vector: Each block is represented by a 1 bit. If the block is free, the bit is
0; if the block is allocated, the bit is 1.
(2) Linked List: This approach link all the free disk blocks together, keeping a
pointer to the first free block. This block contains a pointer to the next free disk
block, and so on.
(3) Grouping: This approach stores the addresses of n free blocks in the first free
block. The first n-1 of these are actually free. The last one is the disk address
of another block containing addresses of other 'n' free blocks. The importance
of this implementation is that addresses of a large number of free blocks can
be found quickly.
(4) Counting: This approach takes advantage of the fact that several contiguous
blocks may be allocated or freed simultaneously. Thus, rather than keeping a list
of free disk addresses, the address of the first free block is kept and the number
n of free contiguous blocks that follow the first block.
Directory System/Structures:
The most common directory structures used by multi-user systems are:
1. Single-Level Directory:-
In a single-level directory system, all the files are placed in one directory. This
is very common on single-user OS. It has significant limitations when the no.
of files or when there is more than one user. Since all the files are in same folder,
they must have unique name.
2. Two-Level Directory:-
In the two-level directory system, the system maintains a master block that has
one entry for each user. This master block contains the addresses of the
directories of the users. The problem with this structure is that it effectively
isolates one user from another.
3. Tree-Structured Directories:-
In this structure, the directory are files. This leads to the possibility of having
sub-directories that can contain files and sub-subdirectories.
4. Acyclic-Graph Directories:-
It is an extension of the tree-structured directory structure. In the tree structured
directory, files and directories starting from some fixed directory are owned by
one particular user. In the acyclic structure, this prohibition is taken out and
thus a directory or file under directory can be owned by several users.
EBD_7203
S3-370 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
I/O SYSTEM
I/O management is a major component of operating system design and operation
• Important aspect of computer operation
• I/O devices vary greatly
• Various methods to control them
• Performance management
• New types of devices frequent
• Ports, busses, device controllers connect to various devices
Device drivers encapsulate device details
• Present uniform device-access interface to I/O subsystem
I/O HARDWARE
Incredible variety of I/O devices
• Storage
• Transmission
• Human-interface
Common concepts - signals from I/O devices interface with computer
• Port - connection point for device
• Bus - daisy chain or shared direct access
PCI bus common in PCs and servers, PCI Express (PCIe)
Expansion bus connects relatively slow devices
• Controller (host adapter) - electronics that operate port, bus, device
Sometimes integrated
Sometimes separate circuit board (host adapter)
Contains processor, microcode, private memory, bus controller, etc
– Some talk to per-device controller with bus controller, microcode,
memory, etc
I/O instructions control devices
Devices usually have registers where device driver places commands, addresses,
and data to write, or read data from registers after command execution
• Data-in register, data-out register, status register, control register
• Typically 1-4 bytes, or FIFO buffer
Devices have addresses, used by
• Direct I/O instructions
• Memory-mapped I/O
Device data and command registers mapped to processor address
space
Especially for large address spaces (graphics)
Device I/O Port Locations on PCs (partial)

I/O address range Device


(hexadecimal)
000 – 00F DMA controller
020 – 021 interupt controller
040 – 043 timer
200 – 20F game controller
2F8 – 2FF Serial port (secondary)
320 – 32F hard-disk controller
378 – 37F parallel port
3D0 – 3DF graphics controller
3F0 – 3F7 skette-drive controller
3F8 – 3FF serial port (primary)
OPERATING SYSTEM S3-371
Polling
For each byte of I/O
• Read busy bit from status register until 0
• Host sets read or write bit and if write copies data into data-out register
• Host sets command-ready bit
• Controller sets busy bit, executes transfer
• Controller clears busy bit, error bit, command-ready bit when transfer done
Step 1 is busy-wait cycle to wait for I/O from device
• Reasonable if device is fast
• But inefficient if device slow
• CPU switches to other tasks?
But if miss a cycle data overwritten / lost
Interrupts
Polling can happen in 3 instruction cycles
• Read status, logical-and to extract status bit, branch if not zero
• How to be more efficient if non-zero infrequently?
CPU Interrupt-request line triggered by I/O device
• Checked by processor after each instruction
Interrupt handler receives interrupts
• Maskable to ignore or delay some interrupts
Interrupt vector to dispatch interrupt to correct handler
• Context switch at start and end
• Based on priority
• Some nonmaskable
• Interrupt chaining if more than one device at same interrupt number
Interrupt mechanism also used for exceptions
• Terminate process, crash system due to hardware error
• Page fault executes when memory access error
System call executes via trap to trigger kernel to execute request
Multi-CPU systems can process interrupts concurrently
• If operating system designed to handle it
• Used for time-sensitive processing, frequent, must be fast
Direct Memory Access
Used to avoid programmed I/O (one byte at a time) for large data movement

Requires DMA controller CPU


1 I/O controller
Bypasses CPU to transfer data directly between
I/O device and memory device driver initiates I/O 2
OS writes DMA command block into memory initiates I/O
• Source and destination addresses CPU executing checks for
• Read or write mode interrupts between instructions 3
• Count of bytes
• Writes location of command block to DMA CPU receiving interrupt, 4 input ready, output
controller 7 transfers control to complete, or error
• Bus mastering of DMA controller - grabs interrupt handler generates interrupt signal
bus from CPU 5
• Cycle stealing from CPU but still much
interrupt handler processes
more efficient data, returns from interrupt
• When done, interrupts to signal completion
• Version that is aware of virtual addresses can be 6
even more efficient - DVMA CPU resumes processing
of interrupted task
Interrupt-Driven I/O Cycle
EBD_7203
S3-372 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Six Step Process to Perform DMA Transfer
1. disk driver is told
to transfer disk data
to buffer at address X CPU
2. device driver tells
5. DMA controller disk controller to
transfers bytes to transfer C butes
buffer X, increasing from disk to buffer
memory address and at address X cache
decreasing G
unit C = 0 DMA/bus/ X
6. when C = 0, DMA interrupt – CPU memory bus – memory buffer
interrupts CPU to signal controller
transfer completion
PCI bus

3. disk controller initiates


IDE disk DMA transfer
controller 4. disk controller sends
each byte to DMA
controller
disk disk

disk disk

Characteristics of I/O Devices


Aspect Variation Example
data transfer mode character terminal
block disk
access method sequential modem
random CD-ROM
transfer shedule synchronous tape
asynchronous keyboard
sharing dedicated tape
sharable keyboard
device speed latency
seek time
transfer rate
delay between
operations
I/O direction read only CD-ROM
write only graphics
read-write controller
disk
Subtleties of devices handled by device drivers
Broadly I/O devices can be grouped by the OS into
• Block I/O
• Character I/O (Stream)
• Memory-mapped file access
• Network sockets
For direct manipulation of I/O device specific characteristics, usually an escape
/ back door
• Unix ioctl() call to send arbitrary bits to a device control register and data
to device data register
OPERATING SYSTEM S3-373
Block and Character Devices
Block devices include disk drives
• Commands include read, write, seek
• Raw I/O, direct I/O, or file-system access
• Memory-mapped file access possible
File mapped to virtual memory and clusters brought via demand
paging
• DMA
Character devices include keyboards, mice, serial ports
• Commands include get(), put()
• Libraries layered on top allow line editing
Streams
STREAM - a full-duplex communication channel between a user-level process
and a device in Unix System V and beyond
A STREAM consists of:
- STREAM head interfaces with the user process
- driver end interfaces with the device
- zero or more STREAM modules between them
Each module contains a read queue and a write queue
Message passing is used to communicate between queues
• Flow control option to indicate available or busy
• Asynchronous internally, synchronous where user process communicates
with stream head

User process

stream head
read queue write queue

read queue write queue


modules
read queue write queue

read queue write queue


driver end

device

Fig. Stream structure


Network Devices
Varying enough from block and character to have own interface
Linux, Unix, Windows and many others include socket interface
• Separates network protocol from network operation
• Includes select() functionality
Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes)
Kernel I/O Subsystem
Kernel I/O Subsystem is responsible to provide many services related to I/O.
Following are some of the services provided.
• Scheduling - Kernel schedules a set of I/O requests to determine a good order
in which to execute them. When an application issues a blocking I/O system call,
the request is placed on the queue for that device. The Kernel I/O scheduler
EBD_7203
S3-374 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
rearranges the order of the queue to improve the overall system efficiency and
the average response time experienced by the applications.
• Buffering - Kernel I/O Subsystem maintains a memory area known as buffer that
stores data while they are transferred between two devices or between a device
with an application operation. Buffering is done to cope with a speed mismatch
between the producer and consumer of a data stream or to adapt between
devices that have different data transfer sizes.
• Caching - Kernel maintains cache memory which is region of fast memory that
holds copies of data. Access to the cached copy is more efficient than access
to the original.
• Spooling and Device Reservation - A spool is a buffer that holds output for a
device, such as a printer, that cannot accept interleaved data streams. The
spooling system copies the queued spool files to the printer one at a time. In
some operating systems, spooling is managed by a system daemon process. In
other operating systems, it is handled by an in kernel thread.
• Error Handling - An operating system that uses protected memory can guard
against many kinds of hardware and application errors.
Device driver
Device driver is a program or routine developed for an I/O device. A device driver
implements I/O operations or behaviours on a specific class of devices. For example
a system supports one or a number of multiple brands of terminals, all slightly
different terminals may have a single terminal driver. In the layered structure of I/O
system, device driver lies between interrupt handler and device independent I/O
software. The job of a device driver are following.
• To accept request from the device independent software above it.
• To see to it that the request is executed.
How a device driver handles a request is as follows: Suppose a request comes to read
a block N. If the driver is idle at the time a request arrives, it starts carrying out the
request immediately. Otherwise, if the driver is already busy with some other request,
it places the new request in the queue of pending requests.
PROTECTION AND SECURITY
The terms protection and security are often used together, and the distinction
between them is a bit blurred, but security is generally used in a broad sense to refer
to all concerns about controlled access to facilities, while protection describes
specific technological mechanisms that support security.
Protection
Protection: mechanisms that prevent accidental or intentional misuse of a
system.
• Accidents: generally easier to solve (make them unlikely)
• Malicious abuse: much more difficult to eliminate (can't leave any
loopholes, can't use probabilities).
Three aspects to a protection mechanism:
• Authentication: identify a responsible party (principal) behind each action.
• Authorization: determine which principals are allowed to perform which
actions.
• Access enforcement: combine authentication and authorization to control
access.
A tiny flaw in any of these areas can compromise the entire protection mechanism.
Authentication
Typically done with passwords:
• A secret piece of information used to establish identity of a user.
• Must not be stored in a directly-readable form: use one-way transformations.
• Passwords should be relatively long and obscure.
OPERATING SYSTEM S3-375
Alternate form of authentication: badge or key.
• Does not have to be kept secret.
• Should not be forgable or copyable.
• Can be stolen, but owner should know if it is.
Paradox: key must be cheap to make, hard to duplicate.
Once authentication is complete, the identity of the principal must be protected
from tampering, since other parts of the system will rely on it.
Once you log in, your user id is associated with every process executed under
that login: each process inherits the user id from its parent.
Authorization
Goal: determine which principals can perform which operations on which
objects.
Logically, authorization information represented as an access matrix:
• One row per principal.
• One column per object.
• Each entry indicates what that principle can do to that object.
In practice a full access matrix would be too bulky, so it gets stored in one of
two compressed ways: access control lists or capabilities.
Access Control Lists (ACLs): organize by columns.
• With each object, store information about which users are allowed to
perform which operations.
• Most general form: list of <user, privilege> pairs.
• For simplicity, users can be organized into groups, with a single ACL for
an entire group.
• ACLs can be very general (Windows) or simplified (Unix).
• UNIX: 9 bits per file:
owner, group, anyone
read, write, execute permissions for each of the above
In addition, user "root" has all permissions for everything
• ACLs are simple and are used in almost all file systems.
Capabilities: organize by rows.
• With each user, indicate which objects may be accessed, and in what ways.
• Store a list of <object, privilege> pairs with each user. This is called a
capability list.
• Typically, capabilities also act as names for objects: can't even name
objects not referred to in your capability list.
• Almost as if there were no root directory in Unix and no "..".
Systems based on ACLs encourage visibility of objects: shared public
namespace.
Capability systems discourage visibility; namespaces are private by default.
Capabilities have been used in experimental systems attempting to be very
secure. However, they have proven to be clumsy to use (painful to share
things), so they have mostly fallen out of favor for managing objects such as
files.
Example of a simple capability-based protection scheme: page tables.
Access Enforcement
Some part of the system must be responsible for enforcing access controls and
protecting authentication and authorization info.
This portion of the system has total power, so it should be as small and simple
as possible. Example: the portion of the system that sets up page tables.
Security kernel: an inner layer of the operating system that enforces security;
only this layer has total power.
• Most operating systems have no security kernel: the entire OS has
unlimited power.
EBD_7203
S3-376 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Miscellaneous Issues
There are many other things that need to be protected besides just file access
• In Unix, root access is used to control most of these things.
Some common problems:
• Account penetration
• Abuse of valid privileges.
• Trojan Horse: modify valid program to misbehave or steal information.
• Impersonation/phishing: create the appearance of a trusted application,
trick users into divulging personal information
• Network attack: snoop on network traffic or other communications and
steal unprotected information (e.g. passwords).
• Denial of service: create program that uses up all system resources to make
system crash or prevent others from getting work done
• Worm or virus: a Trojan Horse that can spread itself from machine to
machine (exploiting bugs and loopholes)
Examples of successful attacks:
• Tenex page-fault password attack
• Botnets and denial of service
• "Salami attack": checking account interest calculator that credited fractional
cents to the account of the creator
It may not be possible to tell that a system has been penetrated. Example of
undetectable Trojan Horse:
• Modify login program to recognize special login and give root privilege
without a password.
• But, people might notice the login code.
• So, modify the compiler to figure out when it's compiling the login code and
insert the Trojan Horse automatically.
• But, people might notice the compiler code.
• Modify the compiler to insert the compiler Trojan Horse.
• Compile the compiler.
• Remove the Trojan Horse from the sources.
• The Trojan Horse is completely hidden in the binaries!
Once penetrated, it may be difficult or impossible to secure it again: too many
complex Trojan Horses.
Any bug can result in a security loophole, and all systems have bugs.
Security Solutions
Logging: record important actions and uses of privilege
Principle of minimum privilege: limit access to only what is absolutely needed.
Involve humans more:
• Auditing code to catch bugs and Trojan Horses.
• Human approval for particularly dangerous operations (e.g., large funds
transfers)
Prove correctness of system (absence of bugs)
Information flow control:
• Control not only who can access what, but what they can do with the
information once they have it.
• Goal: prevent Trojan Horses
• Example: can my editor leak my files out onto the Internet?
• Many attempts at information flow control, none that both work and are
convenient to use.
• Example: covert channels
Use some observable property of the system as a channel for signaling to an
accomplice.
E.g. modulate CPU load, accomplice observes.
OPERATING SYSTEM S3-377
Cryptographic Protocols
K K Encryption
In distributed systems, data is usually sent over insecure channels. A prudent user
M E M should assume that it is easy for a "bad guy" to see all the data that goes over the
f1 f2
hello a1&%×# hello wire. In fact, the bad guy may be assumed to have the power to modify the data as
it goes by, delete messages, inject new messages into the stream, or any combination
of these operations, such as stealing a message and playing it back at a later time.
In such environments, security is based on cryptographic techniques.
Messages are scrambled, or encrypted before they are sent, and decrypted on receipt.
Here M is the original plaintext message, E is the encrypted message, f1 and f2 are
the encryption and decryption functions, and K is the key. In mathematical notation,
E = f1(M,K)
f2(E,K) = f2(f1(M,K), K) = M
According to the principle of PUBLIC DESIGN, the encryption and decryption
functions are well-known publicly available algorithms. It is the key K, known only
to the sender and receiver, that provides security.
The most important feature of the encryption algorithm f1 is that be infeasible to
invert the function. That is, it should be impossible, or at least very hard, to recover
M from E without knowing K. In fact, it is quite easy to come up with such an
algorithm: exclusive or. If the length of K (in bits) is the same as the length of M,
let each bit of E be zero if corresponding bits of M and K are the same, and one if
they are different. Another way of looking at this function is that it flips bits of M
that correspond to one bits in K and passes through unchanged bits of M in the same
position as zero bits of K. In this case, f1 and f2 are the same function. Where there
is a zero bit in K the corresponding bit of M passes through both boxes unchanged;
where there is a one bit, the input bit gets flipped by the first box and flipped back
to its original value by the second box. This algorithm is perfect, from the point of
view of invertability. If the bits of K are all chosen at random, knowing E tells you
absolutely nothing about M.
However, it has one fatal flaw: The key has to be the same length as the message,
and you can only use it once (in the jargon of encryption, this is a one-time pad
cipher). Encryption algorithms have been devised with fixed-length keys of 100 or so
bits (regardless of the length of M) with the property that M is provably hard
(computationally infeasible) to recover from E even if the bad guy
Has seen lots of messages encrypted with the same key,
Has seen lots of (M,E) pairs encrypted with the same key (a "known plaintext"
attack),
Can trick the sender into encrypting sample messages chosen by the bad guy
(a "chosen plaintext" attack).
The algorithms (proof of their properties) depend on high-powered mathematics that
is beyond the scope of this course.
Key Distribution
KA KB Even with such an algorithm in hand, there's still the problem of how the two parties
KDC who wish to communicate get the same key in the first place -- the key distribution
1 problem. If the key is sent over the network without encryption, a bad guy could see
2 it and it would become useless. But if the key is to be sent encrypted, the two sides
3 have to somehow agree on a key to encrypt the key, which leaves us back where we
KA KB started. One could always send the key through some other means, such as a trusted
A 4 B
5 courier (think of James Bond with a briefcase handcuffed to his wrist). This is called
"out-of-band" transmission. It tends to be expensive and introduces risks of its own
EBD_7203
S3-378 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
(see any James Bond movie for examples). Ultimately, some sort of out-of-band
transmission is required to get things going, but we would like to minimize it.
A clever partial solution to the key distribution problem was devised by Needham and
Schroeder. The algorithm is a bit complicated, and would be totally unreadable
without some helpful abbreviations. Instead denoting the result of encrypting
message M with key K with the expression f1(M,K), we will write it as [M]K. Think
of this as a box with M inside secured with a lock that can only be opened with key
K. We will assume that there is a trusted Key Distribution Center (KDC) that helps
processes exchange keys with each other securely. A the beginning of time, each
process A has a key KA that is known only to A and the KDC. Perhaps these keys
were distributed by some out-of-band technique. For example, the software for
process A may have been installed from a (trusted!) floppy disk that also contained
a key for A to use. The algorithm uses five messages.
Message 1 is very simple. A sends the KDC a message saying that it wants to
establish a secure channel with B. It includes in the message a random number,
denoted id, which it makes up on the spot.
1: request + id
(In these examples, "+" represents concatenation of messages.)
The KDC makes up a brand new key Kc which it sends back to A in a rather
complicated message.

2 : [Kc + id + request + [Kc + A]K B ]K


A
First note that the entire message is encrypted with A's key KA. The encryption
serves two purposes. First, it prevents any eavesdropper from opening the message
and getting at the contents. Only A can open it. Second, it acts as a sort of signature.
When A successfully decrypts the message, it knows it must have come from the
KDC and not an imposter, since only the KDC (besides A itself) knows KA and could
use it to create a message that properly decrypts.1
A saves the key Kc from the body of the message for later use in communicating with
B. The original request is included in the response so that A can see that nobody
modified the request on its way to KDC. The inclusion of id proves that this is a
response to the request just sent, not an earlier response intercepted by the bad guy
and retransmitted now. The last component of the response is itself encrypted with
B's key. A does not know B's key, so it cannot decrypt this component, but it doesn't
have to. It just sends it to B as message 3.
3:[Kc + A]K
B
As with message 2, the encryption by KB serves both to hide Kc from eavesdroppers
and to certify to B that the message is legitimate. Since only the KDC and B know
KB, when B successfully decrypts this message, it knows that the message was
prepared by the KDC. A and B now know the new key Kc, and can use it to
communicate securely. However, there are two more messages in the protocol.
Messages 4 and 5 are used by B to verify that the message 3 was not a replay. B
chooses another random number id' and sends it to A encrypted with the new key
Kc. A decrypts the message, modifies the random number in some well-defined way
(for example, it adds one to it), re-encrypts it and sends it back.
4: [ id' ]Kc
5: [ f(id') ] Kc
This is an example of a challenge/response protocol.
OPERATING SYSTEM S3-379
Public Key Encryption
In the 1970's, Diffie and Hellman invented a revolutionary new way of doing P S
encryption, called public-key (or asymmetric) cryptography. At first glance, the
change appears minor. Instead of using the same key to encrypt and decrypt, this M E M
f1 f2
method uses two different keys, one for encryption and one for decryption. Diffie and hello a1&%×# hello
Hellman invented an algorithm for generating a pair of keys (P,S) and an encryption
algorithm such that messages encrypted with key P can be decrypted only with
key S.
Since then, several other similar algorithms have been devised. The most commonly
used one is called RSA (after its inventors, Rivest, Shamir, and Adelman) and is
patented (although the 17-year lifetime of the patent is about to run out). By contrast,
the older cryptographic technique described above is called conventional, private key,
or symmetric cryptography. In most public-key algorithms, the functions f1 and f2 are
the same, and either key can be used to decrypt messages encrypted with the other.
That is,
f(f(M,P), S) = f(f(M,S), P) = M.
The beauty of public key cryptography is that if I want you to send me a secret
message, all I have to do is generate a key pair (P,S) and send you the key P. You
encrypt the message with P and I decrypt it with S. I don't have to worry about
sending P across the network without encrypting it. If a bad guy intercepts it, there's
nothing he can do with it that can harm me (there's no way to compute S from P or
vice versa). S is called the secret key and the P is the public key.
However, there's a catch. A bad guy could pretend to be me and send you his own
public key Pbg, claiming it was my public key. If you encrypt the message using Pbg,
the bad guy could intercept it and decrypt it, since he knows the corresponding Sbg.
Thus my problem is not how to send my public key to you securely, it is how to
convince you that it really is mine. We'll see in a minute a (partial) solution to this
problem.
Public key encryption is particularly handy for digital signatures. Suppose I want to
send you a message M in such a way as to assure you it really came from me. First
I compute a hash function h(M) from M using a cryptographic hash function f. Then
I encrypt h(M) using my secret key S. I send you both M and the signature [h(M)]S.
When you get the message, you compute the hash code h(M) and use my public key
P to decrypt the signature. If the two values are the same, you can conclude that the
message really came from me. Only I know my secret key S, so only I could encrypt
h(M) so that it would correctly decrypt with S. As before, for this to work, you must
already know and believe my public key.
An important application of digital signatures is a certificate, which is a principal's
name and public key signed by another principal. Suppose Alice wants to send her
public key to Bob in such a way that Bob can be reassured that it really is Alice's
key. Suppose, further, that Alice and Bob have a common friend Charlie, Bob knows
and trusts Charlie's public key, and Charlie knows and trusts Alice's public key. Alice
can get a certificate from Charlie, which contains Alice's name and public key, and
which is signed by Charlie:
[Alice + PAlice]SCharlie
Alice sends this certificate to Bob. Bob verifies Charlie's signature on the certificate,
and since he trusts Charlie, he believes that PAlice really is Alice's public key. He can
use it to send secret messages to Alice and to verify Alice's signature on messages
she sends to him. Of course, this scenario starts by assuming Bob has Charlie's public
EBD_7203
S3-380 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
key and Charlie has Alice's public key. It doesn't explain how they got them. Perhaps
they got them by exchanging other certificates, just as Bob got Alice's key. Or perhaps
the keys were exchanged by some out-of-band medium such snail mail, a telephone
call, or a face-to-face meeting.
A certificate authority (CA) is a service that exists expressly for the purpose of
issuing certificates. When you install a web browser such as Netscape, it has built
into it a set of public keys for a variety of CAs. In Netscape, click the "Security"
button or select "Security info" item from the "Communicator" menu. In the window
that appears, click on "Signers". You will get a list of these certificate authorities.
When you visit a "secure" web page, the web server sends your browser a certificate
containing its public key. If the certificate is signed by one of the CAs it recognizes,
the browser generates a conventional key and uses the server's public key to transmit
it securely to the server the browser and the server can now communicate securely
by encrypting all their communications with the new key. The little lock-shaped icon
in the lower left corner of the browser changes shape to show the lock securely
closed to indicate the secure connection. Note that both public-key and conventional
(private key) techniques are used. The public-key techniques are more flexible, but
conventional encryption is much faster, so it is used whenever large amounts of data
need to be transmitted.

Cryptosystem Services Cryptographic Methods


• Confidentiality Symmeteric
• Integrity • Same key for encryption and decryption.
• Authenticity • Key distribution problem.
• Nonrepudiation Asymmetric
• Access Control • Mathematically related key pairs for encryption and decryption.
• Public and private keys.
Hybrid
• Combines strengths of both methods.
• Asymmetric distributes symmeteric key (also known as session key).
• Symmeteric provides bulk encryption.
OPERATING SYSTEM S3-381

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

Total Execution Process selected 1 2 3 4 2 1 5 3 2 4 6


6 2 4 6 3 for Execution with 1 1 1 1 5 3 6
Time (Given)
Shortest Remaining - 2 2 2 2 2 2
Process A B C D E exec. Time. - - 3 4 4 4 4
Time Remaining Execution time Y Y Y Y N N Y Y N N Y
0 6 - - - - A
3 3 2 - - - B
5 3 0 4 - - A We can see that “Page 4” replaced “Page 3” as it will not be
7 1 0 4 6 - A used for longest period of time (Page 1, 2 both will be used
8 0 0 4 6 - C before page 3). Similarly, Red marked page - 3 replaced
10 0 0 2 6 3 C
E
page - 5 as both page - 2, 4 will be used in future.
12 0 0 0 6 3
15 0 0 0 6 0 D From the above table:
21 0 0 0 0 0 - Total no. of page faults = 7.
EBD_7203
S3-404 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY

55. 1000 PRACTICE EXERCISE


1. (c) Spatial locality of reference says that once a location is
Process id t c ti0 A.T TQ = 50 ms referenced then there is a high probability that a nearby
A 100 ms 500 ms 0 ms location will be referenced soon.
B 350 ms 500 ms 5 ms Hence option (c) is correct.
2. (c) Page fault occurs when required page that is to be
C 200 ms 500 ms 10 ms exists not found in the memory. When the page is found
in the memory it is called page hit otherwise miss. It is
The Gantt chart for Round robin algorithm for the first
not necessary to page in main memory it can either in
iteration execution for each of the 3 processes is as follows :
cache memory or any other level of memory.
R.Q A B CA 3. (b) Concurrent processes are share the CPU and memory.
They do overlap in time while execution. At a time CPU
A B C A B C B C B C B entertain only one process but it can switch to other
without completing it as a whole.
0 50 100 150 200 250 300 350 400 450 500 650
Hence option (b) is correct.
4. (c) Air Traffic Control Systems, continues to change its
A goes for I/O C goes for I/O state even after its controlling computer system has
operation operation
stopped.
After finishing tc CPU ms at time 500ms, C goes for I/O 5. (a)
operation, that needs 500ms more, so the time at which 6. (c) Kernel is the set of primitive functions upon which the
process C would complete its first I/O operations is rest of operating system functions are built up.
500 + 500 = 1000ms 7. (b)
56. (d) Pages 1, 2, 3, ... 19, 20, 21, ... 100, 1, ... 19, 20, 21, ... 100 8. (c) To specify a particular segment, 5 bits are required
Optimal page replacement : (since 25 = 32). Having selected a page, to select a
particular byte one needs 10 bits (since 210 = 1K byte).
1 2 3 19 20 20 page faults after 1 to 20 pages
So, totally 5 + 10 = 15 bits are needed.
9. (b) Segments are themselves paged. This means each
1 2 3 19 100 80 page faults after 21 to 100 pages
segment is represented in the form of pages hence must
contain the page tables.
1 2 3 19 100 No page faults from 1 to 19 pages
10. (d) There are 64 words in a block. So the 4 K cache has
(4 × 1024)/64 = 64 blocks. Since 1 set has 4 blocks,
20 21 22 20 100 üï 80 pages faults after 20 to 99 pages there are 16 sets. 16 sets needs 4 bits for representation.
and then no page fault for 100
ý In a set there are 4 blocks, which needs 2 bits. Each
20 21 22 20 100 ï Total page faults = 180
þ block has 64 words. So, the word field has 6 bits.
57. 6 11. (a) The memory configuration after the arrival of the jobs
Implementing least recently used (LRU) page replacement 1, 2 and 3 and the termination of job 1 can be depicted
policy using 3 page frames. as:
FREE-200 JOB 2-350 JOB3-300 FREE-150
4/ 1 First fit algorithm will allocate the FREE-200 slot for job
2/ 2 4. But best fit algorithm will allocate the FREE-150 slot
6/ 7 for job 4. The memory configuration for the first fit and
best fit will be
Total page faults = 6 JOB4-120 FREE-80 JOB2-350 JOB3-300 FREE-150
58. 5.5 and
The Gantt chart for SRTF scheduling algorithm is: FREE-200 JOB2-350 JOB3-300 JOB4-120 FREE-30
P1 respectively. When job 5 arrives, it will be allotted the
P2 P3 P4 P1
FREE-150 slot by the first fit algorithm and the FREE-
0 2 126 17 27 200 slot by the best fit algorithm. The memory allocation
15 + 0 + 3 + 4 table for the first fit and best fit will be
Average waiting time =
4 JOB4-120 FREE-80 JOB2-350 JOB3-300 JOB5-150
22 and
= = 5.5
4 JOB5-150 FREE-50 JOB2-350 JOB3-300 FREE-30
OPERATING SYSTEM S3-405
When job 6 arrives, it will be allotted the FREE-80 slot 19. (b) Semaphores are used in deadlock avoidance by using
by the first fit algorithm. The best fit algorithm will find them interprocess communication. It is used to solve
no room to store job 5 as the needed 80 K, is not the problem of synchronisation among processes and
available contiguously. So, it has to wait till a job mutual exclusion.
terminates. So, the first-fit algorithm performs better in 20. (d) A group of disks may be interleaved to speed up data
this case. transfers in a manner analogous to the speedup
achieved by main memory interleaving. Conventional
0 + 10 + (15 - 2 ) + (18 - 5 ) + ( 38 - 10 ) disks may be used for interleaving by spreading data
12. (a) It is = 12.8 ms across disks and by treating multiple disks as if they
5
were a single one. Furthermore, the rotation of the
8 + 0 + 3 + 15 + 8 interleaved disks may be synchronized to simplify
13. (b) It is = 6.8 ms control and also to optimize performance. In addition,
5
check- sums may be placed on separate check-sum
10 + 3 + 0 + 15 + 0 disks in order to improve reliability.
14. (c) It is = 10.8 ms 21. (c) Protection: The purpose of a computer systems is to
5
allow the user to execute programs. So the operating
30 + 3 + 0 + 5 + 0 systems provides an environment where the user can
15. (b) It is = 7.6 ms conveniently run programs. The user does not have to
5
worry about the memory allocation or multitasking or
16. (b) Resource sharing in terms of anything. These things are taken care of by the
Resource: operating system.
hardware - disks and printers Accounting: The output of a program may need to be
software - files, windows, and data objects written into new files or input taken from some files.
Hardware sharing for: The operating systems provides this service. User
convenience gives a command for reading or writing to a file and
sees his her task accomplished. Thus operating systems
reduction of cost
makes it easier for user programs to accomplished their
Data sharing for:
task.
consistency - compilers and libraries Compilation: A compiler translates the high-level
exchange of information - database source programs into target programs in machine
cooperative work - groupware languages for the specific hardwares. Once the target
17. (c) A single-useroperatingsystem is a type of operating program is generated, the user can execute the
system (OS) that is developed and intended for use on program.Compilation is not a service supported by
a computer or similar machine that will only have a Operating system.
single user at any given time. This is the most common I/O Operations : Each program requires an input and
type of OS used on a home computer, as well as on produces output. This involves the use of I/O. The
computers in offices and other work environments. operating systems hides the user the details of
underlying hardware for the I/O. All the user sees is
Xenix is a discontinued version of the Unixoperating
that the I/O has been performed without any details.
system, licensed by Microsoft from AT&T Corporation
So the operating systems by providing I/O makes it
which is a single user operating system. convenient for the users to run programs.
MS-DOS is an operating system for x86-based personal For efficiently and protection users cannot control I/O
computers. It was the most commonly used member of so this service cannot be provided by user-level
the DOS family of operating systems, and was the main programs
operating system for IBM PC compatible personal 22. (b) Locality of reference is based on the fact that a page
computers during the 1980s to the mid-1990s, until it that is referenced is likely to be referenced again in the
was gradually superseded by operating systems near future.
offering a graphical user interface (GUI), in particular 23. (c) Thrashing occurs when a system spends more time
processing page faults than executing transactions.
by various generations of the Microsoft Windows
While processing page faults is necessary to in order
operating system.
to appreciate the benefits of virtual memory, thrashing
18. (c) Supervisor calls are normally used to request privileged has a negative affect on the system.
operations or access to system resources from an As the page fault rate increases, more transactions need
operating system. processing from the paging device. The queue at the
EBD_7203
S3-406 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
paging device increases, resulting in increased service 31. (c) A gets 4, B gets 2, C gets 24, D gets 10.
time for a page fault . While the transactions in the A=10%of 40=4
system are waiting for the paging device, CPU B=5%of 40=2
utilization, system throughput and system response
similarly solve for C and D
time decrease, resulting in below optimal performance
32. (b) Starvation can be avoided either by using round-robin
of a system .
Thrashing becomes a greater threat as the degree of policy or FCFS policy, By using SJF starvation is not
multiprogramming of the system increases. avoided.
24. (d) When a interrupt occurs operating systems decides hence option (b) is current.
the request on the fact that the interrupt has higher 33. (c) The SJF algorithm is provably optimal with regard to
priority or less priority. If less the interrupted process the average waiting time.
is resumed as only after the execution of process, the 34. (c) Turnaround time is the time interval between the first
interrupt is handled. However if interrupt has higher submission of process to the completion of process.
priority the process is blocked and interrupt is 35. (c) Round Robin Policy
entertained. Hence an operating system may or may Gantt Chart
not change the state of the interrupted process to
“blocked” and schedule another process. P Q R S T P R T P R P
25. (d) Multiprocessing is the use of two or more central
0 1 2 3 4 5 6 7 8 9 10 11
processing units (CPUs) within a single computer
system. The term also refers to the ability of a system Hence option (c), 11 is correct.
to support more than one processor and/or the ability 36. (c)
to allocate tasks between them.[1] There are many
5 3 4 1
variations on this basic theme, and the definition of
multiprocessing can vary with context, mostly as a
function of how CPUs are defined (multiple cores on P1 P1 P1 P1 P1 P2 P2 P2 P3 P3 P3 P4
one die, multiple dies in one package, multiple packages
0 1 2 3 4 5 6 7 8 9 10 11 12 13
in one system unit, etc.). Also called parallel systems.
26. (a) Average turnaround time
27. (c) PC is incremented after fetching an instruction, and
holds the memory address of ("points to") the next ( 5 - 0 ) + (8 - 1) + (12 - 2 ) + (13 - 3 )
=
instruction that would be executed. Note : Incase in a 4
processor where the incrementation precedes the fetch, = 8 milli seconds
PC points to the current instruction being executed .
0 + ( 5 - 1) + (8 - 2 ) + (12 - 3)
28. (a) The PCB is a block of data that resides in RAM and the Average waiting time =
OS uses to keep track of the status of the running 4
program. It contains process state information, = 4.75 m sec
execution scheduling data, memory management
No. of processes 5
information, etc. 37. (b) Through put = = = 0.1923
Time duration 29 - 3
29. (b) When system contains ‘n’ processor and ‘n’ processes,
then maximum number of processes in running state 38. (c)
can be ‘n’ with each processor containing maximum of 39. (a) Deadlock prevention scheme handles deadlock by
one process in the running state. The minimum number making sure that one of the four necessary conditions
is zero with no processor having a process in running don't occur. In deadlock prevention, the request for a
state.
resource may not be granted even if the resulting state
hence correct option (b).
is safe.
30. (c) When a process issues an input/output request then it
40. (b) Given execution time (a < b < c < d) arrive at zero time
goes from running state to blocked state.
and then by SJF scheduling
When a process terminates itself it goes from running
state to terminate state. P1 P2 P3 P4
A process cannot go to running state after completing
a+b+c+d a+b+c a+b a 0
its I/0, it most go to ready state.
hence option (c) is correct. turn around time
OPERATING SYSTEM S3-407

( a - 0 ) + ( a + b - 0 ) + ( a + b + c - 0 ) + ( a + b + c = +d - 0 ) 45. (b) Segmentation is associated with virtual memory and


= paging is associated with physical memory. hence
4
( 4a + 3b + 2c + d ) paging is faster than segmentation.
=
4 46. (a) Disk requests are
41. (b) Peterson's Algorithm is an algorithm to provide mutual 98, 183, 37, 122, 14, 124, 65, 67
exclusion. This means that it is guaranteed, that two or Total seek time = Time covered by the disk arm starting
more processes, which have a critical section (for from 53.
example both want to print something etc.), do not
= (65 – 53) + (67 – 65) + (67 – 37) + (37 – 14) + (98 – 14)
simultaneously enter that section. This is pretty hard
+ (122 – 98) + (124 – 122) + (183 – 124) = 236
in time-sharing systems as the following can happen:
p1 wants to print something, but another process is 47. (b) Reference count tells how many hard links point to the
using the printer, so p1 just waits till the printer is free. inode
p2 does the same. Now the other process is finished 48. (d) Bits in virtual address
and p1 gets its turn. It checks whether or not the printer
is free. As it is free, it stops waiting and wants to start 229 bytes 229
= = = 221 Þ 21 bits
the printing job. Just in that moment p1 is interrupted, 256 bytes 28
because it used all its processor time. Now p2 is started
49. (d) In optimal page replacement policy we check for the
and as p1 wasn't able to start printing, the printer is still
page frame that will not be used in the near future and
available and it starts its printing. After some time
is replaced. For the given sequence 0, 9, 0, 1, 8, 1, 8, 7,
(certainly during the printing job of p2) its p1's turn
8, 7, 1, 2, 8, 2, 7, 8, 2, 3, 8, 3
again. And as it still thinks the printer is free (remember:
it was interrupted after checking for the availability of Page hit Page Miss
the resource), it starts printing. 0 8......8 0 8 0 3

42. (a) Requesting process hold already, resources while 9 7......3 1 2 9


waiting for requested resources. 1 2......2 8 7 1
There must exist a process that is holding a resource 8 8 8
already allocated to it while waiting for additional 7 2 7
resource that are currently being held by other 1 8 2
processes. 3

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

Average turnaround time 0 75 200 450 800 1275

(8 - 0 ) + (14 - 2 ) + (15 - 3) + (19 - 1) 75 + 200 + 450 + 800 + 1275


= = 12.5 ms Average turnaround time =
4 5
For preemptive = 560 time units.
A B C C C C C C D B B B A A A A A A A Hence (b) is the correct option.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 89. (a) We can observe clearly that if sequence (3, 2, 1) is
Average turn around time executed in the non-preemptive manner then it leaves
the CPU idle for 1 unit of time.
(19 - 0 ) + (12 - 1) + ( 8 - 2 ) + ( 9 - 3)
= = 10.5 ms Hence option (a) is correct.
4
Hence (c) is the correct option.
3 2 1
86. (d) Multilevel queue scheduling algorithm is used,
processes are permanently assigned to a queue when 0 1 6 15
they enter the system. If there are separate queues for
90. (c) As the check for critical_flag being FALSE is not done
foreground and background processes, processes do
not move from one queue to the other, since processes as a single undivided operation both the processes
do not change their foreground or background nature. can be in the critical region. There is no competition for
This setup has the advantage of low scheduling more than one resource, so there will be no deadlock.
overhead, but it is inflexible. The multilevel feedback- So (i) is true and (ii) is false. This gives choice (c ).
queue scheduling algorithm, in contrast, allows a 91. (d) 92. (b) 93. (a)
process to move between queues
94. (c) The basic idea of the priority inheritance protocol is
87. (c) If the time slice used in the round-robin scheduling
that when a job blocks one or more high priority jobs,
policy is more than maximum time required to execute
it ignores its original priority assignment and executes
any process then the scheduler will proceed to the
next process in the ready queue and the policy will get its critical section at the highest priority level of all the
degenerated to first come first serve. jobs it blocks. After executing its critical section, the
88. (b) FCFS job returns to its original priority level.
95. (b) mutual exclusion is not necessary for R2 and R3while
0 1 2 3 4 mutual exclusion must be there for W1 and W2 since
R1 is selected for access.Resources can be allocated
0 350 475 950 1200 1275
and deallocated to other waiting threads causing no
350 + 475 + 950 + 1200 + 1275 deadlock.
Average turnaround time =
5 96. (c) EAT = p ´ page fault service time + (1 – p) ´ memory
4250
access time
= = 850 time units EAT=p ´ 50 ´ 10–3 + (1– p) ´ (100 × 10–9)
5
Priority Scheduling EAT=10–7 – 10–7 p(500000) seconds
97. (b) Virtual address space consists of pages.
3 1 2 4 0 Given that
0 250 375 850 950 1275 no. of pages = 1 K = 210.
250 + 375 + 850 + 925 + 1275 Page size = 2KB = 211 B
Average turnaround time = Hence virtual address space = 211 × 210 = 221 B
5
\ 21 bits are required to represent the virtual address
3675
= = 735 time units space.
5
OPERATING SYSTEM S3-411
98. (d) Avg. Instruction Execution time = ) = [CPU execution FCFS
time] + (TLB Hit × 2 × Memory access time + TLB
miss ratio(page table access time + 2 × memory access
90
time)) + {page fault probability × page fault service
time} 120
That is 100ns + (0.9 × 2 × 150 + 0.1(150 + 150 + 2 × 150))
+ 800ns 30 No. of times Head changes
70 its direction = 4
100ns + 2 × (135 + 30)ns + 800ns 115
=100ns + 2 × 165ns + 800ns 130
=1230ns 110
80
99. (c) Since the physical memory is equal to the virtual 20
memory and the virtual memory is to be removed hence
the hardware support for memory management is no 25
longer needed for the conversion of virtual address to
physical address. Hence, (c) is the correct option,
Hence (c) is the correct option. 102. (d) track = 500, sector = 100
100. (c) Give the sequence, of holes capacity of sector = 500
10 KB, 4 KB, 17 KB, 18 KB, 7 KB, 9 KB, 12 KB, 15 KB, 600
20 KB Rotational speed = r / sec
60
First fit
60
The segment of size 12 KB will occupy the first hole in 1 second rotation =
600
which it can accommodate.
Seek time = 1 ms
Hence, 17 KB hole is filled.
Best fit 499
Average seek time = = 249.5
The hole in which least space is left after filling the 2
segment is selected. Track capacity
Hence, 12 KB hole is occupied. Data transfer time =
one complete rotation time
Worst fit.
100 ´ 500
Hence, 20 KB hole is occupied = = 5 ´ 105 bytes / sec
æ 60 ö
Hence (c) is the correct option. ç ÷
è 600 ø
101. (c) SSTF
250
Block transfer time = = 0.5 ms
5
90
5 ´ 10 byte / sec

120 Total transfer time = Seek time + data transfer time +


110 115
block transfer time
130
= 249.5 + 0.5 + 50 = 300 ms.
80 103. (b) If 2 indirect pointer then entry will be 2 times and 3
70 indirect pointer then entry will 3 times.
30
25 No. of entries = 128 = 27 and block size 1 KB
20 Now maximum file size = 10 × 1 KB + 27 × 27 × 1 KB + 27
× 27 × 27 × 1KB
(it is too big then other will neglect)
\ Head changes its direction for SSTF = 3 = 221 × 210 B = 2 GB
EBD_7203
S3-412 GATE - COMPUTER SCIENCE & INFORMATION TECHNOLOGY
104. (b) If 3 page frames are used computer architectures that place restrictions on the
type and scope of operations that can be performed by
Page Sequence certain processes being run by the CPU. This design
0 3 4 allows the operating system to run with more privileges
0 1 2
1 0 2 than application software.
3 0 1
4 0 1 112. (a) Pre-emptive scheduling is the strategy of
2 1 3 temporarilysuspending a running process before the
2 3 4
CPU time slice expires
Page fault: 0, 1, 2, 3, 0, 1, 4, 2, 3 113. (d) The round-robin (RR) scheduling algorithm is designed
Page hit : 0, 1, 4. especially for time-sharing systems. It is similar to FCFS
scheduling, but pre-emption is added to switch between
\ No. of page fault = 9
processes. A small unit of time, called a time quantum
If 4 pages frames are used or time slice, is defined. A time quantum is generally
from 10 to 100 milliseconds. The ready queue is treated
Page Sequence as a circular queue.
0 4 3
0 114. (b) FIFO scheduling is Non-pre-emptive scheduling
1 0 4 1 2 3
Process that requests CPU first is allocated the CPU
2 1 0 1 4 0
first.It is non preemptive and cannot utilize resources
3 2 1 2 3 4 in parallel.
115. Page sequence
Page faults: 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 0, 9, 0, 1, 8, 1, 8, 7, 8, 7, 1, 2, 8, 2, 7, 8, 2, 3, 8, 3
Page hit : 0, 1 Given 3 page frames are available and optimal
\ No of page faults = 10 replacement policy.
Hence (b) is the correct option.
105. (a) 0 8
9 7 3
106. (c) Pr ocess Max Allocated Need 1 2
P1 6 2 5
P2 6 2 4 Page faults: 0, 9, 1, 8, 7, 2, 3
P3 7 4 3 Page hit : 0, 1, 8, 8, 7, 1, 8, 2, 7, 8, 2, 8, 3
\ No of page faults = 7
If three additional resources are allocated P3 then its
116. Memory access time A = 1 time unit
need becomes zero. And system will get seven
probability of miss = p
resources back from P3. These resources can be
allocated to either P1 or P2 become the system state. so,probability of hit = (1 – p)
107. (c) In systems programming an interrupt handler, also now in the case of miss i.e. page fault the probability of
known as an Interrupt Service Routine (ISR), is a being dirty page = p
callback subroutine in microcontroller that prioritizes dirty page replace time = 300 time units
the interrupts and saves them in a queue. so,dirty page access time B = p ´ 300 time units.
108. (d) Run-time complexity: O(m × n²). now,probability of not being dirty page = (1 – p).
109. (c) The no. of processes created this (1 – p) is for servicing a page fault and it takes 100
= 2(no. of times the fork has called) = 22 = 4 time unit

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

P1 P2 P4 P3 P1 = 222 + base address of segment 3


= 222 + 498 = 720
0 1 4 5 8 12
Common data for Q. 125 and 126
Turn around time of P1 = 12 – 0 = 12
The following shows the details of four processes under
Turn around time of P2 = 4 – 1 = 3 preemptive priority scheduling algorithm. A large priority number
Turn around time of P3 = 8 – 2 = 6 indicates higher priority.
Turn around time of P4 = 5 – 4 = 1 Process Arrival time Burst time Priority

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)

Hence segment no. is occupying 5 bits out of total of A B C C C D D D D D B B A A A

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

Required 1 M enteries. Hence option (a) is correct

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)

Database design (integrity constraints, normal forms)

N Ø Query languages (SQL)

T
Ø File structures (sequential files, indexing, B and B+ trees)

Ø Transactions and concurrency control.

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.

Value Set or Domain Values:


Emp. no.
A set of possible values that can be assigned to a given attribute in individual entity. For example,
the attribute employee name in employee entity type can have character data and integer value. Hence Simple Attribute
the values in this attribute will be a non-integer domain.

The E-R Model: The enterprise is viewed as set of

• 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

Employee TYPES OF ATTRIBUTES:


There are several types of attributes in E-R model as given below,
(i) Simple and composite attributes
Name The attributes which cannot be divided further is called simple or atomic
attributes.
First Last The attributes which can be divided into smaller subparts with independent
name Middle name meanings.
name For example, In employee entity, the attribute emp_no is a simple attribute.
The emp_name can be called a composite attribute as name can be divided
Composite Attribute
into first name, middle name and last name.

(ii) Single valued and multivalued attributes


The attributes which have a single value for a given entity are said to be
Employee Employee
single valued attributes. For instance, the employee number attribute refers
to only one employee number.
The attributes which have multiple values for a given entity, this type of
Emp. no. Telephone attributes are called multivalued attributes. For example, an employee can
no.
have more than one phone number, therefore phone number is a multivalued
Single value attribute Multi value attribute attribute.

(iii) Derived attributes:


Employee The value of an attribute can be derived from the other values of other related
attributes. For example, the attribute date_of_birth and age are related
attributes. Age is a derived attribute which can be calculated using
Age DOB date_of_birth and need not be a part of schema. And date_of_birth attribute
is called a stored attribute.
Derived attribute NULL Values: An attribute is assigned with a NULL values, if an attribute
does not have a value or it indicates 'Not applicable'. For example, in
emp_name attribute the middle name may be null for some employees. If an
employee does not have a middle name, then middle_name will be assigned
A B with NULL.
A1 B1 RELATIONSHIP SETS
A2 B2 A relationship set defines how two entities interact with each other. For example, an employee works
for HR department, 'works for' is the relationship.
A3 B3 The set of relationship sets of same type is called relationship sets.
A4 B4 A relationship instance is an association between objects. Example: Employee E1 works for HR dept
One to One is one of the relationship instances.
Relationship Degree, Recursive Relationship
A B The degree of a relationship is defined by number of entity types participating in it. The relationship
B1 with degree two is called binary relationship and degree of three is called ternary
A1
B2 Recursive Relationship:
In some cases the entity types self-links and is called recursive relationship. For example, the
A2 B3
employee is an entity type and manages is a relationship. The employee entity is related to manager
B4 entity where both employee and manager belong to same entity sets.
A3 B5 MAPPING CARDINALITIES
One to Many
It describes the number of entities to which another entity can be related
A B
The binary relationship between 2 entity sets, the mapping cardinality should be one of the following.
A1
B1 1. One to one: An entity in A is related utmost to one entity in B and vice versa.
A2
2. One to Many: An entity in A can be associated with any number of entities in B. An entity in
A3 B2 B can be associated to utmost one entity in A.
A4 3. Many to one: An entity in A can be associated to utmost one entity in B and entity B can be
B3
A5
associated with any number of entities in A.
Many to One 4. Many to many: An entity in A is associated with any number of entities in B vice versa.
DATABASES S3-419
PARTICIPATION CONSTRAINTS
Entity Types
An entity type is named and is described by set of attributes
• Student: Id, Name, Address, Hobbies
Domain: possible values of an attribute.
• Note that the value for an attribute can be a set or list of values, sometimes called “multi-
valued” attributes
• This is in contrast to the pure relational model which requires atomic values
• E.g., (111111, John, 123 Main St, (stamps, coins))
Key: subset of attributes that uniquely identifies an entity (candidate key)
Entity Schema:
The meta-information of entity type name, attributes (and associated domain), key constraints Entity
Types tend to correspond to nouns; attributes are also nouns albeit descriptions of the parts of
entities. May have null values for some entity attribute instances – no mapping to domain for those
instances. A B
The participation of entity set is said to be total, if every entity in entity set is associated with at
A1 B1
least one relationship or else the participation is partial.
Keys : Keys are very important part of Relational database. They are used to establish and identify A2 B2
relation between tables. They also ensure that each record within a table can be uniquely identified by A3 B3
the combination of one or more fields within a table. A4 B4
Super Key: It is a collection of one or more attributes used to uniquely identify an entity in entity set.
Candidate key: It is a minimal super key of which no proper subset is also a super key. Many to Many
Primary key: It is the candidate key which is used to uniquel identify an entity in entity set.
Composite key: Key that consists of two or more attributes that
uniquely identity an entity occurance is called Composite key. But Primary Key
any attribute that makes up the Composite key is not a simple key in
its own.
Foreign key: term used in relational databases (but not in the
E-R model) for an attribute that is the primary key of another table s-id s-name age course address
and is used to establish a relationship with that table where it
appears as an attribute also.
So a foreign key value occurs in the table and again in the other
table. This conflicts with the idea that a value is stored only once;
the idea that a fact is stored once is not undermined. Composite Key
Secondary or Alternative key : The candidate key which are not
selected for primary key are known as secondary keys or alternative
keys.
Non-key attribute : Non-key attributes are attributes other than cust_id order _id sale_detail
candidate key attributes in a table
Non-prime attribute : Non-prime attributes are attrubutes other than
primary attribute.
Weak entity types: Entity types that do not have primary key attribute
are called weak entity type.
EBD_7203
S3-420 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
ENTITY RELATIONSHIP DIAGRAM
Entity relationship diagrams express the logical structure of a database the main
components of entity relationship diagram are :
Symbol Meaning

1. Rectangle Entity set


Graphical Representation in E-R diagram

First Last
SSN 2. Ellipse Attributes

Address Birth date


Name Age 3. Diamonds Relatiohship stes

Person Hobbies 4. Lines Linkd attributes to entity sets and


entity sets to relationship sets

5. Double ellipse Multivalued attributes


Rectangle : Entity
Ellipses : Attribute (Underline
attributes are [part of] 6. Dotted ellipse Derived attributes
the primary key)
Double ellipses : Multi-valued attribute 7. Double line Total participation of entity in
Dashed ellipses : derived attributes e.g. relationship sets
age is derivable from
birth date and current 8. Weak entity
date.

9. Identifying relationship for weak entity set

Translating Tables into ERD


1. The following rules can be followed to convert
tables into ERD
Create a table for all strong entities and column for
Example of an E.R. diagram : all attributes. If an attribute is a composite attribute
Employee [Emp. id, emp. name, DOB, address, Phone. number, Salary, then create columns only for sub attributes.
Department (dep. no., dep. name)] 2. Do not create any column for derived attributes as
Emp. id emp. they would not be included in the table.
dep. no. dep.
name 3. Create separate table for multivalued attribute and
name
DOB the primary key of the entity would be added as a
Age Works
column to the table of the multivalued attribute.
Employee Department
for 4. Similarly create separate table for weak entity and the
Address
primary key of weak entities/multivalued attributes is
Salary formed by combining partial key of weak entity and
primary key of strong entity to which the weak entity
is related to.
5. Tables for relations depend upon the cardinality of
Relational Model the relationship. For one to many and one to one
there is no need to create separate tables.
6. For many to many, create a separate table for
relationship and add primary key by combining the
primary key of both the entities.
DATABASES S3-421
RELATIONAL ALGEBRA
Relational algebra is a procedural language. It consists of set of operations which
takes one or two relations as input and gives out a result which is a new relation.
The basic operations of relational algebra are select, union, set difference, Cartesian
product and rename. The other operations in relational algebra are set intersection, Example of select operation : select
natural join, division and assignment. the tuples from employee relation
The examples for the different operations will be explained by using the company whose department number is 10.
database, 's' (dep_number=10)(Employee)
Employee (employee_name, emp_id, DOfB, address,gender,dep_number,salary) Example :
Department (Dep_name, D_number, mngr_id, mngr_st_date) Select the tuples from employees whose
Project (proj_num, proj_name, p_location, d_num) department is 10 and draws salary
Works_on (empl_id, p_num, hours) more than 20000.
s(dep_number=10)(Employee)(salary >20000)
Dependent (emp_id, depen_name, gender, bdate, relationship)
(Employee)
The Fundamental Operations
The basic operation in relational algebra falls into two types, unary and binary Example of project operation : to list
operations. The unary operations operate on one relation and examples are select, the columns, employee id and employee
project and rename. And binary operations operate on pairs of relation, set difference, name in the relation employee.
Cartesian product and rename are examples of binary operations. P (employee_name,emp_id)
The SELECT Operation
The SELECT operation selects the tuples from the relation which satisfies the
selection condition, it is denoted by symbol 's' (sigma). The selection acts as a filter
to the tuples to be selected.
The comparisons operators like <,>, =, ¹ are used in selection predicate. The
connectives like and (), or (V), not(-) are used to combine several predicates.
The PROJECT operation Example of union : We will consider
This operation is used to select certain columns from a relation and discards the other the bank customers, the 2 relations
columns. It is denoted by P (Pi). The projection operation does vertical partitioning, depositor and borrower:
it lists the specified columns of a tuple and discards rest of the attributes. The Depositor (customer_id, customer_name,
projection operation removes any duplicate tuples as the projection operation must address,acct_number, access_date,
be a set of tuples and mathematical sets do not allow any duplicates. balance)
Borrower (customer_id, customer_name,
Composition of relational operations address, loan_number, amount)
The select and projection operations can be combined to write a single relational The expression, P (customer_id,
algebra expression. customer_name (Depositor ) U
Union operation P (customer_id, customer_name
(borrower) Gives the result set that are
This is a binary operation and is denoted by È. The relation A È B, includes all tuples either in depositor or borrower or
of relation A and relation B which are in either A or B or both in A and B. The both.
duplicate tuples are eliminated.
The relations A and B must have same number of attributes and every corresponding Example of set difference : The
pair of attributes should be of same domain type. expression P customer_id, customer_
name(Depositor) _ P customer_id,
customer_name(borrower)
Set difference operation Gives the customers who are having
The set difference operation gives the tuples which are present in one relation but an account with the bank but not
not in another, it is denoted by symbol '–'. who have taken loan.
The expression A–B, gives the tuples which are present in relation A but not in B. Example of Intersection difference
The relations A and B should be compatible; they should have same number of Õcustomer_id, customer_name
attributes and domain types. ( D ep os i t or ) Ç Õ c u s t o m e r _ i d ,
Intersection Operation customer_name(borrower)
Intersection operation given the tuples which are common in both the relations and The result set consists of the customers
who have an account and also have
is denoted by Ç . The expression A Ç B gives the tuples which are present in both
borrowed loan from the bank.
A and B relation. The attributes names in A and B are same and of same domain types.
EBD_7203
S3-422 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Set Operations - semantics
Consider two relations R and S.
• UNION of R and S
the union of two relations is a relation that includes all the tuples that are
either in R or in S or in both R and S. Duplicate tuples are eliminated.
• INTERSECTION of R and S
the intersection of R and S is a relation that includes all tuples that are both
in R and S.
• DIFFERENCE of R and S
the difference of R and S is the relation that contains all the tuples that are
in R but that are not in S.
SET Operations - requirements
For set operations to function correctly the relations R and S must be union
compatible. Two relations are union compatible if
• they have the same number of attributes
• the domain of each attribute in column order is the same in both R and S.
UNION Example

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

R LEFT OUTER JOIN R. ColA = S. SColA S


R ColA ColB
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 - -

S SColA SColB R RIGHT OUTER JOIN S


R. ColA = S. SColA
A 1
C 2 A 1 A 1
D 3 D 3 D 3
E 4 E 5 E 4
- - C 2

OUTER JOIN (left/right)


OUTER JOIN example 2

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

OUTER JOIN (full)

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

Example of existential quantifier, Tuple relational Calculus


Select the name and address of the employees A tuple variable is a variable which ranges over particular database
who work for finance department, relation. That is, every value assigned to tuple variable has same
{t.emp_name,t,address|employee(t) and ($d) number and type of fields. For example, a simple calculus query can
department(d) and d.d_name = 'finance' and be written as {T | p(T)}.
d.d_num = t.dept_num} Here T is a tuple variable and p(T) is a conditional expression for
Here all the tuple variables appear before |, it. The query will return the result set which satisfies the selection
d.d_name = 'finance' is a selection condition and condition.
d.d_num = t.dept_num is a JOIN condition. The existential and universal quantifiers:
Example for universal quantifier Two special quantifiers which can appear in formulas are universal
(V D) (D.dept_name 1 'finance') quantifier( ") and existential quantifier($).
This means for all department tuples not in For a given formula F and ($t) and ( "t) where t is a tuple variable,
finance department. In a formula (Et) is true if F evaluates to true at least for one of the tuple
The languages which are based on tuple calculus and "t is true if formula F evaluates to true for every tuple (in universe).
are SQL (structured query language) and QUEL. Commonly, "t is called as 'for all' and $t is 'there exists'

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 :

Student_id S tudent_name S ubjects


123 A mar Phys ics
123 A mar Chemis try
124 Rekha M aths
125 A vin as h Biology
This can be normalized in 1NF by creating 2 separate tables
Student Table: Subject table :
Stu_id Stu_name Subject_id Student_id Subj_name
123 Amar 101 123 Physics
124 Rekha
102 123 Chemistry
125 Avinash
103 124 Maths
104 125 Biology
Second normal form(2NF)
A table is said to be in 2NF, if it
• Satisfies 1NF
• No partial dependency of any column on primary key.
If a table has concatenated primary key, each column in table should depend on entire primary
key rather a part of it or else it fails 2NF.
DATABASES S3-429
Customer Table:

Cust_id Cust_name Prod_id Prod_name Sales_detail


123 Amar 10 Prod1 Sales_1
123 Amar 11 Prod2 Sales_2
124 Rekha 12 Prod3 Sales_3

To reduce this into second normal form, create 3 different tables.


Sales Table:
Customer_table: Product table:
Customer_id Product_id Sales_detail
Cust_id Cust_name Prod_id Prod_name
10 Prod1 123 10 Sales1
123 Amar
11 Prod2 123 11 Sales2
124 Rekha
12 Prod3 124 12 Sales3

Third Normal form (3NF)


A table or relation is said to be in 3NF if,
• It satisfies 2NF
• Every non-prime attribute in the table should depend on primary key. The functional
transitive dependency is removed from the table. This helps in reducing the data
duplication and achieves data integrity.
Employee table:

Emp_id Emp_name DOB Addr1 City State Zipcode


This will be in 3NF when ZIPcode table is created as addr1, city, state is dependent on zipcode
Emp_table:

Emp_id Emp_name DOB Zip_code

Address table:

Zip_code Addr1 City State

Boyce & Codd normal form (BCNF)


BCNF is a higher version of 3NF. A 3NF table doesn’t have multiple candidate keys.
Fourth normal form
A table is said to be in 4NF if,
• It satisfies 3 NF Basic structure of SQL
• A record should not contain two or more independent multi values about an entity. It consists of three
clauses: select,
Said t
from and where.
Fifth Normal Form
Select corresponds
A table is said to be in 5NF if, to attributes to be
• It satisfies 4NF retrieved from the
• The table consists of a key and non-key attribute only. table
From is the
QUERRY LANGUAGES (SQL) relation or data
SQL is a structured query language used in all relational database management systems for structure to be
manipulating, retrieving and storing in relational database. SQL allows the users to define, describe scanned to get the
and manipulate the data in the database. It is also possible to embed SQL with other languages like desired result.
java, libraries and pr-compilers. Where clause
specifies the
SQL operators : condition used
1. Rename operation : it is used to rename the attributes i.e columns or relations i.e tables using ‘as’ while fetching the
clause. data from one or
2. ALL : This specifies all the tuples and explicitly doesn’t remove the duplicates from the result multiple tables.
set.
EBD_7203
S3-430 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY

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

A-217 Brighton 750


A-101 Downtown 500
A-110 Downtown 600
A-215 Mianus 700
A-102 Perryridge 400
A-201 Perryridge 900
A-218 Perryridge 700
A-222 Redwood 700
A-305 Round Hill 350

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

Customer_name customer_street customer_city


Hayes Main Brooklyn
Turner Putnam Stamford

Multitable clustering organization of customer and depositor:

Hayes Main Brooklyn


Hayes A-102
Hayes A-220
Hayes A-503
Turner Putnam Stamford
Turner A-305

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

( ) A. Key Attributes X Attribute A 1. Transitive dependencies


(a) P a,c ( sa =c R ) (b) P a <c sa,c R

(c) Pa <2 R (d) s a <c ( P a,c R )


B. Key Attributes X Attribute A 2. Trivial dependencies
27. Relation R has attributes A, B, C, D, E, F, G, H, I, J and
satisfies FD’s
ABD ® E C. Key Attributes A Attribute XA 3. Partial dependencies
C ®J
AB ® G
CI ® I Codes:
B ®F A B C A B C
G ® HI (a) 1 2 3 (b) 1 3 1
Find candidate key. (c) 3 1 2 (d) 3 2 1
(a) A, B, C, I (b) A, B, C, D, G 33. 3NF is preferred than BCNF because
(c) A, B, C, D, E (d) A, B, C, D 1. We normally choose to retain dependency preservation
2. A high penalty in system performance is to be paid or
28. For the given relation instance the best normal form is
risk the integrity of the data in our database.
3. There isn’t any problem of repetition of information
A B C D E F
4. Given statement is wrong.
(a) Only 4 is true (b) Only 2 and 3 are true
(c) Only 1 and 2 are true (d) Only 3 is true
34. Relation x = (d, b, c, f, g, h) (d ® bc, g ® hd) is decomposed
(a) 1 NF (b) 2 NF into
a = (d, b, c)
(c) 3 NF (d) BCNF
e = (d, f, g, h)
29. Consider a relation schema R = (A, B, C, D, E, F, G, I) on
Which of the following is correct ?
which the following functional dependency hold {ABD ®
(a) lossy and dependency preservation
E ,
(b) lossless and dependency preservation
AB ® G, B ® F, C ® J, CJ ® I, G ® H} then what are the
(c) lossless and no dependency preservation
candidate keys of R?
(d) lossy and not dependency preservation
(a) A, B, C, D (b) A, B, G, F
35. Consider the relation r (A, B, C, D, E) and the set F = {AB ®
(c) A, B, C, I (d) A, B, C
CE, E ® AB, C ® D}. What is the highest normal form of this
30. The language L = {a nb nC n | n ³ 0} is used for an application
relation ?
of typeset text. Typeset text use italics where ordinary typed
(a) 1 NF (b) 2 NF
text uses underlining. In convenient a file of a text destined (c) 3 NF (d) BCNF
to be printed on a line printer to text suitable for a photo 36. Consider the relation R(A, B, C, D, E, F, G) satisfies the
typesetter, one has to replace underlined works by italics. following functional dependencies.
An underline word is a string of letters followed by an equal A ® B, BC ® DE, AEF ® G
number of backspaces and an equal number of underscores. Which of the following statement is true?
If we regard a as any letter, b as backspace and c as underscore (a) BC ® DG (b) ACF ® DG
then which of the following statements is correct? (c) A ® DG (d) B ® DG
(i) L represents underlined words. 37. Consider the following functional dependencies.
(ii) We cannot use a grammar to describe underlined words. {a,b ® c, d}
(iii) We cannot use a parser generating tool based solely e ® c;
on CFG to create a program to convert underlined text. b ® e, f}
DATABASES S3-451
Given the functional dependencies shown above, what The labeled precedence graph will be –
normal form is the following relation in: R (a, b, c, d, e, f)?
(a) BCNF (b) 1 NF T3 T4 T7 T3
(a) (b) T7 T4
(c) 2 NF (d) 3 NF
38. Which of the following is correct statement about SQL?
(a) Data Control Language provides facilities to retrieve
data (c) T3 T4 T7 (d) T3 T4 T7
(b) Data Manipulation Language can delete all records and
tables in a database. 43. In case of timestamp ordering R-timestamp (Q) denotes
(c) Data Definition Language provides facilities to add more (a) the largest timestamp of any transaction that execute
data into a database while providing integrity of data read (Q) successfully.
(d) Data Definition Language provides facilities to modify (b) the average timestamp of any transaction that execute
structures or tables. read (Q) successfully.
39. Which of the following is correct? (c) the average timestamp of any transaction that execute
(a) An SQL query automatically eliminates duplicates read (Q) unsuccessfully
(b) An SQL query will not work if there are no indexes on (d) the smallest timestamp of any transaction that execute
the relations read (Q) successfully.
(c) SQL permits attribute names to be repeated in the same 44. Locking was introduced into database so that
relation (a) Keys can be provided to maintain security.
(d) None of these (b) All simultaneous transactions are prevented.
(c) Passwords can be provided to maintain security.
40. In SQL, relations can contain null values, and comparisons
(d) Consistency can be enforced.
with null values are treated as unknown . Suppose all 45. Which of the following is true for two-phase locking?
comparisons with a null value are treated as false. Which of (a) lock acquisition is the second phase
the following pairs is not equivalent? (b) locks can be acquired at any time
(a) x = = 5 not (not (x = 5)) (c) locks are acquired in the first phase
(b) x = 5 x > 4 and x < 6, where x is an (d) None of the above
integer 46. Choose the false statement.
(c) x ¹ 5 not (x = 5) (a) Timestamp protocol is deadlock free.
(d) None of these (b) Two phase locking guarantees serializability
41. The following table has two attributes A and C where A is (c) Strict two phase locking is deadlock free.
the primary key and C is the foreign key referencing A with (d) Timestamp protocol may not result recoverable
on-delete cascade. schedule.
47. Choose the correct statements.
A C (a) For fixed length recores unspanned organization is
2 4 pareterred.
3 4 (b) For variable length records unspanned organization is
4 3 preferred.
(c) For fixed length records spanned organization is
5 2
preferred.
7 2 (d) None of the above
9 5 48. Index sequential file is made of all of these expect
6 4 (a) primary data storage area
The set of all tuples that must be additionally deleted to (b) overflow area
preserve referential integrity when the tuple (2, 4) is deleted (c) hierarchy indices
(d) address of prime data track.
is:
49. Given relations R(w, x) and S(y, z), the result of SELECT
(a) (3, 4) and (6, 4) (b) (5, 2) and (7, 2)
DISTINCT w, x
(c) (5, 2), (7, 2) and (9, 5) (d) (3, 4), (4, 3) and (6, 4) FROM R, S
42. Consider the following transaction schedule is guranteed to be same as R, if
(a) R has no duplicates and S is non-empty
T3 T4 T7 (b) R and S have no duplicates
R (Q ) (c) S has no duplicates and R is non-empty
W ( Q) (d) R and S have the same number of tuples
50. A functional dependency of the form X ® Y is trivial if
W ( Q) R (Q)
(a) Y Í X (b) Y Ì X
W (Q)
(c) XÍY (d) X Ì Y and Y Ì X
EBD_7203
S3-452 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
51. The employee information in a company is stored in the 56. Consider the relation
relation Employee: (name, sex, salary, dept Name) Employee (Emp-No. Emp-Name, salary, project-no, due-date)
Assume name is the primary key, consider the SQL query (Assuming an 1-1 relationship between project and
Employee– employees)
Employee Project-no is functionally dependent on
Where sex = M (a) Emp-name (b) Emp-no
Group By dept. Name (c) due-date (d) none of the above
HAVING avg(salary)>(SELECT /deptName avg(salary) 57. In the previous question, which of the following is/are
FROM Employee) it returns the names of the departments in functionally depedent on Emp-name? (Assume no two
which the average salary
persons have the same name)
(a) is more than the average salary in the company
1. Emp-no. 2. Project-no salary
(b) of the male employees is more than the average salary
3. Salary, due-date 4. Emp-no, salary, project-no
of all the male employees in the company
(a) 1 and 3 (b) 2 only
(c) of the male employees is more than the average salary
of the employees in the same department (c) 3 and 4 (d) 1, 2, 3 and 4
(d) of the male employees is more than the average salary 58. If P and Q are predicates and P is the relational algebra
in the company expression, then which of the following equivalence are
52. Choose the correct statements. valid?
(a) Relational algebra and relational calculus are both (a) sP (sQ(e)) = sQ(sP(e)) (b) sP (sQ(e)) = sPAQ(e)
procedural query langauges. (c) sQ (sP(e)) = sPAQ(e) (d) All of the above
(b) Relational algebra and relational calculus are both non- 59. Consider the following set of functional dependencies on
procedural query languages. the scheme (A, B, C).
(c) Relational algebra is a procedural query language and A ® BC
relational calculus is a non-procedural query langauge. B ®C
(d) Relational algebra is a non-procedural query langauge A ®B
and relational calculus is a procedural query language. AB ® C
53. Let R be a relation. Which of the following comments about The canonical cover for this set is
the relation R are correct? (a) A ® BC and B ® C
1. R will necessrily have a composite key if R is in BCNF (b) A ® BC and AB ® C
but not in 4NF (c) A ® BC and A ® B
2. If R is in 3NF and if every key of R is simple, then R is in (d) A ® B and B ® C
BCNF
60. Consider the following ERD diagram depicting the
3. If R is in BCNF and if R has at least one simple key, then
relationship of an employee and supervisor
R is in 4NF
4. If R is in 3NF and if its every key is simple, then R is in
5NF Salary
(a) 1 and 4 (b) 2 and 3 BirthDate
FirstName
(c) 1, 2 and 3 (d) 1, 2, 3 and 4 EmpID
Name MiddleName
EMPLOYEE
54. A primary key if combined with a foreign key creates LastName
(a) parent child relationship between the tables that connect
them Supervisor
Supervisee
(b) many-to-many relationship between the tables that 1
SUPERVISION N
connect them
(c) Network model between the tables the conenct them
(d) none of the above
Which is the possible relations if the above ERD is mapped
55. The SQL expression
into a relational model?
select distinct T.branch_name from branch T. branch S where
T.assets > S. assets and S.branch_city = “PONDICHERRY” (a) Employee (EmpID, BirthDate, Salary, Name(FirstName,
finds the names of MiddleName, LastName))
(a) all branches that have greater assets than any branch (b) Supervision (EmpID, BirthDate, Salary,
located in PONDICHERRY Name(FirstName, MiddleName, LastName),EmpID)
(b) all branches that have greater assets than all branches (c) Supervision (Supervision, BirthDate, Salary,
in PONDICHERRY Name(FirstName, MiddleName, LastName), EmpID)
(c) the branch that have greater asset in PONDICHERRY {EmpID}
(d) any branches that have greater asset than any branch (d) Employee (EmpID, BirthDate, Salary, Name(FirstName,
located in PONDICHERRY MiddleName, LastName), Supervisor/ID)
DATABASES S3-453
61. It is desired to design an object-oriented employee record 65. Which of the following relational calculas expressions is nto
system for a company. Each employee has a name, unique id safe?
and salary. Employees belong to different categories and (a) {t | $u Î R1(t[A] = u [A] ^Ø $s Î R2 (t[A] = s [A]}
their salary is determined by their category. The functions (b) {t | "u Î R1(u [A] “x” $s Î R2 (t[A] = s [A]= ^[A]))}
get Name, getid and compute Salary are required. Given the (c) {t | Ø (t Î R1)}
class hierearchy below, possible locations for these
(d) {t | $u Î R1(t[A] = u [A] ^ $s Î R2 (t[A] = s [A]}
functions are:
66. What is the goal of concurrency control protocol?
1. getid is implemented in the superclass
2. getid is implemented in the subclass (a) schedule should be serializable
3. get Name is an abstract function in the superclass (b) schedule should be recoverable
4. getName is implemented in the superclass (c) both (a) and (b)
5. getName is implemented in the subclass (d) none of these
6. getSalary is an abstract function in the superclass 67. Consider the relation Student (name, sex, marks) where the
7. getSalary is implemented in the superclass primary key is shown underlined, pertaining to students in a
8. getSalary is implemented in the subclass class that has at least one boy and one girl. What does the
following relational algebra expression produce? (Note: r is
Employee the rename operator)
P na m e (r sex= fema le (S tud en t)) –P na m e (S tu de n t (Sex = female
^ x = male
^marks £ m)

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

PAST GATE QUESTIONS EXERCISE 5. (c) R = (A, B, C, D)


1. (d) A ®B, BC ®D, E ® C, D ® A r1 = P A,B,C ( R ) and r2 = P A,D ( r )
We start form set of all the attributes and reduce s = r1 * r 2
them using given functional dependences The tuples in s are more than that of r. Also, s consists
ABCDEH ABCDEH of all the tuples of r along with other tuples. Therefore,
ABCEH {BC- ® D} the most appropriate relation is r Ì s .
ABEH{E ® C} BCDEH {D ® A} 6. (c) The statement false is Lossless, dependency-
AEH {A ® B} BEH {E ® C} preserving decomposition into BCNF is always
ABCDEH possible.
ACDEH {A ® B} Lossless, dependency preserving decomposition is
possible in certain cases only. It is important to note
ADEH{E ® C}
that BCNF is not dependency preserving in all cases
DEH{D ® A}
but in some cases only.
So candidate keys are AEH, BEH &DEH
7. (d) We know that indexing is better if the data block is
2. (d) The computation is as follows large.
1. Select the name of the title Now, B+ trees are preferred over the binary search trees
2. title is selected from the book as in B+ trees, transfer of data from disk to primary
memory is in form of data blocks. These data blocks
3. Initiates a count
can store large information while transferring,
4. consider book as T information on a single block is more efficient.
5. compute the title of five most expensive books 8. (c) Consider a+
3. (c) On delete cascade says that deletion of a primary key result = a
value should Also consider, a = a+
delete its all foreign key references. While do
So in (2,4) 2 is primary key so tuples (5,2) & (7,2) for each functional dependency X ® Z in f
should be deleted, do begin
but in (5,2) 5 is also a key so (9,5) also deleted if X C a (result), then
cascade. result = result YZ
Hence (C) is correct option. end
compute {AF}+ = {AF}
= {AFD} AF -> D
4. (b) ={AFDE} F -> E
9. (c) Given that left hand side is plan 1 and right hand side is
E1 R1 E1 plan2.
Plan1
1. select records form paid
R2
2. joins them
Plan2
Since R2 is many to many so E1 has some primary 1. Joins records from paid
key so one tables for E1 & to represent many to 2. records are checked
The seek time of disk is 4 ms and data transfer rate is
many relationship 1 table for R2 which will have the
300 MB/s.
common attribute of E2.R1 & E2 can be merged. So
So, if x = 5000. Although the output remains the same
total 3 tables are required.
but the plan 1 executes faster than plan 2 for all
Hence (b) is correct option
databases.
DATABASES S3-461
10. (c) Query1 selects and defines that students enrolled in the result as after the ‘where not exists’, it does not
the course are same as students paid. have statement to produce the result.
Query2 selects and defines that students paid in the Query2 It selects an employee who gets higher salary
course are same as students enrolled. than anyone in the department 5.
Query3 Enrolled = paid student Therefore, the query2 is correct.
Query4 selects the students where enrolled student = 16. (c) We are given with the below relational calculus: (e.name
paid student. | employee (e) Ù }
The result is same in all queries. ( "x ) (¬ employee (x) Ú x.supervisor Name ¹ x.sex =
11. (c) Query1 where A.balance <= B.balance ® this line “male”]}
computes the A group of customers and the balance is (e.name | employee (e) Ù } gives the name of the
less than or equal to the group B. employee
Query2 where A.balance < B.balance ® this line
computes the A group of customers and the balance is ( "x ) (¬ employee (x) Ú x.supervisor Name ¹ x.sex =
less than the group B. “male”]} tells that employee does not have any female
Therefore, the row produced by query1 and query2 subordinate.
will be same but not in every case as the results of 17. (b) (ssex = “female” (studinfo) tells that students are females.
query1 and query2 differ in case where query1 has the Pcourseld (enroll) gives the Id of the course in which to
situation <= but query2 has only <. enroll.
PstudId (enroll) tells regarding a proper subset of females
None of the query provides the correct implementation
that are enrolled.
of the specification.
Finally,
12. (c) Lets construct the S1 and S2 with the time to check the
Pcourseheld tells Course in which a proper subset of
serializable conflict
female students are enrolled.
¾¾¾® 18. (c) As it is given that the transaction is already committed,
Time
the changes are already made.
S1 : r1 ( X ) ; r2 ( Y ) ; r2 ( X ) ; r2 ( Y ) ; w 2 ( Y ) ; w1 ( X ) Now, since the changes are made, they are permanent
S2 : r1 ( X ) ; r2 ( X ) ; r2 ( Y ) ; w 2 ( Y ) ; r1 ( Y ) ; w1 ( X ) so we do need to restore them as the failure has no
effect on the transaction.
S1 ® No serializable conflict We need not redo log records 2 and 3 because
13. (b) Let the order of leaf node is n. transaction T1 has committed.
As per given, Block size = 1 k = 1024 19. (a) Since P2 depends on P1, the only key value, so merging
Þ 6 + 7n + (n – 1) 9 = 1024 P and M in one result will lead to non-normalized tables.
Þ 16n = 1024 This needs to be removed without the loss to the
Þ n = 64 information as P1 and P2 have primary key as P1, and
14. (d) Statement (A) Any relation with two attributes is in N1 and N2 has primary key as N1.
BCNF is true as with the rule of BCNF, any relation Therefore, the attribute set of table is
with two attributes gets into Boyce codd normal form. {M1, M2, M3, P1}
20. (a) As per the given
Statement (B) A relation in which every key has only
The entity set : M, P and N
one attribute is 2NF is true as 2NF allows only the
Binary relations: R1 and R2
relation where a key has only one attribute.
Since, there are two binary relations, so minimum 2
Statement (C) A prime attribute can be transitively
tables are needed for representing the given diagram.
dependent on a key in a 3 NF relation is also true as
21. (c) No. of records = 16384
prime attribute has to be transitively dependent on a Size of record = 32 byte
key is 3 NF. Block size = 1024 = 2 ^ 10
Statement (D) A prime attribute can be transitively Here, we need to find the option that satisfies the
dependent on a key in a BCNF relation is false as this is condition 2^10.
a feature of 3NF and not BCNF. Option (a), 8 × 0 = 0
15. (b) As per given, Option (b), 128 × 6 = 768
employee (empld, name, department, salary) Option (c), 256 × 4 = 1024
This suggests that an employees is to be denoted using Option (d), 512 × 5 = 2560
the employee Id, name, department, salary Since, option (c) satisfies the block size, it is the desired
Query1 It selects an employee but does not compute answer.
EBD_7203
S3-462 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
22. (c) We will observe that if all the non-key fields are fully 26. (a) S name is selected from Supplier S. Now this S.sid
dependent on a whole key then a table would be formed should not be in C.sid of Catalog C.
in the Second normal form (2NF). Therefore, it will find the names of all suppliers who
This table will be in 3NF only when non-key fields are have supplied a non-blue part.
independent on a whole key then a table. 27. (c) This is very clear from the options itself that the option
Alternatively, 2 and option 4 are equivalent as option 2 is technical
Relation Book: transitivity dependency by 1, 2, 3 representation of code given in option 4.
statements as given, hence, the relation Book is in 2NF. Therefore
Relation Collection L: it is in 3 NF as there is fully
transitive dependency. {t | t Î pR -S ( r ) Î "u Î s ( $Ú Î r ( u = v [s] Ù t = v [R - S]) )}
Therefore Book is in 2NF and Collection is in 3NF. = Select R.a, R.b
23. (c) From R, S
1. Pp (R S) = Where R.c = S.c
Joins the relation between R and S projecting column 28. (a) No. of splits would be three. This can be further
P. displayed in the figure below
2. Pp (R) Pp (S) Insert 10 : 10
Insert 3 : 3, 10
Column P is projected from R and individually, column Insert 6
P is projected from S, finally joining the relation. This
can simply be said that it joins the relation between R 6
and S projecting column P.
First split
3. Pp(PP, Q (R) Ç PP, Q (S))
3 10
Column P and column Q are projected from R. Similarly,
Column P and column Q are projected from R.
6
Similarly, Column P and Column Q are projected from
S. The intersection function finally joins the relation of Insert 8
R and S projecting column P. 3 8, 10
4. Pp(PP, Q (R) PP, Q (R) – PP, Q (S)))
Function will not create relation between R and S. 6
Therefore, 1, 2, 3 are similar and one kind.
Insert 4
24. (a) We are given that the clustering index is defined on 3, 4 8, 10
the fields.
Now, if the records of the file are physically ordered on
3, 6
a non-key field since it is a non-key, it will not have a
distinct value for each record. Insert 2
Therefore, the clustering index is defined on the fields 2 8, 10
4
of type non-key and ordering.
25. (b) The candidate key needs to be searched first so that Second split
the prime attribute (candidate key) is identified,
3, 6
Here (sname, city) is the candidate key. So, the prime
attribute are sname and city.
Insert 1
Each supplier and each street has a unique name ® 1, 2 8, 10
4
street, city ® sname
Since street, city does not form a candidate key as the Therefore, the total number of splits is
candidate key available here is (sname, city), the schema
is in 3NF and not in BCNF.
DATABASES S3-463
29. (b) Let us construct the schedule and transition diagram
to determine the conflict: Dependency graph T1 T2 S3 also have no

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

R contains 200 tuples and S contains 100 tuples.

T1 R1x W1x W1y Natural join =R S = p [s (R × S)]

S2 So, R = 200 tuples and S = 100 tuples

T2 R2x R2y W2x So, R S = 100 [common is both or we can say


distinct equality between all common attributes]

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

Dependency graph T1 T2 S 2 have no


pld pname Age
cycles.
1 Rahul 66
Schedule S3
2 Sourav 67
3 Anil 69
T1 T2
R[x]
W[x] and the pld common to reservation is 1 and 3.
R[x]
W[y] 1 AC
W[y]
W[y] 3 AC
EBD_7203
S3-464 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
34. (b) In B+ tree, the root node has minimum 2 block pointers The result of given relational algebra expression will
and maximum P block pointer where, P = order where, be
key = order – 1 and in the non-root node, the minimum Id Name Age Id Phone Area
number of keys ---------------------------------
12 Arun 60 10 2200 02
éPù 15 Shreya 24 10 2200 02
= ê ú -1
ë2û 99 Rohit 11 10 2200 02
25 Hari 40 10 2200 02
So, in the question key = 5, order = 6
98 Rohit 20 10 2200 02
So, minimum number of keys in non-root node 99 Rohit 11 99 2100 01
98 Rohit 20 99 2100 01
é6ù
= ê ú -1 = 2 40. (b) SELECT A. Id
ë 2û FROM A
WHERE A. Age > ALL (SELECT B. Age
35. (a) X Y FROM B
1 1 WHERE B. Name = ‘Arun’)
2 3 In the table B ‘Arun’ is not there, so there query in
3 7 WHERE clause returns null set.
4 15
If a subquery returns zero rows, the condition evaluates
5 31
6 63
as true.
7 127 So, all 3 rows will evaluated as true.
41. (b) Suppose the schedule is
For X= 7 Þ Y = 127
36. (a) T1 T2

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

Borrower Bank manager Bank manager Loan amount T1 T2


Ramesh Sunderajan Sunderajan 10000.00
Ramesh Sunderajan Sunderajan 7000.00
Ramesh Sunderajan Sunderajan 5000.00 Precedence graph for the schedule
Mahesh Sunderajan Sunderajan 10000.00 So, this is not the conflict serilizable schedule so option
Mahesh Sunderajan Sunderajan 7000.00 (c) is not correct. Also option (d) is eliminated because
Count *( S T) = 5
above, we have drawn the precedence graph.
37. (c) Above schedule is not even view serilizable schedule
38. (a) Candidate key cannot be commen. Here, the two (it fails the condition of view serializable schedule).
students can have common account nuntler bank So, above schedule is not serializable schedule.
account number will not work like candidate keys. 42. (b) Suppose, there are two relation schemas R1 (A, B)
39. (a) Result of AUB will be following table and R2 (C, D)
Id Name Age r1 and r2 are two relation instances of R1 and R2
---------------- respectively.
12 Arun 60 B is a foreign key that refers to C in R2.
15 Shreya 24 If r1 and r 2 satisfy referential integrity constraints
99 Rohit 11
25 Hari 40 therefore, P B ( r1 ) Ê P B ( r2 )
98 Rohit 20
DATABASES S3-465
43. (c) According to relation between the different normal 45. (d) Consider P statement:
forms i.e., An SQL query can contain a having clause even if it
1NF has a GROUP BY clause. So, the given statement is
2NF false.
3NF Consider Q statement:
This statement is correct.
BCNF Consider R statement:
This statement is wrong because all the attributes used
in GROUP BY clause are superset of all the attributes
which are listed in SELECT clause.
Consider S statement:
This statement is wrong because not all attributes used
BCNF is more restricted than 3 NF and 3 NF is more
in GROUP BY clause need to appear in the SELECT
restricted than 2 NF and so on. clause.
Consider option (a): 46. (c) A clustered Index sorts and stores the data rows in
The statement is given which is wrong because every the table or view based on their key values.
relation which is in 3rd normal form it is not necessar The column on which clustered Index is created need
that those will be in BCNF form. Hence, this is false. not be primary key but it should always be not Null.
Consider option (b): 47. (a) "´ ($z (Øb) ® "y(a))
When every non-prime attribute of R is fully functionally
(d) "´ ($y (Øa ) ® $z (Øb))
dependent on every key of R.
is NOT logically equivalent to
Then, that relation is in 2 NF not in 3 NF.
Consider option (c): Ø$ ´ ("y (a ) Ù "z (b))
Every relation which is in BCNF, then it is confirmed 48. (a) (P) The line graph of a cycle is a cycle.
that it is also in 3 NF. Let c be a cycle. In the line graph L(c)
(i) There will be an edge between two vertices
Consider option (d):
corresponding to adjacent edges in the cycle.
This statement is wrong because the relation can be in
(ii) Degree of each vertex in L(c) will be 2.
both BCNF and 3 NF. (iii) L(c) will be connected.
44. (c) An attribute of an entity can have more than one value Hence L(c) will also be a cycle \ P is true.
or multivalue. (Q) The line graph of a clique is a clique.
For example, Let 'Kn' be a clique on 'n' vertices.
Consider line graph L (Kn) – L (Kn) has nC2 vertices.
For n> 3, there will be atleast two edges say e1, e2
Name Phone Number in "Kn" which do not share a vertex in "Kn".
Ram 012364 So, V (e1), V (e2) will not be adjacent in L(Kn)
Ram 023146 Hence, L(Kn) is not always a clique.
Anil 058633 (Q) is false.
Anil 014362 (R) The Line graph of a planar graph is planar
Let G be a star graph. Considering a line graph
Anil 056342
L(G) : V(e1), V(e2), V(e3) ® K5,

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

R(a, b, c) and S ( d, e, f) For AB ® C in BCNF ü INF


ï
here d is the foreign key of S that refers to the primary A ® D in 1 NF ( Partial dependency ) ý
key of R. B ® EF in 1 NF ( Partial dependency ) ïþ
1. Insert into R will not cause any violation.
Hence (a) is the correct option.
2. Insert into S may cause violation because for each entry
in ‘S’ it must be in ‘R’. 29. (a) R = {A, B, C, D, E, F, G, I}
3. Delete from R may cause violation because for the FD = {ABD ® E, AB ® G, B ® F, C ® J,CJ ® I,G ® H}
deleted entry in R there may be referenced entry in the Since J does not belong to the R hence the
relation S. Functional Dependency C ® J and CJ - I is not valid
4. Delete from S will not cause any violation. but C ® I is valid.
23. (c) Given query performs natural join between r & s , & Hence the remaining FD’s are
then project {ABD ® E, AB ® G, B ® F, C ® I, G ® H
attribute A where A = a. This same result is \ The candidate key is {A, B, C, D}
produced by the query sA=a (r) A s . {ABD ® E, AB ® G, B ® F, C ® J,CJ ® I,G ® H}
This query selects attribute A = a from r & then \ The candidate key is {A, B, C, D}
performs join
Hence (a) is the required option.
operation results are same.
30. (d)
Hence (C) is correct option
31. (c) Dependency Preserving Decomposition:
24. (d) Decomposition of R into R1 and R2 is a dependency
25. (a) A foreign key field may be null since there may be no preserving decomposition if closure of functional
entries in the referenced relations for the foreign key dependencies after decomposition is same as closure
attribute. of FDs before decomposition. A simple way is to just
check whether we can derive all the original FDs from
26. (d) a c the FDs present after decomposition.
1 2 In the above question R(A, B, C, D) is decomposed
into R1 (A, B) and R2(C, D) and there are only two
2 3
FDs A -> B and C -> D. So, the decomposition is
dependency preserving
As we can see clearly both entries of (a < c) also for
Lossless-Join Decomposition:
selecting the entries we have to project on R.
Decomposition of R into R1 and R2 is a lossless-
Hence (d) sa <c ( P a,c R ) is the correct option. join decomposition if at least one of the following
functional dependencies are in F+ (Closure of
27. (d) R(A, B, C, D, E, F, G, H, I, J) functional dependencies)
A+ = {A} (A B C D)+ = (A, B, C, D, G, E, F, H, I) R1 Ç R2 ® R1
B+ = {B, F} OR
R1 Ç R2 ® R2
C+ = {C, J} Hence (A B C D) is the candidate key
In the above question R(A, B, C, D) is decomposed
D+ = {D}
into R1 (A, B) and R2(C, D), and R1 Ç R2 is empty.
E+ {E} So, the decomposition is not lossless.
F+ = {F} 32. (c)
G+ = {G, H, I}
EBD_7203
S3-470 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
33. (c) Statement 1 and 2 depicts the nature of preference or fetching such records, it makes more sense to
security and data over the data redundancy which is fetch only unique records instead of fetching
satisfy by the 3 NF. duplicate records.The SQL Distinct keyword,
Although BCNF satisfy this property also but which we already have discussed, is used in
dependencies not preserved always. conjunction with SELECT statement to eliminate
34. (b) For the relation X = (d, b, c, f, g, h) all the duplicate records and fetching only
unique records.
decompose into a = (d, b, c) and e = (d, f, g, h)
Syntax:
We have ‘d’ is the candidate key for the relation ‘a’. The basic syntax of DISTINCT keyword to
Hence decomposition is lossless. eliminate duplicate records is as follows:
SELECT DISTINCT column1, column2,.....
x (d, b, c, f, g, h)
{d ® bc, g ® hd} columnN
FROM table_name
a e
(a, b, c) (d, f, g, h) WHERE [condition]
a ® bc g ® hd (b) An SQL query will not work if there are no
indexes on the relation;False
Clearly we can see that all the dependencies in the parent Indexes are used to police database constraints,
relation X in preserved in a & e hence dependencies is such as UNIQUE, EXCLUSION, PRIMARY
preserved. KEY and FOREIGN KEY. An index may be
35. (b) F = {AB ® CE, E ® AB, C ® D} declared as UNIQUE, which creates an implicit
Candidate key = {E, AB} constraint on the underlying table. Database
AB ® CE E ® AB C ® D systems usually implicitly create an index on a
set of columns declared PRIMARY KEY, and
BCNF BCNF 2NF
some are capable of using an already existing
2NF
index to police this constraint. Many database
Hence relation in 2NF systems require that both referencing and
36. (b) R(A, B, C, D, E, F, G) referenced sets of columns in a FOREIGN KEY
FD’s = A ® B, BC ® DE, AEF ® G constraint are indexed, thus improving
performance of inserts, updates and deletes to
Candidate key = {ACF}
the tables participating in the constraint. Tables
for option (a) BC ® DG is not possible since A in not are combined in queries by matching the
there for option (b) ACF ® DG in possible as ACF is
column or columns in the foreign key . However,
candidate key, for (c) A ® DG is not possible since C
creating this index is not required.
& F in not there, for (d) B ® DG is not possible.
(c) SQL permits attribute names to be repeated in
37. (b) FD’s = {a, b ® c, d; e ® c; b ® e, f} the same relation: False
Candidate key = {a, b} An attribute value is an attribute name paired
ab ® cd e ® c b ® ef with an element of that attribute’s domain, and
BCNF 2NF 1NF a tuple is a set of attribute values in which no
two distinct elements have the same name.
1NF
Thus, in some accounts, a tuple is described as
Hence R(a, b, c, d, e, f) in 1 NF. a function, mapping names to values. A set of
38. (d) Data definition – Data Definition Language provides attributes in which no two distinct elements
facilities to modify structures or tables such as defining have the same name is called a heading. A set
new data structures for a database, removing data of tuples having the same heading is called a
structures from the database, modifying the structure body
of existing data. 40. (d) (a) x = = 5 and not (not (n = 5))
39. (d) (a) An SQL query automatically eliminates (b) x = 5 and x > 4 & x < 6, x in integer
duplicates:False
(c) x ¹ 5 and not (x = 5) are all equivalent hence the
There may be a situation when you have
correct option (d)
multiple duplicate records in a table. While
DATABASES S3-471
41. (c) When the tuple (2, 4) is deleted then wherever the (b) Two phase locking guarantees serializability-
primary key value 2 comes under the referenced True : Two-phase locking protocol through its
attribute C then that corresponding tuple is violating implementation guarantees the serializability of
the referential constant therefore that tuple must be the schedule. This is done by enforcing any
deleted also. transactions T in a schedule
Hence correct option is (c)
(c) Strict two phase locking is deadlock free-False :
Primary key Foreign key
with strong strict two-phase locking (SS2PL)
A C the locking protocol releases both write
2 4 (exclusive) and read (shared) locks applied by
3 4 a transaction only after the transaction has
4 3 On delete ended, i.e., only after both completing executing
cascade (being ready) and becoming either committed
5 2
or aborted.Two-phase locking does not ensure
7 2
freedom from deadlocks.Cascading roll-back is
9 5
possible under two-phase locking. To avoid
6 4 this, follow a modified protocol called strict
42. (b) As we can see clearly T4 and T7 are followed by T3 two-phase locking. Here a transaction must
and T 4 in succeed by T 3 & T 7 and soon, hence hold all its exclusive locks till it commits/aborts.
topological sequence represented by the above
(d) Timestamp protocol may not result recoverable
transactions is
schedule: True Timestamp protocol ensures
R(Q) freedom from deadlock as no transaction ever
waits. But the schedule may not be cascade-
free and may not even be recoverable.
W(Q) 47. (a) For fixed length record unspanned organization is
preferred.
W(Q) R(Q) A block is the unit of data transfer between disk and
W(Q) memory. Unspanned records are records that is
found in one and only one block. Records do not
span across block boundaries and are used with
fixed-length
T3 T7 T4
48. (d) Index sequential file is made of all of these except
address of prime data track. An indexed file system
43. (a) In case of timestamp ordering R-timestamp (Q) denotes consists of a pair of files, one holding the data and one
the largest timestamp of any transaction that execute storing an index to that data. The index file will store
read (Q) successfully. the addresses of the records stored on the main file.
44. (d) Locking was introduced into database so that 49. (a) The query selects all attributes of r. Result can be equal
consistency can be enforced. A lock, as a read lock or to r only if r doesn’t have duplicates because of the
write lock, is used when multiple users need to access SQLN DISTINCT.If we do not give any attribute on
a database concurrently. This prevents data from being
which we want to join two tables, then the queries like
corrupted or invalidated when multiple users try to read
above become equivalent to Cartesian product.
while others write to the database.
Cartisian product of two sets will be empty if any of the
45. (c) For two-phase locking locks are acquired in the first
two sets is empty. So, s should have atleast one record
phase. Two phase locking has two phases, one is
to get all rows of r.
growing; where all locks are being acquired by
transaction and second one is shrinking, where locks 50. (a) FD X ® Y is trivial if set {Y} is a subset of set {X}
held by the transaction are being released. 51. (d) The given query first calculates the average salary from
46. (c) (a) Timestamp protocol is deadlock free. True: The the relation Employee, then it selects the department
protocol manages concurrent execution such that name wher employee who ahve average salary more
the time-stamps determine the serializability than the average salary of the company.
order. Timestamp protocol ensures freedom from Hence (d) is correct option.
deadlock as no transaction ever waits
EBD_7203
S3-472 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
52. (c) Relational algebra is a procedural query language and 59. (a) For the relation (A, B, C)
relational calculus is a non-procedural query language. A ® BC
Relational algebra consists of a collection of operators B ®C
used to perform various operations on the relations A ®B
of database.
AB ® C
In relational algebra, relational operators are:
The canonical cover is A ® BC and B ® C which is
(a) The select operator functionally determining all the FD’s represented in
(b) The project operator the relation and is minimally satisfying all the non-trival
(c) Set operators relationships.
(i) Union 60. (d) The given ERD shows the self recursively relationship
among Employees.
(ii) Difference
1 is supervisor 2 is supervisee.
(iii) Intersection
The possible relation is
(iv) Cartesian product Relational Calculus:
Employee (Emp Id, Birthdate, Salary, Name (First Name,
Relational calculus is a non-procedural relational Middle Name, Last Name), Supervisor ID)
data manipulation language in which user simply
61. (a) Each employee has a unique Id, name and salary,
specifies what data should be retrieved, but not how
Employees may have different salary as per their
to retrieve the data. The relational calculus is a formal
category e.g. Manager, Engineer or Secretary.
query language. It is not related to the differential
and integral calculus. The relational calculus is not Id is unique for each emoployee for a given employee
with Id name is unique.
easy to learn and to use. It is not used in commercial
database processing. Hence, get id and get name must be implemented in
Superclass as whatever their designation it will not
53. (d)
change. Get salary must be an abstract function in
54. (a) A foreign key is a key of a relation which is primary key superclass and implemented in subclasses.
of some othe rrelation. A primary key is combined with 62. (b)
foreign key then a referential constraint is set up
between the two relation, hence it creates a parent-
child relationship between the tables that connects E1 1 R m E2
them.
55. (a) The condition T, assets > S. assets and S, branch_city
= “PONDICHERRY” checks for the all those branch- A11 A13 A21 A23
name who have greater assets than any branch located A12 A22
in Pondicherry. The keyword distinct removes the
duplicacy of branch_name satisfy the given condition. Since each table is to in 3rd Normal form for each multi-
56. (b) The relation EMPLOYEE has one to one relation valued attribute individual table is to be created. Hence,
between project and employee i.e. each employee has total number of tables in the database is 3.
being assigned a project and each project is associated 1 for entity set E1, 2 for entity set E2 and 3 for attributes
with only one employee, hence project-number is A23 .
functionally dependent on Emp-no.
57. (a)
63. (d) ( ) (
sC1 sC1 ( R1 ) ® sC2 sC 2 ( R 2 ) )
58. (d) All of the given option valid. The conditions C1 and C2 may not be same.
(a) sP (sQ(e)) = sQ(sP(e)) 64. (a) With the help of {p, x, –} we can perform division
(b) sP (sQ(e)) = sP^Q(e) operation.
(c) sQ (sP(e)) = sP^Q(e) Note. Division operator produces a relation R (X) that
includes all tuples t[x] in R(z) that appear in R1 in
They simply find and selects the tuples which are
combination with every tuple from R2 (y) when
common on both P and Q.
Z= XÈY
DATABASES S3-473
65. (c) A relational calculus expression may contain infinite A ® B, C®D E
tuples that are not in the relation, R1. a a (Ist row) a a a (IInd row)
{t | Ø (t Î R1)} a b (IIIrd row) a b b (IIIrd row)
s[A] = u convert be to a in IIIrd row convert b to a in IIIrd row
66. (c) When multiple transactions are trying to access the Since IIIrd row contains all ‘a’s hence the relation has
same sharable resource, there could arise many lossless join property.
problems if the access control is not done properly.
72. (c) Whenever {A,B} are the same then C must also be the
There are some important mechanisms to which access
same. If two tuples differ in either A or B fields then
control can be maintained. Goal of concurrency is
they may also differ in the C field. Hence that is best
serializability and recoverability.
represented by (c)
67. (d) The given expression can be understood as
73. (d) From the given instance we can determine that
(i) The sub-expression
pname(Student Pn’,x,m(Student)) when A =1 B = 1ü
ý Hence A functionally
(sex = female) A = 2 B = 3þ
^ x = male determines B.
^ marks £ m)
gives the same of female students who have less marks when B = 1 C = 1ü
ï
than other boys. C = 0ý
Hence B functionally determines C.
(i) The expression pname(rsex=female(student)) gives B = 3 C = 2ïþ
the name of all the female student from (i) and
74. (c) R = (A, B, C, D, E)
(ii) The given expression finally calculates the names
of females student who have marks more than all F = {A ® BC, CD ® E, B ® D, E ® A}
the boys in the class. A+ = ABCDE so A is the candidate key.
68. (d) r contain 1000 tuples and values for A are uniformly A can be replaced by E.
distributed in the interval [0, 500] So, E also a candidate key.
No. of values in [0, 500] = 500 E can be replaced by CD.
No. of tuples to be covered = 1000 Hence, {A, E, C, D} are the candidate keys.
\ Each value in domain accounts for 2 tuples. 75. (c) A relation is 3NF it for X ® A
Hence sA ³ 100 (r) returns 200 tuples in best case (i) X is a super key or candidate key
estimates.
(ii) A is a prime attribute
69. (b)
Hence, for A to be non-key attribute (non-prime
70. (a) R (A, B, C, D) FDs = {A ® B, A ® C, A ® D} attribute)
R1 (A, B, D), FDs = (A ® B, A ® D) x-must be satisfying (i)
R2 (B, C), FDs = {} 76. (b)
clearly we can see that B is the common attribute and B R = {V, W, X, Y, Z}
is not candidate key of any of the decomposed
FD = {VY ® W, WX ® Z, ZY ® V}
relations.
V+ = {V}
Hence, dependency is not preserved.
VY+ = {V, W, Y}
71. (a) R = {A, B, C, D, E, F} F = {A ® B, C ® DE, AC ® F}
R1 = (A, B) R2 = {C, D, E}, R3 = {A, C, F} VYX+ = {V, W, X, Y, Z}
77. (d) {a, b ® c, d;
A B C D E F a, c ® b, d}
AB a a b b b b here either of (a, c) or (a, b) can be made key for
CDE b b a a a b normalization of Relation (a, b, c, d).
ACF a ab a ab ab a Only (d) is correctly implementing the relation.
EBD_7203
S3-474 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
78. (c) The given query 1 88. (c) The database contains the adjacency list of the
` UPDATE project J1, set CITY to New York. graph. So relation algebra with face problems when
updates the city to New York where J# is J1. while calculating the length of cycle self loops come,
then the query would execute in one tuple only.
Hence Query 1 is accepted.
Given Query 2 89. (c) In option (c) {t G(t Î R1)} is not safe since no criteria
UPDATE part P3, set P# to P4 for selection of tuple has been given.
tries to update the Table Part and P# to P4 which is not 90. (a) BCNF (Boyce Cold Normal Form) Since R is
valid. decomposed in BCNF then no redundancy in the
Hence, Query 2 is rejected. resulting set may occur and all transitive
79. (d) 80. (b) dependencies are removed.
81. (c) For the required list of departments having average 91. (d) Size of 1 record of index = 8 + 4 = 12 bytes.
salary greater than 20000 from employee table. We have Let no. of pointers required = P
to first calculate the average salary of each department No. of index values per block = P – 1
and then lists the departments who have their average So (P – 1)8 + 4P = 512
salary greater than 20000. 12P = 520
82. (c) For relation X cardinality = 2 P=44
For relation Y cardinality = 4 92. (b) A is said to be functionally determined by B only is
Hence the SQL statement A has same value for same values of B for every
Select COUNT (*) from X, Y corresponding tuple.
gives the number of rows for the relation obtained from In given database
cross product of X, Y.
Hence, 2 × 4 = 8 is the correct option.
A B
83. (c) Time stamp ordering ensure both conflict serializability
and free from deadlock. 1 1
84. (c) Assuming that large enough memory is available for 1 1
all data needed. Both plans need to load both tables 2 3
courses and enrolled. So disk access time is same for
both plans. 2 3
Plan 2 does lesser number of comparisons compared
to plan 1. here if A is 1 then B is necessarily 1 & if A is 2 then
(1) Join operation will require more comparisons as B is 3. So B is functionally determined by A. But this
the second table will have more rows in plan 2 relationship is not true for any other pair.
compared to plan 1. 93. (d) (a) read & then write.
(2) The joined table of two tables will have more rows, (b) read after read
so more comparisons are needed to find amounts (c) read after committed write
greater than x. (d) read after uncommitted write
85. (b) empid name department salary Option (d) is a condition for inconsistency
1 a 4 90k 94. (d) Date of Birth ® Age
2 b 5 30k Age ® Eligibility so transitively
3 c 5 50k Date of Birth ® Eligibility
4 d 5 80k ˆˆ†
Name ‡ˆˆ Roll no.
Q1 will give empid 1
Q2 will give empid 1, 3, 4 Given relation ¾¾
¾¾
® (Roll no. Name, Date of
®
But the correct answer is 4 Birth, Age) Roll no.
86. (c) There is no means to represent a tie in a particular & Name are keys
event. 1. Age is functionally dependent upon date of
87. (c) R(A,B,C,D) birth which is non key, so 2NF is not applicable.
R1(AB) & A ® B, C ® D 2. In 3NF, every non key should be non transitively
R1(AB) & R2(CD). or fully dependent upon all the keys, but here
So dependencies are preserved during decomposition. this is not the case, so not in 3NF.
But for lossless join. 3. In BCNF every non trivial functional dependency
R1(AB) Ç R2(CD) ® R1(AB) in the relation is a dependency on a super key.
R1(AB) Ç R2(CD) ® R2(CD) So also not in BCNF.
Since A ® B &C ® D So it is in INF only, since no repeating tuples.
So lossless join not possible. Hence (D) is correct option.
DATABASES S3-475
95. (c) Tuple (x,y) is deleted. 102. (d) R(A, B, C, D, E, F, G, H, I, J)
Here y $ x A+ ® {A}
lb is primary key B+ = {B, F}
ub is foreign key C+ = {C, J}
Table A (geq) Table B (geq)
D+ = {D}
E+ = {E}
X Y X Y F+ = {F}
x y deleted z w G+ = {G, H, I}
[A B C D]+ = {A, B, C, D, E, F, G, H, I}
103. (a) AB is candidate key.
Since y refer to same key z . & in table A x a primary AB ® C in BCNF
key is deleted. so all enteries from table B will also A ® D (Partial dependency) so, it is not in 2 NF, it
be deleted. is in 1 NF
And also all enteries referencing it in y will also be B ® EF 1 NF (Partial dependency)
deleted. Hence, the given relation is in 1 NF.
So a tuple (z,w) with w < x will also be deleted. 104. (a) R1 = (N, R, C, T Z)
96. (a) Employee ID & employee name are independent of FD = {N ® RCT, RCT ® Z, Z ® CT}
subclasses; manager engineer or secretary, so these N+ = {N R C T Z}
should be implemented in super class, but salary is So, N is candidate key.
part of employee dependent, so abstract get salary 105. (c)
should be in super class & its actual implementation 106. (b) Every value of referencing attribute must be null or
in subclass. be available in the reference attribute.
97. (d) “Select average (salary) from employee” selects 107. (c) For the given entity relationship diagram, the
average salary of the company. attributes of the relation qualification, i.e., qualified
So the query returns the names of all the male data must be included when any relationship between
employees of all the departments whose average person and exam is required.
salary is more than the average salary in the 108. (d) Ellipse with underlined attribute is known as key
company. attribute.
98. (c) On delete cascade says that deletion of a primary key
value should delete its all foreign key references. 109. (d) ABCDE F
So in (2,4) 2 is primary key so tuples (5,2) & (7,2)
should be deleted, but in (5,2) 5 is also a key so (9,5)
also deleted cascade.
99. (d) It selects all those book titles where the price of the
book has difference than most expensive book not
more than 5.
So it selects five most expensive books. B ® D, D ® E Þ B ® E
100. (b) Loans (br_name, loan_no, _amount) E®AÞB®A
Query “Find the loan number for each loan of an
B ® Aü
amount greater than 2000”. ý ÞB®C
We can write this query as A ® Cþ
[+ 1 $ s Î loans [ + [loan_no] = S[loan_no] F®B
n[amount] > 2000] So, F ® B, F ® C, F ® A, F ® D, F ® E
101. (a) Referential integrity constraint. So, F is candidate key.
Every value of referencing attribute must be null or 110. (b)
be available in the referenced attribute 111. 2 + 22+ 4 + 10 =38 bytes
(d, e f) and R(a, b, c) 112. bfr = floor( B/R) = [512/38] =13
Here, d is the foreign key of S that refer to the Number of blocks b = ceiling (500/13) =39
primary key of R. 113. 512 – 38 *13 = 512 – 494= 18 bytes
1. Insert into R will not cause any violation. 114. = ( 39 *13 – 500) * 38 bytes = (507 -500) * 38 bytes
2. Insert into S may cause violation because for = 7 * 38 =266 bytes
each entry in S it must be in R. 115. 26
3. Delete from R may cause violation because for
(x-1)14+6x<=512 x=26
the deleted entry is R there may be referenced
116. (c) Given B+-tree
entry in the relation S.
Child pointer takes 6 bytes
4. Delete from S will not cause any violation.
EBD_7203
S3-476 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Search field value takes 14 bytes transaction number. This discriminator is used to
block size is 512 bytes uniquely identify each transaction of a particular
To find The order of the internal node account.
Solution Let the order of the internal node be X, 122. (b) In order to identify each transaction of any account
Then from the given, the key of strong entity with the addition of the
(X – 1) 14 + 6X £ 512 discriminator of weak entity can be taken. Here
Þ 15X – 14 + 6x £ 512 [Account number, transaction number] act as the
Þ 20X £ 256 primary key of weak entity. This is because weak entity
Þ X = 26 has no existence without strong entity.
+
117. (a) Given, A B -tree index 123. (b) R = (A, B, C, D, E, F, G)
Name attribute of the relation STUDENT FD’s = {A ® B, BC ® DE AEF ® G)
length 8 bytes (AC)+ = (A, B, C, D, E) using A ® B
disk blocks are of size 512 BC ® DE
index pointers are of size 4 bytes 124. (a)
To find Best choice of the degree of the tree 125. (a) From the relation DEPOSIT first we have to select the
Solution Size of disc block = 512 = 29 those entries in which balance is over 1000. This can
Size of index pointer = 4 = 22 be obtained by scustomer_name (Deposit),
The degree of the tree cna be calculated by the Now, we have to select those customers name who
formula below : have balance over 1000 which can be obtained by simply
projecting customer name in above sub-query.
Size of the block
Degree of the tree = 126. (a) Clients of Bankers Agassi can beobtained by using
Length X size of pointer the relation client_scheme while the corresponding
= (29 / 23 × 22) customer_city can be obtained using
= 2^4 = 16 customer_scheme.
118. (d) r contain 1000 tuples and values for A are uniformly Hence cross product of client and customer must be
distributed in the interval [0, 500] taken. This can be achieved in two ways.
Number of values in [0, 500] = 500 (i) first taking the Bankers Agasi clients and then
Number of values of be covered = 1000 checking their name in customer relation and
\ Each value in domain accounts for 2 tuples. projecting their customer city.
Hence, sA>100(r) returns 200 tuples in best estimates. (ii) first taking all the customers and matching them
119. (a) Minimum number of tables needed is 2. in customer_scheme, then finding out the
1st table have the relation between M and P and 2nd customers who have the Agassi as the Banker,
table as P and M. finally projecting the customer_city of the
respective customers.
120. (b) E1 1 m E2 127. (c) We have to find all customers in the relation Borow,
R
this can be achieved by
(t | $ s eborrow (t [customer_name]) = s
[customer_name]
The s here is bound variable and the condition of
A11 A12 A13 A21 A22 A23 checking loan-amount more than 1200 is to be checked
with each customer_name condition.
Since, each table in to be in 3rd normal form for each Hence option (c) is correct.
multivalued attribute individual table is to be created. 128. (b)
Hence, total number of tables in the database is 3. 1
for entity set E1, 2 for entity set E2, and 3 for
attributes A23.
121. (b) We can clearly see that transaction is the weak entity
with the discriminator (key for weak entity) as
9
Page - 477 - 514

INFORMATION SYSTEM AND


SOFTWARE ENGINEERING

C Ø Information gathering, requirement and feasibility analysis

O Ø

Ø
Data flow diagrams

Process specifications, input/output design

N Ø Process life cycle, planning and managing the project

T Ø Design, coding, testing, implementation, maintenance

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

Data Flow Diagram Process Specification and Logic

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

Software Processes and Process Groups in IEEE 1074


Process Group Processes
Life Cycle Modeling Selection of a Life Cycle Model
Project Initiation
Project Management Project Monitoring and Control
Software Quality Management
Concept Exploration
Pre-development
System Allocation
Requirements
Development Design
Implementation
Installation
Operation and Support
Post-development
Maintenance
Retirement
Verification and Validation
Software Configuration Management
Integral Processes
Documentation Development
Training
A summary of the activities and work products of each process group follows.
Life Cycle Modeling- The project manager customizes the selection and sequencing of
the activities required for a particular project
Project Management- The project manager initiates, monitors and controls the project
throughout the software life cycle.
The project management plan is documented in the Software Project Management Plan
(SPMP) during the Project Initiation process, and the plan is updated to reflect changes
throughout the project.
Pre-Development- Management and the client identify an idea or need, and the manager
establishes the initial system architecture. The need may addressed through:
· greenfield engineering — a new development effort
· interface engineering — a change to the interface of an existing system
· reengineering — a software replacement of an existing business process
A Problem Statement or Statement of Need (IEEE 1074) describes the business
requirements to be addressed by the project. Most authors say that the problem statement
should not discuss design and implementation topics, but your textbook suggests that
subsystem decomposition and communication infrastructure be included.
Development
The development process per se includes all the process directly involved in the
construction of the system.
Post-Development
After the software product is developed, it must be installed, maintained, and given
operational support, and an existing system may need to be retired (terminated).
Integral (Cross-Development) Processes
Some processes (in addition to project management) take place during the complete
lifetime of the project. Two of these processes require definition:
· verification — showing that the system models comply with the specification,
through reviews, audits, and inspections
· validation — ensuring that the system addresses the client’s needs, through
system testing, beta testing, and client acceptance testing
EBD_7203
S3-488 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Life Cycle Models
A variety of life cycle models have been proposed, most of which focus exclusively on
the development processes.
Code and Fix
A simple and widely used software life cycle model: Repeat the following steps until the
solution is good enough.
1. Code
2. Compile and execute
3. Detect errors
4. Fix
Waterfall Model
The prescribes a sequential execution of a set of development and management processes,
with no return to an earlier activity once it is completed. Some variants of the waterfall
model allow revisiting the immediately preceding activity (“feedback loops”) if
inconsistencies or new problems are encountered during the current activity.
V-Model
Another variant of the waterfall model — the V-model — associates each development
activity with a test or validation at the same level of abstraction. Each development
activity builds a more detailed model of the system than the one before it, and each
validation tests a higher abstraction than its predecessor.
Spiral Model
Spiral model addresses the weakness of the waterfall model, spiral model focuses on
addressing risks incrementally by repeating the waterfall model in a series of cycles or
rounds:
· Concept of Operation
· Software Requirements
· Software Product Design
· Detailed Design
· Code
· Unit Test
· Integration and Test
· Acceptance Test
· Implementation
The spiral model is an improvement on the waterfall model, as it provides for multiple
builds and provides several opportunities for customer involvement. However, it is
elaborate, difficult to manage, and does not keep all workers occupied during all phases.
Prototyping — the Sawtooth and Shark Tooth Models
As a software product is being developed, the developers’ view of the system diverges
from the client’s view, since the developer’s focus is on the design and implementation
while the client remains focused on requirements.
The sawtooth model provides checkpoints during the development process in order to
check that development is proceeding in a direction that will eventually meet the client’s
requirements. Typically, the checkpoints involve demonstrating a prototype to the client.
For example, two prototypes may be developed:
1. a revolutionary prototype is an illustrative model of the system, representing
only a small fraction of the required functionality
2. an evolutionary prototype, shown late in the development process, is based on
a completed design and implements some of the required functionality
The shark tooth model adds management reviews and demonstrations to the sawtooth
model. Since these may be seen to be at an intermediate level of abstraction, a diagram of
the model includes large “teeth” and small “teeth”.
Rapid Application Development and the Time Box Model
Rapid application development (RAD) is an approach rather than a model. The formality
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-489
of such models is seen as interfering with customer communication.
Instead, RAD focuses on developing a sequence of evolutionary prototypes which are
reviewed with the customer, both to ensure that the system is developing toward the
user’s requirements and to discover further requirements.
The process is controlled by restricting the development of each integration to a well-
defined period of time, called a time box. Each time box includes analysis, design, and
implementation of a prototype.
One problem with RAD is reaching closure — the customer always has feedback, and
the developers and the customer may never agree that the project is done.
Synch-and-Stabilize
Synch-and-stabilize is Microsoft’s attempt to scale-up a loosely structured small-team
(“hacker”) style of product development.
· many small teams (3 - 8 developers per team) work in parallel
· changes are synchronize frequently so components will work together
o developers check-in their code by a particular time so a new build (complete
recompile) is done by the end of the day or the next morning
o a defect that “breaks” the build must be fixed immediately
· features are evolved incrementally, with occasional innovations
o start with a “vision statement”
o select features and establish priority of features with user input
o developers are free to innovate or adapt to unforseen competitive
opportunities or threats
o continual testing during development
· the product is stabilized at 3 or 4 milestone junctures in the project lifetime
o thorough internal and external testing (beta sites)
o fix almost all errors detected
o “zero-bug” release at the last milestone
The process is also called a “milestone”, “daily build”, “nightly build”, and “zero-defect”
process. The overall strategy is to quickly introduce products that are “good enough”
to capture a mass market, then improve the product, selling multiple product versions
and upgrades.
PLANNING AND MA NAGING THE PRO JECT
Much of the project management effort across the lifecycle will be driven by the owner/
sponsor of the project (known as the Senior Responsible Owner (SRO) ), and the Project
Manager.

Initiating the project


The SRO, or identifier of the potential project should:
1. Define and justify the need for the project
2. Specify, quantify and agree desired outcome and benefits
3. Appoint a Project Manager and if appropriate set up a Project Board
The project management team should:
1. Plan how to deliver the required outcomes and benefits
2. Decide how to manage relationships with key stakeholders
3. Decide how to project manage the delivery process
4. Determine resource requirements and ensure they can be made available when
required
EBD_7203
S3-490 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
5. Develop Business Case to enable the SRO/Project Board to decide whether project
is cost and risk justified .
The SRO should ensure:
1. Post project reviews are carried out to measure the degree to which benefits have
been achieved
2. The Business Case is updated to reflect operational reality
3. Potential improvements/changes/opportunities identified in the reviews fed into
the strategic planning process for consideration
Defining project scope and objectives
Project objectives, scope and desired benefits must all be addressed when starting up a
project, and should be recorded in the Project Brief, and subsequently refined in the
Project Initiation Document (PID) during detailed project definition and planning.By
defining a project's scope you are trying to do a number of things to ensure that the
boundary between this project and other projects and programmes is clearly understood
and prevents gaps or overlaps in all the work that is necessary to achieve higher-level
objectives.
How to define SMART project objectives
A well defined and agreed (set of) objective(s) is a necessary pre-cursor to detailed
project planning. For the objectives to be useful as an aid to project management they
must be:
Specific to the project, and within the project. For example the objective: ‘To improve the
efficiency of our interactions with customers.’ is too vague.
Measurable. You need to define in as measurable and subjective terms as possible what
must be achieved. Measurability will depend on the nature of the objective and may be
in terms of such things as performance, cost, effort, % change, amount of time,
deliverables, quality levels, numbers of events, agreements, approvals, commencement
or termination of something, numbers of people/organisations, etc
Achievable. It must be possible to achieve the objective in practical terms and also
within whatever time target has been set .
Relevant. Is the objective consistent with, and does it contribute towards, the goal/
objective at the next level up . Make sure the project, or some part of it is not just there
because of a whim or has been influenced by an agenda that is not aligned with the
organisation's core purpose.
Time Bound (and, perhaps Trackable). It is useful to have a target date by which each
objective should be achieved.
Designing the Project Organisation
Every project must have its own management structure defined at the start and dismantled
at the end. The definition of the management roles, responsibilities, relationships and
accountabilities and authorities provides the basis of the governance arrangements for
the project.
Designing the structure and getting people to agree to take on roles takes time and may
require many discussions/negotiations with management at appropriately senior levels.
Senior Responsible Owner (SRO) (in certain circumstances/environments known as
Project Sponsor or Programme Director). The SRO is the project's owner and champion
and is ultimately accountable for delivery of the project and so he must provide leadership
and direction to other members of the Project Board and to the Project Manager and
ensure that all key stakeholders are committed to the project and adequately represented
in the project's organisation structure .
The Project Board The Project Board must jointly to create an environment where the
project can succeed in delivering the changes necessary for the benefits to be realised
andset the direction for the project and to approve key milestones.
Project Assurance
The SRO and other Project Board members must assure themselves that the project for
which they are accountable is properly planned, organised and controlled. Project
Manager : The Project Manager will be responsible on behalf of the SRO for day to day
execution of the project plan and for dealing with issues that might affect achievement of
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-491
the plan. The Project Manager must prepare the Project Initiation Document, submit the
PID to the Project Board for approval ,submit any revised versions of the Project Plan
and Business Case to the Project Board for approval ,monitor progress of the project.
Planning the project
Without careful planning it is likely that your project will fail to achieve its objectives. In
a small project it is possible that one plan may be used to define the entire scope of work
and all the resources needed to carry out that work.
The contents of the project plan
The Project Plan, the first version of which will form part of the PID, will typically contain
the following:
· Plan Description (a brief narrative description of the plan's purpose and what it
covers)
· Pre-requisites (things that must be in place for the plan to succeed)
· External dependencies (e.g. commitments required from outside agencies)
· Planning Assumptions (e.g. availability of resources)
· Financial budget - planned expenditure
· Resource requirements (e.g. in a table produced using a spreadsheet or project
planning tool)
· Requested/assigned specific resources
Planning checklist
1. Confirm scope and purpose of the plan:
Are you clear about the purpose of the plan? (e.g.: to gain commitment and
approval for a project/stage, for day to day management and control, to establish
feasibility or viability, to define contingency arrangements.
2. Define the deliverables:
Specify for each deliverable:
· What it must contain/cover
· Who will be responsible for its development
· What it is dependant on (e.g. information, resources)
· The required quality characteristics that must be built in to it
· The types of quality checks to be applied
· The skills, resources, individuals needed to develop the deliverable
· and to apply the quality checks
3. Identify and estimate activities
Identify all the activities necessary to quality control each deliverable
· Agree the order in which activities must be carried out
· Include activities that take into account the interest of stakeholders who will
use, operate and maintain the deliverables from the project
· Break down `large' activities that are difficult to estimate into sets of smaller
activities of a size you can estimate resource requirements and durations
with confidence
· Identify the skill types required to carry out each activity
· Estimate the amount of effort and optimum numbers of individuals
· Identify and estimate any non-human resources and services required
· If required, calculate the estimated cost to develop each deliverable/product
4. Schedule the work and resources
5. Identify risks and design controls
6. Document and gain approval for the plan
The plan to a form that should l be understood by its its audience.
The version of a plan for the SRO/Project Board should include, as a minimum: Narrative
describing the purpose, author(s), current status, assumptions, constraints, pre-
requisites, recommendations.
Risk Management
Managing your project risks helps you to demonstrate to your SRO, Project Board,
colleagues and key stakeholders that you are aware of your challenges, have considered
EBD_7203
S3-492 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
options appropriately, and that the project is going to deliver successfully. What this
means for you - the risk management process.
Risk identification - Risk management means identifying and managing uncertainties to
delivery of objectives, not managing issues that might be constant.
Risk evaluation - The probability and impact can both be scored, e.g. using a High/
Medium/Low scale. A Risk Profile could be used to show the overall pattern of risk
Risk prioritisation - The urgency and importance of a risk is not the same thing - deal
with the urgent risks quickly, deal with the important risks comprehensively.
Risk management planning - What actions and resources will you need to reduce the
impact and/or probability of the risk happening.How to prevent it from happening -
either by putting some counter-measures in place or putting the project in a position
where it would have no impact
· How to reduce the risk - what action is needed to reduce the probability of the risk
happening and/or to reduce the impact if it does occur
· Can you transfer the risk to a third party (e.g. take out insurance) or share it in
some way (shared risk-shared gain)?
· What to do to if the risk does occur - do you need a contingency plan?
· What are the implications of accepting the risk - ensuring that all the stakeholders
are aware of the possible consequences?
Planning and resourcing - actions should be built in to the project's plans. If it has been
decided to accept a particular risk without action you may need to inform key stakeholders.
Risk monitoring - Individual risks, and the project's overall exposure to risk, must be
reviewed throughout the life of a project and where necessary actions to mitigate risks
must be changed or revisions to the project business case or assumptions must be
considered, if circumstances alter.
Categories for Status include:
· Open: risk identified but no actions agreed.
· Actioned: actions have been agreed and responsibility allocated.
· Closed: risk no longer is a threat to this project.
· Increasing: the likelihood and/or impact have increased since the last review of
risk.
· Decreasing: the likelihood and/or impact have decreased since the last review of
risk.
· Issue: the risk has become reality and is now an issue for direct management.
Creating the right environment for project control
The basic requirements for control isa plan that is:
· realistic
· credible
· detailed enough to be executed
· acceptable to those who must execute it (Project Manager and Project Teams)
· approved by those who are accountable for its achievement (the SRO/ Project
Board);

Handling Issues, Problems and Changes


In all projects issues will arise that may deflect the project from its intended path. In all
projects a straightforward communication mechanism is needed so that anyone associated
with the project can communicate to the Project Manager an issue they think might
require management attention e.g.:
· Changes to requirements (e.g. Requests to change to the scope, objectives,
target dates or detailed deliverables of the project).
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-493
· Faults/errors (e.g. notification that one or more delivered products that have
been signed-off after quality control are subsequently found not to meet
specification).
· Problems (e.g. a key stakeholder/agency failing to meet commitments).
· Risks that has become reality. (e.g. supplier failure, industrial action)
· Loss of key skills (resignation, promotion, transfer, sickness).
· Concerns about the project and/or its deliverables (e.g. concerns about the ability
to achieve the required benefits).
· Questions (e.g. about how the delivered products will be implemented).
Software Estimation
Estimation techniques
Organizations need to make software effort and cost estimates. There are two types of
technique that can be used to do this: Cost is estimated as a mathematical function of
product, project and process attributes whose
values are estimated by project managers:
· Effort = A ‘SizeB’ M
· A is an organisation-dependent constant, B reflects the disproportionate effort
for large projects and M is a multiplier reflecting product, process and people
attributes.
The most commonly used product attribute for cost estimation is code size.Most models
are similar but they use different values for A, B and M.
The COCOMO 2 model
Long history from initial version published in 1981 (COCOMO-81) through various
instantiations to COCOMO 2.COCOMO 2 takes into account different approaches to
software development, reuse, etc.
COCOMO estimation models
Project Formula Description
complexity
Simple PM = 2.4 (KDSI)1.05 ´ M Well-understood applications
developed by small teams.
Moderate PM = 3.0 (KDSI)1.12 ´ M More complex projects where
team members may have limited
experience of related systems.
Embedded PM = 3.6 (KDSI)1.20 ´ M Complex projects where the
software is part of a strongly
coupled complex of hardware,
software, regulations and
operational procedures.

Application composition model


Based on standard estimates of developer productivity in application (object) points/
month.
Formula is
· PM = ( NAP ´ (1 - %reuse/100 ) ) / PROD
· PM is the effort in person-months, NAP is the number of application points
and PROD is the productivity.
Application-point productivity
Based on a standard formula for algorithmic models
· PM = A ´ SizeB ´ M where
· M = PERS ´ RCPX ´ RUSE ´ PDIF ´ PREX ´ FCIL ´ SCED;
· A = 2.94 in initial calibration, Size in KLOC, B varies from 1.1 to 1.24 depending
on novelty of the project, development flexibility, risk management
approaches and the process maturity.
EBD_7203
S3-494 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Multipliers reflect the capability of the developers, the non-functional requirements,
the familiarity with the development platform, etc.
· RCPX - product reliability and complexity;
· RUSE - the reuse required;
· PDIF - platform difficulty;
· PREX - personnel experience;
· PERS - personnel capability;
· SCED - required schedule;
· FCIL - the team support facilities.
Reuse model estimates
1. For generated code:
· PM = (ASLOC * AT/100)/ATPROD
· ASLOC is the number of lines of generated code
· AT is the percentage of code automatically generated.
· ATPROD is the productivity of engineers in integrating this code.
2. When code has to be understood and integrated:
· ESLOC = ASLOC * (1-AT/100) * AAM.
· ASLOC and AT as before.
· AAM is the adaptation adjustment multiplier computed from the costs of
changing the reused code, the costs of understanding how to integrate the
code and the costs of reuse decision making.
Post-architecture level
The code size is estimated as:
· Number of lines of new code to be developed;
Scale factors used in the exponent computation in the post-architecture model
Scale factor Explanation
Precedentedness Reflects the previous experience of the organisation with this type
of project. Very low means no previous experience. Extra high
means that the organisation is completely familiar with this
application domain.
Development Reflects the degree of flexibility in the development process. Very
flexibility low means a prescribed process is used; Extra high means that the
client only sets general goals.
Architecture/risk Reflects the extent of risk analysis carried out. Very low means
resolution little analysis, Extra high means a complete a thorough risk analysis.
Team cohesion Reflects how well the development team know each other and
work together. Very low means very difficult interactions. Extra
high means an integrated and effective team with no communication
problems.
Process maturity Reflects the process maturity of the organisation. The computation
of this value depends on the CMM maturity Questionnaire but an
estimate can be achieved by subtracting the CMM process
maturity level from 5.
Multipliers
Product attributes
· Concerned with required characteristics of the software product being
developed.
Computer attributes
· Constraints imposed on the software by the hardware platform.
Personnel attributes
· Multipliers that take the experience and capabilities of the people working
on the project into account.
Project attributes
· Concerned with the particular characteristics of the software development
project.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-495
The effect of cost drivers on effort estimates
Exponent value 1.17
System size (including factors for reuse and 128,000 DSI
requirements volatility)
Initial COCOMO estimate without cost drivers 730 person-months
Reliability Very high, multiplier = 1.39
Complexity Very high, multiplier = 1.3
Memory constraint High, multiplier = 1.21
Tool use Low, multiplier = 1.12
Schedule Accelerated, multiplier = 1.29
Adjusted COCOMO estimate 2,306 person-months
The effect of cost drivers on effort estimates
Exponent value 1.17
Reliability Very low, multiplier = 0.75
Complexity Very low, multiplier = 0.75
Memory constraint None, multiplier = 1
Tool use Very high, multiplier = 0.72
Schedule Normal, multiplier = 1
Adjusted COCOMO estimate 295 person-months
Project duration and staffing
Calendar time can be estimated using a COCOMO 2 formula
, *
· TDEV = 3 (PM)(0.33 + 0.2 (B-1.01))
PM is the effort computation and B is the exponent computed as discussed above (B is
1 for the early prototyping model). This computation predicts the nominal schedule for
the project.The time required is independent of the number of people working on the
project.
SDLC - CODING, TESTING, IMPLEMENTATION,
MAINTENANCE P HA SES
Coding Phase
The document contains all the details for a programmer to convert it into a working program.
Designed in the right way, the job of the developer is to convert the pseudo code into a
programming language in the specified platform. The developer will be given specific
guidelines that tell how to code. These guideline includes the naming convention of
procedures, variables, commenting methods etc. As per the guidelines, the developer
codes and at the end of the coding, he/she compiles the program unit.
By compiling and correcting the errors, all syntax error are removed. Syntax errors are the
easy ones to rectify. The logical errors in the programs are the difficult ones to identify and
then rectify. By logical error, we mean, the program behaves in a way, that it is not expected
to behave. The role of testers is to identify the logical errors at various stages.
Systems Development Life Cycle (SDLC) adheres to important phases that are essential
for developers, such as planning, analysis, design, and implementation, and are explained
in the section below. A number of system development life cycle (SDLC) models have
been created: waterfall, fountain, spiral, build and fix, rapid prototyping, incremental, and
synchronize and stabilize.
1. Project planning, feasibility study: Establishes a high-level view of the intended
project and determines its goals.
2. Systems analysis, requirements definition: Refines project goals into defined
functions and operation of the intended application. Analyzes end-user
information needs.
3. Systems design: Describes desired features and operations in detail, including
screen layouts, business rules, process diagrams, pseudocode and other
documentation.
· Implementation: The real code is written here.
· Integration and testing: Brings all the pieces together into a special testing
environment, then checks for errors, bugs and interoperability.
EBD_7203
S3-496 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
· Acceptance, installation, deployment: The final stage of initial development,
where the software is put into production and runs actual business.
· Maintenance: What happens during the rest of the software's life: changes,
correction, additions, moves to a different computing platform and more.
This, the least glamorous and perhaps most important step of all, goes on
seemingly forever.
System analysis
Requirements analysis sometimes requires individuals/teams from client as well as service
provider sides to get detailed and accurate requirements; often there has to be a lot of
communication to and from to understand these requirements. Requirement gathering is
the most crucial aspect as many times communication gaps arise in this phase and this
leads to validation errors and bugs in the software program.
Design
In systems design the design functions and operations are described in detail, including
screen layouts, business rules, process diagrams and other documentation. The output
of this stage will describe the new system as a collection of modules or subsystems.The
design stage takes its initial input the requirements identified in the approved requirements
document. For each requirement, a set of one or more design elements will be produced
as a result of interviews, workshops, and/or prototype efforts.Design elements describe
the desired software features in detail, and generally include functional hierarchy
diagrams, screen layout diagrams, tables of business rules, business process diagrams,
pseudocode, and a complete entity-relationship diagram with a full data dictionary. These
design elements are intended to describe the software in sufficient detail that skilled
programmers may develop the software with minimal additional input design.
Implementation
Modular and subsystem programming code will be accomplished during this stage. Unit
testing and module testing are done in this stage by the developers. This stage is
intermingled with the next in that individual modules will need testing before integration
to the main project.
Testing
The code is tested at various levels in software testing. Unit, system and user acceptance
testings are often performed. This is a grey area as many different opinions exist as to
what the stages of testing are and how much if any iteration occurs. Iteration is not
generally part of the waterfall model, but usually some occur at this stage. In the testing
the whole system is test one by one
Following are the types of testing:
· Path testing
· Data set testing
· Unit testing
· System testing
· Integration testing
· Black box testing
· White box testing
· Regression testing
· User acceptance testing
· Performance testing
Operations and maintenance
The deployment of the system includes changes and enhancements before the
decommissioning or sunset of the system. Maintaining the system is an important aspect
of SDLC.
INFORMATION SYSTEM AND SOFTWARE ENGINEERING S3-497
Systems Analysis and Design
The Systems Analysis and Design (SAD) is the process of developing Information
Systems (IS) that effectively use of hardware, software, data, process, and people to
support the company’s business objectives.
Activities & Deliverables of SDLC

Investigation Prob. def. Estimate project sope Preliminary Feasibility Report


Estimate project feasibility, General Problem Statement
Estimate resource commitment.
Go/no decision
Analysis Create logical models DFD – current system
Refine problem statement ERD – current system
Determine requirements for new Formal prob. Statement
system Formal Reqs Definition
Logical Design Revise current system logical DFD – proposed system
models to reflect proposed ERD – proposed system
changes Final performance spec.
Validate logical model of
proposed system against reqs
Physical Design determination
HW spec. SW spec. cost HW spec., SW spec., Final
justification, implementation
Feasibility Report, Physical Data
schedule, design data structure,
training guide, testing procedures Structure & data dictionary.
decided Implementation schedule
Implementation Build the system Fully installed system, fully
Cutover covered data files, fully trained
users, fully performance test
Maintenance Review Fully functioning system
Makes requested changes
Monitor performance

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

PAST GATE QUESTIONS EXERCISE Control coupling


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

3. Software Development Life Cycle (SDLC)


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

Development Step VII


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

Initiation Step II
Step I

The answer of the match of the following can be obtained 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

Program Flow Graph (Control Flow Diagram) region

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

115. Availability = [MTTF/MTTF + MTTR] é MTTF2 ù


A2 = ê ú ´ 100 Þ 95
MTBF = 25 days ë MTTF2 + MTTR 2 û
MTTR = 6 hours = 6/24 days
MTBF × MTTF = MTTR MTTF2
= ´ 100
MTTF2 + 25
1
MTTF = 25 - = 99/4 days After calculation
4
MTTF = Mean time to failure Þ \ MTTF2 = 475
MTBF2 = MTTF2 + MTTR2
é 99 ù = 475 + 20
ê 4 ú = 500 days
Availability = ê 1ú 117. 0.95
ê 99 / 4 + ú
ë 4û
10
F(1) = = 0.05
200
99 44
= ´ = 99% R(1) = 1 – 0.05 = 0.95
4 100
(Here, we are calculating reliability cost test cases instead
Availability = 99%
of days)
116. 500
R(1) Þ Not failing for one test case.
Case I
118. 6.25
Availability A1 = 90%
Doubling the developing time reduces the project effort by
Mean Time Between Failure
a factor of 2 = 16. The project effort by a factor of 2 4 = 16 so
MTBF1 = 200 days
the project effort will be 100/16 = 6.25 PM.
Mean TIme. To Repair (MTTR1) = X
10
Page - 515 - 568

COMPUTER NETWORKS

C Ø ISO/OSI Network Model

O Ø

Ø
LAN technologies (Ethernet, Token ring)

Flow and error control techniques

N Ø Routing Algorithms

T Ø

Ø
Congestion Control

TCP/UDP and sockets, IP(v4), Application layer protocols (icmp, dns,

E Ø
smtp, pop, ftp, http)

Basic concepts of hubs, switches, gateways, and routers

N Ø Network security - basic concepts of public key and private key


cryptography, digital signature, firewalls

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

Transport Transport protocol Transport TPDU


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

2 Data link Data link Data link Data link Frame

1 Physical Physical Physical Physical Bit


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

Layer 1 – Physical - Physical layer defines the cable or 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

LA N TECH NOLOG IES (ETHERNET, TOKEN interchangeably.


R I NG ) A standard for a 1-persistent CSMA/CD LAN.
IEEE 802.3 and Ethernet It covers the physical layer and MAC sublayer protocol.
Very popular LAN standard. Ethernet Physical Layer
Ethernet and IEEE 802.3 are distinct standards but as they A Comparison of Various Ethernet and IEEE 802.3 Physical-
are very similar to one another these words are used Layer Specifications
Characteristic Ethernet Value IEEE 802.3 Values
10Base5 10Base2 10BaseT 10BaseF 10BaseTX 100BaseT4
Data rate (Mbps) 10 10 10 10 10 10 100
Signaling method Baseband Baseband Baseband Baseband Baseband Baseband Baseband
Maximum 500 500 185 100 2,000 100 100
segment length (m)
Media 50-ohm coax 50-ohm coax 50-ohm coax Unshielded Fiber-optic Cat 5 UTP Unshielded
(thick) (thick) (thin) twisted-pair cable twisted-pair cable
Nodes/segment 100 100 30 1024 1024
Topology Bus Bus Bus Star Point-to-point Bus Bus
EBD_7203
S3-518 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
All 802.3 baseband systems use Manchester encoding , which is a way for receivers to unambiguously determine the start, end
or middle of each bit without reference to an external clock. There is a restriction on the minimum node spacing (segment length
between two nodes) in 10Base5 and 10Base2 and that is 2.5 meter and 0.5 meter respectively. The reason is that if two nodes
are closer than the specified limit then there will be very high current which may cause trouble in detection of signal at the receiver
end. Connections from station to cable of 10Base5 (i.e. Thick Ethernet) are generally made using vampire taps and to 10Base2
(i.e. Thin Ethernet) are made using industry standard BNC connectors to form T junctions. To allow larger networks, multiple
segments can be connected by repeaters as shown. A repeater is a physical layer device. It receives, amplifies and retransmits
signals in either direction.
IEEE 802.3 Frame Structure

Preamble Start of Frame Delimiter Dest. Address Source Address Length 802.2 Header + Data Frame Checksum
(7 bytes) (1 byte) (2/6 bytes) (2/6 bytes) (2 bytes) (46-1500 bytes) (4 bytes)

Preamble :Each frame starts with a preamble of 7 bytes, each byte containing the bit pattern 10101010. Manchester encoding
is employed here and this enables the receiver’s clock to synchronize with the sender’s and initialise itself.
Start of Frame Delimiter :This field containing a byte sequence 10101011 denotes the start of the frame itself.
Dest. Address :The standard allows 2-byte and 6-byte addresses. Note that the 2-byte addresses are always local addresses
while the 6-byte ones can be local or global.

2-Byte Address - Manually assigned address


Individual(0)/Group(1) Address of the machine
(1 bit) (15 bits)

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

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


(1 bit) (1 bit) (46 bits)

Multicast : Sending to group of stations. This is ensured by setting the first bit in either 2-byte/6-byte addresses to 1
Broadcast : Sending to all stations. This can be done by setting all bits in the address field to 1.All Ethernet cards(Nodes)
are a member of this group.
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

Preamble Dest. Address Source Address Type Data Frame Checksum


(8 bytes) (2/6 bytes) (2/6 bytes) (2 bytes) (46-1500 bytes) (4 bytes)
COMPUTER NETWORKS S3-519
A brief description of the fields which differ from IEEE Whenever a station wants to transmit a frame it inverts a
802.3 single bit of the 3-byte token which instantaneously
Preamble :The Preamble and Start of Frame Delimiter changes it into a normal data packet. Because there is
are merged into one in Ethernet standard. However, the only one token, there can atmost be one transmission at
contents of the first 8 bytes remain the same in both. a time.
Type :The length field of IEEE 802.3 is replaced by Type Since the token rotates in the ring it is guarenteed that
field, which denotes the type of packet being sent viz. IP, every node gets the token with in some specified time. So
ARP, RARP, etc. If the field indicates a value less than there is an upper bound on the time of waiting to grab the
1500 bytes then it is length field of 802.3 else it is the type token so that starvation is avoided.
field of Ethernet packet. There is also an upper limit of 250 on the number of nodes
Truncated Binary Exponential Back off in the network.
In case of collision the node transmitting backs off by a random To distinguish the normal data packets from token
number of slots , each slot time being equal to transmission time (control packet) a special sequence is assigned to the
of 512 bits (64 Byte- minimum size of a packet) in the following token packet. When any node gets the token it first sends
fashion: the data it wants to send, then recirculates the token.
No of Collision Random No of slots
1st 0-1
2nd 0-3
3rd 0-7
| |
| |
10th 0-1023
———————————————————
11th 0-1023 Token
12th 0-1023
| | If a node transmits the token and nobody wants to send the
16th 0-1023 data the token comes back to the sender. If the first bit of the
In general after i collisions a random number between 0-2^i-1 is token reaches the sender before the transmission of the last bit,
chosen , and that number of slots is skipped. However, after 10 then error situation arises. So to avoid this we should have:
collisions have been reached the randomization interval is propogation delay + transmission of n-bits (1-bit delay in each
frozen at maximum of 1023 slots. After 16 collisions the node ) > transmission of the token time
controller reports failure back to the computer. A station may hold the token for the token-holding time. which
is 10 ms unless the installation sets a different value. If there
IEEE 802.5: Token Ring Network
is enough time left after the first frame has been transmitted to
Token Ring is formed by the nodes connected in ring
send more frames, then these frames may be sent as well. After
format as shown in the diagram below. The principle used
all pending frames have been transmitted or the transmission
in the token ring network is that a token is circulating in
frame would exceed the token-holding time, the station
the ring and whichever node grabs that token will have
regenerates the 3-byte token frame and puts it back on the ring.
right to transmit the data.
Token Ring Using Ring Concentrator
1 2 3 4 5
One problem with a ring network is that if the cable breaks
somewhere, the ring dies. This problem is elegantly
addressed by using a ring concentrator. A Token Ring
concentrator simply changes the topology from a physical
ring to a star wired ring. But the network still remains a ring
logically. Physically, each station is connected to the ring
concentrator (wire center) by a cable containing at least
two twisted pairs, one for data to the station and one for
data from the station. The Token still circulates around the
network and is still controlled in the same manner, however,
using a hub or a switch greatly improves reliability because the hub can automatically bypass any ports that are disconnected or have
a cabling fault.This is done by having bypass relays inside the concentrator that are energized by current from the stations. If the ring
breaks or station goes down, loss of the drive current will release the relay and bypass the station. The ring can then continue
operation with the bad segment bypassed.
EBD_7203
S3-520 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Who should remove the packet from the ring ? This bit shall be transmitted as 0 in all frame and tokens. The
There are 3 possibilities- active monitor inspects and modifies this bit. All other stations
1. The source itself removes the packet after one full round shall repeat this bit as received.
in the ring. R = Reserved bits
2. The destination removes it after accepting it: This has The reserved bits allow station with high priority Frames to request
two potential problems. Firstly, the solution won’t work that the next token be issued at the requested priority.
for broadcast or multicast, and secondly, there would be Ending Delimiter Format:
no way to acknowledge the sender about the receipt of
the packet. J K I J K I I E
3. Have a specialized node only to discard packets: This is
a bad solution as the specialized node would know that J = Code Violation
the packet has been received by the destination only K = Code Violation
when it receives the packet the second time and by that I = Intermediate Frame Bit
time the packet may have actually made about one and E = Error Detected Bit
half (or almost two in the worst case) rounds in the ring. Frame Format:
Thus the first solution is adopted with the source itself MSB (Most Significant Bit) is always transmitted first - as
removing the packet from the ring after one full round. With this opposed to Ethernet
scheme, broadcasting and multicasting can be handled as well
as the destination can acknowledge the source about the SD AC FC DA SA DATA CRC ED FS
receipt of the packet (or can tell the source about some error).
SD=Starting Delimiter(1 octet)
Token Format AC=Access Control(1 octet)
The token is the shortest frame transmitted (24 bit) MSB (Most FC = Frame Control (1 Octet)
Significant Bit) is always transmitted first - as opposed to DA = Destination Address (2 or 6 Octets)
Ethernet SA = Source Address (2 or 6 Octets)
DATA = Information 0 or more octets up to 4027
SD AC ED
CRC = Checksum(4 Octets)
SD = Starting Delimiter (1 Octet) ED = Ending Delimiter (1 Octet)
AC = Access Control (1 Octet) FS=Frame Status
ED = Ending Delimiter (1 Octet) Starting Delimiter Format:
Starting Delimiter Format:
J K 0 J K 0 0 0
J K O J K O O O
J = Code Violation
J = Code Violation K = Code Violation
K = Code Violation Access Control Format:
Access Control Format:
P P P T M R R R
P P P T M R R R
T=Token
T=Token T = “0” for Token,
T = 0 for Token T = “1” for Frame.
T = 1 for Frame When a station with a Frame to transmit detects a token which
When a station with a Frame to transmit detects a token which has a priority equal to or less than the Frame to be transmitted,
has a priority equal to or less than the Frame to be transmitted, it may change the token to a start-of-frame sequence and
it may change the token to a start-of-frame sequence and transmit the Frame.
transmit the Frame P = Priority
P = Priority Bits Priority Bits indicate tokens priority, and therefore, which
Priority Bits indicate tokens priority, and therefore, which stations are allowed to use it. Station can transmit if its priority
stations are allowed to use it. Station can transmit if its priority is atleast as high as that of token.
as at least as high as that of the token. M = Monitor
M = Monitor The monitor bit is used to prevent a token whose priority is
The monitor bit is used to prevent a token whose priority is greater than 0 or any frame from continuously circulating on the
greater than 0 or any frame from continuously circulating on the ring. if an active monitor detects a frame or a high priority token
ring. If an active monitor detects a frame or a high priority token with the monitor bit equal to 1, the frame or token is aborted.
with the monitor bit equal to 1, the frame or token is aborted. This bit shall be transmitted as 0 in all frame and tokens. The
COMPUTER NETWORKS S3-521
active monitor inspects and modifies this bit. All other stations acknowledgment, which takes a similar amount of
shall repeat this bit as received. propagation time to get back to the sender. The advantage
R = Reserved bits the reserved bits allow station with high is simplicity.
priority Frames to request that the next token be issued at the
Stop and wait
requested priority
Frame Control Format:

F F CONTROL BITS (6 BITS)

FF= Type of Packet-Regular data packet or MAC layer packet


Control Bits= Used if the packet is for MAC layer protocol itself
Data Format:
No upper limit on amount of data as such, but it is limited by
the token holding time.
Checksum:
The source computes and sets this value. Destination too
calculates this value. If the two are different, it indicates an
error, otherwise the data may be correct.
Frame Status:
It contains the A and C bits.
A bit set to 1: destination recognized the packet. In the above diagram
C bit set to 1: destination accepted the packet. Sender keeps a copy of the last frame until it receives an
This arrangement provides an automatic acknowledgement for acknowledgement.For identification, both data frames and
each frame. The A and C bits are present twice in the Frame acknowledgements (ACK) frames are numbered
Status to increase reliability in as much as they are not covered alternatively 0 and 1.Sender has a control variable (S) that
by the checksum. holds the number of the recently sent frame. (0 or
1).Receiver has a control variable ® that holds the number
Ending Delimiter Format: of the next frame expected (0 or 1).Sender starts a timer
when it sends a frame. If an ACK is not received within
J K 1 J K 1 I E
a allocated time period, the sender assumes that the frame
J = Code Violation was lost or damaged and resends it.Receiver send only
K = Code Violation positive ACK if the frame is intact.ACK number always
I = Intermediate Frame Bit defines the number of the next expected frame.
If this bit is set to 1, it indicates that this packet is an
intermediate part of a bigger packet, the last packet would have
this bit set to 0.
E = Error Detected Bit
This bit is set if any interface detects an error.
FLOW AND ERROR CONTROL
FLOW CONTROL
Flow control tells the sender how much data to send. It makes
the sender wait for some sort
of an acknowledgment (ACK) before continuing to send more
data.
There are two primary methods of fow control: Stop-and-wait,
and Sliding Window.
Stop And Wait
When a receiver receives a damaged frame, it discards it
Stop And Wait is a simple scheme, where the sender has
and keeps its value of R.After the timer at the sender
to wait for an acknowledgment of every frame that it
expires, another copy of frame 1 is sent. If the sender
sends. It sends a frame, waits for acknowledgment, then
receives a damaged ACK, it discards it.When the timer of
it sends another frame, and again, waits for
the sender expires, the sender retransmits frame Receiver
acknowledgment.
has already received frame 1 and expecting to receive
The trouble with this scheme is that it’s very slow. For
frame 0 (R=0). Therefore it discards the second copy of
every frame that is sent, there needs to be an
frame1.
EBD_7203
S3-522 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Stop-and-Wait, delayed ACK frame 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, …
Sender Sliding Window
At the sending site, to hold the outstanding frames until
they are acknowledged, we use the concept of a
window.The size of the window is at most 2m -1 where m
is the number of bits for the sequence number.Size of the
window can be variable, e.g. TCP.The window slides to
include new unsent frames when the correct ACKs are
received.

The ACK can be delayed at the receiver or due to some


problem.It is received after the timer for frame 0 has
expired.Sender retransmitted a copy of frame 0. However, Receiver Sliding Window
R =1 means receiver expects to see frame 1. Receiver Size of the window at the receiving site is always 1 in this
discards the duplicate frame 0.Sender receives 2 ACKs, it protocol.Receiver is always looking for a specific frame to
discards the second ACK. arrive in a specific order.Any frame arriving out of order
Piggybacking is discarded and needs to be resent.Receiver window
slides as shown in fig. Receiver is waiting for frame 0 in
part a.

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.

Go-Back-N ARQ, lost frame

Frames 0 and 1 are accepted when received because they are


in the range specified by the receiver window. Same for frame
3.Receiver sends a NAK2 to show that frame 2 has not been
received and then sender resends only frame 2 and it is
accepted as it is in the range of the window
Selective Repeat ARQ, sender window size
Size of the sender and receiver windows must be at most one-
half of 2m. If m = 2, window size should be 2m /2 = 2. Fig
compares a window size of 2 with a window size of 3. Window
size is 3 and all ACKs are lost, sender sends duplicate of frame
0, window of the receiver expect to receive frame 0 (part of the
window), so accepts frame 0, as the 1st frame of the next cycle
Frame 2 is lost.When the receiver receives frame 3, it discards - an error.
frame 3 as it is expecting frame 2 (according to window).After Sliding Window
the timer for frame 2 expires at the sender site, the sender sends The whole idea behind Sliding Window is not to wait for
frame 2 and 3. (go back to 2) an acknowledgment for individual frames, but to send a
Go-Back-N ARQ, damaged/lost/delayed ACK few frames (and then get an acknowledgment that
If an ACK is damaged/lost, we can have two situations.If the acknowledges several frames at the same time).
next ACK arrives before the expiration of any timer, there is no It works by having the sender and receiver have a
need for retransmission of frames because ACKs are cumulative “window” of frames. The sender can send as many frames
in this protocol. as would fit into a window. The receiver, upon receiving
Go-Back-N ARQ, sender window size enough frames, will respond with an acknowledgment of
Size of the sender window must be less than 2m. Size of the all frames up to a certain point in the window. The window
receiver is always 1. If m = 2, window size = 2m - 1 = 3. it then said to “slide”, and the whole thing starts again
(the sender sends more frames, the receiver gets more
EBD_7203
S3-524 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
frames, sends an acknowledgment of those frames, etc.) • Selective reject
Each frame has to be numbered in relation to the sliding Selective reject allows the sender to reject any
window. For a window of size N, frames get a number from particular frame, without having the sender resend all
0 to N - 1. Subsequent frames get a number mod N. the following frames. For example, the sender may
send frames 1,2,3,4 and the receiver may send a NAK
ERROR CONTROL
with value of 2. At which point, the sender retransmits
To ensure reliable communication, there needs to exist flow frame 2. If frames 3,4 were received without any
control (managing the amount of data the sender sends), and problems, then the receiver acknowledges them with
error control (that data arrives at the destination error free). a ACK 4 (note that ACK now points to the last
Flow and error control needs to be done at several layers. For successful frame, as opposed to the next expected
node-to-node links, flow and error control is carried out in the frame). In order to support Selective reject, the
data-link layer. For end-point to end-point, flow and error sender needs to maintain all data that hasn’t been
control is carried out in the transport layer. Error control acknowledged yet. The receiver also needs to have
involves retransmission of the lost, damaged, or corrupted sorting (rearranging) logic to be able to re-order
frame. The scheme is called ARQ, for Automatic Repeat frames that may have arrived out of sequence (or
Request. some frames that were damaged and retransmitted
The general scheme works this way: the sender sends the data. out of sequence). The sender needs to be able to
If data arrives without any problems, the receiver sends out an find any particular frame for retransmission.
ACK message (acknowledgment). If the data has a problem
(corrupt), the receiver sends out an NAK (negative ROUTI NG ALGORITHMS
acknowledgment). Upon getting a NAK message, the sender Routing is the process of forwarding of a packet in a network
retransmits. There is also a timer; which allows for data so that it reaches its intended destination. The main goals of
retransmission if the original message or ACK or NAK got lost. routing are:
There are several forms: Stop-and-Wait ARQ, and Sliding
1. Correctness: The routing should be done properly and
Window ARQ.
Stop-and-Wait ARQ correctly so that the packets may reach their proper
Each frame has an alternating bit (0 or 1). The sender destination.
sends out the message, and starts the timeout counter. If 2. Simplicity: The routing should be done in a simple
the receiver gets the message without any problems, it manner so that the overhead is as low as possible. With
sounds out an ACK message, otherwise it sends out a increasing complexity of the routing algorithms the
NAK message. overhead also increases.
If the sender gets an NAK message, it retransmits the 3. Robustness: Once a major network becomes operative, it
sent message.
may be expected to run continuously for years without
If the timer expires (and no NAK nor ACK arrived) then
the sender retransmits the frame. If it happened that the any failures. The algorithms designed for routing should
message was received ?ne, but the ACK got lost, then the be robust enough to handle hardware and software
even/odd bit in the data frame will alert the receiver to the failures and should be able to cope with changes in the
duplicate frame. topology and traffic without requiring all jobs in all hosts
Sliding Window ARQ to be aborted and the network rebooted every time some
There are two categories of Sliding Window ARQ: Go- router goes down.
back-n, and Selective reject. Both of these schemes keep 4. Stability: The routing algorithms should be stable under
a copy of all the sent frames until they have been
all possible circumstances.
acknowledged. The receiver has the option of responding
with a ACK (acknowledgment) or NAK (negative 5. Fairness: Every node connected to the network should
acknowledgment). Each frame needs to be numbered. The get a fair chance of transmitting their packets. This is
ACK indicates the next expected frame number, while a generally done on a first come first serve basis.
NAK identi?es the broken frame that needs to be resent. 6. Optimality: The routing algorithms should be optimal in
There is also a timer, in case the sender doesn’t hear an terms of throughput and minimizing mean packet delays.
ACK or NAK, the sender will resend the data from the last Here there is a trade-off and one has to choose depending
time it got an ACK or a NAK. on his suitability.
• Go-back-n
In the Go-back-n scheme, upon an error, the sender Classification of Routing Algorithms
retransmits all the frames that came after the error. The routing algorithms may be classified as follows:
For example, sender may send frames 1,2,3,4 and get 1. Adaptive Routing Algorithm: These algorithms change
an NAK with a value of 2. The NAK acknowledges their routing decisions to reflect changes in the topology
everything that came before it, and asks for frame 2
and in traffic as well. These get their routing information
(and subsequent frames) to be resent.
COMPUTER NETWORKS S3-525
from adjacent routers or from all routers. The optimization 2. Non-Adaptive Routing Algorithm: These algorithms do
parameters are the distance, number of hops and estimated not base their routing decisions on measurements and
transit time. This can be further classified as follows: estimates of the current traffic and topology. Instead the
1. Centralized: In this type some central node in the route to be taken in going from one node to the other is
network gets entire information about the network computed in advance, off-line, and downloaded to the
topology, about the traffic and about other nodes. routers when the network is booted. This is also known
This then transmits this information to the respective as static routing. This can be further classified as:
routers. The advantage of this is that only one node 1. Flooding: Flooding adapts the technique in which
is required to keep the information. The disadvantage every incoming packet is sent on every outgoing line
is that if the central node goes down the entire except the one on which it arrived. One problem with
network is down, i.e. single point of failure. this method is that packets may go in a loop. As a
2. Isolated: In this method the node decides the routing result of this a node may receive several copies of a
without seeking information from other nodes. The particular packet which is undesirable. Some
sending node does not know about the status of a techniques adapted to overcome these problems are
particular link. The disadvantage is that the packet as follows:
may be send through a congested route resulting in • Sequence Numbers: Every packet is given a
a delay. Some examples of this type of algorithm for
sequence number. When a node receives the
routing are:
packet it sees its source address and sequence
• Hot Potato: When a packet comes to a node, it
number. If the node finds that it has sent the
tries to get rid of it as fast as it can, by putting
same packet earlier then it will not transmit the
it on the shortest output queue without regard
packet and will just discard it.
to where that link leads. A variation of this
• Hop Count: Every packet has a hop count
algorithm is to combine static routing with the
associated with it. This is decremented(or
hot potato algorithm. When a packet arrives,
incremented) by one by each node which sees
the routing algorithm takes into account both
the static weights of the links and the queue it. When the hop count becomes zero(or a
lengths. maximum possible value) the packet is dropped.
• Backward Learning: In this method the routing • Spanning Tree: The packet is sent only on
tables at each node gets modified by information those links that lead to the destination by
from the incoming packets. One way to implement constructing a spanning tree routed at the
backward learning is to include the identity of source. This avoids loops in transmission but is
the source node in each packet, together with a possible only when all the intermediate nodes
hop counter that is incremented on each hop. have knowledge of the network topology.
When a node receives a packet in a particular Flooding is not practical for general kinds of
line, it notes down the number of hops it has applications. But in cases where high degree of
taken to reach it from the source node. If the robustness is desired such as in military
previous value of hop count stored in the node applications, flooding is of great help.
is better than the current one then nothing is 2. Random Walk: In this method a packet is sent by the
done but if the current value is better then the node to one of its neighbours randomly. This
value is updated for future use. The problem algorithm is highly robust. When the network is
with this is that when the best route goes down highly interconnected, this algorithm has the property
then it cannot recall the second best route to a of making excellent use of alternative routes. It is
particular node. Hence all the nodes have to usually implemented by sending the packet onto the
forget the stored informations periodically and least queued link.
start all over again.
3. Distributed: In this the node receives information
Delta Routing
from its neighbouring nodes and then takes the Delta routing is a hybrid of the centralized and isolated routing
decision about which way to send the packet. The algorithms. Here each node computes the cost of each line (i.e
disadvantage is that if in between the the interval it some functions of the delay, queue length, utilization, bandwidth
receives information and sends the paket something etc) and periodically sends a packet to the central node giving
changes then the packet may be delayed. it these values which then computes the k best paths from
node i to node j. Let Cij1 be the cost of the best i-j path, Cij2
EBD_7203
S3-526 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
the cost of the next best path and so on.If Cijn - Cij1 < delta, Every node keeps information about every other node in
(Cijn - cost of n’th best i-j path, delta is some constant) then the network
path n is regarded equivalent to the best i-j path since their In case of adaptive routing, the routing calculations are
cost differ by so little. When delta -> 0 this algorithm becomes done and updated for all the nodes.
centralized routing and when delta -> infinity all the paths The above two are also the disadvantages of non-hierarchical
become equivalent. routing, since the table sizes and the routing calculations
Multipath Routing become too large as the networks get bigger. So this type of
In the above algorithms it has been assumed that there is a routing is feasible only for small networks.
single best path between any pair of nodes and that all traffic Source Routing
between them should use it. In many networks however there Source routing is similar in concept to virtual circuit routing. It
are several paths between pairs of nodes that are almost equally is implemented as under:
good. Sometimes in order to improve the performance multiple Initially, a path between nodes wishing to communicate is
paths between single pair of nodes are used. This technique is found out, either by flooding or by any other suitable
called multipath routing or bifurcated routing. In this each node method.
maintains a table with one row for each possible destination This route is then specified in the header of each packet
node. A row gives the best, second best, third best, etc routed between these two nodes. A route may also be
outgoing line for that destination, together with a relative specified partially, or in terms of some intermediate hops.
weight. Before forwarding a packet, the node generates a
Policy Based Routing
random number and then chooses among the alternatives,
In this type of routing, certain restrictions are put on the type
using the weights as probabilities. The tables are worked out
of packets accepted and sent. e.g.. The IIT- K router may decide
manually and loaded into the nodes before the network is
brought up and not changed thereafter. to handle traffic pertaining to its departments only, and reject
packets from other routes. This kind of routing is used for links
Hierarchical Routing with very low capacity or for security purposes.
This is essentially a ‘Divide and Conquer’ strategy. The
network is divided into different regions and a router for a Shortest Path Routing
particular region knows only about its own domain and other A network is represented as a graph, with its terminals as nodes
routers. Thus, the network is viewed at two levels: and the links as edges. A ‘length’ is associated with each edge,
1. The Sub-network level, where each node in a region has which represents the cost of using the link for transmission.
information about its peers in the same region and about Lower the cost, more suitable is the link. The cost is determined
the region’s interface with other regions. Different regions depending upon the criteria to be optimized. Some of the
may have different ‘local’ routing algorithms. Each local important ways of determining the cost are:
algorithm handles the traffic between nodes of the same
Minimum number of hops: If each link is given a unit
region and also directs the outgoing packets to the
cost, the shortest path is the one with minimum number
appropriate interface.
2. The Network Level, where each region is considered as a of hops. Such a route is easily obtained by a breadth first
single node connected to its interface nodes. The routing search method. This is easy to implement but ignores
algorithms at this level handle the routing of packets load, link capacity etc.
between two interface nodes, and is isolated from intra- Transmission and Propagation Delays: If the cost is fixed
regional transfer. as a function of transmission and propagation delays, it
Networks can be organized in hierarchies of many levels; e.g. will reflect the link capacities and the geographical
local networks of a city at one level, the cities of a country at distances. However these costs are essentially static and
a level above it, and finally the network of all nations. do not consider the varying load conditions.
In Hierarchical routing, the interfaces need to store information Queuing Delays: If the cost of a link is determined
about:
through its queuing delays, it takes care of the varying
All nodes in its region which are at one level below it.
load conditions, but not of the propagation delays.
Its peer interfaces.
Ideally, the cost parameter should consider all the above
At least one interface at a level above it, for outgoing
packages. mentioned factors, and it should be updated periodically to
reflect the changes in the loading conditions. However, if the
Non-Hierarchical Routing routes are changed according to the load, the load changes
In this type of routing, interconnected networks are viewed as
again. This feedback effect between routing and load can lead
a single network, where bridges, routers and gateways are just
to undesirable oscillations and sudden swings.
additional nodes.
COMPUTER NETWORKS S3-527

Shortest Path Algorithm


1. Dijktstra’s Algorithm: B 7 C B(2, A) C(¥, –)
At the end each node will be labeled 2 3
2 E 2 F 3 E(¥, –)
with its distance from source node along A D A F(¥, –) D(¥, –)
the best known path. Initially, no paths 1 2
6 4 2
are known, so all nodes are labeled with
infinity. As the algorithm proceeds and G
(a) H G(6, A) (b) H(¥, –)
paths are found, the labels may change
reflecting better paths. Initially, all labels B(2, A) C(9, B) B(2, A) C(9, B)
are tentative. When it is discovered that
a label represents the shortest possible E(4, B) E(4, B)
path from the source to that node, it is A F(¥, –) D(¥, –) A F(6, E) D(¥, 1)
made permanent and never changed
thereafter. G(6, A) H(¥, –) G(5, E) H(¥, –)
(c) (d)
Look at the weighted undirected graph
where the weights represent, for example,
distance. We want to find shortest path B(2, A) C(9, B) B(2, A) C(9, B)
from A to D. We start by making node
E(4, B) E(4, B)
A as permanent, indicated by a filled in A F(6, E) D(¥, –) A F(6, E) D(¥, –)
circle.
Then we examine each of the nodes G(5, E) G(5, E)
H(9, G) H(8, F)
adjacent to A (the working node), (e) (f)
relabeling each one with the distance to
A. Whenever a node is relabeled, we also label it with the information. We do not need to be synchronized i.e. do not
node from which the probe was made so that we can need to exchange information at the same time.
construct the final path later. Having examined each of the Routing algorithms based on Dijkstra’s algorithm are called Link
nodes adjacent to A, we examine all the tentatively labeled State Algorithms. Distance Vector Protocols are based on
nodes in the whole graph and make the one with the distributed Bellman’s algorithm. In the former we are sending
smallest label permanent, This one becomes new working little information to many nodes while in the latter we send huge
node. information to few neighbors.
We now start at B, and examine all nodes adjacent to it. Count-to-Infinity problem:
If the sum of the label on B and the distance from B to
Suppose the link between A and E is down events may occur
the node being considered is less than the label on the
node, we have a shorter path, so the node is relabeled. are:
After all the nodes adjacent to the working node have (1) F tells A that it has a path to E with cost 6
been inspected and the tentative labels changed if (2) A sets cost to E to be 11, and advertise to F again
possible, the entire graph is searched for the tentatively (3) F sets the cost to E to be 16, and advertise to A again
labeled node with the smallest value. This node is made
permanent and becomes the working node for the next
round. B
2. Bellman Ford’s Algorithm:
We look at the distributed version which works on the 3
premise that the information about far away nodes can be
had from the adjoining links. 1 A
The algorithm works as follows. E
• Compute the link costs from the starting node to 5
every directly connected node.
• Select the cheapest links for every node (if there is 7
more than one). F G
• For every directly connected node, compute the link
costs for all these nodes. This cycle will continue and the cost to E goes to infinity. The
• Select the cheapest route for any node. core of the problem is that when X tells Y that it has a path
Repeat until all nodes have been processed. somewhere ,Y has no way to know whether it itself is on the
Every node should have the information about it’s immediate path.
neighbors and over a period of time we will have information During this process of counting to infinity, packets from A or
about other nodes. Within n units of time , where n is the F destined to E are likely to loop back and forth between A and
diameter of the network, every node will have the complete F, causing congestion for other packets.
EBD_7203
S3-528 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
CONGESTION CONTROL For example: Retransmission policy at data link layer affects
Problem: When too many packets are transmitted through a congestion: A jumpy sender that times out quickly and
network, congestion occurs. retransmits all the outstanding frames using go back n will put
At very high traffic, performance collapses completely, and a heavy load on the system than a leisurely sender that uses
almost no packets are delivered. selective repeat
Congestion prevention tries to design these policies
Perfect
carefully to minimise congestion in the first place
Maximum carrying Traffic shaping: As burstiness of traffic is a main cause
capacity of subnet of congestion, it is used to regulate average rate and
Packets delivered

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

Congestion Control in Virtual Circuits


Choke Choke
These are closed-loop based designed for virtual circuits Reduced
flow
subnets, which are connection oriented ® during
connection set up, something can be done to help
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

signaled, no more new virtual circuits can be set up


until the problem has gone away. This is crude but
simple and easy to do Flow is still
at maximum rate
• Select alternative routes to avoid part of the
network that is overloaded, i.e. temporarily rebuild
your view of network Flow is
reduced
(a) (b)
EBD_7203
S3-530 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Choke packets in WANS (a) basic, (b) hope-by-hope So to help this, Hop-by-Hop Choke packets are used. In
Basic idea: Router checks the status of each output line: this approach, the choke packet affects each and every
if it is too occupied, sends a Choke packet to the source. intermediate router through which it passes by.
The host is assumed to be cooperative and will slow Here, as soon as choke packet reaches a router back to
down. its path to the source, it curtails down the traffic between
• When the source gets a chock packet, it cuts rate by those intermediate routers. In this scenario, intermediate
half, and ignores further choke packets coming from nodes must dedicate few more buffers for the incoming
the same destination for a fixed period. traffic as the outflow through that node will be curtailed
• After that period has expired, the host listens for down immediately as choke packet arrives it, but the input
more choke packets. If one arrives, the host cut rate traffic flow will only be curtailed down when choke packet
by half again. If no choke packet arrives, the host reaches the node which is before it in the original path.
may increase rate.
Uncooperative cheating host may get all bandwidth while
cooperative honest host gets penalized ® Use weighted P P
Q Chok
e Q
fair queueing to enforce cooperation and assign priority R
Heavy Heavy
Problem of basic Choke Packets: For high-speed WANs, flow
R flow
(a) (b)
return path for a choke packet may be so long that too
many packets have already been sent by the source P P
Q
Choke Q
before the source notes congestion and takes action Host R R
Reduced Reduced Reduced
in San Francisco (router A) is sending heavy traffic to a flow flow flow
(c) (d)
host in New York (router D), and D is in trouble. It sends
a choke packet to A. Note how long it takes for A to
reduce the rate and eventually to relieve D Depict the functioning of Hop-by-Hop choke packets
• Solution: Use “push-back” or hop-by-hop choke (a) Heavy traffic between nodes P and Q, (b) Node Q
packets sends the Choke packet to P, (c) Choke packet
When choke packet reaches router F, it forwards choke packet reaches R, and the flow between R and Q is curtail down.
to router E as well as reduces its traffic to D. Thus the problem Choke packet reaches P, and P reduces the flow out.
that D has is “push-back” to F and D gets relief quickly. This TCP AND UDP
process is repeated down the route until the “ball” is back to Protocol : A protocol is the special set of rules that end points
the “root” source A. in a telecommunication connection use when they communicate.
Hop-by-Hop Choke Packets There are two types of Internet Protocol (IP) traffic. They are
This technique is an advancement over Choked packet TCP or Transmission Control Protocol and UDP or User
method. At high speed over long distances, sending a Datagram Protocol. TCP is connection oriented – once a
packet all the way back to the source doesn’t help much, connection is established, data can be sent bidirectional. UDP
because by the time choke packet reach the source, is a simpler, connectionless Internet protocol. Multiple messages
already a lot of packets destined to the same orginal are sent as packets in chunks using UDP.
destination would be out from the source.
COMPUTER NETWORKS S3-531

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

Protocol Role Port


HTTP Hyper Text Transfer Protocao
• browser and web server communication
1. client browser connects to HTTP server 80
2. client browser send a request to the
HTTP server
3. HTTP server by sending a response
4. HTTP server disconnects
Figure : a basic network architecture
FTP File transfer protocol A problem with this approach is that hubs generate a lot of
20 traffic, especially on larger networks. Most of this traffic is
1. allow people anywhere on the Internet to
wasted, since it is intended for only one node but it is sent to
log in and download whatever files they
have placed on the FTP server, or upload all nodes on the network.
other files.
2. Port 20 for data channel and 21 for
control channel 21

POP3 Post Office Protocol 3


1. The point of POP3 is to fetch email from Hub
the remote mailbox and store it on the 110
user’s local machine to read later.
2. Downloaded emails are then deleted Switch
from the server.

IMAP Internet Message Access Control


1. Retrieve e-mails
143
2. retaining e-mail on the server and for
organizaing it in folders on the serve
Figure : a basic network with a hub and a switch
SMTP Sending email A commonly used solution today is a switch. A switch still
25 connects all nodes to each other, like a hub, but is more
1. Sending e-mails
2. Establish TCP connection to port 25 of intelligent in which messages are passed on to which node. A
the destination machine/server switch examines incoming Ethernet messages to see which
3. Start sending email message node is the intended recipient, and then directly (and only)
passes the messages to that node. This way other nodes do not
BA SI C CO NC EP TS O F HU BS , SW IT CH ES , unnecessarily receive all traffic.
GATEWAYS, AND ROU TERS Since switches are more expensive than hubs, a low-traffic part
TCP/IP networks are the most common type of network today. of the network could be set up using a hub, with the more high-
With such a network, a number of computers or nodes can traffic nodes being interconnected to the switch. The hub
segment is then connected to the switch as well, as shown in
communicate with each other. An important aspect of this
above figure.
communication is routing: getting data packets from one node
to another, in particular from one node on one network to Segments and bridges
another node on another network. A large network can be divided into multiple parts which are
called segments. Each segment can use its own network
Nodes, hubs and switches protocol, security rules, firewalls and so on. Nodes on different
A network is a collection of computers or other devices, segments cannot directly communicate with each other. To
commonly called nodes, that are able to communicate with each make this possible, a bridge is added between the segments, as
other. This communication takes place on different network shown in figure.
levels. A network may use the Internet Protocol (IP) at one level
and Ethernet at the level directly below it. This distinction is
important because some parts of the network operate at the IP
level and others at the Ethernet level. Bridge
The most common type of network (especially in the home) is
the Ethernet network shown in figure 1, where all nodes are
connected to a central device. In its simplest form this central
node is called a hub. Figure : two network segments connected via a bridge
EBD_7203
S3-534 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
Routers and gateways doing the encryption twice. If we send the certificate also along
A router is connected to two different networks and passes with this then we have authentication also. So what we finally
packets between them, as shown in figure 4 to the right. In a send looks like this:
typical home network, the router provides the connection Z : Certificatesender + Publicreciever ( Privatesender ( Ek ) )
between the network and the Internet. + Ek ( M )
A gateway is the same as a router, except in that it also Here Ek stands for the symmetric key and Ek ( M ) for the
translates between one network system or protocol and message which has been encrypted in this symmetric key.
another. The NAT protocol for example uses a NAT gateway to However this still does not ensure integrity. The reason is that
connect a private network to the Internet. if there is some change in the middle element, then we will not
get the correct key and hence the message which we decrypt
NETWORK SECURITY will be junk. So we need something similar to CRC but slightly
Data on the network is analogous to possessions of a person. more complicated. This is because somebody might change the
It has to be kept secure from others with malicious intent. This CRC and the message consistently. This function is called
intent ranges from bringing down servers on the network to Digital Signature.
using people’s private information like credit card numbers to Digital Signatures
sabotage of major organizations with a presence on a network. Suppose A has to send a message to B. A computes a hash
To secure data, one has to ensure that it makes sense only to function of the message and then sends this after encrypting
those for whom it is meant. This is the case for data it using its own private key. This constitutes the signature
transactions where we want to prevent eavesdroppers from produced by A. B can now decrypt it, recompute the hash
listening to and stealing data. function of the message it has received and compare the two.
The various issues in Network security are as follows: Obviously, we would need the hash functions to be such that
1 Authentication: We have to check that the person who the probability of two messages hashing to the same value is
has requested for something or has sent an e-mail is extremely low. Also, it should be difficult to compute a message
indeed allowed to do so. In this process we will also look with the same hash function as another given message.
at how the person authenticates his identity to a remote Otherwise any intruder could replace the message with another
machine. that has the same hash value and leave the signatures intact
2 Integrity: We have to check that the message which we leading to loss of integrity. So the message along with the
have received is indeed the message which was sent. digital signature looks like this :
Here CRC will not be enough because somebody may Z + Privatesender ( Hash ( M ) )
deliberately change the data. Nobody along the route Key exchange in symmetric key schemes is a tricky business
should be able to change the data. because anyone snooping on the exchange can get hold of the
3 Confidentiality: Nobody should be able to read the data key if we are not careful and since there is no public-private key
on the way so we need Encryption arrangement here, he can obtain full control over the
4 Non-repudiation: Once we sent a message, there should communication. There are various approaches to the foolproof
be no way that we can deny sending it and we have to exchange of keys in these schemes. We look at one approach
accept that we had sent it. which is as follows:-
5 Authorization: This refers to the kind of service which is Diffie - Hellman Key Exchange
allowed for a particular client. Even though a user is A and B are two persons wishing to communicate. Both of them
authenticated we may decide not to authorize him to use generate a random number each, say x and y respectively. There
a particular service. is a function f which has no inverse. Now A sends f(x) to B and
To ensure all this, we take the help of cryptography. We can B sends f(y) to A. So now A knows x and f(y) and B knows y
have two kinds of encryption : and f(x). There is another function g such that g(x, f(y)) = g(y,
1 Symmetric Key Encryption: There is a single key which f(x)). The key used by A is g(x, f(y)) and that used by B is g(y,
is shared between the two users and the same key is used f(x)). Both are actually same. The implementation of this
for encrypting and decrypting the message. approach is described below :
2 Public Key Encryption: There are two keys with each user B generates number y
A generates number x
: a public key and a private key. The public key of a user
is known to all but the private key is not known to anyone
except the owner of the key. If a user encrypts a message 1 n, g, g mod n
in his private key then it can be decrypted by anyone by
using the sender’s public key. To send a message A B
securely, we encrypt the message in the public key of the
receiver which can only be decrypted by the user with his 2
g y mod n
private key.
Key Exchange in Symmetric Key Schemes
The sender first encrypts the message using the symmetric key. A computes (g y mod n)x B computes (g x mod n)y
Then the sender encrypts the symmetric key first using it’s = gxy mod n = gxy mod n
private key and then using the receiver’s public key. So we are The Diffie-Hellman Key Exchange
COMPUTER NETWORKS S3-535
1. A has two large prime numbers n and g. There are other and so it comes to know that there is some problem in
conditions also that these numbers must satisfy. communication.
2. A sends n, g and gx mod n to B in a message. B evaluates Here we have assumed that there is some application level
(gx mod n)y to be used as the key. understanding between A and B like the port number. If A
3. B sends gy mod n to A. A evaluates (gy mod n)x to be sends a packet at port number 25 and receives a packet at port
used as the key. So now both parties have the common number 35, then it will come to know that there is some problem.
number gxy mod n. This is the symmetric (secret At the very least we have ensured that C cannot read the
communication) key used by both A and B now. packets though it can block the communication.
This works because though the other people know n, g, gx mod There is another much simpler method of exchanging keys
n, gy mod n but still they cannot evaluate the key because they which now discuss :
do not know either x or y.
Key Distribution Center
Man in the Middle Attack There is a central trusted node called the Key Distribution
However there is a security problem even then. Though this Center ( KDC ). Every node has a key which is shared between
system cannot be broken but it can be bypassed. The situation it and the KDC. Since no one else knows A’s secret key (KA)
which we are referring to is called the man-in-the-middle attack. KDC is sure that the message it received has come from A. We
We assume that there is a guy C in between A and B. C has show the implementation through this diagram :
the ability to capture packets and create new packets. When A
sends n, g and gx mod n, C captures them and sends n, g and
gz mod n to B. On receiving this B sends n, g and gy mod n
but again C captures these and sends n, g and gz mod n to A.
A
So A will use the key (gz mod n)x and B will use the key (gz KDC
1 A, KA (B, Kg )
mod n)y . Both these keys are known to C and so when a
packet comes from A, C decrypts it using A’s key and encrypts
it in it’s own key and then sends it to B. Again when a packet
comes from B, it does a similar thing before sending the packet 2
to A. So effectively there are two keys - one operating between
A and C and the other between C and B. KB (A, Kg)

A picks x I picks z B picks y


K S becomes the Key for Information
Transfer between A and B
1 n, g, g x mod n
B
2 n, g, g za mod n
A I B

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

A KB (A, KS), KS (RA2 )) The otway-rees key excahnge protocol


In real life all protocols will have time-stamps. This is because
we cannot remember all random numbers generated in the past.
We ignore packets with higher time stamps than some limit. So
KS (RA2 – 1), RB B
we only need to remember nonces for this limit. Looking at
these protocols, we can say that designing of protocols is more
of an art than science. If there is so much problem in agreeing
KS (RB – 1) on a key then should we not use the same key for a long time.
The key can be manually typed using a telephone or sent
The Needham-Schroeder Authentication Protocol through some other media.
COMPUTER NETWORKS S3-537
Challenge - Response Protocol changing the order of authentication which is leading to
Suppose nodes A and B have a shared key KAB which was problems. Basically KAB(RB) should be sent before KAB(RA). If
somehow pre-decided between them. Can we have a secure we have a node C in the middle, then C can pose as B and talk
communication between A and B ? We must have some kind of to A. So C can do replay attack by sending messages which it
a three way handshake to avoid replay attack So, we need to had started some time ago.
have some interaction before we start sending the data. A A B
challenges B by sending it a random number RA and expects
an encrypted reply using the pre-decided key KAB. B then 1. A—————————>
challenges A by sending it a random number RB and expects 2. <————————RB
an encrypted reply using the pre-decided key KAB. 3. KAB(RB)—————>
A B
1. A, RA——————> 4. RA————————>

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

1. Suppose the round trip propagation delay for a 10 Mbps B1


Ethernet having 48 bit jamming signal is 46.4 ms. The minimum
1 2
frame size is [2005, 2 marks] H1 H2 H3 H4
(a) 94 (b) 416
(c) 464 (d) 512 2 3
2. In a packet switching network, packets are routed from source B5 4 B3
3
to destination along a single path having two intermediate 1 4 1 2
nodes. If the message size is 24 byte and each packet contains
a header of 3 byte, then the optimum packet size is
[2005, 2 marks] H5 H6 H7 H8
2 2 1
1
(a) 4 (b) 6 B4 B2
(c) 7 (d) 9 3 3
3. The maximum window size for data transmission using the
selective reject protocol with n-bit frame sequence number H9 H10 H11 H12
is [2005, 1 mark] 6. For the given connection of LANs by bridges, which one of
(a) 2 n (b) 2 n–1 the following choices represents the depth first traversal of
the spanning tree of bridges? [2006, 2 marks]
(c) 2n – 1 (d) 2n – 2 (a) B1, B5, B3, B4, B2 (b) B1, B3, B5, B2, B4
4. The Address Resolution Protocol (ARP) is used for (c) B1, B5, B2, B3, B4 (d) B1, B3, B4, B5, B2
[2005, 1 mark] 7. Consider the correct spanning tree for the previous question.
(a) finding the IP address from the DNS Let host H1 send out a broadcast ping packet. Which of the
following options represents the correct forwarding table on
(b) finding the IP address of the default gateway
B3 ? [2006, 2 marks]
(c) finding the IP address that corresponds to a MAC
address Host Port
(d) finding the IP address that corresponds to a IP address H1, H2, H3, H4 3
5. Packets of the same session may be routed through different (a) H5, H6, H9, H10 1
paths in [2005, 1 mark] H7, H8, H11, H12 2
(a) TCP but not UDP (b) TCP and UDP
(c) UDP but not TCP (d) Neither TCP nor UDP Host Port
Statements for Linked Answer Questions 6 and 7 H1, H2 4
Consider the diagram shown below where a number of LANs are H3, H4 3
(b) H5, H6 1
connected by (transparent) bridges. In order to avoid packets
looping through circuits in the graph, the bridges organize H7, H8, H9, H10, H11, H12 2
themselves in a spanning tree. First, the root bridge is identified
as the bridge with the least serial number. Next, the root sends out Host Port
(one or more) data units to enable the setting up of the spanning H3, H4 3
tree of shortest paths from the root bridge to each bridge. H5, H6, H9, H10 1
Each bridge identifies a port (the root port) through which it will (c) H1, H2 4
forward frames to the root bridge. Port conflicts are always resolved H7, H8, H11, H12 2
in favour of the port with the lower index value. When there is a
possibility of multiple bridges forwarding to the same LAN (but Host Port
not through the root port), ties are broken as follows: bridges H1, H2, H3, H4 3
closest to the root get preference and between such brides, the (d) H5, H7, H9, H10 1
one with the lowest serial number is preferred. H7, H8, H9, H10 4
COMPUTER NETWORKS S3-541
8. Station A needs to send a message consisting of 9 packets é 2LTR + 2K ù é 2LTR ù
to Station B using a sliding window (window size 3) and go- (a) ê log2 K ú (b) ê log 2
K úû
ë û ë
back-n error control strategy. All packets are ready and
immediately available for transmission. If every 5th packet é 2LTR + K ù é 2LTR + K ù
that A transmits gets lost (but no acts from B ever get lost),
(c) êlog 2 K ú (d) êlog 2
2K ú
ë û ë û
then what is the number of packets that A will transmit for 14. The message 11001001 is to be transmitted using the CRC
sending the message to B? [2006, 2 marks] polynomial x3 + 1 to protect it from errors. The message that
(a) 12 (b) 14 should be transmitted is [2007, 2 marks]
(c) 16 (d) 18 (a) 11001001000 (b) 11001001011
9. Two computers C1 and C2 are configured as follows. C1 has (c) 11001010 (d) 110010010011
IP address 203.197.2.53 and netmask 255.255.128.0. C2 has IP 15. The address of a class B host is to be split into subnets with
address 203.197.75.201 and netmask 255.255.192.0. Which a 6-bit subnet number. What is the maximum number of
one of the following statements is true? [2006, 2 marks] subnets and the maximum number of hosts in each subnet?
(a) C1 and C2 both assume they are on the same network [2007, 2 marks]
(b) C2 assumes C1 is on same network, but C1 assumes C2 (a) 62 subnets and 262142 hosts
is on a different network (b) 64 subnets and 262142 hosts
(b) C1 assumes C2 is on same network, but C2 assumes C1 (c) 62 subnets and 1022 hosts
is on a different network (d) 64 subnets and 1024 hosts
(d) C1 and C2 both assume they are on different networks 16. In a token ring network, the transmission speed is 107 bps
10. Station A uses 32 byte packets to transmit messages to and the propagation speed is 200 m/ms. The 1-bit delay in
Station B using a sliding window protocol. The round trip this network is equivalent to [2007, 2 marks]
delay between A and B is 80 ms and the bottleneck bandwidth (a) 500 m of cable (b) 200 m of cable
on the path between A and B is 12 kbps. What is the optimal (c) 20 m of cable (d) 50 m of cable
window size that A should use? [2006, 2 marks] 17. There are n stations in a slotted LAN. Each station attempts
(a) 20 (b) 40 to transmit with a probability p in each time slot. What is the
probability that only one station transmits in a given time
(c) 160 (d) 320
slot? [2007, 2 marks]
11. For which one of the following reasons does Internet
(a) np(1 – p)n – 1 (b) (1 – p)n – 1
Protocol (IP) use the Time To Live (TTL) field in the IP (c) p(1 – p)n – 1 (d) 1 – (1 – p)n – 1
datagram header? [2006, 1 mark] 18. Which one of the following uses UDP as the transport
(a) Ensure packets reach destination within that time protocol? [2007, 1 mark]
(b) Discard packets that reach later than that time (a) HTTP (b) Telnet
(c) Prevent packets from looping indefinitely (c) DNS (d) SMTP
(d) Limit the time for which a packet gets queued in 19. In Ethernet when Manchester encoding is used, the bit rate
intermediate routers is [2007, 1 mark]
12. Match the List I with List II and select the correct answer by (a) half the baud rate (b) twice the baud rate
using the codes given below the lists. [2007, 2 marks] (c) same as the baud rate (d) None of these
20. A client process P needs to make a TCP connection to a
server process S. Consider the following situation. The server
List I List II process S executes a socket (), a bind () and a listen () system
P: SMTP 1. Application layer call in that order, following which it is preempted.
Q: BGP 2. Transport layer Subsequently, the client process P executes a socket () system
call followed by connect () system call to connect to the
R: TCP 3. Data link layer
server process S. The server process has not executed any
S: PP 4. Networ k layer accept () system call. Which one of the following events
5. Physical layer could take place?
(a) Connect () system call returns successfully
(a) P - 2, Q - 1, R - 3, S - 5 (b) P - 1, Q - 4, R - 2, S - 3 (b) Connect () system call blocks
(c) P - 1, Q - 4, R - 2, S - 5 (d) P - 2, Q - 4, R - 1, S - 3 (c) Connect () system call returns an error
(d) Connect () system call returns in a core dump
13. The distance between two stations M and N is L km. All
21. A computer on a 10 Mbps network is regulated by a token
frames are K bits long. The propagation delay per kilometer
bucket. The token bucket is filled at a rate of 2 Mbps. It is
is t s. Let R b/s be the channel capacity. Assuming that initially filled to capacity with 16 Megabits. What is the
processing delay is negligible, the minimum number of bits maximum duration for which the computer can transmit at
for the sequence number field in a frame for maximum the full 10 Mbps?
utilization, when the sliding window protocol is used, is (a) 1.6 s (b) 2 s
[2007, 2 marks] (c) 5 s (d) 8 s
EBD_7203
S3-542 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
22. If a class B network on the Internet has a subnet mask of (a) 0.015/s (b) 0.064/s
255.255.248.0, what is the maximum number of hosts per (c) 0.135/s (d) 0.327/s
subnet? 30. In the RSA public key cryptosystem, the private and public
(a) 1022 (b) 1023 keys are (e, n) and (d, n) respectively, where n = p*q and p
(c) 2046 (d) 2047 and q are large primes. Besides, n is public and p and q are
23. In the slow start phase of the TCP congestion control private. Let M be an integer such that 0 < M < n and f (n)
algorithm, the size of the congestion window[2008, 2 marks] = (p – 1) (q – 1). Now consider the following equations.
(a) does not increase (b) increases linearly [2009, 2 marks]
(c) increases quadratically (d) increases exponentially
1. M’ = Me mod n
24. Which of the following system calls results in the sending of
M = (M’)d mod n
SYN packets? [2008, 1 mark]
2. ed º 1 mod n
(a) Socket (b) Bind
(c) Listen (d) Connect 3. ed = 1 mod f n
25. What is the maximum size of data that the application layer 4. M’ = Me mod f n
can pass on to the TCP layer below? [2008, 1 mark] M = (M’)d mod f n
(a) Any size Which of the above equations correctly represent RSA
(b) 216 byte size of TCP header cryptosystem?
(c) 216 byte (a) 1 and 2 (b) 1 and 3
(d) 1500 byte (c) 2 and 4 (d) 3 and 4
Statements for Linked Answer Questions 26 and 27 Statements for Linked Answer Questions 31 and 32
Frames of 1000 bits are sent over a 106 bps duplex link between Consider a network with 6 routers R1 to R6 connected with links
two hosts. The propagation time is 25 ms. Frames are to be having weights as shown in the following diagram.
transmitted into this link to maximally pack them in transit (within
the link). R2 7 R4
26. What is the minimum number of bits l that will be required to 6 8
represent the sequence numbers distinctly? Assume that no
time gap need to be given between transmission of two R1 2 1 R6
frames. [2009, 2 marks] 3 4
(a) l = 2 (b) l = 3
R3 9 R5
(c) l = 4 (d) l = 5
27. Suppose that the sliding window protocol is used with the
sender window size of 21, where 1 is the number of its 31. All the routers use the distance vector based routing
identified in the earlier part and acknowledgments are always algorithm to update their routing tables. Each router starts
piggy backed. After sending 21 frames, what is the minimum with its routing table initialized to contain an entry for each
time, the sender will have to wait before starting transmission neighbour with the weight of the respective connecting link.
of the next frame? (Identify the closest choice ignoring the After all the routing tables stabilize, how many links in the
frame processing time.) [2009, 2 marks] network will never be used for carrying any data?
(a) 16 ms (b) 18 ms [2011, 2 marks]
(c) 20 ms (d) 22 ms (a) 4 (b) 3
28. Let G(x) be the generator polynomial used for CRC checking. (c) 2 (d) 1
What is the condition that should be satisfied by G(x) to 32. Suppose the weights of all unused links in the previous
detect odd number of bits in error? [2009, 2 marks] question are changed to 2 and the distance vector algorithm
(a) G(x) contains more than two terms is used again until all routing tables stabilize. How many
(b) G(x) does not divide 1 + xk, for any k not exceeding the links will now remain unused? [2011, 2 marks]
frame length (a) 0 (b) 1
(c) 1 + x is a factor of G(x) (c) 2 (d) 3
(d) G(x) has an odd number of terms 33. Suppose computers A and B have IP addresses 10.105.1.113
29. While opening a TCP connection, the initial sequence number and 10.105.1.91 respectively and they both use the same net
is to be derived using a time-of-day (ToD) clock that keeps mask N. Which of the values of N given below should not be
running even when the host is down. The low order 32 bits used, if A and B should belong to the same network?
of the counter of the ToD clock is to be used for the initial [2011, 2 marks]
(a) 255.255.255.0 (b) 255.255.255.128
sequence numbers. The clock counter increments once per
(c) 255.255.255.192 (d) 255.255.255.244
millisecond. The maximum packet lifetime is given to be 64s.
34. One of the header fields in an IP datagram is the Time To
Which one of the choices given below is closest to the
Live (TTL) field. Which of the following statements best
minimum permissible rate at which sequence numbers used explains the need for the field? [2010, 1 marks]
for packets of a connection can increase? [2009, 2 marks]
COMPUTER NETWORKS S3-543
(a) It can be used to prioritize packets (c) m1: SMTP m2: POP m3 : HTTP
(b) It can be used to reduce delays (d) m1: POP m2: SMTP m3 : IMAP
(c) It can be used to optimize throughput 39. A layer-4 firewall (a device that can look at all protocol
(d) It can be used to prevent packet looping headers up to the transport layer) cannot [2011, 1 mark]
Statements for Linked Answer Questions 35 and 36 (a) block entire HTTP traffic during 9:00 PM and 5:00 AM
Consider a network with five nodes, N1 to N5, as shown below: (b) block all ICMP traffic
(c) stop incoming traffic from a specific IP address but
allow outgoing traffic to the same IP address
3 1
N5 N2 N1 (d) block TCP traffic from a specific user on a multi-user
system during 9:00 PM and 5:00 AM
40. An Internet Service Provider (ISP) has the following chunk
4 6 of CIDR-based IP addresses available with it; 245.248. 128.0/
20. The ISP wants to give half of this chunk of addresses to
organization A and a quarter to organization B, while retaining
N4 N3 the remaining with itself. Which of the following is a valid
2
allocation of addresses to A to B? [2012, 2 marks]
The network uses a distance vector routing protocol. Once the (a) 245.248. 136.0/21 and 245.248. 128.0/022
routes have stabilized, the distance vectors at different nodes are (b) 245.248. 128.0/21 and 245.248. 128.0/22
as following. Each distance vector is the distance of the best (c) 245.248. 132.0/22 and 245.248. 132.0/21
known path at that instance to nodes, N1 to N5, where the distance (d) 245.248. 136.0/24 and 245.248. 132.0/21
to itself is 0. Also, all links are symmetric and the cost is identical 41. Consider a source computer (S) transmitting a file of size 106
in both directions. In each round, all nodes exchange their distance bit to a destination computer (D) over a network of two
vectors with their respective neighbours, Then all nodes update routers (R1 and R2) and three links (L1, L2 and L3). L1 connects
their distance vectors. In between two rounds, any change in S to R1; L2 connects R1 to R2 and L3 connects R2 to D. Let
cost of a link will cause the two incident nodes to change only each link be of length 100 km. Assume signals travel over
that entry is their distance vectors. each link at a speed of 108 m/s. Assume that the link
35. The cost of link N2-N3 reduces to 2 in (both directions). bandwidth on each link is 1 Mbit/s. Let the file be broken
After the next round of updates, what will be the new distance down into 1000 packets each of size 1000 bits. Find the total
vector at node N3? [2011, 2 marks] sum of transmission and propagation delays in transmitting
(a) 3, 2, 0, 2, 5 (b) 3, 2, 0, 2, 6 the file from S to D? [2012, 2 marks]
(c) 7, 2, 0, 2, 5 (d) 7, 2, 0, 2, 6 (a) 1005 ms (b) 1010 ms
36. After the update in the previous question, the link N1-N2 (c) 3000 ms (d) 3003 ms
goes down. N2 will reflect this change immediately in its 42. Consider an instance of TCP’s Additive Increase
distance vector as cost ¥ . After the next round of update, Multiplicative Decrease (AIMD) algorithm where the Window
what will be the cost to N1 in the distance vector of N3? size at the start of the slow phase is 2 MSS and the threshold
[2011, 2 marks] at the start of the first transmission is 8 MSS. Assume that a
(a) 3 (b) 9 timeout occurs during the fifth transmission. Find the
(c) 10 (d) ¥ congestion Window size at the end of the tenth transmission.
37. HTML (Hyper Text Markup Language) has language [2012, 2 marks]
elements which permit certain actions other than describing (a) 8 MSS (b) 14 MSS
the structure of the web document. Which one of the (c) 7 MSS (d) 12 MASS
following actions is not supported by pure HTML (without 43. The Protocol Data Unit (PDU) for the application layer in the
any server or client side scripting) pages? [2011, 1 mark] Internet stack is [2012, 1 mark]
(a) Embed web objects from different sites into the same (a) segment (b) datagram
page (c) message (d) frame
(b) Refresh the page automatically after a specified interval Common Data for questions 44 and 45
(c) Automatically redirect to another page upon download Consider the following C code segment :
(d) Display the client time as part of the page int a, b, c = 0 ;
38. Consider the different activities related to email: void prtFun (void);
m1: Send an email from a mail client to a mail server. main ( )
m2: Download an email from mailbox server to a mail client. { static int a = 1; /* Line 1 */
m3: Checking email in a web browser. [2011, 1 mark] prtFun ( );
Which is the application level protocol used in each activity? a + = 1;
(a) m1: HTTP m2: SMTP m3 : POP prt Fun ( ) ;
(b) m1: SMTP m2: FTP m3 : HTTP printf (“\n %d %d” , a, b) ;
EBD_7203
S3-544 GATE COMPUTER SCIENCE & INFORMATION TECHNOLOGY
} (a) 1 (b) 2
void prt Fun (void) (c) 2.5 (d) 5
{ static int a = 2;
50. In an IPv4 datagram, the M bit is 0, the value of HLEN
int b = 1 ;
is 10, the value of total length is 400 and the fragment
a + = + + b;
offset value is 300. The position of the datagram, the
}
sequence numbers of the first and the last bytes of the
printf (“\n %d” %d”, a, b);
payload, respectively are [2013, 2 Marks]
44. In the IPv4 addressing format, the number of networks allowed
(a) Last fragment, 2400 and 2789
under Class C addresses is [2012, 1 mark]
(b) First fragment, 2400 and 2759
(a) 214 (b) 27
(c) Last fragment, 2400 and 2759
(c) 221 (d) 224
(d) Middle fragment, 300 and 689
45. Which of the following transport layer protocols is used to
51. Which of the following are used to generate a message
support electronic mail? [2012, 1 mark]
(a) SMTP (b) IP digest by the network security protocols?
(c) TCP (d) UDP [2014, Set-1, 1 Mark]
(p) RSA (q) SHA-1
46. The transport layer protocols used for real time
(r) DES (s) MD5
multimedia, file transfer, DNS and e-mail, respectively are
(a) P and R only (b) Q and R only
[2013, 1 Mark]
(c) Q and S only (d) R and S only
(a) TCP, UDP, UDP and TCP
52. Identify the correct order in which the following actions
(b) UDP, TCP, TCP and UDP take place in an interaction between a web browser and a
(c) UDP, TCP, UDP and TCP web server.
(d) TCP, UDP, TCP and UDP 1. The web browser requests a webpage using HTTP.
47. Using public key cryptography, X adds a digital signature 2. The web browser establishes a TCP connection with
s to message M, encrypts < M, s > and sends it to Y, the web server.
where it is decrypted. Which one of the following 3. The web server sends the requested webpage using
sequences of keys is used for the operations? HTTP.
[2013, 1 Mark] 4. The web browser resolves the domain name using
(a) Encryption: X’s private key followed by Y’s private DNS. [2014, Set-1, 1 Mark]
key; Decryption: X’s public key followed by Y’s (a) 4, 2, 1, 3 (b) 1, 2, 3, 4
private key (c) 4, 1, 2, 3 (d) 2, 4, 3
(b) Encryption: X’s private key followed by Y’s public 53. Consider a token ring network with a length of 2 km having
key; Decryption: X’s public key followed by Y’s 10 stations including a monitoring station. The propagation
private key speed of the signal is 2 × 108 m/s and the token transmission
(c) Encryption: X’s public key followed by Y’s private time is ignored. If each station is allowed to hold the token
key; Decryption: Y’s public key followed by X’s for 2 msec, the minimum time for which the monitoring station
private key should wait (in m sec)before assuming that the token is lost
(d) Encryption: X’s private key followed by Y’s public is _______. [2014, Set-1, 2 Marks]
key; Decryption: Y’s private key followed by X’s 54. Let the size of congestion window of a TCP connection be
public key 32 KB when a timeout occurs. The round trip time of the
48. Assume that source S and destination D are connected connection is 100 msec and the maximum segment size used
through two intermediate routers labelled R. Determine is 2 KB. The time taken (in msec) by the TCP connection to
how many times each packet has to visit the network get back to 32 KB congestion window is _________.
layer and the data link layer during a transmission from [2014, Set-1, 2 Marks]
S to D. [2013, 1 Mark] 55. Consider a selective repeat sliding window protocol that
uses a frame size of 1 KB to send data on a 1.5 Mbps link
with a one-way latency of 50 msec. To achieve a link utilization
S R R D of 60%, the minimum number of bits required to represent
the sequence number field is ________.
(a) Network layer–4 times and Data link layer–4 times [2014, Set-1, 2 Marks]
(b) Network layer–4 times and Data link layer–3 times 56. Which one of the ofllowing is TRUE about the interior
(c) Network layer–4 times and Data link layer–6 times gateway routing protocols - Routing Information Protocol
(d) Network layer–2 times and Data link layer–6 times (RIP) and Open Shortest Path First (OSPF) ?
[2014, Set-2, 1 Mark]
49. Determine the maximum length of the cable (in km) for (a) RIP uses distance vector routing and OSPF uses link
transmitting data at a rate of 500 Mbps in an Ethernet state routing
LAN with frames of size 10,000 bits. Assume the signal (b) OSPF uses distance vector routing and RIP uses link
speed in the cable to be 2,00,000 km/s. [2013, 2 Marks] state routing
COMPUTER NETWORKS S3-545
(c) Both RIP and OSPF use link state routing (a) Only I1 and I2 (b) Only I1
(d) Both RIP and OSPF use distance vector routing

Potrebbero piacerti anche