00:00Now, first of all, let's talk about try data structure. Try data structure is a carey tree. Carey tree means
00:08what does it mean? If I had some example of this before, then we talked about binary trees. Binary tree
00:17means BIN is number 2.
00:19So binary trees are those trees that have two children in each node. So if I take a tree in
00:26which I have two children at max, then I can call it a carey tree. So my try data structure
00:32will show how many children in each node.
00:36That's why trys space-wise, because they store a lot of information. In every node, here in binary trees, there
00:46was a left pointer, a right pointer, which was left and right sub-tree. But in trys, we have many
00:56pointers, multiple pointers.
00:59And we know that the pointer type has a node, so there was so much extra data to create a
01:06node every time. So when we create trys, we have to store a lot of nodes, so that's why we
01:12occupy space. But wherever we use trys, for which we solve special questions, trys gives us a very good time
01:20complexity. How do we give time complexity? Let's take an example, I have taken a balance tree.
01:28Balanced tree or Balanced BST, we talked about Balanced BST in detail. If I have a Balanced BST example, BST
01:37can see how many levels are, which are login levels. If I have a Balanced BST example,
01:48which is an unbalanced tree within the height which is an unbalanced tree. So it will go from this way,
01:53in which I have total height which is equal to n. Now if I perform the balance BST within the
01:58insertion or search queries, then I have login time. If I perform the same thing in unbalanced BST, then I
02:07have big of n time. I have recognized this thing here that when my tree is balanced, it means its
02:12height is less than less. So in that time, I will insert
02:20as compared to when my tree is unbalanced or its height is more. So in trice, we try to store
02:27a lot of data from the same node in the child. This data, or I can bring these three nodes
02:35to the same level, but in trice, because many nodes come to the same level, our time complexity is reduced.
02:44The height is less than trice,
02:46time complexity is reduced in most of the cases. As compared to there, if we use a normal tree or
02:52binary tree. That's why we use tries because in many problems it gives us an optimized solution. Especially those problems
03:01where we have to search a word, or prefixes, or suffixes, which are the queries on the strings.
03:10Tries are very useful for us. Let's see how a sample try actually creates. Let's say that I have a
03:18lot of strings.
03:20I have given all these strings and I want to create my try. So, how do I show a try?
03:26First, I will create a node within the try which is empty node. My root is empty node within the
03:33try. Then, I will use my first word. If I want to store the the, then I will store level
03:41-wise and letter-wise. First, I have store T here. Then, I will store H and E.
03:49If I have a string, it will be the first letter. Then it will be the second letter. And in
03:54the last letter, it will be the third letter. Now I will come to my next string. Here is A,
03:59so I will store A in some way. Then next string. Here is T, so T is already stored. Then
04:06H is already stored. Then H is already stored. E is already stored. Here is R, which is already stored.
04:12So what do I do here?
04:14I will add another R and add another E. Now, let's talk about there. So, T already stored here. H
04:20stored here. E stored here. I don't have that. So, I will create a new child here. I will store
04:27R. Now, let's talk about Annie. So, Annie has a stored here.
04:31Then I will store it in some way and then I will store it in some way and then I
04:35will store it in some way and then I will store it in some way and then I will store
04:38it in some way and then I will store it in some way and then I will store it in
04:42some way and then I will store it in some way and then I will store it in some way
04:50and then I will store it in some way
04:58There was the there and there was the there and the there was the there and the there was the
05:02there and the there was the there and the there was the there there was the there there was the
05:03there there and there was the there there was the there there there was the there there there there there
05:05there there there there there there there there there there there there there there there there there there there there
05:05there there there there there there there there there there there there there there there there there there there there
05:05there there there there there there there there there there there there there there there there there there there there
05:05there there there there there there there there there there there there there there there there there there there there
05:05there there there there there there there there there there there there there there there there there there there there
05:06there there there there there there there there there there there there there there there there there there there there
05:08there there there there there there there there there there there there there there there there there there there there
05:09there there there there there there there there there there there there there there there there there there there there
05:09there there there there
05:27How do we solve this?