PLEX86  x86- Virtual Machine (VM) Program
 CVS  |  Mailing List  |  Download  |  Newsgroups

The Bubble Sort 2464


Your Ad Here

Your Ad Here

Charles Richmond

Insertion sort takes the next unsorted item and searches the sorted item list to find where to insert it in order.

The Bubble Sort 2466
Greg Menke) writes: One advantage of an insertion sort is that the table stays in sequence as you build it. This is good if you're looking things up...

Selection sort searches the unsorted item list to find the smallest item, then adds it to the end of the sorted item list.

Either sort can be done in place, moving the block of items between the insertion point (insertion sort) or end of the currently sorted items (selection sort) and the next unsorted item (insertion sort) or the selected item (selection sort) down one item to create space for the inserted-selected item.

The Bubble Sort 2467
Charlie Gibbs wrote On 10-25-05 13:35,: Um, er, I was referring to something different: Not a procedure that keeps...

Obviously you can also do them using separate memory areas for the unsorted and sorted items, at a cost of the extra space, but saving some time.

The Bubble Sort 2465
Charles Richmond Hi Why not use a distribution sort. While quicksort works well for a small number of items, as the items increase...

You can also do insertion sort from an input stream, but not selection sort, as you can't know the smallest item remaining if you haven't input it yet.

For external sorting, you can, however use either method from an input stream for the preliminary sorts before a merge. You read as many items as you can into memory, sort them and write out the sorted list, then repeat until done, and start the merge.

A variant of this is replacement selection sort, where you fill the input area, write out the smallest unmarked item and replace it with a new input item. If the new item is smaller than than the last output item, it won't fit into the current sorted list, so you mark it. Repeat until all items in the input area are marked, when you terminate the current output list, clear all marks and start the next output list with the smallest item currently in the input. This give initial sorted strings on average twice as long as straight replacement, typically saves one phase of merge.

--brian

-- "What's life? Life's easy. A quirk of matter. Nature's way of keeping meat fresh."



Your Ad Here

List | Previous | Next

The Bubble Sort 2465

Alt Folklore Computers from Newsgroups

The #1 Usenet Provider on the Internet

Random Access Tape 2463