K
K
Kiri Kurayami2015-05-22 17:32:23
C++ / C#
Kiri Kurayami, 2015-05-22 17:32:23

How to build an N-tree and find the longest branch without branches?

Good day.
According to the basics of programming, they set a task, the solution of which I can’t think of in any way, maybe someone can tell you how to do it or at least in which direction to drip / look for documentation: you need to build an N-tree and find the longest branch without branches.
This problem needs to be solved using c/c++.
Thanks in advance for the replies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2015-05-22
@Mercury13

Something like

максРазмер : целое
началоМаксВетви: узел

проц максВетвь(узел : Узел, началоВетви: Узел, текРазмер: целое)
  в зависимости от степени узла «узел»
    если 0:
      если текРазмер > максРазмер
        максРазмер = текРазмер
        началоМаксВетви = началоВетви
    если 1: максВетвь(единственныйCын, началоВетви, текРазмер + 1)
    если 2+:
      для всех сыновей
        максВетвь(сын, сын, 1)

максВетвь(корень, корень, 1)

Counts max. a branch ending in a leaf; if it can end with a fork, I leave it as homework.

J
jcmvbkbc, 2015-05-22
@jcmvbkbc

Build a tree, go through all the leaves, from each leaf go to the root, to the first node with several children encountered, remembering the longest such branch found.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question