UNIT I - ABSTRACT DATA TYPES

Unformatted text preview:

lOMoAR cPSD 28397533 UNIT I ABSTRACT DATA TYPES Variables are used to hold data Ex x2 2y 2 1 Data Types string etc Variables are placeholders for representing data In computer programming variables A data type in a programming language is a set of data with predefined values Examples of data types are integer 2 Bytes floating point 4 Bytes unit number character At the top level there are two types of data types System defined data types also called Primitive data types User defined data types System defined data types Primitive data types Data types that are defined by system are called primitive data types The primitive data types provided by many programming languages are int float char double bool etc The number of bits allocated for each primitive data type depends on the programming languages the compiler and the operating system For the same primitive data type different languages may use different sizes Depending on the size of the data types the total available values domain will also change For example int may take 2 bytes or 4 bytes If it takes 2 bytes 16 bits then the total possible values are minus 32 768 to plus 32 767 215 to 215 1 If it takes 4 bytes 32 bits then the possible values are between 2 147 483 648 and 2 147 483 647 231 to 231 1 The same is the case with other data types lOMoAR cPSD 28397533 User defined data types If the system defined data types are not enough then most programming languages allow the users to define their own data types called user defined data types Good examples of user defined data types are structures in C C and classes in Java For example in the snippet below we are combining many system defined data types and calling the user defined data type by the name newType This gives more flexibility and comfort in dealing with computer memory struct newType int data1 float data2 char datan Data Structures it can be used efficiently Data structure is a particular way of storing and organizing data in a computer so that A data structure is a special format for organizing and storing data General data structure types include arrays files linked lists stacks queues trees graphs and so on Depending on the organization of the elements data structures are classified into two types 1 Linear data structures Elements are accessed in a sequential order but it is not compulsory to store all elements sequentially Examples Linked Lists Stacks and Queues 2 Non linear data structures Elements of this data structure are stored accessed in a non linear order Examples Trees and graphs Note For system defined data types by default the system supports implementations operations like addition subtraction etc lOMoAR cPSD 28397533 Abstract Data Types ADTs For user defined data types we also need to define operations The implementation for these operations can be done when we want to actually use them That means in general user defined data types are defined along with their operations To simplify the process of solving problems we combine the data structures with their operations and we call this Abstract Data Types ADTs An ADT consists of two parts 1 Declaration of data 2 Declaration of operations Commonly used ADTs include Linked Lists Stacks Queues Priority Queues Binary Trees Dictionaries Disjoint Sets Union and Find Hash Tables Graphs and many others Object Oriented Design Goals Software implementations should achieve robustness adaptability and reusability Robustness A program produces the right output for all the anticipated inputs in the program s application In addition we want software to be robust that is capable of handling unexpected inputs that are not explicitly defined for its application For example if a program is expecting a positive integer and instead is given a negative integer then the program should be able to recover gracefully from this error Adaptability Software therefore needs to be able to evolve over time in response to changing conditions in its environment Thus another important goal of quality software is that it achieves adaptability also called evolvability Related to this concept is portability which is the ability of software to run with minimal change on different hardware and operating system platforms An advantage of writing software in Python is the portability provided by the language itself Developing quality software can be an expensive enterprise and its cost can be offset somewhat if the software is designed in a way that makes it easily reusable in future Reusability applications Such reuse should be done with care however for one of the major sources of software errors in the Therac 25 came from inappropriate reuse of Therac 20 software lOMoAR cPSD 28397533 Object Oriented Design Principles Chief principles of object oriented approach is Modularity Abstraction Encapsulation Modularity Modularity refers to an organizing principle in which different components of a software system are divided into separate functional units Using modularity in a software system can also provide a powerful organizing framework that brings clarity to an implementation In Python we have already seen that a module is a collection of closely related functions and classes that are defined together in a single file of source code Python s standard libraries include for example the math module which provides definitions for key mathematical constants and functions and the os module which provides support for interacting with the operating system Abstraction Applying the abstraction paradigm to the design of data structures gives rise to abstract data types ADTs An ADT is a mathematical model of a data structure that specifies the type of data stored the operations supported on them and the types of parameters of the operations the collective set of behaviours supported by an ADT designed as public interface Python supports abstract data types using a mechanism known as an abstract base class ABC An abstract base class cannot be instantiated i e you cannot directly create an instance of that class but it defines one or more common methods that all implementations of the abstraction must have An ABC is realized by one or more concrete classes that inherit from the abstract base class while providing implementations for those method declared by the ABC Encapsulation Another important principle of object oriented design is encapsulation Different components of a software system should not reveal the internal details of their respective


View Full Document

UNIT I - ABSTRACT DATA TYPES

Download UNIT I - ABSTRACT DATA TYPES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view UNIT I - ABSTRACT DATA TYPES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view UNIT I - ABSTRACT DATA TYPES and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?