comp.lang.ada
 help / color / mirror / Atom feed
From: "Des Walker" <des.walker@dessy.fsnet.co.uk>
Subject: Re: array
Date: Thu, 12 Apr 2001 19:59:41 +0100
Date: 2001-04-12T18:49:10+00:00	[thread overview]
Message-ID: <9b4tb6$cha$1@news5.svr.pol.co.uk> (raw)
In-Reply-To: DpjB6.4297$FY5.303408@www.newsranger.com


Ted Dennison <dennison@telepath.com> wrote in message
news:DpjB6.4297$FY5.303408@www.newsranger.com...
> In article <5s2B6.32267$ii5.3236241@afrodite.telenet-ops.be>, Pieter
Thysebaert
> says...
> >Now I was looking for a function that would allow me to convert the
contents
> >of a tree into an array (and vice versa)
> >I've found something like arrays with variable range (I mean not
fixed at
> >compile-time)
> >Well I think that's what I found - does that thing exist ?
> >
> >And if it does, how would one manipulate it (add/remove elements)
>
> Back in the olden days, binary trees were ususally implmented as
arrays. I
> believe the algorithms for doing so are avilable in "The Art of
Computer
> Programming, Volume 3"
 http://www-cs-faculty.stanford.edu/~knuth/taocp.html ).
> Go find, or preferably purchase yourself, a copy.
>
>
> >
> >Or are there data structures like C++ STL stuff (vector etc)
available ?
> The Ada implementation of the Booch Components should have something
for
> size-limited trees, which I would imagine would be implemented using
arrays (but
> I haven't examined the code).
>
> ---
> T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
>           home email - mailto:dennison@telepath.com

Hi,
  I think the underlying implementation for some of the 'bounded' items
in the Booch Components use arrays, but the array would not be directly
accessible to the user. The BC does provide some useful binary tree
implementations for dynamically changing binary trees, I've used the AVL
tree to good effect.

One method of representing a binary tree in an array is put each node at
the index which corresponds to the order you would obtain it in a
breadth order traversal.
i.e. If you number your binary tree nodes starting at the root node

-------1
---2-------3
4----5--6----7

The numbers correspond to the array index for the element

for an element at index I,
the left child will be at index (I*2)
the right child will be at index (I*2+1)
the parent will be at index (I/2)

If your binary tree has holes in it, you'll need some way of describing
an empty array element, to maintain the correct position of a node in an
array.
In this way you'll know a node doesn't have a child if the index for the
child is greater than the maximum size of the array, or the value at
that index is the empty element.

Sorry I can't be more helpful, I've never used an array implementation
for a binary tree. Binary Trees I have used have been ones which are
dynamically changing and need continuous rebalancing, for which the AVL
tree has been satisfactory.

    Des Walker






  reply	other threads:[~2001-04-12 18:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-11 19:41 array Pieter Thysebaert
2001-04-12 14:59 ` array Ted Dennison
2001-04-12 18:59   ` Des Walker [this message]
2001-04-12 18:51 ` array Stephen Leake
2001-04-12 21:05 ` array Jeffrey Carter
2001-04-13  7:09 ` array Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
1998-04-15  0:00 Array BanaN
1998-04-17  0:00 ` Array BanaN
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox