TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why Sorted Array Are Processed Faster Than Unsorted Array?

1 pointsby mayankj08over 11 years ago

2 comments

dalkeover 11 years ago
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 未加载
dalkeover 11 years ago
That link now says &quot;Page Not Found&quot;. What happened to it?