Monday, January 30, 2012

Tower of Hanoi Method

The Tower of Hanoi game relies on recursion to successfully simulate the directions. While the code isn't difficult to write, picturing and understanding the recursive calls may be more challenging. The recursive method written in Java is as follows:
  public static void hanoi(int disks, String source, String destination, String temp)
  {
      if(disks!=0)
      {
          hanoi(disks-1, source, temp, destination);
          System.out.println("Move disk " + disks + " from " + source + " to " + destination);
          hanoi(disks-1, temp, destination, source);
      }
  }
To start out with the simplest case of 3 discs, picture the following memory stacks, illustrated horizontally with the indentation of bullet points. Call the smallest piece at the top disk 1, and so forth. Currently, the discs are on the left tower. The ultimate destination is the right tower.
  • hanoi(3, left, right, middle) //from an outside main method
    • hanoi(2, left, middle, right)
      • hanoi(1, left, right, middle)
        • "Move disk 1 from left to right"
      • "Move disk 2 from left to middle"
      • hanoi(1, right,  middle, left)
        • "Move 1 disk from right to middle"
    • "Move disk 3 from left to right"
    • hanoi(2, middle, right, left)
      • hanoi(1, middle, left, right)
        • "Move disk 1 from middle to left"
      • "Move disk 2 from middle to right"
      • hanoi(1, left, right, middle)
        • "Move disk 1 from left to right"
Collecting the direction displays:
  • Move disk 1 from left to right
  • Move disk 2 from left to middle
  • Move 1 disk from right to middle
  • Move disk 3 from left to right
  • Move disk 1 from middle to left
  • Move disk 2 from middle to right
  • Move disk 1 from left to right
In general, while moving n disks from tower A to tower B (using tower C as temporary holder):
  • If n is even, begin by moving disk 1 from A first to C
  • If n is odd, begin by moving disk 1 from A first to B
Source:

Sunday, January 29, 2012

Power Function Method

To program the mathematical function b^e, where b and e are non-negative integers, a recursive method can be written and used. Assume an existing method sqr(int a) that returns an integer, that is the square of int a.
  public static int exp(int b, int e)
  {
      if(e == 0)
          return 1;
      else if (e%2 == 0)
          return sqr(exp(b,e/2));
      else
          return b*exp(b,e-1);
  }
This program takes advantage of the property that (a^b)^c = a^(b*c). For example, 3^16 = (3^8)^2. Therefore, if the exponent e is even, the next call uses e/2 while the entire result is simply squared. The advantage then is that this program runs in O(log e) efficiency, rather than the O(e) efficiency, had the boolean test of e being even not been tested.

To illustrate the running of the program using memory stacks, illustrated up-side-down, here's a case of an even exponential. For example, to calculate 3^4, or running of exp(3,4):
  • return exp(3,4)
  • return sqr(exp(3,2))
  • return sqr(exp(3,1))
  • return 3*exp(3,0)
To see what each memory stack returns to the previous, follow each from the bottom of the list back up:
  • 3*exp(3,0) --> 3 --> exp(3,1)
  • sqr(exp(3,1)) --> 9 --> exp(3,2)
  • sqr(exp(3,2)) --> 81 --> exp(3,4)
  • return exp(3,4) //equals 81
Indeed,  3^4 = 81 as returned. Note that exp(3,3) was never called, since during exp(3,4), as 4 is an even integer, it directly halved the exponential called next, and moved onto exp(3,2). While a linear efficiency only would've meant an extra step in this scenario, the difference will be more pronounced when the exponential gets substantially bigger. Consider exp(3,80): instead of 81 calls, this logarithmically efficient method would only have to call exp(3,80), exp(3,40), exp(3,20), exp(3,10), exp(3,5), exp(3,4), exp(3,2), exp(3,1), exp(3,0) for a total of 9 calls.

Wednesday, January 25, 2012

Compulsory Transition to Facebook Timeline

