Algorithm for sorting files on hard disk
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Algorithm for sorting files on hard disk

  1. #1
    Join Date
    May 2014
    Posts
    1

    Algorithm for sorting files on hard disk

    Which algorithm is used for sorting files on hard disk?

  2. #2
    Join Date
    Aug 2013
    Posts
    55

    Re: Algorithm for sorting files on hard disk

    Quote Originally Posted by sayantika View Post
    Which algorithm is used 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.

    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,

    http://en.wikipedia.org/wiki/External_sorting
    Last edited by zizz; May 12th, 2014 at 03:19 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center