Question 1 |

The output of following C program is

#include <stdio.h> char str1[100]; char *fun(char str[]) { static int i = 0; if (*str) { fun(str+1); str1[i] = *str; i++; } return str1; } int main() { char str[] = "GATE CS 2015 Mock Test"; printf("%s", fun(str)); return 0; }

GATE CS 2015 Mock Test | |

tseT kcoM 5102 SC ETAG
| |

Nothing is printed on screen | |

Segmentation Fault |

**String**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 1 Explanation:

The function basically reverses the given string.

Question 2 |

Consider the following two problems of graph.

**1)**Given a graph, find if the graph has a cycle that visits every vertex exactly once except the first visited vertex which must be visited again to complete the cycle.**2)**Given a graph, find if the graph has a cycle that visits every edge exactly once. Which of the following is true about above two problems.Problem 1 belongs NP Complete set and 2 belongs to P | |

Problem 1 belongs to P set and 2 belongs to NP Complete set | |

Both problems belong to P set | |

Both problems belong to NP complete set |

**NP Complete**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 2 Explanation:

Problem 1 is Hamiltonian Cycle problem which is a famous NP Complete problem.
Problem 2 is Euler Circuit problem which is solvable in Polynomial time.

Question 3 |

Routers forward a packet using forwarding table entries. The network address of incoming packet may match multiple entries. How routers resolve this?

Forward it the the router whose entry matches with the longest prefix of incoming packet | |

Forward the packet to all routers whose network addresses match. | |

Discard the packet. | |

Forward it the the router whose entry matches with the longest suffix of incoming packet |

**Network Layer**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 3 Explanation:

The network addresses of different entries may overlap in forwarding table. Routers forward the incoming packet to the router which hash the longest prefix matching with the incoming packet.

Question 4 |

Consider the following routing table of a router.

Consider the following three IP addresses.

How are the packets with above three destination IP addresses are forwarded?

1->D, 2->B, 3->B | |

1->D, 2->B, 3->D | |

1->B, 2->D, 3->D | |

1->D, 2->D, 3->D |

**Network Layer**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 4 Explanation:

Refer following source of this question for explanation.
https://www.youtube.com/watch?v=PSC5omE3pX8&list=PLkHsKoi6eZnzJl1qTzmvBwTxrSJW4D2Jj&index=32

Question 5 |

Which of the following is not true about User Datagram Protocol in transport layer?

Works well in unidirectional communication, suitable for broadcast information. | |

It does three way handshake before sending datagrams | |

It provides datagrams, suitable for modeling other protocols such as in IP tunneling or Remote Procedure Call and the Network File System | |

The lack of retransmission delays makes it suitable for real-time applications |

**Transport Layer**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 5 Explanation:

// UDP is a connectioness protocol, so it doesn't establish connection. Three way handshake is done by transport layer.
A- UDP is a stateless protocol thus, useful in servers which answer small queries of large number of clients as it doesn’t need to store the state for each client. Thus, UDP is suitable for broadcast and unidirectional communication.
B- Three way handshake is performed by TCP before establishing the connection in which it first sends SYN packet then SYN-ACK is received,then ACK packet is sent. UDP is a connectionless protocol and thus,doesn’t to perform 3-way handshake.
C- IP tunneling is a communication channel between two different kind of networks .It is used to connect islands of IPv6 across the IPV internet by encapsulating the packets in the frame format of IPV4 . Remote procedure call is when a program causes a subroutine to run in another address space .This address space can be on server.It is a request response protocol and thus,UDP is suitable for it. Datagrams are also useful as UDP is a packet stream protocol.
D- TCP retransmits the errorneous packets from source to destination while UDP discards them.
This solution is contributed by

**Shashank Shanker khare**Question 6 |

Select the correct asymptotic complexity of an algorithm with runtime T(n, n) where

T(x, c) = Θ(x) for c <= 2, T(c, y) = Θ(y) for c <= 2, and T(x, y) = Θ(x+y) + T(x/2, y/2)

Θ(nLogn) | |

Θ(n ^{2}) | |

Θ(n) | |

Θ(n ^{2}Logn) |

**Analysis of Algorithms (Recurrences)**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 6 Explanation:

The recurrence is

T(x, y) = Θ(x+y) + T(x/2, y/2)It can be written as below.

T(x, y) = Θ(x+y) + Θ((x+y)/2) + Θ((x+y)/4) + Θ((x+y)/8) ..... T(x, y) = Θ((x+y) + (x+y)/2 + (x+y)/4 + (x+y)/8 ..... )The above expression forms a geometric series with ratio as 2 and starting element as (x+y)/2 T(x, y) is upper bounded by Θ(x+y) as sum of infinite series is 2(x+y). It is lower bounded by (x+y) Source: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/assignments/MIT6_006F11_ps1.pdf

Question 7 |

