Thursday, 3 August 2017

DAA PRACTICAL MANUAL: PRACTICAL 3

                                                                                           Date:  03/08/2017
Experiment No: 03

1. Experiment vision: Write a program to study and implement Bubble sort.
2. OBJECTIVE: Program to implement an array of object in C and to sorting all the   
                              elements in array.  
3. THEORY: Bubble sort, sometimes incorrectly referred to as sinking 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 the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists.
        The smallest element is bubbled from the unsorted list and moved to the sorted sub list.
     After that, the wall moves one element ahead, increasing the number of sorted elements and decreasing the number of unsorted ones.
   Each time an element moves from the unsorted part to the sorted part one sort pass is completed.
       Given a list of n elements, bubble sort requires up to n-1 passes to sort the data.
4.  PROGRAM:
#include<stdio.h>

void main()
{
   int array[10],n,i,j,swap;
  printf("Enter the Number of Elements for an array\n");
   scanf("%d",&n);

  printf("\nEnter the Number of Elements");
  for(i=0;i<n;i++)
{   scanf("%d",&array[i]);}

   for(i=0;i<n;i++)
     {
       for(j=0;j<n;j++)
        {
           if(array[i]<array[j])
          {  
              swap=array[i];
              array[i]=array[j];
              array[j]=swap;
             }
     }   }

 printf("Sorted elements are\n");
  for(i=0;i<n;i++)
 printf("%d\n", array[i]);
}

5. OUTPUT:
------------------------------------------------------------------------------------
6. conclusion:
Thus a C Programs by using array of object for bubble sorting method has been implemented and executed successfully.
7.  REMARK:
Array of element is the concepts are used for printing the values of number element and to sort the element using implementing bubble sorting method.

8. Discussion Questions:

1) what is bubble sort?
_________________________________________________________________________________________________________________________________________________________
2) How is bubble sort working explain with example? (Diagrammatically)
________________________________________________________________________________________________________________________________________________________
3) What is the complexity of bubble sort method?
____________________________________________________________________________________________________________________________________________________________

                                    

1 comment:

About Me

Hi, I am Prof. Amol Zade, working in the field of teaching and research from last more than 10 years. My area of interests are Artificial Intelligence, Wireless Networking, Algorithms. I have 16 International paper publications along with 4 International Conference; also 3 Books published. published on Object Oriented Programming with open source approach.