当前位置:网站首页>线性表的查找
线性表的查找
2022-07-06 20:15:00 【ScarboroughFair#】
目录
1.顺序表查找算法
顺序查找的实现



改进:运用&,for循环后面加上分号
改进:把待查关键字key存入表头(哨兵),从后往前逐个比较,可以免去查找过程中每一步都要检测是否查找完毕,加快速度

当ST.length较大时,此改进能使进行一次查找所需的平均时间几乎减少一半
(带哨兵)顺序查找时间效率分析



顺序查找的特点

2.二分查找(详细见专栏:Acwing基础课)
二分查找的实现


普通折半查找
二分查找的递归算法

二分查找的性能分析——判定树




时间复杂度 O(logn)
二分查找特点
对线性链表无效的原因是找不到mid
3.分块查找
分块查找的实现
条件:1.将表分成几块,且表或者有序,或者分块有序;若i<j,则第j块中所有记录的关键字均大于第i块中的最大关键字
2.建立“索引表”(每个结点含有最大关键字和指向本块第一个结点的指针,且按关键字有序)
分块查找性能分析

分块查找特点

4.插值查找(了解)

5. 斐波那契查找

int Fibonacci_Search(int* a, int n, int key)
{
int low, high, mid, i, k;
low = 1; //定义最低下标为记录首位
high = n; //定义最高下标为记录末位
k = 0;
while (n > F[k] - 1) //计算n位于斐波那契数列的位置
k++;
for (i = n; i < F[k] - 1; i++) //将不满的数值补全
a[i] = a[n];
while (low <= high)
{
mid = low + F[k - 1] - 1; //计算当前分隔的下标
if (key < a[mid]) //若查找记录小于当前分隔记录
{
high = mid - 1; //最高下标调整到分割下标mid-1处
k = k - 1; //斐波那契数列下标减一位
}
else if (key > a[mid]) //若查找记录大于当前分隔记录
{
low = mid + 1; //最低下标调整到分隔下标mid+1处
k = k - 2; //斐波那契数列下标减两位
}
else
{
if (mid <= n)
return mid; //若相等则说明mid即为查找到的位置
else
return n; //若mid>n,说明是补全数值,返回n
}
}
return 0;
}
边栏推荐
- 【达梦数据库】添加自动收集统计信息的任务
- 密码学系列之:在线证书状态协议OCSP详解
- 上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
- SQL Tuning Advisor一个错误ORA-00600: internal error code, arguments: [kesqsMakeBindValue:obj]
- Simple bubble sort
- Cocos2d-x box2d physical engine compilation settings
- Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
- opencv环境的搭建,并打开一个本地PC摄像头。
- 【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
- 如何分析粉丝兴趣?
猜你喜欢

Variables, process control and cursors (MySQL)

mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA
![[cpk-ra6m4 development board environment construction based on RT thread studio]](/img/08/9a847c73d6da6fc74d84af56897752.png)
[cpk-ra6m4 development board environment construction based on RT thread studio]
![Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]](/img/f4/8464bf9b66a1215265ac873f286688.png)
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]

Don't you know the relationship between JSP and servlet?

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

体会设计细节

Flutter3.0了,小程序不止于移动应用跨端运行

Mathematical induction and recursion

尚硅谷JVM-第一章 类加载子系统
随机推荐
Unity uses maskablegraphic to draw a line with an arrow
leetcode
Household appliance industry under the "retail is king": what is the industry consensus?
cocos3——8. Implementation Guide for beginners
Mathematical induction and recursion
oracle连接池长时间不使用连接失效问题
Install torch 0.4.1
杰理之RTC 时钟开发【篇】
New benchmark! Intelligent social governance
杰理之发射端在接收端关机之后假死机【篇】
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
装饰设计企业网站管理系统源码(含手机版源码)
数学归纳与递归
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
美国空军研究实验室《探索深度学习系统的脆弱性和稳健性》2022年最新85页技术报告
[dream database] add the task of automatically collecting statistical information
【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
c语言字符串排序
变量、流程控制与游标(MySQL)
