RadixSort

摘要: Radix sortis a non-comparativeintegersorting algorithmthat sorts data with integer keys by grouping keys by the individual digits which share the samesignificantposition and value. Apositional notationis required, but because integers can represent strings of characters (e.g., names or dates) and sp 阅读全文
posted @ 2013-03-31 10:41 melotang 阅读(266) 评论(0) 推荐(0)

CountingSort

摘要: Counting sortis analgorithmforsortinga collection of objects according to keys that are smallintegers; that is, it is aninteger sortingalgorithm. It operates by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each k 阅读全文
posted @ 2013-03-31 00:12 melotang 阅读(125) 评论(0) 推荐(0)

QuickSort

摘要: Quicksort, orpartition-exchange sort, is asorting algorithmthat,on average, makes O(nlogn) comparisons to sortnitems. In theworst case, it makes O(n2) comparisons, though this behavior is rare. Quicksort is often faster in practice than other O(nlogn) algorithms. 1 /* 2 * Best Average Worst ... 阅读全文
posted @ 2013-03-30 19:23 melotang 阅读(156) 评论(0) 推荐(0)

PriorityQueue

摘要: <Introduction to algorithm>A priority queue is a data structure for maintaining a set S of elements, eachwith an associated value called a key. A max-priority queue supports the followingoperations:INSERT.S; x/ inserts the element x into the set S, which is equivalent to the operationMAXIMUM.S 阅读全文
posted @ 2013-03-30 17:40 melotang 阅读(154) 评论(0) 推荐(0)

HeapSort

摘要: Heapsortis acomparison-basedsorting algorithmto create asorted array(or list), and is part of theselection sortfamily. Although somewhat slower in practice on most machines than a well-implementedquicksort, it has the advantage of a more favorable worst-caseO(nlogn) runtime. Heapsort is anin-place a 阅读全文
posted @ 2013-03-30 10:05 melotang 阅读(146) 评论(0) 推荐(0)

BuildMaxHeap

摘要: 1//O(nlogn) public class BuildMaxHeap { 2 3 private static int[] input = new int[] { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 }; 4 private static int heapSize = input.length; 5 6 public static void buildMaxHeap(){ 7 for(int i=heapSize/2;i>0;i--){ 8 maxHeapify(in... 阅读全文
posted @ 2013-03-29 23:52 melotang 阅读(400) 评论(0) 推荐(0)

MaxHeapify

摘要: Aheapis a specializedtree-baseddata structurethat satisfies theheap property:IfAis a parentnodeofBthen key(A) is ordered with respect to key(B) with the same ordering applying across the heap. Either the keys of parent nodes are always greater than or equal to those of the children and the highest k 阅读全文
posted @ 2013-03-29 22:29 melotang 阅读(252) 评论(0) 推荐(0)

BubbleSort

摘要: Bubble sort, is a simplesorting algorithmthat works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items andswappingthem if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. Th 阅读全文
posted @ 2013-03-29 16:19 melotang 阅读(152) 评论(0) 推荐(0)

BinaryInsertion

摘要: <Introduction to algorithm>Observe that the while loop of lines 5–7 of the INSERTION-SORT procedure inSection 2.1 uses a linear search to scan (backward) through the sorted subarrayAOE1 : : j  1. Can we use a binary search (see Exercise 2.3-5) instead to improvethe overall worst-case running 阅读全文
posted @ 2013-03-29 15:19 melotang 阅读(260) 评论(0) 推荐(0)

BinarySearch

摘要: binary searchorhalf-interval searchalgorithmfinds the position of a specified value (the input "key") within asorted array.In each step, the algorithm compares the input key value with the key value of the middle element of the array. If the keys match, then a matching element has been fou 阅读全文
posted @ 2013-03-29 10:38 melotang 阅读(165) 评论(0) 推荐(0)