Transcript for:
Understanding Abstract Data Types (ADT)

yo what's going on guys Thun Meyer for simple snippets and welcome back to another video tutorial under data structures and algorithms and in this video tutorial we're going to be understanding what is an abstract data type in data structures so when you're studying data structures you'll come across this term abstract data types quite often and it's a theoretical concept so we will quickly understand this and the best way to understand this is by taking examples so in this video tutorial we'll understand what exactly is an abstract or logical view and the implementation view of a data structure so that is the two ways in which we can study or view at data structures and we'll understand this by taking an example so with that being said let's get started so what exactly is a abstract data type now we have the definition of data structures which we've already seen in the previous video but I just mentioned it so that you can reiterate it so in computer science of data structure is a way of data organization management and storage that enables efficient access and modification so this is something that we've cleared out in the previous video of this data structures playlist but the way we look at data structures can be categorized into two parts you know or two different types the one is where we actually have a logical or abstract or mathematical view or model wherein we just specify what all things the data structure is going to have now we know that data structure is a way of storing data right so when I'm seeing way it means that there are some protocols there are some rules that are gonna be followed right so all those protocols all those rules can be modeled as a proper view or a model and you can basically just write down all the specifications right so that comes under the logical or abstract or mathematical model or view on the second way or the second part you can say is the implementation part wherein you use all those rules and regulations and actually implement that using some programming language right so Indian obviously we are going to be implementing these data structures in practicals by using some programming language in our case we are going to be using C++ programming right so all these programming syntaxes will be based on this mathematical and logical or abstract model so now that you have a overview of the ways in which you can look at data structures let's try to define what the abstract data type is and let's take those samples into consideration okay so when you are talking about abstract data types ADT is that is the short form are entities there are definitions of data and operations but do not have implementation details so basically the abstract data type is the logical or mathematical or abstract view that we were talking about right so here we have the entities that are definitions of data and operations but do not have implementation which means that we know what we are going to be storing and we also know the operations that can be performed and the way in which the data is going to be stored depending upon what data structure we are going through but we haven't yet implemented it in any practical sense now the reason why we do not have any implementation in edit is because every different programming language has different implementations for example a particular data structure in C can be implemented using the concept of structures but that same data structure can be implemented by using the concept of objects and classes in Java programming and so on and so forth you know so different programming languages have different implementation strategies to tackle different abstract data types so basically data structures are these abstract data types which has specifications about how the data is going to be stored and what are the operations that can be performed on these data types and these different entities but the implementation depends upon the programming language that we use okay so to get this thing more cleared out let's actually take a real-world example so here's a real world example of a smart phone okay so if we were to look at this smart phone in an abstract or logical view what we are going to be doing is we're just going to be defining what all things does a smart phone have at a high level okay for example this smart phone will have 4 GB RAM this smart phone is having a Snapdragon 2.2 gigahertz processor so every smartphone has a ram as processor has a 5.5 inch LCD screen now the screen size obviously varies depending upon what smartphone we're using but this particular smartphone has dual cameras it has Android operating system which is 8.0 version and whatnot you know and along with all these properties this smartphone also has some functionality also has some operations and behaviors right so this is what that operation stands for and this is the data rate so information can be termed as a data of that particular entity we are looking at smartphone so this is all the information and data about that smartphone and the operations are you can use your smart phone to call you can use it to perform text you can send text you can click photos you can click videos and so on and so forth so these come under the behavior and the operations rate so this is what an abstract or logical view of this smartphone looks like wherein you just hitting all the different properties and all the different operations and behaviors that that particular entity can do but when you look at the implementation view over your so when you are actually implementing this in terms of programming in terms of actual code this is how the pool would look like in a proper C++ programming language so you are creating a class so of course we have objects and classes in the C++ programming language if it was C then we could have used structures so in that we have these different variables created follow those respective properties right we have RAM size processor name we have screen size and their respective data types obviously in string float and then we also have some methods which correspond to these behaviors so we avoid call text and obviously the definition can be defined later on but right now I just want to state or show you how the implementation he would look like now if this was some other programming language let's say it was Java or Python obviously syntax is going to be changing some keywords and some mechanism is also going to be changing right which means that the implementation view can change however the abstract and logical view is independent of this implementation so this is what this hashtag datatype actually means now coming to our data structures word let's take an example in the data structures environment ok so let's take the basic integer array so we've seen an array data structure in the previous video also so let's continue with that only so that you'll understand it in a better way now here's an example which has an integer array of size 4 okay so we have the index position starting from 0 1 2 3 so array is a data structure wherein it is a collection of elements which has stored add contiguous memory locations so you can see in the orange we have memory addresses which are just one besides other so one thousand one thousand four one thousand eight and one thousand twelve so this is basically in bytes and each integer element in C++ takes up four bytes so that's why four bytes and then we have 1 0 0 4 and then one 0:08 and the addresses are allocated just right besides each other which means that it is contiguous in nature and not continuous okay we have index positions allocated and then the blue ones are the actual values so this first position is storing value 10 this 20 30 and 40 so this implementation so this is basically what an array is and all these index positions value memory address all these things are implemented in programming languages differently by different programming language right so the abstract or logical view of this integer array can be stated as this data structure or this array store a set of elements of integer datatype so in this case we are using integer array right so you can also say of a particular datatype if you want to go more generic then we need elements by position that is index so we have indexes to access different positions starting from 0 we can again modify elements by its index so if we access one particular index we can change the value at that index and we can also perform sorting and obviously there would be many more things that can be done using this array data structure right now I've just given an example of how I abstract or logical we would look like now coming to the implementation side this is how it will look like in C++ programming so the syntax would be int arr I am creating an array of size Phi in this case and not for I am having one two three four five as the actual element so I am also initializing the array I am saying C out ARR of one which means I want the value at position two okay so this is zero index position this is one index position if I am saying error of one so the output would be two over here now what I am doing is I am saying error of 2 equals to 10 so this is the third position or second index value the value is 3 over here but when I am saying error of 2 equals to 10 the new value will be 10 so I am modifying it by using the index rate so this is what is specified over here so this is basically the implementation view so when we are talking about abstract data types it is just entities which have a definition for how the data is going to be stored and what kind of data is going to be showed and what are the operations that are going to be operating on that particular data so this was an example of array rate so if you go ahead and check out other data structures as we move ahead we will obviously see them but just for example we can talk about stat szostak is a linear data structure which works on last in first out which means the last value being added into the stack will be popped out first or you can also say first in last out which means the first value that goes in will be the last one to come out so that would be written in this logical view and then obviously the implementation is something that we have to type in in form of code depending upon what kind of programming language you use so that's why implementation always keeps on changing a little bit here and there obviously the operation that is the actual behavior is always going to be the same just that since every programming language has its unique properties also the implementation slightly changes okay so this was a little bit detail about what is abstract data types you don't really have to stress out on this topic it is not really a big thing it is just as I mentioned small entities that are having definitions of data in operation but do not have implementation that's about it this is one line that should be enough and as you can see we've also talked about the example so abstract data types are nothing but the specification that we provide without the implementation okay so that's it for this video guys I hope you have got an idea about what are abstract data types you might come across this term quite often as you move I'd so thanks for watching guys if you like this video please share it with your friends do give it a like let me know comments of this video watch and I'll see you guys in the next video peace