Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following function: 1 def func(1st: List[int]) -> None: n = len(1st) i = 0 j = 1 while i < n: if

 

Consider the following function: 1 def func(1st: List[int]) -> None: n = len(1st) i = 0 j = 1 while i < n: if 1st (i] >= 0: i = i + j 2 3 4 7. else: = abs (1st (i] ) 1st [i] i = 0 j-j+ 2 10 11 (a) Find, with proof, an inmput family for func whose running time is O(log n). (b) Find, with proof, an input family for func whose running time is O(n) and for which the else branch (Lines 9-11) executes 2(log n) times. To simplify your analysis, you may assume n (the length of the list) is a power of 2.4 You may use the following formula, valid for all n eN and r eR where r + 1: n-1 1- r" i-0 (c) Prove that the worst-case running time for func is O(n).

Step by Step Solution

3.30 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

Solution a for a running time of thetalognwe need to have negative values at every power of 2 index ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus Early Transcendentals

Authors: William L. Briggs, Lyle Cochran, Bernard Gillett

2nd edition

321954428, 321954424, 978-0321947345

More Books

Students also viewed these Programming questions

Question

describe solar, wind, geothermal, wave, hydro and biomass energy

Answered: 1 week ago

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

How does the purpose of ERP differ from the purpose of MRP II?

Answered: 1 week ago