GATE-CS-2015 (Mock Test)

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;
}
Cross
GATE CS 2015 Mock Test
Tick
tseT kcoM 5102 SC ETAG
Cross
Nothing is printed on screen
Cross
Segmentation Fault


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.
Tick
Problem 1 belongs NP Complete set and 2 belongs to P
Cross
Problem 1 belongs to P set and 2 belongs to NP Complete set
Cross
Both problems belong to P set
Cross
Both problems belong to NP complete set


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?
Tick
Forward it the router whose entry matches with the longest prefix of incoming packet
Cross
Forward the packet to all routers whose network addresses match.
Cross
Discard the packet.
Cross
Forward it the router whose entry matches with the longest suffix of incoming packet


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.

PrefixNext Hop
192.24.0.0/18D
192.24.12.0/22B

Consider the following three IP addresses.

Prefix
192.24.0.0/18
192.24.12.0/22
192.24.54.0

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

Cross

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

Tick

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

Cross

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

Cross

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



Question 4-Explanation: 

Option I matches the first and third IP addresses because they fall within the range defined by its subnet mask. Option II matches the second IP address because it falls within the range defined by its subnet mask. Option III doesn't match any IP addresses as they fall outside the range defined by its subnet masks. So, the correct option is B.

Question 5

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

Cross

Works well in unidirectional communication, suitable for broadcast information.

Tick

It does three way handshake before sending datagrams

Cross

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

Cross

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



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 erroneous packets from source to destination while UDP discards them.

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) 
Cross
Θ(nLogn)
Cross
Θ(n2)
Tick
Θ(n)
Cross
Θ(n2Logn)


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: \\\\ f_{1}(n) = n^{0.999999}log (n)\\\\ f_{2}(n) = 10000000n\\\\ f_{3}(n) = 1.000001^{n} f_{4}(n) = n^{2}
Cross
f1(n); f4(n); f2(n); f3(n)
Cross
f1(n); f2(n); f3(n); f4(n);
Cross
f2(n); f1(n); f4(n); f3(n)
Tick
f1(n); f2(n); f4(n); f3(n)


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).
Cross
1/32
Cross
5/16
Cross
1/2
Tick
7/64


Question 8-Explanation: 
The above question is an example of Binomial Experiment. Any user can be either Online(O) or Offline(F) P(O) = \\frac{1}{2} P(F) = \\frac{1}{2} Let X be the Random Variable denoting the number of users online. The users get degraded service when X=5 or X=6,  = P(X>4) \\\\ = P(X=5) + P(X=6) \\\\ = C(6,5) * P(O)^5 * P(F)^1 +  C(6,6) * P(O)^6\\\\ = 6 * \\frac{1}{2}^5 * \\frac{1}{2}^1 +  1 * \\frac{1}{2}^6\\\\ = \\frac{7}{2^6}\\\\ = 7/64
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)
Cross

1 and 2

Cross

2, 3, and 4

Tick

1, 2 and 3

Cross

2, 3 and 4



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:
Cross
Θ(n)
Cross
Θ(nLogn)
Tick
Θ(Logn)
Cross
Θ(1)


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/
There are 18 questions to complete.

  • Last Updated : 02 Dec, 2021

Share your thoughts in the comments
Similar Reads