2
$\begingroup$

I have an algorithm and I would like to know how many times each line is called. There I wrote which lines I understand and some lines is left.

j := 1   ---------------------- 1 time while j < n do  --------------- n times   x := B[j]    ---------------- n-1 times   k := j    ------------------- n-1 times   for i := j + 1 to n do  ----- ?     if B[i] < x then     ------ ?       x := B[i]     ----------- ?       k := i    --------------- ?   B[l] := B[j]   -------------- n-1 times   B[j] := x     --------------- n-1 times   j := j + 1   ---------------- n-1 times 

Note: k := i means that line is called once but for i := j + 1 to n do - twice: assign and comparison.

2 Answers 2