sorted()函数的复杂度是多少? [英] What is the complexity of the sorted() function?

查看:47
本文介绍了sorted()函数的复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表列表,我正在使用以下内容对其进行排序

I have a list of lists and I am sorting them using the following

data=sorted(data, key=itemgetter(0))

想知道此python函数的运行时复杂度是什么吗?

Was wondering what is the runtime complexity of this python function?

推荐答案

data一起使用时,提供的 itemgetter(0) O(1) ,在平均情况和最坏的情况下,排序均为 O(n log n).

有关Python中使用的排序方法的更多信息,请参见维基百科.

For more information on the sorting method used in Python, see Wikipedia.

这篇关于sorted()函数的复杂度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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