before self-study data structure of the time to see the C language version of the four basic sorting method, C language is almost forgotten, recently available in PHP four sort method to re-write again, review the increasingly unfamiliar algorithm. Paste the code directly.
"; Print_r ($var); echo "";} $arr =array (33,11,22,66,55,44,88,99,77);p rintf ("* * Original array * *");p($arr);/*** Bubble
the time complexity of O (N) sorting algorithm:
The algorithm of Time Complexity O (N) has cardinal sort, counting sort, but both of them need to know the range of the elements in advance so as to build the number of buckets, so it is not appropriate to solve this problem. Exclude!
2, for the time comple
Heap sort and quick sort, merging sort are all the common sorts of time complexity O (N*LOGN). Before learning heap sorting, first explain what is the data structure of the two-fork heap.
The definition of a binary
First, prefaceIf you need a Java version of the heap ordering or the basics of heap sorting-the concept of a tree, see my blog "Sorting algorithm (ii) heap sorting"Questions about choosing a sortThe problem of choosing the most sort is not knowing whether the sorted data is
); }}Four-heap sorting algorithmInitially, the heap sorting algorithm uses BUILD-MAX-HEAP to build the largest heap of input array arr[0...n-1]. Because the largest element in the array is always in the root node arr[0], by swapping it with arr[n-1], we can put the elemen
Topic Information1098. Insertion or Heap Sort (25)Time limit (MS)Memory Limit 65536 KBCode length limit 16000 BAccording to Wikipedia:Insertion sort iterates, consuming one INPUT element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the
The heap can be regarded as a complete two-fork tree, with the exception of the lowest level, where each layer is full, which allows the heap to be represented by an array, with each node corresponding to an element in the array.
The relationship between the array and the heap:
Binary heaps are generally divided into two types: maximum
One, what is a heapA heap is a complete binary tree with the following properties. Each node is greater than or equal to the value of its left and right child nodes, called the Big Top heap.Or the value of each node is less than or equal to the value of the left and right child nodes, called the small top heap.Second, if you sort by heapAs defined by the heap, th
The previous article summarizes the bubble sort and quick sort of the interchange sort. This article summarizes the selection of sorting, the choice of sorting is divided into direct selection of sorting and heap sorting, mainly from the following points to summarize.1. Direct selection sequencing and
million, but if you remove the duplicates, no more than 3 million. The higher the repetition of a query string, the more users are queried for it, the more popular it is, please count the hottest 10 query strings, which requires no more than 1G of memory.Solution: Although there are 10 million query, but because of the high repetition, so in fact only 3 million of the query, each query255byte, (300w*255b
Hash statistics: This batch of massive data preprocessing (maintain a key for the
Hill SortPackage Shellsort;import utils.sortutils; Public classDemo { Public Static void Shellsort(int[] a) {intTemp,j;intincrement = A.length; Do{increment = increment/3+1;//If it is a direct insert sort, the increment here are 1. //system.out.println (increment); for(inti = increment; i if(A[i]//Staged in temp for(J=i-increment; j>=0 a[j]>temp; j-=increment) {A[j+increment] = a[j];//record and move back to
The previous article used the Quicksort method to sort, but if the rapid sorting method for high repetition rate of slice, time complexity will soar, the speed is quite slow, so try to heap sorting, experimental results, feel very good. Here is the code, you can refer to, This is the building of the big top pile. Two fork tree features: Last Non-leaf node: root = LENGTH/2 (root down rounding when length is
Title Addresshttps://pta.patest.cn/pta/test/16/exam/4/question/6765-14 insertion or Heap Sort (25 points)According to Wikipedia:Insertion Sort Iterates, consuming one INPUT element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the locati
Objective:Thick one of the "algorithm fourth edition", see One-fifth has benefited a lot, and the top one-fifth is about the sort, bubble sort, quick sort, heap sort, direct insertion sort
In the external links below, fromHill sort
The essence of the hill sort is the grouping insert sort, which is also known as narrowing the incremental sort, because of the DL. The shell was named after it was introduced in 1959.
In fact, the so-called increment is the first number after the beginning of a
#include The heap can be seen as a complete binary tree, and the small heap sort takes advantage of the smallest of keywords in the top record of a small root heap, making it easy to select the smallest keyword from the current unordered area and further record the operation.C + +
, test scores are the sort of key words. In practice, the attribute used by each datasheet as a sort key depends on the specific application needs.
There are many ways to sort, and in terms of their overall performance it is difficult to propose a method that is considered the best, each with its own advantages and disadvantages, and suitable for use in differen
the I node is2*i+1and the2*i+2. 3, Heap sorting algorithm implementation (maximum heap)#include 4, the time complexity of the heap and the complexity of spacethe best, worst, and average time complexity of the heap is O (nlogn).the space complexity of the
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.