Odev 3
Odev 3
HW - 2
Assigned: 08.11.2020
Due: 18.11.2020
Submission: Will be announced on piazza.
Regulations: Late submissions are not allowed. Plagiarism is strictly forbidden, all that take part will be punished
according to the regulations of the university.
P (T ) = v if n = 1
∀k ∈ children(v)P (T ) = v + ”(” + P (T1 ) + P (T2 ) + ... + P (Tk ) + ”)”
In this case, P e (T ), string representation for the edge-labeled trees can be defined as follows:
P e (T ) = v if n = 1
∀k ∈ children(v)P e (T ) = v + ”(” + e1 P e (T1 ) + e2 P e (T2 ) + ... + ek P e (Tk ) + ”)”
where ei is the label of the edge connecting v and the root node of tree Ti . For the edge-labeled tree above, P e (T ) =
A(oB(yD)zC(xEkF mG)).
Finally consider that we assign a number n, (0 ≤ n ≤ 9) to each of the external nodes in the tree by converting labels to
numbers:
And, for the edge labeled tree with numbers on external (leaf) nodes above, P e (T ) = A(oB(y5)zC(x4k9m4)).
1
Note the following rules on labeling:
We will define a path on such a tree by a sequence of node and edge labels. For example AoBy corresponds to the colored
path in the following tree:
A path can end in an external node or an internal node. The above colored path ends in an external node. If a path
ends in an external node v, we will say that the path has a value, which is the label of v. Also a given path may not even
exist on a tree, for example, there is no path on the above tree that does not start with A as A is the label of the root
node. And for instance, AzCn or AzCkDl or AoBm do not exist in the above tree, and therefore do not have any value.
In this assignment you will be given a file of trees represented by P e (T ) function. The file can include any number of
lines where each line corresponds to a tree. A second file will include paths separated by a newline character.
Finally, if we exclude the external nodes of the original tree, the remaining tree can also constitute a heap. In that case,
you have to multiply the value found for the paths by 2, those paths in heaps are more valuable.
From these two files what we expect from you is to output the mean values for each path. Therefore you will execute the
following:
Your code should be executed by taking the filenames as command line arguments:
and should write the values on standard output, each on a separate line.
Follow piazza for questions, comments and updates. But please think twice before posting a question on piazza, as the
explanation may exist in the assignment text. Note that such questions may not get an answer.