摘要:从 stackoverflow中找到了一个时间复杂度分析很棒的链接 https://www.inf.hs-flensburg.de/lang/algorithmen/pattern/kmpen.htm 判断字符串 str 中是否包含子串 match。 next [i] : match [i-1] 结
阅读全文
摘要:程序员代码面试指南(第2版)第3章 二叉树问题:遍历二叉树的神级方法 https://leetcode.com/articles/binary-tree-inorder-traversal/ Step 1: Initialize current as root Step 2: While curre
阅读全文
摘要:参考资料:Algorithms, 4th 精髓 In a heap, the parent of the node in position k is in position ⎣k /2⎦ and, conversely, the two children of the node in positio
阅读全文
摘要:资料来源于The algorithm design manual 拓扑排序是所有日程安排问题的自然解法。 拓扑排序的使用条件是有向无环图,即DAG。 在日程安排正常完成的情况下,日程之间是没有循环依赖的,因此日程安排问题天然适合使用拓扑排序解决。 拓扑排序有2种解法。 第一个算法Kahn: 原文描述
阅读全文
摘要:参考资料:Algorithms, 4th 背景:红黑树来源于2-3树。 解决的问题:2-3树通过代码难实现。2-3树作为平衡二叉树在树高方面有优势,但是在插入操作时维护树结构的操作过于繁琐,导致时间复杂度没有明显优势。 方法:为节点间的links添加颜色,用node和link对2-node和3-no
阅读全文
摘要:资料来源于The algorithm design manual 问题引入 考虑以下2个操作: Same component(v1,v2)– Do vertices v1 and v2 occur in the same connected component of the current grap
阅读全文