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;
}
A
GATE CS 2015 Mock Test
B
tseT kcoM 5102 SC ETAG
C
Nothing is printed on screen
D
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.
A
Problem 1 belongs NP Complete set and 2 belongs to P
B
Problem 1 belongs to P set and 2 belongs to NP Complete set
C
Both problems belong to P set
D
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?
A
Forward it the the router whose entry matches with the longest prefix of incoming packet
B
Forward the packet to all routers whose network addresses match.
C
Discard the packet.
D
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.
GATE CN1
Consider the following three IP addresses.
GATE CN
How are the packets with above three destination IP addresses are forwarded?
A
1->D, 2->B, 3->B
B
1->D, 2->B, 3->D
C
1->B, 2->D, 3->D
D
1->D, 2->D, 3->D
Network Layer    GATE-CS-2015 (Mock Test)    
Discuss it


Question 4 Explanation: 
Question 5
Which of the following is not true about User Datagram Protocol in transport layer?
A
Works well in unidirectional communication, suitable for broadcast information.
B
It does three way handshake before sending datagrams
C
It provides datagrams, suitable for modeling other protocols such as in IP tunneling or Remote Procedure Call and the Network File System
D
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) 
A
Θ(nLogn)
B
Θ(n2)
C
Θ(n)
D
Θ(n2Logn)
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
The increasing order of following functions in terms of asymptotic complexity is: GATE CN2
A
f1(n); f4(n); f2(n); f3(n)
B
f1(n); f2(n); f3(n); f4(n);
C
f2(n); f1(n); f4(n); f3(n)
D
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).
A
1/32
B
5/16
C
1/2
D
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 = (6C5 + 6C6)/26
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)
A
1 and 2
B
2, 3, and 4
C
1, 2 and 3
D
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:
A
Θ(n)
B
Θ(nLogn)
C
Θ(Logn)
D
Θ(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
A
{20, 10, 40, 30, 60, 50, 80, 70}
B
{10, 30, 20, 40, 60, 50, 80, 70}
C
{10, 20, 30, 40, 50, 60, 70, 80}
D
{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(EnrollNo, Name)
Course(CourseID, Name)
EnrollMents(EnrollNo, CourseID) 
What does the following query do?
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")
A
Name of all students who are either enrolled in "DBMS" or "OS" courses
B
Name of all students who are enrolled in "DBMS" and "OS"
C
Name of all students who are either enrolled in "DBMS" or "OS" or both.
D
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      CS 
How 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)
A
0
B
4
C
5
D
6
SQL    GATE-CS-2015 (Mock Test)    
Discuss it


Question 13 Explanation: 
Background:
  1. WHERE EXISTS tests for the existence of any records in a subquery.
  2. EXISTS returns true if the subquery returns one or more records.
  3. EXISTS is commonly used with correlated subqueries.
Here in the above question, there is a correlated subquery because the subquery references the enclosing query (relation Employee renamed as E) The subquery (SELECT E2.salary FROM Employee E2 WHERE E2.DeptName = 'CS') Filters out E2 relation as (all tuples where DeptName is CS and the respective salaries) Now the correlated query works as follows: SELECT E.ID FROM Employee E WHERE EXISTS (SELECT E2.salary FROM Employee E2 WHERE E2.DeptName = 'CS' AND E.salary > E2.salary) It takes one tuple from the Employee Relation and displays its ID if the WHERE EXISTS returns true i.e. the subquery returns one or more records. This happens in the case when the tuple from the Employee Relation E has the value of the salary attribute greater than any one of the values of the salary attribute filtered out above. So tuples filtered out would be all the tuples that have their salary attribute value greater than the salary values of at least one from the E2 relation (3000 and 7000). ID salary DeptName 2 40000 EC 4 40000 ME 5 50000 ME 6 60000 ME 7 70000 CS Finally it displays their ID’s and the output would be: 2 4 5 6 7 Hence option (C) 5 rows.   This solution is contributed by 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?
A
600
B
810
C
505
D
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. 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. nitika_14 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
Consider the following Deterministic Finite Automata Automata Which of the following is true?
A
It only accepts strings with prefix as "aababb"
B
It only accepts strings with substring as "aababb"
C
It only accepts strings with suffix as "aababb"
D
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.
A
1
B
2
C
3
D
4
Regular languages and finite automata    GATE-CS-2015 (Mock Test)    
Discuss it


Question 16 Explanation: 
Automata
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.
A
1/9
B
1/6
C
2/9
D
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
A
Only S1
B
Only S2
C
Both S1 and S2
D
Neither S1 nor S2
GATE-CS-2015 (Mock Test)    CPU Scheduling    
Discuss it


Question 18 Explanation: 
  1. 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.
  2. 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.
Refer Process Scheduling for more details.
There are 18 questions to complete.

GATE CS Corner


See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.