Session 2 (8 PM - 10 PM) ONLINE Questions for Unprotected Exam (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)
Question 1 Here is an function to return the maximum value in a list of integers. There is an error in this function. Provide an input list for which maxbad produces an incorrect output. def maxbad(l): mymax = 0 for i in range(len(l)): if l[i] > mymax: mymax = l[i] return(mymax) Open up the code submission box below and write your test case where you would normally paste your code. 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]: ...