Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:16:32+00:00 2026-06-17T08:16:32+00:00

I have multi-way tree structure, which i have to traverse to determine status. I

  • 0

I have multi-way tree structure, which i have to traverse to determine status. I am looking into ‘Post-Order’ type traversal where leaf nodes are processed first. And search end condition depends on any of child node having status inactive. Also, from performance perspective, i would to use JDK7’s fork-join mechanism.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:16:33+00:00Added an answer on June 17, 2026 at 8:16 am

    Here is a (very) rough sketch of how you could do it.

    final class TreeNode {
        private final Iterable<TreeNode> children;
    
        TreeNode(Iterable<TreeNode> aChildren) {
            children = aChildren;
        }
    
        Iterable<TreeNode> getChildren() {
            return children;
        }
    
        void postorder(TreeNodeIterator iterator) {
            postorderTraverse(this, iterator);
        }
    
        private void postorderTraverse(TreeNode node, TreeNodeIterator iterator) {
            for (TreeNode child : children) {
                postorderTraverse(child, iterator);
            }
            iterator.visit(node);
        }
    
        void postorderParallel(TreeNodeIterator iterator) {
            new ForkJoinPool().invoke(new VisitNodeAction(iterator, this));
        }
    
        interface TreeNodeIterator {
            void visit(TreeNode child);
        }
    
        private class VisitNodeAction extends RecursiveAction {
            private final TreeNodeIterator iterator;
            private final TreeNode node;
    
            private VisitNodeAction(TreeNodeIterator iterator, TreeNode node) {
                this.iterator = iterator;
                this.node = node;
            }
    
            @Override
            protected void compute() {
                List<RecursiveAction> tasks = new LinkedList<RecursiveAction>();
                for (TreeNode child : children) {
                    tasks.add(new VisitNodeAction(iterator, child));
                }
                invokeAll(tasks);
                iterator.visit(node);
            }
        }
    }
    

    Some things that would need to be modified:

    • Adding your check for the status being inactive. Easiest way would be to keep a atomic boolean in each RecursiveAction that is checked before processing the node and updated when a node is inactive, although this is not a very clean or functional route.
    • Adding a way to decide when new threads should be used, the above uses a thread for every node. Also, you could possibly optimize it a bit by not creating a ForkJoinPool on every invocation of postorderParallel.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to design the Domain objects which can have multi-lingual
I have a multi-step order form built in this manner: Step 1: Choose category
I have a multi-dimensional array, which basically consists of one sub-array for each year.
In a multi-dimensional space, I have a collection of rectangles, all of which are
I have a tree-like object structure that consists of two types of objects: object
I have a multi column report in crystal report.Is there any way to start
I have a multi language site, what is the way to proceed for good
Is there any way to have multi-line plain-text, constant literals in C++, à la
I have a multi-paned form, in the left pane is a tree and in
I have a multi-threaded application which scales well to begin with, but running on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.