11.1 直接寻址表

11.1-1

findmax(T,m)
{max=T[0];for i=1 to m-1{if T[i]!=NIL && T[i]>maxmax=T[i]}return max
}

最坏情况下的运行时间为O(m)

11.1-2

如果位向量的第k位有元素则设为1,否则设为0

11.1-3

用链表解决碰撞问题

11.1-4

We denote the huge array by T and, taking the hint from the book, we also have a
stack implemented by an array S . The size of S equals the number of keys actually
stored, so that S should be allocated at the dictionary’s maximum size. The stack
has an attribute S: top, so that only entries S[1.. S.top] are valid.
The idea of this scheme is that entries of T and S validate each other. If key k is
actually stored in T , then T[k] contains the index, say j , of a valid entry in S , and
S[j] contains the value k. Let us call this situation, in which 1 ≤ T[k] ≤ S.top,
S[T[k]] = k, and T[S[j]] = j , a validating cycle.
Assuming that we also need to store pointers to objects in our direct-address table,
we can store them in an array that is parallel to either T or S . Since S is smaller
than T , we’ll use an array S', allocated to be the same size as S , for these pointers.
Thus, if the dictionary contains an object x with key k, then there is a validating
cycle and S[T[k]] points to x .
The operations on the dictionary work as follows:

  • Initialization: Simply set S.top = 0, so that there are no valid entries in the stack.
  • SEARCH: Given key k, we check whether we have a validating cycle, i.e., whether 1 ≤ T[k] ≤ S.top and S[T[k]] = k. If so, we return S'[T[k]], and otherwise we return NIL
  • INSERT: To insert object x with key k, assuming that this object is not already in the dictionary, we increment S.top, set S[S.top] = k, set S'[S.top] = x , and set T[k] = S.top.
  • DELETE: To delete object x with key k, assuming that this object is in the dictionary, we need to break the validating cycle. The trick is to also ensure that we don’t leave a “hole” in the stack, and we solve this problem by moving the top entry of the stack into the position that we are vacating—and then fixing up that entry’s validating cycle. That is, we execute the following sequence of assignments:

S[T[k]]←S[top[S]]
S'[T[k]] ← S'[top[S]]

T[S[T[k]]]←T[k]

T[k]←0

top[S]←top[S]−1

Each of these operations---initialization, SEARCH, INSERT, and DELETE---takes
O(1)time.
实现:http://blog.csdn.net/mishifangxiangdefeng/article/details/7709567

11.2 散列表

11.2-1

11.2-3

成功查找:Θ(1 + α)    The element we search for is equally likely to be any of the elements in the hash table.

不成功查找:1/2 of the original running time, but still Θ(1 + α), if we simply assume that the probability thatone element's value falls between two consecutive elements in the hash slot is uniformly distributed.

This is because the value of the element we search for is equally likely to fall between any consecutive elements in the hash slot, and oncewe find a larger value, we can stop searching. Thus, the running time for unsuccessful searches is a half of the originalrunning time.
插入:Θ(1 + α), compared to the original running time of Θ(1 ).

This is because we need to find the right location instead of the head to insert the element so that the list remains sorted.

删除:Θ(1 + α), same as successful searches.

11.2-4

11.2-5

鸽笼原理:Hash U中所有元素,则必有一个slot的元素数量大于n。若不然,m个slots共有小于等于nm个元素,矛盾

11.3 散列函数

11.3-1

先将给定元素的散列值与链表中的散列值比较,如果相等,再比较关键字

11.3-2

从字符串的低位开始,每处理一个字符,就将得到的数取一次模,这样就可以只利用常数个机器字了

11.3-3

11.3-4

h(61)=700

h(62)=318

h(63)=936

h(64)=554

h(65)=172

11.3-5

11.3-6*

11.4 开放寻址法

11.4-1

线性探查 22 88 0 0 4 15 28 17 59 31 10

二次探查 22 0 88 17 4 0 28 59 15 31 10

双重散列 22 0 59 17 4 15 28 88 0 31 10

11.4-2

HASH-DELETE(T,i)
{if T[i]!=NILthen T[i]=DELETED elsereturn false}HASH-INSERT(T,k)
{i=0repeat j=h(k,i)if T[j]=NIL or DELETEDthen T[j]=k return jelse i=i+1until i=merror "hash table overflow"
}

11.4-3 *

11.4-4

定理11.6及11.8

不成功的查找:1/(1-a)     1/(1-3/4)=4次   1/(1-7/8)=8次

成功的查找:  (1/a)ln(1/(1-a))   (1/(3/4))ln(1/(1-3/4)) =1.848   (1/(7/8))ln(1/(1-7/8))=2.377

11.4-5*

1/(1-a)=2*(1/a)ln(1/(1-a))   解得a≈0.715

算法导论答案 第11章:散列表相关推荐

  1. 【算法导论】学习笔记——第11章 散列表

    11.1 直接寻址表 当关键字的全域U很小,可采用直接寻址的方式.假设动态集合S的元素都取自全域U={0, 1, ..., m-1}的一个关键字,并且没有两个元素具有相同的关键字. 为表示动态集合,使 ...

  2. 《算法图解》——第五章 散列表(服务器大姨妈来了?第四第五内容传不上去= =!)

        第五章    散列表 1 散列函数(散列映射.映射.字典.关联数组) 散列函数是这样的函数,即无论你给它什么数据,它都还你一个数字.即散列函数"将输入映射到数字" 散列函数 ...

  3. 算法导论答案 第10章:基本数据结构

    10.1 栈和队列 10.1-2 从数组的两端向数组的中间插入元素.数组的两端相当于2个栈的栈顶. 10.1-4 ENQUEUE(Q,x) {if head[Q]=(tail[Q]+1)%length ...

  4. 《算法导论3rd第十三章》红黑树

    前言 红黑树是一种较为"平衡的"二叉查找树.它能保证最坏的情况下其基本操作时间为O(lgn). 红黑树的性质 红黑树 是一种二叉查找树,但在每个结点上增加了一个存储位表示结点的颜色 ...

  5. 应用概率统计(陈魁)部分答案7~11章

    数理统计应用概率统计(陈魁)部分答案7~11章 第七章 数理统计的基本概念 习题7.2.7.3.7.4.7.6,答案见下图 第八章 参数估计 习题8.1.8.4.8.6.8.8.8.11.8.12,答 ...

  6. 《算法导论》第四章-第4节_练习(参考答案)

    算法导论(第三版)参考答案:练习4.4-1,练习4.4-2,练习4.4-3,练习4.4-4,练习4.4-5,练习4.4-6,练习4.4-7,练习4.4-8,练习4.4-9 Exercise 4.4-1 ...

  7. 《算法导论》第四章-第3节_练习(参考答案)

    算法导论(第三版)参考答案:练习4.3-1,练习4.3-2,练习4.3-3,练习4.3-4,练习4.3-5,练习4.3-6,练习4.3-7,练习4.3-8,练习4.3-9 Exercise 4.3-1 ...

  8. 《数据结构与算法》(二十)- 散列表查找

    目录 前言 1. 散列表查找(哈希表)概述 1.1 散列表查找定义 1.2 散列表查找步骤 2. 散列函数的构造方法 2.1 直接定址法 2.2 数字分析法 2.3 平方取中法 2.4 折叠法 2.5 ...

  9. CLSR 11.2散列表

    11.2-1 对两个不同的关键字 k,lk,l,定义随机变量指示器 Xkl=I{h(k)=h(l)}X_{kl}=I\{h(k)=h(l)\},则 Pr{Xkl=1}=Pr{h(k)=h(l)}=1/ ...

最新文章

  1. 获得 bootstrapTable行号index
  2. AndroidStudio 生成Jar并混淆
  3. JSF开发人员应该知道的5种有用方法
  4. 数据结构:(2)什么是数据结构
  5. 产品新人如何快速成长?
  6. 十二、程序返回、数据类型表示、代码注释
  7. 鸿蒙系统深度解析,深度解析鸿蒙内核最重要的结构体
  8. 四、hibernate实体对象,事务管理,锁
  9. 转正述职报告 实习转正 工作汇报 述职模板免费下载_PPTX图片设计素材_包图网888pic.com...
  10. Python机器视觉--OpenCV进阶(核心)-边缘检测之SIFT关键点检测
  11. 快速排序(过程图解)
  12. 利用Python画直方图
  13. 霸王级”寒潮来袭 神华国华“智能供热”送温暖
  14. Windows下使用IDEAS对cala文件打jar包
  15. word中间空白页删除技巧
  16. EASEUS Partition Master 调整Windows 7分区
  17. 2022 届大四学长实习心得、职场经验分享、转型思考
  18. 文本分类概念类大总结(机器学习+深度学习)
  19. 长尾关键词 挖掘出来的长尾关键词要怎么筛选?筛选条件有哪些
  20. react 对象克隆_如何使用React&GraphQL(Dune World Edition)创建全栈Yelp克隆

热门文章

  1. Windows脚本 - Bat批处理命令使用教程
  2. Quartus II三种方式实现D触发器及时序仿真
  3. 计算机原理与结构 实验3《单周期微处理器设计》
  4. GDUT22级寒假训练专题四
  5. java从入门到精通API02
  6. Java300集速学堂(5)
  7. slurm作业管理系统怎么用?
  8. 不用找,你想要的概念车壁纸素材都在这里
  9. while(t--)和while(--t)的区别
  10. Axure 8.1.0.3381激活码 亲测可用