java notes - LINEAR SEARCH BINARY SEARCH SELECTION SORT...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
LINEAR SEARCH BINARY SEARCH
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SELECTION SORT
Background image of page 2
INSERTION SORT
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
BUBBLE SORT
Background image of page 4
QUICK SORT Find Partition (Quick Sort’s helper method)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
MERGE SORT
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
HEAP SORT public class HeapSorter { private static int [] a; private static int n; public static void sort( int [] a0) { a=a0; n=a.length; heapsort(); } private static void heapsort() { buildheap(); while (n>1) { n--; exchange (0, n); downheap (0); } } private static void buildheap() { for ( int v=n/2-1; v>=0; v--) downheap (v); } private static void downheap( int v) { int w=2*v+1; // first descendant of v while (w<n) { if (w+1<n) // is there a second descendant? if (a[w+1]>a[w]) w++; // w is the descendant of v with maximum label if (a[v]>=a[w]) return ; // v has heap property // otherwise exchange(v, w); // exchange labels of v and w v=w; // continue w=2*v+1; } } private static void exchange( int i, int j) { int t=a[i]; a[i]=a[j]; a[j]=t; }
Background image of page 8
} // end class HeapSorter HEAP SORT public class Heapsort { /** * The main method illustrates the use of a heapsort to sort a
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

java notes - LINEAR SEARCH BINARY SEARCH SELECTION SORT...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online