31. Which of the following typecasting is accepted by C?
Answer: Both
Explanation:Here is no explanation for this answer
Workspace
TCS TCS NQT
32. Selection sort and quicksort both fall into the same category of sorting algorithms. What is this category?
Answer: Interchange sorts
Explanation:Selection sort is not O(n log n) and not a Divide-conquer sort too and Average time of quicksort is not quadratic.
Workspace
BOA (Bank of America) TCS NQT
33. Let P be a quick sort program to sort numbers in ascending order using the first element as the pivot. Let t1 and t2 be the number of comparisons made by P for the input [1 2 3 4 5] and [4 1 5 3 2] respectively. Which one of the following holds?
Answer: t1 > t2
Explanation:When first element or last element is chosen as pivot, Quick Sort's worst case occurs for the sorted arrays.
In every step of quick sort, numbers are divided as per the following recurrence.
T(n) = T(n-1) + O(n)
Workspace
Nagarro TCS NQT
34. Consider the C function given below. Assume the array listA contains (n>0) elements, sorted in ascending order.
int Process array (int * list A, int x, int n)
{
int i, j, k;
i =0;j=n-1;
do {
k = (i+j)/2;
if (x<=list A[k])
j=k-1;
if (list A[k] <=x)
i =k+1;
} while (i <=j);
if (list A[k] == x)
return (k);
else
return -1;
}
Answer: It is an implementation of binary search.
Explanation:Here is no explanation for this answer
Workspace
Nagarro Societe Generale TCS NQT
35. Specifically, overloading involves
Answer: multiple functions defined with the same name
Explanation:Here is no explanation for this answer
Workspace
TCS NQT
36. public class SwitchTest {
public static void main(String argv[]) {
SwitchTest ms=new SwitchTest();
ms.display();
}
public void display() {
int k=10;
switch(k){
default:
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}
Answer: ten
Explanation:Here is no explanation for this answer
Workspace
Virtusa TCS NQT
37. class ArrayTest {
public static void main(String[] args) {
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]);
}
}
Answer: Prints: 3, 4, 8
Explanation:Here is no explanation for this answer
Workspace
Virtusa TCS NQT
38. public class Test {
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String {
a = "xyz";
}
}
Answer: abc
Explanation:Java pass reference as value. passing the object reference, and not the actual object itself. The parameter is essentially a local variable.
Workspace
TCS NQT
39. public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}
Answer: abc
Explanation:Here is no explanation for this answer
Workspace
TCS NQT
40. public class Example {
int x = 50;
int y = 100;
public static void main(String args[]) {
int x = 0, y = 10;
Example ex = new Example();
while(x < {
x++; y--;
}
System.out.println("X = "+x+",Y ="+y);
}
}
Answer: x = 3, y = 7
Explanation:x = 3, y = 7
Workspace
TCS NQT