- 博客(5)
- 收藏
- 关注
原创 Data Structure: Binary Index Tree(LC308作为例子)
Binary Index Tree适合用以Range Query. 例如:求一个大区间的某个小区间的和。为什么要使用Binary Index Tree?先看看,如果不使用Binary Index Tree的话,我们可以使用的方法。1)直接求。那么复杂度是O(mn)。m是查询次数,n是大区间的元素个数。2)使用sum的array,建立一个array,每个ind
2017-09-29 23:10:17 1469
原创 Data Structure: Segment Tree 线段树
线段树主要用于Range Query. 适用问题在:这个大区域的某个子区间最小值,这个大区间的某个子区间的和等等。线段树的某个叶子节点都是代表一个大区间的元素。为什么要使用线段树?那先让我们看看,如果不使用线段树,上述的求某个子区间最小值的问题该如何解决。方案1:每次query都去遍历一次子区间。如果有m次查询,有n个元素的话,时间复杂度就是O(mn)。
2017-09-29 12:02:29 480
原创 System Design: How to design a tiny URL
At first glance, this problem seems to very easy. We can solve it with a HashMap. However, if you think it more deeper, you will find out HashMap approach does not have scalablity and persistenc
2017-09-28 03:33:13 1601
原创 Data Structure: 图的拓扑排序
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is e...
2017-09-13 12:21:39 383
原创 Data Structure: Trie(字典树)
字典树是一个用数组(数组代表子节点数目是静态的)来表示子节点的树结构。同时节点也需要域:boolean isEnd。 本文章参考:https://leetcode.com/problems/implement-trie-prefix-tree/solution/Trie的一些应用:1)Autocomplete; 2) Spell checker; 3) IP routing
2017-09-10 03:02:17 745
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人