Note that there are some explanatory texts on larger screens.

plurals
  1. POEasiest to implement online sorted data structure in C
    primarykey
    data
    text
    <p>I'm scanning a large data source, currently about 8 million entries, extracting on string per entry, which I want in alphabetical order.</p> <p>Currenlty I put them in an array then sort an index to them using <code>qsort()</code> which works fine.</p> <p>But out of curiosity I'm thinking of instead inserting each string into a data structure that maintains them in alphabetical order as I scan them from the data source, partly for the experience of emlplementing one, partly because it will feel faster without the wait for the sort to complete after the scan has completed (-:</p> <p>What data structure would be the most straightforward to implement in C?</p> <p><strong>UPDATE</strong></p> <p>To clarify, the only operations I need to perform are inserting an item and dumping the index when it's done, by which I mean for each item in the original order dump an integer representing the order it is in after sorting.</p> <p><strong>SUMMARY</strong></p> <ul> <li>The easiest to implement are binary search trees.</li> <li>Self balancing binary trees are much better but nontrivial to implement.</li> <li>Insertion can be done iteratively but in-order traversal for dumping the results and post-order traversal for deleting the tree when done both require either recursion or an explicit stack.</li> <li>Without implementing balancing, runs of ordered input will result in the degenerate worst case which is a linked list. This means deep trees which severely impact the speed of the insert operation.</li> <li>Shuffling the input slightly can break up ordered input significantly and is easier to implement that balancing.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload