Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values ( but not necessarily

Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not have to have the same number of elements, they just have to have one of more copies of the same values.
If you are programming in Java, the function prototype is int equivalentArrays(int[] a1, int[] a2)
Hint: If your solution compares the length of the first array with the length of the second array or vice versa, you have misunderstood the problem!! Your solution does not need to determine which array is bigger!
Examples:
if a1 is and a2 is return
{0,1,2}{2,0,1}1(because both arrays contain the values 0,1,2)
{0,1,2,1}{2,0,1}1(because both arrays contain the values 0,1,2)
{2,0,1}{0,1,2,1}1(because both arrays contain the values 0,1,2)
{0,5,5,5,1,2,1}{5,2,0,1}1(because both arrays contain the values 0,1,2,5)
{5,2,0,1}{0,5,5,5,1,2,1}1(because both arrays contain the values 0,1,2,5)
{0,2,1,2}{3,1,2,0}0(the value 3 is not in the first array)
{3,1,2,0}{0,2,1,0}0(the value 3 is not in the second array)
{1,1,1,1,1,1}{1,1,1,1,1,2}0(the value 2 is not in the first array)
{}{3,1,1,1,1,2}0(3 is not in the first array.)
{}{}1(not possible to find a counterexample)

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Why isn't manual programming used for continuous-path NC?

Answered: 1 week ago

Question

3. What will distinguish success from failure?

Answered: 1 week ago