二分搜索-时间复杂度分析

The time complexity of Binary Search

Created by Cloudys and reveal.js

在线观看 PPT: https://slide.shan333.cn/slides/slide_for_course.html#/

What is binary search

binary search, also known as half-interval search,

logarithmic search, is a search algorithm that finds the

position of a target value within a sorted array.

- from wikipedia

核心(core)

查找从有序序列的中间开始,如果查找的数据在序列的中间位置,那么查找终止;否则,依据查找数据与中间位置数据的比较结果,可以递归的查找序列的左半部分或右半部分

算法实现

Down arrow

伪代码

二分查找伪代码

C 实现-递归

C 递归

分而治之

分治
Up arrow
每次对比都将下一步的比对范围缩小一半
每次比对后剩余数据项如下表:

谢谢

THANKS

reference