You are on page 1of 118

Algorithms - I

CSC 302

SK Hafizul Islam

Department of CSE, IIIT Kalyani

September 14, 19 & 21, 2022

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 1 / 43
Agenda I

1 Greedy Algorithm
Matroid
Vector Space
Spanning Set
Linear Independence of Vectors
Basis
Dimension of Vector Space
Matric Matroid
Undirected Graph
Directed Graph
Graphic Matroid
2 Greedy algorithms on a weighted matroid
3 Suggested Readings
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 2 / 43
Independent System

Consider a finite set S and a collection I of nonempty family of subsets of S.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 3 / 43
Independent System

Consider a finite set S and a collection I of nonempty family of subsets of S.


M = (S, I) is called an independent system if

A ⊂ B, B ∈ I ⇒ A ∈ I

We say that I is hereditary if it satisfies this property.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 3 / 43
Independent System

Consider a finite set S and a collection I of nonempty family of subsets of S.


M = (S, I) is called an independent system if

A ⊂ B, B ∈ I ⇒ A ∈ I

We say that I is hereditary if it satisfies this property.


The members of I is called independent subsets of M and all other subsets of S is called
dependent sets of M.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 3 / 43
Independent System

Consider a finite set S and a collection I of nonempty family of subsets of S.


M = (S, I) is called an independent system if

A ⊂ B, B ∈ I ⇒ A ∈ I

We say that I is hereditary if it satisfies this property.


The members of I is called independent subsets of M and all other subsets of S is called
dependent sets of M.
Note that the empty set, i.e., ϕ is necessarily a member of I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 3 / 43
Matroid

A finite matroid M is a pair (S, I), where S is a finite set (called the ground set) and I
is a family of subsets of S (called the independent sets) with the following properties:

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 4 / 43
Matroid

A finite matroid M is a pair (S, I), where S is a finite set (called the ground set) and I
is a family of subsets of S (called the independent sets) with the following properties:
The empty set is independent, i.e., ϕ ∈ I. Alternatively, at least one subset of S is independent,
i.e., I =
̸ ϕ.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 4 / 43
Matroid

A finite matroid M is a pair (S, I), where S is a finite set (called the ground set) and I
is a family of subsets of S (called the independent sets) with the following properties:
The empty set is independent, i.e., ϕ ∈ I. Alternatively, at least one subset of S is independent,
i.e., I =
̸ ϕ.
Every subset of an independent set is independent, i.e., if B ∈ I, and A ⊂ B, then A ∈ I.
This is sometimes called the hereditary property, or the downward-closed property.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 4 / 43
Matroid

A finite matroid M is a pair (S, I), where S is a finite set (called the ground set) and I
is a family of subsets of S (called the independent sets) with the following properties:
The empty set is independent, i.e., ϕ ∈ I. Alternatively, at least one subset of S is independent,
i.e., I =
̸ ϕ.
Every subset of an independent set is independent, i.e., if B ∈ I, and A ⊂ B, then A ∈ I.
This is sometimes called the hereditary property, or the downward-closed property.
If A and B are two independent sets (i.e., each set is independent) and A has more elements
than B, i.e., |B| < |A|, then there exists x ∈ A − B such that B ∪ {x } ∈ I. We say the S
satisfies the augmentation property or the independent set exchange property.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 4 / 43
Matroid

A finite matroid M is a pair (S, I), where S is a finite set (called the ground set) and I
is a family of subsets of S (called the independent sets) with the following properties:
The empty set is independent, i.e., ϕ ∈ I. Alternatively, at least one subset of S is independent,
i.e., I =
̸ ϕ.
Every subset of an independent set is independent, i.e., if B ∈ I, and A ⊂ B, then A ∈ I.
This is sometimes called the hereditary property, or the downward-closed property.
If A and B are two independent sets (i.e., each set is independent) and A has more elements
than B, i.e., |B| < |A|, then there exists x ∈ A − B such that B ∪ {x } ∈ I. We say the S
satisfies the augmentation property or the independent set exchange property.
Thus a matroid should satisfy two requirements: hereditary and exchange property.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 4 / 43
Matroid

The word “matroid” is due to Hassler Whitney1 , who first studied matric matroid (1935).

1
Hassler Whitney. On the abstract properties of linear dependence. American Journal of Mathematics,
57:509-533, 1935.
2 Islam (Department of CSE, IIIT Kalyani)
https://link.springer.com/article/10.1007/BF01584082
SK Hafizul Algorithms - I September 14, 19 & 21, 2022 5 / 43
Matroid

The word “matroid” is due to Hassler Whitney1 , who first studied matric matroid (1935).
Actually the greedy algorithm2 first appeared in the combinatorial optimization literature
by Jack Edmonds3 .

1
Hassler Whitney. On the abstract properties of linear dependence. American Journal of Mathematics,
57:509-533, 1935.
2 Islam (Department of CSE, IIIT Kalyani)
https://link.springer.com/article/10.1007/BF01584082
SK Hafizul Algorithms - I September 14, 19 & 21, 2022 5 / 43
Matroid

The word “matroid” is due to Hassler Whitney1 , who first studied matric matroid (1935).
Actually the greedy algorithm2 first appeared in the combinatorial optimization literature
by Jack Edmonds3 .

1
Hassler Whitney. On the abstract properties of linear dependence. American Journal of Mathematics,
57:509-533, 1935.
2 Islam (Department of CSE, IIIT Kalyani)
https://link.springer.com/article/10.1007/BF01584082
SK Hafizul Algorithms - I September 14, 19 & 21, 2022 5 / 43
Matroid

The word “matroid” is due to Hassler Whitney1 , who first studied matric matroid (1935).
Actually the greedy algorithm2 first appeared in the combinatorial optimization literature
by Jack Edmonds3 .

Hassler Whitney Jack R. Edmonds


(New York, March 23, 1907 - Princeton, New (Washington, D.C., April 5, 1934)
Jersey, May 10, 1989)
1
Hassler Whitney. On the abstract properties of linear dependence. American Journal of Mathematics,
57:509-533, 1935.
2 Islam (Department of CSE, IIIT Kalyani)
https://link.springer.com/article/10.1007/BF01584082
SK Hafizul Algorithms - I September 14, 19 & 21, 2022 5 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v
(α + β)v = αv + βv

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v
(α + β)v = αv + βv
α(u + v) = αu + αv

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v
(α + β)v = αv + βv
α(u + v) = αu + αv
1v = v

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v
(α + β)v = αv + βv
α(u + v) = αu + αv
1v = v

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Vector Space

Definition 1
A vector space V over a field F is an abelian group with a scalar product α·v or αv defined
for all α ∈ F and all v ∈ V satisfying the following axioms.
α(β)v = (αβ)v
(α + β)v = αv + βv
α(u + v) = αu + αv
1v = v
where α, β ∈ F and u, v ∈ V . The elements of V are called vectors; the elements of F are
called scalars.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 6 / 43
Spanning Set

Definition 2 (Spanning Set)


Let V be any vector space over a field F and suppose that {v1 , v2 , · · · , vn } ∈ V and the scalars
{α1 , α2 , · · · , αn } ∈ F . Any vector w ∈ V of the form

w = α1 v1 + α2 v2 + · · · + αn vn

is called a linear combination of v1 , v2 , · · · , vn .


The spanning set of vectors v1 , v2 , · · · , vn is the set of vectors obtained from all possible linear
combinations of v1 , v2 , · · · , vn . If W is the spanning set of v1 , v2 , · · · , vn , then we often say
that W is spanned by v1 , v2 , · · · , vn .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 7 / 43
Spanning Set

Definition 2 (Spanning Set)


Let V be any vector space over a field F and suppose that {v1 , v2 , · · · , vn } ∈ V and the scalars
{α1 , α2 , · · · , αn } ∈ F . Any vector w ∈ V of the form

w = α1 v1 + α2 v2 + · · · + αn vn

is called a linear combination of v1 , v2 , · · · , vn .


The spanning set of vectors v1 , v2 , · · · , vn is the set of vectors obtained from all possible linear
combinations of v1 , v2 , · · · , vn . If W is the spanning set of v1 , v2 , · · · , vn , then we often say
that W is spanned by v1 , v2 , · · · , vn .

Theorem 3
Let S = {v1 , v2 , · · · , vn } be a set of vectors in a vector space V . Then the Span(S) is a
subspace of V .
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 7 / 43
Spanning Set

Theorem 4
Let S = {v1 , v2 , · · · , vn } is the spanning set of the vector space V , i.e., Span(S) = V . Then
for any vector w ∈ V , the set S ′ = {w, v1 , v2 , · · · , vn } also spans V , i.e., Span(S ′ ) = V .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 8 / 43
Spanning Set

Theorem 4
Let S = {v1 , v2 , · · · , vn } is the spanning set of the vector space V , i.e., Span(S) = V . Then
for any vector w ∈ V , the set S ′ = {w, v1 , v2 , · · · , vn } also spans V , i.e., Span(S ′ ) = V .

Theorem 5
Let S = {v1 , v2 , · · · , vn } is the spanning set of the vector space V , i.e., Span(S) = V and
assume that vk is a linear combination of some of the other v’s. Then v1 , v2 , · · · , vk−1 ,
vk+1 ,· · · , vn also span V , i.e., Span(v1 , v2 , · · · , vk−1 , vk+1 ,· · · , vn ) = V .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 8 / 43
Spanning Set

Example 1 (Spanning Set)


The set S = {v1 , v2 , v3 } = {(1, 0, 0), (0, 1, 0), (0, 0, 1)} form a basis for R3 . The set S certainly
spans R3 , since any arbitrary vector x = (x1 , x2 , x3 ) ∈ R3 can be written as x = α1 v1 + α2 v2 +
α3 v3 . Assume that x = (2, 3, 4) ∈ R3 can be written as x = 2v1 + 3v2 + 4v3 . Therefore,
Span(v1 , v2 , v3 ) = R3 .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 9 / 43
Spanning Set

Example 1 (Spanning Set)


The set S = {v1 , v2 , v3 } = {(1, 0, 0), (0, 1, 0), (0, 0, 1)} form a basis for R3 . The set S certainly
spans R3 , since any arbitrary vector x = (x1 , x2 , x3 ) ∈ R3 can be written as x = α1 v1 + α2 v2 +
α3 v3 . Assume that x = (2, 3, 4) ∈ R3 can be written as x = 2v1 + 3v2 + 4v3 . Therefore,
Span(v1 , v2 , v3 ) = R3 .

Example 2 (Spanning Set)


We claim that the following vectors {w1 , w2 , w3 } = {(1, 1, 1), (1, 1, 0), (1, 0, 0)} also form a
spanning set of R3 . Specifically, if any v = (a, b, c) ∈ R3 , then v = (a, b, c) = cw1 + (b −
c)w2 + (a − b)w3 . For example, v = (5, −6, 2) = 2w1 − 8w2 + 11w3 .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 9 / 43
Linear Independence of Vectors

Let S = {v1 , v2 , · · · , vn } be a set of vectors in a vector space V . If there exist scalars {α1 , α2 ,
· · · , αn } ∈ F such that not all of the αi ’s are zero, and

α1 v1 + α2 v2 + · · · + αn vn = 0

then S is said to be linearly dependent. If the set S is not linearly dependent, then it is said
to be linearly independent. More specifically, S is a linearly independent set if

α1 v1 + α2 v2 + · · · + αn vn = 0

implies that α1 = α2 = · · · = αn = 0 for any set of scalars {α1 , α2 , · · · , αn } ∈ F .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 10 / 43
Basis

Definition 6 (Basis)
A set {v1 , v2 , · · · , vn } of vectors in a vector space V is called a basis for V if (i) {v1 , v2 , · · · ,
vn } is a linearly independent set, and (ii) Span(v1 , v2 , · · · , vn ) = V .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 11 / 43
Basis

Definition 6 (Basis)
A set {v1 , v2 , · · · , vn } of vectors in a vector space V is called a basis for V if (i) {v1 , v2 , · · · ,
vn } is a linearly independent set, and (ii) Span(v1 , v2 , · · · , vn ) = V .

Example 3 (Basis)
The set S = {v1 , v2 , v3 } = {(1, 0, 0), (0, 1, 0), (0, 0, 1)} form a basis (standard basis) for R3 .
The set S certainly spans R3 , since any arbitrary vector x = (x1 , x2 , x3 ) ∈ R3 can be written as
x = α1 v1 + α2 v2 + α3 v3 . Assume that x = (2, 3, 4) ∈ R3 can be written as x = 2v1 + 3v2 + 4v3 .
Also, none of the vectors v1 , v2 , v3 can be written as a linear combination of the other two;
hence, they are linearly independent. The vectors v1 , v2 , v3 are not the only basis of R3 , the set
{(3, 2, 1), (3, 2, 0), (1, 1, 1)} is also a basis for R3 .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 11 / 43
Dimension of Vector Space

Definition 7
If {v1 , v2 , · · · , vn } is a basis for a vector space V , then we say that the dimension of V is n
and we write dim(V ) = n.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 12 / 43
Dimension of Vector Space

Definition 7
If {v1 , v2 , · · · , vn } is a basis for a vector space V , then we say that the dimension of V is n
and we write dim(V ) = n.

Example 4
Vector space M = Mr ,s of all r × s matrices: The following six matrices form a basis of the
vector space M2,3 of all 2 × 3 matrices over F .
" #" #" #" #" #" #
1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1

Here dim(M) = rs

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 12 / 43
Dimension of Vector Space

Example 5
Let W be the subspace of R5 spanned by the following vectors: v1 = (1, 2, 1, 3, 2), v2 =
(1, 3, 3, 5, 3), v3 = (3, 8, 7, 13, 8), v4 = (1, 4, 6, 9, 7), v5 = (5, 13, 13, 25, 19).
Form the matrix M whose columns are the given vectors, and reduce M to echelon form:
   
1 1 3 1 5 1 1 3 1 5
2 3 8 4 13 0 1 2 2 3
   
1 3 7 6 13 ∼ 0 0 0 2 2
   
   
3 5 13 9 25 0 0 0 0 0
2 3 8 7 19 0 0 0 0 0

Now, we have, dim(W ) = 3.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 13 / 43
Matric Matroid

Definition 8
Consider a matrix M. Let S be the set of row vectors of M and C the collection of all linearly
independent subsets of S. Then (S, C ) is called Matric matroid.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 14 / 43
Matric Matroid

Definition 8
Consider a matrix M. Let S be the set of row vectors of M and C the collection of all linearly
independent subsets of S. Then (S, C ) is called Matric matroid.

Hereditary: If A ⊂ B and B ∈ C , meaning B is a linearly independent subset of row


vectors of M, then A must be linearly independent.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 14 / 43
Matric Matroid

Definition 8
Consider a matrix M. Let S be the set of row vectors of M and C the collection of all linearly
independent subsets of S. Then (S, C ) is called Matric matroid.

Hereditary: If A ⊂ B and B ∈ C , meaning B is a linearly independent subset of row


vectors of M, then A must be linearly independent.
Exchange Property: The exchange property is a well known fact for linearly
independence. Say, If A, B are sets of linearly independent rows of M, and |A| < |B|,
then dim(span(A)) < dim(span(B)). Choose a row x ∈ B, where x ̸∈ span(A). Then
A ∪ {x } is a linearly independent subset of rows of M.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 14 / 43
Undirected Graph4

Graph is a non-linear data structure.


An undirected graph G(V , E ) is a triple consisting of:
1 A vertex set V
2 An edge set E
3 A relation between an edge and a pair of vertices
V = {a, b, c, d} and E = {e1 , e2 , e3 , e4 , e5 , e6 , e7 }

a
We represent an edge for undirected graph
e1 as e = [a, b]
e6
e2

b e5 d
e4
e7
e3

c
4
Chapter 8: S. Lipschutz, Data Structures. Mc-Graw Hill Education.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 15 / 43
Directed Graph

A directed graph G, also called a digraph, is a graph in which every edge has a direc-
tion assigned to it. An edge e of a directed graph is given as an ordered pair (u, v ) of
nodes/vertices in G. For an edge e = (u, v ),
1 The edge e begins at u and terminates at v .
2 u is known as the origin or initial point of e and v is known as the destination or terminal point
of e.
3 u is the predecessor of v and v is the successor of u.
4 u and v are adjacent to each other.

