Tideman is a CS50 problem set that I have solved. The Tideman voting method (also known as “ranked pairs”) is a ranked-choice voting method that’s guaranteed to produce the Condorcet winner of the election if one exists. Generally speaking, the Tideman method works by constructing a “graph” of candidates, where an arrow (i.e. edge) from candidate A to candidate B indicates that candidate A wins against candidate B in a head-to-head matchup. The graph for the above election, then, would look like the below.
The arrow from Alice to Bob means that more voters prefer Alice to Bob (5 prefer Alice, 4 prefer Bob). Likewise, the other arrows mean that more voters prefer Alice to Charlie, and more voters prefer Charlie to Bob.
Looking at this graph, the Tideman method says the winner of the election should be the “source” of the graph (i.e. the candidate that has no arrow pointing at them). In this case, the source is Alice — Alice is the only one who has no arrow pointing at her, which means nobody is preferred head-to-head over Alice. Alice is thus declared the winner of the election.
To run Tideman in your IDE, first install the libraries used in this project. Or you can also use CS50.dev which is an CS50 Online IDE which contain all the libraries.
./tideman Alice Bob Charlie Number of voters: 5 Rank 1: Alice Rank 2: Charlie Rank 3: Bob
Rank 1: Alice Rank 2: Charlie Rank 3: Bob
Rank 1: Bob Rank 2: Charlie Rank 3: Alice
Rank 1: Bob Rank 2: Charlie Rank 3: Alice
Rank 1: Charlie Rank 2: Alice Rank 3: Bob
Charlie