Skip to content

M-Aqib-02/Tideman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Tideman

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.

condorcet_graph_1

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.

Running Tideman

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.

Your program should behave per the example below:

./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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages