Programming logic to set up Trinitarian network

0

I can not mount the trinational network below:

The logic is as follows:

  • I register on the system and a link to the indication is generated;
  • The 1st, 2nd and 3rd position is occupied (it can be registered through my link indication or spill, that is, another link);
  • 4th register goes to the first available position of your 1st position already occupied in 1st class;
  • register goes to the first available position of your 2nd position already occupied in 1st class;
  • 6th register goes to the first position available from your 3rd position already occupied in 1st class;
  • This is the case for all classes , always distributing the e-mail on a network;

The problem

According to the image, when the 8th register is performed, it can not occupy the 7th position of the 2nd class. This position has already been filled by a direct register.

At this point, the system should look for the next available position in the 2nd class.

You will always have to fill in the class / line to start another class.

I do not want the programming, I want the logic to mount this network.

    
asked by anonymous 29.01.2014 / 22:27

1 answer

1

I think the algorithm would look something like this:

1. Se o último nível da árvore estiver cheio então:
2.     Pendure o novo nó abaixo do primeiro item do último nível, criando um novo nível.
3. Senão:
4.     Escolha um grupo X no último nível que tenha o menor número de nós dentre os grupos no mesmo nível. Em caso de empate, pegue o grupo mais a direita destes.
5.     Pendure o novo item no final grupo X.
6. Fim se
    
29.01.2014 / 22:46