Computer Science 61B - Summer 1996 - Huang - Midterm 2

Computer Science 61B - Summer 1996 - Huang - Midterm 2 - CS...

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

View Full Document Right Arrow Icon
CS 61Bc, Midterm #2, Summer 1996 CS61B, Summer 1996 Midterm #2 Question 1 [6 points total]: Heap on the medals, please Suppose that a character array G , to be sorted into alphabetical order via heapsort, initially contains the following sequence of characters: O L Y M P I C S In this situation the search keys are characters, and a search key is considered is ">" another search key if it occurs earlier in the alphabet. Please circle your answers for each part. If you wish, show your work neatly to receive partial credit in case your answer is wrong. Part A. (2 pts) We can transform an array into a heap by calling Rebuild Heap (see Carrano 11) on each element in the last array, from last to first. Show how the characters would be arranged in the array after transforming the above array into a heap. Part B. (3 pts) Suppose that instead of starting with a filled array and then transforming it into a heap, we start with an empty heap and successively insert the characters in "OLYMPICS" from "O" to "S". Show how the characters would be arranged in the array after adding all eight characters into the heap. How many comparisons of search keys are done in total after inserting all eight characters into the heap? file:///C|/Documents%20and%20Settings/Jason%20Raf. ..20Summer%201996%20-%20Huang%20-%20Midterm%202.htm (1 of 10)1/27/2007 6:33:02 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 61Bc, Midterm #2, Summer 1996 Part C. (1 pt) Using the heap from Part B, show how the characters would be arranged in the array after removing the first two items from the heap. Question 2 [7 points total] Let's hash this out This problem contains three independent parts that all concern hash table. You should assume for this problem that there are no problems with arithmetic overflows. i.e., that the machine can handle arbitrarily large numerical values. Part A. (2 pts) Suppose that we implement a hash table using a character array of size 13 to store the keys themselves. Show the contents of the array when the keys S I L V E R M E D A L are inserted in that order into an empty hash table with linear probing to resolve conflicts. Use h(k) = k mod 13 as the hash function for the k th letter of the alphabet. (Note: S = 19th letter of alphabet, I = 9th, L = 12th, V = 2nd, E = 5th, R = 19th, M = 13th, E = 5th, D = 4th, A = 1st, L = 12th.) Circle those keys that encountered collisions when they were inserted into the table. Part B. (3 pts) Suppose you wish to make a hash table of all the computer science students at UC Berkeley using as the key each student's ID number, and suppose you have decided to implement the hash table using an unsigned long integer array of size 499, with quadratic probing to resolve conflicts. (by the way, both
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 - Summer 1996 - Huang - Midterm 2 - CS...

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