You are on page 1of 1

IT5003: Data Structure and Algorithm

Semester I, 2019/2020

Practical Exam – Preview (23rd November, 2019)

Task 1. Hash? [X marks]


Note: this is just lab question 3a from TL06. Only for you to familiarize the "PE mode" of
coursemology. There is no need to actually get the correct answer . Try submitting to get
the feel. In PE, you are limited to FIVE submissions (per problem). i.e. you have to do more
checks locally on PC instead of using Coursemology as "debugger".

[Hash Table – Opening Addressing Simulation] We choose to "simulate" one aspect of the
hash table instead of implementing a complete hash table. Write the following function that
returns the probe sequence as a Python list. For simplicity, we use the primary hash
function h(key) = key % m, where m is the table size. You can assume m is > 3.

1. Linear Probing: Given table size m and key k, return the probe sequence that goes
from [ h(k), h(k)+1, …., m-1, 0, …. h(k)-1]. This function returns m probes.
def linearProbe( m, k ):
""" Return the linear probe sequence as a Python List."""
Example:
linearProbe(11, 35)  [2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1]
linearProbe(7, 35)  [0, 1, 2, 3, 4, 5, 6]

Sample skeleton code (just like normal lab exercise) will be given.

Task 2. Something crazier


There will be two question to solve in the PE. Usually, the second question is harder. Read
both questions and choose how you want to attempt the problems.

~~~ End of PE Question ~~~

1|Page

You might also like