Merge branch 'gh-pages' of https://github.com/parkjs814/AlgorithmVisu… · hackboy/AlgorithmVisualizer@0f883f7 · GitHub
Skip to content

Commit 0f883f7

Browse files
committed
Merge branch 'gh-pages' of https://github.com/parkjs814/AlgorithmVisualizer into gh-pages
2 parents ee9e4d9 + 88914ec commit 0f883f7

12 files changed

Lines changed: 189 additions & 15 deletions

File tree

README.md

Lines changed: 75 additions & 3 deletions

algorithm/category.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"bubble": "Bubble Sort",
3131
"quick": "Quicksort",
3232
"merge": "Mergesort",
33-
"heap" : "Heap Sort"
33+
"heap" : "Heap Sort",
34+
"radix" : "Radix Sort"
3435
}
3536
},
3637
"string": {

algorithm/etc/dp/desc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"fibonacci": "Fibonacci Sequence",
1212
"sliding_window": "Finding the largest sum of three contiguous number",
1313
"max_sum_path": "Finding the maximum sum in a path from (0, 0) to (N-1, M-1) when can only move to right or down",
14-
"longest_increasing_subsequence": "Find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order"
14+
"longest_increasing_subsequence": "Find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order",
15+
"max_subarray": "Find the sum of the maximum Subarray in the given Array"
1516
}
1617
}

algorithm/etc/dp/longest_increasing_subsequence/code.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Initialize LIS values for all indexes
2-
for (var i = 0; i < 20; i++) {
2+
for (var i = 0; i < A.length; i++) {
33
LIS[i] = 1;
44
}
55

66
logger._print('Calculating Longest Increasing Subsequence values in bottom up manner ');
77
// Compute optimized LIS values in bottom up manner
8-
for (var i = 1; i < 10; i++) {
8+
for (var i = 1; i < A.length; i++) {
99
tracer._select(i);
1010
logger._print(' LIS[' + i + '] = ' + LIS[i]);
1111
for (var j = 0; j < i; j++) {
@@ -22,9 +22,9 @@ for (var i = 1; i < 10; i++) {
2222
// Pick maximum of all LIS values
2323
logger._print('Now calculate maximum of all LIS values ');
2424
var max = LIS[0];
25-
for (var i = 1; i < 10; i++) {
26-
if (max < LIS[i]) {
27-
max = LIS[i];
28-
}
25+
for (var i = 1; i < A.length; i++) {
26+
if (max < LIS[i]) {
27+
max = LIS[i];
28+
}
2929
}
3030
logger._print('Longest Increasing Subsequence = max of all LIS = ' + max);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var tracer = new Array1DTracer();
22
var logger = new LogTracer();
33
var A = Array1D.random(10, 0, 10);
4-
var LIS = new Array(10);
4+
var LIS = new Array(A.length);
55
tracer._setData(A);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var maxSubarraySum = (function maxSubarray (array) {
2+
var maxSoFar = 0,
3+
maxEndingHere = 0;
4+
5+
tracer._print ('Initializing maxSoFar = 0 & maxEndingHere = 0');
6+
7+
for (var i = 0; i < array.length; i++) {
8+
tracer._select (i);
9+
tracer._print (maxEndingHere + ' + ' + array [i]);
10+
maxEndingHere += array [i];
11+
tracer._print ('=> ' + maxEndingHere);
12+
13+
if (maxEndingHere < 0) {
14+
tracer._print ('maxEndingHere is negative, set to 0');
15+
maxEndingHere = 0;
16+
}
17+
18+
if (maxSoFar < maxEndingHere) {
19+
tracer._print ('maxSoFar < maxEndingHere, setting maxSoFar to maxEndingHere (' + maxEndingHere + ')');
20+
maxSoFar = maxEndingHere;
21+
}
22+
23+
tracer._deselect (i);
24+
}
25+
26+
return maxSoFar;
27+
}) (D);
28+
29+
tracer._print ('Maximum Subarray\'s Sum is: ' + maxSubarraySum);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var tracer = new Array1DTracer ();
2+
var D = [-2, -3, 4, -1, -2, 1, 5, -3];
3+
4+
tracer._setData (D);

algorithm/sorting/heap/basic/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ function heapify(array, size, root) {
5151
}
5252
}
5353

54-
heapSort(D, 10);
54+
heapSort(D, D.length);
5555

5656
logger._print('Final array = [' + D.join(', ') + ']');

algorithm/sorting/radix/desc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Radix LSD Sort": "Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.",
3+
"Complexity": {
4+
"time": "worst O(n), best O(n), average O(n)",
5+
"space": "always O(n)"
6+
},
7+
"References": [
8+
"<a href='https://en.wikipedia.org/wiki/Radix_sort'>Wikipedia</a>"
9+
],
10+
"files": {
11+
"lsd": "LSD Radix sort"
12+
}
13+
}
Lines changed: 44 additions & 0 deletions

0 commit comments

Comments
 (0)