Fundamental Algorithms, Spring 1998
Assignment 9. Greedy Algorithms.
Given April 1, due Monday, April 13.
\tt int discord = 0; int M; individual person, friend; for ( int i = 0; i < N; i++) { person = people[i]; M = person.Nfriends; my_taste = person.taste for ( int j = 0; j < M; j++) { friend = person.friends[j]; their_taste = friend.taste; if ( my_taste != their_taste ) discord++; } }
We have the option to change the taste of k people and want to do so to lower the discord as much as possible. Design a greedy strategy to do this. Your strategy should change the taste of one person at a time, at each step switching the person who, at that stage, is creating the most discord. Does this strategy give the optimal switches?