Better HN
topnewbestaskshowjobs
Log inSign up

park0ur

-4 karma · joined Mar 16, 2015 (11y ago) · 2 submissions

Submissions

comment 11y ago · link · parent

Whoops, 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!

comment 11y ago · link · parent

    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.