Count the number additions and multiplications in the following Python code segment. Ignore the multiplications used to test the condition 2**j <= i in the while loop statement. a ** b means $a^b$ in Python. for i in range(4,64): j=0 while 2**j<=i: k=3*i+2*j j=j+1 print(k)
Added by Sherri H.
Close
Step 1
The for loop runs from i = 4 to i = 63. So, there are 60 iterations of the for loop. Show more…
Show all steps
Your feedback will help us improve your experience
Elizabeth Waters and 74 other Algebra educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Count the number of primitive operations and calculate the time complexity? def foo(lst): result1 = 1 Result2 = 6 for i in range(len(lst)): for j in range(len(lst)): result1 += i*j result2 = lst[j] + i return
Areen D.
Give a big- $O$ estimate for the number of operations (where an operation is an addition or a multiplication) used in this segment of an algorithm. $$ \begin{array}{c}{t :=0} \\ {\text { for } i :=1 \text { to } 3} \\ {\quad \text { for } j :=1 \text { to } 4} \\ {t :=t+i j}\end{array} $$
Algorithms
Complexity of Algorithms
In Python Given that n refers to a positive integer, use a while loop to compute the sum of the cubes of the first n counting numbers, and assign this value to total. In other words, total should be assigned: 1 * 1 * 1 + 2 * 2 * 2 + … n * n * n Use no variables other than n, k, and total.
Aarya B.
Recommended Textbooks
Elementary and Intermediate Algebra
Algebra and Trigonometry
Watch the video solution with this free unlock.
EMAIL
PASSWORD