laziness, impatience, and hubris PerlMonks

### Re: Random Trees

by dmitri (Priest)
 on Feb 11, 2003 at 20:16 UTC ( #234519=note: print w/replies, xml ) Need Help??

++. As far as your "googly" comments go, you can substitute German umlaut letters with that letter followed by 'e', so Prüfer becomes Pruefer:

Replies are listed 'Best First'.
Re(2): Random Trees
by FoxtrotUniform (Prior) on Feb 11, 2003 at 21:10 UTC

That was actually the first thing I googled for. Apparently, though, "Prufer" is the more common Anglicism, and neither produced any useful introductory documents.

So what the hell, I'll give it a shot.

The idea is to generate a unique sequence for each labelled tree on N vertices. What you end up doing is removing vertices one at a time, starting with the highest label leaf vertex (you can start with the lowest, it doesn't matter, as long as you're consistent). When you remove a vertex, you add the label of the vertex it was adjacent to to the sequence. Keep going until you only have two vertices left. You've got a Prüfer sequence!

So, for example, if you have the tree:

``` 1--3--2--4
|\
| 5
6

You'd start by removing vertex 6 (highest label leaf vertex). Add 3 to the Prüfer sequence (which is now 3), and you have the tree:

``` 1--3--2--4
\
5

Now remove 5 and add 3, you have (3, 3) and the tree:

``` 1--3--2--4

Remove 4, add 2, you get (3, 3, 2) -- eventually, you end up with (3, 3, 2, 3) and the tree 1--3.

It turns out that there's a one-to-one correspondence between labelled trees and Prüfer sequences, so each Prüfer sequence uniquely determines a tree. (Which is why the code I posted earlier works.)

Going from a Prüfer sequence to a tree is left as an exercise for the reader. :-)

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
The hell with paco, vote for Erudil!

Create A New User
Node Status?
node history
Node Type: note [id://234519]
help
Chatterbox?
 [Corion]: Hurrr - on a machine that is behaving weirdly, I have two processes CROND running. I guess that is the source of unattended jobs sometimes not finding their files anymore... [ambrus]: Most of the time if I make slides, they're just a formatted document with a medium level of formality (between a well written article and an informal draft), with usually the page breaks chosen carefully and possibly some content repeated between pages. [Corion]: ambrus: My slides are mostly a list of things I want to talk about. But sometimes I want to point out interesting parts, or build up a larger image from small components. This is where animations/ highlights would come in well [choroba]: what I like about slides in HTML + CSS is I can use templates to produce them, which means all code in slides is tested, and I can version them in git [ambrus]: Btw, a request to everyone who organizes international conferences where presenters will show slides. [ambrus]: In the document where you tell people how long the presentations are supposed to be, please also tell the aspect ratio of your projectors, because that's not obvious in advance. [Corion]: ambrus: A more important point is that when constructing slides, you should respect a margin around your slide content of maybe 10% where no important information should be ;) [ambrus]: If you don't do that, some people will be able to use only two thirds of the available screen area, or have to prepare three versions of their slides, each of which is a waste that you could avoid with one simple phrase in the call for papers. [Corion]: As for somebody hosting national conferences, we don't always know the kind of connectors and aspect ratios available ;) [ambrus]: Corion: well sure, but that's the similar to any printed document, and the margin is diminishing with today's technology. Video games no longer have to assume that the CRTs won't show the edges of the screen.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2017-09-26 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
During the recent solar eclipse, I:

Results (293 votes). Check out past polls.

Notices?