当前位置:网站首页>Binary search basis
Binary search basis
2022-07-05 05:16:00 【lee2813】
One 、 Two points search
First , It is clear that the premise of binary search is for ordered arrays , Then the significance of binary search on this basis is to use the order of data structure to simplify the time and space overhead of the algorithm .
in addition , Binary search is the same as double pointer traversal array , But the difference is that binary search moves every time ‘ Half interval ’ length , The double pointer problem moves step by step .
Two 、 classification
The standard of classification here is the method to solve the problem :
- The interval is defined as left closed and right closed , The corresponding boundary condition is
l<=r
, Because when there is only one number left , Still reasonable , for example[5,5]
, At this time, it is written as :
int l = 0;
int r = nums.size()-1;
while(l<=r){
mid = (l+r)/2;
...
}
- The interval is defined as left closed and right open , The corresponding boundary condition is
l<r
, Because when there is only one number left , unreasonable , for example[5,5)
, and[5,6)
reasonable , At this time, it is written as :
int l = 0;
int r = nums.size();
while(l<r){
mid = (l+r)/2;
...
}
Both can solve the problem , But there are some differences in writing , It is suggested to learn one .
边栏推荐
- 3dsmax2018 common operations and some shortcut keys of editable polygons
- Collapse of adjacent vertical outer margins
- 质量体系建设之路的分分合合
- 支持多模多态 GBase 8c数据库持续创新重磅升级
- PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
- Shell Sort
- 小程序直播+電商,想做新零售電商就用它吧!
- Development error notes
- Unity intelligent NPC production -- pre judgment walking (method 1)
- Unity ugui source code graphic
猜你喜欢
Panel panel of UI
Count sort
用 Jmeter 工具做个小型压力测试
C language Essay 1
The present is a gift from heaven -- a film review of the journey of the soul
LeetCode之單詞搜索(回溯法求解)
3dsmax scanning function point connection drawing connection line
Embedded database development programming (V) -- DQL
2021-10-29
Establish cloth effect in 10 seconds
随机推荐
Reverse one-way linked list of interview questions
Es module and commonjs learning notes -- ESM and CJS used in nodejs
C语言杂谈1
Optimization scheme of win10 virtual machine cluster
Unity find the coordinates of a point on the circle
Grail layout and double wing layout
Solon Logging 插件的添加器级别控制和日志器的级别控制
3dsmax2018 common operations and some shortcut keys of editable polygons
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Establish cloth effect in 10 seconds
Unity intelligent NPC production -- pre judgment walking (method 1)
How to choose a panoramic camera that suits you?
Panel panel of UI
Shell Sort
Chinese notes of unit particle system particle effect
Simple modal box
What is the agile proportion of PMP Exam? Dispel doubts
Page countdown
Romance of programmers on Valentine's Day
远程升级怕截胡?详解FOTA安全升级