Programming, Data Structures And Algorithms Using Python Week 7
Programming, Data Structures And Algorithms Using Python Week 7
• 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.
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
2.5 points
2.5 points
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)
def foo(self):
if self.isempty():
return(0)
elif self.isleaf():
return(1)
else:
return(self.left.foo() + self.right.foo()))
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:
Hint
2.5 points
You may submit any number of times before the due date. The final submission will be considered for grading.