[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: How to create a binary tree hierarchy given a list of elements as its leaves
From:       MRAB via Python-list <python-list () python ! org>
Date:       2024-01-28 19:23:59
Message-ID: 99f5cf21-8f22-4900-889f-b2bbbe8356f5 () mrabarnett ! plus ! com
[Download RAW message or body]

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.

-- 
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic