1. Heap sorting not only has the same time complexity as the merge sort O (NLGN), but also the space complexity occupies an extra number of elements space, this has the advantage of inserting sort.2. Heap sorting is divided into 3
Len is the number of elements in the heap. The process of building the heap is a linear process, from LEN/2 to 0 has been called to adjust the heap process, equivalent to O (H1) +o (H2) ... +o (HLEN/2) where h represents the depth of the node, LEN/2 represents the number of nodes, this is a summation process, the result is a linear O (n). ② adjustment
some properties are prioritized, sorted by low priority, then sorted by high priority, and the final order is high priority high, high priority is the same low-priority high. Base sorting is based on sorting separately and is collected separately, so it is a stable sorting algorithm.
(7) Hill sort (shell)
Hill sort is the insertion of elements according to different steps, when the first element is very di
001
#include
002
#include
003
int main ()
004
{
005
int l[11]={0,70,38,65,97,76,93,1,15,68,64}; 0 do not sort just as sentinels, or temporarily swap space for use.
006
int i=0;
007
printf ("Unordered pre-sequence: \ n");
008
for (i=1;i
009
{
Heap Sorting algorithm
First, the basic characteristics of heap sorting algorithmComplexity of Time: O (N*LGN)Worst: O (N*LGN)Complexity of Space: O (1)Not stable.
Heap sorting is a sort of selection algorithm, which is independent of the initial order of keywords, that is,
The heap sort contains two steps:
The first step: is to establish a large top heap (from large to small sort) or a small top heap (from little to large sort), from the bottom up; When the hea
Heap sorting is an efficient algorithm using heap sequencing, which can realize O (nlogn) Sorting time complexity, and the algorithm can analyze the time complexity of heap sorting algorithm.Algorithm implementation:To adjust the heap:void
reduced (the last number is removed), and then the first number is adjusted downwards, the largest number is the last. Until there is only one number in the heap.The process of building the heap is from the last non-leaf node until the node is adjusted downwards. Let's say we're going to sort in ascending order. That is, when the downward adjustment, the small swap to the parent node.650) this.width=650; "
Select sortHow it works: each time the largest or smallest element is selected from the data element to be sorted, it is stored at the beginning of the sequence until all the data elements to be sorted are exhausted.Voidselectsort (int*a,size_tsize) {assert (a); for (inti=0;iHeap Sortonly needAscending Voidadjustdown (int*a,size_tsize,introot) { ASSERT (a);intchild=root*2+1; while (childThis article from "Write Quality or Low" blog, declined reprint!Sort
Heap sorting is a sort of tree selection, which is an effective improvement on direct selection Sorting.Basic Idea:The heap is defined as follows: a sequence with n elements (k1,k2,..., kn), when and only if it satisfiesis called a heap. As can be seen from the definition of a heap
variable to the value on the first position in the unordered area for(intj = i +1; J if(Datas[j] //Exchange two values inttemp = Datas[i]; Datas[i] = MinValue; DATAS[J] = temp; } } } } Public Static void Main(string[] args) {int[] Datas =New int[] {8,5,2,6,9,3,1,4,0,7}; System.out.println ("******** sort before ********"); for(inti =0; i ","); } Selectsort Selectsor
Heap sorting is a sort of selection, with a time complexity of O (Nlogn).Definition of a heapThe sequence of n elements, {k1,k2,...,kn}, is called a heap when and only if one of the following relationships is met.Case 1:ki minimized heap or small top
the heap, it is necessary to the current unordered area (R1,R2,...... Rn-1) is adjusted to the new heap, and then again R[1] is exchanged with the last element of the unordered area to get the new unordered area (R1,R2 ...). Rn-2) and a new ordered region (RN-1,RN). Repeat this process until the number of elements in the ordered area is n-1, the entire sort proc
Heap sorting is a sort of selection, with a time complexity of O (Nlogn).Definition of a heapThe sequence of n elements, {k1,k2,...,kn}, is called a heap when and only if one of the following relationships is met.Case 1:ki minimized heap or small top
binary tree, satisfies any node is smaller than its child node; Features: Minimal elements appear on the root nodeNote: When the left and right subtree of the root node is a heap, but itself is not a heap, it can be transformed into a heap by a downward adjustment. Heap sort
PHP implements Heap Sort and heap
Algorithm introduction:
Here I directly reference the beginning of "big talk Data Structure:
As mentioned above, simply select sorting. It needs to be compared n-1 times to select the smallest record among the n records to be sorted. This can also be understood, it is normal that the first data needs to be compared so many times;
Heap sort Ah, actually is a data structure, binary tree, binary tree is divided into two fork tree and complete binary tree. A depth of k, and there are 2k-1 nodes called full two fork tree, complete binary tree: The depth of k, there are n nodes of the two-tree, when and only if each of its nodes with a depth of k in the full two-tree with a number of 1 to n nodes corresponding to the node, called a comple
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.