Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I want to create a data structure to work with isomorphic tree. I don't search for a "algorithms" or methods to check if two or more trees are isomorphic each other. Just to create various trees with the same structure.

Example:

  2 - - - - - - - 'a' - - - - - - - 3.5 
 / \              / \               / \
3   3           'f' 'y'           1.0 3.1
   / \              / \               / \
  4   7           'e' 'f'           2.3 7.7

The first "layer" or tree is the "natural tree" (a tree with natural numbers), the second layer is the "character tree" and the third one is the "float tree".

The data structure has a method or iterator to traverse the tree and to make diferent operations with its values. These operations could change the value of nodes, but never its structure (first I create the structure and then I configure the tree with its diferent layers). In case of that I add a new node, this would be applied to each layer.

Which known design pattern fits with this description or is related with it?

share|improve this question
    
Are you forced into this implementation, or can you consider other options to accomplish the same end effect? I.e. can you not just create a Node object to contain the "isomorphic"-ally associated datapoints and store these nodes in one tree? –  Ed Hastings Dec 11 '12 at 18:47
add comment

1 Answer 1

If your trees are isomorphic on principle, there is no point at all in actually maintaining three parallel trees - that's just a waste of pointers and processor cycles. instead you should define a composite type that holds what ever items you want to maintain in parallel, and build one tree containing such composite nodes. Remember, how you access or present your data to other modules or users can be entirely independent from the actual data structure.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.