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
when i reaches 3rd loop in uniqueElements1 algorithm it find a==a[j] for i==2 and j==4 and returns false.
values 5 7 9 3 9 14 i from 0-->4 0 1 2 3 4 j from 1-->5 1 2 3 4 5
so no of iteration =3 for i loop
Which solution is correct and why?
Because it doesn't seem efficient enough of solutions.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.
Nevermind i have solved itI'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