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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:21:36+00:00 2026-06-03T19:21:36+00:00

Here is a link to a similar question with a good answer: Java Algorithm

  • 0

Here is a link to a similar question with a good answer: Java Algorithm for finding the largest set of independent nodes in a binary tree.

I came up with a different answer, but my professor says it won’t work and I’d like to know why (he doesn’t answer email).

The question:

Given an array A with n integers, its indexes start with 0 (i.e, A[0],
A[1], …, A[n-1]). We can interpret A as a binary tree in which the two
children of A[i] are A[2i+1] and A[2i+2], and the value of each
element is the node weight of the tree. In this tree, we say that a
set of vertices is “independent” if it does not contain any
parent-child pair. The weight of an independent set is just the
summation of all weights of its elements. Develop an algorithm to
calculate the maximum weight of any independent set.

The answer I came up with used the following two assumptions about independent sets in a binary tree:

  1. All nodes on the same level are independent from each other.
  2. All nodes on alternating levels are independent from each other (there are no parent/child relations)

Warning: I came up with this during my exam, and it isn’t pretty, but I just want to see if I can argue for at least partial credit.

So, why can’t you just build two independent sets (one for odd levels, one for even levels)?

If any of the weights in each set are non-negative, sum them (discarding the negative elements because that won’t contribute to a largest weight set) to find the independent set with the largest weight.

If the weights in the set are all negative (or equal to 0), sort it and return the negative number closest to 0 for the weight.

Compare the weights of the largest independent set from each of the two sets and return it as the final solution.

My professor claims it won’t work, but I don’t see why. Why won’t it work?

  • 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-03T19:21:38+00:00Added an answer on June 3, 2026 at 7:21 pm

    Your algorithm doesn’t work because the set of nodes it returns will be either all from odd levels, or all from even levels. But the optimal solution can have nodes from both.

    For example, consider a tree where all weights are 0 except for two nodes which have weight 1. One of these nodes is at level 1 and the other is at level 4. The optimal solution will contain both these nodes and have weight 2. But your algorithm will only give one of these nodes and have weight 1.

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

Sidebar

Related Questions

I asked a precursor to this question here: Click link in DIV and show
Just a follow up question to this one here => link Is it possible
I couldn't find a similar question, that's why here it is: Whats the best
Similar question here: jQueryMobile, Phonegap and Device Token - iOS The scenario is, I
This question is similar to the one i asked here . But its related
This question seems similar to those asked in a few other posts: here and
there is a similar question in here but for some reason I cannot make
The question quite an older and often asked around, i have similar questions here
Continuing another but similar question about testing ( see here ). I'll use a
This is very similar to this question ( link ), but I'm not quite

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.