Skip to content

Commit f86e3d4

Browse files
committed
Merge pull request algorithm-visualizer#30 from TornjV/fix/sorting
Sorting time complexity
2 parents dc6901c + 17c8767 commit f86e3d4

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

algorithm/sorting/bubble/basic/code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ do {
77
swapped = false;
88
tracer._select(N - 1);
99
for (var i = 1; i < N; i++) {
10+
tracer._notify(i - 1, i);
1011
if (D[i - 1] > D[i]) {
1112
tracer._print('swap ' + D[i - 1] + ' and ' + D[i]);
1213
var temp = D[i - 1];
1314
D[i - 1] = D[i];
1415
D[i] = temp;
1516
swapped = true;
16-
tracer._notify(i - 1, i);
1717
}
1818
}
1919
tracer._deselect(N - 1);

algorithm/sorting/quick/basic/code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function partition(low, high) {
1717
var temp;
1818

1919
for (var j = low; j < high; j++) {
20+
tracer._notify(i, j);
2021
if (D[j] <= pivot) {
2122
temp = D[i];
2223
D[i] = D[j];
2324
D[j] = temp;
24-
tracer._notify(i, j);
2525
i++;
2626
}
2727
}

algorithm/sorting/selection/basic/code.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ for (var i = 0; i < D.length - 1; i++) {
55
var minJ = i;
66
tracer._select(i);
77
for (var j = i + 1; j < D.length; j++) {
8-
if (D[j] < D[minJ]) {
9-
tracer._select(j);
10-
minJ = j;
11-
tracer._deselect(j);
12-
}
8+
tracer._select(j);
9+
if (D[j] < D[minJ]) minJ = j;
10+
tracer._deselect(j);
1311
}
1412
if (minJ != i) {
1513
tracer._print('swap ' + D[i] + ' and ' + D[minJ]);

0 commit comments

Comments
 (0)