TCS NQT - cap ability

Test Number 4/11

Q: Choose the correct option.
The term "push" and "pop" is related to the
A. Array 4%
B. Lists 2%
C. stacks 88%
D. all of above 6%
Solution: Here is no explanation for this answer
Q: Choose the correct option.
The prefix of (A+ B) * (C-D) is
A. +-AB*(C-D) 24%
B. * +-ABCD 19%
C. * +AB-CD 51%
D. *AB+ CD 6%
Solution: Here is no explanation for this answer
Q: Choose the correct option.
How is linked list implemented
A. Nodes 36%
B. Structure 25%
C. Referential Structures 36%
D. None of these
Solution: Here is no explanation for this answer
Q: Choose the correct option.
The concatenation of 2 lists can be performed O(1) time. Which of the following implementation of list should be used?

Choose the correct option.
What is the difference between a normal(naive) array and a sparse array?
A. Singly Linked List 24%
B. Doubly Linked List 28%
C. Circular Linked List 34%
D. Array Implementation Of Linked List 14%
Solution: Here is no explanation for this answer
Q: 
Choose the correct option.
What is the difference between a normal(naive) array and a sparse array?
A. A naive array is more efficient 17%
B. Sparse array can hold more elements than a normal array 35%
C. Sparse array is memory efficient 37%
D. Sparse array is dynamic 11%
Solution: A naive implementation allocates space for the entire size of the array, whereas a sparse array(linked list implementation) allocates space only for the non-default values.
Q: Choose the correct option.
Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.

I. public int count()
{
int count = 1;
for (List cur = this.next; (cur != null); cur = cur.next.next)
{
count++;
}
return count;
}

II. public int count()
{
int count = 0;
for (List cur = this.next; (cur != null); cur = cur.next)
{}
return count;
}

III. public int count()
{
int count = 0;
for (List cur = this; (cur != null); cur = cur.next)
{
count++;
}
return count;
}

IV. public int count()
{
int count = 1;
for (List cur = this.next; (cur != null); cur = cur.next)
{{
count++;
}
return count;
}
A. I 21%
B. II 37%
C. III 26%
D. IV 16%
Solution: A simple ‘for loop’ to count the non-null elements.
Q: Choose the correct option.
Choose the correct function from the following which determines the number of inversions in an array?

I. int InvCount(int arr[], int n) 
{ 
 int count = 0; 
 for (int i = 0; i < n - 1; i++) 
  for (int j = i + 1; j < n; j++) 
   if (arr[i] < arr[j]) 
    count++; 
 
 return count + 1; 
}

II. int InvCount(int arr[], int n) 
{ 
 int count = 0; 
 for (int i = 0; i < n - 1; i++) 
for (int j = i ; j < n; j++) 
   if (arr[i] >= arr[j]) 
    count++; 
 
 return count; 
}

III. int InvCount(int arr[], int n) 
{ 
 int count = 0; 
 for (int i = 0; i < n - 1; i++) 
  for (int j = i + 1; j < n; j++) 
   if (arr[i] > arr[j]) 
    count++; 
 
 return count; 
} IV. int InvCount(int arr[], int n) 
{ 
 int count = 0; 
 for (int i = 0; i < n - 1; i++) 
  for (int j = i + 1; j < n; j++) 
   if (arr[i] > arr[j]) 
    count++; 
 
 return count + 1; 
}
A. I 21%
B. II 27%
C. III 38%
D. IV 14%
Solution: To determine the number of inversions we apply a nested loop and compare the value of each element with all the elements present after it. Then the count of number of inversions is counted and returned to the main function.
Q: What will be the auxiliary space complexity of the following code?
#include 
using namespace std;
int main()
{   
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];
 
    for(int i=0;i
A. O(n*d) 28%
B. O(1) 15%
C. O(n) 48%
D. O(d) 8%
Solution: The given code rotates an input array by d. It does so by using an auxiliary array temp[] which stores first d elements of the original array. So the auxiliary space complexity will be O(d).
Q: What will be the output of the following code?
#include  
using namespace std; 
 
void func1(int arr[], int n) 
{ 
 int k = arr[0], i; 
 for (i = 0; i < n - 1; i++) 
  arr[i] = arr[i + 1]; 
 
 arr[i] = k; 
} 
 
void func(int arr[], int d, int n) 
{ 
 for (int i = 0; i < d; i++) 
  func1(arr, n); 
} void printArray(int arr[], int n) 
{ 
 for (int i = 0; i < n; i++) 
  cout << arr[i] << " "; 
} 
 
int main() 
{ 
 int arr[] = { 1, 2, 3, 4, 5}; 
 int n = sizeof(arr) / sizeof(arr[0]); 
 
 
 func(arr, 3, n); 
 printArray(arr, n); 
 
 return 0; 
}
A. error 21%
B. 4 5 1 2 3 41%
C. 3 4 5 1 2 20%
D. 5 4 3 1 2 18%
Solution: The given code rotates the input array by 3. It does so by rotating the elements one by one until the desired rotation is achieved. So the output will be 4 5 1 2 3.
Q: What will be the time complexity of the following code?
#include 
using namespace std;
int main()
{   
    int arr[] = {1,2,3,4,5,6};
    int n = sizeof(arr)/sizeof(arr[0]);
    int d=4;
    int temp[10];
 
    for(int i=0;i
A. O(n*d) 13%
B. O(d) 46%
C. O(n) 35%
D. O(n2) 6%
Solution: The given code rotates an input array by d. The longest loop in the code takes n iterations so the time complexity will be O(n).

You Have Score    /10