1
$\begingroup$

I am new to this Community. Actually I am myself a Software Engineer and our company has stuck to a problem and has not come up with a solution for many days. So, I just remembered an old school Math Chapter of Probability and a King to pass 8 doors etc. I thought Mathematicians can solve this problem.

So, here is the problem, we have an increasing numbers of Email Addresses and Buckets. And each Bucket can hold 1000 Emails

enter image description here

Just for a side note, if it is hard to work on alphabats, we can convert each email to numbers first like a=1, b=2, c=3 ... z=26 with 0 (Zero) appended for making it unique and +s for @ and . characters. For Example

 [email protected]  ->  10203040+901301090+3015013

So, now we have numbers which make it easier to apply any calculations. Once we get the solution, we will make a Hashing Library to solve problems in Software Industry

$\endgroup$
1
  • $\begingroup$ You can use some sort of hashing function, keeping in mind that we can't really enforce the upper limit on the buckets, only make some probabilistic argument about why we probably wont exceed the upper limits. A trivial example of such a hashing function might be to convert the email to hex, add the digits, then mod by some value. To avoid bias towards certain results (e.g. if just modding the email converted to hex without further digit manipulation, that might just have everything @gmail.com go to same bucket) more complicated hashing functions can be used. $\endgroup$
    – JMoravitz
    Commented Apr 23, 2020 at 12:02

1 Answer 1

-1
$\begingroup$

Each email can be given a unique primary key. This can be given relative to their positions when you sort them alphabetically, or convert strings to numbers or whatever way.

Now we essentially need to find which bucket holds that key.

If each bucket can hold $1000$ keys, then key $1-1000$ are in first bucket, keys $1001-2000$ are in second bucket and so on.

Then given a key $K$ it lies in the $\lceil \frac{K}{1000}\rceil$ bucket.

Similarly if each bucket can hold $n$ emails, then you can replace $1000$ with $n$.

$\endgroup$
2
  • $\begingroup$ relative to their positions with sorting is a problem because Email addresses are not fixed and increasing. So, We give any Email address a unique key according to it sorting then It will have different Key when new Emails are added and sorted. So, we will lose the Key for this Email Address. P.S. I didn't down voted your answer. $\endgroup$ Commented Apr 23, 2020 at 12:02
  • $\begingroup$ Maybe you can try to assign keys based on when an email joins, this way newer databases will have keys that will not have conflict with the old keys $\endgroup$
    – h-squared
    Commented Apr 23, 2020 at 12:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .