Choose The Correct Function From The Following Which Determines #377
Choose the correct function from the following which determines the number of inversions in an array?
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Array Types - Count Inversion - Quiz No.1.
Choose the correct function from the following which determines the number of inversions in an array?
int InvCount(int arr[], int n) { int count = 0; for (int i = 0; i < n - 1; i++) for (int j = i ; j < n; j++) if (arr[i] >= arr[j]) count++; return count; }
int InvCount(int arr[], int n) { int count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (arr[i] > arr[j]) count++; return count; }
int InvCount(int arr[], int n) { int count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (arr[i] > arr[j]) count++; return count + 1; }
int InvCount(int arr[], int n) { int count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (arr[i] < arr[j]) count++; return count + 1; }
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes