Skip to content

Commit 75751ab

Browse files
committed
add Quicksort
1 parent 13a7881 commit 75751ab

File tree

17 files changed

+97
-15
lines changed

17 files changed

+97
-15
lines changed

algorithm/category.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"insertion": "Insertion Sort",
1313
"selection": "Selection Sort",
1414
"bubble": "Bubble Sort",
15-
"quick": "Quick Sort"
15+
"quick": "Quicksort"
1616
}
1717
}
1818
}

algorithm/graph_search/bfs/basic/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ function BFS(s) { // s = start node
1212
}
1313
}
1414
}
15-
1615
BFS(0);

algorithm/graph_search/bfs/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"Construction of the failure function of the Aho-Corasick pattern matcher."
1111
],
1212
"cpx": {
13-
"time": "O(|E|)",
14-
"space": "O(|V|)"
13+
"time": "worst O(|E|)",
14+
"space": "worst O(|V|)"
1515
},
1616
"refs": [
1717
"https://en.wikipedia.org/wiki/Breadth-first_search"

algorithm/graph_search/bfs/shortest_path/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function BFS() {
2222
}
2323
return W[e];
2424
}
25-
2625
var s = Math.random() * G.length | 0; // s = start node
2726
var e; // e = start node
2827
do {

algorithm/graph_search/dfs/all_paths/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function DFS(node, parent) { // node = current node, parent = previous node
1111
D[node] = false; // label current node as undiscovered
1212
tracer._leave(node, parent);
1313
}
14-
1514
var D; // D[i] indicates whether the i-th node is discovered or not
1615
for (var i = 0; i < G.length; i++) { // start from every node
1716
tracer._print('start from ' + i);

algorithm/graph_search/dfs/basic/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ function DFS(node, parent) { // node = current node, parent = previous node
66
}
77
}
88
}
9-
109
DFS(0);

algorithm/graph_search/dfs/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"Finding biconnectivity in graphs."
1515
],
1616
"cpx": {
17-
"time": "O(|E|)",
18-
"space": "O(|V|)"
17+
"time": "worst O(|E|)",
18+
"space": "worst O(|V|)"
1919
},
2020
"refs": [
2121
"https://en.wikipedia.org/wiki/Depth-first_search"

algorithm/graph_search/dfs/shortest_path/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function DFS(node, parent, weight) { // node = current node, parent = previous n
2020
D[node] = false; // label current node as undiscovered
2121
tracer._leave(node, parent, 0);
2222
}
23-
2423
var s = Math.random() * G.length | 0; // s = start node
2524
var e; // e = end node
2625
do {

algorithm/graph_search/dfs/weighted_graph/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function DFS(node, parent, weight) { // node = current node, parent = previous n
1111
D[node] = false; // label current node as undiscovered
1212
tracer._leave(node, parent, 0);
1313
}
14-
1514
var D; // D[i] indicates whether the i-th node is discovered or not
1615
tracer._pace(1000);
1716
for (var i = 0; i < G.length; i++) { // start from every node
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
tracer._print('original array = [' + D.join(', ') + ']');
2+
tracer._sleep(1000);
3+
tracer._pace(300);
4+
var N = D.length;
5+
var swapped;
6+
do {
7+
swapped = false;
8+
tracer._select(N - 1);
9+
for (var i = 1; i < N; i++) {
10+
if (D[i - 1] > D[i]) {
11+
tracer._print('swap ' + D[i - 1] + ' and ' + D[i]);
12+
var temp = D[i - 1];
13+
D[i - 1] = D[i];
14+
D[i] = temp;
15+
swapped = true;
16+
tracer._notify(i - 1, i);
17+
}
18+
}
19+
tracer._deselect(N - 1);
20+
N--;
21+
} while (swapped);
22+
tracer._print('sorted array = [' + D.join(', ') + ']');

0 commit comments

Comments
 (0)