This preview has intentionally blurred sections. Sign up to view the full version.View Full 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 430—Spring, 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 Knuth’s algorithm (1971) Knuth’s 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
This note was uploaded on 04/07/2009 for the course CS 430 taught by Professor Kapoor during the Spring '08 term at Illinois Tech.
- Spring '08