51. Under what condition the number of inversions in an array are maximum?
52. 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;
}
#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;
}53. It is not possible to reach the end of an array if starting element of the array is 0.
54. Which of the following is an advantage of using variable-length arrays?
55. Which of the following is not the method to represent Sparse Matrix?
56. What is the condition for two elements arr[i] and arr[j] to form an inversion?
57. When array reversal and rotation is applied to the same array then the output produced will also be the same every time.
58. How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)
59. 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;
}
#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;
}60. Which one of the following operations returns the first occurrence of bit 1 in bit arrays?
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.
