RSS

Monthly Archives: December 2014

QuickSort Algorithm

Quicksort is a divide and conquer algorithm. Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays.

The steps are:

  1. Pick an element, called a pivot, from the array.
  2. Reorder the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called thepartition operation.
  3. Recursively apply the above steps to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values.

quicksort-algorithm

Reference: Wikipedia

Advertisements
 
Leave a comment

Posted by on December 30, 2014 in General

 

Tags: ,

What You Can Learn From My Christmas Card

I don’t think I ever hand out Christmas card to friends or colleagues, but this year, I decided to do just the opposite. Here’s the card I wrote for my colleagues at work.

what-you-can-learn-from-my-christmas-card

This is a legit, working code by the way. And I think there are few things we can learn from my Christmas card:

  • Readbility
    Good codes are readable by everybody, not just the developer. This includes the use of:

    • Indentation
    • Self-describing variable names
  • Reusability
    I write the code once and re-use it for every Christmas card I handed out this year. Write once, use many.
  • I am not good at drawing, thus the “<img src='santa.jpg' />” shortcut.

Merry Christmas and Happy New Year to all of you!

 
Leave a comment

Posted by on December 23, 2014 in General

 

Tags:

Selection Sort Algorithm

The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

selection-sort-algorithm

Reference: Wikipedia

 
Leave a comment

Posted by on December 19, 2014 in General

 

Tags: ,

SQL Server Instances You May Not Know You Have

There are 3 SQL Server database instance in most local machines. These are SQL Server Express instances that mainly useful for developers so they don’t have to install any SQL Server instance to get a project up and running. They are:

  • \SQLEXPRESS or .\SQLEXPRESS
    For example: “stack247\SQLEXPRESS”, or simply “.\SQLEXPRESS”.
    This is older version of SQL Server Express, 2008 to be precise. It’s also installed when you install Visual Studio 2010.
  • (LocalDB)\v11.0 or (LocalDB)\v11.1
    Comes with SQL Server 2012 or Visual Studio 2012. This is a newer version of SQL Server Express, or as the folks at SQL Express team call it, an improved SQL Express. The official name is SQL Express LocalDB
  • (LocalDB)\Projects
    Mainly used as default database by SQL Data Tools to host sandbox databases for your Database projects. Just like SQL Express LocalDB, it also comes with SQL Server 2012 or Visual Studio 2012.
  • (localdb)\mssqllocaldb
    SQL Server 2014 uses this as local database. This is also a default database where Azure Storage Emulator first initialize its database.
 
Leave a comment

Posted by on December 18, 2014 in General

 

Tags: ,

Peek Your Definition in Visual Studio 2013

My friend, Scott G, told me about this. There is a new feature in Visual Studio 2013 called Peek Definition. Peek Definition allows you to see your class definition in the same file window. It even lets you edit and save the file!

You can access Peek Definition by right click on class that you want to peek and click Peek Definition. Or simply use shortcut key ALT + F12.

peek-your-definition-in-visual-studio-2013-1

peek-your-definition-in-visual-studio-2013-2

To exit from the Peek Definition, press ESC on your keyboard. You can also switch between the class definition window and your current file window by pressing SHIFT + ESC on your keyboard.

I found this very convenient feature when writing unit testing code, I can easily and quickly switch between two files.

Shortcut summary:

ALT + F12
Show Peek Definition.

ESC
Exit from Peek window.

SHIFT + ESC
Switch between Peek and current file windows.

 
Leave a comment

Posted by on December 15, 2014 in General

 

Tags:

Insertion Sort Algorithm

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

insertion-sort-algorithm

Reference: Wikipedia

 
Leave a comment

Posted by on December 12, 2014 in General

 

Tags: ,

What is the Best and Fastest Way to Flatten Data?

Given the following data set, what’s the best and fastest way to flatten them? This can be achieved with LINQ, SQL, C#, or whatever else you prefer.

001 12/5/2013 113 143 11143 44 673
001 12/6/2013 113 143 11143 44 673
001 12/7/2013 113 143 11143 44 673
001 12/8/2013 113 143 11143 44 673
001 12/9/2013 113 143 11143 44 673
001 12/10/2013 113 143 11143 44 673
002 12/5/2013 113 143 11143 44 673
002 12/6/2013 113 143 11143 44 673
002 12/7/2013 113 143 11143 44 673
002 12/8/2013 113 143 11143 44 673
002 12/9/2013 113 143 11143 44 673
002 12/10/2013 113 143 11143 44 673

Desired result:

001 12/5/2013 113 143 11143 44 673 12/6/2013 113 143 11143 44 673 12/7/2013 113 143 11143 44 673 12/8/2013 113 143 11143 44 673 12/9/2013 113 143 11143 44 673 12/10/2013 113 143 11143 44 673
002 12/5/2013 113 143 11143 44 673 12/6/2013 113 143 11143 44 673 12/7/2013 113 143 11143 44 673 12/8/2013 113 143 11143 44 673 12/9/2013 113 143 11143 44 673 12/10/2013 113 143 11143 44 673
 
Leave a comment

Posted by on December 3, 2014 in General

 

Tags: , , ,

 
%d bloggers like this: