Currently this method has a run time of O(N^2) and I am trying to get it to O(N). Any suggestion as to where I should start?

    public void removeAll(e removeNum)
        node nodeToFind = this.find(removeNum);
        while(nodeToFind != null)
            nodeToFind = this.find(removeNum);


Recommended Answers

All 2 Replies

will you please post some working code over here.
so we can suggest some solution of your problem.

Details depend on what you are removing from (ArrayList, HashSet etc?), but re-starting the find from the beginning each time is what gives you the O(N^2).
Use an algorithm that just searches once through the data, removing as it goes. (You may need to start at the end of the data and iterate backwards towards the beginning, depending on what happens when you delete an item.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.