9. Space Complexity Given the following implementations of countWays2 and countWays3, what are the space complexities of countWays2 and countWays3 as a function of dist? def countWays2 (dist): count =...


9. Space Complexity<br>Given the following implementations of countWays2 and countWays3, what are the space complexities of countWays2 and countWays3 as a function of dist?<br>def countWays2 (dist):<br>count = [0] * (dist + 1)<br>count[@] = 1<br>if dist >= 1:<br>count [1] = 1<br>if dist >= 2:<br>count[2] = 2<br>for i in range(3, dist + 1):<br>count[i] = (count[i - 1] + count[i - 2] + count[i - 3])<br>return count[dist]<br>def countWays3(dist):<br>if dist <= 1:<br>return 1<br>6.<br>if dist == 2:<br>return 2<br>first = 1<br>second = 1<br>third = 2<br>for i in range(3, dist + 1):<br>next_val = third + second + first<br>first = second<br>second = third<br>third = next_val<br>return third<br>8.<br>Pick ONE option<br>10<br>O countWays2: 0(1), countWays3: O(dist)<br>11<br>countWays2: O(dist), countWays3: O(1)<br>12<br>countWays2: O(dist), countWays3: O(dist)<br>13<br>countWays2: O(2dist), countWays3: O(log(dist))<br>14<br>

Extracted text: 9. Space Complexity Given the following implementations of countWays2 and countWays3, what are the space complexities of countWays2 and countWays3 as a function of dist? def countWays2 (dist): count = [0] * (dist + 1) count[@] = 1 if dist >= 1: count [1] = 1 if dist >= 2: count[2] = 2 for i in range(3, dist + 1): count[i] = (count[i - 1] + count[i - 2] + count[i - 3]) return count[dist] def countWays3(dist): if dist <= 1:="" return="" 1="" 6.="" if="" dist="=" 2:="" return="" 2="" first="1" second="1" third="2" for="" i="" in="" range(3,="" dist="" +="" 1):="" next_val="third" +="" second="" +="" first="" first="second" second="third" third="next_val" return="" third="" 8.="" pick="" one="" option="" 10="" o="" countways2:="" 0(1),="" countways3:="" o(dist)="" 11="" countways2:="" o(dist),="" countways3:="" o(1)="" 12="" countways2:="" o(dist),="" countways3:="" o(dist)="" 13="" countways2:="" o(2dist),="" countways3:="" o(log(dist))="">

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here