Data Abstraction and Abstract Data Types

Chapter 2 · Tamil Nadu State Board

  • 6 min read
  • 5-question quiz

Every key point below shows the sentence from your textbook it comes from. Book back answers are solved and checked against the book; answers we could not prove are left out. How we check content

In short

This lesson explains how data abstraction lets programs use data without depending on how it is represented or implemented. Abstract Data Types use constructors to create objects and selectors to retrieve their information. Lists, tuples, pairs, and classes provide ways to bundle and access data. These ideas help programmers handle complex data in a simpler, more modular way.

Written by AI from this lesson. How we check it

Key points

  • An ADT describes the values and operations of a type without specifying its implementation details.
    From your textbook
    “The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented.”
  • A constructor creates an abstract data object, while a selector retrieves information from it.
    From your textbook
    “Constructors are functions that build the abstract data type. Selectors are functions that retrieve information from the data type.”
  • A concrete data type has a known representation, unlike an abstract data type.
    From your textbook
    “A concrete data type is a data type whose representation is known”
  • Lists use square brackets and can hold values of different types, including other lists.
    From your textbook
    “List can store multiple values. Each value can be of any type and can even be another list.”
  • A pair bundles two values together, and it can be represented using a list or a tuple.
    From your textbook
    “Any way of bundling two values together into one can be considered as a pair.”
  • A tuple’s elements cannot be changed after it is assigned, but list elements can be changed.
    From your textbook
    “you cannot change the elements of a tuple once it is assigned whereas in a list, elements can be changed.”
  • A class can name the separate parts of a multi-item object and include functions that work on its data.
    From your textbook
    “A class is not just data, it has functions defined within it.”
Test yourself: 5 questions

Data Abstraction and Abstract Data Types

Data abstraction lets a programmer use an object by knowing what it does, without needing to know how it is built. This makes programs easier to divide into modules. Classes or structures can represent Abstract Data Types.

Definition

Abstract Data Type (ADT)
An ADT is a type of object described by its values and operations, without specifying how its data is stored or how its operations are implemented.

Abstract and concrete data types

Abstract data typeConcrete data type
Describes what operations can be done, without explaining their implementation.Has a representation that is known.
Can have different implementations. A List ADT, for example, can use a singly linked list or a doubly linked list.Provides the representation used to implement operations.

A program can have one part that works with abstract data and another part that defines its concrete representation. A small set of functions connects the two parts. This lets the main program make few assumptions about how data is represented.

Remember: An ADT says what operations do, not how they are implemented.

Constructors, Selectors, and Pairs

Definition

Constructor
A constructor is a function that creates an abstract data type object.

Definition

Selector
A selector is a function that retrieves information from an abstract data type object.

City object functions

  • makecity(name, lat, lon) creates a city object. It is the constructor.
  • getname(city) retrieves the city’s name.
  • getlat(city) retrieves its latitude.
  • getlon(city) retrieves its longitude.

A program can find the distance between two city objects by using getlat() and getlon() to retrieve their coordinates. It does not need to know how the city objects store those values. In the assignment notation, := means “assigned as” or “becomes”.

Point object functions

  • makepoint(x, y) creates a point and is the constructor.
  • xcoord(point) retrieves the point’s x-coordinate.
  • ycoord(point) retrieves the point’s y-coordinate.

Definition

Pair
A Pair is a compound structure used to bring pieces of information together; the described implementation uses a List or Tuple.

Rational Numbers as Abstract Data

Definition

Rational number
A rational number is a ratio of integers, written as a numerator divided by a denominator.

The numerator and denominator are both needed to represent the exact value. Dividing them directly gives a float approximation and can lose the exact precision of the integers. A rational number can instead be handled through a constructor and selectors.

Rational number functions

  • rational(x, y) is the constructor. It creates a rational number with numerator x and denominator y.
  • numer(x) is a selector that returns the numerator.
  • denom(y) is a selector that returns the denominator.

Worked example

Represent the rational number 8/3 using the constructor and selectors.