It looks as though Facebook this time will indeed transition its users to switch to the Timeline service, whether or not the users like it or not. As a mere new format, Timeline doesn't really reveal anything that was previously inaccessible. Nevertheless, it greatly facilitates the access of information from the past that used to be burdensome to retrieve. Instead of continuously hitting "Older Posts" to go to the past, users now can simply click on the year to instantly jump to the past. In computer science lingo, retrieval of information just went from O(n) to O(1) efficiency. While efficiency is greatly appreciated in computer algorithms, is it necessary good in the case of Facebook? It really depends.

Numerous Facebook users have deactivated their accounts since the inception of the Timeline program. Many remarks have come in that Timeline is "creepy" and "makes stalking easy." Indeed, by making past information much more accessible, Timeline does it make it easy for an user to look into the digital history of others. In anticipation of the changes, Facebook gives users "seven days to clean up their profiles before Timeline gets automatically activated." During this time, users get a preview of Timeline to make the necessary privacy settings before the new page goes public. But that still may be too much hassle for those to go through their scrapbook and change privacy settings, or totally remove, items from the past that they don't want others to see presently.

Facebook has grown with its expansion into complexity, each time facing massive opposition. For those preferring simplicity, Facebook has grown out of touch and function. LinkedIn has become the stream for professional information and contacts. Twitter has become more effective at quickly digesting news and developments, without all of the comments and "likes." What's Facebook good for then? Currently on my News Feed, there are shared pictures, various comments and status updates about people's evenings, among others. Indeed, these seemingly random pieces of floating information are what holds Facebook together. Yet that can be quite useful. These aren't exactly the information one will try to actively search for. Instead, the information comes to them, some useful, most of them not. Facebook also still is the best tool to keep in contact with the average friend. One learns about other's activities effortlessly and can easily communicate, without having to look up email addresses.

Back to Timeline though, it seem as though this privacy issue has concerned many users. However, there should be no concern if one is indifferent about past information being exposed presently. People continuously share too much pieces of information, and don't want it to be easily accessible by all. Ironically, unbridled sharing is what makes Facebook useful. The more information people post, the more useful Facebook becomes for everyone who views that information. But the more information an individual puts out, the bigger chance that the information eventually will get to those unintended. Timeline actually serves as an apt reminder that public digital information is indeed public. Even had Timeline been implemented, the information posted today will still be accessible in the future.

Facebook is still useful. From textbook transactions, campus events, to friends reconnecting, Facebook excels in the expediency and ease with which information spreads. Timeline's quick access helps those looking for useful information from the past. For those concerned about excess personal information going public and the easy access of such from others, don't feed that much information into the system. Don't post that embarrassing status or picture; there is a reason why email or private messaging exists. Instead, use Facebook to share information that doesn't mind being easily accessible forever, or simply use it for passive intake of information. Facebook is a digital archive with information that will stay. The sooner people realize that, the better it can serve all users in what it does best.

Sources:

Sunday, January 22, 2012

Behind the Production for Apple

Most of the production for Apple's products are done outside the United States. Is that a good or bad outcome for Americans? Focusing on the labor, it seems as though United States lose these jobs that are outsources overseas. Around 700,000 people work for Apple's contractors, most notably Foxconn. The factory in Shenzhen alone employs 430,000 workers. It's been cited that the necessary skills are more easily found in Asia than the United States. Apple's analysts estimated that it would take nine months to find the necessary number of engineers to oversee and guide the assembly lines; in China, it took 15 days.

But it's not an entirely a loss for United States. Apple is able to charge its products relatively cheaply and retain enormous amount of profit as a result of utilizing the labor in China. As a comparison, Apple retained a whopping 23.95% profit margin in 2011, while Hewlett-Packard (NYSE:HPQ) only had 5.56% and Dell (NASDAQ:DELL) 4.28%. This wealth has benefited individual investors and pension plans. Furthermore, the price of the Apple products would be higher if they were made in United States. Estimates put additional $65 into each iPhone made with US labor. While Apple can still maintain a profit with that increase, it is unsure how much of that hike in input prices will be pushed onto the consumers. However, the bigger issue is still the availability of skillful labor.

Sources:

Friday, January 13, 2012

Eurozone Downgrade

