What should be the time complexity of the isempty(), size(), and tostring() methods?
Answers
Answered by
0
isEmpty() and size() can be O(n) or O(1), for the reasons stated above. toString's complexity depends on the implementation. Array.toString() is O(n) because you have to traverse the array, whereas, Object.toString() is O(1) because it's simply outputs the object's hashcode.
Similar questions