The SICStus Prolog libraries assoc
and avl
both provide tree implementations of association lists.
While the binary trees used by library(assoc)
are unbalanced (and thus can degrade to linear lists in the worst case), the binary trees used in library(avl)
are kept balanced (using balancing operations upon insertion which utilize additional bookkeeping data).
So with library(avl)
tree heights are guaranteed to be in O(log N)—even in the worst-case. With library(assoc)
, heights can range from log2(N) (best case) to O(log N) (average case) to N (worst case)—depending on the order of insertions.
So why then does library(avl)
offer avl_height/2
while library(assoc)
does not offer assoc_height/2
?
(I don't see a use case of avl_height/2
, but I see a clear one of assoc_height/2
.)