Currently am developing a program that solves (if possible) any given labyrinth of dimensions from 3X4 to 26×30. I represent the graph using both adj matrix (sparse) and adj list. I would like to know how to output the total time taken by the DFS to find the solution using one and then the other method. Programatically, how could i produce such benchmark?
Currently am developing a program that solves (if possible) any given labyrinth of dimensions
Share
An useful table to work out with various graphs implementations:
where
mis the number of edges,nis the number of vertices andd(vertex)is the number of elements in the vertex adjacency list.. adj matrix implementation has anO(n²)to add and remove vertices because you have to reallocate the matrix..Just prepared this for an article, that why I have it ready 🙂
This is not directly related to benchmarking, since usually you study which operations you will mostly need and choose the right implementation for your needs, so it’s a sort of “theoretical” benchmark that you do by studying what you are going to implement. Otherwise you can just measure time that your code needs to do the whole work with both implementations and compare it.
EDIT: since you use a sparse matrix implementation the complexity of operations could slightly change (mostly getting a little worse, since you are trading memory for speed).
EDIT2: ok, now that I know that this is Java it will be fair simple:
Answer is in nanoseconds and accuracy is not guaranteed, so use this thing carefully. Doing an average of many runs (and checking that variance is low, discarding the result that are more distant from the average) will give coherence to your results.