当前位置:网站首页>Binary search
Binary search
2022-06-26 03:37:00 【kingsley1212】
1、 Half algorithm or binary search
// Two points search
private void binarySearch() {
// Define an array
int[] list = new int[]{1, 3, 5, 14, 35, 46, 67, 109, 800, 2345};
// The data you need to find , Determine where the value is in the array
int targetData = 800;// Suppose you want to know the location of this data
// Starting position ( The subscript of the first data )
int start = 0;
// Last position
int end = list.length - 1;// The subscript of the last data )
while (start < end) {
// Get the subscript of the intermediate field , And if it is greater than the target number , After the compromise, the subscript needs to be added with the subscript of the starting position
int middle = start + (end - start) / 2;
// If the target data is less than the number of intermediate subscripts , Just subtract the middle subscript number by one to become the last number, and then , Half after cycle
if (targetData < list[middle]) {
end = middle - 1;
// If the target data is greater than the number of intermediate subscripts ,
// The middle subscript minus one becomes the first number plus one , Because it is smaller than him , So it can't be equal to him ,
// So add one
} else if (targetData > list[middle]) {
start = middle + 1;
} else {
// Then we get the subscript position , The subscript number is middle
targetData = list[middle];
}
}
}
边栏推荐
- 经典模型——AlexNet
- Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
- MySQL addition, deletion, query and modification (Advanced)
- golang正則regexp包使用-06-其他用法(特殊字符轉換、查找正則共同前綴、切換貪婪模式、查詢正則分組個數、查詢正則分組名稱、用正則切割、查詢正則字串)
- 解析少儿编程的多元评价体系
- Review of the paper: unmixing based soft color segmentation for image manipulation
- 个人用同花顺软件买股票安全吗?怎么炒股买股票呢
- 使用IDEA画结构图
- MySQL development environment
- Leetcode 176 The second highest salary (June 25, 2022)
猜你喜欢

Lumen Analysis and Optimization of ue5 global Lighting System

Graphics card, GPU, CPU, CUDA, video memory, rtx/gtx and viewing mode

经典模型——NiN&GoogLeNet

Drag and drop

Analysis and optimization of ue5 global illumination system lumen

Upload file / text / picture, box shadow

给网站添加“开放搜索描述“以适配浏览器的“站点搜索“
![[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters](/img/84/2b66b513a0a36464233708fbb4b57d.png)
[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters

Inkscape如何将png图片转换为svg图片并且不失真

【论文笔记】Deep Reinforcement Learning Control of Hand-Eye Coordination with a Software Retina
随机推荐
文献阅读---优化RNA-seq研究以研究除草剂耐药性(综述)
分割、柱子、list
解决uniapp插件robin-editor设置字体颜色和背景颜色报错的问题
Butterknife unbinder uses flashback in fragment and viewpager
Plug in installation and shortcut keys of jupyter notebook
Qt编译出错ERROR: Unknown module(s) in QT: script
Cloud Computing Foundation -0
请求对象,发送请求
Scratch returns 400
P2483-[template]k short circuit /[sdoi2010] Magic pig college [chairman tree, pile]
Various errors in kitti2bag installation
Is the compass app regular? Is it safe or not
Cliquez sur le bouton action de la liste pour passer à une autre page de menu et activer le menu correspondant
Golang regexp package use - 06 - other usage (Special Character conversion, find regular Common prefix, Switch gourmand mode, query regular Group NUMBER, query regular Group name, cut with regular, qu
Is it safe to open an online stock account?
经典模型——NiN&GoogLeNet
How to prepare for a moving wedding
国信金太阳靠谱吗?开证券账户安全吗?
Types and application methods of screen printing
数字孪生智慧水务,突破海绵城市发展困境