Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help. 1. 2. For each function below, give the time cost of each individua

ID: 3855250 • Letter: P

Question

Please help.

1.

2.

For each function below, give the time cost of each individual line of code in big-Oh notation. This time, though, give the total cost for that ilne, across all iterations. (That is, an O(1) line, which runs O(n) times, should be listed as O(n).) Make sure to account for the cost of other functions that these functions call! def max min(vals) : assert len(vals) 0 max = vals[0] min = vals[0] other vals - vals [1:] for v in other vals: if v min: if v max: max = v return (min,max) def wrapper (vals): bigOh 1 func (vals) for in vals: bigoh n func (vals) def list to str (vals): retval = "', for v in vals: new retval = retval + str (vals) retval - new retval return retval

Explanation / Answer

max_min functions has O(n) time complexity becuase it has one For loop which runs in n time complexity.

wrapper has o(n2) complexity becuase it has one For loop which runs in n time complexity and In that loop it has Function which runs in O(n) time.Hence.It has  o(n2) complexity

list_to_str has o(n) complexity becuase it has one For loop which runs in n time complexity

func1 has  o(n) complexity becuase it has one For loop which runs in n time complexity and another  For loop which runs in n time complexity.but both loops are not nested ,they are independent.Hence it has O(n)

func2 has o(n) complexity when numbers in vals are negative then,it will not enter in if condition and then inner loop wont execute