Question: ans = Modify the following Python function alg into another Python function alg2 to improve its running time by using a heap. Assume that the

ans = Modify the following Python function alg into another Python function alg2 to improve its running time by using a heap. Assume that the given function always takes a valid input (a list 'nums' and an integer 'target') and returns a list of the 'target' smallest numbers in 'nums'. The example input of nums = [3, 1, 4, 5] and target = 2 gives the output of (1,3]. def alg1(nums, target): [] maximum_num = max(nums) while target > 0: minimum_num = maximum_num for i in range(len(nums)): if i not in ans and nums[i]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
