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())
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()))
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?
⚠️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.
No comments:
Post a Comment