Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Am I wrong to assume a TreeMap's array's initial size should be able to be set? </p> </blockquote> <p>Yes. A <code>TreeMap</code> doesn't have an array. A <code>TreeMap</code> uses binary nodes with 2 children.</p> <p>If you are suggesting that the number of children in a tree node should be a parameter, then you need to figure out how that impacts on search time. And I think that it turns the search time from <code>O(log2N)</code> to <code>O(log2M * log2(N/M))</code> where <code>N</code> is the number elements and <code>M</code> is the average number of node children. (And I'm making some optimistic assumptions ...) That's not a "win".</p> <blockquote> <p>Is there a different reason that it is so slow?</p> </blockquote> <p>Yes. The reason that a (large) <code>TreeMap</code> is slow relative to a (large) <code>HashMap</code> under optimal circumstances is that lookup using a balanced binary tree requires looking at <code>log2N</code> tree nodes. By constrast, in an optimal <code>HashMap</code> (good load factor and no collision hotspots) a lookup involves 1 hashcode calculation and looking at <code>O(1)</code> hashchain nodes.</p> <p>Notes:</p> <ol> <li><code>TreeMap</code> uses a binary tree organization that gives balanced trees, so <code>O(log2N)</code> is the worst case lookup time.</li> <li><code>HashMap</code> performance depends on the collision rate of the hash function and key space. In the worst case where all keys end up on the same hash chain, a <code>HashMap</code> has <code>O(N)</code> lookup.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload