Bogosort Multiple choice Questions and Answers (MCQs)

 

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

Bogosort Multiple choice Questions and Answers (MCQs)

Click on any option to know the CORRECT ANSWERS

Question 6
Which of the following sorting algorithm is not stable .....
A
insertion sort
B
bubble sort
C
merge sort
D
bogosort
Reasoning Questions answers


Question 6 Explanation: 
Out of the given algorithms only bogosort is not stable. This is because it creates permutations of the input array in order to obtain the sorted version. So there is no guarantee that the sorted version obtained by such a method gives a stable output.

Question 7
Which of the following is an in-place sorting algorithm?
A
Merge sort
B
Bogosort
C
Radix sort
D
Counting sort
Education Questions answers


Question 7 Explanation: 
Out of the given algorithms only bogosort is an in-place sorting algorithm. It is because bogosort algorithm do not require any extra space for sorting the input array.

Question 8
Sleep sort should be preferred over bogosort as it has better time complexity.
A
true
B
false
Computer science Questions answers


Question 8 Explanation: 
If we sort an array using sleep sort then there is no guarantee that the output we get is correctly sorted. So even though sleep sort is better than bogosort in time complexity but it cannot be preferred due to its inaccuracy.

Question 9
What is the average case time complexity of bogosort?
A
O(n2)
B
O(n*n!)
C
O(infinity)
D
O(n log n)
Reading comprehension Questions answers


Question 9 Explanation: 
For calculating the average we first need to calculate the number of possible permutations an array of size n can have. This will be equal to n!. As each permutation also needs to be checked whether it is sorted or not so this takes another n time. Thus overall time complexity becomes O(n*n!).

Question 10
Which of the following code correctly implements bogosort algorithm?
A

bool isSorted(int a[],  int n) { while ( --n > 1 ) if (a[n] < a[n-1]) return fals
B

bool isSorted(int a[],  int n) { while ( --n > 1 ) if (a[n] < a[n-1])<
C

bool isSorted(int a[],  int n) { while ( --n > 1 ) if (a[n] > a[n-1]) return true
D

bool isSorted(int a[],  int n) { while ( --n > 1 ) if (a[n] < a[n-1]) return false<
Aptitude test Questions answers


Question 10 Explanation: 
To implement bogosort algorithm we need to shuffle the input array until we get the sorted array. So we first check whether the array is sorted using function isSorted(). If it is not, then we shuffle it using function shuffle(). This process is repeated until we get a sorted array.

There are 10 questions to complete.

 

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