Вы находитесь на странице: 1из 6

Samuel Lau

8261166
Logic And Sets: Assignment 2

1. (a)

h = neither (not bijective or surjective)

k = neither (not bijective or surjective)

(b)

k ◦ h

x
1

y 2

k ◦ h(y) = 2, k ◦ h(x) = 2

(c)

The function k ◦ h is not invertible as it is not a bijective function.

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

Samuel Lau Assignment 2C 1 of 6


(b)

The graph is connected.

(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

There are zero paths of length 2 from vertex 1 to vertex 2.

(d)

5
2 3

1
1 4

7 3

1 → 5 = 7

2 → 3 = 5

3 → 5 = 1

4 → 5 = 3

Total weight of minimum spanning tree = 16

Samuel Lau Assignment 2C 2 of 6


4. (a)

6b 7d

4f 1e

1e 0

Shortest Path

e→f→a→b=7

Samuel Lau Assignment 2C 3 of 6


5. (a)

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

Samuel Lau Assignment 2C 4 of 6



2

3 5

9 8 6

5 6

9 8

6 8

Samuel Lau Assignment 2C 5 of 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]

Samuel Lau Assignment 2C 6 of 6

Вам также может понравиться