rootstrap/blog

Algorithms in our daily life I

mrubi-rootstrap opened this issue · 0 comments

Using hash functions to do the laundry

Motivation:

The idea is to write a series of posts to present experiences in the daily life where we all use well known computational algorithms without noticing it. Some of these algorithms include how do banks compare passwords without storing them in plain text, how to prioritise the attention of patients of different ages in a massive vaccination event without making anyone angry (adults can afford to wait for more time than kids yet they still would like to get their number called eventually), how to efficiently order the clean laundry until each customer gets his order, the use of caches in stores to deliver products with high demand using a dedicated sales point at rush hours (like frozen cones in fast food stores) and that kind of articles.

This particular post would be an example of the use of a deadly simple hash function to optimise the delivery of completed orders in a hypothetical laundry store from O(n) to an average O(1).


📌 Notes:

The idea of this article is to present to readers the concept of computational complexity with a real example of an optimisation in a laundry store.

First I would present the original problem of searching (and waiting for) a clean laundry order in O(n), where n is the number of pending orders to be retrieved by customers. I would start with a real story in a real laundry store from many years ago.

Then I would introduce a formal definition of a hash function.

I would propose the use of a hash function to improve the efficiency of searching an order from O(n) to O(1) in the average case.
Then I would talk about hash collisions using the laundry example and how to resolve collisions in this particular case.

Finally I would write about the method :hash present in languages like Ruby and Smalltalk which use is pretty much the same as it is in the laundry example and I would mention a few details and concerns with the use of the operators :hash and :equal


🔍 Keywords:

algorithms, computation complexity, hash functions