41. 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;
}
#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;
}42. 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;
}
#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;
}43. To rotate an array by using the algorithm of rotating its elements one by one is an in place algorithm.
44. What is a sorted array?
45. When do you use a sparse array?
46. What is the minimum possible time complexity to find the number of steps to reach the end of an array?
47. Under what condition the number of inversions in an array are minimum?
48. What does Hamming weight/population count mean in Bit arrays?
49. Dynamic arrays overcome the limit of static arrays.
50. Is Sparse Matrix also known as Dense Matrix?
Read More Section(Arrays in Data Structures)
Each Section contains maximum 100 MCQs question on Arrays in Data Structures. To get more questions visit other sections.
