Vidyalelo
Data Structure · all questions

Arrays in Data Structures
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

176

Questions

7/9

Page

Pick an option on a question to see the right answer and solution.

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; 
}

Select an option to see the answer and solution.

Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?

Select an option to see the answer and solution.

What is meant by physical size in a dynamic array?

Select an option to see the answer and solution.

What is the difference between a normal(naive) array and a sparse array?

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}?

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?

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?

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?

Select an option to see the answer and solution.

What will be the resulting array after reversing arr[]={3,5,4,2}?

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;
}

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; 
}

Select an option to see the answer and solution.

What is a sparse array?

Select an option to see the answer and solution.

How will you implement dynamic arrays in Java?

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?

Select an option to see the answer and solution.

In what way the Symmetry Sparse Matrix can be stored efficiently?

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?

Select an option to see the answer and solution.

The number of items used by the dynamic array contents is its . . . . . . . .

Select an option to see the answer and solution.