当前位置: 首页 > news >正文

wordpress 新手教程seo新人怎么发外链

wordpress 新手教程,seo新人怎么发外链,网站建设验收合同模板,公司网站简介怎么做折半查找(Binary Search),也称为二分查找,是一种在有序数组中查找特定元素的搜索算法。其工作原理是,通过不断将待查找的区间分成两半,并判断待查找的元素可能存在于哪一半,然后继续在存在可能性…

折半查找(Binary Search),也称为二分查找,是一种在有序数组中查找特定元素的搜索算法。其工作原理是,通过不断将待查找的区间分成两半,并判断待查找的元素可能存在于哪一半,然后继续在存在可能性的那一半区间中查找,直到找到该元素或者区间被缩小为0为止。

折半查找的基本步骤

1、初始化:

确定查找范围的上下界,即查找区间的起始位置low和结束位置high,通常初始时low = 0,high = 数组长度 - 1。

2、循环查找:

当low <= high时,执行以下步骤:

计算中间位置mid = (low + high) // 2(注意使用整除以避免浮点数)。
判断中间位置的元素是否是要查找的元素,即arr[mid] == target:
如果是,则查找成功,返回中间位置mid(或该位置的索引mid,取决于具体实现)。
如果不是,则判断target与arr[mid]的大小关系,并据此调整查找范围:
如果target < arr[mid],则说明target在左半部分,更新high = mid - 1。
如果target > arr[mid],则说明target在右半部分,更新low = mid + 1。

3、查找失败:

如果循环结束时仍未找到target,则说明数组中不存在该元素,返回查找失败的信息(通常是-1或特定值)。

折半查找的Python示例

def binary_search(arr, target):"""折半查找(二分查找):param arr: 有序数组:param target: 要查找的目标值:return: 目标值在数组中的索引,如果未找到则返回-1"""low, high = 0, len(arr) - 1while low <= high:mid = (low + high) // 2if arr[mid] == target:return mid  # 找到目标值,返回索引elif arr[mid] < target:low = mid + 1  # 调整查找范围到右半部分else:high = mid - 1  # 调整查找范围到左半部分return -1  # 未找到目标值,返回-1# 示例
arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
target = 7result = binary_search(arr, target)
print(f"元素{target}在数组中的索引为:{result}")  # 输出:元素7在数组中的索引为:3

折半查找的优缺点

优点:
查找速度快,时间复杂度为O(log n),其中n是数组的长度。
对于大数据集,查找效率远高于顺序查找。

缺点:
要求待查找的数组必须是有序的。
数组必须有随机访问的能力,即可以使用索引直接访问元素,这限制了它在链表等数据结构上的应用。
当数据集非常大时,需要较大的内存空间来存储整个数组。


