Official Paper

GATE CS 2017 Official Paper: Shift 1 (Previous Year Paper)

65 questions · 180 minutes · with answers · free

General Aptitude (10 questions)

1

After Rajendra Chola returned from his voyage to Indonesia, he ________ to visit the temple in Thanjavur.

  1. ((a))

    Was wishing

  2. ((b))

    Is wishing

  3. ((c))

    Wished

  4. ((d))

    Had wished

Show Answer
Answer: ((c))

Wished

Concept: Based on the concept of clauses.

A clause is a combination of related words containing a subject and a verb. It can be a simple sentence or a part of a compound sentence.

Main clause: It gives a complete meaning and can stand alone as a complete sentence

Subordinate clause: It depends on the main clause to give a complete meaning.

Explanation

Rules of clauses:

According to the rule, when main clause is in the past or past perfect tense, the subordinate clause must also be in the past or past perfect tense.

So, here past form of verb will be used. Given sentence will become:

“After Rajendra Chola returned from his voyage to Indonesia, he wished to visit the temple in

Thanjavur.”

2

Research in the workplace reveals that people work for many reasons _________.

  1. ((a))

    money beside

  2. ((b))

    beside money

  3. ((c))

    money besides

  4. ((d))

    besides money

Show Answer
Answer: ((d))

besides money

Beside and besides both have different meaning.

CASE 1:

When s is added after beside i.e. besides, it can be used as a preposition or can be used as an adverb. While using as a preposition, its meaning is “in addition to” or “apart from” and while using as an adverb its meaning is “furthermore; as well as; also”.

CASE 2:

When beside is used without s at the end, it behaves only like a preposition which means “next to “, “at the side of”.

Here, correct answer is ‘besides money’, used as a preposition.

Correct sentence will be:

Research in the workplace reveals that people work for many reasons besides money.

3

Rahul, Murali, Srinivas and Arul are seated around a square table. Rahul is sitting to the left of Murali. Srinivas is sitting to the right of Arul. Which of the following pairs are seated opposite each other?

  1. ((a))

    Rahul and Murali

  2. ((b))

    Srinivas and Arul

  3. ((c))

    Srinivas and Murali

  4. ((d))

    Srinivas and Rahul

Show Answer
Answer: ((c))

Srinivas and Murali

The correct answer is option 3

EXPLANATION

While facing towards the center of the square,

Left – clockwise direction

Right – anticlockwise direction

So, Srinivas and Murali are seating opposite to each other.

4

Find the smallest number y such that y x 162 is a perfect cube.

  1. ((a))

    24

  2. ((b))

    27

  3. ((c))

    32

  4. ((d))

    36

Show Answer
Answer: ((d))

36

Given y × 162,

Take the factors of 162:

Factors of 162 = 2 × 3 × 3 × 3 × 3  

So to make it a perfect cube, there is need of two 2’s and two 3’s .

So y = 2 × 2 × 3 × 3 = 36

Minimum value of y to make y × 162 a perfect cube is 36.

5

The probability that a k-digit number does NOT contain the digits 0, 5, or 9 is

  1. ((a))

    0.3k

  2. ((b))

    0.6k

  3. ((c))

    0.7k

  4. ((d))

    0.9k

Show Answer
Answer: ((c))

0.7k

Consider k = 1, means 1-digit number doesn’t contain the digits 0, 5, or 9.

Remaining digits are 1, 2, 3, 4, 6, 7 ,8.

Total outcomes = 10

Favourable outcomes = 7

Probability = 710\frac{7}{{10}} = 0.7

Consider k = 2, means 2-digit number doesn’t contain the digits 0, 5, or 9

So, both the places can be filled by the remaining 7 digits.

Total outcomes = 10 × 10

Favourable outcomes = 7 × 7

Probability = 710\frac{7}{{10}} × 710\frac{7}{{10}} = 0.72{0.7^2}

Similarly it goes for k = 3, probability = 0.73{0.7^3}

It goes up to k….

The probability that a k-digit number does NOT contain the digits 0, 5, or 9 = 0.7k{0.7^k}

6

“The hold of the nationalist imagination on our colonial past is such that anything inadequately or improperly nationalist is just not history.”

Which of the following statements best reflects the author's opinion?

  1. ((a))

    Nationalists are highly imaginative.

  2. ((b))

    History is viewed through the filter of nationalism.

  3. ((c))

    Our colonial past never happened.

  4. ((d))

    Nationalism has to be both adequately and properly imagined.

Show Answer
Answer: ((b))

History is viewed through the filter of nationalism.

The author is saying that the hold of the nationalist imagination is on our country's colonial history, but it is not always necessary that anything that is not completely nationalist is not history. History and nationalism can be seen together but not always. Sometimes, history is viewed through the imagination of nationalism.

So, the correct answer is, "History is viewed through the filter of nationalism."

7

Six people are seated around a circular table. There are at least two men and two women. There are at least three right-handed persons. Every woman has a left-handed person to her immediate right. None of the women are right-handed. The number of women at the table is

  1. ((a))

    2

  2. ((b))

    3

  3. ((c))

    4

  4. ((d))

    Cannot be determined

Show Answer
Answer: ((a))

2

There are atleast two men and two women and atleast three right-handed person.

No women is right handed. It means, all three right-handed person are men.

So, women can’t be more than 3.

Now it is given that every woman has a left-handed person to her right. Here two cases:

CASE 1:

Diagram

If 3 women are considered on table, then there will be atleast one women who has a right-handed person on her right. So, it violates the given condition.

CASE 2:

Diagram

So, only 2 women are there on the circular table.

8

The expression (x+y)xy2\frac{{\left( {x + y} \right) - \left| {x - y} \right|}}{2} is equal to

  1. ((a))

    The maximum of x and y

  2. ((b))

    The minimum of x and y

  3. ((c))

    1

  4. ((d))

    None of the above

Show Answer
Answer: ((b))

The minimum of x and y

Equation: (x+y)xy2\frac{{\left( {x + y} \right) - \left| {x - y} \right|}}{2}

CASE 1

When x > y

xy\left| {x - y} \right| = x – y,

(x+y)xy2=(x+y)x+y2=2y2=y\frac{{\left( {x + y} \right) - \left| {x - y} \right|}}{2} = \frac{{\left( {x + y} \right) - x + y}}{2} = \frac{{2y}}{2} = y

It means minimum of x and y.

CASE 2

When x < y

xy\left| {x - y} \right| = y - x,

(x+y)xy2=(x+y)y+x2=2x2=x\frac{{\left( {x + y} \right) - \left| {x - y} \right|}}{2} = \frac{{\left( {x + y} \right) - y + x}}{2} = \frac{{2x}}{2} = x

Results in minimum of x and y.

So, in both the cases result is minimum of x and y.

9

Arun, Gulab, Neel and Shweta must choose one shirt each from a pile of four shirts coloured red, pink, blue and white respectively. Arun dislikes the colour red and Shweta dislikes the colour white. Gulab and Neel like all the colours. In how many different ways can they choose the shirts so that no one has a shirt with a colour he or she dislikes?

  1. ((a))

    21

  2. ((b))

    18

  3. ((c))

    16

  4. ((d))

    14

Show Answer
Answer: ((d))

14

Total number of shirts = 4

Total number of persons = 4

Arun dislikes red colour and Shweta dislike white colour.

No. of ways in which Arun chooses the shirt = 3P1^3{P_1} = 3

No. of ways in which Shweta chooses shirt = 3

As, Gulab and Neel can choose from all colour’s shirts.

So, no. of ways in which Gulab chooses a shirt = 4

no. of ways in which Neel chooses a shirt = 4

Total possible ways = 3 + 3 + 4 + 4 = 14

10

A contour line joins locations having the same height above the mean sea level. The following is a contour plot of a geographical region. Contour lines are shown at 25 m intervals in this plot. If in a flood, the water level rises to 525 m, which of the villages P, Q, R, S, T get submerged?

  1. ((a))

    P, Q

  2. ((b))

    P, Q, T

  3. ((c))

    R, S, T

  4. ((d))

    Q, R, S

Show Answer
Answer: ((c))

R, S, T

Explanation:

Heights of all the villages according to the given data is :

As contour lines are shown at 25 m intervals.

Height of P = more than 550

Height of Q = between 525 and 550

Height of R = between 450 and 500

Height of S = between 425 and 450

Height of T = between 500 and 525

The water level is 525 m. All the villages below this water level height get submerged.

So, the answer is R, S, and T.

Computer Science and Information Technology (55 questions)

11

The statement (¬ p) ⇒ (¬ q) is logically equivalent to which of the statements below?

  1. p ⇒ q
  2. q ⇒ p
  3. (¬q) ∨ p
  4. (¬p) ∨ q
  1. ((a))

    I only

  2. ((b))

    II and IV only

  3. ((c))

    II only

  4. ((d))

    II and III only

Show Answer
Answer: ((d))

II and III only

Formula:

p ⇒ q ≡ ¬ p ∨ q

Derivation:

(¬ p) ⇒ (¬ q)

≡ ¬ (¬ p) ∨ (¬ q)

≡ p ∨ (¬ q)

Statement I,

p ⇒ q

≡ (¬ p) ∨ q,

Statement II,

q ⇒ p

≡ (¬ q) ∨ p

≡ p ∨ (¬ q)

Statement III,

(¬q) ∨ p

≡ p ∨ (¬ q)

Statement IV,

(¬p) ∨ q

Only II and III option matches with the given implication.

Alternate Method:

By using Truth table:

Pq¬ p¬ q(¬ p) (¬ q)p ⇒ qq p(¬q) p(¬p) ∨ q
TrueTrueFalseFalseTrueTrueTrueTrueTrue
TrueFalseFalseTrueTrueFalseTrueTrueFalse
FalseTrueTrueFalseFalseTrueFalseFalseTrue
FalseFalseTrueTrueTrueTrueTrueTrueTrue

 

So, only II and III matches with the given implication.

12

Consider the first-order logic sentence F: ∀x (∃ y R(x, y)). Assuming no-empty logical domains, which of the sentence below are implied by F?

  1. ∃y (∃x R(x, y))
  2. ∃y (∀x R(x, y))
  3. ∀y (∃x R(x, y))
  4. ¬ ∃x (∀y ¬ R(x, y))
  1. ((a))

    IV only 

  2. ((b))

    I and IV only

  3. ((c))

    II only

  4. ((d))

    II and III only 

Show Answer
Answer: ((b))

I and IV only

Concept:

TrueFalse
∀ xAllAt least one false
∃ xAtleast one trueFor all x, if P(x) is false, if we are taking predicate as P(x)

 

One of the methods for this question is by considering x and y as the domains by using some statements.

Let us suppose x is for a girl and y is for a boy.

Given F is ∀x(∃ y R(x, y)) , in case of English language this means,

F: All girls like some boys

Now, check all the option one by one.

  1. ∃y (∃x R(x, y)) means some boys are liked by some girls.

From this statement it is clear that it is the subset of given statement. TRUE

  1. ∃y (∀x R(x, y)) means some boys are liked by all the girls. FALSE
  2. ∀y (∃x R(x, y)) means all boys are liked by some girls which is opposite of given statement. So, this is FALSE.
  3. ¬ ∃x (∀y ¬ R(x, y)) means for all girls like some boys. So, this is equivalent to given statement. TRUE

Alternate:

¬ ∃x (∀y ¬ R(x, y)) ≡ ∀x(¬ ∀y( ¬ R(x, y))) ≡ ∀x(∃x R(x, y))

∀x (∃ y R(x, y)) → ∃ x (∃ y R(x, y))

13

Let c1 … cn be scalars, not all zero, such that \(\mathop \sum \limits_{i = 1}^n {c_i}{a_i} = 0\) where ai are column vectors in Rn. Consider the set of linear equations

Ax = b

where A = \(\left[ {{a_1} \ldots {a_n}} \right];and;b = \mathop \sum \limits_{i = 1}^n {a_i}\) The set of equations has

  1. ((a))

    a unique solution at x = Jn where Jn denotes a n-dimensional vector of all 1

  2. ((b))

    no solution

  3. ((c))

    infinitely many solutions 

  4. ((d))

    finitely many solutions

Show Answer
Answer: ((c))

infinitely many solutions 

Explanation:

c1, c2, … cn are scalars i.e. not all zero. \(\mathop \sum \limits_{i = 1}^n {c_i}{a_i} = 0\). Here ci is scalar and ai vector.

And when a scalar multiplied with vector, result will be zero, scalar value will be zero.

c1a1 + c2 a2 + … + cn an = 0 So, here ci value will be 0.

Here we can say that A is linearly dependent, and determinant of A is 0. (Linearly Dependent: Vectors being linearly independent means they represent independent directions in your vector spaces, while linearly dependent vectors mean they don’t. So, for example if you have a set of vectors {v1, v2, v3, v4, v5} and you can walk some distance in the v1 direction, then a difference distance in v2 and then in direction v3. If in the end, you are back at the point where you started then the vectors are linearly dependent otherwise not). A= [a1, a2, a3, … an]

b = \(\mathop \sum \limits_{i = 1}^n {a_i}\)

Ax = b

a1x1 + a2 x2 + … + an xn = a1 + a2 + … + an

x1 = x2 = x3 = … = xn = 1 (It is one of the infinite solutions) and all other solution are on that same line.

So, the answer will be infinitely many solutions.

14

Consider the following functions from positive integers t real numbers:

10,n,;n,log2n,100n10,\sqrt n ,;n,{\log _2}n,\frac{{100}}{n}

The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:

  1. ((a))

    log2n,100n,;10;,n,;n{\log _2}n,\frac{{100}}{n},;10;,\sqrt n ,;n

  2. ((b))

    100n,;10;,log2n,;n,;n\frac{{100}}{n},;10;,{\log _2}n,;\sqrt n ,;n

  3. ((c))

    10.100n,;n,log2n,;n10.\frac{{100}}{n},;\sqrt {n,} {\log _2}n,;n

  4. ((d))

    100n,log2n,;10,n,;n\frac{{100}}{n},{\log _2}n,;10,\sqrt n ,;n

Show Answer
Answer: ((b))

100n,;10;,log2n,;n,;n\frac{{100}}{n},;10;,{\log _2}n,;\sqrt n ,;n

Given values are: 10 (a constant value)

√n (square root of a variable n which can take any value) n (a variable) log2n (logarithmic)

100n\frac{100}{n} (it divides 100 by a variable)

As we know that constant is smaller than a variable in case of asymptotic complexity because a variable can take any value smaller or larger. But when we compare 10 with 100n\frac{100}{n}, as 100 is divisible by n and if n goes to infinite than this value will become zero. So, 100n\frac{100}{n} is smaller than 10.

In the case of log2n growth rate is logarithmic which is smaller than linear growth.

Comparison between √n and n. Linear growth in case of n, it is larger than √n.

So, complete order is: 100n\frac{100}{n} < 10 < log2 n < √n < n                                                                                        

Alternated method:

Take n = 21024

10, 2102422^{\frac{1024}{2}}, 10021024\frac{100}{2^{1024}}, log2(21024), 21024

10, 2512, 10021024\frac{100}{2^{1024}}, 1024 × log22, 21024

10, 2512, 10021024\frac{100}{2^{1024}}, 1024, 21024

In terms of increasing order:

100/(21024) < 10 < 1024 < 2512< 21024

that is, 100n\frac{100}{n}< 10 < log2 n < n\sqrt n  < n

15

Consider the following table:

AlgorithmsDesign Paradigms
(P) Kruskal(i) Divide and Conquer
(Q) Quicksort(ii) Greedy
(R) Floyd-Warshall(iii) Dynamic Programming

 

Match the algorithms to the design paradigms they are based on.

  1. ((a))

    (P) ↔ (ii), (Q) ↔ (iii), (R) ↔ (i)

  2. ((b))

    (P) ↔ (iii), (Q) ↔ (i), (R) ↔ (ii) 

  3. ((c))

    (P) ↔ (ii), (Q) ↔ (i), (R) ↔ (iii) 

  4. ((d))

    (P) ↔ (i), (Q) ↔ (ii), (R) ↔ (iii) 

Show Answer
Answer: ((c))

(P) ↔ (ii), (Q) ↔ (i), (R) ↔ (iii) 

  • Quick Sort algorithm is based on divide and conquer approach in which a pivot is element is selected and array is partitioned based on that pivot element.
  • Kruskal algorithm is a minimum spanning tree algorithm in which in every iteration, minimum weighted edge is found and then it is added to the construction of minimum spanning tree. Edges are added in increasing order of the edge weights. That’s why it is a greedy approach.
  • Floyd Warshall algorithm is based on the principle of dynamic programming. It is used to solve the all pair shortest path problem.
16

Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are:

Note: The height of a tree with a single node is 0.

  1. ((a))

    4 and 15 respectively

  2. ((b))

    3 and 14 respectively

  3. ((c))

    4 and 14 respectively

  4. ((d))

    3 and 15 respectively

Show Answer
Answer: ((b))

3 and 14 respectively

Concepts:

Minimum height of the tree is when all the levels of BST are completely filled.

Maximum height of the binary search tree (BST) is the worst case when nodes are in skewed manner.

Formula:

Minimum height of the BST with n nodes is ⌈log2 (n + 1)⌉ - 1

Maximum height of the BST with n nodes is n - 1.

Calculation:

Maximum height of the BST with 15 nodes 15 - 1 = 14

Diagram:

Minimum height of the BST with n nodes is ⌈log2 (15 + 1)⌉ - 1 = 3

Diagram: 

17

The n-bit fixed-point representation of an unsigned real number X uses f bits for the fraction part. Let i = n - f. The range of decimal values for X in this representation is.

  1. ((a))

    2*-f* to 2*i*

  2. ((b))

    2*-f* to (2*i* - 2*-f*)

  3. ((c))

    0 to 2*i*

  4. ((d))

    0 to (2*i* - 2*-f*)

Show Answer
Answer: ((d))

0 to (2*i* - 2*-f*)

Diagram:

i represents an integral part of the and f represents the fractional part of the number.

Since, the n number is in unsigned representation, it's decimal value starts with 0. So Minimum value will be zero.

Range of unsigned representation is 0 to 2i - 1.

So, the mum value with i bits goes to 2i - 1.

Fraction of value is in the form of 2(-i). So, when we take the value of i = 1, 2, 3 … n this range of fractional value goes like, 2-1, 2-2, 2-3, …

So, it makes a GP series, with f bit maximum number possible is sum of GP series.

Consider a = ½, r = ½

Maximum value with f bits possible

= 12+14+18+116+132+\frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{{16}} + \frac{1}{{32}} + \ldots

= a×1rn1ra \times \frac{{1 - {r^n}}}{{1 - r}}

=12;1(12)f112;=12f;= \frac{1}{2};\frac{{1 - {{\left( {\frac{1}{2}} \right)}^f}}}{{1 - \frac{1}{2};}} = 1 - {2^{ - f}};

So, maximum fractional value possible

= maximum value with i bits + maximum value with f bits

= 2i - 1 + 1 - 2-f

= 2i - 2-f

So, require range will be 0 to 2i - 2-f.

18

Consider the C code fragment given below. typedef struct node {int data; node* next;} node;

void join (node* m, node* n) {node* p = n;

while (p- >next! = NULL) {

p = p - > next;

}

p - > next = m;

}

Assuming that m and n point to valid NULL-terminated linked lists, invocation of join will

  1. ((a))

    append list m to the end of list n for all inputs

  2. ((b))

    either cause a null pointer dereference or append list m to the end of list n

  3. ((c))

    cause a null pointer dereference for all inputs.

  4. ((d))

    append list n to the end of list m for all inputs

Show Answer
Answer: ((b))

either cause a null pointer dereference or append list m to the end of list n

It is not mentioned in the question that both the lists m and n are empty or not. So, consider two cases.

CASE 1:

When lists are not empty, so according to the code given, join will append list m to end of the list n.

Diagram

CASE 2:

When lists are empty but valid like this,

node *head;

head - > NULL;

p = head

p- > next! = NULL. So, it will create a NULL reference issue.

So, answer will be either cause a null pointer dereference or append list m to the list n.

19

When two 8-bit numbers A7 … A0 and B7 … B0 in 2’ s complement representation (with A0 and B0 as the least significant bits) are added using a ripple-carry adder, the sum bits obtained are S7 … S0 and the carry bits are C7 … C0. An overflow is said to have occurred if

  1. ((a))

    the carry bit C7 is 1

  2. ((b))

    all the carry bits (C7 …, C0) are 1

  3. ((c))

    (A7.B7.S̅7 + A̅ 7.B̅ 7.S7) is 1

  4. ((d))

    (A0.B0.S̅0 + A̅0.B̅0.S0) is 1

Show Answer
Answer: ((c))

(A7.B7.S̅7 + A̅ 7.B̅ 7.S7) is 1

Overflow is a condition that indicates that the result is too large or too small to fit in the original data type.

Here given 2’s complement representation means signed bit representation.

Two key points that must remember in a signed operation:

  1. MSB is used to indicate the sign of the number.
  2. For negative numbers, 2’s complement representation is used.

2’s complement overflow rules:

  • If the sum of two positive numbers gives a negative output, then the sum is overflowed.
  • If the sum of two negative numbers gives a positive output, then the sum is overflowed.
  • In other cases, the sum is not overflowed.

Overflow for the signed numbers occurs when the carry-in into the MSB (most significant bit) is not equal to carry out. Now according to the rules,

If both A7 and B7 are 1 then S7 must be 0. For this C7 will be 1 and C6 will be 0. Hence, it will give

C7.C6

If both A7 and B7 are 0 then S7 must be 1. For this C7 will be 0 and C6 will be 1. Hence, it will give

C7’.C6

When we combine these two, we get C7.C6’ + C7’.C6 (means C7 XOR C6) which is a condition to detect overflow. So, Option C is the answer.

Overflow is said to have occurred if:

(A7.B7.S̅7 + A̅ 7.B̅ 7.S7) is 1

20

Consider the following context-free grammar over the alphabet ∑ = {a, b, c} with S as the start symbol:

S → abScT | abcT

T → bT | b

Which one of the following represents the language generated by the above grammar?

  1. ((a))

    {(ab)n (cb)n | n ≥ 1}

  2. ((b))

    {(𝑎𝑏)𝑛 𝑐𝑏𝑚1 𝑐𝑏𝑚2 … 𝑐𝑏𝑚𝑛 |𝑛, 𝑚1, 𝑚2 … , 𝑚𝑛 ≥ 1}

  3. ((c))

    {(ab)n (cbm)n | m, n ≥ 1}

  4. ((d))

    {(ab)n (cbn)m | m, n ≥ 1}

Show Answer
Answer: ((b))

{(𝑎𝑏)𝑛 𝑐𝑏𝑚1 𝑐𝑏𝑚2 … 𝑐𝑏𝑚𝑛 |𝑛, 𝑚1, 𝑚2 … , 𝑚𝑛 ≥ 1}

String Derivation:

S → abScT

→ ababScTcT (∵ S → abScT)

→ abababcTcTcT (∵ S → abcT)

→ abababcbTcTcT (∵ T → bT)

→ abababcbbTcTcT (∵ T → bT)

→ abababcbbbTcTcT (∵ T → bT)

→ abababcbbbbcTcT (∵ T → b)

→ abababcbbbbcbcT (∵ T → b)

→ abababcbbbbcbcbT (∵ T → bT)

→ abababcbbbbcbcbb (∵ T → b)

abababcbbbbcbcbb = (ab)3cb4cbcb2

From this string, it is clear that all the option 1),3) and 4) are not generated by given grammar.

Only option 2 matches.

21

Consider the C struct defined below:

struct data {

     int marks [100];

     char grade;

     int cnumber;

};

struct data student;

