Re: Dynamic data structures
- From: Gene <gene.ressler@xxxxxxxxx>
- Date: Sun, 27 Jul 2008 14:11:57 -0700 (PDT)
On Jul 26, 11:52 am, Roman Töngi <roman.toe...@xxxxxxxxxx> wrote:
I've learned a strategy to resize the size of a data structure to
implement a dynamic data structure as follows:
E.g. for a stack:
- If the stack if full, create a new one with double of the old size.
before insertion operation it looks like:
|xxxxxxxxxx|
after insertion operation:
|xxxxxxxxxx|x |
- If number of elements in the stack gets below a quarter of the size
of the stack, create a new one of half the old size.
before deletion operation:
|xxxxx| |
after deletion operation:
|xxxx | |
dar
With such a strategy (doubling if full and halving if count gets below 25%),
an amortized worst case analysis shows that the average cost per operation is
constant.
Are there better strategies?
For any simple resizable array, this is the standard approach to limit
copy overhead.
There is no a priori reason the multiple should be 2. Any constant
factor will do.
Certainly for a stack you can use linked nodes or blocks of nodes to
eliminate copying completely.
There are many other approaches that don't require any copying even
for a general resizable array. See for example http://en.wikipedia.org/wiki/VList
(and the Variants note at the end).
.
- References:
- Dynamic data structures
- From: Roman Töngi
- Dynamic data structures
- Prev by Date: Re: 16-bit value in 3 bytes?
- Next by Date: Re: core features and functions required in modern programming languages
- Previous by thread: Re: Dynamic data structures
- Next by thread: trees
- Index(es):
Relevant Pages
|