11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 1.2 Abstract <strong>D<strong>at</strong>a</strong> Types <strong>and</strong> <strong>D<strong>at</strong>a</strong> <strong>Structures</strong> 9ple, Section 12.2 describes the d<strong>at</strong>a structure used to implement a sparse m<strong>at</strong>rix, alarge two-dimensional array th<strong>at</strong> stores only a rel<strong>at</strong>ively few non-zero values. Thisimplement<strong>at</strong>ion is quite different from the physical represent<strong>at</strong>ion of an array ascontiguous memory loc<strong>at</strong>ions.An abstract d<strong>at</strong>a type (ADT) is the realiz<strong>at</strong>ion of a d<strong>at</strong>a type as a softwarecomponent. The interface of the ADT is defined in terms of a type <strong>and</strong> a set ofoper<strong>at</strong>ions on th<strong>at</strong> type. The behavior of each oper<strong>at</strong>ion is determined by its inputs<strong>and</strong> outputs. An ADT does not specify how the d<strong>at</strong>a type is implemented. Theseimplement<strong>at</strong>ion details are hidden from the user of the ADT <strong>and</strong> protected fromoutside access, a concept referred to as encapsul<strong>at</strong>ion.A d<strong>at</strong>a structure is the implement<strong>at</strong>ion for an ADT. In an object-oriented languagesuch as Java, an ADT <strong>and</strong> its implement<strong>at</strong>ion together make up a class.Each oper<strong>at</strong>ion associ<strong>at</strong>ed with the ADT is implemented by a member function ormethod. The variables th<strong>at</strong> define the space required by a d<strong>at</strong>a item are referredto as d<strong>at</strong>a members. An object is an instance of a class, th<strong>at</strong> is, something th<strong>at</strong> iscre<strong>at</strong>ed <strong>and</strong> takes up storage during the execution of a computer program.The term “d<strong>at</strong>a structure” often refers to d<strong>at</strong>a stored in a computer’s main memory.The rel<strong>at</strong>ed term file structure often refers to the organiz<strong>at</strong>ion of d<strong>at</strong>a onperipheral storage, such as a disk drive or CD.Example 1.3 The m<strong>at</strong>hem<strong>at</strong>ical concept of an integer, along with oper<strong>at</strong>ionsth<strong>at</strong> manipul<strong>at</strong>e integers, form a d<strong>at</strong>a type. The Java int variable typeis a physical represent<strong>at</strong>ion of the abstract integer. The int variable type,along with the oper<strong>at</strong>ions th<strong>at</strong> act on an int variable, form an ADT. Unfortun<strong>at</strong>ely,the int implement<strong>at</strong>ion is not completely true to the abstractinteger, as there are limit<strong>at</strong>ions on the range of values an int variable canstore. If these limit<strong>at</strong>ions prove unacceptable, then some other represent<strong>at</strong>ionfor the ADT “integer” must be devised, <strong>and</strong> a new implement<strong>at</strong>ionmust be used for the associ<strong>at</strong>ed oper<strong>at</strong>ions.Example 1.4 An ADT for a list of integers might specify the followingoper<strong>at</strong>ions:• Insert a new integer <strong>at</strong> a particular position in the list.• Return true if the list is empty.• Reinitialize the list.• Return the number of integers currently in the list.• Delete the integer <strong>at</strong> a particular position in the list.From this description, the input <strong>and</strong> output of each oper<strong>at</strong>ion should beclear, but the implement<strong>at</strong>ion for lists has not been specified.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!