Click here to Skip to main content
15,892,161 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Color Ranges Pin
Malcolm Smart22-Jul-07 23:33
Malcolm Smart22-Jul-07 23:33 
GeneralRe: Color Ranges Pin
CPallini22-Jul-07 23:41
mveCPallini22-Jul-07 23:41 
Questionfinding all recurring elements in an array Pin
Rocky#17-Jul-07 6:40
Rocky#17-Jul-07 6:40 
AnswerRe: finding all recurring elements in an array Pin
El Corazon17-Jul-07 6:56
El Corazon17-Jul-07 6:56 
GeneralRe: finding all recurring elements in an array Pin
Dan Neely17-Jul-07 7:08
Dan Neely17-Jul-07 7:08 
GeneralRe: finding all recurring elements in an array Pin
El Corazon17-Jul-07 7:11
El Corazon17-Jul-07 7:11 
GeneralRe: finding all recurring elements in an array Pin
Rocky#17-Jul-07 7:13
Rocky#17-Jul-07 7:13 
AnswerRe: finding all recurring elements in an array Pin
Luc Pattyn17-Jul-07 7:28
sitebuilderLuc Pattyn17-Jul-07 7:28 
well, what did you expect ?

Here are two approaches without any visible sorting:

1.
just enter the numbers one by one in a hashtable; use the numbers as the key,
and their multiplicity as the value.
So to add a[i], check for presence of key a[i]; if not, add the pair (a[i], 1),
else replace (a[i], value) by (a[i], value+1).
When done, enumerate the keys with value>=2

2.
Since you are not interested in actual multiplicity values, you could try
two simple lists: one for "seen just once", the other for "seen more than once".
Now for each a[i] first test the "more than once", if not present, the "just once",
and move/add the item appropriately.
Dont be surprised if this takes longer, for new numbers you are searching two lists
(albeit they both are smaller).


For both of the above methods, here is a big optimization:
just do it for all numbers but the last one.
If these all appear more than once, there is no need to read the last number at all.

Smile | :)




AnswerRe: finding all recurring elements in an array Pin
PICguy22-Jul-07 12:10
PICguy22-Jul-07 12:10 
QuestionInteresting math magic? Pin
Paul Conrad15-Jul-07 12:35
professionalPaul Conrad15-Jul-07 12:35 
AnswerRe: Interesting math magic? Pin
cp987616-Jul-07 12:49
cp987616-Jul-07 12:49 
AnswerRe: Interesting math magic? Pin
MarkB77716-Jul-07 23:14
MarkB77716-Jul-07 23:14 
JokeRe: Interesting math magic? Pin
Luc Pattyn16-Jul-07 23:25
sitebuilderLuc Pattyn16-Jul-07 23:25 
GeneralRe: Interesting math magic? Pin
MarkB77716-Jul-07 23:33
MarkB77716-Jul-07 23:33 
GeneralRe: Interesting math magic? Pin
Paul Conrad17-Jul-07 7:33
professionalPaul Conrad17-Jul-07 7:33 
GeneralRe: Interesting math magic? Pin
PIEBALDconsult17-Jul-07 7:37
mvePIEBALDconsult17-Jul-07 7:37 
GeneralRe: Interesting math magic? Pin
stevepqr7-Aug-07 6:07
stevepqr7-Aug-07 6:07 
AnswerRe: Interesting math magic? Pin
PIEBALDconsult17-Jul-07 7:36
mvePIEBALDconsult17-Jul-07 7:36 
GeneralRe: Interesting math magic? Pin
Paul Conrad17-Jul-07 7:42
professionalPaul Conrad17-Jul-07 7:42 
GeneralRe: Interesting math magic? Pin
Bassam Abdul-Baki19-Jul-07 5:10
professionalBassam Abdul-Baki19-Jul-07 5:10 
AnswerRe: Interesting math magic? Pin
_Damian S_17-Jul-07 16:56
professional_Damian S_17-Jul-07 16:56 
QuestionEncoding vs Encrypting Pin
HakunaMatada13-Jul-07 0:22
HakunaMatada13-Jul-07 0:22 
AnswerRe: Encoding vs Encrypting Pin
SHatchard13-Jul-07 0:59
SHatchard13-Jul-07 0:59 
GeneralRe: Encoding vs Encrypting Pin
Paul Conrad13-Jul-07 10:32
professionalPaul Conrad13-Jul-07 10:32 
AnswerRe: Encoding vs Encrypting Pin
CPallini13-Jul-07 2:57
mveCPallini13-Jul-07 2:57 

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.