Zipf's algorithm