e7
We represent an edge for a directed graph as e = (a, b).
v1 v2 v6 The out-degree of a node u, written as outdeg(u), is the number of
e1
edges beginning at u. outdeg(v1 ) = 3, outdeg(v2 ) = 2, outdeg(v3 ) =
e8 2, outdeg(v4 ) = 1, outdeg(v5 ) = 0, outdeg(v6 ) = 0.
e2 e5 e4

v5
The in-degree of a node u, written as indeg(u), is the number of
edges ending at u. indeg(v1 ) = 0, indeg(v2 ) = 3, indeg(v3 ) = 1,
v3 e3
v4 e6
indeg(v4 ) = 3, indeg(v5 ) = 0, indeg(v6 ) = 0.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 16 / 43
Directed Graph

e7

v1 e1
v2 v6

e8
e2 e5 e4

v5

v3 e3
v4 e6

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 17 / 43
Directed Graph

e7
The degree of a node, written as deg(u), is equal to
v1 v2 v6 the sum of in-degree and out-degree of that node. Therefore,
e1
deg(u) = outdeg(u) + indeg(u).
e2 e5 e4
e8
A vertex with degree zero is called isolated vertex. Such a vertex
v5 is not an end-point of any edge. v6 is the isolated vertex.
v3 e3
v4 e6 A vertex with degree one is called pendant vertex or leaf vertex.
v5 is the pendant vertex.
A vertex u is known as a source if it has a positive out-degree but a zero in-degree. v1
is the source.
A vertex u is known as a sink if it has a positive in-degree but a zero out-degree. v5 is
the sink.
A vertex v is said to be reachable from vertex u, if and only if there exists a (directed)
path from u to v . Vertex v5 is reachable from the vertex v1 .
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 17 / 43
Directed Graph

e7
A digraph is said to be strongly connected if and only if
there exists a path between every pair of nodes in the graph,
v1 v2
e1 i.e., if there is a path from node u to v , then there must be
a path from node v to u.
e8
e2 e5 e4 A digraph is said to be unilaterally connected if there exists
v5a path between any pair of nodes u, v in the graph such that
v3 v4 e6
there is a path from u to v or a path from v to u, but not
e3
both.
Distinct edges which connect the same end-points are called multiple/parallel edges.
e1 = (v1 , v2 ) and e7 = (v1 , v2 ) are multiple edges.
A directed graph is said to be a simple directed graph if and only if it has no parallel edges.
However, a simple directed graph may contain loops with an exception that it cannot have
more than one loop at a given node.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 18 / 43
Graph

v1 v5

e2 e5
e1 e6

v3 e4
v4
e3 e7
v2 v6

A vertex v is called a cut vertex/articulation point, if removing v along with the edges
incident on it increases the number of components. v3 and v4 are the articulation points.
A cut edge of a graph is an edge whose deletion increases the number of components. e4
is the cut edge.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 19 / 43
g
Graph
FIGURE 1.8. Deletion operations.

G G
A graph S is connected if every pair of vertices can be joined by a path.
1 2 G3
FIGURE 1.9. Connected and disconnected graphs.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 20 / 43
g
Graph
FIGURE 1.8. Deletion operations.

G G
A graph S is connected if every pair of vertices can be joined by a path.
1 2 G3
G1 is connected, and both G2 and G3 are not connected (or disconnected).
FIGURE 1.9. Connected and disconnected graphs.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 20 / 43
g
Graph
FIGURE 1.8. Deletion operations.

G G
A graph S is connected if every pair of vertices can be joined by a path.
1 2 G3
G1 is connected, and both G2 and G3 are not connected (or disconnected).
Each maximal connected1.9.
FIGURE piece of a graph and
Connected is called a connected
disconnected component.
graphs.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 20 / 43
g
Graph
FIGURE 1.8. Deletion operations.

G G
A graph S is connected if every pair of vertices can be joined by a path.
1 2 G3
G1 is connected, and both G2 and G3 are not connected (or disconnected).
Each maximal connected1.9.
FIGURE piece of a graph and
Connected is called a connected
disconnected component.
graphs.
G1 has one component, G2 has three components, and G3 has two components.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 20 / 43
Spanning Tree

Let G(V , E ) be a connected graph. A tree T , which is a subgraph of G, is called a


spanning tree if it contains all the vertices of G.
Spanning tree is defined only for a connected graph.
A edge e ∈ T is called a branch.
An edge e ∈
/ T is called a chord.
Set of branches and set of chords will be changed, if we change the spanning tree.
If T is spanning tree (set of branches) of G and T ′ (set of chords) be its compliment,
then T ∪ T ′ = G.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 21 / 43
Spanning Tree

Figure: Graph Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning
tree tree tree tree

Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning
tree tree tree tree tree

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 22 / 43
Spanning Tree

3 3 3 3

7
6
7

7
4 6 4
5

5
2
2 2 2 2

Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning


Figure: Graph
tree tree tree tree
3 3 3 3 3

7
6 4 6
5

5
2 2

Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning Figure: Spanning
tree tree tree tree tree
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 23 / 43
Spanning Subgraphs

Definition 9
A spanning subgraph G ′ = (V , E ′ ) is a subgraph that contains all the vertices of the original
graph G = (V , E ), where E ′ ⊆ E .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 24 / 43
Spanning Subgraphs

Definition 9
A spanning subgraph G ′ = (V , E ′ ) is a subgraph that contains all the vertices of the original
graph G = (V , E ), where E ′ ⊆ E .

e1 e2

e3

e5
e7 e8

e6

Figure: Graph G

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 24 / 43
Spanning Subgraphs

Definition 9
A spanning subgraph G ′ = (V , E ′ ) is a subgraph that contains all the vertices of the original
graph G = (V , E ), where E ′ ⊆ E .

e1 e2 e1 e2

e3

e5 e5
e7 e8 e7 e8

e6 e6

Figure: Graph G Figure: Spanning Subgraph of


G

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 24 / 43
Spanning Subgraphs

Definition 9
A spanning subgraph G ′ = (V , E ′ ) is a subgraph that contains all the vertices of the original
graph G = (V , E ), where E ′ ⊆ E .

e3

e1 e2 e1 e2
e7 e8
e3

e6
e5 e5
e7 e8 e7 e8

Figure: Not a spanning


e6 e6
Subgraph of G
Figure: Graph G Figure: Spanning Subgraph of
G

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 24 / 43
Induced Subgraphs

Let G = (V , E ) be any graph, and let S ⊂ V be any subset of vertices of G. Then the
induced subgraph G ′ = (S, E ′ ), E ′ ⊆ E , is the graph whose vertex set is S and whose
edge set consists of all of the edges in E that have both endpoints in S. That is, for any
two vertices u, v ∈ S, u and v are adjacent in G ′ if and only if they are adjacent in G.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 25 / 43
Induced Subgraphs

Let G = (V , E ) be any graph, and let S ⊂ V be any subset of vertices of G. Then the
induced subgraph G ′ = (S, E ′ ), E ′ ⊆ E , is the graph whose vertex set is S and whose
edge set consists of all of the edges in E that have both endpoints in S. That is, for any
two vertices u, v ∈ S, u and v are adjacent in G ′ if and only if they are adjacent in G.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 25 / 43
Induced Subgraphs

Let G = (V , E ) be any graph, and let S ⊂ V be any subset of vertices of G. Then the
induced subgraph G ′ = (S, E ′ ), E ′ ⊆ E , is the graph whose vertex set is S and whose
edge set consists of all of the edges in E that have both endpoints in S. That is, for any
two vertices u, v ∈ S, u and v are adjacent in G ′ if and only if they are adjacent in G.

v1 e1
v2

e2 e5 e4

v3 e3
v4

Figure: Graph G

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 25 / 43
Induced Subgraphs

Let G = (V , E ) be any graph, and let S ⊂ V be any subset of vertices of G. Then the
induced subgraph G ′ = (S, E ′ ), E ′ ⊆ E , is the graph whose vertex set is S and whose
edge set consists of all of the edges in E that have both endpoints in S. That is, for any
two vertices u, v ∈ S, u and v are adjacent in G ′ if and only if they are adjacent in G.

v1 e1
v2 v1 e1
v2

e2 e5 e4 e2 e5

v3 e3
v4 v3

Figure: Graph G Figure: G ′ is induce graph of G

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 25 / 43
Cyclic Graph

A cyclic graph is a graph containing at least one graph cycle. A graph that is not cyclic
is said to be acyclic.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 26 / 43
Cyclic Graph

A cyclic graph is a graph containing at least one graph cycle. A graph that is not cyclic
is said to be acyclic.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 26 / 43
Cyclic Graph

A cyclic graph is a graph containing at least one graph cycle. A graph that is not cyclic
is said to be acyclic.

v1 v5

e1 e2 e5 e7

v2 v3 v7

e3 e4 e6 e8

v4 v6

Figure: Cyclic graph

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 26 / 43
Cyclic Graph

A cyclic graph is a graph containing at least one graph cycle. A graph that is not cyclic
is said to be acyclic.

v1 v5 v1 v5

e1 e2 e5 e7 e2 e7

v2 v3 v7 v2 v3 v7

e3 e4 e6 e8 e3 e4 e6 e8

v4 v6 v4 v6

Figure: Cyclic graph Figure: Acyclic graph

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 26 / 43
Acyclic Graph

Consider a (undirected) graph G = (V , E ). A set S of edges in E is independent if it


contains no cycles, and dependent otherwise. In other words, a set of edges is independent
if the induced graph is acyclic.

5
https://mathworld.wolfram.com/MaximalSet.html
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 27 / 43
Acyclic Graph

Consider a (undirected) graph G = (V , E ). A set S of edges in E is independent if it


contains no cycles, and dependent otherwise. In other words, a set of edges is independent
if the induced graph is acyclic.
Every subset of an acyclic set of edges is acyclic.

5
https://mathworld.wolfram.com/MaximalSet.html
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 27 / 43
Acyclic Graph

Consider a (undirected) graph G = (V , E ). A set S of edges in E is independent if it


contains no cycles, and dependent otherwise. In other words, a set of edges is independent
if the induced graph is acyclic.
Every subset of an acyclic set of edges is acyclic.
If A and B are two sets of edges, both acyclic, and |A| < |B|, then some edge x ∈ B − A can
be added to produce an acyclic set, i.e., A ∪ {x } is acyclic.

5
https://mathworld.wolfram.com/MaximalSet.html
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 27 / 43
Acyclic Graph

Consider a (undirected) graph G = (V , E ). A set S of edges in E is independent if it


contains no cycles, and dependent otherwise. In other words, a set of edges is independent
if the induced graph is acyclic.
Every subset of an acyclic set of edges is acyclic.
If A and B are two sets of edges, both acyclic, and |A| < |B|, then some edge x ∈ B − A can
be added to produce an acyclic set, i.e., A ∪ {x } is acyclic.
If S is a subset of edges, then the maximal5 acyclic subsets of S are all equal in size.

5
https://mathworld.wolfram.com/MaximalSet.html
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 27 / 43
Graphic Matroid or Cycle Matroid

Definition 10
Consider a (undirected) graph G = (V , E ). Let S = E and I the collection of all edge sets each
of which induces an acyclic subgraph of G. Then MG = (S, I) is called Graphic Matroid.
If A ⊂ S, then A ∈ I if and only if A is acyclic. That is, a set of edges A is independent
if and only if the subgraph GA = (V , A) forms a forest.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 28 / 43
Graphic Matroid or Cycle Matroid

Definition 10
Consider a (undirected) graph G = (V , E ). Let S = E and I the collection of all edge sets each
of which induces an acyclic subgraph of G. Then MG = (S, I) is called Graphic Matroid.
If A ⊂ S, then A ∈ I if and only if A is acyclic. That is, a set of edges A is independent
if and only if the subgraph GA = (V , A) forms a forest.

Hereditary: If B ∈ I is an edge set which induces an acyclic subgraph of G, obviously


any A ⊂ B induces an acyclic subgraph, i.e., A ∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 28 / 43
Graphic Matroid or Cycle Matroid

Exchange Property: Suppose that GA = {V , A} and GB = {V , B} are forests of G and that


|A| < |B|. That is, A and B are acyclic sets of edges.
We claim that a forest F = {VF , EF } contains exactly |VF | − |EF | trees. Suppose F consists of t
trees, where the ith tree contains vi vertices and ei edges. Then, we have
t
X
|EF | = ei
i=1
Xt
= (vi − 1)
i=1
Xt
= vi − t
i=1
= |VF | − t

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 29 / 43
Graphic Matroid or Cycle Matroid

Exchange Property: Suppose that GA = {V , A} and GB = {V , B} are forests of G and that


|A| < |B|. That is, A and B are acyclic sets of edges.
We claim that a forest F = {VF , EF } contains exactly |VF | − |EF | trees. Suppose F consists of t
trees, where the ith tree contains vi vertices and ei edges. Then, we have
t
X
|EF | = ei
i=1
Xt
= (vi − 1)
i=1
Xt
= vi − t
i=1
= |VF | − t
That is t = |VF | − |EF |. Thus, forest GA contains |V | − |A| trees, and forest GB contains
|V | − |B| trees.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 29 / 43
Graphic Matroid or Cycle Matroid

Since forest GB has fewer trees than forest GA does, forest GB must contain some tree T
whose vertices are in two different trees in forest GA . That is B has an edge e connecting
two connected components of (V , A), which implies A ∪ {e} ∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 30 / 43
Graphic Matroid or Cycle Matroid

Given a matroid M = (S, I), we call an element x ̸∈ A an extension of A ∈ I if


A ∪ {x } ∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 31 / 43
Graphic Matroid or Cycle Matroid

Given a matroid M = (S, I), we call an element x ̸∈ A an extension of A ∈ I if


A ∪ {x } ∈ I.
For a graphic matroid MG = (S, I). If A is an independent set of edges, then edge e is an
extension of A if and only if e ̸∈ A and the addition of e to A does not create a cycle, i.e.,
A ∪ {e} ∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 31 / 43
Graphic Matroid or Cycle Matroid

Given a matroid M = (S, I), we call an element x ̸∈ A an extension of A ∈ I if


A ∪ {x } ∈ I.
For a graphic matroid MG = (S, I). If A is an independent set of edges, then edge e is an
extension of A if and only if e ̸∈ A and the addition of e to A does not create a cycle, i.e.,
A ∪ {e} ∈ I.
If A is an independent subset in a matroid M, we say that A is maximal if it has no
extensions. That is, A is maximal if it is not contained in any larger independent subset of
M.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 31 / 43
Graphic Matroid or Cycle Matroid

Theorem 11
All maximal independent subsets in a matroid have the same size.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 32 / 43
Graphic Matroid or Cycle Matroid

Theorem 11
All maximal independent subsets in a matroid have the same size.

Proof.
We will prove this theorem by contradiction.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 32 / 43
Graphic Matroid or Cycle Matroid

Theorem 11
All maximal independent subsets in a matroid have the same size.

Proof.
We will prove this theorem by contradiction.
Suppose to the contrary that A is a maximal independent subset of M and there exists
another larger maximal independent subset B of M.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 32 / 43
Graphic Matroid or Cycle Matroid

Theorem 11
All maximal independent subsets in a matroid have the same size.

Proof.
We will prove this theorem by contradiction.
Suppose to the contrary that A is a maximal independent subset of M and there exists
another larger maximal independent subset B of M.
By the exchange property implies that for some x ∈ B − A, we can extend A to a larger
independent set A ∪ {x }, contradicting the assumption that A is maximal.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 32 / 43
Graphic Matroid or Cycle Matroid

Consider a graphic matroid MG = (S, I) for a connected, undirected graph G = (V , E ), where


S = E . Every maximal independent subset of MG must be a free tree with exactly |V | − 1
edges that connects all the vertices of G. Such a tree is called a spanning tree of G.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 33 / 43
Graphic Matroid or Cycle Matroid

Consider a graphic matroid MG = (S, I) for a connected, undirected graph G = (V , E ), where


S = E . Every maximal independent subset of MG must be a free tree with exactly |V | − 1
edges that connects all the vertices of G. Such a tree is called a spanning tree of G.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 33 / 43
Graphic Matroid or Cycle Matroid

Consider a graphic matroid MG = (S, I) for a connected, undirected graph G = (V , E ), where


S = E . Every maximal independent subset of MG must be a free tree with exactly |V | − 1
edges that connects all the vertices of G. Such a tree is called a spanning tree of G.

Definition 12 (Weighted Matroid)


A matroid M = (S, I) is weighted if it is associated with a weight function w : S → R+ for that assigns
a strictly positive weight w (x ) to each element x ∈ S. The weight function w extends to subsets of S
by summation: X
w (A) = w (x )
x ∈A

for any A ⊆ S.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 33 / 43
Graphic Matroid or Cycle Matroid

Consider a graphic matroid MG = (S, I) for a connected, undirected graph G = (V , E ), where


S = E . Every maximal independent subset of MG must be a free tree with exactly |V | − 1
edges that connects all the vertices of G. Such a tree is called a spanning tree of G.

Definition 12 (Weighted Matroid)


A matroid M = (S, I) is weighted if it is associated with a weight function w : S → R+ for that assigns
a strictly positive weight w (x ) to each element x ∈ S. The weight function w extends to subsets of S
by summation: X
w (A) = w (x )
x ∈A

for any A ⊆ S.

For example, if we let w (e) denote the weight of an edge e in a graphic matroid MG , then w (A) is
the total weight of the edges in edge set A.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 33 / 43
Greedy algorithms on a weighted matroid

Many problems for which a greedy approach provides optimal solutions can be formulated
in terms of finding a maximum-weight maximal independent subset in a weighted
matroid. That is, we are given a weighted matroid M = (S, I), and we wish to find an
independent set A ∈ I such that w (A) is maximized.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 34 / 43
Greedy algorithms on a weighted matroid

Many problems for which a greedy approach provides optimal solutions can be formulated
in terms of finding a maximum-weight maximal independent subset in a weighted
matroid. That is, we are given a weighted matroid M = (S, I), and we wish to find an
independent set A ∈ I such that w (A) is maximized.
Such a subset that is independent and has maximum possible weight called optimal
subset of the matroid. Because the weight w (x ) of any element x ∈ S is positive, an
optimal subset is always a maximal independent subset - it always helps to make A as
large as possible.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 34 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )
1 A := ϕ

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )
1 A := ϕ
2 Assume that |S| = n
3 Sort the elements of S into monotonically decreasing order by w . Assume that the
ordering is x1 , x2 , · · · , xn

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )
1 A := ϕ
2 Assume that |S| = n
3 Sort the elements of S into monotonically decreasing order by w . Assume that the
ordering is x1 , x2 , · · · , xn
4 for i ← 1 to n do

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )
1 A := ϕ
2 Assume that |S| = n
3 Sort the elements of S into monotonically decreasing order by w . Assume that the
ordering is x1 , x2 , · · · , xn
4 for i ← 1 to n do
5 if (A ∪ {xi } ∈ I) then

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Algorithm: GREEDY(M, w )
1 A := ϕ
2 Assume that |S| = n
3 Sort the elements of S into monotonically decreasing order by w . Assume that the
ordering is x1 , x2 , · · · , xn
4 for i ← 1 to n do
5 if (A ∪ {xi } ∈ I) then
6 A := A ∪ {xi }
7 end
8 end
9 Return(A)

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 35 / 43
Greedy algorithms on a weighted matroid

Let |S| = n. Line 3 (sorting) takes time O(nlogn).

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 36 / 43
Greedy algorithms on a weighted matroid

Let |S| = n. Line 3 (sorting) takes time O(nlogn).


Line 4 executes exactly n times, once for each element of S. Each execution of line 4
requires a check on whether or not the set A ∪ {xi } ∈ I is independent. If each such
check takes time O(f (n)), the entire algorithm runs in time O(nlogn) + O(f (n)).

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 36 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .
In the jth iteration, we checked whether Aj = Aj−1 ∪ {xj } ∈ I?

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .
In the jth iteration, we checked whether Aj = Aj−1 ∪ {xj } ∈ I?
Since xj ∈ C − An , xj ̸∈ An . Hence we must found that Aj−1 ∪ {xj } ̸∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .
In the jth iteration, we checked whether Aj = Aj−1 ∪ {xj } ∈ I?
Since xj ∈ C − An , xj ̸∈ An . Hence we must found that Aj−1 ∪ {xj } ̸∈ I.
But Aj−1 ∪ {xj } ⊂ C

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .
In the jth iteration, we checked whether Aj = Aj−1 ∪ {xj } ∈ I?
Since xj ∈ C − An , xj ̸∈ An . Hence we must found that Aj−1 ∪ {xj } ̸∈ I.
But Aj−1 ∪ {xj } ⊂ C
Due to the Set exchange property of M, Aj−1 ∪ {xj } ∈ I. So we arrived at a contradic-
tion.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 1
An (final output) is a maximal independent set.

Proof.
Let An is not a maximal independent set of the matroid M = (S, I).
Then there exists a C ∈ I, such that An ⊂ C and there must some xj ∈ C − An .
Here Aj−1 = {xi ∈ An : i < j} ⊂ An .
In the jth iteration, we checked whether Aj = Aj−1 ∪ {xj } ∈ I?
Since xj ∈ C − An , xj ̸∈ An . Hence we must found that Aj−1 ∪ {xj } ̸∈ I.
But Aj−1 ∪ {xj } ⊂ C
Due to the Set exchange property of M, Aj−1 ∪ {xj } ∈ I. So we arrived at a contradic-
tion.
Therefore A must be a maximal independent
Algorithms - Iset.
SK Hafizul Islam (Department of CSE, IIIT Kalyani) September 14, 19 & 21, 2022 37 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

