Professional Documents
Culture Documents
GATE Overflow
GATE Overflow
GATE Overflow
(A) NP-complete = NP
(B) NP-complete ∩ P = ϕ
(C) NP-hard = NP
(D) P = NP-complete
Answer is
(B) NP-complete ∩ P = ϕ
Since, P ≠ NP, there is at least one problem in NP, which is harder than all P problems. Lets take the hardest such problem, say X . Since, P ≠ NP, X ∉ P.
Now, by definition, NP-complete problems are the hardest problems in NP and so X problem is in NP-complete. And being in NP, X can be reduced to all
problems in NP-complete, making any other NP-complete problem as hard as X . So, since X ∉ P, none of the other NP-complete problems can also be not in P.
-- Arjun Suresh
GATE2012_16 top
The recurrence relation capturing the optimal execution time of the T owersofHanoi problem with n discs is
(A) T (n) = 2T (n − 2) + 2
(B) T (n) = 2T (n − 1) + n
(C) T (n) = 2T (n/2) + 1
(D) T (n) = 2T (n − 1) + 1
T(1) = 1
T(n) = 2 T( n-1 ) +1
-- Narayan Kunal
Do i need to study P, NP computational problems like vertex cover problem also for gate
2015 or only the basic definitions? top
You would need to know some examples (not all) of NP Complete problems and why they are NP Complete. For example 3SAT problem is
NPC and in GATE they have asked about 2SAT. So, just learning some examples won't be enough.
-- Arjun Suresh
We first find a in the BST in O(log n) time. Now there are two possibilities, b can be in the right subtree ofa or b can be in the right subtree of
any of the parents of a. For the first case, we simply search forb , in the right subtree ofa and at each step we add the number of elements in
the left subtree +1, if we are moving right and simply 1 if we are moving left. When we find b , this sum will give as the required number of
elements.
For the second case also we do the same method. But first we find the common ancestor of a and b (possible inO(log n)- say p and from p to
a add the number of nodes in the right subtree for each level and add this to the required sum. So, in the worst case we have to doO(log n)
additions.
-- Arjun Suresh
top
ln N! = N ln N − N + ln √−−−
2πn
-- Arpit Dhuriya
GATE2003_66 top
The cube root of a natural number n is defined as the largest natural number m such that (m3 ≤ n) . The complexity of computing the cube root of n (n is
represented by binary notation) is
We can simply do a binary search in the array of natural numbers from 1..n and check if the cube of the number matches n. In this way we
can find the cube root in O(log n). So, options (A) and (B) are wrong.
Now, a number is represented in binary using log n bit. Since each bit is important in finding the cube root, any cube root finding algorithm
must examine each bit at least once. This ensures that complexity of cube root finding algorithm cannot be lower than log n. (It must be
Θ log n). So, (D) is also false and (C) is the correct answer.
-- gatecse
Given an integer n ≥ 3 , consider the problem of determining if there exist integersa, b ≥ 2 such that n = ab . Call this the forward problem. The
reverse problem is: given a and b , compute ab ( mod b). Note that the input length for the forward problem is ⌊log n⌋ + 1, while the input length
for the reverse problem is ⌊log a⌋ + ⌊log b⌋ + 2. Which of the following statements is TRUE?
(a) Both the forward and reverse problems can be solved in time polynomial in the lengths of their respective inputs.
(b) The forward problem can be solved in polynomial time, however thereverse problem in NP-hard.
(c) The reverse problem can be solved in polynomial time, however theforward problem in NP-hard.
pow(int a, int b)
{
if(b%2)
return a* pow(a*a, b/2);
else
return pow(a*a, b/2);
}
Now, the forward problem is also solvable in polynomial time. We need to check for all the roots ofn (from √−
1
n till n log n ) whether it is an
integer . But each of these check can be done in log n time using a binary search on the set of integers from 2..n and so, the overall
complexity will be (log n)2 which is polynomial in log n (log n is the size of input). So, (a) must be the answer.
-- gatecse
GATE2008_40 top
The minimum number of comparisons required to determine if an integer appears more than n times in a sorted array ofn integers is
2
A. Θ(n)
B. Θ(log n)
C. Θ(log∗ n)
D. Θ(1)
To check whether a given number is repeated n/2 times in the array can be done in O(log n) time.
Algo
1. find the first occurrence (index i) of x(given number) in the array which can be done in O(log n) time (a variant of binary search).
return true
-- Vikrant Singh
GATE2008_74,75 top
int f1 (int n)
{
if(n == 0 || n == 1)
return n;
else
return (2 * f1(n-1) + 3 * f1(n-2));
}
int f2(int n)
{
int i;
int X[N], Y[N], Z[N];
X[0] = Y[0] = Z[0] = 0;
X[1] = 1; Y[1] = 2; Z[1] = 3;
for(i = 2; i <= n; i++){
X[i] = Y[i-1] + Z[i-2];
Y[i] = 2 * X[i];
Z[i] = 3 * X[i];
}
return X[n];
}
The solution to this (fibonacci series) is given by Golden ratio. https://en.wikipedia.org/wiki/Golden_ratio which is O(2n). (Using theta in
question must be a mistake)
Time complexity of f2 is ϴ(n) as here all recursive calls are avoided by saving the results in an array (dynamic programming).
-- Arjun Suresh
GATE2008_78,79 top
Let xn denote the number of binary strings of lengthn that contain no consecutive 0s.
A. xn = 2xn−1
B. xn = x⌊n/2⌋ + 1
C. xn = x⌊n/2⌋ + n
D. xn = xn−1 + xn−2
A. 5
B. 7
C. 8
D. 16
0 1 -2
01 10 11 -3
010 011 101 110 111 -5
0101 0110 0111 1010 1011 1101 1110 1111 -8
So, xn = xn-1 + xn-2 (For all the strings ending in 1, we get two new strings and for all strings ending in 0, we get a new string. So, the new set
of strings for n+1, will have exactly n strings ending in 1)
x5 = 8+5 = 13
-- Arjun Suresh
GATE2000_2.15 top
Suppose you are given an array s[1....n] and a procedure reverse (s, i, j) which reverses the order of elements in s between positions i and j (both inclusive). What
does the following sequence do, where 1 ≤ k ≤ n:
Answer is (a)
Effect of the above 3 reversal for any K is equivalent to left rotation of the array of size n by k.
Let , S[1......7]
1 2 3 4 5 6 7
so, n=7 ,k = 2
-- Kalpna Bhargav
GATE2000_2.16 top
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 true?
a. LASTIN = LASTPOST
b. LASTIN = LASTPRE
c. LASTPRE = LASTPOST
d. None of the above
The answer is D.
Take any random sequence and check for the inorder, postorder and preorder Last Node.
-- Gate Keeda
GATE2000_2.18 top
Let G be an undirected connected graph with distinct edge weights. Let emax be the edge with maximum weight and emin the edge with minimum weight. Which of
the following statements is false?
GATE2001_1.14 top
Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers
using Randomized quicksort?
(A) O(n)
(C) O(n 2 )
(D) O(n!)
In worst case, we may pick pivot elements in the increasing order (input also given in sorted order) which will result in running time of O(n 2 )
Ans. C
-- Vikrant Singh
GATE2005_39 top
Suppose there are log n sorted lists of n log n elements each. The time complexity of producing a sorted list of all these elements is: (Hint:Use a heap data
structure)
Since we have log n lists we can make a min-heap of log n elements by taking the first element from each of thelog n sorted lists. Now, we
start deleting the min-element from the heap and put the next element from the sorted list from which that element was added to the heap.
(This identity can be done by making a structure of two values, one for the number and one for identifying the origin sorted list of that number
and storing this structure in the heap). In this way each delete and the corresponding insert will take O(log log n) time as delete in heap is
O(1) and inserting an element on a heap of sizen is O(log n). (here, heap size is log n). Now, we have a total of log n × n = n elements.
log n
So, total time will be O(n log log n).
-- gatecse
GATE2002_1.4 top
The minimum number of colours required to colour the vertices of a cycle with n nodes in such a way that no two adjacent nodes have the
same colour is
A. 2
B. 3
C. 4
D. n − 2[ n2 ] + 2
Chromatic number will be 3 for when n is odd and will be 2 when n is even. Option (d) is a representation for this, hence the correct answer
-- Madhur Rawat
GATE2003_12 top
Ram and Shyam have been asked to show that a certain problem Π is NP-complete. Ram shows a polynomial time reduction from the 3-SAT
problem to Π, and Shyam shows a polynomial time reduction fromΠ to 3-SAT. Which of the following can be inferred from these reductions?
So NPC.
-- Anurag_s
GATE2003_20 top
A. I and II
B. I and III
C. II and III
D. I, II, and III
so TRUE
so TRUE
2^(2n) = (2^n)^2
so FALSE
CORRECT ME IF I AM WRONG
-- Danish
GATE2006_15 top
Consider the following C-program fragment in which i, j and n are integer variables.
Let val ( j ) denote the value stored in the variablej after termination of the for loop. Which one of the following is true?
(A)
(B)
(C)
(D)
j = n/2+n/4+n/2+...+1
GATE2006_16 top
Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and S is
polynomial-time reducible to R. Which one of the following statements is true?
(A) R is NP-complete
(B) R is NP-hard
(C) Q is NP-complete
(D) Q is NP-hard
Q cannot be NP hard as no np hard problems(unless they are np) can be polynomial time reducible to np complete.Answer is B, as npc
problem can be reducible to np hard problem. But there is confusion if Q is not NP hard then what complexity class it is in!!
-- Shaun Patel
GATE2006_17 top
An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an
array
(A) Solves it in linear time using a left to right pass of the array
(B) Solves it in linear time using a right to left pass of the array
(C) Solves it using divide and conquer in time Θ(n log n)
(D) Solves it in time Θ(n 2 )
We can move from right keeping a note of the maximum element(suppose current_max). At the start the right most element will
always be a leader. If an element is greater than our current_max, it will a leader. Add this element to leaders. Set current_max to
this element and carry on leftward. Time Complexity would be O(n)
-- Madhur Rawat
GATE2004_29 top
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) n 2
(c) n log n
(d) n log2 n
For comparison-based sorting the asymptotically tight bound for worst case is given by Θ(log n), which means it is the tightest upper bound
(big O) as well as the tightest lower bound (big omega). So, answer is n log n.
Tightest lower bound of sorting (say S(n)) is n log n means there is no function f which has an order of growth larger than n log n and
f(n) = Ω(S(n)) holds.
A usual mistake is to think worst case changes with lower and upper bounds, but that is not the case. Worst case is defined for the problem
and it is always the input which causes the algorithm the maximum complexity.
-- Arjun Suresh
GATE2004_44 top
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
Ans is (B). In Dijkstra's algorithm at each point we choose the smallest weight edge which starts from any one of the vertices in the shortest
path found so far and add it to the shortest path.
-- gate_asp
GATE2004_82 top
Let A[1, …n] be an array storing a bit (1 or 0) at each location, and f(m) is a function whose time complexity isΘ(m). Consider the following
program fragment written in a C like language:
counter =0;
for (i=1; i<=n; i++)
{ if a[i] == 1) counter++;
else {f (counter); counter = 0;}
}
A. Ω(n 2 )
C. Θ(n)
D. o(n)
The key part in the code is "counter = 0" in the else part as we can see below.
Lets take the best case. This happens when a[i] = i for all i, and then the loop executes with time complexity (1) for each iteration and hence
overall time complexity of ϴ(n) and we can say time complexity of the code fragment is Ω(n) and hence options a and b are false.
Now, consider the worst case. This happens when a[i] = 0 or when else part is executed. Here, the time complexity of each iteration will
be (counter) and after each else counter is reset to 0. So, the maximum complexity will be (1) + (1) + ... + (1) (n times) which will
be (n) for the whole loop. Even if we mix some if part and some else part, the maximum sum of the complexities for else part will always
be ϴ(n) (because of counter = 0) and hence for the code fragment the time complexity will be ϴ(n).
Since the time complexity is Ω(n) and (n) we can say it is (n) also. Option (C). (Option D is false because the small o needs the growth
rate to be STRICTLY lower and not equal to or lower as the case for big 0)
If counter = 0 was not there in else part, time complexity would be Ω(n) and O(n2) as ϴ(1) + ϴ(2) + ... + ϴ(n) would give O(n2).
-- Arjun Suresh
GATE2004_84 top
The recurrence equation
T (1) = 1
T (n) = 2T (n − 1) + n, n ≥ 2
evaluates to
=n(2n-1) -(n.2n-2n+1+2)
= 2n+1-n -2
-- suraj
GATE2004_85 top
A program takes as input a balanced binary search tree with n leaf nodes and computes the value of a functiong(x) for each node x. If the cost
of computing g(x) is
A. Θ (n)
B. Θ (n log n)
C. Θ(n 2 )
D. Θ (n 2 log n)
should be B....at the root node the cost would be n/2 and similarly at each level the cost would be n/2 and so for log n levels it would be n/2
log n.
-- Shaun Patel
GATE2003_23 top
Time to find the 7th smallest element - requires O(2 7 − 1) = O(127) check operations to find the seventh smallest element out of 127
possible ones - Θ(1)
In short if the number of required operations is independent of the input size n, then it is always Θ(1).
(Here, we are doing a level order traversal of the heap and checking the elements)
-- gatecse
GATE2007_13 top
The maximum number of binary trees that can be formed with three unlabeled nodes is:
A. 1
B. 5
C. 4
D. 3
can be found with formula... (2nCn/n+1)... n being the number of nodes. for the given question... where n=3... answer is 5. Let me also specify
here.. that number of Binary Search Trees with n nodes is equal to number of unlabeled Binary trees.
http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_nodes
-- Gate Keeda
GATE2007_14 top
Which of the following sorting algorithms has the lowest worse-case complexity?
A. Merge sort
B. Bubble sort
C. Quick sort
D. Selection sort
A.
Irrespective of the input, Merge sort always have a time complexity of Θ(n log n).
-- Gate Keeda
GATE2007_39 top
d b e a f c g and a b d e c f g , respectively
B. e d b g f c a
C. e d b f g c a
D. d e f g b c a
The answer is A.
Take the first node in preorder traversal - a will be the root of the tree
All nodes to the left of 'a' in inorder traversal will be in the left subtree of 'a' and all elements on the right will be in the right subtree of 'a'.
Take the second element from preorder traversal - 'b' - goes to left subtree of 'a' as it is in the left of 'a' in inorder list.
Proceeding likewise we can construct the binary tree as:
-- Gate Keeda
GATE2007_46 top
Consider the following C program segment where CellNode represents a node in a binary tree:
struct CellNode {
struct CellNode *leftChild;
int element;
struct CellNode *rightChild;
};
The value returned by GetValue when a pointer to the root of a binary tree is passed as its argument is:
Answer: C
As the function returns 1 if and only if any node has both left & right children as NULL (that node is a leaf node). Hence,value gets
incremented at each leaf node.
-- Jon Snow
GATE2009_11 top
What is the number of swaps required to sortn elements using selection sort, in the worst case?
A. Θ(n)
B. Θ(n log n)
C. Θ(n 2 )
D. Θ(n 2 log n)
The answer is A.
we have 1 swap in each loop and hence n swaps at max for 1 to n. Therefore the worst case number of swaps is
-- Gate Keeda
GATE2009_39 top
In quick-sort, for sorting n elements, the (n/4) th smallest element is selected as pivot using an O(n) time algorithm. What is the worst case time
complexity of the quick sort?
A. Θ(n)
B. Θ(n log n)
C. Θ(n 2 )
D. Θ(n 2 log n)
B.
T(n)= O(n) pivot selection time + O(n) partition time + T(n/4 - 1) + T(3n/4)
-- Gate Keeda
GATE2009_53,54 top
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two
sequences X[m] and Y [n] of lengths m and n, respectively with indexes ofX and Y starting from 0 .
We wish to find the length of the longest common sub-sequence (LCS) ofX[m] and Y [n] as l(m, n), where an incomplete recursive definition
for the function I(i, j) to compute the length of the LCS ofX[m] and Y [n] is given below:
l(i,j) = 0, if either i = 0 or j = 0
= expr1, if i,j > 0 and X[i-1] = Y[j-1]
= expr2, if i,j > 0 and X[i-1] ≠ Y[j-1]
A. expr1 = l(i − 1, j) + 1
B. expr1 = l(i, j − 1)
54. The value of l(i, j) could be obtained by dynamic programming based on the correct recursive definition ofl(i, j) of the form given above,
using an array L[M, N], where M = m + 1 and N = n + 1 , such that L[i, j] = l(i, j).
Which one of the following statements would be TRUE regarding the dynamic programming solution for the recursive definition ofl(i, j)?
A. All elements of L should be initialized to 0 for the values ofl(i, j) to be properly computed.
B. The values of l(i, j) may be computed in a row major order or column major order ofL[M, N].
C. The values of l(i, j) cannot be computed in either row major order or column major order ofL[M, N].
D. L[p, q] needs to be computed before L[r, s] if either p < r or q < s.
53. Answer is C . When the currently compared elements doesn't match, we have two possibilities for the LCS, one including X[i] but not
Y[j] and other including Y[j] but not X[i].
54. Answer is D. Dynamic programming is used to save the previously found LCS. So, for any index [p,q] all smaller ones should have been
computed earlier.
else
L[i][j] = max(L[i-1][j], L[i][j-1]);
}
}
-- Praneeth A S
GATE2005_37 top
A. T (n) = O(n 2 )
C. T (n) = Ω(n 2 )
D. T (n) = O(n log n)
Hence answer is C.
-- shreya ghosh
GATE2005_45 top
Consider three decision problems P1, P2 and P3. It is known that P1 is decidable and P2 is undecidable. Which one of the following is TRUE?
A. P3 is decidable if P1 is reducible to P3
B. P3 is undecidable if P3 is reducible to P2
C. P3 is undecidable if P2 is reducible to P3
D. P3 is decidable if P3 is reducible to P2's complement
(A) If P1 is reducible to P3, then P3 is at least as hard as P1. So, no guarantee if P3 is decidable.
(B) If P3 is reducible to P2, then P3 cannot be harder than P2. But P2 being undecidable, this can't say P3 is undecidable.
(C) If P2 is reducible to P3, then P3 is at least as hard as P2. Since, P2 is undecidable, this means P3 is also undecidable -hence the answer.
(D) Complement of an undecidable problem is undecidable. Now, reducing to an undecidable problem can't prove P3 is decidable.
http://gatecse.in/wiki/Some_Reduction_Inferences
-- Arjun Suresh
GATE1999_1.12 top
GATE1999_1.14 top
20 47 15 8 9 4 40 30 12 17
\ / \ / \ / \ / \ /
20 47 8 15 4 9 30 40 12 17 after 1st pass
\ / \ / \ /
\ / \ / \/
8,15,20,47 4,9, 30,40 12,17 after 2nd pass
Ans. B
-- Vikrant Singh
GATE1999_2.21 top
n(n+1)
(M) T (n) = Sum of first n natural numbers = = O(n 2 )
2
(f(n) = n = Ω(n log b a+ϵ ) = Ω(n log 2 1+ϵ ) = Ω(n 0.5+ϵ ), satisfied for any positive ϵ less than 0.5. Also,
af( n ) < cf(n) ⟹ f( n ) < cf(n) ⟹ n < cn, satisfied for any c between 0 and 0.5)
b 2 2
(O) T (n) = Θ(n log n) = O(n log n), third case of Master theorem
(f(n) = n log n = (n log b a+ϵ ) = Ω(n log 2 1+ϵ ) = Ω(n 0.5+ϵ ), satisfied for positive ϵ = 0.5. Also,
af( nb ) < cf(n) ⟹ f( n2 ) < cf(n) ⟹ n
2
log n
2
< cn log n, satisfied for c = 0.5)
(P) Like in (M), here we are adding the log of the first n natural numbers. So,
= log(1 × 2 × ⋯ × n)
= log(n!)
GATE1999_2.24 top
a b c Return
The final return statement is c < b, so this never returns.
111
Answer D.
-- Arjun Suresh
GATE2013_30 top
The number of elements that can be sorted in Θ(log n) time using heap sort is
log n
To sort k elements in a heap, complexity is Θ(k log k). Lets assume there are elements in the heap.
log log n
log n
= Θ( log log n (log log n − log log log n))
)
log n log log log n
= Θ( log n − log log n
) = Θ(log n)
log n log log log n
⟹ Θ( log n − log log n
-- Arjun Suresh
GATE2013_31 top
int i, j, k=0;
for (i=n/2; i<=n; i++)
for (j=2; j<=n; j=j*2)
k = k + n/2;
return (k);
(A) Θ(n 2 ) (B) Θ(n 2 log n) (C) Θ(n 3 ) (D) Θ(n 3 log n)
The outer loop is running for n/2 times and inner loop is running for log2 n times (each iteration doubles j and j stops at n means log2 n times j
loop will iterate).
Now in each iteration k is incremented by n/2. So, overall k will be added n/2 * log n * n/2 with an initial value of 0. So, final value of k will
be Θ(n2 log n)
-- Arjun Suresh
GATE2013_43 top
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder
traversal sequence of the same tree?
Since it is a binary search tree, its inorder traversal produces a sorted sequence i.e. 10, 15, 20, 23, 25, 30, 35, 39, 42.
From this, we can give postorder traversal sequence as 15,10,23,25,20,35,42,39,30 i.e. option (D).
-- Happy Mittal
GATE2013_50,51 top
The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters
to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length
of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed.
Q.50 The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If
the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?
(A) Only one (B) Only two (C) Only three (D) All four
Q.51 If array A is made to hold the string “abcde”, which of the above four test cases will be successful in exposing the flaw in this procedure?
The test cases 3 and 4 are the only cases that capture the flaw. The code doesn't work properly when an old character is replaced by a new
character and the new character is again replaced by another new character. This doesn't happen in test cases (1) and (2), it happens only in
cases (3) and (4).
50. B
51. C
-- Vikrant Singh
GATE1998_1.21 top
The algorithm is an example of dynamic programming.
http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm
-- csegate2
GATE1998_1.22 top
insertion sort O(n) note if you use O(n^2) here you will not be left with any choice to fill selection sort
-- Bhagirathi Nayak
GATE2006_47 top
Which one of the following cannot be the sequence of edges added,in that order, to a minimum spanning tree using Kruskal’s algorithm?
in kruskal's algo the edges are added in non decreasing order of their weight. But in Option D edge d-e with weight 3 is added before edge d-
c with weight 2. Hence Option D is wrong option
-- Sankaranarayanan P.N
GATE2006_51 top
Consider the following recurrence:
T (n) = 2T (⌈√−
n ⌉) + 1, T (1) = 1
T (n) = 2T (n 2 ) + 1
1
= 2(T ( n 2 2 ) + 1) + 1
1
= 2 × T (n 2 2 ) + 3
1
= 4 × T (n 2 3 ) + 5
1
⋯
= 2 (lg lg n) + 2 × lg lg n + 1 (Proved below)
= O(lg n)
1
n 2k = 2
(Putting 2 so that we can take log.
One more step of recurrence can't change the complexity.)
1
lg n = 1(Taking log both sides)
2k
lg n = 2 k
k = lg lg n
-- Arjun Suresh
GATE2006_54 top
Given two arrays of numbers a1 , . . . , an and b 1 , . . . , b n where each number is 0 or 1 , the fastest algorithm to find the largest span(i, j) such
that ai + ai+1 +. . . . aj = b i + b i+1 +. . . . . b j or report that there is not such span,
#include <stdio.h>
}
if(savei >= 0)
{
printf("The largest span is from %d to %d\n", start[savei]+(savei != n), end[savei]);
//when sum zero is having the largest span, span starts from first element itself. Else, the span starts from the next element from which the span does not change
}
else
{
printf("No span\n");
}
}
-- Arjun Suresh
GATE2014-1_39 top
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ________
Ans: minimum number of comparison require to find minimum and maximum is: Approach is divide and conquer ....
T(n) = 2T(n/2) + 2
T(n) = 3/2n -2
Thus, the approach does 3/2n -2 comparisons if n is a power of 2. And itdoes more than 3/2n -2 comparisons if n is not a power of 2.
So, here in this case put n=100 and we will get (3/2)(100) - 2 = 148 comparison .....
-- Jayesh Malaviya
GATE2014-1_41 top
Consider the following C function in which size is the number of elements in the array E:
{
int Y= 0;
int z;
int i, j,k;
{ // elements of
z = 0; // all possible
z=z+E[k]; // of E
if(z>Y) // checks whether sum of elements of each subarray is greater than the sum of array if // so, that sum
is assigned toY will be the sum of elements of complete array
Y = z;
return Y; // ultimately returns the maximum possible sum of elements in any sub array of given array E
-- Kalpna Bhargav
GATE2014-2_38 top
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by
merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing
this is ____.
The optimal algorithm always chooses the smallest sequences for merging.
20 24 -44, 43 comparisons
30 35 -65, 64 comparisons
44 50 -94, 93 comparisons
65 94 -159, 158 comparisons
-- Arjun Suresh
GATE2014-3_10 top
Let A be the square matrix of size n × n . Consider the following pseudocode. What is the expected output?
C=100;
for i=1 to n do
for j=1 to n do
{
Temp = A[i][j]+C;
A[i][j] = A[j][i];
A[j][i] = Temp -C;
}
for i=1 to n do
for j=1 to n do
output (A[i][j]);
(C) Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
A.
In the computation of given pseudo code for each row and column of Matrix A, each upper
triangular element will be interchanged by its mirror image in the lower triangular and after
that the same lower triangular element will be again re-interchanged by its mirror image in
the upper triangular, resulting the final computed Matrix A same as input Matrix A.
-- Gate Keeda
GATE2014-3_12 top
Consider the following rooted tree with the vertex labeled P as the root:
The order in which the nodes are visited during an in-order traversal of the tree is
(A) SQPTRWUV
(B) SQPTUWRV
(C) SQPTWUVR
(D) SQPTRUWV
A.
GATE2014-3_13 top
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first
checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is _________.
GATE2014-3_37 top
Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a
pre-specified pair of integers i, j with i < j . Given a shortcut i, j if you are at position i on the number line, you may directly move to j . Suppose T (k) denotes
the smallest number of steps needed to move from k to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is
a shortcut to 15. Let y and z be such that T (9) = 1 + min(T (y), T (z)). Then the value of the product yz is _____.
There are only two such values where we can reach from 9 , one is simple step to right on number line , i.e 10 and another is 15 (given
shortcut)
GATE2011_25 top
An algorithm to find the length of the longest monotonically increasing sequence of numbers in an arrayA[0 : n − 1] is given below.
Let L i , denote the length of the longest monotonically increasing sequence starting at indexi in the array.
Initialize L n−1 = 1.
(B) The algorithm has a linear complexity and uses branch and bound paradigm
(C) The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm
The algorithm is storing the optimal solutions to subproblems at each point (for each i), and then using it to derive the optimal solution of a
bigger problem. And that is dynamic programming approach. And the program has linear time complexity.
http://stackoverflow.com/questions/1065433/what-is-dynamic-programming
Now, branch and bound comes when we explore all possible solutions (branch) and backtracks as soon as we find we won't get a solution (in
classical backtracking we will retreat only when we won't find the solution). So, backtracking gives all possible solutions while branch and
bound will give only the optimal one. http://www.cs.cornell.edu/~wdtseng/icpc/notes/bt2.pdf
The given algorithm here is neither backtracking nor branch and bound. Because we are not branching anywhere in the solution space.
And the algorithm is also not divide and conquer as we are not dividing the problem and then merging the solution as in the case of merge
sort (where merge is the conquer step).
https://en.wikipedia.org/wiki/Divide_and_conquer_algorithms
-- Arjun Suresh
GATE2010_34 top
The weight of a sequence a 0 , a 1 , … , a n−1 of real numbers is defined as a 0 + a 1 /2 + ⋯ + a n−1 /2 n−1 . A subsequence of a sequence is obtained by
deleting some elements from the sequence, keeping the order of the remaining elements the same. Let X denote the maximum possible weight of a subsequence
of a o , a 1 , … , a n−1 and Y the maximum possible weight of a subsequence of a 1 , a 2 , … , a n−1 . Then X is equal to
(A) max(Y , a 0 + Y )
(C) max(Y , a 0 + 2Y )
(D) a 0 + Y /2
this case,
In
-- Pragy Agarwal
GATE1997_1.5 top
answer B
-- ankitrokdeonsns
GATE1997_4.2 top
c is the answer, in AI12 matrix will result into the same matrix as A but first column will be exchanged with second column.
A matrix:
a b c
d e f
g h i
I12 matrix
010
100
001
resulted matrix
bac
edf
hgi
-- Manu Thakur
GATE1997_4.6 top
answer B
where a = 2, b = 2
-- ankitrokdeonsns
GATE1997_6.2 top
Let G be the graph with 100 vertices numbered 1 to 100. Two vertices i and j are adjacent if | i − j| = 8 or | i − j| = 12.
The number of connected components in G is
a. 8
b. 4
c. 12
d. 25
1-9-17-...-97
2-10-18-...-98
3-11-19-...-99
4-12-20-...-100
5-13-21-...-93
6-14-22-...-94
7-15-23-...-95
8-16-24-...96
We have covered all vertices using 8 vertex sets considering only ∣ i − j ∣= 8 . Using ∣ i − j ∣= 12 we can see the vertex 1 is connected to 13,
2-14, 3-15 and 4-16, so the top 4 vertex sets are in fact connected to the bottom 4 sets, thus reducing the connected components to 4.
-- Arjun Suresh
GATE1993_7.4 top
Answer is simply A i.e. it swaps the values of the two.. Take any two values for A and B. and perform the given operations over them.
-- Gate Keeda
GATE2010_35 top
#include<stdio.h>
int main()
{
int a[] = (12, 7, 13, 4, 11, 6);
printf("%d", f(a, 6));
return 0;
}
(A) -9
(B) 5
(C) 15
(D) 19
It will print
12 + ( 7 - (13 - (4 + (11 - ( 6 + 0)))))
= 12 + (7 - (13 - ( 4 + ( 11 -6)))))
= 12 + 7 - 13 + 9
= 15
-- gatecse
GATE2010_36 top
The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list.
Some part of the code is left blank.
_______________
return head;
}
as per given code p points to last node which should be head in modified.
answer D
-- Sankaranarayanan P.N
GATE2010_50,51 top
Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry W ij in the matrix W below is the weight of the edge {i, j}
Q.50 What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the tree T ?
(A) 7
(B) 8
(C) 9
(D) 10
Q.51 What is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges?
(A) 7
(B) 8
(C) 9
(D) 10
Answer for 50 is (D) 10. The edges of the spanning tree are: 0 - 1, 1 - 3, 3 - 4, 4 - 2. Total Weight = 10
GATE1994_1.7 top
It is A. searching for only one half of the list. leading to T(n/2) + constant time in comparing and finding mid element.
-- Gate Keeda
GATE1994_1.11 top
J+(sum of natural number till i-1) because if you form a lower triangular matrix it contains elements in rows 1,2,3,... so c is the correct answer
-- Bhagirathi Nayak
GATE1994_1.17 top
B. Because in binary search we need to have access to the mid of the list in constant time. and finding the mid itself in a linked list takes O(n)
time which makes no sense to Binary search which takes O(logn).
-- Gate Keeda
GATE1994_1.19 top
GATE1994_1.23 top
For complexity, we assume sufficiently large n. So, g1(n) = n2 and g2(n) = n3. Growth rate of g1 is less than that of g2. i.e., g1(n) = O(g2(n))
-- Arjun Suresh
GATE1994_6 top
answer - xn
-- ankitrokdeonsns
GATE1994_25 top
i=1
j=n
while(i != j) {
}
-- ankitrokdeonsns
GATE1995_1.5 top
It is A.
GATE1995_1.16 top
It is C.
The number of moves are however always m+n so that we can term it as theta(m+n). But the number of comparisons vary as per the input. In
the best case the comparisons are Min(m,n) and in worst case they are m+n-1.
-- Gate Keeda
GATE1995_2.9 top
C.
concat(a,head(tail(tail(acbc))))
concat(a,head(tail(cbc)))
concat(a,head(bc))
concat(a,b)
ab.
-- Gate Keeda
GATE1995_2.22 top
Binary search using linked list is not efficient as it will not give O(logn), because we will not be able to find the mid in constant time. Finding
mid in linked list takes O(n) time.
Recursive programs are not efficient because they take a lot of space, Recursive methods will often throw StackOverflowException while
processing big sets. moreover it has its own advantages too.
-- Gate Keeda
GATE1995_12 top
1st Pass: 37 52 12 11 25 92
2nd Pass: 37 12 11 25 52 92
3rd Pass: 12 11 25 37 52 92
4th Pass: 11 12 25 37 52 92
5th Pass: 11 12 25 37 52 92
-- Gate Keeda
GATE1995_22 top
2 only.
GATE1996_2.13 top
The average number of key comparisons done on a successful sequential search in a list of length n is
(a) log n
(b) n−1
2
(c) n
2
(d) n+1
2
1 2 3
= n
+ n
+ n
+. . . . + n
n
( )
n×(n+1)
= n
2
= n+1
2
-- Arjun Suresh
GATE1996_2.15 top
C.
GATE1996_16 top
-- Anu
GATE1996_18 top
k=(i+j) / 2;
initially i = 1 ,j=10;
first time k =(i+j) /2 = 11/2 =5.5 = 5 (because of integer type) =i
second time = k =(i+j) /2 =15/2 =7.5 =7 =i
third time = k =(i+j) /2 = 17/2 = 8.5 = 8 =i
GATE2008-IT_11 top
For problems X and Y, Y is NP-complete and X reduces to Y in polynomial time. Which of the following is TRUE?
We can't say X is NP hard unless until X is also a NP-complete. X can be NP-complete or below it.. that means it belongs to NP class, in that
class(in NP class) it may be NP-complete.. so X is NP for sure but may be NP-complete(but not neccessary).. so option (D)...
-- Vicky Bajoria
GATE2008-IT_12 top
1) The cost of searching an AVL tree is θ (log n) but that of a binary search tree is O(n)
2) The cost of searching an AVL tree is θ (log n) but that of a complete binary tree is θ (n log n)
3) The cost of searching a binary search tree is O (log n ) but that of an AVL tree is θ(n)
4) The cost of searching an AVL tree is θ (n log n) but that of a binary search tree is O(n)
1) is true as AVL tree is a balanced search tree that has time complexity of searching , but in binary search tree, we can have a
completely left/right skewed tree, in which search is O(n).
-- Happy Mittal
GATE2007-IT_3 top
Consider a weighted undirected graph with positive edge weights and let uv be an edge in the graph. It is known that the shortest path from the
source vertex s to u has weight 53 and the shortest path from s to v has weight 65. Which one of the following statements is always true?
D. weight(u,v) ≥ 12
If weight (u, v) < 12, then the min. weight of (s, v) = weight of (s, u) + weight of (u, v) = 53 + (<12) will be less than 65.
-- Arjun Suresh
GATE2007-IT_27 top
int f (int n) {
if (n <= 1) return 1;
else if (n % 2 == 0) return f(n/2);
else return f(3n - 1);
}
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
The function terminates for all powers of 2 (which is infinite), hence (i) is false and (ii) is TRUE.
Let n = 5.
Now, recursive calls will go like 5 - 14 - 7 - 20 - 10 - 5 -
And this goes into infinite recursion. And if we multiply 5 with any power of 2, also result will be infinite recursion. Since, there are infinite
powers of 2 possible, there are infinite recursions possible (even considering this case only). So, (iv) is TRUE and (iii) is false.
-- Arjun Suresh
GATE2006-IT_10 top
A problem in NP is NP-complete if
(B) A problem in NP becomes NPC if all NP problems can be reduced to it in polynomial time. This is same as reducing any of the NPC
problem to it. 3-SAT being an NPC problem, reducing it to a NP problem would mean that NP problem is NPC.
http://gatecse.in/wiki/NP,_NP_Complete,_NP_Hard
-- Arjun Suresh
GATE2004-IT_58 top
Consider the following C program which is supposed to compute the transpose of a given 4 x 4 matrix M. Note that, there is an X in the
program which indicates some missing statements. Choose the correct option to replace X in the program.
#include<stdio.h>
#define ROW 4
#define COL 4
int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
main()
{
int i, j, t;
for (i = 0; i < 4; ++i)
{
X
}
for (1 = 0; i < 4; ++i)
for (j = 0; j < 4; ++j)
printf ("%d", M[i][j]);
}
option C:
look at the initial value ofj, if j starts with 0, then double for loop will swap M[i][j] with M[j][i] and also M[j][i] and M[i][j] so the matrix M will
remain unchanged, so to avoid this double swapping we need to initialize j = i and swap only upper triangular matrix with lower triangular
matrix.
-- Vikrant Singh
GATE2005-IT_52 top
Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G
containing the edge e. Which of the following statements is always TRUE?
Option c is not true when e is part of a cycle and all edge weights are same in that cycle
Option a is always true as only the min weight edge in a cut set will be part of a minimum spanning tree.
-- Bhagirathi Nayak
GATE2005-IT_53 top
The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string
obtained by permuting the letters in s.
The answer is D
#include <stdio.h>
int main(void) {
return 0;
}
/*
so this loop will initialize count of all the ASCII characters to be
0 (zero)
*/
for (j = 0; j < 128; j++) count[j] = 0;
j = 0;
/*
"a[j] && b[j]" ensures that anagram returns 0 (false) in case both
strings have different length. Because different length strings cannot
be anagram of each other
*/
/*
Logic:
Below while loop increments ASCII equivalent position for its occurence
in array 'a'in count array; and decrements ASCII equivalent position
for its occurence in array 'b'in count array.
*/
while (a[j] && b[j]) {
A; //count [a[j]]++
/*
Note: j will be increment after count[]-- will execute
Resource: http://www.c4learn.com/c-programming/increment-operator-inside-printf
*/
B; //count[b[j++]]--
}
/*
This loop checks that the number of occurences of the individual ASCII
characters is same or not.
If count[i] = 0 ---> same number of occurences for ASCII chracter i
---> return 1 (true)
-- Sohil Ladhani
GATE2005-IT_57 top
#include <stdio.h>
int main () {
printf("%d", f(20, 1));
return 0;
}
A) 5
B) 8
C) 9
D) 20
6.) f(20,1) = 9.
5.) f(10,2) - 1 = 9
4.) f(5,4) - 2 = 10
3.) f(2,8) + 4 = 12
2.) f(1,16) - 8 = 8
1.) f(0,32) + 16 = 16
-- Gate Keeda
GATE2005-IT_58 top
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the
array whose difference is a specified number S > 0.
i = 0; j = 1;
while (j < n ){
if (E) j++;
else if (a[j] - a[i] == S) break;
else i++;
}
if (j < n) printf("yes") else printf ("no");
Answer is (B)
For some 'i' if we find that difference of ( A[j] - A[i] <S )we increment 'j' to make this difference wider so that it becomes equal to S .
If at times difference becomes greater than S we know that it wont reduce further for same 'i' and so we increment the .'i'
-- Sandeep_Uniyal
GATE2005-IT_59 top
Let a and b be two sorted arrays containing n integers each, in non-decreasing order. Let c be a sorted array containing 2n integers obtained by
merging the two arrays a and b. Assuming the arrays are indexed starting from 0, consider the following four statements
A) only I and II
B) only I and IV
C) only II and III
D) only III and IV
a[i] ≥ b[i]
Since both a and b are sorted in the beginning, there are i elements smaller than a[i] (i starts from 0), and similarly i elements smaller than b[i].
So, a[i] ≥ b[i] means there are 2i elements smaller than a[i], and hence in the merged array a[i] can come only after these 2i elements (its
index will be > 2i). So, c[2i] ≤ a[i] (equality only comes when array contains repeated elements)
Similarly, a[i] ≥ b[i] says for b that, there are not more than 2i elements smaller than b[i] in the sorted array (i elements from b, and maximum
another i elements from a). So, b[i] ≤ c[2i]
A sink in a directed graph is a vertex i such that there is an edge from every vertex j ≠ i to i and there is no edge from i to any other vertex. A
directed graph G with n vertices is represented by its adjacency matrix A, where A[i] [j] = 1 if there is an edge directed from vertex i to j and 0
otherwise. The following algorithm determines whether there is a sink in the graph G.
i = 0;
do {
j = i + 1;
while ((j < n) && E1) j++;
if (j < n) E2;
} while (j < n);
flag = 1;
for (j = 0; j < n; j++)
if ((j! = i) && E3) flag = 0;
if (flag) printf("Sink exists");
else printf ("Sink does not exist");
A) E1 : A[i][j] and E2 : i = j;
B) E1 : !A[i][j] and E2 : i = j + 1;
C) E1: !A[i][j] and E2 : i = j;
D) E1 : A[i][j] and E2 : i = j + 1;
If there is a sink in the graph, the adjacency matrix will contain all 1's(except diagonal) in one column and all 0's (except diagonal) in the
corresponding row of that vertex. The given algorithm is a smart way of doing this as it finds the sink in O(n) time complexity.
The first part of the code, is finding if there is any vertex which doesn't have any outgoing edge to any vertex coming after it in adjacency
matrix. The smart part of the code is E2, which makes rows skip when there is no edge from i to it, making it impossible them to form a sink.
This is done through
E1: !A[i][j]
and
E2: i = j;
E1 makes sure that there is no edge from i to j and i is a potential sink till A[i][j] becomes 1. If A[i][j] becomes 1, i can no longer be a sink,
similarly all previous j can also not be a sink (as there was no edge from i to them and a sink requires an edge from all other vertices). Now,
the next potential candidate for sink is j. So, in E2, we must make i = j.
For E3,
http://gateoverflow.in/3857/gate2005-it_84b
-- Arjun Suresh
Hashing top
A hash table of size M = 8 (0 to 7) is using open addressing for hashing the binary strings. Assume finding an empty slot directly without
collision or after collision is also a probe. Calculate the total number of probes that occur while hashing five strings using linear probing.
http://webdocs.cs.ualberta.ca/~holte/T26/open-addr.html
-- Arjun Suresh
i=0
for(i=1;i<=n;++i)
for(j=1;j<=i*i;++j)
if((j%i)==0)
for(k=1;k<=j;++k)
c=c+1;
(The third loop executes only when j%i == 0, which will be true for j = i, 2i, 3i, ... i*i. i.e., it also executes i times. )
for i = 1, 2, 3, 4, ... n
∑ni=1 ∑ij=1 j × i
= 1 + 6 + 18 + 40+. . . +n × n × n+1
2
= ∑ni=1 i × i × i+1
2
= O(n 4 )
(We can assume the sum to the cubes of first n natural numbers)
-- Arjun Suresh
What is the complexity of finding 50th smallest element in an already constructed binary
min-heap? top
GATE2015-2_2 top
Consider two decision problems Q 1 , Q 2 such that Q 1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time toQ 2 . Then
which one of the following is consistent with the above statement?
A. Q 1 is in NP, Q 2 is NP hard.
B. Q 2 is in NP, Q 1 is NP hard.
C. Both Q 1 and Q 2 are in NP.
D. Both Q 1 and Q 2 are in NP hard.
Now, any less or equally hard problem can be reduced (in polynomial time) to 3-SAT. So, Q1 reducing to 3-SAT means Q1 is less harder than
3-SAT- can be P or NP. Since P ⊆ NP. Q1 is in NP, need not be NP-Hard.
3-SAT reducing (in polynomial time) to Q2 means Q2 is harder or as hard as 3-SAT meaning Q2 is also NP-Hard. Q2, need not be in NP.
GATE2015-2_11 top
int fun(int n) {
int x=1, k;
if (n==1) return x;
for (k=1; k<n; ++k)
x = x + fun(k) * fun (n-k);
return x;
}
fun(1) = 1;
fun(5) = 1 + fun(1) * fun(4) + fun(2) * fun(3) + fun(3) * fun(2) + fun(4) * fun(1) = 1 + 15 + 10 + 10 + 15 = 51;
-- Arjun Suresh
GATE2015-1_6 top
option c is correct ..
-- Anoop Sonkar
GATE2015-2_22 top
An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum
is
A. Θ(n log n)
B. Θ(n)
C. Θ(log n)
D. Θ(1)
Ans O(1), because all elements are distinct, select any three numbers and output 2nd largest from them.
-- Vikrant Singh
GATE2015-2_36 top
Given below are some algorithms, and some algorithm design paradigms.
Match the above algorithms on the left to the corresponding design paradigm they follow.
Answer: C
-- Jon Snow
GATE2015-1_31 top
Which one of the following most closely approximates the return value of the function fun1?
A. n3
B. n(log n)2
C. n log n
D. n log(log n)
i loop is executing n times. j loop is executing log n times for each i, and so value of p is log n. k loop is executing log p times, which is log log
n times for each iteration of i. In each of these q is incremented. So, over all iterations of i, q will be incremented n log log n times. So, D
choice.
-- Arjun Suresh
GATE2015-1_45 top
Let G = (V, E) be a simple undirected graph, and s be a particular vertex in it called the source. For x∈V, let d(x) denote the shortest distance in
G from s to x. A breadth first search (BFS) is performed starting at s. Let T be the resultant BFS tree. If (u, v) is an edge of G that is not in T,
then which one of the following CANNOT be the value of d(u) - d(v)?
A. -1
B. 0
C. 1
D. 2
2 is the answer.
d(u) - d(v) = 0 is possible when both u and v have an edge from t and t is in the shortest path from s to u or v.
d(u) - d(v) = 1 is possible when u is in the shortest path from s to v, and t is also in the shortest path from s to v and both t and s are siblings-
same distance from s to both t and u causing t-v edge to be in BFS tree and not u-v.
d(u) - d(v) = 2 is not possible. This is because on BFS traversal we either visit u first or v. Let's take u first. Now, we put all neighbors of u on
queue. Since v is a neighbour and v is not visited before as assumed, d(v) will become d(u) + 1. Similarly, for v being visited first.
-- Arjun Suresh
GATE2015-1_49 top
Let an represent the number of bit strings of length n containing two consecutive 1s. What is the recurrence relation foran ?
Counting the number of bit strings NOT containing two consecutive 1's. (It is easy to derive a recurrence relation for the NOT case as shown
below.)
01
00 01 10 - 3 (append both 0 and 1 to any string ending in 0, and append 0 to any string ending in 1)
000 001 010 100 101 - 5 (all strings ending in 0 give two strings and those ending in 1 give 1 string)
0000 0001 0010 0100 0101 1000 1001 1010 - 8
....
an' = an-1' + an-2' (where an denote the number of bit strings of length n containing two consecutive 1s)
A choice.
-- Arjun Suresh
GATE2015-3_4 top
I. Θ(n 4 )
II. Θ(n 5 )
III. O(n 5 )
IV. Ω(n 3 )
A. Only I
B. Only II
C. I or III or IV but not II
D. II or III or IV but not I
Sum of the cubes of the first n natural numbers is given by (n(n+1)/2 2) which is ϴ(n4). So, I, III and IV are correct. II is wrong. C choice.
-- Arjun Suresh
GATE2015-3_27 top
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely
approximates the maximum input size of a problem that can be solved in 6 minutes?
A. 256
B. 512
C. 1024
D. 2018
The worst case time complexity of Mergesort is k × n log n for an input of size n .
k × 64 log2 64 = 30s
⟹ k × 384 = 30s
⟹ k = 0.078125s
Let the size of the problem that can be solved in 6 minutes be x. Then,
k × x log2 x = 360s
360s
x log2 x =
0.078125s
⟹ x = 512
-- Pragy Agarwal
GATE2015-3_30 top
Consider the following two C code segments. Y and X are one and two dimensional arrays of sizen and n × n respectively, where
2 ≤ n ≤ 10 . Assume that in both code segments, elements ofY are initialized to 0 and each element X[i][j] of array X is initialized to i + j.
Further assume that when stored in main memory all elements of X are in same main memory page frame.
Code segment 1:
// initialize elements of Y to 0
// initialize elements of X[i][j] of X to i+j
for (i=0; i<n; i++)
Y[i] += X[0][i];
Code segment 2:
// initialize elements of Y to 0
// initialize elements of X[i][j] of X to i+j
for (i=0; i<n; i++)
Y[i] += X[i][0];
S2: Elements of array X accessed inside the for loop shown in code segment 1 are contiguous in main memory
S3: Elements of array X accessed inside the for loop shown in code segment 2 are contiguous in main memory
A. Only S2 is correct
B. Only S3 is correct
C. Only S1 and S2 are correct
D. Only S1 and S3 are correct
option C. Only S1 and S2 are correct because Y have same element in both code and in code1
Y[i] += X[0][i];
this row major order (In C, arrays are stored in row-major order) which gives address of each element in sequential order(1,2,3,....,n) means
we cross single element each time to move next shows contiguous in main memory but in code2 for
Y[i] += X[i][0];
we are crossing n element (row crossing with n element )to move next
-- Anoop Sonkar
GATE2015-3_39 top
void get(int n)
{
if (n<1) return;
get (n-1);
get (n-3);
printf("%d", n);
}
If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?
A. 15
B. 25
C. 35
D. 45
T(n<=0) = 0
T(1) = 2
T(2) = 4
T(3) = 6
T(4) = 10
T(5) = 16
T(6) = 24
So, answer is 24 + 1 call from main = 25.
-- Arjun Suresh
GATE2015-3_40 top
Let G be a connected undirected graph of 100 vertices and 300 edges. The weight of a minimum spanning tree ofG is 500. When the weight of
each edge of G is increased by five, the weight of a minimum spanning tree becomes ______.
GATE2015-3_42 top
Let f(n) = n and g(n) = n (1+sin n) where n is a positive integer. Which of the following statements is/are correct?
I. f(n) = O(g(n))
II. f(n) = Ω(g(n))
A. Only I
B. Only II
C. Both I and II
D. Neither I nor II
Since the value of sin(n) will always range from -1 to +1, hence g(n) can take values 1, n, n^2.
-- saurabhrk
GATE2015-3_49 top
Suppose c = ⟨c[0], … , c[k − 1]⟩ is an array of length k, where all the entries are from the set {0, 1}. For any positive integersa and n, consider
the following pseudocode.
DOSOMETHING (c, a, n)
z←1
for i ← 0 to k − 1
do z ← z 2 mod n
if c[i]=1
then z ← (z × a) mod n
return z
in the do loop
in the do loop
z = 2*2 % 8 = 4 (since now z = 2) (non zero value so considered as true and continue)
reason all the operations that update Z are multiplicative operations and hence the value of Z will never change from 0.
-- Tamojit Chatterjee
minimum number of comparison required to compute the largest and second largest
element in an array is top
a) n- ( lg(n)) - 2
b) n + (lg(n)-2)
we can start comparing the elements pair wise and build a decision tree in which case it takes n-1 comparisons to obtain the highest element.
In order to get the second highest element we need to check only those elements which were compared with the highest element while building the decision tree, now as the height of the
tree is logn as logn comparisons are required for the highest element to reach the top, so to obtain second highest element one need logn-1 comparisons so all together n-1+logn-1=n+logn-2
comparisons are required.
common data Linked quetion :- 1) which of the following is correct recurrence formula of
I(j) 2)how to evaluate this R.R top
At the end of it's 5th Successful season,The siruseri Permier league is planning to give an award to most improved bowler over 5 years . For
this an important Index will be computed for each bowler,This is defined as the longest Subsequence of strictly decreasing economy rate's by
the bowler among all his matches over 5 season's.For example seasons are (10.0,5.0,8.9,6.7,4.2,5.5,2.2,3.4,6.0,2.3,2.0) so his improvement
index is 7 based on sequence (10.0 ,8.9, 6.7, 5.5, 3.4, 2.3, 2.0)
Now let E[1...........N] Donates a sequence of n economy rates for which improvement index is to be calculated
for 1 ≤ j ≤ n,Let I[j] denotes the improved index for the prefix of score E[1.......j ] ending atE[j]
b) I(1)=1
for j ∈2,3,......,n I(j) = 1+E(j-1) if E(j-1)<E(j)
1 otherwise
C) I(1)=1
for j ∈2,3,......,n I(j) = 1+ max {I(k)/ 1≤ K<j, E[k] < E[j]}
d)I(1)=1
for j ∈2,3,......,n I(j) = 1+E(j-1) if E(j-1) > E(j)
1 otherwise
2. How to evaluate this Recursive definition Using Dynamic programming?
a) A 2-D table T of Size N X N to be filled row wise from T[1][1] to T[n][n]
c) O(n2 )
d) O(n3 )
The current considered element must be smaller than ALL previous entries. So, b, c, and d are false.
3. O(n)
-- Arjun Suresh
A(n)
if(n>=1)
A(n-1); // statement 1
print n; //statement 2
A(n-1);// statement 3
Size of stack is of the order of the number of recursive calls which are currently live. (It is not equal because we save many info on the stack
during a call like local variables, return address etc. )
Here, we have two recursive calls with value (n-1) for input n. But before the second one starts, the first one finishes. So, total number of
recursive calls for n can be given by
Solve recurrence T(n) = 2T(n-1) + 1 (1 for the stack space required for the current process) with T(0) = 1.
arrange the following in the increasing order of their asymptotic complexity in big theta notation
-- Arjun Suresh
Time complexity of a while loop top
Assuming n>2
A()
while(n>1)
n = n/2;
Since we have a sqrt term, considering only perfect squares and those which are multiple of 2 as that can take care of log.
T (2) = 1//assume
T (2 2 ) = T (2) + 1 = 2
T (2 2 ) = T (4) + 1 = 3
2
T (2 2 ) = T (16) + 1 = 4
3
T (2 2 ) = T (256) + 1 = 5
4
Pankaj and Mythili were both asked to write the code to evaluate the following expression
top
Pankaj and Mythili were both asked to write the code to evaluate the following expression:
a − b + c/(a − b) + (a − b)2
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or division between two operands is same, which of the following is
true?
In code A, three variables are used a, b and c to store values. The computation of a-b is repetitive and is performed 4 times in print statement
requires more time compared to the computation of print statement of code B, because of the use of additional variable d, to store the
computed value of a-b. The print statement of code B replaces d with the already computed value of a-b.
-- Keith Kr
GATE2008_50 top
Answer is C:
Statement 1 is true: Using GNF we can convert Left recursive grammar to right recursive and by using reversal of CFG and GNF we can
convert right recursive to left recursive.
Statement 2 is false: because if ∊ is in the language then we can't remove ∊ production from Start symbol. (For example L = a*)
Statement 4 is true, only two non-terminals are there in each production in CNF. So it always form a binary tree.
-- Vikrant Singh
GATE2008_12 top
Some code optimizations are carried out on the intermediate code because
C. The information from dataflow analysis cannot otherwise be used for optimization
D. The information from the front end cannot otherwise be used for optimization
Ans is (A)
Intermediate codes are machine independent codes. So, intermediate code can be used for code optimization since a given source code can
be converted to target machine code.
-- Keith Kr
GATE2000_1.18 top
is
a. 3
b. 26
c. 10
d. 21
answer - C
Tokens are:
1. printf
2. (
3. "i=%d, &i=%x"
4. ,
5. i
6. ,
7. &
8. i
9. )
10. ;
-- ankitrokdeonsns
GATE2001_1.17 top
The process of assigning load addresses to the various parts of the program and adjusting the code and the date in the program to reflect the
assigned addresses is called
(A) Assembly
(B) parsing
(C) Relocation
GATE2004_9 top
Consider a program P that consists of two source modules M 1 and M 2 contained in two different files. If M 1 contains a reference to a function
defined in M 2 the reference will be resolved at
A. Edit time
B. Compile time
C. Link time
D. Load time
answer - C. Each module is compiled separately and then linked together to make the executable. The below commands shows how to do
this for two modules c1.c and c2.c using gcc.
-- ankitrokdeonsns
GATE2013_9 top
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production
(i.e., of type A → ϵ and A → a) to parse a string with n tokens?
(A) n/2
(B) n − 1
(C) 2n − 1
(D) 2 n
Ans will be B
A->BC
B->aa
C->bb
then
A->BC(reduction 3)
->aaC(reduction 2)
->aabb (reduction 1)
n=4
GATE1998_1.27 top
Type checking is normally done during
The answer is C .
The use of syntax analyser is used to create parse Tree. But along with Grammar as input to Syntax Analyser we add even semantic rules
which form the basis of Syntax Directed Translation That help us in Evaluation of Expression .Remember that
4.Type Checking
GATE1998_1.28 top
answer - B
first module loaded starting at address 0. Size is 200. hence it will occup first 200 address last address being 199. Second module will be
present from 200 and so on.
-- ankitrokdeonsns
GATE2014-1_34 top
S → L. > R
Q → R.
GATE2006_59 top
S → ER
R →∗ E{print(′ ∗ ′ ); }R ∣ ε
E → F + E{print(′ + ′ ); } ∣ F
F → S ∣ id{print(id. value); }
Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4', this translation
scheme prints
(A) 2 * 3 + 4
(B) 2 * +3 4
(C) 2 3 * 4 +
(D) 2 3 4+*
GATE2006_60 top
4*j
i%2
x += 5*i
can be replaced by
x += p;
p +=5; (p must be initialized to 0 before the loop).
Thus replacing * with + and giving strength reduction.
-- Arjun Suresh
GATE2014-2_18 top
Dynamic means- at runtime. Dynamic memory allocation happens during the execution time and hence (A) is the answer.
-- Arjun Suresh
GATE2014-2_34 top
For a C program accessing X[i] [j] [k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of
a character is 8 bits.
t0 = i ∗ 1024
t1 = j ∗ 32
t2 = k ∗ 4
t3 = t1 + t0
t4 = t3 + t2
t5 = X[t4]
Which one of the following statements about the source code for the C program is CORRECT?
So, (A) is correct. The first dimension is not needed for code generation and that is why in C language while passing an array to a function,
we can omit the value of the first dimension but not any others.
-- Arjun Suresh
GATE2014-3_11 top
The minimum number of arithmetic operations required to evaluate the polynomial P (X) = X 5 + 4X 3 + 6X + 5 for a given value of X , using only one
temporary variable is ______.
In the above 8 steps of evaluation, the total number of arithmetic operations required are 7 [4
Multiplications, 3 Additions]
So answer is 7 arithmetic operations.
-- Gate Keeda
GATE2014-3_17 top
(C) increase the chances of reusing the machine-independent code optimizer in other compilers.
C.
GATE2014-3_18 top
1. Static allocation of all data areas by a compiler makes it impossible to implement recursion.
2. Automatic garbage collection is essential to implement recursion.
3. Dynamic allocation of activation records is essential to implement recursion.
4. Both heap and stack are essential to implement recursion.
It will be D.
option 2 is wrong because it is not necessary to have automatic garbage collection to implement recursion.
option 4 is wrong because it says that both are required to implement recursion, which is wrong. Either of them will suffice.
-- Gate Keeda
GATE2011_27 top
Consider two binary operators ‘↑ ′ and ‘↓ ′ with the precedence of operator ↓ being lower than that of the operator ↑ . Operator ↑ is right
associative while operator ↓ is left associative. Which one of the following represents the parse tree for expression(7 ↓ 3 ↑ 4 ↑ 3 ↓ 2)
(A)
(B)
(C)
(D)
Answer is B.
-- Praneeth A S
GATE2010_13 top
Which data structure in a compiler is used for managing information about variables and their attributes?
GATE1997_1.6 top
X ::= X ⊕ Y ∣ Y
Y ::= Z ∗ Y ∣ Z
Z ::= id
It will be A. For multiple '⊕ ', the derivation is possible only via X
' ' which is on left side of ⊕
' ' in the production. Hence it is left associative.
If both left and right derivations were possible, the grammar would have been ambiguous and we couldn't have given associativity.
-- Gate Keeda
GATE1997_1.7 top
Which of the following is essential for converting an infix expression to the postfix form efficiently?
a. An operator stack
b. An operand stack
c. An operand stack and an operator stack
d. A parse tree
A.
we use operator stack (only operators are pushed as +, *, (, ), / ) for converting infix to postfix. And we use operand stack( operands such as
5,4,17 etc) for postfix evaluation.
-- Gate Keeda
GATE1997_1.8 top
A language L allows declaration of arrays whose sizes are not known during compilation. It is required to make efficient use of memory. Which
one of the following is true?
C.
GATE1993_7.7 top
A part of the system software which under all circumstances must reside in the main memory is:
a. text editor
b. assembler
c. linker
d. loader
e. none of the above
Answer: D
The loader is a program that loads the object program from the secondary memory into the main memory for execution of the program. The
loader resides in main memory.
-- Jon Snow
GATE1994_20 top
A grammar G is in Chomsky-Normal Form (CNF) if all its productions are of the formA → BC or A → a, where A, B and C , are non-terminals
and a is a terminal. Suppose G is a CFG in CNF and w is a string in L(G) of length n , then how long is a derivation ofw in G ?
its answer is 2n-1 for n length string, because in CNF at every step only 1 terminal can replace a variable, for example
S-AB
A-a
B-c
GATE1995_1.10 top
S∝ ->
This violates the conditions of context-free and hence the grammar becomes context-sensitive.
-- Arjun Suresh
GATE1995_1.14 top
(c) is the answer. For linker to link external symbols (for example in C, to link an extern variable in one module to a global variable in another
module), it must know the location of all external symbols. In C external symbols includes all global variables and function names.
(a) is trivially there is an object module. (b) must be there if we need to have relocation capability.
GATE1995_2.10 top
A.
Making a tree and performing post order traversal will yield answer as A.
S-->x x W (Pf'1')
W-->S z (Pf'3')
S-->x x W (Pf'1')
W-->S z (Pf'3')
S-->y (Pf'2').
-- Gate Keeda
GATE1996_2.10 top
-> id := id
is ambiguous because
(b) the left most and right most derivations of the sentence
GATE1996_11 top
final grammar is
A------> aA / a
B-------> bB / b
C-------> d
correct me ....
-- csegate2
GATE2008-IT_78 top
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.
S → aS ∣ A
A → aAb ∣ bAa ∣ ϵ
Which of the following strings is generated by the grammar above?
1) aabbaba
2) aabaaba
3) abababb
4) aabbaab
S→ aS
S→ aA
S→ aaAb
S→ aabAab
S→ aabbAaab
S→ aabbaab
hence d is d answer
-- Shreyans Dhankhar
GATE2008-IT_79 top
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.
S → aS ∣ A
A → aAb ∣ bAa ∣ ϵ
For the correct answer in above Question http://gateoverflow.in/3392/gate2008-it_78, how many steps are required to derive the string and how
many parse trees are there?
A) 6 and 1
B) 6 and 2
C) 7 and 2
D) 4 and 2
S→ aS 1
S→ aA 2
S→ aaAb 3
S→ aabAab 4
S→ aabbAaab 5
S→ aabbaab 6
Thus 6 steps are needed and only one way to derive the string so only one parse tree.
-- Shreyans Dhankhar
GATE2007-IT_9 top
Consider an ambiguous grammar G and its disambiguated version D. Let the language recognized by the two grammars be denoted by L(G)
and L(D) respectively. Which one of the following is true ?
A) L (D) ⊂ L (G)
B) L (D) ⊃ L (G)
C) L (D) = L (G)
D) L (D) is empty
GATE2005-IT_83a top
Consider the context-free grammar
E→E+E
E → (E * E)
E → id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.
Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?
A) id + id + id + id
B) id + (id* (id * id))
C) (id* (id * id)) + id
D) ((id * id + id) * id)
Answer is A.
-- Gate Keeda
GATE2005-IT_83b top
E→E+E
E → (E * E)
E → id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of non-terminals is {E}.
For the terminal string id + id + id + id, how many parse trees are possible?
A) 5
B) 4
C) 3
D) 2
GATE2005_61 top
Identify the compiler’s response about this line while creating the object-module:
A. No compilation error
C language allows only certain words in it- these are called tokens. If we input any invalid tokens it causes lexical error.
eg:
44a44
causes lexical error as in C as an alphabet cannot come in between digits.
Syntactic error is caused by bad combination of tokens. For example, we cannot have a constant on the left hand side of an assignment
statement, a for loop must have two expressions inside () separated by semi colon etc.
In the given question, line 3 won't cause lexical error or syntactic error. The statement will be treated as a function call with three arguments.
Function definition being absent will cause link time error, but the question asks only for compile time errors. So, (a) must be the answer.
http://stackoverflow.com/questions/15570553/lexical-and-semantic-errors-in-c
-- Arjun Suresh
GATE2004_10 top
Consider the grammar rule E → E1 – E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The
subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub expression, in order to get the
shortest possible code
After evaluating E2 first and then E1, we will have E1 in the register and thus we can simply do SUB operation with E2 which will be in
memory (as we have only a single register). If we do E1 first and then E2, we must move E2 to memory and E1 back to register before doing
SUB, which will increase the code size.
-- Arjun Suresh
GATE2015-1_8 top
For computer based on three-address instruction formats, each address field can be used to specify which of the following:
A. Either S1 or S2
B. Either S2 or S3
C. Only S2 and S3
D. All of S1, S2 and S3
-- Anoop Sonkar
GATE2015-2_19 top
Answer: C
-- Jon Snow
GATE2015-1_13 top
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
B. Viable prefixes appear only at the top of the stack and not inside
C. The stack contains only a set of viable prefixes
D. The stack never contains viable prefixes
GATE2015-1_55 top
The least number of temporary variables required to create a three-address code in static single assignment form for the expression q + r / 3 +
s - t * 5 + u * v/w is__________________.
Answer should be 8. We will need a temporary variable for storing the result of each binary operation and SSA (static single assignment)
implies the variable cannot be repeated.
q + r / 3 + s - t * 5 + u * v/w
t1 = r/3;
t2 = t*5;
t3 = u*v;
t4 = t3/w;
t5 = q + t1;
t6 = t5 + s;
t7 = t5 - t2;
t8 = t7 + t4
http://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/240%20TAC%20Examples.pdf
-- Arjun Suresh
GATE2015-3_16 top
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to
implement and the method that is the most powerful, in that order?
A. SLR, LALR
B. Canonical LR, LALR
C. SLR, canonical LR
D. LALR, canonical LR
Answer is C.
http://en.wikipedia.org/wiki/LALR_parser_generator
-- Arjun Suresh
GATE2015-3_31 top
S→F|H
F→p|c
H→d|c
Where S, F, and H are non-terminal symbols, p, d, and c are terminal symbols. Which of the following statement(s) is/are correct?
S1: LL(1) can parse all strings that are generated using grammarG
S2: LR(1) can parse all strings that are generated using grammarG
A. Only S1
B. Only S2
C. Both S1 and S2
D. Neither S1 and S2
A parser works on the basis of given grammar. It takes the grammar as it is. Parser does not work on the basis of the yield of the
grammar. Also, while constructing the LL(1) parser table, that entry for terminal 'c' will contain multiple entries. SO LL(1) parser
cannot be constructed for the given grammar.
S→F|H
F→p|c
H→d|c
That {p, d, c} are the strings generated by the grammar is absolutely correct. But LL(1) and LR(1) can parse these strings
successfully only if the grammar is unambiguous and like given below...
S→P|D|C
P→p
D→d
C→c
Please note the difference between these two grammars. Both derive the same strings, but in different manner. With the
grammar given in the question, both top-down and bottom-up parsers will get confused while deriving "c". Top-down parser
will get confused between F → c and H → c. Similarly, bottom-up parser will get confused while reducing "c". This confusion
in case of bottom-up parsing is technically termed as "reduce-reduce" conflict.
While top-down parsing, follow(F) and follow(H) are not disjoint, so the grammar cannot be LL(1). Therefore, LL(1) parser
cannot parse it.
Hence, the answer should be option (D). Neither S1 nor S2.
-- ashishacm
CO & Architecture top
GATE2004_47 top
Consider a system with a two-level paging scheme in which a regular memory access takes 150 nanoseconds, and servicing a page fault takes
8 milliseconds. An average instruction takes 100 nanoseconds 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?
GATE2013_45 top
Consider an instruction pipeline with five stages without any branch prediction: Fetch Instruction (FI), Decode Instruction (DI), Fetch Operand
(FO), Execute Instruction (EI) and Write Operand (WO). The stage delays for FI, DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns,
respectively. There are intermediate storage buffers after each stage and the delay of each buffer is 1 ns. A program consisting of 12
instructions I1, I2, I3, …, I12 is executed in this pipelined processor. Instruction I4 is the only branch instruction and its branch target is I9. If the
branch is taken during the execution of this program, the time (in ns) needed to complete the program is
clk1 clk2 cl3 clk4 clk5 clk6 clk7 clk8 clk9 clk10 clk11 clk12
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
9 9 9 9 9
10 10 10 10 10
11 11 11 11 11
12 12 12 12 12
15 ∗ 11 = 165ns.
Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
I1 FI DI FO EI WO
I2 FI DI FO EI WO
I3 FI DI FO EI WO
I4 FI DI FO EI WO
stall
stall
stall
I9 FI DI FO EI WO
I10 FI DI FO EI WO
I11 FI DI FO EI WO
I12 FI DI FO EI WO
-- gatecse
GATE2008_33 top
II. If it is included in an Instruction Set Architecture, then an additional ALU is required for effective address calculation
III. The amount of increment depends on the size of the data item accessed
A. I only
B. II only
C. III only
D. II and III only
In auto increment addressing mode, the base address is incremented after operand fetch. This is useful in fetching elements from an array.
But his has no effect in self-relocating code (where code can be loaded to any address) as this works on the basis of an initial base address.
An additional ALU is desirable for better execution especially with pipelining, but never a necessity.
Amount of increment depends on the size of the data item accessed as there is no need to fetch a part of a data.
-- Arjun Suresh
GATE2008_36 top
A. I and II only
B. I and III only
C. II and III only
D. I, II and III
(B) I and III
I - False Bypassing can't handle all RAW hazard, consider when any instruction depends on the result of LOAD instruction, now LOAD
updates register value at Memory Access Stage (MA), so data will not be available directly on Execute stage.
III- False, It cannot completely eliminate, though it can reduce Control Hazard Penalties
-- Prateeksha Keshari
GATE2008_38 top
In an instruction execution pipeline, the earliest that the data TLB (Translation Lookaside Buffer) can be accessed is
C as only after the calculation of Virtual address you can look up in the TLB
-- Shaun Patel
GATE2008_71,72,73 top
Consider a machine with a 2-way set associative data cache of size 64 Kbytes and block size 16 bytes. The cache is managed using 32 bit
virtual addresses and the page size is 4 Kbytes. A program to be run on this machine begins as follows:
double ARR[1024][1024];
int i, j;
/*Initialize array ARR to 0.0 */
for(i = 0; i < 1024; i++)
for(j = 0; j < 1024; j++)
ARR[i][j] = 0.0;
The size of double is 8 bytes. Array ARR is located in memory starting at the beginning of virtual page 0xFF000 and stored in row major order.
The cache is initially empty and no pre-fetching is done. The only data memory references made by the program are those to array ARR.
72) Which of the following array elements have the same cache index as ARR[0][0]?
Number of WORD bits required = 4 as a cache block consists of 16 bytes and we need 4 bits to address each of them.
So, number of tag bits = 32 - 11 - 4 = 17
= 68 KB
We use the top 17 bits for tag and the next 11 bits for indexing and next 4 for offset. So, for two addresses to have the same cache index,
their 11 address bits after the 4 offset bits from right must be same.
ARR[0][0] is located at virtual address 0x FF000 000. (FF000 is page address and 000 is page offset). So, index bits are 00000000000
Address of ARR[0][4] = 0xFF000 + 4 * sizeof (double) = 0xFF000 000 + 4*8 = 0xFF000 020 (32 = 20 in hex) (index bits differ)
Address of ARR[4][0] = 0xFF000 + 4 * 1024 * sizeof (double) [since we use row major storage] = 0xFF000 000 + 4096*8 = 0xFF000 000 +
0x8000 = 0xFF008 000 ( index bits matches that of ARR [0][0] as both read 000 0000 0000)
Address of ARR[0][5] = 0xFF000 + 5 * sizeof (double) = 0xFF000 000+ 5*8 = 0xFF000 028 (40 = 28 in hex) (index bits differ)
Address of ARR[5][0] = 0xFF000 + 5 * 1024 * sizeof (double) [since we use row major storage] = 0xFF000 000 + 5120*8 = 0xFF000 000 +
0xA000 = 0xFF00A 000 (index bits differ)
So, only ARR[4][0] and ARR[0][0] have the same cache index.
The inner loop is iterating from 0 to 1023, so consecutive memory locations are accessed in sequence. Since cache block size is only 16
bytes and our element being double is of size 8 bytes, during a memory access only the next element gets filled in the cache. i.e.; every
alternative memory access is a cache miss giving a hit ratio of 50%. (If loops i and j are reversed, all accesses will be misses and hit ratio will
become 0).
-- Arjun Suresh
GATE2008_76,77 top
76. For all delayed conditional branch instructions, irrespective of whether the condition evaluates to true or false,
77. The following code is to run on a pipelined processor with one branch delay slot:
I1: ADD R2 ← R7 + R8
I3: ADD R1 ← R2 + R3
BRANCH to Label if R1 == 0
Which of the instructions I1, I2, I3 or I4 can legitimately occupy the delay slot without any program modification?
A. I1
B. I2
C. I3
D. I4
76. Answer is A. In order to avoid the pipeline delay due to conditional branch instruction, a suitable instruction is placed below the conditional
branch instruction such that the instruction will be executed irrespective of whether branch is taken or not and won't affect the program
behaviour.
77. Answer is D) I4. The STORE instruction can be moved below the conditional branch instruction. Whether the branch is taken or not,
STORE will be executed as the next instruction after conditional branch instruction, due to delayed branching.
Here, I3 is not the answer because the branch conditional variable R1 is dependent on it. Same for I1. Similarly, I4 has a dependency on I2
and hence I2 must be executed before I4.
-- Arjun Suresh
GATE1991_03,iii top
03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(iii) The total size of address space in a virtual memory system is limited by
Virtual memory concept is independent of size of main memory and depends only on the availability of the secondary storage.
MAR holds the address generated by CPU and this obviously limits the total virtual memory address space.
-- Kalpna Bhargav
GATE1992_05,a,b top
Average memory access time = Time spend for read + Time spend for write
= Read time when cache hit + Read time when cache miss
+Write time when cache hit + Write time when cache miss
= 36 + 44 + 99 + 11 = 190 ns
http://www.howardhuang.us/teaching/cs232/24-Cache-writes-and-examples.pdf
-- Arjun Suresh
GATE2000_1.8 top
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 and T2 plus the time taken for one instruction fetch cycle
Here we are comparing the execution time of only a single instruction. Pipelining in no way increases the execution time of a single instruction
(the time from its start to end). It increases the overall performance by splitting the execution to multiple pipeline stages so that the following
instructions can use the finished stages of the previous instructions. But in doing so pipelining causes some problems also as given in the
below link, which might slow some instructions. So, (B) is the answer.
http://www.cs.wvu.edu/~jdm/classes/cs455/notes/tech/instrpipe.html
-- Arjun Suresh
GATE2000_12 top
An instruction pipeline has five stages where each stage take 2 nanoseconds and all instruction use all five stages. Branch instructions are not
overlapped. i.e., the instruction after the branch is not fetched till the branch instruction is completed. Under ideal conditions,
a. Calculate the average instruction execution time assuming that 20% of all instructions executed are branch instruction. Ignore the fact
that some branch instructions may be conditional.
b. If a branch instruction is a conditional branch instruction, the branch need not be taken. If the branch is not taken,
the following instructions can be overlapped. When 80% of all branch instructions are conditional branch instructions, and 50% of the
conditional branch instructions are such that the branch is taken, calculate the average instruction execution time.
Each stage is 2ns. So, after 5 time units each of 2ns, the first instruction finishes (i.e., after 10ns), in every 2ns after that a new instruction gets
finished. This is assuming no branch instructions. Now, once the pipeline is full, we can assume that the initial fill time doesn't matter our
calculations and average execution time for each instruction is 2ns assuming no branch instructions.
(a) Now, we are given that 20% of instructions are branch (like JMP) and when a branch instruction is executed, no further instruction enters
the pipeline. So, we can assume every 5th instruction is a branch instruction. So, with this assumption, total time to finish 5 instruction will be 5
* 2 + 8 = 18 ns (as when a branch instruction enters the pipeline and before it finishes, 4 pipeline stages will be empty totaling 4 * 2 = 8 ns).
And this is the same for every set of 5 instructions, and hence the average instruction execution time = 18/5 = 3.6 ns
(b) This is just a complex statement. But what we need is to identify the % of branch instructions which cause a branch to be taken as others
will have no effect on the pipeline flow.
20% of branch instructions are branch instructions. 80% of branch instructions are conditional.
That means .2*.8 = 16% of instructions are conditional branch instructions and it is given that 50% of those result in a branch being taken.
So, 8% of instructions are conditional branches being taken and we also have 20% of 20% = 4% of unconditional branch instructions which
are always taken.
So, percentage of instructions where a branch is taken is 8+4 = 12% instead of 20% in (a) part.
So, in 100 instructions there will be 12 branch instructions. We can do a different calculation here as compared to (a) as 12 is not a divisor of
100. Each branch instruction causes a pipeline delay of 4*2 = 8 ns. So, 12 instructions will cause a delay of 12 * 8 = 96 ns. For 100
instructions, we need 100 * 2 = 200 ns without any delay and with delay we require 200 + 96 = 296 ns for 100 instructions.
(We can also use this method for part (a) which will give 100 * 2 + 20*8 = 360 ns for 100 instructions)
-- Arjun Suresh
GATE2001_2.9 top
Which is the most appropriate match for the items in the first column with the items in the second column
While passing array as parameter we can make use of a pointer (as in C) and hence can use Indirect addressing
Base Register addressing can be used to write relocatable code by changing the content of Base Register.
-- Arjun Suresh
GATE2001_9 top
A CPU has 32-bit memory address and a 256 KB cache memory. The cache is organized as a 4-way set associative cache with cache block
size of 16 bytes.
= 256KB/(4*16 B)
= 4096
What is the size (in bits) of the tag field per cache block?
Number of bits required to identify a paticular location in cache line = 4 (cache block size = 16)
What is the number and size of comparators required for tag matching?
We use 4-way set associate cache. So, we need 4 comparators each of size 16 bits
http://ecee.colorado.edu/~ecen2120/Manual/caches/cache.html
How many address bits are required to find the byte offset within a cache block?
Cache block size is 16 byte. so 4 bits are required to find the byte offset within a cache block.
What is the total amount of extra memory (in bytes) required for the tag bits?
Set associativity = 4
Extramemory required to store the tag bits = 16 * 4096 * 4 bits = 215 bytes
-- suraj
GATE2004-IT_50 top
In an enhancement of a design of a CPU, the speed of a floating point until has been increased by 20% and the speed of a fixed point unit has been increased by
10%. What is the overall speedup achieved if the ratio of the number of floating point operations to the number of fixed point operations is 2:3 and the floating point
operation used to take twice the time taken by the fixed point operation in the original design?
-- gatecse
GATE2002_1.24 top
(b) is the answer. Absolute addressing mode means address of operand is given in the instruction.
GATE2002_2.7 top
Horizontal microprogramming
Ref: http://www.cs.virginia.edu/~cs333/notes/microprogramming.pdf
-- Suvojit Mondal
GATE2002_10 top
In a C program, an array is declared as float A[2048]. Each array element is 4 Bytes in size, and the starting address of the array is
0x00000000. This program is run on a computer that has a direct mapped data cache of size 8 Kbytes, with block (line) size of 16 Bytes.
a. Which elements of the array conflict with element A[0] in the data cache? Justify your answer briefly.
b. If the program accesses the elements of this array one by one in reverse order i.e., starting with the last element and ending with the first
element, how many data cache misses would occur? Justify your answer briefly. Assume that the data cache is initially empty and that
no other data or instruction accesses are to be considered.
(a)
Since each array element occupies 4B, four consecutive array elements occupy a block line (elements are aligned as starting address is 0)
Number of cache blocks = 8KB/16B = 512. Number of cache blocks needed for the array = 2048/4 = 512. So, all the array elements has its
own cache block and there is no collision.
We can also explain this with respect to array address. Starting address is 0x00000000 = 0b0000..0 (32 0's). Ending address is 0x00001000
= 0b0000..01000000000000.
Here, the last 4 bits are used as OFFSET bits and the next 9 bits are used as SET bits. So, since the ending address is not extending beyond
these 9 bits, all cache accesses are to diff sets.
(b) If the last element is accessed first, its cache block is fetched. (which should contain the previous 3 elements of the array also since each
cache block hold 4 elements of array and 2048 is and exact multiple of 4). Thus, for every 4 accesses, we will have a cache miss => for 2048
accesses we will have 512 cache misses. (This would be same even if we access array in forward order).
-- Arjun Suresh
GATE2004_39 top
Two matrices M 1 and M 2 are to be stored in arraysA and B respectively. Each array can be stored either in row-major or column-major order
in contiguous memory locations. The time complexity of an algorithm to compute M 1 × M 2 will be
D is correct
Here time complexity is asked, for each access of array element it will be constant,
So the time complexity will not depend upon storage. If at all program execution time is asked
a is true
-- Anurag_s
GATE2004_63,64 top
Consider the following program segment for a hypothetical CPU having three user registers R1, R2 and R3.
63. Consider that the memory is byte addressable with size 32 bits, and the program has been loaded starting from memory location 1000
(decimal). If an interrupt occurs while the CPU has been halted after executing the HALT instruction, the return address (in decimal) saved in
the stack will be
A. 1007
B. 1020
C. 1024
D. 1028
64. Let the clock cycles required for various operations be as follows:
A. 29
B. 24
C. 23
D. 20
63. Word size is 32 bits (4 bytes). Interrupt occurs after execution of HALT instruction NOTduring, So address of next instruction will be
saved on to the stack which is 1028. (We have 5 instructions starting from address 1000, each of size 2, 1, 1, 2, 1 totaling 7 words = 28
bytes).
After HALT instruction CPU enters a HALT state and if an interrupt happens the return address will be that of the instruction after the HALT.
Ref http://x86.renejeschke.de/html/file_module_x86_id_134.html
option D
64. B. 24 cycles
-- Vikrant Singh
GATE2004_69 top
A 4-stage pipeline has the stage delays as 150, 120, 160 and 140 nanoseconds respectively. Registers that are used between the stages have
a delay of 5 nanoseconds each. Assuming constant clocking rate, the total time taken to process 1000 data items on this pipeline will be
A. 120.4 microseconds
B. 160.5 microseconds
C. 165.5 microseconds
D. 590.0 microseconds
Pipelining requires all stages to be synchronized meaning, we have to make the delay of all stages equal to the maximum pipeline stage
delay which here is 160.
Time for execution of the first instruction = (160+5) * 3 + 160 = 655 ns (5 ns for intermediate registers which is not needed for the final stage).
GATE2007_10 top
Consider a 4-way set associative cache consisting of 128 lines with a line size of 64 words. The CPU generates a 20-bit address of a word in
main memory. The number of bits in the TAG, LINE and WORD fields are respectively:
A. 9, 6, 5
B. 7, 7, 6
C. 7, 5, 8
D. 9, 5, 6
= 32.
So, number of index (LINE) bits = 5 and number of WORD bits = 6 size cache block (line) size is 64. So, number of TAG bits = 20 - 6 - 5 = 9.
GATE2007_80,81 top
Consider a machine with a byte addressable main memory of 216 bytes. Assume that a direct mapped data cache consisting of 32 lines of 64
bytes each is used in the system. A 50 x 50 two-dimensional array of bytes is stored in the main memory starting from memory location 1100H.
Assume that the data cache is initially empty. The complete array is accessed twice. Assume that the contents of the data cache do not change
in between the two accesses.
A. 48
B. 50
C. 56
D. 59
81. Which of the following lines of the data cache will be replaced by new blocks in accessing the array for the second time?
A. line 4 to line 11
B. line 4 to line 12
C. line 0 to line 7
D. line 0 to line 8
2 16 = 64 KB main memory is mapped to 32 lines of 64 bytes. So, number of offset bits = 6 (to identify a byte in a line) and number of indexing
bits = 5 (to identify the line).
Size of array = 50* 50 = 2500 B. If array is stored in row-major order (first row, second-row..), and if elements are also accessed in row-major
order (or stored and accessed in column-major order), for the first 64 accesses, there will be only 1 cache miss, and for 2500 accesses, there
will be 2500/64 = 40 cache misses during the first iteration.
We have 5 index bits and 6 offset bits. So, for 211 (5 + 6 = 11) continuous memory addresses there wont be any cache conflicts as the least
significant bits are offset bits followed by index bits.
So, number of array elements that can be accessed without cache conflict = 2048 (as element size is a byte). The next 452 elements conflict
with the first 452 elements. This means 452/64 = 8 cache blocks are replaced. (We used ceil, as even if one element from a new block is
accessed, the whole block must be fetched).
So, during second iteration we incur misses for the first 8 cache blocks as well as for the last 8 cache blocks. So, total data cache misses
across 2 iterations = 40 + 8 + 8 = 56.
For 81. answer is lines 4 to 11 as we start from
1100 H = (0001 0001 0000 0000)b excluding lower 6 bits for offset, we get 0001 0001 00 bits for cache block which is the 4th block.
-- Arjun Suresh
GATE2005_65 top
ADD A[R0], @B
The first operand (destination) “A[R0]” uses indexed addressing mode with R0 as the index register. The second operand (source) “@B” uses
indirect addressing mode. A and B are memory addresses residing at the second and third words, respectively. The first word of the instruction
specifies the opcode, the index register designation and the source and destination addressing modes. During execution of ADD instruction,
the two operands are added and stored in the destination (first operand).
The number of memory cycles needed during the execution cycle of the instruction is:
A. 3
B. 4
C. 5
D. 6
1 memory read - get first operand from memory address A+R0 (A is given as part of instruction)
1 memory read - get address of second operand (since second uses indirect addressing)
1 memory read - to get second operand from the address given by the previous memory read
GATE2005_66 top
Match each of the high level language statements given on the left hand side with the most natural addressing mode from those listed on the
right hand side.
GATE2013_20 top
In a k-way set associative cache, the cache is divided intov sets, each of which consists of k lines. The lines of a set are placed in sequence
one after another. The lines in set s are sequenced before the lines in set(s + 1). The main memory blocks are numbered 0 onwards. The
main memory block numbered j must be mapped to any one of the cache lines from
The question gives a sequencing for the cache lines. For set 0, the cache lines are numbered 0, 1, .., k-1. Now for set 1, the cache lines are
numbered k, k+1,... k+k-1 and so on.
So, main memory block j will be mapped to set (j mod v), which will be any one of the cache lines from (j mod v) * k to (j mod v) * k + (k-1).
(Associativity plays no role in mapping- k-way associativity means there are k spaces for a block and hence reduces the chances of
replacement.)
-- Arjun Suresh
GATE1999_13 top
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
F D D E W
F - D D E E W
F F - D - E E E W W
F - D D D - E E W
F - - - D D - E W W
CORRECT ME IF I AM WRONG
-- Danish
GATE2013_48,49 top
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have
atmost two source operands and one destination operand. Assume that all variables are dead after this code segment.
c = a + b;
d = c * a;
e = c + a;
x = c * c;
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
}
Q.48 Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion,
which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the
compiled code?
Q.49 What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without
any spill to memory? Do not apply any optimization other than optimizing register allocation.
c = a + b; //a and b in register and b replaced by the result c after the instruction
x = c * c; //x replaces c in register and c is spilled (moved to memory)
if (x > a) { //x and a in memory
y = a * a;
d = c * a; //spilled c taken from memory and replaces x in register.
e = c + a;
}
else {
d = c * a; //spilled c taken from memory and replaces x in register. d replaces a in register
d = d * d; //c and d in register
e = c + a; //a taken from memory and e replaces c in register (a taken from memory is not a spill, it is a fill)
e = e * e;
}
https://en.wikipedia.org/wiki/Register_allocation
49) Here, we are told not to do code motion. So, we start with 3 registers
c = a + b; //a, c in register
d = c * a; //a, c, d in register
e = c + a; //a, c, e in register, d spilled.
c = a + b; //a, c in register
d = c * a; //a, c, d in register
e = c + a; //a, c, d, e in register
x = c * c; //a, x, d, e in register
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
}
No spilling. So, 4 is the minimum number of registers needed for avoiding spilling. (If code motion was allowed, we need only 3 registers for
avoiding spilling).
-- Arjun Suresh
GATE1998_2.18 top
ans a)
-- Aditi Dan
GATE2014-1_9 top
A machine has a 32-bit architecture, with 1-word long instructions. It has 64 registers, each of which is 32 bits long. It needs to support 45 instructions, which have
an immediate operand in addition to two register operands. Assuming that the immediate operand is an unsigned integer, the maximum value of the immediate
operand is ____________
64 registers means 6 bits for a register operand. So, 2 register operand requires 12 bits. Now, 45 instructions require another 6 bits for
opcode. So, totally 18 bits. So, we have 32 - 18 = 14 bits left for the immediate operand. So, the max value will be 214 - 1 = 16383 (as the
operand is unsigned we don't need a sign bit and with 14 bits we can represent from 0 to 214 -1)
-- Arjun Suresh
GATE2006_42 top
A CPU has a five-stage pipeline and runs at 1 GHz frequency. Instruction fetch happens in the first stage of the pipeline. A conditional branch
instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new
instructions following a conditional branch until the branch outcome is known. A program executes 109 instructions out of which 20% are
conditional branches. If each instruction takes one cycle to complete on average, the total execution time of the program is:
GATE2006_74,75 top
Consider two cache organizations. First one is 32 kb 2-way set associative with 32 byte block size, the second is of same size but direct
mapped. The size of an address is 32 bits in both cases . A 2-to-1 multiplexer has latency of 0.6ns while a k − bit comparator has latency of
k
10
ns . The hit latency of the set associative organization ish1 while that of direct mapped is h2 .
(A) 2.4 ns
(B) 2.3 ns
(C) 1.8 ns
(D) 1.7 ns
(A) 2.4 ns
(B) 2.3 ns
(C) 1.8 ns
(D) 1.7 ns
Case 1:
cache size
number of sets = no. of blocks in a set × block size
32KB
= 2×32B
= 512
So, number of index bits needed = 9 ( since 29 = 512). Number of offset bits = 5 (since 25 = 32 B is the block size and assuming byte
addressing). So, number of tag bits = 32 - 9 - 5 = 18 (as memory address is of 32 bits).
So, time for comparing the data = Time to compare the data + Time to select the block in set = 0.6 + 18/10 ns = 2.4 ns. (Two comparisons of
tag bits need to be done for each block in a set, but they can be carried out in parallel and the succeeding one multiplexed as the output)
Case 2:
cache size
number of sets = no. of blocks in a set × block size
= 32KB = 1024
1×32B
So, number of index bits = 10, and number of tag bits = 32 - 10 - 5 = 17. So, h2
= 17/10 = 1.7 ns
-- Arjun Suresh
GATE2006_80,81 top
A CPU has a 32 KB direct mapped cache with 128 byte-block size. Suppose A is two dimensional array of size512 × 512 with elements that
occupy 8-bytes each. Consider the following two C code segments, P1 and P2.
P1:
P2:
P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache andi, j, x are in registers. Let the
number of cache misses experienced by P1 be M1 and that for P2 be M2.
(A) 0
(B) 2048
(C) 16384
(D) 262144
(A) 0
(B) 1
16
(C) 1
8
(D) 16
http://en.wikipedia.org/wiki/Row-major_order
When A[0][0] is fetched, 128 consecutive bytes are moved to cache. So, for the next 128/8 -1= 15 memory references there won't be a cache
miss. For the next iteration of i loop also the same thing happens as there is no temporal locality in the code. So, number of cache misses for
P1
512
= 16
× 512
= 32 × 512
= 2 14 = 16384
In the case of P2, the memory references are not consecutive. After A[0][0], the next access is A[1][0] which is after 512 * 8 memory locations.
Since our cache block can hold only 128 contiguous memory locations, A[1][0] won't be in cache after a[0][0] is accessed. Now, the next
location after A[0][0] is A[0][1] which will be accessed only after 512 iterations of the inner loop- after 512 distinct memory block accesses. In
our cache we have only space for 32 KB/128 B = 256 memory blocks. So, by the time A[0][1] is accessed, its cache block would be replaced.
So, each of the memory access in P2 results in a cache miss. Total number of cache miss
= 512 × 512
32×512 1
So, M1
= 512×512
= 16
M2
-- Arjun Suresh
GATE2014-1_43 top
Consider a 6-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining.
When an application is executing on this 6-stage pipeline, the speedup achieved with respect to non-pipelined execution if 25% of the
instructions incur 2 pipeline stall cycles is ____________
=1+.25*2
=1.5
Speed up = 6/1.5
=4
-- aravind90
GATE2014-1_44 top
An access sequence of cache block addresses is of length N and contains n unique block addresses. The number of unique block addresses
between two consecutive accesses to the same block address is bounded above by k. What is the miss ratio if the access sequence is passed
through a cache of associativity A ≥ k exercising least-recently-used replacement policy?
(A) n/N
(B) 1/N
(C) 1/A
(D) k/n
We are given that between two consecutive accesses to the same block, there can be only k-1 unique block addresses. So, for a block to get
replaced we can assume that all the next k-1 block addresses goes to the same set (given cache is set-associative) which will be the worst
case scenario. Now, if associativity size is >= k, and if we use LRU (Least Recently Used) replacement policy, we can guarantee that these k
accesses wont throw out our previously accessed cache entry (for that we need at least k accesses). So, this means we are at the best-cache
scenario for cache replacement -- out of N accesses we miss only n (which are unique and can not be helped from getting missed). So, miss
ratio is n/N.
-- Arjun Suresh
GATE2014-1_55 top
Consider two processors P 1 and P 2 executing the same instruction set. Assume that under identical conditions, for the same input, a program running on P2
takes 25% less time but incurs 20% more CPI (clock cycles per instruction) as compared to the program running on P 1 . If the clock frequency of P 1 is 1GHZ, then
the clock frequency of P 2 (in GHz) is ______.
CPU TIME ( T ) = No. of Instructions( I ) x No. of Cycles Per Instruction (c) x Cycle Time (t)
OR
CPU TIME ( T ) = No. of Instructions( I ) x No. of Cycles Per Instruction (c) x [Clock frequency ( f )-1]
===> T = I x c x f -1 ===> f = ( I x c) / T
P1 & P2 executing same instruction set -----> No. of Instructions same for both = 1I = I2 = I
-- Suraj Kaushal
GATE2014-2_9 top
A 4-way set-associative cache memory unit with a capacity of 16 KB is built using a block size of 8 words. The word length is 32 bits. The size
of the physical address space is 4 GB. The number of bits for the TAG field is ____
Now, we can divide the physical address space equally between these 128 sets. So, the number of bytes each set can access
= 4 GB / 128
= 32 MB
= 32/4 = 8 M words = 1 M blocks. (2 20 blocks)
-- Arjun Suresh
GATE2014-2_43 top
In designing a computer's cache system, the cache block (or cache line) size is an important parameter. Which one of the following statements
is correct in this context?
(B) A smaller block size implies a smaller cache tag and hence lower cache tag overhead
(C) A smaller block size implies a larger cache tag and hence lower cache hit time
(A) A smaller block size means during a memory access only a smaller part of near by addresses are brought to cache- meaning spatial
locality is reduced.
(B) A smaller block size means more number of blocks (assuming cache size constant)and hence we need more cache tag bits to identify the
correct block. So, cache tag becomes bigger.
(C) A smaller block size implying larger cache tag is true, but this can't lower cache hit time in any way.
(D) A smaller block size incurs a lower cache miss penalty. This is because during a cache miss, an entire cache block is fetched from next
lower level of memory. So, a smaller block size means only a smaller amount of data needs to be fetched and hence reduces the miss penalty
(Cache block size can go til the size of data bus to the next level of memory, and beyond this only increasing the cache block size increases
the cache miss penalty).
-- Arjun Suresh
GATE2014-2_44 top
If the associativity of a processor cache is doubled while keeping the capacity and block size unchanged, which one of the following is
guaranteed to be NOT affected?
If associativity is doubled, keeping the capacity and block size constant, then the number of sets gets halved. So, width of set index decoder
can surely decrease - (B) is false.
Width of way-selection muntiplexer must be increased as we have to double the ways to choose from- (C) is false
As the number of sets gets decreased, the number of possible cache block entries that a set maps to gets increased. So, we need more tag
bits to identify the correct entry. So, (A) is also false.
(D) is the correct answer- main memory data bus has nothing to do with cache associativity- this can be answered without even looking at
other options.
-- Arjun Suresh
GATE2014-3_9 top
Consider the following processors (ns stands for nanoseconds). Assume that the pipeline registers have zero latency.
P1: Four-stage pipeline with stage latencies 1 ns, 2 ns, 2 ns, 1 ns.
P2: Four-stage pipeline with stage latencies 1 ns, 1.5 ns, 1.5 ns, 1.5 ns.
P3: Five-stage pipeline with stage latencies 0.5 ns, 1 ns, 1 ns, 0.6 ns, 1 ns.
P4: Five-stage pipeline with stage latencies 0.5 ns, 0.5 ns, 1 ns, 1 ns, 1.1 ns.
(A) P1
(B) P2
(C) P3
(D) P4
-- Arpit Dhuriya
GATE2014-3_43 top
An instruction pipeline has five stages, namely, instruction fetch (IF), instruction decode and register fetch (ID/RF), instruction execution (EX),
memory access (MEM), and register writeback (WB) with stage latencies 1 ns, 2.2 ns, 2 ns, 1 ns, and 0.75 ns, respectively (ns stands for
nanoseconds). To gain in terms of frequency, the designers have decided to split the ID/RF stage into three stages (ID, RF1, RF2) each of
latency 2.2/3 ns. Also, the EX stage is split into two stages (EX1, EX2) each of latency 1 ns. The new design has a total of eight pipeline
stages. A program has 20% branch instructions which execute in the EX stage and produce the next instruction pointer at the end of the EX
stage in the old design and at the end of the EX2 stage in the new design. The IF stage stalls after fetching a branch instruction until the next
instruction pointer is computed. All instructions other than the branch instruction have an average CPI of one in both the designs. The execution
times of this program on the old and the new design are P and Q nanoseconds, respectively. The value of P /Q is __________.
cpi for first case = 2.2(1+2*.2) as the stall required is 2 and 2.2 is the maximum stage delay.
cpi for second state = 1*(1+5*.2) as now stall increase to 5 as there are five stages before the address is calculated and the maximum stage
delay now is 1.
GATE2014-3_44 top
The memory access time is 1 nanosecond for a read operation with a hit in cache, 5 nanoseconds for a read operation with a miss in cache, 2 nanoseconds for a
write operation with a hit in cache and 10 nanoseconds for a write operation with a miss in cache. Execution of a sequence of instructions involves 100 instruction
fetch operations, 60 memory operand read operations and 40 memory operand write operations. The cache hit-ratio is 0.9. The average memory access time (in
nanoseconds) in executing the sequence of instructions is ______.
=[160*1.4+40*2.8]/200
=336/200
=1.68
-- aravind90
GATE2011_28 top
On a non-pipelined sequential processor, a program segment, which is the part of the interrupt service routine, is given to transfer 500 bytes
from an I/O device to memory.
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 instruction. The load-store instructions take two clock cycles to execute.
The designer of the system also has an alternate approach of using the DMA controller to implement the same transfer. The DMA controller
requires 20 clock cycles for initialization and other overheads. Each DMA transfer cycle takes two clock cycles to transfer one byte of data from
the device to the memory.
What is the approximate speed up when the DMA controller based design is used in a place of the interrupt driven program based input-
output?
(A) 3.4
(B) 4.4
(C) 5.1
(D) 6.7
-- Manu Thakur
GATE2011_41 top
Consider an instruction pipeline with four stages (S1, S2, S3 and S4) each with combinational circuit only. The pipeline registers are required between each stage
and at the end of the last stage. Delays for the stages and for the pipeline registers are as given in the figure.
What is the approximate speed up of the pipeline in steady state under ideal conditions when compared to the corresponding non-pipeline implementation?
(A) 4.0
(B) 2.5
(C) 1.1
(D) 3.0
In pipeline system Time taken is determined by the max delay at any stage ie, 11ns plus the delay incurred by pipeline stages ie 1ns =12ns.
In non-pipeline system Delay=5ns+6ns+11ns+8ns=30ns.
-- Praneeth A S
GATE2010_33 top
A 5-stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Opearnd Fetch (OF), Perform Operation (PO) and Write
Operand (WO) stages. The IF, ID, OF and WO stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD
and SUB instructions, 3 clock cycles for MUL instruction and 6 clock cycles for DIV instruction respectively. Operand forwarding is used in the
pipeline. What is the number of clock cycles needed to execute the following sequence of instructions?
(A) 13
(B) 15
(C) 17
(D) 19
Operand forwarding allows an output to be passed for the next instruction. Here from the output of PO stage of DIV instruction operand is
forwarded to the PO stage of ADD instruction and similarly between ADD and SUB instructions.
http://www.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/forward.html
-- Arjun Suresh
GATE2010_48,49 top
A computer system has an L1 cache, an L2 cache, and a main memory unit connected as shown below. The block size in L1 cache is 4 words. The block size in L2
cache is 16 words. The memory access times are 2 nanoseconds, 20 nanoseconds and 200 nanoseconds for L1 cache, L2 cache and the main memory unit
respectively.
Q.48 When there is a miss in L1 cache and a hit in L2 cache, a block is transferred from L2 cache to L1 cache. What is the time taken for this transfer?
(A) 2 nanoseconds
(B) 20 nanoseconds
(C) 22 nanoseconds
(D) 88 nanoseconds
Q.49 When there is a miss in both L1 cache and L2 cache, first a block is transferred from main memory to L2 cache, and then a block is transferred from L2 cache
to L1 cache. What is the total time taken for these transfers?
A block is transferred from L2 to L1. And L1 block size being 4 words (since L1 is requesting we need to consider L1 block size and not L2
block size) and data width being 4 bytes, it requires one L2 access (for read) and one L1 access (for store). So, time = 20+2 = 22 ns.
For the second question, L2 block size being 16 words and data width between memory and L2 being 4 words, we require 4 memory
accesses(for read) and 4 L2 accesses (for store). Now, we need to send the requested block to L1 which would require one more L2 access
(for read) and one L1 access (for store). So, total time
= 880 + 22
= 902 ns
-- Arjun Suresh
GATE1995_1.2 top
It is C.
Only the top of the stack can be accessed at any time. You can imagine a stack to be opened from only one side data structure. So that if we
put one thing over the other, we are able to access the last thing we inserted first. That is Last in First Out.(LIFO).
-- Gate Keeda
GATE1995_1.6 top
(a) Interrupts
(b) DMA
(c) Polling
(d) Cache Memory
It is D.
Locality of reference is actually the frequent accessing of any storage location or some value. We can say in simple language that whatever
things are used more frequently, they are stored in the locality of reference. So we have cache memory for the purpose.
-- Gate Keeda
GATE1995_2.25 top
A computer system has a 4 K word cache organized in block-set-associative manner with 4 blocks per set, 64 words per block. The number of
bits in the SET and WORD fields of the main memory address format is:
(A) 15, 40
(B) 6, 4
(C) 7, 2
(D) 4, 6
Number of sets = 4K /(64*4) = 16. So, we need 4 bits to identify a set => SET = 4 bits.
So, (D)
-- Arjun Suresh
GATE2008-IT_38 top
Assume that EA = (X)+ is the effective address equal to the contents of location X, with X incremented by one word length after the effective
address is calculated; EA = −(X) is the effective address equal to the contents of location X, with X decremented by one word length before the
effective address is calculated; EA = (X)− is the effective address equal to the contents of location X, with X decremented by one word length
after the effective address is calculated. The format of the instruction is (opcode, source, destination), which means (destination ← source op
destination). Using X as a stack pointer, which of the following instructions can pop the top two elements from the stack, perform the addition
operation and push the result back to the stack.
-- Shaun Patel
GATE2008-IT_80 top
Consider a computer with a 4-ways set-associative mapped cache of the following characteristics: a total of 1 MB of main memory, a word size
of 1 byte, a block size of 128 words and a cache size of 8 KB.
The number of bits in the TAG, SET and WORD fields, respectively are:
A. 7, 6, 7
B. 8, 5, 7
C. 8, 6, 6
D. 9, 4, 7
So, number of SET bits required = 4 (as 24 = 16, and with 4 bits we can get 16 possible outputs)
We can now straight away choose (D) as answer but for confirmation can proceed further.
Since, only physical memory information is given we can assume cache is physically tagged (which is anyway the common case even in case
of virtual memory). So, we can divide the physical memory into 16 regions so that, each set maps into only its assigned region. So, size of a
region a set can address = 1MB/16 = 216 Bytes = 216 /128 = 29 cache blocks (as cache block size is 128 words = 128 bytes). So, when an
access comes to an cache entry, it must be able to determine which out of the 29 possible physical block it is. In short it needs 9 bits for TAG.
Now, cache block size is 128 words and so to identify a word we need 7 bits for WORD.
-- Arjun Suresh
GATE2008-IT_81 top
Consider a computer with a 4-ways set-associative mapped cache of the following characteristics: a total of 1 MB of main memory, a word size
of 1 byte, a block size of 128 words and a cache size of 8 KB.
While accessing the memory location 0C795H by the CPU, the contents of the TAG field of the corresponding cache line is
A. 000011000
B. 110001111
C. 00011000
D. 110010101
As shown in https://gateoverflow.in/3403/gate2008-it_80 we have 16 sets in cache and correspondingly 16 regions in physical memory to
which each set is mapped. Now, WORD bit size is 7 as we need 7 bits to address 128 possible words in a cache block. So, the lowest 7 bits of
0C795H will be used for this giving us the remaining bits as
0000 1100 0111 1
Of these bits, the lower 4 are used for addressing the 16 possible sets, giving us the tag bits: 0000 1100 0 in (A) choice.
-- Arjun Suresh
GATE2007-IT_37 top
Consider a Direct Mapped Cache with 8 cache blocks (numbered 0-7). If the memory block requests are in the following order
3, 5, 2, 8, 0, 63, 9,16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82,17, 24.
Which of the following memory blocks will not be in the cache at the end of the sequence ?
A) 3
B) 18
C) 20
D) 30
ans is B
cache location (memory block) = block req mod number of cache blocks. Since each block has only one location (associativity is 1) the last
mod 8 request will be in cache (no need of any replacement policy as mapping is direct)
1- at ends contains 17
2 - at end contains 82
3-3
4- 20
5-5
6-30
7-63
-- rajsh3kar
GATE2006-IT_39 top
(D) is false. Relative addressing cannot be faster than absolute addressing as absolute address must be calculated from relative address.
(A) is true as instead of absolute address we can use a much smaller relative address in instructions which results in smaller instruction size.
(B) By using the base address of array we can index array elements using relative addressing.
(C) is true as we only need to change the base address in case of relocation- instructions remain the same.
-- Arjun Suresh
GATE2006-IT_40 top
The memory locations 1000, 1001 and 1020 have data values 18, 1 and 16 respectively before the following program is executed.
MOVI Rs, 1 ; Move immediate
LOAD Rd, 1000(Rs) ; Load from memory
ADDI Rd, 1000 ; Add immediate
STOREI 0(Rd), 20 ; Store immediate
-- Abhinav Rana
GATE2006-IT_42 top
A cache line is 64 bytes. The main memory has latency 32ns and bandwidth 1G.Bytes/s. The time required to fetch the entire cache line from
the main memory is
A) 32 ns
B) 64 ns
C) 96 ns
D) 128 ns
ans : c
so for 64 bytes?
64+32 = 96 ns
-- rajsh3kar
GATE2006-IT_79 top
A pipelined processor uses a 4-stage instruction pipeline with the following stages: Instruction fetch (IF), Instruction decode (ID), Execute (EX)
and Writeback (WB). The arithmetic operations as well as the load and store operations are carried out in the EX stage. The sequence of
instructions corresponding to the statement X = (S - R * (P + Q))/T is given below. The values of variables P, Q, R, S and T are available in the
registers R0, R1, R2, R3 and R4 respectively, before the execution of the instruction sequence.
ADD R5, R0, R1 ; R5 → R0 + R1
MUL R6, R2, R5 ; R6 → R2 * R5
SUB R5, R3, R6 ; R5 → R3 - R6
DIV R6, R5, R4 ; R6 → R5/R4
STORE R6, X ; X ← R6
The IF, ID and WB stages take 1 clock cycle each. The EX stage takes 1 clock cycle each for the ADD, SUB and STORE operations, and 3
clock cycles each for MUL and DIV operations. Operand forwarding from the EX stage to the ID stage is used. The number of clock cycles
required to complete the sequence of instructions is
A) 10
B) 12
C) 14
D) 16
This is what i have solved. so answer is 12
-- Manu Thakur
GATE2004-IT_12 top
Consider a system with 2 level cache. Access times of Level 1 cache, Level 2 cache and main memory are 1 ns, 10 ns, and 500 ns,
respectively. The hit rates of Level 1 and Level 2 caches are 0.8 and 0.9, respectively. What is the average access time of the system ignoring
the search time within the cache?
A) 13.0 ns
B) 12.8 ns
C) 12.6 ns
D) 12.4 ns
option C
GATE2004-IT_47 top
Consider a pipeline processor with 4 stages S1 to S4. We want to execute the following loop:
for (i = 1; i < = 1000; i++)
{I1, I2, I3, I4}
where the time taken (in ns) by instructions I1 to I4 for stages S1 to S4 are given below:
A) 11 ns
B) 12 ns
C) 13 ns
D) 28 ns
time 1 2 3 4 5 6 7 8 9 10 11 12 13
I1 s1 s2 s2 s3 s4 s4
I2 s1 s1 s2 s3 s3 s4
I3 s1 s2 - s3 s3 s4
I4 s1 s1 s2 - s3 s3 s4
I1 s1 s2 s2 - s3 s4 s4
correct me if i am wrong...
-- Suvojit Mondal
GATE2004-IT_48 top
Consider a fully associative cache with 8 cache blocks (numbered 0-7) and the following sequence of memory block requests:
A) 4
B) 5
C) 6
D) 7
[4 3 19 6 25 8 16 35]
So, 45 replaces 4
45 3 25 8 19 6 16 35 [3 19 6 25 8 16 35 45]
45 22 25 8 19 6 16 35 [19 6 25 8 16 35 45 22]
8 hits in cache
45 22 25 8 19 6 16 35 [19 6 25 16 35 45 22 8]
3 replaces 19
45 22 25 8 3 6 16 35 [6 25 16 35 45 22 8 3]
45 22 25 8 3 6 16 35 [6 35 45 22 8 16 25 3]
GATE2004-IT_49 top
A CPU has only three instructions I1, I2 and I3, which use the following signals in time steps T1-T5:
I3 : T1 : Din, Aout
T2 : Ain, Bout
T3 : Zout, Ain
T4 : Dout, Ain
T5 : End
Which of the following logic functions will generate the hardwired control for the signal Ain ?
We just have to see which all options give 1 whenever Ain is 1 and 0 otherwise.
So, Ain is 1 in T3 of I1, I2 and I3. Also during T1 of I1, and T2 and T4 of I3. So, answer will be
Since CPU is having only 3 instructions, T3.I1 + T3.I2 + T3.I3 can be replaced with T3 (we don't need to see which instruction and A
in will be
activated in time step 3 of all the instructions).
-- Arjun Suresh
GATE2005-IT_49 top
An instruction set of a processor has 125 signals which can be divided into 5 groups of mutually exclusive signals as follows:
Group 1 : 20 signals, Group 2 : 70 signals, Group 3 : 2 signals, Group 4 : 10 signals, Group 5 : 23 signals.
How many bits of the control words can be saved by using vertical microprogramming over horizontal microprogramming?
A) 0
B) 103
C) 22
D) 55
In horizontal microprogramming we need 1 bit for every control word, therefore total bits in
Horizontal Microprogramming=20+70+2+10+23=125
Now lets consider vertical microprogramming, In vertical microprogramming we use Decoder (n to 2n ) and output lines are equal to number
of control words . A input is given according to what control word we have to select.
Now in this question these 5 groups contains mutually exclusive signals, i.e, they can be activated one at a time for a given group, we can
safely use decoder.
group 1= ⌈ log220⌉=5 (Number of input bits for decoder, given output is number of control word in given group)
group 2= ⌈ log270⌉ =7
group 3= ⌈ log22 ⌉ =1
group 4= ⌈ log210⌉ =4
-- Prateeksha Keshari
GATE2005-IT_61 top
Consider a 2-way set associative cache memory with 4 sets and total 8 cache blocks (0-7) and a main memory with 128 blocks (0-127). What
memory blocks will be present in the cache after the following sequence of memory block references if LRU policy is used for cache block
replacement. Assuming that initially the cache did not have any memory block from the current job?
0 5 3 9 7 0 16 55
A) 0 3 5 7 16 55
B) 0 3 5 7 9 16 55
C) 0 5 7 9 16 55
D) 3 5 7 9 16 55
128 main memory blocks are mapped to 4 sets in cache. So, each set maps 32 blocks each. And in each set there is place for two blocks (2-
way set).
Now, we have 4 sets meaning 2 index bits. Also, 32 blocks going to one set means 5 tag bits.
Now, these 7 bits identify a memory block and tag bits are placed before index bits. (otherwise adjacent memory references- spatial locality-
will hamper cache performance)
So, based on the two index bits (lower 2 bits) blocks will be going to sets as follows:
Since, each set has only 2 places, 3 will be throw out as its the least recently used block. So, final content of cache will be
0 5 7 9 16 55
(C) choice.
-- Arjun Suresh
coa top
A hard disk with a transfer rate of 10 M bytes/second is constantly transferring data to memory using DMA. The processor runs at 600 MHz.
and takes 300 and 900 clock cycles to initiate and complete DMA transfer respectively. If the size of the transfer is 20 Kbytes, what is the
percentage of processor time consumed for the transfer operation?
(A) 5.0%
(B) 1.0%
(C) 0.5%
(D) 0.1%
Solution : D
20×210
Duration of transfer =
10×220
= 2 × 2 −10
1200
Time for 1200 clocks = = 2 × 10−6 and processor is used only for this much of time. So,
600×106
Percentage of CPU time consumed = 2×10−6 × 100%
2×2−10
-- Gowthaman Arumugam
GATE2015-2_24 top
Assume that for a certain processor, a read request takes 50 nanoseconds on a cache miss and 5 nanoseconds on a cache hit. Suppose while
running a program, it was observed that 80% of the processor's read requests result in a cache hit. The average read access time in
nanoseconds is _____.
GATE2015-2_42 top
Consider a processor with byte-addressable memory. Assume that all registers, including program counter (PC) and Program Status Word
(PSW), are size of two 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 and the second word is the starting address of the subroutine (one word = 2 bytes). The CALL instruction is implemented as
follows:
The content of PC just before the fetch of a CALL instruction is(5F A0)16 . After execution of the CALL instruction, the value of the stack pointer
is
A. (016A)16
B. (016C)16
C. (0170)16
D. (0172)16
-- Anoop Sonkar
GATE2015-1_38 top
Consider a non-pipelined processor with a clock rate of 2.5 gigahertz and average cycles per instruction of four. The same processor is
upgraded to a pipelined processor with five stages; but due to the internal pipeline delay, the clock speed is reduced to 2 gigahertz. Assume
that there are no stalls in the pipeline. The speedup achieved in this pipelined processor is_______________.
answer is 3.2
Speed up = Old execution time/New execution time
= CPIold / CFold / (CPInew / CFnew) (CF is clock frequency and CPI is Cycles Per Instruction, so CPI/CF gives time per instruction)
= 4 / 2.5 / (1 / 2)
= 3.2
Without pipelining an instruction was taking 4 cycles. After pipelining to 5 stages we need to see the max. clock cycle a stage can take and
this will be the CPI assuming no stalls.
-- naresh1845
GATE2015-3_47 top
Consider the following code sequence having five instructions fromI 1 to I 5 . Each of these instructions has the following format.
OP Ri, Rj, Rk
Where operation OP is performed on contents of registers Rj and Rk and the result is stored in register Ri.
S3: Within an instruction pipeline an anti-dependence always creates one or more stalls
A. Only S1 is true
B. Only S2 is true
C. Only S1 and S3 are true
D. Only S2 and S3 are true
Answer should be B.
Anti-dependence can be overcome in pipeline using register renaming. So, "always" in S3 makes it false. Also, if I2 is completed before I4
(execution stage of MUL), then also there won't be any stall.
-- ppm
A 2-way set associative cache consists of four sets. Main memory contains 2K blocks of eight words each.
a) Show the main memory address format that allows us to map addresses from main memory to cache. Be sure to include the fields as well
as their sizes.
b) Compute the hit ratio for a program that loops 3 times from locations 8 to 51 in main memory. You may leave the hit ratio in terms of a
fraction.
Hello Sir, I am write now solving sums from "The essentials of Computer architecture " I got this sum . and there is no solution provided i just
wanna ask you to check this
Solution :
No of lines in a set=2
No of set in Cache = 4
Block size=8 words
So, Size of each cache= No of set* No of line in set * Block Size= 8*4*2=64 Words
Size of MM= no of block in main memory * size of each block=(2^11)*(2^3)= 2^14 words
We have a cache size/ capacity = 64 words and Size of Main Memory as( 2 ^ 14 words )
And since the loop says it starts from location 8 to 51 then . No of elements that will be encountered = (51-8+1)= 44 which is equivalent for
running i from 0 to 43 times (for 44 words )
Out of these 44 words there would be 22 words which would be mapped to set 0 and 22 words which would be mapped to Set 1
Now in each Set , we have 2 lines and Each block has a size of 8 words ,
And so in reamining in (22-16) words we would have 6 words . to accomodate these 6 words again 1 block need to replaced
While in second iteration there would be again need of replacing 1 block to (first 8 words ) rest would be hit till and then again 1 miss for (last 6
words ) this is just for 1 set
Is this correct ? Please help . i am sorry to write such a big content . But this question need and to show my way of approaching towards sums
:)
Actually in first part we got 9 tag bits, 2 index bits and 3 offset bits. So, these bits are like these:
tag bits | index bits | offset bits
That is, the lower bits are offset bits followed by index bits and then tag bits.
Our memory access starts from address 8. With 3 offset bits, this cache line reference will be from address 8 to address 15 (1000 - 1111 in
binary). Say this cache line goes to cache set A during the memory access for address 8. Next 7 accesses are cache hits. When address 16
is accessed, its cache line goes to set B and not set A because after offset comes the index/set bits so the set changes (this is made so that
spacial locality won't reduce cache hits). Now, all accesses till 23 are hits and 24 will be a miss and cache line for 24 goes to set C. Similarly,
cache line for 32 goes to set D. Now, for cache line of 40, it should go to set A. But it won't replace the cache line at set A, as each set has
space for 2 cache lines (2-way associative). Similarly cache line of address 48 goes to set B. And that is the last cache miss in iteration 1. So,
we have 6 cache misses and 38 cache misses in iteration 1. For iterations 2 and 3, all are cache hits. So,
= 126/132
-- Arjun Suresh
In Operand Forwarding technique how does the next instruction is able to access the
dependent operand which is calculated in the previous instruction in the same Cpu Cycle?
top
In the same CPU cycle is not possible. Operand forwarding happens in the next cycle after the operation producing the operand is finished.
-- Arjun Suresh
co top
What will be the minimum size of ROM which maintains truth table of square of 3 bit numbers(in bits) ?
I0 I1 I2 B0 B1 B2 B3 B4 B5
0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 1
0 1 0 0 0 0 1 0 0
0 1 1 0 0 1 0 0 1
1 0 0 0 1 0 0 0 0
1 0 1 0 1 1 0 0 1
1 1 0 1 0 0 1 0 0
1 1 1 1 1 0 0 0 1
so it will have 3 address line mean 8 address [000 to 111] and 6 bits [B0 to B5] at each address = 8 X 6 = 48 bits
-- Praveen Saini
16 KB, 4-way set-associative cache, 32-bit address, byte addressable memory, 32-byte
cache blocks/lines top
16 KB, 4-way set-associative cache, 32-bit address, byte addressable memory, 32-byte cache blocks/lines
No of sets = 4 = 2 bit
. = 32 - 7 - 5 = 20 bit
0x200356A4 = (<0010 0000 0000 0011 0101> <0110 101> <0 0100>)
A computer system contains a main memory of 32K 16-bit words. It also has a 4Kword cache divided into four-line sets with 64 words per line.
Assume that the cache is initially empty. The processor fetches words from locations 0, 1, 2, . . ., 4351 in that order. It then repeats this fetch
sequence nine more times.The cache is 10 times faster than main memory. Estimate the improvement resulting from the use of the
cache. Assume an LRU policy for block replacement.
Memory access time without cache = 4352 × 10x = 43520x, where x is the time for one access.
In cache we have 64 words per line and 4 lines per set (4 way associativity) and total size is 4096 words. So,
4096
number of sets = 64×4
= 16
So after accessing 16 × 64 = 1024 words (0-1023) all the sets will be filled with one entry each. But with 4-way associativity each set has
space for 3 more. So filling can go like this for 4096 words (0-4095). After this next entry (cache line from 4096-4159) will go to first set and will
replace the cache line 0-63 due to LRU policy. Like wise total no. of cache replacements = (4351-4096)/64 = 256/64 = 4.
Now for the second iteration the first four cache line accesses will be cache misses as they got replaced. But these cache lines will be
replacing the oldest used one in the set. For example cache line 0-63 will be replacing 1024-1095. Now the cache line 1024-1095 will in turn
be replacing 2048-2111 and likewise all new cache line accesses will be cache misses (LRU works badly). This will trigger 16 cache line
misses - 4 each from the first four sets. For 5th set to 16th set, there won't be any cache miss. Now, for the cache lines 4096-4351, there
will be 4 more cache misses which are again coming from the first 4 sets. So, totally 16+4 = 20 cache misses. (Shown in figure at end)
Thus,
So,
43520x
Performance improvement = 4574.9x
= 9.45 times
-- Arjun Suresh
Operating System top
GATE2012_8 top
fork();
fork();
fork();
(A) 3
(B) 4
(C) 7
(D) 8
At each fork() the no. of processes becomes doubled. So, after 3 fork calls, the total no. of processes will be 8. Out of this 1 is the parent
process and 7 are child processes. So, total number of child processes created is 7.
-- Arjun Suresh
A memory page containing a heavily used variable that was initialized very early and is in constant use is removed when
(a) LRU page replacement algorithm is used
(b) FIFO page replacement algorithm is used
(c) LFU page replacement algorithm is used
(d) None of the above
LRU can't be used as the page is still is in use , so it will be in most high priority.
LFU can't be used as it has been accessed several time , it's frequency value will be larger.
FIFO can do it as it only considers the time the page came in RAM. So the page can be deleted byFIFO . also from that statement we can
assume FIFO wasn't in use till now.
-- Palash Nandi
GATE2013_52,53 top
A computer uses 46-bit virtual address, 32-bit physical address, and a three–level paged page table organization. The page table base register
stores the base address of the first-level table (T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of
the second-level table (T2). Each entry of T2 stores the base address of a page of the third-level table (T3). Each entry of T3 stores a page
table entry (PTE). The PTE is 32 bits in size. The processor used in the computer has a 1 MB 16 way set associative virtually indexed
physically tagged cache. The cache block size is 64 bytes.
What is the minimum number of page colours needed to guarantee that no two synonyms map to different sets in the processor cache of this
computer?
We should have an entry for each page in last level page table which here is T3. So,
number of entries in T3 = 246
x
Now, T3 must occupy (sizeof T3/page size) pages and for each of these page we must have an T2 entry. So, no. of entries in T2
2 48
= x
x
= 248
x2
2 50
Now, for each of these page we must have an entry in T1. So, number of entries in T1
= 250
x3
x= 252
x3
x4 = 2 52
x = 2 13
= 8KB
Min. no. of page color bits = No. of set index bits + no. of offset bits - no. of page index bits (This ensures no synonym maps to different sets
in the cache)
number of sets = 1MB/(64B * Number of blocks in each set) = 16K/16 (16 way set associative) = 1K = 10
2.
So, we need 10 index bits. Now, each block being 64 (26) bytes means we need 6 offset bits.
And we already found page size = 8KB = 213, so 13 bits to index a page
A synonym is a physical page having multiple virtual addresses referring to it. So, what we want is no two synonym virtual addresses to map
to two different sets, which would mean a physical page could be in two different cache sets. This problem never occurs in a physically
indexed cache as indexing happens via physical address bits and so one physical page can never go to two different sets in cache. In virtually
indexed cache, we can avoid this problem by ensuring that the bits used for locating a cache block (index+offset) of the virtual and physical
addresses are the same.
In our case we have 6 offset bits + 10 bits for indexing. So, we want to make these 16 bits same for both physical and virtual address. One
thing is that the page offset bits - 13 bits for 8 KB page, is always the same for physical and virtual addresses as they are never translated.
So, we don't need to make these 13 bits same. We have to only make the remaining 19 + 6 - 13 = 3 bits same. Page coloring is a way to do
this. Here, all the physical pages are colored and a physical page of one color is mapped to a virtual address by OS in such a way that a set in
cache always gets pages of the same color. So, in order to make the 3 bits same, we take all combinations of it (23 = 8) and colors the
physical pages with 8 colors and a cache set always gets a page of one color only. (In page coloring, it is the job of OS to ensure that the 3
bits are the same).
http://ece.umd.edu/courses/enee646.F2007/Cekleov1.pdf
-- Arjun Suresh
GATE2008_20 top
The data blocks of a very large file in the Unix file system are allocated using
A. continuous allocation
B. linked allocation
C. indexed allocation
D. an extension of indexed allocation
The data blocks of a very large file in the unix file system are allocated using an extension of indexed allocation or EXT2 file system. Hence
option (d) is the right answer.
-- Kalpna Bhargav
GATE2008_67 top
A processor uses 36 bit physical address and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table entry is of size 4
bytes. A three level page table is used for virtual to physical address translation, where the virtual address is used as follows:
Bits 30-31 are used to index into the first level page table.
Bits 21-29 are used to index into the 2nd level page table.
Bits 12-20 are used to index into the 3rd level page table.
Bits 0-11 are used as offset within the page.
The number of bits required for addressing the next level page table(or page frame) in the page table entry of the first, second and third level
page tables are respectively
a) 20,20,20
b) 24,24,24
c) 24,24,20
d) 25,25,24
Physical address is 36 bits. So, number of page frame's possible = 36/12 = 24 (12 offset bits as given in question). So, the third level page
table must have 24 bits for addressing the page frames.
http://www.cs.utexas.edu/~lorenzo/corsi/cs372/06F/hw/3sol.html See Problem 3, second part solution - It clearly says that we should not
assume that page tables are page aligned.
So, we need 25 bits in second level page table for addressing the third level page tables.
So, we need 25 bits for addressing the second level page tables as well.
-- Arjun Suresh
GATE1991_02,iii top
02. Match the pairs in the following questions by writing the corresponding letters only.
A-R
B-P
C-S
D-Q
-- Gate Keeda
GATE1992_02,x top
02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
Ans=option B
currently semaphore is 7 so after 20 P(wait) operation it will come to -12 then for 15 V(signal) operation the value comes to 2.
-- sanjeev_zerocode
GATE1992_02,xi top
02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(xi) A computer system has 6 tape devices, with n processes competing for them. Each process may need 3 tape drives. The maximum value
of n for which the system is guaranteed to be deadlock free is:
a. 2
b. 3
c. 4
d. 1
Answer: A
For n=2, 3 - 3 is the maximum need and that can always be satisfied.
-- Jon Snow
GATE2001_1.7 top
exploit the spatial locality of reference in a program as, if the next locality is addressed immediately, it will already be in the cache.
-- Arjun Suresh
GATE2001_1.22 top
Which of the following requires a device driver?
(A) Register
(B) Cache
(D) Disk
A disk driver is a device driver that allows a specific disk drive to communicate with the remainder of the computer. A good example of this
driver is a floppy disk driver.
-- Bhagirathi Nayak
GATE2005_72 top
TRUE?
Let u,v be the values printed by the parent process and x,y be the values printed by the child process. Which one of the following is
b) x < u and y = v
d) x = u+10 y = v
(d) is the answer. Child is incrementing a by 5 and parent is decrementing a by 5. So, x = u + 10.
During fork(), address space of parent is copied for the child. So, any modifications to child variable won't affect the parent variable or vice-
verse. But this copy is for physical pages of memory. The logical addresses remains the same between the parent and child processes.
-- gatecse
GATE2003_78,79 top
A processor uses 2-level page tables for virtual to physical address translation. Page tables for both levels are stored in the main memory.
Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most
significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second
level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in
both levels of page tables are 4 bytes wide. Further, the processor has a translation look-aside buffer (TLB), with a hit rate of 96%. The TLB
caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed
cache with a hit rate of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and TLB access time is also 1 ns.
78. Assuming that no page faults occur, the average time taken to access a virtual address is approximately (to the nearest 0.5 ns)
79. Suppose a process has only the following pages in its virtual address space: two contiguous code pages starting at virtual address
0x00000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual address 0xFFFFF000. The
amount of memory required for storing the page tables of this process is
78. It's given cache is physically addressed. So, address translation is needed for all memory accesses.
Average access time = Average address translation time + Average memory access time
= 1ns (TLB is accessed for all accesses) + 2*10*0.04 (2 page tables accessed from main memory in case of TLB miss) + Average memory access time
= 1.8ns + Cache access time + Average main memory access time
= 1.8ns + 1 * 0.9 (90% cache hit) + 0.1 * 10 (main memory is accessed for cache misses only)
= 1.8ns + 0.9 + 1
= 3.7ns
79. First level page table is addressed using 10 bits and hence contains 210 entries. Each entry is 4 bytes and hence this table requires 4 KB.
Now, the process uses only 3 unique entries from this 1024 possible entries (two code pages starting from 0x00000000 and two data pages
starting from 0x00400000 have same first 10 bits). Hence, there are only 3 second level page tables. Each of these second level page tables
are also addressed using 10 bits and hence of size 4 KB. So,
-- gatecse
GATE2002_1.23 top
The optimal page replacement algorithm will select the page that
A. Has not been used for the longest time in the past
B. Will not be used for the longest time in the future
C. Has been used least number of times
D. Has been used most number of times
Optimal page replacement algorithm will always select the page that will not be used for the longest time in the future for replacement, and
that is why the it is called optimal page replacement algorithm. Hence, (B) choice.
-- Arjun Suresh
GATE2003_76 top
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statistically linked libraries?
D. Existing programs need not be re-linked to take advantage of newer versions of libraries
option c) DLL takes more time in program setup(in loading and linking phase)
Since DLLs are separated from executable, the size of executable becomes smaller.
Since DLLs are shared among multiple executables, the total memory usage of the system goes down and hence overall page fault rate
decreases.
Dynamic linking takes place during program runtime. So, if a DLL is replaced to a new version, it will automatically get linked during runtime.
There is no explicit relinking required as in the case of static linking. (This works by linking the DLL calls to Global Offset Table and the
contents of this table is filled during program run. So, a simple jump in static linking becomes an indirect jump in dynamic linking).
-- GateMaster Prime
GATE2004_12 top
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% 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 hence there is no use of any
disk scheduling algorithm. Anyone will give the same sequence and hence the improvement will be 0%.
-- Arjun Suresh
GATE2004_21 top
The minimum number of page frames that must be allocated to a running process in a virtual memory environment is determined by
GATE2007_11 top
Consider a disk pack with 16 surfaces, 128 tracks per surface and 256 sectors per track. 512 bytes of data are stored in a bit serial manner in a
sector. The capacity of the disk pack and the number of bits required to specify a particular sector in the disk are respectively:
ans is A.
16 surfaces= 4 bits, 128 tracks= 7 bits, 256 sectors= 8 bits, sector size 512 bytes = 9 bits
to specify a particular sector we do not need sector size, so bits required = 4+7+8 = 19
-- jayendra
GATE2009_33 top
The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows:
void enter_CS(X)
{
while(test-and-set(X));
}
void leave_CS(X)
{
X = 0;
}
In the above solution, X is a memory location associated with the CS and is initialized to 0. Now consider the following statements:
IV. More than one process can enter CS at the same time
A. I only
B. I and II
C. II and III
D. IV only
2) Progress as at initially X is 0 and at least one process can enter critical section at any time.
But no guarantee that a process eventually will enter CS and hence option IV is false. Also, no ordering of processes is maintained and hence
III is also false.
GATE2009_34 top
A multilevel page table is preferred in comparison to a single level page table for translating virtual address to physical address because
B. It helps to reduce the size of page table needed to implement the virtual address space of a process
B.
When the page table size increases we perform paging on the page table. Resulting in multi-level page table.
-- Gate Keeda
GATE2009_51,52 top
A hard disk has 63 sectors per track, 10 platters each with 2 recording surfaces and 1000 cylinders. The address of a sector is given as a triple
⟨c, h, s⟩, where c is the cylinder number, h is the surface number and s is the sector number. Thus, the 0th sector is addresses as ⟨0, 0, 0⟩ , the
1st sector as ⟨0, 0, 1⟩ , and so on
A. 505035
B. 505036
C. 505037
D. 505038
B. ⟨0, 16, 30 ⟩
The data on a disk is ordered in the following way. It is first stored on the first sector of the first surface of the first cylinder. Then in the next
sector, and next, until all the sectors on the first track are exhausted. Then it moves on to the first sector of the second surface (remains at the
same cylinder), then next sector and so on. It exhausts all available surfaces for the first cylinder in this way. After that, it moves on to repeat
the process for the next cylinder.
So, to reach to the cylinder numbered 400 (401th cylinder) we need to skip 400 * (10*2) * 63 = 504,000 sectors.
Then, to skip to the 16th surface of the cylinder numbered 400, we need to skip another 16*63 = 1,008 sectors.
52. 1039th sector will be stored in track number (1039 + 1)/63 = 16.5 (as counting starts from 0 as given in question) and each track has 63
sectors. So, we need to go to 17th track which will be numbered 16 and each cylinder has 20 tracks (10 platters * 2 recording surface each) .
Number of extra sectors needed = 1040-16*63 = 32 and hence the sector number will be 31. So, option C.
-- Pragy Agarwal
GATE2013_16 top
Three concurrent processes X , Y , and Z execute three different code segments that access and update certain shared variables. ProcessX
executes the P operation (i.e., wait ) on semaphores a, b and c ; process Y executes the P operation on semaphores b , c and d; process Z
executes the P operation on semaphores c , d, and a before entering the respective code segments. After completing the execution of its code
segment, each process invokes the V operation (i.e., signal ) on its three semaphores. All semaphores are binary semaphores initialized to
one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?
(A) X : P (a)P (b)P (c)Y : P (b)P (c)P (d)Z : P (c)P (d)P (a)
(B) X : P (b)P (a)P (c)Y : P (b)P (c)P (d)Z : P (a)P (c)P (d)
(C) X : P (b)P (a)P (c)Y : P (c)P (b)P (d)Z : P (a)P (c)P (d)
(D) X : P (a)P (b)P (c)Y : P (c)P (b)P (d)Z : P (c)P (d)P (a)
For deadlock-free invocation, X, Y and Z must access the semaphores in the same order so that there won't be a case where one process is
waiting for a semaphore while holding some other semaphore. This is satisfied only by option B.
In option A, X can hold a and wait for c while Z can hold c and wait for a
In option C, X can hold b and wait for c, while Y can hold c and wait for b
In option D, X can hold a and wait for c while Z can hold c and wait for a
http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf
-- Arjun Suresh
GATE1999_2.11 top
Which of the following is/are advantage(s) of virtual memory?
(c) Linker can assign addresses independent of where the program will be loaded in physical memory.
(d) Program larger than the physical memory size can be run.
Virtual memory provides an interface through which processes access the physical memory. So,
(a) Is false as direct access can never be slower.
(b) Is true as without virtual memory it is difficult to give protected address space to processes as they will be accessing physical memory
directly. No protection mechanism can be done inside the physical memory as processes are dynamic and number of processes changes
from time to time.
(c) Position independent can be produced even without virtual memory support.
(d) This is one primary use of virtual memory. Virtual memory allows a process to run using a virtual address space and as and when memory
space is required, pages are swapped in/out from the disk if physical memory gets full.
-- Arjun Suresh
GATE2013_39 top
A certain computation generates two arrays a and b such that a[i] = f(i) for 0 ≤ i < n and b[i] = g(a[i]) for 0 ≤ i < n. Suppose this computation is
decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two
binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown
below.
Process X:
private i;
for (i=0; i< n; i++) {
a[i] = f(i);
ExitX(R, S);
Process Y:
private i;
for (i=0; i< n; i++) {
EntryY(R, S);
b[i] = g(a[i]);
Which one of the following represents the CORRECT implementations of ExitX and EntryY?
(A)
ExitX(R, S) {
P(R);
V(S);
EntryY(R, S) {
P(S);
V(R);
(B) ExitX(R, S) {
V(R);
V(S);
EntryY(R, S) {
P(R);
P(S);
(C) ExitX(R, S) {
P(S);
V(R);
}
EntryY(R, S) {
V(S);
P(R);
(D) ExitX(R, S) {
V(R);
P(S);
EntryY(R, S) {
V(S);
P(R);
A choice:
B choice:
Process X is doing Signal operation on R and S without any wait and hence multiple signal operations can happen on the binary semaphore
so Process Y won't be able to get exactly n successful wait operations. i.e., Process Y may not be able to complete all the iterations.
C choice:
Process X does Wait(S) followed by Signal(R) while Process Y does Signal(S) followed by Wait(R). So, this ensures that no two iterations of
either X or Y can proceed without an iteration of the other being executed in between. i.e., this ensures that all n iterations of X and Y
succeeds and hence the answer.
D choice:
Process X does Signal(R) followed by Wait(S) while Process Y does Signal(S) followed by Wait(R). There is a problem here that X can do two
Signal(R) operation without a Wait(R) being done in between by Y. This happens in the following scenario:
So, this can result in some Signal operations getting lost as the semaphore is a binary one and thus Process Y may not be able to complete
all the iterations. If we change the order of Signal(S) and Wait(R) in EntryY, then D option also can work.
-- Arjun Suresh
GATE1998_1.31 top
Initially semaphore is 10 , then 6 down operations are performed means (10-6=4) and 4 up operations means (4+4=8)
GATE1998_1.32 top
A computer has six tape drives, with n processes competing for them. Each process may need two drives. What is the maximum value ofn for
the system to be deadlock free?
a. 6
b. 5
c. 4
d. 3
P1 P2 P3 P4 P5 P6
1 1 1 1 1 1
This is scenario when a deadlock would happen, as each of the process is waiting for 1 more process to run to completion. And there are no
more Resources available as max 6 reached. If we could have provided one more R to any of the process, any of the process could have
executed to completion, then released its resources, which further when assigned to other and then other would have broken the deadlock
situation.
In case of processes, if there are less than 6 processes, then no deadlock occurs.
P1 P2 P3 P4 P5
1 1 1 1 1
In this case system has 6 resources max,and hence we still have 1 more R left which can be given to any of the processes, which in turn runs
to completion, releases its resources and in turn others can run to completion too.
Ans b) 5
-- Sourav Roy
GATE1998_2.9 top
Ans is C
http://en.wikipedia.org/wiki/Disk_formatting
-- Keith Kr
GATE1998_2.16 top
B) 14 KB is answer,
At execution time overlays D and E will both utilize the same memory locations
The following example shows the control statements that instruct the OS/360 Linkage Editor to link an overlay program, indented to show
structure:
INCLUDE SYSLIB(MOD1)
INCLUDE SYSLIB(MOD2)
OVERLAY A
INCLUDE SYSLIB(MOD3)
OVERLAY AA
INCLUDE SYSLIB(MOD4)
INCLUDE SYSLIB(MOD5)
OVERLAY AB
INCLUDE SYSLIB(MOD6)
OVERLAY B
INCLUDE SYSLIB(MOD7)
+--------------+
| Root Segment |
| MOD1, MOD2 |
+--------------+
|
+----------+----------+
| |
+-------------+ +-------------+
| Overlay A | | Overlay B |
| MOD3 | | MOD7 |
+-------------+ +-------------+
|
+--------+--------+
| |
+-------------+ +-------------+
| Overlay AA | | Overlay AB |
| MOD4, MOD5 | | MOD6 |
+-------------+ +-------------+
These statements define a tree consisting of the permanently resident segment, called theroot, and two overlays A and B which will be loaded
following the end of MOD2. Overlay A itself consists of two overlay segments, AA, and AB. At execution time overlays A and B will both utilize
the same memory locations; AA and AB will both utilize the same locations following the end of MOD3.
All the segments between the root and a given overlay segment are called apath.
refere @ http://en.wikipedia.org/wiki/Overlay_(programming)#Example
-- csegate2
GATE2014-1_31 top
An operating system uses the Banker's algorithm for deadlock avoidance when managing the allocation of three resource types X, Y, and Z to
three processes P0, P1, and P2. The table given below presents the current system state. Here, the Allocation matrix shows the current
number of resources of each type allocated to each process and the Max matrix shows the maximum number of resources of each type
required by each process during its execution.
Allocation Max
X Y Z X Y Z
P0 0 0 1 8 4 3
P1 3 2 0 6 2 0
P2 2 1 1 3 3 3
There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system is currently in asafe state. Consider the following
independent requests for additional resources in the current state:
Option B
P0 0 0 3 8 43 8 4 0
P1 3 2 0 6 20 3 0 0
P2 2 1 1 3 3 3 1 2 2
Since Z is not available now, neither P0 nor P2's requirement can be satisfied. So its an unsafe state.
-- Poulami Das
GATE2014-1_32 top
Consider the following set of processes that need to be scheduled on a single CPU. All the times are given in milliseconds.
Using the shortest remaining time first scheduling algorithm, the average process turnaround time (in msec) is ____________________.
-- Jayesh Malaviya
GATE2014-1_33 top
Assume that there are 3 page frames which are initially empty. If the page reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, the number of page
faults using the optimal replacement policy is__________.
Ans : initially all empty frames fill by 1,2,3 so all time page fault which is 3 .
then next 4 was not available in frame set sowe look at ahead of request which was coming lastwe replace 4 with that so 3 will be
replace by 4 and like wise next 2 and 1 is present already so no page fault and then next 5 is not present so replace with 1 and then 3 was not
present and replace with 5 and then 2 and 4 are present already so no page fault and then last 6th was not already there so page fault.
-- Jayesh Malaviya
GATE2014-2_55 top
Consider a main memory system that consists of 8 memory modules attached to the system bus, which is one word wide. When a write request
is made, the bus is occupied for 100 nanoseconds (ns) by the data, address, and control signals. During the same 100 ns, and for 500 ns
thereafter, the addressed memory module executes one cycle accepting and storing the data. The (internal) operation of different memory
modules may overlap in time, but only one request can be on the bus at any time. The maximum number of stores (of one word each) that can
be initiated in 1 millisecond is ________
When a write request is made, the bus is occupied for 100 ns. So, between 2 writes at least 100 ns interval must be there.
Now, after a write request, for 100 + 500 = 600 ns, the corresponding memory module is busy storing the data. But, assuming the next stores
are to a different memory module (we have totally 8 modules in question), we can have consecutive stores at intervals of 100 ns. So,
maximum number of stores in 1 ms
-- Arjun Suresh
GATE2014-3_31 top
A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that
deadlocks never arise is _________.
for this types of problems in which every process is making same number of request,use the formula n.(m-1)+1<=r
r=no. of resources
GATE2014-3_33 top
Consider a paging hardware with a TLB. Assume that the entire page table and all the pages are in the physical memory. It takes 10
milliseconds to search the TLB and 80 milliseconds to access the physical memory. If the TLB hit ratio is 0.6, the effective memory access time
(in milliseconds) is _________.
EMAT=TLB hit*(TLB access time+memory access time)+TLB miss(TLB access time+page table access time+memory access time)
=0.6(10+80)+0.4(10+80+80)
= 54+68
=122msec
-- neha pawar
GATE2011_44 top
An application loads 100 libraries at startup. Loading each library requires exactly one disk access. The seek time of the disk to a random location is given as 10
ms. Rotational speed of disk is 6000 rpm. If all 100 libraries are loaded from random locations on the disk, how long does it take to load all libraries? (The time to
transfer data from the disk block once the head has been positioned at the start of the block may be neglected.)
(A) 0.50 s
(B) 1.50 s
(C) 1.25 s
(D) 1.00 s
disk access time =seek time +rotational latency+transfer time (given that transfer time is neglected)
rotational speed=6000rpm
1 rotation------60/6000 sec
GATE2010_23 top
Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean
variables S1 and S2 are randomly assigned.
ans is A ..in this mutual exclusion is satisfied,only one process can access the critical section at particular time but here progress will not
satisfied because suppose when s1=1 and s2=0 and process p1 is not interested to enter into critical section but p2 want to enter critical
section. P2 is not able to enter critical section in this as only when p1 finishes execution, then only p2 can enter (then only s1 = s2 condition
be satisfied). Progress will not be satisfied when any process which is not interested to enter into the critical section will not allow other
interested process to enter into the critical section.
-- neha pawar
GATE2010_24 top
A system uses FIFO policy for system replacement. It has 4 page frames with no pages loaded to begin with. The system first accesses 100
distinct pages in some order and then accesses the same 100 pages but now in the reverse order. How many page faults will occur?
(A) 196
(B) 192
(C) 197
(D) 195
ans is A
when we access the 100 distinct page in some order (suppose order is 1 2 3....100) then total page fault occurs are 100. and in last, frame
contain the pages 100 99 98 97 .when we reverse the string (100,99,98....1) then first four page will not cause the page fault bcz they already
present in frame but the remaining 96 page will cause 96 page fault,so total page fault are 100+96=196
-- neha pawar
GATE2010_25 top
(A) I only
ans is D
i)In SRTF ,job with the shorest CPU burst will be scheduled first bcz of this process with large CPU burst may suffer from starvation
ii)In preemptive scheduling , suppose process P1 is executing in CPU and after some time process P2 with high priority then P1 will arrive in
ready queue then p1 is prrempted and p2 will brought into CPU for execution.in this way if process which is arriving in ready queue is of
higher prioirity then p1 ,then p1 is always preempted and it may possible that it suffer from starvation.
iii)round robin will give better response time then FCFS ,in FCFS when process is executing ,it executed upto its complete burst time,but in
round robin it will execute upto time quantum.
-- neha pawar
GATE1997_3.9 top
Thrashing
http://en.wikipedia.org/wiki/Thrashing_%28computer_science%29
-- Sankaranarayanan P.N
GATE1997_3.10 top
The dirty bit allows for a performance optimization. A page on disk that is paged in to physical memory, then read from, and subsequently
paged out again does not need to be written back to disk, since the page hasn't changed. However, if the page was written to after it's paged
in, its dirty bit will be set, indicating that the page must be written back to the backing store answer: a
-- Sankaranarayanan P.N
GATE1997_6.8 top
repeat
P(mutex)
{Critical section}
V(mutex)
forever
The code for P10 is identical except it uses V(mutex) in place of P(mutex). What is the largest number of processes that can be inside the
critical section at any moment?
A. 1
B. 2
C. 3
D. None
Answer is D
If initial value is 1//execute P1 or P10 first
If initial value is 0, P_10 can execute and make the value 1.
since the both code (ie p1 to p9 and p10)can be executed any number of times and code for p10 is
repeat
{
v(mutex)
C.S.
V(mutex)
}
forever
-- Kalpish Singhal
GATE1993_7.8 top
file system uses directories which are the files containing the name and location of other file in the file system. unlike other file,directory does
not store the user data.Directories are the file that can point to other directories. Root directory point to various user directory.so they will be
stored in such a way that user cannot easily modify them .they were placed at fixed location in system disk.
-- neha pawar
GATE1993_7.9 top
Consider a system having m resources of the same type. These resources are shared by 3 processes A, B and C, which have peak demands
of 3, 4 and 6 respectively. For what value of m deadlock will not occur?
a. 7
b. 9
c. 10
d. 13
e. 15
13 and 15.
Consider the worst scenario: all processes require one more instance of the resource. So, P1 would have got 2, P2 - 3 and P3 - 5. Now, if one
more resource is available at least one of the processes could be finished and all resources allotted to it will be free which will lead to other
processes also getting freed. So, 2 + 3 + 5 = 10 would be the maximum value of m so that a deadlock can occur.
-- Arjun Suresh
GATE2010_46 top
A system has n resources R0 , … , Rn−1 , and k processes P 0 , … , P k−1 . The implementation of the resource request logic of each process P i is as follows:
if (i%2==0) {
if (i<n) request Ri;
if (i+2 < n) request Ri+2
}
else {
if (i<n) request Rn-i ;
if (i+2 <n) request Rn-i-2;
}
(A) n = 40, k = 26
(B) n = 21, k = 12
(C) n = 20, k = 10
(D) n = 41, k = 19
From the resource allocation logic, it's clear that even numbered processes are taking even numbered resources and all even numbered
processes share no more than 1 resource. Now, if we make sure that all odd numbered processes take odd numbered resources without a
cycle, then deadlock cannot occur. The "else" case of the resource allocation logic, is trying to do that. But, if n is odd, Rn−i and Rn−i−2 will
be even and there is possibility of deadlock, when two processes requests the same Ri and Rj . So, only B and D are the possible answers.
Now, in D , we can see that P0 requests R0 and R2 , P2 requests R2 and R4 , so on until, P18 requests R18 and R20 . At the same time P1
requests R40 and R38 , P3 requests R38 and R36 , so on until, P17 requests R24 and R22 . i.e.; there are no two processes requesting the same
two resources and hence there can't be a cycle of dependencies which means, no deadlock is possible.
But for B, P8 requests R8 and R10 and P11 also requests R10 and R8 . Hence, a deadlock is possible. (Suppose P8 comes first and occupies
R8 . Then P11 comes and occupies R10 . Now, if P8 requests R10 and P11 requests R8 , there will be deadlock)
-- Arjun Suresh
GATE1994_1.13 top
FIFO replaces a page which was brought into memory first will be removed first so since variable was initialized very early. it is in the set of
first in pages. so it will be removed answer: b if you use LRU - since it is used constantly it is a recently used item always. so cannot be
removed. If you use LFU - the frequency of the page is more since it is in constant use. So cannot be replaced
-- Sankaranarayanan P.N
GATE1995_1.15 top
Which scheduling policy is most suitable for a time shared operating system?
B. Round Robin.
-- Sankaranarayanan P.N
GATE1995_19 top
Consider the following program segment for concurrent processing using semaphore operatorsP and V for synchronization. Draw the
precedence graph for the statements S1 to S9.
var
a,b,c,d,e,f,g,h,i,j,k : semaphore;
begin
cobegin
begin S1; V(a); V(b) end;
begin P(a); S2; V(c); V(d) end;
begin P(c); S4; V(e) end;
begin P(d); S5; V(f) end;
begin P(e); P(f); S7; V(k) end
begin P(b); S3; V(g); V(h) end;
begin P(g); S6; V(i) end;
begin P(h); P(i); S8; V(j) end;
begin P(j); P(k); S9 end;
coend
end;
GATE1995_20 top
The head of a moving head disk with 100 tracks numbered 0 to 99 is currently serving a request at track 55. If the queue of requests kept in
FIFO order is
which of the two disk scheduling algorithms FCFS (First Come First Served) and SSTF (Shortest Seek Time First) will require less head
movement? Find the head movement for each of the algorithms.
Hence SSTF.
-- kireeti
GATE1996_1.18 top
Answer is B. The transition from running to ready indicates that the process in the running state can be preempted and bought back to ready
state.
-- kireeti
GATE1996_1.19 top
C. is the answer
http://en.wikipedia.org/wiki/Critical_section
B - critical section by default doesn't avoid deadlock. While using critical section, programmer must ensure deadlock is avoided.
D - This is not a requirement of critical section. Only when semaphore is used for critical section management, this becomes a necessity. But,
semaphore is just ONE of the ways for managing critical section.
-- Gate Keeda
GATE1996_1.20 top
ans is A
spooling(simultaneous peripheral operations online) is a technique in which an intermediate device such as disk is interposed between
process and low speed i/o device.for ex. in printer if a process attempt to print a document but printer is busy printing another document ,the
process,instead of waiting for printer to become available,write its output to disk.when the printer become available the data on disk is
printed.spooling allows process to request operation from peripheral device without requiring that the device be ready to service the request.
-- neha pawar
GATE1996_2.18 top
A 1000 Kbyte memory is managed using variable partitions but no compaction. It currently has two partitions of sizes 200 Kbytes and 260
Kbytes respectively. The smallest allocation request in Kbytes that could be denied is for
(a) 151
(b) 181
(c) 231
(d) 541
Answer is B. Since the total size of the memory is 1000KB, lets assume that the partitioning for the current allocation is done in such a way
that it will leave minimum free space.
Partitioning the 1000kB as below will allow gaps of 180KB each and hence a request of 181kB will not be met.
GATE1996_2.19 top
acc. to me it should be c) because.. according to condition.. out of all , one philosopher will get both the forks.. so deadlock should not be
there.
-- Sneha Goel
GATE1996_2.20 top
here all process arrive at time 0.so there order of execution will be A B C D, in this manner completion time for A is 9
-- neha pawar
GATE2008-IT_16 top
A paging scheme uses a Translation Look-aside Buffer (TLB). A TLB-access takes 10 ns and a main memory access takes 50 ns. What is the
effective access time(in ns) if the TLB hit ratio is 90% and there is no page-fault?
A) 54
B) 60
C) 65
D) 75
Effective access time = hit ratio * time during hit + miss ratio * time during miss
In both cases TLB is accessed and assuming page table is accessed from memory only when TLB misses.
= 54 + 11
= 65
-- Arjun Suresh
GATE2008-IT_41 top
Assume that a main memory with only 4 pages, each of 16 bytes, is initially empty. The CPU generates the following sequence of virtual
addresses and uses the Least Recently Used (LRU) page replacement policy.
0, 4, 8, 20, 24, 36, 44, 12, 68, 72, 80, 84, 28, 32, 88, 92
How many page faults does this sequence cause? What are the page numbers of the pages present in the main memory at the end of the
sequence?
A) 6 and 1, 2, 3, 4
B) 7 and 1, 2, 4, 5
C) 8 and 1, 2, 4, 5
D) 9 and 1, 2, 3, 5
The question says LRU policy, so the cache must be associative as there is no need of a replacement policy in direct-mapped cache. We can
assume fully associative cache as no other information is given. So, we have 4 spaces for a page and there will be a replacement only when a
5th distinct page comes.
-- Arjun Suresh
GATE2008-IT_53 top
The following is a code with two threads, producer and consumer, that can run in parallel. Further, S and Q are binary semaphores equipped
with the standard P and V operations.
semaphore S = 1, Q = 0;
integer x;
producer: consumer:
while (true) do while (true) do
P(S); P(Q);
x = produce (); consume (x);
V(Q); V(S);
done done
D Consumer can consume only once the producer has produced the item, and producer can produce(except the first time) only once the
consumer has consumed the item.
-- Shaun Patel
GATE2008-IT_55 top
If the time-slice used in the round-robin scheduling policy is more than the maximum time required to execute any process, then the policy will
ans is c
-- Sanjay Sharma
GATE2007-IT_12 top
The address sequence generated by tracing a particular program executing in a pure demand paging system with 100 bytes per page is
0100, 0200, 0430, 0499, 0510, 0530, 0560, 0120, 0220, 0240, 0260, 0320, 0410.
Suppose that the memory can store only one page and if x is the address which causes a page fault then the bytes from addresses x to x + 99
are loaded on to the memory.
-- Arjun Suresh
GATE2007-IT_44 top
What is the average time taken for transferring 250 bytes from the disk ?
A) 300.5 ms
B) 255.5 ms
C) 255 ms
D) 300 ms
Avg. time to transfer = Avg. seek time + Avg. rotational delay + Data transfer time
RPM = 600
In 1 rotations we can transfer the whole data in a track which is equal to number of sectors in a track * bytes per track
Avg. seek time = (0 + 1 + 2 + .... + 499)/500 (as time to move between successive tracks is 1 ms and we have 500 such tracks) = 499 * 250
/500 = 249.5
So, average time for transferring 250 bytes = 249.5 + 50 + 0.5 = 300 ms
-- Arjun Suresh
At the call of fork, a child process is created which executes the same code of the parent from that point. the return value or fork is 0 for the
child and is child pid (not 0) for the parent and this value is used to distinguish between child-parent while writing code using fork.
Thus 5 child processes are created. Since the question asks for "total number of processes created" we must include parent also making this
6 processes in total,
-- Arjun Suresh
GATE2004-IT_14 top
Which one of the following is NOT shared by the threads of the same process ?
A) Stack
B) Address Space
C) File Descriptor Table
D) Message Queue
GATE2004-IT_62 top
A disk has 200 tracks (numbered 0 through 199). At a given time, it was servicing the request of reading data from track 120, and at the
previous request, service was for track 90. The pending requests (in order of their arrival) are for track numbers.
How many times will the head change its direction for the disk scheduling policies SSTF(Shortest Seek Time First) and FCFS (First Come Fist
Serve)?
A. 2 and 3
B. 3 and 3
C. 3 and 4
D. 4 and 4
Answer is (C)
-- Sandeep_Uniyal
GATE2004-IT_63 top
In a certain operating system, deadlock prevention is attemped using the following scheme. Each process is assigned a unique timestamp, and
is restarted with the same timestamp if killed. Let Ph be the process holding a resource R, Pr be a process requesting for the same resource R,
and T(Ph) and T(Pr) be their timestamps respectively. The decision to wait or preempt one of the processes is based on the following algorithm.
Answer is (A)
When the process wakes up again after it has been killed once or twice IT WILL HAVE SAME TIME-STAMP as it had WHEN IT WAS KILLED
FIRST TIME. And that time stamp can never be greater than a process that was killed after that or a NEW process that may have arrived.
So every time when the killed process wakes up it MIGHT ALWAYS find a new process that will say "your time stamp is less than me and I
take this resource", which of course is as we know, and that process will again be killed.
This may happen indefinitely if processes keep coming and killing that "INNOCENT" process every time it try to access.
-- Sandeep_Uniyal
GATE2004-IT_64 top
A) n
B) ((n(n + 1))/2)
C) 2n - 1
D) 3n - 1
option C
-- prakash
GATE2004-IT_66 top
In a virtual memory system, size of virtual address is 32-bit, size of physical address is 30-bit, page size is 4 Kbyte and size of each page table
entry is 32-bit. The main memory is byte addressable. Which one of the following is the maximum number of bits that can be used for storing
protection and other information in each page table entry?
A) 2
B) 10
C) 12
D) 14
ans is D
page table entry must contain bits for representing frames and other bits for storing information like dirty bit,reference bit etc
no. of frames (no. of possible pages) = Physical memory size/ Page size = 230/212 = 218
x =14 bits
-- neha pawar
GATE2005-IT_17 top
A student wishes to create symbolic links in a computer system running Unix. Three text files named "file 1", "file 2" and "file 3" exist in her
current working directory, and the student has read and write permissions for all three files. Assume that file 1 contains information about her
hobbies, file 2 contains information about her friends and file 3 contains information about her courses. The student executes the following
sequence of commands from her current working directory
ln -s file 1 file 2
ln -s file 2 file 3
Which of the following types of information would be lost from her file system?
(I) Hobbies (II) Friends (III) Courses
option B
GATE2005-IT_62 top
Two shared resources R1 and R2 are used by processes P1 and P2. Each process has a certain priority for accessing each resource. Let Tij
denote the priority of Pi for accessing Rj. A process Pi can snatch a resource Rh from process Pj if Tik is greater than Tjk.
Given the following :
Which of the following conditions ensures that P1 and P2 can never deadlock?
If R1 and R2 are allocated to the Process P1 , then it will complete it's job and release it . After that process P
2 will get both the resources and
complete it's Job .
-- zabiullah shiekh
GATE2005-IT_63 top
In a computer system, four files of size 11050 bytes, 4990 bytes, 5170 bytes and 12640 bytes need to be stored. For storing these files on disk,
we can use either 100 byte disk blocks or 200 byte disk blocks (but can't mix block sizes). For each block used to store a file, 4 bytes of
bookkeeping information also needs to be stored on the disk. Thus, the total space used to store a file is the sum of the space taken to store
the file and the space taken to store the book keeping information for the blocks allocated for storing the file. A disk block can store either
bookkeeping information for a file or data from a file, but not both.
What is the total space required for storing the files using 100 byte disk blocks and 200 byte disk blocks respectively?
11050 = 111 blocks requiring 111 * 4 = 444 bytes of bookkeeping info which requires another 5 disk blocks. So, totally 111 + 5 = 116 disk
blocks. Similarly,
4990 = 50 + (50*4)/100 = 52
5170 = 52 + (52*4)/100 = 55
12640 = 127 + (127*4/100) = 133
-----
356 x 100 = 35600 bytes
56 + (56*4/200) = 58
25 + (25 * 4 / 200) = 26
26 + (26 * 4 / 200) = 27
64 + (64 * 4 / 200) = 66
-----
177 x 200 = 35400
So, C option.
-- Viral Kapoor
GATE2005-IT_81a top
A disk has 8 equidistant tracks. The diameters of the innermost and outermost tracks are 1 cm and 8 cm respectively. The innermost track has
a storage capacity of 10 MB.
What is the total amount of data that can be stored on the disk if it is used with a drive that rotates it with (i) Constant Linear Velocity (ii)
Constant Angular Velocity?
With Constant Linear Velocity, CLV, the density of bits is uniform from cylinder to cylinder. Because there are more sectors in outer
cylinders, the disk spins slower when reading those cylinders, causing the rate of bits passing under the read-write head to remain
constant. This is the approach used by modern CDs and DVDs.
With Constant Angular Velocity, CAV, the disk rotates at a constant angular speed, with the bit density decreasing on outer cylinders.
( These disks would have a constant number of sectors per track on all cylinders. )
CLV=10+20+30+40+..80=360
CAV=10*8 = 80 so answer should be d
-- spriti1991
Now, 32-5-12 = 15 bits are there and we need all of them to be used as tag bits as otherwise we cannot identify a page from the tag.
(215 possible page can come to a set and minimum 15 bits are needed to identify the page).
-- Arjun Suresh
Deadlock top
Consider a system consisting of n resources of same type being shared by 4 processes, 2 of which need at most 2 resources each and other
need at most 3 resources each.The min value of n so that the system is deadlock free is ___________?
Now, assume the worst case. All processes are allotted all resources except 1. So, 2*1 + 2 * 2 = 6. Here, deadlock is possible with n = 6.
When n = 7, at least one process must finish and we get 7 resources for 3 processes which require maximum 8 resources between them. So,
again at least one of them will finish and there won't be a deadlock.
-- Arjun Suresh
GATE2015-2_23 top
A system has 6 identical resources and N processes competing for them. Each process can request atmost 2 requests. Which one of the
following values of N could lead to a deadlock?
A. 1
B. 2
C. 3
D. 4
3*2=6
4 * 2 = 8.
I guess a question can't get easier than this- D choice. (Also, we can simply take the greatest value among choice for this question)
[There are 6 resources and all of them must be in use for deadlock. If the system has no other resource dependence, N=4 cannot lead to a
deadlock. But if N=4, the system can be in deadlock in presence of other dependencies.
Why N=3 cannot cause deadlock? It can cause deadlock, only if the system is already in deadlock and so the deadlock is independent of the
considered resource. Till N=3, all requests for considered resource will always be satisfied and hence there won't be a waiting and hence no
deadlock with respect to the considered resource. ]
-- Arjun Suresh
GATE2015-2_25 top
A computer system implements a 40-bit virtual address, page size of 8 kilobytes, and a 128-entry translation look-aside buffer (TLB) organized
into 32 sets each having 4 ways. Assume that the TLB tag does not store any process id. The minimum length of the TLB tag in bits is ____.
TLB maps a virtual address to the physical address of the page. (The lower bits of page address - offset bits- are not used in TLB as they are
the same for virtual as well as physical addresses). Here, for 8 kB page size we require 13 offset bits.
In TLB we have 32 sets and so virtual address space is divided into 32 using 5 set bits. (Associativity doesn't affect the set bits as they just
adds extra slots in each set).
GATE2015-2_30 top
Consider 6 memory partitions of sizes 200 KB, 400 KB, 600 KB, 500 KB, 300 KB and 250 KB, where KB refers to kilobyte. These partitions
need to be allotted to four processes of sizes 357 KB, 210 KB, 468 KB, 491 KB in that order. If the best fit algorithm is used, which partitions
are NOT allotted to any process?
option A is correct because we have 6 memory partitions of sizes 200 KB, 400 KB, 600 KB, 500 KB, 300 KB and 250 KB and the partition
allotted to the process using best fit is given below-
357 KB process allotted at partition 400 KB.
210 KB process allotted at partition 250 KB
468 KB process allotted at partition 500 KB
491 KB process allotted at partition 600 KB
so we have left only two partitions 200 KB and 300 KB
-- Anoop Sonkar
GATE2015-1_12 top
Consider a system with byte-addressable memory, 32-bit logical addresses, 4 kilobyte page size and page table entries of 4 bytes each. The
size of the page table in the system in megabytes is_________________.
GATE2015-2_47 top
A computer system implements 8 kilobyte pages and a 32-bit physical address space. Each page table entry contains a valid bit, a dirty bit,
three permission bits, and the translation. If the maximum size of the page table of a process is 24 megabytes, the length of the virtual address
supported by the system is _______ bits.
Virtual address supported = No. of PTEs * Page size (As we need a PTE for each page)
= 8 M * 8 KB
= 64 GB = 236 Bytes
-- Arjun Suresh
GATE2015-2_49 top
Consider a typical disk that rotates at 15000 rotations per minute (RPM) and has a transfer rate of 50 × 106 bytes/sec. If the average seek time
of the disk is twice the average rotational delay and the controller's transfer time is 10 times the disk transfer time, the average time (in
milliseconds) to read or write a 512-byte sector of the disk is _____.
Average time to read/write = Avg. seek time + Avg. rotational delay + Effective transfer time
Ref: http://www.csc.villanova.edu/~japaridz/8400/sld012.htm
-- Arjun Suresh
GATE2015-1_48 top
Consider a disk pack with a seek time of 4 milliseconds and rotational speed of 10000 rotations per minute (RPM). It has 600 sectors per track
and each sector can store 512 bytes of data. Consider a file stored in the disk. The file contains 2000 sectors. Assume that every sector access
necessitates a seek, and the average rotational latency for accessing each sector is half of the time for one complete rotation. The total time (in
milliseconds) needed to read the entire file is__________________.
Total time = 2000 * (seek time + avg. rotational latency + data transfer time)
Since data transfer rate is not given, we can take that in 1 rotation, all data in a track is read. i.e., in 60/10000 = 6ms, 600 * 512 bytes are
read. So, time to read 512 bytes = 6/600 ms = 0.01 ms
= 14020 ms.
http://www.csee.umbc.edu/~olano/611s06/storage-io.pdf
-- Arjun Suresh
GATE2015-3_1 top
The maximum number of processes that can be in readyReady state for a computer system with n CPUs is
A. n
B. n2
C. 2n
D. Independent of n
D. independent of n.
The number of processes that can be in READY state depends on the Ready Queue size and is independent of the number of CPU's.
-- Arjun Suresh
GATE2015-3_10 top
Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes
Process X Process Y
Here varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?
A. The proposed solution prevents deadlock but fails to guarantee mutual exclusion
B. The proposed solution guarantees mutual exclusion but fails to prevent deadlock
C. The proposed solution guarantees mutual exclusion and prevents deadlock
D. The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion
When both processes try to enter critical section simultaneously,both are allowed to do so since both shared variables varP and varQ are
true. So, clearly there is NO mutual exclusion. Also, deadlock is prevented because mutual exclusion is one of the conditions for deadlock
to happen.Hence, answer is A.
-- tanaya
GATE2015-3_52 top
Consider the following policies for preventing deadlock in a system with mutually exclusive resources.
I. Process should acquire all their resources at the beginning of execution. If any resource is not available, all resources acquired so far are
released.
II. The resources are numbered uniquely, and processes are allowed to request for resources only in increasing resource numbers
III. The resources are numbered uniquely, and processes are allowed to request for resources only in deccreasing resource numbers
IV. The resources are numbered uniquely. A processes is allowed to request for resources only for a resource with resource number larger
than its currently held resources
a deadlock will not occur if any one of the below four conditions are prevented :
4> no-premption
now
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/7_Deadlocks.html
-- Tamojit Chatterjee
Databases top
GATE2012_2 top
(C) Every relation in BCNF is also in 3NF. Striaght from definition of BCNF.
-- Arjun Suresh
GATE2012_14 top
Given the basic ER and relational models, which of the following isINCORRECT?
(C) is incorrect as a relational table requires that, in a row, an attribute can have exactly one value or NULL value.
-- Arjun Suresh
GATE2012_15 top
(A) P and R
(B) P and S
(C) Q and R
(D) Q and S
GATE2008_70 top
Consider a file of 16384 records. Each record is 32 bytes long and its key field is of size 6 bytes. The file is ordered on a non-key field, and the
file organization is unspanned. The file is stored in a file system with block size 1024 bytes, and the size of a block pointer is 10 bytes. If the
secondary index is built on the key field of the file, and a multi-level index scheme is used to store the secondary index, the number of first-
level and second-level blocks in the multi-level index are respectively
(A) 8 and 0 (B) 128 and 6 (C) 256 and 4 (D) 512 and 5
Content of an index will be <key, block pointer> and so will have size 6 + 10 = 16.
In the first level, there will be an entry for each record of the file. So,total size of first-level index
= 16384 * 16
In the second-level there will be an entry for each block in the first level. So, total number of entries = 256 and total size of second-level index
=4
-- gatecse
GATE2008_82,83 top
A. 2
B. 3
C. 4
D. 5
83. Which of the following is a correct attribute set for one of the tables for the correct answer to the above question?
First strong entity types are made to tables. So, we get two tables M and P.
I assume R1 is 1:1 or 1:n as that would minimize the number of tables as asked in question.
Now participation of M in R1 is total (indicated by double arrow) meaning every entity of M participate in R1. Since R1 is not having an
attribute, we can simple add the primary key of P to the table M and add a foreign key reference to M. This handles R1 and we don't need an
extra table. So, M becomes {M1, M2, M3, P1}.
N here is a weak entity weakly related to P. So, we form a new table N, and includes the primary key of P (P1) as foreign key reference. Now
(P1, N1) becomes the primary key of N.
-- Arjun Suresh
GATE2008_15 top
Which of the following tuple relational calculus expression(s) is/are equivalent to∀t ∈ r(P (t))?
(A) I only
(B) II only
(C) III only
(D) III and IV only
IV is not correct as it as saying that there exist a tuple, not in r for which P is not true, which is not what the given expression means.
-- Arjun Suresh
GATE2008_68 top
I. ΠP (R ⋈ S)
A. Only I and II
B. Only I and III
C. Only I, II and III
D. Only I, III and IV
(d) i, iii, iv
R : {⟨" 1 ", " abc ", " p1 ", " p2 ", " p3 "⟩,
⟨" 2 ", " xyz ", " p1 ", " p2 ", " p3 "⟩}
S : {⟨" 1 ", " abc ", " q1 ", " q2 ", " q3 "⟩
⟨" 2 ", " def ", " q1 ", " q2 ", " q3 "⟩}
i. R ⋈ S gives
{⟨" 1 ", " abc ", " p1 ", " p2 ", " p3 ", " q1 ", " q2 ", " q3 "⟩}
{⟨" 1 ", " abc "⟩, ⟨" 2 ", " xyz "⟩} ∩ {⟨" 1 ", " abc "⟩, ⟨" 2 ", " def "⟩ }
= {⟨" 1 ", " abc "⟩}
{⟨" 1 ", " abc "⟩, ⟨" 2 ", " xyz "⟩}
− ({⟨" 1 ", " abc "⟩, ⟨" 2 ", " xyz "⟩} − {⟨" 1 ", " abc "⟩, ⟨" 2 ", " def "⟩})
= {⟨" 1 ", " abc "⟩, ⟨" 2 ", " xyz "⟩}
− {⟨" 2 ", " xyz "⟩}
= {⟨" 1 ", " abc "⟩}
GATE2008_69 top
Assume { Author, Title } is the key for both schemes. Which of the following statements is true?
Answer: C
So , here no partial dependency exists . So , it is in 2NF , Now , let's check for Transitive dependency. We can not find any TD as well. So . it
is in 3NF. Now , let's check for BCNF. Catalog_no is also key attribute. So , Collection is in BCNF.
Now , let's see Book (Title , Author , Catalog_no , Publisher , Year , Price ) :
But in the given dependencies , {Publisher , Title , Year} --> Price , which has Transitive Dependency.So , Book is in 2NF.
-- Shounak Kundu
GATE2000_1.23 top
which of the following queries cannot be expressed using the basic relational algebra operations(σ, π, ×, ⋈, ∪, ∩, −)?
or
or
or
(c) but we can't generate relational algebra of aggregate function using basic operation , so we need extended operation here , option (c) is
false .
-- csegate2
GATE2000_2.25 top
select distinct w, x
from r, s
(a)
GATE2000_2.26 top
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?
Answer: C
GATE2001_2.23 top
R(A,B,C,D) is a relation. Which of the following does not have a lossless join, dependency preserving BCNF decomposition?
A. A → B, B → CD
B. A → B, B → C, C → D
C. AB → C, C → AD
D. A → BCD
(C) is the answer. Because of AB -> C and C -> A, we cannot have A, B and C together in any BCNF relation- in relation ABC, C is not a
super key and C->A exists violating BCNF condition. So, we cannot preserve AB -> C dependency in any decomposition of ABCD.
For (A) we can have AB, BCD, A and B the respective keys
For (B) we can have AB, BC, CD, A, B and C the respective keys
For (D) we can have ABCD, A is key
-- Arjun Suresh
GATE2002_1.19 top
Relation R with an associated set of functional dependencies, F, is decomposed into BCNF. The redundancy (arising out of functional
dependencies) in the resulting set of relations is
A. Zero
B. More than zero but less than that of an equivalent 3NF decomposition
C. Proportional to the size of F+
D. Indeterminate
Answer: A
If a relation schema is in BCNF then all redundancy based on functional dependency has been removed, although other types of redundancy
may still exist. A relational schema R is in Boyce–Codd normal form if and onlyif for every one of its dependencies X → Y, at least one of
the following conditions hold:
-- Priya_das
GATE2002_16 top
M → O, NO → P , P → L and L → MN
a) Yes as R1 ∩ R2 = M and M → O
b) NO
Mistake That CAN be made: Here we CANNOT apply Pseudo Transitivity Rule using M→O & MN →P to obtain NO → P because the
rule says :
But here we have M→O and MN→P ... SO we CANNOT apply the rule here to obtain NO→P from it.
c) BCNF
-- Danish
GATE2003_30 top
Select distinct a1 , a2 , … , an
from r1 , r2 , … , rm
where P
For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?
A. Πa 1 ,a 2 ,…a n σp (r1 × r2 × ⋯ × rm )
B. Πa ,a ,…a σp (r1 ⋈ r2 ⋈ ⋯ ⋈ rm )
1 2 n
C. Πa 1 ,a 2 ,…a n σp (r1 ∪ r2 ∪ ⋯ ∪ rm )
D. Πa 1 ,a 2 ,…a n σp (r1 ∩ r2 ∩ ⋯ ∩ rm )
select distinct in SQL is equivalent to project and by default relation 1, relation 2 in SQL corresponds to cross-product. So, option A.
-- Arjun Suresh
GATE2003_85 top
C. in BCNF
There are three FDs that are valid from the above set of FDs for the given relation :
clearly there is partial dependency here (Date_of_Birth -> Age) and Age is not a prime attribute. So it is only in 1NF.
Option (D).
-- Danish
GATE2004_13 top
Let R1 ( A , B, C, D) and R2 ( D , E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key inR1
−
− −−
referring to R2 . Suppose there is no violation of the above referential integrity constraint in the corresponding relation instancesr1 and r2 .
Which of the following relational algebra expressions would necessarily produce an empty relation?
A. ΠD (r2 ) − ΠC (r1 )
B. ΠC (r1 ) − ΠD (r2 )
C. ΠD (r1 ⋈ C≠ D r2 )
D. ΠC (r1 ⋈ C= D r2 )
ans (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.
-- Vicky Bajoria
GATE2004_14 top
where the primary keys are shown underlined. The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the
maximum and minimum number of tuples that can be present in (Student * Enroll), whew ‘*’ denotes natural join?
A. 8, 8
B. 120, 8
C. 960, 8
D. 960, 120
Rollno in students is key, ans students table has 120 tuples, In Enroll table rollno is FK referencing to Students table. in natural join it'll return
the records where the rollno value of enroll matches with the rollno of students so in both conditions min and max records will be resulted
(8,8).
hence A is the answer.
GATE2004_50 top
The relation scheme Student Performance (name, courseNo, rollNo, grade) has the following functional dependencies:
A. 2 NF
B. 3 NF
C. BCNF
D. 4 NF
If we proceed with given FDs then either Name,courseno or RollNo,courseNo becomes the candidate key. So no non-prime attributes are
partially dependent on any Key attributes. Hence 2NF test passed.
Again for 3rd and 4th FD, Name,roll are part of the key and for first 2 FDs, determinants are candidate key itself. So 3NF test passed but not
BCNF. Hence 3NF answer. b.
-- shreya ghosh
GATE2007_60 top
Consider the relation employee(name, sex, supervisorName) with name as the key, supervisorName gives the name of the supervisor of the
employee under consideration. What does the following Tuple Relational Calculus query produce?
A. Names of employees with a male supervisor.
B. Names of employees with no immediate male subordinates.
C. Names of employees with no immediate female subordinates.
D. Names of employees with a female supervisor.
Query is selecting e such that e is an employee and for all x, either x is not an employee or x's supervisor's name is not e.name or x is male.
So, this is equivalent to saying, select all employees who don't have an immediate female subordinate. (Assuming there is no transgender).
(C) option.
-- Arjun Suresh
GATE2007_62 top
(d)
The 3NF version of the definition is weaker than Date's BCNF variation, as the former is concerned only with ensuring thatnon-key attributes
are dependent on keys. Prime attributes (which are keys or parts of keys) must not be functionally dependent at all; they each represent a fact
about the key in the sense of providing part or all of the key itself. (It should be noted here that this rule applies only to functionally dependent
attributes, as applying it to all attributes would implicitly prohibit composite candidate keys, since each part of any such key would violate the
"whole key" clause.)
-- Aravind
Consider table R(A,B,C,D,E) with FDs as A->B, BC->E and ED-> A. The table is in which
normal form? Justify your answer. top
First step: Identify the candidate keys. Candidate keys must be able to determine all other attributes. Most of the time they can be found by
just looking at the FDs. Here,
Similarly in BC->E and ED->A, E and A are prime-attributes and hence both are not partial functional dependencies. Hence R is in 2NF.
Now 3NF states that every non-prime attribute must be dependent on the candidate key. In the given functional dependencies, all dependent
attributes are prime-attributes and hence it is trivially in 3NF.
Now BCNF requires that for every FD α− > β, α must be a super key (candidate key or its superset). This condition is violated by all the 3
FDs given and hence R is not in BCNF.
So, 3NF is the highest normal form table can be in.
-- gatecse
GATE2009_45 top
Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following queries on the database:
4.
Select R.a,R.b
From R,S
Where R.c = S.c
(A) 1 and 2
(B) 1 and 3
(C) 2 and 4
(D) 3 and 4
2. Expanding logically the statement means to select t (a,b) from r such that for all tuples u in s, there is a tuple v in r, such that u = v[S] and t =
v[R-S]. This is just equivalent to
(r/s)
3. Expanding logically the statement means that select t (a,b) from r such that for all tuples v in r, there is a tuple u in s, such that u = v[S] and t
= v[R-S]. This is equivalent to saying to select (a,b) values from r, where the c value is in (s/r), which will be true only if c in r is a foreign key
referring to c in s.
4. This selects (a,b) from all tuples from r which has an equivalent c value in s.
r
a b c
Arj TY 12
Arj TY 14
Cell TR 13
Tom TW 12
Ben TE 14
s
c
12
14
http://pages.cs.wisc.edu/~dbbook/openAccess/firstEdition/slides/pdfslides/mod3l1.pdf
-- Arjun Suresh
GATE2005_29 top
option c
-- Sankaranarayanan P.N
GATE2005_30 top
Let r be a relation instance with schema R = (A, B, C, D). We definer1 = πA,B,C (R) and r2 = πA,D (r). Let s = r1 ∗ r2 where ∗ denotes
natural join. Given that the decomposition of r into r1 and r2 is lossy, which one of the following is TRUE?
A. s ⊂ r
B. r ∪ s = r
C. r ⊂ s
D. r∗ s = s
Answer is C.
R
A B C D
1 2 3 3
1 5 3 4
R1
A B C
1 2 3
1 5 3
R2
A D
1 3
1 4
S = R1 * R2
A B C D
1 2 3 3
1 2 3 4
1 5 3 3
1 5 3 4
-- Vikrant Singh
GATE2005_75 top
Let E 1 and E 2 be two entities in an E/R diagram with simple-valued attributes. R1 and R2 are two relationships between E 1 and E 2 , where R1
is one-to-many and R2 is many-to-many. R1 and R2 do not have any attributes of their own. What is the minimum number of tables required to
represent this situation in the relational model?
A. 2
B. 3
C. 4
D. 5
one-to-many relation doesn't need a separate table and can be handled using a foreign key.
Ref: http://web.cse.ohio-state.edu/~gurari/course/cse670/cse670Ch9.xht
-- Arjun Suresh
GATE2005_76 top
The following table has two attributes A and C where A is the primary key and C is the foreign key referencing A with on-delete cascade.
A C
2 4
3 4
4 3
5 2
7 2
9 5
6 4
The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple (2, 4) is deleted is:
(c)
since deleting (2,4) , since 2 is a primary key, u have to delete its foreign key occurence i.e (5,2) and (7,2)
since we are delting 5 , and 7 we have delete it foreign key occurence i.e (9,5)
GATE2005_78 top
Consider a relation scheme R = (A, B, C, D, E, H) on which the following functional dependencies hold: {A→ B, BC → D, E → C, D → A}.
What are the candidate keys R?
A. AE, BE
B. AE, BE, DE
C. AEH, BEH, BCH
D. AEH, BEH, DEH
using the given functional dependencies and looking at the dependent attributes, E and H are not dependent on any. So, they must be part of
any candidate key. So, only option is D. If we see the FD's, adding A, B or D to EH do form candidate keys.
-- Aravind
GATE1999_2.25 top
(d)
GATE2013_54,55 top
Relation R has eight attributes ABCDEFGH. Fields of R contain only atomic values. F ={CH→G, A→BC, B→CFH, E→A, F→EG} is a set of
functional dependencies (FDs) so that F + is exactly the set of FDs that hold for R.
(D) in BCNF.
55) A.
as in F->G,G is non-prime attribute but F is a proper subset of a candidate key.so violates 2nf condition.hence R is in 1nf.
-- kalpashri
GATE1998_2.19 top
Which of the following query transformations (i.e., replacing the l.h.s. expression by the r.h.s expression) is incorrect? R1 and R2 are relations,
C 1 and C2 are selection conditions and A1 and A2 are attributes of R1.
A. σC 1 (σC 2 (R1 )) → σC 2 (σC 1 (R1 ))
D) if the selection condition is on attribute A2, then we cannot replace it by RHS as there will not be any attribute A2 due to projection of A1
only.
-- Shaun Patel
GATE2014-1_21 top
Consider the relation scheme R = (E, F , G, H, I, J, K, L, M, N) and the set of functional dependencies
(A) {E, F }
(B) {E, F , H}
(C) {E, F , H, K, L}
(D) {E}
hence it is key
-- Sankaranarayanan P.N
GATE2014-1_22 top
S1: A foreign key declaration can always be replaced by an equivalent check assertion in SQL.
S2: Given the table R(a, b, c) where a and b together form the primary key, the following is a valid table definition.
CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R)
S1: foreign key constraint means a lot of constraints it has to be a primary key(which intrun has few constraints)
foreign ken dfn: it should be a candidate key in some other table(in our case it is only a prime attribute)
GATE2006_70 top
The following functional dependencies are given:
AB → CD, AF → D, DE → F ,C → G, F → E, G → A
GATE2014-1_54 top
You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the
following query:
(D) It generates an error because of the GROUP BY clause cannot be used with table joins in a sub-query.
this inner query will give the max hire date of each department whose location_id =1700
and outer query will give the last name and hire-date of all those employees who joined on max hire date.
answer should come to (B) no errors
And we can use group by and where together, who said we can not :(
-- Manu Thakur
GATE2014-2_22 top
For (StudentName, StudentAge) to be a key for this instance, the value X should NOT be equal to______.
Since if it is equal the same key will have two different values which cannot be true by the definition of candidate/primary/super key.
-- Aravind
GATE2014-2_54 top
SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives
the same answer as the nested query shown below:
(A)
(B)
(C)
(D)
C)
Let R
A B C
1 2 3
1 2 3
7 8 9
7 8 9
Let S:-
A X Z
1 2 3
3 5 7
7 6 5
7 5 4
A B C
1 2 3
1 2 3
7 8 9
7 8 9
For Option,
∴ Output will be
A B C
1 2 3
1 2 3
7 8 9
7 8 9
7 8 9
7 8 9
B)
∵only Distinct R will be chosen in the end so , Output will look like
A B C
1 2 3
7 8 9
C) ANSWER
Multiplicity of tuples is maintained. ∵ Multiplicity of duplicate tuples will be distributed when there is a match between R.a and S.a and for that
match S.a’s value is repeated.
A B C
1 2 3
1 2 3
7 8 9
7 8 9
-- Kalpish Singhal
GATE2014-3_21 top
What is the optimized version of the relation algebra expression πA1 (πA2 (σF1 (σF2 (r)))), where A1, A2 are sets of attributes in r with A1 ⊂ A2 and F 1, F 2
are Boolean expressions based on the attributes in r?
since A1 is subset of A2 will get only A1 attributes as it is in th eoutside, so we can remove project A2
two selects with boolean expreassion can be combined into one select with and of two boolean expressions
-- Aravind
GATE2014-3_22 top
prime attribute is a constituent of a candidate key. it need not present in all candidate keys. hence option B is correct
GATE2014-3_30 top
Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee.
Assume that every employee has at least one associated dependent in the dependent relation.
The above query evaluates to the set ofempIds of employees whose age is greater than that of
The inner query selects the employees whose age is less than or equal to at least one of his dependents. So, subtracting from the set of
employees, gives employees whose age is greater than all of his dependents.
-- Arjun Suresh
GATE2014-3_54 top
employee(empId,empName,empDept)
customer(custId,custName,salesRepId,rating)
salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer.
What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
FROM customer C
WHERE C.salesRepId = E.empId
AND C.rating <> 'GOOD');
(A) Names of all the employees with at least one of their customers having a ‘GOOD’ rating.
(B) Names of all the employees with at most one of their customers having a 'GOOD' rating.
(C) Names of all the employees with none of their customers having a 'GOOD' rating.
(D) Names of all the employees with all their customers having a 'GOOD' rating.
(D)
so negation on the above stmt give -> "employees with all ratings as good"
GATE2011_32 top
Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record(X=1, Y=1) is
inserted in the table.
Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. UsingMX and MY ,
new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after
the insertion, values of MX and MY change.
What will be the output of the following SQL query after the steps mentioned above are carried out?
(A) 127
(B) 255
(C) 129
(D) 257
X = 1, Y = 1
X = 2, Y = 2*1 +1 = 3
X = 3, Y = 2*3 + 1 = 7
X = 4, Y = 2*7 + 1 = 15
X = 5, Y = 2*15 + 1 = 31
X = 6, Y = 2*31+1 = 63
X = 7, Y = 2*63 + 1 = 127
-- Arjun Suresh
GATE2011_46 top
SELECT count(*)
FROM (
SELECT Borrower, Bank_Manager FROM Loan_Records) AS S
NATURAL JOIN
(SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T
);
(A) 3
(B) 9
(C) 5
(D) 6
when we perform natural join on S and T then result will be like this
after that count (*) will count total tuples present in this table so here it is 5
-- neha pawar
GATE2010_19 top
Table: Passenger
pid pname Age
0 'Sachin' 65
1 'Rahul' 66
2 'Sourav' 67
3 'Anil' 69
Table: Reservation
pid class tid
0 'AC' 8200
1 'AC' 8201
2 'SC' 8201
5 'AC' 8203
1 'SC' 8204
3 'AC' 8202
What pids are returned by the following SQL query for the above instance of the tables?
SELECT pid
FROM Reservation
WHERE class='AC' AND
EXISTS (SELECT *
FROM Passenger
WHERE age>65 AND
Passenger.pid=Reservation.pid)
(A) 1, 0
(B) 1, 2
(C) 1, 3
(D) 1, 5
(c)1,3
the inner query gives passenger_id with age above 65 i.e. 1,2,3
the outer query chooses the class as AC, which are 1 and 3
-- Aravind
GATE1997_6.9 top
Ck is ab.
a->c(P->NP)
b->d(P->NP)
GATE1997_6.10 top
R
a Let(PK) b b
1
2
S
d(FK referring to PK of R) e f
2
1
Insert into S can cause violation if any value is inserted into d of S, which value is not in a of R.
Delete from R would cause violation if it any tuple is deleted,and as a result a value in a gets deleted which is refereed to by d in S.
Hence
d)Ans
-- Sourav Roy
GATE1993_14 top
Answer: 3
No. of first level index entries = No. of Data Blocks needed for data file = 2 K
No. of first level index blocks = ⌈ No. of first level index entries ⌉ = ⌈ 2K ⌉ = 64
Blocking factor of index file 32
No. of second level index entries = No. of first level index blocks = 64
No. of second level index blocks = ⌈ No. of second level index entries ⌉ = ⌈ 64 ⌉ = 2
Blocking factor of index file 32
No. of third level index entries = No. of second level index blocks = 2
No. of third level index blocks = ⌈ No. of third level index entries ⌉ = ⌈ 2
⌉ =1
Blocking factor of index file 32
-- Jon Snow
GATE2010_42 top
T1 T2 T3
Read(X)
Read(Y)
Read(Y)
Write(Y)
Write(X)
Write(X)
Read(X)
Write(X)
Which one of the schedules below is the correct serialization of the above?
(A) T1 → T3 → T2
(B) T2 → T1 → T3
(C) T 2 → T3 → T1
(D) T 3 → T1 → T2
You can use method of conflict serializability graph or precedence graph Ref: Elmasri Navathe. Then serialisation is T1 T3 T2
-- Sankaranarayanan P.N
GATE2010_43 top
The following functional dependencies hold for relations R(A, B, C) and S(B, D, E).
B→A
A→C
The relation R contains 200 tuples and the relation S contains 100 tuples. What is the maximum number of tuples possible in the natural join
R ⋈ S?
(A) 100
(B) 200
(C) 300
(D) 2000
(A) 100
natural join will combine tuples with same value of the common rows(if there are two common rows then both vaues must be equal to get into
the resultant set). So by this defn: we can get at the max only 100 common values :P
-- Aravind
Information about a collection of students is given by the relationstudInfo(studId, name, sex). The relation enroll(studId, courseId ) gives
−−−−− −−−−− −−−−−−−
which student has enrolled for (or taken) what course(s). Assume that every course is taken by at least one male and at least one female
student. What does the following relational algebra expression represent?
What the cartesian product actually doing is, it taking the studentId of "female" student from studInfo relation, and performing the cartesian
product with all courses that are available... so it will return the all possible combination of "female" student can enroll in various courses.. Now
finally we are subtracting "enroll" from it.. "enroll" relation contain what actually enrollment has been done.. so the substraction will return the
"courseId" a "female student has not been enrolled..!!
because, ( all possible enrollment in various course of female) - ( actual enrollment) = courses in which female enrollment has not
happened!!...
Option (b) is saying "female student which are enrolled (proper Subset)".. No but it is returning courses in which female student are NOT
enrolled!!.. so option (D)
-- Vicky Bajoria
GATE1994_3.7 top
An instance of a relational scheme R(A, B, C) has distinct values for attribute A. Can you conclude that A is a candidate key for R?
No.
A B C
1 5 6
2 4 7
3 4 5
Now we may see that A->BC holds for this instance ,hence A+={ABC}.
But FD s are defined on the schema itself not the instance, so based on the state of the instance we cannot say what holds for schema (there
can be a many instances for R).
-- Sourav Roy
GATE1995_26 top
Consider the relation scheme R(A, B, C) with the following functional dependencies:
A, B → C,
C→A
None of the given functional dependencies are partial. So, the scheme qualifies for 2 NF.
All determinants are not Candidate Keys. So, the scheme do not qualify for BCNF.
-- Jon Snow
GATE1995_27 top
and publisher.pcity='Madras';
-- Manu Thakur
GATE1996_27 top
Explain in one English sentence, what each of the following relational algebra queries is designed to determine
(a) Select the (user# and) titles of the books issued to User# 6
(b) Select author names of the books issued to users whose home town is Delhi
-- Arjun Suresh
X Y Z
2 8 4
2 10 6
2 12 6
6 4 4
A)XY → Z, Z → Y
B)YZ → X, Y → Z
C)YZ → X, X → Z
D)XZ → Y, Y → X
Z-> Y is not satisfied as when Z = 4, Y has values 8 as well as 4. So, (A) is False.
YZ and Y are unique and hence FDs in (B) are trivially satisfied.
X->Z is not satisfied as when X=2, Z can have 4 as well as 6. So, (C) is false.
XZ -> Y is not satisfied as when XZ = {2,6}, Y can have 10 as well as 12. So, D is false.
-- Arjun Suresh
A relation R with 5 attributes A1, A2, A3, A4, A5. Given the following FDs
A1 → A2
A2A3 → A5
A4A5 → A1
Find the number of candidates keys that includes attribute A3
A4 and A3 are not coming on the RHS of any FD. So, they must be in all candidate keys.
Consider A4A5, due to A4A5 -> A1 and A1-> A2, A4A5 determines {A1 A2 A4 A5}, and hence A3A4A5 is a candidate key.
Similarly, A2A3A4 and A1A3A4 are candidate keys.
GATE2008-IT_61 top
Option A.
(A,B) (B,C) -> common attribute is B and due to B->C, B is a key for (B,C) and hence ABC can be losslessly decomposed into (A,B) and (B,C).
(A, B, C) (B, D), common attribute is B and B->D is a FD (via B->C, C->D), and hence B is a key for (B, D). So, decomposition of (A, B, C, D)
into (A, B, C) (B, D) is lossless.
The given decomposition is also dependency preserving as the dependencies A->B is is present in (A, B), B->C is present in (B, C), D->B is
present in (B, D) and C->D is indirectly present via C->B in (B, C) and B->D in (B, D).
http://www.sztaki.hu/~fodroczi/dbs/dep-pres-own.pdf
-- Arjun Suresh
GATE2008-IT_62 top
Let R (A, B, C, D, E, P, G) be a relational schema in which the following functional dependencies are known to hold: AB → CD, DE → P, C →
E, P → C and B → G. The relational schema R is
1) in BCNF
2) in 3NF, but not in BCNF
3) in 2NF, but not in 3NF
4) not in 2NF
Answer: D
Here AB is the candidate key and B->G is a partial dependency. So, R is not in 2 NF.
-- Jon Snow
GATE2008-IT_74 top
1) for each school with more than 200 students appearing in exams, the name of the school and the number of 100s scored by its students
2) for each school with more than 200 students in it, the name of the school and the number of 100s scored by its students
3) for each school with more than 200 students in it, the name of the school and the number of its students scoring 100 in at least one exam
4) nothing; the query has a syntax error
D:
If Select clause consist aggregate and non - aggregate columns.All non aggregate columns in the Select clause must appear in Group By
clause. But in this query Group by clause consists school-id instead of school-name
http://weblogs.sqlteam.com/jeffs/archive/2007/07/20/but-why-must-that-column-be-contained-in-an-aggregate.aspx
-- erravi90
GATE2007-IT_68 top
Let branch, account and depositor be respectively instances of the above schemas. Assume that account and depositor relations are much
bigger than the branch relation.
Which one of the following queries is the most efficient version of the above query ?
It should be A. As in B we are doing a join between two massive table whereas in A we are doing join between relatively smaller table and
larger one and the output that this inner table gives(which is smaller in comparison to joins that we are doing in B) is used for join with
depositer table with the selection condition.
-- Shaun Patel
GATE2006-IT_14 top
Consider the relations r1(P, Q, R) and r2(R, S, T) with primary keys P and R respectively. The relation r1 contains 2000 tuples and r2 contains
2500 tuples. The maximum size of the join r1⋈ r2 is :
A) 2000
B) 2500
C) 4500
D) 5000
the common attribute is R and it is primary key in the second relation. hence the R value is distinct for 2500 rows. hence when we join max
possible number of tuples is 2000
option A
-- Sankaranarayanan P.N
GATE2006-IT_84 top
Consider a database with three relation instances shown below. The primary keys for the Drivers and Cars relation aredid and cid respectively
and the records are stored in ascending order of these primary keys as given in the tables. No indexing is available in the database.
D: Drivers relation
did dname rating age
22 Karthikeyan 7 25
29 Salman 1 33
31 Boris 8 55
32 Amoldt 8 25
58 Schumacher 10 35
64 Sachin 7 35
71 Senna 10 16
74 Sachin 9 35
85 Rahul 3 25
95 Ralph 3 53
R: Reserves relation
did cid day
22 101 10/10/06
22 102 10/10/06
22 103 08/10/06
22 104 07/10/06
31 102 10/11/06
31 103 06/11/06
31 104 12/11/06
64 101 05/09/06
64 102 08/09/06
74 103 08/09/06
C: cars relation
cid cname colour
101 Renault blue
102 Renault red
103 Ferrari green
104 Jaguar red
select D.dname
from Drivers D
where D.did in (
select R.did
from Cars C, Reserves R
where R.cid = C.cid and C.colour = 'red'
intersect
select R.did
from Cars C, Reserves R
where R.cid = C.cid and C.colour = 'green'
)
A) Karthikeyan, Boris
B) Sachin, Salman
C) Karthikeyan, Boris, Sachin
D) Schumacher, Senna
For color = "Red"
Ans: A
-- Vikrant Singh
GATE2004-IT_21 top
Which level of locking provides the highest degree of concurrency in a relational database ?
A) Page
B) Table
C) Row
D) Page, table and row level locking allow the same degree of concurrency
row level locking provides more concurrency. because different transactions can access different rows in a table / page at same time
-- Sankaranarayanan P.N
GATE2004-IT_74 top
A relational database contains two tables student and department in which student table has columns roll_no, name and dept_id and
department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty
tables:
Insert into department values (1, 'Mathematics')
Insert into department values (2, 'Physics')
Insert into student values (l, 'Navin', 1)
Insert into student values (2, 'Mukesh', 2)
Insert into student values (3, 'Gita', 1)
How many rows and columns will be retrieved by the following SQL statement?
since there is no specific joining condition specified it will retrieve cartesian product of the table
answer: D
-- Sankaranarayanan P.N
GATE2004-IT_75 top
A relation Empdtl is defined with attributes empcode (unique), name, street, city, state and pincode. For any pincode, there is only one city and
state. Also, for any given street, city and state, there is just one pincode. In normalization terms, Empdtl is a relation in
A. 1NF only
B. 2NF and hence also in 1NF
C. 3NF and hence also in 2NF and 1NF
D. BCNF and hence also in 3NF, 2NF an 1NF
its in 2nf - for 2nf all non prime attribute should be fully functionally dependent on key. here key is empcode. key contains only one attribute
hence. no partial dependency. but there is transitive dependency in this. so it is not in 3 NF
answer: B
-- Sankaranarayanan P.N
GATE2004-IT_76 top
The following sequence of SQL statements was successfully executed on table T1.
A. 18.75
B. 20
C. 25
D. Null
Update on null gives null. Now, avg function ignores null values. So, here avg will be (15 + 25 + 35) / 3 = 25.
http://msdn.microsoft.com/en-us/library/ms177677.aspx
-- Arjun Suresh
GATE2004-IT_78 top
Consider two tables in a relational database with columns and rows as follows:
Table: Student
Roll_no Name Dept_id
1 ABC 1
2 DEF 1
3 GHI 2
4 JKL 3
Table: Department
Dept_id Dept_name
1 A
2 B
3 C
Dept_id Dept_name
Roll_no is the primary key of the Student table, Dept_id is the primary key of the Department table and Student.Dept_id is a foreign key from
Department.Dept_id
What will happen if we try to execute the following two SQL statements?
ans is C
here in (i) when we update in STUDENT table dept id =NULL then it will not cause any problem to referenced table
but in (II) if we set in DEPARTMENT table dept id =NULL then it will produce inconsistency because in STUDENT table we still have the
tuples containing the dept id =1
-- neha pawar
GATE2005-IT_21 top
Consider the entities 'hotel room', and 'person' with a many to many relationship 'lodging' as shown below:
If we wish to store information about the rent payment to be made by person (s) occupying different hotel rooms, then this information should
appear as an attribute of
A) Person
B) Hotel Room
C) Lodging
D) None of these
since it is many to many. rent cannot be an attribute of room or person entities alone. if depending on number of persons sharing a room the
rent for each person for the room will be different. otherwise rent can be attribute of room. hence i go for attribute of Lodging
-- Sankaranarayanan P.N
GATE2005-IT_22 top
A table has fields Fl, F2, F3, F4, F5 with the following functional dependencies
F1 → F3 F2→ F4 (F1 . F2) → F5
In terms of Normalization, this table is in
1) 1 NF
2) 2 NF
3) 3 NF
4) None of these
ans : 1
key is f1f2
Amongst the ACID properties of a transaction, the 'Durability' property requires that the changes made to the database by a successful
transaction persist
answer d. irrespective of any failure the successful result of transaction should persist.
then when we are going to board the train on that time they tells because of system/disk/power crash they dont have your seat information
and you are not allowed in the seat
GATE2005-IT_67 top
A company maintains records of sales made by its salespersons and pays them commission based on each individual's total sales made in a
year. This data is maintained in a table with following schema:
In a certain year, due to better business results, the company decides to further reward its salespersons by enhancing the commission paid to
them as per the following formula:
The IT staff has written three different SQL scripts to calculate enhancement for each slab, each of these scripts is to run as a separate
transaction as follows:
Update salesinfo
T1 Set commission = commission * 1.02
Where commission < = 50000;
Update salesinfo
T2 Set commission = commission * 1.04
Where commission > 50000 and commission is < = 100000;
Update salesinfo
T3 Set commission = commission * 1.06
Where commission > 100000;
Which of the following options of running these transactions will update the commission of all salespersons correctly
so he wil get increment two times. but he is eligible for only one slab of commision
-- Sankaranarayanan P.N
GATE2005-IT_68 top
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown
below:
Table: Student
Roll Name Hostel Marks
1798 Manoj Rathod 7 95
2154 Soumic Banerjee 5 68
2369 Gumma Reddy 7 86
2581 Pradeep Pendse 6 92
Table: hobby
Roll Hobbyname
1798 chess
1798 music
2154 music
2369 swimming
2581 cricket
2643 chess
2643 hockey
2711 volleyball
2872 football
2926 cricket
2959 photography
3125 music
3125 chess
select hostel
from student natural join hobby
where marks > = 75 and roll between 2000 and 3000;
Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S’ is
obtained by the following relational algebra operation:
S’ = ∏hostel ((σ s.roll = H.roll (σmarks > 75 and roll > 2000 and roll < 3000 (S)) X (H))
The difference between the number of rows output by the SQL statement and the number of tuples in S’ is
A) 6
B) 4
C) 2
D) 0
Roll Hostel
2369 7
2581 6
2643 5
5 Duplicate Row is present in
2643
Hobby table
2872 5
2926 5
2959 7
Answer is B
-- Vikrant Singh
GATE2005-IT_70 top
In a schema with attributes A, B, C, D and E following set of functional dependencies are given
A→B
A→C
CD → E
B→D
E→A
Which of the following functional dependencies is NOT implied by the above set?
A) CD → AC
B) BD → CD
C) BC → CD
D) AC → BC
Answer is B.
1.) CD-->AC
CD+ = CDEAB
2.) BD-->CD
BD+ = BD
-- Gate Keeda
GATE2005-IT_82a top
A database table T1 has 2000 records and occupies 80 disk blocks. Another table T2 has 400 records and occupies 20 disk blocks. These two
tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The
memory buffer space available can hold exactly one block of records for T1 and one block of records for T2 simultaneously at any point in time.
No index is available on either table.
If Nested-loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of
block accesses required for reading the data are
A) 800000
B) 40080
C) 32020
D) 100
Refer : http://en.wikipedia.org/wiki/Nested_loop_join
as per this reference This algorithm will involve n r*bs + br block transfers
either T1 can be R or T2
-- Sankaranarayanan P.N
GATE2005-IT_82b top
A database table T1 has 2000 records and occupies 80 disk blocks. Another table T2 has 400 records and occupies 20 disk blocks. These two
tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The
memory buffer space available can hold exactly one block of records for T1 and one block of records for T2 simultaneously at any point in time.
No index is available on either table.
If, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in
number of block accesses required for reading the data will be
A) 0
B) 30400
C) 38400
D) 798400
In Nested loop join for each tuple in first table we scan through all the tuples in second table.
Here we will take table T2 as the outer table in nested loop join algorithm. The number of block accesses then will be 20 + (400 × 80) = 32020
In block nested loop join we keep 1 block of T1 in memory and 1 block of T2 in memory and do join on tuples.
For every block in T1 we need to load all blocks of T2. So number of block accesses is 80*20 + 20 = 1620
-- Omesh Pandita
SO , A weak entity is an entity that cannot be uniquely identified by its attributes alone . Does it mean it has duplicates and it always a multi-set ?
Weak entity normally can be identified in connection with strong entity also . They are connected by an identifying relation. But it does not
mean that it should always have duplicates . it need not be always multi set
-- Sankaranarayanan P.N
Explain top
Ans is B:
here, inner query will retrive all students who have enrolled for the course with less than 5 credits. after join operation we are retriving SID of
all those students.
now, difference operator will return all SID which are in student relation but not in the result that we can from inner query. therefore it will
return all the SID of students who have enrolled for courses with credit greater than 5.
while performing set difference operator if any student has enrolled for any subject with less than 5 credit will be removed.
-- jayendra
Consider the following transactions with data items P and Q initialized to zero:
Ans is (B): explanation: T1:r(P),r(Q),w(Q) T2:r(Q),r(P),w(P) now consider any non serial schedule for example,
S:r1(P),r2(Q),r1(Q),r2(P),w1(Q),w2(P) now draw a precedence graph for this schedule. here there is a conflict from T1->T2 and there is a
conflict from T2->T1 therefore, the graph will contain a cycle. so we can say that the schedule is not conflict serializable.
-- jayendra
A relational table EMP(ENO(PK), EName, Dept) has 88 number of tubples. What will be the
result of following SQL Statement? top
Where E_no not in NULL - the predicate evaluates to unknown. so no rows will be printed.
-- shreya ghosh
GATE2015-2_1 top
The constraint that the sum of the accounts x and y should remain constant is that of
A. Atomicity
B. Consistency
C. Isolation
D. Durability
Kindly check out PPT for Transaction chapter in below link.( Part 5: Transaction Management Ch. 15)
http://www.cse.iitb.ac.in/~sudarsha/db-book/slide-dir/
Question is directly taken from Korth. And wording almost completely matches to Consistency requirement.
-- kshirsagar1992
GATE2015-2_6 top
With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the Root node) that must be fetched in
order to satisfy the following query. "Get all records with a search key greater than or equal to 7 and less than 15" is ______.
(9)-->(5)-->(5,7)-->(9,11)-->(13,15).
-- Gate Keeda
GATE2015-1_7 top
option D is correct because SELECT operation in SQL is equivalent to The projection operation in relational algebra, except
that SELECT in SQL retains duplicates but projection gives only distinct
-- Anoop Sonkar
GATE2015-1_24 top
A file is organized so that the ordering of the data records is the same as or close to the ordering of data entries in some index. Than that index
is called
A. Dense
B. Sparse
C. Clustered
D. Unclustered
Clustered- this is the definition of clustered indexing and for the same reason a table can have only one clustered index.
http://www.ece.rutgers.edu/~yyzhang/spring03/notes/7-B+tree.ppt
-- Arjun Suresh
GATE2015-1_27 top
Student
Performance
The numbers of rows that will be returned by the SQL query is_________________.
GATE2015-2_46 top
Consider a simple checkpointing protocol and the following set of operations in the log.
(start, T4); (write, T4, y, 2, 3); (start, T1); (commit, T4); (write, T1, z, 5, 7);
(checkpoint);
(start, T2); (write, T2, x, 1, 9); (commit, T2); (start, T3); (write, T3, z, 7, 2);
If a crash happens now and the system tries to recover using both undo and redo operations, what are the contents of the undo list and the
redo list?
T1 T2 T3 T4
start
W(y,2,3)
start
commit
W(z,5,7)
Checkpoint Checkpoint Checkpoint Checkpoint
start
W(x,1,9)
commit
start
W(z,7,2)
crash crash crash crash
Now from the table we can find , T1 and T3 has uncommitted write operation , so they must be undone. and even though T2 has committed
after writing , but it is after checkpoint. So , it needs to be redone. So answer is A.
-- Shounak Kundu
GATE2015-3_3 top
Which of the following options will be needed at the end of the SQL query
SELECT P1.address
FROM Cinema P1
such that it always finds the addresses of theaters with maximum capacity?
A is the answer
B - Returns the addresses of all theaters except the one with the min capacity
C - Returns null set. max() returns a single value and there won't be any value > max.
D - Returns null set. Same reason as C. All and ANY works the same here as max returns a single value.
-- Arjun Suresh
GATE2015-3_20 top
Consider the relation X(P , Q, R, S, T , U) with the following set of functional dependencies
F ={
{P , R} → {S, T }
{P , S, U} → {Q, R}
}
Which of the following is the trivial functional dependency inF + , where F + is closure to F?
A. {P , R} → {S, T }
B. {P , R} → {R, T }
C. {P , S} → {S}
D. {P , S, U} → {Q}
-- Anoop Sonkar
GATE2015-3_29 top
Consider the partial Schedule S involving two transactions T 1 and T 2 . Only the read and the write operations have been shown. The read
operation on data item P is denoted by read(P) and write operation on data item P is denoted by write(P) .
Schedule S
Transaction id
Time Instance
T1 T2
1 read(A)
2 write(A)
3 read(C)
4 write(C)
5 read(B)
6 write(B)
7 read(A)
8 commit
9 read(B)
Suppose that the transaction T 1 fails immediately after time instance 9. Which of the following statements is correct?
A. T 2 must be aborted and then both T 1 and T 2 must be re-started to ensure transaction atomicity
B. Schedule S is non-recoverable and cannot ensure transaction atomicity
C. Only T 2 must be aborted and then re-started to ensure transaction atomicity
D. Schedule S is recoverable and can ensure transaction atomicity and nothing else needs to be done
Why A is not correct because it says abort transaction T2 and then redo all the operations .
But is there a gaurantee that it will succed this time ??(no maybe again T1 will fail). .
now as to why b is correct because as the other answer points out it is by definition an irrecoverable schedule now even if we start to undo the actions
on by one(after t1 fails) in order to ensure transaction atomicity. Still we cannot undo a commited transaction. hence this schedule is unrecoverable by
definition and also not atomic since it leaves the data base in an inconsistent state.
-- Tamojit Chatterjee
GATE2015-3_46 top
Consider a B+ tree in which the search key is 12 bytes long, block size is 1024 bytes, recorder pointer is 10 bytes long and the block pointer is
8 byte long. The maximum number of keys that can be accommodated in each non-leaf node of the tree is ______.
(n-1)12 + n*8<=1024
n<=51
=51-1=50
-- ppm
SQL top
Which of following query finds all the professors who have not offices in any of those buildings that professor Piper has offices in
A.
Select distinct P.profname from professor P Where not exists (( Select building from department d where P.deptname= D.deptname ) Union (Select building from department D1, professor P1 Wh
B.
C)
From professor P
D) None of these
Option B is correct, even though it has NOT EXISTS, it checks whether set of the building(s) belonging to the "current" professor (in the outer query) has any intersection with
the set of building(s) belonging to Prof. Piper, and if they intersect, we shouldn't take the current professor, otherwise yes. This is ensured by the NOT EXISTS clause that is
dependent on the outer query this time.
-- spriti1991
r={a,b,c,d,e}
a->b
bc-> e
ed -> a
So all attributes are prime attributes and it is in 3 NF.. but not in BCNF as any of the determinants is not super keys (even one is sufficient to
disprove BCNF Condition).
-- Digvijay Pandey
Theory of Computation top
GATE2012_12 top
What is the complement of the language accepted by the NFA shown below?
Assume Σ = {a} and ϵ is the empty string.
(A) ϕ
(B) {ϵ}
(C) a∗
(D) {a, ϵ}
A is Turing recognizable if TM for A, say TA outputs "yes" for "yes" cases of A- i.e.; when M accepts at most 2 distinct inputs. But M can loop
forever without accepting more than 2 distinct inputs and we can never be sure if it will or will not accept any more input. Thus, TA may not
output "yes" for "yes" cases of the language and hence A is not Turing recognizable.
Similarly, B is Turing recognizable if TM for B, say TB outputs "yes" for "yes" cases of B- i.e.; when M accepts more than 2 distinct inputs. If M
is accepting more than 2 distinct inputs, it's possible to enumerate all strings from the language (strings of length 1 followed by strings of
length 2 and so on ) and feed to M. (We should use [ dovetailing][1] technique so that even if some string causes TM to loop forever, we can
continue progress). If M is accepting more than 2 distinct inputs we are sure that we'll encounter those strings after some finite moves of the
TM. Thus TB can always output "yes" for "yes" cases of the language and hence B is Turing recognizable.
(It's easier to see that A and B are complement to each other. TM can say "yes" for "yes" cases of B means it can say "no" for "no" cases of A.
But to make A Turing recognizable we need the output "yes" for "yes" cases of A, which is not the case here. )
(Once we prove that B is Turing recognizable but not Turing acceptable (recursive), there is no need to check for A. The complement of a
Turing recognizable but not Turing acceptable language is always not Turing recognizable.)
[1]: http://www.xamuel.com/dovetailing/
-- Arjun Suresh
L= {| L(M) = Σ*} top
A. L is RE but L ′ is not RE
C. L is not RE but L ′ is RE
Yes. Both L and L' are not RE. We can have the same reduction as done for L(M) is infinite.
Lets assume L is RE. So, we have a TM N which will say "yes" if given an encoding of a TM whose language isΣ ∗ . Now using N we try to
solve non-halting problem as follows:
A non halting problem is given as follows: Given an encoding of TM <H> and a word w, whether H does not halt on w. That is, we have to
decide if H does not halt on w. This problem is proved to be not RE and so no TM can not even say "yes" for "yes" case of the problem.
Now, given a halting problem (<H>, w), we proceed as follows: We make a new TM say A, which on input x, just simulates H on w for |x|
steps. If H halts on w, A goes to reject state. Otherwise it accepts. So, L(A) = Σ ∗ if H does not halt on w and L(A) = a finite set if H halts on
w. (If H halts in |x| steps for w, any string with length greater than |w|, would certainly be not in L, making L a finite set and hence can never
equal Σ ∗ ).
Now, we just give the encoding of A to our assumed TM N. If N says "accept", we have that L(A) isΣ ∗ => H does not halt on w => we solved
"yes" case of not halting problem, which is not possible. Hence, our initial assumption of L is RE is false. L is not RE.
L(M) is not equal to Σ ∗ is a non-monotonic property of TM. Because we can take TMTyes with L(Tyes ) = ϕ and Tno with L(Tno ) = Σ ∗. Here,
Tyes satisfies the property (of being not being equal toΣ ∗ ) and Tno does not satisfy that property and L(Tyes ) ⊂ L(Tno ), making this a non-
monotonic property of TM. And hence this becomes not RE as per Rice's theorem second part.
So, both L and L' are not RE making (D) the correct answer.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- gatecse
GATE2003_15 top
If the strings of a language L can be effectively enumerated in lexicographic (i.e., alphabetic) order, which of the following statements is true ?
(A) L is Regular
Answer is (c)- L is recursive but not necessarily Regular or not even context-free.
Since, the strings of L can be enumerated it means L is recursively enumerable. That is we have a TM which accepts all strings in L. Now, to
be recursive the TM should reject all strings not in L. Since, the strings of the language can be enumerated in lexicographic order, it's easy to
do this. For any word w , if we see a word in the enumeration which is lexicographically higher thanw but no w , it means w is not in the
language. This makes L '''recursive'''.
L = {an b n c n | n ≥ 0}
The strings of this language can be enumerated in lexicographic order. But we know L is not context free as no PDA can accept L.
-- Arjun Suresh
To say P=NP top
To say P=NP which one of the following is sufficient? (All reductions in polynomial time)
Option B is the most correct answer. (To know why it is not THE correct answer read the tail section of this answer)
A problem p in NP is NP-complete if every other problem in NP can be transformed intop in polynomial time. They have another property
that given a problem in NP and a solution, we can verify deterministically in polynomial time that the solution is indeed a valid solution or not.
P represents the class of all problems whose solution can be found in polynomial time.
This implies that all problems in NP are solvable in polynomial time. (1)
Tail
The statement of option B is incomplete. It is not enought to say that that reduction of NPC problem to a problem in P, but the reduction
should be polynomial reduction or karp reduction.
The statement which implies P=NP would be There exist a polynomial time reduction of a problem in NPC to a problem in P. The
answer is partially correct because when we say reduction, we usually mean polynomial time reduction, but neverthless it doesnt hurt to be
precise.
-- NitHish Divakar
Let L be a regular language and w be a string in L . If w can be split into x, y and z such that |xy| ≤ number of states in the minimal DFA forL ,
and |y| > 0 then,
(A) ∀i ∈ N, xy i z ∉ L
(B) ∃i ∈ N, xy i z ∈ L
(C) ∀i ∈ N, xy i z ∈ L
(D) ∃i ∈ N, xy i z ∉ L
(C) ∀i ∈ N, xy i z ∈ L
1. Myhill-Nerode theorem
2. Pumping lemma
3. Drawing an NFA
4. Forming a regular expression
(A) All of these
As from the given options, Myhill-Nerode theorem is useful by providing necessary and sufficient condition for proving that a language regular.
Pumping lemma is often used to prove that a language is non-regular. Drawing an NFA can be useful to prove a language is regular. Forming
a regular expression can also help us prove if it is a regular language
-- Keith Kr
GATE2003_54 top
Define languages L0 and L1 as follows :
Both L and L ʼ are undecidable and not even semi-decidable (not recursively-enumerable). Because halting problem can be solved with both
L and Lʼ.
Halting problem can be stated as follows: A machine M and a word w are given. You have to tell, if M halts on w .
So, to solve halting problem < M, w > using L , just give < M, w, 0 > and < M, w, 1 > to two instances of T which is the assumed Turing
machine for L . If T accepts the triplet < M, w, 0 > , it means M halts on w => we have solved halting problem. If T accepts the triplet
< M, w, 1 > , it means M doesn't halt on w => we have solved halting problem. We know that either< M, w, 0 > or < M, w, 1 > is in L. So,
i f L is recursively enumerable, T is bound to stop on at least one of these inputs T
( M for a recursively enumerable language stops and
accepts, when provided with a word in its language).
Hence, if L is recursively enumerable we can solve halting problem => L is not recursively enumerable.
Similarly, we can also show that halting problem can be solved with L ʼ.
GATE1999_1.6 top
Let L1 be the set of all languages accepted by a PDA by final state and L2 the set of all languages accepted by empty stack. Which of the
following is true?
A) L1 = L2
B) L1 ⊃ L2
C) L1 ⊂ L2
D) None
There are two modes of acceptance of DPDA - final state and empty stack. For languages accepted by empty stack there is a prefix property.
Explain in simple terms about this property and its importance.
The set of languages accepted by a DPDA by empty stack is a strict subset of the set of languages accepted by a DPDA by final
state.
It can also be said that set of languages accepted by a DPDA by empty stack is the set of languages accepted by a DPDA by final state and
which has the prefix property.
From the above definition of prefix property it must be clear why DPDA by empty stack has this property. If any prefix of a word w (w in L) is in
L means the stack should have been empty even before completely processing w . But, being a deterministic PDA, once the stack becomes
empty, the DPDA accepts and halts. So, in no way can a DPDA accepts w and its prefix.
-- gatecse
GATE2008_10 top
A. I and II
B. I and IV
C. II and III
D. II and IV
(1) Intersection of two regular languages is regular. And checking if a regular language is infinite is decidable.
(2) Undecidable
(3) Undecidable
(4) Decidable as we just have to check if the grammar obeys the rules of CFG. (Obviously undecidable had it been language instead of
grammar)
Reference: http://gatecse.in/wiki/Grammar:_Decidable_and_Undecidable_Problems
-- gatecse
GATE2008_13 top
A. regular
B. context-free
C. context-sensitive
D. recursive
(D) recursive
L is recursively enumerable means a T M accepts all strings in L. L̄ is recursively enumerable means a T M accepts all strings in L̄ . So, we
can always decide if a string is in L or not, making L recursive.
http://books.google.co.in/books?
id=hsxDiWvVdBcC&pg=PA283&lpg=PA283&dq=if+l+and+l+are+recursively+enumerable+then+l+is+recursive&source=bl&ots=rdEqRfUndV&sig=1dglP3QL4
-- Keith Kr
GATE2008_48 top
B. Every non-deterministic Turing machine can be converted to an equivalent deterministic Turing machine
GATE2008_52 top
Match the following NFAs with the regular expressions they correspond to
2. ϵ + 0(10∗ 1 + 00)∗ 0
3. ϵ + 0(10∗ 1 + 10)∗ 1
GATE2008_53 top
I. {an b 2m ∣ n ≥ 0, m ≥ 0}
II. {an b m ∣ n = 2m }
III. {an b m ∣ n ≠ m}
A. I and IV only
B. I and III only
C. I only
D. IV only
Answer is A.
Since in option 2 and 3, n is dependent on m, therefore a comparison has to be done to evaluate those and hence are not regular.
GATE1991_03,xiii top
ans is A and C
a) L(S) L(R) : string generated by S is any numbers of 1's followed by one 0 ,i.e 10,110,1110,1110,,,,. string generated by R is 1 followed by
any combination of 0 or 1,i.e 1,10,11,1110,101,110...... it shows that all the strings that can be generated by S ,can also be
generated by R it means L(S) L(R) is true.
L(S) L(T): here string generated by T is any numbers of 1(here 1* means we have strings as ,1,11,111,....) followed by only one 0,i.e
0,10,110,1110..... ..so we can see that all the strings that are present in S can also be generated by T,hence L(S) L ( T )
it shows that option A is true
b) L(R) L(S):it is false because string 1 which can be generated by L(R), cannot be generated by L(S)
C) same as option A
d)L(T) L(S): it is false because string 0 which can be generated by T,cannot be generated by L(S).
-- neha pawar
GATE1991_03,xiv top
03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(b), (c) and (d) are true. But the strongest answer would be (d) a regular language. It is trivial to say that a finite set of strings (finite language)
can be accepted using a finite set of states. And regular language context-free context-sensitive Turing recognizable, would imply that
regular language is the strongest answer.
-- gatecse
GATE1992_02,xvii top
02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(a) r(∗ ) = r∗
(c) (r + s)∗ = r∗ + s∗
(d) r∗ s∗ = r∗ + s∗
(b) RHS generates Σ ∗ while LHS can't generate strings where r comes after s like sr, srr etc. LHS ⊂ RHS.
(c) LHS generates Σ ∗ while RHS can't generate strings where r comes after an s. RHS ⊂ LHS.
(d) LHS contains all strings where after an s, no r comes. RHS contains all strings of either r or s but no combination of them. So, RHS ⊂
LHS.
-- Arjun Suresh
GATE2000_1.4 top
Let S and T be languages 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 = ϕ
A. L = 0+
B. L is regular but not 0+
C. L is context free but not regular
D. L is not context free
GATE2001_1.4 top
S1 : {0 2n ∣ n ≥ 1} is a regular language
Only s1 is correct a dfa with 2 states where one of the states is both the initial and final state..
-- Bhagirathi Nayak
GATE2001_1.5 top
(A) If a language is context free it can always be accepted by a deterministic push-down automaton
Answer is (B)
(A) is wrong as a language can be context free even if it is being accepted by non deterministic PDA for ex- { WWr: W ∈ ∑*(a,b) and Wr is
reverse}
(C) and (D) not always true as Context free languages are not closed under Complement and Intersection.
-- Prateeksha Keshari
GATE2001_2.5 top
Consider a DFA over Σ = {a, b} accepting all strings which have number of a's divisible by 6 and number of b's divisible by 8. What is the
minimum number of states that the DFA will have?
(A) 8
(B) 14
(C) 15
(D) 48
Answer is D. It can be proved using Myhill Nerode theorem. We need a separate state for #a mod 6 = 0..5 and #b = 0..7. Each combination of
them must also be a new state giving 6*8 = 48 minimum states required in the DFA.
http://courses.cs.washington.edu/courses/cse322/05wi/handouts/MyhillNerode.pdf
-- Arjun Suresh
GATE2001_2.7 top
Given a Turing machine M over the input alphabet Σ , any state q of M and a word w ∈ Σ ∗ , does the computation of M on w visit the state of q?
A. X is decidable
B. X is undecidable but partially decidable
C. X is undecidable and not even partially decidable
D. X is not a decision problem
We have the TM M. Just make the state q the final state and make all other final states non-final and get a new TM M'. Give input w to M'. If w
would have taken M to state q (yes case of the problem), our new TM M' would accept it. So, the given problem is partially decidable.
If M goes for an infinite loop and never reaches state q (no case for the problem), M' cannot output anything. This problem is the state entry
problem, which like word accepting problem and halting problem is undecidable.
-- Arjun Suresh
GATE2001_7 top
X : Given a Turing machine M over Σ and any word w ∈ Σ , does M loop forever on w ?
You may assume that the halting problem of Turing machine is undecidable but partially decidable.
The question asks if M loop forever on w. If M loop forever on w, M wouldn't halt on w. And if M doesn't halt on w, M should loop forever. So,
this problem is exactly same as asking if "M doesn't halt on w", which is the complement of halting problem and is not even partially decidable.
So, X is not even partially decidable.
-- Arjun Suresh
GATE2002_2.14 top
GATE2002_21 top
NFA for regular expression (a+b)*abb and its equivalent DFA will be as follow:
-- Praveen Saini
GATE2003_13 top
Nobody knows yet if P=NP. Consider the language L defined as follows.
L = { (0 + 1) ∗ if P = NP
ϕ otherwise
(A) L is recursive
(D) Whether L is recursively enumerable or not will be known after we find out ifP = NP
(A) L is recursive. If P = NP , L is Σ ∗ which is recursive (in fact regular). If not, L = ϕ which is again recursive. So, in both casesL is
recursive.
-- Arjun Suresh
GATE2003_14 top
The regular expression 0 ∗ (10∗ )∗ denotes the same set as
(A) (1 ∗ 0)∗ 1 ∗
(B) 0 + (0 + 10)∗
(A) is the answer. Both (A) and the given expression generates all strings over Σ .
GATE2003_50 top
Let S denote the set of seven bit binary strings in which the first, the fourth, and the last bits are 1. The number of strings in S that are accepted
by M is
A. 1
B. 5
C. 7
D. 8
Language of above DFA is all strings over {0,1} that contain substring 001.
1 that is underlined can not be first bit of 7-bit binary no, but can be fourth bit or last bit.
-- Praveen Saini
GATE2003_53 top
A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The tape alphabet of M is {0, 1, B} and its input
alphabet is {0, 1}. The symbol B is the blank symbol used to indicate end of an input string. The transition function of M is described in the
following table.
0 1 B
q0 q1, 1, R q1, 1, R Halt
q1 q1, 1, R q0, 1, L q0, B, L
The entry (q1, 1, R) in row q0 and column 1 signifies that if M is in state q0 and reads 1 on the current page square, then it writes 1 on the same
tape square, moves its tape head one position to the right and transitions to state q1.
option A. or epsilon is only accepted i.e tape contain B as the first character
-- Supromit Roy
GATE2003_55 top
Let the language accepted by M be L. Let L 1 be the language accepted by the NFA M 1 obtained by changing the accepting state of M to a non-
accepting state and by changing the non-accepting states of M to accepting states. Which of the following statements is true?
A. L1 = {0, 1} ∗ − L
B. L1 = {0, 1} ∗
C. L1 ⊆L
D. L1 =L
GATE2006_19 top
Let
L1 = {0 n+m 1 n 0 m ∣ n, m ≥ 0 } ,
(A) L1 only
(B) L3 only
(C) L1 and L2
(D) L2 and L3
L1 is context-free. We count the number of 0's and check if the remaining number of 1's followed by 0's count to the initial number of 0's.
L2 is not context-free. Here the number of 0's and the following 1's must be same, which can be checked using a PDA. But after that we must
also ensure that the following number of 0's must be less than the previous count of 0's and 1's (otherwise n < 0, which violates the condition
for acceptance) and we cannot do these two checks using a single PDA.
L3 is again not context-free as it is nothing but equal number of 0's followed by equal number of 1's followed by equal number of 0's.
-- Arjun Suresh
GATE2006_29 top
If s is a string over (0+1)* then let n0(s) denote the number of 0’s in s and n1(s) the number of 1’s in s. Which one of the following languages is
not regular?
A. There are only finite 3 digit primes. And any finite set is regular
1. #0 - #1 = 0
2. #0 - #1 = 1
3. #0 - #1 = 2
4. #0 - #1 = -1
5. #0 - #1 = -2
If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible
because of the words "for every prefix s' of s" in L and that is what makes this language regular.
C. L is not regular
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = 3
#0 - #1 = 4
#0 - #1 = 5
.....
#0 - #1 = 1000
......
All these forms distinct equivalent classes under Myhill-Nerode theorem meaning from the strings in each of these sets, we can append a
string which will take the new string to L, while the same string appended to string in any other set won't reach L.
For example, for 000000, we append 11, for 0000000, we append 111 etc. So, in short we need to maintain the count of 1's and 0's and the
count here is not finite.
D. This is regular. We need a finite automata with 5 * 7 = 35 states for maintaining the counts of 0's mod 7 and 1's mod 5.
-- Arjun Suresh
GATE2006_30 top
For s ∈ (0 + 1)∗ let d(s) denote the decimal value of s (e.g. d(101) = 5 ). Let
Refer this
http://gateoverflow.in/1695/gate1998_4
as given in example in posted link [in same DFA , final state will be 2 instead of 0 ]
GATE2006_33 top
Let L1 be a regular language,L2 be a deterministic context-free language and L3 a recursively enumerable, but not recursive, language. Which
one of the following statements is false?
C) True : L1 is regular hence also CFL and every DCFL is also CFL and All CFL are closed under Union.
D) True : L1 is regular hence also RE; L2 is DCFL hence also RE; RE languages are closed under Intersection
B) False : L1 is recursive hence also decidable, L3 is RE but not Recursive hence it is undecidable. Intersection of Recursive language and
Recursive Enumerable language is Recursive Enumerable language.
-- Danish
GATE2004_87 top
A. regular
Language is not regular bcoz we need to match count of c's is equal to count of b's + count of a's
∂(q0,b,a) = (q1,ba) [push b in stack, state change to q1 that sure b comes after a]
∂(q2,c,b) = (q2,c) [ pop one b's for each c and continue same ]
∂(q2,c,a) = (q3,^) [ pop one a for one c , when there is no more b in stack]
∂(q3,^,^) = (qf,^) [ if sum of c's is sum of a's and b's then stack will be empty when there is no c in input]
Note :1. state changes make sure b's comes after a and c's comes after b's]
-- Praveen Saini
L = {an b : n ≥ 0} ∪ {b n a : n ≥ 1}
-- gatecse
GATE2007_6 top
Finiteness problem is decidable for FSAs (also for CFGs), as we just need to check for a loop in the DFA.
Equivalence problem for FSAs is decidable as we can take the complement of one FSA (complement of FSA is another FSA), and do an
intersection with the other (FSAs are closed under intersection also), giving a new FSA. If this new FSA accept no string, then the given FSAs
are equivalent, else not equivalent.
http://gatecse.in/wiki/Grammar:_Decidable_and_Undecidable_Problems
-- Arjun Suresh
GATE2007_7 top
Which of the following is TRUE?
Σ ∗ being regular any non regular language is a subset of this, and hence (A) is false.
If we take a CFL which is not regular, and takes union with its complement (complement of a CFL which is not regular won't be regular as
regular is closed under complement), we get Σ ∗ which is regular. So, (C) is false.
So, D is false.
-- Omesh Pandita
GATE2007_29 top
A. 15 states
B. 11 states
C. 10 states
D. 9 states
We need a separate state for #0 = 0, 1, 2 and #1 = 0, 1, 2, 3, 4 giving total minimum number of states = 3 * 5 = 15.
http://courses.cs.washington.edu/courses/cse322/05wi/handouts/MyhillNerode.pdf
-- Arjun Suresh
GATE2007_30 top
A. not recursive
C. is a regular language
GATE2007_31 top
A. {ww R ∣ w ∈ {0, 1} + }
B. {ww R x ∣ x, w ∈ {0, 1} + }
C. {wxw R ∣ x, w ∈ {0, 1} + }
D. {xww R ∣ x, w ∈ {0, 1} + }
A. CFL
B. CFL
C. Regular, language is string stating and ending with same symbol and having length at least 3. e.g. 0x0 or 1x1
D. CFL
http://gatecse.in/wiki/Identify_the_class_of_the_language
-- Vikrant Singh
GATE2007_74,75 top
74. The language accepted by this automaton is given by the regular expression
A. b ∗ ab ∗ ab ∗ ab ∗
B. (a + b)∗
C. b ∗ a(a + b)∗
D. b ∗ ab ∗ ab ∗
75. The minimum state automaton equivalent to the above FSA has the following number of states
A. 1
B. 2
C. 3
D. 4
The answer for 74 is C.
You can see that both the states, Q1 and Q2 are final and are accepting (a+b)*.
75 its B.
The state Q3 is redundant as it is not reachable. And the Regular expression b*a(a+b)* can be made with two states.
Q1-->b-->Q1
Q1-->a-->Q2
Q2-->a-->Q2
Q2-->b-->Q2.
GATE2006_34 top
Consider the regular language L = (111 + 11111)∗ . The minimum number of states in any DFA accepting this languages is:
(A) 3
(B) 5
(C) 8
(D) 9
there will be 9 states. with 1st,4th,6th,7th and 9th state being the final states. with a loop on the ninth state.
{0,3,5,6,8,9,10,11,12,........}this is the set which will be accepted by the min dfa for this expression.
-- Gate Keeda
GATE2009_12 top
S → aSa ∣ bSb ∣ a ∣ b
The language generated by the above grammar over the alphabet {a, b} is the set of
(C) strings that begin and end with the same symbol
ans is B..string generated by this language is a,b,aba,bab,aabaa,.....all this strings are odd length palindromes
-- neha pawar
GATE2009_16 top
Option d ndpa is more powerful than dpda so they are not equivalent..actually dpda is a proper subset of ndpa...
C is TRUE as CFL is a proper subset of recursive languages and recursive languages are closed under complement.
-- Bhagirathi Nayak
GATE2009_40 top
L1 = {am b m can b m ∣ m, n ≥ 0}
L2 = {ai b j c k ∣ i, j, k ≥ 0}
Then L is
A. Not recursive
B. Regular
C. Context free but not regular
D. Recursively enumerable but not context free.
-- Arjun Suresh
GATE2009_41 top
The above DFA accepts the set of all strings over {0,1} that
B. end with 0.
c) end with 00
-- Praveen Saini
GATE2005_55 top
A. L 1 ∩ L 2 is a context-free language
B. L 1 ∪ L 2 is a context-free language
c) is True.
b) is True CFL is closed under Union [ S-> S1 | S2 where S1 is grammar for L1 and S2 for L2]
CFL is not closed under Intersection, so intersection of two CFLs may or may not be CFL. Lets examine:
L1 ∩ L2 = { aibici , i>0 } which is Context sensitive but not context free [can't match a's,b's and c's with one stack]
So a) is False
d) is True
-- Praveen Saini
GATE2005_56 top
Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive language. Which one of the following is TRUE?
L1 being recursive, we have a TM M for L1 which accepts all words in L1 and rejects all words in L1'. So, this TM also works for L1' by changing
the accept and reject states. Thus L1' is recursive.
L2 being recursively enumerable but not recursive means TM for L2 can accept all words in L2 but cannot reject all words not in L2 => TM for
L2' cannot exist (as otherwise TM for L2 could simulate the moves of that TM to reject words in L2')=> L2' is not recursively enumerable. So,
(B).
-- Arjun Suresh
GATE2005_57 top
L1 = {ww R ∣ w ∈ {0, 1} ∗ }
L2 = {w#w R ∣ w ∈ {0, 1} ∗ } , where # is a special symbol
L3 = {ww ∣ w ∈ {0, 1} ∗ }
A. L 1 is a deterministic CFL
B. L 2 is a deterministic CFL
D. L 3 is a deterministic CFL
B. http://gatecse.in/wiki/Identify_the_class_of_the_language
-- Gate Keeda
GATE2005_63 top
The following diagram represents a finite state machine which takes as input a binary number from the least significant bit.
for any binary no, FSM read input from LSB and remain unchanged till first 1, and it complement after that
100 -> 100 [1's complement of 100 + 1 = 011+ 1 = 100 = 2's complement of 100]
010 -> 110 [1's complement of 010 + 1 = 101 + 1 = 110 = 2's complement of 010]
Note : Underline part is unchanged (till first 1 from lsb) then 0's changed to 1's and 1's changed to 0's
-- Praveen Saini
GATE2013_8 top
(A) {ϵ}
(B) ϕ
(C) a∗
(D) {ϵ, a}
GATE1999_1.5 top
Cfl are not closed under intersection and complement now choose the correct option so b)union and klenne closure
-- Bhagirathi Nayak
GATE1999_7 top
Show that the language
language contains strings where sub string on left of c is same as that on right of c
say 01100c01100
sub string on left of c and right of c cannot be matched with one Stack
if we push all 0's and 1's on left of c in stack 1 , and all 0's and 1' on right of c in stack 2
then Top of stack of both stack will have same symbol .. that can be matched
-- Praveen Saini
GATE2013_32 top
L1 = {0 p 1 q 0 r ∣ p, q, r ≥ 0}
L2 = {0 p 1 q 0 r ∣ p, q, r ≥ 0, p ≠ r}
(A) L 2 is context-free.
(B) L 1 ∩ L 2 is context-free.
(C) Complement of L 2 is recursive.
(D) Complement of L 1 is context-free but not regular.
L1 is regular and hence context-free also. Regular expression for L1 is 0*1*0*. So, (D) is the false choice.
L2 is context-free but not regular. We need a stack to count if the number of 0's before and after the 1 (1 may be absent also) are not same.
(L2 is but not deterministic context-free)
-- Arjun Suresh
GATE2013_33 top
1. Complement of L(A) (regular language) is regular , i.e also Context Free . True
So 3 is False
-- Praveen Saini
GATE2013_41 top
1. G is a CFG. Is L(G) = ϕ?
2. G is a CFG. Is L(G) = Σ ∗ ?
3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
(A) 3 only (B) 3 and 4 only (C) 1, 2 and 3 only (D) 2 and 3 only
It will be D.
GATE1998_1.9 top
If the regular set A is represented by A = (01 + 1)∗ and the regular set B is represented by B = ((01)∗ 1 ∗ )∗ , which of the following is true?
(a) A ⊂ B
(b) B ⊂ A
(d) A = B
(d) A = B. Both generates all strings over {0, 1} where a 0 is immediately followed by a 1.
-- Arjun Suresh
GATE1998_1.10 top
Option A is correct
A. is regular
DFA :
-- Praveen Saini
GATE1998_1.11 top
Ans B
-- Keith Kr
GATE1998_1.12 top
The string 1101 does not belong to the set represented by
(a) 110*(0 + 1)
(b) 1(0 + 1)*101
(c) (10)*(01)*(00 + 11)*
(d) (00 + (11)*0)*
In (c) after 11, we can not have 01 and so 1101 cannot be generated.
GATE1998_2.5 top
Let L be the set of all binary strings whose last two symbols are the same. The number of states in the minimal state deterministic finite state
automaton accepting L is
A. 2
B. 5
C. 8
D. 3
Having NFA
Equivalent DFA
Total no of states = 5
-- Praveen Saini
GATE1998_4 top
in binary if we have 10 ( i.e 2 in decimal say old no) and after that we get symbol 1 it become 101( i.e 5 in decimal say new no )
We need 5 states in DFA , 0,1,2,3 and 4 .Each state represent remainder that comes when we divide no by 5.
[Old state x base + input symbol] mod 5 = New state , where base is 2
[3 x 2 + 0]mod 5 = 1 [4 x 2 + 0]mod 5 = 3
[3 x 2 + 1]mod 5 = 2 [4 x 2 + 1]mod 5 = 4
-- Praveen Saini
GATE2014-1_15 top
(C) The language L = {w ∣ w has 3k + 1 b ′ s for some k ∈ N with Σ = {a, b}} is regular.
(A) is CFL and (B) and (D) are CSL. (C) is regular and regular expression for (C) would be
-- Arjun Suresh
GATE2014-1_16 top
What is the set of reachable states for the input string 0011?
(A) {q 0 , q 1 , q 2 }
(B) {q 0 , q 1 }
(C) {q 0 , q 1 , q 2 , q 3 }
(D) {q 3 }
GATE2014-1_35 top
Let L be a language and L̄ be its complement. Which one of the following is NOT a viable possibility?
(B) One of L and L̄ is r.e. but not recursive; the other is not r.e.
(C) is not possible. If L is re we have a TM that accepts string in L. If L' is re, we have a TM that accepts strings in L'. So, using both these
TMs we can make a new TM M which accepts strings in L and rejects strings in L' - that is M decides L, making L recursive.
-- Arjun Suresh
GATE2014-1_36 top
Which of the regular expressions given below represent the following DFA?
(B) is the answer. (II) doesn't generate 11011 which is accepted by the given DFA
-- Arjun Suresh
GATE2014-2_15 top
(II) L 1 . L 2 = {an b n ∣ n ≥ 0}
L1.L2 = {ϵ, a, b, ab, abb, abbb, abbbb,..........,aab, aabb, aabbb, ................} = a*b* This is regular language and not equal to anbn
-- Viral Kapoor
GATE2014-2_16 top
Let A ≤ m B denotes that language A is mapping reducible (also known as many-to-one reducible) to language B. Which one of the following is FALSE?
A ≤m B means A cannot be harder than B. (Since A can be reduced to B, instead of deciding A, we can now decide B)
So, the first 3 options are correct. Option (D) is false, as B is not recursively enumerable doesn't guarantee A is not recursively enumerable.
-- Arjun Suresh
GATE2014-2_35 top
Let < M > be the encoding of a Turing machine as a string over∑ = {0, 1} . Let
. Then L is
There are only a finite number of strings of length 2014. So, we can give all those strings to TM simulating each string for 1 step, then 2 step
and so on (dovetailing), and if the TM accepts any of them ("yes" case of TM), we can say "yes". So, L is recursively enumerable.
(If the TM doesn't accept any string of length 2014, it can go to an infinite loop ("no" case of TM), and hence we can't say the method is
decidable).
Now, to prove whether the problem is decidable or not we can make use of Rice's theorem. Rice's theorem (I) states that any non-trivial
property of L(TM) is undecidable. L(TM) has a string of length 2014 is a non-trivial property as there are TMs whose language contains such a
string and there are TMs whose language doesn't have such a string. So, the given problem is undecidable.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- Arjun Suresh
GATE2014-2_36 top
L2 = {w ∈ {0, 1} ∗ ∣ w has at least as many occurrences of (000)′ s as(111)′ s} . Which one of the following is TRUE?
(A) L1 is regular but not L2
(A) is True. Though at first look both L1 and L2 looks non-regular, L1 is in fact regular. The reason is the relation between 110 and 011.
We cannot have two 110's in a string without a 011 or vice verse. And this would mean that we only need a finite number of states to check for
acceptance of any word in this language.
That was just an intuitive explanation. Now I say that L contains all binary strings starting with 11. Yes, if a binary string starts with 11, it can
never have more no. of 011 than 110.
-- gatecse
GATE2014-3_15 top
The length of the shortest string NOT in the language (over Σ = {a, b}) of the following regular expression is _______.
a∗ b ∗ (ba)∗ a∗
R = a*b*(ba)*a*
for finding shortest string that is not in language it is better to look strings of length 0, then of length 2 and soon
length0 { ∊} is in L
length 3 {aaa, aab, aba, abb, baa, bab, bba, bbb} bab does not belong to L
-- Praveen Saini
GATE2014-3_36 top
L1 = {0 n 1 n ∣ n ≥ 0}
L2 = {wcw r ∣ w ∈ {0, 1} ∗ }
L3 = {ww r ∣ w ∈ {0, 1} ∗ }
Here, w r is the reverse of the string w . Which of these languages are deterministic Context-free languages?
(B) Only L 1
(C) Only L 1 and L 2
C.
L3 is CFL and not DCFL as in no way we can deterministically determine the MIDDLE point of the input string.
-- Gate Keeda
GATE2011_42 top
(A) k + 1
(B) n+1
(C) 2 n+1
(D) 2 k+1
(A) n+1
We need a state for strings of length 0, 1, 2, ... n (and their respective multiples with k). Each of these set of strings form an equivalence class
as per Myhill-Nerode theorem and hence needs a separate state in min-DFA.
-- Arjun Suresh
GATE2011_45 top
Which of the following finite state machines is a valid minimal DFA which accepts the same languages as D ?
(A)
(B)
(C)
(D)
In (B) and (C) when the first letter of input is 'b' we reach final state, while in the given DFA first letter 'b' is not a final state. So, (B) and (C) are
not accepting same language as the given DFA.
In (D) we can reach final state when the last letter is 'a', whatever be the previous transitions. But in the given DFA, when the first 2 letters are
'b' we can never reach the final state. So, (D) is also accepting a different language than the given DFA.
-- Arjun Suresh
GATE2012_46 top
Consider the set of strings on {0, 1} in which, every substring of 3 symbols has at most two zeros. For example, 001110 and 011001 are in the
language, but 100010 is not. All strings of length less than 3 are also in the language. A partially completed DFA that accepts this language is
shown below.
(A)
00 01 10 11 q
00 1 0
01 1
10 0
11 0
(B)
00 01 10 11 q
00 0 1
01 1
10 0
11 0
(C)
00 01 10 11 q
00 1 0
01 1
10 0
11 0
(D)
00 01 10 11 q
00 1 0
01 1
10 0
11 0
(D) is the answer. From 00 state, a '0' should take the DFA to the dead state-q. From 11, a '0' should go to 00 representing the 00 at the end
of string so far. Similarly, from 00 a 1 should go to 01, from 01 a '1' should go to 11 and from 10 a '0' should go to '00'.
-- Arjun Suresh
GATE2010_17 top
Let L 1 be the recursive language. Let L 2 and L 3 be languages that are recursively enumerable but not recursive. Which of the following statements is not
necessarily true?
Recursively enumerable languages are closed under union and intersection. So, lets consider each option
(A) L 2 − L 1 = L 2 ∩ L¯1
Recursive languages are closed under complement, and so L¯1 is recursive and hence recursively enumerable also. So, L 2 ∩ L¯1 is recursively
enumerable is always TRUE.
(B) L 1 − L 3 = L 1 ∩ L¯3
Recursively enumerable languages are not closed under complement. So, L¯3 may or may not be recursively enumerable and hence we can't
say anything if L 1 ∩ L¯3 is recursively enumerable or not.
(C) Intersection of two recursively enumerable languages is always recursively enumerable(RE closed under intersection).
(D) Union of two recursively enumerable languages is always recursively enumerable(RE closed under union).
-- Arjun Suresh
GATE1997_3.4 top
Ref: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-045j-automata-computability-and-complexity-spring-
2011/lecture-notes/MIT6_045JS11_lec05.pdf
-- Arjun Suresh
GATE1997_6.4 top
Which one of the following regular expressions over {0, 1} denotes the set of all strings not containing100 as substring?
(a) 0 ∗ (1 + 0)∗
(b) 0 ∗ 1010∗
(c) 0 ∗ 1 ∗ 01∗
"A regular expression denoting a language (set of strings) means it should generate all string in L and not generate any string not
in L"
(b) doesn't generate 0 (start trying strings in lexicographic order- 0, 1, 00, 01, 10,...)
-- Arjun Suresh
GATE1997_6.5 top
GATE1997_6.6 top
Which of the following languages over {a, b, c} is accepted by a deterministic pushdown automata?
(C) {an b n c n ∣ n ≥ 0}
GATE1997_20 top
Construct a finite state machine with minimum number of states, accepting all strings over (a,b) such that the number of a's is divisible by two
and the number of b's is divisible by three.
q00 means namod2 =0 , nbmod3=0 [no of a's is divisible of 2 and no of b's are divisible of 3]
q00 x a → q10
-- Praveen Saini
GATE1997_21 top
Given that L is a language accepted by a finite state machine, show that L P and L R are also accepted by some finite state machines, where
Suppose we have a finite automation for L , then we can build a finite automation for L P by marking all the states from which final state is
reachable as the final states for new automaton, the reasoning is that suppose we can reach final state f form some state q, then that means
there exists some string s' that takes automation from q to f, so if there is some string s that takes automation to state q from start state this
string should belong to the new language L P .
Also, we can obtain an automation for L R by swapping the start and final states of original automationL and by reversing all the edges in the
DFA.
-- Omesh Pandita
GATE1993_27 top
Draw the state transition of a deterministic finite state automaton which accepts all strings from the alphabet {a, b} , such that no string has 3
consecutive occurrences of the letter b.
then take complement of DFA such that no string has 3 consecutive occurrences of the letter b.
-- Praveen Saini
GATE2010_39 top
Let L = {w ∈ (0 + 1)∗ ∣ w has even number of 1s} . i.e., L is the set of all the bit strings with even numbers of 1 s. Which one of the regular expressions
below represents L ?
(A) (0 ∗ 10 ∗ 1)∗
(B) 0 ∗ ( 10 ∗ 10 ∗ ) ∗
(C) 0 ∗ ( 10 ∗ 1) ∗ 0 ∗
(D) 0 ∗ 1( 10 ∗ 1) ∗ 10 ∗
(A) - If the string contains a 1, it must end in a 1 hence cannot generate all bit strings with even number of 1's (eg, 1010)
(C) - between the second and third 1's a 0 is not allowed (eg, 011011)
GATE2010_40 top
L1 = {0 i 1 j ∣ i ≠ j},
L2 = {0 i 1 j ∣ i = j},
L3 = {0 i 1 j ∣ i = 2j + 1},
L4 = {0 i 1 j ∣ i ≠ 2j}
L2 -> Do the same as for L1, but accept if stack is empty at end of string.
L3 -> Do, the same as for L2, but for each 0, push two 0's on stack and start the stack with a 0.
L4 -> Do the same as for L1, but for each 0, push two 0's on stack
All are in fact DCFL. Pushing two 0's on stack might sound non-trivial but we can do this by pushing one symbol and going to a new state.
Then on this new state on empty symbol, push one more symbol on stack and come back.
-- Arjun Suresh
GATE2010_41 top
Let w be the any string of length n in {0, 1} ∗ . Let L be the set of all substrings of w . What is the minimum number of states in non-deterministic finite automation
that accepts L ?
(A) n−1
(B) n
(C) n + 1
(D) 2 n−1
We need a state for counting the length. So, for length n we need n+1 states (one for length zero). We don't need a reject state for larger
strings as we have NFA and not DFA. So, totally n+1 states are required. (For DFA it would be n+2).
-- Arjun Suresh
How ϕ ∗ = ϵ ?
ϕ = {} , which is empty set. Now by definition of *, it repeats the content of a set ZERO or more times. And anything repeated zero time is
ϵ.
And nothing repeated 1 or more times is nothing.
ϕ∗ = ϵ
GATE1994_1.16 top
This will be C. Because if that would have been possible then NPDA and DPDA must had same powers, which is not the case. You can take
example of NFA and DFA. Both are convertible to each other and hence share the same power.
-- Gate Keeda
GATE1994_2.10 top
L={0*1*}
-- Manu Thakur
GATE1994_3.3 top
A FSM (Finite State Machine) can be designed to add two integers of any arbitrary length (arbitrary number of digits).
No. Perhaps that wont be possible to add any two arbitrary numbers because that will need a memory element which is not there in a FSM.
-- Gate Keeda
GATE1994_19 top
Which of the following statements is true with respect to S? No reason to be given for the answer.
i. S is regular
ii. S is recursively enumerable
iii. S is not recursively enumerable
iv. S is recursive
(b) Given that a language L 1 is regular and and that the language L 1 ∪ L 2 is regular, is the language L 2 always regular? Prove your answer.
(a) S is regular. It might not be possible to find what is x, but once it is found, it will be an integer and hence can be represented using an
automaton. For finding the class of a language, we needn't consider the difficulty in getting the language contents (strings of language). We
only need to count the difficulty in recognizing the strings of language.
(b) No. need not be. Take L2 = {anbn | n > 0} and L1 = all strings over {a,b}. Now, L1 U L2 is L1 only and is regular but L2 is not regular.
-- Arjun Suresh
GATE1995_1.9 top
In some programming language, an identifier is permitted to be a letter followed by any number of letters or digits. If L and D denote the sets of
letters and digits respectively, which of the following expressions defines an identifier?
(a) (L ∪ D)+
(c) (LD)∗
(d) L(LD)∗
It is B.
It has to be started by a letter followed by any number of letters and digits.
-- Gate Keeda
GATE1995_2.20 top
A.
In the other two you can have any number of x and y. There is no such restriction over the number of both being equal.
-- Gate Keeda
GATE1995_2.23 top
b) is correct.
-- Praveen Saini
GATE1995_2.24 top
Let Σ = {0, 1}, L = Σ ∗ and R = {0 n 1 n ∣ n > 0} then the languages L ∪ R and R are respectively
Answer is (C). L ∪ R is nothing but L as R is a subset of L and hence regular. R is deterministic context-free but not regular as we require a
stack to keep the count of 0's to match that of 1's.
-- Arjun Suresh
GATE1996_1.8 top
C.
A is false because you cannot have single 0 in ii). same for option B. In D you are forced to have single 0 in iv) whereas not in iii).
-- Gate Keeda
GATE1996_1.9 top
D..
1.Membership,
2.Emptiness,
3.Finiteness,
4.Equivalence,
5.Ambiguity,
6.Regularity,
7.Everything,
8.Disjointedness...
All are decidable for Regular languages.
-- Gate Keeda
GATE1996_1.10 top
Let L ⊆ Σ ∗ where Σ = {a, b} . Which of the following is true?
Only D. because n and m are independent and thus no memory element required.
-- Gate Keeda
GATE1996_2.8 top
B.
GATE1996_2.9 top
(b) is the answer. Because for any binary string of 0's and 1's we can append another string to make it contain equal number of 0's and 1's.
i.e., any string over {0,1} is a prefix of a string in L.
Example:
3 states are required in the minimized machine. States B and C can be combined as follows:
-- Arjun Suresh
GATE1996_12 top
We can combine the final state of M1 with the start state of M2 as follows recognizing L1L2
-- Arjun Suresh
GATE1996_13 top
Let Q = ({q 1 , q 2 }, {a, b}, {a, b, ⊥}, δ, ⊥, ϕ) be a pushdown automaton accepting by empty stack for the language which is the set of all
nonempty even palindromes over the set {a, b} . Below is an incomplete specification of the transitions δ . Complete the specification. The top of
the stack is assumed to be at the right end of the string representing stack contents.
δ(q1 , a, b) = {(q2 , ba)} means from state q1 on input a with stack top being b , the PDA moves to state q2 and pushes a on top of stack.
So, here the missing transitions are at the middle of the input string:
Once middle is reached, now we should start popping. And so, we must go to state q 2 as well as pop the previous character on the stack.
(The character before and after the middle must be same as the string is even length palindrome)
GATE1998_3b top
Give a regular expression for the set of binary strings where every 0 is immediately followed by exactly k 1's and preceded by at least k 1’s (k
is a fixed integer)
Hence, regular.
GATE2008-IT_5 top
Which of the following regular expressions describes the language over{0, 1} consisting of strings that contain exactly two 1's?
A) (0 + 1) * 11(0 + 1) *
B) 0 * 110 *
C) 0 * 10 * 10 *
D) (0 + 1) * 1(0 + 1) * 1 (0 + 1) *
GATE2008-IT_6 top
Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language. Which of the following in
NECESSARILY true?
A) m ≤ 2n
B) n≤m
C) M has one accept state
D) m = 2n
A state in a DFA will be a subset of the set of states of the equivalent NFA. So, the maximum number of states in the equivalent DFA of an
NFA, will be 2n, where n is the number of states in NFA, as a set with n items has maximum n2 subsets.
-- Arjun Suresh
GATE2008-IT_32 top
If the final states and non-final states in the DFA below are interchanged, then which of the following languages over the alphabet {a, b} will be
accepted by the new DFA?
Above DFA is for regular expression (a+b)*ab . All strings end with ab.
Complement of DFA accepts all strings does not end with ab.
DFA(L') is
B. String begin with either a or b.
bab (string start with b) doesnt accept in it reach to nonfinal state q2.
aba (have substring ab) does accept in it reach to final state q1.
b is string accepted by DFA(L') but above regular expression cannot derive it.
Option A is correct.
DFA (L') accepts all strings that doesnt end with ab.
-- Praveen Saini
GATE2008-IT_33 top
L1 = {ai bj ck | i = j, k ≥ 1}
L2 = {ai bj | j = 2i, i ≥ 0}
L1 = start pushing element X into the stack on input 'a' ... start poping X on input 'b' ... move to final state when stack empty and input = 'c'
L2 = start pushing elements XX into the stack on input 'a' ... start poping X on input 'b' ... move to final state when stack empty and input =
'epsilon'
L1 ∪ L2 is a CFL ... we can build it by having L1, L2 and an extra state ... and an 'epsilon' transition to both L1 and L2 from that extra state.
so (C) is false
L1 ∩ L2 = Phi because we have no string aibj where i=j and i=2j for i,j>=1
so (B) is true.
-- Danish
GATE2008-IT_35 top
L1 = {0m1n | 0 ≤ m ≤ n ≤ 10000}
L2 = {w | w reads the same forward and backward}
L3 = {w ∊ {0, 1} * | w contains an even number of 0's and an even number of 1's}
A) L2 and L3 only
B) L1 and L2 only
C) L3 only
D) L2 only
L3 is also regular.. we can make DFA for L3.. states will represent mod 2 for 0 and mod 2 for 1, which is finite
so option (d)
-- Vicky Bajoria
GATE2008-IT_36 top
Consider the following two finite automata. M1 accepts L1 and M2 accepts L2.
Which one of the following is TRUE?
A) L1 = L2
B) L1 ⊂ L2
C) L1 ∩ L2' = ∅
D) L1 ∪ L2 ≠ L1
L1: (0 + 10)*11(0 + 1)* L2: (0 + 1)*11(0 + 1)* it is quite clear that L1 = L2.. So, option (A)
-- Vicky Bajoria
Gate2011_24 top
Let P be a regular language and Q be a context-free language such that Q ⊆ P . (For example, let P be the language represented by the regular expression
p ∗ q ∗ and Q be {p n q n ∣ n ∈ N}) . Then which of the following is ALWAYS regular?
(A) P ∩Q
(B) P −Q
(C) Σ ∗ −P
(D) Σ ∗ −Q
GATE2007-IT_46 top
The two grammars given below generate a language over the alphabet {x, y, z}
G1 : S → x|z|xS|zS|yB
B → y|z|yB|zB
G2 : S → y|z|yS|zS|xB
B → y|yS
Which one of the following choices describes the properties satisfied by the strings in these languages ?
Option A is correct
-- Praveen Saini
GATE2007-IT_47 top
Consider the following DFA in which s0 is the start state and s1, s3 are the final states.
and ∂(q00, x) -> q10 [(0+1)mod2 =1 as x increase from 0 to 1 ] ∂(q00, y) -> q01
and ∂(q10, x) -> q00 [(1+1)mod2 =0] ∂(q00, y) -> q01 and soon
so D is correct answer
-- Praveen Saini
GATE2007-IT_48 top
S → xB|yA
A → x|xS|yAA
B → y|yS|yBB
(i) xxyyx
(ii) xxyyxy
(iii) xyxy
(iv) yxxy
(v) yxx
(vi) xyx
so option C is correct
Above grammar is for equal no of x and y
S->xB
S->xB
-- Praveen Saini
GATE2007-IT_49 top
Consider the following grammars. Names representing terminals have been specified in capital letters.
G1 : stmnt → WHILE (expr) stmnt
stmnt → OTHER
expr → ID
G2 : stmnt → WHILE (expr) stmnt
stmnt → OTHER
expr → expr + expr
expr → expr * expr
expr → ID
Regular grammar is either right linear or left linear. A left linear grammar is one in which there is at most 1 non-terminal on the right side of
any production, and it appears at the left most position. Similarly, in right linear grammar non-terminal appears at the right most position.
S -> w(E
E -> id)S
S -> o
(w - WHILE, o - OTHER)
So, both G1 and G2 have an equivalent regular grammar. But as such both these grammars are neither right linear nor left linear and hence
not a regular grammar. So, D must be the answer.
http://www.cs.odu.edu/~toida/nerzic/390teched/regular/grammar/reg-grammar.html
-- Arjun Suresh
GATE2007-IT_71 top
Consider the regular expression R = (a + b)* (aa + bb) (a + b)*
Which of the following non-deterministic finite automata recognizes the language defined by the regular expression R? Edges labeled λ denote
transitions on the empty string.
A)
B)
C)
D)
A is correct.
-- Praveen Saini
GATE2007-IT_72 top
Which deterministic finite automaton accepts the language represented by the regular expression R ?
A)
B)
C)
D)
http://gateoverflow.in/3523/gate2007-it_71
-- Praveen Saini
GATE2007-IT_73 top
R = (a+b)*(aa+bb)(a+b)*
having NFA
Equivalent DFA :
which is equivalent Transition graph [ by removing transition from q1 to q2 and q2 to q1 but does not effect on language ..be careful ]
That is equivalent to
which is equivalent to
which is equivalent to
so option C is answer.
-- Praveen Saini
GATE2006-IT_3 top
In the automaton below, s is the start state and t is the only final state.
Consider the strings u = abbaba, v = bab, and w = aabb. Which of the following statements is true?
-- Praveen Saini
GATE2006-IT_4 top
In the context-free grammar below, S is the start symbol, a and b are terminals, and ϵ denotes the empty string
S → aSa | bSb | a | b | ϵ
A) aaaa
B) baba
C) abba
D) babaaabab
L(G) = PALINDROME
GATE2006-IT_29 top
S → bS | aA | ϵ
A → aS | bA
The Myhill-Nerode equivalence classes for the language generated by the grammar are
Option A is correct.
The given grammar generates all string over the alphabet which have an even number of 's.
-- Pragy Agarwal
GATE2006-IT_30 top
D) Every subset of a finite language is regular: True. Every subset of a finite set must be finite by definition. Every finite set is regular.
Hence, every subset of a finite language is regular.
-- Pragy Agarwal
GATE2006-IT_31 top
Which of the following languages is accepted by a non-deterministic pushdown automaton (PDA) but NOT by a deterministic PDA?
A) {anbncn | n ≥ 0}
B) {albmcn | l ≠ m or m ≠ n}
C) {anbn| n ≥ 0}
D) {ambn| m, n ≥ 0}
option B is correct
L = {albmcn | l ≠ m or m ≠ n}
(q0,a,Z0) →(q0,aZ0)
(q0,a,a) →(q0,aa)
[here it is NPDA where we have to check l≠ m or m≠ n; for l≠ m we need to pop a for b; for m≠ n we need to keep b in
stack so that we can pop b for c ]
(q1,b,a)→(q1,∊)
(q1,c,a) → (qf,∊)
(q1,b,Z0) → (qf,∊)
(q2,b,b)→q2,bb)
(q2,c,b)→(q3,∊)
(q3,c,b)→(q3,∊)
(q3,c,a)→(qf,∊)
(q3,∊,b)→(qf,∊)
-- Praveen Saini
GATE2006-IT_33 top
Consider the pushdown automaton (PDA) below which runs over the input alphabet (a, b, c). It has the stack alphabet {Z 0, X} where Z0 is the
bottom-of-stack marker. The set of states of the PDA is (s, t, u, f} where s is the start state and f is the final state. The PDA accepts by final
state. The transitions of the PDA given below are depicted in a standard manner. For example, the transition (s, b, X) → (t, XZ0) means that if
the PDA is in state s and the symbol on the top of the stack is X, then it can read b from the input and move to state t after popping the top of
stack and pushing the symbols Z0 and X (in that order) on the stack.
A) {albmcn | l = m = n}
B) {albmcn | l = m}
C) {albmcn | 2l = m + n}
D) {albmcn | m = n}
after that for every b we pop out one X [reach to state t ( getting b after a) ]
after that for every c we pop out one X [reach to state u (getting c after b)]
if all X are popped out then reached to final state f , mean for every b there is a, for every c there is a .
means sum of no of b's and no of c's = twice of no of a's [ one a for one b , one a for one c ]
i.e. {albmcn | 2l = m + n}
-- Praveen Saini
GATE2006-IT_34 top
In the context-free grammar below, S is the start symbol, a and b are terminals, and ϵ denotes the empty string.
S → aSAb | ϵ
A → bA | ϵ
A → bA|ϵ
∴ A = b∗
S → aSAb | ϵ
≡ S → aS b ∗ b | ϵ
≡ S → aS b + | ϵ
n
S = an ( b + ) , n≥0
n n ∗,
S=a b b n≥0
S = am b n , m≤n
-- Pragy Agarwal
L contains aabb, aaabbb, aaaaabbbbb, ... ak bk where k is the largest prime below 327. Now there are only a finite set of strings in L making it
a finite language. L can be accepted by a finite automaton.
-- Arjun Suresh
GATE2004-IT_7 top
Which one of the following regular expressions is NOT equivalent to the regular expression (a + b + c)*?
A) (a* + b* + c*)*
B) (a*b*c*)*
C) ((ab)* + c*)*
D) (a*b* + c*)*
-- Praveen Saini
GATE2004-IT_9 top
A) There exist context-free languages such that all the context-free grammars generating them are ambiguous
B) An unambiguous context-free grammar always has a unique parse tree for each string of the language generated by it
C) Both deterministic and non-deterministic pushdown automata always accept the same set of languages
D) A finite set of string from some alphabet is always a regular language
A) this is true for inherently ambiguous language
B) always correct, that's why called un ambiguous
C) NPDA is a supper set of DPDA, hence it's FALSE
D) finite language is always regular
-- Manu Thakur
GATE2004-IT_41 top
A grammar to generate the language accepted by M can be specified as G = (V, Σ, R, S), where V = K U Σ, and S = A.
Which one of the following set of rules will make L(G) = L(M) ?
δ(A, a) = A, A →aA
δ(A, b) = B, A →bB
δ(B, a) = B B →aB
δ(B, b) = A B →bA
B is final state so B → ε
-- Praveen Saini
GATE2005-IT_4 top
Let L be a regular language and M be a context-free language, both over the alphabet Σ. Let Lc and Mc denote the complements of L and M
respectively. Which of the following statements about the language Lc ∪ Mc is TRUE?
We know that complement of CFL need not be a CFL as CFL is not closed under complement.
-- Arjun Suresh
GATE2005-IT_5 top
Which of the following statements is TRUE about the regular expression 01*0?
(B). Infinite set (because of *) of finite strings. A regular expression cannot generate any infinite string AFAIK.
-- Arjun Suresh
GATE2005-IT_6 top
A) regular
B) context-free but not regular.
C) context-free but its complement is not context-free.
D) not context-free.
Regular (in fact finite). Since n is finite, we have a finite set of strings satisfying the given conditions. So, we can easily make a finite automata
for those strings.
-- Arjun Suresh
GATE2005-IT_37 top
Consider the non-deterministic finite automaton (NFA) shown in the figure.
State X is the starting state of the automaton. Let the language accepted by the NFA with Y as the only accepting state be L1. Similarly, let the
language accepted by the NFA with Z as the only accepting state be L2. Which of the following statements about L1 and L2 is TRUE?
A) L1 = L2
B) L1 ⊂ L2
C) L2 ⊂ L1
D) None of the above
So we can conclude neither they are same set not proper subset of each other.
Hence Ans. D.
-- shreya ghosh
GATE2005-IT_39 top
S → Xa | Ya
X → Za
Z → Sa | ϵ
Y → Wa
W → Sa
where S is the starting symbol, the set of terminals is {a} and the set of non-terminals is {S, W, X, Y, Z}.
We wish to construct a deterministic finite automaton (DFA) to recognize the same language. What is the minimum number of states required
for the DFA?
A) 2
B) 3
C) 4
D) 5
(D) 3
The string generated by the language is the set of strings with a's such that number of a mod 3 is 2.
So the number of states required should be 3 to maintain the count of number of a's mod 3.
-- Omesh Pandita
Given that a language L A = L 1 ∪ L 2 , where L 1 and L 2 are two other languages. If L A is known to be a regular language, then which of the
following statements is necessarily TRUE?
(b) is the answer because we cannot make an irregular set S regular, by adding a finite number of elements to it. This can be proved as
follows:
Let R ∪ F = T be regular, where F is a finite set. We remove all elements from F which are in R and let the new set be E. Still,
R ∪ E = T. and E is a finite set (but no strings common between E and R)
Now, T being regular means we have a DFA for T. We can find all the states in this DFA where each of the strings in F is being accepted. In
each of these accepting state, none of the string in R will be accepted as R and E doesnt have any string in common. So, if we make all these
states non-accepting, what we get is DFA for R. Meaning R is regular.
We can prove (a) false be taking L 1 = Σ ∗ and L 2 = {an b n ∣ n > 0} . Now, union of these is Σ ∗ which is regular but L 2 is not regular.
(c) can be proved false by taking L 1 = {a} and L 2 = {an ∣ n > 0} . Now L 1 ∪ L 2 is regular and L 1 finite but L 2 is not finite.
-- Arjun Suresh
How to draw NPDA for language L = { a^i b^j c^m | m >= min( i,j) } top
My understanding :
For Language L1 :
By looking at language , it is not possible to construct PDA as it contains 2 conditions ( i > j or i < j And m ≥ min (i,j) )
I dont know correct way to construct NPDA but I tried in following way.
1) At some point PDA will assume that i < j or i > j
condition 1st : i < j
We are interested in min , so consider only i,≥ means accept "a" and skip all "b" and for each "c" , pop each "a"
Condition 2nd: i > j
We are interested in min , so consider only j means skip all "a" and accept "b" and for each "c" , pop each "b" So it is CFL. Please correct me if
it is wrong.
If above NPDA is right , then we can construct NPDA for L2 also.
But Answer part saying L2 is not CFL.
Prefix property is not obeyed by all DCFLs. It is obeyed only by those languages accepted by a deterministic PDA which accepts by empty
stack- if a prefix of the string is in L, stack should have been empty before and deterministic means, this cannot happen.
Now, a language obeys prefix property doesn't mean it is DCFL. {anbncn | n ≥ 1} obeys prefix property but not even CFL.
L1 = { a i bj cm | m ≥ min(i,j) }
Here number of c's is greater than minimum of number of a's and number of b's. So, we can say that if number of c's is greater than number
of a's or if number of c's is greater than number of b's, we accept. i.e.,
L1 = { a ibjcm | m ≥ i OR m ≥ j) }
The OR condition here means even though we need to do two checks, we can accept in either case and hence using non-determinism we just
need a PDA to accept L1 (we non-deterministically check if m ≥ j and if m ≥ i). So, L1 is a CFL but not DCFL.
L2 = { a i bj cm | m ≥ max(i,j) }
L2 = { a ibjcm | m ≥ i AND m ≥ j) }
The AND condition here means we need to do two checks and even non-determinism cannot help us here. This is because if we non-
deterministically guess i ≥ j, and accept if m ≥ i, suppose if the guess is wrong, then we would have accepted a word not in L2. (In short non-
determinism can help only when we have OR condition). So, L2 is not even CFL- it is a CSL.
-- Arjun Suresh
Here we want to prove whether RE or not. (Rice's theorem part 1 won't help)
So, lets see if the property is non-monotonic so that we can apply Rice's theorem part 2.
For non-monotonicity, language of TM satisfying the property must be a subset of language of TM not satisfying the property. So, if we take
L(TMyes) = ∅ and T(TMno) = any non regular language, this proves the property is non-monotonic. So, as per Rice's theorem part 2, REG is
not RE.
Using the same technique we can prove Co-Reg is also not RE. Just take L(TMyes) = any non regular language and L(TMno) = Σ*.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- Arjun Suresh
L1 - L2 = L1 ⋂ L2'
Now CFL complement need not be CFL (as CFL's are not closed under complement).But any CFL is also a CSL and CSLs are closed under
complement. So, any CFL complement is guaranteed to be a CSL. Now, CSL intersection CSL (regular is also a CSL) is CSL, and so L1-L2 is
always Context Sensitive.
(It can also be regular or CFL but we can say always only with respect to CSL)
http://gatecse.in/wiki/Closure_Property_of_Language_Families
-- Arjun Suresh
I think the answer should be 32 but its not in options? Help me in this question.. top
First of all I would like to clear that empty language is ϕ and not λ and there is only one way to have final state in finite automata then - By not
having any final state at all . Now 16 is total number of transitions possible in DFA of two states and two inputs. So possible number of DFA's
with no final state= 16 , now there are 4 more possibilities when q1 is final state and it is not reachable from initial state.. ( courtesy @Arjun sir
) Therefore ans is 16+4=20
-- Prateeksha Keshari
For G,
S -> bAcAb -> bcAb ->bcb
So, G is generating all strings where number of b's to the left of 'c' in the input string is greater than or equal to the number of b's to the right.
So, L(G) is context-free but not regular.
For G' we have an extra production bA -> A which can condense any number of b's. So, G' will generate all strings over b and c containing at
least one b before and after a c. This language is hence regular.
-- Arjun Suresh
(A) P ∩ Q
(B) P-Q
(C) Σ* -P
(D) Σ* - Q
B. P − Q need not be regular when P = Σ ∗ and Q is a CFL as this will be Q̄ and CFL complement need not be even CFL.
If it does, how??
Consider the following Languages:
-- Pragy Agarwal
CFL is a strict subset of CSL. CSL is closed under complement. So, CFL complement is CSL.
And CSL is a strict subset of recursive which in turn is a strict subset of recursively enumerable.
-- Arjun Suresh
Now u want to find whether L 1 − L 2 is dcfl or not? (if DCFL is closed under set-difference, this must be TRUE for ANY suchL 1 and L 2 ).
To prove this we make use of the fact that DCFL is not closed under intersection. (For example take L 1 = {a∗ b n c n ∣ n ≥ 0} and
L2 = {an b ∗ c n ∣ n ≥ 0} which gives L1 ∩ L2 = {an b n c n ∣ n ≥ 0} , which is not even a CFL.)
DCFL is closed under complement (If we complement the accept states of DPDA for L we get DPDA for the complement of L, but this is not
true for a general PDA.) So, L¯2 is a DCFL, let it be R. So,
L1 ∩ L2 = L1 − R , where L1 , L2 and R are DCFLs. Now, if DCFL is closed under set difference it must also be closed under complement.
But we already showed that it is not. So, DCFL is not closed under set difference.
-- Shreyans Dhankhar
The number of states in a DFA accepting all the strings over {0,1} in which 5th symbol from
right hand side is always '1' is? top
Will the answer be 4 or 2 5 ?
It will be 25 as 25 possible combinations of characters are possible with the 5th last character being 1. We need to remember each of them as
any of them can be the 5th last character as we continue processing further characters.
-- Arjun Suresh
What is the number of states in the minimal DFA with input symbols {0,1,2} where 2nd last
symbol is 1? top
What is the number of states in the minimal DFA with input symbols {0,1,2} where 2nd last symbol is 1?
A. 8
B. 9
C. 6
D. None
-- Praveen Saini
In q 0 when stack is empty and an a comes, a is pushed on stack. After this for either a or b , we reach q 1 without modifying the stack. In q 1 we
can ignore all a's and b's without modifying the stack. Finally, we can move to q 2 on a b and this pops the a on stack (there is non-determinism
here for the given PDA). And now stack is empty and PDA reached final state. So, L is regular but infinite.
-- Arjun Suresh
Given R1 + R2 ⋅ R3 = (R1 + R2 ) ⋅ (R1 + R3 ) for any R2 and R3 . Which of the following could be correct condition which always satisfies the
above equation.
1. R1 = R2
2. R1 = R3
3. R1 = ∅
Answer is given as D
So, they are not equal. For example consider R1 = R2 = a, R3 = b. LHS = a + ab, RHS = aa + ab
When R1 = ϕ,
LHS = ϕ as ϕ concatenated with anything is ϕ
RHS = ϕ hence equal.
-- Arjun Suresh
toc top
Let L1 = {anbmcn | m,n ≥ 0 } and L2 = {ancn | n ≥ 0 }. Both L1 and L2 are context free languages. if L = ( L1 - L2 ) then L is ____.
a. Finite Language
b. Regular language
c. DCFL
d. Not DCFL
So,
L1 − L2 = {an b m c n ∣ m > 0, n ≥ 0}
DCFL.
-- Arjun Suresh
a. {< M > | M is a TM and there exist an input whose length is less than 100, on which M halts}
d. All of these
a) is recursively enumerable but not recursive. If there is such an input, then we can say "yes". But for the no case we cannot decide as we
can never be sure that such an input does not exist.
b) is not RE. We can use Rice's 2nd theorem which will be most straightforward. Here we are given the encoding of a TM and asked if the
language of that machine is {00, 11}. (This is different from asking if that machine accepts 00 and 11, which would be RE). So, now to apply
Rice's 2nd theorem, we need to make 2 TMs, TM yes and TMno, with L(TMyes) = {00,11} and L(TMno) != {00,11} and L(TMyes) subset of
L(TMno). (The last condition is for non-monotonicity).
Here, we can easily get a TMno as L(TMno) can be {00, 11, 011} or any subset of sigma star containing {00, 11} except {00, 11}. Since we get
TMyes, and TMno, the given language is not RE.
c) Checking the equivalence of language of 2 TMs itself is not even semi-decidable. So, this is a double non-recursively enumerable
language. We can use Rice's 2'nd theorem here also, by taking L(TM no) = sigma star.
-- Arjun Suresh
No. of states in the minimal finite automata which accepts the binary strings whose
equivalent is divisible by 32 is ________? top
No. of states in the minimal finite automata which accepts the binary strings whose equivalent is divisible by 32 is ________?
A. 5
B. 6
C 31
D 32
Answer is 6.
For binary strings divisible by 2 we check if the last char from right is a 0.
For binary strings divisible by 22 we check if the last char from right is a 00.
...
For binary strings divisible by 25 we check if the last char from right is a 00000
So, we need 6 states for counting the number of 0's on right, from 0 to 5.
-- Arjun Suresh
GATE2015-1_3 top
For any two languages L 1 and L 2 such that L 1 is context-free and L 2 is recursively enumerable but not recursive, which of the following is/are
necessarily true?
I. L̄ 1 ( Compliment of L 1 ) is recursive
II. L̄ 2 ( Compliment of L 2 ) is recursive
III. L̄ 1 is context-free
1
1
IV. L̄ 1 ∪ L 2 is recursively enumerable
A. I only
B. III only
C. III and IV only
D. I and IV only
D.
L1 is context-free and hence recursive also. Recursive set being closed under complement, L1' will be recursive.
L1' being recursive it is also recursively enumerable and Recursively Enumerable set is closed under Union. So, L1' U L2 is recursively
enumerable.
Context free languages are not closed under complement- so III is false
Recursive set is closed under complement. So, if L2' is recursive, (L2')' = L2 is also recursive which is not the case here. So, II is also false.
-- Arjun Suresh
GATE2015-2_35 top
Consider the alphabet Σ = {0, 1} , the null/empty string λ and the set of strings X 0 , X 1 , and X 2 generated by the corresponding non-terminals
of a regular grammar. X 0 , X 1 , and X 2 are related as follows.
X 0 = 1X 1
X 1 = 0X 1 + 1X 2
X 2 = 0X 1 + {λ}
Which one of the following choices precisely represents the strings inX 0 ?
A. 10(0*+(10)*)1
B. 10(0*+(10)*)*1
C. 1(0+10)*1
D. 10(0+10)*1 +110(0+10)*1
option c is correct because look at the smallest string generated by the grammar is 11 which is not accepted by any option.
-- Anoop Sonkar
GATE2015-2_51 top
L1 : {wxw R ∣ w, x ∈ {a, b} ∗ and |w|, |x| > 0}, w R is the reverse of string w
L2 : {an b m ∣ m ≠ n and m, n ≥ 0}
L3 : {ap b q c r ∣ p, q, r ≥ 0}
A. L1 and L 3 only
B. L2 only
C. L2 and L 3 only
D. L3 only
Ans A.
L1: all strings of length 3 or more with same start and end letter- because everything in middle can be consumed by x as per the definition of
L.
L2: We need to compare number of a's and b's and these are not bounded. So, we need at least a DPDA.
L3: Any number of a's followed by any number of b's followed by any number of c's. Hence regular.
-- Vikrant Singh
GATE2015-1_51 top
Consider the NPDA ⟨Q = {q 0 , q 1 , q 2 }, Σ = {0, 1}, Γ = {0, 1, ⊥ }, δ, q 0 , ⊥, F = {q 2 }⟩ , where (as per usual convention) Q is the set of states,Σ
is the input alphabet, Γ is the stack alphabet, δ is the state transition function q0 is the initial state, ⊥ is the initial stack symbol, and F is the set
of accepting states. The state transition is as follows:
Which one of the following sequences must follow the string 101100 so that the overall string is accepted by the automaton?
A. 10110
B. 10010
C. 01010
D. 01001
In q 0 state for '1', a '1' is pushed and for a '0' a '0' is pushed. In q1 state, for a '0' a '1' is popped and for a '1' a '0' is popped. So, the given PDA
is accepting all strings of of the form x0x'r or x1x'r, where x'r is the reverse of the 1's complement of x.
The given string 101100 has 6 letters and we are given 5 letter strings. So, x0 is done, with x = 10110. So, x'
r = (01001)r = 10010.
B choice.
-- Arjun Suresh
GATE2015-1_52 top
Consider the DFAs M and N given above. The number of states in a minimal DFA that accept the language L(M) ∩ L(N) is_____________.
So, L(M) ∩ L(N) = {}. So, in the minimal DFA, we just have 1 start state with all transitions going to it self and no final state.
-- Arjun Suresh
GATE2015-3_18 top
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̄ (complement of L)?
A. 4
B. 5
C. 6
D. 8
first we can draw dfa for L which has 5 states after that for L compliment we will convert all final to non final and all non final to final so total
states is 5 .. option B
-- Anoop Sonkar
GATE2015-3_32 top
L1 : {am b n an b m ∣ m, n ≥ 1}
L2 : {am b n am b n ∣ m, n ≥ 1}
L3 : {am b n ∣ m = 2n + 1}
A. L1 and L 2 only
B. L1 and L 3 only
C. L2 and L 3 only
D. L3 only
first check for L1. now look a^m&b^m and a^n&b^n must b comparable using one stack for CFL.
now take a stack push all a^m in to the stack then push all b^n in to stack now a^n is coming so pop b^n for each a^n by this
b^n and a^n will b comparable. now we have left only a^m in stack and b^m is coming so pop a^m for each b^m by which we
can compare a^m to b^m ..we conclude that we are comparing this L1 using a single stack so this is CFG.
now for L2.this can not be done in to a single stack because m and n are not comparable we can not find when to push or
pop so this is CSL.
now for L3. push all a's in to stack and pop a single a for every 2b and after popping all a's with 2 b's we will get a single b in
stack so this comparable hence L3 is CFG.
so the option is B.. L1 and L3 are CFG
-- Anoop Sonkar
L1 is a finite language n L2 is a language, if L1 intersection L2 is empty and L1 union L2 is regular, than L2 is-
regular n finite
regular n infinite
need not to be regular
none of these
Let L2 = compl(L1). Now, L1 intersect L1 is empty and L1 union L2 is ∑* and hence regular. And L2 here is regular and infinite - so A option is
eliminated.
Now, we have L1 union L2 as regular and hence we have a DFA (say D) for it. We also have DFA for L1 (say D1). Now, we can make a DFA
for L2 (say D2) by doing D intersect compl(D1), as complement of a regular language is regular and regular set is closed under intersect. So,
L2 must be regular.
Now, consider L2 = {}. Now, L1 intersect L2 is empty and L1 union L2 is L1 which is regular. But here, L2 is regular and finite.
a) 2
b) 3
c) 4
d) 5
if we use stack symbols as {z0,A} where initial stack symbol is {z0} and final state is {q2} than if the transition functions are-
q2 is final state..
NFA for the language, L= (ab, ba)* would have how many states? top
Having 3 states
have 4 states
-- Praveen Saini
Build an FA that accepts the language of all strings of a's and b's such that next-to-last
letter is an a top
alphabet set is {a,b}
if you mean to say second last symbol is always a
regular expression = anything secondlast last = (a+b)* a (a+b) [ second last is a , last is either a or b ]
-- Praveen Saini
How many DFA's exist with three states over the input alphabet {0,1} top
Thanks in advance
Input set is given. So, we have 3 parts of DFA which we can change:
1. Start state
2. Transition Function
3. Final state
Transition function is from Q ⨯ Z to Q, where Q is the set of states and Z is the alphabet state. |Q| = 3, |Z| = 2. So, number of possible
transition functions = 3(3 * 2) = 36
Final state can be any subset of the set of states including empty set. With 3 states, we can have 23 = 8 possible sub states.
= 3 × 3 6 × 2 3 = 17496
n × n nm × 2 n = n mn+1 × 2 n
-- Arjun Suresh
Question of regular expression top
(a) (i) ,(ii) are equal and (ii) , (iii) are not .
(b) (i) ,(ii) are equal and (i) , (iii) are not .
(c) (ii) ,(ii) are equal and (i) , (ii) are not .
But , my question is :
from (ii) (a∗ /b ∗ )∗ : I can derive (a/ϵ)∗ , which can give me (a)* . Isn't it so ?
1. (a + b)*
2. (a* + b*)* =(a+b) *
3. ((null + a)b*)* = (b* + ab*)*
= ((null + b + bb + bbb + .....) + a(null + b + bb + bbb + .....))*
= (b + a + a(all string of b) + null + (all string of b except ))* //rearranging b*
= (a +b + rest) *
Answer given as : e
But , my question is (P*Q*) * = {null string , any number of P , any number of Q , P followed by Q , }
whereas (P*+Q*)* = { null string , any number of P , any number of Q , P followed by Q , Q followed by P }
Q 1.
In case of L3 , it can also be resolved using a single stack . So , this is also CFL.
Q2.
Q1.
L1 = {apc2p | p ≥ 0} is DCFL
L2 is CFL but not DCFL as we cannot deterministically check two unbounded conditions using a single check but the conditions being OR we
can do this non-deterministically.
L3 again is CFL but not DCFL. At every point we have two options- to equal the number of 0's or to double the number of 0's.
Q2.
-- Arjun Suresh
A) n*(n+1)/2 - 1
B) n*(n+1)/2
C) n*(n+1)/2 + 1
I basically want a good explanation here for whatever option you choose???thanks in advance .
1. a
2. b
3. c
4. ab
5. bc
6. abc
For a string of length n, we can have 1 sub-string of length n, 2 sub-strings of length n-1, 3 sub-strings of length n-2, ... n substrings of length
1. So, total no. of sub-strings = 1 + 2 + ... + n = n (n+1)/2
But the question asks for "proper" sub-strings. Proper sub-string means the given string (of length n) must not be counted. So, the answer
must be n(n+1)/2 - 1.
Ref: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/StringMatch/stringMatchIntro.htm
-- Arjun Suresh
A) (1*0)*1*
B) 0+(0+10)+
C) (0+1)*10(0+1)*
well according to me in option A we can get 111111...(many no of one's) without the need of 0, but same is not the case with the original R.E
posted above, where in i have to get 0's in order to get 1's in my strings. <answer given is option A> what do you say guys??
CFLs are not closed under complement. So , how can the answer be (d) ?
A. is clearly CSL. // CFL can do string matching in order likr WWr but not as WW
C. Again CSL. two infinite comparison on same variable 'n' simultaneously.. PDA cant simulate.
LET A be CFL & its complement is B which is CSL.. now some one asking what is complement of CSL 'B' ?? Obviously answer will be A
which is CFL only..
S(odd) ----> 0A | 1A | 0 | 1
S(even) ----> BC | CB
B ----> DBD | 0
C ----> DCD | 1
D ----> 0 | 1
-- Digvijay Pandey
Computer Networks top
GATE2012_10 top
The protocol data unit (PDU) for the application layer in the Internet stack is
(A) Segment
(B) Datagram
(C) Message
(D) Frame
For Transport layer, PDU is segment for TCP and datagram for UDP
If a organisation requires 30 hosts.which is the best possible mask that can be used? top
Since organistation has 30 hosts, Class C network with /24 Prefix should be used since it can support 254 hosts.
Now there are 30 hosts, so the minimum number of bits required for host number is 5, since 2 5 − 2 is 30.
GATE1992_03,v top
Answer is C
-- saurabhrk
GATE2003_82 top
The subnet mask for a particular network is 255.255.31.0. Which of the following pairs of IP addresses could belong to this network?
Consider B,
Consider D.
-- Arjun Suresh
GATE2003_84 top
Host A is sending data to host B over a full duplex link. A and B are using the sliding window protocol for flow control. The send and receive
window sizes are 5 packets each. Data packets (sent only from A to B) are all 1000 bytes long and the transmission time for such a packet is
50 μs. Acknowledgement packets (sent only from B to A) are very small and require negligible transmission time. The propagation delay over
the link is 200 μ s. What is the maximum achievable throughput in this communication?
I think options are given in bytes per sec instead of bits per sec.
total number of bits transmitted before first ACK is received = 1000x5x8 bits =40000 bits
Throughput = (40000/450) x10^6 bits = 88.88x10^6 bits ps=11.11x10^6 bytes per sec
-- Parul Agarwal
GATE2004_15 top
Group - 1 Group -2
1. Ensures reliable transport of data over a physical point-to-point
P. Data link layer
link
Q. Network layer 2. Encodes/decodes data for physical transmission
R. Transport
3. Allows end-to-end communication between two processes
layer
4. Routes data from one network node to the next
GATE2007_19 top
Bit rate is half the baud rate in Manchester encoding as bits are transferred only during a positive transition of the clock.
http://stackoverflow.com/questions/25834577/why-in-manchester-encoding-the-bit-rate-is-half-of-the-baud-rate
-- Arjun Suresh
GATE2007_70 top
P - 2, Q - 1, R - 3, S - 5
P - 1, Q - 4, R - 2, S - 3
P - 1, Q - 4, R - 2, S - 5
P - 2, Q - 4, R - 1, S - 3
https://docs.oracle.com/cd/E18752_01/html/816-4554/ipov-6.html
-- Madhur Rawat
GATE2009_57,58 top
Frames of 1000 bits are sent over a 106 bps duplex link between two hosts. The propagation time is 25ms. Frames are to be transmitted into
this link to maximally pack them in transit (within the link).
57. What is the minimum number of bits (I) that will be required to represent the sequence numbers distinctly? Assume that no time gap needs
to be given between transmission of two frames.
A. I=2
B. I=3
C. I=4
D. I=5
58. Suppose that the sliding window protocol is used with the sender window size of2 l , where I is the numbers of bits identified in the earlier
part and acknowledgements are always piggy backed. After sending 2 I frames, what is the minimum time the sender will have to wait before
starting transmission of the next frame? (Identify the closest choice ignoring the frame processing time.)
A. 16ms
B. 18ms
C. 20ms
D. 22ms
So, to fully utilize the channel, we must send 106 bits into the channel in a second, which will be 1000 frames per second as each frame is
1000 bits. Now, since the propagation time is 25 ms, to fully pack the link we need to send at least 1000 * 25 * 10-3 = 25 frames. So, we need
⌈log 2 25⌉ = 5 bits.
Now, we need to get RTT (which is the time between which a frame is sent and its ACK is received), to determine the waiting time.
RTT = Propagation time for frame + Transmission time for frame + Propagation time for ACK + Transmission time for ACK
= 25 ms + 1 ms + 25 ms + 1 ms (ACK is piggy backed and assuming frame size for piggy backing is also 1000 bits)
= 52 ms
-- Arjun Suresh
GATE2005_23 top
Packets of the same session may be routed through different paths in:
Routing happens in Network layer and hence has no dependency with the the transport layer protocols TCP and UDP. The transport layer
protocol- whether TCP or UDP is hidden to the router and the routing path is determined based on the the network configuration at the time
and hence can change even during a session.
-- Arjun Suresh
GATE2005_24 top
The address resolution protocol (ARP) is used for:
ans d)
-- Aditi Dan
GATE2005_25 top
The maximum window size for data transmission using the selective reject protocol with n − bit frame sequence numbers is:
ans b)
In selective reject protocol, the maximum window size must be half the sequence number space = n2/2 = 2n-1.
http://webmuseum.mi.fh-offenburg.de/index.php?view=exh&src=73
-- Aditi Dan
GATE2005_74 top
Suppose the round trip propagation delay for a 10 Mbps Ethernet having 48-bit jamming signal is 46.4 µs. The minimum frame size is:
A. 94
B. 416
C. 464
D. 512
The sender must be able to detect a collision before completely sending a frame. So, the minimum frame length must be such that, before the
frame completely leaves the sender any collision must be detected.
Now, the worst case for collision detection is when the start of the frame is about to reach the receiver and the receiver starts sending.
Collision happens and a jam signal is produced and this signal must travel to the sender. So, the time for this will be propagation delay for the
start of the frame to reach near the receiver + propagation delay for the jam signal to reach the sender + transmission time for the jam signal.
(We don't need to include propagation time for the frame as as soon as the first bit of the frame arrives, the receiver will have detected it). So,
this will be
2 * 46.4/2 + 48/10 (48 bits at 10 Mbps takes 4.8 micro sec.) = 51.2 µs.
Now, the frame length must be such that its transmission time must be more than 51.2 µs. So, minimum frame length
http://gatecse.in/w/images/3/32/3-MACSublayer.ppt
-- Arjun Suresh
GATE2014-1_24 top
Which of the following are used to generate a message digest by the network security protocols?
RSA and DES are used for Encryption where MD5 and SHA 1 are used to generate Message
Digest.
-- Shiva Chaitanya Gajula
GATE2014-1_26 top
Consider a token ring network with a length of 2 km having 10 stations including a monitoring station. The propagation speed of the signal is
2 × 108 m/s and the token transmission time is ignored. If each station is allowed to hold the token for2µsec , the minimum time for which the
monitoring station should wait (in µsec ) before assuming that the token is lost is _______.
= 10 + 10 * 2 = 30 µs
-- Rajat Sharma
GATE2014-1_27 top
Let the size of congestion window of a TCP connection be 32 KB when a timeout occurs. The round trip time of the connection is 100 msec and the maximum
segment size used is 2 KB. The time taken (in msec) by the TCP connection to get back to 32 KB congestion window is _________.
Ans: Given that at the time of Time Out, Congestion Window Size is 32KB and RTT = 100ms ,
When Time Out occurs, for the next round of Slow Start, Threshold = (size of Cwnd) / 2 ,
It means Threshold = 16KB
So , we have Slow start ==>> 2KB | 4KB | 8KB | 16KB (now threshold reaches so Additive increase starts) | 18KB | 20KB | 22KB |
24KB | 26KB | 28KB | 30KB | 32KB
So, in above number of | (vertical line) is represented by RTT so total number of vertical line is 11 * 100ms ==>> 1100 msec is
Answer...
-- Jayesh Malaviya
GATE2006_46 top
Station A needs to send a message consisting of 9 packets to Station B using a sliding window (window size 3) and go-back-n error control
strategy. All packets are ready and immediately available for transmission. If every 5th packet that A transmits gets lost (but no acks from B
ever get lost), then what is the number of packets that A will transmit for sending the message to B?
(A) 12
(B) 14
(C) 16
(D) 18
Since all packets are ready initially itself, we can assume a timeout is detected after all possible packets are sent. So, the sending happens as
shown in figure (I draw the figure assuming 10 packets. For 9 packets answer will be 16).
-- Arjun Suresh
GATE2011_2 top
A layer-4 firewall (a device that can look at all protocol headers up to the transport layer) CANNOT
(C) stop incoming traffic from specific IP address but allow outgoing traffic to the same IP address
(D) block TCP traffic from a specific user on a multi-user system during 9:00PM to 5:00AM
Answer is (D).
(A) It is POSSIBLE to block "entire" HTTP traffic by blocking all the traffic on port number 80 Since here we DON'T need to check anything that is application layer specific. We only need to
block port no 80 for required time span.
(D) However (D) is not possible to achieve although the service uses TCP at transport layer. But see the question. We dont need to block entire TCP traffic so we cant block any specific
PORT number. Also it is given that IT IS MULTI- USER System and so many user may be using same port for communication. Therefore blocking that port would block all the users WHILE
we want a specific user. So how to do that. To do so we need Application layer specific information of the user like user_id type of things which cant be checked as it is 4-layer firewall.
So it is not possible to allow other users and block some specific at the same time using a 4-layer firewall (unless they all be using different port numbers which we actually cant predict).
-- Sandeep_Uniyal
GATE2010_15 top
One of the header fields in an IP datagram is the Time-to-Live (TTL) field. Which of the following statements best explains the need for this field?
-- Sankaranarayanan P.N
GATE1995_1.12 top
What is the distance of the following code 000000, 010101, 000111, 011001, 111111?
A. 2
B. 3
C. 4
D. 1
Distance (also called min-distance) of a block code is the minimum number of positions in which any two distinct codes differ. Here, min-
distance occurs for the codes 2 and 3 and they differ only in 2 positions. So, d = 2.
https://en.wikipedia.org/wiki/Block_code
-- Arjun Suresh
GATE2008-IT_65 top
8m/s
The minimum frame size required for a CSMA/CD based computer network running at 1 Gbps on a 200m cable with a link speed of 2 × 10
is
A) 125 bytes
B) 250 bytes
C) 500 bytes
D) None of the above
Minimum frame size is needed to ensure that collisions are detected properly. The minimum frame size ensures that before a frame is
completely send, it would be notified of any possible collision and hence collision detection works perfectly.
In CSMA/CD a sender won't send a packet if it senses that another sender is using it. So, assume a sender A and a receiver B. When sender
sends a packet, receiver might use the cable until it is notified that a packet is being send to it. The receiver will be notified as soon as the first
bit arrives that a packet is coming and it won't send any packet after this until that packet is finished. So, in the worst case for collision,
receiver will transmit a packet back to the sender just before the first bit of the packet reaches it. (If t d is the propagation delay of the channel,
this time would be just t d ). In this case, surely there will be collision. But for the sender to detect it, it should be notified of B's packet before
the sending of the first packet finishes. i.e., when B's packet arrives at A (takes another t d time), A shouldn't have finished transmission of the
first packet for it to detect a collision. i.e., A should be still continuing the sending of the packet in this time interval of 2 × t d . Thus,
The amount of bits that can be transmitted by A in 2 × t d time should be less than the frame size (S) (sending of the frame shouldn't finish in
this time)
So, S ≥ 2 × bandwidth × t d
≥ 2 × 109 × 200
2×108
≥ 2000 bits
≥ 250 bytes
-- Arjun Suresh
GATE2008-IT_70 top
The total number of keys required for a set ofn individuals to be able to communicate with each other using secret key and public key
cryptosystems, respectively are:
A) n(n-1) and 2n
B) 2n and ((n(n - 1))/2)
C) ((n(n - 1))/2) and 2n
D) ((n(n - 1))/2) and n
For private key crypto for communication between each pair of individuals on secret key will be required, so if a individual wants to
communicate with other n-1 individuals he should have n-1 secret keys, so the total number of secret keys for private encryption is n*(n-1).
For public key encryption each individual needs to have a public and private key, so the total keys required in 2*n
-- Omesh Pandita
GATE2008-IT_85 top
Host X has IP address 192.168.1.97 and is connected through two routers R1 and R2 to another host Y with IP address 192.168.1.80. Router
R1 has IP addresses 192.168.1.135 and 192.168.1.110. R2 has IP addresses 192.168.1.67 and 192.168.1.155. The netmask used in the
network is 255.255.255.224.
1) 192.168.1.67
2) 192.168.1.110
3) 192.168.1.135
4) 192.168.1.155
Now, the gateway must also have the same subnet number. Lets take IP 192.168.1.110 of R1. 192.168.1.110 &
255.255.255.224 =192.168.1.96 and hence this can be used by X.
(To quickly identify the matching mask divide the last part of mask (224 here) into powers of 2. So, 224 = 128 + 64 + 32. Now, our host X has
97 as the last part of IP = 64 + 32 + 1. So, the last part of subnet number becomes 64 +32 =96. Now, we need to consider only those IPs
whose last part will contain 64 as well as 32)
http://courses.washington.edu/css432/joemcc/slides/03_cidr.ppt
-- Arjun Suresh
GATE2007-IT_64 top
A broadcast channel has 10 nodes and total capacity of 10 Mbps. It uses polling for medium access. Once a node finishes transmission, there
is a polling delay of 80 μs to poll the next node. Whenever a node is polled, it is allowed to transmit a maximum of 1000 bytes. The maximum
throughput of the broadcast channel is
1) 1 Mbps
2) 100/11 Mbps
3) 10 Mbps
4) 100 Mbps
GATE2006-IT_70 top
A subnetted Class B network has the following broadcase address : 144.16.95.255. Its subnet mask
A) is necessarily 255.255.224.0
B) is necessarily 255.255.240.0
C) is necessarily 255.255.248.0.
D) could be any one of 255.255.224.0, 255.255.240.0, 255.255.248.0
option (D) is correct. In the broadcast address for a subnet, all the host bits are set to 1. So as long as all the bits to the right are 1, bits left to
it can be taken as possible subnet.
broadcast address for subnet is .95.255 .0101 1111. 1111 1111 (as in Class B, 16 bits each are used for network and host)
So we can take minimum 3 bits (from left) as subnet and make rest as host bits(as they are 1).
GATE2004-IT_25 top
A sender is employing public key cryptography to send a secret message to a receiver. Which one of the following statements is TRUE?
-- Omesh Pandita
GATE2004-IT_26 top
A subnet has been assigned a subnet mask of 255.255.255.192. What is the maximum number of hosts that can belong to this subnet?
A) 14
B) 30
C) 62
D) 126
GATE2004-IT_27 top
A host is connected to a Department network which is part of a University network. The University network, in turn, is part of the Internet. The
largest network in which the Ethernet address of the host is unique is
Ans is D, Ethernet address is nothing but MAC Address which is present on NIC and it is unique for every system.
-- Pradyumna Paralikar
GATE2004-IT_28 top
A) byte
B) word
C) segment
D) message
a) it should be byte
http://www.industrialethernetu.com/courses/202_2.htm
-- Parul Agarwal
GATE2004-IT_45 top
A serial transmission T1 uses 8 information bits, 2 start bits, 1 stop bit and 1 parity bit for each character. A synchronous transmission T2 uses
3 eight-bit sync characters followed by 30 eight-bit information characters. If the bit rate is 1200 bits/second in both cases, what are the transfer
rates of T1 and T2?
In 264 = 30 character
Then 1200 = ?
264/30 = 1200/X
-- Shreyans Dhankhar
GATE2004-IT_80 top
In a data link protocol, the frame delimiter flag is given by 0111. Assuming that bit stuffing is employed, the transmitter sends the data
sequence 01110110 as
A) 01101011
B) 011010110
C) 011101100
D) 0110101100
The bit stuffing is done after every two '11' (as flag is 0111) to differentiate the data part from the flag- there must not be "111" in the data so
after every 11 a '0' is added. The receiver also knows this and so it decodes every "110" as "11". Therefore option D. is the answer.
http://web.nchu.edu.tw/~pcwang/computer_networks/data_link_layer.pdf
https://en.wikipedia.org/wiki/High-Level_Data_Link_Control
-- Gate Keeda
GATE2004-IT_81 top
In a sliding window ARQ scheme, the transmitter's window size is N and the receiver's window size is M. The minimum number of distinct
sequence numbers required to ensure correct operation of the ARQ scheme is
A) min (M, N)
B) max (M, N)
C) M+N
D) MN
C) M+N
Because Ws+Wr ≤ Sequence numbers (as the maximum number of unacknowledged packets at sender will be Ws and at the receiver it will
be Wr, similar to the sequence numbering in Selective Repeat)
GATE2004-IT_86 top
In the TCP/IP protocol suite, which one of the following is NOT part of the IP header?
A) Fragment Offset
B) Source IP address
C) Destination IP address
D) Destination port number
Why? Because the IP header has nothing to do with the port number.
Port numbers are used by the transport layer to ensure process to process delivery.
-- Gate Keeda
GATE2005-IT_25 top
RCPT->Recipient to,As the name suggest it is used in SMTP(Simple Mail Transfer protocol)
HEAD->this is used in HTTP to get the meta-information,to decide the category of packet.
Prompt->turns off prompting for individual files when using the mget or mput commands
-- nagalla pruthvi
GATE2005-IT_26 top
Traceroute reports a possible route that is taken by packets moving from some host A to some other host B. Which of the following options
represents the technique used by traceroute to identify these hosts
1) By progressively querying routers about the next router on the path to B using ICMP packets, starting with the first router
By requiring each router to append the address to the ICMP packet as it is forwarded to B. The list of all routers en-route to B is returned by
2)
B in an ICMP reply packet
3) By ensuring that an ICMP reply packet is returned to A by each router en-route to B, in the ascending order of their hop distance from A
4) By locally computing the shortest path from A to B
A) Traceroute works by sending packets with gradually increasing TTL value, starting with TTL value of 1. The first router receives the packet, decrements the
TTL value and drops the packet because it then has TTL value zero. The router sends an ICMP Time Exceeded message back to the source. The next set of
packets are given a TTL value of 2, so the first router forwards the packets, but the second router drops them and replies with ICMP Time Exceeded. Proceeding
in this way, traceroute uses the returned ICMP Time Exceeded messages to build a list of routers that packets traverse, until the destination is reached and
returns an ICMP Echo Reply message
-- Shaun Patel
GATE2005-IT_71 top
A network with CSMA/CD protocol in the MAC layer is running at 1 Gbps over a 1 km cable with no repeaters. The signal speed in the cable is
2 x 10 8 m/sec. The minimum frame size for this network should be
A) 10000 bits
B) 10000 bytes
C) 5000 bits
D) 5000 bytes
Minimum frame size is needed to ensure that collisions are detected properly. The minimum frame size ensures that before a frame is
completely send, it would be notified of any possible collision and hence collision detection works perfectly.
In CSMA/CD a sender won't send a packet if it senses that another sender is using it. So, assume a sender A and a receiver B. When sender
sends a packet, receiver might use the cable until it is notified that a packet is being send to it. The receiver will be notified as soon as the first
bit arrives that a packet is coming and it won't send any packet after this until that packet is finished. So, in the worst case for collision,
receiver will transmit a packet back to the sender just before the first bit of the packet reaches it. (If t d is the propagation delay of the channel,
this time would be just t d ). In this case, surely there will be collision. But for the sender to detect it, it should be notified of B's packet before
the sending of the first packet finishes. i.e., when B's packet arrives at A (takes another t d time), A shouldn't have finished transmission of the
first packet for it to detect a collision. i.e., A should be still continuing the sending of the packet in this time interval of 2 × t d . Thus,
The amount of bits that can be transmitted by A in 2 × t d time should be less than the frame size (S) (sending of the frame shouldn't finish in
this time)
So, S ≥ 2 × bandwidth × t d
≥ 2 × 109 × 1000
2×108
≥ 10000 bits
-- Arjun Suresh
GATE2005-IT_73 top
On a TCP connection, current congestion window size is Congestion Window = 4 KB. The window size advertised by the receiver is Advertise
Window = 6 KB. The last byte sent by the sender is LastByteSent = 10240 and the last byte acknowledged by the receiver is LastByteAcked =
8192. The current window size at the sender is
A) 2048 bytes
B) 4096 bytes
C) 6144 bytes
D) 8192 bytes
Answer is (A)
Current Sender window = min (Congestion Window, Advertised Window)= min(4KB, 6KB)= 4B
Since 2KB data is unacknowledged it can send only (Current window- Unacknowledged Bytes)= 4KB- 2KB =2KB = 2048 Bytes
-- Sandeep_Uniyal
GATE2015-2_20 top
Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API.
Answer: B
It extracts the first connection request on the queue of pending connections for the listening socket, creates a new connected socket, and
returns a new file descriptor referring to that socket. The newly created socket is not in the listening state. The original socket is unaffected
by this call
-- Jon Snow
GATE2015-2_34 top
Assume that the bandwidth for a TCP connection is 1048560 bits/sec. Letα be the value of RTT in milliseconds (rounded off to the nearest
integer) after which the TCP window scale option is needed. Let β be the maximum possible window size with window scale option. Then the
values of α and β are
A. 63 milliseconds, 65535 ×2 14
B. 63 milliseconds, 65535 ×2 16
C. 500 milliseconds, 65535 ×2 14
D. 500 milliseconds, 65535 ×2 16
In TCP when the bandwidth delay product increases beyond 64K receiver window scaling is needed.
The bandwidth delay product is the maximum amount of data on the network circuit at any time and is measured as RTT * Bandwidth. This is
not the time for sending data rather just the time for sending data without acknowledgement.
When window scaling happens, a 14 bit shift count is used in TCP header. So, the maximum possible window size gets increased from 16
2-
1 to (216-1) * 214 or from 65535 to 65535 * 214
http://en.wikipedia.org/wiki/TCP_window_scale_option
-- Arjun Suresh
GATE2015-1_17 top
In one of the pairs of protocols given below , both the protocols can use multiple TCP connections between the same client and the server.
Which one is that?
A. HTTP, FTP
B. HTTP, TELNET
C. FTP, SMTP
D. HTTP, SMTP
Ref: https://tools.ietf.org/html/rfc821
Ref: https://tools.ietf.org/html/rfc854
Ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1
FTP: FTP uses Telnet protocol for Control info on a TCP connection and another TCP connection for data exchange
So, answer is A.
-- Arjun Suresh
GATE2015-1_19 top
Suppose two hosts use a TCP connection to transfer a large file . Which of the following statements is/are FALSE with respect to the TCP
connection?
I. If the sequence number of a segment is m, then the sequence number of the subsequent segment is always m+1.
II. If the estimated round trip time at any given point of time is t sec, the value of the retransmission timeout is always set to greater than or
equal to t sec.
III. The size of the advertised window never changes during the course of the TCP connection.
IV. The number of unacknowledged bytes at the sender is always less than or equal to the advertised window.
A. III only
B. I and III only
C. I and IV only
D. II and IV only
Option B
III. False. It is the size of the receiver's buffer that's never changed. RcvWindow is the part of the receiver's buffer that's changing all the time
depending on the processing capability at the receiver's side and the network traffic.
http://web.eecs.utk.edu/~qi/teaching/ece453f06/hw/hw7_sol.htm
-- GATERush
GATE2015-1_22 top
A. Check sum
B. Source address
C. Time to Live (TTL)
D. Length
Source Address.
-- Arjun Suresh
GATE2015-2_52 top
Host A sends a UDP datagram containing 8880 bytes of user data to host B over an Ethernet LAN. Ethernet frames may carry data up to 1500
bytes (i.e. MTU = 1500 bytes). Size of UDP header is 8 bytes and size of IP header is 20 bytes. There is no option field in IP header. How
many total number of IP fragments will be transmitted and what will be the contents of offset field in the last fragment?
A. 6 and 925
B. 6 and 7400
C. 7 and 1110
D. 7 and 8880
Ans C
TCP or UDP header will be added to the DataUnit received from Transport Layer to Network Layer. And fragmentation happens at Network
Layer. So no need to add TCP or UDP header into each fragment.
-- Vikrant Singh
GATE2015-1_53 top
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 transmission time for the acknowledgement and the processing time at nodes are negligible. Then the minimum frame size in
bytes to achieve a link utilization of at least 50% is_________________.
Link Utilization = Amount of data sent/Max. amount of data that could be sent.
In stop-and-wait protocol, once a frame is sent, next frame won't be sent until ACK is received. Time for this,
RTT = Propagation delay for frame + Transmission time for frame + Propagation delay for ACK + Transmission time for ACK
= 20 ms + x /64 ms + 20 ms + 0(as given in question)
= (40 + x/64) ms.
Amount of data sent during RTT = x
Max. amount of data that could be sent = (40 + x/64) * 64 = 2560 + x bits.
GATE2015-3_6 top
Consider a CSMA/CD network that transmits data at a rate of 100 Mbps (108 bits per second) over a 1 km (kilometer) cable with no repeaters.
If the minimum frame size required for this network is 1250 bytes, what is the signal speed (km/sec) in the cable?
A. 8000
B. 10000
C. 16000
D. 20000
For collision to be detected, the frame size should be such that the transmission time of the frame should be greater than twice the
propagation delay (So, before the frame is completely sent, any possible collision will be discovered).
x = 2 * 104 = 20000
-- Arjun Suresh
GATE2015-3_22 top
A. Only I is correct
B. Only I and III are correct
C. Only II and III are correct
D. All of I, II and III are correct
answer is (A) since TCP has options for selective ACK and TCP uses byte streams that is every byte that is send using TCP is numbered.
http://repo.hackerzvoice.net/depot_madchat/ebooks/TCP-IP_Illustrated/tcp_tran.htm
-- Tamojit Chatterjee
GATE2015-3_28 top
Consider a network connecting two systems located 8000 kilometers apart. The bandwidth of the network is 500 × 106 bits per second. The
propagation speed of the media is 4 × 106 meters per second. It is need to design a Go-Back-N sliding window protocol for this network. The
average packet size is 107 bits. The network is to be used to its full capacity. Assume that processing delays at nodes are negligible. Then, the
minimum size in bits of the sequence number field has to be ______.
Answer = 8 bits
In order to achieve full utilization, sender has to keep on sending frames till the acknowledgement arrives for the first frame.
Time taken for acknowledgement to arrive is 2 times propagation delay + transmission time for a frame.
One way propagation time = 8000x10^3 / (4x10^6)
= 2 secs
=0.02 secs
So, RTT = 2 * 2 = 4
=200
Hence minimum number of bits required for sequence numbers till 200 is 8 (as 2^8 = 256)
-- overtomanu
GATE2015-3_38 top
In the network 200.10.11.144/27, the fourth octet (in decimal) of the last IP address of the network which can be assigned to a host is _____.
Answer=158
out of this 3 bits in left are subnet bits. (27 bits are used for subnet, which means top 3 bytes and leftmost 3 bits from the last byte)
so the 4th octet in the last ip address of the network which can be assigned to a host is 100 11110. (its not 100 11111 because its network
broadcast address)
networks top
Response:
Simplex
Half duplex
Full duplex
None of these
I think It is simplex.
half duplex is a two way communication but one way at a time not simultaneous (eg. as walkie-talkie over and out)
X Y (X,Y)
0 0 0
0 1 0
1 0 1
1 1 1
(A) X
(B) X + Y
(C) X ⊕ Y
(D) Y
Whenever X is true (X, Y ) is true and whenever X is false (X, Y ) is false, so the answer is (A) X .
-- Omesh Pandita
GATE2012_7 top
The decimal value 0.5 in IEEE single precision floating point representation has
(B) is the answer. In IEEE uses normalized representation and hence an implicit '1' is used before the decimal point. So, if mantissa is
0000..0
it would be treated as
1.000..0
and hence the exponent need to be -1 for us to get 0.1 which is the binary representation of 0.5.
GATE2012_19 top
The amount of ROM needed to implement a 4 bit multiplier is
(A) 64 bits
(B) 128 bits
(C) 1 Kbits
(D) 2 Kbits
A ROM cannot be written. So, to implement a 4 bit multiplier we must store all the possible combinations of 2 4 ∗ 2 4 input bits and 8 output bits
giving a total of 2 4 ∗ 2 4 ∗ 8 bits = 2048 bits. So, (D) is the answer.
-- Arjun Suresh
GATE1991,05,c top
Find the maximum clock frequency at which the counter(given in figure) can be operated. Assume that the propagation delay through each flip-
flop and AND gate is 10ns. Also assume that the setup time for the JK inputs of the flip-flops is negligible.
In a JK flip flop the output toggles when both J and K inputs are 1. So, we must ensure that with each clock the output from the previous stage
reaches the current stage. From the figure, there is an AND gate between each stage and 2 × 10 = 20ns (10ns for output to reach the gate
and 10ns for the output of AND gate to reach the next flipflop) is needed for the output to reach the next stage. So, minimum time period
needed for of clock is 20ns which would mean a maximum clock frequency of
1/20GHz = 50MHz
-- Arjun Suresh
GATE2005_62 top
D = AX + X'Q'
Y=D
Ai represent the logic level on the line A at the i-th clock period. If we see the timing diagram carefully, we can see that during the rising edge,
the output Y is determined by the X value just before that rising edge. i.e., during the rising edge say for clk2, X value that determines the
output is 1 and not 0 (because it takes some propagation delay for the 0 to reach the flip flop). Similarly, the A output that determines the
output for clk i, is Ai-1
For clk2, X is 1, so D = A = A1
For clk4, X is 1, so D = A = A3
For clk5, X is 1, so D = A = A4
-- Arjun Suresh
GATE2008_6 top
Let r denote number system radix. The only value(s) of r that satisfy the equation √−−−− = 11 , is/are
121 r
(A) decimal 10
(B) decimal 11
Check by substituting all the options given satisfies above relation. (D) is the most appropriate answer
-- Keith Kr
GATE2008_8 top
Given f 1 , f 3 and f in canonical sum of products form (in decimal) for the circuit
f 1 = Σm(4, 5, 6, 7, 8)
f 3 = Σm(1, 6, 15)
f = Σm(1, 6, 8, 15)
then f 2 is
A. Σm(4, 6)
B. Σm(4, 8)
C. Σm(6, 8)
D. Σm(4, 6, 8)
answer - C
GATE2008_26 top
A. P . Q̄
B. P . R̄
C. P . Q̄ + R
D. P . R̄ + Q
Ans is (A) P Q̄
(P + Q̄ )(P Q̄ + P R)(P¯ R̄ + Q̄ )
= (P P Q̄ + P P R + P Q̄ + P Q̄ R)(P¯ R̄ + Q̄ )
= (P Q̄ + P R + P Q̄ + P Q̄ R)(P¯ R̄ + Q̄ )
= P Q̄ + P Q̄R̄ + P Q̄ R
= P Q̄ + P Q̄ (R̄ + R)
= P Q̄ + P Q̄
= P Q̄
-- Keith Kr
GATE1991_01,iii top
-- Keith Kr
GATE1992_02,i top
answer - D
-- ankitrokdeonsns
GATE2000_1.6 top
A. 01010101
B. 11010101
C. 00101011
D. 10101011
2's complement representation is not same as 2's complement of a number. In 2's complement representation positive integers are
represented in its normal binary form while negative numbers are represented in its 2's complement form. So (c) is correct here.
http://www.ele.uri.edu/courses/ele447/proj_pages/divid/twos.html
-- Arjun Suresh
GATE2000_2.14 top
Consider the values of A = 2.0 x 1030 , B = -2.0 x 10 30 , 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
Given 32 bits representation. So, the maximum precision can be 32 bits (In 32-bit IEEE representation, maximum precision is 24 bits but we
take best case here). This means approximately 10 digits.
So, A + C should make the 31st digit to 1, which is surely outside the precision level of A (it is 31st digit and not 31st bit). So, this addition will
just return the value of A which will be assigned to Y.
B choice.
#include<stdio.h>
int main()
{
float a = 2.0e30;
float b = -2.0e30;
float c = 1.0;
float y = a+c;
printf("a = %0.25f y = %0.25f\n",a, y);
y = y + b;
float x = a + b;
printf("x = %0.25f\n",x);
x = x + c;
printf("x = %0.25f\n",x);
}
-- Arjun Suresh
GATE2001_1.11 top
Given the following karnaugh map, which one of the following represents the minimal Sum-Of-Products of the map?
(A) XY + Y ′ Z
(B) W X ′ Y ′ + XY + XZ
(C) W ′ X + Y ′ Z + XY
(D) XZ + Y
answer - A
-- ankitrokdeonsns
GATE2001-2.10 top
(a) ABE
(b) DBC
(c) DE5
(d) 9E7
539 = 512 + 16 + 8 + 2 + 1 = 29 + 24 + 23 + 21 + 20
= (1000011011)2
Now all answers have 12 bits, so we add two 0's at beginning = (001000011011)2
To convert to 2's complement invert all bits till the rightmost 1, which will be (110111100101)2
= (DE5)16
-- Arjun Suresh
GATE2001.2.11 top
Consider the circuit shown below. The output of a 2:1 Mux is given by the function(ac ′ + bc).
(B) f = X1 ′ X2 + X1X2 ′
(C) f = X1X2 + X1 ′ X2 ′
(D) f = X1 + X2 ′
g = x1'
So, f = ac' + bc
= x1'x2' + x1x2
So, (C).
-- Arjun Suresh
GATE2001_2.12 top
Consider the circuit given below with initial state Q 0 = 1, Q 1 = Q 2 = 0 . The state of the circuit is given by the value4Q 2 + 2Q 1 + Q 0
A. 1, 3, 4, 6, 7, 5, 2
B. 1, 2, 5, 3, 7, 6, 4
C. 1, 2, 7, 3, 5, 6, 4
D. 1, 6, 5, 7, 2, 3, 4
-- Arjun Suresh
GATE2003_44 top
Let zk , n k denote the number of 0’s and 1’s respectively in initialk bits of the input
(zk + n k = k). The circuit outputs 00 until one of the following conditions holds.
zk − n k = 2 . In this case, the output at thek-th and all subsequent clock ticks is 10.
n k − zk = 2 . In this case, the output at thek-th and all subsequent clock ticks is 01.
What is the minimum number of states required in the state transition graph of the above circuit?
A. 5
B. 6
C. 7
D. 8
Though the question is from digital logic, answer is purely from automata. As per question, we just need to count the difference of the number
of 0's and 1's in the first k bit of a number. And we just need to count till this count reaches 2 or -2 (negative when number of 0's is less than
number of 1's) . So, the possibilities are -2, -1, 0, 1 and 2 which represents the five states of the state transition diagram.
For state -2, the output of the circuit will be 01, for state 2, output will be 10 (both these states not having any outgoing transitions) and for
other 3 states, output will be 00 as per the given description of the circuit.
-- gatecse
GATE2009_5 top
(1217)8 is equivalent to
A. (1217)16
B. (028F )16
C. (2297)10
D. (0B17)16
Answer is B.
-- Praneeth A S
GATE2005_16 top
The range of integers that can be represented by an n bit 2’s complement number system is:
A. −2 n−1 to (2 n−1 − 1)
C. −2 n−1 to 2 n−1
answer - A
-- ankitrokdeonsns
GATE2005_17 top
(a) 1AF
(b) D78
(c) D71
(d) 32F
-- Arjun Suresh
GATE2005_64 top
The flip-flops are positive edge triggered D FFs. Each state is designated as a two-bit stringQ 0 Q 1 . Let the initial state be 00. The state
transition sequence is
A.
B.
C.
D.
Clearly Q0 alternates in every clk cycle as Q0' is fed as input and it is D flipflop.
So, the sequence of transitions will be 00 -> 11 -> 00 -> (B) choice.
-- Arjun Suresh
GATE2013_5 top
Inputs Outputs
D0 D1 D2 D3 X0 X1 V
0 0 0 0 x x 0
1 0 0 0 0 0 1
x 1 0 0 0 1 1
x x 1 0 1 0 1
x x x 1 1 1 1
Answer is A.
For
http://en.wikipedia.org/wiki/Priority_encoder
-- Praneeth A S
GATE1999_2.16 top
answer - B
for addition of subsequent bits we need full adders since carry from previous addition has to be fed into the addition operation
-- ankitrokdeonsns
GATE1999_2.17 top
A. Sign magnitude
B. 2's complement
C. 1's complement
D. None of the above
GATE1998_1.14 top
2^n:1
GATE1998_2.8 top
Which of the following operations is commutative but not associative?
A. AND
B. OR
C. NAND
D. EXOR
we all know AND ,OR are both associative and commutative.we dont know about EXOR and NAND
we can consume some time and prove it by truth table..and come up with the results that EXOR is also associative and commutative so the
only left out is NAND its commutative but not associative
-- Bhagirathi Nayak
GATE1998_2.20 top
I assume byte addressable memory- nothing smaller than a byte can be used.
We have four digits. So, to represent signed 4 digit numbers we need 5 bytes- 4 for four digits and 1 for the sign. So, required memory = 5
bytes
Now, if we use integer, the largest number needed to represent is 9999 and this requires 2 bytes of memory for signed representation.
(5−2) 3
So, memory savings while using integer is
5
= 5
= 60%
-- Arjun Suresh
GATE2014-1_8 top
The base (or radix) of the number system such that the following equation holds is____________.
312
20
= 13.1
By solving above quadratic equation you will get x=0 and x=5
-- vinodmits
GATE2006_39 top
We consider the addition of two 2’s complement numbers b n−1 b n−2 . . . . . b 0 and an−1 an−2 . . . . . a0. A binary adder for adding unsigned binary
numbers is used to add the two numbers. The sum is denoted by c n−1 c n−2 . . . . . c 0 and the carry-out by c out . Which one of the following options
correctly identifies the overflow condition?
(A) c out (¯
a¯¯n−1
¯¯¯¯¯⊕
¯¯¯¯ ¯¯¯¯)
b¯n−1
n−1 n−1 +
(B) an−1 b n−1 ¯ ¯¯¯¯ + ¯a¯¯n−1
c¯n−1 ¯¯¯¯b¯¯¯¯¯¯¯c¯¯¯¯¯
n−1 n−1
Overflow in 2's complement : Carry to MSB & no carry out of MSBOR no carry to MSB and carry out of MSB..
Here C(n-1) is carry into MSB & Cout is carry out of MSB..
Writing overflow condition in expression ,
C(n-1) . Cout' + C(n-1)' . Cout = C(n-1) Ex-OR Cout
Should be Option C.
-- Digvijay Pandey
GATE2014-1_45 top
Consider the 4-to-0 multiplexer with two select lines S 1 and S 0 given below
The minimal sum-of-products form of the Boolean expression for the output F of the multiplexer is
(A) P¯ Q + QR̄ + P Q̄ R
(D) P QR̄
S0 S1 Output
0 0 0
0 1 1
1 0 R
1 1 R'
= P ′ Q + P Q ′ R + P QR′
= P ′ Q + P QR′ + P Q ′ R
= Q(P ′ + P R′ ) + P Q ′ R
= Q(P ′ + R′ ) + P Q ′ R (∵ A + A′ B = A + B)
= P ′ Q + QR′ + P Q ′ R
Option (A)
-- Arjun Suresh
GATE2014-3_7 top
F (P , Q, R, S) = ∑ 0, 2, 5, 7, 8, 10, 13, 15
The minterms 2, 7, 8 and 13 are 'do not care' terms. The minimal sum-of-products form forF is
(A) QS̄ + Q̄ S
(B) Q̄S̄ + QS
While putting the terms to K-map the 3rd and 4th columns are swapped so do 3rd and 4th rows. So, term 2 is going to (0,3) column instead of
(0,2), 8 is going to (3,0) instead of (2,0) etc..
Reference: http://www.cs.uiuc.edu/class/sp08/cs231/lectures/04-Kmap.pdf
-- Srinath Sri
GATE2014-3_45 top
The above synchronous sequential circuit built using JK flip-flops is initialized with Q 2 Q 1 Q 0 = 000 . The state sequence for this circuit for the next 3 clock cycles
is
0 0 0 1 0 0 1 0 1 1 0 0
1 0 0 1 0 1 0 0 1 1 1 0
1 1 0 0 0 1 0 1 1 1 1 1
∴ Option C
-- Gate_15_isHere
GATE2011_15 top
(A) 9
(B) 8
(C) 512
(D) 258
Answer is A
-- Praneeth A S
GATE2010_7 top
A main memory unit with a capacity of 4 megabytes is built using 1M × 1-bit DRAM chips. Each DRAM chip has 1K rows of cells with 1K cells in each row. The time
taken for a single refresh operation is 100 nanoseconds. The time required to perform one refresh operation on all the cells in the memory unit is
There are 4*8 = 32 DRAM chips to get 4MB from 1M × 1-bit chips. Now, all chips can be refreshed in parallel so do all cells in a row. So, the
total time for refresh will be number of rows times the refresh time
= 1K × 100
= 100 × 2 10 nanoseconds
Ref: http://www.downloads.reactivemicro.com/Public/Electronics/DRAM/DRAM%20Refresh.pdf
-- Arjun Suresh
GATE1997_2.1 top
z ∗ x = (x ∗ y) ∗ x
= (x̄ + y) ∗ x
= ¯x̄¯¯¯+
¯¯¯y¯ + x
x. ȳ + x = x
-- Arjun Suresh
GATE1997_5.1 top
Answer: C
A prime implicant of a function is an implicant that is not included in any other implicant of the function.
a product term in which all the variables appear is called a minterm of the function
-- Praveen Saini
GATE1997_5.4 top
√ (224)r = (13)r
convert r base to decimal
2
√ 2r + 2r + 4 = r + 3
take square both sides
2r2 + 2r + 4 = r2 + 6r+ 9
r2 - 4r -5 = 0
r2 -5r +r - 5 = 0
(r-5)(r+1)=0
r can not be -1 so
r = 5 is correct answer
-- Praveen Saini
GATE1997_5.5 top
f = (f 1 ∧ f 2 ) ∨ f 3
Since f 1 and f 2 are in canonical sum of products form,f 1 ∧ f 2 will only contain their common terms- that is f 1 ∧ f 2 = Σ8
Now, Σ8 ∨ f 3 = Σ8, 9
So, f 3 = Σ9
-- Arjun Suresh
GATE1993_6.6 top
A ROM is used to store the Truth table for a binary multiple unit that will multiply two 4-bit numbers. The size of the ROM (number of words ×
number of bits) that is required to accommodate the Truth table is M words × N bits. Write the values of M and N .
A4 A3 A2 A1 B4 B3 B2 B1 M8 M7 M6 M5 M4 M3 M2 M1
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 0 0 0 0 0 0 0
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
1 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0
1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1
So 4 bit of A 4 bit of B
so memory will be of 2 8 × 8
M = 256 , N = 8
-- Praveen Saini
GATE1993_9 top
Assume that only half adders are available in your laboratory. Show that any binary function can be implemented using half adders only.
S = A⊕B
C = A.B
We can Perform any operation using Half adder if we can implement basic gates using half adder
AND operation C = AB
GATE1994_2.1 top
Let say we have to Design mod-8 counter i.e 000 to 111. so we need 3 bit to represent i.e 3 FF
for Mod N
2x = N
x = ceiling (log2N)
-- Praveen Saini
GATE1994_2.7 top
Consider n-bit (including sign bit) 2's complement representation of integer numbers. The range of integer values, N , that can be represented is
_____ ≤ N ≤_____
but when we have one signed bit then we have half of negative -4 to -1 and 0 and 1 to 3
bit pattern: 100 101 110 111 000 001 010 011
1's comp: -3 -2 -1 0 0 1 2 3
2's comp.: -4 -3 -2 -1 0 1 2 3
-- Praveen Saini
GATE1994_4 top
a) i) A* A = AA+A'A' = A + A' = 1
b) AB + A'C= 1 , AC + B = 0
AB+ A'C = 1
A'C = 1 [ bcoz B = 0 so AB = 0 ]
So C = 1 and A= 0
so A = 0 , B = 0 and C = 1
-- Praveen Saini
GATE1995_2.2 top
ans c)
-- Aditi Dan
GATE1995_2.5 top
For verification, just put up the values and check for AND OR operations and their outputs.
-- Gate Keeda
GATE1995_2.12 top
The number of 1's in the binary representation of (3*4096 + 15*256 + 5*16 + 3) are:
(A) 8
(B) 9
(C) 10
(D) 12
3 = (11)2
3 × 4096 = 3 × (2 12 ) = (11)2 << 12 = (11000000000000)2
GATE1996_1.21 top
A ROM is used to store the table for multiplication of two 8-bit unsigned integers. The size of ROM required is
1. 256 ⨯ 16
2. 64 K ⨯ 8
3. 4 K ⨯ 16
4. 64 K ⨯ 16
When we multiply two 8 bit numbers result can go up to 16 bits. So, we need 16 bits for each of the multiplication result. Number of results
possible = 28 ⨯ 28 = 216 = 64 K as we need to store all possible results of multiplying two 8 bit numbers. So, 64 K⨯ 16 is the answer.
-- Arjun Suresh
GATE1996_2.22 top
Options for this question seem wrong, its expression f will come to A'B'C + A'BC + AB'C + ABC, that further can be minimized to C.
-- Manu Thakur
GATE2008-IT_1 top
A set of Boolean connectives is functionally complete if all Boolean functions can be synthesized using those. Which of the following sets of
connectives is NOT functionally complete?
1) EX-NOR
2) implication, negation
3) OR, negation
4) NAND
EX-NOR is not functionally complete. NOR and NAND are functionally complete logic gates, OR , AND, NOT any logic gate can be generated using them.
-- Manu Thakur
GATE2008-IT_7 top
The following bit pattern represents a floating point number in IEEE 754 single precision format
1 10000011 101000000000000000000000
The value of the number in decimal form is
A) - 10
B) - 13
C) - 26
Exponent is added with 127 bias in IEEE single precision format. So, Actual exponent = 10000011 - 127 = 131 - 127 = 4
In IEEE format, an implied 1 is before mantissa, and hence the actual number is
-1.101 * 24
=- (11010)2 = - 26
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
-- Arjun Suresh
GATE2007-IT_42 top
(C012.25)H - (10111001110.101)B =
A) (135103.412)o
B) (564411.412)o
C) (564411.205)o
D) (135103.205)o
(C012.25)H - (10111001110.101)B
= (135103.412)o
Binary subtraction is like decimal subtraction: 0-0 = 0, 1-1 = 0, 1-0 = 1, 0-1 = 1 with 1 borrow.
-- Arjun Suresh
GATE2006-IT_7 top
The addition of 4-bit, two's complement, binary numbers 1101 and 0100 results in
Answer: C
The addition results in 0001 and no overflow with 1 as carry bit.
Sign bit of two input numbers is 0, and the result has sign bit 1.
Sign bit of two input numbers is 1, and the result has sign bit 0.
-- Jon Snow
GATE2004-IT_8 top
What is the minimum number of NAND gates required to implement a 2-input EXCLUSIVE-OR function without using any other logic gate?
A) 3
B) 4
C) 5
D) 6
Any 2-input Exclusive OR function can be implemented with the 4 NAND gates.
Input: A,B
output: (AB)'
Input: (AB)' , A
Input: (AB)', B
GATE2004-IT_10 top
What is the minimum size of ROM required to store the complete truth table of an 8-bit x 8-bit multiplier?
A) 32 K x 16 bits
B) 64 K x 16 bits
C) 16 K x 32 bits
D) 64 K x 32 bits
answer - B
-- ankitrokdeonsns
GATE2004-IT_42 top
Using a 4-bit 2's complement arithmetic, which of the following additions will result in an overflow?
i. 1100 + 1100
ii. 0011 + 0111
iii. 1111 + 0111
A) (i) only
B) (ii) only
C) (iii) only
D) (i) and (iii) only
1. Sign bit of two input numbers is 0, and the result has sign bit 1
2. Sign bit of two input numbers is 1, and the result has sign bit 0.
Overflow is important only for signed arithmetic while carry is important only for unsigned arithmetic.
A carry happens when there is a carry to (or borrow from) the most significant bit. Here, (i) and (iii) cause a carry but only (ii) causes
overflow.
http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt
-- Arjun Suresh
GATE2004-IT_43 top
(123456)8 = (001 010 011 100 101 110)2 = (00 1010 0111 0010 1110)2 = (A72E)16
-- Arjun Suresh
GATE2004-IT_44 top
A) AC’ + AB + A’C
B) AB’ + AC’ + A’C
C) A’B + AC’ + AB’
D) A’B + AC + AB’
K-map
A'B' A'B AB AB'
C' 0 0 1 1
C 1
A'B' 1
A'B 0
AB 1
AB'
So, the equivalent expression will be A'C + AC' + AB'
(B) option
-- Arjun Suresh
GATE2005-IT_7 top
A. (A + B + C)(Ā + B̄ + C̄ )
B. (A + B + C)(Ā + B̄ + C)
C. ABC + Ā(B ⊕ C) + B̄(A ⊕ C)
D. None of these
Correct answer is C
(A⨁B)⨁C
GATE2005-IT_9 top
A dynamic RAM has a memory cycle time of 64 nsec. It has to be refreshed 100 times per msec and each refresh takes 100 nsec. What
percentage of the memory cycle time is used for refreshing?
A. 10
B. 6.4
C. 1
D. 0.64
Ans : C) 1
-- Afaque Ahmad
GATE2005-IT_10 top
A two-way switch has three terminals a, b and c. In ON position (logic value 1),a is connected to b, and in OFF position, a is connected to c.
Two of these two-way switches S1 and S2 are connected to a bulb as shown below.
Which of the following expressions, if true, will always result in the lighting of the bulb ?
¯¯¯¯
A. S1.S2
B. S1 + S2
C. ¯
¯¯¯¯⊕
S1 ¯¯¯¯S2
¯¯¯
D. S1 ⊕ S2
If it's looked carefully, bulb will be on when both switch s1 and s2 are in same state, either off or on. that is exnor operation
S1 S2 Bulb
0 0 On
0 1 Off
1 0 Off
1 1 On
it's Ex-NOR operation hence (C) is the correct option.
-- Manu Thakur
GATE2005-IT_11 top
How many pulses are needed to change the contents of a 8-bit up counter from 10101100 to 00100111 (rightmost bit is the LSB)?
A. 134
B. 133
C. 124
D. 123
D.123 Pulses.
As in a 2^8 Counter the range would be from 0-255. Hence to go from 10101100 (172) to 00100111 (39) , the counter has to go initially from
172 to 255 and then from 0 to 39.
Hence to go from 172 to 255, 255-172 = 83 Clock pulses would be required. then from 255 to 0 , again 1 clock pulse would be required.Then
from 0 to 39 , 39 clock pulses would be required. Hence in total 83+1+39 =123 Clock pulses would be required.
-- Afaque Ahmad
GATE2005-IT_47 top
A) (1053.6) 8
B) (1053.2) 8
C) (1024.2) 8
D) None of these
Simply Convert 34.4 and 23.4 to decimal. We can do this by this method :
-- Afaque Ahmad
GATE2005-IT_48 top
The circuit shown below implements a 2-input NOR gate using two 2-4 MUX (control signal 1 selects the upper input). What are the values of
signals x, y and z?
A) 1, 0, B
B) 1, 0, A
C) 0, 1, B
D) 0, 1, A
= x(Az + B z̄ ) + y (¯Az
¯¯¯¯¯+
¯¯¯Bz̄
¯¯¯¯)
-- John Carter
Let f(x,y,z) = x' + y'x + xz be a switching function. Which one of the following is valid? top
Let f(x,y,z) = x' + y'x + xz be a switching function. Which one of the following is valid?
2 xz is a minterm of f.
3. xz is an implicant of f
4 y is a prime implicant of f
xz is an implicant and ¬y is both prime and essential prime implicant. The sop would be z + ¬x + ¬y .
Ref: https://en.wikipedia.org/wiki/Implicant
-- Shaun Patel
Self complementing code is a code wherein sum of weights is 9. Except for D, all other options have sum of weights=9
-- Keith Kr
GATE2015-2_7 top
The minimum number of JK flip-flops required to construct a synchronous counter with the count sequence (0, 0, 1, 1, 2, 2, 3, 3, 0, 0, ...) is
_______.
Here it appears to have 8 discrete states. That requires 3 bits, therefore 3 flip-flops. From inspection, there are 4 groups of 2 identical bits per group. I'd
break that down to into a divide by two (1 flip-flop) followed by a divide by four (2 flip-flops).
-- Vikrant Singh
GATE2015-2_48 top
A half adder is implemented with XOR and AND gates. A full adder is implemented with two half adders and one OR gate. The propagation
delay of an XOR gate is twice that of an AND/OR gate. The propagation delay of an AND/OR gate is 1.2 milliseconds. A 4-bit-ripple-carry
binary adder is implemented by using four full adders. The total propagation time of this 4-bit binary adder in microseconds is ______.
S1 should wait for C1 to be ready. Delay for generating C is 1 EXOR + 1 AND + 1 OR = 2.4 + 1.2 + 1.2 = 4.8 ms
But for the second adder, there the first EXOR can be done even before waiting for the previous output. So, we can get sum in another 2.4
ms and carry in another 2.4 ms. In this way, 4 bit sum can be obtained after
But the question says we use ripple-carry adder. So, each adder must wait for the full output from the previous adder. This would make the
total delay = 4 * 4.8 = 19.6 ms and this is the key given by GATE, so obviously they meant this.
Ref: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Comb/adder.html
-- Arjun Suresh
GATE2015-3_35 top
Consider the equation (43)x = (y3)8 where x and y are unknown. The number of possible solutions is _____
(43)x =(y3)8
From this equation it is clear x should be greater than 4 and y should be less than 8
4*x+3=y*8+3 , ie 4x = 8y
x=2y. and( x>=5 ,y<=7) and x,y should be integer.
x=6,y=3
x=8,y=4
x=10,y=5
x=12,y=6
-- Praveen Saini
GATE2015-3_43 top
The total number of prime implicants of the function f(w, x, y, z) = ∑(0, 2, 4, 5, 6, 10) is __________.
0 m0 0000
m2 0010
1
m4 0100
m5 0101
2 m6 0110
m10 1010
Combine minterms with other minterms. If two terms vary by only a single digit changing, that digit can be replaced with a dash indicating that
the digit doesn't matter. Terms that can't be combined any more are marked with a "*". When going from Size 2 to Size 4, treat '-' as a third bit
value. For instance, -110 and -100 or -11- can be combined, but -110 and 011- cannot. (Trick: Match up the '-' first.)
First Comparison
(2, 0) 00-0
0
(4, 0) 0-00
(6, 2) 0-10
(10, 2) -010
1
(5, 4) 010-
(6, 4) 01-0
Second Comparison
0 (6, 4, 2, 0) 0--0
Prime Implicants
(6, 4, 2, 0) 0--0
(10, 2) -010
(5, 4) 010-
-- Shyam Singh
GATE2015-3_44 top
Given the function F = P ′ + QR , where F is a function in three Boolean variables P , Q and R and P ′ =!P , consider the following statements.
(S1)F = ∑(4, 5, 6)
(S2)F = ∑(0, 1, 2, 3, 7)
(S3)F = Π(4, 5, 6)
(S4)F = Π(0, 1, 2, 3, 7)
A Q Q+
0 0 1
0 1 0
1 0 0
1 1 1
means ,
-- csegate2
125..
cascading two modulo M and modulo N counter gives modulo M*N counter..
-- Digvijay Pandey
solve top
D = X' Z + Y Z' which an be compared with eq D = J Q' + K' Q hence option D is correct
-- gate2016
digital top
Z = f(A,B,C) = + B + AB + AC
A'B'C' : 000
ABC' : 110
= min { 0, 2, 3, 5, 6, 7}
0132
4576
B + AC + A'C'
-- Digvijay Pandey
IS & Software Engg. top
GATE2009_50 top
50. Consider the following statements about the cyclomatic complexity of the control flow graph of a program module. Which of these are
TRUE?
I. The cyclomatic complexity of a module is equal to the maximum number of linearly independent circuits in the graph.
II. The cyclomatic complexity of a module is the number of decisions in the module plus one, where a decision is effectively any conditional
statement in the module.
III. The cyclomatic complexity can also be used as a number of linearly independent paths that should be tested during path coverage
testing.
(A) I and II (B) II and III (C) I and III (D) I, II and III
ans: b) 2 and 3
GATE2013_38 top
The following figure represents access graphs of two modules M1 and M2. The filled circles represent methods and the unfilled circles
represent attributes. If method m is moved to module M2 keeping the attributes where they are, what can we say about the average cohesion
and coupling between modules in the system of two modules?
Answer: A
-- Jon Snow
GATE2014-1_18 top
a) Specifications can be
1) Waterfall model
developed incrementally
b) Requirements compromises are
2) Evolutionary model
inevitable
3) Component-based software
c) Explicit recognition of risk
engineering
d) Inflexible partitioning of the project into
4) Spiral development
stages
Ans is (B)
-- Keith Kr
GATE2014-3_19 top
In the context of modular software design, which one of the following combinations is desirable?
(A) High cohesion and high coupling
(Ideal software design requires less interaction between modules so that any module can be easily modified/replaced as the requirements
change)
-- Preeti Verma
GATE2011_7 top
A company needs to develop a digital signal processing software for one of its newest inventions. The software is expected to have 40000 lines of code. The
company needs to determine the effort in person-months needed to develop this software using the basic COCOMO model. The multiplicative factor for this model
is given as 2.8 for the software development on embedded systems, while the exponentiation factor is given as 1.20. What is the estimated effort in person-months?
(A) 234.25
(B) 932.50
(C) 287.80
(D) 122.40
kLOC = 40000/1000 = 40
= 234.22
-- Aditya Gaurav
GATE2011_10 top
Which one of the following is NOT desired in a good Software Requirement Specifications (SRS) document?
Algorithms for software implementation may not be required at requirement phase. they are required at later stages like design and
development
-- Sankaranarayanan P.N
GATE2011_47 top
A software engineer is assigned the job of doing black box testing. He comes up with the following test cases, many of which are redundant.
Which one of the following options provide the set of non-redundant tests using equivalence class partitioning approach from input perspective for black box
testing?
In Black Box Testing we just focus on inputs and output of the software system without bothering about internal knowledge of the software .
Equivalence partitioning is a software testing technique that divides the input data of a software unit into partitions of equivalent data from
which test cases can be derived
GATE2010_21 top
The cyclomatic complexity of each of the modules A and B shown below is 10. What is the cyclomatic complexity of the sequential integration shown on the right
hand side?
(A) 19
(B) 21
(C) 20
(D) 10
GATE2010_22 top
What is the appropriate pairing of items in the two columns listing various activities encountered in a software life cycle?
GATE2010_44 top
begin
if (a==b) {S1; exit;}
else if (c==d) {S2;}
else {S3; exit;}
S4;
end
The test cases T1, T2, T3 and T4 given below are expressed in terms of the properties satisfied by the values of variablesa, b, c and d. The
exact values are not given.
T3: a = b and c != d
T4: a != b and c = d
Which of the test suites given below ensures coverage of statements S1, S2, S3 and S4?
(B) T2, T4
(C) T3, T4
T1 covers S1
T2 covers S3
T3 covers S1
T4 covers S2, S4
option D
-- Sankaranarayanan P.N
GATE2008-IT_60 top
(S1) If the system fails during any operation, there should not be any loss of data
(S2) The system must provide reasonable performance even under maximum load conditions
(S3) The software executable must be deployable under MS Windows 95, 2000 and XP
(S4) User interface windows must fit on a standard monitor's screen
1) S4 and S3
2) S4 and S2
3) S3 and S1
4) S2 and S1
3rd is correct, as not specified what standard size of monitor is, and for 2nd, reasonable performance cannot be measured specifically.
-- Shaun Patel
GATE2007-IT_4 top
In the Spiral model of software development, the primary determinant in selecting activities in each iteration is
A) Iteration size
B) Cost
D) Risk
d) risk
-- Aditi Dan
GATE2007-IT_53 top
In the simplified flowchart given below, the shaded boxes represent code that is executed during a test case.
The Branch coverage is
A) 3/4
B) 2/3
C) 1/2
D) 3/8
There are 8 possible branches. 3 are covered by the test case. So, branch coverage is 3/8.
-- Arjun Suresh
GATE2006-IT_16 top
A) an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
B) a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
C) an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
D) a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
its C as each edge must be visited at least once that's why we use cyclomatic complexity to determine the number of independent paths.
-- nagendra
GATE2006-IT_17 top
With respect to software testing, consider a flow graph G with one connected component. Let E be the number of edges, N be the number of
nodes, and P be the number of predicate nodes of G. Consider the following four expressions:
I. E-N+P
II. E-N+2
III. P+ 2
IV. P+1
A) I or III
B) II or III
C) II or IV
D) I or IV
ans c)
-- Aditi Dan
GATE2004-IT_69 top
A) 1
B) 2
C) 3
D) 4
answer - C
2. if condition
GATE2004-IT_70 top
Assume that the delivered lines of code L of a software is related to the effort E in person months and duration t in calendar months by the
relation L P* (E/B)1/3 * t4/3, where P and B are two constants for the software process and skills factor. For a software project, the effort was
estimated to be 20 person months and the duration was estimated to be 8 months. However, the customer asked the project team to complete
the software project in 4 months. What would be the required effort in person months?
A) 10
B) 40
C) 160
D) 320
E1 = 20 person-months
t1 = 8 months
t2 = 4 months
-- Aditya Gaurav
GATE2004-IT_71 top
A software was tested using the error seeding strategy in which 20 errors were seeded in the code. When the code was tested using the
complete test suite, 16 of the seeded errors were detected. The same test suite also detected 200 non-seeded errors. What is the estimated
number of undetected errors in the code after this testing?
1) 4
2) 50
3) 200
4) 250
-- Aditya Gaurav
GATE2004-IT_72 top
A) 1%
B) 24%
C) 99%
D) 99.009%
= 25*24/(25*24 + 6) * 100
= 99.009 %
-- Aditya Gaurav
GATE2005-IT_20 top
The Function Point (FP) calculated for a software project are often used to obtain an estimate of Lines of Code (LOC) required for that project.
Which of the following statements is FALSE in this context.
1) The relationship between FP and LOC depends on the programming language used to implement the software.
2) LOC requirement for an assembly language implementation will be more for a given FP value, than LOC for implementation in COBOL.
3) On an average, one LOC of C++ provides approximately 1.6 times the functionality of a single LOC of FORTRAN
4) FP and LOC are not related to each other
option D... relation between FP and LOC depends on programming language chosen
http://www.cs.helsinki.fi/u/taina/ohtu/fp.html
-- Manali
GATE2005-IT_64 top
The availability of a complex software is 90%. Its Mean Time Between Failure (MTBF) is 200 days. Because of the critical nature of the usage,
the organization deploying the software further enhanced it to obtain an availability of 95%. In the process, the Mean Time To Repair (MTTR)
increased by 5 days.
What is the MTBF of the enhanced software
A) 205 days
B) 300 days
C) 500 days
D) 700 days
Case 1 :
0.9 = 200/(200 + x)
x = 22.22
Case 2 :
0.95 = y/(y+22.22+5)
0.95 = y/(y+27.22)
-- Aditya Gaurav
GATE2005-IT_65 top
Tb carry out white box testing of a program, its flow chart representation is obtained as shown in the figure below:
For basis path based testing of this program, its cyclomatic complexity is
A) 5
B) 4
C) 3
D) 2
No. of Nodes(N) = 9
No. of Edges(E) = 10
Cyclomatic Complexity = E - N + 2P
= 10 -9 + 2*1
=3
-- Aditya Gaurav
GATE2015-1_1 top
A. P - ii, Q - iii, R - i, S - iv
B. P - iii, Q - iv, R - ii, S - i
C. P - iii, Q - i, R - iv, S - ii
D. P - iii, Q - i, R - ii, S - iv
C) P - iii, Q - i, R - iv, S - ii
Ref: https://en.wikipedia.org/wiki/Software_testing
-- piyushhurpade
GATE2015-2_4 top
A software requirements specification (SRS) document should avoid discussing which one of the following?
Ans C
-- Vikrant Singh
GATE2015-2_12 top
Consider the basic COCOMO model where E is the effort applied in person-months, D is the development time in chronological months,
KLOC is the estimated number of delivered lines of code (in thousands) andab , b b , c b , db have their useful meanings. The basic COCOMO
equations are of the form
A. E = ab (KLOC)exp(b b ), D = c b (E)exp(db )
B. D = ab (KLOC)exp(b b ), E = c b (D)exp(db )
C. E = ab exp(b b ), D = c b (KLOC)exp(db )
D. E = ab exp(db ), D = c b (KLOC)exp(b b )
Answer: A
where KLOC = Estimated number of delivered lines in thousands and a,b,c,d depends upon the software being Organic, Semi detached or
Embedded.
http://www.mhhe.com/engcs/compsci/pressman/information/olc/COCOMO.html
-- Jon Snow
GATE2015-2_43 top
Which one of the following assertions concerning code inspection and code walkthrough is true?
A. Code inspection is carried out once the code has been unit tested
B. Code inspection and code walkthrough are synonyms
C. Adherence to coding standards is checked during code inspection
D. Code walkthrough is usually carried out by an independent test team
c.
Unit testing is not necessary before code inspection. Code walk through is done by a member of development team in presence of reviewers.
So, a and d are false.
http://nptel.ac.in/courses/106105087/pdf/m10L23.pdf
http://www.tutorialspoint.com/software_testing_dictionary/code_inspection.htm
-- Arjun Suresh
GATE2015-1_42 top
GATE2015-3_11 top
Consider a software program that is artificially seeded with 100 faults. While testing this program, 159 faults 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 distribution, the
estimated number of undetected real faults is _______.
Answer:28
Explanation:
75% of faults are detected because 75 artificially seeded faults are detected out of 100.
=112
GATE2015-3_21 top
Consider a software project with the following information domain characteristics for calculation of function point metric.
It is given that the complexity weighting factors for I, O, E, F and N are 4, 5, 4, 10 and 7, respectively. It is also given that, out of fourteen value
adjustment factors that influence the development effort, four factors are not applicable, each of the other four factors have value 3, and each of
the remaining factors have value 4. The computed value of function point metric is _________.
Ans: 612.06
FP = UAF * VAF
UAF = 30 * 4 + 60 * 5 + 23 * 4 + 08 * 10 + 02 * 7 = 606
-- ashwini anand
GATE2015-3_55 top
Consider the following software items: Program-X , Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown
below
The values of McCabe's Cyclomatic complexity of program-X , program-Y , and program-Z respectively are
A. 4, 4, 7
B. 3, 4, 7
C. 4, 4, 8
D. 4, 3, 8
-- Praveen Saini
Web Technologies top
GATE2009_20 top
The number of rows in each column and the number of columns in each row are:
-- Arjun Suresh
GATE2014-2_28 top
A graphical HTML browser resident at a network client machine Q accesses a static HTML webpage from a HTTP server S . The static HTML page has exactly
one static embedded image which is also at S . Assuming no caching, which one of the following is correct about the HTML webpage loading (including the
embedded image)?
(A) Q needs to send at least 2 HTTP requests to S , each necessarily in a separate TCP connection to server S
(B) Q needs to send at least 2 HTTP requests to S , but a single TCP connection to server S is sufficient
(C) A single HTTP request from Q to S is sufficient, and a single TCP connection between Q and S is necessary for this
(D) A single HTTP request from Q to S is sufficient, and this is possible without any TCP connection between Q and S
A separate HTML request must be send for each image or component in HTML like css file of js. But all can be done in same connection. So,
(B) is the answer.
-- Arjun Suresh
GATE2010_16 top
(C) E-mail
(D) Ping
GATE2004-IT_24 top
B is false, HTTP is protocol, which has no relations with the structure of a web page. Web page structure is given using HTML.
-- Manu Thakur
GATE2004-IT_29 top
Which of the following objects can be used in expressions and scriplets in JSP (Java Server Pages) without explicitly declaring them?
GATE2004-IT_90 top
A) I and II only
B) I and III only
C) I, II and III only
D) I, II, III and IV
III. For relative URL starting from the current page location
IV. For relative URL starting from the current page location and then going to "test" part of the loaded page
-- Arpit Dhuriya
GATE2005-IT_30 top
A HTML form is to be designed to enable purchase of office stationery. Required items are to be selected (checked). Credit card details are to
be entered and then the submit button is to be pressed. Which one of the following options would be appropriate for sending the data to the
server. Assume that security is handled in a way that is transparent to the form design.
A) Only GET
B) Only POST
C) Either of GET or POST
D) Neither GET nor POST
Refer: http://www.w3schools.com/tags/ref_httpmethods.asp
-- Sankaranarayanan P.N
GATE2015-1_15 top
I. XML overcomes the limitations in HTML to support a structured way of organizing content.
II. XML specification is not case sensitive while HTML specification is case sensitive.
III. XML supports user defined tags while HTML uses pre-defined tags.
IV. XML tags need not be closed while HTML tags must be closed.
A. Ⅱ only
B. Ⅰ only
C. II and IV only
D. III and IV only
option c
-- GATERush
GATE2015-3_8 top
In a web server, ten WebPages are stored with the URLs of the form http://www.yourname.com/ var.html; where var is a different number from 1
to 10 for each Webpage. Suppose the client stores the Webpage with var = 1 (say W1) in the local machine, edits and then tests. Rest of the
Webpages remains on the web server. W1 contains several relative URLs of the form "var.html" referring to the other Webpages. Which one of
the following statements needs to be added in W1, so that all the relative URLs in W1 refer to the appropriate Webpages on the web server?
B choice.
http://www.w3schools.com/tags/tag_base.asp
-- Arjun Suresh
Verbal Ability top
GATE2014-1_GA_1 top
Which of the following options is the closest in meaning to the phrase in bold in the
sentence below?
Answer is Adapt to. Often seen in newspaper "Indian players couldn't adapt to foreign conditions".
Adopt - means legally take care of. Also means to take up and use as in "He adopted my point of view."
GATE2014-1_GA_2 top
Choose the most appropriate word from the options given below to complete the following sentence.
He could not understand the judges awarding her the first prize, because he thought that her performance was quite _________.
A. superb
B. medium
C. mediocre
D. exhilarating
C. Mediocre meaning not very good, not up to par, average. Her performance was average and not worthy of 1st prize.
-- Kathleen Bankson
GATE2014-1_GA_3 top
In a press meet on the recent scam, the minister said, "The buck stops here". What did the minister convey by the statement?
C. The buck stops here is a term meaning to put an end to something, not continue, stop it.
(idiomatic) A statement that no excuses will be made, that the speaker is going to take direct responsibility for matters, rather than pass the responsibility to higher
authorities.
-- Kathleen Bankson
GATE2014-1_GA_6 top
The Palghat Gap (or Palakkad Gap) , a region about 30 km wide in the southern part of the Western Ghats in India, is lower than the hilly
terrain to its north and south. The exact reasons for the formation of this gap are not clear. It results in the neighbouring regions of Tamil Nadu
getting more rainfall from the South West monsoon and the neighbouring regions of Kerala having higher summer temperatures.
Select one:
A. The Palghat gap is caused by high rainfall and high temperatures in southern Tamil Nadu and Kerala
B. The regions in Tamil Nadu and Kerala that are near the Palghat Gap are low-lying
C. The low terrain of the Palghat Gap has a significant impact on weather patterns in neighbouring parts of Tamil Nadu and Kerala
D. Higher summer temperatures result in higher rainfall near the Palghat Gap area
The answer is C. The primary statement is about the Palghat Gap being low lying which is mentioned in thefirst sentence. The second part
mentions the results of that causing lots of rain and unusual temperatures in the other areas. (Tamil Nadu and Kerala)
-- Kathleen Bankson
GATE2014-1_GA_7 top
Geneticists say that they are very close to confirming the genetic roots of psychiatric illnesses such as depression and schizophrenia, and
consequently, that doctors will be able to eradicate these diseases through early identification and gene therapy.
Select one:
C. All human diseases can be traced back to genes and how they are expressed
D. In the future, genetics will become the only relevant field for identifying psychiatric illnesses
B is correct, The first sentence mentions two specific illnesses, (depression and schizophrenia). B is the only one that mentions certain illnesses.
A states strategies are now available. The statement says they are very close so its not yet available.
C states that ALL human diseases can be traced back. The statement only mentions two specific illnesses.
D the statement does not mention at all that it is the only relevant field.
-- Kathleen Bankson
GATE2013_56 top
Which one of the following options is the closest in meaning to the word given below?
Nadir
GATE2013_57 top
Complete the sentence:
Specificity Diffuseness
Direct, to the point, purposeful in Indirect, circuitous, seemingly
relating "aimless" forms of relating
Precise, blunt, definitive and Evasive, tactful, ambiguous, even
transparent opaque
Principles and consistent moral Highly situational morality
stands independent of the person depending upon the person and
being addressed context encountered
-- Kathleen Bankson
GATE2013_59 top
Were you a bird, you ___________________ in the sky.
(A) would fly (B) shall fly (C) should fly (D) shall have flown
A...would fly
-- Kathleen Bankson
GATE2013_60 top
"The sound of a word's first letter determines which to use. If the word starts with a vowel sound, you should use an. If it starts with a consonant sound, you
should use a."
The word "European" does not start with a vowel sound, it starts with the syllable "you". The "y"-sound is in this case a consonant (or at least a half-consonant), so the
indefinite article is "a".
-- Kathleen Bankson
GATE2013_63 top
After several defeats in wars, Robert Bruce went in exile and wanted to commit suicide. Just before committing suicide, he came across a
spider attempting tirelessly to have its net. Time and again, the spider failed but that did not deter it to refrain from making attempts. Such
attempts by the spider made Bruce curious. Thus, Bruce started observing the near-impossible goal of the spider to have the net. Ultimately,
the spider succeeded in having its net despite several failures. Such act of the spider encouraged Bruce not to commit suicide. And then, Bruce
went back again and won many a battle, and the rest is history.
Which one of the following assertions is best supported by the above information?
D is my answer. He gave up hope and wanted to commit suicide until he saw the spider in his struggles so no struggle or difficulty is worth
giving up hope. Continue on!
-- Kathleen Bankson
GATE2014-2_GA_3 top
Match the columns.
Column 1 Column 2
1) eradicate P) misrepresent
3) saturate R) use
Answer is A
-- Poshita Shrivastava
GATE2014-3_GA_1 top
While trying to collect an envelope from under the table, Mr. X fell down and
I II III
IV
Which one of the above underlined parts of the sentence is NOT appropriate?
(A) I
(B) II
(C) III
(D) IV
Answer D)
While trying to collect an envelope from under the table, Mr. X fell down and was losing consciousness.
A :Mr. X is trying to collect an envelope from under the table (Present continuous tense)
B :Mr. X fell down (Simple past tense)
C :Mr. X was losing consciousness. (Past continuous tense)
While A, B and C
"We use the past continuous tense with the simple past tense when we want to show that one thing happened in the middle of another thing."
eg-I was taking a bath and the telephone rang.
Here it says..
"Mr. X fell down and was losing consciousness."
i.e B is done.. and C starts. Where as the usage says.. C should have happened in the middle of B.
Source - http://www.5minuteenglish.com/nov12.htm
-- Srinath Sri
GATE2014-3_GA_2 top
If she _______________ how to calibrate the instrument, she _______________ done the experiment.
To answer these i normally use the language(even english itself) i am fluent in.
Option C) makes perfect sense , rest do not relate to each other.
-- Srinath Sri
GATE2014-3_GA_3 top
(A) sticky
(B) well-connected
(C) rambling
(D) friendly
C)Rambling
-- Srinath Sri
GATE2014-3_GA_6 top
A dance programme is scheduled for 10.00 a.m. Some students are participating in the programme and they need to come an hour earlier than the start of the
event. These students should be accompanied by a parent. Other students and parents should come in time for the programme. The instruction you think that is
appropriate for this is
(A) Students should come at 9.00 a.m. and parents should come at 10.00 a.m.
(B) Participating students should come at 9.00 a.m. accompanied by a parent, and other parents and students should come by 10.00 a.m.
(C) Students who are not participating should come by 10.00 a.m. and they should not bring their parents. Participating students should come at 9.00 a.m.
(D) Participating students should come before 9.00 a.m. Parents who accompany them should come at 9.00 a.m. All others should come at 10.00 a.m.
It will be B.
-- Gate Keeda
GATE2014-3_GA_7 top
By the beginning of the 20th century, several hypotheses were being proposed, suggesting a paradigm shift in our understanding of the
universe. However, the clinching evidence was provided by experimental measurements of the position of a star which was directly behind our
sun.
Which of the following inference(s) may be drawn from the above passage?
-- Srinath Sri
GATE2011_56 top
Which of the following options is the closest in the meaning to the word below:
Inexplicable
(A) Incomprehensible
(B) Indelible
(C) Inextricable
(D) Infallible
answer is (a)
Indelible => impossible to remove, erase or wash away => Not appropriate
-- Kalpna Bhargav
GATE2012_57 top
Choose the most appropriate alternative from the options given below to complete the following sentence:
Despite several ––––––––– the mission succeeded in its attempt to resolve the conflict.
(A) attempts
(B) setbacks
(C) meetings
(D) delegations
B...setbacks
-- Kathleen Bankson
GATE2012_58 top
Which one of the following options is the closest in meaning to the word given below?
Mitigate
(A) Diminish
(B) Divulge
(C) Dedicate
(D) Denote
A. Diminish
-- Kathleen Bankson
GATE2012_59 top
(A) They gave us the money back less the service charges of Three Hundred rupees.
(B) This country’s expenditure is not less than that of Bangladesh.
(C) The committee initially asked for a funding of Fifty Lakh rupees, but later settled for a lesser sum.
(D) This country’s expenditure on educational reforms is very less.
GATE2012_60 top
Choose the most appropriate alternative from the options given below to complete the following sentence:
(A) that
(B) which
(C) who
(D) whom
A....that
Restrictive Clause—That
A restrictive clause is just part of a sentence that you can't get rid of because it specifically restricts some other part of the sentence. Here's an
example:
The words that sparkle restrict the kind of gems you're talking about. Without them, the meaning of the sentence would change. Without
them, you'd be saying that all gems elicit forgiveness, not just the gems that sparkle. (And note that you don't need commas around the
words that sparkle.)
Nonrestrictive Clause—Which
A nonrestrictive clause is something that can be left off without changing the meaning of the sentence. You can think of a nonrestrictive clause
as simply additional information. Here's an example:
-- Kathleen Bankson
GATE2012_61 top
Wanted Temporary, Part-time persons for the post of Field Interviewer to conduct personal interviews to collect and collate
economic data. Requirements: High School-pass, must be available for Day, Evening and Saturday work. Transportation paid,
expenses reimbursed.
Which one of the following is the best inference from the above advertisement?
(A) Gender-discriminatory
(B) Xenophobic
(C) Not designed to make the post attractive
(D) Not gender-discriminatory
Xenophobic means having or showing an intense or irrational dislike or fear of people from other countries, so does not apply.
-- Kathleen Bankson
GATE2010_56 top
Choose the most appropriate word from the options given below to complete the following sentence:
His rather casual remarks on politics ________ his lack of seriousness about the subject.
(A) masked
(B) belied
(C) betrayed
(D) suppressed
-- Kalpna Bhargav
GATE2010_57 top
Which of the following options is the closest in meaning to the word given below:
Circuitous
(A) cyclic
(B) indirect
(C) confusing
(D) crooked
B Indirect
-- Kathleen Bankson
GATE2010_58 top
Choose the most appropriate word from the options given below to complete the following sentence:
If we manage to __________ our natural resources, we would leave a better planet for our children.
(A) uphold
(B) restrain
(C) cherish
(D) conserve
D Conserve
-- Kathleen Bankson
GATE2010_60 top
The question below consists of a pair of related words followed by four pairs of words. Select the pair that best expresses the relation in the
original pair.
Unemployed : Worker
A. Fallow: Land
-- Kathleen Bankson
GATE2010_63 top
Modern warfare has changed from large scale clashes of armies to suppression of civilian populations. Chemical agents that do their
work silently appear to be suited to such warfare; and regretfully, there exist people in military establishments who think that
chemical agents are useful tools for their cause.
Which of the following statements best sums up the meaning of the above passage:
A. commit
B. to commit
C. committed
D. commiting
http://www.thefreedictionary.com/DARE
-- Arjun Suresh
GATE2015-2_GA_4 top
A generic term that includes various items of clothing such as a skirt, a pair of trousers and a shirt is
A. fabric
B. textile
C. fibre
D. apparel
-- Anoop Sonkar
GATE2015-3_GA_2 top
The Tamil version of __________ John Abraham-starrer Madras Cafe __________ cleared by the Censor Board with no cuts last week, but the
film's distributor _______ no takers among the exhibitors for a release in Tamilnadu _______ this Friday.
answer is c
-- naresh1845
GATE2015-3_GA_3 top
Extreme focus on syllabus ans studying for tests has become such a dominant concern of Indian student that they close their minds to anything
___________ to the requirements of the exam.
A. related
B. extraneous
C. outside
D. useful
answer is b
-- naresh1845
GATE2015-3_GA_4 top
Select the pair of best expresses a relationship similar to that expressed in the pair:
Children : Pediatrician
A. Adult : Orthopaedist
B. Females : Gynaecologist
C. Kidney : Nephrologist
D. Skin : Dermatologist
-- Anoop Sonkar
GATE2015-3_GA_6 top
Alexander turned his attention towards India, since he had conquered Persia.
Which one of the statements below is logically valid and can be inferred from the above sentence?
A. Alexander would not have turned his attention towards India had he not conquered Persia.
B. Alexander was not ready to rest on his laurels, and wanted to march to India.
C. Alexander was not completely in control of his army and could command it to move towards India.
D. Since Alexander's kingdom extended to Indian borders after the conquest of Persia, he was keen to move further.
GATE2015-3_GA_7 top
The head of newly formed government desires to appoint five of the six selected members P, Q, R, S, T and U to portfolios of Home, Power,
Defense, Telecom, and Finance. U does not want any portfolio if S gets one of the five. R wants either Home or Finance or no portfolio. Q says
that if S gets Power or Telecom, then she must get the other one. T insists on a portfolio if P gets one.
"U does not want any portfolio if S gets one of the five"
Just to confirm:
Q says that if S gets Power or Telecom, then she must get the other one
In B, T is getting a portfolio.
-- Arjun Suresh
Numerical Ability top
GATE2014-1_GA_5 top
The roots of ax2 +bx+c=0 are real and positive. a, b and c are real. Then ax2 +b|x|+c=0 has
A. no roots
B. 2 real roots
C. 3 real roots
D. 4 real roots
-- Arjun Suresh
GATE2014-1_GA_4 top
Ans: (Z+1/Z)2 = (z2 + 2(z)(1/z) + (1/z)2) = (z2 + 1/z2) +2 = 98 ==>> 98-2 = 96 is answer..
-- Jayesh Malaviya
GATE2014-1_GA_8 top
Round-trip tickets to a tourist destination are eligible for a discount of 10% on the total fare. In addition, groups of 4 or more get a discount of
5% on the total fare. If the one way single person fare is Rs 100, a group of 5 tourists purchasing round-trip tickets will be charged Rs
__________
For individual , Round-trip discount 10% on TOTAL fare . So for each person (200 X 10%)=20 .
For 5 member group they will get 5% discount on TOTAL fare i.e. (5x200 X 5%)= 50 rupess.
-- Palash Nandi
GATE2014-1_GA_9 top
In a survey, 300 respondents were asked whether they own a vehicle or not. If yes, they were further asked to mention whether they own a car
or scooter or both. Their responses are tabulated below. What percent of respondents do not own a scooter?
Men Women
Car 40 34
Both 60 46
Not having scooter from Men (34 (car owner) + 50 (nothing owns))=84
GATE2014-1_GA_10 top
When a point inside of a tetrahedron (a solid with four triangular surfaces) is connected by straight lines to its corners, how many (new) internal
planes are created with these lines?
It is 6.
-- Palash Nandi
GATE2013_64 top
A tourist covers half of his journey by train at 60 km/h, half of the remainder by bus at 30 km/h and the rest by cycle at 10 km/h. The average
speed of the tourist in km/h during his entire journey is
avg speed-120/5=24
-- Bhagirathi Nayak
GATE2014-2_GA_5 top
−−−−−−−−−−−−−−−−−−
The value of √12 + √−−−−−−−
12 + √−−−−
12 −−…
−+ −−is
(A) 3.464
(B) 3.932
(C) 4.000
(D) 4.444
x = √−−−−
12 +−
x
⟹ x2 = 12 + x
⟹ x2 − x − 12 = 0
⟹ (x − 4)(x + 3) = 0
⟹ x = 4 or x = −3
-- Arjun Suresh
GATE2014-3_GA_4 top
(A) 17
(B) 37
(C) 64
(D) 26
GATE2014-3_GA_10 top
Consider the equation: (7526)8 − (Y )8 = (4364)8 , where (X)N stands for X to the base N . Find Y .
(A) 1634
(B) 1737
(C) 3142
(D) 3162
C)
The given numbers are in octal representation. Digits range from 0 to 7.
Y=7526-4364
7526
-4364
_______
3142
steps : 1. (6-4) =2
2. (2-6) , borrow a 8. Now (8+2-6)=4
3. (5-1-3) = 1 (Subtracted by 1 because ONE 8 was borrowed)
4. (7-4) = 3
-- Srinath Sri
GATE2011_57 top
If log(P) = (1/2) log(Q) = (1/3) log(R), then which of the following options is TRUE ?
(A) P2 = Q 3 R2
(B) Q 2 = PR
(C) Q 2 = R3 P
(D) R = P2 Q 2
B.
-- shreya ghosh
GATE2011_62 top
P, Q, R and S are four types of dangerous microbes recently found in a human habitat. The area of each circle with its diameter printed in brackets represents the
growth of a single microbe surviving human immunity system within 24 hours of entering the body. The danger to human beings varies proportionately with the
toxicity, potency and growth attributed to a microbe shown in the figure below:
A pharmaceutical company is contemplating the development of a vaccine against the most dangerous microbe. Which microbe should the company target in its
first attempt?
(A) P
(B) Q
(C) R
(D) S
Answer is D.
As per the question, it is quite clear that the danger of a microbe to human being will be directly proportional to potency and growth. At the
same time it is inversely proportional to toxicity, defined as( more dangerous will a microbe be if lesser of its milligram is required).
So,
Potency (P)
1/ Toxicity (T)
D = KGP/T
Given by,
D S = 0.8 * (10)2/200
= 1.256
Similar Calculations for DP , DQ , DR can be done. Which will consequently lead to DS being the most dangerous and hence will be targeted
first.
-- Gate Keeda
GATE2011_64 top
A transporter receives the same number of orders each day. Currently, he has some pending orders (backlog) to be shipped. If he uses 7 trucks, then at the end of
the 4th day he can clear all the orders. Alternatively, if he uses only 3 trucks, then all the orders are cleared at the end of the 10 th day. What is the minimum number
of trucks required so that there will be no pending order at the end of 5th day?
(A) 4
(B) 5
(C) 6
(D) 7
Let the amount of orders received per day be x and let the amount of pending orders be y and let the amount of orders carried by a truck each
day be z.
7z * 4 = 4x + y -> (1)
3z * 10 = 10x + y (2)
We want to find the number of trucks to finish the orders in 5 days. Let it be A.
Az * 5 = 5x + y
15Ax = 5x + 80x
GATE2011_65 top
A container originally contains 10 litres of pure spirit. From this container 1 litre of spirit replaced with 1 litre of water. Subsequently, 1 litre of the mixture is again
replaced with 1 litre of water and this process is repeated one more time. How much spirit is now left in the container?
(C) 7 litres
GATE2012_56 top
The cost function for a product in a firm is given by5q 2 , where q is the amount of production. The firm can sell the product at a market price of
₹ 50 per unit. The number of units to be produced by the firm such that the profit is maximized is
(A) 5
(B) 10
(C) 15
(D) 25
Answer is A. The equation for profit is Profit=SP-CP, here SP=Q*50 and CP=5Q^2 so when a function attains its maximum value its first
order differentiation is zero. Hence 50-5*2*Q=0. therefore Q=5.
-- kireeti
GATE2012_62 top
A political party orders an arch for the entrance to the ground in which the annual convention is being held. The profile of the arch follows the
equation y = 2x − 0.1x2 where y is the height of the arch in meters. The maximum possible height of the arch is
(A) 8 meters
(B) 10 meters
(C) 12 meters
(D) 14 meters
B. 10
y = 2x - 0.1x2
so y= 20-10=10
-- shreya ghosh
GATE2012_63 top
An automobile plant contracted to buy shock absorbers from two suppliers X and Y . X supplies 60% and Y supplies 40% of the shock
absorbers. All shock absorbers are subjected to a quality test. The ones that pass the quality test are considered reliable. Of X ′ s shock
absorbers, 96% are reliable. Of Y ′ s shock absorbers, 72% are reliable.
The probability that a randomly chosen shock absorber, which is found to be reliable, is made by Y is
(A) 0.288
(B) 0.334
(C) 0.667
(D) 0.720
B.
Probability of Y and R
Probability of Y given R = Probability of R
0.4×0.72
= 0.4×0.72+0.6×0.96
= 1 = 0.33
3
-- shreya ghosh
GATE2012_64 top
Q: Adding 7 to each entry in a list adds 7 to the standard deviation of the list
S: Doubling each entry in a list leaves the standard deviation of the list unchanged
(A) P, Q
(B) Q, R
(C) P, R
(D) R, S
Suppose we double each entry of a list
n
∑ i=1 xi
Initial Mean (M I ) = n
∑ i=1 2×xi
n
New Mean (M N ) =
n
2
= n
∑ni=1 xi
So, when each entry in the list is doubled, mean also gets doubled.
−−−−−−−−−−−−−−
Standard Deviation σI = √∑ni=1 (M I − xi )2
−−−−−−−−−−−−−−−−−
New Standard Deviation σN = √∑ni=1 (M N − 2 × xi ) 2
−−−−−−−−−−−−−−−−−−
= √∑ni=1 (2 × (M I − xi ))2
= 2 σI
So, when each entry is doubled, standard deviation also gets doubled.
When we add a constant to each element of the list, it gets added to the mean as well. This can be seen from the formula of mean.
When we add a constant to each element of the list, the standard deviation (or variance) remains unchanged. This is because, the mean also
gets added by the same constant and hence the deviation from the mean remains the same for each element.
-- Arjun Suresh
GATE2012_65 top
Given the sequence of terms, AD CG FK JP, the next term is
(A) OV
(B) OW
(C) PV
(D) PW
A. OV
AD - difference 2 (B,C)
CG - difference 3 (D,E,F)
again each term starts with preceding term's 2nd last letter
so JKLMNOP , next term will start with O and having 6 difference it will be OV
-- shreya ghosh
GATE2010_59 top
25 persons are in a room. 15 of them play hockey, 17 of them play football and 10 of them play both hockey and football. Then the number of persons playing
neither hockey nor football is:
(A) 2
(B) 17
(C) 13
(D) 3
D. 3
-- shreya ghosh
GATE2010_61 top
(A) 534
(B) 1403
(C) 1623
(D) 1513
Answer. C.
-- shreya ghosh
GATE2010_64 top
5 skilled workers can build a wall in 20 days; 8 semi-skilled workers can build a wall in 25 days; 10 unskilled workers can build a wall in 30 days. If a team has 2
skilled, 6 semi-skilled and 5 unskilled workers, how long it will take to build the wall?
(A) 20 days
(B) 18 days
(C) 16 days
(D) 15 days
D. 15 days
1 skilled person can do 1/100 of work in 1 day, so 2 skilled person do 2/100 of work in a day.
similarly, 6 semi-skilled and 5 unskilled person can do 6/200 and 5/300 respectively in 1 day.
so they do 1/15 of work together in 1 day, which gives required number of day to complete the work = 15 .
-- shreya ghosh
GATE2015-1_GA_9 top
The pie chart below has the breakup of the number of students from different departments in an engineering college for the year 2012. The
proportion of male to female students in each department is 5:4. There are 40 males in Electrical Engineering. What is the difference between
the numbers of female students in the civil department and the female students in the Mechanical department?
Number of female students in Civil = 32 * 30/20 = 48 (Since proportion of male students to female students is same, the breakup chart is the
same for number of female students)
So, answer = 48 - 16 = 32
-- Arjun Suresh
GATE2015-2_GA_5 top
Based on the given statements, select the most appropriate option to solve the given question.
Statements:
Ans C
-- Vikrant Singh
GATE2015-2_GA_8 top
In a triangle PQR, PS is the angle bisector of∠QP R and ∠QP S = 60∘ . What is the length of PS?
(q+r)
A. qr
qr
B. q+r
C. √−−−−−−−
(q 2 + r2 )
(q+r) 2
D.
qr
QS/SR = r/q
QS/(p-QS) = r/q
QS = pr/(q+r) -> (1)
PS = qr/(q+r)
B choice.
http://en.wikipedia.org/wiki/Angle_bisector_theorem
-- Arjun Suresh
GATE2015-3_GA_1 top
A. VXDQ
B. VZDQ
C. VZDP
D. UXDQ
GATE2015-3_GA_5 top
A function f(x) is linear and has a value of 29 atx = −2 and 39 at x = 3 . Find its value at x = 5 .
A. 59
B. 45
C. 43
D. 35
solve the equation and find out value for a and b. then find f(5). it will be 43
-- Sankaranarayanan P.N
GATE2015-3_GA_8 top
Choose the most appropriate equation for the function drawn as thick line, in the plot below.
A. x = y − |y|
B. x = −(y − |y|)
C. x = y + |y|
D. x = −(y + |y|)
When y is -1, x is 2.
When y is positive x is 0.
GATE2015-3_GA_10 top
The exports and imports (in crores of Rs.) of a country from the year 2000 to 2007 are given in the following bar chart. In which year is the
combined percentage increase in imports and exports the highest?
Exports + % Increase = (Increase/Value) *
Increase
Imports 100
2000 90 - -
2001 110 20 18.18
2002 130 20 15.38
2003 130 0 0
2004 150 20 13.33
2005 160 10 6.25
2006 220 60 27.27
2007 230 10 4.35
So, 2006.
-- Arjun Suresh
Mathematical Logic top
GATE2012_1 top
I 1 is a correct inference. I 2 is not a correct inference as it was not mentioned what would have happened if it hadn't rained- They might have
played or they might not have played.
-- Arjun Suresh
GATE2012_13 top
What is the correct translation of the following statement into mathematical logic?
GATE2013_47 top
i.e.; If some property α is true for all x, then it is equivalent ot say that no x exists such that property α does not hold for it.
A: ∀x(∃z(¬β) → ∀y(α))
⟹ ∀x(¬∃z(¬β) ∨ ∀y(α))
⟹ ∀x(∀z(β) ∨ ∀y(α))
⟹ ¬∃x¬(∀z(β) ∨ ∀y(α))
B: ∀x(∀z(β) → ∃y(¬α))
⟹ ∀x(¬∀z(β) ∨ ∃y(¬α))
⟹ ¬∃x¬(¬∀z(β) ∨ ∃y(¬α))
⟹ ¬∃x(∀z(β) ∧ ¬∃y(¬α))
⟹ ¬∃x(∀z(β) ∧ ∀y(α))
C. ∀x(∀y(α) → ∃z(¬β))
⟹ ∀x(¬∀y(α) ∨ ∃z(¬β))
⟹ ¬∃x¬(¬∀y(α) ∨ ∃z(¬β))
⟹ ¬∃x(∀y(α) ∧ ¬∃z(¬β))
⟹ ¬∃x(∀y(α) ∧ ∀z(β))
D: ∀x(∃y(¬α) → ∃z(β))
⟹ ∀x(¬∃y(¬α) ∨ ∃z(β))
⟹ ∀x(∀y(α) ∨ ∃z(β))
⟹ ¬∃x¬(∀y(α) ∨ ∃z(β))
Thus both A and D are not logically equivalent to the given statement.
In GATE 2013 marks were given to all for this question
-- Arjun Suresh
GATE1992_92,xv top
Which of the following predicate calculus statements is/are valid?
(1) The corresponding English meaning: If P (x) is true for all x, or if Q(x) is true for all x, then for all x, either P (x) is true or Q(x) is true. This
is always true and hence valid. To understand deeply, consider X = {3, 6, 9, 12} . For LHS of implication to be true, eitherP (x) must be true
for all elements in X or Q(x) must be true for all elements in X . In either case, if we take each elementx in X , either one of P (x) or Q(x) will
be true. Hence, this implication is always valid.
(If still in doubt, let P (x) mean x is a multiple of 3 and Q(x) means x is a multiple of 2 )
(2) The corresponding English meaning: If P (x) is true for at least one x, and if Q(x) is true for at least one x, then there is at least one x for
which both P (x) and Q(x) are true. This is not always true as P (x) can be true for one x and Q(x) can be true for some other x . To
understand deeply, consider X = {3, 6, 9, 12} . Let P (x) be x is a multiple of 9 and Q(x) be x is a multiple of 6 . Now, LHS of implication is
true, since P (x) is true for x = 9 , and Q(x) is true for x = 6 . But RHS of implication is not true as there is nox for which both P (x) and Q(x)
holds. Hence, this implication is not valid.
(3) If for each x, either P (x) is true or Q(x) is true then P (x) is true for all x or Q(x) is true for all x. Just one read is enough to see this is an
invalid implication. Consider set {2,4,5}. Here every element is either a multiple or 2 or 5. But all elements are neither multiple of 2 nor 5.
(4)If there is at least one x for which either P (x) or Q(x) is true then either it is not the case that P (x) is true for all x or Q(x) is true for at
least one x. This is clearly invalid as LHS of implication becomes true ifP (x) is true for some x and Q(x) is not true for any x, but RHS will
be false.
which means if there is at least one x for which either P (x) or Q(x) is true then
either it is not the case that ∼ P (x) is true for all x (which means P(x) is true for some x) or Q(x) is true for some x.
Note
De Morgan's law is applicable in first order logic and is quite useful:
This is a logical reasoning statement which means ifP (x) is true for all x, then there can never exist an x for which P (x) is not true. This
formula is quite useful in proving validity of many statements as is its converse given below:
-- gatecse
GATE2001_1.3 top
F 1 : P ⇒ ¬P F 2 : (P ⇒ ¬P ) ∨ (¬P ⇒ P )
F1: P => ⌝ P
=⌝ P V ⌝ P
=⌝ P V (P V P)
=⌝PVP
=T
VALID
Option A
-- Manali
GATE2009_23 top
Which one of the following is the most appropriate logical formula to represent the statement?
Answer is D.
-- Praneeth A S
GATE2009_24 top
P Q P□Q
T T T
T F T
F T F
F F T
(A) ¬Q □ ¬P
(B) P □ ¬Q
(C) ¬P □ Q
(D) ¬P □ ¬Q
Answer is B because the truth values for option B is same as that of P "or" Q.
¯ +P =P +Q
Now, with A option we get Q̄
-- chetna
GATE2002_1.8 top
"If X then Y unless Z" is represented by which of the following formulas in prepositional logic? ("¬ " is negation, "∧ " is conjunction, and "→" is
implication)
A. (X ∧ ¬Z) → Y
B. (X ∧ Y ) → ¬Z
C. X → (Y ∧ ¬Z)
D. (X → Y ) ∧ ¬Z
while ( not z ) {
if (X) then
or
unless( z ) {
if (X) then
this is what it means in programming. if you want to execute statement Y then X must be True and Z False,
option A
-- Vikrant Singh
GATE2003_33 top
α in words:
LHS implies RHS, where for I 1
LHS = If for all x, x is prime if and only if for all y, y is a factor of x if and only if y does not divide itself. In other words, for all x, if x is prime, x
cannot have any factor and if x is not having any factor then x is prime.
RHS = All x are non-prime
Here LHS is always TRUE but RHS is not true as domain of x is set of natural numbers and hence x cannot be always not prime. So, α is not
satisfiable for I 1 .
Now for I 2 ,
LHS = If for all x, x is composite if and only if for all y, y is a factor of x if and only if y does not divide itself. In other words, for all x, if x is
composite, x cannot have any factor and if x is not having any factor then x is composite.
RHS = All x are non-composite
Here, LHS can never be true. x can either be prime or composite. If x is composite, P (x) is true but the right side of double implication is false.
If x is prime, P (x) is false, but right side of double implication is true. So, the double implication never returns TRUE making LHS ofα always
FALSE. So, α becomes TRUE irrespective of RHS and I 2 is satisfiable.
-- Arjun Suresh
GATE2004_23 top
Identify the correct translation into logical notation of the following assertion.
Some boys in the class are taller than all the girls
GATE2010_30 top
Suppose the predicate F(x, y, t) is used to represent the statement that person x can fool person y at time t. which one of the statements below
expresses best the meaning of the formula
B is the correct answer.the trick is bring the negate sign to the extreme left ..form a sentence withou using negate and just negate that
-- Bhagirathi Nayak
GATE2005_41 top
What is the first order predicate calculus statement equivalent to the following?
Answer is B. In simpler way we can sayIf X is a teacher then there exists some Y who is a student and likes X.
A choice: If X is a teacher, then there exists a Y such that if Y is a student, then Y likes X.
C choice: There exist a student who likes all teachers.
D choice: Everyone is a teacher and there exists a Y such that if Y is student then y likes X. Assuming one cannot be both student and
teacher at same time, this just means, everyone is a teacher.
-- Manali
GATE2007_22 top
Let Graph(x) be a predicate which denotes that x is a graph. Let Connected(x) be a predicate which denotes that x is connected. Which of
the following first order logic sentences DOES NOT represent the statement:
D says "all graphs are not connected" but the qs says " not every graph is connected" .i.e " there exists atleast one graph which is not
connected". Hence the answer is D
-- Manali
GATE2013_27 top
-- Bhagirathi Nayak
GATE1998_1.5 top
A only if B => A->B
A= "I stay"
B= "You go"
Answer: A
-- Manali
GATE2014-1_53 top
Which one of the following propositional logic formulas is TRUE when exactly two of p, q and r are TRUE ?
(A) ((p ↔ q) ∧ r) ∨ (p ∧ q ∧ ∼ r)
(B) (∼ (p ↔ q) ∧ r) ∨ (p ∧ q∧ ∼ r)
(C) ((p → q) ∧ r) ∨ (p ∧ q∧ ∼ r)
(D) (∼ (p ↔ q) ∧ r) ∧ (p ∧ q∧ ∼ r)
A. will be true if P,Q,R are true,((p ↔q) ∧ r) will return true. So "exactly two" is false
C. if r is only true and p and q are false, first part of implication itself will result in true
D. if r is true or false, this returns false due to r and ~r present in conjunction.
B is the answer. B is true if p is TRUE and q is FALSE or vice verse, and r is true or if p and q are TRUE and r is FALSE.
PS: Actually the question should have been "TRUE ONLY when exactly two of p,q and r are TRUE"
-- Manu Thakur
GATE2014-3_1 top
L: P implies Q
M: Q implies P
N: P is equivalent to Q
D)
Lets break the given compound statements into atomic statements.
GATE2014-3_53 top
The CORRECT formula for the sentence, "not all Rainy days are Cold" is
In other words it says "Some rainy days are cold" or "Some rainy days are not cold"
Given statement is
~Vd[R(d)->C(d)]
<=>~Vd[~R(d)VC(d)]
<=> ∃ d[R(d) ^ ~C(d)]
D)
-- Srinath Sri
GATE1997_3.2 top
C) P OR (P -->Q) = P OR (NOT P OR Q)
=T OR Q
=T
-- Manali
GATE1993_8.2 top
OPTION (B)
-- Manali
GATE1994_3.13 top
Let p and q be propositions. Using only the Truth Table, decide whether
is True or False.
p q p↔q p → ¬q (p ↔ q) → (p → ¬q)
0 0 1 1 1
0 1 0 1 1
1 0 0 1 1
1 1 1 0 0
-- Arjun Suresh
GATE1996_2.3 top
GATE2008-IT_22 top
Now, doing complement gives (complement of ∀ is ∃ and vice versa while propagating negation inwards as ∀x (P) = ¬∃x (¬P) and ∃x (P)
= ¬∀x (¬P))
[∃ x, α ʌ (∀y, β ʌ (∃ u, ∀ v, ¬y))]
D choice
-- Arjun Suresh
GATE2007-IT_21 top
(A)
LHS: For every x, if P holds then Q holds
RHS: If P(x) holds for all x, then Q(x) holds for all x.
LHS implies RHS but RHS does not imply LHS.
(B)
LHS: An x exist for which either P(x) is true or Q(x) is true.
RHS: If an x exist for which P(x) is true then another x exist for which Q(x) is true.
LHS does not imply RHS, but on RHS if we change ∃xP(x) to ~∃xP(x), implication becomes TRUE.
(C)
LHS: There exist an x for which both P(x) and Q(x) are true.
RHS: There exist an x for which P(x) is true and there exist an x for which Q(x) is true.
LHS implies RHS but RHS does not imply LHS as the 'x' for P and Q can be different on the RHS
(DP
LHS: For every x, there exist a y such that P(x, y) holds.
RHS: There exist a y such that for all x P(x, y) holds.
Here RHS implies LHS but LHS does not imply RHS as the y on LHS can be different for each x.
-- Arjun Suresh
GATE2006-IT_21 top
Consider the following first order logic formula in which R is a binary relation symbol.
The formula is
The given relation is nothing but symmetry. We have both symmetric relations possible as well as anti-symmetric but neither always holds for
all sets. So they both are not valid but are satisfiable. B option.
-- Arjun Suresh
GATE2005-IT_36 top
Let P(x) and Q(x) be arbitrary predicates. Which of the following statements is always TRUE?
Answer: B
Option B says: IF for all student x if x is a girl then the student is smart THEN if the whole class comprises of girls then the whole class
comprises of smart students.
-- Jon Snow
Use quantifiers to express:->There is exactly one person whom everybody loves top
Let L(x, y) be the statement "x loves y," where the domain for both x and y consists of all people in the world.
Use quantifiers to express:
Q->There is exactly one person whom everybody loves.
E-some || A-for all ||
Answer-> Ex ( AyL(y,x) ^ Az((Aw L(w,z))->z=x) )
Can anyone explain the answer and how to solve these questions
i mean how to analyze these questions??
First of all we have only two quantifiers- exists and forall. So, first try to convert the given sentence into a sentence containing those (its just
English)
There is someone who is loved by everyone, and there is no one else who is loved by everyone
There is someone, x, who is loved by everyone, and if there is another one, y, who is loved by everyone else, means x and y are
the same person.
This can be translated into first order logic (first order logic is just propositional logic with ∃ and ∀)
Here actually in place of w, we can use y as the life of y expires immediately after ∀y(y,x) this. Using w instead of y is strictly not needed.
You can also try to express "There is at most one person whom everybody loves"
Now, the translations I did is based on my knowledge about the expressive powers of first order logic. Thats is first order logic can't be used
for all statement forms- we first need to convert it into a suitable form. Luckily there are only a few cases, which you will get experienced by
solving previous year questions in this topic. You can see the below 3 questions and they should cover almost any type of question from this
topic.
http://gateoverflow.in/256/gate1992_92-xv
http://gateoverflow.in/923/gate2003_33
http://gateoverflow.in/922/gate2003_32
-- Arjun Suresh
GATE2002_5b top
Determine whether each of the following is a tautology, a contradiction, or neither ("∨ " is disjunction, "∧ " is conjunction, "→" is implication, "¬ "
is negation, and "↔" is biconditional (if and only if).
A. A ↔ (A ∨ A)
B. (A ∨ B) → B
C. A ∧ (¬(A ∨ B))
This can be solved by Truth table. But there is something else which can be done quickly. See what each formula means:
2. (A∨B)→B If A or B then B. No guarantee that if only A is true, B need to be true. Hence neither tautology nor contradiction
3. A∧(¬(A∨B)) When A is true ¬(A∨B) will be false. So, this formula is a contradiction
-- Arjun Suresh
Comment on (R,*) group / commutative / monoid top
2) A commutative group
3) Not a semigroup
4) Not a monoid
Its a monoid.
Closure, associativity, Identity are defined for Real numbers.But inverse is not defined as R can be zero also. So (R,*) is neither Group nor
Abelian(commutative), but Monoid.
-- GateMaster Prime
P → Q = ¬P ∨ Q
¬Q → ¬P = Q ∨ ¬P
Hence, D is correct.
C choice is also correct as → is usually taken as right associative (See here: http://math.stackexchange.com/questions/12223/associativity-of-
logical-connectives ). It'll be interpreted as
((P → Q) ∧ (Q → R)) → (P → R)
This is a tautology.
-- Arjun Suresh
maths_mocktest1_11 top
A contradiction means any assignment ot variables produces a 0. So, it can never be satisfied.
Coming to B option, it says Every satisfiable formula is not tautology. This is wrong as valid formula is both satisfiable as well as tautology. If
we change "every" to "some", B option becomes correct. Actually this sentence is not grammatically correct and can also be interpreted as
"Every satisfiable formula is not a tautology" meaning some satsfiable formula is not tautology. In this case B option becomes TRUE.
-- Arjun Suresh
GATE2015-2_3 top
Which one of the following statements follows from S1 and S2 as per sound inference rules of logic?
GATE2015-1_14 top
A. (⏋p ∨ q) ∧ (p ∨ ⏋q)
B. (⏋p ∨ q) ∧ (q → p)
C. (⏋p ∧ q) ∨ ( p ∧ ⏋q)
D. (⏋p ∧ ⏋q) ∨ (p ∧ q)
p↔q
= (p→ q) ∧ (q→p)
= (⏋p ∨ q) ∧ (q → p) ( As p→ q = ⏋p ∨ q )
=(⏋p ∨ q) ∧ (⏋q ∨ p)
=(⏋p ∧ ⏋q) ∨ (p ∧ q)
So, answer C
-- Priya_das
GATE2015-2_55 top
A. ∀x ∃y R(x, y) ↔ ∃y ∀x R(x, y)
B. (∀x [∃y R(x, y) → S(x, y)]) → ∀x ∃y S(x, y)
C. [∀x ∃y (P (x, y) → R(x, y))] ↔ [∀x ∃y(¬P (x, y) ∨ R(x, y))]
D. ∀x ∀y P (x, y) → ∀x ∀y P (y, x)
Ans C.
(P → Q) ↔ (¬P ∨ Q)
Now, P(2,3) is true but P(3,2), P(4,2) etc are false and hence the implication also.
-- Vikrant Singh
GATE2015-3_24 top
In a room there are only two types of people, namely Type 1 and Type 2. Type 1 people always tell the truth and Type 2 people always lie. You
give a fair coin to a person in that room, without knowing which type he is from and tell him to toss it and hide the result from you till you ask for
it. Upon asking the person replies the following
"The result of the toss is head if and only if I am telling the truth"
Both these are of the form A → B = ¬A ∨ B. Now, the truth will be the negation of these statements which will beA ∧ ¬B which can be
expressed as
Both of these means, result is head. (Actually even if iff is replaced with if, answer would be A)
So, option A.
-- Arjun Suresh
What is the correct representation of the stmt in first-order predicate calculus ? top
a is correct.
b is wrong due to implication having lower precedence than quantifiers. It will be evaluated as
(∀x∃y man(x) ∧ intelligent(x)) ⟹ (knowledge(y) ∧ have knowledge(x, y)).
Here, for the RHS, there is no quantification for x or y , meaning it must be true for every x and y .
Ref: https://en.wikipedia.org/wiki/First-order_logic#Notational_conventions
-- Arjun Suresh
Probability top
GATE2008_27 top
Aishwarya studies either computer science or mathematics everyday. If she studies computer science on a day, then the probability that she
studies mathematics the next day is 0.6. If she studies mathematics on a day, then the probability that she studies computer science the next
day is 0.4. Given that Aishwarya studies computer science on Monday, what is the probability that she studies computer science on
Wednesday?
answer - C
prob of studying CS on Wed given that it was studied on Tue = 0.4 x 0.4 = 0.16
prob of studying CS on Wed given that Math was studied on Tue = 0.6 x 0.4 = 0.24
GATE2000_1.1 top
The minimum number of cards to be dealt from an arbitrarily shuffled deck of 52 cards to guarantee that three cards are from same suit is
There are 4 sets of cards. So, up till 8 cards there is a chance that no more than 2 cards are from a given set. But, once we pick theth9 one, it
should make 3 cards from any one of the sets. So, (C) is the answer.
-- gatecse
GATE2001_2.4 top
Seven (distinct) car accidents occurred in a week. What is the probability that they all occurred on the same day?
(a) 1
77
(b) 1
76
(c) 1
27
(d) 7
27
answer - B [EDIT]
-- ankitrokdeonsns
GATE1995_1.18 top
The probability that a number selected at random between 100 and 999 (both inclusive) will not contain the digit 7 is:
(a) 16/25
(b) (9/10)3
(c)27/75
(d) 18/25
Second digit can be chosen in 9 ways from 0−9 excluding 7 and similarly the third digit in 9 ways.
-- gatecse
GATE2002_2.10 top
Consider the following algorithm for searching for a given number x in an unsorted array A[1..n] havingn distinct values:
Assuming that x is present in A, what is the expected number of comparisons made by the algorithm before it terminates?
(A) n
(B) n − 1
(C) 2n
(D) n
2
The way I see it, the probability of getting it in 2nd try is: Probability of failing at first trial times probability of succeeding in 2nd trial.
It's not like we are removing one element from the list after the first trial.
GATE2002_2.16 top
Four fair coins are tossed simultaneously. The probability that at least one head and one tail turn up is
A. 1
16
B. 1
8
C. 7
8
D. 15
16
answer - C
probability of getting at least one head and one tail = 1 - 1/16 - 1/16 = 7/8
-- ankitrokdeonsns
GATE2006_21 top
For each element in a set of size 2n, an unbiased coin is tossed. The 2n coin tosses are independent. An element is chosen if the
corresponding coin toss was a head. The probability that exactly n elements are chosen is
2n C
(A) n
4n
2n C
(B) n
2n
(C) 1
2n C
n
(D) 1
2
answer - A
-- ankitrokdeonsns
GATE2004_78 top
Two n bit binary strings, S 1 and S 2 are chosen randomly with uniform probability. The probability that the Hamming distance between these
strings (the number of bit positions where the two strings differ) is equal to d is
A. n
C d /2 n
B. n
C d /2 d
C. d/2 n
D. 1/2 d
answer - A
there n binary digits that can differ but only d should differe in this case
no of ways = nC d/2n
-- ankitrokdeonsns
GATE2010_27 top
Prime factorization of 10 = 2 × 5 .
So, 1099 = 2 99 × 5 99 and
No. of possible factors for 1099 = No. of ways in which prime factors can be combined
= 100 × 100 (1 extra possibility for each prime number as prime factor raised to 0 is also possible for a factor)
= 16
1
= 625
Here we can prime factorize 1000 as 2 3 × 5 3 . Now, any factor of 1000 will be some combination of these prime factors. For 2, a factor has 4
options - 2 0 , 2 1 , 2 2 or 2 4 . Similarly 4 options for 5 also. This is true for any numbern , if n can be prime factorized as am
1
1.
am
2
2. … .
am
n ,
n
the extra one in each factor term coming for power being 0.
-- Arjun Suresh
GATE2005_52 top
A random bit string of length n is constructed by tossing a fair coin n times and setting a bit to 0 or 1 depending on outcomes head and tail,
respectively. The probability that two such randomly generated strings are not identical is:
answer - D
suppose there are k places within n bit string where mismatch has occoured
probability of this occouring is nC k (prob. of mismatch)k (prob. of match)(n - k) = nC k (1/2)k (1/2)(n-k) = nC k (1/2)n
k can range from 1 to n hence required probability sum(nC k (1/2)n) where k ranges from 1 to n
Alternatively
-- ankitrokdeonsns
GATE2007_24 top
Suppose we uniformly and randomly select a permutation from the 20! permutations of 1, 2, 3 ... ,20. What is the probability that 2 appears at
an earlier position than any other even number in the selected permutation?
There are 10 even numbers (2,4,..20) possible as the one in the earliest position and all of these are equally likely. So, the probability of 2
becoming the earliest is simply 1 .
10
-- Arjun Suresh
GATE2013_24 top
Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the
expected number of unordered cycles of length three?
Probability that 3 vertices form a cycle = Probability of edge between vertices 1 and 2 * Probability of edge between vertices 2 and 3
* Probability of edge between vertices 1 and 3
-- Arjun Suresh
GATE1998_1.1 top
A die is rolled three times. The probability that exactly one odd number turns up among the three outcomes is
(a) 1
6
(b) 3
8
(c) 1
8
(d) 1
2
answer - B
there are total 8 possible combinations for three rolls of the die
out of them only 3 will have exactly one odd number {OEE, EOE, EEO}
probability = 3/8
-- ankitrokdeonsns
GATE1998_3a top
Two friends agree to meet at a park with the following conditions. Each will reach the park between 4:00 pm and 5:00 pm and will see if the
other has already arrived. If not, they will wait for 10 minutes or the end of the hour whichever is earlier and leave. What is the probability that
the two will not meet?
We are given that both will be reaching the park between 4:00 and 5:00.
Probability that one friend arrives between 4:00 and 4:50 = 5/6
Probability that one friend arrives between 4:00 and 4:50 and meets the other arriving in the next 10 minutes = 5/6 * 1/6 * 2 = 10/36 = 5/18
(For any time of arrival between 4:00 and 4:50, we have a 10 minute interval possible for the second friend to arrive, and 2 cases as for
choosing which friend arrives first)
Probability that both friend arrives between 4:50 and 5:00 = 1/6*1/6 = 1/36
= 1 - (5/18 + 1/36)
= 1 - 11/36
=25/36
-- Arjun Suresh
GATE2014-1_2 top
Suppose you break a stick of unit length at a point chosen uniformly at random. Then the expected length of the shorter stick is ________ .
Length of shorter stick can be from 0 to 0.5 (because if it is greater than 0.5, it is no longer a shorter stick). This random variable L (length of
shorter stick) follows a uniform distribution, and hence probability density function of L is for all lengths in range 0 to 0.5.
-- Happy Mittal
GATE2014-1_48 top
X . The value of
Four fair six-sided dice are rolled. The probability that the sum of the results being 22 is
1296
X is _______
There are only two possible sets whose elements sum to 22 : {6,6,6,4}, {6,6,5,5}
So X =10.
-- Happy Mittal
GATE-2014-2_1 top
The security system at an IT office is composed of 10 computers of which exactly four are working. To check whether the system is functional, the officials inspect
four of the computers picked at random (without replacement). The system is deemed functional if at least three of the four computers inspected are working. Let
the probability that the system is deemed functional be denoted by p. Then 100p = _____________.
Case 1 : three computers are functional : There are 4 sub-cases WWWN, WWNW, WNWW, NWWW, where W means working, N means
non-working, but P(WWWN) = P(WWNW) = P(WNWW) = P(NWWW), because for example
In all other 3 sub-cases, we get same numerators and denominators (in different order), so total prob in this case is 4*144/5040 = 576/5040.
So 100 * p =11.90
-- Happy Mittal
GATE2014-2_2 top
Each of the nine words in the sentence ‘‘T he quick brown fox jumps over the lazy dog” is written on a separate piece of paper. These nine pieces of
paper are kept in a box. One of the pieces is drawn at random from the box. The expected length of the word drawn is _____________. (The answer should be
rounded to one decimal place.)
Each of the nine words have equal probability. So, expected length
1 1 1 1 1 1 1 1 1
= 3× 9
+ 5× 9
+ 5× 9
+ 3× 9
+5× 9
+4× 9
+3× 9
+4× 9
+3× 9
= 35
9
= 3.9
-- Arjun Suresh
GATE2011_3 top
If two fair coins are flipped and at least one of the outcomes is known to be a head, what is the probability that both outcomes are heads?
(A) 1/3
(B) 1/4
(C) 1/2
(D) 2/3
answer - A
GATE1994_1.4 top
Since ,
-- Happy Mittal
GATE1994_2.8 top
GATE1995_2.14 top
answer - C
GATE1996_1.5 top
1-(no 6 in both the dice)=1-(5/6 *5/6)=11/36
-- Bhagirathi Nayak
GATE1996_2.7 top
There are 52 cards including 4 aces so the probabilit must be 4/52 * 3/51
-- Bhagirathi Nayak
GATE2006-IT_22 top
When a coin is tossed, the probability of getting a Head is p, 0 < p< 1. Let N be the random variable denoting the number of tosses till the first
Head appears, including the toss where the Head appears. Assuming that successive tosses are independent, the expected value of N is
A) 1/P
B) 1/(1 - P)
C) 1/P2
D) 1/(1 - P2)
E - (1 - p)E = p * 1 + (1 - p)p + (1 - p)(1 - p)p +.... = p /(1 - (1 -p)) = 1 (because it's now forming a GP)
=>(1 - 1 + p)E = 1
=> E = 1 / P
GATE2004-IT_33 top
Let X and Y be two exponentially distributed and independent random variables with mean α and β, respectively. If Z = min (X, Y), then the
mean of Z is given by
A) (1/(α + β))
B) min (α, β)
C) (αβ/(α + β))
D) α+β
X is an exponential random variable of parameter λ when its probability distribution function is
f(x) = { λe
−λx
x≥0
0 x<0
a a
Fx (a) = ∫ f(x)dx = ∫ λe−λx dx = −e−λx ∣a0 = 1 − e−λa
0 0
So,
P {X < a} = 1 − e−λa
and
P {X > a} = e−λa
Now, we use P {X > a} for our problem because our concerned variable Z is min of X and Y .
P {X > a} = e− α a
1
1
P {Y > a} = e− β a
)a
α+ β
−(
=e αβ
α+ β αβ
This shows that Z is also exponentially distributed with parameter and mean .
αβ α+β
R e f : http://ocw.mit.edu/courses/mathematics/18-440-probability-and-random-variables-spring-2011/lecture-
notes/MIT18_440S11_Lecture20.pdf
-- Arjun Suresh
Answer is 0.75
As X3 = 0 is given, to have Y = 0, X1X2 should be 0, meaning (X1, X2) should be one of {(0,0) (0,1) (1,0)}....
Consider the set {a, b, c} with binary operators + and ∗ defined as follows.
+ a b c
a b a c
b a b c
c a c b
* a b c
a a b c
b b c a
c c c b
(a ∗ x) + (a ∗ y) = c
(b ∗ x) + (c ∗ y) = c
The number of solution(s) (i.e., pair(s) (x, y) that satisfy the equations) is
Given a set of elements N = {1, 2, ..., n} and two arbitrary subsets A⊆N and B⊆N, how many of the n! permutationsπ from N to N satisfy min(
π(A)) = min(π(B)), where min(S) is the smallest integer in the set of integers S, andπ(S) is the set of integers obtained by applying permutation
π to each element of S?
|A∩B| |A∩B| 2
(A) (n - |A ∪ B|) |A| |B| (B) (|A|2 + |B|2 )n 2 (C) n! (D)
|A∪B| nC
|A∪B|
min(π(N)) = 1, since in a permutation of n elements from 1..n, some element must get 1.
Similarly, in any subsets A and B, min(π(A)) = min(π(B)) only if A and B has a common element and its permutation is the smallest of all the
other elements in A and B.
Now we have n! total permutations and we have to see the number of permutations satisfying the given condition. If A = B, all of the n!
permutations satisfy the given condition. (This is enough to get the answer as C). Otherwise, the fraction of the n! permutations satisfying the
given condition
= |A ⋂ B| / |A ⋃ B|
This is because without the given restriction, the smallest element (among the |A ⋃ B| elements) can be any one of the |A ⋃ B| elements, and
with the restriction, the smallest element must be one of the |A⋂B| elements.
So, answer is C.
-- Arjun Suresh
GATE2010_3 top
A relation consists of set of ordered pairs(a, b). Here a can be chosen in n ways and similarly b can be chosen in n ways. So, totally n 2
possible ordered pairs are possible for a relation. Now each of these ordered pair can either be present in the relation or not- 2 possibilities for
each of the n 2 pair. So, total number of possible relations =
2 (n
2)
Now, for a relation R to be reflexive, ordered pairs {(a, a) ∣ a ∈ S} , must be present in R. i.e.; the relation set R must have n ordered pairs
fixed. So, number of ordered pairs possible is n 2 − n and hence total number of reflexive relations is equal to
2 (n
2 −n)
-- Arjun Suresh
GATE1999_3 top
-- Happy Mittal
GATE2014-1_50 top
Let S
ܵ denote the set of all functions f : {0, 1} 4 → {0, 1} . Denote by N the number of functions from S to the set {0, 1} . The value of log2 log2 N is _______.
For a function from set A to set B, we need to have a mapping for all elements of A and mapping must be unique.
Let number of elements in A be m and that in B be n
So, if we consider an element from A, it can be mapped to any of the element from B. i.e., it has n possibilities when a function is formed.
Similarly, for all other members also there are n possibilities as one element from A can be mapped to only a single element in B (though
reverse need not true). So, for n elements in A, we totally have n × ⋯ × n = n m possible functions.
m times
In the question Number of elements (functions) in f is 2 2 as {0, 1} 4 contains 2 4 elements. So, number of functions from S to {0, 1} will be
4
4
2 2 . So, log2 log2 N = 2 4 = 16.
2
-- Arjun Suresh
GATE2014-2_5 top
A non-zero polynomial f(x) of degree 3 has roots at x = 1 , x = 2 and x = 3 . Which one of the following must be TRUE?
So f(0)f(4) < 0.
-- Happy Mittal
GATE2014-3_2 top
Let X and Y be finite sets and f : X → Y be a function. Which one of the following statements is TRUE?
D)
Let x = { a , b , c } and y = { 1 , 2 }
A Function f maps each element of x to 1 in y.
f(a)=1 , f(b)=1 , f(c) =1
A={a,b}B={b,c}
A)
|f ( A u B )| = |f ({a,b,c})| = 3
|f(A)|+|f(B)| = 2 + 2 = 4 , LHS != RHS.
B)
f ( A ∩ B ) = f ({b}) = { 1 }
f(A) ∩ f(B) = { 1 , 1 } ∩ { 1 , 1 } = { 1 , 1 }
LHS!=RHS
C)
|f ( A ∩ B )| = |f ({b})| = |{ 1 }| = 1
min{|f(A)|,|f(B)|} = min(2,2) = 2
LHS!=RHS
D) Its easy to see that this is true because in a function a value can be mapped only to one value.
-- Srinath Sri
GATE2014-3_49 top
Consider the set of all functions f : {0, 1, … , 2014} → {0, 1, … , 2014} such that f(f(i)) = i, for all 0 ≤ i ≤ 2014 . Consider the following
statements:
P . For each such function it must be the case that for every i, f(i) = i.
Q . For each such function it must be the case that for some i, f(i) = i.
Let f(i) = j. Now, we have f(j) = i, as per the given condition f(f(i)) = i.
When j = i, the condition holds and since domain and co-domain of the functions do intersect (actually same),Q is definitely true.
Since f(i) = j and f(j) = i, and since 0 ≤ i ≤ 2014 i must take all 2015 possible values (since f is a function, it must have a value for any
element in the domain). We can easily see that f(i) cannot be the same for two different is- because suppose f(2) = 5 , and f(3) = 5 . Now
as per given condition, f(5) = 2 and f(5) = 3 , which is not allowed in a function. So, allf(i) values are unique ⟹ co-domain = range as
there are only 2015 values in co-domain. So, R is true.
An identity function satisfies the given conditions. But that alone cant prove that P is true. We can also have a different function where all even
numbers maps to the next odd number and all odd numbers map to the previous even number which satisfies the given conditions. i.e.,
f(0) = 1, f(1) = 0, f(2) = 3, f(3) = 2 … f(2015) = 2014 . This proves, P is false.
GATE2014-3_50 top
There are two elements x, y in a group (G, ∗) such that every element in the group can be written as a product of some number ofx's and y 's
in some order. It is known that
where e is the identity element. The maximum number of elements in such a group is ____.
And so the answer is 4.
-- Gate Keeda
GATE1997_4.4 top
A polynomial p(x) is such that p(0) = 5, p(1) = 4, p(2) = 9 and p(3) = 20. The minimum degree it should have is
A. 1
B. 2
C. 3
D. 4
p(1) = 4 => a + b = 4, a = -1
p(0) = 5 => c = 5
-- Arjun Suresh
GATE1997_6.1 top
A partial order ≤ is defined on the set S = {x, a1, a2, ... an, y} as x ≤ ai for all i and ai ≤ y for all i, where n ≥ 1. The number of total orders on the
set S which contain the partial order ≤ is
A. n!
B. n+2
C. n
D. 1
To make this partial order a total order, we need the relation to hold for every two element of the partial order. Currently between any iaand
aj, there is no relation. So, for every ai, aj, we have to add either (ai, aj) or (aj, ai) in total order. So, this translates to giving an ordering for n
elements between x and y, which can be done in n! ways. So, answer is (a).
The bottom figure is for a total order. We can permute the ai from i = 1 to n, and each permutation will also be a total order containing the
given partial order.
-- Arjun Suresh
GATE1997_6.3 top
Ans A. no. of equivalence relations = no. of partition set possible = 1 (all four elements) + 3(2 + 2 elements partition) + 4(3 + 1 element
partition) + 6 (2 + 1 + 1 element partition) + 1 (1 + 1+ 1+ 1 element partition) = 15
-- Vikrant Singh
GATE1995_23 top
Prove using mathematical induction for n ≥ 5, 2 n > n 2
GATE1996_1.1 top
(a - b) U (b - a) U (a ^ b)
a - b is a but not b i.e. only a
b - a. is b but not a i.e. only b
a ^ b is a and b both
GATE1996_2.1 top
Let R denote the set of real numbers. Let f : R × R → R × R be a bijective function defined by f(x, y) = (x + y, x − y). The inverse function
of f is given by
(a) f −1 (x, y) = ( 1 , 1 )
x+y x−y
(b) f −1 (x, y) = (x − y, x + y)
(c) f −1 (x, y) = ( )
x+y x−y
2
, 2
z1=x+y
z2=x-y
-- neha pawar
GATE1996_8 top
Let F be the collection of all functions f: {1, 2, 3} → {1, 2, 3}. If f and g ∊ F, define an equivalence relation ~ by f~g if and only if f(3) = g(3).
a. So, total number of equivalence classes = 3, one each for 3 -> 1, 3 -> 2, and 3 -> 3.
On a set of n elements, how many relations are there that are both irreflexive and
antisymmetric? top
On a set of n elements, how many relations are there that are both irreflexive and antisymmetric?
A relation consists of set of ordered pairs (a, b). Here a can be chosen in n ways and similarly b can be chosen in n ways. So, totally n 2
possible ordered pairs are possible for a relation. Now each of these ordered pair can either be present in the relation or not- 2 possibilities for
each of the n 2 pair. So, total number of possible relations =
2 (n
2)
Now, for a relation R to be reflexive, ordered pairs {(a, a) ∣ a ∈ S} , must be present in R. i.e.; the relation set R must have n ordered pairs
fixed. So, number of ordered pairs possible is n 2 − n and hence total number of reflexive relations is equal to
2 (n
2 −n)
Number of irreflexive relations is same as number of reflexive relations. In reflexive relations we always included n ordered pairs for
{(a, a) ∣ a ∈ S} , while in irreflexive relation we always omit thosen ordered pairs. So, the number of ordered pairs to choose for the relation
is the same for both reflexive as well as irreflexive relations which is
2 (n
2 −n)
A relation becomes symmetric, if for ordered pair (a, b) in R, ordered pair (b, a) is also present in R. So, here, the total number of ordered
pairs possible is reduced from
n + n + ⋯ + n to
n(n+1)
n+n−1+n−2+⋯+1= 2
.
( )
n(n+1)
2 2
A relation becomes anti-symmetric if for the ordered pairs (a, b) and (b, a) in R, a = b . i.e., the pairs (a, b) and (b, a) cannot be simultaneously
be in the relation unless a = b .
For the n pairs (a, a) in R, they can be either present in relation or absent. So, 2 possibilities for each giving2 n possible relations.
n(n−1)
Number of pairs (a, b) in R such that a ≠ b equals number of ways of selecting 2 numbers fromn without repetition, equals
2
Now, for each of these pairs (a, b), there are 3 possibilities-
Finally, coming to your question, number of relations that are both irreflexive and anti-symmetric which will be same as the number of
relations that are both reflexive and antisymmetric is
( )
n(n−1)
3 2
We just have to always exclude n pairs being considered for (a, a) while calculating the possible relations for anti-symmetric case.
-- Arjun Suresh
GATE2008-IT_28 top
ans is (1)
hasse diagram is lattice when every pair of element have least upper bound and greatest lower bound.in fig 2 and 3 every element will not
have least upper bound and greatest lower bound so they are not lattice.
-- neha pawar
GATE2007-IT_23 top
A partial order P is defined on the set of natural numbers as follows. Here x/y denotes integer division.
i. (0, 0) ∊ P.
ii. (a, b) ∊ P if and only if a % 10 ≤ b % 10 and (a/10, b/10) ∊ P.
i. (101, 22)
ii. (22, 101)
iii. (145, 265)
iv. (0, 153)
Ans. D
For ordered pair (a, b), to be in P, each digit in a starting from unit place must not be larger than the corresponding digit in b.
GATE2007-IT_76 top
Suppose there exists a non-empty, open interval such that for all satisfying , the sequence converges to a limit. The
sequence converges to the value?
A)
B)
C)
D)
or
Solving for x:
GATE2006-IT_2 top
For the set N of natural numbers and a binary operation f : N x N → N, an element z ∊ N is called an identity for f, if f (a, z) = a = f(z, a), for all a
∊ N. Which of the following binary operations have an identity?
I. f (x, y) = x + y - 3
II. f (x, y) = max(x, y)
III. f (x, y) = xy
A) I and II only
B) II and III only
C) I and III only
D) None of these
Answer: A
I. Identity element is 3.
-- Jon Snow
GATE2006-IT_24 top
A) 28
B) 33
C) 37
D) 44
No's divisible by 3 in X = 41
No's divisible by 5 in X = 24
= 61 +41+24 -20-12-8 +4 = 90
Cardinality = 123 - 90 = 33
-- Praveen Saini
GATE2005-IT_31 top
Let f be a function from a set A to a set B, g a function from B to C, and h a function from A to C, such that h(a) = g(f(a)) for all a ∈ A. Which of
the following statements is always true for all such functions f and g?
Let h be onto (onto means co-domain = range). So, h maps to every element in C from A. Since h(a) = g(f(a)), g should also map to all
elements in C. So, g is also onto -> option (C).
-- Arjun Suresh
GATE2005-IT_33 top
Let A be a set with n elements. Let C be a collection of distinct subsets of A such that for any two subsets S
1 and S2 in C, either S1 ⊂ S2 or S2⊂
S1. What is the maximum cardinality of C?
1) n
2) n+1
3) 2n-1 + 1
4) n!
Let's start by adding sets of size 1 to S. We can only add one of the sets {a}, {b}, {c}.
Now lets add sets of size 2 to S. Again we see that we can only add one of {a,b}, {a,c} or {b,c}, and we cannot add {b,c} since we already
added {a}.
Continuing this way we see we can add only one set for a all size till n.
maths_mock_test4 top
2 is correct answer. fig 2, b and c have {f,g} as upperbound. but for the graph to be a lattice it should have a least upper bound. Since b and c
have two upper bounds they cannot have a least upper bound<which is always unique for a pair for vertices>. In other words we cannot say
which one is least one out of the pair {f,g}. therefore it is not a join semilattice(every pair of element should have a least upper bound).
henceforth it is also not a lattice
-- Madhur Rawat
GATE2015-1_5 top
g(h(x))
If g(x) = 1 − x and h(x) = x , then is:
x−1 h(g(x))
h(x)
A.
g(x)
B. −1
x
g(x)
C.
h(x)
D. x
(1−x) 2
option a) is correct.
g(h(x)) = g( x−1
x
)
= 1− x
x−1
−1
= x−1
h(g(x)) = h(1 − x)
= 1−x
−x
g(h(x)) h(x)
= x
=
h(g(x)) (1−x)(x−1) g(x)
option A)
-- GateMaster Prime
GATE2015-2_GA_9 top
If p, q, r, s are distinct integers such that:
remainder of
Answer:
-- Shyam Singh
GATE2015-2_9 top
The number of divisors of 2100 is ____.
Answer: 36
2100 = 7*3*22*52
because any factor is obtained by multiplying the prime factors zero or more times. (one extra for zero)
-- Jon Snow
GATE2015-2_18 top
The cardinality of the power set of {0, 1, 2, … , 10} is _______
Answer: 2048
-- Jon Snow
GATE2015-2_26 top
Let f(x) = x−(1/3) and A denote the area of region bounded byf(x) and the X-axis, when x varies from -1 to 1. Which of the following
statements is/are TRUE?
I. f is continuous in [-1, 1]
II. f is not bounded in [-1, 1]
III. A is nonzero and finite
A. II only
B. III only
C. II and III only
D. I, II and III
Answer: C
I. False.
II. True.
III. True. An area is always positive, while the definite integral might be composed of several regions, some positive and some negative. A
definite integral gets you the net area, because any part of the graph that is below the x-axis will give you a negative area. So, a definite
integral is not necessarily the area under the curve, but the value of the area above the x-axis less the area under the x-axis. So, A is non-
zero and finite.
-- Jon Snow
GATE2015-1_16 top
For a set A, the power set of A is denoted by 2 A . If A = {5, {6}, {7}} , which of the following options are TRUE?
I. ϕ ∈ 2A
II. ϕ ⊆ 2A
III. {5, {6}} ∈ 2 A
IV. {5, {6}} ⊆ 2 A
Power set of A consists of all subsets of A and from the definition of a subset, ϕ is a subset of any set. So, I and II are TRUE.
5 and {6} are elements of A and hence {5, {6} } is a subset of A and hence an element of 2A. An element of a set is never a subset of the set.
For that the element must be inside a set- i.e., a singleton set containing the element is a subset of the set, but the element itself is not. Here,
option IV is false. To make IV true we have to do as follows:
-- Arjun Suresh
GATE2015-2_54 top
Let X and Y denote the sets containing 2 and 20 distinct objects respectively andF denote the set of all possible functions defined fromX to
Y . Let f be randomly chosen from F . The probability of f being one-to-one is ______.
For a function, the first element in X has 20 choices (to map to) and the second element also has 20 choices. For a one-to-one function the
second element has only 19 choices left after 1 being taken by the first. So, required probability
GATE2015-1_39 top
g is preserving 0 as when all inputs are zero, output is always 0 and so g cannot be functionally complete.
f is not preserving 0.
f is not preserving 1. (when all inputs are 1, output is 0).
f is not linear as in XY' only one (odd) input needs to be 1 and in X'YZ two inputs (even) needs to be 1.
f is not monotone as changing Y from 0 to 1, can take f from 1 to 0.
f is not self dual as f(X, Y, Z) ≠ ~f(~X, ~Y, ~Z)
So, f satisfies all 5 conditions required for functional completeness and hence B is the answer.
http://cs.ucsb.edu/~victor/ta/cs40/posts-criterion.pdf
-- Arjun Suresh
GATE2015-3_2 top
Which are the following is/are true for the Boolean variables P, Q and R?
A. Only S1 is true
B. Only S2 is true
C. Both S1 and S2 are true
D. Neither S1 nor S2 are true
Answer=B
(P#Q)#R=(P'+Q')#R
=P.Q+R'
whereas
P#(Q#R)=P'+(Q#R)'
=P'+(Q'+R')'
=P'+QR
-- overtomanu
GATE2015-3_5 top
The number of 4 digit numbers having their digits in non-decreasing order (from left to right) constructed by using the digits belonging to the set
{1, 2, 3} is ________.
you can arrive at a solution by constructing a graph for each starting digit. for example root 3 means - starting with 3 it can have 3 child 1,2,3
and the construction goes
1 can have only 1 as child. Graph need to be done till three levels
GATE2015-3_23 top
Suppose U is the power set of the setS = {1, 2, 3, 4, 5, 6} . For any T ∈ U , let |T | denote the number of elements in T and T ′ denote the
complement of T . For any T , R ∈ U let T ∖R be the set of all elements inT which are not in R. Which one of the following is true?
A. ∀X ∈ U, (|X| = |X ′ |)
B. ∃X ∈ U, ∃Y ∈ U, (|X| = 5, |Y | = 5 and X ∩ Y = ϕ)
C. ∀X ∈ U, ∀Y ∈ U, (|X| = 2, |Y | = 3 and X∖Y = ϕ)
D. ∀X ∈ U, ∀Y ∈ U, (X∖Y = Y ′ ∖X ′ )
Answer D
Option B is wrong as any two possible subsets of S with 5 elements should have atleast 4 elements in common.Hence X intersection Y not
null
Option C is wrong, consider X={1,2} y={3,4,5} and X\Y={1,2} which is not null
-- overtomanu
GATE2015-3_41 top
Let R be a relation on the set of ordered pairs of positive integers such that((p, q), (r, s)) ∈ R if and only if p − s = q − r. Which one of the
following is true about R?
so it is symmetric.
-- Tamojit Chatterjee
Combinatory top
GATE2008_24 top
Let P = ∑ i and Q = ∑ 1≤i≤2k i , where k is a positive integer. Then
1≤i≤2k
i odd i even
(A) P = Q−k
(B) P = Q+k
(C) P =Q
(D) P = Q + 2k
Substitute k=3 then we get p=9 and q=12 on verifying we get option A.
-- kireeti
GATE2002_13 top
a. In how many ways can a given positive integern ≥ 2 be expressed as the sum of 2 positive integers (which are not necessarily distinct).
For example, for n = 3 the number of ways is 2, i.e., 1+2, 2+1. Give only the answer without any explanation.
b. In how many ways can a given positive integern ≥ 3 be expressed as the sum of 3 positive integers (which are not necessarily distinct).
For example, for n = 4 , the number of ways is 3, i.e., 1+2+1, 2+1+1. Give only the answer without explanation.
c. In how many ways can a given positive integern ≥ k be expressed as the sum of k positive integers (which are not necessarily distinct).
Give only the answer without explanation.
This is same as number of ways of putting n-2 (as we can't have 0 for either x1 or x2) identical balls into two distinct bins, which is obtained by
putting a divider across n-2 balls and taking all possible permutations with n-2 being identical. i.e., (n-2 + 1)!/(n-2)! = (n-1). We can also use
the following formula
n-2+2-1C =n-1C 1
2-1
Here, we can permute n-3 items with 2 dividers which will give (n-3 + 2)!/(n-3)!2!
= (n-1)!/(n-1-2)!2!
=n-1C 2
-- Supromit Roy
GATE2003_4 top
Let A be a sequence of 8 distinct integers sorted in ascending order. How many distinct pairs of sequences, B and C are there such that
answer - C
GATE2003_5 top
n couples are invited to a party with the condition that every husband should be accompanied by his wife. However, a wife need not be
accompanied by her husband. The number of different gatherings possible at the party is
(2n)!
(A) 2n C n × 2 n (B) 3 n (C) (D) 2n C n
2n
-- Palash Nandi
GATE2005_35 top
How many distinct binary search trees can be created out of 4 distinct keys?
A. 5
B. 14
C. 24
D. 42
answer - B
-- ankitrokdeonsns
GATE1998_1.23 top
no of strings of length 1 = n
no of strings of length 2 = n-1
no of strings of length 3 = n-2
.
.
.
no of string of length n = 1
total = n + (n -1) + (n - 2) + (n - 2) + ..... + 1
= n(n+1)/2
-- Digvijay Pandey
GATE2014-1_49 top
A pennant is a sequence of numbers, each number being 1 or 2. An n -pennant is a sequence of numbers with sum equal to n . For example, (1, 1, 2) is a 4-
pennant. The set of all possible 1-pennants is (1) , the set of all possible 2-pennants is(2), (1, 1) and the set of all 3-pennants is (2, 1), (1, 1, 1), (1, 2) . Note
that the pennant (1, 2) is not the same as the pennant (2, 1) . The number of 10-pennants is________
A 10-pennant means sum of numbers in sequence is 10. If we look at any 9-pennent, we can make it a 10-pennant by adding 1 into that
sequence. Similarly, we can make any 8-pennant a 10-pennant by adding 2 into that sequence.
So all 10-pennants can be formed by 8-pennants and 9-pennants, and no other pennant (since we can add only 1 or 2 into a sequence)
This is in fact a fibonacci sequence, in which F(1) = 1, f(2) = 2, so this sequence becomes
So f(10) = 89.
-- Happy Mittal
GATE2014-2_49 top
Now to get a factor of 2014, we can choose any combination of the prime factors including 0. i.e; 02 and 21 are possible and similarly for other
prime factors also, there are 2 possibilities. So, total number of positive integral factors
= 2×2×2= 8
(When all the powers of prime factors are 0, we get 1 and when all the powers are maximum, we get the given number.)
-- Arjun Suresh
GATE1994_1.15 top
so n(n+1)/2
-- Bhagirathi Nayak
GATE2008-IT_25 top
In how many ways can b blue balls and r red balls be distributed in n distinct boxes?
(n+b−1)! (n+r−1)!
A)
(n−1)! b! (n−1)! r!
(n+(b+r)−1)!
B)
(n−1)! (n−1)! (b+r)!
C) n!
b! r!
(n+(b+r)−1)!
D)
n! (b+r−1)
r red balls can be distributed into n distinct boxes in C(n+r-1,r) = .(n+r-1)! / (n-1)! r!
SO THE ANSWER IS A.
-- Madhu Veluguri
GATE2005-IT_46 top
A line L in a circuit is said to have a stuck-at-0 fault if the line permanently has a logic value 0. Similarly a line L in a circuit is said to have a
stuck-at-1 fault if the line permanently has a logic value 1. A circuit is said to have a multiple stuck-at fault if one or more lines have stuck at
faults. The total number of distinct multiple stuck-at faults possible in a circuit with N lines is
A) 3N
B) 3N - 1
C) 2N - 1
D) 2
This is because the total possible combinations (i.e a line may either be at fault (in 2 ways i.e stuck at fault 0 or 1) or it may not be , so there
are only 3 possibilities for a line ) is 3^N. In only one combination the circuit will have all lines to be correct (i.e not at fault.) Hence 3^N-1. (as it
has been said that circuit is said to have multiple stuck up fault if one or more line is at fault )
How many strings of length 10 over the alphabet {a, b, c} have either exactly three a's or
exactly four b's? top
Case 1: Exactly 3 a's: We fill 3 places with 3 a's in 3C3 * 10C3 ways. Now, remaining 7 places can be filled using b or c in72ways.
Case 2: Exactly 4 b's: We fill 4 places with 4 b's in 4C4 * 10C4 ways. Remaining 6 places can be filled using a or c in62ways.
So, number of strings possible = Case 1 + Case 2 - Case 3 = 10C3 * 128 + 10C4 * 64 - 4200 = 24,600
-- Arjun Suresh
We have to arrange 8 a's, 3 b's, 4 c's and 5 d's.. i.e Permutation to find possible number of answer keys that are possible=20! but the all a's
are identical, b's are identical , c's are identical and d's are identical, therefore Answer is = 20!/(8! . 3! . 4! . 5!)= 3491888400
-- Prateeksha Keshari
The maximum number of distinct subwords of the word "AXIOMATIZABLE" is: a)183 b) 111
c)92 d)88 top
Subwords means letters must be consecutive as in the word. Since, the given word has 13 letters we can have
13 subwords of 1 letter
12 subwords of 2 letters
11 subwords of 3 letters
....
1 subword of 13 letters
No two consecutive letters are repeating in the given word. But there are 3 A's, and 2 I's. So, 3 subwords of length 1 are counted extra. So,
total number of distinct subwords = 91 - 3 = 88.
-- gatecse
4 * 23 = 32
Of length 4, one we take for 1. Remaining 3 characters can be filled with 2 symbols in 23 = 8 ways. Now, the one can be placed in 4 ways
between the 3 characters giving 4 * 8 = 32 strings.
-- Arjun Suresh
How many seven digits number are there such that Digits are distinct integers taken from
{1, 2, ..., 9} and Digits 5 and 6 do not appear together (consecutively) top
Case 1: 5 and 6 appear together. Here, it can be 56 or 65. So, 2 ways and remaining we have 5 digits to chose from 7 and 6! ways (5 digits
plus 56 or 65) to arrange them. This gives 2! * 7C5 * 6! = 42 * 720
GATE2012_38 top
Let G be a complete undirected graph on 6 vertices. If vertices of G are labeled, then the number of
distinct cycles of length 4 in G is equal to
(A) 15 (B) 30 (C) 90 (D) 360
No. of cyclic permutations of n objects = (n-1)! and for n = 4, we get 3! = 6 ways. But number of distict cycles in a graph is exactly half the
number of cyclic permutations as there is no left/right ordering in a graph. For example a - b - c - d and a - d - c - b are different permutations
but in a graph they form the same cycle.
Since, 45 was not in the choice, marks were given to all in GATE.
-- gatecse
GATE1991_01,xv top
The maximum number of possible edges in an undirected graph withn vertices and k components is ______.
Hopefully it should be clear that in any such graph all components will be complete, i.e., have all possible edges. Thus the
only remaining question is how large each component should be?
If there are two components with a and b vertices, a > 1, b > 1 , then together they can have at most
( a2 ) + ( b2 ) = 1
2
(a2 − a + b 2 − b) edges.
However, if we place all but one of the vertices in a single component, we could have
( a+b−1
2
) + ( 12 ) = 1
2
(a + b − 1)(a + b − 2)
= 1
2
(a + 2ab − 3a + b 2 − 3b + 2) edges.
2
This leaves us with the answer that all components should have one vertex except one, which will have n − k + 1 vertices, for
a total of ( n−k+1
2
) edges.
reference @ http://www.quora.com/What-is-the-maximum-number-of-edges-in-graph-with-n-vertices-and-k-components
GATE2003_8 top
Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G , the number of components in the resultant graph
must necessarily lie down between
A. k and n
B. k − 1 and k + 1
C. k − 1 and n − 1
D. k + 1 and n − k
Lower Bound: number of components decreased by one = k - 1 ( remove a vertex from 'n' isolated vertices)
Upper Bound: number of components = n-1 ( remove the center vertex of a star graph )
Therefore (C)
-- Danish
GATE2003_36 top
How many perfect matching are there in a complete graph of 6 vertices?
Note: To understand the solution please go through the definitions of perfect matching
The complete graph kn have a perfect matching only when n is even.. So let n=2m.
Similarly go till V2m which will have only one vertex to be joined with..
-- Hunaif
GATE2003_40 top
A graph G = (V , E) satisfies |E| ≤ 3|V | − 6. The min-degree of G is defined as min v∈V {degree(v)}. Therefore, min-degree of G cannot be
Consider an undirected graph G where self-loops are not allowed. The vertex set of G is {(i, j) ∣ 1 ≤ i ≤ 12, 1 ≤ j ≤ 12} . There is an edge between (a, b)
and (c, d) if |a − c| ≤ 1 and |b − d| ≤ 1 . The number of edges in this graph is______.
If you think of a 12 * 12 grid (like a chess board of size 12*12), then each each point (i,j), which is in ith row and jth column, is a vertex (i,j).
Now we are allowed to connect only those points which are atmost 1 distance apart (in both horizontal and vertical direction). So we will
connect only horizontal neighbours, vertical neighbours, and diagonal neighbours.
So horizontal edges on each row are 11 i.e. 11*12 = 132 horizontal edges. Similarly we have 132 vertical edges.
To count diagonal edges, think of 1*1 square boxes in which diagonals meet each other. There are 11*11 such square boxes, and each box
contains 2 diagonals, so total diagonals = 242.
GATE2014-1_52 top
An ordered n −tuple ( d1 , d2 , . . . . , dn ) with d1 ≥ d2 ≥. . . ≥ dn is called graphic if there exists a simple undirected graph with n vertices having degrees
d1 , d2 , . . . , dn respectively. Which one of the following 6-tuples is NOT graphic?
(A) (1, 1, 1, 1, 1, 1)
(B) (2, 2, 2, 2, 2, 2)
(C) (3, 3, 3, 1, 0, 0)
(D) (3, 2, 1, 1, 1, 0)
The idea is simple : Remove a vertex, which results into decrease of degree by 1 of each vertex which was connected to it. Keep removing
like this, and if we get any negative degree, the degree sequence was not possible.
We need not check (A) and (B) as they are clearly graphs : (A) is 3 disconnected edges, (B) is 2 disconnected triangles.
For (C), we remove first vertex of degree 3, and thus decrease degree by 1 of next 3 vertices, so we get (2,2,0,0,0), then we remove vertex of
degree 2, and decrease degree of next 2 vertices to get (1,-1,0,0). Since we get negative degree, original degree sequence is impossible.
For (D) : (3,2,1,1,1,0) -> (1,0,0,1,0). Now since this list is not sorted (which is required to apply further steps of algorithm), we sort it to get
(1,1,0,0,0). Then we continue our algorithm on this list to get (0,0,0,0), which is valid (4 isolated vertices).
So (C) is answer.
-- Happy Mittal
GATE2014-2_51 top
GATE2014-3_3 top
Let G be a group with 15 elements. Let L be a subgroup of G . It is known that L ≠ G and that the
Lagranges theorem : For any finite group G, the order (number of elements) of every subgroup L of G divides the order of G.
G has 15 elements.
Factors of 15 are 1,3,5, and 15.
Since given the size of L is atleast 4(1 and 3 eliminated) and not equal to G(15 eliminated) , the only size left is 5.
Size of L is 5.
-- Srinath Sri
GATE2014-3_51 top
If G is the forest with n vertices and k connected components, how many edges does G have?
(A) ⌊n/k⌋
(B) ⌈n/k⌉
(C) n − k
(D) n − k +1
A forest is an acyclic graph(with no cycle) , i.e all these components are a tree. With k components there are k roots. And whenever a new node is
added to a tree only a singe edge is introduced.
With k roots , remaining nodes are (n-k) each of which introduces an edge. Hence there are (n-k)*1=(n-k) edges.
-- Srinath Sri
GATE1994_2.5 top
in a complete graph which is (n-1) regular (where n is the no of vertices) has edges n(n-1)/2
n vertices are adjacent to n-1 vertices and an edge contributes two degree so dividing by 2.
GATE1995_1.25 top
The minimum number of edges in a connected cyclic graph on n vertices is:
(a) n − 1
(b) n
(c) n + 1
(d) None of the above
B.
For making a cyclic graph, the minimum number of edges have to be equal to the number of vertices.
-- Gate Keeda
GATE1995_24 top
Prove that in finite graph, the number of vertices of odd degree is always even.
sum of degree of all the verices with even degree + sum of degree of all the verices with odd degree = 2* number of egdes
even number + sum of degree of all the verices with odd degree = even number
GATE2008-IT_27 top
G is a simple undirected graph. Some vertices of G are of odd degree. Add a node v to G and make it adjacent to each odd degree vertex of G.
The resultant graph is sure to be
1) regular
2) complete
3) Hamiltonian
4) Euler
In any simple undirected graph, total degree of all vertices is even (since each edge contributes 2 degrees). So number of vertices having odd
degrees must be even, otherwise their sum would have been odd, making total degree also odd.
Now Single vertex v is connected to all these even number of vertices (which have odd degrees). So degree of v is also even. Moreover, now
degree of all vertices which are connected to v is increased by 1, hence vertices which had odd degree earlier now have even degree.
So now, all vertices in graph have even degree, which is necessary and sufficient condition for euler graph. So 4) is correct.
-- Happy Mittal
GATE2004-IT_37 top
What is the number of vertices in an undirected connected graph with 27 edges, 6 vertices of degree 2, 3 vertices of degree 4 and remaining of
degree 3?
A) 10
B) 11
C) 18
D) 19
x=10.
Number of vertices = 6 + 3 +x = 19
The correct answer is (D).
-- suraj
GATE2005-IT_56 top
Let G be a directed graph whose vertex set is the set of numbers from 1 to 100. There is an edge from a vertex i to a vertex j iff either j = i + 1
or j = 3i. The minimum number of edges in a path in G from vertex 1 to vertex 100 is
A) 4
B) 7
C) 23
D) 99
The trick to solve this question is tothink in reverse way. Instead of finding a path from 1 to 100, try to find a path from 100 to 1.
The edge sequence with minimum number of edges is 1 - 3 - 9 - 10 - 11 - 33 - 99 - 100 which consists of 7 edges.
The answer is option 2.
-- Shridhar
In a simple undirected graph with n vertices what is maximum no of edges that you can have keeping the graph disconnected?
A) nC 2 -1
B) nC 2
C) n-1C 2
D n-1C2 -1
Since we have to find a disconnected graph with maximum number of edges with n vertices. Therefore our disconnected graph will have only
two partions because as number of partition increases number of edges will decrease.
Now assume that First partition has x vertices and second partition has (n-x) vertices.
-- suraj
Number of distinct graphs top
Number of distinct graphs with p vertices and q edges ( p not equal to q) is always equal to
a) p
b) q
c)min(p,q)
d)max (p,q)
e) none of this
I think, None of this should be answer for this question. total no of distinct graphs will be
p(p-1)/2 C q
-- Manu Thakur
GATE2015-2_50 top
In a connected graph, a bridge is an edge whose removal disconnects the graph. Which one of the following statements is true?
Ans B
In a cycle if we remove an edge, it will still be connected. So, bridge cannot be part of a cycle.
-- Vikrant Singh
GATE2015-1_54 top
Let G be a connected planar graph with 10 vertices. If the number of edges on each face is three, then the number of edges in G
is_______________.
n-e+f=2
f/2 = 8
f = 16
e = 3f/2 = 24
http://www.personal.kent.edu/~rmuhamma/GraphTheory/MyGraphTheory/planarity.htm
-- Arjun Suresh
a)2
b)3
c)4
d) 5
obviously in complete graph der is an edge which connect every pair of vertices..
Let A be a 4 × 4 matrix with eigen values -5,-2,1,4. Which of the following is an eigen value of the matrix
A) -5 B) -7 C) 2 D) 1
Ans is (C) 2
|A − λI| = 0
This is a 2 × 2 block matrix where the first and last and the second and third elements are the same. So, applying the formula for
determinant of a block matrix as given here (second last case) https://en.wikipedia.org/wiki/Determinant#Block_matrices we get
|A − λ I − I| × |A − λI + I| = 0
⟹ |A − (λ + 1)I| × |A − (λ − 1)I| = 0
Each of the eigen value of A is the solution of the equation |A − αI| = 0 (α being the eigen value of A). So, we can equate λ + 1 and λ − 1
to any of the eigen value of A, and that will get our value ofλ. If we take α = 1 , we get λ = 2 , and that is one of the choice. For no other
choice, this equation holds. So, (c) 2 is the answer.
-- Keith Kr
GATE2008_28 top
How many of the following matrices have an eigenvalue 1?
[1 0 ][ 0 1 ][ 1 −1 ] and [ −1 0 ]
0 0 0 0 1 1 1 −1
∣1−λ 0 ∣∣ = 0
∣
∣ 0 −λ ∣
(1 − λ)(−λ) = 0
λ = 0, 1
Similarly, (2) λ = 0, 0
(3) λ ≠ 1
(4) λ = 0, −2
A. D -1C -1A-1
B. CDA
C. ADC
D. Does not necessarily exist
Given
ABCD = I
=> BC = A-1 D -1
=> B = A-1 D -1 C -1
B -1 = CDA
-- Madhur Rawat
GATE1998_1.2 top
4x + 8y = 20
4x + 8y = 12
Clearly, there can not be any pair of (x,y), which satisfies both equations.
-- Happy Mittal
GATE1998_2.1 top
Ans D
-- Keith Kr
GATE1998_2.2 top
Answer is B
R2->R2 - R1
R3 -> R3 - R2
in matrix operations, you cannot multiply rows or columns. That will not yield the same matrix. So abc is not correct
-- Dhananjay
GATE2014-2_47 top
Let Eigen value be X. Now, equating the determinant of the following to 0 gives us the values for X. To find X in the following matrix, we can
equate the determinant to 0. For finding the determinant we can use row and column additions and make the matrix a triangular one. Then
determinant will just be the product of the diagonals which should equate to 0.
1-X 0 0 0 1
0 1-X 1 1 0
0 1 1-X 1 0
0 1 1 1-X 0
1 0 0 0 1-X
R1 ← R1 + R5, R4 ← R4 - R3
2-X 0 0 0 2-X
0 1-X 1 1 0
0 1 1-X 1 0
0 0 X -X 0
1 0 0 0 1-X
Taking X out from R4, 2-X from R1, (so, X = 2 is one eigen value)
1 0 0 0 1
0 1-X 1 1 0
0 1 1-X 1 0
0 0 1 -1 0
1 0 0 0 1-X
R2 ← R2 - R3, R5 ← R5 - R1
1 0 0 0 1
0 -X X 0 0
0 1 1-X 1 0
0 0 1 -1 0
0 0 0 0 -X
C3 ← C3 + C4
1 0 0 0 1
0 -X X 0 0
0 1 2-X 1 0
0 0 0 -1 0
0 0 0 0 -X
1 0 0 0 1
0 -1 1 0 0
0 1 2-X 1 0
0 0 0 -1 0
0 0 0 0 -X
R3 ← R3 + R2
1 0 0 0 1
0 -1 1 0 0
0 0 3-X 1 0
0 0 0 -1 0
0 0 0 0 -X
Now, we got a triangular matrix and determinant of a triangular matrix is product of the diagonal.
So (3-X) (-X) = 0 => X = 3 or X = 0. So, X = 3 is another eigen value and product of non-zero eigen values = 2 * 3 = 6.
https://people.richland.edu/james/lecture/m116/matrices/determinant.html
-- Arjun Suresh
GATE2014-3_5 top
If V 1 and V 2 are 4 -dimensional subspaces of a 6 -dimensional vector space V , then the smallest possible dimension of V 1 ∩ V 2 is _____.
GATE1995_1.24 top
Ans is A.
we can eliminate all other rows using row 1. in the last only 1 row will be left.
GATE2008-IT_29 top
If M is a square matrix with a zero determinant, which of the following assertion (s) is (are) correct?
(S1) Each row of M can be represented as a linear combination of the other rows
(S2) Each column of M can be represented as a linear combination of the other columns
(S3) MX = 0 has a nontrivial solution
(S4) M has an inverse
1) S3 and S2
2) S1 and S4
3) S1 and S3
4) S1, S2 and S3
Since M has zero determinant, its rank is not full i.e. if M is of size 3*3, then its rank is not 3. So there is a linear combination of rows which
evaluates to 0 i.e.
Now MX = 0 always has one solution : X = 0 (which is called trivial solution). Now if |M| = 0, then MX = 0 has non-trivial solutions also.
-- Happy Mittal
GATE2004-IT_6 top
⎡1 2 3 ⎤⎡ x ⎤ ⎡ 6 ⎤
y = 8
⎣2 3 ⎦⎣ z ⎦ ⎣ 12 ⎦
1 3 4
2
A) x = 6, y = 3, z = 2
B) x = 12, y = 3, z = - 4
C) x = 6, y = 6, z = - 4
D) x = 12, y = - 3, z = 0
Correct answer is (C). It can be easily verified by keeping the value of variables in the equations.
-- suraj
GATE2004-IT_36 top
If matrix X = [ a 1 ] and 2 − X + I = O (I is the identity matrix and O is the zero matrix), then the inverse ofX is
X
− a2 + a − 1 1−a
A) [ 1 −2a −1 ]
a a
B) [ 2 1 − a −1 ]
a −a+1 a
C) [ −a 1 ]
− a2 + a − 1 1−a
[a −a+1 a ]
2
D)
1 1−a
It's a very simple question, We need to calculate the inverse of a 2x2 matrix,
adjoint of A = [cofactors of A]^T, but for 2x2 matrix we have direct forumla:
A= a b
c d is a 2x2 matrix then
Adjoint of A = d -b
-c a
|A| = ad-bc
so answer is (B)
-- Manu Thakur
GATE2015-2_5 top
For finding the Eigen Values of a Matrix we need to build the Characteristic equation which is of the form,
is a constant
We'll have a Linear equation after solving . Which will give us 2 roots for .
(4- ) (1- ) - 10 = 0
4 - 5 + 2 = 10
2 -5 - 6 = 0
( - 6) ( + 1) = 0
So = -1 , 6.
GATE2015-2_27 top
⎡ 3 4 45 ⎤
⎣ 13 195 ⎦
Perform the following operations on the matrix 7 9 105
2
i. Add the third row to the second row
ii. Subtract the third column from the first column.
GATE2015-3_15 top
⎡1 −1 2⎤
⎣1 1⎦
In the given matrix 0 1 0 , one of the eigenvalues is 1. The eigenvectors corresponding to the eigenvalue 1 are
2
A. {a(4, 2, 1) ∣ a ≠ 0, a ∈ R}
B. {a(−4, 2, 1) ∣ a ≠ 0, a ∈ R}
C. {a(√2 , 0, 1) ∣ a ≠ 0, a ∈ R}
D. {a(−√2 , 0, 1) ∣ a ≠ 0, a ∈ R}
⎡1−1 −1 2 ⎤ ⎡0 −1 2⎤ ⎡ x⎤
= 0 0 ∗ y
⎣ 1 1−1⎦ ⎣1 0⎦ ⎣ z⎦
0 1−1 0 0
2 2
−y + 2z = 0
x + 2y = 0
now consider each of the triplets as the value of x, y, z and put in these equations the one which satisfies is the answer.
why so because an eigen vector represents a vector which passes through all the points which can solve these equations.
-- Tamojit Chatterjee
GATE2015-3_33 top
px + qy + rz = 0
qx + ry + pz = 0
rx + py + qz = 0,
A. p−q+r = 0 or p = q = −r
B. p+q−r = 0 or p = −q = r
C. p+q+r = 0 or p =q=r
D. p−q+r = 0 or p = −q = −r
for non-trivial solution
|A| = 0
⎡p q r⎤
where |A| = p = p ∗ (rq − p 2 ) − q ∗ (q 2 − pr) + r ∗ (qp − r2 )
⎣r q⎦
q r
p
now if you check the options the only options where each individual condition can make|A| = 0 zero is C
-- Tamojit Chatterjee
Given equation is
9 50 = 3 98 (a2 + b 2 )
( a2 + b 2 ) = 9
-- suraj
Numerical Methods top
GATE2012_28 top
The bisection method is applied to compute a zero of the function f(x) = x4 – x3 – x2 – 4 in the interval [1,9]. The method converges to a
solution after ––––– iterations.
(A) 1
(B) 3
(C) 5
(D) 7
In bisection method, in each iteration, we pick the mid point of the interval as approxiamation of the root, and see where are we, i.e. should
we choose left sub-interval, or right-subinterval, and we continue until we find the root, or we reach some error tolerance.
So in first iteration, our guess for root is mid point of [1,9] i.e. 5. Now f(5) > 0, so we choose left sub-interval [1,5] (as any value in right sub-
interval [5,9] would give more positive value of ).
In second iteration, we choose mid point of [1,5] i.e. 3, but again f(3) > 0, so we again choose left sub-interval [1,3].
-- Happy Mittal
GATE2014-2_46 top
In the Newton-Raphson method, an initial guess of x0 = 2 is made and the sequence x0 , x1 , x2 … is obtained for the function
0.75x3 − 2x2 − 2x + 4 = 0
I. x3 = 0
II. The method converges to a solution in a finite number of iterations.
(A) Only I
(B) Only II
f( xn )
xn+1 = xn − for Newton-Raphson method (See the link below)
f ′ ( xn )
⟹ f(2) = −2
f ′ (x) = 2.25x2 − 4x − 2
⟹ f ′ (2) = 9 − 8 − 2 = −1
So, x1 = 2 − −2
−1
= 2−2= 0
f( x1 ) 4
x2 = x1 − = 0− −2
=2
f ′ ( x1 )
https://www.math.ubc.ca/~anstee/math104/104newtonmethod.pdf
-- Arjun Suresh
GATE2015-3_50 top
The velocity v (in kilometer/minute) of a motorbike which starts form rest, is given at fixed intervals of timet (in minutes) as follows:
t 2 4 6 8 10 12 14 16 18 20
v 10 18 25 29 32 20 11 5 2 0
The approximate distance (in kilometers) rounded to two places of decimals covered in 20 minutes using Simpson's1/3 rd rule is ________.
The total distance covered is given by the area under the speed curve and can be calculated by integrating the speed curve equation in the
given range. In the question, exact speed function is not given, but the speed at different time instants is given.
Question is asking the distance covered in 20 minutes. According to the question, the motion starts at t = 0 and ends at t = 20. So the speed
function has to be integrated in the range t=0 to t=20. Therefore an additional point (t=0) has to be considered while integrating. After adding
t=0, number of points will be 11 and number of intervals will be 10. And the answer will be 309.33.
Distance
(b−a)
S= 3n
[f(0) + 4(f(2) + f(6) + f(10) + f(14) + f(18))
+ 2(f(4) + f(8) + f(12) + f(16) + f(20))]
2
= 3
[0 + 4(10 + 25 + 32 + 11 + 2)
+ 2(18 + 29 + 20 + 5)]
= 309.33
Ref: http://www.saylor.org/site/wp-content/uploads/2011/11/ME205-7.2-TEXT2.pdf
-- ashishacm
Calculus top
GATE2007_1 top
ans is A. f(x)=|x| here for all values of x, f(x) exists. therefore it is continuous for all real values of x.
At x=0, f(x) is not differentiable. Because if we take the left hand limit here, it is negative while the right hand limit is positive.
Ref: http://math.stackexchange.com/questions/991475/why-is-the-absolute-value-function-not-differentiable-at-x-0
-- jayendra
GATE1998_1.4 top
(b) It is continuous but not differentiable at x=0 as left hand limit will be negative while the right hand limit will be positive but for differentiation,
both must be same.
-- Gate_15_isHere
GATE1998_8 top
(a) Find the points of local maxima and minima, if any, of the following function defined in 0 ≤ x ≤ 6 .
x3 − 6x2 + 9x + 15
(b) Integrate
π
∫ x cos xdx
−π
(a)
so
Now
f''(1) < 0, so x = 1 is point of local maxima, f''(3) > 0, so x = 3 is point of local minima.
Also the end points 0 and 6 are critical points. 0 is point of local minima, because it is to the left of x = 1 (which is point of maxima). Similarly x
= 6 is point of local maxima.
(b) Since xcosx is an odd function, by the properties of definite integration, answer is 0.
-- Happy Mittal
GATE2014-1_47 top
A function f(x) is continuous in the interval [0, 2] . It is known that f(0) = f(2) = −1 and f(1) = 1 . Which one of the following statements must be true?
(A) There exists a y in the interval (0, 1) such that f(y) = f(y + 1)
(D) There exists a y in the interval (0, 1) such that f(y) = −f(2 − y)
since g is continuous and goes from negative to positive value in [0,1]. therefore at some point g would be 0 in (0,1).
-- suraj
GATE1997_4.1 top
Answer: B
f'(x) = 4x - 2 = 0
So at x = 2, f(x) is maximum.
-- Jon Snow
GATE1995_1.21 top
ans is B.
after this x is increasing and cosx is decreasing. so we can say exactly 1 solution.
-- jayendra
GATE1995_25 top
f(x) = 3-4x+2x2
f''(x) = 4
2=1
f''(1) = 4>0, therefore at x=1 we will get mimimum value, which is : 3 - 4(1) + 2(1)
ans for B:
-- jayendra
GATE1996_3 top
⎧ x2 for x ≤ 1
f(x) = ⎨ ax2 + bx + c
⎩ for 1 < x ≤ 2
x+d for x > 2
Find the values for the constants a, b , c and d so that f is continuous and differentiable everywhere on the real line.
f is differentiable at 1 if
f is differentiable at 2 if
a = -0.5, b = 3
=> 1 = a + b + c
=> c = -1.5
=> d = 0.5
-- Happy Mittal
GATE2015-1_4 top
1
lim x→∞ x x is
A. ∞
B. 0
C. 1
D. Not defined
Since the exponential function is continuous, we may factor it out of the limit.
Evaluate .
Answer:
-- Shyam Singh
GATE2015-1_44 top
2/π cos(1/x)
∫ 1/π dx =__________________________.
x2
The antiderivative of is :
Answer:
-- Shyam Singh
GATE2015-3_9 top
A. 0
B. 1
2
C. 1
D. ∞
Since the exponential function is continuous, we may factor it out of the limit.
Evaluate .
Answer:
-- Shyam Singh
GATE2015-3_45 top
A. 1
[ a(ln 2 − 25) + 47b ]
a 2 −b 2 2
B. 1
[ a(2 ln 2 − 25) − 47b ]
a 2 −b 2 2
C. 1 [ a(2 ln 2 − 25) + 47b ]
a 2 −b 2 2
D. 1
[ a(ln 2 − 25) − 47b ]
a 2 −b 2 2
af(x) + bf( 1x ) = 1
x
− 25 --- (1)
af( 1x ) + bf(x) = x − 25
Eliminate ∫ 12 f( 1x ) between (2) and (3) by multiplying (2) by a and (3) by b and subtracting
∴ ∫ 12 f(x)dx = 1
[a(log 2 − 25) + 47b
2
]
(a 2 −b 2 )
-- Shyam Singh
Programming top
GATE2013_42 top
What is the return value of f(p,p), if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas
the second parameter is passed by value.
In GATE 2013 marks were given to all as the same code in C/C++ produces undefined behavior. This is because * is not a sequence point in
C/C++. The correct code must replace
return f(x,c) * x;
with
res = f(x,c);
return res * x;
In this code, there will be 4 recursive calls with parameters (6,4), (7,3), (8,2) and (9,1). The last call returns 1. But due to pass by reference, x
in all the previous functions is now 9. Hence, the value returned by f(p,p) will be 9 * 9 * 9 * 9 * 1 = 6561.
-- Arjun Suresh
I have been struggling with pointers in multi-dimensional arrays. Please help me with this
code :- top
Here, b is a 2D array and it contains 3*4 = 12 elements. Suppose address of b starts from 1000. Now the elements will be stored as:
1000-3: 1
1004-7: 2
1008-11: 3
1012-15: 4
1016-19: 5
....
1045-48: 12
So, *p will have 1. (assuming a 32 bit architecture, on 64 bit architecture *p will be 8 bytes and the array element being int is only 4 bytes)
Now, *p+1, is pointer arithmetic. It will add 1 *sizeof(int) to *p. So, *p+1 will give 1 + 4 = 5. (This 5 is not the element 5 in the array)
Similarly, *p+2, will add 2*sizeof(int) = 2*4 = 8 to *p. So, *p+2 will give 1+8 = 9.
These are all valid only on a 32 bit compiler. On a 64 bit compiler, if we use
(long)*p
This output is entirely implementation dependent as it depends on the sizeof (int) and sizeof pointer and also depends on the endianness of the machine(if sizeof
(int) is different from sizeof pointer) .
For more details about pointer arithmetic you can see here:
http://gatecse.in/wiki/Chapter_3:_Pointers#Pointer_Arithmetic
-- Arjun Suresh
GATE1994_1.20 top
In which of the following cases is it possible to obtain different results for call-by-reference and call-by-name parameter passing methods?
{
....
a[] = {0,1,2,3,4};
i = 0;
fun(a[i]);
print a[0];
}
fun(int x)
{
int i = 1;
x = 8;
}
Output:
call-by-reference: 8
call-by-name: 0
In Call-by-name, each occurence of the formal parameter is replaced by the actual argument text. So, the function fun will be executed like:
{
int i = 1;
a[i] = 8; //a[1] is changed to 8 and not a[0]
}
-- Arjun Suresh
GATE2008_18 top
Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?
A. x = 3, y = 4, z =2
B. x = 6, y = 5, z =3
C. x = 6, y = 3, z =5
D. x = 5, y = 4, z =5
a=(3>4)? No
therefore don't evaluate the first part and check second part ((y>z)?y:z)
(4>2)? Yes
a= value of y =4
-- Keith Kr
GATE2008_61 top
Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is
terminated by a new line character.
void reverse(void) {
int c;
if(?1) reverse();
?2
}
main() {
printf("Enter text"); ptintf("\n");
reverse(); printf("\n");
}
A. ?1 is (getchar() != ’\n’)
?2 is getchar(c);
?2 is getchar(c);
C. ?1 is (c != ’\n’)
?2 is putchar(c);
?2 is putchar(c);
Here we are using the '=' operator which has less priority than '!=' operator. So (c=getchar()) has to be in brackets and after reversing the
string we use function putchar(c) for printing the character So option (d) is the right answer
-- Kalpna Bhargav
GATE1991_09,a,b top
(a) Consider the following pseudo-code (all data items are of type integer):
procedure P(a, b, c);
a := 2;
c := a + b;
end {P}
begin
x := 1;
y := 5;
z := 100;
P(x, x*y, z);
Write ('x = ', x, 'z = ', z);
end
i. value
ii. reference
iii. name
are used
procedure P;
a := 5;
b := 10;
end {P};
procedure Q;
var a, b : integer;
P;
end {Q};
begin
a := 1;
b := 2;
Q;
Write ('a = ', a, 'b = ', b);
end
(a)
1. Pass by value: Function cannot modify a variable in the calling function. So,
x = 1, z = 100
2. Pass by reference: An alias of the variable (a different name but having same memory location) is used to pass the variable to a function.
So, whatever change occurs for the variable in the called function is reflected in the calling function.
x = 2, z = 7 (2 + 5)
3. Pass by name: The expression used to call a function is copy pasted for each formal parameter. So, the body of P becomes,
x := 2;
z := x + x*y;
x = 2, z = 12
(b) In static scoping, if a variable is not found in the local scope, its looked upon in global scope. In dynamic scoping, if a variable is not found
in local scope, its looked upon in the function which called the current executing one.
1. a = 5, b = 10
2. a = 1, b = 2
(The modification in Q, happens to the variables in P but in main we use the global variables)
-- Arjun Suresh
GATE2000_1.11 top
struct node {
int i:
float j;
};
struct node *s[10];
define s to be
(a) is the answer. [] has greater precedence than * in C. So, s becomes an array of pointers.
-- gatecse
GATE2001_2.18 top
[P1]
int *g(void)
{
int x = 10;
return (&x);
}
[P2]
int *g(void)
{
int *px;
*px = 10;
return px;
}
[P3]
int *g(void)
{
int *px;
px = (int*) malloc (sizeof(int));
*px = 10;
return px;
}
Which of the above three functions are likely to cause problems with pointers?
A. Only P3
B. Only P1 and P3
C. Only P1 and P2
D. P1, P2 and P3
[P1] may cause an error because function is returning the address of locally declared variable.
[P2] will cause a problem because px is an int pointer that is not assigned with any address and we are doing dereferencing.
[P3] will work because memory in bytes of size of int will be reserved and its address will be stored in px that can be further use, once function
execution completes, this m/m will still exist in Heap until we free it using free() function.
hence answer is C
-- Manu Thakur
GATE2002_2.8 top
char a[100][100];
Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a [40][50] is
A. 4040
B. 4050
C. 5040
D. 5050
answer is (b)
loc(a[i][j]) = BA + [(i-lb1)*NC+(j-lb2))*c
= 0+[4000+50]*1 = 4050
-- Kalpna Bhargav
GATE2003_2 top
I. A[2]
II. A[2][3]
III. B[1]
IV. B[2][3]
which will not give compile-time errors if used as left hand sides of assignment statements in a C program?
A[2] =
can take a pointer
A[2][3] =
can take an int
B[1] =
B[1] is the base address of array and it cannot be changed as array in C is a constant pointer.
B[2][3] =
can take an integer
GATE2004_1 top
The goal of structured programming is to
Answer is (c) The goal of structured programming is to able to infer the flow of control from the program text . It means user can execute the
code according to his requirement. C 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.
-- Kalpna Bhargav
GATE2004_31 top
int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}
A. 5
B. 6
C. 7
D. 8
answer is 7.as,
f(1):n=2,i=2
f(2):n=4,i=3
f(4):n=7,i=4
f(7):print(n)===>>> 7<ans>
-- sumit kumar singh dixit
GATE1998_2.13 top
function f(x) calling only for one time and f(x)*f(x) replacing value of f(x) = 6*6 ;
#include <iostream>
using namespace std;
int x , result;
int f (int x)
{
x=x+1;
return x;
}
int main ()
{
x=5;
result = f(x)*f(x);
cout << "The result is " << result;
}
-- csegate2
GATE1998_2.15 top
Faster access to non-local variables is achieved using an array of pointers to activation records called a
A. stack
B. heap
C. display
D. activation tree
it is C
properties of displays
1> Use a pointer array to store the activation records along the static chain.
2> Fast access for non-local but may be complicated to maintain.
3> Calling a subprogram in the same level – simply replace and restore.
4> Calling a subprogram in the higher level – add an entry and may need to save the old pointers.
5> Calling a subprogram in the lower level – shrink the pointer and restore it when the subprogram returns.
http://users.dickinson.edu/~wahlst/356/ch10.pdf
GATE2012_36 top
Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.
Program main;
Var ...
Procedure A1;
Var ...
Call A2;
End A1
Procedure A2;
Var ...
Procedure A21;
Var ...
Call A1;
End A21
Call A21;
End A2
Call A1;
End main.
Consider the calling chain: Main -> A1 -> A2 -> A21 -> A1
The correct set of activation records along with their access links is given by
Since, Activation records are created at procedure entry time and destroyed at procedure exit time.
therefore here Calling sequence is given as ,
Main->A1->A2->A3->A1
now A1,A2 are defined under Main...So A1,A2 Access link are pointed to main
A21 is Defined under A2 hence its Access link will point to A2
-- Kalpish Singhal
GATE2006_56 top
Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.
subroutine swap(ix,iy)
it = ix
L1 : ix = iy
L2 : iy = it
end
ia = 3
ib = 8
call swap (ia, ib+5)
print *, ia, ib
end
S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell to swap
S2: On execution the code will generate a runtime error on line L1
S3: On execution the code will generate a runtime error on line L2
S4: The program will print 13 and 8
S5: The program will print 13 and -2
(A) S1 and S2
(B) S1 and S4
(C) S3
(D) S1 and S5
S1 and S4 are correct. There won't be any runtime error for the given code using pass by reference.
-- Arjun Suresh
GATE2006_57 top
Consider this C code to swap two integers and these five statements: the code
S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process
S4: implements the swap procedure correctly for some but not all valid inputpointers
(A) S1
(B) S2 and S3
(C) S2 and S4
(D) S2 and S5
s1 is false . s2 is true ,depending on the argument passed it may generate segmentation fault s3 is false bcz implementation is having some
problem ...let x=3 and i want to implement SWAP[x,x] now ans would be 0 but that must be remain x problem is bcz we are not checking
whether both pointer are pointing the same address or different so s4 is true s5 is obviously false so Option(c) is right
-- Kalpna Bhargav
GATE2014-2_11 top
Suppose n and p are unsigned int variables in a C program. We wish to set p to n C 3 . If n is large, which one of the following statements is most likely to set p
correctly?
B)
In c, * and / have the same precedence and are left associative.
In option b)
n*(n-1)/2 gives an integer value.
This integer value multiplied by (n-2) again gives an integer value.
Which when divided by 3 gives an integer value(Sets p correctly).
-- Srinath Sri
GATE2014-3_42 top
Consider the C function given below. Assume that the array listA contains n(> 0) elements, sorted in ascending order.
int ProcessArray(int *listA, int x, int n)
{
int i, j, k;
i = 0;
j = n-1;
do {
k = (i+j)/2;
if (x <= listA[k])
j = k-1;
if (listA[k] <= x)
i = k+1;
}while (i <= j);
if (listA[k] == x)
return(k);
else
return -1;
}
Which one of the following statements about the function P rocessArray is CORRECT?
B)....
-- Siddhartha Datta
GATE2012_48,49 top
int a, b, c = 0;
void prtFun(void);
main()
{
static int a = 1; /* Line 1 */
prtFun();
a += 1;
prtFun();
printf(“ \n %d %d ”, a, b);
}
void prtFun(void)
{
static int a = 2; /* Line 2 */
int b = 1;
a += ++b;
printf(“ \n %d %d ”, a, b);
}
(A)
3 1
4 1
4 2
(B)
4 2
6 1
6 1
(C)
4 2
6 2
2 0
(D)
3 1
5 2
5 2
Q.49 What output will be generated by the given code segment if:
(A)
3 1
4 1
4 2
(B)
4 2
6 1
6 1
(C)
4 2
6 2
2 0
(D)
4 2
4 2
2 0
48.
main
a=1
prtFun()
a=2
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a = a+1 --> 1+1 -->2 (local static a is taken)
prtFun()
a=4 // previous value in the function is retained bcos of static
b=1
a= a + ++b = 4+2 = 6
b=2
printf --> 6 2
back to main
a=2
b = 0 (initial value of global b. in prtFun local b is only updated)
printf --> 2 0
Answer: C
49
main
a=1
prtFun()
a=2
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a = a+1 --> 1+1 -->2
prtFun()
a=1 //previous a is lost
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a=2
b = 0 (initial value of global b. in prtFun local b is only updated)
printf --> 2 0
Anwer: D
-- Sankaranarayanan P.N
GATE2010_11 top
#include<stdio.h>
int main() {
f(&i, &j);
printf("%d %d\n", i,j);
return 0;
}
(A) 2 2
(B) 2 1
(C) 0 1
(D) 0 2
-- Manu Thakur
GATE2010_14 top
-- Sankaranarayanan P.N
GATE2008-IT_13 top
Match the programming paradigms and languages given in the following table.
Paradigms Languages
(I) Imperative (a) Prolog
(II) Object Oriented (b) Lisp
(III) Functional (c) C, Fortran 77, Pascal
(IV) Logic (d) C++, Smalltalk, Java
A is correct. Lisp is a pure functional language and Prolog is a logic language. Other languages are well known.
-- Arjun Suresh
GATE2008-IT_49 top
# include <stdio.h>
int main ()
{
char a [6] = "world";
int i, j;
for (i = 0, j = 5; i < j; a [i++] = a [j--])
printf ("%s\n", a);
}
A) dlrow
B) Null string
C) dlrld
D) worow
char a[6] =
w o r l d \0
a[0] 1 2 3 4 5
a[0] =a[5]
a[0] =`\0`
printf(‘’%s’’, a) , the string starting at address a prints the string starting with `\0` and it indicates the end of string ,so it will print null string.
so option (B)
-- Mitali
GATE2008-IT_50 top
Consider the C program below. What does it print?
# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
int tmp;
tmp = a; a = b; b = tmp;
}
void swap3 (int*a, int*b)
{
int tmp;
tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
int num1 = 5, num2 = 4, tmp;
if (num1 < num2) {swap1 (num1, num2);}
if (num1 < num2) {swap2 (num1 + 1, num2);}
if (num1 > = num2) {swap3 (&num1, &num2);}
printf ("%d, %d", num1, num2);
}
A) 5, 5
B) 5, 4
C) 4, 5
D) 4, 4
Answer: C
Only
-- Jon Snow
GATE2008-IT_51 top
#include <stdio.h>
int main ()
{
int i, j;
int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
for(i = 0; i < 3; i++) {
a[i] = a[i] + 1;
i++;
}
i--;
for (j = 7; j > 4; j--) {
int i = j/2;
a[i] = a[i] - 1;
}
printf ("%d, %d", i, a[i]);
}
A) 2, 3
B) 2, 4
C) 3, 2
D) 3, 3
a[0] 1
a[1] 2
a[2] 3
a[3] 4
a[4] 5
a[5] 6
a[6] 7
a[7] 8
a[0]=a[0]+1 = 1+1=2
i++
i++
a[2]=a[2]+1 = 3+1=4
i++
i++
i-- (i=3)
now another for loop started where in loop integer type variable named i declared
Block Scope: A Block is a set of statements enclosed within left and right braces ({ and } respectively). Blocks may be nested in C
(a block may contain other blocks inside it). A variable declared in a block is accessible in the block and all inner blocks of that
block, but not accessible outside the block.
What if the inner block itself has one variable with the same name?
If an inner block declares a variable with the same name as the variable declared by the outer block, then the visibility of the outer
block variable ends at the point of declaration by inner block
so here inner block int i has the scope in this block only and outer block int i visibility is not allowed in that block
j=7 j>4(true)
int i = 7/2=3
a[3]=a[3]-1=4-1=3
j=6 j>4(true)
int i = 6/2=3
a[3]=a[3]-1=3-1=2
j=5 j>4(true)
int i = 5/2=2
a[2]=a[2]-1=4-1=3
j=4 j>4(false)
now when the for loop ends its variable named i scope is also end and the outer block variable now visible
GATE2008-IT_52 top
# include <stdio.h>
int main ()
{
int i, j;
char a [2] [3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
char b [3] [2];
char *p = *b;
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
*(p + 2*j + i) = a [i] [j];
}
}
}
What should be the contents of the array b at the end of the program?
a b
A) c d
e f
a d
B) b e
c f
a c
C) e b
d f
a e
D) d c
b f
then an integer type 2-d array a[2][3] is declared and initialized and 2-d array b[3][2] is created but not initialized. i.e
now the char type pointer is declared and the base address of array b is put in it. so p=3000
j++
j++
j++
i++
j++
j++
j++
i++
b[0][0] 3000 a
b[0][1] 3001 d
b[1][0] 3002 b
b[1][1] 3003 e
b[2][0] 3004 c
b[2][1] 3005 f
Note:
*(p + 2*j + i)
p + sizeofinner dimension * j + i, hence is same as p[j][i]. Hence with this statement we can identify that the code is transposing the matrix a
and storing in b using pointer p.
-- Kalpna Bhargav
GATE2007-IT_32 top
#include <stdio.h>
#define EOF -1
void push (int); /* push the argument on the stack */
int pop (void); /* pop the top of the stack */
void flagError ();
int main ()
{ int c, m, n, r;
while ((c = getchar ()) != EOF)
{ if (isdigit (c) )
push (c);
else if ((c == '+') || (c == '*'))
{ m = pop ();
n = pop ();
r = (c == '+') ? n + m : n*m;
push (r);
}
else if (c != ' ')
flagError ();
}
printf("% c", pop ());
}
What is the output of the program for the following input ?
52*332+*+
A) 15
B) 25
C) 30
D) 150
B) 25
let first part
5 ----push
2------push
push------5*2=10. (pops 5 and 2)
push 3
push 3
push 2
push 3+2 = 5 (pops 2 and 3)
push 5*3 = 15 (pops (5 and 3)
push 15 + 10 = 25 (pops (15 and 10)
-- Arpit Dhuriya
GATE2007-IT_33 top
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods
of parameter passing.
int i ;
program main ()
{
int j = 60;
i = 50;
call f (i, j);
print i, j;
}
procedure f (x, y)
{
i = 100;
x = 10;
y=y+i;
}
Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
CALL BY VALUE :- i as global variable declared. Then in main() a local variable j as integer declared i.e j=60 And global variable i initialized to
50 by i=50. Now procedure f called and values of i and j are passed to it. i.e., in f(i,j) -> f(x, y) content of memory location of i (here 50) is
copied to memory location of x (which is different from i) and content of memory location of j (here, 60) is copied to memory location of y.
Then in f(x,y) i=100 changes the global i to 100, X= 10 changes the local X from 50 to 10 and Y= y+ i means y=60+100=160. Now when
return back to main, i and j will be 100 and 60 respectively.
CALL BY REFERENCE:- Now procedure f called and passed reference of i and j to it. i.e., in f(i,j) -> f(x, y) x and y are new names (aliases)
pointing to the same memory location of i and j respectively. So, i = 100 changes the global i to 100 and x= 10 means x as well as global i =10
(as the i being passed is the global variable and x and i share the same address).
y= y+ i means y = 60+10=70 and this changes the value of j also to 70 as j and y have the same address. Now when return back to main, i
and j will be 10 and 70 respectively.
-- Kalpna Bhargav
GATE2007-IT_34 top
Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping.
int i ;
program main ()
{
i = 10;
call f();
}
procedure f()
{
int i = 20;
call g ();
}
procedure g ()
{
print i;
}
Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then, x and y are
A) x = 10, y = 10
B) x = 20, y = 10
C) x = 10, y = 20
D) x = 20, y = 20
In static scoping, the scope of an identifier is determined by its location in the code, and since that doesn't change, the scope doesn't either. In dynamic scoping,
the scope is determined by the sequence of calls that has led to the use of an identifier, and since that can be different each time that use is reached, is dynamic.
so here.
as,
GATE2007-IT_35 top
Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the
following statements:
The right choices of wl, w2, w3 and w4 (in that order) are
Static scoping can do early binding (during compile time). Early binding increases efficiency.
Dynamic scoping requires late binding (during execution time). Late binding decreases efficiency as this binding needs to be done at runtime.
(but it increases flexibility)
a = 0, b = 3
A)
a = 0, b = 3
a = 3, b = 0
B)
a = 12, b = 9
a = 3, b = 6
C)
a = 3, b = 6
a = 6, b = 3
D)
a = 15, b = 12
First of all the swap function just swaps the pointers inside the function and has no effect on the variables being passed.
Inside printab, a and b are added odd integers from 1-5, i.e., 1+3+5 = 9. So, in first call to printab, a = -3 + 9 = 6 and b = -6 + 9 = 3.
Static variables have one memory throughout program run (initialized during program start) and they keep their values across function calls.
So, during second call to printab, a = 6 + 9 = 15, b = 3 + 9 = 12.
-- Arjun Suresh
GATE2006-IT_51 top
Which one of the choices given below would be printed when the following program is executed?
#include <stdio.h>
int a1[] = {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x[] = {a1, a2, a3};
void print(int *a[])
{
printf("%d,", a[0][2]);
printf("%d,", *a[2]);
printf("%d,", *++a[0]);
printf("%d,", *(++a)[0]);
printf("%d\n", a[-1][+1]);
}
main()
{
print(x);
}
A) 8, -12, 7, 23, 8
B) 8, 8, 7, 23, 7
C) -12, -12, 27, -31, 23
D) -12, -12, 27, -31, 56
a = {a1, a2, a3};
printf("%d,", a[0][2]);
printf("%d,", *a[2]);
a[2] is a3. So, this will print *a3 = a3[0] = -12 ([] has greater precedence than *)
printf("%d,", *++a[0]);
a[0] which is a1 is incremented. a1 is a pointer to int (base address of an integer array) and so increment means adding sizeof(int) and hence
a1 now points to the second element in the array. So, *++a[0] prints second element of a1 which is 7 and now a1 starts from 7.
printf("%d,", *(++a)[0]);
++a will increment a, which being an array of pointers (to int) will add sizeof (pointer) to a. So, a now contains {a2, a3} and a[0] will be a2 and
*a2 will be the first element in a2 which is 23
printf("%d\n", a[-1][+1]);
a[-1] will subtract a size of pointer from the base address of a. Normally this results in invalid memory access, but since we have incremented
a previously, a[-1] is valid and will point to a1. So, a[-1][+1] will be a1[1] which has the value 8.
(a1 was incremented in 3 rd printf and hence starts from 7 and not 6. +1 is same as 1, just given to create confusion)
-- Arjun Suresh
GATE2004-IT_60 top
Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is
terminated by a new line character.
#include <stdio.h>
void wrt_it (void);
int main (void)
{
printf("Enter Text");
printf ("\n");
wrt_ it();
printf ("\n");
return 0;
}
void wrt_it (void)
{
int c;
if (?1)
wrt_it();
?2
}
?1 is getchar() ! = '\n'
A)
?2 is getchar(c);
?1 is (c = getchar()); ! = '\n'
B)
?2 is getchar(c);
?1 is c! = '\n'
C)
?2 is putchar(c);
?1 is (c = getchar()) ! = '\n'
D)
?2 is putchar(c);
it should be option D
?1 is (c = getchar()) ! = '\n'
?2 is putchar(c);
#include <stdio.h>
typedef struct {
char *a;
char *b;
} t;
void f1 (t s);
void f2 (t *p);
main()
{
static t s = {"A", "B"};
printf ("%s %s\n", s.a, s.b);
f1(s);
printf ("%s %s\n", s.a, s.b);
f2(&s);
}
void f1 (t s)
{
s.a = "U";
s.b = "V";
printf ("%s %s\n", s.a, s.b);
return;
}
void f2(t *p)
{
p -> a = "V";
p -> b = "W";
printf("%s %s\n", p -> a, p -> b);
return;
}
AB
UV
A)
VW
VW
AB
UV
B)
AB
VW
AB
UV
C)
UV
VW
AB
UV
D)
VW
UV
first print A B
from f1 U V is printed
then in f2 V W is printed
hence answer is B
-- Sankaranarayanan P.N
if "condition"
printf ("Hello");
else
printf ("World");
if(printf("Hello") != 5)
printf("Hello");
else
printf("World");
-- prathams
main()
{
int i =300;
char *ptr=&i;
*++ptr=2;
printf("%d",i);
}
Here, we are modifying an integer variable using a char pointer. The modification happens to the second byte (from the left of the starting
location) and it is changed to 2.
i.e., 300 will be stored as (lower address on left) on a big endian machine
0 * 224 0 * 216 1 * 28 44 * 20
and as
44 * 20 1 * 28 0 * 216 0 *224
In both the cases using the char pointer we point to the starting byte. And we are incrementing the starting byte by 2.
0 * 224 2 * 216 1 * 28 44 * 20
44 * 20 2 * 28 0 * 216 0 *224
(This is the most common method of checking if an architecture is little endian or big endian)
-- Arjun Suresh
int i = 1;
int main()
{
int a[]= { 0,1, 2} ;
f(a[i], i);
printf("%d", a[i]);
}
void f(int x, int y)
{
y++;
x=5*i;
}
In above function f() uses " call by name" technique, what is the output printed?
a) 2 b) 10 c) 5 d) 1
Using a C style creates confusion for call by name. The scope of variables comes from the function where it is called (dynamic scoping) in call
by name.
y++; i becomes 2
int main(void) {
char p[20];
char *s = "Gate015";
int length = strlen(s);
int i=0;
for(i=0;i<length;i++)
p[i]=s[length-i];
printf("%s",p);
return 0;
}
printf("%s",p);
%s prints all characters from the start address given by p till the first occurrence of '\0'; But p[0] = s[length - 0] = '\0'; So, nothing will be
printed.
for(i=0;i<length;i++)
p[i]=s[length-i-1];
-- Arjun Suresh
please explain the reason for the "weird" false condition coming out from for conditional
checking. top
In this program the TOTAL_ELEMENTS calculates properly when not used in for loop. And the first printf prints properly.
But why the 2nd printf is not working even if the condition in the loop is true. TOTAL_ELEMENTS returns 7.
#include<stdio.h>
int main()
{
int d;
printf("Total= %d\n", TOTAL_ELEMENTS);
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
Due to implicit type casting.
When we operate on two different data types, the smaller one is implicitly casted to bigger one. And between signed and unsigned, unsigned
is ranked higher.
http://gatecse.in/wiki/Chapter_2:_Data_Types_and_Operators_in_C#Implicit_Type_Conversion
In the definition of TOTAL_ELEMENTS, sizeof, returns unsigned int, and unsigned int divided by unsigned int returns unsigned int. When
compared with d, an integer, d is promoted to unsigned and becomes 2n-1, where n is the number of bits used for storing an int. So, the
comparison here returns false.
-- Arjun Suresh
GATE2015-2_15 top
A. ABCD EFGH
B. ABCD
C. HGFE DCBA
D. DCBA
GATE2015-1_11 top
here f1 will not change any values bcz it is call by value but f2 is call by referance and it swaps values of b and c and changes are also
reflected in main function...so 5-6-4= -5 hence answer is -5
-- target gate
GATE2015-1_35 top
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.
int main () {
unsigned int x [4] [3] =
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
printf ("%u, %u, %u, x + 3, * (x + 3), * (x + 2) + 3);
}
Address of x is 2000.
x being a 2 D array,
= 2000 + 36 = 2036.
*(x+3) returns the value at address 2036. But since x is 2-D array, one * will just return the 1D array which is the starting address of it, which is
2036 only.
(x + 2) = 2000 + 2 * 3 * 4 = 2024
*(x + 2) + 3 = 2024 + 3 * 4 = 2036 (The * changes the data type from 2D to 1D and hence + 3 will add 3*4 and not 3 * 3 * 4)
So, A.
-- Arjun Suresh
GATE2015-3_7 top
# include <stdio.h>
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
}
A. 12
B. 120400
C. 1204
D. 1034
p = s1 + 2;
*p = '0';
-- Arjun Suresh
GATE2015-3_26 top
#include<stdio.h>
int main()
{
static int a[] = {10, 20, 30, 40, 50};
static int *p[] = {a, a+3, a+4, a+1, a+2};
int **ptr = p;
ptr++;
printf("%d%d", ptr-p, **ptr);
}
GATE2015-3_48 top
#include<stdio.h>
int main()
{
int i, j, k = 0;
j=2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k-=--j;
for (i=0; i<5; i++)
{
switch(i+k)
{
case 1:
case 2: printf("\n%d", i+k);
case 3: printf("\n%d", i+k);
default: printf("\n%d", i+k);
}
}
return 0;
}
j=2 * 3 / 4 + 2.0 / 5 + 8 / 5;
j = (((2 * 3) / 4) + (2.0 / 5) ) + (8/5); //As associativity of +,* and / are from left to right and + has less precedence than * and /.
j = ((6/4) + 0.4) + 1); //2.0 is double value and hence 5 is implicitly typecast to double and we get 0.4. But 8 and 5 are integers and hence 8/5
gives 1 and not 1.6
j = 2.4; // since j is integer when we assign 2.4 to it, it will be implicitly typecast to int.
So, j = 2;
k -= --j;
The variables j and k have values 1 and -1 respectively before the for loop. Inside the for loop, the variable i is initialized to 0 and the loop
runs from 0 to 4.
Answer:
-- Shyam Singh
GATE2015-3_54 top
The variable x is initialized to 1 . First and only call to f1() returns 26. First call to f2() returns 51. First and only call to f3() returns 100 .
Second call to f2() returns 52 (The value of local static variable x in f2() retains its previous value 51 and is incremented by 1 ).
x = 1 + 26 + 51 + 100 + 52 = 230
Answer: 230
-- Shyam Singh
There is a rule called "sequence point rule" in C. We are not allowed to modify a memory location more than once or read and write the same
location (reading other than for the purpose of getting a value to write) between two sequence points. If we do this, the result is "Undefined".
Reference: http://gatecse.in/wiki/Undefined_Value
-- Arjun Suresh
DS top
GATE2013_44 top
Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.
MultiDequeue(Q){
m=k
while (Q is not empty) and (m > 0) {
Dequeue(Q)
m=m–1
}
}
What is the worst case time complexity of a sequence of n queue operations on an initially empty
queue?
(A) Θ(n)
(B) Θ(n + k)
(C) Θ(nk)
(D) Θ(n 2 )
There are three possible operations on queue- Enqueue, Dequeue and MultiDequeue. MultiDequeue is calling Dequeue multiple times based
on a global variable k. Since, the queue is initially empty, whatever be the order of these operations, there cannot be more no. of Dequeue
operations than Enqueue operations. Hence, the total no. operations will be n only.
-- Arjun Suresh
GATE2008_62 top
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with
the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after function completes execution?
struct node {
int value;
struct node *next;
};
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
The loop is interchanging the adjacent elements of the list. But after each interchange, next interchange starts from the unchanged elements
only (due to p = q -> next;).
1st iteration 1 2 3 4 5 6 7
=> 2 1 3 4 5 6 7
2nd iteration 2 1 4 3 5 6 7
3rd iteration 2 1 4 3 6 5 7
p pointing to null q pointing to 7, as p is false hence q=p? p->next:0; will return q=0 ending the loop
-- Manali
GATE1991_01,ix top
41673258
-- Keith Kr
GATE1991_01,viii top
This is straightforward. The nodes of the given tree are given in square boxes. The weights associated with the nodes are the numbers
example 15,9,10 etc.
Weighted path length = sigma(for(each node in the tree) (path length)*(weight of the node) ).
So answer (written in path_length*weight form) = 4*2 + 4*4 + 4*5 + 4*7 + 3*9 + 3*10 + 1*15 =144
-- arvchamp
GATE1991_03,vii top
03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
Lets try something different when you read the word pop then delete the last pushed element and print it ..now delete the push word which we
have already executed ..now go on from left to right and do the same
-- Bhagirathi Nayak
GATE2002_2.12 top
A weight-balanced tree is a binary tree in which for each node, the number of nodes in the left sub tree is at least half and at most twice the
number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the furthest leaf) of such a
tree on n nodes is best described by which of the following?
A. log2 n
B. log 4 n
3
C. log3 n
D. log 3 n
2
As this makes maximum nodes go to one subtree and that is what we want to get the maximum height with a given number of nodes.
H(n) = H(2/3(n-1)) + 1
H(1) = 0
We can draw a recurrence tree and the cost at each level is 1, and the height will be log(3/2)n.
So, D option is the answer.
-- Arjun Suresh
GATE2003_6 top
Let T (n) be the number of different binary search trees on n distinct elements.
A. n−k+1
B. n−k
C. n−k−1
D. n−k−2
The summation is for each node, if that node happens to be the root. When a node is root, it will have (k-1) nodes on the left sub tree (k being
any number) and correspondingly (n-k) elements on the right sub tree. So, we can write recurrence T(k-1) * T(n-k) for the number of distinct
binary search trees, as the numbers on left and right sub trees form BSTs independent of each other. Hence, answer is B.
Knowing the direct formula can also help in getting the answer but is not recommended.
http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_nodes
-- Arjun Suresh
GATE2003_19 top
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses
the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?
A. 7 5 1 0 3 2 4 6 8 9
B. 0 2 4 3 1 6 5 9 8 7
C. 0 1 2 3 4 5 6 7 8 9
D. 9 8 6 4 2 3 0 1 5 7
GATE2006_13 top
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored
at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum
size of X should be
(A) log2 n
(B) n
(C) 2n + 1
(D) 2 n − 1
should be D...
Since binary tree can be of any form, the worst case happens for right skewed binary tree. Now, root goes to index 1, its child goes to index 3,
its child goes to index 7 and so on the nth vertex goes to 2n - 1 th index of array.
-- Shaun Patel
GATE2004_3 top
A single array A[1 .. MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top 2
(top < top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full”
is
D. top1 = top2 - 1
ans d)
Since the stacks are growing from opposite ends, initially top1 = 1 and top2 = MAXSIZE. Now, to make the space usage most efficient we
should allow one stack to use the maximum possible space as long as other stack doesn't need it. So, either of the stack can grow as long as
there is space on the array and hence the condition must be top1 = top2 - 1;
-- Aditi Dan
GATE2004_7 top
Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements
are true?
A. I only
B. II only
C. I and II only
D. III or IV
option c is correct because the last digit of every digit given is equal in i and ii
-- Bhagirathi Nayak
GATE2004_36 top
A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that
both the operations enQueue and deQueue can be performed in constant time?
A. rear node
B. front node
C. not possible with a single pointer
D. node next to front
EnQueue: Insert newNode after Rear, and make Rear point to the newly inserted node:
DeQueue: Delete the Front node, and make the second node the front node.
-- Pragy Agarwal
GATE2007_38 top
The following postfix expression with single digit operands is evaluated using a stack:
823^/23*+51*-
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are
A. 6, 1
B. 5, 7
C. 3, 2
D. 1, 5
push 8 so stack is 8
push 2 so stack is 8 2
push 8 2 3
push 2 stack is 1 2
push 3 stack is 1 2 3
hence answer is A
-- Sankaranarayanan P.N
GATE2007_43 top
A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of
leaves in a complete n-ary tree. If L = 41 and I = 10, what is the value ofn?
A. 3
B. 4
C. 5
D. 6
Sum of degrees in tree = L + I * (n+1) - 1 = 10n + 50 (Each leaf node has degree 1 and all internal nodes have degree k+1, except root which
has degree k)
So, number of edges = 5n + 25 (Number of edges in a graph (hence applicable for tree also) is half the sum of degrees as each edge
contribute 2 to the sum of degrees)
In a tree with n nodes we have n-1 edges, so with 41+10 = 51 nodes, there must be 50 edges.
So, 5n + 25 = 50
5n = 25 => n = 5
-- Arjun Suresh
GATE2009_36 top
The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k)
= k mod 10 and linear probing. What is the resultant hash table?
A.
0
1
2 2
3 23
4
5 15
6
7
8 18
9
B.
0
1
2 12
3 13
4
5 5
6
7
8 18
9
C.
0
1
2 12
3 13
4 2
5 3
6 23
7 5
8 18
9 15
D.
0
1
2 2, 12
13, 3,
3
23
4
5 5, 15
6
7
8 18
9
C is the correct option ..directly from the definition of linear probing. In linear probing, when a hashed location is already filled, locations are
linearly probed until a free one is found.
http://courses.cs.washington.edu/courses/cse326/00wi/handouts/lecture16/sld015.htm
-- Bhagirathi Nayak
GATE2009_59,60 top
60. What is the content of the array after two delete operations on the correct answer to the previous question?
Taking the given array as level order traversal, we can build binary tree.
(C) is a valid binary max-heap as all children are smaller than their parent
60. During delete, the root element is removed, replaced with the last element and heap property is corrected by pushing the root downwards.
So, for first delete,
25 14 16 13 10 8 12 -> 12 14 16 13 10 8 -> 16 14 12 13 10 8 (the element not satisfying max-heap property is exchanged with the largest of its
children) (heap property satisfied)
Second delete:
http://homepages.ius.edu/RWISMAN/C455/html/notes/Chapter6/heapify.htm
-- Arjun Suresh
GATE2005_5 top
A program P reads in 500 integers in the range [0, 100] representing the scores of 500 students. It then prints the frequency of each score
above 50. What would be the best way for P to store the frequencies?
A. An array of 50 numbers
as we our area of interest is only the 50 numbers so take An array of 50 numbers where A[0] corresponds to 51...A[49] corresponds to 100
then after reading an input just increment the counter in correct position as said above
-- Bhagirathi Nayak
GATE2005_33 top
Postorder traversal of a given binary search tree, T produces the following sequence of keys
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?
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
in order traversal of b binary search tree returns the element in sorted order - ascending (inorder is left parent then right. in a bst left is less
than parent and right is greater than parent). In this option 1 is the only sorted list. hence it is the only possiblity
-- Sankaranarayanan P.N
GATE2005_34 top
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are
inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
(A) 10, 8, 7, 5, 3, 2, 1
(B) 10, 8, 7, 2, 3, 1, 5
(C) 10, 8, 7, 1, 2, 3, 5
(D) 10, 8, 7, 3, 2, 1, 5
ans is D....whenever we insert an element in heap,it will always inserted in last level from left to right..so here we insert element 1 and 7 as a
child of node 5.then we perform heapify algorithm until we get the min/max heap..so here finally in above question we get the heap whose
level order traversal is 10,8,7,3,2,1,5
Initial heap:
After insert of 1
After insert of 7
-- neha pawar
GATE2013_7 top
Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of n
nodes?
(A) O(1 )
(B) O(log n )
(C) O(n )
Best case:O(log n) Worst case:O(n) worst case occurs when the bst is left or right skewed then we have to go through all the elements if the
element is to be placed to in the bottom most level
-- Bhagirathi Nayak
GATE1998_2.14 top
A [ LB1..............UB1,LB2.................UB2 ]
BA = Base address.
-- Gate Keeda
GATE1998_20 top
Draw the binary tree with node labels a, b, c, d, e, f and g for which the inorder and postorder traversals result in the following sequences:
Inorder: a f b c d g e
Postorder: a f c g e d b
binary tree
-- Anu
GATE2006_49 top
let n insert and m(≤ n) delete operations be performed in an arbitrary order on an empty queue Q. Letx and y be the number of push and
pop operations performed respectively in the process. Which one of the following is true for allm and n ?
Answer is (a)
The order in which insert and delete operations are performed matters here.
The best case: Insert and delete operations are performed alternatively. In every delete operation, 2 pop and 1 push operations are
performed. So, total m+ n push (n push for insert() and m push for delete()) operations and 2m pop operations are performed.
The worst case: First n elements are inserted and then m elements are deleted. In first delete operation, n + 1 pop operations and n push
operation are performed. Other than first, in all delete operations, 1 pop operation is performed. So, total m + n pop operations and 2n push
operations are performed (n push for insert() and m push for delete())
-- Kalpna Bhargav
GATE2014-1_40 top
Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The collisions are resolved by chaining. The following 9 keys are
inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
(A) 3, 0, and 1
(B) 3, 3, and 3
(C) 4, 0, and 1
(D) 3, 0, and 2
So, Ans is A
-- Jayesh Malaviya
GATE2014-2_41 top
Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH
and POP instructions. Which one of the following statements is TRUE (with respect to this modified 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 take a single instruction each.
(C) is the answer. While ENQUEUE we REVERSE the stack, PUSH the element and then again REVERSE the stack. For DEQUE we simply
POP the element.
(Option (B) can be used to get the first element from the stack by doing a POP after REVERSE. But we have to restore the stack using
REVERSE (otherwise next POP won't work) which means ENQUEUE actually needs 3 instructions and not 2)
-- Arjun Suresh
GATE2014-3_40 top
Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are
unfilled after the first 3 insertions?
We have 100 slots each of which are picked with equal probability by the hash function (since hashing is uniform). So, to avoid first 3 slots, the
hash function has to pick from the remaining 97 slots. And repetition is allowed, since chaining is used- meaning a list of elements are stored
in a slot and not a single element.
= (97 × 97 × 97)/100 3
-- Arjun Suresh
GATE1997_4.7 top
Implementing stack using priority queue require first element inserted in stack will be deleted at last, and to implement it using deletemin()
operation of queue will require first element inserted in queue must have highest priority.
GATE1994_1.14 top
Which of the following permutations can be obtained in the output (in the same order) using a stack assuming that the input is the sequence
1, 2, 3, 4, 5 in that order?
(a) 3, 4, 5, 1, 2
(b) 3, 4, 5, 2, 1
(c) 1, 5, 2, 3, 4
(d) 5, 4, 3, 1, 2
push 1 push 2 push 3 pop 3 push 4 pop 4 push 5 pop 5 pop 2 pop 1 then o/p is 3,4,5,2,1 option b
-- Sankaranarayanan P.N
GATE1995_2.21 top
It will be B.
GATE1995_6 top
GATE1996_1.12 top
A.
http://en.wikipedia.org/wiki/List_(abstract_data_type)#Operations
-- Gate Keeda
GATE1996_1.13 top
C.
http://en.wikibooks.org/wiki/Data_Structures/Hash_Tables#Chaining
-- Gate Keeda
GATE1996_1.14 top
B.
a,b,c will become unbalanced with Balance factor as +2,+2,+2 respectively. Balance factor should be -1,0,+1.
GATE1996_1.15 top
C.
Left-->Right-->Root.
Ref: http://gateoverflow.in/2718/gate1996_1-14
-- Gate Keeda
GATE1996_2.11 top
The minimum number of interchanges needed to convert the array into a max-heap is
(a) 0
(b) 1
(c) 2
(d) 3
Answer: C.
Only element 70 violates the rule. Hence, it must be shifted to its proper position.
Step1: swap(10, 70)
Step2: swap(40, 70)
Hence, only 2 interchanges are required.
-- Gate Keeda
GATE1996_2.14 top
B.
Root will be 50. now insert one by one, greater to 50 in the right sub tree, lesser in left sub tree.
Or you can simply count the number looking at the i/p. less than 50 are 7. more than 50 are 4.
-- Gate Keeda
GATE2008-IT_71 top
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could
have encountered them in the search?
Answer: D
GATE2008-IT_72 top
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
it should be C)
Inorder sequences are sorted. In preorder traversal root comes first and in postorder traversal root comes last.
-- Sneha Goel
GATE2008-IT_76 top
A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three respectively. The degree of a node is defined as the
number of its neighbours.
n3 can be expressed as
A) n1 + n2 - 1
B) n1 - 2
C) [((n1 + n2)/2)]
D) n2 - 1
assume the above tree so value of n1 is 3 n2 =1 n3 =1 check with options now u vil get option B as correct
-- Shreyans Dhankhar
GATE2008-IT_77 top
A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three respectively. The degree of a node is defined as the
number of its neighbours.
Starting with the above tree, while there remains a node v of degree two in the tree, add an edge between the two neighbours of v and then
remove v from the tree. How many edges will remain at the end of the process?
A) 2 * n1 - 3
B) n2 + 2 * n1 - 2
C) n3 - n2
D) n2 + n1 - 2
-- Shreyans Dhankhar
GATE2007-IT_29 top
When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20, 40, 50, 70 80, 90 are traversed, not
necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to
the node containing the value 60?
A) 35
B) 64
C) 128
D) 5040
In BST search we if we go from say 10 to 40 while searching for 60, we will never encounter 20. So, 10, 20, 40 and 50 visited, means they are
visited in order. Similarly, 90, 80 and 70 are visited in order. So, our required answer will be
(Since only one permutation is valid for both the smaller set of number as well as larger set of numbers)
7!
= 4!3!
= 35
-- Arjun Suresh
GATE2006-IT_44 top
for a heap(max heap) parent should be greater than or equal to children. in a heap of [1..n] left child of ith node will be at 2*i th position and
right child will be at 2*i+1 position
Suppose that we have numbers between 1 and 100 in a binary search tree and want to search for the number 55. Which of the following
sequences CANNOT be the sequence of nodes examined?
at 47 we see that search key 55 is greater and it will be on right side of 47. so in further comparison a value less than 47 will not come
GATE2006-IT_71 top
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. The index of the parent
of element X [i], i ≠ 0, is
A. ⌊i / 2⌋
B. ⌈(i - 1)/2⌉
C. ⌈i/2⌉
D. ⌈i/2⌉ - 1
option D
left child of ith element will be at 2*i+1 and right child at 2(i+1)
-- Sankaranarayanan P.N
GATE2006-IT_73 top
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If the root node is at
level 0, the level of element X[i], i ≠ 0, is
A) ⌊log 2 i⌋
⌈log 2 (i +
B)
1)⌉
⌊log 2 (i +
C)
1)⌋
D) ⌈log 2 i⌉
Floor(log(i+1)) draw the tree and realise that the last element at each level is the best choice to arrive at a conclusion
-- Bhagirathi Nayak
GATE2004-IT_53 top
An array of integers of size n can be converted into a heap by adjusting the heaps rooted at each internal node of the complete binary tree
starting at the node ⌊(n - 1) /2⌋, and doing this adjustment up to the root node (root node is at index 0) in the order ⌊(n - 1)/2⌋, ⌊(n - 3)/ 2⌋, ....., 0.
The time required to construct a heap in this manner is
A) O(log n)
B) O(n)
C) O (n log log n)
D) O(n log n)
it shud be O(n).
-- Sneha Goel
GATE2004-IT_54 top
Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD, respectively?
A)
B)
C)
D)
answer: D
-- Sankaranarayanan P.N
The number of different insertion sequences on numbers {1, 14, 26, 44, 60, 71} on an initially empty hash table H of size 6 and a hash function
x%6 with linear probing scheme for collision resolution such that the end hash table should look like 60, 1, 14, 26, 44, 71 (The indices of
numbers from left to right are 0 to 5) are ________
14, 26 and 44 mod 6 = 2 and hence in any input sequence they must come in sequence (otherwise their sequence changes in the end result).
Now, we have 6 places to fill these 3 numbers and this can be done in 6P3 = 120 ways. There are 3! = 6 permutations possible for 14, 26 and
44 and out of these only 1 is valid. So, valid permutations for these 3 numbers = 120/6 = 20.
Now, we have 3 places to fill in 3 remaining numbers. This can be done in 3! = 6 ways. So, total ways = 20*6 = 120.
-- Arjun Suresh
GATE2005-IT_12 top
The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the right subtree of the root contains p nodes.
The first number to be inserted in the tree must be
A. p
B. p+1
C. n-p
D. n-p+1
from 1,...n elements p elements are on the right. so root or first inserted will be at n-p
-- Sankaranarayanan P.N
GATE2005-IT_13 top
A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and
integers i.
If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
A) 6
B) 4
C) 3
D) 2
-- Shridhar
GATE2005-IT_16 top
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and the hash function used is key
% 10. If the values 43, 165, 62, 123, 142 are inserted in the table, in what location would the key value 142 be inserted?
A) 2
B) 3
C) 4
D) 6
43 in loc 3
165 in loc 5
62 in loc 2
hence answer D
-- Sankaranarayanan P.N
GATE2005-IT_50 top
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is
h > 0, then the minimum number of nodes in the tree is
A) 2h - 1
B) 2h - 1 + 1
C) 2h - 1
D) 2h
it should be B)
-- Sneha Goel
GATE2005-IT_54 top
The following C function takes a singly-linked list of integers as a parameter and rearranges the elements of the list. The list is represented as
pointer to a structure. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of
the list after the function completes execution?
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
i think it's B) 2 1 4 3 6 5 7:
as,
GATE2005-IT_55 top
A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-order and the values in each node printed out,
the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in post-order, the sequence obtained would be
A) 8, 7, 6, 5, 4, 3, 2, 1
B) 1, 2, 3, 4, 8, 7, 6, 5
C) 2, 1, 4, 3, 6, 7, 8, 5
D) 2, 1, 4, 3, 7, 8, 6, 5
Answer is D.
-- Gate Keeda
GATE2015-2_17 top
Consider a complete binary tree where the left and right subtrees of the root are max-heaps. The lower bound for the number of operations to
convert the tree to a heap is
A. Ω(log n)
B. Ω(n)
C. Ω(n log n)
D. Ω(n 2 )
Ans A
Max-Heapify(root)
-- Vikrant Singh
GATE2015-1_10 top
Which of the following is/are correct in order traversal sequence(s) of binary search tree(s)?
I. 3, 5, 7, 8, 15, 19, 25
II. 5, 8, 9, 12, 10, 15, 25
III. 2, 7, 10, 8, 14, 16, 20
IV. 4, 6, 7, 9, 18, 20, 25
A. I and IV only
B. II and III only
C. II and IV only
D. II only
GATE2015-2_38 top
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode) {
case -1: size = val; break;
case 0: if (stkTop < size ) A[stkTop++]=val; break;
default: if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20]; A=B; stkTop = -1;
stkFunc (-1, 10);
stkFunc (0, 5);
stkFunc (0, 10);
printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}
Answer: 15
The code is pushing 5 and 10 on stack and then popping the top two elements and printing their sum.
GATE2015-1_23 top
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 5
are
A. 63 and 6, respectively
B. 64 and 5, respectively
C. 32 and 6, respectively
D. 31 and 5, respectively
option A is correct because height 5 means level 6 so maximum node = 2^l -1 =2^6 -1=63
and for minimum, at each level only single node so total 6
-- Anoop Sonkar
GATE2015-1_32 top
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4.
Array index 1 2 3 4 5 6 7 8 9
Value 40 30 20 10 15 16 17 8 4
Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
Heap is complete binary tree. To insert a new element, we put it at the end of the tree and move up towards root till heap property is satisfied.
Here, 35 comes as child of 15, with the path 40-30-15-35. So, we swap 15, 35 and then 30, 35 to get the new path 40-35-30-15. So, new
heap will be 40 35 20 10 30 16 17 8 4 15.
-- Arjun Suresh
GATE2015-3_12 top
A. 284
B. 213
C. 142
D. 71
we have to keep symbol into stack and when we get two operands followed by operator ..we will apply operator on last two operands
symbol stack
10 10 (keep in stack)
5 10 5 (keep in stack)
60 15 60 (keep in stack)
6 15 60 6 (keep in stack)
/ 15 60 6 / = 15 10 ( apply operator on last 2 operands)
So answer is 142
-- Praveen Saini
GATE2015-3_13 top
While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest
level is
A. 65
B. 67
C. 69
D. 83
GATE2015-3_17 top
Given that hash table T with 25 slots that stores 2000 elements, the load factora for T is _________.
GATE2015-3_19 top
A. 4
B. 5
C. 2
D. 3
GATE2015-3_25 top
Consider a binary tree T that has 200 leaf nodes. Then the number of nodes in T that have exactly two children are ______.
Let number of nodes with exactly two children be x, and with exactly one children be y.
Total degree = 200 + 3x + 2y - 1 (As all nodes with 2 children have degree 3 except the root)
x = 199
-- Arjun Suresh
Is it correct? top
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
i = delete(Q);
f(Q);
push(s, i);
}
}
why in open address hash table with load factor α=n/m<1, the expected number of probes in an unsuccessful search is at most 1/(1-α)
assuming uniform hashing ?
Here, P (x) denotes the probability of having x number of probes in an unsuccessful search (In probing a search fails as soon as we reach an
empty slot). Probability of a probe going to an occupied slot is α = n and this reduces for consecutive probes as both n and m decreases by
m
1 each. Still, we can say probability of having at least i probes, say Q(i) < α(i−1) as (i − 1) probes must be going to occupied slots.
Now, we can try to put this Q term inside the expectation formula. Probability of having exactly i probes is equal to probability of having at
least (i) probes minus probability of having at least i + 1 probes. i.e., P (i) = Q(i) − Q(i + 1)
Thus,
-- Arjun Suresh
A hash table with ten buckets with one slot per bucket is shown in the following figure with the symbols s1 to s7 entered into it using some hashing function with
linear probing.The worst case number of comparison required when the symbol being searched is not in the table is
No of comparison in worst case if an element not in hash table is size of largest cluster +1..
No ofcomparison is 4 + 1 = 5
-- Digvijay Pandey
Brought to you by GATE Overflow
http://gateoverflow.in/