An Algorithm Problem

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Aug 2008
Posts: 6
Reputation: alien2006.happy is an unknown quantity at this point 
Solved Threads: 0
alien2006.happy alien2006.happy is offline Offline
Newbie Poster

An Algorithm Problem

 
0
  #1
24 Days Ago
Let say we have N number and N is odd. Among the N numbers, two of them equal to each other except one. For example, let's say we have 7 numbers, which could be 5, 3, 4, 1, 3, 5, 1. Only 4 is distinct, other number always has anther one member equal to it. Then how can we design a algorithm to find the distinct number(among N numbers) in linear time with only one variable introduced.
Last edited by alien2006.happy; 24 Days Ago at 3:55 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #2
23 Days Ago
Let's say I have a homework question. Let's say I have no intention of actually doing it myself.

Let's say I post that question on an internet forum and see how many people will try and post the answer.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #3
23 Days Ago
Let's say I have a homework question. Let's say I have no intention of actually doing it myself.

Let's say I post that question on an internet forum and see how many people will try and post the answer.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter
 
0
  #4
22 Days Ago
Let's say I can do it with no variables.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,076
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 140
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Veteran Poster
 
0
  #5
21 Days Ago
Hint, a odd number plus a odd number equals a even number.
I give up! 
1) What word becomes shorter if you add a letter to it?
2) What does this equal :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 6
Reputation: alien2006.happy is an unknown quantity at this point 
Solved Threads: 0
alien2006.happy alien2006.happy is offline Offline
Newbie Poster
 
0
  #6
21 Days Ago
Yeah, thank you for your hint. I guess I could solve it now. Let me make it public. We could just using XOR with all this numbers, and after that, we could get the number that we want.
But just let me change that problem a little. If there are 2N+2 numbers, and only 2 numbers are distinct. Other number always has another member, which is equal to it. Then how can we solve it using the least memory and the least time now ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter
 
0
  #7
20 Days Ago
At the very minimum, if this is an array of N-bit integers, we'll need 2N bits of state, because there's no way to represent two arbitrary N-bit integers with fewer than that amount of information. So if there's a very clever solution, it'll have two accumulatory variables. Maybe there isn't -- maybe it needs something like three or four variables, because of the nature of the problem. Of course, it might need O(N) space and O(N) time if you can't do better than a hash table.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC