TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why Sorted Array Are Processed Faster Than Unsorted Array?

1 点作者 mayankj08超过 11 年前

2 条评论

dalke超过 11 年前
EDIT: What I wrote here is entirely wrong. I misread the use of &#x27;sorted&#x27;, and that colored my interpretation of the paragraph. My apologies.<p>&quot;Well, this is due to something called as Branch Prediction. Branch Prediction is a strategy used in processors to decide if the branch would be taken or not.&quot;<p>Emphatically false. Python&#x27;s sort is based on timsort. Timsort makes the observation that most real-world lists are partially sorted; either forward or reverse. This can help sorting go faster. The observed timing difference is nearly all to do with that, and not with branch prediction.<p>Consider the Shell sort. It&#x27;s O(n*n) for an unsorted list and O(n) for a sorted list. Again, nothing to do with branch prediction and everything to do with how well the data fits the algorithm&#x27;s expectations.
评论 #6320986 未加载
dalke超过 11 年前
That link now says &quot;Page Not Found&quot;. What happened to it?