├── Graph Theory ├── Edge.js ├── Graph Order.html ├── Adjacency Lists.html ├── Adjacency Matrix.html ├── FindPath.html └── ShortestPath.html ├── isPrime.html ├── copyReverse.html ├── Sort ├── BubbleSort.html ├── InsertionSort.html ├── SelectSort.html ├── Shell Sort.html ├── SortTestHelper.js ├── Heap Sort.html ├── ThreeWayQuickSort.html ├── Double Way Quick Sort.html ├── MergeSort Bottom.html ├── Radix Sort.html ├── Quick Sort.html └── MergeSort.html ├── Template Algorithms.html ├── findMaxGroup.html ├── Classical algorithm problem ├── Manacher.html ├── monotonyStack.html ├── KMP.html ├── Binary Search.html ├── knapsack01.html ├── 8-Queens.html ├── LRU.html ├── BFPRT.html ├── Boyer-Moore.html ├── Bellman-Ford.html ├── Top K.html └── Dijkstra.html ├── Queue └── priority_queue.html ├── Drumming and passing flowers.html ├── Tree ├── Union Find.html ├── IndexHeap.html ├── RedBlack Tree.html ├── Segment Tree.html ├── Heap.html ├── Trie.html ├── AVL Tree.html └── Binary Search Tree.html ├── HashMap.html ├── Minimum Span Tree ├── LazyPrim.html ├── kruskal.html └── PrimMinIndexHeap.html ├── Linked list ├── Linked List.html ├── Double LinkedList.html └── DoubleLoopLinkedList.html ├── Other data structures └── HashTable.html └── README.md /Graph Theory/Edge.js: -------------------------------------------------------------------------------- 1 | class Edge { 2 | constructor(start, end, weight) { 3 | this.start = start; 4 | this.end = end; 5 | this.weight = weight; 6 | } 7 | 8 | other(x) { 9 | return x === this.v() ? this.w() : this.v() 10 | } 11 | 12 | v() { 13 | return this.start 14 | } 15 | 16 | w() { 17 | return this.end 18 | } 19 | 20 | wt() { 21 | return this.weight 22 | } 23 | } -------------------------------------------------------------------------------- /isPrime.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 26 | 27 | -------------------------------------------------------------------------------- /copyReverse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 24 | 25 | -------------------------------------------------------------------------------- /Sort/BubbleSort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 24 | 25 | -------------------------------------------------------------------------------- /Sort/InsertionSort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 27 | 28 | -------------------------------------------------------------------------------- /Sort/SelectSort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 28 | 29 | -------------------------------------------------------------------------------- /Template Algorithms.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 27 | 28 | -------------------------------------------------------------------------------- /Sort/Shell Sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 29 | 30 | -------------------------------------------------------------------------------- /Sort/SortTestHelper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by di on 2017/6/10. 3 | */ 4 | var swap = function (arr, curr, min) { 5 | var temp = arr[curr]; 6 | arr[curr] = arr[min]; 7 | arr[min] = temp; 8 | } 9 | 10 | var generateRandomArray = function (n, rangeL, rangeR) { 11 | var arr = []; 12 | for (var i = 0; i < n; i++) { 13 | arr.push(Math.floor(Math.random() * (rangeR - rangeL + 1))) 14 | } 15 | return arr; 16 | } 17 | 18 | var testSort = function (fn) { 19 | var start = new Date(); 20 | console.log(start) 21 | var arr = [].slice.call(arguments, 1); 22 | fn.apply(this, arr); 23 | var end = new Date(); 24 | console.log(end); 25 | var time = end - start; 26 | console.log(time); 27 | } 28 | 29 | var isSorted = function (n) { 30 | var arr = []; 31 | for (var i = 0; i < n; i++) { 32 | arr.push(i); 33 | } 34 | return arr; 35 | } -------------------------------------------------------------------------------- /Graph Theory/Graph Order.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 37 | 38 | -------------------------------------------------------------------------------- /Sort/Heap Sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 38 | 39 | -------------------------------------------------------------------------------- /findMaxGroup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 36 | 37 | -------------------------------------------------------------------------------- /Sort/ThreeWayQuickSort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 40 | 41 | -------------------------------------------------------------------------------- /Classical algorithm problem/Manacher.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 41 | 42 | -------------------------------------------------------------------------------- /Sort/Double Way Quick Sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 48 | 49 | -------------------------------------------------------------------------------- /Classical algorithm problem/monotonyStack.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 单调栈 6 | 7 | 8 | 42 | 43 | -------------------------------------------------------------------------------- /Queue/priority_queue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 45 | 46 | -------------------------------------------------------------------------------- /Classical algorithm problem/KMP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | KMP 6 | 7 | 8 | 47 | 48 | -------------------------------------------------------------------------------- /Sort/MergeSort Bottom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 47 | 48 | -------------------------------------------------------------------------------- /Sort/Radix Sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 52 | 53 | -------------------------------------------------------------------------------- /Drumming and passing flowers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 | 50 | 51 | -------------------------------------------------------------------------------- /Classical algorithm problem/Binary Search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 51 | 52 | -------------------------------------------------------------------------------- /Graph Theory/Adjacency Lists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 62 | 63 | -------------------------------------------------------------------------------- /Classical algorithm problem/knapsack01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 54 | 55 | -------------------------------------------------------------------------------- /Classical algorithm problem/8-Queens.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 61 | 62 | -------------------------------------------------------------------------------- /Graph Theory/Adjacency Matrix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 77 | 78 | -------------------------------------------------------------------------------- /Tree/Union Find.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 65 | 66 | -------------------------------------------------------------------------------- /Graph Theory/FindPath.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 79 | 80 | -------------------------------------------------------------------------------- /Classical algorithm problem/LRU.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LRU 6 | 7 | 8 | 76 | 77 | -------------------------------------------------------------------------------- /HashMap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 79 | 80 | -------------------------------------------------------------------------------- /Sort/Quick Sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 94 | 95 | -------------------------------------------------------------------------------- /Graph Theory/ShortestPath.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 86 | 87 | -------------------------------------------------------------------------------- /Classical algorithm problem/BFPRT.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BFPRT 6 | 7 | 8 | 9 | 10 | 81 | 82 | -------------------------------------------------------------------------------- /Minimum Span Tree/LazyPrim.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Prim 6 | 7 | 8 | 9 | 84 | 85 | -------------------------------------------------------------------------------- /Tree/IndexHeap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 索引堆 6 | 7 | 8 | 9 | 93 | 94 | -------------------------------------------------------------------------------- /Classical algorithm problem/Boyer-Moore.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BM算法(坏字符匹配) 6 | 7 | 8 | 93 | 94 | -------------------------------------------------------------------------------- /Sort/MergeSort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 108 | 109 | -------------------------------------------------------------------------------- /Minimum Span Tree/kruskal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 104 | 105 | -------------------------------------------------------------------------------- /Linked list/Linked List.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 143 | 144 | -------------------------------------------------------------------------------- /Tree/RedBlack Tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 147 | 148 | -------------------------------------------------------------------------------- /Tree/Segment Tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 119 | 120 | -------------------------------------------------------------------------------- /Classical algorithm problem/Bellman-Ford.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 134 | 135 | -------------------------------------------------------------------------------- /Other data structures/HashTable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 140 | 141 | -------------------------------------------------------------------------------- /Classical algorithm problem/Top K.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 153 | 154 | -------------------------------------------------------------------------------- /Linked list/Double LinkedList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 145 | 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms-and-Data-Structures 2 | 3 | ##### 经典算法 4 | > 已完成 5 | - [x] [BFPRT(无序数组寻找第N大(小)元素)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/BFPRT.html) 6 | - [x] [KMP(字符串快速匹配)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/KMP.html) 7 | - [x] [knapsack01(背包01问题)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/knapsack01.html) 8 | - [x] [monotonyStack(单调栈)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/monotonyStack.html) 9 | - [x] [Binary Search(二分查找)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/Binary%20Search.html) 10 | - [x] [8-Queens(八皇后问题)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/8-Queens.html) 11 | - [x] [Dijkstra(迪杰斯特拉算法)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/Dijkstra.html) 12 | - [x] [Boyer-Moore(坏字符串匹配算法)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/Boyer-Moore.html) 13 | - [x] [Bellman-Ford(负权边最短路径)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/Bellman-Ford.html) 14 | - [x] [Top K(前K大(小)的数)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Classical%20algorithm%20problem/Top%20K.html) 15 | 16 | ##### 排序 17 | > 已完成 18 | - [x] [冒泡排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/BubbleSort.html) 19 | - [x] [选择排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/SelectSort.html) 20 | - [x] [插入排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/InsertionSort.html) 21 | - [x] [归并排序 I](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/MergeSort.html) 22 | - [x] [归并排序 II](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/MergeSort%20Bottom.html) 23 | - [x] [快速排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/Quick%20Sort.html) 24 | - [x] [双路快速排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/Double%20Way%20Quick%20Sort.html) 25 | - [x] [三路快速排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/ThreeWayQuickSort.html) 26 | - [x] [希尔排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/Shell%20Sort.html) 27 | - [x] [堆排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/Heap%20Sort.html) 28 | - [x] [基数排序](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Sort/Radix%20Sort.html) 29 | 30 | ##### 链表 31 | > 已完成 32 | - [x] [单向链表](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Linked%20list/Linked%20List.html) 33 | - [x] [双向链表](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Linked%20list/Double%20LinkedList.html) 34 | - [x] [双向循环链表](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Linked%20list/DoubleLoopLinkedList.html) 35 | 36 | ##### 图论 37 | > 已完成 38 | - [x] [邻接矩阵](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Graph%20Theory//Adjacency%20Matrix.html) 39 | - [x] [邻接表](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Graph%20Theory//Adjacency%20Lists.html) 40 | - [x] [寻路算法](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Graph%20Theory//FindPath.html) 41 | - [x] [寻路 - 最短路径查找](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Graph%20Theory/ShortestPath.html) 42 | - [x] [无向图 - 连通分量](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Graph%20Theory/Graph%20Order.html) 43 | 44 | ##### 树 45 | > 已完成 46 | - [x] [二分搜索树(包含前中后序遍历(递归、非递归、morris解法)、广度遍历)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/Binary%20Search%20Tree.html) 47 | - [x] [堆](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/Heap.html) 48 | - [x] [索引堆](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/IndexHeap.html) 49 | - [x] [线段树](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/Segment%20Tree.html) 50 | - [x] [并查集](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/Union%20Find.html) 51 | - [x] [字典树](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/Trie.html) 52 | - [x] [AVL树](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/AVL%20Tree.html) 53 | - [x] [红黑树](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Tree/RedBlack%20Tree.html) 54 | 55 | ##### 最小生成树 56 | > 已完成 57 | - [x] [LazyPrim(有权图最小生成树 - 普通递归构建)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Minimum%20Span%20Tree/LazyPrim.html) 58 | - [x] [PrimMinIndexHeap(有权图最小成生成树 - 最小索引堆构建)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Minimum%20Span%20Tree/PrimMinIndexHeap.html) 59 | - [x] [kruskal(有权图最小生成树 - 并查集构建)](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Minimum%20Span%20Tree/kruskal.html) 60 | 61 | ##### 其他数据结构 62 | > 已完成 63 | - [x] [哈希表](https://github.com/biaodigit/JavaScriptAlgorithms/blob/master/Other%20data%20structures/HashTable.html) 64 | 65 | ##### 致谢 66 | > 衷心感谢[波波老师](https://github.com/liuyubobobo)的优秀教学 67 | 68 | -------------------------------------------------------------------------------- /Tree/Heap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 171 | 172 | -------------------------------------------------------------------------------- /Linked list/DoubleLoopLinkedList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 165 | 166 | -------------------------------------------------------------------------------- /Minimum Span Tree/PrimMinIndexHeap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 177 | 178 | -------------------------------------------------------------------------------- /Tree/Trie.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Trie 6 | 7 | 8 | 205 | 206 | -------------------------------------------------------------------------------- /Classical algorithm problem/Dijkstra.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 单源最短路径 - 迪杰斯特拉算法 6 | 7 | 8 | 9 | 206 | 207 | -------------------------------------------------------------------------------- /Tree/AVL Tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AVL(平衡树) 6 | 7 | 8 | 324 | 325 | -------------------------------------------------------------------------------- /Tree/Binary Search Tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 363 | 364 | --------------------------------------------------------------------------------