Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What sort of inserts are there

Shulou Source: shulou.com Published: 2022-06-03 02:57:29 10月03日 Update

What this article shares with you is about the sort of insertions. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it with the editor.

There are two kinds of insertion sort: simple insertion sort and Hill sort. The time complexity of simple insertion sort is [O (N2) stable sort], and the time complexity of Hill sort is [related to the selection of incremental sequence, unstable sort].

Insert sort

Simple insert sort

A set of sequences to be sorted is divided into ordered and unsorted parts. in the initial state, the sorted sequence contains only the first element, and the element in the unsorted sequence is an element except the first one; then the elements in the unsorted sequence are inserted into the sorted sequence one by one. To and fro, if the number of elements in the unsorted sequence is 0 after NMMI is inserted once, the sorting is completed.

Time complexity: O (N2) stable sorting

Hill ranking

A group of elements to be sorted are divided into several sequences according to a certain interval, and are inserted and sorted respectively. The "interval" set at the beginning is larger, and the interval is gradually reduced in each round of sorting until the interval is 1, that is, the last step is to do a simple insert sort.

Time complexity: unstable sorting related to the selection of incremental sequences

The above are the insertion sort, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Sort sequence element complexity complexity time Hill related incremental more knowledge article part practical larger two number lieutenant general that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux Apple Redmi Docker