RSS

How will you return a number which exist odd number of times from an array

Fri, Mar 5, 2010

Algorithm

Method 1) Hash Map
 
Insert the entire element
Key……………………Data
Element……………….Number Of occurrence
Once the data has been processed, the number of occurrence can be checked. If the number of occurrence is odd number then that is the required element
 
 

Method 2) Sorting with known range
 
If range is known, then counting sort can be modified. Please refer Counting Sort
 
 

Method 3) Digital Logic
 
EXOR all the element, only odd occurrence will remain. EXOR will flush all the elements that are present for even number of times.

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.