0% found this document useful (0 votes)
7 views7 pages

Understanding Abstract Data Types (ADTs)

This worksheet covers Abstract Data Types (ADTs) and their applications, including definitions, advantages, and disadvantages. It includes exercises on conceptual questions, application scenarios, problem-solving, and coding examples related to ADTs like Stack, Queue, and Set. The document emphasizes the importance of abstraction and information hiding in software engineering, along with practical examples in various systems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Understanding Abstract Data Types (ADTs)

This worksheet covers Abstract Data Types (ADTs) and their applications, including definitions, advantages, and disadvantages. It includes exercises on conceptual questions, application scenarios, problem-solving, and coding examples related to ADTs like Stack, Queue, and Set. The document emphasizes the importance of abstraction and information hiding in software engineering, along with practical examples in various systems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Eviyen Kody S.

Consimino BSCPE 1-7

Worksheet – Abstract Data Types (ADTs)


This worksheet contains exercises to help you understand the concept of Abstract Data
Types (ADTs). Answer the questions in the spaces provided.

Part A: Conceptual Questions


 1. Define Abstract Data Type (ADT) in your own words. How does it differ from a data
structure?
An Abstract Data Type is like a blueprint that tells us what operations we
can do with some data but it doesn’t exactly say how those operations are carried out. On
the other hand, a data structure is the actual way we store and organize the data in the
computer’s memory. So ADT is the idea of what can be done and the data structure is the
doing of that idea.

 2. Why is abstraction important in software engineering? Give a real-world example.


Abstraction is important because it hides the hard details and lets us focus
only on what we need to use. For example here in the Philippines, when we use GCash to
pay bills or shop online, we just need to click a button to send money and we don't see or
worry about the complicated process happening inside the system.

 3. Explain how information hiding helps in maintaining large systems.


Information hiding is important in maintaining large systems because if
something changes inside, we don't have to change everything outside. For example again
here in the Philippines, when the government updates the system for paying taxes online
like the BIR e-services, the users still see the same buttons and forms. The changes in the
background don't affect how people use the system and this makes it easier to maintain and
improve without confusing the users.

 4. What are the advantages and disadvantages of using ADTs?


The advantage of using ADTs is that they make programs easier to
understand and use because we only think about what the data can do and not how it is
build. This also makes it easier to fix or improve the code later. The disadvantage is that
since the details are hidden, beginner users may find it harder to know how it really works
inside and sometimes it might be less flexible.
 5. Identify whether each of the following is a linear or non-linear structure:
- Stack
- Queue
- Graph
- Linked List
- Tree
Stack, Queue, and Linked List are linear structure while Graph and Tree are
non-linear structure.

Part B: Application Exercises


 6. Suppose you are tasked to design a Queue ADT for a hospital system. List at least
three operations that should be supported and explain their purpose.
If I were to design a Queue ADT for a hospital system, here are the three
operations that I think it should support. First, enqueue or add patient. This operation adds
a new patient at the end of the line just like when people line up in the hospital’s waiting
area. Second, dequeue or serve patient. This operation removes the patient at the front of
the line, meaning it’s their turn to see the doctor. Lastly is check the new patient, this
operation checks who is next in the line without removing them so hospital staff know who
will be served next.

 7. A Stack ADT can be implemented using either an array or a linked list. Discuss the
trade-offs between the two implementations.
Using an array makes it faster to access elements since they are stored in
continuous memory, but the size of the stack is fixed so if it becomes full, we cannot easily
add more unless we resize it. On the other hand, using a linked list allows the stack to grow
or shrink as needed without worrying about a fixed size but it uses extra memory for
storing pointers and is a bit slower to access compared to arrays. For example, small clinics
with limited computer memory might prefer arrays because they are simple and efficient
while bigger hospitals with larger systems might use linked lists for flexibility in handling
many patients' records.

 8. Consider a Set ADT with operations add, remove, union, and intersection. Give a real-
world application where a Set ADT would be useful.
A set ADT would be useful in a university enrollment system. For example,
one set can store students enrolled in Data Structure and Algorithms and another set can
store students enrolled in Basic Calculus. Using union, we can find all students taking either
subject while intersection can show the students taking both subjects. This helps schools
easily organize class lists and avoid duplicate records.

Part C: Problem-Solving
 9. Imagine you’re building a Library Management System. Which ADT would you use
for:
- Storing a list of borrowed books?
- Managing the waiting line for new arrivals?
- Representing relationships between authors and co-authors?
In storing a list of borrowed books, I would use list ADT because it can keep
track of all the books a person has borrowed in order. In managing the waiting line for new
arrivals, I would use queue ADT since people should get the book in the order they signed
up. In representing relationships between authors and co-authors, I would use graph ADT
because it can show the connections between different authors.

 10. Design an ADT for a Playlist in a music app. Specify the data (songs, artists, duration)
and at least four operations (e.g., add song, delete song, shuffle, play next).

Data:
 Song title - the name of the song
 Artist - the performer of the song
 Duration - how long the song plays

