Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
"unique-elements-in-an-array" - Discussion
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
This discussion is about page unique-elements-in-an-array
flag
  17 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
unique-elements-in-an-array was changed (view version 2) by jhshukla@gmail.com
cg.yu  
View profile  
 More options Jan 29 2007, 4:58 am
From: "cg.yu" <chungon...@gmail.com>
Date: Mon, 29 Jan 2007 09:58:18 -0000
Local: Mon, Jan 29 2007 4:58 am
Subject: Discussion on unique-elements-in-an-array
using hash table

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dor  
View profile  
 More options Feb 1 2007, 1:55 am
From: "dor" <bynd...@gmail.com>
Date: Thu, 01 Feb 2007 06:55:37 -0000
Local: Thurs, Feb 1 2007 1:55 am
Subject: Re: Discussion on unique-elements-in-an-array
O(N*log(N)) is straightforward.. sort the array in O(N*log(N)) and
then remove duplicates in linear time.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vijendra Singh  
View profile  
 More options Feb 4 2007, 2:29 am
From: "Vijendra Singh" <vs.puro...@gmail.com>
Date: Sat, 3 Feb 2007 23:29:32 -0800
Local: Sun, Feb 4 2007 2:29 am
Subject: Re: [algogeeks] Re: Discussion on unique-elements-in-an-array

Hash table is the way to go in most of the cases..

-Vijju

Visit me at http://vijju.net/

On 1/31/07, dor <bynd...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
unique-elements-in-an-array was changed (view version 3) by Shashi Kant
joke  
View profile  
 More options Feb 26 2007, 11:18 pm
From: "joke" <dfxha...@gmail.com>
Date: Mon, 26 Feb 2007 20:18:34 -0800
Local: Mon, Feb 26 2007 11:18 pm
Subject: Discussion on unique-elements-in-an-array
bitmap

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dor  
View profile  
 More options Mar 5 2007, 1:28 am
From: "dor" <bynd...@gmail.com>
Date: Mon, 05 Mar 2007 06:28:44 -0000
Local: Mon, Mar 5 2007 1:28 am
Subject: Re: Discussion on unique-elements-in-an-array
A bitmap is a very bad idea in general since the numbers can be
arbitrarily large.

On Feb 26, 11:18 pm, "joke" <dfxha...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pratapgarhi2000@yahoo.com  
View profile  
 More options May 4 2007, 2:01 am
From: "pratapgarhi2...@yahoo.com" <pratapgarhi2...@yahoo.com>
Date: Thu, 03 May 2007 23:01:00 -0700
Subject: Discussion on unique-elements-in-an-array
You can use a tweak of Merge Sort:

Only change while merging of the two lists:
Just while merging if two elements are equal you can make one of them
equal to some predefined value.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
unique-elements-in-an-array was changed (view version 4) by scdong
MD  
View profile  
 More options Oct 29 2007, 7:31 pm
From: MD <madhu.da...@gmail.com>
Date: Mon, 29 Oct 2007 16:31:02 -0700
Local: Mon, Oct 29 2007 7:31 pm
Subject: Discussion on unique-elements-in-an-array
There can be multiple ways to do this.. obviously sorting gives you
o(nlogn).
another approach of hashtable gives o(n)
and here is another approach:
1. maintaining array of size N, initialized to 0. Say B
2. for(i=0;i<N;i++) { B[a[i]]++;}
3. Output all values with B[i] >= 1 , which gives unique elements
only.

Only restriction is the memory.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Channa Bankapur  
View profile  
 More options Nov 6 2007, 7:01 am
From: "Channa Bankapur" <channabanka...@gmail.com>
Date: Tue, 6 Nov 2007 17:31:25 +0530
Local: Tues, Nov 6 2007 7:01 am
Subject: Re: [algogeeks] Discussion on unique-elements-in-an-array

Hi MD,

In your last approach, watch out for arbitrarily large values. What
would 'N' be? By the way, 'for' loop there should be for 'n', which is the
size of array 'a'. A simple array like {20, 5, 123456789} would kill your
memory.
Hashing approach would be great if we've some idea on nature of the array
contents. Here's a method of O(n logn) again.
Parse through each entry in the array and insert into a BST (Binary Search
Tree). Ignore duplicate entries and hence gives unique elements when done
in-traversal later. However, worst-case shoots to O(n^2) if the distribution
is skewed.

Regards,
Channa

On Oct 30, 2007 5:01 AM, MD <madhu.da...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey  
View profile  
 More options Nov 6 2007, 1:36 pm
From: Andrey <andrey_rya...@bk.ru>
Date: Tue, 06 Nov 2007 10:36:00 -0800
Subject: Re: Discussion on unique-elements-in-an-array
dor is absolutely right

> O(N*log(N)) is straightforward.. sort the array in O(N*log(N)) and
> then remove duplicates in linear time.

it doesn't need any extra memory.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pramod Negi  
View profile  
(1 user)  More options Nov 9 2007, 7:54 am
From: "Pramod Negi" <negi.1...@gmail.com>
Date: Fri, 9 Nov 2007 04:54:13 -0800
Local: Fri, Nov 9 2007 7:54 am
Subject: Re: [algogeeks] Re: Discussion on unique-elements-in-an-array

