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
Unformatted text preview: CS61B, Midterm #2, Spring 1995 CS61B, Spring 1995 Midterm #2 Professor P. N. Hilfinger Throughout this test, assume that the following declarations and definitions are available. (It is adapted from $master/include/List.h and here for your convenience. There is nothign new here.) You may also freely use the classes (or template classes) Stack, Map, String1, Vector, or any other type introduced in labs, homeworks, or lectures. template <class T> class List { public: T head; /* First element. */ List<T>* tail; /* Rest of list. */ /* A List with a head initialized to head0, and */ /* a tail initialized to tail0. */ List(T head0, List<T>* tail0 = NULL) { head = head0; tail = tail0; } }; Problem #1 file:///C/Documents%20and%20Settings/Jason%20Rafte...Spring%201995%20%20Hilfinger%20%20Midterm%202.htm (1 of 5)1/27/2007 6:31:31 PM CS61B, Midterm #2, Spring 1995 Tell whether each of the following is true or false. In each case, give a brief explanation where possible; for false entries, this should take the form of a counterexample. Assume that comparisons always take constant time. a. If all items in a heap are distinct, the secondsmallest item in a heap has no children (assuming the heap is ordered with the largest item at the top). b. Suppose that an ordinary binary tree (not a search tree) obeys the heap property  that the value of any node is at least as large as that of any of its children. Then inserting a new item into this tree while maintaining the heap property requires time O(lg n) , where n is the number of nodes in the tree....
View
Full
Document
This note was uploaded on 05/17/2009 for the course CS 61B taught by Professor Canny during the Spring '01 term at University of California, Berkeley.
 Spring '01
 Canny
 Computer Science

Click to edit the document details