Question: ==== Relationship(vw): returns the precise relationship between v and w. Answers can be of the form v is the grandfather of w or v and
====


Relationship(vw): returns the precise relationship between v and w. Answers can be of the form "v is the grandfather of w" or "v and w are second cousins twice removed". If u and w belong to different generations, v should be part of the earlier generation and w of the older generation. (If these terms have always confused you, you're not alone! See details below.) RelatedTo(v,i,j): returns a list that contains all individuals who call u their ith cousin jth removed. There's a lot of information online about "degree of cousins but it's always helpful to de- scribe it in Computer Science terms. First, the notion of least common ancestor (LCA) is important. Given two nodes v and w in T, the LCA of v and w is a node z such that z is an ancestor of both v and w and has the greatest depth among all such ancestors. We shall say z = LCA(,w). Let T, denote the subtree rooted at z. Clearly, v and w are in this subtree. The next impor- tant information is the depth of u and w in Tg. Let us denote them as dy and du respectively. Assume v #w. Case 1: dy = dw (i.e., v and w are part of the same generation in T). Then we say that v and w are (du 1)-degree cousins, where 0-degree cousins are just siblings. For example, 2 my cousin Stephanie and I have our grandparents as our LCA. Both of us have depth 2 from our LCA. This is why we're called first-degree cousins. Case 2: dy # dw. WLOG, assume dy
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
