Exactly. Here's a more refined procedure to illustrate
what happens to edges on the path from old to new root:
With the tree hanging freely held by the old root with
one (top) hand, grab the new root with the other (bottom)
hand and tighten thus determining the said path;
now turn over the hands: the new root is at the top.
Now think what happened to the path: each edge flipped.
Since other edges remained hanging as they had been, they
did not participate in the transformation.
--- On Mon, 5/19/08, Roger Hui <[EMAIL PROTECTED]> wrote:
> Grab the node you want to be the root, lift the whole graph,
> and shake ...
>
>
>
> From: Oleg Kobchenko <[EMAIL PROTECTED]>
>
> > Looks like you just need to
> > flip each pair in path from old root to new root
> >
> > |: t1 (|."[EMAIL PROTECTED])}~ c i. }: (p {~ c i. ])^:(c
>
> > e.~])^:a: 3
> > 1 0 3 2 2 3 3 4 4 4 4 5 5 6
> > 6 6 6 7 7
> > 0 2 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > tree t1 (|."[EMAIL PROTECTED])}~ c i. }: (p {~ c i.
> ])^:(c
> > e.~])^:a: 3
> > +----------------------------------+
> > | +- 8 |
> > | +- 9 |
> > | +- 4 -+- 10|
> > | | +- 11|
> > | +- 1 --- 0 --- 2 -
> > + +- 12|
> > |
> > | +- 5 -+- 13|
> > | | +-
> > 14 |
> > | | +-
> > 15 |
> > |- 3 -+- 6 -+-
> > 16 |
> > | | +-
> > 17 |
> > | | +-
> > 18 |
> > | +- 7 -+-
> > 19 |
> > +----------------------------------+
> >
> >
> > --- On Mon, 5/19/08, Jose Mario Quintana
> > <[EMAIL PROTECTED]> wrote:
> >
> > > From: Jose Mario Quintana
> <[EMAIL PROTECTED]>
> > > Subject: Re: [Jprogramming] Displaying trees - J
> > Wiki/Essays/Tree Sum
> > > To: "Programming forum"
> <[email protected]>
> > > Date: Monday, May 19, 2008, 12:12 PM
> > > A directed tree can be rerooted at any of its
> nodes. For
> > > example, t1 from
> > >
> http://www.jsoftware.com/jwiki/Essays/Tree_Display ,
> > >
> > >
> > > |:t1
> > > 0 0 1 2 2 3 3 4 4 4 4 5 5
> > 6 6 6 6 7 7
> > > 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> > > tree t1
> > > +----------------------------+
> > >
> > | ┌─ 14|
> > >
> > | ├─ 15|
> > >
> > | ┌─ 6 ─┼─ 16|
> > >
> > | │ └─ 17|
> > > | ┌─ 1 ─── 3
> > ─┤ ┌─ 18|
> > > |
> > │ └─
> > 7 ─┴─ 19|
> > > |
> > │ ┌─
> > 8 |
> > > |─ 0
> > ─┤ ├─ 9 |
> > > | │ ┌─ 4 ─┼─
> > 10 |
> > > | │
> > │ └─ 11 |
> > > | └─ 2 ─┤ ┌─
> > 12 |
> > > |
> > └─ 5 ─┴─ 13 |
> > > +----------------------------+
> > >
> > > Can be rerooted at 3 as,
> > >
> > > tree t2=. 3 reroot t1
> > > +----------------------------------+
> > > |
> > ┌─ 14 |
> > > |
> > ├─ 15 |
> > > | ┌─ 6 ─┼─
> > 16 |
> > > | │ └─
> > 17 |
> > > | │ ┌─
> > 18 |
> > > | ├─ 7 ─┴─
> > 19 |
> > > |─ 3
> > ─┤ ┌─ 8 |
> > > |
> > │ ├─ 9 |
> > > |
> > │ ┌─ 4 ─┼─ 10|
> > > |
> > │ │ └─ 11|
> > > | └─ 1 ─── 0 ─── 2
> > ─┤ ┌─ 12|
> > >
> > | └─ 5 ─┴─ 13|
> > > +----------------------------------+
> > >
> > > |:t2 NB. (reroot rendering t2 or equivalent)
> > > 3 3 6 6 6 6 7 7 3 1 0 2 2
> > 4 4 4 4 5 5
> > > 6 7 14 15 16 17 18 19 1 0 2 4 5 8 9 10 11 12 13
> > >
> > >
> > > Has any J version of reroot been made public
> already?
> > >
> > >
> > > ----- Original Message ----
> > > From: Roger Hui <[EMAIL PROTECTED]>
> > >
> > > Nothing new under the sun.
> > >
> >
> http://groups.google.com/group/comp.lang.apl/browse_thread/thread/5f1c1df7bd72fe51/32691205433c3152?lnk=gst#32691205433c3152>
>
> > > ----- Original Message -----
> > > From: Roger Hui <[EMAIL PROTECTED]>
> > >
> > > >
> http://www.jsoftware.com/jwiki/Essays/Tree_Display
> ----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm