我需要在Julia中实现一个深度为l = 3的树。最初,根节点具有m = 10000个随机值(k = rand(m))的向量。然后该向量被分成k = 10个分区,其中每个节点子节点具有n = 1000个值的向量。最后,叶子连接到给定的子节点。
每个分区(子节点)都有一定数量的叶子,其中每个叶子都有一个数据向量。由于每个子节点都有一个1000个值的向量。后者与其叶子共享。叶子总数为100,每个孩子的叶子数量可能因孩子而异。 所以树的结构如下:
0级根节点:10000个值的向量
1级10个子节点每个1000个值
2级100片叶子
type MyNode{T}
data::T
level::Int
child:: Vector{MyNode}
nchilds :: Int
nLeafs::Int
leafs::Vector{MyNode}
end
MyNode() = MyNode(0,0,MyNode[])
N = 10 # number of child
root = MyNode(0,N, [MyNode() for i in 1:N])
# in the first level l need to link the root to the child. the number of childs is 10
childs=MyNode(1,N, [MyNode() for i in 1:N])
for node in root.childs
# add edges between root and each child , transfer the data from root to childs
# addEdge() and TransferData() to be developed
end
k= 100 # number of leafs
leafs=Mynode(1,k,[MyNode() for i in 1:K])
# in the second level we add edge between each child and its leafs . let's set the total number of leafs is 100
for node in child.leafs
# add edges between each childs with its leafs. the number of leafs of each child may differ for instance child 1 has 5 leafs child 7 has 3 leafs and so one. We just need to have the total number of leafs equals 100.
# addEdge() and TransferData() to be developed
end
感谢您的帮助