edited by
6,142 views
31 votes
31 votes

An independent set in a graph is a subset of vertices such that no two vertices in the subset are connected by an edge. An incomplete scheme for a greedy algorithm to find a maximum independent set in a tree is given below:

V: Set of all vertices in the tree;	
I := ϕ
while	V ≠ ϕ do	
begin	
    select a vertex u ∊ V such that	
    _______;
    V := V - {u};	
    if u is such that	
    ________then I := I ∪ {u}	
end;	
Output(I);	
  1. Complete the algorithm by specifying the property of vertex $u$ in each case.

  2. What is the time complexity of the algorithm?

edited by

2 Answers

Best answer
10 votes
10 votes

Some points:

  1. An independent set of vertices of a graph is a set of vertices which do not have any edge in common
  2. A maximal independent set of a graph is an independent set to which no more vertex can be added. A graph can have multiple maximal independent sets
  3. A maximum independent set of a graph is the maximal independent set with maximum cardinality. A graph can have multiple maximum independent sets only when multiple maximal sets in it have the same maximum cardinality.

Reference: https://mathworld.wolfram.com/MaximumIndependentVertexSet.html

In the question we are asked to find the maximum independent set of a tree (a tree is a connected graph with no cycles). Finding the maximum independent set of a graph is an NP hard problem. But if the graph is restricted to a tree this problem not only becomes polynomial time solvable but can even be solved in linear time as shown here. The given algorithm in this question is using a greedy approach (not the optimal one). The greedy decision made here is to choose the vertex of minimum degree at any point. This greedy algorithm is guaranteed to work for trees and some other restricted class of graphs. 

  1. At each iteration we must select the vertex $u$ with the least degree
  2. $u$ is added to $I$ if there is no common edge between $u$ and any vertex in $I.$ For a single vertex this can take $O(|V|)$ time and hence for all the vertices this will take $O(|V|)^2$ time.

Complete algorithm is as follows:

V: Set of all vertices in the tree;	
I := ϕ
while	V ≠ ϕ do	
begin	
    select a vertex u ∊ V such that	
    degree(u) is minimum of all vertices in V
    V := V - {u};	
    if u is such that	
      no edge is common for u and any v ∊ I, then I := I ∪ {u}	
end;	
Output(I);
selected by
28 votes
28 votes
  1. While adding vertex $u$ to $I$ it should not have an edge with any node in $I$.
  2. The algorithm runs till $V$ is empty (in $O(n)$ time) and is checking $u$ with each vertex $v$ in set $I$ (in $O(n)$ time). So, overall complexity $O(n^2)$ where $n$ is the number of nodes in the tree.
edited by

Related questions

35.9k
views
12 answers
80 votes
Kathleen asked Oct 4, 2014
35,853 views
The number of distinct simple graphs with up to three nodes is$15$10$7$9$
8.2k
views
3 answers
20 votes
Kathleen asked Oct 4, 2014
8,189 views
The number of edges in a regular graph of degree $d$ and $n$ vertices is ____________
12.7k
views
3 answers
26 votes
Kathleen asked Oct 4, 2014
12,693 views
Consider the following heap (figure) in which blank regions are not in use and hatched region are in use.The sequence of requests for blocks of sizes ... fit but not best fit policybest fit but not first fit policyNone of the above
2.6k
views
1 answers
3 votes
gatecse asked May 3, 2021
2,568 views
State whether the following statements are True or False with reasons for your answer:A two pass assembler uses its machine opcode table in the first pass of assembly.