搜索算法 All In One
搜索算法 All In One
在计算机科学中,
搜索算法是解决搜索问题的任何算法,即检索存储在某个数据结构中的信息,或者在问题域的搜索空间中计算的信息。
这种结构的例子包括但不限于链表,数组数据结构或搜索树。
合适的搜索算法通常取决于正在搜索的数据结构,并且还可能包括有关数据的先前知识。
二分搜索 / 二分查找
二叉树搜索 / 二叉搜索树
哈希表 / 字典 / 哈希图
搜索树
数据库索引

二分搜索算法
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function(nums, target) {
    // 二分搜索算法
    let left = 0;
    // -1 防止越界 bug
    let right = nums.length -1;
    while(left <= right) {
      // let mid = Math.floor((left + right) / 2);
      // 性能优化 ?
      const mid = Math.floor(left + (right - left)/2);
      if(nums[mid] === target) {
        return mid;
      }
      if(nums[mid] > target) {
        right = mid - 1;
      }
      if(nums[mid] < target) {
        left = mid + 1;
      }
    }
    return -1;
};
https://leetcode.com/problems/binary-search/
https://leetcode.cn/problems/binary-search/
https://www.cnblogs.com/xgqfrms/p/11392498.html
https://www.cnblogs.com/xgqfrms/p/12927211.html
图解算法数据结构 All In One
https://www.cnblogs.com/xgqfrms/p/16366896.html
LeetCode
搜索算法题
https://leetcode.com/tag/binary-search/
refs
https://zh.wikipedia.org/wiki/搜索算法
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16398983.html
未经授权禁止转载,违者必究!

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号