为什么堆排序不稳定? [英] Why isn't heapsort stable?

查看:1936
本文介绍了为什么堆排序不稳定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解为什么heapsort不稳定. 我已经用谷歌搜索过,但是没有找到一个很好的,直观的解释.

I'm trying to understand why heapsort isn't stable. I've googled this, but haven't found a good, intuitive explanation.

我了解稳定排序的重要性-它使我们能够基于多个键进行排序,这非常有益(即,进行多种排序,每种基于不同的键进行.因为每种排序都会保留相对顺序元素的总和,以前的排序可以累加得出通过多个条件排序的元素的最终列表). 但是,为什么堆排序也不能保留呢?

I understand the importance of stable sorting - it allows us to sort based on more than one key, which can be very beneficial (i.e., do multiple sortings, each based on a different key. Since every sort will preserve the relative order of elements, previous sortings can add up to give a final list of elements sorted by multiple criteria). However, why wouldn't heapsort preserve this as well?

感谢您的帮助!

推荐答案

heapsort的结果的最终顺序是从创建的堆中纯粹以大小顺序(基于键字段)删除项目.

The final sequence of the results from heapsort comes from removing items from the created heap in purely size order (based on the key field).

有关堆中原始序列中项目顺序的任何信息都在堆创建阶段(首先出现的阶段)中丢失了.

Any information about the ordering of the items in the original sequence was lost during the heap creation stage, which came first.

这篇关于为什么堆排序不稳定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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