Proof.
Let s > t. Let At−1 = {xi ∈ An : i < t}.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

Proof.
Let s > t. Let At−1 = {xi ∈ An : i < t}.
We know that At−1 ⊂ B. Because xt ∈ B, but xt ̸∈ At−1 .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

Proof.
Let s > t. Let At−1 = {xi ∈ An : i < t}.
We know that At−1 ⊂ B. Because xt ∈ B, but xt ̸∈ At−1 .
We must found that At−1 ∪ {xt } ̸∈ I.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

Proof.
Let s > t. Let At−1 = {xi ∈ An : i < t}.
We know that At−1 ⊂ B. Because xt ∈ B, but xt ̸∈ At−1 .
We must found that At−1 ∪ {xt } ̸∈ I.
But At−1 ⊂ B and xt ∈ B, therefore, At−1 ∪ {xt } ⊂ B.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 2
Let B (̸= An ) be another maximal independent set. Let s be the smallest index in An − B and
t be the smallest index in B − An . Then s < t.

Proof.
Let s > t. Let At−1 = {xi ∈ An : i < t}.
We know that At−1 ⊂ B. Because xt ∈ B, but xt ̸∈ At−1 .
We must found that At−1 ∪ {xt } ̸∈ I.
But At−1 ⊂ B and xt ∈ B, therefore, At−1 ∪ {xt } ⊂ B.
Based on hereditary property, At−1 ∪ {xt } ∈ I and we arrived at contradiction.
Therefore, s < t.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 38 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

Proof.
Assume that An is not a maximum weight maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

Proof.
Assume that An is not a maximum weight maximal independent set.
Let B1 , B2 , · · · , Br , r > 0 are all maximum weight maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

Proof.
Assume that An is not a maximum weight maximal independent set.
Let B1 , B2 , · · · , Br , r > 0 are all maximum weight maximal independent set.
From the Lemma 2, there exists smallest index si in An − Bi and another smallest index ti
in Bi − An such that si < ti holds for i = 1, 2, · · · , r .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

Proof.
Assume that An is not a maximum weight maximal independent set.
Let B1 , B2 , · · · , Br , r > 0 are all maximum weight maximal independent set.
From the Lemma 2, there exists smallest index si in An − Bi and another smallest index ti
in Bi − An such that si < ti holds for i = 1, 2, · · · , r .
Assume that s1 is the largest index among all si , and t1 is the largest index among all ti .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Lemma 3
Prove that An is a maximum weight maximal independent set.

Proof.
Assume that An is not a maximum weight maximal independent set.
Let B1 , B2 , · · · , Br , r > 0 are all maximum weight maximal independent set.
From the Lemma 2, there exists smallest index si in An − Bi and another smallest index ti
in Bi − An such that si < ti holds for i = 1, 2, · · · , r .
Assume that s1 is the largest index among all si , and t1 is the largest index among all ti .
We define B ′ = (B1 ∪ {xs1 }) − {xj }, where xs1 ∈ An − B1 , xt1 ∈ B1 − An and xj is some
element in B1 − An .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 39 / 43
Greedy algorithms on a weighted matroid

Proof.
Since j ≥ t1 > s1 . Therefore, w (xj ) ≤ w (xs1 ) ⇒ w (B ′ ) ≥ w (B).

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 40 / 43
Greedy algorithms on a weighted matroid

Proof.
Since j ≥ t1 > s1 . Therefore, w (xj ) ≤ w (xs1 ) ⇒ w (B ′ ) ≥ w (B).
Hence B ′ is a maximum weight maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 40 / 43
Greedy algorithms on a weighted matroid

Proof.
Since j ≥ t1 > s1 . Therefore, w (xj ) ≤ w (xs1 ) ⇒ w (B ′ ) ≥ w (B).
Hence B ′ is a maximum weight maximal independent set.
Since An − B ′ = An − B1 − {xs1 }. Thus, the smallest index in An − B ′ must be grater than
s1 .

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 40 / 43
Greedy algorithms on a weighted matroid

Proof.
Since j ≥ t1 > s1 . Therefore, w (xj ) ≤ w (xs1 ) ⇒ w (B ′ ) ≥ w (B).
Hence B ′ is a maximum weight maximal independent set.
Since An − B ′ = An − B1 − {xs1 }. Thus, the smallest index in An − B ′ must be grater than
s1 .
We found that B ′ = Bp for some i = p, so sp > s1 . Which is a contradiction. Therefore,
An is a maximum weight maximal independent set.

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 40 / 43
Suggested Readings

Chapter 16, Thomas H. Cormen, Charles E. Lieserson, Ronald L. Rivest and Clifford Stein,
Introduction to Algorithms, 3rd Edition, MIT Press/McGraw-Hill, 2009.
Chapter 04, E. Harowitz, S. Sahani, and S. Rajasekaran, Fundamentals of Computer
Algorithms, 2nd Edition, University Press, 2008.
Chapter 10, Michael T. Goodrich and Roberto Tamassia, Algorithm Design and Appli-
cations, Wiley, 2014.
https://www.youtube.com/watch?v=a5W3oQ8gdtw

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 41 / 43
Thank You

SK Hafizul Islam (Department of CSE, IIIT Kalyani) Algorithms - I September 14, 19 & 21, 2022 42 / 43

You might also like