Hashing and Breadth-First Search
Assignment 9
Submit your answers via Moodle. Submissions may be uploaded as PDF or as plain text files.
A LaTeX answer template is available here: answers.tex.
New to LaTeX? See the LaTeX guide for DSA students.
Exercise 1: Hashing (6 points)
Suppose that the following keys are inserted in some order into an initially empty linear-probing hash table of size 7 (assuming no resizing), using the following table of hash values:
| Key | Hash |
|---|---|
| A | 5 |
| B | 2 |
| C | 5 |
| D | 1 |
| E | 4 |
| F | 1 |
| G | 3 |
-
Give the contents of the linear-probing array if the keys are inserted in alphabetical order:
A, B, C, D, E, F, G. Report the resulting array in your submission, for example as a row indexed from0to6. - Which of the following could be the contents of the linear-probing array if the keys are inserted in some other order?
| Candidate 1 | ||||||
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| A | F | D | B | G | E | C |
| Candidate 2 | ||||||
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| F | A | D | B | G | E | C |
| Candidate 3 | ||||||
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| C | A | B | G | F | E | D |
Choose the best answer.
- 1 only
- 1 and 2 only
- 1 and 3 only
- 1, 2, and 3
- None
Exercise 2: Breadth-first search (16 points)
-
Run breadth-first search on the graph below, starting at vertex
A. Assume the adjacency sets are in sorted order. For example, when exploring vertexF, the algorithm considers the edgeF-CbeforeF-D,F-E, orF-H.
-
Consider two vertices
xandythat are simultaneously on the FIFO queue at some point during the execution of breadth-first search fromsin an undirected graph. Which of the following are true?- The number of edges on the shortest path between
sandxis at most one more than the number of edges on the shortest path betweensandy. - The number of edges on the shortest path between
sandxis at least one less than the number of edges on the shortest path betweensandy. - There is a path between
xandy.
- The number of edges on the shortest path between