Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and Algorithms I

Similar presentations


Presentation on theme: "Data Structures and Algorithms I"— Presentation transcript:

1 Data Structures and Algorithms I
CMP 338 Data Structures and Algorithms I Day 13, 10/18/11 Balanced Search Trees

2 Good Pivot int goodPivot(double[] a, int lo, int hi) int n = hi-lo+1,
for (int i=0; i<n/5; i++) median5(a, lo+i*5) exch(a, lo+i, lo+i*5+2) select(a, lo, lo+n/5-1, lo+n/10) return lo+n/10 void median5(double a, int n) for (int i=n; i<n+3; i++) for (int j=i+1; j<n+5) if (a[j]<a[i]) exch(a, i, j)

3 Homework 10, due noon 10/21 Improve quicksort (any variant)
Use insertion sort to sort small regions static void setSmall(int s) static int getSmall() Find the best value for small Turn in (include your name in a comment) a) working code for your program Homework10.java b) performance numbers (standard out) hw10.txt c) performance graphs hw10.doc or hw10.odt d) your interpretation of the data hw10.doc or hw10.odt

4 Improved Quicksort? quicksort(double[] a) // StdRandom.shuffle(a);
quicksort(a, 0, ||a||-1) if (0 < small) insertionSort(a) quicksort(double[] a, int lo, int hi) if (hi<=lo + small) return; int j = partition(a, lo, hi) sort(a, lo, j-1) sort(a, j+1, hi)


Download ppt "Data Structures and Algorithms I"

Similar presentations


Ads by Google