Which Of The Following Code Correctly Implements Bogosort #871
Which of the following code correctly implements bogosort algorithm?
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Sorting - Bogosort - Quiz No.1.
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 false; return true; } void shuffle(int a[], int n) { for (int i=0; i < n; i++) swap(a[i], a[rand()%n]); } void bogosort(int a[], int n) { while ( !isSorted(a, n) ) shuffle(a, n); }
bool isSorted(int a[], int n) { while ( --n > 1 ) if (a[n] < a[n-1]) return true; return false; } void shuffle(int a[], int n) { for (int i=0; i < n; i++) swap(a[i], a[rand()%n]); } void bogosort(int a[], int n) { while ( !isSorted(a, n) ) shuffle(a, n); }
bool isSorted(int a[], int n) { while ( --n > 1 ) if (a[n] > a[n-1]) return true; return false; } void shuffle(int a[], int n) { for (int i=0; i < n; i++) swap(a[i], a[rand()%n]); } void bogosort(int a[], int n) { while ( !isSorted(a, n) ) shuffle(a, n); }
bool isSorted(int a[], int n) { while ( --n > 1 ) if (a[n] < a[n-1]) return false; return true; } void shuffle(int a[], int n) { for (int i=0; i < n; i++) swap(a[i], a[rand()%n]); } void bogosort(int a[], int n) { while ( isSorted(a, n) ) shuffle(a, n); }
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes