为什么要对字符串O(n log n)进行排序?

编程入门 行业动态 更新时间:2024-10-09 17:19:34
本文介绍了为什么要对字符串O(n log n)进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 大O的简单英语解释

回答编程难题的原因是,对字符串进行排序需要O(n log n)时间。 它是如何得出的?

In the answer to a programming puzzle it said sorting a string takes O(n log n) time. How is that derived?

有人对Big O资源有很好的参考链接。

Does anybody have a good reference link for Big O resources.

谢谢

推荐答案

为什么要对字符串O(n log n)进行排序?

Why is sorting a string O(n log n)?

对字符串中的字符进行排序不一定是O(n log n)。

Sorting the characters in a string is not necessarily O(n log n).

  • O(n log n)是最优值。 >比较排序。这也是许多语言默认排序实现的复杂性。但是,当然可以做得比这更糟。对字符串中的字符进行排序的复杂程度取决于您选择用于解决此任务的特定算法。
  • 在某些情况下,通过使用O(n log n)也可能会做得更好不是比较排序的排序算法。例如,如果您知道ASCII字符串最多包含127个不同的字符,则可以使用计数排序为O(n)。对于所有字符都在基本多语言平面。
  • O(n log n) is the optimal value for a comparison sort. It is also the complexity of many languages' default sort implementation. However it's certainly possible to do worse than this. The complexity of sorting the characters in a string depends on the specific algorithm you choose to solve this task.
  • It's also possible to do better than O(n log n) in some cases by using a sorting algorithm which is not a comparison sort. For example, if you know that you have an ASCII string with a maximum of 127 distinct characters you could use a counting sort which is O(n). A counting sort would also be feasible for Unicode strings where all characters are in in the Basic Multilingual Plane.

更多推荐

为什么要对字符串O(n log n)进行排序?

本文发布于:2023-11-29 09:01:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   为什么要对   log

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!