| 2 | using namespace std; |
| 3 | |
| 4 | int main() |
| 5 | { |
| 6 | /* |
| 7 | |
| 8 | Hashing: |
| 9 | --> passing data through a formula |
| 10 | which produces a result, called a hash. |
| 11 | --> usually used to implement insert, |
| 12 | search and delete in O(1). |
| 13 | --> always has unique values. |
| 14 | --> not useful in: |
| 15 | - finding closest value |
| 16 | - sorted data |
| 17 | - prefix searching |
| 18 | |
| 19 | Applications of Hashing: |
| 20 | --> dicitonaries |
| 21 | --> database indexing |
| 22 | --> cryptography |
| 23 | --> caches |
| 24 | --> routers |
| 25 | --> getting data from databases |
| 26 | |
| 27 | Direct Address Table: |
| 28 | --> imagine 1000 keys with values |
| 29 | from (0-999) implement: search,insert |
| 30 | delete in O(1) |
| 31 | --> make array of size int arr[1000] |
| 32 | for every insert make corresponding |
| 33 | index 1 store value like arr[i]=1 |
| 34 | --> for values(1000-1999) use insert |
| 35 | as arr[i-1000]=1 |
| 36 | --> disadvatnages: |
| 37 | - large values not handled |
| 38 | - strings not handled |
| 39 | - floating values not handled properly |
| 40 | |
| 41 | Hashing: |
| 42 | --> take large keys and take hashing function |
| 43 | generate small values and use these values |
| 44 | as index. |
| 45 | |
| 46 | Hash Function: |
| 47 | --> should generate values from (0,m-1) |
| 48 | --> should be fast O(1) for integers and O(len) |
| 49 | for strings |
| 50 | Eg: |
| 51 | - hash=large_key%m |
| 52 | - string="abcd" --> hash='a'*0+'b'*1+'c'*2+d*3 |
| 53 | --> should do uniform distribution |
| 54 | |
| 55 | Collision Handling: |
| 56 | --> if we know keys in advance then perfect hashing. |
| 57 | --> if we don't know keys in advance then use one |
| 58 | of the following. |
| 59 | - Linear Probing |
| 60 | - Quadratic Probing |
| 61 | - Double Hashing |
nothing calls this directly
no outgoing calls
no test coverage detected