File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 }
2222 }
2323
24- /**
24+ /**
2525 * Finds all the permutations of given array.<br><br>
2626 * Permutation relates to the act of rearranging, or permuting,
2727 * all the members of a set into some sequence or order.
Original file line number Diff line number Diff line change 6666 }
6767 } ;
6868
69- // function isSubstr(tree, str) {
70- // if (!tree) {
71- // return false;
72- // }
73- // if (tree.nodes[str[0]]) {
74- // return isSubstr(tree, str.substr(1, str.length));
75- // }
76- // var match = '';
77- // for (var i = 0; i < Math.min(tree.value.length, str.length); i += 1) {
78- // if (tree.value[i] === str[i]) {
79- // match += str[i];
80- // } else {
81- // break;
82- // }
83- // }
84- // if (match.length === str.length) {
85- // return true;
86- // }
87- // return false;
88- // }
89-
90- // var suffix = new SuffixTree();
91- // suffix.build('banana');
92- // console.log(suffix);
93-
9469 exports . Node = Node ;
9570 exports . SuffixTree = SuffixTree ;
9671
Original file line number Diff line number Diff line change 33
44 exports . longestSubsequence = ( function ( ) {
55
6- /**
6+ /**
77 * Find the index of the first largest element in array.
88 * Complexity: O(N).
99 *
2929 return maxIdx ;
3030 }
3131
32- /**
32+ /**
3333 * Default comparison method.
3434 * @private
3535 */
3636 function cmp ( a , b ) {
3737 return a . distance - b . distance ;
3838 }
3939
40- /**
40+ /**
4141 * Creates directed graph from given array.
4242 * Each element's neighbours are the elements which can be
4343 * after the element in the resulting sequence.<br><br>
5959 return result ;
6060 }
6161
62- /**
62+ /**
6363 * Finds the longest sub-sequence for given node.<br><br>
6464 * Complexity: O(N^N).
6565 * @private
9898 return result ;
9999 }
100100
101- /**
101+ /**
102102 * Algorithm from dynamic programming. It finds the longest
103103 * sub-sequence of increasing numbers. It is not required
104104 * the numbers to be neighboring. For example for 1, 5, 2
Original file line number Diff line number Diff line change 2828( function ( exports ) {
2929 'use strict' ;
3030
31- /**
31+ /**
3232 * Initialization.<br><br>
3333 * Time complexity: O(N).
3434 *
4545 }
4646 } ;
4747
48- /**
48+ /**
4949 * Finds the root of given node.<br><br>
5050 * Time complexity: O(log N).
5151 * @private
6060 return i ;
6161 } ;
6262
63- /**
63+ /**
6464 * Checks whether two nodes are connected.<br><br>
6565 * Time complexity: O(log N).
6666 *
7272 return this . _root ( p ) === this . _root ( q ) ;
7373 } ;
7474
75- /**
75+ /**
7676 * Connects two nodes - p and q.<br><br>
7777 * Time complexity: O(log N).
7878 *
You can’t perform that action at this time.
0 commit comments