Sobes.tech
Middle

What is the worst-case execution time of the get(key) method for an existing key in a HashMap?

sobes.tech AI

Answer from AI

$O(n)$, where $n$ is the number of elements in the HashMap. This occurs in the case of collisions, when all elements are placed in one bucket and linked in a linked list (or a tree). In this case, the search becomes equivalent to searching in a linked list or a tree (the worst case for a tree is a degenerate tree), which takes linear time.

What is the worst-case execution time of the get(key)… - sobes.tech