0
$\begingroup$

I'm not so much confused as to write the actual code as I am to write the pseudocode.

To determine if two arrays of the same size contain the same elements, I know you would need two for loops, then compare one element in the first array to each element in the second array, and repeat this for each element in the first array, stopping the loops if there are no elements that match. But is there a faster way to do this? If not, how would I go about putting the for loops into pseudocode?

$\endgroup$
  • 8
    $\begingroup$ Hints: what happens to the speed if you sort the arrays? $\endgroup$ – jmite Apr 19 '15 at 17:15
  • 3
    $\begingroup$ Are you saying you know how to write actual runnable code for this, but not pseudocode? Why do you think it has to be so different? $\endgroup$ – Juho Apr 19 '15 at 18:19
  • $\begingroup$ Pseudocode is just loose code designed to be more readable. If you know how to write the real code, write it, and then if something seems at all unclear, restate it in a more natural language way. In your case I don't think the pseudocode looks much different. The case is just so simple. $\endgroup$ – Jake May 1 '15 at 6:22
  • $\begingroup$ Take jmite's hint (it will be faster) then follow Jake's idea. If you know anything about arrays or can afford expected complexity (which might degrade) you can use one hash array, input elements from first array and then delete elements from the second and terminate if element was not found. $\endgroup$ – Evil Jun 15 '16 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.