Re: [BLACKBOX] AVL Trees

From: [at]} <Robert>
Date: Tue, 6 Sep 2011 22:20:13 +0100

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

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----boundary-LibPST-iamunique-1799204785_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0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iB0byBMSVNUU0VS
VkBMSVNUUy5PQkVST04uQ0hccGFyDQp9
----boundary-LibPST-iamunique-1799204785_-_---
Received on Tue Sep 06 2011 - 23:20:13 UTC

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