On Friday, the financial crisis in Europe took another turn as Standard & Poor, the same rating agency that cut the AAA rating for United States, downgraded the ratings for 9 euro-zone countries, citing that "the policy initiatives taken by European policy makers in recent weeks may be insufficient to fully address ongoing systemic stresses in the euro zone." Among the top-notch ratings downgraded were France and Austria, which like the United States, fell to AA+. Italy saw its rating fall to BBB+, dangerously close to the junk bond level. Other countries seeing their ratings fall were Slovenia, Slovakia, Spain, Malta, Cyprus, and Portugal. However, avoiding the downgrade was Germany, which kept its AAA rating and its role as the stronghold in the euro-zone.

Although the downgrade was predicted, stock markets on both sides of the Atlantic fell Friday. London's FTSE 100 and Germany's DAX were both done about 1.5%, while indexes in United States fell about 0.5%. The downgrades will mean that the cost of borrowing will be higher for these European nations, and the impact will be seen in two days when France sells over 8 billion euros in bills. After the S&P announcement of increased European bonds, investors sought the US treasuries, sending the yield on 10-year note to 1.87%. Similarly, yield on Germany's 10-year also decreased to 1.76% as the country maintained its strong rating. Meanwhile, as the collective risk of the euro-zone governments increased, demand for euro decreased as the euro hits a 16-month low against the dollar, at $1.2665.

Sources:

Wednesday, January 11, 2012

Probability of Consecutive Coin Flips

Given (n) coin flips, what's the probability of getting at least one pair of consecutive heads?

If n = 2, the probability is 1/4. If n = 3, the probability is 3/8 (HHH, HHT, THH). If n = 4, the probability turns out to be 8/16. The denominator of the probability fraction, in its unsimplified form, will be 2^n. The challenge is to find the numerator. For simplify in wording, here are the phrase abbreviations:
  • "at least a pair of consecutive heads" --> "HH" 
  • "no pair of consecutive heads" --> "!HH"
  • "heads" --> "H" and "tails" --> "T"
Let p(n) be the probability that first (n) flips feature HH. This is what we're ultimately looking for. As with many cases in probability, it may be easier to define and use the complimentary probability q(n) as 1-p(n). Moreover, let's define q'(n) as simply the denominator of the unsimplified fraction q(n). So q'(2) = 3, q'(3) = 5, q'(4) = 8, and so on. To get started, take the first values of (n) and list out the possibilities of combinations featuring !HH.

n = 2 n = 3 n = 4
HT HTT HTTT
TH THT THTT
TT TTT TTTT

TTH TTHT

HTH HTHT


TTTH


THTH


HTTH

While the ordering wasn't particularly important at this stage, notice that the first three rows of n=3 was conveniently laid out so that they are simply addition of one more T from the same row under n=2; same for going from n=3 to n=4. Now take a looks specifically at n=3. The first toss can be H or T. For 3 flips featuring !HH:
  • If the 1st flip is T, there are 3 possible combinations (THT, TTT, TTH)
  • If the 1st flip is H, there are 2 possible combinations (HTT, HTH)
The combinations of those 5 combinations happen to be the 5 combinations listed in the column above for n=3. Now start from n=2:
  • For 2 of those combinations ending with T, each will produce 3 further possible combinations in 3rd and 4th flip to keep the !HH property
  • For the remaining combination ending with H, it will produce 2 further possible combinations instead
Add 2*3 + 1*2 = 8, and it is no surprise that q'(4) = 8 as established. How the question remains: how did we just know that for n=2, two combinations ended in T?

The answer actually indirectly lies in q'(3). Observe the column of combinations above for n=2 and n=3. In particular, look at the last two rows. Similarly, compare n=3 and n=4 rows and observe the last three rows of n=4. What are those "extra" rows without something to the left of it in the table? They all end in H, and the rest of the term (without the final H) are exactly the combinations that end in T for the previous column.

Let's formulate some ideas for q'(5). Take q'(3) = 5 to start.
  • Each of those 5 combinations will produce at least two possible combinations (of 4th and 5th flip) to keep the !HH property ongoing at n=5
  • Furthermore, some portion of those 5 combinations will produce a third combination, if it ends in T