The base address of student is available in register R1. The field student. grade can be accessed efficiently using

  1. ((a))

    Post-increment addressing mode, (R1) +

  2. ((b))

    Pre-decrement addressing mode, - (R1)

  3. ((c))

    Register direct addressing mode. R1

  4. ((d))

    Index addressing mode. X (R1). Where X is an offset represented in 2’s complement 16- bit representation.

Show Answer
Answer: ((d))

Index addressing mode. X (R1). Where X is an offset represented in 2’s complement 16- bit representation.

Concept:

The field student. Grade can be accessed efficiently using the base address of the student which is available in register R1.

Explanation:

Now, consider all the options one by one.

  • Post – increment addressing mode, (R1) +: In this, after accessing the operand, the content of the register are automatically incremented to point to next memory location, not to the desired student.grade memory location.
  • Pre – increment addressing mode, - (R1) : In this, before accessing the operand, the contents of the register are decremented to point to the previous consecutive memory location, not to the desired memory location.
  • Register direct addressing mode. R1: In this, location of the operand is a data register or an address register, memory location is itself embedded in the instruction code.
  • Index addressing mode: In index mode, the addition of base address and displacement index value gives the actual memory location. So, by adding constant (offset) value to the base address, we can easily access the student.grade.

Index addressing mode

22

Consider the following intermediate program in three address code:

p = a – b

q = p * c

p = u * v

q = p + q

Which one of the following corresponds to a static single assignment form of the above code?

  1. ((a))

    p1 = a - b

    q1 = p1 * c

    p1 = u * v

    q1 = p1 + q1

  2. ((b))

    p3 = a – b

    q4 = p3 * c

    p4 = u * v

    q5 = p4 ­+ q4

  3. ((c))

    p1 = a – b

    q1 = p2 * c

    p3 = u * v

    q2 = p4 + q

  4. ((d))

    p1 = a – b

    q1 = p * c

    p2 = u * v

    q2 = p + q

Show Answer
Answer: ((b))

p3 = a – b

q4 = p3 * c

p4 = u * v

q5 = p4 ­+ q4

Concept:

Rules in static single assignment form:

  • Each variable must be assigned exactly once.
  • Every variable must be defined before it is used.
  • All of the uses reached by the assignment must be renamed.

 

Explanation

Now consider, all the option one by one

Option 1:

It violated the rule 1 of static single assignment form. Because in this, p1 is assigned (initialized) two times: one in p1 = a – b and another in p1 = u * v

Option 3:

It violates the rule 2. Because in this case p2, p4 and q3 are not assigned any values. They are being used here without initializing.

Option 4:

It is invalid, because in last line p + q is directly added without moving into the register.

Option 2:

Follows all the rules of static single assignment form. So, this is the answer.

23

Consider the following C code:

#include <stdio.h>

int *assignval(int *x, int val) {

*x = val;

return x;

}

void main () {

int *x = malloc(sizeof(int));

if (NULL == x) return;

x = assignval (x, 0);

if (x) {

x = (int *) malloc (sizeof(int));

if(NULL == x) return;

x = assignval (x, 10);

}

printf(“%d\n”, *x);

free(x);

}

The code suffers from which one of the following problems:

  1. ((a))

    Compiler error as the return of malloc is not typecast appropriately

  2. ((b))

    Compiler error because the comparison should be made as x == NULL and not as shown

  3. ((c))

    Compiles successfully but execution may result in dangling pointer

  4. ((d))

    Compiles successfully but execution may result in memory leak

Show Answer
Answer: ((d))

Compiles successfully but execution may result in memory leak

Option 1:

As, it is a C program not a C++ program, so typecasting will de done automatically. There is no need to do typecasting. FALSE

Option 2:

Null means, memory location is 0. There is no difference between (x==NULL) and (NULL==x ), ( == ) is just to check the equality. FALSE

Option 3:

When the given code is compiled, it runs successfully, and x always points to a valid memory location and doesn’t result in dangling pointer.  FALSE

Option 4:

In the given code, x is assigned memory location two times. When memory location is assigned again to x, then the previous memory location gets lost and that results in memory leak problem. TRUE

Code Explanation:

void main () {

int *x = malloc(sizeof(int));    // Allocates memory to x i.e.   

if (NULL == x) return;                                                                              

x = assignval (x, 0);           // It calls the function *assignval ( int *x, int val ) and x gets the value 0.

if (x) {                                  // Condition becomes true, as x means address here

x = (int *) malloc (sizeof(int));           //Again allocates memory to x and previous memory get lost

if(NULL == x) return;                          // condition false as x means address not NULL

x = assignval (x, 10);                          // Again calls the function and x values becomes 10.

}

printf(“%d\n”, *x);                           // Print the value of x i.e. 10

24

Consider a TCP client and TCP server running on two different machines. After completing data transfer, the TCP client calls close to terminate the connection and a FIN segment is sent to the TCP server. Server-side TCP responds by sending an ACK, which is received by the client-side TCP. As per the TCP connection state diagram (RFC 793), in which state does the client-side TCP connection wait for the FIN from the server-side TCP?

  1. ((a))

    LAST - ACK

  2. ((b))

    TIME-WAIT

  3. ((c))

    FIN-WAIT-1

  4. ((d))

    FIN-WAIT-2

Show Answer
Answer: ((d))

FIN-WAIT-2

After completing the data transfer, the TCP client executes a close primitive, and a FIN segment is sent to the TCP server by the client and wait for the corresponding ACK from the server. After this, two cases will happen:

  1. When the ACK arrives from the server, a transition is made to state FIN-WAIT 2 by the client and then one direction of the connection will be closed. When other side closes too, a FIN comes in which is acknowledged and both sides will be closed.

  2. In second case, instead of getting ACK from server till the time-out, TCP client received FIN from server. Client will acknowledge this FIN and then it will move to the close state. TCP client will wait for the ACK for its own FIN from server. After receiving ACK, TCP client will move to the TIME-WAIT state.

Diagram:

25

A sender S sends a message m to receiver R, which is digitally signed by S with its private key. In this scenario. One or more of the following security violations can take place.

  1. S can launch a birthday attack to replace m with a fraudulent message.

  2. A third-party attacker can launch a birthday attack to replace m with a fraudulent message. 

  3. R can launch a birthday attack to replace m with a fraudulent message.

Which of the following are possible security violations?

  1. ((a))

    1 and 2 only

  2. ((b))

    1 only

  3. ((c))

    2 only

  4. ((d))

    2 and 3 only

Show Answer
Answer: ((b))

1 only

Concept:

Birthday attack means sending a fraudulent message with the same has value and digitally signed as that of original message.

Two ways are there for using digital signature:

One is, in which whole message will be encrypted first using sender’s private key and then receiver’s public key.

Second is, when only message digest is encrypted using sender’s private key.

Explanation:

Consider all the violations one by one:

  1. S can launch a birthday attack to replace m with a fraudulent message. TRUE

 In this, S can use some fraudulent message and then encrypt it with its private key and then receiver’s public key.

  1. A third-party attacker can launch a birthday attack to replace m with a fraudulent message.  FALSE

Third party attacker can’t launch birthday attack, as it doesn’t have sender’s private key and then can’t encrypt the message.

  1. R can launch a birthday attack to replace m with a fraudulent message. FALSE

R can’t launch the birthday attack, because it doesn’t have the sender’s (S) private key and thereby can’t encrypt the message.

26

The following functional dependencies hold true for the relational schema R{V, W, X, Y, Z}:

V → W

VW → X

Y → VX

Y → Z

Which of the following is irreducible equivalent for this set of functional dependencies?

  1. ((a))

    V → W

    V → X

    Y → V

    Y → Z

  2. ((b))

    V → W

    W → X

    Y → V

    Y → Z

  3. ((c))

    V → W

    V → X

    Y → V

    Y → X

    Y → Z

  4. ((d))

    V → W

    W → X

    Y → V

    Y → X

    Y → Z

Show Answer
Answer: ((a))

V → W

V → X

Y → V

Y → Z

Concept: 

To find the irreducible equivalent of the given functional dependencies, we need to find the minimal cover set for these functional dependencies by removing all the left extraneous attributes and extra dependencies.

Explanation

V → W

VW → X

Y → VX

Y → Z

Consider,

V → W (As this is a single dependency that must be required, no need to remove)

VW → X ( In this, we have to delete the left extra attribute, for this we need to find the V+  and W+ from original dependencies, Now doing V+ if in V+ we get a W, then we can remove W attribute otherwise not same in case of W+)

So here, V+ = {V W X} and W+ = {W}

So, W → X can be removed from these functional dependencies.

Y → VX (Y → X can be find out using Y → V, V → X)

So, the irreducible equivalent of the given functional dependencies is:

V → W

V → X

Y → V

Y → Z

27

Consider the following grammar:

P → xQRS Q → yz |z R → w | ε S → y
<br>

What is FOLLOW(Q)?

  1. ((a))

    {R}

  2. ((b))

    {w}

  3. ((c))

    {w, y}

  4. ((d))

    {w $}

Show Answer
Answer: ((c))

{w, y}

Concept:

Follow(X) is the set of terminals that can appear immediately to the right of non-terminal X in some sentential form. Rules for finding the follow (X) are given here as:

1) Follow (S) = {$}, where S is the start symbol.

  1. If A → bBC is the production, where b, B and C are grammar symbols, then Follow (B) is first (C).

  2. If A → bB is production then follow (B) is follow (A).

  3. If A → bBC is production and first(c) contains ε, then follow (B) contains {first (C) - ε} U follow (A).

Explanation:

Follow (Q) = First (RS) = {w, ε} = {w}, First (S) = {w, y}

Diagram:

28

Threads of a process share.

  1. ((a))

    Global variables but not heap.

  2. ((b))

    Heap but not global variables.

  3. ((c))

    Neither Global variables nor heap.

  4. ((d))

    Both heap and global variables.

Show Answer
Answer: ((d))

Both heap and global variables.

Concepts:

Multiple threads of the same process share other resources of process except register, stack and stack pointer.

A process is generally considered to consist of a set of threads sharing an address space, heap, static data, code segments and file descriptors.

Diagram:

29

Let X be a Gaussian random variable with mean 0 and variance σ2. Let Y = max(X, 0) where max(a, b) is the maximum of a and b. The median of Y is ______.

30

Let T be a tree with 10 vertices. The sum of the degrees of all the vertices in T is _________.

31

Consider the Karnaugh map given below. Where X represents “don’t care” and blank represents 0.

Assume for all inputs (a, b, c, d), the respective complements (a̅, b̅, c̅, d̅) are also available. The above logic is implemented using 2-input NOR gates only. The minimum number of gates required is ________.

32

Consider the language L given by the regular expression (a + b)* b (a + b) over the alphabet {a, b}. The smallest number of states needed in a deterministic finite-state automaton (DFA) accepting L is ________.

33

Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.

EMP
EmpIdEmpNameDeptName
1XYAAA
2XYBAA
3XYCAA
4XYDAA
5XYEAB
6XYFAB
7XYGAB
8XYHAC
9XYIAC
10SYJAC
11XYKAD
12XYLAD
13XYMAE
<br>

 

SELECT AVG(EC.Num FROM EC WHERE(DeptName, Num) IN (SELECTED DeptName, COUNT(EmpId)AS EC(DeptName, Num) FROM EMP GROUP BY DeptName)

 

The output of executing the SQL query is _________.

34

Consider the following CPU processes with arrival times (in milliseconds) and length of CPU bursts (in milliseconds) as given below:

ProcessArrival timeBurst time
P107
P233
P355
P462

 

If the pre-emptive shortest remaining time first scheduling algorithm is used to schedule the processes. Then the average waiting time across all processes is ________ milliseconds.

35

Consider a two-level cache hierarchy with L1 and L2 cashes. An application incurs 1.4 memory accesses per instruction on average. For this application, the miss rate of L1 cache is 0.1: the L2 cache experiences. On average, 7 misses per 1000 instructions. The miss rate of L2 expressed correct to two decimal places is ________.

36

Let G = (V, E) be any connected undirected edge-weighted graph. The weights of the edges in E are positive and distinct. Consider the following statements:

I) Minimum Spanning Tree of G is always unique.

II) Shortest path between any two vertices of G is always unique.

Which of the above statements is/are necessarily true?

  1. ((a))

    I only

  2. ((b))

    II only

  3. ((c))

    Both I and II

  4. ((d))

    Neither I nor II

Show Answer
Answer: ((a))

I only

Concept:

A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges(V – 1 ) of a connected, edge-weighted undirected graph G(V, E) that connects all the vertices together, without any cycles and with the minimum possible total edge weight.

Example:

Graph G(V, E)

G(V, V – 1) → minimum spanning tree

If edge weights are distinct then there exist unique MST.

Hence Statement I is correct.

When edge weights are distinct and positive in that case shortest path between any two vertices of the graph is not always unique. Shortest path can be different even if the edge weights are unique.

Example:

Distance between A → C (3) and A → B → C (1 + 2 = 3), both paths has same distance.

Hence statement II is incorrect.

37

A multithreaded program P executes with x number of threads used y number of locks for ensuring mutual exclusion while operating on shared memory locations. All locks in the program are non-re-entrant. i.e. if a thread holds a lock l, then it cannot re-acquire lock l without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum value of x and the minimum value of y together for which execution of p can result in a deadlock are:

  1. ((a))

    x = 1, y = 2

  2. ((b))

    x = 2, y k = 1

  3. ((c))

    x = 2, y = 2

  4. ((d))

    x = 1, y = 1

Show Answer
Answer: ((d))

x = 1, y = 1

Concept:

Re-entrant locks: It allows a thread to reacquire the lock multiple times without blocking on itself. It prevents the thread from the situation of deadlock.

Non- re-entrant locks: It don’t allow a thread to re-acquire the lock. Same process cannot acquire the lock multiple times without releasing it. So, here situation of deadlock occurs.

Explanation:

Three key points to be considered for this:

  1. It is asking about minimum value of x and y

  2. Locks are non-re-entrant (recursive)

  3. Programs gets block if another lock is unavailable

Now, question is asking about the minimum value of x and y for which execution of p can result in a deadlock. So, minimum value of x and y are 1 and 1. Only one thread and one lock can cause deadlock, if the thread tries to reacquire the lock. If there are more than one lock available in the system, then process/thread can acquire the lock to do the further execution.

38

The value of limx1x72x5+1x33x2+2\mathop {\lim }\limits_{x \to 1} \frac{{{x^7} - 2{x^5} + 1}}{{{x^3} - 3{x^2} + 2}}

  1. ((a))

    is 0

  2. ((b))

    is -1

  3. ((c))

    is 1

  4. ((d))

    does not exist

Show Answer
Answer: ((c))

is 1

Concept:

Substitute the value of x as 1 in given function, if it results in 00\frac{0}{0} form, then use L’Hospital rule for this.

In L’Hospital rule, both then numerator and denominator are differentiated.

Calculation: 

limx1x72x5+1x33x2+2=00\mathop {\lim }\limits_{x \to 1} \frac{{{x^7} - 2{x^5} + 1}}{{{x^3} - 3{x^2} + 2}} = \frac{0}{0}

Apply L’Hospital rule,

limx17x610x43x26x;\mathop {\lim }\limits_{{\rm{x}} \to 1} \frac{{7{{\rm{x}}^6} - 10{{\rm{x}}^4}}}{{3{{\rm{x}}^2} - 6{\rm{x}}}}{\rm{;}}

limx17(1)610(1)4;3(1)26(1)=1\mathop {\lim }\limits_{{\rm{x}} \to 1} \frac{{7{{\left( 1 \right)}^6} - 10{{\left( 1 \right)}^4}{\rm{;}}}}{{3{{\left( 1 \right)}^2} - 6\left( 1 \right)}} = 1

39

Let p, q, and r be propositions and the expression (p → q) → r be a contradiction. Then the expression (r → p) → q is

  1. ((a))

    A tautology

  2. ((b))

    A contradiction.

  3. ((c))

    Always TRUE when p is FALSE

  4. ((d))

    Always TRUE when q is TRUE

Show Answer
Answer: ((d))

Always TRUE when q is TRUE

(p → q) → r is a contradiction which is possible only when r is false and (p → q) is true.

Now, from here we can clearly say that option 4 is correct as (r → p) → q means ¬ (r → p) ∨ q.

Since r is false, (r → p) is true and ¬ (r → p) becomes false.

So, it becomes (false ∨ q). Now it totally depends on q. Whenever q is true, this value will always be true.

Alternate Method:

Let X ≡ p → q, Y ≡ (p → q) → r ≡ X → r,

Z ≡ r → p and W ≡ (r → p) → q ≡ Z → p

Using Truth table

pqrXYZW
0001010
0011101
0101011
0111101
1000110
1010110
1101011
1111111

 

So, from truth table also, it is clear that (r → p) → q is always true when q is true, and Y is false.

40

Let u and v be two vectors in R2 whose Euclidean norms satisfy u=2v.\parallel u\parallel = 2\parallel v\parallel . What is the value of α such that w = u + αv bisects the angle between u and v?

  1. ((a))

    2

  2. ((b))

    1

  3. ((c))

    1/2

  4. ((d))

    -1/2

Show Answer
Answer: ((a))

2

Concept: 

The resultant of two equal vectors bisects the angle between them.

Explanation: 

w = u + αv (given)

where u and v are two vectors

Here, we can say that w is the resultant of two vectors u and αv. For w, to bisect the angle between u and v, magnitude of two vectors must be same.

u=2v\parallel u\parallel = 2\parallel v\parallel , [Given]

Also,              

u=αv\parallel u\parallel = {\rm{\alpha }}\parallel v\parallel , i.e. 2v=;αv2\parallel v\parallel = ;{\rm{\alpha }}\parallel v\parallel

∴ α = 2.

Alternate Method:

By using graph method.

From here, u = 0 x + 2 y

v = 1 x + 0 y [Because, u=2v\parallel u\parallel = 2\parallel v\parallel ]

It is given that, w = u + αv

Put value of u and v in w.

w = (0x + 2y) + α (1x + 0y)

= α.x + 2y

Now, vector w bisects the angle between u and v only when magnitude of along both the directions is same.

i.e. α should be 2.

41

Let A be (n x n) real valued square symmetric matrix of rank 2 with \(\mathop \sum \limits_{i = 1}^n \mathop \sum \limits_{j = 1}^n A_{ij}^2 = 50\). Consider the following statements.

(I) One eigenvalue must be in [–5, 5]

(II) The eigenvalue with the largest magnitude must be strictly greater than 5

Which of the above statements about eigenvalues of A is/are necessarily CORRECT?

  1. ((a))

    Both I and II

  2. ((b))

    I only

  3. ((c))

    II only

  4. ((d))

    Neither I nor II

Show Answer
Answer: ((b))

I only

Try to find out the eigen values by taking the example of matrix with rank 2. Then check if given statement follows from that or not.

Calculation:

A be (n x n) real valued square symmetric matrix of rank 2.

\(\mathop \sum \limits_{i = 1}^n \mathop \sum \limits_{j = 1}^n A_{ij}^2 = 50\),

which means, sum of square of all elements of A = 50.

Also, rank of A = 2 i.e. we have (n – 2) eigen values are 0.

So eigen values are in the form of a1, a2,0, 0, ……

Let us consider a matrix A = \(\left[ {\begin{array}{*{20}{c}} { - 5}&0\ 0&5 \end{array}} \right]\)

Here, for this eigen values are [-5, 5].

Take another example, B = \(\left[ {\begin{array}{{20}{c}} 5&0&0\ 0&5&0\ 0&0&0 \end{array}} \right]\) and C = \(\left[ {\begin{array}{{20}{c}} 6&0&0\ 0&{\surd 14}&0\ 0&0&0 \end{array}} \right]\)

Matrix B and C are of rank 2 and symmetric.

Eigen value for A = 5, 5, 0

And eigen value for B = 6,;14,;06,;\sqrt {14} ,;0

As 0 and 5 are in the range of [-5, 5], So statement 1 is correct.

But eigen value with largest magnitude which is 6 for C must be strictly greater than 5 and in case of B largest value is 5 which is not strictly greater than 5, So, second statement is incorrect here.

42

A computer network uses polynomials over GF (2) for error checking with 8 bits as information bits and uses x3 +x +1 as the generator polynomial to generate the check bits. In this network. The message 01011011 is transmitted as

  1. ((a))

    01011011010

  2. ((b))

    01011011011

  3. ((c))

    01011011101

  4. ((d))

    01011011100

Show Answer
Answer: ((c))

01011011101

STEP:

Append no. of 0’s equal to the degree of the generator polynomial to the original data and then divide the message with the generator polynomial. Remainder obtained from this will be added with the original message and transmitted as CRC.

Calculation:

Generator is given as x3 +x +1

Degree of the generator is 3.

So, 3 0’s is added to the data and new data will be 01011011000 and it is divided by 1011.

Diagram

Here remainder is 101. Append this to the original message. The message will become 01011011101. So, the original message 01011011 will be transmitted as 01011011101.

43

Consider a combination of T and D flip-flops connected as shown below. The output of the D flip-flop is connected to the T flip-flop and the output of the T flip-flop is connected to the input of the D flip-flop.

Initially, both Q0 and Q1 are set to 1 (before the 1st clock cycle). The outputs

  1. ((a))

    Q1 Q0 after the 3rd cycle are 11 and after the 4th cycle are 00 respectively

  2. ((b))

    Q1 Q0 after the 3rd cycle are 11 and after the 4th cycle are 01 respectively

  3. ((c))

    Q1 Q0 after the 3rd cycle are 00 and after the 4th cycle are 11 respectively

  4. ((d))

    Q1 Q0 after the 3rd cycle are 01 and after the 4th cycle are 01 respectively

Show Answer
Answer: ((b))

Q1 Q0 after the 3rd cycle are 11 and after the 4th cycle are 01 respectively

Output of one flip- flop becomes the input of another flip- flop. Two flip flops are given T and D flip flop. We can solve it using the characteristic equation of D and T flip flop and then calculate the next states Q1N and Q0N.

Explanation:

Here, T flip flop output is denoted by Q1 and D flip flop output by Q0.

Output of D flip flop i.e. Q0 is coming at the T flip flop and Q1 is going to D flip flop as input.

So, Q1N = Q1 EXOR T = Q1 EXOR Q0

       Q0N = D = Q1

Initially, Q0 = Q1 = 1

Next State Table:

Clock CycleQ1Q0Q1NQ0N
11101
20110
31011
41101

 

So, Q1Q0 after 3rd clock cycle is 11 and Q1Q0 after 4th clock cycle is 01.

44

If G is a grammar with productions

S → SaS | aSb | bSa | SS | ∈

Where S is the start variable. Then which one of the following strings in not generated by G?

  1. ((a))

    abab

  2. ((b))

    aaab

  3. ((c))

    abbaa

  4. ((d))

    babba

Show Answer
Answer: ((d))

babba

STEP:

Consider all the strings, then check if they can be generated from given grammar or not.

Derivation:

Grammar Production: S → SaS | aSb | bSa | SS | ∈

Option 1: String: abab

S → aSb

S → abSab 

S → ab∈ab

S → abab

So, abab can be generated by the given grammar.

Option 2: String: aaab

S → SS

S → SaSS 

S → SaSaSS 

S → aaaSbS 

S → aaa∈bS 

S → aaa∈b∈ 

S → aaab

Option 3: String:  abbaa

S → SS

S → aSbS 

S → a∈bS 

S → abbSa  

S → abbSaSa 

S → abb∈aSa

S → abba∈a

S → abbaa  

All three abab, aaab and abbaa are generated by the given grammar.

Only babba can’t be generated. So, option 4) is the answer.

45

Consider the following two functions.

void fun1 (int n) {

if (n == 0) return;

printf(“%d”, n);

fun2(n – 2);

printf (“%d”, n);

}

void fun2(int n) {

if (n == 0) return;

printf (“%d”, n);

fun1(++n);

printf(“%d”, n);

}

