exer4 - i:= h k and set j:= 0(b Probe in position i for the...

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

CMPT 307 — Data Structures and Algorithms Exercises on Elementary Data Structures. Due: Thursday, October 22th (at the beginning of the class) Reminder: the work you submit must be your own. Any collaboration and consulting outside resourses must be explicitely mentioned on your submission. 1. Suggest how storage for elements can be allocated and deallocated within the hash table itself by linking all unused slots into a free list. Assume that one slot can store a Fag and either one element plus a pointer or two pointers. All dictionary and free-list operations should run in O (1) expected time. Does the free list need to be doubly linked, or does a singly linked free list su±ce? 2. Suppose that we are given a key k to search for in a hash table with positions 0 , 1 , . . . , m - 1, and suppose that we have a hash function h that maps the key space into the set { 0 , 1 , . . . , m - 1 } . The search scheme is as follows. (a) Compute the value
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i := h ( k ), and set j := 0 (b) Probe in position i for the desired key k . If you ²nd it, or if this position is empty, terminate the search (c) Set j := ( j + 1) (mod m ) and i := ( i + j ) (mod m ), and return to the previous step Assume that m is a power of 2. (a) Show that this scheme is an instance of the general “quadratic probing” scheme by ex-hibiting the appropriate constants c, d for the corresponding equation (b) Prove that this algorithm examines every table position in the worst case. 3. Prove that no matter what node we start at in a height h binary search tree, k successive calls to Tree-Successor take O ( k + h ) time. 4. Is the operation of Deletion “commutative” in the sense that deleting x and then y from a binary search tree leaves the same tree as deleting y and then x ? Argue why or give a counterexample. 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online