It's UWAweek 47

help2200

This forum is provided to promote discussion amongst students enrolled in CITS2200 Data Structures and Algorithms.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 4 articles in this topic
Showing 4 of 176 articles.
Currently 9 other people reading this forum.


 UWA week 18 (1st semester, week 9) ↓
SVG not supported

Login to reply

👍x1
helpful
8:43pm Thu 2nd May, ANONYMOUS

Hi, my code kept failing the get_cousin_dist() part. it is passing the tests until (B, D).

From what i understood, to find the degree value of 2 individuals, I have to find the generation distance between their common ancestor and the originator. For example: the pair D and E they have the common ancestor B, and the generation distance between B and Originator A is 0. So the degree value is 0.

And if their common ancestor is the Originator itself, then take the larger distance as the degree. For example: the pair B and F the generation distance from B to A is 0, and the distance from F to A is 1, so the degree value is 1.

But for the pair B and D, B itself is the ancestor of D, the pair's expected degree value is 0. Clearly the "B to A is 0, D to A is 1, so take 1" method isn't working here. So I thought, then B itself would be their common ancestor? B to A is 0, and the expected value is 0, it seems to be working.

But then there's the pair B and J, their expected degree value is 1. B is also the ancestor of J. B to A is 0, J to A is 2, but the expected value isn't 2. And going with b is the common ancestor, the expected value isn't 0 either.

So I am genuinely confused on why the expected degree value of (B, D) is 0, and for (B, J) is 1.


SVG not supported

Login to reply

👍x1
helpful
12:38am Fri 3rd May, Diarmuid OC.

Hi, not a facilitator, but I think I can help.

You seem quite close with what you've got, but I think the problem is that you don't need to consider the Originator as something separate, the same constant rules will always apply.

As we know, the generation distance (or order) of two individuals is the number or generations that separate them, which you seem to be doing right.

To calculate the degree between two individuals, we need to consider the order of both individuals against their closest shared ancestor. So taking the example of the pair B and D, which is expected to return a degree of 0, we start by finding their closest ancestor, which is B. Then we calculate the order of each of the individuals in the pair compared to the single shared ancestor.

So starting with D (because it's simpler), we compare it against the shared ancestor B, and we get an order of 0. Then we do the same thing with the second individual in the pair, B, comparing it against the shared ancestor B, which gives us a weird order value of -1 because it's the same individual.

The degree is the bigger one of these two orders, 0 and -1. 0 > -1, so the degree is 0.

We can do the same process for B and J. Their closest shared ancestor is (again) B. So starting with B this time: B to the shared ancestor of B gives us an order of -1. And for J: J to the shared ancestor of B gives us an order of 1.

Comparing these orders: 1 > -1, therefore the degree for the pair B and J is 1.

I'm pretty sure this is the right way to approach it, I hope this helps to explain it a bit better!


SVG not supported

Login to reply

👍x1
helpful
9:31am Fri 3rd May, ANONYMOUS

Ohhh, I think I get it. Yeah! Thank you so much!


SVG not supported

Login to reply

👍?
helpful
9:39pm Fri 3rd May, Diarmuid OC.

No problem :) Glad I could help!

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy