KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've searched high and low and can't seem to find a lot of material related to run-time complexities, recursion, and java. I'm currently learning run-time complexities and Big-O notation in my Algorithms class, and I'm having trouble analyzing recursive algorithms. private String toStringRec(DNode d) { if (d == trailer) return ""; else return d.getElement() + toStringRec(d.getNext()); } This is a recursive method that will simply iterate though a doubly-linked list and print out the elements. The only thing I can come up with is that it has a run-time complexity of O(n), since the number of recursive method calls will depend on the number of nodes in the DList, but I still don't feel comfortable with this answer. I'm not sure whether I should be accounting for the addition of d and d.getNext() . Or am I just completely off track and the run-time complexity is constant, since all its doing is retrieving elements from the DNodes in the DList ?
Tags (comma-separated)
Save Edits
Cancel