The larger binary trees in this chapter were generated automatically by a program.This | StudySoup

Textbook Solutions for Data Structures and Algorithm Analysis in Java

Chapter 4 Problem 4.38

Question

The larger binary trees in this chapter were generated automatically by a program.This was done by assigning an (x, y) coordinate to each tree node, drawing a circlearound each coordinate (this is hard to see in some pictures), and connecting eachnode to its parent. Assume you have a binary search tree stored in memory (perhapsgenerated by one of the routines above) and that each node has two extra fields tostore the coordinates.a. The x coordinate can be computed by assigning the inorder traversal number.Write a routine to do this for each node in the tree.b. The y coordinate can be computed by using the negative of the depth of thenode. Write a routine to do this for each node in the tree.c. In terms of some imaginary unit, what will the dimensions of the picture be?How can you adjust the units so that the tree is always roughly two-thirds ashigh as it is wide?d. Prove that using this system no lines cross, and that for any node, X, all elementsin Xs left subtree appear to the left of X and all elements in Xs right subtreeappear to the right of X.

Solution

Step 1 of 4)

The first step in solving 4 problem number 38 trying to solve the problem we have to refer to the textbook question: The larger binary trees in this chapter were generated automatically by a program.This was done by assigning an (x, y) coordinate to each tree node, drawing a circlearound each coordinate (this is hard to see in some pictures), and connecting eachnode to its parent. Assume you have a binary search tree stored in memory (perhapsgenerated by one of the routines above) and that each node has two extra fields tostore the coordinates.a. The x coordinate can be computed by assigning the inorder traversal number.Write a routine to do this for each node in the tree.b. The y coordinate can be computed by using the negative of the depth of thenode. Write a routine to do this for each node in the tree.c. In terms of some imaginary unit, what will the dimensions of the picture be?How can you adjust the units so that the tree is always roughly two-thirds ashigh as it is wide?d. Prove that using this system no lines cross, and that for any node, X, all elementsin Xs left subtree appear to the left of X and all elements in Xs right subtreeappear to the right of X.
From the textbook chapter Trees you will find a few key concepts needed to solve this.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Data Structures and Algorithm Analysis in Java 3 
Author Mark A. Weiss
ISBN 9780132576277

The larger binary trees in this chapter were generated automatically by a program.This

Chapter 4 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back