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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started