• Re: How to create a binary tree hierarchy given a list of elements as

    From MRAB@3:633/280.2 to All on Mon Jan 29 06:23:59 2024
    Subject: Re: How to create a binary tree hierarchy given a list of elements as
    its leaves

    On 2024-01-28 18:16, marc nicole via Python-list wrote:
    So I am trying to build a binary tree hierarchy given numerical elements serving for its leaves (last level of the tree to build). From the leaves I want to randomly create a name for the higher level of the hierarchy and assign it to the children elements. For example: if the elements inputted
    are `0,1,2,3` then I would like to create firstly 4 elements (say by random giving them a label composed of a letter and a number) then for the second level (iteration) I assign each of 0,1 to a random name label (e.g. `b1`)
    and `2,3` to another label (`b2`) then for the third level I assign a
    parent label to each of `b1` and `b2` as `c1`.

    An illustation of the example is the following tree:


    [image: tree_exp.PNG]

    This list strips images, and discussion has mostly moved to https://discuss.python.org.


    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)