Question: This is java Given two arrays of integers a[] and b[], design two algorithms to determine whether the two arrays contain precisely the same set
This is java
Given two arrays of integers a[] and b[], design two algorithms to determine whether the two arrays contain precisely the same set of points (though possibly in a different order).
(2a) Design an algorithm for the problem whose running time is linearithmic in the worst case and uses at most constant extra space.
The solution proposed in class was to sort both arrays, then compare the sorted arrays. How can we sort in linearithmic guaranteed time and constant extra space? (discuss this in your README).
(2b) Design an algorithm for the problem whose running time is linear under reasonable assumptions and uses at most linear extra space.
The solution proposed in class was to place all elements from one array in a hash table, then test if all elements in the other are present. What assumption does this make about your hashing function? (README)
Implement these two solutions in the context of the CompareTwoArrays.java file I've provided. You'll need to fill in details for the functions compareWithHeap() and compareWithHash().
Test using pairs of arrays from the folder single_arrays/. In this folder, there are arrays of lengths ranging from 100 (e.g. 100A.txt) to 10 million (e.g. 10mA.txt) integers, with a trio of files for each length of array. The A and B variant should match, while C should not match A or B.
How effective are these the two methods you've implemented? (a) do they work, and (b) what are the run times of the approaches? What is the impact of the method of collision detection, and the size of the underlying array? Document these in your README.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
