Question: Please answer by exact blanks given for the codes. This is python 3 5. (10 points) Trees Definition. A sibling of a node in a
5. (10 points) Trees Definition. A sibling of a node in a tree is another node with the same parent (a) (4 pt) Implement siblings, which takes a Tree instance t. It returns a list of the labels of all nodes in t that have a sibling. These labels can appear in any order def siblings(t): """Return a list of the labels of all nodes that have siblings in t 10 >>>a Tree(4, Tree(5), Tree (6, Tree(7, [Tree (8)])) >siblings(Tree (1, [Tree(3, [a]) Tree(9, Tre(10)])])) 3, 9, 5, 6, 7 result for b in t.branches: return result (b) (6 pt) Implement the Sib class that inherits from Tree. In addition to label and branches, a Sib instance t has an attribute siblings that stores the number of siblings t has in Sib trees containing t as a node. Assume that the branches of a Sib instance will never be mutated or re-assigned. class Sib(Tree) "A tree that knovs hov nany siblings it has >>>a Sib(4, [Sib (5), Sib(6), Sib(7, [Sib(8)])]) >> a.label a. branches [1).1 >>>a.siblings >>> a. branches [1).siblings abel def ..init..(self, label, branches-D) self.siblings 5. (10 points) Trees Definition. A sibling of a node in a tree is another node with the same parent (a) (4 pt) Implement siblings, which takes a Tree instance t. It returns a list of the labels of all nodes in t that have a sibling. These labels can appear in any order def siblings(t): """Return a list of the labels of all nodes that have siblings in t 10 >>>a Tree(4, Tree(5), Tree (6, Tree(7, [Tree (8)])) >siblings(Tree (1, [Tree(3, [a]) Tree(9, Tre(10)])])) 3, 9, 5, 6, 7 result for b in t.branches: return result (b) (6 pt) Implement the Sib class that inherits from Tree. In addition to label and branches, a Sib instance t has an attribute siblings that stores the number of siblings t has in Sib trees containing t as a node. Assume that the branches of a Sib instance will never be mutated or re-assigned. class Sib(Tree) "A tree that knovs hov nany siblings it has >>>a Sib(4, [Sib (5), Sib(6), Sib(7, [Sib(8)])]) >> a.label a. branches [1).1 >>>a.siblings >>> a. branches [1).siblings abel def ..init..(self, label, branches-D) self.siblings
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
