Comparing Order of Magnitude of Algorithms

Algorithm A:
i = 1
while (i < n):
	j = 1
	while (j < n):
		if ((i+j) == n):
			output i, j
		j = j + 1
	i = i + 1


Algorithm B:
i = 1
while (i < n):
	j = n - i
	output i, j
	i = i+ 1




  1. For each algorithm, count the number of steps if n = 3.

  2. Both algorithms perform the same task. What is it?

  3. What would the expression for number of steps be for any value of n for each algorithm?

  4. What is the order of magnitude for each algorithm?

  5. Which algorithm is more efficient in terms of order of magnitude?