More OCaml: Algorithms, Methods & Diversions by John Whitington

More OCaml: Algorithms, Methods & Diversions by John Whitington

Author:John Whitington [Whitington, John]
Language: eng
Format: epub
Publisher: Coherent Press
Published: 2014-09-22T07:00:00+00:00


* * *

Figure 11.3:

* * *

When the tree is balanced insert and member run in logarithmic time. The size function runs in linear time, since it must visit every node irrespective of the balance. The same is true of list_of_set. When unbalanced, insert and member take linear time. We can extend our table now:

Notice that, in the unordered case, performance is dramatically increased for insertion and membership, by about two hundred times. However, if the elements are inserted in order, the unbalanced tree actually takes longer to build than its equivalent list. Finding all the elements as a list also takes a huge amount of time in the ordered insertion case.

Balanced trees



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.