Bank of America Interview Question
Software Engineer / DevelopersIt is sorted in C++ STL (implemented as a tree), unlike HashMap. The tree structure wouldbe corrupted if you get the reference to the key and override it by brute force. Then the tree search will stop at the node even if the searched element is in the tree (i.e. at the subtree which has the parent with overridden key as a parent).
map will be corrupted when you have one key references two values. A map should always have a unique key for each value.
In case of Java HashMap, corruption is easy to occur if you use it in multi-threaded application without synchronization between threads.
The HashMap has bucket (represents a hash value) and an array representing the list of items that correspond to the given hash value.
{0} -> [x] -> [y] -> null
{1} -> [a] -> null
A common scenario of a corrupted HashMap looks like this:
{0} -> [x] -> [y]
<-
That is, [x] has [y] as its next element and [y] has [x] as its next element. This causes an infinitely loop if you traverse the list.
How about catching memory exception?
- Map September 28, 2009