Re: [BLACKBOX] AVL Trees

From: [at]} <Gérard>
Date: Wed, 7 Sep 2011 03:00:09 +0200

----boundary-LibPST-iamunique-1257188583_-_-
Content-type: text/plain

Hello Robert,

What do you call a fast list?

Gérard

Le mardi 06 septembre 2011 à 22:20 +0100, Robert a écrit :
> Thanks to everyone who provided suggestions.
>
>
> I have now solved my problem (6 different ways!) so I don't need any more solutions!
>
>
> The irony is that I originally asked for help with the 'Delete' routine. I now
> know that I only needed to build the data structure and traverse it once; I
> didn't actually need to do any deleting.
>
>
> The problem was characterised by three integers: C (known and large), B, which
> is smaller than C, and A (the answer) which is smaller again.
>
> I thought that A would be (*much*) smaller than B, which would be (*much*)
> smaller than A.
>
>
> There were four obvious algorithms with the following properties:
>
> Data-Structure Required-Memory Required-Time
>
> Array C C
> List A B * A
> List B B * Log (B)
> Tree A B * Log (A)
>
>
> I ruled out the Array as I thought the memory would be too big.
> In fact it is the best. It requires only 1 bit per node, compared to a
> threaded AVL tree which requires about 100 bits per node, so the memory was
> affordable.
>
> I ruled out the Lists as I thought they would be either too slow (correct) or
> too big. In fact B is not much bigger than A so the list solution is efficient
> and SIMPLE!.
>
> The times are:
>
> Array 0.22 s
> Slow list > 10 hours
> Fast list 1.42 s
> Unbalanced binary tree 8.28 s
> AVL tree (Modula-2 book) 1.39 s
> AVL tree (Wirth's book) 1.3 s
> AVL tree (Subsystem Util on CPC) 2.0 s
>
>
> The Util version is a threaded tree, which means that it is a little more
> costly to build, but more efficient / flexible to access; features not used here.
>
>
> Next time (if there is a next time!) I will use an unbalanced binary tree.
> The list would not have been competitive if A had been (*much*) smaller than B,
> and the advantage of the AVL tree does not justify the complexity.
>
>
>
> Cheers
>
> Robert
>
>
> ----
> To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy
>


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1257188583_-_-
Content-type: application/rtf
Content-transfer-enc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WZmaWNpZW50IC8g
ZmxleGlibGUgdG8gYWNjZXNzOyBmZWF0dXJlcyBub3QgdXNlZCBoZXJlLlxwYXINCj4gXHBhcg0K
PiBccGFyDQo+IE5leHQgdGltZSAoaWYgdGhlcmUgaXMgYSBuZXh0IHRpbWUhKSBJIHdpbGwgdXNl
IGFuIHVuYmFsYW5jZWQgYmluYXJ5IHRyZWUuXHBhcg0KPiBUaGUgbGlzdCB3b3VsZCBub3QgaGF2
ZSBiZWVuIGNvbXBldGl0aXZlIGlmIEEgaGFkIGJlZW4gKCptdWNoKikgc21hbGxlciB0aGFuIEIs
XHBhcg0KPiBhbmQgdGhlIGFkdmFudGFnZSBvZiB0aGUgQVZMIHRyZWUgZG9lcyBub3QganVzdGlm
eSB0aGUgY29tcGxleGl0eS5ccGFyDQo+IFxwYXINCj4gXHBhcg0KPiBccGFyDQo+IENoZWVyc1xw
YXINCj4gXHBhcg0KPiBSb2JlcnRccGFyDQo+IFxwYXINCj4gXHBhcg0KPiAtLS0tXHBhcg0KPiBU
byB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9Y
IiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQo+IFxwYXINClxwYXINClxwYXINCi0t
LS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZG
IEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQp9
----boundary-LibPST-iamunique-1257188583_-_---
Received on Wed Sep 07 2011 - 03:00:09 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:11 UTC