算法本质
算法本质上可以看做是在一个解空间当中的搜索问题 学习一项知识,必须问自己三个重要问题:1. 它的本质是什么。2. 它的第一原则是什么。3. 它的知识结构是怎样的。
算法的学习方法
【Better Explained】
所谓“正儿巴经”学习算法,意即开始对算法思想的本质进行归根究底的过程、对思维方法论进行归纳抽象的过程、对各种解题技巧进行一般化的过程、通过不断练习来让记忆内隐化的过程..
你的理解,记忆,以及学习的效率都会得到质的提高:
这个算法的本质是什么? 为什么这种解法是对的? 为什么那种解法是错的? 为什么这种解法不是最优的? 证明为什么没有更优的解法。
学习与记忆
学习——本质上是个体力活
将外界(书本上的)知识转化为外显记忆
【Better Explained】 The Art of Learning A Journey in the Pursuit of Excellence
通过不断练习,将外显记忆转化为内隐记忆
【Better Explained】 把时间当作朋友 将关于思维方法的知识转化为内隐记忆从而不知不觉就遵循 将关于事实知识(例如“定理”、“性质”)的提取线索们转化为内隐记忆从而看到XX就能想到YY
知其所以然
问题
算法书都是欧几里德式的,这完全把人类大脑创造发明的步骤给反过来了。看起来是阳关大道,实际上神鬼难行。 答案&做法到底是怎么来的,从问题到答案之间经历了怎样的思维过程。
思考一个问题的过程中有两种思维形
【Better Explained】
很大的试错成分(好听一点叫“探索”)
联想 演绎&归纳
忽略思考本身,才是本末倒置
【Better Explained】
对于不断学习的我们来说,忽视到达解的那个过程实际上却变成了舍本逐末。【要知道,你不是为了解一道题!】 如果问题求解是一部侦探小说,那么算法只是结局而已,而思考过程才是情节。【代码敲出来,能用多长时间,你说是吧】
一来思维的漫长繁杂的过程已经在大脑里面淡化得差不多了 二来,思考过程是我们的空气和水,而“鱼是最后一个感觉到水的” 三来,由于我们的目标是问题的解,解才是我们为之兴奋和狂喜的东西,而不是求解的过程,过程只是过程,目的才是目的。 其四:感到介绍思维过程是不相干的【对于传授知识的人】
思维过程远胜于问题的解决方案
内隐化 跨情境运用
对问题解的更多记忆提取线索
【Better Explained】 譬如你知道堆(heap)是怎样由朴素的决策树演化而来的,它又是为了解决什么问题的,你即便忘记了具体的细节,也可以自己推导出来。 譬如你知道KMP算法的本质在于消除回溯,至于如何消除回溯却并不是那么难以推导的,所以即便忘了也可以借助于大脑的逻辑演绎能力再现出来。 譬如你知道Tarjan算法其实只是从后序遍历经过两个优化调整而来的(其中并査集的使用其实只是优化手段——为了能够迅速判断祖先节点是谁——而非算法本质——当然,算法设计的主要任务本来就是通过问题条件中蕴含的知识来“消除冗余计算”和“避免不必要计算”,所以你也可以说并査集的使用是关乎本质的,只不过,知道了为什么需要引入并査集,就会强烈地感觉到一切是顺理成章的了),那这个出了名的绕人的算法也就不那么难以理解和记忆了。 譬如你知道排序的本质,就能够对什么是最优排序,为什么它是最优排序有深刻的认识。四两拨千斤。 没有一个本质层面上的关联,算法只是一堆离散的机械步骤【亚里士多德:学习即联接】 知道算法是怎样一步步被推导【产生】出来的,就拥有了大量的记忆提取线索:对算法发现过程中的任何一个关键步骤(尤其是本质)的回忆都可能使我们能够自己动手推导出剩余的内容。
包含了多得多的知识
记背后的思想,却有助于解决一类问题。
重在分析推理,而不是联想
不知道问题的本质是什么,就需要靠联想、类比来领路探索。只不过,养成优先从问题的本质入手进行考察的好习惯绝对是有更大的好处的。
深入理解一个算法的来龙去脉前因后果,从一个算法中领悟尽量深刻的东西
寻找该算法的原始出处
原始出处将的不给力
网上找找,牛人讲得未必比经典教材上的差
牛人不给力
自己来喽 为什么要这样(为什么这是好的)? 为什么不是那样(有其它做法吗?有更好的做法吗?)? 这样做是最好的吗?(为什么?能证明吗?) 这个做法跟其它的什么做法有本质联系吗? 这个跟这个的区别是什么? 问题的本质是什么? 这个做法的本质又是什么? 到底本质上是什么东西导致了这个做法如此..? 与这个问题类似的还有其它问题吗?(同样或类似的做法也适用吗?)等等。
总结
TopLanguage主题讨论“今天我们思考”的索引
知其所以然(续)
【Better Explained】
看定理必看证明
看一个问题的解法,必然要看解法所诞生的过程
背后是否隐藏着更具一般性的解决问题的思路和原则。
三件事情
Dark time 很有效
在你懂的时侯反问自己:你真的懂了吗
你是否有一种“哦,原来是这样啊,这下再也不可能忘记了”的感觉。
记录只是学习和思考的副作用
只要还在学习和思考,就必然会有新的记录,博客会不断更新
知道怎么做是从正确(高效)解法得到的,而知道为什么必须得那样做则往往是从错误(低效)的解法当中得到的。
Mathematic
The foundation concept
Number Power Logarithms
Discrete Mathematics
Mathematical induction
Concrete Mathematic
Sums Integer Functions Number Theory Binomial Coefficients
Special Numbers
Harmonic Numbers Fibonacci numbers
Generating Functions Asymptotics
Combinatorics
Permutations and Combinations
Algorithms Analysis
要分析一个算法的好坏,首先弄清它的解空间的结构,然后分析它是怎么来探索这个解空间的。
【Better Explained】
【1】解空间 【2】算法探索这个解空间方面的行为决定了它的效率高低。
排序算法
解空间N!——n个元素的全排列
探索解空间的行为
基于比较的排序 Quick sort 一次比较操作最多有两个结果,a>b或a<b,既然只有两种结果,那么最多只能将解空间进行2分,如果每次都能完美的2分,那么找到那个唯一点最终需要的步骤就是log(n!) = O(nlogn)。
01背包问题
解空间的大小是2^n——每个item是否选取(0,1)的序列 有种O(nw)的算法我还没看懂
Computer Science
Loop invariant
Initialization: It is true prior to the first iteration of the loop. Maintenance: If it is true before an iteration of the loop, it remains true before the next iteration. Termination: When the loop terminates, the invariant gives us a useful property that helps show that the algorithm is correct.
Algorithms
http://en.wikipedia.org/wiki/List_of_algorithms
Combinatorial algorithms
General combinatorial algorithms
Graph algorithms
Graph drawing Network theory Routing Search Subgraphs
Tree traversal
Depth-first Traversal
Preorder traversal Visit the root. Traverse the left subtree. Traverse the right subtree. Inorder(symmetric) traversal Traverse the left subtree. Visit the root. Traverse the right subtree. Postorder traversal Traverse the left subtree. Traverse the right subtree. Visit the root.
Breadth-first Traversal
Level order traversal
Sequence algorithms
Approximate matching Item search Merging Permutations Sequence alignment Subsequences Substrings
Sorting algorithm
http://en.wikipedia.org/wiki/Sorting_algorithm
Insertion sorts 【Better Explained】 本质 打桥牌 一边抓牌,一边码牌 对于insertion sort 改进 主要从 减少比较和移动 两方面 Insertion sort 本质 一边抓牌,一边码牌 原始出处 也许是来自于打扑克的灵感吧 Binary insertion sort 本质 Insertion sort in which the proper location for the next item is found with a binary search. 原始出处 insertion sort 改进 ,减少比较次数 Shell sort 本质 Shell sort exploits the fact that insertion sort works efficiently on input that is already almost sorted. 所以 就得先大概排一下 input data,怎么排?类似于 playing golf,一开始需要一次远距离转移,之后每次递减,直到小鸟球。交换未必完美,我想你知道老鹰球? 历史出处 devised by Donald Shell in 1959,应该说同时减少了比较和移动 List insertion sort 本质 附加的数组链表记录顺序【不是移动 】,之后用这个order 重排 原始数组i,cur,next 关于重排序:有两条线1.i是按照原始的数组前进的。cur和next 是按照附加数组内定的order 前进 。本质上就是为了指定交换的对象而已 List insertion sort 的本质是一边抓牌,一边码牌,只不过码牌有点绕 历史出处 TAOCP ,insertion sort 的改进版 ,减少移动次数 Exchange Sorts 【Better Explained】 本质 Systematically interchange pairs of elements that are out of order until no more such pairs exit 系统的交换乱序的items,直到排好了 Topic exchange selection Bubble sort 本质 for each pair of indices, swap the items if out of order 最大的被移动的最后是效果,结果。不是本质。 Two properties of the correct implementation of bubblesort: If there are no exchanges, then the sorting is complete . Each next pass ends at the last swap of the previous pass. merge exchange parallel sort partition exchange quicksort 本质 divide and conquer pivot ,reorder , partition 历史出处 Hoare developed the algorithm in order to sort the words to be translated Distribution sorts Radix sort 本质 sorts strings letter by letter 一个字母一个字母的排 所有待排数据格式化成相同字符宽度,从LSD到MSD,每次只 按一位 的大小 排序 整个元素 历史出处 Radix sort dates back as far as 1887 to the work of Herman Hollerith on tabulating machines. Counting sort 本质 本质上已经不是传统的排序了,将存储方式的转换。 是一个取巧的诡计 only for integer 有重复的 历史出处 The algorithm was first used by Harold H. Seward in 1954 Bucket sort 本质 divide and conquer partition an array into a number of buckets. Each bucket is then sorted individually . Selection sorts 【Better Explained】 本质 Repeated Selection 不是重复,是反复 Selection sort 本质 repeated selection pick the smallest 【maximum 】of the remaining elements, and exchange it with the first【last】 item of the remaining elements 历史出处 Heapsort 本质 repeated selection convert the list into a heap, keep removing the largest element from the heap and adding it to the end of the list 本质仍是,不断的选择 pick ,只是 选择的地方换了,变得更利于 pick,当然,首先你需要把 数组链表转换成——heap 建堆,不是我们现在应该关心的,他不是本质。 Merge sorts 【Better Explained】 本质 divide and conquer &merge partition ,sort...until can't partition ,then merge Merge sort 本质 divide and conquer & merge partition ,sort...until can't partition ,then merge sort the first and second half of the list separately, then merge the sorted lists 历史出处 Merge sort was invented by John von Neumann in 1945. Strand sort 本质 divide and conquer & merge extract sorted list from raw list,then merge it with the previous extracted list 历史出处 对于大半排好序的链表,strand sort 表现很好
ETC
Computational mathematics
Abstract algebra Computer algebra Geometry Number theoretic algorithms
Numerical algorithms
Elementary and special functions Geometric Interpolation and extrapolation Linear algebra Monte Carlo Numerical integration Root finding
Optimization algorithms
Computational science
Astronomy Bioinformatics Geoscience Linguistics Medicine Physics Statistics
Computer science
Computer architecture Computer architecture Computer graphics Cryptography Digital logic Machine learning and statistical classification
Programming language theory
Parsing
Quantum algorithms Theory of computation and automata
Information theory and signal processing
Coding theory
Error detection and correction Lossless compression algorithms Lossy compression algorithms
Digital signal processing
Image processing
Software engineering
Database algorithms Distributed systems algorithms Memory allocation and deallocation algorithms
Operating systems algorithms
Disk scheduling Networking Process synchronization Scheduling
Data structures
http://en.wikipedia.org/wiki/List_of_data_structures
Data types
Primitive types
Boolean Char Double Float int String
Composite types
Record (also called tuple or struct) Union
Tagged union
我理解为 enum
Abstract data types
Container Deque Map/Associative array/Dictionary Multimap Multiset Priority queue Queue Set Stack String Tree Graph Hash
Trees
Binary trees
AA tree AVL tree
Binary search tree
【Better Explained】 Properties The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. Operations Searching Insertion Deletion Traversal Sort
Binary tree Cartesian tree Randomized binary search tree
Red-black tree
【Better Explained】 Requirements A node is either red or black. The root is black. (This rule is sometimes omitted from other definitions. Since the root can always be changed from red to black but not necessarily vice-versa this rule has little effect on analysis.) All leaves are black. Both children of every red node are black. Every simple path from a given node to any of its descendant leaves contains the same number of black nodes. 历史出处 Robert Sedgewick Left-Leaning Red-Black Trees I need to see it more and more.
Rope Scapegoat tree Self-balancing binary search tree Splay tree T-tree Tango tree Threaded binary tree Top tree Treap Van Emde Boas tree Weight-balanced tree
B-trees
B-tree B+ tree B*-tree B sharp tree Dancing tree 2-3 tree 2-3-4 tree Queap Fusion tree Bx-tree
Heaps
Heap Binary heap Binomial heap
Fibonacci heap
AF-heap
2-3 heap Soft heap Pairing heap Leftist heap Treap Beap Skew heap Ternary heap D-ary heap [edit]
Tries
Trie Radix tree Suffix tree Suffix array Compressed suffix array FM-index Generalised suffix tree B-trie Judy array
Multiway trees
Ternary search tree And–or tree (a,b)-tree Link/cut tree SPQR-tree Spaghetti stack Disjoint-set data structure Fusion tree Enfilade Exponential tree Fenwick tree
Space-partitioning trees
Segment tree Interval tree Range tree Bin Kd-tree Implicit kd-tree Min/max kd-tree Adaptive k-d tree Kdb tree Quadtree Octree Linear octree Z-order UB-tree R-tree R+ tree R* tree Hilbert R-tree X-tree Metric tree Cover tree M-tree VP-tree BK-tree Bounding interval hierarchy BSP tree Rapidly-exploring random tree
Application-specific trees
Syntax tree Abstract syntax tree Parse tree Decision tree Alternating decision tree Minimax tree Expectiminimax tree Finger tree
Linear data structures
Arrays
Array Bidirectional map Bit array Bit field Bitboard Bitmap Circular buffer Control table Image Dynamic array Gap buffer Hashed array tree Heightmap Lookup table Matrix Parallel array Sparse array Sparse matrix Iliffe vector Variable-length array
Lists
The operations of linear lists
【1】Search 【2】Insert 【3】Delete 【】
Doubly linked list Linked list Self-organizing list Skip list Unrolled linked list VList Xor linked list Zipper Doubly-connected edge list
Hashes
Bloom filter Distributed hash table Hash array mapped trie Hash list Hash table Hash tree Hash trie Koorde Prefix hash tree
Graphs
Graph Adjacency list Adjacency matrix Graph-structured stack Scene graph Binary decision diagram Zero suppressed decision diagram And-inverter graph Propositional directed acyclic graph Directed graph Multigraph
Other
Lightmap Winged edge Quad-edge Routing table Symbol table