Professional Documents
Culture Documents
PREVIOUS YEARS’ SOLVED QUESTION PAPERS Also Helpful for GAIL, BARC, HPCL, BHEL, ONGC, SAIL, DRDO & Other PSU’s
ish
COMPUTER SCIENCE AND
INFORMATION TECHNOLOGY
na
G R AD UAT E A PT I T UD E T E S T I N E NG I N EE R I N G
SERIES
2019
’s
This book is a one-stop solution for GATE aspirants to crack the exam. The book includes previous years’ GATE questions
segregated topic-wise along with exam analysis at the beginning of every unit. Detailed step-wise solutions are
QUESTION PAPERS
This book will help GATE aspirants to learn the ways to solve GATE questions quickly and know about the areas/topics to
concentrate on. The detailed solutions of GATE previous year questions will give students glimpse of pattern of
questions usually asked in GATE examination.
Dr. Manoj Kumar, Associate Professor, Delhi Technological University, New Delhi
This book is a standalone source book for preparing GATE competitive exam as the language used in the book is very
good. The solutions are detailed, step-wise, and easily understandable. The content is very well organized in the book
for easy learning. PREVIOUS YEARS’
Dr. R. Velmani, Assistant Professor (Senior Grade),
Madanapalle Institute of Technology and Science, Chittoor, Andhra Pradesh
SOLVED QUESTION PAPERS
The language used in the book is simple and easy to understand and the approach used is excellent. Detailed solutions
are provided for GATE previous year questions. The exam analysis provided in the book will be extremely useful for the COMPUTER SCIENCE
GATE aspirants to get an idea about the pattern of questions asked in GATE exam.
Gurpreet Kaur, Assistant Professor, LPU, Phagwara, Punjab AND INFORMATION
TECHNOLOGY
INFORMATION TECHNOLOGY
given in this book are step-wise and easy to understand. The book will be very helpful for GATE aspirants.
2019
Guneet Kaur, Lecturer, LPU, Phagwara, Punjab
C ra ck th e
crack the gate series
HIGHLIGHTS
Includes more than 28 years’ GATE questions
arranged chapter-wise
Detailed solutions for better understanding
Includes latest GATE solved question papers with detailed analysis
in.pearson.com
2019
About Pearson
Pearson is the world’s learning company, with presence across 70 countries
worldwide. Our unique insights and world-class expertise comes from a long
history of working closely with renowned teachers, authors and thought
leaders, as a result of which, we have emerged as the preferred choice for
millions of teachers and learners across the world.
We believe learning opens up opportunities, creates fulfilling careers and
hence better lives. We hence collaborate with the best of minds to deliver you
class-leading products, spread across the Higher Education and K12 spectrum.
Superior learning experience and improved outcomes are at the heart of
everything we do. This product is the result of one such effort.
Your feedback plays a critical role in the evolution of our products and you
can contact us - reachus@pearson.com. We look forward to it.
No part of this eBook may be used or reproduced in any manner whatsoever without the publisher’s
prior written consent.
This eBook may or may not include all assets that were part of the print version. The publisher
reserves the right to remove any material in this eBook at any time.
ISBN 978-93-530-6127-2
eISBN 9789353065072
First Impression
Head Office: 15th Floor, Tower-B, World Trade Tower, Plot No. 1, Block-C, Sector 16, Noida 201 301,
Uttar Pradesh, India.
Registered Office: 4th Floor, Software Block, Elnet Software City, TS-140, Block 2 & 9, Rajiv
Gandhi Salai, Taramani, Chennai 600 113, Tamil Nadu, India.
Fax: 080-30461003, Phone: 080-30461060
in.pearson.com, Email: companysecretary.india@pearson.com
Salient Features
• Includes more than 27 years’ GATE questions arranged chapter-wise.
• Detailed solutions for better understanding.
• Includes latest GATE solved question papers with detailed analysis.
• Includes free online mock test based on GATE examination pattern for practice.
Despite of our best efforts, some errors may have inadvertently crept into the book. Constructive comments and
suggestions to further improve the book are welcome and shall be acknowledged gratefully.
1. Go through the pattern (using previous years’ GATE paper) and syllabus of the exam and start preparing
accordingly.
2. Preparation time for GATE depends on many factors, such as, individual’s aptitude, attitude, fundamentals,
concentration level etc. Generally rigorous preparation for four to six months is considered good but it may
vary from student to student.
3. Make a list of books which cover complete syllabus, contains solved previous year questions and mock tests
for practice based on latest GATE pattern. Purchase these books and start your preparation.
4. Make a list of topics which needs to be studied and make priority list for study of every topic based upon the
marks for which that particular topic is asked in GATE exam. Find out the topics which fetch more marks
and give more importance to those topics. Make a timetable for study of topics and follow the timetable
strictly.
5. An effective way to brush up your knowledge about technical topics is group study with your friends.
During group study you can explore new techniques and procedures.
6. While preparing any subject highlight important points (key definitions, equations, derivations, theorems
and laws) which can be revised during last minute preparation.
7. Pay equal attention to both theory and numerical problems. Solve questions (numerical) based on latest
exam pattern as much as possible, keeping weightage of that topic in mind. Whatever topics you decide to
study, make sure that you know everything about it.
8. Try to use short-cut methods to solve problems instead of traditional lengthy and time consuming methods.
9. Go through previous years’ papers (say last ten years), to check your knowledge and note the distribution
of different topics. Also analyze the topics in which you are weak and concentrate more on those topics.
Always try to solve papers in given time, to obtain an idea how many questions you are able to solve in the
given time limit.
10. Finish the detail study of topics one and a half months before your exam. During last month revise all the
topics once again and clear leftover doubts.
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks Questions.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Q.1 to Q.5 carry 1 mark each and Q.6 to Q.10 carry Question Number: 4 Question Type: MCQ
2 marks each. “A ___ investigation can sometimes yield new facts, but
Question Number: 1 Question Type: MCQ typically organized ones are more successful.”
What would be the smallest natural number which when The word best fills the blank in the above sentence is
divided either by 20 or by 42 or by 76 leaves a remainder (A) meandering (B) timely
of 7 in each case? (C) consistent (D) systematic
(A) 3047 (B) 6047 Solution: A process or activity that does not seem to
(C) 7987 (D) 63847 have a clear purpose or direction is said to meander. Thus,
Solution: The LCM of 20, 42, 76 = 20 (3) (7) (19) “meandering” is the apt word; the sentence suggests that a
meandering investigation might yield new facts, but organ-
= 7980.
ized ones are more successful.
The required number is 7987.
Hence, the correct option is (A).
Hence, the correct option is (C).
Question Number: 5 Question Type: MCQ
Question Number: 2 Question Type: MCQ
The area of a square is d. What is the area of the circle
What is the number missing in the following sequence? which has the diagonal of the square as its diameter?
2, 12, 60, 240, 720, 1440, ___, 0 (A) πd (B) πd2
(A) 2880 (B) 1440 1 1
(C) 720 (D) 0
(C) d 2 (D) d
4 2
Solution: 2, 12, 60, 240, 720, 1440, _____, 0 Solution: The area of the square is d. Its side is d .
2 12 60 240 720 1440 1440 Its diagonal is 2d . This is the diameter of the circle.
π(2d ) πd
Therefore, the area of the circle = = ⋅
2×6 12×5 60×4 240×3 720×2 1440× 4 2
The blank value will be 1440. Hence, the correct option is (D).
Hence, the correct option is (B). Question Number: 6 Question Type: MCQ
Question Number: 3 Question Type: MCQ In the figure below, ∠DEC + ∠BFC is equal to ____.
“From where are they bringing their books? _____ bring- E
ing ______ books from _____.”
D C
The words that best fill the blanks in the above sentence are F
(A) Their, they’re, there (B) They’re, their, there
A B
(C) There, their, they’re (D) They’re, there, there
Solution: The words that are apt for the three blanks are ∠BCD – ∠BAD
(A)
“they’re” (which is a contraction of “they are”), “their” ∠BAD + ∠BCF
(B)
(which means “belonging to the people previously men- ∠BAD + ∠BCD
(C)
tioned) and “there” (which means in that place). ∠CBA + ∠ADC
(D)
Hence, the correct option is (B).
execution.
(P) The processor pushes the process status of L onto Solution:
the control stack. For an = 2n + 3 for all n = 0, 1, 2, …. generating function of
(Q) The processor finishes the execution of the cur- the given sequence {an}, will be
rent instruction. ∞
(R) The processor executes the interrupt service F(x) = ∑ ( 2n + 3 ) x n
routine. n=0
(S) The processor pops the process status of L from = 3 + 5x + 7x2 + 9x3 + 11x4 +……
the control stack. = (3 + 6x + 9x2 + 12x3 + 15x4+…...)
(T) The processor loads the new PC value based on
– (x + 2x2 + 3x3 + 4x4 + …..)
the interrupt.
= 3(1 + 2x + 3x2 + 4x3 +……) Question Number: 19 Question Type: MCQ
– x(1 + 2x +3x2 + 4x3 + .…) Let ⊕ and denote the Exclusive OR and Exclusive NOR
1 1 3− x operations, respectively. Which one of the following is
= 3⋅
#include<stdio.h>
−x = NOT CORRECT?
(1 − x )2 (1 − x ) 2
(1 − x )2
struct Ournode { P ⊕Q = P Q
(A)
Hence, the correct option is (D).
char x, y, z; (B) P ⊕Q = PQ
Question Number: 17 Question Type: NAT
} ;
Consider (C) P ⊕ Q = P⊕Q
Int the following
main () { C program.
struct Ournode p = {‘1’, ‘0’, ‘a’+2}; (P ⊕ P)⊕Q = (P P) Q
(D)
struct Ournode *q = &p;
printf (“%c, %c”, *( (char*)q+1),
Solution:
* ( (char*)q+2) ); If we consider the last option given in problem, then we
have
return 0;
} ( )
P⊕P ⊕Q = PP Q( )
The output of this program is: 1⊕ Q ≠ 0 Q
(A) 0, c Q≠Q
(B) 0, a+2
Hence, the correct option is (D).
(C) ‘0’, ‘a+2’
(D) ‘0’, ‘c’ Question Number: 20 Question Type: MCQ
Solution: Consider the following processor design characteristics.
I. Register-to-register arithmetic operations only
P→ 1 0 ‘a’ + 2 II. Fixed-length instruction format
III. Hardwired control unit
q q+1 q+2
Which of the characteristics above are used in the design of
*((char*) q + 1)⇒0 a RISC processor?
*((char*) q + 2)⇒‘a’+2 (A) I and II only
(B) II and III only
⇒ c
(C) I and III only
The output of program is 0, c (D) I, II and III
Hence, the correct option is (A).
Solution:
Question Number: 18 Question Type: MCQ
Hence, the correct option is (D).
A queue is implemented using a non-circular singly linked
list. The queue has a head pointer and a tail pointer, as Question Number: 21 Question Type: MCQ
shown in the figure. Let n denote the number of nodes in In an Entity-Relationship (ER) model, suppose R is a
the queue. Let enqueue be implemented by inserting a new many-to-one relationship from entity set E1 to entity set E2.
node at the head, and dequeue be implemented by deletion Assume that E1 and E2 participate totally in R and that the
of a node from the tail. cardinality of E1 is greater than the cardinality of E2.
Which one of the following is the time complexity of Which one of the following is true about R?
the most time-efficient implementation of enqueue and (A) Every entity in E1 is associated with exactly one
dequeue, respectively, for this data structure? entity in E2.
(A) θ (1), θ (1) (B) θ (1), θ (n) (B) Some entity in E1 is associated with more than
(C) θ (n), θ (1) (D) θ (n), θ (n) one entity in E2.
Solution: We know that enqueue operation is done at (C) Every entity in E2 is associated with exactly one
header of linked list, if will take θ (1) time. entity in E1.
(D) Every entity in E2 is associated with at most one
Also we know that dequeue() takes θ (n) time because after
entity in E1.
deletion it takes ‘n’ computations to reach last node, as tail
points last node of linked list. Solution: Consider figure given below
Hence, the correct option is (B).
From above figure we conclude that every entity in E1 is (A) P-III, Q-IV, R-II, S-I
associated with (B) P-II, Q-I, R-IV, S-III
(C) P-IV, Q-I, R-II, S-III
exactly one entity in E2 (D) P-IV, Q-I, R-III, S-II
Hence, the correct option is (A).
Solution:
Question Number: 22 Question Type: MCQ The correct mapping is given in option C.
Consider the following two tables and four queries in SQL. Hence, the correct option is (C).
Book (isbn, bname), Stock (isbn, copies)
Question Number: 24 Question Type: MCQ
Query 1: SELECT B.isbn, S.copies
Consider the following statements regarding the slow start
FROM Book B INNER JOIN Stock S phase of the TCP congestion control algorithm. Note that
ON B.isbn = S.isbn; cwnd stands for the TCP congestion window and MSS
Query 2: SELECT B.isbn, S.copies denotes the Maximum Segment Size.
FROM Book B LEFT OUTER JOIN Stock S (i) The cwnd increases by 2 MSS on every success-
ful acknowledgment.
ON B.isbn = S.isbn; (ii) The cwnd approximately doubles on every
Query 3: SELECT B.isbn, S.copies successful acknowledgement.
FROM Book B RIGHT OUTER JOIN Stock S (iii) The cwnd increases by 1 MSS every round trip
ON B.isbn = S.isbn; time.
(iv) The cwnd approximately doubles every round trip
Query 4: SELECT B.isbn, S.copies time.
FROM Book B FULL OUTER JOIN Stock S Which one of the following is correct?
ON B.isbn = S.isbn; (A) Only (ii) and (iii) are true
Which one of the queries above is certain to have an output (B) Only (i) and (iii) are true
that is a superset of the outputs of the other three queries? (C) Only (iv) is true
(A) Query 1 (B) Query 2 (D) Only (i) and (iv) are true
(C) Query 3 (D) Query 4 Solution: Slow start phase of TCP congestion control al-
Solution: gorithm:
1. The natural join will return only those values which • Each time an ACK is received the congestion win-
are common in both the tables. dow is increased by one segment.
2. The left outer join will gives all rows from left ta- • If ack acknowledges 2 segment, cwnd is still in-
ble with null values, if right side table is not having creased by only one segment.
match. • If ack acknowledges a segment smaller than MSS
3. The right outer join will gives all rows from table bytes long, cwnd is increased by MSS bytes.
on right hand side with null values, if left hand side • If cwnd is 3, and if there is still outstanding ack,
table is not having the match. sender can only send two segments.
4. Full outer join will gives all rows in output which Hence, the correct option is (C).
are common in both tables, present in left table only
or right table only. Question Number: 25 Question Type: NAT
Hence, the correct option is (D). Two people, P and Q, decide to independently roll two
identical dice, each with 6 faces, numbered 1 to 6. The
person with the lower number wins. In case of a tie, they π2 /16
1
roll the dice repeatedly until there is no tie. Define a trial as
a throw of the dice by P and Q. Assume that all 6 numbers
= ∫ (cos (t )) dt
2
t =0
on each dice are equi-probable and that all trials are inde- 2
π /16
pendent. The probability (rounded to 3 decimal places) that 1
= sin t
one of them wins on the third trial is __________. 2 0
Solution: Let A be the event of both P and Q getting same
1 π2
number on the dice in one trial. = sin − sin 0
2 16
and B be the event of P and Q getting different numbers on
the dice in one trial. = 0.289
6 1 Hence, the correct answer is 0.27 to 0.30.
∴ =
P(A) =
36 6 Question Number: 27 Question Type: NAT
30 5 ⎛1⎞ ⎛ 1⎞
=
P( B ) = Consider a matrix A = uvT where u = ⎜ ⎟ , v = ⎜ ⎟ . Note
36 6 2
⎝ ⎠ ⎝ 1⎠
∴ The probability that one of them wins on the third trial that vT denotes the transpose of v. The largest eigenvalue of
= P(A ∩ A ∩ B) A is ________.
= P(A) P(A) P(B) 1 1
Solution: Given u = and v =
(∴ A and B are independent) 2
1
1 1 5 1 1 1
= × × ∴ A = uvT = (1 1) =
6 6 6 2 2 2
5 As det (A) = 0, one of the eigen values of A is 0.
= = 0.023
216 Let λ be the other eigne value of A
Hence, the correct answer is 0.021 to 0.024. ∴ 0 + λ = Trace (A) ⇒ λ = 1 + 2 = 3
Question Number: 26 Question Type: NAT So the largest eigen value of A is 3.
π /4 Hence, the correct answer is 3.
∫ x cos ( x ) dx
2
The value of correct to three decimal
0 Question Number: 28 Question Type: NAT
places (assuming that π = 3.14) is _______. The chromatic number of the following graph is ________.
π/4
Solution: Let I = ∫ x cos ( x 2 ) dx (1) a e
0
Put x = t ⇒ 2x dx = dt
2
c d
1
⇒ xdx = dt
2
At x = 0; t = 02 = 0 b f
2
π π π2 Solution: The chromatic number of the given graph is 3.
and at x = ; t = =
4 4 16
1
∴(1) becomes, 2
a e
π/4
3
I = ∫ x cos ( x 2 ) dx
c
0
d
π/4
∫ (cos ( x
2 2 b f
= )) ( x dx )
3
0
Hence, the correct answer is 3.
Question Number: 29 Question Type: NAT Question Number: 31 Question Type: NAT
Let G be a finite group on 84 elements. The size of a largest Consider the following C program:
possible proper subgroup of G is __________.
#include <stdio.h>
Solution: Given order of G = O(G) = 84 int counter = 0;
Any proper subgroup of G will have order less than 84. int calc (int a, int b) {
Also, we know that the order of a subgroup of a finite group int c;
divides the order of the group. counter++;
∴ The size of a largest possible proper subgroup of G. if (b==3) return (a*a*a);
= The largest divisor of 84 that is less than 84 = 42 else {
Hence, the correct answer is 42. c = calc (a, b/3);
return (c*c*c);
Question Number: 30 Question Type: NAT }
The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, }
3, 1. The inorder traversal of the same tree is 8, 6, 9, 4, 7, int main () {
2, 5, 1, 3. The height of a tree is the length of the longest calc (4, 81);
path from the root to any leaf. The height of the binary tree printf (“%d”, counter);
above is ______. }
Solution: Postorder: 8,9,6,7,4,5,2,3,1 The output of this program is _____.
In order: 8,6,9,4,7,2,5,1,3
Solution:
calc (4, 81)
8694725 1 3
Solution:
1 - - - - - - - - - - - - root level 0
2 3 - - - - - - - - - - - level 1 in out
4 5 - - - - -- - - - - - - - - - - level 2 D Q D Q
Clock
6 7 - - - - - - - - - -- - - - - - - - - - - level 3
8 9 - - - - - - - - - - - - - -- - - - - - - - - - - level 4
Solution: We know that any eigen vector of a matrix P is R: Set of functions from N to { 0,1}
1
a multiple of ⋅
In a function from N to {0, 1},
4 Every element of N is mapped to 0 or 1
1 So, the number of ways of mapping any element of
As every eigen vector of P is a multiple of , N is 2.
4
∴ The number or elements in the set of functions
P has only one linearly independent eigen vector
from N to {0,1}
As P is a 2 × 2 matrix, if the two eigen values of P are
= The number of elements in the power set of N
distinct, then P should have two linearly independent eigen
vectors. But the power set of N is uncountable because the
power set of a infinite countable set is uncountable.
So, P has a repeated eigen value
So R is uncountable.
Hence (II) is correct.
S: Set of finite subsets of N.
A 2 × 2 matrix is diagonalizable if and only if it has two As we are considering only the finite subsets of N,
linearly independent eigen vectors. S is a countably infinite set.
But P has only one linearly independent eigen vector. So only P, Q and S are countable.
Hence P is not diagonalizable. Hence, the correct option is (D).
So (III) is correct.
Question Number: 38 Question Type: MCQ
P need not be a singular matrix.
Consider the first-order logic sentence
So, (I) is not correct.
φ = ∃ s ∃ t ∃ u ∀ v ∀ w ∀ x ∀ y ψ ( s, t , u , v , w , x , y )
∴ Only (II) and (III) are necessarily correct.
where ψ ( s, t , u, v, w , x, y ) is a quantifier-free first-order
Hence, the correct option is (D). logic formula using only predicate symbols, and possibly
Question Number: 37 Question Type: MCQ equality, but no function symbols. Suppose ϕ has a model
Let N be the set of natural numbers. Consider the follow- with a universe containing 7 elements.
ing sets. Which one of the following statements is necessarily true?
P: Set of Rational numbers (positive and negative) (A) There exists at least one model of ϕ with universe
of size less than or equal to 3.
Q: Set of functions from {0,1} to N (B) There exists no model of ϕ with universe of size
R: Set of functions from N to {0,1} less than or equal to 3.
S: Set of finite subsets of N. (C) There exists no model of ϕ with universe of size
Which of the sets above are countable? greater than 7.
(A) Q and S only (B) P and S only (D) Every model of ϕ has a universe of size equal to 7.
(C) P and R only (D) P, Q and S only Solution:
Solution: We know that the set of rational numbers is Hence, the correct option is (A).
countable. So P is countable Question Number: 39 Question Type: MCQ
Q: set of functions from {0, 1} to N. Consider the following C program:
As 0 can be mapped to a number in N ways and 1
can be mapped to a number in N ways, #include<stdio.h>
void fun1 (char *s1, char * s2) {
The number of elements in the set of functions
from {0, 1} to N char *tmp;
tmp = s1;
= The number of elements in the cartesian product
s1 = s2
N×N
s2 = tmp;
We know that the cartesian product of two count-
}
able sets is countable.
void fun2 (char **s1, char **s2) {
As N is countable, N × N is countable char *tmp;
So Q is countable. tmp = *s1;
The value returned when we call fun with the input 240 is Then size of the block = (2M+W) B (2M words ×
(A) 4 (B) 5 2W bytes/word)
(C) 6 (D) 40 N–M–W
Number of lines =2
Solution: For input 240, j get incremented to ‘40’ Number of Cache memory
Number of sets =
j = 40 j = 20 j = 10 j=5 j=2 P -way
sum=1 sum=2 sum=3 sum=4 sum=5
2 N − M −W
=
Hence, the correct option is (B). log2 K
Question Number: 43 Question Type: MCQ ∴ The Tage size will be
Consider the unsigned 8-bit fixed point binary number rep- = P – (M + W – log2k + M + W)
resentation below,
= P – N + log2K.
b7 b6 b5 b4 b3 ⋅ b2 b1 b0
Hence, the correct option is (B).
Where the position of the binary point is between b3 and b2.
Assume b7 is the most significant bit. Some of the decimal Question Number: 45 Question Type: MCQ
numbers listed below cannot be represented exactly in the Consider the following languages:
above representation:
(i) 31.500 (ii) 0.875 I. {ambncpdq | m + p = n + q, where m, n, p, q ≥ 0}
(iii) 12.100 (iv) 3.001 II. {ambncpdq | m = n and p = q, where m, n, p, q ≥ 0}
III. {ambncpdq | m = n = p and p ≠ q, where m, n, p,
Which one of the following statements is true? q ≥ 0}
(A) None of (i), (ii), (iii), (iv) can be exactly repre- IV. {ambncpdq | mn = p + q, where m, n, p, q ≥ 0}
sented
(B) Only (ii) cannot be exactly represented Which of the languages above are context-free?
(C) Only (iii) and (iv) cannot be exactly represented (A) I and IV only (B) I and II only
(D) Only (i) and (ii) cannot be exactly represented (C) II and III only (D) II and IV only
Solution: Solution:
(31.500)10 = (11111.100)2 I. {am bn cp dq | m + p = n + q}
(0.875)10 = (00000.111)2 The given language is context free language, as
it can be implemented by using stack
(12.100)10 = (01100.000110011…..)2
II. {am bn cp dq | m = n and p = q}
(3.001)10 = (00011.0000000001….)2
The given language is CFL, as it can be imple-
Fraction part in the given representation is of only 3 - bits, mented by using stack.
(iii) and (iv) can’t be represented accurately due to lack of
Hence, the correct option is (B).
storage.
Hence, the correct option is (C). Question Number: 46 Question Type: MCQ
Consider the following problems. L(G) denotes the lan-
Question Number: 44 Question Type: MCQ
guage generated by a grammer G. L(M) denotes the lan-
The size of the physical address space of a processor is 2P guage accepted by a machine M.
bytes. The word length is 2W bytes. The capacity of cache (I) For an unrestricted grammer G and a string w,
memory is 2N bytes. The size of each cache block is 2M whether w ∈L(G)
words. For a K-way set-associative cache memory, the (II) Given a Turing machine M, whether L(M) is
length (in number of bits) of the tag field is regular
(A) P – N – log2K (III) Given two grammars G1 and G2, whether L(G1) =
(B) P – N + log2K L(G2)
(C) P – N – M – W – log2K (IV) Given and NFA N, whether there is a determin-
(D) P – N – M – W + log2K istic PDA P such that N and P accept the same
Solution: Given main memory space = 2M bytes language.
Physical address size = ‘P’ bits Which one of the following statements is correct?
(A) Only I and II are undecidable
Cache memory size = 2N bytes
(B) Only III is undecidable
(C) Only II and IV are undecidable (C) $ has higher precedence and is left associative; #
(D) Only I, II and III are undecidable is left associative
(D) # has higher precedence and is right associative; $
Solution:
is left associative
I. Membership problem of unrestricted grammar
(i.e. REL) is undecidable as there is a possibility Solution:
of entering into infinite loop.
#
II. Every regular language is REL, but REL may or
may not be regular. (undecidable) a #
III. As the type of grammar is not given, the equiva-
lence problem is undecidable in REL. $ #
IV. Every regular language is Deterministic CFL.
(decidable) $ d e f
Hence, the correct option is (D)
b c
Question Number: 47 Question Type: MCQ
A lexical analyzer uses the following patterns to recognize The operator which appears at lower level of tree has higher
three tokens T1, T2, and T3 over the alphabet {a, b, c}. precedence. Therefore ‘$’ has higher precedence.
T1: a?(b|c)*a # operator is right associative, as right subtree is extended.
T2: b?(a|c)*b Hence, the correct option is (A).
T3: c?(b|a)*c Question Number: 49 Question Type: MCQ
Note that ‘x?’ means 0 or 1 occurrence of the symbol x. In a system, there are three types of resources: E, F and
Note also that the analyzer outputs the token that matches G. Four processes P0, P1, P2 and P3 execute concurrently.
the longest possible prefix. At the outset, the processes have declared their maximum
If the string bbaacabc is processed by the analyzer, which resource requirements using a matrix named Max as given
one of the following is the sequence of tokens it outputs? below. For example, Max[P2,F] is the maximum number
(A) T1T2T3 (B) T1T1T3 of instances of F that P2 would require. The number of
(C) T2T1T3 (D) T3T3 instances of the resources allocated to the various processes
at any given state is given by a matrix named Allocation.
Solution: Given string is given below
Consider a state of the system with the Allocation matrix as
bbaacabc shown below, and in which 3 instances of E and 3 instances
The longest possible prefix will be bbaac that can be of F are the only resources available.
obtained from T3. a b c is the another possible prefix
Allocation Max
obtained from T3.
E F G E F G
bbaac abc P0 1 0 1 P0 4 3 1
↓ ↓ P1 1 1 2 P1 2 1 4
T3 T3 P2 1 0 3 P2 1 3 3
P3 2 0 0 P3 5 4 1
Hence, the correct option is (D).
Question Number: 48 Question Type: MCQ From the perspective of deadlock avoidance, which one of
Consider the following parse tree for the expression the following is true?
a#b$c$d#e#f, involving two binary operators $ and #. (A) The system is in safe state.
(B) The system is not in safe state, but would be safe
Which one of the following is correct for the given parse
if one more instance of E were available
tree?
(C) The system is not in safe state, but would be safe
(A) $ has higher precedence and is left associative; #
if one more instance of F were available
is right associative
(D) The system is not in safe state, but would be safe
(B) # has higher precedence and is left associative; $
if one more instance of G were available
is right associative
Solution:
Max Allocation Need Available
E F G E F G E F G E(3) F(3) G(0)
P0 4 3 1 1 0 1 3 3 0 3 3 0 (On ‘P1’ execution)
↓ ↓ ↓
P1 2 1 4 1 1 2 1 0 2 4 3 1 (On ‘P2’ execution)
↓ ↓ ↓
P2 1 3 3 1 0 3 0 3 0 5 3 4 (On ‘P1’ execution)
↓ ↓ ↓
P3 5 4 1 2 0 0 3 4 1 6 4 6 (On ‘P3’ execution)
↓ ↓ ↓
8 4 6
The system is in safe state, with safe sequence P0, P2, P1, When producer places an item in buffer, it implies there
P3. is increase in the number of available slots in the buffer,
Hence, the correct option is (A). for the consumer to read from. This can be done by signal
(empty). So, Q:empty
Question Number: 50 Question Type: MCQ
Similarly, consumer has to wait when there are no items to
Consider the following solution to the producer-consumer consume in buffer, which can be shown by wait (empty).
synchronization problem. The shared buffer size is N. So, R: empty
Three semaphores empty, full and mutex are defined with
Once the consumer consumes item, it implies, there is
respective initial values of 0, N and 1. Semaphore empty
increase in-the available slots in the buffer, for the producer
denotes the number of available slots in the buffer, for the
to write to. So, S:full
consumer to read from. Semaphore full denotes the num-
ber of available slots in the buffer, for the producer to write Hence, the correct option is (C).
to. The placeholder variables, denoted by P, Q, R, and S, in Question Number: 51 Question Type: MCQ
the code below can be assigned either empty or full. The
valid semaphore operations are: wait () and signal (). Consider the relations r(A, B) and s(B, C), where s ⋅ B is
a primary key and r ⋅ B is a foreign key referencing s ⋅ B.
Producer Consumer Consider the query
do { do { Q: r (σB<5(S))
wait(P); wait(R); Let LOJ denote the natural left outer-join operation.
wait (mutex); wait (mutex); Assume that r and s contain no null values.
//Add item to //Consume item
Which one of the following queries is NOT equivalent
buffer from buffer
to Q?
signal (mutex); signal (mutex); (A) σB<5(r s)
signal (Q); signal (S);
(B) σB<5(r LOJ s)
} while (1); } while (1);
(C) r LOJ (σB<5(s))
Which one of the following assignments to P, Q, R and S (D) σB<5(r) LOJ s
will yield the correct solution? Solution: Consider a data set
(A) P: full, Q: full, R: empty, S: empty
(B) P: empty, Q: empty, R: full, S: full r A B s B C
(C) P: full, Q: empty, R: empty, S: full 12 2 2 A
(D) P: empty, Q: full, R: full, S: empty 13 6 3 B
Solution: In the producer - consumer problem, producer 15 4 4 C
keeps the item in buffer when the slots on the buffer are 12 6 5 A
empty. While, it has to wait when the buffer is full. In the 13 4 6 C
given problem, full denotes number of available slots in 16 7
buffer, i.e. full will be 0, when there are no empty slots in
buffer. So P: full.
A B
12 2
15 4 LOJS
GATE
13 2018 Solved
4 Paper CSIT: Set – I | xii-o
Q: x (σB<5 (s)) A B C
A B C 12 2 A
12 2 A 15 4 C
15 4 C 13 4 C
A B C
12 2 A
15 4 C
13 4 C
Question Number: 53 Question Type: NAT Consider the first row in the table above. The first entry
Let G be a graph with 100! vertices, with each vertex denotes that if Guwahati has high temperature (HG) then
labeled by a distinct permutation of the numbers 1, 2, …, the probability of Delhi also having a high temperature
100. There is an edge between vertices u and v if and only (HD) is 0.40; i.e., P(HD|HG) = 0.40. Similarly, the next two
if the label of u can be obtained by swapping two adjacent entries are
numbers in the label of v. Let y denote the degree of a ver- P(MD|HG) = 0.48 and P(LD|HG) = 0.12.
tex in G, and z denote the number of connected compo- Similarly for the other rows.
nents in G.
If it is known that P(HG) = 0.2, P(MG) = 0.5, and P(LG) =
Then, y + 10z = ________. 0.3, then the probability (correct to two decimal places)
Solution: As the label of a vertex in the graph G is a per- that Guwahati has high temperature given that Delhi has
mutation of the numbers 1,2,3,….,100 and two vertices u high temperature is ________.
and v of G are adjacent if and only if the label of one vertex Solution: Probability that Guwahati has high temperature
can be obtained from the other by swapping two adjacent given that Delhi has high temperature
numbers,
P ( H G ) P ( H D /H G )
If the label of a vertex u of G is 1,2,3,….,100 P(HG/HD) =
P ( H G ) P ( H D /H G ) + P ( M G ) P ( H D /M G )
deg(u) = Number of ways of swapping two adjacent + P ( LG ) P ( H D /LG )
numbers in 1,2,3,…,100 = 99
Similarly, we can observe that every vertex will have the (By Baye’s theorem)
same degree. Substituting these in the above, we have
∴ y = 99 0.2 × 0.40
P(HG/HD) =
Also, from any permutation consisting of the numbers 0.2 × 0.40 + 0.5 × 0.1 + 0.3 × 0.01
1,2,3,…,and 100, we can obtain any other permutation of
= 0.601
the 100! permutations of 1,2,3,….,100 by a finite number
of swaps with swapping two adjacent numbers at a time. Hence, the correct answer is 0.60 to 0.62.
This means there exists a path from any vertex of G to any Question Number: 55 Question Type: NAT
other vertex of G.
Consider the following program written in pseudo-code.
So G is a connected graph. Assume that x and y are integers.
Hence, the number of connected components in Count (x,y) {
G=z=1 if (y ! = 1) {
So, y + 10z = 99 + 10 × 1 = 109. if (x ! = 1) {
Hence, the correct answer is 109. print (“*”);
Count (x/2, y);
Question Number: 54 Question Type: NAT
}
Consider Guwahati (G) and Delhi (D) whose temperatures else {
can be classified as high (H), medium (M) and low (L). y = y–1;
Let P(HG) denote the probability that Guwahati has high
temperature. Similarly, P(MG) and P(LG) denotes the prob- Count (1024, y);
ability of Guwahati having medium and low temperatures }
respectively. Similarly, we use P(HD), P(MD) and P(LD) for }
Delhi.
}
The following table gives the conditional probabilities for
Delhi’s temperature given Guwahati’s temperature. The number of times that the print statement is executed by
the call count (1024, 1024) is _______.
HD MD LD
HG 0.40 0.48 0.12 Solution: The number of times that the print statement is
executed = (1023 * 10)
MG 0.10 0.65 0.25
LG 0.01 0.50 0.49 = 10230
Hence, the correct answer is 10230.
=2–1+2=3 Choose a value for x that will maximize the number of min-
R = 21 – 1 + max (0, 4 – 21) imum weight spanning trees (MWSTs) of G. The number
=2–1+2=3 of MWSTs of G for this value of x is ________.
2
f (3) = C1 × f (1) × f (1) = 2 × 1 × 1 = 2
Solution: Consider Kruskal’s algorithm to find Minimum Weight Spanning Tree (MWST).
6! 6 × 5 × 4 × 3!
=
(7) edges
Arrangef the in×ascending
2 × 2 = order 1, 3, 4,×4,2 4,
× 25, ssx
3! 3! 3 × 2 × 3!
= 80.
4
1 1 3 3
1
1 2
1 3 4
4 3 1 3
1 4 5
5
If x = 5
3 4
5 5
4
3 1 3
1 4
4
if x < = 4, then vertex with weight ‘4’ will be considered every time, and If x > 5, then vertex with weight ‘5’ will be con-
sidered everytime - which gives total of 2-spanning trees. When x = 5, there will be two choices, which gives total of 4
spanning trees.
Hence, the correct answer is 4.
= 24 + 20 I
Question Number: 60 Question Type: NAT Floating point register requires 6 bits
The instruction pipeline of a RISC processor has the fol- • Both Type1 and Type2 opcode sizes will be 4-bits in
lowing stages: Instruction Fetch (IF), Instruction Decode which max number of instructions to be formulated
(ID), Operand Fetch (OF), Perform Operation (PO) and are 16, but it uses 12 instructions out of 16, other 4
Writeback (WB). The IF, ID, OF and WB stages take 1 combinations are reserved for tpe-3.
clock cycle each for every instruction. Consider a sequence • Similarly for Type-3, Number of instruction produced
of 100 instructions. In the PO stage, 40 instructions take are maximum 16 bit instructions, it uses 14 instruc-
3 clock cycles each, 35 instructions take 2 clock cycles tions out of 16.
each, and the remaining 25 instructions take 1 clock cycle
from 110000 to 111101
each. Assume that there are no data hazards and no control
hazards. and
The number of clock cycles required for completion of 111110 and 111111 are combinations used for Type-4
execution of the sequence of instructions is ________. instructions.
Type-4:
Solution: From the given question, there are three types of
questions, based on number cycles required by PO stage, 111110 Floating
----
and remaining stages in instruction takes one cycle each. 111111 register
4-free 6
Number of Number of Number Bits
instructions cycles of cycles
required by required for For each, there will be free combination of first 6-bit
PO stage Instruction opcode and 4-bits are used for Type-4 instructions.
execution
Type 1 40 3 7
∴ Maximum number of instructions to be formed = 2 ×
24 = 32
Type 2 35 2 6
Type 3 25 1 5
Hence, the correct answer is 32.
Question Number: 62 Question Type: NAT
Type 1 instruction executions ends on 124th cycle. Given a language L, define Li as follows:
Similarly, Type 2 Instruction execution ends on 194th cycle L0 = {ε}
and Type 3 Instructions execution ends on 219th cycle.
Li = Li – 1 . L for all i > 0
In other words, Number of clock cycles required are
The order of a language L is defined as the smallest k such
= 1 + 1 + 1 +[(40 × 3) + (35 × 2) + (25 × 1)] + 1 that Lk = Lk + 1. Consider the language L1 (over alphabet 0)
= 219 accepted by the following automaton.
Hence, the correct answer is 219. 0
Question Number: 63 Question Type: NAT The fragmentation offset value stored in the third fragment
Consider a storage disk with 4 platters (numbered as 0, 1, is _________ .
2 and 3), 200 cylinders (numbered as 0, 1, ….., 199), and Solution: Data packet length = 4.500B
256 sectors per track (numbered as 0, 1, …., 255). The fol-
TCP header = 40 bytes
lowing 6 disk requests of the form [sector number, cylinder
number, platter number] are received by the disk controller IP header = 20 bites
at the same time: Given maximum transmission unit of 600 Bytes
[120, 72, 2], [180, 134, 1], [60, 20, 0], [212, 86, 3], [56, Data packet will be
116, 2], [118, 16, 1] Data Header
Currently the head is positioned at sector number 100 of 580 20
cylinder 80, and is moving towards higher cylinder num-
bers.The average power dissipation in moving the head The fragmented Bytes and its offset are
over 100 cylinders is 20 milliwatts and for reversing the
1st fragment 2nd fragment 3rd fragment
direction of the head movement once is 15 milliwatts.
576 576 576
Power dissipation associated with rotational latency and
switching of head between different platters is negligible. + + +
20 20 20
The total power consumption in milliwatts to satisfy all of
the above disk requests using the Shortest Seek Time First Fragment offset 0 72 144
disk scheduling algorithm is _________.
Hence, the correct answer is 144.
Solution: Disk requests in cylinders are 72, 134, 2.0, 8.6,
116, 16 currently it is at 80. Question Number: 65 Question Type: NAT
Consider a simple communication system where multiple
16 20 72 80 86 116 134
nodes are connected by a shared broadcast medium (like
Ethernet or wireless). The nodes in the system use the
following carrier-sense based medium access protocol. A
node that receives a packet to transmit will carrier-sense
the medium for 5 units of time. If the node does not detect
any other transmission in this duration, it starts transmit-
ting its packet in the next time unit. If the node detects
another transmission, it waits until this other transmission
finishes, and then begins to carrier-sense for 5 time units
Number of head movements again. Once they start to transmit, nodes do not perform
= |86 – 80| + |72 – 86| + |116 – 72| +|134 – 116| any collision detection and continue transmission even if a
+ |20 – 134| + |20 – 16| collision occurs. All transmissions last for 20 units of time.
= 200 Assume that the transmission signal travels at the speed of
Average power dissipation for 200 cylinders = 40 milliwatt 10 meters per unit time in the medium.
and there are 3 reversals of head movement direction which Assume that the system has two nodes P and Q, located
takes 45 milliwatt. at a distance d meters from each other. P starts transmit-
Total power consumption ting a packet at time t = 0 after successfully completing
its carrier-sense phase. Node Q has a packet to transmit at
= 40 + 45 85 milliwatt. time t = 0 and begins to carrier-sense medium.
Hence, the correct answer is 85. The maximum distance d (in meters, rounded to the clos-
Question Number: 64 Question Type: NAT est integer) that allows Q to successfully avoid a collision
Consider an IP packet with a length of 4,500 bytes that between its proposed transmission and P’s ongoing trans-
includes a 20-byte IPv4 header and a 40-byte TCP header. mission is ________.
The packet is forwarded to an IPv4 router that supports a Solution: Given channel sensing time = 5 units time.
Maximum Transmission Unit (MTU) of 600 bytes. Assume As a packet travel time = 10 meters/sec
that the length of the IP header in all the outgoing frag-
ments of this packet is 20 bytes. Assume that the fragmen- For avoiding collision for Q, the distance should be 50 meters.
tation offset value stored in the first fragment is 0. Hence, the correct answer is 50.
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15
Question 1 to Question 5 carry 1 mark each and Question Number: 4 Question Type: MCQ
Question 6 to Question 10 carry 2 marks each. Research in the workplace reveals that people work for
Question Number: 1 Question Type: MCQ many reason _________.
Rahul Murali, Srinivas, and Arul are seated around (A) money beside (B) beside money
a square table. Rahul is sitting to the left of Murali. (C) money besides (D) besides money
Srinivas is sitting to the right of Arul. Which of the fol- Solution: Hence, the correct option is (C).
lowing pairs are seated opposite each other?
Question Number: 5 Question Type: MCQ
(A) Rahul and Murali (B) Srinivas and Arul
After Rajendra Chola returned from his voyage to
(C) Srinivas and Murali (D) Srinivas and Rahul Indonesia, he _____ to visit the temple in Thanjavur.
Solution: Hence, the correct option is (C). (A) was wishing (B) is wishing
Question Number: 2 Question Type: MCQ (C) wished (D) had wished
Find the smallest number y such that y × 162 is a per- Solution: Hence, the correct option is (C).
fect cube. Question Number: 6 Question Type: MCQ
(A) 24 (B) 27 (C) 32 (D) 36 Six people are seated around a circular table. There are
Solution: Factorization of 162 is 2 × 3 × 3 × 3 × 3 y × at least two men and two women. There are at least three
162 is a perfect cube right-handed persons. Every woman has a left-handed
person to her immediate right. None of the women are
y × 2 × 3 × 3 × 3 × 3 = Perfect cube
right-handed. The number of women at the table is
For perfect cube 2’s & 3’s are two more required each.
(A) 2 (B) 3
Hence, the correct option is (D).
(C) 4 (D) Cannot be
Question Number: 3 Question Type: MCQ determined
The probability that a k-digit number does NOT con- Solution: Out of six people, 3 place definitely occu-
tain the digits 0, 5, or 9 is pied by right handed people as atleast 2 women are there
so these two will sit adjacently. Now, as only one seat
(A) 0.3k (B) 0.6k (C) 0.7k (D) 0.9k
is left it will be occupied by a left-handed man because
Solution: on right side of this seat is sitting a right-handed man.
R (m)
R (m)
R (m)
k digits
Question Number: 7 Question Type: MCQ At floods, the water level is 525 m. So, the village of R,
Arun, Gulab, Neel, and Shweta must choose one shirt S, and T are under a contour of 500. Therefore, these
each from a pile of four shirts coloured red, pink, blue, villages are submerged.
and white, respectively. Arun dislikes the colour red Hence, the correct option is (C).
and Shweta dislikes the colour white. Gulab and Neel
Question Number: 9 Question Type: MCQ
like all the colours. In how many different ways can
they choose the shirts, so that, no one has a shirt with a 9. “The hold of the nationalist imagination on our
colour he or she dislikes? colonial past is such that anything inadequately or
improperly nationalist is just not history”. Which of the
(A) 21 (B) 18 (C) 16 (D) 14
following statements best reflects the author’s opinion?
Solution: As there are 4 people A, G, N, S and 4 (A) Nationalists are highly imaginative.
colours, so without any restriction total ways have to (B) History is viewed through the filter
be 4 × 4 = 16. of nationalism.
Now, Arun → dislikes Red and (C) Our colonial past never happened.
Shweta → dislikes white. (D) Nationalism has to be both adequately
So, 16 – 2 = 14 ways. and properly imagined.
Hence, the correct option is (D). Solution: Hence, the correct option is (B).
Question Number: 8 Question Type: MCQ Question Number: 10 Question Type: MCQ
A contour line joins locations having the same height ( x + y) − x − y
above the mean sea level. The following is a contour plot The expression is equal to
2
of a geographical region. Contour lines are shown at 25
(A) the maximum of x and y
m intervals in this plot. If in a flood, the water level rises
to 525 m, which of villages P, Q, R, S, T get submerged? (B) the minimum of x and y
(A) P, Q (B) P, Q, T (C) 1
(C) R, S, T (D) Q, R, S (D) None of the above
Solution: If x > y; then |x – y| = x – y
425 Q
R x + y − ( x − y)
450 550 Exp = = ymin
2
If x < y; then |x – y| = –(x – y) = y – x
P
550 x + y − ( y − x)
Exp = = xmin
T 2
500
450 ( x + y) − x − y
500 S The expression Exp = is equal to min-
2
Solution: The given contour is a hill station, the peak imum of x and y.
point of this hill station is P, it is under a contour of 550. Hence, the correct option is (B).
Client* Server*
* or vice-versa, though requests typically originate at clients.
5 Established 5 Established
The connection is open. Received acknowledgement. 2
Data moves both directions. The connection is open.
Data moves both directions.
7 Fin − wait. 2
Received acknowledgement.a
Still awaiting close − request.b 9 Last − Ack
or Sant close − request.b
10 closing Awaiting acknowledgement.b
Received Close − request.b
Sent acknowledgement.b
Still awating acknowledgement.a
11 Time − wait
Received acknowledgement.a
Received close − request.b
Sant acknowledgement.b
Allowing time for delivery
of acknowledgement.b
1 closed 2 Listening
Question Number: 12 Question Type: MCQ Question Number: 14 Question Type: MCQ
Consider the following context-free grammar over the When two 8-bit numbers A7 . . . . A0 and B7 . . . . B0 in 2’s
alphabet = {a, b, c} with S as the start symbol. complement representation (with A0 and B0 as the least
S → abScT |abcT significant bits ) are added using a ripple-carry adder,
the sum bits obtained are S7 . . . . S0 and the carry bits
T → bT|b are C7….C0. An overflow is said to have occurred if
Which one of the following represents the language gen- (A) the carry bit C7 is 1.
erated by the above grammar? (B) all the carry bits (C7….C0) are 1.
(A) {(ab)n (cb)n |n ≥ 1} (C) ( A 7 B7 S7 + A 7 B7S7 ) is 1.
(B) {(ab)n cbm1 cbm2 … cbm2 |n, m1, m2,…, mn ≥ 1} ( A 0 B0 S0 + A 0 B0 S0 ) is 1.
(D)
(C) {(ab)n (cbm)n |m, n ≥ 1}
Solution: Overflow flag indicates an overflow condi-
(D) {(ab)n (cbn)m |m, n ≥ 1}
tion for a signed operation. Some points to remember
Solution: The given grammar over Σ = {a, b, c} with in a signed operation:
S as the start symbol is • MSB is always reserved to indicate sign of the number.
S → abScT | abcT • Negative numbers are represented in 2’s – complement.
T → bT | b • An overflow results in invalid operation.
The minimum length string generated by the grammar 2’s complement overflow rules:
is 1.
• If the sum of two positive numbers yields a negative
S → abcT → abcb; hence, all variable greater than 1. result, the sum has overflowed.
Other cases • If the sum of two negative number yields a positive
S → abScT → ab abScT cT → ab ab abScTcTcT → result, the sum has overflowed.
. ......→ (ab)n (cT)n . • Otherwise, the sum has not overflowed.
Here, T can generate any number of b’s starting with
single b. Overflow for signed numbers occurs when the carry-
in into the MSB (most significant bit) is not equal to
Hence, the language is L = {(ab)n cbm1 cbm2 cbm3 carry-out. Conveniently, an XOR-operation on these
cbm4 ,. . ., cbmn | m1, m2, m3, m4…mn n ≥ 1} two bits can quickly determine if an overflow condition
Hence, the correct option is (B). exists.
Therefore, (( A 7 B7 )) ⊕ S7 = A 7 B7S7 + A 7 B7S7 = 1) has
Question Number: 13 Question Type: MCQ overflowed
Consider the first-order logic sentence F:∀z($yR(x, y)).
Hence, the correct option is (C).
Assuming non-empty logical domains, which of the
sentences below are implied by F? Question Number: 15 Question Type: NAT
I. $y($xR(x, y)) II. $y(∀xR(x, y)) Consider a database that has the relation schema EMP
III. ∀y(xR(x, y)) IV. ¬$x(∀y¬R(x, y)) (EmpId, EmpName, and DeptName). An instance of
the schema EMP and a SQL query on it are given in
(A) IV only (B) I and IV only
the table.
(C) II only (D) II and III only
EMP
Solution: ∀x($yR (x, y)) ⇒$y$xR(x, y) EmpId EmpName DeptName
$y∀xR (x, y) ⇒∀x$yR(x, y) 1. XYA AA
∀x$yR(x, y) ⇒$y∀xR (x, y) 2. XYB AA
¬$x(∀y¬R (x, y)) ⇔ ∀x$yR(x, y) 3. XYC AA
4. XYD AA
Hence, the correct option is (B).
EMP V → W
(A) (B) V → W
EmpId EmpName DeptName V → X W → X
5. XYE AB Y → V Y → V
6. XYF AB Y → Z Y → Z
7. XYG AB V → W, (D)
(C) V→W
8. XYH AC
W → X W → X
9. XYI AC
Y → V Y → V
10 XYJ AC
Y → X Y → X
11. XYK AD
Y → Z Y → Z
12. XYL AD
13. XYM AE Solution:
V → W, VW → X, Y → V, Y → X, Y → Z
SELECT AVG(EC.Num) FROM EC
(W is extraneous)
WHERE(DeptName, Num)IN
V → W, V → X, Y → V, Y → X, Y → Z
(SELECTDeptName, COUNT(EmpId)AS
\ Y → X is redundant
EC(DeptName, Num)
FROMEMP \ {V → W, V → X, Y → V, Y → Z}
GROUP BYDeptName) Hence, the correct option is (A).
The output of executing the SQL query is ___________. Question Number: 17 Question Type: MCQ
Solution: Consider the following functions from positive integers
EC to real numbers:
Dept Name Num 100
10, n , n, log 2 n,
AA 4 n
AB 3 The CORRECT arrangement of the above functions in
AC 3 increasing order of asymptotic complexity is:
AD 2 100
(A)
log 2 n, 10, n , n,
AE 1 n
13 100
=
Avg (NUM) = 2.6 (B) ,10, log 2 n, n , n,
5 n
Hence, the correct answer is (2.6). 100
10,
(C) , n , log 2 n, n,
Question Number: 16 Question Type: MCQ n
The following functional dependencies hold true for 100
the relational schema R{V, W, X, Y, Z}: (D) , log 2 n, 10, n , n,
n
V→W 100
Solution: < 10 < log 2 n n , n
VW → X n
Y → VX Hence, the correct option is (B).
Y→Z
Question Number: 18 Question Type: NAT
Which of the following is irreducible equivalent for Let T be a tree with 10 vertices. The sum of the degrees
this set of functional dependencies? of all the vertices in T is ____________.
Assume for all inputs (a, b, c, d) the respective comple- R. Floyd-Warshall iii. Dynamic Programming
ments ( a , b , c , d ) are also available. The above logic is Match the algorithms to the design paradigms they are
implemented 2-input NOR gates only. The minimum based on.
number of gates required is ____________.
(A) P-(ii), Q-(iii), R-(i)
Solution: (B) P-(iii), Q-(i), R-(ii)
ba (C) P-(ii), Q-(i), R-(iii)
dc (D) P-(i), Q-(ii), R-(iii)
00 01 11 10
signature and he can decrypt the signature by his own per instruction on average. For this application, the
public key and gets the hash value. With that same hash miss rate of L1 cache 0.1, the L2 cache experiences,
value, he can create another message and can be sent on average, 7 misses per 1000 instructions. The miss
instead of original. rate of L2 expressed correct to two decimal places is
Hence, the correct option is (B). ___________.
Solution:
Question Number: 26 Question Type: MCQ
Consider the following grammar. Number of memory access
= 1.4 × 1000 = 1, 400
P → xQRS in 1000 instructions
Q → yz z 7
Miss Rate = = 0.05
R→w∈ 1400 × 0.1
S→y Hence, the correct answer is (0.05).
What is FOLLOW (Q) ? Question Number: 29 Question Type: NAT
(A) {R} (B) {w} Consider the following CPU processes with arrival
times (in milliseconds) and length of CPU burst (in
(C) {w, y} (D) {w, $}
milliseconds) as given in the table:
Solution: FOLLOW(Q) is FIRST(R)
Process Arrival Time Burst Time
Hence, FIRST(R) = {w, ∈}
P1 0 7
We add ‘w’ in FOLLOW(Q) and for ∈, we calculate P2 3 3
FIRST(S)
P3 5 5
FIRST(S) = {y}
P4 6 2
FOLLOW(Q) is {w, y},
Hence, the correct option is (C). If the pre-emptive shortest remaining time first sched-
uling algorithm is used to schedule the processes,
Question Number: 27 Question Type: NAT then the average waiting time across all processes is
Consider the language L given by the regular expression __________ milliseconds.
(a + b) * b(a + b) over the alphabet {a, b}. The smallest
Solution:
number of states needed in a deterministic finite-state
automation (DFA) accepting L is __________. PID AT BT CT TAT WT
P1 0 7 12 12 5
Solution: The regular expression can be described as
P2 3 3 6 3 0
“All strings over {a, b} ending with “ba” or “bb”.
P3 5 5 17 12 7
The minimal DFA accepting L is having 4 states:
P4 6 2 8 2 0
a b
Gantt chart:
b b P1 P2 P2 P4 P1 P3
0 3 5 6 8 12 17
a a
P1 P1–4 P1–4 P1–4 P1–4 P3–5
P2–3 P2–1 P3–5 P3–5
b
P3–5 P4–2
a
P1 P2 P4 P1 P3
0 3 6 8 17
Hence, the correct answer is (4).
Question Number: 28 Question Type: NAT 5 + 0 + 7 + 0 12
Average waiting time = = = 3 ms
Consider a two-level cache hierarchy with L1 and L2 4 4
caches. An application incurs 1.4 memory accesses Hence, the correct answer is (3).
∑c a
i =1
i i = 0 where ai are column vectors in R . Consider
n pointer “p” to the last node of the list “n”. And at the
last statement, we are initializing the next of the last
the set of linear equations Ax = b node of list n to start of list “m”.
where n But in some cases it may dereference to null pointer.
A = [a1. . . an] and b = ∑ ai . Hence, the correct option is (B).
i =1
The set of equations has
Question Number: 33 Question Type: MCQ
(A) a unique solution at x = Jn where Jn denotes a
The n-bit fixed-point representation of an unsigned real
n-dimensional vector of all 1
number real X uses f bits for the fraction part. Let i =
(B) no solution n – f. The range of decimal values for X in this repre-
(C) infinitely many solutions sentation is
(D) finitely many solutions (A) 2–f to 2i (B) 2–f to (2i – 2–f)
Solution: Since the scalars are not all zero (C) 0 to 2i (D) 0 to (2i – 2–f)
\ The column vectors a for i = 1, 2,..., n are linearly i = n – f·f
i
dependent
Solution:
⇒
n
A = 0 and b = ∑ ai ⇒Ax = b has infinitely manyMax value = 111.....1(i times).111........1(f times)
solutions.
i =1
1 1 1 2 f −1
Ax = b has infinitely many solutions. = 2i − 1 + + 2 +…+ f = 2i − 1 + f = 2i − 2− f
2 2 2 2
Hence, the correct option is (C).
\ 0 to (2i – 2f)
Question Number: 32 Question Type: MCQ
Hence, the correct option is (D).
Consider the C code fragment given below.
typedef struct node { Question Number: 34 Question Type: MCQ
int data; Consider the following intermediate program in three
node* next ; address code
} node; p=a-b
void join (node* m, node* n){ q=p*c
node* p=n ; p=u*v
while (p->next ! =NULL){ q=p+q
p = p –> next ; Which one of the following corresponds to a static sin-
} gle assignment form of the above code
p1 = a - b (B)
(A) p3 = a - b (A) (I) only
q1 = p1 * c q4 = p3 * c (B) (II) only
p1 = u * v p4 = u * v (C) Both (I) and (II)
q1 = p1 + q1 q 5 = p4 + q4 (D) Neither (I) nor (II)
p1 = a - b
(C) (D) p1= a - b Solution:
q1 = p2 * c q1 = p* c
A 1 B
p3 = u * v p2 = u * v
q2 = p4 + q3 q2=p+q
2 3 5
Solution:
(A) code violates condition for static single as- C 4 D
signment since p1 is initialized twice
(C) p2, p4, and q3 are not initialized anywhere Shortest path from B to C are two B-A-C and B-C both
(D) q2 = p + q is incorrect code of weight “3”
Hence, the correct option is (B). Hence, the correct option is (A).
Question Number: 35 Question Type: MCQ Question Number: 37 Question Type: MCQ
Consider the C struct defined below: A multithreaded program P executes with x number
struct data { of threads and uses y number of locks for ensuring
mutual exclusion while operating on shared memory
int marks [100] ;
locations. All locks in the program are non-reentrant,
char grade; i.e., if a thread holds a lock l, then it cannot re-acquire
int cnumber; lock l without releasing it. If a thread is unable to
}; acquire a lock, it blocks until the lock becomes avail-
struct data student; able. The minimum value of x and the minimum value
of y together for which execution of P can result in a
The base address of student is available in register R1. deadlock are:
The field student-grade can be accessed efficiently using
(A)
x = 1, y = 2 (B) x = 2, y = 1
(A) Post-increment addressing mode. (R1)+
(C)
x = 2, y = 2 (D) x = 1, y = 1
(B) Pre-decrement addressing mode, -(R1)
(C) Register direct addressing mode, R1 Solution: As per given question, there x number of
threads and y number of locks for ensuring mutual ex-
(D) Index addressing mode, X(R1), where X is an
clusion while operating on shared memory locations
offset represented in 2’s complement 16-bit
representation. Option (A): x = 1; y = 2
Solution: Direct access is possible with only index Means that 1 thread and 2 locks clearly showing that no
addressing mode. deadlock situation.
Hence, the correct option is (D). Option (B): x = 2; y = 1
Question Number: 36 Question Type: MCQ Means that 2 threads and 1 lock → No deadlock situation.
Let G = (V, E) be any connected undirected edge- After usage of lock by 1 thread, it can release that lock
weighted graph. The weights of the edges in E are posi- and then 2nd thread can be used that lock. So, no dead-
tive and distinct. Consider the following statements: lock.
(I) Minimum spanning tree of G is always unique. Option (C): x = 2; y = 2
(II) Shortest path between any two vertices of G is Means that 2 threads and 2 locks → Deadlock can arise.
always unique. Which of the above statements Both threads can hold 1 lock and can wait for release
is/are necessarily true? of another lock
B = 1 Mbps 1011
Tp = 0.75 ms
L = 1980 Bytes
Hence, the correct option is (C).
LOH = 20 Bytes
LA = 20 Bytes Question Number: 40 Question Type: MCQ
Efficiency (h) = ? Let p, q, and r be propositions and the expression (p →
L (1980 + 20) × 8 2 × 8 × 103 q) → r be a contradiction. Then, the expression (r →
(i) Tx = = = = 16 ms p) → q is,
B 106 106
(A) a tautology
LA 20 × 8 (B) a contradiction
(ii) TACX = = = 0.16 ms
B 106 (C) always TRUE when p is FALSE,
In stop-and-wait ARQ, efficiency (D) always TRUE when q is TRUE
Tx 16 ms Solution: (p → q) → r is contradiction only when,
η= = 0.8933 ≈ 89.33%
Tx + TACK + 2TP + T proc 17.91 ms
p q r
Hence, the correct answer is (89.33). T T F
Question Number: 39 Question Type: MCQ F T F
A computer network uses polynomials over GF(2) for F F F
error checking with 8 bits as information bits and uses
x3 + x + 1 as the generator polynomial to generate the And now for the above combination, the expression
check bits. In this network, the message 01011011 is (r → p) → q is always true when q is true. When q is
transmitted as false in the above combination (third one) (r → p) →
(A) 01011011010 (B) 01011011011 q will be false.
(C) 01011011101 (D) 01011011100 Hence, the correct option is (D).
Solution: SB CC
SC CA
N
Total bits = 10 + log 2 + log 2 B SC CB
B
Offset SC CC
# of blocks
SD CA
N
10 + log 2 ( N ) = log 2 + T SD CB
16
SD CC
where T is the required length of TAG field SD CD
\T = 14 SE CD
Hence, the correct answer is (14). SE CA
Question Number: 42 Question Type: MCQ SE CB
Consider the following two functions. SF CA
SF CB
void funl (int n) void fun2 (int n)
{ { SF CC
Solution:
r(A) < n ⇒ |A| = 0 ⇒ one eigen value must be 0 ∈[5, 5] T Q1 Q0
D
(I) is true Flip- Flip-
Flop Flop
5 0 0 n n
Let A = 0 −5 0 ⇒ ∑ ∑ Aij2 = 50 and ρ ( A) = 2
Clock
we check the right part of the array recursively, which The speedup (correct to two decimals places) achieved
takes log 231 comparisons in the worst case. by EP over NP in executing 20 independent instruc-
Hence, the correct answer is (5). tions with no hazards is ______
rate may increase as the number of allocated frames Solution: Count in the function total is static.
increases. Now, consider the following statements: I Count Total (i)
Statement 1: Random page replacement algorithm 5 0 2
(where a page chosen at random is replaced) suffers 4 2 3(2 + 1)
from Belady’s anomaly. 3 3 5(3 + 2)
Statement 2: LRU page replacement algorithm suffers 2 5 6(5 + 1)
from Belady’s anomaly. 1 6 7(6 + 1)
Which of the following is CORRECT? = 23
Question Number: 63 Question Type: MCQ Solution: A TM is recursive iff it halts for every input
In a database system, unique time stamps are assigned string (either in accept or reject state).
to each transaction using Lamport’s logical clock. Let Here, a computable function is defined in a similar way.
TS(T1) and TS(T2) be the timestamps of transactions Hence, the correct answer is (A).
T1 and T2 respectively. Besides, T1 holds a lock on the
resource R, and T2 has requested a conflicting lock on Question Number: 65 Question Type: MCQ
the same resource R. The following algorithm is used Consider the expression (a – 1)* (((b + c)/ 3) +d)). Let
to prevent deadlocks in the database system assum- X be the minimum number of registers required by an
ing that a killed transaction is restarted with the same optimal code generation (without any register spill)
timestamp. algorithm for a load/store architecture in which (i) only
if TS(T2 ) < TS(T1 ) then T1 is killed else T2 waits. loads and store instructions can have memory operands
Assume any transactions that is not killed terminates and (ii) arithmetic instructions can have only register
eventually. Which of the following is TRUE about the or immediate operands. The value of X is_________.
database system that uses the above algorithm to pre- Solution:
vent deadlocks?
(A) The database system is both deadlock-free 2
and starvation-free. ∗
(B) The database system is deadlock- free, but not
starvation-free. 1 1
− +
(C) The database system is starvation-free but not
deadlock- free.
(D) The database system is neither deadlock-free a 1 1 1 d
nor starvation-free. 0
1 0
Solution: Elder kills younger and youngers waits on
+ 3
elder. So both are not waiting for each other. Hence 1
0
no deadlock and there won’t be any starvation as well
because the transaction who got killed will be starting b c
with same time stamp.
1 0
Hence, the correct answer is (A).
The given expression is (a - 1)*(((b + c)/3)+d))
Question Number: 64 Question Type: MCQ
Let A and B be infinite alphabets and let # be a symbol The optimal generated code is:
outside both A and B. Let f be a total functional from A* LOAD R1 b R1← b
to B*. We say f is computable if there exists a Turning LOAD R2 C R2← c
machine M which given an input x in A*, always halts
ADD R1 R2 R1← R1 + R2
with f(x) on its tape. Let Lf denote the language {x #f
(x)|x∈A*}.Which of the following statements is true: DIV R1 3 R1 R1/3
(A) f if computable if and only if Lf is recursive. LOAD R2 d R2←d
(B) f is computable if and only Lf recursively enu- ADD R1 R2 R1←R1+R2
merable. LOAD R2 a R2←a
(C) If f is computable then Lf is recursive, but not SUB R2 1 R2 R2-1
conversely.
MUL R2 R1 R2←R2*R1
(D) If f is computable then Lf is recursively enu-
Hence, the correct answer is (2).
merable, but not conversely.
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15
Question 1 to Question 5 carry 1 mark each and Question Number: 4 Question Type: MCQ
Question 6 to Question 10 carry 2 marks each. There are 3 red socks, 4 green socks, and 3 blue socks,
Question Number: 1 Question Type: MCQ you choose 2 socks. The probability that they are of the
same colour is ___________.
There are five buildings called V, W, X, Y, and Z in a
row (not necessarily in that order). V is to the west of (A) 1 5 (B) 7 30
W. Z is to the East of X and the West of V. W is to the (C) 1 4 (D) 4 15
West of Y. Which is the building in the middle?
3C2 + 4C2 + 3C2 4
(A) V (B) W (C) X (D) Y Solution: Required probability = =
10C2 15
Solution: From the given data, the following is formed
X Z V W Y
Hence, the correct option is (D).
N
Question Number: 5 Question Type: MCQ
W E Choose the option with words that are not synonyms.
(A) aversion, dislike
S
West East (B) luminous, radiant
(C) plunder, loot
\ The building ‘V’ is in the middle (D) yielding, resistant
Hence, the correct option is (A). Hence, the correct option is (D).
Question Number: 2 Question Type: MCQ
Question Number: 6 Question Type: MCQ
A test has twenty questions worth 100 marks in total.
An air pressure contour line joins locations in a region
There are two types of questions, multiple choice ques-
having the same atmospheric pressure. The following
tions are worth 3 marks each and essay questions are
is an air contour plot of a geographical region. Contour
worth 11 marks each. How many multiple choice ques-
lines are shown at 0.05 bar intervals in this plot.
tions does the exam have?
(A) 12 (B) 15 (C) 18 (D) 19 R
Solution: x + y = 20 (x = MCQ, y = Essay type) 065
3x + 11y = 100 07 09
the following regions is most likely to have a thunder- (A) 90 digits (B) 91 digits
storm? (C) 92 digits (D) 93 digits
(A) P (B) Q
Solution: X = (47…) 30 digits
(C) R (D) S
Suppose (47)330 digits = ( 2 + 2 + 2) digits in (47)3
Solution:
Region Air Pressure Difference Similarly (47)330 digits = contains (30 + 30 + 30) digits
P 0.95 – 0.90 = 0.05 = 90 digits
Q 0.80 – 0.75 = 0.05
R 0.85 – 0.65 = 0.20
Hence, the correct option is (A).
S 0.95 – 0.90 = 0.05 Question Number: 10 Question Type: MCQ
In general thunder storms are occurred in a region, There are three boxes, one contains apples, another con-
where suddenly air pressure changes (i.e.,) sudden rise tains oranges and the last one contains both apples and
(or) sudden fall of air pressure. From the given contour oranges. All three are known to be incorrectly labelled.
map in ‘R’ region only more changes in air pressure. If you are permitted to open just one box and then pull
So, the possibility of a thunder storms in this region. So out and inspect only one fruit, which box would you
option (C) is correct. open to determine the contents of all three boxes?
Hence, the correct option is (C). (A) The box labelled “Apples”
(B) The box labelled “Apples and Oranges”
Question Number: 7 Question Type: MCQ
The number of roots of e + 0.5x2 − 2 = 0 in the range
x (C) The box labelled “Oranges”
[-5, 5] is (D) Cannot be determined
(A) 0 (B) 1 (C) 2 (D) 3 Solution: The person who is opening the boxes, he
Solution: f (x) = e + 0.5x − 2
x 2 knew that all 3 are marked wrong.
f (−5) =10.50; f (−4) = 6.01, f (−2) = 0.135; f (−1) = Suppose if 3 boxes are labelled as below.
−1.13;
f (0) = −1, f (1) =1.21, f (2) = 7.38, f (3), f (4), f (5) also + ve.
\ As there are 2 sign changes from +ve to -ve and -ve
to +ve, two roots will be there in the range [-5, 5].
Hence, the correct option is (A). (1) Apples (2) Oranges (3) Apples and Oranges
Question Number: 8 Question Type: MCQ If he inspected from Box (1), picked one fruit, found
“We lived in a culture that denied any merit to literary orange, then he don’t know whether box contains or-
works, considering them important only when they were anges (or) both apples and oranges.
handmaidens to something seemingly more urgent— Similarly, if he picked one fruit from Box (2), found
namely ideology. This was a country where all gestures, apple then he don’t know whether box contain apples
even the most private, were interpreted in political terms.” (or) both apples and oranges.
The author’s belief that ideology is not as important as But, if he picked one fruit from Box (3), i.e., labelled
literature is revealed by the word: is “apples and oranges”, if he found apple then he can
(A) “culture” (B) “seemingly” decide compulsorily that Box (3) contains apples and
(C) “urgent” (D) “political” as he knew all boxes are labelled as incorrect, he can
tell Box (2) contains both apples and oranges, Box (1)
Hence, the correct option is (B).
contain remaining oranges. So, he should open box la-
Question Number: 9 Question Type: MCQ belled “Apples and Oranges” to determine contents of
X is a 30 digit number starting with the digit 4 followed all the three boxes.
by the digit 7, then the number X3 will have Hence, the correct option is (B).
In table T1, P is the primary key and Q is the foreign Hence, the correct option is (B).
key referencing R in table T2 with on-delete cascade
and on-update cascade. In table T2, R is the primary Question Number: 13 Question Type: MCQ
key and S is the foreign key referencing P in table T1 A circular queue has been implemented using a single
on-delete set NULL and on-update cascade. In order linked list where each node consists of a value and a
to delete record 3, 8 from table T1, the number of ad- single pointer pointing to the next node. We maintain
ditional records that need to be deleted from table T1 is exactly two external pointers FRONT and REAR
______________. pointing to the front node and the rear node of the
queue, respectively. Which of the following statements
Solution: Only (8, 3) will be deleted from T2. is/are CORRECT for such a circular queue, so that,
Hence, the correct answer is (0). insertion and deletion operation can be performed in
O (1) time?
Question Number: 12 Question Type: MCQ
I. Next pointer of front node points to the rear node.
Which of the following is/are shared by all the threads
II. Next pointer of rear node points to the front node.
in a process?
I. Program counter II. Stack (A) I only
III. Address space IV. Registers (B) II only
(A) I and II only (B) III only (C) Both I and II
(C) IV only (D) III and IV only (D) Neither I nor II
Solution: Next pointer of the front node would point
Solution:
to the second node, if any.
Code Data File Font Rear
T1 T2 T3
Single process P with 3 threads Multi threading Hence, the correct option is (B).
Question Number: 14 Question Type: MCQ Note: only M ! N relationship needs exclusive table: If
Given the following binary number in 32-bit (single a relationship is 1 ! M or M ! 1 thenthat relation could
precision) IEEE-754 format: be included in the many side table with the help of for-
00111110011011010000000000000000 eign key concept.
The decimal value closest to this floating- point num- Hence, the correct option is (C).
ber is
Question Number: 16 Question Type: MCQ
(A) 1.45 × 101 Match the algorithms with their time complexities:
(B) 1.45 × 10–1
Algorithm Time complexity
(C) 2.27 × 10–1
P. Towers of Hanoi with n disks i. q (n–2)
(D) 2.27 × 101
Q. Binary search given n sorted ii. q (n log n)
Solution: Sign numbers
R. Heap sort given n numbers at iii. q (2n)
0 01111100 11011010000000000000000
the worst case
+1 124
S. Addition of two n ⋅ n matrices iv. q (log n)
+1 2–3 [2–1 + 2–2+-------] = 0.227…
[1+]0.8515625 (A) P-(iii), Q-(iv), R-(i), S-(ii)
(B) P-(iv), Q-(iii), R-(i), S-(ii)
Hence, the correct option is (C).
(C) P-(iii), Q-(iv), R-(ii), S-(i)
Question Number: 15 Question Type: MCQ (D) P-(iv), Q-(iii), R-(ii), S-(i)
An ER model of a database consists of entity types
A and B. These are connected by a relationship R, Solution: P. Towers of Hanoi ⇒ T(n) = 2T (n - 1) + 1
which does not have its own attribute. Under which one ⇒ q (2°)
of the following conditions, can the relational table for n
Q. Binary search ⇒ T ( n) = T + C ⇒ θ (log n)
R be merged with that of A? 2
(A) Relationship R is one-to-many and the R. Heap sort ⇒ q (n log n)
participation of A in R is total. S. Addition of two n × n matrices ⇒ q (nr)
(B) Relationship R is one-to-many and the Hence, the correct option is (C).
participation of A in R is partial.
Question Number: 17 Question Type: MCQ
(C) Relationship R is many-to-one and the par-
Match the following according to input (from the left
ticipation of A in R is total.
column) to the complier phase (in the right column)
(D) Relationship R is many-to-one and the par- that processes it.
ticipation of A in R is partial.
Column-1 Column-2
Solution: P. Syntax tree i. Code generator
Q. Character stream ii. Syntax analyser
The minimum number of ordered pairs that need to be 10 contiguous bytes of memory is allocated is address
added to R to make (X, R) a lattice is ________. of first byte is stored in ‘m’ and later it is updated
with NULL. Now we lost the address of first bytes of
Solution: Given POSET is already a lattice so no need
that chunk of memory completely. So, we can’t free
to add any ordered pairs.
that space as we need the address of first byte to free
Hence, the correct answer is (0). it up
Question Number: 27 Question Type: MCQ R. char * ptr [10]:
Which of the following statements about parser is/are ptr is an array of 10 pointers pointing to character vari-
CORRECT? ables.
I. Canonical LR is more powerful than SLR.
S. register int varl:
II. SLR is more powerful than LALR.
Suggesting the complier to store the var1 “value” in
III. SLR is more powerful than Canonical LR. CPU register.
(A) I only (B) II only
Hence, the correct option is (A).
(C) III only (D) II and III only
Question Number: 29 Question Type: MCQ
Solution: Bottom up parsers in decreasing order of
Let L1 L2 be any two context free languages and R be
their power: CLR >> LALR >> SLR >> LR (0) any regular language. Then which of the following is/
The given statements: are CORRECT?
I. Canonical LR is more powerful than SLR is I. L1 ∪ L2 is context—free
CORRECT. II. L1 is context—free
II. SLR is more powerful than LALR is INCORRECT. III. L1 − Ris context—free
III.
SLR is more powerful than Canonical LR is IV. L1 ∩ L2 is context—free
INCORRECT.
(A) I, II and IV only
P. static char var; i. Sequence of memory loca- (B) I and III only
tions to store addresses
(C) II and IV only
Q. M = malloc (10); ii. A variable located in data
m = NULL; section of memory (D) I only
R. char * ptr [10] iii. Request to allocate a CPU
Solution: Given L1 and L2 are context free languages
register to store data
and R is a regular language.
S. register int var1; iv. A lost memory which can-
not be freed I. L1 ∪ L2 is context free is CORRECT, context free
language are closed under union operation.
Hence, the correct option is (A). II. L1 is context free is INCORRECT, context free
Question Number: 28 Question Type: MCQ languages are not closed under complement
operation.
Match the following:
III. L1 – R is Context free is CORRECT. L1 – R = L1
(A) P-(ii), Q-(iv), R-(i), S-(iii) ∩ R, Context free intersection Regular is always
(B) P-(ii), Q-(i), R-(iv), S-(iii) Context free.
(C) P-(ii), Q-(iv), R-(iii), S-(i) IV. L1 ∩ L2 is context free is INCORRECT; context
(D) P-(iii), Q-(iv), R-(i), S-(ii) free languages are not closed under complement
operation.
Solution: P. static char var:
Hence, the correct option is (B).
var is defined as character variable whose associated
storage class is static because of this it is given memory Question Number: 30 Question Type: NAT
from data segment .
G is undirected graph with n vertices and 25 edges such
Q. m = malloc(10); that each vertex of G has degree at least 3. Then the
m = NULL; maximum possible value of n is ___________.
Solution: If every vertex has degree at least k then Solution: BFS: Start at root (some arbitrary node of
K V ≤ 2( E ) a graph, sometimes referred to as “search key”) and
explore the neighbour nodes first, before and moving
3 V ≤ 2 × 25 to the next level neighbours.
a, b a, b a a, b a, b a, b
Solution: Therefore,
(38 + 0 + 37 + 28 + 42) 145
Q1 Q0 Q1+ Q0+ T1 T0 Average waiting time = =
5 5
0 0 0 1 0 1
= 29 ms
0 1 1 0 1 1
Hence, the correct answer is (29).
1 0 1 1 0 1
1 1 1 1 0 0 Question Number: 39 Question Type: MCQ
For any discrete random variable X, with probabil-
T1 = Q1Q0 ity mass function P(X = j) = pj, pj ≥ 0, j€ {0,.....,
N
T0 = Q1 + Q0 N} and ∑p j =0
j = 1, define the polynomial function
N
P1 P4 P2 P4 P1 P3 P6 Read Access 2 2 8 90
Time (in ns)
0 2 5 33 40 49 51 67
Hit Ratio 0.8 0.9 0.9 1.0
And in execution of program 60% of memory reads are Question Number: 42 Question Type: NAT
for instruction fetch and 40% are for memory operand Consider the following snippet of a C program. Assume
fetch. Now, that swap (&x, &y) exchanges the contents of x and y.
Average instruction fetch time = I-cache access time int main ( ) {
+ I-cache miss ratio * L2-cache access time + I-cache
int array[]={3,5,1,4,6,2};
miss rate * L2-cache miss ratio * main memory access
time = 2 + (1− 0.8)8 + (1 − 0.8)(1 − 0.9)90 = 5.4 nsec int done =0 ;
And int i ;
Average data fetch time = D-cache access time + D- while (done = = 0) {
cache miss ratio* L2-cache access time + D-cache miss done = 1;
ratio * L2-cache miss ratio * main memory access time for (i = 0; i <=4; i ++) {
2 + (1 − 0.9)8 + (1 − 0.9) × (1 − 0.9) × 90 = 3.7 nsec
if (array [i] < array [i +1]) {
Therefore,
swap (& array [i], &array [i+1]);
Average memory access time = Fraction of instruction
done = 0;
fetch * Average instruction fetch time + Fraction of
data fetch * Average data fetch time = 0.6 ⋅ 5.4 + 0.4 ⋅ }
3.7 = 4.72 (in nsec) }
Hence, the correct answer is (4.72). for (i = 5 ; i > =1; i --) {
Question Number: 41 Question Type: NAT if (array [i] > array [ i-1]) {
If the ordinary generating function of a sequence swap ( & array [i] , &array [i-1]);
1+ z done = 0;
{an }∞n= 0 is , then a3 – a0 is equal to _________.
(1 − z )3 }
}
Solution:
1 }
f ( z) = = 1 + z + z 2 +… printf ( “ %d “ , array [3] );
1− z
1 }
f ′( z ) = = 1 + 2 z + 3 z 2 +…
(1 − z ) 2 The output of the program is ____________.
1+ z 1 2z
Consider = + Solution: The final contents of the array is
(1 − z )3 (1 − z ) 2 (1 − z )3
1 6 5 4 3 2 1
= 1 + 2 z + 3z 2 + 4 z 3 …
(1 − z ) 2
\ a[3] = 3 will be printed
2
f ′′( z ) = = 2 + 6 z + 12 z 2 … Hence, the correct answer is (3).
(1 − z )3
1 2z Question Number: 43 Question Type: NAT
+ = (1 + 2 z + 3 z 2 + 4 z 3 −…)
(1 − z ) 2 (1 − z )3 Consider the following C program.
= 1 + 4 z + 9 z 2 + 16 z 3 … # include <stdio.h>
= a0 + a1 z + a2 z + a3 z …
2 3
int main ( ) {
a0 = 1 int m = 10;
a3 = 16 int n, n1;
a3 − a0 = 16 − 1 = 15 n = ++m;
n1 = m++;
Hence, the correct answer is (15). n--;
Pele Brazil 12 00 1 1 1 1
Klinsmann Germany 11
01 0 x 1 x
Kocsis Hungary 11
(X + Z)
Batistuta Argentina 10 11 0 0 x 0
Cubillas Peru 10
Lato Poland 10 10 1 0 x 1
Lineker England 10
T Miller Germany 10
Rahn Germany 10
(W + Z)
is 2 bytes, then maximum order of the B+ tree is Question Number: 48 Question Type: NAT
_______________. Consider a machine with a byte addressable main
Solution: Let ‘K’ be the order memory of 232 bytes divided into blocks of size 32
K(2) + (K – 1)(8) ≤ 512 bytes. Assume that a direct mapped cache having 512
cache lines is used with this machine. The size of the
⇒ 2K + 8k – 8 ≤ 512
520 tag field in bits is ______.
⇒ 10K ≤ 520 ⇒ K ≤
10 Solution:
\ K ≤ 52
32 − (5 + 9) = 18
Hence, the correct answer is (52).
Question Number: 47 Question Type: MCQ
Total block block
Let L(R) be the language represented by regular expres-
size identifier
sion R. Let L(G) be the language generated by a context
free grammar G. Let L(M) be the language accepted by
Hence, the correct answer is (18).
a Turning machine M. Which of the following decision
problems are undecidable? Question Number: 49 Question Type: MCQ
I. Given a regular expression R and a string w, is w Let d denote that transition function and δˆ denote the
∈ L(R)? extended transition function of the ∈− NFA whose
II. Given a context-free grammar G, L(G) = ∅? transition table is given below:
III. Given a context-free grammar G, is L(G) = S* for
some alphabet S? d ∈ a b
δ (q 3, a) ϕ δ (q 0, a) Calculac c closure
δ (q 3, a) δ (q 0, a) δ (q 2, a) Take Transition
q1 ϕ Calculac c closure
{q 0, q 1, q 2} Final Answer
Hamming distance between code 1 and code 2 is 3. Question Number: 53 Question Type: NAT
Hamming distance between code 1 and code 3 is 3. Two transactions T1 and T2 are given as:
Hamming distance between code 1 and code 4 is 4. T1 : r1 (X) w1 (X) r1 (Y) w1 (Y)
Hamming distance between code 2 and code 3 is 4. T2 : r2 (Y) w2 (Y) r2 (Z) w2 (Z)
Hamming distance between code 2 and code 4 is 3. where ri(V) denotes a read operation by transaction Ti
on a variable V and wi(V) denotes a write operations
Hamming distance between code 3 and code 4 is 3.
by transaction I, T on a variable V. The total number of
So, as per Hamming code, minimum Hamming dis- conflict serializable schedules that can be formed by T1
tance of all code words is considered as Hamming dis- and T2 is _____________.
tance, i.e., 3(p).
Solution: Conflict conditions RW WR WW
Now, the max number of erroneous bits that can be cor-
\ 5 conflicts
rected by the Hamming code is 2d + 1.
T1–T2
So, 2d + 1 = 3 ⇒ d = 1
a b c d
Hence, the correct option is (A). r1 (X) w1 (X) r1 (Y) w1 (y)
Question Number: 52 Question Type: MCQ r2 (Y) w2 (Y) r2 (Z) r2 (Z)
A system shares 9 tape drives. The current allocation 1 2 3 4
and maximum requirement of tape drives for three pro- Constraints:
cesses are shown in the table: a<b<c<d
Current Maximum 1<2<3<4
Process Allocation Requirement
d<1 (or) 2<c
P1 3 7
only 1 way
P2 1 6 Total = 70 = 70 − (12 + 5)
P3 3 5
L.H.S : wx ( y + z ) + wx = wx + yz
(B) Strlen (100 + x + 11 – x – 1 [assume x has the ASCII
value of I]
R.H.S : wx ( y + z ) + wx
⇒ Strlen 110
Apply De’Morgan theorem
2 is printed
⇒ wx ( y + z ) + wx = [ x + y = xy ]
Hence, the correct answer is (2).
⇒ ( w + x ) + ( yz ) + wx
Question Number: 56 Question Type: MCQ
⇒ w + x + yz + wx
P and Q are considering to apply for a job. The prob-
⇒ w + x + yz = R.H.S 1
L..H.S=R.H.S ability that P applies for the job is . The probability
4
that P applies for the job given that Q applies for the
(C) {[wx ( y + z )] + wx} y = xy
1
L.H.S ≠ R.H.S job is , and the probability that Q applies for the job
2 1
(D) L.H.S: (w + y)(wxy + wyz) = wxy + wyz given that P applies for the job . Then the probability
3
(w + y)(wxy + wyz) that P does not apply for the job given that Q does not
⇒ wxy + wyz + wxy wyz apply for the job is
⇒ wxy + wyz 4 5
(A) (B)
L.H.S = R.H.S 5 6
7 11
Hence, the correct option is (C). (C) (D)
8 12
Question Number: 55 Question Type: NAT Solution: Let A, B be the events denote that P, Q, re-
Consider the following C Program. spectively applies for a job
# include <stdio.h> 1 1
⇒ Pr ( A) = 1 , Pr ( A/B) = 1
#include< string.h> ⇒ Pr ( A) = 4 , Pr ( A/B ) = 2 (1)
4 2
#int main ( ) { 1
Pr ( B /A) = 1
Pr ( B /A) = 3
(2)
char* c = “GATECSIT2017”; 3
char* p = c; 1
( 2) gives Pr ( A ∩ B) = 1
( 2) gives Pr ( A ∩ B ) = 12
printf(“%d”, (int) strlen 12
(c+2[p]-6[p]-1)); 1
∴ gives Pr ( B) = 1
∴ gives Pr ( B) = 6
return 0; 6
} 1 1 1
1 − 1 × 1 − 1
A r( A ∩ B ) 1 − P ( A ∪ B) 1 − 4 × 6 − 12
The output of the program is _______________. ∴ A = r ( A ∩ B ) = 1 − Prr ( A ∪ B ) = 4 6 12
∴ B = P ( B ) = 1 − P ( B ) = 1
Solution: B Prr ( B ) 1 − Prr ( B ) 1− 1
1− 6
100 6
2 6 4
G A T E C S I T 2 0 1 7 10 = 2×6 = 4
= 3×5 = 5
3 5 5
P ( A ∪ B)
Here Pr is Probability and P ( A/B) = P ( A ∪ B)
Here P is Probability and P ( A / B ) = P ( B)
C
P ( B)
r
100 P 100
Hence, the correct option is (A).
Question Number: 57 Question Type: NAT
strlen (c + 2[p] − 6[p] −1) If the characteristics polynomial of 3 × 3 matrix M
over R ( the set of real numbers) is l3 − 4l2 + al+ 30,
100 + T − I −1 a ∈ R, and one eigenvalue of M is 2, then the largest
Note: Whenever, we have characters in the arithmetic ex- among the absolute values of the eigenvalues of M is
pressions, we can replace those with their ASCII v alues ________.
Solution: E(X) = 5 ⇒ (X2) = 30, Hence after removal of the left recursion:
where X ~ P(l), (l) = 5 E → TX
\ E[(X + 2) ] = E(X ) + 4.E(X) + 4 = 30 + 20 + 4 = 54
2 2
X → - TX|∈
(\V(X) = E(X2) - (E(X))2) T → FY
Since, one eigenvalue of Mis 2 Y → +FY|∈
\ 23 – 4(22) + a(2) + 30 = 0 F → (E) | id
⇒ a = –11 Hence, the correct option is (C).
\ Characteristic polynomial is
Question Number: 59 Question Type: MCQ
l3 - 4l2 - 11l30 = 0 In a two-level cache system, the access times of 1 2 L
(l - 2)(l - 5)(l - 3) = 0 and L caches are 1 and 8 clock cycles, respectively.
\ l = 2.5, -3 The miss penalty from L2 cache to main memory is 18
clock cycles . The miss rate of L1 cache is twice that of
Largest absolute value of ‘l’ is 5
L2. The average memory access time (AMAT) of this
Hence, the correct answer is (271). cache system is 2 cycles. This miss rates of L1 and L2
respectively are :
Question Number: 58 Question Type: MCQ
(A) 0.111 and 0.056 (B) 0.056 and 0.111
Consider the following expression grammar G:
(C) 0.0892 and 0.1784 (D) 0.1784 and 0.0892
E → E – T |T Solution: 2 = 1 + 2 m × 8 + m × 18
T → T + F | F 1
\ m=
F → (E)| id 34
Hence, the correct option is (A).
Which of the following grammars is not left recursive,
but is equivalent to G? Question Number: 60 Question Type: MCQ
(A) E → E – T | T (B) E → E – TE Consider two hosts X and Y, connected by a single
T → T + F |F E′ → TE′|€ direct link of rate 106 bits/sec. The distance between
the two hosts is 10,000 km and the propagation speed
F → (E) id T → T + F |F
along the link is 2 × 108 msec. Host X sends a file of
F → (E)|id 50,000 bytes as one large message to host Y continu-
(C) E → TX (D) E → TX|(TX) ously. Let the transmission and propagation delays be p
X → TX|€ X → TX | + TX |€ milliseconds and q milliseconds, respectively. Then the
values of p and q are
T → FY T → id
(A) p = 50 and q = 100 (B) p = 50 and q = 400
Y → FY |€
(C) p = 100 and q = 50 (D) p = 400 and q = 50
F → (E)|id
Solution: Given data
Solution: The rule for removal of left recursion is B = 106 bits/sec
A →Aα |β will be D = 10,000 km = 104 × 103 m
A →β A’ V = 2 × 108 m/s
A’ → αA’|∈ L = 50,000 Bytes
L 50, 000 × 8
The given grammar is: \ Transmission time (p) = = = 400 ms
B 106
E → E – T|T; in this α is “–T” and β is T
d 107
T →T + F|F , In this α is “+F” and β is F \ Propagation Time (q) = = = 50 ms
v 2 × 108
F → (E)|id Hence, the correct option is (D).
Question Number: 61 Question Type: MCQ Time complexity of fun in terms of q notation is
Consider the recurrence function (A) θ ( n n ) ⋅ (B) q (n2)
2T ( n ) + 1, n > 2 (C) q (n log n) (D) q (n2 log n)
T ( n) =
0<n≤2 Solution: for i = 1
2,
Then T(n) in terms of q notation is j will run from 1 to n by incrementing by ‘1’ in each
step ⇒ ‘j’ will run for n times For i = 2
(A) q (log log n) (B)
q (log n)
j will run from 1 ton by incrementing by ‘2’ in each step
(C) (θ n )
⋅ q (n)
(D) n
⇒ j will run for times and so on
Solution: 2
T ( n) = 2T ( n ) + 1 n n n
Time Complexity (Tc) = n + + +…+
Put n = 2 K 2 3 n
T ( 2 K ) = 2T ( 2 K / 2 ) + 1 1 1 1
= n 1 + + +…+ = θ ( n log n)
Assume T ( 2 ) = δ ( K )
K 2 3 n
Hence, the correct option is (C).
K
⇒ δ ( K ) = 2δ + 1
2 Question Number: 64 Question Type: MCQ
By master’s theorem The pre-order transversal of a binary search tree is
d(K) = q (K) given by 12,8,6,2,7,9,10,16,15,19,17,20. Then the
post-order traversal of this tree is:
T(2K) = q (K)
(A) 2,6,7,8,9,10,12,15,16,17,19,20
T(n) = q (log n)
(B) 2,7,6,10,9,8,15,17,20,19,16,12
\ 2k = n
(C) 7,2,6,8,9,10,20,17,19,15,16,12
Hence, the correct option is (B).
(D) 7,6,2,10,9,8,15,16,17,20,19,12
Question Number: 62 Question Type: NAT
If a random variable X has a Poisson distribution Solution: Given: Preorder ! 12,8,6,2,7,9,10,16,15,19,
with mean 5, then the expectation E[( X + 2) 2 ] equals 17,20
______________. In order! 2,6,7,8,9,10,12,15,16,17,19,20
Solution: E(X) = 5 ⇒ E(X 2) = 30, where X - P(l), Note: BST In order will give ascending order Corre-
l = 5 sponding BST is
\ E[(X + 2)2] = E(X2) + 4E(X) + 4 12
= 30 + 20 + 4 = 54
(V(X) = E(X2)–(E(X))2) 8 16
Hence, the correct answer is (54).
Question Number: 63 Question Type: MCQ 6 9 15 19
Consider the following C function
int fun (int n) {
2 7 10 17 20
int i, j;
for (i = 1; i < = n; i++) { \ Post order is 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12
for (j = 1 ; j < n ; j+=i) { Hence, the correct option is (B).
printf (“%d %d , i, j ) ;
Question Number: 65 Question Type: MCQ
}
Consider the C program fragment below which is meant
} to divide x by y using repeated subtractions. The vari-
} ables x, y, q and r are all unsigned int.
Programming &
C Programming 1 1 2
Data Structures
Functions 1 2 3 5
Pointers & Structures 1 1 1
Stacks, Queues & Linked lists 2 2 4
Trees and Heaps
Graphs
Total Marks 12
Algorithms Asymptotic analysis 1 2 3 5
TCP/UDP 1 1 2
IP(V4), IPV6 and wireless
1 1 2
networks
Network Security 1 1 2
Total Marks 10
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Question 1 to Question 5 carry 1 mark each and Question Number: 4 Question Type: MCQ
Question 6 to Question 10 carry 2 marks each. If ‘relftaga’ means carefree, ‘otaga’ means careful and
Question Number: 1 Question Type: MCQ ‘fertaga’ means careless, which of the following could
mean ‘aftercare’?
Out of the following four sentences, select the most
suitable sentence with respect to grammar and usage. (A) zentaga (B) tagafer
(A) I will not leave the place until the minister (C) tagazen (D) relffer
does not meet me. Solution: Hence the correct option is (C).
(B) I will not leave the place until the minister
Question Number: 5 Question Type: MCQ
doesn’t meet me.
A cube is built using 64 cubic blocks of side one unit.
(C) I will not leave the place until the minister After it is built, one cubic block is removed from every
meets me. corner of the cube. The resulting surface area of the
(D) I will not leave the place until the minister body (in square units) after the removal is _____.
meets me. (A) 56 (B) 64 (C) 72 (D) 96
Solution: The use of does not and doesn’t after until is Solution: The total surface area of the body after the
redundant therefore options (A) and (B) are incorrect. 8 unit cubes are removed, is
Option (C) is also incorrect because the verb ‘meet’
does not agree with the singular noun minister. = 6 × 16 = 96.
Hence the correct option is (D). Hence the correct option is (D).
Question Number: 2 Question Type: MCQ Question Number: 6 Question Type: MCQ
A rewording of something written or spoken is a ______. A shaving set company sells 4 different types of razors,
(A) paraphrase (B) paradox elegance, smooth, soft and executive. Elegance sells at
Rs. 48, smooth at Rs. 63, soft at Rs.78 and executive at
(C) paradigm (D) paraffin Rs. 173 per price. The table below shows the numbers
Solution: Hence the correct option is (A) of each razor sold in each quarter of a year.
Question Number: 3 Question Type: MCQ Quarter/
Archimedes said, “Give me a lever long enough and Product Elegance Smooth Soft Executive
a fulcrum on which to place it, and I will move the Q1 27300 20009 17602 9999
world.” Q2 25222 19392 18445 8942
The above sentence is an example of a ____ statement. Q3 28976 22429 19544 10234
(A) figurative (B) collateral Q4 21012 18229 16595 10109
(C) literal (D) figurine
Which product contributes the greatest frication to the
Solution: To create a particular mental picture the revenue of the company in that year?
words lever and fulcrum are used in a way that is differ- (A) Elegance (B) Executive
ent from the usual meaning in order.
(C) Smooth (D) Soft
Hence the correct option is (A).
Solution: If the numbers of razors are divided by 1000 (A) (i) only
the date is shown below (B) (ii) only
Quarter El Sm Sf Ex (C) (i) and (ii)
Q1 27 20 18 10 (D) neither (i) nor (ii)
Q2 25 19 18 9 Solution: Consider the statements (i) and (ii)
Q3 29 22 20 10 (ii) definitely cannot be inferred
Q4 21 18 17 10 (i) As S loses to P only sometimes, it is not likely that
Total 102 79 73 39 P beats S. Therefore,
Rate 48 63 78 173 (i) too cannot be inferred.
Revenue 4896 4977 5694 6747 Hence, the correct option is (D).
Executive is the product that contributes the greatest Question Number: 9 Question Type: MCQ
amount from the table given above. If f (x) = 2x + 3x – 5, which of the following is a factor
7
x
k 106
From (1), y = x
As y = 104 for x = 40, it follows If y = 5000, 10 20 = = 200
5000
10 20 x
that k = 106 ⇒ = log 200 = 2.3010
Therefore from (1), 20
⇒ x = 46.02.
106
y= x Hence, the correct option is (B).
10 20
Question Number: 15 Question Type: NAT Question Number: 18 Question Type: MCQ
(
Two eigenvalues of a 3 × 3 real matrix P are 2 + −1 ) We want to design a synchronous counter that counts
the sequence 0-1-0-2-0-3 and then repeats. The mini-
and 3. The determinant of P is ___.
mum number of J-K flip-flops required to implement this
Solution: As 2 + −1 is an Eigen value of P, 2 – −1 counter is _____.
is also an Eigen value of P.
Solution: For 6 states we require 3-flipflops. Therefore,
The determinant of P ≡ |P| the minimum number of J-K flip-flops required to
= Product of the Eigen vales of P implement this counter is 3.
( )( )
= 2 + −1 2 − −1 × 3 = 15. Hence, the correct Answer is (3).
Question Number: 19 Question Type: NAT
Hence, the correct Answer is (15).
A processor can support a maximum memory of 4GB,
Question Number: 16 Question Type: MCQ where the memory is word - addressable (a word con-
Consider the Boolean operator # with the following sists of two bytes). The size of the address bus of the
properties: processor is atleast ___ bits.
x # 0 = x, x # 1 = x ,x # x = 0 Solution: 1 word = 2 Bytes = 2 × 8 bits
and = 16 - bits
x # x = 1. Then x # y is equivalent to Number of words in memory
(A)
x y + x y (B)
xy +x y 4 × 230 × 23
=
(C)
x y +x y (D)
xy+x y 16
30 31
Solution: x # 0 = x = 2×2 = 2
x # 1 = x′ The size of the address bus of the processor is at least
31 - bit length.
x # x = 0, x # x′ = 1, by observing, # operation is XOR Hence, the correct Answer is (31).
so x # y = x′y + xy′ Question Number: 20 Question Type: MCQ
Hence, the correct option is (A). A queue is implemented using an array such that
Question Number: 17 Question Type: NAT ENQUEUE and DEQUEUE operations are performed
efficiently. Which one of the following statements is
The 16-bit 2’s complement representation of an inte-
correct (n refers to the number of items in the queue)?
ger is 1111 1111 1111 0101; its decimal representation
is ___. (A) Both operations can be performed in O(1) time.
(B) At most one operation can be performed in
Solution: We know that 2’s complement representa-
O(1) time but the worst case time for the other
tion is 1111 1111 1111 0101.
operation will be Ω(n).
By looking at MSB, we can understand it is negative
(C) The worst case time complexity for both
number (MSB = 1), so by taking the 2’s complement
operations will be Ω (n).
we will get positive number.
2’s complement of given number is 0000 0000 0000 (D) Worst case time complexity for both
1011. operations will be Ω(log n).
Its decimal equivalent is 11. Solution: We know that Enqueue and Dequeue opera-
So given number is –11. tions always take one unit of time. Thus Both opera-
Hence, the correct Answer is (–11). tions can be performed in O(1) time.
Hence, the correct option is (A).
Question Number: 21 Question Type: NAT Question Number: 23 Question Type: MCQ
Consider the following directed graph: The worst case running times of Insertion sort, Merge
sort and Quick sort, respectively are:
b c
(A) Q(n log n), Q(n log n), and Q(n2)
(B) Q(n2), Q(n2) and Q(n log n)
a f (C) Q(n2), Q(n log n) and Q(n log n)
(D) Q(n2), Q(n log n) and Q(n2)
d e Solution: We know that the worst case running time
of insertion sort is q(n2) and of merge sort is q(n log n)
The number of different topological orderings of the and of quick sort is q(n2).
vertices of the graph is _______. Hence, the correct option is (D).
Solution: ‘a’ and ‘f ’ are fixed in first and last positions Question Number: 24 Question Type: MCQ
respectively. Let G be a weighted connected undirected graph with
Possible topological orderings are given below: distinct positive edge weights. If every edge weight is
(1) a b c d e f increased by the same value, then which of the follow-
(2) a d e b c f ing statements is/are true?
(3) a b d c e f P: Minimum spanning tree of G does not change.
(4) a b d e c f Q: Shortest path between any pair of vertices does not
(5) a d b c e f change.
(6) a d b e c f (A) P only (B) Q only
Hence, the correct Answer is (6). (C) Neither P nor Q (D) Both P and Q
Question Number: 22 Question Type: MCQ Solution: Let us consider a graph G
Consider the following C program. 1 2
void f (int, short); 5 6
void main( ) 2 3 3 4
6 7
{
4 5
int i = 100;
Spanning tree Spanning tree
short s = 12;
short *p = &s; 1 2
_____; // call to f( )
2 3 3 4
}
Solution:
(A) V X Y Z Super key
Old database:
Primary key = (Volume, Number, Start page, End page)
(B) V W XZ Not a super key because Volume, Number, Startpage, Endpage → Title
Y is not present
(Fully dependency)
(C) V W X Y Super key Volume, Number → Year (Partial dependency)
Volume, Number, Start page, End page → Price
(D) (Full dependency)
V WX Y Z Super key
Old database does not satisfy 2NF because it has partial
Hence, the correct option is (B). dependency.
New database:
Question Number: 32 Question Type: MCQ
(Volume, Number, Start page, End page, Title, Price)
Which one of the following is not a part of the ACID
properties of database transactions? (Volume, Number, Year)
All three given functional dependencies satisfy second
(A) Atomicity
normal form.
(B) Consistency
Hence, the correct option is (B).
(C) Isolation
Question Number: 34 Question Type: MCQ
(D) Deadlock-freedom
Which one of the following protocols is not used to
Solution: Deadlock-freedom is not a part of the ACID resolve one form of address to another one?
properties of database transactions because the acid (A) DNS (B) ARP
properties are atomicity, consistency, isolation and
durability. (C) DHCP (D) RARP
Hence, the correct option is (D). Solution: DHCP is a client/server protocol that auto-
matically provides an IP host with its IP address and
Question Number: 33 Question Type: MCQ
other related configuration information. Therefore, this
A database of research articles in a journal uses the fol- is the protocol which is not used to resolve one form of
lowing schema. address to another one.
(VOLUME, NUMBER, STARTPAGE, ENDPAGE, Hence, the correct option is (C).
TITLE, YEAR, PRICE)
The primary key is (VOLUME, NUMBER, Question Number: 35 Question Type: MCQ
STARTPAGE, ENDPAGE) and the following func- Which of the following is/are example(s) of stateful
tional dependencies exist in the schema. application layer protocols?
(VOLUME, NUMBER, STARTPAGE, ENDPAGE) → (i) HTTP (ii) FTP
TITLE (iii) TCP (iv) POP3
(VOLUME, NUMBER) → YEAR (A) (i) and (ii) only (B) (ii) and (iii) only
(VOLUME, NUMBER, (C) (ii) and (iv) only (D) (iv) only
STARTPAGE, ENDPAGE) → PRICE
Solution: .
The database is redesigned to use the following schemas.
TCP is transport layer protocol.
(VOLUME, NUMBER, STARTPAGE, ENDPAGE,
HTTP is stateless protocol.
TITLE, PRICE)
FTP is stateful protocol
(VOLUME, NUMBER, YEAR)
POP3 is stateful protocol.
Which is the weakest normal form that the new data-
base satisfies, but the old one does not? Hence, (ii) and (iv) are stateful application layer
protocols.
(A) 1NF (B) 2NF
Hence, the correct option is (C).
(C) 3NF (D) BCNF
Question Number: 44 Question Type: MCQ Solution: The initial values of n, d are
The following function computes the maximum value n 3 d 1
contained in an integer array p [ ] of size n (n > =1). here ‘d’ is a static variable. Initialization is done only
int max (int *p, int n) { once.
int a = 0, b = n – 1; count( ) performs five operations.
while (_____) { (1) print n
(2) print d
if (p [a] < = p [b]) {a = a+1;} (3) increment d
else { b = b – 1;} (4) call recursively count (n – 1) if n > 1
} (5) print d
return p[a]; The ‘d’ value is printed from the present updated values
rather activation record value.
}
Count (3) n 3
d 2 m(a);
n 2
m( y)
(1) (2) (3) Count(2) (5)
d 2 a=1;
a=y–a;
n(a)
print(a);
(1) (2) (3) Count (1) (5)
n(x)
d 3
x = x ∗ a;
print(x) ;
d 3 d 4
L = an n 0 an bn n 0 * has low precedence.
3 * 3 = 9
And is accepted by a deterministic CFL. Hence, the correct Answer is (9).
Hence, the correct option is (D).
Question Number: 56 Question Type: MCQ
Question Number: 54 Question Type: MCQ Consider the following Syntax Directed Translation
Let X be a recursive language and Y be a recursively Scheme (SDTS), with non-terminals {S, A} and termi-
enumerable but not recursive language. Let W and Z be nals {a, b}.
two languages such that Y reduces to W, and Z reduces S → aA { print 1 }
to X (reduction means the standard many-one reduc- S → a { print 2 }
tion). Which one of the following statements is true?
A → Sb { print 3 }
(A) W can be recursively enumerable and Z is Using the above SDTS, the output printed by a bottom-
recursive. up parser, for the input aab is:
(B) W can be recursive and Z is recursively (A) 1 3 2
enumerable.
(B) 2 2 3
(C) W is not recursively enumerable and Z is
recursive. (C) 2 3 1
(D) W is not recursively enumerable and Z is not (D) syntax error
recursive.
Which one of the following is true about the above (A) {m, K B+ (H(m))} (B) {m, K B− (H(m))}
solution?
(C) {m, K A− (H(m))} (D) {m, K A+ (m)}
(A) At most one process can be in the critical
section at any time. Solution: Kx(m) represents encryption of m with key
Kx.
(B) The bounded wait condition is satisfied.
H(m) represents message digest.
(C) The progress condition is satisfied.
To send a digitally signed message from B to A, the
(D) It cannot cause a deadlock. message need to be encrypted by private key of B. i.e.,
Solution: The synchronization solutions for the above
n processes guarantee mutual exclusion.
{m, K −
B ( H ( M ))}
Hence, the correct option is (A). Hence, the correct option is (B).
Question Number: 61 Question Type: MCQ Question Number: 63 Question Type: NAT
Consider the following two phase locking protocol. An IP datagram of size 1000 bytes arrives at a router.
Suppose a transaction T accesses (for read or write The router has to forward this packet on a link whose
operations), a certain set of objects {O1, …, Ok). This MTU (maximum transmission unit) is 100 bytes.
is done in the following manner: Assume that the size of the IP header is 20 bytes.
Step 1. T acquires exclusive locks to O1, …, Ok in The number of fragments that the IP datagram will be
increasing order of their addresses. divided into for transmission is ______.
Step 2. The required operations are performed. Solution: IP datagram has a size of 1000 Bytes.
Step 3. All locks are released. Maximum transmission unit capacity is 100 bytes.
This protocol will In these 100 bytes, 20 bytes is for header.
(A) guarantee serializability and deadlock- So 80 bytes is for data.
freedom. To transfer 1000 bytes, with 80 byte data in the packet,
(B) guarantee neither serializability nor deadlock- 1000
freedom. = 12.5 13 packets required.
80
(C) guarantee serializability but not deadlock- Hence, the correct Answer is (13).
freedom.
Question Number: 64 Question Type: NAT
(D) guarantee deadlock-freedom but not serial-
izabilty. For a host machine that uses the token bucket algorithm
for congestion control, the token bucket has a capac-
Solution: If every transaction in a schedule follows ity of 1 megabyte and the maximum output rate is 20
2-phase locking protocol, that schedule is definitely megabytes per second. Token arrives at a rate to sustain
serialiazable. output at a rate of 10 megabytes per second. The token
→ It guarantees serializability. bucket is currently full and the machine needs to send
→ There is deadlock freedom. 12 megabytes of data. The minimum time required to
Hence, the correct option is (A). transmit the data is _____ seconds.
c
Question Number: 62 Question Type: MCQ Solution: Time taken for 1 MB of data (s) m − ρ
Consider that B wants to send a message m that is 1
= = 0.1 sec.
digitally signed to A. Let the pair of private and pub- 20 − 10
lic keys for A and B be denoted by K x− and K x+ for x = Data transmitted in 0.1 sec
A, B respectively. Let Kx(m) represent the operation
= 0.1 × output rate
of encrypting m with a key Kx and H(m) represent the
message digest. Which one of the following indicates = 0.1 × 20 MBPS
the correct way of sending the message m along with
= 2 MB.
the digital signature to A?
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Question 1 to Question 5 carry 1 mark each and Question Number: 4 Question Type: MCQ
Question 6 to Question 10 carry 2 marks each. Pick the odd one from the following options.
Question Number: 1 Question Type: MCQ (A) CADBE (B) JHKIL
The man who is now Municipal Commissioner worked (C) XVYWZ (D) ONPMQ
as ________.
Solution: Each group contains five consecutive letters
(A) the security guard at a university from the English alphabet. The arrangement within the
(B) a security guard at the university group is similar in (A), (B) and (C), but different in (D).
(C) a security guard at university Hence, (D) is the odd one.
(D) the security guard at the university Hence, the correct option is (D).
Solution: The reference is to a particular person who Question Number: 5 Question Type: MCQ
worked as a security guard. In a quadratic function, the value of the product of the
Hence, the correct option is (B). α n + βn
roots (α β) is 4. Find the value of − n
Question Number: 2 Question Type: MCQ α + β −n
Nobody knows how the Indian cricket team is going to (A) n4 (B) 4n
cope with the difficult and seamer-friendly wickets in (C) 22n–1 (D) 4n–1
Australia.
Choose the option which is closest in meaning to the Solution: Let the quadratic equation be ax2 + bx +
underlined phrase in the above sentence. c = 0. The roots of quadratic equation are a, b
(A) put up with −b
\ a+b=
(B) put in with a
c
(C) put down to and ab = .
a
(D) put up against As per problem ab = 4
Solution: To cope with something or someone is to α n + βn α n + βn n n
= a b = (ab)n = 4n.
bear with something or someone. α −n + β −n α n + β n
Hence, the correct option is (D). Hence, the correct option is (B).
Question Number: 3 Question Type: MCQ Question Number: 6 Question Type: MCQ
Find the odd in the following group of words. Among 150 faculty members in an institute, 55 are con-
Mock, deride, praise, jeer nected with each other through Facebook® and 85 are
(A) mock (B) deride connected through WhatsApp®. 30 faculty members
(C) praise (D) jeer do not have Facebook® or WhatsApp® accounts. The
number of faculty members connected only through
Solution: Mock, deride, and jeer convey the same Facebook® accounts is ______.
meaning. Praise is the odd one out.
(A) 35 (B) 45 (C) 65 (D) 90
Hence, the correct option is (C).
Solution: Consider the Venn diagram given below Statement (ii) is not valid. Because according to the
in which F represents Facebook and W represents author many people think internet is an unintended
WhatsApp. consequence, but did not make such comment about
mobile computers.
F(55) W(85) Hence, neither (i) nor (ii) is valid.
Hence, the correct option is (D).
Choose the correct expression for f(x) given in the Solution: The graph shows a V which opens down-
graph. wards. The mod expression has to be preceded by a
(A) f(x) = 1 – |x – 1| (B) f(x) = 1 + |x – 1| negative sign (we reject B, D) at the vertex of the V,
i.e., at x = 1, y is 2. We accept C and reject A.
(C) f(x) = 2 – |x – 1| (D) f(x) = 2 + |x – 1|
Hence, the correct option is (C).
P ∧ (P → Q) ⇒ Q ⇒ P ∨ Q (Addition) 4-colors
\ P ∧ (P →Q) ⇒ True Non planar graph
Consider P ∧ (P → Q → (~ Q ∨ P) 1
⎤ Q ∨ P is false only when P is false and Q is true.
In that case P ∧ (P → Q) is false.
\ P ∧ (P → Q) → (⎤ Q ∨ P) is a tautology. 2 3
Hence the number of expressions among (i), (ii), (iii),
(iv) and (v) that are tautologically implied by
P ∧ (P → Q) is 4.
Hence, the correct Answer is (4). 4 5
Solution: Floyd-warshall algorithm for all-pair short- Which one of the following is TRUE?
est paths computation is based on dynamic program- (A) Both P and Q are true
ming paradigm.
(B) P is true and Q is false
Hence, the correct option is (C).
(C) P is false and Q is true
Question Number: 25 Question Type: MCQ (D) Both P and Q are false
N items are stored in a sorted doubly linked list. For a
delete operation, a pointer is provided to the record to Solution: L1 accepts strips which are in the form of
be deleted. For a decrease-key operation, a pointer is {an bn | n ≥ 0}
provided to the record on which the operation is to be This is not regular.
performed.
The DFA for the language generated by this grammar is
An algorithm performs the following operations on
a
the list in this order: Q (N) delete, O (log N) insert, O
(log N) find, and Q (N) decrease-key. What is the time
complexity of all these operations put together?
(A) O (log2N) (B) O(N)
b
(C) O(N 2) (D) Q (N 2logN)
Solution: Time complexity = O(N) \ L2 is regular.
Total time complexity = (N + N log N + N log N + N) \ P is false and Q is true.
= (2N + 2N log N) = 2(N + N log N) Hence, the correct option is (C).
= N + N log N ≤ C * N2 Question Number: 28 Question Type: MCQ
= N + N log N ∈ O(N2) Consider the following types of languages: L1: Regular,
L2: Context-free, L3: Recursive, L4: Recursively
Hence, the correct option is (C).
enumerable. Which of the following is/are TRUE?
Question Number: 26 Question Type: NAT
I. L3 ∪ L4 is recursively enumerable.
The number of states in the minimum sized DFA that
accepts the language defined by the regular expression II. L 2 ∪ L3 is recursive.
(0 + 1)* (0 + 1) (0 + 1)* is ______ . III. L*1 ∩ L2 is context–free.
0, 1 Solution:
(i) L3 ∪ L4 is recursively enumerable.
0, 1 As L3 is recursive, L3 is also recursive.
Every recursive language is recursively
enumerable.
\ Two states required. Recursively enumerable languages are closed
Hence, the correct Answer is (2). under union.
Question Number: 27 Question Type: MCQ \ L3 ∪ L4 is recursively enumerable.
Language L1 is defined by the grammar: S1 → aS1b|∈ (ii) L 2 ∪ L3 is recursive.
Language L2 is defined by the grammar: S2 → abS2|∈ L2 is CFL. L2 is not necessarily CFL but L2 is
Consider the following statements: recursive.
P: L1 is regular As L3 is recursive, L2 ∪ L3 is recursive.
Q: L2 is regular (∵ Recursive languages are closed under union).
Question Number: 33 Question Type: MCQ 3. After connection is established, the client requests
Anarkali digitally signs a message and sends it to data from server using HTTP GET request.
Salim. Verification of the signature by Salim requires Hence, the correct option is (C).
(A) Anarkali’s public key. Question Number: 36 Question Type: MCQ
(B) Salim’s public key. A binary relation R on N × N is defined as follows:
(C) Salim’s private key. (a, b) R (c, d) if a ≤ c or b ≤ d. Consider the following
(D) Anarkali’s private key. propositions:
P: R is reflexive
Solution: Anarkali digitally signs a message and
Q: R is transitive
sends it to Salim. For this Anarkali uses her private key.
To verify this Salim requires Anarkali’s public key. Which one of the following statements is true?
Hence, the correct option is (A). (A) Both P and Q are true.
(B) P is true and Q is false.
Question Number: 34 Question Type: MCQ
(C) P is false and Q is true.
In an Ethernet local area network, which one of the fol-
lowing statements is true? (D) Both P and Q are false.
(A) A station stops to sense the channel once it Solution: We know that a ≤ a and b ≤ b
starts transmitting a frame. ⇒ (a, b) R (a, b), ∀ (a, b) ∈ N × N
(B) The purpose of the jamming signal is to pad
Thus relation R is reflexive.
the frames that are smaller than the minimum
frame size. ⇒ P is true.
For Q consider this example:
(C) A station continues to transmit the packet
even after the collision is detected. We know that
(D) The exponential back off mechanism reduces (4, 10) R (7, 6) (∵ 4 ≤ 7)
the probability of collision on retransmissions. and (7, 6) R (3, 9) (∵ 6 ≤ 9)
Solution: The exponential backoff algorithm reduces But (4, 10) R (3, 9) (∵ 4 ≰ 3 and 10 ≰ 9)
the probability of collision on retransmission. This
statement is true. Thus relation R is not transitive.
Hence, the correct option is (D) Hence Q is false.
Hence, the correct option is (B).
Question Number: 35 Question Type: MCQ
Identify the correct sequence in which the following Question Number: 37 Question Type: MCQ
packets are transmitted on the network by a host when Which one of the following well-formed formulae in
a browser requests a webpage from a remote server, predicate calculus is not valid?
assuming that the host has just been restarted. (A) (∀x p(x) ⇒ ∀xq(x)) ⇒ (∃x¬p(x) ∨ ∀xq(x))
(A) HTTP GET request, DNS query, TCP SYN (B) (∃x p(x) ∨ ∃x q(x)) ⇒ ∃x (p(x) ∨ q(x)))
(B) DNS query, HTTP GET request, TCP SYN (C) ∃x(p(x) ∧ q(x)) ⇒ (∃xp(x) ∧ ∃xq(x))
(C) DNS query, TCP SYN, HTTP GET request (D) ∀x(p(x) ∨ q(x)) ⇒ (∀xp(x) ∨ ∀xq(x))
(D) TCP SYN, DNS query, HTTP GET request Solution: ∀x(p(x) ∨ q(x)) ⇒ (∀xp(x) ∨ ∀xq(x))
Solution: We know that when a browser requests a This formulae is not valid.
webpage from a remote server, the packets to be trans- Hence, the correct option is (D).
mitted are
Question Number: 38 Question Type: MCQ
1. Client sends DNS query for remote server.
Consider a set U of 23 different compounds in a
2. To get connection, client will send TCP SYN
Chemistry lab. There is a subset S of U of 9 compounds,
packet.
each of which reacts with exactly 3 compounds of U.
(D) 1 7 6 * + 2 5 4 3 * – ∧ –
When P is pointing to a
Solution: Post fix expression is
P[0] = 3, P[1] = 5, P[2] = 2, P[3] = 6, P[4] = 3
34 * 5 − 2 ∧ 67 * 1 + −
This expression is post order of the expression tree. The When P is pointing to a[1] (P → P + 1)
expression tree of the above expression is
0 1 2 3 4
− a 3 5 2 6 4
∧ +
P
2
− ∗ 1
Then P[0] = 5, P[1] = 2, P[2] =6, P[3] = 4
5 *P = P + 1
∗
6 7
Similarly, when *P = P + 2 and *P = P + 3
3 4
A (n/2)
A (n/2)
Solution: If we consider the maximum depth of the At each level (other than at root-level 1) the node can be
recursive function, and the recurrence relation would placed either as left child or as right child i.e., there are
be: 2 ways to place a node at each level (other than level 1).
⎛ n⎞ The total number of structures formed = 2 × 2 × 2 × 2
T(n) = 5T ⎜ ⎟ + 1
⎝ 2⎠ ×2×2
Apply Master theorem on the above recurrence relation. = 26
⎛ n⎞ = 64 structures
T(n) = 5T ⎜ ⎟ + 1
⎝ 2⎠ For every structure the elements can be placed in only
one way to form binary search tree. Hence, total 64
⎛ n⎞
T(n) = aT ⎜ ⎟ + f(n) BST’s can be formed.
⎝ b⎠
Hence, the correct Answer is (64).
a
f(n) Vs nlogb Question Number: 51 Question Type: MCQ
5
1 Vs nlog2 In an adjacency list representation of an undirected
a
f(n) < nlogb (case 1 of master theorem) simple graph G = (V, E), each edge (u, v) has two adja-
a 5
cency list entries: [v] in the adjacency list of u and [u]
O(nlogb ) = O(nlog2 ) = O(n2.32 ) in the adjacency list of v. These are called twins of each
Hence, the correct Answer is (2.2 to 2.4). other. A twin pointer is a pointer from an adjacency list
entry to its twin. If |E| = m and |V| = n, and the memory
Question Number: 50 Question Type: NAT size is not a constraint, what is the time complexity of
The number of ways in which the numbers 1, 2, 3, 4, the most efficient algorithm to set the twin pointer in
5, 6, 7 can be inserted in an empty binary search tree, each entry in each adjacency list?
such that the resulting tree has height 6 is ____. (A) Q(n2) (B) Q(n + m)
Note: The height of a tree with a single node is 0. (C) Q(m ) (D)
2
Q(n4)
Solution: Binary search tree of height 6 with seven Solution: To represent a graph, if we use matrix the
numbers (height of single node is 0) contain seven lev- time complexity of the most efficient algorithm to set
els with each level containing only one node. the twin pointer will be O(n2).
Level 1 Height 0 – If we use adjacency list, it will be 2(edges +
vertices) = 2 (m + n) = q (m + n).
Hence, the correct option is (B).
Level 2 Height 1
Question Number: 52 Question Type: MCQ
Consider the following two statements:
Level 3 Height 2 I. If all states of an NFA are accepting states then the
language accepted by the NFA is S*.
II. There exists a regular language A such that for all
Level 4 Height 3 languages B, A ∩ B is regular.
Which one of the following is correct?
(A) Only I is true
Level 5 Height 4
(B) Only II is true
(C) Both I and II are true
Level 6 Height 5 (D) Both I and II are false
Solution:
I. If all the states of an NFA are accepting states then
Level 7 Height 6
the language accepted by the NFA is Σ*.
This is not always correct. (In some cases, every But checking the equality of a’s, b’s with n c’s is not
transition is not included). possible with the stack memory of PDA.
For example, consider below NFA. Hence, the correct option is (B).
a Question Number: 54 Question Type: MCQ
Consider the following languages.
a b L1= {〈M〉 | M takes at least 2016 steps on some input},
L2= {〈M〉 | M takes at least 2016 steps on all inputs} and
The DFA equivalent to this NFA is given below: L1= {〈M〉 | M accepts e}.
b Where for each Turing machine M, 〈M〉 denotes a spe-
cific encoding of M. Which one of the following is true?
b (A) L1 is recursive and L2, L3 are not recursive.
a
(B) L2 is recursive and L1, L3 are not recursive.
(C) L1, L2 are recursive L3 is not recursive.
(D) L1, L2, L3 are recursive.
a Solution: From given information L1 is recursive. It is
This does not represent Σ*. decidable. L1 accepts strings which takes atleast 2016
\ I is false. steps on some input.
II. There exists a regular language A such that for all The machines says ‘yes’ for some input which has
languages B, A ∩ B is regular. atleast 2016 steps, for other string it says ‘no’.
This statement is always correct. From given information L2 is decidable and recursive
also.
Example: A = f (A is regular)
Machines says ‘yes’ for all the strings which take
B = {an bn/n ≥ 0} atleast 2016 steps. And says ‘no’ for an input which has
A ∩ B = f, which is regular. below 2016 steps.
For any B, A ∩ B = f, which is regular. L3 is undecidable. Empty tape acceptance problem is
\ II is correct. undecidable, and so L3 is not recursive.
Hence, the correct option is (B). Hence, the correct option is (C).
Question Number: 53 Question Type: MCQ Question Number: 55 Question Type: MCQ
Consider the following languages: Which one of the following grammars is free from left
recursion?
L1 = {anbmcn+m : m, n ≥ 1}
(A) S → AB
L2 = {anbnc2n : n ≥ 1}
A → Aa|b
Which one of the following is true? B → c
(A) Both L1 and L2 are context-free. (B) S → Ab|Bb|c
(B) L1 is context-free while L2 is not context–free. A → Bd|ε
(C) L2 is context-free while L1 is not context -free. B → e
(D) Neither L1 nor L2 is context-free. (C) S → Aa|B
Solution: The PDA can be designed which pushes A → Bb|Sc|ε
a’s, b’s on stack and pops a’s, b’s for every c as L1 is B → d
context-free.
S → Aa|Bb|c
(D)
Since, L2 is not context-free.
A → Bd|ε
{an bn | n ≥ 1} is context-free.
B → Ae|ε
Solution: If left most variable of right hand side of Question Number: 57 Question Type: NAT
production is same as the variable at left hand side of Consider the following processes, with the arrival time
production then the grammar is said to be left recursive. and the length of the CPU burst given in milliseconds.
Option (B) is free from left recursion. The scheduling algorithm used is preemptive shortest
Hence, the correct option is (B). remaining-time first.
Question Number: 56 Question Type: MCQ Process Arrival Time Burst Time
A student wrote two context - free grammars G1 and P1 0 10
G2 for generating a single C-like array declaration. The P2 3 6
dimension of the array is at least one.
P3 7 1
For example, int a [10] [3];
P4 8 3
The grammars use D as the start symbol, and use six
terminal symbols int; id [ ] num. The average turn around time of these processes is
Grammar G1 Grammar G2 ____ milliseconds.
D → int L; D → int L;
Solution:
L → id [E L → id E
E → num] E → E [num] Turn
Process Arrival Burst Completion around
E → num] [E E → [num] id time time time time
Which of the grammars correctly generate the declara- P1 0 10 20 20
tion mentioned above?
P2 3 6 10 7
(A) Both G1 and G2 P3 7 1 8 1
(B) Only G1 P4 8 3 13 5
(C) Only G2
(D) Neither G1 nor G2 Gantt chart:
D D
Turn around time (Pi) = Completion time (Pi) – Arrival
time (Pi)
int L; int L; 20 + 7 + 1 + 5 33
Average T.A.T = = = 8.25
4 4
id [E id E Hence, the correct Answer is (8.2 to 8.3).
a Num] [E a
Question Number: 58 Question Type: MCQ
E [Num]
Consider the following two-process synchronization
solution.
10 Num] [Num] 3
Process 0 Process 1
3 10 --------- ---------
int a [10] [3] ; int a [10] [3] ; Entry: loop while Entry: loop while
(turn = = 1); (turn = = 0);
Using both grammars G1 and G2, we can generate the (Critical section) (Critical section)
string int a [10] [3].
Exit: turn = 1; Exist: turn = 0;
Hence, the correct option is (A).
The shared variable turn is initialized to zero. Which If 20 P(S) and 12 V(S) operations are performed on S in
one of the following is true? any order, it results in −8.
(A) This is a correct two-process synchronization We need to choose the value of S such that, the resulting
solution. value should be −1 (given atleast one process should be
(B) This solution violates mutual exclusion blocked after performing above operations)
requirement. So the value of S should be 7.
(C) This solution violates progress requirement. (∵ −8 + 7 = −1)
(D) This solution violates bounded wait Hence, the correct Answer is (7).
requirement. Question Number: 60 Question Type: NAT
Solution: The given solution guarantees the mutual A file system uses an in-memory cache to cache disk
exclusion principle. There can be only one process blocks. The miss rate of the cache is shown in the figure.
in critical section at any time (either process 0 or The latency to read a block from the cache is 1 ms and
process 1). to read a block from the disk is 10 ms. Assume that the
But it does not guarantee progress requirement. cost of checking whether a block exists in the cache
is negligible. Available cache sizes are in multiples of
No process running outside the critical section should
10 MB.
block another process which is interested in executing
critical section. The smallest cache size required to ensure an average
read latency of less than 6 ms is ____ MB.
Initially, turn = 0 (given in solution) suppose P0 and
P1 are in the system, now process P0 is not interested 90
in executing critical section (C.S), it is executing non- 80
critical section. 70
P1 is interested in executing C.S but it is not allowed in 60
Miss rate (%)
Question Number: 61 Question Type: MCQ The number of tuples returned by the following SQL
Consider the following database schedule with two query is ______.
transactions T1 and T2. with total (name, capacity) as
S = r2(X); r1(X); r2(Y); w1(X); r1(Y); w2(X); a1;a2 select district _ name, sum
(capacity)
Where ri(Z) denotes a read operation by transaction Ti
from water _ schemes
on a variable Z, wi(Z) denotes a write operation by Ti on
group by district _ name
a variable Z and ai denotes an abort by transaction Ti.
with total _avg (capacity) as
Which one of the following statements about the above
select avg (capacity)
schedule is true?
from total
(A) S is non – recoverable.
select name
(B) S is recoverable, but has a cascading abort. from total, total _ avg
(C) S does not have a cascading abort. where total . capacity ≥ total_
(D) S is strict. avg. capacity
Solution: Solution:
T1 T2 Total:
1. r2(X)
District-name Sum(Capacity)
2. r1(X)
Ajmer 20
3. r2(Y)
Bikaner 40
4. w1(X)
Churu 30
5. r1(Y)
Dungargarh 10
6. w2(X)
7. a1 Total - avg:
8. a2 Avg(Capacity)
25
There is no RW - conflict in the schedule, so it is
recoverable. Select name
from total, total – avg
– T2 is not reading any data item which is updated
by T1. Where total. Capacity ≥ total - avg.
capacity
– Abort operation performed by T1 does not give any
effect to abort operation performed by T2. Ajmer 20 ≥ 25
water_schemes Churu 30 ≥ 25
scheme_no District name Capacity
1 Ajmer 20
1 Bikaner 10 Dungargarh 10 ≥ 25
2 Bikaner 10
Output:
3 Bikaner 20
Name
1 Churu 20
Bikaner
2 Churu 20
Churu
1 Dungargarh 10
Hence, the correct Answer is (2).
Question Number: 63 Question Type: NAT Question Number: 65 Question Type: NAT
A network has a data transmission bandwidth of 20 × Consider a 128 × 103 bits/second satellite commu-
106 bits per second. It uses CSMA/CD in the MAC nication link with one way propagation delay of
layer. The maximum signal propagation time from one 150 milliseconds. Selective retransmission (repeat)
node to another node is 40 microseconds. The mini- protocol is used on this link to send data with a frame
mum size of a frame in the network is ___ bytes. size of 1 kilobyte. Neglect the transmission time of
acknowledgement. The minimum number of bits
Solution: Transmission bandwidth
required for the sequence number field to achieve
= 20 × 106 bps 100% utilization is ______.
Propagation time = 40 msec Solution: Link utilization of selective repeat protocol
Minimum size of frame = bandwidth * 2 * propagation is
delay Window size
Link utilization =
= 20 * 106 * 2 * 40 × 10−6 1+ 2 * a
TPropagation delay
= 1600 bits Where a=
1600 TTransmission delay
= bytes
8 TPropagation delay = 150 msec.
= 200 bytes.
1024 × 8
TTransmission delay = = 64 msec
Hence, the correct Answer is (200). 128 × 103
Question Number: 64 Question Type: MCQ 150
a= = 2.34375
For the IEEE 802.11 MAC protocol for wireless com- 64
munication, which of the following statements is/ are
true? Window size = 1 * (1 + 2 * 2.34375) = 5.6875
I. At least three non-overlapping channels are avail- In selective repeat, the sending and receiving window
able for transmissions. sizes must be equal and half the maximum sequence
number.
II. The RTS-CTS mechanism is used for collision
detection. 2* window size = maximum sequence number
III. Unicast frames are ACKed. ⇒ Maximum sequence number = 2 * 5.6875 = 11.375
(A) All I, II and III (B) I and III only \ Minimum number of bits required to generate this
(C) II and III only (D) II only maximum sequence number is 4. (∵ 24 = 16 11.375)
Hence, the correct Answer is (4).
Solution: At least 3 non-overlapping channels are
available for the IEEE 802.11 MAC protocol for wire-
less communication.
RTS - CTS mechanism is used for collision avoidance,
not for detection.
In 802.11, unicast frames are acknowledged.
Hence, the correct option is (B).
Computer
Organization Pipeline 0 1 1 2
Instruction Types 1 0 1 1
Miscellaneous 0 1 1 2
Total Marks 5
DS Algorithm and Data Structure and
Programming Algorithm Analysis 1 2 3 5
Stack, Queues, Linklist 0 1 1 2
Trees 3 0 3 3
Priority Queues (Heaps) 0 1 1 2
Sorting Algorithm 1 0 1 1
Graph Algorithm 1 2 3 5
C Programming 1 2 3 5
Total Marks 23
DBMS E-R Diagram 0 1 1 2
SQL 1 1 2 3
Total Marks 5
Theory of
Computation Finite Automata 0 1 1 2
PDA 0 1 1 2
Turning of Machine 1 0 1 1
Total Marks 5
Compiler Design Parsing 1 0 1 1
Total Marks 1
Operating System CPU Scheduling 0 1 1 2
Deadlocks and
Synchronization 1 0 1 1
Memory Management and
Virtual Memory 1 1 2 3
Disc Management 0 2 2 4
Total Marks 10
Software
Engineering Validation and Verification 0 2 2 4
XML 1 0 1 1
Testing 1 0 1 1
Total Marks 6
DMGT Graph Theory 0 1 1 2
Sets, Function and
Relations 1 1 2 3
Mathematic Logic 1 0 1 1
Total Marks 6
Memory Management
and Virtual Memory 1 2 3 5
I/O System 0 1 1 2
Total Marks 9
Software Engineering Introduction 1 0 1 1
Process and Module 1 0 1 1
Testing 0 1 1 2
Total Marks 4
DMGT Graph Theory 0 2 2 4
Sets, Function and
Relations 2 1 3 4
Combinatorics 1 1 2 3
Mathematic Logic 1 1 2 3
Total Marks 14
Computer-Network The Data Link Layer 1 0 1 1
TCP/IP, UDP and
Socket, IPV4 0 3 3 6
Application Layer 1 0 1 1
Total Marks 8
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Question 1 to Question 5 carry 1 mark each and ( iii) He failed to make many of his good starts count.
Question 6 to Question 10 carry 2 marks each. (iv)
Improving his technical skills will guarantee
Question Number: 1 Question Type: MCQ success.
Alexander turned his attention towards India, since he (A) (iii) and (iv) (B) (ii) and (iii)
had conquered Persia. (C) (i), (ii) and (iii) (D) (ii) only
Which one of the statements below is logically valid Solution: Form the given passage only statement (ii)
and can be inferred from the above sentence? and (iii) can be inferred. Whereas, statement (i) is con-
(A) Alexander would not have turned his atten- tradicting the main essence of the passage and (iv) is a
tion towards India and had he not conquered farfetched conclusion.
Persia. Hence, the correct option is (B).
(B) Alexander was not ready to rest on his laurels,
Question Number: 3 Question Type: NAT
and wanted to march to India.
The exports and imports (in crores of Rs.) of a country
(C) Alexander was completely in control of his from the year 2000 to 2007 are given in the follow-
army and could command it to move towards ing bar chart. In which year is the combined percentage
India. increase in imports and exports the highest?
(D) Since Alexander’s kingdom extended to
Indian borders after the conquest of Persia, he Exports Imports
120
was keen to move further. 110
100
Solution: The logically consistent form of the above 90
given statement is implicit only from (A). 80
70
Hence, the correct option is (A). 60
50
Question Number: 2 Question Type: MCQ 40
Most experts feel that in spite of possessing all the 30
technical skills required to be a batsman of the high- 20
10
est order, he is unlikely to be so due to lack of req- 0
uisite temperament. He was guilty of throwing away 2000 2001 2002 2003 2004 2005 2006 2007
his wicket several times after working hard to lay a
strong foundation. His critics pointed out that until he
Solution: From 2005 to 2006, the combined imports
addressed this problem, success at the highest level will
and exports increased by `60 crores. ∴ The combined
continue to elude him.
percentage increase in imports and imports in 2006
Which of the statement(s) below is/are logically valid 60
and can be inferred from the above passage? (over the previous year) was (100) % i.e., (37.5).
160
(i) He was already a successful batsman at the highest This was the maximum combined percentage increase
level. in imports and exports in any year over the given period.
(ii) He has to improve his temperament in order to Hence, the correct Answer is (2006).
become a great batsman.
20 Options (A)
The distance travelled in 20 minutes = ∫ Vdt
256 log2 256 = 6 minutes
t =0
1
By Simpson’s – rule, we have 256 log 256 = 360 seconds
3
20 360
h 256 = = 45 time units
∫ Vdt = ⎡⎣(V0 + V10 ) + 4 (V1 + V3 + V5 + V7 + V9 ) 8
3
0 Option (B)
+ 2 (V2 + V4 + V6 + V8 )⎤⎦ 512 log 512 = 360 seconds
360
Here, h = 2, V0 = Vat t = 0 = 0 (∵ starting from rest) 512 = = 40 time units
9
∴ from (1),
Elements – 64 = 26 = 5 time units
20
2 Elements – 128 = 27 = 10 time units
∫ Vdt = 3 [(0 + 0) + 4(10 + 25 + 32 + 11 + 2) Elements – 256 = 28 = 20 time units
0
get (6)
= P′QR + PQ′R + P′Q R′ + P′Q′R′ + PQR The output of the program is ______.
Question Number: 23 Question Type: NAT Solution: The time slot info for stage 1 – 10001
Consider a network connecting two systems located Time Slot info for stage 2 – 1010
8000 kilometers apart. The bandwidth of the network is Time slot info for stage 3 – 00100
500 × 106 bits per second. The propagation speed of the From the above, the average latency will be 3.
media is 4 × 106 meters per second. It is needed to design
Hence, the correct Answer is (3).
a Go-Back-N sliding window protocol for this network.
The average packet size is 107 bits. The network is to be Question Number: 25 Question Type: MCQ
used to its full capacity. Assume that processing delays Consider the following code sequence having five
at nodes are negligible. Then, the minimum size in bits instructions l1 to l5. Each of these instructions has the
of the sequence number field has to be _______ following format.
packet size L 10 × 106 OP Ri, Rj, Rk
Solution: TT = = = = 0.02 sec
Bandwidth B 500 × 106 Where operation OP is performed on contents of reg-
distance d 8000 × 103 8 × 106 isters Rj and Rk and the result is stored in register Ri.
TP = = = = = 2 sec l1: ADD R1, R2, R3
velocity v 4 × 106 4 × 106 l2: MUL R7, R1, R3
Link utilization is 100% (η = 100)
l3: SUB R4, R1, R5
T 2
a= P = = 100 l4: ADD R3, R2, R4
TT 0.02
l5: MUL R7, R8, R9
W
In Go-Back-N-Protocol, Efficiency = η = Consider the following three statements.
1 + 2a
S1: There is an anti-dependence instruction between
(W = 2n – 1) (η = 100%) instructions l2 and l5
2n − 1 S2: There is an anti-dependence between instructions
η=
1 + 2a l2 and l4
2n − 1 S3: Within an instruction pipeline anti-dependence
1 = always creates one or more stalls
1 + 2a
Which one of the above statements is/are correct?
⇒ 1 + 2a = 2n – 1
(A) Only S1 is true
1 + 2(100) = 2n – 1
(B) Only S2 is true
201 + 1 = 2n
(C) Only S1 and S3 are true
2n = 202
(D) Only S2 and S3 are true
2n ≅ 28
n = 8 Solution: An anti–dependency between instructions
can also be refereed as WAR hazard. There is no WAR
In sequence number, minimum bit required is 8. between l2 and l5 .There is anti–dependency between l2
Hence, the correct Answer is (8). and l4 as l4 writes R3 which is read by l2.
Question Number: 24 Question Type: NAT An anti–dependency may or may not create a stall.
Consider the following reservation table for a pipeline Hence, the correct option is (B).
having the stages S1, S2 and S3. Question Number: 26 Question Type: MCQ
Time → Consider the following two C code segments. Y and X
1 2 3 4 5 are one and two dimensional arrays of size n and n ×
S1 X X
n respectively, where 2 ≤ n ≤ 10. Assume that in both
code segments, elements of Y are initialized to 0 and
S2 X X
each element X[i] [j] of array X is initialized to i + j.
S3 X Further assume that when stored in main memory all
The minimum average latency (MAL) is ______. elements of X are in same main memory page frame.
Schedule S
for (i = 0; i < n; i++) Suppose that the transaction T1 fails immediately after
Y[i] += X[i] [0]; time instance 9. Which one of the following statements
Which of the following statements is/are correct? is correct?
S1: Final contents of array Y will be same in both code (A) T2 must be aborted and then both T1 and
segments T2 must be re-started to ensure transaction
S2: Elements of array X accessed inside the for loop atomicity.
shown in code segment 1 are contiguous in main (B) Schedule S is non-recoverable and cannot
memory ensure transaction atomicity.
S3: Elements of array X accessed inside the for loop (C) Only T2 must be aborted and then re-started
shown in code segment 2 are contiguous in main to ensure transaction atomicity.
memory.
(D) Schedule S is recoverable and can ensure
(A) Only S2 is correct atomicity and nothing else needs to be done.
(B) Only S3 is correct
Solution:
(C) Only S1 and S2 are correct
(D) Only S1 and S3 are correct Transaction-Id
T1 T2
Solution: Both the code segments will be initialized
1 read(A)
first [Y to 0, & X[i][j] with i + j] the values of Y[i] will
2 write(A)
be same in both segments as it is assigned i + j values
to Y[i]. 3 read(C)
Question Number: 30 Question Type: MCQ Question Number: 31 Question Type: NAT
⎛ 1⎞ 1 Let G be a connected undirected graph of 100 verti-
If for non-zero x, af(x) + bf ⎜ ⎟ = - 25 where a ≠ b ces and 300 edges. The weight of a minimum spanning
2
⎝ x⎠ x
tree of G is 500. When the weight of each edge of G is
then ∫ f ( x ) dx is
increased by five, the weight of a minimum spanning
1
1 ⎡ 47b ⎤ tree becomes______.
(A) 2 2
a −b ⎢ a (ln 2 − 25) + 2 ⎥ Solution: Vertices = 100
⎣ ⎦
1 ⎡ 47b ⎤ Edges = 300
(B) 2 2
a −b ⎢ a ( 2 ln 2 − 25) − 2 ⎥ Minimum spanning tree weight = 500
⎣ ⎦
In minimum spanning tree, if there are n-vertices there
1 ⎡ 47b ⎤
⎢ a ( 2 ln 2 − 25) + 2 ⎥
(C) 2 2 will be (n – 1) edges.
a −b ⎣ ⎦ ∴ For 100 vertices, we will have 99 edges in the
1 ⎡ 47b ⎤ minimum spanning tree.
(D) 2 2
a −b ⎢ a (ln 2 − 25) − 2 ⎥ 99 Edges, Weight is 500,
⎣ ⎦
Now each edge weight is increased by 5
⎛ 1⎞ 1
Solution: Given af(x) + b f ⎜ ⎟ = − 25 (1) ⇒ 99 × 5 = 495
⎝ x⎠ x
Total weight = 500 + 495 = 995
1 ⎛ 1⎞
Replacing x by , we have af ⎜ ⎟ + b f(x) Hence, the correct Answer is (995).
x ⎝ x⎠
= x – 25 (2) Question Number: 32 Question Type: NAT
Two hosts are connected via a packet switch with 107 bits
a(1) – b(2) ⇒ per second links. Each link has a propagation delay of 20
⎛ 1⎞ ⎛1 ⎞ microseconds. The switch begins forwarding a packet 35
a2 f(x) + abf ⎜ ⎟ = a ⎜ − 25⎟
⎝ x⎠ ⎝x ⎠ microseconds after it receives the same. If 10000 bits of
⎛ 1⎞ data are to be transmitted between the two hosts using a
abf ⎜ ⎟ + b2 f(x) = b(x – 25) packet size of 5000 bits, the time elapsed between the
⎝ x⎠
––––––––––––––––––––––––––––––––––– transmission of the first bit of data and the reception of
the last bit of the data in microseconds is _______.
⎛1 ⎞
a2 f(x) – b2 f(x) = a ⎜ − 25⎟ − b ( x − 25)
⎝x ⎠ Solution:
⎛ a ⎞ Host 1
⇒ (a2 – b2) f(x) = ⎜ − bx ⎟ – (a – b)25 5000 bits Switch Host 2
⎝x ⎠
1 ⎡a ⎤
⇒ f(x) = 2 2 ⎢
− bx − ( a − b ) 25⎥ 35
a −b ⎣x ⎦
Now
2 2
⎡ 1 ⎛a ⎞⎤
∫ f ( x ) dx = ∫ ⎢ 2 2 ⎜⎝ − bx − ( a − b ) 25⎟⎠ ⎥
1 ⎣a −b
x ⎦
1
2
1 ⎡ b 2 ⎤
=
a − b2
2 ⎢ a ln x − 2 x − ( a − b ) 25 x ⎥
⎣ ⎦1
Transmission Time (TT) = The time taken to put the
1 ⎡ 47b ⎤ packet on line:
= 2 2
a −b ⎢ a (ln 2 − 25) + 2 ⎥
⎣ ⎦ packet size 5000
TT = = = 500 micro seconds
Hence, the correct option is (A). Bandwidth 107
Arrival Processing
Process Time Time A A B C C D B
A 0 3 0 1 3 4 6 8 10 15
B 1 6
C 4 4 Process A.T B.T C.T T.A.T
D 6 2 A 0 3 5 3
B 1 6 15 14
(A) First come first serve C 4 4 8 4
(B) Non-preemptive shortest job first D 6 2 10 4
(C) Shortest remaining time
25
(D) Round Robin with quantum value two Average T.A.T = = 6.25
4
Solution:
Round Robin
FCFS
A B A C B D C B
A B C D
0 2 4 5 7 9 11 13 15
0 3 9 12 14
33 ∴ program ‘X’ = 4
Average T.A.T. = = 8.25
4 Control flow diagram for program – X:
Shortest remaining first has less average T.A.T.
Hence, the correct option is (C).
Question Number: 34 Question Type: MCQ
Consider three software items: Program-X, Control
Flow Diagram of Program-Y and Control Flow
Diagram of Program-Z as shown below:
3 if (C[0] = 1)
So Pr[Y = 0/x3 = 0] = = 0.75
4 z = 1 × 2 mod 8 = 2
Hence, the correct Answer is (0.75).
i = 1:-
Question Number: 38 Question Type: NAT z = 22 mod 8 = 4
The total number of prime implicants of the function i = 2
f(w, x, y, z) = Σ(0, 2, 4, 5, 6, 10) is ______.
z = 42 mod 8 = 0
Solution: f(w, x, y, z) = Σm(0, 2, 4, 5, 6, 10) z = (0 × 2)mod 8 = 0
yz i = 3
wx 00 01 11 10 z = 02 mod 8 = 0
z = (0 × 2) mod 8 = 0
00 1 1
z = 0
01 1 1 1 Hence, the correct Answer is (0).
Question Number: 40 Question Type: MCQ
11 Let f(n) = n and g(n) = n(1 + sin n), where n is a posi-
tive integer. Which of the following statements is/are
10 1 correct?
I. f(n) = O(g(n))
II. f(n) = Ω(g(n))
f = w′ xy′ + w′ z′ + x′ yz′ (A) Only I (B) Only II
3 prime implicants (2 pairs, 1 Quad) (C) Both I and II (D) Neither I nor II
Hence, the correct Answer is (3). Solution: f(n) = n
Question Number: 39 Question Type: NAT g(n) = n(1+sin n)
Suppose c = <c[0], …, c[k – 1]> is an array of length n = positive integer
k, where all the entries are from the set {0, 1}. For any
–1 ≤ sin n ≤ 1
positive integers a and n, consider the following pseudo
code. Suppose if we take ‘–1’ in the place of (sin n) then
DOSOMETHING (c, a, n) g(n) = n° = 1
z ← 1 Suppose If we take ‘1’ in the place of (sin n) then
g(n) = n2
for i ← 0 to k – 1
g(n) value keeps changing. So neither I nor II can be
do z ← z2 mod n
correct.
if c[i] = 1
Hence, the correct option is (D).
then z ← (z × a) mod n
return z Question Number: 41 Question Type: MCQ
Consider the following grammar G
If k = 4, c = <1,0,1,1>, a = 2 and n = 8, then the output
S → F | H
of DOSOMETHING(c, a, n) is ______.
F → p | c
Solution:
H → d | c
K = 4; C = <1, 0, 1, 1>; a = 2; n = 8
Where S, F and H are non-terminal symbols, p, d
z = 1
and c are terminal symbols. Which of the following
statement(s) is/are correct?
at i = 0:- S1. LL(1) can parse all strings that are generated using
z = 12 mod 8 = 1 grammar G
S2. LR(1) can parse all strings that are generated using {
grammar G char s1[7] = “1234”, *p;
(A) Only S1 p = s1 + 2;
(B) Only S2 *p = ‘0’;
(C) Both S1 and S2 printf(“%s”, s1);
(D) Neither S1 nor S2 }
What will be printed by the program?
Solution:
(A) 12 (B) 120400
S → F|H
(C) 1204 (D) 1034
F → |C
H → d|c Solution:
0 1 2 3
LR(1)
S1 1 2 3/0 4 \0
S S1 → S., $
S1 →. S, $ E S → F., $
S →. F, $
S →. H, $ H
S → H., $
F →. p, $
p
F →. c, $ P
F → p., $
H →. d, $ d P = S1 = 2
H →. c, $
F → d., $ P is a pointer pointing to the 3rd character of S1
c
∗ P = ‘0’;
F → c., $
H → c., $ RR conflict it rewrites the value of S1[2] (‘3’ is replaced with 0)
S1 had ‘1204’, when S1 is printed, it prints 1204.
Hence, the correct option is (C).
The above grammar is having RR conflict therefore it is
Question Number: 43 Question Type: MCQ
not LR(1) grammar.
Suppose U is the power set of the set S = {1,2,3,4,5,6}.
LL(1)
For any T ∈ U, let |T| denote the number of elements in
S → F T and T′ denote the complement of T. For any T, R ∈
S → H U, let T \R be the set of all elements in T which are not
F → p|c in R. Which one of the following is true?
H → d|c (A) ∀ X ∈ U (|X| = |X ′|)
(B) ∃X ∈ U ∃Y ∈ U (|X| = 5, |Y| = 5 and X ∩ Y = f)
First (S) = {p, c, d}
The productions of S → F, S → H will be at (C) ∀X ∈ U ∀Y ∈ U(|X| = 2, |Y| = 3 and X \ Y = f)
M[S, c] (D) ∀X ∈ U ∀Y ∈ U (X \ Y = Y ′ \ X ′)
Question Number: 44 Question Type: MCQ Question Number: 47 Question Type: MCQ
Consider the relation X(P, Q, R, S, T, U) with the Let # be a binary operator defined as
following set of functional dependencies X # Y = X ′ + Y ′ where X and Y are Boolean variables.
F = { Consider the following two statements.
{P, R} → {S, T} (S1) (P # Q) # R = P # (Q # R)
{P, S, U} → {Q, R} (S2) Q#R=R#Q
} Which of the following is/are true for the Boolean vari-
Which of the following is the trivial functional depend- ables P, Q and R?
ency in F+, where F+ is closure of F? (A) Only S1 is true
(A) {P, R} → {S, T} (B) {P, R} → {R, T} (B) Only S2 is true
(C) {P, S} → {S} (D) {P, S, U} → {Q} (C) Both S1 and S2 are true
Solution: (D) Neither S1 nor S2 are true
Trivial: Solution: X # Y = X ′ + Y ′ = (XY) ′ – this is NAND gate.
If A → B (S1) = (P # Q) # R ≠ P # (Q # R)
B has to be subset of A
NAND gate does not obey associative law
{P, S} → {S}
((PQ) ′.R) ′ ≠ (P.(QR) ′) ′
{S} is subset of {P, S}
Hence, the correct option is (C). PQ + R ′ ≠ P ′ + QR
(S2) Q # R = R # Q
Question Number: 45 Question Type: MCQ
The maximum number of processes that can be in Commutative law is, true for NAND gate
Ready state for a computer system with n CPUs is (QR) ′ = (RQ) ′
(A) n (B) n2 Q ′ + R ′ = R ′ + Q ′
(C) 2n (D) Independent of n (S2) is true.
Solution: The maximum number of processes that are Hence, the correct option is (B).
running will be ‘n’, with each process assigned to CPU, Question Number: 48 Question Type: NAT
but the number of processes present in ready queue is Consider a software project with the following
independent of the number of CPU’s. information domain characteristics for calculation of
Hence, the correct option is (D). function point metric.
Question Number: 46 Question Type: MCQ Number of external inputs (I) = 30
Among simple LR (SLR), canonical LR, and look- Number of external outputs (O) = 60
ahead LR (LALR), which of the following pairs iden- Number of external inquiries (E) = 23
tify the method that is very easy to implement and the Number of files (F) = 08
method that is the most powerful, in that order? Number of external interfaces (N) = 02
(A) SLR, LALR It is given that the complexity weighting factors for I,
(B) Canonical LR, LALR O, E, F and N are 4, 5, 4, 10 and 7, respectively. It is
(C) SLR, canonical LR also given that, out of fourteen value adjustment factors
that influence the development effort, four factors are
(D) LALR, canonical LR not applicable, each of the other four factors has value
Solution: CLR is more powerful among all the parsers. 3, and each of the remaining factors has value 4. The
SLR parser is easy to implement, as it works on only computed value of function point metric is ______.
LR(0) items, CLR parser works on LR(0) items and Solution: Number of external inputs (I) = 30
their corresponding look – ahead’s.
Number of external outputs (O) = 60
Hence, the correct option is (C).
Number of external enquires (E) = 23
( )
−x
Eigen value 1 are The value of limx→∞ 1 + x 2 e
is
(A) {∞(4, 2, 1)|∞ ≠ 0, ∞ ∈ R} 1
(A) 0 (B)
(B) {∞(–4, 2, 1)|∞ ≠ 0, ∞ ∈ R} 2
(C) {∞( 2 , 0, 1)|∞ ≠ 0, ∞ ∈ R} (C) 1 (D) ∞
( )
e− x
(D) {∞(– 2 , 0, 1)|∞ ≠ 0, ∞ ∈ R} Solution: Let y = Lim 1 + x 2
x →∞
⎡1 −1 2⎤ ⎛
( ) ⎞
e− x
⇒ ln y = ln ⎜ lim 1 + x 2
Solution: Let A = ⎢⎢0 1 0 ⎥⎥ ⎝ x →∞ ⎟⎠
⎢⎣1 2 1 ⎥⎦ ⎡ ⎛
( ) ⎞⎤
e− x
= lim ⎢ln ⎜ 1 + x 2 ⎟⎠ ⎥
Given λ = 1 is an eigen value of A. x →∞ ⎣ ⎝ ⎦
⇒ x →∞ ⎣
(
= lim ⎡e − x ln 1 + x 2 ⎤
⎦ )
(A)
(B)
The result is head
The result is tail
= lim ⎢
(
⎡ ln 1 + x 2 ⎤
⎥
) (C) If the person is of Type 2, then the result is tail
x →∞ ⎢ ex ⎥ (D) If the person is of Type 1, then result is tail
⎣ ⎦
Solution: Let us assume that the person is of Type 1 –
⎡ 2x ⎤ a truth teller. His statement is ‘The result of the toss is
⇒ = lim ⎢
⎢ 1+ x 2 ⎥
⎥
( ) head if and only if I am telling the truth.’ We can sym-
x →∞ ⎢ ex ⎥ bolize this as S: ‘p if q’.
⎢⎣ ⎥⎦ S is true, q is true.
(By L’Hospitals Rule) ∴ p is true.
⎡ ⎤ Let us assume that the person is of Type 2 – a liar.
⎢1 2 x ⎥ His statement is S: ‘p iff q’
= lim ⎢ x . ⎥
x →∞ ⎢ e ⎛ 1 ⎞⎥ S is false, q is false.
⎢ ⎜⎝1 + 2 ⎟⎠ ⎥
⎣ x ⎦ ∴ p has to be true.
⇒ ln y = 0 In either case, P is true, the result of the toss is head.
⇒ y = e0 = 1 Hence, the correct option is (A).
( )
e− x
⇒ lim 1 + x 2 =1 Question Number: 58 Question Type: MCQ
x →∞ While inserting the elements 71, 65, 84, 69, 67, 83
Hence, the correct option is (C). in an empty binary search tree (BST) in the sequence
shown, the element in the lowest level is
Question Number: 56 Question Type: NAT
(A) 65 (B) 67 (C) 69 (D) 83
The number of 4 digit numbers having their digits in
non-decreasing order (from left to right) constructed by 71
using the digits belonging to the set {1, 2, 3} is _____.
Solution: Following are the 4 digit numbers having 65 84
their digits in non-decreasing order (from left to right)
69 83
constructed by using the digits 1, 2 and 3.
1111 1122 1222 1333 2233
67
1112 1123 1223 2222 2333
1113 1133 1233 2223 3333 Solution: The element in the lowest level is 67.
∴ The number of such 4 digit numbers = 15. Hence, the correct option is (B).
Hence, the correct Answer is (15). Question Number: 59 Question Type: MCQ
Question Number: 57 Question Type: MCQ The result of evaluating the postfix expression 10 5 +
In a room there are only two types of people, namely 60 6 / * 8 – is
Type 1 and Type 2. Type 1 people always tell the truth (A) 284 (B) 213 (C) 142 (D) 71
and Type 2 people always lie. You give a fair coin to a
Solution:
person in that room, without knowing which type he
is from and tell him to toss it and hide the result from 10 5 + 60 6 / ∗ 8 –
you till you ask for it. Upon asking, the person replies + 6 / ∗ –
the following 5 60 60 10 8
‘The result of the toss is head if and only if I am telling
10 15 15 15 150 142
the truth.’
Which of the following options is correct? Result: 142
Hence, the correct option is (C).
As the real and seeded faults are of same nature then Solution: Given,
1 Block size = 24 B
number of undetected real faults = × 84
3 So word offset = 4 bits
= 28 Number of lines = 212 so line field length = 12 bits
Hence, the correct Answer is (28). Main memory address is (E201F)16 and main memory
Question Number: 65 Question Type: MCQ has 20–bits length address:
Consider a machine with a byte addressable main
TAG Lines Offset
memory of 220 bytes, block size of 16 bytes and a direct
mapped cache having 212 cache lines. Let the addresses In the address last 4 bits will be offset that is F
of two consecutive bytes in main memory be (E201F)16
Next 12 bits from and will be line field that is 201 and
and (E2020)16. What are the tag and cache line address
remaining bits, tag as E.
(in hex) for main memory address (E201F)16?
Hence, the correct option is (A).
(A) E, 201 (B) F, 201
(C) E, E20 (D) 2, 01F
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Question 1 to Question 5 carry 1 mark each and Solution: When there is a significant drop in the
Question 6 to Question 10 carry 2 marks each. water level in the lakes supplying water in the city.
The plausible course of action has to be the ones which
Question Number: 1 Question Type: MCQ
are practically possible.
Select the alternative meaning of the underlined part of
Among the three given courses of action, only I and II
the sentence.
are practically possible. III speaks about banning the
The chain snatchers took to their heels when the police water supply in lower areas.
party arrived.
This is not an appropriate solution to the existing prob-
(A) took shelter in a thick jungle lem. And stopping or banning water in the lower areas
(B) open indiscriminate fire for proper supply in the city is unethical as well.
(C) took to flight Hence, the correct option is (A).
(D) unconditionally surrendered Question Number: 3 Question Type: NAT
Solution: ‘Took to their heels’ means to run away. This The pie chart below has the breakup of the number of
supports choice (C) and the other answer choices are students from different departments in an engineering
incorrect. college for the year 2012. The proportion of male to
Hence, the correct option is (C). female students in each department is 5:4. There are 40
males in Electrical Engineering. What is the difference
Question Number: 2 Question Type: MCQ between the numbers of female students in the Civil
The given statement is followed by some courses of department and the female students in the Mechanical
action. Assuming the statement to be true, decide the department?
correct option.
Statement:
There has been significant drop in the water level in the Electrical
lakes supplying water to the city. 20%
Course of action: Computer
science
(I) The water supply authority should impose a Mechanical 40%
partial cut in supply to tackle the situation. 10%
(II) The government should appeal to all the residents
through mass media for minimal use of water.
Civil
(III) The government should ban the water supply in 30%
lower areas.
(A) Statements I and II follow.
(B) Statements I and III follow. Solution: Number of students in the Electrical
(C) Statements II and III follow. ⎛ 9⎞
Engineering department = 40 ⎜ ⎟ = 72.
(D) All statements follow. ⎝ 5⎠
(I) p + m + c = 27/20 4 2 23 18 3
5 5 31 12 1
(II) p + m + c = 13/20
(III) (p) × (m) × (c) = 1/10 What is the average of the marks obtained by the class
(A) Only relation I is true. in the examination?
(B) Only relation II is true. (A) 2.290 (B) 2.970
(C) Relations II and III are true. (C) 6.795 (D) 8.795
(D) Relations I and III are true. Solution: Average of the marks obtained by the class
Solution:
2 ( 21) + 3 (15) + 1(11) + 2 ( 23) + 5 (31)
VD for probabilities =
Total number of students
Total = 1
299
p m = = 6.795
44
Hence, the correct option is (C).
a d b
Question Number: 6 Question Type: MCQ
g
e f
Didn’t you buy ______ when you went shopping?
(A) any paper (B) much paper
c (C) no paper (D) a few paper
Solution: The use of ‘any paper’ is correct. The use of
c
‘a few’ would have been correct had it been followed by
‘papers’ and ‘not paper’. The rest of the choices render
p + m + c = a + b + c + 2 (d + e + f ) +3g the sentence incorrect.
= (a + b + c +d + e + f + g) + (d + e + f + 2g) Hence, the correct option is (A).
Question Number: 7 Question Type: MCQ (B) Statement II alone is sufficient, but state-
Which of the following options is the closest in mean- ment I alone is not sufficient.
ing to the sentence below? (C) Both statements together are sufficient, but
She enjoyed herself immensely at the party. neither statement alone is sufficient.
(A) She had a terrible time at the party (D) Statement I and II together are not sufficient.
(B) She had a horrible time at the party Solution: The distance between the 2 floors of the
(C) She had a terrific time at the party building is 9 feet. And we are asked to find the number
(D) She had a terrifying time at the party of steps from first floor to second floor.
From I:
Solution: The question statement means that the girl
If each step is 3/4th foot.
had a very good time at the party. Choice (C) brings
this out. ‘Terrific’ means extremely good and is used in Let there be a total of n steps from first floor to record
a positive connotation. The other choices have negative floor.
3
contexts. × n = 9
4
Hence, the correct option is (C).
4×9
⇒ n= = 12
Question Number: 8 Question Type: MCQ 3
Which one of the following combinations is incorrect? So, I alone give this answer
(A) Acquiescence – Submission II speaks about the width of each step. From width, we
(B) Wheedle – Roundabout cannot get the number of steps between 1st and 2nd
(C) Flippancy – Lightness floors.
Hence, the correct option is (A).
(D) Profligate – Extravagant
Question Number: 10 Question Type: MCQ
Solution: ‘Acquiescence’ means ‘submission’
‘Wheedle’ is to persuade someone to do something for Given Set A = {2, 3, 4, 5} and Set B = {11, 12, 13,
you. ‘Roundabout’ means indirect. ‘Flippancy’ means a 14, 15}, two numbers are randomly selected, one from
lack of seriousness in grave matters. ‘Lightness’ means each set. What is the probability that the sum of the two
the same. ‘Profligate’ means ‘extravagant’. Thus, numbers equals 16?
choice (B) is the incorrect option. (A) 0.20 (B) 0.25
Hence, the correct option is (B). (C) 0.30 (D) 0.33
Question Number: 9 Question Type: MCQ Solution: Let the numbers randomly selected from
Based on the given statements, select the most appro- set A and set B be a and b respectively.
priate option to solve the given question. The number of (a, b) that can be formed taking a from
If two floors in a certain building are 9 feet apart, how A and b from B is 4 × 5 = 20. And the (a, b) for which
many steps are there in a set of stairs that extends from a + b = 16 are (2, 14), (3, 13), (4, 12), (5, 11).
the first floor to the second floor of the building? Number of favorable selections = 4
Statements: 4
Required probability = = 0.2
(I) Each step is ¾ foot high. 20
(II) Each step is 1 foot wide. Hence, the correct option is (A).
(A) Statement I alone is sufficient but statement II
alone is not sufficient.
vn = 5 elements
Now consider that a value 35 is inserted into this heap.
To insert an element ‘14’ (Worst case) After insertion, the new heap is
We need to compare with First 5 elements (A) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
∴ θ(n) (B) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
To delete an element, first we have to search for that (C) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
element.
(D) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
Assume that element to be deleted is 15(Worst case), to
search for 15, we need 5 comparisons. Solution: The given heap is
∴ θ(n) 40
Hence, the correct option is (B).
Question Number: 12 Question Type: NAT
30 20
Suppose that the stop-and-wait protocol is used on
a link with a bit rate of 64 kilobits per second and
20 milliseconds propagation delay. Assume that the 10 15 16 17
transmission time for the acknowledgement and the
processing time at nodes are negligible. Then the mini-
mum frame size in bytes to achieve a link utilization of 8 4
at least 50% is _______.
When 35 is inserted into the heap Solution: Cyclomatic complexity of the program is
(number of conditions in the program) + 1;
40
4+1=5
30 20 In the program, there is 1 while condition and 3 if
conditions.
10 15 Hence, the correct Answer is (5).
16 17 Question Number: 15 Question Type: NAT
Consider a LAN with four nodes S1, S2, S3 and S4. Time
8 4 is divided into fixed-size slots, and a node can begin its
35
transmission only at the beginning of a slot. A collision
is said to have occurred if more than one node transmit
It is not following ordering property, requires swaps. in the same slot. The probabilities of generation of a
There are 2 swaps i.e., swap (15, 35) and swap (30, 35) frame in a time slot by S1, S2, S3 and S4 are 0.1, 0.2,
The resultant heap is 0.3 and 0.4, respectively. The probability of sending a
frame in the first slot without any collision by any of
40
these four stations is ______.
35 20 Solution: When S1 is sending remaining nodes have
to listen.
30
The probability for S1 is (0.1) (1 – 0.2) (1 – 0.3)
10
16 17 (1 – 0.4) = 0.0336.
For S2 ⇒ (1 – 0.1) (0.2) (1 – 0.3) (1 – 0.4) = 0.0756
8 4 15 For S3 ⇒ (1 – 0.1) (1 – 0.2) (0.3) (1 – 0.4) = 0.1296
For S4 ⇒ (1 – 0.1) (1 – 0.2) (1 – 0.3) (0.4) = 0.2016
The new heap is The probability of sending a frame in the first slot with-
40, 35, 20, 10, 30, 16, 17, 8, 4, 15 out any collision by any of these 4 stations is
∴ 0.0336 + 0.0756 + 0.1296 + 0.2016 = 0.4404
Hence, the correct option is (B).
Hence, the correct Answer is (0.40 to 0.46).
Question Number: 14 Question Type: NAT
Consider the following C program segment. Question Number: 16 Question Type: MCQ
The binary operator ≠ is defined by the following truth
while(first <= last)
table:
{
p q p≠q
if (array[middle] < search)
0 0 0
first = middle + 1;
0 1 1
else if (array[middle] ==
1 0 1
search)
1 1 0
found = TRUE;
else last = middle – 1; Which one of the following is true about the binary
middle = (first + last)/2; operator ≠?
} (A) Both commutative and associative
if (first > last) notPresent = (B) Commutative but not associative
TRUE;
(C) Not commutative but associative
The cyclomatic complexity of the program segment is (D) Neither commutative nor associative
______.
Solution: p ≠ q ⇒ x or operation t
p ⊕ q = q ⊕ p, so commutative
p ⊕ (q ⊕ r) = (p ⊕ q) ⊕ r, so associative.
Hence, the correct option is (A). q r s
Question Number: 17 Question Type: NAT
99
1
∑ x ( x + 1) = ________ . p
x =1
99
1 99
⎛1 1 ⎞ Given, L3 = {(x, y, z)/x, y, z ∈ L}
Solution: We have ∑ x ( x + 1) = ∑ ⎜⎝ x − x + 1⎟⎠ ∴ The total number elements of L3 = The number of
x =1 x =1
ordered triples that can be formed using 5 elements =
⎛1 1 ⎞ ⎛ 1 1 ⎞ ⎛1 1 ⎞
=⎜ − +⎜ − +⎜ − +… 53 = 125.
⎝ 1 1 + 1⎠ ⎝ 2 2 + 1⎠ ⎝ 3 3 + 1⎟⎠
⎟ ⎟
Of all these ordered triples, all ordered triples satisfy
⎛ 1 1 ⎞ ⎛ 1 1 ⎞ the condition.
+⎜ − +⎜ −
⎝ 98 98 + 1⎠ ⎝ 99 99 + 1⎟⎠
⎟ x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z)
1 except those in which all the three elements q, r and s
=1−
100 are present in any order.
99 For, take x = q, y = r and z = s
= = 0.99
100 ∴ x ∨ (y ∧ z) = q ∨ (r ∧ s) = q ∨ p = q (1)
Hence, the correct Answer is (0.99). and
Question Number: 18 Question Type: MCQ (x ∨ y) ∧ (x ∨ z) = (q ∨ r) ∧ (q ∨ s) = t ∧ t = t(2)
Suppose ℒ = {p, q, r, s, t} is a lattice represented by the From (1) and (2),
following Hasse diagram: x ∨ (y ∧ z) ≠ (x ∨ y) ∧ (x ∨ z)
t
The number of ordered triples involving all the three
elements in any order = 3! = 6
q r s ∴ Probability that an element (x, y, z) ∈ L3 chosen
equi-probably satisfies x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z) is
125 − 6 119
Pr = =
p 125 125
1
For any x, y ∈ ℒ, not necessarily distinct, x ∨ y and Hence, < Pr < 1.
5
x ∧ y are join and meet of x, y, respectively. Let ℒ3 =
{(x, y, z): x, y, z ∈ ℒ} be the set of all ordered triplets Alternative Solution: The total number of elements
of the elements of ℒ. Let pr be the probability that an (ordered triples) of
element (x, y, z) ∈ ℒ3 chosen equi-probably satisfies L 3 = 125.
x ∨ (y ∧ z) = (x ∨ y) ∧ (x ∨ z). Then
Of these, the ordered triples, which start p, or t defi-
(A) pr = 0 (B) pr = 1 nitely satisfies the given condition. The 50 elements in
1 1 L3 that starts either with p or t. and also the ordered
(C) 0 < pr ≤ (D) < pr < 1 triples consisting of the three elements q, r, and s does
5 5
not satisfy the condition.
Solution: Given that L = {p, q, r, s, t} is a lattice with
1
Hasse diagram as shown below. ∴ < Pr < 1.
5
Hence, the correct option is (D).
p=q+r t7 = t6 – t2
1 s=p+q
u=s∗v
t8 = t7 + t4
The temporary variables required = 8
2 v=r+u 3 q=s∗u Hence, the correct Answer is (8).
Question Number: 24 Question Type: NAT
4 q=v+r
Consider an Entity-Relationship (ER) model in which
entity sets E and E are connected by an m : n relation-
The variables which are live both at the statement in ship R . E 1and E 2 are connected by a 1 : n (1 on the
basic block 2 and at the statement in basic block 3 of side of12E and 1 3
n on the side of E3) relationship R13.
1
the above control flow graph are
E1 has two single-valued attributes a11 and a12 of which
(A) p, s, u (B) r, s, u a11 is the key attribute. E2 has two single-valued attributes
(C) r, u (D) q, v a21 and a22 of which a21 is the key attribute. E3 has two
single-valued attributes a31 and a32 of which a31 is the key
Solution: Initially the variables which are live on entry
attribute. The relationships do not have any attributes.
to block 1 are {q, r, u} as these variables are required to
get the values defined in that block If a relational model is derived from the above ER
model, then the minimum number of relations that
– On exit from block 1 live variables are {r, u, v} as
would be generated if all the relations are in 3 NF is
p, q and s values are not required by other blocks.
_______.
– Live variables on entry to block 2 are {r, u} as
these variables are required to get v, and v is not Solution: R12 has m : n Relation
live as it is defined in block 2 Extra table is needed to store all the primary keys of
– On exit from block 2 live variables are {r, v} as 4 participating Entities in R12.
is no where used and v is used in block 4 a11 a12 a21 a22
– On entry to block 3, live variables are {r, u, v} and
on exit live variables are {r, q, v} as U is no where
m n
used and q is used in block 4 E1 R12 E2
t6 = t5 + s
R13 has 1 : n relation, place 1’s side primary key into Solution: In the question, on information given about
n’s side table. ‘z’. If we assume z as any stack symbol (either 0 or 1)
Hence, the correct Answer is (4). then we can able to solve the problem.
Given input is 101100
Question Number: 25 Question Type: NAT
Push till last but one is zero.
Consider the DFAs M and N given above. The number
of states in a minimal DFA that accepts the language The PDA will be q0 state till this input then, the stack
L(M) ∩ L(N) is _______. will have
1 0 1 1 0
b a a b
a b With last zero it will move to q1, without pushing or
M: N:
popping anything
Hence, the correct option is (A).
b a
10110
Solution: M is a DFA which accepts language with – With input 1, it checks 0 as top of stack, as 0 is in
strings ends with ‘a’ over Σ = {a, b} i.e., M = {a, aa, top, it pops that symbol, with next input 0, and it
ba, baa, aaa….} will check 1 as top. As 1 is top, pop that 1.
N is a DFA which accepts a language with strings ends – With next input 1 as input, it checks for 0 as top of
with ‘b’ over Σ = {a, b}, i.e., N = {b, bb, ab, bbb,…} the stack but top is 1
then L(M) ∩ L(N) is an empty language i.e., L(M) ∩
∴ Choice (A) is not the answer
L(N) = ∅. The automata for L(M) ∩ L(N)
Choice (A)
a, b 10010
– With input 1, it checks 0 as top of stack. As 0 is top
of stack, it pops that symbol
Number of states = 1 – With next input 0, it will check 1 as top As 1 is top,
Hence, the correct Answer is (1). pop that 1
Question Number: 26 Question Type: MCQ – With next input 0 as input, it checks for 1 as top of
Consider the NPDA < Q = {q0, q1, q2}, Σ = {0, 1}, Γ = the stack as top is 1 pop it similarly with the next
{0, 1, ⊥}, δ, q0, ⊥, F = {q2}>, where (as per usual con- inputs 1 and 0 it pops 0 and 1 respectively
vention) Q is the set of states, Σ is the input alphabet, – With left-out initial stack symbol on epsilon-input
Γ is the stack alphabet, δ is the state transition function, it riches final state
q0 is the initial state, ⊥ is the initial stack symbol, and Hence choice (B) is the answer
F is the set of accepting states. The state transition is Hence, the correct option is (B).
as follows:
Question Number: 27 Question Type: MCQ
1.Z → 1Z 0.1Z → Z
0.Z → 0Z 1.0Z → Z Let G = (V, E) be a simple undirected graph, and s be
q0 q1 q2 a particular vertex in it called the source. For x ∈ V,
let d(x) denote the shortest distance in G from s to x.
0/1/e.Z → Z e,1 → e A breadth first search (BFS) is performed starting at
s. Let T be the resultant BFS tree. If (u, v) is an edge
Which one of the following sequences must follow the of G that is not in T, then which one of the following
string 1011 00 so that the overall string is accepted by CANNOT be the value of d(u) – d(v)?
the automation? (A) –1 (B) 0
(A) 10110 (B) 10010 (C) 1 (D) 2
(C) 01010 (D) 01001
Solution: Solution:
Example:
Arrival times Burst time Priority
Case 1:
1 T1 – 0, 3, 6, 9, 12… 1 1
S
T2 – 0, 7, 14, 21…. 2 0.5
T3 – 0, 20, 40, … 4 0.25
After 3 Clk pulses, the circuit came back to original The frequency is reduced in pipe lined processor by a
state, mod-3 counter. ⎛ 2 ⎞
factor of ⎜ = 0.8
Sequence at QJK = 011011011….. ⎝ 2.5 ⎟⎠
Hence, the correct option is (A). ∴ 4 ∗ 0.8 = 3.2
Question Number: 30 Question Type: NAT Hence, the correct Answer is (3.2).
Consider a disk pack with a seek time of 4 milliseconds Question Number: 32 Question Type: NAT
and rotational speed of 10000 rotations per minute
Suppose the following disk request sequence (track
(RPM). It has 600 sectors per track and each sector
numbers) for a disk with 100 tracks is given: 45, 20,
can store 512 bytes of data. Consider a file stored in
90, 10, 50, 60, 80, 25, 70. Assume that the initial posi-
the disk. The file contains 2000 sectors. Assume that
tion of the R/W head is on track 50. The additional
every sector access necessitates a seek, and the aver-
distance that will be traversed by the R/W head when
age rotational latency for accessing each sector is
the Shortest Seek Time First (SSTF) algorithm is used
half of the time for one complete rotation. The total
compared to the SCAN (Elevator) algorithm (assuming
time (in milliseconds) needed to read the entire file is
that SCAN algorithm moves towards 100 when it starts
________.
execution) is ______ tracks.
Solution: Given seek time = 4 m sec
Solution:
Given rotational speed = 10000 rotations/minute SCAN
60 10 20 25 45 50 60 70 80 90 100
Number of rotations in one second = = 6 ms
10000
1
Rotational latency = × 6 ms = 3 ms
2
Given that there are 600 sectors/track
So, to access 600 sectors it takes 6 ms.
6 ms
To access 1 sector = = 0.01 ms
600
For accessing 2000 sectors it takes 2000 (0.01) = 20 ms Total head movements = 10 + 10 + 10 + 10 + 10 + 55
∴ total time needed to read the entire file + 20 + 5 + 10
= (2000(4 + 3) + 20)ms ⇒ 140.
= 14020 ms SSTF
Hence, the correct Answer is (14020). 1 10 20 25 45 50 60 70 80 90 100
5
Question Number: 31 Question Type: NAT
15
Consider a non-pipelined processor with a clock rate 10
10
of 2.5 gigahertz and average cycles per instruction of 10
four. The same processor is upgraded to a pipelined 65
processor with five stages; but due to the internal
pipeline delay, the clock speed is reduced to 2 giga- 10 5
hertz. Assume that there are no stalls in the pipeline.
The speed up achieved in this pipelined processor is ∴ Total head movements = 5 + 15 + 10 + 10 + 10 + 65
______. + 5 +10
nk ⇒ 130
Solution: Speed-up =
( K + n − 1) ∴ The extra distance that is traversed
Assume that n = 16
= 140 – 130
k = 5 (stages)
16 ∗ 5 80 = 10
S (for 5 stages) = = =4
( 5 + 16 − 1) 20 Hence, the correct Answer is (10).
36
∫ x2
∫ cos t ( −dt )
π
1
π
π
83 2
28 = − ∫ cos tdt
92 π
π
1 = ∫ cos t dt
π
2
✓✓✓✓✓✓✓ ✓ ✓✓✓
= sin t ]π
π
3, 8, 2, 3, 9, 1, 6, 3, 8, 9, 3, 6, 2, 1, 3 2
= 9 page faults π
= sin π – sin = –1
2
LRU
Hence, the correct Answer is (–1).
3
86 Question Number: 35 Question Type: MCQ
28 Consider the following 2 × 2 matrix A, where two ele-
ments are unknown and are marked by a and b. The
91
Eigen values of this matrix are -1 and 7. What are the
12 values of a and b?
⎡1 4⎤
✓✓✓ ✓✓✓ ✓ ✓✓ A= ⎢ ⎥
3, 8, 2, 3, 9, 1, 6, 3, 8, 9, 3, 6, 2, 1, 3 ⎣b a⎦
= 9 page faults a = 6, b = 4
(A) (B) a = 4, b = 6
a = 3, b = 5
(C) (D) a = 5, b = 3
Both LRU and FIFO incur same number of page faults.
Hence, the correct option is (A). ⎡1 4 ⎤
Solution: Given matrix is A = ⎢ ⎥
Question Number: 34 Question Type: NAT ⎣b a ⎦
Given the Eigen values of A are –1 and 7. We know that
2π
cos (1 x )
∫ x2
dx = _________. the sum of the Eigen values of A.
1π = Trace of A
Solution: Consider the integral ⇒ – 1 + 7 = 1 + a
cos 1( x ) dx = ⇒ a = 5
∫ ⎡⎣cos ( 1 x )⎤⎦
2 2
π π
1
∫ x 2
x2
dx (1) The product of the Eigen values of A = The determinant
1
π
1
π of A.
3 Raj 3 Math 80
9 6
2 Rohit 2 Math 75 C D
2 Rohit 2 Physics 65
Solution: The edge weight of AB is 10 (It has to be >9)
Output:
The edge weight of CD (has to be >15) is 16
Student Name sum (marks)
Raj 310 ED Edge weight is 7 (It has to be >6)
Rohit 140 All edge weights =
∴ 2 tuples AB = 10
Hence, the correct Answer is (2). CD = 16
Question Number: 38 Question Type: MCQ ED = 7
What is the output of the following C code? Assume
AC = 9
that the address of x is 2000 (in decimal) and an integer
requires four bytes of memory. BC = 2
int main ( ) { BE = 15
unsigned int x[4] [3] =
EF = 4
{{1. 2, 3}, {4, 5, 6}, {7, 8, 9},
{10, 11, 12}}; DF = 6
printf (“%u, %u, %u”, x + 3, Total = 69
*(x + 3), *(x + 2) + 3);
Hence, the correct Answer is (69).
}
Question Number: 40 Question Type: MCQ
(A) 2036, 2036, 2036 (B) 2012, 4, 2204
Consider the following C function.
(C) 2036, 10, 10 (D) 2012, 4, 6
int fun1(int n) {
Solution: All the expressions int i, j, k, p, q=0;
(x + 3), ∗(x + 3), ∗(x + 2) + 3 points to the same address for (i=1; i<n; ++i) {
It prints the address of the first element of fourth row in p=0;
an array i.e., x[3][0] (or) x[3] (i.e., element 10)
for (j=n; j>1; j=j/2)
The address of x[3] is 2036
++p;
∴ It prints 2036 2036 2036.
for (k=1; k<p; k=k*2)
Hence, the correct option is (A).
++q;
Question Number: 39 Question Type: NAT }
The graph shown below has 8 edges with distinct inte- return q;
ger edge weights. The minimum spanning tree (MST) }
is of weight 36 and contains the edges: {(A, C), (B, C),
Which one of the following most closely approximates
(B, E), (E, F), (D, F)}. The edge weights of only those
the return value of the function fun1?
edges which are in the MST are given in the figure
shown below. The minimum possible sum of weights (A) n3 (B) n(logn)2
of all 8 edges of this graph is _______. (C) nlogn (D) nlog(log n)
( )
equations given in the options below, c is a constant.
⇒ ln y = ln Lim x
1
x
⎡1 ⎤
= Lim ⎢ x ⎥ [By L’ Hospital’s Rule] T(7) T(1)
x →∞ ⎢ 1 ⎥
⎣ ⎦
T(6) T(1)
∴ ln y = 0
⇒ y = 1 T(5) T(1)
⇒ Lim x = 1
1
x
x →∞ T(4) T(1)
Hence, the correct option is (C).
Question Number: 44 Question Type: MCQ T(3) T(1)
Question Number: 51 Question Type: MCQ Question Number: 53 Question Type: MCQ
For a set A, the power set of A is denoted by 2A. If A = For computers based on three-address instruction
{5, {6}, {7}}, which of the following options are true? formats, each address field can be used to specify
I. ∅ ∈ 2A II. ∅ ⊆ 2A which of the 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
(A) Either S1 or S2
Solution: Given A = {5, {6}, {7}}
(B) Either S2 or S3
⇒ The power set of A = 2A = {∅, {5}, {{6}}, {{7}},
{5,{6}}, {{6}, {7}}, {{7}, 5}, {5,{6}, {7}}} (C) Only S2 and S3
Clearly, ∅ ∈ 2A (D) All of S1, S2 and S3
∴ I is TRUE Solution: Computer with 3 address instruction format
Because the null set ∅ is a subset of every set, can use each address field to specify either processor
register (or) memory operand.
∅ ⊆ 2A
Example:
∴ II is TRUE
ADD R1, A, B R1 ← M[A] + M[B]
As {5, {6}} is an element of 2A
ADD R2, C, D R2 ← M[C] + M[D]
{5, {6}} ∈ 2A
MUL X, R1, R2 M[X] ← R1 ∗ R2
∴ III is TRUE
Hence, the correct option is (A).
An element of a set cannot be subset of that set.
Question Number: 54 Question Type: MCQ
∴ {5, {6}} Ü 2A
Suppose two hosts use a TCP connection to transfer
∴ IV is NOT TRUE.
a large file. Which of the following statements is/are
Note that {5, {6}} Ü 2A, but {{5, {6}}} ∈ 2A FALSE with respect to the TCP connection?
Hence, I, II and III are only TRUE. I. If the sequence number of a segment is m, then
Hence, the correct option is (C). the sequence number of the sub sequent segment
Question Number: 52 Question Type: MCQ is always m + 1.
Consider a 4-bit Johnson counter with an initial value II. If the estimated round trip time at any given point
of 0000. The counting sequence of this counter is of time is t sec, the value of the retransmission
timeout is always set to greater than or equal to t
(A) 0, 1, 3, 7, 15, 14, 12, 8, 0 sec.
(B) 0, 1, 3, 5, 7, 9, 11, 13, 15, 0 III. The size of the advertised window never changes
(C) 0, 2, 4, 6, 8, 10, 12, 14, 0 during the course of the TCP connection.
(D) 0, 8, 12, 14, 15, 7, 3, 1, 0
IV. The number of unacknowledged bytes at the
sender is always less than or equal to the adver-
Solution: 4 bit Johnson counter (or) twisted ring counter
tised window.
Clk Q3 Q2 Q1 Q0 Value
(A) III only (B) I and III only
0 0 0 0 0 0
(C) I and IV only (D) II and IV only
1 1 0 0 0 8
2 1 1 0 0 12 Solution:
3 1 1 1 0 14 I.
The sequence number of the subsequent segment
4 1 1 1 1 15 depends on the number of 8 byte characters of the
5 0 1 1 1 7 current segment (False)
6 0 0 1 1 3
II.
Window will keep changing depending on network
7 0 0 0 1 1
traffic and processing capability.
8 0 0 0 0 0
Hence, the correct option is (D). Hence, the correct option is (B).
Solution: Context free language (CFL) is not closed Solution: The functions P1 and P2
under complement.
P1( ) P2( )
If Language ‘L’ is recursive enumerable but not
{ {
recursive, then L is not recursive enumerable.
C = B – 1 ; → 1 D = 2 ∗ B ; → 3
Option-I is true
B = 2 ∗ C ;→ 2 B = D – 1 ; → 4
If L1 is CFL then L1 is not CFL, but the language L1 is
} }
recursive, so this is true.
Option-II is false Let us number the instructions in P1( ) and P2( ) as 1,
L2 is recursive enumerable but ‘not recursive’, i.e., L2 2, 3, 4.
is not recursive enumerable. So, it is not recursive. The possible execution sequence of instructions and
Option-III is false the value of B is
(I) 1, 2, 3, 4 ⇒ B = 3
L1 is not context free.
(II) 1, 3, 2, 4 ⇒ B = 3
Option-IV is true
(III) 1, 3, 4, 2 ⇒ B = 2
L1 is recursive and L2 is Recursive Enumerable. (IV) 3, 1, 2, 4 ⇒ B = 2
Union of recursive and recursive enumerable is recur- (V) 3, 1, 4, 2 ⇒ B = 2
sive enumerable.
(VI) 3, 4, 1, 2 ⇒ B = 4
Hence, the correct option is (D).
The value of B can be 2, 3, 4.
Question Number: 60 Question Type: NAT Hence, the correct Answer is (3).
Consider a system with byte-addressable memory,
Question Number: 62 Question Type: MCQ
32-bit logical addresses, and 4 kilobyte page size and
page table entries of 4 bytes each. The size of the page SELECT operation in SQL is equivalent to
table in the system in megabytes is _______. (A) the selection operation in relational algebra.
Solution: Logical address = 32 bits (B) the selection operation in relational algebra,
except that SELECT in SQL retains duplicates.
Page size = 4 K byte (4 KB)
Page table entry = 4 bytes each (C) the projection operation in relational algebra.
Logical address space = 232 = 4 GB (D) the projection operation in relational algebra,
except that SELECT in SQL retains d uplicates.
Logical address space
Number of pages =
page size Solution: Let us consider the following
4 GB SELECT NAME
= = 1 MB
4 KB FROM Student
Page table size = 1 MB × page table Entry WHERE Grade = ‘A’
= 1 MB × 4B = 4 MB πNAME (σGrade=’A’ (student))
Hence, the correct Answer is (4). ∴ π – eliminates duplicates from the result.
∴ To eliminate duplicates in SQL query, we have to use
Question Number: 61 Question Type: NAT
DISTINCT keyword in SELECT clause.
The following two functions P1 and P2 that share a var-
Hence, the correct option is (D).
iable B with an initial value of 2 execute concurrently.
P1 ( ) { P2 ( ) { Question Number: 63 Question Type: MCQ
C = B – 1; D = 2 * B; A file is organized so that the ordering of data records
B = 2 * C; B = D – 1; is similar to that of the ordering of data entries in some
index. Then that index is called
} }
(A) Dense (B) Sparse
The number of distinct values that B can possibly take
(C) Clustered (D) Unclustered
after the execution is _______
⎡ 2 2⎤ ⎡ l11 0 ⎤ ⎡1 u12 ⎤
⇒ ⎢ 4 9⎥ = ⎢l
⎣ ⎦ ⎣ 21 l22 ⎥⎦ ⎢⎣0 1 ⎥⎦
∗a ∗b
⎡ l11 l11 μ12 ⎤ ⎡ 2 2⎤
⇒ ⎢l ⎥=⎢ ⎥
⎣ 21 l21 u12 + l22 ⎦ ⎣ 4 9⎦ The value of (c – a – b) is (5 – 4 – 6).
Comparing the corresponding elements on both sides, ∴ –5
we have l11 = 2, l21 = 4 It prints –5
l11 u12 = 2 Hence, the correct Answer is (–5).
2 2
⇒ u12 = = =1
l11 2
Wrong answer for MCQ will result in negative marks, (-1/3) for 1 Mark Questions and (-2/3) for 2 Marks
Question.
General Aptitude
Number of Questions: 10 Section Marks: 15.0
Question 1 to Question 5 carry 1 mark each and Solution: Area of triangle PQR = Area of triangle
Question 6 to Question 10 carry 2 marks each. PQS+
Question Number: 1 Question Type: MCQ Area of triangle PSR
Out of the following four sentences, select the most 1
Area of triangle PQR = (r) (q) sin ∠ P
suitable sentence with respect to grammar and usage: 2
1 rq
(A) Since the report lacked needed information, it = (r) (q) sin (2 ∠ QPS) = sin 120°
2 2
was of no use to them.
(∵ PS is the angle bisector of ∠ QPR)
(B) The report was useless to them because there
were no needed information in it. 1 1 1
∴ (r q sin 120°) = (r (PS) sin 60°) +
(C) Since the report did not contain the needed 2 2 2
information, it was not real useful to them. (q (PS) sin 60°)
(D) Since the report lacked needed information, it ⎛ 3⎞ 3 rq
would not have been useful to them. r q ⎜ ⎟ = r (PS) PS =
⎝ 2 ⎠ 2 r+q
Solution: Choice (A) is free of all errors. Though the Hence, the correct option is (B).
article ‘the’ before ‘needed’ would render it correct, but
of the given choices, (A) is correct. The use of ‘there Question Number: 3 Question Type: NAT
were’ in (B) is incorrect. ‘Real useful’ is ungrammati-
cal in (C). ‘Not had been’ is ungrammatical in (D). If p, q, r, s are distinct integers such that:
Hence, the correct option is (A). f (p, q, r, s) = max(p, q, r, s)
g(p, q, r, s) = min(p, q, r, s)
Question Number: 2 Question Type: MCQ
h(p, q, r, s) = remainder of (p × q)/(r × s) if (p × q) >
In a triangle PQR, PS is the angle bisector of ∠QPR (r × s) or remainder of (r × s)/(p × q) if (r × s) >
and ∠QPS = 60o. What is the length of PS? (p × q)
P Also a function fgh(p, q, r, s) = f (p, q, r, s) × g(p, q, r, s)
× h(p, q, r, s)
Also the same operations are valid with two variable
r q functions of the form f (p, q)
What is the value of fg(h(2,5,7,3), 4,6,8)?
⎛ 21⎞
S Solution: h (2, 5, 7, 3) = remainder of ⎜ ⎟ = 1
Q R ⎝ 10 ⎠
(∵ (r × s) > (p × q))
p
fg (h (2,5,7,3),4,6,8) = fg (1,4,6,8)
(q + r ) (B)
(A)
qr = f (1,4,6,8) × g (1,4,6,8)
qr (q + r ) = max (1, 4, 6, 8) × min (1, 4, 6, 8) = 8 × 1 = 8
( q + r )2
(
(C) q 2 + r 2 (D) ) qr
Hence, the correct Answer is (8).
What will be the total weight of 10 poles each of same 10W = 160 + 2W
weight? 8W = 160
Statements:
W = 20 kg
(I) One fourth of the weight of a pole is 5 kg.
(II) The total weight of these poles is 160 kg more So 10W = 200 kg
than the total weight of two poles. (II) alone also is sufficient to arrive at the answer.
(A) Statement I alone is not sufficient. So, both (I) and (II) alone are sufficient to answer the
(B) Statement II alone is not sufficient. question.
(C) Either I or II alone is sufficient. Hence, the correct option is (C).
(D) Both statements I and II together are not suf-
ficient. Question Number: 10 Question Type: MCQ
Solution: We are asked to find the total height 10 Consider a function f (x) = 1 − |x| on −1 ≤ x ≤ 1. The
notes, each of same height value of x at which the function attains a maximum and
the maximum value of the function are:
From (I) alone we know that one fourth weight of a
pole = 5 kg (A) 0, −1 (B) −1, 0
Let us assume each pole to be of height W units (C) 0, 1 (D) −1, 2
1 Solution: f (x) is maximum when |x| is minimum i.e.
W = 5 kg
4 when |x| is zero i.e. when x is zero.
W = 20 Kg Maximum value of f (x) = 1 – 0 = 1. Which occurs at
Weight of each pole = 20K x = 0.
Then, 10 poles = 200 kgs Hence, the correct option is (C).
So, (I) alone can give us the answer (II) alone tells us
let us assume each pole to be of height ‘W’
(B) A cookie gains entry to the user’s work area 128.96.1010 0111.1001 0110
through an HTTP header. 255.255.1111 1110. 0000 0000
(C) A cookie has an expiry date and time. 128.96. 166 .0
(D) Cookies can be used to track the browsing
∴ The next hop will be R2
pattern of a user at a particular site.
i – a, ii – c, iii – e, iv – d
Solution: A cookie is a piece of code which is sent
from a website and stored in web browser. It has the Hence, the correct option is (A).
potential to compromise the security of a user.
Question Number: 14 Question Type: MCQ
Hence, the correct option is (A).
Host A sends a UDP datagram containing 8880 bytes
Question Number: 13 Question Type: MCQ of user data to host B over an Ethernet LAN. Ethernet
Consider the following routing table at an IP router: frames may carry data up to 1500 bytes (i.e., MTU =
1500 bytes). Size of UDP header is 8 bytes and size
Network No. Net Mask Next Hop of IP header is 20 bytes. There is no option field in IP
128.96.170.0 255.255.254.0 Interface 0 header. How many total number of IP fragments will be
128.96.168.0 255.255.254.0 Interface 1 transmitted and what will be the contents of offset field
128.96.166.0 255.255.254.0 R2 in the last fragment?
128.96.164.0 255.255.252.0 R3 (A) 6 and 925 (B) 6 and 7400
0.0.0.0 Default R4 (C) 7 and 1110 (D) 7 and 8880
For each IP address in group I identify the correct Solution: User data = 8880 bytes
choice of the next hop from group II using the entries MTU = 1500 bytes
from the routing table above.
UDP header = 8 bytes
Group I Group II
IP header = 20 bytes
(i) 128.96.171.92 (a) Interface 0
Header length = (20 + 8) = 28 bytes
(ii) 128.96.167.151 (b) Interface 1
(iii) 128.96.163.151 (c) R2 Actual data in each fragment = 1500 – 28 = 1472 bytes
(iv) 128.96.165.121 (d) R3
Data Header Offset
(e) R4
1st fragment 1472 28 0/8 = 0
2 nd
fragment 1472 28 1472/8 = 184
(A) i-a, ii-c, iii-e, iv-d (B) i-a, ii-d, iii-b, iv-e
(C) i-b, ii-c, iii-d, iv-e (D) i-b, ii-c, iii-e, iv-d 2 ∗1472
3rd fragment 1472 28 = 368
8
Solution: (i) Given IP address 128.96.171.92
3 ∗1472
4th fragment 1472 28 = 552
Perform AND operation with given masks. If the result 8
gives any specific network number, the next hop of that
4 ∗1472
network will be chosen. 5th fragment 1472 28 = 736
8
128.96.171.92 5 ∗1472
6th fragment 1472 28 = 920
255.255.254.0 8
Question Number: 15 Question Type: MCQ (A) Undo: T3, T1; Redo: T2
Assume that the bandwidth for a TCP connection is (B) Undo: T3, T1; Redo: T2, T4
1048560 bits/sec. Let α be the value of RTT in milli- (C) Undo: none; Redo: T2, T4, T3, T1
seconds (rounded off to the nearest integer) after which (D) Undo: T3, T1, T4; Redo: T2
the TCP window scale option is needed. Let β be the
maximum possible window size with window scale Solution: Check point:
option. Then the values of α and β are The automatic recovery processes by identifying a
point at which all completed transactions are guaran-
(A) 63 milliseconds, 65535 × 214 teed have been written to the database device.
(B) 63 milliseconds, 65535 × 216 A check point creates a known good point from
(C) 500 milliseconds, 65535 × 214 which the SQL server database engine can start apply-
ing changes contained in the log during recovery after
(D) 500 milliseconds, 65535 × 216
an unexpected crash.
Solution: In TCP connection, default window size is Before checkpoint:
64 kilobytes.
→ T4 is committed
If then, Round Trip Time (RTT) is the main factor to
No need to REDO T4
decide TCP throughput between 2 locations.
→ T1 is not committed
If, RTT = 10 msec ⇒ TCP throughput = 52428000 bps Need to UNDO T1
RTT = 20 msec ⇒ TCP throughput = 26214000 bps
After checkpoint:
RTT = 100 msec ⇒ TCP throughput = 5242800 bps
→ T2 is committed, but for recovery, we should
RTT = 200 msec ⇒ TCP throughput = 2621400 bps REDO from the point of ‘checkpoint’.
RTT = 300 msec ⇒ TCP throughput = 1747600 bps → T3 is not committed,
RTT = 500 msec ⇒ TCP throughput = 1048560 bps Need to UNDO.
α = 500 msec Hence, the correct option is (A).
If we are not using TCP window scaling option, TCP
Question Number: 17 Question Type: MCQ
window size will be used as 64 kilobytes ⇒ 65536 bytes.
Consider two relations R1(A, B) with the tuples (1, 5),
Actual window size, using TCP window scaling, is
(3, 7) and R2(A, C) = (1, 7), (4, 9). Assume that R(A, B,
= (window size) ∗ 2(window scale) C) is the full natural outer join of R1 and R2. Consider
= 65535 × 214 the following tuples of the form (A, B, C): a = (1,5,
null), b = (1, null, 7), c = (3, null, 9), d = (4,7,null),
The window scaling option may be sent only once dur- e = (1,5,7), f = (3,7, null), g = (4,null, 9). Which one of
ing a connection by each host, in its SYN packet. The the following statements is correct?
maximum valid scale value is 14 (RFC 1323).
(A) R contains a, b, e, f, g but not c, d.
Hence, the correct option is (C).
(B) R contains all of a, b, c, d, e, f, g.
Question Number: 16 Question Type: MCQ (C) R contains e, f, g but not a, b.
Consider a simple check pointing protocol and the fol- (D) R contains e but not f, g.
lowing set of operations in the log.
Solution: R1
(start, T4); (write, T4, y, 2, 3); (start, T1); (commit, T4);
(write, T1, z, 5, 7); A C
(checkpoint); 1 7
4 9
(start, T2); (write, T2, x, 1, 9); (commit, T2); (start, T3),
(write, T3, z, 7, 2); R2
If a crash happens now and the system tries to recover A B
using both undo and redo operations. What are the con- 1 5
tents of the undo list and the redo list? 3 7
R1 FULL OUTER JOIN R2 the average rotational delay and the controller’s transfer
A B C time is 10 times the disk transfer time, the average time
1 5 7 (in milliseconds) to read or write a 512-byte sector of
3 7 NULL the disk is ________.
4 NULL 9 Solution: 60 sec → 15000 rotations
a = (1, 5, Null) Not Present 60
= 4 ms ← 1 rotation
b = (1, Null, 7) Not present 15000
c = (1, 5, 7) present 1
∴ Average rotational delay = × 4 = 2 ms
f = (3, 7, Null) present 2
g = (4, Null, 9) Present Average seek time = 2 × Average rotational delay
Hence, the correct option is (C). = 2 × 2 ⇒ 4 ms
Question Number: 18 Question Type: MCQ 1 sec → 50 × 106 bytes
Consider six memory partitions of sizes 200 kB, 400 512
0.01 ms → ⇒ 512 bytes
kB, 600 kB, 500 kB, 300 kB and 250 kB, where kB 50 × 106
refers to kilobyte. These partitions need to be allotted Transfer time = 10 × 0.01 ms
to four processes of sizes 357 kB, 210 kB, 468 kB and = 0.1 ms
(7) a[t4] = -1
24 × 220
n= (8) j = j + 1
3
(9) if j < = 5 goto (3) → leader
n = 223
(10) i = i + 1 → leader
Number of pages = 223
(11) if i < 5 goto (2) → leader
Virtual address
The basic blocks for the above code.
Page number Page offset
B1 i=1
B2 j=1
B3 t1 = 5 ∗ i
23 13 t 2 = t1 + i
t3 = 4 ∗ t2
23 13 t4 = t3
a[t4] = –1
= 23 + 13 j=j+1
= 36 bits
Virtual address = 36 bits B4 if j < = 5 goto 3
(4) t2 = t1 + j
(5) t3 = 4 * t2
(6) t4 = t3
B2
(7) a[t4] = -1
(8) j = j + 1
(9) if j <=5 goto (3)
(10) i=i+1
B3
(11) if i<5 goto (2)
The number of nodes and edges in the control-flow-
graph constructed for the above code, respectively, are
(A) 5 and 7 (B) 6 and 7 B4
(C) 5 and 5 (D) 7 and 8
Solution:
(1) i = 1 B5
(2) j = 1
(3) t1 = 5 * i
(4) t2 = t1 + j
(5) t3 = 4 * t2 B6
(6) t4 = t3
Solution: Number of min terms The area bounded by the curve f(x), x- axis and the lines
[D1 + AB1 + A1C + AC1D + A1C1 D]1 x = –1 to x = 1
1 1 0 1
If we consider f = D1 + AB1 + A1C + C1D = A = ∫ f ( x ) dx = ∫ x ( ) dx = − ∫ x dx + ∫ x ( ) d
−13 −(1 3)
−13
Sum delay = 2 XOR = 4.8 µs Question Number: 45 Question Type: MCQ
Carry delay = XOR + AND + OR Let R be the relation on the set of positive integers such
= 4.8 µs that a R b if and only if a and b are distinct and have a
For 4 bit ripple carry adder common divisor other than 1. Which one of the follow-
ing statements about R is true?
tdelay = (n – 1)tcarry + tsum = 3 × 4.8 + 4.8
(A) R is symmetric and reflexive but not transitive
= 19.2 µs
(B) R is reflexive but not symmetric and not
Hence, the correct Answer is (19.2). transitive
Question Number: 43 Question Type: MCQ (C) R is transitive but not reflexive and not
Consider the following two statements. symmetric
S1: If a candidate is known to be corrupt, then he will (D) R is symmetric but not reflexive and not
not be elected. transitive
S2: If a candidate is kind, he will be elected.
Solution: Given R is a relation on the set of positive
Which one of the following statements follows from S1 integers Z+ defined by R = {(a, b)/a and b are distinct
and S2 as per sound inference rules of logic? and have a common divisor other than 1}
(A) If a person is known to be corrupt, he is kind (i) R is NOT reflexive because (a, b) ∈ R ⇒ a ≠ b
(B) If a person is not known to be corrupt, he is ⇒ (a, a) ∉ R, a ∈ Z+
not kind (ii) R is symmetric.
(C) If a person is kind, he is not known to be For, let (a, b) ∈ R ⇒ a and b are distinct and have
corrupt. a common divisor other than 1.
(D) If a person is not kind, he is not known to be ⇒ b and a are distinct and have a common divisor
corrupt. other than 1.
Solution: Given ⇒ (b, a) ∈ R
S1: If a candidate is known to be corrupt, then he will (iii) R is NOT symmetric
not be elected. For, (2, 6) ∈ R and (6, 9) ∈ R but (2, 9) ∈ R
S2: If a candidate is kind, he will be elected. ∴ R is symmetric, but not reflexive and not transitive.
Let P: A candidate is known to be corrupt. Hence, the correct option is (D).
Q: A candidate will be elected. Question Number: 46 Question Type: NAT
and R: A candidate is kind The number of divisors of 2100 is ______.
then S1 and S2 in symbolic form are
Solution: We have 2100 = 22 × 3 × 52 × 7
S1: P → Q and S2: R → Q
∴ The number of divisors of 2100 is (2 + 1) (1 + 1)
⇒ Q → P ( A → B ⇒ B → A) (2 + 1)(1 + 1)
Now, R → Q, Q → P ⇒ R → P (By hypothetical = 36.
syllogism) Hence, the correct Answer is (36).
i.e., If a candidate is kind, he is not known to be corrupt.
Question Number: 47 Question Type: NAT
Hence, the correct option is (C).
The larger of the two Eigen values of the matrix
Question Number: 44 Question Type: NAT ⎡ 4 5⎤
The cardinality of the power set of {0, 1, 2,…, 10} is ⎢ 2 1⎥ is______.
⎣ ⎦
_____.
⎡ 4 5⎤
Solution: Let A = ⎢ ⎥
Solution: Let A = {0,1, 2, 3,….., 10} ⎣ 2 1⎦
The cardinality of the power set of A = The number of The characteristic equation of A is |A – λI| = 0
elements in the power set of A = 2n(A) = 211 = 2048.
4−λ 5
Hence, the correct Answer is (2048). ⇒ =0
2 1− λ
3 – leaves
foo (B C D E F G H) 2 – (nodes with 2 children)
put char (A) Case 2:
foo (C D E F G H)
put char (B)
foo (D E F G H)
put char (C)
4 – leaves
foo ((space) E F G H) 3(nodes with 2 – children)
put char (D)
∴ For 20 – leaves, the number of nodes having 2 – chil-
It prints in reverse order of the string “A B C D” dren will be 19.
i.e., D C B A Hence, the correct Answer is (19).
Hence, the correct option is (D). Question Number: 56 Question Type: NAT
Consider the following C function
Question Number: 54 Question Type: MCQ
Consider a complete binary tree where the left and the int fun(int n) {
right sub-trees of the root are max-heaps. The lower int x=1, k;
bound for the number of operations to convert the tree if (n==1) return x;
to a heap is for (k=1; k<n; ++k)
x = x + fun(k) * fun(n – k);
Ω(log n) (B)
(A) Ω(n) return x;
Ω(n log n) (D)
(C) Ω(n2) }
Solution: Left and right sub trees are max-heaps The return value of fun(5) is _____.
Solution: Recurrence relation for above function is Solution: Lexical Analyzer is a finite automaton which
if n = 1 is constructed from pattern recognizing rules.
⎧ 1
⎪ n −1 Parsing of string is done using the production trees.
f (n) = ⎨
⎪1 + ∑ f ( k ) ⋅ f ( n − k ) if n >1 Register allocation is similar to that of graph coloring.
⎩ k =1 Expression evaluation is done using post order traversal.
Hence, the correct option is (C).
n 1 2 3 4 5 6
f(n) 1 2 5 15 51 188 Question Number: 60 Question Type: MCQ
In the context of abstract-syntax-tree (AST) and con-
Hence, the correct Answer is (51) trol-flow-graph (CFG), which one of the following is
Question Number: 57 Question Type: MCQ true?
A software requirements specification (SRS) document (A) In both AST and CFG, let node N2 be the suc-
should avoid discussing which one of the following? cessor of node N1. In the input program, the
(A) User interface issues code corresponding to N2 is present after the
code corresponding to N1.
(B) Non-functional requirements
(B) For any input program, neither AST nor CFG
(C) Design specification
will contain a cycle.
(D) Interfaces with third party software
(C) The maximum number of successors of a
Solution: Design specifications are not specified in node in an AST and a CFG depends on the
SRS documents it is done in software design phase. input program.
Hence, the correct option is (C). (D) Each node in AST and CFG corresponds to at
most one statement in the input program.
Question Number: 58 Question Type: MCQ
Consider two decision problems Q1, Q2 such that Q1 Solution: CFG may contain cycles, then option (A) is
reduces in polynomial time to 3-SAT and 3-SAT false.
reduces in polynomial time to Q2. Then which one of The CFG can contain cycle; therefore option (B) is
the following is consistent with the above statement? false.
(A) Q1 is in NP, Q2 is NP-Hard. Single node contains a block of statements, so option
(D) is false.
(B) Q2 is in NP, Q1 is NP-Hard.
The maximum number of successors in AST and CFG
(C) Both Q1 and Q2 are in NP.
depends on the input program.
(D) Both Q1 and Q2 are NP-Hard. Hence, the correct option is (C).
Solution: 3-SAT is a NP-complete problem if Q1 ≤P Question Number: 61 Question Type: MCQ
3 – SAT ≤P Q2 Consider the basic COCOMO model where E is the
then Q1 is in NP, but Q2 is not given in NP. effort applied in person-months, D is the development
Therefore Q2 is in NP-Hard. time in chronological months, KLOC is the estimated
Hence, the correct option is (A). number of delivered lines of code (in thousands) and
ab, bb, cb, db have their usual meanings. The basic
Question Number: 59 Question Type: MCQ COCOMO equations are of the form
Match the following
(A) E = ab(KLOC) exp(bb), D = cb(E) exp(db)
P. Lexical analysis 1. Graph coloring
(B) D = ab(KLOC) exp(bb), E = cb(D) exp(db)
Q. Parsing 2. DFA minimization
R. Register allocation 3. Post-order traversal
(C) E = ab exp(bb), D = cb(KLOC) exp(db)
S. Expression evaluation 4. Production tree (D) E = ab exp(db), D = cb(KLOC) exp(bb)
(A) P-2, Q-3, R-1, S-4 (B) P-2, Q-1, R-4, S-3 Solution: Basic COCOMO model take the form effort
(C) P-2, Q-4, R-1, S-3 (D) P-2, Q-3, R-4, S-1 applied (E) = ab(KLOC)b
Development time = Cb(E)db. The constraint that the sum of the accounts x and y
Hence, the correct option is (A). should remain constant is that of
(A) Atomicity (B) Consistency
Question Number: 62 Question Type: MCQ
(C) Isolation (D) Durability
A system has 6 identical resources and N processes
competing for them. Each process can request almost Solution:
2 resources. Which one of the following values of N read (y)
could lead to a deadlock? y = y + 50
(A) 1 (B) 2 Write (y)
(C) 3 (D) 4
read (x)
Solution: When N = 6,
x = x – 50
The system will lead to deadlock, when each process
Write (x)
requests for atmost 2 resources.
Assume that initial balance in each account is 1000
Let us consider 6 processes P1, P2, …., P6
(x + y = 2000)
Process P1 P2 P3 P4 P5 P6 read (x) → 1000 read (y) → 1000
Resources 1 1 1 1 1 1
x = x – 50 → 950 y = y + 50 → 1050
write (x) → 950 write (y) → 1050
As there are only 6 resources, if it allocates one resource 950 1050
to each process, then there are no resources to allocate ∴ x + y = 2000
to complete their request.
The balance in both accounts, after and before per-
Therefore it leads to deadlock, as they wait for a forming transactions is ‘consistent’.
resource which will never be allocated,
Hence, the correct option is (B).
Hence option is matching in the given question.
Question Number: 64 Question Type: NAT
Question Number: 63 Question Type: MCQ
With reference to the B+ tree index of order 1 shown
Consider the following transaction involving two bank below, the minimum number of nodes (including the
accounts x and y. root node) that must be fetched in order to satisfy the
read (x) ; x := x – 50; write (x) ; read(y); y:= y + 50; following query: ‘Get all records with a search key
write(y) greater than or equal to 7 and less than 15’ is ________.
5 13 17
1 3 5 7 9 11 13 15 17
Question Number: 65 Question Type: MCQ bind ( ) will bind the socket to the
Identify the correct order in which a server process address in the Unix domain.
must invoke the function calls accept, bind, listen, and listen ( ) instructs socket to
recv according to UNIX socket API. listen for incoming connections from
client programs.
(A) listen, accept, bind, recv
accept ( ) accepts a connection from
(B) bind, listen, accept, recv a client and returns another socket
(C) bind, accept, listen, recv descriptor,
(D) accept, listen, bind, recv once the connection is set client is
ready to
Solution: The order in which server invokes the func- send( ) and recv ( ).
tion calls are bind, listen, accept and recv.
Hence, the correct option is (B).
11/19/2015 3:24:47 PM
Chapter 1
RL, FA, RE and RG
0,1 1
q0 1 q1 0,1 q2 0,1 q3
Solution: (a)
One-mark Questions
0,1 1
1. Which of the following is TRUE? [2014] q0 1 q1 0,1 q2 0,1 q3
A
(a) The language L = {an bn | n ≥ 0} is regular.
(b) The language L = {an | n is prime} is regular. W = 0011
(c) The language L = {w|w has 3k + 1 b’s for some 0 0
q0 q0 q0 1 q0 1 q0
k ∈ N with Σ = {a, b} } is regular.
(d) The language L = {ww | w ∈ Σ* with Σ =
0 q0 0 q0 1 q0 1 q1
{0, 1} is regular. q0
Solution: (c)
As per option (c), we get L = {w| w has 3k + 1 b’s So, by this analysis we can conclude that the states
for some k ∈ N with Σ = {a, b} } for every value of acceptable to the string w: {q0, q1, q2}.
k, we get the language L with finite number of b’s Hence, the correct option is (a).
in a string of a’s and b’s. Let n = 3k + b. 3. If L1 = {an| n ≥ 0} and L2 = {bn | n ≥ 0} [2014]
Now, L is a language of all strings over the alpha- Consider I) L1.L2 is a regular language
bet Σ = {a, b} where every string contains exactly
II) L1.L2 = anbn | n ≥ 0}
n b’s. Then L is accepted by a finite autometa with
(a) Only I
n + 2 states.
(b) Only II
So, L is a regular language. (c) Both I and II
Hence, the correct option is (c). (d) Neither I nor II
2. Consider the finite automaton of the following Solution: (a)
figure. [2014] Because L1 = {an| n ≥ 0}, it is a regular language
and L2 = {bn| n ≥ 0} is also a regular language.
0,1 1
So, it can be concluded that L1. L2 is also a regular
q0 1 q1 0,1 q2 0,1 q3 language.
Hence, the correct option is (a).
What is the set of reachable states? 4. The length of shortest string NOT in the language
(a) {q0, q1, q0,1
2
} (b) {q
1 ,q}
0 1
(over Σ = {a, b}) of the following regular expres-
(c) {q0, q1,q ,
q02 3q 1} q1 0,1 (d) {q }
q2 30,1 q3 sion is _____________. [2014]
A
A*b*(ba)*a*
W = 0011
0 q0 0 q0 1 q0 1 q0
q0
0 q0 0 q0 1 q0 1 q1
q0
12. Given an arbitrary non-deterministic automation Here the string of length n can be defined by n + 1
with N states the maximum number of states in an states. Moreover, there is also a dead state.
equivalent minimized DFA is at least [2001] So, total state = (n + 1) + 1 = n + 2.
(a) N2 (b) 2N
Hence, the correct option is (c).
(c) 2N (d) N!
16. If the regular set A is represented by A = (01
Solution: (b)
+ 1)* and the regular set B is represented by B
For 1 ≤ M ≤ 2N, number of states in the DFA is M. = ((01)*1*)*, which of the following is true?
Hence, the correct option is (b). [1998]
13. Let S & T be language over Σ = {a, b} represented (a) A ⊂ B
by regular expression (a + b*)* and (a + b)*, (b) B ⊂ A
respectively, which of the following is true?
(c) A and B are incomparable
[2000] (d) A = B
(a) S & 2 (b) 1 = ⊃
Solution: (d)
(c) S = T (d) S ∩ T = Φ
Applying rule (r1 + r2)* = (r1* + r2*)*,
Solution: (c)
Substituting r1 = (01) and r2 = 1 in the above equa-
Same language is generated by S and T, as
tion, we get
(r1 + r2)* = (r1 + r2*)*.
[(01)*1*]* = {((01)*)* + (1*)*}*.
Hence, the correct option is (c).
As (01)*)* = 01 and (1*)* = 1, therefore [(01)*1*]*
14. Let L denote the language generated by grammar S
= { 01 + 1}*.
→ 0S0|00. Which one of the following is true?
Hence, the correct option is (d).
[2000]
(a) L=0+ 17. Which of the following sets can be recognized by
(b) L is regular but not 0 + a Deterministic Finite State Automation? [1998]
(c) L is context free but not regular (a) the number 1, 2, 4, 8,…2n, …. written in binary
(d) L is not context free (b) the number 1, 2, 4,... 2n, …. written in unary
Solution: (c) (c) the set of binary string in which the number of
zeros is the same as the number of ones.
By S → 0S0|00, which is CNG, can generate a
CFL but not a regular set. (d) the set {1, 101, 11011, 1110111, ….}.
Hence, the correct option is (c). Solution: (a)
15. Consider the regular expression (0 + 1)(0 + 1)… 1, 2, 4, 8… written in binary is deterministic
n times. The minimum state finite automation that autometa,
recognizes the language represented by this regu- 1, 2, 4, 8 … written in unary is not accepted by
lar expression contains [1999] finite autometa
(a) n states {1.101, 11011…} is not FA because for a set to
(b) n + 1 states be accepted by FA the count should be maintained
(c) n + 2 states between 0’s and 1’s.
(d) none of the above Hence, the correct option is (a).
Solution: (c) 18. The string 1101 does not belong to the set
We know that (0 + 1)(0 + 1) … n times = (0 + 1)n represented by [1998]
and (0 + 1)n = {w ε (0,1)*| |w| = n}. (a) 110*(0 + 1)
(b) 1(0 + 1)*101
0,1 0,1 0,1
q0 q1 q2 qn q n+1 (c) (10)* (01)*(00 + 11)*
(d) (00 + (11)*0)*
(b) 00 01 10 11 q
00
00 0 1 0
0 1
0 1 1
01 1 1 0,1
0 01
10 0 10
0 1
11 0 0
1 1 10
(c) 00 01 10 11 q 0 0
1
00 1 0 11
01 1 1
10 0
w = 000 has substring 0000, containing more
11 0
than two zeros. So, it is an invalid string but it is
(d) 00 01 10 11 q accepted by DFA. So, (b) is an invalid option.
00 1 0
00
01 1 0 1 0
10 0 0 1 1
0 01 0,1
11 0 10
0 1
Solution: (d) 1 0 0
1 10
L = { All the string of 0’s and 1’s where substring 0 0
of symbol s has at the most two zeros. 1
11
Case I: for option (a),
1
00
0 Case III: for option (b),
0 0
0 1 w = 001000 has substring 000, containing more
0 01 0,1
than two zeros. So it is an invalid string but it is
10 accepted by DFA. So, (c) is an invalid option.
0 1
0
1 1 10
1 00
0 0
1 1 0
11 0 0,1
0 1 01
1 10
0 1
1 0
If we take substring 0000, it has a substring 000 1 10
containing more than two zeros. So, it is an invalid 0 1
string but it is accepted by DFA. So, (a) is an inva- 1
11
lid option.
Case III: for option (b), 1
5. Definition of the language L with alphabet {a} is 8. L = L2 ∩ L1 where language are defined as follows
given as follows. L = {ank| k > 0, n is a positive L1 = [am bm can bn|n, m ≥ 0}
integer constant}. What is the minimum number
L2 = {ai bj ck |i, j, k ≥ 0} then [2009]
of states needed in a DFA to recognize L?
(a) Not recursive
[2011]
(b) Regular
(a) k + 1 (b) n + 1
(c) Context free
(c) 2n + 1 (d) 2k + 1
(d) Recursively enumerable but not context free
Solution: (b)
Solution: (d)
By using instantiation,
L = L2 ∩ L1 = [am bm c| m ≥ 0} which requires a
let n = 2. stack to check the equality between a’s and b’s.
L = {∈, a2, a4, a6,… } – {∈} So, L is a context-free but not a regular language.
= set of all even numbers of a’s –{∈}. Hence, the correct option is (d).
That is accepted by minimal DFA of three states. 9. The DFA accepts the set of all strings over {0, 1}
that [2009]
a a
(a) begins either with 0 or 1
(b) ends with 0
a
(c) ends with 00
(d) contains the substring 00.
So, n = 2, and the answer = 3. Solution: (c)
Hence, the correct option is (b). This DFA accepts all strings from x00 ending with
6. Let L = {w ∈(0 + 1)*| w has even numbers of 1’s}, 00.
i.e. L is the set of all bit strings with even numbers Hence, the correct option is (c).
of 1’s. Which one of the regular expression below 10. Given below are two finite state automata (→ indi-
represents L? [2010] cates the start state and F indicates the final state)
(a) (0*10*1)
(b) 0*(10*10*)* Y:
(c) 0*(10*1)*0* a b
(d) 0*1(10*1)*10* → 1 1 2
Solution: (b) 2 (F) 2 1
Considering 111, option (d) is invalid.
Considering 1010101, option (c) is invalid. Z:
Considering 01010, option (b) is invalid. a b
Hence, the correct option is (b). → 1 2 2
7. Let w be any string of length n in {0, 1}*. Let L
2 (F) 1 1
be the set of all substrings of w. What is the mini-
mum number of states in a non-deterministic finite Which of the following represents the product
automation that accepts L? [2010] automation ZY? [2008]
(a) n – 1 (b) n (a) a b
(c) n + 1 (d) 2n – 1
→ P S R
Solution: (d)
Q R S
Here, w is a string of length n. So, it requires mini-
mum of n + 1 state to be accepted by NFA. R (F) Q P
Hence, the correct option is (d). S Q P
(b) a b (b) P – 1, Q – 3, R – 2, S – 4
(c) P – 1, Q – 2, R – 3, S – 4
→ P S Q
(d) P – 3, Q – 2, R – 1, S – 4
Q R S
Solution: (c)
R (F) Q P P accepts 00. The invalid option is (d).
S Q Q P accepts 001. The invalid option is (a).
(c) a b Q accepts 00. The invalid option is (b).
→ P Q S Hence, the correct option is (c).
Q R S 1 2. Which of the following are regular sets? [2008]
I {an b2n | n ≥ 0, m ≥ 0}
R (F) Q P
II {an bn | n = 2m}
S Q P III {an bn | n! = m}
IV {xcy| x, y ∈{a, b}*}
(d) a b (a) I & IV only (b) I & III only
→ P S Q (c) I only (d) IV only.
Q S R Solution: (c)
R (F) Q P Case-I, L = a*(b2)* and it is regular.
S Q P Case IV, {(x, y)x, y ∈ (a + b)* and it is regular.
Hence, the correct option is (c).
Solution: (a) 13. A minimum state deterministic finite automation
By trying input ‘b’, automation Z and Y go to finite accepting the language [2007]
state. L = {w|w€ {0, 1}* number of 0’s and 1’s in w are
δ0 δ[1Z, 1Y, b] final state. With output ‘b’ option b, divisible by 3 and 5, respectively} has
c, d are not valid. (a) 15 states (b) 11 states
Hence, the correct option is (a). (c) 10 states (d) 9 states
11. Match the following NFAs with the regular expres- Solution: (a)
sion they correspond to [2008] 1
(P) 1 (Q) 1 1 1
0 q1 q2 q3 1 q4 1 q5
1 0
0 1 0 0 0
0 0 0 1 0 0
0 0 0 0
0
q6 1 q7 1 q8 1 q9 1 q10
0 0 0 0
0
1 1 1 1 1
(R) (S) q11 q 12 q 13 1 q14 q15
0 0
1 1
0 1 Hence, the correct option is (a).
0 1
1 4. Which of following language is regular? [2007]
(a) {wwr| w € {0, 1}+}
(b) {wwr|x, w € {0, 1}+}
(c) {wwr| x, w € {0, 1}+}
(1) ε + 0(01*1 + 00)*01*
(d) {wwr| x, w € {0, 1}+}
(2) ε + 0(10*1 + 00)*0
(3) ε + 0(10*1 + 10)*1 Solution: (c)
(4) ε + 0(10*1 + 10)*10* As it is generated by regular expression, it is a
(a) P – 2, Q – 1, R – 3, S – 4 regular language.
r = 0 (0 + 1)*0 + 1(0 + 1)*1. 17. If s is a string over (0 + 1)* then let n0(s) denote
Hence, the correct option is (c). the number of 0’s in s and n1(s) the number of
1’s in which one of the following language is not
15. Consider the following finite state automaton. regular? [2006]
[2007] (a) L = {s € {0 + 1}*| n0(s) is a 3-digit prime}
(b) L = {s € {0 + 1}*| for every prefix of s| n0(s’)
q3
– n1(s’) |≤ 2 }
a b
b b (c) L = {s € {0 + 1}*| n0(s) – n1(s)| ≤ 4 }
a (d) L = {s € {0 + 1}*| n0(s) mod 7 = n0(s) mod 5 = 0}
q0 q1 q2 b Solution: (c)
a
Every finite language is regular and it is a finite
a
language.
The language accepted by this automation is given An infinite language, but by taking prefixes apart
by the regular expression from comparing from 0’s & 1’s, DFA can be con-
(a) b*ab*ab*ab* (b) (a + b)* structed. Hence, it is a regular language.
(c) b*a(a + b)* (d) b*ab*ab*
Is a language accepted by DFA with 35 state. So it
Solution: (c) is also regular.
As the start state is not the final state ∈ is not Hence, the correct option is (c).
accepted by the DFA. So, (b) is an invalid option.
18. Consider the regular language L = (111 + 11111)*.
As aaa is accepted by FA, (d) is an invalid option The minimum number of states in any DFA accept-
as it does not accept aaa. ing this language is [2006]
As the string must be accepted by finite automata, (a) 3 (b) 5
(a) is an invalid option. (c) 8 (d) 9
Hence, the correct option is (c). Solution: (b)
b b a Putting this pattern in figure, we will get
b 1 1 1 1 1
q0 q1 q2
a
a 1
a b
Hence, the correct option is (b).
→ q0 * q1 q0 1 9. What is the minimum number of ordered pairs of
*q1 q2 *q1 non-negative numbers that should be chosen to
q2 *q1 q2
ensure that there are two pairs (a, b) and (c, d) in the
chosen set such that a ≡ c mod 3 and b ≡ d mod 5.
[2005]
16. The minimum state automation equiva lent to the (a) 4 (b) 6
above FSA has the following number of states: (c) 16 (d) 24
(a) 1 (b) 2
(c) 3 (d) 4 Solution: (c)
[FPO] The required order pair will be (3*5 + 1) = 16.
Solution: (b) Hence, the correct answer is (c).
See the construction of minimal DFA of the last
solution.
Hence, the correct option is (b).
(a) {w € {a, b}*| every a in w is followed by ex- (a) Divisible by 3 and 2
actly two b’s} (b) Odd and even
(b) {w€ {a, b}*| every a in w is followed by at (c) Even and odd
least two b’s} (d) Divisible by 2 and 3
(c) {w € {a, b}*| w contains the substring ‘abb’} Solution: (a)
(d) {w € {a, b}*| w does not contain ‘aa’ as sub- By the method of elimination:
string} Option (b) considers the string 100. The number of
Solution: (b) 1’s is odd and the number of 0’s is even.
The DFA state can be named The string is not accepted by DFA, so this option is
not valid.
a b
b Option (c) considers string 11000. The number of
a b b 1’s is even and the number of 0’s is odd.
H P M C
a a As this is not accepted by DFA, so this option is
H a,b not valid.
Option (d) consider s string 11000. The number of
As S is a dead state or a trap state, that is why it 1’s is divisible by 2 and the number of 0’s is divis-
can be deleted without affecting the set that is w ible by 3.
accepted.
As this is not accepted by DFA, so this option is
a b not valid.
b
a b b In Option (a) the given DFA will be
H P M C
1
Option (d) the string ∈ is in {a, b} and does not p00,q0 0> 1 <p 00,q01 > 1 <p10,q01 >
contain ‘aa’ as a substring. As the start state is not 0
the final state ∈ is not accepted by the DFA. So, it
is an invalid option. 0 0 0
Option (a) considers the string abbb. It is accepted
by the DFA. So, it is a valid option.
Option (c) ∈ is accepted by the DFA. So, it is a <p10,q0 0 > <p10,q01 > <p00,q02 >
1 1
valid option.
1
Hence, the correct option is (b).
21. The following finite state machine accept all those Hence, the correct answer is (a).
binary strings in which the number of 1’s and 0’s
are, respectively [2004] 2 2. Consider the following deterministic finite state
automation M. [2003]
1
0 0,1
0 0
1 1
0 1,0 a,b
1 3 States
a,b
a,b
1,0 0
depicts the three states.
When we will change final and non-final state,
Hence, the correct option is (b).
w will get
26. Consider DFA over ∑ = {a, b} accepting all strings 27. Consider the following languages:
which have number of a’s divisible by 6 and num- (a) L1 = {w w | w€ {a, b}*}
ber of b’s divisible by 8. What is the minimum (b) L2 = {w wr | w€ {a, b}*, wr is the reverse of w}
number of states that the DFA will have? (c) L3 = {02i | I is an integer}
[2001] (d) L4 = {0i2 | I is an integer}
(a) 8 (b) 14 Which of the following languages are regular?
(c) 15 (d) 48
[2001]
Solution: (d) (a) Only L1 L2
The 48 state DFA follows. (b) Only L2, L3, L4
a b a b (c) Only L3, L4
(d) Only L3
→ q00 q10 q01 q10 q20 q11
Solution: (d)
Input of length 1 q01 q11 q02
For the expression L3 = {02i | I is an integer}
a b Input of length 2
0
q20 q30 q21 a b
Accepts L3
q11 q21 q12 q30 q40 q31
Input of length 8
Hence, the correct option is (b). If the initial state is unknown, then the shortest
input sequence to reach the final state C is here,
30. Which of the following regular expression over since initial make unknown m 10 input we can
{0, 1} denotes the set of all strings not containing each final state C with shortest path.
100 as substring? [1997] (a) 01
(a) 0*(1 + 0)* (b) 0*1010* (b) 10
(c) 0*1*01* (d) 0*(10 + 1)* (c) 101
Solution: (d) (d) 110
0*1*01* and 0*(10 + 1)* both generate the string Solution: (b)
that doesn’t contain 100 as a substring, and it can Here, the initial state is unknown, so on 10 input
also be said that (c) does not guarantee ε but the we can reach the final state C in shortest path.
option (d) guarantees ε.
Hence, the correct option is (d). 0/0
A B 1/1
31. Which of the following definitions given below 1/1
generate the same language?[1995] 1/0 1/0 0/1
Where L = {xnyn |n ≥ 1}
0/0
(i) E → xEy| xy (ii) xy |(x+ xyy+ ) D C
(iii) x y
+ + 0/1
L = {xn yn | n ≥ 1} generates string with equal num-
Hence, the correct option is (b).
ber of x and equal number of y’s.
3 3. The number of substring (of all length inclusive)
E → xBy |xy abo generators tips same.
that can be formed from a character string of
(a) i only (b) i & ii
length n is [1994]
(c) ii & iii (d) ii only
(a) n (b) n2
Solution: (a) n ( n −1) n ( n +1)
In expression L = {xnyn |n ≥ 1}, the strings are gen- (c) (d)
2 2
erated with equal number of x and y. Solution: (d)
E → xEy| xy also generates the same string as of L. Let s be the string
Hence, the correct option is (a). Let the length of s be ‘n’.
32. A finite state machine with the following state n( n + 1)
table has a single input X and a single output Z. No. of substrings = Σn + 1 = +1.
2
[1995] Hence, the correct option is (d)
0 1 0 Solution: (a)
Expanding r = 1 (1 + 0)* = all strings start with 1.
1 0 Expanding s = 11*0 = 10, 110, 1110,……
B C
Expanding t = 1*0 = 0, 10, 110, 1110…..
So, it can be concluded that L(s) ⊆ L(r) & L(s) ⊆
1 L(t)
Hence, the correct option is (a).
Solution:
38. Let R1 and R2 be regular sets defined over the
By the given diagram the expression 0* + 0*11*
alphabet Σ then: [1990]
defines it properly.
(a) R1 ∩ R2 is not regular
35. Which of the following regular expression identi-
ties are true? [1992] (b) R1 ∪ R2 is regular
(a) R(*) = r* (c) Σ*– R1 is regular
(b) (r*s*)* = (r + s)* (d) R1* is not regular
(c) (r + s)* = r* + s*
Solution: (c)
(d) r*s* = r* + s*
Let Σ be any alphabet. Σ* is a universal language
Solution: (b)
which is accepted by a finite automata.
As r and s are regular expressions, the expres-
Also R1 is a regular language and complement of
sion (r + s)* = (r* + s*)* will generate the same
R1 = Σ* – R1 that is also a finite automata.
language.
Finite automata for R1c can be obtained by inter-
Hence, the correct option is (b).
changing final and non-final states from FA of R1.
36. If G is a context-free grammar and w is a string of
Hence, if R1 is a regular language, then Σ* – R1 is
length n in L(G), how long is derivation of w in G,
also regular.
if G is in Chomsky normal form? [1992]
(a) 2n (b) 2n + 1 Hence, the correct option is (c).
(c) 2n –1 (d) n 39. How many substrings (of all lengths inclusive)
Solution: (c) can be formed from a character string of length
The length of derivation tree = 2n – 1. n? Assume all characters to be distinct. Prove your
As S → AB answer. [1989]
A → BC|a Solution:
B → CC|b| Total no of substrings = Σ n + 1
Derivation: w = ab
n( n + 1)
S → AB +1
S → aB 2
S → ab For example, let s = Pearson be the string then |s| = 7
Let the string w = ab and |w| = 2(n) s has substring of length l = 0,1, 2, …7
Number of product in derivation = 2n – 1 = 4 – 1 = 3. substring of length 0, ∈
Hence, the correct option is (c). substring of length 1 p, e, a, r, s, o, n
37. Let r = 1(1 + 0)*, s = 11*0 and t = 1*0 be three substring of length 2, pe, pa, pr…..
regular expressions. Which one of the following is
substring of length 3, pea, par,….
true? [1991]
(a) L(s) ⊆ L(r) & L(s) ⊆ L(t) Similarly,
(b) L(t) ⊆ L(s) & L(s) ⊆ L(t) substring of length 7, pearson.
(c) L(s) ⊆ L(t) & L(s) ⊆ L(r) So, total no of substring is Σ7 + 1.
(d) L(t) ⊆ L(s) & L(s) ⊆ L(r)
so, total no. of substring = n( n + 1) + 1 .
2
One-mark Questions
1. The lexical analysis for a modern computer lan- (c) Complement of every context-free language is
guage such as java needs the power of which one recursive
of the following machine model in necessary and (d) Every non-deterministic PDA can be convert-
sufficient sense? [2011] ed to an equivalent deterministic PDA
(a) Finite state automata Solution: (b)
(b) Deterministic pushdown automata NFA is not equal to PDA but is equal to DFA. No
(c) Non-Deterministic pushdown automata conversion can take place between NFA and PDA.
(d) Turning Machine.
Hence, the correct option is (b).
Solution: (a) 4. Let L1 = {o m + n 1n om | n, m ≥ 0}
In the process of lexical analysis, the tokens are L2 = {om + n 1n + m om | n, m ≥ 0} and
recognized by a FA. That is why FA is necessary
L3 = {o m + n 1n + m om + n | n, m ≥ 0}. Which is not
and also sufficient.
context free? [2006]
Hence, the correct option is (a). (a) L1 only (b) L3 only
2. S → a Sa | bSb | a |b (c) L1 and L2 (d) L2 and L3
The language generated by the above grammar Solution: (d)
over the alphabet {a, b} is the set of: [2009] It requires two counters or two stacks.
(a) All palindromes Hence, the correct option is (d).
(b) All odd length palindromes 5. Which of the following grammar rules violate the
(c) String that begins and ends with same symbols requirement of an operator grammar? P, Q, R are
(d) All even length palindromes non-terminal and r, s, t are terminals.[2004]
Solution: (c) (1) P → QR (2) P → QsR
A, aa, aaa, … b, bb, bbb, …, aba, bab, … are the (3) P → ε (4) P → QtQr
string generated by grammar that starts and ends (a) 1 only (b) 1 and 3 only
with the same symbol. (c) 2 and 3 only (d) 3 and 4 only
Hence, the correct option is (c). Solution: (b)
3. Which of the following is FALSE? [2009] An operator grammar does ε production and two
(a) There is a unique minimal DFA for every regu- adjustment non-terminal at RHS. Since
lar language P → QR has two adjacent variables at RHS and ε
(b) Every NFA can be converted to an equivalent at RHS,
PDA Hence, the correct option is (b).
2. Consider the following DFA given below 3. The FIRST and FOLLOW sets for the non-
1 terminal A & B are
(a) FIRST(A) = {a, b, c} = FIRST (A)
1 FOLLOW (A) ={a, b}
FOLLOW (B) = {a, b, $}
(b) FIRST (A) = {a, b, $} FIRST (B) = {a, b, ε}
0 0 FOLLOW (A) = {a, b}
FOLLOW (B) = {$}
(c) FIRST (A) = {a, b, ε} = FIRST(B)
FOLLOW (A) = {a, b}
FOLLOW (B) = Φ
(d) FIRST(A) ={a, b} = FIRST (B)
0,1
FOLLOW (A) = {a, b}
FOLLOW (B) = {a, b}
Which of the following are False? [2013]
1. Complement of L(A) is context-free Solution: (a)
2. L(A) = L(11*0 + 0)(0 + 1)*)*1*) S → aAbB|bAaB|ε
3. For the language accepted by A, A is DFA A→S
4. A accepts all strings over {1, 0} of length at B→S
least 2
First: FIRST (S) = {a, b, ε}
(a) 1 and 3 only (b) 2 and 4 only
(c) 2 and 3 only (d) 3 and 4 only FIRST (A) = {a, b, ε}
Solution: (d) FIRST (B) = {a, b, ε}
As the given DFA can be minimized to two states FOLLOW: FOLLOW (S) = {a, b, $}
and abc accepts the string of length 1, FOLLOW (A) = {a, b, $}
So 3 and 4 are False. FOLLOW (B) = {a, b, $}
Hence, the correct option is (d). Hence, the correct option is (a).
Common Data for Questions Q 3 and 4 4. The appropriate entries for E1, E2 and E3 are
For the grammar below, a partial LL(1) parsing (a) E1: S → aAbB, A → S
tables are also presented along with the grammar. E2: S → bAaB, B → S
Entries that need to be filled are indicated as E1, E3 : B → S
E2 and E3, ε is the empty string , $ indicates end of (b) E1: S → aAbB, S → ε
input and | separated alternate RHS of productions. E2: S → bAaB, S → ε
[2012] E3: S → ε
S → aAbB | bAaB | ε (c) E1: S → aAbB, S → ε
A → S E2: S → bAaB, S → ε
E3: B → S
B → S
(d) E1: S → aAbB, A → S
a b $
E2: S → ε, B → S
E3: B → S
S E1 E2 S→e Solution: (c)
B B→S B→S E3
(a) a, b
a b $
b b
p q r
S → aAbB S → bAbB
S1 S→ε
S→ε S→ε
[2011] s
L1 = {0p 1q | p, q ∈ N}
L2 = {0p 1q | p, q ∈ N and p = q } and b
a,b
L3 = {0p 1q 0r | p, q, r ∈ N and p = q = r} a,b
p q r
Which of the following statements is not TRUE? a
(a) PDA can be used to recognize L1 and L2
(b) L1 is a regular language (c) a,b
a,b
(c) All the three languages are context free
(d) Turing machines can be used to recognize all a,b
p b r
the languages q
Solution: (d)
(d)
L1 requires no stack, so it is a regular language b b
p q
L2 requires one stack, so it is CFL.
L3 requires two stacks, so it is CSL.
a a
All these are accepted by Turing machine.
Hence, the correct option is (d).
s a,b
6. A deterministic automata DFA with alphabet
Σ = {a, b} is given below
a,b Solution: (a)
b b S and t are equal states. Merge these states into a
p q r
single state.
Hence, the correct option is (a).
a
a 7. Consider the language [2010]
a,b a,b L1 = {0i 1j | i ≠ j} L2 = L = {0i 1j | i = j}
s t L3 = L = {0i 1j | i = 2j + 1} L4 = L = {0i 1j | i ≠ 2j}
(a) Only L2 is context free
(b) Only L2 and L3 are context free
Which of the following finite state machines (c) Only L1 and L2 are context free
is a valid minimal DFA which accepts the same (d) All are context free
languages as D? [2011] Solution: (d)
As we need to maintain count between 0’s and 1’s,
so one extra memory is required. So, all of these
languages are accepted by PDA, hence by CFL.
Hence, the correct option is (d).
8. For the correct string of Q. 21 how many deriva- (c) Trivally every regular language is also a con-
tion trees are there? [2008] text-free language
(a) 1 (b) 2 (c) 3 (d) 4 Hence, the correct option is (d).
Solution: (b) 10. Which of the following statements is true?
The derivation tree is [2008]
S (a) Every left-recursive grammar can be converted
S to a right-recursive grammar and vice versa.
(b) All ∈-production can be removed from any
a aB context-free grammar by suitable grammar.
B
(c) The language generated by a context-free
grammar all of whose productions are of X →
a & a wY or X → wY (where w is a string of terminals
B B B
B and Y is a non-terminal) is always regular.
(d) The derivation tree of strings generated by a
b b b S context-free grammar in Chomsky Normal
b S Form is always binary tree
a Solution: (a)
B
b A (a) Using GNF left-recursive grammar can be
converted to a right-recursive grammar.
b (b) ∈- production can be removed from any con-
a text-free grammar but containing string ∈ then
rule must be S → ∈. So, ii is false.
Hence, the correct option is (b).
(c) For context-free grammar X → wY, grammar
9. Which of the following statements is false? is right linear and hence generates a regular
[2008] set.
(a) Every NFA can be converted to an equivalent (d) Derivation tree is always binary.
DFA Hence, the correct option is (a).
(b) Every non-deterministic Turing Machine can 11. Match list-I with List-II. [2008]
be converted to an equivalent deterministic Tu- List-I
ring Machine.
(a) Checking that identifier are declared before
(c) Every regular language is also a context-free their usage
language (b) Number of formal parameters in the declara-
(d) Every subset of a recursively enumerable set is tion of function agrees with the number of
recursive actual parameters in a use of that function.
Solution: (d) (c) Arithmetic expression with matched pairs of
Consider the set Σ* which is a regular and r.e. All parenthesis
the r.e sets are subsets of Σ*. All the r.e sets that are (d) Palindromes
not recursive are subsets of Σ*. So, the statement List –II
(d) is false. P) L = { am bn cn dm | m, n ≥ 1}
(a) By algorithm NFA can be converted to an Q) X → XbX | XCX | dXf | g
equivalent DFA. R) L = {wcw | w ∈ (a | b)*}
(b) Start with non-deterministic Turing Machine. S) X → BXb | XcX | ε
Simulate the sequences of moves with a DTM. Codes:
NFA can be converted to an equivalent deter- (a) E-P, F-R, G-Q, H-S
ministic Turing Machine. (b) E-R, F-P, G-S, H-Q
(c) E-R, F-P, G-Q, H-S
Also produces the string with equal number of a’s (c) L3 = is a CFL but not deterministic
and b’s. (d) L3 = is a deterministic CFL
It is also accepted DPDA. Solution: (d)
Hence, the correct option is (d). L2 is DCFL, since it is accepted DPDA.
15. Let Nf and Np denote the classes of language b,b bb
a,a aa a,z0 az0 b,b
accepted by non-deterministic finite automata and
a,b ab a,a
non-deterministic pushdown automata, respec- b,a ba b,z0 bz0
tively. Let Df and Dp denote the classes of lan- A B
guage accepted by deterministic finite automata ,z0
and deterministic pushdown automata, respec-
tively. Which of the following is True? [2005] ,a
(a) Df ⊂ Nf and Dp ⊂ Np ,b
(b) Df ⊂ Nf and Dp = Np Hence, the correct option is (d).
(c) Df = Nf and Dp = Np
1 8. The language {am bn cm + n | m, n ≥ 0} is [2004]
(d) Df = Nf and Dp ⊂ Np
(a) Regular language
Solution: (d) (b) Context-free language but not regular
FA PDA
(c) Context-sensitive language but not context-free
(d) Type-0 but not context-sensitive
Solution: (b)
NFA= DFA DPDA NPDA As count b/w a and c is 0 be maintained.
Nf=Df but Dp = Np
Hence, the correct option is (b).
Hence, the correct option is (d). 19. S → bS | aA | b [2004]
1 6. Consider the language L1 = { am bm Cm |n, m ≥ 0} A → bA | aB
and L2 = { am bn Cm|n, m ≥ 0} B → αbb | ab
Which of the following statements is False? Let Na (w) and Nb (w) denote the number of a’s
[2005] and b’s in a string w, respectively.
(a) L1 ∩ L2 is context free The language
(b) L1 ∩ L2 is context free L(G) ⊆ {a, b} + generated by G is
(c) L1 and L2 are context free (a) {w | Na (w) > 3Nb(w)}
(d) L1 ∩ L2 is a context-sensitive language (b) {w | Nb (w) > 3Na(w)}
Solution: (d) (c) {w | Na (w) = 3 k, k = {0, 1, 2, 3, … }}
L2 ∩ L2 is CSL. (d) {w | Nb (w) = 3 k, k = {1, 2, 3 …}
Since L1 ∩ L2 = {ai, bj, ck/i = j = k}, it requires two Solution: (c)
stacks to maintain a count. String generated by grammar is of a’s and
Hence, the correct option is (d). b’s where the number of a’s is congruent of 0
17. Consider the languages: (mod 3).
L1 = {wwR | w ∈ {0, 1}*} Hence, the correct option is (c).
L2 = {w # wR | w ∈ {0, 1}*} where # is a special 20. Let M = (K, Σ, F, ∆, s, F) be a pushdown automata,
symbol where K = {s, f}, F = {f}, Σ = {a, b}, F = {a},
L3 = {ww | w ∈ {a0, 1}*} ∆ = {((s, a, ε), (s, a)), ((s, b, ε), (s, a), ((s, a, ε), (f, ε)),
Which of the following is true? [2005] ((f, b, a), (f, ε))}.
(a) L1 = is a deterministic CFL Which of the following strings is not a number of
(b) L2 = is a deterministic CFL L(M)? [2004]
26. L1 and L2 are context-free languages and R is a (c) Closed under intersection
regular set. One of the languages below is not nec- (d) Closed under kleene closure
essarily a context-free language. Which one? Solution: (a) and (d)
[1996] The context-free language is closed w.r.t. union and
(a) L1 L2 (b) L1 ∩ L2 kleene closure, but not closed under Intersection,
(c) L2 ∩ R (d) L2 ∪ L1 complement.
Solution: (b) Hence, the correct option is (a) and (d).
Intersection of two CFL need not be CFL. 30. Context-free language and regular language are
Hence, the correct option is (b). both closed under operations of: [1989]
27. Let G be a context-free grammar where G = ({S, (a) Union (b) Intersection
A, B, C}, {a, b, c}, P, S} with production P given (c) Concatenation (d) Complementation
below. [1996] Solution: (a) and (c)
S → ABAC A → Aa| ε B → bB | ε C → d ε As per definition, intersection and complement of
is null string. CFL need not be CFL.
Transform the given grammar G to an equivalent Hence, the correct option is (a) and (c).
context-free grammar G1 that has no ε production. 31. A context-free grammar is ambiguous if : [1987]
(A unit production is of the form x → y, x & y are (a) The grammar contains useless non-terminals
non-terminal.) (b) It produces more than one parse tree for some
Solution: sentence
S → ABAC|BAC|ABC|BC|AAC|AC|d (c) Some production has two non-terminals side
A → aA|a by side on RHS
B → bB|b (d) None of the above
C→d Solution: (b)
28. Which of the following features cannot be cap- For some string if the grammar gives more than
tured by context-free grammar? [1994] one parse tree, then it is called ambiguous.
(a) Syntax of if-then-else Hence, the correct option is (b).
(b) Syntax of recursive procedure 32. FORTRAN is [1987]
(c) Whether a variable has been declared before (a) Regular language
its use (b) Context-free language
(d) Variables name of arbitrary length (c) Context-sensitive language
Solution: (c) (d) None of the above
The context-free language is proper with syntax of Solution: (c)
source code and would not bother about declara- FORTRAN is a programming language. All pro-
tion of variable before use. gramming languages are defined by CFG, and all
Hence, the correct option is (c). CFL is CSL. So, FORTRAN is CSL.
29. Context-free languages are [1992] Hence, the correct option is (c).
(a) Closed under union
(b) Closed under complementation
a b
FA q0 q1 q2
a b
q0 q1 q2 FA
(b) Equivalence of two TM is not decidable {by Which of the following statements is true about
Rice’s theorem} M?
(c) Emptiness is decidable (a) M does not halt on any string in (0 + 1)+
(d) Emptiness is decidable (b) M does not halt on any string in (00 + 1)*
Hence, the correct option is (b) (c) M halts on any string ending with zero
5. Which of the following is true?[2002] (d) M halts on any string ending in
(a) The complement of recursive language is Solution: (a)
recursive If input is ∈ then δ(q0, b) = Halt.
(b) The complement of recursively enumerable Let input be 1, δ(q0, b) = (q1, 1R) & δ(q1, B)
language is recursively enumerable = δ (q0, B, C)
(c) The complement of recursively language is
q0 q1
either recursive or recursively enumerable
(d) The complement of context-free language is q0
context-free
Solution: (c) q1
Hence, the correct option is (c)
6. The C language is:[2002]
(a) Context-free language
(b) Context-sensitive language B
(c) Regular language 0 0
q0 q1 q1
(d) Parsable fully only by TM
q0 1
Solution: (a)
C cannot be regular as it does parenthesis match- q1
ing. CSLs are powerful to specify C. q0
Parsing techniques show that C program can be
parsed by PDA. The figure does not Halt.
Hence, the correct option is (a). Hence, the correct option is (a)
7. A single-tape TM M has two states q0 and q1 of 8. Define languages L0 and L1 as follows[2003]
which q0 is the starting state. The tape alphabet of
L0 = {< M, w, 0 > | M halts on w}
M is {0, 1, B} and its input alphabet {0, 1}. The
symbol B is the blank symbol used to indicate end L1 = {< M, w, 1 > | M does not halt on w}
of an input string. The transition function of M is Here, < M, w, i > is a triplet, whose first component,
described in the following table.[2003] M, is an encoding of a TM, second component, w,
is a string and third component t is a bit.
0 1 B
Let L = L0 ∪ L1, which of the following is true?
Q0 Q, 1, R Q, 1, R Hatt
(a)•L is recursively enumerable but L is not.
Q1 Q, 1, R Q0, 1, L Q0, B, L
L is recursively enumerable but•L is not.
(b)
B B→S B→S E3
(c) Both L and•L are recursive.
The table is interpreted as illustrated below. The (d) Neither L nor is recursive enumerable•L
entry (Q1, 1, R) in row q0 and Column 1 signifies Solution: (b)
that if M is in state q0 and reads 1 on current tape L is recursive than we can decide the halting
square, then it writes 1 on the same tape square. problems.
Moves its tape head one position to the right and Hence, the correct option is (b)
transitions to state q1.
Lexical Analysis 0 1 0 1 0 0 0 0 2 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0
Parsing Techniques 0 1 0 0 0 1 0 0 1 1 0 1 0 0 2 0 6 2 5 4 6 2 0 1 0 1 2 2
Syntax Directed 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 2
Translation
Code Generated 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 2 1 2 0 1 1 1 0 0 0 2
& Optimization
11/19/2015 3:26:17 PM
Chapter 1
Lexical Analysis
3. The lexical analysis
One-mark Questions 4. The code optimization
1. In a compiler, keywords of a language are recog- Solution: (b)
nized during [2011] Regular expression for recognizing strings — the
(a) Parsing the program lexical analysis.
(b) The code generation Pushdown automata for syntax checking — the
(c) The lexical analysis of the program syntax analysis.
(d) Dataflow analysis
Dataflow analysis for constructing flow graphs —
Solution: (c) minimize the code.
Keywords of a language are recognized during Register allocation for code generation.
lexical analysis.
Hence, correct option is (b).
Hence, correct option is (c).
4. The number of tokens in the following C statement
2. Which data structure in a compiler is used for
[2000]
managing information about variables and their
attributes? [2010] Printf(“i = %d, &i = %x, I,&i); is
(a) Abstract syntax tree (b) Symbol table (a) 3 (b) 26
(c) Semantic stack (d) Parse table (c) 10 (d) 21
Solution: (b) Solution: (c)
Printf(“i = %d,&i = %x,I,&i);
Symbol table is that data structure used for manag-
Tokens: Printf → 1
ing information about variables and their atributes.
( → 2
Hence, correct option is (b). “i = %d,&i = %x → 3
3. Match the followings:. [2009] , → 4
Group-I I → 5
P. Regular expression , → 6
Q. Pushdown automata & → 7
R. Dataflow analysis I → 8
S. Register allocation ) → 9
; → 10
Group- II
No. of tokens = 10.
1. The syntax analysis
2. Code generation Hence, correct option is (c).
Five-marks Question (a) (ii) and (iv) (b) (i) (iii) and (iv)
(c) (i), (ii) and (v) (d) (ii) (iii) and (v)
1. Which of the followings are true? [2008] Solution: (a)
(i) A programming language that does not permit Consider each statement separately.
global variable of any kind and has no nesting (i) FALSE. Recursion cannot be implemented
of procedures/functions, but static storage al- with static storage. The language FORTRAN
located. is an example where recursion is not possible.
(ii) Multi-level access link (or display) arrange- (ii) TRUE. Multi-level access link, normally con-
ment is needed to arrange activation records sidered to a DISPLAY , is essential for nest-
only if the programming language being im- ed procedures/functions and to keep track of
plemented has nesting of procedures/func- scope of variables.
tions. (iii)
FALSE. With dynamic storage allocation
(iii) Recursion in programming language cannot & heap one can have a linked stack. Push
be implemented with dynamic storage alloca- means new storageand pop means deletion of
tion. storage.
(iv) Nesting of procedures/functions and recursion (iv) FALSE. A stack data structure is sufficient to
require a dynamic heap allocation scheme and implement recursive procedures/functions.
cannot be implemented with a stack-based al- (v) FALSE. A stack can be implement the
location scheme for activation records. programming languages feature of a function
(v) Programming languages which permit a func- to return .
tion to return a function as its result cannot be Hence, correct option is (a).
implemented with a stack-based storage allo-
cation scheme for activation records.
Solution: (b)
One-mark Questions
If w is a string with n tokens, the parser can take
1. Conside the following grammar defined by the atmost (n-1) reduce operation to parse the string.
following production rules, with two operator * Hence, correct option is (b).
and + 3. Given the language = {ab, aa, baa}, which of the
S → T*P following string are in L* ? [2012]
T → U| T*U 1) abaabaaabaa 2) aaaabaaaa
P → Q + P|Q 3) baaaaabaaaab 4) baaaaabaa
Q → id (a) 1, 2 and 3 (b) 2, 3 and 4
U → id [2014] (c) 1, 2 and 4 (d) 1, 3 and 4
Which one of the following is TRUE? Solution: (b)
(a) + is left associative while * is right associative. A bottom up parser which can parse the string in a
(b) * is left associative while + is right associative. CFG in a single pass takes O (n) operations.
(c) Both * and + is right associative. Hence, correct option is (b).
(d) Both * and + will be left associative.
4. Which of the following describes a handle (as
Solution: (b) applicable to LR parsing) appropriately? [2008]
S → T*P (a) It is a position in sentential form where the
T → U| T*U ……………….(1) next shift or reduce operation will occur.
P → Q + P|Q ………………..(2) (b) It is a non-terminal whose production will be
Q → id used for reduction in the next step.
U → id (c) It is production that may be used for reduc-
From (1), T → T*U * is left associative tion in the next step along with a position in
From (2), P → Q + P + is right recursive sentential form where the next shift or reduce
Hence, correct option is (b). operation will occur.
2. Which is the maximum number of reduce moves (d) It is production p that will be used for reduc-
that can be taken by a bottom up parser for a gram- tion in the next step along with a position in
mar with no epsilon and unit production (i.e., of sentential form where the right-hand side of
Type A → e and A → a) to parser a string with n the production may be found.
tokens? [2013] Solution: (d)
(a) n/2 (b) n-1 (a) The handle does not arise for a shift operation.
(c) 2n-1 (d) 2n (b) Handle is a string of characters in the RHS of
a rule, it is not the LHS rule.
(c) Handle only enters for reduce operation. (c) Right recursive
Hence, correct option is (d). (d) An operator grammar
5. Which one of the following is a top-down parser? Solution: (b and a)
[2007] (a) S S
(a) Recursive descent parser ↓↓ ↓↓
(b) Operator precedence parser A A & AA
(c) An LR(k) parser ↓↓ ↓↓
(d) An LALR(k) parser ε A εε
Solution: (a) ↓
Recursive descent parser is an LL(1) parser, and ε
hence, a top-down parser. (b) Left recursion: S → AA
Hence, correct option is (a). → AAA
6. Consider the following grammar: [2006] → AAAA
S → S*E → AAAA….
S → E (c) RIGHT recursion does not matter in LL.
E → F + E (d) An operator grammar can be LL
E → F S → aAcA|bBcA
F → id A → a
Consider the following LR(0) items correspond- B → a is an example of an operator grammar
ing to the grammar above: that is LL(1).
i. S → S*E Hence, correct option is (b and a).
ii. E → F. + E
8. Which of the following suffices to convert an arbi-
iii. E → F + E.
trary CFG to an LL (1) grammar? [2003]
(a) i & ii (b) ii & iii
(a) Removing left recursion alone
(c) i & iii (d) none of above
(b) Factoring the grammar alone
Solution: (d) (c) Removing left recursion and factoring the
Construct the LR matter grammar
S (d) None of the above
S S. * E
S .S * E
S .E Solution: (d)
E (a) FALSE. As the grammar
E .F + E S E.
E .F + E + E S → AB
F .id F A → aa/a
E F. + E
E F'. + E + E B → Ba/a
id Can be replaced by
F id. + S → A/B
F
A → Aa/a
id B → aB/a
S .S * E E F + .E The equivalent grammar is not left recursive
E .F + E E F + .E + E but not LL.
E .F + E + E E .F + E
E .F + E + E (b) FALSE.
F .id * F .id S → aA/Ab
A → AB/b
B → b is left recursive. Factoring will not
Hence, correct option is (d). remove left recursion.
7. The grammar A → AA|A|e is not suitable for pre- (c) Ambiguity cannot be eliminated by only left
dictive parsing because the grammar is [2005] recursion and factoring the grammar
(a) Ambiguous Hence, correct option is (d).
(b) Left recursive
Q → R S1 – – – S1 → S
The input symbol > R S → aSa S → bS S → cS –
⇒ S → L > R } – Ij As there is no conflict the grammar is LL(1) .
Neither a shift reduce conflict nor a reduce-reduce The LR(0) machine following
conflict.
S → aSa| bS|c
Hence, correct option is (d).
2. Consider the following two sets of LR(1) items of S a.Sa
S
S aSa a S aSa S aS.a
an LR(1) grammar: S bS S bS
X → c.X, c/d S c S c a a
X → .cx, c/d a S aSa.
b
X → .d, c/d b
c S b.S
AND
S aSa
X → c.X, $ S .c S bS
S c
X → c.X, $
X → .d, $
Which of the following statements related to
merging of two sets in the corresponding LALR Hence, correct option is (c).
PARSER is/are FALSE? [2013]
C → b ⇒ aabbS (B → bS)
lm
(c) It is ambiguios
(d) It is not context free So, aaabbab is generated by the grammar for string
aabbab the parser trees are given below.
Solution: (c)
Consider the dangling else problem in control
structure
S → if C then S else S1
S1 → else s/∈
S S B → Bb|b
Solution: (d)
aB aB
Hence, correct option is (d).
10. In the correct grammar above, what is the length
aBB a B B
of derivation (number of steps starting from S) to
or generate the string a1 bm with l ≠ m [2006]
bSb b b S (a) max (l, m) + 2 (b) l + m + 2
(c) l + m + 3 (d) max (l, m) + 3
b A a B Solution: (a)
Hence, correct option is (a).
a b
11. Consider the grammar
Hence, correct option is (c). S → FR
8. How many derivation trees are there? T → *S|ε
(a) 1 (b) 2 F → id
(c) 3 (d) 4 In the predictive parser table, M, of the grammar the
Solution: (b) entries M [S, id] and M [R, $ ], respectively. [2006]
There are two parse trees are given for the string (a) {S → FR} and {R → ε}
aabbab — one from leftmost derivation and one (b) {S → FR}and {}
from rightmost derivation. (c) {S → FR} and {R → *S}
(d) {F → id} and {R → ε}
S S
Solution: (a)
a B a B S → FR
R → *S|ε
a B B
a B B F → id
First (F) = {id}, FIRST (s) = FIRST (f) = {id}
b S b b B S
FIRST(RR) = {*} ∪ FOLLOW (R) = {*, $}
b A a B
id * $
a b
S S → FR - -
R - R → *S R→e
Hence, correct option is (b).
F F → id - -
9. Which of the following grammars generates the
language L = (ai bj | i ≠ j)? [2006]
(a) S → AC|CB There is no conflict in predictive parsing tape. We
C → aCb|a|b have M[S, id] = S → FR
A → aA|ε & M [R, $ ] = {R → ε}.
B → Bb|ε Hence, correct option is (a).
(b) S → aS|Sb|a|b
12. Consider the grammar E → E + n |Exn|n for a sen-
(c) S → AC|CB
tence n + nxn, the handles in the right-sentential
C → aCb|ε
form of the reduction tree are [2005]
A → aA|ε
(a) n, E + n and E + nxn
B → Bb|ε
(b) n, E + n and E + Exn
(d) S → AC|CB
(c) n, n + n and n + nxn
C → aCb|ε
(d) n, E + n and Exn
A → aA|a
Solution: (d) 15. Assume the conflicts in question (10) are resolved
n → E + n |E X n|n and an LALR (1) parser is generated for parsing
arithmetic expression as per the given grammar.
input string n + nxn ⇒ E + n × n⇒ E × n⇒ E
Consider an expression 3 × 2 + 1.
Hence, correct option is (d).
What precedence and associatively properties does
13. Consider the grammar the generated parser realization? [2006]
S → (S)|a (a) Equal precedence and left associativity;
Let the number of states in SLR (1), LR® and expression is evaluated to 7.
LALR parser for grammar ne n1 n2, n3 respectively. (b) Equal precedence and right associativity;
The following relation holds good [2005] expression is evaluated to 9.
(a) n1 < n2 < n3 (b) n1 = n3 < n2 (c) Precedence of ‘x’ is higher than that of ‘+’ and
(c) n1 = n2 = n3 (d) n1 ≥ n3 ≥ n2 both operators are left associative ; expression
is evaluated to 7.
Solution: (b)
(d) Precedence of ‘+’ is higher than that of ‘x’ and
The number of states in SLR (1) and LALR parser both operators are left associative ; expression
are equal to n1 = n3. is evaluated to 9.
The number of states of DFA in LR (1) or canoni- Solution: (c)
cal LR is greater than the number of states of DFA With look ahead, we should prefer to shift because
SLR (1) & LALR parser . the look ahead has greater precedence than x over
Hence n1 = n3 < n2. + and both operators are left associative.
Hence, correct option is (b). Hence, correct option is (c).
Common Data For Question 14 and 15 16. Which of the following grammar rules violate the
requirement of an operator grammar? P, Q, R are
Consider the following expression grammar. The
non-terminal and r, s, t are terminals. [2004]
semantic rules for expression evaluation are stated
i) P → QR ii) P → QsR
next to each grammar production. [2005]
iii) P → e iv) P → QtRr
E → number E.val = number.Val (a) I ONLY
|E ‘+’ E E(1).val = E(2).VAL + E(3).val (b) I & II ONLY
|E ‘x’ E E(1).val = E(2).VAL + E(3).val (c) II & III ONLY
(d) III & IV ONLY
14. The above grammar and semantic rules are fed to a
yacc tool (which is an LALR (1) parser generator) Solution: (b)
for parsing and evaluating arithmetic expression. In an operator grammar , the RHS of no production
Which one of the following is true about the action is an empty string ε. Also the RHS of no of produc-
of yacc for the given grammar? tion does not contain adjacent non-terminal. So P
(a) It detects recursion an eliminate recursion. → QR and P → ε violates the requirement of an
(b) It detects reduce - reduce conflict, and resolve operator grammar.
(c) It detects reduce conflict and resolve the con- Hence, correct option is (b).
flict in favor of a shift over a reduce action.
17. Consider the grammar with the following transla-
(d) It detects reduce conflict and resolve the con-
tion rule and E as the start symbol.
flict in favor of a reduce over shift.
E → E1 # T ⇒ {E. value = E1.value* T.value}
Solution: (c)
T ⇒ E.value = T value}
E → number |E ‘+’ E| E ‘x’ E
T → T1 & F ⇒ { T.value = T1 + F.value}
Shift reduce conflict arises and resolved in favour
of a shift over a reduce action. F ⇒{T.value = F.value}
Hence, correct option is (c). F → num ⇒ {F.value = num.value}
Compute E.value for the root of the parse tree for
the expression. [2004]
⇒F#3&5#6&4
num
⇒2#3&5#6&4 2
Hence, correct option is (c).
Transferring the tree for a top-down parse, we get
1 8. Consider the translation scheme shown below:
the output 95 + 2 +
S → TR
R → + T{printf (‘+’) However, if we take a bottom up SDT, we get (c) as
T → num {print (num.val);} answer. Bottom-up answer is different.
Here num is a token that represents the corre- The string is 9 + 5 + 2
sponding integer and num.val represent an integer The rightmost derivation of the string is
value. For an input string ‘9 + 5 + 2’, this transla- S ⇒ TR ⇒ T + TR ⇒ T + T + TR ⇒ T + T + Te
tion scheme will print [2003]
⇒T+T+2⇒T+5+2⇒9+5=2 E → b
Consider the derivation tree, In the predictive parse table, M of this grammar,
S the entries M [S′, e] and M [S′, $] respectively are
[2003]
(a) {S → eS} and {S′ → ε}
T R (b) {S → eS} and {}
(c) {S → ε} and {S′ → ε}
+ T R (d) {S → eS, S′ → ε} and {S′ → ε}
Solution: (d)
+ T R The grammar is
S → I E t S S′|a
S′ → es|ε
9 5 2 E → b
OUTPUT = 952 + + The predictive parser table is
a b e i ∈ $
Hence, correct option is (b).
S S→a – S→a S → iEtSS – –
19. Consider the grammar shown below:
S → CC S 1
– S → es
1
– – S1 → ∈
S1 → ∈
C → cC|d E – S→b – – –
The grammar is [2003]
(a) LL(1) Hence, correct option is (d).
(b) SLR(1) but not LL(1) 2 1. A shift reduce the parser carries out the actions
(c) LALR(1) but not SLR(1) specified within braces immediately after reducing
(d) LR(1) but not LALR(1) with the corresponding rule of grammar. [1995]
Solution: (a) S → xxW
S → y{print “2”}
Here is the predictive parsing table for the grammar
S → Sz{print “3”}
What is the translation of xxxyzzz using the syntax
S S → CC S → CC – directed translation scheme described by the above
rules?
C cC d –
(a) 23131 (b) 11233
S1 – – S1 → S
(c) 11231 (d) 33211
accepted
Solution: (a)
Use the grammar S1 → e S → xxW ⇒ xxSz ⇒ xxxxWz ⇒ xxxxSzz
⇒ xxxxyzz
S → CC
The rule used in the reverse of the rightmost
C → cC|d
derivation is
The grammar is LR (0), SLR (1), LARL (1) & LR S → y
(1). W → Sz
Hence, correct option is (a). S → xxW
20. Consider the grammar shown below: w → Sz
S → I E t S S′|a S → xxW
S′ → es| → The dependency graph is
2 2 print ("3")
S Z
1 print ("2")
S1 .S S1 .S S1 .S
1. Consider the following grammar: [1988] S .SS S S S.S S S.S
S
S .a S .SS S .SS
S → S S .I0 S .a S .a
S → S S|a|∈ S .I1 S .I4
(a) Construct the collection of sets of LR (0) items Shift
a s/r conflict s/r conflict
state a
for this grammar and draw its go to graphs. a
S a.12
(b) Indicate the shift reduce conflict and reduce-
reduce conflict in the various states of LR (0) reduce state
parser. S 13
Solution: reduce state
S1 → S
S → SS/a/∈ R-R conflicts are not there. I1 and I4 have S/R con-
flicts. Following is the go to graph and table:
Rule 1: r1: S1 → S
a ∈ S S1
Rule 2: r2: S → SS
I0 S2 S3 – –
Rule 3: r3: S → a
I1 S2 S3 4 –
Rule 4: r4: S → ∈
I2 r3 – – –
I3 – r4 – –
I4 S2 S3 4 –
a, d e c d
+ –
b
c
9. Consider the following tuple relational calculus (b) For each school with more than 200 student in
query: [2008] it, the name of school and the number of 100s
{t|∃ E∈ Enrollment t = E.school-id ^ |x|x∈Exam scored by its students.
Result B.school-id = t ^ (∃B∈ExamResult (c) For each school with more than 200 student
B.erollno = x.erollno ^ B.examname ^ B.marks > in it, the name of school and the number of
35}| / |{x|x ∈Enrolment ^ x.school-id = t}|*100 > students scoring 100s in at least one exam.
35} (d) Nothing; the query has a syntax error
If a student needs to score more than 35 marks to Solution: (d)
pass an exam, what does the query returns? If SELECT clause consists aggregate and non-
(a) Empty set aggregate columns in the SELECT list must appear
(b) School with more than 35% of its student en- in Group By clause. But in this query Group by
rolled in some exam or the other consist school id instead of such names.
(c) Schools with a pass percentage above 35% Hence, the correct option is (d).
over all exam taken together
1 1. Consider the table employee (empId, name, depart-
(d) Schools with a pass percentage above 35%
ment, salary) and the two queries Q1, Q2 below.
over each exam
Assuming that department 5 has more than one
Solution: (c) employee, and we want to find the employees who
Division operator is used. Numerator produces get higher salary than anyone in the department 5,
all who scores more than 35 marks, denominator which one of the statments is TRUE for any arbi-
checks all exams, hence, it produces above 35% trary employee table?
over all exams taken together. Q1.: Select e.empId
Hence, the correct option is (c). From employee e
10. What does the following SQL query output? Where not exists(Select * From employee s
[2008] Where s. department = “5” and s.salary > =
Select sch-name, e.salary)
Count(*) Q1. : Select e.empId
FROM school C, From employee e
Enrolment E, Where e.salary > Any (Select distinct salary
Exam Result R From employee s Where s. department = “5”)
Where E.school_id = C.school_id [2007]
AND (a) Q1 is the correct query
E.examname = R.examname (b) Q2 is the correct query
AND (c) Both Q1 and Q2 produce the same answer
E.erollno = R.erolno (d) Neither Q1 nor Q2 is correct queries
AND Solution: (b)
R.amrks = 100 Since Q1 consists ‘not exists’, it produces unde-
AND sired results in certain condition. Q2, inner query
S.school_id IN(SELECT school_id FROM produces salaries for department 5, > Any operator
Student produces the desired results.
GROUP BY school-id HAVING COUNT(*) > Hence the correct option is (b).
200 12. Consider the relation enrolled (student, course)
GROUP BY school-id in which (student, course) is the primary key, and
(a) For each school with more than 200 students the relation paid (student, amount) where student
appearing in the exams, the name of the school is the primary key. Assume no null values and no
and the number of 100s scored by its student. foreign keys or integrity constraints. Given the
following four queries:
3.18 | Database Management System
Query 1: Select student from enrolled where stu- 13. What is the output of the following SQL Query?
dent in (select student from paid) Select D. name
Query 2: Select student from paid where student in
From Drivers D
(select student from enrolled)
Query 3: Select E. student from enrolled E, paid P Where D.did in (Select R.did from Cars C, reserves
where E. student = P student R where R.cid = C.cid and C.color = ’red’
Query 4: Select student from paid where exists Intersect
(select * from enrolled where enrolled. Select R.did
Student = paid. Student
From Cars C, Reserves R
Which one of the following statements is correct?
Where R.cid = C.cid and C.color = ’green’)
[2006]
(a) Karthikeyen, boris
(a) All queries return identical row sets for any da-
(b) Sachin, salman
tabase.
(c) Karthikeyan, Boris, Sachn
(b) Query 2 and Query 4 return identical row sets
(d) Schumacher, Senna
for all databases but there exist databases for
which Query 1 and Query 2 return different Solution: (a)
row sets. First inner queries produces 222, 31. Second inner
(c) There exist databases for which Query 3 re- query produces 22, 31, 74. Intersect operation
turns strictly fewer rows than Query 2. gives 22, 31 as an output. The dname of 22, 31 are
(d) There exist databases for which Query 4 will Karthikeyen, boris.
encounter an integrity violation at runtime. Hence, the correct option is (a).
Solution: (a)
D: Drivers relation
Employee Did Dname Rating Age
Student Course 22 Karthikeyan 7 25
1 a 29 Salman 1 33
1 b 31 Boris 8 55
3 c 32 Amoldt 8 25
3 d 58 Schumacher 10 35
64 Sachin 7 35
All queries producing students (1, 3) details. 71 Senna 10 16
Hence, the correct option is (a). 74 Sachin 9 35
Common Data for Questions 13 and 14 85 Rahul 3 25
Consider database with three relation instances 95 Ralph 3 53
shown below. The primary keys for the Drivers
and Cars relation are did and cid respectively and
the record are stored in ascending order of these R: Reserves relation
primary keys as given in the tables. No indexing is Did Cid Day
available in the database. [2006] 22 101 10/10/06
22 102 10/10/06
Paid
22 103 08/10/06
Student Amount
22 104 07/10/06
1 10
31 102 10/11/06
2 20
31 103 06/11/06
3 10
4 d
Chapter 3 Structure Query Language | 3.19
31 104 12/11/06 R: Reserves relation Which two of the above statements are correct
[2006]
64 101 05/09/06 Did Cname Color
(a) 2 and 5 (b) 1 and 3
64 102 08/09/06 101 Renault Blue
(c) 1 and 4 (d) 3 and 5
74 103 08/09/06 102 Renault Red
Solution: (c)
103 Ferrari Green
104 Jaguar Red Table A Table B
Customer Balance Customer Balance
14. Let n be number of comparisons performed when 1 10 1 10
above SQL query is optimally executed. If linear 2 20 2 20
search is used to locate a tuple in a relation using a
3 10 3 10
primary key, then n lies in the range
(a) 36 - 40 (b) 44 - 48 4 15 4 15
(c) 60 - 64 (d) 100 - 104
Solution: (a) Output of Query 1
Number of linear searches for searching ‘col- Customer Count (B.Customer)
our = red’, ‘color = green’ would be around 38. 1 4
Searching 22, 31 need one more linear search. 2 1
Hence the correct option is (a). 3 4
15. Consider the relation account (customer, balance) 4 2
where customer is a primary key and there are
no null values. We would like to rank customers Output of Query 2
according to decreasing balance. The customer Customer Count (B.Customer)
with the largest balance gets rank 1. Ties are not
1 3
broken but ranks are skipped.
2 1
If exactly two customers have the largest balance
3 3
they each get rank 1 and rank 2 is not assigned.
Query 1: Select A. customer, count (B. customer) 4 2
from account A, account B where A, cus-
tomer If there are no duplicates of balance, then they pro-
Query 2: Select A. customer, 1 + count (B. cus- duce some row set else not. Both are not producing
tomer) from account A, account B where desired result.
A. balance < B. balance 7 group by A. Hence, the correct option is (c).
customer.
16. In an inventory management system implemented
Consider these statements about Query 1 and at a trading corporation, there are several tables
Query 2. designed to hold all the information.
1 Query 1 will produce the same row set as Que-
Amongst theses, the following two tables hold
ry 2 for some but not all databases.
information on which items are supplied by which
2. Both Query 1 and Query 2 are correct imple-
suppliers, and which warehouse keeps which items
mentations of the specification.
along with the stock-level of these items.
3. Query 1 is a correct implementation of the
specification but Query 2 is not. Supply = (supplierid, itemcode) Inventory = (item-
4. Neither Query 1 nor Query 2 is a correct im- code, warehouse, stocklevel)
plementation of the specification. For a specific information required by the manage-
5. Assigning rank with apure relational query ment, following SQL query has been written:
takes less time than scanning in decreas- Select distinct STMP supplierid
ing balance order and assigning ranks using
From Supply as STMP
ODBC.
3.20 | Database Management System
Where not unique (Select ITMP. Supplierid From (a) Execute T1 followed by T2 followed by T3
Inventory, Supply as ITMP (b) Execute T2 followed by T3; T1 running con-
Where STMP. supplierid = ITMP. Supplierid And currently throughout
ITMP. itemcode = Inventory. itemcode (c) Execute T3 followed by T2; T1 running con-
currently throughout
And Inventory. warehouse = ‘Nagpur’);
(d) Execute T3 followed by T2 followed by T1
For the warehouse at Nagpur, this query will find
Solution: (d)
all suppliers who [2005]
(a) Do not supply any item If commission is 99000. If we run T2, it will
(b) Supply exactly one item update commission as 102960. While running T3,
(c) Supply one or more items it will be further updated as 1091376. It is modi-
(d) Supply two or more items fied twice, hence wrong. To have correct result,
execute T3 then T2 and finally T1.
Solution: (d)
Hence the correct option is (d).
Since query consists ‘not unique’ in where class. It
looks for a supply of two or more items. 1 8. The relation book (title, price) contains the title
and prices of different books. Assuming that no
Hence, the correct option is (d).
two book have the same price, what does the fol-
17. A company maintains records of sales made by its lowing SQL query list?
salesperson and pays them commission based on
Select title
each individual’s total sales made in a year. This
data is maintained in a table with the following From book as B
schema: Where (select count(*) from book as T where
Sales info = (sales person id, total sales, com- T.price > B.price) < 5 [2005]
mission). In a certain year, due to better business (a) Titles of the four most expensive books
results, the company decides to further reward its (b) Titles of the fifth most inexpensive books
salespersons by enhancing the commission paid to (c) Titles of the fifth most expensive books
them as per the following formula. If commission (d) Titles of the five most expensive books
< = 50000, enhance it by 2%; if 5000 < commis- Solution: (d)
sion < = 100000, enhance it by 4%; if commis-
Table T Table B
sion > 100000, enhance it by 6%. The IT staff has
written three different SQL scripts to calculate Title Price Title Price
enhancement for each slab, each of these scripts is A 100 A 100
to run as a separate transaction as follows: B 200 B 200
T1 Update sales info C 300 C 300
Set commission = commission * 1.02 D 400 D 400
Where commission < = 50000; E 500 E 500
T2 Update sales info F 600 F 600
19. Consider two tables in a relational database with Insert into student values (2, mukesh, 2)
columns and rows as follows: [2004] Insert into student values (3, gita, 1)
Table: Student How many rows and columns will be retrieved by
the following SQL statement?
Roll_no. Name Dept_id
Select * from student, department [2004]
1 ABC 1 (a) 0 row and 4 columns
2 DEF 1 (b) 3 row and 4 columns
3 GHI 2
(c) 3 row and 5 columns
(d) 6 row and 5 columns
4 JKL 2
Solution: (b)
Table: Department Roll_no. Name Dept-Id Dept_Name
Dept_id Dept_name 1 Naveen 1 Mathematics
2 Mukesh 2 Physics
1 A
3 Gita 1 Physics
2 B
3 C
Hence, the correct option is (b).
2 1. The employee information in a company is stored
Roll_no is a primary key of the student table,
in the relation
Dept_id is the primary key of the department
table and Student. Dept_id is a foreign key to Employee (name, sex, salary, dept Name).
Department_Deptid. Consider the following SQL query
What will happen if we try to execute the follow- Select Dept Name
ing two SQL statements? From Employee
(i) Update Student set Dept-id = Null where
Where sex = ‘M’
Roll_no = 1
(ii) Update department set Dept_id = Null where Group by dept Name having avg (salary) > (select
Dept_id = 1 avg (salary) from Employee)
(a) Both i & ii will fail It returns the names of the department in which
(b) i will fail but ii will succeed [2004]
(c) i will succeed but ii will fail (a) The average salary is more than the average
(d) Both i and ii will succeed salary in the company.
Solution: (c) (b) The average salary of male employee is more
than the average salary of all male employee in
i will succeed as foreign key as Dept_id in student
the company.
can have null values but ii will fail as primary key
(c) The average salary of male employee is more
as Dept_id in department cannot have null values.
than the average salary of employee in the
Hence, the correct option is (c). same department.
20. A relational database contains two tables student (d) The average salary of male employee is more
and department in which student table has a col- than the average salary in the company.
umns roll_no, name and dept_id and department Solution: (d)
table has column dept_id and dept_name.
Inner query gives average salary of all the employ-
The following insert statement was executed suc- ees, and outer query gives the salary of all the male
cessfully to populate the empty tables: employees.
Insert into department values (1, Mathematics) Hence, the correct option is (d).
Insert into department values (1, Physics)
Insert into student values (1, Navin, 1)
3.22 | Database Management System
22. Consider the set of relation shown below and SQL 24. In SQL, relation can contain null values and com-
query that follow: parisons with null values are treated as unknown.
Students: (Roll_number, Name < Date_of_birth) Suppose all comparisons with a null value are
treated as false. Which of the following pairs is not
Course: (Course_number, course_name, Instructor)
equivalent? [2000]
Grades: (Roll_number, Course number, Grades) (a) x = 5 not (not (x = 5))
Se lect distinct Name (b) x = 5 x > 4 and x < 6 where x is an integer
From Students, Course, Grades (c) x ≠ not (x = 5)
Where Students. Roll_number = Grades. (d) None of the above
Roll_number Solution: (c)
And Course. Instructor = “Korth” Hence the correct option is (c)
And Course. Course_number = Grades. 25. Consider the set of relations:
Course_number
EMP (Employee-no, dept-no, Employee-name,
And Grades.grade = ‘A’ Salary)
Which of the following sets is computed by the DEPT (Dept_no, Dept_name, Locaton)
above query? [2003]
(a) Name of student who have got an A grade in Write an SQL query to: [1999]
all courses taught by Korth. (a) Find all employee names who work in depart-
(b) Name of students who have got an A grade in ment located at ‘Calcutta’ and whose salary is
all courses. greater than 50, 000.
(c) Name of the student who have got an A grade (b) Calculate for each department, the number of
in at least one of the course taught by Korth. employees with a salary greater than 100, 000.
(d) None of the above Solution:
Solution: (c) (a) Select EMP Employee-name FROM EMP,
Students. Roll_number = Grades. Roll_number DEPT where EMP.Dept-no = DEPT.Dept-no
and Grades.grade = ‘A’ lokks for stdent with A and DEPT > Location = ‘calcutta’
grades. (b) Select Dept. no,
Count( Employee-no) from EMP where salary
Course. Instructor = ‘Korth‘ And Course.Course_
> 100, 000 GROUP BY Deptno
number = Grades. Course_number looks for
course taught by Korth. 26. Which of the following is/are correct? [1999]
So, students taught by Korth with grade B will not (a) An SQL query automatically eliminates dupli-
be retrieved in the query. cates.
Hence, the correct option is (c). (b) An SQL query will not work if there are no
indexes on the relation.
23. Given relation r(w, x) and s(y, z) the result of select (c) SQL permits attributes names to be repeated
distinct w, x from r, s is guaranteed to r, provided in the same relation.
[2000] (d) None of the above
(a) r has no duplicate and s is non-empty
(b) r and s have no duplicates Solution: (d)
(c) s has no duplicates and r is non-empty Hence the correct option is (d)
(d) r and s have the same number of tuples 27. Suppose we have a database consisting of the
Solution: (a) following three relations. [1998]
Hence the correct option is (a) FREQUENTS (student, parlor) giving the parlors
each student visit.
Chapter 3 Structure Query Language | 3.23
SERVES (parlor, ice-cream) indicating which kind Print the student that frequents to at least one
of ice-cream each parlor serves. parlor that serves some ice-cream that they like.
LIKES (student, ice-cream) indicating what ice- Solution:
cream each students likes. Select Student from FREQUENTS where parlor in
(Assume that each student likes at least one ice- (Select ice-cream in (Select ice-cream from LIKES
cream and frequents to at least one parlor). where LIKE.Student = FREQUENT.Student
Express the following SQL:
Chapter 4
Relational Algebra and
Relational Calculus
Solution: (d)
One-mark Questions
Relational algebra, tuple relation calculus, domain
1. What is the optimized version of the relation alge- relation calculus have same expression power.
bra expression π A1 (πA2 (σFl (σF2 (r)))), where A1, Hence the correct option is (d)
A2 are sets of attributes in r with A1 ⊂ A2 and F1, 4. Consider the relations r1 (P, Q, R) and r2 (R, S,
F2 are Boolean expressions based on the attributes T) with primary keys P and R, respectively. The
in r? [2014] relation r1 contains 2000 tuples and r2 contains
(a) πA1( σ F1 ∧ F2 (r)) (b) πA1( σ F1 ∨ F2 (r)) 2500 tuples. The maximum size of the join r1 r2 is
(c) πA2( σ F1 ∧ F2 (r)) (d) πA1( σ F1 ∨ F2 (r)) [2006]
Solution: (a) (a) 2000 (b) 2500
Hence the correct option is (a) (c) 4500 (d) 5000
2. Which of the following tuple relational calculus Solution: (a)
expression(s) is/are equivalent to ∀t∃r(P(t)? R in r1 (P, Q, R) is foreign key with 2000 tuple ref-
[2008] erences R (primary key) in r2 (R, S, T) with 2500
(a) ¬ ∀t∈ r(P(t) (b) ∃t ∉ r(P(t) tuples. So, natural matching rows are 2000.
(c) ¬ ∃t∈ r( ¬P(t) (d) ∃t ∉ r(¬P(t) Hence the correct option is (a)
Solution: (d) 5. Let r be a relation instance with schema R = (A,
Output of option (c) and (d) and output of expres- B, C, D). We define r1 = ΠA, B, C (r) and r2 = Π
sion in question are all equivalent. A.D (r). Let s = r1 * r2 where * denotes natural
join. Given that the decomposition of r into r1 and
Hence the correct option is (d) r2 is lossy, which one of the following is TRUE?
3. Which of the following relational query languages [2005]
have the same expressive power? (a) s⊂r (b) r ∪ s = r
(I) Relational algebra (c) r⊂s (d) r * s = s
(II) Tuple relational calculus restricted to safe ex- Solution : (c)
pressions
(III)Domain relational calculus restricted to safe S = r1*r2 will have all matching rows from r1 & r2
expressions [2006] and possible to have more rows than original table r.
(a) II and III only (b) I and II only Hence the correct option is (c)
(c) I and III only (d) I, II and III
Chapter 4 Relational Algebra and Relational Calculus | 3.25
6. Let R1 (A, B, C) and R2 (D, E) be two relation (c) Relational algebra has the same power as safe
schema, where the primary keys are shown under- relational calculus.
lined and let C be a foreign key in R1 referring (d) None of the above.
to R2. Suppose there is no violation of the above Solution: (c)
referential integrity constraint in the correspond-
Hence the correct option is (c)
ing relation instances r1 and r2. Which one of the
following relational algebra expressions would 9. Given the relations employee (name, salary, deptno)
necessarily produce an empty relation? [2004] and department (deptno, deptname, address).
1. ΠD (r2) - ΠC (r1) Which of the following queries cannot be expressed
2. ΠC (r1) - ΠD (r2) using the basic relational algebra operations (σ, π,
3. ΠD (r1 C1D r2) × , ∪, ∩, −)? [2000]
4. ΠC (r1 C = D r2) (a) Department address of every employee
Solution: (b) (b) Employees whose name is the same as their
department name
Since C is a forign key, values in C must be avail-
(c) The sum of all employees’ salaries
able in R2. Relational algebra expression πc(r1) -
(d) All employees of a given department
πD (r2) describes rows available in c (r1) but not
available in re, but that is not possible for foreign Solution: (c)
key column. For aggregates, extended algebra is needed as
Hence the correct option is (b) basic RA operators are not possible.
7. Consider the following SQL query Hence the correct option is (c)
select distinct a1, a2 ..., an 10. The relational algebra expression equivalent to the
following tuple calculus expression
from r1, r2, ..., rm
{t/ t e r∧(t[A] = 10∧t[B] = 20)} is: [1999]
where P
(a) σ (A = 10VB = 20) (r)
For an arbitary predicate P, this query is equiva- (b) σ (A = 10) (r) ∪ σ (B = 20) (r)
lent to which of the following relational algebra (c) σ (A = 10) (r) ∪ σ (B = 20) (r)
expressions? [2003] (d) σ (A = 10) (r) - σ (B = 20) (r)
(a) Π σ p (r1 × r2 × ... × rm ) Solution: (c)
a a 1, 2,..., an
‘∩’ and ‘∧’ have same effect.
(b) Π σ p (r1 r2 ... rm ) Hence the correct option is (c)
a a2,..., an
1,
11. Consider the join of a relation R with a relation S.
(c) Π σ p (r1 ∪ r2 ∪ ... ∪ rm ) If R has m tuples & S has n tuples , then the maxi-
a a2,..., an
1,
mum and minimum sizes of join respectively are:
(d) Π σ p (r1 ∩ r2 ∩ ... ∩ rm ) [1999]
a a 1, 2,..., an (a) m + n and 0 (b) mn and 0
Solution: (a) (c) m + n and |m - n| (d) mn and m + n
Project operator (π) filters attributes, select opera- Solution: (b)
tor filters row with a condition. The maximum size would be the case where every
Hence the correct option is (a) tuple of R is combined with every tuple of S to get
8. With regard to the expressive power of the formal mn tuples. The minimum case is when 0 tuples of
relational query languages, which of the following R is able to combine with any tuple of S.
statements is true? [2002] Hence the correct option is (b)
(a) Relational algebra is more powerful than rela- 12. Give a relational algebra expression using only the
tional calculus. minimum number of operators from {U, - }.
(b) Relational algebra has the same power as rela-
tional calculus. What is equivalent of R∩S. [1994]
3.26 | Database Management System
Solution: (TRUE) (d) Join selection factor between r(R) and s(S) is
As we know that intersection can be expressed in less than 0.5.
union and minus. Solution: (a)
For example, (A ∪ B) – (A - B) ∪ (B - A). Relation instance ‘s’ can be used by the reserve
13. An instance of a relational schema R (A, B, C) has buffer. Relation instance ‘r’ has less number of
distinct values for attribute A. Can you conclude records than ‘s’, hence using ‘r’ in the outer query
that A is a candidate key for R? [1994] requires fewer block accesses.
Solution: (TRUE) Hence the correct option is (a)
The minimal set of attributes that uniquely 3. Suppose R1(A, B) and R2(C, D) are two relation
identifies a tuple on a selection. schemas . Let r1 and r2 be the corresponding rela-
tion instances. B is a foreign key that refers to C in
R2 . If data in r1 and r2 satisfy referential integrity
Two-marks Questions constraints, which of the following is ALWAYS
TRUE? [2012]
1. Consider the relational schema given below, where (a) Π B (r1) - ΠC (r1) = ϕ
eId of the relation employee. Assume that every (b) Π C (r1) - ΠB (r1) = ϕ
employee has at least one associated dependent in (c) Π B (r1) = ΠC (r1)
the dependent relation. Employee (empId, emp- (d) Π B (r1) - ΠC (r1)ϕ
Nmae, empAge) and dependent (depId, eId, dep- Solution: (a)
Name, depAge) consider the following relational
Π B (r1) - ΠC (r1) = ϕ is always true.
algebra query:
Consider the following relations A, B and C:
ΠempId (employee) - ΠenpId (employee ∞
(emoId = eId) ^ (empAge ≤ depAge) dependent) Id Name Age
The above query evaluates to the set of empIds of 12 Arun 60
employees whose age is greater than that of[2014] 15 Shreya 24
(a) Some dependent 99 Rohit 11
(b) All dependent
Hence the correct option is (a)
(c) Some of his/her dependent
(d) All of his/her dependent A
S1 is conflict seriaizable to T2 → T3 → T1
S2 :
T1 T2 T3
R(x) T4 T3
R(y)
R(y) Because the precedence graphs does not contain
Precedence graph R(z) R(x) cycles, the schedule given is conflict serializable.
R(z) As the given schedule is strict , every strict sched-
T1 T2 W(x) W(y) ule is both recoverable and cascade less.
Hence, the correct option is (c).
W(z)
W(z) 3. Consider the following four schedules due to three
T3
transactions (indicated by the subscript) using read
and write on a data item x, denoted by r(x) and
S2 is not conflict serializable. w(x) respectively. Which one of them is conflict
Hence, the correct option is (a). serializable? [2014]
(a) r1(x); r2(x); w1(x); r3(x); w2(x)
(b) r2(x); r1(x); w2(x); r3(x); w1(x)
Chapter 5 Transactional and Concurrency Control | 3.33
(c) r3(x); r2(x); r1(x); w2(x); w1(x) 4. Consider the following transactions with data
(d) r2(x); w2(x); r3(x); r1(x); w1(x) items P and Q initialized to zero:
Solution: (d) T1: read (P);
Option (A) read (Q);
T1 T2 T3
if P = 0 then Q : = Q + 1 ;
R(x) T1 T2 write (Q).
T2: read (Q);
R(x)
W(x) T3
If Q = 0 then P: = P + 1;
R(x) write (P).
W(x)
Any non-serial interleaving of T1 and T2 for
concurrent execution leads to [2012]
Option (B)
(a) a serializable schedule
T1 T2 T3 (b) a schedule that is not conflict serializable
R(x) T1 T2 (c) a conflict serializable schedule
R(x) (d) a schedule for which a precedence graph can-
not be drawn.
W(x) T3
R(x) Solution: (b)
W(x) Since P and Q are initialized to zero, write opera-
tion on P and Q will be executed. Consider any
Option (C) non-serial schedule like R1(P). R2(Q), R1(Q),
R2(P), W1(Q), W2(P). R1(P), R2(Q), R1(P) conflicts
T1 T2 T3
T1 T2
with W2(P), hence, T1 must be before T2. R2(Q)
R(x) conflicts with W1(Q), hence T2 must be before T1.
R(x)
R(x) There is no serial schedule satisfies both of them,
T3 hence, it is not conflict serializable.
W(x)
Hence, the correct option is (b).
W(x)
5. T T T
Option (D) 1 2 3
Read (X)
T1 T2 T3 Read (Y)
R(x) T1 T2 Read (Y)
W(x) Write (Y)
R(x) Write (X) Write (X)
Read (X)
T3
R(x)
W(x) Write (X)
Conflict Serializable
Which one of the schedules below is the correct
Option (D) serialization of the above? [2010]
T1 T2 T3 (a) T1 → T3 → T2 (b) T2 → T1 → T3
R(x) T1 T2 (c) T2 → T3 → T1 (d) T3 → T1 → T2
W(x) Solution: (a)
R(x)
R1(X), R1(Y), R3(Y), W2(Y), W1(X), W3(X), R2(X),
T3
R(x) W2(X).
W(x)
Conflict Serializable
R3(Y), W2(Y) are conflicting, and hence, serial-
izability says T3 must be before T2 in any serial
Hence, the correct option is (d). schedule.
3.34 | Database Management System
W1(X), W3(X) are conflicting, and hence, serial- 8. Consider the following three schedules of transac-
izability says T1 must be before T3 in any serial tion T1, T2 and T3. Notation: In the following, NYO
schedule. represents the action Y (R for read, W for write)
W3(X), R2(X) are conflicting, and hence, serial- performed by transaction N on object O.]
izability says T3 must be before T2 in any serial (S1) 2RA 2WA 3RC 2WB
schedule. 3WA 3WC 1RA 1RB
The serial schedule T1, T3 and T2 is satisfying all 1WA 1WB
the above conditions. Directed graph for the non-
(S2) 3RC 2RA 2WA 2WB
serial schedule will also give same sequence.
3WA 1RA 1RB 1WA
Hence, the correct option is (a).
1WB 3WC
6. Let R and S be relational schemes such that R =
{a, b, c} and S = {c}. Now consider the following (S3) 2RA 3RC 3WA 2WA 3WB
queries on the database. 3WC 1RA 1RB 1WA
I. πR - S (r) - πR - S (πR - S (r)XS - πR - S.S (r)) 1WB
II. {t|t∈πR - S (r) ∧ ∀u∈s (∃ v ∈r((u = v[s] ∧ t =
Which of the following statements is TRUE?
v[R - S]))}
[2008]
III. {t|t ∈πR - S (r) ∧ ∀v∈r(∃u ∈s(u = v[s] ∧ t = v[R
(a) S1, S2 and S3 are all conflict equivalent to each
- S]))}
other
IV. select R.a, R.b (b) No two of S1, S2 and S3 are conflict equivalent
From R, S to each other
Where R.c = S.c (c) S2 is conflict equivalent to S3, but not to S1
(d) S1 is conflict equivalent to S2, but not to S3
Which of the above queries are equivalent?[2009]
(a) I and II (b) I and III Solution: (d)
(c) II and IV (d) III and IV S1 and S2 are conflict serializable schedule T2, T3,
Solution: (c) T1.
In IV, output consists a, b attributes of R where c S3 is not conflict equivalent as 2RA, 3WA (T2 <
in R and S must match. In II, πR - S gives a, b as T3) and 3WA, 2WA (T3 < T2) are the conflict opera-
output, u is variable of S and V is variable of R. tions. There is no serial schedule that satisfies both
verifying existence of u in v gives same output of IV T2 < T3 and T3 < T2.
Hence, the correct option is (c). Hence, the correct option is (d).
7. Consider two transactions T1 and T2, and four 9. Consider the following two transactions: T1 and T2.
schedules S1, S2, S3, S4 of T1 and T2 as given below: T1: read (a); T2: read (b);
T1: R1 [x] W1 [x] W1 [y] read (b); read (a);
T2: R2 [x] R2 [y] W2 [y] if A = 0 then
S1: R1 [x] R2 [x] R2 [y] W1 [x] W1 [y] W2 [y] B → B + 1; if B → 0 then
S2: R1 [x] R2 [x] R2 [y] W1 [x] W2 [y] W1 [y] A → A – 1;
S3: R1 [x] W1 [x] R2 [x] W1 [y] R2 [y] W2 [y] write (b) ; write (a) ;
S4: R2 [x] R2 [y] R1 [x] W1 [x] W1 [y] W2 [y] Which of the following schemes, using shared and
exclusive locks, satisfy the requirements for strict
Which of the above schedules are conflict-
two-phase locking for the above transactions?
serializable? [2009]
[2007]
(a) S1 and S2 (b) S2 and S3
(a) S1: lock S(a); S2: lock S(b);
(c) S3 only (d) S4 only
read(a); read (b);
Solution: (b) lockS(b); lockS(a);
Hence, the correct option is (b).
Chapter 5 Transactional and Concurrency Control | 3.35
12. Consider three data items D1, D2, and D3, and the 13. For the schedule given below, which of the follow-
following execution schedule of transactions T1, T2 ing is correct
and T3. In the diagram, R(D) and W(D) denote the
actions reading and writing the data item D respec- T1 T2
tively. [2003] Read A
T1 T2 T3 Read B
T3 R(D3); Write A
R(D2); Read A
W(D2); Write A
R(D2);
Write B
R(D3);
Read B
R(D1);
Write B
W(D1);
W(D2); [1999]
W(D3); (a) This schedule is serializable and can occur in a
R(D1); scheme using 2PL, protocol.
(b) This schedule is serializable but cannot occur
R(D2);
in a scheme using 2PL protocol.
W(D2); (c) This schedule is not serializable but can occur
W(D1) in a scheme using 2PL protocol.
(d) This schedule is not serializable and cannot
Which of the following statement is correct? occur in a scheme
(a) The schedule is serializable as T2; T3; T1; Solution: (d)
(b) The schedule is serializable as T2; T1; T3;
W1(a), R(2) and W2(b) , R1(b) are conflicting;
(c) The schedule is serializable as T3; T2; T1;
going by the principles of seriaziability, it is not
(d) The schedule is not serializable as T2; T3; T1;
serializable and cannot occur in 2PL.
Solution: (d)
Hence, the correct option is (d).
Apart from other conflicts operations, we have
W2(D2), W1(D2) [which says T2 < T1], W1(D2),
R2(D1) [which says T1 < T]. T2 < T1 and T1 < T2 are
not possible in any serializable schedule.
Hence, the correct option is (d).
Chapter 6
File Structure
and Indexing
Solution: (a)
One-mark Questions Insertion of new key will lead insertion at all the
four levels. Thus, new root node insertion. Hence,
1. Consider a B + - tree in which the maximum num-
maximum 5 nodes can be created.
ber of keys in a node is 5. What is the minimum
Hence, the correct option is (a).
number of keys in any non-root node? [2010]
(a) 1 (b) 2 4. B* - trees are preferred to binary trees in data-
(c) 3 (d) 4 bases because [2000]
(a) Disk capacities are greater than memory
Solution: (b)
capacities.
All internal nodes except root, will have between (b) Disk access is much slower than memory
n/2 and n children where n is the order of the nodes. access.
As maximum node is given 5, the maximum num- (c) Disk data transfer rates are much less than
ber of children a node can have is 6. Number of memory data transfer rates.
keys in node is (n - 1). Hence, maximum number (d) Disks are more reliable than memory.
of keys are = n/2 - 1 = 6/2 - 1 = 2. Solution : (b)
Hence, the correct option is (b). While accessing large sets of data, B + trees are
2. A clustering index is defined on the fields which faster than binary tree as they grow vertically. Also
are of type [2008] all leaf nodes are equal distance from the node.
(a) Non-key and ordering Hence, the correct option is (b).
(b) Non-key and non-ordering 5. Which of the following is correct? [1999]
(c) Key and ordering (a) B-trees are for storing data on disk and B*
(d) Key and non-ordering. trees are for main memory.
Solution: (a) (b) Range queries are faster on B* trees.
Cluster index is created on a column with cluster (c) B-trees are for primary indexes and B* trees
of values, so it is non-key but it requires order. are for secondary indexes.
(d) The height of a B* tree is independent of the
Hence, the correct option is (a).
number of records.
3. A B-tree, used as an index for a large database Solution: (b)
table, has four levels including the root node. If
In B + tree, leaf nodes are linked together. So,
a new key is inserted in this index, then the maxi-
range queries will be faster.
mum number of nodes that could be newly created
Hence, the correct option is (b).
in the process are [2005]
(a) 5 (b) 4
(c) 3 (d) 2
3.38 | Database Management System
Rama 27 CON A
Abdu 22 ENG A
Jeniffer 28 DOC B Split: 2
Maya 32 SER D
Insert 4
Dev 24 MUS C
Two-marks Questions
1. The following key values are inserted into a B +
–tree in which the 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 is the Hence, the correct option is (b).
maximum number of tree pointers in each node, 2. Consider a file of 1684 records. Each record is 32
and the order of leaf nodes is the maximum num- bytes long and its key field has the size of 6 bytes.
ber of data items that can be stored in it. The B + The file ordered on a non-key field, and the file
–tree is initially empty. organization is unplanned. The file is stored in a
10, 3, 6, 8, 4, 2, 1 file system with block size 1024 bytes, and the
The maximum number of times leaf nodes would size of a block pointer is 10 bytes. If the secondary
get split up as a result of these insertions is[2009] index in built on key field of the file, and a multi-
(a) 2 (b) 3 level index scheme is used to store the secondary
(c) 4 (d) 5 index, the number of first-level and second-level
blocks in the multi-level index are, respectively
Solution: (b) [2008]
Insert 10 (a) 8 and 0 (b) 128 and 6
(c) 256 and 4 (d) 512 and 5
Insert 3 Solution: (c)
Since, block size is 210 , 2m X 2n = 210, therefore,
Split: 1 option (c) satisfies with m = 8 and n = 2.
Insert 6 Hence, the correct option is (c).
6
Chapter 6 File Structure and Indexing | 3.39
Common Data for Questions 3 and 4. (i) The height of tree remains the same.
Consider the B + tree in adjoining figure, where (ii) The node
each node has at most two keys and three links (disregarding the links) is present in the tree.
[2007] K20
(a) 1 (b) 2
(c) 3 (d) 4
Solution: (a)
Insert 15
Hence, root now consists (i) & (ii) are true and (iii)
is not true.
Hence , the correct option is (a).
5. The order of a leaf node in a B + –tree is the maxi-
mum number of (value, data record pointer) pairs
Insert 25 it can hold. Given that the block size is 1K bytes,
data record pointer is 7 bytes long, the value field
is 9 bytes long and a block pointer is 6 long, what
is the order of the leaf node? [2007]
(a) 63 (b) 64
(c) 67 (d) 68
Solution: (b)
n X P + (n - 1) k < = B, Where n is order of the
nodes, p is the block pointer, k search key value
Hence, the correct option is (a). and B is block size.
4. Now the key K50 is deleted from the B + tree Therefore n X 6 + (n - 1) 9 < = 1024.
resulting after the two insertion made earlier.
Consider the following statements about the B + n = 1033/16 = 64(approx.).
tree resulting after this deletion. Hence the correct option is (b).
3.40 | Database Management System
11/19/2015 6:59:54 PM
Chapter 1
Fundamentals and SWP
4. Choose the best matching group between Group-I
One-mark Questions and Group-II [2004]
1. Which of the following are used to generate a Group-I Group-II
message digest by the network security protocols? P. Data Link Layer 1. Ensure reliable transport
[2014] of data over a physical
(a) RSA (b) SHA-1 point-to-point network
(c) DES (d) MD5 Q. Network layer 2. Encodes/decodes data for
physical transmission
Solution: (c) R. Transport Layer 3. Allows end-to-end com-
Message digest function is generated by SHA-1 munication between two
and MD-5 only. processes
RSA and DES are used for encryption and 4. Routes data from one
decryption. network node to next
Hence, the correct option is (c) node
(a) P-1, Q-4, R-3 (b) P-2, Q-4, R-1
2. Which of the following is not client server applica- (c) P-2, Q-3, R-1 (d) P-1, Q-3, R-2
tion? [2010]
(a) Internet chat (b) Web browsing Solution: (a)
(c) e-mail (d) Ping Data link layer offers reliability on link to link
Solution: (d) basis. Where as transport layers offers the same on
end to end basis. And network layer is responsible
PING is utility, to check connectivity either for routing.
between client-client or client server.
Hence, the correct option is (a)
Hence, the correct option is (d)
3. The maximum window size for data transmission
using the selective reject protocol with n-bit frame Two-marks Questions
sequence numbers is [2005]
(a) 2n (b) 2n-1 1. Consider a selective repeat sliding window proto-
(c) 2n -1 (d) 2n-2 col that uses a frame of size of 1KB to send data on
Solution: (b) a 1.5 mbps link with one wave latency of 50 msec.
To achieve a link utilization of 60% , l is minimum
WS+WR = 2n ; If WS = WR then maximum window number of bits required to represent the sequence
2n-1. number field is_______. [2014]
Hence, the correct option is (b)
1024 N = 5 bits.
Total sequence number required in SR = 22, hence Hence, the correct option is (d)
it requires 5 bits.
4. Suppose the sliding window protocol is used with
2. An Internet service provider has the following the sender window size of 2l , where l is the number
chunk of CIDR-based IP address available with it: of bits identified in the earlier part and acknowl-
245:248:128.0/20. The ISP wants to give half of edgement are always piggy backed. After sending
this chunk of address to organization A and a quar- 2l frames, what is the minimum time the sender
ter to organization B, while retaining the remain- will have to wait before starting transmission of
ing with itself. Which of the following is value the next frames?
allocation of address A and B? [2012]
(Identify the closest choice ignoring the frame pro-
(a) 245.248.136.0/21 and 245.248.128.0/22
cessing time).
(b) 245.248.128.0/21 and 245.248.128.0/22
(a) 16 ms (b) 18 ms
(c) 245.248.132.0/22 and 245.248.132.0/21
(c) 20 ms (d) 22 ms
(d) 245.248.136.0/21 and 245.248.132.0/21
Solution: (b)
Solution: (b)
Transmission delay for a packet = C/B = 1µsec.
20 address indicates that 20-bits are allocated for
NID and remaining 12-bits are left over hosts. If l = 5, then sequence numbers
Therefore, total possible hosts are 40. If half of 25 = 32
them are allocated to network, then it will have For 32 packets it takes 32µsec.
2048 hosts with 11 hosts bits and network B will
RTT = 2 × 25 µsec = 50 µsec.
have 1024 hosts with 10 host ID bits. Therefore
/21 is for network A and /22 for network B. Since Hence minimum time sender has to wait to trans-
it is class network and first 20-bits are allocated for fer next set of packet
N, hence by keeping 245.248.128 as it is generate = 50µsec - 32µsec = 18µsec.
above IDs through VLSM. Hence, the correct option is (b)
Hence, the correct option is (b) 5. Station A needs to send a message consisting of 9
Common Data for Questions 3 and 4 packets to station B using sliding window(window
Frames of 1000-bits are sent over a 106 bps duplex size 3) and 'go-back-n-error control strategy'. All
link between two hosts. The propagation time is packets are ready & and immediately available for
25ms. Frames are to be transmitted into this link transmission. If every 5th packet that A transmit
to maximally pack them in transit(within the link) gets lost (but no acks from B ever lost), then what
[2009] is the number of packets that A will transmit from
sending the message to B? [2006]
3. What is the minimum number of bits (l) that will
(a) 12 (b) 14
be required to represent the sequence numbers dis-
(c) 16 (d) 18
tinctly? Assume that no time gap needs to be given
between transmissions of two frames. Solution: (c)
(a) l = 2 (b) l = 3 Hence, the correct option is (c)
(c) l = 4 (d) l = 5 6. Station A uses a 32 byte packets to transmit mes-
Solution: (d) sages to Station B using a sliding window pro-
RTT = 25µsec × 2 = 50µsec. tocol. The round trip delay between A & B is 80
milliseconds and bottleneck path between A & B
1 sec – link is capable of delivering 106/2 bps.
is 128 kbps. What is the optimal window size that over the link is 200 µs. What is the maximum
A should use? [2006] achievable throughput in this communication?
(a) 20 (b) 40 [2003]
(c) 160 (d) 320 (a) 7.69 × 106 bps (b) 11.11 × 106 bps
Solution: (b) (c) 12.33 × 106 bps (d) 15.00 × 106 bps
RTT = 80 µsec, packet size Solution: (b)
= 32 × 8-bits B = 128 kbps. L = 1000 bytes
Optimal window size in terms bits Tr delay = 50µ sec
= 128*103*80*10-3 = 128 × 80. Prop delay = 200 µsec
Window in term of packets Window size = 5 packets
= 128*80/32*8 RTT = Tr delay + 2x prop delay
= 40 = 450µsec
Hence, the correct option is (b) Throughput = 1 window/RTT
7. Host A is sending data to host B over a full duplex = 5 × 1000 × 8 bits/sec
link. A and B are using the sliding window protocol OR
for flow control. The send and receive window sizes Throughput = 1 window/RTT
are 5 packets each. Data packets (sent only from A
= 5 × 1000 bytes/ 450 µsec
to B) are all 1000 bytes long and the transmission
time for such a packet is 50µs. Acknowledgement = 11.11 × 106 bytes/sec.
packets (sent from B to A) are very small & request Hence, the correct option is (b)
negligible transmission time. The propagation delay
Two-marks Questions
Solution:
For each hop TTL is reduced by 1 and there are 6 1. Consider a token ring network with a length of 2
hops here hence 32 - 6. km having 10 stations including a monitoring sta-
2. In Ethernet when Manchester encoding is used, the tion. The propagation speed of signal is 2 × 108
bit rate is: [2007] m/s and the token transmission time is ignored if
(a) Half the baud rate each station is allowed to hold the token for 2 µsec,
(b) Twice the baud rate the minimum time for which the monitoring sta-
(c) Same as baud rate tion should wait(in µsec) before assuming that the
(d) None of the above token is lost is__________. [2014]
Solution: (a) Solution:
In Manchester encoding, we use two signal Token rotation time
changes to represent a bit. So, baud rate is twice = propagation delay in the ring + Number of active
the bit rate. stations × THT
Hence, the correct option is (a) = 2 × 103 / (2 × 108) + 10 × 2 micro sec
= 30 micro sec.
Minimum time monitoring station should wait (a) 500 meters of cable
= Token rotation time (b) 200 meters of cable
(c) 20 meters of cable
= 30 micro sec.
(d) 64 meters of cable
2. Determine the maximum length of the cable (in
Solution: (c)
km) for transmitting data at a rate of 500Mbps
in an Ethernet LAN with frames of size 10,000- 1 Bit delay = 1/B = 1/10 × 106 = 0.1 µsec.
bits. Assume the signal speed in the cable to be Propagation speed = 200m/µsec.
2,00,000 km/s. [2013] Hence, within 0.1 µsec we are able to travel upto
(a) 1 (b) 2 20m.
(c) 2.5 (d) 5
Hence, the correct option is (c)
Solution: (b)
5. There are n stations in a slotted LAN. Each station
To find all collision in Ethernet Transmission delay attempts to transmit with a probability p in each
must be equal to RTT. time slot. What is the probability that ONLY one
L/B = 2 × D/V. 10000/500 × 106 station transmits in a given time slot? [2007]
= 2 × D/200000 = 2 KM (a) np(1 - p)n - 1 (b) (1 - p)n - 1
(c) p(1 - p)n - 1 (d) 1 - (1 - p)n - 1
Hence, the correct option is (b)
Solution: (a)
3. The distance between two stations M and N is L
kilometers. All frames are K-bits long. The prop- Probability of a station not to transfer packet =
agation delay per kilometers is t seconds. Let R 1 - P.
bits/second be the channel capacity. Assuming that For a successful transmission, remaining n - 1 stations
processing delay is negligible, the minimum num- should not transfer a packet.
ber of bits for the sequence number field in a frame Probability for n - 1 station not to transfer packet
for maximum utilization, when the sliding window = (1 - p)n - 1
protocol is used, is: [2007]
So, for a successful transmission for a single station
(a) [log2 2LtR + 2k/k]
among n stations
(b) [log2 2LtR/k]
(c) [log2 2LtR + k/k] = np(1 - p)n - 1`
(d) [log2 2LtR + 2/2k] Hence, the correct option is (a)
Solution: 6. A and B are only two stations on an Ethernet. Each
Utilizing = Tr delay for W packets/Tr delay + RTT has a steady queue of frames to send. Both A &
B attempt to transmit a frame, collide and A wins
(W X K/R)
the first back off race. At the end of this successful
K + 2 LT = 1 transmission by A, both A and B attempt to trans-
R mit and collide. The probability that A wins sec-
For a maximum utilization it should be equal to 1. ond backoff race is [2004]
(a) 0.5 (b) 0.625
W = K + 2LRt
(c) 0.75 (d) 1.0
Sequence number required = W. Therefore
Solution: (b)
2n = K + 2LRt/ K
Collision number for 'A' is 1, and for 'B' it is 2.
N = log2(K + 2LRt)/K Possible numbers for ‘A’ from back off algorithm
Where n number of bits in sequence number field. is (0, 1), for 'B' they are (0, 1, 2, 3). Going by the
4. In a token ring network, the transmission speed is combinations, A will have 5 chances and 'B' has 1
107 bps and the propagation speed is 200 meters/ chance out of 8. Rest of the two is Undecided.
µs. The 1-bit delay in this network is equivalent to: Hence, probability of A is 5/8 = 0.625
[2007] Hence, the correct option is (b)
7. A 2 km long broadcast has LAN has 107 bps band = 2*(d/v)*B = 2 × (2/2 × 105) × 107
width and uses CSMA/CD. The signal travels along = 200 bits or 25 bytes.
wire at 2 × 108 m/s. What is the minimum packet
So, answer is none of them.
size that can be used on this network? [2003]
(a) 50 bytes Hence, the correct option is (d)
(b) 100 bytes 8. Suppose the round trip propagation delay for a 10
(c) 200 bytes Mbps Ethernet having 48-bit jamming signal is
(d) None of the above 46.4 µs. The minimum frame size is: [2003]
Solution: (d) (a) 94 (b) 416
(c) 464 (d) 512
d = 2km
Solution: (c)
v = 2 × 108 m/sec = 2 × 105 km/sec
L = 4.64 µsec × 10 × 106 = 464
B = 107 kbps
Hence, the correct option is (c)
Minimum packet size (L)
(c) UDP, TCP, UDP and TCP 10. One of the header field in an IP datagram is the
(d) TCP, UDP, TCP and UDP Time-To-Live(TTL) field. Which of the following
Solution: (c) statements best explains the need for this field?
[2010]
UDP : Multimedia
(a) It can be used to prioritize packets.
TCP, DNS : File transfer (b) It can be used to reduce delays.
TCP: Email (c) It can be used to optimized throughput.
Hence, the correct option is (c) (d) It can be used to prevent packet looping.
6. The Protocol Data Unit (PDU) for the application Solution: (d)
layer in the Internet stack is [2012] Router is using default route to transfer packet
(a) Segment (b) Datagram if DIP of packet does not match with any of the
(c) Message (d) Frame entries of its routing table.
Solution: (c) Default route leading to infinite looping some-
Hence, the correct option is (c) times, hence TTL is used to avoid infinite looping.
7. The decimal value 0.5 in IEEE single precision Hence, the correct option is (d)
floating points representation has [2012] 11. What is the maximum size of data that the applica-
(a) fraction bits of 000…000 and exponent value tion layer can pass to the TCP layer below?[2008]
of 0. (a) Any size
(b) fraction bits of 000…000 and exponent value (b) 216 bytes – size of TCP header
of -1. (c) 216 bytes
(c) fraction bits of 100…000 and exponent value (d) 1500 bytes
of 0 Solution: (a)
(d) no exact repvresentation.
Application layer can forward any size of packet
Solution: (b) but transport layer should ensure that each seg-
Exponent value is 0 1 1 1 1 1 1 0 ment should be of 64 KB.
True Fraction is -1
Hence, the correct option is (a)
Also fraction 0000....00000 = exponent
12. For which one of the following reason does
Hence, the correct option is (b)
Internet Protocol (IP) use the Time-To-Live(TTL)
8. In the IPv4 addressing format, the number of field in the IP diagram header? [2006]
networks all allowed under Class C addresses is (a) Ensure packets reach destination within that
[2012] time
(a) 214 (b) 27 (b) Discards packets that reach later than that time
(c) 221 (d) 224 (c) Prevents packets from looping indefinitely
Solution: (c) (d) Limits the time for which a packet gets queued
In class C network, NID bits are 24, but first three in intermediate routers
bits are reserved as 110. Hence, network possible Solution: (c)
is 221. Router is using default route to transfer packet
Hence, the correct option is (c) if DIP of packet does not match with any of the
9. Which of the following transport layer protocol is entries of its routing table.
used to support electronic mail? [2012] Default route leading to infinite looping some-
(a) SMTP (b) IP times, hence TTL is used to avoid infinite looping.
(c) TCP (d) UDP Hence, the correct option is (c)
Solution: (c) 13. Packets of the same sessions may be routed
Hence, the correct option is (c) through different paths in: [2005]
(a) TCP but not UDP
(b) TCP and UDP
(c) UDP, but not TCP (a) It is possible for a computer to have multiple
(d) Neither TCP, nor UDP IP addresses.
Solution: (c) (b) IP packets from the same source to the same
destination can take different routes in the
Therefore packets of the same sessions may be routed
network.
through different paths in UDP, bot not TCP because
(c) IP ensures that a packet is discarded if it is
packets are flowing through different paths based on
unable to reach its destination within a given
availability of paths and also UDP is connectionless.
number of hops.
Hence, the correct option is (c) (d) The packet source cannot set the route of an
14. The Aaddress ReSolution Protocol(ARP) is used outgoing packets; the route is determined only
for: [2005] by the routing tables in the routers on the way.
(a) Finding the IP address from the DNS Solution: (d)
(b) Finding the IP address of default gateway
Types of routing
(c) Finding the IP address that corresponds to a
MAC address • Router routing: Router decides outgoing route of
(d) Finding the MAC address that corresponds to the packet.
an IP address • Source mounting: Source can decide the route.
Solution: (d) Hence, the correct option is (d)
Hence, the correct option is (d) 18. Which of the following functionalities must be
15. An organization has a class B network and wishes implemented by a transport protocol over and
to form subnets for 64 departments. The subnet above the network protocol? [2003]
mask would be:[2005] (a) Recovery from packet losses
(a) 255.255.0.0 (b) 255.255.64.0 (b) Detection of duplicate packets
(c) 255.255.128.0 (d) 255.255.252.0 (c) Packet delivery in the correct order
(d) End to end connectivity
Solution: (d)
Solution: (c)
We need to borrow 6-bits to generate 64 subnet
from Host ID. TCP and UDP both are transport layer protocols.
Detection of duplicate packets and end-to-end
Hence mark is: 255.255.255.0
connectivity are responsibilities of TCP. Packet
Hence, the correct option is (d) delivery in connect order is must for both TCP and
16. Which of the following is NOT true with respect to UDP.
a transparent bridge and a router? [2004] Hence, the correct option is (c)
(a) Both bridge and router selectively forward
19. Which of the following system calls results in
data packets.
sending of SYN packets? [2008]
(b) A bridge uses IP addresses while a router uses
(a) Socket (b) Bind
MAC addresses.
(c) Listen (d) Connect
(c) A bridge builds up its routing table by inspect-
ing incoming packets. Solution: (d)
(d) A router can connect between a LAN and a The active endpoint sends a synchronize packet
WAN. when connect() system call is invoked.
Solution: (b) Hence, the correct option is (d)
Bridge works at data link layer, hence works on
MAC address. Router works at network layer, Two-marks Questions
hence uses IP address.
Hence, the correct option is (b) 1. An IP router with a Maximum Transmission Unit
17. Which of the following assertion is FALSE about (MTU) of 1500 bytes has received an IP packet
the Internet Protocol (IP)? [2003] of size 4404 bytes with an IP header of length
20 bytes. The values of the relevant fields in the Transmission time = L/B = 1100bytes/106
header of the third IP fragment generated by the There are 3 transmission time , total = 3300 micro
router for this packet are: [2014] sec.
(a) MF bit: 0, Datagram length: 1444; offset: 370
Case 2: L = 100 + 100 bytes.
(b) MF bit: 1, Datagram Length: 1424; offset: 185
(c) MF bit: 1, Datagram Length: 1500; offset: 370 Transmission source = 10 × 200/106 = 2000 micro
(b) MF bit: 1, Datagram Length: 1424; offset: 2960 second at R1, 200 microsecond, at R2, 200 micro
sec.
Solution: (a)
Case 3: L = 50 + 100 bytes.
Data + header size in datagram must be less
than or equal to MTU size. Three fragments Transmission Source = 20 × 150/106 = 3000 micro
1480, 1480, 1444 bytes with MF (1, 1, 0) offset second. At R1, 150 micro sec, at R2, 150 micro
(0, 1408/8 = 185), (1480 + 1480)/8 = 370. sec.
Hence, the correct option is (a) When file size is too big or too small, response
times are high due to retransmission and header
2. Let the size of congestion window of a TCP con-
overhead. Hence, T1 and T3 might be same as under
nection be 32 KB when a timeout occurs. The
these condition but definitely more than T2.
round trip time of the connection is 100msec and
the maximum segment size used is 2KB. The time Hence, the correct option is (d)
taken (in msec) by the TCP connection to get back 4. An IP machine Q has a path to another IP machine
to 32 KB congestion window is ___________. H via three IP routers R1, R2 & R3.
[2014] Q-R1-R2-R3-H
Solution: H acts an HTTP server, and Q connects to H via
Once timeout occurs, congestion window is set HTTP and downloads a file. Session layer encryp-
to one MSS and threshold value is set to half of tion is used, with DES as the shared key encryp-
the congestion window at timeout. Window now tion protocol. Consider the following four pieces
increase exponentially up to threshold value from of information.
there it increases linearly. [I1] The URL of the file downloaded by Q
So, overall it takes 1100 msec. [I2] The TCP port numbers at Q and H
3. Consider the store 7 forward packet switched net- [I3] the IP address of Q and H
work given below. Assume that the bandwidth of
[I4] The link layer addresses of Q and H
each link is 106 bytes/sec. A user on host A sends a
file size 103 bytes to host B through routers R1 and Which of I1, I2, I3 and I4 can an intruder learn
R2 in three different ways. In the first case, a single through sniffing at R2 alone? [2014]
packet containing the complete file is transmitted (a) Only I1 and I2
from A to B. In the second case, the file is split (b) Only I1
into 20 equal parts and these packets are sent from (c) Only I2 and I3
A to B. Each packet contains 100 bytes of header (d) Only I3 and I4
information along with use data. Consider only Solution: (c)
transmission time, ignoring processing, queuing Hence, the correct option is (c)
and propagation delays. Also assume that there are
5. An IP router implementing Classless Inter-Domain
no errors during transmission. Let T1, T2 and T3
Routing(CIDR) receives with a packet address
be the times taken to transmit the file in the first,
131.23.151.76. The router’s routing table has the
second and third case, respectively. Which one of
following entries:
the following is correct? [2014]
(a) T1 < T2 < T3 (b) T1 > T2 > T3 Prefix Output interface identifier
(c) T2 = T3, T3 < T1 (d) T1 = T3, T3 > T2 131.16.0.0/12 3
Solution: (d) 131.28.0.0/14 5
Case 1: L = 1000 + 100 bytes. 131.19.0.0/16 2
m3: Checking email in a web browser. (c) A single HTTP request from Q to S is suffi-
What is the application level protocol used in each cient and a single TCP connection between Q
activity? [2011] and S is necessary for this.
(a) m1: HTTP m2: SMTP m3: POP (d) A single HTTP request from Q to S is suffi-
(b) m1: SMTP m2: FTP m3: HTTP cient and this is possible without any TCP con-
(c) m1: SMTP m2: POP m3: HTTP nection between Q and S.
(d) m1: POP m2: SMTP m3: IMAP Solution: (b)
Solution: (c) Embedded image in HTML page need require a
For transferring mail SMTP is used, and POP/ separate TCP connection but require as there is no
IMAP is used to display mail we use HTTP. caching.
Hence, the correct option is (c) Hence, the correct option is (b)
5. Which of the following uses UDP as the transport 2. Consider a source computer (S) transmitting file
protocol? [2007] of size 106 bits to destination computer (D) over a
(a) HTTP (b) Telnet network of two routers (R1 and R2) and three links
(c) DNS (d) SMTP (L1, L2, L3). L1 connects to R1; L2 connects to R1
to R2; L3 connects to D. Let each link be of length
Solution: (c)
100 meter. Assume signals travel over each link at
Hence, the correct option is (c) a speed of 108 meters per second. Assume the link
6. In the following pairs of OSI protocol layer/sub bandwidth on each link is 1Mbps. The file is bro-
layer and its functionality, the incorrect pair is ken down into 1000 packets each of size 1000-bits.
[2007] Find the total sum of transmission and propagation
(a) Network layer and routing delays in transmitting the file from S to D?[2012]
(b) Data link layer and bit-wise synchronization (a) 1005 ms (b) 1010 ms
(c) Transport layer and end-to-end protocol com- (c) 3000 ms (d) 3003 ms
munication Solution: (a)
(d) Medium access control sub-layer and channel
At source(S), it takes 1 sec(L/B) to transfer all
sharing
1000 packets. At 1.001 sec (D/V = 100 KM/108)
Solution: (b) last packet will be arriving at router 1(R1), at R1
Data link layer has error, flow, access control, transmission delay for this at last packet is 0.001
framing as functionalities. Bit synchronization is sec (L/B = 1000bits/1Mbps), propagation from R1
part of physical layer. to R2 is 0.001 sec, transmission delay at R2 is 0.001
Hence, the correct option is (b) sec propagation from R2 to destination D is 0.001
sec hence it takes 1.005 sec or 1005 msec.
Hence, the correct option is (a)
Two-marks Questions
Common Data for Questions 3 and 4
1. A graphical HTML browser resident at a network Consider a network with five nodes, N1 to N5 as
client machine Q accesses a static HTML web- shown below.
page from a page has exactly one static embedded
N1
image which is also at S. Assuming no caching,
which one of the following is correct about the 1
HTML webpage loading(including the embedded 3
N5 N2
image)? [2014]
(a) Q needs to send at least 2 HTTP requests to S,
each necessarily in a separate TCP connection 4 6
to server S.
N4 2 N3
(b) Q needs to send at least 2 HTTP requests to S but
a single TCP connection to server S is sufficient.
The network uses a distance vector routing proto- Common Data for Questions 5 and 6
col. Once the router have stabilized, distance vec- Consider a network with 6 routers R1 to R6 con-
tor at different nodes are following: nected with links having weights as shown in the
N1: (0, 1, 7, 8, 4) following diagram:
N2: (1, 0, 6, 7, 3) R2 7 R4
N3: (7, 6, 0, 2, 6) 8
6
N4: (8, 7, 2, 0, 4)
R1 2 1 R6
N5: (4, 3, 6, 4, 0)
Each distance vector is distance of the known path 4
at that instance to nodes, N1 to N5, where the dis- R3 9 R5
tance to itself is 0. Also links are symmetric and
cost is identical in both directions. In each round [2010]
all number exchange their distance vectors with 5. All the routers use the distance vector-based rout-
the respective neighbors. Then all nodes update ing algorithm to update their routing table initial-
their distance vector. In between two routes, any ized to contain an entry for each neighbor with the
change in cost of a link will cause the incident weight of the respective connecting link. After all
nodes to change only that entry their distance vec- the routing tables stabilizes, how many links in the
tors. [2011] network will never be used for carrying any data?
3. The cost of link N2-N3 reduces to 2( in both direc- (a) 4 (b) 3
tions). After the next round of update, what will be (c) 2 (d) 1
new distance vector of node N3? Solution: (c)
(a) (3, 2, 0, 2, 5) (b) (3, 2, 0, 2, 6) R1--- → R2(6) will never be used as we have R1--
(c) (7, 2, 0, 2, 5) (d) (7, 2, 0, 2, 6) → R3(3) and R3- → R2(2).
Solution: (a) Similarly, R4----- → R6 will never be used as we
N3→N1→3,N3→N2→2,N3→N3→0,N3→N4→2, have R4-- → R5(1) and R5- → R6(3)
N3 → N5 → 5 ( Via N2) OR, R1-- → R5(2) and R4-- → R6(2).
Hence, the correct option is (a) Hence, the correct option is (c)
4. After the update in previous question, link N1-N2 6. Suppose the weights of all unused links in the pre-
goes down. N2 will reflect change immediately vious question are changed to 2 and the distance
in its distance vector cost, ∞. After the NEXT vector algorithm is used again until all routing
ROUND of update, what will be the cost to N1 in tables stabilize. How many links will now remain
the distance vector of N3? unused?
(a) 3 (b) 9 (a) 0 (b) 1
(c) 10 (d) ∞ (c) 2 (d) 3
Solution: (c) Solution: (a)
Alternative route is N3 → N4 → N5 → N2 → N1, The number of links that will remain unused will
so its value is 2 + 4 + 3 + 1 = 10. be 0 because when we make changes to R1 to R2
NEXT ROUND' of update means ‘∞’ at N2 will be and R4 to R6, we will use all the links.
received ball N5 but not ball N3. Hence, N3 still Hence, the correct option is (a)
assume N3 → N4 → N5 → N2 is all alternative
route to N1. 7. A computer on a 10 Mbps network is regulated
by a token bucket. The token bucket is filled at
Hence, the correct option is (c) a rate of 2Mbps. It is initially filled to capacity
with 16 megabits. What is the maximum duration
for which the computer can transmit at the full
10Mbps? [2008]
Process Management- I 0 1 0 1 0 1 2 0 2 3 0 3 3 0 4 3 1 2 1 2 3 2 2 1 4 2 1 4
Process Management- II 2 0 2 1 1 1 1 1 1 3 1 3 1 2 4 3 2 0 0 2 1 1 1 2 0 1 4 0
Deadlocks 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 2
Memory Management 0 0 1 5 4 2 3 2 7 3 3 4 2 1 4 4 4 4 1 1 3 1 5 1 0 1 0 4
File System & Device 1 0 1 3 0 0 2 0 1 1 4 3 2 0 3 1 1 1 2 0 1 2 1 0 1 2 0 3
Management
11/19/2015 6:53:59 PM
Chapter 1
Process Management-I
Solution: (b)
One-mark Questions
Once every process got scheduled one time each
1. Which one of the following is FALSE? [2014] (for T times unit), all process now have the same
(a) User-level threads are not scheduled by the waiting time = (n - 1) T where n = # process.
kernel. Till now, the scheduling was round robin with pre-
(b) When a user-level thread is blocked, all other emption at periods of T. The same analysis can be
threads of its process are blocked. extended for further scheduling as all the process
(c) Context switching between user-level thread is have the same priority = (n - 1)T.
faster than context switching between kernel- Hance the correct option is (b)
level threads. 3. A process executes the code
(d) Kernel level threads cannot share the code
segment. fork ();
Solution: (d) fork ();
We know that kernel level threads can share the fork ();
code segment therefore option (d) is false. The total number of child processes created[2012]
Hance the correct option is (d) (a) 3 (b) 4
(c) 7 (d) 8
2. A scheduling algorithm assigns priority propor-
tional to the waiting time of a process. Every pro- Solution: (c)
cess starts with priority zero (the lowest priority). The number of child process with n - fork() is 2n - 1.
The scheduler re-evaluates the process priorities Hance the correct option is (c)
every T time units and decides the next process to 4. A computer handles several interrupts sources of
schedule. Which one of the following is TRUE if which the following are relevant for this question
the processes have no I/O operations and all arrive [2011]
at time zero? [2013] • Interrupt from CPU temperature sensor (raises
(a) This algorithm is equivalent to the first come interrupts if CPU temperature is too high)
first serve algorithm. • Interrupt from mouse (raises interrupt if the
(b) This algorithm is equivalent to round robin mouse is moved for a button pressed)
algorithm. • Interrupts from keyboard (raises interrupts
(c) This algorithm is equivalent to the SJF when a key is pressed or released)
algorithm. • Interrupt from hard disk (raises interrupt when
(d) This algorithm is equivalent to the a disk is completed)
shortest-remaining-job-first algorithm.
Which one of the following will be handled at the (a) I only (b) I and II only
HIGHEST priority? (c) II and III only (d) I, II and III only
(a) Interrupt from hard disk Solution: (d)
(b) Interrupt from mouse All statements are true.
(c) Interrupts from keyboard Hance the correct option is (d)
(d) Interrupt from CPU temperature sensor
8. A CPU generally handles an interrupt by execut-
Solution: (d) ing an interrupt service routine [2009]
Real time application. (a) as soon as an interrupt is raised.
Hance the correct option is (d) (b) by checking the interrupt register at the end of
fetch cycles.
5. Let the time taken to switch between user and ker-
(c) by checking the interrupt register after finish-
nel modes of execution be t1 while time to switch
ing the execution of the current instruction.
between two processes be t2 . Which of the follow-
(d) by checking the interrupt register at fixed time
ing is TRUE? [2011]
interval.
(a) t1 > t2
(b) t1 = t2 Solution: (c)
(c) t1 < t2 Hance the correct option is (c)
(d) Nothing can be said about the relation between 9. Group-I contains some CPU scheduling algo-
t1 and t2 rithms and Group-II contains some applications.
Solution: (c) Match entries in Group-I to entries in Group-II.
Since process switching involves mode switching [2007]
process, switching time is time consuming than Group I Group II
mode switching. (P) Gang scheduling (1) Guaranteed scheduling
Hance the correct option is (c) (Q) Rate monotonic scheduling (2) R e a l - t i m e
scheduling
6. A thread is usually defined as a 'light-weight pro-
(R) Fair share scheduling (3) Thread scheduling
cess' because an Operating System (OS) maintains
(a) P – 3 Q – 2 R – 1 (b) P – 1 Q – 2 R – 3
smaller data structure for a thread than for a pro-
(c) P – 2 Q – 3 R – 1 (d) P – 1 Q – 3 R – 2
cess. In relation to this, which of the following
TRUE [2011] Solution (a)
(a) On per-thread basis, the OS maintains only • Gang scheduling is scheduling algorithm for
CPU register state. parallel system that schedules related threads.
(b) The OS does not maintain virtual a separates • Fair share scheduling ensures that no process
stack for each thread. starve indefinitely for resources.
(c) On per-thread basis, the OS does not maintains • Rate monotonic scheduling used in real time
virtual memory state. OS with a static-priority scheduling class.
(d) On per-thread basis, the OS maintains only Hance the correct option is (a)
scheduling and accounting information. 9. Consider the following statements about user-level
Solution: (a) threads.
Each thread is maintained by its own stack, CPU Which of the following statement is FALSE? [2007]
registers. (a) Context switching time is longer for kernel-level
Hance the correct option is (a) threads than for user-level threads.
(b) User-level threads do not need any hardware
7. Which of the following statements are TRUE?
support.
I. Shortest remaining time first scheduling may
(c) Related-kernel level threads can be scheduled
cause starvation.
on different processors in a multi-processor
II. Preemptive scheduling may cause starvation .
system.
III. Round robin is better than FCFS in terms of
(d) Blocking one kernel-level thread blocks all
response time. [2010]
related threads.
(a) Shortest job first (b) Round robin Process Arrival time Burst time
(c) First come first serve (d) Elevator P1 0 12
Solution (b) P2 2 4
Round Robin pre-emptive scheduler and designed P3 3 6
especially for time sharing systems. In RR, a pro-
P4 8 5
cess is allotted a time slot (called time slice) and if
the process does not finish, process will 'get back Solution: (5.5)
in line' and another process will receive the time
The process gets scheduled in the order <p1; p2;
slot.
p3; p4; p1> generating a schedule length of 27,
Hance the correct option is (b) and hence average waiting time of 22/4 = 5.5
3. Consider the following set of processes that need
Two-marks Questions to be scheduled on a single CPU. All the times are
given in millisecond. [2014]
1. Three processes A, B and C each execute a loop of Process Arrival time Burst time
100 iterations . In each iteration of the loop, a pro-
A 0 6
cess performs a single computation that requires
B 3 2
tc CPU millisecond and then initiates a single I/O
operation that lasts for tio millisecond. It is assumed C 5 4
that the computer where the processes execute has D 7 6
sufficient number of I/O devices and the OS of E 10 3
the computer assigns different I/O devices to each
process. Also the scheduling overhead of the OS is Using the shortest remaining time first scheduling
negligible. The processes have the following char- algorithm, the average process turnaround time (in
acteristics: [2014] MS) is ___________
Solution: ( 7.2)
Process ID tc tio
Processes are scheduled in the order <A; B; A; C;
A 100ms 500ms E; D> at times 0, 3, 5, 8, 12, 15, 21; giving an aver-
B 350ms 500ms age turnaround time of 7.2.
C 200 ms 500ms 4. Consider the 3 processes, P1, P2 and P3 shown in
the table
The processes A, B and C are started at times 0,
Process Arrival time Time unit required
5 and 10 millisecond, respectively in a pure time-
sharing system (round robin scheduling) that uses P1 0 5
a time slice of 50 millisecond; the time in millisec- P2 1 7
ond at which process C would complete its first I/O P3 3 4
operation is _________
Solution: (1000) The completion order of the 3 processes under the
policies FCFS and RRS (round robin scheduling
By gantt chart with CPU quantum of 2 time units) are
First process A initiates IO operation at time 200 [2012]
and then process C initiates IO at times 500 and (a) FCFS: P1, P2, P3 RR2: P1, P2, P3
completing the same at time 1000. (b) FCFS: P1, P3, P2 RR2: P1, P3, P2
2. An operating system uses the shortest remaining (c) FCFS: P1, P2, P3 RR2: P1, P3, P2
time first scheduling of processes. Consider the (d) FCFS: P1, P3, P2 RR2: P1, P2, P3
following set of processes with their arrival times Solution: (c)
and CPU burst time (in millisecond): [2014]
Hance the correct option is (c)
P1 10 2 7 1
Gantt Chart
P2 20 4 14 2 P1 P2 P4 P3 P1
0 1 4 5 8 12
P3 30 6 21 3
(C) ExitX(R, S) {(D) ExitX(R, S) { Z reads x from memory, decrements by two, stores
P(S); V(R); it to memory, and then terminates. Each process
V(R); P(S); before reading x invokes the P operation (i.e.,
wait) on a counting semaphore S and invokes the
} } V operation (i.e., signal) on the semaphore S after
EntryY(R, S) {EntryY(R, S) { storing x to memory. Semaphore S is initialized
V(S); V(S); to two. What is the maximum possible value of x
P(R); P(R); after all processes complete execution? [2013]
(a) –2 (b) –1
} } (c) 1 (d) 2
Solution: (c) Solution: (d)
(a) WRONG. Suppose process x executes ExitX,
then it will wait for R, and then process y ex- W and X reads x from memory, incre-
ecutes EntryY, then it will wait for s. Since ment x by 1, Y and Z reads x, dec-
initially both binary semaphores are ‘0’ no one rement x by 2.
will increment it and both the processes will perform P(S), then S=1,
stuck in deadlock. x=0 x=x+1=1
(b) WRONG. Here if the process executes for n Then Y will perform P(S) then S=0,
times repeatedly, it will set both semaphore to
‘1’.(since only two values are possible) and af- x=0 x=x-2= -2, then store x.
ter that process y executes . First time, it passes V(S) , S=1.
the EntryYy and makes both semaphores to Then Z will perform P(S) then S=0,
‘0’. And on second time, it finds both sema- read x=-2 x=x-2= -4 , then store
phores to ‘0’ and cannot pass the EntryY bar- V(S), S=1
rier. Hence, it will stuck. Then x will store x , V(S) , S=2,X=1
(c) CORRECT. Here take any sequence of opera-
tion of process x and process y. First x will Then W will perform P(S), S=1,
wait for s which is incremented by process y read
and then y waits for R which is incremented by x=1 x=x+1= 2, store x, V(S), S=2,
process x. x=2.
There is no sequence of operation in which the Hence, the correct option is (d).
value R or S overlaps. 3. Fetch_And_Add (X, i) is an atomic Read-Modify-
Hence, both processes execute one after an- Write instruction that reads the value of memory
other. location X, increments it by the value i, and returns
(d) WRONG. Suppose first process x ex- the old value of X. It is used in the pseudocode
ecutes. It sets R = 1 and then waits for shown below to implement a busy-wait lock. L is
s. Now after that process y executes. an unsigned integer shared variable initialized to 0.
It first sets S = 1 and then decrement The value of 0 corresponds to lock being available,
R = 0. It comes again and again sets s = 1(i.e., while any non-zero value corresponds to the lock
it overlaps the value of s) and then wait for R. being not available. [2012]
Clearly, we lost one iteration of s, and after (n
- 1) iteration processes well stuck. AcquireLock(L){
Hence, the correct option is (c). while (Fetch_And_Add(L,1))
2. A shared variable x, initialized to zero, is operated L = 1;
on by four concurrent processes W, X, Y, Z as fol- }
lows. Each of the processes W and X reads x from ReleaseLock(L){
memory, increments by one, stores it to memory, L = 0;
and then terminates. Each of the processes Y and
}
void P (binary_semaphore *s) { (d) V(S) at W,V(T) at X, P(S) at Y, P(T) at Z,S and
unsigned y; T initially 0
unsigned *x = &(s->value); Solution: (b)
do { By applying definitions of down and up opera-
fetch-and-set x, y; tions, taking value of 1 & 0 respectively.
} while (y); Hence, the correct option is (b).
}
12. Which of the following will ensure that the output
void V (binary_semaphore *s) {
string never contains a substring of form 01n0 or
S->value = 0; 10n1 where n is odd?
} (a) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z,S
Which one of the following is TRUE? and T initially 1
(a) The implementation may not work if context (b) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z,S
switching is disabled in P. and T initially 1
(b) Instead of using fetch-and-set, a pair of normal (c) P(S) at W, V(S) at X, P(S) at Y, V(S) at Z,S
load/store can be used. and T initially 1
(c) The implementation of V is wrong. (d) V(S) at W, V(T) at X, P(S) at Y, P(T) at Z,S
(d) The code does not implement a binary sema- and T initially 1
phore. Solution: (c)
Solution: (a) By applying definitions of down and up opera-
With the value 1 of semaphore and disabling con- tions, taking value of 1 and 0 respectively.
text switching, it will go in infinite loop. Hence, the correct option is (c).
Common Data Questions 11 and 12 13. Consider Peterson’s algorithm for mutual exclu-
Suppose we want to synchronize two concurrent sion between two concurrent processes I and j. The
processes P and Q using binary semaphores S and program executed by process-I is shown below.
T. The code for processes P and Q is shown below. [2001]
[2003] Repeat
Process P: Process Q: Flag[i] =true;
While(1) While(1) Turn=j;
W: Y: while (P) do no-op;
Print ‘0’; Print ‘1’; Enter critical section perform actions,
Print ‘0’ Print ‘1’; Then exit critical section
X: Z: Flag[i]=false;
} } Perform other non-critical section actions
Synchronization statements can be inserted only at Until false;
points W, X, Y and Z.
For the program to guarantee mutual exclusion,
Hence, the correct option is (a). the predicate P in the while loop should be:
11. Which of the following will always lead to an out- (a) Flag[j]=true and tun=i
put staring with 001100110011? (b) Flag[j]=true and tun=j
(a) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z,S (c) Flag[i]=true and tun=j
and T initially 1 (d) Flag[j]=true and tun=i
(b) P(S) at W, V(T) at X, P(T) at Y, V(S) at 1 and Solution: (b)
T initially 0
If a process gets pre-empted before updation, it
(c) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z,S
will raise the problem of synchronization.
and T initially 1
Hence, the correct option is (b).
18. Semaphore operations are atomic because they are (b) A program segment that has not been proved
implemented within the OS……. [1990] bug-free.
Solution: (kernel) (c) A program segment that often causes unex-
pected system crashes.
Semaphore operations are atomic, and hence must
(d) A program segment where shared resources
be implementable by kernel.
are accessed.
19. A critical region is: [1987]
Solution: (d)
(a) One which is enclosed by a pair of P and V
operations on semaphores. Hence, the correct option is (d).
Five-marks Questions (iii) If the process gets pre-empted after A1, then
mutual exclusion is not ensured. The Solutio-
nution degenerates to lock variable which do
1. The functionality of atomic test-and-set assembly
not guarantee mutual inclusion.
language instruction is given by the following C
function. 2. The following Solutionution to the single producer
single consumer problem uses semaphores for
int TEST-AND-SET (in *x)
synchronization. #define BUFFERSIZE 100
{
buffer buf[BUFFSIZE];
int y; int first =last=0;
A1: y=*x; Semaphore b_full=0;
A2: *x=1; semaphore b_empty=BUFFSIZE;
A3: return y; void producer()
} {
(i) Complete the following C functions for imple- While(1)
menting code for entering and leaving critical c1………. ;
sections based on the above test-and-set in-
take the item from buf[last];
struction.
last=(last+1)%BUFFSIZE;
int mutex=0;
c2: ……… ;
void enter-cs(0
consume the item;
{
}
while(…….); }
} (a) Complete the dotted part of the above Solutio-
void leave-cs() nution.
{ (b) Using another semaphore variable, insert on
line statement each immediately after p1, im-
…………… mediately before p2, immediately after c1,
} and immediately before c2 so that the program
(ii) Is the above solution to the critical section works correctly foe multiple producers and
problem deadlock-free and starvation-free? consumers. [2002]
(iii) For the above situation, shown with example Solution:
states that mutual exclusion is not ensured if
test-and-set instruction is not atomic. [2002] Producer_item(item p)
Solution: Put the item into buf(empty)
(i) void enter-cs(0 Put the item into buf(first)
{ First=(first+1) % BUFFERSIZE
while(TEST-And-SET (mutex)); put the item into buf(mutex)
} put the items into buf(full)
void leave-cs() }
{ }
mutex= ϕ; (b) void consumer (void)
} {
(ii) Solutionution is deadlock free, but not starva- int item; out=0;
tion free. while (1)
{
Solution: S5 i:=i+1
S1
S6 next: Write a(i)
(b) Can this graph be converted to a concurrent
program using parbegin-parend. Construct
S3 only? [1994]
S2
Solution:
(a)
S6 S1
S4 S5 S8
S7
S2
S9
S1 S4 S6
S5
S2 S3
Solution: S1
parbegin
begin S1; v(a); v(b);v(c); v(d);
end;
S2 S3
begin p(a); S2; v(c); end
begin p(b); S3; v(f); end
begin p(c); p(f);p(g); S5; end
parend
8. (a)
Draw a precedence graph for the following
sequential code. The statements are numbered S54 S5
from S1 to S0.
S1 read n
S2 i:=1
S3 if i>n goto next S6
S4 a(i):=i+1
Solution: Solution:
parbegin (a) No, it does not guarantee mutual exclusion.
(b) Yes, it is possible that a waiting process can
begin S1;v(a); v(b); end;
never enter critical section.
begin p(a); S2;v(c); v(e);end;
11. A system of four concurrent processes P, Q, R,
begin p(b); S3; v(d); end; S use shared resources A, B, C. The sequence in
begin p(c) ; S4;v(v);end; which processes P ,Q, R, S request and release the
begin p(d);p(e);S5; v(g); end; resources are as follows:
begin p(f); p(g); S6;end; Process P:
1. P requests A
parend
2. P requests B
10. Consider the following scheme for implementing 3. P requests A
a critical section in a situation with three processes 4. P requests B
Pi, Pj, Pk.
Process Q:
Pi: 1. Q requests C
repeat 2. Q requests A
flag[i]:=true; 3. Q requests C
4. Q requests A
While flag[j] or flag[k] do
Process R:
Case turn of
1. R requests B
J: if flag [j] then 2. R requests C
begin 3. R requests B
flag[i]:=false; 4. R requests C
while turn ≠ i do skip; Process S:
1. S requests A
flag[i]:=true
2. S requests C
end; 3. S requests A
k: if flag[k] then 4. S requests C
begin If a resource is free, it is granted to a requesting
flag[i]:=false; process immediately. There is no pre-emption of
granted resources. A resource is taken back from a
while turn ≠ i do skip;
process only when the process explicitly release it.
flag[i]:= true [1989]
end (i) Can the system of four processes get into
critical section deadlock? If yes, give a sequence of opera-
tions (for requesting and releasing resources)
if turn=I then turn:=j;
of these processes which lead to a deadlock.
flag[i]:=false; (ii) Will the processes always get into a deadlock?
non-critical section If your Solution is no, give a sequence of these
until false; operations which leads to completion of all
(a) Does the scheme ensure mutual exclusion in processes.
the critical section? Briefly explain. (iii) What strategies can be used to prevent dead-
(b) Is there a situation in which a waiting process lock in a system of concurrent processes us-
can never enter the critical section? ing shard resources if pre-emption of granted
resources is not allowed?
If so, explain and suggest modification to the code
to Solutionve this problem. [1991]
Solution: P4
i. Yes, all 4 processes can get involved in dead- L4 : join C3;
lock; see what happens if every process gets
P6;
pre-empted after 1st instruction.
ii. No, first complete P, then Q, followed by R and 13. Consider the following proposal to the 'readers and
lastly S in that sequence without pre-emption. writers problems shared variables and semaphores:
iii. Synchronization mechanism like semaphores aw,ar,rw,rr : integer ;
can be used to prevent Deadlocks among con- mutex, reading writing : semaphore:
current processes.
Initial values of variables and
12. Consider the following precedence graph of pro- states of semaphores:
cesses where node denotes a processes and a
Ar=rr=aw=rw=0
directed edges from node Pi to node Pj implies that
Pi must complete before Pj commences. Implement Reading-value=writing- value=0
the graph using FORK & JOIN constructs. The Mutex-value=1.
actual computation done by a process may be indi- Process writer;
cated by a comment line. [1989]
Begin
P1
While true do
Begin
P(mutex);
Aw:=aw+1;
P2 P4 Grantwrite
V(mutex);
P(writing);
P3 Write;
P(mutex);
Rw:=rw-1;
Aw:=aw-1:
P5 P6
Grantread;
V(mutex);
Solution: Other work
C1=2; C2=2; C3=2; End
P1; End
fork L1; Process reader;
P2; Begin
fork L2 Repeat
L3; jin C2; P(mutex);
P5; Ar:=ar+1;
goto L4; Grantread;
L1: fork L2 V(mutex);
P3 P(reading);
goto L3; Read;
L2 : join C1; P(mutex);
rr:=rr-1; If rr=0
ar:=ar-1; Then while (rw<aw) do
grantwrite; Begin rw:=rw+1;
V(mutex) V(writing)
Other-work; End
Until false End;
End. (a) Give the value of shared variables and the
states of semaphore when 12 readers are read-
Procedure grantread:
ing and 31 writers are writing.
Begin (b) Can a group of readers make waiting writers
If aw=0 starve? Can writers starve readers?
Then while (rr<ar) do (c) Explain in two sentence why the Solutionution
is incorrect. [1987]
Begin rr:=rr+1;
Solution:
V(reading)
(a) ar=12; aw=31 ; reading =0 mutex=1
End rr=0; rw= ϕ; writing =ϕ;
End; (b) YES.
Procedure grantwrite; (c) In the precedence grant write, the condition
if (rr=ϕ) is incorrect. It should be if (ar=ϕ)
Begin
}
One-mark Question
}
1. A computer system has 6 tape drives, with n pro- void consumer ()
cess competing for them. Each process may need {
two tape drives. The maximum value of n for while(true)
which the system is deadlock free? [1998]
{ semWait(s);
(a) 6 (b) 5
(c) 4 (d) 3 semWait(n);
Solution: (b) removeFromBuffer():
If there are 5 processes, then at least 1 process will semSignal(s);
get 2 tape drives out of 6 tape drives. Hence, the consume();
system is deadlock free. }
Hance the correct option is (b) }
Which of the following is TRUE? [2014]
Two-marks Questions (a) The producer will be able to add an item to the
buffer, but the consumer can never consume it.
1. Consider the procedure below for the producer- (b) The consumer will remove no more than one
consumer problem which uses semaphores: item from buffer.
(c) Deadlock occurs if the consumer succeeds
Semaphores n=0;
in acquiring semaphores s when the buffer is
Semaphores n=1; empty.
Void producer () (d) The starting value for the semaphore n must be
{ 1 and not 0 for deadlock free operation.
while(true) Solution: (c)
{ producer(); In this scenario, consumer locks the semaphores s
and then gets blocked on empty buffer; thereafter
SemWait(s);
producer also gets blocked while performing down
addToBuffer(); operation on s.
semSignal(s); Hance the correct option is (c)
semSignal(n);
2. An operating system uses the banker’s algorithm the cylinder number of the last sector of the file, if
for deadlock avoidance when managing the allo- it is stored in a contiguous manner? [2013]
cation of three resources types X,Y and Z to (a) 1281 (b) 1282
the three processes P0, P1, P2. The table given (c) 1283 (d) 1284
below presents the currents system state. Here, Solution: (d)
the allocation matrix shows the current number of
File occupies (42797*1024)/512 sectors = 85594
resources of each type allocated to each process
sectors starting sector number < 1200,9,40>
and the Max matrix shows the maximum number
of resources of each type required by each process = 1200*64*16 + 9*64 + 40
during execution. = 1229416
Allocation Max
Last sector number = 1220416 + 85594 = 13.1
X Y Z X Y Z 5010 = x
P0 0 0 1 8 4 3 Number of sectors/cylinder = 16*64 = 210 = 1024 = y
P1 3 2 0 6 2 0 Cylinder number = x/y
P2 2 1 1 3 3 3 1315010/1024 = 1284.
Hance the correct option is (d)
There are 3 units of type X, 2 units of type Y and 4. A system has n resource es R0,…Rn-1 and k pro-
2 units of type Z still available. The system is cur- cesses P0,….Pk-1. The implementation of the
rently in a safe state. Consider the following inde- resources request logic of each process Pi, is as
pendent request for additional resources in the follows:
current state:
If ( i%2==0){
REQ1: P0 requests 0 unit of X, 0 units of Y and 2
If (i<n) request Ri;
units of Z
If (i+2<n) request R i+2;
REQ2: P1 requests 2 units of X, 0 units of Y and 0
units of Z }
Which of the following is TRUE? [2014] Else{
(a) Only REQ1 can be permitted. If (i<n) request Rn-1;
(b) Only REQ2 can be permitted. If (i+2<n) request Rn-1-2;
(c) Both REQ1 and REQ2 can be permitted.
}
(d) Neither REQ1 nor REQ2 can be permitted.
In which one of the following situations is a dead-
Solution: (b)
lock possible? [2010]
Running the Resource-Request Algorithm, it (a) n = 40, k = 26
is observed that after satisfying the request (b) n = 21, k = 12
of P0, System goes into Unsafe State; On the (c) n = 20,k = 10
contrary satisfying the request of P1, transits (d) n = 41, k = 19
the system to safe state, and hence the request is
Solution: (a)
granted.
Hance the correct option is (a)
Hance the correct option is (b)
5. Consider a system with four types of resources
3. Consider a hard disk with 16 recording surfaces
R1 (3 units), R2 (2 units), R3 (3 units), R4 (2 Units),
(0 – 15) having 16384 cylinders (0 – 16384) and
R3 (3 units), R4 (2 units). A non-pre-emptive resource
each cylinder contains 64 sectors (0 – 63). Data
allocation policy is used .At any given instance, a
storage capacity in each sector is 512 bytes. Data
request is not entertained if it cannot be completely
are organized cylinder-wise and addressing format
satisfied. Three processes P1, P2 and P3 request as
is <cylinder no., surface no., sector no.>. A file of
follows if executed independently.
size 42797 KB is stored in the disk and the starting
disk location of the file is <1200, 9, 40>. What is
Process P1: Process P2: Process P3: 7. A single processor system has three resources types
t = 0 reqiests t = 0: reqiests t = 0: reqiests X, Y and Z which are shared by three processes.
2 units of R2 2 units of R3 1 units of R4 There are 5 units of each resource type. Consider
t = 1: requests t = 2: requests t = 2: requests
the following scenarios, where the column alloc
1 unit of R3 1 unit of R4 2 unit of R1
t = 3: request 2 t = 4: request 1 t = 5: request denotes the number of units of each resource type
units of R1 units of R1 2 units of R1 allocated to each process, and the column request
t = 5: request 1 t = 6: request 1 t = 7: requests denotes the number of units of each resource type
units of R2 units of R3 1 unit of R2
requested by a process in order to complete execu-
and 1 unit of R1 t = 8: Finishes t = 8: requests
t = 7: request 1 1 units of R3 tion. Which of the following processes will finish
units of R3 t = 9: Finishes LAST ? [2007]
t = 8: request
2 units of R4 Alloc Request
t = 10:
X Y Z X Y Z
Finishes
P0 1 2 1 1 0 3
‘p’ and ‘q’ process can complete, upon which they 11. An operating system contains 3 users per pro-
would release their resources Xp xp , Xq xq there- cesses each requiring 2 units of resources R. The
fore, if xp + xq ≥ max k ≠ p, q yk. minimum number of units of R is such that no
This would guarantee that one out of blocked pro- deadlock will ever arrive [1997]
cesses can come out of cycle. (a) 3 (b) 5
(c) 4 (d) 6
Hance the correct option is (b)
Solution: (c)
9. Suppose n processes, P1………Pn share m iden-
tical resources unit which can be reserved and As there are 3 processes and 4 resources, then at
released at a time. The maximum resource require- least 1 process will get two resources. Therefore
ment of process Pi is Si where S i< 0. Which one of Deadlock will not occur.
the following is a sufficient condition for ensuring Hance the correct option is (c)
that deadlock does not occur? [2005]
12. Consider a system having m resources of the same
(a) ∀I, si < m (b) ∀I, sin < n
type. These resources are shared by 3 processes A,
(c) Σsi (m + n) (d) Σsi < (m + n)
B and C, which have peak demands of 3, 4 and 6,
Solution: (c) respectively. For what value of m deadlock will not
For deadlock to occur, occur?[1993]
m ≤ ∑in=1Si - n (a) 7 (b) 9
(c) 10 (d) 13
for no deadlock
Solution: (d)
m ≤ ∑in=1Si - n
If there are 13 resources, then deadlock will not
(m + n) ≥ ∑in=1Si
occur as the maximum demand is also 13.
Hance the correct option is (c)
Hance the correct option is (d)
10. Which of the following is NOT a valid deadlock
13. A computer system has 6 tape drives, with n pro-
prevention scheme? [2000]
cess competing for them. Each process may need
(a) Release all resources before requesting a new
two tape drives. The maximum value of n for
resource.
which the system is guaranteed to be deadlock
(b) Number the resources uniquely and never
free? [1992]
request a lower-numbered resource than the
(a) 2 (b) 13
last one requested.
(c) 4 (d) 1
(c) Never request a resource after releasing any
resource. Solution: (a)
(d) Request and be allocated all required If there are 2 processes, then each process will hold
resources before execution. 3 tape drives as there are 6 tape drives for which
Solution: (c) the system is guaranteed to be deadlock free.
Hance the correct option is (c) Hance the correct option is (a)
P1 1 5 1
P2 1 2 3
Current Allocation
R0 R1 R2 P 1 P
0 P2 P
1
P0 1 0 2
P1 0 3 1 3r
P2 1 0 2
(a) First if the system is in deadlock state.
Available R0 R1
(b) Otherwise, find a safe sequence.
R2
Solution:
2 2 0
(a) No; the system is not in deadlock.
(a) Show that the system can be in this state.
(b) Applying deadlock detection algorithm with
(b) What will system do on a request by process
multiple instances of a resource type, you get
P0 for one unit of resource type R1?
the safe sequence. Derive the matrices alloca-
tion, request, available from the graph.
15. In a resident OS computer, which of the following (a) 256 × 16 (b) 64K × 8
system software must reside in the main memory (c) 4K × 16 (d) 64K × 16
under all situations? [1998] Solution: (d)
(a) Assembler (b) Linker
The size of ROM required is 64K × 16.
(c) Loader (d) Compiler
Hence, the correct option is (d).
Solution: (c)
A loader is used to load the program and data on to 20. The principal of locality justifies the use of [1995]
memory and will reside in main memory. (a) Interrupts (b) DMA
(c) Polling (d) Cache memory
Hence, the correct option is (c).
Solution: (d)
16. Locality of reference implies that the page refer-
ence being made by a process [1997] Hence, the correct option is (d).
(a) will always be to the page used in previous 21. In a paged segmented scheme of memory manage-
page reference. ment, the segment table itself must have a page
(b) is likely to be to one of the pages used in last table because: [1995]
few pages reference. (a) The segment table is often too large to fit in
(c) will always be to one of the pages existing in one page
memory. (b) Each segment is spread over number of pages.
(d) will always lead to page fault. (c) Segment tables point to page table and not to
Solution: (b) the physical locations of the segment.
(d) The processor’s description base register
Localty of reference also known as the principal of
points to a page table.
locality is the phenomena of the same value storage
location being related storage location frequency. Solution: (a)
Segment table must be paged in order to be accom-
Hence, the correct option is (b).
modates in one page.
17. Thrashing [1997] Hence, the correct option is (a).
(a) Reduces page I/O
(b) Decrease the degree of multiprogramming 22. A linker is given object modules for a set of
(c) Implies excessive page I/O programs that were compiled separately. What
(d) Improve the system performance information need to be included in an object
module? [1995]
Solution: (c) (a) Object code
In thrasing, paging activity is more as compared to (b) Relocation bit
execution. (c) Names and locations of all external symbols
Hence, the correct option is (c). defined in the object module
18. Dirty bit for page in a page table [1997] (d) Absolute addresses of internal symbols
(a) helps avoid unnecessary writes on paging de- Solution: (d)
vice. Hence, the correct option is (d).
(b) helps maintain LRU information. 23. Which page replacement policy sometimes
(c) allows only read on a page. leads to more page fault when size of memory is
(d) None of the above increased? [1992]
Solution: (a) (a) Optimal (b) LPU
Dirty bit indicates whether page is clean or (c) FIFO (d) None of these
modified. Solution: (c)
Hence, the correct option is (a). Belady’s anamaly: When we increase the number
19. A ROM is used to store the table for multiplication of page frames while using FIFO page replace-
of two 8 bits unsigned integers. The size of ROM ment algorithm, the number of page fault will also
required is [1996] increase.
Hence, the correct option is (c).
EMAT = 0.96 [1ns + 0.9 (1ns) + 0.1 (1ns + 10ns)] 17. Consider a machine with 64MB physical memory
+ 0.04 [1ns + 10ns + 10ns + 0.9 (1ns) + 0.1 (1ns + and a 32 – bit virtual address space. What is the
10ns)] approximate size of the page table? [2001]
Hence, the correct option is (d). (a) 16 MB (b) 8 MB
(c) 2 MB (d) 24 MB
14. Suppose a process has only the following pages
in its virtual address space: two contiguous code Solution: (c)
pages starting at virtual address 0x00000000, two Hence, the correct option is (c).
contiguous data pages starting at virtual address 18. Suppose the time to service a page fault is on the
0x00400000 and a stack page starting at virtual average 10 milliseconds, while a memory access
address 0xFFFFF000. The amount of memory takes 1 microsecond. Then the 99.99% hit ratio
required for storing the page tables of this process results in average memory access of time. [2000]
is (a) 1,9999 ms (b) 1 ms
(a) 8 KB (b) 12 KB (c) 9999 ms (d) 1,9999 ms
(c) 16 KB (d) 20 KB
Solution: (d)
Solution: (c)
By using formula EMAT = P × S + (1 – p) m
First level page table size = 4KB in the second
Where P is the page fault rate and S is the page
level, we require 3 pages of the inner page table.
fault service line m is main memory access time.
One for the code, another for data and last one for
stack. Sizes of each page is 4KB; outer page table Hence, the correct option is (d).
is also 4\KB. 19. Which of the following is/are advantages of virtual
Hence, the correct option is (c). memory? [1999]
(a) Faster access to memory on an average.
15. Which of the following is not an advantage of
(b) Processes can be given protected address
using statically linked libraries as opposed to using
space.
statically linked libraries? [2003]
(c) Linker can assign addresses independent of
(a) Smaller size of executable files.
where the program will be loaded in physical
(b) Lesser overall page fault rate in the system.
memory.
(c) Faster program startup.
(d) Programs larger than the physical memory
(d) Existing programs need not be re – linked to
size can be run.
take advantage of newer versions of libraries.
Solution: (b and d)
Solution: (b)
Hence, the correct option is (a and d).
Page fault rate may increase due to dynamic
locality 20. The overlay tree for a program is shown below:
[1998]
Hence, the correct option is (b).
Root 2KB
16. Dynamic linking can cause security concerns
because [2002]
(a) security is dynamic.
(b) the path for searching dynamic libraries is not A 4KB B 6KB C 8KB
known till runtime.
(c) linking is insecure.
(d) cryptographic procedures are not available for D 6KB E F G 4KB
8KB
dynamic linking.
Solution: (b) What will be the size of the partition (in physical
Linking is done at runtime. memory) required to load (and run) this program?
Hence, the correct option is (b).
The sequence of requests for blocks of size 300, (c) the available main memory.
25, 12550 can be satisfied if we use: (d) All of the above.
(a) Either first fit or best fit Solution: (b)
(b) First fit but not best fit policy
Virtual memory is implemented on secondary
(c) Best fit but first fit policy
storage.
(d) None of the above
Hence, the correct option is (b).
Solution: (b)
32. The 'link editor' is a program that: [1991]
Using first fit, all the requests will be satisfied. But
(a) Matches the parameters of micro definition
best fit will not satisfy the last request as the mem-
with locations of parameters of the micro call.
ory is not contagious. The optimal page replace-
(b) Matches external names of one of the program
ment algorithm will select the page that will not be
with their location in other programs.
used for the longest time in future.
(c) Matches the parameters of subroutine defi-
Hence, the correct option is (b). nition with locations of parameters of the
28. A Simple two pass assembler does the following in subroutine call.
the first pass: [1993] (d) Acts as link between text editor and the user.
(a) It allocates space for the literals. (e) Acts as link between compiler and user program.
(b) It computes the total length of the program. Solution: (b)
(c) It builds the symbol table for the symbol and
Hence, the correct option is (b).
their value.
(d) It generates code for all the load and store reg- 33. Indicate all the FALSE statement from the state-
ister instruction. ments given below. [1991]
(a) The amount of virtual memory available is
Solution: (c)
limited by the availability of secondary storage
Hence, the correct option is (c). (b) Any implementation of a critical section
29. A part of the system software, which under all requires the use of an indivisible machine –
circumstances, must reside in the main memory is instruction such as test and set.
[1993] (c) The use of monitors ensures that no deadlock
(a) Text editor (b) Assembler will be caused.
(c) Linker (d) Loader (d) The LRU page – replacement policy may
Solution:(d) cause thrashing for some type of programs.
(e) The best fit techniques for memory allocation
Loader is frequently required system software.
ensures the memory will never be fragmented.
Hence, the correct option is (d).
Solution:
30. Match the pairs in the following question [1991]
(a): True
GROUP–I
(b): False
(A) Buddy system (B) Interpretation
(C) Pointer type (D) Virtual memory (c): True
GROUP–II (d): True
(p) Run – time type specification (e): False
(q) Segmentation 34. State whether the following statements are TRUE/
(r) Memory allocation FALSE with reason. [1990]
(s) Garbage collection
Transferring data in blocks from the main memory
Solution: (A – r, B – p, C – s, D – q) unit to the cache memory enables an inter – leaved
31. The total size of address space in a virtual memory main memory unit to operate units at its maximum.
system is limited by [1991] Solution: (TRUE)
(a) the length of MMR.
(b) the available secondary storage .
35. State whether the following statements are TRUE/ 38. Match the following. [1990]
FALSE with reason. [1990] GROUP – I
The link load and go loading scheme requires less (a) critical region (b) Wait/signal
storage space than the link – and – go loading (c) Working set (d) Deadlock
scheme. GROUP – II
Solution: ( TRUE) (p) Hoare monitor (q) Mutual exclusion
36. In a two level virtual memory. The memory (r) Principle of locality (s) Circular wait
access time for main memory tA1 = 10 – 8 sec, and Solution: (a – q, b – p, c – r, d – s)
the memory access time for secondary memory,
tag = 10 – 8. What must be the hit ratio H, such that 39. Match the following. [1989]
the access efficiency is within 80 percent of its GROUP – I
maximum value? [1990] (a) Virtual memory
Solution: (b) Shared memory
Hit ratio must be less than or equal to 80% in order (c) Look ahead buffer
to ensure that the access efficiency is within 80% (d) Look aside buffer
of its maximium value. GROUP – II
37. Under paged memory management scheme, simple (p) Temporal locality
lock and key memory protection arrangement may (q) Spatial locality
still be required if the ……………… processors do (r) Address translation
not have address mapping hardware. [1990] (s) Mutual exclusion
Solution: ( input/output) Solution: (a – q, b – s , c – p, d – r)
Control Page
bit Frame Solution:
in Physical address in
memory main memory Minimum page size = 128 bytes.
Let page size = 2k Bytes
(b) 210 = 1K Page table size = 213 = ( 213 – k) x2 bytes = 214 – k
f X bytes.
by given condition 214 – k = 2k, k = 7
20 12 x = 12 bits
and page size = 27 = 128 bytes.
32 bits (b) Please refer the cache organization in the com-
puter architecture course.
Hence, the correct option is (a) (c) 7 1 3 1 x
F V/I PPv D Age
17 1 63 J3 300 J2 350k
→
J2 J3 300k
LRU page
For each hexadecimal address in the address J5 150k J5 150k
sequence given below, 00FF, 010D, 10FF, 11B0
Indicate, J6 has to wait.
i) The new status of the list With first fit, it is possible to satisfy all the requests.
ii) Page faults, if any, and 6. The following page addresses, in the given
iii) Page replacements, if any sequence, were generated by a program: [1993]
Solution: 12341352154323
i) New status of pages in memory
This program is run on a demand paged virtual
memory system, with main memory size equal
to 4 pages. Indicate the page reference for which
Five-marks Questions (b) Consider an initial set of 100 library disk re-
quests and assume that no new disk requests
arrive while servicing these requests. If the
1. Consider a disk with following specification:
head is initially at track 0 and the elevator al-
20 surfaces, 1000 tracks/surface, 16 sectors/track,
gorithm is used to schedule disk requests, what
data density 1KB/sector, rotation speed 3000rpm.
is the worst case time to complete all the re-
The operating system initiates the transfer between
quests?
the disk and the memory sector-wise. Once the
head has been placed on the right track, the disk Solution:
reads a sector in a single scan. It reads bits from (a) 34ms; (100 - 25) = (100 - 5) = 170 secs.
bits from the sector while the head is passing over ST = 170 × 0.2 = 34ms
the sector. The read bits are formed into bytes in (b) Time for worst case request = 100 × 0.2ms =
a serial = in parallel-out buffer and each byte is 20ms
then transferred to memory. The disk writing is Time for one request = S.T + L.T + T.T
exactly a complementary process. For part (c) and
= 20 + 10 + 0.2 ms = 30.2 ms
(d) below, assume memory read - write time = 0.1
microsecond /byte, interrupt driven transfer has an Time for all 100 requests
interrupt overhead - 0.4 micro-second, the DMA = 100 × 30.2 ms
initialization and termination overhead is negli- = 3020ms = 3.02 seconds.
gible compared to the total sector transfer time.
3. A file system with a one-level directory structure
DMA requests are always granted. [2001]
is implemented on a disk with disk block size of
(a) What is the total capacity of the disk?
4KB. The disk is used as follows: [1996]
(b) What is data transfer rate?
(c) What is the percentage of time the CPU is re- Disk-block 0: File allocation , consisting of one 8
quired for this disk I/O for byte - wise inter- bit entry per date block the data block address of
rupt driven transfer? the next data block in the file:
(d) What is the maximum percentage of time the Disk block 1: Directory, with on 32 bit entry per
CPU is held up for this disk I/O for cycle - file:
stealing DMA transfer? Disk block 2: Data block 1;
Solution: Disk block 3: Data block 2; etc
Disk capacity : 20 × 1000 × 16 × 1Kb ~ 500MB (a) What is the maximum possible number of
Trash = 16 KB; rpm = 3000; D.T.R. = 800KB/S files?
(b) What is the maximum possible file size in
Almost 25% the total time CPU spend on transfer
blocks?
is 0.5 µs for total time of 13µs.
Solution:
Almost 5.4% time for reading one sector is 1250µs
time to copy the section to memory is 100µs. No. of files = 4KB/4B = 1K
2. Consider a disk with the 100 tracks numbered As there must be one directory entry per file,
from 0 to 99 rotating at 3000rpm. The number number of files
of sectors per track is 100. The time to move the = Directory size/Directory entry size
head between two successive tracks is 0.2 mil-
= 4KB/ 32B = 1024
liseconds. [2001]
(a) Consider a set of disk requests to read data (b) Maximum possible = 28 – 2 = 254 block file
from tracks 32, 7, 45, 5 and 10. Assuming that size
the elevator algorithm is used to schedule disk A single file can occupy at most as many data
requests and the head is initially at track 25 blocks as can be addressed by 8 bit FAT entries.
moving upn (towards large track numbers). Number of distinct FAT entry representative
What is the total seek time for servicing the = 28 = 256.
requests?
1 Mark Questions 0 0 0 0 0 0 0 0 3 1 2 2 5 1 3 2 7 4 1 7 3 2 6 1 2 2 4 9
2 Marks Questions 4 0 0 3 4 5 1 4 0 6 1 0 1 3 2 2 4 7 6 8 7 12 5 3 4 2 3 8
5 Marks Questions 0 0 3 0 1 1 2 2 1 3 2 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
Greedy Method 0 0 1 0 2 1 0 1 1 2 1 0 0 1 1 0 3 1 0 3 3 1 2 3 2 1 0 2
Dynamic Programming 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 3 2 0 2 0 0 1
P and NP Concepts 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 2 0 1 1 0 0 0 1 6
Miscellaneous Topics 0 0 0 2 1 2 2 2 0 3 2 1 3 1 3 0 3 2 2 7 4 3 3 0 1 0 0 0
11/19/2015 10:48:44 AM
Chapter 1
algorithm analysis and
asymptotic notations
One-mark QuestiOns
1. Which one of the following is the tightest upper Solution: (c)
bound that represents the number of swaps Time complexity of Bellman-Ford algorithm on a
required to sort n numbers using selection sort? graph with n vertices and m edges is O(nm).
[2013] For a complete graph, m − nc = O( n2 ). As there is
2
(a) O(log n) (b) O(n) an edge between all pair of vertices. Hence, Time
(c) O(n log n) (d) O(n2) complexity = O(n2.n) = O(n3)
Solution: (b) Hence, the correct option is (c).
n − 1 passes are required for selection sort, and 4. The worst case running time to search for an
in each pass there is one swap so the number of element in a balanced binary search tree with n2n
swaps (passes) = O (n) elements is [2012]
Hence, the correct option is (b).
(a) Θ(n log n) (b) Θ(n2 )n
2. Which one of the following is the tightest upper (c) Θ(n) (d) Θ(log n)
bound that represents the time complexity of
Solution: (c)
inserting an object into a binary search tree of n
nodes? [2013] log2 (n 2n) = log2 n + log2 (2n)
(a) O(1) (b) O(log n) = log2 n + n
(c) O(n) (d) O(n log n) = q (n)
Solution: (c) Hence, the correct option is (c).
To insert an element we compare all elements, 5. Let W(n) and A(n) denote respectively, the worst
so O(n). case and average case running time of an algo-
Hence, the correct option is (b). rithm executed on an input of size n. Which of the
3. What is the time complexity of Bellman-Ford following is ALWAYS TRUE? [2012]
single-source shortest path algorithm on a com- (a) A(n) = Ω (W(n))
plete graph of n vertices? [2013] (b) A(n) = O(W(n))
(a) Θ(n2) (b) Θ(n2log n) (c) A(n) = Θ(W(n))
(c) Θ(n3) (d) Θ(n3log n) (d) A(n) = 0(W(n))
12. In the worst case, the number of comparisons 16. Which of the following is false? [1996]
needed to search a singly linked list of length n for
n log n
a given element is [2002] (a) 100 n log n = O
n 100
(a) log n (b)
2 (b) √log n = O (log n)
(c) log2 n − 1 (d) n (c) If 0 < x < y then nx = O (ny)
(d) 2n ≠ O (nk)
Solution: (d)
Linked list can always use linear search and hence Solution: (b)
O(n). (a) 100 n log n = O(nlogn)
In the worst case, the comparison is done between
n log n
the element to be searched and all elements of = O ( 100 is constant)
linked list. 100
Hence, the correct option is (d).
log n = log1/ 2 n → (True)
13. Let f(n) = n2 log n and g(n) = n(log n)10 be two posi-
tive functions of n. Which of the following state- 1
= log n
ments is correct? [2001] 2
(a) f (n) = O(g(n) and g(n) ≠ O( f(n)) = O (log n)
(b) g(n) = O(f (n) and f (n) ≠ O(g(n)) Which is not O(logn)
(c) f (n) ≠ O(g(n)) and g(n) ≠ O( f(n)) (b) 0 <¢x < y
(d) f (n) ≠ O(g(n)) and g(n) ≠ O( f(n)) Let x = 3, y = 5
Solution: (b) n3 = 0 (n5)
The term n log n is common between f (n) and g(n) lower = O (higher)
is; therefore the term n of f (n) and (log n)9 of g(n) (c) 2n ≠ 0 (nk)
are compared; it is true asymptotically that (log n)9 Here, 2n is higher growth rate function there nk
is O(n); therefore g(n) is O( f(n)) Hence True.
Hence, the correct option is (b). Hence, the correct option is (b).
14. The maximum gate delay for any output to appear
in an array multiplier for multiplying two n bit twO-marks QuestiOns
number is [1999]
(a) O(n2) (b) O(n) 1. The number of elements that can be sorted in
(c) O(log n) (d) O(l) Θ(log n) time using heap sort is [2013]
Solution: (a)
Multiplying two n-bit binary no’s of size ‘n’ and ‘m’
(a) Θ(1) (b) Θ ( logn )
is O(nm). log n
(c) Θ (d) Θ(log n)
Hence, the correct option is (a). log log n
15. The concatenation of two lists is to be performed
on 0(1) time. Which of the following implementa- Solution: (c)
tions of a list should be used? [1997] Suppose the number of element is ‘K’. They can be
(a) Singly linked list sorted in Θ(k log k) time.
(b) Doubly linked list By trying the options in decreasing order of com-
(c) Circular doubly linked list plexity as we need a tight band i.e. Θ
(d) Array implementation of list
Solution: (c)
log n
i.e Θ(log n), Θ
log log n
,Θ ( )
log n , Θ (1)
While all other types of linked lists need to reach
till end to attach the second list but the traversal for So if K ∈Θ(log n) time required for heap
concatenation is not done by circular linked lists. sort is. Θ (k log k) i.e. Θ (log n × log log n), But this
Hence, the correct option is (c). is not in Θ (log n).
Time required for heap sort Which of the following statements about the as-
ymptotic behaviour of f(n), g(n), and h(n) is true?
log n [2008]
if k ∈ Θ
log log n (a) f (n) = O(g(n)); g(n) = O(h(n))
(b) f (n) = Ω(g(n)); f(n) = O(h(n))
log n log n (c) g(n) = Ω(f (n)); h(n) = O( f (n))
Θ × log
log log n log log n (d) h(n) = O(f (n)); g(n) = Ω(f (n))
Solution: (d)
log n f (n) = 2n
log
log log n f (n) = O(2n)
i.e Θ log n × , g (n) = n! − g(n) = O(n!)
log log n
h (n) = nlogn − h(n) = O(nlogn)
nlogn < cn < n!
nlogn < c2n < n!
log n h(n) = O( f(n), g(n) = Ωf(n)
log Hence, the correct option is (d).
log log n ≤ 1
log log n 4. The minimum number of comparisons required
to determine if an integer appears more than n/2
times in a sorted array of n integers is [2008]
So, this is in Θ(logn) (a) Θ(n) 1 (b) Θ(log* n)
Hence, the correct option is (c). (c) Θ(log n) (d) Θ(l)
2. Which of the given options provides the increasing Solution: (a)
order of asymptotic complexity of functions fi, f2, By initializing the counter to zero and checking
f3 and f4? linearly in a loop.
n Hence, the correct option is (a).
f1(n) = 2
5. You are given the post order traversal, P, of a
f2(n) = n3/2
binary search tree on the n element, 1, 2,…,n. You
f 3 ( n) = n log n2 have to determine the unique binary search tree
f4(n) = nlog2n [2011] that has P as its post order traversal. What is the
time complexity of the most efficient algorithm for
(a) f3, f2, f4, f1 doing this? [2008]
(b) f2, f3, f1, f4 (a) Θ(logn)
(c) f2, f3, f1, f4 (b) Θ(n)
(d) f2, f3, f4, f1 (c) Θ(n log n)
Solution: (a) (d) None of the above, as the tree cannot be uniquely
With n = 1024 the values of given functions are f1 determined
(1024) = 21024, f2 (1024) = 10243/2, f3(1024) = 1024 Solution: (c)
log1024 , f4(1024) Unique tree can be constructed with in order along
2
1024
with either pre-order or post-order traversal. Since
= 1024 log2 = (1024)10 we know in order and post order of BST, so tree
nlog2n < n3/2 < nlog2 n < 2n can be constructed using O (nlogn) time.
f3 (n) < f2(n) < f4 (n) < f1(n) Hence, the correct option is (c).
Hence, the correct option is (a). 6. Consider the following C functions:
3. Consider the following functions:
F(n) = 2n
G(n) = n! = = = =
H(n) = nlogn
1. X [i ] Y [i ] Z [i ]
= = = =
2. X [2] + Z [0] Y [2] = 2 × [2] Z [2] = 3 × 2
=4 =6
+ 3. X [3] = Y [2] + 2[1] Y [3] = 2 × [3] Z [3] = 3×7
=4+3 = 2 × (7) = 21
=7 = 14
4. X [4] = Y [3] + Z [2] Y [4] = 2 × [4] Z [4] = 3 × 20
= 14 + 6 = 2 × [20] = 60
= 20 = 40
= = = 5. X [5] = Y [4] + Z [3] Y [5] = 2 × [61] Z [5] = 3 × 61
= = = = 40 + 21 = 61 = 122 = 183
= <= ++ 6. X [6] = Y [5] + 2[4] Y [6] = 2 × 182 Z[6] = 3 × 182
= + = 122 + 60 = 364 = 546
= 7. X [7] − Y [6] + Z [5] Y [7] = 2 × 547 Z [7] = 3 × 547
= = 364 + 183 = 547 = 1094 = 1641
8. X [8] = Y [7] + Z [6] Y [8] = 2 × 1640 Z [8] = 3 × 1640
= 1094 + 546 = 3280 = 4920
= 1640
f1(8) and f2(8) return the values Hence, the correct option is (b).
3 2 1
= <= ++
root
= = 10
Level order
Heap after traversal:
inserting 1 10873215
8 7
3 2 1 5
Let T(n) denote the number of times the for loop is
executed by the program on input n. Which of the
Hence, the correct option is (d).
following is TRUE? [2007]
(a) T(n) = O (√n) and T(n) = Ω(√n) 11. Consider the following C-function:
(b) T(n) = O(√n) and T(n) = Ω(1)
(c) T(n) = O(n) and T(n) = Ω(√n)
(d) None of the above
= = Solution: (b)
An array of size ‘n’ is required to store temporary
= results. So solution is O(n).
= < ++ Hence, the correct option is (b).
+ =
13. What does the following algorithm approximate?
> ∈ >
=
The space complexity of the above function is: =
∈ > ∈
[2005]
(a) O(1) (b) O(n) (c) O(n!) (d) O(nn) = +
=
Solution: (b)
[2004]
(a) log m (b) m2
(c) m1/2 (d) m1/3
= Solution: (c)
The loop will fail for x − y ≤ y
So x ≤ y
=
= < ++ m m
x≤ ∵ y =
= + x x
x2 ≤ m
x ≤ m1/2
Hence, the correct option is (c).
The maximum size of recursion stack space is ‘n’
14. Let A[1,...,n] be an array storing a bit (1 or 0) at
Hence, the correct option is (b).
each location, and f (m) is a function whose time
12. Consider the following C-function: complexity is 0(m). Consider the following pro-
gram fragment written in a C like language: coun-
ter = 0;
= < = ++
= = = = ++
= =
= < ++
+ =
The complexity of this program fragment is
[2004]
(a) Ω (n2)
(b) Ω(nlogn) and O(n2)
Suppose we modify the above function foo( ) and
(c) q (n)
store the values of foo(i), 0 ≤ i ≤ n, as and when
(d) O(n)
they are computed. With this modification, the
time complexity for function foo( ) is significantly Solution: (c)
reduced. The space complexity of the modified In all cases, when A[i] = l for all
function would be: [2005] i = l, n
A[i] = 0; for all i = l, n
(a) O(l) (b) O(n) (c) O(n2) (d) O(nn) A[i] = l; for i = l, n/2
n A0 = A1 − l = l − 1 = −2
= 0; for i =+ 1,… n an = 2n+1 − n − 2
2
The order of magnitude is O(n) c·2 − 2 − 1 = 1 ⇒ 2c = 4 ∴ c = 2
Hence, the correct option is (c). Hence, the correct option is (c).
15. The time complexity of the following C-function 17. The cube root of a natural number n is defined as
is (assume n > 0) the largest natural number m such that m3 ≤ n. The
complexity of computing the cube root of n (n is
= = represented in binary notation) is [2003]
(a) O(n) but not O(n0 5)
(b) O(n0 5) but not O((log n)k) for any constant k > 0
+ (c) O((log n)k) for some constant k > 0, but not
O((log n)m) for any constant m > 0
(d) O((log n)k) for some constant k >0 5, but not
[2004] O((log n)0.5)
(a) O(n) (b) O(nlog n)
Solution: (c)
(c) O(n2) (d) O(2n)
18. Consider the following algorithm for searching for
Solution: (d)
a given number x in an unsorted array A[1…n].
The recurrence for the given problem is
having n distinct values:
T(n) = l, n = l
= 2T(n − 1) +1 1. Choose an i uniformly at random from l…n;
According to back-substitution, it is O(2n) 2. If A[i] = x then Stop else Goto 1;
Hence, the correct option is (d). Assuming that x is present A, what is the expected
16. The recurrence equation number of comparisons made by the algorithm be-
T(l) = l fore it terminates? [2002]
T(n) = 2T(n − l) +n, n>2 (a) n (b) n − l
Evaluates to [2004] n
(c) 2n (d)
(a) 2n+1 − n − l 2
Solution: (a)
(b) 2n − n The maximum number of comparisons can be ‘n’.
(c) 2n+1 − 2n − 2 Hence, the correct option is (a).
(d) 2n + n
19. The running time of the following algorithm
Solution: (c) Procedure A(n)
According to back-substitution. If n <=2 return (1) else return
T(n) = 2T(n − l) + n, n > 2, T(l) = 1
2
A1 = , 3A0 = l, A0 = 13
3
( A ( n )) ;
n = 1 A0 + A1 = 1 ⇒ A0 + A1 = 1 Is best described by [2002]
n = 0 − [2A0 (−l) + A1] = 0 (a) O(n) (b) O(log n)
(c) O(log n) (d) O(l)
2A0 − A1 =0
an − 2an− l = n Solution: (c)
(A0 + A1 n) − 2 [A0 +A1 (n − 1)] = n T(n) = l, n ≤ 2
n = l ⇒ A0 + A1 − 2A0 = l T(n) = T ( n ) + K, n > 2
n = 0 ⇒ A0 − 2A0 − 2A1 (−l) = 0 k
n2 = 2
A1 − A0 = l − A1 + A0 = −l
−A0 + 2 + 1 = 0 2−K = logn 2
2A1 − A0 = 0 2K = log2 n ⇒ K = log2 n
A1 = −l Hence, the correct option is (c).
g ( n) = 2 n log 2 n
∑ 1≤ k ≤ n
o( n) = O( n)∑ 1≤ k ≤ n i = O( n2 )
h(n) = n!
Hence, the correct option is (b).
Which of the following is true? [2000]
23. Express T(n) in terms of harmonic number
(a) h(n) is O( f(n)) n
(b) h(n) is O(g(n)) HHnn = ∑ 1 / i, n ≥ 1, where T(n) satisfies the recur-
(c) g(n) is not O( f(n)) t =1
(d) f(n) is O(g(n)) rence relation,
Solution: (d) n +1
T ( n) = T ( n − 1) + 1, for n ≥ 2 and T(l) =1
n = 256, f(n) = 3 × 2128 2
What is the asymptotic behaviour of T(n) as a
g(n) = 216 × 23 = 219 h(n) = 256!
function of n? [1990]
∴ g(n) < f(n) < h(n)
n +1
Hence, the correct option is (d). T ( n) = T ( n − 1) + 1 (1)
n
21. Consider the following two functions:
Back-substitution method can be used to find the
n for 0 ≤ n < 10, 000
3 values of T(n − 1), T(n − 2) using equation (1) and
g1 ( n) = 2 , eliminate the recurrence using T(l) = 1. The R.H.S
n for n ≥ 10, 000 of the recurrence will be in the harmonic series
n
1
n for 0 ≤ n < 100 form, ∑ ,(i + 1) + n
g 2 ( n) = 3 i =1 i
n for n ≥ 100
Which of the following is true: [1994] 24. Solve the recurrence equations [1987]
T(n) = T(n − 1) + n
(a) g1 (n) is O(g2 (n)) T(l) = 1
(b) g1 (n) is O(n3) T(n) = O(n2)
(c) g2 (n) is O(g1 (n)) T(n) = n + (n − l) + (n − 2) +…+ T(1)
(d) g2 (n) is O(n)
n( n + 1)
Solution: (a) =
2
g1(n) is O(g2(n)) whenever n > 100
(or)
Hence, the correct option is (a).
T(n) − T (n − 1) = n, T(1) = 1
22. ∑ O(n), where O(n) stands for order n is: T(n) − T(1) = 2 + 3 + …n
1≤ k ≤ n
[1993] n( n + 1)
T ( n) = 1 + 2 + 3 + … + n =
(a) O(n) (b) O(n2) 2
(c) O(m3) (d) O(3n2)
25. What is the generating function G(z) for the
Solution: (b) sequence of Fibonacci numbers? [1987]
It is like a nesting of loop as given The recurrence of Fibonacci numbers is
for k ← 1 to n
Fn = Fn − 1 + Fn − 2
for i ← 1 to n
S; 5 + 1 1+ 5 5 −1 1 − 5
For each value of ‘K’, ‘S’ executed ‘n’ times, so Fn = +
total time is O(n2) 2 5 2 2 5 2
Five-marks Question
1. Consider the following algorithms. Assume, pro-
1
cedure A and procedure B take O (1) and O unit
n
of time respectively. Derive the time complexity of Solution:
the algorithm in O - notation. [1999] Let T(n) denote the timing complexity of proce-
dure what (n); T(n) = 1 n = 1
= T(n − 1) + 1 + 1
n
Expanding it using back substitution
− T(n) = O(n)
One-mark QuestiOns
1. Let P be quicksort programme to sort numbers (a) Θ(n) (b) Θ(n log n)
in ascending order using the first element as the (c) Θ(n2) (d) Θ(log n)
pivot. Let t1 and t2 be the number of comparisons
Solution: (a)
made by P for the inputs [1 2 3 4 5] and [4 1 5 3 2]
respectively. Which one of the following holds? n
T(n) = 2T + log n
[2014] 2
(a) t1 = 5 By using Master Theorem, a = 2, b = 2, k = 0, p = l
(b) t1 < t2 As a > bk, so it is case (i) of Master Theorem
(c) t1 > t2 a
∴ T ( n) = q ( nlogb )
(d) t1 = t2
= q ( n)
Solution: (c)
Hence, the correct option is (a).
Case (i): If the array elements are in the increasing
order then the quick sort takes number of compari- 3. The minimum number of arithmetic operations
sons are required to evaluate the polynomial P(X) = X 5 +
4X3 + 6X + 5 for a given value of X, using only one
n( n − 1) temporary variable is ______. [2014]
t1 =
2
Solution: (7)
Case (ii): If the array elements are randomly dis- By using Divide and Conquer approach
tributed then the quick sort takes number of com- an = a if n = l
parison are = a . an−1 if n is odd
= (an/2)2 if n is even
t 2 = 2( n + 1)(log en + 0.577) − 4 n
∴ P(x) = x5 + 4x3 + 6x + 5
∴ t1 > t2 = x(x4) + 4(x)(x2) + 6(x) + 5
Hence, the correct option is (c). = x(x2)2 + 4 (x) (x) (x) + 6(x) + 5
2. Which one of the following correctly determines = x(x((x)))2 + 4(x(x(x))) + 6(x) + 5
the solution of the recurrence relation with T(1) = 1? Hence, total 7 multiplications are required.
[2014]
n 4. You have an array of n elements. Suppose you
T(n) = 2T + log n
2 implement quicksort by always choosing the
of n-elements. So, total time for n-elements is O(n (d) t(n) = ()n
2
10. A sorting technique is called stable if [1999] 14. Which of the following statements is true?
(a) it takes O(n log n) time I. As the number of entries in a hash table in-
(b) it maintains the relative order of occurrence of creases, the number of collisions increases.
non-distinct elements II. Recursive programmes are efficient
(c) it uses divide and conquer paradigm III. The worst case complexity for Quicksort is
(d) it takes O(n) space O(n2)
Solution: (b) IV. Binary search using a linear linked list is ef-
ficient [1995]
11. If one uses straight two-way merge sort algorithm
(a) I and II
to sort the following elements in ascending order:
(b) II and III
20, 47, 15, 8, 9, 4, 40, 30, 12, 17
(c) I and IV
Then the order of these elements after second pass
(d) I and III
of the algorithm is: [1999]
(a) 8, 9, 15, 20, 47, 4, 12, 17, 30, 40 Solution: (d)
(b) 8, 15, 20, 47, 4, 9, 30, 40, 12, 17
(c) 15, 20, 47, 4, 8, 9, 12, 30, 40, 17 twO-marks QuestiOns
(d) 4, 8, 9, 15, 20, 47, 12, 17, 30, 40
Solution: (b) 1. The minimum number of comparisons required to
[20] [47] [15] [8] [9] [4] [40] [30] [12] [17] find the minimum and the maximum of 100 num-
ber is [2014]
Solution: 148
Pass 1: [20 [47 [8 15] [4 9] [30 40] [12 17]
1.5 (100) − 2 = 148
2. Consider the following pseudo code. What is the
Pass 2: [8 15 20 47] [4 9 30 40] [12 17]
total number of multiplications to be performed?
Hence, the correct option is (b). [2014]
12. Merge sort uses [1995] D=2
(a) Divide and conquer strategy for i = 1 to n do
(b) Backtracking approach for j = i to n do
(c) Heuristic search for k = j + 1 to n do
(d) Greedy approach D=D*3
(a) Half of the product of the 3 consecutive inte-
Solution: (a) gers.
In merge sort algorithm, it uses divide and con- (b) One-third of the product of the 3 consecutive
quer strategy because for every iteration, array is integers.
divided into two equal parts. (c) One-sixth of the product of the 3 consecutive
Hence, the correct option is (a). integers.
13. For merging two sorted lists of sizes m and n into (d) None of the above.
a sorted list of size m + n, we require comparisons Solution:
of [1995] If we take n = 3 then the total number of multi-
(a) O(m) plications performed are 4 which is equivalent to
(b) O(n) One-sixth of the product of 3 consecutive integers,
(c) O(m + n) i.e. (2*3*4)/6.
(d) O(log m + log n)
3. Consider the following function:
Solution: (c)
The complexity depends on the number of com-
parisons involved in the merging process, which is
not more than (m + n).
Hence, the correct option is (c).
3n Solution: (b)
and the other with elements. Therefore di- Using Divide and conquer method not more than
4
vide and conquer recurrence in this case would be 3n
− 2 comparisons are required in all cases of
n 3n 2
T(n) = T + T + n
4 4 input.
By using variation of Mater-Theorem T(n) = T(αn) 10. Consider the following recurrence:
+ T(βn) + f(n) T ( n) = 2T (| n |) + 1T (1) = 1,
The recursion expression becomes:
n 3n Which one of the following is true? [2006]
T(n) = T + T + n. Solving the recursion
4 4 (a) T(n) = Θ(log log n)
using variant of master theorem, we get Θ (n logn). (b) T(n) = Θ(log n)
Hence, the correct option is (b). (c) T(n) = Θ.(n)
(d) T(n) = Θ(n)
8. Consider the quick sort algorithm. Suppose there
is a procedure for finding a pivot element which Solution: (a)
splits the list into two sub-lists each of which con- Applying master theorem, case-1 applies and hence
tains at least one-fifth of the elements. Let T(n) be it is Θ(log log n)
the number of comparisons required to sort n ele- (or)
ments. Then [2008] T(n) = 2T ( n) + l
n T(l) = l
(a) T(n) ≤ 2T + n By continuing, till Kth iteration, we get
5
1
n 4n
⇒ n 2 k = 2
(b) T(n) ≤ T + T + n
5 5
⇒ 2 − k = log n 2
4n
(c) T(n) ≤ 2T + n ⇒ K = log log 2 n
5
11. The median of n elements can be found in O(n)
n
(d) T(n) < 2T + n time. Which one of the following is correct about
2 the complexity of quick sort, which median is
Solution: (b) selected as pivot? [2006]
By applying divide and conquer concept one list (a) Θ(n)
1 (b) Θ(n log n)
would have elements and the other would have (c) Θ(n2)
5
4 (d) Θ(n3)
of the no. of elements ‘n’ comparisons are re-
5 Solution: (b)
quired for fixing up the pivot. Altering the pivot that is fixed at the correct place,
Hence, the correct option is (b). we get two sub-lists.
The number of steps required is log n and hence
9. An array of n numbers is given, where n is an even
the complexity becomes Θ(n log n). Pivot gets
number. The maximum as well as the minimum of
fixed at the middle which would split the list into
these n numbers needs to be determined. Which of n
the following is TRUE about the number of com- two parts each having elements.
2
parisons needed? [2007] Hence, the correct option is (b).
(a) At least 2n − c comparisons for some constant
c, are needed. n
12. Suppose T ( n) = 2T + n,
(b) At most 1.5n − 2 comparisons are needed. 2
(c) At least n log2 n comparisons are needed. T(0) = T(1)
(d) None of the above. Which one of the following is FALSE? [2005]
Solution: (a) case it has to be at the first position of the list (in
After comparing the key with the middle element, case the elements are in decreasing order).
the search is made either in the left or right sublist 19. Following algorithm (s) can be used to sort n inte-
n gers in the range [1…n3] in O(n) time?
with elements.
2 [1992]
n (a) Heap sort
∴ T(n) = T + K,
2 (b) Quick sort
(c) Merge sort
where ‘K’ is constant.
(d) Radix sort
Hence, the correct option is (a).
Solution:
17. Which one of the following statements is false? If we subtract each number by 1 then we get the
[1994] range [0, n3 −1]. Considering all number as 3-digit
(a) Optimal binary search tree construction can be base n: each digit ranges from 0 to n3 − 1. Sort-
performed efficiently using dynamic program- ing this using radix sort, it uses only three calls
ming. to counting sort. Finally, add 1 to all the numbers.
(b) Breadth-first search cannot be used to find Since there are 3 calls, the complexity is O(3n) ≈
connected components of a graph. O(n).
(c) Given the prefix and postfix walks over a bi-
20. Let P be a quicksort programme to sort numbers in
nary tree, the binary tree cannot be uniquely
ascending order. Let t1 and t2 be the time taken by
constructed.
the program for the inputs [1 2 3 4] and [5 4 3 2 1],
(d) Depth-first search can be used to find connect-
respectively. Which of the following holds?
ed components of a graph.
[1987]
Solution: (b) (a) t1 = t2
Breadth First Search [BFS] (b) t1 > t2
Breadth-first search (BFS) is an algorithm for tra- (c) t1 < t2
versing or searching tree or graph data structures. (d) t1 = t2 + 5 log 5
It starts at the tree root and explores the neighbour Solution: (a)
nodes first, before moving to the next level neigh- Quicksort behaves in worst case, for the sorted
bours. Initially, BFS starts at a given vertex, which list. Since both the list are already in order, it takes
is at level 0. In the first stage it visits all vertices at O(n2) as worst case.
level 1. In the second stage, it visits all vertices at Hence, the correct option is (a).
second level. These new vertices are the one which
21. Find a solution to the following recurrence equa-
are adjacent to level 1 vertices. BFS continues this
tion [1987]
process until all the levels of the graph are com-
pleted. n
Hence, the correct option is (b). T ( n) = T + n
2
18. Assume that the last element of the set is used as T(l) = l
partition element in quick sort. If n distinct ele- Solution:
ments from the set [1…n] are to be sorted, give an
input for which quick sort takes maximum time. n
T(n) = T + n, T(l) = l
[1992] 2
Solution: Master Theorem
Quick sort takes maximum time when the ele- a = l, b = 2, k = l, p = 0
ments are already in sorted order. So, when the Since a < bK, so it is 1 < 21 of master theorem
partition element is at the end, then in the worst Hence, T(n) = O(n)
Five-marks Questions
1. Give an optimal algorithm is pseudo-code for
sorting a sequence of n numbers which has only
k distinct numbers (k is not known a Priori. Give
a brief analysis for the time-complexity of your
algorithm). [1991] Total Complexity: O(k) + O(n) + O(k) + O(n) =
Solution: Counting Sort: O(n) if K = O(n). Space Complexity:
Counting sort is algorithm gives O(n) complexity O(n) if K = O(n).
for sorting. To achieve O(n) complexity, it assumes Note: Counting works well if K = O(n).
that each of the elements is an integer in the range Otherwise, the complexity will be more.
1 to k, for some integer k. When k = O(n), it runs in
O(n) time. The basic idea is to determine, for each 2. An input file has 10 records with keys as given
input elements X, the number of elements less than below:
X. This information can be used to place directly 25 7 342 70 9 61 16 49 19
into its correct position. For example, if there 10
elements less than X, then X belongs to position 11 This is to be sorted in non-decreasing order.
in output. (a) Sort the input file using QUICKSORT by
In the below code, A[0…n − 1] is the input array correctly positioning the first element of the
with length n. In counting sort we need two more file/sub file. Show the sub files obtained at
arrays: let us assume array B[0…n − 1] contains all intermediate steps. Use square brackets to
the sorted output and the array C[0…k − 1] pro- demarcate sub files.
vides temporary storage.
(b) Sort the input file using 2-way MERGESORT
showing all major intermediate steps. Use
square brackets to demarcate sub files.
[1989]
Solution: (a)
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10)
25 7 34 2 70 9 61 16 49 19
25 7 19 2 16 9 61 70 49 34
[2 7 9 16 19 25 34 49 61 [70]
one-mark QuesTions
1. Consider the DAG with Solution: (b)
V = {1, 2, 3, 4, 5, 6}, shown below. When vi is connected to vi + 1, the edge cost is 2.
there will be (n − 1) such edges with a cost of ‘2’.
2 5
Therefore total cost = 2(n − l) = 2n − 2
(or)
1 4
n n
∑2J
i =1
i − J i − 1 = 2∑ 1 = 2 n − 1 = 2 n − 2
i =1
(1)
3 6
4 Hence, the correct option is (b).
Which of the following is NOT a topological or- 3. To implement Dijkstra’s shortest path algorithm on
dering? [2009] weighted graphs so that it runs in linear time, the
(a) 1 2 3 4 5 6 data structure to be used is: [2006]
(b) 1 3 2 4 5 6
(a) Queue
(c) 1 3 2 4 6 5
(b) Stack
(d) 3 2 4 1 6 5
(c) Heap
Solution: (d) (d) B-Tree
1 should come before 3, 2 and 4 as shown by the
edges in the DAG. Solution: (c)
Hence, the correct option is (d). Edges and vertices of the graph can be represented
in the form of a Heap data structure to have a lin-
2. Consider a weighted complete graph G on the ver- ear time complexity algorithm.
tex set {v1, v2, vn} such that the weight of, the edge Hence, the correct option is (c).
(vi, vj) is 2 |i − j|. The weight of a minimum span-
ning tree of G is: [2006]
(a) n − 1 Two-marks QuesTions
(b) 2n − 2
1. Suppose P, Q, R, S, T are sorted sequences having
n
(c) lengths 20, 24, 30, 35, 50 respectively. They are
2 to be merged into a single sequence by merging
(d) n2 together two sequences at a time. The number of
2 2 v3 7 v4
1 1 2 1
4 5
2 2 6
v1 v2
Solution: 6 3
Hence, the correct option is (c). Hence, the correct option is (d).
6. Consider a complete undirected graph with vertex 7. Consider a complete undirected graph with vertex
set {0, 1, 2, 3, 4}. Entry W (i, j) in the matrix W set {0, 1, 2, 3, 4}. Entry W(i, j) in the matrix W
below is the weight of the edge {i, j} [2010] below is the weight of the edge {i, j} [2010]
0 1 8 1 4
1 0 12 4 9 0 1 8 1 4
1 0 12 4 9
W = 8 12 0 7 3
W = 8 12 0 7 3
1 4 7 0 2
4 9 3 2 0 1 4 7 0 2
4 9 3 2 0
What is the minimum possible weight of a span-
ning tree T in this graph such that vertex 0 is a leaf
node in the tree T ? What is the minimum possible weight of a path P
(a) 7 (b) 8 (c) 9 (d) 10 from vertex 1 to vertex 2 in this graph such that P
contains at most 3 edges?
Solution: (d) (a) 7 (b) 8 (c) 9 (d) 10
Two possible Spanning Trees wherein vertex ‘o’ is
at the leaf level is as given below: Solution: (c)
Original Graph With 4 edges it is possible to have a cost of (7)
1 for the path between 1 and 2. But this path ‘p’
0 1
4 12 will have 4 edges i.e. (1-0-3-4-2). This is obtained
8 using Dijkstra’s Single Source shortest path
4 9 2 spanning tree. However with almost 3 edges, the
1 4 minimum possible cost path from 1 to 2 is not
2 7
3 less than 9.
3 Hence, the correct option is (c).
8. Consider the following graph: (a) There is a minimum spanning tree containing e.
b e
(b) If e is not in a minimum spanning tree T, then
5 2 in the cycle formed by Adding e to T, all edges
5
6 6 have the same weight.
a 4 d 3 g (c) Every minimum spanning tree has an edge of
6 weight w.
5 4 (d) e is present in every minimum spanning tree.
3
c f
6 Solution: (d)
If there are multiple edges in the graph with the
Which one of the following is NOT the sequence minimum weight ‘w’, then it is not necessary that
of edges added to the minimum spanning tree us- the specific edge with cost ‘w’ must be present in
ing Kruskal’s algorithm? [2009] all spanning trees. There may be many edges of
(a) (b, e) (e, f) (a, c) (b, c) (f, g) (c, d) weight w in the graph and e.
(b) (b, e) (e, f) (a, c) (f, g) (b, c) (c, d) Hence, the correct option is (d).
(c) (b, e) (a, c) (e, f) (b, c) (f, g) (c, d)
11. Suppose the letters a, b, c, d, e, f have probabilities
(d) (b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
1 1 1 1 1 1
Solution: (d) , , , , , , respectively.
2 4 8 16 32 32
After adding (b, e) one can add either (e, f ) or (a, c)
Which of the following is the Huffman code for
Kruskal’s algorithm uses greedy strategy (picks
the letter a, b, c, d, e, f? [2007]
minimum weight edge). Weight of edge (a, c) is
(a) 0, 10, 110, 1110, 11110, 11111
less than (b, c). So it cannot come after (b, c).
(b) 11, 10, 011, 010, 001, 000
Hence, the correct option is (d).
(c) 11, 10, 01, 001, 0001, 0000
9. (d) 110, 100, 010, 000, 001, 111
−3 Solution: (a)
b e
The Huffman Encode tree can be obtained by ap-
1 2 1 4 plying optimal merge pattern algorithm. Assign ‘0’
−5 to the left branch and ‘1’ to the right branch in the
a c h f
encode tree. Collect the stream of binary bits to get
2 3 2 3 the codes of the message.
Hence, the correct option is (a).
2 g
d
12. Suppose the letters a, b, c, d, e, f have probabili-
Dijkstra’s single source shortest path algorithm 1 1 1 1 1 1
ties , , , , , , respectively. What is the
when run from vertex a in the above graph, com- 2 4 8 16 32 32
putes the correct shortest path distance to [2008] average length of the correct answer to Q.11?
(a) only vertex a
[2007]
(b) only vertices a, e, f, g, h
(a) 3 (b) 2.1875
(c) only vertices a, b, c, d
(c) 2.25 (d) 1.9375
(d) all the vertices
Solution: (d)
Solution: (c) The average no. of bits/message is obtained by
Dijkstra’s Algorithm can not apply for negative using the formula
weight edges.
n
Hence, the correct option is (c).
∑d i
*
qi
10. Let w be the minimum weight among all edge i =1
2 7
7
(c) P Q R U T S - Invalid
1 3 4
Which one of the following cannot be the sequence 7 3
of edges added, in that order, to a minimum span-
(d) P Q T R U S - Invalid
ning tree using Kruskal’s algorithm? [2006]
1 2 4
(a) (a–b), (d–f ), (b–f ), (d–c), (d–e) Hence, the correct option is (b).
(b) (a–b), (d–f ), (d–c), (b–f ), (d–e)
(c) (d–f ), (a–b), (d–c), (b–f ), (d–e) 16. Let G = (V, E) be an undirected graph with a sub-
(d) (d–f ), (a–b), (b–f ), (d–e), (d–c) graph G1 = (V1, E1). Weights are assigned to edges
Solution: (d) of G as follows.
(a) (a1 − b), (d 1 − f ), (b2 − f ), (d 2 − c), (d 3 − e) - 0 if e ∈ E1
correct w (e) =
1 otherwise
(b) (a1 − b), (d 1 − f ), (d 2 − f ), (b2 − f ), (d 3 − e) -
correct A single-source shortest path algorithm is ex-
(c) (d 1 − f ), (a1 − b), (d 2 − c), (b2 − f ), (d 3 − e) - ecuted on the weighted graph (V, E, w) with an
correct arbitrary vertex vi of V1 as the source. Which of
the following can always be inferred from the path
(d) (d 1 − l ), (a1 − b),(b − f 2),(d − e3 (d 2 − c) -
costs computed? [2003]
incorrect
Hence, the correct option is (c). (a) The number of edges in the shortest paths
from vi to all vertices of G
15. Suppose we run Dijkstra’s single source shortest- (b) Gi is connected
path algorithm on the following edge-weighted (c) Vi forms a clique in G
directed graph with vertex P as the source. (d) Gi is a tree
Solution: (a) +
No. of edges in the shortest paths can be deter-
mined as a result of Dijkstra’s single source short-
est paths algorithm. Which of the following statements is necessarily
Hence, the correct option is (a). true for all j and k after termination of the above
algorithm? [2003]
17. What is the weight of a minimum spanning tree of (a) A[j, k] < n
the following graph?
(b) If A[j, j] > n − 1, then G has a Hamiltonian
2 cycle
b g 19
i (c) If there exists a path from j to k, A[j, k] con-
6
tains the longest path length from j to k
1 c 3 8 14
2 (d) If there exists a path from j to k, every sim-
a 2 5
15 ple path from j to k contains at most A[j, k}
d h 4 edges
8 4 9 j
8 f Solution: (c)
11
It is just opposite of all pairs shortest path, where
2
e max replaces min; therefore it finds longest path
[2003]
cost from j to k;
(a) 29 (b) 31 Hence, the correct option is (c).
(c) 38 (d) 41
19. Let G be an undirected connected graph with
Solution: (b) distinct edge weight. Let max e be the edge with
maximum weight and min e the edge with mini-
2 i mum weight. Which of the following statements is
h g
false? [2000]
5
3 8 (a) Every minimum spanning tree of G must con-
c 2 4 tain mine
d i
1 h (b) If max e is in a minimum spanning tree, then
a 4 its removal must disconnect G
2
(c) No minimum spanning tree contains max e
f (d) G has a unique minimum spanning tree
e Solution: (d)
Weight Hence, the correct option is (d).
Hence, the correct option is (b). 20. The weighted external path length of the binary
18. Let G = (V, E) be a directed graph with n vertices. tree in figure is [1991]
A path from vi to vj in G is a sequence of vertices
(vi,vi + 1,…,vj ) such that (vk, vk + 1) ∈ E for all k in i
through j − 1. A simple path is a path in which no
vertex appears more than once. 15
Let A be an n × n array initialized as follows.
1 if ( j , k ) ∈ E
A[ j , k ] =
1 otherwise 9 10
2 4 5 7
Solution: The formula for weighted external path can be done in O(mlogn) which is O(mlogn) for
length any graph because for each edge (u, v) we check
n whether u and v are in the same tree, this is done
= ∑d
i =1
i
*
qi ; di = dist. from root to with two calls to find which is O(logn), and we un-
Fi qi = length of file Fi. ion the two if necessary which is O(1). Therefore
the loop is O(mlogn). Hence the total time com-
=4×2+4×4+4×5+4×7+3×9+3×
plexity is O(mlogn).
10 + 1 × 15
Hence, the correct option is (d).
= 8 + 16 + 20 + 28 + 27 + 30 + 15 = 144
22. Complexity of Kruskal’s algorithm for finding the
21. Kmskal’s algorithm for finding a minimum span-
minimum spanning tree of an undirected graph
ning tree of a weighted graph G with n vertices and
containing n vertices and m edges if the edges are
m edges has the time complexity of: [1991]
sorted is________
(a) O(n2) (b) O(mn)
(c) O(m + n) (d) O(m log m) Solution: θ ( m log m); ‘m’ edges are maintained in
the form of min-Heap Heap operation requires log
Solution: (d)
m time for deletion. Hence 9(m log m)
Kruskal’s Algorithm uses min Heap to keep the
list of edges 9(m log m). The sorting of the edges
Five-marks Questions
1. A Language uses an alphabet of six letters, {a, b, 0.40
c, d, e, f}. The relative frequency of use of each 0.24 0.36
letter of the alphabet in the language is m given e
below.
0.11 0.13 0.17 0.19
Letter Relative frequency of use
f c a
A 0.19
0.05 0.08
B 0.05
b d
C 0.17
D 0.08
0.6
E 0.40 0.4
F 0.11 e
Design a prefix binary code for the language which 0.24 0.36
would minimize the average length of the encoded
words of the language. [1989]
0.11 0.13 0.17 0.19
Solution:
f
0.13 0.05 0.08
1 1 1
0 1 2 n−1
= Φ
≠
It is a chain of (n − 1) edges in an n - vertex graph
skewed tree.
= − (b)
n−1 n−1
= 1 0
1
2 3
2 3
(a) Complete the algorithm by specifying the
property of vertex u in each case It is like a star graph.
(b) What is the time complexity of the algorithm. 5. Let G be the directed, weighted graph shown below
[1994] in Figure
Solution:
(a) (1) ∈ I 41
B
22
(2) u is not adjacent to any vertex of I 6 12
9φ
(b) time complexity is O (n2) A C
2
3. How many minimum spanning trees does the 12 6φ
following graph have? Draw them. (Weights are
assigned to the edge). [1995] D E
5φ 1φ
7φ 15
A B
2 F
3
3 4 C
4 We are interested in the shortest paths from A.
5
E D (a) Output the sequence of vertices identified
by the Dijkstra’s algorithm for single source
Solution: shortest path when the algorithm is started at
By using Kruskal’s Algorithm node A to E.
A 2 B (b) Write down sequence of vertices in shortest
3 path from A to E.
3 C (c) What is the cost of the shortest path from A
4 to E? [1996]
E D
Cost = 12 Solution:
Another possibility
(a) Sequence of vertices identified by the Dijk-
A 2 B
3
stra’s Single Source shortest path algorithm
3 when started from vertex ‘A’ is A, F, B, E, C
C
4
(b) Shortest path from A to E is A, B, D, C, E
E D
(c) Cost = 69 (6 + 41 + 12 + 10)
(a) What is the weight of a minimum weight- 7. Consider a weighted undirected graph with vertex
spanning tree in this graph? Write only the set
answer without any explanations. V = {n1, n2, n3, n4, n5 And Edge set E = {(n1, n2, 2),
(b) What is the weight of a maximum weight- (n1, n3, 8), (n1, n6, 3), (n2, n4, 4), (n2, n5, 12), (n3, n4, 7),
spanning tree in this graph? Write only the (n4, n5, 9), (n4, n6, 4)}. The third value in each tu-
answer without any explanations? [1997] ple represents the weight of the edge specified in
a) A, E, B, D, C, F the tuple.
b) A to E ⇒ A → E (a) List the edges of a minimum spanning tree of
c) cost (A, E) = 2 the graph.
(b) How many distinct minimum spanning trees
does this graph have?
Value X DISTANCE
Initial S (c) Is the minimum among the edge weights of a
schedule A B C D E F minimum spanning tree unique overall possi-
1 A {E} 6 9 2 7 ble minimum spanning trees of a graph?
(d) Is the maximum among the edge weights of a
6 6 5 2 7 minimum spanning tree unique over all pos-
2 A,E {B} 6 6 4 2 7 sible minimum spanning trees of a graph?
[2001]
3 A,B,E {D} 6 5 4 2 7 Solution:
4 A, B, E, D {C} 6 5 4 2 6 (a) [(n1, n2), (n1, n6), (n4, n6), (n3, n4), (n4, n5)]
5 A, B, C, D, E F 6 5 4 2 6 (b) It has two distinct Spanning Tree
(c) Yes it is unique;
Let us take n = 3, then the graph can be shown as The graph and its Spanning Tree
n1 n2
8 3
1 (2,3 1 (3,3 4
(1,3 12
n3 n6
(2,2 7 4
(1,2 (3,2 n4 n5
1 1 9
2 2
n1 n2
(1,1 1 (2,1 1 (3,1
all edge costs are unit cost form the given con- n3 n6
dition (a) and (b) since a spanning tree with n2-
7 4
vertices will have (n2 − 1) edges. n5
n4 9
Therefore cost of both minimum and maximum
sparing tree is (n − 1) and ( )
2 n2 − 2 + 1 respec-
tively.
one-mark QuesTions
1. An algorithm to find the length of the longest (a) n (b) n2
monotonically increasing sequence of numbers in (c) n log n (d) n log2n
an array
Solution: (c)
A[0: n − 1] is given below. The number of comparisons that a comparison sort
Let Li denote the length of the longest monotoni- algorithm requires in proportion to n log n, where
cally increasing sequence starting at index i in the n is the number of elements to sort.
array Hence, the correct option is (c).
Initialise Ln − 1 = 1 3. Which one of the following algorithm design tech-
For all i such that 0 ≤ i ≤ n − 2 niques is used in finding all pairs of shortest dis-
tances in a graph? [1998]
1 + Li +1 if A[i ] < A[i + 1]
Li = (a) Dynamic programming
1 otherwise (b) Backtracking
Finally the length of the longest monotonically in- (c) Greedy
creasing sequence is (d) Divide and Conquer
Max(L0, L1,…Ln − 1) Solution: (a)
Which of the following statements is TRUE? Hence, the correct option is (a).
[2011]
(a) The algorithm uses dynamic programming
paradigm
Two-mark QuesTions
(b) The algorithm has a linear complexity and
1. A sub-sequence of a given sequence is just the
uses branch and bound paradigm
given sequence with some elements (possibly none
(c) The algorithm has a non-linear polynomial
or all) left out. We are given two sequences X [m]
complexity and uses branch and bound paradigm
and Y [n] of lengths m and n, respectively, with
(d) The algorithm uses divide and conquer para-
indexes of X and Y starting from 0 [2009]
digm.
We wish to find the length of the longest common
Solution: (a) sub-sequence (LCS) of X [m] and Y [n] as l(m, n),
It is based on the principle of optimality. where an incomplete recursive definition for the
Hence, the correct option is (a). function l(i, j) to compute the length of the LCS of
2. The tightest lower bound on the number of com- X[m] and Y[n] is given below:
parisons, in the worst case, for comparison-based l(i, j) = 0, if either i = 0 or j = 0
sorting is of the order of [2004] = exprl, if i, j > 0 and
(a) Change line 6 to if (Y [k] < x) 7. Obtain the optimal binary search tree with equal
i = k + l; else j = k − 1; probabilities for the identifier set (a1, a2, a3) = (if,
(b) Change line 6 to if (Y [k] < x) stop, while) [1991]
i = k − 1; else j = k + 1;
(c) Change line 6 to if (Y [k] < = x) i = k; else Solution:
i = k; Apply the Dynamic Programming formula for ob-
(d) Change line 7 to while ((Y [k] = = x) and (I < taining minimum cost Binary Search tree.
j )); COST (i, j) = min {c [I, k − 1)
It will cause the loop to terminate wherein the con- + c(k, j)] + w (I, j) (1)
dition i < j now becomes false. i<k≤j
COST (I, i) = Φ
Solution: (c) j
Hence, the correct option is (c). w (i, j) = qi + ∑ (p
e = i +1
c + qc ); w ( I , i ) = qi
6. A binary search tree is generated by inserting in R (i, i) = the value of ‘k’ that minimise equation
order the following integers: (1) is
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
R (i, j) = Φ; the root of B.S.T
The number of nodes in the left subtree and right
subtree of the root respectively is [1996] Let R (i, j) be the root of B.S.T Tij then the tree is
(a) (4, 7) (b) (7, 4) constructed as
(c) (8, 3) (d) (3, 8) Tij = k
Solution: (b)
50
Tik−1 Tkj
3 8 37 60
24
Hence, the correct option is (b).
Five-marks Question
1. Fill in the blanks in the following template of (a) Copy the complete line containing the blanks
an algorithm to compute all pairs shortest path in the Initialization step and fill in the blanks.
lengths in a directed graph G with n*n adjacency (b) Copy the complete line containing the blanks
matrix A. A[i, j] equals to 1 if there is an edge in in the Algorithm step and fill in the blanks.
G from i to j, and 0 otherwise. Your aim in fill- (c) Fill in the blank: The running time of the Algo-
ing in the blanks is to ensure that the algorithm is rithm is O (____). [2002]
correct. Solution:
←
←
Φ Φ
←
←
←
One-mark QuestiOns
1. Let G be a graph with n vertices and m edges. Which one of the following is TRUE?
What is the tightest upper bound on the running (a) The graph does not have any topological or-
time of Depth First Search on G, When G is repre- dering.
sented as an adjacency matrix? [2014] (b) Both PQRS and SRQP are topological order-
(a) Θ(n) (b) Θ(n + m) ings.
(c) Θ(n2) (d) Θ(m2)
(c) Both PSRQ and SPRQ are topological order-
Solution: (c) ings.
If the graph is represented using adjacency matrix, (d) PSRQ is the only topological ordering.
then total number of elements matrix are bounded
by q (n2). So DFS algorithm takes q (n2). Solution: (c)
Hence, the correct option is (c). To get topological ordering, we have to start from
the vertex of degree 0, and add that vertex to the
2. Consider a rooted n node binary tree represented topological ordering sequence and then remove it
using pointers. The best upper bound on the time together with all its edges from the graph. Con-
required to determine the number of subtrees hav- tinue this process to remaining all vertices.
ing exactly 4 nodes is O(nalogbn). Then the value Hence, there are two topological ordering are in
of a + 10b is _______. [2014] the graph PSRQ and SPRQ.
Solution: 1 Hence, the correct option is (c).
The best algorithm on the time required to de- 4. A priority queue is implemented as a Max-leap.
termine the number of subtrees having exactly 4 Initially, it has five elements. The level-order
nodes takes q (n) traversal of the heap is: 10, 8, 5, 3, 2. Two new
Hence, a = 1 and b = 0, so a + 10(b) = 1 elements 1 and 7 are inserted into the leap in that
3. Consider the directed graph given below. [2014] order. The level-order traversal of the heap after
the insertion of the elements is: [2014]
P Q (a) 10, 8, 7, 3, 2, 1, 5
(b) 10, 8, 7, 2, 3, 1, 5
(c) 10, 8, 7, 1, 2, 3, 5
R S (d) 10, 8, 7, 5, 3, 2, 1
3 2 1 7 Solution: (a)
Hence, the correct option is (a).
7. Let A be a problem that belongs to the class NP.
Then which one of the following is TRUE?
[2009]
10 (a) There is no polynomial time algorithm for A.
(b) If A can be solved deterministically in polyno-
8 5
mial time, then P = NP.
3 2 1 7 (c) If A is NP-Hard, then it is NP-complete.
(d) A may be undecidable.
Solution: (c)
10 By definition of NP-Hard and NP-complete rest all
choices can be shown to be false.
8 7 If A is NP-Hard, then it is NP-complete.
Hence, the correct option is (c).
3 2 1 5
8. Let S be an NP-complete problem and Q and R be
two other problems not known to be in NP. Q is
Level order traversal: 10, 8, 7, 3, 2, 1, 5 polynomial time reducible to S and S is polynomial-
Hence, the correct option is (a). time reducible to R. Which one of the following
statements is true? [2006]
5. Consider the tree arcs of a BFS traversal from
(a) R is NP-complete
source node W in an unweighted, connected, indi-
(b) R is NP-Hard
rected graph. The tree T formed by the three arcs is
(c) Q is NP-complete
a data structure for computing [2014]
(d) Q is NP-Hard
(a) The shortest path between every pair of verti-
ces. Solution: (b)
(b) The shortest path from W to every vertex in Since S α R ‘R’ is definitely NP-Hard R is NP-
the graph. Hard.
(c) The shortest paths from W to only those nodes Hence, the correct option is (b).
that are leaves of T.
(d) The longest path in the graph. 9. The problem 3-SAT and 2-SAT are [2004]
(a) both in P
Solution: JFS algorithm is useful for finding, (b) both NP-complete
shortest path distance from source node to every (c) NP-complete and in P respectively
either node. (d) undecidable and NP-complete respectively
one-mark QuesTions
1. The following numbers are inserted into an empty the complexity classes P, NP and NP-complete
binary search tree in the given order: 10, 1, 3, 5, (NPC)? [2014]
15, 12, 16. What is the height of the binary search
tree (the height is the maximum distance of a leaf
(a) (b)
node from the root)? [2004]
NP
(a) 2 (b) 3 P P NP
(c) 4 (d) 6
NPC
Solution: (b)
The leaf ‘5’ is at a distance of path length 3 from
the root.
It’s binary search tree will be: NPC
(c) (d)
10 P = NP P = NP = NPC
NPC
1 15
3 12 16
5
Solution: (d)
Hence, the correct option is (b). Computing largest Clique in a given graph, is
NP-Hard problem. So if a polynomial time algo-
rithm discovered for NP-Hard problem then we
Two-mark QuesTions can discover polynomial time algorithm for every
1. Suppose a polynomial time algorithm is discov- NP-Hard problem i.e. P = NPH and P = NP.
ered that correctly computes the largest clique in Therefore, P = NPC
a given graph. In this scenario, which one of the Hence, P = NP = NPC
following represents the correct Venn diagram of Hence, the correct option is (d).
2. Consider the decision problem 2CNFSAT defined 4. A binary search tree is used to locate the number
as follows: 43. Which of the following probe sequences are
{Φ | Φ is a satisfiable propositional formula in possible and which are not? Explain. [1996]
CNF with at most two literals per clause} (a) 61 52 14 17 40 43
For example, Φ = (x1 ∨ x2) ∧ (x1 ∨ x3) ∧ (x2 ∨ x4) is (b) 2 3 50 40 60 43
a Boolean formula and it is in 2CNFSAT. (c) 10 65 31 48 37 43
The decision problem 2CNFSAT is [2014] (d) 81 61 52 14 41 43
(a) NP-complete (e) 17 77 27 66 18 43
(b) Solvable in polynomial time by reduction to
directed graph reachability. Solution: (a)
(c) Solvable in constant time since any input in- (b)
stance is satisfiable. Not possible 60
61 2 cannot lie to the
(d) NP-Hard, but not NP-complete. left of 50
52 3
Solution: (b)
2CNFSAT problem is P-class problem so it can be 50
14
solved in polynomial time by reduction to polyno-
mial time reachability. 17 40
Solution: (a) 48 14
For the nodes at leaf level, the number of nodes = n
Possible 37 41
n n2 nk Possible
The next level it is , then next ,… . 43
2 2 2 43
For nodes at leaf level number of leaves = 0
For nodes at leaf next level number of leaves = 1 (e)
n n nk 17
i.e. n … 0 −1 −2 −K
2 4 2
77
Therefore total time Not possible as ‘18’ cannot
k 27 lie to the right of ‘27’
k 2k
nn
=∑
2k
= ii ⋅⋅ ii
∑
i =1 2
i =1 2
66
k 2kk
k 2 n
= nn ∑ ii
= n
∑
i =1
i =1 22
18
=
=OO(( nn)) 48
Hence, the correct option is (a). Hence, the correct option is (a).
One-mark QuestiOns
1. Max heap is a heap where the value of each parent Solution: (a)
is greater than or equal to the value of children. To sort ‘n’ elements using selection sort it requires
Which of the following is a max-p? [2011] O(n) swaps.
Hence, the correct option is (a).
(a) 10 (b)
10 3. Which one of the following array represents a max
8 6
8 6
heap? [2009]
(a) {25, 12, 16, 13, 10, 8, 14}
4 5 2 4 5 2 (b) {25, 14, 13, 16, 10, 8, 12}
1
(c) {25, 14, 16, 13, 10, 8, 12}
1 (d) {25, 14, 12, 13, 10, 8, 16}
(c) 10 (d) 5 Solution: (c)
5 6 2 8 In option (a) (13) cannot be the child of (12) in
max Heap in option (b) (16) cannot be the child
4 8 2 1 1 4 6 10 of (14). In option (d) (16) cannot be the child of
smaller value node.
Solution: (b) In (a), s[3] which is the left child of a[1] is greater
Trees in (e) and (d) violate the property of Max than the parent (13 > 12). In (b), also a[3] > a[1]
Heap. Tree (a) satisfies the property of Max Heap, (16 > 14). In (d), a[6] which is right child of a[2]
but it is not a complete Binary Tree. Tree (b) is the is greater than a[2] (16 > 12).
correct answer. (a) is not a complete binary tree. In Hence, the correct option is (c).
(c) and (d), heap property is not satisfied between
4. It is the content of the array after two operations
5 and 8.
on the correct answer to the previous question?
Hence, the correct option is (b).
[2009]
2. What is the number of swaps required to sort (a) {14, 13, 12, 10, 8}
n-elements using selection sort, in the worst case? (b) {14, 12, 13, 8, 10}
[2009] (c) {14, 13, 8, 12, 10}
(a) Θ(n) (b) Θ(nlogn) (d) {14, 13, 12, 8, 10}
(c) Θ(n2) (d) Θ(n2logn) Solution: (d)
Tree for option (b) ‘8’ is greater than ‘6’ not possible Inserting ‘2’ 9
9
7 6 8
3 6 8 3 1 5 2
9 7 9 8
3 1 5 2 6 4
5 6 8
Hence, the correct option is (a).
3 1
8. Let G(V, E) be an undirected graph with positive
edge weights. Dijkstra’s single source shortest path
Tree for option (d) is max Heap
algorithm can be implemented using the binary
Hence, the correct option is (d).
heap data structure with time complexity
7. A 3-ary max heap is like a binary max heap, but [2005]
instead of 2 children, nodes have 3 children. A (a) O (|V2|)
3-heap can be represented by an array as follows: (b) O ((|E|+|V| log |V|)
root is stored in the first location, a[0], nodes in (c) O (V |log| V.J)
next level, from left to right, is stored from a[l] (d) O (E. |V| log |V|)
[3]. The nodes from the second level of the tree Solution: (b)
from the left to right are stored from a[4] location Using Binary heap Data structure, the time com-
onward. An item x can be inserted into a 3-ary plexity is O((E + V) logV)
heap containing n items by placing x in the loca- Hence, the correct option is (b).
tion a[n] and pushing it up the tree to satisfy the
9. Suppose there are [log n] sorted lists of n log n-ele-
heap property. [2006]
ments each. The time complexity of producing a
Suppose the elements 7, 2, 10 and 4 are inserted, sorted list of all these elements is: (Hint: Use a
in that order, into the valid 3-array max heap found heap data structure) [2005]
in the question 6. Which one of the following is (a) O(n log log n)
the sequence of items in the array representing the (b) O(n log n)
resultant heap? (c) Ω(n log n)
(a) 10, 7, 9, 8, 3, 1, 5, 2, 6, 4 (d) Ω(n3/2)
(b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 Solution: (b)
(c) 10, 9, 4, 5, 7, 6, 8, 2, 1, 3 Total number of elements in all the lists log
(d) 10, 8, 6, 9, 7, 2, 3, 4, 1, 5 n
n⋅ = n. A heap of ‘n’ elements and sorting
log n
Solution: (a)
9
it require O(n log n)
Hence, the correct option is (b).
5 6 8 10. The elements 32, 15, 20, 30, 12, 25, 16, are inserted
3 1 one by one in the given order into a max Heap. The
resultant max Heap is [2004]
(a) Original tree
(a) 32 (b) 32
Inserting 7 9
30 25 25 30
7 6 8
15 12 20 16 12 15 20 16
3 1 5
(c) 32 (d) 32 n ( n − 1)
(a)
30 25 25 30 2
(b) 2n
15 12 16 20 12 15 16 20 (c) n!
(d) 2n(n−1)/2
Solution: (a) Solution: (d)
32
It is based on Kirchoff’s Theorem
Hence, the correct option is (d).
30 25 13. Lt G be an undirected graph. Consider a depth-first
15 16
traversal of G, and let T be the resulting depth-first
12 20
search tree. Let u be a vertex in G and let v be the
Hence, the correct option is (a). first new (unvisited) vertex visited after visiting u
in the traversal. Which of the following statements
11. Consider an undirected unweighted graph G. Let a is always true? [2000]
breadth-first traversal of G be done starting from a (a) {u, v} must be an edge in G, and u is a de-
node r. Let d(r, u) and d(r, v) be the lengths of the scendant of v in T
shortest paths from r to u and v respectively in G. (b) {u, v} must be an edge in G, and v is a de-
If u is visited before during the breadth-first tra- scendant of u in T
versal which of the following statements is correct (c) If {u, v} is not an edge in G then u is a leaf in T
[2001] (d) If {u, v} is not an edge in G then u and v must
(a) d (r, u) < d(r, v) have the same parent in T
(b) d (r, u) > d(r, v)
(c) d (r, u) ≤ d(r, v) Solution: (c)
(d) None of the above (c) is always true but (b) and (d) are true in only
few cases, (a) is never true.
Solution: (c) Hence, the correct option is (c).
If ‘u’ is visited before ‘v’, then the distance from ‘r’ to
‘u’ will be less than or equal to the distance from ‘r’ to 14. If Tl = O(1), give the correct matching for the fol-
‘v’ as shown in the graph below lowing pairs:
List I List II
A
(M) Tn = Tn − 1 +n (U) Tn = O(n)
B C (N) Tn = Tn/2 + n (V) Tn = O(nlogn)
(O) Tn = Tn/2 + nlog n (W) Tn = O(n2)
D E F G (P) Tn = Tn − 1 + log n (X) Tn = O(logn!)
[1999]
H (a) M–W, N–V, O–U, P–X
(G) (b) M–W, N–U, O–X, P–V
A (c) M–V, N–W, O–X, P–U
r (d) M–W, N–U, O–V, P–X
C
B Solution: M–W, N–U, O–V, P–X
u 15. The minimum number of interchanges needed to
D E F G
v convert the array 89, 19, 40, 17, 12, 10, 2, 5, 7, 11,
H 6, 9, 70 into a heap with the maximum element at
v (B.T.T) the root is
Hence, the correct option is (c). [1996]
12. How many undirected graphs (not necessarily con- (a) 0 (b) 1 (c) 2 (d) 3
nected) can be constructed out of a given set V = Solution: (c)
{v1, v2,… vn} of n vertices? [2001] Tree Representation of The array
Five-marks Questions
1. An array A contains n ≥ 1 positive integers in the
locations A[1], A[2],…,A[n].
The following programme fragment prints the
length of a shortest sequence of consecutive ele- = = =
ments of A, A[i], A[i + 1],…,A[ j] such that the sum
of their values is ≥ M, a given positive number. It +
prints ‘n + 1’ if no such sequence exists. Complete
the programme by filling the boxes. In each case = + =
use the simplest possible expression. Write only +
the line number and the contents of the box.
+ =
= = [1996]
= =
Solution:
(a) i = l; j = 1
= =
(b) line 2; while (x > A[I + j] [ j] or x > A[i][ j + l])
line 7; A[i] [ j] = A[i] D + l ];
= + j = j + i;
=
line 9; A[i] [ j] = x;
1 Mark Questions 2 0 0 0 0 0 0 0 1 4 1 1 0 3 0 1 1 7 4 2 3 1 0 0 1 0 1 2
2 Marks Questions 1 1 1 0 2 0 0 3 1 1 2 4 0 1 0 1 2 7 7 9 10 10 1 5 1 3 1 7
5 Marks Questions 0 1 0 0 1 0 3 3 1 1 2 3 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 4 7 2 0 9 0 15 21 8 11 15 24 5 10 0 3 5 21 18 20 23 21 2 10 3 6 3 16
Arrays 0 0 0 0 0 0 1 1 0 0 0 1 0 2 0 0 0 2 1 0 0 0 0 0 0 0 0 1
Linked Lists 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 1 2 1 0 0 2 0 1 0 0 1 0
Trees 2 1 0 0 2 0 1 1 2 3 2 4 1 2 0 1 0 5 7 7 6 6 1 0 2 1 0 4
Graphs 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 2 1 1 0 2 0 1 0 1
Hashing 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 3 2 0 2 0 0 1 2
11/19/2015 12:05:28 PM
chapter 1
array
One-mark QuestiOns
1. A program P reads in 500 integers in the range [0, 1 2 3 4 5 6 Maxsize
100] representing the cores of 500 students. It then
prints the frequency of each score above 50. What
would be the best way for P to store the frequen- Top1 Top2
cies? [2005] There are two stacks in the array. Stack that is
(a) An array of 50 numbers above is occupied from 1 to [bottom to up] and 2nd
(b) An array of 100 numbers stack occupied from MAXSIZE to 2. The array is
(c) An array of 500 numbers filled completely. So condition for ‘stack full’ is
(d) A dynamically allocated array of 550 numbers Top1 = Top2−1.
Solution: (a) Hence, the correct option is (d).
The additional subtraction operator is needed, 3. An n ´ n array v is defined as follows
when array of 50 numbers to stack frequencies are V [i, j] = i − j for all i, j, 1 ≤ i ≤ n, 1 ≤ j ≤ n.
used. The sum of the elements of the array v is [2000]
By using an array of 100 elements in this case, we (a) 0 (b) n − 1
are wasting storage space.
n2 ( n + 1)
Hence, the correct option is (a). (c) n2 − 3n + 2 (d)
2
2. A single array A[1…MAXSIZE] is used to imple- Solution: (a)
ment two stacks. The two stacks grow from oppo- The element 1, 2 … n appear n times at i, j, s place
site ends of the array. Variables top1 and top2 (top1 in i − j in the sum.
< top2) point to the location of the topmost ele- So total sum = [1 + 2 + 3 … + n]n − [1 + 2 + 3… + n]n
ment in each of the stacks. If the space is to be = 0.
used efficiently, the condition for “stack full” is Hence, the correct option is (a).
[2004] 4. Suppose you are given an array s[1, n] and a pro-
(a) (top1 = MAXSIZE/2) AND cedure reverse the order of elements in s between
(top2 = MAXSIZE/2 + 1) positions i and j (both inclusive). What does the
(b) top1 + top2 = MAXSIZE following sequence do, where i ≤ k ≤ n:
(c) (top1 = MAXSIZE/2) or (top2 = MAXSIZE) reverse (s, 1, k);
(d) top1 = top2−1 reverse (s, k + 1, n);
Solution: (d) reverse (s, 1, n); [2000]
One-mark QuestiOns
1. A function f defined on stack of integers satisfies from top when any closing parenthesis appears in
the following properties. the input.
f (f) = 0 and f (push(S, i) = max ( f (S), 0) + i Hence, the correct option is (b).
for all stacks S and integer i. if a stack contains the 3. Which of the following is essential for converting
integers 2, −3, 2, −1, 2, in order from bottom to an infix expression to the postfix form efficiently?
top, what is f (S)? [2005] [1997]
(a) 6 (b) 4 (c) 3 (d) 2 (a) An operator Stack
Solution: (c) (b) An operand Stack
Stack S is (c) An operand stack and an operator stack
Let S1 S2 S3 S4 (d) A parse tree
2 Solution: (a)
-1 -1 Consider the figure given below
2 2 2
∗(Highest)
-3 -3 -3 -3 Precedence
+(Lowest)
2 2 2 2 2
f (f) = 0
∗ → Left to right
f (S4) = max{f (f),o} + 2 = 2 Associativity
f (S3) = max{f (S4),o} + −3 = −1 + → Left to right
f (S2) = max{f (S3),o} + 2 = 2
f (S1) = max{f (S2),o} + −1 = 1 For the two operators consider the figure given below
f (S) = max{f (S1),o} + 2 = 3
f (S) = 3. In-coming On-stack
Hence, the correct option is (c). ∗ 3 4
2. The best data structure to check whether an arithme- + 1 2
tic expression has balanced parenthesis is a [2004]
(a) Queue (b) Stack Consider the algorithm given below for conversion
(c) Tree (d) List from infix to postfix which uses stack of operator.
Solution: (b) Read input symbol
When top braces appears in the input, Push it onto 1. If input symbol is an operand, print it.
the top of stack. Pop the corresponding parenthesis 2. If input symbol is an operator
9. Assume that the operators +, −, × are left asso- 11. Compute the postfix equivalent of the following
ciative and ^ is right associative. The order of infix operation expression.
precedence (from highest to lowest) is ^, ×, +, −. 3*log(x + 1) −a/2 [1998]
The postfix expression corresponding to the infix Solution:
expression a + b × c – d ^ e ^ f is [2004] Postfix: 3 × 1 + log *a/2−
(a) abc × + def ^^−
(b) abc × + de ^ f ^ − 12. That value would the following function return for
(c) ab + c × d − e ^ f ^ the input x = 95? Function fun(x: integer): integer;
(d) − + a × bc ^^def [1998]
Solution: (a)
Infix expression: [a + (b × c) − (d ^(e, f ))
And its corresponding Postfix expression: abc ×
def ^^−
Hence, the correct option is (a).
(a) 89 (b) 90 (c) 91 (d) 92
10. Let S be a stack of size n ≥ 1. Starting with the
empty stack, suppose we push the first n natural Solution: (c)
number in sequence, and then perform n pop oper- f (95) / f (( f (106)) / f (96) / f ( f (107)) / f (97) /
ations. Assume that push and pop operations take f ( f (108)) / f (98) / f ( f (109)) / f (99) / f ( f (110)) /
X seconds each, and Y seconds elapse between the f (100) / f ( f (111) / f (101) / 91
end of one such stack operation and start of the Hence, the correct option is (c).
next operation. For m ≥ 1, define the stack life of m 13. A priority queue Q is used to implement a stack
as the time elapsed from the end of Push(m) to the S that stores characters. PUSH(C) is implemented
start of the pop operation that removes m from S. as INSERT(Q, C, K) where K is an appropriate
The average stack –life of an element of this stack integer key chosen by the implementation. POP
is [2003] is implemented as DELETEMINE(Q). For a
(a) n(X + Y ) (b) 3Y + 2X sequence of operations the keys chosen are in
(c) n(X + Y ) − X (d) Y + 2X [1997]
(a) Non-increasing order
Solution: (c) (b) Non-decreasing order
Stack life of element 1 is (c) Strictly increasing order
[(n − 1)x + (n − 1)y + y] (d) Strictly decreasing order
Stack life of element 2 is
[(n − 2)x + (n − 2)y + 2y + x] Solution: (a)
Stack life of element 3 is PUSH(C) operations keys should be in decreasing
[(n − 3)x + (n − 3)y + 3y + 2x] order. Because extract-MIN(Q) give the charac-
Stack life of element k is ter with minimum key value and that is recently
[(n − k)x + (n − k)y + ky + (k − 1)x] inserted character, chosen keys are in decreasing
Sum of life-times is order.
S = [n − 1 + n − 1 +……..+ 0] Keys may be same as when we perform pop opera-
x + [(n − 1) + (n − 2) +…….0] tion, we are deleting the key inserted. We can allow
y + (1 + 2 +…..+ n)y + [0 + 1 +….+ n − 1]x the same key values for two insert operation, by
tracking deletions.
n ( n!) n ( n − 1) n ( n + 1) ( n − 1) n x Hence, the correct option is (a).
S= x+ y+ y+
2 2 2 2 14. The postfix expression for the infix expression
Average Life time A + B*(C + D)/F + D*E [1995]
S/n = (n − 1/2)x + (n − 1/2)y + (n + 1/2)y + (n − 1/2)x (a) AB + CD + * F/D + E *
= (n − 1)x + ny (b) ABCD + * F/ + DE * +
= n(x + y) – x (c) A * B + CD/F * DE ++
Hence, the correct option is (c). (d) A + * BCD/F * DE ++
Stack 10 10 20 10 10 20 10 10 20 10 10 10 Stack 20
The sequence of values popped out is 20, 20, 10, 10, 20.
one-mark QuesTions
1. Let P be a singly linked list, Let Q be the pointer to
an intermediate node x in the list. What is the worst
case time complexity of the best known algorithm
to delete the node from list? [2004]
(a) O(n)
(b) O(log2 n)
(c) O(log n)
(d) O(1)
Solution: (a)
We need to a pointer to the node behind it to de-
lete an intermediate node x. Traversal is to be done
from starting to the node behind required node. So
O(n) is worst case complexity.
2. In the worst case, the number of comparisons
needed to search a singly linked list of length n
given element is [2002]
(a) log n
(b) n/2 Choose the correct alternative to represent the
(c) log n−1 blank line. [2013]
(d) n (a) q = NULL; p->next=head; head=p
(b) q-> next = NULL; head = p; q-> next = head
Solution: (d)
(c) head = p; p-> next = q; q-> next = NULL
The element to be searched is supposed to be com-
(d) q-> next = NULL; p-> next = head; head = p
pared with all elements of linked list, in the worst case.
Solution: (d)
q contains address of second last node and p con-
Two-marks QuesTions tains address of last node when the while loop
ends. So following things has to be done after
1. The following C function takes a simply linked-list while loop.
as input argument. It modifies the list element to i. Set next of q as NULL, q-> next = NULL
the front of the list and returns the modified list. ii. Set next of p as head , p-> next = head
Some part of the code is blank. iii. Make head as p(head = p)
20 39
10
25 35 42
15
23
Queue. To which node should p point such that (c) The elements in the list are sorted in non-
both the operations enQueue and deQueue can be increasing order of data value
performed in constant time. [2004] (d) Not all elements in the list have the same data
value
Solution: (b)
Front Rear f() working:
1. If linked list is empty return 1.
2. Else if linked list has only one element return 1
P ?
3. Else if node->data is smaller than equate node-
>next->data and same thing for rest of the list.
(a) Rear node Then
(b) Front node 4. Else return 0
(c) Not possible with a single pointer
(d) Node next to front 7. Linked list are not suitable data structures of which
one of the following problems? [1994]
Solution: (c) (a) Insertion Sort
For option (a) we have to traverse back to the node (b) Binary search
behind rear node for queue operation, if p points to (c) Radix sort
rear node. (d) Polynomial manipulation
For option (b) we need extra pointer to perform de-
Queue operation, if p points to front node. Solution: (b)
For option (d) we have to traverse back to perform de- Middle node is O(1) in binary search and that’s not
Queue operation, if p points to node next to front node. possible with linked list.
6. Consider the function f defined below: 8. In a circular linked list organization, insertion of a
record involves modification of: [1987]
(a) One pointer
(b) Two pointers
(c) Multiple pointers
(d) No pointers
Solution: (b)
(1)
(2)
Five-marks Questions
1. Let P be a pointer as shown in the figure in a singly 2. Consider a singly linked list having n nodes. The
linked list. data items d1, d2….dn are stored in these n nodes.
Let X be a pointer to the j-th node (1 ≤ j ≤ n) in
which dj is stored. A new data item d stored in a
P (Cell i) Cell (i + 1) (Cell (i + 2) Cell (i + 2) node with address Y is to be inserted. Give an algo-
rithm to insert d into the list to obtain a list having
What do the following assignment statements items d1, d2,…dj − 1, d, dj …dn in that order without
achieve? [1998] using the header. [1993]
(i) q:=p->next Solution:
(ii) p->next:=q->next
X
(iii) q->next:=(q->next)->next
(iv) (p->next)->next:=q
Solution:
d1 dj−1 dj dn
(i) Status after first statement
step 2
p i i+1 i+2
q
One-mark QuestiOns
1. Consider the following rooted tree with the vertex P
labeled P as the root:
Q R
P
S T U V
W
Q R
S Q P T RWU V
2 1
root 10
1 B 3 1 C 3
2 2 6
(b) 8
root 10
6
(c) 5
If height = 2 ⇒ full B.T.
Number of nodes = 1 + 21 + 22
4 8 2 1
root 5
8
(d) 2
If height = 3 ⇒ full B.T.
1 4 6 1 Number of nodes = 1 + 22 + 22 + 23
If height = h,
Solution: (b)
Number of nodes = 1 + 22 + 22 ……..+ 2h
Option (a) is not a complete B.T.
(c) and (d), heap property is not satisfied between ( 2h−1 − 1)
=1 −1
5 and 8, so they are not max-Heap. 2
Hence, the correct option is (b). = 2h+1 − 1
3. Which of the following is TRUE? [2008] Hence, the correct option is (b).
(a) The cost of searching an AVL tree is q (log n) 5. The maximum number of binary tree that can be
but that of a binary search tree is O(n) formed with three unlabeled nodes is: [2007]
(b) The cost of searching an AVL tree is q(n log n) (a) 1 (b) 5 (c) 4 (d) 3
but that of a complete binary tree is q(n log n) Solution: (b)
(c) The cost of searching a binary tree is q(n log n)
but that of an AVL tree is q(n)
(d) The cost of searching an AVL tree is q(n log n)
but that of a complete binary tree is O(n).
Solution: (a)
Cost of searching BST: Best case O(min height) = 2n
Cn
Worst case Formula =
O(max height) = O(n). n +1
6
Where n is total number of nodes. C3 6!
Cost of searching AVL tree is q(log n) = =5
4 3! 3! 4
Hence, the correct option is (a).
Hence, the correct option is (b).
4. The height of a binary tree is the maximum num-
6. A scheme for storing binary trees in an array X
ber of edges in any root to leaf path. The maximum
is as follows. Indexing of X starts at instead of 0.
number of nodes in a binary tree of height h is:
The root is stored at X[1]. For node stored at X[i],
[2007]
the left child , if any item is stored at X[2i] and
(a) 2h − 1 (b) 2h − 1 − 1
right child, if any X[2i = 1]. To be able to store any
(c) 2h+1 − 1 (d) 2h+1
binary tree on n vertices the minimum size of X
Solution: (b) should be [2006]
Only maximum number of nodes will be possible, (a) log n (b) n
if tree is a full binary tree. (c) 2n + 1 (d) 2n −1
If height = 0 ⇒ full B.T.
Solution: (b)
Number of nodes = 1
If given tree is a complete binary tree, minimum
If height = 1 ⇒ full B.T. size will be used. No intermediate gaps between
Number of nodes = 1 + 21 the elements of tree will be present.
No intermediate gaps ⇒ so the array size = no of Here is 6 nodes with degree 2, 5 nodes with degree 1.
nodes = n. 7 leaf nodes
Hence, the correct option is (b).
If nodes
7. In a binary tree, the number of internal nodes of
degree 1 is 5, and the number of internal node of
degree 2 is 10. The number of leaf nodes in the
binary tree is [2006]
(a) 10 (b) 11 (c) 12 (d) 15
Solution: (b)
In any binary tree, possible degrees of any node
0 ⇒ leaf node
1,2 ⇒ internal node
Internal node with degree 1 = 5 By taking any 4 leaf nodes and put children for
Internal node with degree 2 = 10 each, gives 10 nodes with degree 2, 5 nodes with
Take internal nodes of degree 1 degree 1 and 11 leaf nodes.
p q r s t Hence, the correct option is (b).
8. The number 1, 2, 3….n are inserted in binary
search tree in some order. In the resulting tree , the
right subtree of the root contains p nodes. The first
a b c d e number to be inserted in the tree must be
[2005]
Parent nodes are to be presented for these nodes (a) p (b) p + 1
with degree 2. (c) n − p (d) n − p + 1
It may be possible
Solution: (c)
Inserting any number x will first be the root of
BST, there should be p numbers after x, because
right subtree of root contains p nodes.
Hence, the correct option is (c).
9. The following numbers are inserted into
Parents are not required for the new 3 nodes having empty binary search tree in the given order
two children 10,1,3,15,12,16. What is the height of the binary
search tree (the height is the maximum distance of
a node from the root)? [2004]
(a) 2 (b) 3 (c) 4 (d) 6
Solution: (b)
10
1
15
3
5 12 16
Solution:
Expanded as
((1+1) − (0 − 1)) + ((1 − 0) + (1 + 1))
The number of internal nodes = n − 1, if number =3+3
of leaves = n. =6
Hence, the correct option is (b). 2. Consider the pseudo code given below. The func-
16. it is possible to construct a binary tree uniquely tion DoSomething() takes as argument a pointer
whose pre-order and post-order traversals are to the root of an arbitrary tree represented by the
given. [1987] leftMostchild-right Sibling representation. Each
mode of the tree is of type treeNode
Solution: FALSE
Pre-order = ab
Post-order = ba
a a
b b
+1 +1
+1
0 0
Max height → 3
−1
Hence, the correct option is (b). 3,4,5 3,4,5 3,4,5 3,4,5 3,4,5
3 5
Common Data for Questions 7, 8 and 9. 3 4 5
A binary search tree (BST) stores values in the range
4 5 3 4
37 to 573. Consider the following sequences of keys.
I. 81,537,102,439,285,376,305 5 3 5 3
4 4
II. 52,97,121,195,242,381,472
III. 142,248,520,386,345,270,307
IV. 550,149,507,395,463,402,270 Number of distinct BSTs: 5
7. Suppose that the BST has been unsuccessfully Hence, the correct option is (b).
searched for key 273. Which all of the above 10. You are given the post-order traversal P of a binary
sequence list nodes in the order in which we could search tree on the n elements 1,2,3….n. You have
have encountered them in the search? [2008] to determine the unique binary search tree that has
(a) II and III only P as its post-order traversal. What is the time com-
(b) I and III only plexity of the most efficient algorithm for doing
(c) III and IV only this? [2008]
(d) III only (a) q (log n) (b) q (n)
Solution: (d) (c) q (n log n) (d) None
Add 273 to the given sequence & verify the fol- Solution: (d)
lowing properties for sequence: 11. The in-order and pre-order traversal of a binary
(i) if x, y are two consecutive numbers in the se- tree are d b e a f c g and a b d e c f g , respectively.
quence and y.x, then all numbers following x The post-order traversal of the binary tree is
should be greater than x. [2007]
(ii) if y < x , then all numbers following x should (a) d e b f g c a (b) e d b g f c a
be ≤ x. (c) e d b f g c a (d) d e f g b c a
Hence, the correct option is (d).
Solution: (a)
8. Which of the following statements is TRUE? In order ⇒ d b e a f c g
[2008] Pre order ⇒ a b d e c f g
(a) I , II and IV are in-order sequence of three dif- ↓ since a comes first in preorder root, element ⇒ a
ferent BSTs Since a is root, as per in order ⇒ left subtree of a
(b) I is a pre-order sequence of some BST with has ⇒ d be
439 as the root ⇒ Since ‘b’ is in left subtree of ‘a’ and b come next
(c) II is an in-order sequence of some BST where to a in preorder ⇒ b
121 is the root and 52 is a leaf is the left child of a.
(d) IV is a post-order sequence of some BST with Since d be e is left subtree’s inorder, b is root
149 as the root
Solution: (c) b
The in-order traversal of a BST is non-decreasing
sequence of its keys. Hence d e is left subtree
Hence, the correct option is (c).
→ In the preorder, after completing left subtree of
9. How many distinct BSTs can be constructed with root, ‘c’ is next.so.root
three distinct keys? [2008] Of right subtree ⇒ c
(a) 4
(b) 5 → In the inorder f precedes c and g succeeds.. c
(c) 6 so it will
(d) 9 c
Solution: (b)
Consider three keys 3,4,5 f g
b c
d e f c
30
60
40
20
50
30
90
40
80
50
70
60
60
two choices A Y
6 nodes left
2 choices M C P
5 nodes left
B F H
2 choices
4 nodes left Hence, the correct option is (d).
2 choices 16. Which of the following sequences of array ele-
3 nodes left ments forms a heap? [2006]
2 choices (a) {23,17,14,6,13,10,1,12,7,5}
2 nodes left (b) {23,17,14,6,13,10,1,5,7,12}
(c) {23,17,14,7,13,10,1,5,6,12}
2 choices
(d) {23,17,14,7,13,10,1,12,5,7}
1 nodes left
Solution: (c)
1 choices
{23,17,14,7,13,10,1,5,6,12}
So, there are totally 23
2*2*2*2*2*2*1 permutations are there = 26 = 64.
So, the formula = 2n−1 where n is number of nodes to 17 14
be traversed
Here n = 7 ⇒ 27−1 = 26 = 64 7 13 10 1
Hence, the correct option is (b).
5 6 12
15. The following three are known to be in pre-order,
post-order and in-order sequence of the binary Hence, the correct option is (c).
tree. But it is not known which is which.
17. Suppose that we have numbers between 1 and 100
I. MBCAFHPYK
in a binary search tree and want to search for the
II. KAMCBYPKH
number 55. Which of the following sequence can-
III. MABCKYFPH
not be the sequence of nodes examined? [2006]
Pick the true statement from the following.
(a) { 10,75,64,43,60,57,55}
[2007]
(b) {90,12,68,34,62,45,55}
(a) I and II are pre-order and in-order sequence,
(c) {9,85,47,68,43,57,55}
respectively.
(d) {79,14,72,56,16,53,55}
(b) I and III are pre-order and post-order sequence,
respectively. Solution: (c)
90
(c) II is in-order sequence. But nothing more can
be said about other two sequence 10 12
(d) II and III are the pre-order and in-order se-
quence respectively.
75 68
Solution: (d)
As we know that value at first place in pre-order 64
34
should be last value in post-order.
43
If I is pre-order, M should appear last in II or III, 62
So I is not pre-order. 60
Similarly III is not pre-order 45
So, II is pre-order and I is post-order. 57
79 19. If only the root node does not satisfied the heap
property, the algorithm to convert the complete
14
binary tree into a heap has the best asymptotic
9 time complexity of [2006]
(a) O(n) (b) O(log n)
72 (c) O(n log n) (d) O(n log log n)
85
56 Solution: (b)
47 20. If the root node is at level zero, the level of element
16
x[i], i ≠ 0, is [2006]
68 53 (a) log i
(b) log(i + 1)
43 55 (c) log(i + 1)
(d) log i
(c) not possible (d) Possible
Solution: (c)
Hence, the correct option is (c). 0 Level 1 = 2 = 21
Common Data for Questions 18, 19 and 20.
An array X of n distinct integers is interpreted as a 1 2 Level 0 = 1 = 20
complete binary tree. The index of the first element of Level 2 = 4 = 22
3 4 5 6
an array is 0.
Level 3 = 8 = 23
18. The index of parent of element x[i], i ≠ 0 7 8 9 10 11 12 13 14
[2006]
i − 2
15 16 17 18 Level 4 = 16 = 24
(a)
i
(b)
2 2 Max nodes at a level ‘l’ is 2l.
To put an element at level ‘l’, max possible ele-
(c) (d) − 1 .
i i
ments are to be placed at level ‘l−1’ i.e., 2l−1
2 2
i. e. level ‘0’ → 1
Solution: (d) level ‘1’ → 2
Complete binary tree
level ‘2’ → 4
0 level ‘3’ → 8
1 2 So the least index of an element at the level ‘l’ will
be
3 4 5 6 Indexmin = (20 + 21 + 22 +…..+ 2l−1)
( 21 − 1)
7 8 9 10 = 20 − 1= 2l − 1
2
The index of parent element of The level ‘l’ will have at most 2l elements so
x[1] = 0 indexmax will be
x[2] = 0 = (2l − 1) = (2l − 1) = 2(2l − 1)
x[3] = 1 (2l − 1) ≤ index level‘l’ ≤ 2(2l − 1)
x[4] = 1 i = (2l − 1) when index is maximum.
x[5] = 2 i + 1 = 2l
x[6] = 2 log(i + 1) = l = log((2l + 1 − 1).
i. e., for x[i] = −1
i When index is
2 Min = l < l + 1< l + 1
Hence, the correct option is (d). By applying floor operator,
So, the expression level is subtree is utmost 2. If the height of the tree is h >
[ log(i + 1)] 0, then the minimum number of nodes in the tree
Hence, the correct option is (c). is [2005]
21. Post-order traversal of a given binary search tree T (a) 2 − 1
h
(b) 2 −1 (c) 2 −1
h−1 h
(d) 2h
produces the following sequence keys. Solution: (b)
10,9,23,22,27,25,15,50,95,60,40,29 Tree with height 1 and minimum number of nodes is
Which one of the following sequence of keys can
be the result of an in-order traversal of the tree T?
[2005]
(a) 9,10,15,22,23,25,27,29,40,50,60,95
(b) 9,10,15,22,40,50,60,95,23,25,27,29
(c) 29,15,9,10,25,22,23,27,40,60,50,95
(d) 95,50,60,40,27,23,22,25,10,9,15,29
Solution: (a)
Inorder traversal of BST is non-decreasing se-
quence . And it always gives an increasing order of
elements.
Among all four options (a) is only increasing order Height 1 → 2 nodes
sequence. 2 → 2 + 1 nodes
Hence, the correct option is (a). 3→2+1+2
22. How many distinct binary search trees can be cre- 4→2+1+2+4
ated out of four distinct keys? [2005] 5→2+1+2+4+8
(a) 5 (b) 14 (c) 24 (d) 42 Height → 2 + 2h−1 −1
= 2h−1 +1
Sol: (b) Hence, the correct option is (b).
2*nCn /n + 1 = 2*4C4 / 5
25. A binary search tree contains the number
8 × 7 × 6 × 5 1,2,3,4,5,6,7,8 when the tree is traversed in pre-
= 14
4 × 3 × 2 × 5 order and values in each node printed out, the
sequence of values obtained is 5,3,1,2,4,6,8,7. If
Hence, the correct option is (b).
the tree is traversed in post-order the sequence
23. In a complete k-array tree every internal node has obtained would be [2005]
exactly k children. The number of leaves in such a (a) 8,7,6,5,4,3,2,1
tree with n internal nodes is: [2005] (b) 1,2,3,4,8,7,6,5
(a) nk (c) 2,1,4,3,6,7,8,5
(b) (n − 1)k + 1 (d) 2,1,4,3,7,8,6,5
(c) n(k − 1) + 1 Solution: (c)
(d) n(k − 1) A unique pattern tree for pre-order and in-order is
Solution: (c) generated as:
Let x be the depth of the k-array tree.
5
No of internal nodes ‘n’ = 1 + k1 + k2 +…..+ kx−1
1( k x − 1) 3 6
n=
k −1
kx = n(k − 1) + 1 1 4 8
No of leaf nodes = kx = n(k − 1) + 1
2 7
Hence, the correct option is (c).
24. In a binary tree for every node the difference Post-order traversal is 2,1,4,3,7,8,6,5.
between the number of nodes in the left and right Hence, the correct option is (c).
LAST IN: 3
LAST PRE: 6
LAST POST: 1
The value returned by the function DoSomething
Hence, the correct option is (d).
when a pointer to the root of an empty tree is
passed as argument is [2002] 32. A complete n-array tree is one in which every node
(a) The number of left node in the tree has 0 or n sons. If x is the number of internal nodes
(b) The number of right node in the tree of a completes n-array tree, the number of leaves
(c) The number of internal node in the tree in it is given by [1998]
(d) The height of the tree (a) x(n − 1) + 1 (b) xn − 1
(c) xn + 1 (d) x(n + 1)
Solution: (d)
Given routine finds height of the tree. Solution: (a)
30. The number of leaf nodes in a rooted tree nodes, When there is one internal node
with each node having 0 or 3 children is [2001]
n ( n −1)
(a) (b)
2 3
( n −1) ( 2n − 1) 1 2 ---- n
(c) (d)
2 3 => leaves = n
Solution: (b) => L1 = n
Say ‘i’ be the no of internal nodes. When there is two internal nodes
Ip be no of leaf nodes of tree having p internal
nodes.
Ii = Ii − 1 + 2 2 3 -- n
I1 = 3 1
So, Ip = 2(i − 1) + 3 n−1
i + 2(i − 1) + 3 = n
1 1 -- n
3i − 2 + 3 = n
( n −1) n
i=
3 ⇒ leaves = n + n − 1
Hence, the correct option is (b). L2 = L1 + (n−1)
31. Let LASTPOST, LASTIN and LASTPRE denote When there is three internal nodes
the last vertex visited in a post-order, in-order and ⇒leaves = n + n − 1 + n − 1
pre-order traversal respectively, of a complete L3 = L2 + (n − 1)
binary tree. Which of the following is always true? = L1 + 2(n − 1)
[2000] Lx = Lx − 1 + (n − 1)
(a) LASTIN = LASTPOST = Lx − (x − 1) + (x − 1)(n − 1)
(b) LASTIN = LASTPRE = n + (x − 1)(n − 1)
(c) LASTPRE = LASTPOST = x(n − 1) + 1
(d) None of the above Hence, the correct option is (a).
Solution: (d) 33. A binary search tree contains the values
Complete B.T. is given below 1,2,3,4,5,6,7,8. The tree is traversed in pre-order
1
and the values are printed out. Which of the fol-
lowing sequence is a valid output? [1997]
(a) 53124786
2 3
(b) 53126487
6 (c) 53241678
4 5 (d) None of the above
4 6 5
5 20 58 91
2 8
3 8 37 60
Five-marks Questions
1. (a) In a binary tree, a full node is defined to be a H 0 1 2 3 4 5 6 7 8
node with two children. Use induction on the
N(H) 1 2 4 7 12 20 33 54 88
height of binary tree to prove that the number
of full nodes plus one is equal to the number 4. A size-balanced binary tree is a binary tree in
of leaves. which for every node, the difference between the
(b) Draw the min-heap that results from insertion number of nodes in the left and right subtree is at
of the following elements in order into an ini- most 1. The distance of a node from the root to the
tially empty min-heap: 7,6,5,4,3,2,1. Show the node. The height of a binary tree is the maximum
result after the deletion of this heap. [1999] distance of a leaf node from the root.
Solution: (a) Prove, by using induction on h, that the size
(a) In any Binary tree degree of each node 3 or 1. – balanced binary tree of height h contains at
If one leaf node is converted to internal is 1, least 2h nodes.
increase in number of leaves, (b) In a size-balanced tree of height h > = 1, how
In = In + 1 many nodes are at distance h − 11 from the
I1 = 2 root? Write only the answer without any expla-
So, In = 2 + (n − 1)1 nations. [1997]
In = n + 1. Solution:
Number of leaves = number of full nodes + 1. (a) Min no of nodes for tree of height
(b) After deletion of root from above heap, the 1→2
tree will be:
2 2
4 2 3 4 3
Min no of nodes for tree of height
7 7
5 6 5 6 2→4
d
f
c c e
Min no of nodes for tree of height h → 2
g 4 + 8 +…….+ 2h − 1
= 2 + 2(2h−1 −1)
3. Derive a recurrence relation for the size of the = 2 + 2h −2
smallest AVL tree with height 8. [1998] = 2h
Solution: (b) Here no of nodes at height (h − 1) be K.
L=H=0 Up to height h − 1, the tree looks like full bi-
ì1
ï nary tree with internal nodes (K − 1).
N ( H) í2 L = H= 1 K + K – 1 = 2h − 1
min
ï1 + N( H - 1) + N( H - 2) ( L = H) > 1
î K = 2h − 1
5. What is the number of binary trees with 3 nodes the trees is one more that the number of non-leaf
which when traversed in post-order give the nodes. [1993]
sequence A, B, C? Draw all these binary trees. Solution:
[1995] Binary tree which is having one node with two de-
Solution: scendants
Post order ⇒ A, B, C
Possibilities = 5,
C
Number of leaf nodes = 2.
C B
Leaf node = non-leaf + 1
Binary tree which is having two nodes with two
A B A descendants
C C
or
B
B
A
A
So 2 − 1 = 1 leaf node added and one internal node
C
added. For increase in every internal node only one
B leaf node is increased. There is no change in rela-
A
tion between internal nodes and leaf nodes.
1 Solution:
Height of a binary tree: Height of a binary tree is the
5 18
maximum distance of all leaf nodes from root node.
7 13 25 20 AVL tree: An empty binary tree with left & right
subtree if both left and right subtree are AVL tree.
11 9 15 17 27 (i) With balance factors
1
17
(b) Give the different steps for deleting the node
with key 5 so that the structure is preserved. 0
12 0 20
[1991]
1 0
Solution: 5
0
15 18 0 24
(a) In a complete binary tree, every node stores a
0 0
value which is less than every one of its chil- 1 14 0 16
dren, so, structure is a min heap.
(b) Delete node (5) (ii) After inserting (13) So LR imbalance
2 ancestor
Remove the very last node i.e.; 27 17
Place it in the position of 5.
−1
Compare it with min (7,13) = 7 12 L 0 20
Place 27 in place of 7 and put 7 in place of 27. R
1 0
Now compare 27 with minimum of (11,9) = 9 5
1
15 18 0 24
By, Swap places of 7 and 27, we will get Heap 0 1
property. 1 14 0 16
One-mark QuestiOns
1. Suppose depth first search is executed on the graph By analyzing connected graph below:
below starting at some unknown vertex. Assume Starting time
that a recursive call to visit a vertex is made only Finishing time
after first checking that vertex has not been visited (1,10) S
earlier. Then the maximum possible recursion depth 1
(2,9)
(including the initial call) is______. [2014] A B
2 4 (7,8)
3
(3,4) C D (5,6)
Q R
Component 1 Component 2
(b) There must exist a vertex w when removal dis- # first adjacent node discovered except ‘u’ till all
connects u and v in G the adjacent nodes of u are discovered.
(c) There must exist a cycle in G containing u # Path in G having all the adjacent nodes of u con-
and v nected is to be there.
(d) There must exist a cycle in G containing u and 8. Write the adjacency matrix representation of the
all its neighbors in G. graph given in [2008]
Solution: (d) P1
Say a random node ‘u’ has some ‘n’ adjacent nodes
numbered 1 to n. For making ‘u’ as a leaf node of
P5 P2
the tree.
# First discover all the adjacent nodes of (u) and
then only come to (u).
# Say, we have first discovered the node (1). Since
if any one of them, say node p is of degree 1 it is P4 P3
already a leaf node. And it can’t be.
6 Solution:
u P1 P2 P3 P4 P5
P1 0 1 0 0 0
1 2
3
4
P2 0 0 0 1 0
P3 1 0 0 0 0
P4 0 0 1 0 1
P5 1 1 0 0 0
One-mark QuestiOns
1. Using public key cryptography, X adds digital sig- Statement 2 An encryption technique such as DES
nature s to message M, encryption <M, s > and performs a permutation on the elements of its in-
sends to Y, where it is decrypted. Which one of the put alphabet.
following sequences of the keys is used for opera- Which one of the following options is valid for the
tions [2014] above two statements? [2007]
(a) Encryption: X’s private key followed by Y’s (a) Both are false
private key (b) Statement 1 is true and other is false
Decryption: X’s public key followed by Y’s (c) Statement 2 is true and other is false
public key. (d) Both are true
(b) Encryption: X’s private key followed by Y’s Solution: (c)
public key • A hash function need not be an injective func-
Decryption: X’s public key followed by Y’s tion. Hash function generates same values for
private key. two or more keys.
(c) Encryption: X’s public key followed by Y’s • There are total 19 stages in the data encryption
private key standard algorithm. The first stage performs
Decryption: Y’s public key followed by X’s transposition on 64 bits blocks of plain text.
public key. Hence, the correct option is (c).
(d) Encryption: X’s private key followed by Y’s
3. A hash table contains 10 buckets and uses linear
public key
probing to resolve collisions. The key values are
Decryption: Y’s public key followed by Y’s
integers and hash function used is key %10. If the
public key.
values 43, 165, 62, 123, 142 are inserted in the
Solution: (d) table, in what location would the key value 142 be
Answer can be found by definition of digital signa- inserted. [2005]
ture and PKC. (a) 2 (b) 3 (c) 4 (d) 6
Hence, the correct option is (d). Solution: (d)
2. Consider the following two statements: When all elements are into hash table, picture of
Statement 1 A hash function (these are often used hash table is in linear probing. The collisions are
for computing digital signatures) is an injective resolved. This is done by putting the new element
function. into in first empty bucket.
0
twO-marks QuestiOns
1
2 62 1. Consider a hash table with 9 slots. The hash func-
tion is h(k) = k mod 9. The collisions are resolved
3 43
by chaining. The following 9 keys are inserted in
4 123 the order: 5, 28, 19, 15, 20, 33, 12, 17 and 10. The
5 165 maximum, minimum and average chain lengths in
6 142 the hash table, respectively, are [2014]
(a) 3, 0 and 1 (b) 3, 3 and 3
7
(c) 4, 0 and 1 (d) 3, 0 and 2
8
Solution: (a)
9
0
Maximum
Hence, the correct option is (d). 1 28 19 10
Five-marks Question
1. Consider a hash table with n buckets, where exter- Solution:
nal (overflow) chaining is used to resolved colli- Given that all buckets are almost of same size.
sions. The hash function is such that the probability Hash function distributes keys ideally.
1
1 (a) Probability that a key goes to a bucket =
that a key value is hashed to particular bucket is . n
n Probability that a key does not goes to bucket
The hash table initially empty and K distinct val-
ues are inserted in the table. =
( n − 1)
[1997] n
Probability that the bucket number 1 is empty
(a) What is the probability that bucket number 1 is
empty after the Kth insertion? =
( n − 1) ∗ ( n − 1) ….
K times
(b) What is the probability that no collision has n n
occurred in any of the K insertions? (b) Probability that no collision has occurred in
(c) What is the probability that the first collision any of the K insertions.
occurs at the Kth insertion? = no of favorable cases/total cases
(c) Probability that the first collision occurs in the
(a) 2 (b) 3 Kth insertion
(c) 4 (d) 6
n pk −1 × (k − 1)
=
nk
Programming Language 2 2 3 2 3 1 5 4 1 2 3 1 4 2 2 1 3 2 1 0 0 1 0 1 0 0 1 8
Concepts
Programming in C - I 0 1 0 0 0 0 1 1 2 0 0 2 1 1 0 2 2 2 4 0 1 1 0 0 1 2 0 0
Programming in C -II 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 2 2 1 1 0 1 0 1 1 2 0 0
11/19/2015 5:03:07 PM
Chapter 1
Programming
Language Concepts
{
One-mark Questions
Count + + ;
1. Consider the following program in C language Num > > = 1;
[2014] }
#include < stdio.h > Return(count);
main() }
{ The value returned by func (435) is =
int I; Solution: 9
int *pi = &I; num num
scanf(“%d”,pi) 435 00000001 10110011
printf(“%d\n”,i + 5); 101 100 Address 101 100
}
Which one of the following statements is TRUE? The expression num >> = 1[bitwise right shift
(a) Compilation fails operator is same as integer division by 2]; inter-
(b) Execution results in a run time error preting content in variable num which is shifted
(c) On execution, the value printed in 5 more than one bit right for every while loop. So, after “9”
the address of variable i times of while loop, the content in num is zero.
(d) On execution, the value printed is 5 more than 3. Suppose n and p are unsigned int variables in a
the integer value entered C program. We wish to set p to nC3.If n is large,
Solution: (d) which one of following statements is most likely
to set p correctly? [2014]
The user input is read by scan function storing it
(a) P = n * (n − 1) * (n − 2)/6;
in variable ‘i’ thus printing 5 more than the integer
(b) P = n * (n − 1)/2 * (n − 2)/3;
value entered on execution.
(c) P = n * (n − 1)/3* (n − 2)/2;
Hence, the correct option is (d). (d) P = n * (n − 1) * (n − 2)/6.0;
2. Consider the function func shown below: [2014] Solution: (b)
Intfunc (intnum) n n! n( n − 1)( n − 2)
c3 = =
{ 3!( n − 3)! 3!
Int count = 0;
While(num) n( n − 1)( n − 2) n( n − 1) ( n − 2)
= = ×
2×3 2 3
maintenance. In order to avoid spaghetti code caused (c) Differ in all cases
by over reliance on GOTO statement, indentations (d) May differ in the presence of execution
help making the logic clear encouraging program- Solution: (d)
mers to use loops and branch control structures and result obtained by call by value may differ from the
named procedures rather than GOTO statement. result of call by reference.
Hence, the correct option is (d). Hence, the correct option is (d).
10. Choose the best matching between the program- 13. The most appropriate matching for the following
ming styles in Group 1 and their characteristics in pairs [2000]
Group 2 [2004] 1. Loops 2. Pointers 3. Constants
Group 1: X: indirect addressing
P. Functional R. Object oriented
S. Imperative Q. Logic Y: immediate addressing
Group 2: Z: auto decrement addressing
1. command-based, procedural (a) X - 3 Y - 2 Z - 1
2. imperative, abstract data types (b) X - 1 Y - 3 Z - 2
3. side effect free, declarative, expression (c) X - 2 Y - 3 Z - 1
evaluation (d) X - 3 Y - 1 Z - 2
4. declarative, clausal representation, theorem Solution (c)
proving The most appropriate matching is indirect address-
(a) P - 2 Q - 3 R - 4 S - 1 ing with pointers immediate addressing with con-
(b) P - 4 Q - 3 R - 2 S - 1 stants auto decrement addressing with loops
(c) P - 3 Q - 4 R - 1 S - 2 Thus, X - 2 ;Y - 3; Z - 1.
(d) P - 3 Q - 4 R - 2 S - 1
Hence, the correct option is (c).
Solution: (d)
14. Heap allocation is required for languages [1997]
Hence, the correct option is (d). (a) That support recursion
11. Which of the following statements is FALSE? (b) That support dynamic data structures
[2003] (c) That use dynamic scope rules
(a) In statistically typed languages, each variable (d) None of above.
in a program has a fixed type Solution: (b)
(b) In un-typed languages, values do not have any
types Stack is needed by recursion, whereas heap is
(c) In dynamically type languages, variables have needed by data structure.
no types Hence, the correct option is (b).
(d) In all statically typed languages, each variable 15. What are x and y in the following macro
in a program is associated with values of only definition? [1995]
a single type during the execution of the pro- Macro Add x, y
gram Load y
Solution: (b) Mul x
values will have some type variables which may Store y
not be a part of any type. End macro
Hence, the correct option is (b). (a) Variables
12. The results returned by function under value result (b) Identifiers
and reference parameter passing conventions (c) Actual parameters
[2002] (d) Formal parameters
(a) Do not differ Solution: (d)
(b) Differ in the presence of loops Hence, the correct option is (d).
(b) Multi-level access link(or display) arrange- 5. If the programming language uses static scoping
ment is needed to arrange activation records and call by need parameter passing mechanism,
only if the programming language being the values printed by the above program are
implemented has nesting of procedures/ (a) 115, 220 (b) 25, 220
functions (c) 25, 15 (d) 115, 105
(c) Recursion in programming languages cannot be Solution: (d)
implemented with dynamic storage allocation
Global values i = 100 and j = 5 is carried by P
(d) Nesting procedures/functions and recursion
(i + j) in static scoping. So, (X + 10) will give 115
require a dynamic heap allocation scheme and
output.
cannot be implemented with a stack based al-
location scheme for activation records Hence, the correct option is (d).
(e) Programming languages which permit a func- 6. If the programming language uses dynamic scop-
tion to return a function as its result cannot be ing and call by name parameter passing mecha-
implemented with a stack based storage allo- nism, the values printed by the above program are
cation scheme for activation records (a) 115, 220 (b) 25, 220
i. b and e only ii. a, c, d only (c) 25, 15 (d) 115, 105
iii. a, b, e only iv. b, c, e only Solution: (b)
Solution: (b) Global value j = 5 and i = 10 is carried by P (i + j)
A programming language which does not permit in dynamic scoping. So, (X + 10) will give 25 as
global variables of any kind and has no nesting of output.
procedures/functions, but permits recursion can be And second print (X) takes i = 200, j = 20 produc-
implemented with static storage allocation. ing output 220.
Recursion in programming languages cannot be Hence, the correct option is (b).
implemented with dynamic storage allocation.
7. What is the printed by the print statement in the
Nesting procedures/functions and recursion program P1 assuming call by reference parameter
require a dynamic heap allocation scheme and passing? [2001]
cannot be implemented with a stack based alloca-
Program P1 ()
tion scheme for activation records.
{
Hence, the correct option is (b).
x = 10;
Common Data for Questions 5 and 6 [2003]
y = 3;
The following program fragment is written in a
programming language that allows global variables func1 (y, x, x);
and does not allow nested declaration of functions print x;
Program P2 print y;
var n: int; }
procedure W (var x: int)
begin Func1(x, y,z)
x = x + 1; {
Print x;
end y = y + 4;
procedure D z = x + y + z;
begin
}
var n: int;
n = 3; (a) 10, 3
W (n); (b) 31, 3
end (c) 27, 7
begin\\begin P2 (d) None of the above
n = 10;
D;
end;
13. Given the following Pascal like program segment (c) Passing an array element as parameter
[1997] (d) Passing an array following statements is true
Procedure A; Solution: (c)
x, y: integer; Hence, the correct option is (c).
Procedure B;
16. The value of n, output by the program PARAM is:
x, z: real; [1993]
S1 (a) 1, because m is a local variable in p
end B; (b) 0, because m is the actual parameter that
Procedure C; corresponds to the formal parameter in p
i: integer; (c) 0, because both x and y are just reference to m,
S2 and y has the value 0
end C;
(d) 1, because both x and y are just references to m
end A;
which gets modified in procedure P
Solution: (d)
The variable accessible in S1 and S2 are: if x and y are references to m, then change made in
(a) x or A, y, x of B and z in S1 and x of B, y and i ‘P’ will get affected in PARAM, so m = 1 will be
in S2 output.
(b) x or B, y and z in S1 and x of B, I and z in S2 Hence, the correct option is (d).
(c) S1, x, z of B, y of A
S2: i of C, x, y of A 17. The value of n, output by the program PARAM is
(d) None of the above [1993]
(a) 0, because n is the actual parameter corre-
Solution: (c) u se referencing environment concept. sponding to x in procedure Q
Hence, the correct option is (c). (b) 0, because n is the actual parameter to y in pro-
14. The correct matching for the following pairs is cedure Q
[1996] (c) 1, because n is the actual parameter corre-
List 1 sponding to x in procedure Q
(a) Activation record (d) 1, because n is the actual parameter corre-
(b) Location counter sponding to y in procedure Q
(c) Reference counts Solution: (b)
(d) Address relocation If ‘n’ is actual parameter to then it will print ‘0’.
List 2 Hence, the correct option is (b).
1. Linking loader 18. What is the scope of m declared in the main
2. Garbage collection program? [1993]
3. Subroutine call (a) PARAM, P, Q (b) PARAM, P
4. Assembler (c) PARAM, Q (d) P, Q
(a) A - 3 B - 4 C - 1 D - 2
(b) A - 4 B - 3 C - 1 D - 2 Solution: (c)
(c) A - 4 B - 3 C - 2 D - 1 The variable ‘m’ which is declared in PARAM is
(d) A - 3 B - 4 C - 2 D - 1 accessible in PARAM, Q but not in P as ‘P’ is con-
Solution: (d) A - 3; B - 4; C - 2; D - 1 taining local variable with the name ‘m’.
Hence, the correct option is (d). Hence, the correct option is (c).
15. In which one of the following cases is it possible 19. For the program segment given below, which of
to obtain different results for call by reference and the following are true? [1993]
call by name parameter passing methods? [1994] (a) The program leads to compile time error
(a) Passing a constant value as a parameter (b) The program leads to run time error
(b) Passing the address of an array as a parameter (c) The program outputs 5.2
(d) The program produces error relating to NIL 22. In which of the following cases is it possible to
pointer dereferencing obtain different results for call-by-reference and
Solution: (d) call-by-name parameter passing? [1989]
(a) Passing an expression as a parameter
when data is assigned to null pointer it will return
(b) Passing an array as a parameter
null pointer assignment error.
(c) Passing a pointer as a parameter
Hence, the correct option is (d). (d) Passing an array element as a parameter
20. Match the pairs in the following [1990] Solution: (d)
List 1 when an array element is passed in call by name, it
(a) Pointer data type works like call by value not by call by reference.
(b) Activation record
Hence, the correct option is (d).
(c) Repeat until
(d) Coercion 23. Consider the following program selection and
given figure which shows activation records of
List 2
procedures involved in the calling sequence
(a) Type conversion
(b) Dynamic data structure P - > s - > q - > r - > q.
(c) Recursion Write the access links of the activation records to
(d) Non deterministic loop enable correct access of variables in the proce-
Solution: A - q, B - r, C - s, D - p. dures from other procedures involved in the call-
ing sequence. [1988]
21. Match the pairs in the following [1990]
List 1 access link (a, 1)
(a) Small talk (b) LISP p
(c) Prolog (d) VAL
a, 1
List 2
p. logic programming s
q. data flow programming a, 1
r. functional programming
q
s. object oriented programming
Solution: A - s, B - r, C - p, D - q. a, 1
Note: for sub-question 09 to 11, refer to the Pascal r
program shown in below
a, 1
program PAEAM (input, output);
var m, n; integer; q
procedure P(var x, y: interger);
var m: ineger; Procedure P;
begin Procedure q;
m : = 1; Procedure r;
x:= y+1 begin
end; q;
end r;
procedure Q (x: inreger; vary: integer);
begin begin
x:= y+1 r;
end q;
end;
begin Procedure s;
m : = 0 ; P (m, m); write (m); begin
n* : = 0 ; Q (n*1, n), write (n); q;
end; end s;
s;
end p;
Solution: begin
The referencing environment in procedure ‘S’ - > x: = 3;
‘S’ and ‘P’. y: = 4
The referencing environment in procedure ‘Q’ - > P(y);
‘Q’, ‘S’ and ‘P’.
Write (x)....................(1)
The referencing environment in procedure ‘R’ - >
end;
‘R’, ‘Q’, ‘S’ and ‘P’.
begin
24. What is referential trparency? [1988]
x; = 7
Solution:
y; = 8
The evaluation of an expression should only pro-
duce value without changing the environment. Q;
25. An unrestricted use of the “go to “ statement is Write (x)....................(2)
harmful because of which of the following rea- end
sons: [1989] Hence, the correct option is (a).
(a) It makes it more difficult to verify programs
26. What will be printed by the write statements
(b) It makes program more inefficient
marked (1) and (2) in the program if variable are
(c) It makes it more difficult to modify existing
statistically scoped [1987]
program
(a) 3, 6 (b) 6, 7
(d) It results in the compiler generating longer
(c) 3, 7 (d) None
machine code
Solution: (a)
Solution: (a)
under static scoping the reference to free variable is
it makes more difficult to verify programs due to
in the environment of immediate next outer block
haphazard flow of control of GOTO statement.
(statically/lexically), therefore, the Solutionwer is
Hence, the correct option is (d). (3, 6).
Common data for questions 26 & 27 Hence, the correct option is (a).
Study the following program written in a 27. For the program given Q01 in what will be printed
block-structured language : by the write statement marked (1) and (2) if the
var x, y :integer; variable are dynamically scoped:
(a) 3,6 (b) 6,7
procedure P (n: integer);
(c) 3,7 (d) None
begin
Solution: (b)
x: = (n + 2) (n - 3);
The reference to free variable is at point of invo-
End; cation in reverse order under dynamic scoping,
procedure Q therefore, the Solutionwer is (6, 7).
var x, y :integer; Hence, the correct option is (b).
What is printed by above program if Is the implementation correct? Explain and
i) static scoping is assumed for all variables correct it if necessary. You are supposed to
ii) dynamic scoping is assumed for all variables make only small changes.
Give reasons for your Solutionwer. (b) show the activation records and the display
structure just after the procedures called at
Solution:
lines marked x and y have started their execu-
i) 2, 2, and 2 in static scope the referencing envi-
tion.Be sure to indicate which of the two pro-
ronment of free variable is in the next immedi-
cedures named you are referring to [1992]
ate outer block.
ii) 2, 5, 2 in dynamic scoping the referencing en- Program Test;
vironment of free variable is at point of invo- Procedure A;
cation. Procedure B;
5. State whether the following statements are True or Procedure A;
False with reasons of your Answer [1994] ..........
(a) A subroutine cannot always be used to replace end A;
a macro in an assembly language program begin
(b) A symbol declared as ‘external’ in assembly y: A;
language is assigned an address outside the end B;
program by the assembler itself begin
Solution: B;
(a) No; it can be replace any macro. end A;
(b) No; external symbols are resolved by linker begin
not by assembler.
x: A;
6. A stack is used to pass parameters to procedures in end Test.
a procedure call.
(a) If a procedure P has two parameters as de- Solution:
scribed in procedure definition: Procedure P
(a) call-by name
(var x: integer; y: integer); and if P is called
(b) There is a flaw in the implementation.
by; P (a, b) state precisely in a sentence what
is pushed on stack for parameters a and b 8. Consider the following pesudo code(all data items
(b) In the generated code for the body of proce- are of type integer): [1991]
dure P, how will the addressing of formal pa- Procedure P (a, b, c);
rameters x and y differ? [1993] a: = 2;
Solution: c: = a + b;
(a) The address of ‘a’ and the value of ‘b’ is end {P}
pushed onto the stack begin
(b) x is a reference to a, y is reference to b x: = 1;
7. a. What type of parameter passing mechanism y: = 5;
(call-by-value, call-by-reference, call-by-name, or z: = 100;
call-by-result) is the following sequence of actions P(x, x*y, z);
trying to implement for a procedure call P (A[i]) Write (‘x = ’, x, ’z = ’, z)
where P (i: integer) is a procedure and A is an inte- end;
ger array?
Determine its output, if the parameters are passed
3. Create a new local variable, say z
to the procedure P by
4. Assign to z the value of A[i]
i. value
5. Execute the body of P using z for A[i]
ii. reference and
6. Set A [i] to z
iii. name
10. What is the return value of the function foo when 2%2 = 0 2/2 = 1
it is called as foo (345, 10)? foo(1, 2)
(a) 345 (b) 12
1%2 = 1 ½ = 0
(c) 5 (d) 3
foo(0, 2)
Solution: ( b)
Foo(345, 10) 1 + (0)
= 345%10 = 5 345/10 = 34 1 + (0)
Foo(34, 10) 1 + (0)
= 34%10 = 4 34/10 = 3
1 + (0)
Foo(3, 10)
1 + (0)
= 3%10 = 0 3/10 = 0
Foo(0, 100) 1 + (0)
1 + (0)
3+0=3 1 + (0)
3 + (0) 4 + 3 = 7
1 + (0)
4 + (3) 5 + 7 = 12 1 + (0) therefore outpur is 2
(a) 2 2 (b) 2 1
One-mark Questions (c) 0 1 (d) 0 2
1. What does the following fragment of C program Solution: (d)
prints? [2011] the function int*p, int *q are two pointer vari-
Char c [] = “GATE 2011” ables with global function and f(&i, &j)are the
local values of the pointer variables. Here p stores
Char *p = c;
200 address and q stores 300 addresses and &i
Printf(“%s”, p + p[3] - p[1]); is pointed to p address whereas &j points to q
(a) GATE2011 (b) E2011 address. Thus, p = q then address of p and q both
(c) 2011 (d) 01 are storing at same address then i = 0, j = 2 and
Solution : (c) *p = 2 where after *p and *q both stores at same
The ASCII values of p[3] which is E and p[1] location where same values are printed. First *p =
which is ‘A’ gets subtracted, therefore, the differ- 0 after *p = 2, thus, output is 0 2.
ence from ‘A’ to ‘E’ is 4. Hence, the correct option is (d)
Hence, the correct option is (c) 3. What does the following C-statement declare?
Thus, p + 4 is ‘2004’ assuming ‘p’ to be 2000; thus [2005]
the output is 2011. int (*f)(int *)
2. What does the following program print? [2010] (a) A function that takes an integer pointer as
argument and returns an integer
#include < stdio.h >
(b) A function that takes an integer as argument
Void f (int *p, int*q){ and returns an integer pointer
P = q (c) A pointer to a function that takes an integer
*p = 2; pointer as argument and returns an integer
(d) A function that takes an integer pointer as
}
argument and returns a function pointer
Inti = 0, j = 1;
Solution: (c) int (*f) (int *);
Int main () {
Syntax pointer to function is for declaration of
F(&i, &j) return_type(*ptr variable)(list of arguments);
Printf (“%d %d\n”, i, j); Hence, the correct option is (c)
Return 0;
}
Assume that objects of the type short, float and Solution: I (d)
long occupy 2 bytes, 4 bytes and 8 bytes respec- If the variables are static then it is persisting previ-
tively. The memory requirements for variable t, ous state value from destruction of various func-
ignoring alignment considerations is tion calls. The variable ‘a’ in prtFunc() is static,
(a) 22 bytes (b) 14 bytes i.e., its global life time retains its value always
(c) 18 bytes (d) 10 bytes [2000] leading to history sensitive.
Solution: (c) Hence, the correct option is (d)
short S [5] takes 10 bytes and union takes ‘8’ bytes 2. What output will be generated by the given code
so total 18 bytes. segment if :
Hence, the correct option is (c) Line 1 is replace by auto int a = 1;
Line 2 is replaced by register int a = 2;
Two-marks Questions (a) (b)
3 1 4 2
Common Data for Questions 1 and 2
4 1 6 1
Consider the following C code segment
4 2 6 1
Inta, b, c = 0;
(c) (d)
Void prtfun(void);
4 2 4 2
Main()
6 2 4 2
{
2 0 2 0
Static int a = 1;//Line1
Solution: (d)
prtFunc();
The auto variables will initialized in every func-
printf(“\n %d %d”, a, b); tion call. Since the variable are all auto storage
} class their lifetime is local.
Void prtFun(void) Hence, the correct option is (d)
Static int a = 2;//Line 2 3. What is printed by the following C program?
Int b = 1; [2008]
a + = + + b; Intf(intx, int *py, int **ppz)
printf(“\n %d %d”, a, b); {
} [2012] Inty, z;
1. What output will be generated by the given code ** ppz + = 2;z = *ppz
segment? *py + = 2; y = *py;
(a) (b) X + = 3;
3 1 42 Returnx + y + z;
4 1 61 }
4 2 61 Void main ()
(c) (d) {
4 2 31 Int c, *b, **a;
6 2 52 C = 4; b = &c;a = &b;
2 0 52 Printf(“%d”, f(c, b, a));
}
Solution: }
in main () function, one has to pass ad dress of x = [P3] int *g(void)
5 to the function p () and in p () x = 7 is passed to {
Q ().So print (z) gives an output 12 and print(x) in
Int *px
p (), prints 7 where print (x) in main will print 6.
Px = (int*)malloc(size of (int));
7. Consider the following three C functions [2001]
*px = 10;
[P1] int *g(void)
Return (px);
{
}
Int x = 10;
Which of the above three functions are likely to
Return (&x);
cause problems with pointers?
} (a) Only P3 (b) Only P1 and P3
[P2] int *g(void) (c) Only P1 and P2 (d) P1, P2 and P3
{ Solution: (c)
Int *px Dangling pointer problem is created by P1
Int *px = 10; Uninitialized pointer problem is created by P2
Return (px); Hence, the correct option is (c)
1 Mark Questions 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 4 1 3 0 1 2 2 2 3 2 0 3 7
2 Marks Questions 0 0 0 3 1 0 0 0 0 3 3 0 2 3 4 4 3 4 0 3 3 1 1 1 2 1 0 3
5 Marks Questions 0 0 0 3 1 0 0 0 0 2 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0
Total Marks 0 0 0 21 7 0 0 0 0 16 7 0 5 7 9 17 12 16 0 7 8 4 4 5 6 2 3 13
Number Systems 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 3 1 2 0 0 0 0 1 1 0 0 1 2
Boolean Algebra 0 0 0 3 1 0 0 0 0 1 3 0 1 1 0 4 1 3 0 1 2 2 1 2 2 0 1 4
K-Maps 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 0 1 0 1
Combinational Circuits 0 0 0 1 0 0 0 0 0 2 0 0 0 0 1 1 1 0 0 1 2 0 0 1 0 0 1 1
Sequential Circuits 0 0 0 1 1 0 0 0 0 1 0 0 0 1 2 0 1 2 0 2 1 0 1 0 2 0 0 2
11/19/2015 11:17:42 AM
chapter 1
Number Systems
One-mark QuestiOns
1. Consider the equation (123)5 = (x8)y with x and y 2. The base (or radix) of the number system such that
as unknown. The number of possible solutions is the following equation holds is
[2014] [2014]
Solution: (123)5 = 1 × 5 + 2 × 5 + 3 × 5
2 1 0 312
= 13.1.
= 25 + 10 + 3 = 38. 20
(x8)y = x × y + 8.
Solution: (312)x = (20)x(13.1)x, where x is radix or
Since (123)5 = (x8)y. base (1).
⇒ 38 = xy + 8. ⇒ 3x2 + x + 2 = (2x + 0) (x + 3 + x−1).
⇒ xy = 30 (1). 1
⇒ 3x2 + x + 2 = (2x) x + 3 + .
Natural number solutions of equation (1) are x
x y ⇒ 3x2 + x + 2 = 2x2 + 6x + 2.
1 × 30 ⇒ x2 − 5x = 0.
2 × 15 ⇒ x (x − 5) = 0.
3 × 10 ⇒ x = 0 or x = 5.
5 × 6 Since digits used in equation (1) are 0, 1, 2 and 3,
the base must be greater than 3.
6 × 5 ∴ x = 5 is the solution.
10 × 3
3. The smallest integer that can be represented by an
15 × 2 8-bit number in 2’s complement form is
30 × 1 [2013]
Out of these, we consider only those in which (a) −256 (b) −128
ly > 8, (∵ base > digits appearing). (c) −127 (d) 0
4. P is a 16-bit signed integer. The 2’s complement However, magnitude of number = −5 (∵ MSB of
representation of P is (F87B)16. The 2’s comple- 2’s complement = 1).
ment representation of 8 * P is [2010] Consider option (a).
(a) (C3D8)16 (b) (187B)16 2’s complement of (11100111) = 00011000 + 1
(c) (F878)16 (d) (987B)16 = 00011001 = (25)d.
Solution: (a) Magnitude of number = −25.
(F87B)16 = 1111 1000 0111 1011. −25 is divided by −5
8 * (F87B) = 23 * (F87B)16 Hence, the correct option is (a).
= right shift operation by 3 digits 8. The decimal value 0.25 [2002]
= 1100 0011 1101 1000 (a) Is equivalent to binary 0.1
= (C3D8)16. (b) Is equivalent to binary 0.01
Hence, the correct option is (a). (c) Is equivalent to binary 0.00111
(d) Cannot be represented precisely in binary
5. (1217)8 is equivalent to [2009]
Solution: (b)
(a) (1217)16 (b) (028F)16
In binary numbers, if 0 or 1 is written after decimal
(c) (2297)10 (d) (0B17)16
point, the place value decreases in the order of 2−1,
Solution: (b) 2−2,… and so on while converting from binary to
(1217)8 = (0010 1000 1111)2 (∵ to convert from decimal.
octal to binary, each digit to expanded into its (0.25)d = 2−2, and binary of 2−2 is represented as
3 digit binary equivalent, and to convert from 0 0 1
binary to hexadecimal, groups of 4 are created) ↓ ↓ = 0 × 2−1 + 1 × 2−2.
= (28 F)16.
2 −1 2 −2
Hence, the correct option is (b).
Hence, the correct option is (b).
6. 73x (in base-x number system) is equal to 54y (in 9. The 2’s compliment representation of the decimal
base-y number system), the possible values of x value −15 is [2002]
and y are [2004] (a) 1111 (b) 11111
(a) 8, 16 (b) 10, 12 (c) 111111 (d) 10001
(c) 9, 13 (d) 8, 11
Solution: (d)
Solution: (d) In case of negative decimal numbers, the conver-
7x + 3 = 5y + 4 sion into 2’s complement form is done using the
or 7x = 5y + 1. following steps:
The possible combination for x and y is 8 and 11 (a) Write the magnitude of number into its binary.
respectively. (15)d = (1111)b.
Hence, the correct option is (d). (b) Find 1’s complement of the binary equivalent
7. Assuming all numbers are in 2’s complement and add 1 to it,
representation, which of the following number is i.e., (1111)6 → (0000)6 + 1 = (0001)b.
divisible by 11111011? [2003] (c) The 2’s complement representation of −15 =
(a) 11100111 (b) 11100100 10001.
(c) 11010111 (d) 11011011 1 is put in the MSB position since the number is
Solution: (a) negative.
All numbers are given in 2’s complement represen- Hence, the correct option is (d).
tation. The MSB is 1 which means that the numbers 10. Sign extension is the step in [2002]
are negative. (a) Floating point multiplication
To get magnitude of numbers, perform 2’s comple- (b) Signed 16 bit integer addition
ment of numbers. (c) Arithmetic left shift
2’s complement of (11111011) = 00000100 + 1 (d) Converting a signed integer from one size to
= 00000101 = (5)d. another.
One-mark QuestiOns
1. Consider the following combinational function 2. The dual of a Boolean function F(X1, X2, ..., Xn
block involving four Boolean variables x, y, a, b ‘+, −,′), written as FD, is the same expression as
where x, a, b are inputs and y is the output. that of F with + and swapped. F is said to be self-
dual if F = FD. The number of self-dual functions
with n Boolean variables is [2014]
(a) 2 n
(b) 2 n−1
(c) 2 2n
(d) 22n−1
Solution: (d)
Dual of Boolean function F = Fs.
Self dual exists if F = FD.
n
Number of functions with n Boolean variables = 22 .
Then number of self dual functions with n variables
Which one of the following digital logic blocks is = 22 n−1.
the most suitable for implementing this function? Hence, the correct option is (d).
[2014] 3. Consider the following Boolean expression for F:
(a) Full adder (b) Priority encoder F(P, Q, R, S) = PQ + PQR + PQRS.
(c) Multiplexer (d) Flip-flop The minimal sum-of-products form of F is
Solution: (c) (a) PQ + QR + QS (b) P + Q + R + S
x output = y (c) P + Q + R + S (d) PR + P RS + P
1 a [2014]
0 b Solution: (a)
This truth table can be implemented using a MUX F ( P, Q , R , S ) = PQ + PQR + PQRS .
with x being the select line like: Constructing, the k-map for the given function
RS
PQ 00 01 11 10
a 2XI y 00
b MUX
01 1 1 1
11 1 1 1 1
10
X
x y Q (a) (b) (c) (d) Hence, the option (d) is not equivalent to 2-input
0 0 1 1 1 1 0 XNOR gate.
0 1 0 0 0 0 1 6. The simplified SOP (Sum of Product) form of the
(
Boolean expression P + Q + R . P + Q + R . P + Q + R )( )( )
( )( )( )
1 0 0 0 0 0 1
P + Q + R . P + Q + R . P + Q + R is
1 1 0 0 0 0 0
[2011]
Hence, the option (d) is not representing NOR of
x and y. (a) ( P ⋅ Q + R)
5. Which one of the following circuits is NOT equiv-
alent to a 2-input XNOR (exclusive NOR) gate (b) ( P + Q R)
[2011] (c) ( P ⋅ Q + R)
(a)
(d) ( P Q + R)
(b) Solution: (b)
( P + Q + R )( P + Q + R)( P + Q + R )
(c) = ( P ⋅ Q ⋅ R) + PQR + PQR
= PQ( R + R ) + PQR
= PQR + PQR
(d)
= PR(Q + Q )
= P ( RQ )
= P + RQ.
Solution: (d)
Hence, the correct option is (b).
The characteristic equation of XNOR gate is given
by 7. The minters expansion of f ( P , Q, R ) = PQ + QR + P R
A B = A B + A B. f ( P , Q, R ) = PQ + QR + P R is [2010]
(a) m2 + m4+ m6 + m7
Considering the options, (b) m0 + m1 + m3 + m5
∆ (c) m0 + m1 + m6 + m7
A⊕B l A⊗
(a) A • B (d) m2 + m3 + m4 + m5
B
Solution: (a)
A A
(b)
AB + AB = A ⊕ B A⊗
• B F ( P , Q, R) = PQ + QR + PR
B B = PQ( P + R ) + QR ( P + P ) + PR (Q + Q ).
A
10 1 1
C
⇒ f = xz + xz .
B f depends on 2 independent variables x and z.
Therefore, minimum number of gates required = 3. Hence, the correct option is (b).
Hence, the correct option is (b). 11. The Boolean function x′y′ + xy + x′y is equivalent
9. Given f1, f3, and f in canonical sum of products to [2004]
form (in decimal) for the circuit. (a) x ′ + y ′
f1 = Σm(4, 5, 6, 7, 8) (b) x + y
f3. = Σm(1, 6, 15) (c) x + y′
f = Σm(1, 6, 8, 15) (d) x′ + y
Then f2 is Solution: (d)
f1 x′y′ + xy + x′y
f2 = ?
f = xy′ + xy + xy
= x′ (y + y′) + xy
= x′ (1) + xy
f3
= x′ + xy
[2008]
= x′ + y.
(a) Σm(4, 6) (b) Σm(4, 8)
Hence, the correct option is (d).
(c) Σm(6, 8) (d) Σm(4, 6, 8)
Solution: (c) 12. Let * be defined as
f = f1 f2 + f3. x * y = x + y , Let z = x * y .
⇒ Σm(1, 6, 8, 15) = f1 f2 + Σm(1, 6, 15). Value of z * x is [1997]
⇒ f1 f2 must contribute additional min term 8. (a) x + y (b) x
f1 f2 = f2 (Σm(4, 5, 6, 7, 8)). (c) 0 (d) 1
f2 must have 8. It can have any of (1, 6, or 15). Solution: (b)
From amongst the options,
f2 = Σm(6, 8). x*y = x + y (given)
Hence, the correct option is (c). z = x*y = x + y (1)
z *x = z + x Solution: (a)
= x +y +x (from (1)) P P+Q = P.Q
= x ⋅y + x (∵ A + B = A ⋅ B using Q (P +Q) (Q +R ) = Q + PR
De Morgan’s law ) Q
R Q+R = QR
= x ⋅y + x (∵ A = A ) f
= x ( y + 1)
P
=x (∵ A + 1 = 1).
R
Hence, the correct option is (b). Q (P +R) (Q+R ) = R + PQ
R
twO-marks QuestiOns F = Q + PR ⋅ R + PQ
= Q( P + R ) ⋅ R( P + Q )
1. Let ⊕ denote the exclusive OR(XOR) opera-
tion. Let ‘1’ and ‘0’ denote the binary constants. = Q ⋅ R = Q + R.
Consider the following Boolean expression for F
over two variables P and Q: F(P,Q) = [(1⊕ P) ⊕ Hence, the correct option is (a).
(P ⊕ Q) ⊕ (P ⊕ Q) ⊕ (Q ⊕ 0)] The equivalent
3. If P, Q, and R are Boolean variables, then (P + Q)·
expression for F is [2014]
(P· Q + P·R)· ( P ⋅ R + Q ) simplifies to
(a) P + Q (b) P + Q
[2008]
(c) P ⊕ Q (d) P ⊕ Q (a) P· Q (b) P· R
Solution: (d) (c) P· Q +R (d) P·R+ Q
F(P, Q) = (1 ⊕ P)[(P ⊕ Q) ⊕ (P ⊕ Q)] ⊕ (Q ⊕ O)
= (1 ⊕ P) ⊕ O ⊕ (Q ⊕ O) Solution: (a)
= (1 ⊕ Q) ⊕ (P ⊕ O)
= (Q) ⊕ (P) ( P + Q )( PQ + P ⋅ R)( P ⋅ R + Q )
=P⊕ Q = ( PQ + PR + PQ + PRQ )( P ⋅ R + Q )
= P ⊕ Q. = P ( P + Q )(Q + R)( P + Q )( R + Q )
Hence, the correct option is (d).
= P (Q + RPR ) = P ⋅ Q.
2. What is the Boolean expression for the output f of
the combinational logic circuit of NOR gates given Hence, the correct option is (a).
below? [2010]
4. Let f(w, x, y, z) = Σ(0, 4, 5, 7, 8, 9, 13, 15). Which of
P the following expressions are NOT equivalent to f ?
Q
[2007]
Q (P) x′y′z′ + w′xy′ + wy′z + xz
R (Q) w′y′z′ + wx′y′ + xz
f
(R) w′y′z′ + wx′y′ + xyz + xy′z
(S) x′y′z′ + wx′y′ + w′y
P
R (a) P only
Q (b) Q and S
R (c) R and S
(d) S only
(a) Q + R (b) P + Q
Solution: (d)
(c) P + R (d) P + Q + R f(w, x, y, z) = Σ (0, 4, 5, 7, 8, 9, 13, 15).
yz in w, x, y, z
wx 00 01 11 10
5 0 1 0 1
00 1
1 1 3 2 7 0 1 1 1 ↓ differ in 2 bit positions,
∴ in between 1111 they exist
01 1 1 1 1 (15 )
4 5 7 6
11 1 0 1 1 ↑ in between 1010,1011 and
11 1 1 1 (10 ) (11)
12 13 15 14
1111,1101 must ok
(15 ) (13 )
10 1 1
8 9 11 10
12 1 1 0 0
Consider P = x′y′z′ + w′xy′ + wy′z + xz 13 1 1 0 1
= Σm(0, 8, 4, 5, 13, 9, 7, 15) 15 1 1 1 1
= f. to cover the entire set, f must include the min-
∴
Q = w′y′z′ + wx′y′ + xz term 10 additionally.
= Σm(0, 4, 8, 9, 5, 7, 13, 15) yz
= f. wx 00 01 11 10
f3 = ? D
f1,(w, x, y, z) = Σ 8, 9, 10 E
f2(w, x, y, z) = Σ 7, 8, 12, 13, 18, 15
f (w, x, y, z) = Σ(8, 9) (a) Y = A BC + DE (b) Y = ABC + DE
The function f3 is [1997]
(c) Y = A BC ⋅ DE (d) Y = ABC·DE
(a) Σ9, 10 (b) Σ9
(c) Σ1, 8, 9 (d) Σ8, 10, 15 Solution: (c)
Solution: (b) A ABC
f1 (w, x, y, z) = Σm(8, 9, 10). B
C
f2 (w, x, y, z) = Σm(7, 8, 12, 13, 16, 15).
Output of AND gate f3 (w, x, y, z) = Σm(8).
f(w, x, y, z) = Σn(8, 9).
∴ f3 = input of OR gate = Σm(8, 9) or Σ m(9).
D
Hence, the correct option is (b).
13. Let f ( x , y , z ) = x + yx + xz be a switching E DE
function. Which one of the following is valid?
[1997] Y = ABC ⋅ DE = ABC + DE (∵ the open collectors
(a) yx is a prime implicates of f tied together behave as a wired AND gate).
(b) xz is a minters of f Hence, the correct option is (c).
Five-marks Questions
1. A circuit outputs a digit in the form of 4 bits. 0 The non-inverting buffers have delays d = 4 ns as
is represented by 0000, 1 by 0001, … 9 by 1001. shown in the figure. Both XOR gates and all wires
A combinational circuit is to be designed which have zero delay. Assume that all gate inputs, outputs
takes these 4 bits as input and outputs 1 if the digit and wires are stable at logic level 0 at time 0. If the
≥ 5, and 0 otherwise. If only AND, OR and NOT following waveform is applied at input A, how many
gates may be used, what is the minimum number transition(s) (change of logic levels) occur(s) at B dur-
of gates required? [2004] ing the interval from 0 to 10 ns? [2003]
(a) 2 (b) 3 Logic 1
(c) 4 (d) 5
Solution: (b) A
Logic 0
A B C D output
Time 0 1 2 3 4 5 6 7 8 9 10 11 ns
0 0 0 0 0
0 0 0 1 0 (a) 1 (b) 2
0 0 1 0 0 (c) 3 (d) 4
0 0 1 1 0 Solution: (d)
0 1 0 0 0 Waveforms are as follows:
0 1 0 1 1
t 0 to 10
0 1 1 0 1
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
A 1
k-map implementation
CD
AB 00 01 11 10
Output 1 0
00
01 1 1 1 Output 2
1 2 3 4
11 X X X X
10 1 1 X X
A
⇒ Output = A + BC + BD
Output 1 Output 2
= A + B(C + D).
Minimum number of gates required = 3. There are four transitions
f = ABC + A B C [1990]
z
Solution: F = ABC + A BC.
4. A logic network has two data inputs A and B, and
two control inputs C0 and C1. It implements the BC
function F according to the following Table. A 00 01 11 10
C1 C0, F 1 0 0
0 0
0 0 A+B
0 1 A+B 1 0 0 1 0
1 0 A⊕B
1 1 AB F = ( A + C ) ⋅ ( A + B ) ⋅ ( B + C ).
Implement the circuit using one 4 to 1 Multiplexer,
one 2-input Exclusive OR gate, one 2-input AND 7. Show with the help of a block diagram Boolean
gate, one 2-mput OR 1 and one inverter. [1996] function:
f = AB + BC + CA can be realized using only 4:1
Solution:
multiplexer. [1990]
A
I0 Solution:
B
I1 F = AB + BC + CA
4XI
A
MUX A B C F
I2
B
0 0 0 0
A
I3 C1 C0
B 0 0 1 0
0 1 0 0 f = Σm(3, 5, 6, 7)
0 1 1 1 ⇒C
5. Find the minimum sum of products form of the
logic function 1 0 0 0
f(A, B, C, D) 1 0 1 1 ⇒C
= Σd(3, 11, 12, 14) + Σm(0, 2, 8, 10, 15)
1 1 0 1 ⇒ 10
Where m and d denote the minterms and don’t 1 1 1 1 ⇒1
cares respectively [1991]
Solution: A4 × 1 MUX has only 2 select lines (A and B) and
f(A, B, C, D) C will be the inputs to MUX.
= Σd(3, 11, 12, 14) + Σm(0, 2, 8, 10, 15)
CD O I0
AB 00 01 11 10
00 1 1 X 1 BD C I1
f (A,B,C)
01 C I2
11 X 1 X AC
1 I3 S1 S2
10 1 X 1
f = AC + BD.
A B
One-mark QuestiOns
1. Consider the following minterm expression of F: ab
00 01 11 10
F(P, Q, R, S) = Σ0, 2, 5, 7, 8, 10, 13, 15 cd
The minterms 2, 7, 8 and 13 are ‘do not care’ 00 1 1 1
terms. The minimal sum-of-products form for F is
01 X
[2014]
(a) QS + QS 11 X
(b) QS + QS 10 1 1 X
(c) QRS + QRS + QRS + QRS (a) b·d + a·d
(d) PQS + PQS + PQS + PQS (b) a ⋅ d + b ⋅ d + a ⋅ b ⋅ d
Solution: (b) (c) b ⋅ d + a ⋅ b ⋅ d
F(P, Q, R, S) = Σm(0, 5, 10, 15) + Σd(2, 7, 8, 13). (d) a ⋅ b + b ⋅ d + a ⋅ a ⋅ d
RS Solution: (a)
PQ 00 01 11 10
ab
00 1 X 00 01 11 10
cd
00 1 1
01 1 X
11 X 1 01 X 1
11 X 1
10 X 1
In SOP form, 10 1 1 X
F = QS +QS . F = ad + pd
Hence, the correct option is (b). Hence, the correct option is (a).
2. In the Karnaugh-map shown below, X denotes a 3. Minimum SOP for f (w, x, y, z) shown in Karnaugh-
don’t care term. What is the minimal form of the map below is [2002]
function represented by the Karnaugh-map? (a) xz + y ′z (b) x z′ + z x′
[2008] (c) x′ y + z x′ (d) None
(a) xy + y′z 00 0 0 0
(b) wx ′y ′ + xy + xz
(c) w′x + y′z + xy 01 X X X
(d) xz + y
11 0 0
Solution: (a)
wx 10 0 0
yz 00 01 11 10
00 X X
In POS form, F = (A + C) · (C + D) (C + D).
Hence, the correct option is (b).
01 X 1 X 1
11 X 1 twO-marks QuestiOns
1. What is the minimal form of the Karnaugh-map
10 1 X
shown below? Assume that X denotes a don’t care
term. [2012]
11 00 X 0
10 1 X
01 0 X 0
ab
cd 00 01 11 10 11 X X 0
00 1 X X 1
10 X 0 0 X
01 X 1
11 In POS form,
f = ( z + w ) ⋅ ( z + y ) ⋅ ( x + w )( x + y + w ).
10 1 X
Literal count = 9.
Hence, the correct option is (c).
f = bd + bc.
3. Which function does NOT implement the
2. The literal count of a Boolean expression is the Karnaugh map given below? [2000]
sum of the number of times each literal appears
wz
in the expression. For example, the literal count 00 01 11 10
xy
(xy + yz) is 4. What are the minimum possible literal
counts of the product-of-sum and sum-of-product 00 0 X 0 0
representations respectively of the function given
by the following Karnaugh-map? Here, X denotes 01 0 X 1 1
“don’t care”. [2003]
zw 11 1 1 1 1
xy 00 01 11 10
10 0 X 0 0
00 X 1 0 1
01 0 1 X 0 (a) (w + x) y
(b) xy + yw
11 1 X X 0 (c) ( w + x )( w + y )( x + y )
(d) None of the above
10 X 0 0 X
Solution: (d)
(a) (11, 9) (b) (9, 13) wz
(c) (9, 10) (d) (11, 11) xy 00 01 11 10
Solution: (c) 00 X
zw
xy 00 01 11 10 01 X 1 1
00 X 1 1
11 1 1 1 1
01 1 X
10 X
11 1 X X
10 X X
In SOP form, f = xy + wy
= (w + x) y.
wz AB
xy 00 01 11 10 CD 00 01 11 10
00 0 X 0 0 00 1 1
01 0 X 01 1 1
11 11 1 1
10 0 X 0 0 10 1 1
One-mark QuestiOns
1. In the following truth table V = l if and only if, the Solution: (b)
input is valid. P Q R Output = f
INPUTS OUTPUTS 0 0 0 0 ⇒R
D0 D1 D2 D3 X0 X1 V 0 0 1 1
0 0 0 0 X X 0 0 1 0 1
1 0 0 0 0 0 1 0 1 1 0 ⇒R
X 1 0 0 0 1 1 1 0 0 1
X X 1 0 1 0 1 1 0 1 0 ⇒R
X X X 1 1 1 1 1 1 0 0 ⇒R
What function does the truth table represent? 1 1 1 1
[2013] f = PQR + PQR + PQR + PQR
(a) Priority encoder (b) Decoder = P (QR + QR ) + P (QR + QR)
(c) Multiplexer (d) Demultiplexer
= P ( Q ⊕ R) + P ( Q R)
Solution: (a)
A priority encoder uses a valid bit to set priorities = P ⊕ Q ⊕ R.
while encoding. Hence, the correct option is (b).
Hence, the correct option is (a). 3. How many 3 to 8 decoders with an enable input
2. The Boolean expression for the output f of the are needed to construct to constant 6 to 64 line
multiplexer shown below is [2010] decoder without using any other logic gates
(a) P ⊕ Q ⊕ R (b) P ⊕ Q ⊕ R [2007]
(c) P + Q + R (d) P + Q + R (a) 7 (b) 8
(c) 9 (d) 10
R 0 Solution: (c)
R 1 4×1 To construct 6 × 64 decoder, one 3 × 8 decoder
0
R 2 S must be used such that its output connects the en-
R S 0 able input of 8 decoders which in total can produce
3 1
64 outputs.
∴ number of decoders required = 1 + 8 = 9.
Hence, the correct option is (c).
PQ
Solution: (c)
twO-marks QuestiOns (n − 1) variables will be connected to select lines.
∴ site of MUX = 2n−1.
1. Consider the 4-to-1 multiplexer with two select Hence, the correct option is (c).
lines S1 and S0 given below
3. Consider the circuit above. Which one of the
0 0 following options correctly represents f(x, y, z)?
1 1 4 –to–1 x
F 0 MUX
R 2 Multiplexer
1
R 3 S1 S0 y
z 0 MUX
f
P Q 1
x
1 0 I2 = y
1 1 I3 = y
Tabulating for different values of x, y and z d4 d3 d2 d1 dφ
C 0 Ain Bin
4 to 1
C 1 Cin
multiplexer 1
C 2 f
C 3 2 bit full adder 2
S1 S0 sum
VCC
A B
C0 S1 S0
(a) A BC + ABC + A BC
(b) A + B + C
One-mark QuestiOns
1. Let k = 2n. A circuit is built by giving the output (a) f D D
of an n-bit binary counter as input to an n-to 2n-bit
decoder. This circuit is equivalent to a Q
[2014] CLK
(a) k-bit binary up counter (b) f D D
(b) k-bit binary down counter
(c) k-bit ring counter
CLK
(c) k-bit Johnson counter
Solution: (c)
k = 2n
(c) f D Q D
The output of n bit binary counter is given to n to
2n decoder as input. This would cause the outputs
to change from d0, d1, d2, d3, …dn, i.e., the overall CLK
circuit will act as bit ring counter with outputs as
dk dk−1 … d2 d1 d0 (d) f D D
0 0 … 0 0 1
0 0 … 0 1 0 Q
CLK
0 0 … 1 0 0
− − … − − − Solution: (b)
A NOT gate delays the phase of f by 180° with Q
− − … − − − output, delay in phase = 0° or 360° with Q output,
0 1 … 0 0 0 delay in phase of f = 180°. In option b, delay in
1 0 … 0 0 0 phase = 180° (due to NOT gate only).
Hence, the correct option is (b).
2. You are given a free running clock with a duty 3. SR latch is made by cross coupling two NAND
cycle of 50% and a digital waveform f which gates if S = R = 0, then it will result in [2004]
changes only at the negative edge of the clock. (a) Q = 0, Q′ = l
Which one of the following circuits (using clocked (b) Q = l, Q′ = 0
D flip-flops) will delay the phase of f by 180°? (c) Q = 1, Q′ = 1
[2006] (d) Indeterminate state
Present
Solution: (d)
state J2 K2 J1 K1 J0 K0 Next state
If PQR has value 010, output of NOR = 1.
Q2 Q1 Q0 Q2 Q1 Q0 ∴ Q = 1, output of AND gate = 0. At next clock
0 0 0 1 0 0 1 0 1 1 0 0 pulse, P Q R = 011 in next cycle.
1 0 0 1 0 1 0 0 1 1 1 0 4. Given the following state table of an FSM with two
1 1 0 0 0 1 0 1 1 1 1 1 states A and B one input and one output:
Common Data for Questions 2 and 3: [2011] Present Present Next Next
Consider the following circuit involving three D State State State State
type flip-flops used in a certain type of counter A B Input A B Output
configuration. 0 0 0 0 0 1
0 1 0 1 0 0
P
1 0 0 0 1 0
D Q
1 1 0 1 0 0
Clock 0 0 1 0 1 0
Q
0 1 1 0 0 1
Q 1 0 1 0 1 1
D Q
1 1 1 0 0 1
Q
If the initial state is A = 0, B = 0, what is the mini-
mum length of an input string which will take the
D Q machine to the state A = 0, B = 1 with output =1?
Clock [2009]
Q
(a) 3 (b) 4
(c) 5 (d) 6
Input
T1 Q2 X T1 Q1
0 0 1 1
Assume that the counter and gate delays are neg- MSB LSB
ligible. If the counter starts at 0, then it cycles
through the following sequences: [2007]
To complete the circuit, the input X should be
(a) 0, 3, 4 (b) 0, 3, 4, 5
[2004]
(c) 0, 1, 2, 3, 4 (d) 0, 1, 2, 3, 4, 5
(a) Q2 (b) Q2 + Q1
Solution: (c) (c) (Q1 ⊕ Q2) (d) Q1 ⊕ Q2
When the counter outputs 0101, all inputs are
cleared, counting sequence is 3, 4, 0, 1, 2, 3, 4, … Solution: (d)
Hence, the correct option is (c). 6 Q2 Q1 T1 = 0/P of xbR Input of 2nd FF = x
6. Consider the circuit in the diagram. The ⊕ opera- CLK
0 0 1
tor represents EX-OR. The D flip-flops are initial-
ized to zeros (cleared). 1 1 0 0 0
2 1 1 1 1
3 0 1 0 0
Q D Q D Q D data 4 0 0 1 1
q2 q1 q0
x = T1′= Q1 Q 2 = Q1 ⊕ Q 2 .
CLK
Hence, the correct option is (d).
The following data: 100110000 is supplied to the 8. A 1-input, 2-output synchronous sequential circuit
“data” terminal in nine clock cycles. After that the behaves as follows. Let Zk, nk denote the number of
values of q2q1q0 are [2006] 0’s and 1’s respectively in initial k bits of the input
(Zk + nk = k). The circuit outputs 00 until one of the Hold time is the time interval after the clock where
following conditions holds. data must be held stable that it can be propagated.
• Zk = nk + 2. In this case, the output at the k-th and Setup time = 20ns and hold time = 0ns.
all subsequent clock ticks is 10. When the second clock cycle comes, X = 1, Q1 = 0
• nk = Zk + 2. In this case, the output at the k-th and (setup time Q will be small as earlier value of Q)
all subsequent clock ticks is 01. and Q1 = 1.
What is the minimum number of states required
Output of AND gate = 1.
in the state transition graph of the above circuit?
[2003] D2 = 1 ⇒ Q2 = y = 1.
(a) 5 (b) 6 Hence, the correct option is (a).
(c) 7 (d) 8 10. Consider the circuit given below with initial state
Solution: (a) Q0 = 1, Q1 = Q2 = 0. The state of the circuit is given
The state transition graph is as follows by the value of 4Q2 + 2Q1 + Q0.
1/00
0/00 B 0/10 01/10
A C
1/00
D0 Q0 D1 Q1 D2 Q2
D 01/01
0/00 E
1/01
Minimum number of states required are 5.
LSB MSB
Hence, the correct option is (a).
9. Consider the following circuit with initial state
Clock
Q0 = Q1 = 0. The D Flip-Flops are positive edge
triggered and have set up times 20 nanosecond and Which one of the following is the correct state
hold times 0. sequence of the circuit? [2001]
(a) 1, 3, 4, 6, 7, 5, 2 (b) 1, 2, 5, 3, 7, 6, 4
D Q Y
X D (c) 1, 2, 7, 3, 5, 6, 4 (d) 1, 6, 5, 7, 2, 3, 4
Clock Q1
clock Solution: (b)
C Clock XOR gate
Consider the following timing diagrams of X and cycles Q2 Q1 Q0 output = D0 4Q2 + 2Q1 + Q0
C; the clock period of C > 40 nanosecond which 0 0 0 1 0 1
one is the correct plot of Y? [2001]
1 0 1 0 1 2
C 2 1 0 1 1 5
3 0 1 1 1 3
X
4 1 1 1 0 7
(a)
5 1 1 0 0 6
(b) 6 1 0 0 1 4
7 0 0 1 0 1
(c)
∴ correct sequence of state = 1, 2, 5, 3, 7, 6, 4, 1.
(d) Hence, the correct option is (b).
Solution: (a) 11. The following arrangement of master-slave flip
Q0 = Q1 = 0. flop has the initial state of P, Q as 0, 1 (respec-
Setup time is the interval before the clock is tively). After three clock cycles the output states
applied, where data must be held stable. P, Q is (respectively). [2000]
J K D
‘1’ J0 Q0 J1 Q1 J2 Q2
CLK K0 Ck K1 Ck K2 Ck
(a) 1,0 (b) 1,1 CLK
(c) 0,0 (d) 0, 1 [1991]
Solution: (b) Solution:
Propagation delay through each flip flop & AND
J K Pt D Qt gate = 10 ns.
Clock Tclk = one clock pd
cycles 1 1 0 0 1 ≥ Tff + Tcombinational circuit
1 1 1 1 1 1 ≥ 10 + (10 + 10 + 10)
2 1 1 0 0 0 ↓ ↓
3 1 1 1 1 1 amc clock For 3AND gates
is applied to
Hence, the correct option is (b).
all ffs
12. Find the maximum clock frequency at which the
counter in figure, can be operated. Assume that the ≥ 40 ns.
propagation delay through each flip-flop and each 1 103
Max m clock frequency = = MHz = 25 MHz.
AND gate is 10 ns. Also assume that the setup time 40 ns. 40
Five-marks Questions
1. Consider the synchronous sequential circuit in States follow the order:
figure S4 → S2 → S5 → S6 → S7 → S3 → S1.
The missing state is S0.
2. For the synchronous counter shown in figure write
D1 Q1 D2 Q2 D3 Q3 the truth table of Q0, Q1 and Q2 after each pulse
starting from Q0 = Q1 = Q0 = 0 and determine
CK CK CK
the counting sequenced also the modulus of the
counter.
Clock
Computer Arithmetic 0 0 0 1 0 0 0 0 0 2 1 0 2 0 0 2 1 2 2 1 1 1 0 0 0 1 0 1
Memory Organization 0 0 0 1 0 0 0 0 3 2 0 0 1 0 2 0 0 1 2 5 3 4 2 3 1 3 2 6
Pipeline 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 1 1 1 1 1 1 4 1 1 1 1 1 3
CPU Organization 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 2 2 3 1 4 0 3 0 0 1 0 1 2
Control Unit Design 0 0 0 0 0 0 0 0 0 0 0 0 1 0 2 1 0 0 2 0 0 0 0 0 0 0 1 0
I/O Organization 0 0 0 0 0 1 0 0 1 1 1 2 1 1 1 1 0 3 3 0 0 0 1 0 2 0 0 0
Secondary Memories 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 1 2 0 1 0 1 0
Register Allocation 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 4 0
11/19/2015 6:44:07 PM
Chapter 1
Computer Arithmetic
15 14 8 7 0 Solution: (b)
In given data ExOr gate is not available so for one
ExOr gate 2 level network is needed because com-
plemented and uncomplemented inputs are avail-
Sign Bit Excess-64 Mantisa able .
Exponent So, delay is 2 + 2 + 2 = 6
In the above first 2 is for first ExOr gate
4. Mantissa is a pure fraction in sign-magnitude from.
Second 2 is for CLG
The decimal number 0.239 × 213 has the following
hexadecimal representation without normalization Third 2 is for 2nd ExOr gate.
and rounding off Hence, the correct option is (b)
(a) 0A 20 (b) 11 34 7. The following is a scheme for floating point num-
(c) 4D D0 (d) 4A E8 ber representation using 16 bits [2003]
Solution: (d)
15 14 9 8 0
In non-normalized from
S e m
0.00111101 × 213
e = 13, b = 64, so e = 77 = 1001101
M = 00111101
Sign Bit Excess-64 Mantisa
0100110100111101 = 4D3D Exponent
Hence, the correct option is (d)
5. The normalized representation for the above for- Let s, e and m be the numbers represented in binary
mat is specified as follows. The mantissa has an in sign exponent and mantissa fields respectively.
implicit preceding the binary (radix) point. Assume Then the floating point number represented is
that only 0’s are padded in while shifting in a field. (-1)s (1 + m × 2-9)2e-31, if the exponent ≠ 111111
The normalized representation of the above (0.239
0 otherwise
× 213 ) is
(a) 0A 20 (b) 11 34 What is the maximum difference between two suc-
(c) 4D D0 (d) 4A E8 cessive real numbers representable in this system?
Solution: (d) [2003]
Implicit normalized form is 1.11101 × 210. (a) 2-40 (b) 2 -9
(c) 222 (d) 231
M = 11101000, e = 10, b = 64
E = 74 = 1001010 Solution: (c)
0100101011101000 = 4AE8 Max exponent is 62 Biasing = 31 and given expo-
nent value is -9. So maximum difference between
Hence, the correct option is (d)
such successive integers is 262 - 31 -9 = 222.
6. A 4-bit carry look ahead adder, which adds two
Hence, the correct option is (c)
4-bit numbers is designed using AND, OR, NOT,
NAND, NOR gates only. 8. Sign extension is the step in [2002]
(a) Floating point multiplication
Assuming that all the inputs are available in both
(b) Signed 16-bits integer addition
complemented and uncomplemented forms and
(c) Arithmetic left shift
delay of each gate is one time unit, what is the
(d) Converting a signed integer from one size to
overall propagation delay of the adder? Assume
another
that the carry network has been implemented using
two-level AND-OR logic. [2004] Solution: (d)
(a) 4 time units (b) 6 time units Sign extension is used for converting smaller size
(c) 10 time units (d) 12 time units signed data to larger size by padding the sign bit to left.
Hence, the correct option is (d)
9. The number of full and half adders required to add 11. Consider the following floating point number
two 16-bit numbers is: [1999] representation
(a) 8 half adder, 8 full adders
(b) 1 half adder, 15 full adder Exponent Mantissa
(c) 16 half adder, 0 full adder
(d) 4 half adder, 12 full adder 31 24 23 0
M ← Multiplicand (8)
1. State the booth’s algorithm for multiplication of Q ←Multiplier (8)
two numbers. Draw a block diagram for the imple- Q−1← 0; A ← 000...0 (8)
mentation of the Booth’s algorithm from multi- Count 8
plication for determining the product of two 8-bit
signed numbers. [1990] 10
Q0Q−1
01
Solution:
A← A−M A←A+M
Booth’s algorithm is used for fast multiplication 00, 11
algorithm and no correction is needed for the final
result.
Initially Q register is used for storing multiplier Arithmetic
and finally it is used for storing the partial result. Right Shift
AQQ-1
Count ← Count − 1
No
Count = 0
Yes
Result
AQ (16)
Stop
Set 0 can accommodates blocks 0, 2, 4, 6, 10 and (ii) How many bits are needed to represent the
12 onwards. TAG, SET and WORD fields?
Set 1 can accommodates blocks 1, 3, 5, 7 and 11 Solution:
onwards. No. of blocks = 128
Seq 8, 12, 0, 12, 8 can be mapped by set 0 only. Block size = 256(8) bit words
By LRU, No. of compulsory misses = 2 Set size = 4 blocks
No. of conflict misses = 2 No. of sets, S = 128/4 = 32
Total number of misses = 4 (a) MM size = 16, 384 × 256 words
Hence, the correct option is (c) = 222 word
26. A block-set associative cache memory consists of Physical address = 22 bits
128 blocks divided into four block sets. The main (b) Physical Address = TAG + SET off SET +
memory consists of 16, 384 I blocks and each WORD
block contains 256 eight-bit words. [1990] Word field size = 8-bits, set field size = 5-bits,
(i) How many bits are required for addressing the so TAG size = (22 - 8 - 5) = 9-bits
main memory?
of this program, the time (in ns) needed to com- forwarding is used in the pipeline. What is the
plete the program is [2013] number of clock cycles needed to execute the fol-
(a) 132 (b) 165 lowing sequence of instructions?
(c) 176 (d) 328 Instruction
Solution: (b) 10: MULR2, R0, R1
Pipeline clock = Max (stage delay + Over head) 11: DIV R5, R3, R4
= Max (5, 7, 10, 8, 6) + 1 = 1ns 12: ADD R2, R5, R2
CPU gets target address after completion of branch 13: SUB R5, R2, R6 [2010]
instruction in EX stage only. (a) 13 (b) 15
(8 + (5 - 1))*11 ns + 6 + 8 + 11 + 8 = 165 ns. (c) 17 (d) 19
Hence, the correct option is (b) Solution: (b)
5. Consider an instruction pipeline with four stages 1 2 3 4 5 6 7
(S1, S2, S3 and S4) each with combinational IF ID OF PO WO
MUL R0, R1 R0 * R1 R2 8 9 10 11 12 13
circuit only. The pipeline registers are required
between each stage and at the end of the last stage. IF ID OF PO WO DIV
R3, R4 R3/R4 R5
Delays for the stages and for the pipeline registers 14
are as given in the figure. IF ID OF PO WO
ADD R2 R2 15
IF ID OF PO WO SUB
Pipeline Register (Delay 1 ns)
R5
1: Loops Solution:
2: Pointers Word size = 32-bit
3. Constants [2000] No of CPU register = 64 = 26
(a) X-3, Y-2, Z-1 (b) X-1, Y-3, Z-2 So, register of 6-bits size are needed.
(c) X-2, Y-3, Z-1 (d) X-3, Y-l, Z-2
Instruction Opcode size is 32 bits.
Solution: (c)
Number of supporting instructions = 45, so min
Indirect addressing mode is for pointers and imme- 6-bits are needed.
diate addressing mode is used for constant access.
Instruction is having with operation part , reg1,
Hence, the correct option is (c) reg2 and immediate operand.
The range of unsigned operand with 14-bit is 0 to
Two-marks Questions 214 - 1.
∴ Max unsigned integer is 16383.
1. Consider two processors P1 and P2 executing the 3. Consider a hypothetical processor with an instruc-
same instruction set. Assume that under identical tion of type LW Rl, 20 (R2), which during execu-
conditions, for the same input, a program running tion reads a 32-bit word from memory and stores it
on P2 takes 25% less time but incurs 20% more in a 32-bit register Rl. The effective address of the
CPI (clock cycles per instruction) as compared to memory location is obtained by the addition of a
the program running on P1 if the clock frequency constant 20 and the contents of register R2. Which
of P1 is 1GHZ, then the clock frequency of P2 (in of the following best reflects the addressing mode
GHZ) is____. [2014] implemented by this instruction for the operand in
Solution: memory? [2013]
Here P1 and P2 ate two processors with the differ- (a) Immediate addressing
ence in time taken for instruction and CPI. (b) Register addressing
(c) Register indirect scaled addressing
• P2 takes 25% less time than P1; that is if a task
(d) Base or indexed addressing
completed by P1 is 1 unit time, for that same task
P2 takes 0.75 unit times only. Solution: (d)
• P2 takes 20% more CPI then P1, i.e., if P1 takes Here R2 will act as base or index register and 20 is
one clk cycle for completion of one instruction, the displacement.
at the same time, clk cycle P2 completes the 1.2 Hence, the correct option is (d)
instruction. 4. On a non-pipelined sequential processor, a pro-
So, frequency design for P2 is 1.2/0.75 = 1.6 gram segment, which is a part of the interrupt ser-
∴ P2 frequency must be 1.6 times more than P1 vice routine, is given to transfer 500 bytes from an
frequency. I/O device to memory. Initialize the address regis-
ter .
That is, P1 frequency is GHz , P2 frequency is 1.6
GHz. Initialize the count to 500
2. A machine has a 32-bit architecture, with 1-word LOOP: Load a byte from device
long instruction. It has 64 registers, each of which Store in memory at address given by address
is 32-bits long. It needs to support 45 instructions, register
which have an immediate operand in addition to Increment the address register
two register operands.
Decrement the count
Assuming that the immediate operand is an
If count! = 0 go to LOOP
unsigned integer, the maximum value of the imme-
diate operand is [2014] Assume that each statement in this program is
equivalent to a machine instruction which takes
one clock cycle to execute if it is a non-load/store
The content of each of the memory locations from If the first interrupt occurs at INC R3 instruction,
2000 to 2010 is 100. The program is loaded from then first the instruction is executed and PC con-
the memory location 1000. All the numbers are in sists of 1024, which is stored in stack.
decimal. Hence, the correct option is (c)
8. Assume that the memory is word addressable. The 11. Consider a three word machine instruction ADD A
number of memory references for accessing the [R0], @ B
data in executing the program completely is
The first operand (destination) “A [Ro]” uses
(a) 10 (b) 11
indexed addressing mode with R0 as the index
(c) 20 (d) 21
register. The second operand (source) “@B” used
Solution: (d) indirect addressing mode. A and B are memory
Let the data at memory 3000 is 10. addresses residing at the second and the third
The content of R3 is 2000. words, respectively. The first word of the instruc-
tion specifies the opcode, the index register desig-
The content of memory location from 2000 to
nation and the source and destination addressing
2010 is 100.
modes. During execution of ADD instruction, the
The number of memory reference accessing data two operands are added and stored in the destina-
is: tion (first operand).
Instruction Operation No. of memory refers The number of memory cycles needed during the
execution cycle of the instruction is [2005]
MOV R1, 5000 R1 ← M [3000] 1
(a) 3 (b) 4
MOV R2,R3 R2 ← M [R3] 10
(c) 5 (d) 6
Add R3 (R2) M [R3] ← R2 10
Solution: (b)
Total number of memory references is 21. In instruction execution cycle, to get the first oper-
Hence, the correct option is (d) and through index addressing mode, it takes one
machine cycle. To get the second operand through
9. Assume that the memory is word addressable. indirect mode (B), it takes two more machine cycle
After the execution of this program, the content of because B is the address.
memory location 2010 is
(a) 100 (b) 101 After the addition is completed, the result is to
(c) 102 (d) 110 send to destination with the help of index address-
ing mode, which requires one more machine cycle.
Solution: (a)
So, total of four machine cycles are required to
As the memory locations are incremented from execute the above instruction.
2000 to 2009, R3 consists of 2010 when the loop
is terminated whose contain will be 100 only. Hence, the correct option is (b)
Hence, the correct option is (a) Common Data Question 12 and 13
10. Assume that the memory is byte addressable and Consider the following program segment for a
the word size is 32-bits. If an interrupt occurs dur- hypothetical CPU having three user registers R1,
ing the execution of the instruction “INC R3”, R2 and R3.
what return address will be pushed on to the stack? Instruction Operation Instruction size
(a) 1005 (b) 1020 MOV R1, 5000 :R1← Memory[5000] 2
(c) 1024 (d) 1040
MOV R2,(R1) :R2 ← Memory[R1] 1
Solution: (c)
Add R2,R3 : R2 ← R2+R3 1
Program loaded from memory location 1000 MOV 6000, R2 :Memory[6000] ← R2 2
onwards. The word size is 32-bit. The memory size
HALT Machine halts 1
is addressable.
12. Let the clock required for various operations be as flag is set
follows: SUBC, #1 ; C ← C-1
Register to/from memory transfer: RRC A, # 1 ; right rotate A
3 clock cycles through carry by one bit.
Add with both operand in register: Thus, if the initial values of A and the carry flag
1 clock cycle are a7... a0 and
Instruction fetch decode: C0 respectively, their values after the execution of
2 clock cycle this instruction will be c0a7... a1 and a0, respectively.
The total number of clock cycle required to exe- JC Y ; jump to Y if carry
cute the program is flag is set
(a) 29 (b) 24 JMP Z ; jump to Z
(c) 23 (d) 20
Y: ADD B, # 1 ; B ← B + l
Solution: (b)
JMP Z ; jump to Z
I1 (7) I2 (5) I3 (3) I4 (7) I5 (2) = 24 clock
X:
(4 + 3) + (2 + 3) + (2 + 1) + (4 + 3) + (2 + 0)
14. Which of the following instructions when inserted
FD E FD E FD E FD E FD E FD E at location X will ensure that the value of register
Hence, the correct option is (b) A after program execution is the same as its initial
13. Consider that the memory is byte addressable with value?
word size 32-bits, and the program has been loaded (a) RRC A, #1
starting from memory location 1000(decimal). If (b) NOP : no program
an interrupt occurs while the CPU has been halted (c) 1 RC A, # 1; left rotate A through carry flag by
after execution the HALT instruction, the return one bit
address (in decimal) saved in the sack will be (d) ADD A, #1
(a) 1007 (b) 1020 Solution: (a)
(c) 1024 (d) 1028 Extending the previous question , if the contents
Solution: (d) of register A is rotated right once again, and then
PC holds the address 1028. register A will remain its value.
I1 1000 - 1007 Therefore, the instruction at X will be RRC A, #1.
I2 1008 - 1011 Hence, the correct option is (a)
I3 1012 - 1015 15. If the value of register A is A0 , the value of register
B after the program execution will be
I4 1016 - 1023
(a) The number of 0-bits in A0
I5 1024 - 1027 (b) the number of 1-bits in A0
Hence, the correct option is (d) (c) A0
Common Data for Question 14 and 15 [2003] (d) 8
Consider the following assembly language pro- Solution: (b)
gram for a hypothetical processor. A, B and C are Register A is rotated 8 times. During each rotation
8-bit registers. The meanings of various instruc- operation , if carry flag is set the value of register B
tions are shown as comments. is incremented, after 8 rotations B register contains
MOV B, # 0 ; B ← 0 the number of 1’s in register A.
MOV C, #8 ; C ← 8 Hence, the correct option is (b)
Z: CMPC, #0 ; compare C with 0 16. Which is the most appropriate match for the items
in the first column with the items in the second
JZ X ; jump to X if zero
column?
JMP S4 Z:…
S3: INC A
1. a) Initially, Rl, R2, and R3 contain the values 5,
DAA
0, and 0. respectively. What are the final values of
MOV E, A R1 and R3 when control reaches Z?
S4:… (a) 5, 2 (b) 5, 0
(a) For the two pairs (B-44. C = 25) and (B = 33, (c) 2, 2 (d) 0, 2
C = 46) at S1, Solution: (d)
(i) Find the values in register A when control Hence, the correct option is (d)
reaches S2. …..(1) 1. b) In general, if R1, and R2, and R3 initially
(ii) Find the values in registers D and E when contain the values n, 0, and 0 respectively, what is
control reaches S4. ... (2) the final value of R3 when control reaches Z?
(b) What in general, is the value of D and E as a [1999]
function of B and C when control reaches S4? (a) It counts the number of zeros in ;, binary
[2000] representation ‘n’
(b) It counts number of l’s in binary !l representa-
Solution:
tion of ‘n’.
a) The program performs BCD subtractions (c) It counts number of bits in binary in represen-
(99-C) + B = B-1 tation of ‘n’
i) B = 44 ; C = 25 (d) It gives always ‘n’ output.
ii) B = 33; C = 46 Solution: (b)
b) i) 19, 0, 0 Hence, the correct option is (b)
ii) 86, 0
4. The microinstructions stored in the control mem- (b) Hardwired control, horizontal microprogram-
ory of a processor have a width of 26-bits. Each ming, vertical microprogramming
microinstruction is divided into three fields: a (c) Horizontal micro-programming, vertical mi-
micro-operation of 13-bits, a next address field(X), cro-programming, hardwired control
and a MUX select field(Y). There are 8 status bits (d) Vertical micro-programming, horizontal mi-
in the inputs of the MUX. cro-programming, hardwired control
Solution: (b)
Load Fastest control unit is hard-wired control unit and
Control
Address Register vertical microprogramming control unit is the
Increment slowest.
Hence, the correct option is (b)
MUX Control
Memory 7. Consider the following data path of a simple non-
8 Y pipelined CPU. The registers A, B, A1, A2, MDR,
13
X the bus and the ALU are 8-bit wide. SP and MAR
Status bits
are 16-bit registers. The MUX is of size 8 x (2:1)
Micro-operations and the DEMUX is of size 8 x (1:2). Each memory
How many bits are there in the X and Y fields and operation takes 2 CPU clock cycles and uses MAR
what is the size of the control memory in number (Memory Address Register) and MDR (Memory
of words? [2004] Data Register). SP can be decremented locally.
(a) 10, 3, 1024 (b) 8, 5,256
(c) 5, 8, 2048 (d) 10,3, 512
Solution: (a) A A B A MUX DEMUX
1:2 1:2
Total size of micro instruction = 26 bits
Size of micro operation = 13 bits Dcr MAR MDR
Total inputs for the multiplexer (status bit) input =
8
So the multiplexer selection lines field (Y) = 3 bits Hi/Low Set
The number of bits in the next address field size The CPU instruction “push r”, where r = A or B,
(X) = 13 - 3 = 10 bits has the specification M[SP] + - r SP < - SP - 1.
Size of control memory = 210 = 1024. How many CPU clock cycles are needed to exe-
cute the “push r” instruction? [2001]
Hence, the correct option is (a) (a) 2 (b) 3
5. Horizontal micro programming [2002] (c) 4 (d) 5
(a) does not require use of signal decoders. Solution: (a)
(b) results in larger-sized micro instructions than SP is decremented locally; Memory operation
vertical micro programming. needs 2 clocks
(c) uses one bit for each control signal. Hence, the correct option is (a)
(d) All of the above
8. The main difference (s) between a CISC and
Solution: (d)
a RISC processor is/are that a RISC processor
Hence, the correct option is (d)
typically [1999]
6. Arrange the following configurations for CPU in (a) has fewer instructions.
decreasing order of operating speeds: Hardwired (b) has fewer addressing modes.
control, vertical microprogramming, horizontal (c) has more registers.
microprogramming [2001] (d) is easier to implement using hard-wired
(a) Hardwired control, vertical microprogram- control logic.
ming, horizontal microprogramming
Solution: All the given points are true.
Solution: (c)
One-Mark Questions
A CPU generally handles an interrupt by checking
1. A computer handles several interrupt sources. Which the interrupt register after finishing the execution
of the following are relevant for this question? of the current instruction.
• Interrupt from CPU temperature sensor (raises Hence, the correct option is (c)
interrupt if CPU temperature is too high) 3. Normally user programs are prevented from han-
• Interrupt from Mouse (raises interrupt if the dling I/O directly by I/O instructions in them. For
mouse is moved or a button is pressed) CPUs having explicit I/O instructions, such I/O
• Interrupt from Keyboard (raises interrupt protection is ensured by having the I/O instruc-
when a key is pressed or released) tions privileged. In a CPU with memory mapped
• Interrupt from Hard Disk (raises interrupt I/O, there is no explicit I/O instruction. Which one
when a disk read is completed) of the following is true for a CPU with memory
Which one of these will be handled at the mapped I/O? [2005]
HIGHEST priority? [2011] (a) I/O protection is ensured by operating system
(a) Interrupt from Hard Disk routine(s)
(b) Interrupt from Mouse (b) I/O protection is ensured by a hardware trap
(c) Interrupt from Keyboard (c) I/O protection is ensured during system con-
(d) Interrupt from CPU temperature sensor figuration
Solution: (d) (d) I/O protection is not possible
CPU first takes care about its temperature. Solution: (a)
Hence, the correct option is (d) Hence, the correct option is (a)
2. A CPU generally handles an interrupt by executing 4. Which one of the following is true for a CPU
an interrupt service routine [2009] having a single-interrupt request line and single-
(a) as soon as an interrupt is raised. interrupt grant line? [2004]
(b) by checking the interrupt register at the end of (a) Neither vectored interrupt nor multiple-inter-
fetch cycle. rupting devices are possible.
(c) by checking the interrupt register after finish- (b) Vectored interrupts are not possible but multi-
ing the execution of the current instruction. ple interrupting devices are possible.
(d) by checking the interrupt register at fixed time (c) Vectored interrupts and multiple interrupting
intervals. devices are both possible.
(d) Vectored interrupt is possible but multiple in-
terrupting devices are not possible.
interface reads a 4 byte word from the memory in For 20K bit takes = 2 ms
each DMA cycle. Memory cycle time is 40 nsec. CPU frequency is 600 MHz
The maximum percentage of time that the CPU
T = 10 - 6 / 600 = 10/6 ns
gets blocked during DMA operation is [2005]
(a) 10 (b) 25 For initialize it takes 300 clk = 500ns(10x300/60)
(c) 40 (d) 50 For completing 900 clk = 1500 ns(10x900/6)
Solution: (b) Total CPU time is 2000ns = 2µs
Disk rotation speed = 3000rp = 50 rps Processor consumes 2 µs each 2 msec.
The data that can be read/write per track = 512 KB ∴1000th time in percentage it is 0.1%
The data that can be read/write in one second = Hence, the correct option is (c)
512 KB*50 tracks 5. A graphics card has on board memory of 1 MB.
The time taken to read/write one byte data from/to Which of the following modes can the card not
the disk = (1/512 KB*50) = 38.14 nsec support? [2000]
Memory cycle time = 40nsec (a) 1600 × 400 reSolutionution with 256 colours
on a 17 inch monitor
During one DMA cycle 4 bytes of data is used
(b) 1600 × 400 reSolutionution with 16 million
from memory.
colours on a 14 inch monitor
Time taken to transfer the 4 bytes of data the disk (c) 800 × 400 reSolutionution with 16 million
= 4* 38.14 = 152.56 n sec colours on a 17 inch monitor
The maximum % of time the CPU is busy during (d) 800 × 400 reSolutionution with 256 colours
DMA cycle on, a 14 inch monitor
= 40 nsec*100/512.56 n sec Solution: (b)
= 26% Hence, the correct option is (b)
Hence, the correct option is (b) 6. RAID configurations of disks are used to provide
4. A Hard disk with a transfer rate of 10Mbytes/ [1999]
second is constantly transferring data to memory (a) Fault-tolerance
using DMA. The processor runs at 600MHz and (b) High speed
takes 300 and 900 clock cycles to initiate and com- (c) High data density
plete DMA transfer, respectively. The size of the (d) None of the above
data transfer is 20 KB. What is the % of processor Solution: (a and b)
time consumed for this operation? [2004] RAID is a storage technology. It combines mul-
(a) 10% (b) l% tiple disk drive components into a logical unit.
(c) 0.1% (d) 0.01% RAID configurations of disks are used to provide
Solution: (c) fault-tolerance and high speed.
Transfer rate = 10K bytes/sec Hence, the correct option is (a and b)
For 10K bytes it takes 1 msec
(The time to transfer data from the disk block once 5. For a magnetic disk with concentric circular tracks,
the head has been positioned at the start of the the latency is not linearly proportional to the seek
block may be neglected.) [2011] distance due to [2008]
(a) 0.50 s (b) 1.50 s (a) non-uniform distribution of requests.
(c) 1.25 s (d) 1.00 s (b) arm starting and stopping inertia.
Solution: (b) (c) higher capacity of tracks on the periphery of
Given seek time = 10ms the platter.
(d) use of unfair arm scheduling policies.
RPM = 6000, RPS = 100.
Solution: (b)
On revolution takes 10 ms
∴Average rotational delay = 5ms The seek latency is not linearly proportional to the
seek distance to arm starting and stopping inertia.
(Transfer delay is neglected)
Hence, the correct option is (b)
T access/one library = t seek + t rotational + t transfer
= 10ms + 5 ms + 0 6. A hard disk with a transfer rate of 10 Mbytes/
second is constantly transferring data to memory
= 15ms
using DMA. The processor runs at 600 MHz, and
So, for 100 libraries loading, it takes 1.5 ms × 100 takes 300 and 900 clock cycles to initiate and com-
= 1500 ms = 1.5 sec plete DMA transfer, respectively. If the size of the
Hence, the correct option is (b) transfer is 20 Kbytes, what is the percentage of
Common Data for Questions 3 and 4 processor time consumed for the transfer opera-
A hard disk has 63 sectors per track, 10 platters tion? [2004]
each with 2 recording surfaces and 1000 cylinders. (a) 5.0% (b) 1.0%
The address of a sector is given as a triple (c.h.s) (c) 0.5% (d) 0.1%
where c is the cylinder number, h is the surface Solution: (d)
number and s is the sector number. Transfer rate = 10K bytes/sec
Thus, the 0th sector is addressed as (0, 0, 0), the 1st For 10 K bytes it takes 1 msec
sector as (0, 0, 1) and so on. For 20 K bit takes = 2ms
3. The address (400, 16, 29) corresponds to sector CPU frequency is 600 MHz
number
(a) 505035 (b) 505036 T = 10 - 6 /600 = 10/6 ns
(c) 505037 (d) 505038 For initialize, it takes 300 clk
Solution: (c) = 500ns(10/6 × 300)
The address (400, 16, 29) corresponds to the Sector For completing 900 clk = 1500 ns(10 × 900/6)
number = (cylinder no. × no. of sector/cylinder) + Total CPU time is 2000ns = 2µs
(surface no. × no. of sector/track) + present sector Processor consumes 2 µs for each 2 msec.
number
∴ 1000th time in percentage is 0.1%
= (400 × 20 × 63) + (16 × 63) + 29 = 505037
Hence, the correct option is (d)
Hence, the correct option is (c)
7. A certain moving arm disk-storage, with one head,
4. The address of 1039th sector is has the following specifications:
(a) (0, 15, 31) (b) (0, 16, 30)
(c) (0, 16, 31) (d) (0, 17, 31) Number of tracks / recording surface = 200
Solution: (c) Disk rotation speed = 2400 rpm
1039/ 63 × 20: 0th cylinder Track storage capacity = 62, 500 bits
1039/63: 16th surface and remainder gives sector The average latency of this device is P msec and
number: 31 (0, 16, 31) the data transfer rate is Q bits/sec.
Hence, the correct option is (c) Write the values of P & Q. [1991]
Solution: P = 12.5 ms
T = 200, RPM = 2400, RPS = 40 Q = Data transfer rate = No. of bits /sec
Track capacity = 62, 500 bits In one second it can complete 40 tracks
One revolution time is 25ms ∴ Q = 40 × 62500 bits/sec = 2500000 bits/sec
Average latency time = 12.5ms
Solution: (b)
Two-marks Questions
We need to minimize spills to memory (writes) as
Common Data for Questions 1 and 2: [2013] variables d, e are only used in else part. So, we can
move d, e instruction inside else.
The following code segment is executed on a pro-
cessor which allows only register operands in its The code, we get is c = a + b;
instructions. Each instruction can have at most x=c * c
two source operands and one destination operand. if(x > a)
Assume that all variables are dead after this code {
segment.
Y = a * a;
c = a + b;
}
d = c * a;
else
e = c + a;
{
x = c * c;
d = c * a;
if(x > a)
d = d * d;
{y = a * a;
e = e * e;
} else
}
{
Assume: Register R1 and R2 already hold a & b,
d = d * d; respectively.
e = e * e; We will first calculate the number of memory spill
} the machine code is equivalent to
1. Suppose the instruction set architecture of the pro- R2 ← R1 + R2 (c = a + b)
cessor has only two registers. The only allowed Write R2 to memory (So memory has
compiler optimization is code motion, which value of c)
moves statements from one place to another while
preserving correctness. What is the minimum R2 ← R2 * R2 ( x = c * c)
number of spills to memory in the compiled code? If (R2 > R1) (x > a)
(a) 0 (b) 1 {
(c) 2 (d) 3 R2 ← R1 * R1 (y = a * a)
}
Software Engineering 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 4 0 3 3
11/19/2015 3:30:35 PM
Chapter 1
Software Engineering
the process. In each phase, one or more features
One-mark Questions of the product are implemented after resolving
any associated risks through prototyping. The
1. Match the following: [2014]
exact number of loops of the spiral is not fixed and
1. Waterfall model
varies from one project to another.
2. Evolutionary model
3. Component-based software engineering Hance, the correct option is (b)
4. Spiral development 2. Which one of the following is TRUE? [2014]
(a) Specifications can be developed incrementally (a) The requirements document also describes
(b) Requirements compromises are inevitable how the requirements that are listed in the
(c) Explicit recognition of risk document are implemented efficiently.
(d) Inflexible partitioning of the project into stages (b) Consistency and completeness of functional
(a) l-a, 2-b, 3-c, 4-d requirements are always achieved in practice.
(b) l-d, 2-a, 3-b, 4-c (c) Prototyping is a method of requirements vali-
(c) l-d, 2-b, 3-a, 4-c dation.
(d) l-c, 2-a, 3-b, 4-d (d) Requirements review is carried out to find the
Solution: (b) errors in system design.
The waterfall model which is also called as classic Solution: (c)
life cycle model or one shot or once through model ‘Prototyping is method of requirements validation’
begins with customer specification of require- is true since prototype serves as a mechanism for
ments and progresses through planning, modeling, identifying software requirements.
construction and deployment. Hence, waterfall
Hance, the correct option is (c)
model relates with inflexible partitioning of the
project into stages. 3. In the context of modular software design, which
one of the following combinations is desirable?
Evolutionary software models are iterative. They
[2014]
are characterized in manner that enables the soft-
(a) High cohesion and high coupling
ware engineers to develop increasingly more com-
(b) High cohesion and low coupling
plete version of software.
(c) Low cohesion and high coupling
Component-based software engineering relates to (d) Low cohesion and low coupling
specifications can be developed incrementally.
Solution: (b)
Spiral model relates to incremental style of
Cohesion is defined as a measure of internal
develop and the ability to handle various types of
strength within the module. Coupling is a qualitative
risks. Each loop of the spiral is called a phase of
measure of the degree to which classes are con- 5. A company need to develop digital signal processing
nected to one another. In the context of modular software for one of its newest inventions. The software
software design, high cohesion and low coupling is expected to have 4000 lines of code. The company
is desirable. needs to determine the effort in person-months needed
Hance, the correct option is (b) to develop this software using basic COCOMO model.
The multiplicative factor — for this model — given
4. A company needs to develop a strategy for soft-
as 2.8 for the software development on embedded
ware product development for which it has a
systems. While the exponentiation factor is given
choice of two programming language L1 and L2.
as 1.20. What is the estimated effort in person
The number of Lines Of Code (LOC) developed
months? [2011]
using L2 is estimated to be twice the LOC devel-
(a) 234.25 (b) 932.50
oped with L1, the product will have to be main-
(c) 287.80 (d) 122.40
tained for five years. Various parameters for the
company are given in the table below. Solution: (a)
Parameter Language L1 Language L2 The estimated effort in person-months is calcu-
lated by:
Man years LOC/10000 LOC/10000
needed for
Effort = c(size)k
development Where effort is measured in person-months
Development Rs 10,00,000 Rs 7,50,000 Size is measured in kdsi, thousands of delivered
cost per year
source code instructions.
Maintenance 5 years 5 years
time
c and k are constants.
Cost of Rs 1,00,000 Rs 50,000 Effort = 2.8 (40)1.20
maintenance = 234.22 person-months.
per year
Hance, the correct option is (a)
Total cost of the project includes cost of develop- 6. Which of the following is NOT desired in a good
ment and maintenance. What is the LOC for L1 for Software Requirement Specifications (SRS) docu-
which the cost of the project using L1 is equal to ment? [2011]
the cost of the project using L2. [2011] (a) Functional requirements
(a) 4000 (b) 5000 (b) Non-functional requirements
(c) 4333 (d) 4667 (c) Goals of implementation
Solution: (b) (d) Algorithms for software implementation
L1 = x, L2 = 2x Solution: (d)
Total cost of the project is calculated as follows: Software Requirement Specification (SRS) is a
requirement specification for a software system
x 2x
× 1000000 + 5 × 100000 = prepared based on a Domain Analysis Requirement
10000 10000 Capture which includes the full description of the
+ 750000 + 5 × 50000 behavior of a system to be developed. It includes
100x + 500000 = 150x + 250000 both functional as well as non-functional require-
ments. Algorithms for software implementation
50x = 250000
were developed during design phase where struc-
x = 250000/50 tural and behavioral modeling is performed.
= 5000 Hance, the correct option is (d)
Hance, the correct option is (b) 7. The cyclomatic complexity of each of the module
A and B shown below is 10. What is the cyclomatic
complexity of the sequential integration shown on
the right-hand side? [2010]
Web Technologies 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 1 0 0 1 1 1 0 1 0
11/19/2015 3:31:31 PM
Chapter 1
Web Technologies
Solution: (d)
One-mark Questions Date & Time can be displayed using JavaScript
(a) For embedding, object tag is available <Object>
1. Match the problem domains in GROUP-I with the (b) For refreshing <META http-equiv = “refresh” con-
solution technologies in GROUP-II. tents = “5”> this will refresh a page after 5 seconds
GROUP-I (c) <META http-equiv = “refresh” contents = “5”
P) Service oriented computing URL = http://www.othersite.com”> this will re-
Q) Heterogeneous and communicating systems direct a page after 5 seconds
R) Information representation (d) Pure HTML have no tag to shown the time on
S) Process description the page, it will need Java Script.
GROUP-II Hence, the correct option is (d)
1) Interoperability 3. Which one of the following is not a client-server
2) BPMN application? [2010]
3) Publish-find-bind (a) Internet chat (b) Web browsing
4) XML (c) E-mail (d) Ping
[2013] Solution: (d)
(a) P-l, Q-2, R-3, S-4 Chat web browsing and e-mail needs an application
(b) P-3, Q-4, R-2, S-1 on user machine and a server on remote. But ping is
(c) P-3, Q-1, R-4, S-2 a utility of administrator that will require to check
(d) P-4, Q-3 ,R-2, S-1 the reachability of a host.
Solution: (c) Hence, the correct option is (d)
Hence, the correct option is (c) 4. Consider the HTML table definition given below:
2. HTML has language elements which permits cer- <table border = l>
tain action other than describing the structure of <tr><td rowspan=2> ab </td>
the web document. Which one of the following <td colspan=2> cd </td>
actions is not supported by pure HTML (without </tr>
any client pr server side scripting) pages? [2011] <tr> <td> ef </td>
(a) Embed web objects from different sites into <td rowspan=2> gh </td>
same page </tr>
(b) Refresh the page automatically after a speci- <tr> <td colspan=2> ij </td>
fied interval </tr>
(c) Automatically redirect to another page upon </table>
download The number of rows in each column and the num-
(d) Display the client time as part of the page ber of columns in each row are: [2009]
11/19/2015 3:31:31 PM