Computer Science 61B - Fall 1995 - Yelick - Midterm 2

Computer Science 61B - Fall 1995 - Yelick - Midterm 2 -...

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

View Full Document Right Arrow Icon
CS61b, Midterm #2, Fall 1995 CS61B, Fall 1995 Midterm #2 K. Yelick Problem #1 a. (2 points) Show the binary search tree (BST) that would result from applying the following operations to the given BST: insert(6), insert(8), delete(10), delete(7). (Just show the final BST.) b. (2 points) Given below is a hash table with space for 5 entries. Assume we are using the (naive) hash function: key % 5 . What will the table look like after the following 4 operations, assuming we are using chaining: insert(2), insert(8), insert(17), insert(12). c. (2 points) Redo the previous problem assuing we are using linear probing d. (2 points) Show the value of the heap that would result after inserting the following elements in this order: 19, 4, 20, 12, 18, 3, 32, 5. file:///C|/Documents%20and%20Settings/Jason%20Rafte. ..0-%20Fall%201995%20-%20Yelick%20-%20Midterm%202.htm (1 of 6)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, Midterm #2, Fall 1995 e. (3 points) The list class is built using listNode objects. Allysa P. Hacker has decided to write a destructor for the listNode objects, using the code given below. Will this function work? If not, describe what is wrong. //Precondition: this != NULL. //Postcondition: Delete this node and all nodes accessible through it. listNode::~listNode() { assert (this != NULL); listNode* list = this; while (list != NULL) { tempPtr = list; list = list->Next; delete tempPtr; } } f. (2 points) Draw an inheritance hierarchy for the following classes: class B : public C { ... }; class C { ... }; class A : public D { ... }; class D : public C { ... }; Problem 2. (6 points) Henry Pointerdexter is modifying his 61b Ataxx project to play the game of tic-tac-toe. The game of tic- tac-toe is played on a 3x3 board using white and black pieces. At each step, a player may place a piece on any open square. The goal of the game is to get three of your pieces in a row: left-right, up-down, or diagonally. The key function in Henry's MachinePlayer class is a recursive function that looks for the best move by doing backtracking search of the "game tree." Below is a sketch of his code. (There is nothing
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.

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 / 6

Computer Science 61B - Fall 1995 - Yelick - Midterm 2 -...

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