Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting 10GB Data in 1 GB memory. How will I do it?

Tags:

Here is the problem: I have only 1GB RAM in computer. I have a text file of 10 GB data.This file contains numbers. How will I sort them?

Adding some more details.

 -They are all integers like 10000, 16723998 etc.     -same integer values can be repeatedly appearing in the file. 
like image 756
WinW Avatar asked Aug 07 '11 16:08

WinW


People also ask

How do I sort large files with small memory?

Suppose we have to sort a 1GB file of random integers and the available ram size is 200 Mb, how will it be done? The easiest way to do this is to use external sorting. We divide our source file into temporary files of size equal to the size of the RAM and first sort these files.

Which sorting technique will be most appropriate to sort 1.2 GB of data with only one 20 MB available main memory?

Which sorting technique will be most appropriate? Explanation: The data can be sorted using external sorting which uses merging technique.


1 Answers

split the file into parts (buffers) that you can sort in-place

then when all buffers are sorted take 2 (or more) at the time and merge them (like merge sort) until there's only 1 buffer remaining which will be the sorted file

like image 73
ratchet freak Avatar answered Sep 19 '22 11:09

ratchet freak