Algorithms question help

View attachment 10794
Solution 1

A) 5,7,9,3,9,14
Compare 5 with 7,9,3,9,14 (no match)
Compare 7 with 9,3,9,14 (no match)
Compare 9 with 3,9 (match 9=9) so returns false.


Solution 2

A) array values are
values5793914
i from 0-->401234
j from 1-->512345
when i reaches 3rd loop in uniqueElements1 algorithm it find a==a[j] for i==2 and j==4 and returns false.
so no of iteration =3 for i loop

Which solution is correct and why?


Why do you think only one is correct? As far as I can see they are describing the same events.

The issue for me is, what does your teacher mean by "trace"? What format is appropriate, and what level of detail is required? Both of these explanations are incomplete, but show that you have understood the algorithm.
 
Why do you think only one is correct? As far as I can see they are describing the same events.

The issue for me is, what does your teacher mean by "trace"? What format is appropriate, and what level of detail is required? Both of these explanations are incomplete, but show that you have understood the algorithm.
Because it doesn't seem efficient enough of solutions.
Trace in a table with i, j, a==a[j] outcomes till final return outcome.
 
Because it doesn't seem efficient enough of solutions.
Trace in a table with i, j, a==a[j] outcomes till final return outcome.


I'm not sure what you're saying. How does this explain your asking which is correct, or tell me what format you were taught to use?

If you were told to trace a program, you just do that; they didn't say it was an efficient algorithm! (Maybe that's what algorithm 2 is ...)
 
I'm not sure what you're saying. How does this explain your asking which is correct, or tell me what format you were taught to use?

If you were told to trace a program, you just do that; they didn't say it was an efficient algorithm! (Maybe that's what algorithm 2 is ...)
Nevermind i have solved it :)
 
Nevermind i have solved it :)

That's good.

In case anyone else who has been reading this would benefit, you might want to briefly tell us how you solved your issue; but I understand if you don't.
 
Top