which algo sort array in O(N lgN) without extra space??????

On 11/6/07, Andrey <andrey_rya...@bk.ru> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey  
View profile  
 More options Nov 9 2007, 8:43 am
From: Andrey <andrey_rya...@bk.ru>
Date: Fri, 09 Nov 2007 05:43:59 -0800
Local: Fri, Nov 9 2007 8:43 am
Subject: Re: Discussion on unique-elements-in-an-array
Heapsort http://en.wikipedia.org/wiki/Heapsort#Comparison_with_other_sorts

On Nov 9, 3:54 pm, "Pramod Negi" <negi.1...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pramod Negi  
View profile  
 More options Nov 9 2007, 8:51 am
From: "Pramod Negi" <negi.1...@gmail.com>
Date: Fri, 9 Nov 2007 05:51:33 -0800
Local: Fri, Nov 9 2007 8:51 am
Subject: Re: [algogeeks] Re: Discussion on unique-elements-in-an-array

i think if array of n elements is given and to make a heap out of it we need
O(n) space.
heap sort will surely take constant amount of auxially space if heap is
already build.

isn't it?
correct me if i m wrong..

On 11/9/07, Andrey <andrey_rya...@bk.ru> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrey  
View profile  
 More options Nov 10 2007, 5:08 am
From: Andrey <andrey_rya...@bk.ru>
Date: Sat, 10 Nov 2007 02:08:40 -0800
Local: Sat, Nov 10 2007 5:08 am
Subject: Re: Discussion on unique-elements-in-an-array

No, it is not.
Read carefully the article on Wikipedia. There is a very detailed
explanation of the algorithm.
Heap is build in an array being sorted. It's the strongest feature of
the algorithm.

On Nov 9, 4:51 pm, "Pramod Negi" <negi.1...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MJ  
View profile  
 More options Nov 20 2007, 1:20 am
From: MJ <mayurdj...@gmail.com>
Date: Mon, 19 Nov 2007 22:20:30 -0800 (PST)
Local: Tues, Nov 20 2007 1:20 am
Subject: Discussion on unique-elements-in-an-array
Heap sort has a function heapify which will build the heap. If you
just modify this heapify algorithm to eliminate the repeated elemenst
it will work in O(nLogn).
Also this will work for any number of repeated elements. you can find
this algo in hte Design analysis and algorithms by Corment in Chapter
7 : heap Sort.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "在 unique-elements-in-an-array 上讨论" by Bookpet
Bookpet  
View profile  
 More options Dec 20 2007, 9:02 pm
From: Bookpet <lid...@gmail.com>
Date: Thu, 20 Dec 2007 18:02:20 -0800 (PST)
Local: Thurs, Dec 20 2007 9:02 pm
Subject: 在 unique-elements-in-an-array 上讨论
I think this method will solve the problem:
1). first, sort the linear array using quick sort method, it will take
n(logn) time
2).second, scan the sorted linear array:
Array[nLen] //sorted data Array.
T  tSameData;
int iNum;
int i, j, k,  iLast = nLen; //nLen is the length of the array.
for (i=0; i<iLast; i++)
{
      tSameData = Array[i];
      j = i;
      while (Array[j+1] == tSameData)   j++;
      if (j > i)
      {
             iNum = j - i;
             for(k=iLast-1, i=i+1;  k>iLast-1-iNum; k--, i++)
             {
                      Array[i] = Array[k];
             }
            iLast -= iNum;
      }
}

nLen = iLast;

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bookpet  
View profile  
 More options Dec 20 2007, 9:04 pm
From: Bookpet <lid...@gmail.com>
Date: Thu, 20 Dec 2007 18:04:03 -0800 (PST)
Local: Thurs, Dec 20 2007 9:04 pm
Subject: 在 unique-elements-in-an-array 上讨论
I think this method will solve the problem:
1). first, sort the linear array using quick sort method, it will take
O(n(logn)) time
2).second, scan the sorted linear array:
Array[nLen] //sorted data Array.
T  tSameData;
int iNum;
int i, j, k,  iLast = nLen; //nLen is the length of the array.
for (i=0; i<iLast; i++)
{
      tSameData = Array[i];
      j = i;
      while (Array[j+1] == tSameData)   j++;
      if (j > i)
      {
             iNum = j - i;
             for(k=iLast-1, i=i+1;  k>iLast-1-iNum; k--, i++)
             {
                      Array[i] = Array[k];
             }
            iLast -= iNum;
      }
}

nLen = iLast;
because the same elements are not more than two, so the time spent
will be O(n)

So the total time spent:  O(nlog(n)).


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave  
View profile  
 More options Dec 20 2007, 10:22 pm
From: Dave <dave_and_da...@juno.com>
Date: Thu, 20 Dec 2007 19:22:00 -0800 (PST)
Subject: Re: 在 unique-elements-in-an-array 上讨论
Quicksort has an _average_ time of O(n log n) for random data, but it
can degenerate to O(n^2) for certain initial orderings. Thus, your
statement that it will take O(n log n) time is not justified. That is
why it has been suggested to use a heapsort or mergesort, both of
which are O(n log n).

Dave

On Dec 20, 8:02 pm, Bookpet <lid...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google