(or Ranked Pairs) algorithm is widely considered the most difficult problem in CS50x.

The implementation involves the following functions:

A cycle occurs if:

The First Boss: sort_pairs

The goal here is to sort the pairs of candidates based on the strength of their victory. The stronger the win, the higher the rank.

  1. The candidate with the fewest first-place votes is eliminated.
  2. In the event of a tie, the candidate with the fewest second-place votes is eliminated, and so on.
  3. The process continues until a candidate has more than half of the first-place votes.

array. For each pair, call your cycle check before locking it in the adjacency matrix. lock_pairs( ; i < pair_count; i++)