NPTEL Programming Data Structures And Algorithms Using Python | NPTEL Week 7 Quiz Assignment | NPTEL Assignment Solutions

NPTEL Programming, Data Structures And Algorithms Using Python Week 7 Quiz Assignment | NPTEL Swayam Assignment Answers 



programming, data structures and algorithms nptel


MCQs (multiple choice questions) Nptel Week 7 Quiz Answers:


Note:

(1) If the question asks about a value of type string, remember to enclose your answer in single or double quotes.
(2) 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.


Q.1: Given the following permutation of a,b,c,d,e,f,g,h,i,j, what is the next permutation in lexicographic (dictionary) order? Write your answer without any blank spaces between letters.

fjadbihgec

Answer is :  'fjadcbeghi'



Q.2: We want to add a function length() to the class Node that implements user defined lists which will compute the length of a list. An incomplete implementation of length() given below. You have to provide expressions to put in place of XXX, YYY. and ZZZ.

def length(self):
  if self.value == None:
     return(XXX)
  elif self.next == None:
     return(YYY)
  else:
     return(ZZZ)

Options are:

(a) XXX: 0, YYY: 0, ZZZ: self.next.length()
(b) XXX: 0, YYY: 0, ZZZ: 1 + self.next.length()
(c) XXX: 0, YYY: 1, ZZZ: self.next.length()
(d) XXX: 0, YYY: 1, ZZZ: 1 + self.next.length()

Answer is : (d) XXX: 0, YYY: 1, ZZZ: 1 + self.next.length()


Q.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(1)
        else:
            return(1 + max(self.left.foo(),self.right.foo()))

Options are:

(a) The number of nodes in mytree
(b) The largest value in mytree.
(c) The length of the longest path from root to leaf in mytree.
(d) The number of paths in mytree.

Answer is: (c) The length of the longest path from root to leaf in mytree.



Q.4: Inorder traversal of a binary tree has been defined in the lectures. A preorder traversal lists the vertices of a binary tree (not necessarily a search tree) as follows:
(1) Print the root.
(2) Print the left subtree in preorder.
(3) Print the right subtree in preorder.
Suppose we have a binary tree with 10 nodes labelled a, b, c, d, e, f, g, h, i, j, with preorder traversal gbhecidajf and inorder traversal ehbicgjafd. What is the right child of the root node?


Answer is : 'd'

If you are facing any queries regarding this assignment solutions, then please drop comment in comment section.

Post a Comment

0 Comments