Академический Документы
Профессиональный Документы
Культура Документы
8261166
Logic And Sets: Assignment 2
1. (a)
(b)
k ◦ h
x
1
y 2
k ◦ h(y) = 2, k ◦ h(x) = 2
(c)
2. (a)
A m
B s
D c
3. (a)
1 2 3 4 5
1 0 8 0 0 7
2 8 0 5 6 0
3 0 5 0 4 1
4 0 6 4 0 3
5 7 0 1 3 0
(c)
A2
1 2 3 4 5
1 113 0 47 69 0
2 0 125 24 20 79
3 47 24 42 33 12
4 69 20 33 61 4
5 0 79 12 4 59
(d)
5
2 3
1
1 4
7 3
1 → 5 = 7
2 → 3 = 5
3 → 5 = 1
4 → 5 = 3
6b 7d
4f 1e
1e 0
Shortest Path
e→f→a→b=7
The original heap is obtained by assigning the elements of the list into nodes, starting from the left-most
value (5) which will be the root node. Two child nodes are created under the root, which will be
assigned to the second and third values of the list (8 and 3). The process is repeated, adding a
maximum of 2 child nodes under each parent node until all the values of the list are assigned to the
binary tree.
By comparing all the parent nodes (starting from bottom-left) to the child nodes, and swapping if the
parent node has a greater value than its child, eventually we will end up with a min-heap.
8 3
9 1 6 2
Min-Heap
1
2 3
9 8 6 5
3 5
9 8 6
5 6
9 8
6 8
6 9
[] ; [1,2,3,9,8,6,5]
[1] ; [2,3,5,9,8,6]
[1,2] ; [3,5,6,9,8]
[1,2,3] ; [5,6,8,9]
[1,2,3,5] ; [8,6,9]
[1,2,3,5,6] ; [8,9]
[1,2,3,5,6,8] ; [9]
[1,2,3,5,6,8,9]