Data Structure Questions and Answers-Largest and Smallest Number in an Array using Recursion

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Largest and Smallest Number in an Array using Recursion

Click on any option to know the CORRECT ANSWERS

Question 1
Which of the following methods can be used to find the largest and smallest element in an array?
A
Recursion
B
Iteration
C
Both recursion and iteration
D
None of the mentioned
GK Questions answers

Question 1 Explanation: 
Both recursion and iteration can be used to find the largest and smallest element in an array.

Question 2
Consider the following iterative code snippet to find the largest element:

int get....max....element(int *arr, int n) { int i,  max....element = arr[0]; for(i = 1; i < n; i++) if(.....) max....element = arr[i]; return max....element; }

Which of the following lines should be inserted to complete the above code?

A
arr[i] > max....element
B
arr[i] < max....element
C
arr[i] == max....element
D
none of the mentioned
Microbiology Questions answers

Question 2 Explanation: 
The line "arr[i] > max....element" should be inserted to complete the above code snippet.

Question 3
Consider the following code snippet to find the smallest element in an array:

int get....min....element(int *arr,  int n) { int i,  min....element = arr[0]; for(i = 1; i < n; i++) if(.....) min....element = arr[i]; return min....element; }

Which of the following lines should be inserted to complete the above code?

A
arr[i] > min....element
B
arr[i] < min....element
C
arr[i] == min....element
D
none of the mentioned
Journalism Questions answers

Question 3 Explanation: 
The line "arr[i] < min....element" should be inserted to complete the above code.

Question 4
What is the output of the following code?

#include<stdio.h> int get....max....element(int *arr, int n) { int i,  max....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] > max....element) max....element = arr[i]; return max....element; } int get....min....element(int *arr,  int n) { int i,  min....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] < min....element) min....element = arr[i]; return min....element; } int main() { int n = 7,  arr[7] = {5, 2, 4, 7, 8, 1, 3}; int max....element = get....max....element(arr, n); int min....element = get....min....element(arr, n); printf("%d %d", max....element, min....element); return 0; }
A
5 3
B
3 5
C
8 1
D
1 8
Geography Questions answers

Question 4 Explanation: 
The program prints the values of the largest and the smallest elements in the array, which are 8 and 1 respectively.

Question 5
What is the output of the following code?

#include<stdio.h> int get....max....element(int *arr, int n) { int i,  max....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] > max....element) max....element = arr[i]; return max....element; } int get....min....element(int *arr,  int n) { int i,  min....element; for(i = 1; i < n; i++) if(arr[i] < min....element) min....element = arr[i]; return min....element; } int main() { int n = 7,  arr[7] = {1, 1, 1, 0, -1, -1, -1}; int max....element = get....max....element(arr, n); int min....element = get....min....element(arr, n); printf("%d %d", max....element, min....element); return 0; }
A
1 -1
B
-1 1
C
1 Garbage value
D
Garbage value -1
Geography Questions answers

Question 5 Explanation: 
Since the min....element variable is not initialised, the get....min....element() function will return a garbage value.

There are 5 questions to complete.

 

 Download all FREE PDF Ebook >>>CLICK HERE<<<