11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

434 Chap. 13 Advanced Tree <strong>Structures</strong>this leads to a leaf node, the search key is compared against the key storedin th<strong>at</strong> node. If they m<strong>at</strong>ch, then the desired record has been found.Note th<strong>at</strong> during the search process, only a single bit of the search key is compared<strong>at</strong> each internal node. This is significant, because the search key could bequite large. Search in the PAT trie requires only a single full-key comparison,which takes place once a leaf node has been reached.Example 13.2 Consider the situ<strong>at</strong>ion where we need to store a library ofDNA sequences. A DNA sequence is a series of letters, usually many thous<strong>and</strong>sof characters long, with the string coming from an alphabet of onlyfour letters th<strong>at</strong> st<strong>and</strong> for the four amino acids making up a DNA str<strong>and</strong>.Similar DNA sequences might have long sections of their string th<strong>at</strong> areidentical. The PAT trie would avoid making multiple full key comparisonswhen searching for a specific sequence.13.2 Balanced TreesWe have noted several times th<strong>at</strong> the BST has a high risk of becoming unbalanced,resulting in excessively expensive search <strong>and</strong> upd<strong>at</strong>e oper<strong>at</strong>ions. One solution tothis problem is to adopt another search tree structure such as the 2-3 tree or thebinary trie. An altern<strong>at</strong>ive is to modify the BST access functions in some way toguarantee th<strong>at</strong> the tree performs well. This is an appealing concept, <strong>and</strong> it workswell for heaps, whose access functions maintain the heap in the shape of a completebinary tree. Unfortun<strong>at</strong>ely, requiring th<strong>at</strong> the BST always be in the shape of acomplete binary tree requires excessive modific<strong>at</strong>ion to the tree during upd<strong>at</strong>e, asdiscussed in Section 10.3.If we are willing to weaken the balance requirements, we can come up withaltern<strong>at</strong>ive upd<strong>at</strong>e routines th<strong>at</strong> perform well both in terms of cost for the upd<strong>at</strong>e<strong>and</strong> in balance for the resulting tree structure. The AVL tree works in this way,using insertion <strong>and</strong> deletion routines altered from those of the BST to ensure th<strong>at</strong>,for every node, the depths of the left <strong>and</strong> right subtrees differ by <strong>at</strong> most one. TheAVL tree is described in Section 13.2.1.A different approach to improving the performance of the BST is to not requireth<strong>at</strong> the tree always be balanced, but r<strong>at</strong>her to expend some effort toward makingthe BST more balanced every time it is accessed. This is a little like the idea of p<strong>at</strong>hcompression used by the UNION/FIND algorithm presented in Section 6.2. Oneexample of such a compromise is called the splay tree. The splay tree is describedin Section 13.2.2.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!