sicp-2.3.3
Posted on 2015-02-22 23:54:30 +0900
in SICP
Lisp
2.59
2.60
adjoin-set
goes from $O(n)$ to $O(1)$
union-set
goes from $O(n^2)$ to $O(n)$
2.61
2.62
2.63
It would make no difference on the final result, both of them are in order traverse.
But there is something tricky on the time complexity1.
append
is much more expensive than cons
.
Let $T(n)$ be the time complexity for a balanced tree of $n$ nodes.
For tree->list-1:
For tree->list-2:
2.64
The analysis of time complexity is similar to the 2.63
, which is $O(nlog n)$.
2.65
Use tree-list
from 2.63
and list-tree
to convert bidirectional.
2.66