• Tidak ada hasil yang ditemukan

CSL202: Discrete Mathematical Structures

N/A
N/A
Protected

Academic year: 2025

Membagikan "CSL202: Discrete Mathematical Structures"

Copied!
21
0
0

Teks penuh

(1)

Ragesh Jaiswal, CSE, IIT Delhi

(2)
(3)

How do we design a good hash function?

A set S of keys from a universeU ={0,1, ...,m−1} is supposed to be stored in a table of sizen with indices T ={0,1, ...,n−1}.

Assume collisions are resolved using auxiliary data structure.

What we need is a hash functionh :U →T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

(4)

How do we design a good hash function?

A set S of keys from a universeU ={0,1, ...,m−1} is supposed to be stored in a table of sizen with indices T ={0,1, ...,n−1}.

Assume collisions are resolved using auxiliary data structure.

What we need is a hash functionh :U →T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

Claim 1: Ifm>n, then for anyh there exists a key setS such that h has collision w.r.t. S (i.e., ∃x,y ∈S,h(x) =h(y))

(5)

How do we design a good hash function?

A set S of keys from a universeU ={0,1, ...,m−1} is supposed to be stored in a table of sizen with indices T ={0,1, ...,n−1}.

Assume collisions are resolved using auxiliary data structure.

What we need is a hash functionh :U →T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

Claim 1: Ifm>n, then for anyh there exists a key setS such that h has collision w.r.t. S (i.e., ∃x,y ∈S,h(x) =h(y))

Claim 1.1: Any fixed hash functionh:U →T, must map at leastdmneelements of U to some index in the setT.

(6)

How do we design a good hash function?

A set S of keys from a universeU ={0,1, ...,m−1} is supposed to be stored in a table of sizen with indices T ={0,1, ...,n−1}.

Assume collisions are resolved using auxiliary data structure.

What we need is a hash functionh :U →T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

Claim 1: Ifm>n, then for anyh there exists a key setS such that h has collision w.r.t. S (i.e., ∃x,y ∈S,h(x) =h(y)) Claim 2: For any fixed key set S such that |S| ≤n, there exists a hash function such thath has no collisions w.r.t. S.

(7)

How do we design a good hash function?

A set S of keys from a universeU ={0,1, ...,m−1} is supposed to be stored in a table of sizen with indices T ={0,1, ...,n−1}.

Collisions are resolved using auxiliary data structure.

What we need is a hash functionh :U →T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

Claim 1: Ifm>n, then for anyh there exists a key setS such that h has collision w.r.t. S (i.e., ∃x,y ∈S,h(x) =h(y)) Claim 2: For any fixed key set S such that |S| ≤n, there exists a hash function such thath has no collisions w.r.t. S. The issue is that the key setS is not known a-priori. That is, before using the data structure.

Question: How do we solve this problem then?

(8)

How do we design a good hash function?

A setS of keys from a universeU={0,1, ...,m−1}is supposed to be stored in a table of sizenwith indicesT ={0,1, ...,n−1}.

Collisions are resolved using auxiliary data structure.

What we need is a hash function h:U→T with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

Claim 1: If m>n, then for anyhthere exists a key set S such thath has collision w.r.t. S (i.e., ∃x,y ∈S,h(x) =h(y))

Claim 2: For any fixed key setS such that|S| ≤n, there exists a hash function such thath has no collisions w.r.t. S.

The issue is that the key setS is not known a-priori. That is, before using the data structure.

Question: How do we solve this problem then?

Randomlyselect a hash function from afamilyHof hash functions.

(9)

How do we design a good hash function?

A setSof keys from a universeU={0,1, ...,m1}is supposed to be stored in a table of sizenwith indicesT={0,1, ...,n1}.

Collisions are resolved using auxiliary data structure.

What we need is a hash functionh:UT with the following main requirements:

1 The hash function should minimize the number of collisions.

2 The space used should be proportional to the number of keys stored. (i.e.,n≈ |S|)

The issue is that the key set Sis not known a-priori. That is, before using the data structure.

Question: How do we solve this problem then?

Randomlyselect a hash function from afamilyHof hash functions.

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y U,x 6=y,Prh←H[h(x) =h(y)]1 n.

(10)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

(11)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

Proof sketch: Consider any keyx. The expected number of keys in locationh(x) is at most t/n.

Question: Can you think of a 2-universal hash function family?

(12)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

Proof sketch: Consider any keyx. The expected number of keys in locationh(x) is at most t/n.

