jan21 - Illinois Institute of Technology Department of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Illinois Institute of Technology Department of Computer Science Lecture 1: January 21, 2009 CS 430 Introduction to Algorithms Spring Semester, 2009 1 How to draw a tree 1.1 Defining the problem The first algorithm we examine is one to determine a clean way to draw a tree. For instance, we could draw a tree in this fashion: This is undesirable. We can give an aesthetic to define properties that we would like to see in the output: Aesthetic 1: Nodes on the same level should be on a straight line, and lines defining levels should be parallel and evenly spaced. As well, nodes on a level should be in the same left-to-right order as in the level-order traversal. These observations lead to this drawing: This is better but still not great. Let us insist on a second aesthetic: CS 430Spring, 2009 2 Lecture 1: January 21, 2009 Aesthetic 2: A left child must be to the left of its parent; a right child must be to the right of its parent. How can we accomplish this algorithmically? 1.2 Knuths algorithm (1971) Knuths algorithm is a simple recursive algorithm for drawing a tree. To understand the order of the operations, think of the tree being printed on a line printer on its side , so the right part of the tree comes out first. 1. Go down a level and print the right subtree recursively. 2. Go up a level and to the left and print the root ....
View Full Document

Page1 / 6

jan21 - Illinois Institute of Technology Department of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online