当前位置:网站首页>21 days learning challenge 】 【 sequential search
21 days learning challenge 】 【 sequential search
2022-08-04 04:16:00 【Alex holding popcorn】
活动地址:CSDN21天学习挑战赛
怕什么真理无穷,进一步有一份的欢喜.
目录
【21天学习挑战赛】顺序查找
我为什么参与挑战赛
1,机缘
读到研一了,暑假器件打开私信发现这个挑战赛就鼓起勇气参加了.
2,期待的收获
A, 本人在华南理工大学攻读专硕,目前研究方向是图像恢复,从事深度学习相关工作,目标是从事Java后端开发.
B, 期待您的反馈,如果有什么不对的地方,欢迎指正!
C, 期待认识志同道合的领域同行或技术交流.
如果感觉博主的文章还不错的话,还请关注、点赞、收藏三连支持一下博主哦
什么是查找?
在计算机科学中定义为:在一些(有序的/无序的)数据元素中,Find and give by a certain method关键字The process of identical data elements is called lookup.也就是说,We are there for a purpose,Pass in e.g. to the algorithmkey(序号,别名等)或者value(具体的值),returns the data type we want,That is to find.
Definition of sequential lookup
Find a specified element,Traverse the entire data structure(比如表,树,集合等),to find if the specified element exists.If it exists, the search succeeds,If the specified element is not found at the end of the scan, the search fails.
The pros and cons of sequential search
优势
简单,以一维数组为例,I'm the one from the front to the backforThe loop solves the simple and rude.Sequential sorting is more suitable for unordered data structures with small amounts of data.
劣势
时间复杂度高,以一维数据为例,The time efficiency of sequential search is O(n),The time efficiency of sequential lookup in a 2D array is O(n^2)
️ 算法实现
public class SequentalSearch {
public static void main(String[] args) {
int[] arr = {
1, 4, 6, 7, 11};
int key = 3;
int value = 11;
Integer search = Search(arr, null, 11);
if (search!=null) {
System.out.println("value found: "+search);
}else {
System.out.println("没找到!");
}
}
/** * @param arr 输入数组 * @param key 如果不为空,返回对应value * @param value 如果不为空,返回对应key */
public static Integer Search(int[] arr, Integer key, Integer value) {
if (key == null && value == null) {
System.out.println("请输入key或value");
}
if (key != null && value != null) {
System.out.println("cannot be entered at the same timekey和value");
}
//输入key
if (key != null) {
for (int i = 0; i < arr.length; i++) {
if (i == key) {
return arr[i];
}
}
}
//输入value
if (value != null) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == value) {
return i;
}
}
}
//没有找到
return null;
}
}
如果觉得对你有帮助的话:
点赞,你的认可是我创作的动力!
️ 收藏,你的青睐是我努力的方向!
️ 评论,你的意见是我进步的财富!
边栏推荐
- 8.Haproxy 搭建Web集群
- Significant differences between Oracle and Postgresql in PLSQL transaction rollback
- Hey, I had another fight with HR in the small group!
- 中信证券网上开户怎么开的?安全吗?
- Based on the statistical QDirStat Qt directory
- JVM Notes
- sql语句查询String类型字段小于10的怎么查
- 2003. 每棵子树内缺失的最小基因值 DFS
- 8. Haproxy builds a web cluster
- typescript type 和 interface 的区别
猜你喜欢
随机推荐
How to systematically plan and learn software testing?
Tensors - Application Cases
网络工程师入门必懂华为认证体系,附系统学习路线分享
Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析
【源码】使用深度学习训练一个游戏
docker+bridge+redis master-slave+sentry mode
Introduction to mq application scenarios
目标检测-中篇
备份工具pg_dump的使用《postgres》
【技巧】借助Sentinel实现请求的优先处理
2003. 每棵子树内缺失的最小基因值 DFS
仿牛客论坛项目梳理
转:管理是对可能性的热爱,管理者要有闯进未知的勇气
企业直播风起:目睹聚焦产品,微赞拥抱生态
7-3 LVS+Keepalived Cluster Description and Deployment
7-3 LVS+Keepalived集群叙述与部署
if,case,for,while
【21天学习挑战赛】图像的旋转问题(二维数组)
打造一份优雅的简历
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)