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

The complexity ladder, The complexity Ladder: T(n) = O(1). It is ca...

The complexity Ladder: T(n) = O(1). It is called constant growth. T(n) does not raise at all as a function of n, it is a constant. For illustration, array access has this c

State an algorithm which inputs 3 - digit code for 280 items, A small shop ...

A small shop sells 280 different items. Every item is identified by a 3 - digit code. All items which start with a zero (0) are cards, all items which start with a one (1) are swee

Queues, what is the difference between data type and abstract data type

what is the difference between data type and abstract data type

Darw a flowchart to inputs top speeds of 5000 cars, Write an algorithm in t...

Write an algorithm in the form of a flowchart that: inputs top speeds (in km/hr.) of 5000 cars Outputs fastest speed and the slowest speed Outputs average (mean) s

Algorithm to sort a given list by quick sort method, Q. Write down an algor...

Q. Write down an algorithm to sort a given list by making use of Quick sort method. Describe the behaviour of Quick sort when input given to us is already sorted.

Program, insertion and deletion in a tree

insertion and deletion in a tree

Multiple queue, #questionalgorithm for implementing multiple\e queues in a ...

#questionalgorithm for implementing multiple\e queues in a single dimensional array

Show that towers of hanoi is o (2n), Question 1 Discuss the advantages of ...

Question 1 Discuss the advantages of implementation checks preconditions Question 2 Write a ‘C' program to search for an item using binary search Question 3 Show that To

Inorder and preorder traversal to reconstruct a binary tree, Q. Using the f...

Q. Using the following given inorder and preorder traversal reconstruct a binary tree Inorder sequence is D, G, B, H, E, A, F, I, C

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