Midterm 2 Solutions

Assumethat thehashfunctionusedishxxmod296points probe

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e of linear probing with increment d = 5? Assume that the hash function used is h(x) = x mod 29. 6 points Probe sequence: 5, 10, 15, 20, 25 4) Consider a binary search tree application in which the same key can occur more than once. This is handled in the application by using an additional field Count that contains the number of occurrences. Rewrite the procedure insert in this case. The standard insert is shown below. (If you need a different constructor, you should write one.) 8 points BinaryTree* insert(BinaryTree* T, int x) { // inserts x into T and returns a pointer to the resulting tree if (T==null) return BinaryTree(x, null, null, 1); // a new constructor sets count to the last parameter (in this case // 1) else if (T->key < x) { T->Right = insert(T->Right, x); return T;} else if (T->key > x) { T->left = insert(T->left, x); return T;} else {T->count++; return T;} // do nothing; x is...
View Full Document

This note was uploaded on 02/08/2014 for the course CS 315 taught by Professor Kooshesh,a during the Fall '08 term at Sonoma.

Ask a homework question - tutors are online