hw4Solutions

hw4Solutions - BCB 567/CprE 548 Fall 2007 Homework 4...

Info iconThis preview shows pages 1–2. 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: BCB 567/CprE 548 Fall 2007 Homework 4 Solutions I am going to start this solution page with a note on this homework and answering application questions using suffix trees in general. I am seeing a lot of very convoluted and complicated answers to simple problems. You should have noticed by now that the solutions to the various homework problems utilize tree traversals. For the benefit of those who do not have a lot of computer science background, or just need a refresher, I am going to talk a bit about traversals and what they are good for. • Top-down Traversal: A top-down operation on a tree has the following property. The operation can be performed on a node as long as the operation has been performed on its parent. Top down traversals can make certain types of operations more efficient. For example, lets say you wanted to find the lowest ancestor of every leaf with property X . You could start at each leaf and traverse up the tree until you find the said ancestor. However, this would take O ( Lh ) time in the worst case, where L is the number of leaves and h is the height of the tree. If instead you used a top down tree traversal to answer the question, you would take O ( N ) time, where N is the number of nodes in the tree. How to perform this operation in a top down manner? It is simple. Remember to describe a top down operation on a tree, we only have to answer the question: Given the answer for the parent, what is the answer for the child? In this case, we use the following logic. If I have property X , the lowest ancestor with property X is myself. Otherwise, copy the answer from my parent. It is that simple. • Bottom-up Traversals: A bottom up operation on a tree has the following property. The operation can be performed on a node as long as the operation has been performed on all of its children first. Like top down operations, bottom up operations are made for certain problems. For example, lets say that we label all the leaves with property X or property Y . We wish a node to have property X only if all of the leaves in its subtree have property X and property Y only if all of the leaves in its subtree have property Y . The bad way to solve this problem would be to independently traverse the subtrees of each node to come to the answer. This would take O ( N 2 ) in the worst case. Obviously, the answer can be answered very quickly in a bottom up manner. Given the answer for all of the children, we can quickly decide on the answer for the parent. In this case, if all children have property X , then the parent has property X . If all children have property Y , then the parent has property Y . It is that simple. Many suffix tree applications make use of either (or both) of these two operations, as well as possibly finding some specific leaf (usually leaf 1) and then tracing a path to the root. It is important to understand these two operations and how to use them to truly master the use of the suffix tree....
View Full Document

This note was uploaded on 10/01/2009 for the course CS BCB/Co taught by Professor Olivereulenstein during the Fall '06 term at Iowa State.

Page1 / 5

hw4Solutions - BCB 567/CprE 548 Fall 2007 Homework 4...

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

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