Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
-
Upload
francis-hutchinson -
Category
Documents
-
view
214 -
download
1
Transcript of Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
![Page 1: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/1.jpg)
Data Structure
Lecture 3Abstract Data Type
Sandy Ardianto & Erick Pranata© Sekolah Tinggi Teknik Surabaya
1
![Page 2: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/2.jpg)
Motives» Problem Solving is different from coding˃ Algorithm˃ Documentation˃ Code
» Algorithm and Documentation is Abstract Layer
» Code is Implementation Layer
2
© Sekolah Tinggi Teknik Surabaya
![Page 3: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/3.jpg)
Motives» Abstraction is important to˃ Improve Readablity˃ Organize Data through Encapsulation
» Abstract Data Type (ADT)˃ an object with a generic description
independent of implementation details˃ we think about what can be done with the
data, not how it is done
3
© Sekolah Tinggi Teknik Surabaya
![Page 4: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/4.jpg)
ADT is A Set of Operation» ADT abstracts away from a specific representation to
focus on the semantic meaning of the data » In what sense are the following two definitions
different?
» Although the representations differ, the client should instead consider a Point as a set of operations to create and manipulate 2D points on the plane
» By restricting the client to only call operations to access data, the potential for modifying the representation (and supporting algorithms) remains
4
© Sekolah Tinggi Teknik Surabaya
![Page 5: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/5.jpg)
ADT = Objects + Operations» The only operations on objects of the
type are those provided by the abstraction
» The implementation is hidden
5
© Sekolah Tinggi Teknik Surabaya
![Page 6: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/6.jpg)
ADT Example
6
© Sekolah Tinggi Teknik Surabaya
![Page 7: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/7.jpg)
Implementation of ADT» An implementation of ADT consists of
storage structures to store the data items and algorithms for basic operation
7
© Sekolah Tinggi Teknik Surabaya
![Page 8: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/8.jpg)
Another Example» Consider example of an airplane flight with 10
seats to be assigned» Tasks
˃ List available seats˃ Reserve a seat
» How to store, access data?
![Page 9: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/9.jpg)
Another Example» Consider example of an airplane flight with 10
seats to be assigned» Tasks
˃ List available seats˃ Reserve a seat
» How to store, access data?˃ 10 individual variables
![Page 10: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/10.jpg)
Use 10 individual variables
» Algorithm to List available seats
1. If seat1 == ‘ ’:display 1
2. If seat2 == ‘ ’: display 2
.
.
.10. If seat10 == ‘ ’:
display 10
» Algorithm to Reserve a seat
1. Set DONE to false2. If seat1 ==‘ ’:
print “do you want seat #1??”Get answerif answer==‘Y’:
set seat1 to ‘X’set Done to True
3. If seat2 ==‘ ’:print “do you want seat #2??”Get answerif answer==‘Y’:
set seat2 to ‘X’set Done to True
.
.
.
![Page 11: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/11.jpg)
Another Example» Consider example of an airplane flight with 10
seats to be assigned» Tasks
˃ List available seats˃ Reserve a seat
» How to store, access data?˃ 10 individual variables˃ An array of variables
![Page 12: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/12.jpg)
Use Array» Algorithm to List available seats
For number ranging from 0 to max_seats-1, do:If seat[number] == ‘ ’:
Display number
» Algorithm to Reserve a seat
Read in number of seat to be reservedIf seat[number] is equal to ‘ ’:
set seat[number] to ‘X’Else
Display a message that the seat having this number is occupied
![Page 13: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/13.jpg)
Exercise» Develop a USD ADT˃ Properties
+ dollar: int+ cent: int
˃Methods+ Add+ Subtract+ Multiply+ Divide+ ToString
13
© Sekolah Tinggi Teknik Surabaya
![Page 14: Lecture 3 Abstract Data Type Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022070411/56649f585503460f94c7dfdc/html5/thumbnails/14.jpg)
Reference» Abstract Data Type, http://
c2.com/cgi/wiki?AbstractDataType, accessed on March 24th 2014.
» Abstract Data Types, http://cse.iitkgp.ac.in/pds/notes/ADT.html, accessed on March 24th 2014.
» Dr. Bernard Chen Ph.D., Data Structures and Abstract Data Type, 2008
14
© Sekolah Tinggi Teknik Surabaya