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

8/9

Page

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

Consider the following piece of code in C++. What does the following code implement?
#include <iostream>   
using namespace std;
int main()
{
    int *arr_vla;
    int size;
    cout<<"Enter the size of variable length array: ";
    cin>>size;
    arr_vla = new int [size];
    for (int i = 0; i < size; i++)
    {
        cout<<"Enter the integers to be inserted in the variable length array: ";
        cin>>arr_vla[i];
    }
    for(int i = 0; i < size; i++)
    {
        cout<<arr_vla[i]<<"  ";
    }
    cout<<endl;
    return 0;
}

Select an option to see the answer and solution.

What will be the time 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.

To rotate an array by using the algorithm of rotating its elements one by one is an in place algorithm.

Select an option to see the answer and solution.

What is a sorted array?

Select an option to see the answer and solution.

When do you use a sparse array?

Select an option to see the answer and solution.

What is the minimum possible time complexity to find the number of steps to reach the end of an array?

Select an option to see the answer and solution.

Under what condition the number of inversions in an array are minimum?

Select an option to see the answer and solution.

What does Hamming weight/population count mean in Bit arrays?

Select an option to see the answer and solution.

Dynamic arrays overcome the limit of static arrays.

Select an option to see the answer and solution.

Is Sparse Matrix also known as Dense Matrix?

Select an option to see the answer and solution.

Under what condition the number of inversions in an array are maximum?

Select an option to see the answer and solution.

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

It is not possible to reach the end of an array if starting element of the array is 0.

Select an option to see the answer and solution.

Which of the following is an advantage of using variable-length arrays?

Select an option to see the answer and solution.

Which of the following is not the method to represent Sparse Matrix?

Select an option to see the answer and solution.

What is the condition for two elements arr[i] and arr[j] to form an inversion?

Select an option to see the answer and solution.

When array reversal and rotation is applied to the same array then the output produced will also be the same every time.

Select an option to see the answer and solution.

How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)

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

Which one of the following operations returns the first occurrence of bit 1 in bit arrays?

Select an option to see the answer and solution.