Click here to Skip to main content
15,902,635 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerFinding an extra/missing number Pin
supercat918-Dec-08 9:56
supercat918-Dec-08 9:56 
GeneralRe: Question from my Phone Interview Pin
Luc Pattyn18-Dec-08 13:15
sitebuilderLuc Pattyn18-Dec-08 13:15 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 1:28
sitebuilderLuc Pattyn19-Dec-08 1:28 
GeneralRe: Finding several extra/missing numbers Pin
supercat919-Dec-08 7:00
supercat919-Dec-08 7:00 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 7:25
sitebuilderLuc Pattyn19-Dec-08 7:25 
GeneralRe: Finding several extra/missing numbers Pin
supercat919-Dec-08 8:56
supercat919-Dec-08 8:56 
GeneralRe: Finding several extra/missing numbers Pin
Luc Pattyn19-Dec-08 9:36
sitebuilderLuc Pattyn19-Dec-08 9:36 
GeneralRe: Finding several extra/missing numbers Pin
supercat921-Dec-08 12:28
supercat921-Dec-08 12:28 
For the n=2 case, if there were 16 xors produced (xor of all numbers with bit 0 set, with bit 1 set, etc.) then if the missing numbers were 2 and 5, then xor[0] and xor[2] would both be 5, while xor[1] would be 2. Easy.

If the numbers shared a bit but each had at least one bit the other lacked (e.g. the values were 3 and 5) then the xor's would have three non-zero values: xor[0] would be 6 (3 xor 5), xor[1] would be 3, and xor[2] would be 5. Simplest thing to do in that scenario is to ignore the non-zero xor value which does not have the 'indicated' bit set (i.e. xor[0] in this case, since the value 6 has bit 0 clear). The other two non-zero xor values are the missing numbers.

If one number is a subset of the other (e.g. 2 and 3), then one of the non-zero xors will have its corresponding bit clear (e.g. xor[1] will equal 1, which has bit 1 clear) and the other will have it set. The one that has the bit set is one of the missing numbers; xor that with the other one to get the other missing number.

For n=3, one will have a count of bit values, mod 4. Bits that are missing from none of the numbers or from all three will be trivial to place accurately. Bits that are missing from exactly one of the numbers will be easy to place; if any such bits exist, the problem will then decompose to n=2. The only hard case is where three different bits are each used by exactly two of the missing numbers (e.g. if the missing numbers are 3, 5, and 6, then tally[0][2..0] = (1,1,2); tally[1][2..0] = (1,2,1); tally[2][2..0] = (2,1,1). The tally values make it possible to determine which bits are isomorphic; that in turn will make it possible to determine which numbers are missing.
GeneralRe: Finding an extra/missing number Pin
cp987619-Dec-08 11:46
cp987619-Dec-08 11:46 
GeneralRe: Finding an extra/missing number Pin
Luc Pattyn19-Dec-08 12:48
sitebuilderLuc Pattyn19-Dec-08 12:48 
GeneralRe: Finding an extra/missing number Pin
supercat920-Dec-08 15:57
supercat920-Dec-08 15:57 
GeneralRe: Finding an extra/missing number [modified] Pin
cp987621-Dec-08 13:58
cp987621-Dec-08 13:58 
GeneralRe: Finding an extra/missing number Pin
supercat922-Dec-08 9:58
supercat922-Dec-08 9:58 
GeneralRe: Finding an extra/missing number Pin
Mark Churchill22-Dec-08 18:55
Mark Churchill22-Dec-08 18:55 
GeneralRe: Finding an extra/missing number Pin
supercat923-Dec-08 6:55
supercat923-Dec-08 6:55 
GeneralRe: Finding an extra/missing number Pin
stevepqr8-Jan-09 5:59
stevepqr8-Jan-09 5:59 
AnswerRe: Question from my Phone Interview Pin
C Change25-Jan-09 0:55
C Change25-Jan-09 0:55 
QuestionWhat is Combinatorial Optimization? Pin
alexdow13-Dec-08 9:39
alexdow13-Dec-08 9:39 
AnswerRe: What is Combinatorial Optimization? Pin
Alan Balkany15-Dec-08 3:57
Alan Balkany15-Dec-08 3:57 
QuestionSome kind of LCS Pin
aggressorus9-Dec-08 7:22
aggressorus9-Dec-08 7:22 
Questionhelp me About Big O Pin
bosszy7-Dec-08 2:00
bosszy7-Dec-08 2:00 
GeneralRe: help me About Big O Pin
Luc Pattyn7-Dec-08 6:32
sitebuilderLuc Pattyn7-Dec-08 6:32 
AnswerRe: help me About Big O Pin
Paul Conrad9-Dec-08 11:37
professionalPaul Conrad9-Dec-08 11:37 
GeneralRe: help me About Big O Pin
Luc Pattyn9-Dec-08 13:13
sitebuilderLuc Pattyn9-Dec-08 13:13 
GeneralRe: help me About Big O Pin
Paul Conrad9-Dec-08 13:15
professionalPaul Conrad9-Dec-08 13:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.