Skip to content

Commit e4a7efd

Browse files
committed
Merge remote-tracking branch 'upstream/gh-pages' into feature/mst
2 parents e55aa83 + da6ef40 commit e4a7efd

File tree

8 files changed

+97
-1
lines changed

8 files changed

+97
-1
lines changed

algorithm/category.json

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
"heap" : "Heap Sort"
3434
}
3535
},
36+
"string": {
37+
"name": "String",
38+
"list": {
39+
"edit_distance": "Edit Distance"
40+
}
41+
},
3642
"etc": {
3743
"name": "Uncategorized",
3844
"list": {
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Edit-Distance": "Given two strings str1 (length M) and str2 (length N) and below operations that can performed on str1. Find minimum number of edits (operations) required to convert str1 into str2.<br />Insert<br />Remove<br />Replace<br />All of the above operations are of equal cost",
3+
"Applications": [
4+
"Displaing Near-Proximity Words",
5+
"Information Retrieval (eg- Lucene API)",
6+
"Natural Language Processing"
7+
],
8+
"Complexity": {
9+
"time": "worst O(|M|.|N|)",
10+
"space": "worst O(|M|.|N|)"
11+
},
12+
"References": [
13+
"<a href='https://en.wikipedia.org/wiki/Edit_distance'>Wikipedia</a>"
14+
],
15+
"files": {
16+
"dynamic_programming": "Distance from str1 to str2 using Dynamic Programming (2D Array method)"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
tracer._pace (200);
2+
tracer._print ('Initialized DP Table');
3+
tracer._print ('Y-Axis (Top to Bottom): ' + str1);
4+
tracer._print ('X-Axis (Left to Right): ' + str2);
5+
6+
var dist = (function editDistance (str1, str2, table) {
7+
//display grid with words
8+
tracer._print ('*** ' + str2.split ('').join (' '));
9+
table.forEach (function (item, index) {
10+
var character = (index === 0) ? '*' : str1 [index-1];
11+
tracer._print (character + '\t' + item);
12+
});
13+
14+
//begin ED execution
15+
for (var i = 1; i < str1.length+1; i++) {
16+
for (var j = 1; j < str2.length+1; j++) {
17+
if (str1 [i-1] === str2 [j-1]) {
18+
tracer._select (i-1, j-1);
19+
table [i] [j] = table [i-1] [j-1];
20+
tracer._notify (i, j);
21+
tracer._deselect (i-1, j-1);
22+
}
23+
else {
24+
tracer._select (i-1, j);
25+
tracer._select (i, j-1);
26+
tracer._select (i-1, j-1);
27+
table [i] [j] = Math.min (table [i-1] [j], table [i] [j-1], table [i-1] [j-1]) + 1;
28+
tracer._notify (i, j);
29+
tracer._deselect (i-1, j);
30+
tracer._deselect (i, j-1);
31+
tracer._deselect (i-1, j-1);
32+
}
33+
}
34+
}
35+
36+
tracer._select (str1.length, str2.length);
37+
return table [str1.length] [str2.length];
38+
}) (str1, str2, table);
39+
40+
tracer._print ('Minimum Edit Distance: ' + dist);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var tracer = new Array2DTracer ();
2+
var str1 = 'stack', str2 = 'racket', table = new Array (str1.length + 1);
3+
4+
table [0] = Array.apply (null, {length: str2.length + 1}).map (Number.call, Number);
5+
for (var i = 1; i < str1.length+1; i++) {
6+
table [i] = Array.apply (null, Array (str2.length+1)).map (Number.prototype.valueOf, -1);
7+
table [i] [0] = i
8+
}
9+
10+
tracer._setData (table);

css/stylesheet.css

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ body {
1010
color: rgb(187, 187, 187);
1111
}
1212

13+
*::-webkit-scrollbar {
14+
width: 15px;
15+
}
16+
*::-webkit-scrollbar-track {
17+
background-color: #3C3F41;
18+
}
19+
20+
*::-webkit-scrollbar-thumb {
21+
background-color: rgba(0, 0, 0, 0.2);
22+
}
23+
*::-webkit-scrollbar-button {
24+
background-color: #7c2929;
25+
}
26+
*::-webkit-scrollbar-corner {
27+
background-color: #3C3F41;
28+
}
29+
1330
a {
1431
text-decoration: none;
1532
}
@@ -287,4 +304,4 @@ pre {
287304

288305
.mtbl-cell.notifying {
289306
background: #f00;
290-
}
307+
}

img/favicon.ico

1.12 KB
Binary file not shown.

img/image.png

25.8 KB
Loading

index.html

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5+
<meta name="description" content="Tool for visualizing algorithms." />
6+
<meta property="og:title" content="Algorithm Visualizer" />
7+
<meta property="og:description" content="Tool for visualizing algorithms." />
8+
<meta property="og:image" content="img/image.png" />
9+
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
510
<title>Algorithm Visualizer</title>
611
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
712
<link rel="stylesheet" href="css/font-awesome.min.css">

0 commit comments

Comments
 (0)