Download Data Structures and Algorithms

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
IIT Bombay
Data Structures and Algorithms
Prof. Ajit A. Diwan
Prof. Ganesh Ramakrishnan
Prof. Deepak B. Phatak
Department of Computer Science and Engineering
IIT Bombay
Session: Abstract Data Type
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
1
Programming Problem
Input data
variables
Program
IIT Bombay
Output data
functions
• Define variables to represent data
• Define functions to manipulate data
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
2
Abstract Data Type
IIT Bombay
• Variables have a type
• Type of a variable defines its possible values
• Defines the operations that can be performed on it
• Type can be defined independent of
• the actual data structure
• the programming language
• the computer
• Hence called ABSTRACT DATA TYPE
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
3
Example: integers
IIT Bombay
• Integer
• Values are …., -3, -2, -1, 0, 1, 2, 3, …..
• Operations are +, -, *, /, % …
• The abstract data type Integer is an infinite set
• The built-in data structure int is a particular implementation
of the abstract data type Integer
• Another built-in data structure long long int also
implements the same abstract type
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
4
Example: real numbers
IIT Bombay
• Real numbers
• Values : 2.5, 1.33333333…., 3.1415926…, 2.7182818…
• Operations +, -, *, /,
, …..
• Real values cannot be represented exactly
• Built-in types float, double, long double give a
data structure for representing real numbers approximately
• Errors in representation
• May need other data structures to reduce errors
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
5
Definition vs. Implementation
IIT Bombay
• Use of abstract data types separates the definition of the type
from its implementation
• We only need to define the abstract types to be used in a program
• This is independent of any computer or programming language or
any specific implementation
• Implementation of a given type in a particular language can be
done separately.
• For many common data types, implementations are readily
available : built-in types, libraries, etc.
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
6
Exercise: rational numbers
IIT Bombay
• Define the abstract data type Rational Number
• A rational number is a ratio of 2 integers
• Define all arithmetic operations on rational numbers
• Build a data structure for implementing this abstract type
• Write functions for implementing all operations on rational
numbers
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
7
Course Outline
IIT Bombay
• The first part of this course will concentrate on the
definitions of some standard abstract data types, and their
uses.
• The second part will concentrate on implementations of
these types, including those that are available as part of
standard libraries.
• The third part will look at uses of these types in algorithms
for solving problems.
Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
8