Press "Enter" to skip to content

Posts published in “SP”

花花酱 Min Heap SP21

C++

Python3

Fast Power for DP SP20

Iterative DP usually takes O(n) to compute dp[n] from dp[0], we could do better if the problem can be written as matrix multiplication. With fast power, dp[n] can be computed in O(logn)

KMP Algorithm SP19

KMP Algorithm, KMP 字符串搜索算法

Time complexity: O(m+n)
Space complexity: O(m)

Implementation

C++

Python3

Applications

LeetCode 28. strStr()

C++

LeetCode 459. Repeated Substring Pattern

C++

1392. Longest Happy Prefix

C++

花花酱 Minimum Spanning Tree (MST) 最小生成树 SP18

Prim’s Algorithm

Time complexity: O(ElogV)
Space complexity: O(V+E)

C++

Python

Kruskal’s Algorithm

Time complexity: O(ElogV)
Space complexity: O(V+E)

C++

Python