Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The D\'Hondt method is an algorithm that is used to allocate seats to parties in

ID: 3661734 • Letter: T

Question

The D'Hondt method is an algorithm that is used to allocate seats to parties in elections, based on their number of votes. In general, the number of seats for each party should be proportional to the number of votes received; however, achieving exact proportionality is often not possible. In the D'Hondt method, the seats are assigned to parties one by one, to the party has the highest quotient, q, given by q = V/s + 1. where V is the number of votes the party received and s is the number of seats assigned to the party so far. If two quotients of two parties are identical, the seat is assigned to the party with the highest number of votes, and we assume that no two parties have an identical number of votes.

Explanation / Answer

Good Wishes,

First let me give the function definition in MATLAB:

function seatsAllocated = dhondt( votes, seats )

N= length( votes );

for i = 1:N

seatsAllocated(i) = 0;

end

while( seats>0 )

maxq=0;

for j= 1:N

q= votes(j) / (seatsAllocated(j) + 1 );

if( maxq<q )

maxq= q;

pos= j;

end

elseif( maxq==q )

maxq= q;

if( votes(j) > votes(j-1) )

pos=j;

end

else

pos= j-1;

end

end

end

seatsAllocated(pos)= seatsAllocated(pos) + 1;

seats= seats - 1;

end

end

Explaination:

Initially the function takes the vector 'votes' and 'seats' as input parameters.

function seatsAllocated = dhondt( votes, seats )

First the length of the vector 'votes' is evaluated using length() function and is stored in 'N'

N= length( votes );

Then i created a vector called 'seatsAllocated' with length 'N' and all values intialized to zero.

for i = 1:N

seatsAllocated(i) = 0;

end

Then to for each seat that is to be allocated i ran a while loop

while( seats>0 )

Then for each party i calculated quotient value 'q'

  maxq=0;

for j= 1:N

q= votes(j) / (seatsAllocated(j) + 1 );

and checked to see whose 'q' value is the highest( stored in 'maxq' ) and then allocated the seat to that party, if two parties 'q' values are equal then the party with highest value of votes is allocated the seat, this done by incrementing the value in vector seatsAllocated of the respective party

if( maxq<q )

maxq= q;

pos= j;

end

elseif( maxq==q )

maxq= q;

if( votes(j) > votes(j-1) )

pos=j;

end

else

pos= j-1;

end

end

end

seatsAllocated(pos)= seatsAllocated(pos) + 1;

seats= seats - 1;

end

end

Finally the vectot seatsAllocated contain the number of seats allocated to the respective parties.

Hope this is clear.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote