-1

I was asked this question on an interview. Can someone give me some insight on how to do this? I was stumped

Often, greedy algorithms they are used as heuristics. An independent set in an undirected graph G is a set of nodes I so that no edge has both endpoints in I. In other words, if {u,v} included in set E, then either u not included in set I or v not included in set I. The maximum independent set problem is , given G, nd an independent set of the largest possible size.

Implement a greedy algorithm for maximum independent set based on including nodes of smallest degree.

user3602193
  • 11
  • 1
  • 1
  • 3

2 Answers2

2

Your greedy strategy based on nodes degree can be the following:

I := resulting set
V := set of unused vertices, initially all vertices

while V not empty:
   v := vertex in V with smallest degree
   I.add(v)
   for each u adjacent to v:
      V.remove(u)

return I

The strategy is greedy, because a single decision depends only on the local situation.

pkacprzak
  • 5,537
  • 1
  • 17
  • 37
  • 1
    I just wanted to post a similar algorithm (in english languag not in pseudo code). The only difference is that I would decrease the "degree" of all nodes that are adjacent to a node that is removed. If I have a node that is adjacent to nodes that are already removed it will be selected as the next node in the result set I and not a node that is adjacent to some "vivid" nodes – miracle173 May 04 '14 at 21:20
0

The greedy algorithm selects the elements of the probably maximum independent set S step by step. After each step the set of vertices of the graph G is partitioned in three sets:

  • the set S of vertices selected so far
  • the set A of vertices that are adjacent to the vertices of S and therefore cannot be selected for the set S in future steps
  • the set R of remaining vertices that are neither in S nor in A.

In the next step one of the vertices v of R can be removed from R and added to the set S. All vertices adjacent to v must be removed from R, too, and added to A (if they are not already members of A). But which v from R should the greedy algorithm select? It should choose a vertex v from R such that the next R ( := current R \ ({v} union {vertices adjacent to v}) ) is as large as possible.

We define G[R] as the subgraph of G induced by R, this is the subgraph of G with vertices R and all edges of G that have their vertices in R. Then v should be a vertex with minimal degree in G[R] but not necessarily the vertex with minimal degree in G.

miracle173
  • 1,852
  • 16
  • 33