# PSET3 Tideman - What to do with the lock_pairs function?

Can someone please help me with the lock_pairs section of the problem? The lock_pairs function is killing me. I get that you have to compare the pairs to each other and then return false or true in the locked array and that if a candidate is compared to himself/herself it should return false on that index of the locked array. Should preferences be used to check for the boolean values, like for example,

``````if (preferences[i][j] > preferences[j][i])
{
locked[i][j] = true;
}
``````

I'm not sure how to implement the whole lock_pairs function?

• You will not be using preference array to lock pairs. By this time you should have completed `pairs array(add_pairs function)`, which has all necessary winners & losers(as pair). Use that to methodically lock connections b/w pairs. Here's a good breakdown of that function: Lock pairs
– C--
Apr 11 at 17:40
• @user8570772 my pairs array is filled, just wasn't sure how to lock them. Will check out the link. Apr 11 at 18:34

Specification says that, The function should create the locked graph, adding all edges in decreasing order of victory strength so long as the edge would not create a cycle.

How are cycles created? Let's answer that first.

Cycles are created if there is at least one arrow pointed towards each candidate. Uhm, okay. It is easier said than done, right? How do we suppose to generalize this rule in practice then? This is where things get a lil tricky. For the sake of simplicity, let's try to illustrate a possible scenario:

• A wins over B
• B wins over C
• C wins over D
• D wins over A

You immediately spot the cycle there right? So by convention, if there is no cycle, we can say "once winner always winner!"

Now, all that being said, consider a function in which you are looping through all the pairs and trying to detect whether loser side of current pair was once a winner side of an earlier pair. Otherwise, locking them (`locked[winner][loser] = true`).

I am assuming that you have already completed the sort_pairs function. So, you don't need to bother with decreasing order part as long as you start your loop from `0` to `pair_count` since they are already sorted.