0

I understood the process to shorten the URL with base 62 at How do I create a URL shortener?.

Steps given are

  1. Think of an alphabet we want to use. In your case, that's [a-zA-Z0-9]. It contains 62 letters.
  2. Take an auto-generated, unique numerical key (the auto-incremented id of a MySQL table for example).
  3. For this example, I will use 12510 (125 with a base of 10).
  4. Now you have to convert 12510 to X62 (base 62)

My question is why not just create unique numerical key and return it ? What is the advantage of concerting numerical key > Base 62 > then Finally some alphanumeric number ? Is it because final alphanumeric number will be much smaller than unique numerical key ?

emilly
  • 9,488
  • 28
  • 87
  • 161

1 Answers1

1

Yes. The idea is to make it short and usable in a URL. A number in base 62 will use fewer characters than the same number in base 10. Notice also that URL shorteners use short hosts, such as g.co.

Andrew Morton
  • 22,953
  • 9
  • 55
  • 76
  • Yeah you are right that `base 62 will use fewer characters than the same number in base 10` But my question is why not just return the shortened URL with digits instead of characters i.e. after step 2 in my question ? For example : Input Url is `https://en.wikipedia.org/wiki/Computer_architecture` just return `https://tinyurl/4321` where `4321` uniquely identifies the input URL . Why we need to further encode `4321` to some characters ? – emilly May 10 '21 at 04:30
  • @emilly To make it even shorter. – Andrew Morton May 10 '21 at 08:06
  • Looks like your last comment is incomplete ? – emilly May 10 '21 at 12:18
  • @emilly I was replying to "Why we need to further encode 4321 to some characters ?" – Andrew Morton May 10 '21 at 12:23