Question: For this exercise you are given a hashtable and for that hashtable you need to calculate the index positions in the table that will be

For this exercise you are given a hashtable and for that hashtable you need to calculate the index positions in the table that will be the most inefficient for performing insertion (i.e., the index positions that give the longest probe sequence) using linear probing.

For example, assume that a hashtable list has been created, and has had some keys inserted using the linear probing collision resolution technique. Given the resulting hashtable, you need to calculate the "worst" index position(s) in the table, i.e. the index position(s) in the hashtable which will generate the longest probe sequence (using linear probing). For example, consider the hashtable of size 11 below:

[88, 10, None, 25, 26, 15, None, None, None, None, 32]

Inserting at index position 3 would result in a linear probe length of 3 Inserting at index position 10 would result in a linear probe length of 3

Inserting at any other index position would result in a shorter probe sequence, therefore indexes 3 and 10 are the worst index positions. Define the get_worst_index_positions() function which takes one parameter, a Python list representing hashtable keys. The function returns a sorted list containing the worst index position (or positions, if there are multiple indexes) which would lead to equally long probe sequences. For example, the following code

values = [88, 10, None, 25, 26, 15, None, None, None, None, 32] print(get_worst_index_positions(values))

should print:

[3, 10]

because trying to insert at index positions 3 or 10 would generate equally long probe sequences - worse than any other index position in the table.

NOTE: You may find it useful to define one or more helper functions.

For example:

Test Result
values = [88, 10, None, 25, 26, 15, None, None, None, None, 32] print(get_worst_index_positions(values))
[3, 10]
values = [26, None, None, 3, 4, 16, None, 7, 20, 9, None, 11, 12] print(get_worst_index_positions(values))
[3, 7, 11

in python please.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!