# Duplicate removal

Discussion in 'C Programming' started by raja, Feb 4, 2006.

1. ### rajaGuest

Design and implement an efficient algorithm to remove consecutive
1char, 2char, 3 char... so on recurrences in dictionary words.
For example, "abbabccbc" first will become "ababcbc", then become
"abc". Similarly, "abcaab" will become "abcab" and but stays as it is
after that.

raja, Feb 4, 2006

2. ### Keith ThompsonGuest

"raja" <> writes:
> Design and implement an efficient algorithm to remove consecutive
> 1char, 2char, 3 char... so on recurrences in dictionary words.
> For example, "abbabccbc" first will become "ababcbc", then become
> "abc". Similarly, "abcaab" will become "abcab" and but stays as it is
> after that.

And why exactly would we want to do that?

This looks like a homework assignment. If so, try to solve the
problem yourself; if you run into trouble, show us what you have and
exactly what problems your having, and we might be able to give you
some hints.

Either that, or give us your instructor's e-mail address so we can
submit our solutions directly.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Keith Thompson, Feb 4, 2006

3. ### MalcolmGuest

"raja" <> wrote in message
> Design and implement an efficient algorithm to remove consecutive
> 1char, 2char, 3 char... so on recurrences in dictionary words.
> For example, "abbabccbc" first will become "ababcbc", then become
> "abc". Similarly, "abcaab" will become "abcab" and but stays as it is
> after that.
>

Start by specifying the problem as a function.

/*
remove consecutive repeated characters from a string
Parmas: dest - pointer to destination
src - source string
*/
void removerepeats(char *dest, const char *src)

The algorithm should be pretty trivial to write. You just need one pass
through the source string.

Once you have written the function, test it, and then apply it to your
problem.

Malcolm, Feb 4, 2006

raja wrote:
>
> Design and implement an efficient algorithm to remove consecutive
> 1char, 2char, 3 char... so on recurrences in dictionary words.
> For example, "abbabccbc" first will become "ababcbc", then become
> "abc". Similarly, "abcaab" will become "abcab" and but stays as it is
> after that.

Before you do that, consider whether it makes a difference in what
order the replacements are done. If so, what order will you do them?
If not, can you prove it?

--

5. ### Default UserGuest

raja wrote:

> Design and implement an efficient algorithm to remove consecutive
> 1char, 2char, 3 char...

Sorry, I have better things to do.

Brian

Default User, Feb 5, 2006
6. ### Arndt JonassonGuest

"raja" <> writes:
> Design and implement an efficient algorithm to remove consecutive
> 1char, 2char, 3 char... so on recurrences in dictionary words.
> For example, "abbabccbc" first will become "ababcbc", then become
> "abc". Similarly, "abcaab" will become "abcab" and but stays as it is
> after that.

I'm probably unusually thick this morning, but I don't understand the
specification.

Arndt Jonasson, Feb 7, 2006