Insertion sort is a simple algorithm. Insertion sort logic works as follows: To insert an element in an already existing set, we make room for the new item by moving larger items one position to the right. Then insert the new item at the newly available position. The algorithm most often used to sort cards in […]
SB Right – Large Image List
Selection sort is one of the simplest sorting algorithms. It is easy to implement but it is not very efficient. 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 […]
Computing height of a tree in Computer Science is very common. Most of the examples and online discussions talk about computing the height of a Binary Tree. The example method I am sharing can be used to compute the height of any tree. So even if you have a non-Binary tree, you can use this method […]
Quite often in our day to day programming, we need to compute how long does a specific portion of the code takes to complete. For e.g; you might want to check how long does a method take to complete. In Java, the simplest way to accomplish this is to use System.nanoTime() method. Following example shows […]
Here is a utility method to check if a given String is a valid Social Security number using Java Regular Expression.