On 4/6/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
HOWEVER. isn't a tree the most general data structure?
I have had no problem making trees out of arrays.
Arrays are nice because they are so close to the way memory is
laid out in your typical computer. Trees... there's so many kinds
of trees, and so many algorithms for working with them that the
variety alone makes them complex. Or, if you simplify them, you've
basically got something that "looks like an array".
Any feedback on why J is an array processing language and how it might
handle tree/hierarchical data is appreciated.
Ok, let's take a tree that looks like this:
0
/ \
1 2
/ \ \
3 4 5
One representation looks like this:
t=. 0 0 0 1 1 2
Here, each number locates the parent node.
To help visualize, consider
(,: [EMAIL PROTECTED])t
0 0 0 1 1 2
0 1 2 3 4 5
Or you could use names rather than numbers (though that
requires more elaborate code to implement).
Also, you can implement trees using boxed arrays.
Just the other day I posted a somewhat elaborate example of
this http://www.jsoftware.com/pipermail/programming/2007-April/005903.html
(That's a shift/reduce parser which converts an indented character
list into boxed arrays using "pythonish" rules to define the
structure.)
Etc. etc. ...
And how good is J with infinite data structures/streams?
As good as your imagination. (Computers are finite.)
If you mean handling indefinite cases -- J can deal. Sometimes I
wish for more elegance, but then I usually get stuck trying to
unambiguously specify what I mean by elegance in the ambiguous
contexts where this arises.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm