The Infinite Zenith

Where insights on anime, games, academia and life dare to converge

Leap Year 2012

Technically speaking, a full revolution of the Earth around the sun requires roughly 365.25 days. As such, across four years, an extra day has accumulated, and so, an extra day is added to ensure the calander remains consistent with the sun’s relative position. The Julian reform introduced the idea of a leap day and was implemented in 46 BC.

  • Unlike my website, images may not be pertinent to the discussion topic. Sometimes, they’re just here to decorate the page. But, you knew that already, right?

I am reminded of a period nearly a year ago, when I was enrolled in a data structures course and was tasked with the objective of optimising performance of a red-black tree. One part of the assignment included determining the worst-case runtime of the tree in Big-O notation. When I look at the pseudo-code for determining whether or not any given year is a leap year, I cannot help but wish that the algorithms in assignments were as simple as this one. Suppose that isLeapYear is a boolean declared elsewhere, and mod represents the modulo operator. Then:

METHOD void LeapYear (int year)

IF (year mod 4 == 0) AND (year mod 100 == 0) AND (year mod 400 == 0)) THEN isLeapYear;
ELSE !isLeapYear;

In terms of performance, this method has a worse-case runtime in O(1), quite simply because there are only two simple operations that run in constant time: we are simply passing in a value for the purposes of comparison, and then making an assignment value. Because we know each operation runs in constant time, the entire algorithm runs in constant time.

  • If I have some 420 MB of K-On! wallpapers and art gracing my image host, I might as well use them, lest readers fall asleep at the pictureless entries. Interestingly, ever since I found the “Yes We Nyan!” posters, I’ve warmed up fully to Azusa’s role and interaction with the other characters in K-On!

While a nifty utility of predicting when the leap year is, this algorithm is not implemented on my website’s calender; the website’s calender is a much more simple utility that simply uses a machine’s local time and updates correspondingly to it. It then uses that date to determine the season. I think it updates in real time, although I never remain on the home page long enough to see it do so.

Please provide feedback!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: