Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Parallel Array Matching
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
deltatux




PostPosted: Tue Dec 02, 2008 9:50 pm   Post subject: Parallel Array Matching

Hey guys,

Recently I had my test, but this question completely stumped me. I was wondering how you guys would approach this question:

So basically I get two parallel arrays as such:

userid_t[] 1001, 1002, 1003, 1001, 1001, 1002, 1004, 1005
itemcode_t[] A , A , B , B , C , A , B , F

So basically, I have to go through the parallel arrays and see the frequency of them having two distinct users selecting the item code.

So in that question, the array:

itemcodes[] A, B, C, F <--- this part I got, just sort them and then drop in the ones that aren't duplicated.
frequency[] 2, 3, 1, 1 <--- this is the part that I'm having trouble with.

deltatux
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Dec 02, 2008 10:06 pm   Post subject: RE:Parallel Array Matching

Ugghhh.... parallel arrays is the wrong data structure. Though assuming that the fault is with the assignment on this one, lets move on.

Since we are looking for the frequency of use by distinct users, the converse is that we don't want to count duplicate user-item pairs.

See that 1001-A and another 1001-A ? Drop one of them, just as you've been dropping duplicate codes. The only difference is that you have to keep parallel arrays in sync (and that is why they are the wrong data structure choice). Now the frequency of code use is guaranteed to by made by distinct users.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
deltatux




PostPosted: Tue Dec 02, 2008 10:18 pm   Post subject: RE:Parallel Array Matching

I understand that this isn't the best way, but I was specifically told to do it with parallel arrays.

As for dropping the duplicates, how do I go about that without sorting both arrays (which will break it's parallelness)?

Thanks,
deltatux
Tony




PostPosted: Tue Dec 02, 2008 10:25 pm   Post subject: RE:Parallel Array Matching

You could sort both arrays and keep them in sync, as long as you do the same swap operations to both arrays.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
deltatux




PostPosted: Wed Dec 03, 2008 1:52 am   Post subject: RE:Parallel Array Matching

What do you mean by that? Any examples you can show?

Thanks,
deltatux
DemonWasp




PostPosted: Fri Dec 05, 2008 11:54 pm   Post subject: RE:Parallel Array Matching

In your sort algorithm, when you would normally do

code:

temp = array1 ( i )
array1 ( i ) = array1 ( j )
array ( j ) = temp


that is, any time you would swap two values, do the following instead:

code:

// Swap in array1
temp = array1 ( i )
array1 ( i ) = array1 ( j )
array1 ( j ) = temp

// Swap in array 2
temp = array2 ( i )
array2 ( i ) = array1 ( j )
array2 ( j ) = temp
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: