收藏 分享(赏)

C语言编程学习课件 (31).pdf

上传人:职教中国 文档编号:13894382 上传时间:2022-11-06 格式:PDF 页数:8 大小:1.49MB
下载 相关 举报
C语言编程学习课件 (31).pdf_第1页
第1页 / 共8页
C语言编程学习课件 (31).pdf_第2页
第2页 / 共8页
C语言编程学习课件 (31).pdf_第3页
第3页 / 共8页
亲,该文档总共8页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、Programming In C Sequential Search The sequential search, also known as linear search. Start with the first number of the data list and search the number one by one. 5 21 23 10 7 15 18 2 6 20 For example, the number we entered from the keyboard is 7. Then the searching process is as shown above. Ass

2、uming there is a data list: 7 not equal 7 equal In this way, we find the number 7 in the data list, and we can determine that it is the third element. Sequential Search 5 21 23 10 7 15 18 2 6 20 For example, the number we entered from the keyboard is 25. Then the searching process is as shown below.

3、 However, what if the number we entered from the keyboard is not in the data list? 25 not equal In this way, no element equal to 25 has been found in the data list. Code Running result 7 The position of 7 is: 3 Running result 25 The number is not found! Binary Search Here I will introduce to you a m

4、ore efficient searching method: binary search. A necessary premise for binary search is that the data list should be an ordered sequence. That is, the data list is arranged in ascending or descending order. For example, there is such a sequence data. Suppose we want to search 16 in the sequence. We

5、first compare 16 with the number 13 in the middle of the sequence. Because 16 is bigger than 13, it will never appear in a position smaller than 13. That means 16 will be in the right half of the sequence. 16 not equal should go this way Binary Search Therefore, we exclude the first half of the sequence and do a binary search on the second half of the sequence. Because 16 is in the middle of the second half, compare the values of them, then we find it. So we find it. 16 not equal 16 equal Code Running result 16 The position of 16 is: 7 Programming In C

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报