in Algorithms retagged by
2,234 views
2 votes
2 votes

There are n white dots and n black dots. Equally spaced in a line. You want to connect each white dot with some block dot in one to one fashion with a minimum total length of wire.
Consider 2 examples:

 

Greedy algorithm gives optimal solution for

  •  Only (i)

     

  • Only (ii)

     

  • Both (i) and (ii)

     

  • None of these
in Algorithms retagged by
2.2k views

4 Comments

Shubham

how (2,5)=3?

0
0

@srestha Its the path length between two dots i.e 2 and 5 .

1
1
ok , hanks :)
0
0

2 Answers

7 votes
7 votes
Best answer
Solve for optimal solution without changing the sequence given in 1 and 2.

For optimal, Leftmost black dot should be matched with the leftmost white dot.

Total length of wire for 1st case according to greedy will be

(1,3)=2

(2,5)=3

(4,6)=2

total length=2+3+2=7

Total Length of wire for 2nd case according to greedy will be

(1,3)=2

(2,4)=2

(5,7)=2

(6,8)=2

total length=2+2+2+2=8

So 1st gives optimal.
selected by

1 comment

sir,why we don't connect (7,8) in fig(i) plzz answer on this??
0
0
1 vote
1 vote

Related questions