def double_then_sum(array):= []
doubled_array
for number in array:* 2)
doubled_array.append(number sum = 0
for number in doubled_array:sum += number
sum return
1. \(4N + 16\) Steps
1.1 Tony’s Solution: \(O(N)\)
\(O(4N+16) \rightarrow O(4N) \rightarrow O(N)\)
2. \(2N^2\) Steps
2.1 Tony’s Solution: \(O(N^2)\)
\(O(2N^2) \rightarrow O(N^2)\)
3. double_then_sum
Function
3.1 Tony’s Solution: \(O(N)\)
- Loop through
array
: \(N\) steps
- Loop through
doubled_array
: \(N\) steps
- Total steps: \(2N\)
- Big O: \(O(2N) \rightarrow O(N)\)
4. mutiple_cases
Function
def multiple_cases(array):
for string in array:
print(string.upper())
print(string.lower()) print(string.capitalize())
4.1 Tony’s Solution: \(O(N)\)
The function performs multiple operations on each string in the input array:
- \(3\) operations or steps per
string
or \(N\)
- Total Steps: \(3N\) steps
- Big O: \(O(3N) \rightarrow O(N)\)
5. every_other
Function
def every_other(array):enumerate(array):
for index, number in % 2 == 0:
if index
for other_number in array:+ other_number) print(number
5.1 Tony’s Solution: \(O(N)\)
- \(N\) operations to iterate through
array
- \(N/2\) operations applies in the
if
statement - Total Steps: \(N*N/2=N^2/2\) steps
- Big O: \(O(N^2/2) \rightarrow O(N^2)\)