 All right guys, so now we're gonna go over something called sets. We're gonna go over sets All right I already went over this in another video But I'm gonna go over sets and then after that I'm gonna go over stacks and queues and then I'm going to go over graphs And then after that I'll start another series on algorithms. I'll start like sorting series and stuff like that Okay, so what is a set basically in math? Sets are pretty much the same thing as there are math. There's pretty much no duplicates. All right, no duplicates That's a good thing about sets. There is no duplicates one thing that about in mathematics Sets are unchanging right, but in computer science sets are Manipulated by algorithms to grow or shrink over time. So we call these dynamic Dynamic so that means they could grow or Shrink over time Okay, and it depends on whatever type of algorithm allows us to do things So typically the algorithms that we use for sets are three things. Okay, so there's a There's three simplest simplest things you need to know in order to actually call these things One is the ability to insert an element inserting an element the second one is is it the ability to Delete an element delete an element and The final thing is to test if it's a Membership So what do I mean by membership? It just means Test does there exist something? So does there exist a value in the set? Okay, so the dynamic elements that Support these operations. So all these operations if a set supports all these we call these dictionaries Okay, we call these dictionaries. So if a set supports Supports all these operations. We call them dictionaries. All right Dynamics set by the way. Yeah Other why other other algorithms have more complicated things which we'll introduce later on. Okay All right. So typically there's Dynamic sets have elements represented by objects, which could be manipulated with pointers and stuff like that and also To identify a certain object in a set. So let's say I have this giant set of I don't know Set of people let's say like all this people and have a bunch of people Right. Well in order to identify each person in here. I'll just have to have them. I label them as keys keys Okay So because of this all keys are unique in order to label these so these are all keys. I'll call them like key one Key, okay one key one key two key three key four key five So on and so forth, right? These are just like keys that tell you that There's names of whichever objects or elements in the set and they are unique Right. They are unique So the key for each object to identify the objects are different. Okay, um So object can also contain satellite data, which are carried in other object attributes But are unused by the set implementation. So Yeah, so each object can have like Data about other objects, but they are totally unrelated to each other. So that's what we call them satellite data. All right, um So yeah, that's pretty much sets some dynamic sets are Ordered are drawn totally where the keys are totally ordered. So some of the times they order them by like alphabetical order alphabetical order So order the keys the keys are ordered alphabetically Sometimes they're not Maybe if there's numbers it's like Sorted order sorted order if it's numbers it really depends on what set it is It's not like a specific set has to have certain these like types of attributes like this Okay. Now, let's go over the Oh, yeah, yeah, so ordering allows us to define the minimum element of a set or the maximum element of a set So like ordering allows us to allows us to define minimum element or max Right, if I have a certain ordering of the keys I could tell if it's a minimum element or a maximum element. Okay, so like this is like This is just that's just how it works. Now. Let's talk about the operations on a set so Let's talk about operations on a set So what are the type of operations you could do? Well, you have to These are called like there's two types Categories which is a one is querying which is just returning an information about an element querying So there's two type of operations querying which is like giving you information about an element about The set well the set actually in CLRS. They call it. It's the set So giving information about the set. Hope you guys can see this. Wow. That's a really bad handwriting in formation About the set the other one that you do is modifying operations So what does that mean? This just changes the element in the set. Okay, so those are the types of Toes those are the types of Operations you could do on a set. There's two types of categories. Okay, um So yeah, here so here's how some some things that should be implemented and sets if you're gonna implement things Searching searching for an element. Does it contain something? So like if you have like this set s and then your key k So this is like the set and this is like the key This returns it if there is an L if if there is an element of this key in a set so it returns an element if has the key In the set That that has the key in the set. Otherwise it gives a null Another one's inserting which is just inserting an element Into the set. I'm not gonna not gonna write that It basically just inserts the element to the set. You also delete an element deleting So it deletes an element in the set Minimum would get you if it's a ordered Set it would get you the minimum element maximum would get you the maximum element and Yeah Now there's these two interesting ones. These are there's two interesting ones. Let's call these a successor and predecessor So what does the successor do? So you're given an element in the set, right? Whose key is from a totally From a totally ordered set s it returns to the pointer of the next larger element in the set right so Let's say If this is ordered so it just returns the next larger element So like let's say if I had like a set of one two three four Elements and then let's say I want to and I give it the element three The next larger element would give me four because it's the next larger element, right? This is assuming it's ordered And we also have a predecessor predecessor and What does this do? This just returns you the the To the next smaller element Okay returns next smaller element So let's say if I have like one two three four and I give you three it would return me two, right? So if I had like predecessor this Three it would give me two. Okay. Um, so if the In successor if it's the maximum element over return all by the way I forgot to add that if if if x is a maximum element return all and then If it's a not for predecessor if it's a minimum if x is minimum It would return the Return all okay, so that's that's a thing for predecessor and Successor and that's a thing for these operations of a set So some in some situations we could extend the successor and predecessor to apply to non-distinctive keys, so there might be I don't know It depends on what type of set but in some languages you might have keys that are non-distinctive keys So like you might actually there might be multiple multiple sets, right? Where the the values are not where they allow duplicates, right? There there might be I don't know that there are some sets like that, but yeah but generally a set doesn't allow duplicates the keys are all unique and yeah so Depending on which type of structure you could do things like this So for dictionary objects Operations of searching insertion deletion They now know they normally do something called hashing which like hashes the specific key to a specific value So you has a good space and you can look things up quicker. I'll go over that later in the next like next videos, but yeah Sometimes I use binary search trees to implement sets Typically that would take log of n time in order to do things but that I'll go We already went over a binary search tree. Yeah, right, right. So yeah um you some people some implementations Just use it or a so you could use an array to implement a set typically just like create these functions like this and just make sure that the Your you can insert your delete. You couldn't have a max and minimum get the predecessor successor stuff like that Yeah Sometimes you could also There's also other types of data structures that support these but yeah That's all you have to know about sets pretty much Well, can you guys see this? Yeah, sorry That's all you have to know about sets. We'll go over like what maps are so Maps maps are pretty easy Pretty much maps are just like mapping a specific value to another specific value. So it's just like maps one value to another Right um pretty so it's just like a So like let's say I have like a group of students IDs and then I have their names I can map the specific ID to a specific name, right? That's what maps are maps like one value to another. Let's say I have like um, I Don't know. Let's say you have like a bunch of colors people's colors And then the types of shirt that they wear right you can map specific color with the type of shirt that they wear Stuff like that depending on the languages Maps can also occur where it's like the Some of them some of them don't allow duplicates where you get like a specific key and a value and The keys have to be distinct right some some languages They override the key if you add in add a new map has the same value as one another. So yeah Generally you map a specific key with a specific value So yeah, you map one value to another you don't normally map a specific key with a value So if like I'm gonna map The people's names with the type of shirt they wear I would map like their names as a key and then the type of shirt that they wear as their value, right? But yeah keys down generally are are unique. So generally the keys that you map are No duplicates right and there's unique it's You can't just have like the same same person with the same Say a two-peat different people with the same type of value right generally because it would like override it But yeah, that's that's pretty much what maps are also. I'll go over the all these Types in C C++. So I'll create another video series on all these data structures and their specific Outcome in C++ and how do you use them in STL? I'll go over that and yeah That's pretty much it. I'll also go over that in other videos as well But yeah, this is just a video on brief intro on sets and maps Hope you guys enjoy this video great cobs subscribe. I'll check you guys later. Peace