Question: 5. THE THIRD PART: THE R1 SEARCH ALGORITHM In this next scenario, inspired by RAID 1, we will just duplicate all the given data using

 5. THE THIRD PART: THE R1 SEARCH ALGORITHM In this nextscenario, inspired by RAID 1, we will just duplicate all the given

5. THE THIRD PART: THE R1 SEARCH ALGORITHM In this next scenario, inspired by RAID 1, we will just duplicate all the given data using hashing. Given an array A of non-negative integers of length N, a second array B of length Nis created: for each element i of A, the value A[i] is hashed to give an index j of B, and the value A[i] is stored in B[j]. For the hashing function, given constants a>0 and b, for each i, the value A[i] is hashed by the function (a*A[i] + b) mod N, which is equal to the index of B into which we store i. The following example demonstrates this: A: 7 5 6 4 1 2 3 B: 5 4 7 6 0 1 2 3 In this example the hash function is (3*A[i] + 1) mod 4. For instance, the value 5 stored at index 1 in A is hashed to the value (3*5 + 1) mod 4 = 0, and thus 5 is stored at B[0]. In this example there were no collisions in the hashed values since all values in A are distinct. For this task we assume there are no repeated values in A, and a hash function is chosen so there are no collisions for distinct values. To look for errors we hash all the values in array A to see if there is a match in the corresponding element of array B. If there is a mismatch between the two elements then an error is returned; if no errors are found, if a value is found then its index in A is returned. Task 4: Complete the following: 1. Write a pseudocode function R1(key, a, b, A, B, N) that takes non-negative integers key, a and b where a and b come from to the hashing function used to store indices in B; the arrays A and B of length N are also inputs: the function should return an index i where the value key is stored in array A if found; it should return -1 if the value cannot be found; otherwise it should return -2 if there was an error in the data storage, i.e. one of the values was altered unintentionally in at most one of the arrays. (8 marks] 2. Briefly explain how the method above could be adapted to allow for repeated integers in array A. [6 marks]

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!