<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amy Hua on Medium]]></title>
        <description><![CDATA[Stories by Amy Hua on Medium]]></description>
        <link>https://medium.com/@amyhuajs?source=rss-ebee3176b755------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AuBUCIsd3mhcpaljoaHVzw.jpeg</url>
            <title>Stories by Amy Hua on Medium</title>
            <link>https://medium.com/@amyhuajs?source=rss-ebee3176b755------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:39:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amyhuajs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A closer (and clearer) look at the US stats on Coronavirus COVID-19 (“hindsight is 20/20”)]]></title>
            <link>https://medium.com/@amyhuajs/a-closer-and-clearer-look-at-the-us-stats-on-coronavirus-covid-19-hindsight-is-20-20-d39314df2794?source=rss-ebee3176b755------2</link>
            <guid isPermaLink="false">https://medium.com/p/d39314df2794</guid>
            <category><![CDATA[coronavirus]]></category>
            <category><![CDATA[2020]]></category>
            <category><![CDATA[pandemic]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Amy Hua]]></dc:creator>
            <pubDate>Thu, 26 Mar 2020 05:35:23 GMT</pubDate>
            <atom:updated>2020-03-26T18:11:45.716Z</atom:updated>
            <content:encoded><![CDATA[<p>In this rapidly developing pandemic, I’d like to focus on some views of the growth rates of COVID-19 that are more important, in my view, than the data views I have seen shared so far.</p><p>Most stats on COVID-19 currently are focused on reporting their daily increase rate. Scattered news articles across various published dates describe the current confirmed case count of the day but do not raise awareness on overall growth trends. The clearest overall time charts I have seen on the Coronavirus growth rates in the US come from the <a href="https://www.nytimes.com/interactive/2020/world/coronavirus-maps.html?te=1&amp;nl=morning-briefing&amp;emc=edit_NN_p_20200305&amp;section=topNews&amp;campaign_id=9&amp;instance_id=16495&amp;segment_id=21886&amp;user_id=98a075da0a19b8e645ccac88c34dca54&amp;regi_id=107708951tion=topNews">NYTimes Live Tracking site</a> and this vigilantly updated Wikipedia article for the <a href="https://en.wikipedia.org/wiki/2020_coronavirus_pandemic_in_the_United_States">2020 coronavirus epidemic in the United States</a>.</p><p>However, daily growth rates are too minuscule for human minds to comprehend: we tend not to be able to make decisions on the daily interval, but we prepare based on our multiday, weekly, or multiweekly forecasts of the future instead. Moreover, mentally grasping that a <strong>daily</strong> multiplying rate of <strong>20%</strong> is a five-day multiplying rate of <strong>149%</strong> every 5 days is asking a lot out of people.</p><p>These daily-based data views do not do justice towards empowering our ability to act on the data: most things take at least a week or 2, or sometimes a month or more, to accomplish. So why are we looking at data about daily growth rates, at all? We should instead, be looking at what may happen in meaningful time frames that we actually plan and prepare for.</p><p>You don’t want to visit the grocery store every 1–2 days, do you? You generally want to buy food and essentials for at least 3 to 7 days at a time instead…</p><p>So to help us better make decisions about how to prepare for this pandemic, with statistics that empower us, let us take a look at some Coronavirus hindsights over multi-day time periods.</p><h3>Let’s begin</h3><p>What if we could have predicted the future 2 days from now? What about 7 days from now, or even a few weeks at a time?</p><p>While we cannot predict the future, we can take a look at the past as one of many signals we can review on what is likely to come in the future. While I am no statistician, and certainly there are many cases where looking at the past does <em>not</em> predict the future, I’d like us to instead focus on our decision making mindset, and what we could have or would have done, if we knew what was to come, 5 or 14 days later.</p><p>So let’s now take a look at the daily data on all past confirmed cases of COVID-19 in the United States.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0vImLkQzLWcl8Y3FIIccQ.png" /><figcaption><a href="https://docs.google.com/spreadsheets/d/1YbZ3bzA6ZCuWurNAOvVDpPB1mVjxF_Fpbeb3aKYUtWQ/edit#gid=2031461274">The full spreadsheet</a> used for analysis</figcaption></figure><p>My source is based on counts taken from the <a href="https://en.wikipedia.org/wiki/2020_coronavirus_pandemic_in_the_United_States">Wikipedia article on the 2020 coronavirus pandemic in the United States</a>, and <a href="https://docs.google.com/spreadsheets/d/1YbZ3bzA6ZCuWurNAOvVDpPB1mVjxF_Fpbeb3aKYUtWQ/edit#gid=2031461274">here is the full spreadsheet</a>, transparently showing all the formulas I used for deriving my analysis below, so you can freely check my methods and can help correct any flaws you may see int he comments below. :)</p><p>There is a curious period from Feb 2nd to the 14th where the confirmed case count barely moves. In fact, the confirmed case count does not shift more than <strong>10–20% every 5 days,</strong> from Feb 2nd to Feb 22nd, during this long 20 day period. However, from Feb 25th onward (exactly a month ago), the confirmed case count will continually shift <strong>300%+ or multiply by 3x every 5 days,</strong> for the next month (where March 25th marks today’s date). Recently, even, the 5-day increase rate is between 4x to 6x every 5 days. We are likely simply better at testing and being tested since 2/25. So let’s ignore all data prior to 2/25, for making today-based decisions about the actual and current coronavirus growth and infection rates.</p><p>So if you take the nationwide statistics, and look at the number of coronavirus cases in your local county, town, or state, it can be reasonably said that it will likely 3–6x that number 5 days from now, just based on historical data over the past month; albeit, this is not a big time period, but, that has been the case over the past month.</p><p>Okay, you may think, 4–6x every 5 days. Not bad for my [low case count state/county]. But that’s only in 5 days. What about in 14 days?</p><p>Let’s take a look at the data. The numbers are rattling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UL2EXSq5UQg7cSPawjd7KQ.png" /></figure><p>A 3-day <strong>2.5x-er</strong> on March 9th becomes a <strong>66x-er</strong>, 14 days later.</p><p>That means that when the nation’s confirmed case count was</p><p><strong>645</strong> on 3/9</p><p>and became</p><p>1598 (or <strong>2.5x</strong>) 3 days later on 03/12</p><p>it was then going to become</p><p><strong>42,749</strong> (or <strong>66.3x</strong>), 2 weeks later on 03/23.</p><p>And so, <strong>645 → 42,749 in 2 weeks.</strong> This is hard to comprehend, but that is the nature of the compounding rate of growth of this virus.</p><p>What is the timeframe that most policymakers need to act? Well, if a military hospital ship is going to take 2 weeks or so to arrive in New York City, then 2 weeks or so is about the timeframe we should likely be planning for right now.</p><p>The 2-week time frame hovers above 25x, and lately, between 65–117x, the current count.</p><p>Let’s think about what we were doing 2 weeks ago, when the count was <strong>not 64,661, but 1,205, </strong>what we would have done then, and what we should be doing, 2 weeks from <em>today</em>.</p><p><a href="https://www.newsweek.com/coronavirus-fauci-many-millions-response-us-mitigation-1491780">The experts have been screaming lately for aggressive and prompt action</a> on the policy level, since at least when the count was just 1,205 on 03/11 (the date the linked article was published). Hopefully clearer views of the data will help open some eyes, based on planning intervals that actually matter.</p><p>In summary, over the entire USA, looking at data since 2/25,</p><ul><li>The average <strong>5-day</strong> confirmed case count multiplier since 2/25 has been<br><strong>4.8x every 5 days </strong>over the past month. (2/25–3/20)<br>(See spreadsheet cell N94 for the calculation)</li><li>The <strong>7-day</strong> average is <strong>9.2x every 7 days </strong>(2/25–3/18)</li><li>The <strong>14-day</strong> average is <strong>76.9x every 14 days</strong> (2/25–3/11)</li><li>The <strong>21-day</strong> average is <strong>708x every 21 days</strong> (2/25–3/4)</li><li>The x-ers quickly become meaningless, as the 28-day average becomes <strong>~4037x after 28 days</strong>, based on just the days 02/25 and 02/26, and what happens 28 days later.</li></ul><p>There is, of course, enormous geographic diversity in the data to consider. Notably, New York has 15x or so more cases than anywhere else in the US.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-TNthf0LJb1Uy56ChklCQ.png" /><figcaption>Source: <a href="https://www.nytimes.com/interactive/2020/world/coronavirus-maps.html?te=1&amp;nl=morning-briefing&amp;emc=edit_NN_p_20200305&amp;section=topNews&amp;campaign_id=9&amp;instance_id=16495&amp;segment_id=21886&amp;user_id=98a075da0a19b8e645ccac88c34dca54&amp;regi_id=107708951tion=topNews">NYTimes Live Coronavirus Map</a> captured as of date of writing</figcaption></figure><p>Certainly, this virus will reel its head in clusters across the United States, and at even faster rates than I calculated, since I have only been counting confirmed cases, and confirmed cases are usually those of the most severe symptoms.</p><h4>Why?</h4><p>Let’s take a step back and look at a few possible reasons why the spread of COVID-19 is so rapid, and is rather inconceivably dozens to hundreds of time more rapid-spreading, infectious, and deadlier than the flu.</p><p>First, we can put to bed the argument that COVID-19 is no deadlier than [tuberculosis / insert other death-causing illness here], considering its eventual and not-so-distant trajectory. We won’t be saying this very soon in even the next 2 weeks to follow.</p><ul><li>The <strong>main characterization of a coronavirus</strong> from a non-coronavirus virus is based on <em>the spreadability</em> of the pathogen itself, from animals as genetically diverse as bats, to humans. No joke, that’s its main evolutionary advantage, and is how and why we call it a coronavirus.</li><li>Let’s recall some old high school biology: viruses lay somewhere between the living and the dead. Outside of a host cell, no virus cannot function, and viruses don’t really “live”. They are parasitic pathogens that can lay dormant and dead outside of a host cell for years or longer, “reviving” itself when it is able to attach to a host cell, so they can exist for a long time outside of a body. And also, because of their simple nature, antibiotics have no effect on a virus.</li><li>COVID-19 is very small, over twice as smaller as even small bacteria, standing at ~0.1-0.125 microns in size, comparable to SARs, another coronavirus. Most air filters and even the N95 face masks are rated at catching particles 0.3 microns or larger.</li></ul><p>These are some, but not all, of the reasons why the US Department of Health and Human Services predicts the pandemic lasting for <a href="https://www.nytimes.com/2020/03/17/us/politics/trump-coronavirus-plan.html"><strong>18 months or longer</strong></a>.</p><p>So long as casual inter-state travel is still allowed, spread via commonly trafficked between states will continue.</p><p>If, say, <strong>4</strong> infected people travel from New York City to San Francisco one day, then — looking at historical insights, back when the <em>national</em> case count jumped +4 in a day from 15 to 19 on 2/28 across the whole United States (let alone within a given city where likelihood of contact and infection from person-to-person is much higher), then those <strong>4</strong> travelers will go on infecting at least 13 <em>other</em> people, <em>each, </em>within 7 days, or a total of 4 travelers x 13 others = <strong>52</strong> <em>more</em> people, as a result of their relocation to San Francisco. This is even assuming that the amount of social distancing we are currently doing is equivalent to the average amount of social distancing one infected patient does relative to another to-be infected patient <em>across the nation, </em>considering we are basing our predictions upon national, historical figures.</p><p>So the <strong>4</strong> infected becomes <strong>56</strong> infected after traveling, a mere <strong>7</strong> days later.</p><p>The 4 infected +will go on to indirectly infect <strong>1589 </strong>others for a total of 4x(113.8x 14-day multiplier based on 2/28 alone) or <strong>1593</strong> total, a mere <strong>14</strong> days later.</p><h4>How America may be affected 7–14 days from today</h4><p>The lack of stringent measures against travel will clearly result in the failure of local and federal government to protect its people from the coronavirus. And the fact is, we have to act now, for <em>measures that will take 3 weeks or longe</em>r <em>to realize</em>, to actually prevent at all the eventual millions of infected cases we will see — strictly based on the average calculated multiplier from 02/25 onward, <strong>the additional 527,747 Americans</strong> or <strong>592,409 total Americans</strong> who will become infected <strong>in the next 7 days.</strong></p><p>Or, in another view of the average time period, the <strong>additional 4.91 million Americans</strong> who will be infected <strong>14 days</strong> from now (or a total of <strong>4.97 million total Americans </strong>14 days from now).</p><p>Read that twice: that’s almost 5 million Americans in the next 2 weeks, if we still let possibly infected people travel state to state, 100% domestically. This does not include any abroad threats at all.</p><p>Or, viewed over a 21-day averaged time period,<br> <strong>the 45.78 million total Americans</strong> who <strong>will be </strong>infected<strong> 21 days</strong> from now.</p><p>I hope this article convinces some of you to write more compelling narratives to your local policymakers to do the right thing in restricting all travel and take aggressive lockdown measures, not 2 weeks or even 1 week from now, but, <strong>now</strong>.</p><p>Considering the real multiday spread rates, we can see how certain measures different countries are taking — like the airports in Africa scanning travelers for symptoms before entering (like they were in early March), or the heat scans taken before letting travelers arrive in crowds — were entirely useless.</p><h3>What this could mean in determining the proper response.</h3><p>Now that we are looking at the data on real growth rates based on more sane planning time intervals, we can start to see more clearly the ineffectiveness of certain approaches towards containment, around the world.</p><p><strong>“Waiting to lock down” — when leaders borrow from the future.</strong></p><p>It can certainly make sense for a country to essentially “borrow from the future”, choosing not to shutter businesses now for a few more days , a week or several more weeks, rather than shutting things down <em>now</em>. The imagined devastation we can predict to developing and tourism-dependent economies, especially if it means starving people on the streets, is something worth saving innocent people from, like what Mayor De Blasio tried to do in keeping schools open to feed homeless kids in New York City <a href="https://www.usnews.com/news/education-news/articles/2020-03-14/bill-de-blasio-new-york-city-schools-to-stay-open-for-now">11 days ago</a> on 3/14, when it was 613 total confirmed cases versus the 33,066 and counting infected New Yorkers, today — a 50x multiplier in 11 days. Again, hindsight is 20/20. Certainly if De Blasio could have known that it would 50-x in 11 days time, he would have thought differently about the real growth rates of this virus and resulting lockdown impact. In many cases, borrowing from the future makes a lot of sense in policy-making,.. so long as the expected return exceeds the interest rate that you are borrowing at.</p><p>Now imagine not only travel-based business, itself a near trillion dollar market for NYC alone, but also inter-street local commerce closing in this 8.5 million person locale, and you’ve got a bigger problem than you ever could have accounted for when just looking at the travel-based economic impact.</p><p>Now that we have <em>some</em> signal on the multi-day growth rate of this virus — which from looking at national stats alone, is</p><p>9.2x in 7 days (N=23 days)<br>77x in 14 days (N=16)<br>708x in 21 days (N=9)</p><p>We can start to see the real borrowing rate from the future. While policymakers may be typically used to borrowing from the future at a metaphorical weekly compounding interest rate,of, say, ~10–20% by the next week (very aggressively speaking), they are definitely <em>not</em> used to borrowing from the future at an interest rate of 9200% by next week.</p><p>Imagine borrowing $1 today and having to pay back $9,200 for it by next week. Is that a good deal now?</p><p>That’s the real nature of the viral growth, which we must consider when deferring strict travel and movement bans for the sake of a few more days or weeks of growth. “Maybe it won’t happen to us” succumbs to the pitfalls of magical thinking, which if we take a week to flip back on, will be $9200 for every $1 too late for the average case, according to the national average.</p><h4>Why scanning for symptoms is pretty useless.</h4><p>Let’s consider 4 rather healthy travelers who had, so far, been asymptomatic, coronavirus carriers traveling across their neighborhood, county, state, country, etc. as if there is no lockdown or seriousness in the matter. As they travel, they get screened by certain airport staff or screeners checking for symptoms. They exhibit none. 7 days later, however, they start having symptoms of coughing; had they coughed earlier, these travelers likely would not have traveled. However, they had already spread the coronavirus freely in the meantime. If these 4 people had already infected <strong>56</strong> others by the time they became aware of the need to self-quarantine, then we can clearly see how such policies that check, or test, or restricting testing criteria for — strictly those who exhibit symptoms, are, well, rather flawed and useless, since 56 others will be already on the loose, undetected, carrying it, and uncontained.</p><p>It is like blocking a single port when the entire channel has already flooded over; completely, entirely, useless.</p><p>It should be clear that <a href="https://www.nytimes.com/2020/03/22/health/coronavirus-restrictions-us.html">certain harsh steps</a> and widespread lockdown measures should be taken that <em>anticipate</em> the widespread community transmission, well <em>before</em> it is documented, considering the average time window (in number of days) for a virus carrier to either report/get test results/prompt to self-quarantine, and the number of anticipated infected by then, running loose. That moving target is the bane of us, forever putting our medical and enforcement resources on a running treadmill.</p><h4>The economic impact: why $2 trillion in stimulus is a drop in the bucket.</h4><p>I will highly doubt if any $2 trillion dollar economic stimulus package is going to catch this runaway train. Speaking of which, let’s talk about the economy, since that is likely more concerning to some people than some viral pandemic.</p><p>The economic depression will continue for as long as people are in lockdown and are not allowed to move, particularly in large metropolises, in this world where <a href="https://www.mckinsey.com/featured-insights/urbanization/urban-world-mapping-the-economic-power-of-cities">600 cities around the world power 60% of <strong>global</strong><em> </em>GDP.</a> So long as big cities, like NYC and SF, are prompted by the viral spread to go into lockdown due to the coronavirus spread, <strong>so will the economy.</strong> No $2 trillion stimulus package is going to fix the continually increasing sinkhole created by the lack of people’s movement. Remember, as even <a href="https://www.cnbc.com/2019/04/12/amazons-jeff-bezos-most-us-sales-still-in-brick-and-mortar-stores.html">Amazon’s Jeff Bezos puts it</a>, that <strong>90% of all US retail sales are based offline</strong>, in person, in brick and mortar stores. <a href="https://tradingeconomics.com/united-states/retail-sales-annual">US retail sales comprise a roughly 4 to 5 trillion dollar market</a>.</p><p>There is a large portion of 90% not happening now, every day. As sales and revenues for many businesses freeze, and costs merely increase, day by day, because of labor costs (hence the rising unemployment and layoffs), capital, rent, and other ongoing costs, many businesses will try and wade this time period over with a depleting reservoir of cash, and you can bet on bailouts and ballooning debt.</p><p>Wiping clean even about ~27% of that 90% of US retail sales that would have occurred offline would amount to a $1 trillion drop if such sales continued and were averaged over a whole year.</p><p>If we want to save our future paychecks, then we should, as a collective whole, not be so focused on distributing “stimulus” paychecks, as if this is some typical economic recession; we should be focusing a grand portion of our resources on containing the spread of the virus itself.</p><p>And so I have to say that <a href="https://sports.yahoo.com/poll-half-americans-approve-trumps-180016558.html?src=rss">the half of all Americans currently approving of Trump’s responses to the Coronavirus </a>— from closing the US-Mexico border (yawn; note that all of my analysis is 100% inside the US borders), to giving us checks that are a fraction of what people could have earned in a month or so at their jobs — are just ill-informed about what will really, actually, make our economy become “great again”, in the context of a pandemic.</p><p>This point is too important for me to keep to myself, so please share this widely, and/or add color to my rudimentary analysis. All of my derived numbers are completely based on the <a href="https://docs.google.com/spreadsheets/d/1YbZ3bzA6ZCuWurNAOvVDpPB1mVjxF_Fpbeb3aKYUtWQ/edit#gid=2031461274">spreadsheet I referenced above</a> and can definitely be further refined, but this is a good start.</p><p>Hindsight, as they say, is 20/20. We have some hindsight already into what we could have possibly done before the cases became ~average 77x (1 infected person resulting in 76 other infected persons), 14 days later, across our country. It is time to take a good hard, real look at the reality, and remind ourselves of Benjamin Franklin’s insight:</p><h3>“An ounce of prevention is worth a pound of cure.”</h3><p>and remember also what Charlie Munger, Warren Buffet’s right hand man and one of the best investors in this world, has to add:</p><h3><strong>“An ounce of prevention is worth a <em>ton</em> of cure.”</strong></h3><p>This time will be a challenging time of realizing some basic math and the nature of compounding growth, and taking our own individual micro actions in helping to contain this pandemic. Literally as few as 1–4 infected travelers to another region, makes a huge difference, a few weeks later.</p><p>We all probably already know of or heard of people who have lost jobs around us due to the rippling effects of this pandemic on the economy. We don’t want to see our local movie theaters close, and see companies beg for bailouts and file for bankruptcy in these few weeks to come. Surely, what is out of sight (in the future) is generally out of mind, but in the case of a pandemic, it can be and will be an even starker reality to come.</p><p>Literally for the sake of us all, let’s all take the recommended actions and pressure our local governments and politicians, to, <em>finally,</em> lock down, <strong>locally</strong>, to do things that <em>matter </em>towards containment, and most of all <strong>enforce </strong>lockdown aggressively, to fool-proof against the portion of youth who will inevitably never fear death and haven’t yet gotten all the facts yet. After all, this is happening so quickly day by day, 1 week to the next, and many of the youth do not even read the news.</p><p>The experts are already recommending the proper actions to take, so what we ought to do is not unknown; it is <strong>hesitancy in swift leadership across all local government</strong> boards that is causing the most issues with containment. I talk about the necessary speed of local government action to produce real containment outcomes, in the section below on <em>Borrowing from the Future.</em></p><p>Since we cannot depend on top-level leadership that focuses <em>so much</em> — to a great degree of false comfort — on stopping the virus from spreading from abroad (achem, Trump), to actually help us stop its spread locally <em>within</em> our borders, it is time for citizens to speak up with their local governments, where they already have the most leverage and most ear to the ground from their local politicians, anyways, about the need for aggressive action and lockdown, just as the experts are decrying, in cities and countries with low confirmed case count that are <em>still</em> not taking lockdown seriously.</p><p>An ounce of lockdown will be worth a ton in non-coronavirus-related economic depression. Some of our local politicians will not be as particularly good with math or the numbers, and will take longer to swallow this pill of exponential growth — or they will understand some of it, but never conceive of <strong>the roughly 700x-er this beast has been over a 28 day time period </strong>(that is 699 new infected patients <em>per 1 infected newcoming traveler </em>28 days later, and growing, of course; based on just the 2 data points, 2/25–2/26 over the observable time period since 2/25, but is irregardless better insight than the nothing so far).</p><p>For those with friends in other countries, it would be best to inform them of the seriousness, and to have them try to pressure their leaders to take travel bands and lockdowns, more seriously. So that leaders do not simply wait until Phase 1 becomes Phase 2, to do something about the Coronavirus travelers they are letting into their countries. Because remember, there will always be the people traveling around who do not fear death, regardless of what you tell them. So some lockdown actual enforcement <em>is</em> required, regardless of the local cultures of precaution or “strong recommendations” from local leaders.</p><h4>Addendum: On Borrowing from the Future (the country-wide games of tag)</h4><p>Imagine playing a game of tag, where the person who is “it” has to tag everyone else to win. If the number of people you need to tag grows by a fast enough increase rate, you’ll never catch them all, and the “curve” will not flatten.</p><p>There are certain viral growth rate thresholds that will simply render certain policies and approaches taken later, essentially useless in bringing about any real containment efforts. They become dollars wasted, lives lost, morgues filled, a pipeline of healthcare efforts simply resulting in either ‘back to normal’ treatment for some, and the morgue for others, at a fairly linear rate, seemingly never-ending.</p><p><strong>“Speed, but how much speed?”</strong> is the question on everyone’s mind right now.</p><p>Recall that South Korea went into (effectively) full (culturally induced + partly legally enforced) lockdown while the populace self-contained itself, around 2/20–2/21 when the number of confirmed cases was only <strong>544</strong> on 2/21, and they <em>already</em> had organized contact tracing at that point. They were able to begin declining around 3/12, <a href="https://en.wikipedia.org/wiki/2020_coronavirus_pandemic_in_South_Korea#18_February%E2%80%93present_outbreak">peaking</a> at around 7,400–7,900 confirmed cases that day, having 14x’d in 20 days after aggressive measures began. This is how South Korea had been able to succeed in containing and treating coronavirus cases without overwhelming its country. Can the US do what South Korea did, as swiftly as it did?</p><p>The United States is already far ahead of 544 cases. The 20-day balloon rate is somewhere between 77x and 708x, based on historical confirmed case counts.</p><p>I believe the containment outcomes for countries will swing between two extremes — either the scenario of effective aggressive, prompt measures when the growth rates and case counts are maintainable (whose thresholds can be further studied and refined than this article alone and will dictate most appropriate timing), such as in the case of India right now, and the vast number of scenarios of ineffective, basically last-minute measures to save face while letting one’s entire populace become infected within time, completely giving up on any real containment efforts and allowing healthcare systems to be overwhelmed and needing to choose between the living and the dead. Even then, a conscious populace with vigilant lockdowns — especially during early count days — can eventually allow the curve to increase for some time before tapering off during its lockdown period, assuming aggressive to ubiquitous testing and self-containment measures.</p><p>This reinforces the lack of effectiveness of all other options beyond the <a href="https://www.newsweek.com/coronavirus-fauci-many-millions-response-us-mitigation-1491780">recommended strategies</a> for urgent, non-complacent action.</p><p>I believe we need to start not thinking we are searching in the dark, anymore — allowing leaders to skirt ownership by feigning ignorance — and just stare at the real, actual multi-week stats of how this virus has grown, to plan accordingly. If it’s 700x over 28 days, so be it; now, plan. Nothing is less effective in planning for the future than assuming we know so little. And if we have to wait until the final bottom alternative, waiting for a company to simply find a cure, then I think you can bet we will be struggling to pay for it in this privatized healthcare world of the United States, while many thousands will have died unnecessarily at the hands of hesitant leadership, due to the lack of prompt aggressive action that properly values the (immediate) future more than the few scant days, weeks, or even months of deferring such containment. I applaud the leadership of countries like South Korea and India right now, who are putting skin in the game to truly prove how much they are both prepared for and committed to the futures of their countries.</p><p>Thanks for reading so far. Please leave constructive comments on the analysis so far and any other further insights or recommended references you may have. <a href="https://external-preview.redd.it/Br0D6A1cDVZdnJARzB1QOWefuHEeVQtfKXwbpd9uY4Y.gif?width=640&amp;format=mp4&amp;s=a9230aa12d1ef4af7bbc96bf45b040107aee0cc2">Thank you for staying at home</a>. :)</p><p>All numbers are based on the spreadsheet calculations based on available confirmed case count as of this time of writing, evening of 03/25/2019.</p><p><strong>Aside: what am I doing?</strong></p><p>Personally speaking, I have been safe-housing myself off the Yucatan territory in Mexico. I am okay with being laughed at while I plan on building my chicken house to raise 8 chicks and growing my vegetable garden. Chicken is one of the most efficient forms of protein, and a chick takes about a month to grow into a daily egg-laying chicken. (Fun fact: chickens eat basically anything that’s not a meat product, including compost).</p><p>Peace of mind is important to me, better than sitting around anxiously wondering when the grocery store shelves will either empty or replenish, and how fast I need to get there.</p><p>This will be a boon for the homesteading DIYers, in a day and age where free online resources can teach you<a href="https://www.gardenguides.com/139235-grow-vegetables-indoors-year-round.html"> how to grow year-round indoor vegetables using a 6x6 feet indoor greenhouse</a>, and chickens are both generously giving, and very low maintenance to raise and maintain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d39314df2794" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The iterative solution to inorder tree traversal, easily explained (an “intuitive” guide to…]]></title>
            <link>https://medium.com/@amyhuajs/the-iterative-solution-to-inorder-tree-traversal-easily-explained-f25f09e5435b?source=rss-ebee3176b755------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25f09e5435b</guid>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Amy Hua]]></dc:creator>
            <pubDate>Sat, 05 May 2018 06:46:18 GMT</pubDate>
            <atom:updated>2020-03-20T16:47:21.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>The iterative solution to inorder tree traversal, easily explained (an “intuitive” guide to recursion)</h3><p>I hadn’t been satisfied with the way in which the iterative solution of inorder binary tree traversal has been explained so far in my searches on the intertubes. It kind of <em>doesn’t really exist.</em> Nor does really good guides on recursion: intuitive explanations are hard to find.</p><p>So here is my attempt at explaining the solution in greater and clearer depth for everyone. May all confusion about this problem, as well as recursion and iterative solutions to recursive algorithms, be forever put to bed after this.<br>Just kidding!</p><p>In any case, I hope this serves as a clear guide for those dealing with the problem and can help you deepen your intuitive grasp of recursion and the call stack. I’ll be using Javascript throughout.</p><p><em>Prerequisite knowledge</em>: inorder tree traversal (“left, root, right”), binary tree. Just know what they are.</p><p>The problem is usually stated like the following:</p><blockquote>Given a binary tree, return the inorder traversal of its nodes’ values.<br>Aim for an iterative solution.</blockquote><p>Solution Template:</p><pre>/**<br> * <a href="http://twitter.com/param">@param</a> {TreeNode} root<br> * <a href="http://twitter.com/return">@return</a> {number[]}<br> */<br>function inorderTraversal(root) {</pre><pre>  var result = [];<br>  /* ...your solution here!... */<br>  return result;</pre><pre>}</pre><p>A binary tree is defined as</p><pre>function TreeNode(val) {<br>     this.val = val;<br>     this.left = this.right = null;<br> }</pre><p>So, for a tree like</p><pre>var root =</pre><pre>TreeNode {<br>  val: 1,<br>  right: <br>   TreeNode {<br>     val: 2,<br>     right: null,<br>     left: TreeNode { val: 3, right: null, left: null } },<br>  left: null }</pre><p>which, in drawings, translates to:</p><pre>1<br> \<br>  2<br> /<br>3</pre><p>the solution should return</p><pre>result = [1,3,2]</pre><p>as the answer.</p><p>Semantics: notice that <em>root</em> refers to the entire tree itself, not just the <em>root value </em>(which is simply the Number 1). <em>root</em> is a (binary) tree that optionally contains a left and/or right (binary) tree.</p><h4><strong>Some review of inorder traversal (and recursion intuition)</strong></h4><p>By nature of inorder traversal (AKA “left, root, right; repeat”), the way in which we traverse a given tree is by following these 3 rules:</p><ol><li>Prioritize traversals of the “left side” tree of the given root over the value of the root itself.</li></ol><p>2. Prioritize the traversal of the value of the root itself over traversal of its “right side” tree.</p><p>3. Do traversals of all subtrees also using inorder traversal.</p><p>In this example, then, the function attempts to traverse the left of the root node at 1 first (Rule #1). It finds no left child to traverse, so it moves on to traverse the value of the root node (Rule #2): 1 gets added to the final result set of “ordered traversed nodes”.</p><p>var result = [1]</p><p>Finally, it traverses the right of root 1, finding a subtree with root value 2 (Rule #2). It needs to traverse this subtree at root 2 also in inorder fashion (Rule #3) in order to complete our inorder traversal of the entire tree.</p><p>To do this (last) traversal at root 2, the traversal of any “left side” tree at root2 must be prioritized over the traversal of the root2 itself (Rule #1 again). So we go to the left of 2 to find it has a subtree with root value 3.</p><p>We have to traverse this subtree at root 3, in order to finish our left-side traversal of root 2, <em>before</em> we can even get to traversing the value2 itself, then traverse its right child, <em>in order</em> to finish the right-side traversal of root 1, which would complete our inorder traversal of the entire original tree, root 1.</p><p>You feeling me? Alright, keep going. We’re going to traverse root 3 now.</p><p>We attempt to traverse its left, and find nothing to the left of 3. Next in priority, we traverse 3 itself, adding it to the result set:</p><p>result = [1, 3]</p><p>Next in priority, we attempt to traverse its right, finding nothing to the right of 3. Which means the left, root, and right hand sides of root 3 have been totally traversed.</p><p>(Turns out, you always completely explore things that don’t exist. I find this an amusing consequence. I’ve totally traversed Zigatron #61732.)</p><p>Fully traversing root 3 means we finish the left-side traversal of root 2. “Bubbling up the call stack by 1”, we move on to traverse the root value of 2, adding 2 to the result set:</p><p>result = [1, 3, 2]</p><p>Finally, we move on to traverse the right side of root 2. There’s nothing there. Having traversed the left, root, and right of 2 means we’ve fully traversed root 2.</p><p>“Bubbling up the call stack by 1” again, fully traversing root 2 means we fully traversed the right of root 1. Completing the traversal of the right of root 1 means, since this is inorder traversal, we completed the traversal of the left, root, and right of root 1; which was what the function was designed to return. So to finish our function’s objective, we simply return the result set and we’re done.</p><p>inorderTraversal(root) = [1, 3, 2]</p><h3>Getting to the iterative solution</h3><p>For the record, the recursive solution is simply</p><pre>function inorderTraversal(root) {<br>    var result = [];<br>    if (!!root.left) result = result.concat(inorderTraversal(root.left));<br>    result = result.push(root.val);<br>    if (!!root.right) result = result.concat(inorderTraversal(root.right));<br>    return result;<br>}</pre><p><em>Note: </em>in Javascript, if (!!x) is the same as asking “if it exists (or is not zero)”, or technically, if it is not null / undefined / 0 (in Javascript). It returns an explicit true or false value, which is totally not needed, but helpful for the sake of explaining things more clearly.</p><p>Traverse the left in an inorder fashion, and add the result to the result set. Then, when you’re done with that, add the root to the result set. Finally, traverse the right and add the result of that to the result set. The traversals are also done in inorder fashion. That’s inorder traversal for you, by definition. Simple stuff right?</p><p>Great. Now, try not to use any recursion at all in your solution.<br>Hmm….</p><p>There are a couple basic, gotta-know ingredients to your solution:</p><ul><li>While Loops</li><li>Stacks (AKA “last in, first out” linear lists)</li><li>(Optionally) Break statements.<br><em>Pro-tip</em>: while(true) is useful when you break out of it with break during “special” circumstances, i.e. when you have fully built out the result you wanted, and want to be done with repeating a series of steps.</li><li>Conditionals (if, else-if)</li></ul><p>That’s it. The rest is up to you and your intuition on recursion. At this point you can try and use your understanding of the above to attempt the iterative solution on your own before reading further, which I wholly recommend.</p><p>…</p><p>…</p><p>…</p><p>A key insight that you need to derive the iterative solution is an understanding of how <strong>recursive functions essentially imitate a stack</strong>.</p><p>Become aware of how a recursive function — generally speaking —utilizes and builds the call stack, the nature by which the function gets repeatedly invoked, and you are one step closer to going from a (typically) exponential solution that is recursive, to a linear one that is iterative (woohoo!). Recursive functions have the benefit of being easy to write and derive, leading to simple task procedures, with the consequence of taking up a lot of memory and time executing its <strong>call stack</strong> due to its numerous, repeated executions.</p><p>Our goal in replacing the recursive applications of its call stack is to <em>replace the call stack with an explicit stack that we track instead. </em>We work from the recursive solution <em>into</em> the iterative solution.</p><p>So what is the call stack doing in the recursive solution?</p><p>Let’s look at it again:</p><pre>function inorderTraversalRecursive(root) {<br>    var result = [];<br>    if (!!root.left) result = result.concat(inorderTraversal(root.left));<br>    result = result.push(root.val);<br>    if (!!root.right) result = result.concat(inorderTraversal(root.right));<br>    return result;<br>}</pre><p>To start with, let’s imagine that root is a fairly complete tree with many left and right children and grandchildren nodes, so that whenever we come upon an if statement, it’s simply true. This lets us think of the “stock” solution first, so we can deal with edge cases of empty left/right children later.</p><p>In the first call, the recursive solution says, “traverse the left side”. It immediately invokesinorderTraversal(root.left), leading to our second call of the same function.</p><p>Let’s track these recursive calls and number them, so we can become aware of the pattern inherent in the generation of this stack of recursive calls.</p><p>Let’s call the first call <em>S1</em>, for “call 1 of the stack”. For as long as there is a left child of the root in <em>S1</em>, the second call <em>S2</em> will point to a <em>root</em> that is theleft child of S1’s root:</p><pre>S1&#39;s root = what is passed to inorderTraversal, originally.<br>S2&#39;s root = S1’s root.left</pre><p>Then, for <em>as long as there is a left-hand child</em>, you continue to call the function recursively. The call stack gets generated with a series of calls, <em>S1,…,SN</em>, such that</p><pre>S1&#39;s root = what is passed to inorderTraversal, originally.<br>S2&#39;s root = S1&#39;s root.left<br>S3&#39;s root = S2&#39;s root.left = S1’s root.left.left<br>.<br>.<br>.<br>SN: root = S[N-1]&#39;s root.left = S1’s root.left.left...left</pre><p>Let <em>N</em> be the number of times that the original function is called (<em>1</em>) + the number of times that inorderTraversal(root.left) is called (<em>N-1</em>).</p><p>We know that this recursive call to inorderTraversal(root.left) continues until the condition !!root.left evaluates to <em>false</em> in the recursive solution when the root is the root of <em>SN, </em>ending the number of calls to inorderTraversal(root.left) at the <em>N</em>th call in the stack.</p><p>If we track the root targeted in each call in the call stack in a list we simply call callStack, and we call the root of the <em>current</em> call in the call stack simplycurrent, then we get that the following is happening at every recursive call:</p><pre>var callStack = [];<br>var current = root;</pre><pre>while (!!current) {<br>  callStack.push(current);<br>  current = current.left;<br>}</pre><p><strong>Q</strong>. How long is callStack at this point?</p><p>…</p><p><strong>A</strong>. callStack becomes a list of <em>N</em> many roots, referring to the roots passed during the calls of:</p><ul><li><em>S1</em>, the originalinorderTraversal call, captured by setting var current = root initially and later pushing it to the call stack with callStack.push(current) during the first run of the while loop; and</li><li>S<em>2</em> through S<em>N</em>, made toinorderTraversal(root.left) in the recursive solution, captured above by setting current = current.left at the end of the while loop, which then evalutes to <em>true</em>, and then gets added to the callStack.</li></ul><p>The root at <em>SN</em> has no left child, ending the number of times inorderTraversal(root.left) is invoked on the <em>Nth</em> call in the call stack — that is, !!current evaluates to <em>false, </em>exiting the while loop, making the last element of callStack the root of <em>SN</em>.</p><p>During <em>SN</em>, !!root.left evaluates to <em>false</em> in the recursive solution. The recursive solution moves on to traverse the root value (Rule #1 applied), appending it to result:</p><p>result = result.push(root.val)</p><p>This is the same <em>root</em> as the root of <em>SN</em>, the last element of callStack after exiting the while loop.</p><p>And so, at this point of executing the call stack, it is equivalent to doing the following:</p><pre>var callStack = [];<br>var current = root;<br>var result = [];</pre><pre>while (!!current) {<br>  callStack.push(current);<br>  current = current.left;<br>}<br>// callStack has N roots, the last root being the root of SN</pre><pre>var lastCurrent = callStack.pop(); // root of SN<br>result.push(lastCurrent.val);</pre><p>Now, we continue to follow the execution of the call stack.</p><p>Next in the recursive solution, during <em>SN</em>, we traverse the right side: the following statement executes.</p><pre>if (!!root.right) result = result.concat(inorderTraversal(root.right));</pre><p><em>Note: </em>This will look oddly like <em>maybe </em>it’s a symmetrical version of what we already did for the left side. However, there is a significant difference that does not make this symmetric: you do not traverse the right side until you first evaluate the left side first, and then append the root to the result, and only <em>then</em> evaluate the right side. There is <em>not</em> a symmetrically equivalent operation for the left side.</p><p><em>If</em> there is a right child to the last root targeted in the call stack, i.e. if !!lastCurrent.right is <em>true</em> in the iterative version, <em>then</em> we call inorderTraversal again, adding another call of this function to the call stack, but this time on the rootlastCurrent.right. Again, this is only if lastCurrent.right exists.</p><p>If you understood all that, you would understand the code equivalent:</p><pre>while (!!current) {<br>  callStack.push(current);<br>  current = current.left;<br>}</pre><pre>var lastCurrent = callStack.pop();<br>result.push(lastCurrent.val);<br>current = lastCurrent.right;</pre><pre>//... we want to then repeat all of the above steps, for current = lastCurrent.right</pre><p>How many times do we want to repeat these steps for? How do we know when to stop repeating these steps — that is, where do we break these steps to finally return the result set accurately? Is it after the lineresult.push(lastCurrent.val);? Or is it before the line var lastCurrent = callStack.pop();?</p><p>The answer lies in understanding what you’ve been tracking this whole time…</p><p>The call stack!</p><p>callStack has been tracking the layers of calls you enter.</p><p>It grows whenever there is more to be traversed on either the left or right side of a root, and it shrinks whenever you had finished traversing the left side of a given root, or there was no right side remaining to traverse.</p><p>Given inorder traversal, the appropriate point to break the repetition of these steps must be immediately after the left, root value, and right of the last remaining root, callStack[0], has been traversed and pushed to result.</p><p>We note, then, that when callStack[0] gets popped and pushed to the result, rendering the callStack empty, it does so after the while loop executes, if it does at all, after having fully traversed the left side of callStack[0]. It has no left child.</p><p>As the last root to traverse in the call stack, it must have no right child to traverse either. When current = lastCurrent.right executes, current must not exist, and the while loop in the next iteration of these steps must never be evaluated.</p><p>It is only after the while loop condition fails do we know that the last root was already pushed to the result (during the prior iteration). Hence, we break when the call stack is empty, immediately after the while loop fails to find a right child on the last node to be traversed.</p><p>We encode “repeat these steps until the call stack is empty after the while loop fails” with a while(true){...} loop that repeats forever until we break` it when callStack.length == 0 after the while (!!current) {...} loop.</p><pre>var callStack = [];<br>var current = root;<br>var result = [];</pre><pre>while (true) {</pre><pre>  while (!!current) {<br>    callStack.push(current);<br>    current = current.left;<br>  }</pre><pre>  if (callStack.length == 0) break;</pre><pre>  var lastCurrent = callStack.pop();<br>  result.push(lastCurrent);<br>  current = lastCurrent.right;</pre><pre>}</pre><p>Aside: if we put this break statement instead at, say, after the result of lastCurrent was pushed, then we risk breaking the steps at a point where, while the call stack was empty, there was still a right tree (that, say, potentially has a large left child) to be traversed, which would have grown the call stack with many more calls of that right tree’s left child, and that right tree’s left child’s left child, etc.</p><p>It was necessary for us to think of how the while loop was being dual-purposed for traversing right trees as well as traversing left trees in order to understand where to break the steps.</p><p><strong>The Final Solution</strong></p><pre>// **recursive solution**<br>function inorderTraversal(root) {<br>    var result = [];<br>    if (!!root.left) result = result.concat(inorderTraversal(root.left));<br>    result = result.push(root.val);<br>    if (!!root.right) result = result.concat(inorderTraversal(root.right));<br>    return result;<br>}</pre><pre>// **iterative solution**<br>function inorderTraversalIterative(root) {<br>  var callStack = [];<br>  var current = root;<br>  var result = [];</pre><pre>  while (true) {</pre><pre>    while (!!current) {<br>        callStack.push(current);<br>        current = current.left;<br>    }</pre><pre>    if (callStack.length == 0) break;</pre><pre>    var lastCurrent = callStack.pop();<br>      result.push(lastCurrent);<br>      current = lastCurrent.right;</pre><pre>  }<br>  // finally, return the result; left as an exercise for the reader.</pre><pre>}</pre><p>(Note: a comment left by <a href="https://medium.com/@rajannpatel">Rajan Patel</a> in the responses explains how to output the final result.)</p><p>That’s it! I hope you enjoyed the explanation, and feel free to leave comments on how I could improve its clarity.</p><p>Next great steps after you think you’ve understood this is to try and implement the iterative solutions for preorder binary tree traversal and postorder binary tree traversal! Then, try and do the same for calculating a sum of a fibonacci sequence.</p><p>Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25f09e5435b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>