Sunday, March 10, 2019

SORTING

  There are a number of sorting techniques that can be employed to sort a given list of data elements.the suitability of a specific techniques in the specific situation depends on a number of factors,such as

  1. Size of the data structure. 
  2. Algorithm efficiency.
  3. Programmer's knowledge of the technique.
 While all the sorting methods produce the same results, that is a list of sorted elements, it is one or more of the above factors that play an important role in choosing a specific sorting technique in a given situation.

Sorting techniques:

  • Consider a list L containing 'n' elements,as shown 
                           L1 ,L2,L3........,Ln
  • Now there are n! ways in which the elements can be arranged within the list.we can apply a sorting technique to the list L to arrange  the elements in either ascending or descending order.
  • If we sort the list in ascending order,then
                  L1<=L2<=L3........<=Ln
  • Alternatively,if we arrange the list in descending order,then
                  L1>=L2>=L3........>=Ln
  • A telephone directory is one such example where both sorting and searching technique are applied.
EXAMPLE 

   Consider an array A containing 5 elements,as shown below
What would be the resultant array if it is sorted in ascending order & descending order?

Solution:

         (a)Array A sorted in ascending order.
                          
         (b)Array A sorted in descending order.
                          
The number of Sorting methods are given below:
             (1)Insertion sort
           (2)Selection sort
           (3)Shell sort
           (4)Bubble sort
           (5)Quick sort
           (6)Merge sort
           (7)Radix sort
  • All sorting techniques which require the data set to be present in the main memory are referred as internal sorting techniques.
                               *******

No comments:

Post a Comment