当前位置:网站首页>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 .
边栏推荐
- 2020-10-27
- Bucket sort
- TF-A中的工具介绍
- Pause and resume of cocos2dx Lua scenario
- Kali 2018 full image download
- stm32Cubemx(8):RTC和RTC唤醒中断
- C language Essay 1
- Reverse one-way linked list of interview questions
- Basic knowledge points of dictionary
- PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
猜你喜欢

Grail layout and double wing layout

TF-A中的工具介绍

UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存

【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research

stm32Cubemx(8):RTC和RTC唤醒中断

对象的序列化

C语言杂谈1

Research on the value of background repeat of background tiling

Do a small pressure test with JMeter tool

Unity ugui source code graphic
随机推荐
[turn to] MySQL operation practice (III): table connection
Unity find the coordinates of a point on the circle
Redis has four methods for checking big keys, which are necessary for optimization
National teacher qualification examination in the first half of 2022
Panel panel of UI
Collapse of adjacent vertical outer margins
Stm32cubemx (8): RTC and RTC wake-up interrupt
Listview pull-down loading function
Unity get component
Solon 框架如何方便获取每个请求的响应时间?
对象的序列化
2020-10-27
Chinese notes of unit particle system particle effect
Do a small pressure test with JMeter tool
A complete attack chain
Vs2015 secret key
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
2022/7/1学习总结
Web APIs DOM节点
A three-dimensional button