RSS

How will you remove duplicate from an unsorted array

Fri, Mar 5, 2010

Algorithm

Method 1) Using extra space
 
Bucket sort if range is known
Declare an array of known range and initialize the value of each element as zero
On visiting each input number increment the corresponding array by 1(e.g. if 2 is found then make a[2]+=1)
At the last visit all the elements in the array and display the element if the array value is non-zero. This way the repeated number will be removed
 
 

Method 2) without extra space
 
Sort the elements
Keep info about the first element that is visited and the first array that has been filled
Once the info element is not equal to next element (means non-duplicate), put that next to the array that has been filled up
the problem to find duplicate and remove duplicate character to get code/algorithm

Sharing ~ Helping Other:
  • Print
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • BlinkList
  • DZone
  • Slashdot
  • YahooMyWeb
  • StumbleUpon
  • Live
  • IndianPad
  • DotNetKicks
  • Technorati

Other Posts:

This post was written by:

eXclusiveMinds - who has written 500 posts on eXclusiveMinds.


Contact the author

Leave a Reply

You must be logged in to post a comment.