Posts

Showing posts from April, 2016

Bubble Sorting In c Language

Keep In Mind:- 1. If there are N number of unsorted elements then N-1 number of iteration. 2. Start comparison from left to right. 3. Do comparison only with adjacent  elements (left to right). 4. T(n) = O(n2)    (worst case) 5. Best case : O(n) 6. Average case : O(n2). Basic Idea:- Given elements in an array: - 2,4,1,5,3,7 . Step 1- Choose 2 and compare with 4  =  2,4  (2<4 no swapping).                    "     4   "        "           "     1=   2,1,4  (4>1  swaping done)                     "     4   "         "         "     5=   2,1,4,5  (4<5  no swapping)                     "      5   "   ...

Insertion Sorting in C Language.

Keep in mind:- 1. Take one element at a time for sorting (i.e. one by one). 2.  Useful for sorting small data set (not used this sorting for large data sets). 3. Time complexity is Worst case =O(n2).. 4. Time complexity depend on number of compare + number of movement. 5. Sometime calls as In-Place Algorithm. 6. It may be ascending or descending orders. Basic Idea:- If you have 4 cards (numbering 4,3,7,1).           Before sorting :- 4,3,7,1.            After sorting :-   1,3,4,7. Process:- 1. Take first card (i.e. 4). 2.  Take another card 3 compare with first one, we got 4>3. So move 3 before 4. 3. Take 3rd card 7 compare with previous one 4, we got 7>4. So no need to sorting, 4. Take 4th card 1 compare with previous one 7, we got 1<7. So move one place left, again 1<4 move      left, again 1<3 move left. Therefore 1 comes at their position. Sorting Done. Alg...