p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Go Back   p2p.wrox.com Forums > Other Programming > BOOK: Beginning Algorithms
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Algorithms
This is the forum to discuss the Wrox book Beginning Algorithms by Simon Harris, James Ross ; ISBN: 9780764596742
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Algorithms section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 21st, 2007, 02:48 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Remove method for Ternary Search Tree

Hi,

I enjoyed reading parts of this book as it really shins lights on the inner work of most sought after collection algorithm from a very simplistic point of view.

In Chapter 14, where Ternary Search Tree is discussed, authors do not include a removal method to exclude a word from the tree. Although, I assume such algorithm is intended for initial huge number of insertions and subsequence lookups, I too intend to use it for the reasons aforementioned. But I also need to very rarely remove a word from the tree (perhaps for every 100 insertions, one removal).

At first glance, I assumed writing a remove method would be simple but I was wrong. One has to take in many possible scenarios to effectively and correctly accomplish this task. After a few minutes of ponder, I came to the conclusion to do the following:
 
  • Find the last character of the word with the search method
  • Starting from that node, go up the tree, removing potentially "qualified" nodes
Going up the tree branch requires an additional node to the "node" class, let's call it a "parent node." So the insertion method had to be modified... All good so far.

Removing each node is based on many assumptions as to whether its has any child node depending on it, or even larger and smaller "sub-branches" hanging from it. I successfully wrote a remove method that "cosmetically" removes a set of nodes that are part of the "word." That is, if the search method is run against our word, it shows that it has been removed -- I can attest to that.

But removal of the word does not guarantee that "all" the character in the tree would be eliminated. That's due to the fact that some nodes are a part of another word(s). So one has to be very careful in implementation of the removal method.

I thought I had everything working perfectly until I noticed (thanks to vigorous testing) that number of nodes are not removed from the tree because they contain a sub-branch (larger or/and smaller) but the parent to these sub-branches that is also part of "removing" word can be safely removed _IF_ all the sub-trees are moved up the tree to its parent which requires a whole of work (perhaps a method that insert a single node to a branch and that single node can have an entire sub-tree hanging from it).

So obviously some of the node may truly belong to any word but the removal of such node requires rearranging a whole lot of sub-trees around which seems to be a very daunting task.

At the end, I would like to know whether has anyone implemented a sane and fast removal method for Ternary Search Tree that might want to share before I go on with my own implementation which seems to be not very elegant?

How about word replacement method? ... And how about a thread-safe version of this class? Is it safe to assume if a method uses recursion, it is best to be entirely synchronized? :)

Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search A Hierarchy Tree for Node where id=value sdaspen XSLT 4 February 2nd, 2007 06:34 PM
file search method esfaryn Excel VBA 0 November 4th, 2005 04:14 AM
conditional (ternary) operator using C# cjo ASP.NET 1.0 and 1.1 Basics 3 January 12th, 2005 11:55 AM
Binary Search Tree mehdi62b General .NET 1 September 10th, 2004 04:01 AM
best search method stoneman Access 2 September 4th, 2003 02:04 PM



All times are GMT -4. The time now is 08:07 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc