We have already seen how lists expand our possibilities, but for creating truly complex projects, this will often be insufficient.
Let's look at an example. Imagine you are in a square with a crowd of people, and you need to find Andriy (you don't know what he looks like—only his name). You can approach people and ask for their name, and after a certain number of steps, you will find him. But there are 3 nuances:
<aside> ⚠️ Nuances...—these are just a small part of the use case for trees.
</aside>
All this leads us to the idea that perhaps simple data lists are not enough; we need something more complex and convenient.
Continuing our comparison with people—imagine that these people live in one building, and in the real world, buildings have numbers, floors, apartment numbers, and finally—the names of the residents of each apartment. This kind of structure can be called a data tree, let's take a look at it:
Of course, this diagram is conditional, and it is possible to use some names for each level, but in GH, it is implemented slightly differently:
Instead, trees in GH are implemented as a set of lists with names that explain where this list is located in the tree. Since we have only one street for the entire tree, we have 0 in all list names. Next, we have buildings, so we have 0 and 1 (⚠️ I remind you that in programming, the first element is 0), then apartments 0, 1, 2, 3... and this way we can access a certain branch of the tree: { 0; 1; 2 }
In fact, when working in GH, it creates the tree structure itself, and we usually just need to observe and occasionally make adjustments. Let's create an algorithm that will have a similar structure to our example, but for a start, let's have the same number of people in each apartment, so the number of people is zero, and instead of people, there will be points😉
Circle
with a radius of 100.Divide Curve
node to create points on the circle, and in "N", set it to 2 for the number of points.