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

5/9

Page

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

In special case, the time complexity of inserting/deleting elements at the end of dynamic array is . . . . . . . .

Select an option to see the answer and solution.

Suffix array can be created by performing . . . . . . . . traversal of a suffix tree.

Select an option to see the answer and solution.

If comparison based sorting algorithm is used construct the suffix array, then what will be time required to construct the suffix array?

Select an option to see the answer and solution.

Which of the following is/are advantages suffix array one suffix tree?
I. Lesser space requirement
II. Improved cache locality
III. Easy construction in linear time

Select an option to see the answer and solution.

Which of the following bitwise operations will you use to toggle a particular bit?

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 func(int arr[], int left, int right) 
{ 
    if (left >= right) 
    return; 
 
    int temp = arr[left];  
    arr[left] = arr[right]; 
    arr[right] = temp; 
 
    func(arr, left + 1, right - 1);  
}      
 
void printArray(int arr[], int size) 
{ 
    for (int i = 0; i < size; i++) 
    cout << arr[i] << " "; 
} 
 
int main() 
{ 
	int arr[] = {1,2,3,4}; 
	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.

Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.

Options are not available for this question.

Select an option to see the answer and solution.

Which of the following is a disadvantage of dynamic arrays?

Select an option to see the answer and solution.

What will be the auxiliary space requirement 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.

Which of the following is/are not applications of bit arrays?

Select an option to see the answer and solution.

Which of the following don't use matrices?

Select an option to see the answer and solution.

How many swaps are required for reversing an array having n elements where n is an odd number?

Select an option to see the answer and solution.

What is the space 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.

What will be the auxiliary space complexity of the code to rotate an array by using the reversal algorithm (d = number of rotations)?

Select an option to see the answer and solution.

What is the time complexity of the code that uses self balancing BST for determining the number of inversions in an array?

Select an option to see the answer and solution.

Array is divided into two parts in . . . . . . . .

Select an option to see the answer and solution.

To search for an element in a sorted array, which searching technique can be used?

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 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.

Run-Length encoding is used to compress data in bit arrays.

Select an option to see the answer and solution.

In how many different ways we can reach the end of the array arr[]={1,3,5,8,9}?

Select an option to see the answer and solution.