The difference between BST, Hashing, Tries and map

I read a blog and tutorial on Tries, Hashing, Map (stl) and BST. I am very confused when to use it and where. I know that making such a difference between them is pointless because they are implementation dependent. Could you tell me more specifically and please do not forget to mention the difficulty (worst, medium and best).

Thanks in advance...

+4
source share
1 answer

BST is a binary search tree. It is used for vocabulary. BST has no structural limitations, and therefore search / insert / delete is O (n) worst case.

The map [on stl] is also a dictionary and is actually a red-black tree [on stl]. this is a special kind of BST that has limitations on structures, which is why in the worst case, search / insert / delete is O (logn).

<x> hashing a hash table is another type of dictionary, the advantage of a hash table [with good hash functions] is O (1) average search / delete / insert time. however, the worst case is O (n), which happens if too many elements collide and / or when renaming is required [when the Load Balance is too high, we allocate a larger array and replay all the elements in is].

Tries are special for strings. all operators are O (S), where S is the length of the string. this is an advantage for others [when working with strings] - you still need to read the string, so the difficulty if a Map , for example, when working with strings, is actually O (S * n * logn).

when to use?
a Map [or any other balanced tree] should always be a better choice than a regular BST .
hash table is a good choice when you need a medium short time, but don't care that in some cases you will have a performance loss due to rephrasing, and in some cases there may be collisions.
Trie usually a good dictionary for strings.

+6
source

All Articles