Comparison of algorithms:
In this table, n is the number of records to be sorted. The columns "Average" and "Worst" give the time complexity in each case, under the assumption that the length of each key is constant, and that therefore all comparisons, swaps, and other needed operations can proceed in constant time. "Memory" denotes the amount of auxiliary storage needed beyond that used by the list itself, under the same assumption. These are all comparison sorts. The run time and the memory of algorithms could be measured using various notations like theta, sigma, Big-O, small-o, etc. The memory and the run times below are applicable for all the 5 notations.
20 !
20 !
25 !
05 !
Depends
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
Yes
No
No
Yes
Yes
No
Yes
Yes
No
Partitioning
Merging
Selection
Insertion
Partitioning & Selection
Selection
Insertion & Merging
Insertion
Exchanging
Insertion
Insertion
Insertion
Insertion & Selection
Selection
Selection
Selection
Exchanging
Exchanging
Exchanging
Merging
Luck
Quicksort can be done in place with O(log(n)) stack space, but the sort is unstable[citation needed]. Naïve variants use an O(n) space array to store the partition. An O(n) space implementation can be stable[citation needed].
Used to sort this table in Firefox [2].
Average case is also
20 !
20 !
20 !
50 !Depends
00 !
20 !
20 !
20 !
15 !
25 !
25 !
00 !
50 !—
25 !
20 !
20 !
05 !
, where d is the number of inversions
Used in SGI STL implementations
Its stability depends on the implementation. Used to sort this table in Safari or other Webkit web browser [3].
25 !
25 !
00 !
15 !
20 !
20 !
15 !
15 !
23 !
23 !depends on gap sequence. Best known: O(nlog2n)
25 !
00 !
comparisons when the data is already sorted or reverse sorted.
Tiny code size
When using a self-balancing binary search tree
In-place with theoretically optimal number of writes
Finds all the longest increasing subsequences within O(n log n)
An adaptive sort -
15 !
25 !
00 !
15 !
20 !
20 !
15 !
50 !—
50 !—
50 !—
15 !
25 !
25 !
00 !
20 !
25 !
15 !
50 !—
20 !
20 !
15 !
20 !
00 !
50 !—
15 !
20 !
20 !
25 !
25 !
00 !
50 !—
15 !
50 !—
25 !
25 !
00 !
25 !
00 !
25 !
25 !
25 !
00 !
15 !
45 !
45 !
00 !
The following table describes integer sorting algorithms and other sorting algorithms that are not comparison sorts. As such, they are not limited by a lower bound. Complexities below are in terms of n, the number of items to be sorted, k, the size of each key, and d, the digit size used by the implementation. Many of them are based on the assumption that the key size is large enough that all entries have unique key values, and hence that n << 2k, where << means "much less than."
to know more : http://en.wikipedia.org/wiki/Sorting_algorithm
Code to determine Leap Year
if year modulo 400 is 0
then is_leap_year
else if year modulo 100 is 0
then not_leap_year
else if year modulo 4 is 0
then is_leap_year
else
not_leap_year
Longest common substring problem
http://en.wikipedia.org/wiki/Longest_common_substring_problem
Finding the longest substring in a string without repetition
http://analgorithmaday.blogspot.com/2011/05/finding-longest-substring-in-string.html
Find the longest duplicated substring in C
http://snippets.dzone.com/posts/show/6516
External Links: