GATE 2016 (Session 1)
65 questions
MCQ 39 · NAT 261-mark 30 · 2-mark 35
Questions 21–25 of 65
Consider the following directed graph:
The number of different topological orderings of the vertices of the graph is
The number of different topological orderings of the vertices of the graph is
Answer: 6
Vertex a has to be first, and vertex f has to be last. Between them, b has to come before c, and d has to come before e. The two chains do not depend on each other.
Ways to merge the order b c with the order d e = .
Answer: 6
Ways to merge the order b c with the order d e = .
Answer: 6
Consider the following C program.
void f(int,short);
void main()
{
int i=100;
short s=12;
short *p=&s;
__________ ;//calltof()
} Which one of the following expressions, when placed in the blank above, will NOT result in a typec hecking error?Answer: (D)
The function f takes an (int, short) pair and returns void.
- f(s, *s): s is a short and not a pointer, so *s is not valid.
- i = f(i, s): f returns void, so its result cannot be assigned.
- f(i, *s): here too *s is not valid.
- f(i, *p): i is an int and *p is the short value s. This is correct.
Answer: f(i,*p)
- f(s, *s): s is a short and not a pointer, so *s is not valid.
- i = f(i, s): f returns void, so its result cannot be assigned.
- f(i, *s): here too *s is not valid.
- f(i, *p): i is an int and *p is the short value s. This is correct.
Answer: f(i,*p)
The worst case running times of Insertion sort, Mergesort and Quicksort, respectively, are:
Answer: (D)
Let us check each sort one by one:
- Insertion sort, worst case (the input is in reverse order):
- Merge sort takes the same time in every case:
- Quicksort, worst case (a bad pivot is chosen every time):
Answer:
- Insertion sort, worst case (the input is in reverse order):
- Merge sort takes the same time in every case:
- Quicksort, worst case (a bad pivot is chosen every time):
Answer:
Let G be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increasedby the same value ,then which of the following statements is/are TRUE?
P: Minimum spanning tree of G does not change
Q: Shortest path between any pair of vertices does not change
P: Minimum spanning tree of G does not change
Q: Shortest path between any pair of vertices does not change
Answer: (A)
P is true. Adding the same value to every edge keeps the order of the weights, so Kruskal's algorithm picks the same edges. Also every spanning tree has edges, so every tree's weight rises by the same amount and the minimum tree stays the same.
Q is false. A path with more edges gains more weight. Take a direct edge of weight 4 and a two-edge path with weights 1 and 2 (all distinct). The path is shorter: . Add 10 to every edge: the path becomes and the direct edge becomes 14. Now the direct edge is the shortest path, so shortest paths can change.
Answer: (A)
Q is false. A path with more edges gains more weight. Take a direct edge of weight 4 and a two-edge path with weights 1 and 2 (all distinct). The path is shorter: . Add 10 to every edge: the path becomes and the direct edge becomes 14. Now the direct edge is the shortest path, so shortest paths can change.
Answer: (A)
Consider the following C program.
#include <stdio.h>
void mystery(int *ptra,int *ptrb){
int *temp;
temp =ptrb;
ptrb =ptra;
ptra =temp;
}
int main(){
int a=2016,b=0,c=4,d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%d\n", a);
} The output of the program is _________.Answer: 2016
The function mystery swaps only its local copies of the pointers (ptra, ptrb). It never changes the values *ptra or *ptrb. So a, b, c and d in main stay the same.
The value of a is still 2016.
Answer: 2016
The value of a is still 2016.
Answer: 2016