A
ak
Is it possible to find repeated(duplicate) element in an array in
single loop ?
AK
single loop ?
AK
Is it possible to find repeated(duplicate) element in an array in
single loop ?
Is it possible to find repeated(duplicate) element in an array in
single loop ?
Of course. As long as you don't mind if the loop has quite a lot of
iterations.
Is it possible to find repeated(duplicate) element in an array in
single loop ?
Is it possible to find repeated(duplicate) element in an array in
single loop ?
AK
Is it possible to find repeated(duplicate) element in an array in
single loop ?
AK
Is it possible to find repeated(duplicate) element in an array in
single loop ?
Yes u can using a single pass of a loop....
but it may use an extra array space and the integer range shoould be
specified...
consider the array NUM[1...n]
consdier all numbers in the array are within the range 1...k then we
have another array A from 1...k
then the loop would be...
for(i=0;i<n;i++)
{
if(A[NUM]==0)
{
A[NUM]=1;
}
if(A[NUM]==1)
{
printf("%d",NUM);
}
}
this loop structure prints only the repeated elements in an array of
integers....
Of course. As long as you don't mind if the loop has quite a lot of
iterations.
for (k = 0; k < n*n; ++k) {
i = k / n; j = k % n;
...
}
for(i=0;i<n;i++)
{
if(A[NUM]==0)
{
A[NUM]=1;
}
if(A[NUM]==1)
{
printf("%d",NUM);
}
}
this loop structure prints only the repeated elements in an array of
integers....
[/QUOTE]Is it possible to find repeated(duplicate) element in an array in
single loop ?
Yes, if you use a hash table.
The implementation of the hash table is likely to use another loop.
Does it count if we unroll it?
[/QUOTE]The implementation of the hash table is likely to use another loop.
Not so. For a std C implementation that expects insertion,
deletion, search to all be O(1) see:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.