Implement Reverse DNS Look Up Cache - Coddicted

Implement Reverse DNS Look Up Cache

Title: How to Implement Reverse DNS Look Up Cache? Source:

Reverse DNS look up is using an internet IP address to find a domain name. For example, if you type in browser, it automatically redirects to

How to implement Reverse DNS Look Up cache? Following are the operations needed from cache.
1) Add a IP address to URL Mapping in cache.
2) Find URL for a given IP address.

One solution is to use Hashing.

In this post, a Trie based solution is discussed. One advantage of Trie based solutions is, worst case upper bound is O(1) for Trie, for hashing, the best possible average case time complexity is O(1). Also, with Trie we can implement prefix search (finding all urls for a common prefix of IP addresses).
The general disadvantage of Trie is large amount of memory requirement, this is not a major problem here as the alphabet size is only 11 here. Ten characters are needed for digits from ‘0’ to ‘9’ and one for dot (‘.’).
The idea is to store IP addresses in Trie nodes and in the last node we store the corresponding domain name.

Java solution

Back To Top
Rate this post

Leave a Reply