Skip to main content

Bubble Sort

BubbleSort
                                 It is an inplace and comparison based sorting techoique.
                                 In this algorithm each element is compared to its next element if they and not 'n' corooct order then swap these data item  go to the next element.
     
Algorithm of Bubble Sort
   
      Bubblesort( a[Max],n)
         This algo arrange the item of              array in asscending order
         a[Max]=a[0 to Max-1]
        n= NO. of item in array
STEP 1. Start
STEP 2.for i=1 to n-1 do 
              (a){ for j=0 to n-1-i do
                   if (a[j]>a[j+1]) trhen
                   swap (a[j] and a[j+1] }
STEP 3. stop

Time Complexity
  Total Comparesion=(n-1)+(n-2)+_                                               _ _+3+2+1
                                             =N\2(a+l)
+n-1\2(n-1+1)
+(m-1)\2=
T








Program of Bubble Sort

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int a[20],n,i,j,i,team;
  cout<<"enter the size of array:";
  cin>>n;
  cout<<"enter the array element:";
for(i=0; i<n; i++)
{
   cin>>a[i];
}
for(i=1; i<n; i++)
{
  for(j=0; j<n-1; j++)
  {
     if(a[j]<a[j+1])
      {
            team=a[j];
           a[j]=a[j+1];
          a[j+1]=team;
      }
   }
}
cout<<"array after bubble sort:";
for(i=0; i<n; i++)
{
   cout<<"  "<<a[i];
}
getch();
}

Popular posts from this blog

PHYSICS, B.sc. SEMESTER V EXAMINATION,2018

  Subject:- PHYSICS (BPH-E501), Digital and Analog Circuits and Instrumentation

MATHEMATICS, B.sc. SEMESTER V EXAMINATION,2018

Subject- MATHEMATICS (BMA-E503), Linear Algebra

COMPUTER SCIENCES, B.sc. SEMESTER II EXAMINATION,2018

Subject- COMPUTER SCIENCES (BCS-C-201), Data Structure ➡️Sessional Exam paper 2    Department of Computer science, GKV, Haridwar 1st Sessional Exam ( 2017-18)                   B.sc. II Semester      BCS-C201:Data  Structure and File              Processing Time: 1 hr.                          Maximum Marks: 20                         Section -A Note: Attempt all questions . Each question carries equal marks. ( 2 × 2 = 4 ) Q.1 What do you understand by Linked Queue & Linked Stack? Q.2 Compare Array and Linked List.                        Section-B Note: Attempt any two  questions. Each question carries equ...