f1(n); f4(n); f2(n); f3(n) | |

f1(n); f2(n); f3(n); f4(n); | |

f2(n); f1(n); f4(n); f3(n) | |

f1(n); f2(n); f4(n); f3(n) |

**Analysis of Algorithms**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 8 |

An ISP has a link of 100Mbps which is shared by its subscribers. Considering the fact that all of its subscribers are active 50% of the time and the probabilities of being active are independent, the ISP has promised 25 Mbps to its 6 subscribers. What is the probability that any subscriber gets degraded service (less than promised speed).

1/32 | |

5/16 | |

1/2 | |

7/64 |

**Probability**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 8 Explanation:

The probability that more than 4 users are active a time is = (

^{6}C_{5}+^{6}C_{6})/2^{6}Question 9 |

Which of the following changes to typical QuickSort improves its performance on average and are generally done in practice.

1) Randomly picking up to make worst case less likely to occur. 2) Calling insertion sort for small sized arrays to reduce recursive calls. 3) QuickSort is tail recursive, so tail call optimizations can be done. 4) A linear time median searching algorithm is used to pick the median, so that the worst case time reduces to O(nLogn)

1 and 2 | |

2, 3, and 4 | |

1, 2 and 3 | |

2, 3 and 4 |

**Sorting**

**GATE-CS-2015 (Mock Test)**

**QuickSort**

**Discuss it**

Question 9 Explanation:

The 4th optimization is generally not used, it reduces the worst case time complexity to O(nLogn), but the hidden constants are very high.

Question 10 |

Given an array that represents elements of arithmetic progression in order. It is also given that one element is missing in the progression, the worst case time complexity to find the missing element efficiently is:

Θ(n) | |

Θ(nLogn) | |

Θ(Logn) | |

Θ(1) |

**Misc**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 10 Explanation:

We can use Binary Search to find the missing element. See following link for details.
http://www.geeksforgeeks.org/find-missing-number-arithmetic-progression/

Question 11 |

Let swap() be a function that swaps two elements using their addresses. Consider the following C function.

void fun(int arr[], int n) { for (int i = 0; i < n; i+=2) { if (i>0 && arr[i-1] > arr[i] ) swap(&arr[i], &arr[i-1]); if (i<n-1 && arr[i] < arr[i+1] ) swap(&arr[i], &arr[i + 1]); } }If an array {10, 20, 30, 40, 50, 60, 70, 80} is passed to the function, the array is changed to

{20, 10, 40, 30, 60, 50, 80, 70}
| |

{10, 30, 20, 40, 60, 50, 80, 70} | |

{10, 20, 30, 40, 50, 60, 70, 80} | |

{80, 70, 60, 50, 40, 30, 20, 10} |

**Misc**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 11 Explanation:

The function sorts the array in waveform. See Sort an array in wave form for more details.

Question 12 |

Consider the following three table to store student enrollements in different courses.

Student(What does the following query do?EnrollNo, Name) Course(CourseID, Name) EnrollMents(EnrollNo, CourseID)

SELECT S.Name FROM Student S, Course C, Enrollments E WHERE S.EnrollNo = E.EnrollNo AND C.Name = "DBMS" AND E.CourseID = C.CourseID AND S.EnrollNo IN (SELECT S2.EnrollNo FROM Student S2, Course C2, Enrollments E2 WHERE S2.EnrollNo = E2.EnrollNo AND E2.CourseID = C2.CourseID C2.Name = "OS")

Name of all students who are either enrolled in "DBMS" or "OS" courses | |

Name of all students who are enrolled in "DBMS" and "OS" | |

Name of all students who are either enrolled in "DBMS" or "OS" or both. | |

Non of the above |

**SQL**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 12 Explanation:

Background Reading: The above query is an example of

**nested query**i.e. query within a query. Firstly the inner query is solved and then the outer one depending on the result of the inner query.- WHERE IN returns values that matches values in a list or subquery.
- WHERE IN is a shorthand for multiple OR conditions.

Here, firstly the inner query is solved. It returns all the Enrollment Numbers (SELECT S2.EnrollNo) of students where the students’ enrollment number matches with the enrollment number of the courses (WHERE S2.EnrollNo = E2.EnrollNo) which have the course IDs whose Course Name is “OS” (E2.CourseID = C2.CourseID and C2.Name = “OS”).Hence all the enrollment IDs are filtered out for the students who are enrolled for the “OS” course.

The outer query works similarly and filters out all the all tuples where the Students Enrollment Number matches with the Enrollment Number where the course ID’s are for the course names “DBMS” (S.EnrollNo = E.EnrollNo AND C.Name =”DBMS” AND E.CourseID = C.CourseId) and additionally matches with the ones that are returned by the inner query i.e. Enrollment Number of students who are enrolled for the course “OS”.Hence the above queries returns names of all students (SELECT S.Name) who have enrolled for both courses “DBMS” and “OS”. Hence option (B). This explanation has been contributed by

