What will be the worst case time complexity of the following code?
#include <bits/stdc++.h>
using namespace std;
void func(int arr[], int n)
{
int count[n];
memset(count, 0, sizeof(count));
for (int i=n-2; i>=0; i--)
{
if (arr[i] >= n - i - 1)
count[i]++;
for (int j=i+1; j < n-1 && j <= arr[i] + i; j++)
if (count[j] != -1)
count[i] += count[j];
if (count[i] == 0)
count[i] = -1;
}
for (int i=0; i<n; i++)
cout << count[i] << " ";
}
int main()
{
int arr[] = {1, 3, 5, 8, 9};
int n = sizeof(arr) / sizeof(arr[0]);
func(arr, n);
return 0;
}A. O(n1/2 )
B. O(n)
C. O(n3/2 )
D. O(n2 )
Select an option to see the answer and solution.
Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?
A. Identity matrix
B. Inverse of A
C. Square of A
D. Transpose of A
Select an option to see the answer and solution.
What is meant by physical size in a dynamic array?
A. The size allocated to elements
B. The size extended to add new elements
C. The size of the underlying array at the back-end
D. The size visible to users
Select an option to see the answer and solution.
What is the difference between a normal(naive) array and a sparse array?
A. Sparse array can hold more elements than a normal array
B. Sparse array is memory efficient
C. Sparse array is dynamic
D. A naive array is more efficient
Select an option to see the answer and solution.
What will be the minimum number of jumps required to reach the end of the array arr[] = {1,2,0,0,3,6,8,5}?
A. 1
B. 2
C. 3
D. not possible to reach the end
Select an option to see the answer and solution.
Select the code snippet which performs matrix multiplication.(a and b are the two given matrices, resultant marix is c)
Options are not available for this question.
Select an option to see the answer and solution.
Which one of the following is a Special Sparse Matrix?
A. Band Matrix
B. Skew Matrix
C. Null matrix
D. Unit matrix
Select an option to see the answer and solution.
The time complexity of the code that determines the number of inversions in an array using self balancing BST is lesser than that of the code that uses loops for the same purpose.
Select an option to see the answer and solution.
What does the number of inversions in an array indicate?
A. mean value of the elements of array
B. measure of how close or far the array is from being sorted
C. the distribution of values in the array
D. median value of the elements of array
Select an option to see the answer and solution.
Suppose the contents of an array A are, A = {1, null, null, null, null, 10};
What would be the size of the array considering it as a normal array and a sparse array?
A. 6 and 6
B. 6 and 2
C. 2 and 6
D. 2 and 2
Select an option to see the answer and solution.
What will be the resulting array after reversing arr[]={3,5,4,2}?
A. 2,3,5,4
B. 4,2,3,5
C. 5,4,2,3
D. 2,4,5,3
Select an option to see the answer and solution.
What will be the auxiliary space complexity of the following code?
#include <iostream>
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<d;i++)
temp[i]=arr[i];
int j=0;
for(int i=d;i<n;i++,j++)
arr[j]=arr[i];
int k=0;
for(int i=n-d;i<n;i++,k++)
arr[i]=temp[k];
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";
return 0;
}A. O(1)
B. O(n)
C. O(d)
D. O(n*d)
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;
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]);
int d = 3;
func(arr, d, n);
printArray(arr, n);
return 0;
}A. O(n*d)
B. O(n)
C. O(d)
D. O(n2 )
Select an option to see the answer and solution.
What is a sparse array?
A. Data structure for representing arrays of records
B. Data structure that compactly stores bits
C. An array in which most of the elements have the same value
D. An array in which memory is allocated in run time
Select an option to see the answer and solution.
How will you implement dynamic arrays in Java?
A. Set
B. Map
C. HashMap
D. List
Select an option to see the answer and solution.
Which of the following bitwise operations will you use to set a particular bit to 0?
Select an option to see the answer and solution.
Which of the following arrays are used in the implementation of list data type in python?
A. Bit array
B. Dynamic arrays
C. Sparse arrays
D. Parallel arrays
Select an option to see the answer and solution.
In what way the Symmetry Sparse Matrix can be stored efficiently?
A. Heap
B. Binary tree
C. Hash table
D. Adjacency List
Select an option to see the answer and solution.
What is the time complexity of the code that uses merge sort for determining the number of inversions in an array?
A. O(n2 )
B. O(n)
C. O(log n)
D. O(n log n)
Select an option to see the answer and solution.
The number of items used by the dynamic array contents is its . . . . . . . .
A. Physical size
B. Capacity
C. Logical size
D. Random size
Select an option to see the answer and solution.