Operations:
1. Add song - add a new song with its title, artist, and duration.
2. Remove song - remove a song from the playlist.
3. Shuffle - randomize the order of songs in the playlist.
4. Play next - move to the next song in order.

Part D: Coding Exercises (Python examples)


 11. Implement a Stack ADT in Python using a list. Support the operations push, pop, and
peek.
 12. Write a function to simulate a Queue ADT using [Link]. Include enqueue
and dequeue operations.
 13. Implement a Set ADT in Python without using the built-in set. Support at least add,
remove, and contains.
Part E: Critical Thinking
 14. Explain why changing the data structure used in an ADT (e.g., from array-based to
linked list) should not affect the client program using the ADT.
Changing the data structure used in an ADT should not affect the client
program because the client only interacts with the operations like push, pop, enqueue, add
and not with how those operations are carried out inside. The ADT hides the internal
details, so whether it is implemented using an array or a linked list, the client program still
uses the same commands. For example, in a hospital system, the staff just clicks “add
patient” in the system. They don’t care if the system stores the patients in an array or a
linked list, as long as the operation works the same.

 15. Consider a Banking System. Which ADTs would you use for:
- Transaction history
- Queueing clients in a branch
- Detecting fraudulent activity in a transaction graph
In transaction history, I would use list ADT because it can store past transactions in
order. In queueing clients in a branch, I would use queue ADT since clients should be served
in the order they arrive. In detecting fraudulent activity in a transaction graph, I would use
graph ADT because transactions can be represented as connections between accounts
which makes it easier to trace suspicious links.

Common questions

Powered by AI

For managing a music app's playlist, a list ADT would be suitable as it allows the storage of sequentially ordered data. The operations it should support include: 1) Add song – to add new songs, 2) Remove song – to delete specific songs, 3) Shuffle – to randomize the song order, and 4) Play next – to play the next song in the sequence. These operations facilitate efficient playlist management and enhance user engagement .

An Abstract Data Type (ADT) is like a blueprint that specifies what operations can be performed on data, without detailing how these operations are implemented. In contrast, a data structure is the actual implementation in the computer's memory that performs these operations. Thus, ADTs focus on 'what' can be done, while data structures focus on 'how' it is done .

Information hiding is essential for maintaining large systems because it allows developers to update internal processes without altering the external interfaces that users interact with. This means that changes can be made behind the scenes, such as those in the BIR e-services, without affecting the user experience. Consequently, systems can be updated or improved efficiently without disrupting user operations or requiring users to adapt to new interfaces .

The advantages of using ADTs include making programs easier to understand by focusing on the operations possible rather than the underlying implementations. This promotes code maintainability and ease of future enhancements. However, a potential disadvantage is that the hidden implementation details might pose challenges for beginners to grasp how the system functions internally, and in some cases, this abstraction might lead to reduced flexibility in specific implementations .

Abstraction simplifies complex systems by hiding intricate details and presenting only the necessary information to users or developers. For instance, when using GCash in the Philippines for transactions, the user only sees a simple interface to send money, oblivious to the underlying complex processes occurring within the system. This abstraction allows users to interact with software efficiently without needing to understand its internal mechanics .

A Set ADT can be effectively utilized in a university enrollment system. For example, one set can store students enrolled in 'Data Structure and Algorithms', while another set stores students enrolled in 'Basic Calculus'. Using operations like union and intersection, the university can efficiently determine the list of students enrolled in either or both subjects, helping in organizing class lists and avoiding duplicate records .

When implementing a Stack ADT, using an array offers faster access times due to contiguous memory allocation, but it has a fixed size, which can limit expandability unless explicitly resized. Conversely, using a linked list allows dynamic resizing, providing flexibility as it can grow or shrink as needed. However, linked lists consume more memory for pointers and generally offer slower access times than arrays. The choice between these implementations depends on the specific needs, such as limited memory resources preferring arrays, while flexible, dynamic requirements might favor linked lists .

A Queue ADT can be structured for a hospital system to manage patient flow. It should support operations like 'enqueue', which adds a patient to the end of the line, mimicking a real-world waiting area. 'Dequeue' would remove the patient at the front, signifying it's their turn to see a doctor. 'Check next' allows staff to view the upcoming patient without removal, aiding in preparation for patient handling. These operations maintain efficient and organized patient service flow .

In a Library Management System, a list ADT would be suitable for storing a list of borrowed books to maintain ordered records. A queue ADT would manage the waiting line for new arrivals, ensuring books are distributed in the order requests are placed. Finally, a graph ADT would represent relationships between authors and co-authors, providing a flexible way to display interconnected data such as author collaborations .

Changing the underlying data structure of an ADT should not affect a client program because the client interacts solely with the ADT's operations, such as push or enqueue, rather than its implementation details. For instance, in a hospital system, the staff's interaction with an 'add patient' operation is unaffected by whether the patients are stored in an array or a linked list, as the operation should behave consistently regardless of the internal data structure .

You might also like