How do you compute the number of operations each line of code would take.
Example.
Algorithm find2D (A,x)
arrLength = A.length
for j <- 1 to arrLength – 1 do
for k <- 1 to arrLength – 1 do
if A[j][k] = x then
return true
increment k
increment j
return false
I came up with this pseudo code. So I'm not really sure how to count the number of operations each line of code takes.
So like the first loop would be 1+n operations since you have to set the j, compare j to arrLength - 1, and it will loop n-1 times. So that gives you n-1 + 1 + 1 which is n+1 operations.
So for the second loop would it just be the same thing even though its nested.
I'm a little confused on the A[j][k] = x
comparison, how many operations would that be.
Thanks.