Hewlett Packard Interview Question
Software Engineer / DevelopersWe could do with a bucket sort. We use a vector of 255 elements , where every element is a list.Now, we put every IP address is this list after it's last 8 bits.Now we have the array sorted after the last 8 bits. We repeat the step with the next 8 bits from the back, applying the sorting now for the new array(sorted after the la 8 bits). We do like this 4 times(for every group of 8 bits). The sorting will take O(N) time.
Radix Sort
- manju February 04, 2011