The output printed when fun1 (5) is called is

  1. ((a))

    53423122233445

  2. ((b))

    53423120112233

  3. ((c))

    53423122132435

  4. ((d))

    53423120213243

Show Answer
Answer: ((a))

53423122233445

STEP:

This problem can be solved using tree approach. Make a tree as the function call arrives, then traverse the tree from top to bottom and left to right.

Diagram:

So, output printed when fun1(5) is called is 53423122233445.

46

Consider the C functions foo and bar given below:

Int foo (int val) {

int x = 0;

while (val  > 0)

x = x + foo (val --);

}

return val;

}

int bar (int val) {

int x = 0;

while (val > 0) {

x = x + bar (val – 1);

}

return val;

}

Invocations of foo (3) and bar (3) will result in:

  1. ((a))

    Return of 6 and 6 respectively.

  2. ((b))

    Infinite loop and abnormal termination respectively.

  3. ((c))

    Abnormal termination and infinite loop respectively.

  4. ((d))

    Both terminating abnormally.

Show Answer
Answer: ((c))

Abnormal termination and infinite loop respectively.

CASE 1:

Here, when foo(3) is called, this block is executed.

Int foo (int val) {     // val is 3 here

int x = 0;

while (val  > 0)        // condition becomes true as (3 > 0)

x = x + foo (val --); 

}

return val;

}

Here, foo (val - -) is equivalent to

  1. foo(val )

  2. val = val -1

val is post decremented, here it will not change the value of val during the function call. So, it will call foo(3) again and again. So, foo (3) is called infinite number of times causes abnormal termination.

Key point

In foo (3) , there is no problem of infinite loop. Because val is decrementing here.

CASE 2:

When bar (3) is called, block that is executed is,

int bar (int val) {               // val become 3

int x = 0;

while (val > 0) {            // condition becomes true as (3 > 0)

x = x + bar (val – 1);                     //here it will call bar (2)

}

return val;

}

 

So, in this case val is not not decremented in the loop only it is decrementing during the function call. i.e

bar (3) is called, then bar (2), then bar (1), then bar (0), again bar (0) …

bar(0) will return 0.

But while (val > 0) // this condition will always become true. As val value remain the same throughout.

So, Infinite loop problem occurs here in this case.

47

Consider the context-free grammars over the alphabet {a, b, c} given below. S and T are non-terminals.

G1: S → aSb | T, T → cT | ∈

G2: S   → bSa | T, T  → cT | ∈

The language L(G1) ∩ L(G2) is

  1. ((a))

    Finite

  2. ((b))

    Not finite but regular

  3. ((c))

    Context-Free but not regular

  4. ((d))

    Recursive but not context-free

Show Answer
Answer: ((b))

Not finite but regular

Grammar G1 is:  S → aSb | T, T → cT | ∈

Grammar G2 is:  S   → bSa | T, T → cT | ∈

Language generated by grammar G1 is in the form of acb* + ∈

Language generated by grammar G2 is in the form of bca* + ∈

We have to find the intersection of L (G1) and L (G2)

So, only common production from two grammar G1 and G2 is:

S → T

T → cT | ∈

This will result in the language c*.  [Because, it generates string like ∈, c, cc, ccc, cccc, ………]

As, c* is a regular and infinite language. So, option 2) is the answer.

48

Consider the following languages over the alphabet ∑ = {a, b, c}

Let L1 = {an bn cm | m, n ≥ 0} and L2 = {am bn cn | m, n ≥ 0}

Which of the following are context-free languages?

I. L1 ∪ L2

II. L1 ∩ L2

  1. ((a))

    I only

  2. ((b))

    II only

  3. ((c))

    I and II

  4. ((d))

    Neither I nor II

Show Answer
Answer: ((a))

I only

CFL Properties:

  1. Union of two context free languages is context free.

  2. Intersection of two context free languages may or may not be context free.

L1 = {an bn cm | m, n ≥ 0}

This language is DCFL and hence CFL.  As number of a’s are equal to number of b’s in this. Hence, only one stack is needed.

L2 = { am bn cn | m, n ≥ 0}

This language is also DCFL and hence CFL also. In this, number of b’s are equal to number of c’s, so, one stack is needed for this.

Now, from properties of CFL it is clear that union of two CFL is CFL.

So, statement 1 is correct

Statement 2 is correct.

 intersection of two CFL may or may not be CFL.

For, L1 ∩ L2, we require two stacks, which becomes the case of context sensitive language. L1 ∩ L2 is not a CFL. So, option 2) is incorrect.

49

Let A and B be finite alphabets and let # be a symbol outside both A and B. Let f be a total function from A* to B*. We say f is computable if there exists a Turing machine M which given an input x in A*. always halts with f(x) on its tape. Let Lf denote the language {x # f(x) |x ∈ A*}. Which of the following statements is true:

  1. ((a))

    f is computable if and only if Lf is recursive.

  2. ((b))

    f is computable if and only if Lf is recursively enumerable.

  3. ((c))

    If f is computable then Lf is recursive. But not conversely.

  4. ((d))

    If f is computable then Lf is recursively enumerable, but not conversely.

Show Answer
Answer: ((a))

f is computable if and only if Lf is recursive.

Here, question is asking about the reason behind f is computable.

Since, x belongs to A* is a total function, that’s why every alphabet in x yields some alphabet in B* (same as f(x)) if given to a turing machine. In given statement, it is mentioned that f is computable only if there exists a Turing machine M which always halts with f(x) output. It means language that has to be always halting and accepting by Turing machine must be recursive language.

Therefore option 1 is the answer.

Important Points:

Second option is not true because recursive language has the membership property which proves that f is computable while in case of recursive enumerable languages, membership property is not available.

50

Recall that Belady’s anomaly is that the page-fault rate may increase as the number of allocated frames increases. Now, consider the following statements:

S1: Random page replacement algorithm (where a page chosen at random is replaced)

Suffers from Belady’s anomaly

S2: LRU page replacement algorithm suffers from Belady’s anomaly

Which of the following is CORRECT?

  1. ((a))

    S1 is true, S2 is true

  2. ((b))

    S1 is true, S2 is false

  3. ((c))

    S1 is false, S2 is true

  4. ((d))

    S1 is false, S2 is false

Show Answer
Answer: ((b))

S1 is true, S2 is false

Concepts:

Belady’s anomaly is that the page-fault rate may increase as the number of allocated frames increases.

Explanation:

S1: Random page replacement algorithm (where a page chosen at random is replaced)

Suffers from Belady’s anomaly.

Random page replacement algorithm can behave like any replacement algorithm. It may behave as FIFO, LRU, MRU etc.). When random page replacement algorithm behaves like a FIFO page replacement algorithm in that case there can be chances of belady’s anamoly.

For this let us consider an example of FIFO case, if we consider the reference string 3  2 1 0 3 2 4 3 2 1 0 4 and 3 frame slots, in this we get 9 page fault but if we increase slots to 4, then we get 10 page faults.

So, page faults are increasing by increasing the number of frame slots. It suffers from belady’s anamoly.

S2: LRU page replacement algorithm suffers from Belady’s anomaly

It doesn’t suffers from page replacement algorithm because in LRU, the page which is least recently used is replaced by the new page. Also, LRU Is a stack algorithm. (A stack algorithm is one that satisfies the inclusion property.) and stack algorithm doesn’t suffer from belady’s anamoly.

51

Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId) Note that the deptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus.

(I) { t |∃u ∈ EMP(tEmpName] = u[EmpName] ∧ ∀ v∈ DEPT(t[DeptId] ≠ v[DeptId]))}

(II) {t |∃ u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] ≠ v[DeptId]))}

(III) {t | ∃ u∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] = v[DeptId]))}

Which of the above queries are safe?

  1. ((a))

    (I) and (II) only

  2. ((b))

    (I) and (III) only

  3. ((c))

    (II) and (III) only

  4. ((d))

    (I), (II) and (III)

Show Answer
Answer: ((d))

(I), (II) and (III)

Concept:

Safe tuple expression is the one that guaranteed to yield a finite number of tuples as its results. Otherwise, it is called unsafe.

Explanation:

∀ = for all

∃ = There exist / some

Consider the options one by one

Option 1:

 {t |∃u ∈ EMP(tEmpName] = u[EmpName] ∧ ∀ v∈ DEPT(t[DeptId] ≠ v[DeptId]))}

It gives all the name of employees who do not belong to the any department. Before ∧ operator, it results in finite tuples, after ∧ it results in infinite number of tuples. Finite ∧ infinite results in finite number of tuples. So, it is safe expression

Option 2:

{t |∃ u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] ≠ v[DeptId]))}

It gives the employee names who do not belong to some department. Before ∧ it is finite, after ∧ it is infinite. Results in a finite number of tuples. So, it is safe expression.

Option 3:

{t | ∃ u∈ EMP(t[EmpName] = u[EmpName] ∧ ∃ v ∈ DEPT(t[DeptId] = v[DeptId]))}

This expression gives the name of employees who belongs to atleast one same department. It also results in a finite expression. So, it is safe expression.

All three are safe expressions.

52

In a database system, unique timestamps are assigned to each transaction using Lamport’s logical clock. Let TS(T1) and TS(T2) be the timestamps of transactions T1 and T2 respectively. Besides, T1 holds a lock on the resource R, and T2 has requested a conflicting lock on the same resource R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp.

If TS(T2) < TS(T1) then

T1 is killed

else T2 waits.

Assume any transaction that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?

  1. ((a))

    The database system is both deadlock-free and starvation-free.

  2. ((b))

    The database system is deadlock-free but not starvation-free.

  3. ((c))

    The database system is starvation-free, but not deadlock-free.

  4. ((d))

    The database system is neither deadlock-free nor starvation-free.

Show Answer
Answer: ((a))

The database system is both deadlock-free and starvation-free.

Concept:

Wound – wait scheme means the newer transactions are killed when an older transaction make a request for a lock being held by newer transaction.

Explanation:

Here, Unique timestamps are assigned to each transaction using Lamport’s logical clock.

  1. Now, first check if is it wound – wait scheme?

If TS(T2) < TS(T1) then

T1 is killed

else T2 waits.

This logic comes under wound – wait scheme, because it is given that T1 holds a lock on the resource R and T2 has requested a lock on same resource R. When T2 requests, T1 is killed because timestamp of T1 ­is larger than T2 means T1 is the newer transaction.

  1. Now, wound – wait avoid starvation or not?

As newer transaction dies and restart with same timestamp and older one survives so after older transaction new will definitely execute. It means no possibility of starvation.

  1. Deadlock free or not?

As, there is no starvation in this means no deadlock possibility.

53

Consider the following grammar:

stmt → if expr then expr else expr; stmt | ȯ

expr → term relop term | term

term → id | number

id → a | b | c

number → [0 – 9]

where relop is a relational operator (e.g ., < , >, …), ȯ refers to the empty statement, and if, then, else are terminals.

Consider a program P following the above grammar containing ten if terminals. The number of control flow paths in P is _______. For example. The program.

if e1 then e2 else e3

has 2 control flow paths, e1 e2 and e1 e3

54

In an RSA cryptosystem, a participant A uses two prime numbers p = 13 and q = 17 to generate her public and private keys. If the public key of A is 35, then the private key of A is ______.

55

The values of parameters for the Stop-and-Wait ARQ protocol are as given below:

Bit rate of the transmission channel = 1 Mbps.

Propagation delay from sender to receiver = 0.75 ms.

Time to process a frame = 0.25 ms.

Number of bytes in the information frame = 1980

Number of bytes in the acknowledge frame = 20

Number of overhead bytes in the information frame = 20

Assume that there are no transmission errors. Then. The transmission efficiency (expressed in percentage) of the stop-and – Wait ARQ [protocol for the above parameters in _____ (correct to 2 decimal places).

56

Consider a database that has the relation schema CR(StudentName. CourseName). An instance of the schema CR is as given below.

CR
Student NameCourse Name
SACA
SACB
SACC
SBCB
SBCC
SCCA
SCCB
SCCC
SDCA
SDCB
SDCC
SDCD
SECD
SECA
SECB
SFCA
SFCB
SFCC

 

The following query is made on the database.

T1 ← πCourseNaneStudentName=’SA’(CR))

T2 ← CR ÷ T1

The number of rows in T2 is _______.

57

The number of integers between 1 and 500 (both inclusive) that are divisible by 3 or 5 or 7 is ______.

58

Let A be an array of 31 numbers consisting of a sequence of 0’s followed by a sequence of 1’s. The problem is to find the smallest index i such that A[i] is 1 by probing the minimum number of locations in A. The worst-case number of probes performed by an optimal algorithm is _____.

59

Consider a RISC machine where each instruction is exactly 4 bytes long. Conditional and unconditional branch instructions use PC-relative addressing mode with Offset specified in bytes to the target location of the branch instruction. Further the Offset is always with respect to the address of the next instruction in the program sequence. Consider the following instruction sequence.

\(\begin{array}{*{20}{c}} {\underline {Instr.;No.} }&{}&{}&{\underline {Instruction} }\ i&:&{add}&{R2,;R3,R4}\ {i + 1}&:&{sub}&{R5,R6,R7}\ {i + 2}&:&{cmp}&{R1,R9,R10}\ {i + 3}&:&{beq}&{R1,;;;Offset} \end{array}\)

If the target of the branch instruction is i, then the decimal value of the Offset is _____.

60

Instruction execution in a processor is divided into 5 stages, Instruction Fetch (IF), Instruction Decode (ID), Operand Fetch (OF), Execute (EX), and Write Back (WB). These stages take 5, 4, 20, 10, and 3 nanoseconds (ns) respectively. A pipelined implementation of the processor requires buffering between each pair of consecutive stages with a delay of 2 ns. Two pipelined implementations of the processor are contemplated:

i) a naïve pipeline implementation (NP) with 5 stages and

ii) an efficient pipeline (ER) where the OF stage is divided into stages OF1 and OF2 with execution times of 12ns and 8ns respectively.

The speedup (correct to two decimal places) achieved by EP over NP in executing 20 independent instructions with no hazards in _______.

61

Consider a 2- way set associative cache with 256 blocks and uses LRU replacement. Initially the cache is empty. Conflict misses are those misses which occur due to contention of multiple blocks for the same cache set. Compulsory misses occur due to first time access to the block. The following sequence of accesses to memory blocks.

(0, 128, 256, 128, 0, 128, 256, 128, 1, 129, 257, 129, 1, 129, 257, 129)

Is repeated 10 times. The number of conflict misses experienced by the cache is _____.

62

Consider the expression (a – 1) * (((b + c) / 3) + d). Let X be the minimum number of registers required by an optimal code generation (without any register spill) algorithm for a load/store architecture, in which (i) only load and store instructions can have memory operands and (ii) arithmetic instructions can have only register or immediate operands. The value of X is _____.

63

Consider the following C program.

#include <stdio.h>

#include <string.h>

void printlength (char *s, char *t) {

unsingned int c = 0;

int len = ((strlen(S) – strlen(t)) > c) ? strlen(S) : strlen(t); printf(“%d\n”, len);

}

void main () {

char *x = “abc”;

char *y = “defgh”;

printlenght (x, y);

}

Recall that strlen is defined in string. h as returning a value of type size_t, which is an unsigned int. the output of the program is ______.

64

A cache memory unit with capacity of N words and block size of B words is to be designed. If it is designed as a direct mapped cache, the length of the TAG field is 10 bits. If the cache unit is now designed as 16-way set-associative cache, the length of the TAG field is _______ bits.

65

The output of executing the following C program is ________.

#include <stdio.h>

int total (int v) {

static int count = 0;

while (v) {

count += v &1;

v >>= 1;

}

return count;

}

int main() {

static int x = 0;

int i=5;

for(; i > 0; i--) {

x = x + total(i);

}

printf("%d\n", x);

}

Attempt this paper under real exam conditions

Timed interface, section switching, instant scoring, and question-by-question analytics — free.

Start Timed Attempt