Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 21 (10 points) Suppose you are given an arrays a[] and b[] each containing distinct numbers (ie, they have no repeated numbers). Both arrays

image text in transcribed
Question 21 (10 points) Suppose you are given an arrays a[] and b[] each containing distinct numbers (ie, they have no repeated numbers). Both arrays are unordered (ie, they are not sorted). Further, suppose that a. length s b.length; thus all is the smaller array. For the purposes of this question, suppose a[] is much smaller than b[ ] (for example a. length = 10,000 and b.length = 10,000,000 000,000.) Design an algorithm to determine how many numbers there are in common between the two arrays. Let M = a.length and N = b.length. In the worst case, your algorithm must run in time proportional to Mog M. Only partial credit for Nlog N. Write your algorithm in Java. You may use any algorithms or data structures that we have discussed in class, without defining them. For example, you can create a Stack or a MinPQ. You can also assume that you have access to algorithms implemented on arrays, such as swap, swim, heapSort, and binarySearch, with reasonable parameter and return types. For each operation, make sure it is clear which array you are working on: al] or b[]. Be sure to include a return statement, to return the result. public static int number InComon (double) a doublet) b) { sue a much smaller than

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions