{"id":203,"date":"2024-07-30T06:50:40","date_gmt":"2024-07-30T06:50:40","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/abstract-data-types\/"},"modified":"2026-03-16T14:30:55","modified_gmt":"2026-03-16T14:30:55","slug":"abstract-data-types","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/abstract-data-types\/","title":{"raw":"Abstract Data Types","rendered":"Abstract Data Types"},"content":{"raw":"<div class=\"abstract-data-types\">\n<p class=\"import-Normal\">An [pb_glossary id=\"249\"]<strong>Abstract Data Type (ADT)<\/strong> [\/pb_glossary]involves two components: (1) the data that are being stored and manipulated and (2) the methods and operations that can be performed on that data. For example, an <em>int <\/em>is an ADT. The data are the integers ranging from some MIN_INT to some MAX_INT. The operations are the various integer operations: addition, subtraction, multiplication, and division. These operations prescribe the ways that ints can be used. There are no other ways to manipulate integers.<\/p>\n<p class=\"import-Normal\">Moreover, in designing an ADT, it\u2019s important to hide the implementation of the operations from the users of the operations. Thus, our programs have used all of these integer operations on ints, but we have no real idea how they are implemented\u2014that is, what exact algorithm they use.<\/p>\n<p class=\"import-Normal\">Objects can be designed as ADTs, because we can easily distinguish an object\u2019s use from its implementation. Thus, the private parts of an object\u2014its instance variables and private methods\u2014are hidden from the user while the object\u2019s interface\u2014its public methods\u2014are available. As with the integer operators, the object\u2019s public methods prescribe just how the object can be used.<\/p>\n\n<h3>Abstract Containers<\/h3>\n<p class=\"import-Normal\">Abstraction provides a useful way to conceptualize and design data structures. Consider a list. What kinds of lists can you think of? You might think of grocery lists, todo lists, quest lists, best sellers lists, and perhaps the ArrayList.\u00a0 What operations do these lists have in common? The basic functionality you expect from a list would be to add to the list, remove from the list, and search the list.<\/p>\n\u00a0\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n\nWhat methods would the public interface of this abstract list include?\n\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Note that at this point, you don't need to know any of the private details. How will the list be stored? Where will the elements be stored? How will the list be searched? Note that there are several different algorithms that could be used to answer each of these questions. However, this is the point of abstraction! The implementation details are left to the developer (which will be you, later!). But the [pb_glossary id=\"244\"]<strong>interface<\/strong> [\/pb_glossary]can be specified with a generalized idea of the behavior you expect from the data structure.<\/p>\n<p class=\"import-Normal\">The following sections will look at several concrete examples of how these interfaces can be used.<\/p>\n\n<\/div>","rendered":"<div class=\"abstract-data-types\">\n<p class=\"import-Normal\">An <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_203_249\"><strong>Abstract Data Type (ADT)<\/strong> <\/a>involves two components: (1) the data that are being stored and manipulated and (2) the methods and operations that can be performed on that data. For example, an <em>int <\/em>is an ADT. The data are the integers ranging from some MIN_INT to some MAX_INT. The operations are the various integer operations: addition, subtraction, multiplication, and division. These operations prescribe the ways that ints can be used. There are no other ways to manipulate integers.<\/p>\n<p class=\"import-Normal\">Moreover, in designing an ADT, it\u2019s important to hide the implementation of the operations from the users of the operations. Thus, our programs have used all of these integer operations on ints, but we have no real idea how they are implemented\u2014that is, what exact algorithm they use.<\/p>\n<p class=\"import-Normal\">Objects can be designed as ADTs, because we can easily distinguish an object\u2019s use from its implementation. Thus, the private parts of an object\u2014its instance variables and private methods\u2014are hidden from the user while the object\u2019s interface\u2014its public methods\u2014are available. As with the integer operators, the object\u2019s public methods prescribe just how the object can be used.<\/p>\n<h3>Abstract Containers<\/h3>\n<p class=\"import-Normal\">Abstraction provides a useful way to conceptualize and design data structures. Consider a list. What kinds of lists can you think of? You might think of grocery lists, todo lists, quest lists, best sellers lists, and perhaps the ArrayList.\u00a0 What operations do these lists have in common? The basic functionality you expect from a list would be to add to the list, remove from the list, and search the list.<\/p>\n<p>\u00a0<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p>What methods would the public interface of this abstract list include?<\/p>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Note that at this point, you don&#8217;t need to know any of the private details. How will the list be stored? Where will the elements be stored? How will the list be searched? Note that there are several different algorithms that could be used to answer each of these questions. However, this is the point of abstraction! The implementation details are left to the developer (which will be you, later!). But the <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_203_244\"><strong>interface<\/strong> <\/a>can be specified with a generalized idea of the behavior you expect from the data structure.<\/p>\n<p class=\"import-Normal\">The following sections will look at several concrete examples of how these interfaces can be used.<\/p>\n<\/div>\n<div class=\"glossary\"><span class=\"screen-reader-text\" id=\"definition\">definition<\/span><template id=\"term_203_249\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_203_249\"><div tabindex=\"-1\"><p>Abbreviated ADT. The specification of a data type within some language, independent of an implementation. The interface for the ADT is defined in terms of a type and a set of operations on that type. The behavior of each operation is determined by its inputs and outputs. An ADT does not specify how the data type is implemented. These implementation details are hidden from the user of the ADT and protected from outside access, a concept referred to as encapsulation.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_203_244\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_203_244\"><div tabindex=\"-1\"><p>An interface is a class-like structure that only contains method signatures and fields. An interface does not contain an implementation of the methods or any data members.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><\/div>","protected":false},"author":1,"menu_order":4,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-203","chapter","type-chapter","status-publish","hentry"],"part":195,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":2,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/203\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/203\/revisions\/259"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/parts\/195"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/203\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapter-type?post=203"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/contributor?post=203"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/license?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}