Re: Heap vs BST
- From: alex.gman@xxxxxxxxx
- Date: 23 Dec 2005 09:50:52 -0800
sillybanter@xxxxxxxxx wrote:
> alex.gman@xxxxxxxxx wrote:
>
> > Ok, if I cache max of a BST, then get_max is O(1), and my BST behaves
> > like a Heap, but also provides the usual extras. Makes me wonder, what
> > are the advantages of Heaps over BSTs now, after get_max is no longer
> > one of them?
>
> Are you going to keep your BST balanced?
Yes
> If so, then the code is much
> more complex. Compare an AVL implementation (insert with rebalance
> would probably be 100+ lines of code) to a heap (insert can be done in
> about 5-6 lines of code).
I don't think this matters much, because this is library code. Written
once, used by many people many times.
> Add to that the fact that balanced BST
> require pointers or indices to indicate parent/child relationships,
> whereas a heap can be thrown into an array with implied (or computed)
> parent/child relationships, and you see that heaps are in fact quite a
> bit more space efficient.
Firstly, there are pluses and minuses to using "pointers" instead of
storing everything in an array. Arrays are difficult to grow.
Secondly, why shouldn't I put my AVL tree onto an array as well, and
use the same parent/children formula?
.
- Follow-Ups:
- Re: Heap vs BST
- From: Googmeister
- Re: Heap vs BST
- References:
- Heap vs BST
- From: alex . gman
- Re: Heap vs BST
- From: sillybanter
- Heap vs BST
- Prev by Date: Re: Heap vs BST
- Next by Date: Re: Heap vs BST
- Previous by thread: Re: Heap vs BST
- Next by thread: Re: Heap vs BST
- Index(es):
Relevant Pages
|
|