What is O(1) space complexity?

To answer your question, if you have a traversal algorithm for traversing the list which allocate a single pointer to do so, the traversal algorithms is considered to be of O(1) space complexity. Additionally, let’s say that traversal algorithm needs not 1 but 1000 pointers, the space complexity is still considered to be O(1). However, … Read more

Will Arrays.sort() increase time complexity and space time complexity?

I am assuming you are talking about Java here. So the loop will cost O(n) time, my question is that will Arrays.sort() cost more time? Yes, Arrays.sort(int[]) in all Java standard library implementations that I know, is an example of a comparison-based sort and thus must have worst-case complexity Ω(n log n). In particular, Oracle Java 7 uses … Read more