In the worst case, it's still O(n2).
You would do better to go back to your compact function in post #61 and make it in-place by simplifying it, rather than by complicating it. Essentially all...
Type: Posts; User: R.Stiltskin
In the worst case, it's still O(n2).
You would do better to go back to your compact function in post #61 and make it in-place by simplifying it, rather than by complicating it. Essentially all...
Still working on this, I see. I was hoping that by the time you finished implementing the step-counting you would have realized how simply (and efficiently) you could complete the assignment with...
Nice job. Now why don't you modify the program so it counts (and prints) the number of assignments performed (i.e., how many times a number is moved from one place to another) while processing a...
We shouldn't turn this into a debate about complexity, but doesn't repeatedly shifting the entire array change it from O(n) to O(n2)?
But even ignoring the time complexity, it makes the program...
That's a viable approach and certainly worth doing, if only for the benefit of the programming practice it gives you. However, think about how many operations the computer will be performing as...
Of course it's solvable. Think.
Are you sure you want to compare to element [i-1]?
PS: when you see entries like 2686632 popping up, you should suspect that you might be running out of the bounds of your array somewhere.