KimDahye / kimdahye.github.io

kimdahye's tech blog
https://kimdahye.github.io/
MIT License
1 stars 1 forks source link

Hash table 정리 #2

Closed KimDahye closed 6 years ago

KimDahye commented 6 years ago

완성되면 post에 추가하기. 아래는 draft.


함께하고 있는 알고리즘 스터디 멤버들을 위해 Hash table 자료구조를 정리합니다.

Background

Array: direct addressing

Array can be a candidate. But it has the following shortcuts:

Hash table

내부적으로 Array를 데이터 저장공간으로 사용하지만, key가 꼭 integer일 필요 없다. Hash function을 이용하여 key를 integer 값으로 변환하여 그 값을 array 의 index로 사용한다!

충돌을 피하는 2가지 방법: open addressing & separate chaining

open addressing

separate chaining

시간 복잡도

따라서, insert, search, delete에 대해 평균 constant time으로 할 수 있다.

insert search delete findMin findMax
Hash table O(1) avg O(1) avg O(1) avg O(N) O(N)

각 언어에서의 Hash Table

References