![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 55
jsc0218
I am a PhD student in University of Waterloo. This Blog is some notes about technical details I met.
展开
-
Manacher's algorithm for finding longest palindromic substring
Given a string S, find the longest palindromic substring in S.An O(N) Solution (Manacher’s Algorithm):First, we transform the input string, S, to another string T by inserting a special charac转载 2014-03-18 20:54:31 · 1010 阅读 · 0 评论 -
Longest Palindromic Subsequence
Longest Palindromic Subsequence (not substring, for the substring solution, please find answers in myGitHub) is to find (one of) the longest palindromic subsequence in a string. It is short for LP原创 2014-03-19 17:06:51 · 1405 阅读 · 0 评论 -
Longest Common Substring
Longest Common Substring (notsubsequence, for thesubsequence solution, please find answers in the book >) is to find (one of) the longest common substring in two strings. It is short for LCS in原创 2014-03-21 15:06:53 · 2344 阅读 · 0 评论 -
Solving Greatest Common Divisor
Two ways of solving greatest common divisor: recursion and iteration.#include using namespace std;int maxCommonDivisor1(int a, int b) { int n = max(a, b), d = min(a, b), m = n % d; return (m==0原创 2014-05-11 20:19:56 · 755 阅读 · 0 评论 -
Counting Inversion Pairs in an Array
Given an array, for example, 246135, an inversion pair is the pair whose first value is larger than its second value according to the sequence from left to right, (2,1) (4,1) (4,3) (6,1) (6,3) (6,5).原创 2014-05-11 23:44:22 · 1243 阅读 · 0 评论 -
Iterative (non-recursive) Merge Sort
An iterative way of writing merge sort:#include using namespace std;void merge(int A[], int l, int r, int e, int B[]) { int i = l, j = r, k = l; while (i<r && j<e) { if (A[i] > A[j]) B[k++] =原创 2014-05-29 21:52:15 · 1556 阅读 · 0 评论 -
Iterative (non-recursive) Quick Sort
An iterative way of writing quick sort:#include #include #include using namespace std;void quickSort(int A[], int n) { stack> stk; stk.push(make_pair(0, n-1)); while (!stk.empty()) { pair原创 2014-05-30 15:46:15 · 1221 阅读 · 0 评论 -
Enumerate Combination C(k, n) in a bitset
Suppose n#include #include #include using namespace std;bitset getComb(const vector &comb) { bitset bitcombs; for (int i=0; i<comb.size(); ++i) bitcombs.set(comb[i], true); return bitcombs原创 2014-08-01 07:21:45 · 950 阅读 · 0 评论