練習 Big O 表示法
在這個練習中,你會持續練習對 Big O 表示法的理解。
第一步,你將建立一個演算法,列印出以下串列中的所有元素:
colors = ['green', 'yellow', 'blue', 'pink']
這個演算法的時間複雜度是 $O(n)$。
在第二與第三步中,你會計算兩個演算法的複雜度。
本練習屬於課程
Data Structures and Algorithms in Python
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
colors = ['green', 'yellow', 'blue', 'pink']
def linear(colors):
# Iterate the elements of the list
____:
# Print the current element of the list
print(____)
linear(colors)