随笔分类 -  算法

摘要:Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths from given source to all other vertices. For a gener 阅读全文
posted @ 2016-04-08 11:20 流白 阅读(377) 评论(0) 推荐(0)
摘要:Strongly Connected Components <!-- .entry-header --> A directed graph is strongly connected if there is a path between all pairs of vertices. A strong 阅读全文
posted @ 2016-04-07 08:23 流白 阅读(612) 评论(0) 推荐(0)
摘要:#include using namespace std; int divide(int dividend, int divisor) { long long n = dividend, m = divisor; // determine sign of the quotient int sign = n = 0; i--) if (t ... 阅读全文
posted @ 2016-03-16 05:00 流白 阅读(539) 评论(0) 推荐(0)
摘要:Finding Shortest Paths By BFS􀁺 The BFS code we have seen 􀁻 find outs if there exist a path from a vertex s to a vertex v 􀁻 prints the vertices of a 阅读全文
posted @ 2016-03-16 03:34 流白 阅读(641) 评论(0) 推荐(0)
摘要:The trivial way, O(m + n): Merge both arrays and the k-th smallest element could be accessed directly. Merging would require extra space of O(m+n). Th 阅读全文
posted @ 2016-02-08 01:59 流白 阅读(1044) 评论(0) 推荐(0)
摘要:public static int[] max_min(int[] a){ //res[0] records the minimum value while res[1] records the maximal one. int res[] = new int[2]; int n = a.lengt 阅读全文
posted @ 2016-02-07 04:27 流白 阅读(190) 评论(0) 推荐(0)
摘要:一道来自jhu algorithm的作业题: Given two sorted arrays A, B, give a linear time algorithm that finds two entries i,j such that|A[i]−B[j]|is minimized. Prove th 阅读全文
posted @ 2016-02-05 01:12 流白 阅读(221) 评论(0) 推荐(0)
摘要:package dataStructure; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.io.*; cl 阅读全文
posted @ 2016-01-24 08:32 流白 阅读(516) 评论(0) 推荐(0)
摘要:#include#include#include#include#include#includeusing namespace std;//****************************************************************// Miller_Rabin ... 阅读全文
posted @ 2015-10-26 15:17 流白 阅读(318) 评论(0) 推荐(0)
摘要:Check whether a given graph is Bipartite or notABipartite Graphis a graph whose vertices can be divided into two independent sets, U and V such that e... 阅读全文
posted @ 2015-10-24 10:09 流白 阅读(194) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn=6; 8 struct edge{ 9 int to,cost; 10 e... 阅读全文
posted @ 2015-10-15 21:23 流白 阅读(275) 评论(0) 推荐(0)
摘要:一. KMP算法KMP算法是一种改进的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,简称KMP算法。KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现就是实现一个next()函数,函数本身包含了模式串的局部匹... 阅读全文
posted @ 2015-02-10 11:53 流白 阅读(1146) 评论(3) 推荐(2)
摘要:一. 什么是快速幂:快速幂顾名思义,就是快速算某个数的多少次幂。其时间复杂度为 O(log₂N), 与朴素的O(N)相比效率有了极大的提高。一般一个矩阵的n次方,我们会通过连乘n-1次来得到它的n次幂。但做下简单的改进就能减少连乘的次数,方法如下:把n个矩阵进行两两分组,比如:A*A*A*A*A*A... 阅读全文
posted @ 2015-02-09 12:44 流白 阅读(1381) 评论(1) 推荐(0)