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

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

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

View Full Document Right Arrow Icon
CS 61B, Midterm #3 and solutions, Spring 1996 CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3 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 __ Problem 1 __ __ __ Problem 2 __ Problem 3 __ Problem 4 __ Problem 5 __ __ Total: __/20 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. This exam comprises 10% of the points on which your final grade will be based. Partial credit will be given for wrong answers. Your exam should contain six problems (numbered O through 5) on nine pages. Please write your answers in the spaces provided in the test. file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%201996%20-%20Clancy%20-%20Midterm%203.htm (1 of 16)1/27/2007 6:33:03 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
CS 61B, Midterm #3 and solutions, Spring 1996 Anywhere you are directed to write a function, your solution may include auxiliary functions. You need not rewrite a function that appears in Deitel and Deitel, in Carrano, or in any of the CS 61B handouts; merely cite the page in the textbook or the handout in which the function appears. A few students are taking this exam next week. Do not discuss this exam with them, or post any news about the exam until next Wednesday. Relax--this exam is not worth having heart failure about. 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 (3 points, 8 minutes) A debugged version of the code for heap verification and insertion used in lab assignment 11 appears below. Buestions in parts a and b refer to this code. heaps.h class Heap ( public: Heap (ifstream&); bool IsHeap (); void Insert (int); private: int size; Vector<int> values; }; heaps.cc size(0), values(some positive integer) { int value; while (valuesIn >> value) { values[size] = value; size++; }; file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%201996%20-%20Clancy%20-%20Midterm%203.htm (2 of 16)1/27/2007 6:33:03 PM
Background image of page 2
CS 61B, Midterm #3 and solutions, Spring 1996 assert (IsHeap ()); } bool Heap::IsHeap () { for (int k=O; k<size/2; k++) { if (values[k] < values[2*k+ll) { return false; } return false; } } return true; } void Heap::Insert (int newValue) { values[size] = newValue; size++; for (int k=size-l; k>0; k = (k-1)/2) { if (values[k] < values[(k-1)/2]) { break; } int temp = values[k]; values[k] = values[(k-1)/2]; values[(k-1)/2] = temp;
Background image of page 3

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

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

This note was uploaded on 05/17/2009 for the course CS 61B taught by Professor Canny during the Spring '01 term at Berkeley.

Page1 / 16

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

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

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