Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:09,440 --> 00:00:16,350
‫In this episode we're going to walk through the structure set up in the properties of a binary search
2
00:00:16,350 --> 00:00:16,880
‫tree.
3
00:00:17,160 --> 00:00:25,350
‫The first thing to know about a binary search tree is what it is and how you can think of it is a visual
4
00:00:25,380 --> 00:00:28,670
‫representation of a data structure.
5
00:00:28,740 --> 00:00:36,260
‫And when you connect the search functionality what you're doing is trying to create a rapid way that
6
00:00:36,340 --> 00:00:41,590
‫you can iterate through your data structure to give you a result.
7
00:00:41,610 --> 00:00:43,860
‫And so if that doesn't make any sense.
8
00:00:43,860 --> 00:00:47,010
‫Don't worry we're going to walk through every stage of it.
9
00:00:47,010 --> 00:00:53,460
‫The first thing we're going to do is talk first about how to set it up because that's the way that I
10
00:00:53,460 --> 00:00:56,540
‫learned best and that's the way that helps me out the most.
11
00:00:56,540 --> 00:01:01,980
‫So to set it up you're going to assign a integer to a root node.
12
00:01:02,250 --> 00:01:05,220
‫And so we put that up at the top of the tree.
13
00:01:05,250 --> 00:01:10,300
‫And so we're going to give it a value of 15 and we're going to put a circle around it.
14
00:01:10,320 --> 00:01:15,360
‫That is what is called our root node.
15
00:01:15,600 --> 00:01:16,590
‫That is
16
00:01:19,850 --> 00:01:26,360
‫the root node and everything else is going to be based off of that whether it's to the left or to the
17
00:01:26,360 --> 00:01:27,000
‫right.
18
00:01:27,020 --> 00:01:33,060
‫So the next thing we're going to do is give it to different branches to its children.
19
00:01:33,080 --> 00:01:40,250
‫So we're going to have a branch here and branch here and then we're going to go to different nodes the
20
00:01:40,250 --> 00:01:48,530
‫other node on the left is going to be 12 and the node on the right is going to be 20.
21
00:01:48,750 --> 00:01:54,570
‫Now each of these nodes has their own set of children.
22
00:01:54,720 --> 00:01:59,390
‫And so to represent that we're going to draw two more.
23
00:01:59,460 --> 00:02:08,630
‫And so we have a node here and here and this one is going to be 10 and on this one we're going to set
24
00:02:08,630 --> 00:02:17,820
‫it up with 14 and we're going to keep on going here on the left hand side of the of the tree.
25
00:02:17,900 --> 00:02:32,030
‫And so the last one we're going to do is going to have two nodes and it's going to be one and 11.
26
00:02:32,250 --> 00:02:40,770
‫Now when we get to a spot of the tree where it did know does not have eight children.
27
00:02:40,860 --> 00:02:43,590
‫These are called leaves.
28
00:02:43,590 --> 00:02:54,730
‫So this is and this these are all called leave notes
29
00:02:58,990 --> 00:03:05,620
‫and so when you hear someone say the leaf of the tree or the leaves of the tree that means that they're
30
00:03:05,620 --> 00:03:09,980
‫talking about you no that has no subsequent children underneath them.
31
00:03:10,000 --> 00:03:14,560
‫So that complete to the left hand side of our tree.
32
00:03:14,770 --> 00:03:17,050
‫And now we're going to go on the right hand side.
33
00:03:17,080 --> 00:03:30,990
‫So 20 root than 20 has two children what once every 16 and the one on the right is going to be a 22.
34
00:03:33,270 --> 00:03:39,010
‫And then 22 has two children notes as well.
35
00:03:39,120 --> 00:03:48,330
‫And on 22 it's going to be 21 and the last one is 25 thinker.
36
00:03:48,480 --> 00:03:58,250
‫Now the leaf nodes on this are 16 21 and 25.
37
00:03:58,420 --> 00:04:03,700
‫And we have a complete binary search tree structure set up now looking.
38
00:04:03,700 --> 00:04:05,470
‫Talking about the properties.
39
00:04:05,620 --> 00:04:13,570
‫It's a very important thing as I was writing it out you probably saw with the sequences and the way
40
00:04:13,810 --> 00:04:17,980
‫that's to be set up this root node right here in the middle
41
00:04:20,940 --> 00:04:25,480
‫anything to the left of the node has to be less than the root node.
42
00:04:25,770 --> 00:04:29,530
‫So everything over here.
43
00:04:32,460 --> 00:04:39,490
‫Everything on the left hand side is going to be less than the root.
44
00:04:40,050 --> 00:04:42,320
‫Everything on the right hand side
45
00:04:46,750 --> 00:04:50,750
‫is going to be greater than the root.
46
00:04:50,830 --> 00:05:02,410
‫Now if you notice because this is some recursive functionality not only is this the case for the root
47
00:05:02,900 --> 00:05:06,560
‫is also the case for each of its subsequent children.
48
00:05:06,610 --> 00:05:10,680
‫So let's do something what we call traversing the tree.
49
00:05:10,870 --> 00:05:21,400
‫So we start off with 15 and then we go down to 12 from 12 you see 12 as two children twelves children
50
00:05:21,600 --> 00:05:29,200
‫a child on the right is 14 on the left it's 10 the right node is greater than 12 the left node is less
51
00:05:29,200 --> 00:05:35,930
‫then go down further down the training of 10 which is less than 11.
52
00:05:36,120 --> 00:05:42,660
‫The the child on the right hand side and then one which is less than the parent of ten.
53
00:05:42,760 --> 00:05:50,470
‫And if you go into the right hand side you have the exact same structure and set up the really nice
54
00:05:50,470 --> 00:06:00,700
‫thing about using a binary search tree is not only is it great to search and or the subject of our next
55
00:06:00,700 --> 00:06:05,490
‫episode it's going to be on how to actually iterate through the tree to find the number.
56
00:06:05,560 --> 00:06:14,620
‫The really nice thing is to find min and max value and if you think about it you think about it's very
57
00:06:14,620 --> 00:06:17,050
‫easy it's also very fast and efficient.
58
00:06:17,080 --> 00:06:19,170
‫From a performance standpoint.
59
00:06:19,330 --> 00:06:23,400
‫So how do you find the minimum value of a tree.
60
00:06:23,710 --> 00:06:32,560
‫All you have to do is start at the root and traverse all the way down the left side and you know the
61
00:06:32,560 --> 00:06:40,660
‫left route the left node the no furthest to the left in the tree is always going to be the lowest value
62
00:06:40,960 --> 00:06:41,780
‫in the tree.
63
00:06:41,980 --> 00:06:52,210
‫And in the exact opposite context if you take the 15 the route and extend all the way to the right to
64
00:06:52,210 --> 00:06:54,530
‫find the max all you have to do is do that.
65
00:06:54,550 --> 00:07:00,580
‫You just go through the tree traversing the tree go all the way find the element all the way to the
66
00:07:00,580 --> 00:07:02,830
‫right and you found your next county.
67
00:07:02,970 --> 00:07:04,800
‫So great job.
68
00:07:04,810 --> 00:07:08,120
‫If this is your first time learning binary search trees.
69
00:07:08,380 --> 00:07:12,790
‫If they look a little bit tricky at first do not let that stop you from learning them.
70
00:07:12,790 --> 00:07:16,090
‫They are extremely useful in computer science.
71
00:07:16,090 --> 00:07:22,760
‫They're a great way to visualize data and they are have a great performance value as we're going to
72
00:07:22,790 --> 00:07:28,700
‫get in the next episode when it comes to search and using heaps and different things like that.
73
00:07:28,840 --> 00:07:35,920
‫And I think the more you get used to the easier they'll be you'll become very familiar and you'll be
74
00:07:35,920 --> 00:07:39,760
‫able to use it in a lot of practical ways as you develop applications.
75
00:07:39,770 --> 00:07:42,080
‫So thank you for your time.
76
00:07:42,100 --> 00:07:44,890
‫And I look forward to seeing the next episode.
8239
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.