top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between bubble sort and selection sort?

0 votes
3,504 views

both seems to be same, can someone explain the difference with example and complexity?

posted Sep 8, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Both of them have same time complexity i.e. O(n2).
Here I'm assuming an unsorted array. For example: int a[7] = {3,4,1,2,5,7,6}; and operation is ascending order.

Bubble Sort: it's focus on element, by swapping it move the largest element to a[6] position in first iteration,
In the second iteration, it moves second largest element to the a[5] position and so on.

Selection Sort: It does just reverse operation of bubble sort. In the first iteration, it selects the smallest element from array and put into the first position. And in the second iteration, it does the same thing for the second smallest element and so on.

answer Sep 10, 2014 by Neelam
Similar Questions
+2 votes

Can someone share the C code for selection or bubble sort for string. String comparison should be based on dictionary comparison.

+3 votes

1) Implement both algorithms
2) Test both on three cases of data:
a) sorted in increase order,
b) sorted in decrease order,
c) randomly
3) Use data of different sizes: 10000, 100000, 1000000.

...