def greedy(itemsmaxweightkeyfunction)"""assumes items listmaxweight > keyfunction maps elements of items to floats""itemscopy sorted(itemskey=keyfunctionreverse trueresult [totalvalue totalweight for in range(len(itemscopy))if (totalweight itemscopy[igetweight()<maxweightresult append(itemscopy[ ]totalweight +itemscopy[igetweight(totalvalue +itemscopy[igetvalue(return (resulttotalvaluedef testgreedy(itemsconstraintkeyfunction)takenval greedy(itemsconstraintkeyfunctionprint 'total value of items taken 'val for item in takenprint 'item def testgreedys(maxweight )items builditems(print 'use greedy by value to fill knapsack of size'maxweight testgreedy(itemsmaxweightvalueprint '\nuse greedy by weight to fill knapsack of size'maxweight testgreedy(itemsmaxweightweightinverseprint '\nuse greedy by density to fill knapsack of size'maxweight testgreedy(itemsmaxweightdensityfigure using greedy algorithm to choose items when testgreedys(is executed it prints use greedy by value to fill knapsack of size total value of items taken use greedy by weight to fill knapsack of size total value of items taken use greedy by density to fill knapsack of size total value of items taken what is the algorithmic efficiency of greedythere are two things to considerthe time complexity of the built-in function sortedand the number of times through the for loop in the body of greedy the number of iterations of the loop is bounded by the number of elements in itemsi it is ( )where is the length of items howeverthe worst-case time for python' built-in sorting