Hi I have some homework assignments about algorithm and run time analysis but i have no idea what I have to do.
The question is about the multiplication of two square matrices and I have to carry out this run time analysis and determine the number of executions dependent of n, which corresponds to the number of element in the arrays. The solution are written in comments below.
01 int i, j, k, n, z; //1
02 for( i = 0; i < n; i++ ) { //n+1
03 for( j = 0; j < n; j++ ) { //n*(n+1)
04 z = 0; //n²
05 for ( k = 0 ; k < n ; k++ ) //n*n*(n+1)
I have no idea after searching through google about this. And for the question I hope it is clear because I translated it from another language. Thank you for your help.
That gives you an in-depth review of what to do. But as a start you need to set the code out so you can easily see the loop structure. Once that's done count the number of cycles through the (nested) loops. You should be able to determine the number of iterations(cycles) in terms of n.
thanks for the link. After reading I am still quite unsure about what happened at line 3 to 5 at the code above. Could you please briefly explain the logic behind this? Or a better way to understand it?
I think you might have to go back to the source because it is not really intelligible with the missing brackets and what appears to be commenting out. Other than that I can't say. :(