What is the space used by programs when we use Hashmap in our program?

2017

What is the space used by programs when we use Hashmap in our program?

  1. A.

    O(1)

  2. B.

    O(LogN)

  3. C.

    O(N)

  4. D.

    None

Attempted by 485 students.

Show answer & explanation

Correct answer: C

The space complexity of a HashMap is O(N) because it stores N key-value pairs. Each entry requires constant space, leading to linear total memory usage relative to the number of elements.

Explore the full course: Isro