Try it first, then show the solution
  1. Set x, y := 8, 3.
  2. Create the rational number with rational(x, y).
  3. Use numer(x)/denom(y) to divide the selected numerator by the selected denominator.

Answer: The output is 2.6666666666666665.

Definition

Wishful thinking
In program design, wishful thinking means assuming that needed functions are available before deciding how they are implemented.

Remember: For rational numbers, rational() constructs the object; numer() and denom() select its parts.

Lists and accessing list elements

Definition

List
A list is a sequence of values written inside square brackets, with commas between the values.

A list can hold several values. Its elements can have different types, and an element can itself be another list. Lists allow their elements to be changed.

Worked example

Create a list and assign its values to two names.

Try it first, then show the solution
  1. Write lst := [10, 20].
  2. Use x, y := lst to unpack the list.

Answer: x becomes 10 and y becomes 20.

Two ways to access list elements

  • Multiple assignment unpacks the list and assigns its elements to separate names, as in x, y := lst.
  • The element selection operator uses an index, as in lst[0] and lst[1].

In [10, 20], index 0 selects 10 and index 1 selects 20. A pair bundles two values together. A list can represent a pair, so it can be used to represent a rational number as a numerator and a denominator.

Rational number represented by a list

rational(n, d): return [n, d]; numer(x): return x[0]; denom(x): return x[1]

n is the numerator, d is the denominator, x is the list representing the rational number, numer selects its first value, and denom selects its second value.

Tuples and pairs

Definition

Tuple
A tuple is a comma-separated sequence of values surrounded by parentheses.

Lists and tuples

ListTuple
Written inside square brackets.Written inside parentheses.
Elements can be changed.Elements cannot be changed once the tuple is assigned.
Can represent a pair.Can also represent a pair.

Worked example

Access the values in nums := (1, 2).

Try it first, then show the solution
  1. Use nums[0] to select the first value.
  2. Use nums[1] to select the second value.

Answer: nums[0] is 1 and nums[1] is 2.

Remember: A pair bundles two values. It can be represented using either a list or a tuple.

Data abstraction with classes

A list can group related values under one name. For example, Predict can hold the four colours guessed in Mastermind. But list positions do not name what each value means.

Worked example

Represent a person using named parts instead of relying on list positions.

Try it first, then show the solution
  1. Define a Person class with the fields firstName, lastName, id, and email.
  2. Create p1 as a Person object.
  3. Set its fields to Padmashri, Baskar, 994-222-1234, and [email protected].

Answer: Each value is stored in a named field, such as firstName, rather than being identified only by its position.

A class defines the form of objects and groups related data. A class can also contain functions that modify or analyse that data. The class is the type, while an individual created from it is an object or instance.

Definition

Abstract Data Type (ADT)
An ADT is a type or class whose behaviour is defined by its values and operations, without specifying how the data is stored or how the operations are implemented.

Important data abstraction terms

  • Constructors are functions that build an abstract data type.
  • Selectors are functions that retrieve information from a data type.
  • A concrete data type has a known representation.
  • An abstract data type hides its representation and gives a high-level way to use a concept.

Remember: A class can name the parts of a multi-item object, while a list groups values without naming what each part represents.

Questions students ask

Short, direct answers to what students search for in this chapter.

What is data abstraction?

Data abstraction lets a programmer use an object by knowing what it does, without needing to know how it is implemented. It helps keep a program modular and lets other programmers use its functions without reading every implementation detail.

What is an Abstract Data Type?

An Abstract Data Type (ADT) describes a type of object through its values and operations. It explains what operations are available, but does not specify how data is organized in memory or how the operations are implemented.

What is the difference between a constructor and a selector?

A constructor creates an abstract data type object by bringing its information together. A selector retrieves a particular piece of information from that object. For a city, makecity() constructs the object, while getname(), getlat(), and getlon() select its values.

How is a rational number represented using an ADT?

The rational() constructor creates a rational number from a numerator and denominator. The numer() and denom() selectors retrieve those parts. Keeping the two integers together gives an exact representation instead of immediately dividing them into a float approximation.

What is a list in computer science?

A list is a sequence of values written inside square brackets, with commas between them. It can hold values of different types, including another list. List elements can be accessed by unpacking the list with multiple assignment or by selecting an element with an index.

How do you access elements in a list?

There are two ways. Multiple assignment unpacks the list into separate names, as in x, y := lst. The element selection operator uses an index, such as lst[0] for the first value and lst[1] for the second value.

Show 2 more questions

What is the difference between a list and a tuple?

A list is written inside square brackets, and its elements can be changed. A tuple is a comma-separated sequence written inside parentheses, and its elements cannot be changed once it is assigned. Both lists and tuples can be used to represent a pair of values.

What are constructors and selectors?

Constructors are functions that build an abstract data type. Selectors are functions that retrieve information from a data type. They have different roles: constructors create the data structure, while selectors let a program obtain information from it.

Book back answers

19 textbook exercises, solved and checked against the book. Questions we could not prove are left out.

Choose the best answer (1 Mark)

  1. Which of the following functions that build the abstract data type ?

    • (A) Constructors
    • (B) Destructors
    • (C) recursive
    • (D)Nested
    Try it, then show the answer

    (A) Constructors

    Constructors build the abstract data type.

    From the book: “Constructors are functions that build the abstract data type.”

  2. Which of the following functions that retrieve information from the data type?

    • (A) Constructors
    • (B) Selectors
    • (C) recursive
    • (D)Nested
    Try it, then show the answer

    (B) Selectors

    Selectors retrieve information from a data type.

    From the book: “Selectors are functions that retrieve information from the data type.”

  3. The data structure which is a mutable ordered sequence of elements is called

    • (A) Built in
    • (B) List
    • (C) Tuple
    • (D) Derived data
    Try it, then show the answer

    (B) List

    A list can store multiple values, and its elements can be changed. The chapter contrasts this with a tuple, whose elements cannot be changed once assigned.

    From the book: “in a list, elements can be changed.”

  4. A sequence of immutable objects is called

    • (A) Built in
    • (B) List
    • (C) Tuple
    • (D) Derived data
    Try it, then show the answer

    (C) Tuple

    A tuple is a sequence of values whose elements cannot be changed once it is assigned.

    From the book: “you cannot change the elements of a tuple once it is assigned”

All 19 book back answers →

Practice

Question 1 of 5Score 0

What does an ADT description specify?

Exam questions

Practice questions with model answers. These are not from an official paper.

What is an Abstract Data Type?2 marks

An Abstract Data Type is a type for objects whose behavior is defined by a set of values and operations. It describes what operations are performed, not how they are implemented.

Differentiate between constructors and selectors.2 marks

Constructors build an abstract data type object. Selectors retrieve information from that object.

What is a pair? Give an example.2 marks

A pair bundles two values together into one compound data type. For example, the list [10, 20] can represent a pair.

Explain how a class can represent a multi-part object.5 marks

A class represents a multi-part object by defining a new data type whose parts are separately named. This makes it possible to work with the object without relying on unnamed positions in a list.

  1. Use a class: Define a class for the kind of object to be represented. The class specifies the form of objects of that type.
  2. Name each part: Give every component a meaningful name, such as firstName, lastName, id and email. These named parts are fields belonging to the class.
  3. Define the fields: The class definition can declare the fields and assign them initial values. This defines the data that the object can hold.
  4. Create an object: After defining the class, create an instance by calling it. The instance is a particular object of that class.
  5. Set field values: Assign values to the object's named fields, for example, the person's name, id and email. The fields identify what each value represents.
  6. Add functions: A class can also contain functions that work with its data, such as modifying or analysing it. Thus, a class bundles data and functions that operate on that data.

Example: A Person class can have the fields firstName, lastName, id and email; p1:=Person() creates an object, and values can be assigned to those fields.

Thus, a class represents a multi-part object by grouping its named data fields and related functions into one type.

Watch out

  • Do not confuse an ADT’s operations with their implementation: an ADT describes what operations do, not how they are carried out.
  • Do not assume lists and tuples behave the same when changed; the lesson says list elements can be changed, but tuple elements cannot.

Still stuck on this lesson?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →