## 1. What will be the minimum number of jumps required to reach the end of the array arr[] = {1,3,6,3,6,8,5}?

**a) 1****b) 2****c) 3****d) not possible to reach the end**

**Answer: c**

**Explanation: **

** Each element of the array represents the maximum number of steps that can be taken forward from that element. If the first element is 0 then it is not possible to reach the end.**

## 2. What will be the minimum number of jumps required to reach the end of the array arr[] ={0,1,3,6,3,6,8,5}?

**a) 1****b) 2****c) 3****d) not possible to reach the end**

**Answer: d**

**Explanation: **

** Each element of the array represents the maximum number of steps that can be taken forward from that element. So as the first element here is 0 so we cannot move any further from the first element. Thus, it is not possible to reach the end of the array.**

## 3. What will be the output of the following code?
#include
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;
}

**a) 1****b) 2****c) 3****d) error**

**Answer: c**

**Explanation:**

** The given code finds the minimum number of steps required to reach the end of the array by using recursion. So the output will be 3.**

## 4. What will be the output of the following code?
#include
using namespace std;
int min(int x, int y)
{ return (x < y)? x: y; }
int func(int arr[], int n)
{
int *jump = new int[n];
int i, j;
if (n == 0 || arr[0] == 0)
return INT_MAX;
jump[0] = 0;
for (i = 1; i < n; i++)
{
jump[i] = INT_MAX;
for (j = 0; j < i; j++)
{
if (i <= j + arr[j] && jump[j] != INT_MAX)
{
jump[i] = min(jump[i], jump[j] + 1);
break;
}
}
}
return jump[n-1];
}
int main()
{
int arr[] = {1, 3, 6, 1, 9,7};
int size = sizeof(arr)/sizeof(int);
cout<< func(arr,size);
return 0;
}

**a) 1****b) 2****c) 3****d) error**

**Answer: c**

**Explanation: **

** The given code finds the minimum number of steps required to reach the end of the array by using dynamic programming. So the output will be 3.**

## 5. What will be the time complexity of the following code?
#include
using namespace std;
int min(int x, int y)
{ return (x < y)? x: y; }
int func(int arr[], int n)
{
int *jump = new int[n];
int i, j;
if (n == 0 || arr[0] == 0)
return INT_MAX;
jump[0] = 0;
for (i = 1; i < n; i++)
{
jump[i] = INT_MAX;
for (j = 0; j < i; j++)
{
if (i <= j + arr[j] && jumps[j] != INT_MAX)
{
jump[i] = min(jump[i], jump[j] + 1);
break;
}
}
}
return jump[n-1];
}
int main()
{
int arr[] = {1, 3, 6, 1, 9,7};
int size = sizeof(arr)/sizeof(int);
cout<< func(arr,size);
return 0;
}

**a) O(n log n)****b) O(n)****c) O(n1/2)****d) O(n2)**

**Answer: d**

**Explanation:**

** The given code finds the minimum number of steps required to reach the end of an array by using dynamic programming. As there is a nested loop in the code so the time complexity will be O(n2).**

## 6. What will be the minimum number of jumps required to reach the end of the array arr[] = {1,2,0,0,3,6,8,5}?

**a) 1****b) 2****c) 3****d) not possible to reach the end**

**Answer: d**

**Explanation:**

** Each element of the array represents the maximum number of steps that can be taken forward from that element. So we cannot move any further after reaching the second element hence it is impossible to reach the end of the array.**

## 7. It is not possible to find the minimum number of steps to reach the end of an array in linear time.

**a) true****b) false**

**Answer: b**

**Explanation:**

** It is possible to find the minimum number of steps to reach the end of an array in O(n) time complexity. So it is the fastest possible method of finding the minimum number of steps to reach the end of an array.**

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

**a) 1****b) 2****c) 3****d) 4**

**Answer: d**

**Explanation:**

** There are 4 possible ways in which we can reach the end of the array. The possible paths are – 1->3->5->8->9, 1->3->5->9, 1->3->8->9, 1->3->9.**

** **

## 9. What will be the output of the following code?
#include
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

**a) 3****b) 4****c) 4 4 2 1 0****d) 4 2 2 0 1**

**Answer: c**

**Explanation:**

** The given code finds the number of possible ways to reach the end of an array from each element. So the output will be 4 4 2 1 0.**

## 10. What will be the worst case time complexity of the following code?
#include
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;
}

**a) O(n1/2)****b) O(n)****c) O(n3/2)****d) O(n2)**

**Answer: d**

**Explanation:**

** The given code finds the number of possible ways to reach the end of an array from each element. By observing the nested loop in the code we can say that the worst case time complexity will be O(n2).**

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

**a) true****b) false**

**Answer: a**

**Explanation:**

** If the first element of an array is 0 then it is not possible to reach the end. However, if 0 is present at other positions then we may/may not be able to reach the end.**

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

**a) O(n)****b) O(n2)****c) O(n3/2)****d) O(1)**

**Answer: a**

**Explanation:**

** The minimum possible time complexity to reach the end of an array is O(n). So a linear time complexity is possible.**

## 13. Which of the following is the predefined function for array reversal in javascript?

**a) reverse()****b) arr_reverse()****c) array_reverse()****d) rev()**

**Answer: a**

**Explanation:**

** The predefined function for reversing an array is reverse() in javascript. It does not requires any argument.**

## 14. Predefined function reverse() in C++ is available under which header file?

**a) math****b) stdio****c) stdlib****d) algorithm**

**Answer: d**

**Explanation:**

** The predefined function for reversing an array is reverse() in C++ which comes under the library called an algorithm. It requires 2 arguments the first being the pointer to the starting index of the array and the second being the pointer to the last index of the array.**

## 15. What is the time complexity of the juggling algorithm to rotate an array?

**a) O(1)****b) O(n)****c) O(d)****d) O(n*d)**

**Answer: b**

**Explanation:**

** Time complexity of juggling algorithm is O(n). Its auxiliary space complexity is O(1).**

## 16. Reversal algorithm and juggling algorithm for array rotation have the same time complexity.

**a) True****b) False**

**Answer: a**

**Explanation:**

** Time complexity of juggling algorithm is O(n) which like that of reversal algorithm. They also have the same space complexity**

- Know About Most Powerful Jagannath Temple, Puri
- Top Story About Ghatgan Tarini Temple, Keonjhar District
- Famous Rayagada Maa Majhighariani Temple [ Top Story]
- Positive / Negative Impacts of Social Media on Students
- 1000+ Words Essay on Covid-19 and Its Impact
- TOP 20+ MCQs on Postfix to Infix Conversion Data Structure with Answers
- TOP 20+ MCQs on Data Structure with Answers
- TOP MCQs on Data Structure with Answers