I have $200000$ users in database. I want to know the given user's position depending on his earnings, but without listing all the $200000$ users (explodes the memory of my small laptop)
So, given $200000$ users, and each users has an earning rank. My calculation so far was very simple:
Mist all $200000$ users sorted by rank and get the index of the given user. But this is not working anymore, because of RAM and obviously also not efficient way.
The most efficient strategy will probably depend on what operation you expect you perform frequently.
If your userlist is static, why not just precompute the ranks for all the users? Now, each search is constant time.
If you expect many more insertions than searches, then you might be fine with using an unsorted array. This will give constant time insertions and $O(n)$ searches.
If you expect more searches, or around the same number of insertions and searches, then some sort of self balancing tree (like B-tree, AVL etc) will be best. This will give $O(\log n)$ insertions and $O(\log n)$ searches.