Week 6 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)
Get link
Facebook
X
Pinterest
Email
Other Apps
Supposeuandvboth denote sets in Python. Under what condition can we guarantee thatu-(v-u) == u?
Feedback:
v-u has no elements from u, so u-(v-u) removes nothing from u and is hence always equal to u.
Accepted Answers: D
2.5 points
Suppose u and v both denote sets in Python. and u|v != u^v. What can we conclude about u and v?
Feedback:
If the two sets were disjoint, we would have u|v == u^v. Since the two expressoins are not equal, it must be that the sets overlap.
Accepted Answers: D
2.5 points
Which of the following does not correspond to a min-heap on the list of values [19,97,83,45,72,55,31,28,31,29].
Feedback:
In [19, 28, 29, 31, 45, 83, 97, 55, 72, 31], value 45 has left child 31.
Accepted Answers: D
2.5 points
Consider the min-heap [19, 28, 31, 31, 29, 83, 55, 97, 45, 72]. Suppose we apply the operation delete_min() to this min-heap. The resulting min-heap is:
Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the previous permutation in lexicographic (dictionary) order? Write your answer without any blank spaces between letters. fjadchbegi Feedback: Invert the algorithm given in the video. Look for the longest suffix in increasing order, here begi . The letter before is h . Replace by the next smallest letter in the suffix, g and arrange the remaining letters in descending order, to get giheb . So the final answer is fjadcgiheb . Accepted Answers: fjadcgiheb (Type: Regex Match) [ ]*fjadcgiheb[ ]* (Type: Regex Match) [ ]*\'fjadcgiheb\'[ ]* (Type: Regex Match) [ ]*\"fjadcgiheb\"[ ]* 2.5 points 2.5 points Assume we have defined a class Node that implements user defined lists of numbers. Each object node of type Node has two attributes node.value and node.next with the usual interpretation. We want to add a function sum() to the class Node which will compute the sum of values ...
All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline. Your final submission will be graded. Note : If the question asks about a value of type string , remember to enclose your answer in single or double quotes. If the question asks about a value of type list , remember to enclose your answer in square brackets and use commas to separate list items. Consider the following Python function. def mystery(l,v): if len(l) == 0: return (v) else: return (mystery(l[:-1],l[-1]+v)) What does mystery([22,14,19,65,82,55],1) return? Accepted Answers: (Type: Numeric) 258 2.5 points What is the value of triples after the following assignment? triples = [ (x,y,z) for x in range(2,4) for y in range(2,5) for z in range(5,7) if 2*x*y > 3*z ] Feedback: triples = [] for x in range(2,4): # x = 2,3 for y in range(2,5): # y = 2,3,4 for z in range(...
Comments
Post a Comment