Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Removing du...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 9387 of 10094
Post > Topic >>

Re: Removing duplicates from a sorted array

by Michael.Boehnisch@[EMAIL PROTECTED] Mar 15, 2008 at 02:14 PM

On 13 Mrz., 23:42, "Andrei Alexandrescu (See Website For Email)"
<SeeWebsiteForEm...@[EMAIL PROTECTED]
> wrote:
> Michael.Boehni...@[EMAIL PROTECTED]
 wrote:
> > On 13 Mrz., 09:42, "Andrei Alexandrescu (See Website For Email)"
[..]
>
> > Sorry, the problem is solvable, without any extra data storage but for
> > a single iterator (or index) used for traversing the list and one
> > helper variable for exchanging elements.
>
> That restates what I said, so I guess "Indeed" should replace "Sorry"
:o).

The "sorry" refers to the O(log N) complexity estimate.

> > For working on N elements its
> > complexity is O(N) time and O(N) space - each list element needs to be
> > touched O(1) times.
>
> The complexity is O(N) time and O(log N) space.

How do you store N integers in log N space? If you refer to extra
space in excess to the storage for the ints itself only, there is no
need for it. One extra int for exchanging elements is enough. O(1)...

> > If the container is initially unsorted, it needs to sorted first. The
> > complexity of sorting is O( N log N ) time and O(N) space. For space
> > complexity this means no change, the time complexity of the sorting
> > dominates the uniqueness algorithm.
>
> The problem said that the array was already sorted.

*If*... just wanted to point out that the pre-sort makes a difference.

best,

   Michael



--
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 1 Posts in Topic:
Re: Removing duplicates from a sorted array
Michael.Boehnisch@[EMAIL   2008-03-15 14:14:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:17:15 CDT 2008.