Professional Documents
Culture Documents
2000
2004 (50 QUESTIONS)
2020 SET1 (30 QUESTIONS)
Gate 2000
1.1 The minimum number of cards to be dealt from an arbitrarily shuffled deck of 52
cards to guarantee that three cards are from some same suit is
(a) 3 (b) 8 (c) 9 (d) 12
Solution:
Use Pigeon Hole Principle:
N=(R-1)k+1 R=3;k=4 (52 cards 4 different shades)
= 2*4+1=9
We know that there are 4 suits. Let, Heart= H Spade= S Diamond= D
Club= C
So the possible withdrawal sequence (alternating/worst case)
HSDCHSDCHSDCHSDC__ (this 9th card will make 3 cards of same suit.)
Therefore option C
1.4 Let S and T be language over ={a,b} represented by the regular expressions
(a+b*)* and (a+b)*, respectively. Which of the following is true?
(a) S T (b) T S (c) S = T (d) S T =
1.8 Comparing the time T1 taken for a single instruction on a pipelined CPU with time
T2 taken on a non-pipelined but identical CPU, we can say that
(a) T1 T2 (b) T1 T2 (c) T1 < T2
(d) T1 is T2 plus the time taken for one instruction fetch cycle
Pipelined CPU has greater throughput than non-pipelined
1.15 Let s be a sorted array of n integers. Let t(n) denote the time taken for the most
efficient algorithm to determined if there are two elements with sum less than
1000 in s. which of the following statements is true?
(a) t (n) is 0(1) (b) n t(n) n log2 n
(c) n log2 n t(n) <
Solution:
Array is sorted. The sum of first 2 elements either will be less than 1000 or will be more than 1000.
and if first 2 elements(which are smallest one) have sum more than 1000, then no other sum will be
less than 1000
1.16 Aliasing in the context of programming languages refers to
(a) multiple variables having the same memory location
(b) multiple variables having the same value
(c) multiple variables having the same identifier
(d) multiple uses of the same variable
Solution:
In computer programming, aliasing refers to the situation where the same memory location can
be accessed using different names. For instance, if a function takes two pointers A and B which have
the same value, then the name A aliases the name B.
Here, structure creates the memory for 'array and unionarray and union', but union only creates the
memory for only 'long z' which is the largest size data type inside it.
Hence,
short×[5]=5∗2=10short×[5]=5∗2=10 bytes [ shorts take 22 bytes]
long z=8long z=8 bytes
So, (10+8)=1810+8)=18 bytes
1.20. Which of the following need not necessarily be saved on a context switch
between processes?
(a) General purpose registers (b) Translation look-aside buffer
(c) Program counter (d) All of the above
We don't need to save TLB or cache to ensure correct program resumption. They are just bonus for
ensuring better performance. But PC, stack and registers must be saved as otherwise program
cannot resume.
TLS buffer need not be saved as it will flush out the contents of the switched process and
will have the new process contents.
2.1 X, Y and Z are closed intervals of unit length on the real line. The overlap of X and Y is half a
unit. The overlap of Y and Z is also half a unit. Let the overlap of X and Z be k units. Which of the
following is true?
(a) k must be 1 (b) k must be 0
(c) k can take any value between 0 and 1 (d) None of the above
2.4. Let P(S) denotes the powerset of set S. Which of the following is always true? (a)
P(P(S))=P(S) (b) P(S) P(P(S)) = {}
(c) P(S) S = P(S) (d) S P(S)
2.5. Let a, b, c, d be propositions. Assume that the equivalence a
(b V-b) and b
c hold. Then the truth-value of the formula a b a c d
is always
(a) True (b) False
(c) Same as the truth-value of b (d) Same as
the truth-value of d
2.6. What can be said about a regular language L over {a} whose
minimal finite state automation has two states?
(a) L must be {an|n is odd} (b) L must
be {an|n is even}
(c) L must be {an|0}
(d) Either L must be {an|n is odd}, or L must be {an| n is even}
2.10. P Q 1 T
he following arrangement of master-slave flip flops
JK D
1
Clock
has the initial state of P, Q as 0, 1 (respectively). After the clock cycles the output
state P, Q is (respectively),
(a) 1, 0 (b) 1, 1 (c) 0, 0 (d) 0, 1
2.11. A graphics card has on board memory of 1 MB. Which of the following modes can the card
not support?
(a) 1600 400 resolution with 256 colours on a 17 inch monitor
(b) 1600 400 resolution with 16 million colours on a 14 inch monitor
(c) 800 400 resolution with 16 million colours on a 17 inch monitor
(d) 800 800 resolution with 256 colours on a 14 inch monitor
A. 256 colors means 8 bits for color representation meaning 1 byte. So, 1600 * 400 resolution
requires 640 kB. We have 1 MB, so fine.
B. 16 million colors require 24 bits or 3 bytes. So, 1600 * 400 resolution requires 640 k * 3 = 1920
kB which is over our on board memory. So, not possible.
C. Again 3 bytes for a color. 800 * 400 resolution requires 320 k * 3 = 960 kB which is fine as we
have 1 MB on board.
D. 256 colors require 1 byte. 800 * 800 resolution requires 640 k * 1 = 640 kB which is again fine.
So, answer is B.
2.12. Consider the values of A = 2.0 1030, B = -2.0 1030, C = 1.0, and the sequence
X: = A + B Y:= A + c
X: = X + C Y:= Y + B
Executed on a computer where floating point numbers are represented with 32 bits. The
values for X and Y will be
(a) X = 1.0, Y = 1.0 (b) X = 1.0, Y = 0.0
(c) X = 0.0, Y = 1.0 (d) X = 0.0, Y = 0.0
2.13. Suppose you are given an array s[1…n] and a procedure reverse (s,i,j) which reverses the
order of elements in a between positions i and j (both inclusive). What does the following
sequence do, where 1 k n:
reverse (s, 1, k);
reverse (s, k + 1, n);
reverse (s, 1, n);
(a) Rotates s left by k positions (b) Leaves s unchanged
(c) Reverses all elements of s (d) None of the above
2.14. Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder
and preorder traversal. Respectively, of a complete binary tree. Which of the following is
always tree?
(a) LASTIN = LASTPOST (b) LASTIN = LASTPRE
(c) LASTPRE = LASTPOST (d) None of the above
2.17. The value of j at the end of the execution of the following C program
int incr (int i)
{
static int count = 0;
count = count + i;
return (count);
}
main () {
int i,j;
for (i = 0; i <=4; i++) j
= incr(i);
}
is
(a) 10 (b) 4 (c) 6 (d) 7
2.19. Suppose the time to service a page fault is on the average 10 milliseconds, while a
memory access takes 1 microsecond. Then a 99.99% hit ratio results in average memory
access time of
(a) 1.9999 milliseconds (b) 1 millisecond
(c) 9.999 microseconds (d) 1.9999 microseconds
2.26 In SQL, relations can contain null values, and comparisons with null values are treated as
unknown. Suppose all comparisons with a null value are treated as false. Which of the
following pairs is not equivalent?
(a) x = 5 not (not (x = 5)
(b) x = 5 x > 4 and x < 6, where x is an integer
(c) x 5 not (x = 5)
(d) None of the above
Gate 2004
1. The goal of structured programming is to:
A. have well indented programs
B. be able to infer the flow of control from the compiled code
C. be able to infer the flow of control from the program text
D. avoid the use of GOTO statements
It means user can execute the code according to his requirement. CC and Pascal are good example of
structured programming. In structured programming control passes one instruction to another
instruction in sequential manner.
Avoiding the use of GOTO statements is not the goal of structured programming, it (avoiding the use
of GOTO) is one of the requirements for a program to be structured.
Option A will not exchange the values of xx and yy because parameters are passed by value in C. i.e.,
the code is exchanging x′x′ and y′y′ which are having the values of xx and yy respectively.
Option B will not swap the value
void swap(int a, int b)
Here, it is wrong to pass in address (int*) as the parameters are of int type, even sizeof int and int*
varies depending on the compiler. Now, even if ignoring this error, the given code would not
exchange the values of xx and yy as it is merely exchanging p′1p1′ and p′2p2′ where p′1p1′ and p
′2p2′ are containing the copies of the addresses of xx and yy respectively. (Even addresses are
passed by value in C language).
Option C is false, return value is not required for exchanging the variables.
Option D is correct. We cannot use swap(x,y)swap(x,y) because parameters are passed by value.
Only way now to exchange the variables are by passing their addresses and then modifying the
contents using the de-referencing operator (∗).
Therefore to exchange the values of x and y, we cannot use pass by value( given code is for pass by
value). So option D is correct
6. Level order traversal of a rooted tree can be done by starting from the root and
performing
A. preorder traversal
B. in-order traversal
C. depth first search
D. breadth first search
Solution:
Preorder traversal: Root, then L, then R
Inorder traversal: L, then Root, then R
Postorder traversal: L, then R, then Root
Levelorder traversal: Start from the root and call BFS.
Level order traversal of the tree resembles the Breadth-first search of the graph and also level order
traversal uses the queued data structure.
11. Consider the following statements with respect to user-level threads and kernel-
supported threads
I. context switch is faster with kernel-supported threads
II. for user-level threads, a system call can block the entire process
III. Kernel supported threads can be scheduled independently
IV. User level threads are transparent to the kernel
Which of the above statements are true?
A. (II), (III) and (IV) only
B. (II) and (III) only
C. (I) and (III) only
D. (I) and (II) only
Solution:
I. User level thread switching is faster than kernel level switching. So, (I) is false.
II. is true.
III. is true.
IV. User level threads are transparent to the kernel
In case of Computing transparent means functioning without being aware. In our case user
level threads are functioning without kernel
being aware about them. So (IV) is actually
correct.
"The kernel knows nothing about user-level threads
and manages them as if they were single-threaded
processes"
12. Consider an operating system capable of loading and executing a single sequential user
process at a time. The disk head scheduling algorithm used is First Come First Served
(FCFS). If FCFS is replaced by Shortest Seek Time First (SSTF), claimed by the vendor to
give 50%50% better benchmark results, what is the expected improvement in the I/O
performance of user programs?
A. 50%
B. 40%
C. 25%
D. 0%
Question says "single sequential user process". So, all the requests to disk scheduler will be in
sequence and each one will be blocking the execution and hence there is no use of any disk
scheduling algorithm. Any disk scheduling algorithm gives the same input sequence and hence the
improvement will be 0%0% for SSTF over FCFS.
Answer is (B).
C in R1 is a foreign key referring to the primary key D in R2. So, every
element of C must come from some D element.
18. In an SR latch made by cross-coupling two NAND gates, if both S and R inputs are set
to 0, then it will result in
a. Q=0,Q′=1
b. Q=1,Q′=0
c. Q=1,Q′=1
d. Indeterminate states
19. If 73x (in base-x number system) is equal to 54y (in base-y number system), the
possible values of x and y are
(A) 8, 16
(B) 10, 12
(C) 9, 13
(D) 8, 11
Solution:
abx= cdy => b+a*x=d+c*y
We can solve it by converting both to decimals.
3 + 7*8 = 4 + 11*5
20. Which of the following addressing modes are suitable for program relocation at run
time?
I. Absolute addressing
II. Based addressing
III. Relative addressing
IV. Indirect addressing
A. I and IV
B. I and II
C. II and III
D. I, II and IV
21. The minimum number of page frames that must be allocated to a running process in a
virtual memory environment is determined by
A. the instruction set architecture
B. page size
C. number of processes in memory
D. physical memory size
Its instruction set architecture .if you have no indirect addressing then you need at least two pages in
physical memory. One for instruction (code part) and another for if the data references memory. if
there is one level of indirection then you will need at least three pages one for the instruction(code)
and another two for the indirect addressing. If there three indirection then minimum 44 frames are
allocated.
Pages in virtual address space (which is what all code running under a virtual memory OS deals with)
are called simply pages, or virtual pages.
Pages in physical memory (RAM) are called physical memory, or physical pages, or... "page frames
The maximum number of frames that a process can have in the physical memory depends on
Options B, C and D.
Page size and physical memory size determine the total number of frames. And the number of
processes in the physical memory also play a role
22. How many 8−bit characters can be transmitted per second over a 9600 baud serial
communication link using asynchronous mode of transmission with one start bit, eight data bits, two
stop bits and one parity bit?
a. 600 b. 800 c. 876 d. 1200
23. Identify the correct translation into logical notation of the following assertion.
Some boys in the class are taller than all the girls
Note: taller(x,y) is true if x is taller than y.
a. (∃x)(boy(x)→(∀y)(girl(y)∧taller(x,y)))
b. (∃x)(boy(x)∧(∀y)(girl(y)∧taller(x,y)))
c. (∃x)(boy(x)→(∀y)(girl(y)→taller(x,y)))
d. (∃x)(boy(x)∧(∀y)(girl(y)→taller(x,y)))
Binomial distribution:-
P(H) = 1/2
P(T) = 1/2
4
C2(1/2)2(1/2)2 = 6/16 = 3/8.
27. Let A,B,C,D be n×n matrices, each with non-zero determinant. If ABCD=I, then B −1 is
a. D−1C−1A−1
b. CDA
c. ADC
d. Does not necessarily exist
29. The tightest lower bound on the number of comparisons, in the worst case, for
comparison-based sorting is of the order of
a. n b. n2 c. nlogn d. nlog2n
34. It is desired to design an object-oriented employee record system for a company. Each employee
has a name, unique id, and salary. Employees belong to different categories and their salary is
determined by their category. The functions get name, getId and compute salary are required. Given the
class hierarchy below, possible locations for these functions are:
I. getId is implemented in the superclass
II. getId is implemented in the subclass
III. getName is an abstract function in the superclass
IV. getName is implemented in superclass
V. getName is implemented in subclass
VI. getSalary is an abstract function in the superclass
VII. getSalary is implemented in the superclass
VIII. getSalary is implemented in the subclass
35. Consider the label sequences obtained by the following pairs of traversals on a labeled
binary tree. Which of these pairs identify a tree uniquely?
I. preorder and postorder
II. inorder and postorder
III. preorder and inorder
IV. level order and postorder
A. I only
B. II, III
C. III only
D. IV only
36. A circularly linked list is used to represent a Queue. A single variable pp is used to access the
Queue. To which node should pp point such that both the
operations enQueueenQueue and deQueuedeQueue can be performed in constant time?
A. rear node
B. front node
C. not possible with a single pointer
D. node next to front
38. Assume that the operators +,−,×are left associative and ^ is right associative. The order of
precedence (from highest to lowest) is ^,×,+,−. The postfix expression corresponding to the infix
expression a+b×c−d^e^f is
A. abc×+def^^−
B. abc×+de^f^−
C. ab+c×d−e^f^
D. −+a×bc^^def
Solution:
Use Bracket according to precedance
^ - Precedance from Right to Left and others left to right
((a + (b * c )) - (d ^ (e ^ f))) then solve it
But if the question asked best time complexity in which of the following implementation (not
algorithm) then Option a is correct.
40. Suppose each set is represented as a linked list with elements in arbitrary order. Which
of the operations among union, intersection, membership, cardinality will be the slowest?
A. union only
B. intersection, membership
C. membership, cardinality
D. union, intersection
Membership is linear search - O(n1+n2) (traverse all nodes of L1 and L2 and look for a match)
Cardinality is linear - O(n1+n2) (simple count all the nodes)
For union we need to ensure no duplicate elements should be present - O(n1×n2) for each element
we need to check if that element exists in other set
For intersection also for every element in set1 we need to scan set2 - O(n1×n2)
44. Suppose we run Dijkstra’s single source shortest path algorithm on the following edge-
weighted directed graph with vertex P as the source.
In what order do the nodes get included into the set of vertices for which the shortest path distances
are finalized?
A. P,Q,R,S,T,U
B. P,Q,R,U,S,T
C. P,Q,R,U,T,S
D. P,Q,T,R,U,S
45. Consider the grammar with the following translation rules and E as the start symbol
Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4
a. 200 b. 180 c.160 d.40
Here # is multiplication and & is addition by semantics rules given in the question.
By observation of productions,
1. here &(+) is higher precedence than #(*), because & is far from starting symbol
2. both &,# are left associative
So, we can solve the expression as ((2∗(3+5))∗(6+4))=160
"Operator which is at lower level in the grammar is termed to have higher precedence."
if there is left recursion then operator will be left associative .. or if right recursion then
operator will be right associate ..
eg : E---> E+T(here E derive E+T so it is left recursive
46. Consider the following set of processes, with the arrival times and the CPU-burst times
gives in milliseconds.
What is the average turnaround time for these processes with the
preemptive shortest remaining processing time first (SRPT)
algorithm?
A. 5.50
B. 5.75
C. 6.00
D. 6.25
47. Consider a system with a two-level paging scheme in which a regular memory access
takes 150nanoseconds, and servicing a page fault takes 8 millisecond. An average
instruction takes 100nanoseconds of CPU time, and two memory accesses. The TLB hit
ratio is 90%, and the page fault rate is one in every 10,000 instructions. What is the
effective average instruction execution time?
A. 645 nanoseconds
B. 1050 nanoseconds
C. 1215 nanoseconds
D. 1230 nanoseconds
Ans: D
50. The relation scheme Student Performance (name, courseNo, rollNo, grade) has the
following functional dependencies:
name, courseNo, → grade
rollNo, courseNo → grade
name → rollNo
rollNo → name
The highest normal form of this relation scheme is
A. 2NF
B. 3NF
C. BCNF
D. 4NF
2. Let P be an array containing n integers. Let t be the lowest upper bound on the number
of comparisons of the array elements, required to find the minimum and maximum values
in an arbitrary array of n elements. Which one of the following choices is correct?
A. t>2n−2
B. t>3⌈n2⌉ and t≤2n−2
C. t>n and t≤3⌈n/2⌉
D. t>⌈log2(n)⌉ and t≤n
Which algorithm out of the following options uses the least number of comparisons (among the array
elements) to sort the above array in ascending order?
(A) Selection sort
(B) Mergesort
(C) Insertion sort
(D) Quicksort using the last element as pivot
Explanation:
No algorithm can beat insertion sort, if array is already sorted
Paging is the technique of non contiguous allocation of physical memory which solves
external fragmentation. True
Paging may cause internal fragmentation depends on the page size and process size in last
page, if page size is larger and process size is smaller. False
Implementation of Paging requires management of Page tables which resides in pages and
hence consume additional memory. True
Multilevel paging is required when size of page table exceeds the size of page. Since page
table reside in page, it is further divided to pages of same size. False
13. Suppose a database system crashes again while recovering from a previous crash.
Assume checkpointing is not done by the database either during the transactions or during
recovery. Which of the following statements is/are correct?
(A) The same undo and redo list will be used while recovering again
(B) The system cannot recover any further
(C) All the transactions that are already undone and redone will not be recovered again
(D) The database will become inconsistent
14. Which of the following standard C library functions will always invoke a system call
when executed from a single-threaded process in a UNIX/Linux operating system?
(A) exit
(B) malloc
(C) sleep
(D) strlen
Answer: (A) (C)
The exit and sleep call in Linux is also a system call.
malloc is a library call and not always a system call. This is a function defined in standard C library
and it does not always invoke the system call. When a process is created, certain amount of heap
memory is already allocated to it, when required to expand or shrink that memory, it internally uses
sbrk/brk system call on Unix/Linux.
15. Consider a linear list based directory implementation in a file system. Each directory is
a list of nodes, where each node contains the file name along with the file metadata, such
as the list of pointers to the data blocks. Consider a given directory foo. Which of the
following operations will necessarily require a full scan of foo for successful completion?
(A) Creation of a new file in foo
(B) Deletion of an existing file from foo
(C) Renaming of an existing file in foo
(D) Opening of an existing file in foo
Explanation:
The key here’s it is asking for successful completion.
Let’s take option one by one
A. Creation of new file → while creating new file we have to check whether same name file
exist or not , so we always need full scan for this
B. Deletion of an existing file → for deleting file , file can be present at any node (best case if
present as first node, worst if present at last). So we don’t always need to full scan list.
C. Renaming of file → same reason can be given as option A.
D. Opening of existing file → same reason as option B.
So correct options are A , C
16. In an undirected connected planar graph G, there are eight vertices and five faces. The
number of edges in G is _________.
(A) 10
(B) 11
(C) 12
(D) 6
Given: For a planner graph G
Number of vertices(V)= 8
Number of region/faces(R/f)=5
Number of edges (E)=?
For any planner graph V+F=E+2
⟹8+5=E+2
⟹E=13−2=11
∴ Number of edges in given graph G is 11.
Similar Question: UGC NET june 2012
1. Two graphs A and B are shown below: Which one of the following statements is true?
Assuming the initial state of the counter given by PQRPQR as 000000, what are the next three
states?
A. 011,101,000
B. 001,010,111
C. 011,101,111
D. 001,010,000
34. Let G be a group of order 6, and H be a subgroup of G such that 1<|H|<6. Which one of
the following options is correct?
A. Both G and H are always cyclic
B. G may not be cyclic, but H is always cyclic
C. G is always cyclic, but H may not be cyclic
D. Both G and H may not be cyclic
From the above loop code we can see that the loop iterates 7 times for j∈{−3,−2,−1,0,1,2,3}.
Now, we have an “if” condition and inside it we have a logical AND operator (&&). In C language we
have the following short-circuit rule for binary logical operators
1. The second operand of logical OR operator || is ignored if the first operand is non zero.
2. The second operand of logical AND operator (&&) is ignored if the first operand is 0.
So, for j∈{−3,−2,−1} the first operand of || operator (j >= 0) will be 0, and hence the second
operand (i++) will be ignored.
For j∈{0,1,2,3} the first operand of || operator (j >= 0) will be 1,and hence the second
operand (i++) will get evaluated 4 times and final value of i=4.
The post increment operator i++, returns the original value of ii and then increments i. So, when the first
time i++ happens, the second operator of logical AND operator is 0 and hence the “if” condition fails.
The correct automata for LL must accept every binary string ending with “011” and not accept any
other binary string.
A. False it accepts binary strings ending with 111
B. False it accepts binary strings ending with 0,00,00,100,001,111 etc.
C. False it accepts binary string ending with 1111
D. True it accepts all strings that end with 011 and no other strings.
Correct Ans: D