Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That seems more like a layman's explanation of a binary search than O(log N). Binary search just happens to be O(log N)


Binary search is an example of a O(log N) algorithm, as OP said. Having tangible examples is great for explaining algorithmic complexity to people.

One I've used is sorting with a deck of cards. Take a single suit, A-K, and have people sort it using bubble or insertion or other sorts. It's only 13 cards, but the difference even between some of the O(n^2) algorithms becomes obvious when swapping is postponed until the latest stage versus earliest.

Then you can also demonstrate radix sort. One of the most underrated sorting algorithms, in my opinion. A lot of people focus on the (potentially) large constant. But it can be appropriate, or may be reduced depending on your use-case. And it's a fantastic sort when you can't give a neat numeric quality for sorting and have to sort over multiple dimensions. Again with cards, you can do two passes. One with buckets by value, and one with buckets by suit. After the second, you collect each of the 4 stacks and the deck is sorted.

Cards, phone books, recipes, these are things that most people encounter (ok, maybe not phone books anymore), in their lives. They offer great aids to demonstrating CS concepts to either new students or people who have only a passing curiosity (or none but they shouldn't have asked :P).


I'm not sure how drawing that distinction helps a layman.


Clarifying something as an example of a principle instead of the principle itself seems pretty important, regardless of lay status.


Ah, when you phrase it that way I see what you mean, I agree.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: