Here is a function stablesortbad that takes a list of pairs of integers as input and sorts them by the second coordinate in each pair. A stable sort preserves the order of pairs that have an equal second coordinate. This is not a stable sort. Provide an input for which stablesortbad produces an output that is not stably sorted. Your input should be a list of pairs of integers of the form [(i1,j1),(i2,j2),...,(in,jn)].
def stablesortbad(l):
for j in range(len(l)-1):
for i in range(len(l)-1):
if l[i][1] >= l[i+1][1]:
(l[i],l[i+1]) = (l[i+1],l[i])
return(l)
please explain logic for how to predict such list which is asked for
Answers
Answered by
0
Answer:
Explanation:
Here is a function stablesortbad that takes a list of pairs of integers as input and sorts them by the first coordinate in each pair. A stable sort preserves the order of pairs that have an equal first coordinate. This is not a stable sort. Provide an input for which stablesortbad produces an output that is not stably sorted. Your input should be a list of pairs of integers of the form [(i1,j1),(i2,j2),…,(in,jn)].
Similar questions
Biology,
2 months ago
Math,
4 months ago
Math,
4 months ago
Hindi,
10 months ago
Computer Science,
10 months ago