Which Of The Following Function Represents Pigeonhole Sort #894
Which of the following function represents pigeonhole sort correctly?
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 - Pigeonhole Sort - Quiz No.2.
Which of the following function represents pigeonhole sort correctly?
void Sorting(int arr[], int n) { int minimum = arr[0], maximum = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < minimum) minimum = arr[i]; if (arr[i] > maximum) maximum = arr[i]; } int r = maximum - minimum + 1; vector<int> p_holes[r]; for (int i = 0; i < n; i++) p_holes[arr[i]-minimum].push_back(arr[i]); int ind = 0; for (int i = 0; i < r; i++) { vector<int>::iterator it; for (it = p_holes[i].begin(); it != p_holes[i].end(); ++it) arr[ind++] = *it; } }
void Sorting(int arr[], int n) { int minimum = arr[0], maximum = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < minimum) minimum = arr[i]; if (arr[i] > maximum) maximum = arr[i]; } int r = maximum - minimum + 1; vector<int> p_holes[n]; for (int i = 0; i < n; i++) p_holes[arr[i]-minimum].push_back(arr[i]); int ind = 0; for (int i = 0; i < r; i++) { vector<int>::iterator it; for (it = p_holes[i].begin(); it != p_holes[i].end(); ++it) arr[ind++] = *it; } }
void Sorting(int arr[], int n) { int minimum = arr[0], maximum = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < minimum) minimum = arr[i]; if (arr[i] > maximum) maximum = arr[i]; } int r = maximum - minimum + 1; vector<int> p_holes[r]; for (int i = 0; i < n; i++) p_holes[arr[i]-minimum].push_back(arr[i]); int ind = 0; for (int i = 0; i < n; i++) { vector<int>::iterator it; for (it = p_holes[i].begin(); it != p_holes[i].end(); ++it) arr[ind++] = *it; } }
void Sorting(int arr[], int n) { int minimum = arr[0], maximum = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < minimum) minimum = arr[i]; if (arr[i] > maximum) maximum = arr[i]; } int r = maximum - minimum + 1; vector<int> p_holes[n]; for (int i = 0; i < n; i++) p_holes[arr[i]-minimum].push_back(arr[i]); int ind = 0; for (int i = 0; i < n; i++) { vector<int>::iterator it; for (it = p_holes[i].begin(); it != p_holes[i].end(); ++it) arr[ind++] = *it; } }
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