Insertion Sort

Imagine you have a randomly sorted poker hand which you need to reorganize from left to right in the traditional fashion of 2,3,4,5…etc up until Jack,Queen,King,Ace. Most people, without thinking, will likely grab an individual card and move it to the correct spot and repeat this action until they achieve a “sorted” hand – this is called “insertion sort” by computer scientists and the procedure goes something like this:

1.) Take the first card in your hand. Lets say its a queen.
2.) Look at the next card in your hand. Is it less than a Queen? If so, skip it and look at the next card after that.
3.) Keep repeating this procedure until you find a King or Ace and then stop. Insert the Queen card prior to the King or Ace you encountered.
4.) Working from left to right, perform this operation over and over again until you reach the last card, which should be an Ace by the time you are done.
5.) If you are attempting to sort an Ace, you will keep searching until you reach the end of the hand – in many programming languages, an Array is terminated by a null character which signals you are holding the highest card in the set currently.

So now we have an idea of what Insertion Sort is all about.

However, in Computer Science – knowing how to implement an algorithm is only the beginning of the process. When thinking about any algorithm such as Insertion-Sort, we immediately have to think about a list of common questions which will be asked in any programming interview and should arise:

  • How fast is this method of sorting?
  • How much space does it take up to perform insertion sort?
  • Is there a faster way to sort than insertion sort?

Anyone who has ever studied complexity analysis will understand the importance of these questions – because, unlike in the world of poker, in the world of computer science it is common to sort millions of records instead of only a single handful. At very vast scales…such as those performed in datacenters owned by Amazon, Google and Facebook on a daily basis, algorithms matter…they really *really* matter. A simple adjustment can exponentially increase the speed at which an operation is performed and becoming conversational in the “craft” of complexity analysis (nerd speak for “analyzing algorithms generally with the intent to make them faster”) is a critical skill.

So returning to the three major questions which we are asking of Insertion-Sort.

“How fast is this method of sorting.”

Well – there are a couple ways to approach this. Lets say I am handed a stack of cards which are already completely sorted except for one out of place card at the very end – the Ace is in the second to last position instead of the last position. I would have to tediously iterate over every card in the deck and compare it to every other card in the deck to check if it is “in place” one at a time before finally reaching that single “misplaced” Ace and realizing that I have found an unsorted card.

In short – if I have 52 cards, I would have to compare each of those 52 cards to every other card in order to see if it is out of place.That isn’t very efficient – and Computer Scientists would say the algorithm has a complexity of “n-squared.”

“How much space does it take to perform Insertion-Sort”

Technically, looking at the problem, it seems that we don’t really need any more space than what is provided by the cards in our hand – in computer science speak this is an “in-place” sorting algorithm because no extra space is needed. In other algorithms, it might be necessary to have a sort of “buffer” in which we do our busy-work before arriving at a final solution. Insertion-Sort does not require such a bugger.

“Is there a faster way to sort than insertion sort?”

The answer to that question is “yes.” Over the years, numerous sorting algorithms have been developed to solve the sorting problem. Sorting has been recognized as a central problem for many, many business applications where large data is a factor and a quick search on Wikipedia will turn up at least a dozen different variants of the sorting process.

With it’s sorting speed of n-squared, Insertion-Sort is rated as the 3rd slowest type of sorting procedure. The only way you could do worse is to have what is known as an “exponential” sorting speed such as 5 to the N or, if you have really done something wrong, N! or “n-factorial.”

Posted in Uncategorized | Comments Off

Hey Sony, Nintendo and Microsoft: It’s A Trap

Alarm bells should be going off at the headquarters of Microsoft, Apple and Sony…because if they continue pretending that they can uphold the status quo with yet another round of physical media based devices…they are going to be walking directly into a trap of their own devising (complete with spinning blades and chutes for bloody giblets).

While the usual big three console makers are slowly circling the next iterations of their physical console devices…Apple is loudly (come on guys…this is so freakin’ obvious) working on a strategy to severely wound the foundations underpinning the entire hardcore games market: artificially inflated prices.

With last week’s visit to Valve’s Bellevue offices, Tim Cook could not have signaled more clearly his intention to completely overturn the console market with some sort of new gaming device…be it a stand alone console or integrated television set.

This new iDevice will have the following characteristics:

  • App store
  • 100%  downloadable content

Developers will love it because:

While it is true that the current flock of consoles have some or all of these features…there is tremendous room for streamlining and simplification. Sales on XBox Live, for example, are nowhere near their potential.

Gamers will love it because:

  • Hardcore game prices will plummet as developers race to the bottom to populate the store
  • Unlike the XBOX and other devices, purchases they make will be good forever – it is likely any games they buy will work on several future iterations of Apple console devices

With the Infinity Blade series of games, Apple has already struck gold. They now have a thirst for the riches which can be reaped from selling hardcore content….and they want more….and believe me, they are going to get more. If there ever was an industry more ripe for disruption, it is the cloistered, fortified and monopolized hardcore gaming console market.

The following scenario may well come to pass…Microsoft, Nintendo and Sony release their respective 3rd round of heavyweight consoles and flag ship games at $60 a pop. At the same time, the iConsole comes out where developers predominantly price their hardcore content anywhere from $1 to $10 (max!)…complete with social and micro-transaction enabled content. Developers will flock to load the app store with hardcore games at much cheaper rates than XBOX or Sony can compete with. It’s not going to be pretty.

For those of you thinking Apple is going to produce an overpriced console…you are on the wrong track. Apple is many things but stupid isn’t one of them. Whatever they re lease is going to be priced for a mass market…there is no point for them to target expensive niche devices.

The big three are also completely and hopelessly doomed by their love affair with physical retail sales…at least according to some analysts: “We think it is unlikely that the next generation of video game consoles will implement technology that blocks used content as it would be considered a very unfriendly consumer initiative.” (source). Apple has no such attachments and fully plans on ending the retail games business for good.

Nintendo has already been hopelessly injured by Apple’s encroachments in the mobile space…it doesn’t take much of a leap of imagination to see where this is going next.

At the very least, GameStop is as dead as a doornail at this point. There is just no way they are going to survive what is coming. This will also surely have a massive impact on the prices of ALL downloadable PC casual games because they are heavily connected to the artificially high prices of traditional console games e.g. Steam prices are surely going to drop to keep up.

Posted in Apple, blood bath, Microsoft, Nintendo, Sony, trap, XBOX | Comments Off