What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int a[], int n, int k)
{
if (k <= n)
{
for (int i = 0; i < k/2; i++)
swap(a[i], a[k-i-1]);
}
}
int main()
{
int a[] = {1, 2, 3, 4, 5};
int n = sizeof(a) / sizeof(int), k = 3;
func(a, n, k);
for (int i = 0; i < n; ++i)
cout << a[i]<<" ";
return 0;
}A. O(k)
B. O(n)
C. O(k log k)
D. O(n log n)
Select an option to see the answer and solution.
Predefined function rotate() in C++ is available under which header file?
A. math
B. stdio
C. stdlib
D. algorithm
Select an option to see the answer and solution.
Which among the following is the worst-case time complexity for appending an element in a variable-length array?
A. O(n)
B. O(1)
C. O(n2 )
D. O(log n)
Select an option to see the answer and solution.
Which of the following is not an advantage of bit array?
A. Exploit bit level parallelism
B. Maximal use of data cache
C. Can be stored and manipulated in the register set for long periods of time
D. Accessing Individual Elements is easy
Select an option to see the answer and solution.
Suffix array can be created in O(nlogn) time.
Select an option to see the answer and solution.
What is the time required to locate the occurrences of a pattern P of length m in a string of length n using suffix array?
A. O(nm)
B. O(n2 )
C. O(mnlogn)
D. O(mlogn)
Select an option to see the answer and solution.
What is the functionality of the following piece of code?
public Object function(int row_index, int col_index)
{
if (row_index < 0 || col_index > N)
{
System.out.println("column index out of bounds");
return;
}
return (sparse_array[row_index].fetch(col_index));
}A. Store the element in the specified position
B. Get the element from the specified position
C. Alter the element in the specified position
D. Removes the element from the specified position
Select an option to see the answer and solution.
How many inversions are there in the array arr = {1,5,4,2,3}?
Select an option to see the answer and solution.
What will be the time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
int min(int x, int y)
{ return (x < y)? x: y; }
int func(int arr[], int n)
{
int *jump = new int[n];
int i, j;
if (n == 0 || arr[0] == 0)
return INT_MAX;
jump[0] = 0;
for (i = 1; i < n; i++)
{
jump[i] = INT_MAX;
for (j = 0; j < i; j++)
{
if (i <= j + arr[j] && jumps[j] != INT_MAX)
{
jump[i] = min(jump[i], jump[j] + 1);
break;
}
}
}
return jump[n-1];
}
int main()
{
int arr[] = {1, 3, 6, 1, 9,7};
int size = sizeof(arr)/sizeof(int);
cout<< func(arr,size);
return 0;
}A. O(n log n)
B. O(n)
C. O(n1/2 )
D. O(n2 )
Select an option to see the answer and solution.
Bit fields and Bit arrays are same.
Select an option to see the answer and solution.
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;
int func(int arr[], int s, int e)
{
if (s == e)
return 0;
if (arr[s] == 0)
return INT_MAX;
int min = INT_MAX;
for (int i = s + 1; i <= e && i <= s + arr[s]; i++)
{
int jumps = func(arr, i, e);
if(jumps != INT_MAX && jumps + 1 < min)
min = jumps + 1;
}
return min;
}
int main()
{
int arr[] = {1, 3, 6, 3, 8, 5};
int n = sizeof(arr)/sizeof(arr[0]);
cout << func(arr, 0, n-1);
return 0;
}Select an option to see the answer and solution.
Which of the following is the predefined function for array reversal in C++ ?
A. reverse()
B. arr_reverse()
C. array_reverse()
D. rev()
Select an option to see the answer and solution.
LCP array and . . . . . . . . is used to construct suffix tree.
A. Hash tree
B. Hash trie
C. Suffix array
D. Balanced tree
Select an option to see the answer and solution.
The size of the dynamic array is deallocated if the array size is less than . . . . . . . .% of the backend physical size.
Select an option to see the answer and solution.
What will be the output of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int left, int right)
{
while (left < right)
{
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
}
void printArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[] = {1,4,3,5};
int n = sizeof(arr) / sizeof(arr[0]);
func(arr, 0, n-1);
printArray(arr, n);
return 0;
}A. 5 1 4 3
B. 3 5 1 4
C. 5 3 4 1
D. error
Select an option to see the answer and solution.
If row-major order is used, how is the following matrix stored in memory?
a b c
d e f
g h i
A. ihgfedcba
B. abcdefghi
C. cfibehadg
D. adgbehcfi
Select an option to see the answer and solution.
Which of the following property does not hold for matrix multiplication?
A. Associative
B. Distributive
C. Commutative
D. Additive Inverse
Select an option to see the answer and solution.
What is a dynamic array?
A. A variable size data structure
B. An array which is created at runtime
C. The memory to the array is allocated at runtime
D. An array which is reallocated everytime whenever new elements have to be added
Select an option to see the answer and solution.
Is O(n) the Worst case Time Complexity for addition of two Sparse Matrix?
Select an option to see the answer and solution.
The growth factor of ArrayList in Java is . . . . . . . .
Select an option to see the answer and solution.