{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Computer Science 61B - Spring 2001 - Clancy - Midterm 3

# Computer Science 61B - Spring 2001 - Clancy - Midterm 3 -...

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
CS61B Spring 2001 Midterm #3 Problem 0 (1 point, 1 minute) Put your login name on each page. Also make sure you have provided the information requested on the first page. Problem 1 (5 points, 15 minutes) Consider the code given below, which applies the heapsort algorithm to sort the values in the argument array in place. /* * REQUIRES: values is an initialized array; * MODIFIES: values. * EFFECTS: Sorts the elements of values from smallest to largest. */ public static void heapSort (int [ ] values) { if (values.length <= 1) { return; } changeToMaxHeap (values); for (int k=values.length-1; k>0; k--) { int temp = values[k]; values[k] = values[0]; values[0] = temp; reheapifyDown (values, 0, k); } } /* * REQUIRES: values is an initialized array; * 0 heapSize values.length; 0 index < heapSize; * in the "almost-heap" rooted at values[index], * only values[index] may violate the heap property. * MODIFIES: values. * EFFECTS: Moves values[index] down in its subheap if necessary * so that all nodes in the heap rooted at values[index] satisfy * the heap property. */ private static void reheapifyDown (int [ ] values, int index, int heapSize) . .. /* * REQUIRES: values
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

Computer Science 61B - Spring 2001 - Clancy - Midterm 3 -...

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

View Full Document
Ask a homework question - tutors are online