# Category Archives: Code Lib

an online library of common codes

## Bubble Sort java code

Bubble sort  is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in wrong order. We make several passes over the list till no swaps are needed, which indicates that the list is sorted. For more information on bubble sort visit http://en.wikipedia.org/wiki/Bubble_sort. Complexity… Read More »

## Binary Search java code

Binary Search finds the position of a specified value (key) in a sorted array.In each step it discards half of the elements to search , thus the worst case running time of binary search is O(log n).Believe it or not 80 out of 100 of the programmers fail to write the correct code for binary… Read More »

## Counting Sort

Counting Sort is not a comparison sort.Counting sort assumes that each of the input element is an integer in the range 0 to k, for some integer k. When k=O(n), the sort runs in O(n) time. The basic idea of counting sort is to determine, for each input element x, the number of elements less… Read More »

## Binary Search code

Binary Search finds the position of a specified value (key) in a sorted array.In each step it discards half of the elements to search , thus the worst case running time of binary search is O(log n).Believe it or not 80 out of 100 of the programmers fail to write the correct code for binary… Read More »