Click here to Skip to main content
16,016,134 members
Home / Discussions / Algorithms
   

Algorithms

 
Question[Message Deleted] Pin
klck20008-Aug-06 11:22
klck20008-Aug-06 11:22 
AnswerRe: Calculate Mean,Median and Standard Deviation Pin
Paul Conrad8-Aug-06 12:30
professionalPaul Conrad8-Aug-06 12:30 
GeneralRe: Calculate Mean,Median and Standard Deviation Pin
klck20008-Aug-06 12:34
klck20008-Aug-06 12:34 
GeneralRe: Calculate Mean,Median and Standard Deviation Pin
Jeremy Falcon8-Aug-06 17:03
professionalJeremy Falcon8-Aug-06 17:03 
AnswerRe: Calculate Mean,Median and Standard Deviation Pin
OMalleyW8-Aug-06 22:55
OMalleyW8-Aug-06 22:55 
QuestionMatching two arrays Pin
Ratish Philip7-Aug-06 22:09
Ratish Philip7-Aug-06 22:09 
AnswerRe: Matching two arrays Pin
Ingo8-Aug-06 0:30
Ingo8-Aug-06 0:30 
AnswerRe: Matching two arrays Pin
Sebastian Schneider8-Aug-06 5:14
Sebastian Schneider8-Aug-06 5:14 
I'd do the following:
another array of the same size as the first two. used to store flags (say: all values initialized as 'o' and they are to be set to 'x')

if array1.size != array2.size
abort with message "not identical"
arraysize = array1.size

For i = 0 to arraysize
iterate over array1 with i
For j = 0 to arraysize
iterate over array2 with j
if array1[i] == array2[j] && array3[j] != 'x'
array3[j] = 'x'
else if j == arraysize - 1 abort with message "not identical"
else continue

message "identical"

(i wrote this down from memory. if this doesnt work, my memory failed me.)


Basically, you need to examine each element of the first array and see if there is a match in the second array. If there is a match, you need to exclude that element from further comparison (so you can have multiple identical objects in one array and you dont match one object against 2 others). The check is over once you reach the end of the second array without finding a match for an element of the first array.

Since the arrays are unsorted, you need additional space for each element of array2 to remember if it was already used for a match. Also, in the worst case, you have to make (n² + n) comparisons and n assignments to compare both arrays.

if you had 2 containers with sorted contents, you would not have to make any assignments and only n comparisons in the worst case.

Cheers,
Sebastian

--
Contra vim mortem non est medicamen in hortem.

AnswerRe: Matching two arrays Pin
El Corazon8-Aug-06 6:46
El Corazon8-Aug-06 6:46 
GeneralRe: Matching two arrays Pin
Zac Howland17-Aug-06 7:11
Zac Howland17-Aug-06 7:11 
GeneralRe: Matching two arrays Pin
El Corazon17-Aug-06 15:48
El Corazon17-Aug-06 15:48 
GeneralRe: Matching two arrays Pin
Zac Howland18-Aug-06 3:46
Zac Howland18-Aug-06 3:46 
GeneralRe: Matching two arrays Pin
El Corazon18-Aug-06 4:45
El Corazon18-Aug-06 4:45 
AnswerRe: Matching two arrays Pin
Samuel.D16-Aug-06 5:06
Samuel.D16-Aug-06 5:06 
AnswerRe: Matching two arrays Pin
Zac Howland17-Aug-06 7:25
Zac Howland17-Aug-06 7:25 
AnswerRe: Matching two arrays [modified] Pin
Ennis Ray Lynch, Jr.17-Aug-06 9:52
Ennis Ray Lynch, Jr.17-Aug-06 9:52 
Questionsnowball effect Pin
OMalleyW7-Aug-06 22:07
OMalleyW7-Aug-06 22:07 
AnswerRe: snowball effect Pin
El Corazon8-Aug-06 6:32
El Corazon8-Aug-06 6:32 
GeneralRe: snowball effect Pin
OMalleyW8-Aug-06 22:41
OMalleyW8-Aug-06 22:41 
QuestionHow much math have you retained/forgotten? Pin
Michael Dunn1-Aug-06 19:54
sitebuilderMichael Dunn1-Aug-06 19:54 
AnswerRe: How much math have you retained/forgotten? Pin
Ingo1-Aug-06 23:03
Ingo1-Aug-06 23:03 
AnswerRe: How much math have you retained/forgotten? Pin
Jeremy Falcon3-Aug-06 15:43
professionalJeremy Falcon3-Aug-06 15:43 
AnswerRe: How much math have you retained/forgotten? Pin
Andy Brummer3-Aug-06 17:13
sitebuilderAndy Brummer3-Aug-06 17:13 
GeneralRe: How much math have you retained/forgotten? Pin
Bassam Abdul-Baki3-Aug-06 18:08
professionalBassam Abdul-Baki3-Aug-06 18:08 
GeneralRe: How much math have you retained/forgotten? Pin
Andy Brummer3-Aug-06 18:34
sitebuilderAndy Brummer3-Aug-06 18:34 

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.