Hi MD, In your last approach, watch out for arbitrarily large values. What would 'N' be? By the way, 'for' loop there should be for 'n', which is the size of array 'a'. A simple array like {20, 5, 123456789} would kill your memory. Hashing approach would be great if we've some idea on nature of the array contents. Here's a method of O(n logn) again. Parse through each entry in the array and insert into a BST (Binary Search Tree). Ignore duplicate entries and hence gives unique elements when done in-traversal later. However, worst-case shoots to O(n^2) if the distribution is skewed.
Regards, Channa On Oct 30, 2007 5:01 AM, MD <[EMAIL PROTECTED]> wrote: > > There can be multiple ways to do this.. obviously sorting gives you > o(nlogn). > another approach of hashtable gives o(n) > and here is another approach: > 1. maintaining array of size N, initialized to 0. Say B > 2. for(i=0;i<N;i++) { B[a[i]]++;} > 3. Output all values with B[i] >= 1 , which gives unique elements > only. > > Only restriction is the memory. > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---