Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:08,240 --> 00:00:15,030
So far we've talked about traversing a binary tree adding to a tree deleting from a tree but there's
2
00:00:15,050 --> 00:00:22,100
a few other things that it's important to know especially if you're taking an algorithm class or you're
3
00:00:22,100 --> 00:00:29,360
needing to create a good visualization for search and that's what binary trees are great for and the
4
00:00:29,360 --> 00:00:37,280
very first thing we're going to do in this tutorial is go over what's called a pre order traversal.
5
00:00:37,280 --> 00:00:40,750
And there is a few properties associated with it.
6
00:00:40,970 --> 00:00:47,750
And I'm going to walk through the way the process works on the sample binary tree right here.
7
00:00:47,780 --> 00:00:53,600
So the very first thing that you're going to do in a preorder traversal is visit the root.
8
00:00:53,660 --> 00:00:57,670
So right here you can see that the root is 7.
9
00:00:57,740 --> 00:01:03,200
And so we're going to traverse a tree and actually put this into an array appear at the top.
10
00:01:03,200 --> 00:01:12,140
So for the array we're going to start off in or just say the first value we get is 7 because we're traversing
11
00:01:12,380 --> 00:01:16,780
a tree and pre order the next step is actually to move to the left.
12
00:01:16,790 --> 00:01:24,550
So we would move to this one value right here and we'd put this one in the array.
13
00:01:24,740 --> 00:01:31,090
From there we would go further down to the left and get zero.
14
00:01:31,220 --> 00:01:37,490
Put that in the array and then we're just going to keep on going down the list so now we're going to
15
00:01:37,490 --> 00:01:42,860
come back up because zero doesn't have any children.
16
00:01:42,950 --> 00:01:44,120
It's leafnode.
17
00:01:44,130 --> 00:01:46,810
So then we're going to go over to three.
18
00:01:46,890 --> 00:01:49,550
And so three is going to be the next value.
19
00:01:49,790 --> 00:01:52,900
And from there we have to
20
00:01:56,100 --> 00:02:04,050
and then back up to 3 and back down to 5 and evens is pretty straightforward it's more a process of
21
00:02:04,050 --> 00:02:05,820
understanding just how it works.
22
00:02:05,830 --> 00:02:08,660
But still finish this one out so you can see it.
23
00:02:08,850 --> 00:02:18,440
So from five go down to four and then go back up to 5 and then go to six.
24
00:02:18,450 --> 00:02:25,050
And so we've completed the left side of the binary search tree.
25
00:02:25,230 --> 00:02:28,370
So now that we've done that we traverse all the way back up.
26
00:02:28,500 --> 00:02:32,810
And then we go to that next value which is going to be 9.
27
00:02:32,820 --> 00:02:35,260
So we'll go 7 to 9.
28
00:02:35,340 --> 00:02:46,910
So this is on the right subtree and then from 9 would go down to 8 and then to 10 and that's it.
29
00:02:47,220 --> 00:02:56,550
So this is how you traverse a tree using the pre order method when you're traversing a binary search
30
00:02:56,550 --> 00:02:56,830
tree.
31
00:02:56,850 --> 00:03:01,320
In the next video we're going to go over what's called the Post order traversal.
32
00:03:01,320 --> 00:03:02,530
So see you in that video.
3455
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.