A tree storing multiple values ​​per node

I am trying to find a way to create a binary tree where 3 doublings are stored in each node and another tree where 6 doubles are stored in each node.

The problem I ran into is figuring out a way to implement search and insert methods (no need to delete).

Basically, my tree contains x, y, z, and when I call find, I want it to return a node that contains the x, y and z values ​​closest to the ones I'm trying to find.

How can I approach this problem and what are some ideas for solving it?

Thanks!

+4
source share
3 answers

It seems that you are looking for a kd tree data structure that also allows you to find the closest neighbor for a given element.

+4
source
public class BinaryTreeNode<T> { public T Value {get; set;} public BinaryTreeNode<T> Left {get; set;} public BinaryTreeNode<T> Right {get; set;} public BinaryTreeNode<T> Seach(T forWhat) { if(Value == forWhat) return this; BinaryTreeNode<T> leftResult = Left.Search(forWhat); if(leftResult != null) return leftResult; BinaryTreeNode<T> rightResult = Right.Search(forWhat); if(rightResult != null) return rightResult; return null; } } BinaryTreeNode<Tuple<double, double, double>> threeDoublesTree = new BinaryTreeNode<Tuple<double, double, double>>(); BinaryTreeNode<Tuple<double, double, double, double, double, double>> sixDoublesTree = new BinaryTreeNode<Tuple<double, double, double, double, double, double>>(); 
+1
source

Basically you save 1 value per node. You can consider these x, y, z values ​​as 3D points. To the left of one node you place the point closer to (0, 0, 0), and to the right you hold the others. If you have such a structure, you can search and insert data, as in a regular binary tree.

0
source

Source: https://habr.com/ru/post/1416462/


All Articles