What is the most inefficient of the quadratic sorts we have studied in class?
| A. | They are all equally bad. | |
| B. | Bubble sort | |
| C. | Insertion sort | |
| D. | Selection sort |
The O(n 2) family of algorithms are conceptually the simplest, and in some cases very fast. The swap operation is fundamental to both the bubble sort and the selection sort. Insertion sort works by selecting the smallest values and inserting them in the proper order by shifting the higher values right. A common characteristic of quadratic algorithms is nested looping, where each item in the list is compared to every other item in the list, (n * n) or (n 2).
While Insertion sort typically makes fewer comparisons than Selection sort, it requires more writes because the inner loop can require shifting large sections of the sorted portion of the data set. In general, Insertion sort perform O(n 2) writes, whereas Selection sort will only perform O(n) writes. For this reason Selection sort may be preferable in cases where writing to memory is more expensive than reading.
So : Selection sort
What is the most inefficient of the quadratic sorts we have studied in class? A. They...