1.) Let T be the binary tree a.) Give the out put of algorithm preorderPrint (T,
ID: 3609611 • Letter: 1
Question
1.) Let T be the binary tree a.) Give the out put of algorithm preorderPrint (T,T.root( )). b.) Give the out put of algorithm parenPrint(T, T.root( )). c.) Give the out of postorderPrint (T, T.root ( ) ). d.) Give the out of printExpression (T, T.root( )). Could any send solution for above question. Please explain good 1.) Let T be the binary tree a.) Give the out put of algorithm preorderPrint (T,T.root( )). b.) Give the out put of algorithm parenPrint(T, T.root( )). c.) Give the out of postorderPrint (T, T.root ( ) ). d.) Give the out of printExpression (T, T.root( )). Could any send solution for above question. Please explain goodExplanation / Answer
Preorder traversal of a binary tree
Algorithm binaryPreorder(T,v)
Visit node v
If T.isInternal(v) then
binaryPreorder(T,T.leftChild(v))
binaryPreorder(T,T.rightChild(v))
Algorithm binaryPreorder(T)
binaryPreorder(T,T.root())
Postorder traversal of a binary tree
Algorithm binaryPostorder(T,v)
if T.isInternal(v) then
binaryPostorder(T,T.leftChild(v))
binaryPostorder(T,T.rightChild(v))
Visit node v
Algorithm binaryPosttorder(T)
binaryPostorder(T,T.root())
Inorder traversal of a binary tree
Algorithm binaryInorder(T,v)
if T.isInternal(v) then
binaryInorder(T,T.leftChild(v))
Visit node v
if T.isInternal(v) then
binaryInorder(T,T.rightChild(v))
Algorithm binaryIntorder(T)
binaryPostorder(T,T.root())
Algorithm for printing of the expression
Algorithm printExpression(T,v):
Input: T an expression tree v a node in T.
if T.isLeaf(v) then
print v.element() // for aleaf the element is a value
else
print "("
printExpression(T,T.leftChild(v))
print v.element() // for aninternal node the element is an operator
printExpression(T,T.rightChild(v))
print ")"
Algorithm printExpression(T):
printExpression(T,T.root())
I hope this will helps to you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.