Skip to content

Commit

Permalink
docs(readme): add complexity analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnamchoi committed Mar 21, 2024
1 parent 2ee10ea commit e5fee7a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ Run the Hare-Clark process
## Examples

For a practical example of the library being applied, see [example/README.md](example/README.md)

## Complexity analysis

* Let $v$, $b$, and $c$ be the number of vacancies, ballots, and candidates respectively.
* `HareClark()` uses $O(1)$ time as it only has a single variable assignment
* `add_candidates()` uses $O(c)$ time as it has to insert each of the $c$ candidates to the private variable
* `add_ballots()` uses $O(bc)$ time as each ballot must have exactly $c$ values, and each of the $b$ ballots must be inserted to the private variable
* `run()` It takes $O(bc)$ time and auxilliary space for preprocessing and creating a copy of the private variables. It will then take $O(bb+bc)$ time to calculate the results. $O(bb)$ since there can be a maximum of $b$ loops which each go through each of the $b$ ballots, and an additional $O(bc)$ since there can be at most $bc$ `pop_back()` operations on the ballots. Note that it is not $O(bbc)$ despite there being $O(b)$ calls to an $O(bc)$ function (`process_candidate()`) as the `pop_back()` operations are amortized.

0 comments on commit e5fee7a

Please sign in to comment.