a)
1. could split the string using a regexp (into an array) in which you
define a "word"  --  is  "hi."  the same as "hi,"  and "hi"  ?
2. then perform a "unique" operation on the array (some languages have
this built in) to remove duplicates
3. recombine array elements into string by joining with a space, for
example, depending on how you split it in the first step

b) Perhaps another way, in-place, could be to check the string, one
"word" (again define this) at a time, storing each word in a hash.  If
the hash already contains the word, replace this occurrence with
spaces or null bytes.  Finally compact the string (remove all null
bytes, or turn all extra spaces into one space, etc).

icy`

On Oct 10, 3:08 pm, sunny agrawal <sunny816.i...@gmail.com> wrote:
> Trie will take too much space..
> Balanced Binary tree can be Better ...??
>
>
>
>
>
>
>
>
>
> On Tue, Oct 11, 2011 at 12:16 AM, Ankur Garg <ankurga...@gmail.com> wrote:
> > I think this can be done through tries
>
> > Any better solution ?
>
> > On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal <monugoya...@gmail.com>wrote:
>
> >> remove duplicate words from a string with min. complexityy.....
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/algogeeks?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Sunny Aggrawal
> B.Tech. V year,CSI
> Indian Institute Of Technology,Roorkee

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

Reply via email to