r/programming • • Dec 02 '19

Bubble sort visualization

7.4k Upvotes

268 comments sorted by

View all comments

Show parent comments

1

u/chucker23n Dec 03 '19

Why would you teach anyone how not to do something?

Umm. To explain strengths and weaknesses? To explain how to optimize something that already fulfills requirements but isn’t efficient? To make a design trade off that the simpler algorithm is sometimes good enough?

IMO, the introductory algorithm to sorting is Selection sort.

Selection sort introduces state and is therefore way more complicated to explain.

1

u/[deleted] Dec 03 '19

How does selection sort introduce state?

And why do you think it's more complicated to explain? It is literally how a fourth grader would approach sorting a list of numbers, it is how you would sort the money in your wallet, it is the default human way of thinking.