Introsort Multiple choice Questions and Answers (MCQs)

 

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

Introsort Multiple choice Questions and Answers (MCQs)

Click on any option to know the CORRECT ANSWERS

Question 16
What will be the output of the given C++ code?

#include <bits/stdc++.h>  using namespace std; int main() { int arr[] = {1, 3, 4, 2, 5}; int n = sizeof(arr)/sizeof(arr[0]); sort(arr,  arr+n,  greater<int>()); int a; for (a = 0; a < n; a++) cout << arr[a] << " "; return 0; }
A
1 2 3 4 5
B
1 3 4 2 5
C
5 4 3 2 1
D
error
Data interpretation (DI) Questions answers

Question 16 Explanation: 
The given program sorts the input in descending order. It is due to the third parameter i.e. greater() which is passed to the function sort().

Question 17
What will be the output of the given C++ code?

#include <bits/stdc++.h>  using namespace std; int main() { int arr[] = {1,  3, 4, 2, 5}; int n = sizeof(arr)/sizeof(arr[0]); sort(arr,  arr+n); int a; for ( a = 0; a< n; a++) cout << arr[a] << " "; return 0; }
A
1 2 3 4 5
B
1 3 4 2 5
C
5 4 3 2 1
D
error
Journalism Questions answers

Question 17 Explanation: 
The given program sorts the input in ascending order. Function sort() uses two parameters in the form of address of the first and last element of the array to sort the array.

Question 18
What will be the output of the given C++ code?

#include <bits/stdc++.h>  using namespace std; int main() { 	int arr[] = {1,  3, 4, 2, 5}; 	int n = sizeof(arr)/sizeof(arr[0]); 	sort(arr+2,  arr+n,  greater<int>()); int a; 	for (int a = 0; a < n; a++) 		cout << arr[a] << " "; 	return 0; }
A
1 2 3 4 5
B
1 5 4 3 2
C
5 4 3 2 1
D
1 3 5 4 2
Management Questions answers

Question 18 Explanation: 
As the first parameter to function sort() is arr+2 so the sorting begins from the third element i.e. 4. Also as there is a third argument greater () to the function sort() so the sorting will be done in descending order.

There are 18 questions to complete.

 

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