Insertion sorting of Java data structures
•
Java
Insert sort is to insert the elements to be sorted into an ordered list. A very vivid example is to grab a poker card with your right hand and insert it into the ordered poker held in your left hand.
The worst run time of insertion sort is O (N2), so it is not the optimal sort algorithm.
If the input array is already in good order, the insertion sort is the best, and its running time is a linear function of the input scale.
If the input array is arranged in reverse order, the worst case occurs. The average case is the same as the worst case, and the time cost is Θ (n2)。
Simple example:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码