Welcome back, everyone.
So when you come up with your test case for these interface design questions, what will happen is that
you're going to be expected to call your interface and its methods in a sequence of ways that built
out the tree that I showed you in the previous example.
Generally speaking, your interviewer may or may not walk through the problem as extensively as I did.
But as you start thinking about test cases or conversing with your interviewer, a general picture of
what we went through should emerge here.
What you'll see will happen is that with our general test case, what we've done is initialized the
monarchy with Jake as the king.
So what we're doing is calling the methods in the same order that we went through in order to build
out such a tree.
So we need to call the birth of Katherine to Jake.
And here you might change up the order in which these different calls happen, but it should not deviate
from how this tree looks.
In the end, the only thing to consider is the order in which children get born to their parent.
What this means is that because Seline is the third child of Jake, you cannot call the birth of Seline
before you call the birth of Tom, because if you do, then Saleen gets born before Tom does.
This might be one of those cases where, as you're thinking about this test case, that's something
that pops to your mind about the way that the children are ordered, because the succession of this
example does matter by birth order.
So that's an important thing you need to notice.
So let's say, for example, Arthur Katherine gets born to Jake, Jane gets born to Katherine, then
let's say father gets born to Jane and then Tom gets born to Jake here.
It doesn't matter when Tom is born, as long as it's after Katherine.
Katherine can have all of her children and you can call all of these arguments.
However, you must call Tom before sailin.
That's the real only order that matters as far as the children birth order goes.
Let's say afterwards.
Then Celine gets born to Jake and let's say Marc then gets born to Katherine and then Peter gets born
to Celine.
Even in this order, this is still the resulting tree for our best case test case example.
So when you think about how you're designing the order of the calls of this monarchy, because at this
point we know what these methods will do, we have to think about how it constrains to the give an example
of what exactly we're trying to build is.
And here this should be very clearly defined to you by your interviewer.
When they told you about the monarchy family tree.
You might want to discuss this as well as your writing this out, because at this point, when you're
figuring out these methods and when to call them to form this tree, these might be the types of examples
that are jumped to your head.
So moving on from here, let's say we call, then get order of succession.
Clearly, the order of succession goes Jake, then Catherine and then Jane and then Fera, because these
are all of the first borns, first born children and subsequent first born children.
And then after that, it goes Mark for Katherine and then it goes Tom and then finally Saleen and Peter.
So this is the same order of succession we saw earlier.
Let's say once again, we kill off Jake and we kill off Jane.
What then happens if we scratch out these names?
To represent their deaths, as that will see the new order of succession goes Katherine and then Farah,
as you can see, and then it's Mark and then Tom and then Celine and Peter, which is also what you
see in the remainder of the array.
So this is going to be the order of calls that will come from the interface that we're expected to design
as our test case.
So with interface design questions, oftentimes what's going to happen is that they want to test that.
The order of your sequencing of what the logic is intended to achieve with your interface is valid once
you've designed the interface.
So these are the different ways that you want to think about what kind of constraints you need to capture
in the logic of the interface that you're designing.
So now that we understand what it is that we're building here, I want you to try and see if you can
figure out some of the insights so that you can try and solve this question yourself.
Some hints that might help you before you dive in.
You can pause the video here and try and figure out yourself or you can listen to me talk and then try
it yourself, because in the next video, we're going to solve it all together.
But what I want you to notice is that this is indeed a tree structure and the order of succession is
probably the most challenging part here.
What I want you to think about is the order in which these elements appear.
And when you think about this tree, it's not a binary tree, but it is a binary tree, meaning that
there are still these different tree nodes, but they might have any number of branches.
So here you can still utilize the exact same traversal order, breadth versus depth research that we
know with trees, because as we know with enteric trees, these are still trees at the end of the day,
which means that our breadth of research and our depth research and even our subsequent order of the
traversal, whether it's preorder in order or post order, these are all things that can help you.
So I want you to think about this question in the context of what it's like to build out an energy tree
and then perform one of these search algorithms.
And when you do think about that order traversal, if it even helps you, so it's kind of a tree problem
that's wrapped up inside of this interface.
But this is where I mentioned that these different data structures that you already know could help
you solve these problems.
In fact, these problems are probably grounded in these data structures that you already know.
So here, I want you to try and solve this question yourself.
Think about that interface design, those three methods, birth, death and the order of succession
and how it all ties together.
I'm going to solve it with a JavaScript class in the next video.
You might have to do it in your own native language implementation, whichever language you choose to
do.
And in the next video, let's do it together.