forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
30 lines (28 loc) · 896 Bytes
/
Copy pathcode.js
File metadata and controls
30 lines (28 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Initialize LIS values for all indexes
for (var i = 0; i < A.length; i++) {
LIS[i] = 1;
}
logger._print('Calculating Longest Increasing Subsequence values in bottom up manner ');
// Compute optimized LIS values in bottom up manner
for (var i = 1; i < A.length; i++) {
tracer._select(i);
logger._print(' LIS[' + i + '] = ' + LIS[i]);
for (var j = 0; j < i; j++) {
tracer._notify(j)._wait();
tracer._denotify(j);
if (A[i] > A[j] && LIS[i] < LIS[j] + 1) {
LIS[i] = LIS[j] + 1;
logger._print(' LIS[' + i + '] = ' + LIS[i]);
}
}
tracer._deselect(i);
}
// Pick maximum of all LIS values
logger._print('Now calculate maximum of all LIS values ');
var max = LIS[0];
for (var i = 1; i < A.length; i++) {
if (max < LIS[i]) {
max = LIS[i];
}
}
logger._print('Longest Increasing Subsequence = max of all LIS = ' + max);