What is a good algorithm for getting the minimum vertex cover of a tree?

后端 未结 7 649
感动是毒
感动是毒 2020-12-28 16:55

What is a good algorithm for getting the minimum vertex cover of a tree?

INPUT:

The node\'s neighbours.

OUTPUT:

The minimum number of vertice

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 17:16

    We can use a DFS based algorithm to solve this probelm:

    DFS(node x)
    {
    
        discovered[x] = true;
    
        /* Scan the Adjacency list for the node x*/
        while((y = getNextAdj() != NULL)
        {
    
            if(discovered[y] == false)
            {
    
                DFS(y);
    
               /* y is the child of node x*/
               /* If child is not selected as a vertex for minimum selected cover
                then select the parent */ 
               if(y->isSelected == false)
               {
                   x->isSelected = true;
               }
            }
       }
    }
    

    The leaf node will never be selected for the vertex cover.

提交回复
热议问题