Loading

随笔分类 -  基础算法系列

怎能不对算法感到愉悦呢?
摘要:方法论 回溯法和分支限界法都是搜索解空间的方法。两者都可以用剪枝函数优化加快搜索。 回溯法采取深度优先搜索,通常用于搜索所有可行解的情况。 分支限界法采取广度优先搜索,根据策略不同有先进先出分支限界和优先级分支限界,通常用于搜索最优解。 解空间 两种方法适用于解空间是两类树,子集树和排列树。 子集树 阅读全文
posted @ 2020-07-10 11:08 沉云 阅读(260) 评论(0) 推荐(0)
摘要:方法论 对于某些优化问题,可以利用问题本身的特殊性质,使用贪心法通过不断寻找局部最优解从而找到全局最优解。贪心法与动态规划的最主要不同点在于状态转移时选择,动态规划总是需要确定多个可行的方案,而贪心法只有一个可行方案。 step: Cast the optimization problem as o 阅读全文
posted @ 2020-06-12 21:16 沉云 阅读(240) 评论(0) 推荐(0)
摘要:方法论 Like the divide-and-conquer method. But in contrast dynamic programming applies when the subproblems overlap. A dynamic-programming algorithm solv 阅读全文
posted @ 2020-06-06 13:51 沉云 阅读(309) 评论(0) 推荐(0)
摘要:方法论 步骤 Divide :Divide the problem into a number of subproblems that are smaller instances of the same problem. Conquer :Conquer the subproblems by sol 阅读全文
posted @ 2020-06-04 17:35 沉云 阅读(383) 评论(0) 推荐(0)
摘要:循环不变性 loop invariant 证明算法正确性 Initialization: It is true prior to the first iteration of the loop. 在第一次执行赋值操作后,检查真值前的状态。 Maintenance: If it is true bef 阅读全文
posted @ 2020-06-04 16:32 沉云 阅读(228) 评论(0) 推荐(0)
摘要:​ 讲KMP算法,离不开BF,实际上,KMP就是BF升级版,主要流程和BF一样 ​ 不同是在匹配失败时能利用子串的特征减少回溯,利用根据子串特征生成的Next数组来减少 1)Next[0]=0; //其实Next[0]等于0或者等于 1效果没什么影响, //因为在KMP中不匹配时判断是不是第一个字符 阅读全文
posted @ 2019-10-05 21:30 沉云 阅读(290) 评论(0) 推荐(0)