Professional Documents
Culture Documents
Shai Wyborski
Question 1
a.
The described algorithm will return {[4, 7]} while the best solution is {[0, 5], [6, 10]}
b.
{[0, 1], [1, 2], [1, 2], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [5, 6], [5, 6], [6, 7]}
(we'll assume that similar segments which are denoted twice describe dierent
tasks at similar times)
The algorithm will rst choose [3, 4], as it intersects with the fewest tasks, and
will remain with
{[0, 1], [1, 2], [1, 2], [1, 2], [5, 6], [5, 6], [5, 6], [6, 7]}
this set can be divided to
{[0, 1], [1, 2], [1, 2], [1, 2]} , {[5, 6], [5, 6], [5, 6], [6, 7]}
1
Question 2
a.
• li ≥ 0
Pk
• i=1 ak lk = n
i=1 li is minimal
Pk
•
Let us dene Di = oi − ji .
Let i = min {i : oi 6= li }. It's obvious that oi < li (as oi > li =⇒
Pi
j=1 oj > n
from the denition of the algorithm), and that i 6= k.
We know that Di > 0, let us notice that
k k
X Di X
0= aj Dj ≤ ai−1 + (Di mod2)ai + aj Dj
j=i
2 j=i+1
we get that
X X X X
o?j ≤ o j − oi + D i = oj − oi + (oi − ji ) < oj
2
b.
We'll use the coins 6, 5, 3, 1. Trying to return 10 shekels using our algorithm
will result in the output 1, 0, 1, 1 while a better output would be 0, 2, 0, 0.
Question 3
Let us denote wi = pi
ai .
For every test ei the amount of points we get for each hour we spent learning
for it is wi · 100.
Since wi is independent of other grades, or how many hours spent on each test,
we just want to choose the highest among the wi such that xaii < 1, when xi is
the amount of hours we already spent studying for that test.
The output will be the succession x1 , ..., xn .
The algorithm:
Proof of correctness: Trivial, every hour we choose to study for the test which
is most benecial, which is exactly like choosing the largest k out of n numbers.
Choosing the largest one k times is just ne.
Running time: Sorting the array is o(n log n), after the sorting we do
P constant
time calculations until we run out of hours or time, which is o (T + ei ai ).
The overall running time would be o(n log n + T + ei ai ).
P
Question 4
a.
3
b.
c.
Let S = {1, 2, 3, 4}, I1 = {{1, 2}, {1, 3}, {1}, {2}, {3}}, I2 = {{1, 2}, {2, 3}, {1}, {2}, {3}}.
Then (S, I1 ) and (S, I2 ) are matroids, however
I = {X1 ∩ X2 : X1 ∈ I1 and X2 ∈ I2 } = {{1, 2}, {1}, {2}, {3}}
Since |{1, 2}| > |{3}| yet {1, 3}, {2, 3} ∈/ I we get that the augmentation isn't
satised.
d.
This is a matroid.
Hereditary: Let A ∈ I , and let B ⊂ A. Let x ∈/ A\B , since M1 and M2 are
matroids, X1 \{x} ∈ I1 and X2 \{x} ∈ I2 , thus
(X1 \{x}) ∪ (X2 \{x}) ∈ I
since S is nite we know that |A\B| is nite, and we can repeat this process for
every element in A\B until we get that
(X1 \(A\B)) ∪ (X2 \(A\B)) = (X1 ∪ X2 ) \(A\B) = A\(A\B) = B ∈ I
Question 5
Hereditary: Let A ∈ I and let B ⊂ A. Since A doesn't contain a circle, neither
does B , which proves B ∈ I .
Augmentation: Let A, B ∈ I such that |A| < |B|. A ∪ {x} ∈ I i {x} gaps two
connectivity components in A, we need to prove that such an x exists in B .
Let us assume that every x ∈ B\A closes a circle in A, thus, none of them
gap between two connectivity components in A, and since A ∩ B ⊂ A, and
B = A ∪ (B\A) we get that B has at least as much connectivity components as
A.
4
However, we know that B is acyclic, which means that A ∩ B ( A since A ∩ B =
A =⇒ (A ∩ B) ∪ {x} ⊂ B which means B closes a cycle.
Since this is true for every x ∈ B\A, we know that |A ∩ B| ≤ |A| − |B\A|, thus
|B| = |(A ∩ B) ∪ (B\A)| = |(B\A)| + |(A ∩ B)| ≤ |(B\A)| |A| − |B\A| = |A|
which is a contradiction.
Question 6
b.
• Build a bipartite graph (L, R, E) where L and R are empty.
This algorithm always holds a perfect matching, and it's correctness is almost
immediate from a.