当前位置:网站首页>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 .
边栏推荐
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- Research on the value of background repeat of background tiling
- Web APIs DOM节点
- 2022年上半年国家教师资格证考试
- Common technologies of unity
- Es module and commonjs learning notes
- Lua GBK and UTF8 turn to each other
- Bucket sort
- 【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
- Es module and commonjs learning notes -- ESM and CJS used in nodejs
猜你喜欢

Quick sort summary

Unity3d learning notes

National teacher qualification examination in the first half of 2022

Chinese notes of unit particle system particle effect

2021-10-29

Grail layout and double wing layout

Romance of programmers on Valentine's Day

Learning notes of "hands on learning in depth"

Establish cloth effect in 10 seconds

Recherche de mots pour leetcode (solution rétrospective)
随机推荐
Do a small pressure test with JMeter tool
GBase数据库助力湾区数字金融发展
Stm32cubemx (8): RTC and RTC wake-up interrupt
Quick sort summary
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
Listview is added and deleted at the index
Download and use of font icons
Unity writes timetables (without UI)
[转]MySQL操作实战(一):关键字 & 函数
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
《动手学深度学习》学习笔记
The difference between heap and stack
PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
C iterator
Unity connects to the database
Unity get component
Unity and database
stm32Cubemx(8):RTC和RTC唤醒中断
2022/7/1學習總結
UE fantasy engine, project structure