12

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

Company Wise Coding Practice    Topic Wise Coding Practice