Hi, everyone.
So in this video, let us discuss what is posted at traversal.
OK, so suppose you have this root node, then you have the left subtree and you have the right subtree.
So Bulstrode Traversal says first you visit the left subtree, then you visit that I had subtree and
then you visit the data of the root node.
OK, so NRD left subtree right.
And the date of the root node, very simple.
OK, now let us apply the poster trevisan on this by Nutri.
OK, so first left, this will be number one and then the right separates or two and number three,
which is the data.
OK, so it will be basically left subtree.
Right subtree and so so five to.
OK, so when is completed?
Now let's go for two.
So this is only three, so likely three and two is visited.
So let's go to number three one.
OK, so this is the Beausoleil traversal for Destry.
Now, let us discuss the post-war traversal for Destry, very simple left right data, so left does
not exist.
Now let's go to right, OK, so left three right does not exist data.
So left right data.
So three, two.
And then one.
So this is the poster traversal for distri.
Now let us write the poster traversal for distri.
OK, I remember left right data.
OK, so left right data for 2010.
Simple again, left right data, so this will be 18, 24, 22, then 15.
So left is completed now let's go for the ride.
Sabry so left right data So this will be 31, 44 and 35 again left right data to this will be 66, 90
and 70.
Then 50.
OK, so 50.
Now, the rights are pretty complicated, so left is completely dry, discomfited now data.
OK, so left, right and data.
So now 25.
OK, so this is the poster traversal for this by Nutri.
So I hope you understood the logic.
Let us ride the cold.
So cold will be very, very simple.
So let's say you have a function visit.
So this visit function will take root as input and what it will do.
So first of all, left subtree.
So I will visit the left subtree, then I will visit the right subtree, left right data.
So let us visit the right separate.
And then finally I can directly, I can print, I can visit the data.
OK, so very simple.
Left right data.
So this is left.
This is right and this is data, OK, very, very simple.
Now, let us write the gold.
OK, so again, if this is Nedry, this is the poster traversal three to one.
OK, now let's write the code.
So first we will write the simple code for post water and then we will modify the code according to
the question.
OK.
So first of all, the base case.
So if rotational, that means the crew did not exist.
So you can basically done.
OK.
Then I have to follow the order left right data, so both order.
Left.
Dendrite.
So left, right, and then later.
OK, so very, very simple.
So this is the code for BORSTAR Driesell, first left, then right and then later.
OK, so in this question I have to return the property just so there's no need to print.
So again, I will create.
A vector of integers, let's say the name of the vector is answer, I will call it the function Bulstrode.
I will give the road Nordhausen, but I will give them three years in port and I will give the answer
Victor and finally I will return my answer.
OK, now let us modify the function so it will take a vector of integers as input and obviously by reference,
the name of the vector is answer.
OK, so instead of and here I have to modify so I will pass answer.
And answer, and instead of printing the value, I will store it in the onset of that.
OK, Sir Lancelot.
Bushwack.
Well, you.
OK, so let's run and then we will submit.
OK, now let's meet.
OK, so level code is working fine now let us discuss the timing, the space complexity for the postal
address.
OK, so again, that time complexity is basically big often as we have to visit each and every node
and the space complexity in the worst cases big often.
OK, so this is complexity is due to the collision course.
So it is due to the collision.
OK.
And is the number of nodes, total number of nodes presently by Nutri?
OK, now let us compare all the traversal.
OK, so, you know, traversal traversal and Beausoleil traversal.
OK, so what is in order traversal.
So in order to wss first you visit left then data and then right.
OK, so left-to-right what is preorder traversal.
So Purita is first you visit data, then you go for left and then you go for.
Right.
OK, so basically if you see carefully this is top down approach.
We are visiting from top to down.
OK, so if you have a tree.
You have you have you have left and then you have right.
So what I am doing first data and then left and then right.
So basically this top down approach.
OK, I'm going from top to bottom.
Now, the third one, which is the poster that.
So this is first who is it left, then who was it right and then who is it?
Data.
OK, so if you see carefully, this is bottom up approach.
This is bottom up.
OK, you have RWD, you have the left subtree, you have the right subtree and what you are doing left
right data.
So first I will visit the left, then I will visit the right, and then I will move ahead, move up
and then I will visit route.
OK, so this is bottom up.
So I'm repeating myself in order.
It is very simple.
You visit the left, then data and then right subtree.
OK, so Eliade preorder is very simple again.
Data left.
Right.
This is top down approach because first I am visiting the top node and then I'm going down ok.
I am going down and I'm printing the left and the right post today is different.
So Postgres left right data.
So this is Bottom-Up.
Why this is a Bottom-Up because first you are visiting the left subtree, then you are visiting the
right subtree and then you are visiting up.
OK, so very simple.
This is a top down approach.
This is bottom up approach and this is simple.
Left, right.
OK, and the time and space complexity for all the three approaches is basically big often and big often.
OK, so this is team, you know, traversal traversal and boaster traversal.
OK, so these are two different types of traversal that we can perform.
OK, thank you.