0% found this document useful (0 votes)
15 views

05 Abstract Data Type

The document discusses abstract data types (ADTs) and their relationship to data structures. It defines an ADT as a theoretical concept that specifies the essential operations of a data type without specifying how those operations are implemented. Data structures then provide concrete implementations of the operations defined in an ADT. This allows the internal implementation to change without affecting how the data type is used. The document provides the vector ADT as an example, defining common operations like get, set, find, and push_back without specifying how they are implemented.

Uploaded by

Ramsha Tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

05 Abstract Data Type

The document discusses abstract data types (ADTs) and their relationship to data structures. It defines an ADT as a theoretical concept that specifies the essential operations of a data type without specifying how those operations are implemented. Data structures then provide concrete implementations of the operations defined in an ADT. This allows the internal implementation to change without affecting how the data type is used. The document provides the vector ADT as an example, defining common operations like get, set, find, and push_back without specifying how they are implemented.

Uploaded by

Ramsha Tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Data Structures

Abstract Data Type

Mostafa S. Ibrahim
Teaching, Training and Coaching since more than a decade!

Artificial Intelligence & Computer Vision Researcher


PhD from Simon Fraser University - Canada
Bachelor / Msc from Cairo University - Egypt
Ex-(Software Engineer / ICPC World Finalist)
What vs How

Img Src
What vs How
● Do you care how:
○ a TV/Car work? Google really searches and find results? Browser access the internet?
○ C++ computes pow(2.0, 3.2)
○ C++ handles OS to read/write from files using fstream?
● Most of the time, the user care about WHAT not HOW
○ What = Function takes and return
○ How = it is implemented. But
■ Some implementation can be slow (loop to sum 1 to n) or fast (sum = n * n+1 / 2)
■ Some might be buggy or stable (internet explorer vs Firefox)
■ Some might takes more memory (chrome vs Firefox)
○ We can change the internal implementation of the class independently without affecting the
user.
■ User depends on limited visible functionalities of specific WHAT details
Data Types
● Primitive Data Type
○ E.g. int, float
○ Supported Operations: e.g. x + 2 * y
● User-Defined Data Type
○ E.g. Our vector
○ Supported Operations: push_back, find, get(idx)
● What is an Abstract Data Type?
○ It is like a user defined data type
○ But we focus on the what: e.g. push_back
○ But we don’t care about how (not specified yet)
■ is it slow push_back or push_back with capacity trick?
○ There is only ONE what, but MANY how
What is ADT?
● ADTs are a theoretical concept. More like logical/mathematical view
○ We specify the what part and also potentially the expected performance
○ It is independent of a programming language and how it will be implemented
● Data structures are concrete. They are implementing the ADT
○ E.g. providing a push_back functionality with capacity enhancement
● The word abstraction?!
○ Abstraction is about hiding unwanted details while showing most essential in a given context
○ So we show the expected ‘what’ is supported and hide the how
○ Abstraction = High-level
■ Tip: Senior managers have high abstraction skills
■ They focus on the big picture and let the technical details for the engineers
Why ADT?
● Recall when you learned STL vector or stack, did u care how implemented?
○ Similarly, when you first learned driving, you never care of the inner details
● ADT are acting like an interface
○ We as clients: use it based on the agreed provided functionality (interface)
○ The implementer: follow the agreed design (interface)
● In industry
○ You discuss with your team lead the proper interface (provided functionalities / logic)
○ Then implement it
Vector ADT
● get-size()
● get-front()
● get-back()
● get(idx)
● set(idx, val)
● print()
● find(value): Return the position of the given value or None if not found
○ In C++, the position will be 0-based index. We can return -1 if not found
● push-back(value): Expected to add an element to the end of the vector
C++: Headers for interface separation
“Acquire knowledge and impart it to the people.”

“Seek knowledge from the Cradle to the Grave.”

You might also like