The notes of Algorithms ---- Data Structures ---- Hash Table

本文深入探讨了哈希表的工作原理,包括直接访问表的优势与局限性、哈希函数的设计原则,以及解决冲突的方法如链接法和开放地址法。此外,还介绍了如何选择合适的哈希函数以提高效率,并讨论了通用哈希的概念及其应用。

Table S holding n records.

One record structure is like this:

struct{

Key;

Satellite data;

}

X, as a pointer, which point to one record.

Operations

- Insert(S,x); //S<--S∪{x}

- Delete(S,x); //S<--S - {x}

- Search(S,k);  //return x, such as key[x]=k or nil if no such x. (Note, the second param is k not x.)


Direct Access Table:

Suppose keys are drown form U={0,1,......m-1}

Set up array T[0,......,m-1] to represent the dynamic set S.


T[k]=x if x∈S and key[x]=k

T[k]=nil otherwise

Operation take Θ(1) time.

Disadvantage: if the range of U is very large and only a subpartion of U will be map into table S, there will be lots of waste space. Furthermore, if the key is not represent by numeral, it cannot map the key into index of the array. So, we need another data-structure  ------   Hash-Table.


Hashing:

m: stands there are m slots(space).

n: there are n records to map into the slots.


Hash funcion h maps keys "randomly" into slots of table T. When a record to be inserted maps to an already occupied slot, a collision occurs.


Resolving collisions 

The first method --- by chaining:

Idea: link records in same slot into a list.

Analysis:

Worst-case: every hashes to the same slot. Access takes Θ(n) time.

Anverage-Case: assumption of simple uniform hashing

- each key  is equally likely to be hashed to any slot in T independent of where other keys are hash.

P{h(k_i)=h(k_j)}=1/m*1/m*m=1/m

P{h(k_i)=2}=1/m

The load factor of a hash table with n keys and m slots, is α=n/m="anverage numbers of keys per slot".

So, the Expected unsuccessful search time will be Θ(1+α)

       the Expected successful search time will be Θ(1) (if α=O(1))

The second method --- by open addressing  --- no stroge for links.

- Probe table systematically until an empty slot is found.

- h: U×{0,1,......,m-1} ---> {0,1,.....,m-1}

U: universe of keys

frist {0,1,...m-1}: probe

second {0,1,...m-1}: slot

- Table may fill up, so we should make sure n<=m.

- Deletion is impossible.

   Probing stratagies:

- Linear detect : "primary clustring"

- Double hashing - h(k,i)=(h_1(k)+i*h_2(k)) mod m

To guarateen search whole table, there are two methods.

Method1 : usually pick m=2^r and h_2(k) gets odd. 

Method2 : m get a prime. m` as a number little than m and keep positive interger. h_2(k)=1+(k mod m`)


Choose a hash function :

Division method:

h(k)=k mod m 

Notice: 1.Don`t pick m with small divisor d such as d=2.

Ex: if d=2 and all keys are even, then the slots which index is odd can never use.

2.Don`t pick m=2^n so that hash doesn`t depend on all bits of k.

3.Pick m = prime not too close to power of 2 and 10.

Multiplication method:

Condition: 1.m=2^r     2. computer has w-bits words.

Then: h(k)=(A*k mod 2^w) rsh (w-r)

Don`t pick A too close to the power of 2^(w-1) or 2^w

Muliple and mod 2^w is much faster than division, btw, rsh is also fast.

It like a modular wheel, A decide when the wheel shoud stop.

Universal hashing:

If you put out a certain hash function, there must be a array, we can make it out, to make your hash function map these data into one slot. How to deal with it: Randomized.

Define: let U be a universal of keys, and let H be a finite collection of has functions, mapping U to {0,1,...m-1},

We can call H is universal: if any x,y∈U where x!=y the following is true:

{h∈H | h(x)=h(y)}=|H|/m 

(This means there are |H| hash function in H, and only |H|/m functions make h(x)=h(y))

Thm: Choose h randomly from H suppose hashing n keys into m slots in table T. Then for a given key x.

E[# collisions wiht x]<n/m

Constructing a universal hash function:

Let m be prime: Decompose key k into r+1 digits: k=<k_0,k_1...k_r> where 0<=k_i<=m-1

(make k into many digital base m, it can be realized using k mod m and k/m)

Pick a=<a_0,a_1,...a_r>(base m) each a_i is chosen randomly from {0,1,....m-1}

(This step insert radom into our algorithm)

Define h_a(k)=(∑a_i*k_i) mod m

The size of H is m^(r+1).

Perfect hashing:

Given n keys, construct a static hash table of size m=O(n), such as the search take O(1) time in the worst-case.

Idea: use 2-level schema with universal hashing at both level. No collisions at level 2.

level-1:  If n_ items that hash to level-1 slot i the use m_i=n_i^2 in level-2 table S_i.

The level-1 table store m_i, the index of universal hash, and a pointer to level-2 table.

level-2: to make sure that no collisions at the level, just test a few at random. Find one quickly since at least half of these functions will work fine.

内容概要:本文围绕“基于交流潮流的电力系统多元件N-k故障模型研究”展开,深入探讨了利用Matlab代码实现电力系统在发生多个关键元件同时故障(即N-k故障)情况下的交流潮流计算与故障分析方法。该模型不仅考虑了传统潮流方程的非线性特性,还引入了故障约束条件,能够精确模拟复杂多样的故障场景,如短路、断线等,进而评估电网在极端运行条件下的稳态与动态行为。研究通过构建典型电力系统算例,验证了所提模型在故障筛选、脆弱性识别及系统恢复策略制定方面的有效性,为电力系统安全评估、风险预警和防御体系构建提供了坚实的理论依据和技术支撑。此外,模型具备良好的扩展性,可进一步应用于连锁故障传播分析、恶意攻击模拟等高级安全分析领域。; 适合人群:具备电力系统分析基础理论知识和Matlab编程能力的高校研究生、科研院所研究人员以及电力公司从事电网规划、运行与安全管理的技术人员,特别适用于开展电力系统安全稳定、可靠性评估与应急响应机制研究的专业人士。; 使用场景及目标:①开展电力系统在多重故障条件下的交流潮流仿真,评估系统电压稳定性、线路过载风险及负荷损失程度;②识别电网中的关键薄弱环节与脆弱元件,支撑电网加固改造与防御资源配置;③用于科研项目中的故障场景建模与算法验证,或作为教学案例帮助学生理解复杂故障下的系统响应机制。; 阅读建议:此资源以Matlab代码为核心实现手段,建议读者结合理论推导与代码实现进行对照学习,重点关注故障建模过程中雅可比矩阵的修正方法、故障注入方式及收敛性处理策略,建议在仿真中逐步增加故障数量与复杂度,深入理解N-k故障对系统潮流分布的影响规律,并尝试将其拓展至含新能源接入的现代电力系统场景中进行验证与优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值