Answer the question
In order to leave comments, you need to log in
How to determine the parent cell in the pyramid?
There is a pyramid of numbers, it looks like this:
Each cell has its own number and starts from 0.
Thus, it turns out that the cell coordinates are: level and number.
The question is, how can one rise to the topmost cell through the parents?
That is, for example, we determine the cell from which we will rise:
level 4 (account from 0), number 1.
You need to get the following cells:
- level 3 number 1
- level 2 number 0
- level 1 number 0
- level 0 number 0
Naturally, that the matrix can be any and the number of cells as much as you like. Can you please tell me how to calculate it?
Answer the question
In order to leave comments, you need to log in
It's very similar to a binary heap , only it's ternary in your example. In this regard, it may be convenient to store such a pyramid in a one-dimensional array, as is done for a heap. For the case with two children, the formulas for the address of the children are at the link, it is very easy to get the formulas for your case from them.
Level 4 (score from 0), number 1.
You need to get the following cells:
- Level 3 number 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question