You are on page 1of 565

tr

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

PREVIOUS YEARS’ SOLVED


provided for all the questions. It will help the students to get an idea about the pattern and weightage of questions
appeared in GATE exam.

WHAT THE FACULTIES SAY ABOUT THIS BOOK...

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

COMPUTER SCIENCE AND


The language used in solutions is very simple and will be very useful for students preparing for GATE exam. The solutions

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.

00_GATE_CSIT_Prelims.indd 1 6/13/2017 4:55:25 PM


This page is intentionally left blank.

00_GATE_CSIT_Prelims.indd 2 6/13/2017 4:55:25 PM


GATE
Previous Years’ Solved
Question Papers
Computer Science
and
Information Technology

00_GATE_CSIT_Prelims.indd 3 6/13/2017 4:55:25 PM


Copyright © 2018 Pearson India Education Services Pvt. Ltd

Published by Pearson India Education Services Pvt. Ltd, CIN: U72200TN2005PTC057128.

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

00_GATE_CSIT_Prelims.indd 4 6/13/2017 5:11:01 PM


Contents
Preface    ix
Reviewers    x
Syllabus: Computer Science and Information Technology    xi
Important Tips for GATE Preparation    xii
Detailed Analysis of GATE 2018 Papers xii-a

Solved Papers 2018 xii-b

Detailed Analysis of GATE 2017 Papers    xiii


Solved Papers 2017    xiv
Detailed Analysis of GATE 2016 Papers    li
Solved Papers 2016    lvi
Detailed Analysis of GATE 2015 Papers    xcii
Solved Papers 2015    xcvii

Unit 1:  Theory of Computation 1.1


Chapter 1:  RL, FA, RE and RG 1.3
Chapter 2:  CFL and PDA 1.18
Chapter 3:  CSL, RS, RES, LBA and TM 1.28
Chapter 4:  Undecidability 1.33

Unit 2:  Compiler Design 2.1


Chapter 1:  Lexical Analysis 2.3
Chapter 2:  Parsing Techniques 2.6
Chapter 3:  Syntax Directed Translation 2.17
Chapter 4:  Code Generated & Optimization 2.20

Unit 3:  Database Management System 3.1


Chapter 1  ER – Diagrams 3.3
Chapter 2  Functional Dependencies and Normalization 3.6
Chapter 3  Structure Query Language 3.13
Chapter 4  Relational Algebra and Relational Calculus 3.24
Chapter 5  Transactional and Concurrency Control  3.31
Chapter 6  File Structure an Indexing 3.37

Unit 4:  Computer Networks 4.1


Chapter 1:  Fundamental and SWP 4.3
Chapter 2:  Local Area Network 4.6

00_GATE_CSIT_Prelims.indd 5 6/13/2017 4:55:26 PM


vi | Contents

Chapter 3:  TCP/IP 4.9


Chapter 4:  Application Layer and Routing Algorithm 4.17

Unit 5:  Operating Systems 5.1


Chapter 1:  Process Management–I  5.3
Chapter 2:  Process Management–II  5.13
Chapter 3:  Deadlocks 5.28
Chapter 4:  Memory Management 5.33
Chapter 5:  File System and Device Management 5.46

Unit 6:  Design and Analysis of Algorithms 6.1


Chapter 1  Algorithm Analysis and Asymptotic Notations 6.3
Chapter 2:  Divide and Conquer 6.13
Chapter 3:  Greedy Method 6.22
Chapter 4:  Dynamic Programming 6.32
Chapter 5:  P and NP Concepts 6.36
Chapter 6:  Optimal Binary Search Tree 6.40
Chapter 7:  Miscellaneous Topics 6.42

Unit 7:  Data Structures 7.1


Chapter 1:  Array 7.3
Chapter 2:  Stacks and Queues 7.6
Chapter 3:  Linked List  7.14
Chapter 4:  Trees 7.18
Chapter 5:  Graphs 7.36
Chapter 6:  Hashing 7.40

Unit 8:  Programming Languages 8.1


Chapter 1:  Programming Language Concepts 8.3
Chapter 2:  Programming in C (Part I) 8.15
Chapter 3:  Programming in C (Part II) 8.24

Unit 9:  Digital Logic 9.1


Chapter 1:  Number Systems  9.3
Chapter 2:  Boolean Algebra 9.6
Chapter 3:  K-Maps 9.15
Chapter 4:  Combinational Circuits 9.19
Chapter 5:  Sequential Circuits 9.23

00_GATE_CSIT_Prelims.indd 6 6/13/2017 4:55:26 PM


Contents  |  vii

Unit 10:  Computer Organization 10.1


Chapter 1:  Computer Arithmetic 10.3
Chapter 2:  Memory Organization 10.8
Chapter 3:  Pipeline 10.17
Chapter 4:  CPU Organization 10.23
Chapter 5:  Control Unit Design 10.30
Chapter 6:  I/O Organization 10.32
Chapter 7:  Secondary Memories 10.36
Chapter 8:  Register Allocation 10.39

Unit 11:  Software Engineering 11.1


Chapter 1:   Software Engineering 11.3

Unit 12:  Web Technologies 12.1


Chapter 1:  Web Technologies  12.3

00_GATE_CSIT_Prelims.indd 7 6/13/2017 4:55:26 PM


This page is intentionally left blank.

00_GATE_CSIT_Prelims.indd 8 6/13/2017 4:55:26 PM


Preface
Graduate Aptitude Test in Engineering (GATE) is one of the primarily tests for various undergraduate subjects—
Engineering/Technology/Architecture and postgraduate level for Science. The GATE examination pattern has
undergone several changes over the years—sometimes apparent and sometimes subtle. It is bound to continue to
do so with changing technological environment.
GATE Previous Years’ Solved Question Papers for Computer Science and Information Technology acts as a
practice material for GATE aspirants to strengthen their conceptual understanding and application skills. The
book includes more than 27 years, GATE questions segregated topic-wise along with exam analysis which is
provided at the beginning of every unit. This book helps the GATE aspirants to get an idea about the pattern and
weightage of questions asked in GATE examination.
Owing to multifaceted opportunities open to any good performer, the number of aspirants appearing for the
GATE examination is increasing significantly every year. Apart from giving the aspirant a chance to pursue an
M.Tech. from institutions such as the IITs /NITs, a good GATE score can be highly instrumental in landing the
candidate a plush public sector job, as many PSUs are recruiting graduate engineers on the basis of their perfor-
mance in GATE.

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.

00_GATE_CSIT_Prelims.indd 9 6/13/2017 5:44:44 PM


Reviewers
We would like to thank the below mentioned reviewers for their continuous feedback and suggestions which has
helped in shaping this book.

Manoj Kumar Associate Professor, Delhi Technological University, New Delhi


Gurpreet Kaur Assistant Professor, LPU, Phagwara, Punjab
Guneet Kaur Lecturer, LPU, Phagwara, Punjab
R. Velmani Assistant Professor (Senior Grade), Madanapalle Institute of Technology and
Science, Chittoor, Andhra Pradesh

00_GATE_CSIT_Prelims.indd 10 6/13/2017 4:55:26 PM


Syllabus: Computer Science and
Information Technology
Digital Logic: Boolean algebra. Combinational and sequential circuits. Minimization. Number representations
and computer arithmetic (fixed and floating point).
Computer Organization and Architecture: Machine instructions and addressing modes. ALU, data-path and
control unit. Instruction pipelining. Memory hierarchy: cache, main memory and secondary storage; I/O interface
(interrupt and DMA mode).
Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees,
binary search trees, binary heaps, graphs.
Algorithms: Searching, sorting, hashing. Asymptotic worst case time and space complexity. Algorithm design
techniques: greedy, dynamic programming and divide-and-conquer. Graph search, minimum spanning trees,
shortest paths.
Theory of Computation: Regular expressions and finite automata. Context-free grammars and push-down
automata. Regular and contex-free languages, pumping lemma. Turing machines and undecidability.
Compiler Design: Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate
code generation.
Operating System: Processes, threads, inter-process communication, concurrency and synchronization.
Deadlock. CPU scheduling. Memory management and virtual memory. File systems.
Databases: ER-model. Relational model: relational algebra, tuple calculus, SQL. Integrity constraints, normal
forms. File organization, indexing (e.g., B and B+ trees). Transactions and concurrency control.
Computer Networks: Concept of layering. LAN technologies (Ethernet). Flow and error control techniques,
switching. IPv4/IPv6, routers and routing algorithms (distance vector, link state). TCP/UDP and sockets, conges-
tion control. Application layer protocols (DNS, SMTP, POP, FTP, HTTP). Basics of Wi-Fi. Network security:
authentication, basics of public key and private key cryptography, digital signatures and certificates, firewalls.

00_GATE_CSIT_Prelims.indd 11 6/13/2017 4:55:26 PM


Important Tips for GATE
Preparation
The followings are some important tips which would be helpful for students to prepare for GATE examination.

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.

00_GATE_CSIT_Prelims.indd 12 6/13/2017 4:55:26 PM


Detailed Analysis of GATE 2018 Papers
GATE CSIT Solved Paper 2018 Detailed Analysis
1 Mark 2 Mark Total
Subject
Questions Questions Marks
General Aptitude 5 5 15
Engineering Mathematics 6 5 16
Theory of Computation 2 3 8
Digital Logic 2 1 4
Computer Organization and Architecture 3 4 11
Programming and Data Structures 3 3 9
Algorithm 1 5 11
Compiler Design 1 2 5
Operating System 2 3 8
Database 2 2 6
Computer Networks 3 2 7
Software Engineering 0 0 0
Web Technology 0 0 0
Total 100

00_GATE_CSIT_Prelims.indd 1 6/18/2018 4:56:48 PM


GATE 2018 Solved Paper
CS: Computer Science and Information Technology
Set – 1
Number of Questions: 65 Total Marks:100.0

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

01_GATE CSIT_2018.indd 2 6/18/2018 4:52:46 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-c

Solution:  E Solution:  Let the number of men be 9x and the number


of women be 3y. (8/9 of the number of men and 2/3 of the
number of women are integers)
C ∴ 9x + 3y = 300 ⇒ 3x + y = 100 (1)
D F
8x men and 2y women claimed the gift.
B Amount given
= 750(8x) + 1000(2y) = 6000x + 2000y(2)
A
= 6000x + 2000(100 – 3x) = 200,000x
∠E + ∠F + ∠A = ∠ECF = ∠BCD
If x is an integer, among the options only B satisfies the
∴∠E + ∠F = ∠BCD − ∠A = ∠BCD − ∠BAD condition.
Hence, the correct option is (A). Hence, the correct option is (B).
Question Number: 7 Question Type: MCQ Question Number: 9 Question Type: MCQ
A six sided unbiased die with four green faces and two red 1 1 1
If pqr ≠ 0 and p – x = , q – y = , r – z = , what is the
faces is rolled seven times. Which of the following combi- q r p
nations is the most likely outcome of the experiment? value of the product xyz?
(A) Three green faces and four red faces. 1
(A) –1 (B)
(B) Four green faces and three red faces. pqr
(C) Five green faces and two red faces. (C) 1 (D) pqr
(D) Six green faces and one red face.
–x 1 − y 1 −z 1
Solution:  The most likely outcome in the one where the Solution:  p = ,q = ,r =
q r p
ratio of the number of green and red faces in closest to 2:1.
∴ p = q, q = r, r = p
x y z
This is 5g, 2r. We may want to consider 4g, 3r.
p = rz = (qy)z = pxyz
2 5 1 2
P(5g, 2r) = C5     = 32(21)/37
7
If p ≠ –1, 0 or 1, then xyz = 1
 3 3
The condition that p = –1 or 1 is not given, only with this
= 16(42)/37 condition we can conclude that xyz = 1. But as cannot be
2 4 1 3 determined is not an option, we select 1.
P(4g, 3r) = 7C4     = 16(35)/37
 3 3 Hence, the correct option is (C).
We see that 5g, 2r is more probable. Question Number: 10 Question Type: MCQ
Hence, the correct option is (C). In a party, 60% of the invited guests are male and 40% are
Question Number: 8 Question Type: MCQ female. If 80% of the invited guests attended the party and
if all the invited female guests attended, what would be the
In appreciation of the social improvements completed in a
ratio of males to females among the attendees in the party?
town, a wealthy philanthropist decided to gift ` 750 to each
(A) 2 : 3 (B) 1 : 1
male senior citizen in the town and ` 1000 to each female
(C) 3 : 2 (D) 2 : 1
senior citizen. Altogether, there were 300 senior citizens
eligible for this gift. However, only 8/9th of the eligible Solution:  Let the number of invited men and women be
men and 2/3rd of the eligible women claimed the gift. How 6 and 4. All the women attended. Overall 80 % attended.
much money (in Rupees) did the philanthropist give away Therefore, 4 men and 4 women attended. The required ratio
in total? is 1 : 1.
(A) 1,50,000 (B) 2,00,000 Hence, the correct option is (B).
(C) 1,75,000 (D) 1,51,000

01_GATE CSIT_2018.indd 3 6/18/2018 4:52:48 PM


xii-d | GATE 2018 Solved Paper CSIT: Set – I

Computer Science and Information Technology


Number of Questions: 55 Section Marks: 85.0
Q.11 to Q.25 carry 1 mark each and Q.26 to Q.65 carry Which one of the following is the correct order in which
2 marks each. the events above occur?
(A) QPTRS (B) PTRSQ
Question Number: 11 Question Type: MCQ
(C) TRPQS (D) QTPRS
Let N be an NFA with n states. Let k be the number of states
of a minimal DFA which is equivalent to N. Which one of Solution: 
the following is necessarily true? Hence, the correct option is (A).
(A) k ≥ 2n (B) k≥n
Question Number: 15 Question Type: MCQ
(C) k ≤ n2 (D) k ≤ 2n
Consider a process executing on an operating system that uses
Solution:  demand paging. The average time for a memory access in the
Hence, the correct option is (D). system is M units if the corresponding memory page is avail-
able in memory and D units if the memory access causes a
Question Number: 12 Question Type: MCQ
page fault. It has been experimentally measured that the aver-
The set of all recursively enumerable languages is age time taken for a memory access in the process is X units.
(A) Closed under complementation.
Which one of the following is the correct expression for the
(B) Closed under intersection.
page fault rate experienced by the process?
(C) A subset of the set of all recursive languages.
(A) (D - M)/(X - M) (B) (X - M/(D - M)
(D) An uncountable set.
(C) (D - X/(D - M) (D) (X - M/(D - X)
Solution: 
Solution:  Effective memory access time
Hence, the correct option is (B).
= (1 – α) ∗ memory access time + α (page fault overhead)
Question Number: 13 Question Type: MCQ α = page fault rate
Which one of the following statements is FALSE? From given data,
(A) Context-free grammar can be used to specify both
lexical and syntax rules. X = (1 – α) × M + α × D
(B) Type checking is done before parsing. X = M – αM + αD
(C) High-level language programs can be translated X −M
α =
to different Intermediate Representations. D−M
(D) Arguments to a function can be passed using the Hence, the correct option is (B).
program stack.
Question Number: 16 Question Type: MCQ
Solution: 
Which one of the following is a closed form expression for
Type checking is done after parsing, as syntax analysis is the generating function of the sequence {an } , where an =
done before semantic analysis. 2n + 3 for all n = 0, 1, 2, …?
Hence, the correct option is (B). 3 3x
(A) (B)
(1 − x ) (1 − x )
2 2
Question Number: 14 Question Type: MCQ
The following are some events that occur after a device 2– x 3– x
controller issues an interrupt while process L is under (C) (D)
(1 − x ) (1 − x )
2 2

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.

01_GATE CSIT_2018.indd 4 6/18/2018 4:52:50 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-e

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

01_GATE CSIT_2018.indd 5 6/18/2018 4:52:52 PM


xii-f | GATE 2018 Solved Paper CSIT: Set – I

Question Number: 23 Question Type: MCQ


M I
E1 R E2 Match the following:
Field Length in bits
P. UDP Header’s Port Number I. 48
Q. Ethernet MAC Address II. 8
R. IPv6 Next Header III. 32
E1 > E2 S. TCP Header’s Sequence Number IV. 16

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

01_GATE CSIT_2018.indd 6 6/18/2018 4:52:52 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-g

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.

01_GATE CSIT_2018.indd 7 6/18/2018 4:52:54 PM


xii-h | GATE 2018 Solved Paper CSIT: Set – I

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

Counter = 1 calc (4, 27)


1

3 Counter = 2 calc (4, 9)


86947 2 5

Counter = 3 calc (4, 3)


1
Counter = 4
2 3
The output of this program is 4.
5
869 4 7
Hence, the correct answer is 4.

1 Question Number: 32 Question Type: NAT


2 3 Consider the sequential circuit shown in the figure, where
both flip-flops used are positive edge-triggered D flip-flops.
4 5 The number of states in the state transition diagram of this
8 6 9 7 circuit that have a transition back to the same state on some
value of “in” is _______.

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

Hence, the correct answer is 4.

01_GATE CSIT_2018.indd 8 6/18/2018 4:52:55 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-i

Percentage of time available for Read/Write operation


p.s x DA DB n.s Out
1.2 m sec
A B A B B = × 100
0 0 0 0 0 0 0 0
2 m sec
0 0 1 1 0 1 0 0 = 60%.
0 1 0 0 0 0 0 0 Hence, the correct answer is 59 to 60.
0 1 1 1 0 1 0 0 Question Number: 34 Question Type: NAT
1 0 0 0 1 0 1 1
Consider a system with 3 processes that share 4 instances
1 0 1 1 1 1 1 1 of the same resource type. Each process can request a max-
1 1 0 0 1 0 1 1 imum of K instances. Resource instances can be requested
1 1 1 1 1 1 1 1 and released only one at a time. The largest value of K that
will always avoid deadlock is ________.
States transition diagram of the above sequential circuit is
Solution: There are 3 processes and 4 resources, one
as shown below
process can be able to obtain two resources.
0/0 Maximum number of instances a process can request will
be 2.
00 P1→1 
0/0 
1/1
P2→1  + 1
1/0
P3→1 
0/1 01
0/1 Hence, the correct answer is 2.
11
1/1 Question Number: 35 Question Type: NAT
1/0
10 Consider a long-lived TCP session with an end-to-end
bandwidth of 1Gbps (= 109 bits-per-second). The session
∴ the number of states in the state transition diagram of starts with a sequence number of 1234. The minimum time
this circuit that have a transition back to the same states on (in seconds, rounded to the closest integer) before this
some value of “in” is 2. sequence number can be used again is _______.
Hence, the correct answer is 2. Solution:
Question Number: 33 Question Type: NAT Amount of time required to lapse sequence numbers are
A 32-bit wide main memory unit with a capacity of 1 GB is 232 × 8
= 34.35 sec.
built using 256M × 4-bit DRAM chips. The number of rows 109
of memory cells in the DRAM chip is 214. The time taken Hence, the correct answer is 34.
to perform one refresh operation is 50 nanoseconds. The
refresh period is 2 milliseconds. The percentage (rounded Question Number: 36 Question Type: MCQ
to the closest integer) of the time available for performing Consider a matrix P whose only eigenvectors are the mul-
the memory read write operations in the main memory unit 1 
is _________. tiples of   ⋅
4
Solution:
Consider the following statements.
Number of memory cells rows in DRAM chip is 214 = 16K (I) P does not have an inverse
Total time for refreshing, if one refreshing takes 50 (II) P has a repeated eigenvalue
nanoseconds (III) P cannot be diagonalized
= 16 K × 50 ns Which one of the following options is correct?
= 800 μsec = 0.8 m sec. (A) Only I and III are necessarily true
(B) Only II is necessarily true
We know that refresh period is 2 msec.
(C) Only I and II are necessarily true
Out of 2 m sec, 0.8 m sec is used for refreshing and remain- (D) Only II and III are necessarily true
ing 1.2 msec is used for RD/WR operation.

01_GATE CSIT_2018.indd 9 6/18/2018 4:52:56 PM


xii-j | GATE 2018 Solved Paper CSIT: Set – I

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;

01_GATE CSIT_2018.indd 10 6/18/2018 4:52:57 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-k

*s1 = *s2; Which of the statements above must necessarily be true?


(A) I only (B) II only
*s2 = tmp;
(C) Both I and II (D) Neither I nor II
}
int main () { Solution:  We know that in DFS of an undirected graph,
char *str1 = “Hi”, *str2 = “Bye”; we will not get cross edge because all edges that are inci-
fun1 (str1, str2); dent on a vertex are explored.
printf (“%s %s “, str1, str2); Hence, the correct option is (A).
fun2 (&str1, &str2);
Question Number: 41 Question Type: MCQ
printf (“%s %s”, str1, str2);
Assume that multiplying a matrix G1 of dimension p × q
return 0;
with another matrix G2 of dimension q × r requires pqr sca-
}
lar multiplications. Computing the product of n matrices
The output of the program above is G1G2G3 … Gn can be done by parenthesizing in different
(A) Hi Bye Bye Hi (B) Hi Bye Hi Bye ways. Define Gi Gi+1 as an explicitly computed pair for a
(C) Bye Hi Hi Bye (D) Bye Hi Bye Hi given paranthesization if they are directly multiplied. For
example, in the matrix multiplication chain G1G2G3G4G5G6
Solution: 
using parenthesization (G1(G2G3))(G4(G5G6)), G2G3 and G5
100 H i 10 G6 are the only explicitly computed pairs.
Str 1 100 Consider a matrix multiplication chain F1F2F3F4F5, where
200 y e
matrices F1, F2, F3, F4, and F5 are of dimensions 2 × 25, 25
B 10
Str 2
× 3, 3 × 16, 16 × 1 and 1 × 1000, respectively. In the paren-
200 thesization of F1F2F3F4F5 that minimizes the total number
main ( ) of scalar multiplications, the explicitly computed pairs is/
fun 1 ( ) are
(A) F1F2 and F3F4 only (B) F2F3 only
Str 1 Str 2 (C) F3F4 only (D) F1F2 and F4F5 only
Solution:  Use Parenthesization ((F1(F2(F3F4)))F5)
100 200 F3F4 = 48 [16 × 3 × 1]
S1 S2 (F2(F3F4)) = 75 [25 × 3 × 1]
fun 2 ( ) (F1(F2(F3F4))) = 50 [ 2 × 25 × 1]
((F1(F2(F3F4)))F5) = 2000 [2 × 1 × 1000]
Str 1 Str 2 Str 2 Str 1 ∴ Total no. of multiplication required
= 2000 + 50 + 75 + 48
S1 S2 = 2173 (minimum number of
The output of the program is Hi Bye Bye Hi multiplications).
Hence, the correct option is (A) Hence, the correct option is (C).
Question Number: 40 Question Type: MCQ Question Number: 42 Question Type: MCQ
Let G be a simple undirected graph. Let TD be a depth first Consider the following C code. Assume that unsigned long
search tree of G. Let TB be a breadth first search tree of G. int type length is 64 bits.
Consider the following statements. unsigned long int fun (unsigned long int n) {
(I) No edge of G is a cross edge with respect to TD. unsigned long int i, j = 0, sum = 0;
(A cross edge in G is between two nodes neither for (i = n; i > 1. i = i/2) j++;
of which is an ancestor of the other in TD.) for (; j > 1; j = j/2) sum++;
(II) For every edge (u,v) of G, if u is at depth i and v is return (sum);
at depth j in TB, then |i – j| = 1. }

01_GATE CSIT_2018.indd 11 6/18/2018 4:52:57 PM


xii-l | GATE 2018 Solved Paper CSIT: Set – I

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

01_GATE CSIT_2018.indd 12 6/18/2018 4:52:58 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-m

(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

01_GATE CSIT_2018.indd 13 6/18/2018 4:52:59 PM


xii-n | GATE 2018 Solved Paper CSIT: Set – I

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.

01_GATE CSIT_2018.indd 14 6/18/2018 4:52:59 PM


(D) σB<5 (x) LOJS

 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

13 4 C Hence, the correct option is (C).


(A) σB<5 (r  s) Question Number: 52 Question Type: MCQ
A B C
Consider the following four relational schemas. For each
schema, all non-trivial functional dependencies are listed.
12 2 A
The underlined attributes are the respective primary keys.
15 4 C
Schema I:
13 4 C
Registration (rollno, courses)
13 6 C
Field ‘courses’ is a set-valued attribute containing the set
12 6 C
of courses a student has registered for.
Non-trivial functional dependency:
(B) σB<5 (x LOJS)
Rollno → courses
A B C
Schema II:
12 2 A
Registration (rollno, courseid, email)
13 6 C
Non-trivial functional dependencies:
15 4 C
Rollno, courseid → email
12 6 C
email → rollno
13 4 C
Schema III:
16 7 —
Registration (rollno, courseid, marks, grade)
(C) x LOJ (σB<5(s)) Non-trivial functional dependencies:
B C Rollno, courseid → marks, grade
 
r LOJ  2 A  Marks → grade
 
 3 B  Schema IV:
 
 4 C  Registration (rollno, courseid, credit)
Non-trivial functional dependencies:
A B C
Rollno, courseid → credit
12 2 A
Courseid → credit
13 6 –
Which one of the relational schemas above is in 3NF but
15 4 C
not in BCNF?
12 6 – (A) Schema I (B) Schema II
13 4 C (C) Schema III (D) Schema IV
16 7 – Solution: 
I. The given relation is not having transitivity depend-
(D) σB<5 (x) LOJS ency therefore it is in 3NF. For BCNF, every deter-
A B minant should be candidate key as email is determi-
 
  nant but not candidate key, the given schema is not
 12 2 
  in BCNF.
 15 4  LOJS
 13 4  Hence, the correct option is (B).

A B C
12 2 A
15 4 C
13 4 C

01_GATE CSIT_2018.indd 15 6/18/2018 4:53:00 PM


xii-p | GATE 2018 Solved Paper CSIT: Set – I

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.

01_GATE CSIT_2018.indd 16 6/18/2018 4:53:00 PM


4 = 1 + 7 – 2K
2K = 1 + 7 – 4
2K = 4
K=2
f (7) = 6C3 × f (3) × f (3)
GATE 2018 Solved Paper CSIT: Set – I | xii-q
L = 21 – 1 + min (21, 4)
=2–1+2=3
Question Number: 56 Question Type: NAT
R = 21 – 1 + max (0, 4 – 21)
The number of possible min-heaps containing each value
from {1, 2, 3, 4, 5, 6, 7} exactly once is ________. =2–1+2=3
f (3) = 2C1 × f (1) × f (1) = 2 × 1 × 1 = 2
Solution: For min - heap, only root possible is ‘1’. 6! 6 × 5 × 4 × 3!
The total ways to design a min heap f (7) = ×2×2 = ×2×2
3! 3! 3 × 2 × 3!

f (N) = (N–1 CL) × f (L) × f (R) = 80.


K–1 K–1
L = 2 – 1 + min (2 , m) Hence, the correct answer is 80.
K–1 K–1
R = 2 – 1 + max (0, m – 2 )
Question Number: 57 Question Type: NAT
M = 1 + N – 2K
Consider the following undirected graph G:
N = 7, M = 4 (no. of leaf nodes)
4 = 1 + 7 – 2K 4 x
2K = 1 + 7 – 4
1 3
2K = 4
K=2 4 5
6
f (7) = C3 × f (3) × f (3)
L = 21 – 1 + min (21, 4) 4

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

01_GATE CSIT_2018.indd 17 6/18/2018 4:53:02 PM


xii-r | GATE 2018 Solved Paper CSIT: Set – I

Question Number: 58 Question Type: NAT


S11 = {(28, 7), (88, 17)}
Consider the weights and values of items listed below. Note
that there is only one unit of each item. { 17 > 11 overflow}
S2 = {(0, 0), (60, 10), (28, 7)}
Item no. Weight Value
(in Kgs) (in Rupees) S12 = {(20, 4), (80, 14), (48, 11)}
1 10 60 {∵ 14 > 11 overflow}
2 7 28 3
S = {(0, 0), (60, 10), (28, 7),
3 4 20 (20, 4), (48, 11)}
4 2 24
S13 = {(24, 2), (84, 12), (52, 9),
(44, 6), (72, 13)}
The task is to pick a subset of these items such that their
total weight is no more than 11 Kgs and their total value is {∵ 12 > 11, 13 > 11 overflow}
4
maximized. Moreover, no item may be split. The total value S = {(0, 0), (60, 10), (28, 7),
of items picked by an optimal algorithm is denoted by Vopt. (20, 4), (48, 11), (24, 2),
A greedy algorithm sorts the items by their value-to-weight (52, 9), (44, 6)}
ratios in descending order and packs them greedily, start- Optimal solution is (60, 10) after back tracking x1 = 1,
ing from the first item in the ordered list. The total value of
items picked by the greedy algorithm is denoted by Vgreedy. ∴ Vopt = ∑ pi xi = 60
The value of Vopt – Vgreedy is ________. The value
n Vopt – Vgreedy = 60 – 44
Solution:  It is 0/1 knapsack problem max ∑ pi xi . = 16
n i =1
Hence, the correct answer is 16.
Subject to = ∑ wi xi < m
1 Question Number: 59 Question Type: NAT
xi = 0 or 1 Consider the minterm list form of a Boolean function F
1≤i≤n given below.
M = 11 kgs F(P, Q, R, S) = ∑m ( 0, 2, 5, 7, 9,11) + d ( 3, 8,10,12,14 )

Item Weight value v/w ∑m ( 0, 2, 5, 7, 9,11) + d ( 3, 8,10,12,14 )


no. (in kgs) (in rupees)
Here, m denotes a minterm and d denotes a don’t care term.
1 10 60 6 The number of essential prime implicants of the function
2 7 28 4 F is ______.
3 4 20 5
Solution: 
4 2 24 12
F(P, Q, R, S) = m(0, 2, 5, 7, 9, 11)
v/w in descending order: + d(3, 8, 10, 12, 14)
12 6 5 4 RS
PQ 00 01 11 10
x4 x1 x3 x2
00 1 x 1
O O 
01 1 1 III
(2 + 4 ≤ 11
11 x x
6 ≤ 11
∴ Vgreedy = ∑ pi xi 10 x 1 1 x II

= 24 + 20 I

= 44 I, II,III all are essential prime implicants


3 essential prime implicants
S 0 = {(0, 0)}
S 1 = {(0, 0), (60, 10)} Hence, the correct answer is 3.
S10 = {(60, 10)}

01_GATE CSIT_2018.indd 18 6/18/2018 4:53:03 PM


GATE 2018 Solved Paper CSIT: Set – I | xii-s

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: 61 Question Type: NAT 0


0
A processor has 16 integer registers (R0, R1, .., R15) and
64 floating point registers (F0, F1…., F63). It uses a 2-byte The order of L1 is ________ .
instruction format. There are four categories of instruc-
Solution: L1 = {ε, 0, 000, 00000, ...}
tions: Type-1, Type-2, Type-3, and Type-4. Type-1 category
consists of four instructions, each with 3 integer register L0 = {ε}
operands (3Rs). Type-2 category consists of eight instruc- L1 = L0 ⋅ L1
tions, each with 2 floating point register operands (2Fs). L1 = {ε, 0, 000, 00000, ...}
Type-3 category consists of fourteen instructions, each L2 = L1 ⋅ L1
with one integer register operand and one floating point L2 = {ε, 0, 000, 0000, ...}
register operand (1R + 1F). Type-4 category consists of
L3 = L2 ⋅ L1
N instructions, each with a floating point register operand
(1F). L3 = {ε, 0, 00, 0000, 00000, ...}
The maximum value of N is _______. ∴ L2 = L3
So, K = 2.
Solution:  Instruction size = 16 bits
Integer register requires 4 bits Hence, the correct answer is 2.

01_GATE CSIT_2018.indd 19 6/18/2018 4:53:03 PM


xii-t | GATE 2018 Solved Paper CSIT: Set – I

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.

01_GATE CSIT_2018.indd 20 6/18/2018 4:53:04 PM


Detailed Analysis of GATE 2017 Papers
GATE CSIT Solved Paper 2017 Detailed Analysis
1 Mark 2 Mark Total
Subject
Questions Questions Marks
General Aptitude 5 5 15
Engineering Maths 4 5 14
Digital Logic 2 2 6
Computer Organization 3 4 11
Operating System 2 2 6
Databases 2 3 8
Theory of Computation 2 4 10
Compiler Design 2 1 4
Computer Network 2 3 8
Algorithms 2 2 6
Programming and Data Structures 4 4 12
Total 100

00_GATE_CSIT_Prelims.indd 13 6/13/2017 4:55:26 PM


GATE 2017 Solved Paper
CSIT: Computer Science Engineering
Set – 1
Number of Questions: 65 Total Marks:100

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

Each digit can be filled in 7 ways as 0, 5, and 9 are not


?
allowed. So, each of these places can be filled by 1, 2, L (w)
k L (w)
3, 4, 6, 7, 8. So, required probability is   or 0.7k.
7
Therefore, answer should be 2 women.
 10 
Hence, the correct option is (C). Hence, the correct option is (A).

01_GATE 2016 CSIT Set-1.indd 14 6/13/2017 11:20:58 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xv

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

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and TCP client calls close to terminate the connectional and a
Question 36 to Question 65 carry 2 marks each. FIN segments is sent to the TCP server. Server-side TCP
responds by sending an ACK, which is received by the
Question Number: 11 Question Type: MCQ client-side TCP. As per the TCP connections state dia-
Consider a TCP client and a TCP server running on two gram (RFC 793), in which state does the client-side TCP
different machines. After completing data transfer, the connection wait for the FIN from the sever-side TCP?

01_GATE 2016 CSIT Set-1.indd 15 6/13/2017 11:20:59 AM


xvi | GATE 2017 Solved Paper CSIT: Set – 1

(A) LAST-ACK (B) TIME-WAIT


(C) FIN-WAIT-1 (D) FIN-WAIT-2
Solution:

Client* Server*
* or vice-versa, though requests typically originate at clients.

3 syn − sent 2 Listening


Sent connection − request. 1 Awaiting connection request.
Awaiting acknowledgement.1
Awaiting connection − request. 2
4 Syn − Received
Received acknowledgement. 1 Received connection − request. 1
Received connection − request. 2 Sent acknowledgement. 1
Sent acknowledgement. 2 Sent connection − request. 2
Awaiting acknowledgement. 2

5 Established 5 Established
The connection is open. Received acknowledgement. 2
Data moves both directions. The connection is open.
Data moves both directions.

6 Fin − waith. 1 8 Close − wait


Sent close − request.a Received close − request.a
Awaiting acknowledgement.a Sant acknowledgement.a
Awaiting close − request.b When finished sending data
Will sent close − request.b

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

A “fictional” state; Awaiting connection request.


There is no connection.

Hence, the correct option is (D).

01_GATE 2016 CSIT Set-1.indd 16 6/13/2017 11:21:00 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xvii

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

01_GATE 2016 CSIT Set-1.indd 17 6/13/2017 11:21:01 AM


xviii | GATE 2017 Solved Paper CSIT: Set – 1

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

01_GATE 2016 CSIT Set-1.indd 18 6/13/2017 11:21:02 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xix

Solution:  A tree with 10 vertices has 9 edges. printf(“%d\n”, *x);


free (x);
As, ∑ d ( vi ) = 2 E
}
⇒ ∑ d ( vi ) = 2 × 9 = 18
The code suffers from which one of the following
Hence, the correct answer is (18). problems:
(A) compiler error as the return of malloc is not
Question Number: 19 Question Type: MCQ typecast appropriately.
Let T be a binary search tree with 15 nodes. The mini- (B) compiler error because the comparison should
mum and maximum possible heights of T are: be made as x == NULL and not as shown.
Note: The height of a tree with a single node is 0. (C)  compiles successfully but execution may
(A) 4 and 15, respectively ­result in dangling pointer.
(B) 3 and 14, respectively (D) compiles successfully but execution may
(C) 4 and 14, respectively ­result in memory leak.
(D) 3 and 15, respectively Solution:
(A) is wrong. We don’t need to cast the result as
Solution:
void * is automatically and safely promoted to
any other pointer type in this case.
(B) It is discarded for obvious reason.
min max
height height (C) is wrong, because dangling pointer is nothing
but the pointer, which is pointing to nonexist-
15 nodes total ing memory (deallocated or deleted memory)
which is not happening here.
Min height = floor (log 2 N) = floor ( log 15) = 3 (D) is the answer. When you are calling malloc
Max height = 14, when the tree is either left skewed or second time, new location is assigned to x and
right skewed. previous memory location is lost and now we
don’t have no reference to that location result-
Hence, the correct option is (B). ing in memory leak.
Question Number: 20 Question Type: MCQ Hence, the correct option is (D).
Consider the following C code: Question Number: 21 Question Type: NAT
# include <stdio.h> Let X be a Gaussian random variable mean 0 and var-
iance s2. Let Y = max(X, 0), where max(a, b) is the
int * assignval (int *x, int val) {
maximum of a and b. The median of Y is __________.
*x = val;
Solution:  ‘X’ is Gaussian random variable
return x;
⇒ X ~ N(0, s 2) for –∞ < X < ∞
}
void main ( ) { Given y = max(x, 0)
int * x= malloc (sizeof (int));  0 if − ∞ < x ≤ 0
=
x if 0 < x < ∞, is a random variable
if (NULL = = x) return;   
x = assignval (x,0); Since, median is positional average
if(x) { Therefore, median of Y is ‘0’.
x=(int *) malloc (sizeof (int)); Hence, the correct answer is (0).
if (NULL = = x) return;
Question Number: 22 Question Type: NAT
x = assignval (x, 10);
Consider the Karnaugh map given below, where x rep-
} resents “don’t care” and blank represents 0.

01_GATE 2016 CSIT Set-1.indd 19 6/13/2017 11:21:03 AM


xx | GATE 2017 Solved Paper CSIT: Set – 1

ba Solution:  By rule of contrapositive,


dc ¬p → ¬q ⇔ q → p
00 01 11 10
q → p ⇔ ~ q∨p
00 X X
Hence, the correct option is (D).
01 1 X Question Number: 24 Question Type: MCQ
Consider the following table:
11 1 1
Algorithms Design Paradigms
10 X X P. Kruskal i. Divide and Conquer
Q. Quicksort ii. Greedy

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

00 X X Solution:  Kruskal’s algorithm follows greedy approach


in order to find MST of a connected graph. Quick sort
01 1 X
follows divide and conquer strategy. Floyd Warshal al-
gorithm is used to find the shortest path between every
11 1 1 pair of vertices and it follows dynamic programming
strategy.
10 X X Hence, the correct option is (C).
Question Number: 25 Question Type: MCQ
F ( a, b, c, d ) = ac ⇒ a.c = a + c ( x + y = x. y ) A sender S sends a message m to receiver R, which is
digitally signed by S with its private key. In this sce-
= a+c nario, one or more of the following security violations
can take place.
c
I.  S can launch a birthday attack to replace m
with a fraudulent message.
a II. A third party attacker can launch a birthday
attack to replace m with a fraudulent message.
Only 1 NOR gate required.
III. 
R can launch a birthday attack to replace m
Hence, the correct answer is (1). with a fraudulent message. Which of the fol-
Question Number: 23 Question Type: MCQ lowing are possible security violations?
The statement (¬p) ⇒ (¬q) is logically equivalent to (A) I and II only
which of the statements below? (B) I only
I. p ⇒ q II. q⇒p (C) II only
III. (¬q) vp IV. (¬p) vq (D) II and III only
(A) I only (B) I and IV only
Solution:  Sender can launch a Birthday Attack to
(C) II only (D) II and III only replace with fraudulent message, because he has the

01_GATE 2016 CSIT Set-1.indd 20 6/13/2017 11:21:04 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xxi

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

01_GATE 2016 CSIT Set-1.indd 21 6/13/2017 11:21:05 AM


xxii | GATE 2017 Solved Paper CSIT: Set – 1

Question Number: 30 Question Type: MCQ p–> next = m;


Threads of a process share }
(A) global variable but not heap. Assuming that m and n point to valid NULL-terminated
(B) heap but not global variables. linked lists, invocation of join will
(C) neither global variables nor heap. (A)  append list m to the end of list n for all
­inputs.
(D) Both heap and global variables.
(B)  either cause a null pointer dereference or
Solution:  Threads of a process can share all resources ­append list m to the end of list n.
except stack and register set.
(C)  cause a null pointer dereference for all
Hence, the correct option is (D). ­inputs.
Question Number: 31 Question Type: MCQ (D)  append list n to the end of list m for all ­inputs.
Let c1........cn be scalars, not all zero, such that Solution:  While loop in Join Procedure moves the
n

∑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

01_GATE 2016 CSIT Set-1.indd 22 6/13/2017 11:21:06 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xxiii

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

01_GATE 2016 CSIT Set-1.indd 23 6/13/2017 11:21:06 AM


xxiv | GATE 2017 Solved Paper CSIT: Set – 1

Option (D): x = 1; y = 1 Solution:  Given generator polynomial G(x) = x3 + x +


Means that 1 thread and 1 lock → No deadlock 1 ⇒ 1011 message m(x) = 01011011
situation.
1011) 0101 1 011000 (01000011
Hence, the correct option is (C).
0000
Question Number: 38 Question Type: NAT
Ø 1011
The values of parameters for the Stop-and-Wait ARQ
1011
protocol are as given below:
Bit rate of the transmission channel = 1Mbps Ø 0000
0000
Propagation delay from sender to receiver = 0.75 ms
Time to process a frame = 0.25 ms Ø 0001
0000
Number of bytes in the information frame = 1980
Ø 0011
Number of bytes in the acknowledge frame = 20
0000
Number of overhead bytes in the information frame = 20
Ø 0110
Assume that there are no transmission errors. Then the
0000
transmission efficiency (expressed in percentage) of
the Stop-and-Wait ARQ protocol for the above param- Ø 1100
1011
eters is ________ (correct to 2 decimal places)
Solution:  Given Data: Ø 1110

B = 1 Mbps 1011

Tproc = 0.25 ms Ø 101

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

01_GATE 2016 CSIT Set-1.indd 24 6/13/2017 11:21:07 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xxv

Question Number: 41 Question Type: NAT CR


A cache memory unit with capacity of N words and Student Name Course Name
block size of B words is to be designed. If it is designed
SA CA
as a direct mapped cache, the length of the TAG field is
10 bits. If the cache unit is now designed as a 16-way SA CB
set-associative cache, the length of the TAG field is SA CC
__________ bits. SB CB

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

if (n = =0 ) if (n = = 0) The following query is made on the database.


return; return ;
T1 ← p CourseName (s StudentName =’SA’ (CR))
printf (“%d” , n); printf (“%d” , n); T2 ← CR¸ T1
fun2 (n - 2); fun1(++n) ;
The number of rows in T2 is_____________.
printf (“%d” , n); printf (“%d” , n);
Solution:
The output printed when fun1(5) is called is T1 ={CA, CB, CC}
(A) 53423122233445 T2 ={SA, SC, SD, SF}
(B) 53423120112233 Hence, the correct Answer is (4).
(C) 53423122132435
Question Number: 44 Question Type: MCQ
(D) 53423120213243
Let A be n × n real valued square symmetric matrix
n n
Solution:  In this the fun 1() is calling fun 2() after
of rank 2 with ∑ ∑ Aij2 = 50. Consider the following
printing value and after returning from fun 2(), it prints i =1 j =1
the same value. In the fun 2() also the same thing hap- statements.
pens So, by looking options we can judge the correct (I) One eigen value must be in [-5, 5]
sequence of output. (II) The eigen value with the largest magnitude
Hence, the correct option is (A). must be strictly greater than 5.
Which of the above statements about eigen values of A
Question Number: 43 Question Type: MCQ
is/are necessarily CORRECT?
Consider a database that has the relation schema
CR (StudentName, CourseName). An instance of the (A) Both (I) and (II) (B) (I) only
schema CR is as given in the table. (C) (II) only (D) Neither (I) nor (II)

01_GATE 2016 CSIT Set-1.indd 25 6/13/2017 11:21:07 AM


xxvi | GATE 2017 Solved Paper CSIT: Set – 1

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

i =1 j =1 Initially, both Q0 and Q1 aarre set to 1 (before the 1st


0 0 0 
clock cycle). The outputs
but eigen values of A are 0, -5, 5 (A) Q1Q0 after the 3rd cycle are 11 and after the
\ The eigen value with the largest magnitude is not 4th cycle are 00, respectively.
greater than 5 (B) Q1Q0 after the 3rd cycle are 11 and after the
5 0 
For n = 2 and Let A A =   ⇒ eigen values = 5, 5 4th cycle are 01, respectively.
0 5  (C) Q1Q0 after the 3rd cycle are 00 and after the
\ One eigen value must be in [–5, 5] and largest eigen 4th cycle are 11, respectively.
value magnitude is not greater than 5. (D) Q1Q0 after the 3rd cycle are 01 and after the
\ (II) is false 4th cycle are 01, respectively.
Hence, the correct option is (B). Solution:
Question Number: 45 Question Type: MCQ CLK Q1 Q0
0 1 1
Consider the context-free grammars over the alphabet
{a, b, c} given below. S and T are non-terminals 1 0 1
2 1 0
G1 : S →aSb|T, T →cT|∈
3 1 1
G2 : S →bSa|T, T → cT|∈ 4 0 1
The language L(G1) Ç L(G2) is
(A) Finite. After 3rd clock pulse :11
After 4th clock pulse: 01
(B) Not finite but regular.
Hence, the correct option is (B).
(C) Context-free but not regular.
(D) Recursive but not context-free. Question Number: 47 Question Type: NAT
Solution:  The context free grammar given over alpha- The number of integers between 1 and 500 (both inclu-
bets Σ ={ a, b, c} with S and T as non-terminals are: sive) that are divisible by 3 or 5 or 7 is __________.
G1 : S → aSb|T, T → cT|∈ Solution:
G2 : S → bSa|T, T → cT|∈ D3 = {integers between 1 to 500 divisible by 3}
Lets L(G1) is the language for grammar G1 and L(G2) is D5 = {integers between 1 to 500 divisible by 5}
the language for grammar G2 D7 = {integers between 1 to 500 divisible by 7}
L(G1) = {ancmbn| n, m ≥0} To find number of integers between 1 to 500 that are
L(G1) = {bncman| n, m≥0} divisible by 3 or 5 or 7 is to find
L1 Ç L2 ={ cm|m ≥ 0 }; which is infinite and regular |D3 ∪ D5 ∪ D7|

Hence, the correct option is (B). = [ D3 + D5 + D7 ] − [ D3 ∩ D7 + D5 ∩ D7 +


Question Number: 46 Question Type: MCQ D3 ∩ D5 ∩ D7 ]
Consider a combination of T and D flip-flops con-   500   500   5000     500   500   500  
nected as shown below. The output of the D flip-flop is =   +  5  +  7   −   15  +  21  +  35  
  3           
connected to the input of the T flip-flop and the output
of the T Flip-flop is connected to the input of the D  500 
+ 
Flip-flop.  105 
= (166 + 100 + 71) − (33 + 23 + 14) + 4
= 337 − 70 + 4 = 271

01_GATE 2016 CSIT Set-1.indd 26 6/13/2017 11:21:08 AM


= [ D3 + D5 + D7 ] − [ D3 ∩ D7 + D5 ∩ D7 +
D3 ∩ D5 ∩ D7 ]
  500   500   5000     500   500   500  
=   +  5  +  7   −   15  +  21  +  35  
 3           
 500  GATE 2017 Solved Paper CSIT: Set – 1 | xxvii
+ 
 105 
= (166 + 100 + 71) − (33 + 23 + 14) + 4 Invocations of foo (3) and bar (3) will result in:
= 337 − 70 + 4 = 271 (A) Return of 6 and 6, respectively.
Hence, the correct answer is (271). (B)  Infinite loop and abnormal termination,
Question Number: 48 Question Type: NAT ­respectively.
Consider a RISC machine where each instruction is (C)  Abnormal termination and infinite loop,
exactly 4 bytes long. Conditional and unconditional ­respectively.
branch instructions use PC-relative addressing mode (D) Both terminating abnormally.
with Offset specified in bytes to the target location of Solution:  Foo (3) calls foo (3) which in turn calls
the branch instruction. Further the Offset is always foo(3). This goes on infinite number of times, which
with respect to the address of the next instruction in the causes memory overflow and causes abnormal termi-
program sequence. Consider the following instruction nation.
sequence.
Bar(3) → bar(2) → bar(1) → bar(0) (return 0) from
Instr. No. Instruction here onwards bar (1) will call bar (0) and bar (0) will
i: add R2, R3, R4 return 0 to bar (1) and this goes on forever without
causing memory overflow.
i + 1; sub R5, R6, R7
Hence, the correct answer is (B).
i + 2; cmp R1, R9, R10
i + 3; beq R1, Offset Question Number: 50 Question Type: NAT
In a RSA cryptosystem a participant A uses two prime
If the target of the branch instruction is i, then the deci- numbers p = 13 and q = 17 to generate her public and
mal value of the Offset is ___________. private keys. If the public key of A is 35. Then the pri-
Solution:  I1 0 - 3 vate key of A is ______.
I2 4-7 Solution:
I3 8-11
Given Data As per RSA Algorithm
I4 12-15
p = 13 Step1: Calculate n = p × q = 13 × 17 = 221
16 - I4 is the branch instruction & I1 is the target.
q = 17 Step 2: Calculate f(n) = (p - 1)(q - 1) = (12)
0 = 16+ relative value (16) = 192
\ relative value = -16 e = 35 Step 3: de mod f(n) = 1 (or) de = 1modf(n)
Hence, the correct answer is (-16). d=? ⇒ d × 35 mod192 = 1 d = 11

Question Number: 49 Question Type: MCQ


Hence, the correct answer is (11).
Consider the C functions foo and bar given below:
int foo (int val ) { Question Number: 51 Question Type: MCQ
int x = 0; Let A be an array of 31 numbers consisting of
sequence of 0’s followed by a sequence of 1’s. The
while (val > 0) {
problem is to find the smallest index i that A[i] is 1 by
x = x + foo ( val --); probing the minimum numbers of locations in A.
} The worst case number of probes performed by an
return val ; optimal algorithm is _________.
} Solution:  In the given array the elements are 0’s fol-
int bar (int val ) { int x = 0; lowed by 1’s, which means array is already sorted.
while (val > 0) { So, we can apply binary search. At each stage, we
x = x + bar (val – 1);  low + high 
compare A  .
}  2 
return val ; [Assuming A is an array of 31 elements] with ‘1’ and if
} it is 1 we check the left part recursively and if it is ‘0’

01_GATE 2016 CSIT Set-1.indd 27 6/13/2017 11:21:09 AM


xxviii | GATE 2017 Solved Paper CSIT: Set – 1

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 ______

Question Number: 52 Question Type: MCQ Solution:  Given,


If G is grammar with productions For Navie pipeline (NP) Number of stages (k) = 5
Tp = max (stage delay + buffer delay)
S → SaS aSb bSa SS ∈
Tp = max (7, 6, 22, 12, 5) = 22 nsec.
where S is the start variable, then which one of the fol- Number of instructions (n) = 20
lowing is not generated by G? So, erection time for navie pipeline
(A) abab (B) aaab ETNP = (k + n - 1) × TP = (5 + 20 - 1) × 22 = 528 nsec
(C) abbaa (D) babba Now, for efficient pipeline
Solution: k = 6, n = 20, TP = 14 nsec.
1. S →SS → aSbS → abS →abaSb → abab EEP = (k + n - 1) × TP = (6 + 20 - 1) × 14 = 350 nsec.
2. S →aSb → aSaSb →aaaSb → aaab ETNP 528
Therefore, Speed up= ( s) =
3. S → SS → aSbS → abS → abbSa → abbSaSa → E EP 350
abbaa Speed up (s) = 1.508
Given grammar generates all strings where n(a) ≥ n (b) 350
Hence, the correct answer is (D).
Hence, the correct answer is (1.508).
Question Number: 53 Question Type: MCQ Question Number: 55 Question Type: MCQ
x − 2x + 1
7 5
Consider a database that has the relation sche-
The value of lim mas EMP(EmpId, EmpName, DepId). And
x →1 x 3 − 3x 2 + 2
DEPT(DeptName, DeptId). Note that the DeptId can
(A) is 0 (B) is -1
be permitted to be NULL in the relation EMP. Consider
(C) is 1 (D) does not exist the following queries on the database expressed in tuple
relational calculus.
x7 − 2 x5 + 1 7 x 6 − 10 x 4 (I) {t |$u ∈ EMP(t[EmpName] = u[EmpName] ∨ ∀v
Solution:  lim = lim = 1.
x →1 x 3 − 3 x 2 + 2 x →1 3 x 2 − 6 x ∈ DEPT(t[DeptId] ≠ v[DeptId]))}
( Using L − Hospiital’s rule) (II) {t |$u ∈ EMP(t[EmpName] = u[EmpName] ∨$v ∈
DEPT(t[DeptId] ≠ v[DeptId]))}
Hence, the correct answer is (C).
(III) {t |$u ∈EMP(t[EmpName] = u[EmpName] ∨$v
Question Number: 54 Question Type: MCQ ∈DEPT(t[DeptId] ≠ v[DeptId]))}
Instructions execution in a processor is divided into 5 Which of the above queries are safe?
stages. Instruction Fetch (IF), Instruction Decode (ID), (A) (I) and (II) only
Operand Fetch (OF), Execute (EX), and Write Back (B) (I) and (III) only
(WB). These stages take 5, 4, 20, 10, and 3 nanosec-
onds (ns), respectively. A pipelined implementation of (C) (II) and (III) only
the processor requires buffering between each pair of (D) (I), (II) and (III)
consecutive stages with a delay of 2 ns. Two pipelined
Solution:  Query which generates infinite number of
implementations of the processor are contemplated.
tuples is called unsafe query. In the given question all
(i) a naïve pipeline implementation (NP) with 5 the given queries generate finite number of tuples.
stages and
Hence, the correct answer is (D).
(ii) an efficient pipeline (EP) where the OF stage
id divided into stages OF1 and OF2 with ex- Question Number: 56 Question Type: MCQ
ecution times of 12 ns and 8 ns, respectively. Recall that Belady’s anomaly is that the pages-fault

01_GATE 2016 CSIT Set-1.indd 28 6/13/2017 11:21:10 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xxix

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

(A) S1 is true, S2 is true Hence, the correct answer is (23).


(B) S1 is true, S2 is false Question Number: 58 Question Type: NAT
(C) S1 is false, S2 is true Consider the following C program.
(D) S1 is false, S2 is false #include <stdio.h>
Solution:  Statement 1 is “TRUE”. Because there can #include<string.h>
be a case when page selected to be replaced is by FIFO void printlength (char *s, char *t)
policy. {
Statement 2 is “FALSE”. Because LRU page re- unsigned int c = 0;
placement algorithm does not suffers from Belady’s int len = ((strlen(s) – strlen (t))
­Anomaly. Only FIFO page replacement algorithm suf- > c) ? strlen(s): strlen(t);
fers from Belady’s Anomaly. printf (“%d\n”, len);
Hence, the correct answer is (B) }
void main ( ) {
Question Number: 57 Question Type: NAT
char *x = “abc”;
The output of executing the following C program
is______. char *y =”defgh”;
printlength (x,y);
# include <stdio.h> Recall that strlen is defined in string.h as returning a
int total (int v) { value of type size_t, which is an unsigned int. The out-
while (v) { put of the program is ________.
count + = v & 1; Solution:  x is pointer of string “abc” which is length 3.
v>> = 1; S is pointer, that pointed x.
} y is pointer of string “defgh” which is length 5.
return count; t is pointer that pointed y.
} Now, ((strlen (s)– strlen (t)) > c) is ((3 –5) > 0) is re-
void main ( ) { turns true, since (3 - 5 = -2) is nonzero value so, ter-
nary operator ‘?’ is returned strlen(s) which is 3 and
static int x = 0;
assigned to len because ternary-operator returns first
int i = 5; if condition is true else second. Therefore, final value
for (; i> 0; i--) { is printed 3.
x=x + total (i) ; Hence, the correct answer is (3).
} Question Number: 59 Question Type: MCQ
printf (“%d\n”, x) ; Consider the following languages over the alphabet S =
} {a, b, c}

01_GATE 2016 CSIT Set-1.indd 29 6/13/2017 11:21:10 AM


xxx | GATE 2017 Solved Paper CSIT: Set – 1

Let L1 = {an bn cm|m, n ³ 0} and L2 = {am bn cn|m, n ≥ 0} (A) 2 (B) 1/2


Which of the following are context-free languages? (C) 1 (D) -1/2
I L1 ∪ L2  2 0
Solution: Let u =    and  v =  
II L1 Ç L2 0
  1
(A) I only (B) II only 2
⇒ u = z. v and w =  
(C) I and II (D) Neither I nor II α 
Solution:  The language given over alphabets Σ = {a,
Now cos(u, w) = cos(v, w)
b, c} as L1 ={anbncm|n,m ≥ 0} and L2= {ambncn|n, m ≥
0}. 4 α
⇒ = ⇒α = 2
L1 ∪ L2 = { anbmck|n = m or m = k, n, m ≥ 0}is a ( 2) α + 42
(1) α 2 + 4
context free language. The context free grammar is: Hence, the correct answer is (A).
S→AB|CD
Question Number: 62 Question Type: NAT
A→aAb|∈
Consider the following grammar:
B→cB|∈
stmt →if exp r then else exp r; s tmt 0
C→aC|∈
exp r →term relop term term
D→bSc|∈ term →id | number
L1 ∩ L2 ={ anbmck|n = m and m = k, n, m ≥ 0}or ­{anbncn| if →a | b | c
n ≥ 0}is a non-context free language.
number → [0 - 9]
Hence, the correct answer is (A).
where relop is a relational operate (e.g <, >,….) ---O
Question Number: 60 Question Type: NAT refers to the empty statement, and if,then, else are
Consider a 2-way set associative cache with 256 blocks terminals.
and uses LRU replacement, Initially, the cache is ­empty. Consider a program P following the above grammar
Conflict misses are those misses which ­occur due the containing ten if terminals. The number of control
contention of multiple blocks for the same cache set. flows paths in P is______. For example the program
Compulsory misses occur due to first time access to the if e1 then e2 else e3
block. The following sequence of accesses to memory has 2 controls flow paths e1 → e2 and e1 → e3
blocks.
(0, 128, 256, 128, 0, 128, 256, 128, 1, 129, 257, 129, 1,  Solution:  For 2 “if statements”, 22 = 4 control flow
129, 257, 129) paths are possible:
is repeated 10 times. The number of conflict misses if
experienced by the cache is ______. e1

Solution:  A miss is not considered a conflict miss if


e3
the block is accessed for the first time. e2
if
1st round: (2 + 2) misses if
e4 e4
2nd round: (4 + 4) misses
\Total = 4 + (8 × 9) = 76 conflict misses e5
e5 e5 e5
Hence, the correct answer is (76).
Question Number: 61 Question Type: MCQ
Let u and v be two vectors in R2 whose Euclidean norms So for 10 “If statements”, 210 control flow paths will
satisfy u = 2 v . What is the value of a such that w = be there.
u +av bisects the angle between u and v? Hence, the correct answer is (1024).

01_GATE 2016 CSIT Set-1.indd 30 6/13/2017 11:21:11 AM


GATE 2017 Solved Paper CSIT: Set – 1 | xxxi

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.

01_GATE 2016 CSIT Set-1.indd 31 6/13/2017 11:21:11 AM


GATE 2017 Solved Paper
CSIT: Computer Science and Information Technology
Set – 2
Number of Questions: 65 Total Marks:100

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

⇒ x = 15, y = 5 095 008


S
Hence, the correct option is (B).
P 09
Question Number: 3 Question Type: MCQ
Saturn is ____ to be seen on a clear night with the Q 08
08
naked eye. 075

(A) enough bright (B) bright enough


(C) as enough bright (D) bright as enough If the possibility of a thunderstorm is given by how
Hence, the correct option is (B). fast air pressure rises or drops over a region, which of

01_GATE 2016 CSIT Set-2.indd 32 6/13/2017 4:59:47 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xxxiii

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

01_GATE 2016 CSIT Set-2.indd 33 6/13/2017 4:59:48 PM


xxxiv | GATE 2017 Solved Paper CSIT: Set – 2

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and
Question 36 to Question 65 carry 2 marks each.
Code Data File
Question Number: 11 Question Type: NAT
Consider the following tables T1 and T2.
P Q R S
2 2 2 2 Registers Stack
3 8 8 3
7 3 3 2
5 8 9 7
6 9 5 7 Thread T
8 5 7 2
9 8 Single threads process

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

Registers Registers Registers

Stack Stack Stack

Counter Counter Counter

T1 T2 T3

Single process P with 3 threads Multi threading Hence, the correct option is (B).

01_GATE 2016 CSIT Set-2.indd 34 6/13/2017 4:59:48 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xxxv

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

A R B R. Intermediate representation iii. Semantic analyser


1 m S. Token stream iv. Lexical analyser

a b c d (A) P-(ii), Q-(iii), R-(iv), S-(i)


(B) P-(ii), Q-(i), R-(iii), S-(iv)
A&R (C) P-(iii), Q-(iv), R-(i), S-(ii)
B (D) P-(i), Q-(iv), R-(ii), S-(iii)
a b c c d
Solution:  Lexical Analysis phase processes char-
acter stream and generates tokens, e.g., identifier or
keywords.

01_GATE 2016 CSIT Set-2.indd 35 6/13/2017 4:59:49 PM


xxxvi | GATE 2017 Solved Paper CSIT: Set – 2

Tokens are processed by Syntax analysis analyzer. 2 16 2


(A) and ⋅ (B) and 0 ⋅
Syntax tree is processed by Semantic analyzer. π π π
Intermediate code such as 3—address code is used for 4 4 16
code generation process. (C) and 0 ⋅ (D) and ⋅
π π π
Hence, the correct option is (C).
Solution: 
Question Number: 18 Question Type: MCQ
2π πx 
Consider the following statements about the routing f 1 ( x) = cos  
protocols, Routing Information Protocol (RIP) and 2  2 
Open Shortest Path First (OSPF) in an IPv4 network. Rπ 4
I. RIP uses distance vector routing. ⇒ f 1 (1/ 2) = 2 gives = 2⇒R=
2 2 π
II. RIP packets are sent using UDP.
III. OSPF packets are sent using TCP.
1
2R −2 R  πx 2R
IV. OSPF operation is based on link-state routing.
Also ∫ f ( x) dx =
0
2
gives
π   cos 
2 
+ S ( x )10 =
π
Which of the statements above are CORRECT? ⇒S =0
(A) I and IV only
Hence, the correct option is (C).
(B) I, II and III only
(C) I, II and IV only Question Number: 20 Question Type: MCQ
(D) II, III and IV only In a file allocation system, which of the following allo-
cation schemes(s) can be used if no external fragmen-
Solution: Statement (1): RIP uses distance vector tation is allowed?
routing. “CORRECT” I. Contiguous
RIP is one of the oldest DVR protocol which employ II. Linked
the hop count as a routing metric. III. Indexed
Statement (2): RIP packets are sent using UDP. (A) I and III only (B) II only
­“CORRECT” (C) III only (D) II and III only
RIP uses the UDP as its transport protocol, and is
­assigned the reserved port no 520. Solution:  Contiguous allocation suffer from exter-
nal fragmentation. But, linked and indexed allocation
Statement (3): OSPF packets are sent using TCP.
schemes free from external fragmentation.
­“INCORRECT”
Hence, the correct option is (D).
OSPF does not use a transport protocol, such as UDP
(or) TCP, but encapsulates its data directly in IP ­packets.
Question Number: 21 Question Type: NAT
Statement (4): OSPF operation is based on link state Consider a quadratic equation x2 − 13x + 36 = 0 with
routing. “CORRECT” coefficients in a base b. The solutions of this equa-
tion in the same base b are x = 5 and x = 6. Then b =
OSPF is a routing protocol which uses link state routing
(LSR) and works within a single autonomous system. ___________.
Hence, the correct option is (C). Solution:  Clearly 13 = 1 ⋅ 10 + 3 and 36 = 3 × 10 + 6
⇒ base b = 10.
Question Number: 19 Question Type: MCQ The quadratic equation with solutions x = 5 and x = 6
πx  1 1 is x22R− 11x + 30 = 0
If f ( x ) = R sin   + S , f   = 2 and ∫ f ( x ) = dx = , then the constants R and S are, respectively
 2  2 0 π
According to the given condition, we have b + 3 = 11
1 2R and 3b + 6 = 30 ⇒ b = 8
= 2 and ∫ f ( x ) = dx = , then the constants R and S are, respectively
0 π Answer is 8.

01_GATE 2016 CSIT Set-2.indd 36 6/13/2017 4:59:50 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xxxvii

Alternate Solution: int *ptr ;


x2 −13x + 36 = 0 (given quadratic equation) x = 0;
In base b, 13 = 1 × b1 + 3 × b0 = b + 3 and ptr = &x;
36 = 3 × b1 + 6 × b0 = 3b + 6 y = * ptr;
So, the equation becomes x2 − b + 3x + 3b + 6 = 0 * ptr = l;
Since, x = 5 is a solution print f (“%d, %d,” x, y);
52 − b + 3 5 + 3b + 6 = 0 ⇒ b = 8. }
Similarly, by putting x = 6, we get b = 8. The output of invoking printxy (l, l) is
Hence, the correct answer is (8). (A) 0,0  (B) 0,1  (C) 1,0  (D) 1,1
Solution: 
Question Number: 22 Question Type: MCQ
Identify the language generated by the following gram- x 1 y 1
mar, where S is start variable.
S → XY 100
200
X → aX | a
Y → aYb | ∈
ptr 100
(A) {aman | m ≥ n, n > 0}
(B) {aman | m ≥ n, n ≥ 0} \ 1,0 is printed
(C) {aman | m > n, n ≥ 0} Hence, the correct option is (C).
(D) {aman | m > n, n > 0} Question Number: 25 Question Type: NAT
Solution:  The given grammar with S as start symbol is The maximum number of IPv4 router addresses that
S → XY can be listed in the record route (RR) option field of an
X → aX|a IPv4 header is _________.
Y → aYb|∈ Solution:  A record route option is used to record the
internet routers that handles the datagram. It can list up
From Non-terminal X, we can generate any number of to nine router addresses. It can be used for debugging
a’s including a single ‘a’ and from Y equal number of and management purpose.
a’s and b’s.
Hence, the correct answer is (9).
Hence, L ={ambn|m > n, n ≥ 0}
Question Number: 26 Question Type: MCQ
Hence, the correct option is (C).
Consider the set X = {a, b, c, d, e} under the partial
Question Number: 23 Question Type: MCQ ordering R = {(a, a), (a , b), (a , c), (a, d), (a, e), (b, b),
The representation of the value of a 16-bit unsigned inte- (b, c), (b, e), (c, c), (c, e), (d, d), (d, e), (e, e)}. The Hasse
ger X in hexadecimal number system is BCA9. The rep- diagram of the partial order (X, R) is shown below.
resentation of the value of X in octal number system is e
(A) 571244 (B) 736251 o
(C) 571247 (D) 136251
Solution: (BCA9)16 → (136251)8 co
Convert hexadecimal to octal number system. od
Hence, the correct option is (D).
bo
Question Number: 24 Question Type: MCQ
Consider the following function implemented in C:
void printxy (int x, int y) { o
a

01_GATE 2016 CSIT Set-2.indd 37 6/13/2017 4:59:51 PM


xxxviii | GATE 2017 Solved Paper CSIT: Set – 2

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

01_GATE 2016 CSIT Set-2.indd 38 6/13/2017 4:59:51 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xxxix

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.

50 Hence, the correct option is (D).


V ≤
3 Question Number: 33 Question Type: NAT
V ≤ 16 1 1 −1   −1 −2 −1
Let P =  2 −3 4  and Q =  6 12
  6 be two matrices.
Hence, the correct answer is (16).
1 1 −1   −1 −2 −1  3 −2 3   5 10 5
Question Number: 31 Question Type: MCQ 
Let P =  2 −3 4  and Q =  6 12
  6
be two matrices.
Let p, q, r denote the statements “It is raining,” “It is 
 3 −2 3 
cold”, and “ It ispleasant,” respectively.
 
 the state-5 Then the rank of P + Q is _____________.
Then 5 10
ment “It is not raining and it is pleasant, and it is not Solution:
pleasant only if it is raining and it is cold” is repre-
sented by
0 −1 12 
(A) (←p ∧ r) ∧ (←r→(p ∧ q)) 0 −1 12 
P + Q = 8 9 10 
(B) (←p ∧ r) ∧ ((p ∧ q)→←r) P + Q = 8 9 10 
8 8 8
(C) (←p ∧ r) ∨ ((p ∧ q)→←r) 8 8 8
8 9 10 
(D) (←p ∧ r) ∨ (r → (p ∧ q)) 8 9 10 
R1 ↔ R2 ∼ 0 −1 −2 
Solution:  X only if Y is same as X ⇒ Y R1 ↔ R2 ∼ 0 −1 −2 
1 1 1 
1 1 1 
“it is not raining and it is pleasant” = ¬p ∧ r R3
R3
“it is not pleasant only if it is raining and it is cold” = 8
¬r → (p ∧ q) 8
8 −9 10 
8 −9 10 
\(¬p ∧ r ) ∧ (¬r → (p ∧ q)). 8 R3 − R1 ∼ 0 −1 −2 
8 R3 − R1 ∼ 0 −1 −2 
Hence, the correct option is (A). 0 −1 −2 
0 −1 −2 
Question Number: 32 Question Type: MCQ 8 −9 10 
8 −9 10 
The Breadth First Search (BFS) algorithm has been R3 − R2 ∼ 0 −1 −2 
implemented using the queue data structure. Which R3 − R2 ∼ 00 −01 −20
0 0 0
one of the following is a possible order of visiting the 
nodes in the figure below? ∴ Rank is 2
∴ Rank is 2

M N O Hence, the correct answer is (2).


Question Number: 34 Question Type: MCQ
Consider socket API on a Linux machine that supports
connected UDP sockets. A connected UDP socket is
R
a UDP socket on which connect function has already
Q P
been called. Which of the following statements is/are
CORRECT?
(A) MNOPQR I. A connected UDP socket can be used to communi-
(B) NQMPOR cate with multiple peers simultaneously.
(C) QMNROP II. A process can successfully call connect function
again for an already connected UDP socket.
(D) POQNMR

01_GATE 2016 CSIT Set-2.indd 39 6/13/2017 4:59:52 PM


xl | GATE 2017 Solved Paper CSIT: Set – 2

(A) I only Question Number: 35 Question Type: NAT


(B) II only The minimum possible number of states of a determin-
(C) Both I and II istic automaton that accepts the regular language
(D) Neither I nor IIs L = {w1 aw2 | w1 ,w2 ∈{a, b}*, |w1| = 2, |w2| ≥ 3} is
____________.
Solution:  A process with a connected UDP socket can
call connect again for that socket for one of two r­ easons: Solution:  The given regular language is
(1) To specify a new IP address and port. L = {w1aw2 | w1, w2 ∈{a, b}*, |w1| = 2 |w2| ≥ 3}
(2) To unconnect the socket. The minimal deterministic finite automata accepting
L is:
Hence, the correct option is (B).
a, b

a, b a, b a a, b a, b a, b

R a, b Figure for question 35

Hence, the correct answer is (8).


Question Number: 36 Question Type: NAT Average length of the character
A message is made up entirely of characters from the = 2(0.19 + 0.22) + 2(0.34) + 3(0.08 + 0.17)
set X = {P, Q, R, S, T}. The table of probabilities for = 2(0.41) + 2(0.34) + 3(0.25)
each of the characters is shown below:
= 0.82 + 0.68 + 0.75
Character Probability
= 2.25 bits
P 0.22
\ Message length = 100 × 2.25 bits = 225 bits.
Q 0.34
Hence, the correct answer is (225).
R 0.17
S 0.19 Question Number: 37 Question Type: MCQ
T 0.08 The next state table of a 2-bit saturating up-counter is
Total 1.00 given below.

If a message of 100 characters over X is encoded Q1 Q0 Q1+ Q0+


using Huffman coding, then the expected length of the 0 0 0 1
encoded message in bits is _____ 0 1 1 0
Solution:  Huffman tree is as follows 1 0 1 1
1.0 1 1 1 1

0.59 The counter is built as a synchronous sequential circuit


0.41 using T flip-flops. The expression forT1 and T0 are
T = QQ , T0 = Q1Q0
(A)
0.25 0.17
S 0.19 0.22 T1 = Q1Q0 , T0 = Q1 + Q0
(B)
Q
P
T1 = Q1 + Q0 , T0 = Q1 + Q0
(C)
0.08 0.17
T R T1 = Q1Q0 , T0 = Q1 + Q0
(D)

01_GATE 2016 CSIT Set-2.indd 40 6/13/2017 4:59:54 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xli

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

Hence, the correct option is (B). gx ( z) = ∑ p j z j .


j =0
For a certain discrete random variable Y, there exists
Question Number: 38 Question Type: NAT a scalar b∈[0,1]such that gY (z) = (1 − β + βz)N. The
Consider the set of processes with arrival time (in mil- expectation of Y is
liseconds). CPU burst time (in milliseconds), and pri-
(A) Nb(1 − b)
ority (0 is the highest priority) shown in the table. None
of the processes have I/O burst time. (B) Nb
(C) N(1 − b)
Process Arrival Time Burst Time Priority (D) Not expressible in terms of N and b alone
P1 0 11 2 Solution:  Hence, the correct option is (B).
P2 5 28 0
Question Number: 40 Question Type: NAT
P3 12 2 3
The read access times and the hit ratios for different
P4 2 10 1
caches in a memory hierarchy are as given in the table.
P5 9 16 4
Cache Read Access Time (in nanoseconds) Hit Ratio
The average waiting time (in milliseconds) of all the I-cache 2 0.8
processes using pre-emptive priority scheduling algo- D-cache 2 0.9
rithm is __________ L2-cache 8 0.9

Solution: The read access time of main memory is 90 nanosec-


onds. Assume that the caches use the referred word-
PID AT BT Priority CT TAT Waiting Time first read policy and the write back policy. Assume that
all the caches are direct mapped caches. Assume that
P1 0 11 2 4 49 38
the dirty bit is always 0 for all the blocks in the caches.
P2 5 28 0 33 28 0 In execution of a program, 60% of memory reads are
P3 12 2 3 51 39 37 for instruction fetch and 40% are for memory operand
P4 2 10 1 40 38 28
fetch. The average read access time in nanoseconds (up
to 2 decimal places) is ______.
P5 9 16 4 67 58 42
Solution:  Given,
Main
Gantt Chart Cache I-Cache D-Cache L2-Cache Memory

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

01_GATE 2016 CSIT Set-2.indd 41 6/13/2017 4:59:55 PM


xlii | GATE 2017 Solved Paper CSIT: Set – 2

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

01_GATE 2016 CSIT Set-2.indd 42 6/13/2017 4:59:56 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xliii

--n1; FROM top_ scorer AS tc


n - = nl; WHERE tc.country = ‘Germany’)
printf (“%d”, n) ; The number of tuples returned by the above SQL query
return 0; is ___________.
}
Solution:  Player
The output of the program is ______________. Klose
Solution:  m = 10 Ronaldo
n = ++m will increment m and assign it to n ⇒ n =11& G Muller
m=1 Fontaine
n1 = m ++ will assign m to n1 and then increment m by 1 Pele
⇒ n1 = 11, m = 12 Klinsmann
n– –; decrement n by1 ⇒ n 10 Kocsis
– –n; decrement n by1 ⇒ n 10 Hence, the correct answer is (7).
n– = n; sameas n = n – n = 10 – 10 = 0 Question Number: 45 Question Type: MCQ
\ ‘0’ is printed Given f(w, x, y, z) = Sm (0, 1, 2, 3, 7, 8, 10) + Sd(5, 6,
Hence, the correct answer is (0). 11, 15), where d represents the do not care condition in
Karnaugh maps. Which of the following is a minimum
Question Number: 44 Question Type: NAT product-of-sums (POS) form of f(w, x, y, z)?
Consider the following database table named (A) f = ( w + z )( x + z )
top_scorer.
f = ( w + z )( x + z )
(B)
top_scorer.
f = ( w + z )( x + z )
(C)
Player Country Goals f = ( w + z )( x + z )
(D)
Klose Germany 16
Solution: 
Ronald Brazil 15
yz
G Muller Germany 14 wx
Fontaine France 13 00 01 11 10

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)

Consider the following SQL query: = ( w + z )( x + z )


SELECT ta.player FROM top _scorer AS ta
WHERE ta.goals > ALL (SELECT tb. goals Hence, the correct option is (a).
FROM top _ scorer AS tb Question Number: 46 Question Type: NAT
WHERE tb.country = ‘Spain’) In a B+ tree, if the search-key value is 8 bytes long,
AND ta.goals > ANY ( SELECT tc. goals the block size is 512 bytes and the block pointer size

01_GATE 2016 CSIT Set-2.indd 43 6/13/2017 4:59:57 PM


xliv | GATE 2017 Solved Paper CSIT: Set – 2

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

IV. Given a Turning machine M and a string w, is → q0 {q2} {q1} (q0}


w∈ L(M)? q1 {q2} {q2} (q0}
(A) I and IV only q2 {q0} ∅ ∅
(B) II and III only q3 ∅ ∅ {q2}
(C) II, III and IV only
(D) III and IV only Then δˆ (q2, aba is)
Solution:  L(R) is the language represented by regular (A) ∅
expression. (B) {q0, q1, q3}
L(G) is the language generated by context free ­grammar. (C) {q0, q1, q2}
L(M) is the language accepted by Turing Machine. (D) {q0, q2, q3}
I. The problem a given regular expression R and a string
w, is w ∈ L(R)? , is a membership problem. Member- Solution: 
ship problem is decidable for Finite state machine and NFA-∈ Transition is shown in the table
regular expression. d ∈ a b
III. A given context free grammar G, is L(G) is Σ* for → q0 {q2} {q1} (q0}
some alphabet Σ?, is undecidable problem. We cannot
q1 {q2} {q2} (q3}
check whether L(G) = Σ* or not but rather we can check
complement of L(G) is ϕ .Since, context free language q2 {q0} F F
are not closed under complement operation L(G ) may q3 F F {q2}
be language accepted by Turing Machine and we can-
not check emptiness for Turing machine. The process is, we start with ∈-closure of q2 then
IV. Given a Turing Machine M and a string w, is w for each input first take the transition then calculate
∈ L(M)? , is a membership problem for TM. Membership ∈-closure.
problem is not a decidable problem for TM. q2 is the start for processing, we take ∈-closure which
Hence, the correct option is (D). is {q0, q2}and process “aba”

01_GATE 2016 CSIT Set-2.indd 44 6/13/2017 4:59:58 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xlv

δ (q 2, aba) Take c closure and process “aba”

δ (q 2, aba) δ (q 0, aba) Take Transition

ϕ δ (q 1, ba) Calculac c closure

δ (q 1, ba) δ (q 2, ba) δ (q 0, ba) Take Transition

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

Hence, the correct option is (C).

Question Number: 50 Question Type: MCQ S → XY


Consider the following languages. X → aX | ∈
L1 = {ap | pis a prime number} Y → bYcc | ∈
L2 = {an bm c2m |n ≥ 0, m ≥ 0} III. L3 is not context free but recursive is CORRECT.
L3 = {an bn c2n |n ≥ 0} L3 is standard context sensitive language.
L4 = {an bn |n ≥ 1} IV. L4 is deterministic context free is CORRECT; the
Which of the following are CORRECT? grammar is S→ aSb|ab.
I. L1 is context-free but not regular. Hence, the correct option is (D).
II. L2 is not context-free. Question Number: 51 Question Type: MCQ
III. L3 is not context-free but recursive. Consider a binary code that consists of only four valid
IV. L4 is deterministic context-free. code words as given below:
(A) I , II and IV only (B) II and III only 00000,01011,10101,11110
(C) I and IV only (D) III and IV only Let the minimum Hamming distance of the code be p
and the maximum number of erroneous bits that can
Solution:  The given languages are be corrected by the code be q. Then the values of p and
L1 = {ap | p is a prime number} q are
L2 = {anbmc2m | n ≥ 0, m ≥ 0} (A) p = 3 and q = 1 (B) p = 3 and q = 2
L3 = {anbnc2n | n ≥ 0} (C) p = 4 and q = 1 (D) p = 4 and q = 2
L4 = {anbn | n ≥ 1}
Solution:  Given:
Statements are:
Code 1 00000
I.  L1 is context free but not regular is INCORRECT,
It required a Turing machine to accept L1. Code 2 01011
II. L2 is not context free is INCORRECT; the con- Code 3 10101
text free grammar is Code 4 11110

01_GATE 2016 CSIT Set-2.indd 45 6/13/2017 4:59:59 PM


xlvi | GATE 2017 Solved Paper CSIT: Set – 2

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

Which of the following best describes current state of a, b, c, d a, b, c


the system? before 2 before 2
(A) Safe, Deadlocked
Therefore, 53 + 1 = 54
(B) Safe, Not Deadlocked
Hence, the correct answer is (54).
(C) Not Safe, Deadlocked
(D) Not Safe, Not deadlocked Question Number: 54 Question Type: MCQ
If w, x, y, z are Boolean variables, then which one of the
Solution:  following is INCORRECT?
PID Current Allocation Max Need Available Need (A) wx + w(x + y) + x(x + y) = x + wy
P1 3 3 2 4 (B) wx ( y + z ) + wx = w + x + yz
P2 1 6 - 5 (C) ( wx ( y + xz ) + wx ) y = xy
P3 3 5 - 2 (D) (w + y)(wxy + wyz) = wxy + wyz
Solution: 
With the above state of systems, we can get the follow-
ing 2 safe sequences. (A) LHS: wx + w(x + y) +x (x + y) = x + wy
(1) < P3, P2, P1 > RHS:
(2) < P3, P1, P2 > ⇒ wx + wy + x+ xy [xx = x]
Hence, system is in safe state, no deadlocked Option ⇒ x[1 + y + w] + wy [1 + x = 1]
B is correct. ⇒ x + wy
Hence, the correct option is (B). ⇒ L.H.S=R.H.S

01_GATE 2016 CSIT Set-2.indd 46 6/13/2017 4:59:59 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xlvii

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

01_GATE 2016 CSIT Set-2.indd 47 6/13/2017 5:00:02 PM


xlviii | GATE 2017 Solved Paper CSIT: Set – 2

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

01_GATE 2016 CSIT Set-2.indd 48 6/13/2017 5:00:03 PM


GATE 2017 Solved Paper CSIT: Set – 2 | xlix

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.

01_GATE 2016 CSIT Set-2.indd 49 6/13/2017 5:00:04 PM


l | GATE 2017 Solved Paper CSIT: Set – 2

while (r >= y) { Solution:  Given, program is:


r = r – y; while (r ≥ y){
q = q +1; r = r – y;
} q = q + 1;
Which of the following conditions on the variables x, y, }
q and r before the execution of the fragment will ensure If we want to final value as x == (y × q + r ). Then initial
that the loop terminates in a state satisfying the condi- value of r should be equal to x (Since y is subtracted
tion x = = (y*q + r)? from r each time in given code). Q incremented by 1 (q
(A) (q == r) && (r == 0) is quotient here). To avoid undefined behavior , value of
(B) (x > 0) && (r == x) && (y > 0) y should be greater than zero.
(C) (q == 0) && (r == x) && (y > 0) Therefore, (q == 0)&&(r == x)&&(y > 0)
(D) (q == 0) && (y > 0) Hence, the correct option is (C).

01_GATE 2016 CSIT Set-2.indd 50 6/13/2017 5:00:04 PM


Detailed Analysis of GATE 2016 Papers
GATE CSIT Solved Paper 2016 (Set 1) Detailed Analysis
1 Mark 2 Marks Total Total
Subject Topic
Questions Questions Questions Marks

General Aptitude Numerical Ability 2 4 6 10


  Verbal Ability 3 2 5 5
Total Marks         15
Engineering Maths Discrete Maths 2 3 5 8
  Calculus 1 - 1 1
  Probability 1 1 2 3
  Linear Algebra 1 - 1 1
Total Marks         13
Digital Number System        
  Boolean Algebra 1   1 1
  Combinational Circuit   1 1 2
  Sequential Circuits 1   1 1
Total Marks         4
Machine instructions,
Computer
Addressing modes and number 1   1 1
Organization
representation
ALU and Data Path, CPU
         
Control Design
  Memory Interface, I/O Interface   1 1 2
  Instruction Pipelining   1 1 2
Cache and Main Memory,
  1   1 1
Secondary Storage
Total Marks         6

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

00_GATE_CSIT_Prelims.indd 51 6/12/2017 2:02:41 PM


lii | Detailed Analysis of GATE 2016 Papers

  Divide & Conquer strategy        


  Greedy design Technique        
  Dynamic programming        
  Sorting and Searching 2   2 2
Graph search, Spanning trees
  1 3 4 7
and Shortest paths
Total Marks         14

Theory of Finite Automata & Regular


2   2 2
Computation languages
Context-free languages & Push
    2 2 4
down Automata
Recursive enumerable
  sets, Turing machines and 1 1 2 3
decidability
Total Marks         9
Compiler design Lexical analysis & parsing        
  Syntax directed translation   1 1 2
  Intermediate code generation        
  Code optimization 1   1 1
Total Marks         3
Processes, Threads and CPU
Operating Systems 1   1 1
scheduling
  Process Synchronization   1 1 2
  Deadlocks        
Memory management and
    2 2 4
Virtual memory
  File systems   1 1 2
Total Marks         9
Databases ER model, Relational model        
  Normalization 1   1 1
  Relational algebra        
  SQL 1   1 1
Transactions & Concurrency
  1 1 2 3
management
  File Organization        
Total Marks         5
OSI Layers and LAN
Computer Networks 1 1 2 3
Technologies
Routing Algorithms and
  1   1 1
application layer protocols

00_GATE_CSIT_Prelims.indd 52 6/12/2017 2:02:42 PM


Detailed Analysis of GATE 2016 Papers  |  liii

  TCP/UDP   1 1 2
IP(V4), IPV6 and wireless
    1 1 2
networks
  Network Security   1 1 2
Total Marks         10

GATE CSIT Solved Paper 2016 (Set 2) Detailed Analysis


1 Mark 2 Marks Total Total
Subject Topic
Questions Questions Questions Marks
General Aptitude Numerical Ability 3 3 6 9
  Verbal Ability 2 2 4 6
Total Marks         15
Engineering Maths Discrete Maths 3 3 6 9
  Probability 1 - 1 1
  Linear Algebra 2 1 3 4
Total Marks         14
Digital Number System        
  Boolean Algebra 1   1 1
  Combinational Circuit 1   1 1
  Sequential Circuits      
Total Marks         2
Machine instructions,
Computer
Addressing modes and number 2 1 3 4
Organization
representation
ALU and Data Path, CPU
    1 1 2
Control Design
  Memory Interface, I/O Interface        
  Instruction Pipelining   1 1 2
Cache and Main Memory,
    2 2 4
Secondary Storage
Total Marks         12
Programming &
C Programming   1 1 2
Data Structures
  Functions 1 1 2 3
  Pointers & Structures        
  Stacks, Queues & Linked lists   3 3 6
  Trees and Heaps        
  Graphs        
Total Marks         11

00_GATE_CSIT_Prelims.indd 53 6/12/2017 2:02:42 PM


liv | Detailed Analysis of GATE 2016 Papers

Algorithms Asymptotic analysis 1 2 3 5


  Divide & Conquer strategy        
  Greedy design Technique        
  Dynamic programming 1 1 2 3
  Sorting and Searching 1   1 1
Graph search, Spanning trees
  1   1 1
and Shortest paths
Total Marks         10

Theory of Finite Automata & Regular


2 1 3 4
Computation languages
Context-free languages & Push
    1 1 2
down Automata
Recursive enumerable
  sets, Turing machines and 1 1 2 3
decidability
Total Marks         9
Compiler design Lexical analysis & parsing 1 2 3 5
  Syntax directed translation        
  Intermediate code generation        
  Code optimization        
Total Marks         5
Processes, Threads and CPU
Operating Systems   1 1 2
scheduling
  Process Synchronization   2 2 4
  Deadlocks        
Memory management and
  1   1 1
Virtual memory
  File systems        
Total Marks         7
Databases ER model, Relational model   1 1 2
  Normalization        
  Relational algebra 1 1 2 3
  SQL        
Transactions & Concurrency
  1   1 1
management
  File Organization        
Total Marks         6

00_GATE_CSIT_Prelims.indd 54 6/12/2017 2:02:42 PM


Detailed Analysis of GATE 2016 Papers  |  lv

OSI Layers and LAN


Computer Networks 1 2 3 5
Technologies
Routing Algorithms and
  1   1 1
application layer protocols
  TCP/UDP        
IP(V4), IPV6 and wireless
    1 1 2
networks
  Network Security 1   1 1
Total Marks         9

00_GATE_CSIT_Prelims.indd 55 6/12/2017 2:02:42 PM


GATE 2016 Solved Paper
CSIT: Computer Science and Information Technology
Set – 1
Number of Questions: 65 Total Marks:100.0

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

01_GATE 2016 CSIT Set-1.indd 56 6/12/2017 1:54:00 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lvii

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

Hence the correct option is (B). of f (x)?


(A) (x3 + 8) (B) (x – 1)
Question Number: 7 Question Type: MCQ
(C) (2x – 5 ) (D) (x + 1)
Indian currency notes show the denomination indicated
in at least seventeen languages. If this is not an indica- Solution:  The given function is
tion of the nation’s diversity, nothing else is. f(x) = 2x7 + 3x – 5
Which of the following can be logically inferred from
f(1) = 2 + 3 – 5 = 0
the above sentences?
(A)  India is a country of exactly seventeen ⇒ x – 1 is a factor of f(x)
­languages. The other expressions are not factors.
(B) Linguistic pluralism is the only indicator of a Hence, the correct option is (B).
nation’s diversity.
Question Number: 10 Question Type: MCQ
(C) Indian currency notes have sufficient space
In a process, the number of cycles to failure decreases
for all the Indian languages.
exponentially with an increase in load. At a load of
(D) Linguistic pluralism is a strong evidence of 80 units, it takes 100 cycles for failure. When the load
India’s diversity. is halved, it takes 10000 cycles for failure. The load for
Solution:  According to the statement nothing else, which the failure will happen in 5000 cycles is ___.
apart from the currency note, can represent the diver- (A) 40.00 (B) 46.02
sity better. Hence, (D) can be inferred. (C) 60.01 (D) 92.02
Hence, the correct option is (D).
Solution:  Let the load be x and the number of cycles to
Question Number: 8 Question Type: MCQ failure be y. As y decreases exponentially with x
Consider the following statements relating to the level k
of poker play of four players P, Q, R and S. y = x (1)
a
I. P always beats Q
⇒ yax = k
II. R always beats S
III. S loses to P only sometimes ⇒ log y + x log a = log k
IV. R always loses to Q For x = 40, y = 104 and for x = 80, y = 102
Which of the following can be logically inferred from \ log 104 + 40log a = log 102 + 80 log a
the above statements? 1
4−2
(i) P is likely to beat all the three other players ⇒ = log a ⇒ a = 10 20 
40
(ii) S is the absolute worst player in the set

01_GATE 2016 CSIT Set-1.indd 57 6/12/2017 1:54:01 PM


lviii | GATE 2016 Solved Paper CSIT: Set – 1

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 

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and Question Number: 13 Question Type: NAT
Question 36 to Question 65 carry 2 marks each. sin ( x − 4 )
lim = _______ .
Question Number: 11 Question Type: NAT x→4 x−4
Let p, q, r, s represent the following propositions.
p : x ∈ {8,9,10,11,12} sin ( x − 4 ) sin ( x − 4 )
Solution:  lim = lim =1
q : x is a composite number x→4 x−4 ( x − 4 )→ 0 x−4
r : x is a perfect square ⎛ sin θ ⎞
⎜⎝∵ θlim = 1⎟
s : x is a prime number →0 θ ⎠

The integer x ≥ 2 which satisfies Hence, the correct Answer is (1).
¬ ((p ⇒ q) ∧ (¬r ∨ ¬s)) is ____. Question Number: 14 Question Type: NAT
Solution:  A probability density function on the interval [a, 1] is
\ ⎤[(p ⇒ q) ∧ (⎤ r ∨ ⎤ s)] given by 1/x2 and outside this interval the value of the
function is zero. The value of a is _____.
≡ ⎤ [(⎤ p ∨ q) ∧ (⎤ r ∨ ⎤ s)]
⎧1
≡ ⎤ (⎤ p ∨ q) ∨ ⎤ (⎤ r ∨ ⎤ s) ⎪ ; x ∈[a,1]
Solution:  f(x) = ⎨ x 2
≡ (p ∧ ⎤q) ∨ (r ∧ s) ⎪0 ; otherwise

\ The value of x that satisfies the above proposition is
11 only. As f(x) is a probability density function,
Hence, the correct Answer is (11). We have

Question Number: 12 Question Type: MCQ ∫ f ( x ) dx = 1
Let an be the number of n-bit strings that do not contain −∞ 
two consecutive 1 s. Which one of the following is the 1
1
recurrence relation for an? ⇒ ∫ x 2 dx = 1
(A) an = an–1 + 2an–2 (B) an = an –1 + an–2 a 
1
(C) an = 2an –1 + an–2 (D) an = 2an –1+ 2an–2 −1⎤
⇒ =1
x ⎥⎦ a
Solution:  a1 = 0, 1 (2 strings) 
a2 = 00, 01, 10 (3 strings) 1
⇒ –1 + = 1
a3 = 000, 001, 010, 100, 101 (5 strings) a
1
a3 = a2 + a1= 2 + 3 = 5 strings ⇒ a= = 0.5.
2
an = an – 1 + an – 2.
Hence, the correct Answer is (0.5).
Hence, the correct option is (B).

01_GATE 2016 CSIT Set-1.indd 58 6/12/2017 1:54:03 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lix

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

01_GATE 2016 CSIT Set-1.indd 59 6/12/2017 1:54:06 PM


lx | GATE 2016 Solved Paper CSIT: Set – 1

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
}

Which one of the following expressions, when placed


in the blank above, will not result in a type checking
\ P is TRUE
error?
Q
(A) f (s,*s) (B) i = f (i,s)
b 6 c
(C) f (i,*s) (D) f (i,*p) 1 3
Solution:  As per the program given in question the a d
function prototype is void and its arguments are int,
short with return type as void. 8 2
Hence f(i, *p) matches with the arguments.
e
Hence, the correct option is (D).

01_GATE 2016 CSIT Set-1.indd 60 6/12/2017 1:54:06 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxi

Shortest path: (A) {an bm | n, m ≥ 0}


a–b–c–d (B) {w ∈ {a, b} * | w has equal number of a’s and
1 + 6 + 3 = 10 b’s}
(C) {an | n ≥ 0 } U {bn |n ≥ 0 } U {anbn | n ≥ 0}
b 7 c
2 4 (D) {a, b}*

a d Solution:  Consider some string derivations from given


grammar:
9 3
S → ∈
e S → aS
Shortest path: S → a
a–e–d S → bS
9 + 3 = 12 → b
Q is false. S → aS
Hence, the correct option is (A). → abS
Question Number: 25 Question Type: NAT → ab
Consider the following C program. S → bS
# include<stdio.h> → baS
void mystery (int *ptra, int *ptrb) { → ba
int *temp; S → aS
temp = ptrb; → abS
ptrb = ptra; → abaS
ptra = temp; → aba.
}
The strings generated by given grammar are
int main ( ) {
{∈, a, b, ab, ba, aba…}
int a = 2016, b = 0, c = 4, d = 42;
mystery (&a, &b); As per the above strings we can conclude that the lan-
guage is {a, b}*
if (a < c)
Hence, the correct option is (D).
mystery(&c, &a);
mystery (&a, &d); Question Number: 27 Question Type: MCQ
printf(“%d\n”, a) Which of the following decision problems are not
} decidable?
I. Given NFAs N1 and N2, is
The output of the program is _____.
L (N1) ∩ L (N2) = Φ?
Solution:  The value of “a” will be 2016 because the
II. Given a CFG G = (N, S, P, S) and a string x ∈ S*,
routine mystery ( ) is manipulating with the addresses
does x ∈ L(G)?
of variables and the values of variables a, b, c, d are not
changing. III. Given CFG’s G1 and G2, is
Hence, the correct Answer is (2016). L(G1) = L(G2)?
Question Number: 26 Question Type: MCQ IV Given a TM M, is L(M) = Φ?
Which of the following languages is generated by the (A) I and IV only (B) II and III only
given grammar?
(C) III and IV only (D) II and IV only
S → aS | bS | ε

01_GATE 2016 CSIT Set-1.indd 61 6/12/2017 1:54:07 PM


lxii | GATE 2016 Solved Paper CSIT: Set – 1

Solution:  The minimum number of total variables required to


I. This decision problem is empty is decidable. convert the above code segment to static single assign-
II. This decision problem is decidable. ment form is _____.
III. This decision problem is not decidable. Solution:  An intermediate representation that facili-
IV. This decision problem is not decidable. tates certain code optimizations is known as Static
Therefore, decision problems III and IV are not single assignment form (SSA). All the assignment in
decidable. SSA is variables with distinct names.
Hence, the correct option is (C). SSA
x = u – t; x1 = u – t;
Question Number: 28 Question Type: MCQ
y = x * v; y1 = x1 * v;
Which one of the following regular expressions repre-
x = y + w; x2 = y1 + w;
sents the language: the set of all binary strings having
two consecutive 0’s and two consecutive 1’s? y = t – y; t2 = t – y1;
y = x * y; y3 = x2 * t2;
(A) (0 + 1)* 0011 (0 + 1)* + (0 + 1)* 1100 (0 + 1)*
From the above equations we conclude that total 10
(B) (0 + 1)* (00(0 + 1)*11 + 11 (0 + 1)*00) (0 + 1)*
variables x1, y1, x2, t2, y3, u, t, v, w, and y are used.
(C) (0 + 1)* 00 (0 + 1)* + (0 + 1)* 11 (0 + 1)* Hence, the correct Answer is (10).
(D) 00 (0 + 1)* 11 + 11 (0 + 1)* 00
Question Number: 30 Question Type: MCQ
Solution:  Consider an arbitrary set of CPU-bound processes with
(A) (0 + 1)*0011(0 + 1)*+ (0 + 1)*1100(0 + 1)* unequal CPU burst lengths submitted at the same time
 The above regular expression accepts the to a computer system. Which one of the following pro-
strings which has 0011 or 1100 as substrings. cess scheduling algorithms would minimize the aver-
This does not accept strings of the form age waiting time in the ready queue?
001010111. (A) Shortest remaining time first.
(B) (0 + 1)*(00(0 + 1)*11 + 11(0 + 1)*00)(0 + 1)* (B) Round - robin with time quantum less than
The above regular expression accepts all the the shortest CPU burst.
strings having two consecutive 0’s and two
(C) Uniform random.
consecutive 1’s.
(D) Highest priority first with priority proportion-
(C) (0 + 1)*00(0 + 1)*+ (0 + 1)*11(0 + 1)*
al to CPU burst length.
 The above regular expression accepts the
strings which have either 00 or 11 as sub Solution:  Shortest remaining time first would mini-
strings. mize the average waiting time in the ready queue
(D) 00(0 + 1)*11 + 11(0 + 1)*00 because in CPU scheduling, the scheduling policy-
 The above regular expression accepts the shortest job first will give a minimal average turn around
strings which starts with 00 or 11 and ends time, minimal waiting time and high throughput.
with 11 or 00 respectively. Hence, the correct option is (A).
Hence, the correct option is (B). Question Number: 31 Question Type: MCQ
Question Number: 29 Question Type: NAT Which of the following is not a superkey in a relational
Consider the following code segment. schema with attributes V, W, X, Y, Z and primary key
VY?
x = u – t;
(A) V XYZ (B) V WXZ
y = x * v;
(C) V WXY (D) V WXYZ
x = y + w;
Solution:  Primary key = VY therefore for a superkey
y = t – z; both V and Y should be present in relation schema.
Considering all the options we get
y = x * y;

01_GATE 2016 CSIT Set-1.indd 62 6/12/2017 1:54:07 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxiii

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

01_GATE 2016 CSIT Set-1.indd 63 6/12/2017 1:54:08 PM


lxiv | GATE 2016 Solved Paper CSIT: Set – 1

Question Number: 36 Question Type: NAT = 6 Σn2 – 6 × 12 + 2 Σn – 2 × 1 + a1


The coefficient of x12 in (x3 + x4 + x5 + x6 +…)3 is ____ . ⎛ n ( n + 1) ( 2n + 1) ⎞ ⎛ n ( n + 1) ⎞
= 6⎜ ⎟ – 6 + 2⎜ – 2 + a1
Solution:  ⎝ 6 ⎠ ⎝ 2 ⎟⎠
(x3 + x4 + x5 + …)3 = [x3(1 + x + x2 + …)]3 = (2n3 + 3n2 + n) + (n2 + n) – 8 + 8
= x9 (1 + x + x2 + …..)3 = 2n3 + 4n2 + 2n
1
= x9. \ an = 2n (n + 1)2(2)
(1 − x )3 
∞ We know that
= x9. ∑ C (3 − 1 + r , r ) x r a99 = k × 104
r=0 

i.e. 2 × 99 × (99 +1)2 = k × 104  (from (2))
= x9 ∑ C (r + 2, r ) x r
r=0  ⇒ 198 × 1002 = k × 104
= x [C(2, 0) x + C(3, 1) x1
9 0
⇒ 198 × 104 = k × 104
2 3
+ C(4, 2)x + C(5, 3) x + …]
⇒ k = 198
= x9 + 3x10 + 6x11 + 10x12 + … Hence, the correct Answer is (197.9 : 198.1).
From the above expression the coefficient of x12 in (x3 +
Question Number: 38 Question Type: NAT
x4 + x5 + …)3 is 10.
A function f : N+ → N+, defined on the set of positive
Hence, the correct Answer is (10).
integers N+, satisfies the following properties:
Question Number: 37 Question Type: NAT f (n) = f (n/2) if n is even
Consider the recurrence relation a1 = 8,
f (n) = f (n+5) if n is odd
an = 6n2 + 2n + an–1. Let a99 = K × 104. The value of K
is _____. Let R = {i|∃ j: f ( j) = i} be the set of distinct values that
f takes. The maximum possible size of R is ____.
Solution:  The given relation is
Solution:  From the definition of f(n) it can be observed
an = 6n2 + 2n + an – 1  (1)
that,
Where a1 = 8 f(1) = f(2) = f(3) = f(4) = f(6) = f(7) = f(8) = f(9)
Using (1), we get
= f(11) = f(12) = f(13) = f(14) = f(16) = …
a2 = 6 × 22 + 2 × 2 + a1
and f(5) = f(10) = f(15) = f(20)
a3 = 6 × 32 + 2 × 3 + a2
The maximum possible size of R = {i/$ j:
= 6 × 32 + 2 × 3 + 6 × 22 + 2 × 2 + a1
f( j) = i} is 2.
= 6 × (22 + 32) + 2 × (2 + 3) + a1
Hence, the correct Answer is (2).
a4 = 6 × 42 + 2 × 4 + a3
Question Number: 39 Question Type: NAT
= 6 × 42 + 2 × 4 + 6 × (22 + 32) + 2 × (2 + 3) + a1 Consider the following experiment.
= 6 × (22 + 32 + 42) + 2 × (2 + 3 + 4) + a1 Step 1. Flip a fair coin twice.
And Step 2. If the outcomes are (TAILS, HEADS) then
output Y and stop.
an = 6 × (22 + 32 + 42 + … + n2)
Step 3. If the outcomes are either (HEADS, HEADS)
+ 2 × (2 + 3 + 4 + … + n) + a1 or (HEADS, TAILS), then output N and stop.
= 6 × [(12 + 22 + 32 + … + n2) – 12] Step 4. If the outcomes are (TAILS, TAILS), then go
to Step 1.
+ 2 × [(1 + 2 + 3 + … + n) – 1] + a1

01_GATE 2016 CSIT Set-1.indd 64 6/12/2017 1:54:09 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxv

The probability that the output of the experiment is Y is Solution: 


(up to two decimal places) ______. Output of first multiplexer = I 0 S + I1S 
Solution:  If A = Getting the output Y then = 0⋅ P + R⋅ P 

1 = PR
P(A) =
4
Output of second multiplexer = I 0 S + I1S 
If B = Getting the output other than Y and N then
1 = R ⋅ Q + PR ⋅ Q 
P(B) =
4 = QR + PQR 
The possible events that are favourable for getting the Hence, the correct option is (D).
output Y are
Question Number: 41 Question Type: NAT
A, B ∩ A, B ∩ B ∩ A, …….
The size of the data count register of a DMA control-
The probability of getting the output Y ler is 16 bits. The processor needs to transfer a file of
= P[A ∪(B ∩ A) ∪ (B ∩ B ∩ A) 29,154 kilobytes from disk to main memory. The mem-
∪ (B ∩ B ∩ B ∩ A) ∪ ……] ory is byte addressable. The minimum number of times
the DMA controller needs to get the control of the sys-
= P(A) + P(B ∩ A) + P (B ∩ B ∩ A) + … tem bus from the processor to transfer the file from the
1 1 1 1 1 1 disk to main memory is _____.
= + × + × × + …
4 4 4 4 4 4 Solution:  The DMA will transfer data once when the
2 3
1 ⎛ 1⎞ ⎛ 1⎞ data count register reached its maximum value.
= + ⎜ ⎟ + ⎜ ⎟ + …
4 ⎝ 4⎠ ⎝ 4⎠ With 16-bits, maximum number possible is 216 = 65536.
1 i.e., one interrupt will be generated for every 65536
4 bytes.
=
⎛ 1⎞ ∴ Total numbers of interrupts
⎜⎝1 − ⎟⎠
4  29154 × 210
1 =
= = 0.33 65536 
3
= 455.5
Hence, the correct Answer is (0.33 to 0.34).
 456
Question Number: 50 Question Type: MCQ
Hence, the correct Answer is (456).
Consider the two cascaded 2-to-1 multiplexers as
shown in the figure. Question Number: 42 Question Type: NAT
R The stage delays in a 4-stage pipeline are 800, 500,
400 and 300 picoseconds. The first stage (with delay
2-to-1 2-to-1 800 picoseconds) is replaced with a functionally equiv-
0 0 0 X
MUX MUX alent design involving two stages with respective delays
R 1 S 1 S 600 and 350 picoseconds. The throughput increase of
the pipeline is ___ percent.
1 1
Solution:  Throughput = =
P Q cycle time 800
Delays for new 5-stage pipeline are 600, 350, 500, 400,
The minimal sum of products form of the output X is
300 ps.
(A)
P Q + PQR (B) P Q + QR Cycle time = 600 ps.
(C)
PQ + P Q R (D)
Q R + PQR 1
Throughput =
600 

01_GATE 2016 CSIT Set-1.indd 65 6/12/2017 1:54:13 PM


lxvi | GATE 2016 Solved Paper CSIT: Set – 1

Percent of increase in throughput The missing loop condition is


1 1 (A) a ! = n (B) b!=0

600 800 (C) b > (a + 1) (D) b ! = a
= × 100
1
Solution:  The routine max( ) computes the maximum
800 value contained in an array p[ ] of size n.
4−3
= × 800 × 100 0 1 2 3 n-5 n-4 n-3 n-2 n-1
2400
....
800
= × 100
2400
a b
= 33.33%
The maximum value is computed by comparing the
Hence, the correct Answer is (33.0 : 34.0).
values from both ends of an array. The routine should
Question Number: 43 Question Type: MCQ stop, when ‘a’ and ‘b’ get intersect each other. The con-
Consider a carry look ahead adder for adding two n-bit dition for it will be b! = a
integers, built using gates of fan - in at most two. The Hence, the correct option is (D).
time to perform addition using this adder is
Question Number: 45 Question Type: MCQ
(A) Q(1) (B) Q(log(n)) What will be the output of the following C program?
(C) ( )
Q n (D) Q(n) void count (int n) {
Solution:  But here maximum fan in (number of inputs static int d = 1;
of gate) is 2. So to implement higher order bits more printf(“%d ”,n);
number of stages are required. printf(“%d ”,d);
d ++;
Number of Number of Stages
Inputs of 2 Input Gates if (n > 1) count (n -1);
1–2 1 printf(“%d ”, d);
3–4 2 }
5–8 3 void main ( ) {
9 – 16 4 count (3);
}
So far ‘n’ bit adder, it requires log2n stages. So delay is
(A) 3 1 2 2 1 3 4 4 4 (B) 3 1 2 1 1 1 2 2 2
also in the order of log2n.
Hence, the correct option is (B). (C) 3 1 2 2 1 3 4 (D) 3 1 2 1 1 1 2

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

01_GATE 2016 CSIT Set-1.indd 66 6/12/2017 1:54:14 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxvii

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

(1) (2) (3) (5)


if (1 > 1) is
false a 3 1 24
y = 3
x = 2
x = 2 * 2
3 1 2 2 1 3 4 4 4 = 4
a = 3;
The output is 3 1 2 2 1 3 4 4 4
main( )
Hence, the correct option is (A).
a 3
Question Number: 46 Question Type: MCQ m(a);
What will be the output of the following pseudo-code
when parameters are passed by reference and dynamic
scoping is assumed?
m( y) y 3
a = 3; a 1 a = 1;
void n(x) { x = x* a; print (x);} a = y – a;
a 2
void m(y) {a = 1; a = y – a; n(a) ;
print (a)} n(a)
print(a);
void main( ) {m(a);}
n(x)
(A) 6,2
x = x ∗ a;
(B) 6,6 x 4 print(x);
(C) 4,2
a 4
(D) 4,4
Solution:
a = 3
4
main( ) 4
It prints 4 4.
Hence, the correct option is (D).

01_GATE 2016 CSIT Set-1.indd 67 6/12/2017 1:54:15 PM


lxx | GATE 2016 Solved Paper CSIT: Set – 1

a, X/X X Solution:  As X is recursive, X is also recursive.


a, Z/X Z b, X/
As Y is recursively enumerable but not recursive so Y
b
is not recursively enumerable.
b, X/ , Z/Z
Z reduces to X and X is recursive so Z is recursive. Y
reduces to W and Y is not recursively enumerable. So,
Which one of the following is true?
W is not recursively enumerable.
(A) L = {an bn| n ≥ 0} and is not accepted by any Hence, the correct option is (C).
finite automata.
(B)  L = {an | n ≥ 0) ∪ {anbn | n ≥ 0} and is not Question Number: 55 Question Type: NAT
­accepted by any deterministic PDA. The attributes of three arithmetic operators in some
programming language are given below.
(C)  L is not accepted by any Turing machine that
halts on every input. Operator Precedence Associativity Arity
(D)  L = {an|n ≥ 0} ∪ {an bn|n ≥ 0} and is deter- + High Left Binary
ministic context-free. – Medium Right Binary
Solution:  Given, input alphabet   a, b * Low Left Binary

Stack alphabet    X , Z  The value of the expression 2 – 5 + 1 – 7 * 3 in this


Z is initial stack symbol. language is ______.
L is the language accepted by below PDA: Solution:  2 – 5 + 1 – 7 * 3
a, Z/XZ b, X/ ‘+’ has high precedence, so it evaluates
5+1=6
2–6–7*3
b, X/ , Z/Z ‘–’ has medium precedence, and associates from right.
This PDA accepts the strings with n number of a’s So it evaluates to
n  0 or strings with equal number of a’s and b’s in 6 – 7 = –1  and  2 – (–1) = 3
the form an bn such that n  0 . 3*3

  
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.

01_GATE 2016 CSIT Set-1.indd 70 6/12/2017 1:54:19 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxxi

Solution:  Input string = a a b Total head movement = 87 – 63 + 92 – 87 + 121 – 92


+ 191 – 121 + 191 – 10 + 11 – 10 + 38 – 11 + 47 – 38
S
Prints 1 = 346
Hence, the correct Answer is (346).
a A
Question Number: 59 Question Type: NAT
Prints 3
b
Consider a computer system with ten physical page
S frames. The system is provided with an access sequence
(a1, a2, …, a20, a1, a2, … a20), where each ai is a distinct
Prints 2
virtual page number. The difference in the number of
a page faults between the last-in-first-out page replace-
ment policy and the optimal page replacement policy
2 3 1 is ______.
It prints as 2 3 1. Solution: 
Hence, the correct option is (C). LIFO
Question Number: 57 Question Type: NAT It just simulates the operation of stack.
Consider a computer system with 40-bit virtual a1, a2, a3 … a10
addressing and page size of sixteen kilobytes. If the a11, a12, a13 … a20
computer system has a one-level page table per process
a1, a2, a3 … a10
and each page table entry requires 48 bits, then the size
of the per-process table is ______ megabytes. a11, a12, a13 … a20

240 Using LIFO the system will have 31 pages faults.


Solution:  Number of pages = = 226 Using optimal page replacement policy the system will
214
be having 30 page faults.
Page table size = 226 × 48 bits
The difference in page faults = 31 – 30.
= 3072 Mbits
Hence, the correct Answer is (1).
= 384 MB
Question Number: 60 Question Type: MCQ
Hence, the correct Answer is (384).
Consider the following proposed solution for the criti-
Question Number: 58 Question Type: NAT cal section problem. There are n processes: P0…Pn–1. In
Consider a disk queue with requests for I/O to blocks on the code, function pmax returns an integer not smaller
cylinders 47, 38, 121, 191, 87, 11, 92, 10. The C-LOOK than any of its arguments. For all i, t[ i ] is initialized
scheduling algorithm is used. The head is initially at cylin- to zero.
der number 63, moving towards larger cylinder numbers do {
on its servicing pass. The cylinders are numbered from 0  c[ i ] = 1; t [ i ] = pmax (t[ i
to 199. The total head movement (in number of cylinders) ], ……,
incurred while servicing these requests is _____.
t[n – 1]) + 1; c[ i ] = 0;
Solution:   for every j ≠ i in (0, …., n – 1)
C – LOOK: {
0 10 11 38 47 63 87 92 121 191 199 while (c [ j ]);
 while (t[ j ] ! = 0 && t[ j ] < =
t[ i ]);
}
Critical Section;
t[ i ] = 0;
Remainder Section;
} while (true);

01_GATE 2016 CSIT Set-1.indd 71 6/12/2017 1:54:20 PM


lxxii | GATE 2016 Solved Paper CSIT: Set – 1

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?

01_GATE 2016 CSIT Set-1.indd 72 6/12/2017 1:54:22 PM


GATE 2016 Solved Paper CSIT: Set – 1 | lxxiii

Remaining data = 12 MB – 2 MB. 1-way propagation delay = 100 msec.


= 10 MB. Round-trip delay = 2 * 100 msec
= 0.2 msec.
To transmit 10 MB, time taken
= 0.1 × 10 = 1 sec. Size of acknowledgment = 100 bytes
Transmission rate at the receiver = 8 Kbps.
Total time required to transmit 12 MB
8 × 103 bits → 1sec
= 1 + 0.1 = 1.1 sec
100 × 8 bits → ?
Hence, the correct Answer is (1.1).
800
Question Number: 65 Question Type: NAT Time to transmit one ack =
8 × 103
A sender uses the Stop-and-Wait ARQ protocol for
= 0.1 sec.
reliable transmission of frames. Frames are of size
1
1000  bytes and the transmission rate at the sender Throughput =
is 80  Kbps (1 Kbps = 1000 bits/second). Size of an T
acknowledgement is 100 bytes and the transmission T = Transmission time + Propagation delay
rate at the receiver is 8 Kbps. The one-way propagation + Acknowledgment delay
delay is 100 milliseconds. = 0.1 + 0.2 + 0.1 = 0.4 sec.
Assuming no frame is lost, the sender throughput is 1
_____ bytes/second. Throughput = = 2.5 frames/sec.
0.4
Solution:  Time taken to transmit One frame = 1000 bytes.
8000 2.5 frames = 2500 bytes/sec.
1 frame = = 0.1 sec
80 × 103 Hence, the correct Answer is (2500).

01_GATE 2016 CSIT Set-1.indd 73 6/12/2017 1:54:22 PM


GATE 2016 Solved Paper
CSIT: Computer Science and Information Technology
Set – 2
Number of Questions: 65 Total Marks:100.0

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

01_GATE 2016 CSIT Set-2.indd 74 6/12/2017 1:55:36 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxv

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

35 20 65 Question Number: 8 Question Type: MCQ


All hill-stations have a lake. Ooty has two lakes.
Which of the statement(s) below is/are logically valid
30
and can be inferred from the above sentences?
(i) Ooty is not a hill-station.
As 30 faculty members have neither account, 120 have (ii) No hill-station can have more than one lake.
accounts. As 55 have a Facebook account and 85 have (A) (i) only
a WhatsApp account,
(B) (ii) only
Faculty members who have only either account = 55 +
(C) Both (i) and (ii)
85 – 120 = 20.
The number of faculty members who have only a (D) Neither (i) nor (ii)
Facebook account is 55 – 20 = 35. Solution:  Hence, neither statement (i) nor statement
Hence, the correct option is (A). (ii) is logically valid.
Question Number: 7 Question Type: MCQ Hence, the correct option is (D).
Computers were invented for performing only high-end Question Number: 9 Question Type: MCQ
useful computations. However, it is no understatement In a 2 × 4 rectangle grid shown below, each cell is a rec-
that they have taken over our world today. The internet, tangle. How many rectangles can be observed in the grid?
for example, is ubiquitous. Many believe that the inter- (A) 21  (B) 27   (C) 30  (D) 36
net itself is an unintended consequence of the original
invention. With the advent of mobile computing on our Solution:  To select a rectangle from the grid, from the
phones, a whole new dimension is now enabled. One 5 vertical lines we have to select 2 and from the 3 hori-
is left wondering if all these developments are good or, zonal lines we have to select 2. The number of ways in
more importantly, required. which this can be done is
Which of the statement (s) below is/are logically valid 5
C 2 3C2 = 10(3) = 30 ways.
and can be inferred from the above paragraph? Hence, the correct option is (C).
(i) The author believes that computers are not good
for us. Question Number: 10 Question Type: MCQ
(ii) 
Mobile computers and the internet are both 2.5
f(x)
intended inventions. 2
(A) (i) only 1.5
(B) (ii) only 1
(C) Both (i) and (ii) 0.5
(D) Neither (i) nor (ii) 0
–4 –3 –2 –1 0 1 2 3 x4
–0.5
Solution:  Statement (i) is not valid because the author
is expressing doubt whether computers are good. –1
Author is not concluding that the computers are not –1.5
good. –2
–2.5

01_GATE 2016 CSIT Set-2.indd 75 6/12/2017 1:55:36 PM


lxxvi | GATE 2016 Solved Paper CSIT: Set – 2

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

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and Solution:  Any planar graph can be colored with 4-colors.
Question 36 to Question 65 carry 2 marks each. Planar graph
Question Number: 11 Question Type: NAT
Consider the following expressions
1 2
 (i) false (ii) Q (iii) true
(iv) PVQ (v)  ⎤QVP
The number of expressions given above that are logi-
cally implied by P ∧ (P ⇒ Q) is ______.
Solution:  P ∧ (P → Q) ⇒ Q (modus ponens) 3 4

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

Question Number: 12 Question Type: NAT


4-colors are not sufficient.
Let f(x) be a polynomial and g(x) = f  ′(x) be its deriva-
Hence, the correct Answer is (4).
tive. If the degree of ( f(x) + f (–x) is 10, then the degree
of (g(x) – g (–x)) is ____. Question Number: 14 Question Type: MCQ
Solution:  Since f(x) + f(–x) is a polynomial of degree Consider the systems, each consisting of m linear equa-
10, therefore tions in n variables.
d I. If m < n, then all such systems have a solution
[f(x) + f(–x)] will be a polynomial of degree 9. II. If m > n, then none of these systems has a solution
dx
⇒ f ′ (x) + f ′(–x) (–1) is a polynomial degree 9. III. If m = n, then there exists a system which has a
solution
⇒ g(x) – g(–x) is a polynomial of degree 9.
Which one of the following is correct?
Hence, the correct Answer is (9).
(A) I, II and III are true
Question Number: 13 Question Type: NAT
(B) Only II and III are true
The minimum number of colours that is sufficient to
(C) Only III is true
vertex-colour any planar graph is __­­___.
(D) None of them is true

01_GATE 2016 CSIT Set-2.indd 76 6/12/2017 1:55:37 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxvii

Solution:  Question Number: 17 Question Type: NAT


\ I is False Consider an 8-bit ripple-carry adder for computing the
\ II is False. sum of A and B, where A and B are integers represented
And in a system of 3 linear equations in 3 unknowns in 2’s complement form. If the decimal value of A is
say, A X = B. one, the decimal value of B that leads to the longest
latency for the sum to stabilize is _____ .
If r(A) = r([A/B]), then the system has a solution.
Hence III is true. Solution:  To have longest latency, the carry should
Hence, the correct option is (C). propagate from all bits. Input A is 1, so other input
should have 1 1 1 1 1 1 1 1. (In 2’s complement form)
Question Number: 15 Question Type: NAT its value is decimal = –1.
Suppose that a shop has an equal number of LED bulbs Hence, the correct Answer is (–1.0).
of two different types. The probability of an LED bulb
lasting more than 100 hours given that it is of Type 1 is Question Number: 18 Question Type: MCQ
0.7, and given that it is of Type 2 is 0.4. The probabil- Let x1 ⊕ x2 ⊕ x3 ⊕ x4 = 0 where x1, x2, x3, x4 are boolean
ity that an LED bulb chosen uniformly at random lasts variables, and ⊕ is the XOR operator. Which one of the
more than 100 hours is _______. following must always be true?
(A) x1 x2 x3 x4 = 0 (B) x1 x3 + x2 = 0
Solution:  If we consider B1 and B2 are the events of
choosing a Type 1 and Type 2 LED bulbs respectively. x1⊕ x 3 = x 2 ⊕ x 4 (D) x1 + x2 + x3 + x4 = 0
(C)
Probability of choosing bulb type 1 will be P(B1) = 0.5
Solution:  XOR of x1, x2, x3, x4 is zero means, it will
Probability of choosing bulb type 2 will be P(B2) = 0.5
have even number of 1’s.
Let A denote the event of choosing an LED bulb that
E.g.: 0000, 0011, 0110, 1100, 0101, 1010, 1001, 1111,
lasts more than 100 hours.
these combinations are true for choice (c).
\ P(A/B1) = 0.7  and  P(A/B2) = 0.4
x11 ⊕ x31 = x12 ⊕ x14
The probability that an LED bulb chosen uniformly at
random lasts more than 100 hours Hence, the correct option is (C).
P(A) = P(B1) ⋅ P(A/B1) + P(B2) ⋅ P(A/B2) Question Number: 19 Question Type: NAT
= 0.5 × 0.7 + 0.5 × 0.4 Let X be the number of distinct 16-bit integers in 2’s
= 0.55. complement representation. Let Y be the number of
distinct 16-bit integers in sign magnitude representa-
Hence, the correct Answer is (0.55).
tion. Then, x – y is ______ .
Question Number: 16 Question Type: NAT
Solution:  For X: The range is −215 to 215 – 1 i.e., there
Suppose that the Eigen values of matrix A are 1, 2, 4. will be 65536 numbers.
The determinant of (A–1)T is ______.
For Y: The range is – (215 – 1) to 215 – 1.
Solution:  Suppose that the Eigen values of matrix A i.e., there will be 65535 numbers.
are 1, 2 and 4. Now
1 1
The Eigen values of A–1 are 1, and \ X – Y = 65536 – 65535 = 1.
2 4
1 1
–1 T
Therefore, the Eigen values of (A ) are 1, and Hence, the correct Answer is (1).
2 4
The determinant of (A–1)T = The product of the Eigen Question Number: 20 Question Type: NAT
values of (A–1)T A processor has 40 distinct instructions and 24 gen-
1 1 eral purpose registers. A 32-bit instruction word has an
=1× ×
2 4 opcode, two register operands and an immediate oper-
1 and. The number of bits available for the immediate
= = 0.125. operand field is ____.
8
Hence, the correct Answer is (0.124 to 0.126).

01_GATE 2016 CSIT Set-2.indd 77 6/12/2017 1:55:38 PM


lxxviii | GATE 2016 Solved Paper CSIT: Set – 2

Solution:  f(&i, j);


6 5 5 print f (“%d”, i +j);
Register Register Immediate }
Opcode
operand 2 operand 2 operand
Solution: 
32-bits
i 5 20 j 10
As there are 40 distinct instructions, the opcode length
will be 6 (40 ≈ 64 = 26).
As there are 24 registers, the length of register oper-
ands will be 5 (24 ≈ 32 = 25). p m 10 15
\ Immediate operand length = 32 − (6 + 5 + 5)
m = m + 5 ⇒ m + 15
= 16-bits ∗p = ∗p + m ⇒ ∗p = 5 + 15
∗p = 20 ⇒ i = 20
Hence, the correct Answer is (16). printf(“%d”, i + j);
Question Number: 21 Question Type: NAT
Prints
Breadth First Search (BFS) is started on a binary tree
beginning from the root vertex. There is a vertex t at a
30
distance four from the root. If t is the n-th vertex in this
BFS traversal, then the maximum possible value of n
Hence, the correct Answer is (30).
is _____.
Question Number: 23 Question Type: MCQ
Solution:  Vertex ‘t’ at a distance four from the root.
Assume that the algorithms considered here sort the
Example:
input sequences in ascending order. If the input is already
1 in ascending order, which of the following are true?
I. Quick sort runs in Q (n2) time
2 3 II. Bubble sort runs in Q (n2) time
III. Merge sort runs in Q (n) time
4 5 6 7
IV. Insertion sort runs in Q (n) time
10 12 13
8 9 11 14 15
(A) I and II only
(B) I and III only
31 t (C) II and IV only
16 17 18 19 20 21 22 23 24 2526 27 28 29 30
(D) I and IV only
t is the nth vertex in the BFS traversal, maximum pos-
sible value of n is 31. Solution:  On ascending order of elements, quick sort
gives, time complexity q(n2) and insertion sort gives,
Hence, the correct Answer is (31).
time complexity q(n).
Question Number: 22 Question Type: NAT Hence, the correct option is (D).
The value printed by the following program is ___.
Question Number: 24 Question Type: MCQ
void f (int* p, int m) {
The Floyd-Warshall algorithm for all-pair shortest
m = m +5; paths computation is based on
*p = *p + m; (A) Greedy paradigm.
return;
(B) Divide-and-Conquer paradigm.
}
(C) Dynamic programming paradigm.
void main () {
(D) Neither greedy nor divide-and-conquer nor
int i = 5, j = 10;
dynamic programming paradigm.

01_GATE 2016 CSIT Set-2.indd 78 6/12/2017 1:55:39 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxix

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.

Solution:  Given regular expression, IV. L1 ∪ L 2 is context–free.


(0 + 1)* (0 + 1) (0 + 1)* (A) I only (B) I and III only
The minimized DFA will be as below: (C) I and IV only (D) I, II and III only

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

01_GATE 2016 CSIT Set-2.indd 79 6/12/2017 1:55:41 PM


lxxx | GATE 2016 Solved Paper CSIT: Set – 2

(iii) L*1 ∩ L2 is context-free Question Number: 31 Question Type: MCQ


B+ Trees are considered balanced because
L*
 1 is regular as regular languages are closed under (A) The lengths of the paths from the root to all
closure.
L2 is context-free. leaf nodes are all equal.
Intersection of regular and CFL is CFL. (B) The lengths of the paths from the root to all
leaf nodes differ from each other by at most 1.
(iv) L1 ∪ L2 is context-free.
(C) The number of children of any two non - leaf
L2 may or may not be CFL. sibling nodes differs by at most 1.
So L1 ∪ L2 may or may not be context-free. (D) The number of records in any two leaf nodes
\ I, II and III are true. differs by at most 1.
Hence, the correct option is (D).
Solution:  B+-trees has a constraint that makes the tree
Question Number: 29 Question Type: MCQ always balanced which is that the length of paths from
Match the following: root to all the leaf nodes is equal.
(P)  Lexical analysis (i)  Leftmost derivation Hence, the correct option is (A).
(Q)  Top down parsing (ii)  Type checking Question Number: 32 Question Type: MCQ
(R)  Semantic analysis (iii)  Regular expressions Suppose a database schedule S involves transactions
(S)  Runtime environments (iv)  Activation records T1, … Tn. Construct the precedence graph of S with ver-
(A) P ↔ i, Q ↔ ii, R ↔ iv, S ↔ iii tices representing the transactions and edges represent-
ing the conflicts. If S is serializable, which one of the
(B) P ↔ iii, Q ↔ i, R ↔ ii, S ↔ iv
following orderings of the vertices of the precedence
(C) P ↔ ii, Q ↔ iii, R ↔ i, S ↔ iv graph is guaranteed to yield a serial schedule?
(D) P ↔ iv, Q ↔ i, R ↔ ii, S ↔ iii (A) Topological order.
Solution:  (B) Depth-first order.
P – iii, because regular expressions are used for the (C) Breadth-first order.
construction of lexical analysis. (D) Ascending order of transaction indices.
Q – i, because top down parsing uses left most deriva-
tion for parsing the string. Solution:  S is serializable, means precedence graph
should not contain any cycles.
R – ii. because semantic analysis is used for type
checking. Example: consider 4 transactions
S – iv. because runtime environments make use of acti- T1 T2
vation records.
Hence, the correct option is (B).
Question Number: 30 Question Type: MCQ
In which one of the following page replacement algo-
rithms it is possible for the page fault rate to increase
T3 T4
even when the number of allocated frames increases?
(A) LRU (Least Recently Used) Topological ordering:
(B) OPT (Optimal Page Replacement) T1, T3, T2, T4
(C) MRU (Most Recently Used)
Depth First order might give T1, T2, T4, T3
(D) FIFO (First In First Out) Breadth First order might give T1, T3, T4, T2
Solution:  Given statement resembles the definition of Ascending order of transaction indices T1, T2, T3, T4
Belady’s anomaly. FIFO is affected with Belady’s anomaly. \ Topological ordering is valid for any precedence graph.
Hence, the correct option is (D). Hence, the correct option is (A).

01_GATE 2016 CSIT Set-2.indd 80 6/12/2017 1:55:42 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxxi

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.

01_GATE 2016 CSIT Set-2.indd 81 6/12/2017 1:55:42 PM


lxxxii | GATE 2016 Solved Paper CSIT: Set – 2

Consider the following statements: Solution:  To perform F(G(1)), F(G(2)), … F(G(10))


I. Each compound in U\S reacts with an odd number it will take 25 ns but 12 ns of this can be done in paral-
of compounds. lel with G(3), G(4) … G(10).
II. At least one compound in U\S reacts with an odd Extra time for calculating F functions
number of compounds. = 25 − 12 = 13 ns
III. Each compound in U\S reacts with an even number \ Minimum time required = 15 ns + 13 ns
of compounds.
= 28 ns
Which one of the above statements is always true?
(A) Only I (B) Only II Hence, the correct Answer is (28).
(C) Only III (D) None Question Number: 41 Question Type: NAT
Consider a processor with 64 registers and an instruc-
Solution:  We know that in any undirected graph, there
tion set of size twelve. Each instruction has five distinct
are even numbers of odd vertices.
fields, namely, opcode, two source register identifiers,
There exists atleast one compound in U\S that reacts one destination register identifier, and a 12-bit immedi-
with odd number of compounds. ate value. Each instruction must be stored in memory in
Hence, the correct option is (B). a byte - aligned fashion. If a program has 100 instruc-
Question Number: 39 Question Type: NAT tions, the amount of memory (in bytes) consumed by
99 the program text is ___.
The value of the expression 13 (mod 17), in the range
0 to 16, is ______. Solution:  Instruction format as given in the problem is
Solution:  Using Fermat’s theorem, if p is a prime num- 4 6 6 6 12
ber and p is not a divisor of a, then ap – 1 = 1 (mod p) Opcode
Source Source Dest. Immediate
register 1 register 2 Register value
Here take a = 13 and p = 17
\ 1317 – 1 = 1 (mod 17) As there are 64 registers, register fields will have 6-bit
⇒ 1316 = 1 (mod 17) (1) length. Instruction set size is 12, the opcode will have
4(12 ≈ 16 = 24) bit length.
Consider
Instruction size = 34-bits.
1399 (mod 17) = 1396 + 3(mod 17)
Each instruction must be stored in byte-aligned fashion.
= (1316)6 133(mod 17)
In byte-aligned fashion, each instruction requires
= (136)6 (mod 17) 133 (mod 17) 5 bytes.
= 16.133 (mod 17) (using (1)) (∵ 5 × 8 = 40-bits  34-bits)
For a program of 100 instructions, memory required =
= 2197 (mod 17) 5 × 100 bytes = 500 bytes
= The remainder obtained when 2,197 is divided by 17 Hence, the correct Answer is (500).
=4 Question Number: 42 Question Type: NAT
Hence, the correct Answer is (4). The width of the physical address on a machine is
40 bits. The width of the tag field in a 512 KB 8-way
Question Number: 40 Question Type: NAT set associative cache is ____ bits.
Suppose the functions F and G can be computed
Solution: 
in 5 and 3 nanoseconds by functional units UF and
UG, respectively. Given two instances of UF and two Tag Set Offset
instances of UG, it is required to implement the compu-
40-bits
tation F(G(Xi)) for 1 ≤ i ≤ 10. Ignoring all other delays,
the minimum time required to complete this computa- Assume that block size = 2x
tion is _____ nanoseconds.
\ Offset requires x-bits.

01_GATE 2016 CSIT Set-2.indd 82 6/12/2017 1:55:43 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxxiii

219 Solution:  There are 1023 elements i.e., 1, …, 1023.


Number of sets in cache = =216−x The maximum number of elements at depth ‘d’ in com-
8 × 2x
plete binary tree is 2d+1 – 1.
Number of bits required for set field is 16 – x.
2d+1 – 1 = 1023
Tag = 40 – (16 – x + x) = 24-bits
2d+1 = 1023 + 1
Hence, the correct Answer is (24).
d + 1 = 10
Question Number: 43 Question Type: NAT
Consider a 3 GHz (gigahertz) processor with a three- d = 9
stage pipeline and stage latencies t1, t2 and t3 such that There will be a depth of 9 for min-heap of 1023
t1 = 3t2/4 = 2t3. If the longest pipelines stage is split elements.
into two pipeline stages of equal latency, the new fre-
quency is ____ GHz, ignoring delays in the pipeline Depth
1
registers.
2
1
Solution:  Cycle time = 3
3 × 109 4
The stage latencies will be, 5
6
4τ1 τ1
t1, , 7
3 2 8
The maximum stage delay is the cycle time. 9
4τ1 1
i.e., = The longest path in min-heap is shown above, so the
3 3 × 109  node 9 can be placed at depth 8.
3 1
⇒ t1 = × 1
4 3 × 109 
⇒ t1 = 0.25 nsec 2
4τ1 3
t2 = = 0.33 nsec
3
4
τ
t3 = 1 = 0.125 nsec
2 5
The longest stage delay is split into two equal stage
6
delays for a new processor. So new stage delays will be
0.25, 0.165, 0.165, 0.125 nsec. 7
Maximum stage delay is 0.25
8
⇒ Cycle time = 0.25 nsec
1 9
⇒ Frequency = = 4 GHz.
0.25 × 10 −9
Hence, the correct Answer is (8).
Hence, the correct Answer is (4).
Question Number: 45 Question Type: MCQ
Question Number: 44 Question Type: NAT The following function computes XY for positive inte-
A complete binary min-heap is made by including each gers X and Y.
integer in [1, 1023] exactly once. The depth of a node int exp (int X, int Y)
in the heap is the length of the path from the root of the
{
heap to that node. Thus, the root is depth 0. The maxi-
mum depth at which integer 9 can appear is _____. int res = 1, a = X, b = Y;
while (b! = 0)

01_GATE 2016 CSIT Set-2.indd 83 6/12/2017 1:55:45 PM


lxxxiv | GATE 2016 Solved Paper CSIT: Set – 2

{ The new-order traversal for the above tree is


if (b%2 = = 0) {a = a*a; b = b/2;} −+1*76∧2–5*43
else {res = res *a; b = b -1;} Hence, the correct option is (C).
}
Question Number: 47 Question Type: NAT
return res;
Consider the following program:
}
int f (int *p, int n)
Which one of the following conditions is true before
{
every iteration of the loop?
if (n < = 1) return 0;
(A) XY = ab (B) (res *a)Y = (res* X)b
else return max (f (p +1, n – 1), p
XY = res *ab (D)
(C) XY = ( res*a)b [0] – p [1] );
Solution:  XY = res * ab will be true before every itera- }
tion of the loop. int main ()
Hence, the correct option is (C). {
Question Number: 46 Question Type: MCQ int a[ ] = {3,5,2,6,4};
Consider the following New–order strategy for travers- printf (“%d”, f(a,5));
ing a binary tree: }
. Visit the root;
Note: max (x,y) returns the maximum of x and y.
. Visit the right subtree using New – order;
The value printed by this program is ______
. Visit the left subtree using New – order;
The New – order traversal of the expression tree cor- Solution:
responding to the reverse polish expression 0 1 2 3 4
3 4 * 5 – 2 ∧ 6 7 * 1 + – is given by: a 3 5 2 6 4
(A) + – 1 6 7 * 2 ∧ 5 – 3 4 *
(B) – + 1 * 6 7 ∧ 2 – 5 * 3 4
(C) – + 1 * 7 6 ∧ 2 – 5 * 4 3 P

(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

01_GATE 2016 CSIT Set-2.indd 84 6/12/2017 1:55:45 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxxv

3 [result 2]10 × 10 × [A4]10 × 5 = 10 × 10 × 5


f(P, 5) = 500
3 Total multiplications = 1000 + 2000 + 500 = 3500
(ii) A1 × A2 = 1000
max (f(P + 1, 4), –2)
A3 × A4 = 20 × 10 × 5 = 1000
3
[A1 × A2]10 × 20 * [A3 × A4]20 × 5 = 10 × 20 × 5 = 1000
max (f(P + 2, 3), 3) Total multiplications = 1000 + 1000 + 1000 = 3000
2 (iii) A3 × A4 = 1000
[A2]5 × 20 × [A3 × A4]20 × 5 = [result 1]5 × 5 = 5 × 20 ×
max (f(P + 3, 2), –4)
5 = 500
2 [A1]10 × 5 × [result 1]5 × 5 = 10 × 5 × 5
max (f(P + 4, 1)2) = 250
0
Total multiplications = 1000 + 500 + 250 = 1750
(iv) A2 × A3 = [result 1]5 × 10 = 5 × 20 × 10 = 1000
It prints 3. [result 2]10 × 10 = [A1]10 × 5 × [result 1]5 × 10 = 10 × 5
Hence, the correct Answer is (3). × 10 = 500
Question Number: 48 Question Type: NAT [result 2]10 × 10 × [A4]10 × 5 = 10 × 10 × 5
Let A1, A2, A3 and A4 be four matrices of dimensions = 500
10 × 5, 5 × 20, 20 × 10 and 10 × 5 respectively. The Total multiplications = 1000 + 500 + 500 = 2000
minimum number of scalar multiplications required to (v) (A2 × A3) = [result 1]5 × 10 = 5 × 20 × 10 = 1000
find the product A1A2A3A4 using the basic matrix multi- [result 2]5 × 5 = [result 1]5 × 10 × [A4]10 × 5
plication method is _____.
= 5 × 10 × 5 = 250
Solution:  Possible order of evaluation [A1]10 × 5 × [result 2]5 × 5 = 10 × 5 × 5 = 250
(i) ((A1 × A2) × A3) × A4) Total multiplications = 1000 + 250 + 250 = 1500
(ii) (A1 × A2) × (A3 × A4) Hence, the correct Answer is (1500).
(iii) A1 × (A2 × (A3 × A4))
Question Number: 49 Question Type: NAT
(iv) (A1 × (A2 × A3)) × A4
The given diagram shows the flowchart for a recursive
(v) A1 × ((A2 × A3) × A4) function A(n). Assume that all statements, except for
(i) A1 × A2 = [result 1]10 × 20 = 10 × 5 × 20 the recursive calls, have O (1) time complexity. If the
= 1000. worst case time complexity of this function is O (na),
[result 1]10 × 20 × [A3]20 × 10 then the least possible value (accurate up to two deci-
= [result 2]10 × 10 = 10 × 20 × 10 = 2000 mal positions) of α is ____.

Flowchat for Recursive Function A(n)


Start

A (n/2)

Return A (n/2) A (n/2) A (n/2) Return

A (n/2)

Return A (n/2) Return

01_GATE 2016 CSIT Set-2.indd 85 6/12/2017 1:55:46 PM


lxxxvi | GATE 2016 Solved Paper CSIT: Set – 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 Σ*.

01_GATE 2016 CSIT Set-2.indd 86 6/12/2017 1:55:48 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxxvii

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

01_GATE 2016 CSIT Set-2.indd 87 6/12/2017 1:55:48 PM


lxxxviii | GATE 2016 Solved Paper CSIT: Set – 2

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:

Solution:  int a[10][3]; P1 P2 P3 P2 P4 P1

Grammar G1: Grammar G2: 0 3 7 8 10 13 20

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

01_GATE 2016 CSIT Set-2.indd 88 6/12/2017 1:55:49 PM


GATE 2016 Solved Paper CSIT: Set – 2 | lxxxix

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

C.S as P0 is blocking P1 (∵ turn = 0), Though C.S is 50


free and P0 is executing N.C.S. 40
P1 gets chance only when P0 complete its C.S and vice 30
versa. 20
The above solution simulates strict alternation 10
­procedure. Therefore, the above solution doesn’t guar- 0
antee progress. 0 10 20 30 40 50 60 70 80 90
Hence, the correct option is (C). Cache size (MB)

Question Number: 59 Question Type: NAT


Solution:  Average access time = Hit ratio * cache
Consider a non-negative counting semaphore S. The access time + (1–hit ratio) * (disk access time + cache
operation P (S) decrements S and V(S) increments S. access time)
During an execution, 20 P(S) operations and 12 V(S)
Let, Hit ratio = H
operations are issued in some order. The largest initial
value of S for which at least one P(S) operation will 6 = H * 1 + (1 – H) (10 + 1)
remain blocked is _____. ⇒ 10H = 5
Solution:  Counting semaphore: 1
⇒ H = = 0.5 = 50%
2
After performing the P(S) operations if the value of Hit ratio = 50%
S is −1 then the process gets blocked
⇒ Miss ratio = 100% − 50% = 50%
If S = 0 then the performing of down(S) (P(S)) opera-
tion by a process results in blocked state. We need an average latency less than 6 ms. So, required
miss rate will be 40%, whose cache size is 30 MB.
If we consider the value of S as 0.
Hence, the correct Answer is (30).

01_GATE 2016 CSIT Set-2.indd 89 6/12/2017 1:55:49 PM


xc | GATE 2016 Solved Paper CSIT: Set – 2

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

– So the abort operations are not cascading aborts.


Hence, the correct option is (C).
Bikaner 40 ≥ 25
Question Number: 62 Question Type: NAT
Consider the following database table water_ schemes:

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

01_GATE 2016 CSIT Set-2.indd 90 6/12/2017 1:55:50 PM


GATE 2016 Solved Paper CSIT: Set – 2 | xci

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

01_GATE 2016 CSIT Set-2.indd 91 6/12/2017 1:55:51 PM


Detailed Analysis of GATE 2015 Papers
GATE CSIT Solved Paper 2015 (Set 1) Detailed Analysis
1 Mark 2 Marks Total
Subject Topic Questions Questions Questions Total Marks
General Aptitude Numerical Ability 1 2 3 5
  Verbal Ability 4 3 7 10
Total Marks         15
Engineering Maths Linear Algebra 1 1 2 3
  Calculus 1 1 2 3
  Numerical Method 0 1 1 2
Probability and
  Distribution 1 1 2 3
Total Marks         11
Number System and
Digital Code Conversion 0 1 1 2
Boolean Algebra and
  KMap 0 2 2 4
  Logic GATE Families 1 0 1 1
Total Marks         7
Computer Memory Hierarchy and
Organization Mapping 1 0 1 1
  Pipeline 0 2 2 4
Total Marks         5
DS Algorithm and Data Structure and
Programming Algorithm Analysis 1 1 2 3
  Stack And Queues 1 0 1 1
  Trees 2 0 2 2
Height Balanced Tree
  (AVL Tree, B-Tree) 0 1 1 2
  Priority Queues (Heaps) 1 0 1 1
  Sorting Algorithm 0 1 1 2
  C Programming 1 5 6 11
  Hashing 1 0 1 1
Total Marks         23
Functional Dependency
DBMS and Normalization 1 0 1 1
  SQL 1 0 1 1
Transaction and
  Concurrency Control 0 1 1 2
Total Marks         4

02_A-GATE_CSIT_2015_Detailed analysis.indd 92 6/12/2017 1:56:50 PM


Detailed Analysis of GATE 2015 Papers  |  xciii

Theory of Regular Expression and


Computation Languages 1 0 1 1
  Properties of CFL 0 1 1 2
  P, NP, NPH, NPC 0 1 1 2
Total Marks         5
Compiler Design Parsing 1 1 2 3
Total Marks         3
Operating System CPU Scheduling 1 1 2 3
Deadlocks and
  Synchronization 1 1 2 3
Total Marks         6
Software
Engineering HTML Structure 1 0 1 1
  Validation and Verification 1 1 2 3
  Testing 1 0 1 1
Total Marks         5
DMGT Graph Theory 0 1 1 2
Sets, Function and
  Relations 1 1 2 3
  Combinatorics 1 0 1 1
Total Marks         6
Computer-Network The Data Link Layer 1 2 3 5
TCP/IP, UDP and Socket,
  IPV4 1 2 3 5
Total Marks         10

GATE CSIT Solved 2015 Paper (Set 2) Detailed Analysis


1 Mark 2 Marks Total Total
Subject Topic Questions Questions Questions Marks
General Aptitude Numerical Ability 2 3 5 8
  Verbal Ability 3 2 5 7
Total Marks         15
Engineering Maths Linear Algebra 1 1 2 3
  Calculus 2 2 4 6
Total Marks         9
Digital Boolean Algebra and KMap 0 1 1 2
  Logic Gates 0 1 1 2
  Sequential circuits 1 1 2 3
Total Marks         7

02_A-GATE_CSIT_2015_Detailed analysis.indd 93 6/12/2017 1:56:50 PM


xciv | Detailed Analysis of GATE 2015 Papers

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

02_A-GATE_CSIT_2015_Detailed analysis.indd 94 6/12/2017 1:56:50 PM


Detailed Analysis of GATE 2015 Papers  |  xcv

Computer Network The Data Link Layer 0 2 2 4


TCP/IP, UDP and Socket,
  IPV4 3 0 3 3
  Cryptography 1 0 1 1
Total Marks         8

GATE CSIT Solved 2015 Paper (Set 3) Detailed Analysis


1 Mark 2 Marks Total Total
Subject Topic Questions Questions Questions Marks
General Aptitude Numerical Ability 2 4 6 10
  Verbal Ability 3 1 4 5
Total Marks         15
Engineering Maths Linear Algebra 1 1 2 3
  Calculus 0 1 2 2
Total Marks         5
Boolean Algebra and
Digital KMap 0 1 1 2
Combinational Digital
  Circuit 0 1 1 2
  Sequential Circuits 1 0 1 1
Total Marks         5
Computer Organization Pipeline 0 1 1 2
  Memory Hierarchy 1 0 1 1
  Miscellaneous 0 1 1 2
Total Marks         5
DS Algorithm and Data Structure and
Programming Algorithm Analysis 0 2 2 4

Height Balanced Tree


  (AVL Tree, B-Tree) 3 0 3 3
  Sorting Algorithm 1 0 1 1
  C Programming 2 3 5 8
  Hashing 0 1 1 2
Total Marks         18
Relational Algebra and
DBMS Relational Calculus 0 1 1 2
Transaction and
  Concurrency Control 1 1 2 3
  File Structure 1 0 1 1
Total Marks         6
Regular Expression and
Theory of Computation Languages 0 2 2 4

02_A-GATE_CSIT_2015_Detailed analysis.indd 95 6/12/2017 1:56:50 PM


xcvi | Detailed Analysis of GATE 2015 Papers

  CGF and CFL 0 1 1 2


  Turning of machine 1 0 1 1
  P, NP, NP-HARD, NPC 1 0 1 1
Total Marks         8
Compiler Design Introduction to Compiler 1 0 1 1
  Run Time Environment 0 1 1 2
Total Marks         3
Operating System Process Management 1 0 1 1
  Deadlocks 1 0 1 1

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

02_A-GATE_CSIT_2015_Detailed analysis.indd 96 6/12/2017 1:56:50 PM


GATE 2015 Solved Paper
CSIT: Computer Science and Information Technology
Set – 1
Number of Questions: 65 Total Marks:100.0

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.

02_GATE 2015 CSIT Set-1.indd 97 6/12/2017 2:23:16 PM


xcviii | GATE 2015 Solved Paper CSIT: Set – 1

Question Number: 4 Question Type: MCQ (B) 


R-Home, S-Power, P-Defense, Q-Telecom,
T-Finance.
y
(C) 
P-Home, Q-Power, T-Defense, S-Telecom,
U-Finance.
(D) 
Q-Home, U-Power, T-Defense, R-Telecom,
(2, 0) x
P-Finance.
Solution:  Only option (B) is complying with all the
(0, –1) rules and constrictions.
Hence, the correct option is (B).
Question Number: 6 Question Type: MCQ
Choose the most appropriate equation for the function Extreme focus on syllabus and studying for tests has
drawn as a thick line, in the plot below. become such a dominant concern of Indian students
(A) x = y – |y| (B) x = –(y – |y|) that they close their minds to anything ________ to the
(C) x = y + |y| (D) x = –(y + |y|) requirements of the exam.
(A) related (B) extraneous
Solution:  Given,
(C) outside (D) useful
x = 0  for  y > 0
Solution:  The sentence implies that students study
x = – 2y for y ≤ 0
only that which is prescribed within the syllabus and
Going from the options, nothing beyond it. ‘Extraneous’ means ‘not important’.
Choice (A) ⇒ x = 0  for  y ≥ 0 ‘Outside; cannot be used as ‘to’ is present after the
blank. ‘Outside to’ is ungrammatical. The other choices
x = 2y for y ≤ 0 are irrelevant to the given sentence.
Choice (B) ⇒ x = 0  for  y ≥ 0 Hence, the correct option is (B).
x = –2y for y ≤ 0 Question Number: 7 Question Type: MCQ
Choice (C) ⇒ x = 2y for y ≥ 0 Select the pair that best expresses a relationship similar
to that expressed in the pair:
x = 0  for  y ≤ 0 Children: Pediatrician
Choice (D) ⇒ x = –2y for y ≥ 0 (A) Adult: Orthopedist
x = 0  for  y ≤ 0 (B) Females: Gynecologist
∴ x = –(y − y ) (C) Kidney: Nephrologist
 (D) Skin: Dermatologist
Hence, the correct option is (B).
Solution:  A pediatrician treats children. In the same
Question Number: 5 Question Type: MCQ
context, a gynecologist treats females. Though a
The head of a newly formed government desires to ­nephrologist treats kidneys and a dermatologist treats the
appoint five of the six selected members P, Q, R, S, T skin, kidneys and skin are not living beings or humans.
and U to portfolios of Home, Power, Defense, Telecom
and Finance. U does not want any portfolio if S gets Hence, the correct option is (B).
one of the five. R wants either Home or Finance or no
portfolio. Q says that if S gets either Power or Telecom, Question Number: 8 Question Type: MCQ
then she must get the other one. T insists on a portfolio The Tamil version of ______ John Abraham-starrer
if P gets one. Madras Café ______ cleared by the Censor Board with
Which is the valid distribution of portfolios? no cuts last week, but the film’s distributor’s _______
(A)  P-Home, Q-Power, R-Defense, S-Telecom, no takers among the exhibitors for a release in Tamil
T-Finance. Nadu _____ this Friday.

02_GATE 2015 CSIT Set-1.indd 98 6/12/2017 2:23:17 PM


GATE 2015 Solved Paper CSIT: Set – 1 | xcix

(A) Mr., was, found, on (B) a, was, found, at Then,


(C) the, was, found, on (D) a, being, find, at S W A N
+3 +3 +3 +3
Solution:  The use of ‘the’ shows that only a certain
John Abraham is being referred to ‘Was’ and ‘found’ fit ↓ ↓ ↓ ↓
the next two blanks. ‘On’ is correct over ‘at’. Though, V Z D Q
the last blank can be deleted as well. Hence, the correct option is (B).
Hence, the correct option is (C). Question Number: 10 Question Type: MCQ
Question Number: 9 Question Type: MCQ A function f(x) is linear and has a value of 29 at x = –2
If ROAD is written as URDG, then SWAN should be and 39 at x = 3. Find its value at x = 5.
written as: (A) 59  (B) 45  (C) 43  (D) 35
(A) VXDQ (B) VZDQ Solution:  Let f (x) = ax + b where a and b are constants
(C) VZDP (D) UXDQ f (–2) = 29  and  f (3) = 39
Solution:  R O A D is written as U R D G a (–2) + b = 29  and  a (3) + b = 39
R O S D Solving these,
+ 3 +3 +3 +3
a = 2  and  b = 33
↓ ↓ ↓ ↓
⇒ f(x) = 2x + 33
U R D G
∴ f(5) = 2(5) + 33 = 43
Applying the same logic to SWAN
Hence, the correct option is (C).

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and 10 8

Question 36 to Question 65 carry 2 marks each. = 2 ×1×


1250 × 8 
Question Number: 11 Question Type: MCQ V = 20000 km/sec
Consider a CSMA/CD network that transmits data at
Hence, the correct option is (D).
a rate of 100 Mbps (108 bits per second) over a 1 km
(­kilometer) cable with no repeaters. If the minimum Question Number: 12 Question Type: NAT
frame size required for this network is 1250 bytes, what The velocity v (in kilometer/minute) of a motorbike
is the signal speed (km/sec) in the cable? which starts from rest is given at fixed intervals of
(A) 8000 (B) 10000 time t (in minutes) as follows:
(C) 16000 (D) 20000 t 2 4 6 8 10 12 14 16 18 20
Solution:  The condition for the minimum packet size v 10 18 25 29 32 20 11 5 2 0
in Ethernet (CSMA/CD) is
The approximate distance (in kilometers) rounded to
Transmission delay = Round trip time two places of decimals covered in 20 minutes using
Simpson’s 1/3rd rule is _____.
L d Solution:  The velocity V of a motorcycle at fixed
= 2×
B V  intervals of time t is given as
B
V = 2 × d × t 2 4 6 8 10 12 14 16 18 20
L V 10 18 25 29 32 20 11 5 2 0

02_GATE 2015 CSIT Set-1.indd 99 6/12/2017 2:23:18 PM


c | GATE 2015 Solved Paper CSIT: Set – 1

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

+ 2 (18 + 29 + 20 + 5)] Elements – 512 = 29 – 40 time units


Therefore, 512 is the maximum input size of a problem
= 309.33 km that can be solved in 6 minutes.
Hence, the correct Answer is (308 to 310). Hence, the correct option is (B).
Question Number: 13 Question Type: MCQ Question Number: 14 Question Type: MCQ
Assume that a merge-sort algorithm in the worst case Consider the following recursive C function
takes 30 seconds for an input of size 64. Which of the void get (int n)
following most closely approximates the maximum
{
input size of a problem that can be solved in 6 minutes?
if (n < 1) return;
(A) 256 (B) 512
get (n – 1);
(C) 1024 (D) 2048
get (n – 3);
Solution:  Time complexity of merge sort is θ(n log n) printf(“%d”, n);
For 64 elements, the algorithm took 30 seconds to sort }
⇒ (n log n) = 30 seconds
If get (6) function is being called in main ( ) then how
(64 log 64) = 30 seconds many times will the get ( ) function be invoked before
returning to the main ( )?
Lets convert the time taken to sort ‘n’ element into
some time units. (A) 15 (B) 25
64 log 64 = 30 (C) 35 (D) 45
30
64 =
log 64 
30
⇒ 64 = = 5 time units
6

02_GATE 2015 CSIT Set-1.indd 100 6/12/2017 2:23:19 PM


GATE 2015 Solved Paper CSIT: Set – 1 | ci

get (6)

get (5) get (3)

get (2) get (0)


get (4) get (2)

get (1) get (–1)


get (1)
get (3) get (1) get (–1)

get (0) get (–2)


get (0) get (-2)
get (2) get (0) get (0) get (–2)

get (1) get (–1)

get (0) get (–2)

Solution:  Total calls: 25


Hence, the correct option is (B).

Question Number: 15 Question Type: NAT Example:


Consider a B+ tree in which the search key is 12 bytes Keys = 2
long, block size is 1024 bytes, record pointer is 10 bytes
long and block pointer is 8 bytes long. The maximum
number of keys that can be accommodated in each non-
leaf node of the tree is ________.
p=3
Solution:  Search key = 12 bytes
Block size = 1024 bytes Hence, the correct Answer is (50).
Record pointer = 10 bytes
Question Number: 16 Question Type: MCQ
Block pointer = 8 bytes
Given the function F = P′ + QR, where F is a func-
The order (P) of the internal node in a B−+ tree,
tion in three Boolean variables P, Q and R and P′ = !P,
P ∗ 8 + (P – 1) (12) ≤ 1024 ­consider the following statements.
8P + 12 P – 12 ≤ 1024 (S1) F = Σ(4,5,6)
(S2) F = Σ(0,1,2,3,7)
20p ≤ 1024 + 12
(S3) F = ∏(4,5,6)
1036 (S4) F = ∏(0,1,2,3,7)
P ≤ = 51.8 ≅ 51
20 Which of the following is true?
P = 51 (A) (S1) – False, (S2) – True, (S3) – True, (S4) –
If the order p = 51, then the keys would be 50. False

02_GATE 2015 CSIT Set-1.indd 101 6/12/2017 2:23:20 PM


cii | GATE 2015 Solved Paper CSIT: Set – 1

(B) (S1) – True, (S2) – False, (S3) – False, (S4) – {


True int x = 1;
(C) (S1) – False, (S2) – False, (S3) – True, (S4) – x += f1( ) + f2 ( ) + f3 ( )

True + f2 ( );
(D) (S1) – True, (S2) – True, (S3) – False, (S4) – printf(“%d”, x);
False return 0;
}
Solution:  F = P′ + QR
int x = 25; x++;
int f1 () {
The given statements are in canonical form, by con- return x;}
verting F to canonical form. static int x = 50;
int f2 () {
F = P′(Q + Q′) (R + R′) + (P + P′)QR x++; return x;}
= P′(QR + Q′R + QR′ + Q′R′) + PQR + P′QR int f3 () {x *= 10; return x};

= P′QR + PQ′R + P′Q R′ + P′Q′R′ + PQR The output of the program is ______.

= ∑ m(0, 1, 2, 3, 7) Solution: 


x=x + f1 ( ) + f2 ( )
= πM(4, 5, 6)
only (S2) and (S3) are true. 51 100
f1 ( ) f2 ( ) f3 ( )
Hence, the correct option is (A). 26
x = 25 x = 50 X = x∗ 10 52
Question Number: 17 Question Type: MCQ x=x+1 x=x+1 return (x)
Language L1 is polynomial time reducible to language return (x) return (x)
L2. Language L3 is polynomial time reducible to L2,
which in turn is polynomial time reducible to language
L4. Which of the following is/are true?
(A) if L4 ∈ P, then L2 ∈ P In f  2( ), x is a static variable it is initialized only once
i.e., x = 50 it increments the x with ‘1’. (x = 51). When
(B) if L1 ∈ P or L3 ∈ P, then L2 ∈ P
f  2( ) is called once again, x retains the previous value
(C) L1 ∈ P, if and only if L3 ∈ P
and is incremented.
(D) if L4 ∈ P, then L1 ∈ P and L3 ∈ P
In f  3 ( ), ‘x’ is not declared, but ‘C’ implements static
Solution:  L1 → L2 scoping, it takes global value of ‘x’ [which is 10].
L3 → L2 ∴ x = 1 + 26 + 51 + 100 + 52 ⇒ 230
Hence, the correct Answer is (230).
L3 → L4
Question Number: 19 Question Type: NAT
L2 ≤p L4
Consider the following C program
L1 ≤p L2 #include<stdio.h>
Hence, the correct option is (C). int main ( )
Question Number: 18 Question Type: NAT {
 static int a[ ] = {10, 20, 30,
Consider the following C program
40, 50};
#include<stdio.h>  static int *p[ ] = {a, a+3,
int f1(void); a+4, a+1, a+2};
int f2(void); int **ptr = p;
int f3(void); ptr++;
int x = 10; printf(“%d%d”, ptr-p, **ptr);
}
int main ( ) The output of the program is _______

02_GATE 2015 CSIT Set-1.indd 102 6/12/2017 2:23:20 PM


GATE 2015 Solved Paper CSIT: Set – 1 | ciii

Solution:  Question Number: 21 Question Type: MCQ


Consider the following policies for preventing dead-
a 10 20 30 40 50
lock in a system with mutually exclusive resources.
I. Processes should acquire all their resources at the
beginning of execution. If any resource is not avail-
able, all resources acquired so far are released.
II. The resources are numbered uniquely, and pro-
cesses are allowed to request for resources only in
increasing resource numbers.
a III. The resources are numbered uniquely, and pro-
cesses are allowed to request for resources only in
decreasing resource numbers.
IV. The resources are numbered uniquely. A process is
ptr will point to (p + 1)
allowed to request only for a resource with resource
after ptr + +
number larger than it’s currently held resources.
Which of the above policies can be used for preventing
ptr deadlock?
(A) Any one of I and III but not II or IV
ptr – p = [pointer Arithmetic] (B) Any one of I, III and IV but not II
∗∗ptr will contain 140 (C) Any one of II and III but not I or IV
∴ it prints 140. (D) Any one of I, II, III and IV
Hence, the correct Answer is (140). Solution:  Option I, II, III and IV are deadlock preven-
Question Number: 20 Question Type: MCQ tion policies. Implementing any one of these can make
Which of the following languages are context-free? system deadlock free.
L1 = {ambnanbm | m, n ≥ 1} Hence, the correct option is (D).

L2 = {ambnambn | m, n ≥ 1} Question Number: 22 Question Type: NAT


In the network 200.10.11.144/27, the fourth octet (in
L3 = {ambn | m = 2n + 1} decimal) of the last IP address of the network which
(A)
L1 and L2 only (B) L1 and L3 only can be assigned to a host is _______
(C)
L2 and L3 only (D) L3 only Solution:  Given network 200.10.11.144/27
Solution:  L1 = {am bn an bm|m, n ≥ 1} To find the last IP-address of the network
L1 is context free language Set ((32 – 27) = 5) the last 5 bits to ‘1’ in the given
IP-address.
Consider a stack, push the ‘a’ elements followed by ‘b’
element, then for every ‘a’ pop the elements should be 200.10.11.144
‘b’], for every b pop the elements [The element should 200.10.11.100 10000
be ‘a’] Last 5 bits set to 1
L2 = {am bn am bn|m, n ≥ 1} 200.10.11.100 11111
L2 is not context free 200 . 10 . 11 .  159

Two stacks should be maintained for the element count Octet 1 octet 2 octet 3 octet 4
of ‘a’ and ‘b’.
The fourth octet value in the last IP-address is 159, but
L3 = {am bn|m = 2n + 1} last address cannot be assigned to a host hence we have
L3 is context free language. to assign 158 to a host.
Hence, the correct option is (B). Hence, the correct Answer is (158).

02_GATE 2015 CSIT Set-1.indd 103 6/12/2017 2:23:20 PM


civ | GATE 2015 Solved Paper CSIT: Set – 1

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.

02_GATE 2015 CSIT Set-1.indd 104 6/12/2017 2:23:22 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cv

Code segment 1: Transaction – id


//initialize elements of Y to 0 Time Instance T1 T2
 //initialize elements X[i] [j] of 1 read(A)
X to i + j 2 write(A)
3 read(C)
for (i = 0; i < n; i++) 4 write(C)
Y[i] += X[0] [i]; 5 read(B)
Code Segment 2: 6 write(B)
//initialize elements of Y to 0 7 read(A)
 //initialize elements X[i] [j] of 8 commit
X to i + j 9 read(B)

 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)

As the elements of X are in page frame, in code seg- 4 write(C)


ment 1 the elements of X belong to same row, therefore 5 read(B)
they are stored in one frame. 6 write(B)
In code segment 2 the elements of X belong to different 7 read(A)
column, it needs to access different page frames. 8 Commit
Hence, the correct option is (C). 9 read(B)

Question Number: 27 Question Type: MCQ There is one RW-conflict (2 → 7)


Consider the following partial schedule S involving In the RW-conflict, the transaction T1 is performing
two transactions T1 and T2. Only the read and the write write operation, so T1 has to commit first, T2 is per-
operations have been shown. The read operation on forming read operation so it has to commit later.
data item P is denoted by read(P) and the write opera-
⇒ It is not recoverable.
tion on data item P is denoted by write(P)
Hence, the correct option is (B).

02_GATE 2015 CSIT Set-1.indd 105 6/12/2017 2:23:22 PM


cvi | GATE 2015 Solved Paper CSIT: Set – 1

Question Number: 28 Question Type: MCQ   {


If the following system has non-trivial solution,     switch(i + k)
px + qy + rz = 0     {
  case 1:
qx + ry + pz = 0
   case 2: printf
rx + py + qz = 0, (“\n%d”, i + k);
then which one of the following options is TRUE?    case 3: printf
(A) p – q + r = 0 or p = q = –r (“\n%d”, i + k);
(B) p + q – r = 0 or p = –q = r    default: printf(
(“\n%d”, i + k);
(C) p + q + r = 0 or p = q = r
   }
(D) p – q + r = 0 or p = –q = –r   }
Solution:  Given system of equations is return 0;
px + qy + rz = 0 }
qx + ry + pz = 0 (1) The number of times printf statement is executed is
_______.
rx + py + qz = 0
Solution:
which can be written in matrix form as
j=2∗ 3 / 4 + 2.0 / 5 + 8 / 5;
AX = 0
6 | 4 +
 2.0 | 5
+8|5
⎡p q r⎤ ⎡x⎤ ⎡0 ⎤
Where A = ⎢⎢ q r p ⎥ ; X = ⎢ y ⎥ and O = ⎢⎢0 ⎥⎥
⎥ ⎢ ⎥
⎢⎣ r p q ⎥⎦ ⎢⎣ z ⎥⎦ ⎢⎣0 ⎥⎦ 1 + 0 + 1
1+0+1
Given (1) has non-trivial solutions
=2
p q r
K = K– (– – j)
⇒ Det A = 0 ⇒ q r p =0 K = 0 – 1
r p q K = – 1

⇒ pqr – p3 – q3 + pqr + pqr – r3 = 0 i=0
⇒ p3 + q3 + r3 – 3 pqr = 0 i+k⇒0–1⇒–1
only one print f( ) is executed
⇒ p3 + q3 + r3 = 3pqr
i=1
which is possible only when i + k ⇒ –1 + 1 ⇒ 0
p + q + r = 0 (OR) p = q = r. only one printf( ) is executed
Hence, the correct option is (C). i=2
Question Number: 29 Question Type: NAT i+k⇒2–1⇒1
Consider the following C program: the printf( ) is executed 3 times.
#include<stdio.h> i=3
int main( ) i+k⇒3–1⇒2
{ The printf( ) is executed 3 times
int i, j, k = 0; i=4
 j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5; i+k⇒4–1⇒3
k -= --j; the printf( ) is executed 2 times
for (i = 0; i < 5; i ++) ∴ The printf( ) is executed 10 times.
Hence, the correct Answer is (10).

02_GATE 2015 CSIT Set-1.indd 106 6/12/2017 2:23:22 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cvii

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

02_GATE 2015 CSIT Set-1.indd 107 6/12/2017 2:23:26 PM


cviii | GATE 2015 Solved Paper CSIT: Set – 1

Tp = 20 micro seconds Turnaround


Tp = The amount of time taken for the packet to transfer Arrival Burst Completion Time
Process Time Time Time (TAT)
from one end to another.
A 0 3 3 3
1. One packet is kept on line in 500 micro seconds.
B 1 6 9 8
2. Immediately second packet is also kept on line
(Tp  = 20 micro seconds of first packet is merged C 4 4 13 9

with TT = 500 micro seconds of second packet) D 6 2 15 9

⇒ 500 micro seconds 29


Average TAT = = 7.25
3. First packet’s, processing delay 35 micro seconds 4
is also merged with TT = 500 micro seconds of
SJF
second packet.
4. Second packet takes TP = 20 micro seconds to Arrival Burst Completion Turnaround
switch (mean while packet 1 will be traversing Time Time Time Time
towards host 2) Process (A.T) (B.T) (C.T) (TAT)
5. At switch, second packet is held for 35 micro A 0 3 3 3
­seconds, then sent for TP = 20 micro seconds. B 1 6 9 8
6. Last bit of second packet takes TT = 500 micro C 4 4 15 11
seconds to reach host 2. D 6 2 11 5
Total time = 500 + 500 + 20 + 35 + 20 + 500
= 1575 27
Average TAT = = 6.75
4
Hence, the correct Answer is (1575).
Question Number: 33 Question Type: MCQ A B C D
For the processes listed in the following table, which of 0 3 9 11 15
the following scheduling schemes will give the lowest
average turnaround time? SRTF

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

02_GATE 2015 CSIT Set-1.indd 108 6/12/2017 2:23:27 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cix

Process A.T. B.T. C.T. T.A.T. Solution: 


A 0 3 5 5 Program X:
B 1 6 15 14 Cyclomatic complexity of program X is the number of
C 4 4 13 9 conditions +1.
D 6 2 11 5 There are 2 ‘if’ conditions and 1 ‘while’ condition

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:

Program-X: Control flow diagram Edges = 10


of program-Y: Vertices = 8
Sumcal (int maxint, int value)
{
int result=0, i=0;
if (value < 0)
{
value = –value;
}
while ((i<value) AND (result If condition
<= maxint))
{
i=i+1;
result = result + 1;
}
if (result <= maxint)
{
print (result);
} While condition
else
{
print (”large”);
}
printf (”end of program”);
}

Control flow diagram


of program-Z:
If-else condition:
Control flow diagram
of program-X:

Control flow diagram


of program-Y:

The value of McCabe’s Cyclomatic complexity of Program y:


­program-X, Program-Y, and Program-Z respectively
Edges = 10
are
Vertices = 8
(A) 4, 4, 7 (B) 3, 4, 7
Cyclomatic complexity = 10 – 8 + 2 = 4
(C) 4, 4, 8 (D) 4, 3, 8
∴ program ‘Y’ = 4

02_GATE 2015 CSIT Set-1.indd 109 6/12/2017 2:23:28 PM


cx | GATE 2015 Solved Paper CSIT: Set – 1

Program Z: (C) Not reflexive but symmetric


(D) Neither reflexive nor symmetric
Control flow
E = 10 Solution:  The relation R on the set of ordered pairs of
diagram of
V=8
program-X positive integers given by

E=1 R = {((p, q), (r, s))/p – s = q – r}


Consider ((a, b), (a, b))
Control flow
E = 10
diagram of
V=8 ((a, b), (a, b)) ∈ R only if a – b = b – a
program-Y
which is NOT true always
Cyclomatic complexity ∴ R is NOT reflexive (1)
Total number of edges = 10 + 1 + 10 = 21 Let ((a, b), (c, d)) ∈ R
Total number of vertices = 8 + 8 = 16 ⇒ a – d = b – c
⇒ 21 – 16 + 2 = 7 (By definition of R)
⇒ d – a = c – b
∴ program ‘Z’ = 7
⇒ c – b = d – a
Hence, the correct option is (A). ⇒ ((c, d), (a, b)) ∈ R
Question Number: 35 Question Type: MCQ ⇒ R is symmetric (2)
Consider the equation (43)x = (y3)8 where x and y are Hence from (1) and (2), R is NOT reflexive but
unknown. The number of possible solutions is _______. symmetric.
Solution:  (43)x = (y3)8 Hence, the correct option is (C).
By converting to decimal system Question Number: 37 Question Type: NAT
4x1 + 3.x0 = y.81 + 3.8° Suppose Xi for i = 1,2,3 are independent and identically
4x + 3 = 8y + 3 distributed random variables whose probability mass
4x = 8y functions are Pr[Xi = 0] = Pr[Xi = 1] = ½ for i = 1,2,3.
Define another random variable Y = X1 X2 ⊕ X3, where
x = 2y
⊕ denotes XOR. Then,
x is base of number system x > 4 Pr[Y = 0|X3 = 0] = ______.
y is number in the number system with base 8, so y < 8.
Solution: 
x y
x1 x2 x3 x1 x2 x1 x2 ⊕ x3
6 3
0 0 0 0 0
8 4
0 0 1 0 1
10 5
0 1 0 0 0
12 6
0 1 1 0 1
14 7
1 0 0 0 0
Number of possible solutions = 5 1 0 1 0 1
Question Number: 36 Question Type: MCQ 1 1 0 1 1
Let R be a relation on the set of ordered pairs of positive 1 1 1 1 0
integers such that ((p, q),(r, s)) ∈ R if and only if p – s =
q – r. Which one of the following is true about R? Pr [Y = 0/x3 = 0] is the probability of Y = 0, when x3 = 0
(A) Both reflexive and symmetric from the truth table, x3 = 0, 4 times, and Y = x1 x2 ⊕
x3 = 0 3 times.
(B) Reflexive but not symmetric

02_GATE 2015 CSIT Set-1.indd 110 6/12/2017 2:23:29 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cxi

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

02_GATE 2015 CSIT Set-1.indd 111 6/12/2017 2:23:29 PM


cxii | GATE 2015 Solved Paper CSIT: Set – 1

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

i.e., at M[S, c] there will be multiple productions. Solution:  Given S = {1, 2, 3, 4, 5, 6}


∴ it is not LL(1). U = P(S)
Hence, the correct option is (D). Consider the set X\Y = {x/x ∈ S, x ∈ X and x ∉ Y}
Question Number: 42 Question Type: MCQ = {x/x ∈ S, x ∈ X and x ∉ Y ′}
Consider the following C program segment. = {x/x ∈ S, x ∈ Y ′ and x ∉ X′}
#include <stdio.h> = Y ′\X′, ∀ X ∈ U, ∀ Y ∈ U
int main() Hence, the correct option is (D).

02_GATE 2015 CSIT Set-1.indd 112 6/12/2017 2:23:30 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cxiii

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

02_GATE 2015 CSIT Set-1.indd 113 6/12/2017 2:23:30 PM


cxiv | GATE 2015 Solved Paper CSIT: Set – 1

Number of files (F) = 08 Solution:  <base href: “http: //www.yourname.com/”>


Number of external interfaces (N) = 2 It reflects to the given data;
The weighting factors for I, O, E, F and N are 4, 5, 4, Hence, the correct option is (B).
10 and 7.
Question Number: 50 Question Type: MCQ
Total Count = 30 × 4 + 60 × 5 + 23 × 4 + 8 × 10 + 2 × 7
Consider the following statements
= 120 + 300 + 92 + 80 + 14
I. TCP connections are full duplex
= 606
II. TCP has no option for selective acknowledgement
Function Point = Total Count ∗ EAF III. TCP connections are message streams
(A) Only I is correct
Effort adjustment factor (EAF) = 0.65 + 0.01 ∗ Σfi (B) Only I and III are correct
EAF = 0.65 + 0.01 ∗ Σfi (C) Only II and III are correct
Σfi = sum of the fourteen adjustment factors (D) All of I, II and III are correct
Out of 14, we will consider only 10 [given in problem, Solution:  TCP connections are full duplex.
4 are neglected] Hence, the correct option is (A).
Σfi = 3 + 3 + 3 + 3 + 4 + 4 + 4 + 4 + 4 + 6 Question Number: 51 Question Type: MCQ
Σfi = 4 × 3 + 6 × 4 n
Consider the equality ∑ i 3 = X and the following
= 12 + 24 choices for X i=0

= 36 I. θ(n )    II.  θ(n5)


4

EAF = 0.65 + 0.01 × 36 III. O(n5) IV.  Ω(n3)


The equality above remains correct if X is replaced by
= 1.01
(A) Only I
FP = 606 ∗ 1.01
(B) Only II
= 612.06 (C) I or III or IV but not II
Hence, the correct Answer is (612 to 613). (D) II or III or IV but not I
n
Question Number: 49 Question Type: MCQ
In a web server, ten web pages are stored with the
Solution:  ∑ i3
i=0
URLs of the form http://www.yourname.com/var.html;
⇒ 03 + 13 + 23 + 33 + 43 + … + n3
where, var is a different number from 1 to 10 for each
web page. Suppose, the client stores the web page with ⇒ 13 + 23 + … + n3
var = 1 (say W1) in local machine, edits and then tests. It is sum of cubes of 1st ‘n’ natural numbers
Rest of the web pages remain on the web server. W1
n2 ( n + 1)
2
contains several relative URLs of the form ‘var.html’ ⇒
referring to the other web pages. Which one of the fol- 4 
n ( n + 1)
2 2
lowing statements needs to be added in W1, so that all
It is θ(n4) as n4 ≤ ≤ 4n4
the relative URLs in W1 refer to the appropriate web 4
pages on the web server? n2 ( n + 1) 2
(A)  <a href:http://www.yourname.com/”, href: It is O(n5) as ≤ C n5
4
“var.html”> (C = constant, C > 0)
(B) <base href:http://www.yourname.com/”> n2 ( n + 1)
2

(C) <a href:http://www.yourname.com/”> It is Ω(n ) as


3
≥ n3
4
(D)  <base href:http://www.yourname.com/”, But it is not θ(n5)
range: “var.html”> Hence, the correct option is (C).

02_GATE 2015 CSIT Set-1.indd 114 6/12/2017 2:23:31 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cxv

Question Number: 52 Question Type: NAT ⎡ x1 ⎤


Consider a binary tree T that has 200 leaf nodes. ⎢ ⎥
Let X = ⎢ x2 ⎥ be an Eigen vector of A corresponding to
Then, the numbers of nodes in T that have exactly two
⎢⎣ x3 ⎥⎦
­children are ______.
the Eigen value λ = 1
Solution:  Let us consider the following Trees.
⇒ (A – λI) X = 0
⇒ (A – I)X = 0
⎡0 −1 2⎤ ⎡ x1 ⎤ ⎡0 ⎤
⇒ ⎢0 0 0 ⎥ ⎢ x ⎥ = ⎢0 ⎥
⎢ ⎥ ⎢ 2⎥ ⎢ ⎥
4 – leaves ⎢⎣1 2 0 ⎥⎦ ⎢⎣ x3 ⎥⎦ ⎢⎣0 ⎥⎦
(3 – nodes has exactly 2 children) 
⇒ – x2 + 2x3 = 0
x
⇒ x3 = 2
2 
and x1 + 2x2 = 0
2 – leaves ⇒ x1 = –2x2
(1 – node has exactly 2 children)
Let x2 = k, where K is arbitrary
∴ 200 leaf nodes ⇒ 199 nodes will have exactly
2 – children k
∴ x1 = – 2k and x3 =
Hence, the correct Answer is (199). 2
∴ The Eigen vector of A corresponding to the Eigen
Question Number: 53 Question Type: NAT
Given a hash table T with 25 slots that stores 2000 ⎡ ⎤
⎢ −2k ⎥ ⎡ −4α ⎤
­elements, the load factor ∝ for T is _______ . ⎢ ⎥
value λ = 1 is X = ⎢ k ⎥ ⇒  = ⎢⎢ 2α ⎥⎥ ,
Solution:  ⎢ k ⎥ ⎢⎣ α ⎥⎦
Number of elements 2000 ⎢ ⎥
Load factor = = = 80 ⎣ 2 ⎦ 
slots 25
Hence, the correct Answer is (80). where k = 2 α , α being arbitrary

Question Number: 54 Question Type: MCQ ⎡ −4 ⎤


= α ⎢⎢ 2 ⎥⎥
⎡1 −1 2⎤
⎢⎣ 1 ⎥⎦
In the given matrix ⎢⎢0 1 0 ⎥⎥ , one of the Eigen
Hence, the correct option is (B).
⎢⎣1 2 1 ⎥⎦
values is 1. The eigenvectors corresponding to the
­ Question Number: 55 Question Type: MCQ

( )
−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 →∞ ⎣ ⎝ ⎦


02_GATE 2015 CSIT Set-1.indd 115 6/12/2017 2:23:35 PM


cxvi | GATE 2015 Solved Paper CSIT: Set – 1

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

02_GATE 2015 CSIT Set-1.indd 116 6/12/2017 2:23:36 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cxvii

Question Number: 60 Question Type: MCQ


T4 A4 200 ≥ 100
Consider the following relation
200
Cinema (theater, address, capacity)
Which of the following options will be needed at the 150
end of the SQL QUERY? ∴ A4 is retrieved
200
SELECT P1.address
FROM Cinema P1 Option (A) always finds the addresses of theaters with
such that it always finds the addresses of theaters with maximum capacity.
maximum capacity? Hence, the correct option is (A).
(A) WHERE P1.capacity >= All (select P2. Question Number: 61 Question Type: MCQ
­Capacity from Cinema P2)
Consider the following array of elements
(B) WHERE P1.capacity >= Any (select P2.
­Capacity from Cinema P2) <89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100>
(C) WHERE P1.capacity > All (select max(P2. The minimum number of interchanges needed to con-
capacity) from Cinema P2) vert it into a max-heap is
(D) WHERE P1.capacity > Any (select max(P2. (A) 4 (B) 5
capacity) from Cinema P2) (C) 2 (D) 3
Solution:  Consider the Relation cinema, with some Solution: 
sample tuples:
89 10
Theater Address Capacity
T1 A1 100 19 10 19 89
T2 A2 200 ⇒
T3 A3 150 17 12 50 2 17 12 50 2
T4 A4 200
5 7 11 6 9 15 5 7 11 69 15
P1 capacity ≥ ALL (P2. Capacity) (Inter change 100 and 89)
100
T1 A1 100 ≥ ∴ 3 Interchanges are required to convert it into a max
200 – Heap.
Hence, the correct option is (D).
∴ A1 is not retrieved 150
Question Number: 62 Question Type: MCQ
200
Two processes X and Y need to access a critical section.
T2 A2 200 ≥ 100 Consider the following synchronization construct used
by both the processes.
200

∴ A2 is retrieved 150 Process X Process Y


/* other code /* other code
200
for process X */ for process Y */
while (true) while (true)
T3 A3 150 ≥ 100
{ {
200 varP = true; varQ = true;
150 while(varQ == while (varP ==
∴ A3 is not retrieved true) true)
200

02_GATE 2015 CSIT Set-1.indd 117 6/12/2017 2:23:37 PM


cxviii | GATE 2015 Solved Paper CSIT: Set – 1

{ { Y are in critical section which violates mutual exclu-


sion principle. There is no deadlock between process X
/* /*
and Y with these solution.
Critical Section Critical Section
Hence, the correct option is (A).
*/ */
varP = false; varQ = false; Question Number: 63 Question Type: MCQ
} } Let L be the language represented by the regular
} } expression Σ* 0011 Σ* where Σ = {0, 1}. What is the
minimum number of states in a DFA that recognizes L
/* other code /* other code
(complement of L)?
for process X */ for process Y */
(A) 4 (B) 5
Here, varP and varQ are shared variables and both are (C) 6 (D) 8
initialized to false. Which one of the following state-
ments is true? Solution:  The language ‘L’ accepts all the strings with
the substring 0011.
(A) The proposed solution prevents deadlock but
fails to guarantee mutual exclusion. The DFA for language ‘L’ is
(B)  The proposed solution guarantees mutual 1 0 0, 1
­exclusion but fails to prevent deadlock.
0 0 1 1
(C)  The proposed solution guarantees mutual A B C D E
­exclusion and prevents deadlock.
1 0
(D) The proposed solution fails to prevent dead-
lock and fails to guarantee mutual exclusion.
The DFA for L will be
Solution: 
1 0
Process X Process Y 0, 1
while (true) while(true) 0 0 1 1
A B C D E
{ {
1. var P = true; 1. var Q = true; 1 0
2. while (var Q 2. while(varP =
= = true) = true) Number of states for L is 5.
{ { Hence, the correct option is (B).
/* critical
 /*critical

Question Number: 64 Question Type: NAT
section”/ section */
Consider a software program that is artificially seeded
var P =
 varQ =

with 100 faults. While testing this program, 159 faults
false; false;
are detected, out of which 75 faults are from those
} } artificially seeded faults. Assuming that both real and
} } seeded faults are of same nature and have same distri-
bution, the estimated number of undetected real faults
The process X has executed instruction (1) and got is _________.
preempted and given chance to process Y, simi-
lar to process X it executes instruction (1) and got Solution:  Number of artificial seeds = 100 faults
preempted, given chance to process X. Process X exe- Number of faults detected (artificial) = 75
cutes (2) instruction and enters into critical section, and Number of faults detected = 159
got preempted when it is in critical section and given Number of real faults = 159 – 75
chance to process Y. Process Y executes (2) instruction
= 84
and enters into critical section in which process X and

02_GATE 2015 CSIT Set-1.indd 118 6/12/2017 2:23:38 PM


GATE 2015 Solved Paper CSIT: Set – 1 | cxix

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

02_GATE 2015 CSIT Set-1.indd 119 6/12/2017 2:23:38 PM


GATE 2015 Solved Paper
CSIT: Computer Science and Information Technology
Set – 2
Number of Questions: 65 Total Marks:100.0

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⎠

02_GATE 2015 CSIT Set-2.indd 120 6/12/2017 2:24:40 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxi

Number of students in the Civil department 75 40 20 27


= + + =
30 100 100 100 20
= (72) = 108
20 ⇒ I is true and II is not true.
Number of students in the Mechanical department (p) (m) (c) = probability (The student passing in all the
10 50 40 10 1
= (72) = 36 three subjects) = – = =
20 100 100 100 10
Number of female students in the Civil and the Hence, I and III are true.
⎛ 4⎞ ⎛ 4⎞ Hence, the correct option is (D).
Mechanical departments are 108 ⎜ ⎟ and 36 ⎜ ⎟
⎝ 9⎠ ⎝ 9⎠ Question Number: 5 Question Type: MCQ
respectively
i.e., 48 and 16 respectively. The number of students in a class who have answered
correctly, wrongly, and not attempted each question in
Difference is 48 – 16 i.e., 32.
an exam are listed in the table below. The marks for
Hence, the correct Answer is (32). each question are also listed. There is no negative or
Question Number: 4 Question Type: MCQ partial marking.
The probabilities that a student passes in Mathematics,
Answered Answered Not
Physics and Chemistry are m, p and c respectively. Of Q.No. Marks Correctly Wrongly Attempted
these subjects, the student has 75% chance of passing
1 2 21 17 6
in at least one, a 50% chance of passing in at least two
2 3 15 27 2
and a 40% chance of passing in exactly two. Following
relations are drawn in m, p, c: 3 1 11 29 4

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

02_GATE 2015 CSIT Set-2.indd 121 6/12/2017 2:24:41 PM


cxxii | GATE 2015 Solved Paper CSIT: Set – 2

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.

02_GATE 2015 CSIT Set-2.indd 122 6/12/2017 2:24:42 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxiii

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and Solution:  Propagation delay TP = 20 m sec
Question 36 to Question 65 carry 2 marks each. (B) Bit rate = 64 K bits/sec
Question Number: 11 Question Type: MCQ To achieve 50% link utilization
What are the worst-case complexities of insertion and The minimum frame size in bytes should be
deletion of a key in a binary search tree? L ≥ BR  (R = 2 TP)
(A) θ(log n) for both insertion and deletion
L = 64 × 103 × 2 ∗ 20 ∗ 10–3
(B) θ(n) for both insertion and deletion
(C) θ(n) for insertion and θ(log n) for deletion = 2560 bits
(D) θ(log n) for insertion and θ(n) for deletion = 320 bytes

Solution:  Worst case binary search tree, consider the 320


= = 160
following: 2

20 Hence, the correct Answer is (160).


Question Number: 13 Question Type: MCQ
18
Consider a max heap, represented by the array: 40, 30,
17 20, 10, 15, 16, 17, 8, 4
16
Array
1 2 3 4 5 6 7 8 9
15 Index
Value 40 30 20 10 15 16 17 8 4

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

02_GATE 2015 CSIT Set-2.indd 123 6/12/2017 2:24:43 PM


cxxiv | GATE 2015 Solved Paper CSIT: Set – 2

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

02_GATE 2015 CSIT Set-2.indd 124 6/12/2017 2:24:43 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxv

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

02_GATE 2015 CSIT Set-2.indd 125 6/12/2017 2:24:45 PM


cxxvi | GATE 2015 Solved Paper CSIT: Set – 2

Question Number: 19 Question Type: MCQ 1


⇒ |E| = 8
Consider the operations 3
f(X, Y, Z) = X ′ YZ + XY ′ + Y ′Z ′ ⇒ |E| = 24
and Hence, the correct Answer is (24).
g(X, Y, Z) = X ′ YZ + X ′ YZ ′ + XY. Question Number: 21 Question Type: MCQ
Which one of the following is correct? Let an represent the number of bit strings of length n
containing two consecutive 1s. What is the recurrence
(A) Both { f } and {g} are functionally complete
relation for an?
(B) Only { f } is functionally complete
(A) an–2 + an–1 + 2n–2
(C) Only {g} is functionally complete
(B) an–2 + 2an–1 + 2n–2
(D) Neither { f } nor {g} is functionally complete
(C) 2an–2 + an–1 + 2n–2
Solution: (D) 2an–2 +2an–1 + 2n–2
f(X, Y, Z) = X ′ YZ + XY ′ + Y ′Z ′
Solution: 
g(X, Y, Z) = X ′ YZ + X ′ YZ ′ + XY a1 = (0)
= Y(X ′Z + X ′Z ′ + X) = Y a2 = 11 (1)
f(X, Y, Z) = X ′YZ + XY ′Z + XY ′Z ′ + Y ′Z ′ a3 = 110, 011, 111 (3)
= (X ′Y + XY ′)Z + Y ′Z ′ a4 = 1100, 1101, 0110, 0011, 1110, 1111, 0111, 1011 (8)
by using { f }, we can implement the functions AND, Option (A)
OR, NOT, so only { f } is functionally complete. If we take n = 4
Hence, the correct option is (B). ⇒ an–2 + an–1 + 2n–2
Question Number: 20 Question Type: NAT a4 = a2 + a3 + 24–2
Let G be a connected planar graph with 10 vertices. = 1 + 3 + 22
If the number of edges on each face is three then the
number of edges in G is ______. a4 = 8
If we take n = 3
Solution:  We have, the no. of vertices of G = |V| = 10
Let |E| and |R| denote the no. of edges and the no. of a3 = 3
regions of the connected planar graph G respectively. a3 = an–2 + an–1 + 2n–2
By Euler’s formula, we have = a1 + a2 + 23–2
|V| + |R| – |E| = 2 (1) = 0 + 1 + 2
Given the number of edges on each face (region) is 3. = 3
We know that the sum of the degrees of all faces of a a3 = 3
planar graph = 2 × the no. of edges.
Hence, the correct option is (A).
i.e., 3 |R| = 2 |E|
Question Number: 22 Question Type: MCQ
2
⇒ |R| = |E| A variable x is said to be live at a statement Si in a program
3 if the following three conditions hold simultaneously:
∴ (1) becomes,
i. There exists a statement Sj that uses x
2
|V| + |E| – |E| = 2 ii. There is a path from Si to Sj in the flow graph
3 ­corresponding to the program.
1 iii. The path has no intervening assignment to x
⇒ 10 – |E| = 2
3 including at Si and Sj.

02_GATE 2015 CSIT Set-2.indd 126 6/12/2017 2:24:46 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxvii

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

– On entry to block 4 live variables are {r, v} and


q is not live as q is defined inside block 4 1
– On exit from block 4 live variables are {q, r, v} as
q is defined in block 4. R13
Hence {r, u} both are live at block 2 and block 3
Hence, the correct option is (C). n
Question Number: 23 Question Type: NAT
The least number of temporary variables required to cre- E3
ate a three-address code in static single assignment form
for the expression q + r/3 + s – t * 5 + u * v/w is _______. a31 a32
Solution:  q + r/3 + s – t ∗ 5 + u ∗ v/w
The 3-address code for above expression is E1 E2
t1 = r/3 a11 a12 a21 a22 a11 a21
t2 = t ∗ 5
t3 = u ∗ v
t4 = t3/w E3

t5 = q + t1 a31 a32 a11

t6 = t5 + s

02_GATE 2015 CSIT Set-2.indd 127 6/12/2017 2:24:47 PM


cxxviii | GATE 2015 Solved Paper CSIT: Set – 2

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

02_GATE 2015 CSIT Set-2.indd 128 6/12/2017 2:24:48 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxix

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

The Gantt chart with above Tasks is


u V
2 3
T1 T2 T2 T1 T3 T3 T1 T2 T2 T1 T3 T3
From source (S)
The distance to u = D(u) = 1 0 1 2 3 4 5 6 7 8 9 10 11 12
The distance to V = D(v) = 1 The first instance of task (T3) completes at 12th milli
D(u) – D(v) = 0 second.
Hence, the correct Answer is (12).
Case 2:
S V Question Number: 29 Question Type: MCQ
A positive edge-triggered D–flip-flop is connected to a
positive edge-triggered JK flip-flop as follows. The Q
u output of the D flip-flop is connected to both the J and
K inputs of the JK flip-flop, while the Q output of the
D(u) = 2, D(v) = 1 JK flip-flop is connected to the input of the D flip-flop.
D(u) – D(v) = 2 – 1 = 1 Initially, the output of the D flip-flop is set to logic one
and the output of the JK flip-flop is cleared. Which one
Case 3: of the following is the bit sequence (including the initial
S u state) generated at the Q output of the JK flip-flop when
the flip-flops are connected to a free-running common
clock? Assume that J = K = 1 is the toggle mode and
V
J = K = 0 is the state-holding mode of the JK flip-flop.
Both the flip-flops have non-zero propagation delays.
D(u) = 1, D(v) = 2
(A) 0110110… (B) 0100100…
D(u) – D(v) = 1 – 2 = –1
(C) 011101110… (D) 011001100…
∴ D(u) – D(v) = 2 is not possible.
Solution: 
Hence, the correct option is (D).
D QD
Question Number: 28 Question Type: NAT J
QJK
Consider a uni-processor system executing three tasks
T1, T2 and T3, each of which is composed of an infinite Clk
sequence of jobs (or instances) which arrive periodi- K
cally at intervals of 3, 7 and 20 milliseconds, respec-
tively. The priority of each task is the inverse of its
The given problem is shown in the above figure initially
period, and the available tasks are scheduled in order
QD = 1, QJK = 0
of priority, with the highest priority task schedule first.
Each instance of T1, T2 and T3 requires an execution D J K
time of 1, 2 and 4 milliseconds, respectively. Given Clk QD QJK QJK QD QD
that all tasks initially arrive at the beginning of the 1st 0 1 0 0 1 1
millisecond and task preemptions are allowed, the first
1 0 1 1 0 0
instance of T3 completes its execution at the end of
________ milliseconds. 2 1 1 1 1 1
3 1 0

02_GATE 2015 CSIT Set-2.indd 129 6/12/2017 2:24:49 PM


cxxx | GATE 2015 Solved Paper CSIT: Set – 2

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

02_GATE 2015 CSIT Set-2.indd 130 6/12/2017 2:24:50 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxxi

Question Number: 33 Question Type: MCQ 1


put, = t
Consider a main memory with five page frames and the x
following sequence of page references: 3, 8, 2, 3, 9, 1, −1
6, 3, 8, 9, 3, 6, 2, 1, 3. Which one of the following is ⇒ dx = dt
x2
true with respect to page replacement policies First In 1
First Out (FIFO) and Least Recently Used (LRU)? ⇒ dx = –dt
x2
(A) Both incur the same number of page faults 1
x =
(B) FIFO incurs 2 more page faults than LRU π 
(C) LRU incurs 2 more page faults than FIFO 2
⇒ t = π and x =
(D) FIFO incurs 1 more page faults than LRU
π 
π
⇒ t=
Solution:  The page references are 2
3, 8, 2, 3, 9, 1, 6, 3, 8, 9, 3, 6, 2, 1, 3 ∴(1) becomes,
No. of page faults using FIFO
2
π
( x ) dx =
cos 1 π
2

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

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.

02_GATE 2015 CSIT Set-2.indd 131 6/12/2017 2:24:54 PM


cxxxii | GATE 2015 Solved Paper CSIT: Set – 2

1 4 – (log N)1/2 decrease key operations will take


⇒ (–1) (7) =  θ(log N)1/2
b a
∴ The best total asymptotic complexity is achieved
⇒ –7 = –a – 4b through unsorted array.
⇒ 5 – 4b = –7 Hence, the correct option is (A).
⇒ 4b = 12
Question Number: 37 Question Type: NAT
⇒ b = 3
Consider the following relations:
∴ a = 5  and  b = 3
Student
Hence, the correct option is (D).
Roll No Student Name
Question Number: 36 Question Type: MCQ 1 Raj
An algorithm performs (log N)1/2 find operations, N 2 Rohit
insert operations, (log N)1/2 delete operations, and 3 Raj
(log  N)1/2 decrease-key operations on a set of data
items with keys drawn from a linearly ordered set. For
Performance
a delete operation, a pointer is provided to the record
that must be deleted for the decrease–key operation; Roll No Course Marks
a pointer is provided to the record that has its key 1 Math 80
decreased. Which one of the following data structures 1 English 70
is the most suited for the algorithm to use, if the goal is 2 Math 75
to achieve the best total asymptotic complexity consid- 3 English 80
ering all the operations?
2 Physics 65
(A) Unsorted array 3 Math 80
(B) Min-heap
Consider the following SQL query.
(C) Sorted array
SELECT S.Student_Name, sum (P.Marks)
(D) Sorted doubly linked list
FROM Student S, Performance P
Solution:  WHERE S.Roll_No = P.Roll_No
MIN-HEAP: GROUP BY S.Student_Name
– To insert ‘N’ elements it takes (N log N) time The number of rows that will be returned by the SQL
– To delete (log N)1/2 elements, it takes ((log N)1/2 ∗ query is ______.
log N) Solution:  In SQL query, order of evaluation is,
– To find (log N)1/2 elements it takes ((log N)1/2 ∗ “FROM”, “WHERE”, “GROUP-BY” and ”SELECT”.
θ(N log N)) time Student X performance (where S.Roll No. = P. Roll No.)
Because, when we apply heap property, position of
­elements change. S. Roll Student
No Name P. Roll No. Course Marks
Sorted array:
1 Raj 1 Math 80
Takes same asymptotic times mentioned above.
1 Raj 1 English 70
Unsorted array:
2 Rohit 2 Math 75
– (log N)1/2 find operations will take (log N)1/2 ∗ θ(N)
2 Rohit 2 Physics 65
⇒ θ(N(log N)1/2)
3 Raj 3 English 80
–  N insertions will take N ∗ θ(1) = θ(N) (element is
inserted at last place) 3 Raj 3 Math 80

– (log N)1/2 delete operations will take, (pointer is


provided to particular element) (log N)1/2 ∗ θ(1) =
θ(log N)1/2

02_GATE 2015 CSIT Set-2.indd 132 6/12/2017 2:24:54 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxxiii

Group by Student- Name: 15


B E
1 Raj 1 Math 80 4
1 Raj 1 English 70
3 Raj 3 English 80 A 2 F

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)

02_GATE 2015 CSIT Set-2.indd 133 6/12/2017 2:24:56 PM


cxxxiv | GATE 2015 Solved Paper CSIT: Set – 2

Solution:  Let, y = 12


for (i = 1; i < n; ++i) → loop 1 So, 17 ≥ 12
{
r = 17 – 12 = 5
p = 0;
for(j = n; j > 1; j = j/2) → q = 1
loop 2 Let’s cross check with the options.
+ + p; Option (A)
for (k = 1; k < p; k = k ∗ 2) → r = qx + y = 1 × 17 + 12 = 29
loop 3 (False)
+ + q; Option (B)
} x = qy + r = 1 × 12 + 5 = 17
return q; (True)
} Option (C)
Loop 1 will iterate for about ‘n’ times [i.e, ‘i’ value y = qx + r = 1 × 17 + 5 = 22
takes ‘n’ values] (False)
Loop 2 will iterate for about (log n) times, therefore, Option (D)
the ‘p’ value will be (log n) approximately, loop 3 will q+1<r–y
iterate for about (log p) times i.e., log(log n) times, the
(Not always true)
‘q’ will increment log(log n) times for every value of i.
Therefore loop will iterate for about ‘n’ times, therefore Hence, the correct option is (B).
the ‘q’ will increment for n(log(log n)) times. return q; Question Number: 42 Question Type: MCQ
will return n(log (log n)).
x g ( h ( x ))
Hence, the correct option is (D). If g(x) = 1 – x and h(x) = , then is
x −1 h ( g ( x ))
Question Number: 41 Question Type: MCQ
Consider the following pseudo code, where x and y are h (x) −1
(A) (B)
positive integers g (x) x
begin g (x) x
(C) (D)
h (x)
q := 0
r := x
(1 − x )2
x
while r ≥ y do Solution:  Given g(x) = 1 – x and h(x) =
begin x −1
⎛ x ⎞
g⎜
g ( h ( x )) ⎝ x − 1⎟⎠
r := r – y
q := q + 1 Consider =
h ( g ( x )) h (1 − x )
end
end ⎡ ⎛ x ⎞⎤
⎢1 − ⎜ ⎥
The post condition that needs to be satisfied after the ⎝ x − 1⎟⎠ ⎦
=⎣
program terminates is ⎡ (1 − x ) ⎤
(A) {r = qx + y ∧ r < y} ⎢ ⎥
⎣ (1 − x ) − 1⎦ 
(B) {x = qy + r ∧ r < y}
⎡ −1 ⎤
(C) {y = qx + r ∧ 0 < r < y} ⎢
(D) {q + 1 < r – y ∧ y > 0} ⎣ ( x − 1) ⎥⎦
⇒ =
⎡ (1 − x ) ⎤
Solution:  Let x = 17. ⎢ ⎥
So, r = 17 ⎣ −x ⎦ 

02_GATE 2015 CSIT Set-2.indd 134 6/12/2017 2:24:58 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxxv

⎡ x ⎤ (C) (P)-(ii), (Q)-(iii), (R)-(iv), (S)-(i)



( x − 1) ⎥⎦ (D) (P)-(ii), (Q)-(i), (R)-(iii), (S)-(iv)
=⎣
[1 − x ] 
Solution:  Prim’s algorithm for minimum spanning tree
h (x) – Greedy Method.
= – Floyd-Warshall algorithm for all pairs shortest
g (x)
 paths – Dynamic programming.
Hence, the correct option is (A). – Merge sort – Divide and conquer
Question Number: 43 Question Type: MCQ – Hamiltonian circuit – Back tracking.
Limx→∞ x1/x is Hence, the correct option is (C).

(A) (B) 0 Question Number: 45 Question Type: MCQ
(C) 1 (D) Not defined Which one of the following is the recurrence equation
for the worst case time complexity of the Quick sort
Solution:  Let y = Lim x
1
x

x →∞ algorithm for sorting n (≥2) numbers? In the recurrence

( )
equations given in the options below, c is a constant.
⇒ ln y = ln Lim x
1
x

x →∞ (A) T(n) = 2T(n/2) + cn


T(n) = T(n – 1) + T(1) + cn
⇒ = Lim ⎡ln x
x →∞ ⎣
( )⎤⎦ 
1
x
(B)
(C) T(n) = 2T(n – 1) + cn
⎡1 ⎤ (D) T(n) = T(n/2) + cn
= Lim ⎢ ln ( x )⎥
x →∞ ⎣ x ⎦
Solution:  The worst quick sort recurrence tree:
⎡ ln x ⎤ Example: Suppose n = 8
⇒ = Lim ⎢
x →∞ ⎣ x ⎥ ⎦ T(8)

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

Match the following:


T(2) T(1)
 (P) Prim’s algorithm for  (i) Backtracking
minimum spanning tree T(1) T(1)
(Q) Floyd-Warshall (ii)  Greedy method
algorithm for All Pairs The Recurrence equation is T(n)
Shortest Paths = T(n – 1) + T(1) + cn.
 (R)  Merge sort  (iii)  Dynamic programming
Hence, the correct option is (B).
 (S)  Hamiltonian circuit (iv)  Divide and conquer
Question Number: 46 Question Type: MCQ
(A) (P)-(iii), (Q)-(ii), (R)-(iv), (S)-(i) The height of a tree is the length of the longest root-to-
(B) (P)-(i), (Q)-(ii), (R)-(iv), (S)-(iii) leaf path in it. The maximum and minimum numbers of
nodes in a binary tree of height 5 are

02_GATE 2015 CSIT Set-2.indd 135 6/12/2017 2:24:59 PM


cxxxvi | GATE 2015 Solved Paper CSIT: Set – 2

(A) 63 and 6, respectively (I) 3, 5, 7, 8, 15, 19, 25


(B) 64 and 5, respectively (II) 5, 8, 9, 12, 10, 15, 25
(C) 32 and 6, respectively (III) 2, 7, 10, 8, 14, 16, 20
(D) 31 and 5, respectively (IV) 4, 6, 7, 9, 18, 20, 25
(A) I and IV only (B) II and III only
Solution:  Height = 2 (max nodes = 7)
(C) II and IV only (D) II only
Solution:  The in order traversal of binary search tree
results in ascending order of the node elements.
In given question, option (I) and (IV) are sorted in
ascending order.
Maximum number of nodes 2h+1 – 1 ∴ Option (I) and (IV) are correct in-order traversal.
∴ Height = 5(max nodes 63) Hence, the correct option is (A).
Question Number: 49 Question Type: MCQ
Which one of the following is true at any valid state in
shift-reduce parsing?
(A) Viable prefixes appear only at the bottom of
the stack and not inside.
Height = 2(min nodes = 3)
(B) Viable prefixes appear only at the top of the
∴ Height = 5 (min nodes = 6)
stack and not inside.
∴ Minimum number of nodes = h + 1
(C)  The stack contains only a set of viable
∴ 63 and 6 ­prefixes.
Hence, the correct option is (A).
(D) The stack never contains viable prefixes.
Question Number: 47 Question Type: MCQ
Solution:  The prefixes of right sentential forms that
Match the following: can appear on the stack of a shift-reduce parser are
called viable prefixes.
 (P)  Condition coverage  (i) Black-box testing
The stack will contain only a set of viable prefixes.
(Q) Equivalence class (ii)  System testing
partitioning Hence, the correct option is (C).
 (R)  Volume testing   (iii)  White-box testing Question Number: 50 Question Type: MCQ
 (S)  Alpha testing (iv)  Performance testing Which one of the following is NOT equivalent to p ↔ q?
(A) (P)-(ii), (Q)-(iii), (R)-(i), (S)-(iv) (A) (⌉p ∨ q) ∧ (p ∨ ⌉q)
(B) (P)-(iii), (Q)-(iv), (R)-(ii), (S)-(i) (B) (⌉p ∨ q) ∧ (q → p)
(C) (P)-(iii), (Q)-(i), (R)-(iv), (S)-(ii) (C) (⌉p ∧ q) ∨ (p ∧ ⌉q)
(D) (P)-(iii), (Q)-(i), (R)-(ii), (S)-(iv) (D) (⌉p ∧ q) ∨ (p ∧ q)

Solution:  Condition coverage – White-Box testing Solution:  p ↔ q biconditional or xnor


Equivalence class partitioning – Black-Box testing (p ↔ q) = ( p ∨ q) ∧ (p ∨ q)
Volume testing – Performance testing = (p ∧ q) ∨ ( p ∧  q)
Alpha testing – System testing = ( p ∨ q) ∧ (q → p)
Hence, the correct option is (C).
[∵ q → p = (q ∨ p)]
Question Number: 48 Question Type: MCQ
Hence, the correct option is (C).
Which of the following is/are correct in order traversal
sequence(s) of binary search tree(s)?

02_GATE 2015 CSIT Set-2.indd 136 6/12/2017 2:25:00 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxxvii

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

02_GATE 2015 CSIT Set-2.indd 137 6/12/2017 2:25:00 PM


cxxxviii | GATE 2015 Solved Paper CSIT: Set – 2

Question Number: 55 Question Type: MCQ TTL: (Time-to-Live)


Suppose that everyone in a group of N people wants to The value of TTL will be decremented at each router,
communicate secretly with the N-1 others, using sym- once the value of TTL becomes ‘0’, the packet will be
metric key cryptographic system. The communication discarded.
between any two persons should not be decodable by Length:
the others in the group. The number of keys required The maximum header length is 15 words (i.e., 60 bytes)
in the system as a whole to satisfy the confidentiality minimum is 20 bytes, but the options may make it
requirement is bigger.
(A) 2N (B) N(N – 1) Example:
(C) N(N – 1)/2 (D) (N – 1)2 When a packet is fragmented at a router, having the
router put in an IP address of a router and a time stamp,
Solution:  In symmetric key cryptography, the final destination knows how long it took to get to
n ( n − 1) each hop.
If there are ‘n’ numbers of users, then we need
keys. 2 ∴ The source and destination in the IP header is the
Hence, the correct option is (C). original source and the final destination.
Hence, the correct option is (B).
Question Number: 56 Question Type: MCQ
Which of the following statements is/are false? Question Number: 58 Question Type: MCQ
I.  XML overcomes the limitations in HTML to In one of the pairs of protocols given below, both the
­support a structured way of organizing content. protocols can use multiple TCP connections between
the same client and the server. Which one is that?
II.  XML specification is not case sensitive while
HTML specification is case sensitive. (A) HTTP, FTP (B) HTTP, TELNET
III. XML supports user defined tags while HTML uses (C) FTP, SMTP (D) HTTP, SMTP
pre-defined tags. Solution: 
IV. XML tags need not be closed while HTML tags HTTP, FTP:
must be closed. Both protocols are used to transfer files from one host
(A) II only (B) I only to another.
(C) II and IV only (D) III and IV only – HTTP transfers files from web server to web user
agent (The browser)
Solution: 
– FTP can send multiple files over the same TCP
– XML over comes the limitations in HTML (TRUE)
connection.
– HTML is not case sensitive
– HTTP is a “pull protocol” (users use HTTP to pull
– XML is case sensitive the information off the server).
– XML supports user defined tags (TRUE) Hence, the correct option is (A).
– XML tags must be closed.
Question Number: 59 Question Type: MCQ
Hence, the correct option is (C).
For any two languages L1 and L2 such that L1 is context-
Question Number: 57 Question Type: MCQ free and L is recursively enumerable but not recursive,
2
Which one of the following fields of an IP header is not which of the following is/are necessarily true?
modified by a typical IP router? I. L1 (complement of L1) is recursive
(A) Checksum (B) Source address II. L 2 (complement of L2) is recursive
(C) Time to Live (TTL) (D) Length
III. L1 is context-free
Solution:  IV. L1 ∪ L2 is recursively enumerable
Checksum:
(A) I only (B) III only
Checksum is calculated at each router, because the
(C) III and IV only (D) I and IV only
value of TTL will be decremented at each router.

02_GATE 2015 CSIT Set-2.indd 138 6/12/2017 2:25:01 PM


GATE 2015 Solved Paper CSIT: Set – 2 | cxxxix

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 _______

02_GATE 2015 CSIT Set-2.indd 139 6/12/2017 2:25:02 PM


cxl | GATE 2015 Solved Paper CSIT: Set – 2

Solution:  Clustered index is constructed on a non-key ⇒ u12 = 1


field which is ordered.
l21 u12 + l22 = 9
Example:
⇒ 4 × 1 + l22 = 9
Data File
Clustered Index D No. D Name Manager ⇒ l22 = 9 – 4 = 5
D No. block pointer 1 ∴ l22 = 5
1
1
2 Hence, the correct Answer is (5).
2
2 Question Number: 65 Question Type: NAT
3
2 The output of the following C program is ______.
4
3 void f1 (int a, int b) {
5 3
int c;
3
c=a; a=b; b=c;
3 }
3 void f2(int  *a, int  *b) {
4
int c;
5
c=*a; *a=*b; *b=c;
Hence, the correct option is (C). }
int main ( ) {
Question Number: 64 Question Type: NAT
int a=4, b=5, c=6;
⎡ 2 2⎤ f1 (a, b);
If the LU decomposition of the matrix ⎢ ⎥ , if the
⎣ 4 9⎦ f2 (&b, &c);
diagonal elements of U are both 1, then the lower diag- printf(“%d”, c-a-b);
onal entry l22 of L is _______. }
⎡ 2 2⎤ Solution:  The values of a, b, c are 4, 5, 6
Solution:  Let A = ⎢ ⎥
⎣ 4 9⎦ a
4 5 b
6 c
Let the LU decomposition of A be
f1(a, b) doesn’t affect the a, b, c values, because param-
A = LU eters are passed by call by value.
⎡l 0⎤ ⎡1 u12 ⎤ f2(&b, &c) reflects the values of b and c (it swaps the
Where L = ⎢ 11 ⎥ and  U = ⎢ ⎥ b, c values)
⎣l 21 l22 ⎦   ⎣0 1 ⎦ 
A = LU a 4 b 5 c 6

⎡ 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


02_GATE 2015 CSIT Set-2.indd 140 6/12/2017 2:25:04 PM


GATE 2015 Solved Paper
CSIT: Computer Science and Information Technology
Set – 3
Number of Questions: 65 Total Marks:100.0

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

02_GATE 2015 CSIT Set-3.indd 141 6/12/2017 2:26:11 PM


cxlii | GATE 2015 Solved Paper CSIT: Set – 3

Question Number: 4 Question Type: MCQ


If the list of letters P, R, S, T, U is in arithmetic sequence, So MP = (5) 2 + (1) 2 = 25 + 1 = 26 = 5.34 Kms.
which of the following are also in arithmetic sequence? Hence, the correct option is (A).
  (I) 2P, 2R, 2S, 2T, 2U Question Number: 6 Question Type: MCQ
(II) P-3, R-3, S-3, T-3, U-3 We _____ our friend’s birthday and we _____ how to
(III) P 2, R 2, S 2, T 2, U 2  make it up to him
(A) I only (B) I and II (A) completely forgot — don’t just know
(C) II and III (D) I and III (B) forgot completely — don’t just know
Solution:  P, R, S, T, U is an arithmetic sequence (C) completely forgot — just don’t know
∴ R – P = S – R = T – S = U – T. Let each of these (D) forgot completely — just don’t know
equal values be k.
Solution:  The correct answer is choice (C). Here,
I.  2 (R – P) = 2 (S – R) = 2 (T- S) = 2 (U – T) = 2k ‘completely’, modifies ‘forgot’, which is to say that
∴ 2P, 2R, 2S, 2T, 2U is an arithmetic sequence. an action was missed out on. The same rule applies to
II. R – 3 – (P – 3) = S – 3 – (R – 3) = T – 3 – (S- 3) the second blank as well. ‘Don’t know’ come together,
= U – 3 – (T – 3) = k. showing a misinformation and ‘just’ modifies it, show-
∴ P – 3, R – 3, S – 3, T- 3, U – 3 is an arithmetic ing an extent.
sequence. Hence, the correct option is (C).
Hence, the correct option is (B). Question Number: 7 Question Type: MCQ
Question Number: 5 Question Type: MCQ Choose the statement where underlined word is used
Four branches of a company are located at M, N, O and correctly.
P. M is north of N at a distance of 4 km; P is south of (A) The industrialist had a personnel jet.
O at a distance of 2 km; N is southeast of O by 1 km. (B) I write my experience in my personnel diary.
What is the distance between M and P in km?
(C) All personnel are being given the day off.
(A) 5.34 (B) 6.74
(D) Being religious is a personnel aspect.
(C) 28.5 (D) 45.49
Solution:  The word ‘personnel’ means a group of peo-
Solution:  Line diagram ple who work for a company or an organization. Choice
M
(C) uses the word correctly. The rest of the choices
should use ‘personal’.
Hence, the correct option is (C).
Question Number: 8 Question Type: MCQ
O
45° A generic term that includes various items of clothing
1 such as a skirt, a pair of trousers and a shirt is
1km
45° N (A) fabric (B) textile
2 km
(C) fibre (D) apparel
1 km
P Solution:  The correct answer is (D) apparel. (A) refers
to the type of apparel. (B) refers to the business that
M
makes apparels. (C) is again a material used to make
an apparel.
Hence, the correct option is (D).
4 + 2 – 1 = 5 km
Question Number: 9 Question Type: MCQ
Based on the given statements, select the most appro-
P priate option to solve the given question.
1 km

02_GATE 2015 CSIT Set-3.indd 142 6/12/2017 2:26:12 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cxliii

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’

Computer Science and Information Technology


Number of Questions: 55  Section Marks: 85.0
Question 11 to Question 35 carry 1 mark each and BR
Question 36 to Question 65 carry 2 marks each. R = Round trip delay if η = 25% then L =
3
i.e., 3L = BR
Question Number: 11 Question Type: NAT
A link has a transmission speed of 106 bits/sec. It uses 3 × 1000 × 8 = 106 × R
data packets of size 1000 bytes each. Assume that the R = 24 × 10−3 [{ R = 2 × propagation delay]
acknowledgement has negligible transmission delay, 2 × Propagation delay = 24 × 10−3
and the propagation delay is the same as that of data Propagation delay = 12 × 10−3
propagation delay. Also assume that the processing
delays at nodes are negligible. The efficiency of the = 12 ms
stop-and-wait protocol in this setup is exactly 25%. The Hence, the correct Answer is (12).
value of the one-way propagation delay (in millisec-
Question Number: 12 Question Type: MCQ
onds) is _______
Which one of the following statements is not correct
Solution:  The efficiency of the stop and wait protocol about HTTP cookies?
L
is η = (A) A cookie is a piece of code that has the poten-
L + BR
tial to compromise the security of an internet
L = Length of the packet user.
B = Bandwidth of the link

02_GATE 2015 CSIT Set-3.indd 143 6/12/2017 2:26:12 PM


cxliv | GATE 2015 Solved Paper CSIT: Set – 3

(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

128.96.170.0 Perform AND operation 6 ∗1472


7th fragment   48 28 = 1104
8
∴ The next hop will be Interface 0.
(ii) 128.96.167.151 Number of IP fragments will be 7.
255.255.254.0 Offset field of last fragment is 1104.
 Perform AND operation Hence, the correct option is (C).

02_GATE 2015 CSIT Set-3.indd 144 6/12/2017 2:26:13 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cxlv

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

02_GATE 2015 CSIT Set-3.indd 145 6/12/2017 2:26:13 PM


cxlvi | GATE 2015 Solved Paper CSIT: Set – 3

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

491 kB in that order. If the best fit algorithm is used,


Average time = 4 ms + 0.1 ms + 2 ms
which partitions are not allotted to any process?
= 6.1 ms
(A) 200 kB and 300 kB
Hence, the correct Answer is (6.1 to 6.2).
(B) 200 kB and 250 kB
(C) 250 kB and 300 kB Question Number: 20 Question Type: NAT
A computer system implements 8 kilobyte pages and
(D) 300 kB and 400 kB
a 32-bit physical address space. Each page table entry
Solution:  The memory map from the question is contains a valid bit, a dirty bit, three permission bits,
and the translation. If the maximum size of the page
Block 1 - 200 kB
table of a process is 24 megabytes, the length of the vir-
Block 2 - 400 kB tual address supported by the system is _______ bits.
Block 3 - 600 kB
Solution:  Page – Table size = (n × e)
Block 4 - 500 kB
n → number of pages
Block 5 - 300 kB
e → page entry size (in bytes)
Block 6 - 250 kB
Page size = 8 kB ⇒ 213
  The process P1, P2, P3, P4 requested for sizes 357 kB, given page-entry contains a valid bit, dirty bits, three
210 kB, 468 kB and 491 kB. permission bits and the translation. i.e., 5 bits are
∴ the process P1 is allocated to Block 2, P2 is allocated reserved, the translation requires 19 bits
to Block 6, P3 is allocated to Block 4 and P4 is allocated ⎡ 232 19 ⎤
in Block 3. ⎢frames = 13 ⇒ 2 ⎥
⎣ 2 ⎦
  So, Block 1 and Block 5 are not allocated to any pro-
cess, i.e., Block 1 (200 kB) and Block 5 (300 kB) is page entry size = (5 + 19) bits
not allotted. = 24 bits
Hence, the correct option is (A). ⇒ 3 bytes
Question Number: 19 Question Type: NAT Number of pages are
Consider a typical disk that rotates at 15000 rotations n × e = page table size
per minute (RPM) and has a transfer rate of 50 × 106 n × (3) = 24 MB
bytes/sec. If the average seek time of the disk is twice 3n = 24 MB

02_GATE 2015 CSIT Set-3.indd 146 6/12/2017 2:26:14 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cxlvii

 (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

Hence, the correct Answer is (36).


B5 i=i+1
Question Number: 21 Question Type: MCQ
B6 if i < 5 goto (2)
Consider the intermediate code given below.
 (1) i = 1 There are 6 basic blocks.
 (2) j = 1 The control flow graph is
 (3) t1 = 5 * i B1

 (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

02_GATE 2015 CSIT Set-3.indd 147 6/12/2017 2:26:15 PM


cxlviii | GATE 2015 Solved Paper CSIT: Set – 3

There are 6 nodes and 7 edges. L3: {ap bq cr/p, q, r ≥ 0}


Hence, the correct option is (B). We can generate a’s independently need not check (or)
save (or) count, again same for b’s and c’s also.
Question Number: 22 Question Type: NAT
Regular Expression = aa* bb* cc*
The number of states in the minimal deterministic finite
automation corresponding to the regular expression ∴ L3 is Regular.
(0 + 1)*(10) is ______. Hence, the correct option is (A).
Solution:  (0 + 1) * (10) Question Number: 24 Question Type: MCQ
The language for the above regular expression is all the Given below are some algorithms, and some algorithm
strings which are ending with 10. design paradigms.
The minimal finite automaton is
1.  Dijkstra’s shortest path i.  Divide and conquer
0 1
2. Floyd-Warshall algorithm to ii. Dynamic
1 0 compute all pairs shortest path programming
A B C
3. Binary search on a sorted array iii.  Greedy design
1 4. Backtracking search on a graph iv.  Depth-first search
0 v. Breadth-first search
The number of states in minimal FA for the above lan- Match the above algorithms on the left to the corre-
guage is 3. sponding design paradigm they follow.
Hence, the correct Answer is (3). (A) 1-i, 2-iii, 3-i, 4-v (B)  1-iii, 2-iii, 3-i, 4-v
Question Number: 23 Question Type: MCQ (C) 1-iii, 2-ii, 3-i, 4-iv (D)  1-iii, 2-ii, 3-i, 4-v
Which of the following languages is/are regular? Solution:
L1: {wxwR|w1 x∈ {a, b}* and |w|, |x| > 0}, wR is the Greedy design → Dijkstra’s shortest path
reverse of string w Dynamic programming → Floyd- Warshall algorithm
L2: {anbm|m ≠ n and m, n ≥ 0} to compute all pairs
L3: {apbqcr|p, q, r ≥ 0} shortest path.
Divide and conquer → Binary search on a sorted
(A)
L1 and L3 only (B) L2 only
array.
(C)
L2 and L3 only (D) L3 only
Depth First search → Back tracking, search on a
Solution:  {W X W R/W, x ∈ {a, b}* graph.
Assume that  W = a b a Hence, the correct option is (C).
 X = a b b
Question Number: 25 Question Type: NAT
W R = a b a
A Young tableau is a 2D array of integers increasing
WXW R from left to right and from top to bottom. Any unfilled
Assume as entries are marked with ∞, and hence there cannot be
X any entry to the right of, or below a ∞. The following
a  a b a a b b  a Young tableau consists of unique entries.
We can write this language as, set of all strings starting 1 2 5 14
and ending with same symbol. 3 4 6 23
∴ L1 is Regular 10 12 18 25
L2: 31 ∞ ∞ ∞
{an bm/m ≠ n}
When an element is removed from a Young tableau,
We need a stack to compare, that every time m ≠ n. other elements should be moved into its place so that
∴ L2 is not Regular the resulting table is still a Young tableau (unfilled

02_GATE 2015 CSIT Set-3.indd 148 6/12/2017 2:26:15 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cxlix

entries maybe filled in with a ∞). The minimum num- } else {


ber of entries (other than 1) to be shifted, to remove 1 return kth_smallest ( __________ ) ;
from the given Young tableau is _______. }
Solution:  }
2 5 14 2 4 5 14 The missing argument lists are respectively
3 4 6 23 3 6 23
(A) (a, left_end, k) and (a+left_end+1, n-left_end-
10 12 18 25 10 12 18 25
1, k-left_end-1)
31 ∞ ∞ ∞ 31 ∞ ∞ ∞
(B) (a, left_end, k) and (a, n-left_end-1, k-left_
2 4 5 14 2 4 5 14 end-1)
3 6 18 23 3 6 18 23 (C) (a+left_end+1, n-left_end-1, k-left_end-1)
10 12 25 ∞ 10 12 25 and (a, left_end, k)
31 ∞ ∞ ∞ 31 ∞ ∞ ∞ (D) (a, n-left_end-1, k-left_end-1) and (a, left_
end, k)
2 4 5 14
Solution:  The above program gets the kth smallest ele-
3 6 23
ment using the concept of quick sort and the binary
10 12 18 25
search [using divide and conquer strategy]
31 ∞ ∞ ∞
  When the condition, left end +1 > k is true, the kth
∴ 5 elements should be moved. smallest element is present left to the pivot, therefore
we have to search to the left of pivot. i.e., kth smallest
Hence, the correct Answer is (5). (a, left-end, k)
Question Number: 26 Question Type: MCQ   When the condition left end +1 < k is true, the kth
Suppose you are provided with the following function smallest element is present right to the pivot, therefore
declaration in the C programming language. we have to search between the left end and kth element.
int partition (int a[ ], int n); kth smallest (a+left-end+1, n – left_end – 1,
The function treats the first element of a [ ] as a pivot, k – left_end – 1)
and rearranges the array so that all elements less than Hence, the correct option is (A).
or equal to the pivot is in the left part of the array, and
all elements greater than the pivot is in the right part in Question Number: 27 Question Type: MCQ
addition, it moves the pivot so that the pivot is the last Which one of the following hash functions on integers
element of the left part. The return value is the number will distribute keys most uniformly over 10 buckets
of elements in the left part. numbered 0 to 9 for i ranging from 0 to 2020?
  The following partially given function in the C pro- (A) h(i) = i2 mod 10
gramming language is used to find the kth smallest (B) h(i) = i3 mod 10
element in an array a [ ] of size n using the partition (C) h(i) = (11 ∗ i2) mod 10
function. We assume k ≤ n. (D) h(i) = (12 ∗ i) mod 10
int kth_smallest (int a [ ], int n,
Solution:  Let’s take first 10 elements that is 0, 1, 2, 3,
int k)
4, 5, 6, 7, 8, 9 bucket numbers (0 – 9)
{
Option (A)
  int left_end = partition(a, n);
  if (left_end+1 == k) { h(i) = i2 mod 10
  return a [left_end]; 02 mod 10 ⇒ 0 mod 10 = 0
) 12 mod 10 ⇒ 1 mod 10 = 1
  if (left_end+1 > k) { 22 mod 10 ⇒ 4 mod 10 = 4
return kth_smallest ( __________ ) ; 32 mod 10 ⇒ 9 mod 10 = 9

02_GATE 2015 CSIT Set-3.indd 149 6/12/2017 2:26:15 PM


cl | GATE 2015 Solved Paper CSIT: Set – 3

42 mod 10 ⇒ 16 mod 10 = 6 Secant


52 mod 10 ⇒ 25 mod 10 = 5 Initialize: xa, xb, ε, N // ε =
62 mod 10 ⇒ 36 mod 10 = 6 convergence indicator
72 mod 10 ⇒ 49 mod 10 = 9 // N = maximum no. of iterations
82 mod 10 ⇒ 64 mod 10 = 4 fb = f(xb)
92 mod 10 ⇒ 81 mod 10 = 1 i = 0
while (i < N and |fb| > ε) do
Hash table:  i = i + 1 // update counter
0 0  xt = ? // missing expression
1 1 9 collision for
2   // intermediate value
3  xa = xb // reset xa
4 2 8 collision  xb = xt // reset xb
5 5  fb = f(xb) //  function value at new xb
6 4 6 collision end while
7 if |fb| > ε then  // loop is terminated
8 with i = N
9 3 7 collision write “Non-convergence”
else
Let us consider the numbers from 0 to 9. write “return xb”
Perform hash function h(i) = i3 mod 10 end if
03 mod 10 → 0 (A)
xb – (fb – f(xa)) fb / (xb – xa)
13 mod 10 → 1 (B)
xa – (fa – f(xa)) fa / (xb – xa)
23 mod 10 → 8
(C)
xb – (xb – xa) fb / (fb – f(xa))
33 mod 10 → 7
(D)
xa – (xb – xa) fa / (fb – f(xa))
43 mod 10 → 4
53 mod 10 → 5 Solution:  It is secant method direct formula
63 mod 10 → 6 Hence, the correct option is (C).
73 mod 10 → 3 Question Number: 29 Question Type: NAT
83 mod 10 → 2 Consider the C program below
93 mod 10 → 9 #include <stdio.h>
From 0 to 9 the numbers are stored in hash table with- int *A, stkTop;
out any collision, similarly from 10 – 19, 20 – 29, int stkFunc (int opcode, int val)
….. The numbers are stored uniformly with the above {
sequence [0, 1, 8, 7, 4, 5, 6, 3, 2, 9] static int size=0, stkTop=0;
Hence, the correct option is (B). switch (opcode) {
case -1: size = val; break;
Question Number: 28 Question Type: MCQ case 0: if (stkTop < size)
The secant method is used to find the root of an equa- A[stkTop++] = val; break;
tion f (x) = 0. It is started from two distinct estimates xa default: if (stkTop) return
and xb for the root. It is an iterative procedure involving A[--stkTop];
linear interpolation to a root. The iteration stops if f (xb) }
is very small and then xb is the solution. The proce- return -1;
dure is given below. Observe that there is an expres- }
sion which is missing and is marked by? Which is the int main ( )
suitable expression that is to put in place of? So that it {
follows all steps of the Secant method? int B[20]; A = B; stkTop = -1;

02_GATE 2015 CSIT Set-3.indd 150 6/12/2017 2:26:15 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cli

stkFunc (-1, 10); Solution:  I – Instruction fetch and decode


stkFunc (0, 5);   O – Operand fetch
stkFunc (0, 10);   P – Perform operation.
printf (“%d\n”, stkFunc(1, 0) + stk-
  W – Write back the result.
Func(1, 0));
} 1 2 3 4 5 6 7 8 9 10 11 12 13
The value printed by the above program is _____. P P P W
O
I O – – P P P P P W
I W
Solution: I – – O – – – – P W
P
The values of size and sktTop will be 10 and 0 when I – – – – – – –
stkFunc(–1, 10) is called. Hence, the correct Answer is (13).
The values of size and stkTop will be 0 and 1 with A[0] Question Number: 31 Question Type: MCQ
= 5, when stkFunc(0, 5) is called. Consider a processor with byte-addressable memory.
The value of size and stkTop will be 10 and 2 with A[1] Assume that all registers, including Program Counter
= 10, when stkFunc(0, 10) is called. (PC) and Program Status Word (PSW), are of size
printf(″%d\n″, stk Func(1, 0) + (stk Func(1, 0)); 2 bytes. A stack in the main memory is implemented
from memory location (0100)16 and it grows upward.
The Stack Pointer (SP) points to the top element of the
stack. The current value of SP is (016E)16. The CALL
instruction is of two words, the first word is the op-code
return A[1] return A[0]
and the second word is the starting address of the sub-
routine (one word = 2 bytes). The CALL instruction is
∴ it prints 15 implemented as follows:
Hence, the correct Answer is (15).
•  Store the current value of PC in the stack
Question Number: 30 Question Type: NAT •  Store the value of PSW register in the stack
Consider the sequence of machine instructions given •  Load the starting address of the subroutine in PC
below:
MUL R5, R0, R1 The content of PC just before the fetch of a CALL
instruction is (5FA0)16. After execution of the CALL
DIV R6, R2, R3
instruction, the value of the stack pointer is
ADD R7, R5, R6
(A) (016A)16 (B) (016C)16
SUB R8, R7, R4
(C) (0170)16 (D) (0172)16
In the above sequence, R0 to R8 are general purpose
registers. In the instructions shown, the first regis- Solution:  To execute CALL instruction, the contents
ter stores the result of the operation performed on of PC and PSW will be stored on to the stack
the second and the third registers. This sequence of Both PC and PSW are of 2 bytes in size
instructions is to be executed in a pipelined instruction Given top of stack is (016E)16
processor with the following 4 stages: (1) Instruction Hence, the correct option is (D).
fetch and decode (IF), (2) Operand fetch (OF), (3) We need to add 4 bytes to the stack address to get stack
Perform operation (PO) and (4) Write back the result pointer address after execution of CALL instruction
(WB). The IF, OF and WB stages take 1 clock cycle
each for any instruction. The PO stage takes 1 clock (016E)16 +4 = (0172)16 .
cycle for ADD or SUB instruction, 3 clock cycles for
Question Number: 32 Question Type: NAT
MUL instruction and 5 clock cycles for DIV instruc-
tion. The pipelined processor uses operand forwarding The number of min-terms after minimizing the follow-
from the PO stage to the OF stage. The number of clock ing Boolean expression is _______.
cycles taken for the execution of the above sequence of [D1 + AB1 + A1C + AC1 D + A1C1D]1
instructions is _______.

02_GATE 2015 CSIT Set-3.indd 151 6/12/2017 2:26:16 PM


clii | GATE 2015 Solved Paper CSIT: Set – 3

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

We need to find minimum terms of f  1, which are same −1 −1 −1 0


as max terms of f. 0 23 1
x2 3 ⎤ x ⎤ −3 2 3 0 3 2 3 1
⎥ = x ⎤⎦ −1 + x ⎤⎦ 0
CD = ⎥ +
AB 00 01 11 10 2 3 ⎦ −1 2 3 ⎦ 0 2 2
−3 3 3 3
00 1 1 1 1
= (0 − 1) + (1 − 0) = +
2 2 2 2
01 1 1 1 1 ∴A=3
∴ A is non-zero and finite.
11 1 1 1 1 ∴ (iii) is TRUE (3)
From the statements (1), (2) and (3)
10 1 1 1 1
(ii) and (iii) only are true.
Hence, the correct option is (C).
D1 = X X X 0
(0, 2, 4, 6, 8, 10, 12, 14) Question Number: 34 Question Type: NAT
AB = 10XX
1 Perform the following operations on the matrix
(8, 9, 10, 11) ⎡ 3 4 45 ⎤
A1C = 0 X 1 X ⎢ 7 9 105⎥
⎢ ⎥
(2, 3, 6, 7) ⎢⎣13 2 195⎥⎦
C1D = XX01 (i) Add the third row to the second row
(1, 5, 9, 13)
(ii) Subtract the third column from the first column
So the only maximum term of f = 1111 The determinant of the resultant matrix is _____.
So no. of minimum terms of f 1 = 1
⎡ 3 4 45 ⎤
Hence, the correct Answer is (1).
Solution:  Let A = ⎢ 7 9 105⎥⎥

Question Number: 33 Question Type: MCQ
⎢⎣13 2 195⎥⎦
-(1/3)
Let f (x)= x and A denote the area of the region
bounded by f (x) and the x-axis, when x varies from -1 (i) Add the third row to the second row
to 1. Which of the following statements is/are true? (ii) Subtract the third column from the first column.
(i) f is continuous in [-1, 1]
We know that operations of the type (i) and (ii) on a
(ii) f is not bounded in [-1, 1]
matrix cannot change its determinant.
(iii) A is nonzero and finite
∴ The determinant of the matrix obtained by applying
(A) ii only (B) iii only the operations (i) and (ii) on A
(C) ii and iii only (D) i, ii and iii 3 4 45
(1/ 3) = Det of A = 7 9 105
Solution:  Given f (x) = x
(1/ 3) 13 2 195
Clearly f (x) = x → ∞ as x → 0
⇒ f (x) is not bounded in [–1, 1] 3 34
∴ (ii) is TRUE (1) =15 7 7 = 15 × 0 = 0
9
⇒ f (x) is NOT continuous in [–1, 1] 13 2 13
∴ (i) is NOT TRUE (2) Hence, the correct Answer is (0).

02_GATE 2015 CSIT Set-3.indd 152 6/12/2017 2:26:18 PM


GATE 2015 Solved Paper CSIT: Set – 3 | cliii

Question Number: 35 Question Type: NAT X1 = 0X1 + 1 X2


The number of onto functions (subjective functions) X2 = 0 X1 + {λ}
from set X = {1,2,3,4} to set Y = (a, b, c} is ______.
Which one of the following choices precisely repre-
Solution:  Given X = {1, 2, 3, 4} and Y = {a, b, c} sents the strings in X0?
∴ n(X) = 4 and n(Y) = 3 (A) 10(0* + (10)*)1
The number of onto functions from set A to set B, (B) 10(0* + (10)*)*1
n −1
where n(A) ≥ n (B) is ∑ ( −r ) r ncr ( n − r ) m (C) 1(0 + 10)*1
r =0
(D) 10(0 + 10)*1 + 110(0 + 10)*1
where n(A) = m and n(B) = n
Solution:  X0 → 1 X1
Here m = n(X) = 4 and n = n(Y) = 3 X1 → 0 X1 | 1 X2
∵ The number of onto functions from X to Y is X2 → 0 X1 | ∈
n −1 3 −1
The above grammar represents a language with the
∑ (−1)r n
C0 ( n − r ) m = ∑ ( −1) r 3
C r (3 − r ) 4
strings starts and ends with ‘1’, with 0’s as substring
r =0 r =0
[10*1] (or) with (10)’s as substring [1(10)*1]
= 3C 0 34 − 3C1 24 + 3C 2 14
The regular expression is
= 81 – 48 + 3 = 36
10* 1 + 1 (10)* 1
Hence the correct Answer is (36). ⇓
Question Number: 36 Question Type: NAT 1(0 + 10)* 1
Let X and Y denote the sets containing 2 and 20 distinct Hence, the correct option is (C).
objects respectively and F denote the set of all possible Question Number: 38 Question Type: MCQ
functions from X to Y. Let f be randomly chosen from
A graph is self-complementary if it is isomorphic to its
the probability of f being one-to-one is ______.
complement. For all self-complementary graphs on n
Solution:  Given n(X) = 2 and n(Y) = 20 vertices, n is
n(F) = The number of elements in F (A) A multiple of 4
= The number of functions that can be (B) Even
defined from X to Y. (C) Odd
= n(Y)n(X) = 202 = 400 (D) Congruent to 0 mod 4, or, 1 mod 4
The number of one-one functions from X to Solution:  Let G be a graph of n vertices which is iso-
Y = n(Y) Pn(X) morphic to its complement G .
= 20
P2 = 380 ∴ G and G should have same no. of edges. This is pos-
sible only when the no. of edges in G and G must be
The probability that a randomly chosen function f from half of the no. of edges in the complete graph of n ver-
380 tices Kn.
F is one-one = = 0.95
400 1
The no. of edges of G = |EG| = Ekn
Hence the correct Answer is (0.95). 2
Question Number: 37 Question Type: MCQ 1 ⎛ n ( n − 1) ⎞ n ( n − 1)
= ⎜ ⎟ =
Consider the alphabet Σ = {0, 1}, the null/empty string 2⎝ 2 ⎠ 4
λ and the sets of strings X0, X1 and X2 generated by the n ( n − 1)
corresponding non-terminals of a regular grammar. X0, As |EG| being a positive integer, is a positive
X1 and X2 are related as follows integer. 4
⇒ n(n – 1) is a multiple of 4.
X0 = 1 X1
⇒ n is a multiple of 4 (or) n – 1 is a multiple of 4.

02_GATE 2015 CSIT Set-3.indd 153 6/12/2017 2:26:20 PM


cliv | GATE 2015 Solved Paper CSIT: Set – 3

⇒ n ≡ 0 (mod 4) (or) n – 1 ≡ 0 (mod 4) (C) Adherence to coding standards is checked


⇒ n ≡ 0 (mod 4) (or) n ≡ 1 (mod 4) during code inspection.
∴ n is congruent to 0 mod 4 or n is congruent to 1 (D) Code walkthrough is usually carried out by
mod 4. independent test team.
Hence, the correct option is (D). Solution:  Inspection is used to verify the compliance
of the product with specified standards and require-
Question Number: 39 Question Type: MCQ
ments, it is done by examining, meetings are needed,
In a connected graph, a bridge is an edge whose on the basis of feedback, rework is done.
removal disconnects a graph. Which one of the follow-
Walkthrough is different from inspections.
ing statements is true?
  In walkthrough author presents their artifacts to
(A) A tree has no bridges
audience of peers. Peer questions and comments on
(B) A bridge cannot be part of a simple cycle these, to identify as many as possible.
(C) Every edge of a clique with size ≥ 3 is a   Inspection is done by examining comparing the
bridge (A clique is any complete subgraph of product with design, code, artifacts and any other doc-
a graph) umentation available.
(D) A graph with bridges cannot have a cycle Hence, the correct option is (C).
Solution:  In a simple cycle of a connected graph, the Question Number: 42 Question Type: NAT
graph cannot be disconnected by removing any edge of
A half adder is implemented with XOR and AND
that cycle.
gates. A full adder is implemented with two half adders
  Hence, edge of a simple cycle cannot be a bridge. and one OR gate. The propagation delay of an XOR
Hence, the correct option is (B). gate is twice that of an AND/OR gate. The propagation
Question Number: 40 Question Type: MCQ delay of an AND/OR gate is 1.2 microseconds. A 4-bit
ripple-carry binary adder is implemented by using four
Which one of the following well formed formulae is a
full adders. The total propagation time of this 4-bit
tautology?
binary adder in microseconds is _____.
(A) ∀x ∃y R(x, y) ↔ ∃y ∀x R(x, y)
Solution:  Half adder → XOR gate, AND gate
(B) (∀x [∃y R(x, y) → S(x, y)] → ∀x∃y S(x, y)
Full adder → 2 Half adder, OR gate
(C) [∀x ∃y (P(x, y) → R(x, y)] ↔ [∀x ∃y (P(x, y)
Propagation delay of XOR = 2 × propagation delay of
V R(x, y)]
AND/OR
(D) ∀x ∀y P(x, y) → ∀x ∀y P(y, x) = 2 × 1.2 µs
Solution:  Consider ∀x ∃y (P(x, y) → R(x, y)) = 2.4 µs
∀x ∃y (  P(x, y) ∨ R(x, y)) Half adder delay
( P → Q ⇔ P∨Q)
a
∴ [∀x ∃y(P(x, y) → R(x, y))] ↔ b
Sum delay = 2.4 µs
[∀x ∃y( P(x, y) ∨ R(x,y))]
is a tautology.
Carry delay = 1.2 µs
Hence, the correct option is (C).
Question Number: 41 Question Type: MCQ Full adder delay
Which one of the following assertions concerning code
inspection and code walkthrough is true? a S S Sum
(A) Code inspection is carried out once the code HA HA
b C C
has been unit tested.
(B) Code inspection and code walkthrough are Carry
C
synonyms.

02_GATE 2015 CSIT Set-3.indd 154 6/12/2017 2:26:21 PM


GATE 2015 Solved Paper CSIT: Set – 3 | clv

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− λ

02_GATE 2015 CSIT Set-3.indd 155 6/12/2017 2:26:21 PM


clvi | GATE 2015 Solved Paper CSIT: Set – 3

⇒ (4 – λ)(1 – λ) – 10 = 0 T2 – Time taken to access read request (on cache miss)


⇒ λ2 – 5 λ – 6 = 0 80
⇒ λ2 + λ – 6 λ – 6 = 0 Hit ratio (H) = 80% ⇒ ⇒ 0.8
100
⇒ (λ + 1)(λ – 6) = 0 T1 = 5 ns
⇒ λ = –1, λ = 6 T2 = 50 ns
∴ The larger of the two Eigen values is 6. ∴ Average read access time =
Hence the correct Answer is (6). = [0.8(5) + 0.2(50)] ns
Question Number: 48 Question Type: MCQ = (4 + 10) ns
= 14 ns
An unordered list contains n distinct elements. The
number of comparisons to find an element in this list Hence, the correct Answer is (14).
that is neither maximum nor minimum is Question Number: 51 Question Type: NAT
θ(n log n) (B)
(A) θ(n) A computer system implements a 40-bit virtual address,
θ(log n) (D)
(C) θ(1) page size of 8 kilobytes, and a 128-entry Translation
Look-aside Buffer (TLB) organized into 32 sets each
Solution:  Consider the following list of elements
having four ways. Assume that the TLB tag does not
10 6 8 9 4 11 12 2 store any process id. The minimum length of the TLB
First compare 10, 6 (1 comparison) tag in bits is ______.
Assign minimum element to MIN variable Solution:  TAG bit will be 22-bits
Assign maximum element to MAX variable
22 5 13
MIN = 6
MAX = 10 TAG SET WORD
OFFSET OFFSET
Now compare 8 with MIN and with MAX, nothing got
updated, so 8 could be that element. Hence the correct Answer is (22).
∴ θ(1)
Question Number: 52 Question Type: MCQ
Hence, the correct option is (D).
Consider the following statements.
Question Number: 49 Question Type: NAT
I. The complement of every Turing decidable lan-
The minimum number of JK flip-flops required to con- guage is Turing decidable.
struct a synchronous counter with the count sequence II. There exists some language which is in NP but is
(0,0,1,1,2,2,3,3,0,0,…) is ______. not Turing decidable.
Solution:  The sequence has 4 different states each III. If L is a language in NP, L is Turing decidable.
repeats time 0, 0, 1, 1, 2, 2, 2, 3, 3, 0, 0….. Which of the above statements is/are true?
So total 8 states, no. of JK flip flops = 3 (8 = 23)
(A) Only II (B) Only III
Hence, the correct Answer is (3).
(C) Only I and II (D) Only I and III
Question Number: 50 Question Type: NAT
Assume that for a certain processor, a read request takes Solution: Every Turing decidable is a recursive
50 nanoseconds on a cache miss and 5 nanoseconds language
on a cache hit. Suppose while running a program, it Every Turing recognizable is a recursive – enumerable
was observed that 80% of the processor’s read requests language.
result in a cache hit. The average read access time in Every Turing recognizable is a recursive enumerable
nanoseconds is _______. language.
Solution:  Average read access time = → Complement of Turing decidable languages is
H(T1) + (1 – H) (T2) decidable which is TRUE.
→ if the language is in NP, then it is turing decidable.
H – cache Hit ratio
T1 – Time to access cache Hence, the correct option is (D).

02_GATE 2015 CSIT Set-3.indd 156 6/12/2017 2:26:22 PM


GATE 2015 Solved Paper CSIT: Set – 3 | clvii

Question Number: 53 Question Type: MCQ 20 Swap


Consider the following function written in the C pro-
gramming language.
18 22
void foo(char *a {
16 19 83 23
if ( *a && *a != ‘ ‘){
foo(a + 1);
putchar(*a); 15
} (logn) operations (2 comparisons, 1 swap)
}
Ω(log n)
The output of the above function on input Hence, the correct option is (A).
‘ABCD EFGH’ is Question Number: 55 Question Type: NAT
(A) ABCD EFGH (B) ABCD A binary tree T has 20 leaves. The number of nodes in
(C) HGFE DCBA (D) DCBA T having two children is ______.
Solution:  Consider the following trees.
Solution:  The function foo is a recursive function.
The function reads the input string, character by Case 1:
character until the end of string (or) until the space is
encountered.
foo (′A B C D E F G H’)

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

02_GATE 2015 CSIT Set-3.indd 157 6/12/2017 2:26:23 PM


clviii | GATE 2015 Solved Paper CSIT: Set – 3

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

02_GATE 2015 CSIT Set-3.indd 158 6/12/2017 2:26:23 PM


GATE 2015 Solved Paper CSIT: Set – 3 | clix

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

Solution:  First start with root node then


At the leaf level,
∴ Total 5 nodes
5 7 9 11 13 15
Hence, the correct Answer is (5).

02_GATE 2015 CSIT Set-3.indd 159 6/12/2017 2:26:23 PM


clx | GATE 2015 Solved Paper CSIT: Set – 3

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

02_GATE 2015 CSIT Set-3.indd 160 6/12/2017 2:26:23 PM


UNIT I
THEORY OF COMPUTATION

Chapter 1: RL, FA, RE and RG 1.3


Chapter 2: CFL and PDA 1.18
Chapter 3: CSL, RS, RES, LBA and TM 1.28
Chapter 4: Undecidability 1.33

Gate_CSE_Unit1_Theory of Computation .indb 1 11/19/2015 3:24:47 PM


Gate_CSE_Unit1_Theory of Computation .indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 0 0 1 1 3 1 5 3 2 3 3 2 1 0 1 0 2 3 1 1 2 2 6
2 Marks Ques. 2 0 3 3 2 4 0 4 2 2 3 3 1 2 3 3 4 4 7 5 7 7 2 3 3 3 3 6
5 Marks Ques. 2 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 14 0 11 6 4 13 0 14 5 7 7 11 5 6 9 9 10 9 14 11 14 16 7 7 7 8 8 18

RF, FA, RE&RG 2 0 2 1 1 2 0 4 2 2 2 5 1 3 4 3 2 1 2 2 4 3 3 3 1 2 2 6


CFL and PDA 2 0 1 0 0 1 0 1 1 2 1 2 3 1 1 1 0 4 3 2 3 3 2 1 3 2 1 1
CSL, RS,RES, 0 0 0 1 0 2 0 1 0 0 1 1 0 0 0 2 4 0 1 2 0 2 0 0 0 0 1 3
LBA and TM
Undecidability 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 2

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

Gate_CSE_Unit1_Theory of Computation .indb 3 11/19/2015 3:24:47 PM


1.4 | Theory of Computation

Solution:  r = a*b*(ba)*a* 8. Which one of the following languages over the


‘r’ may generate all the string with length 0,1 and alphabet {0, 1} is described by the regular expres-
2 but that does not guarantee all string will be of sion (0 + 1)*0(0 + 1)*0(0 + 1)*?  [2009]
length 3. (a) The set of all strings containing the substring 00
5. Consider the language L1 = Φ and L2 = {a}. Which (b) The set of all strings containing at most two 0’s
one of the following represents L1 L2 U L1* ? (c) The set of all strings containing at least two 0’s
(d) The set of all strings starting and ending with 0 or 1
[2013]
(a) {ε} (b) ψ Solution: (c)
(c) a* (d) {ε, a} (0 + 1)*0(0 + 1)*0(0 + 1)* will generate all the
strings containing at least two zeros.
Solution: (a)
Hence, the correct option is (c).
L1 = Φ, i.e. L1* = {ε}
9. Consider the set Σ* of all strings over the alphabet
L2 = {a} L2* = a* Σ = {0, 1}. Σ* with the concatenation operators for
L1 ⋅ L2* = Φ strings  [2003]
L1 ⋅ L2*U L1*   (putting L1 ⋅ L2* = Φ) (a) does not form a group.
= Φ U {ε} = {ε}. (b) forms a non-commutative group.
(c) does not have a right identity element.
Hence, the correct option is (a). (d) forms a group if the empty string is removed
6. What is the complement of the language accepted from Σ*.
to be NFA shown below?  [2012] Solution: (a)
Assume Σ = {a} and ε is the empty string. This does not satisfy the inverse property.
a 
Hence, the correct option is (a).
10. The regular expression 0*(10*)* denotes the same
set as  [2003]
 (a) (1*0)*1*
(b) 0 + (0 + 10)*
(a) Φ (b) {ε} (c) (0 + 1)*10(0 + 1)*
(c) a* (d) {a, ε} (d) none of these
Solution: (b) Solution: (d)
By the definition of NFA, L = a+ is accepted lan- Hence, the correct option is (d).
guage and Σ = {a} 11. Consider the following two statements  [2001]
So L’s complement = Σ * – a+ = a* – a+ = {ε} S1 : {0 | n ≥ 1} is a regular language.
2n

Hence, the correct option is (b). S2 : {0m10n | m ≥ 1 and n ≥ 1} is a regular language.


7. Let L1 be recursive language. Let L2 and L3 be the (a) Only S1 is correct
languages that are recursively enumerable but not (b) Only S2 is correct
recursive. Which of the following statements is not (c) Both S1 and S2 are correct
necessarily true?  [2010] (d) None is correct
(a) L2 – L1 is recursively enumerable. Solution: (a)
(b) L1 – L3 is recursively enumerable. As for S2 we cannot construct a FA.
(c) L2 ∩ L1 is recursively enumerable.
For S1, FA is
(d) L2 ∪ L1 is recursively enumerable.
Solution: (b) 0 0
L2 – L1 = L2 ∩ L1 is recursive enumerable.
L1 – L3 = L1 ∩ L3 may not be a regular expression
0
as L3 need not RES.
Hence, the correct option is (b). Hence, the correct option is (a).

Gate_CSE_Unit1_Theory of Computation .indb 4 11/19/2015 3:24:47 PM


Chapter 1  RL, FA, RE and RG | 1.5

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

Gate_CSE_Unit1_Theory of Computation .indb 5 11/19/2015 3:24:47 PM


1.6 | Theory of Computation

Solution: (c) 22. Which of the following four regular expressions


As (10)* (01)*(00 + 11)* is not having the string are equivalent?[1996]
1101. (i) (00)*(e + 0) (ii) (00)*
Hence, the correct option is (c). (iii) 0* (iv) 0(00)*
19. How many substrings of different length (non- (a) i & ii (b) ii & iii
zero) can be formed from a character string of
(c) i & iii (d) iii & iv
length n? [1998]
(a) n (b) n2 Solution: (c)
n ( n +1) 0* = {e, 0, 00, 000…}
(c) 2n (d)
2 (00)*(e + 0) = (00)* + (00)*0 = even + odd = 0*
Solution: (d) Or 0* = (00)*(0 + e)
Total sub-strings can be calculated as Σn = n ( n +1) . (00)* is even number of 0’s and 0(00)* is odd
Hence, the correct option is (d). 2 number of 0’s,
20. Given Σ = {a, b}, which one of the following sets Hence, the correct option is (c).
is not countable.  [1997] 23. State true or false with one line explanation:
(a) Set of all integers over Σ [1994]
(b) Set of all language over Σ A Finite State Machine (FSM) can be designed to
(c) Set of all regular languages over Σ add two integers of any arbitrary length (arbitrary
(d)  Set of all language over Σ accepted by number of digits).
Turing Machines Solution: False
Solution: (b)  It cannot store carry to add arbitrary length
 Because of no one-to-one correspondence because FSM is having finite memory.
between Σ* and N, set of all natural language is Hence, the given statement is false.
not countable.
Hence, the correct option is (b).
21. Let L ⊆ Σ*, where Σ = {a, b}, which of the Two-marks Questions
following is true?  [1996]
(a)  L = { x| X has an equal number of a’s and b’s} 1. Which of the following regular expressions given
is regular below represent the following DFA?  [2014]
(b) L = {anbn| n ≥ 1} is regular
0 0 1
(c) L = {x| x has more a’s than b’s} is regular
(d) L = {ambn| m ≥ 1, n ≥ 1} is regular
Solution: (d)
As a finite autometa can be designed to accept L. 1

a b (i) 0*1 (1 + 00*1)* (ii) 0*1*1 + 11*0*1


a b
q q q (iii) (0 + 1)*1
(a)  i and ii only
b a (b)  i and iii only
q (c)  ii and iii only
a, b (d)  i, ii and iii

Hence, the correct option is (d).

Gate_CSE_Unit1_Theory of Computation .indb 6 11/19/2015 3:24:47 PM


Chapter 1  RL, FA, RE and RG | 1.7

Solution: (b) 3. Consider the following languages


L1 = {0p 1q 0r| p, q, r ≥ 0}
0 1 1
L2 = {0p 1q 0r| p, q, r ≥ 0, p ≠ r}
Which of the following statements is FALSE?
[2013]
0 (a) L2 is context free
(b) L1 ∩ L2 is context free
0*1 is accepted. (c) Complement of L2 is recursive
(1 + 00*1)* is accepted. (d) Complement of L1 is context-free but not
regular
(i) 0*1(0 + 00*1)* is also accepted.
Solution: (d)
0 1 1 L1 = regular language.
L2 = non-regular context-free language intersec-
tion of CFL with regular language L2 ∩ L1 is CFL.
L2 is DCFL and DCFLs complement. So, L2 is
0 DCFL.
  (0 + 11*0)*11* ( 0 + 1*0) L2 is a recursive set and L1 is a regular set.
  (ε + 1)0 = 1*0 Hence, the correct option is (d).
(ii) (1*0)*1 + = (0 + 1)* 4. Consider the set of strings on {0, 1} in which every
 [0*1(1 + 00*1)*] and (0 + 1)*1 are equal and substring of symbol 3 has at most two zeros. For
accepted by FA. example, 1100001 and 011001 are in the language
but 100010 are in the language, but 100010 is not.
Hence, the correct option is (b). All strings of length less than 3 are also in the lan-
2. Let L1 = {w € {0, 1}* | w have at least as many guage. A partially completed DFA that accepts this
occurrences of (110)’s}. Let L2 = {w € {0, 1}* language is shown below.  [2012]
|w have at least as many occurrences of (000)’s as The missing arcs in DFA are
(111)’s}. Which one of the following is true?
[2014] 00
0
(a) L1 is regular but not L2 1
(b) L2 is regular but not L1 0 00
0
(c) Both L1 and L2 are regular 0
 1 q
(d) Neither L1 and L2 are regular 0,1
1 0
Solution: (a) 1 01
As L1 is accepted by FA, L1 = {w € {0,1}* | w has
11
at least as many occurrences of (110)’s}. 1
Let L2 = {w € {0, 1}* | w has at least as many
occurrences of (000)’s as (111)’s} (a) 00 01 10 11 q
L2 requires to maintain a count. It is not accepted 00 1 0
by FA.
01 1
L2 is not regular.
10 0
Hence, the correct option is (a).
11 0

Gate_CSE_Unit1_Theory of Computation .indb 7 11/19/2015 3:24:48 PM


1.8 | Theory of Computation

(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

Case IV: for option (d),


This substring accepts all substrings of three sym-
bols has more than two zero’s.
Hence, the correct option is (d).

Gate_CSE_Unit1_Theory of Computation .indb 8 11/19/2015 3:24:48 PM


Chapter 1  RL, FA, RE and RG | 1.9

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

Gate_CSE_Unit1_Theory of Computation .indb 9 11/19/2015 3:24:48 PM


1.10 | Theory of Computation

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

Gate_CSE_Unit1_Theory of Computation .indb 10 11/19/2015 3:24:49 PM


Chapter 1  RL, FA, RE and RG | 1.11

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

Gate_CSE_Unit1_Theory of Computation .indb 11 11/19/2015 3:24:49 PM


1.12 | Theory of Computation

20. Consider the machine M. The language recognized 1


by M is:  [2005] 1 1
b
b a 0 0
a b b 0 1 0 0
0
a a
a,b 1 1

(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

Gate_CSE_Unit1_Theory of Computation .indb 12 11/19/2015 3:24:49 PM


Chapter 1  RL, FA, RE and RG | 1.13

Let S denote the set of seven bit binary strings in q1


which the first, the forth, and the last bits are 1.
The number of strings in S accepted by M is 0 1,0 1
(a) 1 (b) 5
(c) 7 (d) 8 qz qo
Solution: (c)
1,0 0
The pattern is represented as 1- -1- -1 . Now it will
need 2 4 = 16 ways to fill the blank spaces.
Final NFA will be the language L1 = { 0, 1}*.
So, for this pattern we will have 16 patterns and all
strings will not be acceptable but only seven. Hence, the correct option is (b).
1001 001 is accepted 2 4. The finite state machine is described by the follow-
1001 011 is accepted ing state diagram with A as starting state, where
1001 101 is accepted an arc label is x/y and x stands for 1-bit input and y
1001 111 is accepted stands for 2-bit output.  [2002]
1011 001 is accepted
1101 001 is accepted 0/01
1111 001 is accepted A B C 1/10
1/01 1/10
Hence, the correct option is (c). 0/01
0/00
23. Consider NFA  M shown below:
0 0,1 (a) Outputs the same of the present and previous
bits of the input
(b) Outputs 01 whenever the input sequence con-
0,1 tains 11
1 0 (c) Outputs 00 whenever the input sequence con-
tains 10
(d) None of the above
Let the language accepted by M be L. let L1 be the Solution: (a)
language accepted by the NFA, M1 obtained by If input is 10, output is 01 = 1 + 0 = 01
changing the accepting state of M to a non-accepting If input is 110, output is 01 = 1 + 0
state and by changing the non-accepting state of M
If input is 111, output is 10 = 1 + 1
to accepting states. Which of the following state-
ment is true? [2003] Hence, the correct option is (a).
(a) L1 = {0, 1}* – L 25. The smallest finite which accepts the language
(b) L1 = {0, 1}* [2002]
(c) L1 ⊆ L
L = {x| length of x is divisible by 3}
(d) L1 = L
(a) 2 states (b) 3 states
Solution: (b) (c) 4 states (d) 5 states
Machine M can be represented as Solution: (b)

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

Gate_CSE_Unit1_Theory of Computation .indb 13 11/19/2015 3:24:50 PM


1.14 | Theory of Computation

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

q02 q12 q03 q21 q31 q22 0

Input of length 3 q12 q22 q13


accepts L3
q03 q13 q04
L3 is regular.
Input of length 4 Hence, the correct option is (d).
a b a b
28. What can be said about the regular language L over
{a} whose minimal finite state automation has two
q40 q50 q41 q50 q50 q41 states?  [2000]
q31 q41 q32 q41 q51 q32 (a) must be {an| n is odd
q22 q32 q23 q32 q42 q33
(b) must be {an| n is even
(c) must be {an| n ≥ 0
q13 q23 q14 q23 q33 q24 (d) Either L must be {an| n is odd} or L must be
q04 q14 q05 q14 q24 q15 {an| n is even}
Input of length 5 q05 q15 q15 Solution: (d)
Input of length 6 With two states, minimal finite automation.
a b
a a
q00 q10 q01 a b
q51 q61 q52 q10 q20 q11
a a
q42 q52 q43 q01 q11 q02
q33 q43 q34 q52 q62 q53 Hence, the correct option is (d).
q24 q34 q25 q43 q53 q44 2 9. Let L be the set of all binary strings whose last two
q15 q25 q16
symbols are the same. The numbers of states in the
q34 q44 q35
minimum state deterministic finite-state automa-
q00 q16 q07 q25 q35 q26 tion accepting L is  [1998]
Input of length 7 q16 q26 q17 (a) 2 (b) 5
q06 q17 q00
(c) 8 (d) 3

Input of length 8

Hence, the correct option is (d).

Gate_CSE_Unit1_Theory of Computation .indb 14 11/19/2015 3:24:50 PM


Chapter 1  RL, FA, RE and RG | 1.15

Solution: (b) Present Next state, Z


0 state
X=1 X=0
0
A D, 0 B, 0
0 1
1 B B, 1 C, 1
0 1 0
C B, 0 D, 1
1 D B, 1 C, 0
1 1

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)

34. The regular expression for the language recog-


nized by the finite state automation of is_______
[1994]

Gate_CSE_Unit1_Theory of Computation .indb 15 11/19/2015 3:24:50 PM


1.16 | Theory of Computation

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

Gate_CSE_Unit1_Theory of Computation .indb 16 11/19/2015 3:24:50 PM


Chapter 1  RL, FA, RE and RG | 1.17

Five-marks Questions Solution:  Σ = {1} ∆ = {0,1}


Q = {A, B, C}. 1 for accept
1. Given that language L1 is regular and that the lan- Number of 1’s ≅ 0 mod 3.  0 for reject
guage L1 ∩ L2 is regular. Is the language L2 always
regular?  [1994] 1
[A,1] [B,0]
Solution:  L2 need to be always regular, since
L1 = {am bn | m, n ≥ 0} is regular.
L2 = {am bn | m = n} is non-regular.
1
Now L2 is a subset of L1. 1

Then L1∩ L2 = L1 is regular.


2. Is the class of regular sets closed under infinite [C,0]
union? Explain.  [1989]
Solution:  Infinite union of regular sets need not
be regular. 4. Give the regular expression over {0,1} to denote
the set of proper non-null substring of the string
Ex: L0 = {ε}
0110.  [1987]
  L1 = {a, b}
Solution:  Σ = {0, 1}
  L2 = {a2b2}….
W = 0110
  Ln = {ambn} and so on, where each Ln is regular.
Proper substring of 0110 : {0, 1, 01, 11, 10, 011,
  Then L = n = {ai bi | i ≥ 0 is not regular} 110, 0110}.
3. Give minimum DFA that performs as MOD-3 The regular expression is
counter, i.e. outputs a 1 each time the number of
0 + 1 + 01 + 11 + 10 + 011 + 110 + 0110.
1’s in the input sequence is a sequence is a multiple
of 3.  [1987]

Gate_CSE_Unit1_Theory of Computation .indb 17 11/19/2015 3:24:50 PM


Chapter 2
CFL and PDA

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

Gate_CSE_Unit1_Theory of Computation .indb 18 11/19/2015 3:24:51 PM


Chapter 2  CFL and PDA  |  1.19

6. The language accepted by a Pushdown Automation Solution: (a)


in which the stack is limited to 10 items is best According to NPDA, every language accepted
described as [2002] by empty stack is accepted by final state and vice
(a) Context free versa.
(b) Regular Hence, LD = LE.
(c) Deterministic context free Hence, the correct option is (a).
(d) Recursive 10. Consider the grammar with the following
Solution: (c) productions. [1995]
This type of language is called deterministic con- S → a α b | b α c| aB S→αS|b
text free. S → α b b | ab Sα → bdb | b
Hence, the correct option is (c). The above grammar is
7. Which of the following is true? [2001] (a) Context-free grammar
(a) If a language is context free it can always (b) Regular grammar
be accepted by deterministic pushdown (c) Context-sensitive grammar
automation (d) LR(k)
(b) The union of two context-free languages is
context free Solution: (d)
(c) The intersection of two context-free languages Extra information is added to the state by redefin-
is context free ing items to include a terminal symbol as second
(d) The complement of a context-free language is component in this type of grammar.
context free For example: [A →αβ, a]
Solution: (b) A → αβ is a production, a is a terminal or right end
The context-free language is closed w.r.t. union and marker $. Such an object is called LK (K).
Kleene closure, but not closed under Intersection, Hence, the correct option is (d).
complement.
Every CFL need not be accepted by DPDA.
Hence, the correct option is (b). Two-marks Questions
8. Context-free languages are closed under: [1999]
1. Consider the following language over alphabet
(a) Union, Intersection
= {0, 1, c}
(b) Union, Kleene closure
(c) Intersection, complement L1 = {0n 1n | n ≥ 0}
(d) Complement, Kleene closure L2 = {wcwr | w ∈ {0, 1}*}
Solution: (b) L3 = {wwr | w ∈ {0, 1}*} wr is the reverse of
The context-free languages are closed w.r.t. string w. [2014]
union and Kleene closure, but not closed under Which of these languages are deterministic CFL?
Intersection, complement. (a) None of the language
Hence, the correct option is (b). (b) Only L1
9. Let LD be the set of all languages accepted by a (c) Only L1 and L2
PDA by final state and LE the set of all languages (d) All the three languages
accepted by empty stack. Which of the following Solution: (c)
is true? [1999]
(a) LD = LE L1 = {0n 1n | n ≥ 0} and L2 = {wcwr | w ∈ {0,1}*}
(b) LD ⊃ LE are generated by DPDA.
(c) LD ⊂ LE L3 = {wwr | w ∈ {0,1}*} is not accepted by DPDA.
(d) None of the above Hence, the correct option is (c).

Gate_CSE_Unit1_Theory of Computation .indb 19 11/19/2015 3:24:51 PM


1.20 | Theory of Computation

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)

A A→S A→S error

B B→S B→S E3

Gate_CSE_Unit1_Theory of Computation .indb 20 11/19/2015 3:24:51 PM


Chapter 2  CFL and PDA  |  1.21

(a) a, b
a b $
b b
p q r
S → aAbB S → bAbB
S1 S→ε
S→ε S→ε

A A→S A→S error a a

B B→S B→S B→S


S

Hence, the correct option is (c). a, b


5. Consider the languages L1, L2, L3 as given below: (b) a,b

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

Gate_CSE_Unit1_Theory of Computation .indb 21 11/19/2015 3:24:52 PM


1.22 | Theory of Computation

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

Gate_CSE_Unit1_Theory of Computation .indb 22 11/19/2015 3:24:52 PM


Chapter 2  CFL and PDA  |  1.23

(d) E-P, F-R, G-S, H-Q Positon


1 2 3 4 5 6
Solution: (c) a a b b a b
P)  L = {am bn cn dm | m, n ≥ 1} is to check actual
L 1 A1A1 A1A1 B1B1 B1B1 A1A1 B1B1
and formal parameters.
Q)  X → XbX | XCX | dXf | g generates arithmetic e 2 A2 S B2 S S
expression.
R)  L = {wcw | w ∈ (a | b)*} to check that identi- n 3 A1S B B1S B1S
fiers are declared before their usage
g 4 S A1S φ
S)  X → BXb | XcX | ε to generate palindromes.
Hence, the correct option is (c). t 5 A1S A1S
12. The language L = {0i 21i | i ≥ 0} over the alphabet h 6 S
{0, 1, 2} is [2007]
(a) not recursive
(b) is recursive and a deterministic CFL S → aB S → bA
(c) is a regular language B → b A→a
(d) is not a deterministic CFL but a CFL B → bS A → aS
B → aBB A → bAA
Solution: (b)
The CNF form is
L = {0i 21i | i ≥ 0}
S → A, B S → B, A
0,z0 0z 0 1,2  B → b A→a
0, 0 00 B → B1S A → A1S
B2 → BB S → B1A2
B2 → BB A1 → AA
2,0 0
B1 → b A→a
It is an accepted DCFL and every DCFL is recur- (1, 2) = (1,1) + (2,1) = [A, A1] . [A, A1] = AA
sive set. (2, 2) = (2,1) + (3,1) = [A, A1] . [B, B1]
Hence, the correct option is (b). (3, 2) = (3,1) + (4,1) = [B, B1] . [B, B1]
(4, 2) = (4,1) + (5,1) = [B, B1] . [A, A1]
13. Consider the CFG with {S, A, B} as the non-termi-
nal alphabet, {a, b} as the terminal alphabet, S as (5, 2) = (6,1) + (5,1) = [B, B1] . [A, A1]
the start symbol and the following set of produc- Hence, the correct option is (c).
tion rules: 14. Consider the following statements about the
S → aB S → bA context-free grammar
B → b A→a
G = {S → SS, S → ab, S → ba, S → ε}
B → bS A → aS
(1) G is ambiguous
B → aBB A → bAA
(2) G produces all strings with equal number of a
Which of the following strings is generated by the and b
grammar? [2007] (3) G can be accepted by deterministic
(a) aaaabb (b) aabbbb
Which combination given below expresses all the
(c) aabbab (d) abbbba
true statements about G? [2006]
Solution: (c) (a) 1 only
The grammar generated string must have an equal (b) 1 and 3 only
number of a’s and b’s only but only (c) has three a’s (c) 2 and 3 only
and three b’s. (d) 1, 2 and 3 only
Applying CYK Solution: (d)
As it is both right and left recursive, it is an ambig-
uous grammar.

Gate_CSE_Unit1_Theory of Computation .indb 23 11/19/2015 3:24:52 PM


1.24 | Theory of Computation

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]

Gate_CSE_Unit1_Theory of Computation .indb 24 11/19/2015 3:24:53 PM


Chapter 2  CFL and PDA  |  1.25

(a) Aaa (b) Aabab Solution : (b)


(c) Baaba (d) bab
0
Solution: (c) 0
The string baaba is not accepted by given PDA; 0
1
hence, it is not a member. 0 1
Hence, the correct option is (c). 0
21. Consider the decision problems: [2000]
1
(P1) Does the given finite state machine accept a
1
given string? 1
(P2) Does the given context-free grammar gener-
ate an infinite number of strings? Hence, the correct option is (c).
Which of the following statements is true? 24. Which of the following statements is false?
(a) Both (P1) and (P2) are decidable. [1998]
(b) Neither (P1) nor (P2) is decidable. (a)  Every finite subset of a non-regular set is
(c) Only (P1) is decidable. regular
(d) Only (P2) is decidable. (b) Every subset of a regular set is regular
Solution: (a) (c) Every finite subset of a regular set is regular
(d) The intersection of two regular sets is regular
Membership property of FA is decidable because
of an algorithm provided for CFG. Solution: (b)
Hence, the correct option is (a). Let L1 = { am bn|n, m ≥ 0} is regular.
22. L1 is context-free languages and L2 is a regular set,   L2 = { a b |n, m ≥ 0} is non-regular.
m n

which of the following statements is false?   L1 ∩ L2 = L2 and L2 non-regular [as L1 ⊂ L2].


[1999] So, every set of a regular set need not to be regular.
(a) L1 – L2 is not context free Hence, the correct option is (b).
(b) L1 ∩ L2 is context free
25. Which of the following languages over {a, b, c} is
(c) ∼ L1 is context free
accepted by deterministic pushdown automata?
(d) ∼ L2 is regular
[1997]
Solution: (b)
(a) {w ⊂ wR | w ∈ {a, b}*}
Because L1 is not closed w.r.t. complement, L1 is (b) {w wR |w ∈ {a, b, c}*}
not CFL. (c) {an bn cn |n ≥ 0}
Regular language is closed w.r.t. intersection, ∼ L2 (d) {w|w is a palindrome over {a, b, c}}
is regular. Solution: (a)
Hence, the correct option is (b). It is accepted by DPDA, hence it is DFCL
23. Let L be the set of all binary strings whose last    aa|aa
two symbols are the same. The number of states in
   bb|bb
minimum state deterministic finite state automata
accepting L is [1998] a,z0 az0
a,a aa
(a) 2 (b) 5 a,b ab b,b bb
b,a ba b,z0 bz0
(c) 8 (d) 3 q q q
c,z0 z0 ,z0 

Hence, the correct option is (a).

Gate_CSE_Unit1_Theory of Computation .indb 25 11/19/2015 3:24:53 PM


1.26 | Theory of Computation

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

Gate_CSE_Unit1_Theory of Computation .indb 26 11/19/2015 3:24:53 PM


Chapter 2  CFL and PDA  |  1.27

Five-marks Questions Regularity is preserved under the operation of


string reversal.
1. State whether the following statements are TRUE/ (b) False
FALSE? [2002] L1 = {am bn | m, n ≥ 0} is regular.
(a) Regularity is preserve under the operation of L2 = {am bn | m = n} is non-regular.
string reversal Now L1∩ L2 = L2
(b) All subsets of regular sets are regular All subsets of regular sets are regular.
(c) A minimal DFA that is equivalent to a NFDA (c) False
with n nodes has always 2n states. DFA that is equivalent to a NFDA with n nodes
(d) The intersection of two CFL is also a CFL. has always 2n states
(e) A recursive if both a and its complement are (d) False
accepted by turning machine M accepts L1 ∩ L2 is not CFL if L1 and L2 are CFL.
(f) The problem is to whether a TM M accepts in-
(f) True
put w is undecidable.
After taking input string to TM it may go to
Solution:  final halt, non-final halt, infinite loop.
(a) True
As regular language satisfies closure property
with respect to reversal operator.
L = {ab}  = {a, b}
R
L = {ba}

a b
FA q0 q1 q2

a b
q0 q1 q2 FA

Gate_CSE_Unit1_Theory of Computation .indb 27 11/19/2015 3:24:53 PM


Chapter 3
CSL, RS, RES, LBA and TM

One-mark Questions Solution: (a)


Both (0 + 1)* and Φ are regular sets. So, L is
1. Regarding the power of recognition of languages, regular and hence recursive.
which of the following statements is false?[1998] Hence, the correct option is (a).
(a) The non-deterministic finite state automata are 3. If the strings of a language L can be effectively
equivalent to deterministic finite state automata enumerable in lexicographic order, which of the
(b)  Non-deterministic push-down automata are following statements is true?[2003]
equivalent to deterministic push-down automata (a) L is necessarily finite
(c) Non-deterministic TM are equivalent to deter- (b) L is regular but not necessarily finite
ministic TM (c) L is context-free but not necessarily regular
(d) Multi-tape TM are equivalent to single-tape TM (d) L is recursive but not necessarily context-free
Solution: (b) Solution: (d )
As NFA and DFA both accept the regular sets, the
Let |w| = n. We enumerate strings of length one,
statement (a) is true.
then two, then three… Then it will be known that
Non-determinism does not add power to TM. So,
the string is enumerable. So, the language is recur-
(c) is true.
sive as the membership problem is decidable.
Multi-tape TM can be simulated to single-tape
Hence, the correct option is (d).
TM. So, (d) is also true.
4. Which of the following is true for language {ap | P
Hence, the correct option is (b).
is prime}?
2. Nobody knows yet if P = NP. Consider the (a) It is not accepted by Turing Machine
language L defined as follows:[2003] (b) It is regular but not context-free
L = (1 + 0)* if P = NP (c) It is context-free but not regular
Φ otherwise. (d) It is neither regular nor CFL but accepted by
Which of the following statements is true? TM.
(a) L is recursive Solution: (d)
(b) L is recursively enumerable but not recursive Language {ap | P is prime} is enumerable of primes
(c) L is not recursive enumerable in unary. It is CSL not CFL. Every CFL is a regular
(d) Whether L is recursive or not will be known set.
after we find out if P = NP
Hence, the correct option is (d).

Gate_CSE_Unit1_Theory of Computation .indb 28 11/19/2015 3:24:54 PM


Chapter 3  CSL, RS, RES, LBA and TM  |  1.29

5. Which of the following is true/false? Solution:  (c and d)


(1) Non-deterministic TM are equivalent to deter- The recursive language is a superset of CSLs and
ministic TM CFLs regular set. They are properly included.
(2) Turing recognizable languages are closed un-
The recursive language is accepted by halting TM;
der union and complementation
hence, they are a class of turing machines.
(3) Turing decidable languages are closed under
intersection and complementation The superset of language is accepted by PDA.
(4) Turing recognizable languages are closed un- Type (0) languages are the r.e sets which are super-
der union and intersection sets of the recursive sets.
(a) 1 and 4 only (b) 1 and 3 only Hence, the correct options is (c and d)
(c) 2 only (d) 3 only 2. In which of the cases stated below is the following
Solution: (c) statement true?[1992]
Case-2:  Turing recognizable languages are not ‘For every deterministic machine M1 there exists
closed under complement but closed equivalent deterministic machine M2, recognizing
under union and intersection. the same language’.
Case-1: Non-determinism does not add power to (a) M1 is non-deterministic finite automation
TM. (b) M1 is non-deterministic PDA
(c) M1 is non-deterministic TM
Case-3:  Turing decidable languages are closed
(d) For no machines M1 use above statement
under union, intersection and complement.
Solution:  (a and c)
Case-4: Turing recognizable languages are closed
under union, intersection and complement. The regular sets which are accepted by NFA and
DFA. The r.e sets which are accepted by determin-
Hence, the correct option is (c).
istic TM are also accepted by non-deterministic
6. Let A ≤m B denote that language A is mapping TM.
reducible (also known as many-to-one reducible) Hence, the correct options is (a and c)
to language B. Which of the following statements
is false? 3. Which of the following conversion is not possible
(a) If A ≤m B and B is recursive then A is recursive (algorithmically)?[1994]

(b) If A ≤m B and A is undecidable then B is unde- (a) Regular grammar to CFG
cidable (b) Non-deterministic FSA to deterministic FSA
(c) If A ≤m B and B is recursively enumerable then (c) Non-deterministic PDA to deterministic PDA
A is recursively enumerable (d) Non-deterministic TM to deterministic TM
(d) If A ≤m B and B is not recursively enumerable Solution: (c)
then A is not recursively enumerable Regular grammar is CFG, non-deterministic FSA
Solution: (d) is deterministic FSA and non-deterministic TM to
A ≤m B. If B is not RES then A may or may not be deterministic TM.
RES. So, (d) is false. Hence, correct option is (c)
Hence, the correct option is (d). 4. Which of the following is not decidable?[1997]
(a) Given TM M, a string s and an integer k, M
accepts s within k steps
Two-marks Questions (b) Equivalence of two TM
1. Recursive languages are: (c)  Language accepted by given finite state
(a) A proper superset of CFL machine is non-empty
(b) Always recognizable by PDA (d)  Language accepted by given context-free
(c) Also called Type (0) languages grammar is non-empty
(d) Recognizable by TM Solution: (b)
(a) Given TM M, a string s and an integer k, M
accepts s within k steps has finite step.

Gate_CSE_Unit1_Theory of Computation .indb 29 11/19/2015 3:24:54 PM


1.30 | Theory of Computation

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

Gate_CSE_Unit1_Theory of Computation .indb 30 11/19/2015 3:24:54 PM


Chapter 3  CSL, RS, RES, LBA and TM  |  1.31

9. Let L1 be a recursive language and let L2 be a Solution: (b)


recursive enumerable but not a recursive language. The answer is to be valid for all DCFLS and all r.e
Which one of the following is true?[2005] sets.
(a)  L1 is recursive and L2 is recursively Hence, the correct option is (b)
enumerable
(b) L1 is recursive and L2 is not recursively 12. If L and L ’ are recursively enumerable then L is
enumerable [2008]
(c) L1 and L2 are recursively enumerable. (a) Regular (b) Context-free
(d) L1 is recursively enumerable and L2 is (c) Context-sensitive (d) Recursive
recursive. Solution: (d)
Solution: (b) To find the membership take a string w and run
The recursive sets are closed under complement both halts TM accepts L and L′. closed or them will
but the classes of r.e sets are not closed under halt we know if w is accepted or rejected by L.
complement. Hence, the correct option is (d)
Hence, the correct option is (b) 13. Let L be a language and L′ be its complement.
10. For s ∈ (0 + 1)*, let d (s) denote the decimal value Which one of the following is NOT a viable pos-
of s.[2006] sibility?[2014]
(a) Neither L1 nor L′ is recursively enumerable.
Let L = {s ∈ (0 + 1)* | d (s) cmad 5 = 2 and d (s) (b) One of L and L′ is r.e but not recursive; the
mod 7 ≠ 4} other is not r.e
Which one of the following is true? (c) Both L and L′ are r.e but not recursive
(a) L is recursively enumerable (d) Both L and L′ are recursive
(b) L is recursive but not context-free Solution: (c)
(c) L is context-free but not regular
Hence, the correct option is (c)
(d) L is regular
14. Let <M> be the encoding of a Turing machine has
Solution: (d)
a string over Σ = {0, 1}. Let L = { <M> | M be a
The FA can compute modulo. The modulo machine TM that accepts a string of length 2014}. Then L
is an FA. is[2014]
Hence, the correct option is (d) (a) decidable and recursively enumerable
11. Let L1 be a regular language, L2 be a deterministic (b) non-decidable but recursively enumerable
CFL, and L3 be a recursively enumerable but not (c) non-decidable and not recursively enumerable
recursive.[2006] (d) decidable but not recursively enumerable
Which one of the following is false? Solution: (b)
(a) L1 ∩ L2 is deterministic CFL L is recursively enumerable but undecidable.
(b) L3 ∩ L1 is recursive
Hence, the correct option is (b)
(c) L1 ∪ L2 is context-free
(d) L1 ∩ L2 ∩ L3 is recursively enumerable

Gate_CSE_Unit1_Theory of Computation .indb 31 11/19/2015 3:24:54 PM


1.32 | Theory of Computation

Five-marks Question The prime in unary is a standard CSL that is not a


CFL or regular. So, (b) is valid.
1. Which one of the following is true? There could be
The number of set of language is closed under infi-
more than one answer.[1992]
nite union. Any undecidable set can be considered
(a) Union of two recursive languages is recursive
to be infinite union of finite sets and every finite set
(b) The language {0n| n is prime} is not regular
is regular.
(c) Regular languages are closed under infinite
union Hence, the correct options is (a and b)
Solution:  (a and b)
The recursive sets are closed under union, inter-
section and complement. So, (a) is valid.

Gate_CSE_Unit1_Theory of Computation .indb 32 11/19/2015 3:24:54 PM


Chapter 4
Undecidability
(a) Whether intersection of two regular languages
One-Mark Questions is infinite
(b) Whether a given context-free language (CFL)
1. Let Σ be a finite non-empty alphabet and let 2Σ* be
is regular
the power set Σ*.  [2014]
(c) Whether two push-down automata (PDA) ac-
Which one of the following is true? cept the same language
(a) Both Σ* and 2Σ* are countable (d) Whether a given grammar is context-free
(b) Σ* is uncountable and 2Σ* are countable
Solution: (b)
(c) Σ* is countable and 2Σ* are uncountable
(a) Regular sets are decidable
(d) Both Σ* and 2Σ* are uncountable
(b) It is undecidable for CFG L and a regular lan-
Solution: (c) guage R is L = R.
Σ* is countable since there is a one-to-one corre- (c) Equivalence problem is undecidable
spondence between Σ* and N. (d) Syntax of grammar is context-free can also be
Again, we know that if S is countable then 2s decidable
is uncountable. So Σ* is countable but 2Σ* are Hence, the correct option is (b).
uncountable sets.
4. Which of the following statements is false?[1996]
Hence, the correct option is (c) (a) The halting problem for TM is undecidable
2. Which of the following statement is undecidable? (b) Determining whether ambiguity in a context-
[2012] free grammar is undecidable
1. Does a given program ever produce an output? (c) Given two arbitrary context-free grammars G1
2. If L is CFL then L’ is also CFL and G2, whether L(G1) = L(G2)
3. If L is regular, then L’ is also regular (d) Given two regular grammars G1 and G2 it is
4. If L is recursive, then L’ is also recursive undecidable whether L(G1) = L(G2)
Solution: (d) Solution: (d)
(a) This can be reduced to the halting problem of (a)  The halting problem for TM is a standard
TMs. undecidable problem
(b) The CFLs are not closed under complement (b)  Ambiguity in a context-free grammar is
(c) The regular sets are closed under complement undecidable
(d) The recursive sets are closed under comple- (c) Equivalence problem is undecidable
ment (d) The regular sets are a well-behaved class of
Hence, the correct option is (d). languages
3. Which of the following statement is undecidable? Hence, the correct option is (d).
[2008]

Gate_CSE_Unit1_Theory of Computation .indb 33 11/19/2015 3:24:54 PM


1.34 | Theory of Computation

Two-marks Questions (a) X is decidable


(b) X is un-decidable but partially decidable
1. Which of the following statement is undecidable? (c)  X is un-decidable and not even partially
[2014] decidable
(a) Deciding if a given context-free grammar is (d) X is not a decision problem
ambiguous
Solution: (c)
(b) Deciding if a string is generated by CFG
Hence, the correct option is (c)
(c) Deciding if the language generated by given
CFG is empty 5. Which of the following is the strongest correct
(d) Deciding if the language generated by a given statement about a finite language over some finite
CFG is finite. alphabet Σ ? [1991]
Solution: (a) (a) It could be undecidable
(b) It is TM recognizable
The ambiguity of CFG is undecidable. No algo-
(c) It is regular language
rithm exists to decide whether the given CFG is
(d) It is a CSL
ambiguous or not.
Solution: (c)
Hence, the correct option is (a)
If L is finite, it is automatically a regular set. The
2. Which of the following statement is un-decidable?
CFLs < R.E, CSLs are larger sets.
[2013]
Hence, the correct option is (c).
1. G is CFG. Is L(G) = Φ
2. G is CFG. Is L(G) = Σ* 6. It is decidable whether: [1990]
3. M is a TM. Is L(M) regular (a) An arbitrary TM halts after 10 Φ steps
4. A is a DFA and N is an NFA. Is L(A) = L(N)? (b) A TM prints a specific letter.
(a) 3 only (b) 3 and 4 only (c) A TM computes the product of two numbers
(c) 1, 2, 3 only (d) 2 and 3 only (d) None of the above.
Solution: (d) Solution: (a)
Emptiness of CFG is decidable. The completeness (a) By running TM for 10 steps we will find that it
problem of CFG is undecidable. This is a non-trivial is decidable
problem so by Rice’s theorem it is undecidable. (b) TM prints a specific letter, is decidable.
The NFS and DFA both accept regular set. So, this (c) TM computes the product of two numbers, so
is decidable. it is undecidable.
Hence, the correct option is (d). Hence, the correct option is (a).
3. Consider the three decision problems P1, P2, P3. It 7. Which of the following statement is undecidable?
is known that P1 is decidable and P2 is undecidable. [1989]
Which of the following is true? [2005] (a) Membership problem in CFL
(a) P3 is decidable if P1 is reducible to P3 (b) Whether a given CFL is regular
(b) P3 is un-decidable if P3 is reducible to P2 (c) Whether a FSA halts on all input
(c) P3 is un-decidable if P2 is reducible to P3 (d) Membership problem for type (0) problem
(d) P3 is decidable if P3 is reducible to P2 ‘s
Solution:  (b) and (d)
complement
(a) parsing algorithm can be used to decide mem-
Solution: (a) bership in CFGs
P3 is decidable if P1 is reducible to P3 (b) We cannot decide if a CFL accepted by a PDA
Hence, the correct option is (a). is regular. Moreover, the regularity problem is
4. Consider the following problem X. [2001] undecidable.
‘Given a TM M over the input alphabet Σ, any state (c) Halting problem of FA is decidable.
q of M and a word w ε Σ*, does the computation of (d) Membership problem for type (0) problem
M on w visit the state q’. reduces to the halting problem of TMs and is
undecidable.
Which of the following statements about X is
correct? Hence, the correct option is (b) and (d).

Gate_CSE_Unit1_Theory of Computation .indb 34 11/19/2015 3:24:55 PM


UNIT II
COMPILER DESIGN

Chapter 1: Lexical Analysis 2.3


Chapter 2: Parsing Techniques 2.6
Chapter 3: Syntax Directed Translation 2.17
Chapter 4: Code Generated and Optimization 2.20

Gate_CSE_Unit2_Compiler Design.indb 1 11/19/2015 3:26:17 PM


Gate_CSE_Unit2_Compiler Design.indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 1 0 2 0 0 0 1 3 1 1 2 0 1 2 0 4 2 1 1 1 2 2 2 1 1 1 3
2 Marks Ques. 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 5 2 5 5 5 1 0 2 0 0 1 3
5 Marks Ques. 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
Total Marks 0 6 0 2 0 2 0 1 5 1 1 2 2 1 2 2 14 6 11 11 11 9 2 6 1 1 3 9

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

Gate_CSE_Unit2_Compiler Design.indb 3 11/19/2015 3:26:17 PM


2.4 | Compiler Design

5. Type checking is normally done during  [1998] Group –II


(a) The lexical analyzer (a) DAG’s
(b) The syntax analyzer (b) Syntax tree
(c) Syntax directed translation (c) Pushdown automation
(d) The code optimizer (d) Finite automation
Solution: (c) Solution:  (a-s, b-p, c-q, d-r)
During semantic analysis, phase-type checking is DAG’s are used for code optimization and make
performed that is implemented by SDT. it easy to find common sub-expression. Syntax
Hence, correct option is (c). directed translation can make use of syntax
6. In some programming languages, an identifier is tree. Abelian groups are related with pushdown
permitted to be letter followed by any number of automation.
letters or digits. If L and D denotes the sets of let- 9. In a compiler the module that checks every
ters and digits, respectively. Which of the follow- character of the source text is called: [1988]
ing expression defines an identifier? [1995] (a) The code generator
(a) (L ∪ D )+ (b) L (L ∪ D)* (b) The code optimizer
(c) (L.D)* (d) L (L.D)* (c) The lexical analyzer
Solution: (b) (d) The syntax analyzer
Identifier = letter followed by any number of Solution: (c)
letters or digits = L (L ∪ D)* Each and every character of the input string is read
Hence, correct option is (b). by lexical analyzer and then it generates token.
7. Which of the following string can definitely be Hence, correct option is (c).
said to be tokens without looking at the next input
character while compiling a Pascal program? Two-marks Question
 [1995]
I. begin II. Program III.<> 1. The number of tokens in the FORTRAN statement
(a) I (b) II DO 10 I = 1.25 is [1999]
(c) III (d) All of the above (a) 3
Solution: (c) (b) 4
As begin & program are reserved words, we know (c) 5
‘<>’ is a token simply by reading the first symbol (d) None of the above
‘<’. Solution:  ( c)
Hence, correct option is (c). Tokens: DO → 1
8. Match the followings:  [1990] 10 → 2
Group-I I → 3
(a) Lexical analysis
= → 4
(b) Code optimization
(c) Code generation 1.25 → 5
(d) Abelian groups Total no. of tokens = 5.
Hence, correct option is (c).

Gate_CSE_Unit2_Compiler Design.indb 4 11/19/2015 3:26:17 PM


Chapter 1  Lexical Analysis   |  2.5

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.

Gate_CSE_Unit2_Compiler Design.indb 5 11/19/2015 3:26:17 PM


Chapter 2
Parsing Techniques

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.

Gate_CSE_Unit2_Compiler Design.indb 6 11/19/2015 3:26:17 PM


Chapter 2  Parsing Techniques  |  2.7

(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

Gate_CSE_Unit2_Compiler Design.indb 7 11/19/2015 3:26:18 PM


2.8 | Compiler Design

9. In a bottom evaluation of a syntax directed defini- S → A


tion, inherited attributes can [2003] A → a
(a) always be evaluated S → a has same leftmost and rightmost derivation.
(b) be evaluated only if the definition is Considering the grammar
L-attributed S → AB
(c) be evaluated only if the definition has A → a
synthesized attributes B → b is unambiguous grammar.
(d) never be evaluated leftmost derivation: S → AB → Ab → ab
Solution:  (b) rightmost derivation: S → AB → Ab → ab
So (a) is false.
L-attributed is very broad definition, deals with
the entire string left of the part being scanned. Hence, correct option is (a).
Hence, correct option is (b). 13. Which of the statements are true? [1998]
(a) SLR parser is more powerful than LALR.
10. Assume that SLR parser for a grammar G has n1
(b) LALR parser is more powerful than canonical
states that LALR parser for G has n2 states.The
LR parser.
relationship between n1 and n2 is [2003]
(c) Canonical LR parser is more powerful than
(a) n1 is necessarily less than n2
LALR parser.
(b) n1 is necessarily equal to n2
(d) The parsers SLR canonicals LR and LALR
(c) n1 is necessarily greater than n2
have the same power.
(d) none of the above
Solution:  (c)
Solution:  (b)
(a) The grammar
The DFA for SLR & LALR parser have the same S → L
numbers of states. S → R
So, n1 is equal to n2. L → *R/id
Hence, correct option is (b). R → L is a grammar that is LALR but not
SLR. Hence false.
11. The process of assigning load address to the
(b) S → Aa/bAc/Bc/bBa
various parts of the program and adjusting the
A → d
code and data in the program to reflect the assigned
B → d is lR but not LALR. Hence false.
addresses is called [2001]
(c) S → E + T/T
(a) Assembly
T → T*F/F
(b) Parsing
F → (E)id IS A GRAMMAR that is SLR but
(c) Relocation
not LALR or LALR.Hence false.
(d) Symbol resolution
(d) S → Xa/bXc/Yc/bYa
Solution:  (a) X → d
The statement describes the process of assembly in Y → d is the grammar that is LR but not
an assembler. LALR. Hence true.
Hence, correct option is (a). Hence, correct option is (c).
12. Which of the statement is false? [2001] 14. The pass numbers for each of the following
(a) An unambiguous grammar has same leftmost activities [1996]
and rightmost derivation (i) Object code generation
(b) An LL(1) parser is a top-down parser (ii) Literals added to literal table
(c) LALR parser is more powerful than SLR (iii) Listing printed
(d) An ambiguous grammar can never be LR(k) (iv) Address resolution of local symbols that occur
for any k in a two pass assembler, respectively are
Solution:  (a) (a) 1, 2, 1, 2 (b) 2, 1, 2, 1
An unambiguous grammar has same leftmost and (c) 2, 1, 1, 2 (d) 1, 2, 2, 2
rightmost derivation.

Gate_CSE_Unit2_Compiler Design.indb 8 11/19/2015 3:26:18 PM


Chapter 2  Parsing Techniques  |  2.9

Solution:  (c) (a)  Cannot be merged since look ahead is


Object code generation is a backend final activity. different.
So, it occurs is pass 2. (b) Can be merged but will result in S-R conflicts.
When literals encountered in source code, then it is (c) Can be merged but will result in L-R conflicts.
added to literal table . (d) Cannot be merged since go to on ‘c’ will lead
Whatever is read in is printed out. So in 1 pass. to two different sets.
As address resolution is backend activity. So, it Solution:  (d)
occurs in pass 2. The given LR(1) item can be merged any way
Hence, correct option is (c). after merging , no R-R conflict occurs and again in
LALR no S-S conflict exists.
Two-marks Questions So, 2 & 3 are false.
Again 1 & 4 are also false.
1. A canonical set of items is given below: in [2014] Since, the items can be merged, hence, correct
S → L > R option is (d).
Q → R Hence, correct option is (d).
On input symbol < the set has 3. The grammar S → aSa|bS|c is [2010]
(a) A shift-reduce conflict and a reduce-reduce (a) LL(1) but not LR(1)
conflict (b) LR(1) but not LL(1)
(b) A shift-reduce conflict but not a reduce-reduce (c) BOTH LL(1) and LR(1)
conflict (d) Neither LL(1) nor LR(1)
(c) A reduce-reduce conflict but not shift-reduce Solution:  (c)
conflict The LL(1) predictive parsing table is as follows:
(d) Neither a shift reduce conflict nor a reduce-
reduce conflict S1 → S
Solution:  (d) S → aSa| bS|c
S → L > R A B C $

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]

Gate_CSE_Unit2_Compiler Design.indb 9 11/19/2015 3:26:18 PM


2.10 | Compiler Design

4. An LALR parser for grammar G can have shift C → b


reduce (S-R) conflicts iff [2008] S → a
(a) The SLR (1) parser for G has S-R conflicts
Rewriting the rule
(b) The LR (1) parser for G has S-R conflicts
(c) The LR (0) parser for G has S-R conflicts S → iCtSS1|a
(d) The LALR (0) parser for G has reduce con- S1 → eS/∈
flicts C → b
Solution: (b) S → a
The LR (1) parser for G has S-R conflicts. The given grammar suffers from the dangling else
Hence, correct option is (b). problem.
5. Consider the following two statements: [2007] Hence, correct option is (c).
P: every regular grammar is LL (1) Common Data for Questions 7 and 8
Q: every regular set has LR (1) grammar Consider the CFG with {S, A, B} as non-terminal
Which one of the following is true? alphabet, {a, b} as terminal alphabet, as a start
(a) Both P & Q are true symbol and the following set of production rules.
(b) P is true and Q is false  [2007]
(c) Q is true and P is false S → bA
(d) Both P & Q are false A → a
Solution: (c) A → aS
Consider regular grammar S → aA/a S → bAA
The grammar is a regular grammar that is not LL B → b
(1).
B → bS
So, statement P is false.
B → aBB
Every regular set is a DCFL. Every DCFL has an
7. Which of the following strings is generated by the
LR(k) grammar in particular therefore L is a DCFL.
grammar?
Statement Q is true. (a) aaaabb (b) aabbbb
Hence, correct option is (c). (c) aabbab (d) abbbba
6. Consider the grammar with non-terminals N = {S, Solution:(c)
C, S1}, terminals T = {a, b, i, t, e} with S as the S ⇒ aB
lm
start symbols, and the following sets of rules
  ⇒ aaBB (B → aBB)
S → iCtSS1|a lm
  ⇒ aabB (B → b)
S1 → eS|ε lm

C → b   ⇒ aabbS (B → bS)
lm

The grammar is not LL(1) because: [2007]   ⇒ aabbaB (S → aB)


lm
(a) It is left recursive   ⇒ aabbab (B → b)
(b) It is right recursive 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/∈

Gate_CSE_Unit2_Compiler Design.indb 10 11/19/2015 3:26:18 PM


Chapter 2  Parsing Techniques  |  2.11

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

Gate_CSE_Unit2_Compiler Design.indb 11 11/19/2015 3:26:18 PM


2.12 | Compiler Design

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]

Gate_CSE_Unit2_Compiler Design.indb 12 11/19/2015 3:26:18 PM


Chapter 2  Parsing Techniques  |  2.13

2#2&5#6&4 (a) 9 + 5 + 2 (b) 95 + 2 +


(a) 200 (b) 180 (c) 952 + (d) + + 952
(c) 160 (d) 40 Solution:  (b)
Solution: (c) Let us construct a recursive descent parser for the
E. value = 160 given grammar.
13 13 void main ()
13
{
E1. value = 16 T. value = 10 scan(); S();
8 8 12 12
}
8 12 void R()
E1. value = 2 # T. value = 8 T. value = 6 & F. value = 44 {
7 if (input = ’ + ’)
3 7 7 { scan(); T();
10
T. value = 3 & F. value = 5
T. value = 2 print (num.val);
F. value = 6
R()
5 11
2
}
else if (input! = $) error();
6 9 }
1 4
void T()
Num = 2 Num = 3 Num = 5 Num = 6 Num = 4 {
The rightmost derivation follows: print(num.val);
E ⇒ E1 # T⇒ E1 # T & F }
⇒ E1 # T & 4 ⇒ E1 # 4 & F We have to take the leftmost derivation for a top-
down parser
⇒ E1 # 6 & 4⇒ E1 # T # 6 & 4
S
⇒ E1 # T & F # 6 & 4
⇒ E1 # T1 & 5 # 6 & 4
T R
⇒ E1 # F & 5 # 6 & 4
⇒ E1 # 3 & 5 # 6 & 4 num + T R
⇒ E1 # 3 & 5 # 6 & 4
9 num +
⇒T#3&5#6&4 5
T R

⇒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]

Gate_CSE_Unit2_Compiler Design.indb 13 11/19/2015 3:26:19 PM


2.14 | Compiler Design

⇒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

Gate_CSE_Unit2_Compiler Design.indb 14 11/19/2015 3:26:19 PM


Chapter 2  Parsing Techniques  |  2.15

S 22. Consider the SLR (1) and LALR (1) parsing ta


bles for a context-free grammar. Which of the fol-
5
5 lowing statements are true? [1992]
(a) The go to part of both tables may be different
x x w
(b) The shift entries are identical in both tables.
4 4 print ("3") (c)  The reduce entry in both tables may be
different.
Z (d) The error entries in the tables may be different.
S
Solution:  (b)
print ("1")
3 The shift entries are identical in both tables.
3 3
W
Hence, correct option is (b).
x x

2 2 print ("3")

S Z

1 print ("2")

Hence, correct option is (a).

Gate_CSE_Unit2_Compiler Design.indb 15 11/19/2015 3:26:19 PM


2.16 | Compiler Design

Five-marks Questions The LR(0) machine:

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 –

Gate_CSE_Unit2_Compiler Design.indb 16 11/19/2015 3:26:19 PM


Chapter 3
Syntax Directed
Translation
3. In the following grammar
One-mark Questions
X:: X ⊕ Y/Y
1. One of the purposes of using intermediate code in Y:: Z ⊗ Y/Z
compiler is to: [2014] Z:: id
(a) Make parsing and semantic analysis simple.
Which of the following is true? [1997]
(b) Improve error recovery and error reporting.
(a) ⊕ is left associative
(c) Increase the chances of reusing the machine-
(b) Both ⊕ and ⊗ are left associative
independent code optimizer in other compiler.
(c) ⊕ is right associative while ⊗left associative
(d) Improve the register location.
(d) None of the above
Solution:  (c)
Solution:  (a)
After semantic analysis, the code is converted to
⊕ is left associative,
intermediate code which is language independent.
The advantage is to improve the performance of Hence, correct option is (a).
the code generation and to increase the chances of 4. A linker is given object module for a set of pro-
reusing the machine independent code optimizer gram that were compiled separately. What infor-
in the other compilers. mation needs not to be included in an object
Hence, correct option is (c). module? [1995]
(a) Object code
2. Which of the following is FALSE? [2003]
(b) Relocation bits
(a) In statistically-typed languages, each variable
(c) Names and location of all external symbols
in a program has a fixed type.
defined in object module
(b) In un-typed language, values do not have any
(d) Absolute address of internal symbol
type.
(c) In dynamically typed languages, variable have Solution:  (c)
no type. Independent compilation of modules needs phase
(d) In all statistically typed languages, each vari- called ‘linking’ to resolve names used in one mod-
able in a program is associated with value of ule but defined in another module.
any single type during the execution of the Hence, correct option is (c).
program.
5. Generation of intermediate code based on an
Solution:  (a) abstract machine model is useful in compilers
Hence, correct option is (a). because: [1994]
(a) It makes implementation of lexical analysis
and syntax analysis easier.

Gate_CSE_Unit2_Compiler Design.indb 17 11/19/2015 3:26:19 PM


2.18 | Compiler Design

(b) Syntax directed translation can be written for a = b + c


intermediate code generation. c = a + d
(c) It enhances the probability of the front end of d = b + c
compiler. e = d - b
(d) It is not possible to generate code for real
a = e + b
machine directly from high-level language.
program Number of nodes = 6
Solution:  (a) Number of edges = 6
(a) FALSE. The lexical analysis and syntax analy- Hence, correct option is (a).
sis phases are the front end of compiler. 2. The program below uses six temporary variables a,
(b)  FALSE. Syntax directed translation can be b, c, d, e, f.
written for intermediate code generation but a=1
this has got nothing to do with usefulness.
b = 10
(c) TRUE. For ex- JAVA software which is so
c = 20
portable as it is based on JVM.
(d) FALSE. It is possible to generate code directly d=a+b
from source code language but the code gen- e=c+d
eration routine becomes bulky. f=c+e
Hence, correct option is (a). b=c+e
e=b+f
d=5=e
Two-marks Questions Assuming that all operators take their operands
from registers, what is the minimum number of
1. Consider the basic block given below: registers needed to execute this program without
a=b+c spilling? [2010]
c=a+d
(a) 2 (b) 3
d=b+c
(c) 4 (d) 6
e=d–b
a=e+b Solution:  (a)
The minimum number of nodes and edges present a=1
in the DAG representation of the above basic block b = 10
respectively, are [2014] c = 20
(a) 6 and 6 (b) 8 and 10
(c) 9 and 12 (d) 4 and 14 a b
Solution:  (a) d=a+b
+ a d

a, d e c d
+ –

b
c

Gate_CSE_Unit2_Compiler Design.indb 18 11/19/2015 3:26:19 PM


Chapter 3  Syntax Directed Translation  |  2.19

e=c+d 3. Which of the following grammar rules violates the


requirement of an operator grammar ?
c e
P, Q, R are no terminals, and r, s, t are terminals.
b=c+e  [2002]
b c (1) P → QR (2) P → QsR
(3) P → ε (4) P → QtRr
f=c+e (a) 1 only (b) 1 & 3 only
b f (c) 2 & 3 only (d) 3 & 4 only
e=b+f Solution:  (b)
(1) P → QR, no two non-terminals can be
f e adjacent on the RHS of a rule.
d=5+e (2) P → ∈, no ∈ - production are allowed in an
operator grammar.
f d
Hence, correct option is (b).
Hence, correct option is (a).
This page is intentionally left blank.

Gate_CSE_Unit2_Compiler Design.indb 24 11/19/2015 3:26:20 PM


Chapter 3  Structure Query Language  |  3.17

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

Set commission = commission * 1.04


Where commission > 50000 and commission is Inner query is correlated sub query, therefore,
< = 100000; T.price > B.Price is equivalent for every B. Price
gives count 4 (300, 400, 500, 600) which is less
T3 Update sales info than 5. Similarly count 3 (400, 500, 600). So, the
Set commission = commission * 1.06 query will list out titles of 200, 300, 400, 500 and
Where commission > 100000; 600, i.e., 5 most expensive book.
Which of the following options of running these Hence, the correct option is (d).
transactions will update the commission of all
salespersons correctly? [2005]
Chapter 3  Structure Query Language  |  3.21

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

Solution: (d) Id Name Age

The RA represents all empId’s – empId of 12 Arun 60


employee whose age is below than some depend- 15 Shreya 24
ent age); result, set of empId of employee whose 99 Rohit 11
age is greater than all of his/her dependent.
B
Hence the correct option is (d)
Id Name Age
2. Consider a join (relation algebra) between relation
r(R) and s(S) using the nested loop method. There 15 Shreya 24
are 3 buffers each of size, out of which one buffer 25 Hari 40
is reserved for intermediate results. Assuming size 98 Rohit 20
((r(R)) < size((s(S)) , the join will have fewer num- 99 Rohit 11
ber of disk block access if [2014]
(a) Relation r(R) is in outer loop. C
(b) Relation s(S) is in outer loop.
(c) Join selection factor between r(R) and s(S) is Id Phone Area
more than 0.5. 10 2200 02
99 2100 01

Chapter 4  Relational Algebra and Relational Calculus  |  3.27

4. Consider a relational table r with sufficient num- I. Πp (R∞ S)


ber of records having attributes A1 II. Πp (R) ∞ Π p(S)
A2 , A3 ………. An and let 1≤p≤n. Two queries Q1 III. ΠP(ΠPQ(R)∩ ΠP, Q(S))
and Q2 are given below. IV. ΠP(Π P.Q(R) - Π P.Q(R) - Π P.Q(S))) [2008]
Q1: πA1…..Ap(σAp = c(r) ) where A is constant (a) Only I and II (b) Only I and II
Q2: πA1…..Ap(σC1≤A≤C2(r) ) where c1 and c2 are (c) Only I, II and III (d) Only I, II and IV
constant Solution: (c)
The database can be configured to do ordered In I, II and III, query selects attributes P from com-
indexing on Ap or hashing on Ap. Which of the fol- mon rows between R and S.
lowing statements is TRUE? [2011] Hence the correct option is (c)
(a)  Ordered indexing will always outperform
7. Consider the following relation schemas:
hashing for both queries.
(b) Hashing will always outperform ordered in- b - Schema = (b - name, b - city, assets)
dexing for both queries. a - Schema = (a - num, b - name, bal)
(c) Hashing will outperform ordered indexing for Let branch, account and despositor be respec-
Q1, but not on Q2. tively instances of the above schemas. Assume that
(d) Hashing will outperform ordered indexing for account and depositor relations are much bigger
Q2, but not on Q1. than the branch relation.
Solution: (c) Consider the following query:
Hence the correct option is (c) Πc - name (σb - city = ”Agra” ∧ bal < 0 (branch
5. The following functional dependencies hold for Symbol (account Symbol depositer))
relations R (A, B, C) and S (B, D, E): Which one of the following queries is the most
B → A, efficient version of the above query ? [2007]
A → C Π c - name (σbal < 0 (σb - city = ‘‘Agra” branch
(a) 
The relation R contains 200 tuples and the relation Symbol account) Symbol depositer)
S contains 100 tuples.
(b) Π c - name (σ b - city = “Agra “ branch Symbol
What is the maximum number of tuples possible in
(σbal < 0 Symbol account Symbol depositer))
the natural join
Π c - name (σ b - city = “Agra” branch
(c) 
R S? [2010]
(a) 100 (b) 200 Symbol σb - city = “Agra” ∧ bal < 0 account
(c) 300 (d) 2000 depositer)
Solution: (a) (d) Π c - name (σ b - city = “Agra” branch
Common column between tables R and S is attrib- (σb - city = “Agra” ∧ branch Symbol bal < 0
ute B. In table R, B is primary key (B→A, A→C). account Symbol depositer))
In table S, B is foreign key, so, join are performed Solution: (b)
on attribute B.
Bal < 0 flters row from account ∞ depositor from
Therefore, minimum tuples possible in the output which we can operate on few rows to filter b city =
is equal to rows in Table S. ‘agra’.
Hence the correct option is (a) Hence the correct option is (b)
6. Let R and S be two relations with the following 8. Consider the relation employee (name, sex, super-
schema: visor Name) with name as the key. supervisor
R (P, Q, R1, R2, R3) Name gives the name of the supervisor of the
S (P, Q, S1, S2) employee under consideration. What does the fol-
lowing tuple relational calculus query produce?
Where (P, Q} is the key for both schemas. Which
of the following queries are equivalent? {e.name | employee (e) ^ (x) [¬ employee (x) v x.
3.28 | Database Management System

supervisor Name ≠ e. name v x. sex = “male”]} Student Info Enroll


 [2007]
a) Names of employees with a male supervisor. Studid Name Sex Stud Id CourseId
b) Names of employees with no immediate male 1 – M 1 a
subordinates.
2 – F 2 b
c) Names of employees with no immediate fe-
male subordinates. 3 – M 1 c
d) Names of employees with a female supervisor. 4 – M 4 d
Solution: (c)
One condition says x.sex equal to male and another Cross product produces
condition says x.supervisor name not equal to
StudId CourseId
e.name. Since it is negation, it produces names
with no intermediate female subordinates. 2 a
Hence the correct option is (c) 2 b
9. Consider a selection of the form σA≤100(r) , where 2 c
r is a relation with 1000 tuples. Assume that the
2 d
attribute values for A among the tuple are uni-
formly distributed in the interval[0, 500]. Which
one of the following options is the best estimate of P courseld (Cross product - Enroll) =
the number of tupples returned by the given selec-
tion query? [2007] CouseId
(a) 50 (b) 100 A
(c) 150 (d) 200
C
Solution: (d)
D
Rows are uniformly distributed from 0 - 500 and
there are 1000 rows. Hence condition A < = 100
produces 200 rows. [2007]
(a) Courses in which all the female students are
Hence the correct option is (d)
enrolled.
10. Information about a collection of students is given (b) Courses in which a proper subset of female
by the relation studInfo (studId, name, sex). The students are enrolled.
relation enroll (studId, courseId) gives which stu- (c) Courses in which only male students are en-
dent has enrolled for (or taken) what course (s). rolled.
Assume that every course is taken by at least one (d) None of the above.
male and at least one female student. What does the
Solution : (c)
following relational algebra expression represent?
Hence the correct option is (c)
ΠcourseId ((ΠstudId (σsex = “female”(studinfo)) × ΠcourseId
(enroll)) - enroll) 11. A table ‘student’ with schema (roll, name, hostel,
marks), and another table ‘hobby’ with schema
(roll, hobbyname) contains records as shown
below:
Chapter 4  Relational Algebra and Relational Calculus  |  3.29

Hobby Solution: (a)


Roll Name Hostel Marks Roll
Name SQL query returns 10 rows (2154, 2369, 2581,
Manoj 2643, with marks 92, 2711, 2872, 2926, 2959,
1798 7 95 1798 chess
Rathod 3125, 3125 with chess as hobby).RA query pro-
Soumic duces 4 rows, hence difference is 6 rows.
2154 5 68 1798 music
Banerjee Hence the correct option is (a)
Gumma
2369 7 86 2154 music 12. Consider the relation Student (name, sex, marks),
Reddy
where the primary key is shown underlined, per-
Pradeep
2581 6 92 2369 swimming taining to students in a class the has at least one
Pendse
boy and one girl. What does the following rela-
Suhas
2643 5 78 2581 cricket tional algebra expression produce?
Kulkarni
Nitin
Π name (σsex - female (Student)) - Π name (Student
2711 8 72 2643 chess
Kadam ρn, x, m (Student))
Kiran (sex = female
2872 5 92 2643 hockey x = male
Vora
∧marks ≤ m) [2004]
Manoj
2926
Kunkalikar
5 94 2711 volleyball (a) Names of girl students with the highest marks
(b) Names of girl students with more marks than
Hemant
2959
Karkhanis
7 88 2872 football some boy student
(c) Names of girl students with marks not less
Rajesh
3125
Doshi
5 82 2926 crickets than some boy student
(d) Names of girl students with more marks than
2959 photography all the boy students
Solution: (d)
3125 music
Minus sign indicates rows available in LHS tables,
3125 chess but not in RHS tables. LHS table produces all the
female student whereasRHS table consists student
The following SQL query is executed on the above with less marks, hence the expression produces the
tables: name of all female students with more marks than
select hostel all the male student.
from student natural join hobby Hence the correct option is (d)
where marks > = 75 and roll between 2000 and 13. Which of the following relational calculus expres-
3000; sions is not safe? [2001]
Relations S and H with the same schema as those (a) {t ∃u ∈ R1 (t[AJ] = u [] A]J ) ∧ ¬∃s ∈ R2 (t ]
of these two tables respectively contain the same [ A]J = s ][ A]J )}
information as tuples. A new relation S is obtained (b) {t ∀u ∈ R1 (u ][ A]J = “ x “ c ∃s ∈ R2 (t [] A]
by the following relational algebra operation: J = s ][ A]J ∧ s ][ A]J = u ][ A]J ))}
(c) {t ¬ (t ∈ R1 )}
S’ = Π hostel ((σs.roll = H.roll(σmarks > 75 and roll > 2000 and roll (d) {t ∃u ∈ R1 (t ][ A]J = u ][ A]J ) ∧ ∃s ∈ R2 (t ]
< 3000
(S)) X(H)) [ A]J = s ][ A]J )}
The difference between the number of rows output Solution: (c)
by the SQL statement and the number of tuples in
S’ is [2005] TRC produces infinite results, hence it is not con-
(a) 6 (b) 4 sidered safe.
(c) 2 (d) 0 Hence the correct option is (c)
3.30 | Database Management System

14. Which of the following query transformations Solution: (a)


(i.e., replacing the L.H.S. expression by the R.H.S. Apply first cross product then filter.
C1, C2 are selection conditions and A1, A2 are
Id B. Id X gives 10 rows Condition
attribute of R1 [1998] (cross
(a) σC1 (σc2 (R1) ) σc2 (σc2 (R1) ) product) A.Id B.Id A.Id > 40 V CId<15
(b) σC1 (πA2 (R1) ) πc2 (σc2 (R1) ) 5 rows 2 rows 12 10 √
(c) σC1 ( (R1πR2) σc1 ( R1) π σc1 (R2) ) 12 99 ×
15 10 √
(d) πA2 (σc2 (R1) )σc1( πA2 (R1) ) 15 99 ×
Solution: (a) 25 10 √
25 99 ×
Here are values of selection condition C1 ≠ 98 10 √
C2, therefore, it is not equivalent. Others are 98 99 √
equivalents. 99 10 √
Result contains 7 rows   99    99   √
Hence the correct option is (a)
15. A library relational database system uses the fol- Hence the correct option is (a)
lowing schema 1 7. How many tuples does the result of the following
USER (User #, User Name, Home Town) SQL query contain?
BOOK (Book#, Book Title, Author Name) SELECT A.Id
ISSUES (Book#, User#, Date) FROM A
Explain in one English sentence, what each of the WHERE A.Age > ALL (SELECT B.Age
following relational algebra queries is designed to FROM B
determine.
(a)  σUser# = 6(II User#, Book Title((USERS IS- WHERE B.Name = ‘Arun’)
SUED BOOKS)) (a) 4 (b) 3
(b) Π Author Name (BOOKS(σHome Town = (c) 0 (d) 1
Delhi (USER ISSUED))) [1996] Solution: (b)
(a) Title of book issued to user 6. The ALL keyword specifies that search condi-
(b) Names of authors of books that are issued to tion is TRUE if the comparison is TRUE for every
users who are from Delhi. value that the sub query returns.
16. How many tuples does the result of the following If sub query returns no value, the condition is
relational algebra expression contain? Assume that TRUE.
the schema (AUB) is the same as that of A. Hence the correct option is (b)
(AUB) l >< l A.Id > 40 v c.id < 15 C
(a) 7 (b) 4
(c) 5 (d) 9
Chapter 5
Transactional and
Concurrency Control
3. Which level of locking provides the highest degree
One-mark Questions of concurrency? [2004]
(a) Page
1. Which of the following concurrency control pro- (b) Table
tocols ensure both conflict serializability and free- (c) Row
dom from deadlock? (d) Pages, table and row level locking allow the
I. 2-phase locking same degree of concurrency
II. Time-stamp ordering [2010] Solution: (c)
(a) I only (b) II only Row has lower level of granularity hence concur-
(c) Both I and II (d) Neither I nor II rency is high.
Solution: (b) Hence, the correct option is (c).
2PL is based on locks, and hence not free from 4. Which of the following scenarios may lead to an
deadlock, but ensures conflict serializability. Time irrecoverable error in a database system? [2003]
stamp ordering is based on time stamp ensures (a) A transaction writes a data item after it is read
conflict serializability, and is deadlock free. by an uncommitted transaction.
Hence, the correct option is (b). (b) A transaction reads a data item after it is read
2. Amongst the ACID properties of a transaction, by an uncommitted transaction.
the ‘Durability’ property requires that the changes (c)  A transaction reads a data item after it is
made to the database by a successful transaction written by a committed transaction.
persist [2005] (d)  A transaction reads a data item after it is
(a) Except in case of an operating system crash written by an uncommitted transaction.
(b) Except in case of a disk crash Solution: (d)
(c) Except in case of a power failure Dirty read is reading uncommitted data. If transac-
(d) Always, even if there is a failure of any kind tion reads uncommitted data and commits before
Solution: (d) the transaction that writes data item, leads to non-
Changes made by committed transaction should be recoverable schedule if
permanent in nature. Hence, the correct option is (d).
Hence, the correct option is (d).
3.32 | Database Management System

Two-marks Questions 2. Consider the following schedule S of transactions


T1, T2, T3, T4: [2014]
1. Consider the transactions T1, T2, and T3 and the T1 T2 T3 T4
schedules S1 and S2 given below.
Reads(X)
T1: r1(X); r1(Z); w1(X); w1(Z)
Writes (X)
T2: r2(Y); r2(Z); w2(Z) Commit
T3: r3(Y); r3(X); w3(Y)
Writes(X)
S1: r1(X); r3(Y); r3(X); r2(Y); r2(Z); w3(Y); w2(Z); Commit
r1(Z); w1(X); w1(Z)
Writes (Y)
S2: r1(X); r3(Y); r2(Y); r3(X); r1(Z); r2(Z); w3(Y); Reads (Z)
w1(X); w2(Z); w1(Z) Commit
Which one of the following statements about the
Reads (X)
schedules is TRUE? [2014] Reads (Y)
(a) Only S1 is conflict-serializable. Commit
(b) Only S2 is conflict-serializable.
(c) Both S1 and S2 are conflict-serializable. Which one of the following statements is
(d) Neither S1 nor S2 is conflict-serializable. CORRECT?
Solution : (a) (a) S is conflict-serializable, but not recoverable.
S1: (b)  S is not conflict-serializable, but is
T1 T2 T3
recoverable.
R(x)
Precedence graph (c) S is both conflict-serializable and recoverable.
R(y)
R(y) R(x) (d)  S is neither conflict-serializable nor is it
R(z) recoverable.
T1 T2 W(y)
W(z)
Solution: (c)
R(z) The precedence graph given is
W(x)
T3 W(z) T1 T2

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

read(b); read (a); 1. Both s1 and s2 are not conflict serializable


if A = 0 if B → 0 2. Both s1 and s2 are conflict serializable
then B → B + 1; then A → A – 1; 3.  s1 is not conflict serializable and s2 is conflict
write (b); write (a); serializable
commit; commit; 4.  s1 is conflict serializable and s2 is not conflict
unlock (a); unlock (a); serialazable
unlock (b); unlock (a); Solution: (c)
(b) S1; lock X (a); S2: lock X (b);
S1:
read (a); read (b);
lock X (b); lock X (a); r1(Y) , w2(Y) are conflict, hence T2 < T1.
read (b); read (a); R2(X) , w1(x) are conflict, hence T2 < T1. There is
if A = 0 if B → 0 no serial schedule which satisfies both the above
then B → B + 1; then A → A –1; rules. Hence, S is not conflict serializable.
write (b); write (a); S2:
unlock (a); unlock (a);
r2(X), w1(x) are conflict, hence T2 < T1.
commit; commit;
unlock (b); unlock (b); W2(Y), r1(Y) are conflict, hence T2 < T1. There is
(c) S1; lock S(a); S2: lock S(b); a serial schedule that satisfies T2 < T1, hence S is
read (a); read (b); conflict serializable.
lock X (b); lock X (a); Hence, the correct option is (c).
read (b); read (a); 11. Consider the following schedule S of transactions
if A = 0 if B → 0 T1 and T2: [2004]
then B → B + 1; then A → A –1;
T1 T2
write (b); write (a);
unlock (a); unlock (a); Read (a) Read (a)
A = A – 10 Tamp = 0.2* A
commit; commit;
Write (a)
unlock (b); unlock (b); Read (b)
(d) S1; lock S(a); S2: lock S(b); Write (a)
read (a); read (b); read (b) B + B + Tamp
lock X (b); lock X (a); B = B + 10 Write (b)
read (b); read (a);
Write (b)
if A = 0 if B → 0
then B → B + 1; then A → A –1; Which of the following is TRUE about the
write (b); write (a); schedule S ?
unlock (a); unlock (a); (a) S is serializable only as T1, T2
unlock (b); unlock (b); (b) S is serializable only as T2, T1
commit; commit; (c) S is serializable both as T1, T2 and T2, T1
(d) S is serializable either as T1 or as T2
Solution: (c)
Solution: (d)
In strict 2PL, all exclusive locks must be removed
after commit statements. Hence, option C is R1(a) , W2(a) [it says T1 < T2] and R2(a) , W1(a)
correct. [it says T2 < T1] are conflict operations. Hence,
options (a, b, c) are wrong . It can be either serial-
Hence, the correct option is (c). izable with T1 or T2 because at some times, we will
10. Consider the following schedules involving two have only one transactions.
transactions. Which one of the following state- Hence, the correct option is (d).
ments is TRUE?[2007]
S1: r1(X); r1(Y); r2(X); r2(Y); w2(Y); w1(X)
S2: r1(X); r2(X); r2(Y); w2(Y); r1(Y); w1(X)
3.36 | Database Management System

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

6. There are five records in a database.


Insert 8 8
Name Age Occupation category

Rama 27 CON A
Abdu 22 ENG A
Jeniffer 28 DOC B Split: 2
Maya 32 SER D
Insert 4
Dev 24 MUS C

(a) Age (b) Name


(c) Occupation (d) category
Solution: (c) Insert 2
Index file is associated with the database with val-
ues 1, 3, 2, 5, and 4 and which is applicable to field
occupation where
CON index = 1 DOC index = 2
ENG index = 3 MUS index = 4
SER index = 5 Split: 3
Hence, the correct option is (c). Insert 1

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

(iii) The roots nodes remains unchanged (disre-


garding the links).
Which of the following options are true?
(a) Statement (i) & (ii) are true
(b) Statement (ii) & (iii) are true
(c) Statement (iii) & (i) are true
(d) All the statements are false.
Solution: (a)
If we remove K50 in index node, there is no change
3. Keys K 15 and then K 25 are inserted into this tree in height as still root, index and node leaf exists.
in that order. Exactly how many of the following
Leaf nodes are now, after deleting 50, the B + is
nodes (disregarding the links) will be present in
the tree after the two insertions?
K30 K50 K25 K30

K20 K25 K15 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

6. Consider a table T in a relational database with a Solution: (c)


key field K. A B-tree of order p is used as an access Formulas to compute n X P + (n - 1)K < = B,
structure on K, where p denotes the maximum where P is the block pointer, K search key value
number of tree pointers in a B-tree index node. and B is block size. Therefore n X 6 + (n - 1)14 =
Assume that k is 10 bytes long; disk block size is 512, ∴n = 26.
512 bytes; each data pointer PD is 8 bytes long and
Hence, the correct option is (c).
each block pointer PB is 5 bytes long. In order for
each B-tree node to fit in a single disk block, the 8. A B + - tree index is to be built on the Name attrib-
maximum value of p is [2004] ute of the relation STUDENT. Assume that all stu-
(a) 20 (b) 22 dent names have the length of 8 bytes, disk block
(c) 23 (d) 32 have the of size 512 bytes, and index pointers are
of size 4 bytes. Given this scenario, what would be
Solution: (c)
the best choice of the degree (i.e., the number of
n X P + (n - 1) k + (n - 1)14 < = B, pointers per node) of the B + –tree? [2002]
Where n is order of the nodes, p is the block (a) 16 (b) 42
pointer, k search key value and B is block size. (c) 43 (d) 44
n X 5 + (n - 1)10 + (n - 1)8 < = B, 23n = 530, Solution: (a)
∴n = 23. n X P + (n - 1)K < = B. Where n is order of the
Hence, the correct option is (c). nodes, p is the block pointer , k search key value
7. The order of an internal node in a B* tree index and B is block size.
is the maximum number of children it can have. n X 4 + (n - 1)8 = 512, 12 n = 512 ,
Suppose that a child pointer takes 6 bytes, the ∴n = 43.
search field value takes 14 bytes, and the block
Hence, the correct option is (a).
size is of 512 bytes. What is the internal node?
 [2004]
(a) 24 (b) 25
(c) 26 (d) 27
UNIT IV
COMPUTER NETWORKS

Chapter 1: Fundamental and SWP 4.3


Chapter 2: Local Area Network 4.6
Chapter 3: TCP/IP 4.9
Chapter 4: Application Layer and Routing Algorithm 4.17

Gate_CSE_Unit4_Computer Networks.indb 1 11/19/2015 6:59:54 PM


Gate_CSE_Unit4_Computer Networks.indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 5 1 2 2 0 2 1 4 2 7
2 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 5 2 4 5 4 3 3 2 3 2 9
5 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 12 9 9 12 10 6 8 5 10 6 25

Fundamental and SWP 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2 0 0 2 1 0 1 0 2


LAN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 0 4 0 0 0 0 0 1 2
TCP/IP 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 5 4 2 1 5 1 2 0 5 2 10
Application Layer and 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 2 3 1 1 2
Routing Algorithms

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)

Gate_CSE_Unit4_Computer Networks.indb 3 11/19/2015 6:59:54 PM


4.4 | Computer Networks

Solution: Then within 50µsec it is capable of delivering


RTT = 100msec, within 1 msec link can be 0.9 = 50* 10 - 3*106 = 25 × 103
Mbps, therefore 100 msec it can transfer 90 x 103 Wpackets = Wbits / Packet size in bits
bits = window size in bits.
2n = 25
Window size in packets = 90 × 10 = 11 packets.
3

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.

Gate_CSE_Unit4_Computer Networks.indb 4 11/19/2015 6:59:54 PM


Chapter 1  Fundamentals and SWP  |  4.5

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

Gate_CSE_Unit4_Computer Networks.indb 5 11/19/2015 6:59:54 PM


Chapter 2
Local Area Network
3. In a network of LANs connected by bridges, pack-
One-mark Questions ets are sent from one LAN to another through
intermediate bridges. Since more than one path
1. In the diagram shown below, L1 is an Ethernet may exists between two LANs packets may have
LAN and L2 is a token-ring LAN. An IP packet to be routed through multiple bridges. Why is the
originates from sender S and traverse to R, as spanning tree algorithm used for bridge-routing?
shown. The links within each ISP and across two  [2005]
ISPs are all point-to-point optical links. The initial (a) For the shortest path routing between LANs
value of TTL field is 32. The maximum possible (b) For avoiding loops in routing paths
value of TTL field when R receives the datagram (c) For fault tolerance
is ___________ . [2014] (d) For minimizing collisions
ISP2 LAN L2 Solution: (b)
ISP1
TTL is used by network layer to avoid infinite
looping.
Hence, the correct option is (b)
LAN L1
S

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.

Gate_CSE_Unit4_Computer Networks.indb 6 11/19/2015 6:59:54 PM


Chapter 2  Local Area Network  |  4.7

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)

Gate_CSE_Unit4_Computer Networks.indb 7 11/19/2015 6:59:54 PM


4.8 | Computer Networks

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)

Gate_CSE_Unit4_Computer Networks.indb 8 11/19/2015 6:59:54 PM


Chapter 3
TCP/IP

3. A bit-stuffing based framing protocol uses 8-bit


One-mark Questions delimiter pattern of 01111110. If output bit-string
after stuffing is 01111100101, then the input bit-
1. Identify the correct order in which the following string is [2014]
actions take place in an interaction between a web (a) 0111110100 (b) 0111110101
browser and a web server. [2014] (c) 0111111101 (d) 0111111111
1. The web browser requests a web using HTTP.
2.  The web browser establishes a connection Solution: (b)
with a web server. Stuffed bit is 4th bit from the last.
3. The web server sends the request web pages Hence, the correct option is (b)
using HTTP. 4. Host A (on TCP/IP v4 network A) sends IP dia-
4. The web browser resolves the domain name gram D to host B(also on TCP/IP network B).
using DNS. Assume that no error occurs during the transmis-
(a) 4, 2, 1, 3 (b) 1, 2, 3, 4 sion of D, when D reaches B, which of the follow-
(c) 4, 1, 2, 3 (d) 2, 4, 1, 3 ing IP header field may be different from that of
Solution: (a) the original datagram D? [2014]
First name is done by DNS, then connection is (i) TTL
established through TCP to request and get HTTP (ii) Checksum
objects. (iii) Fragment offset
Hence, the correct option is (a) (a) (i) only
(b) (i) and (ii) only
2. Which one of the following socket functions con- (c) (ii) and (iii) only
verts an unconnected and TCP sockets into a pas- (d) (i), (ii) and (iii)
sive socket? [2014]
(a) Connect (b) Bind Solution: (d)
(c) Listen (d) Accept In IP datagram, checksum is recalculated at each and
Solution: (c) every router because 16-bit datagram length, TTL,
MF, offset and options are changing at every router.
The listen function is called by only TCP server
and it performs two action – the listen function Hence, the correct option is (d)
converts an unconnected socket into a passive 5. The transport layer protocols used for real time
socket, indicating it should accept incoming con- multimedia, file transfer, DNS and e-mail, respec-
nection requests directed to this socket. It also tively, are [2013]
specifies the maximum number of connections in (a) TCP, UDP, UDP and TCP
the queue for this socket. (b) UDP, TCP, TCP and UDP
Hence, the correct option is (c)

Gate_CSE_Unit4_Computer Networks.indb 9 11/19/2015 6:59:55 PM


4.10 | Computer Networks

(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

Gate_CSE_Unit4_Computer Networks.indb 10 11/19/2015 6:59:55 PM


Chapter 3  TCP/IP  |  4.11

(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

Gate_CSE_Unit4_Computer Networks.indb 11 11/19/2015 6:59:55 PM


4.12 | Computer Networks

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

Gate_CSE_Unit4_Computer Networks.indb 12 11/19/2015 6:59:55 PM


Chapter 3  TCP/IP  |  4.13

131.22.0.0/15 1 threshold at the start of the first transmission is 8


The identifier of the output interface on which this MSS. Assume that a time out occur during the fifth
packet will be forwarded____________. [2014] transmission. Find the congestion window size at
the end of ten transmission. [2012]
Solution:
(a) 8 MSS (b) 14 MSS
Perform AND operation between IP and /12, /14, (c) 7 MSS (d) 12 MSS
/16, /15 mask. If result matches, we “prefix” given
Solution: (d)
in the table then that interface packet is forwarded.
If it match with multiple mask, then use longest Transmission10 Window Size
length mask. 1 2 MSS
6. Every host n an IPv4 network has a 1-second reso- 2 4 MSS
lutionution real time clock battery back-up. Each 3 8 MSS Meets required
host needs to generate up to 1000 unique identi- threshold
fiers per second. Assume that each host a glob- 4 10 MSS Linear growth
ally unique IPv4 address. Design a 50-bit globally
5 12 MSS Timeout occurs,
unique ID for this purpose. After what period (in
hence, conges-
seconds) will the identifiers generated by a host
tion window set to
wrap around? [2014]
2 MSS and new
Solution: 256 threshold is 6 MSS
IP4 is 32-bit address, so 18-bits are used for 6 2 MSS
unique identification for 50-bits. If host generates 7 4 MSS
1000 identifier per second , then in 256 sec, it can
8 6 MSS Meets threshold
generate 218 identifiers.
9 8 MSS Linear growt
7. In an IPv4 datagram, the M bit is 0, the value of
HLEN is 10, the value of total length is 400 and 10 10 MSS
the fragment offset Id 300. The position of data- 11 12 MSS At the end of the
gram, the sequence numbers of the first and last 10th transmission,
bytes of the payload, respectively [2013] it is 12 MSS
(a) Last Fragment, 2400 and 2789 Hence, the correct option is (d)
(b) First Fragment, 2400 and 2759
(c) Last Fragment, 2400 and 2759 9. Suppose computer A and B have IP address
(d) Middle Fragment, 300 and 689 10.105.1.113 and 10.105.1.91, respectively. They
both uses the same net mask N. What value of N
Solution: (c) should not be used if A and B should belong to the
For last fragment always M = 0. If header length network? [2010]
is 40 bytes, therefore, total data in fragment is 400 (a) 255.255.255.0 (b) 255.255.255.128
- 40 = 360 bytes. (c) 255.255.255.192 (d) 255.255.255.224
Since offset is 300 total bytes ahead of this Solution: (d)
fragment is 8 × 300 = 2400 bytes. If result of AND operation between given mask
Therefore it is last fragment, starting byte is 2400 and IP address of A and B is same, then use mask
and ending byte is 2759 (as 2400 + 360 = 2760 else not.
bytes but byte number starts with zero, so it is from Mask: 255.255.255.111 00000
2400 to 2759).
AND
Hence, the correct option is (c)
IP(A):10.105.1.011 10001
8. Consider an instance of TCP’s Additive Increase
Multiplicative Decrease(AIMD) algorithm where 10.105.1.011 10001
the window size at the start phase is 2 MSS and Mask: 255.255.255. 11100000

Gate_CSE_Unit4_Computer Networks.indb 13 11/19/2015 6:59:55 PM


4.14 | Computer Networks

IP(B): 10.105.1.01011011 13. A Client process P needs to make a TCP con-


10.105.1. 0100000 nections to a server process S. Consider the fol-
lowing situations; the server process S executes
Hence, the correct option is (d)
a sockets(), a bind(), and a listen() system call in
1 0. While opening a TCP connection, the initial that order, following which it is preempted sub-
sequence number is to be derived using a Time- sequently the client process P executes a sockets
of-Day (ToD) clock that keeps running even when () system call followed by connect the server pro-
the host down. The low order 32-bits of the coun- cess S. The server process has not executed any
ter of the ToD clock is to be used for the initial accept() system call. Which one of the following
sequence numbers. The clock counter increments events could take place? [2008]
once per milliseconds and maximum packet life- (a) Connect() system call returns successfully
time is given to be 64s. Which one of the follow- (b) Connect() system call blocks
ing choice given below is the closest to minimum (c) Connect() system call returns an error
possible rate at which sequence numbers used for (d) Connect() system call results in a core dump
packets connection can increase? [2009]
Solution: (c)
(a) 0.015 /s (b) 0.064/s
(c) 0.135/s (d) 0.327/s Hence, the correct option is (c)
Solution: (b) 14. The address of a Class B host is to be split into
subnets with a 6-bits number. What is the maxi-
Wraparound time of sequence numbers should not
mum number of subnets and the maximum num-
be less than life period of the packet. If counter
ber of hosts in each subnets? [2007]
increments for every millisecond, then the rate at
(a) 62 subnets and 262142
which sequence numbers can increase is 64/1000
(b) 64 subnets and 262142
= 0.064/s.
(c) 62 subnets and 1022 hosts
Hence, the correct option is (b) (d) 64 subnets and 1024 hosts
11. In a slow start phase of the TCP congestion con- Solution: (c)
trol algorithm, the size of the congestion window
Class B has 16-bits as host ID out of which you
 [2008]
borrow 6-bits, then
(a) does not increase
(b) increases linearly Host ID bits = 10
(c) increases quadratically So, total host per subnet 210 - 2 = 1022
(d) increases exponentially Total subnets = 26 = 64.
Solution: (d) Hence, the correct option is (c)
Congestion window increase exponentially in slow 15. Two computers C1 & C2 are configured as follows:
start phase.
C1 has IP address 203.197.2.53 and net mask
Hence, the correct option is (d) 255.255.128.0, C2 has IP address 203.197.75.201
12. If a Class B network on the Internet has a subnet and net mask 255.255.192.0. Which one of the fol-
mask of 255.255.248.0, what is the maximum lowing statements is TRUE? [2006]
number of hosts per subnet? [2008] (a) C1 and C2 both assume they are on the same
(a) 1022 (b) 1023 network.
(c) 2046 (d) 2047 (b) C2 assumes that C1 is on the same network, but
Solution: (c) C1 assumes C2 is on a different network.
(c) C1 assumes C2 is on same network, but C2 as-
255.255.248.0, 5 bits are borrowed from 16-bit
sumes C1 is on a different network.
host ID for subnet IDs. Therefore, 11 bots are left-
(d) C1 and C2 both assumes they are on different
over for host ID, Hence no of hosts per subnets =
networks.
211 - 2 = 2046
Hence, the correct option is (c)

Gate_CSE_Unit4_Computer Networks.indb 14 11/19/2015 6:59:55 PM


Chapter 3  TCP/IP  |  4.15

Solution: (c) A: 1000 bytes


Both netmask, one subnet mask. In (255.255.128.0) B: 100 bytes
7-bits are borrowed from network, therefore 27 C: 1000 bytes
networks are aggregation, i.e., 128 networks.
The Network A and B are connected through a
C1 was 203.197.2.53 if we consider this start- 1Mbps link, while B and C are connected by a 512
ing network then last network in the super net is Kbps link (bps = bits per second).
203.197.130. So, C1 assumes (203.197.75.201) is
within C1, C2 has netmask 255.255.192.0, 6-bits Destination Subnet Mask Interace
are borrowed from network, there 26 = 64. 128.75.43.0 255.255.255.0 Eth0
Networks are aggregated could be from 128.75.43.0 255.255.255.128 Eth1
203.197.75……..203.197.139. 192.12.17.5 255.255.255.255 Eth3
Therefore C1 assumes C2 is on the sub network, but default Eth2
C2 assumes C1 is on a different network.
Hence, the correct option is (c) [2004]
16. A TCP message consisting of 2100 bytes passed to 17. Assuming that the packets are correctly delivered,
IP for delivery across the network. First network how many bytes, including headers, are delivered
can carry a maximum payload of 1200 bytes per to IP layer at the destination for one application
frame. And the second network can carry a maxi- messages, in the best case? Consider only data
mum payload of 400 bytes per frame. Neglect packets.
network overhead. Assume that IP overhead per (a) 200 (b) 220
packet is 20 bytes. What is the total overhead in (c) 240 (d) 260
the second network transmission? [2004] Solution: (d)
(a) 40 bytes (b) 80 bytes
(c) 120 bytes (d) 160 bytes Datagram size = 180 + 20 = 200.
Solution: (c) (Msg + TCP header)
Maximum payload in first network = 1200 IP header = 20 bytes.
Hence, possible fragments are So, fragment in Network B are
1. 1200 + 20 20 + 80, 20 + 80, 20 + 40.
2. 900 + 20 So, overall bytes received at Network C = 260
Possible fragment in second network. bytes.
1200 + 20 fragment becomes 400 + 20, 400 + 20, Hence, the correct option is (d)
400 + 20. 18. What is the rate at which application data is trans-
900 + 20 fragment becomes 400 + 20, 400 + 20, ferred to Host HC? Ignore errors, acknowledge-
100 + 20. ment and other overheads.
Total fragments in second frame work = 6. (a) 325.5 Kpbs (b) 354.5 Kpbs
(c) 409.6 Kbps (d) 512 Kbps
Hence, IP overload in second network = 120 bytes.
Solution: (b)
Hence, the correct option is (c)
Effective data transfer from network B to Network
Common Data for Questions 17 and 18 C = 180 bytes.
Consider three IP Network A, B and C. Host HA Hence, effective Efficiency = (180/260) × 512
in Network A sends messages each containing 180 Kbps
bytes of application data to a host HC in network
C. The TCP layer prefixes a 20 bytes header to the = 354.46 Kbps
message. This passage through an intermediate Hence, the correct option is (b)
Network B. The maximum packet size, including
20 bytes IP header, in each network is

Gate_CSE_Unit4_Computer Networks.indb 15 11/19/2015 6:59:55 PM


4.16 | Computer Networks

19. The routing table of a router is shown below: Solution: (d)


Destination Subnet Mask Interface Given subnet mask is for class B network. IP
128.75.43.0 255.255.255.0 Eth0 address in option(d) belongs to same network and
class B.
128.75.43.0 255.255.255.128 Eth1
Hence, the correct option is (d)
192.12.17.5 255.255.255.255 Eth3
21. Suppose that the maximum transmit window size
Default Eth2
for a TCP connection is 1200 bytes. Each packet
On which interfaces will the router forward pack- consists of 2000 bytes. At some point of time,
ets addressed to destinations 128.75.43.16 and the connection is in slow start phase with a cur-
192.12.17.10 respectively? [2004] rent transmit window of 4000 bytes. Subsequently,
(a) Eth1 and Eth2 (b) Eth0 and Eth2 the transmitter receives two acknowledgements.
(c) Eth0 and Eth3 (d) Eth1 and Eth3 Assume that no packets are lost and there are no
Solution: (a) time outs. What is the maximum possible value of
General routing process is to perform AND opera- the current transmit window? [2004]
tion between incoming IP address and subnet mask (a) 4000 bytes (b) 8000 bytes
and compare result with destination. If there is a (c) 10000 bytes (d) 12000 bytes
match, route the packet through that interface. Solution: (d)
If there is a match with multiple subnet masks, Congestion window size increases exponentially
choose longest length. in slow start phase. Current window size is 4000
128.75.43.16 bytes means it has two packets. It becomes 4 pack-
AND ets on getting first acknowledgement and 8 on get-
ting second acknowledgement. Therefore, size of
255.255.255.0
transmit window is 8 × 2000 = 16000 bytes.
128.75.43.0
But maximum transmit window is 1200 bytes.
128.75.43.16 Hence, congestion cannot grow beyond transmit
AND window.
255.255.255.128 Therefore, answer is 1200 bytes.
128.75.43.0 Hence, the correct option is (d)
Since it matches with both the entries, choose the 22. In a packet switching network, packets are routed
longest length subnet mask, hence, this packet is from source to destination along a single path hav-
forwarded through Eth1. ing two intermediate nodes. If the message size is
192.12.17.10 24 bytes and each packets contains a header of 3
bytes, then the optimum packet size is:
does not match with any destination even after
(a) 4 (b) 6
performing AND operations with subnet masks,
(c) 7 (d) 9
hence, packet is forwarded through Eth2.
Solution: (d)
Hence, the correct option is (a)
If optimum packet size is 9, then data 9 - 3 = 6
20. The subnet mask for a particular network
bytes, hence, we need only 4 packets carry 24
255.255.31.0. Which of the following pairs of IP
bytes. In option (a), (b), (c) number of packets
addresses could belong to this network. [2003]
transmitted would be more, and hence, network
(a) 172.57.88.62 and 172.56.87.233
traffic is more.
(b) 10.35.28.2 and 10.35.29.4
(c) 191.203.31.87 and 191.234.31.88 Hence, the correct option is (d)
(d) 128.8.129.43 and 128.8.161.55

Gate_CSE_Unit4_Computer Networks.indb 16 11/19/2015 6:59:56 PM


Chapter 4
Application Layer and
Routing Algorithm
(a) RIP uses distance vector routing protocol ;
One-mark Questions OSPF uses link state routing.
(b) OSPF uses distance vector routing ; RIP uses
1. Consider the following three statements about link link state routing.
state and distance vector routing protocols, for a (c) Both RIP and OSPF uses link state routing.
large network with network nodes and 4000 links. (d) Both RIP and OSPF use distance vector routing
 [2014]
Solution: (a)
[S1] The computational overhead in link protocols
is higher than in distance via protocol. RIP is based on hop count so it uses distance
vetor, OSPF is based on cost, hence uses link
[S2]  A distance vector protocol (with horizon) state.
avoids persistent routing but not link state
protocol. Hence, the correct option is (a)
[S3] After a topology change, a link protocol will 3. Assume that source S and destination D are con-
converge faster the distance vector protocol. nected through two intermediate routers labeled
R. Determine how many times each packet has to
Which one of the following is correct about S1, S2 visit the network layer and the data link layer dur-
and S3? ing a transmission from S to D
(a) S1, S2 and S3 are all true
(b) S1, S2 and S3 are all false S---R-----R---S [2013]
(c) S1, S2 are true, but S3 is false (a) Network layer-4 times and Data Link layer-4
(d) S1, S3 are true, but S2 is false times
(b) Network layer-4 times and Data Link layer-3
Solution: (d) times
Distance vector is a slower convergence as it sends (c) Network layer-4 times and Data Link layer-6
periodic update every 30 to 60 seconds. times
Ex-RIP, IGRE, BGP (d) Network layer-2 times and Data Link layer-6
In link state, update are not periodic so it has fast times
convergence. Solution: (c)
Ex- OSPF Hence, the correct option is (c)
Hence, the correct option is (d) 4. Consider different activities related to email:
2. Which one of the following is TRUE about Interior m1: Send an email from a mail client to a mail
Gateway Routing Protocol (IGRP)-Routing server.
Information Protocol (RIP) and Open Shortest m2: Download an email from mailbox server to a
Path First (OSPF) [2014] mail client.

Gate_CSE_Unit4_Computer Networks.indb 17 11/19/2015 6:59:56 PM


4.18 | Computer Networks

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.

Gate_CSE_Unit4_Computer Networks.indb 18 11/19/2015 6:59:56 PM


Chapter 4  Application Layer and Routing Algorithm  |  4.19

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]

Gate_CSE_Unit4_Computer Networks.indb 19 11/19/2015 6:59:56 PM


4.20 | Computer Networks

(a) 1.6 seconds (b) 2 seconds B1


(c) 5 seconds (d) 8 seconds 1 2
H1 H2 H3 H4
Solution: (b)
S = C/M - ρ where C = 16Mbits
2 3
M = 10Mbps, ρ = 2Mbps 4
B5 B3
S = 16/10 - 2 = 16/8 = 2 sec. 3
1 4
Hence, the correct option is (b) 1 2

8. Match the following : [2007]


P. SMTP 1. Application Layer H5 H6 H7 H8

Q. BGP 2.Transport Layer


2 1
R. TCP 3. Data Link Layer 1
2
S. PPP 4. Network Layer B4 B2
3 3
5. Physical Layer
(a) P-2, Q-1, R-3, S-5 H9 H10 H11 H12
(b) P-1, Q-4, R-2, S-3
(c) P-1, Q-4, R-2, S-5
[2006]
(d) P-2, Q-4, R-1, S-5
9. For the given connections of LANs by bridges,
Solution: (b)
which one of the following choices represents the
Hence, the correct option is (b) depth first traversal of the spanning tree of bridges?
Comman Data for Questions 09 and 010: (a) B1, B5, B3, B4, B2
Consider the diagram shown below where a (b) B1, B3, B5, B2, B4
number of LANs are connected by (transparent) (c) B1, B5, B2, B3, B4
bridges. In order to avoid packets looping through (d) B1, B3, B4, B5, B2
circuits in the graph, the bridge organize them- Solution: (c)
selves in a spanning tree. First, the root bridge is In spanning tree, every bridge lies in the tree but
identified as the bridge with the least serial num- no cycles or loops are formed. Hence, answer is
ber. Next the roots sends out (one or more) data B1, B5, B2, B3, B4.
units to enable the setting up of the spanning tree
Hence, the correct option is (c)
of the shortest paths from the root bridge to each
bridge. 10. Consider the correct spanning tree for the previous
question. Let host H1 sends out a broadcast ping
Each bridge identifies a port (the root port) through
packet. Which of the following options represents
which it will forward frames to the root bridge.
the correct forwarding table on B3?
Port conflicts are always reSolutionved in favour
(a) Hosts Port
of the port with the lower index value. Where there
is a possibility of multiple bridge forwarding to the H1, H2, H3, H4 3
same LAN (but not through the root port ), ties are H5, H6, H9, H10 2
broken as follows: bridges closest to the root gets H7, H8, H11, H12 2
preference and between such bridges, the one with (b) Hosts Port
the lowest serial number is preferred.
H1, H2 4
H3, H4, 3
H5, H6, 1
H9, H10, H7, H8, H11, H12 2

Gate_CSE_Unit4_Computer Networks.indb 20 11/19/2015 6:59:56 PM


Chapter 4  Application Layer and Routing Algorithm  |  4.21

(c) Hosts Port Solution: (a)


H3, H4 3 Forwarding packets to H1, H2 through port 4 and
H5, H6, H9, H10 1 H3, H4 through port 3 forms loop. Hence H1, H2.
H1, H2 4 H3, H4 it should be 3, H5, H6, H9, H10; it should
be 1, H7, H8, H11, H12; it should be 2.
H7, H8, H11, H12 2
(d) Hosts Port Hence, the correct option is (a)
H1, H2, H3, H4 3
H5, H7, H9, H10 1
H7, H8, H11, H12 4

Gate_CSE_Unit4_Computer Networks.indb 21 11/19/2015 6:59:56 PM


This page is intentionally left blank.

Gate_CSE_Unit4_Computer Networks.indb 22 11/19/2015 6:59:56 PM


UNIT V
OPERATING SYSTEM

Chapter 1: Process Management-I 5.3


Chapter 2: Process Management-II 5.13
Chapter 3: Deadlock 5.28
Chapter 4: Memory Management 5.33
Chapter 5: File System and Device Management 5.46

Gate_CSE_Unit5_Operating systems .indb 1 11/19/2015 6:53:59 PM


Gate_CSE_Unit5_Operating systems .indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 1 0 0 4 4 7 8 3 1 9 4 2 5 2 1 3 1 4 3 3 2 2 4
2 Marks Ques. 2 1 2 8 4 3 7 2 5 4 2 4 3 2 3 4 6 2 3 5 6 6 6 2 2 4 4 9
5 Marks Ques. 1 0 2 2 1 1 2 2 2 3 0 2 2 1 3 3 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 9 2 14 26 13 12 24 14 24 27 11 26 19 10 30 27 14 9 8 11 15 13 16 7 7 10 10 22

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.

Gate_CSE_Unit5_Operating systems .indb 3 11/19/2015 6:53:59 PM


5.4 | Operating System

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.

Gate_CSE_Unit5_Operating systems .indb 4 11/19/2015 6:53:59 PM


Chapter 1  Process Management-I  |  5.5

Solution: (d) (b) TRUE. It is drawback of user-level threads.


Kernel threads do not get blocked for I/O or (c) TRUE. Kernel-supported threads having own
system-level call when one thread blocks. Blocking memory area and schedules independently by
one thread will not block all the related threads, in the OS.
kernel-level threads. (d) FALSE. As kernel is not aware to user-level
(a)  TRUE. Context switch time is longer for threads and there is no kernel support to user-
kernel-level threads. level thread.
(b) TRUE. User-level thread do not need hardware Hance the correct option is (a)
support. 12. Which of the following scheduling algorithms is
(c)  TRUE. As threads supports multi-processor non-pre-emptive? [2002]
architecture, related kernel-level threads can (a) Round robin
be scheduled on different processors in a (b) First-in-first-out
multi-process system. (c) Multilevel queue scheduling
Hance the correct option is (d) (d) Multilevel queue scheduling with feedback
10. Consider three CPU-sensitive processes which Solution: (b)
require 10, 20 and 30 time units and arrive at In FIFO, pre-emption takes place only after the
times 0, 2 and 6 respectively. How many context completion of a process.
switches are needed if the operating system imple-
Hance the correct option is (b)
ments the shortest remaining time first scheduling
algorithm? Do not count the context switches at 13. A processor needs software interrupt to [2001]
time zero and at the end. [2006] (a) test the interrupt system of the processor
(a) 1 (b) 2 (b) implement co-routines
(c) 3 (d) 4 (c) obtain system services which need execution
of privileged instructions
Solution:(b)
(d) return from subroutine
Solution: (c)
Hance the correct option is (c)
P1 P2 P3
14. A CPU has two modes-privileged and non-privi-
0 10 30 60 leged. In order to change the mode from privileged
to non-privileged [2001]
There are 4 context switching out of which 2 are (a) a hardware interrupt is needed
removed. (b) a software interrupt is needed
Hance the correct option is (b) (c) a privileged instruction (which does not gener-
ate an interrupt) is needed
11. Consider the following statements with respect to
(d) a non-privileged instruction (which does not
user-level thread and kernel supported threads?
generate an interrupt) is needed
[2004]
Solution: (c)
(a) Context switching is faster with the kernel-
supported thread. Hance the correct option is (c)
(b) For user-level threads, a system call can block 15. Consider a set of n tasks with known runtimes r1, r2
the entire process. ….., rn to be run on a uniprocessor machine. Which
(c)  Kernel-supported threads can be scheduled of the following processor scheduling algorithm
independently . will result in the maximum throughput? [2001]
(d)  User-level threads are transparent to the (a) Round robin
kernel. (b) Shortest-job-first
Solution: (a) (c) First-in first-out
(a) FALSE. There is no connection between con- (d) First-come-first serve
text switch and kernel-supported threads.

Gate_CSE_Unit5_Operating systems .indb 5 11/19/2015 6:53:59 PM


5.6 | Operating System

Solution: (b) will be reduced when time quantum is maximum


Total number of jobs executed in per unit time is allowable, i.e, q = t - ns / (n - 1).
maximum in SJF. Hance the correct option is (b)
Hance the correct option is (b) 19. The process state transition diagram in figure is
16. System calls are usually evoked by using [1999] representative of [1996]
(a) a software interrupt
TERMINAT
(b) polling
NE
(c) an indirect jump
(d) a privileged instruction
Solution: (a)
RUNNING READ
System calls, state changes can be caused by pro-
gram commands, which are referred to as system
calls and are implemented using software interrupt
or automatically following certain events. BLOCKED
Hance the correct option is (a)
17. Which of the following is an example of spooled (a) a batch operating system
device? [1998] (b)  an operating system with a preemptive
(a) The terminal used to enter input data for the C scheduler
program being executed (c) an operating system with a non-preemptive
(b) An output device used to print the output of a scheduler
number of jobs (d) a uni-programmed operating system
(c)  The secondary memory device in a virtual Solution: (b)
storage system The process going from running to ready sate is
(d) The swapping area on a disk used by the swap- always preemptive.
per
Hance the correct option is (b)
Solution: (b)
20. Which of the following is an example of spooled
Hance the correct option is (b) device? [1996]
18. Consider n processes sharing the CPU in a round- (a) A line printer used to print the output of a
robin fashion. Assuming that each process which number of jobs.
takes s seconds, what must be the quantum size (b) A terminal used to enter input data to a run-
q such that the overhead resulting from process ning program.
switching is minimized but, at the same time, each (c) A secondary storage device in a virtual memo-
process is guaranteed to its turn at CPU at least ry system.
every second? [1998] (d) A graphic display device.
Solution: (b) Solution: (a)
Each process runs for q period and if there are n SPOOL (Simultaneous Peripheral Operation
process p1, p2, p3…pn, p1, p2…., then p1 turn Online). It says about the process in which data are
comes again when it has a complete time quanta put in temporary working area for anther program
for remaining process p2 to pn, i.e., it would take to process. Spooling allows one program to assign
at most(n-1) q times. So, each process in round work to another without directly communicating
robin gets its turn after < = (n - 1) q times when with it.
we don’t consider overhead but if we consider Hance the correct option is (a)
overhead(s) but if we consider overhead then it would
21. Which scheduling policy is most suitable for a
be ns + (n - 1) q. So, ns + (n - 1) q < = t, overhead
time-shared operating system? [1995]

Gate_CSE_Unit5_Operating systems .indb 6 11/19/2015 6:53:59 PM


Chapter 1  Process Management-I  |  5.7

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

Gate_CSE_Unit5_Operating systems .indb 7 11/19/2015 6:54:00 PM


5.8 | Operating System

5. Consider the following table of arrival time and Solution: (c)


burst time for three processes P0, P1 and P2. It is not necessary for a process to make a transition
Process Arrival time Burst Time ‘A’ immediately when running process completes.
P0 0 ms 9 ms Transition C indicate that OS uses pre-emptive
P1 1 ms 4 ms scheduling.
P2 2 ms 9 ms II is also TRUE.
Hance the correct option is (c)
The pre-emptive shortest job first scheduling
7. A process executes the following code
algorithm is used. Scheduling is carried out only
at arrival or completion of processes. What is the for (i = 0; i < n; i++) fork();
average waiting time for the three processes? The total number of child processes created is
[2011]  [2008]
(a) 5.0 ms (b) 4.33 ms (a) n (b) 2n − 1
(c) 6.33 ms (d) 7.33 ms (c) 2n (d) 2n + 1 − 1;
Solution: (a) Solution: (b)
By Gantt chart Total number of processes will be 2n out of which
one process will be original parent process.
P0 P1 P0 P2 ∴ total number of child process = 2n - 1.
0 1 5 13 22 Hance the correct option is (b)
WT for P0 = [5 - 1] - 0 = 4 8. which of the following is/are TRUE of the auto
increment addressing mode? [2008]
WT for P1 = [1 - 1] = 0 I. It is useful in creating self-relocating code.
WT for P2 = [13 - 2] = 11 II. If it is included in an instruction set Architec-
Average WT for = 4 + 0 + 11/3 = 15/3 = 5 ture, then an additional ALU is required for ef-
Hance the correct option is (a) fective address calculation.
III. The amount of increment depends on the size
6. In the following process state transition diagram of the data items accessed.
for a uniprocessor system, assume that there are (a) I only (b) II only
always some processes in the ready state: (2009) (c) III only (d) II & III only
B Solution: (c)
A D
Star Ready Running Terminated
Hance the correct option is (c)
t C
9. An operating system uses the Shortest Remaining
E F Time first (SRT) process scheduling algorithm.
Blocked Consider the arrival times and execution times for
the following processes:
Now consider the following statements: Process Execution time Arrival time
1. If a process makes a transition D, it would re- P1 20 0
sult in another process making transition A im-
P2 25 15
mediately.
2. A process P2 in blocked state can make transi- P3 10 30
tion E, while another process P1 is in running P4 15 45
state.
3. The OS uses pre-emptive scheduling What is the total waiting time for process P2?
4. The OS uses non-pre-emptive scheduling  [2007]
(a) 1 and 2 (b) 1 and 3 (a) 5 (b) 15
(c) 2 and 3 (d) 2 and 4 (c) 40 (d) 55

Gate_CSE_Unit5_Operating systems .indb 8 11/19/2015 6:54:00 PM


Chapter 1  Process Management-I  |  5.9

Solution: (b) Observe idle time of CPU,


Hance the correct option is (b) = 5/47 * 100
1 0. Consider three processes (process id 0, 1, 2 respec- = 10.6
tively) with compute time bursts 2, 4 and 8 time Hance the correct option is (b)
units. All processes arrive at time zero. Consider
1 2. Consider the following code fragment:
the Longest Remaining Time First (LRTF) sched-
uling algorithm. In LRTF, ties are broken by giving if (fork() = = 0)
priority to the process with the lowest process id. { a = a + 5; printf(“%d,%d\n”, a, & a); }
The average turnaround time is [2006] else { a = a – 5; printf(“%d,%d\n”, a, & a); }
(a) 13 units (b) 14 units
Let u, v be the values printed by the parent process,
(c) 15 units (d) 16 units
and x, y be the values printed by the child process.
Solution: (a) Which one of the following is TRUE? [2005]
P0 P1 P2 P1 P2 P0 P1 P2 P0 P1 P2 (a) u = x + 10 and v = y
0 4 5 6 7 8 9 10 11 12 13 14 (b) u = x + 10 and v ! = y
(c) u + 10 = x and v = y
Avg TAT = 12 + 13 + 14/3 = 13 (d) u + 10 = x and v ! = y
Hance the correct option is (a) Solution: (a)
1 1. Consider three processes, all arriving at time zero, Both parent and child processes will have different
with total execution time of 10, 20 and 30 units, variables with same name ‘a’.
respectively. Each process spends the first 20% of Hance the correct option is (a)
execution time doing I/O, the next 70% of time 13. Consider the following set of processes, with the
doing computation, and the last 10% of time doing arrival times and the CPU burst times given in
I/O again. The operating system uses the shortest milliseconds.
remaining compute time first scheduling algorithm
and schedules a new process either when the run- Process Arrival Time Burst Time
ning process gets blocked on I/O or when the run- P1 0 5
ning process finishes its compute burst. Assume
P2 1 3
that all I/O operations can be overlapped as much
P3 2 3
as possible. For what percentage of time does the
CPU remain idle? [2006] P4 4 1
(a) 0% (b) 10.6%
(c) 30.0% (d) 89.4% What is the average turnaround time for these pro-
cesses with the pre-emptive Shortest Remaining
Solution: (b)
Processing Time first (SROT) algorithm? [2004]
Gantt Chart (a) 5.50 (b) 5.75
(c) 6.00 (d) 6.25
Burst I/o CPU I/o
Process Solution: (a)
Time Time Time Time

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

Gate_CSE_Unit5_Operating systems .indb 9 11/19/2015 6:54:00 PM


5.10 | Operating System

Turn around time for P1 = 12 - 0 = 12 Solution:


Turn around time for P2 = 4 - 1 = 3
Suspend/Ready
Turn around time for P3 = 8 - 2 = 6
Turn around time for P4 = 5 - 4 = 1 Suspend Resume suspended
Average TAT = 12 + 3 + 6 + 1/4 = 5.50 Dispatch
creoted complete
Hance the correct option is (a) Ready Running Terminated
Now
1 4. A uni-processor computer system only has two
I/p complete event Priority
processes, both of which alternate 10ms CPU I/o
I/o completeion
bursts with 90ms I/O bursts. Both the processes
event
were created at nearly the same time. The I/O of Block/wait
both processes can proceed in parallel. Which of Set event
resume
the following scheduling strategies will result in suspend
the least CPU utilization (over a long period of
time) for this system ? [2003] Suspend block
(a) FCFS
(b) SJF 17. Which of the following does not interrupt a run-
(c) Static priority scheduling with different priori- ning process? [2001]
ties for the two processes. (a) A device (b) Timer
(d) RR scheduling with TS = 5ms. (c) Scheduler process (d) Power failure
Solution: (a) Solution: (c)
In FCFS, next job is not started unless current one Hence, the correct option is (c)
is finished. 18. A multi-user, multi-processing operating system
Hance the correct option is (a) cannot be implemented on hardware that does not
15. Which combination of the following features support [1999]
will suffice to characterize an OS as a multi- (a) Address translation
programmed OS? [2002] (b) DMA for disk transfer
(A) More than one program may be loaded into (c) At least two modes of CPU execution (privi-
main memory at the same time for execution. leged and non-privileged)
(B) If a program waits for certain events such as (d) Demand paging
I/O, another program is immediately sched- Solution: (a, b, c)
uled for execution. 19. Four jobs are waiting to be run. Their expected run-
(C) If the execution of a program terminates, an- times are 6, 3, 5 and x. In what order should they be
other program is immediately scheduled for run to minimize the average response time? [1998]
execution.
Solution: ()
(a) A (b) A and B
Run in the order
(c) A and C (d) A, B and C
x, 3, 5, 6, if x < 3
Solution: (a)
3, x, 5, 6, if x > 3 & x < 5
Hance the correct option is (a) 3, 5, x, 6, if x > 5 & x < 6
16. Draw the process state transition diagram of an OS 3, 5, 6, x, if x > 6
in which [2002] By applying SJF; as it generates the least any
(i) Each process is in one of the five states: create, waiting time.
ready, running, blocked( i.e., sleep or wait) or
terminated, and There are only two main choices FCFS and SJF
(ii) Only non-preemptive scheduling is used by the as no priority and quantum size has been given.
OS. It label the transitions appropriately. Moreover, x may take values 1, 2, 3, 4, 5 and
more than that. It is assumed that the job spounds

Gate_CSE_Unit5_Operating systems .indb 10 11/19/2015 6:54:00 PM


Chapter 1  Process Management-I  |  5.11

immediately after getting the CPU. Then the Solution: (a)


response time will be same as waiting time. SJF is optional non-pre-emptive CPU schedul-
SJF is considered as it produces minimum response ing algorithm. In order to produce the optimal
time. Solutionution here, it considers the SJF. The opti-
CASE 1 : x = 1 mal sequence is {j3, j2, j1}.
Average waiting time = (0 + 1 + 4 + 9)/4 = 14/4 = Since burst time(j3) < burst time(j2) < burst
3.5 time(j1), but to start j3, CPU should wait for 1.0
units of time as its interval time is 1.0.
x 3 5 6 Hance the correct option is (a)
22. The details of an interrupt cycle are shown in the
below figure.
CASE 2 : x = 2
Arrival of interrupt [1993]
This job will again be the first job to be executed.
10  sec
Average waiting time = (0 + 2 + 5 + 10)/4 = 17/4 = 4.25
CASE 3 : x = 3
This job will again be the first job to be executed.
Average waiting time = (0 + 3 + 6 + 11)/4 = 20/4 = Main program Main program
execution
5 10  sec 80  se 10  se execution
CASE 2 : x = 4
Saving of Restoration of
Average waiting time = (0 + 3 + 7 + 12)/4 = 22/4 = 5.5 CPU state
Interrupt Service
CPU State
Execution
And so on.
Thus , the order of execution depends on the value What is CPU doing?
of x and average response time is minimum x = 1. Solution:
20. Four jobs to be executed on a single-processor 90% of time CPU is busy executing main program.
system arrive at time 0 in the order A, B, C, D.
23. Assume that the following jobs are to be executed
Their burst CPU time requirements are 4, 1, 8, 1
on a single-processor system
time units, respectively. The completion time of A
under round robin scheduling with time slice of Job ID CPU-Burst Time
one time unit is [1996]
p 4
(a) 10 (b) 4
(c) 8 (d) 9 q 1
r 8
Solution: (d)
s 1
Hance the correct option is (d)
t 2
21. The sequence …………… is an optimal non-pre-
emptive scheduling sequence for the following jobs The jobs are assumed to have arrived at time 0 and
which leaves the CPU idle for ………………… in the order p, q, r, s, t. Calculate the departure
unit(s) of time. [1995] time (completion time) for job p if scheduling is
Job Arrival Time Burst Time
round robin with time slice 1. [1993]
(a) 4 (b) 10
1 0.0 9
(c) 11 (d) 12
2 0.6 5
Solution: (c)
3 1.0 1
Apply RR scheduling with ts = 1.
(a) {3,2,1},1 (b) {2,1,3},0 Gantt Chart,
(c) {3,2,1},0 (d) {1,2,3},5

Gate_CSE_Unit5_Operating systems .indb 11 11/19/2015 6:54:00 PM


5.12 | Operating System

0 1 2 3 4 5 6 7 8 9 10 11 12 25. The highest-response ratio next scheduling policy


P Q R S T P R T P R P R favours……….jobs, but it also limits the waiting
time of…….jobs. [1990]
Turnaround time = 11. Solution: (Shorter, Longer)
Hance the correct option is (c) By applying RR-scheduling with time ts = 1,
2 4. Which of the following is an example of a spooled Gantt Chart,
device? [1992]
(a) The terminal used to the input data for a pro- A B C D A C A C A C
gram being executed. 0 1 2 3 4 5 6 7 8 9 10
(b)  The secondary memory device in virtual
memory system. Turn-around time = 9
(c) A line printer used to print the output of a 2 6. State an undesirable characteristics of each of the
number of jobs. following criteria for measuring performance of an
(d) None of the above. operating system: [1988]
Solution: (c) (a) Turnaround time (b) Waiting time
Simultaneous Peripheral Operation Online (SPOOL) Solution:
says about the process in which data are put in tem- The CPU efficiency/input decreases as the
porary working area for another program to process. turn- around time /waiting time of the processor
Spooling allows one program to assign work to increases. It is desirable to have less turn-around
another without directly communicating with it. time/waiting time for all processes.
Hance the correct option is (c)

Gate_CSE_Unit5_Operating systems .indb 12 11/19/2015 6:54:01 PM


Chapter 2
Process Management-II
2. Consider the methods used by processes P1 and
One-mark Questions P2 for accessing their critical sections when-
ever needed, as given below. The initial values of
1. Three concurrent processes X, Y and Z execute shared boolean variables S1 and S2 are randomly
three different code segments that access and assigned.
update certain shared variables. Process X exe-
cutes the P operation (i.e., wait) on semaphores Method Used by Method Used by
a, b and c; process Y executes the operation P on P1 P2
semaphores b, c, d; process Z execute the opera- while (S1 = S2) ; while (S1 ! = S2) ;
tion P on c, d and a before entering the respective Critica1 Section Critica1 Section
code segment, each process invokes the V opera- S1 = S2; S2 = not (S1);
tion (i.e., signal) on its three semaphores. All sem-
aphores are binary semaphores initialized to 1. Which one of the following statements describes
Which of the following represents a deadlock-free the properties achieved? [2010]
order of invoking the P operations by the pro- (a) Mutual exclusion but not progress
cesses? [2013] (b) Progress but not mutual exclusion
(a) X: P(a) P(b) P(c) (c) Neither mutual exclusion nor progress
Y: P(b) P(c) P(d) (d) Both mutual exclusion and progress
Z: P(c) P(d) P(a) Solution: (a)
(b) X: P(b) P(a) P(c) Hence, the correct option is (a).
Y: P(b) P(c) P(d)
3. Which of the following scheduling algorithm is
Z: P(a) P(c) P(d)
non-pre-emptive? [2002]
(c) X: P(b) P(a) P(c)
(a) Round robin
Y: P(c) P(b) P(d)
(b) FIFO
Z: P(a) P(c) P(d)
(c) Multi-level queue scheduling
(d) X: P(a) P(b) P(c)
(d) Multi-level queue scheduling with feedback
Y: P(c) P(b) P(d)
Solution: (b)
Z: P(c) P(d) P(a)
Hence, the correct option is (b).
Solution: (b)
4. Suppose a processor does not have any stack
All processes do not have reverse call for wait on pointer register. Which of the following statement
any variable. is TRUE? [2001]
Hence, the correct option is (b). (a) It cannot have subroutine call instruction.
(b) It can have subroutine call instruction, but no
nested subroutine calls.

Gate_CSE_Unit5_Operating systems .indb 13 11/19/2015 6:54:01 PM


5.14 | Operating System

(c) Nested subroutine calls are possible, but inter- 6P = > S = S - 6 = 4


rupts are not . 4V = > S = S + 4 = 8
(d) All sequences of subroutine call and also in-
Hence, the correct option is (b).
terrupt are possible.
9. A critical section is a program segment [1996]
Solution: (b)
(a) which should run in a certain specified amount
Hence, the correct option is (b). of time.
5. Where does the swap space reside? [2001] (b) which avoids deadlocks.
(a) RAM (b) Disk (c) where shared resources are accessed.
(c) ROM (d) On-chip cache (d) which must be enclosed by a pair of sema-
Solution: (b) phore operations, P and V.
Hence, the correct option is (b). Solution: (c)
6. Let m[0]…m[4] be mutexes (binary semaphores) Critical section implies usage of shared resources.
and P[0] …. P[4] be processes. Hence, the correct option is (c).
Suppose each process P[i] executes the following:
wait (m[i]);wait (m[(i + 1) mode 4]); Two-marks Questions
release (m[i]); release (m[(i + 1)mod 4]);
This could cause [2000] 1. A certain computation generates two arrays 'a' and
(a) Thrashing 'b' such that a[i] = f(i) for 0 ≤ i < n and b[i] = g (a[i])
(b) Deadlock for 0 ≤ i < n. Suppose this computation is decom-
(c) Starvation, but not deadlock posed into two concurrent processes X and Y such
(d) None of the above that X computes the array 'a' and Y computes the
array 'b'. The processes employ two binary sema-
Solution: (b)
phores R and S, both initialized to zero. The array
If each process gets pre-empted after wait (m[i]); 'a' is shared by the two processes. The structures of
i = 0 to 4, then deadlock occurs. the processes are shown below.
Hence, the correct option is (b) Process X: Process Y:
7. When the result of a computation depends on the private i; private i;
speed of the processes involved there is said to be
for (i=0; i<n; i++) {
[1998] for (i=0; i<n; i++ { a[i] = f(i);
(a) Cycle stealing (b) Race condition EntryY(R, S);
(c) A time lock (d) A deadlock
ExitX(R, S); b[i] = g(a[i]);
Solution: (b)
} }
Problems of synchronization is lead by race
Which one of the following represents the CORRECT
condition.
implementations of Exit X and Entry Y? [2013]
Hence, the correct option is (b). (A) ExitX(R,S) { (B) ExitX(R, S) {
8. A counting semaphore was initialized to 10. Then P(R); V(R);
6 P (wait) operations and 4V (signal) operations
V(S); V(S);
were completed on this semaphore. The resulting
value of the semaphore is [1998] } }
(a) 0 (b) 8 EntryY(R, S) { EntryY(R, S) {
(c) 10 (d) 12 P(S); P(R);
Solution: (b) V(R); P(S);
Since semaphore value S = 10 } }

Gate_CSE_Unit5_Operating systems .indb 14 11/19/2015 6:54:01 PM


Chapter 2  Process Management-II  |  5.15

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

Gate_CSE_Unit5_Operating systems .indb 15 11/19/2015 6:54:01 PM


5.16 | Operating System

This implementation In the above Solution, X is a memory location


(a) fails as L can overflow. associated with the CS and is initialized to 0. Now
(b) fails as L can take on a non-zero value when consider the following statements:
the lock is actually available. I. The above Solution to CS problem is dead-
(c) works correctly but may starve some lock-free.
processes. II. The Solutionution is starvation free.
(d) works correctly without starvation. III. The processes enter CS in FIFO order.
Solution: (d) IV. More than one process can enter CS at the
same time.
Fetch_And_Add () is atomic, theretofore, even if
pre-emption takes place within the while loop, the Which of the above statements is TRUE? [2009]
outer process will be denied to access to CS. (a) I only (b) I and II
(c) II and III (d) IV only
Hence, the correct option is (d).
Solution: (b)
4. The following program consists of 3 concurrent
processes and 3 binary semaphores. The sema- The Solution is not starvation free; processes need
phores are initialized as S0=1, S1=0, S2=0. not follow FIFO order; it guarantees mutual exclu-
sion because test-and-set is atomic instruction.
Process P0 Process P1 Process P2
Hence, the correct option is (b).
while (true) { wait (S1); wait (S2);
6. The P and V operations on counting semaphores,
wait (S0); Release (S0); release (S0);
where s is a counting semaphore, are defined as
print (0); follows;
release (S1); P(s): S=S-1;
release (S2); If s<0 then wait;
} V(s) : s=s+1;
How many times will process P0 print '0'? [2010] If s<=0 then wake up a processes waiting on S;
(a) At least twice (b) Exactly twice Assume that the Pv and Vb the wait and signal
(c) Exactly thrice (d) Exactly once operations on binary semaphores are provided.
Solution: (a) Two binary semaphore Xb and Yb are used to imple-
Since S0=1, and there are two processes that ment the semaphore operations P(s) and V(s) as
are performing release (S0). The minimum num- follows:
ber of times the message is get printed is 2 and P(s) :Pb (Xb);
maximum 3.   S=s-1;
Hence, the correct option is (a).   If(s<0){
5. The enter_CS() and leave_CS() functions to imple-   Vb( Xb);
ment critical section of a process are realized using Pb (Yb);
test-and-set instruction as follows:
}
void enter_CS(X)
Else Vb (Xb);
{
V(s) : Pb (Xb)
while test-and-set(X) ;
S=s+1;
}
If(s<=0) Vb(Yb);
void leave_CS(X)
Vb(Xb);
{
The initial values of Xb and Yb are, respectively
X = 0;  [2008]
} (a) 0 and 0 (b) 0 and 1
(c) 1 and 0 (d) 1 and 1

Gate_CSE_Unit5_Operating systems .indb 16 11/19/2015 6:54:01 PM


Chapter 2  Process Management-II  |  5.17

Solution: (c) 6: process_left++;


Hence, the correct option is (c). 7: if (process_left==3) {
7. P1 and P2 need to access a critical section of code. 8: process_arrived = 0;
Consider the following synchronization construct 9: process_left = 0;
used by the processes: [2007]
10: }
/* P1 */ /* P2 */
11: V(S);
while (true) { while (true) {
}
wants1 = true;   wants2 = true;
while (wants2  while(wants1==true); The variables process_arrived and process_left are
== true); /* Critical
shared among all processes and are initialized to
/* Critical zero. In a concurrent program, all the three pro-
Section */
Section */ cesses call the barrier function when they need to
wants2 = false;
wants1=false; synchronize globally.
}
} /* Remainder section*/ 8. The above implementation of barrier is incorrect.
/*Remainder Which one of the following is TRUE?
section*/ (a) The barrier implementation is wrong due to
the use of binary semaphore S.
Here, wants1 and wants2 are shared variables, (b)  The barrier implementation may lead to a
which are initialized to false. Which one of the deadlock if two barrier in invocations are used
following statements is TRUE about the above in immediate succession.
construct? (c) Lines 6 to 10 need not be inside a critical
(a) It does not ensure mutual exclusion. section
(b) It does not ensure bounded waiting. (d) The barrier implementation is correct if there
(c) It requires that processes enter the critical sec- are only two processes instead of three.
tion in strict alternation. Solution: (b)
(d) It does not prevent deadlocks, but ensures mu-
Hence, the correct option is (b).
tual exclusion.
9. Which one of the following rectifies the problem
Solution: (d)
in the implementation?
Hence, the correct option is (d). (a) Lines 6 to 10 are simply replaced by process_
Common Data for Questions 8 and 9 arrived.
Barrier is a synchronization construct where a set (b) At the beginning of the barrier, the first pro-
of processes synchronizes globally, i.e., each pro- cess to enter the barrier waits until process_ar-
cess in the set arrives at the barrier and waits for rived becomes zero before proceeding to ex-
all others to arrive and then all processes leave the ecute P(S).
barrier. Let the number of processes in the set be (c) Context switch is disabled at the beginning of
three and S be a binary semaphore with the usual P the barrier and re-enabled at the end.
and V functions. Consider the following C imple- (d) The variable process_left is made private in-
mentation of a barrier with line numbers shown on stead of shared.
left.[2006] Solution: (b)
void barrier (void) { Hence, the correct option is (b).
1: P(S); 10. The atomic fetch-and-set x, y instruction uncon-
2: process_arrived++; ditionally sets the memory location x to 1 and
fetches the old value of x in y without allowing
3: V(S);
any intervening access to the memory location x.
4: while (process_arrived !=3); consider the following implementation of P and V
5: P(S); functions on a binary semaphore  [2006]

Gate_CSE_Unit5_Operating systems .indb 17 11/19/2015 6:54:01 PM


5.18 | Operating System

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

Gate_CSE_Unit5_Operating systems .indb 18 11/19/2015 6:54:01 PM


Chapter 2  Process Management-II  |  5.19

14. Each process Pi, i=1…..9 L4: S4


Repeat Goto L2
P(mutex) Next:
{ Solution: (c)
Critical section
S1 S2 S4
}
V(mutex)
Forever
The code for P10 is identical except that it uses S3 S5
V(mutex) in place of P(mutex). What is the largest
number of process that can be inside the critical
section at any moment? [1997] Hence, the correct option is (c).
(a) 1 1 6. A Solution to the Dining Philosophers Problem
(b) 2 which avoids deadlock is [1996]
(c) 3 (a) ensure that all philosophers pick up the left
(d) None of the above fork before the right fork .
Solution: (d) (b) ensure that all philosophers pick up the right
Maximum is 10 processes, as P10 can execute fork before the left fork.
infinitely. (c) ensure that one particular philosopher picks up
the left fork before the right fork, and that all
Hence, the correct option is (d).
other philosophers pick up the right fork be-
15. The concurrent programming construct fork and fore the left fork.
join are as below: [1996] (d) None of the above.
Fork<label> which creates a new process execut- Solution: (c)
ing from the specified label join <variable> which
Hence, the correct option is (c).
decrements the specified synchronization variable
(by 1) and terminates the process if new value is 17. At a particular time of computation, the value of a
not 0. counting semaphore is 7. Then 20P operations and
15V operation were completed on this semaphore.
Show the precedence graph for S1, S2, S3, S4 and
The resulting value of the semaphore is [1992]
S5 of the concurrent program below.
(a) 42 (b) 2
N=2 (c) 7 (d) 12
M=2 Solution: (b)
Fork L3 Semaphore value S=7.
Fork L4 P operation will decrement the value of the sema-
S1 phore by 1.
L1: join N V operation will increment the value of the sema-
S3 phore by 1.
L2: join M 20P operations = > S = S - 20 = 7 - 20 = - 13
S5 15V operations = > S = S + 15 = - 13 + 15 = 2
L3: S2 Hence, the correct option is (b)
goto L1

Gate_CSE_Unit5_Operating systems .indb 19 11/19/2015 6:54:01 PM


5.20 | Operating System

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

Gate_CSE_Unit5_Operating systems .indb 20 11/19/2015 6:54:01 PM


Chapter 2  Process Management-II  |  5.21

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

Gate_CSE_Unit5_Operating systems .indb 21 11/19/2015 6:54:02 PM


5.22 | Operating System

consumer_item(item); Q1: While (R2 is busy) do-no-op;


down(full); Q2: Set R2 ← busy
} Q3: While (R1 is busy) do-no-op;
down(mutex); Q4: Ser R1 ← busy;
item=buffer(out); Q5: Use R1 and R2;
out=(out+1) mod n; Q6: Set R2 ← free;
up(mutex); Q7. Set R1 ← free;
producer_item(items); (a) Is mutual exclusion guaranteed for R1 and
R2? If not, show a possible interleaving of the
}
statements of P1 and P2 such that mutual ex-
} clusion is violated (i.e, both P1 and P2 use R1
void producer(void) and R2 at the same time)
{ (b) Can a deadlock occur in the above program? if
yes, show a possible interleaving of the state-
down(empty);
ments of P1 and P2 leading to deadlock.
down(mutex); (c) Exchange the statements Q1 and Q3 and state-
up(mutex); ment Q2 and Q4. Is mutual exclusion guaran-
up(full); teed now? Can deadlock occur? [2001]
} Solution:
(a) Mutual exclusion is guaranteed.
void consumer (void)
(b) Deadlock occurs; allow both processes to get
{ pre-empted after S2 and Q2, respectively.
down(full); (c)  Now mutual exclusion is not guaranteed;
down(mutex); deadlock is not possible as both the processes
would be executing the same code.
up(mutex);
4. (a) Fill in the boxes below to get the solution for
up(empty);
the readers writers problem, using a single
} binary semaphores, mutex, (initialized to 1)
Process ‘Q’ has to wait until ‘P’ starts, therefore, and busy waiting. Write the box numbers (1,
the value of semaphore in process ‘Q’ must be 2, 3) and their contents in your Solution book.
zero.  [2000]
3. Two concurrent processes P1 and P2 want to use int R=0,W=0
two resources R1 and R2 in a mutually manner. Reader()
Initially, R1 and R2 are free. The program executed
{ L1: wait(mutex);
by the two processes are given below.
If (W==0){
Program for P1:
R=R+1;
S1: While (R1 is busy) do-no-op;
********
S2: Set R1←busy;
}
S3: While (R2 is busy ) do-no-op;
else{
S4: Set R2 ← busy;
********
S5: Use R1 and R2;
Goto L1;
S6: Set R1 ← free;
}
S7: Set R2 ← free;
………/* read this*/
Program for P2:
wait(mutex);

Gate_CSE_Unit5_Operating systems .indb 22 11/19/2015 6:54:02 PM


Chapter 2  Process Management-II  |  5.23

R=R-1; if count=0 then sleep;


signal(mutex); remove item from buffer;
} count=0
Writer(){ Wakeup(Producer);
L2: wait(mutex); Consume item;
if (**********){ forever;
signal (mutex); Show that in this Solutionution, it is possible that
GOTO L2; both the processers are sleeping at the same time.
 [1999]
}
Solution:
W=1;
(a) volatile int lock=0;
Signal(mutex):
void Critical()
……../* do the write*/
{
Wait(mutex);
while(TestAndSet(& lock)==1)
W=0:
critical section;
Signal(mutex);
lock=0
}
}
(b) Can the above solution lead to starvation of
(b)  There is a possibility of deadlock between
writers?
producer and customer. It happens in the case
Solution: when the buffer is empty and consumer starts
The first and second blank must be signal (mutex); first, gets pre-empted after testing the condi-
The third blank is if (R>=1 or W=1) tion if (count=ϕ) and before executing sleep();
5. (a) A certain processor provides a ‘test and set’ 6. Consider the following program segment for con-
instruction that is used as follows: current processing using semaphore operations P
and V for synchronization. Draw the precedence
TEST register, flag
graph for the statements S1 to S9. [1995]
This instruction automatically copies flag to regis-
var
ter and sets flag to 1. Give pseudo code for imple-
menting the entry and exit code to a critical region a, b, c, d, e, f, g, h, I, j, k:
using this instruction. semaphores;
(b) Consider the following Solutionution to the begin
producer  consumer problem using a buffer cobegin
of size1. Assume that the initial value of count
begin S1;V(a); V(b) end;
is 0. Also assume that the testing of count and
assignment to count are atomic operation. begin P(a); S2: V(c);V(d) end;
producer. begin P(c); S2: V(e) end;
repeat begin P(d); S5: V(f) end;
Produce an item begin P(e);P(f); S7: V(k) end;
if count=1; begin P(b); S3: V(g);V(h) end;
wakeup (consumer); begin P(g); S6: V(i) end;
forever; begin P(h);P(i): S8: V(i) end;
Consumer. begin P(j);P(k); S9 end;
repeat coend
end;

Gate_CSE_Unit5_Operating systems .indb 23 11/19/2015 6:54:02 PM


5.24 | Operating System

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

7. Write a concurrent program using par begin to rep-


resent the precedence graph shown below. [1998] S3
Solution:

S1 S4 S6

S5
S2 S3

(b) No, if this graph is implemented with parbe-


gin-parend, then binary semaphores has to be
issued.
S4 9. Write a concurrent program using parbegin-parend
and semaphores to represent the precedence con-
straints of the statement S1 to S6 as shown in the
S5
figure. [1993]

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

Gate_CSE_Unit5_Operating systems .indb 24 11/19/2015 6:54:02 PM


Chapter 2  Process Management-II  |  5.25

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]

Gate_CSE_Unit5_Operating systems .indb 25 11/19/2015 6:54:02 PM


5.26 | Operating System

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

Gate_CSE_Unit5_Operating systems .indb 26 11/19/2015 6:54:02 PM


Chapter 2  Process Management-II  |  5.27

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

Gate_CSE_Unit5_Operating systems .indb 27 11/19/2015 6:54:02 PM


Chapter 3
Deadlock

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

Gate_CSE_Unit5_Operating systems .indb 28 11/19/2015 6:54:02 PM


Chapter 3  Deadlock  |  5.29

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

Gate_CSE_Unit5_Operating systems .indb 29 11/19/2015 6:54:03 PM


5.30 | Operating System

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

Which one of the following statement is TRUE P1 2 0 1 0 1 2


if all the processes run concurrently starting time P2 2 2 1 1 2 0
t = 0 ? [2009]
(a) All processes will finfish without any dead- (a) P0
lock. (b) P1
(b) Only P1 and P2 will be in deadlock. (c) P2
(c) Only P1 and P3 will be in deadlock. (d) NONE of the system is in deadlock
(d) All three processes will be in deadlock. Solution: (c)
Solution: (b) By applying Banker’s Algorithm, the safe state
Draw the timing diagram for all these process; one <P0, P1, P2>.
can observe that all the process requests could be Hance the correct option is (c)
satisfied at different interval of time and eventually 8. Consider the following snapshot of a system run-
leading to successful completion of them. ning n processes. Process i is holding xi instances
Hance the correct option is (b) of resource R, for 1≤ i≤ n. Currently, all instances
6. Which of the following is NOT true of deadlock of R are occupied . Further for all I, process I i
prevention and deadlock avoidance schemes? has placed a request for an additional yi instances
 [2008] while holding they xi instances it already has.
(a)  In deadlock prevention, the request for re- There are abjectly two processes p and q such that
sources is always granted if the resulting state yp = yq. Which of the following can serve as neces-
is safe. sary condition to guarantee that the system is not
(b)  In deadlock avoidance, the request for re- approaching a deadlock? [2006]
sources is always granted if the resulting state (a) (min xp , xq) < max k ≠ p,q yk
is safe. (b) xp + xq ≥ max k ≠ p,q yk
(c)  Deadlock avoidance is less restrictive than (c) (max xp , xq) >1
deadlock prevention. (d) (min xp , xq) >1
(d) Deadlock avoidance requires knowledge of re- Solution: (b)
sources requirement a priori . Right now (n-2) processes are blocked as available
Solution: (a) is zero. Only ‘p’ & and ‘q’ processes can complete,
Deadlock prevention deals only with preventing upon which they would release their resources xp,
I. Mutual exclusion, II. Hold & wait , xq therefore, if x p+q ≥ min yk , k ≠ p, q.
III. No Preemption , IV. Circular wait. This would guarantee that one out of blocked pro-
Hance the correct option is (a) cess can come out of the cycle. Right now (n - 2)
processes are blocked, as available is zero. Only

Gate_CSE_Unit5_Operating systems .indb 30 11/19/2015 6:54:03 PM


Chapter 3  Deadlock  |  5.31

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

Gate_CSE_Unit5_Operating systems .indb 31 11/19/2015 6:54:03 PM


5.32 | Operating System

Five-marks Questions Solution:


(a) System is in safe state; this can be tested by
applying banker’s safety algorithm. <P1, P2,
1. A computer system uses the Banker’s algorithm to
P3>.
deal with deadlocks. Its current state shown in the
(b) By granting the request, the system goes into
table below, where P0, P1<P2 are processes and
unsafe state, and hence, the request is denied.
R0, R1, R2 are resource types. [1996]
Hance the correct option is (b)
Maximum need
2. Consider the resource allocation graph given in the
R0 R1 R2
figure [1994]
P0 4 1 2 r r
1 2

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.

Gate_CSE_Unit5_Operating systems .indb 32 11/19/2015 6:54:03 PM


Chapter 4
Memory Management
3. How many 32 Kx1 RAM chips are needed to pro-
One-mark Questions vided a memory capacity of 256K bytes? [2009]
(a) 8 (b) 32
1. A system uses FIFO policy for page replacement. (c) 64 (d) 128
It has 4 pages frames with no page loaded to begin
with. The system first access 100 distinct pages in Solution: (c)
some order then access the same 100 pages but Hence, the correct option is (c).
now in the reverse order. How many page faults 4. In which of the following page replacement poli-
will occur? [2010] cies, Belady’s anomaly may occur? [2009]
(a) 196 (b) 192 (a) FIFO (b) Optimal
(c) 197 (d) 195 (c) LPU (d) MRU
Solution: (a) Solution: (a)
Given that page frame size = 4. Hence, the correct option is (a).
As there are 100 distinct pages which are first 5. The essential contents in each entry of a page table
accessed → 100 page fault when it accessed → is/are [2009]
the same 100 pages but now in the reverse order (a) Virtual page number
→ (100 – 4), as page frame size is four. (b) Page frame number
Therefore, Total number of page faults (c)  Both virtual page number and page frame
→ 100 + (100 – 4) = 196 number
(d) Access right information
Hence, the correct option is (a).
Solution: (b)
2. A system uses 3 page frames for storing process
pages in main memory. It uses the LRU page Hence, the correct option is (b).
replacement algorithm policy. Assume that all the 6. What is the swap space in the disk used for? [2005]
page fault that will occur while processing the (a) Saving temporary html pages
page reference string given below. [2010] (b) Saving process data
4, 7, 6, 1, 7, 6, 1, 2, 7, 2 (c) Storing the super – block
(d) Storing device drivers
Solution: (6)
Solution: (b)
Assume pure demand paging initially the first
three references causes page fault and from the Hence, the correct option is (b).
remaining reference using LRU policy there more
page faults occurs making the count to 6.

Gate_CSE_Unit5_Operating systems .indb 33 11/19/2015 6:54:03 PM


5.34 | Operating System

7. Consider a program P that consists of two source Solution: (c)


modules M1 and M2 contained in two differ- Hence, the correct option is (c).
ent files. If M1 contains a reference to a function
1 2. The optimal page replacement algorithm will
defined in M2, the reference will be reSolutionved
select the page that. [2002]
at [2004]
(a) Has not been used for the longest time in past.
(a) Edit time (b) compile time
(b) Will not be used for the longest time in the fu-
(c) Link time (d) Load time
ture.
Solution: (c) (c) Has been used for the least number of times.
Hence, the correct option is (c). (d) Has been used for the most number of times.
8. Which of the following addressing modes are suit- Solution: (b)
able for program relocation at run time? [2004] Hence, the correct option is (b).
i) AbSolution addressing
13. Which of the following statements are FALSE?
ii) Based addressing
 [2001]
iii) Relative addressing
(a) Virtual memory implements the translation of
iv) Indirect addressing
program’s address space in to physical memo-
(a) i & iv (b) i & ii
ry address space.
(c) ii & iii (d) i,ii & iv
(b)  Virtual memory allows each program to
Solution: (c) exceed the size of the primary memory.
Hence, the correct option is (c). (c)  Virtual memory increases the degree of
9. The minimum number of page frames that must be multiprogramming.
allocated to a running process in a virtual memory (d) Virtual memory reduces the context switching
environment is determined by [2004] overhead.
(a) the instruction set architecture Solution: (a and b)
(b) page size Hence, the correct option is (a and b).
(c) physical memory size
14. The process of assigning the load address to the
(d) number of processes in memory
various part of the program and adjusting the code
Solution: (a) and data in the program to reflect the assigned
Hence, the correct option is (a). address is called [2001]
10. In a system with 32 bit virtual addresses and 1 (a) Asembly
KB page size, use of one – level tables for vir- (b) Parsing
tual to physical address translation is not practical (c) Relocation
because of [2003] (d) Symbol resolution
(a) the large amount of internal fragmentation. Solution: (c)
(b) the large amount of external fragmentation . Hence, the correct option is (c).
(c)  the large memory overhead in maintaining
15. Consider a virtual memory system with FIFO page
page tables.
replacement policy. For an arbitrary page access
(d) the large computation overhead in the transla-
pattern, increasing the number of page frames in
tion process.
main memory will [2001]
Solution: (c) (a) always decrease the number of page faults,
Hence, the correct option is (c). (b) always increase the number of page faults,
11. Which of the following is not form of memory? (c) sometimes increase the number of page fault ,
 [2002] (d) never affect the number of page fault,
(a) Instruction cache Solution: (c)
(b) Instruction register due to Balady anomaly.
(c) Instruction opcode Hence, the correct option is (c).
(d) Translation look aside buffer

Gate_CSE_Unit5_Operating systems .indb 34 11/19/2015 6:54:03 PM


Chapter 4  Memory Management  |  5.35

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

Gate_CSE_Unit5_Operating systems .indb 35 11/19/2015 6:54:03 PM


5.36 | Operating System

Two-marks Questions to occur once the pattern is repeated thrice. Same


thing happens in the case of MRU.
1. Consider the virtual page reference string [2014] Hence, the correct option is (d).
1, 2, 3, 4, 1, 3, 2, 4, 1 4. Consider a paging hardware with TLB. Assume
that the entire page table and all the pages are in
On demand paged virtual memory system running
the physical memory. It takes 10 ms to search the
on a computer system that has main memory size
TLB and 80 ms to access the physical memory.
of 3 page frames which are initially empty. Let
If the TLB hit ratio is 0.6, the effective memory
LRU, FIFO and OPTIMAL denote the number of
access time (in ms ) is _______ [2014]
page faults under the corresponding page replace-
ment policy, then Solution: (123)
(a) Optimal < LRU < FIFO EMAT = x (c + m) + ( 1 – x) c + 2m;
(b) Optimal< FIFO < LRU where c = 10, m = 80, x = 0.6 generates 122 ms.
(c) Optimal = LRU
5. A multi level page table is preferred in comparison
(d) Optimal = FIFO
to a single level page table for translating virtual
Solution: (b) address to physical address because [2009]
Hence, the correct option is (b). (a) it reduces the memory access time to read or
2. Assume that there are 3 page frames which are write a memory location.
initially empty. If the page reference string is
­ (b) it helps to reduce the size of page table needed
1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, then the number of to implement the virtual address space of a
page fault using the optimal replacement policy process.
is______ [2014] (c)  it is required by the translation look aside
buffer.
Solution: (7)
(d) it helps to reduce the number of page faults in
Applying pure demand paging the first three refer- page replacement algorithms.
ences causes page – faults, and therefore from the
Solution: (b)
remaining reference by applying optimal replace-
ment where in that page is selected which will not The basic objective of multi – level paging is to
be referred for the longest duration of time in the reduce the page table size overhead. A multi level
future. page table saves space over a single page table
because only the parts that are need to be allocated.
3. A computer has twenty physical page frames
As the most processes only use a small fraction of
which contains page numbered 1, 2,….,100 in
the address space, only a small fraction of the page
that order and repeats the access sequence thrice.
table needs to be allocated.
Which one of the following page replacement pol-
icies ­experiences the same number of page faults Hence, the correct option is (b).
as the optimal page replacement policy for this 6. Consider the virtual page reference string [2009]
program? [2014] 1, 2, 3, 2, 4, 1, 3, 2, 4, 1
(a) LRU
On demand paged virtual memory system running
(b) FIFO
on a computer system that has main memory size
(c) LIFO
of 3 page frames which are initially empty. Let
(d) Most recently used
LRU, FIFO and OPTIMAL denote the number of
Solution: (d) page faults under the corresponding page replace-
Initially the first 20 references will cause fault ment policy, then
replacing the page in order from 101 – 120. This is (a) Optimal < LRU < FIFO
just like fault without replacement. Thereafter, the (b) Optimal< FIFO < LRU
next page fault is for page number 21 which should (c) Optimal = LRU
result in replacing the page 20 as it is the last one (d) Optimal = FIFO

Gate_CSE_Unit5_Operating systems .indb 36 11/19/2015 6:54:03 PM


Chapter 4  Memory Management  |  5.37

Solution: (b) The number of bits required for addressing the


The given string is next – level page table(or page frame) in the page
table entry of the first, second and third level page
1, 2, 3, 2, 4, 1, 3, 2, 4, 1
tables are, respectively
Optimal 1, 2, 3, 2, 4, 1, 3, 2, 4, 1 (a) 20, 20 and 20 (b) 24, 24 and 24
1 1 1 1 1 1 1 1 1
(c) 24, 24 and 20 (d) 25, 25 and 24
1
2 2 2 4 4 4 4 4 4 Solution: (b)
3 3 3 3 3 2 2 2 Number of bits required for first lent = 24
F F F F F Number of bits required for second lent = 24
Number of bits required for third lent = 24
Page fault = 5
Hence, the correct option is (b).
LRU 1, 2, 3, 2, 4, 1, 3, 2, 4, 1
8. A virtual memory system uses FIFO page replace-
1 1 1 1 4 4 4 2 2 2 ment policy and allocates a fixed number of frames
2 2 2 2 2 3 3 3 1 to a process. Consider the following statements:
P:  Increasing the number of page frames
3 3 3 1 1 1 4 4
allocates to a process sometimes increases the
F F F F F F F F F
page fault rate. [2007]
Q:  Some programs do not exhibit locality of
Page fault = 8
reference.
FIFO 1, 2, 3, 2, 4, 1, 3, 2, 4, 1
Which of the following is TRUE?
1 1 1 1 4 4 4 4 4 4 (a) Both P & Q are true, and Q is the reason for P.
2 2 2 2 1 1 1 1 1 (b) Both P and Q are true, but Q is not the reason
3 3 3 3 3 2 2 2
for P.
F
(c) P is false but Q is true.
F F F F F
(d) Both P and Q are false.
Page fault = 6 Solution: (b)
From the above Solution if we consider the page Hence, the correct option is (b).
faults Common Data for Question 9 and 10
OPTIMAL < FIFO < LRU A process has been allocated 3 page frames.
Hence, the correct option is (b). Assume that none of the pages of the process
7. A processor used 36 bit physical addresses and are available in memory initially. The process
32 bit virtual addresses, with a page frame size makes the following sequence of page reference
of 4KB. Each page table entry is of size 4 bytes. (reference string):
A three level page table is used for virtual to 1, 2, 1, 3, 7, 4, 5, 6, 3, 1
physical address translation, where the virtual 9. If optimal page replacement policy is used, how
address is used as follows: [2008] many page faults occur for the above reference
• Bits 30 are used to index into the first level string? [2007]
page table. (a) 7 (b) 8
• Bits 21 are used to index into second level (c) 9 (d) 10
page table. Solution: (a)
• Bits 12 are used to index into third level page Given the reference string
table. 1, 2, 1, 3, 7, 4, 5, 6, 3, 1
• Bits 0 are used as offset within the page.

Gate_CSE_Unit5_Operating systems .indb 37 11/19/2015 6:54:04 PM


5.38 | Operating System

1, 2, 1, 3, 7, 4, 5, 6, 3, 1 12. Consider a system with a two level paging scheme


1 2 1 3 7 4 5 6 3 1 in which a regular memory access takes 150 nano-
1 1 1 1 1 1 1 1 1 1 seconds, and servicing a page fault takes 8 ms. An
2 2 2 7 4 5 6 6 6 average instruction takes 100 ns of CPU time, and
3 3 3 3 3 3 3 two memory access. The TLB hit ratio is 90% and
F F F F F F F
the page fault rate is one in every 10,000 instruc-
tions. What is the effective average instruction
Total number of page fault: = 7. execution time? [2004]
(a) 645 ns (b) 1050 ns
Hence, the correct option is (a).
(c) 1215 ns (d) 1230 ns
1 0. Least Recently Used (LRU) page replacement
Solution: (a)
policy is practical approximation to optimal page
replacement. For the above reference string, how Effective instruction time = 100ns + 2 * EMAT ∼
many more page fault occur with LRU than with 640 ns
the optimal page replacement policy? EMAT = 0.9 (150ns) + 0.1
(a) 0 (b) 1 [10 ^ – 4*8ms + (1 – 10 ^ – 4)*300 ns]
(c) 2 (d) 3
Hence, the correct option is (a).
Solution: (c)
Common Data For Questions 13 and 14 [2003]
Given the reference String
A processor uses 2 level page tables for virtual to
1, 2, 1, 3, 7, 4, 5, 6, 3, 1 physical address translation. Page tables for both
1 2 1 3 7 4 5 6 3 1 levels are stored in the main memory. Virtual and
1 1 1 1 1 4 4 4 3 3 physical addresses are both 32 bits wide. The
2 2 2 7 7 7 6 6 6 memory is byte addressable. For virtual to physi-
cal address translation, the 10 most significant bits
3 3 3 5 5 5 1
for the virtual address are used as index into the
F F F F F F F F F
first level page table while the next 10 bits are used
as index into the second level page table. The 12
Total number of page fault: = 9.
significant bits of the virtual address are used as
Page fault in LRU – page fault in Optimal = offset within the page. Assume that the page table
9–7=2 entries in both level of page tables are 4 bytes wide.
Hence, the correct option is (c). Further, the processor has a translation look aside
11. A computer system supports32 bit virtual addresses a buffer with a hit rate of 96%. The TLB caches
as well as 32 bit virtual addresses. Since the vir- recently used virtual page numbers and the corre-
tual address space is of the same size as the physi- sponding virtual page numbers. The processor also
cal address apace, the operating system designers has a physical address cache with a hit rate of 90%.
decide to get rid of the virtual memory entirely. Main memory access time is 10ns, cache success
Which one of the following is true? [2006] time is 1ns, and TLB access time is also 1ns.
(a) Efficient implementation of multi user 13. Assuming that no page fault occur, the average
support is no longer possible. time taken to access a virtual address is approx(to
(b) The processor cache organization can be made the nearest)
for more efficient now. (a) 1.5 ns (b) 2 ns
(c) Hardware support for memory management is (c) 3 ns (d) 4 ns
no longer needed. Solution: (d)
(d) CPU scheduling can be made more efficient
EMAT = 0.96 [1ns + 0.9 (1 ns) + 0.1 (1 ns + 10 ns)]
now .
+ 0.04
Solution: (c)
[1ns + 10 ns + 10 ns + 0.9 (1ns) + 0.1(1ns + 10ns)]
Hence, the correct option is (c).

Gate_CSE_Unit5_Operating systems .indb 38 11/19/2015 6:54:04 PM


Chapter 4  Memory Management  |  5.39

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

Gate_CSE_Unit5_Operating systems .indb 39 11/19/2015 6:54:04 PM


5.40 | Operating System

(a) 12KB (b) 14KB (a) 13 (b) 8


(c) 10KB (d) 8KB (c) 7 (d) 10
Solution: (b) Solution: (c)
Hence, the correct option is (b). Find the reference string first the number of page
21. If an instruction takes i microsecond and page fault = length of reference string in this case as the
fault takes an additional j microseconds, the effec- number of frames is one.
tive instruction time if on the average a page fault Find the reference string first:
occurs every k instruction is: [1998] It is 1, 2, 4, 5, 1, 2, 3
(a) i + (j/k) (b) i + j*k
The number of page fault = length of reference
(c) (i + j)/k (d) (i + j)*k
string in this case as the no. of frame is one.
Solution: (a)
Hence, the correct option is (c).
Use the formula for eff. Inst. Time = p*time with
25. In a virtual memory system, the address space
page fault + (i – p)*time without page fault.
specified by the address lines of the CPU must
Hence, the correct option is (a). be…………… than the physical memory size……..
22. A 1000 Kbyte memory is managed using vari- than the secondary storage size. [1995]
able partition but to compaction. It currently has (a) Smaller, smaller (b) Smaller, larger
two partition of sizes 200Kbytes and 260Kbytes, (c) Larger, smaller (d) Larger, larger
respectively. The smallest allocation request in Solution: (c)
Kbytes that could be denied for [1996]
Hence, the correct option is (c).
(a) 151 (b) 181
(c) 231 (d) 541 26. A memory page containing a heavily used vari-
able, that was initialized very clearly and is in con-
Solution: (d)
stant use, is removed when [1994]
Remaining all are satisfiable in one or the other (a) LRU, page replacement algorithm is used
partition, but 541 is never satisfiable. (b) FIFO, page replacement algorithm is used
Hence, the correct option is (d). (c) LFU, page replacement algorithm is used
23. The capacity of memory units is defined by the (d) None of the above
number of works multiplied by the number of bits/ Solution: (b)
work. How many separate address and data lines Initialized early means, it is FCFS.
are needed for a memory of 4K × 16? [1995]
If FIFO page replacement algorithm is used, then
(a) 10 address, 16 data lines
a memory page containing a heavily used variable
(b) 11 address, 8 data lines
that was initialized very early and is in constant
(c) 12 address, 16 data lines
use is removed.
(d) 12 address, 12 data line
Hence, the correct option is (b).
Solution: (c)
27. Consider the following heap(figure) in which
Memory specification = No. of words × width of
blank regions are not in use and hatched regions
word.
are in use. [1994]
Hence, the correct option is (c).
5 15 30 35 600
24. The address sequence generated by tracing a par-
ticular program executing in a pure demand paging
system with 100 records per page with 1 free main
memory frame is recorded as follows. What is the
number of page faults? [1995]
0100, 0200, 0430, 0499, 0510, 0530, 0560, 0120, Increasing Addresses
0220, 0240, 0260, 0320, 0370

Gate_CSE_Unit5_Operating systems .indb 40 11/19/2015 6:54:04 PM


Chapter 4  Memory Management  |  5.41

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 .

Gate_CSE_Unit5_Operating systems .indb 41 11/19/2015 6:54:04 PM


5.42 | Operating System

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)

Gate_CSE_Unit5_Operating systems .indb 42 11/19/2015 6:54:05 PM


Chapter 4  Memory Management  |  5.43

Five-marks Questions 2. A certain computer system has segmented paging


architecture for virtual memory. The memory is
byte addressable. Both virtual and physical address
1. A computer system uses 32 bit virtual address,
spaces contain 216 bytes each. The virtual address
32 bit physical address. The physical memory is
space is achieved is divided in 8 non overlapping
byte addressable, and to page size is 4k bytes. It
equal size segments. The Memory Management
is decided to use two level page table to translate
Unit (MMU) has a hardware segment table, each
from virtual address to physical address. Equal
entry of which contains the physical address of the
number of bits should be used for indexing first
page table for the segment. Page tables are stored
level and second level page table, and the size of
in the main memory and consists of 2 bytes page
each page table entry is 4 bytes. [2002]
tables entries. [1999]
(a) Give a diagram showing how a virtual address
(a) What is the minimum page size in bytes so that
would be translated into physical address.
the page table for a segment requires atmost on
(b) What is the number of page table entries that
page to store it? Assume that the page size can
can be contained in each page?
only be power of 2.
(c) How many bits are available for storing protec-
(b) Now suppose that the page size is 512 bytes.
tion and other information in each page table
It is proposed to provide a TLB (transaction
entry?
look – aside buffer) for speeding up address
Solution:  (a) translation. The proposed TLB will be capa-
Pages table base register
Virtual address from processor ble of storing page table entries for 16 recently
referenced virtual page, in last cache that will
Page table address
Offset use the direct mapping scheme. What is the
number of tag bits that will need to be associ-
+
PAGE TABLE
Virtual page ated with each cache entry ?
number (c) Assume that each page table entry contains
(besides other information ), 1 valid bit, 3 bit
for page protection and dirty bit. How many
bits are available in a page table entry for stor-
ing the aging information of page? Assume
Page Frame Offset that the page size is 512 bytes.
}
}

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

Page table entry structure


f = frame No. = 216 = 27 = 7 bits.

Gate_CSE_Unit5_Operating systems .indb 43 11/19/2015 6:54:05 PM


5.44 | Operating System

3. In a computer system where the best – fit algorithm


0 1 16 17
is used for allocating jobs to memory partitions,
the following situation was encountered: [1998]
LRU Page
Student Student Student Email Student CP I
ID Name Age
ii) Page fault = 3
2345 Shanker shankar@math X 9.4
iii) Page replacement = 2
1287 Swati swati@ee 19 9.5
For all the above bits, make a note that the page
7853 Shankar shankar@ese 19 9.4 number in decimal are 0, 1, 16, 17 for the given
9876 Swati swati@mech 18 9.3 hexadecimal addresses.
8765 Ganesh ganesh@civil 10 8.7 5. A computer installation has 1000K of main mem-
ory. The jobs arrive and finish in the following
When will the 20K job complete? sequence. [1995]
Solution: Job 1 requiring 200k arrives
Job 20K completes at 31 use best fit only with fixed Job 2 requiring 350k arrives
partitions and FCFS scheduling. As an alternative, Job 3 requiring 300k arrives
one can try with variable partitions with best avail- Job 1 finish
able fir and FCFS algorithm.
Job 4 requiring 120k arrives
The 20K partition will be occupied by the 14K job
which will require 10 units of time for execution. Job 5 requiring 150k arrives
After its completion the 10K job will be occupying Job 6 requiring 80k arrives
this 20K partition. And on its completion, 20K will (a) DRAW the memory allocation table using best
be taking up the partition. fit and first fit algorithm.
Hence total time = 10 + 1 + 8 = 19 units. (b) Which algorithm performs better for this se-
quence?
Other job will be occupying the other partitions.
Solution:
4. A demand paged virtual memory system uses 16
bit virtual address, page size of 256 bytes, and has BEST FIT FIRST FIRST
1K bytes of main memory. LRU page replacement 30k J4 1000k
is implemented using a list whose current status
(page number in decimal ) is [1996] J4 120k J6 80k

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

Gate_CSE_Unit5_Operating systems .indb 44 11/19/2015 6:54:05 PM


Chapter 4  Memory Management  |  5.45

page faults occur for the following page replace- 1 2 3 4 1 3 5 2 1 5 4 3 2 3


ment algorithms: 1 1 1 4 4 4 4 4 4 4 4 4 4 4
2 2 2 1 1 1 2 2 5 5 5 2 2
(a) LRU (b) FIFO 3 3 3 3 5 5 1 1 1 3 3 3
Assume that the main memory is empty initially. F FF F F F F F F F F
Solution:
(a) 9 Page fault with LRU No. of page fault = 11.
(b) 7 page fault with FIFO 7. Let the page reference and working set window be
Apply given page replacement algorithm to find c c d b c e c e a d and 4 respectively. The initial
page faults. working set at time l = 0 contains the pages {a,
(a) LRU d, e} where a was referenced at time t = 0, d was
referenced at time t = – 1, and e – was referenced
12 3 4 1 35 2 1 5 4 3 2 3
1 1 1 4 4 4 5 5 5 5 5 5 2 2
at time t = – 2. Determine the total number of page
2 2 2 1 1 1 2 2 2 4 4 4 4 frames used by computing the working set at each
3 3 3 3 3 3 1 1 1 3 3 3 reference. [1992]
F F F F F F F F F F F Solution: Number of page fault = 4
No. of page fault = 11. Average number of page frame used are 4.
(b) FIFO

Gate_CSE_Unit5_Operating systems .indb 45 11/19/2015 6:54:05 PM


Chapter 5
File System
and Device Management
(c) NP - Hard = NP
One-mark Questions (d) p = NP - complete
Solution: (b)
1. Suppose a disk has 201 cylinders numbered from
0 to 200. At some time the disk arm is at cylinder
100, and there is a queue of disk access requests for
cylinders 30, 85, 90, 100, 105, 110, 135 and 145. If NP hard
P
Shortest Seek Time First (SSTF) is being used for
scheduling the disk access, the request for cylinder
90 is serviced after servicing ____________ nuber
of requests. [2014] NP Complete  P  
(A) 1 (B) 2
(C) 3 (D) 4 Look at the diagram showing the relationship
Solution: (3) between the class of P, NP and NPH problems for
From the current position 100, it will serve the the case when P is not equal to NP;
requests in order 100, 105, 110 and then 90. Hence, the correct option is (b).
2. A based file system is being used and the total 4. The data block of a very large file in UNIX file
overhead of each entry in the FAT is 4 bytes in size. system are allocated using [2008]
Given a 100 × 106 bytes disk on which the file sys- (a) Contiguous allocation
tem is stored and data block size is 103 bytes, the (b) Linked allocation
maximum size of a file that can be stored on this (c) Indexed allocation
disk in units of 106 bytes is ____________.[2014] (d) An extension of indexed allocation.
Solution: 99.6
Solution: (d)
number of blocks on the disk is 100 × 103 ; Hence, the correct option is (d).
The size of FAT = 4 × 100 × 103 . 5. Consider a disk pack with 16 surfaces, 128 tracks
Bytes = 0.4 × 106 Bytes per and 256 sectors per track. 512 bytes of data
Subtracting this value from the size of is the case are stored in a bit serial manner in a sector. The
of size which is 99.6 × 106 capacity of the disk pack and the number of bits
required to specify a particular sector in the disk
3. Assuming P ≠ NP, which of the following is are respectively: [2007]
TRUE? [2012] (A) 256Mbyte, 19 bits
(a) NP - complete = NP (B) 256Mbyte, 28 bits
(b) NP - Complete ∩ P = ϕ

Gate_CSE_Unit5_Operating systems .indb 46 11/19/2015 6:54:06 PM


Chapter 5  File System and Device Management  |  5.47

(C) 512Mbyte, 20 bits Solution: (a)


(D) 64Gbyte, 28 bits Large block size results in more internal fragmen-
Solution: (a) tation and reading a larger block results in read-
Disk capacity = 16 × 128 × 256 × 512 MB. ing a larger block results in reading more data, and
hence higher throughput.
Sector address = 4 + 7 + 8 = 19 bits.
Hence, the correct option is (a)
Hence, the correct option is (a)
9. Which of the following require a device driver?
6. Normally user programs are prevented from han-
 [2001]
dling I/O directly by I/O instructions in them. For
(a) Register (b) Cache
CPUs having explicit I/O instructions, such I/O
(c) Main memory (d) Disk
protection is ensured by having the I/O instruc-
tions privileged. In a CPU with memory mapped Solution: (d)
I/O, there is no explicit I/O instruction. Which Hence, the correct option is (d).
one of the following is for a CPU with memory 10. Listed below are some operating system abstrac-
mapped I/O? [2005] tions (in the left column) and the hardware compo-
(a) I/O protection is ensured by operating system nents. Which matching pairs are correct? [1999]
routine(s)
I
(b) I/O protection is ensured by a hardware trap
(a) Thread
(c) I/O protection is ensured during system con-
(b) Virtual address space
figuration
(c) File
(d) I/O protection is not possible
(d) Signal
Solution: (a)
II
Hence, the correct option is (a). (a) Interrupts (b) Memory
7. Consider an operating system capable of loading (c) CPU (d) Disk
and executing a single sequential user process at Solution: (a - 3, b - 2, c - 4, d - 1)
a time. The head scheduling algorithm is used is
Threads are different simultaneous process in the
First Come First Serve. If FCFS is replaced by
CPU.
Shortest Seek Time First (SSTF), claimed by the
vendor to give 50% better benchmark results what Virtual address space is implemented in memory.
is expected improvement in the I/O performance The file system is the way in which data in a disk
of user programs? [2004] is organized.
(a) 50% (b) 40% A signal is acted upon using the mechanism of
(c) 25% (d) 0% interrupts.

Solution: (d) 11. Which of the following disk scheduling strategies
When there is only one process in the system then is likely to give the best throughput? [1999]
the disk scheduling technique has no role.

(a) Farthest cylinder next
(b) Nearest cylinder next
Hence, the correct option is (d)
(c) First
8. Using a larger block size in a fixed block size file (d) Elevator algorithm
system leads to [2003]
Solution: (b)
(a) better disk throughput but poorer disk space
utilization . Nearest cylinder next is also known as shortest
(b) better disk throughput and better disk space seek time first which is the optimal algorithm.
utilization. Hence, the correct option is (b)
(c) poorer disk throughput but better disk space 12. Which of the following devices should get higher
utilization. priority in assigning interrupts? [1998]
(d) poorer disk throughput and poorer disk space
(a) Hard disk (b) Printer
utilization. (c) Keyboard (d) Floppy disk

Gate_CSE_Unit5_Operating systems .indb 47 11/19/2015 6:54:06 PM


Solution: (c) 16. I/O redirection [1997]
Whatever is typed should be given to the process

(a) Implies changing the name of a file
or displayed on the screen. (b) Can be employed to use an existing file as in-
put for a program
Hence, the correct option is (c)
(c) Implies connection 2 program through a pipe
13. Which of the following is? [1998] (d) None of the above
(a) Unless enabled, a CPU will not be able to pro-
Solution: (b)
cess interrupts.
(b)  Loop instructions cannot be interrupted till Hence, the correct option is (b).
they complete. 17. When an interrupts occurs, an OS [1997]
(c)  A processor checks for interrupts before (a) Ignore the interrupt
executing a new instruction. (b) Always changes state of interrupt process after
(d)  Only triggered interrupts are possible on processing the interrupt
microprocessors. (c)  Always resumes execution of interrupted

Solution: (a, c) process after processing the interrupts
(d) May change state of interrupted processes to
Hence, the correct option is (a, c).
'blocked' and schedule another process.
14. The correct matching for the following pairs is
Solution: (c)
 [1997]
Interrupt process resumes execution of interrupted
I
process after processing the interrupts by OS.
(a) DMA I/O
(b) Cache Hence, the correct option is (c)
(c) Interrupt I/O
(d) Condition code register Two-marks Questions
II
High speed RAM 1. A system contains three programs and each
Disk requires three tape units for its operation. The
Printer minimum number of tape units which the sys-
ALU tem must have such that deadlocks never arise is

(a) a - 4, b - 3, c - 1, d - 2 _________. [2014]
(b) a - 2, b - 1, c - 3, d - 4 Solution: 7
(c) a - 4, b - 3, c - 2, d - 1
Maximum condition for deadlock to occur is 6.
(d) a - 2, b - 3, c - 4, d - 1
2. A file system with 300 GB uses a file descrip-
Solution: (b)
tor with 8 direct block address, 1 indirect block
Hence, the correct option is (b). address and 1 doubly indirect block address. The
15. The correct matching for the following pairs are size of each disk block is 128 Bytes and the size of
 [1997] each disk block address is 8 Bytes. The maximum
(a) Disk (1) Round Robin possible file size in this file system is [2012]
(b) Batch processing (2) SCAN (A) 3
(c) Time sharing (3) LIFO (B) 35
(d) Interrupt Processing (4) FIFO (C) 280 Bytes

(a) a - 3, b - 4, c - 2, d - 1 (D) Dependent on the size of the disk
(b) a - 4, b - 3, c - 2, d - 1 Solution: (b)
(c) a - 2, b - 4, c - 1, d - 3
Max file size in the file = (8*128 + 16*128 +
(d) a - 3, b - 4, c - 3, d - 2
16*16*128) Bytes.
Solution: (c)
Hence, the correct option is (b)
Hence, the correct option is (c).

Gate_CSE_Unit5_Operating systems .indb 48 11/19/2015 6:54:06 PM


Chapter 5  File System and Device Management  |  5.49

3. An application loads 100 libraries at startup. (A) 10 (B) 25


Loading each library requires exactly one disk (C) 40 (D) 50
access. The seek time of the disk to a random loca- Solution: (a)
tion is given as 10ms. Rotational speed of disk is
Time to read 4 bytes word form the wish is 390 ~
6000rpm. If all 100 libraries are loaded from ran-
400ns. Which corresponds to 10 memory cycles.
dom locations on the disk, how long does it take to
Out of 10 memory cycles CPU would be blocked.
load all libraries? (The time to transfer data from
the disk block once the head has been positioned at Hence, the correct option is (a)
the start of the block may be neglected) [2011] 7. In the index allocation scheme of blocks to a file,
(A) 0.50s (B) 1.50s the maximum possible size of the file depends on
(C) 1.25s (D) 1.00s  [2002]
Solution: (b) (A) the size of the blocks, and the size of the ad-
[10ms + 60s/12000] × 100 dress of the blocks.
(B) the number of blocks used for the index, and
Hence, the correct option is (b)
the size of the blocks.
4. Consider a disk system with 100 cylinders. The (C) the size of the blocks, the number of blocks
requests to access the cylinders occur in follow- used for the index, and the size of the address
ing sequence: 4, 34, 10, 7, 19, 73, 2, 15, 6, 20. of the blocks.
Assuming that the head is currently at cylinder 50, (D) None of these.
what is the time taken to satisfy all requests if it Solution: (c)
takes 1ms to move from one cylinder to adjacent
Hence, the correct option is (c).
one and shortest seek time first policy is used?
 [2009] 8. Formatting a floppy disk refers to [1998]
(A) 95ms (B) 119ms (a) the data on the disk in contiguous fashion.
(C) 233ms (D) 276ms (d) the directory.
(c) the system area.
Solution: (b) (c)  identification information on all tracks and
Hence, the correct option is (b). sectors.
5. For a magnetic disk with concentric circular tracks, Solution: (d)
the seek latency is not linearly proportional to the Hence, the correct option is (d).
seek distance due to [2008]
9. If the disk in (a) is rotating at 3600rpm, determine
(a) non-uniform distribution of request. the effective data transfer rate which is defined as
(b) arm starting and stopping inertia. the of bytes transferred per second between disk
(c) higher capacity of tracks on the periphery of and memory. [1995]
the platter.
Solution: 4.8MB/S
(d) use of unfair arm scheduling policies.
10. A certain moving arm disk storage with one head
Solution: (c)
has following specifications: Number of tracks/
Hence, the correct option is (c). recording surface = 200 disk rotation speed = 2400
6. Consider a disk drive with the following specifica- rpm track storage capacity = 62500 bits [1993]
tions: [2005] The average latency of the device is P msec and the
16 surfaces, 512 tracks/surface, 512 sectors/track, data transfer rate is Q bits/sec.
1KB/sector, rotation speed 3000 rpm. The disk is Write the value of P & Q.
operated in cycle stealing mode whereby when- Solution: P - 12.5 ms; Q = 0.3125 MB/S
ever one byte word is ready it is sent to memory; 11. The root directory of a disk should be
similarly, for writing, the disk interface reads a 4 placed: [1993]
byte word from the memory in each DMA cycle. (a) At a fixed address in main memory
Memory cycle time is 40 nsec. The maximum per- (b) At a fixed location on the disk
centage of time that the CPU gets blocked during (c) Anywhere on the disk
DMA operation is: (d) At a fixed location on the system disk

Gate_CSE_Unit5_Operating systems .indb 49 11/19/2015 6:54:06 PM


5.50 | Operating System

Solution: (b) Solution:


To facilitate/ minimize the disk access time. (a) FCFS 876msec
Hence, the correct option is (b) (b) Closest cylinder next - 360 msec.
1 2. State whether the following statements are True or
False with reason. [1990] 14. On receiving an interrupt from an I/O device, the
CPU [1987]
The data transfer between memory and I/O devices
(a) halts for predetermined time.
using programmed I/O is faster than interrupt -
driven I/O. (b) branches off to the interrupt service routine
after completion of the current instruction.
Solution: False (c) branches off to the interrupt service routine
13. Disk request come to disk driver for cylinders immediately.
10, 22, 20, 2, 40, 56 and 38 in that order at a time (d) hands over control of address bus and data bus
when the disk drive is reading from cylinder 20. to the interrupting device.
The seek time is 6 msec peer cylinder. Compute Solution: (d)
the total seek time if the disk arm scheduling algo-
rithm is [1989] Hence, the correct option is (d).
(a) FCFS
(b) Closest cylinder next

Gate_CSE_Unit5_Operating systems .indb 50 11/19/2015 6:54:06 PM


Chapter 5  File System and Device Management  |  5.51

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?

Gate_CSE_Unit5_Operating systems .indb 51 11/19/2015 6:54:06 PM


5.52 | Operating System

As some x of these representative must be used to Solution:


indicate end of file, unusual block, bad block etc. SSTF: 85 movements
Maximum possible file size FIFO: 199 seeks
= 256 - x blocks, For block of small x, SSTF performs better.
or, (256 - x) * 4 bytes. 6. A certain moving arm disk-storage device has the
4. If the overhead for formatting a disk is 96 bytes following specifications: [1990]
for 40000 bytes sector. Compute the unformatted Number of tracks per surface = 4004
capacity of the disk of the following parameters:
Track storage capacity = 130030
 [1995]
Disk speed = 3600rpm
Number of surfaces = 8
Average seek time = 30m secs
Outer diameter of the disk = 12cm
Estimate the average latency the disk storage
Inner diameter of the disk = 4cm
capacity and the data transfer rate.
Inner trace space = 0.1mm
Solution:
Number of sectors per track = 20
Disk capacity is approx 1.2MB
Solution:
Latency time is 9ms.
No of tracks = (6 - 2)cm = 400
Date transfer rate is around 7000 Bytes/sec.
0.1mm inner track space surface capacity
7. Assuming the current disk cylinder to be 50 and
= 400*20*4096
the sequence for cylinders to be 1, 36, 49, 65, 53,
Disk capacity = 8 × 400 × 200 × 40 × 4096 Bytes 1, 2, 3, 20, 55, 16, 65 and 78 [1990]
= 4GB
Find the sequence of servicing using
5. The head of a moving head disk with 100 tracks (i) Shortest Seek Time First
numbered 0 to 99 is currently serving a request (ii) Disk scheduling policies.
at track 55. If the queue of requests kept in FIFO
Solution:
order is 10, 70, 75, 23 and 65, which of two disk
i) SSTF: 49, 53, 55, 65, 78, 36, 20, 16, 12, 3, 1
scheduling algorithm FCFS and SSTF (Shortest
ii) Elevator: 53, 55, 65, 78, 49, 36, 20, 12, 3, 1
Seek Time First) will require less head movement?
 [1995]
Find the total head movement for each of the
algorithm.

Gate_CSE_Unit5_Operating systems .indb 52 11/19/2015 6:54:06 PM


Unit Vi
Design anD analysis
of algorithms
Chapter 1: Algorithm Analysis and Asymptotic Notations 6.3
Chapter 2: Divide and Conquer 6.13
Chapter 3: Greedy Method 6.22
Chapter 4: Dynamic Programming 6.32
Chapter 5: P and NP Concepts 6.36
Chapter 6: Optimal Binary Search Tree 6.40
Chapter 7: Miscellaneous Topics 6.42

Unit 6 _Chapter 1.indd 1 11/19/2015 10:48:44 AM


Unit 6 _Chapter 1.indd 2
exam analysis

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

Algorithm Analysis and 2 0 0 1 0 0 1 1 0 1 1 0 2 1 1 3 3 4 3 1 2 5 0 1 1 2 4 0


Asymptotic Notations

Divide and Conquer 2 0 2 0 1 2 0 2 3 2 1 0 2 1 1 1 1 0 1 2 1 1 3 0 0 1 2 6

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

Optimal Binary Search Tree 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2

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

Unit 6 _Chapter 1.indd 3 11/19/2015 10:48:45 AM


6.4 | Design and Analysis of Algorithms

Solution: (c) Solution: (d)


Average case running time is always less than (or)
n n n n
equal to worst case time. Hence, A(n) = O(w(n)). j= + + + + ... + 1
According to asymptotic notations, average lies al- 1 2 4 8
ways between the best and the worst case inclusive.
1 1 1 1 1
Hence, the correct option is (c). ⇒ n  + + + + ... + 
1 2 4 8 n
6. Two alternative packages A and B are available for
processing a database having 10k records. Package ⇒ O(n) [ Polynomial of degree 1]
A requires 0.0001n2 time units and package B
Hence, the correct option is (d).
requires 10n.logn10 time units to process n records.
What is the smallest value of k for which package 9. The time complexity of computing the transitive
B will be preferred over A? [2010] closure of a binary relation on a set of n elements
(a) 12 (b) 10 (c) 6 (d) 5 is known to be: [2005]
(a) O(n) (b) O(n log n)
Solution: (c) (c) O(n3/2) (d) O(n3)
A takes 0.0001 n2 = 10−4 n2
Solution: (d)
B takes 10 n log10n units of time for k = 6
All-pairs shortest paths can be found with the help
A takes l0−4 × (106)2 = 108 of the transitive closure.
B takes 10 × l06 log10106 = 6 × l07 Hence, the correct option is (d).
Hence, A > B. 10. Consider an array multiplier for multiplying two n
Hence, the correct option is (c). bit numbers. If each gate in the circuit has a unit
7. Consider the following segment of C-code: delay, the total delay of the multiplier is [2003]
(a) Θ(1) (b) Θ(log n)
= (c) Θ(n) (d) Θ(n2)
<= Solution: (d)
= Multiplying two n-bit binary no’s of size ‘n’ and
The number of comparisons made in the execution ‘m’ is O(nm).
of the loop for any n > 0 is: [2007] Hence, the correct option is (d).
(a) [log2n] + 1 (b) n 11. Consider the following three claims [2003]
(c) [log2n] (d) [log2n] + 1 I. (n + k)m = Θ(nm) where k and m are constants
II. 2n+1 = O(2n)
Solution: (d) III. 22n = O(2n)
As ‘j’ increases in powers of 2; i.e. 2, 4, 8… in the Which of these claims are correct?
loop 2k ≤ n (a) I and II
When 2k > n loop exits, so no. of comparisons (b) I and III
made in execution of loop for any n > 0 is [log2 (c) II and III
n] + 1 (d) I, II, and III
Hence, the correct option is (d).
Solution: (a)
8. Consider the following C-program fragment in (n + k)m is a polynomial of power m
which i, j and n are integer variables for(i = n,
∴ O(nm) is True
j = 0; I > 0; i/ = 2, j+= i);
2n+1 = O(2n.2)
Let value ( j) denote the value stored in the variable
j after termination of the for loop. Which one of = O(2n)
the following is true? [2006] Hence, it is true
(a) val ( j) = q(log n) 22n = O(2n·2)
(b) val ( j) = q(√n) ≠ O(2n)
(c) val ( j) = q(n) Therefore, I and II only are correct
(d) val ( j) = q(n log n) Hence, the correct option is (a).

Unit 6 _Chapter 1.indd 4 11/19/2015 10:48:47 AM


Chapter 1 Algorithm Analysis and Asymptotic Notations | 6.5

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

Unit 6 _Chapter 1.indd 5 11/19/2015 10:48:51 AM


6.6 | Design and Analysis of Algorithms

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

Unit 6 _Chapter 1.indd 6 11/19/2015 10:48:56 AM


Chapter 1 Algorithm Analysis and Asymptotic Notations | 6.7

(a) 1661 and 1640 (b) 59 and 59


- + - (c) 1640 and 1640 (d) 1640 and 1661
Solution: (c)
f1(n)
f1(8)
+ 1094 + 546
2 × f1(n − 1) 3 × f1(n − 2)
= = = 547 182
= = = 2×7
= <= ++ 364 + 183
= - + -
182 61
=
2×6 3×5
=
122 + 60
61 20
2×5 3×4
40 + 21
The running time of f 1 (n) and f 2 (n) are [2008]
(a) Θ(n) and Θ(n) 20 7
(b) Θ(2n) and Θ(n) 2×4 3×3
(c) Θ(n) and Θ(2n) 14 + 6
(d) Θ(2n) and Θ(2n) 7 2
Solution: (b) 2×3 3×2
The function f 2 () repeats for n-times, therefore 4 + 3
O(n); whereas the recurrence for f1 () is derived as 2
T(n) = l, n = 1
2×2 3×1
T(n) = 2T (n − 1) + 3T(n − 2) + c, n > l
2 + 0
Hence, the correct option is (b).
2×2 3×1
7. Consider the following C functions:
1094 + 546 = 1640

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

Unit 6 _Chapter 1.indd 7 11/19/2015 10:48:57 AM


6.8 | Design and Analysis of Algorithms

8. What is the time complexity of the following Solution: (b)


recursive function? [2007] The upper bound cannot be more than √n and low-
er bound will be Ω(1) when the loop [terminates
<= with the condition n % i = 0 for the first time.
Big O notation describes the tight upper bound
and Big Omega notation describes the tight lower
bound for a algorithm. The for loop in the question
+ is run maximum n times and minimum 1 time.
Therefore, T(n) = O( n) and T(n) = Ω(l).
(a) Θ6 (n2) (b) Θ(n log2 n) 10. A Priority-Queue is implemented as a Max-Heap.
(c) Θ(log2 n) (d) Θ(log2log2 n) Initially, it has 5 elements. The level-order tra-
versal of the heap is given below: 10, 8, 5, 3, 2
Solution: (d) Two new elements ‘1’ and ‘7’ are inserted in the
T(n) = T( n) + C heap in that order. The level order traversal of the
heap after the insertion of the elements is:
 12  [2005]
= T  n 2  + 2C (a) 10, 8, 7, 5, 3, 2, 1
 
(b) 10, 8, 7, 2, 3, 1, 5
By continuing this process up to ‘Kth’ iteration, (c) 10, 8, 7, 1, 2, 3, 5
then (d) 10, 8, 7, 3, 2, 1, 5
Solution: (d)
  1k  
T ( n) = T  n 2   + KC root
  Heap after inserting 10
 1 the 5 elements
 
Put n =2
2k
8 5
1
= log n 2
2k 2
3
2k = log2 n
K = log2log2n root
Hence, the correct option is (d). Heap after inserting 10
7 and heapify
9. Consider the following C code segment:; int Is
Prime(n) 8 5

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

Unit 6 _Chapter 1.indd 8 11/19/2015 10:49:03 AM


Chapter 1 Algorithm Analysis and Asymptotic Notations | 6.9

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

Unit 6 _Chapter 1.indd 9 11/19/2015 10:49:04 AM


6.10 | Design and Analysis of Algorithms

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

Unit 6 _Chapter 1.indd 10 11/19/2015 10:49:08 AM


Chapter 1 Algorithm Analysis and Asymptotic Notations | 6.11

20. Consider the following functions Hence, S is O(n2)


f ( n) = 3n n (or)

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 

Unit 6 _Chapter 1.indd 11 11/19/2015 10:49:17 AM


6.12 | Design and Analysis of Algorithms

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)

Unit 6 _Chapter 1 FMQ.indd 12 11/19/2015 12:04:02 PM


Chapter 2
Divide and Conquer

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

Unit 6 _Chapter 2.indd 13 11/19/2015 10:42:12 AM


6.14 | Design and Analysis of Algorithms

central element of the array as the pivot. Then the (a) 2k


tightest upper bound for the worst case perfor- (b) (3k + 1 − l)/2
mance is [2014] (c) 3log2k
(a) O(n2) (d) 2log3k
(b) O(n log n)
Solution: (b)
(c) Θ(n log n)
Using back substitution,
(d) O(n3)
T(2k) = 3T(2k − 1) + 1
Solution: (a)
In the worst case the selected pivot element will Let n = 2K
be placed in either first (or) last position. Then the  n
T(n) = 3T   + 1
required recurrence equation is  1
(or)
T(n) = T(n − 1) + Θ(n)
By using substitution method T(2K) = 3T(2K−1) + 1
T(n) = O(n2) aK = 3aK − 1 + l
Hence, the correct option is (a). (E − 3)aK = l
5. Which of the following statement(s) is/are correct aK = C13K
regarding Bellman-Ford Shortest path algorithm?
1 −1
P. Always finds a negative weighted cycle, if one ak = c ⋅ 3k ak = =
1− 3 2
exists.
Q. Finds whether any negative weighted cycle is 1 1 3
ak = c ⋅ 3k − ao = c − = 1 ⇒ c =
reachable from the source. [2009] 2 2 2
(a) P only
3 k 1  3k +1 − 1
(b) Q only ak = ⋅3 − = 
(c) both P and Q 2 2  2 
(d) Neither P nor Q
8. Randomised quick sort is an extension of quick
Solution: (d) sort where the pivot is chosen randomly. What is
Bellman-Ford works only if edges have negative the worst case complexity of sorting n numbers
weights but not having negative weight cycles. using randomised quick sort? [2001]
Hence, the correct option is (d). (a) O(n) (b) O(n log n)
6. The usual Θ(n2) implementation of Insertion Sort (c) O(n2) (d) O(n!)
to sort an array uses linear search to identify the
Solution: (b)
position where an element is to be inserted into
the already sorted part of the any. If, instead, we 9. Let s be sorted array of n integers. Let t(n) denote
use binary search to identify the position, the worst the time taken for the most efficient algorithm to
case running time will [2003] determine if there are two elements with sum less
(a) remain Θ(n2) than 1000 in s. Which of the following statements
(b) become Θ(n (log n)2) is true? [2000]
(c) become Θ(n log n) (a) t(n) is O(1)
(d) become Θ(n) (b) n < t (n) < n log n2
Solution: (c)
As binary search takes time of O(log n) for a set
(c) n log n2 < t(n) < ()
n
2

of n-elements. So, total time for n-elements is O(n (d) t(n) = ()n
2

log n) Solution: (a)


Hence, the correct option is (c). It is enough to check the first two elements of the
7. The solution to the recurrence equation array as the given array is already sorted.
T(2k) = 3T(2k − 1) + l, T(l) − 1 is [2002] Hence, the correct option is (a).

Unit 6 _Chapter 2.indd 14 11/19/2015 10:42:18 AM


Chapter 2 Divide and Conquer | 6.15

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

Unit 6 _Chapter 2.indd 15 11/19/2015 10:42:19 AM


6.16 | Design and Analysis of Algorithms

Hence the worst case time complexity of a se-


quence of n queue operations on an initially empty
queue is Θ(n)
The return value of the function is [2013] Hence, the correct option is (a).
(a) Θ(n2) 5. A list of n strings, each of length n, is sorted into
(b) Θ(n2log n) lexicographic order using the merge sort algo-
(c) Θ(n3) rithm. The worst case running time of this compu-
(d) Θ(n3log n) tation is [2012]
Solution: (b) (a) O(n log n)
n (b) O(n2 log n)
Outer loop: (c) O(n2 + log n)
2
Inner loop: log n (d) O(n2)
 n n Solution: (b)
K will be incremented by   for log n times. In merge sort algorithm number of splits are propor-
 2 2
So, k will be of order tional to height and in each level work done is n2.
n
0(n) * log n = 0(n2 log n) Hence, Total time complexity O(n2 log n). The
2 complexity of merge sort for elements is O(n log n)
4. Consider the following operation along with Hence, the correct option is (b).
Enqueue and Dequeue operations on queues, 6. The running time of an algorithm is represented by
where k is a global parameter. the following recurrence relation:
n n≤3

T ( n)   n 
T  3  + cn otherwise

Which one of the following represents the time
complexity of the algorithm? [2009]
(a) Θ(n)
(b) Θ(n log n)
What is the worst case time complexity of a se- (c) Θ(n2)
quence of n queue operations on an initially empty (d) Θ(n2log n)
queue? [2013]
Solution: (a)
(a) Θ(n) (b) Θ(n + k)
Applying master-theorem Case-III holds.
(c) Θ(nk) (d) Θ(n2)
 n n
Solution: (a) T(n) = T   + ⇒ T(n) = Θ(n)
 3 2
The complexity of a sequence of ‘n’ operations =  n
Total complexity of enqueue operations (α) + To- 7. In quick sort, for sorting n elements, the   th
 4
tal complexity of dequeue operations (β). As, Total
complexity of dequeue operation (β) ≤ Total com- smallest element is selected as pivot using an O(n)
plexity of enqueue operation (α). time algorithm. What is the worst case time com-
plexity of the quick sort? [2009]
i.e. (β) ≤ α (1) (a) Θ(n) (b) Θ(n log n)
We know, Total complexity of enqueue operation (c) Θ(n2) (d) Θ(n2 log n)
(α) ≤ n (2) Solution: (b)
\ Total complexity of n operations = α + β  n
After the   th smallest element is selected as
≤ α + α (From (1))  4
≤ n + n (From(2))  n
pivot the list gets partitioned into one with  
≤ 2n.  4

Unit 6 _Chapter 2.indd 16 11/19/2015 10:42:26 AM


Chapter 2 Divide and Conquer | 6.17

 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]

Unit 6 _Chapter 2.indd 17 11/19/2015 10:42:41 AM


6.18 | Design and Analysis of Algorithms

(a) T(n) = O(n2) 14. The recurrence relation


(b) T(n) = Θ(n log n) T(l) = 2
(c) T(n) = Ω(n2)  n
(d) T(n) = O(n log n) T ( n) = 3T   + n
 4
Solution: (c) Has the solution T(n) equal to [1996]
It is q (n log n) hence is also O(n2) and O(n log n) (a) O(n)
is not Ω(n2) (b) O(log n)
If we use binary search then there will be log n2! (c) O(n3/4)
comparisons in the worst case, which is (nlogn). (d) None of the above
But the algorithm as a whole will still have a run-
ning time of Θ(n2) on average because of the series Solution: (a)
of swaps required for each insertion. Applying Master Theorem, T(n) is O(n);
(or) a = 3, b = 4, K = l
 n Since a < bK so it is
T(n) = 2T   + n, T(0) = T(l) = 1
 2 Master Theorem:
T(2 ) = 2T(2k-1) + n
k a = 3, b = 4, k = 0, p = 0
ak − 2k − l = 2k (
3 > 4°. O n log34)
(Σ−2)ak = 2·2k Hence, the correct option is (a).
ak = c·2k 15. Quick-sort is run on two inputs shown below to
ak = c·2k sort in ascending order
2.2k (a) 1, 2, 3…n
ak = = 2 ⋅ c( k ,1)2k −1
∑− 2 (b) n, n − l, n − 2, … 2, 1
Let C1 and C2 be the number of comparisons
= 2k ⋅ 2k −1 made for the inputs (a) and (b) respectively. Then,
al = c ± l [1996]
ak = 2k + k·2k (a) C1 < C2
T (2k) = 9k = n + nlog2n ⇒ O(nlogn) (b) Cl > C2
Hence, the correct option is (c). (c) Cl = C2
(d) We cannot say anything for arbitrary n.
13. Let T(n) be the function defined by T(l) = 1, T(n)
Solution: (c)
 n
− 2 . T   + √n for n ≥ 2 It takes same number of comparisons for both
 2
the case because quick sort behaves in worst case
Which of the following statements is true? when the elements are already in sorted order
[1997] Hence, the correct option is (c).
(a) T(n) = O(√n)
16. The recurrence relation that arises in relation with
(b) T(n) = O(n)
the complexity of binary search is: [1994]
(c) T(n) = O(log n)
(d) None of the above  n
(a) T(n) = T   + k, k a constant
Solution: (b)  2
 n  n
T ( n) = 2T   + n , n ≥ 2 (b) T(n) = 2 T   + k, k a constant
 2  2
T(1) = 1
Master Theorem:  n
1 (c) T(n) = T   + log n
a = 2, b = 2, k = , p = 0  2
2
2 > 21/2 O(nlog22) = O(n)  n
(d) T(n) = T   + n
Hence, the correct option is (b).  2

Unit 6 _Chapter 2.indd 18 11/19/2015 10:42:53 AM


Chapter 2 Divide and Conquer | 6.19

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)

Unit 6 _Chapter 2.indd 19 11/19/2015 10:42:57 AM


6.20 | Design and Analysis of Algorithms

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

[9 7 19 2 16] 25 [61 70 49 34]

[9 7 2 19 16] 25 [61 70 4 34]

[2 7 9 19 16] 25 [61 70 49 34]

[2 7] 9 [19 16] 25 [61 70 49 34

[2 7] 9 [16 19] 25 [61 34 49 70]

[2 7] 9 [16 10] 25 [49 34] 61 [70]

[2 7 9 16 19] 25 [34 49] 61 [70]

[2 7 9 16 19 25 34 49 61 [70]

Unit 6 _Chapter 2 (FMQ).indd 20 11/19/2015 10:40:20 AM


Chapter 2 Divide and Conquer | 6.21

(b) 2-Way merge sort 3. Find a solution to the following recurrence


equation:
[25 7 34 2 70 9 61 16 49 19]
 n
T(n) = √n + T  
 2
[7 25] [2 34] [9 70] [16 61] [19 49]
T(l) = 1 [1989]
[7 25] [2 34] [9 70] [16 61] [19 49]
Solution: T(n) = T   + n
n
 2
[2 7] [25 34] [9 16 61 70] [19 49] T(l) = 1
Using master theorem for divide and conquer
[2 7] 9 16 25 34 61 70] [19 49] recurrences and applying the cases; by Case (3) of
the master theorem.
[2 7 9 16 19 25 34 49 61 70] T(n) is 8(√n)

Unit 6 _Chapter 2 (FMQ).indd 21 11/19/2015 10:40:22 AM


Chapter 3
Greedy Method

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

Unit 6 _Chapter 3.indd 22 11/19/2015 11:57:37 AM


Chapter 3 Greedy Method | 6.23

comparisons that will be needed in the worst case 2


by the optima algorithm for doing this is___ C E
1 2
[2014] A 1 G
10
Solution: 358 3 4
4 3
If one sorted list contain ‘m’ elements and another 7
S 3
sorted list contain ‘n’ elements then in the worst D
4 T
case we can merge them into a single sorted list 3 5 5
with (m + n − 1) comparison. 3
Hence, given files are P, Q, R, S, T B F

159 (a) SDT (b) SBD


94
(c) SACDT (d) SACET
Solution: (d)
In Dijkstra’s Algorithm, we always consider the
44 65 vertex which are go from the source with last cost,
20 24 30 35 50 and update cost lable of the vertex, if the present
cost is minimum than the previous cost. Greedy
Total number of comparisons = 158 + 93 + 64 + based Dijkstra’s Algorithm can be used here.
43 = 358. Hence, the correct option is (d).
4. An undirected graph G(V, E) contains n(n >
2. The number of distinct minimum spanning trees 2)-named v1, v2, …vn. Two nodes vi, vj are con-
for the weighted graph below is_____ [2014] nected if and only if 0 < |i − j| ≤ 2. Each edge (vi ,
vj) assigned a weight i + j. A sample graph with is
2 shown below. [2011]
2 1 2 1

2 2 v3 7 v4
1 1 2 1
4 5
2 2 6

v1 v2
Solution: 6 3

What will be the cost of the minimum spanning


1 tree (MST) of such a graph with n nodes?
1
1 1
(a) (11n2 − 5n) (b) n2 − n + l
1 12
1
(c) 6n (d) 2n + 1
2
Solution: (b)
Cost of MST with ‘4’ vertices is 3 + 4 + 6
3. Consider the directed graph shown in the figure
Cost of MST with ‘5’ vertices is 3 + 4 + 6 + 8
below. There are multiple shortest paths between
In general cost for ‘n’ vertices we have
vertices S and T. Which one will be reported by
= 3 + 4 + 6 + 8 + …+ 2n − 2
Dijkstra’s shortest path algorithm? Assume that,
= n2 − n + l
in any iteration, the shortest path 0 a vertex v is
Hence, the correct option is (b).
updated only when a strictly shorter path to v is
discovered. [2012] 5. An undirected graph G(V, E) contains n(n >
2)-named v1, v2, …vn. Two nodes vi, vj are

Unit 6 _Chapter 3.indd 23 11/19/2015 11:57:41 AM


6.24 | Design and Analysis of Algorithms

connected if and only if 0 < |i − j| ≤ 2. Each edge 1


0 1
(vi, vj) assigned a weight i + j. A sample graph with
is shown below. [2011]
4
v3 7 v4
4 2
2
4 5 4
6
3
v1 v2
3 Tree - 1
The length of the path from v5 to v6 in the MST of
previous question with n = 10 is 0 1
(a) 11 (b) 25 (c) 31 (d) 41
Solution: (c) 3 4
5 6 4 2
2
8 10 3
3 4
2
4 6
1 2 Tree - 2
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).

Unit 6 _Chapter 3.indd 24 11/19/2015 11:57:47 AM


Chapter 3 Greedy Method | 6.25

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

weights in an undirected connected graph. Let e be di = distance from root to message i


a specific edge of weight w. Which of the follow- qi = probability of message i
ing is FALSE? [2007] Hence, the correct option is (d).

Unit 6 _Chapter 3.indd 25 11/19/2015 11:57:50 AM


6.26 | Design and Analysis of Algorithms

13. In an unweighted, undirected connected graph, the 1


R
Q
shortest path from a node S to every other node is 1 4 2
computed most efficiently, in terms of time com- 6
P S 1
plexity by [2007] 2
(a) Dijkstra’s algorithm starting from S. 7 3
(b) Warshall’s algorithm T U
2
(c) Performing a DFS starting from S.
(d) Performing a BFS starting from S. In what order do the nodes get included into the
Solution: (d) set of vertices for which the shortest path distances
It is one of the application of BFS. are finalized? [2004]
Hence, the correct option is (d). (a) P, Q, R, S, I, U
(b) P, Q, R. U, S, T
14. Consider the following graph: (c) P, Q, R, U, T, S
(d) P, Q, T, R, U, S
2
Solution: (b)
2 7
b d
1 4 (a) P Q R S T U - Invalid (not in
increasing
1 1 4 3
order)
a 2
3 3 f
2 4
5
6 (b) P Q R U S T - Valid
4
c e 1 3 4

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

Unit 6 _Chapter 3.indd 26 11/19/2015 11:57:56 AM


Chapter 3 Greedy Method | 6.27

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

Consider the following algorithm.

2 4 5 7

Unit 6 _Chapter 3.indd 27 11/19/2015 11:57:59 AM


6.28 | Design and Analysis of Algorithms

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

Unit 6 _Chapter 3.indd 28 11/19/2015 11:58:00 AM


Chapter 3 Greedy Method | 6.29

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

0.05 0.08 0.11 0.17 0.19 0.40


1
a d f c a e 0 1

0.24 0.19 0.40 0.6


0.17 0.40
c a e e 0 1

0.11 0.13 0.36


0.24
f 1
0 1 0
0.05 0.08
0.11 0.13 0.17 0.19
b d
0 1
f c a
0.05 0.08
0.36
b d

0.17 0.19 0.24 Prefix codes:


0.40
c a
a → 111; b → 1010;
e c → 110; d → 1011; e → 0
0.11 0.13 2. An independent set in a graph is a subset of ver-
f tices such that no two vertices in the subset are
0.05 0.08 connected by an edge. An incomplete scheme for a
b d greedy algorithm to find a maximum independent
set in a tree is given below:

Unit 6 _Chapter 3 FMQ.indd 29 11/19/2015 10:43:34 AM


6.30 | Design and Analysis of Algorithms

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

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

6. Consider a graph whose vertices are points in the


4. A complete, undirected, weighted graph G is given plane with integer co-ordinates (x, y) such that 1 ≤
on the vertex {0, 1 …, n − 1} for any fixed ‘n’. x ≤ n and 1≤ y ≤ n, where n ≥ 2 is an integer. Two
Draw the minimum spanning tree of G if vertices (x1, y1) and (x2, y2) are adjacent if |x1 − x2| ≤
(a) the weight of the edge (u, v) is |u − v|
1 and | y1 −y2| ≤ 1. The weight of an edge {(x1, y1).
(b) the weight of the edge (u, v) is u + v [1996]
Solution: (x2, y2)} is ( x1 − x2 ) 2 + ( y1 − y2 ) 2 .
(a)

Unit 6 _Chapter 3 FMQ.indd 30 11/19/2015 10:43:39 AM


Chapter 3 Greedy Method | 6.31

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

Unit 6 _Chapter 3 FMQ.indd 31 11/19/2015 10:43:43 AM


Chapter 4
Dynamic Programming

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

Unit 6 _Chapter 4.indd 32 11/19/2015 10:46:36 AM


Chapter 4 Dynamic Programming | 6.33

x[i − −−−l] = y[ j − l] Solution: (c)


= expr2, if i, j > 0 and Hence, the correct option is (c).
x[i − 1] ≠ y[ j − 1]
4. Consider the following C programme that attempts
Which one of the following options is correct?
to locate an element x in an array Y[ ] using binary
(a) expr1 ≡ l(i − lj) + l
search. [2008]
(b) expr2 ≡ l(i, j − l)
(c) expr2 ≡ max (l(i − 1, j), l(i, j − l)) The programme is enoreneous
(d) expr2 ≡ max (l(i − l, j − 1), l(i, j))
Using LCS algorithm, in Dynamic programming
we can write = =
expr1 = l + l(i − l j − 1); and
expr2 = max (l (i − 1, j), l (i, j − 1)) = +
= =
Solution: (b) =
Hence, the correct option is (b). −
2. The subset-sum problem is defined as follows.
Given a set of n positive integers, S = {a1, a2, a3,…,
an}, and positive integer W, is there a subset of S
whose elements sum to W ? A dynamic programme
for solving this problem uses a 2-dimensional On which of the following contents of Y and x does
Boolean array, X, with n rows and W + l columns the programme fail?
X[i, j], l ≤ I ≤ n, 0 ≤ j ≤ W, is TRUE if and only if (a) Y is [1 2 3 4 5 6 7 8 9 10] and x < 10
there is a subset of {a1, a2, a3,…,an} whose ele- (b) Y is [1 3 5 7 9 11 13 15 17 19] and x < 1
ments sum to j. [2008] (c) Y is [2 2 2 2 2 2 2 2 2 2 ] and x > 2
Which of the following is valid for 2 ≤ i ≤ n and (d) Y is [2 4 6 8 10 12 14 16 18 20] and 2 < x < 20
ai ≤ j ≤ W? and x is even
(a) X[i, j] = X[i − 1, j] ∨ X[i, j − ai] In option ‘c’ (y[k]! = x and i < j) always, so it goes
(b) X[i, j] = X[i − 1, j] ∨ X[i − j − ai] into infinite loop
(c) X[i, j] = X[i − 1, j] ∧ X[i, j − ai] Solution: (a)
(d) X[i, j] = X[i − 1, j] ∧ X[i − 1, j − ai] Hence, the correct option is (a).
Solution: (b) 5. Consider the following C program that attempts to
Use Principle of optimality locate an element x in an array Y[ ] using binary
Hence, the correct option is (b). search. [2008]
3. The subset-sum problem is defined as follows. The program is enoreneous
Given a set of n positive integers, S = {a1, a2, a3,…,
an}, and positive integer W, is there a subset of S
whose elements sum to W? A dynamic programme = =
for solving this problem uses a 2-dimensional
Boolean array, X, with n rows and W + l columns = +
X[i, j], l ≤ I ≤ n,0 ≤ j ≤ W, is TRUE if and only if = =
there is a subset of {a1, a2, a3,…,an} whose ele- =
ments sum to j. [2008] −
Which entry of the array X, if TRUE, implies that
there is a subset whose elements sum to W?
(a) X[l, w]
(b) X[n, 0]
(c) X[n, W] The correction needed in the program to make it
(d) X[n − l, n] work properly is

Unit 6 _Chapter 4.indd 33 11/19/2015 10:46:36 AM


6.34 | Design and Analysis of Algorithms

(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

15 62 root of left root of right


subtree subtree
5 20 58 91

3 8 37 60

24
Hence, the correct option is (b).

Unit 6 _Chapter 4.indd 34 11/19/2015 10:46:39 AM


Chapter 3 Dynamic Programming | 6.35

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:


Φ Φ



Time complexity is O (n3)

Unit 6 _Chapter 4 (FMQ).indd 35 11/19/2015 10:46:16 AM


Chapter 5
P and NP Concepts

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

Unit 6_Chapter 5.indd 36 11/19/2015 10:52:25 AM


Chapter 5 P and NP Concepts | 6.37

Solution: (a) 6. Which of the following statements are TRUE?


[2013]
After 1. The problem of determining whether there exists a
10
Step-1 Inserting 1 10 cycle in an undirected graph is in P.
8 5 2. The problem of determining whether there exists a
8 5 cycle in an undirected graph in NP.
3 2 3. If a problem A is NP-complete, there exit a
3 2 1 non-deterministic polynomial time algorithm to
solve A.
(a) 1, 2 and 3
10 (b) 1 and 2 only
(c) 2 and 3 only
8 5 (d) 1 and 3 only

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

Unit 6_Chapter 5.indd 37 11/19/2015 10:52:26 AM


6.38 | Design and Analysis of Algorithms

Solution: (c) (a) Q solves the subset-sum problem in polyno-


For SAT problem, 1-SAT and 2-SAT are consid- mial time when the input is encoded in unary
ered to be in P from 3-SAT onwards, it is treated (b) Q solves the subset-sum problem in polyno-
to be Hard. mial time when the input is encoded in binary
3-SAT is NP-Complete. So it is NP, NP-Hard, and (c) The subset sum problem belongs to the class
NP-complete. NP
2-SAT is solvable in poly-time. So it is P, NP, and
(d) The subset sum problem is NP-Hard
CoNP.
Hence, the correct option is (c). Solution: (b)
10. Ram and Shyam have been asked to show that a Sum of subsets problem is NP-Hard and it also
certain problem Π is NP-complete. Ram shows a belongs to the class of NP. It may have linear
polynomial time reduction from the 3-SAT prob- time algorithm when the I/P is encoded in unary
lem to Π and Shyam shows a polynomial time system.
reduction from Π to 3-SAT. Which of the follow- 3. Let SHAM3 be the problem of finding a Hamiltonian
ing can be inferred from these reductions? cycle in a graph G = (V, E) with |V| divisible by
[2003] 3 and DHAM3 be the problem of determining if
(a) Π is NP-Hard but not NP-complete a Hamiltonian cycle exists in such graphs. Which
(b) Π is in NP, but is not NP-complete one of the following is true? [2006]
(c) Π is NP-complete (a) Both DHAM3 and SHAM3 are NP-Hard
(d) Π is neither NP-Hard, nor in NP
(b) SHAM3 is NP-Hard, but DHAM3 is not
Solution: (a) (c) DHAM3 is NP-Hard, but SHAM3 is not
For a problem to be NP-complete, Π should be-
(d) Neither DHAM3 nor SHAM3 is NP-Hard
long to the class NP.
Hence, the correct option is (a). Solution: (a)
Hence, the correct option is (a).
twO-marks QuestiOns 4. Consider three decision problems P1, P2 and P3.
It is known that P1 is decidable and P2 is undecid-
1. Suppose we have a balanced binary search tree T able. Which one of the following is TRUE?
holding n numbers. We are given two numbers L [2005]
and H and wish to sum up all the numbers in T (a) P3 is decidable if P1 is reducible to P3
that lie between L and H. Suppose there are m such (b) P3 is undecidable if P3 is reducible to P2
numbers in T. If the tightest upper bound on the
time to compute the sum is O(na logb n + mc logd (c) P3 is undecidable if P2 is reducible to P3
n), the value of a + 10b +100c + 1000d is_______. (d) P3 is decidable if P3 is reducible to P2’s com-
[2014] plement

Solution: 110 Solution: (b)


The total time required to perform given task is Using the concept of polynomial time reduction
O(log n + m) so substitute a = 0, b = 1, c = 1 and Hence, the correct option is (b).
d=0
Therefore, a+ 10b + 100c +1000d = 110 5. Which of the following problems is not NP-Hard?
[1992]
2. The subset-sum problem is defined as follows: (a) Hamiltonian circuit problem
Given a set S of n positive integers and a positive
0
integer W, determine whether there is a subset of S (b) The Knapsack problem
whose elements sum to W. An algorithm Q solves 1
this problem in O (nW) time. Which of the follow- (c) Finding bi-connected components of a graph
ing statements is false? [2008] (d) The graph colouring problem

Unit 6_Chapter 5.indd 38 11/19/2015 10:52:27 AM


Chapter 5 P and NP Concepts | 6.39

Solution: (c) mial time complexity algorithm, However finding bi-


0 connected components of a graph is a problem in the
Hamiltonian circuit, Knapsack and graph colouring
1 class of ‘p’.
are also hard problems as they do not have a polyno- Hence, the correct option is (c).

Unit 6_Chapter 5.indd 39 11/19/2015 10:52:28 AM


Chapter 6
Optimal Binary
Search Tree

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

Unit 6_Chapter 6.indd 40 11/19/2015 10:53:47 AM


Chapter 6 Optimal Binary Search Tree | 6.41

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

3. A programme takes as input a balanced binary 40 Not 60


search tree with n leaf-nodes and computes the Possible possible
43 43
value of a function g(x) for each node x. If the cost
of computing g(x) is min (number of leaf-nodes
in left-subtree of x, number of leaf-nodes in right- (c) (d)
10 81
subtree of x) then the worst-case time complexity
of the programme is [2004] 61
65
(a) Θ(n) (b) Θ(nlogn)
(c) Θ(n2) (d) Θ(n2logn) 52
31

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

Unit 6_Chapter 6.indd 41 11/19/2015 10:53:55 AM


Chapter 7
Miscellaneous Topics

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)

Unit 6 _Chapter 7.indd 42 11/19/2015 10:47:03 AM


Chapter 7 Miscellaneous Topics | 6.43

25 Hence, the correct option is (c).


7. Consider the DAG with V = {1, 2, 3, 4, 5, 6} is
14 16
shown below. Which of the following is NOT a
13 10 8 12 topological ordering?
After deleting (25) [2007]
16 14 2 5
After
12 deleting (16)
14 13 12
1 4
13 10 8 10 8
6
The height of a Max Heap is Θ (log n). While in- 3
sertion, we need to traverse from leaf element to
(a) 1 2 3 4 5 6
root (in worst). If we perform binary search to
(b) 1 3 2 4 5 6
find the correct position then we need to do Θ (log
(c) 1 3 2 4 6 5
log n) comparisons. In reality, it is not possible to
(d) 3 2 4 1 6 5
perform binary search on elements from leaf to
root as they are not in sequence. Solution: (d)
Hence, the correct option is (d). Topological sort/ordering starts with that vertex
which does not have any precedence. In the given
5. The most efficient algorithm for finding the num- graph, vertex ‘3’ has a precedence from vertex ‘1’
ber of connected components in an undirected So, it is incorrect.
graph on n vertices and m edges has time complex- Hence, the correct option is (d).
ity [2008]
8. Which of the following sorting algorithms has the
(a) Θ(n)
lowest worst case complexity?
(b) Θ(m)
[2007]
(c) Θ(m + n)
(a) Merge sort
(d) Θ(mn)
(b) Bubble sort
Solution: (c) (c) Quick sort
This is the case when the graph is represented by (d) Selection sort
cost Adjacency matrix. Solution: (a)
Hence, the correct option is (c). Merge sort takes a time of O(n log n) in all cases of
6. The Breadth-first search algorithm has been imple- input. Whereas other sorting techniques have com-
mented using the queue data structure. One possible plexity of O(n2) in worst case.
order of visiting the nodes of the following graph Hence, the correct option is (a).
is [2008] 9. In a binary max heap containing n numbers, the
(a) MNOPQR smallest element can be found in time
(b) NQMPOR [2006]
(c) QMNPRO (a) Θ(n)
(d) QMNPOR (b) Θ(log n)
(c) Θ(log log n)
M N O
(d) Θ(l)
Solution: (a)
Smallest element lie at the leaf level which has
R Q P
n
roughly elements that would require number
Solution: (c) 2
The remaining choices violates the FIFO discipline ofcomparison and number of elements.
of the queue and hence are not valid BFS traversals. Hence, the correct option is (a).

Unit 6 _Chapter 7.indd 43 11/19/2015 10:47:07 AM


6.44 | Design and Analysis of Algorithms

10. Which one of the following in place sorting algo- O(n2)


rithms needs the minimum number of swaps? Hence, the correct option is (c).
[2006]
13. Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are
(a) Quick sort
inserted in that order into an initially empty binary
(b) Insertion sort
search tree. The binary search tree uses the usual
(c) Selection sort
ordering on natural numbers. What is the in-order
(d) Heap sort
traversal sequence of the resultant tree? [2003]
Solution: (c) (a) 7 5 1 0 3 2 4 6 8 9
In selection sort, each iteration takes one swap in (b) 0 2 4 3 1 6 5 9 8 7
the worst case. Hence it requires O(n) swaps in the (c) 0 1 2 3 4 5 6 7 8 9
worst case. (d) 9 8 6 4 2 3 0 1 5 7
Hence, the correct option is (c).
Solution: (c)
11. An element in an array X is called a leader if it is In-order traversal when carried out on Binary
greater than all elements to the right of it in X. The Search Tree, results in a sorted list.
best algorithm to find all leaders in an array Hence, the correct option is (c).
[2006]
(a) Solves it in linear time using a left to right pass 14. Consider the following graph
of the array
(b) Solves it in linear time using a right to left pass a
of the array e b
(c) Solves it using divide and conquer in time 9(n f
log n) h
(d) Solves it in time Θ(n2)
g
Solution: (b)
Algorithm to determine leaders in an array: int Among the following sequences
max = a[n]
I. a b e g h f
← II. a b f e h g
III. a b f h g e
IV. a f g h b e
Which are depth-first traversals of the above
graph? [2003]
(a) I, II and IV only
(b) I and V only
While scanning the array from right to left remem- (c) II, III and IV only
ber the greatest element seen so far and compare (d) I, III and IV only
it with the current element to test for leadership. Solution: (d)
Hence, the correct option is (b). a, b, f, e, h, g is not possible as one cannot visit ‘e’
12. The tightest lower bound on the number of com- after ‘f ’
parisons, m the worst case, for comparison based Hence, the correct option is (d).
sorting is of the order of [2004] 15. In a heap with n-elements with the smallest ele-
(a) n ment at the root, the 7th smallest element can be
(b) n2 found in time [2003]
(c) n log n (a) Θ(n log n) (b) Θ(n)
(d) n log2n (c) Θ(logn) (d) Θ(l)
Solution: (c) Solution: (c)
In comparison based algorithm, tightest lower In-order to find 7th smallest element, we have to
bound is O(n log n) and tightest upper bound if perform ‘7’ deletion operation so it takes O(7

Unit 6 _Chapter 7.indd 44 11/19/2015 10:47:08 AM


Chapter 7 Miscellaneous Topics | 6.45

logn) = O(logn) Selection sort – O (n2)


Hence, the correct option is (c). Insertion sort – O (n) (or) O (n2)
16. Consider any array representation of an n element Merge sort – O (nlogn)
binary heap where the elements are stored from Hence, the correct option is (b).
index 1 to index n of the array. For the element 20. The correct matching for the following pairs is
stored at index i of the array (i < = n), the index of (a) All pairs shortest paths
the parent is [2001] (b) Quick Sort
(c) Minimum weight spanning tree
i (d) Connected Components
(a) i − l (b)  
2 (1) Greedy
(2) Depth-first search
i i + l 
(c)   (d)   (3) Dynamic Programming
2  2  (4) Divide and Conquer [1997]
Solution: (b) (a) A–2, B–4, C–1,D–3
In the array representation of binary tree, the par- (b) A–3, B–4, C–1, D–2
i (c) A–3, B–4, C–2, D–1
ent is at location [ ], whereas left child is at 2i
2 (d) A–4, B–1, C–2, D–3
and right child at 2i + l. Solution: (b)
Hence, the correct option is (b). Hence, the correct option is (b).
17. Suppose we want to arrange the n numbers stored
in any array such that all negative values occur
before all positive ones. Minimum number of twO-marks QuestiOns
exchanges required in the worst case is [1999]
(a) n − l (b) n 1. We have a binary heap on n-elements and wish to
(c) n + 1 (d) None insert n more elements (not necessarily one after
another) into this heap. The total time required for
Solution: (a)
this is [2008]
Worst case input is when the negative number oc-
(a) Θ(log n)
cur at the end of positive number’s minimum num-
(b) Θ(n)
ber of comparisons in such a case is (n − 1)
(c) Θ(n log n)
Hence, the correct option is (a).
(d) Θ(n2)
18. The number of articulation points of the following
Solution: (b)
graph is [1999]
Procedure Heapify with adjust would require
(a) 0 (b) 1 (c) 2 (d) 3
time of O (n) for n-elements, now with addition
Solution: (d) n-elements, total being ‘2n’ would still be order
Nodes 2, 3, 5 are the Articulation points. of O (n). We can reduce the problem to building
Hence, the correct option is (d). Heap for 2n elements. Time complexity for build-
19. Give the correct matching for the following pairs: ing heap is O (n).
(a) O (log n) (P) Selection Hence, the correct option is (b).
(b) O (n) (Q) Insertion sort 2. In the following C function, let n >= m.
(c) O (n log n) (R) Binary search
(d) O (n2) (S) Merge sort [1998]
(a) A-RB-PC-QD-S
(b) A-RB-QC-SD-P
(c) A-PB-RC-SD-Q
(d) A-PB-SC-RD-Q
Solution: (b) How many recursive calls are made by this func-
Binary search – O (logn) tion? [2007]

Unit 6 _Chapter 7.indd 45 11/19/2015 10:47:11 AM


6.46 | Design and Analysis of Algorithms

(a) Θ(log2n) (d) There must exist a cycle in G containing u and


(b) Ω(n) all its neighbours in G.
(c) Θ(log2 log2 n) Solution: (d)
(d) Θ( n ) Hence, the correct option is (d).
Solution: (c) 5. Given two arrays of numbers a1,…an ,…, and bi,…
Hence, the correct option is (c). bn where each number is 0 or 1, the fastest algo-
3. Consider the process of inserting an element into rithm to find the largest span (i, j) such that ai + ai
a Max Heap, where the Max Heap is represented + i… aj = bi + bi + i… bj or report that there is not
by an array. Suppose we perform a binary search such span, [2006]
on the path from the new leaf to the root to find the (a) Takes O(3n) and Ω(2n) time of hashing is per-
position for the newly inserted element, the num- mitted
ber of comparisons performed is: [2007] (b) Takes O(n3) and Ω (n2.5) time in the key com-
(a) Θ(log2 n) parison model
(b) Θ(log2 log2 n) (c) Takes Θ (n) time and space
(c) Θ(n) (d) Takes O(Vn) time only if the sum of the 2n ele-
(d) Θ(n log2 n) ments is an even number
Solution: (b) Solution: (c)
Binary search to be applied along the path which Hence, the correct option is (c).
has log n elements.
6. A 3-ary max heap is like a binary max heap, but
instead of 2 children, nodes have 3 children. A
1000
3-heap can be represented by an array as follows:
root is stored in the first location, a [0], nodes in
logn
80 90 next level, from left to right, is stored from a[l]
[3]. The nodes from the second level of the tree
65 10 20 35
from the left to right are stored from a[4] location
onward. An item x can be inserted into a 3-ary
heap containing n items by placing x in the loca-
x tion a[n] and pushing it up the tree to satisfy the
heap property. [2006]
The height of a Max Heap is Θ(logn). While inser- Which one of the following is a valid sequence of
tion, we need to traverse from leaf element to root elements in an array representing 3-ary max heap?
(in worst). If we perform binary search for finding (a) 1, 3, 5, 6, 8, 9
the correct position then we need to do Θ(log logn) (b) 9, 6, 3, 1, 8, 5
comparisons. In reality, it is not possible to per- (c) 9, 3, 6, 8, 5, 1
form binary search on elements from leaf to root (d) 9, 5, 6, 8, 3, 1
as they are not in sequence. Solution: (d)
4. Let T be a depth-first search tree in an undirected 1
graph G. Vertices u and v are leaves of this tree
T. The degrees of both u and v in G are at least 2. 3 5 6
Which one of the following statements is true?
[2006] 8 9
(a) There must exist a vertex w adjacent to both u Tree for option (a) ‘1’ in at but not possible
and v in G 9
(b) There must exist a vertex w whose removal
disconnects u and v in G 6 3 1
(c) There must exist a cycle in G containing u
and v 8 5

Unit 6 _Chapter 7.indd 46 11/19/2015 10:47:14 AM


Chapter 7 Miscellaneous Topics | 6.47

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

5 1 In the array it is: 10, 7, 9, 8, 3, 1, 5, 2, 6, 4


Tree for option (c) ‘5’ is greater than ‘3’ and hence
1
not Possible Inserting ‘10’

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

Unit 6 _Chapter 7.indd 47 11/19/2015 10:47:21 AM


6.48 | Design and Analysis of Algorithms

(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

Unit 6 _Chapter 7.indd 48 11/19/2015 10:47:26 AM


Chapter 7 Miscellaneous Topics | 6.49

89 18. Following algorithm(s) can be used to sort n inte-


gers in the range [1…n3] in 0(n) time [1992]
19 40
(a) Heap sort
15 12 10 2
(b) Quick sort
(c) Merge sort
5 7 11 6 9 70 (d) Radix sort
Hence, the correct option is (c). Solution: (d)
16. The average number of key comparisons done on Radix Sort is a mechanical sorting technique. Re-
a successful sequential search in list of length n is maining all are comparison based sorting whose
[1996] lower bound complexity is 0(n log n)
n −1 Hence, the correct option is (d).
(a) log n (b)
2 19. The minimum number of comparisons required to
sort five elements is [1991]
n n +1
(c) (d) Solution:
2 2
Minimum may be four, using bubble sort (or) se-
Solution: (d) lection sort (or) insertion sort
If x is found at loc ‘1’ → 1 comparison 20. Match the pairs in the following: [1990]
x is found at loc ‘2’ → 2 comparison
x is found at loc ‘3’ → 3 comparison List I List II
x is found at loc ‘n’ → ‘n’ comparison
(a) Straseen’s matrix (p) Greedy method
n( n +1) multiplication
Total comparison =
2 algorithm
n( n + 1) (b) Kruskal’s mini- (q) Dynamic
2 mum spanning tree programming
Therefore average = algorithm
n
Hence, the correct option is (c). (c) Biconnected com- (r) Divide and
17. Which one of the following statements is false? ponents algorithm Conquer
[1994] (d) Floyd’s shortest (s) Depth-first search
(a) Optimal binary search tree construction can be path algorithm
performed efficiently using dynamic program-
ming. Solution: a–r, b–p, c–s, d–q
(b) Breadth-first search cannot be used to find 21. Match the pairs in the following [1990]
connected components of a graph.
(c) Given the prefix and postfix walks over a bi- List I List II
nary tree, the binary tree cannot be uniquely (a) Heap construction (p) O(n log 10n)
constructed.
(b) Constructing hash table (q) O(n)
(d) Depth-first search can be used to find connect-
with linear probing
ed components of a graph.
(c) AVL Tree construction (r) O(n2)
Solution: (b)
Breadth-first search can be used to find connected (d) Digital tree construction (s) O(n log2 n)
components of a graph.
Hence, the correct option is (b). Solution: a–q, b–r, c–s, d–p

Unit 6 _Chapter 7.indd 49 11/19/2015 10:47:30 AM


6.50 | Design and Analysis of Algorithms

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;

3. An array A contains n integers in non-decreasing


order, A[1] ≤ A [2] ≤…≤ A[n]. Describe, using
− < = −
Pascal-like pseudo code, a linear time algorithm to
= −
find i, j such that A[i] + A[ j] = a given integer M, if
= +
such i, j exist. [1994]
+
Solution:
1. i = l;
[1997]
2. j = n;
Solution: 3. if [(A [i]+ A[ j]) = m] then print (i, j); exit
Line # 3: sum = A [ j] 4. if [(A [i] +A[ j] < m] then i = i + l;
Line # 6: if (sum < M) goto step 3; else
Line # 11: sum = sum + A[ j] j = j − 1; go to step 3;
2. A two dimensional array A [l − n] [1 − n] of inte- The complexity of the above algorithm is O(n);
gers is partially sorted if 4. The following Pascal programme segments finds
∀i j ε[1− n −l] A[i] [ j] < A[i] [ j + 1] and A[i] [ j] the largest number in a two dimensional integer
< A [i + 1] [ j] array A [0…n − l, 0…n − 1] using a single loop.
(a) The smallest item in the array is at A[i] [ j] Fill up the boxes to complete the programme and
where i = − and j = −(1) write against A, B, C and D in your answer book.
(b) The smallest item is deleted. Complete the fol- Assume that max is a variable to store the largest
lowing O(n) procedure to insert item x (which value and i, j are the indices to the array.
is guaranteed to be smaller than any item in the = A = =
last row or column) still keeping A partially B
sorted. =

Unit 6 _Chapter 7 FMQ.indd 50 11/19/2015 10:54:33 AM


Chapter 7 Miscellaneous Topics | 6.51

C = + Solution: an = an−1 + n, n > l


= = c, n = l, c is a const.
=D
Using back-substitution, yields O(n2)
6. Consider the function F(n) for which the pseudo
[1993] code is given below:
Solution: max = Φ Function F(n) begin
While (i < n ) F1 ← 1
if (j < n − l) If (n = 1) then F ← 3 else
i=i+l For i = 1 to n do begin
5. Consider the recursive algorithm given below: C ← 0 For
j = 1 to F(n − 1) do begin C ← C + 1 end
F1 = F1 *C end
+
F = F1 end
= + [n is a positive integer greater than zero]
+ =
(a) Derive a recurrence relation for F(n)
(b) Solve the recurrence relation for a closed form
solutions of F(n). [1992]

Let n be the number of times the ‘if…then….’ Solution:


Statement gets executed when the algorithm is run T(n) = 3, n = 1
with value n. Set up the recurrence relation by de- T(n) = n + T(n − 1)K,
fining an in terms of an − 1 Solve for an. [1993] n > 1; ‘k’ is a constant.

Unit 6 _Chapter 7 FMQ.indd 51 11/19/2015 10:54:34 AM


This page is intentionally left blank.

Unit 6 _Chapter 7 FMQ.indd 52 11/19/2015 10:54:34 AM


Unit Vii
Data structure

chapter 1: Array 7.3


chapter 2: Stacks and Queues 7.6
chapter 3: Linked List 7.14
chapter 4: Trees 7.18
chapter 5: Graphs 7.36
chapter 6: Hashing 7.40

Unit 7 _Chapter 1.indd 1 11/19/2015 12:05:28 PM


Unit 7 _Chapter 1.indd 2
exam analysis
Exam Year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14

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

Stacks and Queues 0 0 0 0 1 0 0 3 1 2 2 2 0 1 0 0 1 3 1 2 3 0 0 0 0 1 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]

Unit 7 _Chapter 1.indd 3 11/19/2015 12:05:30 PM


7.4 | Data Structure

(a) Rotates s left by k positions


(b) Leaves a unchanged
(c) Reverse all elements of s
(d) None of the above The value returned by the function My X is the
Solution: (a) [2014]
Position
(a) Maximum possible sum of elements in any
sub-array of array E
1 2 3 . . . . . . K K + 1. . . . . . . . . . . . n
(b) Maximum element in any sub-array of array E
1 . . . . . . . . K K + 1. . . . . . . . . . . n (c) Sum of the maximum elements in all possible
sub-array of array E.
K Indicates k th element (d) The sum of all the elements in the array E.
Solution: (a)
After reverse (s,1, k):
Say Y will be sum of all elements in array and B
1 2 . . . . . . . . K K + 1. . . . . . . . . . . . n
and Z is sum of all sub-array elements Z > Y if ar-
K . . . . . . . . K K + 1. . . . . . . . . . . n ray contains NEGATIVE number.
After reverse (s,k+1, n):
So, then we are changing Y = Z.
So, maximum sum in sub-array is returned.
1 2 . . . . . . . . K K + 1. . . . . . . . . . . . n Hence, the correct option is (a).
K ........ 1 n ........... n
2. Two matrices M1 and M2 are to be stored in arrays
After reverse (s,1, n): A and B respectively. Each array can be stored
1 2. . . . . . . . . . . . . . . . . . . . . . . . . . .n either in row-major order in contiguous memory
K+1 . . . . . . . n 1 . . . . . . . . . . . . K locations. The time complexity of an algorithm to
compute M1 × M2 will be [2004]
Rotated left by k positions (a) Best if A is in row-major, and B is in column-
Hence, the correct option is (a). major order
(b) Best if both are in row-major order
(c) Best if both are in column-major order
twO-mark QuestiOns (d) Independent of the storage scheme
Solution: (d)
1. Consider the following C function in which size is Algorithm for computing M1 × M2
the number of elements in the array E: Assume M1 is stored in row-major and M2 is stored
in column major.

Algorithm for computing M1 × M2 ,


When both M1, M2 are stored in row major order:
Replace step 6 of above algorithm by

Unit 7 _Chapter 1.indd 4 11/19/2015 12:05:32 PM


Chapter 1 Array | 7.5

R[ j + (i − 1)*r] = A[k + (i − 1)*q]*B[r*(k − 1) + j]; 4. In a compact single dimensional representation


In both a and b, same number of multiplications for lower triangular matrices (i.e. all the elements
and additions are required and similarly for choice above the diagonal are zero) of size n × n, non-
(c) also, so these are obviously independent of zero elements (i.e. elements of the lower triangle)
storage scheme. of each row are stored one after another, starting
Hence, the correct option is (d). from the first row, the index of the (i, j)th elements
3. Let A be a two dimensional array declared as of the lower triangular matrix in this new represen-
follows: tation is [1994]
A: array [1…10][1…15] of integer; (a) i + j
Assuming that each integer takes one memory (b) i + j − 1
locations the array is stored in row-major order and
(c)
( j − 1) + i (i − 1)
the first element of the array is stored at location
2
100, what is the address of the element A[i][j]?
[1998] i + j ( j − 1)
(d)
(a) 15i + j + 84 (b) 15j + i + 84 2
(c) 10i + j + 89 (d) 10j + i + 89 Solution: (c)
Solution: (b) RMO (Row Major Order)
RMO = L0 + (i − 1)r2 + ( j − 1) = L0 + the number of elements in (i − 1) rows
= 100 + (i − 1)15 + ( j − 1) + one dimensional elements
= 100 + 15i + 15 + j − 1 = L0 + (1 + 2 + 3… + i − 1) + ( j − 1)
= 15i + j + 84 = L0 + i(i − 1)/2 + ( j − 1)
Hence, the correct option is (b). Hence, the correct option is (c).

Unit 7 _Chapter 1.indd 5 11/19/2015 12:05:33 PM


Chapter 2
Stacks and Queues

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

Unit 7 _Chapter 2.indd 6 11/19/2015 12:13:05 PM


Chapter 2 Stacks and Queues | 7.7

(a) if stack is empty, push the symbol on to Solution: (c)


stack Three operations of Stack are:
(b) else, let K be on the stack value of stack top → ENQUEUE
and 1 be incoming value of read symbol → PUSH
If K > 1, pop stack and print it. Push new symbol. → POP
If K < 1, push new symbol
For ENQUEUE → procedure is
Hence, the correct option is (a).
1) Reverse the stack
4. Consider the following statements: 2) Push the element
I. First-in-first-out types of computations are 3) Reverse the stack again
efficiently supported by STACKS.
This converses stack to QUEUE => 3 instructions.
II. Implementing LISTS on linked list is more
FOR DEQUEUE,
efficient than implementing LISTS on an array
Just POP → 1 instruction.
for almost all the basic LIST operations.
Hence, the correct option is (c).
III. Implementing QUEUES on a circular array is
more efficient than implementing QUEUES 2. Suppose a circular queue of capacity (n − 1) ele-
on a linear array with two indices. ments is implemented with an array of n elements.
IV. Last-in-first-out type of computations are Assume that the insertion and deletion operations
efficiently supported by QUEUES. are carried out using REAR and FRONT as array
Which of the following is correct? [1996] index variables, respectively, initially , REAR =
(a) (i) and (iii) are true FRONT = 0. The condition to detect queue full
(b) (i) and (ii) are true and queue empty are [2012]
(c) (iii) and (iv) are true (a) full: (REAR + 1)
(d) (ii) and (iv) are true mod n == FRONT
Solution: (a) empty: REAR == FRONT
Wrong statements: (b) full: (REAR + 1)
(i) FALSE (ii) TRUE mod n == FRONT
(iii) TRUE (iv) FALSE empty: (FRONT + 1)
Hence, the correct option is (a). mod n = REAR
(c) full: REAR == FRONT
empty: (REAR + 1)
twO-marks QuestiOns mod n == FRONT
(d) full: (FRONT + 1)
1. Suppose a stack implementation supports an Mod n == REAR
instruction REVERSE, which reverses the order empty: REAR == FRONT
of elements on the stack, in addition to the PUSH Solution: (a)
and POP instructions, which one of the following 3. Consider the following C program:
statements is true with respect to this modified
stack? [2014]
(a) A queue cannot be implemented using this
stack
(b) A queue can be implemented where ENQUEUE
takes a single instruction and DEQUEUE
takes a sequence of two instructions.
(c) A queue can be implemented where ENQUEUE
takes a sequence of three instructions and
DEQUEUE takes a single instruction.
(d) A queue can be implemented where both
ENQUEUE and DEQUEUE takes a single in-
struction each.

Unit 7 _Chapter 2.indd 7 11/19/2015 12:13:05 PM


7.8 | Data Structure

(c) Delete the element at front of the queue Q and


insert it at the rear keeping the other elements
in the same order
(d) Empties the queue Q
Solution: (b)
In every invocation the deleted element is stored in
‘i’ and when the queue becomes empty therefore
the given function f reverses the order of the ele-
ments in the queue Q. The last deleted element will
be inserted first and the procedure goes on because
the insert function calls will be executed from the
What is the output of the program for the following last invoked function.
input? Hence, the correct option is (b).
52*332+*+ [2007]
5. The following postfix expression with single digit
(a) 15 (b) 25 (c) 30 (d) 150 operand is evaluated using stack:
Solution: (b) 8236/23*+51*−
Note that ^ is the exponentiation operator. The top
2
two elements of the stack after the first * is evalu-
3 3 5 ated are: [2007]
2 3 3 3 3 15 (a) 6, 1 (b) 5, 7 (c) 3, 2 (d) 1, 5
5 5 10 10 10 10 10 10 25
Solution: (a)
5 2 ∗ 3 3 2 + ∗ +

Hence, the correct option is (b). 3 3


2 2 8 2 2 6
4. Suppose you are given an implementation of a 8 8 8 8 1 1 1 1
queue of integers. The operation that can be per- 8 2 3 ∧ / 2 3 ∗
formed on the queue are: 2∧3 8×8 2×3
=8 =8
(i) is Empty(Q) – return true if the queue is emp-
ty, false otherwise From the above figure the top two elements are 6, 1.
(ii) delete(Q) – deletes the element at front of the Hence, the correct option is (a).
queue and returns its value. æmö
6. The following function computes the value ç ÷
(iii) insert(Q, i) – inserts the integer I at the rear of ènø
the queue. correctly for all legal value m and n (m ≥ 1, n ≥ 0
Consider the following function: and m > n).

In the above function, which of the following is the


correct expression for E? [2006]
What operation is performed by the above function f ? (a) (n==0) || (m==1)
[2007] (b) (n==0) && (m==1)
(a) Leave the queue unchanged (c) (n==0) || (m==n)
(b) Reverse the order of the elements in the queue Q (d) (n==0) && (m==n)

Unit 7 _Chapter 2.indd 8 11/19/2015 12:13:07 PM


Chapter 2 Stacks and Queues | 7.9

Solution: (c) n + m i.e.; y <= n + m


m
Cn = 1, whenever n = 0 or m = n When the ‘m’ delete operations are completed be-
So the if conditional expression has to be fore the m + 1th insertion operation is to be per-
(n == 0) || (m == n) formed, the number of pop() will be minimum.
Hence, the correct option is (c). → Any permutation of m insert operations with m de-
7. As implemented of a queue Q, using stack S1 and lete operations will give us m + m => 2m pop() only.
S2 is given below: Hence 2m <= y <= n + m
→ For m delete operations the minimum number
of push () => m, when the m + 1th insert will be
done only after mth delete.
For n insert operation, number of push() = n (const)
So minimum number of push = n + m
maximum number of push = n + n
hence, n + m <= x <= n + m
Hence, the correct option is (a).
8. A program attempts to generate as many permuta-
tions as possible of the string ‘abcd’ by pushing the
characters a,b,c,d in the same order onto a stack,
but may pop off the top character at any time.
Which one of the following strings CANNOT be
generated using this program? [2004]
(a) abcd (b) dcba
(c) cbad (d) cabd
Let n insert and m(≤n) delete operation performed Solution: (d)
in an arbitrary order on an queue Q. let x and y be Push the characters on to the stack in the order ‘a’,
the number of push and pop operations performed ‘b’, ‘c’, ‘d’.
respectively the process. Which one of the follow- Pop operation can be performed at any time be-
ing true for all m and n? [2006] tween those push operations.
(a) n + m ≤ x < 2n and 2m ≤ y ≤ n + m Choice (a) Choice (b)
(b) n + m ≤ x < 2n and 2m ≤ y ≤ 2n Program to generate abcd: ‘dcba’ program
(c) 2m ≤ x < 2n and 2m ≤ y ≤ n + m Push ‘a’ Push ‘a’
(d) 2m ≤ x < 2n and 2m ≤ y ≤ 2n Pop ‘a’ Push ‘b’
Solution: (a) Push ‘b’ Push ‘c’
Whatever may be the order of deletion operation, Pop ‘b’ Push ‘d’
each insert operation results in only one push() op- Push ‘c’ Pop ‘d’
eration. Pop ‘c’ Pop ‘c’
n insert operations => n push() Push ‘d’ Pop ‘b’
→ the first deletion operation will yield P push(), Pop ‘d’ Pop ‘a’
p + 1 pop() when at the moments queue contains p Choice (c) Choices (d)
elements. ‘cdba’ program Push ‘a’
→ since it is given that m < = n, when we have car- Push ‘a’ Push ‘b’
ried out all ‘n’ insert operation first and then fol- Push ‘b’ Push ‘c’
lowed operations, the maximum number of pop() Push ‘c’ Pop ‘c’
operation will be required. Pop ‘c’ Cannot pop ‘a’ this time.
Then the number of Pop() operation => y. Pop ‘b’
1 delete operation => n + 1 pop() Pop ‘a’
Remaining m − 1 delete operations => m − 1 pop() Push ‘d’
Total => n + m pop() Pop ‘d’
Maximum number of pop() Hence, the correct option is (d).

Unit 7 _Chapter 2.indd 9 11/19/2015 12:13:07 PM


7.10 | Data Structure

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

Unit 7 _Chapter 2.indd 10 11/19/2015 12:13:10 PM


Chapter 2 Stacks and Queues | 7.11

Solution: (b) Push(4)


The postfix expression for the infix expression A + Pop(4) =>3,4
B * (C + D)/F + D * E is ABCD + * F/ + DE * + Push(5)
Hence, the correct option is (b). Pop(5) =>3,4,5
15. which of the following permutations can be Pop(2) =>3,4,5,2,1
obtained in the output (in the same order) using a Pop(1) =>3,4,5,2,1
stack assuming that the input is the sequence 1, 2, Other combinations are not possible.
3, 4, 5 in that order? [1994] Hence, the correct option is (b).
(a) 3, 4, 5, 1, 2 (b) 3, 4, 5, 2, 1 16. The following sequence of operations is performed
(c) 1, 5, 2, 3, 4 (d) 5, 4, 3, 1, 2 on stack:
Solution: (b) PUSH(10), PUSH(20), POP, PUSH(10),
Insertion order of Stack => 1, 2, 3, 4, 5 PUSH(20), POP, POP, POP, PUSH(20), POP
The only possible output sequence 3, 4, 5, 2, 1 The sequence of values popped out is: [1991]
That occurs when (a) 20, 10, 20, 10, 20
Push(1) (b) 20, 20, 10, 10, 20
Push(2) (c) 10, 20, 20, 10, 20
Push(3) (d) 20, 20, 10, 20, 20
Pop(3) =>3 Solution: (b)

Stack Push Push Push Push Stack Push


Pop Pop Pop Pop Pop
operation (10) (20) (10) (20) operation (20)

Stack 10 10 20 10 10 20 10 10 20 10 10 10 Stack 20

20, 20, 20, 20, 20, 20, 20, 20,


Pop list 20 20 20 20, 20 Pop list
10 10, 10 10, 10 10, 10, 10

The sequence of values popped out is 20, 20, 10, 10, 20.

Unit 7 _Chapter 2.indd 11 11/19/2015 12:13:11 PM


7.12 | Data Structure

Five-mark Questions even Odd


Hence S(1) is true Let n = 2
1. The Fibonacci sequence {f1, f2 f3 …….. fn } defined by
the following recurrence
Fn + 2 = fn + 1 + fn, n ≥ 1; f2 = 1; f1 = 1. S(1) is true N=3
Prove by instruction that every third element of the
f4 = f3 + f2
sequence is even. [2000] Odd num S(2) not true

Solution: even Odd


Fibonacci series f5 = f4 + f3 Odd num S(3) not true
1,1,2,3,5,8,13,21,34…….
First two numbers of series are odd numbers Odd even

Odd + odd = even


Say, S(k) is true.
Odd + even = odd fn + 2 = fn + 1 + fn is also an even number and (k + 2)
Even + even = even − 3 = 0 and both fk + 1 and fk are odd.
Now let us see whether S(k + 1) is true.
f1 is odd, f2 is odd, f3 is even. fk + 3 = fk + 2 + fk + 1
fn + 2 = fn + 1 + fn since from S(k), fk + 2 is an even number and fk + 1
Put n = 1 f3 = f2 + f1 is an odd number,
fk + 3 = even + odd = odd
Odd + odd even the next after k + 2 which is a multiple of 3 is k + 5.
And
n=2 f4 = f3 + f2 fk + 5 = fk + 4 + fk + 3
= odd + odd = even
Even + odd odd k + 5 − 3 == 0 because (k + 2) − 3 = 0.
S(k + 3) is also true.
n=3 f5 = f4 + f3
So, By principle of mathematical induction S(n) is
true for all.
odd + even odd n − 3 = 0.
2. Suppose a stack implementation supports addition
to PUSH and POP, an operation REVERSE, which
n=4 f6 = f5 + f4
reverses the order of elements on the stack.
[2000]
odd + odd even
(a) To implement a queue using the above stack
implementation, show how implement EN-
As given, every even number will succeeded by QUEUE using a single operation and DE-
two odd numbers and then be following up by even QUEUE using a sequence of 3 operations.
number. (b) The following postfix expression containing
⇒ every 3rd number in the series is an even num- single digit operands at arithmetic operators +
ber as the same pattern will be repeated hence and *, is evaluated using a stack.
⇒ PROOF 52*34+52**+
Let S(n) be the statement for Show the contents of the stack
fn + 2 = fn + 1 + fn i. After evaluating 5 2 * 3 4 +
is an even number f(n + 2)/3 == 0. ii. After evaluating 5 2 * 3 4 + 5 2
F3 = f2 + f1 = even number iii. At the end of evaluation

Unit 7 _Chapter 2 (FMQ).indd 12 11/19/2015 12:13:54 PM


Chapter 2 Stacks and Queues | 7.13

Solution: the stack. Again in O(n) time this process is being


(a) ENQUEUE (Q, x) done. As in big-oh arithmetic constant factors can
be ignored, the process is carried out in O(n) time.
Storage has to be big enough to temporarily hold
one item.
4. A queue containing n items and an empty stack
S are given. It is required to transfer all the items
from the queue to the stack, so that the items at the
front of the queue is on the top of the stack, and the
order of all other items are preserved. Show how
this can be done in O(n) time using only a con-
stant amount additional storage. Note that the only
(b) operation which can be performed on the queue
i) ii) and stack are delete, insert, Push and Pop. Do not
4 2 assume any implementation of the queue or stack.
2 3 7 5 [1994]
5 10 10 7 Solution:
10 When we do 2n insertion and 2n deletion, this can
Before Before After
reading reading Performing be done,
‘*’ ‘+’ ‘+’
Rear
iii) 10 e Top
e
7 70
d d
10 10 80
c
c
At the end of evaluation b
a b
Front
At the end of evaluation
a
3. Given a queue Q containing n elements transfer Queue Stack
these items on to a stack S(initially empty) so that
front element of Q appear at the top of the stack Start deletion from front and push onto the stack.
and order of all is preserved. Using enque and
deque operation for the queue and push and pop Rear
operations for the stack. Outline an effective O(n) a
a
algorithm to accomplish the above using only a
b b
constant amount of additional storage.
c
Solution: c
d
Assume the elements of queue Q are a1, a2, ….an. e d
Front
Dequeuing and pushing all elements onto the stack
e
will result in a stack with an at top and a1 at the bot- Queue
tom. This is done in O(n) time as for both dequeue Stack
and push constant time per operation is required. Start pop out from top Start deleting from
The queue is empty. By popping and pushing all and insert into queue. front and inser onto
stack.
elements on the queue we will get a1 at the top of

Unit 7 _Chapter 2 (FMQ).indd 13 11/19/2015 12:13:57 PM


Chapter 3
Linked List

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)

Unit 7 _Chapter 3.indd 14 11/19/2015 12:14:48 PM


Chapter 3 Linked List | 7.15

Step (ii) is always performed before step (iii) as if Solution: (b)


we change head first, then we lose track of head Program interchanges values successive numbered
node in the original linked list. nodes respectively, if there are even numbers of
2. The preorder traversal sequence of a binary search nodes in the linked list.
tree is 30,20,10,15,25,23,39,35,42. Which one of Current Values: 1,2,3,4,5,6,7
the following is the post-order traversal sequence After interchange: 2,1,4,3,6,5,7
of the same tree? [2013] 4. The following C function takes a singly-linked list
(a) 10,20,15,23,25,35,42,39,30 of integer as a parameters and rearranges the ele-
(b) 15,10,25,23,20,42,35,39,30 ments of the list. The function is called with the
(c) 15,20,10,23,25,42,35,39,30 list containing the integer 1,2,3,4,5,6,7 in the given
(d) 15,10,23,25,20,35,42,39,30 order. What will be the contents of the list after the
Solution: (d) function completed execution? [2008]
30

20 39

10
25 35 42

15
23

3. The following C function takes a singly linked list


of integers as a parameter and rearrange the ele-
ments of the list. The list is represented as pointer
to a structure. The function is called with the list
containing the integer 1,2,3,4,5,6,7 in the given
order. What will be the contents of the list after the
function completes the execution?
[2008 and 2005]

(a) 1,2,3,4,5,6,7 (b) 2,1,4,3,6,5,7


(c) 1,3,2,5,4,7,6 (d) 2,3,4,5,6,7,1
Solution: (b)
The values of two adjacent nodes values are
swapped.
i. e.; 1,2,3,4,5,6 ; if total no. of nodes are even.
Else last node’s value is unchanged, remaining
nodes values are changed as said above:
Initial List: 1,2,3,4,5,6,7
List after rearrange: 2,1,4,3,6,5,7
The function rearrange() data of every node is ex-
changed with its next node, starting the exchange
of data from the first node itself.
(a) 1,2,3,4,5,6,7 (b) 2,1,4,3,6,5,7 5. A circularly linked list is used to represent a
(c) 1,3,2,5,4,7,6 (d) 2,3,4,5,6,7,1 Queue. A single variable p is used to access the

Unit 7 _Chapter 3.indd 15 11/19/2015 12:14:49 PM


7.16 | Data Structure

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)

Newly created node

(1)
(2)

For a given linked list p, the function f returns 1 if


and only if [2003]
(a) The list is empty or exactly one element
(b) The elements in list are sorted in non-decreasing
order of data value Two pointers are required as shown above.

Unit 7 _Chapter 3.indd 16 11/19/2015 12:14:50 PM


Chapter 3 Linked List | 7.17

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 step 2 1 step


q
d
(ii) After second statement

p i i+1 i+2
q

(iii) After third statement

q In the above algorithm, perform step (1) followed


p
by step (2) when done with traverse till the node
i i+1 i+2 i+3 i+4
with the value dj − 1.

(iv) After fourth statement

p i i+1 i+2 i+3 i+4


q

i cell i + 2 cell i + 1 cell i + 3 cell i + 4 cell

Unit 7 _Chapter 3 (FMQ).indd 17 11/19/2015 12:17:28 PM


Chapter 4
Trees

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

S T U V We get SQPTRWUV by performing in-order traversal


on the above given figure.
Hence, the correct option is (a).
W 2. A max heap is a heap where the value of each par-
ent is greater than or equal to the value of its chil-
The order in which the nodes are visited during an in- dren. Which of the following is a max-heap?
order traversal of tree is [2014] [2011]
(a) SQPTRWUV (b) SQPTUWRV root 10
(c) SQPTWUVR (d) SQPTUWRV
Solution: (a) 6
8
(a)
1 A 3 5 2
4

2 1

root 10
1 B 3 1 C 3

2 2 6
(b) 8

If we take S as left child of Q and apply same concept


4 5 1 2
to U and W.

Unit 7 _Chapter 4.indd 18 11/19/2015 12:16:39 PM


Chapter 4 Trees | 7.19

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.

Unit 7 _Chapter 4.indd 19 11/19/2015 12:16:48 PM


7.20 | Data Structure

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

BST after inserting 10,1,3,5,15,12,16.


Height of BST is 3.
Hence, the correct option is (b).
10. Level order traversal of a rooted tree can be done
by starting from the root and performing [2004]

Unit 7 _Chapter 4.indd 20 11/19/2015 12:16:53 PM


Chapter 4 Trees | 7.21

(a) Pre-order traversal 12. Which of the following statement is false?


(b) Post-order traversal [1998]
(c) Depth First Search (a) A tree with n nodes has (n − 1) edges
(d) Breadth first search (b) A labeled rooted binary tree can be uniquely
Solution: (d) constructed given its post-order and pre-order
traversal results.
2 (c) A complete binary tree with n internal nodes
has (n + 1) leaves.
3 4
(d) The maximum number
5 6 Solution: (c)
A complete binary tree with n internal nodes has
Level order: 2,3,4,5,6 (n + 1) leaves. This statement is false. For example
BFS: 2,3,4,5,6
Pre-order: 2,3,5,6,4
In-order: 5,3,6,2,4
DFS: 2,3,5,6,4
Hence, the correct option is (d).
11. Consider the following nested representation of Internal nodes = 1 Internal nodes = 2
Leaf nodes = 1 Leaf nodes = 2
binary trees: (X Y Z) indicates Y and Z the left and
right subtree, respectively of root node X. Note that
Y and Z may be NULL or further nested. Which of
the following represents a valid binary tree? Statements given in options (a), (b) and (d) are true.
[2000] Hence, the correct option is (c).
(a) (1 2 (4 5 6 7)) 13. In the balanced binary tree in figure given below,
(b) (1((2 3 4) 5 6) 7) how many nodes will become unbalanced when a
(c) (1 (2 3 4 ) (5 6 7)) node is inserted as a child of the node ‘g’ ?
(d) (1( 2 3 NULL) (4 5)) [1996]
Solution: (c) a
In Binary tree , each node has either two or zero
child. b e
(a) For 1 to have only 1 subtree, 2 must be in left
subtree of 1, c d f
Binary tree is not possible with 5,6,7.
g
1 1
(a) 1 (b) 3 (c) 7 (d) 8
2 4,5,6,7 2 4 Solution: (b)
Ans: (b)
5,6,7 2
a
(b) Subtree of subtree cannot be defined. (2,3,4) 2 1
cannot be root. b e
1 1 2 0 0
c d f
2 5 2 4 1
g
3 4 6 7 3 Null 5 0
k
Hence, the correct option is (c).

Unit 7 _Chapter 4.indd 21 11/19/2015 12:16:58 PM


7.22 | Data Structure

Figure Tree with balance factors when a child is Solution: FALSE


inserted to (g). Number of leaves is 3 which is not power of 2.
Unbalanced nodes in the tree = 3. Even though the figure is a binary tree.
The first node which gets unbalanced is c after in-
serting a child node to g. According to AVL tree
properties whenever a node gets unbalanced all the
nodes on the path from first unbalanced node to till
the root also gets unbalanced.
Hence, the correct option is (b).
14. Which of the following sequences denotes the
post-order traversal sequence of the tree of above twO-marks QuestiOns
question? [1996] 1. Consider the expression tree shown. Each leaf rep-
(a) f e g c b d b a resents a numerical value, which can be either 0
(b) g c b d b a f e or 1. Over all possible choices of the value at the
(c) g c b d f e a leaves, the maximum possible value of the expres-
(d) f e d g c b a sion represented by the tree is_____. [2014]
Solution: (c)
Post-order traversal: g c d b f e a +
Hence, the correct option is (c).
15. A binary tree T has n leaf nodes. The number of − +
nodes of degree 2 in T is [1995]
(a) log n (b) n − 1 (c) n (d) 2n
Solution: (b) + − − +

0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1

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

17. If the number of leaves in a tree is not a power of


2, then the tree is not a binary tree is not a binary
tree. [1987]

Unit 7 _Chapter 4.indd 22 11/19/2015 12:17:02 PM


Chapter 4 Trees | 7.23

When the pointer to the root of a tree is passed as


the argument to DoSomething, the value returned
by the function corresponds to the [2014]
(a) Number of internal nodes in the tree Which of the following statements about the func-
(b) Height of the tree tion process. Array is CORRECT? [2014]
(c) Number of nodes without a right sibling of the (a) It will run into an infinite loop when x is not
tree. list A.
(d) Number of leaf nodes in the tree (b) It is an implementation of binary search
(c) It will always find the maximum element in
Solution: (d)
list A.
The root of the original tree is made the root of
(d) It will return −1 even when x is presented in
binary tree, to form binary tree from arbitrary k-ar-
list A.
ray tree. Starting with the root , each leftmost child
in original tree is m. its left child in the binary tree, Solution: (b)
after nearest sibling to the right in the original tree Function BINARY_SEARCH (K, N, X). Given a
is made its right child in the binary tree. vector K, consisting of N elements − ascending
order. This algorithm searches the structure for
a given element whose value is given by X. The
variables LOW, MIDDLE, and HIGH denote the
lower, middle and upper limits of the search inter-
val, respectively. The function returns the index of
the vector element if the successful, and returns 0
otherwise.
----[Initialize]
LOW ← 1
HIGH ← N
Hence, the correct option is (d).
[Perform search]
3. Consider the C function below. Assume that the Repeat thru step 4 while LOW ≤ HIGH
array list A contains n (>0) element sorted in [Obtain index of midpoint of interval]
ascending order MIDDLE ← [(LOW + HIGH)/2]
[Compare]
If X<K[MIDDLE]
then HIGH ← MIDDLE − 1
else if X>K[MIDDLE]
then LOW ← MIDDLE +1
else Write (‘SUCCESFL SEARCH’)
Return (MIDDLE)

Unit 7 _Chapter 4.indd 23 11/19/2015 12:17:04 PM


7.24 | Data Structure

[Unsuccessful search] Solution: (a)


Write (‘UNSUCCESFUL SEARCH’) In Box, B1, (1 + height (n ⇒ right))
Return(0) B2, (1 + Max (h1, h2)
A trace of this algorithm for the sample table Hence, the correct option is (a).
75. 151. 203. 275. 218. 489. 524. 591. 647. and 727 5. We are given a set of n distinct elements and an
Search for 275 Search for 727 unlabeled binary tree with n nodes. In how many
ways can we populate the tree with the given set so
Iteration L H M Iteration L H M
that it becomes a binary search tree? [2011]
1 1 10 5 1 1 10 5 (a) 0 (b) 1 (c) n! (d) 1/n + 1 2nCn
2 1 4 2 2 6 10 8
Solution: (b)
3 3 4 4 3 9 10 9 Particular unlabeled binary tree may be binary tree
4 4 4 4 4 10 10 10 by only one way.
(a) (b) e.g., if a given particular unlabeled tree is

Hence, the correct option is (b). 4


For keys
4. The height of a tree is defined as the number of 1,2,3,4,5,6
the only 1 5
edges on the longest path in the tree. The func-
arrangement is
tion shown in the pseudo code below is invoked as
3 6
height (root) to compute the height of a binary tree
rooted at the tree pointer root. 2

Hence, the correct option is (b).


6. What is the maximum height of any AVL-tree with
7 nodes? Assume that the height of a tree with a
single node is 0. [2009]
(a) 2 (b) 3 (c) 4 (d) 5
Solution: (b)
Ans: (b)
+1

+1 +1

+1
0 0

Max height → 3
−1

The appropriate expressions for the two boxes B1 +1


and B2 are [2012] −1

(a) B1: [1 + height (n ⇒ right)] B2: [1 + max (h1,


0 −1
h2)] 0
(b) B1: [height (n ⇒ right)] B2: [1 + max (h1, h2)]
(c) B1: (height (n ⇒ right)] B2: [max (h1, h2)] 0
(d) B1: [1 + height (n ⇒ right)] B2: [max (h1, h2)]

Unit 7 _Chapter 4.indd 24 11/19/2015 12:17:06 PM


Chapter 4 Trees | 7.25

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

Unit 7 _Chapter 4.indd 25 11/19/2015 12:17:10 PM


7.26 | Data Structure

b c

d e f c

⇒ post order is d e b f g c a The value returned by Get value where pointer to


Hence, the correct option is (a). the root of a binary tree is passed its argument is:
[2007]
12. A complete n-array is a tree in which each node (a) the number of nodes in the tree
has n children or no children. Let I be the number (b) the number of internal nodes in the tree
of internal nodes and L be the number of leaves in (c) the number of leaf nodes in the tree
a complete n-array tree. If L = 41, and I = 10, what (d) the height of the tree
is the value of n? [2007]
Solution: (c)
(a) 3 (b) 4 (c) 5 (d) 6
The number of leaf nodes in the tree will be re-
Solution: (c) turned.
Leaves = 41 # As only the leaf node value will changed to 1.
Internal nodes = 10 = I # As the function is recursive, the child invoked
Given i = 10 function of a node return numbers of leaves in left
Li = 41 subtree and right child invoked function will num-
41 = n + (10 − 1)(n − 1) ber f leaves in right subtree.
41 = 10n − 9 # both will be added and returned ⇒ to number of
n = 5. leaves.
For a tree with node having children or no chil- Hence, the correct option is (c).
dren, following relation holds L = (n + 1) * I + 1,
14. When searching for the key value 60 in binary
where l is the number of leaf nodes and I is the
search tree, nodes containing the values
number of intermediate node. L = 41
10,20,40,50,70,80,90 are traversed not necessar-
I = 10 implies 41
ily in the order given. How many different orders
= 10*(n − 1) + 1
are possible in which the key values can occur on
Hence, the correct option is (c).
search path from the root to the node containing
13. Consider the following C program segment where the value 60? [2007]
CellNode represents a node in a binary tree: (a) 35 (b) 64 (c) 128 (d) 5040
Solution: (b)
90
10
80
20
70

30
60

40
20
50
30

90
40
80
50
70
60

60

Unit 7 _Chapter 4.indd 26 11/19/2015 12:17:14 PM


Chapter 4 Trees | 7.27

Total there are 7 nodes (10,20,40,50,70,80,90) K

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

PRE = KAMCBYPFH (ii) 55 55


IN = MABCKYFPH (iii)
POST = MBCAKHPYK (I) (a) Possible (b) Possible

Unit 7 _Chapter 4.indd 27 11/19/2015 12:17:19 PM


7.28 | Data Structure

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,

Unit 7 _Chapter 4.indd 28 11/19/2015 12:17:32 PM


Chapter 4 Trees | 7.29

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

Unit 7 _Chapter 4.indd 29 11/19/2015 12:17:35 PM


7.30 | Data Structure

26. A priority queue is implemented as a Max-heap. A


Initially it has 5 elements. The level order traversal A
of heap is given below: 10,8,5,3,2. Two new ele- B
(a) C (b)
ments ‘1’ and ‘7’ are inserted in the heap in that C D
order. The level order traversal of the heap after the
D B
insertion of elements is: [2005]
(a) 10.8,7,5,3,2,1
(b) 10,8,7,2,3,1,5
A
(c) 10,8,7,1,2,3,5
(d) 10,8,7,3,2,1,5
A D
Solution: (d) (c) B (d) B
root
10 C D C
Heap after inserting
the 5 elements 8 5
Solution: (d)
3 2 Required in-order: BCDA
Required pre-order: ABCD
root Choice(A) : in-order: BADC
10
Heap after inserting 1 Pre-order: ABCD
8 5 Choice(B) : in-order: BCAD
Pre-order: ABCD
3 2 1 Choice(C) : in-order: ACBD
Pre-order: ABCD
root Choice(D) : in-order: BCAD
10
Heap after inserting Pre-order: ACBD
7 and heapify
8 7
Hence, the correct option is (d).
29. Consider the following C program segment:
3 2 1 5

Level order traversal: 10 8 7 3 2 1 5

Hence, the correct option is (d).


27. Consider the label sequence obtained by the fol-
lowing pairs of traversals on a labeled binary tree.
Which of these pairs identify a tree uniquely?
[2004]
i) Pre-order and post-order
ii) In-order and post-order
iii) Pre-order and in-order
iv) Level order and post-order
(a) (i) only
(b) (ii), (iii) only
(c) (iii) only
(d) (iv) only
Solution: (b)
28. which one of the following binary tree has its in-
order and pre-order traversal as BCAD and ABCD,
respectively? [2003]

Unit 7 _Chapter 4.indd 30 11/19/2015 12:17:42 PM


Chapter 4 Trees | 7.31

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

Unit 7 _Chapter 4.indd 31 11/19/2015 12:17:50 PM


7.32 | Data Structure

Solution: (d) After inserting all elements:


Consider the rules given below root
1. If x is root of some sub-tree and y is the next 50
key in pre-order sequence then,
(a) if y < x, then y is root of left subtree of x. 1 62
(b) if y > x , then y is root of right subtree of x.
2. if K > x and K is next number in pre-order se- 5 20 58 91
quence to x, the all numbers in between must
be less than x and all numbers after K must 3 8 37 60
be greater than x.
Option (a) does not satisfies rule 2 therefore it is 24
not correct choice.
Option (b) does not satisfies rule 2 therefore it is Hence, the correct option is (b).
not correct choice. 35. If the binary tree in the following figure is traversed
Option (c) does not satisfies rule 2 therefore it is in in-order, then the order in which the nodes will
not correct choice. be visited is…… [1991]
Hence, the correct option is (d).
7
34. A binary search tree is generated by inserting in
order the following integers: 3
50,15,62,5,20,58,91,3, 1
The number of nodes in the left subtree and right 5
subtree of the root respectively is [1996] 4 6
(a) 4,7 (b) 7,4 (c) 8,3 (d) 3,8 2 8
Solution: (b)
Subtree nodes[Left] = 7 Solution:
Subtree nodes[Right] = 4
7
50
1 3
15 62

4 6 5
5 20 58 91

2 8
3 8 37 60

Inorder traversal of given figure: Left-Node-Right


24 41673258

Unit 7 _Chapter 4.indd 32 11/19/2015 12:17:53 PM


Chapter 4 Trees | 7.33

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

2. Draw the binary tree with node labels a, b, c, d,


e, f and g for which the in-order and post-order
traversals result in the following sequences.
In-order: a f b c d g e
Post-order: a f c g e d b [1998] Min no of nodes for tree height
3→8
Solution:
ex
root b

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

Unit 7 _Chapter 4 (FMQ).indd 33 11/19/2015 12:19:15 PM


7.34 | Data Structure

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.

6. A 3-ary tree is a tree in which every internal node or


has exactly three children. Use induction to prove
that the number of leaves in a 3-ary tree with n
interval nodes is 2(n − 1) + 3. [1994]
Solution:
By putting three children to an internal node
⇒we lost one leaf. The change in number of leaves or or
= 3 − 1 = 2, when 3 new leaves added so.
⇒ this is the same case with every single internal
no increment.
⇒ So, for (n − 1) internal nodes and (In − 1) leaves,
n internal nodes we will get In − 1 + 2 leaves.
So, In = In − 1 + 2.
I1 = 3 leaves for tree with one internal nodes. or
So,
In = (In − 2 + 2) + 2
= In − 2 + 2(2)
= (In − 3 + 2) + 2 * 2
= In − 3 + 3 * 2 By principle of mathematical induction, it can be
Generally, concluded that Binary tree with ‘n’ internal nodes
In = In − 1 + i * 2 having two descendants there will be n + 1 leaf
When i = n − 1. nodes.
7. Prove by the principal of mathematics induction 8. Consider the binary tree in as shown below:
that for any binary tree, in which every non-leaf (a) What structure is represented by the binary
node has two descendants, the number of leaves in tree?

Unit 7 _Chapter 4 (FMQ).indd 34 11/19/2015 12:19:19 PM


Chapter 4 Trees | 7.35

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

9. (i) Define the height of a binary tree or subtree 0


and also define a height balanced (AVL) tree. 13
(ii) Mark the Balance factor of each on the tree
(iii) Resultant tree
given in figure and state whether it is height-
0
balanced. 15
(iii) Into the same tree given above, insert 13 and 0
12 −1 17
show the new balance factors that would arise
if the tree is not rebalanced. Finally carry out 1 0
1 0 20
the required rebalancing of the tree and show 5 14 16
the new tree with the balance factors on each 0 0 0
mode. [1988] 1 13 18 0 24

Unit 7 _Chapter 4 (FMQ).indd 35 11/19/2015 12:19:22 PM


Chapter 5
Graphs

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)

If starting from S performing DFS, tree edges are


obtained as numbered. Tree edges are exactly (n −
1) i.e.; if a connected graph contains n vertices its
tree edges are (n − 1).
Hence we will get the number of connected com-
Solution: ponent as (n − k), where n is total no of vertices, k
19 14 13 7 6 is no of tree edges.
Hence, the correct option is (d).
18 15 12 8 5 2 1
3. Consider the following graph among the following
sequences
I. a b e g h f II. a b f e h g
17 16 11 10 9 4 3 III. a b f h g e IV. a f g h b e
a
Recursion depth {MAXIMUM} = 19.
2. In a depth-first traversal p of a graph G with n ver-
e
tices, k edges are marked as tree edges. The num- b f
ber of connected components in G is [2004] h
(a) k (b) k + 1
(c) n − k − 1 (d) n − k
g
Solution: (d)
If v was first discovered by exploring edges (u, v), Which are depth first traversal of the above graph?
we can say that edge (u, v) is a tree edge. [2003]

Unit 7 _Chapter 5.indd 36 11/19/2015 12:37:49 PM


Chapter 5 Graphs | 7.37

(a) I, II and IV only Graph is:


(b) I and IV only 1
(c) II, III and IV only
1 4
(d) I, III and IV only
1
Solution: (d) 0 3
12 9
4 7
8 2
twO-marks QuestiOns 2 4
3
1. Let G be a weighted graph with edge weights
greater than one and G′ be the graph constructed Minimum spanning tree is:
by squaring the weight of edges in G. Let T and 1
T ′ be the minimum spanning trees of G and G′
1 4
respectively, with total weights t and t′. Which of 1 4
the following statements is true? [2012] 0
3 0 3
(a) T′ = T with total weight t′ = t2
(b) T′ = T with total weight t′ < t2
2 2
(c) T′ ≠ T with total weight t′ = t2
(d) None of the above 4 4
Solution: (b)
3
T′ = T and t′ < t2 3
2 2
G G1
2 3 4 9 Since 0 must be leaf we have to add either (0,1)
or (0,3), as edge (3,4) must be added after add-
4 16 ing (0,1), (0,3). Other edges should be minimum
MST (T) MST (T1) weight edge after 1 in the cut-set between {0,1}
and {2,4,3} or {0,3,2,4} and {1}. If (0,1) is taken
2 3 4 9 4 is next minimum edge in the cut-set, so figure 1
is result. If (0,3) is taken 4 next minimum edge in
Weight (t) = 5 Weight (t1) = 13 the cut-set between {0,3,2,4} and {1} then figure 2
Hence, the correct option is (b). is result. So weight of minimum spanning tree with
Common Data for Questions 2 and 3: Con- vertex 0 as leaf node is: 10.
sider a complete undirected graph with vertex Hence, the correct option is (d).
set{0,1,2,3,4}. Entry Wij in the matrix W below is 3. What is the minimum possible weight of a path P
the weight of the edge {i, j} [2010] from vertex 1 to 2 in this graph such that P con-
tains at most 3 edges?
0 1 8 1 4
 1 0 12 4 9  (a) 7 (b) 8 (c) 9 (d) 10
  Solution: (b)
W =  8 12 0 7 3  For Path is 1-0-4-2, weight is (8).
 
1 4 7 0 2 Others:
 4 9 3 2 0  1-2=> 12
1-0-2=>9
2. What is the minimum possible weight of a span- 1-3-2=>11
ning tree T in this graph such that vertex 0 is a leaf 1-4-2=>12
node in the tree T ? 1-0-4-2-8=>minimum
(a) 7 (b) 8 (c) 9 (d) 10 1-4-0-2=>21
Solution: (d) 1-0-3-2=>9

Unit 7 _Chapter 5.indd 37 11/19/2015 12:37:52 PM


7.38 | Data Structure

1-3-0-2=>13 vertices and n edge will have minimum number


1-4-3-2=>18 of spanning trees. The loop has 3 edges, we can
1-3-4-2=> remove any one of them to get a spanning tree.
4. Consider the following sequence of nodes for the So 3 choices => 3 spanning trees.
undirected graph given below 6. Consider the depth first search of undirected graph
c with 3 vertices P, Q and R. Let discovery time d(u)
b represent the instant when the vertex u is first visit
and finish time f(u) represent the time instant when
a e f the vertex u is last visited. Given that
d d(P) = 5 units f(P) = 12 units
g d(Q) = 6 units f(Q) = 10 units
d(R) = 14 units f(R) = 18 units
I. a b e f d g c
II. a b e f c g d Which of the following statements are TRUE about
III. a d g e b c f graph? [2006]
IV. a d b c g e f (a) There is only one connected component
(b) There are two connected components, and P
A depth first search is started at node a. the nodes and R are connected
are listed in the order they are first visited. Which all (c) There are two connected components and Q
of the above is (are) possible output(s)? [2008] and R are connected
(a) I and III only (d) There are two connected components and P
(b) II and III only and Q are connected
(c) II,III and IV only
(d) I,II and III only Solution: (d)
3 vertices (P, Q, R);
Solution: (b) Since, d(P) < d(Q) and f(P) > f(Q) in DFS i.e., after
(I) and (IV) are possible since there is traversal first visiting the vertex P, then Q was visited even
form f to d(I) and c to g(IV) before finishing the routine for P, it is completed
5. What is the largest m such that every simple con- for Q.
nected graph with n vertices and n edges contains It says that P, Q are connected.
at least m different spanning trees? [2007] d(R) > both f(P) and f(Q)
(a) 1 (b) 2 (c) 3 (d) n 14 > 12, 10 => when routine is completed for P, Q
Solution: (c) then only these are visited. So it cannot be reached
Graph with n vertices will have minimum n − 1 from (P, Q). So, R is not connected to either P or Q.
edges. This gives an indication that there are two con-
For example, with n = 6. nected components:
P

Q R
Component 1 Component 2

7. Let T be a depth first tree in a undirected graph G.


Vertices u and v are leaves of this tree T, the degree
With total (n − 1) choices that are there forming a of both u and v are at least 2. Which one of the fol-
cycle. lowing statements is true? [2006]
But among all these permutations possible, if the (a) There must exist a vertex w adjacency of both
cycle is of minimum length, then graph with n u and v in G.

Unit 7 _Chapter 5.indd 38 11/19/2015 12:37:54 PM


Chapter 5 Graphs | 7.39

(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 

Unit 7 _Chapter 5.indd 39 11/19/2015 12:37:57 PM


Chapter 6
Hashing

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.

Unit 7 _Chapter 6.indd 40 11/19/2015 12:37:15 PM


Chapter 6 Hashing | 7.41

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

4. Given the following input (4322, 1334, 1471, 2 20


9679, 1989, 6171, 6173, 4199) and hash function 3 12
x mod 10, which of the following statements are 4
true?
i) 9679, 1989, 4199 hash to the same value 5 5
ii) 1471, 6171 hash to the same value
6 15 33
iii) All elements hash to the same value
iv) Each element hashes to a different value 7 Minimum
[2004]
(a) (i) only 8 17
(b) (ii) only
(c) (i) and (ii) only Hence, the correct option is (a).
(d) (iii) and (iv) only
2. Consider the hash table with 100 slots. Collisions
Solution: (c) are resolved by chaining. Assuming simple uni-
Hash function f(x) = x mod 10 form hashing, what is the probability that the first
i) f(9679) = f(1989) = f(4199) 3 slots are unfilled after the first 3 insertions?
ii) f(1471) = f(6171) = 1. [2014]
Since the given hash function is have mod 10.
Hence, the correct option is (c). ( 97 ´ 97 ´ 97) ( 99 ´ 98 ´ 97)
(a) 3 (b)
5. An advantage of chained hash table (external hash- 100 1003
ing) over the open addressing scheme is [1996] ( 97 ´ 96 ´ 95) ( 97 ´ 96 ´ 95)
(a) worst case complexity of search operations is (c) (d)
less
100 3
(3
1
´ 1003 )
(b) space used is less
Solution: (a)
(c) deletion is easier
For each insertion, possible number of slots = 100
(d) None of the above
But to satisfy given condition,
Solution: (c) Possible number of slots = 97
The elements which are to be deleted in linked list So, for 3 insertions,
of hashed key are searched in separate chaining.
97 97 97
It is easy to delete them as they are in linked list ´ ´
form. 100 100 100
Hence, the correct option is (c). Hence, the correct option is (a).

Unit 7 _Chapter 6.indd 41 11/19/2015 12:37:19 PM


7.42 | Data Structure

Common Data for Questions 3 and 4: (a) 10 (b) 20 (c) 30 (d) 40


A hash table of length 10 uses open addressing Solution: (c)
with hash function h(k) = k mod 10, linear prob- 42, 23, 34 should be inserted before 52.
ing. After inserting 6 values into an empty hash Any of 42, 23, 34
table, the table is as shown below.
52 46 33
0
Possibilities 3! Total 4! + 3! = 30
1
Hence, the correct option is (c).
2 42
5. Consider a hash table of size 11 that uses open
3 23
addressing with linear probing. Let h(k) = k mod
4 34 11 be the hash function used. A sequence of
5 52 records with keys 43, 36, 92, 87, 11, 4, 71, 13, 14
6 46 is inserted into an initially empty hash table, the
7 33 bins of which are indexed from 0 to 10. What is the
index of bin into which the last record inserted?
8 [2008]
9 (a) 3 (b) 4 (c) 6 (d) 7
3. Which one of the following choices gives a pos- Solution: (d)
sible order in which the keys values have been After inserting all the keys, table will be
inserted in the table? [2010]
Key 43 36 92 87 11
(a) 46, 42, 34, 52, 23, 33
(b) 34, 42, 23, 52, 33, 46 Loc 10 3 4 10 0
(c) 46, 34, 42, 23, 52, 33 Key 4 71 13 14
(d) 42, 46, 33, 23, 34, 52 Loc 4 5 2 3
Solution: (c)
´ ´ ´ 0 87
A B C D 1 11
0 2 13
1 3 36
2 42 42 42 42 4 92
3 52 23 23 23 5 4
4 34 34 34 23 6 71
5 23 52 52 34 7 14
6 46 33 46 46 8
7 33 46 33 52 9
8 10 43
9 Hence, the correct option is (d).
Hence, the correct option is (c). 6. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted
4. How many different insertion sequences of the into an initially empty hash table of length 10
key values using the same hash function and linear using open addressing with hash function h(k) =
probing will result in the hash table shown above? k mod 10 and linear probing. What is the resultant
[2010] hash table? [2008]

Unit 7 _Chapter 6.indd 42 11/19/2015 12:37:19 PM


Chapter 6 Hashing | 7.43

(a) 0 (b) 0 Hash function


h(x) = (3x + 4) −7
1 1 h(1) = (3 + 4) −7 = 0
2 2 2 12 h(3) = (9 + 4) −7 = 6
3 23 3 13 h(8) = (24 + 4) −7 = 0
h(10) = (30 + 4) −7 = 6
4 4 Assume Linear probing for collision resolution, as
5 15 5 5 it is closed hashing,
6 6
0 1
7 7
1 8
8 18 8 18
2 1
9 9
3 0
4
(c) 0 (d) 0
5
1 1
6 3
2 12 2 12,2
3 13,3,23 As linear probing is not mentioned, current hashed
3 13
value is used.
4 2 4 Let us put values 1, 3, 8, 10 in the hash of size 7.
5 3 5 5,15 1 8 10 3
6 23 6 0 1 2 4 5 6

7 5 7 Initially, hash table is empty – – – – – – –


8 18 8 18 0 1 2 3 4 5 6
9 15 9 The value of function (3x + 4) 1 – – – – – –
mod 7 for 1 is 0, so let us put 0 1 2 3 4 5 6
Solution: (c) the value at 0
Final hash table
Probes interval is 1, which is fixed. Hash table is The value of function (3x + 4) 1 – – – – – 3
searched sequentially, in linear probing that starts mod 7 for 3 is 6, so let us put 0 1 2 3 4 5 6
from the original hash location. The next location the value at 6
is checked if location is occupied. If necessary, we The value of function (3x + 4) 1 8 – – – – 3
wrap around from the last table location to the first mod 7 for 8 is 0, but 0 is al- 0 2 3 4 5 6
table location. ready occupied, let us put the
Hence, the correct option is (c). value (8) at next available
7. Consider a hash table of size 7, with starting index space (1)
0, and a hash function (3x + 4) mod 7. Assuming The value of function (3 x + 4) 1 8 10 – – – 3
the hash table is initially empty, which of the fol- mod 7 for 10 is 6, but 6 is al- 0 1 2 3 4 5 6
lowing is contents of the table when the sequence ready occupied, let us put the
1, 3, 8, 10 is inserted into the table using closed value (10) at next available
hashing? space (2)
Note that ‘–’ denotes an empty location in the table. Hence, the correct option is (b).
[2007]
8. Consider a hash function that distributes keys uni-
(a) 8,–,–,–,–,–,10 (b) 1,8,10,–,–,–,3
formly. The hash table size is 20. After hashing of how
(c) 1,–,–,–,–,–,3 (d) 1,10,8,–,–,–,3
much keys will the probability that any new hashed
Solution: (b) collides with an existing one exceeds 0.5. [2007]

Unit 7 _Chapter 6.indd 43 11/19/2015 12:37:20 PM


7.44 | Data Structure

(a) 5 (b) 6 (c) 7 (d) 10 S5


Solution: (d)
Hash table size = 20
The probability of collision: S6
p = Number of filled buckets/total number of S3
buckets Solution:
If p ≥ 0.5, the number of filled buckets ≥ 10.
0 S7
Hence, the correct option is (d).
1 S1
9. A hash table with ten buckets with one symbol per
buckets is shown in the following figure with the 2
symbols S1 to S7 entered into it using some hash- s: 3 S4
ing function with linear probing. The worst case 4 S2
number of comparisons required when the symbol
5
being searched not into the table is [1989]
6 S5
S7 7
S1 8 S6
9 S3
S4 By linear probing, the worst are the number of com-
S2 parisons S6, S3, S7 and S1.
That finally ends with an empty bucket.
So, total number of comparison is = 4.

Unit 7 _Chapter 6.indd 44 11/19/2015 12:37:20 PM


Chapter 6 Hashing | 7.45

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 

Unit 7 _Chapter 6 (FMQ).indd 45 11/19/2015 12:36:40 PM


This page is intentionally left blank.

Unit 7 _Chapter 6 (FMQ).indd 46 11/19/2015 12:36:40 PM


UNIT VIII
PROGRAMMING
LANGUAGES
Chapter 1: Programming Language Concepts 8.3
Chapter 2: Programming in C (Part I) 8.15
Chapter 3: Programming in C (Part II) 8.24

Gate_CSE_Unit8_Programming Languages Folder.indb 1 11/19/2015 5:03:07 PM


Gate_CSE_Unit8_Programming Languages Folder.indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 1 0 0 1 1 0 1 0 0 4 0 2 3 3 4 0 0 0 0 2 1 1 0 6
2 Marks Ques. 2 3 2 2 0 0 5 1 1 1 1 3 4 1 3 1 4 3 2 1 1 3 0 0 1 3 1 2
5 Marks Ques. 0 0 1 0 2 1 1 3 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 4 6 9 4 11 5 15 18 8 7 8 6 13 11 11 4 11 9 8 2 2 6 0 2 3 7 2 10

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

Gate_CSE_Unit8_Programming Languages Folder.indb 3 11/19/2015 5:03:07 PM


n n! n( n − 1)( n − 2)
c3 = =
3!( n − 3)! Languages
8.4 | Programming 3!

n( n − 1)( n − 2) n( n − 1) ( n − 2) 3. Dynamic allocation of activation records is es-


= = ×
2×3 2 3 sential to implement recursion
4. Both heap and stack are essential to implement
Hence, the correct option is (b). recursion
4. Which one of the following is NOT performed (a) 1 and 2 only (b) 2 and 3 only
during compilations? [2014] (c) 3 and 4 only (d) 1 and 3 only
(a) Dynamic memory allocation Solution: (d)
(b) Type checking 1. Once the memory is allocated in static alloca-
(c) Symbol table management tion, recursion is not possible since memory re-
(d) Inline expSolutionion mains unchanged during execution of program.
Solution: (a) 2. Instruction reference in recursion is stored is
dynamic memory allocation is done during runtime followed by recursive calls which is stored into
whereas type checking, symbol table management the stack in form of activation record.
and inline expansion are done at compile time. Hence, the correct option is (d).
Hence, the correct option is (a). 7. Which languages necessarily need heap allocation
5. Let A be a square matrix of size n * n. Consider in the runtime environment? [2010]
the following pseudocode. What is the expected (a) Those that support recursion
output? [2014] (b) Those that use dynamic scoping
C = 100; (c) Those that allow dynamic data structures
(d) Those that use global variables
For i = 1 to n do
Solution: (c) 
For j = 1 to n do
Data structures that are allocated space during run
{ time is done from heap portion.
Temp. = A[i][j] + C; Hence, the correct option is (c).
A[i][j] = A[j][i]; 8. A common property of logic programming lan-
A[j][i] = Temp. – C; guages and functional languages is: [2005]
} (a) Both are procedural languages
For i = 1 to n do (b) Both are based on 1 - calculus
(c) Both are declarative
For j = 1 to n do (d) Both use Horn-clause
Output(A[i][j]; Solution: (c)
(a) The matrix A itself
(b) Transpose of matrix A In logic programming language and functional
(c) Adding 100 to the upper diagonal elements language a statement is declared before using it
and subtracting 100 from lower diagonal ele- with a common property of using variables after
ments of A. declaration so both are declarative.
(d) None of above. Hence, the correct option is (c).
Solution: (a) 9. The goal of structured programming is to [2004]
Initially matrix ‘A’ is empty and after performing (a) Have well indented programs
the operations defined in the program then again (b) Be able to infer the flow of control from the
matrix ‘A’ itself will be printed. compiled code
(c) Be able to infer the flow of control from the
Hence, the correct option is (a). program text
6. Which of the following statements are CORRECT? (d) Avoid the use of GOTO statements
 [2014] Solution: (d)
1. Static allocation of all data areas by a compiler
makes it impossible to implement recursion. Structured programming makes a program more
2. Automatic garbage collection is essential verbose with more readable, reliable with easy

Gate_CSE_Unit8_Programming Languages Folder.indb 4 11/19/2015 5:03:07 PM


Chapter 1  Programming Language Concepts | 8.5

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

Gate_CSE_Unit8_Programming Languages Folder.indb 5 11/19/2015 5:03:07 PM


8.6 | Programming Languages

16. An unrestricted use of ‘goto’ statement is harmful If (i = = j)


because [1994] {
(a) it makes it more difficult to verify programs Printf(“something”);
(b) it increases the running time of the programs K = f(i)
(c)  it increases the memory required for the Return 0;
programs }
(d) It results in the compiler generating longer Else return 0;
machine code }
Solution: (a)  Which one of the following is TRUE?
GOTO statement is considered ‘harmful’ since it (a) The function returns 0 for all values of j
hampers program understandability. A program- (b) The function prints the string something for all
mer using GOTO statement should justify every values of j
use of the statement. (c) The function returns 0 when j = 50
(d) The function will exhaust the runtime stack or
Hence, the correct option is (a).
run into an infinite loop when j = 50.
17. Indicate allthe true statements from the following:
Solution: (d)
 [1991]
(a) A programming language not supporting ei- With every function call, the auto variable j is rec-
ther recursion or pointer type does not need reated and reinitialized. Taking j = 50 with every
the support of dynamic memory allocation true condition f (i) will be called where the state-
(b) Although C does not support call by name ments reference are stored into the stack, where
parameter passing, the effect can be correctly stack continuously growing leading to the stack
simulated in C overflow error.
Solution: a: false.  b: true. Hence, the correct option is (d).
3. What is the return value of f(p, p), if the value of
p is initialized to 5 before the call? Note that the
Two-marks Questions first parameter is passed by reference, whereas the
second parameter is passed by value
1. Consider the following function  [2014]
int f(int&x, int c)
Double f(double x)
{
{
c = c - 1;
  If (abs (x*x - 3) < 0.01)return x;
if(c = = 0)return 1;
Else return f (x/2 + 1.5/x);
x = x + 1;
}
return f(x,)*x;
Give a value q(to 2 decimals) such that f(q) will
} [2013]
return q: = …………..?
(a) 3024 (b) 6561
Solution:  (c) 55440 (d) 161051
1.72 to 1.74 If condition will fail if x2 − 3 < 0.01 Solution: (b)
x2 − 2.99 < 0 9*9*9*9*1 = 6561.
Thus possible x values while satisfying the above Hence, the correct option is (b).
equations will be 1.72 to 1.74.
4. Which of the following are true? [2008]
2. Consider the C function given below: [2014] (a)  A programming language which does not
Intf(int j) permit global variables of any kind and has
{ no nesting of procedures/functions, but per-
Static int i = 50; mits recursion can be implemented with static
Int k; storage allocation

Gate_CSE_Unit8_Programming Languages Folder.indb 6 11/19/2015 5:03:07 PM


Chapter 1  Programming Language Concepts | 8.7

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

Gate_CSE_Unit8_Programming Languages Folder.indb 7 11/19/2015 5:03:08 PM


8.8 | Programming Languages

Solution: (b) Solution: (c)


In called function func c1, x refers to the value 3, y in dynamic scope the reference to the free variable
and z refers to 10, so output is 31, 3. is at a point of invocation in reverse order.
Hence, the correct option is (b). Hence, the correct option is (c).
8. Consider the following program [2001] 10. A certain processor supports only the immediate
Program P2 and the direct addressing modes. Which of the fol-
var n: int; lowing programming language features cannot be
procedure W (var x: int) implemented on this processor?
begin (a) Pointers
(b) Arrays
x = x + 1;
Print x;
(c) Records
(d) Recursive procedures with local variables
end  [1999]
Solution: (a)
procedure D indirect addressing mode is required for pointers.
begin
Hence, the correct option is (a).
var n: int;
11. Given the programming constructs (i) assignment
n = 3;
(ii) for loops where the loop parameter cannot be
W (n); changed within the loop (iii) if-then-else (iv)for-
end ward go to (v) arbitrary go to (vi) non-recursive
begin\\begin P2 procedure (vii) recursive procedure/function call
n = 10; (viii) repeat loop, which constructs will you not
D; include in a programming language such that
end; it should be possible to program the terminates
(i.e., halting) function in the same programming
(a) 10
language [1999]
(b) 11
(a) (ii), (iii), (iv) (b) (v), (vii), (viii)
(c) 3
(c) (vi), (vii), (viii) (d) (iii), (vii), (viii)
(d) None of the above
Solution: (b)  an arbitrary go to lead to infinite
Solution: (d) output will be 4 as ‘x’ refers to n.
loops as follows:
Hence, the correct option is (d).
Label 1: gotolabel 2;
9. Consider the following program in a language that
Label 2: gotolabel 1;
has dynamic scoping [1999]
var x: real; Recursive procedure/functional calls may be non-
procedure show: terminatory if terminating condition is never satis-
fied. A repeat loop can also lead to infinite loops if
begin print (x); end,
condition to exit the loop is never satisfied.
procedure small, Hence, the correct option is (b).
var x: real; 12. Faster access to non-local variables is achieved
begin x: = 0.125; show;
using an array of pointers to activation records
called a [1998]
end; (a) Stack (b) Heap
begin x: = 0.25; (c) Display (d) Activation tree
show; small;
Solution: (c)
Then the output of the program is: non-local variables can be accessed using display
(a) 0.125 0.125 (b) 0.25 0.25 (or multilevel access link).
(c) 0.25 0.125 (d) 0.125 0.25 Hence, the correct option is (c).

Gate_CSE_Unit8_Programming Languages Folder.indb 8 11/19/2015 5:03:08 PM


Chapter 1  Programming Language Concepts | 8.9

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

Gate_CSE_Unit8_Programming Languages Folder.indb 9 11/19/2015 5:03:08 PM


8.10 | Programming Languages

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

Gate_CSE_Unit8_Programming Languages Folder.indb 10 11/19/2015 5:03:08 PM


Chapter 1  Programming Language Concepts | 8.11

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

Gate_CSE_Unit8_Programming Languages Folder.indb 11 11/19/2015 5:03:08 PM


8.12 | Programming Languages

Five-marks Questions (a) Suppose the parameter to the procedure ‘recur’


is passed by value.
1. Consider the following program is pseudo-Pascal i.  What value is printed by the program
syntax [2000] ii.  How many time is ‘recur’ called?
program main
(b) What value is printed by the program if the pa-
var x: integer; rameter is passed by the reference?
procedure Q (z: integer Solution:
being
z: = z + x; (a) (i)  call by value prints it as 30.
writeln (z) (ii)  5 times.
end;
procedure P (y: integer);
(b) Call-by-reference prints it as 110.
var x: integer; 3. Consider the following program in pseudo-Pascal
begin
syntax. What is printed by the program if param-
x: = y + 2;
Q(x); eter a in procedure test 1 is passed as [1996]
writeln(x) i. Call by reference parameter
end; ii. Call by value
begin
x; = 5, program Example (input, output)
p(x); var b: integer;
Q(x); procedure test 2
writeln (x) begin b: = 10 end
end. procedure test 1 (a:integer);
begin a:5;
writeln ('point 1: 'a, b);
What is the output of the program, when test 2;
(a) The parameter passing mechanism is call-by- wrote;m ('point: 2:'a,b);
value and the scope rule is static scoping? end;
begin (*Example*)
(b)  The parameter passing mechanism is call-
b : = 3; test] (b);
by-reference and the scope rule is dynamic writeln ('point 3: 'b);
scoping? end
Solution:
(a) 12, 7, 10, 5 with static scoping and call-by-value. Solution: Call by value: 5, 3
(b) 14, 14, 10, 10 with dynamic scope and call-by- 5, 10
reference.
10
2. Consider the following program in pseudo-Pascal
Call-by-reference: 5, 5
syntax [1997]
10, 10
program what:
var z: integer; 10
procedure recur (x): 4. Consider the program below: [1994]
begin if x < 40 then
begin x: x + z; program mam,
var r: integer;
recur (x);
procedure two;
z: = x + 10;
begin write (r) end;
end
procedure one;
var r: integer;
end (*recur*);
begin (*what*) begin r: = 5 two; end;
z = 10; begin r: = 2;

recur (z); two; one; two;


end;
writeln (z);
end

Gate_CSE_Unit8_Programming Languages Folder.indb 12 11/19/2015 5:03:08 PM


Chapter 1  Programming Language Concepts | 8.13

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

Gate_CSE_Unit8_Programming Languages Folder.indb 13 11/19/2015 5:03:09 PM


8.14 | Programming Languages

Solution: Write (‘a = ’, a, ’b = ’, b)


(i) call-by-value: 1, 100. End.
(ii) call-by-reference: 2, 7 because ‘a’ refers to ‘x’
Solution:
and ‘c’ refers to ‘z’.
(iii) Call-by-name: 2, 12 because, formal arguments (i) static scoping: 5, 10.
renamed (or) replaced with actual arguments. (ii) dynamic scoping:1, 2.
9. For the following pseudo code, indicate the output 10. Indicate the result of the following program if the
if [1991] language uses [1989]
i. static scope i. Static scope rules and call by reference
ii. dynamic scope rules are used ii. Dynamic scope rules and call by reference
vara, b: integer; Var x, y: integer;
Procedure P; Procedure A (var z: integer);
a: = 5 ; b: = 10; Var x: integer;
End {P}; Begin x: = 1; B; z: = x; end;
Procedure Q; Procedure B;
Var a, b: integer; Begin x: = x + 1; end;
P; Begin
End {Q} x: = 5; A (y) ; write (y);
Begin end.
A: = 1 ;b: = 2; Solution:
(i) Staticscoping :1
Q;
(ii) Dynamicscoping :2

Gate_CSE_Unit8_Programming Languages Folder.indb 14 11/19/2015 5:03:09 PM


Chapter 2
Programming In C (Part I)

iv) Polymorphism in the presence of inheritance


One-mark Questions (a) (i) and (ii) only
(b) (i) and (iv) only
1. What will be the output of the following C pro-
(c) (i), (ii) and (iv) only
gram segment? [2012]
(d) (i), (iii) and (iv) only
Char inchar = ’A’
Solution: (b) refer features of OOPS
Switch (inchar) {
Hence, the correct option is (b)
Case ‘A’: printf (“choice A\n”);
3. An abstract data type (ADT) is: [2005]
Case B: (a) Same as an abstract class
Case ‘C’: printf (“choice B”); (b) A data type that cannot be instantiated
Case ‘D’: (c) A data type for which only the operations de-
fined on it can be used, but none else
Case ‘E’:
(d) All of above
Default: printf (“no choice”);}
Solution: (c) 
(a) No choice
(b) Choice A Abstract data type is a data type together with all
(c) Choice A its defined operations.
Choice B no change Hence, the correct option is (c)
(d) Program gives no output as it is erroneous 4. Consider the following C function [2003]
Solution: (c) float f, (float x, int y){
Switch statement case A matches initially and all floatp, s;int I;
other cases execute as ‘Break’ in cases. for (s = 1, p = 1, i = 1;i < y;i +
Therefore output (c) - > choice a. + )
p* = x/I;
Choice b is no choice since there is no break in
between the case statement. s + = p;
}
Hence, the correct option is (c)
Return s;
2. Which one of the following are essential features }
of an object-oriented programming language?
 [2005] For large values of y, the return value of the func-
i) Abstraction and encapsulation tion f best approximates
ii) Strictly-typedness
iii) Type-safe property coupled with sub type rule

Gate_CSE_Unit8_Programming Languages Folder.indb 15 11/19/2015 5:03:09 PM


8.16 | Programming Languages

(a) Xy (b) ex Var…


(c) ln(1 + x) (d) Xx Procedure A1;
Solution: (b) Var…
When p = 1, i = 1 Call A2;
p = p*x/i = > p = 1*x; End A1
p = x; Procedure A2;
s = s + p; Var…
= 1 + x; Procedure A21;
When p = 1, i = 2 Var…
P = x * x/2 = x2/2 Call A1;
S = 1 + x + x2 /2
End A21
If we continue we will get
Call A21;
S = 1 + x/1 + x2/2 + x3/3!......
End A2
= ex
Call A1;
Hence, the correct option is (b).
End main
5. In the C language [2002] Consider the calling chain Main - > A1 - > A2 - >

(a) At most one activation record exists between A21 - > A1
the current activation record and the activation
The correct set of activation records along with
record for the main
their access links is given by
(b) The number of activation records between the
current activation record and the activation re- Solution: (d)
cord of the main depends on the actual func-
tion calling sequence
(c) The visibility of global variables depends on A1
the actual function calling sequence Main
A2 A21
(d) Recursion requires the activation record for
the recursive function to be saved on a differ-
ent stack before the recursive fraction can be
called Main
Solution: (b)
With the function call the statements followed by A1
function calls will be stored in to stack in form of Call activates
activation record. A2
Thus, number of activation records depends on
number of function call. A21

Hence, the correct option is (b)


FRAME A1 ACCESS
POINTER LINKS
Two-marks Questions
Hence, the correct option is (d)
1. Consider the program given below, in a block-
structured pseudo-language with lexical scoping 2. Consider the following C function: int f(int n)
and nesting of procedures permitted [2012] { Staticinti = 1;
Program main; If (n > = 5) return n;

Gate_CSE_Unit8_Programming Languages Folder.indb 16 11/19/2015 5:03:09 PM


Chapter 2  Programming In C (Part I) | 8.17

n = n + 1; Assuming that the main memory is byte-addressa-


i + + ; ble and that the array is stored starting from mem-
ory address 0, the address of a[40] [50] is [2002]
return f(n);
(a) 4040 (b) 4050
The value returned by f(1) is [2004] (c) 5040 (d) 5050
} Solution: (b) [(0 + 40 *100) + 50*1] = 4050.
(a) 5 (b) 6
Hence, the correct option is (b)
(c) 7 (d) 8
5. Consider the following C program
Solution: (a)
Main ()
N is incremented by one in each iteration. {int x, y, m, n;
Hence, the correct option is (a) Scanf(“%d %d”, &x, &y);
3. Consider the following class definition in a hypo- /* assume x > 0 and y > 0*/
thetical object oriented language that supports M = x;n = y;
inheritance and uses dynamic binding. The lan- While (m! = n)
guage should not be assumed to be either Java or m = m - n;
C + + , though the syntax is similar Else
Class P { n = n - m;
Void f (inti) }
Print (i); Printf(“%d”, n);
Class Q subclass of P { } [2002]
{
The program computes
Void f(inti)
(a) x + y using repeated subtraction
{ (b) x mod y using repeated subtraction
Print (2*i); (c) the greatest common divisor of x and y
} (d) the least common multiple of x and y
} Solution: (c)
}
The given C program is non recursive. So getting
Now consider the following program fragment: the value of n after some iteration. The main thing
P x = new Q (); about program is:
Q y = new Q (); 1. if m = n then n is GCD
2. if m > n then m = m - n
Pz = new Q ();
3. if m < n then n = n - m
x.f(1);((P)y).f(1);z.f(1);
For example let – x = 40 and y = 2
Here ((P) y) denotes a typecast of y to P. The
M = x = 40 and u = y = 32
output produced by executing the above program
fragment will be [2003] m > n so applying the 2nd condition
(a) 1 2 1 (b) 2 1 1 m=m-n
(c) 2 1 2 (d) 2 2 2 m = 40 - 32 = 8
Solution:(c) m = 8 and n = 8
Hence, the correct option is (c) Applying the first condition
4. Consider the following declaration of a two dimen- GCD (40, 32) = 8
sional array in C
The above algorithm represents the GCD(x, y)
Char a [100][100];
Taking x = 7 y=2
m = 7 n = 2

Gate_CSE_Unit8_Programming Languages Folder.indb 17 11/19/2015 5:03:09 PM


8.18 | Programming Languages

First iteration Foo(a, sum);


7! = 2 = > so m = 7 - 2 = 5 Printf(“%d/n”sum);
Second iteration }
5! = 2 = > so m = 5 - 2 = 3 The function foo is recursive function when called
Third iteration 3! = 2 foo(a, sum) = foo(2048, 0).
M=3-2=1 K = 2048%10 = foo(204, 8)
Since m < n; n = 2 - 1 = 1 Foo(204, 8)
And m = n = > return 1 K = 2048%10 = 4
Therefore, GCD (7, 2) = 1. Foo(20112)
Hence, the correct option is (c) K = 2%10 = 2
6. Consider the following C program: J
voidfoo(intn, int sum){ J = 2048/10
int k = 0, j = 0; 10 = 204
if (n = = 0)return; J = 204/10
k = n%10;j = n/10; 10 = 20
sum = sum + k; J = 2/10 = 0
foo(j, sum); Sum
printf(“%d”, k); Sum 0 + 8 = 8
} Sum 8 + 4 = 12
Intmain() { Sum = 12 - 12 = 14
Int a = 2048, sum = 0; Foo(0, 14)function will be terminated and k value
will print in tscak way, i.e., 2, 0, 4, 8 and sum = 0.
Foo(a, sum);
Since sum is local variable in the main function so
Printf(“%d\n”, sum);
print sequence is 2, 0, 4, 8, 0.
}
Hence, the correct option is (d)
What does the above program print? [2002]
7. Consider the following C-program:
(a) 8, 4, 0, 2, 14 (b) 8, 4, 0, 2, 0
(c) 2, 0, 4, 8, 14 (d) 2, 0, 4, 8, 0 doublefoo (double); /*Line 1*/
Solution : (d) int main(){
Void foo (intn, int sum) doubleda, db;
{ //input da
Int k = 0, j = 0; db = foo(da);
(n = 0)return; }
K = n%10;j = n/10; Double foo(double a){
Sum = sum + k; Return a;
Foo(j, sum) }
Printf(“%d”;k); The above code is compiled without any error or
warning. If line 1 is deleted, the above code will
}
show: [2002]
Int main(c) (a) No compile warning or error
{ (b) Some compiler-warnings not leading to unin-
Int a = 2048 , sum = 0; tended results

Gate_CSE_Unit8_Programming Languages Folder.indb 18 11/19/2015 5:03:09 PM


Chapter 2  Programming In C (Part I) | 8.19

(c) Some compiler - warnings due to type mis- Return f(n + 1) + r = 3 - 1 + 0 = 2


match eventually leading to unintended results Return f(n - 1) + r = 2 - 1 + 0 = 1
(d) Compile errors
Hence, the correct option is (d)
Solution: (d)
9. Choose the correct option to fill ?1 and ?2 so that
function defined later to the call but not defined in the program below prints an input string in reverse
the program requires prototype. order. Assume that the input string is terminated
Hence, the correct option is (d) by a new line character
8. Consider the following C function: Void reverse (void) {
int f(int n) Int c;
{ staticint r = 0; If (?1) reverese ();
if(n < = 0)return 1; ?2
If (n > 3) }
{r = n; Main () {
return f(n - 2) + 2; Printf (“enter text”);
} Printf (“\n”);
Return f(n - 1) + r; Reverse ();
} Printf (“\n”);
What is the value of f(5)? [2002] } [2002]
(a) 5 (b) 7 (a) ?1 is (getchar()! = ’\n’)
(c) 9 (d) 18 ?2 is getchar( c);
Solution: (d) (b) ?1 is (c = getchar()! = ’\n’)
n r ?2 is getchar( c);
(c) ?1 is (c! = ’\n’)
5 0
?2 is putchar( c);
return f(n − 2) + 2 = 5 − 3 + 2 = 5 (d) ?1 is ((c = getchar ()! = ’\n’)
?2 is putchar( c);
Solution: (d)
(c) the ‘ = ’ operator is used which has ‘priority
r=n=5
than ‘! = ’ operator.
Hence, the correct option is (d)
So (c = getchar()) has to be in brackets and after
reversing the string one use function putchar(c) for
printing the character.
() + 2
Common data question 9 &10
Consider the following recursive
(1) + 5 1+5=6 C function that takes two arguments:
(6) + 5 6 + 5 = 11 Unsigned intfoo (unsigned intn, nsignedint r)
(11) + 5
11 + 5 = 16
{
(15) + 2 If (n > 0)return((n%r) + foo(n/r, r));
Elsereturn 0;
16 + 2 = 18  therefore output 18
f(n- -
returnf(n
return + +r =r =5 5- 2- +2 0+ =
2)2) 03=3 } [2002]

Gate_CSE_Unit8_Programming Languages Folder.indb 19 11/19/2015 5:03:09 PM


8.20 | Programming Languages

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

5 + (7) Hence, the correct option is (d)


1 2. The value of j at the end of execution of the
following C program [2000]
Hence, the correct option is (b)
Intincr(inti)
1 1. What is the return value of the function foo when
{
it is called as foo(513, 2)?
(a) 9 (b) 8 Static int count = 0;
(c) 5 (d) 2 Count = count + I;
Solution: (d) Return (count);
foo(513, 2) }
= 513 %2 = 1 513/2 = 256 Main (){
foo(256, 2) IntI, j;
256%2 = 0 256/2 = 128 For (i = 0; i < = 4; i + + )
foo(128, 2) J = incr (i);
128%2 = 0 128/2 = 64 }
foo(64, 2) Is:
64%2 = 0 64/2 = 32 (a) 10 (b) 4
(c) 6 (d) 7
foo(32, 2)
Solution: (a)
32%2 = 0 32/2 = 16
I j
foo(16, 2)
0 0
16%2 = 0 16/2 = 8
1 1
foo(8, 2)
2 3
8%2 = 0 8/2 = 4
3 6
foo(4, 2)
4 10
4%2 = 0 4/2 = 2
foo(2, 2) Hence, the correct option is (a)

Gate_CSE_Unit8_Programming Languages Folder.indb 20 11/19/2015 5:03:10 PM


Chapter 2  Programming In C (Part I) | 8.21

13. Consider the following C function definition writeln(result);


 [1999] end
IntTrial (int a, int b, int c) (a) 5 (b) 25
{ (c) 36 (d) 42
If ((a > = b) &&(c < b)) return b; Solution: (d) (Parameter is passed by reference)
Else if (a > = b) return; Trial (a, c, b); Hence, the correct option is (d)
Else return Trial (b, a, c); 16. What is the value of X printed by the following
program? [1995]
}
program COMPUTE (input,
The function trial: output)
(a) Finds the maximum of a, b and c var
(b) Finds the maximum of a, b and c X: integer;
(c) Finds the middle number of a, b, c procedure FIND (X: real);
(d) None of above begin
Solution: (c) X:sqrt (X);
Comparing (a > = b) & (c < b) will return b if both end;
conditions are true meaning finding middle num- begin
ber of a, b, c again by calling Trial function with X:=2;
different parameters the middle number of a, b , c FIND(X);
is found. writeln(X);
Hence, the correct option is (c) end
14. What value would the following function return
(a) 2
for the input x = 95? [1998]
(b) √2
Function fun(x:integer):integer; (c) Run time error
Begin (d) None of the above
If x > 100 then fun:x - 10 Solution: (a) call by value.
Else fun: fun(fun(x + 11)) Hence, the correct option is (a)
End; 17. What does the following code do? [1993]
(a) 89 (b) 90 Vara, b: integer;
(c) 91 (d) 92
Begin
Solution: (c)
a: = a + b;
Hence, the correct option is (c)
b: = a - b;
15. What is the result of the following program?
a: = a - b;
 [1998]
end;
Program side-effect(input, output);
(a) Exchange a and b
Varx, result:integer: (b) Doubles a and stores in b
Function f(var x:integer):integer; (c) Doubles b and stores in a
Begin (d) Leaves a and b unchanged
x:x + 1; F: = x; Solution: assuming a = 5, b = 6
end a = a + b // ‘a’ becomes ‘11’,
begin b = a - b // ‘b’ becomes ‘5’,
x: = 5; a = a - 6 // ‘a’ becomes ‘6’
result : = f(x)*f(x);

Gate_CSE_Unit8_Programming Languages Folder.indb 21 11/19/2015 5:03:10 PM


8.22 | Programming Languages

17. Consider the two program segments below: [1988] i: i + 1


(a) For i: = 1 to f(x) by 1 do Under what conditions are these two programs
S; equivalent? Text S as any sequence of statements
End and f as a function.
(b) i: = 1; Solution:
While i < = f(x) do If the value of f(x) evaluates to a value greater than
S; one in the first invocation then both the constructs
are same or else different.

Gate_CSE_Unit8_Programming Languages Folder.indb 22 11/19/2015 5:03:10 PM


Chapter 2  Programming In C (Part I) | 8.23

Five-marks Questions Solution: maximum value of n = 64/4 = 16


2. a) Consider the following Pascal function where A
1. Consider the following recursive function: and B are non - zero positive integers. What is the
value of GET(3, 2)? [2002]
Function fib(n:integer);integer;
Function GET (A, B:integer);integer;
Begin
Begin
If(n = 0) or (n = 1)then fib: = 1
If B = 0 then
Elsefib: = fib(n - 1) + fib(n - 2)
GET: = 1
End;
Else if A < B then
The above function is run on a computer with
a stack of 64 bytes. Assuming that only return GET: = 0
address are parameters and passed on the stack, Else
and that an integer value and an address takes 2 GET: = GET(A - 1, B) + GET(A - 1, B - 1)
bytes each, estimate the maximum value of n for
End;
which the stack will not overflow. Give reasons for
your answer. [2002] Solution: 3

Gate_CSE_Unit8_Programming Languages Folder.indb 23 11/19/2015 5:03:10 PM


Chapter 3
Programming In C (Part II)

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

Gate_CSE_Unit8_Programming Languages Folder.indb 24 11/19/2015 5:03:10 PM


Chapter 3  Programming In C (Part II)  |  8.25

4. Consider the following C function 6. The following C declarations


Void swap (int a, int b) Structnode {
{int temp; int I;
Temp = a; Float j;
A = b; };
B = temp; Struct node *s [10];
} Defines to be
In order to exchange the values of two variables x (a) An array each element of which is a pointer to
and y. [2004] a structure of type node
(a) Call swap (x, y) (b) A structure of 2 fields, each fields being a
(b) Call swap (&x, &y) pointer to an array of 10 elements
(c) Swap (x, y) cannot be used as it does not return (c) A structure of 3 fields; an integer, a float, and
any value an array of 10 elements
(d) Swap (x, y) cannot be used as it does not return (d) An array, each element of which is a structure
any value of type node [2000]
Solution: (d) Solution: (a)
If swap (x, y) is called then there is no interchange it is an array of pointers and each pointer is point-
in the values of x and y since parameters are passed ing to structure.
by value. Formal parameters a and b are inter- Hence, the correct option is (a)
changed without changing the actual parameter x 7. The most appropriate matching for the following
and y since the scope of ‘a’ and ‘b’ lies within the pairs
function but not in main program of value x and y.
X: m = malloc (5); m = NULL
Hence, the correct option is (d)
Y: free (n); n - > value = 5;
5. Assume the following C variable declaration
Z: char *p;*p = ’a’;
int * A [10], B [10][10];
Is:
Of the following expressions
1: using dangling pointers
I. A[2] II. A[2][3]
III. B[1] IV. B[2][3] 2: using uninitialized pointers
Which will not give compile time errors if used 3. Lost memory
as left hand sides of assignment statements in a C (a) X - 1 Y - 3 Z - 2
program? [2003] (b) X - 2 Y - 1 Z - 3
(a) I, II and IV only (c) X - 3 Y - 2 Z - 1
(b) II, III and IV only (d) X - 3 Y - 1 Z - 2 [2000]
(c) II and IV only Solution: (d)
(d) IV only Hence, the correct option is (d)
Solution: (a) 8. Consider the following C declaration
two dimensional array is represented by B [10] Struct {
[10] where B [1] represents address so it cannot be
Short s [5];
written on left hand side of assignment operators,
however, remaining I, II and IV represents the val- Unión {
ues so can be written on left hand side of assign- Float y;
ment operator. Long z;
Hence, the correct option is (a) } u;
} t;

Gate_CSE_Unit8_Programming Languages Folder.indb 25 11/19/2015 5:03:10 PM


8.26 | Programming Languages

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

Gate_CSE_Unit8_Programming Languages Folder.indb 26 11/19/2015 5:03:10 PM


Chapter 3  Programming In C (Part II)  |  8.27

(a) 18 (b) 19 Solution: 


(c) 21 (d) 22 S2: on execution the code will generate a runtime
Solution: (b) error on line L1.
c b S3: on execution the code will generate a runtime
*b error on line L@.
7 4 *ppz
5
Hence, the correct option is (c)
*py 100
5. Consider the following C program segment:
**a *a  [2004]
Char p[20];
py 10 10
0 1
20 20
ppz Char *s = ”string”;
100 0 1
200 Int length = strlen (s);
a
f (c, b, a) For (i = 0;i < length;i + + )
P[i] = s[length –i];
Int f (int x, int *py, int **ppz) Printf(“%s”, p);
The output of the program is
(4,100,200) (a) Gnirts
x y z
(b) String
4 7 5 (c) Gnirt
7
(d) No output is prime
return x + y + z
Solution: (d)
x + y + z = 7 + 7 + 5 = 19 the first character in the array p[20], contains
Output is (b) NULL pointer so while compile executing the
array P[20], it reads first character which is NULL
Hence, the correct option is (b) character assuming that it is the end of string so no
4. Consider this C code to swap two integers and output is printed.
these five statements: the code [2006] Hence, the correct option is (d)
6. Consider C program shown below [2003]
Void swap (int * px, int *py) {
*px = *px - *py; #include < stdio.h >
*py = *px + *py;
*px = *py - *px; #define print(x) printf(“%d”, x)
} Int x;
Void Q(intz){
S1: will generate a compilation error
z + = x;print(z);
S2: may generate a segmentation fault at runtime
}
depending on the arguments passed.
VoidP(int *y) {
S3: correctly implements the swap procedure for
all input pointers referring to integers stored in Int x = *y + 2;
memory locations accessible to the process Q(x);*y = x - 1;
S4: implements the swap procedure correctly for Print(x);
some but not all valid input pointers }
S5: may add or subtract integers and pointers The output of this program is
(a) S1 (b) S2 and S3 (a) 1 2 7 6 (b) 22 12 11
(c) S2 and S4 (d) S2 and S5 (c) 14 6 6 (d) 7 6 6

Gate_CSE_Unit8_Programming Languages Folder.indb 27 11/19/2015 5:03:10 PM


8.28 | Programming Languages

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)

Gate_CSE_Unit8_Programming Languages Folder.indb 28 11/19/2015 5:03:10 PM


Chapter 3  Programming In C (Part II)  |  8.29

Five-marks Questions Abc(“123”);


}
1. consider the following C program: (a) What will be the output of the program?
(b) If abc(s) is called with a null terminated string
Void abc(char *s)
s of length n characters (not counting the null
{ (‘\0’) character), how many characters will be
If (s [0] = = ’\0’) return; printed by abc(s)? [2001]
abc (s + 1); Solution:
abc (s + 1); (a) 332 332 1 (b) (2n - 1)
printf(“%c”, s[0]);
}
Main ()
{

Gate_CSE_Unit8_Programming Languages Folder.indb 29 11/19/2015 5:03:10 PM


This page is intentionally left blank.

Gate_CSE_Unit8_Programming Languages Folder.indb 30 11/19/2015 5:03:10 PM


Unit iX
Digital logic

chapter 1: Number Systems 9.3


chapter 2: Boolean Algebra 9.6
chapter 3: K-Maps 9.15
chapter 4: Combinational Circuits 9.19
chapter 5: Sequential Circuits 9.23

M01_Unit-IX_ME-Gate_C01.indd 1 11/19/2015 11:17:41 AM


M01_Unit-IX_ME-Gate_C01.indd 2
Exam analysis
Exam Year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14

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

∴ number of possible solutions are 3 for: Solution: (b)


Range of numbers (8 bits) in 2’s complement form
x y are −28 to 27 − 1, i.e., −128 to 127.
1 × 30 ∴ smallest integer that can be represented by an
2 × 15 8 bit number in 2’s complement form is −128.
3 × 10 Hence, the correct option is (b).

M01_Unit-IX_ME-Gate_C01.indd 3 11/19/2015 11:17:44 AM


9.4 | Digital Logic

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.

M01_Unit-IX_ME-Gate_C01.indd 4 11/19/2015 11:17:46 AM


Chapter 1 Number Systems | 9.5

Solution: (d) Solution: (c)


Sign extension is done in the case of signed integer (−539)10 is to be converted to 2’s complement
conversion from one size to another. form.
Hence, the correct option is (d). (539)10 = (0010 0001 1011)b.
11. The number 43 in 2’s complement representation 2’s complement = 1101 1110 0100 + 1
is [2000] = 1101 1110 0101
(a) 01010101 (b) 11010101 = (DE5)16.
(c) 00101011 (d) 10101011 Hence, the correct option is (c).
Solution: (c) 3. Zero has two representations in: [1999]
The given number is +43, whose binary represen- (a) Sign magnitude
tation is 00101011. If the number is positive, the (b) 1’s complement
binary representation of the number is same as the (c) 2’s complement
number’s 2’s complement. (d) None of the above
∴ 2’s complement of +43 = 00101011.
Hence, the correct option is (c). Solution: (a) and (b)
Zero has two representations in sign magnitude
because it is neither positive nor negative.
twO-mark QuestiOns It also has two representations in 1’s complement
form.
1. Let A = 1111 1010 and B = 0000 1010 be two 8-bit 4. Given ( 224) r = (13) r
2’s complement numbers. Their product in 2’s
The value of the radix r is: [1997]
complement is
(a) 10 (b) 8
[2004]
(c) 5 (d) 6
(a) 1100 0100
(b) 1001 1100 Solution: (c)
(c) 1010 0101 ( 224) r = (13) r .
(d) 1101 0101
⇒ (224)r = (13) .
2
Solution: (a) r
⇒ 2r2 + 2r + 4 = (r + 3)2.
A = 1111 1010.
⇒ 2r2 + 2r + 4 = r2 + 6r + 9.
2’s complement of A = 0000 0101 + 1
⇒ r2 − 4r − 5 = 0.
= 0000 0110
⇒ r2 − 5r + r − 5 = 0.
= (−6)d.
⇒ r (r − 5) + (r − 5) = 0.
B = 0000 1010.
⇒ (r + 1) (r − 5) = 0.
2’s complement of B = 0000 1010 (∵ B is +ve, so
⇒ r = −1 or r = 5.
its 2’s complement is same as the number).
Since radix can’t be negative, ∴ r = 5.
A × B = (−60)d.
Also, all digits are less than 5.
Now (60)d = (0011 1100)b.
Hence, the correct option is (c).
2’s complement of product = 1100 0011 + 1 (= 1’s
complement + 1) 5. Consider the number given by the decimal
= 1100 0100. expression.
Hence, the correct option is (a). 163 × 9 + 162 × 7 + 16 × 5 + 3.
The number of 1’s in the unsigned binary represen-
2. The 2’s complement representation of (−539)10 in
tation of the number is _______
hexadecimal is
[1990]
[2001]
(a) ABE Solution: 163 × 9 + 162 × 7 + 16 × 5 + 160 × 3
(b) DBC = (9753)16
(c) DE5 = (1001 0111 0101 0011)2.
(d) 9E7 Number of 1’s in unsigned binary representation = 9.

M01_Unit-IX_ME-Gate_C01.indd 5 11/19/2015 11:17:48 AM


Chapter 2
Boolean Algebra

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

M02_Unit-IX_ME-Gate_C02.indd 6 11/19/2015 11:02:40 AM


Chapter 2 Boolean Algebra | 9.7

Regrouping the 1′s, we get F = PQ + QS + QR. (c) A A


AB + AB = A ⊗
• B
Hence, the correct option is (a).
4. Which one of the following expressions does NOT B
represent exclusive NOR of x and y?
(d)
[2013]
A AB AB
(a) xy + x ′y ′ (b) x ⊕ y′
(c) x′ ⊕ y (d) x′ ⊕ y′ 0 1
B
Solution: (d) B

NOR output considering optima AB

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

M02_Unit-IX_ME-Gate_C02.indd 7 11/19/2015 11:02:56 AM


9.8 | Digital Logic

QR 10. Consider the following Boolean function with four


00 01 11 10
P variables
0 1 F(w, x, y, z) = Σ(1, 3, 4, 6, 9, 11, 12, 14) the
0 1 2 2
function is [2007]
1 1 1 1
4 5 7 6 (a) Independent of one variable
(b) Independent of two variables
From the k-map, F(P, Q, R) = Σm(2, 4, 6, 7) (c) Independent of three variables
= m2 + m4 + m6 + m7. (d) Depends on all variables
Hence, the correct option is (a).
Solution: (b)
8. What is the minimum number of gates required to f(w, x, y, z) = Σ(1, 3, 4, 6, 9, 11, 12, 14).
implement the Boolean function (AB + C) if we
have to use only 2-input NOR gates? [2009] yz
(a) 2 (b) 3 wx 00 01 11 10
(c) 4 (d) 5 00 1 1
Solution: (b)
AB + C 01 1 1
= (C + A) (C + B)
= (C + A) + (C + B) 11 1 1

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)

M02_Unit-IX_ME-Gate_C02.indd 8 11/19/2015 11:03:05 AM


Chapter 2 Boolean Algebra | 9.9

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

M02_Unit-IX_ME-Gate_C02.indd 9 11/19/2015 11:03:20 AM


9.10 | Digital Logic

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

R = w′y′z′ + w x′y′ + xyz + x y′z 00


= Σm(0, 4, 8, 9, 7, 15, 5, 13)
= f. 01 1 1

S = x′y′z′ + w x′y′ + w′y 11 1 1 1


= Σm(0, 8, 9, 5, 7)
≠ f. 10 1 1
Hence, the correct option is (d).
f = xz + wxy + wxy
5. Consider a Boolean function (w, x, y, z). Suppose
that exactly one of its inputs is allowed to change = xzw + xzw + xzy + xzy + wxy + wxy.
at a time. If the function happens to be true for two yz
input vectors i1 = < w1, x1, y1 z1 > and i2 = < w2, x2, wx 00 01 11 10
y2, z2 >, we would like the function to remain true 00
as the input changes from i1 to i2 (i1 and i2 differ in
exactly one bit position), without becoming false 01 1 1
momentarily. Let f(w, x, y, z) = Σ(5, 7, 11, 12, 13,
15). Which of the following cube covers of f will 11 1 1 1
entire that the required property is satisfied?
[2006] 10 1 1
(a) wxz , wxy , xyz , xyz , wyz
(b) wxy, wxz, wyz f = wxz + wxy + xyz + wxy + wxz + wyz + xyz .
(c) wxyz , xz , wxyz
6. Which are the essential prime implicants of the
(d) wzy , wyz , wxz , wxz , xyz , xyz following Boolean function?
Solution: (a) f(a,b,c) = a′c + ac′+b′c [2004]
f(w, x, y, z) = Σm(5, 7, 11, 12, 13, 15) (a) a′c and ac′ (b) a′c and b′c
yz (c) a′c only (d) ac′ and bc′
00 01 11 10
wx Solution: (a)
00 f(a, b, c) = a′c + ac′ + b′c
bc
01 1 1
a 00 01 11 10
11 1 1 1
0 1 1
10 1 1
1 1 1 1

M02_Unit-IX_ME-Gate_C02.indd 10 11/19/2015 11:03:31 AM


Chapter 2 Boolean Algebra | 9.11

Essential prime implicants are a′c + ac′ because


they are the ones not being grouped twice in the
k-map implementation.
Hence, the correct option is (a).
7. f(A,B) = A′ + B
Simplified expression for function
f((x + y, y),z) is [2002]
(a) (x′ + z)
Solution: A bubbled OR gate is an NAND gate.
(b) x y z
(c) xy′ + z Inserting a NAND gate
as an inverter
(d) None of the above
Solution: (c)
f(A, B) = A′ + B.
f((x + y, y), z) = [ f((x + y), y)]′ + z
= ((x + y)′ + y)′ + z
= (x′y′ + y)′ + z
= (x′y′)′·y′ + z (
∵A ⋅B = A + B )
= (x + y) · y′ + z
= xy′ + yy′ + z
= xy′ + z (∵ A A = 0) .
Hence, the correct option is (c). Ans.
8. Consider the following logic circuit whose inputs
are functions f1, f2, f3, and output is f
Given that
f1(x,y,z)
f2(x,y,z) f (x,y,z)

10. The simultaneous equations on the Boolean vari-


f3(x,y,z) = ? ables x, y, z and w,
x+y+z=1
f1(x, y, z) = Σ(0, 1, 3, 5) xy = 0
f2(x, y, z) = Σ(6, 7) xz + w = 1
f (x, y, z) = Σ(1, 4, 5) f, is [2002] xy + zw = 0
(a) Σ(1, 4, 5) (b) Σ(6, 7) have the following for x, y, z and w, respectively.
(c) Σ(0, 1, 3, 5) (d) None of the above [2000]
Solution: (a) (a) 0100 (b) 1101
f = f1 ⋅ f 2 ⋅ f 3 = f1 ⋅ f 2 + f 3 (c) 1011 (d) 1000
Solution: (c)
= f1 f 2 + f 3
⇒ Σ(1, 4, 5) = Σ(0, 1, 3, 5) Σ(6, 7) + f3 x+y
= f3. x y z w + z xy xz + w xy + z w options
Hence, the correct option is (a). (a) 0 1 0 0 1 0 0 1 ×
9. Transform the following logic circuit (without (b) 1 1 0 1 1 1 1 1 ×
expressing its switching function) into an equiva-
(c) 1 0 1 1 1 0 1 0 √
lent logic circuit that employs only 6 NAND gates
each with 2-inputs. [2002] (d) 1 0 0 0 1 0 0 1 ×

M02_Unit-IX_ME-Gate_C02.indd 11 11/19/2015 11:03:38 AM


9.12 | Digital Logic

11. Which of the following sets of component(s) is/ (c) xz is an implicit of f


are sufficient to implement any arbitrary Boolean (d) y is a prime applicant of f
function? [1999]
(a) XOR gates, NOT gates Solution: (d)
(b) 2 to 1 multiplexers f ( x , y , z ) = x + yx + xz .
(c) AND gates, XOR gates yz
(d) Three-input gates that output x 00 01 11 10
(A·B) + C for the inputs A, B and C.
0 1 1 1 1
Solution: (b) and (c)
Three input gate that outputs (AB) + C only cannot 1 1 1 1
implement all Boolean functions.
XOR gates and NOT cannot be used either, because ⇒ f = x + y + z.
the only output derived can be A ⊕ B and its ‘Not’. x , y and z are prime applicants of f.
Not all Boolean functions can be implemented
x , y and z are minters of f.
using there. 2 × 1 MUX can implement any arbitrary
Boolean function by multiplexing one function at a Hence, the correct option is (d).
time. XOR and AND gates can form a combination 14. Two NAND gates having open collector outputs
of NAND and NOR, which are universal gates. are tied together as shown in figure. The logic
12. Consider the logic circuit shown in the below function Y, implemented by the circuit is [1990]
figure. The functions. f1 f2 and f (in canonical sum A
B
of products form in decimal notations) are: C
f1
f
f2 Y

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

M02_Unit-IX_ME-Gate_C02.indd 12 11/19/2015 11:03:51 AM


Chapter 2 Boolean Algebra | 9.13

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

A 3. Express the function f (x, y, z) = (xy′ + yz) with only


Output one complement operation and one more AND/
OR operations. Draw the logic circuit implement-
C
ing the expression obtained using a single NOT
D
B gate and one or more AND/OR gates. [2002]

2. Consider the following circuit composed of XOR Solution:


gates are non-inverting buffers. F(x, y, z) = xy′ + yz′
= xy′ + yz′ + xz′
A = x ( y′ + z′) + y( y′ + z′)
= (x + y) ( y′ + z′)
d1 = 2 d2 = 4
= (x + y) ( yz ).

M02_Unit-IX_ME-Gate_C02_(FMQ).indd 13 11/19/2015 11:01:45 AM


9.14 | Digital Logic

x 6. Find the minimum product of sums of the follow-


y ing expression
f

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

M02_Unit-IX_ME-Gate_C02_(FMQ).indd 14 11/19/2015 11:01:51 AM


Chapter 3
K-Maps

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

M03_Unit-IX_ME-Gate_C03.indd 15 11/19/2015 11:00:41 AM


9.16 | Digital Logic

wx In SOP form, F = y′z + yx


00 01 11 10
yz = xy + y′z.
00 0 1 1 0 Hence, the correct option is (a).
01 X 0 0 1
5. Which of the following functions implements the
Karnaugh-map shown below? [1999]
11 X 0 0 1 CD
AB 00 01 11 10
10 0 1 1 X
00 0 0 1 0
Solution: (d)
01 X X 1 X
wx
yz 00 01 11 10 11 0 1 1 0
00 1 1 1
10 0 1 1 0
01 X
(a) AB + CD
11 X
(b) D(C + A)
10 1 1 X (c) AD + AB
(d) (C + D(C + D)(A + B)
In SOP form, F = xz′ + x′z. Solution: (b)
Hence, the correct option is (d). CD
AB 00 01 11 10
4. Given the following Karnaugh-map, which one
of the following represents the minimal sum-of- 00 1
products of the map? [2001]
01 X X 1 X
wx
yz 00 01 11 10 11 1 1
00 0 X 0 X
10 1 1
01 X 1 X 1
In SOP form, F = (D + A)
11 0 X 1 0
= D (A +C).
10 0 1 X 0 CD
AB 00 01 11 10

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

M03_Unit-IX_ME-Gate_C03.indd 16 11/19/2015 11:00:48 AM


Chapter 3 K-Maps | 9.17

ab In SOP form, for minimum literal count, f = yw + x zw + xyz


cd 00 01 11 10
f = yw + x zw + xyz literal count = 8.
00 1 X X 1
zw
01 X 1 xy 00 01 11 10

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.

M03_Unit-IX_ME-Gate_C03.indd 17 11/19/2015 11:00:57 AM


9.18 | Digital Logic

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

In POS form, f = (x + w) · ( y) Solution: (c)


For POS form, transforming the given k-maps we get,
= (x + w) · (y + x) · (y + x)
= (x + w) ( y + w) (y + w) AB
CD 00 01 11 10
= (x + w) (w + y) (x + y).
All the given options are wrong. 00 0 0
Hence, the correct option is (d).
01 0 0
4. What is the equivalent Boolean expression in
product-of-sums form for the Karnaugh-map 11 0 0
given in figure? [1996]
(a) ( BD ) ⋅ ( BD ) 10 0 0
(b) ( B + C + D ) ⋅ ( B + C + D )
(c) ( B + D ) ⋅ ( B + D ) F = ( B + D) ⋅ ( B + D)
(d) ( B + D ) ⋅ ( B + D ) Hence, the correct option is (c).

M03_Unit-IX_ME-Gate_C03.indd 18 11/19/2015 11:01:06 AM


Chapter 4
Combinational Circuits

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

M04_Unit-IX_ME-Gate_C04.indd 19 11/19/2015 11:07:15 AM


9.20 | Digital Logic

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

The minimal sum-of-products form of the Boolean y [2006]


expression for the output F of the multiplexer is
[2014] (a) xz + xy + yz (b) xz + xy + yz
(a) PQ + QR + PQR (c) xz + xy + yz (d) xz + xy + yz
(b) PQ + PQR + PQR + PQR Solution: (a)
(c) PQR + PQR + QR + PQR x y z MUX1 f
(d) PQR 0 1 0 0 0 0
Solution: (a) 0 1 0 1 1 1
P Q R f 0 0 1 0 0 0
0 0 1 1 0 0
0 0 0 0
1 1 0 0 1 1
0 0 1 0 ⇒0
1 1 0 1 1 1
0 1 0 1
1 0 1 0 1 1
0 1 1 1 ⇒1 1 0 1 1 0 1
1 0 0 0 yz
1 0 1 1 ⇒R x 00 01 11 10
1 1 0 1 0 1
1 1 1 0 ⇒R
1 1 1 1 1
dR
P 00 01 11 10 f = x + yz
0 1 1
= xz + xy + yz
1 1 1 = xz + xy + yz.

f = PQ + QR + PQR . Hence, the correct option is (a).


4. Consider the ALU shown below
Hence, the correct option is (a). K
B1 B0
A1 A0
2. Suppose only one multiplexer and one inverter
are allowed to be used to implement any Boolean
function of n variables. What is the minimum size
of the multiplexer needed? [2007]
(a) 2n line to 1 line C1 C0
Full adder Full adder
(b) 2n + 1 line to 1 line
(c) 2n − 1 line to 1 line
(d) 2n − 2 line to 1 line S1 S0

M04_Unit-IX_ME-Gate_C04.indd 20 11/19/2015 11:07:26 AM


Chapter 4 Combinational Circuits | 9.21

If the operands are in 2’s complement represen- x y y = A1 z = A0 f


tation, which of the following operations can be
0 0 1 0 0=y
performed by suitably setting the control lines K
0 0 1 1 1=y
and C0 only (+ and − denote addition and subtrac-
0 1 0 0 0=x
tion respectively)? [2003]
0 1 0 1 0=x
(a) A + B, and A − B, but not A + 1 1 0 1 0 0=y
(b) A + B, and A + 1, but not A − B 1 0 1 1 1=y
(c) A + B, but not A − B, or A + 1 1 1 0 0 1=x
(d) A + B, and A − B, and A + 1 1 1 0 1 1=x
Solution: (d) f = x′y′z + xy′z + xyz′ + xyz
The given circuit is a binary parallel adder subtrac- = y′z (x + x′) + xy (z + z′)
tor which can perform A + B, A − B and A + 1 when = y′z + xy.
B = 0. Hence, the correct option is (a).
Hence, the correct option is (d). 6. Consider the circuit shown below. The output of a
5. Consider the following multiplexer where 10, 11, 2:1 MUX is given by the function (ac + be)
12, 13 are four data input lines selected by two 1 a 2:1 a 2:1 f
address line combinations A1A0 = 00, 01, 10, 11 Mux g Mux
0 b c b c
respectively and f is the output of the multiplex
(or). EN is the enable input. x1 x2

Which of the following is true? [2001]


x I0 4 to 1
Multiplexer
(a) f = x1′ + x2 (b) f = x1′ x2 + x1x2
I1 (c) f = x1 x2 + x1′ x2 (d) f = x1 + x2
y I2 Solution: (c)
F(x,y,z ) = ?
I3 Output When x1 = 0, g = 1 = a.
When x1 = 1, g = 0 = b.
A1
For x2 = 0, f = g = a and for x2 = 1, f = x1 = b.
z A0
x1 x2 g f
EN
0 0 1 g=1
0 1 1 x1 = 0
The function f(x, y, z) implemented by the above 1 1 0 x1 = 1
circuit is [2002] 1 0 0 g=0
(a) xyz′ ∴ f = x 1x 2 + x 1¢ x ¢2 .
(b) xy + z
(c) x + y Hence, the correct option is (c).
(d) None of the above 7. b3 b2 b1 b0

Solution: (a) ‘φ’ ‘φ’ ‘φ’


A1 A0
f
y z
4-Bit
0 0 I0 = x Cout Cin ‘φ’
binary
0 1 I1 = x adder

1 0 I2 = y
1 1 I3 = y
Tabulating for different values of x, y and z d4 d3 d2 d1 dφ

M04_Unit-IX_ME-Gate_C04.indd 21 11/19/2015 11:07:32 AM


9.22 | Digital Logic

Consider the circuit in figure which has a four bit (c) A ⊕ B ⊕ C


binary number b3 b2 b1 b0 as input and a five bit (d) AB + BC + CA
binary number d3 d2 d1 d0 as output. The circuit im- Solution: (c)
plements: [1996] The truth table for the multiplexer is
(a) Binary to Hex conversion
(b) Binary to BCD conversion A B C f
(c) Binary to grey code conversion 0 0 0 0 ⇒C
(d) Binary to radix-12 conversion 0 0 1 1
0 1 0 1
Solution:
The operation performed by 4 bit binary adder is 0 1 1 0 ⇒C
1 0 0 1
b3 b2 b1 b0 1 0 1 0 C
+ 0 b2 b3 0 0 1 1 0 0
1 1 1 1 ⇒C
dy d3 d2 d1 d0
( carry )
f = ABC + ABC + ABC + ABC
b3 b2 b1 b0 d4 d3 d2 d1 d0 = A( BC + BC ) + A( BC + BC )
0 0 0 0 → 0 0 0 0 0 = A( B ⊕ C ) + A( B  C )
0 0 0 1 → 0 0 0 0 1
= A( B ⊕ C ) + A( B ⊕ C )
0 0 1 0 → 0 0 0 1 0
0 0 1 1 → 0 0 0 1 1 = A ⊕ B ⊕ C.
0 1 0 0 → 0 0 1 0 0 9. Fill in the blanks:
0 1 0 1 → 0 0 1 0 1 In the two bit full-adder/subtractor unit shown
0 1 1 0 → 0 0 1 1 0 in figure, when the switch is in position 2.
0 1 1 1 → 0 0 1 1 1 ______________using.__________.arithmetic.
1 0 0 0 → 0 1 0 0 0 [1990]
1 0 0 1 → 0 1 0 0 1 Solution: When switch is in position 2, B is sub-
1 0 1 0 → 0 1 0 1 0 tracted from A, and Cin gets added to the result,
1 0 1 1 → 0 1 0 1 1
i.e., A 1A 0 + B1B 0 + C in which is subtraction using
1 1 0 0 → 1 0 0 0 0
1 1 0 1 → 1 0 0 0 1 2’s complement arithmetic.
1 1 1 0 → 1 0 0 1 0 B is subtracted
1 1 1 1 → 1 0 0 1 1 from A
A1 A0 B1 B0 2’s complement
After 1011, output becomes 0000 with a carry bit.
MOD-12 conversion is being performed.
8. Considering the circuit in figure shown f
implements [1996]

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

M04_Unit-IX_ME-Gate_C04.indd 22 11/19/2015 11:07:37 AM


Chapter 5
Sequential Circuits

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

M05_Unit-IX_ME-Gate_C05.indd 23 11/19/2015 10:58:03 AM


9.24 | Digital Logic

Solution: (c) 2. If all the flip-flops were reset to 0 at power on,


S Q what is the total number of distinct outputs (states)
represented by PQR generated by the counter?
(a) 3 (b) 4
R Q
(c) 5 (d) 6
If S = 0 and R = 0, Output of NAND gate = 1
Solution: (b)
irrespective of what R and Q previously were.
As soon as PQR = 100, the counter resets.
∴ Q = 1 and Q = 1.
∴ number of distinct output states = 4.
Hence, the correct option is (c).
Hence, the correct option is (b).
3. If at some instance prior to the occurrence of the
twO-mark QuestiOns clock edge P, Q and R have a value 0, 1 and 0
1. The above synchronous sequential circuit built respectively, what shall be the value of PQR after
using JK flip-flops is initialized with Q2 Q1 Q0 = the clock edge?
000. The state sequence for this circuit for the next (a) 000 (b) 001
3 clock cycles is _____ [2014] (c) 010 (d) 011
(a) 001, 010, 011
(b) 111, 110, 101 J Q2 J Q J Q0
(c) 100, 110, 111 C C C
(d) 100, 011, 001 K Q2 K Q1 K Q0
Solution: (c)

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

M05_Unit-IX_ME-Gate_C05.indd 24 11/19/2015 10:58:08 AM


Chapter 5 Sequential Circuits | 9.25

Solution: (a) (a) 000 (b) 001


Trace from initial solution (c) 010 (d) 101
X = 101. Solution: (c)
L = |X| = 3 inputs.
Hence, the correct option is (a). Clock cycles data bit q0 q1 q2
5. The control signal functions of a 4-bit binary 0 − 0 0 0
counter are given below (where X is “don’t care”): 1 1 1 1 1
Clear Clock Load Count Function 2 0 0 1 1
1 X X X Clear to 0 3 0 0 1 1
0 X 0 0 No change 4 1 1 0 0
0 ↑ 1 X Load input 5 1 1 1 1
0 ↑ 0 1 Count next 6 0 0 1 0
The counter is connected as follows: 7 0 0 1 0
8 0 0 1 0
9 0 0 1 0
Hence, the correct option is (c).
Count = 1
7. Consider the partial implementation of a 2-bit
4-bit counter Load = 0
Clear counter using T flip-flops following the sequence
Clock 0-2-3-1-0, as shown below.

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

M05_Unit-IX_ME-Gate_C05.indd 25 11/19/2015 10:58:13 AM


9.26 | Digital Logic

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

M05_Unit-IX_ME-Gate_C05.indd 26 11/19/2015 10:58:18 AM


Chapter 5 Sequential Circuits | 9.27

for the JK inputs of the flip-flops is negligible.


P
1
Q

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

M05_Unit-IX_ME-Gate_C05.indd 27 11/19/2015 10:58:21 AM


9.28 | Digital Logic

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

(a) Draw a state diagram which is implemented FF1


by the circuit. Use the following names for the
J0 Q0 J1 Q1 J2 Q2
states corresponding to the values of flip-flops
FF0 FF1 FF2
as given below.
K0 Q0 K1 Q1 K2 Q2
1
1
Q1 Q2 Q3 State
0 0 0 S0
What is the modulus of the counter with initial
0 0 1 S1 state Q2 Q1 Q0 = 000? [1990]
– – – – (a) 3
– – – – (b) 4
(c) 5
– – – – (d) 6
1 1 1 S7
Solution: (c)
(b) Given that the initial state of the circuit is S4, (present (Next
identify the set of states which are not reach- state) state) 
able. [1996] Q2 Q1 Q0 J 2 K 2 J1 K1 J 0 K 0 Q2 Q1 Q 

Solution: (a) 0 0 0 1 1 0 1 0 1 1 0 0

Q1 Q2 Q3 state Q1 Q2 Q3 (Next state) 1 0 0 1 1 1 1 1 1 0 1 1  mod 5
0 0 0 S0 0 0 0 S0  counter
0 1 1 0 1 0 0 1 1 0 1 0
0 0 1 S1 1 0 0 S4 0 1 0 0 1 0 1 1 1 0 0 1

0 1 0 S2 1 0 1 S5 0 0 1 0 1 0 0 0 1 0 0 0
0 1 1 S3 0 0 1 S1
1 0 0 S4 0 1 0 S2
1 0 1 S5 1 1 0 S6
1 1 0 S6 1 1 1 S7
1 1 1 S7 0 1 1 S3

M05_Unit-IX_ME-Gate_C05_(FMQ).indd 28 11/19/2015 10:57:15 AM


UNIT X
COMPUTER ORGANIZATION

Chapter 1: Computer Arithmetic 10.3


Chapter 2: Memory Organization 10.8
Chapter 3: Pipeline 10.17
Chapter 4: CPU Organization 10.23
Chapter 5: Control Unit Design 10.30
Chapter 6: I/O Organization 10.32
Chapter 7: Secondary Memories 10.36
Chapter 8: Register Allocation 10.39

Gate_CSE_Unit10_Computer Oranization.indb 1 11/19/2015 6:44:07 PM


Gate_CSE_Unit10_Computer Oranization.indb 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 1 0 0 4 3 2 2 1 2 2 4 1 4 2 2 1 1 2 1 1 3 1 1
2 Marks Ques. 0 0 0 1 1 0 0 0 0 1 0 0 4 1 3 3 3 7 9 10 4 12 4 3 6 2 9 11
5 Marks Ques. 0 0 0 1 0 0 0 0 0 2 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 0 0 0 7 2 1 0 0 4 15 2 2 19 14 18 10 7 18 20 22 9 25 10 7 13 7 19 23

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

113. + (-111. + 7.51)


One-mark Questions (a) 9.51 & 10.0 respectively
(b) 10.0 & 9.51 respectively
1. The decimal value 0.5 in IEEE single precision (c) 9.51 & 9.51 respectively
floating point representation has [2012] (d) 10.0 & 10.0 respectively
(a) fraction bits of 0000….0000000 and exponent
value ‘0’. Solution: (a)
(b) fraction bits of 0000….0000000 and exponent + 2.00 + 7.51 = + 9.51
value -1. 113 + (-103) = 10.0
(c) fraction bits of 10000…0000000 and expo- Hence, the correct option is (a)
nent value 0.
(d) no exact representation. 4. In 2’s complement addition, the overflow [2002]
(a) is flagged whenever there is a carry from sign
Solution: (b) bit addition.
0.5 = 0.102 = 0.10x20 (b) cannot occur when a + ve value is added to a –
Implicit normalization form = 1.00 × 2-1 so frac- ve value.
tion is having with all zero’s and exponent is -1. (c) is flagged when carries from sign bit & previ-
Hence, the correct option is (b) ous bit match .
(d) None of the above
2. In the IEEE floating point representation, the
hexadecimal value 0 × 00000000 corresponds to Solution: (b)
 [2008] There is no overflow because addition of one
(a) the normalized value 2 -127 positive and negative number gives subtraction
(b) the normalized value 2 -126 operation.
(c) the normalized value + 0 Hence, the correct option is (b)
(d) the special value + 0 5. An N-bit carry look ahead adder, where n is a
Solution: (d) multiple of 4, employs Ics 74181 (4-bit ALU)
In the case where mantissa and exponent have all and 74182 (4-bit carry look ahead generator). The
zero’s then it is used to represent + 0. minimum addition time using the best architecture
Hence, the correct option is (d) for this adder is [1997]
(a) Proportional to N
3. What is the result of evaluating the following two (b) Proportional to log N
expression using three-digit floating point arith- (c) A constant
metic with rounding? [2004] (d) None of the above
(11.3 + -111.) + 7.51

Gate_CSE_Unit10_Computer Oranization.indb 3 11/19/2015 6:44:07 PM


10.4 | Computer Organization

Solution: (a) 2. In a look-ahead carry generator, the carry generate


One IC can provide only for 4-bits. So, the addi- function Gi and the carry propagate function Pi for
tion time is directly proportional to number of inputs, Ai and Bi are given by Pi = Ai ⊕ Bi and Gi
chips. = AiBi.
Hence, the correct option is (a) The expression for the sum bit Si and carry bit Ci +
1 of the look ahead carry adder are given by Si = Pi
6. Booth’s Algorithm for integer multiplication gives
⊕ Ci and Ci + 1 = Gi + PiCi, where C0 is the input
worst performance when the multiplier pattern is
carry.
 [1996]
(a) 101010…..1010 (b) 100000…..0001 Consider a two-level logic implementation of the
(c) 111111…..1111 (d) 011111…..1110 look-ahead carry generator. Assume that all Pi and
Gi are available for the carry generator circuit and
Solution: (a)
that the AND and OR gates can have any number
In Booth multiplier, more number of consecutive bit of inputs. The number of AND gates and OR gates
changes need more number of arithmetical operation. needed to implement the look-ahead carry genera-
Hence, the correct option is (a) tor for a 4-bit adder with S3, S2, S1, S0 and C4 as
its outputs are, respectively. [2007]
(a) 6, 3 (b) 10, 4
Two-marks Questions (c) 6, 4 (d) 10, 5
Solution: (b)
1. The value of a float type variable is represented
using the single-precision 32-bit floating point for- Four number of carries are needed to design CLG
mat of IEEE-754 standard that uses 1-bit for sign, For C1 one AND gates + one OR gate
8-bit for biased exponent and 23-bits for mantissa. For C2 two AND gates + one OR gate
A float type variable X is assigned the decimal
For C3 three AND gates + one OR gate
value of -14.25. The representation of X in hexa-
decimal notation is [2014] For C4 four AND gates + one OR gate
(a) C1640000H (b) 416C0000H So, total ten AND gates are needed and four OR
(c) 4160000H (d) C16C000H gates are needed.
Solution: (a) Hence, the correct option is (b)
-14.25 S = 1e = original exponent 3. Given two three bit number a2a1a0 and b2b1b0 and c,
E = Biased exponent the carry in, the function that represents the carry
generate function when these two numbers are
b = biasing amount
added, is [2006]
14.25 = 1110.01 x 20 (a) a2b2 + a2a1b1 + a2a1a0b0 + a2a0b1b0 +
= 1.11001 x 23 a1b2b1 + a1a0b2b0 + a0b2b1b0
e = 3, E = 3 + 127 = 130 (b) a2b2 + a2b1b0 + a2a1b1b0 + a1a0b2b1 +
a1a0b2 + a1a0b2b0 + a2a0b1b0
130 = 10000010 M = 1100100….0(23 bits)
(c) a2 + b2 + (a2 ⊕ b2)(a1 + b1 + (a1⊕ b1)
32 bits (a0 + b0))
1100 0001 0110 0100 00........0 Solution: (a)
Hence, the correct option is (a)
S=1 B=8 M = 23 bits
Common Data for Questions 4 and 5 [2005]
C 1 6 4 0 0 .......
C1640000H
The data given below. Solutionve the problem and
choose the correct answer.
Hence, the correct option is (a)

Gate_CSE_Unit10_Computer Oranization.indb 4 11/19/2015 6:44:07 PM


Chapter 1  Computer Arithmetic  |  10.5

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)

Gate_CSE_Unit10_Computer Oranization.indb 5 11/19/2015 6:44:08 PM


10.6 | Computer Organization

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

Solution: (b) The exponent is in 2’s complement representation


First adder is having two inputs and remaining all and mantissa is in the sign magnitude representa-
adders have three inputs, so for LSB, half adder is tion. The range of the magnitude of the normalized
sufficient and full adders are need for remaining mantissa in this representation is [1996]
all. (a) 0 or 1 (b) 0.5 to 1
Hence, the correct option is (b) (c) 2 -23 to 0.5 (d) 0.5 to (1 - 2 -23)
10. Booth’s coding in 8-bits for the decimal number Solution: (d)
-57 is: [1999] Normalized mantissa range is 100000…..0000(23)
(a) 0 - 100 + 1000 To
(b) 0 - 100 + 100 - 1
111111…..11111(23)
(c) 0 - 1 + 100 - 10 + 1
(d) 0 - 10 + 100 - 1 Hence, the correct option is (d)
Solution: (b)
-128  64  32  16   8  4  2  1
 1   1  0  0  0  1  1  1
 0  -1  0  0  +1  0  0  -1
Hence, the correct option is (b)

Gate_CSE_Unit10_Computer Oranization.indb 6 11/19/2015 6:44:08 PM


Chapter 1  Computer Arithmetic  |  10.7

Five-marks Questions Start

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

Gate_CSE_Unit10_Computer Oranization.indb 7 11/19/2015 6:44:08 PM


Chapter 2
Memory Organization

No. of sets in V, M.M block no = J


One-mark Questions
So, 1st line of cache = (j mod V) × K
1. An access sequence of cache block addresses is of Last Line of cache = j mod V × K + (K + 1)
length N and contains n unique block addresses. Hence the correct option is (a)
The number of unique block addresses between
3. The amount of ROM needed to implement a 4-bit
two consecutive accesses to the same block address
multiplier is  [2012]
is bounded above by k. What is the miss ratio if
(a) 64 bits (b) 128 bits
the access sequence is passed through a cache of
(c) 1 Kbits (d) 2 Kbits
associativity A ≥ k exercising least-recently-used
replacement policy? [2014] Solution: (d)
(a) n/N (b) 1/N ROM needed = 16* 16* 8-bits = 2 K bits
(c) 1/A (d) k/n Hence, the correct option is (d)
Solution: (a) 4. A main memory unit with a capacity of 4 mega-
Hence, the correct option is (a) bytes is built using 1M x 1-bit DRAM chips. Each
2. In a k-way set associative cache, the cache is DRAM chip has IK rows of cells with IK cells in
divided into v sets, each of which consists of k each row. The time taken for a single refresh oper-
lines. The lines of a set are placed in sequence ation is 100 ns. The time required to perform one
one after another. The lines in set s are sequenced refresh operation on all the cells in the memory
before the lines in set (s + 1). The main memory unit is  [2010]
blocks are numbered 0 onwards. The main mem- (a) 100 ns (b) 100*210 ns
ory block numbered j must be mapped to any one (c) 100*220 ns (d) 3200*220 ns
of the cache lines from [2013] Solution: (b)
(a) (j mod v)*k to (j mod v)*k + (k - 1) Total number of recharge = total number of
(b) (j mod v) to (j mod v) + (k - 1) rows as for any fresh operation, one row is being
(c) (j mod k) to (j mod k) + (v - l) recharged.
(d) (j mod k) *v to (j mod k)*v + (v - 1)
Hence, the correct option is (b)
Solution: (a)
5. How many 32K × 1 RAM chips are needed to pro-
Position of M.M set in the cache is (MM block no.) vide a memory capacity of 256KB? [2009]
Mod(Total no. of cache sets) (a) 8 (b) 32
As the lines in the set are places in sequence, we (c) 64 (d) 128
can have the cache blocks(lines) from 0 to k - 1 in
each set.

Gate_CSE_Unit10_Computer Oranization.indb 8 11/19/2015 6:44:08 PM


Chapter 2  Memory Organization  |  10.9

Solution: (c) (a) (k mod m) of the cache


Number of RAM chips required = (256K X 8)/ (b) (k mod c) of the cache
(32K X 1) = 64 (c) (k mod 2c) of the cache
(d) (k mod 2cm) of the cache
Hence, the correct option is (b)
Solution: (b)
6. Consider a 4-way set associative cache consist-
ing of 128 lines with a line size of 64 words. The kth block of MM is placed at (k MOD s) set
CPU generates a 20-bit address of a word in main Hence, the correct option is (b)
memory. The numbers of bits in the TAG, SET and 10. A ROM is used to store the table for multiplication
WORD fields are, respectively [2007] of two 8-bit unsigned integers. The size of ROM
(a) 9, 6, 5 (b) 7, 7, 6 required is [1996]
(c) 7, 5, 8 (d) 9, 5, 6 (a) 256 × 16 (b) 64K × 8
Solution: (d) (c) 4K × l6 (d) 64K × l6
Address size = 20 bits Solution: (d)
Word field: 26 = 64 Memory space = 216 × 16 as address size is 16-bit
The set field consists of 5-bits and data size is also 16-bit.
Number of sets = 128/4 = 32 = 25 Hence, the correct option is (d)
So, TAG, SET and WORD fields are 9, 5, 6 11. A ROM is used to store a truth table for a binary
respectively. multiplier unit that will multiply two 4-bit num-
bers. The size of the ROM (number of words x
Hence, the correct option is (d)
number of bits) that is required to accommodate
7. Increasing the RAM of a computer, typical the truth table is M words × N bits. Write the val-
improves performance because  [2005] ues of M and N. [1995]
(a) Virtual memory increases
Solution:
(b) Larger RAMs are faster
(c) Fewer page faults occur (M = 256, N = 8)
(d) Fewer segmentation faults occur 12. The capacity of the memory unit is defined by the
Solution: (c) number of words multiplied by the number of bits/
word. How many separate address and data lines
Main memory is being increased when RAM is
are needed for a memory of 4K × 16? [1995]
increased, so more pages may accommodated
leading to fewer page fault. Solution:
Hence, the correct option is (c) (12 address lines as 4K = 4 × 210 = 212 and data
lines = 16)
8. More than one words are put in one cache block to
 [2001] 13. A computer system has a 4K word cache organ-
(a) exploit the temporal locality of reference in a ized in block set associative manner with four
program. blocks per set, 64 words per block. The number
(b) exploit the spatial locality of reference a pro- of bits in the SET and WORD fields of the main
gram. memory address format is [1995]
(c) reduce the miss penalty. (a) 15, 40 (b) 6, 4
(d) None of the above (c) 7, 2 (d) 4, 6
Solution: (b) Solution: (d)
Hence, the correct option is (b) Block size = 64 words, so word field size = 6
9. The main memory of a computer has 2 cm blocks Bits & associativity is 4, number of blocks = 4K/64
while the cache has 2 c blocks. If the cache uses Number of sets = 64/4 = 16, so set fields size is 4
the set associative mapping scheme with 2 blocks bits.
per set, then block k of the main memory maps to Hence, the correct option is (d)
the set: [1999]

Gate_CSE_Unit10_Computer Oranization.indb 9 11/19/2015 6:44:08 PM


10.10 | Computer Organization

Two-marks Questions size of MUX is direct proportional to associativity


only physical address size and data bus size are not
altered.
1. A 4-way set-associative cache memory unit with
a capacity of 16KB is built using a block size of 8 Hence, the correct option is (d)
words. The word length is 32-bits. The size of the 4. Consider a main memory system that consists of
physical address space is 4 GB. The number of bit 8 memory modules attached to the system bus,
for the TAG field is [2014] which is one word wide. When a write request is
Solution: made, the bus is occupied for 100 nanoseconds
(ns) by the data, address, and control signals.
Associativity = 4
During the same 100 ns, and for 500 ns thereafter,
Cache size = 16 KB the addressed memory module executes one cycle
Block Size = 8 words accepting and storing the data. The (internal) oper-
Word size = 32 bits ation of different memory modules may overlap
in time, but only one request can be on the bus at
So, Number of cache sets = 29 / 22
any time. The maximum number of stores (of one
No. of cache blocks = 16KB/32B = 29 word each) that can be initiated in 1 millisecond is
Block size = 8*4 Bytes = 32 B ___________. [2014]
Physical address size = 32bits Solution:
Tag offset = 20 For one write request, amount of time needed is
Set offset = 7 100ns.
Byte offset = 5 Buses accept one write at a time.
2. In designing a computer’s cache system, the cache So, total number of write operations initiated by
block (or cache line) size is an important param- bus
eter. Which one of the following statements is cor- = given time/ one write operation time
rect in this context? [2014] = 1ms/100ns
(a) A smaller block size implies better spatial lo-
= 10 - 3 / 10 - 7
cality.
(b) A smaller block size implies a smaller cache = 10 4 = 10000.
tag, and hence, lower cache tag overhead. 5. The memory access time is 1 nanosecond for a
(c) A smaller block size implies a larger cache tag, read operation with a hit in cache 2 nanoseconds
and hence, lower cache hit time. for a read operation with a hit in cache, 5 nano-
(d) A smaller block size incurs a lower cache miss seconds for a write operation with a hit in cache
penalty. and 10 nanoseconds for write operation with a
Solution: (d) miss in cache. Execution of a sequence of instruc-
tion involves 100 instruction fetch operations, 60
Hence, the correct option is (d)
memory operand read operations and 40 memory
3. If the associativity of a processor cache is dou- operand write operations. The cache hit ratio is
bled while keeping the capacity and block size 0.9. The average memory access time (in nanosec-
unchanged, which one of the following is guaran- onds) in executing the sequence of instruction is
teed to be NOT affected? [2014] ____________. [2014]
(a) Width of tag comparator
Solution:
(b) Width of set index decoder
(c) Width of way selection multiplexor Time taken for fetching instructions to execute:
(d) Width of processor to main memory data bus 90*1 ns + 10*5ns = 140 ns.
Solution: (d) Time taken by executing instruction :
The number of bits will increased if associativity For memory operand read operation = hit + miss
is doubled and set offset size reduced. Also the = 54*1ns + 6*5ns

Gate_CSE_Unit10_Computer Oranization.indb 10 11/19/2015 6:44:08 PM


Chapter 2  Memory Organization  |  10.11

= 54 ns + 30 ns 8. The size of the cache tag directory is


= 84 ns (a) 160 Kbits (b) 136 Kbits
(c) 40Kbits (d) 32 Kbits
For memory operand read operation = hit + miss
= 36*2ns + 4*10ns Solution: (a)
= 112 ns Number of blocks = 256KB/32 KB = 8K
Total time taken for 100 instructions = 140 + 84 + Number of sets with 4-way set-association = 8K/4
112 = 336ns = 2K
Total number for memory references for fetching 8K (16 + 1 + 2 + 1) bits = 160Kbits.
the instructions and operand read, Hence, the correct option is (a)
Write operations = 100 + 60 + 40 = 200 9. An 8KB direct-mapped write-back cache is organ-
The avg. access time = 336/200 = 1.68 ns. ized as multiple blocks, each of size 32-bytes. The
processor generates 32-bit addresses. The cache
6. A RAM chip has a capacity of 1024 words of
controller maintains the tag information for each
8-bits each (IK × 8). The number of 2 x 4 decoders
cache block comprising of the following:
with enable line needed to construct a 16K × 16
RAM from IK × 8 RAM is [2013] 1 Valid bit
(a) 4 (b) 5 1 Modified bit
(c) 6 (d) 7 As many bits as the minimum needed to identify
Solution: (b) the memory block mapped in the cache.
Basic capacity = 1k*8 What is the total size of memory needed at the
Target size = 16k * 16 cache controller to store meta-data (tags) for the
cache? [2011]
Total number of chips needed = (16k *16)/ (1k*8)
(a) 4864-bits (b) 6144-bits
= 16*2
(c) 6656-bits (d) 5376-bits
Number of rows = 16 with 2 chips per and both
Solution: (d)
chips get enable with single decode output.
Direct mapping,
Number of decoders needed = 5
Total blocks = 256
i.e., 4 slaves + 1 master.
Number of Tag bits = 19
Hence, the correct option is (b)
Tag directory size = (19 + 1 + 1) *256 = 5376 bits.
Common Data for Questions 7 and 8 [2012]
Hence, the correct option is (d)
A computer has a 256 KB, 4-way set associative,
write back data cache with block size of 32 Bytes. Common Data for Questions 10 and 11: [2010]
The processor sends 32-bit addresses to the cache A computer system has an L1 cache, an L2 cache,
controller. Each cache tag directory entry contains, and a main memory unit connected as shown
in addition to address tag, 2 valid bits, 1 modified below. The block size in L1 cache is 4 words. The
bit and 1 replacement bit. block size in L2 cache is 16 words. The memory
7. The number of bit in the tag field of an address is access times are 2 nanoseconds, 20 nanoseconds
(a) 11 (b) 14 and 200 nanoseconds for L1 cache, L2 cache and
(c) 16 (d) 27 main memory unit, respectively.
Solution: (c) L1 Data Bus L2 Data Bus Main
Number of cache blocks = 256kB/32B = 213 Cache 4 words Cache 4 words Memory
Associativity = 4
Number of sets = 213 /4 = 211 10. When there is a miss in L1 cache and a hit in L2
Tag size = 32 - 11 - 5 = 16. cache, a block is transferred from L2 cache to L1
cache. What is the time taken for this transfer?
Hence, the correct option is (c)

Gate_CSE_Unit10_Computer Oranization.indb 11 11/19/2015 6:44:08 PM


10.12 | Computer Organization

(a) 2 nanoseconds (b) 20 nanoseconds for(i=0;j<1024;i++)


(c) 22 nanoseconds (d) 88 nanoseconds for(j=0 j<1024 j++)
Solution: (d) APR[i][j] = 0.0;
A block to access in L2 cache requires 20 nanosec- The size of double 8 bytes. Array APR is in
onds, and 2 seconds to place in L1 cache. memory starting at the beginning of virtual page
The block size in L1 cache is 4 words and there are 0xFF000 and stored in row major order. The cache
total 16 words, so total time is 4*(20 + 2) = 88. is initially empty and no pre-fetching is done. The
Hence, the correct option is (d) only data memory references made by the program
are/those to array APR.
11. When there is miss in both L1 cache and L2 cache,
first a block is transferred from main memory to 13. The total size of the tags in the cache directory is
L2 cache, and then a block is transferred from L2 (a) 32-kbits (b) 34-kbits
cache to L1 cache. What is the time taken for this (c) 64-kbits (d) 68-kbits
transfer? Solution: (d)
(a) 222 nanoseconds Number of blocks = 4k
(b) 888 nanoseconds
TAG directory = 4k*17 = 68 k bits
(c) 902 nanoseconds
(d) 968 nanoseconds Hence, the correct option is (d)
Solution: (d) 14. Which of the following array elements has the
same cache index as APR[0][0]?
4(2 + 20) ns + 4(20 + 200)ns
(a) APR [0] [4] (b) APR [4] [0]
Hence, the correct option is (d) (c) APR[0][5] (d) APR[5][0]
12. Consider a 4-way set-associative cache (initially Solution: (b)
empty) with total 16 cache blocks.
Blocks occupied by each rows = (1024 × 8 B/16B)
The main memory consists of 256 blocks and the = 512 block.
request for memory blocks in the following order:
The total set of checks is 2k.
0, 255, 1, 4, 3, 8, 133, 159, 216, 129, 63, 8, 48, 32,
73, 92, 155 A[4][0] has same cache index as A[0][0].
Which one of the following memory block will Hence, the correct option is (b)
NOT be in cache if LRU replacement policy is 15. The cache hot ratio for this initialization loop is
used?  [2009]  [2008]
(a) 3 (b) 8 (a) 0% (b) 25%
(c) 129 (d) 216 (c) 50% (d) 75%
Solution: (d) Solution: (b)
The cache consists of 4 sets with each set consists 50% on every block - 1 miss and 1-hit.
of 4 blocks. Hence, the correct option is (b)
Hence, the correct option is (d) 16. For inclusion to hold between cache level Ll and
Common Data Question for 13, 14 and 15 [2008] L2 in a multilevel cache hierarchy, which of the
Consider a machine a two-way set associative data following are necessary? [2008]
cache of size 64 KB and block size 16 bytes. The 1. L1 must be write-through cache
cache is managed using 32-bit virtual address and 2. L2 must be write-through cache
the page size is 4 KB. A program to be run-on this 3. The associative of L2 must be greater than of
machine begins as follows: L1
4. The L2 cache must be at least as large as the
Double APR[1024][1024]
L1 cache
Int i, j; (a) 4 only (b) 1 and 2 only
/* Initialize array APR to 0.0 */ (c) 1, 2 and 4 only (d) 1, 2, 3 and 4

Gate_CSE_Unit10_Computer Oranization.indb 12 11/19/2015 6:44:08 PM


Chapter 2  Memory Organization  |  10.13

Solution: (a) P1 : for(i=0;i<512;i++)


The L2 cache must be at least as large as the L1 {
cache as both are write through cache need not be {for (j = 0; j <512;i++)
the necessary condition.
{x+=A[i][j];
Hence, the correct option is (a)
}
Common Data Question for 17 and 18 [2007]
}
Consider a machine with a byte addressable main
P2: for (i = 0; i<512; i++)
memory of 216 bytes. Assume that a direct mapped
data cache consisting of 32 lines of 64 bytes each For (j = 0; j<512; j++)
is used in the system. A 50x50 two-dimensional x+= A[j] [i];}
array of bytes is stored in the main memory start- }
ing from memory location 1100H. Assume that
}
data cache is initially empty. The complete array
is associated twice. Assume that the contents of P1 and P2 are executed independently with the
the data cache do not change in between the two same initial state, namely, the array A is not in the
accesses. cache and i, j, x are in registers. Let the number of
cache misses experienced by P1 be M1 and that for
17. How many data cache misses will occur in total?
P2 be M2.
(a) 48 (b) 50
(c) 56 (d) 59 19. The value of M1 is
(a) 0 (b) 2048
Solution: (c)
(c) 16384 (d) 262144
The cache and main memory are divided into
Solution: (c)
blocks of 64 bytes each. The direct mapped cache
consists of 32 blocks. The array is stored from main [P1] runs the loops in a way that access elements
memory locations 1100H. The array is placed in of A in row major order and [P2] accesses ele-
MM from 68 blocks onwards. The total array con- ments in column major order.
sists of 2500 bytes, so 40 blocks are required. In No of cache blocks = Cache Size/Block Size =
cache all the 32 blocks are filled and the remain- 32KB / 128 Byte = 256
ing 8 blocks are replacing the previous blocks. 40 No. of array elements in Each Block = BlockSize/
data miss will occur during first access. Also as 16 ElementSize = 128 Byte / 8 Byte = 16
blocks are replaced, 16 cache miss will occur.
Total Misses for [P1] = Array Size * (No. of array
Hence, the correct option is (c) elements in Each Block) / (No of cache blocks) =
18. Which of the following lines of the data cache will 512 * 512 * 16 / 256 = 16384
be replaced by new blocks in accessing the array? Hence, the correct option is (c)
(a) line 4 to line 11
20. The value of the ratio M1/M2 is
(b) line 4 to line 12
(a) 0 (b) l/16
(c) line 0 to line 7
(c) 1/8 (d) 16
(d) line 0 to line 8
Solution: (c)
Solution: (a)
M1/ M2 = 16384/512 × 512 = 1/ 16.
The lines 4 to 11 gets conflict misses frequently.
Hence, the correct option is (c)
Hence, the correct option is (a)
Common Data for Question 21 and 22 [2006]
Common Data for Question 19 and 20 [2006]
Consider two cache organizations: The first one
A CPU has a 32 KB direct mapped cache with
is 32 KB 2-way set associate with 32-byte block
128-byte block size. Suppose A is a two dimen-
size. The second one is of the same size but direct
sional array of size 512 x 512 with elements that
mapped. The size of an address is 32-bits in both
occupy 8-bytes each. Consider the following two C
cases. A 2-to-l multiplexer has latency of 0.6 ns
code segments, P1 and P2.

Gate_CSE_Unit10_Computer Oranization.indb 13 11/19/2015 6:44:09 PM


10.14 | Computer Organization

while a k-bit comparator has a latency of k/10 ns. Solution: (d)


The hit latency of the set associative organization The main memory has k-banks and k = 24. Each
is h1 while that of the direct mapped one is h2. bank is 2 bytes wide that is c = 2.
21. The value of h1 is Time required for one parallel access of the bank T
(a) 2.4 ns (b) 2.3 ns = latency + k/2
(c) 1.8 ns (d) 1.7 ns
= 80ns + 24/2 ns = 92 ns.
Solution: (a)
Latency of retrieving cache blocks = no. of bytes*
First cache organization: 32 KB with 2-way set T = 2*92 = 184 ns
associative cache.
Hence, the correct option is (d)
The size of address = 32 bits
24. Consider a direct mapped cache of size 32 KB
Multiplexer latency = 0.6 ns and k-bit comparator with block size 32 bytes. The CPU generates
latency is (k/10) ns. 32-bit addresses. The number of bits needed for
The hit latency of this cache = 0.6 + (18/10) = 2.4 cache indexing and the number of tag bits are,
ns. respectively [2005]
Hence, the correct option is (a) (a) 10, 17 (b) 10, 22
(c) 15, 17 (d) 5, 17
22. The value of h2 is
(a) 2.4 ns (b) 2.3 ns Solution: (c)
(c) 1.8 ns (d) 1.7 ns Cache size is 32 KB = 215, so, 15-bits are required
Solution: (d) to access cache. A block consists of 32 bytes. The
cache can be divided into 1024 blocks(32KB/32
Second cache organization: 32KB with direct
bytes). The CPU generates 32-bits main memory
mapped cache.
address which is further divided in three fields.
The size of address = 32 bits.
TAG(17 bits), Blocks(10 bits) and Word(5 bits)
Only one tag comparator and number of
Hence, the correct option is (c)
multiplexer.
25. Consider a small two-way set-associative cache
The hit latency of this cache = (17/10) = 1.7 ns
memory, consisting of four blocks. For choosing
Hence, the correct option is (d) the block to be replaced, uses the Least Recently
23. A CPU has a cache with block size 64 bytes. The Used (LRU) scheme. The number of cache misses
main memory has k banks, each bank being c bytes for the following sequence of block addresses is 8,
wide. Consecutive c-byte chunks are mapped on 12, 0, 12, 8. [2004]
consecutive banks with wrap-around. All the k (a) 2 (b) 3
banks can be accessed in parallel, but two accesses (c) 4 (d) 5
to the same bank must be serialized. A cache block Solution: (c)
access may involve multiple iterations of parallel
A two set-associative cache memory with 4 blocks
bank accesses depending on the amount of data
is as shown below:
obtained by accessing all the k banks in parallel.
Each iteration requires decoding the bank numbers
to be accessed in parallel and this takes k/2 ns. The Block 0
Set 0
latency of one bank access is 80 ns. If c = 2 and k
= 24, then latency of retrieving a cache block start- Block 1
ing at address zero from main memory is [2006]
Block 2
(a) 92 ns (b) 104 ns
(c) 172 ns (d) 184 ns Set 1
Block 3

Gate_CSE_Unit10_Computer Oranization.indb 14 11/19/2015 6:44:09 PM


Chapter 2  Memory Organization  |  10.15

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?

Gate_CSE_Unit10_Computer Oranization.indb 15 11/19/2015 6:44:09 PM


10.16 | Computer Organization

Five-mark Questions Size Hit ratio

1. A CPU has 32-bit memory address and a 256 KB 8 KB 0.80


cache memory. The cache is organized as a 4-way 16 KB 0.90
set associative cache with cache block size of 16 64 KB 0.95
bytes.
(a) What is the number of sets in the cache? Level 2 (Main memory)
(b) What is the size (in bits) of the tag field per
Access time = 200 nsec/byte
cache block?
(c) What is the number and size of comparators Size Hit ratio
required for tag matching? 4 MB 0.98
(d) How many address bits are required to find the
16 MB 0.99
byte offset within a cache block?
(e) What is the total amount of extra memory (in 64 MB 0.995
bytes) required for the tag bits? [2001]
Solution: Level 3
(a) Number of sets = 256KB/64KB = 4K sets Access time = 5nsec/byte
(b) What is the size of tag field per cache block is
Size Hit ratio
16.
260 MB 1.0
16 12 4
(c) 4 comparators of 16 bit size (i) What should be the minimum size of level 1
(d) Address bits for byte offset 4 bits and 2 memories to achieve an average access
(e) For TAG extra memory = 16K * 16 = 256 bits. time of less than 100 ns?
2. A computer system has a three-level memory hier- (ii)  What is the average access time achieved
archy, with access time and hit ratios as shown using the chosen sizes of level 1 and level 2
below: memories? [1996]
Level 1 (Cache memory) Solution:
Access time = 50 nsec/byte (a) 16 KB, 4MB, 260 MB
(b) 75 ns

Gate_CSE_Unit10_Computer Oranization.indb 16 11/19/2015 6:44:09 PM


Chapter 3
Pipeline

•  he jth and j + 1th instruction requires the


T
One-mark Questions ALU at the same time comes under structural
hazard.
1. Register renaming is done in pipelined processors
 [2012] Hence, the correct option is (d)
(a) as an alternative to register allocation at com- 3. Comparing the time T1 taken for a single instruc-
pile time. tion on a pipelined CPU with time T2 taken on a
(b) for efficient access to function parameters and non-pipelined but identical CPU, we can say that
local variables.  [2000]
(c) to handle certain kinds of hazards. (a) T1 ≤ T2
(d) as part of address translation. (b) T1 ≥ T2
Solution: (c) (c) T1 < T2
(d) T1 is T2 plus the time taken for one instruction
WAR and WAW kind of hazards are handled.
fetch cycle
Hence, the correct option is (c)
Solution: (b)
2. For a pipelined CPU with a single ALU, consider
Time taken for a single instruction on a pipelined
the following situations
CPU will be greater than time taken on a non-
1. The j + 1 instruction uses the result of the j-th
pipelined CPU, as pipelined CPU will have buffer
instruction as an operand
register delays.
2. The execution of a conditional jump instruc-
tion Hence, the correct option is (b)
3. The jth and j + 1 instructions require the ALU
at the same time Two-marks Questions
Which of the above can cause a hazard? [2003]
(a) 1 and 2 only (b) 2 and 3 only 1. Consider a 6-stage instruction pipeline, where all
(c) 3 only (d) All the three stages are perfectly balanced. Assume that there
Solution: (d) is no cycle-time overhead of pipelining. When an
• The j + 1 instruction uses result of jth instruc- application is executing on this 6-stage pipeline,
tion as an operand, comes under data depend- the speed up achieved with respect to non-pipe-
ency & causes data hazards. lined execution if 25% of the instructions incur 2
• The execution of conditional jump instruction pipeline stall cycles is _____ [2014]
comes under conditional dependency. Solution: 4
For n number of instructions

Gate_CSE_Unit10_Computer Oranization.indb 17 11/19/2015 6:44:09 PM


10.18 | Computer Organization

tn = 6 × n clks (k = 6) which execute in the EX stage and produce the


Highest speed up k = 6 if there is no stall cycle and next instruction pointer at the end of the EX stage
all stage delays are equal but 25% of instruction in the old design and at the end of the EX2 stage
need 2 stall. in the new design. The IF stage stalls after fetch-
ing a branch instruction until the next instruction
tp = (0.75n × 1) + (0.25 n × (2 + 1)) = 1.5n clks.
pointer is computed. All instructions other than the
S = tn / tp branch instruction have an average CPI of one in
= 6n clks / 1.5n clks = 4 both the deigns. The execution times of this pro-
2. Consider the following processors ( ns stands for gram on the old and the new design are P and Q
nanoseconds). Assume that the pipeline registers nanoseconds, respectively.
have zero latency. The value of P/Q is_______. [2014]
P1: Four-stage pipeline with stage latencies 1 ns, 2 Solution: 1.54
ns, 2 ns, 1 ns. ‘P’ has five stages(highest clock cycle time = 2.2 ns)
P2: Four-stage pipeline with stage latencies 1 ns,
1.5 ns, 1.5 ns, 1.5 ns.
IF ID/RF EX MEM WB
P3: Five-stage pipeline with stage latencies 0.5 ns,
Ins, Ins, 0.6 ns, Ins. 1 2.2 2 1 0.75
ns
P4: Five-stage pipeline with stage latencies 0.5 ns,
0.5 ns, Ins, Ins, 1.1ns. ‘Q’ has 8 stages (highest clock cycle time = 1 ns)
Which processor has the highest peak clock
frequency? IF ID RF1 EX1 EX2 MEM WB

(a) P1 (b) P2 1 2.2/3 2.2/3 2.2/3 1 1 1 0.75


(c) P3 (d) P4 [2014]
Solution: (c) In ‘P’ pipeline new instruction fetching stopped
for 2 stage delays,
f ∝ 1/T
In ‘Q’ pipeline new instruction fetching stopped
Minimum clock time gives the highest clock fre-
for 5 stage delays.
quency for the given pipelines processor.
Number of branch instruction = 20%
For P1 largest clock time is 2ns.
∴P total time is (0.8 × 2.2ns) + (0.2 × 2 + 1) 2.2 ns
For P2 largest clock time is 1.5ns.
= 3.08
For P3 largest clock time is 1ns.
Q total time is 0.8 × 1ns + 0.2 × (5 + 1)) × 1ns =
For P4 largest clock time is 1ns. 2ns
So P3 gives peak clock frequency. ∴ P/Q = 3.08 / 2 = 1.54 ns.
Hence, the correct option is (c) 4. Consider an instruction pipeline with five stages
3. An instruction pipeline has five stages namely, without any branch prediction- Fetch Instruction
Instruction Fetch (IF), Instruction Decode and (FI), Decode Instruction (DI), Fetch Operand
Register Fetch (ID/RF), Instruction Execution (FO), Execute Instruction (EI) and Write Operand
(EX), Memory Access (MEM), and Register (WO). The stage delays for FI, PI, FO, EI and WO
Writeback (WB) with stage latencies 1 ns, 2.2 are 5 ns, 7ns, 10 ns, 8 ns and 6 ns, respectively.
ns, 2 ns, 1 ns, and 0.75 ns, respectively. To gain There are intermediate storage buffers after each
in terms of frequency, the designers have decided stage and the delay of each buffer is 1 ns. A pro-
to split the ID/RF stage into three stages (ID, RF1, gram consisting of 12 instructions I1, I2, I3, ....., I12
RF2) each of latency 2.2/3 ns. Also, the EX stage is executed in this pipelined processor. Instruction
is split into two stages (EXI, EX2) each of latency I4 is the only branch instruction and its branch tar-
1 ns. The new design has a total of eight pipeline get is I9. If the branch is taken during the execution
stages. A program has 20% branch instruction

Gate_CSE_Unit10_Computer Oranization.indb 18 11/19/2015 6:44:09 PM


Chapter 3  Pipeline  |  10.19

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)

Pipeline Register (Delay 1 ns)

Pipeline Register (Delay 1 ns)

Pipeline Register (Delay 1 ns)

R5

Stage Stage Stage Stage Hence, the correct option is (b)


S1 S2 S3 S4
Delay Delay
6ns
Delay
11ns
Delay
8ns
7. Consider a 4-stage pipeline processor. The number
5ns
of cycles needed by the four instructions II, I2, I3,
I4 in stages S1, S2, S3, S4 is shown below.
SI S2 S3 .S4
11 2 1 1 1
What is the approximate speed up of the pipeline 12 1 3 2, 2
in steady state under ideal conditions when com- 13 2 1 1 3
pared to the corresponding non-pipeline imple-
14 1 2 2 2
mentation? [2011]
(a) 4.0 (b) 2.5 What is the number of cycles needed to execute
(c) 1.1 (d) 3.0 the following loop? For (i = l to 2) {II; 12; B; 14 ;}
Solution: (b)  [2009]
S = Non-pipelined system/ max. pipeline delay (a) 16 (b) 23
= 30 ns / 12 ns = 2.5 (c) 28 (d) 30
Hence, the correct option is (b) Solution: (b)
6. A 5-stage pipelined processor has Instruction For 1st loop 15 clock cycles and for 2nd loop clock
Fetch (IF), Instruction Decode (ID), Operand Fetch are sufficient so total number of blocks needed is
(OF), perform Operation (PO) and Write Operand 23.
(WO) stages. The IF, ID, OF and WO stages take 1 Hence, the correct option is (b)
clock cycle each for any instruction. The PO stage 8. In an instruction execution pipeline, the earliest
takes 1 clock cycle for ADD and SUB instructions, that the data TLB (Translation Look aside Buffer)
3 clock cycle for MUL instruction, and 6 clock can be accessed is [2008]
cycles for DIV instructio n respectively. Operand

Gate_CSE_Unit10_Computer Oranization.indb 19 11/19/2015 6:44:09 PM


10.20 | Computer Organization

(a)  Before effective address calculation has (c) I3 (d) I4


started Solution: (d)
(b) During effective address calculation
Last instruction is data dependent.
(c)  After effective address calculation has
completed Hence, the correct option is (d)
(d) After data cache lookup has completed 12. Consider a pipelined processor with the following
Solution: (b) four stages
Hence, the correct option is (b) IF : Instruction Fetch
9. Which of the following are true in a pipelined ID : Instruction Decode and Operand Fetch
processor? EX : Execute
1. Bypassing can handle all RAW hazards. WB : Write Back
2. Register renaming can eliminate all register
The IF, ID and WB stages take one clock each
carried WAR hazards.
to complete the operation. The number of clock
3. Control hazard penalties can be eliminated by
cycles for the EX stage depends on the instruction.
dynamic branch prediction. [2008]
The ADD and SUB instructions need 1 clock cycle
(a) 1 and 2 only (b) 1 and 3 only
and the MUL instruction needs 3 clock cycles in
(c) 2 and 3 only (d) 1, 2 and 3
the EX stage. Operand . forwarding is used in the
Solution: (c) pipelined processor. What is the number of clock
Bypassing cannot handle all RAW hazards. cycles taken to complete the following sequence of
Register renaming can eliminate all register car- instructions?
ried WAR hazards. ADD R2, Rl, R0, R2 ← R1 + R0
And Control hazard penalties can be eliminated by MUL R4, R3, R2, R4 ← R3 * R2
dynamic branch prediction.
SUB R6, R5, R4, R6 ← R5 - R4
Hence, the correct option is (c)
10. The use of multiple register windows with over-
[2007]
lap causes a reduction in the number of memory
(a) 7 (b) 8
accesses for
(c) 10 (d) 14
1. function locals and parameters
2. register saves and restores Solution: (b)
3. instruction fetches  [2008] pipelined processor with the following four stages
(a) 1 only (b) 2 only IF, ID, EX, WB clock cycles ;
(c) 3 only (d) 1, 2 and 3
Instruction: ADD, SUB, MUL
Solution: (a)
Consider the following diagram
Hence, the correct option is (a)
1 2 3 4 5 6 7 8
11. The following code is to run on a pipelined proces- IF ID EX WB
sor with one branch delay slot
I1 : ADD R2 ← R7 + R8 IF ID EX EX EX WB
I2 : SUB R4 ← R5 – R6
IF ID EX WB
I3 : ADD R1 ← R2 + R3
I4 : STORE Memory [R4] ← R1
Branch to label if R1 = 0
Clock cycle 1:
Which of the instruction I1, I2, I3, or I4 can legiti-
R2 < R1 + R0
mately occupy the delay slot without any other
program modification? [2008] R4 < R3 * R4
(a) I1, (b) I2 R6 < R5 - R4

Gate_CSE_Unit10_Computer Oranization.indb 20 11/19/2015 6:44:10 PM


Chapter 3  Pipeline  |  10.21

So total cycle required = 8. Solution: (b)


Hence, the correct option is (b) 1 2 3 4 5 6 7 8 9 10
13. A CPU has five-stages pipeline and runs at 1 GHz
IF RD EX MA WB
frequency. Instruction fetch happens in the first
nst. IF RD EX MA WB
stage of the pipeline. A conditional branch instruc-
tion computes the target address and evaluates the IF RD EX MA WB
condition in the third stage of the pipeline. The No. of clock cycles 10
processor stops fetching new instruction following
a conditional branch until the branch outcome is Hence, the correct option is (b)
known. A program executes 109 instructions out
15. A 4-stage pipeline has the stage delays as 150, 120,
of which 20% are conditional branches. If each
160 and 140 nanoseconds respectively. Registers
instruction takes one cycle to complete on average,
that are used between the stages have a delay of
then total execution time of the program is [2006]
5 nanoseconds each. Assuming constant clock-
(a) 1.0 second (b) 1.2 seconds
ing rate, the total time taken to process 1000 data
(c) 1.4 seconds (d) 1.6 seconds
items on this pipeline will be  [2004]
Solution: (c) (a) 120.4 microseconds
two stall cycle CPU clock frequency = 1GHz (b) 160.5 microseconds
109 instructions out of which 20% are conditional (c) 165.5 microseconds
branches requiring 3 clock cycles. (d) 590.0 microseconds
Remaining 80% instruction requires only one Solution: (c)
clock pulse for their completion. Max stage delay = 160 µs
∴ total execution time = 109 *(80/100)*10 + 109 Buffer Delay = 5 µs
*(20/100)*3)* 10 - 9 Pipeline clock = 165 µs
= 0.8 + 0.6 = 1.4 sec T1000 = (K + n - 1) Tp clock
Hence, the correct option is (c) = (4 + 999)*165
14. A 5 stage pipelined CPU has the following = 165.5 µs.
sequence of stages IF-Instruction fetch from
Hence, the correct option is (c)
instruction memory, RD-Instruction decode and
register read, EX-Execute: ALU operation for 16. The performance of pipelined processor suffers if
data and address computation, MA-Data memory  [2002]
access-for write access the register read at RD (a) the pipeline stages have different delay.
stage it used, WB-Register write back. (b) consecutive instructions are depend on each
other.
Consider the following sequence of instructions:
(c) the pipeline stages share single hardware re-
I1:LR0, Loc; R0 < = M[Loc1] sources.
I2:A R0, R0; R0 < = R0 + R0 (d) All of the above
I3:A R2, R0; R2 < = R2 - R0 Solution: (d)
Let each stage takes one clock cycle. Pipeline performance is reduced due to data
What is the number of clock cycles taken to com- dependency, control dependency, structural
plete the above sequence of instructions starting dependency.
from the fetch of Ii?  [2005] Hence, the correct option is (d)
(a) 8 (b) 10
(c) 12 (d) 15

Gate_CSE_Unit10_Computer Oranization.indb 21 11/19/2015 6:44:10 PM


10.22 | Computer Organization

Five-marks Questions = 4% of unconditional branch instructions


which are always taken.
So, percentage of instructions where a branch
1. An instruction pipeline has five stages where each
is taken is 8 + 4 = 12% instead of 20% in (a)
stage takes 2 nanoseconds and all instructions use
part.
all five stages. Branch instructions are not over-
So, in 100 instructions there will be 12 branch
lapped, i.e., the instruction after the branch is not
instructions. We can do a different calculation
fetched till the branch instruction is completed.
here as compared to (a) as 12 is not a divisor
Under ideal conditions:
of 100. Each branch instruction causes a pipe-
(a)  Calculate the average instruction execution
line delay of 4*2 = 8 ns. So, 12 instructions
time assuming that 20% of all instructions ex-
will cause a delay of 12 * 8 = 96 ns. For 100
ecuted are branch instruction. Ignore the fact
instructions, we need 100 * 2 = 200 ns without
that some branch instructions may be condi-
any delay and with delay we require 200 + 96
tional.
= 296 ns for 100 instructions.
(b) If a branch instruction is a conditional branch
 So, average instruction execution time =
instruction, the branch need not be taken; if the
296/100 = 2.96 ns
branch is not taken, the following instructions
(We can also use this method for part (a) which
can be overlapped. When 80% of all branch in-
will give 100 * 2 + 20*8 = 360 ns for 100
structions are conditional branch instructions,
instructions)
and 50% of the conditional branch instructions
are such that the branch is taken, calculate the 2. An instruction pipeline consists of 4 stages: Fetch
average instruction execution time. [2000] (F), Decode operand field (D), Execute (E), and
Result-Write (W). The 5 instructions in a certain
Solution:
instruction sequence need these stages for the dif-
(a) Now, we are given that 20% of instructions are
ferent number of clock cycles as shown by the
branch (like JMP) and when a branch instruc-
table below.
tion is executed, no further instruction enters
the pipeline. So, we can assume every 5th in- No. of clock cycles needed for
struction is a branch instruction. So, with this Instruction F D E W
assumption, total time to finish 5 instruction
1 1 2 1 1
will be 5 * 2 + 8 = 18 ns (as when a branch
instruction enters the pipeline and before it 2 1 2 2 1
finishes, 4 pipeline stages will be empty total- 3 2 1 3 2
ing 4 * 2 = 8 ns, as it is mentioned in question 4 1 3 2 1
that the next instruction fetch starts only when 5 1 2 1 2
branch instruction completes). And this is the
same for every set of 5 instructions, and hence
Find the number of clock cycles needed to perform
the average instruction execution time = 18/5
the 5 instructions [1999]
= 3.6 ns
(b) This is just a complex statement. But what we Solution:
need is to identify the % of branch instructions Number of clock needed for
which cause a branch to be taken as others
Instruction F D E W
will have no effect on the pipeline flow. 20%
of branch instructions are branch instructions. 1 1(1) 2(3) 1(4) 1(5)
80% of branch instructions are conditional. 2 1(2) 2(5) 2(7) 1(8)
That means .2*.8 = 16% of instructions are con- 3 2(4) 1(6) 3(10) 2(12)
ditional branch instructions and it is given that 4 1(5) 3(9) 2(12) 1(13)
50% of those result in a branch being taken.
5 1(6) 2(11) 1(13) 2(15)
So, 8% of instructions are conditional branch-
es being taken and we also have 20% of 20%

Gate_CSE_Unit10_Computer Oranization.indb 22 11/19/2015 6:44:10 PM


Chapter 4
CPU Organization

By changing contents of R, the processor can


One-mark Questions change the absolute address refers to a new block
of instruction.
1. A CPU has 24-bit instructions. A program starts
at address 300 (in decimal). Which one of the This address modification allows the processor to
following is a legal program counter (all values in relocate the entire new block from one region of
decimal)?  [2006] main memory to another without invalidating the
(a) 400 (b) 500 addresses.
(c) 600 (d) 700 Hence, the correct option is (c)
Solution: (c) 3. In absolute addressing mode [2002]
The address of next instruction is maintained by (a) the operand is inside the instruction.
PC. So, PC value must have to be incremented by (b)  the address of the operand is inside the
3 each time. instruction.
(c)  the register containing the address of the
Hence, the correct option is (c)
operand is specified in the instruction.
2. Which of the following addressing modes are suit- (d) location of the operand is implicit.
able for program relocation at run time?
Solution: (b)
1. Absolute addressing
2. Based addressing Hence, the correct option is (b)
3. Relative addressing 4. Which of the following is not a form of memory?
4. Indirect addressing  [2004] [2002]
(a) 1 and 4 (b) 1 and 2 (a) Instruction cache
(c) 2 and 3 (d) 1, 2 and 4 (b) Instruction Register
Solution: (c) (c) Instruction opcode
Absolute and indirect addressing mode is not suit- (d) Translation look aside buffer
able for indirection. Solution: (c)
Based addressing and relative addressing mode are Opcode is not a device.
suitable for program relocation at run time. Hence, the correct option is (c)
In base addressing mode, base address is calcu- 5. The most appropriate matching for the following
lated as pairs
A = R + D, where R is register mostly a PC for rela- X: Indirect addressing
tive addressing and base register for base address-
Y: Immediate addressing
ing mode.
Z: Auto decrement addressing is

Gate_CSE_Unit10_Computer Oranization.indb 23 11/19/2015 6:44:10 PM


10.24 | Computer Organization

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

Gate_CSE_Unit10_Computer Oranization.indb 24 11/19/2015 6:44:10 PM


Chapter 4  CPU Organization  |  10.25

instruction. The load-store instructions take two Solution: (d)


clock cycles to execute. A REF(Return from Exception) instruction con-
The designer of the system also has an alternate tains a trap instruction , privileged instruction and
approach of using the DMA controller to imple- an exception cannot be allowed to occur during the
ment the same transfer. The DMA controller execution of an REF instruction.
requires 20 clock cycles for initialization and other Hence, the correct option is (d)
overheads. Each DMA transfer cycle takes two
7. For all delayed conditional branch instructions,
clock cycles to transfer one byte of data from the
irrespective of whether the condition evaluate true
device to the memory.
or false. [2008]
What is the approximate speed up when the DMA (a)  The instruction following the conditional
controller based design is used in place of the branch instruction in memory is executed.
interrupt driven program based input–output? (b) The first instruction in the fall through path is
[2011] executed.
(a) 3.4 (b) 4.4 (c)  The first instruction in the taken path is
(c) 5.1 (d) 6.7 executed.
Solution: (a) (d) The branch takes longer to execute than any
other instruction.
Non-piped system requires (2 + 2 + 1 + 1 + 1 + 1)
Solution: (d)
2 + 7*500 cycles = 3502 cycles
As condition is not mentioned, ‘d’ will become
DMA clock needs = 20 + 2*500 = 1020 cycles
correct answer because 7-10 clock cycles are
Speed up = 3502/1020 = 3.43 needed for executing conditional branch instruc-
Hence, the correct option is (a) tion in 8085 micro-processor.
5. Which of the following is/are true of the auto Hence, the correct option is (d)
increment addressing mode? Common Data for Question 8, 9 and 10
1. It is useful in creating self relocating code. [2006]
2. If it is included in an instruction set. Architecture Consider the following program segment. Here Rl,
then an additional ALU is required for effective R2 and R3 are the general purpose registers.
address calculation.
Instruction Size
3. The amount of increment depends on the size of Instruction Operation
(in words)
the data item accessed. [2008]
(a) 1 only (b) 2 only MOV R1, (3000) R1 ← M [3000] 2
(c) 3 only (d) 2 and 3 only LOOP

Solution: (c) MOV R2, R1 R2 ← M[R3] 1

Amount of increment depends on the size of data ADD R2, R1 R2 ← R1 + R2 1


item accessed. MOVE (R3), R2 M[R3] ← R2 1
Hence, the correct option is (c) INC R3 R3 ← R3 + 1 1

6. Which of the following must be true for the RFE DEC R1 R1 ← R3 - 1 1


(Return from Expectation) instruction on a general Branch on 2
purpose processor? BNZLOOP
not zero
1. It must be a trap instruction. HALT Stop 1
2. It must be a privileged instruction.
3. An exception cannot be allowed to occur during Assume that the content of memory location 3000
execution of an RFE instruction. [2008] is 10 and the content of the register R3 is 2000.
(a) 1 only (b) 2 only
(c) 1 and 2 only (d) 1, 2 and 3 only

Gate_CSE_Unit10_Computer Oranization.indb 25 11/19/2015 6:44:10 PM


10.26 | Computer Organization

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.

Gate_CSE_Unit10_Computer Oranization.indb 26 11/19/2015 6:44:10 PM


Chapter 4  CPU Organization  |  10.27

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?

Gate_CSE_Unit10_Computer Oranization.indb 27 11/19/2015 6:44:11 PM


10.28 | Computer Organization

X. Indirect addressing (c) (X, III), (Y, II), (Z, I)


Y. Indexed addressing (d) (X, I), (Y, III), (Z, II)
Z. Base register addressing Solution: (a)
I. Array implementation Indirect addressing : Passing array as parameter
II. Writing relocatable code Indexed addressing: array implementation Base
III. Passing array as parameter  [2001] register addressing: Writing relocatable code
(a) (X, III), (Y, I), (Z, II) Hence, the correct option is (a)
(b) (X, II), (Y, III), (Z, I)

Gate_CSE_Unit10_Computer Oranization.indb 28 11/19/2015 6:44:11 PM


Chapter 4  CPU Organization  |  10.29

Five-marks Questions 2. Consider the following program fragment in the


assembly language of a certain hypothetical pro-
cessor. The processor has three general purpose
1. Consider the following basic processor program
registers R1, R2 and R3. The meanings of the
segment, where registers B and C contain BCD
instructions are shown by comments (starting with
values.
;) after the instructions.
SI: MVI A, 99H
; Compare R1 and 0, set flags
MVI D, 00H X: CMP R1, 0
appropriately in status register.
SUB C
JZZ ; Jump if zero to target Z.
ADD B
MOV R2, R1 ; Copy contents of R1 to R2.
DAA
SHR Rl ; Shift right R1 by 1 bot.
S2: JC S3 SHL R1 : Shift left R1 by 1 bit.
MOV E, A ; Compare R2 and R1 and
CMP R2, R1
MVI A, 99H set flags in status register.
SUB E JZ Y ; Jump if zero to target Y.
MOV E, A INC R3 ; Increment R3 by 1:
JZ S4 Y: SHR R1 ; Shift right Rl by 1 bit.

MVI D, FFH JMP X ; Jump to target X.

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

Gate_CSE_Unit10_Computer Oranization.indb 29 11/19/2015 6:44:11 PM


Chapter 5
Control Unit Design
The ALU, the bus and all the registers in the data
Two-Marks Questions path are of identical size. All operations including
incrementation of the PC and the GPRs are to be
1. Consider the following sequence of micro- carried out in the ALU. Two clock cycle are needed
operations for memory read operation-the first one for load-
MBR ← PC ing address in the MAR and the next one for load-
MAR ← X ing data from the memory but into the MDR.
PC ← Y 2. The instruction ‘add R0, R1’ has the register trans-
Memory ← MBR fer interpretation R0 < = R0 + Rl. The minimum
Which one of the following is a possible operation number of cycles needed for execution cycle of
performed by this sequence? [2013] this instruction is
(a) Instruction fetch (a) 2 (b) 3
(b) Operand fetch (c) 4 (d) 5
(c) Conditional branch Solution: (b)
(d) Initiation of interrupt service By using Register Transfer Interpretation
Solution: (d) Clock cycle1 - R0 to S
Clock cycle –R1 to T
To execute interrupt cycles, the present control of
Clock cycle –R0 + R1 to R0
PC will be pushed to stack with the help of MBR
and MAR before placing ISR address PC. (Always 3 clock cycles are required.
only MAR & MBR are used for address in basic Hence, the correct option is (b)
computer). 3. The instruction ‘call Rn, sub’ is a two word instruc-
Hence, the correct option is (d) tion. Assuming that PC is incremented during the
fetch cycle of the first word of the instruction, its
Common Data for Question 2 and 3 [2005] register transfer interpretation is
Consider the following data path of a CPU Rn < = PC + l; .
MAR MDR PC < = M[PC];
The minimum number of CPU clock cycles needed
during die execution cycle of this instruction is:
(a) 2 (b) 3
(c) 4 (d) 5
S T
Solution : (b)
PC IR
Execution cycle: clock cycle 1 - PC + 1 to clock
GPRs cycle 2 & 3 –M[PC] to PC.
ALU 3 clock cycles are required.
Hence, the correct option is (b)

Gate_CSE_Unit10_Computer Oranization.indb 30 11/19/2015 6:44:11 PM


Chapter 5  Control Unit Design  |  10.31

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.

Gate_CSE_Unit10_Computer Oranization.indb 31 11/19/2015 6:44:11 PM


Chapter 6
I/O Organization

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.

Gate_CSE_Unit10_Computer Oranization.indb 32 11/19/2015 6:44:11 PM


Chapter 6  I/O Organization  |  10.33

Solution: (b) (b) Loop instructions cannot be interrupted till


In single-line interrupt system, one line is for they complete.
interrupt request line and another for an interrupt (c) A processor checks for interrupts before ex-
grant line. ecuting a new instruction.
(d) Only level triggered interrupts are possible on
Here more than one interrupt I/O request line may
microprocessors.
exists.
Solution: (a)
Vectored interrupts are not possible but multiple
interrupting devices are possible. After the interrupt pin is enabled, then only CPU is
able to processing.
Hence, the correct option is (b)
Hence, the correct option is (a)
5. How many 8-bit characters can be transmitted per
second over 9600 baud serial communication link 9. Which of the following device should get higher
using a parity synchronous mode of transmission priority on assigning interrupts?[1998]
with one start bit and eight data bits, two stop bits, (a) Hard disk (b) Printer
and one parity bit [2004] (c) Keyboard (d) Floppy disk
(a) 600 (b) 800 Solution: (a)
(c) 876 (d) 1200 CPU has highest priority for high-speed device
Solution: (b) and least priority for low-speed device. Hard disc
Character = 1 + 8 + 2 + 1 = 12 has higher priority than others because it is fastest
secondary memory.
CPS = 9600/12 = 800
Hence, the correct option is (a)
Hence, the correct option is (b)
10. The correct matching for the following pairs is
6. In serial data transmission, every byte of data is
padded with a ‘0’ in the beginning and one or two List -1
‘1’ s at end because  [2002] (a) DMA I/O
(a) Receiver is to be synchronized for byte recep- (b) Cache
tion (c) Interrupt I/O
(b) Receiver recovers lost ‘0’s & l’s from these (d) Condition code Register
padded bits List-II
(c) Padded bits are useful in purity computation (1) High speed RAM
(d) None of the above (2) Disk
Solution: (a) (3) Printer
(4) ALU [1997]
Hence, the correct option is (a)
(a) a-4, b-3, c-1, d-2 (b) a-2, b-1, c-3, d-4
7. A processor needs software interrupt to (c) a-4, b-3, c-2, d-1 (d) a-2, b-3, c-4, d-1
(a) Test the interrupt system of the processor
Solution: (b)
(b) Implement co-routines
(c) Obtain system services which need execution Hence, the correct option is (b)
of privileged instructions 11. For the daisy chain scheme of connecting I/O
(d) Return from subroutine  [2001] devices, which of the following statements is true?
Solution: (c)  [1996]
(a) It gives non-uniform priority to various devic-
Software interrupt is required to obtain system ser-
es.
vices which need execution of privileged instruc-
(b) It gives uniform priority to all devices.
tions for a processor.
(c) It is only useful for connecting slow devices to
Hence, the correct option is (c) a processor
8. Which of the following is true? [1998] (d) It requires a separate interrupt pin on the pro-
(a) Unless enabled, a CPU will not be able to pro- cessor for each device.
cess interrupts

Gate_CSE_Unit10_Computer Oranization.indb 33 11/19/2015 6:44:11 PM


10.34 | Computer Organization

Solution: (a) one clock cycle to execute if it is a non-load/store


In daisy chain scheme, first device has first priority instruction. The load-store instructions take two
and last device has least priority. clock cycles to execute.
Hence, the correct option is (a) The designer of the system also has an alternate
approach of using the DMA controller to imple-
12. In a vectored interrupt [1995]
ment the same transfer. The DMA controller
(a) The branch address is assigned to a fixed loca-
requires 20 clock cycles for initialization and
tion in memory.
other overheads. Each DMA transfer cycle takes
(b) The interrupting source supplies the branch
two clock cycles to transfer one byte of data from
information to the processor through an inter-
the device to the memory.
rupt vector.
(c) The branch address is obtained from a register What is the approximate speed-up when the DMA
in the processor. controller based design is used in place of the inter-
(d) None of these rupt driven program based input-output? [2011]
(a) 3.4 (b) 4.4
Solution: (b)
(c) 5.1 (d) 6.7
For vectored hardware interrupt, the interrupting
Solution: (a)
device supplies the respective address with addi-
tional hardware. Non-pipelined system requires
Hence, the correct option is (b) (2 + 2 + 1 + 1 + 1)
13. Start and stop bits do not contain’ information’ but 2 + 7*500 cycles = 3502 cycles
these are used in serial communication for [1992] DMA clock need = 20 + 2*500 = 1020 cycles
(a) Error detection Speed up = 3502/1020 = 3.43
(b) Error correction
Hence, the correct option is (a)
(c) Synchronization
(d) Slowing down the communication 2. A device with data transfer rate 10 KB/sec is con-
nected to a CPU. Data is transferred byte-wise. Let
Solution: (c)
the interrupt overhead be 4 μsec. The byte trans-
Start and stop bits are used for synchronization. fer time between the device interface register and
Hence, the correct option is (c) CPU or memory is negligible. What is the mini-
mum performance gain of operating the device
under interrupt mode over operating it under pro-
Two-marks Questions gram controlled mode? [2005]
(a) 15 (b) 25
1. On a non-pipelined sequential processor, a (c) 35 (d) 45
program segment, which is a part of the interrupt
Solution: (b)
service routine, is given to transfer 500 bytes from
an I/O device to memory. 10 kBps = 10 KB is transferred in 1 sec = 104 B
Initialize the address register Initialize the count to 1 byte takes = 0.1ms = 100µs
500 So, minimum waiting time needed is 100 µs for
LOOP: Load a byte from device system
Store in memory at address given by address ∴Gain = 100µs/4µs = 25
register Hence, the correct option is (b)
Increment the address register 3. Consider the disk drive with the following speci-
Decrement the Count fications 16 surfaces, 512 tracks/surface, 512
sectors/track, 1 KB/sector, rotation speed 3000
If count! = 0 go to LOOP
rpm. The disk is operated in cycle stealing mode
Assume that each statement in this program is whereby whenever one byte word is ready, it is
equivalent to a machine instruction which takes sent to memory; similarly, for writing, the disk

Gate_CSE_Unit10_Computer Oranization.indb 34 11/19/2015 6:44:12 PM


Chapter 6  I/O Organization  |  10.35

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

Gate_CSE_Unit10_Computer Oranization.indb 35 11/19/2015 6:44:12 PM


Chapter 7
Secondary Memories

the starting disk location of the file is <1200, 9,


One-mark Question 40>. What is the cylinder number of the last sector
of the file if it is stored in a contiguous manner?
1. Consider a disk pack with 16 surfaces, 128 tracks
 [2013]
per surface and 256 sectors per track. 512 bytes of
(a) 1281 (b) 1282
data are stored in a bit serial manner in a sector.
(c) 1283 (d) 1284
The capacity of the disk pack and the number of
bits required to specify a particular sector in the Solution: (d)
disk are, respectively [2006] Size of data to be transferred = 42 797
(a) 256 Mbyte, 19 bits One sector capacity = 512 B
(b) 256 Mbyte, 28 bits
No. of sectors to be store 42979 kB = (42979 ×
(c) 512 Mbyte, 20 bits
1024) / 512 = 85594
(d) 64 Gbyte, 28 bits
One cylinder has 64 × 16 = 1024 sectors = 602
Solution: (a)
602 sectors occupy more than half of one cylinder
H = 24 , T = 27, S = 28 and B = 29
capacity.
Capacity of disk pack = h × T × S × B
But the given cylinder has started with
= 24 × 27 × 28 × 29 = 228 B = 256 MB
<1200, 9, 40> means more than half of the cylinder,
For addressing a particular sector in disk address
So, next cylinder is also needed for storing
format is
complete data
<surface off-set , track offset, Sector Offset>
∴ Last cylinder number
<4, 7, 8> = 19 bits
= 1200 + 83 + next one
Hence, the correct option is (a)
= 1284
Hence, the correct option is (d)
Two-marks Questions 2. An application loads 100 libraries at startup.
Loading each library requires exactly one disk
1. Consider a hard disk with 16 recording surfaces access. The seek time of the disk to a random loca-
(0 - 15) having 16384 cylinders (0 - 16383) and tion is given as 10ms. Rotational speed of disk is
each cylinder contains 64 sectors(0 - 63). Data 6000 rpm. If all 100 libraries are loaded from ran-
storage capacity in each sector is 512 bytes. Data dom locations on the disk, how long does it take to
are organized cylinder-wise and the addressing load all libraries?
format is <cylinder no., surface no., sector no.,>.
A file of size 42797 KB is stored in the disk and

Gate_CSE_Unit10_Computer Oranization.indb 36 11/19/2015 6:44:12 PM


Chapter 7  Secondary Memories | 10.37

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

Gate_CSE_Unit10_Computer Oranization.indb 37 11/19/2015 6:44:12 PM


10.38 | Computer Organization

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

Gate_CSE_Unit10_Computer Oranization.indb 38 11/19/2015 6:44:12 PM


Chapter 8
Register Allocation

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

Gate_CSE_Unit10_Computer Oranization.indb 39 11/19/2015 6:44:12 PM


10.40 | Computer Organization

else Common Data for Questions 3 and 4: [2013]


{ A computer uses 64-bit virtual address, 32-bit
R2 ← (read value of c from memory) physical address, and a three-level paged table
* R1 (d = c * a) organization. The page table base register stores
the base address of the first-level table (T1), which
R2 ← R2 * R2 (e = e * e)
occupies exactly one page. Each entry of T1 stores
} the base address of a page of the second-level table
As we can see from this code, we had one memory (T2). Each entry of T2 stores the base address of a
write. page of the third-level table (T3). Each entry of T3
The minimum number of spills to memory in com- stores a page table entry (PTE). The PTE is 32-bits
plied code is 1. in size. The processor used in the computer has
a 1 MB 16-way set associative virtually indexed
Hence, the correct option is (b)
physically tagged cache. The cache block size is 64
2. What is the minimum number of registers needed bytes.
in the instruction set architecture of the processor
3. What is the size of a page in KB in this computer?
to compile this code segment without any spill to
(a) 2 (b) 4
memory? Do not apply any optimization other
(c) 8 (d) 16
than optimizing register allocation
(a) 3 (b) 4 Solution: (c)
(c) 5 (d) 6 Since, the first level page table exactly fits in one
Solution: (b) page and more over entry size is 4B.
Here, we need not to optimize the code. We have to Assuming the page size of 2B. Dividing the
use minimum number of registers. address space by page size for three levels.
Assume: R1 & R2 hold values of a and b respec- For the last level, multiply the page table entries by
tively the machine code is equivalent. size of 4B, we get page size 8B.
R2 ← R1 + R2 (c = a + b) Hence, the correct option is (c)
R3 ← R2 * R1 (d = c * a) 4. What is the minimum number of page colors
needed to guarantee that no two synonyms map
R4 ← R2 + R1 (e = c + a)
to different sets in the processor cache of this
R2 ← R2 * R2 (x = c * c) computer?
If (R2 > R1) (a) 2 (b) 4
{ (c) 8 (d) 16
R2 ← R1 * R1 (y = a * a) Solution: (c)
} If page size is 8kB , physical address distribution
set associate mapped cache.
Else
Each page use the same set 8 times, then 8 colors
{
are needed
R3 ← R3 * R3 (d = d * d)
= (8 kB page/ 24 * 26 ) = 8
R4 ← R4 * R4 (e = e * e)
Hence, the correct option is (c)
}
5. Consider evaluating the following expression tree
In total, we have used R1, R2, R3 and R4 register on a machine with load-store architecture in which
only. memory can be accessed only through load and
Hence, the minimum number of registers needed store instructions. The variables a, b, c, d and e are
in the instruction set architecture of processor to initially stored in memory. The binary operators
compile this code segment without any spill to used in this expression tree can be evaluated by the
memory is 4. machine only when the operands are in registers.
Hence, the correct option is (b)

Gate_CSE_Unit10_Computer Oranization.indb 40 11/19/2015 6:44:12 PM


Chapter 8  Register Allocation  |  10.41

The instructions produce result only in a register. (a) 2 (b) 9


If no intermediate results can be stored in memory, (c) 5 (d) 3
what is the minimum number of registers needed Solution: (d)
to evaluate this expression? [2011]
Instruction produces result I registers only
+ R < - a, R2 < -b, R1 < - R1-R2
R2 is free;
− −
R2 < - c, R3 < -d, R2 < - R2 + R3
R3 < - e, R3 < - R3-R2
a b e +
R1 < - R1 + R3
c d So, the minimum 3 registers are needed.
Hence, the correct option is (d)

Gate_CSE_Unit10_Computer Oranization.indb 41 11/19/2015 6:44:12 PM


This page is intentionally left blank.

Gate_CSE_Unit10_Computer Oranization.indb 42 11/19/2015 6:44:12 PM


UNIT XI
SOFTWARE ENGINEERING

Chapter 1: Software Engineering 11.3

GATE_CSE_Unit11_Software Engineering.indd 1 11/19/2015 3:30:35 PM


GATE_CSE_Unit11_Software Engineering.indd 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 0 0 3
2 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 1 0 3 0
5 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 4 5 0 6 3

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

GATE_CSE_Unit11_Software Engineering.indd 3 11/19/2015 3:30:35 PM


11.4 | Software Engineering

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]

GATE_CSE_Unit11_Software Engineering.indd 4 11/19/2015 3:30:35 PM


Chapter 1  Software Engineering | 11.5

(a) 19 (b) 21 9. The coupling between different modules of a soft-


(c) 20 (d) 10 ware is categorized as follows:
I. Content coupling
II. Common coupling
III. Control coupling
IV. Stamp coupling
V. Data coupling
Coupling between modules can be ranked in the
order of the strongest (least desirable) to the weak-
Solution: (a) est (most desirable) as follows. [2009]
(a) I-II-III-IV-V (b) V-IV-III-II-I
Cyclomatic complexity is software metric that pro- (c) I-III-V-II-IV (d) Iv-II-V-III-I
vides a quantitative measure of the logical com-
plexity of a program. When used in the context of Solution: (b)
a basis path testing method, the value computed
for cyclomatic complexity defines the number for
independent paths in the basis set of a program and
provides an upper bound for the number of tests I
that must be conducted to ensure that all state-
ments have been executed at least once. c
Cyclomatic complexity of the sequential integra-
tion number of modules is given as:
2*10 - 1 = 19
Hance, the correct option is (a)
Coupling is the qualitative measure of the degree
8. What is the appropriate pairing of items in the two to which classes are connected to one another and
columns listing various activities encountered in a coupling increases when interdependence among
software use cycle? [2010] classes increases.
List - 1 Hance, the correct option is (b)
P. Requirement capture
Q. Design
R. Implementation
Two-marks Questions
S. Maintenance
Common Data for Questions 01 and 02:
List - II
1. Module development and integration The procedure given below is required to find and
2. Domain analysis replace certain characters inside an input charac-
3. Structures and behavioral modeling ter string supplied in array A. The characters to be
4. Performance tuning replaced are supplied in array ‘oldc’, while their
(a) P-3, Q-2, R-4, S-l respective replacement characters are supplied in
(b) P-2, Q-3, R-l, S-4 array ‘newc’. Array A has a fixed length of five
(c) P-3, Q-2, R-l, S-4 characters, while array ‘oldc’ and ‘newc’ contain
(d) P-2, Q-3, R-4, S-l three characters each. However, the procedure is
Solution: (b) flawed.
The activity module development and integration void find_and_replace (char *A, char
is related to implementation. The domain analysis *oldc, char *newc)
is related to requirement capturing. The structure {for (int i = 0; i < 5; i + + )
and behavioral modeling is related to design. The for(int j = 0; j<3; j + + )
performance tuning is related to maintenance.
if(A[i] = - oldc[j]) A[i] = newc[j];
Hance, the correct option is (b)
}

GATE_CSE_Unit11_Software Engineering.indd 5 11/19/2015 3:30:35 PM


11.6 | Software Engineering

The procedure is tested with the following four test


cases;
(1) oldc = ‘abc’, newc = ‘dab’
(2) oldc = ‘cde’, newc = ‘bed’
(3) oldc = ‘bca’, newc - ‘cda’
(4) oldc = ‘abc’, newc ‘bac’
1. The tester now tests the program on all input
strings of length five consisting of characters ‘a’, [2013]
‘ b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If (a) There is no change.
the tester carries out this testing with the four test (b) Average cohesion goes up, but coupling is re-
cases given above, how many test cases will be duced.
able to capture the flaw? [2013] (c) Average cohesion goes down and coupling
(a) Only one (b) Only two also reduces.
(c) Only three (d) All four (d) Average cohesion and coupling increase.
Solution: (b) Solution: (a)
Case 1, 3, and 4 will work but case 2 will not work
because the output strings do not match with ‘oldc’
array elements ‘a’, ‘b’, ‘c’, ‘d’, and ‘e’.
Case 1, 3, and 4 are evaluated by outer strings
whereas Case 2 does not match.
Hance, the correct option is (b)
2. If array A is made to hold the string ‘abcde’, which
Module 1 Module 2
of the above four test cases will be successful is
exposing the flaw in this procedure? [2013] Average Cohesion = 14/15
(a) None (b) 2 only Average coupling = 2/2
(c) 3 and 4 only (d) 4 only After,
Solution: (c)
The above flaw is exposed by the test cases 3 and 4
only.
Test 3: Expected A after replacements = ‘abcde’
→ ‘abcde’
Result from code = ‘abcde’ → ‘bacde’
Test 4: Expected ‘abcde’ → ‘bacde’
Result from code = ‘abcde’ → ‘abcde’ Average cohesion = 14/15
Hance, the correct option is (c) Average coupling = 2/2
The average coupling and cohesion between mod-
3. The following figure represents access graphs of two ules in the system of two modules is unchanged.
modules M1 and M2. The filled circles represent Hance, the correct option is (a)
methods and the unfilled circles represent attributes.
4. The following is comment written for a c func-
If method m is moved to module M2 keeping the
tion. This function computes the roots of quadratic
attributes where they are, what can we say about
equation.
the average cohesion and coupling between mod-
ules in the system of two modules? ax2 + bx + c = 0 the function stores two real roots in
* root1 & * root2 and returns the status of validity
of roots. In handles four different kinds of cases

GATE_CSE_Unit11_Software Engineering.indd 6 11/19/2015 3:30:35 PM


Chapter 1  Software Engineering | 11.7

i) When coefficient a is zero or irrespective of else if(c = = d){S2;}


discriminate else {S3; exit;}
ii) When discriminate is positive.
S4;
iii) When discriminate is zero
iv) When discriminate is negative end
Only in cases (ii) & (iii) the stored roots are valid. The test cases T1, T2. T3 & T4 given below are
Otherwise 0 is stored in the roots; the function expressed in terms of the properties satisfied by
returns 0 when the roots are valid & - 1 otherwise. the values of variables a, b, c and d. The exact
The function also ensures root1 > = root2. values are not given.
T1: a, b, c and d are all equal
int get_QuadRoots(float a, float b, float c, float *
T2: a, b, c and d are all distinct
root1, float * root2);
T3: a = b and c! = d
A software test engineer is assigned the job of T4: a! = b and c = d
doing black box testing. He comes up with the fol-
Which of the test suites given below ensures cov-
lowing test cases, many of which are redundant
erage of statements S1, S2 S3 and S4.
Input Expected (a) T1, T2, T3 (b) T2, T4
Put set
set out (c) T3, T4 (d) T1 , T2, T4[2010]
Test Root Root Rectory Solution: (d)
a b c
case 1 2 value
The exit() function is a library function and it
T1 0.0 0.0 7.0 0.0 0.0 -1 breaks out of the program, abandoning rest of the
T2 0.0 1.0 3.0 0.0 0.0 -1 execution of the program. In the given problem, we
T3 1.0 2.0 1.0 -1.0 -1.0 0 need to take decision based on variable values, as
values are not determined. The test suites given in
T4 4.0 -12.0 9.0 1.5 1.5 0
option (d) – T1, T2, T3, and T4 ensure coverage of
T5 1.0 -2.0 -3.0 3.0 -1.0 0 the Statements S1, S2, S3, and S4.
T6 1.0 1.0 4.0 0.0 0.0 -1
Hance, the correct option is (d)
6. Which of the following statements are TRUE?
Which one of the following options provide the
 [2009]
set of non-redundant tests using equivalence class
I. The content diagram should depict the system
partitioning approach from input perspective for
as a single bubble.
black box testing? [2011]
II. External entities should be identified clearly at
(a) T1, T2, T3, T6 (b) T1, T3, T4, T5
all levels of DFDs
(c) T2, T4, T5, T6 (d) T2, T3, T4, T5
III. Control information should not be represented
Solution: (c) in a DFD
The test cases T1 and T2 are checking same condi- IV. A data store can be connected either to another
tion a = 0, so any of T1 and T2 is redundant. data store or to an external entity [2009]
The test cases T3 and T4 are case discriminant. (a) II & III (b) I, II & IV
(c) I & III (d) I, II & III
D = b2 - 4ac = 0. So, any of T3 and T4 is redundant.
The test cases T5 and T6 are checking for D > 0 and Solution: (c)
D < 0, respectively. Hence, option (c) is correct. A Data Flow Diagram (DFD) represents the flow
Hance, the correct option is (c) of data between different processes. DFD is a
graphical representation of the system which takes
5. The following program is to be tested for state-
an input-process-output view of the system. Data
ment coverage,
objects are represented by labeled arrows, and
begin transformation are represented by bubbles or cir-
if(a = = b){Sl;exit;} cles. The context diagram represents the system as
a whole.

GATE_CSE_Unit11_Software Engineering.indd 7 11/19/2015 3:30:36 PM


11.8 | Software Engineering

Valid Notations: (a) I & II (b) II & III


(c) I & III (d) I, II & III
Solution: (b)
The cyclomatic complexity is equal to the number
of different paths in a method (function) plus one.
The cyclomatic complexity is defined as:
V (G) = p + 1
Where p are predicates.
The cyclomatic complexity is calculated by:
V (G) = e – n + 2p
Where,
Hance, the correct option is (c) e = No. of edges
n = No. of nodes
7. Consider the following statements about the cyc-
p = No. of connected graph
lomatic complexity of the control flow graph of a
program module. Which of these are TRUE? For most of the control flow graphs, all the nodes
I. The cyclomatic complexity of a module is are connected, hence p = 1, then V (G) = e - n + 2
equal to the maximum number of linear inde- V (G) = Number of internal persons + 1 (External
pendent circuits in the graph. Region)
II. The cyclomatic complexity of a module is the Hance, the correct option is (b)
number of decisions in the module plus one,
where a decision is effectively any conditional
statement in the module.
III. The cyclomatic complexity can also be used
as number of linearly independent paths that
should be tested during path coverage testing.
 [2009]

GATE_CSE_Unit11_Software Engineering.indd 8 11/19/2015 3:30:36 PM


UNIT XII
WEB TECHNOLOGIES

Chapter 1: Web Technologies 12.3

GATE_CSE_Unit12_Web Technologie.indd 1 11/19/2015 3:31:31 PM


GATE_CSE_Unit12_Web Technologie.indd 2
EXAM ANALYSIS
Exam year 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
1 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 1 1 1 0 1 0
2 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
5 Marks Ques. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Total Marks 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 2 0 0 1 1 1 0 1 0

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]

GATE_CSE_Unit12_Web Technologie.indd 3 11/19/2015 3:31:31 PM


12.4 | Web Technologies

(a) (2, 2, 3) and (2, 3, 2) (c) HTTP allows information to be stored in a


(b) (2, 2, 3) and (2, 2, 3) URL.
(c) (2, 3, 2) and (2, 3, 2) (d) HTTP can be used to test the validity of a hy-
(d) (2, 3, 2) and (2, 2, 3) pertext link.
Solution: (c) Solution: (b)
Rowspan is used to specify how many rows a cell (a) It uses TCP/IP in transport layer and network
should span and Colspan is used to specify how layer.
many columns a cell should span. (b) HTTP is used to access the web pages.
Hence, the correct option is (c) (c) Pages are accessible by HTTP for which URLs
5. Consider the three commands: PROMPT, HEAD and provide reference to the pages.
RCPT. Which of the following options indicate a cor- (d) As HTTP is links of web pages, it can be used
rect association of these commands with protocols to test validity.
where these are used [2005]
Hence, the correct option is (b)
(a) HTTP, SMTP, FTP
(b) FTP, HTTP, SMTP 8. Which of the following objects can be used in
(c) HTTP, FTP, SMTP expressions and scriplets in JSP (Java Server
(d) SMTP, HTTP, FTP Pages) without explicitly declaring them? [2004]
Solution: (b) (a) Session and request only
(b) Request and response only
 FTP Command: PROMPT- force interactive
(c) Response and session only
prompting on multiple commands
(d) Session, request and response
HTTP Command: HEAD- checks the character-
istics of web pages without downloading it. Used Solution: (a)
when the content of file is not required. • Session object contains session data.
SMTP Command: RCPT – identifies the message • Request objects contain data passed by client
recipients. to server.
Hence, the correct option is (b) •  Response object is output send to client by
server.
6. A HTML form is to be designed to enable pur-
chase of office stationery. Required items are to
• Expression is action element in JSP.
be selected (checked). Credit card details are
• Response cannot be used in expression re-
sponse as expression itself writes in response
to be entered and then the submit button is to object.
be pressed. Which one of the following options
would be appropriate for sending the data to the
•  All three objects request, response and session
can be used in scriplets as Scriplet is used to
server. Assume that security is handled in a way write Java code.
that is transparent to the form design. [2005]
Hence, the correct option is (a)
(a) Only GET
(b) Only POST 9. Consider the following statements:
(c) Either of GET or POST (I) telnet, ftp and http are application layer proto-
(d) Neither GET nor POST cols.
Solution: (c) (II) EJB (Enterprise Java Beans) components can
GET method is used to send small size data but it is not be deployed in a J2EE (Java 2 Enterprise Edi-
so secured; POST method is used to send large size of tion) application server.
data in a secure manner. In this case, form data is small (III) If two languages confirm to the Common Lan-
and credit card details are hidden in form, so, can be guage Specification (CLS) of the Microsoft.
sent using any of the two methods. NET framework, then a class defined in any
Hence, the correct option is (c) one of them may be inherited in the other.
7. Which of the following statements is FALSE? Which of the following Statements are true?
 [2004]  [2004]
(a) HTTP runs over TCP. (a) I and II only (b) II and III only
(b) HTTP describes the structure of web pages. (c) I and III only (d) I, II and III

GATE_CSE_Unit12_Web Technologie.indd 4 11/19/2015 3:31:31 PM


Chapter 1  Web Technologies  |  12.5

Solution: (d) <title> GATE 2005 </title>


Hence, the correct option is (d) <type value= “ BROCHURE”/>
<accno> 10237623786 </accno>
</Book>
Two-marks Questions <Book>
<type value= “ FICTION” />
1. Consider the following XML DTD describing <accno> 0024154807 </accno
course information in a university: </Book>
<! ELEMENT Univ  Given below are several possible excerpts
(Course + Prof)> from “library.dtd”. For which excerpt would
<! ELEMENT Course the above specification be valid?
(Title, Eval*)> [2005]
 <! ATTLIST Course number ID (a) 
<! ELEMENT Book (title+, type,
#REQUIRED accno)>
Instructor IDREF # IMPLIED> <! ELEMENT title(# PCDATA)>
<! ELEMENT Title (# PCDATA)> <! ELEMENT type ATTL1ST>
<! ELEMENT Eval ( n PCDATA)> <IA1TLIST type value
 <! ATTLIST Eval Score CDATA # (BROCHURE|FICTION|TECHNICAL)>
REQUIRED> <!ELEMENT accno (# PCDATA)>
<! ELEMENT Prof Empty> (b)  <! ELEMENT Book (title? , type,
 <!ATTLIST Prof Name ID # REQUIRED accno)>
Teaches <! ELEMENT title(#PCDATA)>
IDREF # IMPLIED> <! ELEMENT type ATTLIST>
What is returned by the following XQUERY? <IATTLIST type value
Let$ as : = //@ Score (BROCHURE|FICTION|TECHNICAL)>
For $ c in /Univ/Course [Eval] <! ATTLIST accno (# PCDATA)>
Let$cs : = $ c/Eval/@Score (c)  <! ELEMENT Book (title*, type,
Where min ($cs)> avg ($ as) accno)>
Return $ c [2006] <! ELEMENT title (# PCDATA)>
(a) The professor with the lowest course evaluation <! ELEMENT type ATTLIST>
(b) Professors who have all their course evaluation <!ATTLIST type value
above the university average (BROCHURE|FICTION|TECHNICAL)>
(c) The course with the lowest evaluation <!ELEMENT accno (# PCDATA)>
(d) Course with all evaluations above the university (d) 
<! ELEMENT Book (title? , type,
average accno)>
Solution:  (d) <! ELEMENT title (# PCDATA)>
 <! ELEMENT type EMPTY>
Return $ c-query return ‘c’ where ‘c’ is as course with <!ATTLISTtypvaue
all evaluations. (BROCHURE |FICTION|TECHNICAL)>
Where min($cs)> avg ($ as) –min(cs) minimum <!ELEMENT accno (# PCDATA)>
score of each evaluation in a co avg(as) is average of Solution:  (d)
all the scores in courses from all professors. Book tag is repeated twice:
Hence, the correct option is (d) <title> can be either
2. Given below is an excerpt of an xml specification. 1. Zero or more(*)
<! DOCTYPE library SYSTEM 2. Zero or one(?)
“ library .dtd”> <type> is EMPTY and have an attribute
<Book> Hence, the correct option is (d)

GATE_CSE_Unit12_Web Technologie.indd 5 11/19/2015 3:31:31 PM


This page is intentionally left blank.

11/19/2015 3:31:31 PM

You might also like