Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

- Sorting bubble-sort anim by Fajar Zain 1341 views
- Bubble sorting lab manual by maamir farooq 83 views
- Matlab by Kelin Jose 1087 views
- PANCASILA (makalah falsafah pancasi... by tita_chubie 519 views
- bubble sorting of an array in 8086 ... by universty of gujrat 8272 views
- Sorting (Bubble,Merge,Selection sort) by oDesk 812 views

3,964 views

Published on

No Downloads

Total views

3,964

On SlideShare

0

From Embeds

0

Number of Embeds

65

Shares

0

Downloads

90

Comments

0

Likes

1

No embeds

No notes for slide

- 1. by: Luisito G. Trinidad MSIT
- 2. Bubble Sort • Sorting takes an unordered collection and makes it an ordered one. • Bubble sort algorithm*: • Compare adjacent elements. If the first is greater than the second, swap them. • Do this for each pair of adjacent elements, starting with the first two and ending with the last two. At this point the last element should be the greatest. • Repeat the steps for all elements except the last one. • Keep repeating for one fewer element each time, until you have no more pairs to compare • Time complexity: O(n2)
- 3. NOTE: As always, it's better if you don't write your own sorts. Java has better sort methods in java.util.Arrays.sort(...) and java.util.Collections.sort(...). But sorts are excellent practice, and are a technique that all students are expected to understand to some extent.
- 4. Working of bubble sort algorithm???
- 5. Sample value 12,9,4,99,120,1,3,10
- 6. SAMPLE CODE
- 7. public class bubbleSort{ public static void main(String a[]){ int i; int array[] = {12,9,4,99,120,1,3,10,23}; System.out.println("Values Before the sort:n"); for(i = 0; i < array.length; i++) System.out.print( array[i]+" "); System.out.println(); bubble_srt(array, array.length); System.out.print("Values after the sort:n"); for(i = 0; i <array.length; i++) System.out.print(array[i]+" "); System.out.println(); System.out.println("PAUSE"); }public static void bubble_srt( int a[], int n ) { int i, j,t=0; for(i = 0; i < n; i++){ for(j = 1; j < (n-i); j++){ if(a[j-1] > a[j]){ t = a[j-1]; a[j-1]=a[j]; a[j]=t; } } } } }
- 8. Bin Sort
- 9. Bucket sort, or bin sort, is a sorting algorithm that works by partitioning an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a cousin of radix sort in the most to least significant digit flavour. Bucket sort is a generalization of pigeonhole sort. Since bucket sort is not a comparison sort, the Ω(n log n) lower bound is inapplicable. The computational complexity estimates involve the number of buckets.
- 10. Elements are distributed among bins
- 11. www.bantayog.net63.net End.

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment