#include<stdio.h>
int main()
{
 int a[]={3,1,2,1};
 int n=4;
 int top=0,i;
for(int i=0;i<n;i++)
{
  int flag=0;
  for(int j=0;j<i;j++)
  {
    if(a[i]==a[j])
    {      flag=1; break;}
  }
  if(!flag)
  {
   a[top++] =a[i];
   }
}
n=top;

for(int i=0;i<n;i++)
   printf("%d",a[i]);
}
time :O(n^2)
space :O(1) extra ...
If we hashing , we can do this in O(n) with cost of space O(n) extra ...
On Sat, Sep 10, 2011 at 5:21 AM, Ishan Aggarwal <
[email protected]> wrote:

> Write a program to remove duplicate elements from an array by printing them
> only once?
>
> What will be the minimum time and space complexity required for this
> program?
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> [email protected] <[email protected]>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar<http://www.google.com/profiles/bagana.bharatkumar>
*
Mobile +91 8056127652*
<[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to