• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Almost complete binary tree help

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys - so not a programming problem here, but one that I just can't seem to figure out.

In my notes, it says,

A binary tree of depth d is almost complete if:
1)Each leaf in the tree is either at level d or at d-1
2)For any node n in the tree with a right descendant at level d,
all the left descendant of n that are leaves are also at level d.

Here are two examples:


The first one, according to my notes, is not almost complete because: "Since A has a right descendant J at level 3, but it has a left descendant E that is a leaf at level 2"
I think that makes sense.

However, for the second one...we didn't get an answer. But, from what I can tell, we have a right descendant F at level 2, and at least all the leaves on the left are at level 2 - so that would be an almost complete binary tree.

Am I even thinking straight here? Finals week...brain's almost fried.

Thanks,
Josh
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're a bit off. The tree is of level 3, correct?

2)For any node n in the tree with a right descendant at level d...



So in the right-hand example, which are the nodes which have a right descendant at level 3?

all the left descendant of n that are leaves are also at level d.



Okay, now that you have identified those nodes, and only those nodes, do they in fact satisfy this requirement?

(I can't really answer those myself, because I don't know what a "right descendant" is, but that's the process you have to follow to answer the question.)
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic