Massive amounts of data

If you have a 2.25 GB 2.25 \text{ GB} file with one string per line, which sorting algorithm would you use to sort the file?

Assume the available memory RAM is N MB N \text{ MB} of memory, where N 100 N \leq 100 .

Selection Sort External sort Heap Sort Binary Tree Sort Bubble sort

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Ossama Ismail
Jan 11, 2017

The expected answer is External sort.

Bubble sort is only good for data sets that are already almost sorted.

Otherwise, it is time-consuming because it requires O( n 2 n^2 ) time, where n n is the size of input data.

A size limit of 2.25 G B 2.25 \ GB , tells you that, don’t bring all the data into memory. You only bring part of the data into memory.

A l g o r i t h m : Algorithm:

Assume that you have N M B N\ MB of memory available, where N 100 N \leq 100 .

  1. Divide the 2.25 G B 2.25 \ GB file into K K chunks, where N × K = 2.25 G B N \times K = 2.25 \ GB .

  2. Bring each chunk into memory and sort the N M B N \ MB lines, as usual, using any known O ( N l o g N ) O(N \ log \ N) algorithm. Save the lines back to the file.

  3. Bring the next chunk into memory and sort.

  4. Once you’re done, merge them one by one.

The above algorithm is known as e x t e r n a l s o r t external \ sort algorithm.

I changed the problem statement from 50 MB to 100 MB because you mentioned so in the solution.

Agnishom Chattopadhyay - 4 years, 5 months ago

Log in to reply

Ok thanks....

Ossama Ismail - 4 years, 5 months ago

Why is bogo sort not in options 😂

Sabhrant Sachan - 4 years, 4 months ago

Log in to reply

I do not recommend this type of sort in any application. It is ineffective sorting algorithm.

Ossama Ismail - 4 years, 4 months ago

Log in to reply

Yes , Bogo sort --> O(n!)

Sabhrant Sachan - 4 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...