**Yashika Arora.**Question 13 |

Consider the following Employee table

ID salary DeptName 1 10000 EC 2 40000 EC 3 30000 CS 4 40000 ME 5 50000 ME 6 60000 ME 7 70000 CSHow many rows are there in the result of following query?

SELECT E.ID FROM Employee E WHERE EXISTS (SELECT E2.salary FROM Employee E2 WHERE E2.DeptName = 'CS' AND E.salary > E2.salary)

0 | |

4 | |

5 | |

6 |

**SQL**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 13 Explanation:

**Background:**

- WHERE EXISTS tests for the existence of any records in a subquery.
- EXISTS returns true if the subquery returns one or more records.
- EXISTS is commonly used with correlated subqueries.

**Yashika Arora**.

Question 14 |

Consider the situation in which the disk read/write head is currently located at track 45 (of tracks 0-255) and moving in the positive direction. Assume that the following track requests have been made in this order: 40, 67, 11, 240, 87. What is the order in which optimised C-SCAN would service these requests and what is the total seek distance?

600 | |

810 | |

505 | |

550 |

**Input Output Systems**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 14 Explanation:

Circular scanning works just like the elevator to some extent. It begins its scan toward the nearest end and works it way all the way to the end of the system. Once it hits the bottom or top it jumps to the other end and moves in the same direction. Keep in mind that the huge jump doesn't count as a head movement.

Reference: http://www.cs.iit.edu/~cs561/cs450/disksched/disksched.html http://iete-elan.ac.in/SolQP/soln/DC14_sol.pdf

This solution is contributed by

**Solution:**Disk queue: 40, 67, 11, 240, 87 and disk is currently located at track 45.The order in which optimised C-SCAN would service these requests is shown by the following diagram. Total seek distance=(67-45)+(87-67)+(240-87)+(255-240)+(255-0)+(11-0)+(40-11) =22+20+153+15+255+11+29 =505 Option (C) is the correct answer.Reference: http://www.cs.iit.edu/~cs561/cs450/disksched/disksched.html http://iete-elan.ac.in/SolQP/soln/DC14_sol.pdf

This solution is contributed by

**Nitika Bansal**Question 15 |

It only accepts strings with prefix as "aababb" | |

It only accepts strings with substring as "aababb" | |

It only accepts strings with suffix as "aababb" | |

None of the above |

**Regular languages and finite automata**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 15 Explanation:

To reach the accepting state, any string will have to go through edges having aababb as labels in
order. Though it might not be a continuous substring, but it sure will be a substring. There might
be some cases where same substring always exists as a prefix or suffix for some DFA, but in this
situation we don’t have to consider those cases, given this question has single choice answer.
− > O − a− > O − a− > O − b− > O − a− > O − b− > O − b− > O
Hence, correct answer should be (B).
This solution is contributed by

**vineet purswani**.Question 16 |

How many minimum states are required in a DFA to find whether a given binary string has odd number of 0's or not, there can be any number of 1's.

1 | |

2 | |

3 | |

4 |

**Regular languages and finite automata**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 17 |

Consider a 3 game tournament between two teams. Assume that every game results in either a win or loss. The team that wins two or more games wins the series. The probability for wining the first game for both teams is 1/2. The probability for a team to win a game after a win is 2/3. The probability of wining a game after a loss is 1/3. Note that the effect of only previous game is considered. What is the probability for a team to win the series after loosing first game.

1/9 | |

1/6 | |

2/9 | |

1/3 |

**Probability**

**GATE-CS-2015 (Mock Test)**

**Discuss it**

Question 17 Explanation:

A team has 3 chances(games) to win tournament.
To win the tournament, a team must win atleast 2 games. Acc to question,
Team looses first chances. Now, to win, it is must to win left 2 games.
Probability to win the 2nd game : 1/3 (as previous game was a loss)
Probability to win the 3rd game : 2/3 (as previous game was a win)
So, Probability to win the tournament = 1/3 * 2/3
= 2/9
This solution is contributed by

**Mohit Gupta.**Question 18 |

Which of the following is FALSE about SJF (Shortest Job First Scheduling)?

S1: It causes minimum average waiting time S2: It can cause starvation

Only S1 | |

Only S2 | |

Both S1 and S2 | |

Neither S1 nor S2 |

**GATE-CS-2015 (Mock Test)**

**CPU Scheduling**

**Discuss it**

Question 18 Explanation:

- Both SJF and Shortest Remaining time first algorithms may cause starvation. Consider a situation when long process is there in ready queue and shorter processes keep coming.
- SJF is optimal in terms of average waiting time for a given set of processes, but problems with SJF is how to know/predict time of next job.

There are 18 questions to complete.