Python Code Task 1 Paired Pivot Partition May Import Libraries Modules Write Function Pair Q43906607
PYTHON CODE
Task 1: Paired-pivot partition
You may not import any other libraries ormodules.
Write a function paired partition(lst), in which it uses twopivots in this manner:
a) Pick an elements P1 and P2 called pivots from the list. (Youmay select the first element in the list as P1 and the last elementin the list as P2)
b) Assume that P1 ≤ P2, otherwise swap it.
c) Reorder the list into three parts: those less than thesmaller pivot, those larger than the larger pivot, and in betweenare those elements between (or equal to) the two pivots (as shownin Figure 1).
Input: an unsorted list containing one or more integers.
Output: a partitioned list as shown in Figure 1.
To receive full marks, this function must have acomplexity of O(N), where N=len(lst).
Examples
a) Let lst1=[3,1,6,2,4,8,9,5], calling paired partition(lst1),returns [2,1,3,4,5,9,6,8].
b) Let lst2=[8,16,20,14,17,2,19,10,1,2], calling pairedpartition(lst2), returns [1,2,2,8,14,19,10,20,16,17].
c) Let lst3=[1,2,3,4], calling paired partition(lst3), returns[1,2,3,4].
Marks are given for the correct behavior of the function:
(a) 1 mark for an implementation without complexity of O(N) andpartitioning is performed without ‘in-place’ strategy.
(b) 3 marks for an implementation without ‘in-place’ strategyand has a best and worst-case complexity of O(N).
(c) 4 marks for an implementation using ‘in-place’strategy and has a best and worst-case complexity ofO(N).
THE RETURN OUTPUT MUST BE TOTALLY SAME WITH THE EXAMPLEOUTPUT SHOWN ABOVE.
NO PRINT FUNCTION CAN BE USED, ONLY USERETURN!
< <P1 P P1 2 en and = 22 > P1 and P2 P2 som > P2 Figure 1: Paired-pivot partition Show transcribed image text P2 Figure 1: Paired-pivot partition
Expert Answer
Answer to PYTHON CODE Task 1: Paired-pivot partition You may not import any other libraries or modules. Write a function paired pa…
OR