Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please don't copy / paste answers from similar questions, all are wrong! In this next scenario, inspired by RAID 1, we will just duplicate all
Please don't copy / paste answers from similar questions, all are wrong!
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 N is created: for each element i of A, the value A[i] is hashed to give an indexj 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: 75 64 @ 1 2 3 B: 5476 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. 2. Briefly explain how the method above could be adapted to allow for repeated integers in array A. 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 N is created: for each element i of A, the value A[i] is hashed to give an indexj 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: 75 64 @ 1 2 3 B: 5476 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. 2. Briefly explain how the method above could be adapted to allow for repeated integers in array AStep 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