二分查找小结

Posted shiina922

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二分查找小结相关的知识,希望对你有一定的参考价值。

Templates

技术图片

These templates come from LeetCode.

Tips

The tip below comes from LeetCode 278. First Bad Version.

If you are setting mid = (left+right) / 2, you have to be very careful. Unless you are using a language that does not overflow such as Python, left + right could overflow. One way to fix this is to use left + (right-left)/2 instead.

If you fall into this subtle overflow bug, you are not alone. Even Jon Bentley‘s own implementation of binary search had this overflow bug and remained undetected for over twenty years.

以上是关于二分查找小结的主要内容,如果未能解决你的问题,请参考以下文章

二分查找小结

LeetCode Binary Search Summary 二分搜索法小结

二分查找法

“红黑树”小结

第七章学习小结

数据结构