graph - Time Complexity of modified dfs algorithm -
i want write algorithm finds optimal vertex cover of tree in linear time o(n), n number of vertices of tree.
a vertex cover of graph g=(v,e) subset w of v such every edge (a,b) in e, in w or b in w.
in vertex cover need have @ least 1 vertex each edge.
if pick non-leaf, can cover more 1 edge.
that's why thought can follows:
we visit root of tree, visit 1 of children, child of latter visited , on.
then if have reached @ leaf, check if have taken father optimal vertex cover, , if not pick it. then, if vertex picked optimal vertex cover has other children, pick first of them , visit leftmost children recursively , if reach @ leaf , father hasn't been chosen desired vertex cover, choose , on.
i have written following algorithm:
dfs(node x){ discovered[x]=1; each (v in adj(x)){ if discovered[v]==0{ dfs(v); if (v->taken==0){ x<-taken=1; } } } }
i thought time complexity
(|v_i|, |e_i| number of vertices , edges respectively of subtrees @ root of call dfs )
is time complexity found right? or have calculated wrong?
edit: complexity of algorithm described recurrence relation:
t(|v|)=e*t(|v|-1)+o(1)
? or wrong?
Comments
Post a Comment