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

  • Home
  • SEARCH
  • 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 9248895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:03:35+00:00 2026-06-18T10:03:35+00:00

Consider the following binary tree: (taken from here ) Given that leaf nodes will

  • 0

Consider the following binary tree: (taken from here)

Given that leaf nodes will either be true or false, how can I find the branch (or branches) where all of the leaf nodes are true?

So if only 8, 5, 6 or 7 are true, then the first branch wouldn’t match (it would need 9 to be true to match), but the second branch would match as all of its leaves are true.

Even identifying this name for this type of search would help so I can Google it.

  • 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-18T10:03:36+00:00Added an answer on June 18, 2026 at 10:03 am

    You can use a recursive function, diving deeper into the tree and determining bottom-up whether for a certain branch all leaves are true. Those branches can then be stored in some list.

    Here’s some Python code. Call this function with the tree’s root node as the first parameter and an empty list as the second, and the list will be populated with the correct branches.

    def allTrue(node, trueList=[]):
        if isLeaf(node):
            return node.value == True
        else:
            leftTrue = allTrue(node.left, trueList)
            rightTrue = allTrue(node.right, trueList)
            bothTrue = leftTrue and rightTrue
            if bothTrue:
                trueList.append(node)
            return bothTrue
    

    One thing to look out for: Many programming languages try to be clever, or lazy, by not evaluating the second argument of x and y, if x is false already. In this case, however, this would result in not visiting the right branch if the left branch is not all-true, missing out some all-true branches. Thus the recursive calls better go to separate lines.

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

Sidebar

Related Questions

Consider the following array, which is claimed to have represented a binary tree: [1,
Consider the binary tree developed in Moose::Cookbook::Basics::Recipe3 To retrieve all nodes in preorder ,
Consider the following text from the PostgreSQL documentation on binary copying: 11-byte sequence PGCOPY\n\377\r\n\0
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following: >> bin: to-binary {Rebol} == #{5265626F6C} >> parse/all bin [s: to
Consider the following example, where grep is used to search in binary mode: $
I'm a bit confused regarding a conversion from bytes to integers. Consider the following
Let us consider the following picture this is a so called range tree. I
Consider following code, I want to make it a thread safe class, so that
Consider following piece of code: declare @var bit = 0 select * from tableA

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.