<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Indistinguishable from Jesse &#187; Computational Complexity</title>
	<atom:link href="http://www.squarefree.com/categories/computational-complexity/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.squarefree.com</link>
	<description>Jesse Ruderman on Firefox, security, and more</description>
	<lastBuildDate>Tue, 05 Jun 2012 15:53:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Winning an election with 22% of the popular vote</title>
		<link>http://www.squarefree.com/2004/11/01/winning-an-election-with-22-of-the-popular-vote/</link>
		<comments>http://www.squarefree.com/2004/11/01/winning-an-election-with-22-of-the-popular-vote/#comments</comments>
		<pubDate>Mon, 01 Nov 2004 14:57:58 +0000</pubDate>
		<dc:creator>Jesse Ruderman</dc:creator>
				<category><![CDATA[Computational Complexity]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Politics]]></category>

		<guid isPermaLink="false">http://www.squarefree.com/test/wp15/wordpress/?p=192</guid>
		<description><![CDATA[A presidential candidate could be elected with as a little as 21.8% of the popular vote by getting just over 50% of the votes in DC and each of 39 small states. This is true even when everyone votes and there are only two candidates. In other words, a candidate could lose with 78.2% of [...]]]></description>
				<content:encoded><![CDATA[<p>A presidential candidate could be elected with as a little as 21.8% of the popular vote by getting just over 50% of the votes in DC and each of 39 small states.  This is true even when everyone votes and there are only two candidates.  In other words, a candidate could lose with 78.2% of the popular vote by getting just under 50% in small states and 100% in large states.</p>

<p>The optimal set of states to take (the one that lets a candidate win with the smallest popular vote) is not the N states with the smallest population.  It's also not the N states with the smallest value for (population/electors), which would be optimal if you could get exactly 270 electoral votes that way.</p>

<p>The optimal solution happens to get exactly 270 electoral votes.  In this solution, the winner takes DC, the 37 smallest states, the 39th smallest state, and the 40th smallest state.  (The winner takes Alabama, Alaska, Arizona, Arkansas, Colorado, Connecticut, Delaware, DC, Hawaii, Idaho, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, New Mexico, North Carolina, North  Dakota, Oklahoma, Oregon, Rhode Island, South Carolina, South Dakota, Tennessee, Utah, Vermont, Virginia, Washington, West Virginia, Wisconsin, and Wyoming.)</p>

<p>Read on for my assumptions and algorithm.</p>
<span id="more-192"></span>
<h3>Assumptions</h3>

<p>I made two simplifying assumptions.  First, I assumed that the entire population of each state can vote.  Second, I assumed that all states were winner-take-all.  Maine and Nebraska are not, but I think I can justify this assumption: it would be "wasteful" to take one congressional district of Maine without taking the other districts and at-large votes.</p>

<p>I used <a href="http://www.census.gov/population/cen2000/tab01.txt">apportionment data from the 2000 census</a> for populations and numbers of electoral votes.  The 2000 census controls electoral vote apportionment for 2004 and 2008.  Since that data didn't include the population of DC, I got the population of DC from <a href="http://www.census.gov/population/cen2000/tab05.txt">another source</a>, which was also connected to the 2000 census but which used different criteria to determine whether a person counted as part of the population of a state.</p>

<h3>Algorithm</h3>

<p>To come up with an algorithm to solve the problem, I first thought about how the Electoral College problem would generalize:</p>

<ul>
<li>Instance: populations[], electors[], goal.  (Population needed to win each state, electoral college vote of each state, number of electoral votes I need to win.)</li>
<li>Solution: W, a set of states.  (States that I win.)</li>
<li>Constraint: (sum over W of electors[]) &gt;= g.  (I win the election.)</li>
<li>Objective: minimize (sum over W of populations[]).  (I win the election with the minimum popuplar vote.)</li>
</ul>

<p>I noticed that the problem looked similar to Subset Sum, an NP-complete problem, so I thought about possible exponential-time algorithms:</p>

<ul>
<li>Brute force, trying every possible W.  This would take 2<sup>51</sup> for 50 states plus DC.</li>
<li>Backtracking (adding states to W until goal is reached).  This would take at least 2<sup>37</sup>, since you can have the 37 smallest states and still need more electoral votes to win.</li>
<li>Backtracking, taking advantage of the fact that several states have the same number of electoral votes.  Sort the states by electoral votes and then by population.  If we didn't add Wyoming (smallest state with exactly 3 electoral votes), we won't add any other states with exactly 3 electoral votes.  Significantly faster than simple backtracking; might be fast enough.</li>
</ul>

<p>I looked up Subset Sum in <a href="http://fortnow.com/lance/complog/2002/08/great-books-computers-and.html">Garey and Johnson</a> to see which exponential-time algorithm they recommended for Subset Sum.  To my surprise, I found a fast dynamic programming algorithm.  The algorithm is "pseudo-polynomial" -- its running time is a polynomial in the size of the input and the integer values represented by the input.  The algorithm is only exponential because an integer can be represented using a number of bits equal to a log of its value.  If the numbers are small, the dynamic programming algorithm is fast.</p>

<p>Once this algorithm is modified to apply to the Electoral College problem, it computes a two-dimensional table containing the minimum population needed for every exactly j electoral votes using only the first i states.  Each cell of the table can be computed quickly by considering two cases, either the candidate wins state i, getting elec<sub>i</sub> electoral votes for pop<sub>i</sub>/2, or doesn't:  minpop<sub>i,j</sub> = min(minpop<sub>i-1,j-elec<sub>i</sub></sub> + pop<sub>i</sub>/2, minpop<sub>i-1,j</sub>).  The algorithm runs in O(states * electors) time.  It is nice that the running time depends on the numbers of electors, not the populations.</p>

<p>I implemented the dynamic programming algorithm in <a href="http://www.squarefree.com/electoral-college.js.txt">ugly JavaScript</a>.  The JavaScript requires the print() function provided by my <a href="http://www.squarefree.com/jsenv/">minimal JavaScript environment</a>.  On my computer, it takes about 3 seconds in IE or 1 second in Firefox.</p>

<h3>Related work</h3>

<p>After getting the answer of 21.8%, I searched Google for variations on "22% of the popular vote" and found <a href="http://www.hulver.com/scoop/story/2004/10/6/112537/693">several</a> <a href="http://www.amazingsyco.com/archives/2004/09/electoral_colle.html">people</a> who had have made similar calculations (some using approximate greedy algorithms, some using correct dynamic programming algorithms, all with different input data).</p>]]></content:encoded>
			<wfw:commentRss>http://www.squarefree.com/2004/11/01/winning-an-election-with-22-of-the-popular-vote/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Garey and Johnson</title>
		<link>http://www.squarefree.com/2004/07/31/garey-and-johnson/</link>
		<comments>http://www.squarefree.com/2004/07/31/garey-and-johnson/#comments</comments>
		<pubDate>Sun, 01 Aug 2004 02:30:00 +0000</pubDate>
		<dc:creator>Jesse Ruderman</dc:creator>
				<category><![CDATA[Computational Complexity]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Travel]]></category>

		<guid isPermaLink="false">http://www.squarefree.com/test/wp15/wordpress/?p=166</guid>
		<description><![CDATA[My copy of Garey and Johnson arrived the other day. I wonder if it will make good airplane reading while I'm heading to Mozilla Developer Day next week.]]></description>
				<content:encoded><![CDATA[<p>My copy of <a href="http://fortnow.com/lance/complog/2002/08/great-books-computers-and.html">Garey and Johnson</a> arrived the other day.  I wonder if it will make good airplane reading while I'm heading to <a href="http://www.mozilla.org/events/dev-day-2004/">Mozilla Developer Day</a> next week.</p>]]></content:encoded>
			<wfw:commentRss>http://www.squarefree.com/2004/07/31/garey-and-johnson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bagging</title>
		<link>http://www.squarefree.com/2003/09/01/bagging/</link>
		<comments>http://www.squarefree.com/2003/09/01/bagging/#comments</comments>
		<pubDate>Tue, 02 Sep 2003 01:04:48 +0000</pubDate>
		<dc:creator>Jesse Ruderman</dc:creator>
				<category><![CDATA[Computational Complexity]]></category>

		<guid isPermaLink="false">http://www.squarefree.com/test/wp15/wordpress/?p=20</guid>
		<description><![CDATA[I bought a textbook, some paper, and some binders at Huntley Bookstore today. I asked the guy at checkout to put my purchase in two bags of roughly equal weight. He thought this was a strange request and expressed uncertainty about his solution, but the bags felt balanced as I walked back to my dorm. [...]]]></description>
				<content:encoded><![CDATA[<p>I bought a textbook, some paper, and some binders at Huntley Bookstore today.  I asked the guy at checkout to put my purchase in two bags of roughly equal weight.  He thought this was a strange request and expressed uncertainty about his solution, but the bags felt balanced as I walked back to my dorm.</p>

<p>Only later did I realize my grave mistake: I had casually asked him to solve <a href="http://www.wikipedia.org/wiki/Subset_sum_problem">an NP-complete problem</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.squarefree.com/2003/09/01/bagging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
