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

6/9

Page

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

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

Select an option to see the answer and solution.

Predefined function rotate() in C++ is available under which header file?

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?

Select an option to see the answer and solution.

Which of the following is not an advantage of bit array?

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?

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

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

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

Select an option to see the answer and solution.

LCP array and . . . . . . . . is used to construct suffix 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; 
}

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

Select an option to see the answer and solution.

Which of the following property does not hold for matrix multiplication?

Select an option to see the answer and solution.

What is a dynamic array?

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.