CSE 331 Homework 5: Expression Trees and Tree Traversals, Assignments of Computer Science

The instructions and problems for homework 5 in cse 331, a computer science course focusing on expression trees and tree traversals. Students are required to submit their solutions via handin, named according to their last name, and include their name and msu net id on each page. Problems include exploring the relationship between expression trees and tree traversals, identifying the original expression tree from a postorder traversal, and performing splay tree operations.

Typology: Assignments

Pre 2010

Uploaded on 07/23/2009

koofers-user-wag
koofers-user-wag 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 331: Homework 5 Spring 2009
Due by 11:59 PM Friday 27 Feb 2009
Submission
Submit your work via Handin. Name your file <name>Results.pdf, where
<name>is your last name, as in jonesResults.pdf.Please make sure that
your name and your MSU net ID (username) appear at the top of
every page and once at the beginning of any code that you may sub-
mit.You may lose points if you do not meet the submission criteria, something
especially likely if your name is missing from sheets on your homework. You
are also responsible for making sure that your assignment is submitted correctly
over Handin.
Problems:
Do the following problems. As always, we do not want just the “answers”, we
want the reasoning behind the answers. An answer that lacks proper justifica-
tion and reasoning will frequently lose several points.
1. (20 points) Explore the relationship between an expression tree and the
sequence generated by a tree traversal:
(a) Draw a binary expression tree for the following preorder sequence:
*+-bc+dae
(b) Is the tree in part a unique? Why or why not?
(c) Do preorder sequences generate unique trees? Why or why not (a
rigorous proof is not required)?
(d) Draw a binary expression tree for the following inorder sequence:
a-b*e+c+b
(e) Is the tree in part d unique? Why or why not?
(f) Do inorder sequences generate unique trees? Why or why not?
1
pf2

Partial preview of the text

Download CSE 331 Homework 5: Expression Trees and Tree Traversals and more Assignments Computer Science in PDF only on Docsity!

CSE 331: Homework 5 Spring 2009

Due by 11:59 PM Friday 27 Feb 2009

Submission

Submit your work via Handin. Name your file Results.pdf, where is your last name, as in jonesResults.pdf. Please make sure that your name and your MSU net ID (username) appear at the top of every page and once at the beginning of any code that you may sub- mit. You may lose points if you do not meet the submission criteria, something especially likely if your name is missing from sheets on your homework. You are also responsible for making sure that your assignment is submitted correctly over Handin.

Problems:

Do the following problems. As always, we do not want just the “answers”, we want the reasoning behind the answers. An answer that lacks proper justifica- tion and reasoning will frequently lose several points.

  1. (20 points) Explore the relationship between an expression tree and the sequence generated by a tree traversal:

(a) Draw a binary expression tree for the following preorder sequence:

      • b c + d a e (b) Is the tree in part a unique? Why or why not? (c) Do preorder sequences generate unique trees? Why or why not (a rigorous proof is not required)? (d) Draw a binary expression tree for the following inorder sequence: a - b * e + c + b (e) Is the tree in part d unique? Why or why not? (f) Do inorder sequences generate unique trees? Why or why not?
  1. (20 points) The following sequence is a post order traversal of an expression tree. Give the corresponding original expression tree and the content of the stack for each scanning position i ∈ { 0 , 1 , 2 , ..., 9 } during the scan.

i 1 2 3 4 5 6 7 8 9 key 9 2 3 * - 9 3 / +

  1. (20 points) Problem 4.25 on page 177.
  2. (20 points) Problem 4.27 on page 177. For every access, give the resulting intermediate tree after the access.
  3. (20 points) Problem 4.28 on page 177. Show the three intermediate trees: after splaying at 6, after splaying the largest key less than 6 to the left child of the root, and the final tree.