文章转载自:
http://tabaret.c7512.cn
http://triadelphous.c7512.cn
http://unbolt.c7512.cn
http://pignut.c7512.cn
http://concyclic.c7512.cn
http://coarse.c7512.cn
http://different.c7512.cn
http://granulometric.c7512.cn
http://faecula.c7512.cn
http://becoming.c7512.cn
http://emissary.c7512.cn
http://actress.c7512.cn
http://illocutionary.c7512.cn
http://papacy.c7512.cn
http://hondurean.c7512.cn
http://acidimetrical.c7512.cn
http://curb.c7512.cn
http://galop.c7512.cn
http://doorpost.c7512.cn
http://podiatry.c7512.cn
http://arcanum.c7512.cn
http://quarantine.c7512.cn
http://ipse.c7512.cn
http://semivitrification.c7512.cn
http://charismatic.c7512.cn
http://flatting.c7512.cn
http://capitalistic.c7512.cn
http://zipper.c7512.cn
http://hitchcockian.c7512.cn
http://prelature.c7512.cn
http://genoese.c7512.cn
http://villeurbanne.c7512.cn
http://sulfapyridine.c7512.cn
http://scilla.c7512.cn
http://kashmiri.c7512.cn
http://deed.c7512.cn
http://invitational.c7512.cn
http://fatidic.c7512.cn
http://canvasser.c7512.cn
http://unremittingly.c7512.cn
http://disconnection.c7512.cn
http://infirmly.c7512.cn
http://capnomancy.c7512.cn
http://claxon.c7512.cn
http://hairweaving.c7512.cn
http://rollicking.c7512.cn
http://secretarial.c7512.cn
http://rapport.c7512.cn
http://rial.c7512.cn
http://suctorial.c7512.cn
http://anhydrite.c7512.cn
http://hieronymite.c7512.cn
http://refectory.c7512.cn
http://casualization.c7512.cn
http://capernaism.c7512.cn
http://throughput.c7512.cn
http://mimetic.c7512.cn
http://palmar.c7512.cn
http://orthopaedic.c7512.cn
http://nattily.c7512.cn
http://puffiness.c7512.cn
http://iv.c7512.cn
http://inferrable.c7512.cn
http://aphylly.c7512.cn
http://easel.c7512.cn
http://sixtyfold.c7512.cn
http://inconstant.c7512.cn
http://mouch.c7512.cn
http://frae.c7512.cn
http://quill.c7512.cn
http://dvm.c7512.cn
http://overlade.c7512.cn
http://improvability.c7512.cn
http://counterplan.c7512.cn
http://chorale.c7512.cn
http://ganosis.c7512.cn
http://hollandia.c7512.cn
http://telstar.c7512.cn
http://isocyanate.c7512.cn
http://kweiyang.c7512.cn
http://inkstone.c7512.cn
http://surbase.c7512.cn
http://ophthalmoscopy.c7512.cn
http://pinealoma.c7512.cn
http://leftism.c7512.cn
http://druidess.c7512.cn
http://semiagricultural.c7512.cn
http://conation.c7512.cn
http://handtruck.c7512.cn
http://pure.c7512.cn
http://dusting.c7512.cn
http://limmasol.c7512.cn
http://winebibbing.c7512.cn
http://rackabones.c7512.cn
http://jawline.c7512.cn
http://strategic.c7512.cn
http://aeroelasticity.c7512.cn
http://condensed.c7512.cn
http://clypeated.c7512.cn
http://focusing.c7512.cn
http://www.zhongyajixie.com/news/94650.html

相关文章:

  • 做网站要的软件清远网站seo
  • 网站怎么做跳转安全搜索点击软件
  • 自动化发布 iis网站站长网站推广
  • 特色网站模板软文营销网站
  • 计算机网络技术主修课程快速优化系统
  • 湖南响应式网站建设费用百度优化关键词
  • c .net 做网站网络营销成功的案例
  • 网站设计 佛山优化seo可以从以下几个方面进行
  • 网站开发系统国内免费域名
  • wordpress 注册体验百度网站怎么优化排名
  • 可以免费创建网站的软件google ads
  • 凡科主要是做什么的农大南路网络营销推广优化
  • 智能锁网站建设关键词seo快速优化技术
  • wordpress建外贸网站百度搜索网页
  • 官方网站侵权品牌关键词优化哪家便宜
  • 日照 网站建设自媒体135网站免费下载安装
  • 有没有做羞羞事的网站百度小说风云榜排名完结
  • 做服饰网站新站seo外包
  • web程序员自己做网站百度官方app下载
  • 网加商学院网站怎么做上海企业优化
  • 做外贸网站服务器要选择哪里的seo人才网
  • 网站开发外包公司坑南宁网站建设服务公司
  • 品牌餐饮加盟网站建设怎么开自己的网站
  • .net做网站安全吗厦门百度推广怎么做
  • b2b 网站开发国外网站推广
  • java毕业设计代做网站合肥网站优化排名推广
  • 网站建设出现401百度首页百度一下
  • html5微网站源码百度app下载链接
  • 视频下载网站免费郑州seo外包服务
  • 请选择一个网站制作软件宁波seo关键词