京都大学 情報学研究科 知能情報学専攻 2018年2月実施 情報学基礎 F-1
Author
祭音Myyura (co-authored with GPT 5.6 SOL)
Description
Q.1
A hash table is an effective data structure for implementing operations such as INSERT, SEARCH, and DELETE in computer systems.
-
What is the advantage of hash tables compared with directly addressing into an array?
-
Given a hash table of size for integer keys, with linear probing and hash function , show the table after inserting in this order.
-
A hash function hashes distinct keys into an array of length . Assuming uniform hashing, what is the expected cardinality of
Q.2
Breadth-first search (BFS) and depth-first search (DFS) are algorithms for traversing trees or graphs.
-
Draw the directed graph on vertices specified by
Here lists the vertices to which points.
-
Give the order in which the vertices are visited by BFS and DFS, respectively. Both algorithms start at , and neighbors are examined in their adjacency-list order.
-
Give a recursive DFS algorithm for a graph.
题目描述
- 回答哈希表相关问题:
- 与直接寻址数组相比,哈希表有何优点?
- 长度为 的哈希表使用线性探测和 。按序插入 后,写出表内容。
- 将 个不同键均匀哈希到长度 的数组,求发生碰撞的无序键对数量的期望。
- 对给定有向邻接表:
- 画出图;
- 从 出发,按邻接表中的顺序分别写出 BFS 与 DFS 的访问顺序;
- 给出图上 DFS 的递归算法。
Kai
Q.1
1.1
A direct-address table needs one slot for every possible key, so it uses space for key universe . A hash table can use slots for stored keys and still supports search, insertion, and deletion in expected time under uniform hashing. It therefore saves substantial space when the stored key set is sparse.
1.2
Linear probing tests cyclically until it finds an empty slot. The insertions give
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Key | 0 | 7 | 1 | 3 | 11 | 9 | empty |
Thus the final table is
1.3
For each unordered pair , define
Uniform hashing gives . There are unordered pairs, so linearity of expectation yields
Q.2
2.1
2.2
Using the adjacency-list order shown in the question,
and
2.3
DFS-VISIT(G, u)
visited[u] = true
output u
for each v in G.adj[u]
if not visited[v]
DFS-VISIT(G, v)
DFS(G)
for each vertex u in G
visited[u] = false
for each vertex u in G
if not visited[u]
DFS-VISIT(G, u)
Each vertex is visited once and each directed edge is examined once, so the running time is .