- 1 day ago
Transcript
00:00Now we have taken the last example in our try data structure. This was my try in which I made
00:06an empty node. There was the th e prefix which is in my 4 strings. The, there, there and the.
00:13The th e here is only one thing but after continuation there is a different string. Here is my second
00:18string and here is my third string and this is my
00:22Now the single node has a single node. If I compare it to binary tree node, what do we write
00:29in binary tree? We write class node in which every time my data comes and with it comes to my
00:37node left and node right.
00:42This is my left child and this is my right child. But because in try in every node, there are
00:47many children in each node. So try in the node is a way that I can define my children, which
00:54is called nodes.
00:56If I have a fixed count, I will have one child, two, three, four. So what do I do? I
01:02make an array. And what do I do in my array? I make 26 size. 26 means how do I
01:09store my trice? I store character type data from small a to small z to small z. So how many
01:16letters from a to small z to small z? 26 letters. I want to make this trice a to small
01:22z type. Or if I have all characters.
01:26So I have to keep the size of 256, so all the characters will come in Java. But in the
01:31most of the general cases, there are 26 sizes usually, which are small characters or lower case characters, they usually
01:40store them. So from here, I get to understand that every node of trice is a single letter of information.
01:48this node will be T and this node will be H. How will this information become? It will be like
01:54my root will be one array and the size of this array will be 26. The array will be many
02:03indexes and how many indexes will be 26.
02:07I will enlarge it a little more and I will show my array something like this, I will take my
02:130th index, this 1st index, this 2nd index, this 3rd index, this 4th index, and this way I will have
02:2026 index to represent numbers A to Z
02:32Now if my root node exists a child node in which I want to store A data in which I
02:39want to store A data in which I want to store A data in which I want to store A
02:42data in which I want to store A data in which I want to store A data in which I
02:43want to store A data in which I want to store A data in which I want to store A
02:43data in which I want to store A data in which I want to store A data in which I
02:44want to store A data in which I want to store A data in which I want to store A
02:46data in which I want to store A data in which I want
02:53189. So here I will store my node A. This node's data directly here to store this node. It means
03:02that automatically, if this is zero-hit index, zero-hit index means A. So I will use my node in
03:08a character.
03:09There is no need to write a character. What did I do? I made my array, 26 letters. If I
03:17store a node in the 0th index, then by default I have to find a store. If I store a
03:23node in the index 3, then by default I have to find a node in the 0th index.
03:28My letter D is stored in this way. If I have done T, then there will be a particular index
03:34which will be stored on this node. So I don't have to store any variable with my characters. The index
03:41of their value is stored in the parent's child's area. I will get to know which character is stored. Besides,
03:49we store another special thing with each node. It is the fact that this node is my end of word.
03:55What is this particular node?
04:10I have two information. Now let's talk about this. I have two information.
04:25One information has a particular area which is equal to size 26.
04:33memory tries because every node has a 26 size array which is a large size array now if I store
04:41left and right in binary tree then I store a little memory here I store a lot of nodes array
04:47so that's why memory is more memory the other information that I have my root is end of word because
04:53I have no word on my root so this will be false now if I talk about t here then
05:00t will also have an array
05:0326 size and it will also be end of word. It will also be false because no string is just
05:10t.
05:12From T to T, the value of TH is coming to H, so here it will be an array, with
05:18the end of word, which will also be false. From H, I will go to E. The size of E
05:26will be 26, which will be my notes, children's array. And here, the value of the end of word will
05:32be true. The value of the first time is true, because T
05:37h e here my word is over here. When I store there, then I will go to t h e
05:44r e. But because my word is t h e to store, that's why I have to store this node
05:50in the end of word. If I talk about there, then I have to store the last node in the
05:58end of word. If I store this node in the end of word, then I have to store the last
05:58node in the end of word. If I store this node in the end of word,
06:06So all these words, I have to store the last letter to end of the word. To represent that there
06:13is a word that has been finished. What will we do? We are going to create a class node in
06:21our code, which will show how our trees will show. This is my public class classroom, which I have made
06:26a main function, and I have stored many words in an area. What will I do? I will create a
06:31node class.
06:34class node. Node in the first thing which we store is my children's data. So, children's data to show the
06:42data, I will use a node array, children. And I can give it to this size, new node of 26.
06:52Besides, I will store a boolean type value, which is my end of word. So, I will store a boolean.
06:59I will give it to E or W, and I will give it to false.
07:04Now I can create a constructor here. In the constructor, there will be any value or data that will come
07:10to me externally. I don't need to track the data here because I can track the data through the index.
07:17I will store the value in the children's index. I will automatically know that I will talk about which character
07:24in my try node.
07:27So here in the beginning, what is the work in the constructor? What do I do with boolean? I will
07:31initialize in the children array. For int i equals 0, i less than 26, i plus plus, I will initialize
07:49in the children array. And what do I do with the public static node? I will name root.
07:55This is the root of my try, which we initialize in the beginning. In fact, I can write here as
08:00a new node. This node is always empty by default. The root of try is empty, there is no valid
08:06data store. There is only our children's information store so that we can store our words from the next level.