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

Lect 1 - DS - ADT

The document discusses abstract data types (ADTs). It defines an ADT as a mathematical model comprising a set of values and operations. ADTs provide an interface that hides implementation details and allows for modular design. While C does not enforce ADT interfaces, other languages like C++ and Java support implementing common ADTs like arrays, linked lists, and stacks through classes and generics. ADTs can be modeled as classes in object-oriented programming.

Uploaded by

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

Lect 1 - DS - ADT

The document discusses abstract data types (ADTs). It defines an ADT as a mathematical model comprising a set of values and operations. ADTs provide an interface that hides implementation details and allows for modular design. While C does not enforce ADT interfaces, other languages like C++ and Java support implementing common ADTs like arrays, linked lists, and stacks through classes and generics. ADTs can be modeled as classes in object-oriented programming.

Uploaded by

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

Course Split-up

 Theory
 Quiz 1- 20
 Quiz 2- 20
 Assignment - 10
 End Sem – 50
 Lab
 Continuous Assessment- 20
 Mid Sem – 30 (1program- 20m, viva -10m)
 End Sem – 50 (2program- 40m, viva -10m)
 It is a core subject in Computer Science and Engineering
 Slides taken from various resources from Internet
Data Structures
 Data structure is a representation of data and the
operations allowed on that data.
 It is a way of organizing the data.
 Examples:
 Bank account details
 Students details
 Employee details
Linear/ Non-linear DS
•3

 Linear data structure: Data can be stored and


accessed in a sequential fashion
 Non-linear data structure: Data can be stored and
accessed in a non-sequential (hierarchical) fashion
Linear/ Non-linear DS
•4
Abstract Data Types
ADT- Definitions
 In computer science, an abstract data type (ADT)
is a mathematical model for data types.
 Formally, an ADT may be defined as a "class of
objects whose logical behavior is defined by a set
of values and a set of operations";
 Abstract Data type (ADT) is a mathematical model,
whose behavior is defined by a set of data and a set
of methods.
What is Data Abstraction?
 Concept of “Abstraction”
 Allows us to consider the high-level characteristics of
something without getting bogged down in the details
 For example: Process abstraction in procedural
programming like C, we can use (pre-defined) functions
without concern how they really works inside.
 Data Abstraction
 We know what a data type can do
 How it is done is hidden
What is an Abstract Data Type?
 Abstract Data Type (ADT)
 Defines a particular data structure in terms of data and
operations
 Offers an interface of the objects (instances of an ADT)
 An ADT consists of
 Declaration of data
 Declaration of operations
 Encapsulation of data and operations : data is hidden from
user and can be manipulated only by means of operations
ADT Implementation
 Implementation of an Abstract Data Type (ADT)
 Hidden from the user
 Same ADT may be implemented in different ways in
different languages
 Some languages offer built-in ADTs and/or features to be
used to implement ADTs (user-define types)
 ADTs support modular design which is very important
in software development
Why Abstract?

 Specify the operations of the data structure and leave


implementation details to later
 in Java use an interface to specify operations
 many, many different ADTs
 picking the right one for the job is an important step in
design
 "Get your data structures correct first, and the rest of the
program will write itself."  -Davids Johnson
 High level languages often provide built in ADTs,
 the C++ STL, the Java standard library
ADT-Benefits

 Manufacturer Benefits:
 easy to modify, maintain
 profitable
 reusable
 Client Benefits:
 simple to use, understand
 familiar
 cheap
 component–based
How Well are ADTs Supported in C
?
•12

 Does C enforce the use of the ADTs inter


face and the hiding of its implementation
?

 No
C++ and OOP
•13

 C++ is a superset of C, which has added feature


s to support object oriented programming (OOP)
 C++ offers STL (Standard Templates Library)
providing a set generic data structures which allow
programmers to easily implement standard data
structures like queues, lists, and stacks.
 C++ supports classes
 things very like ADTs

 Other OOP languages such as Java, Smalltalk


ADT vs Object-Oriented Programming (OOP)
•14

 ADTs are not a part of a particular programming


language
 Rather they are implemented by a programmer to
solve a particular problem or some class of problems
 In OOP, an ADT can be easily modeled as a class
 An instance as an object
 Data of ADT as properties or fields of a class
 Operations as methods
 ADT ≠ OOP
 Classes in OOP offers more features than ADTs :
Inheritance (Superclass-Subclass), Polymorphisms, etc.
In Java- Array ADT
import java.util.ArrayList;
public class MyClass {
public static void main(String[] args) {

ArrayList<Integer> myNumbers = new ArrayList<Integer>();

myNumbers.add(10);
myNumbers.add(15);
myNumbers.add(20);
myNumbers.add(25);

System.out.println(myNumbers);

}
}
In C
•16
In Java- LinkedList ADT
1.import java.util.*;  

2.public class LinkedList1{   Output:
3. public static void main(String args[]){   Ravi
4.  LinkedList<String> al=new LinkedList<String>();   Vijay
5.  al.add("Ravi");   Ravi
6.  al.add("Vijay");   Ajay
7.  al.add("Ravi");  

8.  al.add("Ajay");  

9.    Iterator<String> itr=al.iterator();  

10.  while(itr.hasNext()){  

11.   System.out.println(itr.next());  

12.  }  // end of while

13. }  // end of main

14.}  // end of class LinedList1


#include <stdio.h>
#include <stdlib.h>
 
struct node
{
int data;
struct node *next;
};
 
int main()
{
struct node *prev,*head,*p;
int n,i;
printf ("number of elements:");
scanf("%d",&n);
head=NULL;
for(i=0;i<n;i++)
{
p=malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
if(head==NULL)
head=p;
else
prev->next=p;
prev=p;
}
return 0;
}
•// Java code to show the implementation of

•// add method in list interface

•import java.util.*;

•public class GfG {

• // Driver code

• public static void main(String[] args)

• {

• List<Integer> l = new ArrayList<>();

• l.add(10);

• l.add(15);

• l.add(20);

• System.out.println(l);

• }

•}
Summary

1. Data structure: Introduction


2. What is Data Abstraction? What is ADT?
3. Model for an Abstract Data Type
4. Complex Number ADT Example
5. How Well are ADTs Supported in C?
6. ADT vs Object-Oriented Programming

You might also like