“常用公式”在线计算,“设计手册”在线查询
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 支持支持 反对反对

共 1 个关于本帖的回复 最后回复于 2013-7-30 13:55

沙发
宋倩倩 新来的 发表于 2013-7-30 13:55:11 | 只看该作者
研发埠培训中心
Good answer:Use binary search.Compare the number in the middle of the arraywith x.If it is equal,we are done.If the number is greater,we know to look in thesecond half of the array.If it is smaller,we know to look in the first half.We can repeat the search on the appropriate half of the array by comparing the middle element of that array with x,once again narrowing our search by a factor of 2.We repeat this process until we find x.This algorithm takes O(logn) time.Not‐so‐good answer:Go through each number in order and compare it to x.Thisalgorithm takes O(n) time.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注我们

360网站安全检测平台