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 7547917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:34:43+00:00 2026-05-30T09:34:43+00:00

Given a (m-way) tree T: A / \ B C / \ \ D*

  • 0

Given a (m-way) tree T:

        A
       / \
      B   C
     / \   \
    D*  E*  F
   / \   \   \
  G   H*  I   J*

With the marked nodes D*, E* H* and J*, is there a fast way to retrieve all marked children under a given node, apart from walking all subtrees or storing all marked children for every node? I.e:

B -> D*, E*, H*
C -> J*
A -> D*, E*, H*, J*
  • 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-05-30T09:34:44+00:00Added an answer on May 30, 2026 at 9:34 am

    In principle you have a tradeoff between walking the tree and storing lists of your marked values. You mentioned the two extremes, I will give you an example below that sits somewhere in the middle between them.

    One idea that comes to mind is storing the next “layer” of marked children at each marked node, that should give a pretty balanced mix between storage and time, so in your example it wouldn’t save much, but for example if you have

            A
           / \
          B*  C
         / \   \
        D*  E   F
       / \   \   \
      G   H*  I*  J*
     /   / \
    K   L   M
    

    You would store D,I in B and H in D and “empty” markers in H,I,J.

    To get the list for a node you only have to walk until every branch hits a marked node, so for example, to get the list for A, you would have to walk from A->B and A->C->F->J, then B would give you I,D, D would give you H.

    You can also think of it as storing trees of marked nodes only alongside with the original tree, in this case, the two trees

      B        J
     / \
    D   I
    |
    H
    

    Depending on the distribution of marked nodes, you might be able to optimize this idea for your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a System.Timers.Timer, is there a way from the main thread to tell if
Is there a way to convert a given Python abstract syntax tree (AST) to
Given the following inheritance tree, what would be the best way of implementing it
Given a list of potential ID's is there a quick way using a single
Given a variable which holds a string is there a quick way to cast
Given a url to an image is there a way in Django/Python to pull
Is there a way to deploy a given war file on Tomcat server? I
Given a tree, I want to find the paths from the root to each
Given a node in an HTML document, N1, I need a concise way of
Is there a way to get the items which are under an expanded ADG

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.