-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
Selection Sort, for example, makes the algorithm look extremely (impossibly) good at first glance - O(n) - because it's not showing the majority of the steps.
Instead of
for (var j = i + 1; j < D.length; j++) {
if (D[j] < D[minJ]) {
tracer._select(j);
minJ = j;
tracer._deselect(j);
}
}
it has to be more like
for (var j = i + 1; j < D.length; j++) {
tracer._select(j);
if (D[j] < D[minJ]) {
minJ = j;
}
tracer._deselect(j);
}
Bubble Sort has the same problem, as do Quicksort and Mergesort.
Normally I wouldn't mind, as showing time complexity is probably not the scope of these examples or your visualization, but the examples suggest that this is intended for beginners, and it might give them a false sense of the time complexity of these basic algorithms.
By the way, I really like the visualization, I think it could be quite helpful to aid teaching about algorithms.
rajraku, welll and h75xyz