How did we how many ends in T? It's q'(4) - q'(3), or the number of those "extra" rows.
  • Summing them together, q'(5) = 2*q'(3) + (q'(4) - q'(3))
  • That simplifies to q'(5) = q'(3) + q'(4)
Suddenly, it looks very familiar. That is exactly the Fibonacci sequence that q'(n) is following, with q'(1) = 2, q'(2) = 3, etc. Precisely, given the initial offset, the Fibonnaci sequence F(n) = q'(n-2) or F(n+2) = q'(n). But recall, we're trying to find p(n), and in the process, defined q(n) and q'(n). To convert q'(n) = q'(n-1) + q'(n-2), recall that q'(n) is simply numerator of q(n), whereby the denominator is 2^n.
  • Multiple each term by either 2^n, 2^(n-1), or 2^(n-2)
  • That ends up being 4*q(n) = 2*q(n-1) + q(n-2)
  • Simplify to q(n) = (1/2)*q(n-1) + (1/4)*q(n-2) with conditions that q(1) = 1, q(2) = 3/4
  • Finally, p(n) = 1 - (1/2)*(1-p(n-1)) - (1/4)*(1-p(n-2))
Alternatively, it may just be more convenient to leave the result in Fibonacci sequence, since those numbers are more easily accessible. In that case, it goes from:
  • Given F(n+2) = q'(n)
  • q(n) = F(n+2) / (2^n)
  • p(n) = 1 - F(n+2) / (2^n)
In either case, q(n) gives the probability of featuring no consecutive heads in the first (n) flips; p(n) gives the probability of having consecutive heads. To give some numerical sense, Java coding was written for the modified Fibonacci method. Beware that given the recursive method, the program will run quite slowly as (n) gets around 40.
  int until = 0;
  System.out.print("n = ? ");
  until = reader.nextInt();
  for(int i=1; i<=until; i++)
  {
      System.out.println(i + ": " + (1-fib(i)));
  }

  public static double fib(int run)
  {
      if(run == 1)
          return 1;
      else if(run == 2)
          return 0.75;
      else
          return (0.5)*fib(run-1) + (0.25)*fib(run-2);
  }

The condensed results are as follows:

n p(n)
1 0.00%
2 25.00%
3 37.50%
4 50.00%
5 59.38%
6 67.19%
7 73.44%
8 78.52%
9 82.62%
10 85.94%
15 95.13%
20 98.31%
25 99.41%
30 99.80%
35 99.93%
40 99.98%
45 99.99%

As expected, the probability quickly climbs up as the number of flips increase, and asymptotically approaches certainty.

Friday, January 6, 2012

December Jobs Report

On Friday, the Labor Department announced that 200,000 jobs were added into the economy in December. Beating analysts' estimates of 150,000 gain, this dropped the unemployment rate to 8.5%, the lowest level since February 2009. Overall for 2011, the economy added 1.6 million jobs, the most in five years. However, the US stock markets didn't respond mildly to these news. Dow and S&P 500 posted marginal losses.

Despite the latest signs that the economy is improving, employment still remains 6.1 million below the levels before the recent recession. Even with December's rate of growth, it will still take over two years to recoup such amounts. Moreover, seasonal variability accounted for much of the growth seen in December. Contribution to the growth were construction jobs, boosted by mild weather. Messenger and retail industries also added significant number of jobs for the holiday shopping season. As colder months arrive and the holiday season wanes, growth in these sector may slow down.

Furthermore, European situations continue to worry investors globally. Unemployment in the 17 nations that use the euro is at 10.3%. Italy's 10-year bond yield climbed to 7.09%, above the 7% threshold that impelled bailouts in Portugal and Ireland. The Spanish levels are dangerously resting at over 5.6%. The euro fell to $1.2696, the lowest since September 2010. The yield in US Treasury 10-year note fell to 1.96%. At first, this may contradict the general rule that as interest rates increase in a country, money and investment will flow into that country and appreciate its currency. However, dollar is appreciating against the euro despite decreasing interest rates in US and increasing rates in Europe. In this scenario, it can be explained that higher yield in Italian bonds are due to greater risk. Investors instead choose to put money in the low-risk US Treasury bonds. As the demand for US Treasury bonds increases, the bond yield falls.

Sources:

Thursday, January 5, 2012

Eastman Kodak Company (NYSE: EK)

Kodak, as it is commonly known, has been around since 1892, focusing on imaging and photographic materials. Excelling in photographic film for much of the 20th century, the 131-year-old company has struggled in recent years as use of photographic film has slipped. In recent years, Kodak has tried to focus on printers, but ranks fifth globally with a market share of only 2.6%. On Wednesday, it was announced that  Kodak is "preparing to seek bankruptcy protection in the coming weeks," sending its stock below 50 cents, a dramatic decrease from when it was nearly $30 back in 2007. In the meanwhile as it tries to prevent Chapter 11 bankruptcy, Kodak is trying to sell patent portfolio.

A look at the financial statements for Kodak confirms its recent struggles. Net income has been in the negative each year since 2007, and most recently in 2010, it incurred 687 million loss. During that year, while the COGS margin stayed around 73%, sales weren't enough to cover even the operating expense. Looking at the balance sheet, there is negative equity as of 2010, as long-term debt made up most of the liability. It's interesting to note that the current ratio is above 1. It is plausible that Kodak prepares for Chapter 11 now while it still has the temporary liquidity to restructure the firm. Equity has been on a downward spiral from 2007 when it was at over 3 billion, to the latest 2010 figures of -1 billion. Cash flow statements show similar trends, as merely cash flow from operations has been on a downward spiral into the red.

Sources:

Wednesday, January 4, 2012

Europe at the Brink – A WSJ Documentary

The Wall Street Journal recently published a documentary about the origin of debt crisis in Europe, citing imperfect union as the root cause. After World War II, economic ties were sought to prevent future conflicts. 1957 Treaty of Rome established European Economic Community. In the next decades, the idea of a unifying currency was sought, finally leading to the rise use of euro today. People hoped that this would be the start of a united Europe. However, while there was monetary union, there lacked fiscal union. All countries shared same policies regarding the supply and value of euro, but each country differed in its growth and governmental policies, helping to plants the seeds of current situation. Due to low borrowing costs, counties like Greece took on debt to offset its own weak internal growth.

In October 2009, Greek debt projected to be 3% of its GDP was actually 12%. Foreign investors panicked, and costs of borrowing to Greece increased. Given the abundance of countries and governments in the euro-zone, actions were slow to be implemented. In May 2010, Greece needed a bailout for its debt, but anxiety about Greek fiscal soundness continued. Furthermore, the worry began to spread through the continent. Particularly distressing was Italy, the euro-zone’s third largest economy.

The question looms whether to form a tighter fiscal union or let the countries dissolve further apart. The premise of the euro was for the countries to converge their economies, but such has not been observed. What direction Europe would go also remains a mystery; some even speculate one or more members leaving the zone this year. Disciplined approach to national finance is now crucial. The stake of the entire world economy is contingent on the approaches Europeans take.

Source:

Tuesday, January 3, 2012

2011 Stock Index Trends

On Tuesday, the first day of market activity in the new year, US stocks climbed. Dow, NASDAQ, and S&P 500 all posted around or above 1.50% gain. This comes off 2011 that saw little change, particularly the S&P 500, which ended the year at 1257.60, just 4 ticks below the year's opening mark. Dow increased 5.5% for the year. All three indexes saw a tumultuous 2011. Roughly speaking, stocks rose for the first half of the year, with early July reaching or tying the apex for the year. End of July marked the beginning of downfall, followed by months of extreme volatility and eventual gradual increase to the starting level.

One can note the coincidence of major world events to several strong movements or trends in the indexes. Immediately after the March earthquake and tsunami in Japan, stocks fell with the fear of disruption in the global economy. The S&P 500 reached a nadir of 1279.20 on March 18th, over 60 points lower than the mark a month earlier. The tumble began at the end of July, as slow economic growth coincided with political gridlock in Washington over the debt deal. Unemployment for June was at 9.2%, while US economy grew only at an annual rate of 1.3% in Q2. After S&P downgraded the credit standing of US on August 5th, the indexes dropped over 6%. From August to November, the Dow swung an average of 269 points a day, reflecting the high volatility as the US watched the troubling developments of Europe and saw the unemployment numbers drop to 8.6% in November.

While the US stock market saw little to no growth in 2011 overall, the situation is much worse through rest of the world. Nearly all other countries saw indexes down, with a global (excluding US) average of -14%. But within, various sectors performed drastically different. Leading the sectors within S&P were utilities, consumer staples, and healthcare. McDonald's led the Dow with 31% gain, while financial groups saw biggest decrease.

Sources:

Monday, January 2, 2012

United Parcel Service (NYSE: UPS) & FedEx Corporation (NYSE: FDX)

UPS and FedEx are the leading companies in delivery services. The recent Holiday season showed signs of growth for the industry, as package volumes increased from the previous season. UPS expected to delivery 120 million packages in the week leading up to Christmas, up 6% from the period a year ago. It also expected to feature at least five days approaching or exceeding 25 million packages, the peak amount last year. FedEx shipped 17 million packages on December 12, marking the busiest day in company history, up 10% from last year's peak. To accommodate for these extra services, UPS and FedEx hired over 50,000 and 20,000 seasonal employees, respectively.

In financial analysis of the two companies, raw data was taken from Google Finance and ratio calculations were performed using Excel. The data for UPS was presented for the quarter ending in September 2011, while for FedEx, it was for the quarter ending in November 2011.

UPS FDX
2011 Close Price 73.19 83.51
2011 Open Price 73.18 93.54
Market Cap (Billion) 70.63 26.26
P/E Ratio 17.77 15.18
EPS 4.12 5.50



Latest Quarterly Data in Millions
Total Revenue 13,166 10,587
Cost of Revenue 9,829 7,892
Net Income 1,042 497
BOP Cash 4,691 1,959
EOP Total Receivables 5,584 4,837
BOP Total Current Assets 12,950 7,963
BOP Net PPE 17,489 15,820
BOP Total Assets 35,152 27,838
EOP Accounts Payable 1,974 1,646
BOP Total Current Liabilities 7,618 4,981
BOP Total Debt 12,161 1,668
BOP Total Liabilities 26,898 12,124
BOP Total Equity 8,254 15,714

Notable differences include the market capitalization, in which UPS nearly three-folds FedEx. Nevertheless, the size of the companies as measured by revenue or total assets doesn't differ drastically. In terms of total equity, FedEx's value actually almost doubles that of UPS. For better understanding, ratio analysis was conducted:

Annualized Ratio Analysis

UPS FDX
Returns on Equity 50.50% 12.65%
Profit Margin 7.91% 4.69%
COGS Margin 74.65% 74.54%
Asset Efficiency Ratio 149.82% 152.12%
Return on Assets 11.86% 7.14%
Fixed Asset Efficiency 301.13% 267.69%
AR Turnover 10.60% 11.42%
AP Turnover 5.02% 5.21%
Cash Level 8.91% 4.63%
Debt to Asset Ratio 34.60% 5.99%
Debt to Capitalization Ratio 59.57% 9.60%
BOP Current Ratio 169.99% 159.87%

UPS nearly doubles FedEx in terms of profit margin, despite similar COGS margin, asset efficiency levels, and comparable levels of sales. But drastically different for the companies is debt. The debt level of UPS is nearly 7-fold that of FedEx. As a result, debt to asset and debt to capitalization ratios are significantly higher for UPS. Despite the higher level of debt, UPS has a higher current ratio and cash levels, illustrating its sound liquidity. Furthermore, given that profits and equity levels have been solidly positive, carrying debt shouldn't be a great concern for UPS. The high level of debt is directly reflected in the higher liability and lower equity values for UPS. As a result of the lower equity, UPS features higher returns to equity (ROE) values.

While FedEx saw its stock price decrease in 2011, UPS barely saw any change. Both companies should see growth as the earnings from Q4 come out and reflect on the increased earnings over this year's Holiday season. Both companies are also likely to remain in close watch as financial troubles continue to plague USPS.

Sources: