Posts

Showing posts from March, 2022

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]: ...

Session 1 (10 AM - 12 PM) ONLINE Questions for Unprotected Exam (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS22)

  Question 1 Here is a function  isprimebad  that takes a positive integer as input and returns  True  if the number is prime and  False  otherwise. There is an error in this function. Provide an input  n , which is a positive integer, for which  isprimebad  produces an incorrect output. import math def isprimebad(n): if n < 2: return(False) else: for i in range(2, int(math.sqrt(n))): if n%i == 0: return(False) return(True) Open up the code submission box below and write your test case where you would normally paste your code. Your input should be a single integer  n . Answer:   49 Question 2 Here is a function  lexsortbad  that takes a list of pairs of integers as input and returns them in lexicographically sorted order (i.e., dictionary order). There is an error is this function. Provide an input for which  lexsortbad  produces an incorrect output. Your input should be a ...

Session 2 (8 PM - 10 PM) ONLINE Questions for Unprotected Exam (Programming, Datastructures and Algorithms using Python) (NPTEL 2021 - CS21)

  ONLINE EXAM – SESSION 2 (2021) 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) Ans 1: [-1,-2,-4,-5] Question 2: 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):   ...

Session 1 (10 AM - 12 PM) ONLINE Questions for Unprotected Exam (Programming, Datastructures and Algorithms using Python) (NPTEL 2021 - CS21)

  ONLINE EXAM – SESSION 1 (2021) Question 1 Here is a function isprimebad that takes a positive integer as input and returns True if the number is prime and False otherwise. There is an error in this function. Provide an input n, which is a positive integer, for which isprimebad produces an incorrect output. Ans 1:  4 Question 2 Here is a function lexsortbad that takes a list of pairs of integers as input and returns them in lexicographically sorted order (i.e., dictionary order). There is an error is this function. Provide an input for which lexsortbad produces an incorrect output. Your input should be a list of pairs of integers of the form [(i1,j1),(i2,j2),...,(in,jn)].  Ans 2: [(12, 53), (52, 69), (43, 43), (55, 9), (25, 0) ] Question 3 Here is a function to compute the smallest of three input integers. You have to fill in the missing lines. def min3(x,y,z):   if x <= y:     if x <= z:       minimum = x...