Programming logic for mounting trinary network

Asked

Viewed 405 times

0

I can’t get the trinary network down:

rede trinária

The logic is as follows:

  • I register in the system and a referral link is generated;
  • Occupies the 1st, 2nd and 3rd position (can be registered through my referral or spill link, ie another link);
  • fourth register goes to the First position available from your 1st position already busy in first class;
  • 5th register goes to the First position available from its 2nd position already busy in first class;
  • sixth register goes to the First available position of your 3rd position already busy in first class;
  • It follows thus in all classes, always distributing the register in an equal way in a network;

The problem

According to the image, when the 8º register is accomplished, it will not be able occupy the 7th position 2nd class. This position has already been occupied 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 the class/line to start another class.

I don’t want the programming, I want the logic to build that network.

  • 2

    By "logic", I understand you mean "algorithm"? That’s it?

  • Yeah, the algorithm I can’t quite put together.

1 answer

1

I think the algorithm would be 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.