I got a java test done and somehow my answer for this question is incorrect, can you guys help me explain it?
So the question is: in a binary tree with height 3 the least deep leaf has depth 2 (Root has depth 0).
a)Max numbers of nodes this tree can have?
b) Min numbers of nodes this tree can have?
My answer is 7 and 4, yet my professor said it should be 13 and 5
wat confused me was least deep leaf has depth 2. Why so, it should be depth 3 if height is 3.
It means the leaf that's not at the deepest level (level 3, matching the height). In this case, 7 in the following tree is the "least deep" leaf. The height is 3, the least deep leaf is at level 2, and the tree is as full as it can be, so it's the answer to part a of your question:
4 5 6 7
8 9 a b c d
That's 13 nodes, on the assumption that the height excludes the root. However, if the root is at depth 0 then that's more of a safe assumption than usual. For the minimum you need to recognize that the tree isn't required to be full or complete, and the smallest tree possible while maintaining the two restrictions (a height of 3 and the least deep leaf at level 2) is some variation of this:
The height is still 3, the least deep leaf is still at level 2, and the tree cannot have fewer than 5 nodes without breaking one of those two invariants.