|
50 | 50 | --
|
51 | 51 | -- Operation comments contain the operation time complexity in
|
52 | 52 | -- the Big-O notation <http://en.wikipedia.org/wiki/Big_O_notation>.
|
| 53 | +-- |
53 | 54 | -- Many operations have a worst-case complexity of \(O(\min(n,W))\).
|
54 | 55 | -- This means that the operation can become linear in the number of
|
55 | 56 | -- elements with a maximum of \(W\) -- the number of bits in an 'Int'
|
56 |
| --- (32 or 64). |
| 57 | +-- (32 or 64). These peculiar asymptotics are determined by the depth |
| 58 | +-- of the Patricia trees: |
| 59 | +-- |
| 60 | +-- * even for an extremely unbalanced tree, the depth cannot be larger than |
| 61 | +-- the number of elements \(n\), |
| 62 | +-- * each level of a Patricia tree determines at least one more bit |
| 63 | +-- shared by all subelements, so there could not be more |
| 64 | +-- than \(W\) levels. |
| 65 | +-- |
| 66 | +-- If all \(n\) keys in the tree are between 0 and \(N\) (or, say, between \(-N\) and \(N\)), |
| 67 | +-- the estimate can be refined to \(O(\min(n, \log N))\). If the set of keys |
| 68 | +-- is sufficiently "dense", this becomes \(O(\min(n, \log n))\) or simply |
| 69 | +-- the familiar \(O(\log n)\), matching balanced binary trees. |
| 70 | +-- |
| 71 | +-- The most performant scenario for 'IntMap' are keys from a contiguous subset, |
| 72 | +-- in which case the complexity is proportional to \(\log n\), capped by \(W\). |
| 73 | +-- The worst scenario are exponentially growing keys \(1,2,4,\ldots,2^n\), |
| 74 | +-- for which complexity grows as fast as \(n\) but again is capped by \(W\). |
| 75 | +-- |
57 | 76 | -----------------------------------------------------------------------------
|
58 | 77 |
|
59 | 78 | module Data.IntMap
|
|
0 commit comments