3 ms·
Much more importantly, vectors are almost always the wrong answer (with a handful of exceptions). Consider a perfectly balanced tree with even 1k elements -- it
by park0ur 12y ago
Much more importantly, vectors are almost always the wrong answer (with a handful of exceptions). Consider a perfectly balanced tree with even 1k elements -- it will have height log2(1k) ~ 10, so approximately 11 reads, almost certainly from main memory, to access an element.
Exceptions are things like you have to iterate through elements in some order, a very high ratio of inserts/deletes to queries, etc -- the obvious stuff.
This is the worst argument ever. You basically said, "trees are the wrong answer, except for when you want to do tree stuff." Want to have a priority queue? Or want to search through your collection without sorting it first? Or insert into your sorted collection? Trees are your friend. They're a tool, just like hashmaps.
- x0x0 12y agoWhen you quote things, it's customary to not modify the quote. And no, that's not what I wrote. Trees are an associative data structure. Hashmaps are a better associative data structure, except when you need the few capabilities trees have that hashmaps don't. ps -- if you run that quote through fold -s -w 77, it won't be so wide...
- park0ur 12y agoWhoops, I didn't mean to apply quote formatting to that. I DID mean to take the same argument and swap for vectors, but DIDN'T mean to make it look like your words. My apologies. But, I maintain that trees have their uses. I would never use a hashmap to implement a priority queue, and i'd never use a tree to implement associative arrays!