How to compute the complexity
is there any software or debugger that can compute for me the time and space(memory) complexity?
for example if i have two Java codes which do the same function, and i want to check which takes memory less.
time is not important because by the theories of complexity i can check it.
any help in that?
There are a series of profilers that you can use to determine memory and resource use in your program.
Other tools like PMD will review your code and provide suggestions for improvement and best practice.
a free profiler is JProfiler another is JmemProf. I think you will find JmemProf the easiest to learn.
An alternative to a profiler is to count the number of elements in your arrayList (or whatever type of collection you have) and multiply it by the type of storage element each cell in the array has (for example, each cell is an integer). Example: if an integer is 4 bytes and you have 1234 elements in the array, size is= 4*1234.
***************
Here is a way to measure how long your code takes to run:
Calendar calendar1= Calendar.getInstance();
//put your code you want to time here
Calendar calendar2= Calendar.getInstance();
long differenceInTIme=
calendar2.getTimeInMillis() - calendar2.getTimeInMillis();