JSort

JSort

JSort is an in-place sort algorithm that uses build heap twice to largely order the array then finishes with an insertion sort. JSort is attributed to Jason Morrison. [ [http://cg.scs.carleton.ca/~morin/misc/sortalg/JSortAlgorithm.java Code] for a JSort visualization, in Java.]

The first build heap pass converts the array to a heap, with the least item in the root, which is in the first position of the array. The second build heap pass works in reverse, with the "greatest" item in root, which is in the last position for this pass. The largely-ordered array is finally sorted with insertion sort. Since insertion sort would do all the sorting by itself, the two passes with build heap only save it work, which could be significant.

Build heap partially orders the array very fast, since items may be moved a long way, up to half the length of the array. Items nearer the root are more likely to be in order, since few items were compared with each other. The farther from the root, the more likely items are significantly out of order, since they are not compared with each other, only with their parents. Thus items at the leaves are likely quite unordered, which would cause insertion sort to take a long time.

The second pass reverses the heap and puts the root at the last position in the array. It also reverses the heap sense, so the largest item is at the root. Thus the second pass follows the same general order as the first pass, lesser items near the first position and greater items near the last position, but works more at the last positions. The second pass, then, does most of its work exactly where the first pass did little. Together the two passes mostly order the array. The final insertion sort can run relatively quickly.

ee also

* J sort

External links

References

*


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Merge sort — Example of merge sort sorting a list of random dots. Class Sorting algorithm Data structure Array Worst case performance O(n log n) …   Wikipedia

  • Pigeonhole sort — Class Sorting algorithm Data structure Array Worst case performance O(N + n), where N is the range of key values and n is the input size Worst case space complexity O(N * n) …   Wikipedia

  • Sorting algorithm — In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other… …   Wikipedia

  • Counting sort — In computer science, counting sort is an algorithm for sorting a collection of objects according to keys that are small integers; that is, it is an integer sorting algorithm. It operates by counting the number of objects that have each distinct… …   Wikipedia

  • Bogosort — Class Sorting algorithm Data structure Array Worst case performance [1] Best case performance Ω …   Wikipedia

  • Comb sort — Class Sorting algorithm Data structure Array Worst case performance O(n log n)[1] …   Wikipedia

  • Cocktail sort — Class Sorting algorithm Data structure Array Worst case performance О(n²) Best case performance O(n) …   Wikipedia

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

  • Topological sorting — Dependency resolution redirects here. For other uses, see Dependency (disambiguation). In computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that, for every edge uv, u comes… …   Wikipedia

  • J sort — is an in place sort algorithm that uses strand sort to sort fewer than about 40 items and shuffle sort to sort more. John Cohen claimed to have invented this algorithm. [ [http://groups.google.com/group/fido7.ru.algorithms/msg/26084cdb04008ab3… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”