101k views
0 votes
Your task is to sort an array of students based on their credits completed and their CGPAs for assigning advising slots to them. Which sorting algorithm is most suitable for this task?

a) Bubble Sort
b) Quick Sort
c) Merge Sort
d) Insertion Sort

1 Answer

6 votes

Final answer:

Merge Sort is the most suitable sorting algorithm for this task as it can handle multiple criteria for sorting. It has a time complexity of O(n log n) and is efficient and stable.

Step-by-step explanation:

In this case, the most suitable sorting algorithm would be Merge Sort. Merge Sort is a efficient and stable sorting algorithm that has a time complexity of O(n log n). It works by recursively dividing the input array into smaller subarrays, sorting them individually, and then merging them back together.

In the given task, we need to sort the array of students based on two criteria: credits completed and CGPAs. Merge Sort is suitable because it can handle two or more criteria for sorting. We can compare the credits completed first and then use the CGPAs as a tiebreaker if two students have the same number of credits completed.

For example, let's say we have the following array of students:

  • John: 90 credits, CGPA: 3.5
  • Sarah: 80 credits, CGPA: 4.0
  • Michael: 90 credits, CGPA: 3.7

Using Merge Sort, we would divide the array into smaller subarrays, sort them based on credits completed, and then use the CGPAs for tiebreaking. The final sorted array would be:

  • Sarah: 80 credits, CGPA: 4.0
  • Michael: 90 credits, CGPA: 3.7
  • John: 90 credits, CGPA: 3.5

User Oiva Eskola
by
8.4k points