当前位置:网站首页>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;
}
}
如果觉得对你有帮助的话:
点赞,你的认可是我创作的动力!
️ 收藏,你的青睐是我努力的方向!
️ 评论,你的意见是我进步的财富!
边栏推荐
- 看DevExpress丰富图表样式,如何为基金公司业务创新赋能
- Introduction to mq application scenarios
- 元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
- Gigabit 2 X light 8 electricity management industrial Ethernet switches WEB management - a key Ring Ring net switch
- SVM介绍以及实战
- 学会iframe并用其解决跨域问题
- 2022软件测试面试题 最新字节跳动50道真题面试题 刷完已拿下15k 附讲解+答疑
- Mockito unit testing
- JVM Notes
- [Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
猜你喜欢

自定义通用分页标签02

Based on the statistical QDirStat Qt directory

Y86. Chapter iv Prometheus giant monitoring system and the actual combat, Prometheus storage (17)

7-2 LVS+DR概述与部署

文件系统的简单操作
SQL injection in #, - +, - % 20, % 23 is what mean?

mysql index notes

高效IO模型

Deep learning -- CNN clothing image classification, for example, discussed how to evaluate neural network model

机器学习模型的“可解释性”
随机推荐
Shell 函数
JVM Notes
SVM介绍以及实战
打造一份优雅的简历
JVM的内存模型简介
复现20字符短域名绕过
unity框架之缓存池
Simple operation of the file system
Oracle与Postgresql在PLSQL内事务回滚的重大差异
Tensors - Application Cases
pnpm 是凭什么对 npm 和 yarn 降维打击的
mq应用场景介绍
A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
机器学习之视频学习【更新】
软件测试如何系统规划学习呢?
【源码】使用深度学习训练一个游戏
烧录场景下开发如何进行源代码保密工作
怎么把elastic中的异常登录ip和日志自动导出或抓取到数据库中?
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
解决问题遇到的问题