Click here to Skip to main content
15,915,019 members
Home / Discussions / Algorithms
   

Algorithms

 
Questiondepth first search help.. Pin
neha_rai25-Jul-09 8:00
neha_rai25-Jul-09 8:00 
AnswerRe: depth first search help.. Pin
Abhijit Jana25-Jul-09 10:49
professionalAbhijit Jana25-Jul-09 10:49 
GeneralRe: depth first search help.. Pin
that_dude_tj26-Jul-09 23:22
that_dude_tj26-Jul-09 23:22 
NewsRe: depth first search help.. Pin
Abhijit Jana27-Jul-09 0:56
professionalAbhijit Jana27-Jul-09 0:56 
QuestionMerging Inputs and producting ID number [modified] Pin
ZeroPun24-Jul-09 12:35
ZeroPun24-Jul-09 12:35 
AnswerRe: Merging Inputs and producting ID number Pin
Moreno Airoldi28-Jul-09 23:31
Moreno Airoldi28-Jul-09 23:31 
GeneralRe: Merging Inputs and producting ID number Pin
Leonardo Muzzi7-Aug-09 4:00
Leonardo Muzzi7-Aug-09 4:00 
GeneralRe: Merging Inputs and producting ID number [modified] Pin
Moreno Airoldi7-Aug-09 21:57
Moreno Airoldi7-Aug-09 21:57 
I particularly like the vector modulus idea, very elegant. Thumbs Up | :thumbsup:

But I see a problem with the two approaches you suggested: you should use dynamic weights to take into account for the difference in magnitude between the various inputs. If, for example, we have:

W1=3 ; W2=2 ; W3=1

X1=100 ; X2=300 ; X3=10


it's clear that we should increase the value of W1 in order to restrain X2 from weighing more than X1, even if its weight W2 is already less than W1. With different input sets, weights may have to be re-adjusted again. This means you would have to go through all the input sets in order to come up with proper weights before you start applying them. Even when possible, this would not be optimal.

I suggested factors of 10 because in most real world applications it's natural to have inputs whose range is in boundaries defined by factors of 10 (for example 0 to 999 etc.). Using factors of 10 will retain all of the digits for each input.

If we want to save memory (bits), I think we should switch to factors of 2 and lose the least significant bits. Switching to factors of 2 is trivial: we just left-shift the values with higher weights, while values with lower weights will drop to the right (least significant bits), and we preserve the logic I suggested with factors of 10 in terms of comparisons with thresholds.

For example, let's say that our inputs will be in the range from 0 to 999. We need 10 bits to hold that range of values, hence if we want to combine four inputs X1...X4 we need 40 bits. Now, it would sure be good to make that 32 bits, so that we can optimize memory usage and processing time, going for a nice standard 32-bit int. To do that, we just drop the two least significant bits for each input:

int ID = ((X1 >> 2) << 24) & ((X2 >> 2) << 16) & ((X3 >> 2) << 8) && (X4 >> 2);


EDIT: of course the same can be done with factors of 10, by dividing the inputs by 10, 100, etc. in order to use up less digits.

Looking forward to hear your thoughts about this. Smile | :)

2+2=5 for very large amounts of 2
(always loved that one hehe!)

modified on Saturday, August 8, 2009 4:12 AM

GeneralRe: Merging Inputs and producting ID number Pin
Leonardo Muzzi9-Aug-09 17:33
Leonardo Muzzi9-Aug-09 17:33 
GeneralRe: Merging Inputs and producting ID number Pin
Moreno Airoldi9-Aug-09 22:43
Moreno Airoldi9-Aug-09 22:43 
GeneralRe: Merging Inputs and producting ID number Pin
Moreno Airoldi12-Aug-09 1:36
Moreno Airoldi12-Aug-09 1:36 
QuestionHelp! I need a book that describes hash in details. Pin
jibeex22-Jul-09 15:00
jibeex22-Jul-09 15:00 
AnswerRe: Help! I need a book that describes hash in details. Pin
Luc Pattyn22-Jul-09 15:43
sitebuilderLuc Pattyn22-Jul-09 15:43 
QuestionRe: Help! I need a book that describes hash in details. Pin
harold aptroot22-Jul-09 18:23
harold aptroot22-Jul-09 18:23 
AnswerRe: Help! I need a book that describes hash in details. Pin
riced23-Jul-09 5:59
riced23-Jul-09 5:59 
AnswerRe: Help! I need a book that describes hash in details. Pin
jibeex23-Jul-09 23:42
jibeex23-Jul-09 23:42 
GeneralRe: Help! I need a book that describes hash in details. Pin
harold aptroot25-Jul-09 13:39
harold aptroot25-Jul-09 13:39 
QuestionAbout showing the picture in Matlab Pin
Dhyanga18-Jul-09 2:01
Dhyanga18-Jul-09 2:01 
QuestionAbout Masking function in Matlab Pin
Dhyanga18-Jul-09 1:57
Dhyanga18-Jul-09 1:57 
Question[Message Deleted] Pin
deepthi0916-Jul-09 9:44
deepthi0916-Jul-09 9:44 
AnswerRe: urgent help Pin
Luc Pattyn16-Jul-09 10:04
sitebuilderLuc Pattyn16-Jul-09 10:04 
GeneralRe: urgent help Pin
Tim Craig16-Jul-09 18:18
Tim Craig16-Jul-09 18:18 
QuestionOverlapping dates Algorithem Pin
kKamel9-Jul-09 13:37
kKamel9-Jul-09 13:37 
AnswerRe: Overlapping dates Algorithem Pin
Eslam Afifi9-Jul-09 13:58
Eslam Afifi9-Jul-09 13:58 
GeneralRe: Overlapping dates Algorithem Pin
kKamel9-Jul-09 14:07
kKamel9-Jul-09 14:07 

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.