Bubble sort, Data Structure & Algorithms

Assignment Help:

In this sorting algorithm, multiple swapping occurs in one pass. Smaller elements move or 'bubble' up to the top of the list, so the name given to the algorithm.

In this method, adjacent members of list to be sorted are compared. If item over the top is greater than the item instantly below it, then they are swapped. This procedure is carried on until the list is sorted.

The detailed algorithm is like as:

Algorithm: BUBBLE SORT

1. Begin

2. Read the n elements

3. for i=1 to n

              for j=n downto i+1

               if a[j] <= a[j-1]

              swap(a[j],a[j-1])

4. End // of Bubble Sort

Total number of comparisons in Bubble sort will be:

= (N-1) +(N-2) . . . + 2 + 1

= (N-1)*N / 2 =O(N2)

This inefficiency is because of the fact that an item moves only to the next position in each pass.


Related Discussions:- Bubble sort

Data Structure, Ask consider the file name cars.text each line in the file ...

Ask consider the file name cars.text each line in the file contains information about a car ( year,company,manufacture,model name,type) 1-read the file 2-add each car which is repr

Depth of complete binary tree, What will be depth do , of complete binary t...

What will be depth do , of complete binary tree of n nodes, where nodes are labelled from 1 to n with root as node and last leaf node as node n

Define techniques of dry running of flowcharts, Explain the term- Dry runni...

Explain the term- Dry running of flowcharts  Dry running of flowcharts is essentially a technique to: Determine output for a known set of data to check it carries out th

Psedocodes, write a pseudocode to input the top speed (in km''s/hours) of 5...

write a pseudocode to input the top speed (in km''s/hours) of 5000 cars output the fastest speed and the slowest speed output the average (mean) speed of all the 5000 cars answers

Nonrecursive implementation of a recursive algorithm?, What data structure ...

What data structure would you mostly likely see in a nonrecursive execution of a recursive algorithm? Stack

What is assertions and abstract data types, Assertions and Abstract Data Ty...

Assertions and Abstract Data Types Even though we have defined assertions in terms of programs, notion can be extended to abstract data types (which are mathematical entities).

Process of analysis, The objective analysis of an algorithm is to determine...

The objective analysis of an algorithm is to determine its efficiency. Efficiency is based on the resources which are used by the algorithm. For instance, CPU utilization (Ti

Present the algorithm of binary search. , B i n a ry Search Alg...

B i n a ry Search Algorithm is given as follows 1. if (low > high) 2.     return (-1) 3. mid = (low +high)/2; 4. if ( X = = a [mid]) 5.      return (mid); 6.

Determine the critical path and the expected completion, The information in...

The information in the table below is available for a large fund-raising project. a. Determine the critical path and the expected completion time of the project. b. Plot the total

Write the algorithm to find input and output value, This algorithm inputs 5...

This algorithm inputs 5 values and outputs how many input numbers were positive and how many were negative. Data to be used: N = 1, -5, 2, -8, -7

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd