May 10th, 2014, 10:27 PM
Algorithm for sorting files on hard disk
Which algorithm is used for sorting files on hard disk?
May 12th, 2014, 04:10 AM
Re: Algorithm for sorting files on hard disk
If the file fits in memory you can read it into an array, sort it using the algorithm that comes with your language's standard library, and then write it back again.
Originally Posted by sayantika
The Java documentation offers this note,
"The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations."
In C++ you have a choise of three algorithms: sort, partial_sort and stable_sort. They're based on quicksort, heapsort and mergesort respectively most likely with modifications not to freak out on strange data sets.
If the file is too big for memory it's another ballgame,
Last edited by zizz; May 12th, 2014 at 04:19 AM.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!