Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Translate BinaryTree Node Number to other BinaryTree Node Number of different tree size.

瀏覽次數:4 次
跳到第一則未讀訊息

Skybuck Flying

未讀,
2023年2月17日 下午4:31:262023/2/17
收件者:
Problem description:

Each computer has it's own binary tree. (Merkle Hash Tree).

The computers want to communicate with each other. However each BinaryTree can grow in number of nodes, size, height, etc.

Still the computers want to communicate with each other.

They want to address each other's node data, the same data basically, each node has data.

I can imagine two solutions for this problem:

1. Either a stable numbering system/scheme in which each node keeps the same number as it moves through the tree as it grows.

or

2. A translation algorithm, which translates the node number from one tree to the other tree.

It is possible to compute node numbers mathematical/virtually without memory consumption that would be ideal, for example by using formulas.

The objective is to keep communication to a minimum and to keep the ammount of memory used also to a minimum.

So it would be preferered if both trees are completely "virtual" in math basically.

Not sure if translation is possible, most likely yes, there are many ways to do it, the easiest way is to simply allocate all nodes and traverse the nodes and record it's traversal path and then send the traversal path to the other computer. Maybe this could be used, many not, maybe it's flawed.

Another way would be to do some kind of lookup table.

Or a combination of math.

Basically the information given/available for the tree would ideally be limited to the basic information about the tree, not the nodes:

structure for TBinaryTree
private
mRoot : TTreeNode;

mTotalNumberOfNodes : uint64;
end;

The height could be computed from this total number of nodes as well.

Now the final objective:

Write a routine which can convert a BinaryTreeNodeNumber to another BinaryTreeNodeNumber.

routine TranslateNodeNumber( in TBinaryTree A, in TBinaryTree B, in NodeNumberA, out NodeNumberB )

Developed an algorithm, implement it in your favorate language and post it here !

(You can also ask ChatGPT to see if it can generate it for you ! ;))

Bye for now,
Skybuck.

Skybuck Flying

未讀,
2023年2月17日 下午4:40:242023/2/17
收件者:
Alternative description, perhaps more suited for ChatGPT:

There are two binary trees of different sizes, different node counts.
Try and ask ChatGPT to write an algorithm or routine to convert a Node Number from Tree A to Tree B such that the converted node number will end up on the same node inside Tree B assuming that Tree B grew and added some nodes after Tree A, so Tree A has an older version of the same tree.
The ammount of nodes in the tree always grows from 0 to N-1, and then N+1, N+2, N+3, N+4.
So basically a growing linked list of nodes must be converted into a binary tree, the objective is to address the nodes of the tree as consistently as possible as the tree grows, or translate the node numbers from old tree to new tree as the tree grows.


Bye for now,
Skybuck.

Skybuck Flying

未讀,
2023年2月17日 下午4:51:092023/2/17
收件者:
Short question for ChatGPT:

Describe or invent a numbering scheme, system, method to number nodes in a growing binary tree such that when the tree grows the existing nodes keep their node numbers.

Bye for now,
Skybuck.
0 則新訊息