관리 메뉴

Silver Library (Archived)

Difference between Hash vs Node memory 본문

F2. Problem & Solving/Theory of algorithm

Difference between Hash vs Node memory

Chesed Kim 2023. 4. 25. 18:55
반응형

According to Bard, here is the answer and some note I commented below:

 

Hash memory and node memory are two types of memory that are used in hash tables. Hash memory is used to store the hash values of the data, while node memory is used to store the actual data.

In a hash table, the hash function is used to convert the data into a hash value. The hash value is then used to find the corresponding node in the hash table. The node contains the actual data.

For example, let's say we have a hash table that stores the names of people and their phone numbers. The hash function might be something like this:

function hash(name) {
  return name.toLowerCase().hashCode();
}

This function would convert the name "John Doe" into the hash value 100663248.

The hash value 100663248 would then be used to find the corresponding node in the hash table. The node would contain the actual data, which is the phone number for John Doe.

 

Hash memory is typically much smaller than node memory. This is because the hash values are typically small integers, while the actual data can be of any size.

 

For example, the hash value for the name "John Doe" is 100663248. This is a very small number, and it can be stored in a very small amount of memory.

 

The phone number for John Doe, on the other hand, could be any number. It could be a 10-digit phone number, a 12-digit phone number, or even a longer phone number. This means that the phone number for John Doe would need to be stored in a larger amount of memory.

 

By using separate memory for the hash values and the actual data, hash tables can be more efficient. This is because the hash values can be stored in a small amount of memory, and the actual data can be stored in a larger amount of memory.