Download Here

Note : The Entire's Copyright And Credits Of the Above Material, Guide Or Question Paper is Owned by the Respected Owner and author of the Material. We had Uploaded This Only For Educational.

Top Corner Ads

Below Of Download Button

March 13, 2024

NPTEL Programming, Data Structures And Algorithms Using Python (Week 7 Quiz Assignment) 2024

4.5 Share It

Material Code -

Week 7 Quiz

Week 7 Quiz

1. Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the previous permutation in lexicographic (dictionary) order?

fjadchbegi

2. Assume we have defined a class Node that implements user-defined lists of numbers. What should be put in place of XXX and YYY?


def sum(self):
  if self.value == None:
      return(0)
  elif self.next == None:
      return(self.value)
  else:
      return(self.value + self.next.sum())
        
  • Replace XXX by 1 and YYY by 1 + self.next.sum()
  • Replace XXX by 1 and YYY by self.value + self.next.sum()
  • Replace XXX by self.value and YYY by 1 + self.next.sum()
  • Replace XXX by self.value and YYY by self.value + self.next.sum()

3. 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()))
        
  • The sum of the elements in the tree
  • The maximum sum across all root to leaf paths in the tree
  • The length of the longest root to leaf path in the tree
  • The number of root to leaf paths in the tree.

4. 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?

  • 39
  • 40
  • 41
  • 46

⚠️Disclaimer: The provided solutions are offered for reference purposes only, and we cannot guarantee their absolute accuracy. Students are encouraged to use these solutions as a learning aid and to verify their work independently. We emphasize the importance of understanding the concepts and completing assignments on your own.

Rating and Reviews

No comments:

Post a Comment