• edited by
195 views
2 2 votes

Problem: Sort a file of huge records with tiny keys.

Example application: Reorganize your MP-$3$ files.

Which sorting method to use?

  1. a system sort, guaranteed to run in time $\sim N\log N$
     
  2. selection sort
     
  3. bubble sort
     
  4. a custom algorithm for huge records/tiny keys
     
  5. insertion sort

2 Answers

1 1 vote

Here, the important issue is data movement.

The records are huge, so exchanging or moving an entire record is expensive.

Bubble Sort and Insertion Sort can perform many exchanges or shifts. 

For randomly ordered data, the number of exchanges can be quadratic.

Selection Sort is different.

It searches for the correct element using comparisons and performs only about one exchange per pass.

Thus, $\text{Number of exchanges}\approx N$

even though the number of comparisons is $\sim\frac{N^2}{2}$

Since the keys are tiny, comparing them is relatively cheap. 

Since the records are huge, minimizing movement is much more important.

Selection Sort is best for this scenario because it avoids the large number of exchanges required by Insertion Sort and Bubble Sort.

Answer: B

Answer:
Position:
Show:

Related questions

1 1 vote
2 2 answers
173
173 views
GO Classes asked Aug 11
173 views
When is insertionsort a good choice for sorting an array?Each component of the array requires a large amount of memory. Each component of the array requires a small amoun...
1 1 vote
2 2 answers
175
175 views
GO Classes asked Aug 11
175 views
Suppose that a selectionsort of $100$ items has completed $42$ iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved...
1 1 vote
2 2 answers
173
173 views
GO Classes asked Aug 11
173 views
In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm?$1$ $n-1$ $n\log n$ $n^2$
2 2 votes
2 2 answers
185
185 views
GO Classes asked Aug 11
185 views
The nontrivial operation involved in the bubble sort is comparing two numbers, i.e., checking the $\texttt{if}$ condition in the inner $\texttt{for}$ loop.How many compar...