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

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

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

View Full Document Right Arrow Icon
CS61B Spring 2001 Midterm #3 CS61B Spring 2001 Midterm #3 Professor Mike Clancy Read and fill in this page now. Do NOT turn the page until you are told to do so. Your name: Your login name: Your lab section day and time: Your lab t.a.: Name of the person sitting to your left: Name of the person sitting to your right: Problem 0 Total: /20 Problem 1 Problem 2 Problem 4 Problem 3 This is an open-book test. You have approximately fifty minutes to complete it. You may consult any books, notes, or other paper-based inanimate objects available to you. To avoid confusion, read the problems carefully. If you find it hard to understand a problem, ask us to explain it. If you have a question during the test, please come to the front or the side of the room to ask it. Some students are taking this exam late. Please do not talk to them, mail them information, or post anything about the exam to news groups until after Wednesday. This exam comprises 10% of the points on which your final grade will be based. Partial credit may be given for wrong answers. Your exam should contain five problems (numbered 0 through 4) on twelve pages. Please write your answers in the spaces provided in the test; in particular, we will not grade anything on the back of an exam page unless we are clearly told on the front of the page to look there. Relax--this exam is not worth having heart failure about. file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%202001%20-%20Clancy%20-%20Midterm%203.htm (1 of 10)1/27/2007 5:40:36 PM
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online