# YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

## Bogosort Multiple choice Questions and Answers (MCQs)

Question 6 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

Which of the following sorting algorithm is not stable .....

insertion sort | |

bubble sort | |

merge sort | |

bogosort |

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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

Which of the following is an in-place sorting algorithm?

Merge sort | |

Bogosort | |

Radix sort | |

Counting sort |

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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

Sleep sort should be preferred over bogosort as it has better time complexity.

true | |

false |

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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What is the average case time complexity of bogosort?

O(n ^{2}) | |

O(n*n!) | |

O(infinity) | |

O(n log n) |

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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

Which of the following code correctly implements bogosort algorithm?

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

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

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

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

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.