11. 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;
}
#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;
}12. Which of the following is the predefined function for array reversal in C++ ?
13. LCP array and . . . . . . . . is used to construct suffix tree.
14. The size of the dynamic array is deallocated if the array size is less than . . . . . . . .% of the backend physical size.
15. 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;
}
#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;
}16. If row-major order is used, how is the following matrix stored in memory?
a b c
d e f
g h i
a b c
d e f
g h i
17. Which of the following property does not hold for matrix multiplication?
18. What is a dynamic array?
19. Is O(n) the Worst case Time Complexity for addition of two Sparse Matrix?
20. The growth factor of ArrayList in Java is . . . . . . . .
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.