Question: Can you think of a 2-universal hash function family?

Simple answer: The set ofallfunctions fromU toT.

Do you see any issues with using this hash function family?

(13)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

Proof sketch: Consider any keyx. The expected number of keys in locationh(x) is at most t/n.

Question: Can you think of a 2-universal hash function family?

Simple answer: The set ofallfunctions fromU toT.

Do you see any issues with using this hash function family? The description of any hash function from this family is large.

Question: Can we design a morecompacthash function family?

(14)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

A compact 2-universal hash function family:

Letm≤p≤2m.

H={ha,b|a∈ {1, ...,p−1},b∈ {0, ...,p−1}}and ha,b(x) = ((ax+b) modp) modn.

How many functions doesH have?

(15)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

A compact 2-universal hash function family:

Letm≤p≤2m.

H={ha,b|a∈ {1, ...,p−1},b∈ {0, ...,p−1}}and ha,b(x) = ((ax+b) modp) modn.

How many functions doesH have? p(p−1)

(16)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

A compact 2-universal hash function family:

Letm≤p≤2m.

H={ha,b|a∈ {1, ...,p−1},b∈ {0, ...,p−1}}and ha,b(x) = ((ax+b) modp) modn.

How many functions doesH have? p(p−1) Theorem: H is 2-universal.

(17)

Definition (2-universality)

A hash function familyH is said to be 2-universal iff:

∀x,y ∈U,x 6=y,Prh←H[h(x) =h(y)]≤ 1 n.

Theorem: Consider hashing using a 2-universal hash function family. Considertinsert operations, the expected cost of each operation is at most (1 +t/n).

A compact 2-universal hash function family:

Letm≤p≤2m.

H={ha,b|a∈ {1, ...,p−1},b∈ {0, ...,p−1}}and ha,b(x) = ((ax+b) modp) modn.

Theorem: H is 2-universal.

(18)

Theorem: H is 2-universal.

Proof sketch

Letga,b(x) = (ax+b) modp. So,ha,b(x) =ga,b(x) modn.

Consider anyx,y∈ {0, ...,p−1}such thatx6=y.

Claim 1: Ifha,b(x) =ha,b(y), thenga,b(x) =ga,b(y) modn.

(19)

Theorem: H is 2-universal.

Proof sketch

Letga,b(x) = (ax+b) modp. So,ha,b(x) =ga,b(x) modn.

Consider anyx,y∈ {0, ...,p−1}such thatx6=y.

Claim 1: Ifha,b(x) =ha,b(y), thenga,b(x) =ga,b(y) modn.

Claim 2: For allα, β∈ {0, ...,p−1}:

Pr[ga,b(x) =αandga,b(y) =β] =

(0 ifα=β

1

p(p−1) otherwise

(20)

Theorem: H is 2-universal.

Proof sketch

Letga,b(x) = (ax+b) modp. So,ha,b(x) =ga,b(x) modn.

Consider anyx,y∈ {0, ...,p−1}such thatx6=y.

Claim 1: Ifha,b(x) =ha,b(y), thenga,b(x) =ga,b(y) modn.

Claim 2: For allα, β∈ {0, ...,p−1}:

Pr[ga,b(x) =αandga,b(y) =β] =

(0 ifα=β

1

p(p−1) otherwise Claim 3: We have:

Pr[ha,b(x) =ha,b(y)] = |{(α, β) :α6=β andα≡β modn}|

p(p−1) ≤ 1

n.

(21)

Referensi

Dokumen terkait

The main target of distribution network planning is to minimize the objective function equation whereby the variables of this particular equation have a non-linear

To do this, we need to define aMixedElementas the product space of three simple finite elements and then used the mixed element to define the function space: P1 = FiniteElement’P’,

International principles concerning outer space: The main body of current international space law is contained in five international agreements: 1 Treaty on the principles that

Ideally, we would like data structure operations to run in times proportional to the constant or logarithm function, and we would like our algorithms to run in linear or n-log-n time..

According to Wonoraharjo [10] there are 3 main things that should be considered in the green building concept Figure 1, namely: efforts to minimize the environmental impact on the whole

They need to understand what it means to teach English literature in the class; they need to know what kinds of roles they should play in promoting English literature peda- gogy;they

The need to arrange the furniture and interior of the room to minimize the consequences of disasters, including choosing the main room as a gathering place within the home so that

This document is a permit to work in a confined space. It outlines the requirements for working in a confined space, including the need for a lifeline and an attendant at the