Questions / réponses

Paramètres importants des arbres binaires

Paramètres importants des arbres binaires

par Anna Ornatskaia,
Nombre de réponses : 4

It seems that I misunderstand some part of the task because errors are given on trees that show the correct values in my opinion. For example, for a tree Bin (128, Bin (0, Empty, Empty), Bin (4, Empty, Empty)) i think that the answers are (3,2,0,1,1,1) when p x = x >-1; (2,1,0,1,1,1) when p x = x > 0; (1,0,0,1,-1,1) when p x = x >4 and (0,0,0,0,-1,-1) when  p x = x > 128. 

However, the tree displays an error. Unfortunately, the correct answer is not given to understand in which of the parameters an error is made, and no examples are given in the text of the task to understand the correctness of its understanding.

Could you help me understand which parameter is wrong?

Thank you in advance.

En réponse à Anna Ornatskaia

Re: Paramètres importants des arbres binaires

par Philippe Duchon,

The values you give are correct, except the first (you use the same predicate twice: fun x -> x>0; perhaps you meant fun x -> x>=0 for the first example?)

En réponse à Philippe Duchon

Re: Paramètres importants des arbres binaires

par Anna Ornatskaia,

Yeah, you're right, I made a typo. I corrected the condition in the question text.

But these values ​​are incorrect because I get an error.


En réponse à Anna Ornatskaia

Re: Paramètres importants des arbres binaires

par Philippe Duchon,

I looked a little at your code submission, and most of your parameter functions are incorrect.

The functions to count arity 1 and 2 nodes are incorrect (try to find why).

Your function for the longest branch where all nodes satisfy the predicate, tries to use a special value (-10000) to avoid difficulties with really counting the longest branch satisfying the condition (what if trees have a very high height?)

The last parameter is also incorrect; if the root node does not satisfy the predicate, why should the parameter be 0? You are looking for the (length of) the longest branch containing at least one node satisfying p; just because the root node does not satisfy p, does not mean there cannot be long branches containing "good" nodes.

En réponse à Philippe Duchon

Re: Paramètres importants des arbres binaires

par Anna Ornatskaia,

Thank you for your help, when you look at the task for a long time you do not notice the obvious things))

The only thing I do not understand why the arity functions are incorrect.