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:

  1. Is this the same Andriy? Maybe there are 2 or 3 of them in the square.
  2. How many people will you need to ask for their name? If there are a total of 100 people, then a maximum of 100 times. But what if there are 1000 or 1,000,000,000?
  3. Finally, if we imagine that Andriy is just a point, is it possible that we will need to find certain groups of people—like groups of friends—and perform certain operations with these groups?

<aside> ⚠️ Nuances...—these are just a small part of the use case for trees.

</aside>

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/dc2a1fca-ab90-4c49-b683-06bf2d27e161/Untitled.png

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:

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/99f9dd3c-de95-4a7c-b781-5b4db74c5d73/Untitled.png

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:

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/867a1a39-d511-4b0c-8ec8-81ef5c8e2db4/Untitled.png

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 }

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/612d37e3-6feb-462d-a495-caa43dc4cc4a/Untitled.png

Practice in Creating Trees

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😉

  1. Let's create a circle—Circle with a radius of 100.

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/88067fec-0893-4cdf-a3cf-dfa9ad13b87c/Untitled.png

  1. Add the Divide Curve node to create points on the circle, and in "N", set it to 2 for the number of points.

https://prod-files-secure.s3.us-west-2.amazonaws.com/ee848b0b-0549-4363-9009-29b090347be4/e60ee9d6-ef9a-4752-b29a-0b1aee20c2fe/Untitled.png