Question

Suppose I want remove duplicates from a string. I decided to use a boolean array of length 256 which stores whether a particular character has already occurred or not. I can traverse the string and can remove all duplicate with the help of this auxiliary boolean array.

My question is that "is this algorithm is in-place ?"

I think it is using constant amount of space which not going to change with the size of the input it should be in-place. Please correct if I am wrong.

Was it helpful?

Solution

In place algorithm means you are transforming input data into output data. You cannot retrieve back input data once you run the algorithm.

Out place algorithm means you keep the input data intact and use separate space for output data.

My question is that "is this algorithm is in-place ?"

The algorithm is in place as long as there is no separate array for storing output data. In the input data, after removing duplicates, the remaining elements can be empty/null.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top