How Does tinyurl Work?

The service tinyurl accepts a long URL string (presumably the location of a web document or something else such) and creates a permanent shortcut for it. Here are some examples of such shortcuts:

The question is, how does the service create such a small shortcut for any of the virtually thousands of web URLs out there? Does it compress the URL? Does it store it somewhere?

A little judicious observation can reveal some of the little secrets behind this service. The first fairly obvious factoid is that the shortcut has always a fixed length. In fact, the effective length looks as if it is exactly six (last 6 characters). The second fairly obvious factoid is that the shortcut consists of only small-caps letters and the digits 0-9.

The above observations quickly lead to the conclusion that the number of all possible configurations of the second part of the shortcut string is bounded above by 366 = (26 letters + 10 digits)6. This number equals 2176782336 and is close to maxlongint (or max int in Java).

Therefore, all one has to do to create such a service is have a Java program with the following (pseudo) declaration:

T=array[] of string;

Considering the maximum length of any string allocated to be 255, an upper bound for the memory of this table will then be 2147483647 * 255 = 547608329985 bytes. That's roughly 510 Gigabytes of storage space and is doable with large capacity drives.

Note that the Java string type is immutable, which further serves the service's purpose on never changing the original string.

Easy money, people! Go for it!