Programming and Data Structures - Online Test

Q1. Consider the intermediate code given below.

The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are 
Answer : Option B
Explaination / Solution:
No Explaination.


Q2. Consider the following routing table at an IP router:

For each IP address in Group I identify the correct choice of the next hop from Group II using the entries from the routing table above. 

Answer : Option A
Explaination / Solution:
No Explaination.


Q3.  Consider two relations R1(A,B) with the tuples (1.5), (3,7) and R2 (A,C) = (1,7), (4,9). Assume that R(A,B,C) is the full natural outer join of R1 and R2 . Consider the following tuples of the form (A,B,C): a = (1.5,null), b = (1,null,7) c = (3,null,9), d = (4,7,null), e = (1,5,7), f = (3,7,null), g = (4,null,9). Which one of the following statements is correct?
Answer : Option C
Explaination / Solution:



Q4. A graph is self-complementary if it is isomorphic to its complement For all self-complementary graphs on n vertices, n is
Answer : Option D
Explaination / Solution:

An n vertex self complementary graph has exactly half number of edges of the complete graph i.e., n(n-1)/4 edges. Since n(n-1) must be divisible by 4 , n must be congruent to 0 or 1 module 4.

Q5. If f(x) = 2x7 + 3x - 5 which of the following is a factor of f(x)?
Answer : Option B
Explaination / Solution:

from the option (b0 substitute x=1 in 
2x7 + 3x - 5 = 0
2(1)7 + 3(1) - 5 = 0
5-5 = 0
So (x - 1) is a factor of f (x)



Q6. A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?
Answer : Option A
Explaination / Solution:
No Explaination.


Q7. The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Answer : Option D
Explaination / Solution:

Merge sort θ(n log n) in all the cases 
Quick sort θ(n log n) best case and θ(n2) worst cases
Insertion sort θ(n)best case R θ(n2) worst case

Q8. Let G be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increased by 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

Answer : Option A
Explaination / Solution:
No Explaination.


Q9.  The following function computes the maximum value contained in an integer array p[ ] of size n (n >= 1).
int max(int *p, int n) { 
int a=0, b=n-1; 
while ( _________ ) { 
if (p[a] <= p[b]) { a = a+1; } 
else { b = b-1; } 
}
return p[a]; 
}
The missing loop condition is

Answer : Option D
Explaination / Solution:

When a=b then P[a] will have the maximum value of the array

Q10. What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed? 
a=3;  
void n(x) {x = x * a; print(x);}
void m(y) {a = 1; a = y - a; n(a); print(a);}
void main() {m(a);} 
Answer : Option D
Explaination / Solution:

Dynamic scoping looks for the definition of free variable in the reverse order of calling sequence.