What are the differences between map implementation by hashes or trees?

-1

What is the advantage of mapping hash instead of the binary tree?

    
asked by anonymous 11.07.2018 / 14:17

1 answer

2

Doubt should be more the reverse.

If you need the data to be sorted you need the binary tree. If you need to order, you need an array , or some trick with the binary tree (or not). If you can neglect order or sorting then the spreadsheet can be useful.

The spreading table has complexity O (1), that is, it is constant no matter the volume of data. It's like the access time of an arrya by its index. Not the same time because hash needs to compute the bucket where the data is before accessing.

The binary tree has complexity O (logN) which in many cases is close to constant. In fact because it does not have to calculate with low data volume it is possible that it is faster than hash , even if logN gives something greater than 1. In large volumes it will be slower, but it is not a difference so great. To get an idea 1 billion elements can be accessed in only 30 steps. Although the volume influences the access time, it is ridiculous, and in some cases it makes no difference.

    
11.07.2018 / 15:59