Skip to content

Commit 17c8767

Browse files
committed
Sorting time complexity
1 parent 58473b3 commit 17c8767

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

algorithm/sorting/bubble/basic/code.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 5 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy