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

Abstract Data Types

This document discusses abstract data types (ADTs) and data structures. It defines an ADT as a user-defined type that specifies a set of values and operations on those values, independent of implementation. Examples of ADTs given are complex numbers and dates. A data structure is then defined as an implementation of an ADT in a programming language, with classes often used to represent ADTs in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Abstract Data Types

This document discusses abstract data types (ADTs) and data structures. It defines an ADT as a user-defined type that specifies a set of values and operations on those values, independent of implementation. Examples of ADTs given are complex numbers and dates. A data structure is then defined as an implementation of an ADT in a programming language, with classes often used to represent ADTs in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Grado en Ciencia e Ingeniería de

Datos, 2018-2019

Unit 1. Abstract Data Types

Data Structures and Algorithms (DSA)


Author: Isabel Segura-Bedmar
Index
● Abstraction
● Abstract Data Types
● Data structures

2
Introduction
● Programming languages provide primitive data types:
○ simple data types: cannot be decomposed into
smaller parts. Examples: Integer, Float, String,
Boolean.
○ complex data types: are constructed of multiple
components. Examples: List.
● Primitive types may not be sufficient for solving
complex problems.
● Programmers can define their own user-defined
types.
3
Introduction

4
Abstraction
● Focus on relevant details for a problem and rule out
irrelevant details.
Student
NIA
email
...

Patient
Birthdate
Weight
Allergies
...
5
Index
● Abstraction
● Abstract Data Types
● Data structures

6
What is an abstract data type (ADT)?
● User-defined type that specifies a set of data values
and a collection of operations to manipulate these
values.
● An ADT is independent of its implementation.
● Focus on the ‘what’ must do instead of ‘how’ do it.

7
Example: Complex Number ADT
A complex number consists of two parts:
● a real part, say a
● an imaginary part, say b
The value of such a complex number is: a+ib, where
i=√-1

8
Example: Complex Number ADT
Operations on a complex number:
● The negation of a complex number a+ib is:
-a + i(-b)
● Addition or subtraction:
○ (a+ib) + (c+id) = (a+c) + (b+d)i
○ (a+ib) - (c+id) = (a-c) + (b-d)i

9
Example: Complex Number ADT
Operations on a complex number:
● multiplication:
(a+ib) * (c+id) = (ac-bd) + (ad+bc)i
● absolute value or module:
|a+ib| = √(a2+b2)

10
Example: Date ADT
● A date represents a single day in our calendar (e.g
December 25, 2018 AC).
● The operations are:
○ Date(day,month,year): creates a new date
instance.
○ toString(): returns a string representation in the
format ‘dd/mm’/yyyy’.
○ day(): returns the day number of this date.
○ month(): returns the month number of this date.
○ year(): returns the year number of this date.
11
Example: Date ADT
● More operations:.
○ monthName(): returns the month name of this
date.
○ numDays(other): returns the number of days
between this date and the given date.
○ isLeapYear(): return True if this date falls in a leap
year, and False otherwise.

12
Example: Date ADT
● More operations:.
○ compareTo(other): compares this date to the
other to determine their logical order.
■ If this date is before to the other, returns -1.
■ If both dates are the same, return 0. I
■ If this date is after to the other, returns 1.

13
Index
● Abstraction
● Abstract Data Types
● Data structures

14
What is a data structure?
● A data structure is a representation (implementation)
of an ADT in a programming language.
● In Python, ADT are represented by classes.
● An ADT may have several implementations (data
structures).
● Focus on how they store and organize the data and
what operations are available for manipulating the
data.

15
Data structure for Complex Number ADT

16
Data structure for Complex Mumber ADT

17
Data structure for Complex Number ADT

18
Summary
● An ADT defines what operations, but not how to do
(implement) them.
● An ADT may have different implementations.
● A data structure is an implementation of an ADT.
● In Python, classes allow to implement ADTs.

19

You might also like