Internal Sorting: Quicksort-1:Sorting by Exchanging

本文介绍了快速排序算法,通过动画展示了算法过程,并探讨了选择最后一个元素作为枢轴可能导致的性能问题。文章提供了复杂性分析、伪代码、Java程序及输出结果。
摘要由CSDN通过智能技术生成

Quicksort-1:快速排序-1


Animation

quick sort
Animated visualization of the quicksort algorithm. The horizontal lines are pivot values.


这里写图片描述
Full example of quicksort on a random set of numbers. The shaded element is the pivot. It is always chosen as the last element of the partition. However, always choosing the last element in the partition as the pivot in this way results in poor performance ( O(n2) ) on already sorted arrays, or arrays of identical elements. Since sub-arrays of sorted / identical elements crop up a lot towards the end of a sorting procedure on a large set, versions of the quicksort algorithm which choose the pivot as the middle element run much more quickly than the algorithm described in this diagram on large sets of numbers.


Complexity

Class Sorting algorithm
Data structure Array
Worst case performance O(n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值