0% found this document useful (0 votes)
16 views

ECE 606, Fall 2019, Assignment 6: Zhijie Wang, Student ID Number: 20856733 Zhijie - Wang@uwaterloo - Ca October 22, 2019

Uploaded by

hstrybest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

ECE 606, Fall 2019, Assignment 6: Zhijie Wang, Student ID Number: 20856733 Zhijie - Wang@uwaterloo - Ca October 22, 2019

Uploaded by

hstrybest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ECE 606, Fall 2019, Assignment 6

Zhijie Wang, Student ID number: 20856733

[email protected]
October 22, 2019

1. Let m constraints input as c1 , c2 . . . cm ∈ C, where each constraint is stored as [a, b, 1] representing xa = xb


or [c, d, −1] representing xc 6= xd .
CheckConstraints(C)
1: for each i from 1 to n do
2: for each j from 1 to n do
3: if i = j then
4: r[i][j] ← 1
5: else
6: r[i][j] ← 0
7: for each i from 1 to m do
8: a ← C[i][0], b ← C[i][1], s ← C[i][2]
9: if r[a][b] = 0 then
10: for each j from 1 to n do
11: if r[a][j] = 1 and r[b][j] = 0 then
12: r[b][j] ← s, r[j][b] ← s
13: if r[b][j] = 1 and r[a][j] = 0 then
14: r[a][j] ← s, r[j][a] ← s
15: else if r[a][b] 6= s then
16: return False
17: return True

2. (a) G = {G =< V, E >}, where each G is a directed graph that


V = {u1 , u2 , . . . , un , n ∈ N},
E = {(u1 , u2 , w12 ), (u2 , u3 , w23 ), . . . , (un−1 , un , w(n−1)n ), (u1 , un , w1n )}.
If w12 > w1n > 0, (w12 + w23 + . . . w(n−1)n ) < w1n , then G is satisfied with requirements. Firstly,
there is no negative-weight cycle. Secondly if Dijkstra’s algorithm starting from u1 , then the minimum
weight path from u1 to un will be marked as {u1 , un , w1n }, but obviously {(u1 , u2 , w12 ), (u2 , u3 , w23 ), . . . ,
(un−1 , un , w(n−1)n )} is shorter. Therefore, Dijkstra’s algorithm is not correct.
w12 w23
u1 u2 u3

w1n

un un−1 ...
w(n−1)n

(b) G = {G =< V, E >}, where each G is a directed graph that


V = {u1 , u2 , . . . , un , n ∈ N},
E = {(u1 , u2 , 1), (u2 , u3 , 1), . . . , (un−1 , un , 1), (un , u1 , −1)}.
Firstly there is only one cycle in the graph which has a positive-weight. Secondly, if Dijkstra’s
algorithm starting from un , then obviously it is correct.

1
1 1 1
u1 u2 ... un

−1

3. Proof. Here we consider about an output, G = {g1 , g2 , . . . , gk } that this greedy choice result in, vs. an
optimal set of meetings, T = {t1 , t2 , . . . , tm }. Suppose we represent the start time of a meeting as a
function, s(·), and finish time as a function, f (·). We assume, without any loss of generality, that the
meetings in the two sets are ordered by latest start time.
Firstly, we need to prove that for every i = 1, . . . k, s(gi ) ≥ s(ti ). By induction on i. For the base case,
consider i = 1. The greedy choice is to pick a meeting with the latest start time. This guarantees that
s(g1 ) ≥ s(t1 ). For the step, assume that the assertion is true for i = 1, . . . , p − 1. For i = p, we know that
s(gp−1 ) ≥ s(tp−1 ) ≥ f (tp ). Thus, the meeting tp dose not conflict with gp−1 , and therefore, is available to
be chosen after gp−1 is chosen. Thus, s(gp ) ≥ s(tp ) because we choose the meeting with the latest start
time.
Hence, we need to prove k = m. Assume otherwise, for the purpose of contraction, and that m > k.
Then, there exists a meeting tk+1 in T . But by the claim above, s(gk ) ≥ s(tk ), thus, the meeting tk+1
dose not conflict with gk , and is available to be chosen after gk is chosen, which contradicts the claim that
no more meetings are left that can be chosen after gk is chosen.
4. a6p4.py

You might also like