< Back

Activity 19

Algorithmic Analysis

Being able to code a solution for any given problem is an important skill, that hopefully most of you have at this point. However, a much better skill to have is being able to code an efficient solution to such a problem. Step one in being able to make efficient solutions is being able to tell how efficient your current solution is. For today's activity, we will start off analyzing simple algorithms, in order to determine their Big-Oh class.


Fill in the following table. For each row of the table, write what the Big-Oh class is for the code contained on the left. Be sure to include enough of the analysis to be able to defend your answers. When you have finished, consult with another student in the class.

Algorithm Big-Oh class
	for i in range(N):
	    print(i)
      
	for i in range(N // 3):
	    print(i)
      
	for i in range(1, N // 3):
	    print(i)
      
	i = 0
	while i < N:
	    print(i)
	    i += 1
      
	for i in range(N)
	    for j in range(N):
	        print(i)
      
	i = 1
	while i < N:
	    print(i)
	    i *= 2
      
	i = 1
	while i < 10:
	    print(i)
	    i += 1
      
	i = 1
	while i < 10:
	    for j in range(N // 2):
		  print(i)
	    i += 1