如果选择的枢轴最小为1,则Quicksort帮助 [英] Quicksort help if the pivot chosen is least i.e 1

查看:88
本文介绍了如果选择的枢轴最小为1,则Quicksort帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用quicksort,我有一个问题说我有一个数组5 8 1 2 6我选择1作为枢轴然后没有比Pivot交换的元素..所以我的迭代怎么样变成..!



我尝试了什么:



了解quicksort,我明白最低的数字不应该被选为Pivot,因为它需要n2但是如果我试着去理解如果枢轴实际为1会发生什么。

解决方案

< blockquote>通过调试器运行代码,你会看到到底发生了什么。


Quote:

Quicksort帮助,如果选择的枢轴最小,即1



即使枢轴是最低值,一切都是一样的。

一个糟糕的枢轴选择是不幸的,只比数值中间的数据效率低,它是唯一的区别。

Quicksort - Wikipedia [ ^ ]


Hi All, I am trying to use quicksort and I have a question say i got an array 5 8 1 2 6 and I chose 1 as pivot then there are no elements less than Pivot to swap .. so how will my iteration turn into .. !

What I have tried:

understanding quicksort, i understand that lowest number shouldn't be chosen as Pivot as it will take n2 but if i am tryng to understand what happens if the pivot is actually 1.

解决方案

Run the code through your debugger and you will see exactly what happens.


Quote:

Quicksort help if the pivot chosen is least i.e 1


Even if pivot is lowest value, everything works the same.
A poor choice of pivot is just unfortunate and will be simply less efficient than a pivot than is in middle of values, its the only difference.
Quicksort - Wikipedia[^]


这篇关于如果选择的枢轴最小为1,则Quicksort帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