Week 7 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)

 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
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 in the list. An incomplete implementation of sum() given below. What should be put in place of XXX and YYY?
def sum(self):
  if self.value == None:
    return(0)
  elif self.next == None:
    return(XXX)
  else:
    return(YYY)
 
 
 
 
2.5 points
Suppose we add this function foo() to the class Tree that implements search trees. For a name mytree with a value of type Tree, what would mytree.foo() compute?
def foo(self):
        if self.isempty():
            return(0)
        elif self.isleaf():
            return(self.value)
        else:
            return(self.value + max(self.left.foo(),
                                    self.right.foo()))
 
 
 
 
2.5 points
The preorder traversal of a binary search tree with integer values produces the following sequence: 35, 23, 26, 46, 40, 39, 41, 52. What is the value of the right child of the root of the tree?
 
 
 
 

Comments

Popular posts from this blog

Week 6 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)

Week 4 - Quiz (Programming, Datastructures and Algorithms using Python) (NPTEL 2022 - CS26)