You are on page 1of 31

INTRODUCTION TO DATA STRUCTURE

CHAPTER 1

ROAD MAP

Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure

Data

Data is collection of numbers, alphabets & symbols combined to represent information. Atomic data: it is non-decomposable entity. Example: integer or char Composite data: it is a composition of day atomic data. month Example: date
year

DATA REPRESENTATION
Data is represented using different methods like hierarchical method.

The basic unit is bit.


Eight bits together form one byte which represents a character.

one or more than one characters are used to form a string.

let us discuss how the primitive or basic data types of any language are internally represented in memory.

Integer Representation
The positive data is represented using binary number system. 8 4 2 1 2^3 2^2 2^1 2^0 For negative binary numbers the methods of representation used are ones complement and twos complement.

Real Number Representation

The method used to represent real numbers in computers is floating-point notation. Real number is represented by a mantissa and exponent. For example, if the base is fixed as 10, 209.52 could be represented as 20952 x 10-2. The mantissa is 20952 and exponent is 2. Both the mantissa and exponents are twos complement binary integers. For example, 20952 can be represented as 1 0 1 0 0 0 111 0 1 1 in binary form.

Character Representation

It is used to store character as well as numeric information i.e. alpha-numeric data. 1 1 0 0 0 0 0 0 -> A and 1 1 0 0 0 0 0 1 -> B. Then, finally AB -> 11 0 0 0 0 0 0 11 0 0 0 0 0 1.

ROAD MAP

Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure

Abstract Data Types


Abstract Data Type (ADT): a definition for a data type solely in terms of a set of values and a set of operations on that data type.
Each ADT operation is defined by its inputs and outputs. Encapsulation: Hide implementation details.

ADT

An ADT is defined as a mathematical model of the data objects that make up a data type as well as the functions that operate on these objects. ADT acts as a useful guideline to implement a data type correctly.

IMPLEMENTATION

The implementation of an ADT involves the translation of the ADTs specification into syntax of a particular programming language. The important step is the definition of ADT that involves mainly two parts: 1. Relationship of components with each other 2. List of operations that can be performed on that data type.

EXAMPLES: INTEGER ADT


1>INTEGER-ADT set of numbers (-1, -2, 3....-} & set of whole numbers {O. 1,2.. +}. 2>INTEGER-ADT operations i.e addition subtraction multiplication, etc.

STACK ADT

abstract typedef <1, 2, 3 n, top> STACK; condition top == NULL abstract STACK PUSH (data) Preconditions: top != NULL Operation: insert(data) top->data /* as top points to most recently inserted element*/ abstract Pop ( ) Precondition: top!=null Operation: Remove (top) top >current data

ROAD MAP

Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure

What is a data structure?

In a general sense, any data representation is a data structure. Example: An integer More typically, a data structure is meant to be an organization for a collection of data items.

15

NEED OF A DATA STRUCTURE


Data structure is needed: Give knowledge about how to organize data. How to control flow of data. How to design structure of data. How to implement structure to reduce complexity & increases efficiency of algorithm.

Organizing Data
Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.

ROAD MAP

Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure

DATA TYPE
A method of interpreting a bit pattern is often called a data type. Data type can be defined as an abstract concept that defines an internal representation of data in the memory. A data type is an abstract concept defined by a set of logical properties.

NEED OF DATA TYPE


Think of a universal data type - has two disadvantages: Large volume of memory will be occupied by even a small size of data. Different interpretations for different types of data would become very difficult. Data type - optimum use of memory
- defined way to interpret

the bit strings.

PRIMITIVE DATA TYPE

Primitive data types are basic data type of any language that forms the basic unit for the data structure defined by the user. A primitive type defines how the data will be internally represented in, stored, and retrieved from the memory

EXAMPLES:

Date data type may be implemented using combination of different primitive data types. Following are primitive data typesInteger Character2^(n-1) + 1 to 2^(n+1) 1 09, AZ, az and other special

symbols Real/Float Numbers - mantissa and characteristic. m*n^r where m is the mantissa and n is the base (which is fixed 10) and r is the exponent

Derived Data Type

These are non-primitive data type which are derived from primitive data type. Examples: array structure union

ROAD MAP

Need of data structure Data representation Abstract data type Data type Difference between ADT, DT and DS Classification of data structure

DIFFERENCE BETWEEN ADT, DT AND DATA STRUCTURES

An abstract data type is the specification of the data type which specifies the logical a mathematical model of the data type.

A data type is the implementation of an abstract data type. Data structure refers to the collection of computer variables that are connected in some specific manner.

Relationship:
ADT is specification of data type, DT is implementation of ADT DS is collection of variables of same or different data types. ADT DT DS

ROAD MAP

Need of data structure Data representation Abstract data type Data type Difference between ADT, DT and DS Classification of data structure

Classification of data structure


Data structure

Primitive

Non-primitive

integer

char

float

pointer

Linear Data structure

Non-linear Data structure

Stacks

Queue

Array

Linked List

Trees

Graph

Classification of data structure

Non- primitive data structures are categorized into two classes: linear non-linear. In linear data structure, member elements form a sequence. Various types of linear data structure are stacks queue list Such linear structures can be represented in memory by using two basic strategies: arrays & linked list

Classification of data structure


Arrays are useful when the number of elements to he stored is fixed. Operations like traversal, searching and sorting can easily be performed on arrays. On the other hand, linked lists are useful when number of data items in the collection is likely to change. In non-linear data structure, a member element does not form sequence. There are various non-linear structures, such as trees graphs

Classification of data structure


Various operations can be performed on these data structures such as: Traversal: One of the most important operations which involves processing each element in the list. Searching: Searching or finding any element with a given value or the record with a given key. Insertion: Adding a new element to the list. Deletion: Removing an element from the list. Sorting: Arranging the elements in some order. Merging: Combining two lists into a single list.

You might also like