摘要: 1、算法简单描述 1).输入:一个加权连通图,其中顶点集合为V,边集合为E; 2).初始化:Vnew = {x},其中x为集合V中的任一节点(起始点),Enew = {},为空; 3).重复下列操作,直到Vnew = V: a.在集合E中选取权值最小的边<u, v>,其中u为集合Vnew中的元素,而 阅读全文
posted @ 2021-01-26 16:32 wangheq 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 1.算法简单描述 1).记Graph中有v个顶点,e个边 2).新建图Graphnew,Graphnew中拥有原图中相同的e个顶点,但没有边 3).将原图Graph中所有e个边按权值从小到大排序 4).循环:从权值最小的边开始遍历每条边 直至图Graph中所有的节点都在同一个连通分量中 if 这条边 阅读全文
posted @ 2021-01-26 16:31 wangheq 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 拓扑排序代码: public class Topological { private Iterable<Integer> order; // topological order private int[] rank; // rank[v] = rank of vertex v in order pu 阅读全文
posted @ 2021-01-21 14:45 wangheq 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 有向图中基于深度优先搜索的顶点排序: 前序:在递归调用之前将顶点加入队列 后序:在递归调用之后将顶点加入队列 逆后序:在递归调用之后将顶点压入栈 代码: public class DepthFirstOrder { private boolean[] marked; // marked[v] = h 阅读全文
posted @ 2021-01-21 14:22 wangheq 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 判断图中是否有一个有向环: edgeTo 数组找到有向环的所有顶点 onStack 调用dfs时将其设置为true,调用结束时设为false。 public class DirectedCycle { private boolean[] marked; // marked[v] = has vert 阅读全文
posted @ 2021-01-21 13:59 wangheq 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 判断一个图是否为无环图: 完整代码 public class Cycle { private boolean[] marked; private int[] edgeTo; private Stack<Integer> cycle; /** * Determines whether the undi 阅读全文
posted @ 2021-01-20 16:11 wangheq 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 使用深度优先搜索查找图中的连通分量:思想就是在深度优先搜索的基础上,在加上一个连通分量的数值标识( count),用于统计有几个连通分量。 public class CC { private boolean[] marked; // marked[v] = has vertex v been mar 阅读全文
posted @ 2021-01-20 15:13 wangheq 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 广度优先搜索代码: public class BreadthFirstPaths { private static final int INFINITY = Integer.MAX_VALUE; private boolean[] marked; // marked[v] = is there an 阅读全文
posted @ 2021-01-20 12:14 wangheq 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 深度优先搜索的代码: public class DepthFirstSearch { private boolean[] marked; // marked[v] = is there an s-v path? private int count; // number of vertices con 阅读全文
posted @ 2021-01-20 11:28 wangheq 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 大数据下,数据大都比较稀疏,用矩阵存储的数据是稀疏的,大多数项是0。 算法四中介绍用稀疏矩阵的形式来存储数组 点乘的稀疏向量代码 public double dot(double[] that) { double sum = 0.0; for (int i : st.keys()) sum += t 阅读全文
posted @ 2021-01-19 11:08 wangheq 阅读(532) 评论(0) 推荐(0) 编辑